@RequiredArgsConstructor
public class AuthorizeAndCapture {
private final CheckoutComTransactionService checkoutComTransactionService;
public void performAuthorizationAndCapture() {
CurrencyUnit currency = Monetary.getCurrency(currencyCode);
MonetaryAmount transactionTotal = Monetary.getDefaultAmountFactory().setCurrency(currency).setNumber(amount).create();
PaymentRequest paymentRequest = new PaymentRequest()
.transactionReferenceId(transactionReferenceId)// this is a unique Transaction Reference ID
.transactionTotal(transactionTotal)
.additionalField(CheckoutConstants.SOURCE_ID, sourceId);
PaymentResponse paymentResponse = checkoutComTransactionService.authorizeAndCapture(paymentRequest);
paymentResponse.isSuccessful();
paymentResponse.getGatewayResponseCode(); //Checkout.com Response Code
paymentResponse.getFailureType(); // Failure type in case the transaction was not successful.
paymentResponse.getRawResponse(); // Checkout.com raw response stored as a JSON object.
paymentResponse.getResponseMap().get(CheckoutConstants.PAYMENT_ID); // Checkout.com Payment ID used for subsequent transactions.
paymentResponse.isAwaitingAsyncResults(); // If true, Checkout.com will return detailed response about the Capture portion of the interaction via Webhook
}
}