Skip to content

Instantly share code, notes, and snippets.

@hsntgm
Last active February 7, 2024 15:40
Show Gist options
  • Save hsntgm/c289b1bb0db9c4308cfc8529dcc5a15e to your computer and use it in GitHub Desktop.
Save hsntgm/c289b1bb0db9c4308cfc8529dcc5a15e to your computer and use it in GitHub Desktop.
woocommerce-nvi-tc-kimlik-dogrulama
<?php
function strto($to, $str) {
if ('lower' === $to) {
return mb_strtolower(str_replace(array('I', 'Ğ', 'Ü', 'Ş', 'İ', 'Ö', 'Ç'), array('ı', 'ğ', 'ü', 'ş', 'i', 'ö', 'ç'), $str), 'utf-8');
} elseif ('upper' === $to) {
return mb_strtoupper(str_replace(array('ı', 'ğ', 'ü', 'ş', 'i', 'ö', 'ç'), array('I', 'Ğ', 'Ü', 'Ş', 'İ', 'Ö', 'Ç'), $str), 'utf-8');
} else {
trigger_error('Lütfen geçerli bir strto() parametresi giriniz.', E_USER_ERROR);
}
}
add_action('woocommerce_after_checkout_validation', 'kk_nvi_sorgulama', 20, 2);
function kk_nvi_sorgulama( $data, $errors ) {
if (! empty($_POST['billing_wooccm9']) && ! empty($_POST['billing_wooccm10']) && ! empty($data['billing_first_name']) && ! empty($data['billing_last_name'])) {
$client = new SoapClient("https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx?WSDL");
try{
$requestData = array(
"TCKimlikNo" => $_POST['billing_wooccm9'],
"Ad" => strto('upper', $data['billing_first_name']),
"Soyad" => strto('upper', $data['billing_last_name']),
"DogumYili" => $_POST['billing_wooccm10']
);
$result = $client->TCKimlikNoDogrula($requestData);
if ( ! $result->TCKimlikNoDogrulaResult){
$errors->add( 'validation', 'NVI Hata, T.C. Kimlik numaranız doğrulanamadı !' );
}
}
catch (Exception $ex){
echo $ex->faultstring;
}
}
}
@hsntgm
Copy link
Author

hsntgm commented Oct 2, 2022

Code goes to child theme functions.php, billing_wooccm9 & billing_wooccm10 are custom fields for nvi validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment