# Bharat Seva V3 End-to-End Test Flow

This document provides a sequential, step-by-step test flow covering the complete lifecycle:
0. **Retrieving Supported Languages from Language Master**
1. **New Vendor Registration & Login**
2. **Completing the 6-Step Vendor Shop Onboarding Wizard**
3. **Admin Verification & Approval**
4. **New Customer Registration & Login**
5. **V3 Transactional Booking, Scheduling & QR Purchase Flow**
6. **Web Admin Language Master CRUD Module**

---

# PART 0: RETRIEVING SUPPORTED LANGUAGES FROM LANGUAGE MASTER

Before registering a vendor or customer, the front-end application can retrieve the list of active/supported languages from the Master database to populate dropdown selections.

### Step 0.1: Get Active Languages
* **Endpoint**: `GET /api/v3/languages`
* **Expected Response**: `200 OK`
```json
{
  "status": true,
  "data": [
    {
      "id": 1,
      "name": "English",
      "language_code": "en"
    },
    {
      "id": 2,
      "name": "Hindi",
      "language_code": "hi"
    },
    {
      "id": 3,
      "name": "Marathi",
      "language_code": "mr"
    }
  ]
}
```

---

# PART 1: NEW VENDOR REGISTRATION & 6-STEP SHOP ONBOARDING

### Step 1.1: Register Vendor Account
* **Endpoint**: `POST /api/v1/auth/vendor/register`
* **Payload**:
```json
{
  "name": "Rajesh Kumar",
  "phone": "9922334455",
  "email": "rajesh.kumar@example.com",
  "password": "password123",
  "confirm_password": "password123",
  "language_code": "en",
  "consent": [
    {
      "consent_type": "terms_conditions",
      "policy_version": "v1.0",
      "is_given": true
    },
    {
      "consent_type": "privacy_policy",
      "policy_version": "v1.0",
      "is_given": true
    }
  ]
}
```
* **Expected Response**: `201 Created`

### Step 1.2: Vendor Login
* **Endpoint**: `POST /api/v1/auth/login`
* **Payload**:
```json
{
  "email": "rajesh.kumar@example.com",
  "password": "password123"
}
```
* **Expected Response**: `200 OK` (Extract the `access_token` for next steps)
```json
{
  "status": true,
  "message": "Vendor login successful",
  "data": {
    "access_token": "eyJhbGciOi...",
    "token_type": "bearer"
  }
}
```

---

## 6-STEP WIZARD (Include header `Authorization: Bearer <vendor_token>` for all steps)

### Step 2.1: Register Business (Step 1)
* **Endpoint**: `POST /api/v1/vendor/business/register`
* **Payload**:
```json
{
  "business_name": "Kumar Grocery & General Store",
  "business_email": "store.kumar@example.com",
  "category_id": 1,
  "state_id": 1,
  "city_id": 2,
  "pincode": "400001",
  "address": "Shop No 12, Market Road, Bandra West, Mumbai",
  "has_physical_shop": "yes",
  "latitude": 19.076,
  "longitude": 72.877,
  "language_code": "en"
}
```
* **Expected Response**: `200 OK` (Save the returned business `id` e.g. `2`)

### Step 2.2: Business Details (Step 2)
* **Endpoint**: `POST /api/v1/vendor/business/details`
* **Payload** (Multipart form data):
  - `business_id`: 2
  - `shop_description`: "Fresh organic vegetables and daily essentials"
  - `about_business`: "Established in 2020, serving quality groceries"
  - `shop_logo`: (Image file, optional)
  - `shop_banner`: (Image file, optional)
* **Expected Response**: `200 OK`

### Step 2.3: Operating Hours (Step 3)
* **Endpoint**: `POST /api/v1/vendor/business/operating-hours`
* **Payload**:
```json
{
  "business_id": 2,
  "hours": [
    {
      "day_of_week": "Monday",
      "is_closed": false,
      "open_time": "09:00:00",
      "close_time": "21:00:00"
    },
    {
      "day_of_week": "Tuesday",
      "is_closed": false,
      "open_time": "09:00:00",
      "close_time": "21:00:00"
    }
  ]
}
```
* **Expected Response**: `200 OK`

### Step 2.4: Serviceable Regions (Step 4)
* **Endpoint**: `POST /api/v1/vendor/business/serviceable-regions`
* **Payload**:
```json
{
  "business_id": 2,
  "regions": [
    {
      "pincode": "400001",
      "area_name": "Bandra West"
    },
    {
      "pincode": "400002",
      "area_name": "Khar"
    }
  ]
}
```
* **Expected Response**: `200 OK`

### Step 2.5: Government IDs & Business Registration (Step 5)
* **Endpoint**: `POST /api/v1/vendor/business/government-id-registration`
* **Payload** (Multipart form data):
  - `business_id`: 2
  - `document_type`: "aadhaar"
  - `document_number`: "998877665544"
  - `document_file`: (File upload)
* **Expected Response**: `200 OK`

* **Endpoint**: `POST /api/v1/vendor/business/registration` (For licensing, optional step)
* **Payload** (Multipart form data):
  - `business_id`: 2
  - `registration_type`: "gst"
  - `registration_number`: "27AAAAA1111A1Z1"
  - `document_file`: (File upload)
* **Expected Response**: `200 OK`

### Step 2.6: Bank Details (Step 6 - Wizard Completion)
* **Endpoint**: `POST /api/v1/vendor/business/bank-details`
* **Payload**:
```json
{
  "business_id": 2,
  "account_holder_name": "Rajesh Kumar",
  "bank_name": "State Bank of India",
  "account_number": "123456789012",
  "ifsc_code": "SBIN0000001"
}
```
* **Expected Response**: `200 OK`

