Broadleaf Microservices
  • v1.0.0-latest-prod

Tabby Capture Transaction

Prerequisites

Set up your environment as described in the Environment Setup Guide

Executing a Capture Transaction

Note
When a payment status changes to Authorized, you perform a capture request. When you capture the full amount, the payment will be automatically closed. If only a part of the payment is captured, the payment will remain Authorized until the rest of the amount is Captured or Closed. The payment can be Closed by executing the Reverse Authorization transaction.

Use the following code snippet to perform a Capture transaction:

@RequiredArgsConstructor
public class Capture {

 private final TabbyTransactionService tabbyTransactionService;

 public void performCapture() {

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

		 PaymentRequest paymentRequest = new PaymentRequest()
                .transactionTotal(transactionTotal)
		        .transactionReferenceId(transactionReferenceId)
                .tenantId(tenantId)
                .applicationId(applicationId)
		        .additionalField("payment_id", paymentId); // The Tabby payment id gathered from the Authorize transaction.

	 	PaymentResponse paymentResponse = tabbyTransactionService.capture(paymentRequest);

		paymentResponse.isSuccessful();
		paymentResponse.getFailureType(); // Failure type in case the transaction was not successful
	   	paymentResponse.getRawResponse(); // Tabby raw response stored as a String
		paymentResponse.getGatewayTransactionId(); // the gateway transaction id
		paymentResponse.getResponseMap().get("payment_id"); // Tabby payment id
	   	paymentResponse.getResponseMap().get("payment_status"); // Tabby payment status
	}
}