ExtantApe

payload plugin membership

by ExtantApe
Payments
v3
^3.94.2
MIT

Overview

Summary generated from the README

Adds membership collections to Payload for tiers, categories, memberships and a payments ledger, billed through Stripe subscriptions. Members check out, change plans, cancel or open the Stripe portal through plugin endpoints. Requires a Stripe secret key and webhook, an auth collection for members, and Payload 3.94.2 or later. Hooks let your code award perks on each paid invoice or status change.

Features

  • Fixed monthly or yearly tiers with perks, colors and drag-and-drop order
  • Pick-your-own-amount pledges split across nestable categories
  • Checkout, change, cancel and customer portal endpoints for signed-in members
  • Idempotent Stripe webhook records each paid invoice once and calls onPayment
  • Opt-in backers wall listed by tier or category
  • Multi-site support through scopeField and scopeOf, plus canManage access rules

Use cases

  • Run a Patreon-style supporter program with recurring tiers on a Payload site
  • Let nonprofit donors pledge monthly amounts to chosen causes or categories
  • Grant perks or votes to members whenever a paid invoice arrives

From the author

Memberships for Payload: Patreon-style tiers or pick-your-own-amount pledges to categories, billed as Stripe subscriptions, with a backers wall and hooks for perks.

Installation

npm i @extantape/payload-plugin-membership

1

Stars

0

Forks

0

Open Issues

Today

Last Updated

753

Weekly Downloads

v0.5.5

npm Version

134.4 KB

Unpacked Size

1

Dependencies

GitHub stars

1+1 since Nov 1

Show data
GitHub stars by day (UTC)
DateStars
Dec 6, 20261
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, 20260
Nov 8, 20260
Nov 7, 20260
Nov 6, 20260
Nov 5, 20260
Nov 4, 20260
Nov 3, 20260
Nov 2, 20260
Nov 1, 20260
npm weekly downloads

753+753 since Nov 3

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 2026753
Dec 5, 2026900
Dec 4, 2026893
Dec 3, 2026818
Dec 2, 2026803
Dec 1, 2026787
Nov 30, 2026342
Nov 29, 2026428
Nov 28, 2026285
Nov 27, 2026294
Nov 26, 2026323
Nov 25, 2026321
Nov 24, 2026288
Nov 23, 2026250
Nov 22, 2026353
Nov 21, 2026323
Nov 20, 2026312
Nov 19, 2026280
Nov 18, 2026257
Nov 17, 2026231
Nov 16, 2026215
Nov 15, 20260
Nov 14, 2026302
Nov 13, 2026285
Nov 12, 2026259
Nov 11, 2026388
Nov 10, 2026328
Nov 9, 2026316
Nov 8, 2026285
Nov 7, 2026254
Nov 6, 2026240
Nov 5, 2026193
Nov 4, 20260
Nov 3, 20260

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

Health Score

