feat: Add manual payout system for countries without Stripe Global Payouts

This commit is contained in:
kbe
2025-09-17 08:35:20 +02:00
parent 3c1e17c2af
commit c74140c431
12 changed files with 375 additions and 28 deletions

View File

@@ -25,12 +25,28 @@ class Admin::PayoutsController < ApplicationController
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 has a stripe account
# 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.has_stripe_account?
unless current_user.promoter?
redirect_to dashboard_path, alert: "Access denied."
end
end

View File

@@ -82,6 +82,30 @@ class Payout < ApplicationRecord
service = PayoutService.new(self)
service.process!
end
# Mark payout as manually processed (for countries where Stripe payouts are not available)
def mark_as_manually_processed!
return unless pending? || processing?
update!(
status: :completed,
stripe_payout_id: "MANUAL_#{SecureRandom.hex(10)}" # Generate a unique ID for manual payouts
)
update_earnings_status
end
# Check if this is a manual payout (not processed through Stripe)
def manual_payout?
stripe_payout_id.present? && stripe_payout_id.start_with?("MANUAL_")
end
private
def update_earnings_status
event.earnings.where(status: 0).update_all(status: 1) # pending to paid
end
public
# === Instance Methods ===

View File

@@ -6,6 +6,39 @@ class PayoutService
def process!
return unless @payout.can_process?
# Check if user is in France or doesn't have a Stripe account (manual processing)
if should_process_manually?
process_manually!
else
process_with_stripe!
end
end
private
def should_process_manually?
# For now, we'll assume manual processing for all users
# In a real implementation, this could check the user's country
!@payout.user.has_stripe_account?
end
def process_manually!
@payout.update!(status: :processing)
begin
# For manual processing, we just mark it as completed
# In a real implementation, this would trigger notifications to admin
@payout.mark_as_manually_processed!
Rails.logger.info "Manual payout processed for payout #{@payout.id} for event #{@payout.event.name}"
rescue => e
@payout.update!(status: :failed)
Rails.logger.error "Manual payout failed for payout #{@payout.id}: #{e.message}"
raise e
end
end
def process_with_stripe!
@payout.update!(status: :processing)
begin
@@ -31,8 +64,6 @@ class PayoutService
end
end
private
def update_earnings_status
@payout.event.earnings.where(status: 0).update_all(status: 1) # pending to paid
end

View File

@@ -57,6 +57,11 @@
<%= button_to "Process", admin_payout_path(payout), method: :post,
class: "text-indigo-600 hover:text-indigo-900 bg-indigo-100 hover:bg-indigo-200 px-3 py-1 rounded" %>
<% end %>
<% if payout.pending? || payout.processing? %>
<%= button_to "Mark as Manually Processed", mark_as_manually_processed_admin_payout_path(payout), method: :post,
class: "text-green-600 hover:text-green-900 bg-green-100 hover:bg-green-200 px-3 py-1 rounded ml-2",
data: { confirm: "Are you sure you want to mark this payout as manually processed? This will notify the promoter that the bank transfer is being processed." } %>
<% end %>
<%= link_to "View", promoter_payout_path(payout), class: "text-indigo-600 hover:text-indigo-900 ml-2" %>
</td>
</tr>

View File

