PHP code example of ddevs-20 / nomba-php-sdk
1. Go to this page and download the library: Download ddevs-20/nomba-php-sdk 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/ */
ddevs-20 / nomba-php-sdk example snippets
Nomba\NombaClient;
$client = new NombaClient([
'client_id' => 'your-client-id',
'client_secret' => 'your-client-secret',
'account_id' => 'your-account-id',
'environment' => 'sandbox', // or 'production'
]);
// Authenticate
$client->authenticate();
$order = $client->payments->createOrder([
'amount' => 10000, // Amount in kobo
'currency' => 'NGN',
'customerEmail'=> '[email protected] ',
'callbackUrl' => 'https://yourdomain.com/callback',
'description' => 'Payment for order #12345',
]);
echo "Order Reference: " . $order['data']['orderRef'];
$charge = $client->payments->chargeCard([
'orderRef' => $order['data']['orderRef'],
'card' => [
'number' => '5399838383838381',
'expiryMonth' => '12',
'expiryYear' => '2025',
'cvv' => '123',
'pin' => '1234',
],
]);
echo "Transaction Reference: " . $charge['data']['transactionRef'];
$verification = $client->transactions->verify($charge['data']['transactionRef']);
if ($verification['data']['status'] === 'successful') {
echo "Payment successful!";
}
$virtualAccount = $client->virtualAccounts->create([
'accountName' => 'John Doe',
'bvn' => '12345678901', // Optional: for BVN verification
'expectedAmount' => 500000, // Optional: expected incoming amount
'currency' => 'NGN',
]);
echo "Virtual Account Number: " . $virtualAccount['data']['accountNumber'];
$transactions = $client->virtualAccounts->fetchTransactions([
'accountNumber' => $virtualAccount['data']['accountNumber'],
'from' => '2025-01-01',
'to' => '2025-12-31',
]);
$lookup = $client->virtualAccounts->lookup([
'accountNumber' => $virtualAccount['data']['accountNumber'],
]);
$transfer = $client->transfers->initiate([
'amount' => 100000, // Amount in kobo
'currency' => 'NGN',
'destinationBankCode' => '057', // Zenith Bank
'destinationAccountNumber' => '0123456789',
'narration' => 'Salary payment for March',
]);
echo "Transfer Reference: " . $transfer['data']['transactionRef'];
$status = $client->transfers->getStatus($transfer['data']['transactionRef']);
echo "Transfer Status: " . $status['data']['status'];
use Nomba\Webhook;
$webhook = new Webhook('your-webhook-secret');
// Verify webhook signature
$payload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_NOMBA_SIGNATURE'] ?? '';
if ($webhook->verify($payload, $signature)) {
$event = json_decode($payload, true);
switch ($event['event']) {
case 'payment_success':
// Handle successful payment
handlePaymentSuccess($event['data']);
break;
case 'transfer_success':
// Handle successful transfer
handleTransferSuccess($event['data']);
break;
// ... handle other events
}
http_response_code(200);
} else {
http_response_code(400);
echo "Invalid signature";
}
$client->webhooks->rePush([
'transactionRef' => 'your-transaction-ref',
]);
$mandate = $client->directDebit->createMandate([
'customerEmail' => '[email protected] ',
'customerName' => 'John Doe',
'accountNumber' => '0123456789',
'bankCode' => '057',
'amount' => 100000,
'startDate' => '2025-05-01',
'endDate' => '2025-12-31',
'frequency' => 'monthly', // daily, weekly, monthly
]);
$terminalAction = $client->terminals->createAction([
'terminalId' => 'your-terminal-id',
'action' => 'pre_payout_validation',
'payload' => [
// Custom validation logic
],
]);
use Nomba\NombaClient;
use Nomba\Http\SseHandler;
$client = new NombaClient([...]);
$handler = new SseHandler($client);
$orderRef = $_GET['orderRef'];
// This will keep the connection open and poll Nomba API
$handler->streamStatus($orderRef);
use Nomba\Exceptions\NombaApiException;
use Nomba\Exceptions\AuthenticationException;
use Nomba\Exceptions\ValidationException;
try {
$order = $client->payments->createOrder([...]);
} catch (AuthenticationException $e) {
// Handle authentication errors (401)
echo "Authentication failed: " . $e->getMessage();
} catch (ValidationException $e) {
// Handle validation errors (422)
echo "Validation error: " . $e->getMessage();
print_r($e->getErrors());
} catch (NombaApiException $e) {
// Handle other API errors
echo "API Error (" . $e->getCode() . "): " . $e->getMessage();
}
$client = new NombaClient([
'client_id' => 'your-client-id',
'client_secret' => 'your-client-secret',
'account_id' => 'your-account-id',
'environment' => 'sandbox', // 'sandbox' or 'production'
'timeout' => 30, // Request timeout in seconds
'base_url' => null, // Override base URL (optional)
]);
$client = new NombaClient([
'client_id' => 'your-sandbox-client-id',
'client_secret' => 'your-sandbox-client-secret',
'account_id' => 'your-sandbox-account-id',
'environment' => 'sandbox',
]);
bash
composer