Skip to main content

Laravel Cashier Billing Implementation

Implement subscription billing with Laravel Cashier including plans, trials, metered billing, invoices, payment methods, and webhook handling.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
Implement a complete subscription billing system using Laravel Cashier (Stripe) for a developer API platform with usage-based pricing with 3 (Starter, Pro, Enterprise) subscription plans. The application serves 2,500 customers with flat monthly fee plus metered API usage overage. Use Laravel 11. Build it: 1) Install and configure Cashier: add the Billable trait to the Team (not User — billing is per organization) model, run the Cashier migrations, configure the Stripe/Paddle credentials in services.php, and set up the webhook endpoint at /stripe/webhook. Create the 3 (Starter, Pro, Enterprise) products and prices in Stripe matching: Starter: $29/mo (10K API calls), Pro: $99/mo (100K calls), Enterprise: $299/mo (unlimited). 2) Build the subscription flow: create a SubscriptionController with methods for: showing the pricing page with plan comparison, initiating checkout with Stripe Checkout (hosted payment page), handling successful subscription creation, and redirecting to the billing portal. Implement a 14-day trial that does not require a payment method upfront (yes, collect payment method at trial end). 3) Implement plan management: build upgrade/downgrade logic using swap() with proration (always_invoice for upgrades, create_prorations for downgrades), handle the grace period when downgrading to prevent immediate feature loss, implement add-on subscriptions for additional team seats ($10/seat/mo) and premium support ($49/mo), and create a middleware that checks subscription status and plan tier for feature gating. 4) Set up metered billing for API calls beyond plan allowance at $0.001 per call: report usage with reportUsage() at hourly via a scheduled job, display current usage and projected cost to the user, implement usage caps that throttle to 10 req/min and show upgrade prompt when exceeded, and create a usage tracking service that aggregates metrics from API gateway logs stored in Redis. 5) Handle webhooks robustly: create a WebhookController that processes checkout.session.completed, invoice.paid, invoice.payment_failed, customer.subscription.updated, customer.subscription.deleted. For each event: validate the signature, implement idempotency (skip if already processed), update local database state, trigger notifications, and log the event. Handle the critical failure case: payment_intent.payment_failed — implement the dunning sequence (day 1: retry + email, day 3: second retry + warning, day 7: final notice, day 14: cancel subscription). 6) Build the billing dashboard for customers: display current plan and status, next billing date and amount, payment method management (add, update, set default), invoice history with PDF download, and usage meter visualization. Style with Blade with Tailwind CSS. 7) Create admin billing management: build a Filament resource or admin page showing: MRR calculation, subscription analytics (new, churned, upgraded, downgraded this month), failed payment queue, and manual subscription adjustment tools (extend trial, apply credit, force cancel).

What this prompt does

This prompt makes the AI implement a complete subscription-billing system with Laravel Cashier on [payment_provider], for a [app_description] with [plan_count] plans serving [customer_count] customers on Laravel [laravel_version]. It adds the Billable trait to [billable_model], configures credentials, sets up the webhook at [webhook_route], and builds the subscription flow with [checkout_method] and a [trial_duration]-day trial. Billing is unforgiving, so the prompt front-loads the pieces that quietly lose revenue.

The structure works because it covers the full billing surface. Plan management uses swap() with [proration_behavior], grace periods, and add-ons for [addon_features]; metered billing reports [metered_features] at [usage_reporting_frequency] with caps; webhook handling for [webhook_events] is idempotent and signature-validated, including the [dunning_sequence] on failed payments; a customer billing dashboard manages payment methods and invoices; and admin tooling surfaces MRR, churn, and the failed-payment queue. The [trial_without_payment] setting decides whether you collect a card up front or at trial end, and the [cap_behavior] controls what happens when metered usage exceeds the plan allowance. Because billing is unforgiving, the prompt insists on reconciling local subscription state against [payment_provider] rather than trusting the database alone, and styles the customer-facing pages with [ui_framework] so the billing dashboard matches the rest of your product.

When to use it

  • You are building SaaS subscription billing and cannot afford to get it wrong
  • You need trials, upgrades, downgrades with proration, and add-on subscriptions
  • You have usage-based metered billing on top of a flat plan fee
  • You need idempotent, signature-validated webhook handling
  • You want a dunning sequence that retries and escalates failed payments
  • You need admin billing views for MRR, churn, and failed payments

Example output

The AI returns Cashier setup on [billable_model], products and prices matching [plan_details], a SubscriptionController driving [checkout_method] and a [trial_duration]-day trial, upgrade/downgrade logic with [proration_behavior], metered billing reporting [metered_features] at [usage_reporting_frequency], a WebhookController handling [webhook_events] with idempotency and signature validation plus the [dunning_sequence], a customer billing dashboard styled with [ui_framework], and admin tooling for MRR, churn analytics, and the failed-payment queue.

Pro tips

  • Make webhook handling idempotent — skip already-processed events so a duplicate delivery never double-charges or double-cancels
  • Always validate the webhook signature before trusting the payload; unsigned events are an attack surface
  • Implement the full [dunning_sequence] (retry, warn, final notice, cancel); silent payment failures are pure lost revenue
  • Reconcile local subscription state against [payment_provider] rather than trusting your database alone
  • Set [proration_behavior] intentionally per direction — always_invoice on upgrades, prorations on downgrades, behave differently
  • Use the real [billable_model] (often Team, not User) so billing maps to the organization that actually pays
  • Decide [trial_without_payment] deliberately; collecting a card at trial end lifts signups but raises involuntary churn at conversion
  • Build the admin failed-payment queue early so you can intervene on recoverable accounts before the [dunning_sequence] cancels them

Frequently Asked Questions

Should billing be attached to the User or the Team model?
It depends on `[billable_model]`; the default uses Team because billing is usually per organization, not per individual user. Putting the Billable trait on the wrong model means subscriptions do not map to whoever actually pays the invoice.
How does the prompt prevent duplicate webhook processing?
The WebhookController implements idempotency by skipping events it has already processed, and validates the signature before acting. This matters because providers can deliver the same webhook more than once, and double-processing could double-charge or wrongly cancel a subscription.
What happens when a payment fails?
The prompt handles `invoice.payment_failed` with a `[dunning_sequence]` that retries, sends escalating warnings, and finally cancels the subscription after the configured window. A proper dunning flow is where many setups quietly lose recoverable revenue.
Does it support usage-based metered billing?
Yes. It reports `[metered_features]` usage with reportUsage() at `[usage_reporting_frequency]`, shows current usage and projected cost, and applies caps via `[cap_behavior]` when limits are exceeded. Usage data is aggregated from `[usage_source]`.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Laravel & PHP Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support