Open ciruz opened 1 year ago
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.
Hey @dayhaysoos, thank you for the information. Yeah this sounds like a very good idea.
@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
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?
@milindgoel15 can you show me how you have your CartProvider set up?
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>
@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
How are you using redirectToCheckout?
It is inside a custom component here which is imported in the main cart page.
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!
Worked using nextjs router.
router.push(session.url);
Hello. Do you have any updates on this issue? As it seems to be in the docs
Hey,
redirectToCheckout
expects an optional string https://github.com/dayhaysoos/use-shopping-cart/blob/275cb65f3d2fccb15857f4b9278cbbfca11eaf7a/use-shopping-cart/react/index.d.ts#L65But some examples calls the function with an object: https://github.com/dayhaysoos/use-shopping-cart/blob/275cb65f3d2fccb15857f4b9278cbbfca11eaf7a/examples/vite-react/src/components/price-product.jsx#L24