Added online bankdata validation
This commit is contained in:
@@ -573,6 +573,9 @@ class AddressController extends mfBaseController {
|
||||
case "findAddress":
|
||||
$return = $this->findAddressApi();
|
||||
break;
|
||||
case "validateIbanBic":
|
||||
$return = $this->validateIbanBicApi();
|
||||
break;
|
||||
default:
|
||||
$return = false;
|
||||
}
|
||||
@@ -675,5 +678,56 @@ class AddressController extends mfBaseController {
|
||||
$this->returnJson($results);
|
||||
}
|
||||
|
||||
private function validateIbanBicApi() {
|
||||
$iban = trim($this->request->iban);
|
||||
$bic = trim($this->request->bic);
|
||||
|
||||
if(!$iban) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$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 = [];
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return ["iban" => $data->iban, "bic" => $potential_bics, "iban_correct" => $iban_correct, "iban_sus" => $iban_sus, "bic_correct" => $bic_correct];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user