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>
42 lines
1.1 KiB
Ruby
42 lines
1.1 KiB
Ruby
module Billing
|
|
class InvoiceMailer < ApplicationMailer
|
|
def invoice_pdf
|
|
@invoice = params[:invoice]
|
|
@club = @invoice.club
|
|
|
|
I18n.with_locale(I18n.locale) do
|
|
attach_invoice_pdf!
|
|
mail(
|
|
to: @club.billing_email,
|
|
subject: t("mailers.invoice.subject", number: @invoice.display_number)
|
|
)
|
|
end
|
|
end
|
|
|
|
def plan_activated_with_invoice
|
|
@invoice = params[:invoice]
|
|
@club = @invoice.club
|
|
|
|
I18n.with_locale(I18n.locale) do
|
|
attach_invoice_pdf!
|
|
mail(
|
|
to: @club.billing_email,
|
|
subject: t("mailers.invoice_activated.subject",
|
|
plan: @club.subscription&.plan&.name || @invoice.display_number,
|
|
number: @invoice.display_number)
|
|
)
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def attach_invoice_pdf!
|
|
prefix = t("mailers.invoice.attachment_prefix")
|
|
attachments["#{prefix}-#{@invoice.number.parameterize}.pdf"] = {
|
|
mime_type: "application/pdf",
|
|
content: @invoice.pdf.download
|
|
}
|
|
end
|
|
end
|
|
end
|