com.braintreegateway.PlanGateway 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.
package com.braintreegateway;
import java.util.ArrayList;
import java.util.List;
import com.braintreegateway.exceptions.NotFoundException;
import com.braintreegateway.util.Http;
import com.braintreegateway.util.NodeWrapper;
public class PlanGateway {
private Http http;
private Configuration configuration;
public PlanGateway(Http http, Configuration configuration) {
this.http = http;
this.configuration = configuration;
}
public List all() {
NodeWrapper node = http.get(configuration.getMerchantPath() + "/plans");
List plans = new ArrayList();
for (NodeWrapper planResponse : node.findAll("plan")) {
plans.add(new Plan(planResponse));
}
return plans;
}
public Result create(PlanRequest request) {
NodeWrapper node = http.post(configuration.getMerchantPath() + "/plans", request);
return new Result(node, Plan.class);
}
public Plan find(String id) {
if (id == null || id.trim().equals("")) {
throw new NotFoundException();
}
return new Plan(http.get(configuration.getMerchantPath() + "/plans/" + id));
}
public Result update(String id, PlanRequest request) {
NodeWrapper node = http.put(configuration.getMerchantPath() + "/plans/" + id, request);
return new Result(node, Plan.class);
}
}