Class: Fb::Messenger::Template::Receipt

Inherits:
Object
  • Object
show all
Defined in:
lib/fb/messenger/templates/receipt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Receipt

Returns a new instance of Receipt.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fb/messenger/templates/receipt.rb', line 9

def initialize(opts = {})
  @recipient_name = opts[:recipient_name]
  @order_number = opts[:order_number]
  @currency = opts[:currency]
  # payment_method field cannot be nil
  @payment_method = opts[:payment_method] || 'N/A'
  @order_url = opts[:order_url]
  @timestamp = opts[:timestamp]
  @total_cost = opts[:total_cost]
  @receipt_items = opts[:receipt_items] || []
end

Instance Attribute Details

#currencyObject

Returns the value of attribute currency.



5
6
7
# File 'lib/fb/messenger/templates/receipt.rb', line 5

def currency
  @currency
end

#order_numberObject

Returns the value of attribute order_number.



5
6
7
# File 'lib/fb/messenger/templates/receipt.rb', line 5

def order_number
  @order_number
end

#order_urlObject

Returns the value of attribute order_url.



6
7
8
# File 'lib/fb/messenger/templates/receipt.rb', line 6

def order_url
  @order_url
end

#payment_methodObject

Returns the value of attribute payment_method.



6
7
8
# File 'lib/fb/messenger/templates/receipt.rb', line 6

def payment_method
  @payment_method
end

#receipt_itemsObject

Returns the value of attribute receipt_items.



7
8
9
# File 'lib/fb/messenger/templates/receipt.rb', line 7

def receipt_items
  @receipt_items
end

#recipient_nameObject

Returns the value of attribute recipient_name.



5
6
7
# File 'lib/fb/messenger/templates/receipt.rb', line 5

def recipient_name
  @recipient_name
end

#timestampObject

Returns the value of attribute timestamp.



6
7
8
# File 'lib/fb/messenger/templates/receipt.rb', line 6

def timestamp
  @timestamp
end

#total_costObject

Returns the value of attribute total_cost.



7
8
9
# File 'lib/fb/messenger/templates/receipt.rb', line 7

def total_cost
  @total_cost
end

Instance Method Details

#templateObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fb/messenger/templates/receipt.rb', line 21

def template
  {
    attachment: {
      type: 'template',
      payload: {
        template_type: 'receipt',
        recipient_name: recipient_name,
        order_number: order_number,
        currency: currency,
        payment_method: payment_method, # required field
        order_url: order_url,
        timestamp: timestamp,
        elements: receipt_items.map(&:template),
        summary: {
          total_cost: total_cost
        }
      }
    }
  }
end