diff --git a/src/Processor.php b/src/Processor.php index 913909a..f09b1c5 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, + $exception + ); + + throw $exception; + } } $line->set_total_amount( new Money( $value, $currency ) );