Daraja SDK Logomark
Daraja SDK
Account & Ledger

Reversals

Reverse a recent C2B transaction on the business account.

Endpoint

POST https://sandbox.safaricom.co.ke/mpesa/reversal/v1/request

Overview

Reverses a Customer to Business (C2B) transaction: M-PESA refunds the customer, sends an SMS notification, and returns the result to the organization via Daraja.

Use cases

  • An erroneous payment to your Pay Bill or Till.
  • A duplicate payment.
  • A payment for a service that was never fulfilled.

Prerequisites

  • Daraja account and sandbox app.
  • For production: a live Pay Bill/Till with Business Admin/Manager operators created.

Request

{
  "Initiator": "apiop37",
  "SecurityCredential": "jUb+dOXJiBDui8FnruaFckZJQup3kmmCH5XJ4NY/Oo3KaUTmJbxUiVgzBjqdL533u5Q435MT2VJwr/ /1fuZvA===",
  "CommandID": "TransactionReversal",
  "TransactionID": "PDU91HIVIT",
  "Amount": "200",
  "ReceiverParty": "603021",
  "RecieverIdentifierType": "11",
  "ResultURL": "https://mydomain.com/reversal/result",
  "QueueTimeOutURL": "https://mydomain.com/reversal/queue",
  "Remarks": "Payment reversal"
}
FieldDescriptionSample value
InitiatorAPI operator username.johndoe
SecurityCredentialEncrypted initiator password.(encrypted string)
CommandIDOnly TransactionReversal is accepted.TransactionReversal
TransactionIDThe M-PESA receipt number of the transaction to reverse.PDU91HIVIT
AmountAmount to reverse.100
ReceiverPartyYour organization short code.600997
RecieverIdentifierType (sic)Documented as always 11.11
Remarks2 to 100 characters.Free text
QueueTimeOutURL / ResultURLTimeout and result callback URLs.https://domain:port/path

RecieverIdentifierType is spelled that way, "Reciever," in Safaricom's own documentation, kept as-is since it's the literal field name expected in the request.

Response

{
  "OriginatorConversationID": "f1e2-4b95-a71d-b30d3cdbb7a7735297",
  "ConversationID": "AG_20210706_20106e9209f64bebd05b",
  "ResponseCode": "0",
  "ResponseDescription": "Accept the service request successfully."
}

This is only an acknowledgment; the actual outcome arrives at ResultURL.

Callback

Reversals use standard M-PESA result codes for 2001, 2006, 2028, 8006, 11, and 1, the same as the B2C result codes, plus two reversal-specific codes.

{
  "Result": {
    "ResultType": 0,
    "ResultCode": 0,
    "ResultDesc": "The service request is processed successfully.",
    "OriginatorConversationID": "dad6-4c34-8787-c8cb963a496d1268232",
    "ConversationID": "AG_20211114_201018edbbf9f1582eaa",
    "TransactionID": "SKE52PAWR9",
    "ResultParameters": {
      "ResultParameter": [
        {
          "Key": "DebitAccountBalance",
          "Value": "Utility Account|KES|7722179.62|7722179.62|0.00|0.00"
        },
        { "Key": "Amount", "Value": 1.0 },
        { "Key": "TransCompletedTime", "Value": 20211114132711 },
        { "Key": "OriginalTransactionID", "Value": "SKC82PACB8" },
        { "Key": "Charge", "Value": 0.0 },
        {
          "Key": "CreditPartyPublicName",
          "Value": "254705912645 - NICHOLAS JOHN SONGOK"
        },
        {
          "Key": "DebitPartyPublicName",
          "Value": "600992 - Safaricom Daraja 992"
        }
      ]
    },
    "ReferenceData": {
      "ReferenceItem": {
        "Key": "QueueTimeoutURL",
        "Value": "https://internalsandbox.safaricom.co.ke/mpesa/reversalresults/v1/submit"
      }
    }
  }
}
FieldDescription
DebitAccountBalancePost-reversal balance on the debited account.
Amount / ChargeAmount reversed and fee, if any.
TransCompletedTimeYYYYMMDDhhmmss.
OriginalTransactionIDThe receipt number of the transaction that was reversed.
CreditPartyPublicName / DebitPartyPublicNameNames of the parties involved.

Result codes

CodeMeaningExplanation
0SuccessReversal processed.
R000002Original transaction ID invalidTransactionID doesn't exist on M-PESA.
R000001Already reversedThis transaction was already reversed once.
11DebitParty invalid stateAccount isn't active.
21Initiator not allowedMissing Org Reversals Initiator role.
2001Initiator information invalidWrong credentials or encryption.
2006Account rule declinedAccount isn't active.
2028Not permitted by product assignmentShort code lacks permission.
8006Security credential lockedBusiness Administrator must unlock.
1Insufficient balanceShort code lacks funds to complete the reversal.

Error codes

CodeCauseFix
404.001.03Invalid access tokenRegenerate before expiry.
400.002.02Bad request, invalid fieldMatch the documented payload.
404.001.01Resource not foundCheck the endpoint.

Testing and Go Live

Daraja Simulator with the Reversals product attached, or Postman against the sandbox endpoint above.

Going live requires the Org Reversals Initiator role on your API user; see Organization Portal & Go Live.

FAQs

On this page