Stripe & Razorpay Payments
KaiVox supports two payment gateways: Stripe for global users and Razorpay for Indian users. Both are used exclusively for wallet top-ups. Subscription billing is tracked internally — no recurring charges via Stripe/Razorpay yet.
Environment Variables
| Key | Value | Required For |
|---|---|---|
STRIPE_KEY | Publishable key — starts with pk_live_ or pk_test_ | Stripe wallet top-up |
STRIPE_SECRET | Secret key — starts with sk_live_ or sk_secret_ | Stripe server-side charges |
RAZORPAY_KEY | Key ID — starts with rzp_live_ or rzp_test_ | Razorpay wallet top-up |
RAZORPAY_SECRET | Key Secret from Razorpay Dashboard | Razorpay signature verification |
.env — test credentials
# Stripe (test mode — use pk_test / sk_test for local dev)
STRIPE_KEY=pk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxx
STRIPE_SECRET=sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Razorpay (test mode)
RAZORPAY_KEY=rzp_test_xxxxxxxxxxxxxxxxxxxx
RAZORPAY_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Never commit live Stripe or Razorpay keys to git. Use
.env only — .env is in .gitignore. For staging use test keys. Only switch to live keys on production.Wallet Top-Up Flow
Stripe Flow
-
Tenant selects Stripe and enters amount At Billing → Top Up Wallet, they choose an amount (e.g. $50) and select "Pay with Card (Stripe)".
-
Stripe Checkout Session created
BillingController::topupStripe()creates a Stripe Checkout Session via the Stripe API. The session hassuccess_urlandcancel_urlpointing back to KaiVox. -
Tenant completes payment on Stripe's hosted page They are redirected to Stripe's secure checkout. On success, Stripe redirects to
/billing/topup/stripe/success?session_id=.... -
KaiVox verifies and credits wallet
BillingController::stripeSuccess()retrieves the session from Stripe API, verifiespayment_status = paid, then credits the tenant's wallet and creates awallet_transactionsrecord.
Razorpay Flow
-
Tenant selects Razorpay and enters amount At Billing → Top Up Wallet, they choose an amount (in INR) and select "Pay with Razorpay".
-
Razorpay order created
BillingController::topupRazorpay()creates a Razorpay order via the Razorpay API. The order ID is returned to the frontend. -
Razorpay JS checkout modal opens The tenant completes payment in Razorpay's modal (UPI, net banking, card, etc.).
-
KaiVox verifies signature and credits wallet On payment success, Razorpay returns
razorpay_payment_id,razorpay_order_id, andrazorpay_signature. KaiVox verifies the HMAC signature usingRAZORPAY_SECRET, then credits the wallet.
Wallet System Architecture
| Table / Column | Purpose |
|---|---|
tenants.wallet_balance | Current prepaid balance (decimal, in USD or INR depending on plan currency) |
tenants.wallet_low_threshold | Balance below which the low_wallet automation trigger fires |
wallet_transactions | Every debit and credit — type (topup/call_charge/refund), amount, balance_before, balance_after, reference |
How Calls Deduct from Wallet
// Called at call hangup (VobizService + TwilioService):
BillingService::chargeForCall($tenant, $durationSeconds);
// Logic inside BillingService::chargeForCall():
1. Convert seconds to minutes (round up)
2. Check tenant's remaining monthly quota
3. If quota remaining → deduct from quota (free)
4. If quota exhausted → deduct from wallet at tenant's plan per-minute rate
5. If wallet insufficient → log failure, flag account
6. Record wallet_transaction entry
Subscription Plan Management
Plans are created and managed by the Super Admin at Super Admin → Subscription Plans. Each plan has:
- Name — Starter / Pro / Enterprise
- Monthly price — charged manually or via future Stripe subscription
- Monthly call quota — free minutes per billing cycle
- Features list — shown on pricing page
Tenants can upgrade or downgrade at Billing → Change Plan. The subscriptions table records the current plan, start date, and status.
Invoice / Billing History
Tenants can view their billing history at Billing → History. This shows all wallet top-ups, call charges, and phone number billing deductions from wallet_transactions and phone_number_billing.
Super Admin Billing Controls
Super Admins can at Super Admin → Tenants → [Tenant] → Billing:
- Manually adjust wallet balance (add/deduct with a reason note)
- View all wallet transactions for the tenant
- Override plan assignment
- See low-balance alerts (flagged tenants whose wallet is below threshold)
Troubleshooting Payments
| Problem | Cause | Fix |
|---|---|---|
| Stripe redirect fails | Wrong STRIPE_KEY or missing | Check key in Stripe Dashboard → Developers → API Keys |
| Stripe payment not credited | Success URL not reached or session not verified | Check Laravel logs for stripeSuccess errors |
| Razorpay signature mismatch | Wrong RAZORPAY_SECRET | Regenerate secret in Razorpay Dashboard → Settings → API Keys |
| Wallet not deducting for calls | BillingService not wired or quota still active | Check wallet_transactions table and monthly quota column on subscriptions |
| Test payments going through as live | Using live keys in dev | Use pk_test_ / sk_test_ for Stripe, rzp_test_ for Razorpay |