Selcom
Selcom

Selcom Business API Gateway

The Selcom Business API Gateway provides a secure, REST-based interface that allows your applications to programmatically initiate payments, check account balances, and track transaction statuses — all from a single integration point.

Secure by Design

Every request is authenticated using an HMAC-based digest signature combining your API key, secret, and a time-bounded timestamp.

Real-time Processing

Transactions are processed in real time via the Selcom infrastructure, with instant status tracking through a dedicated status endpoint.

Multi-channel Support

Send money to bank accounts, mobile wallets, or other Selcom Business accounts — all through a unified API interface.

Sandbox URL: https://sandbox.selcom.business — All endpoints listed in this documentation are relative to this base URL.
Production URL: https://api.selcom.business/v1 — All endpoints listed in this documentation are relative to this base URL.

Getting Started

  1. Obtain API Credentials

    Log in to Selcom Business and navigate to My Account → API Credentials to generate your Signing Keys.

  2. Build Request Headers

    Compute the digest. See Authorization and Signature Generation for the formulas.

    api-key timestamp digest signed-fields
  3. Make Your First API Call

    Try the Balance API to verify your credentials and Bearer token are working correctly.

Overview

Client Packages

Following are links to the client library code repositories on GitHub and ways to install using package managers. For more information and source code visit the GitHub pages.

PHP

Installation
bash
composer require selcom/selcom-apigw-client
GitHub Link

PHP GitHub Repository

JAVA

Installation
bash
io.github.selcompaytechltd/apigwClient
Get the snippet for your package manager from https://central.sonatype.com/artifact/io.github.selcompaytechltd/apigwClient/1.0.3/overview

or search for io.github.selcompaytechltd/apigwClient using your package manager.

GitHub Link

JAVA GitHub Repository

C#

Installation
bash
dotnet add package selcom-apigw-client
GitHub Link

C# GitHub Repository

Python

Installation
bash
pip install selcom_apigw_client
GitHub Link

Python GitHub Repository

Node.js

Installation
bash
npm i selcom-apigw-client
GitHub Link

Node.js GitHub Repository

Security

Authorization

The API Gateway uses RSA-SHA256 asymmetric signing for authentication. Your api-key and RSA private key are available from the credentials panel — both are required to sign every request.

How It Works

Each request must include four headers: your api-key, a UTC ISO 8601 timestamp, a computed digest, and a signed-fields list. The server verifies the digest using your stored RSA public key and rejects requests with an invalid signature.

Signing String & digest Format

signing_string = "timestamp=<timestamp>&field1=value1&field2=value2&..."
digest = Base64( RSA_SHA256(signing_string, PrivateKey) )
  • timestamp is always first in the signing string.
  • Fields follow in the exact order listed in the signed-fields header.
  • Values must match the request payload exactly — no extra spaces.
  • timestamp format is ISO 8601 UTC with milliseconds (e.g. 2026-05-27T06:01:03.273Z).
  • The timestamp header value and the value in the signing string must be identical.

Implementation Examples

PHP
$apiKey     = 'YOUR_API_KEY';
$privateKey = file_get_contents('/path/to/private_key.pem');
$timestamp  = (new DateTime('now', new DateTimeZone('UTC')))->format('Y-m-d\TH:i:s.v\Z');

// Request fields (POST body or GET query params)
$fields = [
    'transId'          => '1234567899',
    'recipientFiCode'  => 'SELCOM',
    'recipientAccount' => '255711410410',
    'amount'           => 100,
];

$signedFields  = implode(',', array_keys($fields));
$signingString = 'timestamp=' . $timestamp;
foreach ($fields as $key => $value) {
    $signingString .= '&' . $key . '=' . $value;
}

openssl_sign($signingString, $signature, $privateKey, OPENSSL_ALGO_SHA256);
$digest = base64_encode($signature);

$headers = [
    'api-key: '       . $apiKey,
    'timestamp: '     . $timestamp,
    'digest: '        . $digest,
    'signed-fields: ' . $signedFields,
    'content-type: application/json',
];
Python
import base64
from datetime import datetime, timezone
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import padding

api_key = 'YOUR_API_KEY'
now     = datetime.now(timezone.utc)
timestamp = now.strftime('%Y-%m-%dT%H:%M:%S.') + f"{now.microsecond // 1000:03d}Z"

with open('/path/to/private_key.pem', 'rb') as f:
    private_key = serialization.load_pem_private_key(f.read(), password=None)

fields = {
    'transId':          '1234567899',
    'recipientFiCode':  'SELCOM',
    'recipientAccount': '255711410410',
    'amount':           100,
}

signed_fields  = ','.join(fields.keys())
signing_string = 'timestamp=' + timestamp + '&' + \
                 '&'.join(f"{k}={v}" for k, v in fields.items())

signature = private_key.sign(signing_string.encode(), padding.PKCS1v15(), hashes.SHA256())
digest    = base64.b64encode(signature).decode()

headers = {
    'api-key':       api_key,
    'timestamp':     timestamp,
    'digest':        digest,
    'signed-fields': signed_fields,
    'content-type':  'application/json',
}
JavaScript / Node.js
const crypto = require('crypto');
const fs     = require('fs');

const apiKey     = 'YOUR_API_KEY';
const privateKey = fs.readFileSync('/path/to/private_key.pem', 'utf8');
const timestamp  = new Date().toISOString(); // e.g. 2026-05-27T06:01:03.273Z

const fields = {
    transId:          '1234567899',
    recipientFiCode:  'SELCOM',
    recipientAccount: '255711410410',
    amount:           100,
};

const signedFields  = Object.keys(fields).join(',');
const signingString = 'timestamp=' + timestamp + '&' +
    Object.entries(fields).map(([k, v]) => `${k}=${v}`).join('&');

const sign   = crypto.createSign('RSA-SHA256');
sign.update(signingString, 'utf8');
const digest = sign.sign(privateKey, 'base64');

