Changeset 873 for trunk/Modules/FinanceBankAPI/FioAPI.php
- Timestamp:
- Apr 6, 2020, 11:17:40 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/FinanceBankAPI/FioAPI.php
r836 r873 7 7 function RemoveComma($Text) 8 8 { 9 if ((mb_strlen($Text) >= 2) and ($Text[0] == '"') and (mb_substr($Text, -1, 1) == '"')) return(mb_substr($Text, 1, -1));10 else return ($Text);9 if ((mb_strlen($Text) >= 2) and ($Text[0] == '"') and (mb_substr($Text, -1, 1) == '"')) return (mb_substr($Text, 1, -1)); 10 else return ($Text); 11 11 } 12 12 … … 25 25 function Import($TimeFrom, $TimeTo) 26 26 { 27 if ($this->Token == '') throw new Exception('Missing value for Token property.');27 if ($this->Token == '') throw new Exception('Missing value for Token property.'); 28 28 29 29 // URL format: https://www.fio.cz/ib_api/rest/periods/{token}/{datum od}/{datum do}/transactions.{format} … … 33 33 $Response = ''; 34 34 $Response = @file_get_contents('https://www.fio.cz'.$RequestURL); 35 if ($Response == FALSE)35 if ($Response == FALSE) 36 36 { 37 37 throw new Exception('Connection error'); 38 38 } else 39 39 { 40 if ($this->Format == 'gpc') $Response = iconv('windows-1250', $this->Encoding, $Response);40 if ($this->Format == 'gpc') $Response = iconv('windows-1250', $this->Encoding, $Response); 41 41 $Response = explode("\n", $Response); 42 42 43 if ($this->Format == 'gpc')43 if ($this->Format == 'gpc') 44 44 { 45 45 // Parse all GPC lines 46 46 $GPC = new GPC(); 47 47 $Result = array(); 48 foreach ($Response as $Index => $Line)48 foreach ($Response as $Index => $Line) 49 49 { 50 if (($Index == 0) and (substr($Line, 0, strlen(GPC_TYPE_REPORT)) != GPC_TYPE_REPORT)) $this->NoValidDataError($Response);50 if (($Index == 0) and (substr($Line, 0, strlen(GPC_TYPE_REPORT)) != GPC_TYPE_REPORT)) $this->NoValidDataError($Response); 51 51 $GPCLine = $GPC->ParseLine($Line); 52 if ($GPCLine != NULL) $Result[] = $GPCLine;52 if ($GPCLine != NULL) $Result[] = $GPCLine; 53 53 } 54 54 } else 55 if ($this->Format == 'csv')55 if ($this->Format == 'csv') 56 56 { 57 57 $Result = array( … … 60 60 61 61 // CVS header 62 while ((count($Response) > 0) and ($Response[0] != ''))62 while ((count($Response) > 0) and ($Response[0] != '')) 63 63 { 64 64 $Line = explode(';', $Response[0]); 65 if ($Line[0] == 'accountId') $Result['AccountNumber'] = $Line[0];66 else if ($Line[0] == 'bankId') $Result['BankId'] = $Line[0];67 else if ($Line[0] == 'currency') $Result['Currency'] = $Line[0];68 else if ($Line[0] == 'iban') $Result['IBAN'] = $Line[0];69 else if ($Line[0] == 'bic') $Result['BIC'] = $Line[0];70 else if ($Line[0] == 'openingBalance') $Result['OpeningBalance'] = $Line[0];71 else if ($Line[0] == 'closingBalance') $Result['ClosingBalance'] = $Line[0];72 else if ($Line[0] == 'dateStart') $Result['DateStart'] = $Line[0];73 else if ($Line[0] == 'dateEnd') $Result['DateEnd'] = $Line[0];74 else if ($Line[0] == 'idFrom') $Result['IdFrom'] = $Line[0];75 else if ($Line[0] == 'idTo') $Result['IdTo'] = $Line[0];65 if ($Line[0] == 'accountId') $Result['AccountNumber'] = $Line[0]; 66 else if ($Line[0] == 'bankId') $Result['BankId'] = $Line[0]; 67 else if ($Line[0] == 'currency') $Result['Currency'] = $Line[0]; 68 else if ($Line[0] == 'iban') $Result['IBAN'] = $Line[0]; 69 else if ($Line[0] == 'bic') $Result['BIC'] = $Line[0]; 70 else if ($Line[0] == 'openingBalance') $Result['OpeningBalance'] = $Line[0]; 71 else if ($Line[0] == 'closingBalance') $Result['ClosingBalance'] = $Line[0]; 72 else if ($Line[0] == 'dateStart') $Result['DateStart'] = $Line[0]; 73 else if ($Line[0] == 'dateEnd') $Result['DateEnd'] = $Line[0]; 74 else if ($Line[0] == 'idFrom') $Result['IdFrom'] = $Line[0]; 75 else if ($Line[0] == 'idTo') $Result['IdTo'] = $Line[0]; 76 76 array_shift($Response); 77 77 } 78 78 array_shift($Response); // Remove empty line 79 79 80 if ((count($Response) == 0) or80 if ((count($Response) == 0) or 81 81 ($Response[0] != 'ID pohybu;Datum;Objem;Měna;Protiúčet;Název protiúčtu;Kód banky;Název banky;KS;VS;SS;Uživatelská identifikace;Zpráva pro příjemce;Typ;Provedl;Upřesnění;Komentář;BIC;ID pokynu') 82 82 ) throw new Exception('Unsupported CSV header'); 83 83 array_shift($Response); 84 84 array_pop($Response); 85 foreach ($Response as $Index => $Line)85 foreach ($Response as $Index => $Line) 86 86 { 87 87 $Line = explode(';', $Line); … … 97 97 } 98 98 } 99 return ($Result);99 return ($Result); 100 100 } 101 101 } … … 107 107 $Response = implode('', $Response); 108 108 $ErrorMessageStart = '<div id="oldform_warning">'; 109 if (strpos($Response, $ErrorMessageStart) !== false)109 if (strpos($Response, $ErrorMessageStart) !== false) 110 110 { 111 111 $Response = substr($Response, strpos($Response, $ErrorMessageStart) + strlen($ErrorMessageStart));
Note:
See TracChangeset
for help on using the changeset viewer.