PHP code example of bvn-verification / bvn-verification-php
1. Go to this page and download the library: Download bvn-verification/bvn-verification-php 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/ */
bvn-verification / bvn-verification-php example snippets
use BVNVerification\BVNVerifier;
// Production mode (real NIBSS API)
$verifier = new BVNVerifier(
'your-nibss-api-key', // API key from NIBSS
false, // sandbox mode (false for production)
'live' // mode: 'live' for real API
);
// Development mode (mock data)
$verifier = new BVNVerifier(
'mock-key', // any string for mock mode
true, // sandbox mode (true for testing)
'json-mock' // mode: 'json-mock' for mock data
);
namespace App\Http\Controllers;
use BVNVerification\Laravel\Facades\BVNVerifier;
class VerificationController extends Controller
{
public function verifyCustomer(Request $request)
{
$result = BVNVerifier::verify($request->bvn, $request->full_name);
return response()->json([
'verified' => $result->isMatch(),
'registered_name' => $result->getVerifiedName(),
'message' => $result->message
]);
}
}
namespace App\Http\Controllers;
use BVNVerification\BVNVerifier;
class VerificationController extends Controller
{
public function verifyCustomer(Request $request, BVNVerifier $verifier)
{
$result = $verifier->verify($request->bvn, $request->full_name);
if ($result->isMatch()) {
// Proceed with verified user
return redirect('/dashboard')->with('success', 'BVN verified!');
}
return back()->with('error', 'BVN verification failed: ' . $result->message);
}
}
public function verifyCustomerBVN($bvn, $customerName)
{
try {
// Validate input first
if (empty($bvn) || empty($customerName)) {
throw new InvalidArgumentException('BVN and customer name are bvn,
'provided_name' => $customerName,
'verified' => $result->isMatch(),
'registered_name' => $result->getVerifiedName()
]);
return $result;
} catch (\BVNVerification\Exceptions\VerificationException $e) {
Log::error('BVN verification service error', [
'bvn' => $bvn,
'error' => $e->getMessage()
]);
throw new ServiceUnavailableException('Verification service temporarily unavailable');
} catch (Exception $e) {
Log::error('Unexpected BVN verification error', [
'bvn' => $bvn,
'error' => $e->getMessage()
]);
throw $e;
}
}
namespace Tests\Feature;
use Tests\TestCase;
use BVNVerification\Laravel\Facades\BVNVerifier;
class BVNVerificationTest extends TestCase
{
public function test_successful_bvn_verification()
{
$result = BVNVerifier::verify('12345678901', 'JOHN DOE');
$this->assertTrue($result->isMatch());
$this->assertEquals('JOHN DOE', $result->getVerifiedName());
}
public function test_failed_bvn_verification()
{
$result = BVNVerifier::verify('12345678901', 'WRONG NAME');
$this->assertFalse($result->isMatch());
$this->assertStringContainsString('does not match', $result->message);
}
public function test_invalid_bvn_format()
{
$this->expectException(\BVNVerification\Exceptions\VerificationException::class);
BVNVerifier::verify('123', 'John Doe');
}
}
VNVerification\BVNVerifier;
class BVNVerificationTest
{
private $verifier;
public function setUp()
{
$this->verifier = new BVNVerifier('test-key', true, 'json-mock');
}
public function testVerification()
{
$result = $this->verifier->verify('12345678901', 'JOHN DOE');
assert($result->isMatch() === true, 'Should verify successfully');
assert($result->getVerifiedName() === 'JOHN DOE', 'Should return registered name');
echo "✅ All tests passed!\n";
}
}
$test = new BVNVerificationTest();
$test->setUp();
$test->testVerification();
public function registerCustomer(Request $request)
{
$validated = $request->validate([
'bvn' => 'uired|string'
]);
// Verify BVN
$verificationResult = BVNVerifier::verify(
$validated['bvn'],
$validated['full_name']
);
if (!$verificationResult->isMatch()) {
return back()->withErrors([
'bvn' => 'BVN verification failed. Please ensure your BVN and name match your bank records.'
]);
}
// Create customer account
$customer = Customer::create([
'bvn' => $validated['bvn'],
'verified_name' => $verificationResult->getVerifiedName(),
'email' => $validated['email'],
'phone' => $validated['phone'],
'bvn_verified_at' => now()
]);
return redirect('/dashboard')->with('success', 'Account created successfully!');
}