Class: Atol::Request::PostDocument::Sell::Body

Inherits:
Object
  • Object
show all
Defined in:
lib/atol/request/post_document/sell/body.rb

Instance Method Summary collapse

Constructor Details

#initialize(external_id:, phone: '', email: '', items:, payments: nil, config: nil, **options) ⇒ Body

Returns a new instance of Body.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/atol/request/post_document/sell/body.rb', line 11

def initialize(external_id:, phone: '', email: '', items:, payments: nil, config: nil, **options)
  raise(Atol::EmptyClientContactError) if phone.empty? && email.empty?
  raise(Atol::EmptySellItemsError) if items.empty?

  total = items.sum { |item| item[:sum] }
  validate_payments!(payments, total)

  @config = config || Atol.config
  @external_id = external_id
  @phone = phone
  @email = email
  @items = items
  @total = total
  @payments = payments
end

Instance Method Details

#to_hObject



27
28
29
# File 'lib/atol/request/post_document/sell/body.rb', line 27

def to_h
  build_body.clone
end

#to_json(*_args) ⇒ Object



31
32
33
# File 'lib/atol/request/post_document/sell/body.rb', line 31

def to_json(*_args)
  build_body.to_json
end