Broadleaf Microservices
  • v1.0.0-latest-prod

Braintree Capture Transaction

Prerequisites

Set up your environment as described in the Environment Setup Guide

Executing a Capture Transaction

Note
Braintree only supports executing a single partial capture transaction. Therefore, if a partial capture is executed, the remaining authorized amount will be automatically voided.

Use the following code snippet to perform a Capture transaction:

public class Capture {

 @Autowired
 BraintreeTransactionService braintreeTransactionService;

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

		 PaymentRequest paymentRequest = new PaymentRequest()
		        .additionalField("TRANSACTION_ID", transactionId) // The Braintree transaction id gathered from the Authorize transaction.
		        .transactionTotal(transactionTotal);

	 	PaymentResponse paymentResponse = braintreeTransactionService.capture(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.
	}
}