Hosted Commerce#

A webshop on Afosto has three customer-facing parts:

PartWho builds itWhat it does
StorefrontYouYour shop: product pages, the cart and the login form. It talks to the GraphQL API.
Hosted checkoutAfostoTakes a cart through address, shipping and payment, and turns it into an order.
Hosted accountAfostoLets a customer view orders, invoices, addresses and returns after logging in.

All three belong to one channel. The channel decides the currency, the price lists, the payment and shipping methods, the branding and the domains of the hosted checkout and account.

Storefront
GraphQL API
Hosted checkout & account
1
createCart, addItemsToCart
storefront token
2
logInCustomer
returns the user token
3
Store the user token in the af‑sid cookie
on the parent domain, e.g. .shop.com
4
addCustomerToCart
the cart takes the customer's prices
5
Send the customer to cart.checkout.url
the hosted checkout
6
confirmCart and the payment
logged in through af‑sid
7
Back on success_return_url or failure_return_url
?order_id=…&token=…
8
Link to the hosted account
already logged in through af‑sid
One channel: the storefront, the hosted checkout and the hosted account
PageWhat it covers
Setting upWhat to set up in Afosto first.
StorefrontTokens per call, products, prices and the cart.
Hosted checkoutSending a cart to the checkout and back.
Hosted accountThe customer's account pages.
Logging inCustomer login, registration and organisations.
Price listsCustomer prices and loading them into the cart.

Tokens#

TokenLooks likeTied toUsed for
Storefront tokenstf.…One channelThe shop: products, carts, orders after the checkout, logging in and registering. Safe to ship in front-end code.
User tokenA JWTChannel + personCalls for the customer who is logged in: the account query, account orders, invoices, addresses, organisations.
API keyadm.…Your accountBack-office work from a server. Never put it in a browser.

Create a storefront token in Afosto under Credentials with the purpose Storefront and pick the channel. Every call is a POST to https://afosto.app/graphql, with the token in the same header:

POST https://afosto.app/graphql
Authorization: Bearer stf.xxxxxxxx
Content-Type: application/json

Because the storefront token carries the channel, createCart doesn't need a channel_id when you use it. With an API key you pass channel_id yourself.

A user token also carries the channel, plus the contact (sub) and, after logging in as an organisation, the organisation (organisation_id). Use it only for account calls; everything else keeps using the storefront token, also while a customer is logged in. The Storefront page lists which token works for which call.

Query Runnerhttps://afosto.app/graphql

No query loaded

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