Limited time offers! Get up to 20% OFF.

Braintree

Braintree, owned by PayPal, is a payment platform used in over 40 countries that accepts various payment methods, including PayPal, Venmo, and digital wallets (Apple Pay, Google Pay, and Samsung Pay).

Some payment methods are only available in certain countries and regions; see the complete list at: https://developer.paypal.com/braintree/articles/get-started/payment-methods

Configurando um Perfil

In the menu Tools > API you can create API profiles for use in your projects. This way, you will only need to provide your credentials once to use the API in your project.

See how to obtain the credentials needed to configure the profile.

When deploying your project, you will need to configure the API credentials in Prod, by accessing the API menu.

Configuração de pagamento utilizando API Braintree

To create a profile, we must add the following information:

Name

Defines the name to identify the API profile. This name is unique and will be used to reference the API profile in your project’s applications.

Mode

The mode defines the availability of the Profile in Scriptcase.

  • Public - Users from all projects will be able to view and use the created profile.

  • Project - Users will be able to view and use the profile in the project where it was configured.

  • User - Only the user who created the profile will be able to view and use it in the applications.

Regardless of the mode used for creation, profiles can only be edited by users with administrator access in the project. See how to define user access levels in Scriptcase.

Gateway

Defines the API that will be used to create the profile.

Merchant ID

Your Merchant ID is the unique identifier for your entire gateway account, including the various merchant accounts that may be on your gateway. Often called a Public ID or Production ID, your Merchant ID will be different for your production and sandbox gateways.

Public Key

This is your user-specific Public ID. Each user associated with your Braintree gateway will have their own public key.

Private Key

This is your user-specific Private Key. Each user associated with your Braintree gateway will have their own private key. Your private key should not be shared outside of using an API call – even with us.

Test Mode

Enables or disables the API’s test mode.

Usage Examples

When using the sc_call_api macro, an object is instantiated, click here to see all Braintree methods.

To use the API, your server will be responsible for generating the client token, containing the authorization and configuration information to initialize the SDK and communicate with Braintree, see how to generate a client token

If the client is not found, a validation error will be returned.

To initialize the JavaScript SDK, we must have the client token generated by the Braintree server’s SDK, see how to obtain a client token

It is also recommended that all transactions initiated by the client include device data to increase transaction accuracy and security, see how to paste device data.

See below some examples of using the API.

Example showing the API profile created in the interface as a parameter in the macro.

$gateway = sc_call_api('braintree');

$response = $gateway->transaction()->sale([
  'amount' => '10.00',
  'paymentMethodNonce' => $nonceFromTheClient,
  'deviceData' => $deviceDataFromTheClient,
  'options' => [
    'submitForSettlement' => True
  ]
]);
echo '<pre>';
print_r($response);

Example using credentials in the macro

$merchantId = 'MERCHANT_ID';
$privateKey = 'PRIVATE_KEY';
$publicKey = 'PUBLIC_KEY';

$arr_settings = array('settings' => ['gateway' => 'braintree', 'merchantId'=> $merchantId, 'publicKey' => $publicKey, 'privateKey' => $privateKey, 'testMode' => TRUE]);

$gateway = sc_call_api('', $arr_settings);    
   	 
echo($clientToken = $gateway->clientToken()->generate());