fixes fixes fixes tenaancy
This commit is contained in:
83
PAYMENT-APPROVAL-FIXED.md
Normal file
83
PAYMENT-APPROVAL-FIXED.md
Normal file
@@ -0,0 +1,83 @@
|
||||
# PAYMENT APPROVAL - ADMIN QUICK GUIDE
|
||||
|
||||
## How It Works Now (FIXED)
|
||||
|
||||
### When User Submits Payment Confirmation:
|
||||
1. Payment record created with status: `pending_approval`
|
||||
2. Invoice status: `pending`
|
||||
3. Account status: `pending_payment`
|
||||
4. Credits: 0
|
||||
|
||||
### When You Approve Payment (AUTOMATIC CASCADE):
|
||||
|
||||
**Option 1: Change Status in Admin**
|
||||
1. Open Payment in Django Admin
|
||||
2. Change Status dropdown: `pending_approval` → `succeeded`
|
||||
3. Click Save
|
||||
4. ✅ **EVERYTHING UPDATES AUTOMATICALLY:**
|
||||
- Payment status → `succeeded`
|
||||
- Invoice status → `paid`
|
||||
- Subscription status → `active`
|
||||
- Account status → `active`
|
||||
- Credits added (e.g., 5,000 for Starter plan)
|
||||
|
||||
**Option 2: Bulk Approve**
|
||||
1. Go to Payments list in Django Admin
|
||||
2. Select payments with status `pending_approval`
|
||||
3. Actions dropdown: "Approve selected manual payments"
|
||||
4. Click Go
|
||||
5. ✅ **ALL SELECTED PAYMENTS PROCESSED AUTOMATICALLY**
|
||||
|
||||
## Simplified Payment Statuses (Only 4)
|
||||
|
||||
| Status | Meaning | What To Do |
|
||||
|--------|---------|------------|
|
||||
| `pending_approval` | User submitted payment, waiting for you | Verify & approve or reject |
|
||||
| `succeeded` | Approved & account activated | Nothing - done! |
|
||||
| `failed` | Rejected or failed | User needs to retry |
|
||||
| `refunded` | Money returned | Rare case |
|
||||
|
||||
**REMOVED unnecessary statuses:** pending, processing, completed, cancelled
|
||||
|
||||
## What Happens Automatically When Status → `succeeded`:
|
||||
|
||||
```
|
||||
Payment.save() override does this:
|
||||
├─ 1. Invoice.status = 'paid'
|
||||
├─ 2. Invoice.paid_at = now
|
||||
├─ 3. Subscription.status = 'active'
|
||||
├─ 4. Subscription.external_payment_id = manual_reference
|
||||
├─ 5. Account.status = 'active'
|
||||
└─ 6. CreditService.add_credits(plan.included_credits)
|
||||
```
|
||||
|
||||
## That's It!
|
||||
|
||||
**You only change ONE thing: Payment status to `succeeded`**
|
||||
|
||||
Everything else is automatic. No need to:
|
||||
- ❌ Manually update invoice
|
||||
- ❌ Manually update account
|
||||
- ❌ Manually add credits
|
||||
- ❌ Manually activate subscription
|
||||
|
||||
## Files Changed:
|
||||
|
||||
1. `/backend/igny8_core/business/billing/models.py`
|
||||
- Payment.STATUS_CHOICES: 8 → 4 statuses
|
||||
- Payment.save() override: auto-cascade on approval
|
||||
|
||||
2. `/backend/igny8_core/modules/billing/admin.py`
|
||||
- PaymentAdmin.save_model(): sets approved_by
|
||||
- Bulk actions work correctly
|
||||
|
||||
3. `/backend/igny8_core/business/billing/admin.py`
|
||||
- Duplicate PaymentAdmin disabled
|
||||
|
||||
## Migration:
|
||||
|
||||
Run: `python manage.py migrate`
|
||||
|
||||
This will:
|
||||
- Map old statuses (pending, processing, completed, cancelled) to new ones
|
||||
- Update database constraints
|
||||
Reference in New Issue
Block a user