Tutte le view marketing, legali, viewer, dashboard e admin usano t(); mailer utente-facing e flash localizzati; admin con LocaleResolver e selettore lingua. Co-authored-by: Cursor <cursoragent@cursor.com>
94 lines
3.0 KiB
Ruby
94 lines
3.0 KiB
Ruby
module Public
|
|
class ClubBillingController < WebBaseController
|
|
before_action :require_login!
|
|
before_action :set_club
|
|
before_action :require_club_owner_for_club!
|
|
|
|
def profile
|
|
end
|
|
|
|
def update_profile
|
|
@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")
|
|
else
|
|
redirect_to public_club_billing_path(@club), notice: t("flash.club_billing.profile_updated")
|
|
end
|
|
else
|
|
flash.now[:alert] = @club.errors.full_messages.join(", ")
|
|
render :profile, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def cancel_subscription
|
|
unless MatchLiveTv.stripe_enabled?
|
|
redirect_to public_club_billing_path(@club), alert: t("flash.club_billing.stripe_not_configured")
|
|
return
|
|
end
|
|
|
|
Billing::Stripe::CancelSubscription.call(club: @club)
|
|
sub = @club.subscription.reload
|
|
date = sub.current_period_end ? helpers.l_local(sub.current_period_end.to_date) : t("billing.subscription_status.end_of_period")
|
|
redirect_to public_club_billing_path(@club),
|
|
notice: t("flash.club_billing.subscription_canceled", date: date)
|
|
rescue ArgumentError, RuntimeError => e
|
|
redirect_to public_club_billing_path(@club), alert: e.message
|
|
rescue ::Stripe::StripeError => e
|
|
redirect_to public_club_billing_path(@club), alert: t("flash.club_billing.stripe_error", message: e.message)
|
|
end
|
|
|
|
def download_invoice
|
|
invoice = @club.billing_invoices.find(params[:invoice_id])
|
|
unless invoice.pdf.attached?
|
|
redirect_to public_club_billing_path(@club), alert: t("flash.club_billing.invoice_pdf_unavailable")
|
|
return
|
|
end
|
|
|
|
redirect_to rails_blob_path(invoice.pdf, disposition: "attachment"), allow_other_host: true
|
|
end
|
|
|
|
private
|
|
|
|
def set_club
|
|
@club = current_user.owned_clubs.find(params[:id])
|
|
end
|
|
|
|
def require_club_owner_for_club!
|
|
require_club_owner!(@club)
|
|
end
|
|
|
|
def premium_checkout_return_params
|
|
plan = params[:plan].presence_in(%w[premium_light premium_full])
|
|
return nil if plan.blank?
|
|
|
|
{
|
|
plan: plan,
|
|
interval: params[:interval].presence || Billing::Stripe::PriceCatalog::DEFAULT_INTERVAL
|
|
}
|
|
end
|
|
|
|
def billing_profile_params
|
|
params.require(:club).permit(
|
|
:billing_entity_type,
|
|
:billing_legal_name,
|
|
:billing_vat_number,
|
|
:billing_fiscal_code,
|
|
:billing_email,
|
|
:billing_phone,
|
|
:billing_address_line,
|
|
:billing_city,
|
|
:billing_province,
|
|
:billing_postal_code,
|
|
:billing_country,
|
|
:billing_recipient_code,
|
|
:billing_pec
|
|
)
|
|
end
|
|
end
|
|
end
|