Skip to main content
Discuss your project
Blog

Laravel/

Nine Laravel Stripe subscription mistakes, and how to avoid each one

Nine mistakes that break Stripe subscriptions in Laravel apps using Cashier, from trusting the success page to duplicate webhooks, and how to avoid each.

Ajay Kumar

Ajay Kumar

Web Developer

A Laravel app that sells Stripe subscriptions usually works on launch day. The trouble shows up a month later, when the first renewals fail, a webhook arrives twice, or a customer upgrades mid-cycle and gets an invoice nobody expected.

This post lists nine mistakes behind that, with a fix for each. We built the list by reading Laravel Cashier's docs and source against Stripe's own documentation, for a common setup. That setup is Cashier 16, Stripe Checkout, a monthly and a yearly plan, and webhooks keeping the database current. It is not a client case study, and every section says where its claims come from.

In short

  • Stripe is the record of what a customer has paid for. Your Laravel database is a copy that webhooks keep current. Most of the mistakes below come from treating it the other way round.
  • The costly ones are access granted on the success page, a webhook secret missing in one environment, listeners that run twice, and failed renewals with no rule for what happens next.
  • Cashier 16.9.0 handles a lot, but its webhook controller does not deduplicate events, and it skips signature checks when STRIPE_WEBHOOK_SECRET is empty.
  • Our view is that you should run a renewal, a failed payment and a cancellation through Stripe test clocks before launch. That one habit catches most of this list.
A glass payment card on the left feeds a line through four glowing nodes across a glass browser window. The last node is green, and a branch drops to a red node and a shield.

Mistake 1: granting access on the success page

The success_url of a Checkout session is where the customer's browser lands. It is not proof of payment. The customer can close the tab before the redirect, the bank can ask for 3D Secure, or the first payment can fail after the session completes.

Cashier's docs say the same. Stripe and Cashier update subscription statuses through webhooks, so a subscription "might not yet be active when the customer returns to the application" (Cashier docs). If your success controller sets its own is_paid flag, that flag and Stripe will disagree sooner or later.

The fix is one place that decides access, driven by the subscription row the webhook writes. Keep the success page as a "we're confirming your payment" screen.

// app/Http/Middleware/EnsureSubscribed.php
public function handle(Request $request, Closure $next): Response
{
    if (! $request->user()?->subscribed('default')) {
        return redirect()->route('billing');
    }

    return $next($request);
}

Put that middleware on every paid route and nowhere else. If five controllers each check payment their own way, the fifth one will be wrong.

Mistake 2: a webhook endpoint that is not set up in every environment

Cashier registers /stripe/webhook for you. Three things have to be right on every server, and each one fails quietly.

The first is the signing secret. Cashier's webhook controller applies its signature middleware only when cashier.webhook.secret is set, which means STRIPE_WEBHOOK_SECRET must be in the .env file. Leave it empty on staging, or on a production server someone rebuilt, and that endpoint accepts unsigned requests. Stripe's own warning is that without verification an attacker can send fake events to "trigger actions like fulfilling orders, granting account access or modifying records" (Stripe webhooks).

The secret is also different for each endpoint, for test mode and live mode, and for every stripe listen session. Copying the value from one place to another is the usual way it goes stale.

The second is CSRF. Stripe cannot send a CSRF token, so the route must be excluded. On Laravel 13 that looks like this, per the docs.

// bootstrap/app.php
->withMiddleware(function (Middleware $middleware): void {
    $middleware->preventRequestForgery(except: [
        'stripe/*',
    ]);
})

On Laravel 11 and 12 the same exclusion goes through validateCsrfTokens(except: [...]).

The third is the event list. Cashier needs eight events, among them customer.subscription.created, customer.subscription.updated, customer.subscription.deleted, invoice.payment_succeeded and invoice.payment_action_required. Subscription Checkout in particular relies on customer.subscription.created to create the row in your database. This command creates an endpoint listening to all of them:

php artisan cashier:webhook --url "https://app.example.com/stripe/webhook"

Add one line to your deploy smoke test. Post an unsigned event with a made-up type to the webhook URL and read the status code.

curl -i -X POST https://app.example.com/stripe/webhook -d '{"type":"smoke.test"}'

A 403 means verification is on and CSRF is excluded. A 419 means CSRF is still blocking Stripe. A 200 means nobody is checking signatures. Send a type, because Cashier reads it before anything else, and an empty body returns a 500 that hides the answer.

Mistake 3: your own listeners run twice, or out of order

Cashier gives you the WebhookReceived event for anything it does not handle itself. Stripe is clear about what to expect from webhooks.

  • Endpoints "might occasionally receive the same event more than once", so you log the event IDs you have processed and skip repeats.
  • Stripe "doesn't guarantee the delivery of events in the order that they're generated", and created has one-second resolution, so it cannot sort events either.
  • Live mode retries failed deliveries for up to three days, with exponential backoff.

