Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions .github/workflows/hex-publish.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
name: Publish to Hex.pm
on:
push:
tags:
- '*'
push:
tags:
- '*'

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v2
publish:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v4

- name: Publish to Hex.pm
uses: erlangpack/github-action@v1
env:
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: '1.15'
otp-version: '26'

- name: Install dependencies
run: mix deps.get

- name: Publish to Hex
run: mix hex.publish --yes
env:
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ by adding `mpesa_elixir` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:mpesa_elixir, "~> 0.2.0"}
{:mpesa_elixir, "~> 0.2.1"}
]
end
```
Expand All @@ -46,14 +46,19 @@ Add below config to dev.exs / prod.exs files
This asumes you have a clear understanding of how [Daraja API works](https://developer.safaricom.co.ke/get-started).

In this wrapper I decided to only add credentials to config for flexibility and avoid config bloating.

Add these configuration to runtime config (for production)
```elixir
config :mpesa_elixir,
sandbox: true, # change this if you are in production
consumer_key: "your consumer key",
consumer_secret: "your consumer secret",
pass_key: "your pass key",
env: Mix.env() # will not start the auth server when testing
pass_key: "your pass key"
```

If you dont want to start the auth server when testing, add this to your test.exs, you need to do this in order to avoid auth warnings when testing, by default it is set to true
```elixir
config :mpesa_elixir,
auto_start_auth_server: false
```

## Documentation
Expand Down
3 changes: 2 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ config :mpesa_elixir,
auth_req_options: [
plug: {Req.Test, MpesaElixir.API}
],
env: Mix.env()
env: config_env(),
auto_start_auth_server: config_env() != :test

if File.exists?("config/config.secret.exs") do
import_config("config.secret.exs")
Expand Down
9 changes: 5 additions & 4 deletions lib/mpesa_elixir/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ defmodule MpesaElixir.Application do
use Application

# their failure does not cause panic to the application
# format {child, dont_start_in_test}
# format {child, auto_start_auth_server}
@delayed_children [
{MpesaElixir.AuthServer, Application.compile_env(:mpesa_elixir, :env) == :test}
{MpesaElixir.AuthServer,
Application.compile_env(:mpesa_elixir, :auto_start_auth_server, true)}
]

def start(_type, _args) do
Expand All @@ -23,8 +24,8 @@ defmodule MpesaElixir.Application do
end

defp start_delayed_children do
Enum.each(@delayed_children, fn {child, dont_start_in_test} ->
dont_start_in_test || DynamicSupervisor.start_child(MpesaSupervisor, child)
Enum.each(@delayed_children, fn {child, start_in_test} ->
start_in_test && DynamicSupervisor.start_child(MpesaSupervisor, child)
end)
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule MpesaElixir.MixProject do
def project do
[
app: :mpesa_elixir,
version: "0.2.0",
version: "0.2.1",
elixir: "~> 1.6",
elixirc_paths: elixirc_paths(Mix.env()),
test_coverage: [tool: ExCoveralls],
Expand Down