Aggiunge abbonamenti omaggio admin per sponsor e promozioni.

Gli admin possono concedere o revocare Premium Light/Full senza Stripe;
il piano omaggio ha priorità sui webhook e la società vede un messaggio dedicato.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-02 22:26:19 +02:00
parent 566104aff4
commit 82ff1972a0
24 changed files with 388 additions and 7 deletions

View File

@@ -0,0 +1,45 @@
module Admin
class ClubsController < BaseController
before_action :set_club, only: %i[show grant_comped revoke_comped]
def index
@clubs = Club.includes(:subscription, subscription: :plan, subscription: :admin_comped_by)
.order(:name)
end
def show
@subscription = @club.subscription || @club.build_subscription(plan: Plan["free"], status: "active")
@plans = Plan.ordered.reject { |p| p.slug == "free" }
end
def grant_comped
Billing::AdminCompedSubscription.grant(
club: @club,
plan_slug: params.require(:plan_slug),
reason: params[:reason],
admin: current_admin_account
)
redirect_back_or_club notice: "Abbonamento omaggio #{Plan[params[:plan_slug]].name} attivato per #{@club.name}."
rescue Billing::AdminCompedSubscription::Error, ActiveRecord::RecordInvalid => e
redirect_back_or_club alert: e.message
end
def revoke_comped
Billing::AdminCompedSubscription.revoke(club: @club, admin: current_admin_account)
redirect_back_or_club notice: "Abbonamento omaggio revocato per #{@club.name}."
rescue Billing::AdminCompedSubscription::Error => e
redirect_back_or_club alert: e.message
end
private
def set_club
@club = Club.find(params[:id])
end
def redirect_back_or_club(notice: nil, alert: nil)
target = params[:return_to].presence || admin_club_path(@club)
redirect_to target, notice: notice, alert: alert
end
end
end