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:
- A product list that SharePay reads.
- A checkout that creates the order and a SharePay checkout, the way your store's checkout button already does.
- 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). - Proof you run the domain. Developers, AI ordering shows one line,
like
sharepay-domain-verification=3f9c…. Serve it as plain text athttps://yourstore.com/.well-known/sharepay.txt(in Next.js, put it inpublic/.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,nameandpricePence(whole pence) are required. - Products with
inStock: falseoractive: falseare not offered. - An option value's
pricePenceis the price with that value chosen, ornullfor the product's own price. delivery_optionsis optional (up to 10). The assistant shows them to the customer, andfreeOverPenceis only shown to them; your checkout still works out the real delivery charge.- Set
discount_codes: trueif 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": {
"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:
- 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.
- If you have seen this
request_idbefore, answer with the checkout you made then. It is the same order being retried. - Store the order as pending and create a SharePay checkout session for the total with your secret API key.
- Answer
200with:
{ "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:
- Read
t(Unix seconds),n(a one-time value) andv1. - Refuse the request if
tis more than 5 minutes from your clock. - Build the text from five lines joined with a newline (
\n):t,n, the method in capitals (GETorPOST), the path with any query string exactly as requested (/api/sharepay/products?lang=en), and the raw request body (empty forGET). - Compute HMAC-SHA256 of that text with your signing secret, as hex, and
compare it with
v1in constant time. - Refuse a repeat of the same
nwithin 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.