Broadleaf Microservices
  • v1.0.0-latest-prod

Checkout Capture Transaction

Prerequisites

Before performing a Capture transaction with the Checkout.com gateway, you’ll first need to set up your environment as described in the Environment Setup Guide.

Executing a Capture Transaction

Capture transaction can only be performed using the Payment ID retrieved from Authorize transaction.

Use the following code snippet to perform a Capture transaction:

@RequiredArgsConstructor
public class Capture {

 private final CheckoutComTransactionService checkoutComTransactionService;

 public void performCapture() {
		 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(CheckoutConstants.PAYMENT_ID, paymentId) // This is the Payment ID retrieved from Authorize transaction
                .tenantId("TENANT"); // Declare the tenant id to help identify where transaction results should be recorded

	 	PaymentResponse paymentResponse = checkoutComTransactionService.capture(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.
        paymentResponse.isAwaitingAsyncResults(); // If true, Checkout.com will return detailed response via Webhook
	}
}

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 Capture transaction request & response parameters, refer to the Checkout.Com API Reference.