Fastlane

Server-side Transaction

Step 1: Generate client tokenAnchorIcon

To get started, generate a client token. If you use Braintree's GraphQL API on your server, refer to the GraphQL Documentation.

Using Braintree SDK

  1. node.js
import braintree from 'braintree';

let gateway;
let clientToken;

gateway = new braintree.BraintreeGateway({
    environment: braintree.Environment.Sandbox,
    merchantId: BRAINTREE_MERCHANT_ID,
    privateKey: BRAINTREE_PRIVATE_KEY,
    publicKey: BRAINTREE_PUBLIC_KEY,
});

gateway.clientToken.generate({
    domains: ['example.com'],
}, (error, response) => {
    if (error) {
        // handle the error
        return;
    }
    // pass the clientToken to your front-end
    clientToken = response.clientToken;
});
Using Braintree GraphQL
  1. Graphql
mutation ($input: CreateClientTokenInput) {
    createClientToken(input: $input) {
        clientToken
    }
}
  1. Graphql
{
    "input": {
        "clientToken": {
            "domains": [
                "example.com"
            ]
        }
    }
}
  • After the client token is generated, you can pass it into the client SDK.
  • Send a domain name in the client token generate call: When generating a client token, you need to send a domain name where Fastlane will be displayed to customers to protect against cross-site scripting attacks.
  • Provide the root domain name: You must provide the base or root domain name, such as "Example Domain".
  • If you specify subdomains, wildcards, or protocols, the system will generate an error.
  • Restrictions on Domain Names:
    • No Subdomains: Do not specify subdomains (for example, "sub.example.com").
    • No Wildcards: Do not use wildcard characters (for example, "*.example.com").
    • No Protocols: Do not include HTTP or HTTPS protocols in the domain name (for example,"Example Domain")
  • Error Handling: If you specify subdomains, wildcards, or protocols, the system will generate an error.

Step 2: Create server-side API request to complete transactionAnchorIcon

On your server, you need to create a transaction using the paymentToken generated on your client and either the Braintree GraphQL API or one of the server-side SDKs.

Required Fields When creating the transaction request server-side, the following fields are required:

Field nameDescriptionLink
shipping Shipping information is required to be passed only if you are collecting it on your end. If not, no need to pass. The shipping object contains fields related to the payer’s shipping address. Link
payment_method_nonceA single-use reference to payment information provided by the payer on the client.Link

Along with the required fields, here is a table of fields which we strongly recommend passing in the server-side transaction API request.

Recommended fields for server-side API request:

Field nameDescriptionLink to documentation
device_dataAn identifier that helps prevent fraud and ensures the highest authorization rates.Link
billingThe billing object contains fields related to the payer’s billing information.Link
customer.firstNameThe payer’s first name.Link
customer.lastNameThe payer’s last name.Link
customer.emailThe payer’s email address.Link
  1. node.js
gateway.transaction.sale({
    amount: "10.00",
    paymentMethodNonce: nonceFromTheClient,
    deviceData: deviceDataFromTheClient,
    customer: {
        firstName: "Drew",
        lastName: "Smith",
        email: "drew@example.com",
    },
    billing: {
        firstName: "Paul",
        lastName: "Smith",
        company: "Braintree",
        streetAddress: "1 E Main St",
        extendedAddress: "Suite 403",
        locality: "Chicago",
        region: "IL", //must be sent in 2-letter format
        postalCode: "60622", // you can also use the countryCodeAlpha3 or countryCodeNumeric formats
        countryCodeAlpha2: "US",
    },
    shipping: {
        firstName: "Jen",
        lastName: "Smith",
        company: "Braintree",
        streetAddress: "1 E 1st St",
        extendedAddress: "5th Floor",
        locality: "Bartlett",
        region: "IL", //must be sent in 2-letter format
        postalCode: "60103", // you can also use the countryCodeAlpha3 or countryCodeNumeric formats
        countryCodeAlpha2: "US",
        phoneNumber: "14155551212",
        shippingMethod: "ground",
    },
}, (error, result) => {
    if (error) {
        console.error(error);
        return;
    }

    if (result.success) {
        console.log("Transaction ID: " + result.transaction.id);
    } else {
        console.error(result.message);
    }
});
Using Braintree GraphQL
  1. Graphql
mutation ($input: ChargeCreditCardInput!) {
  chargeCreditCard(input: $input) {
    transaction {
      id
      status
    }
  }
}
  1. Graphql
mutation ($input: ChargeCreditCardInput!) {
  chargeCreditCard(input: $input) {
    transaction {
      id
      status
    }
  }
}
Next step: Test your integration

If you accept cookies, we’ll use them to improve and customize your experience and enable our partners to show you personalized PayPal ads when you visit other sites. Manage cookies and learn more