Aggiunge pagamento con bonifico e importo concordato per società.

Il piano si attiva solo dopo la conferma admin; Stripe resta a listino se non c'è un prezzo commerciale.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-18 23:20:43 +02:00
co-authored by Cursor
parent 1e4e0560f1
commit e436f5ece4
56 changed files with 1571 additions and 53 deletions
@@ -2,6 +2,7 @@ module Admin
class BillingController < BaseController
def index
@pending_payments = pending_scope.recent
@pending_transfers = transfer_scope
@completed_payments = Billing::Payment.with_invoice_pdf.includes(:club, :invoice).recent.limit(40)
@filter_club = Club.find_by(id: params[:club_id]) if params[:club_id].present?
@clubs = Club.order(:name)
@@ -18,6 +19,25 @@ module Admin
alert: e.message
end
def confirm_transfer
order = Billing::TransferOrder.find(params[:id])
Billing::ConfirmBankTransfer.call(
order: order,
admin: current_admin_account,
pdf: params[:pdf]
)
redirect_to admin_billing_path(club_id: order.club_id),
notice: t("admin.flash.transfer_confirmed", plan: order.plan.name, club: order.club.name)
rescue Billing::ConfirmBankTransfer::Error, Billing::AttachPaymentInvoice::Error, Billing::IssueInvoice::Error => e
redirect_to admin_billing_path, alert: e.message
end
def cancel_transfer
order = Billing::TransferOrder.find(params[:id])
order.cancel!
redirect_to admin_billing_path(club_id: order.club_id), notice: t("admin.flash.transfer_cancelled")
end
private
def pending_scope
@@ -26,6 +46,12 @@ module Admin
scope
end
def transfer_scope
scope = Billing::TransferOrder.awaiting_payment.includes(:club, :requested_by_user)
scope = scope.where(club_id: params[:club_id]) if params[:club_id].present?
scope
end
def billing_redirect_params(payment)
{ club_id: payment.club_id, anchor: "payment-#{payment.id}" }.compact
end
@@ -1,9 +1,9 @@
module Admin
class ClubsController < BaseController
before_action :set_club, only: %i[show grant_comped revoke_comped]
before_action :set_club, only: %i[show grant_comped revoke_comped set_quote revoke_quote]
def index
@clubs = Club.includes(:teams, subscription: %i[plan admin_comped_by])
@clubs = Club.includes(:teams, :billing_quote, subscription: %i[plan admin_comped_by])
.order(:name)
end
@@ -11,6 +11,7 @@ module Admin
@subscription = @club.subscription || @club.build_subscription(plan: Plan["free"], status: "active")
@plans = Plan.ordered.reject { |p| p.slug == "free" }
@teams = @club.teams.order(:name)
@quote = @club.active_billing_quote
end
def grant_comped
@@ -32,6 +33,32 @@ module Admin
redirect_back_or_club alert: e.message
end
def set_quote
quote = Billing::SetClubQuote.upsert(
club: @club,
plan_slug: params.require(:plan_slug),
interval: params[:interval],
amount_euros: params[:amount_euros],
note: params[:note],
admin: current_admin_account
)
redirect_back_or_club notice: t(
"admin.flash.quote_saved",
club: @club.name,
plan: quote.plan.name,
amount: quote.formatted_amount
)
rescue Billing::SetClubQuote::Error, ActionController::ParameterMissing => e
redirect_back_or_club alert: e.message
end
def revoke_quote
Billing::SetClubQuote.revoke(club: @club, admin: current_admin_account)
redirect_back_or_club notice: t("admin.flash.quote_revoked", club: @club.name)
rescue Billing::SetClubQuote::Error => e
redirect_back_or_club alert: e.message
end
private
def set_club
@@ -11,11 +11,15 @@ module Public
@club.assign_attributes(billing_profile_params)
if @club.save(context: :billing_profile)
if premium_checkout_return_params.present? && @club.billing_profile_complete?
redirect_to public_club_checkout_path(
@club,
plan: premium_checkout_return_params[:plan],
interval: premium_checkout_return_params[:interval]
), notice: t("flash.club_billing.profile_saved_proceed_payment")
if @club.active_billing_quote.present?
redirect_to public_club_billing_path(@club), notice: t("flash.club_billing.profile_updated")
else
redirect_to public_club_checkout_path(
@club,
plan: premium_checkout_return_params[:plan],
interval: premium_checkout_return_params[:interval]
), notice: t("flash.club_billing.profile_saved_proceed_payment")
end
else
redirect_to public_club_billing_path(@club), notice: t("flash.club_billing.profile_updated")
end
@@ -42,6 +46,29 @@ module Public
redirect_to public_club_billing_path(@club), alert: t("flash.club_billing.stripe_error", message: e.message)
end
def request_bank_transfer
if @club.subscription&.admin_comped?
redirect_to public_club_billing_path(@club), alert: t("flash.clubs.comped_change_denied")
return
end
unless @club.billing_profile_complete?
redirect_to public_club_billing_profile_path(@club, plan: params[:plan], interval: params[:interval]),
alert: t("flash.clubs.complete_billing_first")
return
end
Billing::RequestBankTransfer.call(
club: @club,
user: current_user,
plan_slug: params[:plan],
interval: params[:interval]
)
redirect_to public_club_billing_path(@club), notice: t("flash.club_billing.bank_transfer_requested")
rescue Billing::RequestBankTransfer::Error, ArgumentError => e
redirect_to public_club_billing_path(@club), alert: e.message
end
def download_invoice
invoice = @club.billing_invoices.find(params[:invoice_id])
unless invoice.pdf.attached?
@@ -82,6 +82,8 @@ module Public
@entitlements = @team.entitlements
@plans = Plan.ordered
@payments = @club.billing_payments.recent.includes(:invoice).limit(50)
@quote = @club.active_billing_quote
@pending_transfer = @club.billing_transfer_orders.awaiting_payment.first
end
def checkout
@@ -92,6 +94,12 @@ module Public
return
end
if @club.active_billing_quote.present?
redirect_to public_club_billing_path(@club),
alert: t("flash.club_billing.quote_checkout_denied")
return
end
unless MatchLiveTv.stripe_enabled?
redirect_to public_club_billing_path(@club), alert: t("flash.clubs.stripe_not_configured")
return