You are here

protected function PaymentMethodAddForm::toMinorUnits in Commerce Authorize.Net 8

Converts the given amount to its minor units.

This is a copypaste of PaymentGatewayBase::toMinorUnits() until that method is made public.

@todo Remove when https://www.drupal.org/project/commerce/issues/2944281 gets fixed.

Parameters

\Drupal\commerce_price\Price $amount: The amount.

Return value

int The amount in minor units, as an integer.

1 call to PaymentMethodAddForm::toMinorUnits()
PaymentMethodAddForm::buildCreditCardForm in src/PluginForm/AcceptJs/PaymentMethodAddForm.php
Builds the credit card form.

File

src/PluginForm/AcceptJs/PaymentMethodAddForm.php, line 316

Class

PaymentMethodAddForm

Namespace

Drupal\commerce_authnet\PluginForm\AcceptJs

Code

protected function toMinorUnits(Price $amount) {
  $entity_type_manager = \Drupal::service('entity_type.manager');
  $currency_storage = $entity_type_manager
    ->getStorage('commerce_currency');

  /** @var \Drupal\commerce_price\Entity\CurrencyInterface $currency */
  $currency = $currency_storage
    ->load($amount
    ->getCurrencyCode());
  $fraction_digits = $currency
    ->getFractionDigits();
  $number = $amount
    ->getNumber();
  if ($fraction_digits > 0) {
    $number = Calculator::multiply($number, pow(10, $fraction_digits));
  }
  return round($number, 0);
}