Hosted Commerce#
A webshop on Afosto has three customer-facing parts:
| Part | Who builds it | What it does |
|---|---|---|
| Storefront | You | Your shop: product pages, the cart and the login form. It talks to the GraphQL API. |
| Hosted checkout | Afosto | Takes a cart through address, shipping and payment, and turns it into an order. |
| Hosted account | Afosto | Lets 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.
| Page | What it covers |
|---|---|
| Setting up | What to set up in Afosto first. |
| Storefront | Tokens per call, products, prices and the cart. |
| Hosted checkout | Sending a cart to the checkout and back. |
| Hosted account | The customer's account pages. |
| Logging in | Customer login, registration and organisations. |
| Price lists | Customer prices and loading them into the cart. |
Tokens#
| Token | Looks like | Tied to | Used for |
|---|---|---|---|
| Storefront token | stf.… | One channel | The shop: products, carts, orders after the checkout, logging in and registering. Safe to ship in front-end code. |
| User token | A JWT | Channel + person | Calls for the customer who is logged in: the account query, account orders, invoices, addresses, organisations. |
| API key | adm.… | Your account | Back-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:
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.