#Amos
1 messages · Page 1 of 1 (latest)
No expected changes that would cause something like this, no. Do you have examples of this happening and the code you're using to redirect?
Are you able to reproduce this?
Thanks. This is my website. After choose a class, fulfilled info, and click "proceed to check". It should redirect to Stripe. Previously, working so well until yesterday. https://www.emeralit.com/academy/enroll/
I am wondering, if any changes on API calls recently. Or, need to upgrade
Can you share the code you use in the client and server to request the session and redirect?
<?php
session_start();
require '../stripe/vendor/autoload.php';
\Stripe\Stripe::setApiKey('sk_live_*******************************************************');
header('Content-Type: application/json');
$YOUR_DOMAIN = 'https://emeralit.com/academy';
$checkout_session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [[
'price_data' => [
'currency' => 'usd',
'unit_amount' => $_SESSION["price"] * 100,
'product_data' => [
'name' => $_SESSION["course_fullName"],
'images' => ["https://emeralit.com/academy/enroll/images/stripe.jpg"],
],
],
'quantity' => 1,
]],
'mode' => 'payment',
'success_url' => $YOUR_DOMAIN . '/portal/paid.html',
'cancel_url' => $YOUR_DOMAIN . '/enroll',
]);
echo json_encode(['id' => $checkout_session->id]);
?>
ok, so you return the session id back to the client, that's good
What does the client side code look like?
Thanks. This is on the server side, for redirection. Basically, just the example from create-checkout-session.php.
ok wait, you're just echo ing the json
Does this actually get back to your client app?
Right, so you can do this but redirectToCheckout is deprecated now that sessions have a url
So you can instead send the url back to the client and redirect to that directly, or redirect the request server-side if you request pattern allows that, which is what our example does:
https://stripe.com/docs/checkout/quickstart?lang=php&client=html
$checkout_session = \Stripe\Checkout\Session::create([
'line_items' => [[
# Provide the exact Price ID (e.g. pr_1234) of the product you want to sell
'price' => '{{PRICE_ID}}',
'quantity' => 1,
]],
'mode' => 'payment',
'success_url' => $YOUR_DOMAIN . '/success.html',
'cancel_url' => $YOUR_DOMAIN . '/cancel.html',
'automatic_tax' => [
'enabled' => true,
],
]);
header("HTTP/1.1 303 See Other");
header("Location: " . $checkout_session->url);
If you want/need to do the client reidrect thats fine, but you have the same issue of needing to ensure that response gets back to the client application
Much appreciated, and let me check first. Another quick Q, will my API have a expiry date, and do I need to roll mandatory?
What do you mean by that?
API key, sorry.
On the dashboard, do I have to roll the Security key and public key like every 3 months?
Appreciate it, Synthrider. I am checking the new code example. The thing is if every time Stripe changes API, developer should get an email.
You can register for our developer digest here: https://stripe.com/docs/upgrades#stay-informed