Example #1
0
 /**
  *
  * @param string|SimpleXMLElement $content
  *
  * @throws \Exception
  *
  * @return \Realejo\Ofx\Banking\Statement
  */
 public static function parseBankMessage($content)
 {
     // Verifica se é um string
     if (is_string($content)) {
         $content = \Realejo\Ofx\Parser::makeXML($content);
     }
     // Verifica se existe o bloco de Banking
     $BANKMSGSRSV1 = $content->xpath('//BANKMSGSRSV1');
     if (count($BANKMSGSRSV1) == 1) {
         $Statement = new Statement();
         // Verifica se exite a seção do request Banking
         $STMTTRNRQ = $content->xpath('//BANKMSGSRSV1/STMTTRNRQ');
         if (count($STMTTRNRQ) == 1) {
             throw new \Exception('Baking Request Statment not implemented');
         }
         // Verifica se exite a seção do request Banking
         $STMTTRNRS = $content->xpath('//BANKMSGSRSV1/STMTTRNRS');
         if (count($STMTTRNRS) == 1) {
             $STMTTRNRS = $STMTTRNRS[0];
             $response = new StatementResponse();
             // Currency
             $CURDEF = $STMTTRNRS->xpath('//CURDEF');
             if (count($CURDEF) == 1) {
                 $response->currency = $CURDEF[0];
             }
             // Verifica se tem conta do banco
             $BANKACCTFROM = $STMTTRNRS->xpath('//BANKACCTFROM');
             if (count($BANKACCTFROM) == 1) {
                 $response->setBankAccount(self::parseBankAccount($STMTTRNRS));
             }
             // Verifica as transações
             $BANKTRANLIST = $STMTTRNRS->xpath('//BANKTRANLIST');
             if (count($BANKTRANLIST) == 1) {
                 $response->setTransactionList(self::parseTransactions($STMTTRNRS));
             }
             // Verifica Ledger Balance
             $LEDGERBAL = $STMTTRNRS->xpath('//LEDGERBAL');
             if (count($LEDGERBAL) > 0) {
                 $response->setLedgerBalance(self::parseLedgerBalance($STMTTRNRS));
             }
             // Verifica Available Balance
             $AVAILBAL = $STMTTRNRS->xpath('//AVAILBAL');
             if (count($AVAILBAL) > 0) {
                 $response->setAvailableBalance(self::parseAvailableBalance($STMTTRNRS));
             }
             // Grava o response
             $Statement->setResponse($response);
         }
         // end if (count($STMTTRNRS) == 1);
     }
     // end if (count($BANKMSGSRSV1) == 1)
     return $Statement;
 }