### Braintree Gateway Quick Start Example Source: https://github.com/braintree/braintree_java/blob/master/README.md This example demonstrates how to initialize the Braintree Gateway and process a transaction. Ensure you replace placeholder keys with your actual credentials. It handles successful transactions and displays error details if the sale fails. ```java 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")) .paymentMethodNonce(nonceFromTheClient) .options() .submitForSettlement(true) .done(); Result result = gateway.transaction().sale(request); if (result.isSuccess()) { Transaction transaction = result.getTarget(); System.out.println("Success!: " + transaction.getId()); } else if (result.getTransaction() != null) { 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 { for (ValidationError error : result.getErrors().getAllDeepValidationErrors()) { System.out.println("Attribute: " + error.getAttribute()); System.out.println(" Code: " + error.getCode()); System.out.println(" Message: " + error.getMessage()); } } } } ``` -------------------------------- ### Java Webhook Integration Example Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/webhook-notification-gateway.md This example demonstrates how to set up a Java Servlet to handle incoming webhook notifications. It includes parsing the signature and payload, verifying the challenge for GET requests, and processing different types of webhook events. ```java import com.braintreegateway.*; import javax.servlet.http.*; public class WebhookServlet extends HttpServlet { private BraintreeGateway gateway; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String signature = request.getParameter("bt_signature"); String payload = request.getParameter("bt_payload"); try { WebhookNotification notification = gateway.webhookNotification() .parse(signature, payload); handleWebhook(notification); response.setStatus(200); } catch (InvalidSignatureException e) { response.setStatus(403); response.getWriter().write("Signature verification failed"); } } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String token = request.getParameter("bt_challenge"); try { String verifiedToken = gateway.webhookNotification().verify(token); response.getWriter().write(verifiedToken); response.setStatus(200); } catch (InvalidSignatureException e) { response.setStatus(403); } } private void handleWebhook(WebhookNotification notification) { switch (notification.getKind()) { case TRANSACTION_SETTLED: Transaction transaction = notification.getTransaction(); System.out.println("Transaction settled: " + transaction.getId()); break; case SUBSCRIPTION_CHARGED_SUCCESSFULLY: Subscription subscription = notification.getSubscription(); System.out.println("Subscription charged: " + subscription.getId()); break; case DISPUTE_OPENED: Dispute dispute = notification.getDispute(); System.out.println("Dispute opened for: " + dispute.getTransactionDetails().getId()); break; default: System.out.println("Webhook: " + notification.getKind()); } } } ``` -------------------------------- ### Initialization and Configuration Options Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/COMPLETION_SUMMARY.txt Guide to initializing the SDK and configuring its options. ```APIDOC ## Initialization and Configuration Options ### Description Instructions on how to initialize the Braintree Java SDK and configure various options for your integration. ### Endpoint Refer to `/output/configuration.md` for detailed setup and configuration options. ``` -------------------------------- ### Initialize Braintree Client and Hosted Fields Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/client-token-gateway.md Example of initializing the Braintree client and setting up Hosted Fields on the client-side using JavaScript. This requires a client token obtained from your server. ```javascript // Get client token from your server fetch('/client-token') .then(response => response.json()) .then(data => { // Initialize Braintree client braintree.client.create({ authorization: data.clientToken }, function(err, clientInstance) { if (err) { console.error('Error:', err); return; } // Hosted Fields or Drop-in Hosted Pages braintree.hostedFields.create({ client: clientInstance, fields: { number: { selector: '#card-number' }, expirationDate: { selector: '#expiration' }, cvv: { selector: '#cvv' } } }, function(err, hostedFieldsInstance) { // Handle form submission }); }); }); ``` -------------------------------- ### Transaction Search Example Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/transaction-gateway.md Illustrates how to construct a transaction search request with filters for amount, creation date, and status, then iterates through the results. ```java TransactionSearchRequest searchRequest = new TransactionSearchRequest() .amount().is(new BigDecimal("100.00")) .createdAt().min(Calendar.getInstance()) .status().is(Transaction.Status.SETTLED); ResourceCollection results = gateway.transaction().search(searchRequest); for (Transaction txn : results) { System.out.println("Found transaction: " + txn.getId()); } ``` -------------------------------- ### Sale Transaction Example Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/transaction-gateway.md Demonstrates how to create a sale transaction with options like submitting for settlement and handling the result, including success and error cases. ```java TransactionRequest saleRequest = new TransactionRequest() .amount(new BigDecimal("100.00")) .paymentMethodNonce("nonce_from_client") .orderId("order_456") .options() .submitForSettlement(true) .done(); Result result = gateway.transaction().sale(saleRequest); if (result.isSuccess()) { Transaction transaction = result.getTarget(); System.out.println("Transaction ID: " + transaction.getId()); System.out.println("Status: " + transaction.getStatus()); } else if (result.getTransaction() != null) { Transaction failedTxn = result.getTransaction(); System.out.println("Processor response: " + failedTxn.getProcessorResponseCode()); } else { for (ValidationError error : result.getErrors().getAllDeepValidationErrors()) { System.out.println("Validation error: " + error.getMessage()); } } ``` -------------------------------- ### Get Plan Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a PlanGateway for managing subscription plans. ```java public PlanGateway plan() ``` -------------------------------- ### Get Discount Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a DiscountGateway for managing discounts. ```java public DiscountGateway discount() ``` -------------------------------- ### customer() Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a CustomerGateway for managing customers. Includes an example of creating a customer. ```APIDOC ## customer() ### Description Returns a `CustomerGateway` for managing customers. ### Method ```java public CustomerGateway customer() ``` ### Returns `CustomerGateway` ### Example ```java CustomerGateway customerGateway = gateway.customer(); Result result = customerGateway.create(customerRequest); ``` ``` -------------------------------- ### Submit for Settlement Example Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/transaction-gateway.md Demonstrates submitting an authorized transaction for settlement and checking the success of the operation. ```java Result result = gateway.transaction().submitForSettlement("authorized_txn_id"); if (result.isSuccess()) { System.out.println("Transaction submitted for settlement"); } ``` -------------------------------- ### Get Subscription Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a SubscriptionGateway for managing subscriptions. ```java public SubscriptionGateway subscription() ``` -------------------------------- ### Complete Transaction Request Example Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/transaction-request.md This snippet demonstrates how to build a comprehensive TransactionRequest object for a sale, including all core fields, payment method details, order information, itemized breakdowns, billing and shipping addresses, settlement options, and custom fields. It also shows how to submit the request and process the result. ```java import com.braintreegateway.*; import java.math.BigDecimal; TransactionRequest request = new TransactionRequest() // Core transaction .amount(new BigDecimal("99.99")) .type(Transaction.Type.SALE) // Payment method .paymentMethodNonce("nonce_from_client") .customerId("customer_123") // Order details .orderId("order_001") .currencyIsoCode("USD") // Breakdown .taxAmount(new BigDecimal("7.99")) .shippingAmount(new BigDecimal("5.00")) .discountAmount(new BigDecimal("0.00")) // Addresses .billingAddress() .firstName("John") .lastName("Doe") .streetAddress("123 Main St") .city("Chicago") .state("IL") .postalCode("60622") .done() .shippingAddress() .firstName("John") .lastName("Doe") .streetAddress("456 Oak Ave") .city("New York") .state("NY") .postalCode("10001") .done() // Options .options() .submitForSettlement(true) .skipAdvancedFraudChecking(false) .done() // Custom fields .customField("internal_id", "12345"); Result result = gateway.transaction().sale(request); if (result.isSuccess()) { Transaction transaction = result.getTarget(); System.out.println("Transaction: " + transaction.getId()); System.out.println("Amount: " + transaction.getAmount()); System.out.println("Status: " + transaction.getStatus()); } ``` -------------------------------- ### CustomerRequest Constructor Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/customer-request.md Creates a new empty customer request object. This is the starting point for building a customer request. ```APIDOC ## Constructor CustomerRequest ### Description Creates a new empty customer request. ### Method Signature ```java public CustomerRequest() ``` ``` -------------------------------- ### Create Empty CustomerRequest Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/customer-request.md Use the default constructor to create a new, empty customer request object. This is the starting point for building a customer request. ```java public CustomerRequest() ``` -------------------------------- ### Get AddOn Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Use this method to obtain an AddOnGateway for interacting with add-on objects. ```java AddOnGateway addOnGateway = gateway.addOn(); ``` -------------------------------- ### transaction() Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a TransactionGateway for managing transactions. Includes an example of performing a sale. ```APIDOC ## transaction() ### Description Returns a `TransactionGateway` for managing transactions. ### Method ```java public TransactionGateway transaction() ``` ### Returns `TransactionGateway` ### Example ```java TransactionGateway transactionGateway = gateway.transaction(); Result result = transactionGateway.sale(transactionRequest); ``` ``` -------------------------------- ### Get BankAccountInstantVerificationGateway Java Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a BankAccountInstantVerificationGateway for bank account instant verification. This is used for immediate verification of bank accounts. ```java public BankAccountInstantVerificationGateway bankAccountInstantVerification() ``` -------------------------------- ### Using 3D Secure in Transactions Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/three-d-secure-gateway.md This snippet demonstrates how to integrate 3D Secure data when creating a transaction. It first performs a lookup to get the necessary 3D Secure information and then includes the authentication ID in the transaction request for a secure sale. ```APIDOC ## Using 3D Secure in Transactions This section details how to incorporate 3D Secure data when creating transactions. It involves a two-step process: first, performing a lookup to obtain 3D Secure information, and second, using the obtained authentication ID in the transaction request. ### Workflow 1. **Lookup**: Initiate a lookup request with payment details (nonce, amount, account ID). 2. **Transaction Creation**: If the lookup is successful and 3D Secure is required, create a transaction request including the `threeDSecureAuthenticationId` obtained from the lookup and set `threeDSecureTransaction` to true. ### Code Example (Java) ```java // Initialize lookup request ThreeDSecureLookupRequest lookupRequest = new ThreeDSecureLookupRequest() .nonce("payment_nonce") .amount(new BigDecimal("100.00")) .accountId("account_123"); // Perform lookup Result lookupResult = gateway.threeDSecure().lookup(lookupRequest); // Process lookup result if (lookupResult.isSuccess()) { ThreeDSecureLookup lookup = lookupResult.getTarget(); // Initialize transaction request with 3DS data TransactionRequest transactionRequest = new TransactionRequest() .amount(new BigDecimal("100.00")) .paymentMethodNonce("payment_nonce") .threeDSecureAuthenticationId(lookup.getThreeDSecureInfo().getThreeDSecureAuthenticationId()) .threeDSecureTransaction(true); // Submit transaction Result result = gateway.transaction().sale(transactionRequest); if (result.isSuccess()) { System.out.println("3DS Transaction: " + result.getTarget().getId()); } } ``` ``` -------------------------------- ### Example: Transaction with Inline Credit Card Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/transaction-request.md Demonstrates constructing a transaction request using inline credit card details, including number, expiration, and CVV. The `.done()` method finalizes the credit card details and returns to the TransactionRequest builder. ```java TransactionRequest request = new TransactionRequest() .amount(new BigDecimal("100.00")) .creditCard() .number("4111111111111111") .expirationMonth("12") .expirationYear("2025") .cvv("123") .done(); ``` -------------------------------- ### Get 3D Secure Pass-Thru Builder Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/transaction-request.md Use threeDSecurePassThru() to obtain a builder for manually providing 3D Secure data. ```java public TransactionThreeDSecurePassThruRequest threeDSecurePassThru() ``` -------------------------------- ### Initialize Braintree Gateway with Configuration Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/configuration.md Demonstrates how to initialize the Braintree gateway with environment, merchant ID, public key, and private key. It also shows how to configure timeouts and set up a proxy. ```java import com.braintreegateway.*; public class BraintreeConfig { public static void main(String[] args) { // Initialize with standard credentials BraintreeGateway gateway = new BraintreeGateway( Environment.SANDBOX, "your_merchant_id", "your_public_key", "your_private_key" ); // Configure additional options Configuration config = gateway.getConfiguration(); config.setTimeout(120000); // 2-minute timeout config.setConnectTimeout(30000); // 30-second connect timeout // Set up proxy if needed gateway.setProxy("proxy.example.com", 8080); // Now gateway is ready to use System.out.println("Connected to: " + gateway.getConfiguration().getEnvironment()); } } ``` -------------------------------- ### Get ExchangeRateQuoteGateway Java Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns an ExchangeRateQuoteGateway for getting exchange rate quotes. This gateway is GraphQL-based and used for retrieving currency exchange rate information. ```java public ExchangeRateQuoteGateway exchangeRateQuote() ``` -------------------------------- ### Example: Voiding a Transaction Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/transaction-gateway.md Demonstrates how to void a transaction using the Braintree Java SDK. Check the result for success or failure. ```java Result result = gateway.transaction().void("authorized_txn_id"); if (result.isSuccess()) { System.out.println("Transaction voided"); } ``` -------------------------------- ### Get Billing Address Request Builder Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/transaction-request.md Use the `billingAddress()` method to get a builder for setting inline billing address details for a transaction. This is useful for specifying a billing address directly within the transaction request. ```java public TransactionAddressRequest billingAddress() ``` -------------------------------- ### Create Subscription Using a Plan Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/plan-gateway.md Demonstrates how to create a subscription by first finding a plan and then using its ID and price in a SubscriptionRequest. The plan's price can optionally be overridden. ```java Plan plan = gateway.plan().find("monthly_plan_id"); SubscriptionRequest request = new SubscriptionRequest() .planId(plan.getId()) .paymentMethodToken("card_token_123") .price(plan.getPrice()); // Optional: override plan price Result result = gateway.subscription().create(request); if (result.isSuccess()) { Subscription subscription = result.getTarget(); System.out.println("Subscription created: " + subscription.getId()); System.out.println("Plan: " + subscription.getPlanId()); System.out.println("Next billing date: " + subscription.getNextBillingDate()); } ``` -------------------------------- ### Get UsBankAccountVerificationGateway Java Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a UsBankAccountVerificationGateway for US bank account verification. Use this for verifying the authenticity of US bank accounts. ```java public UsBankAccountVerificationGateway usBankAccountVerification() ``` -------------------------------- ### Get OAuth Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns an OAuthGateway for OAuth operations. ```java public OAuthGateway oauth() ``` -------------------------------- ### Get Dispute Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a DisputeGateway for managing disputes. ```java public DisputeGateway dispute() ``` -------------------------------- ### List All Available Plans (Common Use Case) Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/plan-gateway.md A common use case for listing all plans, iterating through them, and printing their IDs and prices. ```java Collection plans = gateway.plan().all(); for (Plan plan : plans) { System.out.println(plan.getId() + " - $" + plan.getPrice()); } ``` -------------------------------- ### exchangeRateQuote() Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns an ExchangeRateQuoteGateway for getting exchange rate quotes (GraphQL-based). ```APIDOC ## exchangeRateQuote() ### Description Returns an `ExchangeRateQuoteGateway` for getting exchange rate quotes (GraphQL-based). ### Method ```java public ExchangeRateQuoteGateway exchangeRateQuote() ``` ### Returns `ExchangeRateQuoteGateway` ``` -------------------------------- ### Get ThreeDSecure Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a ThreeDSecureGateway for 3D Secure operations. ```java public ThreeDSecureGateway threeDSecure() ``` -------------------------------- ### Create Customer with Credit Card and Billing Address Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/customer-request.md This snippet demonstrates creating a customer along with their credit card details and billing address. It's useful when you need to associate payment information directly during customer creation. ```java CustomerRequest request = new CustomerRequest() .firstName("Jane") .lastName("Smith") .email("jane@example.com") .phone("5559876543") .creditCard() .number("4111111111111111") .expirationMonth("12") .expirationYear("2025") .cvv("123") .billingAddress() .streetAddress("123 Main St") .city("Chicago") .state("IL") .postalCode("60622") .done() .done(); Result result = gateway.customer().create(request); if (result.isSuccess()) { Customer customer = result.getTarget(); System.out.println("Customer: " + customer.getId()); System.out.println("Cards: " + customer.getCreditCards().size()); } ``` -------------------------------- ### Get SettlementBatchSummary Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a SettlementBatchSummaryGateway for settlement batch summaries. ```java public SettlementBatchSummaryGateway settlementBatchSummary() ``` -------------------------------- ### Allow User to Choose and Create Subscription (with Error Handling) Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/plan-gateway.md A function to create a subscription for a chosen plan, including error handling for cases where the plan is not found. ```java public void createSubscriptionForPlan(String planId, String paymentMethodToken) { try { Plan plan = gateway.plan().find(planId); SubscriptionRequest request = new SubscriptionRequest() .planId(plan.getId()) .paymentMethodToken(paymentMethodToken); Result result = gateway.subscription().create(request); if (result.isSuccess()) { System.out.println("Subscription created for plan: " + planId); } else { System.out.println("Failed to create subscription"); } } catch (NotFoundException e) { System.out.println("Plan not found: " + planId); } } ``` -------------------------------- ### Initialize BraintreeGateway with String Environment Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/configuration.md This constructor allows initializing the BraintreeGateway using a string representation of the environment (e.g., "sandbox", "production"). It requires the environment string, merchant ID, public key, and private key. ```java BraintreeGateway gateway = new BraintreeGateway( String environment, String merchantId, String publicKey, String privateKey ); ``` -------------------------------- ### Create a Customer Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/README.md Register a new customer with their first name, last name, and email. The result will contain the customer's ID upon successful creation. ```java CustomerRequest request = new CustomerRequest() .firstName("John") .lastName("Doe") .email("john@example.com"); Result result = gateway.customer().create(request); if (result.isSuccess()) { Customer customer = result.getTarget(); System.out.println("Customer ID: " + customer.getId()); } ``` -------------------------------- ### Get PayPalAccount Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a PayPalAccountGateway for managing PayPal accounts. ```java public PayPalAccountGateway paypalAccount() ``` -------------------------------- ### Get PaymentMethod Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a PaymentMethodGateway for managing payment methods. ```java public PaymentMethodGateway paymentMethod() ``` -------------------------------- ### Display Plan Details to User Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/plan-gateway.md Iterates through all available plans and formats their details, including ID, price, billing period, and description, for user display. ```java Collection plans = gateway.plan().all(); System.out.println("Available Plans:"); for (Plan plan : plans) { System.out.println(" " + plan.getId()); System.out.println(" Price: $" + plan.getPrice() + "/" + getBillingPeriodText(plan.getBillingFrequency(), plan.getBillingPeriod())); System.out.println(" Description: " + plan.getDescription()); } ``` -------------------------------- ### Get MerchantAccount Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a MerchantAccountGateway for managing merchant accounts. ```java public MerchantAccountGateway merchantAccount() ``` -------------------------------- ### Braintree Gateway Initialization Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/COMPLETION_SUMMARY.txt Details on how to initialize the Braintree Gateway, including different constructor patterns. ```APIDOC ## BraintreeGateway Initialization ### Description Provides information on initializing the Braintree Gateway. Supports multiple constructor patterns for flexible setup. ### Usage Refer to `configuration.md` for detailed setup and initialization options. ``` -------------------------------- ### Braintree Gateway Initialization and Transaction Sale Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Demonstrates how to initialize the Braintree Gateway with sandbox credentials and process a payment transaction using a client-provided nonce. Includes error handling for failed sales. ```java import com.braintreegateway.*; import java.math.BigDecimal; public class PaymentExample { public static void main(String[] args) { // Initialize gateway BraintreeGateway gateway = new BraintreeGateway( Environment.SANDBOX, "merchant_id", "public_key", "private_key" ); // Create a transaction TransactionRequest request = new TransactionRequest() .amount(new BigDecimal("10.00")) .paymentMethodNonce("nonce_from_client") .orderId("order_123"); Result result = gateway.transaction().sale(request); if (result.isSuccess()) { Transaction transaction = result.getTarget(); System.out.println("Sale successful: " + transaction.getId()); } else { System.out.println("Sale failed"); for (ValidationError error : result.getErrors().getAllDeepValidationErrors()) { System.out.println("Validation error: " + error.getMessage()); } } } } ``` -------------------------------- ### Get CreditCard Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a CreditCardGateway for managing credit cards. ```java public CreditCardGateway creditCard() ``` -------------------------------- ### Create Customer with Full Details Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/customer-request.md Use this snippet to create a new customer with comprehensive personal and contact information. It includes setting first name, last name, email, phone, fax, company, website, and custom fields. ```java import com.braintreegateway.*; // Create a new customer CustomerRequest request = new CustomerRequest() .firstName("John") .lastName("Doe") .email("john@example.com") .phone("5551234567") .fax("5551234568") .company("Acme Corp") .website("https://example.com") .customField("account_type", "premium"); Result result = gateway.customer().create(request); if (result.isSuccess()) { Customer customer = result.getTarget(); System.out.println("Customer created: " + customer.getId()); } else { for (ValidationError error : result.getErrors().getAllDeepValidationErrors()) { System.out.println("Error: " + error.getMessage()); } } ``` -------------------------------- ### Get Address Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns an AddressGateway for interacting with customer addresses. ```java public AddressGateway address() ``` -------------------------------- ### Initialize BraintreeGateway with Standard Credentials Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Use this constructor to initialize the BraintreeGateway with standard merchant credentials. Ensure you provide the correct environment, merchant ID, public key, and private key. ```java BraintreeGateway gateway = new BraintreeGateway( Environment.SANDBOX, "merchant_id_123", "public_key_abc", "private_key_xyz" ); ``` -------------------------------- ### Get TransactionLineItem Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a TransactionLineItemGateway for managing transaction line items. ```java public TransactionLineItemGateway transactionLineItem() ``` -------------------------------- ### BraintreeGateway (Standard Initialization) Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Instantiates a Braintree Gateway client using standard merchant credentials, including environment, merchant ID, public key, and private key. ```APIDOC ## BraintreeGateway (Standard Initialization) ### Description Instantiates a gateway with standard merchant credentials. ### Method `public BraintreeGateway(Environment environment, String merchantId, String publicKey, String privateKey)` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Parameters * **environment** (Environment) - Required - Either `Environment.SANDBOX` or `Environment.PRODUCTION` * **merchantId** (String) - Required - The merchant ID provided by Braintree * **publicKey** (String) - Required - The public key provided by Braintree * **privateKey** (String) - Required - The private key provided by Braintree ### Request Example ```java BraintreeGateway gateway = new BraintreeGateway( Environment.SANDBOX, "merchant_id_123", "public_key_abc", "private_key_xyz" ); ``` ``` -------------------------------- ### Initialize Braintree Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/README.md Instantiate the BraintreeGateway object with your sandbox credentials. Ensure you replace the placeholder values with your actual merchant ID, public key, and private key. ```java import com.braintreegateway.*; import java.math.BigDecimal; // Create gateway instance BraintreeGateway gateway = new BraintreeGateway( Environment.SANDBOX, "your_merchant_id", "your_public_key", "your_private_key" ); ``` -------------------------------- ### Get PayPalPaymentResource Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a PayPalPaymentResourceGateway for managing PayPal payment resources. ```java public PayPalPaymentResourceGateway paypalPaymentResource() ``` -------------------------------- ### Get PaymentMethodNonce Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a PaymentMethodNonceGateway for managing payment method nonces. ```java public PaymentMethodNonceGateway paymentMethodNonce() ``` -------------------------------- ### Get CreditCardVerification Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a CreditCardVerificationGateway for credit card verification operations. ```java public CreditCardVerificationGateway creditCardVerification() ``` -------------------------------- ### Create and Add Address to Customer Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/address-gateway.md Demonstrates how to create a customer and then add an address to that customer using the Braintree Java SDK. Includes finding the added address. ```java CustomerRequest custRequest = new CustomerRequest() .firstName("John") .lastName("Doe"); Result custResult = gateway.customer().create(custRequest); String customerId = custResult.getTarget().getId(); AddressRequest addrRequest = new AddressRequest() .firstName("John") .lastName("Doe") .streetAddress("123 Main St") .city("Chicago") .state("IL") .postalCode("60622") .countryCodeAlpha2("US"); Result
addrResult = gateway.address().create(customerId, addrRequest); if (addrResult.isSuccess()) { Address address = addrResult.getTarget(); System.out.println("Address ID: " + address.getId()); Address found = gateway.address().find(customerId, address.getId()); System.out.println("Found: " + found.getCity() + ", " + found.getState()); } ``` -------------------------------- ### Create a Subscription Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/subscription-gateway.md Use this method to create a new subscription with specified plan, payment method, and price. It returns the created subscription or validation errors. ```java SubscriptionRequest subRequest = new SubscriptionRequest() .planId("plan_123") .paymentMethodToken("card_token_123") .price(new BigDecimal("29.99")); Result result = gateway.subscription().create(subRequest); if (result.isSuccess()) { Subscription subscription = result.getTarget(); System.out.println("Subscription created: " + subscription.getId()); System.out.println("Status: " + subscription.getStatus()); } else { for (ValidationError error : result.getErrors().getAllDeepValidationErrors()) { System.out.println("Error: " + error.getMessage()); } } ``` -------------------------------- ### Get CustomerSession Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a CustomerSessionGateway for managing customer sessions (GraphQL-based). ```java public CustomerSessionGateway customerSession() ``` -------------------------------- ### Initialize BraintreeGateway with Standard Merchant Authentication Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/configuration.md Use this constructor to initialize the BraintreeGateway with an Environment enum, merchant ID, public key, and private key. Ensure you use the correct environment (SANDBOX or PRODUCTION). ```java BraintreeGateway gateway = new BraintreeGateway( Environment environment, String merchantId, String publicKey, String privateKey ); ``` -------------------------------- ### Build Braintree Java SDK Source: https://github.com/braintree/braintree_java/blob/master/DEVELOPMENT.md Run this command to build the Braintree Java SDK. It utilizes the Makefile and Dockerfile to set up dependencies and provide a terminal for further actions. ```shell make ``` -------------------------------- ### Get SepaDirectDebitAccount Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a SepaDirectDebitAccountGateway for managing SEPA Direct Debit accounts. ```java public SepaDirectDebitAccountGateway sepaDirectDebitAccount() ``` -------------------------------- ### Generate Token for New Customer Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/client-token-gateway.md Use this to generate a client token for a new customer. Send the token to the client to collect payment information. ```java String clientToken = gateway.clientToken().generate(); // Send to client to collect payment information for new customer ``` -------------------------------- ### Get Merchant Gateway (Deprecated) Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a MerchantGateway. This method is deprecated and will be removed in a future version. ```java @Deprecated public MerchantGateway merchant() ``` -------------------------------- ### Get LocalPaymentContext Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a LocalPaymentContextGateway for creating and managing local payment contexts (GraphQL-based). ```java public LocalPaymentContextGateway localPaymentContext() ``` -------------------------------- ### Initialize BraintreeGateway with OAuth Client Credentials Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/configuration.md Use this constructor for OAuth authentication with client ID and client secret. The environment is embedded within the client ID string. ```java BraintreeGateway gateway = new BraintreeGateway( String clientId, String clientSecret ); ``` -------------------------------- ### plan() Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a PlanGateway for managing subscription plans. ```APIDOC ## plan() ### Description Returns a `PlanGateway` for managing subscription plans. ### Method ```java public PlanGateway plan() ``` ### Returns `PlanGateway` ``` -------------------------------- ### Get ClientToken Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a ClientTokenGateway for generating client tokens used in client-side integrations. ```java public ClientTokenGateway clientToken() ``` -------------------------------- ### Retrieving Request Parameters Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/result.md Use getParameters() to get a map of the parameters that were submitted with a failed request. ```java public Map getParameters() ``` -------------------------------- ### Run Unit Tests with Maven Source: https://github.com/braintree/braintree_java/blob/master/DEVELOPMENT.md Use this Maven command to execute unit tests, skipping integration tests. This is a standard way to verify code correctness without external dependencies. ```shell mvn verify -DskipITs ``` -------------------------------- ### addOn() Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns an AddOnGateway for interacting with add-on objects. ```APIDOC ## addOn() ### Description Returns an `AddOnGateway` for interacting with add-on objects. ### Method ```java public AddOnGateway addOn() ``` ### Returns `AddOnGateway` ``` -------------------------------- ### Get Descriptor Builder Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/transaction-request.md Use descriptor() to obtain a builder for configuring the transaction's billing descriptor. ```java public TransactionDescriptorRequest descriptor() ``` -------------------------------- ### Retrieve All Subscription Plans Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/plan-gateway.md Fetches all available subscription plans for the merchant. Useful for displaying plan options to users. ```java Collection allPlans = gateway.plan().all(); for (Plan plan : allPlans) { System.out.println("Plan: " + plan.getId()); System.out.println(" Price: " + plan.getPrice()); System.out.println(" Billing Frequency: " + plan.getBillingFrequency()); } ``` -------------------------------- ### Run Checkstyle for Linting Source: https://github.com/braintree/braintree_java/blob/master/DEVELOPMENT.md Execute this Maven command to run Checkstyle with the Google Java Style configuration. View the linting results in your browser at the specified path. ```shell mvn site ``` -------------------------------- ### Get Transaction Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Use this method to obtain a TransactionGateway for managing transaction objects. It can be used to perform sales. ```java TransactionGateway transactionGateway = gateway.transaction(); Result result = transactionGateway.sale(transactionRequest); ``` -------------------------------- ### Get Customer Gateway Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Use this method to obtain a CustomerGateway for managing customer objects. It can be used to create customers. ```java CustomerGateway customerGateway = gateway.customer(); Result result = customerGateway.create(customerRequest); ``` -------------------------------- ### Create a Transaction Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/README.md Initiate a sale transaction with specified amount, payment method nonce, and order ID. Check the result for success or failure to handle the transaction outcome. ```java TransactionRequest request = new TransactionRequest() .amount(new BigDecimal("10.00")) .paymentMethodNonce("nonce_from_client") .orderId("order_123"); Result result = gateway.transaction().sale(request); if (result.isSuccess()) { Transaction transaction = result.getTarget(); System.out.println("Success: " + transaction.getId()); } else { System.out.println("Error"); } ``` -------------------------------- ### Configuration Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/README.md Provides options for configuring the Braintree SDK, including initialization with API credentials. ```APIDOC ## Configuration ### Description Configuration options and initialization for the Braintree SDK. ### Usage Configure the SDK with your Braintree API credentials before making any gateway calls. ``` -------------------------------- ### Create Braintree Gateway for Partner Use Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Instantiates a BraintreeGateway object specifically for partner integrations. Requires environment details, partner ID, and Braintree public/private keys. ```java public static BraintreeGateway forPartner(Environment environment, String partnerId, String publicKey, String privateKey) ``` -------------------------------- ### Get ReportGateway Java Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a ReportGateway for generating reports. This gateway is GraphQL-based and used for creating various financial reports. ```java public ReportGateway report() ``` -------------------------------- ### Accessing Braintree Gateways Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/INDEX.md Demonstrates how to access specific gateway services like transactions, customers, and credit cards through the main BraintreeGateway instance. Ensure BraintreeGateway is initialized before use. ```java BraintreeGateway gateway = new BraintreeGateway(...); // Access specific gateway gateway.transaction().sale(request); gateway.customer().create(request); gateway.creditCard().find(token); // etc. ``` -------------------------------- ### Get DocumentUploadGateway Java Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a DocumentUploadGateway for uploading documents. Use this when you need to upload files or documents through the Braintree API. ```java public DocumentUploadGateway documentUpload() ``` -------------------------------- ### Get WebhookTestingGateway Java Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a WebhookTestingGateway for generating webhook test data. This is useful for simulating webhook events during testing. ```java public WebhookTestingGateway webhookTesting() ``` -------------------------------- ### Iterating Through Paginated Search Results Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/types.md Demonstrates how to use ResourceCollection to iterate through paginated search results. ```java ResourceCollection results = gateway.transaction().search(query); for (Transaction txn : results) { // Process each transaction } ``` -------------------------------- ### Get WebhookNotificationGateway Java Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a WebhookNotificationGateway for parsing webhook notifications. Use this to process incoming webhook events from Braintree. ```java public WebhookNotificationGateway webhookNotification() ``` -------------------------------- ### Create Customer Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/customer-gateway.md Creates a new customer record with the provided details. Handles success and validation errors. ```java CustomerRequest customerRequest = new CustomerRequest() .firstName("John") .lastName("Doe") .email("john@example.com") .phone("5551234567") .company("Acme Corp"); Result result = gateway.customer().create(customerRequest); if (result.isSuccess()) { Customer customer = result.getTarget(); System.out.println("Customer created with ID: " + customer.getId()); } else { for (ValidationError error : result.getErrors().getAllDeepValidationErrors()) { System.out.println("Error: " + error.getMessage()); } } ``` -------------------------------- ### Configure HTTP Proxy by URL and Port Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/configuration.md Configures an HTTP proxy for all gateway requests using the proxy's URL and port number. Both parameters are required. ```java gateway.setProxy("proxy.company.com", 8080); ``` -------------------------------- ### discount() Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a DiscountGateway for managing discounts. ```APIDOC ## discount() ### Description Returns a `DiscountGateway` for managing discounts. ### Method ```java public DiscountGateway discount() ``` ### Returns `DiscountGateway` ``` -------------------------------- ### Set Connection Establishment Timeout Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/configuration.md Sets the timeout for establishing a new connection in milliseconds. The default is 10000 milliseconds (10 seconds). ```java public void setConnectTimeout(Integer timeout) ``` -------------------------------- ### Get Gateway Configuration Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Retrieves the current Configuration object used by the Braintree Gateway instance. This is useful for inspecting or modifying gateway settings. ```java public Configuration getConfiguration() ``` -------------------------------- ### all() Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/customer-gateway.md Retrieves all customers in a paginated collection. ```APIDOC ## all() ### Description Retrieves all customers in a paginated collection. ### Method GET ### Endpoint /customers ### Returns `ResourceCollection` — Paginated collection of all customers ### Example ```java ResourceCollection allCustomers = gateway.customer().all(); for (Customer customer : allCustomers) { System.out.println("Customer: " + customer.getFirstName() + " " + customer.getLastName()); } ``` ``` -------------------------------- ### Get UsBankAccountGateway Java Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a UsBankAccountGateway for managing US bank accounts. Use this when you need to interact with US bank account functionalities. ```java public UsBankAccountGateway usBankAccount() ``` -------------------------------- ### Generate a basic client token Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/client-token-gateway.md Use this method to generate a general-purpose client token. This token is then sent to your client-side application. ```java String clientToken = gateway.clientToken().generate(); System.out.println("Client token: " + clientToken); // Send this token to your client-side application ``` -------------------------------- ### Initialize BraintreeGateway with OAuth Access Token Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/configuration.md Initialize the BraintreeGateway using an OAuth access token. The access token string must include the environment and merchant ID. ```java BraintreeGateway gateway = new BraintreeGateway( String accessToken ); ``` -------------------------------- ### Get Customer Request Builder Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/transaction-request.md Call `customer()` on a `TransactionRequest` to obtain a builder for setting customer details. This is typically used when creating a new transaction with associated customer information. ```java public CustomerRequest customer() ``` -------------------------------- ### Retrieving Plan Details Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/result.md Use getPlan() to access Plan objects if they are present in the result. ```java public Plan getPlan() ``` -------------------------------- ### Get Shipping Address Request Builder Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/transaction-request.md Call `shippingAddress()` to retrieve a builder for specifying inline shipping address details for a transaction. This method is used when the shipping address is not a pre-saved customer address. ```java public TransactionAddressRequest shippingAddress() ``` -------------------------------- ### BraintreeGateway (String Environment) Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Instantiates a Braintree Gateway client using a string to specify the environment along with merchant credentials. ```APIDOC ## BraintreeGateway (String Environment) ### Description Same as above but accepts environment as a string ("sandbox", "production", "development", "qa"). ### Method `public BraintreeGateway(String environment, String merchantId, String publicKey, String privateKey)` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Parameters * **environment** (String) - Required - Environment name: "sandbox", "production", "development", or "qa" * **merchantId** (String) - Required - The merchant ID provided by Braintree * **publicKey** (String) - Required - The public key provided by Braintree * **privateKey** (String) - Required - The private key provided by Braintree ``` -------------------------------- ### create(CustomerRequest request) Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/customer-gateway.md Creates a new customer record with the provided details. ```APIDOC ## create(CustomerRequest request) ### Description Creates a new customer record. ### Method POST ### Endpoint /customers ### Parameters #### Request Body - **request** (CustomerRequest) - Required - Request containing customer details ### Returns `Result` — The created customer or validation errors ### Example ```java CustomerRequest customerRequest = new CustomerRequest() .firstName("John") .lastName("Doe") .email("john@example.com") .phone("5551234567") .company("Acme Corp"); Result result = gateway.customer().create(customerRequest); if (result.isSuccess()) { Customer customer = result.getTarget(); System.out.println("Customer created with ID: " + customer.getId()); } else { for (ValidationError error : result.getErrors().getAllDeepValidationErrors()) { System.out.println("Error: " + error.getMessage()); } } ``` ``` -------------------------------- ### Run Unit Tests with Rake Source: https://github.com/braintree/braintree_java/blob/master/DEVELOPMENT.md This command runs unit tests using Rake. It's an alternative to Maven for executing the test suite. ```shell rake test:unit ``` -------------------------------- ### Set Transaction Options Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/transaction-request.md Use the options() builder to configure transaction-level settings like submission for settlement, fraud checking, and AVS/CVV verification. ```java TransactionRequest request = new TransactionRequest() .amount(new BigDecimal("100.00")) .paymentMethodNonce("nonce") .options() .submitForSettlement(true) .skipAdvancedFraudChecking(false) .skipAvs(false) .skipCvv(false) .done(); ``` -------------------------------- ### Result Class Constructors Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/result.md Demonstrates the different ways to instantiate a Result object: empty, with a target object, or with validation errors. ```java public Result() ``` ```java public Result(T target) ``` ```java public Result(ValidationErrors errors) ``` -------------------------------- ### Constructing a Transaction Request Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/INDEX.md Demonstrates the fluent builder pattern for creating a TransactionRequest. Use this pattern to set transaction details and options in a single, chained expression. ```java TransactionRequest request = new TransactionRequest() .amount(new BigDecimal("100.00")) .paymentMethodNonce("nonce") .options() .submitForSettlement(true) .done(); ``` -------------------------------- ### Iterate Search Results in Java Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/README.md This pattern demonstrates how to iterate through a collection of resources returned by a search query. ```java ResourceCollection results = gateway.transaction().search(query); for (Transaction txn : results) { System.out.println(txn.getId()); } ``` -------------------------------- ### Plan Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/types.md Represents a subscription plan. ```APIDOC ## Plan ### Description Represents a subscription plan. ### Properties | Property | Type | Description | |---|---|---| | `id` | String | Plan identifier | | `price` | BigDecimal | Recurring billing amount | | `billingFrequency` | Integer | How often to bill (in units defined by billingPeriod) | | `billingPeriod` | Integer | Unit of time for billing (e.g., month) | | `currencyIsoCode` | String | Currency code (e.g., "USD") | | `description` | String | Plan description | | `createdAt` | Calendar | When the plan was created | | `updatedAt` | Calendar | When the plan was last updated | ### Methods - `getId()`: Returns the plan identifier. - `getPrice()`: Returns the recurring billing amount. - `getBillingFrequency()`: Returns how often to bill. - `getBillingPeriod()`: Returns the unit of time for billing. - `getCurrencyIsoCode()`: Returns the currency ISO code. - `getDescription()`: Returns the plan description. - `getCreatedAt()`: Returns the creation timestamp of the plan. - `getUpdatedAt()`: Returns the last update timestamp of the plan. ``` -------------------------------- ### Configure Braintree Gateway Environment Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/README.md Instantiate the BraintreeGateway with the desired environment. Supports Environment enum or string representation. ```java BraintreeGateway gateway = new BraintreeGateway(Environment.SANDBOX, ...); ``` ```java BraintreeGateway gateway = new BraintreeGateway(Environment.PRODUCTION, ...); ``` ```java BraintreeGateway gateway = new BraintreeGateway("sandbox", ...); ``` -------------------------------- ### Client Token Generation Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/COMPLETION_SUMMARY.txt Information on generating client tokens for client-side integration. ```APIDOC ## Client Token Generation ### Description Provides methods for generating client tokens, which are essential for client-side integrations with Braintree. ### Methods - Generate client token ### Endpoint Refer to `api-reference/client-token-gateway.md` for detailed endpoint information. ``` -------------------------------- ### Handle ConfigurationException Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/errors.md Catch ConfigurationException when the gateway is not configured properly, such as missing merchant ID. ```java try { BraintreeGateway gateway = new BraintreeGateway( Environment.SANDBOX, null, // Missing merchant ID "public_key", "private_key" ); } catch (ConfigurationException e) { System.out.println("Configuration error: " + e.getMessage()); } ``` -------------------------------- ### options() Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/transaction-request.md Provides access to the TransactionOptionsRequest builder for configuring transaction-specific options. ```APIDOC ## options() ### Description Returns builder for transaction options. ### Method Not applicable (Java method) ### Endpoint Not applicable (Java method) ### Parameters None ### Request Example ```java TransactionRequest request = new TransactionRequest() .amount(new BigDecimal("100.00")) .paymentMethodNonce("nonce") .options() .submitForSettlement(true) .skipAdvancedFraudChecking(false) .skipAvs(false) .skipCvv(false) .done(); ``` ### Response `TransactionOptionsRequest` — Options builder ``` -------------------------------- ### Set Customer Website Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/customer-request.md Use the `website` method to set the customer's website URL. This method is part of the fluent API and returns the `CustomerRequest` object. ```java public CustomerRequest website(String website) ``` -------------------------------- ### Create Transaction with Pass-Through 3D Secure Data Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/three-d-secure-gateway.md This snippet demonstrates how to include pass-through 3D Secure data when creating a transaction. Use this for manual 3D Secure handling where you have already collected ECI, CAVV, and XID values. ```java TransactionRequest request = new TransactionRequest() .amount(new BigDecimal("100.00")) .paymentMethodNonce("payment_nonce") .threeDSecurePassThru() .eciFlag("05") .cavv("cavity_value") .xid("transaction_id") .done(); Result result = gateway.transaction().sale(request); ``` -------------------------------- ### Generate Token with Custom Options Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/client-token-gateway.md Generate a client token with custom options, such as making it the default payment method or skipping advanced fraud checking. ```java ClientTokenRequest tokenRequest = new ClientTokenRequest() .customerId("customer_123") .options() .makeDefault(true) .skipAdvancedFraudChecking(false) .done(); String clientToken = gateway.clientToken().generate(tokenRequest); ``` -------------------------------- ### localPaymentContext() Source: https://github.com/braintree/braintree_java/blob/master/_autodocs/api-reference/braintree-gateway.md Returns a LocalPaymentContextGateway for creating and managing local payment contexts (GraphQL-based). ```APIDOC ## localPaymentContext() ### Description Returns a `LocalPaymentContextGateway` for creating and managing local payment contexts (GraphQL-based). ### Method ```java public LocalPaymentContextGateway localPaymentContext() ``` ### Returns `LocalPaymentContextGateway` ```