Banking application using Elixir/OTP with the features of creating users, deposits, withdrawals, get balances and send money.
To run the application locally, follow these steps:
elixir 1.16.0-otp-26
erlang 26.2.1
- Elixir and Erlang versions are already added to
.tool-versions
and can be installed using asdf.
git clone https://github.com/sharmadeepak29/ex_banking.git
cd ex_banking
To start your server:
- Run
mix deps.get
to install and setup dependencies - Start inside IEx with
iex -S mix
.
- Creates new user in the system.
- New user has zero balance of any currency.
Request:
ExBanking.create_user(name)
Response:
:ok | {:error, :wrong_arguments | :user_already_exists}
Example:
ExBanking.create_user("Deepak Sharma")
Deposit funds into a user account.
- Increases user’s balance in then given currency by amount value.
- Returns the updated balance of the user in the given currency.
Request:
ExBanking.deposit(name, amount, currency)
Response:
{:ok, updated_balance :: number} | {:error, :wrong_arguments | :user_does_not_exist | :too_many_requests_to_user}
Example:
{:ok, 100.5} = ExBanking.deposit("Deepak Sharma", 100.50, "USD")
Withdraw funds from a user account.
- Decreases the user’s balance in the given currency by amount value.
- Returns the updated balance of the user in the given currency.
Request:
ExBanking.withdraw(name, amount, currency)
Response:
{:ok, updated_balance :: number} | {:error, :wrong_arguments | :user_does_not_exist | :not_enough_money | :too_many_requests_to_user}
Example:
{:ok, 90.0} = ExBanking.withdraw("Deepak Sharma", 10.50, "USD")
Retrieves the current balance of the user in the given currency.
Request:
ExBanking.get_balance(name, currency)
Response:
{:ok, updated_balance :: number} | {:error, :wrong_arguments | :user_does_not_exist | :too_many_requests_to_user}
Example:
{:ok, 90.0} = ExBanking.get_balance("Deepak Sharma", "USD")
Sends money from one account to another.
- Decreases from_user’s balance in given currency by amount value.
- Increases to_user’s balance in given currency by amount value.
- Returns updated balances of from_user and to_user.
Request:
ExBanking.send(from_user, to_user, amount, currency)
Response:
{:ok, from_user_balance :: number, to_user_balance :: number} | {:error, :wrong_arguments | :not_enough_money | :sender_does_not_exist | :receiver_does_not_exist | :too_many_requests_to_sender | :too_many_requests_to_receiver}
Example:
{:ok, 80.0, 10.0} = ExBanking.send("Deepak Sharma", "Pranav", 10, "USD")
To run the tests for this project, simply run in your terminal:
mix test
- Official website: https://www.phoenixframework.org/
- Guides: https://hexdocs.pm/phoenix/overview.html
- Docs: https://hexdocs.pm/phoenix
- Forum: https://elixirforum.com/c/phoenix-forum
- Source: https://github.com/phoenixframework/phoenix