mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Add email validation like in WC to fix confusing error message
This commit is contained in:
parent
fdbbe6afb3
commit
da539ed578
1 changed files with 10 additions and 0 deletions
|
@ -15,6 +15,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\PayerName;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PayerTaxInfo;
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\PayerTaxInfo;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Phone;
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\Phone;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PhoneWithType;
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\PhoneWithType;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class PayerFactory
|
* Class PayerFactory
|
||||||
|
@ -158,6 +159,7 @@ class PayerFactory {
|
||||||
*
|
*
|
||||||
* @param array $form_fields The checkout form fields.
|
* @param array $form_fields The checkout form fields.
|
||||||
* @return Payer
|
* @return Payer
|
||||||
|
* @throws RuntimeException When invalid data.
|
||||||
*/
|
*/
|
||||||
public function from_checkout_form( array $form_fields ): Payer {
|
public function from_checkout_form( array $form_fields ): Payer {
|
||||||
|
|
||||||
|
@ -189,6 +191,14 @@ class PayerFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! is_email( $billing_email ) ) {
|
||||||
|
/*
|
||||||
|
phpcs:disable WordPress.WP.I18n.TextDomainMismatch
|
||||||
|
translators: %s: email address
|
||||||
|
*/
|
||||||
|
throw new RuntimeException( sprintf( __( '%s is not a valid email address.', 'woocommerce' ), esc_html( $billing_email ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
return new Payer(
|
return new Payer(
|
||||||
new PayerName( $first_name, $last_name ),
|
new PayerName( $first_name, $last_name ),
|
||||||
$billing_email,
|
$billing_email,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue