MpesaElixir.Utils (MpesaElixir v0.2.1)
Utility functions for the MpesaElixir application.
Summary
Functions
Generates the base64 encoded password string from shortcode, passkey and timestamp.
Generates a timestamp in the format YYYYMMDDHHMMSS. The timestamp is generated based on the current UTC time, adjusted by 3 hours (Nairobi Timezone).
Converts a struct to a map with keys formatted as required by the M-PESA API. This function transforms snake_case field names to PascalCase as expected by the API.
Functions
Generates the base64 encoded password string from shortcode, passkey and timestamp.
Examples
iex> MPesa.StkPush.Request.generate_password("174379", "bfb279f9aa9bdbcf158e97dd71a467cd2e0c89305", "20160216165627")
"MTc0Mzc5YmZiMjc5ZjlhYTliZGJjZjE1OGU5N2RkNzFhNDY3Y2QyZTBjODkzMDU5YjEwZjc4ZTZiNzJhZGExZWQyYzkxOTIwMTYwMjE2MTY1NjI3"
@spec generate_timestamp() :: String.t()
Generates a timestamp in the format YYYYMMDDHHMMSS. The timestamp is generated based on the current UTC time, adjusted by 3 hours (Nairobi Timezone).
Converts a struct to a map with keys formatted as required by the M-PESA API. This function transforms snake_case field names to PascalCase as expected by the API.
Examples
iex> request = %MpesaElixir.StkPush.Request{
...> business_short_code: "174379",
...> password: "MTc0Mzc5YmZiMjc5ZjlhYTliZGJjZjE1OGU5N2RkNzFhNDY3Y2QyZTBjODkzMDU5YjEwZjc4ZTZiNzJhZGExZWQyYzkxOTIwMTYwMjE2MTY1NjI3",
...> timestamp: "20160216165627",
...> transaction_type: "CustomerPayBillOnline",
...> amount: "1",
...> party_a: "254708374149",
...> party_b: "174379",
...> phone_number: "254708374149",
...> call_back_url: "https://mydomain.com/path",
...> account_reference: "Test",
...> transaction_desc: "Test"
...> }
iex> MpesaElixir.Utils.to_api_map(request, special_cases: ["url"])