atol 0.3 → 0.4
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/Gemfile.lock +2 -2
- data/README.md +2 -2
- data/lib/atol/request/get_document_state.rb +6 -11
- data/lib/atol/request/get_token.rb +1 -5
- data/lib/atol/request/post_document/item/body.rb +21 -9
- data/lib/atol/request/post_document/sell/body.rb +25 -20
- data/lib/atol/request/post_document.rb +12 -18
- data/lib/atol/transaction/get_document_state.rb +2 -6
- data/lib/atol/transaction/get_token.rb +1 -0
- data/lib/atol/transaction/post_document.rb +3 -7
- data/lib/atol/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43777b45ecaae54c9ad99454f9281423d8793cbc
|
4
|
+
data.tar.gz: 867efae667bc6acc6e601e651711eaf8c1ba56e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 608913a36f029a07911c48003a7191bfa34de6c37942559605155b3e503add8a6a4113995af0208a9ec7a05943cd1c1a0d0105dd067698aec9fdc2f380357d4d
|
7
|
+
data.tar.gz: 849b133128f46db62b5b1707a5986bd90fe2346d6f017cb5716e1fd478b4df1df34523723a366e7b24613b29ec375943a358618ba611402b322371821ca02ab2
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
# atol-rb
|
7
7
|
|
8
|
-
Пакет содержит набор классов для работы с [KaaS-сервисом АТОЛ-онлайн](https://online.atol.ru/) по [описанному протоколу](https://online.atol.ru/files
|
8
|
+
Пакет содержит набор классов для работы с [KaaS-сервисом АТОЛ-онлайн](https://online.atol.ru/) по [описанному протоколу](https://online.atol.ru/files/ffd/API_AO_v4.pdf).
|
9
9
|
|
10
10
|
##### Совместимость
|
11
11
|
|
12
|
-
Для корректной работы необходим интерпретатор Руби версии 2.2 и выше. Пакет работает с версией протокола
|
12
|
+
Для корректной работы необходим интерпретатор Руби версии 2.2 и выше. Пакет работает с версией протокола v4.
|
13
13
|
|
14
14
|
|
15
15
|
## Использование
|
@@ -9,22 +9,17 @@ module Atol
|
|
9
9
|
@config = config || Atol.config
|
10
10
|
raise(Atol::ConfigExpectedError) unless @config.is_a?(Atol::Config)
|
11
11
|
raise(Atol::MissingConfigError, 'group_code missing') if @config.group_code.nil?
|
12
|
-
|
13
|
-
@
|
14
|
-
@http_client = @config.http_client
|
12
|
+
@token = token
|
13
|
+
@uuid = uuid
|
15
14
|
end
|
16
15
|
|
17
16
|
def call
|
18
|
-
|
19
|
-
|
20
|
-
http =
|
17
|
+
http_client = @config.http_client
|
18
|
+
uri = URI("#{Atol::URL}/#{@config.group_code}/report/#{@uuid}")
|
19
|
+
http = http_client.new(uri.host, uri.port)
|
21
20
|
http.use_ssl = true
|
22
|
-
http.get(uri.request_uri)
|
21
|
+
http.get(uri.request_uri, 'Token' => @token)
|
23
22
|
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
attr_reader :url
|
28
23
|
end
|
29
24
|
end
|
30
25
|
end
|
@@ -27,16 +27,12 @@ module Atol
|
|
27
27
|
|
28
28
|
def call
|
29
29
|
uri = URI(Atol::URL + PATH)
|
30
|
-
uri.query = URI.encode_www_form(login: login, pass: password)
|
30
|
+
uri.query = URI.encode_www_form(login: @login, pass: @password)
|
31
31
|
|
32
32
|
http = @http_client.new(uri.host, uri.port)
|
33
33
|
http.use_ssl = true
|
34
34
|
http.get(uri.request_uri)
|
35
35
|
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
attr_reader :login, :password
|
40
36
|
end
|
41
37
|
end
|
42
38
|
end
|
@@ -6,20 +6,32 @@ module Atol
|
|
6
6
|
module Item
|
7
7
|
class Body
|
8
8
|
def initialize(name:, price:, quantity: 1, config: nil)
|
9
|
-
@config = config || Atol.config
|
10
|
-
|
11
9
|
raise Atol::ZeroItemQuantityError if quantity.to_i.zero?
|
12
10
|
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
16
|
-
@
|
17
|
-
@body[:sum] = (@body[:price] * @body[:quantity]).to_f.round(2)
|
18
|
-
@body[:tax] = @config.default_tax
|
11
|
+
@config = config || Atol.config
|
12
|
+
@name = name
|
13
|
+
@price = price.to_f
|
14
|
+
@quantity = quantity.to_f
|
19
15
|
end
|
20
16
|
|
21
17
|
def to_h
|
22
|
-
|
18
|
+
body.clone
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_json
|
22
|
+
body.to_json
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def body
|
28
|
+
@body ||= {
|
29
|
+
name: @name,
|
30
|
+
price: @price,
|
31
|
+
quantity: @quantity,
|
32
|
+
sum: (@price * @quantity).round(2),
|
33
|
+
tax: @config.default_tax
|
34
|
+
}
|
23
35
|
end
|
24
36
|
end
|
25
37
|
end
|
@@ -8,20 +8,12 @@ module Atol
|
|
8
8
|
def initialize(external_id:, phone: '', email: '', items:, config: nil)
|
9
9
|
raise(Atol::EmptyClientContactError) if phone.empty? && email.empty?
|
10
10
|
raise(Atol::EmptySellItemsError) if items.empty?
|
11
|
-
@config = config || Atol.config
|
12
|
-
|
13
|
-
@body = body_template
|
14
|
-
@body[:external_id] = external_id
|
15
|
-
@body[:receipt][:attributes][:email] = email unless email.empty?
|
16
|
-
@body[:receipt][:attributes][:phone] = phone unless phone.empty?
|
17
|
-
@body[:service][:callback_url] = @config.callback_url if @config.callback_url
|
18
11
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
@
|
24
|
-
@body[:receipt][:items] = items
|
12
|
+
@config = config || Atol.config
|
13
|
+
@external_id = external_id
|
14
|
+
@phone = phone
|
15
|
+
@email = email
|
16
|
+
@items = items
|
25
17
|
end
|
26
18
|
|
27
19
|
def to_h
|
@@ -34,28 +26,41 @@ module Atol
|
|
34
26
|
|
35
27
|
private
|
36
28
|
|
37
|
-
|
29
|
+
def body
|
30
|
+
@body ||= body_template.tap do |result|
|
31
|
+
result[:external_id] = @external_id
|
32
|
+
result[:receipt][:attributes][:email] = @email unless @email.empty?
|
33
|
+
result[:receipt][:attributes][:phone] = @phone unless @phone.empty?
|
34
|
+
result[:service][:callback_url] = @config.callback_url if @config.callback_url
|
35
|
+
|
36
|
+
total = @items.sum(0) { |item| item[:sum] }
|
37
|
+
|
38
|
+
result[:receipt][:total] = total
|
39
|
+
result[:receipt][:payments][0][:sum] = total
|
40
|
+
result[:receipt][:items] = @items
|
41
|
+
end
|
42
|
+
end
|
38
43
|
|
39
44
|
def body_template
|
40
|
-
|
45
|
+
{
|
41
46
|
receipt: {
|
42
47
|
attributes: {
|
43
|
-
sno: config.default_sno
|
48
|
+
sno: @config.default_sno
|
44
49
|
},
|
45
50
|
items: [],
|
46
51
|
payments: [
|
47
52
|
{
|
48
53
|
sum: 0,
|
49
|
-
type: config.default_payment_type
|
54
|
+
type: @config.default_payment_type
|
50
55
|
}
|
51
56
|
]
|
52
57
|
},
|
53
58
|
service: {
|
54
|
-
inn: config.inn.to_s,
|
55
|
-
payment_address: config.payment_address
|
59
|
+
inn: @config.inn.to_s,
|
60
|
+
payment_address: @config.payment_address
|
56
61
|
},
|
57
62
|
timestamp: Time.now.strftime(Atol::TIMESTAMP_FORMAT)
|
58
|
-
|
63
|
+
}
|
59
64
|
end
|
60
65
|
end
|
61
66
|
end
|
@@ -7,7 +7,7 @@ module Atol
|
|
7
7
|
module Request
|
8
8
|
class PostDocument
|
9
9
|
OPERATIONS = %i[sell sell_refund sell_correction buy buy_refund buy_correction].freeze
|
10
|
-
HEADERS = { 'Content-Type' => 'application/json' }.freeze
|
10
|
+
HEADERS = { 'Content-Type' => 'application/json; charset=utf-8' }.freeze
|
11
11
|
|
12
12
|
def initialize(operation:, token:, body:, config: nil, req_logger: nil, res_logger: nil)
|
13
13
|
@config = config || Atol.config
|
@@ -16,36 +16,30 @@ module Atol
|
|
16
16
|
raise(Atol::MissingConfigError, 'group_code missing') if @config.group_code.empty?
|
17
17
|
raise(Atol::UnknownOperationError, operation.to_s) unless OPERATIONS.include?(operation.to_sym)
|
18
18
|
|
19
|
-
@
|
19
|
+
@operation = operation
|
20
|
+
@token = token
|
20
21
|
@body = body
|
21
22
|
@req_logger = req_logger
|
22
23
|
@res_logger = res_logger
|
23
|
-
@http_client = @config.http_client
|
24
24
|
end
|
25
25
|
|
26
26
|
def call
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
http_client = @config.http_client
|
28
|
+
uri = URI("#{Atol::URL}/#{@config.group_code}/#{@operation}")
|
29
|
+
req_headers = HEADERS.merge(Token: @token)
|
30
|
+
req = http_client::Post.new(uri, req_headers)
|
31
|
+
req.body = @body
|
30
32
|
|
31
|
-
if req_logger.respond_to?(:call)
|
32
|
-
req_logger.call(req)
|
33
|
-
end
|
33
|
+
@req_logger.call(req) if @req_logger.respond_to?(:call)
|
34
34
|
|
35
|
-
res =
|
35
|
+
res = http_client.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
36
36
|
http.request(req)
|
37
37
|
end
|
38
|
-
|
39
|
-
if res_logger.respond_to?(:call)
|
40
|
-
res_logger.call(res)
|
41
|
-
end
|
38
|
+
|
39
|
+
@res_logger.call(res) if @res_logger.respond_to?(:call)
|
42
40
|
|
43
41
|
res
|
44
42
|
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
attr_reader :url, :body, :req_logger, :res_logger
|
49
43
|
end
|
50
44
|
end
|
51
45
|
end
|
@@ -7,11 +7,11 @@ module Atol
|
|
7
7
|
def initialize(uuid:, token:, config: nil)
|
8
8
|
@config = config || Atol.config
|
9
9
|
raise(Atol::ConfigExpectedError) unless @config.is_a?(Atol::Config)
|
10
|
-
@params =
|
10
|
+
@params = { uuid: uuid, token: token, config: @config }
|
11
11
|
end
|
12
12
|
|
13
13
|
def call
|
14
|
-
request = Atol::Request::GetDocumentState.new(params)
|
14
|
+
request = Atol::Request::GetDocumentState.new(@params)
|
15
15
|
response = request.call
|
16
16
|
encoded_body = response.body.force_encoding(Atol::ENCODING)
|
17
17
|
json = JSON.parse(encoded_body)
|
@@ -24,10 +24,6 @@ module Atol
|
|
24
24
|
raise(encoded_body)
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
attr_reader :params
|
31
27
|
end
|
32
28
|
end
|
33
29
|
end
|
@@ -7,18 +7,18 @@ module Atol
|
|
7
7
|
def initialize(operation:, token:, body:, config: nil, req_logger: nil, res_logger: nil)
|
8
8
|
@config = config || Atol.config
|
9
9
|
raise(Atol::ConfigExpectedError) unless @config.is_a?(Atol::Config)
|
10
|
-
@params =
|
10
|
+
@params = {
|
11
11
|
operation: operation,
|
12
12
|
token: token,
|
13
13
|
body: body,
|
14
14
|
config: config,
|
15
15
|
req_logger: req_logger,
|
16
16
|
res_logger: res_logger
|
17
|
-
|
17
|
+
}
|
18
18
|
end
|
19
19
|
|
20
20
|
def call
|
21
|
-
request = Atol::Request::PostDocument.new(params)
|
21
|
+
request = Atol::Request::PostDocument.new(@params)
|
22
22
|
response = request.call
|
23
23
|
encoded_body = response.body.force_encoding(Atol::ENCODING)
|
24
24
|
json = JSON.parse(encoded_body)
|
@@ -31,10 +31,6 @@ module Atol
|
|
31
31
|
raise(encoded_body)
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
attr_reader :params
|
38
34
|
end
|
39
35
|
end
|
40
36
|
end
|
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: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GeorgeGorbanev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: anyway_config
|