Broadleaf Microservices
  • v1.0.0-latest-prod

APS Authorize Transaction

Prerequisites

Before performing an Authorize transaction with the Amazon Payment Services gateway, you’ll first need to set up your environment as described in the Environment Setup Guide.

Executing an Authorize Transaction

Use the following code snippet to perform an Authorize transaction:

public class Authorize {

 @Autowired
 APSTransactionService apsTransactionService;

 public void performAuthorization() {

		 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
		        .customer()
		        .customerId("1")
		        .email("test@test.com")
		        .done()
		        .transactionTotal(transactionTotal)
		        .additionalField(MessageConstants.APS_TOKEN_NAME, tokenName)
		        .additionalField(MessageConstants.APS_LANGUAGE, "en") // If not set here, the default language will be gathered from broadleaf.amazonpaymentservices.default-language
		        .additionalField(MessageConstants.APS_CHECK_3DS, "NO"); // Set this parameter to "YES" to enable 3DS verificati

	 	PaymentResponse paymentResponse = apsTransactionService.authorize(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 Authorize transaction request & response parameters, refer to the Amazon Payment Services documentation.