1. Go to this page and download the library: Download keenops/php-nhiftz 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/ */
keenops / php-nhiftz example snippets
use Keenops\PhpNhiftz\NhifClient;
use Keenops\PhpNhiftz\Config\Configuration;
use Keenops\PhpNhiftz\Config\Environment;
$config = new Configuration(
clientId: 'your_client_id',
clientSecret: 'your_client_secret',
facilityCode: 'FAC001',
environment: Environment::SANDBOX, // or Environment::PRODUCTION
);
$nhif = new NhifClient($config);
$nhif->setUsername('your_username');
// Verify a card
$response = $nhif->serviceHub()->verification()->getCardDetails('12345678');
if ($response->isSuccessful()) {
$cardDetails = $response->json();
// Process card details...
}
// app/Nhif/StaffUsernameResolver.php
namespace App\Nhif;
use Keenops\PhpNhiftz\Contracts\UsernameResolverInterface;
class StaffUsernameResolver implements UsernameResolverInterface
{
public function __invoke(): ?string
{
// Resolve username from your application's context
return auth()->user()?->nhif_username;
}
}
// app/Providers/AppServiceProvider.php
public function boot(): void
{
app('nhif')->setUsernameResolver(function () {
return auth()->user()?->nhif_username;
});
}
Nhif::setUsername('username');
use Keenops\PhpNhiftz\Integrations\Laravel\NhifFacade as Nhif;
$response = Nhif::serviceHub()->verification()->getCardDetails('12345678');
use Keenops\PhpNhiftz\NhifClient;
class PatientController extends Controller
{
public function verify(NhifClient $nhif, string $cardNo)
{
return $nhif->serviceHub()->verification()->getCardDetails($cardNo);
}
}
// src/Nhif/StaffUsernameResolver.php
namespace App\Nhif;
use Keenops\PhpNhiftz\Contracts\UsernameResolverInterface;
class StaffUsernameResolver implements UsernameResolverInterface
{
public function __invoke(): ?string
{
// Resolve username from your application's context
return $this->security->getUser()?->getNhifUsername();
}
}
use Keenops\PhpNhiftz\NhifClient;
class PatientController extends AbstractController
{
public function __construct(private NhifClient $nhif) {}
public function verify(string $cardNo): Response
{
$response = $this->nhif->serviceHub()->verification()->getCardDetails($cardNo);
// ...
}
}
use GuzzleHttp\Client;
$httpClient = new Client([
'timeout' => 60,
'verify' => true,
]);
$nhif = new NhifClient($config, $httpClient);
use Symfony\Component\Cache\Psr16Cache;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
$cache = new Psr16Cache(new FilesystemAdapter());
$nhif = new NhifClient($config, null, $cache);
bash
composer
bash
php artisan vendor:publish --tag=nhif-config
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.