woocommerce / woocommerce-blocks

(Deprecated) This plugin has been merged into woocommerce/woocommerce
https://wordpress.org/plugins/woo-gutenberg-products-block/
GNU General Public License v3.0
403 stars 218 forks source link

Checkout blocks: Potential conflict with Authorize.Net gateway #8504

Closed kaushikasomaiya closed 1 year ago

kaushikasomaiya commented 1 year ago

5977707-zen

Authorize.Net gateway seems to be setting null value on states for countries that don't have states:

    public function tweak_states( $countries ) {

        foreach ( $countries as $country_code => $states ) {

            if ( is_array( $countries[ $country_code ] ) && empty( $countries[ $country_code ] ) ) {
                $countries[ $country_code ] = null;
            }
        }

        return $countries;
    }

This is to remove blank states from some countries such as AF.

This is conflicting with Checkout Blocks and causing a fatal error:

Fatal error: Uncaught TypeError: html_entity_decode(): Argument woocommerce/woocommerce-blocks#12058 ($string) must be of type string, array given in /Applications/MAMP/htdocs/woogenerator/sites/wp-5223712/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/BlockTypes/Checkout.php:372

The line here seems to be skipped due to null state value:

https://github.com/woocommerce/woocommerce-blocks/blob/f4ab91e00c307c798c05870ed427cc53b9e6818e/src/BlockTypes/Checkout.php#L368

Can this be called a conflict on Authorize.Net's side? or on WooCommerce Blocks?

nielslange commented 1 year ago

Hello @kaushikasomaiya 👋

Thanks for reaching out! According to https://github.com/woocommerce/woocommerce/issues/42577 and https://woocommerce.com/document/cart-checkout-blocks-support-status/#section-4, the Authorize.Net payment gateway does not provide support for WooCommerce Blocks yet.

Can this be called a conflict on Authorize.Net's side?

As it's up to the payment service provider to make the extension compatible with WooCommerce Blocks, I'd say the conflict is on their end. We have some documentation for Third-party developers and some Developer Resources available to help with their integration efforts.

I'll close this issue for now, but I suggest keeping an eye on https://woocommerce.com/document/cart-checkout-blocks-support-status/#section-4 where we list payment extensions that are compatible with WooCommerce Blocks.

kaushikasomaiya commented 1 year ago

Hey @nielslange Thanks for the feedback. :)

That makes sense.

I am wondering if this issue will arise irrespective of the compatibility with checkout block.

For example, if any plugin (not necessarily a payment gateway) sets the State value to null - this will skip the checkout blocks line below and pass an array to html_entity_decode() https://github.com/woocommerce/woocommerce-blocks/blob/f4ab91e00c307c798c05870ed427cc53b9e6818e/src/BlockTypes/Checkout.php#L368

Ref: https://github.com/woocommerce/woocommerce-blocks/pull/6896

Or is it that the state value should not* be set null by plugins? (for countries not having any states like AF).

kaushikasomaiya commented 1 year ago

CC: @nielslange @senadir as one more case here: 6024606-zen. Just wanted to get feedback on my theory in comment above. :)

senadir commented 1 year ago

Thank you @kaushikasomaiya I agree that we should be more defensive regardless of plugin compatibility. I'm trying to remember if null is a valid value or not, I know that "" is a valid value.