Broadleaf Microservices
  • v1.0.0-latest-prod

Braintree AuthAndCapture Transaction

Prerequisites

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

Executing an AuthAndCapture Transaction

@RequiredArgsConstructor
public class AuthAndCapture {

 private final BraintreeTransactionService braintreeTransactionService;

 public void performAuthorization() {
		 MonetaryAmount transactionTotal = Monetary.getDefaultAmountFactory().setNumber(amount).create();

		 PaymentRequest paymentRequest = new PaymentRequest()
		        .transactionReferenceId(transactionReferenceId)
		        .transactionTotal(transactionTotal)
		        .additionalField("nonce", nonce); // The nonce which we got from Braintree Client Integration (Drop-in call).

	 	PaymentResponse paymentResponse = braintreeTransactionService.authorizendCapture(paymentRequest);

		paymentResponse.isSuccessful();
		paymentResponse.getGatewayResponseCode(); // The Braintree response code
		paymentResponse.getFailureType(); // Failure type in case the transaction was not successful.
	   	paymentResponse.getRawResponse(); // Braintree raw response stored as a JSON object.
		paymentResponse.getGatewayTransactionId(); // gatewayTransaction Id from Braintree.
		paymentResponse.getGatewayTransactionType(); // Braintree gateway transaction type.
		paymentResponse.getResponseMap().get("TRANSACTION_ID"); // Braintree transaction Id. This value is used to execute subsequent transactions.
	   	paymentResponse.getResponseMap().get("TRANSACTION_STATUS"); // Braintree transaction status.
	}
}

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