External payment gateway
Most organisations connect their own payment providers. A deployment can also connect one external gateway: a separate service that takes payments for its organisations and pays them out. Any service that implements the protocol below can be connected.
The gateway is optional and off by default. Without it, PimaBill works the same and shows nothing about it.
Connect a gateway
Set these on the API and worker:
| Setting | Meaning |
|---|---|
GATEWAY_URL | The gateway's base address |
GATEWAY_API_KEY | The key that identifies this deployment |
GATEWAY_WEBHOOK_SECRET | The secret the gateway signs notifications with |
How organisations join
The gateway owns its application and account pages. When it says an organisation is eligible, the dashboard shows an Apply button in Settings → Payment providers, which opens the gateway's page. Send a notification when the account opens, and PimaBill stores its id.
Protocol
Requests are JSON over HTTPS, with Authorization: Bearer <GATEWAY_API_KEY>. The gateway answers errors with a non-2xx status and { "message": "..." }.
| Request | Purpose |
|---|---|
GET /v1/eligibility?externalId=:id | Answer { "eligible": true } when this organisation may apply |
POST /v1/account-links | Answer { "url", "expiresAt" }: a short-lived link to your own page, where the organisation applies and manages its account. Sent with externalId, notificationUrl and returnUrl. |
GET /v1/accounts/:id | Read the account: id, status, methods, and optional fee, wallets and balances |
POST /v1/accounts/mirror | Sandbox only: return the account set up from the organisation's approved live one, or 404 |
POST /v1/collections | Start a payment. Sent with an Idempotency-Key equal to reference. |
GET /v1/collections/:reference?account=:id | Read a payment |
An account's status is pending_review, active, rejected or suspended. Its methods list what its customers can use: card, mobile_money and paypal. Its wallets name mobile money wallets by currency, such as { "UGX": ["MTN", "Airtel"] }. Its balances give the money you hold for the organisation per currency, such as { "UGX": { "available": "200000", "pending": "50000" } }, shown on the dashboard's Money page.
Start a payment
{
"account": "acc_123",
"reference": "pay_456",
"amount": "50000",
"currency": "UGX",
"description": "Invoice INV-1001",
"method": "card",
"customer": { "email": "payer@example.com", "name": "A Payer" },
"redirectUrl": "https://example.com/done",
"notificationUrl": "https://api.example.com/webhooks/gateway/<organisation id>/callback"
}
The response has reference, status (pending, succeeded or failed), amount, currency, and checkoutUrl when the payer has a page to visit. Reading a payment can also return providerReference, fees and failureReason.
Notifications
The gateway posts to the notificationUrl it was given, with this header:
X-Gateway-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256 of "t.body">
The HMAC uses GATEWAY_WEBHOOK_SECRET. Signatures older than ten minutes are refused.
| Body | Effect |
|---|---|
{ "id": "...", "account": { "id": "...", "externalId": "...", "status": "active" } } | Stores a new account, and turns the organisation's gateway connection on or off with the status |
{ "id": "...", "collection": { "reference": "pay_456" } } | PimaBill reads the payment from the gateway, then settles it |
PimaBill never trusts the content of a payment notification. It always asks the gateway for the payment, and holds it for review when the amount paid differs from the amount asked.