Server-side
Step 1: Generate client token
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
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.
- 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','example2.com'],
}, (error, response) => {
if (error) {
// handle the error
return;
}
// pass the clientToken to your front-end
clientToken = response.clientToken;
});
- Graphql
mutation ($input: CreateClientTokenInput) {
createClientToken(input: $input) {
clientToken
}
}
- 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 address
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 name | Description | Link |
---|---|---|
shipping | The shipping address collected for a customer's order. | Link |
- 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);
}
});
- Graphql
mutation ($input: ChargeCreditCardInput!) {
chargeCreditCard(input: $input) {
transaction {
id
legacyId
createdAt
amount {
value
currencyCode
}
status
}
}
}
- Graphql
{
input: {
paymentMethodId: paymentToken.id,
transaction: {
amount: '1.00',
riskData: { deviceData },
shipping: {
shippingAddress,
shippingMethod: 'GROUND',
},
customerDetails: { email },
vaultPaymentMethodAfterTransacting: {
when: 'ON_SUCCESSFUL_TRANSACTION',
},
},
options: {
billingAddress: paymentToken.paymentSource.card.billingAddress,
},
},