1. Go to this page and download the library: Download hamada-emam-tech/nafath library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hamada-emam-tech / nafath example snippets
use HamadaEmamTech\Nafath\Nafath;
use HamadaEmamTech\Nafath\Config\Environment;
$nafath = Nafath::make(
appId: getenv('NAFATH_APP_ID'),
appKey: getenv('NAFATH_APP_KEY'),
environment: Environment::Staging, // Sandbox | Staging | Production
serverIp: '203.0.113.10', // this machine — Nafath allowlists it
http: $psr18Client,
requests: $psr17Factory,
streams: $psr17Factory,
);
$session = $nafath->web()->start($requestId, $userIp);
// Send the browser to $session->url — unmodified, it is signed.
// Keep $session->state; it is what lets you finish without their callback.
$result = $nafath->web()->complete($session->state, $userIp);
if ($result->isPending()) return 'still waiting'; // NOT an error
if ($result->isVerified()) {
$claims = $result->claims();
$claims->identifier; // national ID / Iqama / Visa / Border
$claims->fullNameAr;
$claims->userType; // National | Resident | Visitor
}
$txn = $nafath->app()->start($nationalId, $requestId, $userIp);
echo "Open your Nafath app and approve request number {$txn->random}";
$result = $nafath->app()->status($txn, $nationalId, $userIp);