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

Why is shipping_options not supported? #247

Closed
szabcsee opened this issue Nov 22, 2021 · 6 comments
Closed

Why is shipping_options not supported? #247

szabcsee opened this issue Nov 22, 2021 · 6 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@szabcsee
Copy link

Is there a reason why shipping_options is not added to the redirectToCheckout? Or it is and I am missing something?

@andria-dev andria-dev changed the title Why shipping_options is not supported? Why is shipping_options not supported? Dec 16, 2021
@andria-dev
Copy link
Collaborator

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?

@andria-dev andria-dev added enhancement New feature or request good first issue Good for newcomers labels Dec 16, 2021
@andria-dev
Copy link
Collaborator

Also, this might be the same issue as #246

@ehowey
Copy link
Contributor

ehowey commented Dec 30, 2021

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.

@ehowey
Copy link
Contributor

ehowey commented Dec 30, 2021

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,
        },
      }
    }
  },
]

@ehowey
Copy link
Contributor

ehowey commented Dec 31, 2021

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.

@dayhaysoos
Copy link
Owner

Closing - I think Eric got it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants