Skip to content

Expert Answers to Your Magento, Shopify & Shopware Questions

Vendor-neutral, engineer-written explanations. Clear definitions first, then practical steps with real examples — no fluff.

Stagebit builds and maintains stores on Magento, Adobe Commerce, Shopify, Shopware, and Laravel, and this library holds the questions our own engineers get asked most often on each platform.

How do I keep Laravel billing and entitlements in sync with Stripe?

SB
Written by Stagebit Engineering Team
Updated November 2026 9 min read Verified by engineers

Laravel billing and entitlements stay aligned when your app calculates access from the billing provider’s record. They drift when access lives as a second fact that your code updates by hand. Laravel Cashier already mirrors Stripe subscription status into your database through webhooks. Your job is to apply your access rules in one place and to repair the mirror when a webhook never arrives or arrives late. The examples target Laravel 13 and Cashier 16.x, and the same approach carries over to other billing providers.

Quick answer

Treat Stripe as the source of truth for billing facts, and let Laravel apply your access rules through one check. Simple apps can call Cashier’s subscribed method directly, while complex apps can derive a rebuildable entitlements table. Verify webhook signatures, return a 2xx quickly, and do the real work in a queued job that re-reads the subscription from Stripe. Add a scheduled reconciliation job to catch events that arrive out of order or never arrive.

Why a Laravel Cashier subscription ends up out of sync with Stripe

A Laravel Cashier subscription out of sync with Stripe usually traces back to a short list of causes. Stripe’s webhook documentation says Stripe does not guarantee delivery order, and that an endpoint can receive the same event more than once.

  • Webhook events arrive late, twice, or out of order.
  • The customer returns from Stripe Checkout before a webhook has activated the subscription.
  • Several code paths write access flags, and only some of them clear those flags.
  • An endpoint stays down longer than Stripe’s retry window, which Stripe’s documentation currently sets at up to three days in live mode.

Cashier’s documentation covers the checkout case. A subscription may not be active when the customer lands back in your app, so show a pending state.

How to keep Laravel billing and entitlements in sync

Steps 1, 2 and 6 describe general architecture. The other steps use Stripe and Cashier 16.x details.

1. Separate billing facts from access rules

Billing state is what Stripe manages: whether a subscription is trialing, active, past due, canceled or unpaid, which prices it holds, and when it ends. An entitlement is what the customer can do in your app, such as use the API or add team members. Stripe is the source of truth for the first. Laravel decides the second.

Stripe does not know about manual grants, complimentary features, internal restrictions or access that comes from another source. Your access rules combine Stripe’s billing facts with those inputs, so the final decision belongs in your app.

Cashier’s subscriptions table mirrors the billing side, and the mirrored status sits in the stripe_status column. Let webhooks and Cashier’s own methods write it. Do not add a separate writable column such as has_pro_access that you update by hand. Every independently edited copy is another place to drift.

2. Choose how your app applies access rules

Two approaches are valid. Both route every decision through one middleware, policy or service, and both enforce it on the server. Hiding a premium button is not enough, so apply the check in policies, middleware and API routes.

ApproachUse it whenWhat to watch
Cashier checks directly: subscribed, subscribedToPrice, subscribedToProductYou sell one or a few plans, access follows the plan, and you have no add-ons or manual grantsAccess depends on Cashier’s local mirror staying correct, so reconcile it (step 7)
A derived entitlements tableYou have add-ons, seat or feature limits, manual grants, or several sources of accessThe table becomes a second source of truth if anyone edits it directly, so rebuild it from Stripe and your rules (step 6)

Start with the first approach and move to the second only when a requirement forces it. The table adds a rebuild path that you then have to maintain.

3. Write down your access policy for every status

Stripe’s subscription webhook guidance says to notify the customer when a subscription becomes past_due and to revoke access when it becomes canceled or unpaid. Cashier’s defaults cover the common cases, and your business rules decide the rest.

Stripe statusCashier subscribed by defaultDecision for you
trialingYesWhich features a trial includes, and what happens when it ends
activeYesGrant the features of the current price
incompleteNo, until payment is confirmedSend the customer to payment confirmation and show a pending state
past_dueNo, unless you call keepPastDueSubscriptionsActiveGrace period, limited features or suspension, per your recovery policy
Canceled, in grace periodYes, until ends_atKeep paid features until the period the customer paid for ends
Canceled, endedNoRemove subscription-based entitlements
unpaidNoRevoke access, as Stripe advises
incomplete_expiredNoTreat as never activated
pausedCan be yes, because Cashier does not exclude itDefine and test your own policy

