Use the following code snippet to perform a Reverse Authorization transaction:
public class ReverseAuthorization {
@Autowired
APSTransactionService apsTransactionService;
public void performReverseAuthorization() {
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
.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)))