Module: Pay::Receipts

Includes:
ActionView::Helpers::NumberHelper
Defined in:
lib/pay/receipts.rb

Instance Method Summary collapse

Instance Method Details

#invoiceObject



48
49
50
# File 'lib/pay/receipts.rb', line 48

def invoice
  invoice_pdf.render
end

#invoice_filenameObject



44
45
46
# File 'lib/pay/receipts.rb', line 44

def invoice_filename
  "invoice-#{created_at.strftime("%Y-%m-%d")}.pdf"
end

#invoice_pdf(**options) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/pay/receipts.rb', line 52

def invoice_pdf(**options)
  bill_to = [owner.name]
  bill_to += [owner.extra_billing_info] if owner.extra_billing_info?
  bill_to += [nil, owner.email]

  total = ActionController::Base.helpers.number_to_currency(amount / 100.0)

  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.
    },
    line_items: line_items
  }

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

#line_itemsObject



85
86
87
# File 'lib/pay/receipts.rb', line 85

def line_items
  line_items
end

#productObject



5
6
7
# File 'lib/pay/receipts.rb', line 5

def product
  Pay.application_name
end

#receiptObject



14
15
16
# File 'lib/pay/receipts.rb', line 14

def receipt
  receipt_pdf.render
end

#receipt_filenameObject Also known as: filename



9
10
11
# File 'lib/pay/receipts.rb', line 9

def receipt_filename
  "receipt-#{created_at.strftime("%Y-%m-%d")}.pdf"
end

#receipt_pdf(**options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pay/receipts.rb', line 18

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"), number_to_currency(amount / 100.0)],
    [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"), number_to_currency(amount_refunded / 100.0)] if refunded?

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

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