Collect a payment
Your server starts an M-Pesa prompt. Store the ids you get back.
Collect a payment
Your server calls STK push. Safaricom shows the prompt on the customer’s phone. You then confirm the result.
Request
| Field | Required | Use |
|---|---|---|
api_secret, account_id, channel_id | Yes | From API Keys. See Authentication. |
phone | Yes | Kenya number, 2547…. Alias phone_number. |
amount | Yes | KES 1–250000. |
account_reference | No | Your invoice id, max 64 characters. Send the same value as external_reference if you prefer that name. Omit it and BluePay generates one. |
callback_url | No | Webhook for this STK only. Otherwise BluePay uses the Account callback URL. |
What to store
Save these from the STK response before you show “waiting for M-Pesa” in your app:
checkout_request_id— best key for payment status.stk_request_id— BluePay’s integer id for that push.account_reference— the invoice id, yours or the one BluePay generated. Status returns the newest STK for that id.
Prepaid accounts need enough service tokens before the push. A
402 with error_code INSUFFICIENT_PREPAID includes required_kes and balance_kes. Top up, then retry. Postpaid accounts skip that check. The fee is debited when the payment succeeds.Samples, error codes, and the full body are on STK push.