ewallet
This web api is using framework Flask from python and database using MySQL
Installation instructions
- Make sure you have python > 3.7 Installed on your machine. Download Python.
- Clone this repo using command on your terminal
git clone https://github.com/adityamuhammad/ewallet.git
- Copy
.env.example
to.env
, and fill the value of the variable, (fill JWT_SECRET_KEY and DATABASE_URI_DEV value. example: Since I use mysql database for this project, so fill the DATABASE_URI_DEV value withmysql+pymysql://<username>:<password>@localhost/ewallet_dev
. Also dont forget to create database with the name ewallet_dev. - Run command on your terminal
pip install pipenv
if you dont have install pipenv yet. - Run command
pipenv shell
to activate the virtual environment. - Run command
pip install -r requirements.txt
to install modules. - Set variable FLASK_ENV to development. Run command on terminal
export FLASK_ENV=development
, if you are using Windows use commandset FLASK_ENV=development
- Set variable CONFIG_SETTING to config.Devconfig . Run command on terminal
export CONFIG_SETTING=config.DevConfig
, if you are using Windows use commandset CONFIG_SETTING=config.DevConfig
- Run migration for database using command
make migrate_dev
. After that, run commandmake seed_dev
for creating seed data. - To run application, use command
flask run
.
Endpoint
1. Login
Used for authenticating registered user, get access token stored in cookie with httponly set to true.
URL : /token/auth
Method : POST
Auth required : NO
Request Body
{
"email": "[valid email address]",
"password": "[password in plain text]"
}
Request Header use default request header
Success Response
set access_token_cookie,csrf_access_token,refresh_token_cookie,csrf_refresh_token in header response
Code : 200 OK
Response body
{
"msg": "login success."
}
Error Response
Condition : If 'email' and 'password' combination is wrong.
Code : 400 BAD REQUEST
Content :
{
"msg": "login failed."
}
2. Refresh token
Used for refresh access token
URL : /token/refresh
Method : POST
Auth required : NO
Request Body None
Request Header
{
"X-CSRF-TOKEN": "[csrf_refresh_token]",
"refresh_token_cookie": "[refresh_token_cookie]"
}
Success Response
Code : 200 OK
Response body
{
"msg": "token refreshed."
}
Error Response
Condition : If request header invalid.
Code : 401 UNAUTHORIZED
Content :
{
"msg": "whether csrf token refresh or refresh token invalid"
}
3. remove token or logout
Used for remove access token
URL : /token/remove
Method : POST
Auth required : NO
Request Body None
Request Header None
Success Response
Code : 200 OK
Response body
{
"msg": "logout success."
}
4. Topup
Used for topup
URL : /api/topup
Method : POST
Auth required : YES
Request Body
{
"amount": "[amount]",
}
Request Header
{
"X-CSRF-TOKEN": "[csrf_access_token]",
"location": "[client location]",
"ip-address": "[ip-address client]"
}
Success Response
Code : 200 OK
Response body
{
"msg": "transaction success."
}
Error Response
Condition : If request send is invalid.
Code : 400 BAD REQUEST
Content :
{
"msg": "transaction failed."
}
5. Transfer
Used for transfer
URL : /api/transfer
Method : POST
Auth required : YES
Request Body
{
"amount": "[amount]",
"code": "[code]"
}
Request Header
{
"X-CSRF-TOKEN": "[csrf_access_token]",
"location": "[client location]",
"ip-address": "[ip-address client]"
}
Success Response
Code : 200 OK
Response body
{
"msg": "transaction success."
}
Error Response
Condition : If request send is invalid.
Code : 400 BAD REQUEST
Content :
{
"msg": "transaction failed."
}