Provides a basic implementation of afterpay as a payment method for
sunnysideup/ecommerce
- using https://github.com/culturekings/afterpay as a base.
Use composer
composer require sunnysideup/afterpay
Add the following code as outlined below:
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
app/_config/ecommerce.yml
:
EcommercePayment:
supported_methods:
# ...
Sunnysideup\Afterpay\Model\AfterpayEcommercePayment: "Afterpay"
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());
}
}
Module rating system helping users find modules that are well supported. For more on how the rating system works visit Module standards
Score not correct? Let us know there is a problem