Skip to content

Checkout and orders

View .mdllms.txt

One order buys one listing; a cart buys several, one order each, paid once. Checkout is three calls and Stripe’s payment form; after that, the order moves on by transitions until the buyer has it and the seller is paid. Every call sends the buyer’s session, unless they check out as a guest: see Guest checkout.

Show what the buyer will pay before they pay it:

POST /v1/me/orders/quote
{
"listing_id": "8f3c…",
"currency": "EUR",
"delivery": {
"method": "shipping",
"option": "standard",
"address": { "name": "Mia Holm", "line1": "Hallvägen 29", "postal_code": "121 62", "city": "Johanneshov", "country": "SE", "phone": "+46…" }
},
"voucher_code": "SPRING10"
}
{
"currency": "EUR",
"total": 61900,
"line_items": [
{ "code": "item", "label": "Eames lounge chair", "unit_price": 59000, "quantity": 1, "amount": 59000 },
{ "code": "shipping", "label": "Shipping", "unit_price": 8800, "quantity": 1, "amount": 8800 },
{ "code": "voucher", "label": "Voucher SPRING10", "unit_price": -5900, "quantity": 1, "amount": -5900 }
]
}
  • Show line_items as they come, by label, and total as the amount to pay. Don’t add things up yourself.
  • Quote again whenever the delivery, address or voucher changes. Placing the order prices it the same way.
  • currency is what the buyer pays in: one of the marketplace’s, the listing’s when left out.

Line item codes:

Code Meaning
item The listing.
shipping Delivery, priced.
collect Collected at the showroom or warehouse where it’s stored. Free.
shipping_address_needed Ask for the address; the price comes with it. Placing without one fails.
shipping_quote Delivery can’t be priced here: the marketplace sends a quote after the order.
voucher A discount (negative).

A voucher that doesn’t apply gives 422 with the reason on body.voucher_code. Show it next to the voucher field.

POST /v1/me/orders
Idempotency-Key: 6f1d3c5e-…
{ the same body as the quote }
{
"order": { "id": "1a2b…", "state": "pending_payment", "total": 61900, "currency": "EUR", "available_transitions": [] },
"payment": { "client_secret": "pi_3Q…_secret_…" }
}
  • This reserves the listing and starts the payment. The buyer has 15 minutes to pay; then the order becomes payment_expired and the listing is released.
  • Send an Idempotency-Key (a new UUID for each press of “Pay”), so a retried request can’t place two orders.
  • 409 means it can’t be bought right now: sold, reserved by someone else, or the delivery isn’t possible. Show the detail and go back to the listing.

Payments run on the marketplace’s own Stripe account. Use Stripe’s Payment Element with that account’s publishable key and the order’s client_secret. Read the key from GET /v1/marketplace (payments.stripe_publishable_key) rather than hard-coding it, so the shop follows the marketplace if it changes accounts. It’s only empty for a marketplace that hasn’t connected its own account yet; then the team gives you the key to use. Cards, Klarna and the other methods the marketplace has turned on in Stripe appear by themselves.

import { loadStripe } from '@stripe/stripe-js'
const stripe = await loadStripe(STRIPE_PUBLISHABLE_KEY)
const elements = stripe.elements({ clientSecret: payment.client_secret })
elements.create('payment').mount('#payment')
// On "Pay":
const { error } = await stripe.confirmPayment({
elements,
confirmParams: { return_url: `${location.origin}/orders/${order.id}` },
})
if (error) showError(error.message) // otherwise Stripe sends the buyer to return_url

When Stripe confirms the payment, mongrl moves the order to purchased. That happens in the background, a moment after the buyer lands on your order page: read the order (GET /v1/me/orders/{id}) and, while it’s still pending_payment, check again every couple of seconds.

