The order-service manages customer orders and exposes the following REST API endpoints:
- Endpoint : GET /api/carts<?cartId=CART_ID>
- Security: N/A
- Response:
- Status Code: 200
- Body:
{ "id": "cart_id", "items": [ { "code": "ISBN_1", "name": "product name", "description": "description", "price": 1.50, "quantity": 1 } ] }
Here cartId query parameter is optional. If not included this request will create a new cart. If cartId is specified then it will return the cart info for given cartId, if cartId not found then returns 404.
- Endpoint : POST /api/carts<?cartId=CART_ID>
- Security: N/A
- Request Body:
{ "code": "ISBN_1", "quantity": 1 //optional, default to 1 }
- Response:
- Status Code: 200
- Body:
{ "id": "cart_id", "items": [ { "code": "ISBN_1", "name": "product name", "description": "description", "price": 12.50, "quantity": 1 } ] }
- Endpoint : PUT /api/carts?cartId=CART_ID
- Security: N/A
- Request Body:
{ "code": "ISBN_1", "quantity": 1 }
- Response:
- Status Code: 200
- Body:
{ "id": "cart_id", "items": [ { "code": "ISBN_1", "name": "product name", "description": "description", "price": 12.50, "quantity": 1 } ] }
- Endpoint : DELETE /api/carts/items/{code}?cartId=CART_ID
- Security: N/A
- Response:
- Status Code: 200
- Body:
{ "id": "cart_id", "items": [ { "code": "ISBN_1", "name": "product name", "description": "description", "price": 1.50, "quantity": 1 } ] }
- Endpoint : DELETE /api/carts?cartId=CART_ID
- Security: N/A
- Response:
- Status Code: 200
- Endpoint : POST /api/orders
- Security: N/A
- Request Body:
{ "items": [ { "code": "ABCDEFGH", // unique "name": "Book Title", // mandatory "price": 24.50, // mandatory "quantity": 1 }, { "code": "JKLMNOP", // unique "name": "Book Title", // mandatory "price": 20.50, // mandatory "quantity": 2 } ], "customer": { "name":"customer name", // mandatory "email": "[email protected]", // mandatory "phone": "999999999" // mandatory }, "deliveryAddress": { "addressLine1": "street", // mandatory "addressLine2": "area", "city": "city", // mandatory "state": "state", // mandatory "zipCode": "zipcode", // mandatory "country": "Country" // mandatory }, "payment": { "cardNumber": "1234123412341234", // mandatory "cvv": "123", // mandatory "expiryMonth": 2, // mandatory "expiryYear": 2025 // mandatory } }
- Success Response:
- Status Code: 202
- Body:
{ "orderId":"abcd-efgh-ijkl-mnop", "status": "NEW" }
- Error Response - Bad Request
- Reasons: Missing required fields, ISBN not exists, Payment rejected.
- Status Code: 400
- Body:
{ "message": "Payment rejected" }
- Endpoint : DELETE /api/orders/{orderId}
- Security: Header
Authorization: Bearer <JWT_TOKEN>
with Role ADMIN or STAFF - Success Response:
- Status Code: 200
- Body:
{ "orderId":"abcd-efgh-ijkl-mnop", "status": "CANCELLED" }
- Error Response - Bad Request
- Reasons: Missing required fields, orderId not exists, Order already delivered.
- Status Code: 400
- Body:
{ "message": "orderId not exists" }
- Endpoint : GET /api/orders
- Security: Header
Authorization: Bearer <JWT_TOKEN>
with Role ADMIN or STAFF - Success Response:
- Status Code: 200
- Body:
{ "totalElements": 25, "totalPages": 3, "currentPage": 1, "data": [ { "orderId":"abcd-efgh-ijkl-mnop", "status": "NEW", "items": [ { "code": "ABCDEFGH", "name": "Book Title", "price": 24.50, "quantity": 1 }, { "code": "JKLMNOP", "name": "Book Title", "price": 20.50, "quantity": 2 } ], "customer": { "name":"customer name", "email": "[email protected]", "phone": "999999999" }, "deliveryAddress": { "addressLine1": "street", "addressLine2": "area", "city": "city", "state": "state", "zipCode": "zipcode", "country": "Country" } } ] }
- Endpoint : GET /api/orders/{orderId}
- Security: N/A
- Success Response:
- Status Code: 200
- Body:
{ "orderId":"abcd-efgh-ijkl-mnop", "status": "NEW", "items": [ { "code": "ABCDEFGH", "name": "Book Title", "price": 24.50, "quantity": 1 }, { "code": "JKLMNOP", "name": "Book Title", "price": 20.50, "quantity": 2 } ], "customer": { "name":"customer name", "email": "[email protected]", "phone": "999999999" }, "deliveryAddress": { "addressLine1": "street", "addressLine2": "area", "city": "city", "state": "state", "zipCode": "zipcode", "country": "Country" } }
- Error Response - Not Found
- Status Code: 404
- Body:
{ "message": "Order with id <order_id> not found" }
-
ORDER_DELIVERED event handler:
- Update order status to "DELIVERED"
-
ORDER_ERROR event handler:
- Update order status to "ERROR"
-
ORDER_CANCELLED event handler:
- Update order status to "CANCELLED"
-
ORDER_CREATED event handler:
- Send order received email notification
-
ORDER_CANCELLED event handler:
- Send order cancellation email notification
-
ORDER_DELIVERED event handler:
- Send order delivered email notification
-
ORDER_ERROR event handler:
- Send order can't be fulfilled email notification
- Order Processing Job
- When an Order is placed and Payment is Accepted then Order details will be stored in DB with status="NEW".
- This job runs at regular intervals and process every order with status="NEW"
- Each new order details will be published with OrderCreatedEvent