Mwongozo wa API

Maelezo kamili ya REST API ya PigaPay

REST API JSON API Key Signed Webhooks

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
KeyWhat 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/or payments: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 simuResult
255700000001failed (insufficient_funds)
255700000002cancelled (user_cancelled)
255700000003stays forwarded (hadi test waiting)
any other valid numbercompleted

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.

HTTPerrorMeaning
400invalid_jsonThe body is not JSON
401unauthorizedMissing, wrong, revoked or expired API key
403https_requiredThe request was not made over HTTPS
403ip_not_allowedThe key may not be used from this IP (its allowed IPs)
403insufficient_scopeThe key does not have the permission for this request
403merchant_inactive, payments_disabled, plan_limit_reachedAccount not active, mobile money switched off in Settings, or the plan's monthly limit is used up
403refunds_disabledRefunds are switched off on PigaPay
403allowed_ips_requiredA live key that withdraws or pays out must list your server's IPs
404not_foundUnknown endpoint, payment, withdrawal, payout or refund
405method_not_allowedWrong HTTP method
409no_payout_accountSave a payout account in the dashboard before withdrawing
409busyAnother withdrawal, payout or refund of the business is being made; try again in a few seconds
422validation_failedSome fields are invalid (see errors)
422withdrawal_refused, payout_refused, refund_refusedA rule stopped it (balance, limit, documents, already refunded); the reason is in message
429rate_limited, too_many_failed_attemptsToo many requests for this key, or this IP sent too many wrong keys; wait Retry-After sekunde
502provider_errorThe mobile money provider refused the prompt; the failed payment is in data
503unavailablePigaPay 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

statusMeaning
pendingCreated; the prompt is being sent
forwardedThe prompt is on the customer's phone, waiting for their PIN
completedPaid. Deliver the goods or service now (final)
failedNot paid: refused, timed out or not enough balance; see failure_reason (final)
cancelledThe customer cancelled on their phone (final)
GET /me

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" }
POST /api/v1/payments

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 } }
GET /api/v1/payments/{id}

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... }}

GET /api/v1/payments

Orodha ya Malipo

Your payments, newest first.

QueryAinaMaelezo
statusstringpending, forwarded, completed, failed au cancelled
limitintegerNumber of results (default 20, max 100)
offsetintegerHow many to skip (for paging)
{ "success": true, "data": [ { "id": "pay_f3h9x1", "status": "completed", "amount": 5000, ... } ], "pagination": { "total": 50, "limit": 20, "offset": 0 } }
POST /checkout

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.

FieldAinaMaelezo
amount requiredintegerTZS, at least 1000
referencestringYour order id. Sending it again returns the same checkout (unless it was cancelled or expired)
descriptionstringShown to the customer, e.g. "School fees, term 1"
success_urlstringWhere the customer goes after paying. PigaPay adds checkout_id, reference and status=paid
cancel_urlstringWhere the customer goes if they cancel or the page expires
customerobjectname, email, phone (fills in the form)
webhook_urlstringOverrides the key's webhook URL for this payment
metadataobjectYour own data; returned on the payment and in webhooks (with checkout_id)
expires_in_minutesinteger5 to 1440, default 60
fee_bearerstringmerchant, customer au shared (see Create Payment). With customer the page shows the total and the fee, and the response has amount_to_pay
splitsarrayShares 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}

Get Checkout

{id} is the chk_... id or your reference. Needs payments:read.

statusMeaning
openWaiting for the customer (also after a failed attempt; see last_error)
processingThe prompt is on the customer's phone
paidPaid; the payment is in payment (final)
expired, cancelledNot paid; create a new checkout to try again (final)
GET /balance

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.

GET /customers

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.

POST /withdrawals

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.

FieldAinaMaelezo
amount requiredintegerTZS taken from the balance; the withdrawal fee is inside it (net_amount is what arrives)
referencestringYour id. Sending it again returns the same withdrawal
notestringUp to 200 characters
instantbooleantrue: 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).

POST /payouts

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).

POST /refunds

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.

FieldAinaMaelezo
payment requiredstringThe pay_... id or the payment's reference
amountintegerTZS, at least 100; leave out to refund all that is left
reason requiredstring5 to 300 characters
referencestringYour id. Sending it again returns the same refund
POST your webhook_url

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.completedThe customer paid
payment.failedThe payment did not go through
payment.cancelledThe customer cancelled on their phone
withdrawal.completed, .failed, .rejectedA withdrawal was paid, failed (money back in the balance) or was rejected
payout.completed, .partially_completed, .failedEvery line of a bulk payout is done; the event has every line
refund.completed, .failed, .rejectedA refund reached the customer, failed or was rejected
pingTuma jaribio on the API Keys page; answer 200

Headers

PigaPay-Signaturet=<Unix time>,v1=<hex HMAC-SHA256 of "t.raw body" with the webhook secret>
X-PigaPay-EventThe event name, e.g. payment.completed
X-PigaPay-DeliveryThe delivery id (the same on every retry of one event)
X-PigaPay-SignatureOlder 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);
Kiingereza Ripoti tatizo la malipo

Ongea nasi

Piga simu+255 678 520 538
Barua pepepay@pigatech.com