Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate Foreigner KIMLIK #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
},
"autoload": {
"psr-4": {
"Deligoez\\TCKimlikNo\\": "src/"
"Deligoez\\TCKimlikNo\\": "src/",
"Deligoez\\YabanciKimlikNo\\": "src/"
}
},
"autoload-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/TCKimlikNo.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static function validate(
* @param $name
* @return bool|false|mixed|string|string[]|null
*/
private static function toUppercaseTr(string $name): string
public static function toUppercaseTr(string $name): string
{
return mb_strtoupper(
str_replace(
Expand Down
74 changes: 74 additions & 0 deletions src/YabanciKimlikNo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Deligoez\YabanciKimlikNo;

use Deligoez\TCKimlikNo\TCKimlikNo;
use RicorocksDigitalAgency\Soap\Facades\Soap;

class YabanciKimlikNo
{
/**
* Validates Citizenship Number using nvi.gov.tr.
*
* @param string $kimlikNo
* @param string $name
* @param string $surname
* @param string $birthYear
* @param string $birthMonth
* @param string $birthDay
* @param bool $autoUppercase
* @return bool
*
* @throws \SoapFault
*/
public static function validate(
$kimlikNo,
string $name,
string $surname,
$birthYear,
$birthMonth,
$birthDay,
bool $autoUppercase = true
): bool {
if ($autoUppercase) {
$name = TCKimlikNo::toUppercaseTr($name);
$surname = TCKimlikNo::toUppercaseTr($surname);
}

if (! preg_match('/^[A-Z\. ÇĞÖŞÜİ]+$/u', TCKimlikNo::toUppercaseTr($name))) {
return false;
}

if (! preg_match('/^[A-Z\. ÇĞÖŞÜİ]+$/u', TCKimlikNo::toUppercaseTr($surname))) {
return false;
}

if (! preg_match('/^\d{4}$/', $birthYear)) {
return false;
}

if (! preg_match('/^\d{2}$/', $birthMonth)) {
return false;
}

if (! preg_match('/^\d{2}$/', $birthDay)) {
return false;
}

if (! TCKimlikNo::verify($kimlikNo)) {
return false;
}

$response = Soap::to('https://tckimlik.nvi.gov.tr/Service/KPSPublicYabanciDogrula.asmx?WSDL')
->YabanciKimlikNoDogrula([
'KimlikNo' => (int) $kimlikNo,
'Ad' => trim($name),
'Soyad' => trim($surname),
'DogumGun' => (int) $birthDay,
'DogumAy' => (int) $birthMonth,
'DogumYil' => (int) $birthYear,
]);

return (bool) $response->YabanciKimlikNoDogrulaResult;
}
}