Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Restaurant Onboarding API - Important Validation Rules

⚠️ Critical Validation Rules (Updated Documentation)

This document summarizes the key validation rules that developers must follow to avoid common errors when using the Restaura## 6. 🔍 Quick Reference Checklist

Before submitting your API request, verify:

  • booking_flow is either "date_first" or "package_first"
  • allow_order_now is set to false (unless delivery inventory is configured)
  • support_order_now is set to false (unless delivery inventory is configured)
  • order_now_attributes section is omitted (unless delivery inventory is configured)
  • EITHER allow_booking_without_package: false OR accept_subsidize_voucher: false (cannot both be true)
  • Owner email is unique (not already in database)
  • All required fields are present: name_en, city_id, address_en, phone, start_date
  • Tag IDs exist in restaurant_tags table (if using tags)
  • Date format is YYYY-MM-DD
  • HMAC authentication is properly configured


1. 🔄 Booking Flow - Valid Values Only

Valid Values

  • "date_first" - Customer selects date first (recommended default)
  • "package_first" - Customer selects package first

Common Error

{
  "success": false,
  "message": "Validation failed: Booking flow is not included in the list",
  "errors": ["Validation failed: Booking flow is not included in the list"]
}

Solution

{
  "restaurant": {
    "booking_flow": "date_first"  // ✅ Use only these two values
  }
}

Code Reference

# app/models/restaurant.rb:254
enumerize :booking_flow, in: %i[date_first package_first], default: :date_first

2. 🚚 Order Now Features - Requires Delivery Inventory

Validation Rule

Cannot enable allow_order_now or support_order_now without delivery inventory configured.

Common Error

{
  "success": false,
  "message": "Failed to create restaurant: Validation failed: Please setup delivery inventory to activate order now",
  "errors": ["Validation failed: Please setup delivery inventory to activate order now"]
}

Solution for Initial Restaurant Creation

{
  "restaurant": {
    "allow_order_now": false,        // ✅ Set to false initially
    "support_order_now": false,      // ✅ Set to false initially
    "activate_auto_call_driver": false,
    
    // ❌ OMIT this section entirely for initial creation
    // "order_now_attributes": {
    //   "call_driver_before_food_ready": 10,
    //   "cooking_time": 25
    // }
  }
}

Workflow

  1. ✅ Create restaurant with allow_order_now: false and support_order_now: false
  2. ✅ Configure delivery inventory separately
  3. ✅ Update restaurant to enable order now features later

3. 📧 Owner Email - Must Be Unique

Common Error

{
  "success": false,
  "message": "Failed to create restaurant: Validation failed: Email has already been taken",
  "errors": ["Validation failed: Email has already been taken"]
}

Solution

{
  "restaurant": {
    "owner": {
      "owner_name": "Restaurant Owner",
      "email": "unique.owner@example.com",  // ✅ Must be unique in database
      "phone": "+66812345678",
      "password": "SecurePassword123!"
    }
  }
}

Verify Email Availability

SELECT email FROM owners WHERE email = 'your-email@example.com';

4. 🎫 Voucher & Booking Package - Cannot Mix

Business Rule

Cannot enable allow_booking_without_package: true and accept_subsidize_voucher: true at the same time.

Common Error

{
  "success": false,
  "message": "Failed to create restaurant: Validation failed: Can't mix \"accept booking without package\" and \"accept restaurant-subsidize voucher\" at the same time",
  "errors": ["Validation failed: Can't mix \"accept booking without package\" and \"accept restaurant-subsidize voucher\" at the same time"]
}

Solutions

{
  "restaurant": {
    "allow_booking_without_package": true,
    "voucher_setting_attributes": {
      "accept_subsidize_voucher": false  // ✅ Must be false
    }
  }
}

Option 2: Accept Subsidized Vouchers

{
  "restaurant": {
    "allow_booking_without_package": false,  // ✅ Must be false
    "voucher_setting_attributes": {
      "accept_subsidize_voucher": true
    }
  }
}

