Collections API

Accept incoming payments in TZS. This API supports collections only — there is no payout endpoint. All requests use HTTPS and JSON.

Authentication

Generate keys on the API Keys page. Each mode (test/live) has a public key (pk_…) and a secret key (sk_…). The secret is shown once; we only store a hash. Keep it on your server — never in a browser or mobile app.

Every request sends four headers. The signature is a hex HMAC-SHA256 using your secret key over timestamp.METHOD.path.body (body is empty for GET).

Authorization: Bearer sk_test_xxx
X-CP-Timestamp: <unix seconds>
X-CP-Signature: hex(HMAC_SHA256(secret, ts + "." + METHOD + "." + path + "." + rawBody))
Idempotency-Key: <unique per new collection, 8-100 chars>   (POST only)
// Node.js
import crypto from "node:crypto";
const ts = Math.floor(Date.now() / 1000).toString();
const path = "/api/public/v1/collections";
const body = JSON.stringify(payload);
const sig = crypto.createHmac("sha256", process.env.CP_SECRET)
  .update(`${ts}.POST.${path}.${body}`).digest("hex");

Endpoints

POST/api/public/v1/collectionsRequest a payment from a customer
GET/api/public/v1/collections/{id}Verify a collection's status

Base URL: your CollectPay TZ site address, e.g. https://your-domain/api/public/v1.

Create a collection

FieldTypeRules
amountintegerRequired. Whole TZS, 500 – 50,000,000
currencystringOptional. Only "TZS"
referencestringRequired. Your unique order ID, 3-64 chars
descriptionstringOptional. Up to 255 chars
customer.namestringRequired. 2-100 chars
customer.phonestringRequired. 2556XXXXXXXX or 2557XXXXXXXX
customer.emailstringOptional
curl -X POST https://your-domain/api/public/v1/collections \
  -H "Authorization: Bearer $CP_SECRET" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-1042-attempt-1" \
  -H "X-CP-Timestamp: $TS" -H "X-CP-Signature: $SIG" \
  -d '{"amount":25000,"reference":"ORDER-1042","customer":{"name":"Asha Mussa","phone":"255712345678"}}'
201 Created
{ "data": { "id": "cp_t_3f9a…", "reference": "ORDER-1042", "mode": "test",
  "amount": 25000, "currency": "TZS", "status": "pending",
  "customer": { "name": "Asha Mussa", "phone": "255712345678", "email": null },
  "created_at": "2026-12-03T17:20:00Z", "completed_at": null } }

Retrying with the same Idempotency-Key returns the original result (header Idempotent-Replayed: true) and never creates a second charge.

Verify transaction status

GET /api/public/v1/collections/cp_t_3f9a…
→ 200 { "data": { "id": "cp_t_3f9a…", "status": "successful", … } }

Statuses: pending, successful, failed. Always verify status from your server before delivering goods.

Webhook notifications

Set an HTTPS webhook URL per mode on the API Keys page. When a collection settles we POST:

POST <your webhook URL>
X-CollectPay-Signature: t=1764781200,v1=5d1e…
{ "event": "collection.successful", "data": { …same shape as GET… } }

Verify: compute HMAC-SHA256 with your webhook signing secret (whsec_…) over t + "." + rawBody, compare to v1 in constant time, and reject timestamps older than 5 minutes. Respond with 2xx quickly.

const [t, v1] = header.split(",").map(p => p.split("=")[1]);
const expected = crypto.createHmac("sha256", WHSEC).update(`${t}.${rawBody}`).digest("hex");
const ok = crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(v1))
  && Math.abs(Date.now()/1000 - Number(t)) < 300;

Error codes

{ "error": { "code": "validation_error", "message": "customer.phone: …" } }
HTTPCodeMeaning
400idempotency_key_requiredMissing or invalid Idempotency-Key header
400invalid_jsonBody is not valid JSON
400https_requiredRequest was not sent over HTTPS
401invalid_api_keySecret key missing, malformed or revoked
401signature_missingX-CP-Timestamp or X-CP-Signature header missing
401timestamp_expiredTimestamp more than 5 minutes from server time
401signature_invalidSignature does not match the request
403account_suspendedMerchant account is suspended
404not_foundCollection does not exist for this key's mode
409duplicate_referenceReference already used in this mode
409idempotency_conflictIdempotency-Key reused with different parameters
422validation_errorOne or more fields are invalid (message lists them)
429rate_limitedMore than 60 requests per minute for this key
503live_provider_unavailableLive collections are not enabled yet

Test mode integration

Use your sk_test_ key. No real money moves and test payments never change your balance. The customer phone decides the outcome:

  • 255700000001 (or any other valid number) → successful
  • 255700000002 → failed
  • 255700000003 → stays pending

Live mode returns live_provider_unavailable until a payment provider is connected to the platform.

Limits & safety

  • HTTPS only; plain HTTP requests are rejected.
  • 60 requests per minute per key (429 when exceeded).
  • Signed requests with a 5-minute timestamp window stop replays.
  • Idempotency keys and unique references stop duplicate collections.
  • Rotate a key any time — the old secret stops working immediately.