All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.braintreegateway.PlanGateway Maven / Gradle / Ivy

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);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy