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

Checkout validation for other fields #861

Closed
Mte90 opened this issue Sep 23, 2022 · 12 comments
Closed

Checkout validation for other fields #861

Mte90 opened this issue Sep 23, 2022 · 12 comments
Labels
enhancement New feature or request support Support case
Milestone

Comments

@Mte90
Copy link

Mte90 commented Sep 23, 2022

Describe the Bug

I have a plugin (that we sell too) that add new fields in the checkout.
Right now for the validation I am doing it by php as there is an AJAX request so with other gateway everything works fine because this AJAX request is executed.

Instead this plugin does it only by pure JS so the AJAX validation is not happening at all breaking the UX and also backward compatibility like in our case and I guess also for others.

if (PayPalCommerceGateway.basic_checkout_validation_enabled) {

So how I was should be able to add support for this plugin anyway? I need the AJAX request woocommerce (wc-ajax=checkout) as I can't do it by JS because I do also validations to external services...

I wasn't able to find any documentation and so on. Maybe there is some field validation happening after the payment for user cases like mine?

@Mte90
Copy link
Author

Mte90 commented Sep 26, 2022

Seems part of #513

Also https://github.com/woocommerce/woocommerce-paypal-payments/wiki/Actions-and-Filters doesn't mention how to add fields for validations.

The filter:

add_filter( 'woocommerce_paypal_payments_basic_checkout_validation_enabled', '__return_false' ); just disable the JS system but the validation it will be only after the Paypal payment.

@dademaru
Copy link

dademaru commented Oct 19, 2022

Hi @Mte90, I've opened a similar issue (#813) with some screenshots to show how the problem already occurs for the WC fields themselves. Also in our case we add custom fields and custom validations, using WC hooks.
For now as a temporary solution we have reverted to PayPal Checkout, which, although no longer supported, gives no problems with validation.

I've also tried to talk with PayPal Tech Support (even with an Integration Engineer) but with no success so far…

Thank you for adding more details.
I hope that if enough of us report the problem, it will be taken into consideration.

@InpsydeNiklas
Copy link
Member

It is currently not possible to perform the WooCommerce validation on the button click. For compatibility reasons, it has to happen after the PayPal order was created.
The payment is only captured after a successful validation, in any case.

But the basic validation only triggers on fields with the validate-required class. Adding this class should be the easiest way to make the basic validation trigger on your own custom fields. But the integration still wouldn't know whether the provided input is valid or not.

@Mte90
Copy link
Author

Mte90 commented Oct 19, 2022

So this means that this official plugin is pushed to all the Woocommerce users but it is not possible for other plugins to add support to validate fields, just because this plugin alter the whole woocommerce checkout experience.

Very sad but is a problem for the people outside Automattic that does business with that.

@InpsydeNiklas
Copy link
Member

@Mte90 The next update later this month replaces the basic validation with this #942.
A test package can be downloaded from here.
Feedback about whether or not this resolves the issue for your application would be appreciated. Thanks!

@Mte90
Copy link
Author

Mte90 commented Nov 7, 2022

Cool but I don't have anymore a test environment. I used a customer one in production (I know) as this plugin requires to you for testing a paypal account also if you are working locally.

@InpsydeNiklas
Copy link
Member

You could also send the team a private message from here: https://paypal.inpsyde.com/docs/request-support/
We could then share sandbox account credentials with you or also give it a try with your plugin, if you share a copy.
In any case, please include a link to this issue when sending a private message.
Thanks!

@Apfelbiss
Copy link

Apfelbiss commented Nov 22, 2022

@Mte90 The next update later this month replaces the basic validation with this #942. A test package can be downloaded from here. Feedback about whether or not this resolves the issue for your application would be appreciated. Thanks!

For me, version 2.0.0 doesn't change anything.

The built-in checkbox for Terms and Conditions is validated correctly (the PayPal popup opens for a second, then it closes and the checkout page scrolls up to the error message which says that the checkbox is required).

But a custom checkbox is added for Data Privacy Regulations via this snippet, that is not validated when a PayPal Payments option is chosen:
https://themeskills.com/add-privacy-checkbox-gdpr-woocoommerce-checkout/

We have got also some products that can't be shipped to all countries, therefore we are using the plugin "Advanced Shipping Validation for WooCommerce", which also doesn't work when a PayPal Payments option is chosen:
https://wordpress.org/support/topic/no-validation-check-with-paypal-checkout/

Is it possible to get this fixed soon?

Edit:
With this Snippet, at least the Data Privacy checkbox is validated in combination with PayPal Payments. But for Advanced SHipping Validation it still doesn't work.

@InpsydeNiklas
Copy link
Member

The terms & conditions checkbox behavior when the Germanized plugin is enabled should be resolved in #1016 or with this test package.
Supporting plugins like Advanced Shipping Validation may be a bit more tricky, but the team will investigate what could be done about it (internal ref#1003).

@Sirvijver
Copy link
Collaborator

Hello all,

this issue should have been resolved after yesterday's release (2.0.1). Please update the plugin and see if it now functions correctly. Since we only handle development activities via GitHub I will ask you to reach out to the support team directly for more guidance in case the issue is still not resolved for you. For now, I will close this thread.

Kind regards,
Joost

@Sirvijver Sirvijver added the support Support case label Dec 14, 2022
@Dinamiko Dinamiko added this to the 2.0.3 milestone Feb 21, 2023
@Dinamiko Dinamiko added the enhancement New feature or request label Feb 21, 2023
@Mte90
Copy link
Author

Mte90 commented Aug 8, 2023

I am still getting issues reported with this plugin using mine that was working with the native woocommerce paypal payments.

I use those filters for fields validation:

  • woocommerce_checkout_process
  • woocommerce_checkout_update_order_meta

I created a function to get the values from AJAX or from a classic request:

function wfi_get_post_data( $var, $default = '' ) {
	if ( isset( $_POST[ $var ] ) ) {
		return esc_html( sanitize_text_field( $_POST[ $var ] ) ); // Input var okay.
	} else {
		if ( !isset( $_POST[ 'post_data' ] ) ) {
			return $default;
		}

		parse_str( sanitize_text_field( wp_unslash( $_POST[ 'post_data' ] ) ), $ajax_checkout ); // Input var okay.
		if ( isset( $ajax_checkout[ $var ] ) ) {
			return esc_html( sanitize_text_field( $ajax_checkout[ $var ] ) );
		}
	}

	return $default;
}

Later I use wc_add_notice(__('SSN is empty.', WFI_TEXTDOMAIN), 'error'); to add notice based on those data.
So I have some doubts about the execution of those hooks or that those POST data are not available on checkout AJAX request.

@InpsydeNiklas
Copy link
Member

Hi @Mte90
The hook woocommerce_checkout_process is called only after creating the PayPal order, so it would not be taken into account when clicking the PayPal button with the early WC validation.

Alternatively, the hook woocommerce_after_checkout_validation could be used, as validate_checkout is called before opening the popup window.

If such a change is not a viable solution for you, then please get in touch with the support team with a download link to your plugin and we would be happy to investigate what it would take to potentially improve the compatibility. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request support Support case
Projects
None yet
Development

No branches or pull requests

6 participants