#androz_best-practices
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1432325921959972927
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- androz_error, 3 hours ago, 24 messages
- androz_best-practices, 4 days ago, 14 messages
Hello, this is linked to the previous threads
๐ Hi there! Let me take a look
What you said sounds viable, but just to clarify: what is the user experience that you want to have?
I would like my user to be able to select their product, then arrive on the payment page (including showing them the card input), and at that time, still be able to add promo codes
This should be possible with allow_promotion_codes: true: https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-allow_promotion_codes
thank you but how can I update my checkout once a user provides me with a coupon code?
Are you building a custom checkout, i.e. with ui_mode: custom when creating a Checkout Session?
From what I understand, you're using Elements with Checkout Sessions (so ui_mode: custom), and so your question is about how to apply a promotion code to the checkout session?
If you're using the latest Stripe.js version, then you can call applyPromotionCode() once a user provides you with a promo code, to apply it to the checkout session: https://docs.stripe.com/js/custom_checkout/apply_promotion_code
This will return a Promise including the updated Session object, where you will see the discountAmounts applied along with the updated prices: https://docs.stripe.com/js/custom_checkout/session_object#custom_checkout_session_object-discountAmounts
Let me try that right now
so that is client-side right? nothing is validated using our backend?
Hey! Taking over for my colleague. Yes
I'm having trouble calling loadActions on a checkout
(I'm debugging it)
const stripeCheckout = await stripe?.initCheckout({
fetchClientSecret: () => Promise.resolve(clientSecret),
})
if (!stripeCheckout) {
throw new Error("Stripe checkout not loaded")
}
const actionsResult = await (stripeCheckout as any).loadActions()
StripeCheckout does not have a loadActions, but a applyPromotionCode directly
I'm upgrading from 7.3 to 8.1
yes, that was the issue
let me try now
upgrading to v8 broke quite a lot of things ahah
or Uncaught IntegrationError: Invalid initCheckout() parameter: options.clientSecret is not an accepted parameter.
I read the v8 migration guide but couldn't figure out anything about confirm
Sorry but what Stripe SDK are you using exacty ?
this one, the latest version https://www.npmjs.com/package/@stripe/stripe-js
This seems to be an issue whith Checkout initialization
Can you share your code ? it shoul dbe something like this:
https://docs.stripe.com/js/custom_checkout/init
I'm creating a new checkout backend-side, then getting createdCheckout.client_secret, and calling:
const stripeCheckout = stripe?.initCheckout({
clientSecret
})
with clientSecret being the one I created on the backend
Can you share a complete stacktrace and i'll try to reproduce ?
Like one single JS file that illustrate what you are doing with Stripe SDK
Sure
Indeed I don't know how to proceed ahah.. it has to be an error on my side because my code is super simple
const clientSecret = "cs_test_b14RDDGxu7RWeSFaa9gF91UgeZVMg1NIqXkWpiMcpIT2NU1Ieult6HTDnj_secret_fidnandhYHdWcXxpYCc%2FJ2FgY2RwaXEnKSd2cGd2ZndsdXFsamtQa2x0cGBrYHZ2QGtkZ2lgYSc%2FY2RpdmApJ3BsSGphYCc%2FJ2ZwdnFqaCd4JSUl";
const stripe = await loadStripe(pubKey)
if (!stripe) {
throw new Error("Stripe not loaded")
}
console.log(clientSecret)
const stripeCheckout = stripe?.initCheckout({
clientSecret: clientSecret,
})
I'm checking every component one by one
You need to remove the %2F
sorry why?
Sorry I got confused by something else
No worries
Indeed I get the same error with the cs_test_b1AYulCRzZCvn51Czr46LEqJS2d1cXD6fPZIpT70X977hdfbrm4KVKMIVH_secret_fidnandhYHdWcXxpYCc/J2FgY2RwaXEnKSd2cGd2ZndsdXFsamtQa2x0cGBrYHZ2QGtkZ2lgYSc/Y2RpdmApJ3BsSGphYCc/J2ZwdnFqaCd4JSUl (decodeURIComponent), and I would be surprised that it's the issue because this code worked really well before
But the clientSecret seems not valid
Here is the clientSecret that you should use:
cs_live_b1P710Os4Jn8ax3v8GnOTjDb43vidDnvCQlhKf4mj3UyowlfnPBo3UhGWQ_secret_fidnandhYHdWcXxpYCc%2FJ2FgY2RwaXEnKSdwbEhqYWAnPydmcHZxamgneCUl
There is a change comparing to yours
No use the encoded one, as it was returned by Stripe API.
thank you for your continuous help by the way, I'm trying to sort a lot of things out by myself to remove some of the load on you ๐
Here is the clientSecret that you should use:
how did you get it?
how did you get it?
From the API response of your API callreq_cW3xnb2BLx8Sun
cs_test_b1KVjssMqtwPQmkvlfRZErgP0W6OQsX1HXUXdluZ3C6CoD99AV46CkqalA_secret_fidnandhYHdWcXxpYCc%2FJ2FgY2RwaXEnKSd2cGd2ZndsdXFsamtQa2x0cGBrYHZ2QGtkZ2lgYSc%2FY2RpdmApJ3BsSGphYCc%2FJ2ZwdnFqaCd4JSUl
this is exactly what I get from Stripe from my backend
is it correct?
Hi, taking over as my teammate needs to step away. Let me catch up.
thank you
So what my teammate still applies here. The client secret would be cs_test_b1KVjssMqtwPQmkvlfRZErgP0W6OQsX1HXUXdluZ3C6CoD99AV46CkqalA_secret_fidnandhYHdWcXxpYCc%2FJ2FgY2RwaXEnKSd2cGd2ZndsdXFsamtQa2x0cGBrYHZ2QGtkZ2lgYSc in this case
Can you try that please?
So with the API version, you're using https://docs.stripe.com/payments/quickstart-checkout-sessions#initialize-checkout-html
Use clientSecret to initialize Checkout, passing a client secret string or a Promise that resolves to it. The Checkout object forms the backbone of your checkout page and contains data from the Checkout Session and methods to update it.
Can you try that guide carefully please?
Yes
my main branch (without upgrading to v8) is now encountering the same issue so I'll have a deeper look at it later and come back to you. Thank you very much for your time and your help, you definitely pointed the right direction with the applyPromoCode function. The implementation is still broken but I hope that I can figure out and it's less important than the design choices!
thank you again for your help
(feel free to close the ticket? I wish I could post the resolution here once I get it but I guess that everything's lock after an idle time?)
Sounds good, let us know if you run in to anything else we can help with! We do close threads after ~15 mins of inactivity so yes this thread will likely be locked by then but I do appreciate the thought.
oh, wait
I think I figured out where it came from
I'll get back to you in a few mins
So indeed the issue was with react stripe, not from the initCheckout that I thought was being called...
and because it's done internally on their end, it didn't show up and I didn't think about it when searching for initCheckout
Nice, glad you were able to figure it out! Thanks for the followup
thanks! everything is working now.