@RequiredArgsConstructor
public class Authorize {
private final PayPalCheckoutTransactionService payPalCheckoutTransactionService;
public void performAuthorization() {
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.ORDER_ID, "paypal_order_id")
.tenantId("TENANT"); // Declare the tenant id to help identify where transaction results should be recorded
PaymentResponse paymentResponse = payPalCheckoutTransactionService.authorize(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.
paymentResponse.getResponseMap().get(MessageConstants.AUTHORIZATION_ID); // PayPal Authorization ID used for subsequent transactions.
}
}