const headers = {
    'api-key':       apiKey,
    'timestamp':     timestamp,
    'digest':        digest,
    'signed-fields': signedFields,
    'content-type':  'application/json',
};
Security reminder: Never expose your RSA private key in client-side code, mobile apps, or public repositories. Store it securely on your server. The timestamp header value must be identical to the one used in the signing string — even a single character difference will fail verification.
Reference

Request Headers

Every request to the API Gateway must include the following HTTP headers. Missing or malformed headers will result in a 400 Bad Request response.

Header Required Format / Example Description
api-key Required a1b2c3d4e5... Your unique API key obtained from the credentials panel.
timestamp Required 2026-05-27T06:01:03.273Z Current UTC time in ISO 8601 format with milliseconds. Must be identical to the value used in the signing string.
digest Required Base64 encoded string RSA-SHA256 signature of the signing string, Base64-encoded. See Authorization for the formula.
signed-fields Required transId,amount,msisdn Comma-separated list of request field names (POST body or GET query params) in the exact same order as the signing string. Do not include timestamp.
Origin Required https://example.com Must exactly match one of the domains registered against your API credential (see the Domain field in the API credentials).
Content-Type Required for POST application/json Must be application/json for all POST endpoints.
Accept Optional application/json Recommended. All responses are returned as JSON.

Signing String Generation

The digest is an RSA-SHA256 signature over a canonical signing string built from the timestamp and the request fields listed in signed-fields.

Signing String & Digest Format
signing_string = "timestamp=" + timestamp + "&" + field1 + "=" + value1 + "&" + ...
digest = Base64( RSA_SHA256(signing_string, PrivateKey) )
  • timestamp is always first, even though it is not listed in signed-fields.
  • Fields follow in the exact order listed in the signed-fields header.
  • Values must match the request payload exactly — no extra spaces or type conversions.
  • For GET requests, use query parameter names and values.
  • For POST requests, use JSON body field names and values.
Implementation Examples
PHP
$apiKey     = 'YOUR_API_KEY';
$privateKey = file_get_contents('/path/to/private_key.pem');
$timestamp  = (new DateTime('now', new DateTimeZone('UTC')))->format('Y-m-d\TH:i:s.v\Z');

$fields = [
    'transId'          => '1234567899',
    'recipientFiCode'  => 'SELCOM',
    'recipientAccount' => '255711410410',
    'recipientName'    => 'John Doe',
    'amount'           => 100,
    'purpose'          => 'FT',
];

$signedFields  = implode(',', array_keys($fields));
$signingString = 'timestamp=' . $timestamp;
foreach ($fields as $key => $value) {
    $signingString .= '&' . $key . '=' . $value;
}

openssl_sign($signingString, $signature, $privateKey, OPENSSL_ALGO_SHA256);
$digest = base64_encode($signature);

$headers = [
    'api-key: '       . $apiKey,
    'timestamp: '     . $timestamp,
    'digest: '        . $digest,
    'signed-fields: ' . $signedFields,
    'content-type: application/json',
];
Python
import base64
from datetime import datetime, timezone
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import padding

api_key = 'YOUR_API_KEY'
now     = datetime.now(timezone.utc)
timestamp = now.strftime('%Y-%m-%dT%H:%M:%S.') + f"{now.microsecond // 1000:03d}Z"

with open('/path/to/private_key.pem', 'rb') as f:
    private_key = serialization.load_pem_private_key(f.read(), password=None)

fields = {
    'transId':          '1234567899',
    'recipientFiCode':  'SELCOM',
    'recipientAccount': '255711410410',
    'recipientName':    'John Doe',
    'amount':           100,
    'purpose':          'FT',
}

signed_fields  = ','.join(fields.keys())
signing_string = 'timestamp=' + timestamp + '&' + \
                 '&'.join(f"{k}={v}" for k, v in fields.items())

signature = private_key.sign(signing_string.encode(), padding.PKCS1v15(), hashes.SHA256())
digest    = base64.b64encode(signature).decode()

headers = {
    'api-key':       api_key,
    'timestamp':     timestamp,
    'digest':        digest,
    'signed-fields': signed_fields,
    'content-type':  'application/json',
}
JavaScript / Node.js
const crypto = require('crypto');
const fs     = require('fs');

const apiKey     = 'YOUR_API_KEY';
const privateKey = fs.readFileSync('/path/to/private_key.pem', 'utf8');
const timestamp  = new Date().toISOString(); // e.g. 2026-05-27T06:01:03.273Z

const fields = {
    transId:          '1234567899',
    recipientFiCode:  'SELCOM',
    recipientAccount: '255711410410',
    recipientName:    'John Doe',
    amount:           100,
    purpose:          'FT',
};

const signedFields  = Object.keys(fields).join(',');
const signingString = 'timestamp=' + timestamp + '&' +
    Object.entries(fields).map(([k, v]) => `${k}=${v}`).join('&');

const sign   = crypto.createSign('RSA-SHA256');
sign.update(signingString, 'utf8');
const digest = sign.sign(privateKey, 'base64');

const headers = {
    'api-key':       apiKey,
    'timestamp':     timestamp,
    'digest':        digest,
    'signed-fields': signedFields,
    'content-type':  'application/json',
};

Sample Raw Request (Protected Endpoint)

HTTP
POST /v1/transaction/process HTTP/1.1
Host: api.selcom.business
api-key: a1b2c3d4e5f6g7h8i9j0
timestamp: 2026-05-27T06:01:03.273Z
digest: Base64EncodedRSASignature==
signed-fields: transId,recipientFiCode,recipientAccount,recipientName,amount,purpose,remarks
Origin: https://example.com
content-type: application/json
Accept: application/json

{
    "transId": "1234567899",
    "recipientFiCode": "SELCOM",
    "recipientAccount": "255711410410",
    "recipientName": "John Doe",
    "amount": 100,
    "purpose": "FT",
    "remarks": "Test transfer"
}

Error Responses for Header Failures

HTTP Status error_code Cause
400 612 One or more required headers are missing.
401 613 API key not found or inactive.
401 631 digest does not match — invalid RSA signature.
403 611 Client IP is not whitelisted for this credential.
403 617 No domain is registered for this API key, or the Origin header does not match a registered domain.
503 613 Authentication service is temporarily unavailable — retry the request after a short delay.
Reference

