Repository navigation
feat(wallet): monthly plan credits, same rules as voice's call limit - #1460
Dev-Bhumika03 wants to merge 1 commit into
Conversation
New merchants get a 0-credit wallet and Assist chat refuses every turn at
zero, so every onboarded widget is dead until an admin recharges it.
Wallets can now carry a plan, pushed by the billing platform (nautilus for
Shopify) through PUT /wallet/{merchant_id}/plan {plan_credits, status}.
The rules mirror nautilus's voice limit (checkMonthlyLimit,
reset_monthly_order_counters):
- balance = plan_credits minus what was used this month
- back to plan_credits on the first credit check of a calendar month (UTC)
- a plan change moves the balance by (new - old) at once; used stays used
- FROZEN blocks, TRIAL is unlimited
Wallets without a plan (plan_status NONE) keep today's prepaid behaviour.
Every balance move writes a ledger row (plan_change / plan_reset); the
monthly reset is keyed merchant+month and runs under the wallet lock, so
concurrent checks reset once.
Migration 086 adds plan_credits, plan_status and period_month to wallets.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
Problem
Every new merchant gets a wallet with 0 credits, and Assist chat refuses every turn at 0 (
insufficient_credits). So every onboarded widget is dead until someone recharges it by hand (e.g. kpspoint.com, 2 Nov).What this does
Wallets can carry a monthly plan, with the same rules as Breeze Buddy voice's monthly call limit (nautilus
checkMonthlyLimit/reset_monthly_order_counters):The billing platform pushes the plan:
/recharge. nautilus already calls asnautilus-service(ADMIN).plan_status = 'NONE', all existing wallets) keep today's prepaid behaviour. They're never reset.plan_change, orplan_reset(keyed merchant+month).plan_creditsis 0 – 1,000,000,000.Changes
086_wallet_plan_credits.sql:wallets.plan_credits,plan_status,period_month(additive, with defaults).services/breeze_buddy/wallet/plan.py: the rules as small pure functions, plusset_plan/reset_month.accessor/.../wallets.py:apply_plan_update(lock → decide → ledger row → plan columns).wallet/deduction.py:has_sufficient_creditsapplies FROZEN/TRIAL and the monthly reset. Chat and try-on callers are unchanged.PUT /wallet/{merchant_id}/plan.Not in this PR
Testing
tests/breeze_buddy/test_wallet_plan.py(20 tests). Full suite: 4,888 passed.🤖 Generated with Claude Code