availability

Braintree Auth is in closed beta. To request access, email auth@braintreepayments.com.

Once you have an $accessToken, you are ready to perform actions on behalf of that merchant.

The API is slightly different than how it looks for a merchant performing their own actions using API keys. The primary difference is a gateway object must be constructed with an access token. Secondly, all API calls must be done through the gateway object, instead of using the class methods.

See below for a few key examples but a full translation of class methods is available in the reference.

Creating a transaction

This is how to create a transaction using an access token:

PHP
Click to copy
Copied
$gateway = new Braintree_Gateway([
    'accessToken' => useAccessTokenForMerchant,
]);

$result = $gateway->transaction()->sale([
  'amount' => '100.00',
  'paymentMethodNonce' => nonceFromTheClient
]);

$transactionId = $result->transaction->id;

Creating a customer

Here's how you would create a customer for a merchant:

PHP
Click to copy
Copied
$gateway = new Braintree_Gateway([
    'accessToken' => useAccessTokenForMerchant,
]);

$result = $gateway->customer()->create([
    'firstName' => 'Joe',
    'lastName' => 'Brown',
    'email' => 'joe@example.com',
    'phone' => '312-555-1234',
]);

$customerId = $result->customer->id;

Authentication errors

The merchant has the right to revoke an authorization grant at any time. If this occurs, you will receive a Braintree_Exception_Authentication when attempting to take any action on the merchant’s behalf.

Next: Multi-currency →

Still have questions?

If you can’t find an answer, contact our Support team.