Purpose Codes

Every transaction request requires a purpose field. Use the Code value from the table below. Only active purposes are listed.

# Purpose Name Code
1 Payment PAYMENT
2 Airfare AIRFARE
3 Airtime AIRTIME
4 Betting and gaming BETTING
5 Business expense BUSINESSEXPENSES
6 Car repair CARREPAIR
7 Cash CASH
8 Contribution CONTRIBUTE
9 Contributions CONTRIBUTES
10 Dining DINING
11 Donation DONATION
12 Dry cleaning DRYCLEANING
13 Education EDUCATION
14 Entertainment ENTERTAINMENT
15 Fitness FITNESS
16 Fuel FUEL
17 Funds transfer FT
18 General repairs GENERALREPAIRS
19 General/uncategorized GENERAL
20 Gift GIFT
21 Gift Cards GIFTCARD
22 Government payment GOV
23 Groceries and essentials GROCERIES
24 Health and fitness HEALTH
25 House repair HOUSEREPAIR
26 Insurance INSURANCE
27 Internet and broadband INTERNET
28 Investments INVEST
29 Legal fees LEGALFEES
30 Loan repayment LOAN
31 Logistics & Shipment SHIPMENT
32 Lottery LOTTERY
33 Medical Bills MEDICALBILLS
34 Office/business expense OFFICEEXPENSE
35 Personal care PERSONALCARE
36 Renewable energy RENERGY
37 Salary and other income INCOME
38 Salary or wages SALARYOFWAGES
39 Savings SAVINGS
40 Shopping SHOPPING
41 Social contribution SOCIALCONTRIBUSTION
42 Stocks & Securities STOCKS
43 Taxes and fines TAX
44 Transport TRANSPORT
45 Travel TRAVEL
46 TV subscription TV
47 Utility payment UTILITY
Use the exact Code value in the purpose field of your transaction request. Invalid codes will result in a validation error (error_code: 651).
Endpoint

Balance API

Retrieve the current available balance for a linked organization account.

POST /v1/balance

Request Body

Parameter Type Required Description
account_number string Required The account number associated with your API credentials. Must be an active B2C account registered under your organization.

Response Fields

Field Type Description
success boolean true on success, false on failure.
error_code integer 1 on success; negative value on error (see Error Codes).
message string Human-readable status message.
data.account_number string The queried account number.
data.currency string Account currency (e.g., TZS).
data.available_balance float Current available balance in the account.
data.active boolean true if the account is currently active; false otherwise.
result string Transaction result based on actual status. See API Response — Result column.
resultcode string Result code based on actual transaction status. See API Response — Errorcode column.

Example

Request
{
    "account_number": "0123456789"
}
Response 200 OK
{
    "success": true,
    "error_code": 1,
    "message": "Balance fetched successfully.",
    "result": "SUCCESS",
    "resultcode": "000",
    "data": {
        "account_number": "000011636",
        "currency": "TZS",
        "available_balance": 100000000,
        "active": true
    }
}
Error Response 400
{
    "success": false,
    "error_code": 641,
    "message": "Invalid or unauthorized account number.",
    "result": "FAIL",
    "resultcode": "641",
    "data": []
}
Webhook

Webhook (Callback)

Selcom sends a POST request to your registered callback URL when an API-initiated transaction completes successfully. Only the parameters you select will be included in the payload. For TIPS / TISS transactions, the callback fires after final network confirmation is received.

Callback URL *

A publicly reachable HTTPS endpoint on your server. Selcom will POST the transaction payload to this URL on every successful transaction.

Configuration Fields

Field Type Required Description
callback_url string Required The HTTPS URL that will receive the POST callback. Maximum 500 characters.
callback_parameters array Required The payload fields to include in the callback. At least one parameter must be selected.

Callback Payload

Every callback always includes reference_id and status. All other fields are included only if selected in the callback configuration.

Payload Fields

Field Type Description
reference_id string Your unique transaction reference ID from the original API request. Always included.
status string Always SUCCESS. Callbacks are only sent for successful transactions. Always included.
sender_account_name string Name of the sending (debit) account.
sender_account_number string Account number of the sender.
recipient_name string Name of the transaction recipient.
recipient_account_number string Destination account number or phone number of the recipient.
amount numeric Principal transaction amount excluding charges.
charges numeric Transaction charges applied. May be 0 if no charges apply.
selcom_receipt string Selcom-issued receipt number for the transaction.

Example

Callback POST (to your server)
{
    "reference_id": "2024061500123",
    "status": "SUCCESS",
    "sender_account_name": "Acme Limited",
    "sender_account_number": "0000123456",
    "recipient_name": "John Doe",
    "recipient_account_number": "255712345678",
    "amount": 50000,
    "charges": 500,
    "selcom_receipt": "202406150001"
}
Webhook

Credit Transaction Callback

Selcom sends a POST request to your registered credit callback URL whenever money is credited (received) into your API-linked account. Only the response parameters you select are included in the payload. Every callback carries a digest header that you validate with your RSA private key to confirm the request genuinely came from Selcom.

Setup

Prerequisites

  • An active API credential with an RSA key pair (the same credential you use for the API Gateway). Keep the RSA private key and api-key — both are needed to validate callbacks.
  • The credited account must be your API-linked (disbursement) account. Credits to other accounts of your organization do not trigger this callback.
  • A publicly reachable HTTPS endpoint on your server.
  • Login with an Organization Admin role.

Steps

  1. Log in to Selcom Business and go to My Account → API Credentials.
  2. Click Add Credit Callback Configuration (top right of the API Credentials list).
  3. Enter your Credit Callback URL (HTTPS only) and click Test URL. The URL must be reachable before you can save.
  4. Select the Response Parameters to receive: Transaction ID, Selcom Receipt, Amount, Balance, Details.
  5. Click Save.
    • If your organization has more than one admin, the request goes to the other admin(s) for approval. The configuration becomes active once approved.
    • With a single admin, the configuration is saved and activated immediately.
  6. Once active, the link changes to Edit Credit Callback Configuration. Changing the URL or parameters follows the same approval flow.

