Skip to content
NOSTREL
Payouts

Money leaving is a
different problem
from money arriving.

Nobody loses sleep over a payment that failed to come in. They lose sleep over one that went out and should not have, to a number nobody can quite account for, approved by a person who has since left.

So the controls here are on by default rather than available as an option. It makes sending a single payout fractionally slower than it could be. That is the trade, we made it deliberately, and we would make it again.

create a payoutbash
curl https://api.nostrel.com/v1/api/payouts \  -H "Authorization: Bearer sk_live_••••••••" \  -H "Idempotency-Key: payroll-oct-1042" \  -d phone=254712345678 \  -d amount=1200 \  -d reference=SAL-1042
queued, funds reserved, waiting for a second person
what comes backjson
{  "id": "pay_4k2nd7qzx1",  "state": "queued",  "amount": 1200,  "currency": "KES",  "reference": "SAL-1042",  "approval": "pending",  "created_by": "usr_9f1",  "approvable_by_creator": false}

Controls

The boring ones, switched on before you arrive

Enforced on the server, not suggested in the console.

Two people, by default

Whoever creates a payout cannot release it. On by default.

A PIN at the moment of release

Separate from the password and the session. A stolen session cannot send money.

The money is held while it waits

The amount is reserved on creation, so two payouts cannot spend it twice.

Who did what, in a chain

Created by, approved by, rejected by, hash-chained. An edit breaks the chain.

Limits that are yours

Per-transaction and monthly ceilings, on an atomic counter. Concurrency cannot slip past.

Roles, not a shared login

Preparing, releasing and reconciling are three different permissions. Every boundary is enforced on the server rather than by hiding a button.

Underneath

Reserve, settle, release

Three movements, and the reason your balance is never briefly wrong in a way somebody could exploit.

  1. 01

    Reserve

    On creation the amount moves from available to held. Nothing else can spend it.

  2. 02

    Settle

    Safaricom confirms. The held amount becomes a real debit, the fee posts as its own entry, and both sides of the movement are written in one database transaction. There is no instant at which one half exists without the other.

  3. 03

    Release

    A rejection, a refusal or a definite failure puts the held amount back into available, by exactly the figure that was taken. Not approximately, and not after a nightly job.

Withdrawing to yourself

Taking your own money out is a payout to a channel you own, so it rides the same rails, the same ledger, the same approval and the same PIN. It is not a separate code path with separate bugs. That is how a withdrawal feature usually becomes the weakest door in the building.

Destinations are verified before they can receive anything, and a bank destination is reached through that bank's own published paybill rather than one we found on an aggregator's list.

Which banks, and where the numbers came from

State

Six states, and the one in the middle is not a failure

The distinction between a payout that failed and a payout we have not heard about is the difference between a refund and a double payment.

  1. queued

    Waiting for a second person. The amount is already reserved.

    funds heldprocessing, failed
  2. processing

    Handed to Safaricom. Out of our hands from here.

    funds heldpaid, failed, timed_out
  3. paid

    Confirmed by the provider. The reservation becomes a real debit, the fee posts, your webhook fires. This is a terminal state.

    balance changedfinal
  4. failed

    Refused or rejected. The reservation is released in full. This is a terminal state.

    funds releasedfinal
  5. timed_out

    No callback within the window. This is not the same as failed.

    funds heldpaid, failed
  6. reversed

    Reversed at the provider. Its own ledger entry, so both stay visible. This is a terminal state.

    funds releasedfinal
Every state a payout can hold. A filled square is terminal: once a record is there it will not change again, which is what makes it safe to act on. A hollow one means something is still owed, by Safaricom, by the payer, or by us.

At volume

One payout, or ten thousand

Payroll, supplier runs, farmer payments, rider earnings. Upload a CSV, see what it is going to do before it does it, approve once.

  • Validated before anything moves

    Phone numbers checked against the real Safaricom prefixes, amounts parsed as integers, duplicates within the file flagged. A bad row is reported with its line number rather than failing the batch halfway through.

  • Approved as a batch, posted as rows

    One approval for the run. Each payout is still its own ledger movement with its own state, so one failure out of nine hundred is one failure, not a batch you have to unpick.

  • Reserved up front

    The whole run is held against your balance before the first payment leaves, so you find out that you are short at the point of approval rather than at row four hundred.

  • Saved beneficiaries

    The people you pay regularly are a list, not a column somebody retypes every month. Retyping a phone number every month is how a digit changes.

payroll-october.csvtext
recipient,amount,reference,notes254712345678,1200,SAL-1042,October254701234567,1200,SAL-1043,October254733123456,980,SAL-1044,October, part time

Four columns, one of which is optional. A format somebody can produce from the spreadsheet they already keep, rather than one that requires a developer to generate.

Where it lives

Money leaving has its own screen, and its own second pair of eyes

Every payout’s approval state on the row, not a click away.

app.nostrel.com/payouts
The NOSTREL payouts screen, listing recipients, queued time, approval state and amount, with balance cards above.
The payouts console, with approval state on every row. Demonstration data from a development environment.

Break it in the sandbox first

Send to a number that refuses, to one that times out, to one with no account. You cannot handle a failure you have never seen, and these are the three you will meet.