Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.paypal.api.payments;
  
  import java.net.URL;
  import java.util.Date;
  import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 
 public class Agreement  extends PayPalResource {

Identifier of the agreement.
 
 	private String id;

State of the agreement
 
 	private String state;

Name of the agreement.
 
 	private String name;

Description of the agreement.
 
 	private String description;

Start date of the agreement. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6).
 
 	private String startDate;

Details of the agreement.
 
Details of the buyer who is enrolling in this agreement. This information is gathered from execution of the approval URL.
 
 	private Payer payer;

Shipping address object of the agreement, which should be provided if it is different from the default address.
 
 	private Address shippingAddress;

Default merchant preferences from the billing plan are used, unless override preferences are provided here.
 
Array of override_charge_model for this agreement if needed to change the default models from the billing plan.
 
Plan details for this agreement.
 
 	private Plan plan;

Date and time that this resource was created. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6).
 
 	private String createTime;

Date and time that this resource was updated. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6).
 
 	private String updateTime;

Payment token
 
 	private String token;

 
 	private List<Linkslinks;

Default Constructor
	public Agreement() {
	}

Parameterized Constructor
	public Agreement(String nameString descriptionString startDatePayer payerPlan plan) {
		this. = name;
		this. = description;
		this. = startDate;
		this. = payer;
		this. = plan;
	}


Setter for id
	public Agreement setId(String id) {
		this. = id;
		return this;
	}

Getter for id
	public String getId() {
		return this.;
	}

Setter for state
	public Agreement setState(String state) {
		this. = state;
		return this;
	}

Getter for state
	public String getState() {
		return this.;
	}

Setter for name
	public Agreement setName(String name) {
		this. = name;
		return this;
	}

Getter for name
	public String getName() {
		return this.;
	}


Setter for description
	public Agreement setDescription(String description) {
		this. = description;
		return this;
	}

Getter for description
	public String getDescription() {
		return this.;
	}


Setter for startDate
	public Agreement setStartDate(String startDate) {
		this. = startDate;
		return this;
	}

Getter for startDate
	public String getStartDate() {
		return this.;
	}


Setter for agreementDetails
	public Agreement setAgreementDetails(AgreementDetails agreementDetails) {
		this. = agreementDetails;
		return this;
	}

Getter for agreementDetails
		return this.;
	}


Setter for payer
	public Agreement setPayer(Payer payer) {
		this. = payer;
		return this;
	}

Getter for payer
	public Payer getPayer() {
		return this.;
	}


Setter for shippingAddress
	public Agreement setShippingAddress(Address shippingAddress) {
		this. = shippingAddress;
		return this;
	}

Getter for shippingAddress
		return this.;
	}


Setter for overrideMerchantPreferences
	public Agreement setOverrideMerchantPreferences(MerchantPreferences overrideMerchantPreferences) {
		this. = overrideMerchantPreferences;
		return this;
	}

Getter for overrideMerchantPreferences
	}


Setter for overrideChargeModels
	public Agreement setOverrideChargeModels(List<OverrideChargeModeloverrideChargeModels) {
		this. = overrideChargeModels;
		return this;
	}

Getter for overrideChargeModels
	}


Setter for plan
	public Agreement setPlan(Plan plan) {
		this. = plan;
		return this;
	}

Getter for plan
	public Plan getPlan() {
		return this.;
	}


Setter for createTime
	public Agreement setCreateTime(String createTime) {
		this. = createTime;
		return this;
	}

Getter for createTime
	public String getCreateTime() {
		return this.;
	}


Setter for updateTime
	public Agreement setUpdateTime(String updateTime) {
		this. = updateTime;
		return this;
	}

Getter for updateTime
	public String getUpdateTime() {
		return this.;
	}

Setter for token
	public Agreement setToken(String token) {
		this. = token;
		return this;
	}

Getter for token
	public String getToken() {
		return this.;
	}

