Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirectToCheckout expects an optional string, some examples outdated #323

Open
ciruz opened this issue May 31, 2023 · 11 comments
Open

redirectToCheckout expects an optional string, some examples outdated #323

ciruz opened this issue May 31, 2023 · 11 comments

Comments

@ciruz
Copy link
Contributor

ciruz commented May 31, 2023

Hey,

redirectToCheckout expects an optional string

redirectToCheckout: (sessionId?: string) => Promise<any>

But some examples calls the function with an object:

redirectToCheckout({ sessionId: response.sessionId })

@dayhaysoos
Copy link
Owner

Hey @ciruz, I'ma be honest, Stripe has deprecated redirectToCheckout in favor of using a Checkout Object instead:

https://stripe.com/docs/payments/checkout/how-checkout-works.

I think I should work towards removing redirectToCheckout from the library or at least warning people that it's deprecated and providing more updated examples. Thank you for flagging this, going to try and make an effort for this in about 2 weeks.

@ciruz
Copy link
Contributor Author

ciruz commented Jun 1, 2023

Hey @dayhaysoos, thank you for the information. Yeah this sounds like a very good idea.

@dayhaysoos
Copy link
Owner

@ciruz sweet! Yeah I'm going to make an issue for this and after 2 weeks I'll work towards getting it done and providing more updated examples

@milindgoel15
Copy link
Contributor

Error:  PropertyTypeError: Invalid value with type "undefined" was received for stripe. Valid type for stripe is "string".

Just to confirm, when using redirectToCheckout in the latest version of useShoppingCart, it will give this error?

@dayhaysoos
Copy link
Owner

@milindgoel15 can you show me how you have your CartProvider set up?

@milindgoel15
Copy link
Contributor

milindgoel15 commented Jun 18, 2023

let stripeKey: string = process.env.STRIPE_PUBLISHABLE_KEY as string;
                        <CartProvider 
                                 stripe={stripeKey} 
                                 cartMode="checkout-session" 
                                 currency="USD" 
                                 shouldPersist 
                         > 
                                 <style jsx global>{` 
                                         html { 
                                                 font-family: ${inter.style.fontFamily}; 
                                         } 
                                 `}</style> 
                                 <Header /> 
                                 <Component {...pageProps} /> 
                                 <Toaster /> 
                                 <Footer /> 
                         </CartProvider>

@dayhaysoos
Copy link
Owner

@milindgoel15 How are you using redirectToCheckout?

If you're doing it with an API function, you won't have access to it since the Provider isn't wrapped around the server functions.

I think this week I can spend time on updating to remove redirect to checkout altogether tbh, since it seems to be deprecated

@milindgoel15
Copy link
Contributor

How are you using redirectToCheckout?

It is inside a custom component here which is imported in the main cart page.

@dayhaysoos
Copy link
Owner

Yeah it could be possible that it doesn't get returned from the Stripe object anymore. USC uses your Stripe API key to initialize stripe and you get back redirectToCheckout from there.

https://stripe.com/docs/js/deprecated/redirect_to_checkout

I didn't know that it stopped being returned at this point. You're going to have to use a server function of some sort to handle this. I need to update use-shopping-cart docs to reflect these changes, I'm sorry!

@milindgoel15
Copy link
Contributor

Worked using nextjs router.

router.push(session.url);

@ajesuscode
Copy link

Hello. Do you have any updates on this issue? As it seems to be in the docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants