
br.com.moip.models.Customers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk-java Show documentation
Show all versions of sdk-java Show documentation
Java SDK for Moip APIs integration
The newest version!
package br.com.moip.models;
import br.com.moip.api.request.RequestMaker;
import br.com.moip.api.request.RequestProperties;
import br.com.moip.api.request.RequestPropertiesBuilder;
import org.apache.http.entity.ContentType;
import java.util.Map;
public class Customers {
private static final String ENDPOINT = "/v2/customers";
private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON;
private RequestMaker requestMaker;
/**
* This method is used to create an customer.
*
* @param body
* {@code Map} the map charged with the correct request
* attributes.
*
* @param setup
* {@code Setup} the basic connection setup (authentication and timeouts).
*
* @return {@code Map create(Map body, Setup setup) {
this.requestMaker = new RequestMaker(setup);
RequestProperties props = new RequestPropertiesBuilder()
.method("POST")
.endpoint(ENDPOINT)
.body(body)
.type(Customers.class)
.contentType(CONTENT_TYPE);
return this.requestMaker.doRequest(props);
}
/**
* This method is used to add a new credit card to a registered customer.
*
* @param body
* {@code Map} the request body.
*
* @param customerId
* {@code String} the Moip customer external ID.
*
* @param setup
* {@code Setup} the setup object.
*
* @return {@code Map}
*/
public Map addCreditCard(Map body, String customerId, Setup setup) {
this.requestMaker = new RequestMaker(setup);
RequestProperties props = new RequestPropertiesBuilder()
.method("POST")
.endpoint(String.format("%s/%s/fundinginstruments", ENDPOINT, customerId))
.body(body)
.type(Customers.class)
.contentType(CONTENT_TYPE)
.build();
return this.requestMaker.doRequest(props);
}
/**
* This method is used to delete a saved credit card of an customer.
*
* @param creditCardId
* {@code String} the Moip credit card external ID.
*
* @param setup
* {@code Setup} the setup object.
*
* @return {@code Map}
*/
public Map deleteCreditCard(String creditCardId, Setup setup) {
this.requestMaker = new RequestMaker(setup);
RequestProperties props = new RequestPropertiesBuilder()
.method("DELETE")
.endpoint(String.format("/v2/fundinginstruments/%s", creditCardId))
.type(Customers.class)
.contentType(CONTENT_TYPE)
.build();
return this.requestMaker.doRequest(props);
}
/**
* This method is used to get the data of a created customer by Moip customer external ID.
*
* @param customerId
* {@code String} the Moip customer external ID. Ex: CUS-XXXXXXXXXXXX.
*
* @param setup
* {@code Setup} the setup object.
*
* @return {@code Map}.
*/
public Map get(String customerId, Setup setup) {
this.requestMaker = new RequestMaker(setup);
RequestProperties props = new RequestPropertiesBuilder()
.method("GET")
.endpoint(String.format("%s/%s", ENDPOINT, customerId))
.type(Customers.class)
.contentType(CONTENT_TYPE)
.build();
return this.requestMaker.doRequest(props);
}
/**
* This method is used to get all registered customers.
*
* @param setup
* {@code Setup} the setup object.
*
* @return {@code Map}
*/
public Map list(Setup setup) {
this.requestMaker = new RequestMaker(setup);
RequestProperties props = new RequestPropertiesBuilder()
.method("GET")
.endpoint(ENDPOINT)
.type(Customers.class)
.contentType(CONTENT_TYPE)
.build();
return this.requestMaker.doRequest(props);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy