Poseidonas

payload abandoned cart

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

Overview

Summary generated from the README

Extends the official Payload ecommerce plugin with fields and endpoints that mark idle carts as abandoned and send a configurable email sequence through payload.sendEmail. Recovery links restore the cart and expire, and orders that follow a link are marked with the cart they came from. It requires Payload 3.88 or newer and the ecommerce plugin, and a sweep endpoint is triggered by your own scheduler.

Features

  • Stores an abandonedAt timestamp after a configurable idle period
  • Multi-step recovery email sequence with string or function templates
  • Expiring recovery links that restore the cart and redirect to the storefront
  • Order attribution through recoveredFromCart and recoveryEmailStep fields
  • Sweep endpoint and exported functions to run marking and sending from any scheduler
  • Adds a customerEmail field to carts so guest carts can be emailed

Use cases

  • Win back shoppers who left items in their cart without checking out
  • Measure how many orders came from recovery emails within an attribution window
  • Run abandoned cart sweeps from an existing cron or script without adding a scheduler dependency

From the author

Marks idle Payload carts abandoned, sends a recovery sequence through payload.sendEmail, and attributes the orders it recovers.

Installation

npm i payload-abandoned-cart

1

Stars

0

Forks

0

Open Issues

2 weeks ago

Last Updated

17

Weekly Downloads

v1.0.2

npm Version

54.5 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

12−8 since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 202612
Dec 4, 202613
Dec 3, 202617
Dec 2, 202621
Dec 1, 202619
Nov 30, 202621
Nov 29, 202622
Nov 28, 202630
Nov 27, 202635
Nov 26, 2026214
Nov 25, 2026209
Nov 24, 2026207
Nov 23, 2026205
Nov 22, 2026203
Nov 21, 2026194
Nov 20, 2026186
Nov 19, 20264
Nov 18, 20266
Nov 17, 20266
Nov 16, 20267
Nov 15, 20267
Nov 14, 20266
Nov 13, 20269
Nov 12, 202611
Nov 11, 20269
Nov 10, 202610
Nov 9, 202610
Nov 8, 202611
Nov 7, 202613
Nov 6, 202611
Nov 5, 202610
Nov 4, 202610
Nov 3, 202610
Nov 2, 202612
Nov 1, 20269
Oct 31, 20267
Oct 30, 20266
Oct 29, 20264
Oct 28, 20264
Oct 27, 20265
Oct 26, 20263
Oct 25, 20264
Oct 24, 20265
Oct 23, 20265
Oct 22, 20267
Oct 21, 20267
Oct 20, 20267
Oct 19, 20266
Oct 18, 20265
Oct 17, 20266
Oct 16, 20266
Oct 15, 20267
Oct 14, 20267
Oct 13, 20266
Oct 12, 20266
Oct 11, 20267
Oct 10, 20267
Oct 9, 20267
Oct 8, 20267
Oct 7, 20268
Oct 6, 202612
Oct 5, 202612
Oct 4, 202615
Oct 3, 202615
Oct 2, 202618
Oct 1, 202615
Sep 30, 202614
Sep 29, 202612
Sep 28, 202612
Sep 27, 20269
Sep 26, 202611
Sep 25, 20269
Sep 24, 202611
Sep 23, 202611
Sep 22, 202610
Sep 21, 202612
Sep 20, 202614
Sep 19, 202614
Sep 18, 202613
Sep 17, 202614
Sep 16, 202617
Sep 15, 202616
Sep 14, 202616
Sep 13, 202614
Sep 12, 202611
Sep 11, 202613
Sep 10, 202610
Sep 9, 20268
Sep 8, 20268
Sep 7, 202612
Sep 6, 202620

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

Health Score

