com.braintreegateway.MerchantAccountGateway Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.apache.servicemix.bundles.braintree-java
Show all versions of org.apache.servicemix.bundles.braintree-java
This OSGi bundle wraps ${pkgArtifactId} ${pkgVersion} jar file.
The newest version!
package com.braintreegateway;
import com.braintreegateway.exceptions.NotFoundException;
import com.braintreegateway.util.Http;
import com.braintreegateway.util.NodeWrapper;
import java.util.ArrayList;
import java.util.List;
public class MerchantAccountGateway {
public static final String CREATE_URL = "/merchant_accounts/create_via_api";
public static final String CREATE_FOR_CURRENCY_URL = "/merchant_accounts/create_for_currency";
private final Http http;
private Configuration configuration;
public MerchantAccountGateway(Http http, Configuration configuration) {
this.http = http;
this.configuration = configuration;
}
public Result create(MerchantAccountRequest request) {
final NodeWrapper response = http.post(configuration.getMerchantPath() + CREATE_URL, request);
return new Result(response, MerchantAccount.class);
}
public Result createForCurrency(MerchantAccountCreateForCurrencyRequest request) {
final NodeWrapper response = http.post(configuration.getMerchantPath() + CREATE_FOR_CURRENCY_URL, request);
return new Result(response, MerchantAccount.class);
}
public MerchantAccount find(String id) {
if (id == null || id.trim().equals("")) {
throw new NotFoundException();
}
return new MerchantAccount(http.get(configuration.getMerchantPath() + "/merchant_accounts/" + id));
}
public Result update(String id, MerchantAccountRequest request) {
final NodeWrapper response = http.put(configuration.getMerchantPath() + "/merchant_accounts/" + id + "/update_via_api", request);
return new Result(response, MerchantAccount.class);
}
public PaginatedCollection all() {
return new PaginatedCollection(new MerchantAccountPager(this));
}
public PaginatedResult fetchMerchantAccounts(int page) {
final NodeWrapper response = http.get(configuration.getMerchantPath() + "/merchant_accounts?page=" + page);
List merchantAccounts = new ArrayList();
for (NodeWrapper node : response.findAll("merchant-account")) {
merchantAccounts.add(new MerchantAccount(node));
}
return new PaginatedResult(response.findInteger("total-items"), response.findInteger("page-size"), merchantAccounts);
}
}