- A second way to pay for a pass: Swiss francs on Stripe's hosted page, where the Stripe account's methods (card, TWINT, wallets) are offered. Off until STRIPE_SECRET_KEY and a CHF price are set; each rail is on or off by itself. Stripe is told nothing about the Heidi account. Own webhook path, /api/pay/webhook/stripe. The provider is paykit's (PR bitbaum/paykit#19), copied in lib/pay/stripe-provider.ts until 0.4.0 is released, with a test that fails the day the package has it. - /pass: one card per pass, a price and button per rail; buying is the one filled action. A failed checkout no longer prints "fetch failed". - /owner/payments: each rail, what is set (names only), what is missing, and the webhook addresses to paste. - Chat: a Model button for everyone; the sheet names the free models. - A daily allowance of free turns (100, HEIDI_FREE_TURNS_PER_DAY), three times with a pass, none with an own key; the chat says so and links /pass. - /pass added to the layout audit. Claude-Session: https://claude.ai/code/session_019MDtmteJuDGFouA1itJ5tM Co-authored-by: Claude <noreply@anthropic.com>
10 KiB
Passes: Bitcoin to Heidi's OrangeCat account
A pass is one payment for a number of days. Bitcoin has no recurring charge, so
nothing renews by itself; paying again before a pass runs out adds the days to
the end. A pass changes two things. The chat allowance is three times the open
one, in the open chat and in saved conversations (PASS_CHAT_MULTIPLIER in
lib/config/payments.ts). And where the deployment names a model for pass
holders, their turn tries it first (see "The model a pass buys" below).
A pass starts in one of two ways: a Bitcoin invoice paid here, or a code the owner issued (see "Pass codes" below). The first needs a price; the second needs only a database and accounts.
The money goes from the learner's wallet to the wallet behind Heidi's OrangeCat entity. Heidi never holds it and stores no wallet address.
What is in the package and what is here
@bitbaum/paykit owns everything that moves or checks money: the provider
interface, the OrangeCat provider (invoice, status, webhook signature), the
entitlement arithmetic and applySettlement, which grants once per payment.
This app owns configuration, storage and words:
| Where | What |
|---|---|
lib/config/payments.ts |
which passes exist, their prices and the payee, all from the environment |
lib/pay/store.ts |
pay_checkouts and entitlements on Postgres (drizzle/0014_passes.sql) |
lib/pay/service.ts |
joins the package to the config and the database |
app/api/pay/checkout |
POST {plan} creates an invoice; GET /<id> reads its state and settles when paid |
app/api/pay/webhook |
receives OrangeCat's payment.settled |
app/[locale]/pass |
the field that takes a pass code; when a price is set, the passes and the link to OrangeCat; while none is, one line that says so; /pass/checkout/<id> shows the invoice |
lib/pay/codes.ts |
pass codes: making one, keeping its hash, granting it once (drizzle/0020_pass_codes.sql) |
app/api/pay/redeem |
POST {code} redeems a code for the signed-in person |
app/api/owner/pass-codes |
owner only: GET what was issued and how much is used, POST {count, days, label} issues codes |
app/[locale]/owner/pass-codes |
the owner's form for the same, since a phone cannot send a POST from its address bar |
lib/domain/model/pass-model.ts |
the model a pass buys, as one paid row in front of the free chain |
lib/pay/stripe-provider.ts |
paying in francs, a copy of @bitbaum/paykit/stripe until 0.4.0 is released |
app/api/pay/webhook/stripe |
Stripe's checkout.session.completed, on its own path and secret |
lib/pay/readiness.ts, app/[locale]/owner/payments |
the owner's checklist: each rail, what is set, what is missing |
How a payment runs
- A signed-in learner presses a pass's button on
/pass. Heidi asks OrangeCat for an invoice paying the configured entity (through paykit: the keyedPOST /api/v1/payments, or the account-lessPOST /api/v1/payments/public) and stores the checkout: OrangeCat'spayment.settlednames only the payment, so the stored row is the only link back to the learner. /pass/checkout/<id>shows the invoice as a QR code and as a wallet link.- Settlement arrives two ways, and both end in the same
applySettlement: OrangeCat calls the webhook, and the open checkout page pollsGET /api/pay/checkout/<id>every four seconds, which asks OrangeCat. The first to arrive grants the days; the other is a duplicate.
A payment made on OrangeCat's own page for the entity reaches the same wallet but starts no pass, because nothing links it to a Heidi account. The webhook acknowledges it and does nothing.
Switching it on
The button on /pass that opens Heidi's public OrangeCat page needs no
configuration, and is shown only together with the passes: a payment there
grants nothing in Heidi.
The automatic pass is off until at least one price is set. While it is off,
/pass says so and offers no payment, POST /api/pay/checkout answers 503 and the webhook answers
503.
The values go in the app's .env on the box, beside the others
(.env.example lists them):
| Name | Value | Needed |
|---|---|---|
HEIDI_PASS_30_SATS |
price of 30 days, in whole sats | yes: this switches it on |
HEIDI_PASS_365_SATS |
price of 365 days, in whole sats | no |
ORANGECAT_API_KEY |
an ock_… integration key with the scopes payments.write and payments.read |
no, see below |
ORANGECAT_WEBHOOK_SECRET |
the ock_whk_… secret of the webhook endpoint |
no, but without it only the open checkout page settles a payment |
ORANGECAT_PAY_ENTITY_ID |
the OrangeCat entity that is paid | no: Heidi's project when unset |
ORANGECAT_PAY_ENTITY_TYPE |
its kind | no: project when unset |
On OrangeCat, signed in as the account that owns the paid entity, at
https://orangecat.ch/settings/integrations:
- Webhook. Add an endpoint for the account's personal actor with the URL
https://heidi.orangecat.ch/api/pay/webhookand the eventpayment.settled. The secret is shown once; it isORANGECAT_WEBHOOK_SECRET. - Integration key. Mint a key with
payments.writeandpayments.read; it isORANGECAT_API_KEY.
About the key: OrangeCat records a key's owner as the buyer of a keyed payment and refuses an owner paying their own entity ("You cannot pay for your own entity"). A key minted by the account that owns Heidi's project is that case. paykit then asks for the invoice through OrangeCat's account-less call instead, so the learner still gets one; the money and the webhook are the same either way. A key from a different OrangeCat account is used as it is.
The wallet behind the entity has to be one OrangeCat can watch settle: wallet-connect (NWC), a Lightning address whose provider supports LUD-21 verification, or an on-chain address. With a bare Lightning address OrangeCat cannot see the payment arrive, and neither the webhook nor the poll will ever report it paid.
Paying in francs: card, TWINT, wallets
Off until configured. A second rail beside Bitcoin, through a Stripe account:
the buyer pays on Stripe's own page, so no card number reaches Heidi, and
Stripe is told nothing about the Heidi account (sendReference: false).
To switch it on:
- Open a Stripe account for whoever receives the money, and finish its verification.
- In Stripe, Settings → Payments → Payment methods: switch on TWINT and any other method. Heidi does not choose: Stripe offers what is on there for a price in CHF. TWINT through Stripe is CHF only and at most 5000.00 CHF a payment.
- On the server:
STRIPE_SECRET_KEYandHEIDI_PASS_30_CHF(andHEIDI_PASS_365_CHFif a year is sold). Prices in francs:12or12.50. - In Stripe, Developers → Webhooks: add
https://<host>/api/pay/webhook/stripeforcheckout.session.completedandcheckout.session.async_payment_succeeded, and put itswhsec_…secret inSTRIPE_WEBHOOK_SECRET. Without it a pass still starts, when the buyer is back on Heidi's checkout page.
/owner/payments shows, for the owner only, which of these are set (names,
never values) and the addresses to paste.
The provider is stripeProvider from @bitbaum/paykit 0.4.0
(bitbaum/paykit#19). Until that version is on the registry it is copied into
lib/pay/stripe-provider.ts, and a test fails the day the package has it, to
say the copy can go.
Each rail is on or off by itself. /pass shows one card per pass, with a
price and a button for each rail that sells it, francs first.
The daily allowance
Without a pass and without an own key, a person may ask 100 questions a day
(HEIDI_FREE_TURNS_PER_DAY; 0 switches it off). A pass gives three times as
many; an own key does not count at all, because those calls are paid on the
learner's account. When it is used up the chat says so in the reader's
language and links /pass.
Pass codes
For a pass that was paid for where Heidi cannot see it: an organisation paying
in francs for its people, or a pass given away. The owner issues one code per
person; each person redeems theirs on /pass, signed in. A code grants its
days once, through the same extendEntitlement of @bitbaum/paykit a settled
payment goes through, so codes and payments add up.
- Name the owner in the app's
.env(OWNER_EMAILSorOWNER_ACTOR_IDS, the same gate as/api/owner/numbers). - Signed in as the owner, open
/owner/pass-codes. Say who the codes are for, how many, and how many days each. Up to 200 codes and 366 days a time. - The codes are shown once. Copy them and send them on. The database keeps only each code's SHA-256 and its last four characters.
- The same page lists what was issued, by label, and how many are used.
A code is sixteen characters without I, L, O and U, written in four groups. What somebody types is read forgivingly: case, spaces and dashes do not matter. Redeeming is limited to ten attempts in ten minutes per account.
Nothing here sets a price. What an organisation pays, and how, is agreed with it directly; the page for organisations says so and offers a mail link.
The model a pass buys
Off until configured. HEIDI_PASS_MODELS names one or more model ids at
OpenRouter, in order; they use the deployment's OPENROUTER_API_KEY. A pass
holder's turn tries them first and falls back to the free chain. Somebody who
brought their own key still gets their own model.
The row is marked paid, so every rule of @bitbaum/ai-kit's spend module
applies and none is restated here: it is in the chain only with
AI_PAID_DISABLED=0 and HEIDI_AI_PAID_OK=1, and a call is made only inside
Heidi's daily paid cap (HEIDI_DAILY_PAID_CALLS, _INPUT_TOKENS,
_OUTPUT_TOKENS) and the fleet's. A call the rules refuse is not made and the
free chain answers.
/pass promises the stronger model only while all of that is set. No model
id is written in this repository.
Trying it without money
lib/pay/codes.test.ts issues and redeems against the real migrations,
including one code redeemed three times at once.
lib/domain/model/pass-model.test.ts asks ai-kit itself whether a pass link
would be let through.
lib/pay/store.test.ts settles against the real migrations on an in-process
Postgres, including the same payment reported three times at once.
app/api/pay/webhook/route.test.ts covers the off state and forged calls. The
package's own tests cover the signature and the OrangeCat request shapes.