Module: Pay::Receipts

Defined in:
lib/pay/receipts.rb

Instance Method Summary collapse

Instance Method Details

#invoiceObject



46
47
48
# File 'lib/pay/receipts.rb', line 46

def invoice
  invoice_pdf.render
end

#invoice_filenameObject



42
43
44
# File 'lib/pay/receipts.rb', line 42

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

#invoice_pdf(**options) ⇒ Object



50
51
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
# 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.try(: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.
    },
    line_items: line_items
  }

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

#line_itemsObject



83
84
85
# File 'lib/pay/receipts.rb', line 83

def line_items
  line_items
end

#productObject



3
4
5
# File 'lib/pay/receipts.rb', line 3

def product
  Pay.application_name
end

#receiptObject



12
13
14
# File 'lib/pay/receipts.rb', line 12

def receipt
  receipt_pdf.render
end

#receipt_filenameObject Also known as: filename



7
8
9
# File 'lib/pay/receipts.rb', line 7

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

#receipt_pdf(**options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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.try(: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.
    },
    line_items: line_items
  }

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