merce.STACK
merce.STACK
Skip to content
PricingDevelopersSecurityAbout
Log inGet started

Commerce API

  • Quickstart
  • Keys & authentication
  • Products & catalog
  • Carts
  • Checkout & payment
  • Digital products
  • Webhooks
  • Errors
  • Without a build step
  • API reference

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 bought

Or 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

  1. 1.Every product is rechecked as still published and every variant as still active.
  2. 2.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.
  3. 3.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.
  4. 4.Gift cards are charged, in the same transaction as the order.
  5. 5.The order is written with a snapshot of every line — name, SKU, price — so a price change tomorrow does not rewrite yesterday's order.
  6. 6.A payment intent is created, unless there is nothing left to pay.

Checkout is idempotent

A double-tapped Pay button and a retried request both get the order that already exists. Neither creates a second one, and neither charges twice.

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.

Never treat a redirect back as proof of payment

A query parameter on your success page is set by the browser, and a browser is not a witness. Wait for the order.paid webhook, or read the order back from the API. This is the single most common way an online shop gives away stock.

PreviousCartsNextDigital products
Create a workspaceTalk to usPricing

The business operating system. One workspace for structure, customers, communication, money and the automation between them.

Create your workspace

Platform

  • Overview
  • Structure & work
  • Customers & communication
  • Finance & commerce
  • Flow & AI Workforce
  • Analytics & files

Developers

  • Documentation
  • Quickstart
  • Keys & authentication
  • Carts & checkout
  • Webhooks
  • API reference

Company

  • About
  • Pricing
  • Security
  • Contact
  • Report a vulnerability

Legal

  • Privacy
  • Terms
  • Cookie policy
  • GDPR
  • Privacy contact

© 2026 Mercestack. All rights reserved.

Mercestack StructureOS