Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lat4732's avatar
Level 12

Cashier (Stripe) double creating a subscription

Hey!

I have Stripe subscriptions in my project and I've faced the following problem. Whenever a subscription is created, stripe is duplicating it. Here's my code for subscription creation:

$stripe = StripeProducts::where('plan_id', $plan->id)->where('billing_cycle_months', $plan->cycle)->first();

$user = Cashier::findBillable(Auth::user()->stripe_id);
$user->newSubscription($plan->name, $stripe->stripe_price_id)
     ->create($request->paymentMethod);

Why might this cause duplicating the subscription? I've tested a lot and these are the only lines that exists for creating a subscription in the whole app. I really need some help!

Note: I am sending an AJAX call to this code if it matters

setTimeout(function() {
    $.ajax({
        url: '{{ route("stripe.pay.update") }}',
        type: 'POST',
        data: {
            status: "succeeded"
        },
        success: function(response) {              
            if(response.status == 1) {
                setTimeout(function() {
                    location.href = "{{ route('dashboard') }}";
                }, 2500);
            } else {

            }
        }
    });
}, 2500);
0 likes
7 replies
lat4732's avatar
Level 12

I've added a check if the user is subscribed:

if($user->subscribed($plan->name) === false) {
     $user->newSubscription($plan->name, $stripe->stripe_price_id)
          ->create($request->paymentMethod);
}

but still the same duplicating.

furqanDev's avatar

Does your application support subscription to multiple products at the same time ?

lat4732's avatar
Level 12

@furqanDev Because there are visual processes - setting up your account..., setting up dashboard... etc ...

lat4732's avatar
Level 12

@furqandev Your answer actually contains the answer - It's because of the timeout (Its probably because the timeout is somehow sending the request twice). Anyways, I removed the timeout and it is working properly now. Thanks for the tip ;)

Please or to participate in this conversation.