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":

query CartCheckout($id: String!) {
  cart(id: $id) {
    id
    checkout {
      url
    }
  }
}
{ "id": "72fca344-2a6f-4c3e-b4ca-029920b2522a" }

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.

StepThe customer…
informationEnters an email and addresses, or logs in. A business customer picks an organisation.
shippingChooses a shipping method or a pick-up point.
paymentChooses a payment method.
checkoutReviews 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:

mutation CreateCart($input: CartInput!) {
  createCart(input: $input) {
    cart {
      id
      checkout {
        url
      }
    }
  }
}
{
  "input": {
    "success_return_url": "https://www.shop.com/thank-you",
    "failure_return_url": "https://www.shop.com/cart"
  }
}

Afosto adds query parameters to the return URL. Parameters already on the URL stay.

ParameterOnValue
order_idBothThe ID of the order the cart became.
tokenBothThe order's checkout token, the same as order.checkout.token.
stateFailure URLfailed when the payment failed, cancelled when the customer cancelled it.
errorFailure URLThe error of the payment provider, when it gives one. message holds its text.
https://www.shop.com/thank-you?order_id=1f0e…&token=odr.…
https://www.shop.com/cart?order_id=1f0e…&token=odr.…&state=cancelled

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:

query Order($id: String!) {
  order(id: $id) {
    id
    number
    status
    is_cancelled
    total
    currency
    checkout {
      token
    }
    acceptance {
      amount_covered
    }
    payments {
      amount
      details {
        status
        is_paid
      }
    }
  }
}
{ "id": "1f0e…" }
  • Compare checkout.token with the token parameter, so you only show the order that came back from this checkout.
  • The order is paid once acceptance.amount_covered reaches total. After a successful payment the order's status is OPEN.
  • 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:

    checkout  CNAME  hosted.afostocommerce.com.
    

    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.

Query Runnerhttps://afosto.app/graphql

No query loaded

Click play on any code block in the docs to load a query here.