This is a simple illustration of a p2p network for payments users are able to carry out 2 primary functions
- Add money to their account via Paystack
- Send money to friends using thier paytags
Before we get started with setup and the nitty gritty of the app the live demo is available ππΌ here
This system was built using Node Js, TypeScript and MongoDB and is deployed on Vercel (frontend) and Render (backend)
In order to run this project you must have Node JS installed, download it here ππΌ node-js-download
To get started clone this repo to your computer
$ git clone https://github.com/Alfred-Onuada/p2p-payments-system.git
Once the repo is cloned go ahead and install the dependencies
$ npm install
You are now ready to start the server, run
$ npm run dev
There are 3 major segments of the applications API
- The Authentication / Authorization controller - to handle functions such as login / register / logout / token rotation
- The user controller - to handle retrieval of user information
- The wallet controller - to handle wallet topup and transfer of funds to other users
-
Registration
This route expects a payload of the fomat
{ "firstName": "Harley", "lastName": "Quin", "email": "quin@dc.com", "password": "joker-me", "username": "Quinny" }
and will return a response of format
{ "message": "Registration successful", "data": { "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NDdiYmQzZTQwOGJjMzhjNjYwZjgwODQiLCJpYXQiOjE2ODU4MzA5NzUsImV4cCI6MTY4NTgzMTg3NX0.FppqYvKN_LjHKjd7GKfnmLbbMJgOgs4hF-X9yH9WwME", "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NDdiYmQzZTQwOGJjMzhjNjYwZjgwODQiLCJ0b2tlbklkIjoiNjQ3YmJkM2U0MDhiYzM4YzY2MGY4MDg2IiwiaWF0IjoxNjg1ODMwOTc1LCJleHAiOjE2ODY0MzU3NzV9.VDil1gimXiY9doxZyPsWlVUoN8EJeh2JUboA70SdAdA" } }
The API uses JWT based auth, as such returns both a refresh token and an access token to the client. The access tokens has a lifespan of 15 minutes while the refresh token has a lifespan of 7 days
If there is a problem with the request a response of the following format will be returned
{ "message": "username already exists" }
Login
This route processes a login request and expects a payload like below
{ "email": "quin@dc.com", "password": "joker-me" }
and errors during login will return a response in similar format to the registration logic
Logout
This route expects no payload except a
refresh token
in the authorization header in the bearer token styleRotate tokens
This accepts a refresh token in the authorization headers, invalidates it and returns a new set of tokens to the client
-
The user controller provides one route
which returns information about the current signed-in user, in order to be classified as a signed-in user the request should contain the access token in the authorization headers.
It returns a response like below
{ "message": "Profile retrieved successfully", "data": { "_id": "647bbd3e408bc38c660f8084", "firstName": "jennifer", "lastName": "aniston", "username": "@racheal", "email": "racheal@friends.com", "walletBalance": 0 } }
-
Transfer
This accepts a couple of information in the body of the request and processes a transfer from one user to another returning errors as neccessary. e.g of the payload
{ "receiver": "@racheal", "amount": 5500, "note": "Happy Birthday" }
Topup Verification
After payment is completed via the paystack frontend client, this route handles the callback by verifying the transaction using the paystack verification endpoint ππΌ https://api.paystack.co/transaction/verify/:ref with the transaction ref sent in the request parameters. Upon successful verification the money will be added to the user's account.
Thanks for getting this far π