MultiSafepay / woocommerce

MultiSafepay WooCommerce plugin
https://docs.multisafepay.com/docs/woocommerce
10 stars 2 forks source link

Fallback instead of error "Country code should be 2 characters (ISO3166 alpha 2)"? #15

Closed jellewebsols closed 3 years ago

jellewebsols commented 3 years ago

Is it possible to create some kind of fallback mechanism if the country code in the customers billing and/or shipping data is missing? We've had this fields disabled in the checkout at one of our clients because they only 'sell' registrations for events in one country (the Netherlands) In previous versions of the MSP payment plugin this wasn't a problem, but in recent versions it has started throwing errors "Country code should be 2 characters (ISO3166 alpha 2)" without a clear explanation why this error is occuring. (Eventually traced it down to the above)

Don't know what the best fallback mechanism would be, but maybe it can assume it's the shop base country? Or else maybe add an select field in the plugin settings?

danielcivit commented 3 years ago

Hello @jellewebsols

Thanks for your report and feedback. Supporting the business and use cases of our partners and merchants is very important for us. So, let's see if we can find a solution to your case, also I would like to share a brief explanation about this.

The country code that we use within the OrderRequest object is provided by shipping address country code, and the billing address country code of the WooCommerce order like you said, which is usually a WooCommerce default field.

This information is not just desirable, is mandatory. https://docs.multisafepay.com/api/#required-transaction-details

Starting with version 4.0.X of the WooCommerce plugin, we completely rewrote the plugin and started using our own PHP-SDK. that standardizes the information we need to process each transaction. In this case, it is the PHP-SDK dependency that throws an exception when no country code is found. As you can understand, requiring country information has not been a decision taken lightly and involves all of our integrations, not just the WooCommerce plugin.

In your case, you are telling me that your client only sells to customers in the Netherlands, so I think all this can have a simple solution. Please, could you try to use the following filter "woocommerce_order_get_billing_country" built in WooCommerce?

An example code will be something like this:

add_filter('woocommerce_order_get_billing_country', 'my_woocommerce_filter_for_billing_country');
add_filter('woocommerce_order_get_shipping_country', 'my_woocommerce_filter_for_billing_country');

function my_woocommerce_filter_for_billing_country( $country ) {
  // Return the country code according with your business case. 
  return 'NL';
}

Please, could you tell me if you understand the above code and if you are able to use it to sort out the reported and expected error?

Thanks.

jellewebsols commented 3 years ago

Hello @Daniel-MultiSafepay, thank you for pointing us to that filter. We thought there had to be something like this, but no luck searching the documentation of Woocommerce and no similar problems found on the internet.

We'll do some more testing, but for now it's seems to work on our known cases which fail at payment.

Thanks a lot!