Setter for links
	public Agreement setLinks(List<Linkslinks) {
		this. = links;
		return this;
	}

Getter for links
	public List<LinksgetLinks() {
		return this.;
	}


Create a new billing agreement by passing the details for the agreement, including the name, description, start date, payer, and billing plan in the request JSON.

Parameters:
accessToken Access Token used for the API call.
Returns:
Agreement
Throws:
com.paypal.base.rest.PayPalRESTException
java.io.UnsupportedEncodingException
java.net.MalformedURLException
		APIContext apiContext = new APIContext(accessToken);
		return create(apiContext);
	}

Create a new billing agreement by passing the details for the agreement, including the name, description, start date, payer, and billing plan in the request JSON.

		if (apiContext == null) {
			throw new IllegalArgumentException("APIContext cannot be null");
		}
		if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) {
			throw new IllegalArgumentException("AccessToken cannot be null or empty");
		}
		if (apiContext.getHTTPHeaders() == null) {
			apiContext.setHTTPHeaders(new HashMap<StringString>());
		}
		apiContext.setSdkVersion(new SDKVersionImpl());
		String resourcePath = "v1/payments/billing-agreements";
		String payLoad = this.toJSON();
		Agreement agreement = configureAndExecute(apiContext.resourcePathpayLoadAgreement.class);
		for (Links links : agreement.getLinks()) {
			if ("approval_url".equals(links.getRel())) {
				URL url = new URL(links.getHref());
				agreement.setToken(splitQuery(url).get("token"));
				break;
			}
		}
		return agreement;
	}

Helper class to parse Query part of a URL

