BluePayAPI
Ask AI
BluePay
API Keys Support Dashboard

Confirm a payment

A prompt was sent when STK returns ok. The payment is settled only when paid is true.

Confirm a payment

STK ok: true means Safaricom accepted the prompt. Mark the order paid only after BluePay reports it settled.

Two signals, one result

SignalWhen to use it
WebhookBluePay POSTs the result to your callback URL. Verify X-BluePay-Signature (HMAC-SHA256 of the raw body, keyed with the API secret) and return 2xx quickly.
Payment statusYour server asks for the latest state. Use this when the webhook has not arrived. There are no automatic webhook retries.

How to read status

FieldMeaning
paid: trueSettled. Fulfill the order.
found: true and paid: falseBluePay has the STK. It is still pending or it failed. Read order.status: pending, completed, or failed.
found: falseNo row for that lookup key. Check the id you stored.
payment.pending_confirmationThe receipt is still a temporary RCHK-… value. Wait for the M-Pesa receipt.

Look up by checkout_request_id first. account_reference (or external_reference) returns the newest STK for that invoice id. stk_request_id is the integer from the STK response.

Webhook rules

  • Account → Callback URL is the default. An STK callback_url overrides it for that payment only.
  • Safaricom notifies BluePay. Your URL receives BluePay’s JSON, not Safaricom’s callback.
  • Header X-BluePay-Event is mpesa.payment.received or mpesa.payment.failed for collections.
  • Header Idempotency-Key is the dedupe key for that delivery. Store it so a repeat delivery does not fulfill twice.
  • Compare the amount, phone, and account_reference in data with the order you stored.

The payload and the PHP and Node checks are on Webhooks.