PHP code example of danhunsaker / laravel-braintree

1. Go to this page and download the library: Download danhunsaker/laravel-braintree 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/ */

    

danhunsaker / laravel-braintree example snippets


// You can alias this in config/app.php.
use Danhunsaker\Braintree\Facades\Braintree;

Braintree::getTransaction()->sale([
    'amount' => '10.00',
    'paymentMethodNonce' => $nonceFromTheClient,
    'options' => ['submitForSettlement' => true]
]);
// We're done here - how easy was that, it just works!

use Danhunsaker\Braintree\Facades\Braintree;

// Writing this…
Braintree::connection('main')->getCharge()->([
    'amount' => '10.00',
    'paymentMethodNonce' => $nonceFromTheClient,
    'options' => ['submitForSettlement' => true]
]);

// …is identical to writing this
Braintree::getCharge()->([
    'amount' => '10.00',
    'paymentMethodNonce' => $nonceFromTheClient,
    'options' => ['submitForSettlement' => true]
]);

// and is also identical to writing this.
Braintree::connection()->getCharge()->([
    'amount' => '10.00',
    'paymentMethodNonce' => $nonceFromTheClient,
    'options' => ['submitForSettlement' => true]
]);

// This is because the main connection is configured to be the default.
Braintree::getDefaultConnection(); // This will return main.

// We can change the default connection.
Braintree::setDefaultConnection('alternative'); // The default is now alternative.

use Danhunsaker\Braintree\BraintreeManager;

class Foo
{
    protected $braintree;

    public function __construct(BraintreeManager $braintree)
    {
        $this->braintree = $braintree;
    }

    public function bar($params)
    {
        $this->braintree->getCharge()->([
            'amount' => '10.00',
            'paymentMethodNonce' => $nonceFromTheClient,
            'options' => ['submitForSettlement' => true]
        ]);
    }
}

App::make('Foo')->bar($params);
bash
$ php artisan vendor:publish --provider="Danhunsaker\Braintree\BraintreeServiceProvider"