use-shopping-cart
use-shopping-cart copied to clipboard
Why is shipping_options not supported?
Is there a reason why shipping_options is not added to the redirectToCheckout? Or it is and I am missing something?
Hi @szabcsee, I think we just didn't originally have the option for shipping_options
when working on this library previously, or we weren't aware of it. As an alternative, you should be able to use getCheckoutData(cart)
and then modify the result of that and pass it to stripe.redirectToCheckout()
.
For the future, do you have a preferred way of passing these values to redirectToCheckout
?
Also, this might be the same issue as #246
Hey I just ran into the need to support this - and am going to have a go at adding it to the library. We will see where I can get to. It might end up being a working draft that can be used by the library maintainers to create a permanent solution.
Just a comment to update that I tried to add this support in - but was having a lot of trouble just getting CRA from the repo to work properly. Some of that was env variables at first - but I also couldn't get the <DebugCart />
component to render and was trying to find a way to console.log
out the Redux state.
I think in theory support for shipping options should be pretty easy - handled similarly to allowedCountries
.
- Default to null
- Check
cart.shippingOptions?.length
- If present then add in the shipping options to the cart options passed to Stripe
Here is an example of what that looks like. My suggestion is that we can start out offering beta support with just an array type and leave it up to developers to properly pass the required object shape...
shipping_options: [
{
shipping_rate_data: {
type: 'fixed_amount',
fixed_amount: {
amount: 0,
currency: 'usd',
},
display_name: 'Free shipping',
# Delivers between 5-7 business days
delivery_estimate: {
minimum: {
unit: 'business_day',
value: 5,
},
maximum: {
unit: 'business_day',
value: 7,
},
}
}
},
{
shipping_rate_data: {
type: 'fixed_amount',
fixed_amount: {
amount: 1500,
currency: 'usd',
},
display_name: 'Next day air',
# Delivers in exactly 1 business day
delivery_estimate: {
minimum: {
unit: 'business_day',
value: 1,
},
maximum: {
unit: 'business_day',
value: 1,
},
}
}
},
]
Okay - so I tried hard coding in the shipping options parameter just to test if I could get it all working and talking to Stripe without USC. I ran into an "Integration Error", which I thought at first was USC but was actually coming from Stripe.
Turns out there is some inconsistency in their API surface area.
https://stripe.com/docs/payments/checkout/shipping
and
https://stripe.com/docs/js/checkout/redirect_to_checkout
Are not perfectly aligned. It does not look like redirectToCheckout supports shippingOptions yet from what I can tell. But I would assume that is coming in the future maybe? It would be nice if someone from Stripe could confirm this or give some insight as that first link really makes it seem as if Stripe should support the shipping_options parameter.
Closing - I think Eric got it!