Java Client Library
Braintree provides an open source jar to integrate with the Braintree Gateway.
Download
braintree-java-2.13.4.jar
SHA1: e624ba4d01539a3b3dc7fe988b6452d9aad371e8
Updates
Current version: 2.13.4. Released February 01, 2012.
For details on what changed see the change log. If we deprecate any functionality we’ll add updating instructions to the deprecations page.
Fill out this form to receive an email when we update the Java library.
Source Code
Integration Examples
Bugs
If you run into a bug, email us at support@getbraintree.com or create an issue on the github issue tracker.
Quick Start Example
import java.math.BigDecimal;
import com.braintreegateway.*;
public class BraintreeExample {
public static void main(String[] args) {
BraintreeGateway gateway = new BraintreeGateway(
Environment.SANDBOX,
"the_merchant_id",
"the_public_key",
"the_private_key"
);
TransactionRequest request = new TransactionRequest().
amount(new BigDecimal("1000.00")).
creditCard().
number("4111111111111111").
expirationDate("05/2009").
done();
Result<Transaction> result = gateway.transaction().sale(request);
if (result.isSuccess()) {
Transaction transaction = result.getTarget();
System.out.println("Success!: " + transaction.getId());
} else if (result.getTransaction() != null) {
System.out.println("Message: " + result.getMessage());
Transaction transaction = result.getTransaction();
System.out.println("Error processing transaction:");
System.out.println(" Status: " + transaction.getStatus());
System.out.println(" Code: " + transaction.getProcessorResponseCode());
System.out.println(" Text: " + transaction.getProcessorResponseText());
} else {
System.out.println("Message: " + result.getMessage());
for (ValidationError error : result.getErrors().getAllDeepValidationErrors()) {
System.out.println("Attribute: " + error.getAttribute());
System.out.println(" Code: " + error.getCode());
System.out.println(" Message: " + error.getMessage());
}
}
}
}