Skip to main content

Overview

Allows store employees to move an order through its lifecycle stages. Each status transition is validated to ensure orders follow the correct workflow. When an order is marked as ready, a 6-digit OTP is automatically generated and sent to the customer via email and push notification.

Authentication

Requires authentication with JWT token. Only available to store_employee role.

Endpoint

PATCH /api/orders/:id/status

Path parameters

id
string
required
The unique order ID (MongoDB ObjectId)

Request body

status
string
required
The new order statusValid transitions:
  • placedaccepted
  • acceptedprocessing
  • processingready
  • readypicked_up

Response

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

Order lifecycle

Status transition rules

placed → accepted

  • Payment status must be success
  • If customer has no-show history (watch/restricted tier), isCommitmentConfirmed must be true
  • Customer receives “Order Accepted” notification

accepted → processing

  • Store starts preparing the order
  • Customer receives “Order Being Prepared” notification

processing → ready

  • Order preparation is complete
  • 6-digit OTP is generated and sent to customer
  • readyAt timestamp is set
  • readyExpiresAt is set to 20 minutes from now
  • Customer must collect order within 20 minutes or it’s marked as no-show
  • Customer receives “Order Ready for Pickup” notification with OTP

ready → picked_up

You cannot mark an order as picked_up without verifying the OTP first. Use the verify OTP endpoint to complete this transition.

Example request

curl -X PATCH https://api.campusbite.com/api/orders/65f7a8b9c1234567890abcde/status \
  -H "Authorization: Bearer STORE_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "status": "accepted"
  }'

Example response (ready status)

{
  "success": true,
  "message": "Order status updated to \"ready\".",
  "data": {
    "order": {
      "id": "65f7a8b9c1234567890abcde",
      "orderNumber": "ORD-20240318-001",
      "orderStatus": "ready",
      "paymentStatus": "success",
      "totalAmount": 249.50,
      "items": [
        {
          "menuItemId": "65f7a8b9c1234567890abcdf",
          "name": "Paneer Burger",
          "price": 120,
          "quantity": 1,
          "total": 120
        }
      ],
      "readyAt": "2024-03-18T14:45:00.000Z",
      "readyExpiresAt": "2024-03-18T15:05:00.000Z",
      "isOtpVerified": false,
      "customer": {
        "id": "65f7a8b9c1234567890abce6",
        "name": "Rahul Sharma",
        "email": "[email protected]"
      },
      "store": {
        "id": "65f7a8b9c1234567890abce2",
        "name": "Campus Cafe"
      },
      "createdAt": "2024-03-18T14:30:00.000Z",
      "updatedAt": "2024-03-18T14:45:00.000Z"
    },
    "otp": "573842"
  }
}

Error responses

OTP generation details

When transitioning to ready status:
  • 6-digit numeric OTP is generated
  • OTP expires in 10 minutes (configurable)
  • OTP is sent via:
    • Email to customer
    • Push notification to customer’s devices
  • OTP is returned in the API response for store’s reference
  • Store must verify this OTP when customer arrives
The OTP is only included in the response when the status changes to ready. It is not returned for other status transitions.

Commitment confirmation

Customers with no-show history must confirm their commitment before stores can accept orders:
  • Trust tier: good - No commitment required
  • Trust tier: watch - Commitment required if no-show count ≥ 2
  • Trust tier: restricted - Always requires commitment
If commitment is required but not confirmed, the store receives an error when trying to accept the order.

Build docs developers (and LLMs) love