Skip to main content

AI ordering

Customers can connect their SharePay account to ChatGPT or Claude. With AI ordering on, they can then ask the assistant to buy from your shop, alone or split with people they name: "Get the hamper from your shop for me and three friends." Their assistant creates the order through your normal checkout, and SharePay sends everyone their share to pay. You're paid when everyone has paid, exactly as for a split started on your site.

The assistant never sees a card and can't pay. Every share is paid by the person it belongs to, on SharePay's normal payment page.

Without setting anything up​

You don't need AI ordering on for assistants to buy from you. An assistant that browses your website can fill the basket and go through your checkout like a person. When it reaches your SharePay checkout page, it hands that page to SharePay, and the customer approves their share on their phone, alone or split with friends. Your prices, discounts and delivery are whatever your checkout already worked out, and the order arrives exactly as any other.

Turning on AI ordering below adds the faster way: the assistant can search your products and order in seconds, without browsing your website.

What you need​

Two addresses on your own domain (the allowed return domain in Developers), both over https, a signing secret, and proof that the domain is yours:

  1. A product list that SharePay reads.
  2. A checkout that creates the order and a SharePay checkout, the way your store's checkout button already does.
  3. A signing secret. Under Developers, AI ordering, choose Create signing secret and store it on your server as SHAREPAY_SIGNING_SECRET. SharePay signs every request to your two addresses with it. Refuse any request whose signature doesn't check out (see Checking the signature).
  4. Proof you run the domain. Developers, AI ordering shows one line, like sharepay-domain-verification=3f9c…. Serve it as plain text at https://yourstore.com/.well-known/sharepay.txt (in Next.js, put it in public/.well-known/sharepay.txt). The SharePay command writes this file for you.

Then turn on AI ordering and save both addresses. Before it switches on, SharePay checks that:

  • the proof file is there;
  • your product list answers a signed request with products;
  • both addresses refuse (401) a request with no signature, and one signed with the wrong secret.

If any check fails, AI ordering stays off and the message says which one. The same checks run again whenever you change an address or your domain.

Product list​

GET, answering 200 with JSON:

{
"products": [
{
"id": "hamper-large",
"name": "Luxury hamper",
"description": "Cheese, chutney and a bottle of fizz.",
"pricePence": 4500,
"inStock": true,
"active": true,
"images": ["https://yourstore.com/images/hamper.jpg"],
"options": [
{
"name": "Size",
"values": [
{ "name": "Regular", "pricePence": null, "inStock": true },
{ "name": "Large", "pricePence": 5500, "inStock": true }
]
}
]
}
],
"delivery_options": [
{ "id": "standard", "name": "Standard (2 to 4 days)", "pricePence": 395, "freeOverPence": 4000 },
{ "id": "express", "name": "Express (next day)", "pricePence": 795 }
],
"discount_codes": true
}
  • In a product, id, name and pricePence (whole pence) are required.
  • Products with inStock: false or active: false are not offered.
  • An option value's pricePence is the price with that value chosen, or null for the product's own price.
  • delivery_options is optional (up to 10). The assistant shows them to the customer, and freeOverPence is only shown to them; your checkout still works out the real delivery charge.
  • Set discount_codes: true if your checkout accepts discount codes.
  • Up to 500 products and 1 MB are read.
  • A plain array of products (the first version of this format) still works, with no delivery options or discount codes.

Checkout​

POST with a JSON body:

{
"version": 2,
"request_id": "3f9c0d6b2a8e4c1f9b7a5d3e1c0f8a6b",
"items": [{ "id": "hamper-large", "qty": 1, "choice": { "Size": "Large" } }],
"customer": {
"email": "[email protected]",
"name": "Alice Smith",
"address": { "line1": "1 High Street", "line2": "", "city": "London", "postcode": "SW1A 1AA" }
},
"delivery_option": "express",
"discount_code": "SUMMER10"
}

delivery_option and discount_code appear only when the customer chose them. Then:

  1. Price the order from your own catalogue, exactly as your website's checkout does: your prices, your sales, your delivery rules, your discount codes. Never trust a price sent to you; none is.
  2. If you have seen this request_id before, answer with the checkout you made then. It is the same order being retried.
  3. Store the order as pending and create a SharePay checkout session for the total with your secret API key.
  4. Answer 200 with:
{ "checkout_url": "https://share-pay.co.uk/checkout/pay/..." }

To refuse, answer 400 with words the customer can read, either { "error": "Plain words" } or { "error": { "code": "invalid_discount_code", "message": "SUMMER10 has expired." } }. SharePay passes your message to the assistant, and nobody is charged.

Fulfil on the usual checkout_split.paid webhook. Nothing else changes.

Checking the signature​

Every request carries one header:

X-SharePay-Signature: t=1795700000,n=Qm9vdHN0cmFwX25vbmNl,v1=5f2c…

To check it:

  1. Read t (Unix seconds), n (a one-time value) and v1.
  2. Refuse the request if t is more than 5 minutes from your clock.
  3. Build the text from five lines joined with a newline (\n): t, n, the method in capitals (GET or POST), the path with any query string exactly as requested (/api/sharepay/products?lang=en), and the raw request body (empty for GET).
  4. Compute HMAC-SHA256 of that text with your signing secret, as hex, and compare it with v1 in constant time.
  5. Refuse a repeat of the same n within those 5 minutes.
import crypto from "node:crypto";

// One-time values seen in the last 5 minutes. Use a shared store (Redis, your
// database) if you run more than one server.
const seen = new Map();

export function isFromSharePay(req, rawBody, secret) {
for (const [n, at] of seen) if (Date.now() - at > 300_000) seen.delete(n);
const header = req.headers["x-sharepay-signature"] ?? "";
const p = Object.fromEntries(header.split(",").map((kv) => kv.split("=")));
const t = Number(p.t);
if (!t || !p.n || !p.v1 || Math.abs(Date.now() / 1000 - t) > 300) return false;
if (seen.has(p.n)) return false;
const text = [t, p.n, req.method, req.originalUrl ?? req.url, rawBody].join("\n");
const want = crypto.createHmac("sha256", secret).update(text).digest("hex");
const ok = want.length === p.v1.length && crypto.timingSafeEqual(Buffer.from(want), Buffer.from(p.v1));
if (ok) seen.set(p.n, Date.now());
return ok;
}

Keep the secret and your SharePay API key on your server only: never in browser code, and never in your code repository.

Rules SharePay applies​

  • Both addresses must be on your allowed return domain, on the normal https port, and resolve to a public address.
  • SharePay checks your domain-proof file again at least once a day while AI ordering is on. If it's gone, no orders are sent until it's back.
  • Redirects are not followed, and each request times out after 10 seconds.
  • The checkout you return must be your own, open, and unsplit. Anything else is refused before anyone is emailed.
  • Each share is at least £1, up to 10 people per order, and nobody who opted out of SharePay emails is contacted.