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.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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);
@Laralex Why did you add timeout there ?
Please or to participate in this conversation.