woocommerce / woocommerce-gateway-stripe

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

When non-supported country is chosen and Payment Request button enabled - variable product functionality breaks #1203

Closed dougaitken closed 3 years ago

dougaitken commented 4 years ago

Describe the bug

When the country for Store Address is something other than the supported countries for Payment Request buttons - set at WooCommerce > Settings > General > Store Address - the variable product functionality breaks and a JS console warning is logged.

Original issue:


WooCommerce considers Puerto Rico as a country* but Stripe designates it as a State of the United States. This means when a WooCommerce site is using the Stripe payment gateway extension and the Payment Request buttons, "we" report this to Stripe via wc_stripe_supported_countries as a country PR - Stripe then looks on their list and doesn't find it, so it rejects the Payment Request button creation.

Uncaught IntegrationError: Invalid value for paymentRequest(): country should be one of the following strings: AE, AT, AU, BE, BR, CA, CH, CZ, DE, DK, EE, ES, FI, FR, GB, GR, HK, IE, IN, IT, JP, LT, LU, LV, MX, MY, NL, NO, NZ, PH, PL, PT, RO, SE, SG, SI, SK, US. You specified: PR.
    at new t (https://js.stripe.com/v3/?ver=3.0:1:10981)
    at Pt (https://js.stripe.com/v3/?ver=3.0:1:19535)
    at Ot (https://js.stripe.com/v3/?ver=3.0:1:19606)
    at new t (https://js.stripe.com/v3/?ver=3.0:1:77203)
    at ba (https://js.stripe.com/v3/?ver=3.0:1:104901)
    at e.<anonymous> (https://js.stripe.com/v3/?ver=3.0:1:163370)
    at e.paymentRequest (https://js.stripe.com/v3/?ver=3.0:1:27321)
    at Object.startPaymentRequest ([...]wp-content/plugins/woocommerce-gateway-stripe/assets/js/stripe-payment-request.min.js?ver=4.3.3:1:5152)
    at Object.init ([...]wp-content/plugins/woocommerce-gateway-stripe/assets/js/stripe-payment-request.min.js?ver=4.3.3:1:8373)
    at HTMLDocument.<anonymous> ([...]/wp-content/plugins/woocommerce-gateway-stripe/assets/js/stripe-payment-request.min.js?ver=4.3.3:1:8420)

What also happens at this point is, I think, JavaScript functionality is disabled so variable product selection doesn't work as expected. Both dropdowns work but the Ajax request isn't used to check stock and variation selection. The Clear button doesn't work.

Disabling the Payment Request buttons from the Stripe payment gateway settings returns the functionality.

Support for PR in the Payment Request button was added to Stripe via #845

I'm unsure how useful this is but since @DanReyLop mentioned having to create some custom code for other scenarios, I looked for similar and found this - https://github.com/woocommerce/woocommerce-gateway-paypal-express-checkout/pull/693

Oh, something similar happened to our integration with USPS. In that case, an address with country: PR was rejected as invalid, but an address with country: US, state: PR was accepted. We had to write a bit of code to transform those Puerto Rico, Guam, Virgin Islands, etc addresses. We'll probably need to do something similar for Stripe.

Semi-related - 53-gh-woocommerce/woocommerce-shipping-usps

Context

forum thread prompting this - https://wordpress.org/support/topic/uncaught-integrationerror-invalid-value-for-paymentrequest-country-should-be/#post-12826393

Stripe.com docs link - Puerto Rico is classed as a state but no other unincorporated territory is treated as such, others aren't supported - https://support.stripe.com/questions/stripe-availability-for-outlying-territories-of-supported-countries

Internal Slack - p1589366017120800-slack-C9976E5MJ

To Reproduce Steps to reproduce the behavior:

  1. Set base country as Puerto Rico
  2. Enable Payment Request buttons via Stripe payment gateway settings
  3. Use Safari or another Payment Request button supporting browser like Chrome or Edge to load a variable product page
  4. Notice no Payment Request button and variation selection doesn't reload the selections
  5. Check browser console for error
  6. Uncheck Payment Request button setting and resave Stripe Payment Request button settings
  7. Reload product page and see that variation selection is as expected

Expected behavior

As Puerto Rico is supported by Stripe.com, the extension needs to support all available APMs as expected.

Screenshots

Gif - https://d.pr/i/DbHiAj

Environment (please complete the following information):

` ### WordPress Environment ### WordPress address (URL): [redacted] Site address (URL): [redacted] WC Version: 4.1.0 REST API Version: ✔ 1.0.7 WC Blocks Version: ✔ 2.5.16 Action Scheduler Version: ✔ 3.1.5 WC Admin Version: ✔ 1.1.1 Log Directory Writable: ✔ WP Version: 5.4.1 WP Multisite: – WP Memory Limit: 256 MB WP Debug Mode: ✔ WP Cron: ✔ Language: en_US External object cache: ✔ ### Server Environment ### Server Info: nginx PHP Version: 7.3.18 PHP Post Max Size: 2 GB PHP Time Limit: 1200 PHP Max Input Vars: 6144 cURL Version: 7.70.0 OpenSSL/1.1.1d SUHOSIN Installed: – MySQL Version: 5.5.5-10.3.22-MariaDB-log Max Upload Size: 2 GB Default Timezone is UTC: ✔ fsockopen/cURL: ✔ SoapClient: ✔ DOMDocument: ✔ GZip: ✔ Multibyte String: ✔ Remote Post: ✔ Remote Get: ✔ ### Database ### WC Database Version: 4.1.0 WC Database Prefix: wp_ Total Database Size: 2.56MB Database Data Size: 1.12MB Database Index Size: 1.44MB wp_woocommerce_sessions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_woocommerce_order_items: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_order_itemmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_actions: Data: 0.02MB + Index: 0.11MB + Engine InnoDB wp_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_logs: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_comments: Data: 0.02MB + Index: 0.09MB + Engine InnoDB wp_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_options: Data: 0.11MB + Index: 0.03MB + Engine InnoDB wp_postmeta: Data: 0.14MB + Index: 0.09MB + Engine InnoDB wp_posts: Data: 0.09MB + Index: 0.06MB + Engine InnoDB wp_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_term_relationships: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_usermeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_users: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_wc_admin_notes: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_admin_note_actions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_product_lookup: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_wc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_product_meta_lookup: Data: 0.02MB + Index: 0.09MB + Engine InnoDB wp_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB ### Post Type Counts ### attachment: 40 customize_changeset: 1 page: 9 post: 2 product: 30 product_variation: 7 revision: 4 ### Security ### Secure connection (HTTPS): ✔ Hide errors from visitors: ✔ ### Active Plugins (4) ### Akismet Anti-Spam: by Automattic – 4.1.5 Jetpack by WordPress.com: by Automattic – 8.5 WooCommerce Stripe Gateway: by WooCommerce – 4.3.3 – Installed version not tested with active version of WooCommerce 4.1.0 WooCommerce: by Automattic – 4.1.0 ### Inactive Plugins (2) ### AMP: by AMP Project Contributors – 1.5.3 Gutenberg: by Gutenberg Team – 8.0.0 ### Dropin Plugins (2) ### advanced-cache.php: advanced-cache.php object-cache.php: Memcached ### Must Use Plugins (1) ### WP.com Site Helper: by – ### Settings ### API Enabled: – Force SSL: – Currency: USD ($) Currency Position: left Thousand Separator: , Decimal Separator: . Number of Decimals: 2 Taxonomies: Product Types: external (external) grouped (grouped) simple (simple) variable (variable) Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog) exclude-from-search (exclude-from-search) featured (featured) outofstock (outofstock) rated-1 (rated-1) rated-2 (rated-2) rated-3 (rated-3) rated-4 (rated-4) rated-5 (rated-5) Connected to WooCommerce.com: – ### WC Pages ### Shop base: #7 - /shop/ Cart: #8 - /cart/ Checkout: #9 - /checkout/ My account: #10 - /my-account/ Terms and conditions: ❌ Page not set ### Theme ### Name: Storefront Version: 2.5.6 Author URL: https://woocommerce.com/ Child Theme: ❌ – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme WooCommerce Support: ✔ ### Templates ### Overrides: – ### Action Scheduler ### Complete: 2 Oldest: 2020-05-11 06:38:40 +0000 Newest: 2020-05-12 07:33:07 +0000 Pending: 1 Oldest: 2020-05-18 05:54:02 +0000 Newest: 2020-05-18 05:54:02 +0000 `

Additional context Add any other context about the problem here.

joweber123 commented 4 years ago

Another report of this here 3023025-zen

automattic-ian commented 3 years ago

another report here: 3397389-zen

madeincosmos commented 3 years ago

Also happens for Aland Islands (reported in 25192248-hc)

dougaitken commented 3 years ago

Bumping to High and L since this happens with any country that isn't a supported Payment Request button country.

Recent forum thread - https://wordpress.org/support/topic/stripe-misbehaves-with-woodmart/#post-13701296

dougaitken commented 3 years ago

This error is thrown if the country for WooCommerce > Settings > General > Store Address doesn't match the array of supported countries of Stripe - https://stripe.com/global - the error is thrown by Stripe.com JavaScript and not our extension.

Since we don't do a country check for the main plugin activation anymore ( #1288 ), I feel we should be disabling the Payment Request button if Stripe is activated for a non-supported country with a warning similar to #1284 to allow the rest of the functionality to proceed.

dechov commented 3 years ago

Haven't tested or looked too deeply but it seems there are 3 issues that could be tackled separately:

v18 commented 3 years ago

Thanks @dechov for looking into this! Would you be able to open the three issues you're proposing? I'm not sure I understand the case for reverting the deletions, so if you have more context to add to that issue I'd love to read it.

dechov commented 3 years ago

I'm not sure I understand the case for reverting the deletions, so if you have more context to add to that issue I'd love to read it.

@v18 The deletions were part of moving the country check "from payment request to main plugin" in https://github.com/woocommerce/woocommerce-gateway-stripe/pull/1254, reverted in https://github.com/woocommerce/woocommerce-gateway-stripe/pull/1288 except that the country check for Payment Request hasn't been restored – which AFAICT is why this issue is now affecting not only Puerto Rico but any unsupported country as well.

allendav commented 3 years ago

except that the country check for Payment Request hasn't been restored

On purpose. The rationale was that Stripe has been adding countries and previews and even specific merchants that any list is rapidly out of date.

dechov commented 3 years ago

👍 On second thought then, we shouldn't revert that bit – if we just fix the error handling, this won't cause any breakage or be an issue for unsupported countries. In order of priority then:

dechov commented 3 years ago

@v18 They (just two now) are independent fixes, so it does make sense to treat them separately, but I'm not really sure if we need separate issues – or which to break out, since both seem to pertain equally to the issue as reported above 🤔 – or did you mean having child issues to this one?

v18 commented 3 years ago

@dechov - you're talking about this:

Adapt the case of "country: PR" to "country: US" + "state: PR" Stripe.js error breaking variation selection – just need to wrap in try…catch?

Yeh, let's keep 'em in this issue. Assigning as good first issue, it's more complex but also more fun!

pjrobertson commented 3 years ago

I've just come across this same error message:

Uncaught IntegrationError: Invalid value for paymentRequest(): country should be one of the following strings: AE, AT, AU, BE, BG, BR, CA, CH, CI, CR, CY, CZ, DE, DK, DO, EE, ES, FI, FR, GB, GR, GT, HK, HU, ID, IE, IN, IT, JP, LT, LU, LV, MT, MX, MY, NL, NO, NZ, PE, PH, PL, PT, RO, SE, SG, SI, SK, SN, TH, TT, US, UY. You specified: CN.

But my situation seems a bit simpler (not related a question of country/state). My store address is set to CN (China) and I'm using Stripe (HK). Stripe works perfectly if people are able to get through to the checkout screen, but this error is thrown on product pages making it difficult for people to add a product to their cart.

Disabling the Payment Request Buttons works as a temporary work around.

saultrejo commented 1 year ago

Turning off Apple Pay and Google Pay fixed this issue for me.

yankarley commented 1 year ago

Turning off Apple Pay and Google Pay fixed this issue for me.

it does not fix it for me!... Plus, why sacrifice Apple pay which is so good!? I cannot believe this has not been fixed yet...who can help me!? My clients should not have to see that error message and I should be able to use Klarna!