ExMpesa.TransactionStatus (ExMpesa v0.1.0) View Source

Use this api to check the transaction status.

Link to this section Summary

Functions

Transaction Status Query

Link to this section Functions

Transaction Status Query

Requirement Params

  • CommandID[String] - Takes only 'TransactionStatusQuery' command id

  • timeout_url [URL] - The path that stores information of time out transaction. Takes the form of https://ip or domain:port/path

  • result_url[URL] - The path that stores information of transaction. Example https://ip or domain:port/path

  • Initiator [Alpha-Numeric] - The name of Initiator to initiating the request. This is the credential/username used to authenticate the transaction request

  • security credential - To generate security_credential, head over to https://developer.safaricom.co.ke/test_credentials, then Initiator Security Password for your environment.

config.exs

    config :ex_mpesa,
        cert: "",
        transaction_status: [
          initiator_name: "",
          password: "",
          timeout_url: "",
          result_url: "",
          security_credential: ""
        ]

Alternatively, generate security credential using certificate cert - This is the M-Pesa public key certificate used to encrypt your plain password. There are 2 types of certificates.

- sandox - https://developer.safaricom.co.ke/sites/default/files/cert/cert_sandbox/cert.cer .
- production - https://developer.safaricom.co.ke/sites/default/files/cert/cert_prod/cert.cer .

password - This is a plain unencrypted password. Environment

- production - set password from the organization portal.
- sandbox - use your own custom password

Parameters

The following are the parameters required for this method, the rest are fetched from config files.

  • transaction_id [Alpha-Numeric] - Unique identifier to identify a transaction on M-Pesa Alpha-Numeric LKXXXX1234
  • receiver_party [Numeric] - Organization/MSISDN receiving the transaction, can be -Shortcode (6 digits) -MSISDN (12 Digits)
  • identifier_type [Numeric] - Type of organization receiving the transaction can be the folowing: 1 – MSISDN 2 – Till Number 4 – Organization short code
  • remarks[String] - Comments that are sent along with the transaction, can be a sequence of characters up to 100
  • occasion [ String] - Optional Parameter String sequence of characters up to 100

Example

iex> ExMpesa.TransactionStatus.request(%{transaction_id: "SOME7803", receiver_party: "600247", identifier_type: 4, remarks: "TransactionReversal",  occasion: "TransactionReversal"})
{:ok,
  %{
      "ConversationID" => "AG_20201010_000056be35a7b266b43e",
      "OriginatorConversationID" => "27288-72545279-2",
      "ResponseCode" => "0",
      "ResponseDescription" => "Accept the service request successfully."
  }
}