Refactor payment flow to use database triggers (Clean Architecture)

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>
This commit is contained in:
dwindown
2025-12-23 16:59:13 +07:00
parent 9d7d76b04d
commit 01579ac299
4 changed files with 386 additions and 417 deletions

View File

@@ -27,6 +27,9 @@ verify_jwt = true
[functions.create-google-meet-event]
verify_jwt = false
[functions.handle-order-paid]
verify_jwt = false
[functions.send-consultation-reminder]
verify_jwt = false