braintree/braintree_php
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The Braintree PHP library, also known as braintree/braintree_php, enables developers to integrate their PHP applications with the Braintree Gateway for online payment processing. This essential tool makes it easier to facilitate secure transactions, which complies with the Payment Card Industry's (PCI) mandate for retiring early versions of TLS. The library is compatible with PHP version 7.3 and onwards, ensuring secure interactions with Braintree’s services.
The most straightforward way to use the braintree/braintree_php library starts with adding it to your project. Once it's part of your codebase, you can instantiate a Braintree Gateway using your credentials. Here's an example in PHP:
<?php
require_once 'PATH_TO_BRAINTREE/lib/Braintree.php';
$gateway = new Braintree\Gateway([
'environment' => 'sandbox', // change to 'production' when you are ready to transact
'merchantId' => 'your_merchant_id',
'publicKey' => 'your_public_key',
'privateKey' => 'your_private_key'
]);
$result = $gateway->transaction()->sale([
'amount' => '10.00',
'paymentMethodNonce' => $nonceFromTheClient,
'deviceData' => $deviceDataFromTheClient,
'options' => [ 'submitForSettlement' => True ]
]);
if ($result->success) {
print_r("success!: " . $result->transaction->id);
} else {
print_r("Error processing transaction: ". $result->message);
}
?>
In this example, a Braintree Gateway instance is created, then that instance is used to initiate a transaction. The response from Braintree is then checked for a success flag. If the transaction was successful, the transaction ID is printed. Otherwise, the error message is printed.
The official Braintree PHP library documentation, which provides more installation instructions, code examples, and API reference, can be found at this URL: Braintree PHP Documentation. If you're upgrading from an older version of the SDK, you might also find the Migration Guide useful. It's essential to check these resources to ensure smooth integration of the Braintree Gateway into your PHP application.