Print API offers two different ways to pay for orders. If you have your own payment system, you can choose to periodically receive an invoice. In that case, you can skip this step.
To generate a payment link for an order, simply POST the payment details to the set-up URL of the order. You can obtain this set-up URL in the HTTP response when placing the order. Pricing can be configured per product from your account.
// $order = $api->post('/orders', ...);
$setupUrl = $order->checkout->setupUrl;
$checkout = $api->post($setupUrl, get_checkout_setup($order));
echo $checkout->paymentUrl; // redirect your user here
function get_checkout_setup($order)
{
return array(
'returnUrl' => 'http://localhost/example?order_id=' . $order->id,
'billingAddress' => array(
'name' => 'Print API',
'line1' => 'Osloweg 75',
'postCode' => '9700 GE',
'city' => 'Groningen',
'country' => 'NL'
)
);
}
Special fields:
Name | Details |
---|---|
"returnUrl" |
The URL where your user will return after payment |
billingAddress["country" ] |
A ISO 3166-1 alpha 2 country code |
If your user completes or cancels the payment, they will be redirected to the returnUrl
you supplied
in the POST. On that page, you can request the payment status from the API, as shown in the example below. If the
payment was not completed, the paymentUrl
remains available for up to 24 hours.
// Sample script for your return URL:
$id = urlencode($_GET['order_id']);
$order = $api->get('/orders/' . $id);
switch ($order->checkout->status) {
case 'Successful':
echo 'Thanks for your order!';
break;
case 'Open':
echo 'Payment was not completed. Please try again. <br />';
echo $order->checkout->paymentUrl;
break;
case 'Cancelled':
echo 'The payment has expired.';
break;
}