woocommerce / woocommerce-gateway-stripe

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

Bancontact payment fails when 'preferred_language' is not a supported language #1109

Open anoordende opened 4 years ago

anoordende commented 4 years ago

Describe the bug Payment using Bancontact fails when 'preferred_language' is not one of the supported languages: en, de, fr, or nl.

To Reproduce Steps to reproduce the behavior:

  1. Create a site in any language not being one of the supported Bancontact languages, so that get_locale() returns an unsupported language (for example, 'es').
  2. Process a Bancontact payment.

Expected behavior Expect the payment not to fail, but to fall back to one of the supported languages.

Actual behavior The payment fails with error "Invalid preferred language 'es'. Supported values are: de, en, fr, nl"

Environment (please complete the following information):

Additional Information Even though we can first avoid the error by setting a neutral default, e.g. 'en', as the fallback language, it can be challenging to decide on a client-friendly fallback. So perhaps this should result in a feature request for a filter so that site owners can apply their own logic, for example:

  1. If WP->get_locale() returns a supported language, use this
  2. Otherwise use the first supported Accept_Language in order of priority
  3. Finally, fall back to a fixed language

One way of solving this could be to pass an optional array of supported languages to WC_Stripe_Payment_Gateway->get_locale(), where a filter could determine the language, passing as parameters the supported languages and the payment gateway.

spraveenitpro commented 4 years ago

Another one 2708080-zen @allendav

LolaLemans commented 4 years ago

Hi, I am a site owner who has experienced and reported this issue, I have reported it both to Stripe and Woocommerce. I can image it has low priority because Bancontact is used in Belgium and not many sites are in Spanish language in this country, but my website serves the Spanish speaking community and I need to fix the issue urgently. I am OK with setting a neutral default, e.g. 'en', as the fallback language. Could anyone please kindly guide me to change the code? Which is the name of the function and where can I find it? Thank you in advance

dougaitken commented 4 years ago

Using @tommyshellberg's workaround for SOFORT in the identical scenario, this snippet can be used

/** Force Bancontact landing page to English - overrules preferred_language **/

add_filter('wc_stripe_bancontact_source', 'wc_stripe_bancontact_force_en_preferred_language', 10, 2); function wc_stripe_bancontact_force_en_preferred_language( $post_data, $order ) { $post_data['bancontact']['preferred_language'] = 'en'; return $post_data; }
LolaLemans commented 4 years ago

Thank you so much @dougaitken, your snippet just solved my issue. I highly appreciate it, wish you a wonderful weekend!