Switch SMS billing to credit units with IRT top-ups.

Balance is SMS credits (1 per 64 chars); top-ups add floor(IRT/500) credits, track sms_sent_count, and convert existing IRT balances.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-09-09 11:10:22 +03:30
co-authored by Cursor
parent 07f3304c07
commit 584c01fcee
9 changed files with 152 additions and 32 deletions
@@ -0,0 +1,8 @@
-- Lifetime count of SMS messages successfully billed to each business
-- (incremented on charge, decremented on refund). One unit = one recipient.
ALTER TABLE businesses
ADD COLUMN IF NOT EXISTS sms_sent_count INTEGER NOT NULL DEFAULT 0;
COMMENT ON COLUMN businesses.sms_sent_count IS
'Lifetime SMS messages billed to this business (one per recipient). Incremented on charge, decremented on refund.';
@@ -0,0 +1,11 @@
-- Convert prepaid SMS balance from IRT to credit units.
-- Previous billing: 400 IRT per 64-char segment.
-- New model: balance is SMS credits (1 credit = 1 segment); top-up at 500 IRT/credit.
-- Preserve existing prepaid capacity: IRT / 400 → credits.
UPDATE businesses
SET sms_balance = sms_balance / 400
WHERE sms_balance > 0;
COMMENT ON COLUMN businesses.sms_balance IS
'Prepaid SMS credit units. 1 unit = one 64-character segment per recipient. Top-up adds floor(IRT / 500) credits.';