diff --git a/src/Form/POSForm.php b/src/Form/POSForm.php index 1519c24..9cd4448 100644 --- a/src/Form/POSForm.php +++ b/src/Form/POSForm.php @@ -249,16 +249,11 @@ class POSForm extends ContentEntityForm { $number_formatter = $number_formatter_factory->createInstance(); $order_balance_amount_format = $number_formatter->formatCurrency($order_balance->getNumber(), Currency::load($order_balance->getCurrencyCode())); $keypad_amount = preg_replace('/[^0-9\.,]/', '', $order_balance_amount_format); - // Fetching fraction digit to set as step. - $fraction_digits = $this->currentStore->getStore() - ->getDefaultCurrency() - ->getFractionDigits(); $form['keypad']['amount'] = [ - '#type' => 'number', + '#type' => 'textfield', '#title' => $this->t('Enter @title Amount', [ '@title' => $payment_gateways[$option_id]->label(), ]), - '#step' => pow(0.1, $fraction_digits), '#required' => TRUE, '#default_value' => $keypad_amount, '#commerce_pos_keypad' => TRUE, @@ -444,12 +439,22 @@ class POSForm extends ContentEntityForm { */ public function validatePaymentForm(array $form, FormStateInterface $form_state) { $triggering_element = $form_state->getTriggeringElement(); + if ($triggering_element['#name'] == 'commerce-pos-pay-keypad-add') { $keypad_amount = $form_state->getValue('keypad')['amount']; if (!is_numeric($keypad_amount)) { $form_state->setError($form['keypad']['amount'], $this->t('Payment amount must be a number.')); } + + /** @var int $fraction_digits */ + $fraction_digits = $this->currentStore->getStore() + ->getDefaultCurrency() + ->getFractionDigits(); + list($whole, $decimal) = sscanf($keypad_amount, '%d.%d'); + if (strlen($decimal) > $fraction_digits) { + $form_state->setError($form['keypad']['amount'], $this->t('The amount should be of two digit precision.')); + } } }