Configuration Fields

Field Type Required Description
callback_url string Required HTTPS URL that receives the POST callback. Maximum 500 characters.
callback_parameters array Required Response parameters to include in data. At least one must be selected.

When Is the Callback Sent?

  • When a credit (incoming transfer / deposit) is successfully posted to your API-linked account.
  • Sent asynchronously within a few seconds of the credit.
  • Your endpoint must respond with any HTTP 2xx status within 30 seconds.
  • On timeout or a non-2xx response, Selcom retries up to 3 times (after ~1 minute, then ~5 minutes).
  • Because of retries, the same credit can be delivered more than once — de-duplicate using data.selcom_receipt (or data.transaction_id).

Callback Request

event and status are always included. Fields inside data are included only if selected. All values inside data are strings.

Request Headers

Header Description
timestamp ISO 8601 date-time when Selcom generated the callback (e.g. 2026-11-26T12:04:46+03:00). Use it exactly as received in the signing string.
digest-method Always RSA-SHA256-ENC — SHA-256 hash, RSA-encrypted with your public key (see Validating the Request).
signed-fields Comma-separated list of body fields covered by the digest, in signing order. data.x refers to key x inside the data object.
digest Base64( RSA-OAEP-Encrypt( SHA256(signing_string), YourPublicKey ) )
api-key-suffix Last 4 characters of your api-key — helps you pick the right private key if you have several credentials.
X-Callback-Type Always credit_transaction.

Body Fields

Field Type Description
event string Always CREDIT_TRANSACTION. Always included.
status string Always SUCCESS — callbacks are sent only for successful credits. Always included.
data.transaction_id string Transaction ID of the credit. Parameter: Transaction ID
data.selcom_receipt string Selcom-issued receipt number. Parameter: Selcom Receipt
data.amount string Credited amount. Parameter: Amount
data.currency string Currency code (e.g. TZS). Included automatically when Amount or Balance is selected.
data.balance string Account balance after the credit. Parameter: Balance
data.details string Full narration of the credit, including sender remarks. May be null. Parameter: Details

Example (all parameters selected)

Callback POST Headers (to your server)
POST /your/credit-callback HTTP/1.1
Content-Type: application/json
Accept: application/json
X-Callback-Type: credit_transaction
timestamp: 2026-11-26T12:04:46+03:00
digest-method: RSA-SHA256-ENC
signed-fields: event,status,data.transaction_id,data.selcom_receipt,data.amount,data.currency,data.balance,data.details
digest: s7dhxy+LWQicheZS7T1/owDYM78Lgy6sOmI2FTquv8zfvBvQ9EnCu0kBIMckyAAK8yPXdt62nzGEbg1kjf+ewKp0Vwi91Cf+EV6MwwerM1oEVPXvg7C1qOWpAbezD10v59woEaPQbSd7GNdAZtiev0SBhchEG5UqECWMeA0vSB7MtgOegLhjqBkO0E7zm7GyHKJ1efsS/5+KzuaRFkmdVhYJlQTAK6vAKPxy1pV3OAhjlvHBJulU6hzpG1JqJj07V+bPmdSqL8vzT6AN2/zhhRGeedPw21qm70ihmByEM3cRMQSN5PjmJxSQmW3YDiuK+nTos1QSMf+20CSdUuUSkg==
api-key-suffix: 5a6f
Callback POST Body
{
    "event": "CREDIT_TRANSACTION",
    "status": "SUCCESS",
    "data": {
        "transaction_id": "105587412366",
        "selcom_receipt": "8A2K19XQ7M",
        "amount": "150000.00",
        "currency": "TZS",
        "balance": "2450000.00",
        "details": "Transfer from ABC TRADERS LTD REMARKS: INV-2026-077"
    }
}
Expected Response 200 OK
{
    "received": true
}

With only Amount selected, the body is {"event":"CREDIT_TRANSACTION","status":"SUCCESS","data":{"amount":"150000.00","currency":"TZS"}} and signed-fields is event,status,data.amount,data.currency.

Validating the Request

This is the reverse of API Gateway signing. For API requests you sign with your private key and Selcom verifies with your public key (RSA-SHA256). For callbacks Selcom only holds your public key, so it encrypts the SHA-256 hash with it, and you decrypt it with your private key and compare. Do not use a signature verify function (openssl_verify, SHA256withRSA, crypto.verify) — it will always fail.

Signing String & digest Format

signing_string = "timestamp=<timestamp>&api_key=<your api-key>&field1=value1&field2=value2&..."
digest = Base64( RSA-OAEP-Encrypt( SHA256(signing_string), YourPublicKey ) )
  • timestamp comes first, then api_key, then the fields in the exact signed-fields order.
  • api_key is your own api-key. It is never sent in the callback — you insert it yourself. This proves the callback came from Selcom: anyone can encrypt with your public key, but only Selcom also knows your api-key.
  • For data.x use the value of x inside data. A null value is an empty string.
  • Use values exactly as they appear after JSON-decoding the body — no trimming, no URL-encoding.
  • SHA-256 output is the raw 32 bytes (not hex). RSA padding is OAEP with SHA-1 / MGF1-SHA-1.
  • The digest is different on every callback (OAEP is randomised) — this is expected.

Validation Steps

  1. Check digest-method is RSA-SHA256-ENC.
  2. Reject if timestamp is more than 5 minutes from your server time (replay protection).
  3. JSON-decode the body and rebuild the signing string using the timestamp header, your api-key and the signed-fields values.
  4. Base64-decode digest and decrypt it with your RSA private key (OAEP).
  5. Compute SHA256(signing_string) and compare with the decrypted bytes (constant-time compare).
  6. If they match, the request is genuine and untampered. De-duplicate on data.selcom_receipt, process the credit and return HTTP 200. Otherwise return 401.

Implementation Examples

PHP
$myApiKey   = 'YOUR_API_KEY';
$privateKey = file_get_contents('/path/to/private_key.pem');

