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
This commit is contained in:
@@ -1,16 +1,35 @@
|
||||
-- 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,
|
||||
user_id uuid NOT NULL REFERENCES users ON DELETE CASCADE,
|
||||
package text NOT NULL,
|
||||
price_huf integer NOT NULL CHECK (price_huf > 0),
|
||||
live boolean NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
completed_at timestamptz,
|
||||
order_id uuid REFERENCES package_orders ON DELETE SET NULL
|
||||
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';
|
||||
|
||||
Reference in New Issue
Block a user