feat(payouts): implement promoter earnings viewing, request flow, and admin Stripe processing with webhooks

Add model methods for accurate net calculations (€0.50 + 1.5% fees), eligibility, refund handling
Update promoter/payouts controller for index (pending events), create (eligibility checks)
Integrate admin processing via Stripe::Transfer, webhook for status sync
Enhance views: index pending cards, events/show preview/form
Add comprehensive tests (models, controllers, service, integration); run migrations
This commit is contained in:
kbe
2025-09-17 02:07:52 +02:00
parent 47f4f50e5b
commit 3c1e17c2af
31 changed files with 1096 additions and 148 deletions

View File

@@ -8,23 +8,32 @@ class PayoutService
@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}"
})
net_amount = @payout.amount_cents - @payout.fee_cents
transfer = Stripe::Transfer.create({
amount: (net_amount / 100.0).to_i,
currency: "eur",
destination: @payout.user.stripe_connected_account_id,
description: "Payout for event #{@payout.event.name}",
metadata: { payout_id: @payout.id, event_id: @payout.event_id }
}, idempotency_key: SecureRandom.uuid)
@payout.update!(
status: :completed,
stripe_payout_id: stripe_payout.id
stripe_payout_id: transfer.id
)
update_earnings_status
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
private
def update_earnings_status
@payout.event.earnings.where(status: 0).update_all(status: 1) # pending to paid
end
end