alext/silverstripe-btpayment

在Dropin UI中集成Braintree支付表单。

安装: 29

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:silverstripe-vendormodule

v0.6 2018-04-05 02:40 UTC

This package is not auto-updated.

Last update: 2024-09-26 04:11:04 UTC


README

一个SilverStripe模块,用于在Dropin UI中集成Braintree支付表单。

目前有以下表单

  • 支付表单

  • 在保险库中添加/删除支付方式

当保险库中没有支付方式时,表单允许用户添加新的支付方式

这两个表单(v0.6)都允许用户授权paypal

  • 显示以前交易的简单列表

支持SilverStripe 4。

安装

使用composer进行安装/更新

composer require alext/silverstripe-btpayment

Braintree设置

安装后重新构建(\dev\build?flush),然后转到网站管理员 - 设置,输入Braintree设置,请参阅下面的截图

SilverStripe成员和Braintree客户

此模块扩展了SilverStripe成员的数据,为每个成员创建一个Braintree客户,并将其客户ID存储在数据库中。

如果找不到客户ID,则将在第一次使用表单时动态创建Braintree客户。

使用方法

  • 要使用支付表单,请在页面模板中使用$BTPaymentForm

示例

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

页面控制器必须扩展BraintreePageController

use AlexT\BTPayment\BraintreePageController;

class SamplePaymentPageController extends BraintreePageController {
}
  • 要使用支付方式管理表单,请在您的模板中使用$BTEditPaymentForm($amount),如果未指定$amount,则默认为0(零)。

示例(如果我们处理支付操作在单独的页面中,动态设置总金额)

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

如果我们想动态更改总金额的示例

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

页面控制器必须扩展BraintreeEditPageController

use AlexT\BTPayment\BraintreeEditPageController;

class SamplePaymentManagementPageController extends BraintreeEditPageController {
}
  • 要使用以前交易的表单,请在您的模板中使用BTPreviousTransactionsForm

示例

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

页面控制器必须扩展BraintreePageController

要手动处理交易,覆盖function processPayment($session, $form, $nonce, $amount)以执行自己的交易,例如

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