Braintree for Paypal Client_Token

Paypal integration now required Braintree SDK, to use the Braintree SDK, you will require the Client_Token generate from the server.

What is Client Token?

A client token is a signed data blob that includes configuration and authorization information required by the Braintree client SDK. These should not be reused; a new client token should be generated for each request that’s sent to Braintree. For security, we will revoke client tokens if they are reused excessively within a short time period.

Your server is responsible for generating the client token, which contains all of the necessary configuration information to set up the client SDKs. When your server provides a client token to your client, it authenticates the application to communicate directly to Braintree.

How to create the server-side client token generator using PHP? Here some easy and straight forward codes you can use.

P/S: this code work for me, if you have simple easier and better please share.

First of all, you need to download the PHP Library from Braintree Developer site
https://developers.braintreepayments.com/start/hello-server/php

Then, include it by

require_once '/lib/Braintree.php';

follow by instantiate a Braintree Gateway like this

$gateway = new Braintree_Gateway([
'environment' => 'sandbox',
'merchantId' => '[paypal-merchant-id]',
'publicKey' => '[paypal-public-key]',
'privateKey' => '[paypal-private-key]'
]);

use below code to generate the key

$clientToken = $gateway->clientToken()->generate();

Leave A Comment?