Kuthibitisha (API Key)
Every request carries an API key. Create keys in Merchant → API Keys, one for each project or app that takes payments (for example one for your website and one for your school system): if one key leaks, you revoke only that one. Base URL: https://pay.pigatech.com/api/v1. New keys work only over HTTPS.
Authorization: Bearer pp_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| Key | What it does |
|---|---|
pp_live_... | Real payments: the customer gets a mobile money prompt and money moves |
pp_test_... | Test payments: nothing reaches a phone and no money moves (see Hali ya Majaribio) |
Each key can have:
- Ruhusa:
payments:write(create payments) and/orpayments:read(see payments) - IP zinazoruhusiwa: your server's IP addresses or ranges; requests from anywhere else are refused. A live key that lists IPs needs both IPv4 and IPv6, unless Seva yangu haina IPv6 is ticked
- An expiry date, and its own webhook URL and signing secret
PigaPay stores only a fingerprint of each key, so the key is shown once, when you create it. Keep it on your server only (an environment variable or a settings file outside the web folder), never in a web page, mobile app or code repository. If it may have leaked, roll it: you get a new key and the old one keeps working for the hours you choose, so you can switch without downtime. The header X-API-Key: pp_live_... also works. Keys that start with pk_live_ (made before October 2026) keep working as before; move them to HTTPS when you can.
PHP projects can use the one-file Maktaba ya PHP ya PigaPay.
Hali ya Majaribio
With a pp_test_ key, payments are saved as test payments (livemode: false, ids pay_test_...). They never reach a phone, never appear in your balance, and settle a few seconds after you create them, with a webhook like a real payment. Test keys only see test payments. The phone number decides the result:
| Namba ya simu | Result |
|---|---|
255700000001 | failed (insufficient_funds) |
255700000002 | cancelled (user_cancelled) |
255700000003 | stays forwarded (hadi test waiting) |
| any other valid number | completed |
Limits & Lockouts
Each key may make 100 requests a minute. Every answer has X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset (Unix time), and an X-Request-Id to quote if you contact us. Over the limit you get 429 rate_limited with Retry-After in seconds.
To stop key guessing, an IP address that sends 10 wrong keys within 10 minutes is blocked for 30 minutes (429 too_many_failed_attempts), even if it then sends a correct key. Fix the key in your settings and wait.
Makosa
Errors use HTTP status codes and a JSON body with a machine-readable error and a readable message. Validation errors list each field in errors.
| HTTP | error | Meaning |
|---|---|---|
| 400 | invalid_json | The body is not JSON |
| 401 | unauthorized | Missing, wrong, revoked or expired API key |
| 403 | https_required | The request was not made over HTTPS |
| 403 | ip_not_allowed | The key may not be used from this IP (its allowed IPs) |
| 403 | insufficient_scope | The key does not have the permission for this request |
| 403 | merchant_inactive, payments_disabled, plan_limit_reached | Account not active, mobile money switched off in Settings, or the plan's monthly limit is used up |
| 403 | refunds_disabled | Refunds are switched off on PigaPay |
| 403 | allowed_ips_required | A live key that withdraws or pays out must list your server's IPs |
| 404 | not_found | Unknown endpoint, payment, withdrawal, payout or refund |
| 405 | method_not_allowed | Wrong HTTP method |
| 409 | no_payout_account | Save a payout account in the dashboard before withdrawing |
| 409 | busy | Another withdrawal, payout or refund of the business is being made; try again in a few seconds |
| 422 | validation_failed | Some fields are invalid (see errors) |
| 422 | withdrawal_refused, payout_refused, refund_refused | A rule stopped it (balance, limit, documents, already refunded); the reason is in message |
| 429 | rate_limited, too_many_failed_attempts | Too many requests for this key, or this IP sent too many wrong keys; wait Retry-After sekunde |
| 502 | provider_error | The mobile money provider refused the prompt; the failed payment is in data |
| 503 | unavailable | PigaPay is temporarily unavailable; try again |
{
"success": false,
"error": "validation_failed",
"message": "Some fields are invalid.",
"errors": {
"amount": "At least 1000 TZS.",
"customer.phone": "Tanzanian mobile number, e.g. 255712345678 or 0712345678."
}
}
Payment Statuses
| status | Meaning |
|---|---|
pending | Created; the prompt is being sent |
forwarded | The prompt is on the customer's phone, waiting for their PIN |
completed | Paid. Deliver the goods or service now (final) |
failed | Not paid: refused, timed out or not enough balance; see failure_reason (final) |
cancelled | The customer cancelled on their phone (final) |
Check Your Key
Shows the account and key a request is made with: good for checking a new setup. Needs no permission.
{
"success": true,
"data": {
"merchant": { "id": "MER-...", "business_name": "PigaTech SoftCompany" },
"key": { "name": "PigaSchool fees", "mode": "test", "key": "pp_test_…9f2c",
"scopes": ["payments:read", "payments:write"], "expires_at": null,
"webhook_url": "https://school.pigatech.com/pigapay/webhook" },
"limits": { "requests_per_minute": 100, "min_amount": 1000, "currency": "TZS" }
},
"request_id": "req_4f1c9a0b2d3e5f67"
}
Anzisha Malipo
Sends a mobile money prompt (USSD push) to the customer's phone. The customer enters their PIN; you learn the result by webhook or by Angalia Malipo.
Request Body (JSON)
| Kipengele | Aina | Maelezo |
|---|---|---|
| amount * | integer | Whole Tanzanian shillings, e.g. 5000 for TZS 5,000. At least the minimum payment (TZS 1,000 by default). |
| customer.phone * | string | The payer's mobile money number: 255712345678, +255712345678 au 0712345678 |
| customer.name | string | Payer's name (shown in your dashboard and receipts) |
| customer.email | string | Payer's email; a receipt is sent there when the payment completes |
| reference | string | Your own ID for this payment (up to 100 letters, digits, . _ - :). Idempotency key: sending the same reference again returns the first payment (with "idempotent_replay": true) instead of charging twice. The Idempotency-Key header is used when no reference is given. |
| description | string | What the payment is for (up to 200 characters) |
| webhook_url | string | Where to send this payment's events. If left out, your account's webhook URL (Settings) is used. Lets one merchant account serve several websites. |
| metadata | object | Anything you want back in responses and webhooks (JSON object, up to 2000 characters) |
| fee_bearer | string | Who pays the PigaPay fee. merchant: the customer is asked for amount and the fee is taken from it. customer: the fee is added on top so you receive the full amount (10,000 becomes a 10,257 prompt); show the total to your customer first. shared: the customer pays the part you chose in Settings (25, 50 or 75 %) on top and you pay the rest (50 %: 10,127 prompt, you receive 9,873.32). Left out: your Settings (Transaction fee), which is merchant unless you changed it. |
| splits | array | Share this payment with other PigaPay businesses (up to 5): [{"account": "MCH-2026-1243", "amount": 3000, "description": "School A"}, {"account": "MCH-2026-1244", "percent": 10}]. account is the receiver's Account ID (on their API Keys page); give amount (TZS) or percent of amount. Together at most what you receive after the fee (net_amount). When the payment completes, each share goes into the receiver's PigaPay balance and they withdraw it as usual; the rest stays with you. |
| currency | string | TZS (the only currency for now; default) |
| method | string | mobile_money (the only method for now; default) |
Example Request
curl -X POST https://pay.pigatech.com/api/v1/payments \
-H "Authorization: Bearer pk_live_..." \
-H "Content-Type: application/json" \
-d '{
"amount": 5000,
"reference": "ORDER-1042",
"description": "Order 1042",
"customer": { "name": "Juma Mwinyi", "phone": "0712345678" },
"webhook_url": "https://yourshop.co.tz/pigapay-webhook.php",
"metadata": { "order_id": 1042 }
}'
Example Response (201 Created)
{
"success": true,
"data": {
"id": "pay_f3h9x1",
"reference": "ORDER-1042",
"amount": 5000,
"currency": "TZS",
"status": "forwarded",
"method": "mobile_money",
"description": "Order 1042",
"customer": { "name": "Juma Mwinyi", "phone": "+255712345678", "email": null },
"fee": 192.48,
"net_amount": 4807.52,
"fee_bearer": "merchant",
"requested_amount": 5000,
"splits": [],
"provider_reference": "MP-...",
"failure_reason": null,
"metadata": { "order_id": 1042 },
"created_at": "2026-10-24T10:30:00+03:00",
"completed_at": null
}
}
Angalia Malipo
One of your payments, with its latest status. While a payment is still waiting, PigaPay asks the mobile money provider again (at most every 10 seconds), so polling every 5-10 seconds works even if a webhook is late.
Vipengele vya URL
| Kipengele | Aina | Maelezo |
|---|---|---|
| id * | string | The id from Create Payment (pay_...), or your own reference |
Response: {"success": true, "data": { ...same fields as Create Payment... }}
Orodha ya Malipo
Your payments, newest first.
| Query | Aina | Maelezo |
|---|---|---|
| status | string | pending, forwarded, completed, failed au cancelled |
| limit | integer | Number of results (default 20, max 100) |
| offset | integer | How many to skip (for paging) |
{
"success": true,
"data": [ { "id": "pay_f3h9x1", "status": "completed", "amount": 5000, ... } ],
"pagination": { "total": 50, "limit": 20, "offset": 0 }
}
Create Checkout
The easiest way to take a payment: PigaPay hosts the payment page. Create a checkout, send the customer to its url, and PigaPay asks for their number, sends the prompt, lets them try again if it fails, shows a receipt and sends them back to your success_url. Your project needs no payment screens. Needs payments:write.
| Field | Aina | Maelezo |
|---|---|---|
amount required | integer | TZS, at least 1000 |
reference | string | Your order id. Sending it again returns the same checkout (unless it was cancelled or expired) |
description | string | Shown to the customer, e.g. "School fees, term 1" |
success_url | string | Where the customer goes after paying. PigaPay adds checkout_id, reference and status=paid |
cancel_url | string | Where the customer goes if they cancel or the page expires |
customer | object | name, email, phone (fills in the form) |
webhook_url | string | Overrides the key's webhook URL for this payment |
metadata | object | Your own data; returned on the payment and in webhooks (with checkout_id) |
expires_in_minutes | integer | 5 to 1440, default 60 |
fee_bearer | string | merchant, customer au shared (see Create Payment). With customer the page shows the total and the fee, and the response has amount_to_pay |
splits | array | Shares for other PigaPay businesses, as in Create Payment; applied when the customer pays |
<?php
$checkout = $pigapay->createCheckout([
'amount' => 25000,
'reference' => 'FEES-2026-0042',
'description' => 'School fees, term 1',
'success_url' => 'https://school.example/fees/paid',
'cancel_url' => 'https://school.example/fees',
]);
header('Location: ' . $checkout['url']); // https://pay.pigatech.com/checkout/...
The return to success_url is for the customer's eyes only: anyone can type that address. Mark the order paid from the signed payment.completed webhook, or check Get Checkout.
Get Checkout
{id} is the chk_... id or your reference. Needs payments:read.
| status | Meaning |
|---|---|
open | Waiting for the customer (also after a failed attempt; see last_error) |
processing | The prompt is on the customer's phone |
paid | Paid; the payment is in payment (final) |
expired, cancelled | Not paid; create a new checkout to try again (final) |
Salio
available (can be withdrawn now), on_hold (inside the settlement period), total, the withdrawal rules (minimum, fee_fixed, fee_percent, daily_limit, left_today), the payout limits (payouts.line_minimum, line_maximum, max_lines) and the saved payout_account. Needs balance:read.
Wateja
Everyone who completed a payment, most paid first: phone, name, email, payments_count, total_paid, first_payment_at, last_payment_at. Query: search (name, email or phone), limit, offset. GET /customers/{phone} returns one customer with their latest payments. Needs customers:read.
Kutoa Pesa
Withdraw to the payout account saved in the dashboard (Withdraw → Payout account); the API cannot send a withdrawal anywhere else. Needs withdrawals:write and, for a live key, Allowed IPs. GET /withdrawals and GET /withdrawals/{id} (the WTH-... id or your reference) need payouts:read.
| Field | Aina | Maelezo |
|---|---|---|
amount required | integer | TZS taken from the balance; the withdrawal fee is inside it (net_amount is what arrives) |
reference | string | Your id. Sending it again returns the same withdrawal |
note | string | Up to 200 characters |
instant | boolean | true: approved and sent at once ("Send now"), for an extra fee, when PigaPay has switched instant withdrawals on and the saved account has been paid before |
Hali: pending, approved, processing, then completed, rejected au failed (with failure_reason; the money is back in the balance).
Malipo ya Wengi
Lipa up to 200 people from the balance: title, reference and lines (each name, phone, amount). Each line must be at least TZS 5,000 (the payout provider's smallest payout; check payouts.line_minimum before you take your customer's money). Each person receives their full amount; the fees are added on top. PigaPay approves the payout first, and a number never paid before waits 24 hours. Needs payouts:write and, for a live key, Allowed IPs. GET /payouts and GET /payouts/{id} (the BAT-... id or your reference, with every line) need payouts:read.
<?php
$batch = $pigapay->createPayout([
'title' => 'Salaries November',
'reference' => 'PAYROLL-2026-11',
'lines' => [
['name' => 'Asha Juma', 'phone' => '0712345678', 'amount' => 150000],
['name' => 'Baraka Mussa', 'phone' => '0754123456', 'amount' => 120000],
],
]);
// $batch['status']: pending_approval, processing, completed, partially_completed or failed
Code for every language: the Developer Guide in your dashboard (section 11).
Kurejesha Pesa
Give a customer money back for a completed payment. The money goes to the phone that paid; the amount is set aside from your balance at once and PigaPay approves every refund. PigaPay's fee for the payment is not returned. Needs refunds:write. GET /refunds (payment, status, limit, offset) and GET /refunds/{id} (the RFD-... id or your reference) need refunds:read.
| Field | Aina | Maelezo |
|---|---|---|
payment required | string | The pay_... id or the payment's reference |
amount | integer | TZS, at least 100; leave out to refund all that is left |
reason required | string | 5 to 300 characters |
reference | string | Your id. Sending it again returns the same refund |
Taarifa za Webhook
When a payment reaches a final status, PigaPay POSTs JSON to the payment's webhook_url, else to the webhook URL of the key that made it, else to your account webhook. Answer with any 2xx status within 10 seconds, to every genuine event: also ping and events you do not use. If not, PigaPay tries again after 1 minute, then 5 minutes, then 30 minutes (3 more tries, each counted from the one before), then stops. Act only on events whose livemode matches your key (a test event must never mark a real order paid). Deliveries are listed on your API Keys page. Webhook addresses must be public (not a private or internal network); use https://.
Matukio
| Taarifa | Maelezo |
|---|---|
payment.completed | The customer paid |
payment.failed | The payment did not go through |
payment.cancelled | The customer cancelled on their phone |
withdrawal.completed, .failed, .rejected | A withdrawal was paid, failed (money back in the balance) or was rejected |
payout.completed, .partially_completed, .failed | Every line of a bulk payout is done; the event has every line |
refund.completed, .failed, .rejected | A refund reached the customer, failed or was rejected |
ping | Tuma jaribio on the API Keys page; answer 200 |
Headers
PigaPay-Signature | t=<Unix time>,v1=<hex HMAC-SHA256 of "t.raw body" with the webhook secret> |
X-PigaPay-Event | The event name, e.g. payment.completed |
X-PigaPay-Delivery | The delivery id (the same on every retry of one event) |
X-PigaPay-Signature | Older scheme: HMAC-SHA256 of the raw body with the webhook secret (no timestamp). Use PigaPay-Signature in new code |
Example Payload
{
"event": "payment.completed",
"event_id": "evt_6b1d0e4c2a9f8e7d5c3b1a09",
"livemode": true,
"id": "pay_f3h9x1",
"status": "completed",
"reference": "ORDER-1042",
"amount": 5000,
"currency": "TZS",
"fee": 192.48,
"net_amount": 4807.52,
"fee_bearer": "merchant",
"requested_amount": 5000,
"customer_name": "Juma Mwinyi",
"phone_number": "255712345678",
"description": "Order 1042",
"provider_reference": "SN17935278001132369705618",
"moshipay_reference": "SN17935278001132369705618",
"created_at": "2026-10-24 10:30:00",
"completed_at": "2026-10-24 10:31:12",
"created_at_iso": "2026-10-24T10:30:00+03:00",
"completed_at_iso": "2026-10-24T10:31:12+03:00",
"metadata": { "order_id": 1042 },
"sent_at": "2026-10-24T10:31:13+03:00"
}
Verify the Signature
Each key has its own webhook secret (whsec_..., on the API Keys page). Before trusting a webhook: check PigaPay-Signature with that secret, refuse events whose t is more than 5 minutes old (someone may be sending an old event again), and handle each event_id only once. For large orders, also confirm with Angalia Malipo.
<?php
// With the PigaPay PHP library
require 'PigaPay.php';
try {
$event = PigaPay\Webhook::fromRequest(getenv('PIGAPAY_WEBHOOK_SECRET'));
} catch (UnexpectedValueException $e) {
http_response_code(401);
exit;
}
if ($event['event'] === 'payment.completed') {
// mark $event['reference'] paid (once per $event['event_id'])
}
http_response_code(200);
<?php
// Without the library
$secret = getenv('PIGAPAY_WEBHOOK_SECRET'); // whsec_...
$body = file_get_contents('php://input');
preg_match('/t=(\d+),v1=([a-f0-9]+)/', $_SERVER['HTTP_PIGAPAY_SIGNATURE'] ?? '', $m);
$fresh = $m && abs(time() - (int)$m[1]) <= 300;
if (!$fresh || !hash_equals(hash_hmac('sha256', $m[1] . '.' . $body, $secret), $m[2])) {
http_response_code(401);
exit;
}
$event = json_decode($body, true);
http_response_code(200);