Example #1
0
 /**
  * @param string|SimpleXMLElement $content
  *
  * @return \Realejo\Ofx\SignOn
  */
 public static function parse($content)
 {
     // Verifica se é um string
     if (is_string($content)) {
         $content = \Realejo\Ofx\Parser::makeXML($content);
     }
     $SignOn = new SignOn();
     // Verifica se existe o bloco de SignOn
     $SIGNONMSGSRSV1 = $content->xpath('//SIGNONMSGSRSV1');
     if (count($SIGNONMSGSRSV1) == 1) {
         // Verifica se exite a seção do request Signon
         $SONRQ = $content->xpath('//SIGNONMSGSRSV1/SONRQ');
         if (count($SONRQ) == 1) {
             throw new \Exception('Signon request not implemented');
         }
         // Verifica se exite a seção do response Signon
         $SONRS = $content->xpath('//SIGNONMSGSRSV1/SONRS');
         if (count($SONRS) == 1) {
             $SONRS = $SONRS[0];
             $response = new SignOnResponse();
             $response->statusCode = (int) $SONRS->STATUS->CODE;
             $response->statusSeverity = $SONRS->STATUS->SEVERITY;
             $response->date = \Realejo\Ofx\Parser::parseDate($SONRS->DTSERVER);
             $response->language = $SONRS->LANGUAGE;
             $response->fiOrganization = $SONRS->FI->ORG;
             $response->fiUniqueId = $SONRS->FI->FID;
             $SignOn->setResponse($response);
         }
         // end if (count($SONRS) == 1)
     }
     //end if (count($SIGNONMSGSRSV1) == 1)
     return $SignOn;
 }
Example #2
0
 public function testParseDate()
 {
     $this->assertNull($this->Parser->parseDate(null));
     $this->assertNull($this->Parser->parseDate(''));
     $this->assertInstanceOf('DateTime', $this->Parser->parseDate('20141031120000[-3:BRT]'));
     $this->assertEquals('2014-10-31', $this->Parser->parseDate('20141031120000[-3:BRT]')->format('Y-m-d'));
     $this->assertEquals('2014-10-31', $this->Parser->parseDate('20141031120000')->format('Y-m-d'));
     $this->assertEquals('2014-10-31', $this->Parser->parseDate('20141031[-3:BRT]')->format('Y-m-d'));
     $this->assertEquals('2014-10-31', $this->Parser->parseDate('20141031')->format('Y-m-d'));
     $this->assertEquals('12:00:00', $this->Parser->parseDate('20141031120000[-3:BRT]')->format('h:i:s'));
     $this->assertEquals('12:00:00', $this->Parser->parseDate('20141031120000[-3:BRT]')->format('H:i:s'));
     $this->assertEquals('12:00:00', $this->Parser->parseDate('20141031120000')->format('h:i:s'));
     $this->assertEquals('12:00:00', $this->Parser->parseDate('20141031120000')->format('H:i:s'));
     $this->assertEquals('12:00:00', $this->Parser->parseDate('20141031120000.1234[-3:BRT]')->format('H:i:s'));
     $this->assertEquals('12:00:00', $this->Parser->parseDate('20141031120000.1234')->format('H:i:s'));
 }
Example #3
0
 /**
  * @param string|SimpleXMLElement $content
  *
  * @return \Realejo\Ofx\Banking\Statement
  */
 public static function parse($content)
 {
     // Verifica se é um string
     if (is_string($content)) {
         $content = \Realejo\Ofx\Parser::makeXML($content);
     }
     $Statement = new Statement();
     // Verifica se exite a seção do Signon
     $request = $content->xpath('//SIGNONMSGSRSV1/SONRQ');
     $SONRS = $content->xpath('//SIGNONMSGSRSV1/SONRS');
     if (count($SONRS) == 1) {
         $SONRS = $SONRS[0];
         $response = new StatementResponse();
         $response->statusCode = (int) $SONRS->STATUS->CODE;
         $response->statusSeverity = $SONRS->STATUS->SEVERITY;
         $response->date = \Realejo\Ofx\Parser::parseDate($SONRS->DTSERVER);
         $response->language = $SONRS->LANGUAGE;
         $response->fiOrganization = \Realejo\Ofx\Parser::parseDate($SONRS->FI->ORG);
         $response->fiUniqueId = \Realejo\Ofx\Parser::parseDate($SONRS->FI->FID);
         $Statement->setResponse($response);
     }
     return $Statement;
 }
Example #4
0
 /**
  *
  * @param string|SimpleXMLElement $content
  *
  * @return \Realejo\Ofx\Banking\Balance
  */
 public static function parseAvailableBalance($content)
 {
     // Verifica se é um string
     if (is_string($content)) {
         $content = \Realejo\Ofx\Parser::makeXML($content);
     }
     $balance = new Balance();
     $AVAILBAL = $content->xpath('//AVAILBAL');
     if (count($AVAILBAL) > 0) {
         $AVAILBAL = $AVAILBAL[0];
         $balance->amount = isset($AVAILBAL->BALAMT) ? (double) $AVAILBAL->BALAMT : null;
         $balance->dateAsOf = isset($AVAILBAL->DTASOF) ? OfxParser::parseDate($AVAILBAL->DTASOF) : null;
     }
     // end if (count($AVAILBAL) == 1)
     return $balance;
 }
