Reverse-Authorize transactions can only be performed using an Authorization ID retrieved from Authorize transaction.
Use the following code snippet to perform a Reverse-Authorize transaction:
@RequiredArgsConstructor
public class ReverseAuthorize {
private final PayPalCheckoutTransactionService payPalCheckoutTransactionService;
public void reverseAuthorize() {
CurrencyUnit currency = Monetary.getCurrency(currencyCode);
MonetaryAmount transactionTotal = Monetary.getDefaultAmountFactory().setCurrency(currency).setNumber(amount).create();
PaymentRequest paymentRequest = new PaymentRequest()
.transactionReferenceId(transactionReferenceId)// this is the unique Transaction Reference ID
.transactionTotal(transactionTotal)
.additionalField(MessageConstants.AUTHORIZATION_ID, "paypal_authorization_id") // This is the Authorization ID retrieved from Authorize transaction
.tenantId("TENANT"); // Declare the tenant id to help identify where transaction results should be recorded
PaymentResponse paymentResponse = payPalCheckoutTransactionService.reverseAuthorize(paymentRequest);
paymentResponse.isSuccessful();
paymentResponse.getGatewayResponseCode(); //PayPal 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()
To get the Broadleaf Payment ID from the response:
PaymentResponse.getPaymentId()
For more details on the Reverse Authorize transaction request & response parameters, refer to the PayPal API Reference.