Merge pull request #680 from woocommerce/pcp-579-email-validation

Fix form decoding and email handling
This commit is contained in:
Emili Castells 2022-06-14 11:15:53 +02:00 committed by GitHub
commit e9e49fb8f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 14 deletions

View file

@ -15,6 +15,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\PayerName;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PayerTaxInfo;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Phone;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PhoneWithType;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
/**
* Class PayerFactory
@ -158,6 +159,7 @@ class PayerFactory {
*
* @param array $form_fields The checkout form fields.
* @return Payer
* @throws RuntimeException When invalid data.
*/
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(
new PayerName( $first_name, $last_name ),
$billing_email,