Stripe also returns buyers who leave paying unfinished: they went back from their bank’s page, or the payment failed. The order is still pending_payment and the listing stays reserved for them for 15 minutes, so don’t leave them waiting for a confirmation that won’t come:

  • Stripe adds payment_intent_client_secret to return_url. Read the payment with stripe.retrievePaymentIntent(clientSecret): while its status is requires_payment_method, requires_action or requires_confirmation, show the Payment Element again with that client secret, for the same order. processing and succeeded mean it’s on its way: keep checking the order.
  • If the buyer starts over and orders the same listing again, mongrl expires their unpaid order first (cancelling its payment and giving back the stock and any voucher), so their own reservation never blocks them. Until then the listing shows as sold (stock: 0), to the buyer too, so your shop can remember the unpaid order in the browser and offer “Finish your payment” on the listing instead.

In the test environment, pay with Stripe’s test card 4242 4242 4242 4242, any future date and any CVC.

Shoppers don’t need to sign in to buy. From your server, with the secret key and no session:

POST /v1/orders/quote (same body as /v1/me/orders/quote)
POST /v1/orders
{ "email": "dora@example.com", "first_name": "Dora", "newsletter": true,
"shopper_ip": "203.0.113.7", "listing_id": "…", "delivery": { … } }
  • The order goes on the account with that email. If there isn’t one, an account that signs in with emailed links is made. Nobody is signed in, so typing someone’s email reveals nothing of theirs.
  • The response has the order, payment.client_secret (pay as in step 3) and guest_token. Keep the token with the shopper in an httpOnly cookie, never in a link. GET /v1/orders/{id}?token=… shows that one order, e.g. on the page Stripe returns to.
  • Everything after the confirmation (booking a delivery time, messages, the order list) needs the buyer signed in. The order emails link to the order page: when they aren’t signed in, offer to email them a sign-in link (POST /v1/sessions/email-link) that brings them back to it.
  • Pass the shopper’s IP address as shopper_ip. Guest checkouts are limited per shopper and per email, so nobody can keep listings reserved with orders they never pay; past the limit, the answer is 429.
  • newsletter: true signs them up to the marketplace’s newsletter. It works on POST /v1/me/orders too.

Buyers can put listings from any sellers in a cart and pay for them in one go. Each listing still becomes its own order, exactly as if bought alone: its own delivery, commission, seller payout, refund and emails to the seller. Only the payment is shared. GET /v1/marketplace has payments.cart: when it’s false, the marketplace takes one listing per checkout, so show Buy now only.

POST /v1/me/checkouts/quote
{
"items": [
{ "listing_id": "8f3c…", "delivery": { "method": "shipping" } },
{ "listing_id": "a71e…", "delivery": { "method": "pickup" } }
],
"address": { "name": "Mia Holm", "line1": "Hallvägen 29", "postal_code": "121 62", "city": "Johanneshov", "country": "SE" },
"voucher_code": "SPRING10"
}
{
"currency": "SEK",
"total": 850000,
"items": [
{ "listing_id": "8f3c…", "total": 650000, "line_items": [ … ] },
{ "listing_id": "a71e…", "total": 200000, "line_items": [ … ] }
]
}
  • Each item has its own delivery, from what its listing offers. address is used by every shipped item that has none of its own, so ask for it once.
  • Show each item’s line_items under it, and total as the amount to pay.
  • A voucher goes on every item it can and counts as one use.
  • 409 names the item that can’t be bought: errors[0].location is body.items[n] and errors[0].value its listing id. Mark it in the cart (usually sold) and let the buyer remove it.
  • Up to 20 listings, each once (quantity for more of the same).

Then check out with the same body:

POST /v1/me/checkouts
Idempotency-Key: 6f1d3c5e-…
{ the same body as the quote }
{
"checkout": { "id": "c9d0…", "currency": "SEK", "total": 850000, "orders": [ { "id": "1a2b…", "state": "pending_payment", "checkout_id": "c9d0…" }, … ] },
"payment": { "client_secret": "pi_3Q…_secret_…" }
}
  • Every order is placed and reserved, or none: if one item went in the meantime, you get the 409 above and nothing is reserved.
  • Pay with payment.client_secret as in step 3. All the orders move to purchased together; GET /v1/me/checkouts/{id} shows them, e.g. on the confirmation page.
  • After that, each order is followed on its own (/v1/me/orders/{id}). Orders bought together share a checkout_id.
  • The buyer gets one receipt for the whole checkout. Each seller gets their own email, as for a single sale.
  • Cancelling one order refunds only that order’s total; the others carry on.
  • Guests check out the same way from your server: POST /v1/checkouts/quote and POST /v1/checkouts with the guest fields (email, first_name, shopper_ip…) beside the cart. guest_token then shows the checkout: GET /v1/checkouts/{id}?token=….
  • payment_method: "invoice" works as for one order.

