Skip to content

Instantly share code, notes, and snippets.

@jaypatel512
Created July 7, 2016 15:45
Show Gist options
  • Save jaypatel512/a4dbd47325f7153de27c422bf8ded0e4 to your computer and use it in GitHub Desktop.
Save jaypatel512/a4dbd47325f7153de27c422bf8ded0e4 to your computer and use it in GitHub Desktop.
// ### Create Patch Request
List<Patch> patchRequest = new ArrayList<Patch>();
// ### Amount
// Let's update the payment amount as an example.
Amount amount = new Amount();
amount.setCurrency("USD");
// Total must be equal to sum of shipping, tax and subtotal.
amount.setTotal("17.50");
amount.setDetails(new Details().setShipping("11.50").setTax("1")
.setSubtotal("5"));
// ### Patch Object
// Create a patch object, and fill these 3 properties accordingly.
Patch patch1 = new Patch();
patch1.setOp("replace").setPath("/transactions/0/amount").setValue(amount);
patchRequest.add(patch1);
try {
// ### Api Context
// Pass in a `ApiContext` object to authenticate
// the call and to send a unique request id
// (that ensures idempotency). The SDK generates
// a request id if you do not pass one explicitly.
APIContext apiContext = new APIContext(clientID, clientSecret, mode);
// Create a payment by posting to the APIService
// using a valid AccessToken
// The return object contains the status;
payment.update(apiContext, patchRequest);
LOGGER.info("Updated Payment with " + payment.getId());
return true;
} catch (PayPalRESTException e) {
System.out.println(e.getDetails());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment