コード例 #1
0
ファイル: SignOn.php プロジェクト: realejo/ofx
 /**
  * @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;
 }
コード例 #2
0
ファイル: Parser.php プロジェクト: realejo/ofx
 /**
  * @param string $content
  *
  * @return \Realejo\Ofx\Ofx
  */
 public static function createFromString($content)
 {
     $content = explode('<OFX>', $content);
     // Cria o objeto Ofx
     $ofx = new Ofx();
     // Define os headers do OFX
     $ofx->setHeaders(self::parseHeaders(trim($content[0])));
     // Verifica se há mais coisda além do header
     if (!isset($content[1])) {
         return $ofx;
     }
     // Define o conteúdo SGML do OFX
     $xmlContent = '<OFX>' . $content[1];
     // Fix encoding
     $currentEncoding = $ofx->getHeader('ENCODING');
     if ($currentEncoding == 'USASCII') {
         $currentEncoding = 'ASCII';
     }
     if (!empty($currentEncoding) && $currentEncoding !== 'UTF-8') {
         $xmlContent = mb_convert_encoding($xmlContent, 'UTF-8', $currentEncoding);
     }
     // Cria o XML
     $xml = self::makeXML($xmlContent);
     $parse = SignOn::parse($xml);
     if (!empty($parse)) {
         $ofx->setSignOn($parse);
     }
     //$ofx->setSignup($this->parseSignup());
     $parse = BankingParser::parse($xml);
     if (!empty($parse)) {
         $ofx->setBanking($parse);
     }
     //$ofx->setInvestment($this->parseInvestment());
     //$ofx->setInterbank($this->parseInterbank());
     //$ofx->setWireFundsTransfers($this->parseWireFundsTransfers());
     //$ofx->setPayments($this->parsePayments());
     //$ofx->setGeneralEmail($this->parseGeneralEmail());
     //$ofx->setInvestmentSecurity($this->parseInvestmentSecurity());
     //$ofx->setFIProfile($this->parseFIProfile());
     return $ofx;
 }
コード例 #3
0
ファイル: SignOnTest.php プロジェクト: realejo/ofx
 /**
  * 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());
 }