Poseidonas

payload order numbers

by Poseidonas
Stores & catalogs
v3
>=3.88 <4
MIT

Overview

Summary generated from the README

Assigns each order a short formatted number such as ORD-01042 in sequence. It adds an order number field and a hidden sequence field to the orders collection, plus a closed reservations collection that claims each value in its own transaction. Requires Payload 3.88 or newer and works with the ecommerce plugin or any orders collection on PostgreSQL or MongoDB.

Features

  • Configurable prefix, suffix, zero padding and starting value
  • Claims numbers via a separate reservations collection to stay unique under concurrency
  • Unique indexed order number field shown read only in the admin sidebar
  • Works with the ecommerce plugin or any custom orders collection
  • Can be disabled while keeping the fields so the database schema stays the same
  • Saves the order without a number if all attempts are exhausted

Use cases

  • Give customers a readable order reference to quote over the phone or in support emails
  • Replace raw MongoDB ObjectIds or integer ids as the visible order identifier
  • Create many orders at the same moment without duplicate numbers

From the author

Human readable sequential order numbers for Payload ecommerce, unique under concurrency.

Installation

npm i payload-order-numbers

1

Stars

0

Forks

0

Open Issues

2 weeks ago

Last Updated

14

Weekly Downloads

v1.0.2

npm Version

16.3 KB

Unpacked Size

0

Dependencies

GitHub stars

10 since Sep 6

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 20261
Dec 4, 20261
Dec 3, 20261
Dec 2, 20261
Dec 1, 20261
Nov 30, 20261
Nov 29, 20261
Nov 28, 20261
Nov 27, 20261
Nov 26, 20261
Nov 25, 20261
Nov 24, 20261
Nov 23, 20261
Nov 22, 20261
Nov 21, 20261
Nov 20, 20261
Nov 19, 20261
Nov 18, 20261
Nov 17, 20261
Nov 16, 20261
Nov 15, 20261
Nov 14, 20261
Nov 13, 20261
Nov 12, 20261
Nov 11, 20261
Nov 10, 20261
Nov 9, 20261
Nov 8, 20261
Nov 7, 20261
Nov 6, 20261
Nov 5, 20261
Nov 4, 20261
Nov 3, 20261
Nov 2, 20261
Nov 1, 20261
Oct 31, 20261
Oct 30, 20261
Oct 29, 20261
Oct 28, 20261
Oct 27, 20261
Oct 26, 20261
Oct 25, 20261
Oct 24, 20261
Oct 23, 20261
Oct 22, 20261
Oct 21, 20261
Oct 20, 20261
Oct 19, 20261
Oct 18, 20261
Oct 17, 20261
Oct 16, 20261
Oct 15, 20261
Oct 14, 20261
Oct 13, 20261
Oct 12, 20261
Oct 11, 20261
Oct 10, 20261
Oct 9, 20261
Oct 8, 20261
Oct 7, 20261
Oct 6, 20261
Oct 5, 20261
Oct 4, 20261
Oct 3, 20261
Oct 2, 20261
Oct 1, 20261
Sep 30, 20261
Sep 29, 20261
Sep 28, 20261
Sep 27, 20261
Sep 26, 20261
Sep 25, 20261
Sep 24, 20261
Sep 23, 20261
Sep 22, 20261
Sep 21, 20261
Sep 20, 20261
Sep 19, 20261
Sep 18, 20261
Sep 17, 20261
Sep 16, 20261
Sep 15, 20261
Sep 14, 20261
Sep 13, 20261
Sep 12, 20261
Sep 11, 20261
Sep 10, 20261
Sep 9, 20261
Sep 8, 20261
Sep 7, 20261
Sep 6, 20261
npm weekly downloads

11−10 since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 202611
Dec 4, 202615
Dec 3, 202620
Dec 2, 202624
Dec 1, 202624
Nov 30, 202624
Nov 29, 202624
Nov 28, 202634
Nov 27, 202639
Nov 26, 2026210
Nov 25, 2026205
Nov 24, 2026203
Nov 23, 2026201
Nov 22, 2026199
Nov 21, 2026189
Nov 20, 2026180
Nov 19, 20266
Nov 18, 20268
Nov 17, 20268
Nov 16, 20269
Nov 15, 20267
Nov 14, 20267
Nov 13, 20268
Nov 12, 20269
Nov 11, 20267
Nov 10, 20269
Nov 9, 20268
Nov 8, 202612
Nov 7, 202614
Nov 6, 202613
Nov 5, 202613
Nov 4, 202613
Nov 3, 202610
Nov 2, 202613
Nov 1, 20269
Oct 31, 20267
Oct 30, 20267
Oct 29, 20264
Oct 28, 20264
Oct 27, 20266
Oct 26, 20265
Oct 25, 20265
Oct 24, 20266
Oct 23, 20265
Oct 22, 20269
Oct 21, 202610
Oct 20, 20269
Oct 19, 20268
Oct 18, 20268
Oct 17, 202610
Oct 16, 202610
Oct 15, 20269
Oct 14, 20268
Oct 13, 20267
Oct 12, 20267
Oct 11, 20268
Oct 10, 20266
Oct 9, 20266
Oct 8, 20264
Oct 7, 20264
Oct 6, 20269
Oct 5, 20268
Oct 4, 202610
Oct 3, 202610
Oct 2, 202615
Oct 1, 202614
Sep 30, 202614
Sep 29, 202613
Sep 28, 202614
Sep 27, 202612
Sep 26, 202614
Sep 25, 20269
Sep 24, 20269
Sep 23, 20269
Sep 22, 20268
Sep 21, 20269
Sep 20, 202611
Sep 19, 202611
Sep 18, 202612
Sep 17, 202615
Sep 16, 202617
Sep 15, 202614
Sep 14, 202613
Sep 13, 202610
Sep 12, 20267
Sep 11, 20269
Sep 10, 20267
Sep 9, 20266
Sep 8, 20269
Sep 7, 202615
Sep 6, 202621

