We decided to build an app for the Node.js Knockout that will give us a head start on developing one of our most requested features: push notifications of gateway activity. Check out PushRelay and vote for us in the Node Knockout!
Java Client Library
Braintree provides an open source jar to integrate with the Braintree Gateway.
Download
braintree-java-2.5.0.jar
SHA1: c2190451998cdf2ff71b8050922f6656abb0d901
Updates
Current version: 2.5.0. Released August 19, 2010.
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
Importing Certificates
In rare cases, your server may not already be configured with the proper certificates. If you’re seeing SSL errors when attempting to connect, you can verify that you don’t have the SecureTrust CA file with:
keytool -list -v -keystore $JAVA_HOME/lib/security/cacerts | grep SecureTrust
If your $JAVA_HOME environment variable is not set, you can get the value that Java is using by compiling and running this small program:
class Properties {
public static void main(String[] args) {
System.out.println(System.getProperty("java.home"));
}
}
If you don’t see any output from the above keytool command, you can download the SecureTrust CA File and install it with:
keytool -import -alias SecureTrust -file securetrust_ca.crt -keystore $JAVA_HOME/lib/security/cacerts
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());
}
}
}
}