lib/atol/request/post_document/item/body.rb in atol-0.4.2 vs lib/atol/request/post_document/item/body.rb in atol-0.5.0
- old
+ new
@@ -3,17 +3,37 @@
module Atol
module Request
class PostDocument
module Item
class Body
- def initialize(name:, price:, quantity: 1, config: nil)
+ BadPaymentMethodError = Class.new(StandardError)
+ BadPaymentObjectError = Class.new(StandardError)
+
+ PAYMENT_METHODS = [
+ 'full_prepayment', 'prepayment', 'advance', 'full_payment',
+ 'partial_payment', 'credit', 'credit_payment'
+ ]
+
+ PAYMENT_OBJECTS = [
+ 'commodity', 'excise', 'job', 'service', 'gambling_bet', 'gambling_prize',
+ 'lottery', 'lottery_prize', 'intellectual_activity', 'payment', 'agent_commission',
+ 'composite', 'another'
+ ]
+
+ attr_accessor :config, :name, :price, :quantity, :payment_method, :payment_object
+
+ def initialize(config: nil, name:, price:, quantity: 1, payment_method:, payment_object:)
raise Atol::ZeroItemQuantityError if quantity.to_i.zero?
+ raise BadPaymentMethodError unless PAYMENT_METHODS.include?(payment_method.to_s)
+ raise BadPaymentObjectError unless PAYMENT_OBJECTS.include?(payment_object.to_s)
- @config = config || Atol.config
- @name = name
- @price = price.to_f
- @quantity = quantity.to_f
+ self.config = config || Atol.config
+ self.name = name
+ self.price = price.to_f
+ self.quantity = quantity.to_f
+ self.payment_method = payment_method.to_s
+ self.payment_object = payment_object.to_s
end
def to_h
body.clone
end
@@ -24,14 +44,16 @@
private
def body
@body ||= {
- name: @name,
- price: @price,
- quantity: @quantity,
- sum: (@price * @quantity).round(2),
- tax: @config.default_tax
+ name: name,
+ price: price,
+ quantity: quantity,
+ sum: (price * quantity).round(2),
+ tax: config.default_tax,
+ payment_method: payment_method,
+ payment_object: payment_object
}
end
end
end
end