Last active
February 7, 2024 15:40
-
-
Save hsntgm/c289b1bb0db9c4308cfc8529dcc5a15e to your computer and use it in GitHub Desktop.
woocommerce-nvi-tc-kimlik-dogrulama
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code goes to child theme functions.php, billing_wooccm9 & billing_wooccm10 are custom fields for nvi validation.