woocommerce / woocommerce-gateway-stripe

The official Stripe Payment Gateway for WooCommerce
https://wordpress.org/plugins/woocommerce-gateway-stripe/
236 stars 206 forks source link

Cryptic error message from SEPA direct debit when name or email address is missing #3605

Open thuautp opened 1 week ago

thuautp commented 1 week ago

Reported in 8856059-zen

Is your feature request related to a problem? Please describe.

If the email address and/or first name are not filled in, SEPA (direct debit) payers see a cryptic message in the checkout: "Missing required param: billing_details[name]". Image

Describe the solution you'd like

The regular WooCommerce checkout form validation error message for email and first name fields should appear, as with the other payment methods. Image

Describe alternatives you've considered

From the ticket above, the user mentioned:

What our developer found out:

The error message is coming directly from Stripe.com.

This is because the parameter "name" sent to Stripe is empty:

The Stripe plugin is passing first name and last name, if they are set - otherwise a value from a hidden data property: https://github.com/woocommerce/woocommerce-gateway-stripe/blob/develop/assets/js/stripe.js#L485-L491

The hidden data property does not exist on the checkout page in this scenario.

I already tried adding the hidden element stripe-payment-data to the page with a dummy value in the full-name data property, but it did not resolve the issue.

I also tried setting a dummy value for the default value in wc_stripe_params.billing_first_name, but it did not resolve the issue.

The wc_stripe_params actually contain an error message "invalid_owner_name" that is supposed to say "Billing First Name and Last Name are required.", but it is never triggered.

→ It seems the plugin was already trying to correctly handle this case, but it is no longer working in the new UPE checkout and the code in the plugin needs to be updated.

Additional context I can replicate this error message with SEPA on my test site.

sun commented 15 hours ago

Here is the complete original debugging information that we provided including screenshots:

The error message is coming directly from Stripe.com (JS): Image

This is because the parameter "name" sent to Stripe is empty: Image

The Stripe plugin is passing first name and last name, if they are set - otherwise a value from a hidden data property: https://github.com/woocommerce/woocommerce-gateway-stripe/blob/09bac72b1c0953d2eb3610e2cdd3eb374dae5cd7/assets/js/stripe.js#L485-L491

The hidden data property does not exist on the checkout page in this scenario: Image

I already tried adding the hidden element #stripe-payment-data to the page with a dummy value in the full-name data property, but it did not resolve the issue.

I also tried setting a dummy value for the default value in wc_stripe_params.billing_first_name, but it did not resolve the issue.

The wc_stripe_params actually contain an error message "invalid_owner_name" that is supposed to say "Billing First Name and Last Name are required.", but it is never triggered.

→ It seems the plugin was already trying to correctly handle this case, but it is no longer working in the new UPE checkout and the code in the plugin needs to be updated.