anyshop docs homeStatusOpen the dashboard

GuidesHeadless checkout

Sell from your own site
with a headless checkout.

Keep your own product pages and cart, and let anyshop take the payment, deliver the keys and send the webhooks. Your server starts a checkout session for the buyer, sends them to its url, and they come back to your site once they have paid.

  • Checkouts scope
  • Your prices, never the request's
  • Back to your own pages

Before you start

  • An API key with the Checkouts scope. Dashboard, Developers, API keys, New API key: Checkouts, read and write. You can make the key before anyshop has approved your store; it starts checkouts once your store is approved, and until then they answer store_not_approved.
  • Your site on your allowed sites. Dashboard, Storefront, Buy buttons, Sites allowed to open checkout: add your site's address (yoursite.com). The buyer is only ever sent back to an address on this list, over https, or to your own anyshop storefront (https://yourstore.anyshop.io). Each site is exact: shop.yoursite.com is its own entry, and no other anyshop address can be one.
  • A way to pay, connected in Settings, Payments: Stripe (every way to pay you turn on in your own Stripe account: cards, Apple Pay, Google Pay, bank debits and more), PayPal (your own PayPal app), or Bitcoin and Litecoin to your own wallet. Connect them before review: they take payments once anyshop has approved your store.
  • A webhook endpoint, recommended: Developers, Webhooks, for order.paid.

Start a checkoutlive key

Send the product option, the quantity, the buyer's email and where the buyer goes back to. Send an Idempotency-Key too (your cart's ID, for example): a retry with the same key answers the same session, as it is now, instead of holding stock twice.

curl https://api.anyshop.io/v1/checkout_sessions \
  -H "Authorization: Bearer $ANYSHOP_LIVE_KEY" \
  -H "Idempotency-Key: cart-4411" \
  -H "Content-Type: application/json" \
  -d '{
    "variant": "var_01m3rs9d2f4k6m8p0r2t4v6x8z",
    "quantity": 1,
    "buyer_email": "ada@example.com",
    "payment_method": "paypal",
    "success_url": "https://yoursite.com/thanks",
    "cancel_url": "https://yoursite.com/cart",
    "metadata": { "cart": "4411" }
  }'