Business Logic

  • Booking Without Package: Customers can make reservations without selecting a specific package/offer
  • Subsidized Vouchers: Restaurant accepts vouchers that are subsidized by the restaurant itself
  • Conflict: These two features are mutually exclusive in the business model

5. 📝 Complete Working Example

Minimal Valid Payload (SAFE)

{
  "restaurant": {
    "name_en": "Test Restaurant",
    "city_id": 1,
    "address_en": "123 Test Street, Bangkok",
    "phone": "+66812345678",
    "start_date": "2024-01-01",
    "booking_flow": "date_first",
    "allow_order_now": false,
    "support_order_now": false,
    
    "owner": {
      "owner_name": "Restaurant Owner",
      "email": "unique.owner@example.com",
      "phone": "+66812345678",
      "password": "SecurePassword123!"
    }
  }
}

See POSTMAN_PAYLOAD_NEW_RESTAURANT.json for a complete example with:

  • ✅ 60+ restaurant attributes
  • ✅ Bilingual content (EN/TH)
  • ✅ Nested associations (owner, managers, google_review, etc.)
  • ✅ Tag assignments
  • ✅ Valid booking_flow
  • ✅ Order now features disabled
  • ✅ Unique email addresses

5. � Complete Working Example

Minimal Valid Payload (SAFE)

{
  "restaurant": {
    "name_en": "Test Restaurant",
    "city_id": 1,
    "address_en": "123 Test Street, Bangkok",
    "phone": "+66812345678",
    "start_date": "2024-01-01",
    "booking_flow": "date_first",
    "allow_order_now": false,
    "support_order_now": false,
    "allow_booking_without_package": false,
    
    "owner": {
      "owner_name": "Restaurant Owner",
      "email": "unique.owner@example.com",
      "phone": "+66812345678",
      "password": "SecurePassword123!"
    },
    
    "voucher_setting_attributes": {
      "accept_subsidize_voucher": false
    }
  }
}

See POSTMAN_PAYLOAD_NEW_RESTAURANT.json for a complete example with:

  • ✅ 60+ restaurant attributes
  • ✅ Bilingual content (EN/TH)
  • ✅ Nested associations (owner, managers, google_review, etc.)
  • ✅ Tag assignments
  • ✅ Valid booking_flow
  • ✅ Order now features disabled
  • ✅ Valid voucher/booking package configuration
  • ✅ Unique email addresses

6. �🔍 Quick Reference Checklist

Before submitting your API request, verify:

  • booking_flow is either "date_first" or "package_first"
  • allow_order_now is set to false (unless delivery inventory is configured)
  • support_order_now is set to false (unless delivery inventory is configured)
  • order_now_attributes section is omitted (unless delivery inventory is configured)
  • Owner email is unique (not already in database)
  • All required fields are present: name_en, city_id, address_en, phone, start_date
  • Tag IDs exist in restaurant_tags table (if using tags)
  • Date format is YYYY-MM-DD
  • HMAC authentication is properly configured

  • Full API Documentation: RESTAURANT_ONBOARDING_API.md
  • Working Payload Example: POSTMAN_PAYLOAD_NEW_RESTAURANT.json
  • Original Payload Example: POSTMAN_PAYLOAD_COMPLETE.json
  • Controller Updates Summary: API_CONTROLLER_UPDATES.md

7. 🆘 Getting Help

If you encounter validation errors:

  1. Check this document for common validation rules

  2. Review the error message - it usually indicates the specific issue

  3. Consult RESTAURANT_ONBOARDING_API.md for detailed field documentation

  4. Use the working examples in POSTMAN_PAYLOAD_NEW_RESTAURANT.json

  5. Run the RSpec tests to validate your changes:

    bundle exec rspec spec/controllers/api/admin/concerns/authentication_spec.rb
    bundle exec rspec spec/requests/api/admin/restaurants_controller_spec.rb
    bundle exec rspec spec/services/restaurant_service/create_from_api_spec.rb
    

Last Updated: October 9, 2025
Status: ✅ All 35 RSpec tests passing
Branch: feat/api-restaurant-onboarding