Transaction Status
By the end of this track you can find out what happened and undo it.
0/3 finished
Step 1
The idea
Ask M-Pesa what happened to a transaction, by receipt or originator ID. The answer comes to your ResultURL.
Step 2
How it works
What you can ask about
Any transaction on your shortcode: a payout, a C2B payment, an STK payment. Give the M-Pesa receipt as TransactionID. When you never got a receipt, as after a B2C or B2B timeout, leave it empty and send the payout's ID as OriginalConversationID. IdentifierType is 4 for a shortcode, 2 for a Till and 1 for a phone number.
The request
POST to /mpesa/transactionstatus/v1/query with your initiator, like B2C.
{ "Initiator": "testapi", "SecurityCredential": "<encrypted password>", "CommandID": "TransactionStatusQuery", "TransactionID": "TJT4XXXXXX", "OriginalConversationID": "", "PartyA": "600996", "IdentifierType": "4", "ResultURL": "https://your-domain.example/status/result", "QueueTimeOutURL": "https://your-domain.example/status/timeout", "Remarks": "Check payout", "Occasion": ""}The answer
Like every operations API, the answer comes later to your ResultURL. Its ResultParameters include ReceiptNo, TransactionStatus (such as Completed), Amount, the debit and credit party names and FinalisedTime.
When to use it
Run it from a scheduled job for anything stuck in accepted or unknown, and before any manual fix a person is about to make.
Step 3
Try it
Look up the receipt from lesson C1.
With the MCP server, ask your agent to use mpesa_transaction_status
Step 4
Common mistakes
- Expecting the status in the immediate response. It comes to your ResultURL.
- Fixing records by hand before checking what M-Pesa says.
Go deeper
Which states in your system should trigger this query?
Answer in your own words first.
Show the answerHide the answer
Accepted, or timed out, for too long.