atol 0.7 → 0.8.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75f129f8ca6618beca5e44db35155e882818694663ee505b9800fedb4767d380
4
- data.tar.gz: 9035482fef46d4db6fbf99781251274fd12be69c6894074d97061b6b49d7976f
3
+ metadata.gz: a1486844075953dec57979f1ef563bc60376b75070f985ba25af3df74169b7ad
4
+ data.tar.gz: a9437ee9226697f12111b729f209cccec6493b86b30ddc3d8e75a36bc9ade358
5
5
  SHA512:
6
- metadata.gz: da49ef69b1c04f79adb7de75e49e45da3a33d313433de6589d3c92a55aa7fcac7df6cae0a9e0304ef85d54fbdd3349cb38f9581430d58af600d73a00ee9ea653
7
- data.tar.gz: 2c6ec17732b8172fdc1e2780dbaef84f13caf843020fa2c1a470a8bfea88686e2215c135f5bcbd16d6afec7084d08c6f03683103902a772631f48917f9955c9a
6
+ metadata.gz: 371bf235401d4c640906305848b3c10239ecd27306551156cc394393f827eb49538ebc75064325a0fbfb1b8743ce2432c0d9abf4297941e9fe56592f5565fd68
7
+ data.tar.gz: 2a1c729790dae84ed6466c1195915ca206b8027ae4930656bf401bd3da9cfb3c2d41eeab98672afbbf900e841c57f8a6b432488d4094cd9f78f7573ca74980a2
data/.rubocop.yml CHANGED
@@ -8,3 +8,7 @@ Style/Documentation:
8
8
 
9
9
  Metrics/LineLength:
10
10
  Max: 125
11
+
12
+ Metrics/ParameterLists:
13
+ Exclude:
14
+ - lib/atol/request/post_document/item/body.rb
data/.rubocop_todo.yml CHANGED
@@ -37,7 +37,7 @@ Layout/ExtraSpacing:
37
37
  # Cop supports --auto-correct.
38
38
  # Configuration parameters: IndentationWidth.
39
39
  # SupportedStyles: special_inside_parentheses, consistent, align_braces
40
- Layout/IndentHash:
40
+ Layout/FirstHashElementIndentation:
41
41
  EnforcedStyle: consistent
42
42
 
43
43
  # Offense count: 1
@@ -66,7 +66,7 @@ Layout/SpaceInsideHashLiteralBraces:
66
66
  # Cop supports --auto-correct.
67
67
  # Configuration parameters: EnforcedStyle.
68
68
  # SupportedStyles: final_newline, final_blank_line
69
- Layout/TrailingBlankLines:
69
+ Layout/TrailingEmptyLines:
70
70
  Exclude:
71
71
  - 'lib/atol.rb'
72
72
  - 'lib/atol/request.rb'
@@ -140,15 +140,6 @@ Style/BlockDelimiters:
140
140
  Exclude:
141
141
  - 'spec/atol/request/post_document/sell/body_spec.rb'
142
142
 
143
- # Offense count: 13
144
- # Cop supports --auto-correct.
145
- # Configuration parameters: EnforcedStyle.
146
- # SupportedStyles: braces, no_braces, context_dependent
147
- Style/BracesAroundHashParameters:
148
- Exclude:
149
- - 'spec/atol/transaction/get_token_spec.rb'
150
- - 'spec/atol/transaction/post_document_spec.rb'
151
-
152
143
  # Offense count: 1
153
144
  # Cop supports --auto-correct.
154
145
  # Configuration parameters: AutoCorrect, EnforcedStyle.
data/Gemfile CHANGED
@@ -3,8 +3,6 @@
3
3
  source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
- gem 'rubocop', require: false
7
-
8
6
  group :test do
9
7
  gem 'coveralls', require: false
10
8
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- atol (0.7)
4
+ atol (0.8.1)
5
5
  anyway_config (~> 1.0)
6
6
 
7
7
  GEM
@@ -10,7 +10,7 @@ GEM
10
10
  addressable (2.5.2)
11
11
  public_suffix (>= 2.0.2, < 4.0)
12
12
  anyway_config (1.1.3)
13
- ast (2.3.0)
13
+ ast (2.4.1)
14
14
  coveralls (0.8.21)
15
15
  json (>= 1.8, < 3)
16
16
  simplecov (~> 0.14.1)
@@ -23,13 +23,14 @@ GEM
23
23
  docile (1.1.5)
24
24
  hashdiff (0.3.7)
