/** * Converts a Money value object to a string for the database reporting etc * @param \SebastianBergmann\Money\Money $value * @return string */ function convertMoneyToString(Money $value) { return convertIntToString($value->getAmount(), $value->getCurrency()); }
/** * Formats a Money object using PHP's built-in NumberFormatter. * * @param \SebastianBergmann\Money\Money $money * @return string */ public function format(Money $money) { return $this->numberFormatter->formatCurrency($money->getConvertedAmount(), $money->getCurrency()->getCurrencyCode()); }
/** * gets currency name * * @param Money $money * @return null|string */ public function formatCurrencyAsName(Money $money) { return Intl::getCurrencyBundle()->getCurrencyName($money->getCurrency()->getCurrencyCode()); }
/** * {@inheritdoc} */ public function getCurrency() { return $this->valueObject->getCurrency(); }
/** * @return string */ public function Currency() { return $this->value->getCurrency()->getCurrencyCode(); }
/** * @param Money $money * @param Currency $to * @param int $roundingMode * @return Money */ public function convert(Money $money, Currency $to, $roundingMode = PHP_ROUND_HALF_UP) { $new = new Money($money->getAmount(), $to); $conversionRate = $this->source->getRateBetween($money->getCurrency(), $to); return $new->multiply($conversionRate, $roundingMode); }
/** * Converts amount from one currency to another using the currency's identifier * * Warning this method can lose precision! * * @param \SebastianBergmann\Money\Money $amount * @param \Heystack\Core\Identifier\IdentifierInterface $to * @return \SebastianBergmann\Money\Money * @throws \InvalidArgumentException */ public function convert(Money $amount, IdentifierInterface $to) { if (!($toCurrency = $this->getCurrency($to))) { throw new \InvalidArgumentException("Currency not supported"); } /** @var \Heystack\Ecommerce\Currency\Interfaces\CurrencyInterface $fromCurrency */ $fromCurrency = $amount->getCurrency(); return $amount->multiply($toCurrency->getValue() / $fromCurrency->getValue()); }