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

#==, #assign_attributes, #to_json

Constructor Details

#initialize(payload = {}) ⇒ ReceiptContent

Returns a new instance of ReceiptContent.



156
157
158
159
160
161
162
163
164
165
# File 'lib/orange_data/receipt.rb', line 156

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

Instance Attribute Details

#additional_user_attributeObject (readonly)

Returns the value of attribute additional_user_attribute.



282
283
284
# File 'lib/orange_data/receipt.rb', line 282

def additional_user_attribute
  @additional_user_attribute
end

#check_closeObject (readonly)

Returns the value of attribute check_close.



282
283
284
# File 'lib/orange_data/receipt.rb', line 282

def check_close
  @check_close
end

#positionsObject (readonly)

Returns the value of attribute positions.



282
283
284
# File 'lib/orange_data/receipt.rb', line 282

def positions
  @positions
end

Instance Method Details

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

Yields:

  • (payment)


189
190
191
192
193
194
195
196
197
# File 'lib/orange_data/receipt.rb', line 189

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)


180
181
182
183
184
185
186
187
# File 'lib/orange_data/receipt.rb', line 180

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



168
169
170
# File 'lib/orange_data/receipt.rb', line 168

def raw_type
  @payload["type"]
end

#set_additional_user_attribute(**options) ⇒ Object



199
200
201
# File 'lib/orange_data/receipt.rb', line 199

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

#to_hashObject



172
173
174
175
176
177
178
# File 'lib/orange_data/receipt.rb', line 172

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