Class: OrangeData::ReceiptContent

Inherits:
PayloadContent show all
Defined in:
lib/orange_data/receipt.rb

Defined Under Namespace

Classes: AdditionalUserAttribute, AgentInfo, CheckClose, Payment, Position, SupplierInfo

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from PayloadContent

#==, #as_json, #assign_attributes, #attributes, #to_json

Constructor Details

#initialize(payload = {}) ⇒ ReceiptContent

Returns a new instance of ReceiptContent.



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/orange_data/receipt.rb', line 70

def initialize(payload={})
  super(payload || {})
  # TODO: import...
  # TODO: taxationSystem default in checkclose
  @check_close = CheckClose.new(@payload['checkClose'])
  if @payload["additionalUserAttribute"]
    @additional_user_attribute = AdditionalUserAttribute.new(@payload["additionalUserAttribute"])
  end

  @positions = (@payload['positions'] || []).map{|pos| Position.new(pos) }
end

Instance Attribute Details

#additional_user_attributeObject (readonly)

Returns the value of attribute additional_user_attribute.



188
189
190
# File 'lib/orange_data/receipt.rb', line 188

def additional_user_attribute
  @additional_user_attribute
end

#check_closeObject (readonly)

Returns the value of attribute check_close.



188
189
190
# File 'lib/orange_data/receipt.rb', line 188

def check_close
  @check_close
end

#positionsObject (readonly)

Returns the value of attribute positions.



188
189
190
# File 'lib/orange_data/receipt.rb', line 188

def positions
  @positions
end

Instance Method Details

#add_payment(amount = nil, type = nil, **options) {|payment| ... } ⇒ Object

Yields:

  • (payment)


104
105
106
107
108
109
110
111
112
# File 'lib/orange_data/receipt.rb', line 104

def add_payment(amount=nil, type=nil, **options)
  payment = Payment.new
  payment.type = type if type
  payment.amount = amount if amount
  payment.assign_attributes(options)
  yield(payment) if block_given?
  check_close.payments << payment
  self
end

#add_position(text = nil, **options) {|pos| ... } ⇒ Object

Yields:

  • (pos)


95
96
97
98
99
100
101
102
# File 'lib/orange_data/receipt.rb', line 95

def add_position(text=nil, **options)
  pos = Position.new
  pos.text = text if text
  pos.assign_attributes(options)
  yield(pos) if block_given?
  positions << pos
  self
end

#raw_typeObject

сырой тип используется в qr_code



83
84
85
# File 'lib/orange_data/receipt.rb', line 83

def raw_type
  @payload["type"]
end

#set_additional_user_attribute(**options) ⇒ Object



114
115
116
# File 'lib/orange_data/receipt.rb', line 114

def set_additional_user_attribute(**options)
  @additional_user_attribute = AdditionalUserAttribute.new.assign_attributes(options)
end

#set_agent_info(**options) ⇒ Object



118
119
120
121
122
# File 'lib/orange_data/receipt.rb', line 118

def set_agent_info(**options)
  # agent info may have some validations/transformations, so
  agent_info = AgentInfo.new.assign_attributes(options)
  assign_attributes(agent_info.attributes.compact)
end

#to_hashObject



87
88
89
90
91
92
93
# File 'lib/orange_data/receipt.rb', line 87

def to_hash
  @payload.dup.tap{|h|
    h["positions"] = @positions.map(&:to_hash)
    h["checkClose"] = check_close.to_hash if check_close
    h["additionalUserAttribute"] = additional_user_attribute.to_hash if additional_user_attribute
  }
end