A set of microservices designed to implement the order and payment processing system.
These instructions will get you a working API that you can interact with.
What things you need to run the system and how to install them
- node.js
- npm (will be automatically installed with node)
- docker
- docker-compose
- insomnia
To launch the set of services, just run the following:
docker-compose up
If you want to run the services in the background then add the -d
flag
docker-compose up -d
In order to rebuild the services add the --build flag at the end
docker-compose up --build
or
docker-compose build
To access the API you can send out curl requests to http://localhost:8000/api
or better, open Insomnia Rest Client and import the collection provided insomnia_collection.json
to view the complete set of routes with sample body provided.
The overall architecture includes two node.js applications, a messaging broker, a gateway and a database service. The entire application is brought up with docker-compose as a proof of concept which can be replaced with a simple kubernetes cluster.
Here is a diagramatic overview of the system:
Authentication middleware has been placed as a dummy that always returns appends a user's details in the request object. A string/token has been hardcoded to protect all routes that needs to be passed in the request authorization header. This mocks an already signed in user behavior where a signed in session will automatically be sending a JWT token for example, in the authorization header.
To make the application work please add this hardcoded token in the request header:
Authorization: thisisajwttoken
A user is allowed to create an order, cancel an order, get a specific order or get all their orders.
- GET /api/orders - gets all the orders for the user
- POST /api/orders - creates an order against the user
- GET /api/orders/{id} - gets a specific order for the user
- DELETE /api/orders/{id} - cancels a specific order for the user
Sample body for order creation:
{
"bill": 2000
}
The provided Insomnia collection has all the routes provided with prefilled request body, headers etc.
- payment-create-event - pushed to the broker whenever an order is created so that a corresponding payment object is created
- payment-processed-event - received whenever a payment is processed. Can be a denied payment or an accepted payment. Based on the status the appropriate event handler is invoked
- Whenever an order is confirmed, a timer is added to the callback queue to process the order and change the status to delivered after a hardcoded time.
A user can get a specific payment using the order ID or can get all their payments as well as initiate a payment for a specific order.
- GET /api/payments - gets all the payments for the user
- GET /api/payments/{orderId} - gets a specific payment against an order for the user
- POST /api/payments/pay/{orderId} - initiates a payment against an order for the user.
A sample body for the last route is provided as below:
{
"creditCardDetails": {
"number": "10298310928301",
"cvt": 345,
"expiry": "4/12/2020"
}
}
The provided Insomnia collection has all the routes provided with prefilled request body, headers etc.
- payment-processed-event - pushed whenever a payment is processed. Can be a denied payment or an accepted payment.
- payment-create-event - received whenever an order is created so that a corresponding payment object is created
In order to run the unit tests, go to either of the apps folders orders-api/
or payments-api/
and run the command:
npm run test
- Express - Fast, unopinionated, minimalist web framework for Node.js
- Hassaan Pasha - website
- PurpleBooth for the awesome README template