#Gironimo4 - redirectToCheckout

1 messages · Page 1 of 1 (latest)

magic sandal
#

Not immediately sure. Thinking on it.

#

Have you checked that sessionID is populated as you are expecting?

faint furnace
#

I believe it is, but where can I confirm? Is it in the dashboard?

magic sandal
#

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

faint furnace
#

When does a sessionID get created? Is it upon calling redirectToCheckout()?

magic sandal
#

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?

faint furnace
#

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.");
}

raven hamlet
#

@faint furnace my advice is to move away from redirectToCheckout entirely

#

redirect in PHP straight to $session->url; it's way easier

faint furnace
#

OK, that's great, would love to do that, is there a link running through that set up?

raven hamlet
#

Not really, it's just simple PHP really

faint furnace
#

Fair enough

raven hamlet
#

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)

faint furnace
#

Happy to send you the code I've got if you want to take a look

raven hamlet
#

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

faint furnace
#

Ah OK, I think I've been working somewhat off of that URL, I'll look into setting up Slim

raven hamlet
#

you don't need Slim or anything

faint furnace
#

OK, I appreciate the help!