woocommerce / woocommerce-gateway-stripe

The official Stripe Payment Gateway for WooCommerce
https://wordpress.org/plugins/woocommerce-gateway-stripe/
232 stars 204 forks source link

Invalid shipping address for UK and Apple Pay #1198

Closed vbelolapotkov closed 3 years ago

vbelolapotkov commented 4 years ago

Added by @v18:

There's a fix for this in WCPay - it needs to be ported over.


Describe the bug Apple Pay anonymises the part of the shipping address (postalCode and address lines) until payment is processed. This leads to invalid shipping address error in the payment request when shipping zones configured in a specific way. I.e. when shipping zones are configured based on zip code regex (e.g. BN11*) it's not detected correctly by payment request due to zip code is truncated by Apple Pay.

More details and screenshots: Support ticket: 2911575-zen. Slack chat: p1589288438496600-slack-CNXMMQBDW

To Reproduce

  1. Create shipping zone with regex-based zip code filter and flat rate (like in the example above).
  2. Serve the site from a public domain, e.g. with ngrok.
  3. Add some cards to Apple Pay.
  4. Add product to the cart and go to the cart page.
  5. Try to pay with Apple Pay and shipping address from UK matching the zone regex.
  6. Invalid shipping address error.

Expected behaviour Correct shipping zone and rate applied based on the selected shipping address.

vbelolapotkov commented 4 years ago

There is an additional note on apple developer site with mode details on postal code truncated:

Note The data returned may differ based on the user's geographic region. For Canada and United Kingdom, a redacted shipping address contains only the first three characters of the postal code. For US addresses, the redacted zip code contains the first five digits. The full postal code is provided after the user authorizes the transaction.

https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778009-onshippingcontactselected

grig-23 commented 4 years ago

User in 2911575-zen reported that the "invalid shipping address" error message only shows when the first part of the postcode is 4 digits, eg BN42. If the first part of the postcode is only 3 digits, eg BN1 - the payment works.

Also, they have reported no errors at all when shipping zones are not implemented although it is not entirely clear to me what exactly does that mean and I'm asking for clarification.

vbelolapotkov commented 4 years ago

The fix for this is probably in the core at the zip code to zone matching logic. It should properly recognize and treat partial UK postal codes.

jarman1 commented 4 years ago

Thank you for looking in to this guys (I'm the customer who reported the issue) I received the support email.

It might also be worth considering if the the postcode issue is also effecting Chrome Payment Requested buttons. I haven't personally set up Chrome/Google Pay to test.

Do you know a work around in the interim?

Thx

vbelolapotkov commented 4 years ago

I did some experiments with Chrome Payment Request buttons and full postal code was passed causing no issues. So this is Apple Pay only thing.

jarman1 commented 4 years ago

Do you know if this is fixed in the 4.2.0 update ?? Thanks :)

dougaitken commented 4 years ago

Another example, using Stripe 4.5.0 - confirmed as Vasily mentioned, this is an Apple Pay thing

https://wordpress.org/support/topic/apple-pay-wildcard-shipping-postcodes/#post-13191932

thedermacompany commented 4 years ago

I am having trouble with a very similar issue.

Apple Pay was working on my site until I integrated a couple of plugins, DPD for WooCommerce & Flexible Shipping. Both are required so that we can create shipping labels directly within the Wordpress dashboard for DPD consignments.

However now I have this installed, I have had to disable standard flat rate & free shipping rates that are built into WooCommerce and replace them with the Flexible Shipping opiton.

Within the flexible shipping options I can create a number of shipping options that are directly linked to a service offered by DPD, eg before 12pm, Saturday etc.

This all works fine but the issue arises when I try to use this in conjunction with Apple Pay, I get the dreaded 'Shipping Address Invalid'. As soon as I disable Flexible Shipping as the shipping method and reenable the standard options all is fine again.

I don't believe the postcode wildcards is causing any further issues as I have removed them and tested and I get the same issue with flexible shipping. If reverted to standard shipping and still include shipping wildcards then it works fine.

So to conclude I can either have Apple Pay live and working but then we will need to create a DPD consignment manually each time an order is placed or turn off Apple Pay and have the easier shipping methods integrated fully.

ps Google Pay works with these integration plug-ins with no issue at all.

katinthehatsite commented 3 years ago

Just wanted to add that this also happens with Canadian addresses and Apple Pay that also use the combination of letters and numbers in the addresses

treibalen commented 3 years ago

I believe this is another instance of the same bug. I created two shipping zones for the UK: one with postcodes and wildcards and the second one for the rest:

https://d.pr/i/JPSUMz Full Size: https://d.pr/i/JPSUMz

When I use Apple Pay, it doesn't match the first zone even though it should:

https://d.pr/i/vmICPV Full Size: https://d.pr/i/vmICPV

If I cancel it and go to the cart page, this how the postcode is truncated:

https://d.pr/i/Qp0Pfs Full Size: https://d.pr/i/Qp0Pfs

However, if I fill in the postcode normally, it shows the correct rate:

https://d.pr/i/QOt0cp Full Size: https://d.pr/i/QOt0cp

@vbelolapotkov can you please confirm that it's related to the same bug?

