54 lines
1.6 KiB
Ruby
54 lines
1.6 KiB
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
|
|
|
|
# Mark a payout as manually processed (for SEPA transfers, etc.)
|
|
def mark_as_manually_processed
|
|
@payout = Payout.find(params[:id])
|
|
|
|
if @payout.pending? || @payout.processing?
|
|
begin
|
|
@payout.mark_as_manually_processed!
|
|
redirect_to admin_payouts_path, notice: "Payout marked as manually processed. Please complete the bank transfer."
|
|
rescue => e
|
|
redirect_to admin_payouts_path, alert: "Failed to mark payout as manually processed: #{e.message}"
|
|
end
|
|
else
|
|
redirect_to admin_payouts_path, alert: "Cannot mark this payout as manually processed."
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def ensure_admin!
|
|
# For now, we'll just check if the user is a professional user
|
|
# In a real app, you'd have an admin role check
|
|
unless current_user.promoter?
|
|
redirect_to dashboard_path, alert: "Access denied."
|
|
end
|
|
end
|
|
end
|