Files
aperonight/app/models/user.rb
kbe 1889ee7fb2 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>
2025-09-17 11:55:07 +02:00

99 lines
3.2 KiB
Ruby
Executable File

# User model for authentication and user management
# Handles user accounts, authentication, and authorization using Devise
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
#
# Include default devise modules for authentication
# :database_authenticatable - encrypts and stores password in database
# :registerable - allows users to sign up and edit their accounts
# :recoverable - handles password reset functionality
# :rememberable - manages token-based user remembering
# :validatable - provides email and password validation
# Other available modules are:
# :confirmable - requires email confirmation
# :lockable - locks account after failed login attempts
# :timeoutable - expires sessions after inactivity
# :trackable - tracks sign-in count, timestamps, and IP
# :omniauthable - allows authentication via OAuth providers
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
# Relationships
has_many :events, dependent: :destroy
has_many :tickets, dependent: :destroy
has_many :orders, dependent: :destroy
has_many :earnings, dependent: :destroy
has_many :payouts, dependent: :destroy
# Validations - allow reasonable name lengths
validates :last_name, length: { minimum: 2, maximum: 50, allow_blank: true }
validates :first_name, length: { minimum: 2, maximum: 50, allow_blank: true }
validates :company_name, length: { minimum: 2, maximum: 100, allow_blank: true }
# Banking information validations
validates :iban, format: { with: /\A[A-Z]{2}[0-9]{2}[A-Z0-9]{4}[0-9]{7}([A-Z0-9]?){0,16}\z/, message: "must be a valid IBAN format" }, allow_blank: true
validates :bank_name, length: { minimum: 2, maximum: 100 }, allow_blank: true
validates :account_holder_name, length: { minimum: 2, maximum: 100 }, allow_blank: true
# Onboarding methods
def needs_onboarding?
!onboarding_completed?
end
def complete_onboarding!
update!(onboarding_completed: true)
end
# Authorization methods
def can_manage_events?
# Only professional users can manage events
is_professionnal?
end
def promoter?
# Alias for can_manage_events? to make views more semantic
can_manage_events?
end
def name
[ first_name, last_name ].compact.join(" ").strip
end
# Stripe Connect methods
def stripe_account_id
stripe_connected_account_id
end
def has_stripe_account?
stripe_connected_account_id.present?
end
def can_receive_payouts?
has_complete_banking_info?
end
# Banking information methods
def has_complete_banking_info?
iban.present? && bank_name.present? && account_holder_name.present?
end
def banking_info_summary
return "No banking information" unless has_complete_banking_info?
"#{account_holder_name} - #{bank_name} - #{iban}"
end
private
def stripe_connect_verified?
return false unless stripe_connected_account_id.present?
begin
account = Stripe::Account.retrieve(stripe_connected_account_id)
account.charges_enabled
rescue Stripe::StripeError => e
Rails.logger.error "Failed to verify Stripe account #{stripe_connected_account_id}: #{e.message}"
false
end
end
end