Broadleaf Microservices
  • v1.0.0-latest-prod

Checkout Refund Transaction

Prerequisites

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

Executing a Refund Transaction

Use the following code snippet to perform a Refund transaction using the store credit account’s account number:

@RequiredArgsConstructor
public class Refund {

 private final StoreCreditTransactionService storeCreditTransactionService;

 public void performRefund() {
		 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(StoreCreditMessageConstants.CREDIT_ACCOUNT_NUMBER, accountNumber)
                .tenantId("TENANT"); // Declare the tenant id to help identify where transaction results should be recorded

	 	PaymentResponse paymentResponse = storeCreditTransactionService.refund(paymentRequest);

		paymentResponse.isSuccessful();
		paymentResponse.getGatewayResponseCode(); //Broadleaf Store Credit Response Code
		paymentResponse.getFailureType(); // Failure type in case the transaction was not successful.
	   	paymentResponse.getRawResponse(); // Broadleaf Store Credit raw response stored as a JSON object.
	}
}

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()