First of all I am working from this URL
https://docs.stripe.com/payments/save-and-reuse
I have watched the video on the page. In the video, after clicking the setup button. The Stripe UI comes up. I never get that screen and I have tried different browsers.
The customer is created. The event log shows.
A new SetupIntent seti_1Ol4kvGznLM7Qekn5jObbbLm was created
The log screen shows a 200 OK POST /v1/checkout/sessions. But the UI never comes up. What am I missing?
require_once "vendor/autoload.php";
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys
$stripe = new StripeStripeClient('sk_test_51J5VXM');
$customer = $stripe->customers->create([
'description' => 'HealthScribe Client',
'email' => '[email protected]',
'name' => 'Jenny Rosen2',
]);
$stripe->checkout->sessions->create([
'mode' => 'setup',
'payment_method_types' => ['card'],
'success_url' => 'https://api.affordablecustomehr.com/stripe/success/?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => 'https://api.affordablecustomehr.com/stripe/cancel',
'customer' => $customer['id']
]);
2
Answers
It seems like you’re creating a SetupIntent and a Checkout Session correctly, but the issue might be with how you’re handling the response and redirecting the user to the Stripe hosted checkout page.
When you create a Checkout Session with the mode set to ‘setup’, Stripe expects that you will redirect your customer to the URL provided in the ‘url’ field of the returned session object. This URL will direct your customer to the Stripe-hosted setup page where they can enter their payment details.
You can adjust your code to handle this:
With this code, after creating the Checkout Session, the user will be redirected to the Stripe-hosted setup page (
$checkout_session->url
), where they can enter their payment details. Once they complete the setup, they will be redirected back to your success URL.Make sure to replace
'sk_test_51J5VXM'
with your actual secret key and handle error cases appropriately in your production code.I am currently using Stripe Laravel and React for frontend I want to create the session without success_url or cancel_url how can I do it As I don’t see any stripe class Named Payment Method and How will I redirect in react.
Thanks,
Muzamil