function verifyCreditCallback(array $headers, string $rawBody, string $myApiKey, string $privateKey): bool
{
    $h    = array_change_key_case($headers, CASE_LOWER);
    $body = json_decode($rawBody, true);

    // 1. digest-method + timestamp window (5 minutes)
    if (($h['digest-method'] ?? '') !== 'RSA-SHA256-ENC') return false;
    if (abs(time() - strtotime($h['timestamp'] ?? '')) > 300) return false;

    // 2. Rebuild signing string
    $signingString = 'timestamp=' . $h['timestamp'] . '&api_key=' . $myApiKey;
    foreach (explode(',', $h['signed-fields'] ?? '') as $field) {
        $value = str_starts_with($field, 'data.')
            ? ($body['data'][substr($field, 5)] ?? '')
            : ($body[$field] ?? '');
        $signingString .= '&' . $field . '=' . $value;
    }

    // 3. Decrypt digest with private key (OAEP) and compare with SHA-256
    $encrypted = base64_decode($h['digest'] ?? '', true);
    if ($encrypted === false
        || !openssl_private_decrypt($encrypted, $decryptedHash, $privateKey, OPENSSL_PKCS1_OAEP_PADDING)) {
        return false;
    }

    return hash_equals(hash('sha256', $signingString, true), $decryptedHash);
}

// ---- Your callback endpoint ----
$rawBody = file_get_contents('php://input');

if (!verifyCreditCallback(getallheaders(), $rawBody, $myApiKey, $privateKey)) {
    http_response_code(401);
    exit;
}

$payload = json_decode($rawBody, true);
// De-duplicate on $payload['data']['selcom_receipt'], then process the credit

http_response_code(200);
echo json_encode(['received' => true]);
Python
import base64, hashlib, hmac, json
from datetime import datetime, timezone
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import padding

MY_API_KEY = 'YOUR_API_KEY'
with open('/path/to/private_key.pem', 'rb') as f:
    PRIVATE_KEY = serialization.load_pem_private_key(f.read(), password=None)

def verify_credit_callback(headers, raw_body):
    h = {k.lower(): v for k, v in headers.items()}

    # 1. digest-method + timestamp window (5 minutes)
    if h.get('digest-method') != 'RSA-SHA256-ENC':
        return False
    ts = h.get('timestamp', '')
    try:
        age = abs((datetime.now(timezone.utc) - datetime.fromisoformat(ts)).total_seconds())
    except ValueError:
        return False
    if age > 300:
        return False

    # 2. Rebuild signing string
    body = json.loads(raw_body)
    data = body.get('data') or {}
    signing_string = f"timestamp={ts}&api_key={MY_API_KEY}"
    for field in h.get('signed-fields', '').split(','):
        value = data.get(field[5:]) if field.startswith('data.') else body.get(field)
        signing_string += f"&{field}={'' if value is None else value}"

    # 3. Decrypt digest with private key (OAEP SHA-1) and compare with SHA-256
    try:
        decrypted = PRIVATE_KEY.decrypt(
            base64.b64decode(h.get('digest', '')),
            padding.OAEP(mgf=padding.MGF1(hashes.SHA1()), algorithm=hashes.SHA1(), label=None),
        )
    except Exception:
        return False

    expected = hashlib.sha256(signing_string.encode('utf-8')).digest()
    return hmac.compare_digest(expected, decrypted)

# ---- Flask example ----
# @app.post('/your/credit-callback')
# def credit_callback():
#     raw = request.get_data(as_text=True)
#     if not verify_credit_callback(request.headers, raw):
#         return '', 401
#     payload = json.loads(raw)   # de-duplicate on payload['data']['selcom_receipt']
#     return {'received': True}, 200
JavaScript / Node.js
const crypto  = require('crypto');
const fs      = require('fs');
const express = require('express');

const MY_API_KEY  = 'YOUR_API_KEY';
const PRIVATE_KEY = fs.readFileSync('/path/to/private_key.pem', 'utf8');

function verifyCreditCallback(headers, rawBody) {
    const h = Object.fromEntries(Object.entries(headers).map(([k, v]) => [k.toLowerCase(), v]));

    // 1. digest-method + timestamp window (5 minutes)
    if (h['digest-method'] !== 'RSA-SHA256-ENC') return false;
    const ts = h['timestamp'] || '';
    if (Number.isNaN(Date.parse(ts)) || Math.abs(Date.now() - Date.parse(ts)) > 5 * 60 * 1000) return false;

    // 2. Rebuild signing string
    const body = JSON.parse(rawBody);
    const data = body.data || {};
    let signingString = `timestamp=${ts}&api_key=${MY_API_KEY}`;
    for (const field of (h['signed-fields'] || '').split(',')) {
        const value = field.startsWith('data.') ? data[field.slice(5)] : body[field];
        signingString += `&${field}=${value ?? ''}`;
    }

    // 3. Decrypt digest with private key (OAEP SHA-1) and compare with SHA-256
    let decrypted;
    try {
        decrypted = crypto.privateDecrypt(
            { key: PRIVATE_KEY, padding: crypto.constants.RSA_PKCS1_OAEP_PADDING, oaepHash: 'sha1' },
            Buffer.from(h['digest'] || '', 'base64')
        );
    } catch (e) {
        return false;
    }
    const expected = crypto.createHash('sha256').update(signingString, 'utf8').digest();
    return expected.length === decrypted.length && crypto.timingSafeEqual(expected, decrypted);
}

// ---- Express endpoint (read the raw body as text) ----
const app = express();
app.post('/your/credit-callback', express.text({ type: '*/*' }), (req, res) => {
    if (!verifyCreditCallback(req.headers, req.body)) return res.status(401).end();

    const payload = JSON.parse(req.body);
    // De-duplicate on payload.data.selcom_receipt, then process the credit
    res.status(200).json({ received: true });
});
Java (Jackson)
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.crypto.Cipher;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.PrivateKey;
import java.time.Duration;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;

public final class CreditCallbackVerifier {

