PHP code example of alext / silverstripe-btpayment

1. Go to this page and download the library: Download alext/silverstripe-btpayment 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/ */

    

alext / silverstripe-btpayment example snippets


public function processPayment($session, $form, $nonce, $amount) {
    $gateway = BraintreeExtension::BTGateway();
    // make a transaction
    $result = $gateway->transaction()->sale([
        'amount' => $amount,
        'paymentMethodNonce' => $nonce,
        'options' => [
            'submitForSettlement' => true
        ]
    ]);

    if ($result->success || !is_null($result->transaction)) {
        // clear session if everything is fine
        $session->clear("FormData.{$form->getName()}.data");
        $form->sessionMessage('A payment of ' . $amount . '$ has been made!', 'Success');
    } else {
        // ERROR
        $errorString = "";

        foreach ($result->errors->deepAll() as $error) {
            $errorString .= 'Error: ' . $error->code . ": " . $error->message . "\n";
        }

        $form->sessionError('Unable to make a payment! ' . $errorString, 'Failure');
    }

    return $this->redirectBack();
}