Stock Reservation
Validates variant stock and price before checkout and holds reserved inventory until payment settles, extending the official Payload ecommerce plugin.
Installation
pnpm add payload-stock-reservation About
This plugin sits on top of `@payloadcms/plugin-ecommerce` and fixes two gaps in its checkout flow. The official plugin reads availability in `initiatePayment` and decrements stock in `confirmOrder`, but writes nothing in between, so two shoppers can both pass validation on the last unit. It also skips variant stock and price checks entirely, because the variant branch sits inside a condition that requires the item to have no variant. Both problems let stock go negative after payment. `stockReservationPlugin` wraps the `post /payments/:adapter/initiate` and `post /payments/:adapter/confirm-order` endpoints rather than replacing them. Before initiation it re-reads the cart, validates every line against recorded stock minus live holds, and writes a hold outside the request transaction so competing requests see it immediately. Holds on the same product or variant are ranked oldest first, with identifier tie-breaking, and a hold keeps its stock only if the running total up to and including it fits inside recorded stock. On confirmation the original handler runs first, then the cart's holds are released. The plugin adds a single `stock-holds` collection with indexed `cart`, `stockCollection`, `stockDocument`, and `expiresAt` fields, and nothing is added to products, variants, carts, or orders. The collection is closed to API access and hidden in the admin panel. A `/stock-reservation/release-expired` endpoint deletes expired holds and accepts either a signed-in user or a `Bearer` secret. `sweepOnCheckout` deletes expired holds for the current cart at the start of every checkout, so no scheduler is required. Options include `ttlSeconds` (default 900), `defaultCurrency`, `refuseNegativeInventory`, `holdScanLimit`, and slug overrides for the carts, products, variants, and holds collections. The plugin must be listed after `ecommercePlugin`, and it logs a clear error on startup if it finds no checkout endpoints to wrap. It has no runtime dependencies and no admin components, which keeps it stable across minor Payload releases. It is verified against Payload 3.88.0 and requires Payload 3.88 or newer.
Package info
- Package name
payload-stock-reservation- Latest version
1.0.0- Unpacked size
- 40 kB
- License
- MIT
- Weekly downloads
- 144
- Last publish
- Aug 21, 2026
More from Poseidonas
View profileBarcodes
Adds Code 128, EAN-13 and QR code generation to Payload product collections with a printable label page and optional admin print buttons.
AI Manager
Writes product titles, descriptions, attributes and translations into Payload fields via Claude, ChatGPT, Gemini or Kimi, and skips content it already generated.
EU VAT
Records EU VAT on Payload ecommerce orders: country rates, B2B reverse charge, VIES validation, and OSS reporting totals.
Stock Alerts
Sends a shop one email when product or variant inventory crosses a low stock threshold, with backorder handling and a storefront-readable status field.
Shipping Rates
Adds shipping zones, rate calculation, and a quote endpoint to Payload ecommerce shops.
Shipping Classes
Adds weight, dimensions, and shipping class fields to Payload products and variants, storing values canonically in grams and millimetres for cart totalling.