paid now (scope orders:read).
Every request on this page goes to
https://connect.laces.run/v1, from
your server, with Authorization: Bearer <token>. Laces must first turn
on payments for your organization, and your API key needs payments:write,
orders:write and orders:read. Never send an
organization id: Laces takes the organization from the token. The client
secret stays on your server, never in a browser or an LLM chat. There is
no sandbox: a pay request moves real money.Set it up
In the Laces app (app.laces.run), an owner or admin opens Settings → Developers → Webhooks, adds a publichttps URL, picks
the events, and copies the signing secret (LCSWHSEC-…-X, shown once) to your
server. Send test event posts a signed ping, with no money involved.
Webhooks go to every subscribed endpoint of your organization, for
every order: ticket orders and payments, whoever created them. Once
Laces turns payments on, endpoints you already have start receiving payment
orders, and API keys with
orders:read start seeing them in reads and lists.
Branch on data.order.order_type.What is different from a ticket order
source_site is the host of source_url, or of the key’s default site. It
says where you said the buyer was; it is not proof. No payload carries the
buyer’s name, email or phone: read the order for those.
The payloads
order.paid
order.failed
order.refunded (the price only)
order.refunded (part)
order.paidcan be late or out of order. Read the order and fulfil only if it ispaidnow: it may have been refunded since.order.failedsays an attempt failed, not that the buyer gave up. It can arrive while they are already trying again, and the order can still becomepaid. It is sent once per order: a second failure sends nothing. Itsdata.order.statusisfailedorexpired. It is not sent for a try that never reached the payment provider. Don’t release stock or places on it: at your own deadline, read the order.- An abandoned payment sends nothing. Read the order.
refund.amountis in the order’scurrency, minor units. For a cross-border payment that is the buyer’s currency, notrequested_currency.refundedmeans the price is back; less ispartially_refunded. Act onrefund.amount, not only on the status. Order reads don’t show refunded amounts, and a refund that fails sends nothing. The fee can come back later, and one charge of an order paid twice can be returned without an event: see Refunds.order.refundedis not proof that the buyer has the money. Where your balance is too low and you pay the buyer directly, it is sent when Laces records the refund, before you have paid them.
A complete handler (Node, Express)
webhook.js
db must do this:
The price below is subtotal - discount_total + donation_total, on ticket
orders and payments alike (on a payment it equals subtotal). stateOf reads
fulfilled, undone and released of the purchase, shared by its ticket orders
and payments. fulfilOnce, recordRefund, undo, rebook, release and
adopt are one transaction each that locks the purchase’s row. They are
short and never take withLock, which can be held for minutes.
fulfilOnce(purchaseId, order): setsfulfilledtoorder.idif it is empty and the purchase is not released. Onlyrebookchanges it later. Returns"fulfilled", or does nothing and returns"already"(this same order did it, undone since or not),"refunded"(there are refunds saved fororder.id, and they reach the price),"undone"(another order did it and it was undone),"paid_by_other_order", or"released"(nothing did it, and the stock or places were given back).rebook(purchaseId, order): only if the purchase is released or undone, and no refunds saved fororder.idreach the price. Takes stock or places again, clearsundoneandreleased, setsfulfilledtoorder.id. In any other case it changes nothing, so twice is the same as once and a purchase that stands is never overwritten.undo(purchaseId, orderId): once, and only ifpurchase.fulfilledisorderIdandpurchase.undoneis empty: setspurchase.undonetoorderIdand takes the goods or places back. A person who undoes by hand uses it too.purchase.fulfilledstays set.recordRefund(purchaseId, order, refund): saves the refund once perrefund.id, withorder.id, then looks at all the refunds saved for that order, also when this one was saved before:purchase.undoneisorder.id: returns"recorded". The fee coming back later, or an event after an undo by hand, changes nothing.- They are less than the price: returns
"short", for a person to adjust. - They reach the price: does what
undodoes, in this same transaction, so a crash can’t save the refund without the undo. Returns"undone", or"recorded"if another order fulfilled the purchase, or none did. So refunding the second of two paid orders never undoes a real purchase.
priceIsBack(order): do the refunds saved fororder.idreach the price?saveForReview(purchaseId, order, why): a person looks at it, once per order and reason, also after they closed it. Unknown payments go there too.attemptsOf(purchaseId): its payments.ticketOrdersOf(purchaseId): its event orders,{ orderId, unansweredAt? }. Keep them apart: a payment retry can’t reuse a ticket order.release: gives kept stock or places back, once, and setsreleased. Never iffulfilledis set, so it does nothing after an undo, which already gave them back.adopt,findByTicketOrderId,saveTicketOrder: only if you move from event orders.adopt(purchaseId, orderId, { undone })setsfulfilled, andundoneif asked, only wherefulfilledis empty.saveTicketOrder(purchaseId, orderId)adds the order toticketOrdersOfonce.seenDelivery,markDelivery: theX-Laces-Deliveryids you have handled.
LCSWHSEC- and -X. Roll signing
secret has no overlap: the old one stops at once, and queued events are signed
with the new one, so deploy the new secret straight away. The 503 above keeps
Laces trying meanwhile; a 400 stops after 3 tries. Those 503s still count
towards the 50 failures in a row that switch the endpoint off. Other languages:
Webhooks.
Delivery
Answer any2xx within 10 seconds. Otherwise Laces tries again after about 1
minute, 5 minutes, 30 minutes, 2, 6 and 12 hours: 7 attempts in all. Redirects
are not followed. Network errors, timeouts, 5xx, 408 and 429 use every
attempt; any other 4xx stops after 3. After 50 failures in a row the
endpoint is switched off until you re-enable it in the app.
Reconcile: catch what you missed
Every few minutes, read each purchase you are still waiting for (GET /orders/{orderId}, scope orders:read). Once a day, list the payments
and compare them with your records:
Response 200
next_cursor is null. A page can be short, or even
empty, and still have a next page.
laces.js
reconcile.js
partially_refunded can’t be seen here. Check the app when you
close such a review.
order_type=ticket lists ticket orders only. Without the filter you get both.
event_id never matches a payment.