# Stripe checkout and CUSTOS lease provisioning

The Express backend serves `POST /api/stripe/webhook` before any JSON parser. Stripe verifies the exact request bytes with the selected environment-only webhook secret and a 300-second tolerance. Unsigned or altered bodies return HTTP 400. Authenticated unrelated events are acknowledged without provisioning.

For `checkout.session.completed`, the handler requires a mode-matched event and received Session, retrieves the Session from the selected Stripe account, and verifies its ID, mode, completion, paid status, one-time payment mode, application product metadata, approved Price, quantity one, and buyer linkage. Unpaid or cross-mode events cannot mint leases. The server-created checkout is linked to the stored buyer reference, email, buyer-provided Ed25519 holder public key, and hashed browser-access token. No buyer private key is generated or derived from an email.

## Production and development configuration

Production (`NODE_ENV=production`) prioritizes one atomic custom application configuration:

- `LIVE_STRIPE_SECRET_KEY`: server-only restricted `rk_live_` or full-access `sk_live_` credential.
- `LIVE_VITE_STRIPE_PUBLISHABLE_KEY`: matching `pk_live_` key. This variable is read by the backend; its public value is returned in `/api/checkout/config`, not resolved from the managed Vite key.
- `LIVE_STRIPE_WEBHOOK_SECRET`: server-only signing secret for the live apex callback.
- `LIVE_STRIPE_PRICE_ID`: approved active live one-time Price, currently `price_1UgsCN3q3nLyDVkIN3XZo9uL`.
- `APP_ORIGIN`: exactly `https://ericscott.ai` for this authorized deployment.

The four LIVE variables are Production-only. Presence of any custom live variable selects live configuration; a missing, blank, or malformed partner fails closed rather than mixing managed sandbox credentials. If no custom live variables have ever been supplied, production retains test-only fallback, explicitly reporting sandbox mode. Development always ignores LIVE variables and uses managed `STRIPE_SECRET_KEY`, `VITE_STRIPE_PUBLISHABLE_KEY`, `STRIPE_WEBHOOK_SECRET`, and the sandbox Price default or development `STRIPE_PRICE_ID` override.

The integration-owned Stripe keys are unchanged and remain sandbox keys. **Custom production application secrets do not switch the managed Integrations UI to Live mode, register a webhook, or claim the temporary sandbox.** Save the custom values through Application secrets/Environment changes approval and republish for production to load them. No secret values belong in source files, commands, documentation, browser storage, or logs.

Readiness retrieves the approved Price from the selected account and requires it to be active, mode-matched, one-time USD, with an integer amount at least Stripe’s USD 0.50 minimum. The public config reports the actual Price amount rather than assuming the historical USD 1.00 sandbox amount. A confirmed missing live callback blocks checkout readiness; inability to read callback registration reports `webhookRegistration: unverified` and must be independently checked by the owner. A registered endpoint is not proof that the secret matches or that a paid event was delivered.

## Restricted-key permissions and callback

The live account needs an enabled endpoint at **`https://ericscott.ai/api/stripe/webhook`**, subscribed to **`checkout.session.completed`**, with a signing secret that matches `LIVE_STRIPE_WEBHOOK_SECRET`. Check the existing live endpoint; do not create a duplicate solely because custom values were saved. The managed integration’s test callback targets Preview and is not evidence of a live callback.

The restricted credential must permit Checkout Sessions creation, retrieval, and expiration; Prices retrieval; and dependent resources required by checkout, customer creation, promotion codes, and expanded line items. Orders enrichment retrieves `payment_intent.latest_charge`; grant the required Payment Intents/Charges read permissions if receipt links are needed. Webhook Endpoints read permission allows the optional registration check. Exact permission labels and account restrictions are controlled by Stripe. Do not grant unrestricted access solely to bypass a missing permission.

Live checkout accepts only the exact apex and www origins and requires the request Origin to match the submitted origin. Paths, queries, credentials, and Preview origins are not accepted for production checkout. Redirect URLs are built from the approved browser origin. The installed Stripe SDK supports `allowed_payment_method_types: ["card"]` to constrain immediate checkout methods.

## CUSTOS signing and policy

`CUSTOS_ISSUER_SEED` is the server-only 32-byte Ed25519 issuer seed encoded as 64 hex characters, with no fallback seed. Its derived public key must match issuer pin `157d41e3024408a115fb8dded8acfc87411668d24df3cba143a199a12de08fda` or the explicit `CUSTOS_TRUSTED_ISSUER_PUBLIC_KEY` override. The owner states this issuer is enrolled in the gate’s trust file; storefront configuration alone cannot enroll it. Do not use the engine signing key as a CUSTOS issuer.

The approved public policy remains `swarm_id: arkheia-7-prod`, sorted scopes `["aegis.evaluate", "mandate.verify"]`, `max_amount: "1000000000"`, and `ttl: 50000` **Lamport ticks**, not seconds. `CUSTOS_LEASE_POLICY` may explicitly override the same closed policy schema. The public transfer fixture policy is not a substitute.

The signer implements the supplied closed v1.0.1 lease schema. Signing preimage: ASCII `ARKHEIA/custos/lease/v1`, a zero byte, and integers-only RFC 8785 JCS of the lease without `sig`, using UTF-16 key ordering. Before issuance, the current clearance head must match both pinned engine key fields and provide a safe Lamport clock. Supplied fixture signatures verify offline; no live transfer fixture is replayed.

## Durability, delivery, and limits

A MySQL transaction inserts the unique event ID and locks the checkout record. Signing and fulfillment commit together. Redelivery, or another event for an already fulfilled Session, cannot issue a second stored lease. Failed processing rolls back and returns 503 so Stripe can retry. No raw payload, lease, email, access cookie, or private signing material is logged.

Managed development and production share the database; apply only committed additive migrations with `pnpm db:migrate`. Regression tests use generated test keys and mocked Stripe/DB adapters, not real purchases.

`GET /api/orders` requires the secure HttpOnly SameSite=None browser token established at checkout. Only its hash is stored. A public Session ID grants no access. The success page stays pending until fulfillment commits, then offers the lease download. Buyer access expires after 30 days; cross-device or expired-token recovery needs a separate authenticated flow. Historical test orders are not deleted during this transition; cross-mode billing enrichment does not masquerade as live billing.

Refund/dispute revocation, recurring renewal, and delayed-payment fulfillment are not implemented. Only immediate one-time card checkout is supported. The storefront’s **Request Founding Pilot Access** CTA remains an intake form, not checkout, and neither grants a lease nor takes payment.

## Deployment verification

Both ericscott.ai and www.ericscott.ai are attached and active; www GET navigation canonicalizes to the apex. No DNS was changed. Validate production readiness and the existing live callback after publication. An authenticated ignored synthetic event tests raw signing only and is not proof of paid fulfillment. No real payment or valid gate action is performed as part of deployment verification.
