feat: replace Stripe Global Payouts with manual bank transfer system for France compliance

- Replace Stripe automatic payouts with manual admin-processed bank transfers
- Add banking information fields (IBAN, bank name, account holder) to User model
- Implement manual payout workflow: pending → approved → processing → completed
- Add comprehensive admin interface for payout review and processing
- Update Payout model with manual processing fields and workflow methods
- Add transfer reference tracking and rejection/failure handling
- Consolidate all migration fragments into clean "create" migrations
- Add comprehensive documentation for manual payout workflow
- Fix Event payout_status enum definition and database column issues

This addresses France's lack of Stripe Global Payouts support by implementing
a complete manual bank transfer workflow while maintaining audit trails and
proper admin controls.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
kbe
2025-09-17 11:55:07 +02:00
parent 3c1e17c2af
commit 1889ee7fb2
20 changed files with 838 additions and 141 deletions

View File

@@ -0,0 +1,157 @@
# Manual Payout Workflow
## Overview
This document describes the manual payout system implemented to replace Stripe Global Payouts, which is not available in France. The system allows promoters to request payouts for their events, and administrators to process these requests manually through bank transfers.
## Workflow Steps
### 1. Promoter Requests Payout
- Promoters can request payouts for ended events through the existing interface
- The system validates that banking information is complete before allowing requests
- Payout status is set to `pending`
### 2. Admin Review (Pending → Approved/Rejected)
**Admin Actions Available:**
- **Approve**: If all information is correct and banking details are valid
- **Reject**: If there are issues (missing info, invalid details, policy violations)
**What Admins Check:**
- Banking information completeness (IBAN, bank name, account holder)
- Event validity and earnings calculation
- Promoter eligibility
### 3. Manual Bank Transfer (Approved → Processing)
**Admin Actions:**
- **Mark as Processing**: When bank transfer is initiated
- Optional: Add transfer reference number
- Admin manually processes SEPA transfer through their banking system
### 4. Transfer Completion (Processing → Completed/Failed)
**Admin Actions:**
- **Mark as Completed**: When transfer is confirmed successful
- **Mark as Failed**: If transfer fails or is rejected by bank
- Update transfer reference if needed
## Banking Information Requirements
### For Promoters
Users must provide:
- **IBAN**: Valid IBAN format (validated by regex)
- **Bank Name**: Name of the banking institution
- **Account Holder Name**: Full name matching bank account
### IBAN Validation
- Basic format validation implemented
- Supports standard European IBAN format
- Regex: `/\A[A-Z]{2}[0-9]{2}[A-Z0-9]{4}[0-9]{7}([A-Z0-9]?){0,16}\z/`
## Database Schema Changes
### New User Fields
```ruby
add_column :users, :iban, :string
add_column :users, :bank_name, :string
add_column :users, :account_holder_name, :string
```
### New Payout Fields
```ruby
add_reference :payouts, :processed_by, foreign_key: { to_table: :users }
add_column :payouts, :processed_at, :datetime
add_column :payouts, :rejection_reason, :text
add_column :payouts, :bank_transfer_reference, :string
```
### Updated Payout Statuses
```ruby
enum :status, {
pending: 0, # Payout requested but not reviewed
approved: 1, # Payout approved by admin, ready for transfer
processing: 2, # Payout being processed (bank transfer initiated)
completed: 3, # Payout successfully completed
failed: 4, # Payout failed
rejected: 5 # Payout rejected by admin
}
```
## Admin Interface
### Dashboard Sections
1. **Pending Review**: New requests requiring admin approval/rejection
2. **Approved**: Ready for manual bank transfer
3. **Processing**: Transfers in progress
4. **Recently Completed**: Completed transfers for reference
### Transfer Information Display
- Promoter banking details
- Transfer amount and reference
- Event information
- Validation warnings for incomplete banking info
## Security & Audit
### Audit Trail
- All status changes tracked with timestamp
- Admin user recorded for each action
- Transfer references stored for bank reconciliation
### Validation
- Banking information validated before approval
- IBAN format checking
- Complete information required before processing
## Migration from Stripe
### Immediate Changes
- ✅ Stripe Transfer functionality disabled
- ✅ Manual workflow implemented
- ✅ Banking information collection added
- ✅ Admin interface updated
### Legacy Support
- Original `PayoutService#process!` method redirects to manual workflow
- Existing payout request flow preserved for promoters
- Database backward compatible
## Usage Instructions
### For Administrators
1. Access admin payout dashboard at `/admin/payouts`
2. Review pending payouts for approval
3. For approved payouts, initiate bank transfers manually
4. Update payout status as transfers progress
5. Mark as completed when transfer is confirmed
### For Promoters
1. Ensure banking information is complete in profile
2. Request payouts for ended events as before
3. Monitor payout status through existing interface
4. Banking information must be valid IBAN format
## Error Handling
### Common Issues
- **Incomplete Banking Info**: Prevents approval until resolved
- **Invalid IBAN**: Validation error displayed to admin
- **Transfer Failures**: Can be marked as failed with reason
### Recovery
- Failed payouts can be retried after fixing issues
- Rejected payouts require new requests
- Banking information can be updated by promoters
## Future Enhancements
### Potential Improvements
1. Integration with banking APIs for automated transfers
2. Enhanced IBAN validation with checksum verification
3. Email notifications for status changes
4. Bulk transfer processing
5. Advanced reporting and reconciliation tools
### France-Specific Considerations
1. SEPA transfer compliance
2. Tax reporting requirements
3. AML/KYC documentation
4. Banking regulation compliance