Each point is npm's rolling 7-day download count.

Health Score

71/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1339781367-root.svg)](https://payloaddirectory.dev/plugins/1339781367-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1339781367-root"><img src="https://payloaddirectory.dev/badge/1339781367-root.svg" alt="Payload Directory"></a>
Updated Nov 17, 2026Created Aug 19, 2026Published Nov 17, 2026

README

payload-order-numbers

npm node license payload

Gives every Payload order a short, human readable number such as ORD-01042, assigned in sequence and unique under concurrency, so that a customer and a shop can refer to the same order out loud.

  • Works with @payloadcms/plugin-ecommerce and with any collection that holds orders
  • Verified on Payload 3.88 against both PostgreSQL and MongoDB
  • No runtime dependencies
  • No admin components, so it survives minor releases

Install

Requires Payload 3.88 or newer and @payloadcms/plugin-ecommerce 3.88 or newer. Verified against Payload 3.88.0 with the official plugin installed.

pnpm add payload-order-numbers
import { orderNumbersPlugin } from 'payload-order-numbers'

export default buildConfig({
  plugins: [
    orderNumbersPlugin({
      prefix: 'ORD-',
      padding: 5,
      startAt: 1000,
    }),
  ],
})

The first order becomes ORD-01000, the next ORD-01001, and so on.

What was measured

A Payload document identifier is not something you can read to a customer over the phone. Measured on a live Payload 3.88 install:

DatabaseWhat an order id looks like
MongoDB6a85cce9ce631c0034f52d84, a 24 character ObjectId
PostgreSQL1, 2, 3, an auto incrementing integer

The MongoDB identifier is unusable as an order reference. The PostgreSQL identifier is readable, but it starts at 1, carries no prefix, and tells anyone who sees it exactly how many orders the shop has taken.

Why the obvious approach does not work

The first design read the highest existing number and added one, inside a beforeChange hook. Measured with 25 orders created in the same instant:

DesignOrders that succeededWhy
beforeChange, highest plus one5 of 25every request reads the same highest value inside its own transaction
afterChange with retry3 of 25retrying inside the same aborted transaction cannot succeed
Reservation committed separately25 of 25each number is claimed in its own transaction and is immediately visible

No design ever produced a duplicate. The unique index held in every run. The failures were refusals, not corruption.

How it works now

Before an order is written, the plugin claims the next free value by inserting it into a small reservations collection. That insert commits on its own, so a second order arriving at the same moment sees the claim and takes the next value. The unique index on the order number is the final guarantee, not the first line of defence.

Verified with 25 orders created simultaneously:

DatabaseOrders with a numberUniqueGaps
MongoDB25 of 2525 of 25none
PostgreSQL25 of 2525 of 25none

Options

OptionDefaultMeaning
attempts50How many values to try before giving up. Each attempt is one insert
disabledfalseStops assigning numbers but keeps the fields, so the database keeps its shape
fieldName'orderNumber'Field holding the formatted number
ordersSlug'orders'Slug of the orders collection
padding0Minimum width of the numeric part, left padded with zeros
prefix''Text placed before the number
reservationsSlug'order-number-reservations'Collection holding claimed values
sequenceFieldName'orderSequence'Numeric field the sequence is read from
startAt1Value given to the first order
suffix''Text placed after the number

A value that cannot be used is replaced by its default rather than being applied. A negative padding becomes 0, a startAt of 0 becomes 1, and 4.9 becomes 4. Nothing is silently reinterpreted: -5 never becomes 5.

What it adds to your database

CollectionFieldTypeNotes
your orders collectionorderNumbertextunique, indexed, read only in the admin sidebar
your orders collectionorderSequencenumberunique, indexed, hidden
order-number-reservationssequencenumberunique, indexed. Collection hidden, no API access

The reservations collection is closed to create, read, update and delete through the API. It is written only by the plugin.

Honest limits

PostgreSQL needs a large enough connection pool. Claiming a number opens a second connection while the order's own transaction holds the first. With the pg default of 10, ten simultaneous orders exhaust the pool and the eleventh waits forever. Measured exactly:

Simultaneous ordersResult with the default pool of 10
2, 4, 6, 8, 10all succeed
153 succeed, the rest time out

Set the pool to at least twice the number of orders you expect in the same instant:

postgresAdapter({
  pool: { connectionString: process.env.DATABASE_URI, max: 60 },
})

MongoDB is not affected and needs no change.

Numbers can have gaps. A claimed value is not returned if the order then fails to save. The sequence stays ascending and unique, but it is not a gapless accounting series. If you need one for invoices, that is a different guarantee and belongs in a different package.

Existing orders are not renumbered. The plugin only assigns a number when an order is created. Orders already in the database keep an empty orderNumber.

Under extreme load the order still saves. If all attempts are exhausted the order is written without a number and an error is logged. Losing a sale is worse than losing a label.

License

MIT. Copyright George Vasiliades, https://github.com/Poseidonas

Similar plugins