thedermacompany commented 3 years ago

It may be that your postcode wildcards are not setup correctly.

Can you send me a screenshot of the zone 1 that is setup with the list of wildcards?

Kind regards,

Asa / Head of Operations asa@thedermacompany.co.uk / 01582 808829

www.thedermacompany.co.uk

On 21 Dec 2020, at 15:37, treibalen notifications@github.com wrote:

I believe this is another instance of the same bug. I created two shipping zones for the UK: one with postcodes and wildcards and the second one for the rest:

https://camo.githubusercontent.com/d12f4fdc39ae7843a617ce51659a179a5123ac2ae42eb3d7c0d9f8352b77fb14/68747470733a2f2f642e70722f692f4976493747722b Full Size: https://d.pr/i/IvI7Gr https://d.pr/i/IvI7Gr When I use Apple Pay, it doesn't match the first zone even though it should:

https://camo.githubusercontent.com/71369982400dace0f5eb6cc6f98ad71a337bccd22979554431bd89b6dcc78e6b/68747470733a2f2f642e70722f692f766d494350562b Full Size: https://d.pr/i/vmICPV https://d.pr/i/vmICPV If I cancel it and go to the cart page, this how the postcode is truncated:

https://camo.githubusercontent.com/4515b62359a5a22b5d724a761b83eb25c7e904283f358f44d6897b5f711e8c0a/68747470733a2f2f642e70722f692f5170305066732b Full Size: https://d.pr/i/Qp0Pfs https://d.pr/i/Qp0Pfs However, if I fill in the postcode normally, it shows the correct rate:

https://camo.githubusercontent.com/158c6dfd27f03d944d554358d6da4e02636ff8ac8952979e785a9a054e284849/68747470733a2f2f642e70722f692f514f743063702b Full Size: https://d.pr/i/QOt0cp https://d.pr/i/QOt0cp @vbelolapotkov https://github.com/vbelolapotkov can you please confirm that it's related to the same bug?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/woocommerce/woocommerce-gateway-stripe/issues/1198#issuecomment-749037075, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARDCL6CL4NPFO4CLL7PYE2DSV5TVPANCNFSM4NAWWHEQ.

treibalen commented 3 years ago

Hi there @thedermacompany,

My wildcard setup can be seen on this screenshot: https://d.pr/i/IvI7Gr

Even if I add the postcode like GL40TY to the zone, it doesn't match with Apple Pay, but works with calculations on cart/checkout page.

So the issue might be with the combination of letters and numbers in the postcode in general.

thedermacompany commented 3 years ago

What I am referring to is when you open up the Zone 1 wildcards.

I believe you may have set these up incorrectly.

Are you looking for a list that include mainland UK postcode for Zone 1?

Kind regards,

Asa / Head of Operations asa@thedermacompany.co.uk / 01582 808829

www.thedermacompany.co.uk

On 21 Dec 2020, at 15:49, treibalen notifications@github.com wrote:

Hi there @thedermacompany https://github.com/thedermacompany,

My wildcard setup can be seen on this screenshot: https://d.pr/i/IvI7Gr https://d.pr/i/IvI7Gr Even if I add the postcode like GL40TY to the zone, it doesn't match with Apple Pay, but works with calculations on cart/checkout page.

So the issue might be with the combination of letters and numbers in the postcode in general.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/woocommerce/woocommerce-gateway-stripe/issues/1198#issuecomment-749042860, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARDCL6DXLBSSSVP3DXKWYIDSV5VBNANCNFSM4NAWWHEQ.

mouligreenlaw commented 3 years ago

3590824-zen

ricardo commented 3 years ago

I wasn't able to reproduce this issue - It works fine for me when I use a UK postcode with a wilcard flat rate shipping method. Apple Pay selects the right shipping method and the payment goes through.

