POST /api/orders/checkout-session
Creates a checkout session that validates the cart, calculates totals, and returns a checkout token. This token must be used within 15 minutes to create the actual order.
Authentication
Requires a valid JWT access token in the Authorization header.
Allowed roles: student, faculty
Request body
The ID of the store from which items are being ordered
Array of cart items with menu item IDs and quantities Quantity to order (must be >= 1)
Optional special instructions for the order (max 500 characters)
Response
Indicates if the request was successful
JWT token to use for order creation (valid for 15 minutes)
Unique payment reference for this order (format: CBPAY + 10 hex chars)
Order preview with calculated totals Normalized cart items with menu item details
Final total amount to pay
UPI payment deep links for various apps
ISO 8601 timestamp when the checkout token expires
Whether the user needs to confirm commitment before placing order (users with no-show history)
Example request
curl -X POST https://api.campusbite.com/api/orders/checkout-session \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"storeId": "507f1f77bcf86cd799439011",
"items": [
{
"menuItemId": "507f191e810c19729de860ea",
"quantity": 2
},
{
"menuItemId": "507f191e810c19729de860eb",
"quantity": 1
}
],
"specialInstructions": "Extra spicy please"
}'
Example response
{
"success" : true ,
"checkoutToken" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." ,
"paymentReference" : "CBPAYF3A2C1B4D5" ,
"preview" : {
"items" : [
{
"menuItemId" : "507f191e810c19729de860ea" ,
"name" : "Chicken Burger" ,
"price" : 150 ,
"quantity" : 2 ,
"subtotal" : 300
},
{
"menuItemId" : "507f191e810c19729de860eb" ,
"name" : "French Fries" ,
"price" : 80 ,
"quantity" : 1 ,
"subtotal" : 80
}
],
"subtotal" : 380 ,
"totalAmount" : 380 ,
"itemCount" : 3
},
"upiLinks" : {
"gpay" : "gpay://upi/pay?pa=store@upi&pn=Campus%20Canteen&am=380&cu=INR&tn=CBPAYF3A2C1B4D5" ,
"phonepe" : "phonepe://pay?pa=store@upi&pn=Campus%20Canteen&am=380&cu=INR&tn=CBPAYF3A2C1B4D5" ,
"paytm" : "paytmmp://pay?pa=store@upi&pn=Campus%20Canteen&am=380&cu=INR&tn=CBPAYF3A2C1B4D5" ,
"bhim" : "bhim://pay?pa=store@upi&pn=Campus%20Canteen&am=380&cu=INR&tn=CBPAYF3A2C1B4D5" ,
"generic" : "upi://pay?pa=store@upi&pn=Campus%20Canteen&am=380&cu=INR&tn=CBPAYF3A2C1B4D5"
},
"expiresAt" : "2024-01-15T10:30:00.000Z" ,
"requiresCommitment" : false
}
{
"success" : false ,
"message" : "Ordering is temporarily restricted due to repeated no-shows until 1/25/2024, 10:30:00 AM."
}
{
"success" : false ,
"message" : "One or more menu items are unavailable or not found."
}
Workflow
User adds items to cart on frontend
Frontend calls checkout-session endpoint with cart items
Backend validates items, calculates totals, generates payment reference
Backend returns checkout token (valid 15 min) and UPI payment links
User completes UPI payment using the payment reference
User calls create order endpoint with checkout token
The checkout token expires after 15 minutes. If the token expires, the user must create a new checkout session.
Users with repeated no-shows may be temporarily restricted from ordering. The requiresCommitment flag indicates if the user must explicitly confirm their commitment before placing the order.