ExMpesa.C2B.registerurl

You're seeing just the function registerurl, go back to ExMpesa.C2B module for more information.

There are two URLs required for RegisterURL API: Validation URL and Confirmation URL. For the two URLs, below are some pointers. This will also apply to the Callback URLs used on other APIs:

  • Use publicly available (Internet-accessible) IP addresses or domain names.
  • Do not use the words MPesa, M-Pesa, Safaricom or any of their variants in either upper or lower cases in your URLs, the system filters these URLs out and blocks them. Of course any Localhost URL will be refused.
  • Do not use public URL testers e.g. mockbin or requestbin especially on production, they are also blocked by the API.

Parameters

attrs: - a map containing:

  • ShortCode - This is your paybill number/till number, which you expect to receive payments notifications about.
  • ResponseType - [Cancelled/Completed] This is the default action value that determines what MPesa will do in the scenario that your endpoint is unreachable or is unable to respond on time. Only two values are allowed: Completed or Cancelled. Completed means MPesa will automatically complete your transaction, whereas Cancelled means MPesa will automatically cancel the transaction, in the event MPesa is unable to reach your Validation URL.
  • ConfirmationURL - [confirmation URL].
  • ValidationURL - [validation URL].

Example

iex> ExMpesa.C2B.registerurl(%{ConfirmationURL: "https://58cb49b30213.ngrok.io/confirmation", ValidationURL: "https://58cb49b30213.ngrok.io/validation",  ResponseType: "Completed"})
{:ok,
  %{
    "ConversationID" => "",
    "OriginatorCoversationID" => "",
    "ResponseDescription" => "success"
  }
}