You are here

protected function OrderPaymentIntentSubscriber::toMinorUnits in Commerce Stripe 8

Converts the given amount to its minor units.

For example, 9.99 USD becomes 999.

@todo Remove after https://www.drupal.org/node/2944281 is fixed.

Parameters

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

Return value

int The amount in minor units, as an integer.

1 call to OrderPaymentIntentSubscriber::toMinorUnits()
OrderPaymentIntentSubscriber::onOrderUpdate in src/EventSubscriber/OrderPaymentIntentSubscriber.php
Ensures the Stripe payment intent is up to date.

File

src/EventSubscriber/OrderPaymentIntentSubscriber.php, line 122

Class

OrderPaymentIntentSubscriber
Subscribes to order events to syncronize orders with their payment intents.

Namespace

Drupal\commerce_stripe\EventSubscriber

Code

protected function toMinorUnits(Price $amount) {
  $currency_storage = $this->entityTypeManager
    ->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);
}