Downloads

Sells digital products from a Payload store using signed, expiring download links that stop working when an order is refunded.

Community 0 MIT v1.0.0

Installation

pnpm add payload-downloads

About

Sells digital products from a Payload ecommerce store. A product or variant carries one or more files, a paid order earns access to them, and the customer receives a signed link that expires, counts its uses, and stops working the moment the order is refunded. The plugin hooks into the orders collection `afterChange` hook and grants or revokes access based on the order status. It adds a `download-grants` collection that records one grant per order and file, plus a `downloadable` checkbox and a `downloadFiles` upload field on the products (and variants) collections. Two endpoints are added: `GET /api/downloads` for a signed in customer to read their own downloads, and `GET /api/downloads/file` to stream the bytes. It works with `@payloadcms/plugin-ecommerce` and with any collection that holds orders. Signed links use `node:crypto` HMAC-SHA256 with no runtime dependencies. The key is derived from the Payload secret rather than being the secret itself, and grant, order, file and expiry are all inside the signed message so a signature cannot be moved to another file, order, grant or a later expiry. Verification uses `timingSafeEqual`. The file is streamed by the plugin, so no storage path, URL or bucket key ever reaches the client. Before a byte is written the plugin reloads the grant and refuses it if it is revoked, expired or at its limit, which means a refund stops links that were already handed out. Options control the download limit, expiry days, link TTL, which statuses grant or revoke, customer and collection slugs, and whether variants are enabled. Local storage works out of the box. Payload has no stable public API for reading the bytes behind an upload document when a cloud adapter owns them, so a storage adapter needs a `fileResolver` callback. There are no admin components, which keeps the plugin stable across minor Payload releases. Server side helpers like `downloadLinksForOrder`, `grantAccess` and `revokeAccess` are exported for use in order emails or custom flows.

Package info

Package name
payload-downloads
Latest version
1.0.0
Unpacked size
47 kB
License
MIT
Last publish
Aug 20, 2026

More from Poseidonas

View profile