77/100Excellent

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/1443205746-root.svg)](https://payloaddirectory.dev/plugins/1443205746-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1443205746-root"><img src="https://payloaddirectory.dev/badge/1443205746-root.svg" alt="Payload Directory"></a>
Updated Dec 5, 2026Created Nov 2, 2026Published Dec 4, 2026

README

payload-plugin-membership

Memberships for Payload, billed as Stripe subscriptions. Run it like Patreon, or let members support categories with their own amount — or both.

Status: 0.x, so a new version can include breaking changes. The CHANGELOG marks them. The automated tests run on Payload 3.94.2 with an in-memory MongoDB and a fake Stripe. CI runs them on Node 24. They call REST and GraphQL in-process, and include @payloadcms/plugin-multi-tenant 3.94.2. Not tested: real Stripe, the admin UI in a browser, REST or GraphQL through a running web server, databases other than MongoDB, Payload versions after 3.94.2, Node 22, Node 26.13.1 or newer, and upgrading a real database from an earlier version. You need Payload 3.94.2 or later, and Node ^22.23.5, ^24.22.3, or 26.13.1 or newer.

  • Tiers (Patreon-style): fixed monthly and/or yearly prices, perks, colors. Drag-and-drop order.
  • Categories: things members can choose to support (e.g. "Turtles", "North American turtles"), nestable, with a minimum amount and an optional earmarked flag (otherwise the category is the member's preference). New categories go in A–Z; drag to reorder. Add your own fields to tie them to anything (taxa, regions, projects…).
  • Memberships: one running membership per member (per scope); a tier, or pledges split across categories. Monthly or yearly. Members change, cancel (at the end of the paid period) or open Stripe's customer portal.
  • Payments ledger: every paid invoice recorded once (idempotent webhooks). onPayment runs once per invoice: award perks, votes, credits, receipts.
  • Backers wall: opt-in only, with the name the member chooses; listed under their tier or under each category they support, A–Z within each group.
  • Works with @extantape/payload-plugin-sponsors: mark a tier "Members are listed as sponsors" and call upsertListing/retireListing from onStatusChange.

On its own, and with others

On its own. Membership needs a Stripe account (a secret key and a webhook) and an auth collection for members. It doesn't import any other plugin. Perks, votes and credits are whatever your own onPayment and onStatusChange do.

Needs. Payload ^3.94.2 as a peer dependency. No other EXTANT APE plugin is required.

Works with:

  • Sponsors (@extantape/payload-plugin-sponsors): tick "Members are listed as sponsors" on a tier, and call Sponsors' upsertListing() and retireListing() from onStatusChange. Your site makes the call; neither plugin imports the other.
  • Roadmap (@extantape/payload-plugin-roadmap): Roadmap's extra votes come from a number your site works out (allocation.earned), and a membership can be where they come from. There's no adapter for this. It's a few lines of your own code.
  • Multi-tenant (@payloadcms/plugin-multi-tenant): set scopeField and scopeOf, and each site has its own tiers and members. The member endpoints answer only for the site scopeOf names: another site's membership, or a request from a site scopeOf doesn't know, gets a 404, and so does a request where scopeOf throws (only the error's name is logged). Managers also need the collection's read access, so the tenant plugin's rules apply to them. See Sites for what scopeOf returns and how getBackers and myMembership take a site.

Color Theory. None needed. It has no screens of its own, and its collections use Payload's standard admin, which takes Color Theory's admin colors when its applyToAdmin option is on.

Family. Membership is in the Patronage family, with Sponsors, Backing, Credits, Printify and Roadmap. Backing and Credits are named but not built yet, and the families are a working draft that may change.

Install

Requires Payload 3.94.2 or later, and Node ^22.23.5, ^24.22.3, or 26.13.1 or newer (^22.23.5 || ^24.22.3 || >=26.13.1, the same range as Payload 3.94.2).

npm install @extantape/payload-plugin-membership
import { membershipPlugin } from '@extantape/payload-plugin-membership'

export default buildConfig({
  plugins: [
    membershipPlugin({
      stripeSecretKey: process.env.STRIPE_SECRET_KEY,
      webhookSecret: process.env.STRIPE_MEMBERSHIP_WEBHOOK_SECRET,
      canManage: ({ req }) => req.user?.role === 'admin',
      onPayment: async ({ payload, payment, membership }) => {
        // e.g. thank the member, grant perks
      },
    }),
  ],
})

In Stripe, add a webhook endpoint https://<your site>/api/memberships/stripe-webhook for checkout.session.completed, invoice.paid, invoice.payment_failed, customer.subscription.updated and customer.subscription.deleted.

Endpoints (signed-in members)

EndpointBodyResult
POST /api/memberships/checkout{ tier } or { pledges: [{ category, amount }] }, interval (month/year), wall?: { show, name }, successPath?, cancelPath?{ url } of Stripe Checkout
POST /api/memberships/:id/change{ tier } or { pledges }the updated membership as the caller can read it (from the next invoice)
POST /api/memberships/:id/cancelcancels at the end of the paid period; answers with the membership as the caller can read it
POST /api/memberships/:id/portal{ returnPath? }{ url } of Stripe's customer portal
POST /api/memberships/:id/wall{ show, name }the member's backers-wall choice. A manager may only send show: false

Amounts are in cents. Server code can call startCheckout, changeMembership, cancelMembership, portalLink, myMembership and getBackers directly.

When two saves reach one record at the same moment, MongoDB keeps one and refuses the other. Over REST the refused save answers 409 (Another change to this record was being saved at the same moment, so this one was not saved. Try again.) and nothing of it is stored, so send it again. This covers saves of a single record only: Payload's own REST routes by id for the plugin's four collections, and the wall endpoint. A bulk PATCH (one with a where) that meets a conflict still answers 500, with nothing of it stored. GraphQL and the Local API pass on the database's error as before.

change and cancel call Stripe first and save the membership after. If that save loses to another save made at the same moment, Stripe has already taken the change, so they answer 409 with Your change went through with Stripe. Your membership will update shortly. Don't send it again. Nothing of the lost save is stored, and the membership catches up when Stripe's customer.subscription.updated event arrives. For that, change writes the new plan (tier or pledges, and the amount) into the subscription's metadata under membershipPlan, in the same Stripe call, and the webhook reads it from the subscription as Stripe holds it at that moment. Once a subscription carries a plan there, that plan is what the membership follows, so change plans through change or changeMembership. A plan that names a tier or category that no longer exists, or one from another site, is left out and the membership keeps what it has. change also sends Stripe an idempotency key made from the membership, the new plan and the subscription's current items, so the same change sent to Stripe twice is one change there. cancel sends no key: asking twice does no harm. changeMembership and cancelMembership throw the same 409 to server code. The clash is logged at error level with the membership's id.

change and cancel answer with the membership read again with the caller's own access, so the body is what GET /api/memberships/:id would give them. A member's answer has no stripe ids, no staff notes and no changingUntil; staff get what staff can read, and still never changingUntil. If that read finds nothing, or the host's read access throws, the answer is still 200 with just the id, because the change has been made by then. The log line for that throw, for a failed scopeOf and for a failed webhook holds the error's name only (control characters dropped, then cut to 60 characters), never its message. Every log call in the plugin goes through one wrapper, so a logger that throws doesn't change the answer, including a 409 after Stripe has taken a change and a cancel whose claim couldn't be released.

Changing plan after a cancel keeps the membership going. change tells Stripe not to cancel at the end of the period, so the cancel is lifted, whoever made it, and the member has to cancel again to stop it.

One change of plan or cancel runs at a time for a membership. change and cancel (staff cancel included, it is the same endpoint) hold the membership before they call Stripe and give it back when they are done. A second change or cancel sent meanwhile answers 409 with Another change to this membership is in progress. Try again in a moment. Nothing is sent to Stripe for it and nothing is stored, so it is safe to send again. This also means a cancel can't be undone by a change that was already at Stripe. The hold lasts two minutes at most, so a process that stops halfway can't leave a membership stuck. It lives in a hidden changingUntil field that only the plugin writes. It shows up in the GraphQL types, reads return null, and where, sort and select on it are refused.

The hold is atomic on MongoDB, where it is tested. On Postgres and SQLite it has not been run: updateOne with a where may be a read followed by a write there, so two claims could both win. The changingUntil field also needs a migration on those adapters, or changes will fail.

On customer.subscription.updated the webhook reads the subscription from Stripe and takes the status, cancelAtPeriodEnd, the period end and the plan from what Stripe holds at that moment. The event's own copy isn't used, so an older event that arrives late can't undo a cancel or bring an older plan back. A subscription event reaches only the membership that already holds that subscription's id, which checkout.session.completed sets. An event for any other subscription is ignored.

Options

OptionDefault
slugsmembership-tiers, membership-categories, memberships, membership-payments
usersadmin.userThe members' auth collection
canManagenobodyWho manages tiers, categories and memberships in the admin: true, or a Where for one site's rows. See Access
canCheckoutalwaysE.g. off in development. Only true allows a checkout
stripeSecretKey / stripeKey, or a ready client (tests)
webhookSecretSigning secret of the webhook endpoint
currencyusd
publicURLserverURLOrigin for Stripe return links
scopeField / scopeOfMulti-site: the owner field (e.g. tenant) and how to read it from a request. Set both or neither. See Sites
onPaymentOnce per paid invoice
onStatusChangeWhen a membership's status changes
overridesAdjust the generated collections

Sites

Leave out scopeField and scopeOf on a single site. For several sites, set both: the plugin refuses to build with only one of them.

  • scopeOf(req) returns the request's site id as a non-empty string. Anything else counts as no site: null, an empty string, a number, or a throw. If your ids are numbers, return String(id).
  • With no site, checkout answers 404 (Not found.) before it reads anything or calls Stripe, and so do the member endpoints. Server code calling startCheckout passes scope the same way.
  • Each membership is saved with its site, and only tiers and categories of that site can be chosen, at checkout and when the member changes plan. A tier or category with no site is never offered. A membership with no site can't be changed (404) until it has one.
  • getBackers(payload, { scope }) lists one site's wall. getBackers(payload, { allSites: true }) lists every site's. Anything else throws, including both at once.
  • myMembership(payload, userId, scope) needs the site too, and throws without it.
  • onPayment and onStatusChange get the site as scope on membership and payment. It is null on a single site and for a row with no site, so don't treat null as a site.

Access

canManage decides everything a manager can do. It gets { req } and answers one of three things:

  • true: a manager of every row.
  • A Where, such as { tenant: { equals: siteId } }: a manager of only the rows it matches. Write it against the memberships collection and the scopeField of tiers and categories. For payments the plugin applies it through each payment's membership.
  • Anything else is no: false, null, 0, '', 1, 'yes', an array, an empty {} or { and: [] }, a field with no operator, an operator Payload doesn't have or the plugin doesn't take (a typo such as equal included), a value that would match every row (like or contains with nothing or only whitespace, not_in: [], all: []), a query that doesn't run against the memberships collection or against the tiers, categories or payments it is used on (an unknown field), or an error thrown or rejected. The request is refused cleanly, never a 500. An empty {} would match every row, so it is a no. Return true to mean all. The accepted operators are equals, not_equals, in, not_in, all, exists, greater_than, greater_than_equal, less_than, less_than_equal, like and contains. in: [] is accepted and matches nothing.

Nobody who isn't signed in is a manager, whatever canManage says.

canManage: ({ req }) => {
  const user = req.user as { role?: string; site?: string } | null
  if (user?.role === 'admin') return true
  if (user?.role === 'manager' && user.site) return { site: { equals: user.site } }
  return false
}

A manager limited by a Where reaches only the matching memberships, payments, tiers and categories: list, read, edit, delete, REST and GraphQL alike, and the endpoints below. A new tier or category must match the Where in its own data. The plugin checks equals, not_equals, in, not_in, exists, and and or there; any other operator is a no for a create. An update that names a field your Where uses is checked the same way, on the stored row with the new data merged over it, so a limited manager can't move a row out of their scope or into another one. An update that leaves those fields alone isn't checked again.

notes, stripe and stripeProduct are judged row by row with the same answer, so a manager of site A never reads site B's notes or Stripe ids, even in a list that includes site B's rows (for example a membership they hold as a member there).

WhereA managerA signed-in memberSigned out
Tiers, categoriesReads; creates, edits, deletes within their scopeReadsReads
Their stripeProduct (field)Reads within their scope; never writesNever sees itNever sees it
MembershipsReads and edits within their scope, deletes within their scopeReads their ownNothing
A membership's stripe and notes (fields)Reads and writes within their scopeNever sees themNothing
PaymentsReads and deletes within their scopeReads their ownNothing
cancel endpointA membership within their scope, on this request's siteTheir own404
wall endpointOnly to hide (show: false), within their scopeTheir own, show and name404
A membership's wall.show (field, the admin form included)Only to hide, within their scopeThrough the wall endpointNothing
change, portal endpointsNeverTheir own404

Only the member changes their own plan, opens their own Stripe billing portal, shows themselves on the backers wall or sets the wall name. A manager, even one who manages everything, gets a 404 on change and portal, and may only hide a wall entry (show: false, for an offensive name or a takedown request). Managers keep cancel. (Decided 2026-11-23.)

This is enforced in field access too, not just in the endpoints, so editing a membership through Payload's own REST, GraphQL or admin can't get around it. A manager can't write a membership's user, kind, status, interval, tier, pledges, amount, currency, label, the period dates or the stripe group, or wall.name, and can only set wall.show to false. Only notes is theirs to edit, plus hiding a wall entry.

A manager of a membership hides its wall entry in the admin form by clearing the show box and saving. The box is open to them only while the entry is shown. Once it is hidden the box is read-only, and only the member can show it again, through the wall endpoint. The wall endpoint (POST /api/memberships/:id/wall with show: false), REST and the Local API hide an entry too. One check decides who may hide on all of them, so the admin form allows what the wall endpoint allows. The wall endpoint also looks the membership up on the request's site first. With scopeField, a membership with no site is on no site, so the wall endpoint answers 404 for it, while a manager of every row (canManage answering true) can still hide it through the field: the admin form, REST or the Local API. A save from a manager that sets show to true leaves the entry hidden and saves the other fields. Server code that writes with overrideAccess (checkout, Stripe events) is unchanged. A manager can set a category's parent only to a category in their scope. That is judged on the parent the row ends up with, whether the save is a create, an update, a duplicate (which keeps the original's parent unless the data changes it) or a restore. A save whose final parent is outside their scope is refused with a message saying so; clear the parent or choose one they manage. If you localize parent through overrides, every locale's parent counts: a save in one locale is refused while another locale's parent is outside their scope, until that locale's parent is cleared or moved.

Saves to the plugin's collections send each field by its plain name, with nested fields as nested objects. A field name that starts with a dollar sign or contains a dot is refused (400) on every save, through any API, bulk updates, drafts and duplicates included, and from your server code with overrideAccess too, since the Local API overrides access by default. The values of JSON and rich text fields are left alone. The plugin puts this check at the front of each collection's beforeOperation hooks, after your overrides. A plugin that runs after this one can still add its own hook in front of it, so that hook sees the data before the check does.

A manager limited by a Where may restore a version of a tier, category or membership only when the version itself matches their Where. A version that can't be read is refused. (Restoring a membership by anyone other than server code fails validation, as it did before, because the fields managers can't write aren't refilled on restore.)

If you turn on drafts for tiers or categories through overrides, people who aren't managers read only published rows (and rows saved before drafts were on). A limited manager also reads drafts in their scope, and a manager of every row reads all of them.

Saved versions are for managers only: the versions routes in REST, the version queries in GraphQL, and findVersions and findVersionByID in the Local API with access on. Members and signed-out visitors get none, and a limited manager gets only the versions that match their Where. This covers all four collections, versions you turn on through overrides included. If your overrides set access.readVersions, your rule is used. If they replace access without one, the plugin's rule is put back, so these collections always have a rule for versions.

A server-side duplicate of a membership starts as pending, without Stripe ids, period dates, canceledAt or cancelAtPeriodEnd. It also starts without the staff notes and off the backers wall (wall.show false, no wall.name). Server code that wants any of these on the copy passes them in data.

stripeProduct on tiers and categories is set only by server code (overrideAccess): the plugin stores it at a row's first checkout, and your own server code (a seed or an import) may set it on create or update. A create or update that doesn't override access ignores it. It belongs to one row, so a duplicate starts without it, in every locale, and gets its own at its first checkout. That includes a duplicate made by your server code. To give a copy a particular value, pass stripeProduct in the data of a duplicate that overrides access.

Nobody creates memberships or payments directly: checkout and Stripe do. The member endpoints answer 404, not 403, to anyone who may not use them, so they don't say whether a membership exists.

Memberships' and payments' read access returns a query for members: the plugin's own "your rows" filter. A manager's query comes only from canManage, and only when it passes the checks above. canCheckout follows the exact-true rule: only true lets a checkout start, and anything else, an error included, refuses it with "Memberships are not available here yet." (503).

Upgrading: a canManage that returned true or false works as before. One that returned an object (it was a no) now has that object used as a query, so return false if you meant no.

Upgrading, stripeProduct: if anything other than server code writes it (the REST or GraphQL API, or the Local API with overrideAccess: false), move that write to server code with overrideAccess, after your own permission check. If your server code duplicates a tier or category and expects the copy to keep the value, pass it in data. Rows saved earlier keep what they hold, and checkout uses it, so check them: each value should be used by one row only, and a product the plugin created names its row in its Stripe metadata (payloadCollection, payloadId). Where a value belongs to another row, set it to null from server code (in each locale, if you localize the field). The next checkout creates the row's own product.

Upgrading from 0.2.0, checks to run once from server code:

  1. Stored products. For each tier and category with a stripeProduct, clear it (set null with overrideAccess, in each locale if you localize the field) when more than one row holds the same value, or when the product's Stripe metadata payloadCollection and payloadId don't name this collection and this row's id. Clear every row that shares a value, the first one too. The next checkout makes each row its own product. Running it again should find nothing.
  2. Parent categories. If you use a Where for managers, list categories whose parent is outside the category's own scope (on another site). If you localize parent, check it in each locale. A limited manager can't save such a category until its parent is cleared or moved into their scope, so fix these from server code or as a manager of every row.

Upgrading, sites (only if you set scopeField):

  1. Set scopeOf too, if you hadn't. Make sure it returns the site id as a string.

  2. Pass a scope to every server call of startCheckout and myMembership. Pass scope or allSites: true to every getBackers call.

  3. Find memberships that have no site, from server code. With tenant as your scopeField:

    const { docs } = await payload.find({
      collection: 'memberships',
      where: { or: [{ tenant: { exists: false } }, { tenant: { equals: null } }] },
      depth: 0,
      pagination: false,
      overrideAccess: true,
    })
    

    For a text field, also look for an empty string. For each row, first try to give it the site its tier or categories belong to, with payload.update({ collection: 'memberships', id, data: { tenant: siteId }, overrideAccess: true }), and its payments too if you added the field to them. If you can't, cancelMembership(payload, id) ends it at the close of the paid period, with no refund. To stop it now or refund, do that in Stripe. A member who joins again before then pays for both. A row with no site can't be managed by the member from any site, and it isn't on any one site's backers wall (allSites: true still lists it). A Checkout opened before the upgrade can still finish afterwards and activate a row with no site, so run the query again a day later.

  4. Give a site to any tier or category that has none, or it won't be offered.

  5. Check: a checkout with no site answers 404 and creates nothing, a checkout on a site works, and the query in step 3 finds nothing.

This version requires Payload 3.94.2 or later (peer range ^3.94.2). Upgrade Payload before you install it.

Saves to these collections, from your front end, scripts and server code alike, must use plain field names (no leading dollar sign, no dots). Nested fields go as nested objects.

overrides can change a collection's access; if you do, your rules replace these, except that a collection whose access has no readVersions keeps the plugin's.

License

MIT

Similar plugins