From ebe24f2f076ed7472de451c24bbc8c43348ba931 Mon Sep 17 00:00:00 2001 From: dhkatz Date: Fri, 20 Nov 2026 11:27:47 -0800 Subject: [PATCH] docs(payments): a payments service of its own, Patreon first Payments move out of the hub into t5de-payments (its own repo, database and secrets) to contain the risk. Patreon is the first way to pay: it's the seller, so sales tax and VAT are its. Polar's acceptable use policy now names YouTube downloaders, so it's only used on a written yes. No IMVU credits, no Stripe or PayPal directly. Music's paid tier sells hosting only: YouTube's limits are the same in both tiers. Entitlements become a count (music.rooms) because a Patreon member has one tier; the owner picks which rooms are paid. --- docs/music.md | 40 +++++---- docs/payments.md | 228 ++++++++++++++++++++++++++++------------------- 2 files changed, 159 insertions(+), 109 deletions(-) diff --git a/docs/music.md b/docs/music.md index 368a7fe..c1d31f1 100644 --- a/docs/music.md +++ b/docs/music.md @@ -10,8 +10,8 @@ accounts there without making a T5DE account first; one can be added later witho ## Goals - **Cheap at scale**: listeners pull audio from a bandwidth-cheap host (Oracle Cloud's free tier to start), never - through home or the relay. A paid tier priced near cost, billed through a payments backend shared with the hub - (docs/payments.md). + through home or the relay. A paid tier priced near cost, through a Patreon membership and a payments service of + its own (docs/payments.md). - **Three things to play** to start (**Decided**): existing internet radio stations (a searchable list from radio-browser.info), the owner's own stream (bring your own), and a queue of songs found on YouTube. **More sources later** without reworking anything (Sources, below). Jamendo and Audius are out for now: Jamendo's API is @@ -255,14 +255,15 @@ both tiers, free with limits: - **If YouTube breaks or has to go** (blocked, a takedown, a processor's demand), paid rooms keep everything they paid for, and it's switched off without refunds. -- **What the pricing page sells** is music bot hosting, not "pay to play YouTube songs". -- **Free YouTube is the trial**: people use it, reach the limits, and upgrade. +- **What the pricing page sells** is music bot hosting, not "pay to play YouTube songs". YouTube's limits are the + same in both tiers (**Decided**), so nothing about YouTube is for sale. +- **The free tier is the trial**: people use it, want better audio or more listeners, and upgrade. -| | Free | Paid ($1.99 a month per room) | +| | Free | Paid (Patreon: $1.99 a month for 1 room, $4.99 for 3) | | --- | --- | --- | -| Rooms | 1 | One subscription per room | +| Rooms | 1 | 1 or 3, by tier, on top of the free one | | Stations and own streams | Yes (direct where possible, so they cost nothing) | Yes | -| YouTube search and queue | Short queue, a few songs an hour | Unlimited queue, longer songs | +| YouTube search and queue | Fair-use limits: queue length, songs an hour, the longest song | The same | | Audio | 64 kbps | 128 kbps | | Listeners | A small cap (about 10) | Up to the room's capacity | | Saved playlists, scheduled playback | No | Yes | @@ -273,13 +274,16 @@ The free limits are what keep free YouTube affordable: it's always relayed (band (CPU), unlike direct stations. The bot also leaves free rooms when they're empty. Exact limits are settings, tuned once there's usage to look at. -Another way to pay, to check: **IMVU credits**, which every IMVU user already has. Buying a product we list in -IMVU's shop (a "Music Pass") is the payment, and the bot checks the buyer owns it. No processor at all, but it -depends on IMVU's rules for selling services and on how its credits cash out now; both to read before relying on it. +IMVU credits aren't a way to pay (**Decided**, docs/payments.md). -The paid entitlement is `music.room` with the room as its scope (docs/payments.md, Entitlements). Pricing: about -$1.99 a month per room (the most popular community bot starts at $4.99 for one room); on PayPal's micropayments -pricing that loses about 19¢ to fees. A yearly price at a discount on top. +**Paying** (**Decided**: Patreon first, docs/payments.md): a Patreon membership, linked to the person's account on +payments.t5de.dev. A Patreon member has one tier, so tiers are room bundles: "Room" ($1.99 a month, 1 room) and +"Rooms" ($4.99, 3 rooms); the most popular community bot starts at $4.99 for one room. After Patreon's 10% and +processing, $1.99 is about $1.59. Yearly memberships at a discount once Patreon turns them on for the page. + +The paid entitlement is `music.rooms`, a count (docs/payments.md, Concepts). The owner picks which of their rooms are +paid on the room's page, up to the count. If the count drops (a lapse, a smaller tier), the most recently picked +rooms go back to the free tier first, and the owner can swap which ones. **One stream URL, many rooms.** The stream is plain HTTP, so anyone can paste a room's URL into other rooms (or any player), and they'll all hear it. Only the bot's own room has commands, but every extra listener costs bandwidth, @@ -324,9 +328,9 @@ published by CI like images. t5de-site moves from its copies to `@t5de/ui` when charging for it makes it commercial. Relaying stations and owners' own streams is the safest part. Search providers stay pluggable, so a licensed one can replace or join YouTube. - **Payment processors**: Stripe and the merchants of record forbid selling services that infringe copyright, and - review what they're selling. A paid service built on YouTube's audio can get the merchant account closed, with - funds held. Music's merchant account is kept separate from T5DE's (docs/payments.md), so that can't take the hub's - payments with it. + Polar's rules name YouTube downloaders outright. A paid service built on YouTube's audio can get the account + closed, with funds held. Patreon is used, selling hosting only, and payments are a service of their own + (docs/payments.md), so a closed account can't take the hub or Music down with it. - **YouTube from a datacenter**: yt-dlp from cloud IPs is often blocked ("confirm you're not a bot") and needs a token provider, a JavaScript runtime and sometimes an account's cookies; it's also against YouTube's terms. Paying users will expect it to work, so the operator setting that turns it off, and the status page, matter more. @@ -347,7 +351,7 @@ published by CI like images. t5de-site moves from its copies to `@t5de/ui` when DJs, bans, the stream URL. Infra: its stack and Postgres on t5de-apps, music.t5de.dev. 3. **Music, playing**: streamer with stations (relayed) and own streams, the bot with commands and permissions, config sync. **Beta** (free tier). -3b. **Payments** (hub, docs/payments.md phases 1-2): entitlements, Music's processor, checkout; the paid tier. +3b. **Payments** (t5de-payments, docs/payments.md phases 1-2): entitlements and grants, Patreon; the paid tier. 4. **Search and queue**: content providers and the audio cache, the YouTube provider from HorizonRadio, MusicBrainz metadata, `!play`, the queue page. (Phase 3's stations and own streams are already live providers.) 5. **Accounts, later**: merging basic into member accounts, `user.merged`, third-party OIDC clients (console, @@ -355,5 +359,5 @@ published by CI like images. t5de-site moves from its copies to `@t5de/ui` when ## Open decisions -- The free tier's exact limits, and the yearly price (Paid tier, above). +- The free tier's exact limits, and YouTube's fair-use limits (Paid tier, above). - Direct mode's details, once phase 0 has found the call that sets a room's radio and On Air. diff --git a/docs/payments.md b/docs/payments.md index 5d9280d..1e18f83 100644 --- a/docs/payments.md +++ b/docs/payments.md @@ -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; - refund(payment, amount?): Promise; - // Verifies the signature and maps the processor's event to ours. - webhook(request): Promise; - subscription(id): Promise; -} +## 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: "" + tiers: + "": { music.rooms: 1 } + "": { music.rooms: 3 } ``` -Webhooks arrive at `POST /api/v1/billing/webhooks/` 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; + // Every source, for the nightly sync. + sources(): AsyncIterable; +} +``` -| 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. -- 2.54.0