All the Afterpay API calls should be available via similar names in the main API factory.
$authorization = new \CultureKings\Afterpay\Model\Merchant\Authorization(
\CultureKings\Afterpay\Model\Merchant\Authorization::SANDBOX_URI,
YOUR_MERCHANT_ID,
YOUR_SECRET_KEY
);
$configuration = \CultureKings\Afterpay\Factory\MerchantApi::configuration($authorization)->get();
$authorization = new \CultureKings\Afterpay\Model\Merchant\Authorization(
\CultureKings\Afterpay\Model\Merchant\Authorization::SANDBOX_URI,
YOUR_MERCHANT_ID,
YOUR_SECRET_KEY
);
$payments = \CultureKings\Afterpay\Factory\MerchantApi::payments($authorization)->listPayments(
[
'fromCreatedDate' => '2016-01-01T00:00:00.000Z',
'limit' => 1
]
);
$authorization = new \CultureKings\Afterpay\Model\Merchant\Authorization(
\CultureKings\Afterpay\Model\Merchant\Authorization::SANDBOX_URI,
YOUR_MERCHANT_ID,
YOUR_SECRET_KEY
);
$payment = \CultureKings\Afterpay\Factory\MerchantApi::payments($authorization)->get(
PAYMENT_ID
);
$authorization = new \CultureKings\Afterpay\Model\Merchant\Authorization(
\CultureKings\Afterpay\Model\Merchant\Authorization::SANDBOX_URI,
YOUR_MERCHANT_ID,
YOUR_SECRET_KEY
);
$payment = \CultureKings\Afterpay\Factory\MerchantApi::payments($authorization)->getByToken(
ORDER_TOKEN
);
$authorization = new \CultureKings\Afterpay\Model\Merchant\Authorization(
\CultureKings\Afterpay\Model\Merchant\Authorization::SANDBOX_URI,
YOUR_MERCHANT_ID,
YOUR_SECRET_KEY
);
$payment = \CultureKings\Afterpay\Factory\MerchantApi::payments($authorization)->authorise(
ORDER_TOKEN,
MERCHANT_REFERENCE,
WEBHOOK_EVENT_URL
);
$authorization = new \CultureKings\Afterpay\Model\Merchant\Authorization(
\CultureKings\Afterpay\Model\Merchant\Authorization::SANDBOX_URI,
YOUR_MERCHANT_ID,
YOUR_SECRET_KEY
);
$payment = \CultureKings\Afterpay\Factory\MerchantApi::payments($authorization)->capture(
ORDER_TOKEN,
MERCHANT_REFERENCE,
WEBHOOK_EVENT_URL
);
$authorization = new \CultureKings\Afterpay\Model\Merchant\Authorization(
\CultureKings\Afterpay\Model\Merchant\Authorization::SANDBOX_URI,
YOUR_MERCHANT_ID,
YOUR_SECRET_KEY
);
$payment = \CultureKings\Afterpay\Factory\MerchantApi::payments($authorization)->void(
PAYMENT_ID
);
$consumer = new \CultureKings\Afterpay\Model\Merchant\Consumer();
$consumer->setEmail('[email protected]');
$consumer->setGivenNames('John');
$consumer->setSurname('Doe');
$consumer->setPhoneNumber('0534242323');
$merchantOptions = new \CultureKings\Afterpay\Model\Merchant\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\Merchant\OrderDetails();
$orderDetails->setConsumer($consumer);
$orderDetails->setMerchant($merchantOptions);
$orderDetails->setTotalAmount($totalAmount);
$orderToken = \CultureKings\Afterpay\Factory\MerchantApi::orders($authorization)->create($orderDetails);
$order = \CultureKings\Afterpay\Factory\MerchantApi::orders($authorization)->get($orderToken->getToken());
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.