Apple Pay continues to provide a partial postcode (first three digits) to wc_stripe_get_shipping_options, so I guess they fixed it in WooCommerce core (I couldn't find where they fixed it though).

Can someone on this thread please confirm if the issue isn't happening anymore? Then we can close this.

graftonhosting commented 3 years ago

The issue still exists for some UK postcodes, specifically when trying SK11* today using latest released versions of Woocommerce and Stripe gateway. As per earlier examples Apple Pay returns Shipping Address Invalid

ricardo commented 3 years ago

@graftonhosting, thanks for checking! I had tested with a 2 and a 3 character wildcard postcode, that's why it worked for me.

Unfortunately, Apple Pay only exposes the first 3 characters for WooCommerce to calculate the shipping options. This is due to privacy reasons. Other browsers don't do that.

This seems like an ongoing discussion at W3C. I added a comment there explaining our use case. If I understood correctly, they have an ongoing PR to allow merchants to negotiate the redacted fields.

For now, I don't have any ideas on how to fix this, but for those having problems, I'd suggest having a maximum of 3 characters wildcard postcodes.

jarman1 commented 3 years ago

Thanks for looking at this Ricardo

For most of the UK it would be sound to use 2-3 character wildcards. The issue arises in areas like the Scottish highlands where couriers charge different rates across the first 4 digits of a post code. A made up example would be say:

AB41 = The courier charges normal UK mainland shipping at £5 AB47 = The courier charges a "Scottish highlands" rate of £20

Again the above is a made up example, but If we to choose a flat rate for just AB or AB4 I could either disadvantage the a customer as the charge is too high, or be under charging the shipping for another customer.

Anyway it might be worth putting that differentiation forward?

thedermacompany commented 3 years ago

You need to enter these postcodes as follows:

UK Mainland AB6...AB43 AB46…AB49

UK Offshore AB37...AB38 AB44...AB45 AB51...AB56

Kind regards,

Asa / Head of Operations shop@thedermacompany.co.uk / 01582 808829

www.thedermacompany.co.uk

On 11 Feb 2021, at 09:37, jarman2020 notifications@github.com wrote:

Thanks for looking at this Ricardo

For most of the UK it would be sound to use 2-3 character wildcards. The issue arises in areas like the Scottish highlands where couriers charge different rates across the first 4 digits of a post code. A made up example would be say:

AB41 = The courier charges normal UK mainland shipping at £5 AB47 = The courier charges a "Scottish highlands" rate of £20

Again the above is a made up example, but If we to choose a flat rate for just AB or AB4 I could either disadvantage the a customer as the charge is too high, or be under charging the shipping for another customer.

Anyway it might be worth putting that differentiation forward?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/woocommerce/woocommerce-gateway-stripe/issues/1198#issuecomment-777314068, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARDCL6CF7UL67TKALONTSQ3S6OQOTANCNFSM4NAWWHEQ.

jarman1 commented 3 years ago

Thanks for this Asa..

I will look at setting my zones up like that. Unfortunately, I can't test if that works with Apple Pay as I don't live in those zones. Maybe Ricardo could check?

Cheers

thedermacompany commented 3 years ago

I have tested this before on my system and these worked fine alongside Apple Pay.

Only issue I encountered was trying to use in conjunction with a shipping plugin to use with DPD so that we could apply & print shipping labels from within the system.

Then the Apple Pay wouldn’t work as the shipping options were unable to be picked up by Apple Pay so would show the error invalid shipping address.

Kind regards,

Asa / Head of Operations shop@thedermacompany.co.uk / 01582 808829

www.thedermacompany.co.uk

On 11 Feb 2021, at 10:40, jarman2020 notifications@github.com wrote:

Thanks for this Asa..

I will look at setting my zones up like that. Unfortunately, I can't test if that works with Apple Pay as I don't live in those zones. Maybe Ricardo could check?

Cheers

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/woocommerce/woocommerce-gateway-stripe/issues/1198#issuecomment-777352175, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARDCL6DZD4Z4CMDFRWFJTMLS6OXYVANCNFSM4NAWWHEQ.

jarman1 commented 3 years ago

Unfortunately I'm getting another bug if I set up using the below.

UK Mainland AB6...AB43 AB46…AB49

UK Offshore AB37...AB38 AB44...AB45 AB51...AB56

UK mainland zone 1 is at the top of the zones list.

I enter an AB6 post code for example but get "No shipping options were found for" ?

graftonhosting commented 3 years ago

Yes, it's definitely still an issue for 4 character postcode prefixes. I have a shipping zone that should include LN1 to LN10 but not LN11, LN12, LN13.

However I set up the zones it is not possible to avoid the Apple Pay error because of the 3 character limit.

ricardo commented 3 years ago

Unfortunately, it looks like there's nothing we can do in Stripe to fix this.

TL;DR:

From Apple:

The data returned may differ based on the user's geographic region. For Canada and United Kingdom, a redacted shipping address contains only the first three characters of the postal code. For US addresses, the redacted zip code contains the first five digits.

The full postal code is provided after the user authorizes the transaction.

We get only the first 3 characters of a postal code when calculating shipping methods for the UK and Canada, e.g. full postal code is LN10 6SH, but we only get LN1 from Apple.

That creates an issue with wildcard shipping zones like LN10*, which should match, but don't because the provided postal code is redacted.

Perhaps what we can do here is to provide a notice for the merchant explaining the incompatibility with Apple Pay if Apple Pay is enabled and the store has UK or CA shipping zones with more than 4 digits.

@v18 Any thoughts?

v18 commented 3 years ago

Perhaps what we can do here is to provide a notice for the merchant explaining the incompatibility with Apple Pay if Apple Pay is enabled and the store has UK or CA shipping zones with more than 4 digits.

@ricardo - since we're not able to provide a fix for this - it sounds like a good idea to let merchants know about this incompatibility. Probably in the shipping zone area would be best, but could also do it near the payment request buttons.

@LevinMedia - I'd be curious to hear your thoughts about how to best let the users know about this problem: basically when using Apply Pay for shipping addresses in the UK, when using 4+ digit wildcard postal codes to calculate shipping, we aren't able to correctly calculate shipping and cannot complete the order. This is because Apple Pay only exposes the first 3 digits of the post code.

v18 commented 3 years ago

Related fix in WooCommerce Payments: https://github.com/Automattic/woocommerce-payments/pull/1528

ricardo commented 3 years ago

@v18 I can sync the changes to this repository.