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
404 stars 218 forks source link

Can't place an order with Cash of Delivery if it's conditional #9074

Closed senadir closed 1 year ago

senadir commented 1 year ago

Recent PR https://github.com/woocommerce/woocommerce-blocks/pull/8441 changed how we define Checkout payment_method schema for enabled payment methods to available ones to checkout with.

This caused an issue with conditional payment methods like Cash on Delivery which aren't available unless certain conditions are met like selected shipping method, which is only available with a session, but schema generation and validation is sessionless.

Steps to reproduce

senadir commented 1 year ago

This issue only seems to happen if you have more than 1 payment method active, if COD is the only one enabled, enum is an empty array and that skips checking all together?

cc @mikejolley

mikejolley commented 1 year ago

cc @ralucaStan I've marked this as cooldown so it can be picked up.

mikejolley commented 1 year ago

@senadir Gonna need you to come back and help replicate this one. I tested a few combinations here; multiple gateways active, various rules (require flat rate, require pickup). When COD was available on checkout my orders went through ok.

You're incorrect about it being stateless afaik. The enum uses get_available_payment_gateways and this will refer to the current session to determine which gateways are available. So if you have a valid cart, and your session is up to date, the request to the server will succeed.

Can you take another look?

senadir commented 1 year ago

It seems the error only surfaces if Accept COD if the order is virtual is off.

You're incorrect about it being stateless afaik. The enum uses get_available_payment_gateways and this will refer to the current session to determine which gateways are available. So if you have a valid cart, and your session is up to date, the request to the server will succeed.

This might not always use a session, hitting OPTIONS endpoint will use session, this is where I found the COD to be missing.

is Schema validation happening before session is loaded?

mikejolley commented 1 year ago

This came up in zendesk—I'll add it to my list to tackle before next release.