I am starting to create an API with Stripe for a web-app that offers memberships.
I cannot use Cashier because the web-app's server also serves an iOS app that has in-app purchases subscriptions and the entire system is already in place.
The issue is that when I fetch the user's card information and create the Customer on Stripe, that customer still gets created even when I use a test card that fails for any reason.
On Stripe's end, it does indicate that the charge failed and the payment is incomplete, but I would rather catch that error and return to the user asking them to fix their mistake before any information is actually saved on Stripe or on our server (which is what usually happens).
On the course here "How to Accept Payments" Jeff Way goes through catching such error but it looks like now Stripe is not throwing these errors anymore and lets the user through regardless.
Here is my controller that expects to catch the error but does not:
public function purchase(Request $request)
{
Stripe::setApiKey(config('services.stripe.secret'));
try {
$customer = Customer::create([
'description' => auth()->user()->full_name,
'email' => auth()->user()->email,
'source' => $request->stripeToken,
'plan' => 'my-plan'
]);
} catch (\Stripe\Exception\CardException $e) {
// This is what I want to happen but never does.
return back()->with('error', $e->getError()->message);
}
return $customer;
}
I expect the catch block to trigger but it never does. Any ideas? Did Stripe change the way they handle such issues, or am I missing something?