// client scope demo
Usage metering, subscriptions & PAYG
Walkthrough of how we align per-job metering, dual-channel reporting (Stripe + RapidAPI), subscription billing with proration and metered overage, API key deactivation after ultimate payment failure, and pay-as-you-go with card on file. Live actions use your existing Stripe test products and prices.
1. Migrate metering: page → per job (4 APIs)
Normalize each successful operation into a single job event before it hits billing. Whether the call is synchronous or async, the usage reporter emits one unit per completed job per API surface.
Before
Usage tied to “pages processed” (or similar). One billable unit does not map cleanly to work done across heterogeneous APIs.
After
Each completed job is one usage event. Same semantics across 4 APIs — easier caps, overage, and forecasting.
2. Usage reporting: Stripe + RapidAPI
Direct subscribers are billed in Stripe; marketplace users are billed via RapidAPI. Internally you still store job counts per account so finance and product see one consistent metric.
- Customer + Subscription in Stripe
- Usage: Billing Meters / usage records → invoice line items
- Webhooks drive entitlements & API key state
- Billing events from RapidAPI (plans / quotas)
- Map marketplace identity → internal account + usage ledger
- Same job-based unit internally; reconcile channels in reporting
3. Subscriptions: proration & metered overage
Plan changes mid-cycle use Stripe's proration behavior (configurable per change). A metered price on the same subscription captures overage beyond included jobs.
Upgrades, downgrades, and monthly ↔ annual switches use Stripe's proration settings on the subscription; overage lines attach the metered price you configure.
STRIPE_METERED_OVERAGE_PRICE_ID to show your overage price here.4. When payments ultimately fail → deactivate API keys
Your webhook worker listens for terminal failure signals (e.g. repeated invoice.payment_failed, subscription past_due / unpaid). After business rules say “give up,” revoke or flag API keys and notify the customer.
invoice.payment_failed / unpaid→Deactivate API keysSimulate webhook (demo log)
5. Pay-as-you-go: card on file & auto-recharge
New API: customers keep a card on file; you decrement an internal balance per job and trigger an off-session PaymentIntent when balance drops below a threshold (auto-recharge). The button below runs a one-time Checkout top-up that saves the card for that model.
Demo below uses a one-time Checkout top-up with setup_future_usage so the saved card can power production-style auto-recharge via PaymentIntents.
Live demo (test mode)
Use Payment Links for a frictionless share, or programmatic Checkout (same products). Customer Portal returns here after managing the subscription.
Subscription (Pro / base plan)
Opens Stripe Checkout with STRIPE_PRO_PRICE_ID.
Optional: set NEXT_PUBLIC_STRIPE_PAYMENT_LINK_SUBSCRIPTION for a hosted link from the Dashboard.
PAYG top-up (one-time)
Saves card with setup_future_usage for auto-recharge patterns.
Configure STRIPE_PAYG_TOPUP_PRICE_ID to enable API checkout for PAYG.
Optional: NEXT_PUBLIC_STRIPE_PAYMENT_LINK_PAYG.
Webhook log (real + simulated)
No events yet. Run checkout or simulate failures above.
Full Connect split-payout walkthrough: Stripe Connect demo →
Next step: production cutover
We wire meters to Stripe Billing, align RapidAPI reporting, tune proration and dunning, and enforce API key lifecycle from subscription state.
Book a call