Billing upgrade/downgrade, inviti in app e diretta YouTube da mobile.
Upgrade Stripe con addebito immediato; downgrade programmato a fine periodo. UX billing più sobria con box info; icone piani. API inviti e OAuth YouTube per staff trasmissione; deep link join; scelta partita programmata o nuova. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -96,16 +96,27 @@ module Public
|
||||
sub = @club.subscription
|
||||
|
||||
if sub&.stripe_subscription_id.present? && sub.active? &&
|
||||
sub.plan.slug == plan_slug && sub.billing_interval == interval
|
||||
sub.plan.slug == plan_slug && sub.billing_interval == interval && !sub.plan_change_pending?
|
||||
redirect_to public_club_billing_path(@club),
|
||||
notice: "Sei già su #{target_plan.name} (#{Billing::Stripe::PriceCatalog.label(plan_slug: plan_slug, interval: interval)})."
|
||||
return
|
||||
end
|
||||
|
||||
if sub&.stripe_subscription_id.present? && sub.active?
|
||||
Billing::Stripe::ChangePlan.call(club: @club, plan_slug: plan_slug, interval: interval)
|
||||
if sub&.plan_change_pending? && sub.pending_plan&.slug == plan_slug &&
|
||||
sub.pending_billing_interval == interval
|
||||
when_label = sub.current_period_end.present? ? I18n.l(sub.current_period_end, format: :long) : "il prossimo rinnovo"
|
||||
redirect_to public_club_billing_path(@club),
|
||||
notice: "Piano aggiornato a #{target_plan.name} (#{Billing::Stripe::PriceCatalog.label(plan_slug: plan_slug, interval: interval)}). Eventuale differenza gestita da Stripe."
|
||||
notice: "Il passaggio a #{target_plan.name} è già programmato dal #{when_label}."
|
||||
return
|
||||
end
|
||||
|
||||
if sub&.stripe_subscription_id.present? && sub.active?
|
||||
result = Billing::Stripe::ChangePlan.call(club: @club, plan_slug: plan_slug, interval: interval)
|
||||
redirect_to public_club_billing_path(@club),
|
||||
notice: Billing::Stripe::PlanChangeMessages.flash_notice(
|
||||
result,
|
||||
current_plan: sub.plan
|
||||
)
|
||||
else
|
||||
url = Billing::Stripe::CheckoutSession.new(
|
||||
club: @club, user: current_user, plan_slug: plan_slug, interval: interval
|
||||
|
||||
@@ -116,7 +116,7 @@ module Public
|
||||
end
|
||||
|
||||
def youtube_connect
|
||||
require_club_owner_for_team!(@team)
|
||||
require_youtube_connect_access!(@team)
|
||||
@team.entitlements.assert_can_connect_youtube!
|
||||
|
||||
if ENV["YOUTUBE_CLIENT_ID"].blank?
|
||||
@@ -124,7 +124,12 @@ module Public
|
||||
return
|
||||
end
|
||||
|
||||
state = Youtube::OauthState.for_team(team_id: @team.id, user_id: current_user.id)
|
||||
return_app = params[:return_app] == "1"
|
||||
state = Youtube::OauthState.for_team(
|
||||
team_id: @team.id,
|
||||
user_id: current_user.id,
|
||||
return_app: return_app
|
||||
)
|
||||
redirect_to Youtube::OauthUrl.build(state: state), allow_other_host: true
|
||||
rescue Teams::EntitlementError => e
|
||||
redirect_to public_team_details_path(@team), alert: e.message
|
||||
@@ -138,6 +143,13 @@ module Public
|
||||
|
||||
private
|
||||
|
||||
def require_youtube_connect_access!(team)
|
||||
return if team.club&.owned_by?(current_user)
|
||||
return if current_user.can_stream_for?(team)
|
||||
|
||||
redirect_to public_team_details_path(team), alert: "Accesso non consentito"
|
||||
end
|
||||
|
||||
def load_team_details!
|
||||
@club = @team.club
|
||||
@can_manage = @club.owned_by?(current_user)
|
||||
|
||||
Reference in New Issue
Block a user