The paused row needs care. In the Cashier 16.x source, active() excludes unpaid and incomplete_expired, and it excludes incomplete and past_due by default. It does not explicitly exclude paused, so a paused subscription can still pass subscribed. Stripe stops creating invoices while a subscription is paused, so keeping paid features on means access with no billing. Cashier’s onTrial, onGracePeriod, pastDue and ended methods help you build the rest of the policy. Check these defaults against your installed version.

4. Register webhooks and verify signatures

Cashier registers a webhook route at /stripe/webhook and verifies signatures when you define STRIPE_WEBHOOK_SECRET. Run php artisan cashier:webhook to create a Stripe webhook for Cashier’s default event list. That list includes invoice.payment_succeeded but not every event your app might want. In the 16.x source, the command reads the cashier.webhook.events config value when you set one. Exclude stripe/* from CSRF protection, or Laravel rejects Stripe’s requests.

5. Protect against duplicate and out-of-order events

These are two different problems. A duplicate is the same event delivered again. An out-of-order event is a different event that arrives after a newer one. Recording event IDs solves only the first.

For duplicates, store each Stripe event ID with a unique database constraint and skip an event whose ID already exists. Make the queued job safe to retry, so a failed attempt can run again without double effects.

For ordering, start from what Cashier does. Its handler writes the status, price and quantity from each customer.subscription.updated payload to its tables, and it has no check on event order. A late, older event can therefore overwrite newer data. The defence is to re-read the latest subscription from Stripe with asStripeSubscription() and derive access from that object, not from the payload or the local mirror.

Cashier dispatches WebhookReceived as soon as an event arrives, before its own handler runs. It dispatches WebhookHandled after its handler finishes, and only for event types Cashier handles. Listen to WebhookHandled for customer.subscription.* events, so the local rows are updated before your job runs. Use WebhookReceived for event types Cashier does not handle, such as refunds and disputes.

Flow from a Stripe webhook through Cashier and a queued job that re-reads Stripe and rebuilds entitlements
use App\Jobs\RecomputeEntitlements;
use Laravel\Cashier\Events\WebhookHandled;

class StripeEventListener
{
    public function handle(WebhookHandled $event): void
    {
        if (! str_starts_with($event->payload['type'], 'customer.subscription.')) {
            return;
        }

        RecomputeEntitlements::dispatch(
            $event->payload['data']['object']['id'],
            $event->payload['id'],
        );
    }
}

Inside the queued job’s handle method, fetch the subscription from Stripe first, then open the transaction. That keeps the network call outside the transaction. The job receives the Stripe subscription ID and the event ID from the listener.

public function handle(): void
{
    $subscription = Subscription::where('stripe_id', $this->stripeSubscriptionId)->first();

    if (! $subscription) {
        return;
    }

    $stripe = $subscription->asStripeSubscription();

    DB::transaction(function () use ($subscription, $stripe) {
        $claimed = DB::table('processed_stripe_events')->insertOrIgnore([
            'event_id' => $this->stripeEventId,
            'processed_at' => now(),
        ]);

        if ($claimed === 0) {
            return;
        }

        app(EntitlementRebuilder::class)->rebuild($subscription->owner, $stripe);
    });
}

EntitlementRebuilder and the processed_stripe_events table are yours to write. The unique constraint belongs on event_id. If the rebuild throws, the transaction rolls back the event ID too, so a retry is not skipped.

The syncStripeStatus() method does not solve ordering on its own. It refreshes only the stripe_status column, and it does not sync prices, quantities, subscription items or end dates. Cashier has no documented method that does. If you gate access with subscribed and related methods, the reconciliation command in step 7 has to compare those fields with Stripe and correct them. That repair writes to Cashier’s tables, so keep it in one tested command and log every change.

If you also want invoice.paid, register it in Stripe yourself and handle it in your own listener, because it is not in Cashier’s default list. Stripe’s guidance is to retrieve the subscription and confirm its status is active before extending access, because a paid invoice does not always make a subscription active. Cashier’s own invoice.payment_succeeded handler does not change subscription status. Stripe also advises returning a 2xx before any complex logic and processing events through an asynchronous queue.

6. If you use an entitlements table, make it rebuildable

A per-feature table helps when access depends on plan, add-ons or manual grants. It also creates the second copy that step 1 warns about, so define it as derived data and never as an independent source of truth.

  • user_id, or the account or tenant ID that owns the plan. Multi-tenant apps should key entitlements to the tenant, not the user.
  • feature_key, which names the permitted feature.
  • source_subscription_id, which names the Stripe subscription that grants it.
  • starts_at and ends_at, which define the access period.
  • status, which records whether the entitlement is enabled.

Rebuild the Stripe-derived rows from one function. It reads the Stripe subscription’s status, price IDs, quantities and cancellation fields, then applies a config map from Stripe price ID to feature keys. Set ends_at from the subscription’s end date, so access still stops on time if the final webhook never arrives. Run it in a database transaction, and call it from both the queued job and the reconciliation command.

Never edit the Stripe-derived rows by hand. Store manual grants as rows with their own source value, and let the rebuild leave those rows alone.

Stripe also offers its own Entitlements feature, which sends an entitlements.active_entitlement_summary.updated event when a customer’s active entitlements change. This page covers the app-owned approach, so check Stripe’s documentation if you want Stripe to hold the feature list.

class EntitlementService
{
    public function allows(User $user, string $feature): bool
    {
        return $user->entitlements()
            ->where('feature_key', $feature)
            ->where('status', 'active')
            ->where(fn ($q) => $q->whereNull('starts_at')
                ->orWhere('starts_at', '<=', now()))
            ->where(fn ($q) => $q->whereNull('ends_at')
                ->orWhere('ends_at', '>', now()))
            ->exists();
    }
}

7. Add a scheduled reconciliation job

Reconciliation is the primary recovery mechanism, because webhooks can arrive late, arrive twice, or fail to arrive. Schedule an Artisan command that loops over local subscriptions in chunks and fetches each one from Stripe with asStripeSubscription(). A nightly run is a reasonable starting point. Tune it to how costly a wrong state is for your product.

use Laravel\Cashier\Subscription;

Subscription::query()->chunkById(200, function ($subscriptions) {
    foreach ($subscriptions as $subscription) {
        $stripe = $subscription->asStripeSubscription();

        $status = $stripe->status;
        $cancelAtPeriodEnd = (bool) $stripe->cancel_at_period_end;
        $cancelAt = $stripe->cancel_at ?? $stripe->canceled_at;

        $items = collect($stripe->items->data)->mapWithKeys(
            fn ($item) => [$item->price->id => $item->quantity]
        );

        // Compare these values with the local row and the entitlements,
        // log any difference, then rebuild.
    }
});

Compare status, price IDs and quantities, the cancellation fields, and the trial end. For a subscription set to cancel at period end, the access end date comes from the subscription items’ current period end. Cashier’s own currentPeriodEnd() method reads it from Stripe. Also flag entitlements that stayed enabled after their end date, and active subscriptions that have no entitlements. Rebuild both, and make the command safe to run twice.

Log every correction. A steady stream of fixes means a webhook path is broken, and the log shows which one. Stripe’s documentation currently allows resending failed events from the Dashboard within 15 days of creation, or with the Stripe CLI within 30 days. Treat those limits as something that can change, and do not rely on resending as your recovery plan.

The trade-off is cost. Each pass spends Stripe API calls, so queue the work, chunk it, and watch your rate limits.

8. Test the failure cases

Replay the same event twice, apply two subscription updates in reverse order, and simulate a failed renewal. The Stripe CLI can forward events to a local endpoint and trigger test events. After each case, run the reconciliation command and assert that local access matches Stripe’s current subscription.

Example: a customer upgrades and then cancels

  1. The customer upgrades from Basic to Premium, and Stripe sends customer.subscription.updated.
  2. Laravel verifies the signature, and Cashier updates the stored price.
  3. Cashier’s handler finishes, and WebhookHandled queues the recompute job.
  4. The job re-reads the subscription from Stripe and rebuilds the entitlements from the Premium price.
  5. Later, the customer cancels at the end of the billing period. Cashier sets ends_at, and subscribed stays true through the grace period.
  6. When the period ends, Stripe sends customer.subscription.deleted, and the job removes the Premium entitlements.

The customer keeps the period they paid for, and no handler needed to know the order of events.

Putting it together

Stripe owns the billing facts, and Laravel owns the access rules. Route every decision through one check, make queued jobs re-read Stripe instead of trusting a payload, and let a scheduled job repair whatever the webhooks missed. Event IDs stop duplicates, and re-reading Stripe handles ordering. For more on how we approach Laravel work like this, see Stagebit’s Laravel development services.

Was this answer helpful?

Your feedback helps us improve our answers.

Still need help?

Billing and access out of sync in your Laravel app?

If you're weighing how to keep Cashier and your access rules in step, we're happy to walk through what you're seeing and what your options are.

Talk to Laravel Experts