- Add Payout model with associations to User and Event - Create payout requests for completed events with proper earnings calculation - Exclude refunded tickets from payout calculations - Add promoter dashboard views for managing payouts - Implement admin interface for processing payouts - Integrate with Stripe for actual payment processing - Add comprehensive tests for payout functionality Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
30 lines
737 B
Ruby
30 lines
737 B
Ruby
class PayoutService
|
|
def initialize(payout)
|
|
@payout = payout
|
|
end
|
|
|
|
def process!
|
|
return unless @payout.can_process?
|
|
|
|
@payout.update!(status: :processing)
|
|
|
|
# Create Stripe payout
|
|
begin
|
|
stripe_payout = Stripe::Payout.create({
|
|
amount: @payout.amount_cents,
|
|
currency: 'eur',
|
|
destination: @payout.user.stripe_account_id,
|
|
description: "Payout for event: #{@payout.event.name}"
|
|
})
|
|
|
|
@payout.update!(
|
|
status: :completed,
|
|
stripe_payout_id: stripe_payout.id
|
|
)
|
|
rescue Stripe::StripeError => e
|
|
@payout.update!(status: :failed)
|
|
Rails.logger.error "Stripe payout failed for payout #{@payout.id}: #{e.message}"
|
|
raise e
|
|
end
|
|
end
|
|
end |