Files
t5de-hub/docs/payments.md
T
dhkatz 20448abd99
Pull request / title (pull_request) Successful in 1s
CI / test (pull_request) Successful in 1m29s
CI / image (apps/api/Dockerfile, t5de-hub-api) (pull_request) Skipped
CI / image (apps/web/Dockerfile, t5de-hub-web) (pull_request) Skipped
docs(payments): PayPal beside Patreon, our own checkout later
PayPal subscriptions sell exactly the pricing ($1.99 a month or $19.99 a year
per room, with a quantity). We're the seller there, so the service works out
EU VAT (included in the price, two pieces of country evidence, a quarterly
One Stop Shop report); it sells outside the EU and the UK until those
registrations take effect.

The service has no website of its own: the app's pages use its API, and the
browser goes through it only for redirects (link Patreon, PayPal checkout,
manage). Later, our own checkout elements embedded from payments.t5de.dev,
so people don't see which processor takes the payment. Staging uses PayPal's
sandbox and the locked staging hub.
2026-11-20 14:16:16 -08:00

278 lines
17 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Payments (plan)
Status: draft (2026-11-20; PayPal added the same day). 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 maybe for the hub later. Payments are their own service,
`t5de-payments`. The first ways to pay are a Patreon membership and a PayPal subscription; later, our own checkout
in which the processor doesn't show.
## Goals
- **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.
- **As little tax work as possible** (**Decided**): Patreon is the seller, so tax on its sales is its own. PayPal
makes us the seller: EU VAT through the non-Union One Stop Shop, worked out and recorded by this service (PayPal,
below); US sales tax only past a state's threshold.
- **No IMVU credits** (**Decided**).
- **No card data** anywhere of ours: the processor's own pages and buttons take the payment.
- **Apps ask one question**: how much of entitlement X does this account have? They never talk to a processor.
- **Eventually, the processor doesn't show** (**Decided**, later): people check out in our own checkout, embedded
from `payments.t5de.dev` in the app's page (Checkout elements, below), and which processor takes the payment is
ours to choose. Patreon is for now.
## Where it lives (**Decided**)
`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.
**Environments** (**Decided**): staging (`payments.staging.t5de.dev`) signs in through staging's hub and uses the
processors' test modes (PayPal's sandbox); prod (`payments.t5de.dev`) uses the live ones. Staging's hub registration
is locked, so only accounts a moderator approved can use it (docs/music.md, Kinds of account).
- **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.
- **No website of its own** (**Decided**): the pages people see (Upgrade, Billing under Account, "Make this room
paid") are the app's, built from this service's API (`GET /v1/accounts/{sub}`: entitlements, links and sources,
for the Billing page). What the browser goes through here only redirects:
- `/link/patreon`: signs in through the hub (at once: they're already signed in), sends them to Patreon to
approve, and back to the app.
- `/checkout/paypal?offer=…&rooms=…&country=…`: makes the subscription (rooms, VAT), sends them to PayPal to
approve, and back.
- `/manage/<source>`: to Patreon's or PayPal's own page for changing or cancelling.
Every redirect back goes only to a return address on the app's list (no open redirects).
```
music.t5de.dev ── /link, /checkout ──► payments.t5de.dev ◄── webhooks, API ──► Patreon, PayPal
▲ │
└─── entitlements.changed, API ─────────┘
```
## Concepts
| | What |
| --- | --- |
| **Provider** | Where money comes from: `patreon`, `paypal`, 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 (Patreon; a PayPal subscription carries the `sub` itself). |
| **Source** | One thing that grants: a Patreon membership, a PayPal subscription, a grant. Mirrored from the provider: status, tier or quantity, 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. |
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).
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.
## 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 (redirect URIs `https://payments.t5de.dev/patreon/callback` and
`https://payments.staging.t5de.dev/patreon/callback`). Patreon has no test mode: staging uses the real page, with
memberships of our own.
**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 }
```
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.
## PayPal (**Decided**: beside Patreon)
A PayPal business account (a sole proprietor, "T5DE Music" on receipts) with PayPal Subscriptions. We are the seller,
so the tax is ours (Tax, below). It sells exactly what the pricing says: **$1.99 a month or $19.99 a year per room**,
one subscription with a quantity (3 rooms is quantity 3), which Patreon's one-tier memberships can't.
**Product and plans** are made through PayPal's API and kept in the configuration (they're IDs, per environment):
```yaml
paypal:
product: PROD-… # "T5DE Music Room", a service, category software
plans:
music.rooms.monthly: P-… # $1.99 a month per room, quantity allowed
music.rooms.yearly: P-… # $19.99 a year per room
```
Prices change through the API (`update-pricing-schemes`) without new plans; how that reaches existing subscribers
(and the notice they're owed) is to check before the first change.
**Checkout** (`/checkout/paypal`): signed in, with the offer, the number of rooms and the buyer's country. The service
makes the subscription with `custom_id` = their `sub`, the quantity, and the VAT for their country (below) as a
plan override, then sends them to PayPal's approval page; PayPal sends them back to the app. Nothing is granted on
the way back: only PayPal's own word (the webhook, or fetching the subscription) does.
**The webhook** is made through the API too, on start (as Patreon's), for `BILLING.SUBSCRIPTION.ACTIVATED`,
`.UPDATED`, `.CANCELLED`, `.SUSPENDED`, `.EXPIRED`, `.PAYMENT.FAILED`, `PAYMENT.SALE.COMPLETED`, `.REFUNDED` and
`.REVERSED`. Each request is verified by PayPal (`/v1/notifications/verify-webhook-signature`, with our webhook's
ID) before anything else; then the subscription is fetched again and its account recomputed. A nightly sync fetches
every subscription the database knows.
**From a subscription to an entitlement**:
| PayPal says | Entitlement |
| --- | --- |
| `ACTIVE` | `music.rooms` × quantity, until `billing_info.next_billing_time` plus 7 days' grace |
| `SUSPENDED` (payments failed 3 times) | Kept until the grace runs out |
| `CANCELLED`, `EXPIRED` | Until the end of the period last paid for, then none |
| A refund or reversal of the last payment | None, at once |
**Where it sells**: everywhere but the EU and the UK at first; the EU once our One Stop Shop registration takes
effect; the UK once registered with HMRC (until then people there use Patreon). The checkout asks for the country and
refuses the ones not open yet.
**Fees**: about 3.49% + 49¢ (56¢ of $1.99) until PayPal enrolls the account in Dynamic Micropayments (4.99% + 9¢,
whichever is cheaper per payment), asked of PayPal support.
### Tax
- **EU VAT** (non-Union OSS, registered in one EU country, Ireland by default): VAT at the buyer's country's rate,
**included** in the price, so $1.99 is $1.99 everywhere. The rate table is in the configuration. Two pieces of
evidence of the country, recorded with each subscription: what the buyer chose and their IP address's country.
If they disagree, no sale; they're asked to check. One return a quarter, made from our own records (`vat-report
<quarter>`), even when there were no EU sales.
- **UK VAT**: the same, once registered with HMRC.
- **US sales tax**: none to start. A state's tax applies only past its threshold (usually $100k of sales, in a few
states also 200 transactions a year); the service reports sales per state, so we see one coming.
- Elsewhere: registration only past thresholds far above our sales (Norway, Switzerland, Australia and others).
## Checkout elements (later)
Our own checkout, so people don't see which processor takes the payment and Patreon can go: the payment parts of
the app's pages are iframes from `payments.t5de.dev/elements/…` (the offer, rooms, country and VAT, and the
processor's own buttons or card fields inside), so the app's page never handles prices, tax or payment details.
- The app frames them; only the apps on a list may (`frame-ancestors`). They tell the app's page when they're done or
need more room (`postMessage`, checked against the origin).
- Who's paying: the hub's sign-in can't be framed (it refuses, as it should), so the app hands the element a
short-lived token for the person (signed by the hub, for this service only). Cookies aren't in the way: the apps
and `payments.t5de.dev` are the same site.
- The redirects above stay, for anything that can't be embedded.
## 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
| | | Notes |
| --- | --- | --- |
| **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. |
| **PayPal** | Used | Above. We're the seller: VAT through the One Stop Shop. Same rules against infringing goods; known for sudden limits and holds, and for siding with buyers in digital goods disputes. |
| Stripe directly | Not used | We'd be the seller, as with PayPal; a candidate for the checkout elements later. |
| 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. |
A provider is an adapter behind one interface, so they run side by side and more can join:
```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>;
}
```
## Lapses
- A failed renewal keeps the entitlement for 7 days past the charge date (Patreon and PayPal retry meanwhile), then
the extra rooms drop to the free tier. Nothing is deleted; paying again brings them back.
- A refund or chargeback ends that source's entitlement at once. Repeated chargebacks: no new PayPal checkouts for
that account.
- Every grant, change and revocation is in the audit log, with the event or person that caused it.
## Selling as an individual
- 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.
- Patreon is the seller, so tax on its sales is Patreon's; PayPal's sales are ours (Tax, above), with "T5DE Music"
as the business name on receipts (some states want a trade name registered as a DBA). Income tax on both 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.
## Phases
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. **PayPal**: checkout (redirect), the webhook, the nightly sync, VAT and its report; outside the EU and the UK
first, the EU once the One Stop Shop registration takes effect.
4. **Checkout elements**: our own checkout, embedded; Patreon retired once it's no longer needed.
5. **Polar**, if it says yes; **the hub's offerings**, if it ever sells any (Processors, above).
## Before taking money
- 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 refunds (Patreon's; ours for PayPal).
- A privacy policy covering what's kept (Patreon: user ID, membership status and tier; PayPal: subscription, payer
ID, country and its evidence; no payment details).
- The accountant's hour (Selling as an individual, above), before registering for the One Stop Shop.
## Open decisions
- Polar's answer.
- Whether Dynamic Micropayments covers subscription renewals (asked of PayPal).
- 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.