Broadleaf Microservices
  • v1.0.0-latest-prod

APS Reverse Authorization Transaction

Prerequisites

Before performing a Reverse Authorization transaction with the PayPal Payment Services gateway, you’ll first need to set up your environment as described in the Environment Setup Guide.

Executing a Reverse Authorization Transaction

Use the following code snippet to perform a Reverse Authorization transaction:

public class ReverseAuthorization {

 @Autowired
 PayPalCheckoutTransactionService transactionService;

 public void performReverseAuthorization() {

		 CurrencyUnit currency = Monetary.getCurrency(currencyCode);
		 MonetaryAmount transactionTotal = Monetary.getDefaultAmountFactory().setCurrency(currency).setNumber(amount).create();

		 PaymentRequest paymentRequest = new PaymentRequest()
                .paymentId(paymentId)
                .transactionTotal(transactionTotal)
                .orderSubtotal(transactionTotal)
		        .paymentOwnerType("BLC_CART")
		        .paymentOwnerId(cartId)
		        .additionalField(MessageConstants.AUTHORIZATIONID, "AuthorizationId")
                .transactionReferenceId(transactionReferenceId);

	 	PaymentResponse paymentResponse = transactionService.reverseAuthorize(paymentRequest);

		paymentResponse.isSuccessful();
		paymentResponse.getGatewayResponseCode(); //PayPa Response Code
		paymentResponse.getFailureType(); // Failure type in case the transaction was not successful.
	   	paymentResponse.getRawResponse(); // PayPal Raw response stored as a JSON object
	}
}

To set additional fields in the PaymentRequest, use method

PaymentRequest.additionalField(key, value)

To get values from responseMap, use

PaymentResponse.getResponseMap().get(key, value)

To get the transaction reference ID from response:

PaymentResponse.getTransactionReferenceId()