61 lines
1.6 KiB
PHP
61 lines
1.6 KiB
PHP
<?php
|
|
|
|
class IbanValidator {
|
|
|
|
public static function validate($iban, $bic = false) {
|
|
if(!$iban) {
|
|
return false;
|
|
}
|
|
|
|
if(!defined("TT_IBAN_VALIDATOR_BASEURL") || !TT_IBAN_VALIDATOR_BASEURL) {
|
|
return ["bank" => "none", "iban" => "none", "bic" => [], "iban_correct" => true, "iban_sus" => false, "bic_correct" => true];
|
|
}
|
|
|
|
$creds = TT_IBAN_VALIDATOR_USER.":".TT_IBAN_VALIDATOR_PASS;
|
|
$b64creds = base64_encode($creds);
|
|
|
|
$ctx = stream_context_create([
|
|
"http" => [
|
|
"header" => "Authorization: Basic $b64creds"
|
|
]
|
|
]);
|
|
|
|
$url = TT_IBAN_VALIDATOR_BASEURL.$iban;
|
|
$resp = file_get_contents($url, false, $ctx);
|
|
|
|
if($resp) {
|
|
$data = json_decode($resp);
|
|
}
|
|
|
|
$iban_correct = false;
|
|
$iban_sus = false;
|
|
$bic_correct = false;
|
|
$potential_bics = [];
|
|
$bank = false;
|
|
|
|
if($data->result == "passed") {
|
|
$iban_correct = true;
|
|
}
|
|
|
|
if(is_array($data->all_bic_candidates) && count($data->all_bic_candidates)) {
|
|
foreach($data->all_bic_candidates as $bic_candidate) {
|
|
if(!$bic_candidate->bic) continue;
|
|
$potential_bics[] = $bic_candidate->bic;
|
|
|
|
if($bic_candidate->bic == $bic) {
|
|
$bic_correct = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if($data->iban_listed) {
|
|
$iban_sus = $data->iban_listed;
|
|
}
|
|
|
|
if($data->bank) {
|
|
$bank = $data->bank;
|
|
}
|
|
|
|
return ["bank" => $bank, "iban" => $data->iban, "bic" => $potential_bics, "iban_correct" => $iban_correct, "iban_sus" => $iban_sus, "bic_correct" => $bic_correct];
|
|
}
|
|
} |