com.braintreegateway.AddressGateway 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;
/**
* Provides methods to create, delete, find, and update {@link Address} objects.
* This class does not need to be instantiated directly.
* Instead, use {@link BraintreeGateway#address()} to get an instance of this class:
*
*
* BraintreeGateway gateway = new BraintreeGateway(...);
* gateway.address().create(...)
*
*/
public class AddressGateway {
private Http http;
private Configuration configuration;
public AddressGateway(Http http, Configuration configuration) {
this.http = http;
this.configuration = configuration;
}
/**
* Creates an {@link Address} for a {@link Customer}.
* @param customerId the id of the {@link Customer}.
* @param request the request object.
* @return a {@link Result} object.
*/
public Result create(String customerId, AddressRequest request) {
NodeWrapper node = http.post(configuration.getMerchantPath() + "/customers/" + customerId + "/addresses", request);
return new Result(node, Address.class);
}
/**
* Deletes a Customer's {@link Address}.
* @param customerId the id of the {@link Customer}.
* @param id the id of the {@link Address} to delete.
* @return a {@link Result} object.
*/
public Result delete(String customerId, String id) {
http.delete(configuration.getMerchantPath() + "/customers/" + customerId + "/addresses/" + id);
return new Result();
}
/**
* Finds a Customer's {@link Address}.
* @param customerId the id of the {@link Customer}.
* @param id the id of the {@link Address}.
* @return the {@link Address} or raises a {@link com.braintreegateway.exceptions.NotFoundException}.
*/
public Address find(String customerId, String id) {
if (customerId == null || customerId.trim().equals("") || id == null || id.trim().equals("")) {
throw new NotFoundException();
}
return new Address(http.get(configuration.getMerchantPath() + "/customers/" + customerId + "/addresses/" + id));
}
/**
* Updates a Customer's {@link Address}.
* @param customerId the id of the {@link Customer}.
* @param id the id of the {@link Address}.
* @param request the request object containing the {@link AddressRequest} parameters.
* @return the {@link Address} or raises a {@link com.braintreegateway.exceptions.NotFoundException}.
*/
public Result update(String customerId, String id, AddressRequest request) {
NodeWrapper node = http.put(configuration.getMerchantPath() + "/customers/" + customerId + "/addresses/" + id, request);
return new Result(node, Address.class);
}
}