Menivor's coupons (videogen processor.py MintDiscounts, apps/mint README
contract) PATCH /mint/v1/sellers/{seller}/discounts/{discount_id} to stop a
code (expires_at now) and to switch it back on with new terms on the same id.
- PATCH forwards a partial Dodo PATCH /discounts/{id} (code, name,
type+amount, currency_options or currency, expires_at incl. null to clear,
restricted_to as the seller's skus) with the seller's own key and answers
200 {discount:{discount_id, id, code, type, amount, expires_at}}.
A change to a percentage sends currency_options [] so an old flat row
never lingers as a percentage cap (Dodo replace-set semantics).
- Seller-scoped authz: Mint now records which seller of which product made
which processor discount id (mint_seller_discounts, migration 0015; memory
store too). Any other id, or a code deleted on the dashboard (Dodo 404),
is 404 unknown_discount; the seller error shape throughout.
- Validation before any call: id charset, type and amount together, flat
needs one currency row whose max_amount_possible is the amount, RFC 3339
dates, unknown fields refused (400 invalid_body).
- Idempotency: PATCH is naturally repeatable; a retried create of a known
code with the same terms answers 200 created:false (checked with GET on
the seller's account), other terms 409 code_in_use, a code gone from the
processor is made again. Create answers carry discount_id as the contract
says (id kept).
- HttpTransport gains patch_json (default refuses; ReqwestTransport sends).
- Verified against Dodo docs: currency_options rows are {currency,
max_amount_possible, is_default, minimum_subtotal?}; is_default is real and
a flat code needs a resolvable default, so the mapping stays.
- Discount handlers moved to mint-server/src/seller_discounts.rs (seller.rs
was over 800 lines).
Tests: cargo test -p mint-payments seller 11/11 (new stop/re-enable/404 and
validation case); cargo test -p mint-server --test seller 5/5 (new end to
end: stop, re-enable flat, clear expiry, re-code, retried create, conflict,
deleted on dashboard, other seller's id, 11 refusals with no processor
call). pg_seller_live extended (ignored without DATABASE_URL). Clippy: no
findings in touched files (pre-existing mint-store/main.rs findings untouched).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
17 lines
981 B
SQL
17 lines
981 B
SQL
-- Seller discount ownership (Wave Q, for Menivor QM1.3 creator coupons).
|
|
-- Mint makes a discount code on the seller's own processor account; the terms
|
|
-- live there. Only which seller of which calling product made which
|
|
-- processor discount id is kept, so one seller can never stop or change
|
|
-- another seller's code. Beside the ledger and never in it. Idempotent: safe
|
|
-- if applied by hand before sqlx records it.
|
|
CREATE TABLE IF NOT EXISTS mint_seller_discounts (
|
|
product TEXT NOT NULL,
|
|
seller TEXT NOT NULL,
|
|
discount_id TEXT NOT NULL CHECK (discount_id ~ '^[A-Za-z0-9_]{1,64}$'),
|
|
code TEXT NOT NULL CHECK (code ~ '^[A-Z0-9_-]{3,32}$'),
|
|
created_at_ms BIGINT NOT NULL,
|
|
PRIMARY KEY (product, seller, discount_id),
|
|
FOREIGN KEY (product, seller) REFERENCES mint_seller_accounts (product, seller)
|
|
);
|
|
CREATE INDEX IF NOT EXISTS mint_seller_discounts_code_idx ON mint_seller_discounts (product, seller, code, created_at_ms DESC);
|