Hosted checkout#
The hosted checkout runs on the domain in the channel's Checkout link: either https://<name>.afostocommerce.com or your own domain, such as checkout.shop.com. See Domains.
The checkout finds the channel from the domain it runs on, so the URL only carries the cart. It uses the colour, logo, favicon and language of the channel.
Sending a customer to the checkout#
Every cart has a checkout URL. Send the customer there when they press "Checkout":
The URL first validates the cart and then redirects to /checkout?cart_id=<id> on the checkout domain, or to /checkout/errors when the cart can't be checked out yet. You don't confirm the cart yourself: the checkout does that after the customer has filled in the steps.
| Step | The customer… |
|---|---|
information | Enters an email and addresses, or logs in. A business customer picks an organisation. |
shipping | Chooses a shipping method or a pick-up point. |
payment | Chooses a payment method. |
checkout | Reviews the order. The checkout calls confirmCart and starts the payment. |
Return URLs#
After payment the checkout shows its own thank-you page, or its payment page with an error when the payment failed or was cancelled. To bring the customer back to your storefront instead, set the return URLs when you create the cart:
Afosto adds query parameters to the return URL. Parameters already on the URL stay.
| Parameter | On | Value |
|---|---|---|
order_id | Both | The ID of the order the cart became. |
token | Both | The order's checkout token, the same as order.checkout.token. |
state | Failure URL | failed when the payment failed, cancelled when the customer cancelled it. |
error | Failure URL | The error of the payment provider, when it gives one. message holds its text. |
Without return URLs the customer stays on the checkout's own thank-you or payment page.
Checking the order#
The return URL tells you which order to show, not that it is paid. Read the order with the storefront token before you show a confirmation:
- Compare
checkout.tokenwith thetokenparameter, so you only show the order that came back from this checkout. - The order is paid once
acceptance.amount_coveredreachestotal. After a successful payment the order'sstatusisOPEN. - After a failed or cancelled payment the order stays unpaid. The customer can pay it again on the checkout's payment page.
A logged-in customer can also read the order with the user token through account { order(id: …) }.
Domains#
The checkout's domain is set in Afosto in the channel's checkout settings:
-
An Afosto domain:
https://<name>.afostocommerce.com. Nothing to set up, but the checkout can't see a login on your storefront, because it doesn't share a domain with it. -
Your own domain, such as
checkout.shop.com: add it in Afosto under Domains for the hosted checkout, pick it in the channel, and add a DNS record:Don't proxy the record (in Cloudflare: DNS only).
Use a subdomain of your shop's domain, so the storefront, the checkout and the account share the login cookie. See Sharing the login. The hosted account's domain is set up the same way.