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.



51
52
53
54
55
56
57
58
59
60
# File 'lib/orange_data/receipt.rb', line 51

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.



165
166
167
# File 'lib/orange_data/receipt.rb', line 165

def additional_user_attribute
  @additional_user_attribute
end

#check_closeObject (readonly)

Returns the value of attribute check_close.



165
166
167
# File 'lib/orange_data/receipt.rb', line 165

def check_close
  @check_close
end

#positionsObject (readonly)

Returns the value of attribute positions.



165
166
167
# File 'lib/orange_data/receipt.rb', line 165

def positions
  @positions
end

Instance Method Details

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

Yields:

  • (payment)


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

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)


75
76
77
78
79
80
81
82
# File 'lib/orange_data/receipt.rb', line 75

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



63
64
65
# File 'lib/orange_data/receipt.rb', line 63

def raw_type
  @payload["type"]
end

#set_additional_user_attribute(**options) ⇒ Object



94
95
96
# File 'lib/orange_data/receipt.rb', line 94

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

#to_hashObject



67
68
69
70
71
72
73
# File 'lib/orange_data/receipt.rb', line 67

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