Build a complete payment integration
Collect a mobile money payment with Direct Receive Money, handle the callback, deal with failed payments and reconcile payments whose callback doesn't arrive.
To collect a mobile money payment, send a payment request from your server, wait for Hubtel's callback with the final result, and check the status of any payment that has no result after 5 minutes.
Before you start(4)
- Create one at business.hubtel.com
A Hubtel business with a merchant account
Business APIs work through your business's merchant account. If you don't have one yet, sign up and set it up first.
- Payment keys
API ID and API key
They identify you on every request. Send them using HTTP Basic authentication.
- Account IDs
Collection account number
This is where your customers' payments arrive. You'll add it to the request URL.
- IP allowlisting
An allowlisted server IP address
Send your server's public IP address to Hubtel to get it allowlisted. Until then, your requests return 403 Forbidden or time out.
Don't have these yet? Start in the sandbox with your test keys while you set them up.
This guide uses Direct Receive Money because your server handles each stage of the payment directly. If you take payments on a website, Online Checkout hosts the payment page for you, but the callback and reconciliation steps below still apply.
How a mobile money payment works
- Your server sends a payment request to Hubtel. Hubtel returns
0001: pending. - The customer receives a prompt on their phone. They can approve it with their PIN, decline it, or let it expire.
- Hubtel sends the final result in a POST request to your
PrimaryCallbackUrl. - If no callback arrives within 5 minutes, your server requests the result with Check a collection's status.
Your integration needs to handle a customer who doesn't respond, a failed payment and a callback that never arrives.
Prepare your integration
Set the example environment variables, deploy your callback endpoint, and replace the sample customer number and callback URL. These examples call production and can move real money. To test first, use the sandbox host, keys and test numbers. In C#, initialise apiId, apiKey and collectionAccount from the corresponding environment variables.
1. Charge the wallet
curl https://rmp.hubtel.com/merchantaccount/merchants/$HUBTEL_COLLECTION_ACCOUNT/receive/mobilemoney \
-u "$HUBTEL_API_ID:$HUBTEL_API_KEY" -H "Content-Type: application/json" \
-d '{"CustomerMsisdn":"233249111411","Channel":"mtn-gh","Amount":45.00,"Description":"Order #1042","ClientReference":"order-1042","PrimaryCallbackUrl":"https://example.com/hubtel/callback"}'Check the HTTP status and response body before saving the result. An accepted request has ResponseCode "0001": the payment is pending while the customer approves it on their phone. Save the order as awaiting payment.
Use a new ClientReference for every payment (your order ID works) of at most 36 characters. If the request times out, don't send it again: check the status with the same reference first. See Client references.
2. Receive the callback
Hubtel POSTs the final result to your PrimaryCallbackUrl, usually within 30 seconds:
{
"ResponseCode": "0000",
"Message": "success",
"Data": { "Amount": 45, "Charges": 0.88, "AmountAfterCharges": 45, "Description": "The MTN Mobile Money payment has been approved and processed successfully", "ClientReference": "order-1042", "TransactionId": "a1c92e8776b0964b1b2448ba16528876", "OrderId": "a1c92e8776b0964b1b2448ba16528876", "AmountCharged": 45.88 }
}Follow Handle a callback to validate and store the result, acknowledge delivery, and fulfil once. Use the documented Receive Money callback address and verify the payment before delivery.
Store the OrderId too: you need it to refund the payment.
3. Handle failed payments
A failed Receive Money callback has ResponseCode 2001, for example when the customer declines or has insufficient funds. Read Data.Description, show the customer a clear message, and let them try again with a new ClientReference. Treat an unexpected code or missing result as unresolved; check the status before starting another payment.
4. Reconcile payments without a callback
Check the status of any payment that has no final result after 5 minutes. This is mandatory:
curl "https://api-txnstatus.hubtel.com/transactions/$HUBTEL_COLLECTION_ACCOUNT/status?clientReference=order-1042" \
-u "$HUBTEL_API_ID:$HUBTEL_API_KEY"A data.status of Paid means you can fulfil the order. Reconciliation and status checks explains how to schedule and process these checks.
Test the complete flow
Use the sandbox scenarios to test success, failure and a lost callback. Confirm that a successful payment fulfils once, a failed payment does not fulfil, and a lost callback is resolved by your status check. Then complete the go-live steps.
Requests and responses
Client references, amounts and fees, phone numbers, channel codes, field casing, asynchronous results and rate limits across the Hubtel APIs.
Networking & IP allowlisting
Get your server IPs allowlisted (whitelisted) for Hubtel services that require it, and give serverless apps a static outbound IP address.