Files
sorsfonalak/crates/db/migrations/0027_stripe_checkouts.sql
T
fecoandClaude Opus 5.5 e530e78c54
CI / test (push) Successful in 1m25s
CI / build (push) Successful in 5m20s
CI / deploy (push) Skipped
Stripe: company purchases, payment details kept for the invoice
The checkout offers buying as a company (name, tax number). A confirmed
payment keeps Stripe's payment id, the amount charged and the buyer's
billing details, and queues the invoice for a background job (Billingo,
once the company exists). Payments outlive a deleted account for the
accounting law's 8 years. The package cards, the FAQ and the privacy
policy say that card details go to Stripe only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
2026-11-20 07:26:03 +00:00

36 lines
1.7 KiB
SQL

-- Stripe Checkout sessions started from the package cards. The package is
-- granted once, when the payment is confirmed (webhook, or the return page
-- asking Stripe), and the session id keeps that from happening twice.
-- Card details never reach us: only what Stripe reports about the payment and
-- the buyer's billing details for the invoice.
CREATE TABLE stripe_checkouts (
-- Stripe's Checkout Session id (cs_test_… / cs_live_…).
id text PRIMARY KEY,
-- Kept when the account is deleted: payments and invoices must be kept
-- for the accounting law's 8 years.
user_id uuid REFERENCES users ON DELETE SET NULL,
package text NOT NULL,
price_huf integer NOT NULL CHECK (price_huf > 0),
live boolean NOT NULL,
created_at timestamptz NOT NULL DEFAULT now(),
-- Filled when the payment is confirmed.
completed_at timestamptz,
order_id uuid REFERENCES package_orders ON DELETE SET NULL,
payment_intent text,
-- What Stripe charged, in forints.
amount_huf integer,
-- Stripe's customer_details: name, e-mail, address, and for a company
-- its name and tax ids.
customer jsonb,
-- The invoice (a background job issues it): pending → issued, or failed
-- after retries (an admin looks at it).
invoice_status text CHECK (invoice_status IN ('pending', 'issued', 'failed')),
invoice_attempts integer NOT NULL DEFAULT 0,
invoice_error text,
invoice_number text,
invoiced_at timestamptz
);
CREATE INDEX stripe_checkouts_user_idx ON stripe_checkouts (user_id, created_at DESC);
CREATE INDEX stripe_checkouts_invoice_idx ON stripe_checkouts (completed_at) WHERE invoice_status = 'pending';