/** * @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; }
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')); }
/** * @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; }
/** * * @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; }