Omise Elixir Client
Omise for Elixir
Installation
-
Add omise to your list of dependencies in
mix.exs:
def deps do
[{:omise, "~> 0.4"}]
end- Ensure omise is started before your application:
def application do
[applications: [:omise]]
endConfiguration
Set the following configuration variables in config/config.exs file:
config :omise,
public_key: "pkey_test_xxx",
secret_key: "skey_test_xxx"Or manually configure at runtime:
Omise.configure(public_key: "pkey_test_xxx", secret_key: "skey_test_xxx")
To configure the HTTP options, you could optionally add :http_options key to the omise configuration. For a full list of the available options, please check HTTPoison documentation.
config :omise,
http_options: [timeout: 20_000, recv_timeout: 20_000]Example
response = Omise.Charge.create(
amount: 1000_00,
currency: "thb",
card: "tokn_51w6fvilnsxalda4cih"
)
case response do
{:ok, charge} ->
# handle success
{:error, error} ->
# handle failure
endYou can also set a per-request key and api version when making an API call:
Omise.Charge.list([], key: "skey_test_xxx", api_version: "2015-11-17")
Omise.Charge.retrieve("chrg_test_4yq7duw15p9hdrjp8oq", key: "skey_test_xxx")
Omise.Charge.create([
amount: 1000_00,
currency: "thb",
customer: "cust_test_xxx"
], key: "skey_test_xxx")Development
-
Install all dependencies with
mix deps.get -
Run tests with
mix test