Files
course-plat/plans/payment-system-summary.md
2026-08-31 14:10:20 -03:00

140 lines
4.8 KiB
Markdown

# Payment Registration System - Summary
## Overview
A complete payment registration system for your course platform that allows guardians/students to register payments and enables admins to track payment status.
## What You'll Get
### 1. **Database Model**
- New [`Payment`](src/app/models/Payment.js) model with fields:
- `classId` - Reference to the class
- `userId` - Reference to the user (guardian/student)
- `amount` - Payment value
- `paymentDate` - Date and time of payment
- `paymentMethod` - Method (PIX, bank transfer, cash, etc.)
- `status` - Pending, Verified, or Rejected
- `receiptUrl` - Optional receipt image
- `notes` - Optional notes
### 2. **API Routes**
- [`/api/payments`](src/app/api/payments/route.js) - Create and list payments
- [`/api/payments/[id]`](src/app/api/payments/[id]/route.js) - Get, update, delete single payment
- [`/api/payments/class/[classId]`](src/app/api/payments/class/[classId]/route.js) - Get all payments for a class
- [`/api/payments/user/[userId]`](src/app/api/payments/user/[userId]/route.js) - Get all payments for a user
### 3. **Admin Dashboard**
- [`/admin/dashboard/payments`](src/app/(protected)/admin/dashboard/payments/page.jsx) - Main dashboard
- **Features**:
- View all payments in a table
- Filter by status (all, pending, verified, rejected)
- See payment statistics (total, verified, pending, rejected)
- Verify or reject payments
- View payment details
### 4. **Guardian/Student Interface**
- **Payment Registration**:
- Form to register payments with amount, date, method
- Optional receipt image upload
- Notes field for additional information
- **Payment History**:
- View all registered payments
- See payment status for each class
### 5. **Payment Status Indicators**
- Reusable [`PaymentStatusBadge`](src/app/(protected)/components/shared/PaymentStatusBadge.jsx) component
- Shows status: Not Paid, Pending, Paid, or Rejected
- Color-coded badges for easy identification
## How It Works
### For Guardians/Students:
1. Navigate to a class they're enrolled in or their ward is enrolled in
2. Click "Registrar Pagamento" (Register Payment)
3. Fill in payment details:
- Amount (R$)
- Payment date
- Payment method (PIX, bank transfer, cash, etc.)
- Optional: Upload receipt image
- Optional: Add notes
4. Submit the form
5. Payment status becomes "Pending" (waiting for admin verification)
### For Admins:
1. Navigate to Admin Dashboard → Payments
2. View all payments in a table
3. See payment statistics at the top
4. Filter payments by status
5. Click on a payment to see details
6. Verify or reject the payment
7. Payment status updates accordingly
## File Structure
```
src/
├── app/
│ ├── api/payments/ # API routes
│ ├── (protected)/
│ │ ├── admin/dashboard/payments/ # Admin dashboard
│ │ ├── dashboard/guardian/payments/ # Guardian interface
│ │ └── dashboard/student/payments/ # Student interface
│ └── components/shared/PaymentStatusBadge.jsx # Reusable component
├── models/Payment.js # Payment model
└── lib/utils/payments.js # Helper functions
```
## Security Features
- **Role-Based Access Control**:
- Only admins can view payment details
- Guardians can only register payments for their wards
- Students can only register payments for their enrolled classes
- **Data Validation**:
- Amount must be positive
- Payment date must be valid
- File uploads are validated
- **Data Integrity**:
- All payments are tracked with timestamps
- Payment status workflow is enforced
## Integration with Existing System
- Uses existing file upload infrastructure
- Integrates with existing User and Class models
- Follows existing API patterns
- Uses existing UI components
- Compatible with current role-based authentication
## Next Steps
1. **Review the plans**:
- [`payment-system-architecture.md`](plans/payment-system-architecture.md) - High-level architecture
- [`payment-system-implementation.md`](plans/payment-system-implementation.md) - Detailed implementation guide
2. **Implementation order**:
- Create Payment model
- Create API routes
- Create admin dashboard
- Create guardian/student interface
- Integrate with class views
- Test the complete flow
3. **Testing checklist**:
- Create payment with guardian account
- Verify payment with admin account
- Test file upload for receipts
- Verify role-based access control
- Test payment status indicators
## Questions?
The detailed implementation guide includes:
- Complete code for all components
- API route implementations
- Database schema definitions
- UI component code
- Integration points
- Testing checklist
Would you like me to proceed with implementing this system? I can start by creating the Payment model and API routes.