25
25
  json (2.1.0)
26
- parallel (1.12.1)
27
- parser (2.4.0.2)
28
- ast (~> 2.3)
29
- powerpack (0.1.1)
26
+ parallel (1.19.2)
27
+ parser (2.7.1.4)
28
+ ast (~> 2.4.1)
30
29
  public_suffix (3.0.1)
31
30
  rainbow (3.0.0)
32
31
  rake (13.0.1)
32
+ regexp_parser (1.7.1)
33
+ rexml (3.2.4)
33
34
  rspec (3.7.0)
34
35
  rspec-core (~> 3.7.0)
35
36
  rspec-expectations (~> 3.7.0)
@@ -43,14 +44,18 @@ GEM
43
44
  diff-lcs (>= 1.2.0, < 2.0)
44
45
  rspec-support (~> 3.7.0)
45
46
  rspec-support (3.7.0)
46
- rubocop (0.52.1)
47
+ rubocop (0.90.0)
47
48
  parallel (~> 1.10)
48
- parser (>= 2.4.0.2, < 3.0)
49
- powerpack (~> 0.1)
49
+ parser (>= 2.7.1.1)
50
50
  rainbow (>= 2.2.2, < 4.0)
51
+ regexp_parser (>= 1.7)
52
+ rexml
53
+ rubocop-ast (>= 0.3.0, < 1.0)
51
54
  ruby-progressbar (~> 1.7)
52
- unicode-display_width (~> 1.0, >= 1.0.1)
53
- ruby-progressbar (1.9.0)
55
+ unicode-display_width (>= 1.4.0, < 2.0)
56
+ rubocop-ast (0.4.0)
57
+ parser (>= 2.7.1.4)
58
+ ruby-progressbar (1.10.1)
54
59
  safe_yaml (1.0.4)
55
60
  simplecov (0.14.1)
56
61
  docile (~> 1.1.0)
@@ -61,7 +66,7 @@ GEM
61
66
  tins (~> 1.0)
62
67
  thor (0.19.4)
63
68
  tins (1.16.3)
64
- unicode-display_width (1.3.0)
69
+ unicode-display_width (1.7.0)
65
70
  webmock (3.2.1)
66
71
  addressable (>= 2.3.6)
67
72
  crack (>= 0.3.2)
@@ -76,8 +81,8 @@ DEPENDENCIES
76
81
  coveralls
77
82
  rake (~> 13.0)
78
83
  rspec (~> 3.0)
79
- rubocop
84
+ rubocop (~> 0.90)
80
85
  webmock (~> 3.0)
81
86
 
82
87
  BUNDLED WITH
83
- 1.17.3
88
+ 2.1.4
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  # atol-rb
7
7
 