69/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/1340409742-root.svg)](https://payloaddirectory.dev/plugins/1340409742-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1340409742-root"><img src="https://payloaddirectory.dev/badge/1340409742-root.svg" alt="Payload Directory"></a>
Updated Nov 17, 2026Created Aug 20, 2026Published Nov 17, 2026

README

payload-abandoned-cart

npm node license payload

Records when a Payload cart was abandoned, sends a recovery sequence through payload.sendEmail, restores the cart from a link that expires, and marks the orders that came back so a shop can measure whether any of it works.

  • Extends @payloadcms/plugin-ecommerce, adding fields and endpoints instead of replacing anything
  • No scheduler dependency: one endpoint you point your own cron at, and the same work as an exported function
  • No mail library: every message goes through the email adapter the host already configured
  • 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-abandoned-cart
import { ecommercePlugin } from '@payloadcms/plugin-ecommerce'
import { abandonedCartPlugin } from 'payload-abandoned-cart'

export default buildConfig({
  plugins: [
    ecommercePlugin({ ... }),
    abandonedCartPlugin({
      idleMinutes: 120,
      steps: [{ delayMinutes: 60 }, { delayMinutes: 1440 }],
      sweepSecret: process.env.ABANDONED_CART_SECRET,
    }),
  ],
})

abandonedCartPlugin must come after ecommercePlugin, because it adds fields to the collections that plugin defines. Then point a scheduler at the sweep:

curl -X POST https://example.com/api/abandoned-cart/sweep \
  -H "Authorization: Bearer $ABANDONED_CART_SECRET"

What was measured

Read in the published @payloadcms/[email protected], in the original TypeScript carried by its source maps.

The abandoned status exists and is never stored

The carts collection declares three statuses in src/collections/carts/createCartsCollection.ts, and the field carries virtual: true with an afterRead hook. src/collections/carts/statusBeforeRead.ts is the whole of it:

if (data?.purchasedAt) return 'purchased'
if (timeNow - createdAt < 7 * 24 * 60 * 60 * 1000) return 'active'
return 'abandoned'

So the value is computed on every read and written nowhere. Four consequences, all of which this package exists to answer:

What the plugin doesWhat follows
The field is virtual: trueIt is not in the database. Payload's own query validation pushes an error for a query on a field with virtual: true, so where: { status: { equals: 'abandoned' } } cannot be run at all
The threshold is the literal 7 * 24 * 60 * 60 * 1000Seven days, not configurable
It is measured from createdAtA cart created eight days ago and updated this morning already reads as abandoned
Nothing records when it changedThere is no moment to count a recovery sequence from

This package therefore stores its own abandonedAt timestamp rather than trying to write a field that would be discarded. If your carts collection carries a stored status field of its own that offers an abandoned option, that field is written too; the virtual one never is.

A cart holds no address

The fields the plugin puts on a cart are items, secret, customer, purchasedAt, status, and, when currencies are configured, subtotal and currency. There is no email address anywhere, and no shippingAddress either; only orders have one of those.

A cart can therefore only be emailed if it has a customer relationship to look an address up through, which a guest cart does not. This package adds a customerEmail field to the cart so that a storefront can capture the address at the first step of checkout, and reads it before falling back to the customer record.

The order does not know which cart it came from

In src/payments/adapters/stripe/confirmOrder.ts the order is created first and the cart is marked second, inside one request:

const order = await payload.create({ collection: ordersSlug, data: { ... }, req })
await payload.update({ id: cartID, collection: cartsSlug, data: { purchasedAt: timestamp }, req })

The order carries items, customer or customerEmail, transactions, status, amount and currency. Nothing points back at the cart. Attribution is therefore taken from the only moment the two are known together: the order id is kept in req.context as the order is created, and the cart's own hook, running later in the same request, writes it onto the order.

Options

OptionDefaultMeaning
attributionWindowHours168How long after a recovery link is followed a purchase is still credited to it
cartsSlug'carts'Slug of the carts collection
currencyDecimals2Decimal places used to format the subtotal, one number or a map from currency code to places
customersSlug'users'Collection the cart's customer relationship points at
disabledfalseStops marking, sending and attributing but keeps every field, so the database keeps its shape
emailFieldName'customerEmail'Field on the cart holding the address a message is sent to
fromnullAddress messages are sent from. Null leaves the choice to the email adapter
idleMinutes60Minutes of inactivity, measured on updatedAt, before a cart is marked abandoned
markLimit200Highest number of carts marked in one sweep
ordersSlug'orders'Slug of the orders collection
recoverEndpointPath'/abandoned-cart/recover'Path a recovery link points at
redirectPath'/cart'Storefront path a followed link is redirected to. Empty means answer with JSON instead
redirectWithSecrettrueWhether the redirect carries the cart secret, which is what gives a guest the cart back
replyTonullAddress replies go to
sendLimit100Highest number of messages sent in one sweep
serverURL''Origin used to build recovery links. Empty falls back to serverURL of the Payload config
statusFieldName'status'Cart status field. Written only when it is stored and offers an abandoned option
stepstwo messages, at 60 and 1440 minutesThe sequence. An empty array turns sending off and leaves marking in place
sweepEndpointPath'/abandoned-cart/sweep'Path of the sweep endpoint
sweepSecret''Secret accepted by that endpoint as Authorization: Bearer <secret>. Empty means only a signed in user may call it
tokenTtlHours336How long a recovery token stays valid, counted from the moment the cart was marked

A value that cannot be used is replaced by its default rather than being applied. An idleMinutes of 0 becomes 60, 90.9 becomes 90, a slug given as an empty string becomes its default, and a path without a leading slash gains one. Steps are sorted by delay, so the sequence always goes out in the order the delays describe.

The sequence

Each step's delayMinutes is counted from abandonedAt, not from the message before it, so the schedule stays readable as steps are added or removed.

abandonedCartPlugin({
  steps: [
    { delayMinutes: 60 },
    {
      delayMinutes: 1440,
      template: {
        subject: 'Still thinking it over?',
        text: 'Your basket of {{itemCount}} items comes to {{subtotalFormatted}}.\n{{recoveryURL}}',
      },
    },
    { delayMinutes: 4320, template: (context) => ({ subject: '...', text: '...' }) },
  ],
})

A template is either a pair of strings carrying {{placeholder}} tokens or a function receiving the context. The tokens are abandonedAt, cartID, currency, itemCount, lineCount, recoveryURL, step, subtotal, subtotalFormatted and to; the whole cart is on cart for a function template. A token with no matching value is left in place, so a mistyped name is visible instead of blank. The built in messages are plain text and compose nothing into markup.

What it adds to your database

CollectionFieldTypeNotes
your carts collectioncustomerEmailemailindexed. Added only when no field of that name exists
your carts collectionabandonedAtdateindexed. Set by the sweep, cleared when the link is followed
your carts collectionrecoveryTokentextindexed, hidden, closed to create, read and update through the API
your carts collectionrecoveryTokenExpiresAtdatehidden
your carts collectionrecoveryEmailsSentnumberhow many steps have gone out, read only
your carts collectionlastRecoveryEmailAtdateread only
your carts collectionrecoveryVisitedAtdateindexed. When the recovery link was first followed
your orders collectionrecoveredFromCartrelationshipindexed, read only. The cart the sale came back from
your orders collectionrecoveryEmailStepnumberread only. How many messages had gone out when the sale happened

No collection is added. A field this package would add and your collection already declares under that name is left alone.

What it adds to your API

EndpointMethodPurpose
/api/abandoned-cart/recover?token=...getPublic. Restores the cart and redirects to the storefront
/api/abandoned-cart/sweeppostMarks idle carts and sends what is due. Returns { "marked": n, "sent": n, "skipped": n }

Running the sweep

There are three ways, none of which needs a scheduler in your dependencies:

  1. Point your existing scheduler at the endpoint, with the secret as a bearer token.

  2. Call it from a route handler or a script.

    import { runAbandonedCartSweep } from 'payload-abandoned-cart'
    
    const { marked, sent, skipped } = await runAbandonedCartSweep(payload, { idleMinutes: 120 })
    
  3. Call the two halves separately, when marking and sending belong on different schedules.

    import { markAbandonedCarts, sendRecoveryEmails } from 'payload-abandoned-cart'
    

Pass the same options you passed to the plugin. Every exported function resolves them the same way the plugin does, so passing nothing gives you the documented defaults.

A token is 32 bytes from getRandomValues of node:crypto, written as 64 hexadecimal characters, minted when the cart is marked and reused by every message of the sequence so that an older message keeps working. Following the link stops the cart being abandoned, which also stops the sequence, records the visit, and redirects to:

/cart?cart=<id>&secret=<cart secret>

The secret is what the ecommerce plugin's own guest cart access reads from req.query.secret, so a guest gets the cart back rather than an empty one. Set redirectWithSecret: false to leave it out, or redirectPath: '' to receive JSON and do the rest yourself:

{ "cart": "68f2...", "recovered": true, "secret": "3f9a..." }

A refused link answers 404 for a token that belongs to nothing, 410 for one that expired and 409 for a cart already paid for. With a redirect configured, all three become ?recovery=unknown, ?recovery=expired and ?recovery=purchased on the storefront path instead.

Honest limits

One sweep at a time. The sweep is not locked. Two overlapping runs can read the same cart before either has written to it, and send one step twice. Space your schedule wider than a sweep takes, and keep markLimit and sendLimit at a size that finishes comfortably.

A message is recorded before it is sent. The step counter is written first and the transport called second, so a cart is never sent the same step twice. The cost is the opposite failure: if the transport throws, that message is lost rather than repeated. The failure is logged as an error and the sweep continues to the next cart. Losing one message is better than mailing a customer twice.

The sweep does not run inside your request transaction. Each cart is written on its own, so a failure late in a sweep does not roll back the messages already sent. On PostgreSQL that means the sweep uses a connection of its own while the endpoint holds another; the same mechanism was measured for payload-order-numbers, where the pg default pool of 10 was exhausted by fifteen simultaneous writers. One scheduled sweep is one extra connection, but do not run the sweep from inside a hot request path.

A guest cart with no address is never mailed. The ecommerce plugin gives a cart no address field, so unless your storefront writes one into customerEmail, only carts with a customer relationship can be reached. Those carts are still marked, still counted, and are passed over with a warning in the log rather than an error.

The recovery token is stored as it is sent. The same link has to appear in every message of the sequence, so the token cannot be replaced by a hash of itself. The field is closed to create, read and update through the API and hidden in the admin panel, but it is in the database in plain text. It grants access to one cart and it expires.

The secret travels in a URL. With redirectWithSecret on, the cart secret arrives on the storefront as a query parameter, which browsers keep in history and may pass on as a referrer. That is how the ecommerce plugin's own guest access works, and it is the only way to hand a guest their cart back. Turn it off if that trade is not one you want.

Attribution needs the order and the cart in one request. The order id is taken from req.context, which is how the two are connected when the official confirmOrder runs. A checkout that creates the order in a separate request, or writes it straight through the local API, leaves recoveredFromCart empty; the visit is still on the cart, and a note is written to the log.

Nothing is measured against a control group. recoveredFromCart counts sales that followed a recovery link inside the attribution window. It does not tell you whether those customers would have come back anyway.

Existing carts are not marked retroactively. The first sweep marks every cart already older than idleMinutes, up to markLimit, oldest first. On a shop with a long history that is several sweeps' worth of work, and the messages that follow are real. Set steps: [] for the first run if you want the marking without the mail.

Deleting a cart deletes its attribution. recoveredFromCart is a relationship; the order keeps recoveryEmailStep, but the link goes.

License

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

Similar plugins