Packages

Elixir client library for the Paymob payment gateway (Egypt, UAE, KSA, Oman)

Current section

Files

Jump to
ex_paymob lib ex_paymob.ex
Raw

lib/ex_paymob.ex

defmodule ExPaymob do
@moduledoc """
Elixir client library for the Paymob payment gateway.
Supports Egypt, UAE, KSA, and Oman regions with both the new V1 API
and legacy endpoints for transaction management.
## Configuration
# config/runtime.exs
config :ex_paymob,
secret_key: System.get_env("PAYMOB_SECRET_KEY"),
public_key: System.get_env("PAYMOB_PUBLIC_KEY"),
hmac_secret: System.get_env("PAYMOB_HMAC_SECRET"),
region: :egypt
## Usage
# Create a payment intention
ExPaymob.Intention.create(%{
amount: 10000,
currency: "EGP",
payment_methods: [integration_id],
billing_data: %{
first_name: "John",
last_name: "Doe",
email: "john@example.com",
phone_number: "+201234567890"
},
items: []
})
# Per-request config override
ExPaymob.Intention.create(params, secret_key: "sk_other_key")
"""
@type id :: String.t()
@type options :: keyword()
@type amount :: pos_integer()
@type region :: :egypt | :uae | :ksa | :oman
# --- Intention ---
defdelegate create_intention(params, opts \\ []), to: ExPaymob.Intention, as: :create
defdelegate update_intention(client_secret, params, opts \\ []),
to: ExPaymob.Intention,
as: :update
# --- Transaction ---
defdelegate get_transaction(id, opts \\ []), to: ExPaymob.Transaction, as: :retrieve
defdelegate inquire_transaction(params, opts \\ []), to: ExPaymob.Transaction, as: :inquire
# --- Refund ---
defdelegate refund(transaction_id, amount_cents, opts \\ []), to: ExPaymob.Refund, as: :create
# --- Void ---
defdelegate void(transaction_id, opts \\ []), to: ExPaymob.Void, as: :create
# --- Capture ---
defdelegate capture(transaction_id, amount_cents, opts \\ []), to: ExPaymob.Capture, as: :create
end