8

I'm using Stripe's PaymentRequest button to collect payment & shipping information to later process the payment with Stripe on the server side. I'm targeting ApplePay, but currently testing under PaymentRequest API (Chrome).

I need to know the customer's shipping address to calculate & show tax amount (and update grand total) before the payment form is submitted. I can easily get it via "shippingaddresschange" event, but only if the customer changes the address.

How can I get the default shipping address that the payment request form is automatically loaded with if customer doesn't change it later on? The initial (default) address does not seem to trigger "shippingaddresschange" event.

Jacob
  • 81
  • 2

3 Answers3

3

See examples at https://rsolomakhin.github.io/pr/single/ and https://rsolomakhin.github.io/pr/multi/. Chrome pre-selects an address if you pre-select a shipping option that you're OK using for any address in the world, i.e., flat rate shipping world-wide. Here you would not know the shipping address until the user authorizes the payment.

However, in your case, you need to know the shipping address to calculate & show the tax amount. This means that you don't have a world-wide flat rate, so you would not pre-select a shipping option. In this case, Chrome requires the user to explicitly approve providing their address to you, which means that the user's address will not be pre-selected in the UI as it is implemented right now.

1

I think this is a bug with Chrome. Safari/ApplePay will trigger an initial onshippingaddresschange when the payment sheet is displayed but Chrome does not.

I've also run into an issue with Chrome where I select a shipping address and onshippingaddresschange triggers. I then cancel/dismiss the dialog and re-open but the "default" shipping address is selected and all of the data (i.e. shipping option, tax, etc...) in my payment sheet is still set from the previous onshippingaddresschange event.

ApplePay doesn't have the same issue because it will trigger that onshippingaddresschange event as soon as it opens.

This isn't really an "answer" but I'm hoping this provides a little more context.

fuchse
  • 61
  • 1
  • 5
  • @Rouslan - I'm hoping you're `rouslan@chromium.org` on the Chromium bugs board and can provide some insight. – fuchse May 02 '18 at 14:22
  • This definitely helps me understand what's going on right now with my testing. Thanks for sharing. I'm having the exact same issue. Have you got a workaround at all? – LeonardChallis Aug 21 '18 at 12:42
-3

There's is no such thing like default shipping address. User always has to explicitly choose one before you get shippingaddresschange event. This is for privacy reasons.

agektmr
  • 2,144
  • 15
  • 14
  • 2
    This is not what happens in my case. For me, clicking Stripe button opens up a PaymentRequest API popup with an address already selected (which is first one from my list of saved addresses). If I proceed with the payment, that's the address that will be used and later provided as a shipping address. That's why I call it a "default" address because it was already selected when the popup appears. What you said makes sense for privacy reasons so that some rouge websites won't trigger the API just to collect your address. But how am I supposed to calculate proper tax then? – Jacob Feb 10 '18 at 23:09
  • @Jacob Sorry for lagged response. Can I see an example site that offers pre-selected shipping address? – agektmr Apr 12 '18 at 04:19