ElixirMpesa.Transactions (ElixirMpesa v0.2.0)

View Source

The M-Pesa OpenAPI operations, one function per endpoint.

Every function here takes an already-resolved ElixirMpesa.Config and an encrypted session key. Most callers want ElixirMpesa instead, which resolves configuration and manages the session for you.

Idempotency

"input_ThirdPartyConversationID" is the idempotency key. It must be unique per logical transaction — and identical across retries of the same transaction, which is how M-Pesa recognises and rejects a duplicate instead of processing it twice.

Summary

Functions

Business to Business payment.

Business to Customer payment.

Customer to Business payment.

Direct debit mandate cancellation.

Direct debit mandate creation.

The operations this module exposes, as {name, method, path}.

Transaction reversal.

Types

attrs()

@type attrs() :: %{optional(String.t()) => term()}

result()

@type result() :: {:ok, ElixirMpesa.Response.t()} | {:error, ElixirMpesa.Error.t()}

Functions

b2b(config, attrs, session_key)

@spec b2b(ElixirMpesa.Config.t(), attrs(), String.t()) :: result()

Business to Business payment.

Sends POST /b2bPayment/.

See ElixirMpesa.b2b/2 for the parameters and a worked example.

b2c(config, attrs, session_key)

@spec b2c(ElixirMpesa.Config.t(), attrs(), String.t()) :: result()

Business to Customer payment.

Sends POST /b2cPayment/.

See ElixirMpesa.b2c/2 for the parameters and a worked example.

c2b(config, attrs, session_key)

@spec c2b(ElixirMpesa.Config.t(), attrs(), String.t()) :: result()

Customer to Business payment.

Sends POST /c2bPayment/singleStage/.

See ElixirMpesa.c2b/2 for the parameters and a worked example.

direct_debit_cancel(config, attrs, session_key)

@spec direct_debit_cancel(ElixirMpesa.Config.t(), attrs(), String.t()) :: result()

Direct debit mandate cancellation.

Sends PUT /directDebitCancel/.

See ElixirMpesa.direct_debit_cancel/2 for the parameters and a worked example.

direct_debit_creation(config, attrs, session_key)

@spec direct_debit_creation(ElixirMpesa.Config.t(), attrs(), String.t()) :: result()

Direct debit mandate creation.

Sends POST /directDebitCreation/.

See ElixirMpesa.direct_debit_creation/2 for the parameters and a worked example.

direct_debit_payment(config, attrs, session_key)

@spec direct_debit_payment(ElixirMpesa.Config.t(), attrs(), String.t()) :: result()

Direct debit payment.

Sends POST /directDebitPayment/.

See ElixirMpesa.direct_debit_payment/2 for the parameters and a worked example.

operations()

@spec operations() :: keyword({:get | :post | :put, String.t()})

The operations this module exposes, as {name, method, path}.

Examples

iex> ElixirMpesa.Transactions.operations() |> Keyword.keys() |> Enum.sort() |> Enum.take(3)
[:b2b, :b2c, :c2b]

query_beneficiary_name(config, attrs, session_key)

@spec query_beneficiary_name(ElixirMpesa.Config.t(), attrs(), String.t()) :: result()

Beneficiary name query.

Sends GET /queryBeneficiaryName/.

See ElixirMpesa.query_beneficiary_name/2 for the parameters and a worked example.

query_direct_debit(config, attrs, session_key)

@spec query_direct_debit(ElixirMpesa.Config.t(), attrs(), String.t()) :: result()

Direct debit mandate query.

Sends GET /queryDirectDebit/.

See ElixirMpesa.query_direct_debit/2 for the parameters and a worked example.

query_transaction_status(config, attrs, session_key)

@spec query_transaction_status(ElixirMpesa.Config.t(), attrs(), String.t()) ::
  result()

Transaction status query.

Sends GET /queryTransactionStatus/.

See ElixirMpesa.query_transaction_status/2 for the parameters and a worked example.

reversal(config, attrs, session_key)

@spec reversal(ElixirMpesa.Config.t(), attrs(), String.t()) :: result()

Transaction reversal.

Sends PUT /reversal/.

See ElixirMpesa.reversal/2 for the parameters and a worked example.