PHP code example of afterpay-global / afterpay-sdk-php

1. Go to this page and download the library: Download afterpay-global/afterpay-sdk-php 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/ */

    

afterpay-global / afterpay-sdk-php example snippets




use Afterpay\SDK\HTTP\Request\CreateCheckout as AfterpayCreateCheckoutRequest;

$createCheckoutRequest = new AfterpayCreateCheckoutRequest([
    'amount' => [ '10.00', 'AUD' ],
    'consumer' => [
        'phoneNumber' => '0400 000 000',
        'givenNames' => 'Test',
        'surname' => 'Test',
        'email' => '[email protected]'
    ],
    'billing' => [
        'name' => 'Joe Consumer',
        'line1' => 'Level 5',
        'line2' => '406 Collins Street',
        'area1' => 'Melbourne',
        'region' => 'VIC',
        'postcode' => '3000',
        'countryCode' => 'AU',
        'phoneNumber' => '0400 000 000'
    ],
    'shipping' => [
        'name' => 'Joe Consumer',
        'line1' => 'Level 5',
        'line2' => '406 Collins Street',
        'area1' => 'Melbourne',
        'region' => 'VIC',
        'postcode' => '3000',
        'countryCode' => 'AU',
        'phoneNumber' => '0400 000 000'
    ],
    'courier' => [
        'shippedAt' => '2019-01-01T00:00:00+10:00',
        'name' => 'Australia Post',
        'tracking' => 'AA0000000000000',
        'priority' => 'STANDARD'
    ],
    'items' => [
        [
            'name' => 'T-Shirt - Blue - Size M',
            'sku' => 'TSH0001B1MED',
            'quantity' => 10,
            'pageUrl' => 'https://www.example.com/page.html',
            'imageUrl' => 'https://www.example.com/image.jpg',
            'price' => [ '10.00', 'AUD' ],
            'categories' => [
                [ 'Clothing', 'T-Shirts', 'Under $25' ],
                [ 'Sale', 'Clothing' ]
            ]
        ]
    ],
    'discounts' => [
        [
            'displayName' => '20% off SALE',
            'amount' => [ '24.00', 'AUD' ]
        ]
    ],
    'merchant' => [
        'redirectConfirmUrl' => 'http://localhost',
        'redirectCancelUrl' => 'http://localhost'
    ],
    'taxAmount' => [ '0.00', 'AUD' ],
    'shippingAmount' => [ '0.00', 'AUD' ]
]);

$createCheckoutRequest->send();

echo $createCheckoutRequest->getRawLog();
bash
composer 
bash
composer 
bash
composer remove afterpay-global/afterpay-sdk-php
bash
phpunit --colors=always ./vendor/afterpay-global/afterpay-sdk-php/test/unit
bash
phpunit --colors=always ./vendor/afterpay-global/afterpay-sdk-php/test/service
bash
phpunit --colors=always ./vendor/afterpay-global/afterpay-sdk-php/test/network
bash
phpunit --colors=always ./vendor/afterpay-global/afterpay-sdk-php/test/integration