From 690e80e86bce7274a1d8240186ee42e3ecc8bdd9 Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Tue, 28 May 2024 11:22:42 +0200 Subject: [PATCH 1/2] Update Processor.php --- src/Processor.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Processor.php b/src/Processor.php index 913909a..2e67c20 100644 --- a/src/Processor.php +++ b/src/Processor.php @@ -12,6 +12,7 @@ use GFCommon; use Pronamic\WordPress\Number\Number; +use Pronamic\WordPress\Number\Parser as NumberParser; use Pronamic\WordPress\Money\Currency; use Pronamic\WordPress\Money\Money; use Pronamic\WordPress\Pay\AbstractGatewayIntegration; @@ -356,9 +357,24 @@ public function entry_post_save( $lead, $form ) { $line->set_unit_price( new Money( $value, $currency ) ); if ( array_key_exists( 'quantity', $product ) ) { - $quantity = Number::from_mixed( $product['quantity'] ); - - $value = $value->multiply( $quantity ); + try { + $parser = new NumberParser(); + + $quantity = $parser->parse( $product['quantity'] ); + + $value = $value->multiply( $quantity ); + } catch ( \Exception $exception ) { + $exception = new \Exception( + \sprintf( + 'Couldn’t parse Gravity Forms product field `%s` quantity to a number.', + \esc_html( $key ) + ), + 0, + $e + ); + + throw $exception; + } } $line->set_total_amount( new Money( $value, $currency ) ); From c356de07ab8266a6335fe5e691c78b5f276f20d9 Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Tue, 28 May 2024 11:24:55 +0200 Subject: [PATCH 2/2] Update Processor.php --- src/Processor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Processor.php b/src/Processor.php index 2e67c20..f09b1c5 100644 --- a/src/Processor.php +++ b/src/Processor.php @@ -370,7 +370,7 @@ public function entry_post_save( $lead, $form ) { \esc_html( $key ) ), 0, - $e + $exception ); throw $exception;