Skip to content

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
AuthSecret key, plus a request signature made with your payout signing secret. See How to sign a request
Scopepayouts:write on the key
PlatformYour 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 onWhere pockets are available: Kenya. Elsewhere the route answers 404

Headers ​

HeaderRequiredValue
AuthorizationYesBearer mkp_…
Idempotency-KeyYes1 to 128 characters. It is part of the signature. It does not make the call idempotent: a code works once
Content-TypeYesapplication/json
X-Mookh-TimestampYesThe Unix time in seconds, within 300 seconds of MOOKHPay's clock
X-Mookh-SignatureYessha256= and 64 lowercase hex characters. See How to sign a request

Parameters ​

Path

NameTypeRequiredConstraints
idstringYesThe same account id you started with

Body. Unknown fields are refused.

NameTypeRequiredConstraints
verification_idstringYesThe verification_id the start call answered, pdv_…
codestringYesExactly 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 ​

FieldTypeMeaning
destination.railstringThe rail the pocket's payouts now go on: mpesa in Kenya
destination.phone_maskedstringThe 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.

HTTPCodeNameWhenWhat to do
4001701INVALID_REQUEST_DATAThe body is not JSON, a field is missing or unknown, code is not six digits, or Idempotency-Key is missingFix the request
4003014IDENTITY_HEADER_REFUSEDThe request carries a session or identity headerRemove it
4012781API_KEY_INVALIDMissing, malformed, unknown or revoked keyCheck the key
4013021PAYOUT_SIGNATURE_INVALIDThe signature is missing, malformed, wrong or already used, or the timestamp is more than 300 seconds outSee How to sign a request
4032941API_KEY_SCOPE_REQUIREDThe key lacks payouts:writeIssue a key with the scope
4033042API_KEY_IP_NOT_ALLOWEDThe account has allowed addresses and the call came from another addressCall from a listed address
4032942PLATFORM_NOT_ENABLEDYour organisation is not a platform, or its platform is suspendedTalk to MOOKHPay
4033013PLATFORM_IP_NOT_ALLOWEDThe call came from an address not on your platform's allow-listCall from a listed address
4033022PAYOUT_SIGNING_SECRET_MISSINGYour platform has no payout signing secret yetAn Owner makes one in API Integrations
4042943PLATFORM_ACCOUNT_NOT_FOUNDThe account is unknown, another platform's or malformedCheck the id
4093061PLATFORM_ACCOUNT_DISCONNECTEDThe person disconnected your platform in MOOKHPayAsk them to connect again
4093063PLATFORM_POCKET_NOT_READYThe pocket is still being openedRetry in a minute, signed again
4151701INVALID_REQUEST_DATAContent-Type is not application/jsonSend JSON
4223064PLATFORM_POCKET_NOT_SET_UPYour platform has no pocket set upAsk MOOKHPay to set one up
4223065OTP_INVALIDThe code is wrong. data.tries_left is how many tries remainAsk the person to check the text and try again
4223066OTP_EXPIREDThe code is past expires_at, was already used, was entered wrong five times, or the verification_id is unknown or not this account'sStart again with Set a payout destination
4291804RATE_LIMIT_EXCEEDEDOver the rate limit belowWait Retry-After seconds
5032782AUTHN_UNAVAILABLEThe key could not be checkedRetry
5033016PLATFORM_ACCOUNTS_UNAVAILABLEThe account or its pocket could not be readRetry

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.

Staging documentation. A checkout made with a secret key on staging charges a real phone. See Environments.