Example #1
0
 /**
  * {@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());
 }
Example #2
0
 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);
 }
Example #3
0
 /**
  * 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();
 }