    // privateKey: load your PKCS#8 PEM with KeyFactory.getInstance("RSA") + PKCS8EncodedKeySpec
    public static boolean verify(Map<String, String> headers, String rawBody,
                                 String myApiKey, PrivateKey privateKey) throws Exception {
        Map<String, String> h = new HashMap<>();
        headers.forEach((k, v) -> h.put(k.toLowerCase(), v));

        // 1. digest-method + timestamp window (5 minutes)
        if (!"RSA-SHA256-ENC".equals(h.get("digest-method"))) return false;
        String ts = h.getOrDefault("timestamp", "");
        long age = Math.abs(Duration.between(OffsetDateTime.parse(ts).toInstant(), Instant.now()).getSeconds());
        if (age > 300) return false;

        // 2. Rebuild signing string
        JsonNode body = new ObjectMapper().readTree(rawBody);
        JsonNode data = body.path("data");
        StringBuilder signing = new StringBuilder("timestamp=").append(ts).append("&api_key=").append(myApiKey);
        for (String field : h.getOrDefault("signed-fields", "").split(",")) {
            JsonNode v = field.startsWith("data.") ? data.path(field.substring(5)) : body.path(field);
            signing.append('&').append(field).append('=')
                   .append(v.isMissingNode() || v.isNull() ? "" : v.asText());
        }

        // 3. Decrypt digest with private key (OAEP SHA-1) and compare with SHA-256
        byte[] decrypted;
        try {
            Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding");
            cipher.init(Cipher.DECRYPT_MODE, privateKey);
            decrypted = cipher.doFinal(Base64.getDecoder().decode(h.getOrDefault("digest", "")));
        } catch (Exception e) {
            return false;
        }
        byte[] expected = MessageDigest.getInstance("SHA-256")
                .digest(signing.toString().getBytes(StandardCharsets.UTF_8));
        return MessageDigest.isEqual(expected, decrypted);
    }
}
Security reminder: Keep your RSA private key and api-key on your server only. Always validate the digest and timestamp before trusting a callback, and process each selcom_receipt only once. For high-value credits you can additionally confirm the transaction via the Statement API.
Endpoint

Transaction API

Initiate a fund transfer, look up a recipient account before transferring, or query the status of a previously submitted transaction. The debit account is automatically resolved from your API credentials.

Transaction Process

POST /v1/transaction/process

Request Body

Parameter Type Required Description
transId string Required Your unique transaction reference ID. Must be unique across all transactions. Used for idempotency and status tracking.
recipientFiCode string Required Destination institution code (bank, wallet, or SELCOM for internal transfers). See destination codes below.
recipientAccount string Required Recipient account number or phone number depending on the recipientFiCode.
recipientName string Required Recipient full name (max 100 characters).
amount numeric Required Transaction amount. Must be at least 1.
purpose string Required Transaction purpose code. See Purpose Codes.
remarks string Optional Free-text remark (max 140 characters). Appears on statements.

Response Fields

Field Type Description
success boolean true on success.
error_code integer 1 on success; negative on error.
message string Human-readable status message.
data.trans_id string Your unique transId for status tracking.
data.selcom_receipt string Selcom internal transaction identifier.
data.status string Initial status: ACCEPTED (async) or COMPLETED (sync). See Transaction Status Values.
data.amount float Transaction amount.
data.currency string Transaction currency.
result string Transaction result based on actual status. See API Response — Result column.
resultcode string Result code based on actual transaction status. See API Response — Errorcode column.

Account Lookup

GET /v1/account/lookup

Look up a recipient account before initiating a transfer. Returns the account holder name, applicable charges, and operator details.

Query Parameters

Parameter Type Required Description
bank string Required Destination institution code (bank, wallet, or SELCOM). See destination codes below.
account string Required Recipient account number or phone number to look up.
transId string Required Unique reference ID for this lookup request.
amount numeric Optional Transfer amount. When provided, the response includes charge calculations for that amount.

Response Fields

Field Type Description
success boolean true on success.
error_code integer 1 on success; negative on error.
message string Human-readable status message.
transId string The reference ID you sent in the request.
resultcode string 000 on success.
data.bank string Institution code used in the lookup.
data.account string Recipient account number used in the lookup.
data.accountName string Recipient account holder name.
data.operator string Institution or operator name.
data.charges array Breakdown of applicable transaction charges.
data.totalCharges float Total of all applicable charges.
data.categoryCode string Category code returned by the bridge.
result string Transaction result based on actual status. See API Response — Result column.
resultcode string Result code based on actual transaction status. See API Response — Errorcode column.

Transaction Status

GET /v1/transaction/query

Query the status and details of a previously submitted transaction using your transId.

Query Parameters

Parameter Type Required Description
transId string Required The unique transaction reference ID submitted in the process request.

Response Fields

Field Type Description
success boolean true on success.
error_code integer 1 on success; negative on error.
message string Human-readable status message.
data.transId string Your transaction reference ID.
data.status string ACCEPTED, COMPLETED, or FAILED.
data.amount float Transaction amount.
data.currency string Transaction currency.
data.selcomReceipt string Selcom internal transaction identifier.
data.transDatetime string Transaction datetime (Y-m-d H:i:s).
data.senderAccount string Sender account number (resolved from your API credentials).
data.senderName string Sender account name (resolved from your API credentials).
result string Transaction result based on actual status. See API Response — Result column.
resultcode string Result code based on actual transaction status. See API Response — Errorcode column.

Destination Shortcodes

