Order Creation Flow
Create Order
Submit order with product list. The system validates stock availability and calculates totals.
Pay Order
Process payment using TRX tokens (see Payment Processing).
Creating an Order
Create a new order with selected products and quantities.Endpoint
Requires authentication. Users can only have one pending order at a time.
Request Body
Request Fields
- products (array, required): List of products to order
- productId (string, required): MongoDB ObjectId of the product
- quantity (number, required): Quantity to purchase (minimum 1)
- color (string, optional): Product color variant
Response
Implementation Example
Order Calculation Logic
The order total is calculated automatically fromsrc/api/orders/createOrder.js:28:
Retrieving Orders
Get a list of all orders for the authenticated user.Endpoint
Query Parameters
- status (optional): Filter by order status (
pending,completed,refunded,failed,cancelled) - limit (optional): Number of orders per page (default: 10)
- page (optional): Page number (default: 1)
Response
Implementation Example
Get Order by ID
Retrieve details of a specific order.Endpoint
Response
Order Status Lifecycle
Orders progress through different statuses as defined insrc/models/Order.js:45:
Order Constraints
Order Model Schema
Fromsrc/models/Order.js:3, each order contains:
Next Steps
After creating an order:Payment Processing
Learn how to process TRX payments for orders
Real-time Notifications
Receive instant notifications when payments are confirmed