|
20 | 20 | include_once __DIR__.'/../../core.php'; |
21 | 21 |
|
22 | 22 | $id_anagrafica = filter('id_anagrafica'); |
| 23 | +$ibanapi_key = setting('Api key ibanapi.com'); |
| 24 | +$endpoint = setting('Endpoint ibanapi.com'); |
23 | 25 |
|
24 | 26 | echo ' |
25 | 27 | <form action="" method="post" id="add-form"> |
|
38 | 40 |
|
39 | 41 | <div class="row"> |
40 | 42 | <div class="col-md-8"> |
41 | | - {[ "type": "text", "label": "'.tr('IBAN').'", "name": "iban", "required": "1", "class": "alphanumeric-mask", "maxlength": 32, "value": "$iban$" ]} |
| 43 | + {[ "type": "text", "label": "'.tr('IBAN').'", "name": "iban", "required": "1", "class": "alphanumeric-mask", "maxlength": 32, "value": "$iban$", "icon-after": "'.(!empty($ibanapi_key) && !empty($endpoint)?'<a class=\'fa fa-search clickable\' id=\'check-iban\'></a>':'<span class=\'tip\' title=\'Da impostazioni sezione API è possibile attivare la verifica iban tramite ibanapi.com\'><i class=\'fa fa-search text-danger clickable\'></i></span>').'" ]} |
42 | 44 | </div> |
43 | 45 |
|
44 | 46 | <div class="col-md-4"> |
@@ -179,4 +181,156 @@ function compilaCampi(values) { |
179 | 181 | } |
180 | 182 | } |
181 | 183 | } |
| 184 | + |
| 185 | + // Funzione per verificare l'IBAN tramite ibanapi.com |
| 186 | + function checkIban() { |
| 187 | + let value = iban.get(); |
| 188 | + if (value.length < 15) { |
| 189 | + swal("<?php echo tr('Errore'); ?>", "<?php echo tr('Inserire un IBAN valido'); ?>", "error"); |
| 190 | + return; |
| 191 | + } |
| 192 | + |
| 193 | + // Verifica il credito residuo e la data di scadenza |
| 194 | + $.ajax({ |
| 195 | + url: globals.rootdir + '/actions.php', |
| 196 | + data: { |
| 197 | + id_module: id_module, |
| 198 | + op: "check_balance", |
| 199 | + api_key: "<?php echo $ibanapi_key; ?>" |
| 200 | + }, |
| 201 | + type: 'GET', |
| 202 | + dataType: "json", |
| 203 | + success: function(balance) { |
| 204 | + if (new Date(balance.data.expiry_date) < new Date()) { |
| 205 | + swal("<?php echo tr('Errore'); ?>", "<?php echo tr('La chiave API è scaduta'); ?>", "error"); |
| 206 | + return; |
| 207 | + } |
| 208 | + |
| 209 | + // Determina quale tipo di verifica utilizzare in base al credito residuo |
| 210 | + let verificationType = ''; |
| 211 | + if (balance.data.bank_balance > 0) { |
| 212 | + verificationType = 'bank'; |
| 213 | + } else if (balance.data.basic_balance > 0) { |
| 214 | + verificationType = 'basic'; |
| 215 | + } else { |
| 216 | + swal("<?php echo tr('Errore'); ?>", "<?php echo tr('Credito insufficiente per la verifica IBAN'); ?>", "error"); |
| 217 | + return; |
| 218 | + } |
| 219 | + |
| 220 | + // Verifica l'IBAN |
| 221 | + $.ajax({ |
| 222 | + url: globals.rootdir + '/actions.php', |
| 223 | + data: { |
| 224 | + id_module: id_module, |
| 225 | + op: "verify_iban", |
| 226 | + iban: value, |
| 227 | + type: verificationType, |
| 228 | + api_key: "<?php echo $ibanapi_key; ?>" |
| 229 | + }, |
| 230 | + type: 'GET', |
| 231 | + dataType: "json", |
| 232 | + success: function(response) { |
| 233 | + // Verifica se l'IBAN è valido (result: 200 indica validità) |
| 234 | + if (response.result === 200) { |
| 235 | + // Compila i campi se disponibili |
| 236 | + if (verificationType === 'bank' && response.data && response.data.bank) { |
| 237 | + if (response.data.bank.bic) { |
| 238 | + $('#modals > div #bic').val(response.data.bank.bic); |
| 239 | + } |
| 240 | + if (response.data.bank.bank_name) { |
| 241 | + $('#modals > div #nome').val(response.data.bank.bank_name); |
| 242 | + } |
| 243 | + } |
| 244 | + |
| 245 | + // Formatta le informazioni per l'alert |
| 246 | + let infoHtml = "<p><strong><?php echo tr('IBAN valido'); ?></strong></p>"; |
| 247 | + |
| 248 | + // Informazioni sul paese |
| 249 | + if (response.data) { |
| 250 | + infoHtml += "<p><strong><?php echo tr('Informazioni paese'); ?>:</strong></p>"; |
| 251 | + infoHtml += "<p><?php echo tr('Paese'); ?>: " + response.data.country_code + " - " + response.data.country_name + "</p>"; |
| 252 | + infoHtml += "<p><?php echo tr('Valuta'); ?>: " + response.data.currency_code + "</p>"; |
| 253 | + infoHtml += "<p>SEPA: " + response.data.sepa_member + "</p>"; |
| 254 | + } |
| 255 | + |
| 256 | + // Informazioni sulla banca |
| 257 | + if (response.data && response.data.bank) { |
| 258 | + infoHtml += "<p><strong><?php echo tr('Informazioni banca'); ?>:</strong></p>"; |
| 259 | + infoHtml += "<p><?php echo tr('Nome banca'); ?>: " + response.data.bank.bank_name + "</p>"; |
| 260 | + |
| 261 | + if (response.data.bank.bic) { |
| 262 | + infoHtml += "<p>BIC: " + response.data.bank.bic + "</p>"; |
| 263 | + } |
| 264 | + |
| 265 | + if (response.data.bank.address) { |
| 266 | + infoHtml += "<p><?php echo tr('Indirizzo'); ?>: " + response.data.bank.address + "</p>"; |
| 267 | + } |
| 268 | + |
| 269 | + if (response.data.bank.city) { |
| 270 | + let location = response.data.bank.city; |
| 271 | + if (response.data.bank.zip) { |
| 272 | + location += " - " + response.data.bank.zip; |
| 273 | + } |
| 274 | + if (response.data.bank.state) { |
| 275 | + location += " (" + response.data.bank.state + ")"; |
| 276 | + } |
| 277 | + infoHtml += "<p><?php echo tr('Località'); ?>: " + location + "</p>"; |
| 278 | + } |
| 279 | + } |
| 280 | + |
| 281 | + if(response.data.sepa){ |
| 282 | + infoHtml += "<p><strong><?php echo tr('Informazioni sepa'); ?>:</strong></p>"; |
| 283 | + infoHtml += "<div class='row'>"; |
| 284 | + |
| 285 | + // Funzione per creare un badge SEPA |
| 286 | + function createSepaBadge(value, label) { |
| 287 | + var status = value === 'Yes'; |
| 288 | + var badgeClass = status ? 'success' : 'danger'; |
| 289 | + return "<div class='col-md-6 mb-2'>" |
| 290 | + + "<div class='card h-100'>" |
| 291 | + + "<div class='card-body p-1 d-flex align-items-center'>" |
| 292 | + + "<span class='small' style='font-size:9pt'>" + label + "</span>" |
| 293 | + + "<span class='badge badge-" + badgeClass + " ml-auto small' style='font-size: 0.75rem;'>" + (status ? '<?php echo tr("Attivo"); ?>' : '<?php echo tr("Non attivo"); ?>') + "</span>" |
| 294 | + + "</div></div></div>"; |
| 295 | + } |
| 296 | + |
| 297 | + // Crea i badge per ogni servizio SEPA |
| 298 | + infoHtml += createSepaBadge(response.data.sepa.sepa_credit_transfer, "SEPA Credit Transfer"); |
| 299 | + infoHtml += createSepaBadge(response.data.sepa.sepa_credit_transfer_inst, "SEPA Credit Transfer Instant"); |
| 300 | + infoHtml += createSepaBadge(response.data.sepa.sepa_direct_debit, "SEPA Direct Debit"); |
| 301 | + infoHtml += createSepaBadge(response.data.sepa.sepa_sdd_core, "SEPA Direct Debit Core"); |
| 302 | + infoHtml += createSepaBadge(response.data.sepa.sepa_b2b, "SEPA B2B"); |
| 303 | + infoHtml += createSepaBadge(response.data.sepa.sepa_card_clearing, "SEPA Card Clearing"); |
| 304 | + |
| 305 | + infoHtml += "</div></div>"; |
| 306 | + } |
| 307 | + |
| 308 | + swal({ |
| 309 | + title: "<?php echo tr('Verifica completata'); ?>", |
| 310 | + html: infoHtml, |
| 311 | + type: "success" |
| 312 | + }); |
| 313 | + |
| 314 | + // Aggiorna i campi del form |
| 315 | + scomponiIban(); |
| 316 | + } else { |
| 317 | + swal("<?php echo tr('IBAN non valido'); ?>", response.message || "<?php echo tr('Formato IBAN non valido'); ?>", "error"); |
| 318 | + } |
| 319 | + }, |
| 320 | + error: function() { |
| 321 | + swal("<?php echo tr('Errore'); ?>", "<?php echo tr('Errore durante la verifica dell\'IBAN'); ?>", "error"); |
| 322 | + } |
| 323 | + }); |
| 324 | + }, |
| 325 | + error: function() { |
| 326 | + swal("<?php echo tr('Errore'); ?>", "<?php echo tr('Errore durante la verifica del credito'); ?>", "error"); |
| 327 | + } |
| 328 | + }); |
| 329 | + } |
| 330 | + |
| 331 | + // Aggiungi l'evento click al pulsante di verifica IBAN |
| 332 | + $("#check-iban").on("click", function(e) { |
| 333 | + e.preventDefault(); |
| 334 | + checkIban(); |
| 335 | + }); |
182 | 336 | </script> |
0 commit comments