ExPesa v0.1.1 ExPesa.Mpesa.AccountBalance View Source

The Account Balance API requests for the account balance of a shortcode.

Link to this section Summary

Functions

Initiates account balnce request

Link to this section Functions

Initiates account balnce request

Configuration

Add below config to dev.exs / prod.exs files This asumes you have a clear understanding of how Daraja API works. See docs here https://developer.safaricom.co.ke/docs#account-balance-api

config.exs

  config :ex_pesa,
      mpesa: [
          cert: "",
          balance: [
              short_code: "",
              initiator_name: "Safaricom1",
              password: "Safaricom133",
              timeout_url: "",
              result_url: "",
              security_credential: ""
          ]
      ]

To generate security_credential, head over to https://developer.safaricom.co.ke/test_credentials, then Initiator Security Password for your environment. 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

Example

iex> ExPesa.Mpesa.AccountBalance.request()
{:ok,
  %{
      "ConversationID" => "AG_20201010_00007d6021022d396df6",
      "OriginatorConversationID" => "28290-142922216-2",
      "ResponseCode" => "0",
      "ResponseDescription" => "Accept the service request successfully."
  }}