sunnysideup / afterpay
Integrate easily with the api.afterpay.com API
Installs: 357
Dependents: 0
Suggesters: 1
Security: 0
Stars: 1
Watchers: 4
Forks: 0
Open Issues: 0
Type:silverstripe-vendormodule
Requires
- silverstripe/cms: ^4.0 || ^5.0
- sunnysideup/afterpay-basics: dev-master
- sunnysideup/ecommerce: *
This package is auto-updated.
Last update: 2024-10-27 08:45:36 UTC
README
Provides a basic implementation of afterpay as a payment method for
sunnysideup/ecommerce
- using https://github.com/culturekings/afterpay as a base.
installation
Use composer
composer require sunnysideup/afterpay
setup
Add the following code as outlined below:
- set up credentials
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
- set afterpay as a payment option
app/_config/ecommerce.yml
:
EcommercePayment: supported_methods: # ... Sunnysideup\Afterpay\Model\AfterpayEcommercePayment: "Afterpay"
- add fields to EcomConfig (via data extension or otherwise)
private static $db = [ 'ShowAfterpayOption' => 'Boolean', 'AfterpayMinValue' => 'Int', 'AfterpayMaxValue' => 'Int', ]
- add functionality to product:
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()); } }