#ruben-checkout-promotioncode
1 messages · Page 1 of 1 (latest)
@mortal oak I'm happy to help, can you share your exact code and then an example Checkout Session URL for me to look at?
ruben-checkout-promotioncode
Hello! Yes for sure I will show you my code example and what I see as a result
@fluid breach please only post in this thread
I deleted your other messages, please share your exact code as text here and an exact URL, no pictures
Ok, sorry, this is the code
with the rule 'allow_promotion_codes'
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [
'price_data' => [
'currency' => 'usd',
'product_data' => [
'name' => $customerName
],
'unit_amount' => 100,
],
'quantity' => 1,
],
'mode' => 'payment',
'allow_promotion_codes' => true,
'success_url' => 'www.barmencosmetic.com/index.html',
'cancel_url' => 'www.barmencosmetic.com/catalog.html',
'customer_email' => $customerEmail,
'billing_address_collection' => 'required',
'phone_number_collection' => [
'enabled' => true
]
]);
okay what's the Checkout Session id?
that Session was never created with the code you mentioned
maybe I missunderstood you
could be this
return stripe.redirectToCheckout({
sessionId: session.id,
lineItems: elements,
successUrl: 'https://www.barmencosmetic.com/index.html?checkout=success',
cancelUrl: 'https://www.barmencosmetic.com/index.html?checkout=fail',
mode: 'payment',
customerEmail: email,
billingAddressCollection: "required",
shippingAddressCollection: { "allowedCountries": ["ES", "PT"] } });
yeah that code is entirely separate, it creates a brand new Checkout Session with only client-side code. It's also been deprecated for at least 2 years.
That code can never allow promotion codes
oh
You need to remove that code completely and use the Session you created in PHP instead really
mmmm don't know how could I migrate it
to be honest
I'm pretty new using Stripe API
there's no reason at all to use redirectToCheckout() anymore, we deprecated this 2 years ago
so remove that entire code. Redirect from the server instead
thanks, so if i just comment out that full block of code
and use the session created in PHP (server-side) is enough?
just with this?
no it's not enough. That code returns a Session id at the end. It needs to redirect to the Session's url like shown on the quickstart I shared.
And client-side you also need to change how you format.
Okay let's try something a lot easier first
return stripe.redirectToCheckout({sessionId: session.id});
Try this instead of the code you had earlier with all the extra parameters
Alright, will do. give me 2 minutes