|
22 | 22 | use Modules\Anagrafiche\Nazione; |
23 | 23 | use Modules\Banche\Banca; |
24 | 24 | use Modules\Banche\IBAN; |
| 25 | +use GuzzleHttp\Client; |
25 | 26 |
|
26 | 27 | include_once __DIR__.'/../../core.php'; |
27 | 28 |
|
|
119 | 120 | $api_key = filter('api_key'); |
120 | 121 |
|
121 | 122 | // Verifica il credito residuo su ibanapi.com |
122 | | - $ch = curl_init(); |
123 | | - curl_setopt($ch, CURLOPT_URL, setting('Endpoint ibanapi.com').'/v1/balance?api_key='.$api_key); |
124 | | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
125 | | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); |
126 | | - $result = curl_exec($ch); |
127 | | - |
128 | | - if (curl_errno($ch)) { |
| 123 | + try { |
| 124 | + $client = new Client(); |
| 125 | + $response = $client->request('GET', setting('Endpoint ibanapi.com').'/v1/balance', [ |
| 126 | + 'query' => ['api_key' => $api_key], |
| 127 | + 'http_errors' => false, |
| 128 | + ]); |
| 129 | + |
| 130 | + echo $response->getBody()->getContents(); |
| 131 | + } catch (\Exception $e) { |
129 | 132 | http_response_code(500); |
130 | | - echo json_encode(['error' => 'Errore durante la connessione a ibanapi.com']); |
| 133 | + echo json_encode(['error' => 'Errore durante la connessione a ibanapi.com: '.$e->getMessage()]); |
131 | 134 | exit; |
132 | 135 | } |
133 | | - curl_close($ch); |
134 | | - |
135 | | - echo $result; |
136 | 136 | break; |
137 | 137 |
|
138 | 138 | case 'verify_iban': |
|
141 | 141 | $api_key = filter('api_key'); |
142 | 142 |
|
143 | 143 | // Verifica l'IBAN tramite ibanapi.com |
144 | | - $ch = curl_init(); |
145 | | - $endpoint = ($type === 'bank') ? setting('Endpoint ibanapi.com').'/v1/validate' : setting('Endpoint ibanapi.com').'/v1/validate-basic'; |
146 | | - curl_setopt($ch, CURLOPT_URL, $endpoint); |
147 | | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
148 | | - curl_setopt($ch, CURLOPT_POST, 1); |
149 | | - curl_setopt($ch, CURLOPT_POSTFIELDS, ['iban' => $iban, 'api_key' => $api_key]); |
150 | | - $headers = []; |
151 | | - $headers[] = 'Accept: application/json'; |
152 | | - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
153 | | - $result = curl_exec($ch); |
154 | | - |
155 | | - if (curl_errno($ch)) { |
| 144 | + try { |
| 145 | + $client = new Client(); |
| 146 | + $endpoint = ($type === 'bank') ? setting('Endpoint ibanapi.com').'/v1/validate' : setting('Endpoint ibanapi.com').'/v1/validate-basic'; |
| 147 | + $response = $client->request('POST', $endpoint, [ |
| 148 | + 'form_params' => [ |
| 149 | + 'iban' => $iban, |
| 150 | + 'api_key' => $api_key |
| 151 | + ], |
| 152 | + 'headers' => [ |
| 153 | + 'Accept' => 'application/json' |
| 154 | + ], |
| 155 | + 'http_errors' => false, |
| 156 | + ]); |
| 157 | + |
| 158 | + echo $response->getBody()->getContents(); |
| 159 | + } catch (\Exception $e) { |
156 | 160 | http_response_code(500); |
157 | | - echo json_encode(['error' => 'Errore durante la connessione a ibanapi.com']); |
| 161 | + echo json_encode(['error' => 'Errore durante la connessione a ibanapi.com: '.$e->getMessage()]); |
158 | 162 | exit; |
159 | 163 | } |
160 | | - curl_close($ch); |
161 | | - |
162 | | - echo $result; |
163 | 164 | break; |
164 | 165 | } |
0 commit comments