200Response
{
  "object": "checkout_session",
  "id": "cs_01m3rs9d2f4k6m8p0r2t4v6x8z",
  "status": "open",
  "url": "https://pay.anyshop.io/session/cs_01m3rs9d2f4k6m8p0r2t4v6x8z#Xk3Fq9...",
  "amount": 4900,
  "currency": "USD",
  "expires_at": "2026-10-04T12:15:00.000Z",
  "order": null,
  "metadata": { "cart": "4411" },
  "agreement": {
    "text": "I agree to the terms of sale and want my key right away.",
    "terms_url": "https://anyshop.io/buyer-terms",
    "version": 5,
    "collected_by": "anyshop"
  }
}
Field
variantThe product option to sell; product instead, for a product with a single option.
quantityBy default the product's min_quantity_per_order (1 unless you set one), between its min_quantity_per_order and its max_quantity_per_order.
buyer_emailWhere anyshop delivers the order, in your store's name.
couponOptional: one of your coupon codes.
payment_methodOptional: stripe (Stripe's own page, with every way to pay you turned on in Stripe), paypal, btc or ltc, as your store offers them. It starts when the buyer opens url, once the buyer has ticked the box above Pay (below). Without it, Stripe starts by itself when it is your store's first way to pay; otherwise the buyer chooses on anyshop's payment page.
success_url, cancel_urlhttps addresses on your allowed sites, or your own anyshop storefront. anyshop adds ?checkout={id}.
metadataOptional: up to 20 keys (letters, digits, _, . or -, not starting with __), string values of up to 500 characters, echoed in the order's webhook events. Your own references, not the buyer's personal data.
terms_acceptedOptional: true only when the buyer ticked the box above your own Pay button (below). Never send it for a buyer who did not.
immediate_delivery_requestedOptional: true only when that box's words asked for the order right away ("and want my key right away") and the buyer ticked it.
answersThe buyer's answers to the product's questions for the buyer, when it has some (the product's questions), keyed by question ID: { "pq_...": "ada_l" }. Ask them on your own page, as the hosted checkout does: a short text up to 200 characters, an email address, or exactly one of a choice's choices. Every required question needs an answer, or no session starts (400 invalid_answers). anyshop stores them encrypted with the order; they come back on the order's items, in its webhook events and in the request to your server for a "From your server" product, never in an email. See Questions for the buyer.
expected_amountOptional: the total your page showed the buyer, in minor units. When the price works out to another amount now (you changed a price, or a sale started or ended), no session starts: 409 price_changed, with the new total in error.amount.
  • The amount is always yours: it comes from your prices (a variant's sale price while one of your sales runs on it), the quantity, the product's quantity discount and then the coupon on what is left. The API never takes a price. Send expected_amount so a buyer never pays a total they did not see.
  • The keys are held for the buyer until expires_at: 15 minutes, then longer while the buyer pays elsewhere (31 minutes on Stripe's page, 30 on PayPal's, a crypto invoice's price lock), and much longer for a bank debit or a voucher (below). Unpaid, they go back to stock.
  • `url` is the buyer's alone. It holds the session's own secret after the #: redirect this buyer's browser to it straight away (a redirect keeps it), rather than emailing it, since a mail scanner that runs scripts could open it before the buyer. Do not log it. The session's ID is not a secret and opens nothing.

Send the buyer to url

Redirect the buyer's browser to url, on anyshop's pay host. Opening it changes nothing by itself: a link preview, a mail scanner or a prefetch that fetches it starts no payment. The page, in your store's name, takes the secret out of the address and sends it from the buyer's browser, and that request is where anyshop checks the buyer: your blocklist against their network and country, since your server only gave an email.

Then, once the buyer has ticked the box above Pay (on your own page or on anyshop's, below), the payment starts, and the request that starts it records the dispute evidence (the buyer's IP, kept encrypted, their country and device), as on the hosted checkout: on to Stripe's own page when you named Stripe (or named nothing and Stripe is your store's first way to pay), on to PayPal's own page when you named PayPal, or to anyshop's payment page for a crypto invoice or the choice of how to pay. A buyer your blocklist stops is sent back to your cancel_url, the session ends and the keys go back, and nothing reaches Stripe or PayPal. The page needs JavaScript, and says so without it.

PayPal sends the buyer back with a one-time code of that payment, never the secret, so a buyer whom PayPal's app returns to another browser still gets in, once.

Nodeserver.js
app.post("/buy", async (req, res) => {
  const session = await startCheckout(req.cart); // POST /v1/checkout_sessions, above
  log.info("checkout started", { id: session.id }); // the ID, never the url
  res.set("Referrer-Policy", "no-referrer");
  res.redirect(303, session.url);
});

The box above Pay

Every buyer, wherever they are, ticks an unticked box above Pay before anything is paid: they agree to the terms of sale, and when a product has the immediate delivery setting on (in the product editor, Buyers ask for it right away: on by default, off for services; immediate_delivery_consent in the API), they ask to have it sent right away. In the EU, the EEA and the UK their 14-day cancellation period then ends on delivery. The words are version 4 (since 10 November 2026):

What the session sellsThe box's words
Keys or licenses, with the setting onI agree to the terms of sale and want my key right away.
Files, with the setting onI agree to the terms of sale and want my download right away.
Anything else with the setting on, or a mixI agree to the terms of sale and want my order right away.
No product with the setting onI agree to the terms of sale.

The session's agreement.text is the line for its items, word for word. In it, "terms of sale" opens anyshop's terms of sale (agreement.terms_url, https://anyshop.io/buyer-terms) together with your refund policy.

anyshop records when the buyer ticked it, the version of the words and where: the order's terms_agreement (with collected_by) and, for the request to have it right away, withdrawal_consent, in the API and in order.paid. The delivery email confirms the request, and both go into the order's dispute evidence.

On anyshop's payment page

By default, anyshop asks. Opening url then starts nothing, not even your payment_method or a free order: anyshop's payment page shows the box above Pay with the words above, and the payment starts once the buyer ticks it and presses Pay. agreement.collected_by is anyshop.

On your own checkout page

You can ask on your own page instead, so the buyer goes straight on to the payment, as with no box at all: Stripe's or PayPal's page, a crypto invoice, or anyshop's choice of how to pay when you named no payment_method and Stripe is not your store's first way to pay.

  • An unticked checkbox, directly above your own Pay button, never ticked in advance, with the exact words from the table (pick the line from your products' type and setting, and check it against the session's agreement.text).
  • "terms of sale" is a link to a page that shows anyshop's terms of sale (agreement.terms_url) and your refund policy.
  • Pay does nothing until it is ticked. Then your server starts the session with terms_accepted: true and, when the words ask for the order right away, immediate_delivery_requested: true. Send them only for a buyer who ticked that box on your page.
json
{
  "variant": "var_01m3rs9d2f4k6m8p0r2t4v6x8z",
  "buyer_email": "ada@example.com",
  "payment_method": "stripe",
  "success_url": "https://yoursite.com/thanks",
  "cancel_url": "https://yoursite.com/cart",
  "terms_accepted": true,
  "immediate_delivery_requested": true
}

The answer's agreement.collected_by is then seller_site: the order recorded the box when the session started, from your site, with the API key that sent it, and anyshop's page does not ask again. The order's dispute evidence says it was collected on your site through the API. If agreement.text is not the line you showed, cancel the session and ask the buyer again with its words.

The two fields count only once your store's owner has agreed to the Terms of Service of 14 November 2026 (section 8, "Checkout on your own site"), when the dashboard asks. Until then, or when they do not cover the words (terms_accepted without immediate_delivery_requested for a product with the setting on), they are taken and ignored, nothing is refused: the session answers collected_by: "anyshop" and anyshop's page shows the whole box.

The buyer comes back

Paid, the buyer lands on success_url?checkout=cs_.... Cancelling, they land on cancel_url?checkout=cs_..., and the keys held for them go back to stock. On the way, where they land depends on how they pay:

Paying withBack without payingPaid
StripeStripe's page sends them to the session's page on anyshop's pay host: "You have not paid yet", nothing charged, with Continue to Stripe and Cancel. Stripe's page stays open 31 minutes, and the keys are held as long.The session's page confirms the payment with Stripe, then moves on to success_url by itself.
PayPalPayPal sends them to the session's page: they can pay another way, or cancel.The session's page confirms the payment, then moves on to success_url.
Bitcoin, LitecoinThe invoice is on the session's page; they can cancel there.The page follows the payment on the chain, then moves on to success_url.

A buyer back from Stripe's page can only go back to it or cancel. To offer another way to pay, cancel the session and start a new one without payment_method.

Do not trust the return alone, nor any page on the way: confirm on your server, with GET /v1/checkout_sessions/{id} or the order.paid webhook.

curl
curl https://api.anyshop.io/v1/checkout_sessions/cs_01m3rs9d2f4k6m8p0r2t4v6x8z \
  -H "Authorization: Bearer $ANYSHOP_LIVE_KEY"

The session answers open, paid (with order, the order's ID), expired or canceled. The order.paid event carries checkout_session: { id, metadata }; verify its signature and handle each webhook-id once (see React to orders).

The keys reach the buyer by anyshop's delivery email, sent in your store's name with your support email as the reply-to, and on their order page. To show a key on your own page, read it with a key that has the audited stock:reveal scope: the Checkouts scope never returns a key.

Bank debits and vouchers

Some ways to pay on Stripe's page are not confirmed at once.

  • Bank debits (SEPA Direct Debit, US bank account, Bacs, BECS and others): the bank takes days to answer, usually 1 to 5 working days. Stripe's page sends the buyer back to the session's page, which says "Payment on its way", and anyshop emails them "Your payment is on its way". When the money clears, the order is paid and delivered. If the bank refuses it, the buyer gets "Your payment did not go through" and can pay again, another way if they like, from their order page.
  • Vouchers and transfers (OXXO, Boleto, Konbini, Multibanco, bank transfer): the buyer gets a voucher on Stripe's page and pays it elsewhere. The session's page links to it, and the keys stay held until the voucher expires, plus a day, since some are confirmed the next day.

The API has no status for a payment on its way, and no webhook for it. While a debit clears, the session stays open and its expires_at moves up to 14 days out, so the keys stay held. Treat a session that stays open with a later expires_at as waiting on the bank, not as abandoned: wait for order.paid, which arrives when the money clears, or for expired.

Cancellive key

POST /v1/checkout_sessions/{id}/cancel ends an unpaid session at once: the payment waiting on the buyer is cancelled (Stripe's page closes, an unpaid voucher is cancelled) and the keys go back to stock. A paid session is refunded instead, with POST /v1/orders/{id}/refund. The buyer can cancel too, on anyshop's payment page.

curl
curl -X POST \
  https://api.anyshop.io/v1/checkout_sessions/cs_01m3rs9d2f4k6m8p0r2t4v6x8z/cancel \
  -H "Authorization: Bearer $ANYSHOP_LIVE_KEY"

A bank debit already on its way cannot be stopped. Cancel still ends the session and frees the keys, but if the debit clears, the order is paid after all: the session turns paid, order.paid arrives, and the buyer gets fresh keys, or waits for stock. Refund it if you no longer want the sale.

A buyer who chose PayPal can go back and pay another way. A crypto invoice cannot be undone that way, since coins may already be on their way to its address: the buyer cancels instead, and your server starts a new session.

What the payment lists

On Stripe's and PayPal's pages, and in your Stripe and PayPal accounts, every payment names its order by number: Order #1001, with "Powered by anyshop.io" under it. The order gets its number when the buyer chooses to pay, so a payment the buyer never finishes leaves a gap in your order numbers. The products bought are on the order's page, in the buyer's email and in your dashboard. The payment goes to your own account, under your own business name, and the buyer's card statement shows the statement descriptor you set in Stripe.

Limits and errors

  • 30 sessions a minute per API key, and 100 open at once per store.
  • Open sessions hold at most half of a product's available keys (or one order's maximum, when that is more): the rest stays for your storefront and buy buttons. A product with stock per option counts each option's keys on their own.
  • The buyer's email: 8 checkouts in 10 minutes, as on the hosted checkout.
  • When your server keeps hitting the last two, your store's owners and admins get an email, at most one a day: a key starting checkouts you did not expect may be in the wrong hands.
  • The hosted checkout's rules apply unchanged: your blocklist, product availability, coupon limits, and a suspended store starts no checkout and takes no payment.
Statuserror.code
400invalid_body, invalidA field is missing or wrong; a return address off your allowed sites; a metadata key starting with __.
400invalid_jsonNot JSON, or a __proto__ key anywhere.
400invalid_email, invalid_coupon, invalid_payment_method
400invalid_answersA required question for the buyer is unanswered, or an answer is not what its question takes: error.param is answers. and the question's ID.
403missing_scopeThe key has no Checkouts scope.
403buyer_blockedThe buyer's email is on your blocklist. Their network and country are checked when they open url.
409sold_out, unavailable, no_payment_methods
409price_changedYou sent expected_amount and the session costs another amount now: error.amount is the new total. Show it to the buyer, then start the session again.
409store_not_approvedanyshop has not approved your store yet: no checkout starts until it has.
409store_pausedYou paused your store: no new checkout starts. See Store visibility.
409idempotency_key_reusedThe same Idempotency-Key with another body.
429rate_limited, too_many_open_sessions, too_much_stock_heldWait for open sessions to end, or cancel them, then retry.

Store visibility

Before anyshop has approved your store, its page says it opens soon, and buy buttons, pay links and checkout sessions are refused (store_not_approved, 409), whatever the setting. Once it is reviewed, Settings, General, Visibility decides who reaches it. Checkouts started from your own site follow it like this:

VisibilityYour store pageBuy buttons, pay links, the API
PublicLists your productsSell
HiddenShows your store without products; each product page still opens by its linkSell
Own site onlyClosedSell
PausedClosedRefused: store_paused (409) for a new session

Own site only is for selling from your own site alone: your anyshop store page answers "This store does not sell here", search engines leave it out, and the checkout shows no way back to it. Buy buttons, pay links and checkout sessions sell as before, and the buyer goes back to your success_url or cancel_url.

Paused stops new sales everywhere. A session already started, a payment already on its way and paid orders are not affected: they finish and deliver as usual, and order pages, Find my order and license checks keep working.

A single product can stay off your store page too (its editor: "Show on your store page"): it is left out of the list, search and the sitemap, and sells everywhere by its link.