alext/silverstripe-btpayment 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

alext/silverstripe-btpayment

Composer 安装命令:

composer require alext/silverstripe-btpayment

包简介

Integrate Braintree payment form in Dropin UI.

README 文档

README

A SilverStripe module to integrate Braintree payment forms in Dropin UI.

Currently there're following forms:

  • Make a payment form:

  • Add/remove payment methods in the vault:

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

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

  • Display previous transactions simple list

Support SilverStripe 4.

Installation

Use composer to install/update:

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:

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.

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

Usage

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

Example:

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

The page controller must extend BraintreePageController

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):

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

Example if we want to change the total amount on the fly:

[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

use AlexT\BTPayment\BraintreeEditPageController;

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

Example:

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

The page controller must extend BraintreePageController.

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

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

统计信息

  • 总下载量: 29
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2018-03-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固