Skip to content

Commit 1042ef7

Browse files
committed
feat: aggiornata verifica iban utilizzando guzzle
1 parent 24d884a commit 1042ef7

3 files changed

Lines changed: 35 additions & 34 deletions

File tree

modules/banche/actions.php

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Modules\Anagrafiche\Nazione;
2323
use Modules\Banche\Banca;
2424
use Modules\Banche\IBAN;
25+
use GuzzleHttp\Client;
2526

2627
include_once __DIR__.'/../../core.php';
2728

@@ -119,20 +120,19 @@
119120
$api_key = filter('api_key');
120121

121122
// 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) {
129132
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()]);
131134
exit;
132135
}
133-
curl_close($ch);
134-
135-
echo $result;
136136
break;
137137

138138
case 'verify_iban':
@@ -141,24 +141,25 @@
141141
$api_key = filter('api_key');
142142

143143
// 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) {
156160
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()]);
158162
exit;
159163
}
160-
curl_close($ch);
161-
162-
echo $result;
163164
break;
164165
}

modules/banche/add.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ function compilaCampi(values) {
184184

185185
// Funzione per verificare l'IBAN tramite ibanapi.com
186186
function checkIban() {
187-
let value = iban.get();
187+
let value = $("#modals #iban").val();
188188
if (value.length < 15) {
189189
swal("<?php echo tr('Errore'); ?>", "<?php echo tr('Inserire un IBAN valido'); ?>", "error");
190190
return;
@@ -235,10 +235,10 @@ function checkIban() {
235235
// Compila i campi se disponibili
236236
if (verificationType === 'bank' && response.data && response.data.bank) {
237237
if (response.data.bank.bic) {
238-
$('#modals > div #bic').val(response.data.bank.bic);
238+
$('#modals #bic').val(response.data.bank.bic);
239239
}
240240
if (response.data.bank.bank_name) {
241-
$('#modals > div #nome').val(response.data.bank.bank_name);
241+
$('#modals #nome').val(response.data.bank.bank_name);
242242
}
243243
}
244244

@@ -278,7 +278,7 @@ function checkIban() {
278278
}
279279
}
280280

281-
if(response.data.sepa){
281+
if(verificationType === 'bank' && response.data.sepa){
282282
infoHtml += "<p><strong><?php echo tr('Informazioni sepa'); ?>:</strong></p>";
283283
infoHtml += "<div class='row'>";
284284

@@ -329,7 +329,7 @@ function createSepaBadge(value, label) {
329329
}
330330

331331
// Aggiungi l'evento click al pulsante di verifica IBAN
332-
$("#check-iban").on("click", function(e) {
332+
$("#modals #check-iban").on("click", function(e) {
333333
e.preventDefault();
334334
checkIban();
335335
});

modules/banche/edit.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ function compilaCampi(values) {
259259

260260
// Funzione per verificare l'IBAN tramite ibanapi.com
261261
function checkIban() {
262-
let value = iban.get();
262+
let value = $("#iban").val();
263263
if (value.length < 15) {
264264
swal("<?php echo tr('Errore'); ?>", "<?php echo tr('Inserire un IBAN valido'); ?>", "error");
265265
return;
@@ -353,7 +353,7 @@ function checkIban() {
353353
}
354354
}
355355

356-
if(response.data.sepa){
356+
if(verificationType === 'bank' && response.data.sepa){
357357
infoHtml += "<p><strong><?php echo tr('Informazioni sepa'); ?>:</strong></p>";
358358
infoHtml += "<div class='row'>";
359359

0 commit comments

Comments
 (0)