Reserve scarce inventory before sending a buyer to crypto checkout, then convert the reservation into a sale only after verified payment. A timer reaching zero is not proof that no money is arriving. Your order system must coordinate stock, payment evidence and fulfillment.
This matters for the last event seat, a limited license key or a physical item. Unlimited downloads do not need an artificial stock limit. The controls below are a merchant-side design, not a claim that Yolfi automatically reserves inventory or prevents overselling.
Keep payment and inventory states separate
A payment request answers how a buyer can pay. A reservation answers whether a particular quantity is still allocated to that buyer. Neither record replaces the other.
Use separate records for the order, reservation, payment attempt and delivery. Save the item or ticket type, quantity, accepted price, reservation deadline and related payment identifiers. Do not let an editable browser parameter decide which scarce item a confirmed payment receives.
| Merchant-side state | Stock treatment | Next action |
|---|---|---|
| Available | Can be offered to a buyer | Create a reservation atomically |
| Held for an order | Exclude from sellable stock | Wait for payment or controlled expiry review |
| Paid and allocated | Belongs to the confirmed order | Issue or dispatch once |
| Exception review | Keep the allocation decision explicit | Resolve late payment, mismatch or uncertain status |
| Released | No longer allocated to the old order | Return to availability once |
For event ticketing with Yolfi, the live product page explicitly leaves inventory and ticket issuance with the organizer. Payment confirmation does not itself create a ticket or guarantee a remaining seat.
Reserve the last item atomically
A separate “check availability” followed by “reduce stock” can let two buyers pass the same check. Make the availability test and reservation one protected database operation. Conditional updates, row locks or equivalent controls can enforce this, depending on your database.
The PostgreSQL locking documentation explains row-level locking and competing updates. That is an implementation reference, not a requirement to use PostgreSQL.
A practical merchant flow is:
- Recalculate the order price on the server and validate the requested quantity.
- In a short database transaction, reserve only if enough unallocated stock remains.
- Save the order and reservation in that same transaction before requesting checkout. Enforce a unique order reference so repeated requests return the existing hold instead of reserving again.
- Create the payment attempt using the documented integration, then save its identifiers.
- If the external call times out, reconcile the attempt before creating another or releasing stock.
Do not keep a database transaction open while waiting for a wallet payment. A database lock protects the short allocation decision; a durable reservation covers the longer customer journey. Limit active holds per buyer and rate-limit reservation creation so unpaid attempts cannot occupy all stock indefinitely.
Link the hold to a server-created payment attempt
For dynamic orders, the Yolfi Checkout API reference keeps quantities and fulfillment data in your system. Your server submits the final amount and can associate merchantOrderId with the Checkout Session. The amount is a decimal string in the pricing currency, not a token base-unit integer or an assumed USDC amount. Store the returned session ID and the Invoice ID when available.
Reuse the same idempotency key and unchanged request when retrying an uncertain session-creation call. This protects payment-attempt creation; it does not reserve a ticket, lock inventory or deduplicate your delivery process.
For reusable payment links, do not assume one link equals one reserved unit. A shared link can be opened by multiple buyers. If your integration cannot reliably associate each accepted payment with a valid reservation, avoid using a public reusable link for the final scarce item. A separately controlled sales process is safer than promising stock you cannot allocate.
Offer USDC or USDT only where that asset and network are actually enabled in the payment flow. Inventory rules should not depend on a generic coin page being present.
Coordinate three clocks, not one countdown
Your reservation deadline, the Checkout Session expiry and the resulting Invoice's payment lifecycle are different. Record them separately. A session may already be linked to an Invoice before the reservation expires.
The Yolfi checkout lifecycle states that session status COMPLETED means an Invoice was linked; payment can still be pending. Fulfillment requires verified payment.confirmed processing, not a browser return or a screenshot.
Choose and disclose how long stock is held and what happens to a transfer detected near the deadline. There is no universal safe number of minutes across networks and payment methods. Do not advertise instant ticket delivery if your operational policy requires confirmation and review.
When a hold approaches expiry:
- Check authoritative payment state and whether an Invoice already exists.
- Distinguish no known payment from funds detected but awaiting confirmation.
- If evidence or retrieval is uncertain, put the order into review rather than declaring it unpaid.
- Stop offering an obsolete attempt where the documented integration allows it; never invent a cancellation endpoint.
- Release stock only through the same serialized decision path used for confirmation.
Stopping a page or expiring your own reservation cannot reverse a transfer already sent. The expired-invoice guide covers payment recovery; this guide focuses on who owns the scarce stock while that recovery happens.
Let confirmation and expiry compete safely
Define sellable stock as total stock minus active holds and paid allocations. Confirmation converts a hold into a paid allocation; it must not subtract from availability again. Update the reservation, order and stock ledger together, and record the delivery task durably in that same transaction.
A background expiry worker and a payment notification can arrive together. Both must operate on the same current reservation state using a transaction, lock or conditional state transition. A stale worker must not release an item already allocated to a paid order.
On verified confirmation, match the payment to the stored attempt, order, expected amount, asset and network. If the hold is still valid under your policy, allocate it once and enqueue delivery durably. Retried notifications must not decrement stock again or issue a second ticket. The webhook idempotency guide explains duplicate-event handling.
If the hold has already been released, do not silently reclaim an item allocated to another buyer. Recheck current availability atomically. If stock remains, fulfill under the accepted terms; otherwise open an exception with an owner and notify the customer. Offer a permitted alternative or a separately approved return of funds according to your terms and obligations. Do not promise an automatic refund: use the refund checklist.
Test the race before selling the last seat
Use controlled test data, not a live customer's purchase. Verify both the financial record and inventory outcome.
| Test | Required outcome |
|---|---|
| Two buyers request the final unit together | At most one valid allocation |
| Session creation times out after remote success | Reconcile the original attempt; no extra hold or checkout |
| Confirmation races with the expiry worker | One serialized allocation decision; no double release |
| Funds are detected before the deadline but confirm later | Apply the disclosed pending-payment policy |
| A confirmed payment arrives after stock was resold | Exception review, not a second sale of the same unit |
| Delivery fails after stock is allocated | Retry delivery without another stock decrement |
Also test duplicate notifications, repeated expiry jobs and a payment-state lookup outage. Monitor old unresolved holds and paid-but-undelivered orders separately. An empty stock counter alone cannot show whether buyers received what they purchased.
FAQ
Does Yolfi reserve inventory automatically?
Do not assume it does. Its ticketing page assigns inventory control and ticket issuance to your system. Keep reservation records and concurrency controls on the merchant side.
Can I release stock when the customer closes checkout?
Closing a tab does not prove payment was abandoned. Review the associated payment attempt and any Invoice before releasing the reservation under your policy.
Should pending confirmations hold stock forever?
No. Define a bounded escalation and review process, including customer communication. Do not mistake an arbitrary timeout for evidence that a transfer cannot still arrive.
What if there is no stock after a late payment?
Keep the payment recorded, stop automatic fulfillment and resolve the exception. Do not take another customer's allocation or treat a paid order as though it never existed.
Conclusion: allocate once, deliver once
The safe unit of work is an order with a traceable reservation and verified payment, not a reusable URL or a countdown. Reserve atomically, reconcile uncertain attempts and serialize confirmation against expiry. If the integration cannot handle late payments and scarce stock together, restrict the sales process before advertising the last available item.
