Broadleaf Microservices
  • v1.0.0-latest-prod

Checkout Authorize Transaction

Prerequisites

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

Executing an Authorize Transaction

Authorize transactions can be performed using either a card token (i.e. a short-lived, single-use token) or a Source ID (i.e. a multi-use token).

Note
A Source ID can be created by exchanging a single-use token when creating a SavedPaymentMethod in PaymentTransactionServices, or by executing a transaction using the single-use token.

Authorize Transaction using Token

Use the following code snippet to perform an Authorize transaction with a token:

@RequiredArgsConstructor
public class Authorize {

 private final CheckoutComTransactionService checkoutComTransactionService;

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

	 	PaymentResponse paymentResponse = checkoutComTransactionService.authorize(paymentRequest);

		paymentResponse.isSuccessful();
		paymentResponse.getGatewayResponseCode(); //Checkout.com Response Code
		paymentResponse.getFailureType(); // Failure type in case the transaction was not successful.
	   	paymentResponse.getRawResponse(); // Checkout.com raw response stored as a JSON object.
        paymentResponse.getResponseMap().get(CheckoutConstants.PAYMENT_ID); // Checkout.com Payment ID used for subsequent transactions.
        paymentResponse.getPaymentMethodProperties().get(CheckoutConstants.SOURCE_ID); // Source ID to be used in place of card token.
	}
}

Authorize Transaction using Source ID

Use the following code snippet to perform an Authorize transaction with a multi-use token (i.e. the Source ID):

@RequiredArgsConstructor
public class Authorize {

 private final CheckoutComTransactionService checkoutComTransactionService;

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

		 PaymentRequest paymentRequest = new PaymentRequest()
		        .transactionReferenceId(transactionReferenceId)// This is the Transaction Reference ID
		        .transactionTotal(transactionTotal)
		        .additionalField(CheckoutConstants.SOURCE_ID, sourceId);
	 	PaymentResponse paymentResponse = checkoutComTransactionService.authorize(paymentRequest);

		paymentResponse.isSuccessful();
		paymentResponse.getGatewayResponseCode(); //Checkout.com Response Code
		paymentResponse.getFailureType(); // Failure type in case the transaction was not successful.
	   	paymentResponse.getRawResponse(); // Checkout.com raw response stored as a JSON object.
        paymentResponse.getResponseMap().get(CheckoutConstants.PAYMENT_ID); // Checkout.com Payment ID used for subsequent transactions.
	}
}

Use following Payment Request fields to enable 3DS.

PaymentRequest paymentRequest = new PaymentRequest()
            .additionalField(CheckoutConstants.THREE_D_SECURE_ENABLED, true)
            .additionalField(CheckoutConstants.SUCCESS_URL, "http://example.com/payments/success")
            .additionalField(CheckoutConstants.FAILURE_URL, "http://example.com/payments/fail");

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

For more details on the Authorize transaction request & response parameters, refer to the Checkout.Com API Reference.