Loading...
Loading...
Implement Stripe Billing for subscriptions, recurring payments, invoicing, and usage-based pricing. Use when: (1) Creating subscription plans (flat, tiered, per-seat, usage-based), (2) Managing subscription lifecycle (trials, upgrades, downgrades, cancellations), (3) Generating and customizing invoices, (4) Implementing metered/usage-based billing, (5) Setting up customer portal for self-service, (6) Configuring dunning and revenue recovery, (7) Applying coupons and promotion codes. Triggers on: subscription, recurring billing, invoice, usage-based, metered billing, SaaS pricing, subscription plan, trial, dunning, proration, customer portal, coupon, promotion code, billing cycle.
npx skill4agent add zef-computers/drivers stripe-billing| Priority | Rule | Impact | Description |
|---|---|---|---|
| 1 | | HIGH | Create subscriptions via Checkout for built-in payment collection, SCA, and tax |
| 2 | | HIGH | Use |
| 3 | | HIGH | Expand |
| 4 | | HIGH | Always verify webhook signatures to prevent forged events |
| 5 | | HIGH | Sync state on every |
| 6 | | HIGH | Use |
| 7 | | HIGH | Design handlers for at-least-once delivery with event deduplication |
| 8 | | HIGH | Acknowledge webhooks immediately, process asynchronously |
| 9 | | HIGH | Use |
| 10 | | HIGH | Enable ML-powered Smart Retries for optimal payment recovery |
| 11 | | HIGH | Cancel at period end for better UX and win-back opportunity |
| 12 | | HIGH | Collect payment method during trial for higher conversion |
| 13 | | HIGH | Include idempotency keys with usage records to prevent double-counting |
| 14 | | HIGH | Flush usage buffers before period end to prevent revenue leakage |
| 15 | | HIGH | Explicitly list products/prices in portal configuration |
| 16 | | HIGH | Use |
| 17 | | MEDIUM | Preview upcoming invoice before applying subscription changes |
| 18 | | MEDIUM | Handle |
| 19 | | MEDIUM | Use Billing Meters over legacy usage records for new integrations |
| 20 | | MEDIUM | Use |
| 21 | | MEDIUM | Pause subscriptions instead of canceling for temporary stops |
| 22 | | MEDIUM | Escalate dunning communications over retry attempts |
| 23 | | MEDIUM | Deactivate old prices instead of deleting them |
What pricing model fits your product?
|
+-- Fixed monthly/annual fee?
| -> Flat-rate pricing (references/pricing-models.md)
|
+-- Per-seat / per-unit?
| -> Per-unit pricing (references/pricing-models.md)
|
+-- Volume tiers (price decreases with quantity)?
| -> Tiered pricing (references/pricing-models.md)
|
+-- Pay for what you use (API calls, storage)?
| -> Usage-based / metered (references/usage-based.md)
|
+-- Hybrid (base fee + usage)?
-> Multiple prices on one subscription (references/pricing-models.md)const product = await stripe.products.create({
name: 'Pro Plan',
description: 'Full access to all features',
});
const price = await stripe.prices.create({
product: product.id,
unit_amount: 2900, // $29/month
currency: 'usd',
recurring: { interval: 'month' },
lookup_key: 'pro_monthly',
});const session = await stripe.checkout.sessions.create({
customer: 'cus_xxx', // or let Checkout create one
line_items: [{ price: price.id, quantity: 1 }],
mode: 'subscription',
success_url: 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}',
cancel_url: 'https://example.com/cancel',
});const subscription = await stripe.subscriptions.create({
customer: 'cus_xxx',
items: [{ price: price.id }],
default_payment_method: 'pm_xxx',
payment_behavior: 'default_incomplete', // requires client confirmation
expand: ['latest_invoice.payment_intent'],
});
// Return subscription.latest_invoice.payment_intent.client_secret to frontendincomplete -> active -> past_due -> canceled
-> canceled (immediate)
-> paused
trialing -> active (payment succeeds)
-> incomplete (payment fails)
-> canceled (trial ends, no payment method)// One-time setup in Dashboard or API
const configuration = await stripe.billingPortal.configurations.create({
features: {
subscription_update: { enabled: true, products: [{ product: 'prod_xxx', prices: ['price_basic', 'price_pro'] }] },
subscription_cancel: { enabled: true, mode: 'at_period_end' },
payment_method_update: { enabled: true },
invoice_history: { enabled: true },
},
});
// Generate portal session per customer
const portalSession = await stripe.billingPortal.sessions.create({
customer: 'cus_xxx',
return_url: 'https://example.com/account',
});
// Redirect to portalSession.url| Event | Action |
|---|---|
| Provision access |
| Handle plan changes, cancellation scheduling, status transitions |
| Revoke access |
| Remind user (3 days before) |
| Confirm payment, extend access |
| Notify user, trigger dunning escalation |
| Preview next charge |
| Topic | Key Concept | Reference |
|---|---|---|
| Flat/tiered pricing | Products have multiple Prices; use | references/pricing-models.md |
| Subscription creation | Prefer Checkout; use | references/subscription-lifecycle.md |
| Usage billing | Billing Meters (modern) or Usage Records (legacy) | references/usage-based.md |
| Trials | | references/trials.md |
| Invoices | | references/invoices.md |
| Customer portal | Configure products explicitly; use deep links | references/customer-portal.md |
| Dunning | Smart Retries + escalating communications | references/dunning.md |
| Coupons | Coupons (internal) + Promotion Codes (customer-facing) | references/coupons.md |
| Proration | | references/proration.md |
| Schedules | Phase-based automation; max 10 phases | references/schedules.md |