sunshineup / afterpay
易于与api.afterpay.com API集成
2.1.1
2023-10-06 04:26 UTC
Requires
- silverstripe/cms: ^4.0 || ^5.0
- sunnysideup/afterpay-basics: dev-master
- sunnysideup/ecommerce: *
This package is auto-updated.
Last update: 2024-08-27 08:34:18 UTC
README
为 sunnysideup/ecommerce
提供了一个基本的 afterpay 支付方式实现,以 https://github.com/culturekings/afterpay 为基础。
安装
使用 composer
composer require sunnysideup/afterpay
设置
按照以下说明添加以下代码
- 设置凭证
app/_config/afterpay.yml
:
--- Name: Afterpay --- Sunnysideup\Afterpay\Factory\SilverstripeMerchantApi: merchant_name: 'my merchant name' merchant_id: yyy secret_key: 'xxx' expectations_folder: 'app/afterpay/configurations' number_of_payments: 4
- 将 afterpay 设置为支付选项
app/_config/ecommerce.yml
:
EcommercePayment: supported_methods: # ... Sunnysideup\Afterpay\Model\AfterpayEcommercePayment: "Afterpay"
- 向 EcomConfig 添加字段(通过数据扩展或其他方式)
private static $db = [ 'ShowAfterpayOption' => 'Boolean', 'AfterpayMinValue' => 'Int', 'AfterpayMaxValue' => 'Int', ]
- 向产品添加功能
app/src/Model/MyProduct.php
:
use Sunnysideup\Afterpay\Factory\SilverstripeMerchantApi; class MyProduct extends Product { public function ShowAfterpay() : bool { return return $this->myAfterpayApi()->canProcessPayment($this->CalculatedPrice()); } protected function myAfterpayApi() : SilverstripeMerchantApi { return SilverstripeMerchantApi::inst() ->setMinAndMaxPrice( (float) EcommerceConfig::inst()->AfterpayMinValue, (float) EcommerceConfig::inst()->AfterpayMaxValue ) ->setIsServerAvailable(EcommerceConfig::inst()->ShowAfterpayOption); } public function getAfterpayNumberOfPayments() : int { return $this->myAfterpayApi() ->getNumberOfPayments(); } public function getAfterpayNumberOfPaymentsInWeeks() : int { return $this->getAfterpayNumberOfPayments() * 2; } public function getAfterpayAmountPerPayment() :float { return $this->myAfterpayApi() ->getAmountPerPayment($this->CalculatedPrice()); } public function getAfterpayAmountPerPaymentAsMoney() : Money { return EcommerceCurrency::get_money_object_from_order_currency( $this->getAfterpayAmountPerPayment() ); } public function getAfterpayAmountPerPaymentAsCurrency(): Currency { return DBField::create_field('Currency', $this->getAfterpayAmountPerPayment()); } }