you can disable the button until you get a response back from first call.
Jun 25, 2019
2
Level 1
Laravel Cashier prevent multiple same subscriptions.
Hi,
I have POST route in my API for buying premium account subscription using Stripe/Cashier.
try {
if($request->user()->subscribed('premium') || is_null($request->stripeToken))
return response()->json([
'message' => __('app.went_wrong')
], 404);
$request->user()->newSubscription('premium', 'XXXXXX')->create($request->stripeToken, [
'name' => $request->user()->first_name.' '.$request->user()->last_name,
]);
return response()->json([
'message' => __('app.premium_bought')
], 200);
} catch (Exception $e) {
return response()->json([
'message' => __('app.went_wrong')
], 404);
}
If i buy premium account and wait for few second and try to buy it again with same user authenticated i will get message that something went wrong and i have checked that with this if statement
if($request->user()->subscribed('premium'))
But if i call this url two times in a row it create two subscriptions because this if statement return false because first request didn't finish yet and user is not premium yet.
How can i solve this problem?
Please or to participate in this conversation.