PHP code example of sunnysideup / afterpay

1. Go to this page and download the library: Download sunnysideup/afterpay library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sunnysideup / afterpay example snippets


    private static $db = [
        'ShowAfterpayOption' => 'Boolean',
        'AfterpayMinValue' => 'Int',
        'AfterpayMaxValue' => 'Int',
    ]

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


}