Broadleaf Microservices
  • v1.0.0-latest-prod

Tabby Refund Transaction

Prerequisites

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

Executing a Refund Transaction

Note
Initiate a refund of Tabby payment in full or partially. You can only refund the payment that has been Captured and Closed. By default, refunds reflect instantly, which means Tabby updates the billed amount and initiates a refund through the payment gateway. Optionally, 'Delayed Refunds' enabled - this means there is a 24 hours gap between the moment when Refund API is called and when it is actually performed. During this time the refund can be canceled. Another refund for the same payment ID cannot be processed until the 1st one is either processed or deleted.
@RequiredArgsConstructor
public class Refund {

 private final TabbyTransactionService tabbyTransactionService;

 public void performRefund() {
		 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.refund(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
	}
}