Mostra il piano attivo dopo il bonifico e allinea il flusso società.

Dopo la conferma admin la card restava su «Paga con bonifico»; la società parte da Free, l'owner è staff trasmissione e le mail non bloccano se manca SMTP.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-19 18:31:39 +02:00
co-authored by Cursor
parent e436f5ece4
commit 5bcb4170c7
31 changed files with 359 additions and 111 deletions
@@ -23,23 +23,28 @@ module Public
ClubMembership.create!(user: current_user, club: club, role: "owner")
first_team_name = params.dig(:first_team, :name).presence || t("club.new.default_first_team_name")
club.teams.create!(
first_team = club.teams.create!(
name: first_team_name,
sport: club.sport
)
plan = params[:plan].presence_in(%w[free premium_light premium_full]) || "free"
Billing::AssignPlan.call(club: club, plan_slug: plan)
desired_plan = params[:plan].presence_in(%w[free premium_light premium_full]) || "free"
Billing::AssignPlan.call(club: club, plan_slug: "free")
Teams::StaffAssignment.designate_club_owner!(team: first_team, user: current_user)
if plan.in?(%w[premium_light premium_full]) && MatchLiveTv.stripe_enabled?
unless club.billing_profile_complete?
redirect_to public_club_billing_profile_path(club, plan: plan, interval: checkout_interval_param),
alert: t("flash.clubs.complete_billing_first")
return
if desired_plan.in?(%w[premium_light premium_full])
interval = Billing::Stripe::PriceCatalog::DEFAULT_INTERVAL
if MatchLiveTv.stripe_enabled?
unless club.billing_profile_complete?
redirect_to public_club_billing_profile_path(club, plan: desired_plan, interval: interval),
alert: t("flash.clubs.complete_billing_first")
return
end
redirect_to public_club_checkout_path(club, plan: desired_plan, interval: interval)
else
redirect_to public_club_billing_path(club), notice: t("flash.clubs.created_complete_subscription")
end
interval = checkout_interval_param
redirect_to public_club_checkout_path(club, plan: plan, interval: interval)
else
redirect_to public_club_path(club), notice: t("flash.clubs.created")
end
@@ -19,6 +19,7 @@ module Public
require_club_owner!(@club)
team = @club.teams.create!(team_params)
attach_branding_logo(team)
Teams::StaffAssignment.designate_club_owner!(team: team, user: current_user)
redirect_to public_club_path(@club), notice: t("flash.teams.added", name: team.name)
rescue ActiveRecord::RecordInvalid => e
flash.now[:alert] = e.record.errors.full_messages.join(", ")
@@ -11,6 +11,13 @@ module Public
quote = club&.active_billing_quote
if quote
if quote.plan_slug == target_plan.slug
if current_paid_plan?(subscription, target_plan)
return {
kind: :current,
label: "#{I18n.t('billing.actions.current_plan')}#{quote.price_label}"
}
end
return { kind: :quoted, plan: target_plan, quote: quote, intervals: [quote.billing_interval] }
end
@@ -19,6 +26,9 @@ module Public
intervals = bank_transfer_intervals_for(target_plan)
unless MatchLiveTv.stripe_enabled?
if current_paid_plan?(subscription, target_plan)
return { kind: :current, label: current_plan_label(target_plan, subscription) }
end
if MatchLiveTv.bank_transfer_configured?
return { kind: :bank_only, plan: target_plan, intervals: intervals }
end
@@ -28,6 +38,9 @@ module Public
stripe_intervals = Billing::Stripe::PriceCatalog.available_intervals(plan_slug: target_plan.slug)
if stripe_intervals.empty?
if current_paid_plan?(subscription, target_plan)
return { kind: :current, label: current_plan_label(target_plan, subscription) }
end
if MatchLiveTv.bank_transfer_configured?
return { kind: :bank_only, plan: target_plan, intervals: intervals }
end
@@ -54,6 +67,10 @@ module Public
}
end
if current_paid_plan?(subscription, target_plan)
return { kind: :current, label: current_plan_label(target_plan, subscription) }
end
if current_slug == "free" || !stripe_subscription_active
{ kind: :checkout_options, plan: target_plan, intervals: stripe_intervals.presence || intervals, subscription: subscription }
else
@@ -136,8 +153,21 @@ module Public
return false unless MatchLiveTv.bank_transfer_configured?
return false if quote && !quote.matches?(plan.slug, interval)
return false if pending_transfer&.awaiting_payment?
return false if current_paid_plan?(club.subscription, plan)
true
end
def current_paid_plan?(subscription, target_plan)
return false unless subscription&.active? && subscription.premium?
return false if subscription.plan_change_pending?
subscription.plan.slug == target_plan.slug
end
def current_plan_label(target_plan, subscription)
interval = subscription&.billing_interval.presence || Billing::Stripe::PriceCatalog::DEFAULT_INTERVAL
"#{I18n.t('billing.actions.current_plan')}#{Billing::Stripe::PriceCatalog.label(plan_slug: target_plan.slug, interval: interval)}"
end
end
end
@@ -88,7 +88,7 @@ module Billing
mailer_action: :plan_activated_with_invoice
)
else
BankTransferMailer.with(order: @order.reload).plan_activated.deliver_now
MatchLiveTv.deliver_mail(BankTransferMailer.with(order: @order.reload).plan_activated)
end
end
@@ -26,8 +26,10 @@ module Billing
@invoice.update!(status: "issued")
Billing::InvoiceMailer.with(invoice: @invoice).public_send(@mailer_action).deliver_now
@invoice.update!(status: "sent", emailed_at: Time.current)
mail = Billing::InvoiceMailer.with(invoice: @invoice).public_send(@mailer_action)
if MatchLiveTv.deliver_mail(mail)
@invoice.update!(status: "sent", emailed_at: Time.current)
end
@invoice
end
@@ -28,7 +28,7 @@ module Billing
existing = @club.billing_transfer_orders.awaiting_payment.first
if existing
if existing.plan_slug == @plan_slug && existing.billing_interval == @interval && existing.amount_cents == amount_cents
BankTransferMailer.with(order: existing).instructions.deliver_now
MatchLiveTv.deliver_mail(BankTransferMailer.with(order: existing).instructions)
return existing
end
@@ -59,7 +59,7 @@ module Billing
)
end
BankTransferMailer.with(order: order).instructions.deliver_now
MatchLiveTv.deliver_mail(BankTransferMailer.with(order: order).instructions)
order
end
@@ -23,5 +23,12 @@ module Teams
ut.update!(staff_kind: "transmission")
ut
end
def self.designate_club_owner!(team:, user:)
membership = user.user_teams.find_or_initialize_by(team: team)
membership.role = "member" if membership.new_record?
membership.save!
call(team: team, user: user, membership: membership)
end
end
end
@@ -42,6 +42,10 @@
</header>
<div class="billing-pending-card__body">
<p style="margin:0 0 12px">
<%= t("admin.billing.index.transfers_table.holder") %>:
<strong><%= MatchLiveTv.bank_transfer_account_holder %></strong><br>
<%= t("admin.billing.index.transfers_table.iban") %>:
<strong><%= MatchLiveTv.bank_transfer_iban %></strong><br>
<%= t("admin.billing.index.transfers_table.causal") %>:
<strong><%= order.payment_causal %></strong>
</p>
+1 -1
View File
@@ -13,7 +13,7 @@
<script src="/admin-dashboard.js?v=1" defer></script>
<% end %>
<link rel="stylesheet" href="/confirm-forms.css?v=4">
<script src="/confirm-forms.js?v=6" defer></script>
<script src="/confirm-forms.js?v=7" defer></script>
</head>
<body class="<%= content_for?(:body_class) ? yield(:body_class) : 'admin-body' %>">
<header class="admin-header">
+1 -1
View File
@@ -23,7 +23,7 @@
<script src="/roster-form.js?v=1" defer></script>
<script src="/password-toggle.js?v=2" defer></script>
<link rel="stylesheet" href="/confirm-forms.css?v=4">
<script src="/confirm-forms.js?v=6" defer></script>
<script src="/confirm-forms.js?v=7" defer></script>
<script src="/cookie-consent.js?v=1" defer></script>
</body>
</html>
@@ -18,7 +18,7 @@
</main>
<%= render "shared/marketing_footer" %>
<link rel="stylesheet" href="/confirm-forms.css?v=4">
<script src="/confirm-forms.js?v=6" defer></script>
<script src="/confirm-forms.js?v=7" defer></script>
<script src="/cookie-consent.js?v=1" defer></script>
</body>
</html>
@@ -18,7 +18,7 @@
</div>
<% else %>
<% if @quote %>
<%= render "shared/quoted_price_banner", quote: @quote %>
<%= render "shared/quoted_price_banner", quote: @quote, subscription: @subscription %>
<% elsif MatchLiveTv.stripe_enabled? %>
<%= render "shared/stripe_secure_payment" %>
<% end %>
+2 -9
View File
@@ -24,15 +24,8 @@
[t("club.new.plan_free"), "free"],
[t("club.new.plan_light"), "premium_light"],
[t("club.new.plan_full"), "premium_full"]
], params[:plan] || "free"), id: "club_plan_select" %>
<div id="club_plan_interval" style="margin-top:10px">
<%= label_tag :interval, t("club.new.interval_label") %>
<%= select_tag :interval, options_for_select([
[t("club.new.interval_yearly"), "yearly"],
[t("club.new.interval_monthly"), "monthly"]
], params[:interval] || "yearly") %>
</div>
<%= render "shared/stripe_secure_payment", compact: true %>
], params[:plan] || "free") %>
<p class="muted" style="margin:8px 0 16px"><%= t("club.new.plan_hint") %></p>
<%= submit_tag t("club.new.submit"), class: "btn btn-primary" %>
<% end %>
</div>
@@ -1,33 +1,33 @@
<% team = local_assigns[:team] %>
<% club = local_assigns[:club] %>
<% can_manage = local_assigns[:can_manage] %>
<% owner_membership = local_assigns[:owner_membership] %>
<% staff_memberships = local_assigns[:staff_memberships] %>
<% pending_invitations = local_assigns[:pending_invitations] %>
<% recordings = local_assigns[:recordings] %>
<% entitlements = local_assigns[:entitlements] %>
<% club_owner = club.owner %>
<% extra_staff = staff_memberships.reject { |ut| ut.user_id == club_owner&.id } %>
<section class="team-streaming-staff" id="responsabili-trasmissione">
<% if can_manage %>
<% if owner_membership&.staff_kind.blank? %>
<div class="card team-streaming-staff__self">
<h2><%= t("team.streaming_staff.self_account_heading", email: current_user.email) %></h2>
<p class="muted">
<%= raw t("team.streaming_staff.self_account_hint") %>
</p>
<div class="team-details-actions">
<%= button_to t("team.streaming_staff.self_assign_submit"), public_team_assign_self_staff_path(team), method: :post, params: { staff_kind: "transmission" }, class: "btn btn-primary" %>
</div>
</div>
<% end %>
<% if club_owner %>
<div class="card team-streaming-staff__self">
<h2><%= t("team.streaming_staff.principal_heading") %></h2>
<p>
<%= raw t("team.streaming_staff.principal_body_html", email: club_owner.email) %>
</p>
<p class="muted">
<%= raw t("team.streaming_staff.principal_score_hint_html") %>
</p>
</div>
<% end %>
<h2><%= t("team.streaming_staff.staff_heading") %></h2>
<div class="card">
<% if staff_memberships.any? %>
<% if extra_staff.any? %>
<h2><%= t("team.streaming_staff.extra_staff_heading") %></h2>
<div class="card">
<table class="data">
<thead><tr><th><%= t("team.streaming_staff.col_name") %></th><th><%= t("team.streaming_staff.col_email") %></th><th><%= t("team.streaming_staff.col_role") %></th><% if can_manage %><th></th><% end %></tr></thead>
<tbody>
<% staff_memberships.each do |ut| %>
<% extra_staff.each do |ut| %>
<tr>
<td>
<%= ut.user.name %>
@@ -37,9 +37,7 @@
<td><%= t("team.streaming_staff.role_transmission") %></td>
<% if can_manage %>
<td>
<% if ut.user_id == current_user.id && team.club.owned_by?(current_user) %>
<%= button_to t("team.streaming_staff.clear_self_staff"), public_team_clear_self_staff_path(team), method: :delete, class: "btn btn-secondary", style: "padding:4px 10px;font-size:0.8rem", form: { data: { turbo_confirm: t("team.streaming_staff.clear_self_staff_confirm"), confirm_kind: "delete" } } %>
<% elsif ut.role == "member" %>
<% if ut.role == "member" %>
<%= button_to t("team.streaming_staff.revoke"), public_team_remove_member_path(team, ut.user), method: :delete, class: "btn btn-secondary", style: "padding:4px 10px;font-size:0.8rem", form: { data: { turbo_confirm: t("team.streaming_staff.revoke_confirm", name: ut.user.name), confirm_kind: "delete" } } %>
<% end %>
</td>
@@ -48,13 +46,8 @@
<% end %>
</tbody>
</table>
<% else %>
<p class="muted">
<%= t("team.streaming_staff.no_staff") %>
<% if can_manage %><%= link_to t("team.streaming_staff.invite_someone"), "#invita-trasmissione" %>.<% end %>
</p>
<% end %>
</div>
</div>
<% end %>
<% if can_manage %>
<div class="card team-invite-form" id="invita-trasmissione">
@@ -1,15 +1,10 @@
<%# locals: (order:) %>
<% return if order.blank? %>
<div class="card" style="margin-top:16px;border-color:#3d3520;background:#1a1810">
<p style="margin:0 0 8px;color:#ddd">
<p style="margin:0;color:#ddd">
<strong><%= t("billing.bank_transfer.pending_title") %></strong>
<%= raw t("billing.bank_transfer.pending_body_html",
plan: order.plan.name,
price: order.price_label,
causal: order.payment_causal) %>
</p>
<p style="margin:0;color:#aaa;font-size:0.9rem">
<%= raw t("billing.bank_transfer.pending_proof_html",
email_link: mail_to(MatchLiveTv.bank_transfer_proof_email, MatchLiveTv.bank_transfer_proof_email)) %>
price: order.price_label) %>
</p>
</div>
@@ -109,7 +109,7 @@
public_club_billing_bank_transfer_path(club, plan: plan.slug, interval: interval),
method: :post,
class: "btn btn-outline plan-interval-btn",
form: { data: { turbo_confirm: t("billing.bank_transfer.hint") } } %>
form: { data: { turbo_confirm: t("billing.bank_transfer.confirm") } } %>
<% end %>
</div>
<p class="plan-action-hint" style="margin-top:8px"><%= t("billing.bank_transfer.hint") %></p>
@@ -1,11 +1,19 @@
<%# locals: (quote:) %>
<%# locals: (quote:, subscription: nil) %>
<% return if quote.blank? %>
<% quoted_plan_active = current_paid_plan?(subscription, quote.plan) %>
<div class="card" style="margin-top:16px;border-color:#2e5a3c;background:#142018">
<p style="margin:0;color:#ddd">
<strong><%= t("billing.bank_transfer.quote_banner_title") %></strong>
<%= raw t("billing.bank_transfer.quote_banner_body_html", plan: quote.plan.name, price: quote.price_label) %>
<% if quoted_plan_active %>
<strong><%= t("billing.bank_transfer.quote_banner_active_title") %></strong>
<%= raw t(
"billing.bank_transfer.quote_banner_active_body_html",
plan: quote.plan.name,
price: quote.price_label,
date: subscription&.current_period_end.present? ? l_local(subscription.current_period_end.to_date) : t("billing.subscription_status.end_of_period")
) %>
<% else %>
<strong><%= t("billing.bank_transfer.quote_banner_title") %></strong>
<%= raw t("billing.bank_transfer.quote_banner_body_html", plan: quote.plan.name, price: quote.price_label) %>
<% end %>
</p>
<% if quote.note.present? %>
<p style="margin:8px 0 0;color:#aaa;font-size:0.9rem"><%= t("billing.bank_transfer.quote_note", note: quote.note) %></p>
<% end %>
</div>