Skip to content

golang-demos/wallet-basic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wallet Basic System

Table Of Contents

Dependencies

  1. Go Language & Modules
  2. Fiber : go get github.com/gofiber/fiber
  3. MongoDB : go get github.com/mongodb/mongo-go-driver/mongo
  4. Env : github.com/joho/godotenv

Modules

  • User Sign-In, Signup
  • Wallet: Credit, Debit

Run

Development Mode

docker-compose -f docker-compose.dev.yml up
cd ./api
go run main.go

Production Mode

docker-compose -f docker-compose.yml up --build

Test Run

User Signup


Details:

Property Value
API /api/v1/signup
Method POST
Authentication Not-Required
Description This API is for registering a new user with name, mobile and password.

Input:

name     : User's name
mobile   : User's mobile. Unique.
password : Password for login

Sample Request:

curl --location --request POST "http://localhost:3000/api/v1/signup" \
--header 'Content-Type: application/json' \
--data-raw '{
	"name": "Vinay Jeurkar",
	"mobile": "9766123123",
	"password": "12345"
}'

Sample Response:

{
    "success": true,
    "user": {
        "name": "Vinay Jeurkar",
        "mobile": "9766123123",
        "role": "user"
    }
}

User Login


Details:

Property Value
API /api/v1/session/login
Method POST
Authentication Not-Required
Description This API is for logging in using the credentials provided at the time of signup.

Input:

mobile   : User's mobile number
password : User's password

Sample Request:

curl --location --request POST "http://localhost:3000/api/v1/session/login" \
--header 'Content-Type: application/json' \
--data-raw '{
	"mobile": "9766123123",
	"password": "12345"
}'

Sample Response:

{
    "isLoggedIn": true,
    "token": "XVlBzgbaiCMRAjWwhTHctcuA"
}

NOTE: After successful login, this API provides a Token in response which should be put as a value of SESS-TOKEN HTTP Header in all the rest of the APIs to indicate the session of a logged in user.

Session Details


Details:

Property Value
API /api/v1/signup
Method GET
Authentication Optional
Description This API is used for fetching currently logged in user's details. This information is derieved from the value of SESS-TOKEN HTTP Header.

Sample Request: (Please substitute <SESS-TOKEN> with right value)

curl --location --request GET "http://localhost:3000/api/v1/session/get" \
--header 'SESS-TOKEN: <SESS-TOKEN>'

Sample Response:

{
    "LoggedIn": true,
    "User": {
        "name": "Vinay Jeurkar",
        "mobile": "9766123123",
        "role": "user"
    }
}

Deposit to Wallet


Details:

Property Value
API /api/v1/wallet/make
Method POST
Authentication Required
Description This API is used for adding money to user's wallet. It also gives updated balance in response.

Input:

trans_type : `credit` to indicate deposit transaction.
amount     : Amount in float

Sample Request:

curl --location --request POST "http://localhost:3000/api/v1/wallet/make" \
--header 'SESS-TOKEN: <SESS-TOKEN>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "trans_type": "credit",
    "amount": 500
}'

Sample Response:

{
    "balance": 500,
    "success": true
}

Withdraw from Wallet


Details:

Property Value
API /api/v1/wallet/make
Method POST
Authentication Required
Description This API is used for withdrawing money from user's wallet. It also gives updated balance in response.

Input:

trans_type : `debit` to indicate withdraw transaction.
amount     : Amount in float

Sample Request:

curl --location --request POST "http://localhost:3000/api/v1/wallet/make" \
--header 'SESS-TOKEN: <SESS-TOKEN>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "trans_type": "debit",
    "amount": 57
}'

Sample Response:

{
    "balance": 500,
    "success": true
}

Check Wallet Balance


Details:

Property Value
API /api/v1/wallet
Method GET
Authentication Required
Description This API is used for withdrawing money from user's wallet. It also gives updated balance in response.

Sample Request:

curl --location --request GET "http://localhost:3000/api/v1/wallet" \
--header 'SESS-TOKEN: <SESS-TOKEN>'

Sample Response:

{
    "balance": 500,
    "success": true
}

Get Wallet Statement


Details:

Property Value
API /api/v1/wallet/statement
Method GET
Authentication Required
Description This API is used for fetching complete statement of wallet transactions.

Sample Request:

curl --location --request GET "http://localhost:3000/api/v1/wallet/statement" \
--header 'SESS-TOKEN: <SESS-TOKEN>'

Sample Response:

[
    {
        "amount": 500,
        "created_at": "2021-12-18 13:38:09 +0530 IST",
        "type": "credit"
    },
    {
        "amount": 22,
        "created_at": "2021-12-18 10:53:01 +0530 IST",
        "type": "debit"
    },
    {
        "amount": 57,
        "created_at": "2021-12-18 10:52:36 +0530 IST",
        "type": "debit"
    },
    {
        "amount": 250,
        "created_at": "2021-12-18 10:52:26 +0530 IST",
        "type": "credit"
    }
]

Author

Vinay Jeurkar

   

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published