Class: MessageQuickly::Messaging::ReceiptTemplateAttachment

Inherits:
TemplateAttachment show all
Defined in:
lib/message_quickly/messaging/receipt_template_attachment.rb

Instance Attribute Summary collapse

Attributes inherited from TemplateAttachment

#template_type

Attributes inherited from Attachment

#payload, #type

Instance Method Summary collapse

Methods inherited from Attachment

#file?

Constructor Details

#initialize(params = {}) ⇒ ReceiptTemplateAttachment

Returns a new instance of ReceiptTemplateAttachment.



7
8
9
10
11
12
13
14
# File 'lib/message_quickly/messaging/receipt_template_attachment.rb', line 7

def initialize(params = {})
  self.elements ||= []
  self.address ||= Receipt::Address.new
  self.summary ||= Receipt::Summary.new
  self.adjustments ||= []
  params['template_type'] ||= 'receipt'
  super(params)
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



5
6
7
# File 'lib/message_quickly/messaging/receipt_template_attachment.rb', line 5

def address
  @address
end

#adjustmentsObject

Returns the value of attribute adjustments.



5
6
7
# File 'lib/message_quickly/messaging/receipt_template_attachment.rb', line 5

def adjustments
  @adjustments
end

#currencyObject

Returns the value of attribute currency.



5
6
7
# File 'lib/message_quickly/messaging/receipt_template_attachment.rb', line 5

def currency
  @currency
end

#elementsObject

Returns the value of attribute elements.



5
6
7
# File 'lib/message_quickly/messaging/receipt_template_attachment.rb', line 5

def elements
  @elements
end

#order_numberObject

Returns the value of attribute order_number.



5
6
7
# File 'lib/message_quickly/messaging/receipt_template_attachment.rb', line 5

def order_number
  @order_number
end

#order_urlObject

Returns the value of attribute order_url.



5
6
7
# File 'lib/message_quickly/messaging/receipt_template_attachment.rb', line 5

def order_url
  @order_url
end

#payment_methodObject

Returns the value of attribute payment_method.



5
6
7
# File 'lib/message_quickly/messaging/receipt_template_attachment.rb', line 5

def payment_method
  @payment_method
end

#recipient_nameObject

Returns the value of attribute recipient_name.



5
6
7
# File 'lib/message_quickly/messaging/receipt_template_attachment.rb', line 5

def recipient_name
  @recipient_name
end

#summaryObject

Returns the value of attribute summary.



5
6
7
# File 'lib/message_quickly/messaging/receipt_template_attachment.rb', line 5

def summary
  @summary
end

#timestampObject

Returns the value of attribute timestamp.



5
6
7
# File 'lib/message_quickly/messaging/receipt_template_attachment.rb', line 5

def timestamp
  @timestamp
end

Instance Method Details

#build_address {|address| ... } ⇒ Object

Yields:



20
21
22
# File 'lib/message_quickly/messaging/receipt_template_attachment.rb', line 20

def build_address
  yield address
end

#build_adjustmentObject



28
29
30
# File 'lib/message_quickly/messaging/receipt_template_attachment.rb', line 28

def build_adjustment
  adjustments << Receipt::Adjustment.new.tap { |adjustment| yield adjustment }
end

#build_elementObject



16
17
18
# File 'lib/message_quickly/messaging/receipt_template_attachment.rb', line 16

def build_element
  elements << Receipt::Element.new.tap { |element| yield element }
end

#build_summary {|summary| ... } ⇒ Object

Yields:



24
25
26
# File 'lib/message_quickly/messaging/receipt_template_attachment.rb', line 24

def build_summary
  yield summary
end

#to_hashObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/message_quickly/messaging/receipt_template_attachment.rb', line 32

def to_hash
  {
    type: type,
    payload: {
      template_type: template_type,
      recipient_name: recipient_name,
      order_number: order_number,
      currency: currency,
      payment_method: payment_method,
      order_url: order_url,
      timestamp: timestamp,
      elements: elements.collect { |element| element.to_hash },
      address: address.to_hash,
      summary: summary.to_hash,
      adjustments: adjustments.collect { |adjustment| adjustment.to_hash }
    }
  }
end