module Pay::Receipts

Public Instance Methods

filename()
Alias for: receipt_filename
invoice() click to toggle source
# File lib/pay/receipts.rb, line 46
def invoice
  invoice_pdf.render
end
invoice_filename() click to toggle source
# File lib/pay/receipts.rb, line 42
def invoice_filename
  "invoice-#{created_at.strftime("%Y-%m-%d")}.pdf"
end
invoice_pdf(**options) click to toggle source
# File lib/pay/receipts.rb, line 50
def invoice_pdf(**options)
  bill_to = [customer.owner.name]
  bill_to += [customer.owner.extra_billing_info] if customer.owner.extra_billing_info?
  bill_to += [nil, customer.owner.email]

  total = Pay::Currency.format(amount, currency: currency)

  line_items = [
    ["<b>#{I18n.t("pay.invoice.product")}</b>", nil, "<b>#{I18n.t("pay.invoice.amount")}</b>"],
    [product, nil, total],
    [nil, I18n.t("pay.invoice.subtotal"), total],
    [nil, I18n.t("pay.invoice.total"), total]
  ]

  defaults = {
    id: id,
    issue_date: I18n.l(created_at, format: :long),
    due_date: I18n.l(created_at, format: :long),
    status: "<b><color rgb='#5eba7d'>#{I18n.t("pay.receipt.paid").upcase}</color></b>",
    bill_to: bill_to,
    product: product,
    company: {
      name: Pay.business_name,
      address: Pay.business_address,
      email: Pay.support_email,
      logo: Pay.business_logo
    },
    line_items: line_items
  }

  ::Receipts::Invoice.new(defaults.deep_merge(options))
end
line_items() click to toggle source
# File lib/pay/receipts.rb, line 83
def line_items
  line_items
end
product() click to toggle source
# File lib/pay/receipts.rb, line 3
def product
  Pay.application_name
end
receipt() click to toggle source
# File lib/pay/receipts.rb, line 12
def receipt
  receipt_pdf.render
end
receipt_filename() click to toggle source
# File lib/pay/receipts.rb, line 7
def receipt_filename
  "receipt-#{created_at.strftime("%Y-%m-%d")}.pdf"
end
Also aliased as: filename
receipt_pdf(**options) click to toggle source
# File lib/pay/receipts.rb, line 16
def receipt_pdf(**options)
  line_items = [
    [I18n.t("pay.receipt.date"), I18n.l(created_at, format: :long)],
    [I18n.t("pay.receipt.account_billed"), "#{customer.customer_name} (#{customer.email})"],
    [I18n.t("pay.receipt.product"), product],
    [I18n.t("pay.receipt.amount"), Pay::Currency.format(amount, currency: currency)],
    [I18n.t("pay.receipt.charged_to"), charged_to]
  ]
  line_items << [I18n.t("pay.receipt.additional_info"), customer.owner.extra_billing_info] if customer.owner.extra_billing_info?
  line_items << [I18n.t("pay.receipt.refunded"), Pay::Currency.format(amount_refunded, currency: currency)] if refunded?

  defaults = {
    id: id,
    product: product,
    company: {
      name: Pay.business_name,
      address: Pay.business_address,
      email: Pay.support_email,
      logo: Pay.business_logo
    },
    line_items: line_items
  }

  ::Receipts::Receipt.new(defaults.deep_merge(options))
end