/**
  * {@inheritdoc}
  *
  * @throws InvalidArgumentException
  *
  * @return int|null
  */
 public function filter($value)
 {
     if (null === $value || is_string($value) && strlen($value) === 0) {
         return null;
     }
     return Money::stringToUnits($value);
 }
Ejemplo n.º 2
0
 /**
  * @param SimpleXMLElement $statementXml
  * @param Statement $statement
  */
 private function addEntriesToStatement(SimpleXMLElement $statementXml, Statement $statement)
 {
     $index = 0;
     $entriesXml = $statementXml->Ntry;
     foreach ($entriesXml as $entryXml) {
         $amount = Money::stringToUnits((string) $entryXml->Amt);
         $currency = (string) $entryXml->Amt['Ccy'];
         $bookingDate = (string) $entryXml->BookgDt->Dt;
         $valueDate = (string) $entryXml->ValDt->Dt;
         if ((string) $entryXml->CdtDbtInd === 'DBIT') {
             $amount = $amount * -1;
         }
         $entry = new Entry($statement, $index, new Money($amount, new Currency($currency)), new DateTimeImmutable($bookingDate), new DateTimeImmutable($valueDate));
         if (isset($entryXml->RvslInd) && (string) $entryXml->RvslInd === 'true') {
             $entry->setReversalIndicator(true);
         }
         if (isset($entryXml->NtryRef) && (string) $entryXml->NtryRef) {
             $entry->setReference((string) $entryXml->NtryRef);
         }
         if (isset($entryXml->NtryDtls->Btch->PmtInfId) && (string) $entryXml->NtryDtls->Btch->PmtInfId) {
             $entry->setBatchPaymentId((string) $entryXml->NtryDtls->Btch->PmtInfId);
         }
         $this->addTransactionDetailsToEntry($entryXml, $entry);
         $statement->addEntry($entry);
         $index++;
     }
 }
Ejemplo n.º 3
0
 /**
  * @param \Money\Money|string $amount
  * @param \Money\Currency|string $from
  * @param \Money\Currency|string $to
  * @return \Money\Money
  */
 public function convert($amount, $from, $to)
 {
     if ($from instanceof Currency == false) {
         $from = new Currency(strtoupper($from));
     }
     if ($to instanceof Currency == false) {
         $to = new Currency(strtoupper($to));
     }
     if ($amount instanceof Money == false) {
         $money = new Money(Money::stringToUnits($amount), $from);
     } else {
         $money = $amount;
     }
     $pair = $this->fetchCached($from, $to);
     if ($pair == null) {
         $pair = $this->provider->getCurrencyPair($from, $to);
         $this->saveCached($pair);
     }
     $converted = $pair->convert($money);
     return $converted;
 }
Ejemplo n.º 4
0
 /**
  * @dataProvider provideStrings
  */
 public function testStringToUnits($string, $units)
 {
     $this->assertEquals($units, Money::stringToUnits($string));
 }
Ejemplo n.º 5
0
 /**
  * @expectedException \Money\InvalidArgumentException
  */
 public function testInvalidStringToUnit()
 {
     Money::stringToUnits('This should be an invalid string');
 }
Ejemplo n.º 6
0
 public function testStringToUnits()
 {
     foreach ($this->moneystrings() as $array) {
         $this->assertEquals($array[1], Money::stringToUnits($array[0]));
     }
 }
Ejemplo n.º 7
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testInvalidStringToUnits()
 {
     Money::stringToUnits('invalid units');
 }