#Amos

1 messages · Page 1 of 1 (latest)

dawn oreBOT
maiden mirage
#

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?

void timber
#

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

maiden mirage
#

Can you share the code you use in the client and server to request the session and redirect?

void timber
#

<?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]);

?>

maiden mirage
#

ok, so you return the session id back to the client, that's good

#

What does the client side code look like?

void timber
#

Thanks. This is on the server side, for redirection. Basically, just the example from create-checkout-session.php.

maiden mirage
#

ok wait, you're just echo ing the json

#

Does this actually get back to your client app?

void timber
#

I do not think it will go back to client, Synthrider.

maiden mirage
#

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

void timber
#

Much appreciated, and let me check first. Another quick Q, will my API have a expiry date, and do I need to roll mandatory?

maiden mirage
#

What do you mean by that?

void timber
#

API key, sorry.

#

On the dashboard, do I have to roll the Security key and public key like every 3 months?

maiden mirage
#

No, that's not expected/required

#

You certainly can if you'd like to, though

void timber
#

Appreciate it, Synthrider. I am checking the new code example. The thing is if every time Stripe changes API, developer should get an email.

maiden mirage