Appearance
Verify a payout destination
Finishes changing where your pocket's payouts go for one account. Send the verification_id from Set a payout destination and the six-digit code the person received by text. When the code is right, that number becomes the pocket's payout number, replacing any number set before, and payouts from the pocket go there.
Only pocket mode has it. Your app only passes the code on: MOOKHPay sends it, and you never see it except as the person types it.
Endpoint
POST /v1/payments/merchant/accounts/{id}/payout-destination/verify| Auth | Secret key, plus a request signature made with your payout signing secret. See How to sign a request |
| Scope | payouts:write on the key |
| Platform | Your organisation must be switched on as a platform, with a pocket set up. Calls must come from an address on your allow-list if MOOKHPay set one |
| Switched on | Where pockets are available: Kenya. Elsewhere the route answers 404 |
Headers
| Header | Required | Value |
|---|---|---|
Authorization | Yes | Bearer mkp_… |
Idempotency-Key | Yes | 1 to 128 characters. It is part of the signature. It does not make the call idempotent: a code works once |
Content-Type | Yes | application/json |
X-Mookh-Timestamp | Yes | The Unix time in seconds, within 300 seconds of MOOKHPay's clock |
X-Mookh-Signature | Yes | sha256= and 64 lowercase hex characters. See How to sign a request |
Parameters
Path
| Name | Type | Required | Constraints |
|---|---|---|---|
id | string | Yes | The same account id you started with |
Body. Unknown fields are refused.
| Name | Type | Required | Constraints |
|---|---|---|---|
verification_id | string | Yes | The verification_id the start call answered, pdv_… |
code | string | Yes | Exactly six digits, as a string: "042815". Anything else is 400 and code 1701, and does not use up a try |
Example request
sh
ACCOUNT=acct_ke_9c2f41b07e5d38a6c1f0b294
HOST=https://payments-ke-staging.mookhpay.co
URL_PATH="/v1/payments/merchant/accounts/$ACCOUNT/payout-destination/verify"
KEY="destination-verify-$(date +%s)"
BODY='{"verification_id":"pdv_ke_7c3e9a1b0d4f52e8a6b1c093","code":"042815"}'
TS=$(date +%s)
SIG="sha256=$(printf '%s.POST.%s.%s.%s' "$TS" "$URL_PATH" "$KEY" "$BODY" \
| openssl dgst -sha256 -hmac "$MOOKHPAY_PAYOUT_SECRET" -hex \
| sed 's/^.* //')"
curl -X POST "$HOST$URL_PATH" \
-H "Authorization: Bearer $MOOKHPAY_SECRET_KEY" \
-H "Idempotency-Key: $KEY" \
-H "Content-Type: application/json" \
-H "X-Mookh-Timestamp: $TS" \
-H "X-Mookh-Signature: $SIG" \
--data-binary "$BODY"js
import { createHmac, randomUUID } from "node:crypto";
const BASE = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant";
export async function verifyDestination(accountId, verificationId, code) {
const url = new URL(`${BASE}/accounts/${accountId}/payout-destination/verify`);
const body = JSON.stringify({ verification_id: verificationId, code });
const idempotencyKey = randomUUID();
const timestamp = Math.floor(Date.now() / 1000).toString();
const signature =
"sha256=" +
createHmac("sha256", process.env.MOOKHPAY_PAYOUT_SECRET)
.update(`${timestamp}.POST.${url.pathname}.${idempotencyKey}.`)
.update(body)
.digest("hex");
const res = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.MOOKHPAY_SECRET_KEY}`,
"Idempotency-Key": idempotencyKey,
"Content-Type": "application/json",
"X-Mookh-Timestamp": timestamp,
"X-Mookh-Signature": signature,
},
body,
});
const answer = await res.json();
if (answer.ok) return { ok: true, destination: answer.data.destination };
if (answer.data?.error === "OTP_INVALID") {
return { ok: false, retry: true, triesLeft: answer.data.tries_left };
}
if (answer.data?.error === "OTP_EXPIRED") return { ok: false, retry: false };
throw new Error(`${res.status} ${answer.code}: ${answer.description}`);
}
const result = await verifyDestination(
"acct_ke_9c2f41b07e5d38a6c1f0b294",
"pdv_ke_7c3e9a1b0d4f52e8a6b1c093",
"042815",
);
console.log(result);Response
200 OK with description Payout destination set.
json
{
"ok": true,
"description": "Payout destination set",
"data": {
"destination": { "rail": "mpesa", "phone_masked": "+254 7•• ••• 678" }
}
}Response fields
| Field | Type | Meaning |
|---|---|---|
destination.rail | string | The rail the pocket's payouts now go on: mpesa in Kenya |
destination.phone_masked | string | The number, masked the same way as on the payout object. Store this, not the number |
Errors
Refusals from the call itself carry the code's name in data.error.
| HTTP | Code | Name | When | What to do |
|---|---|---|---|---|
400 | 1701 | INVALID_REQUEST_DATA | The body is not JSON, a field is missing or unknown, code is not six digits, or Idempotency-Key is missing | Fix the request |
400 | 3014 | IDENTITY_HEADER_REFUSED | The request carries a session or identity header | Remove it |
401 | 2781 | API_KEY_INVALID | Missing, malformed, unknown or revoked key | Check the key |
401 | 3021 | PAYOUT_SIGNATURE_INVALID | The signature is missing, malformed, wrong or already used, or the timestamp is more than 300 seconds out | See How to sign a request |
403 | 2941 | API_KEY_SCOPE_REQUIRED | The key lacks payouts:write | Issue a key with the scope |
403 | 3042 | API_KEY_IP_NOT_ALLOWED | The account has allowed addresses and the call came from another address | Call from a listed address |
403 | 2942 | PLATFORM_NOT_ENABLED | Your organisation is not a platform, or its platform is suspended | Talk to MOOKHPay |
403 | 3013 | PLATFORM_IP_NOT_ALLOWED | The call came from an address not on your platform's allow-list | Call from a listed address |
403 | 3022 | PAYOUT_SIGNING_SECRET_MISSING | Your platform has no payout signing secret yet | An Owner makes one in API Integrations |
404 | 2943 | PLATFORM_ACCOUNT_NOT_FOUND | The account is unknown, another platform's or malformed | Check the id |
409 | 3061 | PLATFORM_ACCOUNT_DISCONNECTED | The person disconnected your platform in MOOKHPay | Ask them to connect again |
409 | 3063 | PLATFORM_POCKET_NOT_READY | The pocket is still being opened | Retry in a minute, signed again |
415 | 1701 | INVALID_REQUEST_DATA | Content-Type is not application/json | Send JSON |
422 | 3064 | PLATFORM_POCKET_NOT_SET_UP | Your platform has no pocket set up | Ask MOOKHPay to set one up |
422 | 3065 | OTP_INVALID | The code is wrong. data.tries_left is how many tries remain | Ask the person to check the text and try again |
422 | 3066 | OTP_EXPIRED | The code is past expires_at, was already used, was entered wrong five times, or the verification_id is unknown or not this account's | Start again with Set a payout destination |
429 | 1804 | RATE_LIMIT_EXCEEDED | Over the rate limit below | Wait Retry-After seconds |
503 | 2782 | AUTHN_UNAVAILABLE | The key could not be checked | Retry |
503 | 3016 | PLATFORM_ACCOUNTS_UNAVAILABLE | The account or its pocket could not be read | Retry |
Rate limit
30 requests a minute per platform, shared with Set a payout destination. Over it: 429, code 1804, with Retry-After and data.retryAfter in seconds.