Example #5
0
 /**
  * Tests SignOn::parse()
  */
 public function testParseResponse()
 {
     $xml = '<OFX>
               <SIGNONMSGSRSV1>
                 <SONRS>
                   <STATUS>
                     <CODE>0</CODE>
                     <SEVERITY>INFO</SEVERITY>
                   </STATUS>
                   <DTSERVER>20141230120000[-3:BRT]</DTSERVER>
                   <LANGUAGE>POR</LANGUAGE>
                   <FI>
                     <ORG>Banco do Brasil</ORG>
                       <FID>1</FID>
                   </FI>
                 </SONRS>
               </SIGNONMSGSRSV1>
             </OFX>';
     $signon = SignOn::parse($xml);
     $this->assertInstanceOf('\\Realejo\\Ofx\\SignOn', $signon);
     $this->assertInstanceOf('\\Realejo\\Ofx\\SignOn\\Response', $signon->getResponse());
     $this->assertNull($signon->getRequest());
     $this->assertNotNull($signon->getResponse()->statusCode);
     $this->assertEquals(0, $signon->getResponse()->statusCode);
     $this->assertEquals('INFO', $signon->getResponse()->statusSeverity);
     $this->assertEquals('2014-12-30', $signon->getResponse()->date->format('Y-m-d'));
     $this->assertEquals('POR', $signon->getResponse()->language);
     $this->assertEquals('Banco do Brasil', $signon->getResponse()->fiOrganization);
     $this->assertEquals('1', $signon->getResponse()->fiUniqueId);
     $xml = \Realejo\Ofx\Parser::makeXML($xml);
     // Os mesmos testes acima
     $signon = SignOn::parse($xml);
     $this->assertInstanceOf('\\Realejo\\Ofx\\SignOn', $signon);
     $this->assertInstanceOf('\\Realejo\\Ofx\\SignOn\\Response', $signon->getResponse());
     $this->assertNull($signon->getRequest());
     $this->assertNotNull($signon->getResponse()->statusCode);
     $this->assertEquals(0, $signon->getResponse()->statusCode);
     $this->assertEquals('INFO', $signon->getResponse()->statusSeverity);
     $this->assertEquals('2014-12-30', $signon->getResponse()->date->format('Y-m-d'));
     $this->assertEquals('POR', $signon->getResponse()->language);
     $this->assertEquals('Banco do Brasil', $signon->getResponse()->fiOrganization);
     $this->assertEquals('1', $signon->getResponse()->fiUniqueId);
     // Testes com XML invalido
     // SEM OFX
     $xml = '
               <SIGNONMSGSRSV1>
                 <SONRS>
                   <STATUS>
                     <CODE>0</CODE>
                     <SEVERITY>INFO</SEVERITY>
                   </STATUS>
                   <DTSERVER>20141230120000[-3:BRT]</DTSERVER>
                   <LANGUAGE>POR</LANGUAGE>
                   <FI>
                     <ORG>Banco do Brasil</ORG>
                       <FID>1</FID>
                   </FI>
                 </SONRS>
               </SIGNONMSGSRSV1>
             ';
     $signon = SignOn::parse($xml);
     $this->assertInstanceOf('\\Realejo\\Ofx\\SignOn', $signon);
     $this->assertInstanceOf('\\Realejo\\Ofx\\SignOn\\Response', $signon->getResponse());
     $this->assertNull($signon->getRequest());
     // Testes com XML invalido
     // SEM OFX e SIGNONMSGSRSV1
     $xml = '
                 <SONRS>
                   <STATUS>
                     <CODE>0</CODE>
                     <SEVERITY>INFO</SEVERITY>
                   </STATUS>
                   <DTSERVER>20141230120000[-3:BRT]</DTSERVER>
                   <LANGUAGE>POR</LANGUAGE>
                   <FI>
                     <ORG>Banco do Brasil</ORG>
                       <FID>1</FID>
                   </FI>
                 </SONRS>
             ';
     $signon = SignOn::parse($xml);
     $this->assertInstanceOf('\\Realejo\\Ofx\\SignOn', $signon);
     $this->assertNull($signon->getResponse());
     $this->assertNull($signon->getRequest());
     // Testes com XML invalido
     // SEM SIGNONMSGSRSV1
     $xml = '<OFX>
                 <SONRS>
                   <STATUS>
                     <CODE>0</CODE>
                     <SEVERITY>INFO</SEVERITY>
                   </STATUS>
                   <DTSERVER>20141230120000[-3:BRT]</DTSERVER>
                   <LANGUAGE>POR</LANGUAGE>
                   <FI>
                     <ORG>Banco do Brasil</ORG>
                       <FID>1</FID>
                   </FI>
                 </SONRS>
         </OFX>
             ';
     $signon = SignOn::parse($xml);
     $this->assertInstanceOf('\\Realejo\\Ofx\\SignOn', $signon);
     $this->assertNull($signon->getResponse());
     $this->assertNull($signon->getRequest());
 }