Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not validate checkout form when creating PayPal order #341

Merged
merged 5 commits into from
Nov 4, 2021

Conversation

Dinamiko
Copy link
Contributor

Fixes #335.

Possible cause

We are currently calling WC process_checkout twice, the first time it's called before creating the PayPal order to validate WC checkout form.

This is causing third party plugins not working because they are using woocommerce_after_checkout_validation for validating its own logic and after that cleaning session data on woocommerce_checkout_order_processed, when our plugin calls process_checkout the second time it calls again woocommerce_after_checkout_validation making it fail because there is no session stored available, it was already cleared on woocommerce_checkout_order_processed.

Suggested solution

We can simply skip WC checkout form validation when creating the PayPal order, that's in fact how it works when we create the PayPal order from other pages like Product or Cart.

By not calling process_checkout when creating the PayPal order we are going to probably also fix some of those WC Failed orders because the WC order is going to be created only after PayPal order is created correctly and WC checkout form is validated.

@Dinamiko Dinamiko changed the title Pcp 375 order of woocommerce checkout ac Do not validate checkout form when creating PayPal order Oct 27, 2021
@Dinamiko Dinamiko requested a review from AlexP11223 October 27, 2021 13:37
@AlexP11223
Copy link
Contributor

But what was the reason to call it twice? Is everything still working?

Looks like we do not have WC validation now before creating the order here, is it ok?

@Dinamiko
Copy link
Contributor Author

Dinamiko commented Oct 28, 2021

@AlexP11223

But what was the reason to call it twice?

The reason to call process_checkout the first time I think was only for validating the WC checkout form before creating the PayPal order.

Here is how it currently works;
We call process_checkout the first time here before creating the PayPal order: https://github.com/woocommerce/woocommerce-paypal-payments/blob/trunk/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php#L380
Then after PayPal order is approved we call it again here: https://github.com/woocommerce/woocommerce-paypal-payments/blob/trunk/modules/ppcp-button/resources/js/modules/OnApproveHandler/onApproveForPayNow.js#L25

process_checkout calls validate_checkout internally: https://github.com/woocommerce/woocommerce/blob/3611d4643791bad87a0d3e6e73e031bb80447417/plugins/woocommerce/includes/class-wc-checkout.php#L1161

which defines woocommerce_after_checkout_validation action: https://github.com/woocommerce/woocommerce/blob/3611d4643791bad87a0d3e6e73e031bb80447417/plugins/woocommerce/includes/class-wc-checkout.php#L887

We are not validating WC checkout form when creating the PayPal order on other pages like Single product or Cart, that´s the reason I proposed this solution, it does separate PayPal order creation from WC order creation. It also opens the door for writing our own PayPal specific validation for order creation.

Is everything still working?

For what it tested so far it works, but we´ll need to do more acceptance to ensure nothing is broken for all cases.

Looks like we do not have WC validation now before creating the order here, is it ok?

For creating the PayPal order we are not going to have WC checkout form validation now but it still does validation when creating the WC order:
https://user-images.githubusercontent.com/456223/139224476-f5581fdc-6eec-406e-9a79-d647deab689a.mp4

…ments into PCP-375-order-of-woocommerce-checkout-ac
@Dinamiko Dinamiko merged commit a969ba9 into trunk Nov 4, 2021
@Dinamiko Dinamiko deleted the PCP-375-order-of-woocommerce-checkout-ac branch November 4, 2021 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Order of WooCommerce checkout actions causing incompatibility with AvaTax address validation (375)
2 participants