Destination Name Destination Shortcode Reference Type Lookup
Selcom Bank/Selcom Pesa/Selcom Business SELCOM NUMERIC Enabled
Absa Bank ABSA NUMERIC Enabled
Access Bank BANCABC NUMERIC Enabled
Akiba Bank ACB NUMERIC Enabled
Amana Bank AMANA NUMERIC Enabled
Azania Bank AZANIA NUMERIC Enabled
Bank of Africa BOA NUMERIC Enabled
Bank of Baroda BOBTZ NUMERIC Enabled
Bank of India BOI NUMERIC Enabled
Bank of Tanzania BOT NUMERIC No
Canara Bank CANARA NUMERIC Enabled
Citi Bank CITI NUMERIC Enabled
CRDB Bank CRDB ALPHANUMERIC Enabled
DCB Commercial Bank DCB NUMERIC Enabled
Diamond Trust Bank DTB NUMERIC Enabled
Ecobank ECOBANK NUMERIC Enabled
Equity Bank EQUITY NUMERIC Enabled
Exim Bank EXIM NUMERIC Enabled
Finca Microfinance Bank FINCA NUMERIC Enabled
Guaranty Trust Bank GTBANK NUMERIC Enabled
Habib African Bank HABIB NUMERIC Enabled
I&M Bank IMBANK NUMERIC Enabled
International Commercial Bank ICB NUMERIC Enabled
KCB Bank KCB NUMERIC Enabled
Letshego Bank LETSHEGO NUMERIC Enabled
Maendeleo Bank MAENDELEO NUMERIC Enabled
Mkombozi Commercial Bank MKOMBOZI NUMERIC Enabled
MUCOBA Bank MUCOBA NUMERIC Enabled
Mwalimu Commercial Bank MWALIMU NUMERIC Enabled
Mwanga Hakika Bank MWANGA NUMERIC Enabled
National Bank of Commerce NBC NUMERIC Enabled
NCBA Bank NCBA NUMERIC Enabled
NMB Bank NMB NUMERIC Enabled
People's Bank of Zanzibar PBZ NUMERIC Enabled
Stanbic Bank STANBIC NUMERIC Enabled
Standard Chartered Bank SCB NUMERIC Enabled
Tanzania Commercial Bank TCB NUMERIC Enabled
Uchumi Commercial Bank UCHUMI NUMERIC Enabled
United Bank for Africa UBA NUMERIC Enabled
Airtel Money AIRTELMONEY NUMERIC Enabled
Halo Pesa HALOPESA NUMERIC Enabled
Mixx by Yas MIXXBYYAS NUMERIC Enabled
TTCL Pesa TTCLPESA NUMERIC Enabled
Vodacom M-pesa MPESA NUMERIC Enabled
Example

Sample Response

Examples

Bank Transfer
Request
{
    "transId": "TXN20250715093045ABC",
    "recipientFiCode": "CRDB",
    "recipientAccount": "01234567890",
    "recipientName": "John Doe",
    "amount": 50000,
    "purpose": "SALARY",
    "remarks": "Monthly salary payment"
}
Response 200 OK
{
    "success": true,
    "error_code": 1,
    "message": "Transaction processed successfully.",
    "result": "INPROGRESS",
    "resultcode": "111",
    "data": {
        "trans_id": "TXN20250715093045ABC",
        "selcom_receipt": "SLK-987654321",
        "status": "ACCEPTED",
        "amount": 50000,
        "currency": "TZS"
    }
}
Wallet Transfer
Request
{
    "transId": "TXN20250715093210XYZ",
    "recipientFiCode": "MPESA",
    "recipientAccount": "255712345678",
    "recipientName": "Jane Smith",
    "amount": 10000,
    "purpose": "VENDOR",
    "remarks": "Payment for services"
}
Response 200 OK
{
    "success": true,
    "error_code": 1,
    "message": "Transaction processed successfully.",
    "result": "INPROGRESS",
    "resultcode": "111",
    "data": {
        "trans_id": "TXN20250715093210XYZ",
        "selcom_receipt": "SLK-112233445",
        "status": "ACCEPTED",
        "amount": 10000,
        "currency": "TZS"
    }
}
Internal Transfer (Selcom to Selcom)
Request
{
    "transId": "TXN20250715095900INT",
    "recipientFiCode": "SELCOM",
    "recipientAccount": "9876543210",
    "recipientName": "Alex Mwangi",
    "amount": 100000,
    "purpose": "BUSINESS",
    "remarks": "Inter-account settlement"
}
Response 200 OK
{
    "success": true,
    "error_code": 1,
    "message": "Transaction processed successfully.",
    "result": "SUCCESS",
    "resultcode": "000",
    "data": {
        "trans_id": "TXN20250715095900INT",
        "selcom_receipt": "SLK-998877665",
        "status": "COMPLETED",
        "amount": 100000,
        "currency": "TZS"
    }
}

Common Error Responses

Validation Error 422
{
    "success": false,
    "error_code": 651,
    "message": "Validation failed.",
    "result": "FAIL",
    "resultcode": "651",
    "data": {
        "purpose": ["The selected purpose is invalid."]
    }
}
Duplicate Transaction 422
{
    "success": false,
    "error_code": 643,
    "message": "Duplicate transaction detected.",
    "result": "FAIL",
    "resultcode": "643",
    "data": []
}
Endpoint

Statement API

Retrieve a paginated transaction statement for a linked organization account, or export it as PDF, XLSX, CSV, or JSON. Date ranges can be specified via a preset label or explicit from_date / to_date values.

POST /v1/statements

Request Body

Parameter Type Required Description
account_number string Required The account number associated with your API credentials. Must be an active account registered under your organization.
preset string Optional Preset date range shortcut. When provided, from_date and to_date are computed automatically server-side.
Allowed values: Today, Last 7 Days, This Month, Last Month, Last 10 Transactions.
from_date string Optional Start date in Y-m-d format (e.g., 2025-01-01). Required when to_date is provided and no preset is given.
to_date string Optional End date in Y-m-d format. Must be on or after from_date. Required when from_date is provided and no preset is given.
per_page integer Optional Number of transactions per page. Min: 1, Max: 500. Defaults to 10.
order string Optional Sort order of transactions. Allowed values: ASC, DESC. Defaults to DESC.
export_type string Optional Controls the response format. Allowed values: pdf, xlsx, csv, json.
File types (pdf, xlsx, csv) return a downloadable file URL instead of paginated data.
json returns the same paginated JSON response as omitting this field entirely.
Date range rules: Either supply a preset or a from_date + to_date pair. If neither is provided the statement returns an empty result set. The two approaches are mutually exclusive — preset values auto-compute their own dates server-side.

Response Fields — Listing