The marketplace’s team can let company customers pay by invoice. In the console, they turn on Pays by invoice on a company account, with a billing address, an invoice email and how many days they have to pay.

  • GET /v1/me then has invoicing (enabled, email, address, terms_days). Offer Invoice as a payment method only when it’s there. It needs a signed-in buyer; guests always pay by card.
  • Place the order with "payment_method": "invoice" on POST /v1/me/orders. There’s no payment step: the order is purchased at once, and the response has no payment. Other accounts get 403.
  • The order has payment_method: "invoice" and invoice: who’s invoiced (as at the order) and, once the team marks them, sent_at, due_at and paid_at. Show those on the order page.
  • The order moves on as any other. Nothing goes through Stripe: the team sends the invoice, makes any refund and pays the seller outside mongrl, and marks it in the console.
(new) ─request-payment─▶ pending_payment ─confirm-payment─▶ purchased
└─expire-payment (15 min)─▶ payment_expired
(new) ─place-on-invoice─▶ purchased (invoice orders)
purchased ─mark-delivered─▶ delivered ─mark-received / auto (14 days)─▶ received
purchased ─mark-received-early─▶ received
purchased ─cancel / auto-cancel (14 days)─▶ canceled
delivered ─dispute─▶ disputed ─resolve-received─▶ received
└─resolve-canceled / auto (60 days)─▶ canceled

payment_expired, received and canceled are final. Each order has history: every transition with when it happened, for a timeline on the order page.

Each order has available_transitions: what this user may do now. Show a button for each and nothing else.

POST /v1/me/orders/{id}/transitions/mark-delivered
{ "data": { "tracking_number": "JJSE00012345", "carrier": "PostNord" } }
Transition Who When
mark-delivered the seller It’s sent or handed over. data can carry tracking_number and carrier; they appear in order.delivery.
mark-received the buyer They have it. The seller is paid.
mark-received-early the buyer They have it before it was marked sent (e.g. picked up). The seller is paid.
dispute the buyer Something’s wrong after delivery. The marketplace’s team resolves it.

When the marketplace delivers a listing itself (fulfilment: marketplace, e.g. stored listings), its team marks the order sent in the console. The timers keep orders moving if nobody acts: an order that’s never sent is canceled and refunded after 14 days; a delivered order counts as received after 14 days.

  • GET /v1/me/orders lists the buyer’s purchases; ?as=seller lists their sales. Filter with state; page with limit and offset.
  • Each order has line_items, total, delivery and, for the seller, payout: subtotal, commission, storage_fee, amount and its status (pending until the buyer has it, then paid; waiting_for_payout_details until the seller sets up payouts).

Buyers and sellers get emails when an order is paid, sent and received, each linking to https://<your shop>/<lang>/orders/<id>. Build that page. See Pages your shop needs.

  • Checkout: delivery choice, address, voucher, live quote, “Pay” with the Payment Element.
  • Idempotency-Key on placeOrder, placeGuestOrder, checkOut and guestCheckOut.
  • A cart when payments.cart is on: add and remove listings, mark sold ones, one checkout for them all.
  • Guest checkout: email, name and newsletter box; the guest token in a cookie; the confirmation page reads GET /v1/orders/{id}?token=.
  • The order page waits for purchased after Stripe returns, then shows the timeline and the buttons from available_transitions.
  • A payment the buyer left unfinished can be paid again on the order page. See When the buyer doesn’t finish paying.
  • A delivery-time picker when the order offers one. See Shipping and delivery.