Hosted payment page integration
Overview
A hosted payment page is the most common integration for small and medium-sized businesses accepting payments online. It offers:
- Branding and customisation of the payment page
- PCI DSS compliance handled on your behalf
- Secure payment processing on pages controlled by Network International
- A mobile-first, responsive design
- Support for several currencies and payment methods
Before you start
You need these from MyBank when your merchant account is set up:
- N-Genius Online portal login credentials
- A service account API key
- The outlet reference for your trading outlet
Keep your API key on your server. Never put it in browser JavaScript or a mobile app. The examples below use the sandbox; production endpoints are provided with your live credentials.
Authentication
Request an access token first. It expires after 5 minutes and is required for every other call.
POSThttps://api-gateway.sandbox.mybank.ngenius-payments.com/identity/auth/access-token
| Header | Value |
|---|---|
| Content-Type | application/vnd.ni-identity.v1+json |
| Authorization | Basic your_api_key |
$apikey = 'your_api_key';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api-gateway.sandbox.mybank.ngenius-payments.com/identity/auth/access-token");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"accept: application/vnd.ni-identity.v1+json",
"authorization: Basic ".$apikey,
"content-type: application/vnd.ni-identity.v1+json"
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
$output = json_decode(curl_exec($ch));
$access_token = $output->access_token;Create an order
Each payment needs an order, which you use for tracking and management.
POSThttps://api-gateway.sandbox.mybank.ngenius-payments.com/transactions/outlets/[outlet-reference]/orders
| Parameter | Description | Example |
|---|---|---|
| action | Order type | "PURCHASE" |
| amount.currencyCode | Order currency | "AED", "USD", "EUR" |
| amount.value | Order amount in minor units | 1000 (= 10.00) |
$postData = new StdClass();
$postData->action = "PURCHASE";
$postData->amount = new StdClass();
$postData->amount->currencyCode = "USD";
$postData->amount->value = 900;
$postData->emailAddress = "customer@test.com";
$postData->merchantOrderReference = "ORDER-123";
$postData->merchantAttributes = new StdClass();
$postData->merchantAttributes->redirectUrl = "https://your-site.com/payment/callback";
$postData->merchantAttributes->skipConfirmationPage = true;
$json = json_encode($postData);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api-gateway.sandbox.mybank.ngenius-payments.com/transactions/outlets/".$outlet."/orders");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer ".$access_token,
"Content-Type: application/vnd.ni-payment.v2+json",
"Accept: application/vnd.ni-payment.v2+json"
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$response = json_decode(curl_exec($ch));Webhooks
Webhooks send you payment status updates in real time, so you do not need to poll for order status.
| Event | Meaning |
|---|---|
| AUTHORISED | Payment has been authorised |
| CAPTURED | Payment has been captured in full |
| DECLINED | Payment was declined by the issuing bank |
| REFUNDED | Payment has been refunded |
<?php
// Receive webhook data
$payload = file_get_contents('php://input');
$event = json_decode($payload);
// Verify webhook signature (implement your own security checks)
if (!verifyWebhookSignature($payload)) {
http_response_code(401);
exit('Invalid signature');
}
// Process the event
switch ($event->eventName) {
case 'AUTHORISED':
handleAuthorizedPayment($event->order);
break;
case 'CAPTURED':
handleCapturedPayment($event->order);
break;
case 'DECLINED':
handleDeclinedPayment($event->order);
break;
// Handle other events...
}
// Always respond with 200 OK
http_response_code(200);
echo json_encode(['status' => 'success']);Support
For help with your integration or a merchant account:
- E-mail: callcenter@mybank.so
- Phone: +252 61 3737777