Resolve merge conflicts in payout system implementation
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -1,27 +1,62 @@
|
||||
class Admin::PayoutsController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
before_action :ensure_admin!
|
||||
before_action :set_payout, only: [ :show, :approve, :reject, :mark_processing, :mark_completed, :mark_failed ]
|
||||
|
||||
def index
|
||||
@payouts = Payout.pending.includes(:user, :event).order(created_at: :asc).page(params[:page])
|
||||
@pending_payouts = Payout.pending.includes(:user, :event).order(created_at: :asc)
|
||||
@approved_payouts = Payout.approved.includes(:user, :event).order(created_at: :asc)
|
||||
@processing_payouts = Payout.processing.includes(:user, :event).order(created_at: :asc)
|
||||
@completed_payouts = Payout.completed.includes(:user, :event).order(created_at: :desc).limit(10)
|
||||
end
|
||||
|
||||
def show
|
||||
@payout = Payout.find(params[:id])
|
||||
@service = PayoutService.new(@payout)
|
||||
@transfer_summary = @service.generate_transfer_summary
|
||||
@banking_errors = @service.validate_banking_info
|
||||
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
|
||||
def approve
|
||||
if @payout.approve!(current_user)
|
||||
redirect_to admin_payout_path(@payout), notice: "Payout approved successfully."
|
||||
else
|
||||
redirect_to admin_payouts_path, alert: "Cannot process this payout."
|
||||
redirect_to admin_payout_path(@payout), alert: "Cannot approve this payout."
|
||||
end
|
||||
end
|
||||
|
||||
def reject
|
||||
reason = params[:rejection_reason].presence || "No reason provided"
|
||||
if @payout.reject!(current_user, reason)
|
||||
redirect_to admin_payouts_path, notice: "Payout rejected."
|
||||
else
|
||||
redirect_to admin_payout_path(@payout), alert: "Cannot reject this payout."
|
||||
end
|
||||
end
|
||||
|
||||
def mark_processing
|
||||
transfer_reference = params[:bank_transfer_reference]
|
||||
if @payout.mark_processing!(current_user, transfer_reference)
|
||||
redirect_to admin_payout_path(@payout), notice: "Payout marked as processing."
|
||||
else
|
||||
redirect_to admin_payout_path(@payout), alert: "Cannot mark payout as processing."
|
||||
end
|
||||
end
|
||||
|
||||
def mark_completed
|
||||
transfer_reference = params[:bank_transfer_reference]
|
||||
if @payout.mark_completed!(current_user, transfer_reference)
|
||||
redirect_to admin_payouts_path, notice: "Payout completed successfully."
|
||||
else
|
||||
redirect_to admin_payout_path(@payout), alert: "Cannot mark payout as completed."
|
||||
end
|
||||
end
|
||||
|
||||
def mark_failed
|
||||
reason = params[:failure_reason].presence || "Transfer failed"
|
||||
if @payout.mark_failed!(current_user, reason)
|
||||
redirect_to admin_payouts_path, notice: "Payout marked as failed."
|
||||
else
|
||||
redirect_to admin_payout_path(@payout), alert: "Cannot mark payout as failed."
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,6 +78,10 @@ class Admin::PayoutsController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def set_payout
|
||||
@payout = Payout.find(params[:id])
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user