View File

@@ -0,0 +1,112 @@
# Payout System Analysis Report
## Current Implementation Overview
The current payout system implemented on the `feat/stripe-global-payouts` branch uses **Stripe Connect** with **Stripe Transfers** to automatically process payouts to promoters. This implementation is **not compatible with France** as it relies on Stripe Global Payouts functionality.
## Architecture Analysis
### Core Components
1. **Models**
- `Payout`: Tracks payout requests with statuses (pending, processing, completed, failed)
- `User`: Contains `stripe_connected_account_id` for Stripe Connect integration
- `Event`: Has payout eligibility and earnings calculation methods
- `Earning`: Tracks individual order earnings (referenced in docs but may not be fully implemented)
2. **Services**
- `PayoutService` (`app/services/payout_service.rb:13-19`): Processes payouts via `Stripe::Transfer.create`
- `StripeConnectService`: Manages Stripe Connect account setup
3. **Controllers**
- `Promoter::PayoutsController`: Handles promoter payout requests and viewing
- `Admin::PayoutsController`: Handles admin payout processing
### Current Payout Flow
1. **Promoter Request**: Promoter requests payout for ended event via `Promoter::PayoutsController#create`
2. **Admin Processing**: Admin processes payout via `Admin::PayoutsController#process`
3. **Stripe Transfer**: `PayoutService` creates `Stripe::Transfer` to promoter's connected account
4. **Status Update**: Payout status updated to completed/failed based on Stripe response
### Key Issues for France
1. **Stripe Global Payouts Dependency**: The system uses `Stripe::Transfer.create` with `destination: stripe_connected_account_id` which requires Stripe Global Payouts
2. **Stripe Connect Requirement**: Users must have verified Stripe Connect accounts (`stripe_connected_account_id`)
3. **Automatic Processing**: System assumes automated Stripe processing capability
## Database Schema
### Payouts Table
- `amount_cents`: Gross payout amount
- `fee_cents`: Platform fees
- `status`: Enum (pending, processing, completed, failed)
- `stripe_payout_id`: Stripe transfer ID
- `total_orders_count`: Number of orders included
- `refunded_orders_count`: Number of refunded orders
- `user_id`: Promoter receiving payout
- `event_id`: Event for which payout is requested
### Users Table (Relevant Fields)
- `stripe_connected_account_id`: Stripe Connect account ID
- `is_professionnal`: Required for event management
## Compliance and Legal Considerations
### France-Specific Issues
1. **Stripe Global Payouts**: Not available in France as of current analysis
2. **Banking Regulations**: May require different approach for cross-border transfers
3. **Tax Reporting**: Manual payouts may require additional documentation
### Alternative Approaches Needed
1. **Manual Bank Transfers**: Admin-initiated SEPA transfers
2. **Payout Request System**: Promoters request, admins approve and process manually
3. **Documentation**: Enhanced record-keeping for manual transfers
## Recommendations
### Immediate Actions Required
1. **Disable Automatic Processing**: Remove Stripe Transfer functionality
2. **Implement Manual Workflow**: Create admin interface for manual payout processing
3. **Add Banking Information**: Collect IBAN/SWIFT details from promoters
4. **Update Status Flow**: Modify payout statuses for manual processing
### Proposed Manual Payout System
1. **Request Phase**: Promoters submit payout requests (existing functionality can be kept)
2. **Review Phase**: Admins review and approve requests
3. **Processing Phase**: Admins mark as "processing" and initiate bank transfer
4. **Completion Phase**: Admins confirm transfer completion manually
## Migration Strategy
### Phase 1: Immediate Fix
- Disable automatic Stripe processing
- Add manual processing interface for admins
- Update payout status workflow
### Phase 2: Enhanced Manual System
- Add banking information collection
- Implement approval workflow
- Add transfer documentation features
### Phase 3: Potential Automation
- Investigate France-compatible payment providers
- Implement API-based bank transfers if available
- Maintain manual fallback option
## Technical Debt
### Files Requiring Updates
- `app/services/payout_service.rb`: Remove Stripe Transfer logic
- `app/controllers/admin/payouts_controller.rb`: Add manual processing actions
- `app/models/user.rb`: Add banking information fields
- Database migrations: Add IBAN/banking fields to users table
### Testing Impact
- Update `test/services/payout_service_test.rb`
- Modify controller tests for manual workflow
- Add integration tests for manual payout flow
## Conclusion
The current Stripe Global Payouts implementation is not viable for France operations. A manual payout system must be implemented immediately to handle promoter payments through traditional banking methods while maintaining audit trails and proper documentation.