Skip to content

Latest commit

 

History

History
39 lines (27 loc) · 1.94 KB

File metadata and controls

39 lines (27 loc) · 1.94 KB

Wallet transaction system

Installation and running

  • Requires Python 3.8 or above installed
  • Install dependencies pip install -r requirements.txt
  • Create database python manage.py migrate
  • Create test user python manage.py createsuperuser
  • Run server python manage.py runserver

Note: tests can be run using python manage.py test

Structure

API structure

  • /<user_id>/wallet/ root node to access all functionalities for the wallet associated with user of id user_id
    • create/ (POST) creates new wallet
    • balance/ (GET) gets current balance
    • debit/ (POST) debits amount
    • credit/ (POST) credits amount

Response structure

Responses are returned in JSON format. Each response has a success field which indicates whether the given action was successfully performed or not. In case of failure, there is an error field which indicates the type of error which occurred.

Sample curl requests

  • curl --request POST --url http://localhost:8000/1/wallet/create/ create a new wallet for user 1
  • curl --request GET --url http://localhost:8000/1/wallet/balance/ get balance for wallet of user 1. returns {"success": true, "balance": 100}
  • curl --request POST --url http://localhost:8000/1/wallet/debit/ -H "Content-Type: application/json" -d '{"amount": 20}' debit 20 amount from wallet of user 1
  • curl --request POST --url http://localhost:8000/1/wallet/credit/ -H "Content-Type: application/json" -d '{"amount": 20}' credit 20 amount to wallet of user 1

Notes

  • all transactions create a log entry in the log file for the respective wallet. log files can be found in logs/ directory with format wallet<wallet_id>.log
  • debit transactions fail if balance is less than minimum balance (currently set to 100. can be adjusted in server/config.py)
  • this API does not handle user creation and authentication
  • only 1 create or credit or debit transaction is performed at a time for a user