/** * {@inheritdoc} */ public function convertAndFormatAmount($amount, $currencyCode = null, $locale = null) { if (null !== $currencyCode) { $amount = $this->currencyConverter->convertFromBase($amount, $currencyCode); } return $this->moneyHelper->formatAmount($amount, $currencyCode, $locale); }
function it_executes_request(InvoiceNumberGeneratorInterface $invoiceNumberGenerator, CurrencyConverterInterface $currencyConverter, Convert $request, PaymentInterface $payment, OrderInterface $order, OrderItemInterface $orderItem, ProductVariantInterface $productVariant, ProductInterface $product) { $request->getTo()->willReturn('array'); $payment->getId()->willReturn(19); $order->getId()->willReturn(92); $order->getId()->willReturn(92); $order->getCurrencyCode()->willReturn('PLN'); $order->getTotal()->willReturn(22000); $order->getItems()->willReturn([$orderItem]); $order->getAdjustmentsTotalRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->willReturn(0); $order->getOrderPromotionTotal()->willReturn(0); $order->getShippingTotal()->willReturn(2000); $orderItem->getVariant()->willReturn($productVariant); $orderItem->getDiscountedUnitPrice()->willReturn(20000); $orderItem->getQuantity()->willReturn(1); $productVariant->getProduct()->willReturn($product); $product->getName()->willReturn('Lamborghini Aventador Model'); $request->getSource()->willReturn($payment); $payment->getOrder()->willReturn($order); $invoiceNumberGenerator->generate($order, $payment)->willReturn('19-92'); $currencyConverter->convertFromBase(22000, 'PLN')->willReturn(88000); $currencyConverter->convertFromBase(20000, 'PLN')->willReturn(80000); $currencyConverter->convertFromBase(2000, 'PLN')->willReturn(8000); $details = ['PAYMENTREQUEST_0_INVNUM' => '19-92', 'PAYMENTREQUEST_0_CURRENCYCODE' => 'PLN', 'PAYMENTREQUEST_0_AMT' => 880.0, 'PAYMENTREQUEST_0_ITEMAMT' => 880.0, 'L_PAYMENTREQUEST_0_NAME0' => 'Lamborghini Aventador Model', 'L_PAYMENTREQUEST_0_AMT0' => 800.0, 'L_PAYMENTREQUEST_0_QTY0' => 1, 'L_PAYMENTREQUEST_0_NAME1' => 'Shipping Total', 'L_PAYMENTREQUEST_0_AMT1' => 80.0, 'L_PAYMENTREQUEST_0_QTY1' => 1]; $request->setResult($details)->shouldBeCalled(); $this->execute($request); }
/** * {@inheritDoc} */ protected function composeDetails(PaymentInterface $payment, TokenInterface $token) { if ($payment->getDetails()) { return; } $order = $payment->getOrder(); $total = $this->currencyConverter->convert($order->getTotal(), $order->getCurrency()); $payment->setDetails(array('amount' => round($total / 100, 2), 'currency' => $order->getCurrency())); }
/** * {@inheritdoc} */ public function convertAndFormatAmount($amount, $currencyCode = null, $exchangeRate = null, $locale = null) { if (null !== $currencyCode && $exchangeRate !== null) { $amount = (int) round($amount * $exchangeRate); } if (null !== $currencyCode && $exchangeRate === null) { $amount = $this->currencyConverter->convertFromBase($amount, $currencyCode); } return $this->moneyHelper->formatAmount($amount, $currencyCode, $locale); }
/** * {@inheritDoc} */ protected function composeDetails(PaymentInterface $payment, TokenInterface $token) { if ($payment->getDetails()) { return; } $order = $payment->getOrder(); $this->payment->execute($obtainCreditCardRequest = new ObtainCreditCardRequest($order)); $creditCard = $obtainCreditCardRequest->getCreditCard(); $total = $this->currencyConverter->convert($order->getTotal(), $order->getCurrency()); $payment->setDetails(array('card' => new SensitiveValue(array('number' => $creditCard->getNumber(), 'expiryMonth' => $creditCard->getExpiryMonth(), 'expiryYear' => $creditCard->getExpiryYear(), 'cvv' => $creditCard->getSecurityCode())), 'amount' => round($total / 100, 2), 'currency' => $order->getCurrency())); }
function it_allows_to_convert_and_format_prices_in_different_currencies(CurrencyContextInterface $currencyContext, CurrencyConverterInterface $converter, MoneyFormatterInterface $moneyFormatter) { $currencyContext->getCurrencyCode()->willReturn('PLN'); $converter->convertFromBase(15, 'USD')->willReturn(19); $converter->convertFromBase(2500, 'USD')->willReturn(1913); $converter->convertFromBase(312, 'PLN')->willReturn(407); $converter->convertFromBase(500, 'PLN')->willReturn(653); $moneyFormatter->format(19, 'USD')->willReturn('$0.19'); $moneyFormatter->format(1913, 'USD')->willReturn('$19.13'); $moneyFormatter->format(407, 'PLN')->willReturn('4.07 zł'); $moneyFormatter->format(653, 'PLN')->willReturn('6.53 zł'); $this->convertAndFormatAmount(15, 'USD')->shouldReturn('$0.19'); $this->convertAndFormatAmount(2500, 'USD')->shouldReturn('$19.13'); $this->convertAndFormatAmount(312, 'PLN')->shouldReturn('4.07 zł'); $this->convertAndFormatAmount(500)->shouldReturn('6.53 zł'); }
function it_converts_money_using_given_currency_and_locale(CurrencyConverterInterface $currencyConverter, MoneyHelperInterface $moneyHelper) { $currencyConverter->convertFromBase(500, 'USD')->willReturn(250); $moneyHelper->formatAmount(250, 'USD', 'fr_FR')->willReturn('$2.50'); $this->convertAndFormatAmount(500, 'USD', 'fr_FR')->shouldReturn('$2.50'); }
/** * Convert amount and format it! * * @param int $amount * @param string|null $currency * @param bool $decimal * * @return string */ public function convertAndFormatAmount($amount, $currency = null, $decimal = false) { $currency = $currency ?: $this->currencyContext->getCurrency(); $amount = $this->converter->convertFromBase($amount, $currency); return $this->moneyHelper->formatAmount($amount, $currency, $decimal); }
/** * @param int $price * @param string $currencyCode * * @return float */ private function convertAndFormatPrice($price, $currencyCode) { return round($this->currencyConverter->convertFromBase($price, $currencyCode) / 100, 2); }
/** * {@inheritdoc} */ public function convertAmount($amount, $sourceCurrencyCode, $targetCurrencyCode) { return $this->currencyConverter->convert($amount, $sourceCurrencyCode, $targetCurrencyCode); }
/** * @param int $price * @param string $currencyCode * * @return int */ private function convertPrice($price, $currencyCode) { return $this->currencyConverter->convertFromBase($price, $currencyCode); }
function it_converts_and_formats_money_using_default_locale_if_not_given(CurrencyConverterInterface $currencyConverter) { $currencyConverter->convert(500, 'USD', 'CAD')->willReturn(250); $this->convertAmount(500, 'USD', 'CAD')->shouldReturn(250); }
function it_converts_money_using_given_currency_and_exchange_rate(CurrencyConverterInterface $currencyConverter, MoneyHelperInterface $moneyHelper) { $currencyConverter->convertFromBase(Argument::cetera())->shouldNotBeCalled(); $moneyHelper->formatAmount(300, 'GBP', null)->willReturn('£3.00'); $this->convertAndFormatAmount(100, 'GBP', 3.0)->shouldReturn('£3.00'); }
/** * {@inheritdoc} */ public function convertAndFormatAmount($amount, $currencyCode = null) { $currencyCode = $currencyCode ?: $this->currencyContext->getCurrencyCode(); $amount = $this->currencyConverter->convertFromBase($amount, $currencyCode); return $this->moneyFormatter->format($amount, $currencyCode); }