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.
1. Quote
Section titled “1. Quote”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_itemsas they come, bylabel, andtotalas 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.
currencyis 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.
2. Place the order
Section titled “2. Place the order”POST /v1/me/ordersIdempotency-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_expiredand 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. 409means it can’t be bought right now: sold, reserved by someone else, or the delivery isn’t possible. Show thedetailand go back to the listing.
3. Take the payment with Stripe
Section titled “3. Take the payment with Stripe”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_urlWhen 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.
When the buyer doesn’t finish paying
Section titled “When the buyer doesn’t finish paying”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_secrettoreturn_url. Read the payment withstripe.retrievePaymentIntent(clientSecret): while itsstatusisrequires_payment_method,requires_actionorrequires_confirmation, show the Payment Element again with that client secret, for the same order.processingandsucceededmean 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.
Guest checkout
Section titled “Guest checkout”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) andguest_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 is429. newsletter: truesigns them up to the marketplace’s newsletter. It works onPOST /v1/me/orderstoo.
Several listings at once
Section titled “Several listings at once”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.addressis used by every shipped item that has none of its own, so ask for it once. - Show each item’s
line_itemsunder it, andtotalas the amount to pay. - A voucher goes on every item it can and counts as one use.
409names the item that can’t be bought:errors[0].locationisbody.items[n]anderrors[0].valueits listing id. Mark it in the cart (usually sold) and let the buyer remove it.- Up to 20 listings, each once (
quantityfor more of the same).
Then check out with the same body:
POST /v1/me/checkoutsIdempotency-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
409above and nothing is reserved. - Pay with
payment.client_secretas in step 3. All the orders move topurchasedtogether;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 acheckout_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/quoteandPOST /v1/checkoutswith the guest fields (email,first_name,shopper_ip…) beside the cart.guest_tokenthen shows the checkout:GET /v1/checkouts/{id}?token=…. payment_method: "invoice"works as for one order.
Pay by invoice
Section titled “Pay by invoice”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/methen hasinvoicing(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"onPOST /v1/me/orders. There’s no payment step: the order ispurchasedat once, and the response has nopayment. Other accounts get403. - The order has
payment_method: "invoice"andinvoice: who’s invoiced (as at the order) and, once the team marks them,sent_at,due_atandpaid_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.
Order states
Section titled “Order states”(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)─▶ receivedpurchased ─mark-received-early─▶ receivedpurchased ─cancel / auto-cancel (14 days)─▶ canceleddelivered ─dispute─▶ disputed ─resolve-received─▶ received └─resolve-canceled / auto (60 days)─▶ canceledpayment_expired, received and canceled are final. Each order has history: every transition with when it happened, for a timeline on the order page.
Moving an order on
Section titled “Moving an order on”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.
Listing orders
Section titled “Listing orders”GET /v1/me/orderslists the buyer’s purchases;?as=sellerlists their sales. Filter withstate; page withlimitandoffset.- Each order has
line_items,total,deliveryand, for the seller,payout:subtotal,commission,storage_fee,amountand itsstatus(pendinguntil the buyer has it, thenpaid;waiting_for_payout_detailsuntil the seller sets up payouts).
Emails mongrl sends
Section titled “Emails mongrl sends”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.
Checklist
Section titled “Checklist”- Checkout: delivery choice, address, voucher, live quote, “Pay” with the Payment Element.
-
Idempotency-KeyonplaceOrder,placeGuestOrder,checkOutandguestCheckOut. - A cart when
payments.cartis 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
purchasedafter Stripe returns, then shows the timeline and the buttons fromavailable_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.