Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LionHeartBlue's avatar

Cashier Stripe Integration fails with error return_url required

I have a very small Stripe Integration in my project to take a one-off payment.

Currently in test mode only, i enter a fake card number etc and click purchase. Stripe returns the following error:

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.

I discussed with Stripe who says these are options I cannot change within the Dashboard and must be sent via the API.

So I added these options to my code:

            $options =  [
                "automatic_payment_methods[enabled]" => true,
                "automatic_payment_methods[allow_redirects]" => 'never'
            ];

But the Cashier integration PerformsCharges.php" file is already passing a 'confirmation_method' => 'automatic', option which results in this error:

You may only specify one of these parameters: automatic_payment_methods, confirmation_method.

What is the best way to overcome this? Should I override the Cashier code somehow? Or do I need to ensure I am correctly sending a return_url?

1 like
3 replies
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

It seems like you're encountering a conflict between the automatic_payment_methods and confirmation_method parameters when using Stripe with Laravel Cashier. The error message indicates that you can only use one of these parameters, not both.

To resolve this issue, you should indeed provide a return_url where Stripe can redirect the user after the payment process is completed. This is especially important if you're using payment methods that require a customer to be redirected to an external page to complete the payment (like 3D Secure for credit cards).

Here's how you can specify the return_url when creating a PaymentIntent with Laravel Cashier:

use Laravel\Cashier\Cashier;

// ...

$payment = $user->charge($amount, $paymentMethod, [
    'return_url' => route('payment.completed'), // Replace with the route to your payment completion page
]);

// ...

Make sure to replace route('payment.completed') with the actual route name or URL that points to the page where you want your users to be redirected after the payment.

If you're using the PaymentIntent API directly, you would do something like this:

\Stripe\Stripe::setApiKey('your-stripe-secret-key');

$intent = \Stripe\PaymentIntent::create([
    'amount' => $amount,
    'currency' => 'usd',
    'payment_method_types' => ['card'],
    'payment_method' => $paymentMethodId,
    'confirmation_method' => 'manual',
    'confirm' => true,
    'return_url' => route('payment.completed'), // Replace with your actual return URL
]);

// ...

In this case, you're setting the confirmation_method to manual, which means you'll need to handle the confirmation of the payment on your server after the user has been redirected back.

Remember to update your routes and controller to handle the redirection after the payment. You'll need to check the status of the payment and take appropriate action based on whether it was successful or not.

Route::get('/payment/completed', 'PaymentController@completed')->name('payment.completed');

// ...

class PaymentController extends Controller
{
    public function completed(Request $request)
    {
        // You can retrieve the PaymentIntent ID from the request and check its status
        $paymentIntentId = $request->payment_intent;
        $paymentIntent = \Stripe\PaymentIntent::retrieve($paymentIntentId);

        if ($paymentIntent->status == 'succeeded') {
            // Handle successful payment
        } else {
            // Handle failed or incomplete payment
        }

        // Redirect the user or display a view with the payment result
    }
}

Make sure to handle all possible statuses of the payment intent, including requires_action, succeeded, and any error states.

2 likes
LionHeartBlue's avatar

Well, that was much simpler than I thought. Thanks. (Silly me)

lesniergonzalez's avatar

@LionHeartBlue

Hi, i was the same problem.

The solution is add option param with the 'return_url' attribute, to the charge function in the server..

$options = [ 'return_url' => 'your_success_url'];
 $user->charge($course->price * 100, $paymentMethod, $options  );
1 like

Please or to participate in this conversation.