Skip to main content

Overview

Creates a new order using a valid checkout token after the customer completes payment. This endpoint validates the checkout session, verifies order details haven’t changed, and creates the order in placed status with pending payment.
You must first call POST /api/orders/checkout-session to get a checkout token before creating an order.

Authentication

Requires authentication with JWT token. Available to student and faculty roles.

Endpoint

POST /api/orders

Request body

checkoutToken
string
required
The JWT token returned from the checkout session endpoint. Valid for 15 minutes.
transactionId
string
The UPI transaction ID from the payment app (8-40 alphanumeric characters). Automatically converted to uppercase.

Response

success
boolean
Indicates if the order was created successfully
message
string
Human-readable status message
data
object
The created order object

Order lifecycle

After creating an order, the typical flow is:
  1. placed (initial state) - Order created, payment pending
  2. Store verifies payment → accepted
  3. Store starts preparation → processing
  4. Store completes preparation → ready (OTP generated)
  5. Customer provides OTP → picked_up
Orders are automatically cancelled if:
  • Payment not confirmed within 8 minutes
  • Customer doesn’t show up within 20 minutes after order is ready
If you submit the same checkout token multiple times, the API returns the existing order instead of creating a duplicate.

Example request

curl -X POST https://api.campusbite.com/api/orders \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "checkoutToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "transactionId": "UPI12345678"
  }'

Example response

{
  "success": true,
  "message": "Order placed. Complete payment and let the store verify before preparation.",
  "data": {
    "id": "65f7a8b9c1234567890abcde",
    "orderNumber": "ORD-20240318-001",
    "paymentReference": "CBPAY1A2B3C4D5E",
    "totalAmount": 249.50,
    "paymentStatus": "pending",
    "orderStatus": "placed",
    "paymentMethod": "direct_store_upi",
    "transactionId": "UPI12345678",
    "items": [
      {
        "menuItemId": "65f7a8b9c1234567890abcdf",
        "name": "Paneer Burger",
        "price": 120,
        "quantity": 1,
        "total": 120
      },
      {
        "menuItemId": "65f7a8b9c1234567890abce0",
        "name": "French Fries",
        "price": 80,
        "quantity": 1,
        "total": 80
      },
      {
        "menuItemId": "65f7a8b9c1234567890abce1",
        "name": "Cold Coffee",
        "price": 49.50,
        "quantity": 1,
        "total": 49.50
      }
    ],
    "specialInstructions": "Extra cheese on the burger please",
    "isCommitmentConfirmed": false,
    "commitmentDeadlineAt": "2024-03-18T14:34:00.000Z",
    "store": {
      "id": "65f7a8b9c1234567890abce2",
      "name": "Campus Cafe",
      "location": "Building A, Ground Floor"
    },
    "createdAt": "2024-03-18T14:30:00.000Z",
    "updatedAt": "2024-03-18T14:30:00.000Z"
  }
}

Error responses

Trust tier system

CampusBite uses a trust tier system to prevent no-shows:
  • good: No recent no-shows, can order freely
  • watch: 2+ no-shows, may require commitment confirmation
  • restricted: 3+ no-shows, ordering blocked for 14 days
Users with watch or restricted status must call the confirm commitment endpoint after creating an order before the store can accept it.

Build docs developers (and LLMs) love