Feature
Payment System
Payment System
Overview
The Payment System in Klinik Gunung Semeru handles all financial transactions related to medical services, screenings, and examinations. The system supports multiple payment methods, generates receipts, and maintains comprehensive transaction records.
Core Components
1. Transaction System
- Transactions Table: General transaction records (may or may not be linked to patients)
- Payments Table: Patient-specific payment records linked to medical services
- AmountServices Table: Predefined service pricing and types
2. Payment Flow
- Patient completes screening process
- Cashier processes payment at the counter
- System records transaction and updates payment status
- Generates receipt (nota) for patient
- Updates screening and patient payment status
3. Key Features
- Multiple payment methods (cash, transfer, etc.)
- Payment proof upload
- Receipt generation in PDF format
- Duplicate payment detection
- Payment history and analytics
API Endpoints
Create Payment Transaction
POST /api/screening/payment/service
Request Body:
{
"patient_id": 123,
"type": "screening",
"amount_paid": 50000,
"payment_method": "cash",
"amount_service_id": 1,
"payment_proof": "file_upload"
}
Response:
{
"success": true,
"message": "Transaksi berhasil dibuat dan pembayaran tercatat.",
"data": {
"transaction": {
"id": 456,
"uuid": "550e8400-e29b-41d4-a716-446655440000",
"type": "screening",
"amount_paid": 50000,
"payment_method": "cash"
},
"payment": {
"id": 789,
"uuid": "550e8400-e29b-41d4-a716-446655440001",
"no_transaction": "PAY-1703123456-1234",
"amount_paid": 50000,
"payment_status": true
},
"screening_updated": 101
}
}
Update Payment Transaction
POST /api/screening/payment/service/{id}
Request Body:
{
"patient_id": 123,
"type": "screening",
"amount_paid": 55000,
"payment_method": "transfer",
"payment_proof": "file_upload"
}
Get Pending Payments
GET /api/screening/payment?page=1&per_page=10&search=john
Response:
{
"data": [
{
"id": 123,
"uuid": "550e8400-e29b-41d4-a716-446655440000",
"name": "John Doe",
"email": "john@example.com",
"screenings": [
{
"id": 456,
"payment_status": "pending"
}
],
"amountServices": [
{
"id": 1,
"type": "screening",
"amount": 50000
}
],
"physicalExaminations": [
{
"id": 789,
"created_at": "2025-01-15T10:30:00Z"
}
]
}
],
"meta": {
"current_page": 1,
"per_page": 10,
"total": 1,
"last_page": 1
},
"filters": {
"search": "john",
"payment_status": "pending"
}
}
Get Payment History
GET /api/screening/payment/completed?page=1&per_page=10&search=john
Get Duplicate Payments
GET /api/screening/payment/duplicate?page=1&per_page=10&search=john
Generate Receipt (Nota)
GET /api/screening/payment/nota/{no_transaction}
Response: PDF download with filename nota_pembayaran_{no_transaction}.pdf
Delete Payment
DELETE /api/screening/payment/delete/{uuid}
Data Models
Transaction Model
Table: transactions
Fields:
uuid: Unique identifiertransaction_number: Auto-generated transaction number (TRX-{timestamp}-{random})patient_id: Optional foreign key to patients tabletype: Service type (screening, medicine, etc.)amount_paid: Payment amount (decimal 2 places)payment_method: Payment method (cash, transfer, etc.)payment_proof: File path to payment proof (optional)status: Transaction status
Payment Model
Table: payments
Fields:
uuid: Unique identifierno_transaction: Auto-generated payment number (PAY-{timestamp}-{random})patient_id: Required foreign key to patients tablecashier_id: Foreign key to cashiers tablepayment_status: Boolean payment statusamount_paid: Payment amount (decimal 2 places)payment_method: Payment methodpayment_proof: File path to payment proof (optional)service_types: JSON array of service typesamount_service_id: Foreign key to amount_services table
AmountService Model
Table: amount_services
Fields:
type: Service type identifieramount: Service price/cost
Business Logic
Payment Creation Process
- Validation: Validate all required fields and relationships
- Duplicate Check: Prevent multiple active payments for same patient
- Transaction Creation: Create transaction record first
- Payment Creation: Create payment record if patient_id provided
- AmountService Validation: Ensure valid service pricing
- Status Updates: Update screening and patient payment status
- Receipt Generation: Generate PDF receipt for patient
Payment Status Updates
When payment is completed:
screenings.payment_status→ "completed"patients.payment_status→ "paid" (if column exists)- QR code generation for patient verification
Duplicate Prevention
- System checks for existing active payments (
payment_status = true) - Prevents creation of new payments for patients with active payments
- Maintains audit trail of all payment attempts
Receipt Generation
PDF Content Includes:
- Patient information (name, ID)
- Cashier information
- Service details and pricing
- Payment method and amount
- Transaction date and number
- Clinic branding and QR code
Validation Rules
PaymentServiceRequest
Required Fields:
type: Service type (string, max 255 chars)amount_paid: Payment amount (numeric, min 0)payment_method: Payment method (string, max 100 chars)
Optional Fields:
patient_id: Patient identifier (must exist in patients table)payment_proof: File upload (jpg, jpeg, png, pdf, max 5MB)amount_service_id: Service pricing referencemedicines: Array of medicine purchases (drug_id, quantity, unit_price)
File Upload Rules:
- Allowed formats: JPG, JPEG, PNG, PDF
- Maximum file size: 5MB
- Storage location:
storage/app/public/transaction_proofs/
Payment Methods
The system supports various payment methods:
- Cash: Direct cash payment
- Transfer: Bank transfer
- Card: Credit/debit card
- Digital Wallet: E-wallets and mobile payments
- Insurance: Health insurance claims
Error Handling
Validation Errors
- Required field validation with Indonesian error messages
- File upload validation (format, size, type)
- Foreign key constraint validation
Business Logic Errors
- Duplicate payment prevention (422 error)
- Missing AmountService (422 error)
- Invalid cashier association (422 error)
- Patient not found errors
System Errors
- Database transaction failures
- File upload failures
- PDF generation errors (logged but don't block payment)
Security Considerations
- Authentication: All payment endpoints require authentication
- Authorization: Role-based access (cashier permissions)
- File Security: Payment proof files stored securely
- Audit Trail: Complete logging of all payment activities
- Data Integrity: Database transactions ensure consistency
Integration Points
Screening System
- Receives patients after physical examination completion
- Updates screening payment status
- Maintains relationship between screening and payment data
Cashier Management
- Links payments to specific cashiers
- Tracks cashier productivity and transaction volume
- Maintains accountability for financial transactions
Patient Management
- Updates patient payment status
- Maintains payment history per patient
- Generates patient-specific receipts
Reporting System
- Provides data for financial reports
- Tracks revenue by service type
- Supports payment analytics and trends
File Storage
Payment Proof Storage
- Location:
storage/app/public/transaction_proofs/ - Naming: Auto-generated filename with timestamp
- Access: Public URL accessible for verification
Receipt Storage
- Format: PDF files
- Naming:
nota_pembayaran_{transaction_number}.pdf - Generation: On-demand PDF creation
Performance Optimization
- Database Indexing: Optimized queries for payment lookups
- File Handling: Efficient file upload and storage
- PDF Generation: Memory-managed PDF creation
- Caching: Service pricing cache for faster lookups
Monitoring & Analytics
Key Metrics
- Daily transaction volume
- Revenue by payment method
- Cashier performance tracking
- Service type popularity analysis
Logging
- All payment activities logged
- Error tracking and alerting
- Performance monitoring
- Security audit logging
Future Enhancements
- Multi-currency Support: International payment handling
- Payment Gateway Integration: Online payment processing
- Partial Payments: Split payment functionality
- Refund Management: Payment reversal and refund system
- Insurance Integration: Automated insurance claim processing
- Mobile Payment: QR code and NFC payment support
- Automated Reconciliation: Bank statement integration
- Advanced Reporting: Real-time financial dashboards