Commerce API
Checkout & payment
One call. Revalidated server-side, idempotent, stock held safely.
const result = await mercestack.checkout({
email: "customer@example.com",
});
result.order.number; // "ORD-000042"
result.paymentLink; // hosted payment page slug, or null
result.paid; // true when gift cards covered it
result.library; // { accessToken, count } when digital goods were boughtOr hand the whole thing over and let us take the payment:
await mercestack.openCheckout({
email,
returnUrl: "https://shop.example.com/thank-you",
});What happens on our side
- Every product is rechecked as still published and every variant as still active.
- Stock is reserved under a row lock, spread across warehouses if one cannot cover it. Two shoppers racing for the last unit: exactly one gets it.
- The discount is re-resolved and its usage count incremented under lock, so a code limited to 100 uses is used 100 times, not 103.
- Gift cards are charged, in the same transaction as the order.
- The order is written with a snapshot of every line — name, SKU, price — so a price change tomorrow does not rewrite yesterday's order.
- A payment intent is created, unless there is nothing left to pay.
An unpaid order holds its stock for one hour. If the customer never pays, the reservation is released automatically and the stock goes back on sale — a closed tab does not hold the last unit all day.