Critical bug fix: Consulting orders were not being processed after payment because
the function checked order_items for consulting products, but consulting orders
don't have order_items - they have consulting_slots instead.
Changes:
- Fetch consulting_slots along with order_items in the query
- Check for consulting_slots.length > 0 to detect consulting orders
- Update consulting_slots status from 'pending_payment' to 'confirmed'
- Create Google Meet events for each consulting slot
- Send consulting_scheduled notification
This fixes the issue where:
- Consulting slots stayed in 'pending_payment' status after payment
- No meet links were generated
- No access was granted
- Schedules didn't show up in admin or member dashboard
BREAKING CHANGE: Complete refactor of payment handling
New Architecture:
1. pakasir-webhook (120 lines -> was 535 lines)
- Only verifies signature and updates order status
- Removed: SMTP, email templates, notification logic
2. Database Trigger (NEW)
- Automatically fires when payment_status = 'paid'
- Calls handle-order-paid edge function
- Works for webhook AND manual admin updates
3. handle-order-paid (NEW edge function)
- Grants user access for products
- Creates Google Meet events for consulting
- Sends notifications via send-email-v2
- Triggers webhooks
Benefits:
- Single Responsibility: Each function has one clear purpose
- Trigger works for both webhook and manual admin actions
- Easier to debug and maintain
- Reusable notification system
Migration required: Run 20241223_payment_trigger.sql
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>