/** * {@inheritdoc} */ public function getCurrencyPair(Currency $baseCurrency, Currency $counterCurrency) { $swapCurrencyPair = new SwapCurrencyPair($baseCurrency->getCode(), $counterCurrency->getCode()); try { $rate = $this->swap->quote($swapCurrencyPair); } catch (SwapException $e) { throw UnresolvableCurrencyPairException::createFromCurrencies($baseCurrency, $counterCurrency); } return new CurrencyPair($baseCurrency, $counterCurrency, $rate->getValue()); }
function it_converts_money_using_swap(SwapInterface $swap, Money $money, Money $converted, Currency $from, Currency $to) { $money->getAmount()->willReturn(100); $money->getCurrency()->willReturn($from); $money->multiply(120.3971)->willReturn($converted); $converted->getAmount()->willReturn(12039); $converted->getCurrency()->willReturn($to); $from->__toString()->willReturn('EUR'); $to->__toString()->willReturn('RSD'); $rate = new Rate(120.3971); $swap->quote('EUR/RSD')->shouldBeCalled()->willReturn($rate); $this->convert($money, $to)->getAmount()->shouldBe(12039); }
/** * It returns a quote from given currency to USD. */ public function getQuote(Request $request, SwapInterface $swap) { $currency = strtoupper($request->input('currency')); return $swap->quote("{$currency}/USD")->getValue(); }