feat: complete promoter payout system with Stripe Connect onboarding
This commit is contained in:
@@ -1,10 +1,32 @@
|
||||
class Promoter::PayoutsController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
before_action :ensure_promoter
|
||||
|
||||
def index
|
||||
@events = current_user.events.includes(:earnings).order(start_time: :desc)
|
||||
end
|
||||
|
||||
def show
|
||||
@event = current_user.events.find(params[:id])
|
||||
@earnings = @event.earnings
|
||||
end
|
||||
|
||||
def create
|
||||
@event = current_user.events.find(params[:event_id] || params[:id])
|
||||
|
||||
if @event.can_request_payout?
|
||||
PayoutService.new.process_event_payout(@event)
|
||||
redirect_to promoter_payout_path(@event), notice: "Payout requested successfully. It will be processed shortly."
|
||||
else
|
||||
redirect_to promoter_payouts_path, alert: "Cannot request payout: #{@event.can_request_payout? ? '' : 'Event not eligible for payout.'}"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ensure_promoter
|
||||
unless current_user.promoter?
|
||||
redirect_to dashboard_path, alert: "Access denied. Promoter account required."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
35
app/services/stripe_connect_service.rb
Normal file
35
app/services/stripe_connect_service.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
class StripeConnectService
|
||||
def self.create_account(user)
|
||||
return if user.stripe_connected_account_id.present?
|
||||
|
||||
account = Stripe::Account.create(
|
||||
type: 'express',
|
||||
country: 'FR',
|
||||
email: user.email,
|
||||
capabilities: {
|
||||
card_payments: {requested: true},
|
||||
transfers: {requested: true}
|
||||
}
|
||||
)
|
||||
|
||||
user.update!(stripe_connected_account_id: account.id)
|
||||
account
|
||||
end
|
||||
|
||||
def self.onboarding_link(user)
|
||||
return unless user.stripe_connected_account_id.present?
|
||||
|
||||
account_link = Stripe::AccountLink.create(
|
||||
account: user.stripe_connected_account_id,
|
||||
refresh_url: Rails.application.routes.url_helpers.promoter_stripe_refresh_url,
|
||||
return_url: Rails.application.routes.url_helpers.promoter_stripe_return_url,
|
||||
type: 'account_onboarding'
|
||||
)
|
||||
|
||||
account_link.url
|
||||
end
|
||||
|
||||
def self.get_account_details(account_id)
|
||||
Stripe::Account.retrieve(account_id)
|
||||
end
|
||||
end
|
||||
@@ -1,2 +1,39 @@
|
||||
<h1>Promoter::Payouts#index</h1>
|
||||
<p>Find me in app/views/promoter/payouts/index.html.erb</p>
|
||||
<div class="container mx-auto px-4 py-8">
|
||||
<h1 class="text-3xl font-bold mb-6">My Payouts</h1>
|
||||
|
||||
<% if @events.any? %>
|
||||
<div class="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
|
||||
<% @events.each do |event| %>
|
||||
<div class="bg-white rounded-lg shadow-md p-6">
|
||||
<h3 class="text-xl font-semibold mb-2"><%= event.name %></h3>
|
||||
<p class="text-gray-600 mb-2">Date: <%= event.start_time.strftime('%B %d, %Y at %I:%M %p') %></p>
|
||||
<p class="text-gray-600 mb-4">Status: <span class="font-medium"><%= event.payout_status.humanize %></span></p>
|
||||
|
||||
<% if event.earnings.pending.any? %>
|
||||
<div class="mb-4">
|
||||
<p class="text-lg font-semibold text-green-600">Gross: €<%= (event.total_earnings_cents / 100.0).round(2) %></p>
|
||||
<p class="text-sm text-gray-500">Fees (10%): €<%= (event.total_fees_cents / 100.0).round(2) %></p>
|
||||
<p class="text-lg font-semibold text-blue-600">Net: €<%= (event.net_earnings_cents / 100.0).round(2) %></p>
|
||||
</div>
|
||||
|
||||
<% if event.can_request_payout? %>
|
||||
<%= button_to "Request Payout", promoter_payouts_path(event_id: event.id),
|
||||
method: :post,
|
||||
class: "w-full bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline" %>
|
||||
<% else %>
|
||||
<p class="text-sm text-gray-500">Payout not available yet</p>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<p class="text-gray-500">No pending earnings</p>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<% else %>
|
||||
<div class="text-center py-12">
|
||||
<h2 class="text-2xl font-semibold mb-2">No events found</h2>
|
||||
<p class="text-gray-600 mb-4">You haven't created any events yet.</p>
|
||||
<%= link_to "Create Event", new_promoter_event_path, class: "bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -1,2 +1,58 @@
|
||||
<h1>Promoter::Payouts#show</h1>
|
||||
<p>Find me in app/views/promoter/payouts/show.html.erb</p>
|
||||
<div class="container mx-auto px-4 py-8">
|
||||
<h1 class="text-3xl font-bold mb-6"><%= @event.name %> - Payout Details</h1>
|
||||
|
||||
<div class="bg-white rounded-lg shadow-md p-6 mb-6">
|
||||
<h2 class="text-xl font-semibold mb-4">Event Summary</h2>
|
||||
<p><strong>Date:</strong> <%= @event.start_time.strftime('%B %d, %Y at %I:%M %p') %></p>
|
||||
<p><strong>Venue:</strong> <%= @event.venue_name %></p>
|
||||
<p><strong>Payout Status:</strong> <span class="font-medium <%= @event.payout_status %>"><%= @event.payout_status.humanize %></span></p>
|
||||
<% if @event.payout_requested_at %>
|
||||
<p><strong>Requested:</strong> <%= @event.payout_requested_at.strftime('%B %d, %Y at %I:%M %p') %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<% if @earnings.any? %>
|
||||
<div class="bg-white rounded-lg shadow-md p-6">
|
||||
<h2 class="text-xl font-semibold mb-4">Earnings Breakdown</h2>
|
||||
<div class="overflow-x-auto">
|
||||
<table class="min-w-full table-auto">
|
||||
<thead>
|
||||
<tr class="bg-gray-100">
|
||||
<th class="px-4 py-2 text-left">Order</th>
|
||||
<th class="px-4 py-2 text-left">Gross Amount</th>
|
||||
<th class="px-4 py-2 text-left">Fee</th>
|
||||
<th class="px-4 py-2 text-left">Net Amount</th>
|
||||
<th class="px-4 py-2 text-left">Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @earnings.each do |earning| %>
|
||||
<tr class="<%= earning.status == 'pending' ? 'bg-yellow-50' : 'bg-green-50' %>">
|
||||
<td class="border px-4 py-2">#<%= earning.order_id %></td>
|
||||
<td class="border px-4 py-2">€<%= (earning.amount_cents / 100.0).round(2) %></td>
|
||||
<td class="border px-4 py-2">€<%= (earning.fee_cents / 100.0).round(2) %></td>
|
||||
<td class="border px-4 py-2">€<%= (earning.net_amount_cents / 100.0).round(2) %></td>
|
||||
<td class="border px-4 py-2">
|
||||
<span class="px-2 py-1 rounded text-xs <%= earning.status == 'pending' ? 'bg-yellow-200 text-yellow-800' : 'bg-green-200 text-green-800' %>">
|
||||
<%= earning.status.humanize %>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 p-4 bg-gray-50 rounded">
|
||||
<h3 class="font-semibold">Total Summary</h3>
|
||||
<p>Gross Total: €<%= (@earnings.sum(:amount_cents) / 100.0).round(2) %></p>
|
||||
<p>Total Fees: €<%= (@earnings.sum(:fee_cents) / 100.0).round(2) %></p>
|
||||
<p>Net Total: €<%= (@earnings.sum(:net_amount_cents) / 100.0).round(2) %></p>
|
||||
</div>
|
||||
</div>
|
||||
<% else %>
|
||||
<div class="bg-white rounded-lg shadow-md p-6">
|
||||
<p class="text-gray-500">No earnings recorded for this event.</p>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class AddIndexToStripeConnectedAccountIdOnUsers < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :stripe_connected_account_id_on_users, :stripe_connected_account_id, :string
|
||||
add_index :users, :stripe_connected_account_id, unique: true
|
||||
add_index :stripe_connected_account_id_on_users, :stripe_connected_account_id
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user