Files
aperonight/app/controllers/admin/payouts_controller.rb
kbe 3c1e17c2af 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
2025-09-17 02:07:52 +02:00

38 lines
1019 B
Ruby

class Admin::PayoutsController < ApplicationController
before_action :authenticate_user!
before_action :ensure_admin!
def index
@payouts = Payout.pending.includes(:user, :event).order(created_at: :asc).page(params[:page])
end
def show
@payout = Payout.find(params[:id])
end
def process
@payout = Payout.find(params[:id])
if @payout.pending? && @payout.can_process?
begin
PayoutService.new(@payout).process!
redirect_to admin_payouts_path, notice: "Payout processed successfully."
rescue => e
redirect_to admin_payouts_path, alert: "Failed to process payout: #{e.message}"
end
else
redirect_to admin_payouts_path, alert: "Cannot process this payout."
end
end
private
def ensure_admin!
# For now, we'll just check if the user has a stripe account
# In a real app, you'd have an admin role check
unless current_user.has_stripe_account?
redirect_to dashboard_path, alert: "Access denied."
end
end
end