1. Go to this page and download the library: Download braintree/braintree_php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
braintree / braintree_php example snippets
stantiate a Braintree Gateway either like this:
$gateway = new Braintree\Gateway([
'environment' => 'sandbox',
'merchantId' => 'your_merchant_id',
'publicKey' => 'your_public_key',
'privateKey' => 'your_private_key'
]);
// or like this:
$config = new Braintree\Configuration([
'environment' => 'sandbox',
'merchantId' => 'your_merchant_id',
'publicKey' => 'your_public_key',
'privateKey' => 'your_private_key'
]);
$gateway = new Braintree\Gateway($config)
// Then, create a transaction:
$result = $gateway->transaction()->sale([
'amount' => '10.00',
'paymentMethodNonce' => $nonceFromTheClient,
'deviceData' => $deviceDataFromTheClient,
'options' => [ 'submitForSettlement' => True ]
]);
if ($result->success) {
print_r("success!: " . $result->transaction->id);
} else if ($result->transaction) {
print_r("Error processing transaction:");
print_r("\n code: " . $result->transaction->processorResponseCode);
print_r("\n text: " . $result->transaction->processorResponseText);
} else {
foreach($result->errors->deepAll() AS $error) {
print_r($error->code . ": " . $error->message . "\n");
}
}
$gateway = new Braintree\Gateway([
'environment' => 'sandbox',
'merchantId' => 'your_merchant_id',
'publicKey' => 'your_public_key',
'privateKey' => 'your_private_key'
]);
// or
$config = new Braintree\Configuration([
'environment' => 'sandbox',
'merchantId' => 'your_merchant_id',
'publicKey' => 'your_public_key',
'privateKey' => 'your_private_key'
]);
$gateway = new Braintree\Gateway($config)