# 🚀 CareerGuide.pk — New Features Upgrade Guide

## ✅ 6 New Features Added

1. **Stripe Payment Integration** — Secure checkout before booking confirmation
2. **Education Level Recommendations** — Smart career suggestions based on your level + quiz
3. **Student Progress Tracking** — Mark roadmap steps as complete, see % progress
4. **Admin Analytics Charts** — Chart.js graphs: bookings, revenue, career views, registrations
5. **Career Search by Skills** — Live AJAX skill search (Python, Marketing, etc.)
6. **Email Notifications** — Auto email on booking confirmation via Laravel Mail

---

## 📦 Step 1: Install Dependencies

```bash
cd career-portal
composer require stripe/stripe-php
```

---

## ⚙️ Step 2: Configure .env

```env
# ============ STRIPE ============
STRIPE_KEY=pk_test_YOUR_PUBLISHABLE_KEY_HERE
STRIPE_SECRET=sk_test_YOUR_SECRET_KEY_HERE
STRIPE_WEBHOOK_SECRET=whsec_YOUR_WEBHOOK_SECRET   # Optional

# ============ MAIL (Mailtrap for testing) ============
MAIL_MAILER=smtp
MAIL_HOST=sandbox.smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your_mailtrap_username
MAIL_PASSWORD=your_mailtrap_password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="noreply@careerguide.pk"
MAIL_FROM_NAME="CareerGuide.pk"

# For Gmail (alternative):
# MAIL_HOST=smtp.gmail.com
# MAIL_PORT=587
# MAIL_USERNAME=your@gmail.com
# MAIL_PASSWORD=your_16char_app_password
# MAIL_ENCRYPTION=tls
```

### Getting Stripe Keys:
1. Go to https://dashboard.stripe.com → Register free
2. Go to Developers → API Keys
3. Copy **Publishable key** → `STRIPE_KEY`
4. Copy **Secret key** → `STRIPE_SECRET`
5. For testing, use test keys (start with `pk_test_` and `sk_test_`)

### Getting Mailtrap Credentials:
1. Go to https://mailtrap.io → Register free
2. Go to Email Testing → Inboxes → SMTP Settings
3. Copy Username & Password

---

## 🗄️ Step 3: Run Migrations

```bash
php artisan migrate
```

This creates 3 new tables:
- `career_roadmap_steps` — Roadmap steps per career
- `student_progress` — Student step completion tracking
- `student_followed_careers` — Which careers a student follows

Also adds 3 columns to `bookings`:
- `stripe_session_id`
- `stripe_payment_intent`
- `payment_status` (unpaid/paid/refunded)

---

## 🌱 Step 4: Seed Roadmap Steps (Optional)

```bash
php artisan db:seed --class=RoadmapStepsSeeder
```

This seeds example roadmap steps for Software Engineer, Doctor, and Lawyer careers.

---

## 🔧 Step 5: Add Stripe Webhook Exception (CSRF)

The `routes/web.php` already has:
```php
Route::post('/stripe/webhook', [PaymentController::class, 'webhook'])->name('stripe.webhook');
```

In `app/Http/Middleware/VerifyCsrfToken.php`, add:
```php
protected $except = [
    'stripe/webhook',
];
```

---

## 📁 New Files Added

### Controllers:
- `app/Http/Controllers/Student/PaymentController.php` — Stripe checkout + webhook
- `app/Http/Controllers/Student/ProgressController.php` — Career progress tracking

### Models:
- `app/Models/CareerRoadmapStep.php`
- `app/Models/StudentProgress.php`

### Mail:
- `app/Mail/BookingConfirmed.php`

### Views:
- `resources/views/emails/booking_confirmed.blade.php`
- `resources/views/student/dashboard/index.blade.php` (updated)
- `resources/views/student/bookings/confirm.blade.php` (updated with Stripe)
- `resources/views/student/careers/index.blade.php` (updated with skill search)
- `resources/views/student/careers/roadmap.blade.php` (updated with progress)
- `resources/views/student/progress/index.blade.php` (new)
- `resources/views/admin/dashboard/index.blade.php` (updated with charts)
- `resources/views/admin/careers/index.blade.php` (updated)
- `resources/views/admin/careers/steps.blade.php` (new)

### Migrations:
- `2024_06_01_000001_add_stripe_to_bookings.php`
- `2024_06_01_000002_create_career_progress_table.php`

---

## 🎯 How Each Feature Works

### 1. Stripe Payment Flow:
1. Student books a counselor → redirected to `/dashboard/booking/{id}/confirm`
2. Clicks "Pay Rs. X" → Stripe Checkout page opens
3. After payment → redirected back → booking status = `confirmed`
4. Confirmation email sent automatically

### 2. Personalized Recommendations:
- `matric` students → Only `easy` difficulty careers shown
- `fsc/inter` → `easy` + `moderate` careers
- `graduate/postgraduate` → All difficulties
- Quiz scores are layered on top to reorder by matching category

### 3. Progress Tracking:
- Admin adds roadmap steps via `/admin/careers/{id}/steps`
- Student clicks "Follow Roadmap" on any career
- Student checks off each step (AJAX, no page reload)
- Dashboard shows % progress per career

### 4. Admin Analytics:
- Admin dashboard `/admin/` now has 4 Chart.js charts
- Monthly bookings bar chart
- Revenue line chart  
- Top career fields horizontal bar chart
- Student registration growth area chart
- Booking status donut chart

### 5. Skill Search:
- On `/careers`, type any skill in the search box
- AJAX live results appear as dropdown
- Also works with regular form filter search
- Popular skill tags for quick search

### 6. Email Notifications:
- Triggered when: admin manually confirms booking OR Stripe payment succeeds
- Email includes all session details
- Uses Mailtrap for safe testing

---

## 🛡️ CSRF Webhook Fix

```php
// app/Http/Middleware/VerifyCsrfToken.php
protected $except = [
    'stripe/webhook',
];
```

---

## ✅ Testing Stripe (Test Mode)

Use these test card numbers:
- **Visa:** `4242 4242 4242 4242`
- **Expiry:** Any future date (e.g. `12/28`)
- **CVC:** Any 3 digits (e.g. `123`)
- **Zip:** Any 5 digits (e.g. `12345`)

---

## 📞 Support

For issues, check:
1. `storage/logs/laravel.log` for errors
2. Stripe Dashboard → Events for payment logs
3. Mailtrap inbox for test emails
