diff --git a/modules/ppcp-api-client/src/Factory/PayerFactory.php b/modules/ppcp-api-client/src/Factory/PayerFactory.php index 6bec8fe80..5716d99cc 100644 --- a/modules/ppcp-api-client/src/Factory/PayerFactory.php +++ b/modules/ppcp-api-client/src/Factory/PayerFactory.php @@ -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, diff --git a/modules/ppcp-button/resources/js/modules/ActionHandler/CheckoutActionHandler.js b/modules/ppcp-button/resources/js/modules/ActionHandler/CheckoutActionHandler.js index 625fd369b..733b5e339 100644 --- a/modules/ppcp-button/resources/js/modules/ActionHandler/CheckoutActionHandler.js +++ b/modules/ppcp-button/resources/js/modules/ActionHandler/CheckoutActionHandler.js @@ -20,7 +20,9 @@ class CheckoutActionHandler { const errorHandler = this.errorHandler; const formSelector = this.config.context === 'checkout' ? 'form.checkout' : 'form#order_review'; - const formValues = jQuery(formSelector).serialize(); + const formData = new FormData(document.querySelector(formSelector)); + // will not handle fields with multiple values (checkboxes,