#ruben-checkout-promotioncode

1 messages · Page 1 of 1 (latest)

surreal sedgeBOT
weary stag
#

@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

fluid breach
#

Hello! Yes for sure I will show you my code example and what I see as a result

weary stag
#

@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

fluid breach
#

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

weary stag
#

okay what's the Checkout Session id?

weary stag
#

that Session was never created with the code you mentioned

fluid breach
#

maybe I missunderstood you

#

could be this

weary stag
#

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

fluid breach
#

oh

weary stag
#

You need to remove that code completely and use the Session you created in PHP instead really

fluid breach
#

mmmm don't know how could I migrate it

#

to be honest

#

I'm pretty new using Stripe API

weary stag
#

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

fluid breach
#

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?

weary stag
#

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

fluid breach
#

Alright, will do. give me 2 minutes