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.
- C#
package com.fastlane.braintreesdksample.sample;
import com.braintreegateway.BraintreeGateway;
import com.braintreegateway.ClientTokenRequest;
import com.braintreegateway.Environment;
public class GenerateClientTokenExample {
private final BraintreeGateway gateway;
public GenerateClientTokenExample() {
// Initialize the Braintree gateway with your credentials
this.gateway = new BraintreeGateway(
Environment.SANDBOX,
"<BRAINTREE_MERCHANT_ID>",
"<BRAINTREE_PUBLIC_KEY>",
"<BRAINTREE_PRIVATE_KEY>"
);
}
public static void main(String[] args) {
ClientTokenRequest clientTokenRequest = new ClientTokenRequest().domains(domains);
String clientToken = gateway.clientToken().generate(clientTokenRequest);
System.out.println("Generated Client Token: " + 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 |
- C#
using Braintree;
public class MakeTransactionExample
{
private static BraintreeGateway gateway;
public MakeTransactionExample()
{
// Initialize Braintree Gateway
this.gateway = new BraintreeGateway
{
Environment = Braintree.Environment.SANDBOX, // or Braintree.Environment.PRODUCTION for production,
MerchantId = "<BRAINTREE_MERCHANT_ID>",
PublicKey = "<BRAINTREE_PUBLIC_KEY>",
PrivateKey = "<BRAINTREE_PRIVATE_KEY>"
};
}
public static void Main(string[] args)
{
// Create a transaction request
var transactionRequest = new TransactionRequest {
Amount = 10.00M,
PaymentMethodNonce = requestBody.PaymentToken.Id,
DeviceData = requestBody.DeviceData,
Customer = new CustomerRequest {
FirstName = requestBody.Name?.FirstName,
LastName = requestBody.Name?.LastName,
Email = requestBody.Email
},
BillingAddress = requestBody.PaymentToken.BillingAddress,
ShippingAddress = requestBody.ShippingAddress != null ?
requestBody.ShippingAddress : null
};
// Create the transaction
Result<Transaction> result = this.gateway.Transaction.Sale(transactionRequest);
// Check if the transaction was successful
if (result.IsSuccess())
{
Console.WriteLine("Transaction ID: " + result.Target.Id);
}
else
{
Console.WriteLine("Error: " + result.Message);
}
}
}
- Graphql
mutation ($input: ChargeCreditCardInput!) {
chargeCreditCard(input: $input) {
transaction {
id
status
}
}
}
- Graphql
mutation ($input: ChargeCreditCardInput!) {
chargeCreditCard(input: $input) {
transaction {
id
status
}
}
}