Parameters:
url
Returns:
Query part in the given URL in name-value pair
Throws:
java.io.UnsupportedEncodingException
	private static Map<StringStringsplitQuery(URL urlthrows UnsupportedEncodingException {
	    Map<StringStringqueryPairs = new HashMap<StringString>();
	    String query = url.getQuery();
	    String[] pairs = query.split("&");
	    for (String pair : pairs) {
	        int idx = pair.indexOf("=");
	        queryPairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8"));
	    }
	    return queryPairs;
	}


Execute a billing agreement after buyer approval by passing the payment token to the request URI.

Parameters:
accessToken Access Token used for the API call.
Returns:
Agreement
Throws:
com.paypal.base.rest.PayPalRESTException
	public Agreement execute(String accessTokenthrows PayPalRESTException {
		APIContext apiContext = new APIContext(accessToken);
		return execute(apiContextthis.getToken());
	}

Execute a billing agreement after buyer approval by passing the payment token to the request URI.

Parameters:
apiContext com.paypal.base.rest.APIContext used for the API call.
token payment token (e.g., EC-0JP008296V451950C)
Returns:
Agreement
Throws:
com.paypal.base.rest.PayPalRESTException
	public static Agreement execute(APIContext apiContextString tokenthrows PayPalRESTException {
		if (apiContext == null) {
			throw new IllegalArgumentException("APIContext cannot be null");
		}
		if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) {
			throw new IllegalArgumentException("AccessToken cannot be null or empty");
		}
		if (apiContext.getHTTPHeaders() == null) {
			apiContext.setHTTPHeaders(new HashMap<StringString>());
		}
		apiContext.setSdkVersion(new SDKVersionImpl());
		Object[] parameters = new Object[] { token };
		String pattern = "v1/payments/billing-agreements/{0}/agreement-execute";
		String resourcePath = RESTUtil.formatURIPath(patternparameters);
		String payLoad = "";
		return configureAndExecute(apiContext.resourcePathpayLoadAgreement.class);
	}


Retrieve details for a particular billing agreement by passing the ID of the agreement to the request URI.

Parameters:
accessToken Access Token used for the API call.
agreementId String
Returns:
Agreement
Throws:
com.paypal.base.rest.PayPalRESTException
	public static Agreement get(String accessTokenString agreementIdthrows PayPalRESTException {
		APIContext apiContext = new APIContext(accessToken);
		return get(apiContextagreementId);
	}

Retrieve details for a particular billing agreement by passing the ID of the agreement to the request URI.

Parameters:
apiContext com.paypal.base.rest.APIContext used for the API call.
agreementId String
Returns:
Agreement
Throws:
com.paypal.base.rest.PayPalRESTException
	public static Agreement get(APIContext apiContextString agreementIdthrows PayPalRESTException {
		if (apiContext == null) {
			throw new IllegalArgumentException("APIContext cannot be null");
		}
		if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) {
			throw new IllegalArgumentException("AccessToken cannot be null or empty");
		}
		if (apiContext.getHTTPHeaders() == null) {
			apiContext.setHTTPHeaders(new HashMap<StringString>());
		}
		apiContext.setSdkVersion(new SDKVersionImpl());
		if (agreementId == null) {
			throw new IllegalArgumentException("agreementId cannot be null");
		}
		Object[] parameters = new Object[] {agreementId};
		String pattern = "v1/payments/billing-agreements/{0}";
		String resourcePath = RESTUtil.formatURIPath(patternparameters);
		String payLoad = "";
		return configureAndExecute(apiContext.resourcePathpayLoadAgreement.class);
	}


Update details of a billing agreement, such as the description, shipping address, and start date, by passing the ID of the agreement to the request URI.

Parameters:
accessToken Access Token used for the API call.
patchRequest PatchRequest
Returns:
Agreement
Throws:
com.paypal.base.rest.PayPalRESTException
	public Agreement update(String accessTokenList<PatchpatchRequestthrows PayPalRESTException {
		APIContext apiContext = new APIContext(accessToken);
		return update(apiContextpatchRequest);
	}

Update details of a billing agreement, such as the description, shipping address, and start date, by passing the ID of the agreement to the request URI.

Parameters:
apiContext com.paypal.base.rest.APIContext used for the API call.
patchRequest PatchRequest (list of patches)
Returns:
Agreement
Throws:
com.paypal.base.rest.PayPalRESTException
	public Agreement update(APIContext apiContextList<PatchpatchRequestthrows PayPalRESTException {
		if (apiContext == null) {
			throw new IllegalArgumentException("APIContext cannot be null");
		}
		if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) {
			throw new IllegalArgumentException("AccessToken cannot be null or empty");
		}
		if (apiContext.getHTTPHeaders() == null) {
			apiContext.setHTTPHeaders(new HashMap<StringString>());
		}
		apiContext.setSdkVersion(new SDKVersionImpl());
		if (this.getId() == null) {
			throw new IllegalArgumentException("Id cannot be null");
		}
		if (patchRequest == null) {
			throw new IllegalArgumentException("patchRequest cannot be null");
		}
		Object[] parameters = new Object[] {this.getId()};
		String pattern = "v1/payments/billing-agreements/{0}";
		String resourcePath = RESTUtil.formatURIPath(patternparameters);
		String payLoad = new GsonBuilder().create().toJson(patchRequest);
		return configureAndExecute(apiContext.resourcePathpayLoadAgreement.class);
	}


Suspend a particular billing agreement by passing the ID of the agreement to the request URI.

Parameters:
accessToken Access Token used for the API call.
agreementStateDescriptor AgreementStateDescriptor
Throws:
com.paypal.base.rest.PayPalRESTException
	public void suspend(String accessTokenAgreementStateDescriptor agreementStateDescriptorthrows PayPalRESTException {
		APIContext apiContext = new APIContext(accessToken);
		suspend(apiContextagreementStateDescriptor);
		return;
	}

Suspend a particular billing agreement by passing the ID of the agreement to the request URI.

Parameters:
apiContext com.paypal.base.rest.APIContext used for the API call.
agreementStateDescriptor AgreementStateDescriptor
Throws:
com.paypal.base.rest.PayPalRESTException
	public void suspend(APIContext apiContextAgreementStateDescriptor agreementStateDescriptorthrows PayPalRESTException {
		if (apiContext == null) {
			throw new IllegalArgumentException("APIContext cannot be null");
		}
		if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) {
			throw new IllegalArgumentException("AccessToken cannot be null or empty");
		}
		if (apiContext.getHTTPHeaders() == null) {
			apiContext.setHTTPHeaders(new HashMap<StringString>());
		}
		apiContext.setSdkVersion(new SDKVersionImpl());
		if (this.getId() == null) {
			throw new IllegalArgumentException("Id cannot be null");
		}
		if (agreementStateDescriptor == null) {
			throw new IllegalArgumentException("agreementStateDescriptor cannot be null");
		}
		Object[] parameters = new Object[] {this.getId()};
		String pattern = "v1/payments/billing-agreements/{0}/suspend";
		String resourcePath = RESTUtil.formatURIPath(patternparameters);
		String payLoad = agreementStateDescriptor.toJSON();
		configureAndExecute(apiContext.resourcePathpayLoadnull);
		return;
	}


Reactivate a suspended billing agreement by passing the ID of the agreement to the appropriate URI. In addition, pass an agreement_state_descriptor object in the request JSON that includes a note about the reason for changing the state of the agreement and the amount and currency for the agreement.

Parameters:
accessToken Access Token used for the API call.
agreementStateDescriptor AgreementStateDescriptor
Throws:
com.paypal.base.rest.PayPalRESTException
	public void reActivate(String accessTokenAgreementStateDescriptor agreementStateDescriptorthrows PayPalRESTException {
		APIContext apiContext = new APIContext(accessToken);
		reActivate(apiContextagreementStateDescriptor);
		return;
	}

Reactivate a suspended billing agreement by passing the ID of the agreement to the appropriate URI. In addition, pass an agreement_state_descriptor object in the request JSON that includes a note about the reason for changing the state of the agreement and the amount and currency for the agreement.

Parameters:
apiContext com.paypal.base.rest.APIContext used for the API call.
agreementStateDescriptor AgreementStateDescriptor
Throws:
com.paypal.base.rest.PayPalRESTException
	public void reActivate(APIContext apiContextAgreementStateDescriptor agreementStateDescriptorthrows PayPalRESTException {
		if (apiContext == null) {
			throw new IllegalArgumentException("APIContext cannot be null");
		}
		if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) {
			throw new IllegalArgumentException("AccessToken cannot be null or empty");
		}
		if (apiContext.getHTTPHeaders() == null) {
			apiContext.setHTTPHeaders(new HashMap<StringString>());
		}
		apiContext.setSdkVersion(new SDKVersionImpl());
		if (this.getId() == null) {
			throw new IllegalArgumentException("Id cannot be null");
		}
		if (agreementStateDescriptor == null) {
			throw new IllegalArgumentException("agreementStateDescriptor cannot be null");
		}
		Object[] parameters = new Object[] {this.getId()};
		String pattern = "v1/payments/billing-agreements/{0}/re-activate";
		String resourcePath = RESTUtil.formatURIPath(patternparameters);
		String payLoad = agreementStateDescriptor.toJSON();
		configureAndExecute(apiContext.resourcePathpayLoadnull);
		return;
	}


Cancel a billing agreement by passing the ID of the agreement to the request URI. In addition, pass an agreement_state_descriptor object in the request JSON that includes a note about the reason for changing the state of the agreement and the amount and currency for the agreement.

Parameters:
accessToken Access Token used for the API call.
agreementStateDescriptor AgreementStateDescriptor
Throws:
com.paypal.base.rest.PayPalRESTException
	public void cancel(String accessTokenAgreementStateDescriptor agreementStateDescriptorthrows PayPalRESTException {
		APIContext apiContext = new APIContext(accessToken);
		cancel(apiContextagreementStateDescriptor);
		return;
	}

Cancel a billing agreement by passing the ID of the agreement to the request URI. In addition, pass an agreement_state_descriptor object in the request JSON that includes a note about the reason for changing the state of the agreement and the amount and currency for the agreement.

Parameters:
apiContext com.paypal.base.rest.APIContext used for the API call.
agreementStateDescriptor AgreementStateDescriptor
Throws:
com.paypal.base.rest.PayPalRESTException
	public void cancel(APIContext apiContextAgreementStateDescriptor agreementStateDescriptorthrows PayPalRESTException {
		if (apiContext == null) {
			throw new IllegalArgumentException("APIContext cannot be null");
		}
		if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) {
			throw new IllegalArgumentException("AccessToken cannot be null or empty");
		}
		if (apiContext.getHTTPHeaders() == null) {
			apiContext.setHTTPHeaders(new HashMap<StringString>());
		}
		apiContext.setSdkVersion(new SDKVersionImpl());
		if (this.getId() == null) {
			throw new IllegalArgumentException("Id cannot be null");
		}
		if (agreementStateDescriptor == null) {
			throw new IllegalArgumentException("agreementStateDescriptor cannot be null");
		}
		Object[] parameters = new Object[] {this.getId()};
		String pattern = "v1/payments/billing-agreements/{0}/cancel";
		String resourcePath = RESTUtil.formatURIPath(patternparameters);
		String payLoad = agreementStateDescriptor.toJSON();
		configureAndExecute(apiContext.resourcePathpayLoadnull);
		return;
	}


Bill an outstanding amount for an agreement by passing the ID of the agreement to the request URI. In addition, pass an agreement_state_descriptor object in the request JSON that includes a note about the reason for changing the state of the agreement and the amount and currency for the agreement.

Parameters:
accessToken Access Token used for the API call.
agreementStateDescriptor AgreementStateDescriptor
Throws:
com.paypal.base.rest.PayPalRESTException
	public void billBalance(String accessTokenAgreementStateDescriptor agreementStateDescriptorthrows PayPalRESTException {
		APIContext apiContext = new APIContext(accessToken);
		billBalance(apiContextagreementStateDescriptor);
		return;
	}

Bill an outstanding amount for an agreement by passing the ID of the agreement to the request URI. In addition, pass an agreement_state_descriptor object in the request JSON that includes a note about the reason for changing the state of the agreement and the amount and currency for the agreement.

Parameters:
apiContext com.paypal.base.rest.APIContext used for the API call.
agreementStateDescriptor AgreementStateDescriptor
Throws:
com.paypal.base.rest.PayPalRESTException
	public void billBalance(APIContext apiContextAgreementStateDescriptor agreementStateDescriptorthrows PayPalRESTException {
		if (apiContext == null) {
			throw new IllegalArgumentException("APIContext cannot be null");
		}
		if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) {
			throw new IllegalArgumentException("AccessToken cannot be null or empty");
		}
		if (apiContext.getHTTPHeaders() == null) {
			apiContext.setHTTPHeaders(new HashMap<StringString>());
		}
		apiContext.setSdkVersion(new SDKVersionImpl());
		if (this.getId() == null) {
			throw new IllegalArgumentException("Id cannot be null");
		}
		if (agreementStateDescriptor == null) {
			throw new IllegalArgumentException("agreementStateDescriptor cannot be null");
		}
		Object[] parameters = new Object[] {this.getId()};
		String pattern = "v1/payments/billing-agreements/{0}/bill-balance";
		String resourcePath = RESTUtil.formatURIPath(patternparameters);
		String payLoad = agreementStateDescriptor.toJSON();
		configureAndExecute(apiContext.resourcePathpayLoadnull);
		return;
	}


Set the balance for an agreement by passing the ID of the agreement to the request URI. In addition, pass a common_currency object in the request JSON that specifies the currency type and value of the balance.

Parameters:
accessToken Access Token used for the API call.
currency Currency
Throws:
com.paypal.base.rest.PayPalRESTException
	public void setBalance(String accessTokenCurrency currencythrows PayPalRESTException {
		APIContext apiContext = new APIContext(accessToken);
		setBalance(apiContextcurrency);
		return;
	}

Set the balance for an agreement by passing the ID of the agreement to the request URI. In addition, pass a common_currency object in the request JSON that specifies the currency type and value of the balance.

Parameters:
apiContext com.paypal.base.rest.APIContext used for the API call.
currency Currency
Throws:
com.paypal.base.rest.PayPalRESTException
	public void setBalance(APIContext apiContextCurrency currencythrows PayPalRESTException {
		if (apiContext == null) {
			throw new IllegalArgumentException("APIContext cannot be null");
		}
		if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) {
			throw new IllegalArgumentException("AccessToken cannot be null or empty");
		}
		if (apiContext.getHTTPHeaders() == null) {
			apiContext.setHTTPHeaders(new HashMap<StringString>());
		}
		apiContext.setSdkVersion(new SDKVersionImpl());
		if (this.getId() == null) {
			throw new IllegalArgumentException("Id cannot be null");
		}
		if (currency == null) {
			throw new IllegalArgumentException("currency cannot be null");
		}
		Object[] parameters = new Object[] {this.getId()};
		String pattern = "v1/payments/billing-agreements/{0}/set-balance";
		String resourcePath = RESTUtil.formatURIPath(patternparameters);
		String payLoad = currency.toJSON();
		configureAndExecute(apiContext.resourcePathpayLoadnull);
		return;
	}


List transactions for a billing agreement by passing the ID of the agreement, as well as the start and end dates of the range of transactions to list, to the request URI.

Parameters:
accessToken Access Token used for the API call.
agreementId String
Returns:
AgreementTransactions
Throws:
com.paypal.base.rest.PayPalRESTException
	public static AgreementTransactions transactions(String accessTokenString agreementIdDate startDateDate endDatethrows PayPalRESTException {
		APIContext apiContext = new APIContext(accessToken);
		return transactions(apiContextagreementIdstartDateendDate);
	}

List transactions for a billing agreement by passing the ID of the agreement, as well as the start and end dates of the range of transactions to list, to the request URI.

Parameters:
apiContext com.paypal.base.rest.APIContext used for the API call.
agreementId String
Returns:
AgreementTransactions
Throws:
com.paypal.base.rest.PayPalRESTException
	public static AgreementTransactions transactions(APIContext apiContextString agreementIdDate startDateDate endDatethrows PayPalRESTException {
		if (apiContext == null) {
			throw new IllegalArgumentException("APIContext cannot be null");
		}
		if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) {
			throw new IllegalArgumentException("AccessToken cannot be null or empty");
		}
		if (apiContext.getHTTPHeaders() == null) {
			apiContext.setHTTPHeaders(new HashMap<StringString>());
		}
		if (startDate == null) {
			throw new IllegalArgumentException("startDate cannot be null");
		}
		if (endDate == null) {
			throw new IllegalArgumentException("endDate cannot be null");
		}
		apiContext.setSdkVersion(new SDKVersionImpl());
		if (agreementId == null) {
			throw new IllegalArgumentException("agreementId cannot be null");
		}
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String sDate = dateFormat.format(startDate);
		String eDate = dateFormat.format(endDate);
		Object[] parameters = new Object[] {agreementIdsDateeDate};
		String pattern = "v1/payments/billing-agreements/{0}/transactions?start_date={1}&end_date={2}";
		String resourcePath = RESTUtil.formatURIPath(patternparameters);
		String payLoad = "";
		return configureAndExecute(apiContext.resourcePathpayLoadAgreementTransactions.class);
	}
New to GrepCode? Check out our FAQ X