# 🎥 ZOOM INTEGRATION - COMPLETE SETUP GUIDE

## 📍 WHERE TO IMPLEMENT ZOOM API

Follow these steps **IN ORDER** to get Zoom integration working:

---

## STEP 1: GET ZOOM API CREDENTIALS

### Go to Zoom Marketplace
1. Visit: https://marketplace.zoom.us/
2. Click **"Sign In"** (use your Zoom account)
3. Click **"Develop"** → **"Build App"**

### Create Server-to-Server OAuth App (Recommended)
1. Choose **"Server-to-Server OAuth"**
2. Enter App Name: `Amanfo Online Classroom`
3. Click **"Create"**
4. You'll get:
   - **Account ID**
   - **Client ID** (This is your API Key)
   - **Client Secret** (This is your API Secret)

### OR Create JWT App (Legacy)
1. Choose **"JWT"**
2. Enter App Name: `Amanfo Online Classroom`
3. Click **"Create"**
4. You'll get:
   - **API Key**
   - **API Secret**

### Add Scopes (Permissions)
Go to **"Scopes"** tab and add:
- `meeting:write:admin` - Create meetings
- `meeting:read:admin` - Read meeting details
- `meeting:delete:admin` - Delete meetings

Click **"Continue"** and **"Activate"** your app.

---

## STEP 2: ADD CREDENTIALS TO .env FILE

**Location:** `/Applications/XAMPP/xamppfiles/htdocs/quiz/.env`

**Add these lines at the bottom:**

```env
# Zoom API Configuration
ZOOM_API_KEY=your_client_id_here
ZOOM_API_SECRET=your_client_secret_here
```

**Replace:**
- `your_client_id_here` with your actual Client ID
- `your_client_secret_here` with your actual Client Secret

**Example:**
```env
ZOOM_API_KEY=AbCdEf123456789
ZOOM_API_SECRET=XyZ987654321aBcDeF
```

---

## STEP 3: INSTALL REQUIRED PACKAGES

Open terminal in your project folder and run:

```bash
composer require guzzlehttp/guzzle
composer require firebase/php-jwt
```

---

## STEP 4: RUN DATABASE MIGRATION

```bash
php artisan migrate
```

This creates the `zoom_meetings` table in your database.

---

## STEP 5: ACCESS THE ZOOM MEETING PAGE

### URL to Create Meetings:
```
http://127.0.0.1:8000/zoom/meetings/create
```

**Note:** You must be logged in to access this page.

---

## 📱 HOW TO USE THE ZOOM INTEGRATION

### Creating a Meeting:

1. **Login** to your account
2. Go to: `http://127.0.0.1:8000/zoom/meetings/create`
3. Fill in the form:
   - **Select Quiz**: Choose which quiz this meeting is for
   - **Meeting Topic**: e.g., "Year 1 Mathematics Quiz Discussion"
   - **Agenda**: What will be covered in the meeting
   - **Start Date & Time**: When the meeting starts
   - **Duration**: How long (15-480 minutes)
   - **Timezone**: Select your timezone (default: Africa/Accra)
4. Click **"Create Zoom Meeting"**
5. You'll get:
   - Meeting ID
   - Join URL (share this with students)
   - Password
   - Start URL (for host)

### Sharing Meeting Link with Students:

**Option 1: Copy the Join URL**
- Click "Copy Link" button
- Share via WhatsApp, Email, or SMS

**Option 2: Display on Quiz Page**
- The meeting link will automatically show on the quiz page
- Students can click to join

---

## 🔧 TROUBLESHOOTING

### Error: "Failed to create Zoom meeting"

**Check:**
1. ✅ API Key and Secret are correct in `.env`
2. ✅ Zoom app is activated in marketplace
3. ✅ Required scopes are added
4. ✅ Packages are installed (`guzzlehttp/guzzle`, `firebase/php-jwt`)

**Fix:**
```bash
# Clear config cache
php artisan config:clear

# Restart server
php artisan serve
```

### Error: "Quiz not found"

**Fix:**
- Make sure you're logged in
- Create at least one quiz first
- You can only create meetings for YOUR quizzes

### Error: "Unauthorized"

**Fix:**
- Check if your Zoom app is activated
- Verify API credentials are correct
- Make sure scopes are added

---

## 📊 DATABASE STRUCTURE

The `zoom_meetings` table stores:
- `quiz_id` - Which quiz the meeting is for
- `meeting_id` - Zoom's meeting ID
- `topic` - Meeting title
- `start_time` - When it starts
- `duration` - How long (minutes)
- `join_url` - Link for participants
- `start_url` - Link for host
- `password` - Meeting password

---

## 🎯 NEXT STEPS

### 1. Add Meeting Link to Quiz Page

Edit: `resources/views/quiz_player/question_answer.blade.php`

Add this code:

```blade
@if($quiz->zoomMeetings->count() > 0)
    <div style="background: #e8f5e9; padding: 20px; border-radius: 10px; margin-bottom: 20px;">
        <h3 style="color: #006400;">📹 Upcoming Zoom Session</h3>
        @foreach($quiz->zoomMeetings as $meeting)
            <p><strong>Topic:</strong> {{ $meeting->topic }}</p>
            <p><strong>Time:</strong> {{ $meeting->start_time->format('M d, Y - h:i A') }}</p>
            <a href="{{ $meeting->join_url }}" target="_blank" 
               style="background: #006400; color: #FFD700; padding: 10px 20px; border-radius: 25px; text-decoration: none; display: inline-block; margin-top: 10px;">
                Join Zoom Meeting
            </a>
        @endforeach
    </div>
@endif
```

### 2. Add Relationship to Quiz Model

Edit: `app/Models/Quiz.php`

Add this method:

```php
public function zoomMeetings()
{
    return $this->hasMany(ZoomMeeting::class);
}
```

### 3. Send Email Notifications

Create a notification to send meeting links to participants automatically.

---

## 📞 SUPPORT

### Zoom API Documentation
https://marketplace.zoom.us/docs/api-reference/zoom-api

### Check Logs
If something goes wrong, check:
```
storage/logs/laravel.log
```

---

## ✅ CHECKLIST

Before going live, make sure:

- [ ] Zoom API credentials are in `.env`
- [ ] Packages installed (`composer require`)
- [ ] Database migrated (`php artisan migrate`)
- [ ] Can access `/zoom/meetings/create` page
- [ ] Successfully created a test meeting
- [ ] Meeting link works when clicked
- [ ] Added meeting display to quiz pages

---

## 🎉 YOU'RE DONE!

Your Zoom integration is now ready. Teachers can create meetings for their quizzes and students can join directly from the quiz page.

**Test URL:** http://127.0.0.1:8000/zoom/meetings/create