---

## ADMIN VERIFICATION & APPROVAL

### Step 3.1: Admin Approves KYC (Generates unique business code)
* **Endpoint**: `POST /api/v1/admin/vendor/verify` (or equivalent admin verification endpoint)
* **Headers**: `Authorization: Bearer <admin_token>`
* **Payload**:
```json
{
  "business_id": 2,
  "verification_mode": "online",
  "overall_status": "approved",
  "admin_id": 1,
  "remarks": "All documents verified."
}
```
* **Expected Response**: `200 OK`
At this point, a unique code (e.g. `738592`) is automatically generated and assigned to this business.

---

# PART 2: NEW CUSTOMER REGISTRATION & LOGIN

### Step 4.1: Customer Registration (Extended V3 Fields)
* **Endpoint**: `POST /api/v1/auth/customer/register`
* **Payload**:
```json
{
  "name": "Aman Verma",
  "email": "aman.verma@example.com",
  "phone": "9988776655",
  "aadhaar_number": "987654321098",
  "pin": "400001",
  "address": "Apartment 101, Sea Breeze, Bandra West, Mumbai",
  "family_members": 3,
  "reference_source": "Friend Referral",
  "language_code": "en"
}
```
* **Expected Response**: `201 Created`
```json
{
  "status": true,
  "message": "OTP sent successfully",
  "user_id": 6,
  "otp": 998877
}
```

### Step 4.2: Customer Verify OTP
* **Endpoint**: `POST /api/v1/auth/customer/verify-otp`
* **Payload**:
```json
{
  "user_id": 6,
  "otp": 998877
}
```
* **Expected Response**: `200 OK` (Extract customer's `access_token` and note `unique_code`)
```json
{
  "status": true,
  "message": "OTP verified successfully",
  "access_token": "eyJhbGciOi...",
  "user": {
    "id": 6,
    "name": "Aman Verma",
    "unique_code": "CUST-893740"
  }
}
```

---

# PART 3: V3 TRANSACTIONS & SCAN-TO-PURCHASE

### Step 5.1: Customer Scans Emblem QR Code
* **Endpoint**: `GET /api/verify-business/738592` (Verifies vendor business status)
* **Expected Response**: `200 OK` showing business is verified and active.

### Step 5.2: Customer Enters Purchase Amount (Mock Transaction logging)
* **Endpoint**: `POST /api/v3/customer/purchase`
* **Headers**: `Authorization: Bearer <customer_token>`
* **Payload**:
```json
{
  "vendor_id": 2,
  "amount": 250.00,
  "payment_method": "digital"
}
```
* **Expected Response**: `201 Created`
```json
{
  "success": true,
  "message": "Purchase transaction logged successfully.",
  "data": {
    "id": 1,
    "customer_id": 6,
    "vendor_id": 2,
    "amount": 250.00,
    "transaction_id": "TXN-E4R5T6Y7U8",
    "status": "completed"
  }
}
```

### Step 5.3: Customer Reviews the Purchase Transaction
* **Endpoint**: `POST /api/v3/customer/purchases/{purchaseId}/review`
* **Headers**: `Authorization: Bearer <customer_token>`
* **Payload**:
```json
{
  "rating": 5,
  "review": "Fast billing and cooperative staff!"
}
```
* **Expected Response**: `200 OK`

---

# PART 4: GENERATION OF REGISTRATION CONFIRMATION PDF

### Step 6.1: Export Summary PDF
* **Endpoint**: `GET /api/v3/vendor/business/2/pdf`
* **Headers**: `Authorization: Bearer <vendor_token>`
* **Expected Response**: `200 OK` binary file download (`registration_summary_738592.pdf`).

---

# PART 5: WEB ADMIN LANGUAGE MASTER CRUD MODULE

This module allows admin users to manage language options directly from the web admin portal.

### Step 7.1: Admin Panel Web Login
* **URL**: `GET /admin/login`
* **Form Action**: `POST /admin/admin-login`
* **Payload**:
  - `email`: `admin@bharatseva.com` (or whichever admin email is configured in your system)
  - `password`: `password`
* **Expected Result**: Redirects to Dashboard (`/admin/dashboard`).

### Step 7.2: Access Language Master Table
* **URL**: `GET /admin/languages`
* **Expected Result**: Renders language list page with the Yajra DataTable showing seeded languages (English, Hindi, Marathi, etc.).

### Step 7.3: Create a New Language
* **URL**: `GET /admin/languages/create` (Form page)
* **Form Action**: `POST /admin/languages`
* **Payload**:
  - `name`: `French`
  - `language_code`: `fr`
  - `is_active`: `1`
* **Expected Result**: Creates language record, redirects back to `/admin/languages` with success message "Language created successfully."

### Step 7.4: Edit/Toggle Language Status
* **URL**: `GET /admin/languages/{id}/edit` (Form page)
* **Form Action**: `POST /admin/languages/{id}`
* **Payload**:
  - `name`: `French`
  - `language_code`: `fr`
  - `is_active`: `0` (Disable language)
* **Expected Result**: Updates language record, redirects back with success message "Language updated successfully."

### Step 7.5: Delete Language Option
* **Form Action**: `POST /admin/languages/{id}/delete`
* **Expected Result**: Deletes language option from database and redirects back with success message "Language deleted successfully."
