Ejemplo n.º 1
0
 protected function saveCached(\Money\CurrencyPair $pair)
 {
     if ($this->cache) {
         $cacheKey = $this->getCacheKey($pair->getCounterCurrency(), $pair->getBaseCurrency());
         $this->cache->save($cacheKey, $pair, self::CACHE_LIFETIME);
     }
 }
Ejemplo n.º 2
0
 /**
  * @param Money\Money $money
  * @return Mone\Money
  */
 public function convert(Money\Money $money)
 {
     if (!isset($this->currencyPair)) {
         $from = new Money\Currency($this->from == 'XBT' ? 'BTC' : $this->from);
         $to = new Money\Currency($this->to == 'XBT' ? 'BTC' : $this->to);
         $this->currencyPair = new Money\CurrencyPair($from, $to, $this->getRatio());
     }
     return $this->currencyPair->convert($money);
 }
 public function convert(Money $money, $currency)
 {
     if (!$currency instanceof Currency) {
         $currency = new Currency($currency);
     }
     if ($money->getCurrency()->equals($currency)) {
         return $money;
     }
     $rates = $this->getRates($money->getCurrency());
     if (!isset($rates[$currency->getName()])) {
         throw new RuntimeException(sprintf('Could not get rate for currency %s', $currency->getName()));
     }
     $pair = new CurrencyPair($money->getCurrency(), $currency, $rates[$currency->getName()]);
     return $pair->convert($money);
 }
Ejemplo n.º 4
0
 public function testConstructorWithMoney()
 {
     $price = new Price([Money::EUR(5), Money::USD(10), Money::GBP(10), 'TRY' => 120], [CurrencyPair::createFromIso('USD/CHF 1.5'), CurrencyPair::createFromIso('USD/AWG 1.0')]);
     $this->assertInstanceOf('Leaphly\\Price\\Price', $price);
     $this->assertEquals(15, $price->getAmount('CHF'));
 }
Ejemplo n.º 5
0
 /**
  * @inheritdoc
  */
 public function convert(Money $amount, $currencyCode)
 {
     $ratio = $this->getRelativeRatio($amount->getCurrency()->getName(), $currencyCode);
     $pair = new CurrencyPair($amount->getCurrency(), new Currency($currencyCode), $ratio);
     return $pair->convert($amount);
 }
Ejemplo n.º 6
0
 /**
  * @expectedException InvalidArgumentException
  * @expectedExceptionMessage The Money has the wrong currency
  */
 public function testConvertWithInvalidCurrency()
 {
     $money = new Money(100, CurrencyProxy::determine('JPY'));
     $pair = new CurrencyPair(CurrencyProxy::determine('EUR'), CurrencyProxy::determine('USD'), 1.25);
     $pair->convert($money);
 }
Ejemplo n.º 7
0
 /** @test */
 public function ParsesIso()
 {
     $pair = CurrencyPair::createFromIso('EUR/USD 1.2500');
     $expected = new CurrencyPair(new Currency('EUR'), new Currency('USD'), 1.25);
     $this->assertEquals($expected, $pair);
 }
Ejemplo n.º 8
0
 /**
  * @expectedException \Money\InvalidArgumentException
  * @expectedExceptionMessage The Money has the wrong currency
  */
 public function testConvertWithInvalidCurrency()
 {
     $money = new Money(100, new Currency('JPY'));
     $pair = new CurrencyPair(new Currency('EUR'), new Currency('USD'), 1.25);
     $pair->convert($money);
 }