Fastlane

Server-side

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

Important

You must include your root domain in the client token request. Omitting the root domain will cause Fastlane to malfunction and will prevent it from working entirely.

  1. Ruby
require 'braintree'

@braintree_gateway ||= Braintree::Gateway.new(
  environment: :sandbox,
  merchant_id: '<BRAINTREE_MERCHANT_ID>',
  public_key: '<BRAINTREE_PUBLIC_KEY>',
  private_key: '<BRAINTREE_PRIVATE_KEY>'
)

# pass client_token to your front-end
@client_token = gateway.client_token.generate(
    :domains => ['example.com', 'example2.com']
)
Using Braintree GraphQL
  1. Graphql
mutation ($input: CreateClientTokenInput) {
  createClientToken(input: $input) {
    clientToken
  }
}
  1. Graphql
{
  "input": {
    "clientToken": {
      "domains": [ "example.com" ]
    }
  }
}
  • 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, "https://example.com/")
  • Error Handling: If you specify subdomains, wildcards, or protocols, the system will generate an error.

Step 2: Update Fastlane with Consumer's shipping addressAnchorIcon

After generating a Fastlane token, if you're processing a payment, make sure to include the customer's shipping address in the request.This ensures the address is saved to their Fastlane profile for future use.

Field nameDescriptionLink
shipping The shipping address collected for a customer's order. Link


  1. Ruby
require 'braintree'
def get_braintree_gateway
  @braintree_gateway ||= Braintree::Gateway.new(
    environment: :sandbox,
    merchant_id: '<BRAINTREE_MERCHANT_ID>',
    public_key: '<BRAINTREE_PUBLIC_KEY>',
    private_key: '<BRAINTREE_PRIVATE_KEY>'
  )
end
def do_POST(request, response)
  data = JSON.parse(request.body)
  email = data['email']
  name = data['name']
  shipping_address = data['shippingAddress']
  payment_token = data['paymentToken']
  device_data = data['deviceData']
  result = get_braintree_gateway.transaction.sale(
    amount: '10.00',
    payment_method_nonce: payment_token['id'],
    device_data: device_data,
    options: {
      submit_for_settlement: true
    }
  )
  response.status = 201
  response.content_type = 'application/json'
  response.body = {
    result: {
      success: result.success?,
      transaction: { id: result.transaction.id }
    }
  }.to_json
end
Using Braintree GraphQLAnchorIcon
  1. Graphql
mutation ($input: ChargeCreditCardInput!) {
  chargeCreditCard(input: $input) {
    transaction {
      id
      legacyId
      createdAt
      amount {
        value
        currencyCode
      }
      status
    }
  }
}
  1. Graphql
{
  input: {
    paymentMethodId: payment_token['id'],
    transaction: {
      amount: '1.00',
      riskData: { deviceData: device_data },
      shipping: {
        shippingAddress: shipping_address,
        shippingMethod: 'GROUND'
      },
      customerDetails: { email: email },
      vaultPaymentMethodAfterTransacting: {
        when: 'ON_SUCCESSFUL_TRANSACTION'
      }
    },
    options: {
      billingAddress: payment_token['paymentSource']['card']['billingAddress']
    }
  }
}

Next step: Test your integration