Broadleaf Microservices
  • v1.0.0-latest-prod

APS Refund Transaction

Prerequisites

Before performing a Refund transaction with the Amazon Payment Services gateway, 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:

public class Refund {

 @Autowired
 APSTransactionService apsTransactionService;

 public void performRefund() {

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

		 PaymentRequest paymentRequest = new PaymentRequest()
		        .transactionReferenceId(merchantReference)// this is merchant reference ID, same that is used to perform Authorize transaction
		        .additionalField(MessageConstants.APS_FORT_ID, fortId)// fortId returned from Authorize transaction. This is optional
		        .transactionTotal(transactionTotal)
		        .additionalField(MessageConstants.APS_LANGUAGE, "en"); // If not set here, the default language will be gathered from broadleaf.amazonpaymentservices.default-language

	 	PaymentResponse paymentResponse = apsTransactionService.refund(paymentRequest);

		paymentResponse.isSuccessful();
		paymentResponse.getGatewayResponseCode(); //APS Response Code
		paymentResponse.getFailureType(); // Failure type in case the transaction was not successful.
	  	paymentResponse.getResponseMap().get(MessageConstants.APS_RESPONSE_MESSAGE); // APS API Response Message
	   	paymentResponse.getRawResponse(); // APS 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 merchant reference ID from response:

PaymentResponse.getPaymentId()

To get fort ID from response:

PaymentResponse.responseMap(MessageConstants.APS_FORT_ID, String.valueOf(response.get(MessageConstants.APS_FORT_ID)))

For more details on the Refund transaction request & response parameters, refer to the Amazon Payment Services documentation.