Class: Prawn::Receipt

Inherits:
Object
  • Object
show all
Includes:
View
Defined in:
lib/prawn/receipt.rb,
lib/prawn/receipt/version.rb

Constant Summary collapse

RECEIPTDATADIR =
File.expand_path '../../data', File.dirname(__FILE__)
VERSION =
"0.2.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Receipt

Returns a new instance of Receipt.



14
15
16
17
# File 'lib/prawn/receipt.rb', line 14

def initialize(options)
  @state = Hash[options.dup]
  build_receipt
end

Instance Attribute Details

#stateObject

Returns the value of attribute state.



12
13
14
# File 'lib/prawn/receipt.rb', line 12

def state
  @state
end

Instance Method Details

#build_receiptObject



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

def build_receipt
  image state.fetch(:logo_image_path),
    :position => :center, :width => 225
  #image "#{Prawn::Receipt::RECEIPTDATADIR}/pr-logo.png",
  #  :position => :center, :width => 225

  move_down 60

  font_size(20) do
    text "Receipt for your payment to #{state.fetch(:company_name)}", :align => :center
  end

  build_table

  font_size(16) do
    text "Your account is all paid up, thank you!", :align=> :center
  end

  bounding_box([0,30], :width => 72*7.5, :height => 30) do

    text "Your payment for your #{state.fetch(:company_name)} subscription has been successfully processed.", :align=> :center
    text "Please keep this receipt for your records. If you have questions, email <color rgb='0000ff'><u>#{state.fetch(:company_email)}</u><color>", :inline_format => true, :align=> :center

  end
end

#build_tableObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/prawn/receipt.rb', line 45

def build_table
  data = [
          ["Payment date", state.fetch(:payment_date) {Time.now.strftime "%B %e, %Y "}],
          ["Account billed", "$#{state.fetch(:amount_billed)} USD"],
          ["Account charged", "#{state.fetch(:customer_name)}(#{state.fetch(:customer_email)})"],
          ["Charged to", state.fetch(:credit_card)],
          ["Transaction ID", state.fetch(:transaction_id)]
         ]

  move_down 20

  table data, :row_colors => ["FFFFFF", "EDEEEE"],
              :position => :center,
              :width => 400 do |t|
    apply_common_styling(t, data.length)
  end



  move_down 20
end