public function go()
{
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $this->bank->url);
curl_setopt($c, CURLOPT_POST, 1);
// User-Agent: http://www.ofxhome.com/ofxforum/viewtopic.php?pid=108091#p108091
curl_setopt($c, CURLOPT_HTTPHEADER, ['Content-Type: application/x-ofx', 'User-Agent: httpclient']);
curl_setopt($c, CURLOPT_POSTFIELDS, $this->request);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$this->response = curl_exec($c);
if (Utils::isNinjaDev()) {
Log::info(print_r($this->response, true));
}
curl_close($c);
$tmp = explode('<OFX>', $this->response);
$this->responseHeader = $tmp[0];
$this->responseBody = '<OFX>' . $tmp[1];
}
public function setup($includeTransactions = true) { $ofxRequest = "OFXHEADER:100\n" . "DATA:OFXSGML\n" . "VERSION:102\n" . "SECURITY:NONE\n" . "ENCODING:USASCII\n" . "CHARSET:1252\n" . "COMPRESSION:NONE\n" . "OLDFILEUID:NONE\n" . "NEWFILEUID:NONE\n" . "\n" . "<OFX>\n" . "<SIGNONMSGSRQV1>\n" . "<SONRQ>\n" . "<DTCLIENT>20110412162900.000[-7:MST]\n" . "<USERID>" . $this->login->id . "\n" . "<USERPASS>" . $this->login->pass . "\n" . "<LANGUAGE>ENG\n" . "<FI>\n" . "<ORG>" . $this->login->bank->org . "\n" . "<FID>" . $this->login->bank->fid . "\n" . "</FI>\n" . "<APPID>QWIN\n" . "<APPVER>2500\n" . "</SONRQ>\n" . "</SIGNONMSGSRQV1>\n"; if ($this->type == 'BANK') { $ofxRequest .= "\t<BANKMSGSRQV1>\n" . "\t\t<STMTTRNRQ>\n" . "\t\t\t<TRNUID>" . md5(time() . $this->login->bank->url . $this->id) . "\n" . "\t\t\t<STMTRQ>\n" . "\t\t\t\t<BANKACCTFROM>\n" . "\t\t\t\t\t<BANKID>" . $this->bankId . "\n" . "\t\t\t\t\t<ACCTID>" . $this->id . "\n" . "\t\t\t\t\t<ACCTTYPE>" . $this->subType . "\n" . "\t\t\t\t</BANKACCTFROM>\n" . "\t\t\t\t<INCTRAN>\n" . "\t\t\t\t\t<DTSTART>20110301\n" . "\t\t\t\t\t<INCLUDE>" . ($includeTransactions ? 'Y' : 'N') . "\n" . "\t\t\t\t</INCTRAN>\n" . "\t\t\t</STMTRQ>\n" . "\t\t</STMTTRNRQ>\n" . "\t</BANKMSGSRQV1>\n"; } elseif ($this->type == 'CC') { $ofxRequest .= "\t<CREDITCARDMSGSRQV1>\n" . "\t\t<CCSTMTTRNRQ>\n" . "\t\t\t<TRNUID>" . md5(time() . $this->login->bank->url . $this->id) . "\n" . "\t\t\t<CCSTMTRQ>\n" . "\t\t\t\t<CCACCTFROM>\n" . "\t\t\t\t\t<ACCTID>" . $this->id . "\n" . "\t\t\t\t</CCACCTFROM>\n" . "\t\t\t\t<INCTRAN>\n" . "\t\t\t\t\t<DTSTART>20110320\n" . "\t\t\t\t\t<INCLUDE>" . ($includeTransactions ? 'Y' : 'N') . "\n" . "\t\t\t\t</INCTRAN>\n" . "\t\t\t</CCSTMTRQ>\n" . "\t\t</CCSTMTTRNRQ>\n" . "\t</CREDITCARDMSGSRQV1>\n"; } $ofxRequest .= "</OFX>"; $o = new OFX($this->login->bank, $ofxRequest); $o->go(); $this->response = $o->response; $x = $o->xml(); $a = $x->xpath('/OFX/*/*/*/LEDGERBAL/BALAMT'); $this->ledgerBalance = (double) $a[0]; $a = $x->xpath('/OFX/*/*/*/AVAILBAL/BALAMT'); if (isset($a[0])) { $this->availableBalance = (double) $a[0]; } }