2017 © Pedro Peláez
 

silverstripe-vendormodule silverstripe-btpayment

Integrate Braintree payment form in Dropin UI.

image

alext/silverstripe-btpayment

Integrate Braintree payment form in Dropin UI.

  • Wednesday, April 11, 2018
  • by conqtc
  • Repository
  • 0 Watchers
  • 0 Stars
  • 18 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 29 % Grown

The README.md

silverstripe-btpayment

A SilverStripe module to integrate Braintree payment forms in Dropin UI., (*1)

Currently there're following forms:, (*2)

  • Make a payment form:

, (*3)

  • Add/remove payment methods in the vault:

, (*4)

When there's no payment method in the vault, the form allows user to add a new payment method:, (*5)

, (*6)

Both forms (v0.6) allow user to authorize paypal:, (*7)

, (*8)

  • Display previous transactions simple list

, (*9)

Support SilverStripe 4., (*10)

Installation

Use composer to install/update:, (*11)

composer require alext/silverstripe-btpayment

Braintree settings

After installing and rebuilding (\dev\build?flush) go to site admin - Settings and input Braintree settings, see screenshot below:, (*12)

, (*13)

SilverStripe member and Braintree customer

This module extends SilverStripe member's data to create a Braintree customer for each member and store its customer id in database., (*14)

Braintree customer will be created on the fly at the first time using the forms if there's no customer id found., (*15)

Usage

  • To use the make payment form, use $BTPaymentForm in your template of the page.

Example:, (*16)

[SamplePayment.ss]
<!-- BEGIN MAIN CONTENT -->
    $BTPaymentForm
<!-- END MAIN CONTENT -->

The page controller must extend BraintreePageController, (*17)

use AlexT\BTPayment\BraintreePageController;

class SamplePaymentPageController extends BraintreePageController {
}
  • To use the payment methods management form, use $BTEditPaymentForm($amount) in your template, if $amount is not specified 0 (zero) will be put in place.

Example (in case we process the payment in the separate page, set the total amount on the fly):, (*18)

[SamplePaymentManagement.ss]
<!-- BEGIN MAIN CONTENT -->
    $BTEditPaymentForm
<!-- END MAIN CONTENT -->

Example if we want to change the total amount on the fly:, (*19)

[PaymentPage.ss]
<h3>Select a property to purchase:</h3>
<p><p>
<select id="js-select-property">
    <option value="0">----- Select property -----</option>
    <% loop $FeaturedProperties %>
        <option value="{$PricePerNight}">{$Title}</option>
    <% end_loop %>
</select>
<hr>
$BTPaymentForm
-----
[scripts.js]
$('#js-select-property').on('change', function (e) {
    $('.js-bt-amount').val($('#js-select-property').val());
});

The page controller must extend BraintreeEditPageController, (*20)

use AlexT\BTPayment\BraintreeEditPageController;

class SamplePaymentManagementPageController extends BraintreeEditPageController {
}
  • To use the previous transactions form, use BTPreviousTransactionsForm in your template.

Example:, (*21)

[SamplePaymentManagement.ss]
<!-- BEGIN MAIN CONTENT -->
    $BTPreviousTransactionsForm
<!-- END MAIN CONTENT -->

The page controller must extend BraintreePageController., (*22)

To manually handle the transaction yourself, override function processPayment($session, $form, $nonce, $amount) to do your own transaction, for example:, (*23)

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();
}

The Versions

11/04 2018

dev-master

9999999-dev http://github.com/conqtc/btpayment

Integrate Braintree payment form in Dropin UI.

  Sources   Download

proprietary

The Requires

 

payment pay silverstripe paypal braintree card credit

05/04 2018

v0.6

0.6.0.0 http://github.com/conqtc/btpayment

Integrate Braintree payment form in Dropin UI.

  Sources   Download

proprietary

The Requires

 

payment pay silverstripe paypal braintree card credit

16/03 2018

v0.5

0.5.0.0 http://github.com/conqtc/btpayment

Integrate Braintree payment form in Dropin UI.

  Sources   Download

proprietary

The Requires

 

payment pay silverstripe paypal braintree card credit

16/03 2018

v0.4

0.4.0.0 http://github.com/conqtc/btpayment

Integrate Braintree payment form in Dropin UI.

  Sources   Download

proprietary

The Requires

 

payment pay silverstripe paypal braintree card credit

15/03 2018

v0.2-alpha

0.2.0.0-alpha http://github.com/conqtc/btpayment

Integrate Braintree payment form in Dropin UI.

  Sources   Download

proprietary

The Requires

 

payment pay silverstripe paypal braintree card credit

15/03 2018

v0.1

0.1.0.0 http://github.com/conqtc/btpayment

Integrate Braintree payment form in Dropin UI.

  Sources   Download

proprietary

The Requires

 

payment pay silverstripe paypal braintree card credit

15/03 2018

v0.1-alpha

0.1.0.0-alpha http://github.com/conqtc/btpayment

Integrate Braintree payment form in Dropin UI.

  Sources   Download

proprietary

The Requires

 

payment pay silverstripe paypal braintree card credit