The error message "The payment attempt failed because additional action is required before it can be completed" indicates that the payment requires 3D Secure authentication. To handle this, you need to implement the 3D Secure flow in your checkout process.
Here are the steps to implement 3D Secure authentication in Laravel Cashier Stripe Subscription:
-
Update your Stripe API version to at least 2019-05-16, which supports 3D Secure 2.0.
-
In your subscription controller, after creating the payment intent, check if it requires 3D Secure authentication by checking the
statusproperty of the payment intent object. If the status isrequires_action, it means that 3D Secure authentication is required. -
If 3D Secure authentication is required, you need to redirect the user to the Stripe hosted authentication page. To do this, you can use the
redirectToCheckoutmethod provided by Laravel Cashier. Pass theclient_secretof the payment intent as a parameter to this method. -
After the user completes the authentication process, they will be redirected back to your website. You can handle the
success_urlandcancel_urlparameters in your subscription controller to update the subscription status accordingly.
Here's an example code snippet for the subscription controller:
use Stripe\PaymentIntent;
public function createSubscription(Request $request)
{
$user = $request->user();
$plan = $request->input('plan');
$paymentIntent = $user->createSetupIntent();
$subscription = $user->newSubscription('default', $plan)
->create($paymentIntent->id);
$paymentIntent = PaymentIntent::retrieve($paymentIntent->id);
if ($paymentIntent->status === 'requires_action') {
return redirect()->route('cashier.payment', [
'payment_intent_client_secret' => $paymentIntent->client_secret,
'success_url' => route('subscription.success'),
'cancel_url' => route('subscription.cancel'),
]);
}
// Subscription created successfully
return redirect()->route('subscription.success');
}
In this example, we check if the payment intent requires 3D Secure authentication by checking its status property. If it does, we redirect the user to the Stripe hosted authentication page using the redirectToCheckout method. If it doesn't, we assume that the subscription was created successfully and redirect the user to the success page.
Note that you need to handle the success_url and cancel_url parameters in your subscription controller to update the subscription status accordingly.