All three come from the Stripe webhooks documentation. Cashier does not add a guard of its own. Its controller dispatches WebhookReceived on every delivery, and the built-in handlers that guard against repeats do it by Stripe object ID, not by event ID. So a listener that sends a receipt, tops up credit or switches on a device runs again on every retry.

The fix is a table of processed event IDs with a unique key, checked in the same transaction as the work. The listener stays thin and hands the work to a queued job, so the endpoint answers quickly.

// migration
Schema::create('processed_stripe_events', function (Blueprint $table) {
    $table->string('stripe_event_id')->primary();
    $table->timestamp('processed_at')->useCurrent();
});
// app/Listeners/StripeEventListener.php
public function handle(WebhookReceived $event): void
{
    if ($event->payload['type'] === 'invoice.payment_succeeded') {
        HandlePaidInvoice::dispatch(
            $event->payload['id'],
            $event->payload['data']['object']['id'],
        );
    }
}
// app/Jobs/HandlePaidInvoice.php
public function handle(): void
{
    DB::transaction(function () {
        $first = DB::table('processed_stripe_events')
            ->insertOrIgnore(['stripe_event_id' => $this->eventId]);

        if (! $first) {
            return; // a repeat delivery
        }

        // Fetch the invoice again instead of trusting the old payload.
        $invoice = Cashier::stripe()->invoices->retrieve($this->invoiceId);

        // Credit the account, activate the device, and so on.
    });
}

If the work fails, the transaction rolls the marker back and the job can retry. The one limit is side effects outside the database. Send the email after the transaction commits, from its own job, or you can send it and still roll back.

Fetching the invoice again also covers ordering. If the invoice event shows up before the subscription event, Stripe's advice is to retrieve the objects from the API instead of waiting.

Mistake 4: the webhook's API version drifts from your code

The shape of a webhook payload depends on the API version of the endpoint, not on the code you wrote. Stripe says the version set when the event occurs dictates its structure, and an event cannot be changed after it is created.

That matters because Stripe has changed what a subscription looks like. The 2025-03-31 basil release removed current_period_start and current_period_end from the subscription and moved them onto each subscription item (Stripe changelog). A listener that reads data.object.current_period_end gets nothing from an endpoint on a newer version, and it works fine on one pinned to an older version. That is how one environment passes and another fails.

Cashier 16 defaults to API version 2025-07-30.basil, and its upgrade guide recommends locking your Stripe version after you upgrade, to avoid drift (upgrade guide). To follow that advice:

  • Read the API version of each webhook endpoint in Stripe's Workbench, in test and live mode.
  • Create endpoints with php artisan cashier:webhook --api-version="2025-07-30.basil" so the version is chosen, not inherited. Without the flag it uses the version of stripe/stripe-php.
  • In your own code, read billing periods from items.data, not from the subscription.

Mistake 5: plan changes that surprise the customer

By default Stripe prorates when a subscription moves between prices. A mid-cycle upgrade produces a credit and a charge, and the customer sees an odd number on the invoice. Neither behaviour is wrong. Not choosing one is.

Cashier gives you three tools, and the docs spell out how they combine.

  • swap() changes the price and bills the difference on the next invoice.
  • swapAndInvoice() invoices straight away.
  • noProrate() skips proration, but it has no effect before swapAndInvoice(), because an invoice is always issued.

Decide per change which one applies. An upgrade, a downgrade and a seat change often deserve different rules. Then show the customer the number before they confirm, using previewInvoice().

$subscription = $user->subscription('default');

$invoice = $subscription->previewInvoice('price_yearly');
// Show $invoice->total() on the confirmation screen.

$subscription->swapAndInvoice('price_yearly');

Two more details from the docs catch people. A subscription in the incomplete state cannot be changed until its payment is confirmed, so swap and updateQuantity throw. And Stripe Checkout ignores anchorBillingCycleOn, proration behaviour and payment behaviour, so set those rules on changes you make after Checkout, not on the Checkout session.

Mistake 6: hard-coded prices and double subscriptions

Price IDs belong in config, read from the environment. Test mode and live mode have different IDs, and a price's amount cannot be edited once it exists. A price change means a new price and a new ID, and that is a config change, not a code change.

One more Cashier detail. checkoutCharge() creates a new product and price in your Stripe dashboard on every call, so the docs recommend creating products up front and using checkout() with a price ID.

Double subscriptions are the other half. A double click, a second browser tab or a retried request can each create a second subscription for the same customer, and Stripe will not stop it. Two layers help.

  1. Before you start Checkout, check $user->subscribed('default'). Send existing subscribers to the billing portal with redirectToBillingPortal() instead.
  2. When your own code creates objects through the Stripe SDK, send an idempotency key.
Cashier::stripe()->subscriptions->create($params, [
    'idempotency_key' => $attempt->uuid,
]);

Generate the key when the form is rendered, not when the request arrives, so a double submit carries the same key twice. Stripe's idempotent requests page covers the rest. For API v1, keys can be pruned after 24 hours, a reused key with different parameters returns an error, and GET and DELETE requests do not need one.

Mistake 7: failed renewals with no rule behind them

A failed renewal is normal. Cards expire. What matters is what the app does while Stripe retries.

