Open laravelblock opened 2 years ago
@laravelblock sorry this course was created a while ago and I totally won't remember how it all works and all potential bugs. I'm planning to re-shoot a lot of courses in 2022, so maybe I will get to this one and debug it, but only in a few months, at best.
Quickly googled, maybe something in that direction? https://stackoverflow.com/questions/57689519/handlecardpayment-error-when-using-stripe
@LaravelDaily @laravelblock
When i submit form $('#payment-method').val(result.setupIntent.payment_method); $('#payment-form').submit();
then pay method return back()->with('error', $ex->getMessage());
A return_url
must be specified because this Payment Intent is configured to automatically accept the payment methods enabled in the Dashboard, some of which may require a full page redirect to succeed. If you do not want to accept redirect-based payment methods, set automatic_payment_methods[enabled]
to true
and automatic_payment_methods[allow_redirects]
to never
when creating Setup Intents and Payment Intents.
But i found solution for it Look at my pay method in controller
public function pay(Request $request)
{
$user = auth()->user();
$order_id = $request->order_id;
$paymentMethod = $request->payment_method;
$order = Order::whereUserId($user->id)->findOrFail($order_id);
$price = $order->price * 100;
try{
$user->createOrGetStripeCustomer();
$user->updateDefaultPaymentMethod($paymentMethod);
// Charge the customer
$response = $user->charge($price, $paymentMethod, [
'return_url' => route('success'), // Replace with the route to your payment completion page
]);
// Check the payment status
if ($response->status === 'succeeded') {
// Update order with payment date
$order->update(['paid_at' => now()]);
// Redirect to success URL
return redirect()->route('success');
} else {
// Handle other payment statuses if necessary
return back()->with('error', 'Payment failed. Please try again.');
}
}catch(Exception $ex){
return back()->with('error', $ex->getMessage());
}
}
Hey im getting this error when i submit the form
Invalid value for stripe.confirmCardPayment intent secret: value should be a PaymentIntent client secret. You specified: a SetupIntent client secret.