atol 0.7.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/Gemfile.lock +2 -2
- data/README.md +9 -3
- data/atol-rb.gemspec +1 -1
- data/lib/atol/request/post_document/item/body.rb +36 -11
- data/lib/atol/request/post_document/sell/body.rb +22 -5
- data/lib/atol/transaction/get_document_state.rb +1 -1
- data/lib/atol/transaction/post_document.rb +1 -1
- data/lib/atol/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 739a43f61f1406eeeb5ef5233e3788c7609d9d480fbe1dfab694073b200e181e
|
4
|
+
data.tar.gz: f967cee6aeb248b5c00217d9548cbd671d771bfc94d4d1d1840b747b36dcb205
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc2d5a6482f6856b7700602148b29698b1b362e004255a28fa27a7cd6b903349ec2d7c33f10c38a31c3b6c98d4f3bed70537fdc2cb69d92edc4b19e78586f73a
|
7
|
+
data.tar.gz: 303cf4af75af283fc6b0917ce4a5f8c7d081c4f4e776b9f5120170e63ed8a6b78a0dddda4d7ab8c516f768c459048a82f2dba632eb4feee61f58e0ec80e1d83c
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
# atol-rb
|
7
7
|
|
8
|
-
Пакет содержит набор классов для работы с [KaaS-сервисом АТОЛ-онлайн](https://online.atol.ru/) по [описанному протоколу](https://
|
8
|
+
Пакет содержит набор классов для работы с [KaaS-сервисом АТОЛ-онлайн](https://online.atol.ru/) по [описанному протоколу](https://atol.online/upload/iblock/dff/4yjidqijkha10vmw9ee1jjqzgr05q8jy/API_atol_online_v4.pdf).
|
9
9
|
|
10
10
|
##### Совместимость
|
11
11
|
|
@@ -151,14 +151,20 @@ body = Atol::Request::PostDocument::Sell::Body.new(
|
|
151
151
|
email: 'example@example.com',
|
152
152
|
items: [
|
153
153
|
...
|
154
|
-
]
|
154
|
+
],
|
155
|
+
agent_info_type: 'bank_paying_agent'
|
155
156
|
).to_json
|
156
157
|
```
|
158
|
+
|
159
|
+
`agent_info_type` опциональный аргумент - признак агента (тег ФФД - 1057)
|
160
|
+
|
157
161
|
Массив `items` должен включать в себя объекты, которые так же соответствуют схеме.
|
158
162
|
|
159
163
|
Для создания `items` можно использовать класс `Atol::Request::PostDocument::Item::Body`.
|
160
164
|
|
161
|
-
Его конструктор принимает обязательные аргументы `name`, `price`, `payment_method`, `payment_object` и
|
165
|
+
Его конструктор принимает обязательные аргументы `name`, `price`, `payment_method`, `payment_object` и опциональные `quantity` (по умолчанию 1), `supplier_info_inn`, `supplier_info_name`, `agent_info_type` (тег ФФД - 1222).
|
166
|
+
|
167
|
+
`supplier_info_inn` обязателен, если передан `agent_info_type`.
|
162
168
|
|
163
169
|
Допустимые значения `payment_method`:
|
164
170
|
```ruby
|
data/atol-rb.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.summary = 'ATOL KaaS client for Ruby'
|
14
14
|
spec.homepage = 'https://github.com/sputnik8/atol-rb'
|
15
15
|
spec.license = 'MIT'
|
16
|
-
spec.required_ruby_version = '>=
|
16
|
+
spec.required_ruby_version = '>= 3.0.0'
|
17
17
|
|
18
18
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
19
|
f.match(%r{^(test|spec|features)/})
|
@@ -21,30 +21,55 @@ module Atol
|
|
21
21
|
'composite', 'another'
|
22
22
|
]
|
23
23
|
|
24
|
-
attr_accessor :config, :name, :price, :quantity, :payment_method, :payment_object
|
24
|
+
attr_accessor :config, :name, :price, :quantity, :payment_method, :payment_object,
|
25
|
+
:agent_info_type, :supplier_info_inn, :supplier_info_name
|
25
26
|
|
26
|
-
def initialize(config: nil, name:, price:, quantity: 1, payment_method:, payment_object
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
def initialize(config: nil, name:, price:, quantity: 1, payment_method:, payment_object:, **options)
|
28
|
+
setup_attributes(config, name, price, quantity, payment_method, payment_object, options)
|
29
|
+
validate_attributes
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_h
|
33
|
+
body.clone
|
34
|
+
end
|
30
35
|
|
36
|
+
def to_json(*_args)
|
37
|
+
body.to_json
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def setup_attributes(config, name, price, quantity, payment_method, payment_object, options)
|
31
43
|
self.config = config || Atol.config
|
32
44
|
self.name = name
|
33
45
|
self.price = price.to_f
|
34
46
|
self.quantity = quantity.to_f
|
35
47
|
self.payment_method = payment_method.to_s
|
36
48
|
self.payment_object = payment_object.to_s
|
49
|
+
self.agent_info_type = options[:agent_info_type].to_s
|
50
|
+
self.supplier_info_inn = options[:supplier_info_inn].to_s
|
51
|
+
self.supplier_info_name = options[:supplier_info_name].to_s
|
37
52
|
end
|
38
53
|
|
39
|
-
def
|
40
|
-
|
54
|
+
def validate_attributes
|
55
|
+
raise Atol::ZeroItemQuantityError if quantity.to_f.zero?
|
56
|
+
raise BadPaymentMethodError unless PAYMENT_METHODS.include?(payment_method)
|
57
|
+
raise BadPaymentObjectError unless PAYMENT_OBJECTS.include?(payment_object)
|
41
58
|
end
|
42
59
|
|
43
|
-
def
|
44
|
-
|
60
|
+
def agent_info
|
61
|
+
return if agent_info_type.nil? || agent_info_type.empty?
|
62
|
+
|
63
|
+
{ agent_info: { type: agent_info_type } }
|
45
64
|
end
|
46
65
|
|
47
|
-
|
66
|
+
def supplier_info
|
67
|
+
return if supplier_info_inn.nil? || supplier_info_inn.empty? || agent_info.nil?
|
68
|
+
|
69
|
+
info = { inn: supplier_info_inn, name: supplier_info_name }
|
70
|
+
filtered_info = info.reject { |_key, value| value&.empty? }
|
71
|
+
{ supplier_info: filtered_info } unless filtered_info.empty?
|
72
|
+
end
|
48
73
|
|
49
74
|
def body
|
50
75
|
@body ||= {
|
@@ -55,7 +80,7 @@ module Atol
|
|
55
80
|
tax: config.default_tax,
|
56
81
|
payment_method: payment_method,
|
57
82
|
payment_object: payment_object
|
58
|
-
}
|
83
|
+
}.merge(supplier_info.to_h, agent_info.to_h)
|
59
84
|
end
|
60
85
|
end
|
61
86
|
end
|
@@ -7,7 +7,7 @@ module Atol
|
|
7
7
|
class PostDocument
|
8
8
|
module Sell
|
9
9
|
class Body
|
10
|
-
def initialize(external_id:, phone: '', email: '', items:, config: nil)
|
10
|
+
def initialize(external_id:, phone: '', email: '', items:, config: nil, **options)
|
11
11
|
raise(Atol::EmptyClientContactError) if phone.empty? && email.empty?
|
12
12
|
raise(Atol::EmptySellItemsError) if items.empty?
|
13
13
|
|
@@ -16,6 +16,7 @@ module Atol
|
|
16
16
|
@phone = phone
|
17
17
|
@email = email
|
18
18
|
@items = items
|
19
|
+
@agent_info_type = options[:agent_info_type]
|
19
20
|
end
|
20
21
|
|
21
22
|
def to_h
|
@@ -32,13 +33,12 @@ module Atol
|
|
32
33
|
body_template.tap do |result|
|
33
34
|
receipt = result[:receipt]
|
34
35
|
client = receipt[:client]
|
36
|
+
|
35
37
|
result[:external_id] = @external_id
|
36
|
-
client[:email] = @email unless @email.empty?
|
37
|
-
client[:phone] = @phone unless @phone.empty?
|
38
38
|
result[:service][:callback_url] = @config.callback_url if @config.callback_url
|
39
39
|
|
40
|
-
|
41
|
-
receipt
|
40
|
+
add_client_data(client)
|
41
|
+
add_receipt_data(receipt)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -65,6 +65,23 @@ module Atol
|
|
65
65
|
}
|
66
66
|
end
|
67
67
|
|
68
|
+
def add_client_data(client)
|
69
|
+
client[:email] = @email unless @email.empty?
|
70
|
+
client[:phone] = @phone unless @phone.empty?
|
71
|
+
end
|
72
|
+
|
73
|
+
def add_receipt_data(receipt)
|
74
|
+
receipt[:total] = receipt[:payments][0][:sum] = total
|
75
|
+
receipt[:items] = @items
|
76
|
+
add_agent_and_supplier_info(receipt)
|
77
|
+
end
|
78
|
+
|
79
|
+
def add_agent_and_supplier_info(receipt)
|
80
|
+
return if @agent_info_type.nil? || @agent_info_type.empty?
|
81
|
+
|
82
|
+
receipt[:agent_info] = { type: @agent_info_type }
|
83
|
+
end
|
84
|
+
|
68
85
|
def total
|
69
86
|
@total ||= @items.inject(0) { |sum, item| sum += item[:sum] }
|
70
87
|
end
|
@@ -14,7 +14,7 @@ module Atol
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def call
|
17
|
-
request = Atol::Request::GetDocumentState.new(
|
17
|
+
request = Atol::Request::GetDocumentState.new(**@params)
|
18
18
|
response = request.call
|
19
19
|
encoded_body = response.body.dup.force_encoding(Atol::ENCODING)
|
20
20
|
json = JSON.parse(encoded_body)
|
@@ -21,7 +21,7 @@ module Atol
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def call
|
24
|
-
request = Atol::Request::PostDocument.new(
|
24
|
+
request = Atol::Request::PostDocument.new(**@params)
|
25
25
|
response = request.call
|
26
26
|
encoded_body = response.body.dup.force_encoding(Atol::ENCODING)
|
27
27
|
json = JSON.parse(encoded_body)
|
data/lib/atol/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GeorgeGorbanev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: anyway_config
|
@@ -138,14 +138,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
138
|
requirements:
|
139
139
|
- - ">="
|
140
140
|
- !ruby/object:Gem::Version
|
141
|
-
version:
|
141
|
+
version: 3.0.0
|
142
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
143
|
requirements:
|
144
144
|
- - ">="
|
145
145
|
- !ruby/object:Gem::Version
|
146
146
|
version: '0'
|
147
147
|
requirements: []
|
148
|
-
rubygems_version: 3.0.3
|
148
|
+
rubygems_version: 3.0.3.1
|
149
149
|
signing_key:
|
150
150
|
specification_version: 4
|
151
151
|
summary: ATOL KaaS client for Ruby
|