Field Type Description
success boolean true on success, false on failure.
error_code integer 1 on success; negative value on error (see Error Codes).
message string Human-readable status message.
data.filters_applied object Echo of the resolved filters used for the query (account_number, preset, from_date, to_date, per_page, order).
data.account.account_name string Registered organization name.
data.account.account_number string Formatted account number.
data.account.sub_account_name string Sub-account / business label for the queried account.
data.currency string Account currency (e.g., TZS).
data.opening_balance float Balance at the start of the requested date range.
data.closing_balance float Balance at the end of the requested date range.
data.pagination.total integer Total number of matching transactions.
data.pagination.per_page integer Records returned per page.
data.pagination.current_page integer Current page number.
data.pagination.last_page integer Last page number.
data.transactions array Array of transaction objects for the current page.
result string Transaction result based on actual status. See API Response — Result column.
resultcode string Result code based on actual transaction status. See API Response — Errorcode column.

Response Fields — Export (pdf / xlsx / csv)

When export_type is pdf, xlsx, or csv, the listing fields are replaced by:

Field Type Description
data.export_type string The requested export format (pdf, xlsx, or csv).
data.file_url string Temporary public URL to download the generated file.
data.expires_at string ISO 8601 timestamp indicating when the download link expires (1 hour from generation).
data.filters_applied object Echo of the resolved filters used for the export.
result string Transaction result based on actual status. See API Response — Result column.
resultcode string Result code based on actual transaction status. See API Response — Errorcode column.

Example — Listing (Preset)

Request
{
    "account_number": "0123456789",
    "preset": "This Month",
    "per_page": 10,
    "order": "DESC"
}
Response 200 OK
{
    "success": true,
    "error_code": 1,
    "message": "Statement fetched successfully.",
    "result": "SUCCESS",
    "resultcode": "000",
    "data": {
        "filters_applied": {
            "account_number": "0123456789",
            "preset": "This Month",
            "from_date": "2025-07-01",
            "to_date": "2025-07-31",
            "per_page": 10,
            "order": "DESC"
        },
        "account": {
            "account_name": "Acme Ltd",
            "account_number": "01234 56789",
            "sub_account_name": "Main Account"
        },
        "currency": "TZS",
        "opening_balance": 500000,
        "closing_balance": 450000,
        "pagination": {
            "total": 42,
            "per_page": 10,
            "current_page": 1,
            "last_page": 5,
            "from": 1,
            "to": 10
        },
        "transactions": [...]
    }
}

Example — Export

Request
{
    "account_number": "0123456789",
    "from_date": "2025-07-01",
    "to_date": "2025-07-31",
    "export_type": "pdf"
}
Response 200 OK
{
    "success": true,
    "error_code": 1,
    "message": "Statement exported successfully.",
    "result": "SUCCESS",
    "resultcode": "000",
    "data": {
        "export_type": "pdf",
        "file_url": "https://your-domain.com/storage/exports/statement-1234.pdf",
        "expires_at": "2025-07-15T10:30:00+00:00",
        "filters_applied": {
            "account_number": "0123456789",
            "preset": "",
            "from_date": "2025-07-01",
            "to_date": "2025-07-31",
            "per_page": 10,
            "order": "ASC"
        }
    }
}

Example — Export (JSON)

Passing "export_type": "json" returns the same paginated JSON listing as omitting the field.

Request
{
    "account_number": "0123456789",
    "from_date": "2025-07-01",
    "to_date": "2025-07-31",
    "export_type": "json",
    "per_page": 10,
    "order": "DESC"
}
Response 200 OK
{
    "success": true,
    "error_code": 1,
    "message": "Statement fetched successfully.",
    "result": "SUCCESS",
    "resultcode": "000",
    "data": {
        "filters_applied": {
            "account_number": "0123456789",
            "preset": "",
            "from_date": "2025-07-01",
            "to_date": "2025-07-31",
            "per_page": 10,
            "order": "DESC"
        },
        "account": {
            "account_name": "Acme Ltd",
            "account_number": "01234 56789",
            "sub_account_name": "Main Account"
        },
        "currency": "TZS",
        "opening_balance": 500000,
        "closing_balance": 450000,
        "pagination": {
            "total": 42,
            "per_page": 10,
            "current_page": 1,
            "last_page": 5,
            "from": 1,
            "to": 10
        },
        "transactions": [...]
    }
}
Error Response 422
{
    "success": false,
    "error_code": 641,
    "message": "Account number not found or not authorized.",
    "result": "FAIL",
    "resultcode": "641",
    "data": []
}
Reference

API Response

The table below describes the possible transaction results returned in the API response, along with their associated error codes and meanings.

Result Errorcode Description
SUCCESS 000 Transaction successful.
INPROGRESS 111 927 Transaction in progress — please query to know the exact status of the transaction.
AMBIGUOUS 999 Transaction status unknown — wait for reconciliation.
FAIL All others Transaction failed.
Reference

Error Codes

All error responses share a consistent structure. Use the error_code integer to programmatically handle specific failure scenarios.

Error Response Structure

JSON
{
    "success": false,
    "error_code": 613,
    "message": "Invalid or inactive API key.",
    "result": "FAIL",
    "resultcode": "613",
    "data": []
}

Complete Error Code Reference

error_code HTTP Status Category Description
000 200 Success Request completed successfully.
611 403 Authentication Requesting IP address is not whitelisted.
612 400 Authentication One or more required headers are missing (api-key, request-timestamp, digest, Origin).
613 401 Authentication API key is invalid or has been deactivated.
617 403 Authentication No domain is registered for this API key, or the Origin header does not match a registered domain.
621 400/404 General Generic server-side error or resource not found.
631 401 Authentication digest signature does not match. Check your formula or secret key.
632 400 Authentication Request timestamp is stale (outside ±5 minute window) or format is invalid. Ensure your server clock is synchronized with UTC.
641 400 Balance Account not found, not authorized, or account type not permitted for balance fetch.
642 400 Transaction Transaction processing failed at the bank or wallet level.
643 422 Transaction Duplicate transaction detected. A transaction with the same parameters was recently processed.
646 403 Transaction Transaction exists but was not initiated by this API key (ownership violation).
651 422 Validation Request body failed field validation. Check the data object for field-level error details.