@@ -1,2 +1,122 @@
<h1>Admin::Payouts#show</h1>
<p>Find me in app/views/admin/payouts/show.html.erb</p>
<div class="container mx-auto px-4 py-8">
<div class="flex justify-between items-center mb-6">
<h1 class="text-3xl font-bold text-gray-900">Payout Details</h1>
<%= link_to "Back to Payouts", admin_payouts_path, class: "text-indigo-600 hover:text-indigo-900" %>
</div>
<div class="bg-white rounded-lg shadow overflow-hidden">
<div class="px-6 py-4 border-b border-gray-200">
<h2 class="text-xl font-semibold text-gray-800">Payout #<%= @payout.id %></h2>
</div>
<div class="p-6">
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<h3 class="text-lg font-medium text-gray-900 mb-4">Event Information</h3>
<div class="space-y-3">
<div>
<p class="text-sm font-medium text-gray-500">Event Name</p>
<p class="text-sm text-gray-900"><%= @payout.event.name %></p>
</div>
<div>
<p class="text-sm font-medium text-gray-500">Event Date</p>
<p class="text-sm text-gray-900"><%= @payout.event.start_time.strftime("%B %d, %Y") %></p>
</div>
</div>
</div>
<div>
<h3 class="text-lg font-medium text-gray-900 mb-4">Promoter Information</h3>
<div class="space-y-3">
<div>
<p class="text-sm font-medium text-gray-500">Name</p>
<p class="text-sm text-gray-900"><%= @payout.user.name.presence || @payout.user.email %></p>
</div>
<div>
<p class="text-sm font-medium text-gray-500">Email</p>
<p class="text-sm text-gray-900"><%= @payout.user.email %></p>
</div>
</div>
</div>
<div>
<h3 class="text-lg font-medium text-gray-900 mb-4">Financial Details</h3>
<div class="space-y-3">
<div>
<p class="text-sm font-medium text-gray-500">Gross Amount</p>
<p class="text-sm text-gray-900">€<%= @payout.amount_euros %></p>
</div>
<div>
<p class="text-sm font-medium text-gray-500">Platform Fees</p>
<p class="text-sm text-gray-900">€<%= @payout.fee_euros %></p>
</div>
<div>
<p class="text-sm font-medium text-gray-500">Net Amount</p>
<p class="text-sm text-gray-900">€<%= @payout.net_amount_euros %></p>
</div>
</div>
</div>
<div>
<h3 class="text-lg font-medium text-gray-900 mb-4">Payout Information</h3>
<div class="space-y-3">
<div>
<p class="text-sm font-medium text-gray-500">Status</p>
<p class="text-sm text-gray-900">
<% case @payout.status %>
<% when 'pending' %>
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-yellow-100 text-yellow-800">
Pending
</span>
<% when 'processing' %>
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-blue-100 text-blue-800">
Processing
</span>
<% when 'completed' %>
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
Completed
</span>
<% when 'failed' %>
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">
Failed
</span>
<% end %>
</p>
</div>
<div>
<p class="text-sm font-medium text-gray-500">Created At</p>
<p class="text-sm text-gray-900"><%= @payout.created_at.strftime("%B %d, %Y at %H:%M") %></p>
</div>
<% if @payout.stripe_payout_id.present? %>
<div>
<p class="text-sm font-medium text-gray-500">Payout ID</p>
<p class="text-sm text-gray-900">
<% if @payout.manual_payout? %>
Manual Transfer - <%= @payout.stripe_payout_id %>
<% else %>
<%= @payout.stripe_payout_id %>
<% end %>
</p>
</div>
<% end %>
</div>
</div>
</div>
<div class="mt-8 flex space-x-4">
<% if @payout.can_process? %>
<%= button_to "Process Payout", admin_payout_path(@payout), method: :post,
class: "inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" %>
<% end %>
<% if @payout.pending? || @payout.processing? %>
<%= button_to "Mark as Manually Processed", mark_as_manually_processed_admin_payout_path(@payout), method: :post,
class: "inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500",
data: { confirm: "Are you sure you want to mark this payout as manually processed? This will notify the promoter that the bank transfer is being processed." } %>
<% end %>
<%= link_to "View as Promoter", promoter_payout_path(@payout), class: "inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md shadow-sm text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" %>
</div>
</div>
</div>
</div>

View File

@@ -159,7 +159,11 @@
<% when 'completed' %>
<span class="payout-status-badge completed">
<i data-lucide="check-circle" class="w-3 h-3 mr-1"></i>
Completed
<% if payout.manual_payout? %>
Manually Processed
<% else %>
Completed
<% end %>
</span>
<% when 'failed' %>
<span class="payout-status-badge failed">

View File

@@ -162,8 +162,41 @@
<% if @payout.stripe_payout_id.present? %>
<div class="px-4 py-5 sm:px-6 payout-detail-item">
<dt class="payout-detail-label">Stripe Payout ID</dt>
<dd class="payout-detail-value font-mono text-xs break-all"><%= @payout.stripe_payout_id %></dd>
<dt class="payout-detail-label">
<% if @payout.manual_payout? %>
Manual Payout ID
<% else %>
Stripe Payout ID
<% end %>
</dt>
<dd class="payout-detail-value font-mono text-xs break-all">
<% if @payout.manual_payout? %>
Manual Transfer - <%= @payout.stripe_payout_id %>
<% else %>
<%= @payout.stripe_payout_id %>
<% end %>
</dd>
</div>
<% end %>
<% if @payout.manual_payout? && @payout.completed? %>
<div class="px-4 py-5 sm:px-6 payout-detail-item">
<dt class="payout-detail-label">Manual Processing Note</dt>
<dd class="payout-detail-value">
<div class="bg-blue-50 border border-blue-200 rounded-md p-4">
<div class="flex">
<div class="flex-shrink-0">
<i data-lucide="info" class="h-5 w-5 text-blue-400"></i>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-blue-800">Bank Transfer Initiated</h3>
<div class="mt-2 text-sm text-blue-700">
<p>Your payout is being processed via bank transfer. Please allow 1-3 business days for the funds to appear in your account.</p>
</div>
</div>
</div>
</div>
</dd>
</div>
<% end %>
</div>