Skip to content

houmam/afterpay

 
 

Repository files navigation

PHP library to interface with the Afterpay API

Coverage Status CircleCI Scrutinizer SensioLabsInsight

Installation

The recommended way to install is via Composer.

composer require culturekings/afterpay

Don't forget to include Composer's autoloader if you haven't already:

require 'vendor/autoload.php';

Usage

All the Afterpay API calls should be available via similar names in the main API factory.

Get Configuration

Get Configuration Docs

$authorization = new \CultureKings\Afterpay\Authorization(
    \CultureKings\Afterpay\Model\Authorization::SANDBOX_URI,
    YOUR_MERCHANT_ID,
    YOUR_SECRET_KEY
);

$configuration = \CultureKings\Afterpay\Factory\Api::configuration($authorization)->get()

List Payments

List Payments Docs

$authorization = new \CultureKings\Afterpay\Authorization(
    \CultureKings\Afterpay\Model\Authorization::SANDBOX_URI,
    YOUR_MERCHANT_ID,
    YOUR_SECRET_KEY
);

$payments = \CultureKings\Afterpay\Factory\Api::payments($auth)->listPayments(
    [
        'fromCreatedDate' => '2016-01-01T00:00:00.000Z',
        'limit' => 1
    ]
);

Get Payment

Get Payment Docs

$authorization = new \CultureKings\Afterpay\Authorization(
    \CultureKings\Afterpay\Model\Authorization::SANDBOX_URI,
    YOUR_MERCHANT_ID,
    YOUR_SECRET_KEY
);

$payment = \CultureKings\Afterpay\Factory\Api::payments($auth)->get(
    PAYMENT_ID
);

Get Payment By Token

Get Payment Docs

$authorization = new \CultureKings\Afterpay\Authorization(
    \CultureKings\Afterpay\Model\Authorization::SANDBOX_URI,
    YOUR_MERCHANT_ID,
    YOUR_SECRET_KEY
);

$payment = \CultureKings\Afterpay\Factory\Api::payments($auth)->getByToken(
    ORDER_TOKEN
);

Authorise Payment

Authorise Payment Docs

$authorization = new \CultureKings\Afterpay\Authorization(
    \CultureKings\Afterpay\Model\Authorization::SANDBOX_URI,
    YOUR_MERCHANT_ID,
    YOUR_SECRET_KEY
);

$payment = \CultureKings\Afterpay\Factory\Api::payments($auth)->authorise(
    ORDER_TOKEN,
    MERCHANT_REFERENCE,
    WEBHOOK_EVENT_URL
);

Capture Payment

Capture Payment Docs

$authorization = new \CultureKings\Afterpay\Authorization(
    \CultureKings\Afterpay\Model\Authorization::SANDBOX_URI,
    YOUR_MERCHANT_ID,
    YOUR_SECRET_KEY
);

$payment = \CultureKings\Afterpay\Factory\Api::payments($auth)->capture(
    ORDER_TOKEN,
    MERCHANT_REFERENCE,
    WEBHOOK_EVENT_URL
);

Void Payment

Void Payment Docs

$authorization = new \CultureKings\Afterpay\Authorization(
    \CultureKings\Afterpay\Model\Authorization::SANDBOX_URI,
    YOUR_MERCHANT_ID,
    YOUR_SECRET_KEY
);

$payment = \CultureKings\Afterpay\Factory\Api::payments($auth)->void(
    PAYMENT_ID
);

Create Order

Create Order Docs

$consumer = new \CultureKings\Afterpay\Model\Consumer();
$consumer->setEmail('john.doe@culturekings.com.au');
$consumer->setGivenNames('John');
$consumer->setSurname('Doe');
$consumer->setPhoneNumber('0534242323');

$merchantOptions = new \CultureKings\Afterpay\Model\MerchantOptions();
$merchantOptions->setRedirectConfirmUrl('https://www.merchant.com/confirm');
$merchantOptions->setRedirectCancelUrl('https://www.merchant.com/cancel');

$totalAmount = new \CultureKings\Afterpay\Model\Money();
$totalAmount->setAmount(mt_rand(1, 300));
$totalAmount->setCurrency('AUD');

$orderDetails = new \CultureKings\Afterpay\Model\OrderDetails();
$orderDetails->setConsumer($consumer);
$orderDetails->setMerchant($merchantOptions);
$orderDetails->setTotalAmount($totalAmount);

$orderToken  = \CultureKings\Afterpay\Factory\Api::orders($auth)->create($orderDetails);

Get Order

Get Order Docs

$order = \CultureKings\Afterpay\Factory\Api::orders($auth)->get($orderToken->getToken());

Exceptions

If a call to Afterpay fails, a \CultureKings\Afterpay\Exception\ApiException will be thrown and the error message can be retrieved via the getErrorResponse method.

Special Thanks

JMS Serializer

Guzzle

About

API integration with Afterpay

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%