Cashier treats past_due and incomplete subscriptions as not active, unless you call Cashier::keepPastDueSubscriptionsActive() or Cashier::keepIncompleteSubscriptionsActive() in a service provider (Cashier docs). That is a product decision, not a technical one. Cut access at the first failed charge and paying customers lose the app on a Monday morning. Never cut it and someone gets a free quarter.

Stripe's side of the decision is the retry setting. New accounts get Smart Retries by default, with up to 8 retries over 2 weeks. When recovery fails, the subscription is cancelled, marked unpaid, left past_due or paused, depending on your setting (Stripe retries). Cashier's webhook handlers cancel the local subscription when Stripe does, so that setting is the one that ends access.

Some declines cannot be retried at all. After a hard decline such as a lost or stolen card, retries only run once the customer adds a new payment method. Waiting does nothing for those customers.

Our rule of thumb:

  • keep access during the retry window,
  • show an "update your card" banner while $subscription->pastDue() is true,
  • link the banner to redirectToBillingPortal(),
  • remove access when the subscription is cancelled or unpaid.

Strong Customer Authentication adds one more case. For customers in the UK and EEA, a renewal can ask for 3D Secure even when the first payment did not. Cashier can email the customer a confirmation link, but it is off by default. Switch it on with CASHIER_PAYMENT_NOTIFICATION=Laravel\Cashier\Notifications\ConfirmPayment, make sure the invoice.payment_action_required event is enabled in Stripe, and check that your billable model uses Laravel's Notifiable trait (Cashier docs).

Mistake 8: turning on tax halfway

Stripe Tax is a one-line setup in Cashier.

// AppServiceProvider::boot()
Cashier::calculateTaxes();

Three things go wrong around it. The first is that Stripe needs the customer's name, address and tax ID synced to the customer record, or it has nothing to calculate from. The second is mixing methods. If you enable calculateTaxes(), do not also apply taxRates() or priceTaxRates() in your own code. Pick one method and use it everywhere. The third is timing. Cashier's docs say automatic tax applies to "any new subscriptions and any one-off invoices" after you enable it, so subscriptions that already exist are not changed.

Whether you need to collect tax at all, and where, is a question for an accountant, not for a developer.

Mistake 9: never testing time

Renewals, trial endings and failed payments happen weeks after signup, so clicking through the app never tests them. Stripe's test clocks move a sandbox customer forward in time, so a renewal, a failure and the retries all happen in minutes. A clock can advance up to two subscription intervals at a time, and the Dashboard disables the simulation for a customer with more than three subscriptions.

Pair the clock with stripe listen forwarding to your local app, so the webhooks actually run.

stripe listen --forward-to localhost:8000/stripe/webhook

It prints a signing secret for that session. Put it in your local .env as STRIPE_WEBHOOK_SECRET.

Two sandbox cards cover the awkward cases. 4000000000000341 attaches fine and then fails on the first charge, which is the right test for a failed payment after a trial. 4000002760003184 triggers 3D Secure. Cashier's own advice is to let tests hit the real Stripe test API instead of mocking it, because mocks mean re-implementing Cashier's behaviour.

Run these before launch.

  • A trial that ends and renews successfully.
  • A renewal that fails, then succeeds after the customer updates their card.
  • A renewal that fails until the retries run out.
  • A cancellation, and the day the grace period ends.
  • An upgrade mid-cycle, with the invoice amount checked against previewInvoice().
  • A renewal that asks for 3D Secure.

Versions worth knowing in 2026

Cashier 16.9.0 is the latest release as of 13 Oct 2026 (releases). Its composer.json supports Laravel 10 to 13, PHP 8.1 or later, and stripe/stripe-php 17.4 to 21.

The jump from Cashier 15 is not a version bump to ignore. The upgrade guide moves the default Stripe API version to 2025-07-30.basil, changes the return type of reportUsage() and reportUsageFor() from Stripe\UsageRecord to Stripe\V2\Billing\MeterEvent, and adds meter_event_name and meter_id columns to subscription_items. Publish the migrations with php artisan vendor:publish --tag="cashier-migrations" and run them. If you bill per unit, test this on staging first. If the app is on an older Laravel version, check our Laravel and PHP version support dates before you touch Cashier.

When we would not build this in Laravel

If you sell one or two plans and nothing in the app depends on billing logic, Stripe Checkout with Stripe's hosted customer portal may be enough, and it removes most of the mistakes above. If your pricing is mostly usage-based and changes often, a dedicated billing platform on top of Stripe can fit better than custom Cashier code. We would want to see the pricing model first.

And if your current setup works and the numbers reconcile, do not rewrite it to match this list. Add the duplicate-event guard, check the webhook secret on every server, and run one test clock. Leave the rest alone.

What to do next

If your Laravel app takes subscription payments and something does not add up, we can review the Stripe setup, the webhooks and the access rules, and tell you what we would fix first. Start on our integrations page. If the developer who built the billing has left, our Laravel app takeover review covers billing as part of the handover.

Sources