docs(payments): a payments service of its own, Patreon first (#26)
Release / release (push) Successful in 4s
CI / test (push) Successful in 1m36s
CI / image (apps/api/Dockerfile, t5de-hub-api) (push) Successful in 5s
CI / image (apps/web/Dockerfile, t5de-hub-web) (push) Successful in 4s

Rewrites the payments plan for a separate payments service, with Patreon as the first way to pay.

**docs/payments.md**
- **`t5de-payments` is its own service:** its own repo, Postgres database and secrets, at `payments.t5de.dev`, to contain the compliance risk. The hub and Music never hold a payment provider's key. Music reads entitlements (`GET /v1/entitlements/{sub}`), is told about changes over a signed back-channel call, and keeps the last answer it got.
- **Patreon first:** Patreon is the seller, so it handles sales tax and VAT.
  - **Linking:** members link Patreon with OAuth (`identity`).
  - **Tiers:** which tier gives how much is set in config in git.
  - **Webhook:** the service checks its webhook exists and is set up right on every start, and fixes it if not. Requests are verified with `X-Patreon-Signature` (HMAC-MD5).
  - **State:** after a webhook it re-fetches the member from Patreon, and a nightly sync of every member catches anything missed.
  - **Grace:** access runs until `next_charge_date` plus 7 days.
  - **Tokens:** Patreon rotates the creator token's refresh token, so the current pair is kept in the database.
- **Entitlements are counts** (`music.rooms` × N), because a Patreon member has only one tier. Moderators' grants (no money) come first, in phase 1.
- **Processors:**
  - **Polar:** used only if their support says yes in writing. Its acceptable use policy names YouTube downloaders (#30) and circumventing other services' terms (#18).
  - **Not used:** Stripe or PayPal directly (we'd be the seller), and IMVU credits.

**docs/music.md**
- **The paid tier sells hosting only.** YouTube limits are now the same in both tiers.
- **Tiers:** Room ($1.99, 1 room) and Rooms ($4.99, 3 rooms). The owner picks which rooms are paid. When the count drops, the most recently picked rooms go back to free first.
- The risks section and phase 3b point to t5de-payments.

Rewrites the payments plan for a separate payments service, with Patreon as the first way to pay.

**docs/payments.md**
- **`t5de-payments` is its own service:** its own repo, Postgres database and secrets, at `payments.t5de.dev`, to contain the compliance risk. The hub and Music never hold a payment provider's key. Music reads entitlements (`GET /v1/entitlements/{sub}`), is told about changes over a signed back-channel call, and keeps the last answer it got.
- **Patreon first:** Patreon is the seller, so it handles sales tax and VAT.
  - **Linking:** members link Patreon with OAuth (`identity`).
  - **Tiers:** which tier gives how much is set in config in git.
  - **Webhook:** the service checks its webhook exists and is set up right on every start, and fixes it if not. Requests are verified with `X-Patreon-Signature` (HMAC-MD5).
  - **State:** after a webhook it re-fetches the member from Patreon, and a nightly sync of every member catches anything missed.
  - **Grace:** access runs until `next_charge_date` plus 7 days.
  - **Tokens:** Patreon rotates the creator token's refresh token, so the current pair is kept in the database.
- **Entitlements are counts** (`music.rooms` × N), because a Patreon member has only one tier. Moderators' grants (no money) come first, in phase 1.
- **Processors:**
  - **Polar:** used only if their support says yes in writing. Its acceptable use policy names YouTube downloaders (#30) and circumventing other services' terms (#18).
  - **Not used:** Stripe or PayPal directly (we'd be the seller), and IMVU credits.

**docs/music.md**
- **The paid tier sells hosting only.** YouTube limits are now the same in both tiers.
- **Tiers:** Room ($1.99, 1 room) and Rooms ($4.99, 3 rooms). The owner picks which rooms are paid. When the count drops, the most recently picked rooms go back to free first.
- The risks section and phase 3b point to t5de-payments.

Co-authored-by: dhkatz <[email protected]>
This commit was merged in pull request #26.
This commit is contained in:
dhkatz authored and dhkatz committed 2026-11-20 19:38:01 +00:00
1 parent b496714151
commit 02e8269d4d
2 files changed
+159 -109

No files matched your search

+137 -91
View File
@@ -1,133 +1,179 @@
# Payments (plan)
Status: proposal for review (2026-11-18). Nothing here is **Decided** yet; open decisions are at the end.
Status: draft (2026-11-20). Decisions marked **Decided** were agreed in discussion; the rest are proposals. Open
decisions are at the end.
Paid offerings for Music now (docs/music.md, Paid tier) and for the hub later, through one billing backend. More
than one payment processor from the start, because T5DE has adult content and the mainstream processors forbid it,
while Music has none.
Paid offerings for Music now (docs/music.md, Paid tier) and maybe for the hub later. Payments are their own service,
`t5de-payments`, and the first way to pay is a Patreon membership.
## Goals
- **One place** for prices, subscriptions and what people have paid for, keyed by the T5DE account (basic or member:
someone who only uses Music can pay).
- **Several processors**, chosen per merchant, behind one interface: switching one touches no app.
- **No card data** anywhere of ours: hosted checkout pages and portals only.
- **Apps ask one question**: does this account have entitlement X (for room Y)? They never talk to a processor.
- **Contain the risk** (**Decided**): processor accounts, their keys, payment records and webhooks live in one small
service with its own database and secrets, apart from the hub and Music. A processor closing an account, or a
payments bug, touches only this service; the hub and Music never hold a processor's key.
- **No tax work of our own** (**Decided**): only platforms that are the seller (or collect and remit tax for us), so
sales tax and VAT are theirs. No Stripe or PayPal directly, where we'd be the seller.
- **No IMVU credits** (**Decided**).
- **No card data** anywhere of ours: the platform's own pages for joining, paying and cancelling.
- **Apps ask one question**: how much of entitlement X does this account have? They never talk to a processor.
## Where it lives
## Where it lives (**Decided**)
In the hub's API, next to accounts (a module, `billing`), because the customer is the account. It moves with
accounts if they're ever split out (`accounts.t5de.dev`, docs/music.md). Apps reach it through the hub's API with the
person's access token, and the hub tells them about changes over the same signed back-channel as `user.merged`.
`t5de-payments`: its own repository, image, stack and Postgres database, at `payments.t5de.dev`. Deployed like the
other stacks, with its secrets in sops like theirs.
- **Who's who**: it's an OIDC client of the hub (docs/music.md, The OIDC provider), like Music, and knows people by
their `sub`. It never sees their IMVU accounts or rooms.
- **Apps read entitlements** with their own client credentials, `GET /v1/entitlements/{sub}`, and are told about
changes over a signed back-channel call (`entitlements.changed {sub}`, as `user.merged`), after which they read
again. Music keeps the last answer, so payments being down doesn't change any room.
- **Its pages** (sign-in, link Patreon, what you have) are few and plain; Music links to them from Account.
```
music.t5de.dev ──checkout──► hub API (billing) ──hosted checkout──► processor (Stripe for Music)
▲ │ ▲ │
└── entitlement.changed ──┘ └──────────── webhooks ◄─────────────────┘
music.t5de.dev ─── link Patreon ───► payments.t5de.dev ◄── webhooks, members ──► Patreon
▲ │
└──── entitlements.changed, GET ─────┘
```
## Concepts
| | What |
| --- | --- |
| **Merchant** | Who sells, with its processor account: `music` and `t5de`. Products belong to one merchant and never mix, so a processor that bans adult content only ever sees Music's sales, and one merchant account being closed can't take the other's payments with it. |
| **Product, price** | What's sold and for how much (`music.room`, yearly). |
| **Customer** | An account at one merchant's processor: `(account, merchant) → processor customer ID`. |
| **Subscription** | Mirrored from the processor: status, period end, cancel at period end. |
| **Payment event** | Every webhook, kept as received. Unique by `(processor, event ID)`, so a replay changes nothing. |
| **Entitlement** | What apps check: `{account, key, scope, from, until, source}`, e.g. `music.room` scoped to a room. Made from subscriptions, from moderators' grants (gifts, testers; console, audited) and later from codes. |
| **Provider** | Where money comes from: `patreon` now, maybe `polar` (Processors, below), `grant` for moderators' gifts and testers. |
| **Link** | A person's account at a provider: `(sub, provider) → provider's user ID`, unique both ways. |
| **Source** | One thing that grants: a Patreon membership, a grant. Mirrored from the provider: status, tier, paid until. |
| **Event** | Every webhook as received, with its verdict. Kept for the audit log; never trusted for state (below). |
| **Entitlement** | What apps read: `{sub, key, quantity, until, source}`, e.g. `music.rooms` × 3 until a date. An account's total is the sum of its live entitlements per key. |
Processing a webhook doesn't trust its order: it fetches the subscription's current state from the processor and
recomputes that account's entitlements from it. Late, repeated or reordered events then all end in the same place.
Entitlements are counts, not tied to a room: a Patreon member has one tier, so tiers are room bundles. Music decides
which of the owner's rooms are paid (docs/music.md, Paid tier).
## Processor adapters
Every change recomputes: a webhook, a nightly sync or a grant fetches the source's current state from the provider
and recomputes that account's entitlements from all its sources. Late, repeated, missed or reordered events then all
end in the same place.
```ts
interface Processor {
checkout(customer, price, scope, returnURL): Promise<{ url: string }>;
portal(customer, returnURL): Promise<{ url: string }>;
cancel(subscription, { atPeriodEnd: boolean }): Promise<void>;
refund(payment, amount?): Promise<void>;
// Verifies the signature and maps the processor's event to ours.
webhook(request): Promise<BillingEvent | null>;
subscription(id): Promise<SubscriptionState>;
}
## Patreon (**Decided**: first)
Patreon is the seller: it collects and remits VAT and US sales tax where required, runs payments, retries, refunds and
cancelling, and pays out. The page is T5DE Music's alone and marked not for adults; the hub's adult offerings never go
on it. Fees: 10% of income plus payment processing (patreon.com/pricing).
Set up by hand on patreon.com (the API reads tiers, it can't write them): the page, the tiers, payouts and tax
details, and an API client in the developer portal (its redirect URI is
`https://payments.t5de.dev/patreon/callback`).
**Configuration, in git**: the campaign's ID and each tier's ID with what it grants:
```yaml
patreon:
campaign: "<campaign ID>"
tiers:
"<Room tier ID>": { music.rooms: 1 }
"<Rooms tier ID>": { music.rooms: 3 }
```
Webhooks arrive at `POST /api/v1/billing/webhooks/<processor>` on the hub's API. Processors retry for days, so a hub
outage only delays them.
A tier that isn't listed grants nothing (a free membership, a tier for something else).
**Linking**: signed in, the person presses "Link Patreon" and approves our client on Patreon (scope `identity`). We
keep their Patreon user ID; `include=memberships` on `/identity` shows their membership to our campaign. A membership
whose Patreon account isn't linked yet grants nothing until it is, then counts at once. One Patreon account links to
one T5DE account; linking it elsewhere asks to unlink first.
**The creator token** (the developer portal's, scopes `campaigns`, `campaigns.members`, `w:campaigns.webhook`) reads
members and manages the webhook. It's seeded from sops; Patreon's refresh hands out a new refresh token each time, so
the current pair lives in the database, and an expiring or refused token is an alert.
**The webhook** is ours to keep right: on start the service lists its webhooks (`/api/oauth2/v2/webhooks` shows only
our client's), creates one if there's none, and patches its URI, triggers and `paused: false` if they've drifted.
The secret Patreon returns is kept in the database.
- Triggers: `members:create`, `members:update`, `members:delete`, `members:pledge:create`, `members:pledge:update`,
`members:pledge:delete`.
- Each request is checked against `X-Patreon-Signature` (the hex HMAC-MD5 of the body with the webhook's secret)
before anything else; then the member is fetched again (`/api/oauth2/v2/members/{id}`, with
`currently_entitled_tiers`) and that account recomputed.
- Patreon retries for a week and then pauses the webhook. The start-up check unpauses it, and a **nightly sync** of
every member (`/campaigns/{id}/members`) catches anything missed.
**From a member to an entitlement**:
| Patreon says | Entitlement |
| --- | --- |
| `patron_status: active_patron`, a listed tier in `currently_entitled_tiers` | The tier's grant, until `next_charge_date` plus 7 days' grace |
| `declined_patron` (a failed charge; Patreon retries) | Kept until the grace runs out |
| `former_patron`, deleted, or no listed tier | None |
Yearly memberships (`pledge_cadence: 12`) need nothing more: their `next_charge_date` is a year off. Patreon turns
them on for a page after some membership history; we've asked to be included.
Refunds, chargebacks and cancelling are Patreon's; the member's status follows them and our entitlement with it.
## Grants
Moderators give entitlements without money (testers, gifts, apologies): `{sub, key, quantity, until, reason, by}`,
from an admin command first and a page later, every one in the audit log. Phase 1 is built on these, so the paid
tier is tested before anyone pays.
## Processors
| Merchant | Candidates | Notes |
| | | Notes |
| --- | --- | --- |
| `music` | **Stripe** directly | 2.9% + 30¢ (US cards). We are the seller: sales tax and VAT are ours (Stripe Tax calculates; registering and filing are ours). EU VAT on digital services applies from the first sale to an EU consumer. |
| | **PayPal** (business account, micropayments pricing) | 4.99% + 9¢ once opted in (it applies to the whole account; standard is 3.49% + 49¢), so the cheapest for small charges, and familiar to buyers. We are the seller, as with Stripe. Same rules against infringing goods; known for sudden limits, funds held up to 180 days, and disputes that favour buyers of digital goods. Goods and services payments only, never friends and family. |
| | A **merchant of record** (Paddle, Polar, Stripe Managed Payments, which absorbed Lemon Squeezy) | About 5% + 50¢. They're the seller and handle tax everywhere. They review what they sell before onboarding, and a YouTube-based music service may not pass. |
| `t5de` | **Adult-friendly processors** (CCBill, Segpay, Verotel, Epoch) | Around 10-15% plus reserves, quoted per merchant. Their own content and age-verification rules (the hub's age checks help); read them before building anything adult that's paid. |
| | Crypto (self-hosted BTCPay Server) | No processor fees; an extra option, not the only one. |
| **Patreon** | Used | Above. No upfront review of what's offered; its guidelines still forbid infringing content, so the pages sell hosting (docs/music.md, Paid tier). |
| **Polar** (merchant of record) | To ask, not used | 5% + 50¢ (+1.5% for non-US cards) on new accounts. Its acceptable use policy (2026-10-01) forbids "third-party content downloaders, including … YouTube" (#30) and "services to circumvent the rules, paywalls or terms of other services" (#18). To ask its support, with an honest description; built only on a written yes. |
| Paddle, Stripe Managed Payments | Not used | Merchants of record with the same rules against downloaders and infringement. |
| Stripe, PayPal directly | Not used | We'd be the seller: sales tax and VAT ours. |
| Adult-friendly processors (CCBill, Segpay, Verotel, Epoch) | For the hub, later | Only if the hub ever sells adult content; a separate merchant account, never through Music's. Whether it's this service or another is decided then. |
## Pricing near cost
A provider is an adapter behind one interface, so Polar (or another) can run beside Patreon:
Card fees are mostly the fixed part, so small charges lose a lot:
```ts
interface Provider {
// Where to send a signed-in person to start paying, and to manage what they pay for.
join(sub, offer): Promise<{ url: string }>;
manage(sub): Promise<{ url: string }>;
// Verifies the signature; null when the request isn't the provider's.
webhook(request): Promise<{ source: string } | null>;
// A source's current state, fetched from the provider.
source(id): Promise<SourceState>;
// Every source, for the nightly sync.
sources(): AsyncIterable<SourceState>;
}
```
| Charge | PayPal micropayments (4.99% + 9¢) | Stripe (2.9% + 30¢) | Merchant of record (5% + 50¢) |
| --- | --- | --- | --- |
| $1 a month | 14¢ (14%) | 33¢ (33%) | 55¢ (55%) |
| $10 a year | 59¢ (6%) | 59¢ (6%) | $1.00 (10%) |
| $5 of credits | 34¢ (7%) | 45¢ (9%) | 75¢ (15%) |
## Lapses
So: a yearly price (about $10 a room), or credits bought in $5 steps that pay $1 a month per room. A real $1 a month
only works on PayPal's micropayments pricing.
- A failed renewal keeps the entitlement for 7 days past the charge date (Patreon retries meanwhile), then the extra
rooms drop to the free tier. Nothing is deleted; paying again brings them back.
- Every grant, change and revocation is in the audit log, with the event or person that caused it.
### Credits
## Selling as an individual
Credits change the fees, not who will process them: processors approve what credits are spent on, so a processor
that won't sell Music's paid tier won't sell credits for it either. If we sell them:
- **Per merchant**: Music's credits are spent only on Music. Credits usable in the hub too would put T5DE's sales
through Music's processor (or the reverse), which undoes the separation above.
- **Never transferable or cashable**: credits that move between people or turn back into money start to look like
money transmission.
- **No expiry, and refunds of unspent credits on request**: some US states treat expiring prepaid balances like gift
cards, and EU buyers have withdrawal rights. A ledger (bought, spent, refunded) per account, not a balance column.
### Selling as an individual
- No company is needed to start: Stripe and the merchants of record accept individuals (sole proprietors), with a
tax ID (SSN in the US) and a bank account. Income goes on a personal return (Schedule C in the US), with
- No company is needed: Patreon (and the merchants of record) accept individuals with a tax ID (SSN in the US) and a
bank account. Patreon reports the income (a 1099-K in the US); it goes on a personal return (Schedule C), with
self-employment tax on the profit.
- **With Stripe directly** we are the seller: the receipts show a business name (a trade name, which some states
require registering as a DBA), and EU sales legally need the seller's name and address shown.
- **With a merchant of record** the merchant of record is the seller: buyers see its name, and it handles tax
everywhere.
- A single-member LLC later: state filing fees vary widely (some states also charge a yearly minimum tax), plus a
free EIN and a registered agent to keep a home address off public records. It shields personal assets from the
business's debts and contracts, but not from claims about what its owner did personally, such as infringement.
- Patreon is the seller, so tax on the sales is Patreon's, not ours; income tax on the payouts is ours.
- A single-member LLC later: state filing fees vary widely, plus a free EIN and a registered agent to keep a home
address off public records. It shields personal assets from the business's debts and contracts, but not from
claims about what its owner did personally, such as infringement.
- An hour with an accountant before the first sale; this section isn't tax or legal advice.
## Lapses, refunds and chargebacks
- A failed renewal gets a grace period (7 days), then the room drops to the free tier. Nothing is deleted.
- A refund or chargeback ends the entitlement at once. Repeated chargebacks: no new checkouts for that account.
- Every grant, refund and revocation is in the audit log.
## Phases
1. **Entitlements without money**: tables, moderators' grants in the console, the back-channel to Music, and
Music's paid features behind `music.room`. Lets the paid tier be tested and given away before anyone pays.
2. **Music's processor**: the adapter, checkout, webhooks, a Billing page under Account on the hub, links from Music.
3. **T5DE's processor**, when the hub has something to sell.
4. **Credits and codes**; a merchant of record if tax work grows.
1. **Entitlements without money**: the service with sign-in, grants, entitlements and the back-channel; Music's paid
features behind `music.rooms`. Lets the paid tier be tested and given away before anyone pays.
2. **Patreon**: linking, the webhook, the nightly sync; the page published.
3. **Polar**, if it says yes.
4. **The hub's offerings**, if it ever sells any (Processors, above).
## Before taking money
Terms of service with a refund policy, a privacy policy, and the accountant's hour (Selling as an individual, above).
- Terms of service: what's paid for (hosting, never a source), that sources such as YouTube can stop working or be
switched off without refunds, and Patreon's refunds.
- A privacy policy covering what's kept from Patreon (user ID, membership status and tier, no payment details).
- The accountant's hour (Selling as an individual, above).
## Open decisions
- Music: PayPal (cheapest for $1 charges, what the popular community bot uses), a merchant of record (it's the
seller and handles tax; a refusal at onboarding costs nothing), Stripe directly, or IMVU credits (docs/music.md,
Paid tier). Several can run side by side behind the adapter interface.
- Yearly price or credits for the paid tier.
- Whether the Billing page lives only on the hub, or Music also shows its own subscriptions.
- Polar's answer.
- Whether grants get a page, or stay an admin command.
- The tiers after launch: a 10-room tier for clubs, prices once there's usage to look at.