#Gironimo4 - redirectToCheckout
1 messages · Page 1 of 1 (latest)
Not immediately sure. Thinking on it.
Have you checked that sessionID is populated as you are expecting?
I believe it is, but where can I confirm? Is it in the dashboard?
Oh I more meant to ask if you have debugged to see the value of that variable
Make sure it isn't null there. Still looking in to what might cause this to just reload
Also, if it makes sense for your integration, you can simply send the Session's URL client side and do a normal redirect to that https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-url
When does a sessionID get created? Is it upon calling redirectToCheckout()?
That would be happening server side when your server makes the call to create the checkout session
What is $stripeSessionId getting set to in your code?
It is in this line of code:
if ($customer->id) {
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'mode' => 'payment',
'customer' => $customer->id,
'line_items' =>
[
//'price' => 'price_H5ggYwtDq4fbrJ',
'price' => $planLevel,
'quantity' => 1,
],
'success_url' => "https://www.lifaexam.org/registration/payment-complete.php?session_id={CHECKOUT_SESSION_ID}",
'cancel_url' => 'https://lifaexam.org/',
]);
$stripeSessionId = $session->id;
$formSubmitted = true;
} else {
/* throw new Exception("The Stripe Token or customer was not generated correctly"); */
throw new Exception("An error has occurred. Your card has not been charged. Please try again.");
}
@faint furnace my advice is to move away from redirectToCheckout entirely
redirect in PHP straight to $session->url; it's way easier
OK, that's great, would love to do that, is there a link running through that set up?
Not really, it's just simple PHP really
Fair enough
Hard to say without seeing your whole code, it depends how you call the Checkout Session creation from your client
let me see if we have an example of this, I'll be back (I hope)
Happy to send you the code I've got if you want to take a look
https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=checkout#redirect-customers
$session = \Stripe\Checkout\Session::create([
'line_items' => [[
'price_data' => [
'currency' => 'usd',
'product_data' => [
'name' => 'T-shirt',
],
'unit_amount' => 2000,
],
'quantity' => 1,
]],
'mode' => 'payment',
'success_url' => 'https://example.com/success',
'cancel_url' => 'https://example.com/cancel',
]);
return $response->withHeader('Location', $session->url)->withStatus(303);
});```
that's what we advise in our official docs for example
it's way easier than trying to get the id back to the JS, then call the function to redirect and all that
Ah OK, I think I've been working somewhat off of that URL, I'll look into setting up Slim
you don't need Slim or anything
OK, I appreciate the help!