8
- Пакет содержит набор классов для работы с [KaaS-сервисом АТОЛ-онлайн](https://online.atol.ru/) по [описанному протоколу](https://online.atol.ru/files/ffd/API_AO_v4.pdf).
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` и опциональный `quantity` (по умолчанию 1).
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
@@ -1,20 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'atol/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = 'atol'
9
- spec.version = Atol::Version::LIB
10
- spec.authors = ['GeorgeGorbanev']
11
- spec.email = ['GeorgeGorbanev@gmail.com']
8
+ spec.name = 'atol'
9
+ spec.version = Atol::Version::LIB
10
+ spec.authors = ['GeorgeGorbanev']
11
+ spec.email = ['GeorgeGorbanev@gmail.com']
12
12
 
13
- spec.summary = 'ATOL KaaS client for Ruby'
14
- spec.homepage = 'https://github.com/sputnik8/atol-rb'
15
- spec.license = 'MIT'
13
+ spec.summary = 'ATOL KaaS client for Ruby'
14
+ spec.homepage = 'https://github.com/sputnik8/atol-rb'
15
+ spec.license = 'MIT'
16
+ spec.required_ruby_version = '>= 2.5.0'
16
17
 
17
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
19
  f.match(%r{^(test|spec|features)/})
19
20
  end
20
21
 
@@ -27,6 +28,6 @@ Gem::Specification.new do |spec|
27
28
  spec.add_development_dependency 'bundler', '~> 1.15'
28
29
  spec.add_development_dependency 'rake', '~> 13.0'
29
30
  spec.add_development_dependency 'rspec', '~> 3.0'
30
- spec.add_development_dependency 'rubocop', '~> 0.52'
31
+ spec.add_development_dependency 'rubocop', '~> 0.90'
31
32
  spec.add_development_dependency 'webmock', '~> 3.0'
32
33
  end
data/lib/atol/errors.rb CHANGED
@@ -20,7 +20,7 @@ module Atol
20
20
  class ZeroItemQuantityError < StandardError; end
21
21
 
22
22
  ERRORS = Hash[
23
- 0 => BadJSONError,
23
+ 0 => BadJSONError,
24
24
  10 => IncomingMissingTokenError,
25
25
  11 => IncomingExpiredTokenError,
26
26
  20 => GroupCodeToTokenError,
@@ -11,6 +11,7 @@ module Atol
11
11
  @config = config || Atol.config
12
12
  raise(Atol::ConfigExpectedError) unless @config.is_a?(Atol::Config)
13
13
  raise(Atol::MissingConfigError, 'group_code missing') if @config.group_code.nil?
14
+
14
15
  @token = token
15
16
  @uuid = uuid
16
17
  end
@@ -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
- raise Atol::ZeroItemQuantityError if quantity.to_i.zero?
28
- raise BadPaymentMethodError unless PAYMENT_METHODS.include?(payment_method.to_s)
29
- raise BadPaymentObjectError unless PAYMENT_OBJECTS.include?(payment_object.to_s)
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 to_h
40
- body.clone
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 to_json
44
- body.to_json
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
- private
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,30 +16,29 @@ 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
22
23
  body.clone
23
24
  end
24
25
 
25
- def to_json
26
+ def to_json(*_args)
26
27
  body.to_json
27
28
  end
28
29
 
29
30
  private
30
31
 
31
32
  def body
32
- @body ||= body_template.tap do |result|
33
+ body_template.tap do |result|
34
+ receipt = result[:receipt]
35
+ client = receipt[:client]
36
+
33
37
  result[:external_id] = @external_id
34
- result[:receipt][:client][:email] = @email unless @email.empty?
35
- result[:receipt][:client][:phone] = @phone unless @phone.empty?
36
38
  result[:service][:callback_url] = @config.callback_url if @config.callback_url
37
39
 
38
- total = @items.inject(0) { |sum, item| sum += item[:sum] }
39
-
40
- result[:receipt][:total] = total
41
- result[:receipt][:payments][0][:sum] = total
42
- result[:receipt][:items] = @items
40
+ add_client_data(client)
41
+ add_receipt_data(receipt)
43
42
  end
44
43
  end
45
44
 
@@ -65,6 +64,27 @@ module Atol
65
64
  timestamp: Time.now.strftime(Atol::TIMESTAMP_FORMAT)
66
65
  }
67
66
  end
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
+
85
+ def total
86
+ @total ||= @items.inject(0) { |sum, item| sum += item[:sum] }
87
+ end
68
88
  end
69
89
  end
70
90
  end
@@ -9,6 +9,7 @@ module Atol
9
9
  def initialize(uuid:, token:, config: nil)
10
10
  @config = config || Atol.config
11
11
  raise(Atol::ConfigExpectedError) unless @config.is_a?(Atol::Config)
12
+
12
13
  @params = { uuid: uuid, token: token, config: @config }
13
14
  end
14
15
 
@@ -9,6 +9,7 @@ module Atol
9
9
  def initialize(operation:, token:, body:, config: nil, req_logger: nil, res_logger: nil)
10
10
  @config = config || Atol.config
11
11
  raise(Atol::ConfigExpectedError) unless @config.is_a?(Atol::Config)
12
+
12
13
  @params = {
13
14
  operation: operation,
14
15
  token: token,
data/lib/atol/version.rb CHANGED
@@ -3,6 +3,6 @@
3
3
  module Atol
4
4
  module Version
5
5
  API = 'v4'
6
- LIB = '0.7'
6
+ LIB = '0.8.1'
7
7
  end
8
8
  end
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.7'
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GeorgeGorbanev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-05 00:00:00.000000000 Z
11
+ date: 2023-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: anyway_config
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.52'
75
+ version: '0.90'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.52'
82
+ version: '0.90'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: webmock
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -138,15 +138,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
138
  requirements:
139
139
  - - ">="
140
140
  - !ruby/object:Gem::Version
141
- version: '0'
141
+ version: 2.5.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
- rubyforge_project:
149
- rubygems_version: 2.7.3
148
+ rubygems_version: 3.1.4
150
149
  signing_key:
151
150
  specification_version: 4
152
151
  summary: ATOL KaaS client for Ruby