atol 0.5.0 → 0.5.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
- SHA1:
3
- metadata.gz: dadf4b469fa9fa9b1489d00b72d057b28e3db6a8
4
- data.tar.gz: 731afecf6097e8767443df85c6c13a919f415b2c
2
+ SHA256:
3
+ metadata.gz: 6c445ed8e20835270102f2c0207d41b334966bfd854d08a40d6ac89f81ecaf31
4
+ data.tar.gz: 7965b5a7c98b1cf217473b97394546d7cb816122a96ea7a380c1c67943e8d403
5
5
  SHA512:
6
- metadata.gz: eb8a892c606a28c653ba0e6bdeede5f9b96b895fe1430f80826dfd91af61126bb0b6a31ec4b261ece202da35ea1c1c0c6f624dd14daa3655192886ac020f6be9
7
- data.tar.gz: 73e2c099851188b28784536d1755b49a8aad2cd706f6ece489e3d46d71972cb8d3eb42c3fa4e66fbdcca6533c22ec1e124d7d1244942d41e000c575d78f17e98
6
+ metadata.gz: 55dca0a0a86b40e5505d63fa15b0a25fe9546fb6cfe777da740e0134104cd829a3feb9311e592d5124f59805e9a1e517ba547cec27a15e2b595834c3017c3d8e
7
+ data.tar.gz: 37caec984ee3d2c4a1311e898e2ea55aa4a80f76142cff9b53b0b5190f129adc9ad389e77a3c28d911dd294d655ac3aba256b3ff66b212d0a4d08ae73e3739bc
@@ -0,0 +1,10 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.5.0
5
+
6
+ Style/Documentation:
7
+ Enabled: false
8
+
9
+ Metrics/LineLength:
10
+ Max: 125
@@ -0,0 +1,202 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2019-10-10 01:05:05 +0300 using RuboCop version 0.52.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Cop supports --auto-correct.
11
+ Layout/BlockEndNewline:
12
+ Exclude:
13
+ - 'spec/atol/request/post_document/sell/body_spec.rb'
14
+
15
+ # Offense count: 2
16
+ # Cop supports --auto-correct.
17
+ # Configuration parameters: EnforcedStyle.
18
+ # SupportedStyles: leading, trailing
19
+ Layout/DotPosition:
20
+ Exclude:
21
+ - 'spec/atol/request/get_token_spec.rb'
22
+
23
+ # Offense count: 1
24
+ # Cop supports --auto-correct.
25
+ Layout/EmptyLineAfterMagicComment:
26
+ Exclude:
27
+ - 'Rakefile'
28
+
29
+ # Offense count: 1
30
+ # Cop supports --auto-correct.
31
+ # Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
32
+ Layout/ExtraSpacing:
33
+ Exclude:
34
+ - 'spec/atol/transaction/post_document_spec.rb'
35
+
36
+ # Offense count: 34
37
+ # Cop supports --auto-correct.
38
+ # Configuration parameters: IndentationWidth.
39
+ # SupportedStyles: special_inside_parentheses, consistent, align_braces
40
+ Layout/IndentHash:
41
+ EnforcedStyle: consistent
42
+
43
+ # Offense count: 1
44
+ # Cop supports --auto-correct.
45
+ Layout/MultilineBlockLayout:
46
+ Exclude:
47
+ - 'spec/atol/request/post_document/sell/body_spec.rb'
48
+
49
+ # Offense count: 3
50
+ # Cop supports --auto-correct.
51
+ # Configuration parameters: AllowForAlignment.
52
+ Layout/SpaceAroundOperators:
53
+ Exclude:
54
+ - 'spec/atol/request/get_token_spec.rb'
55
+
56
+ # Offense count: 2
57
+ # Cop supports --auto-correct.
58
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
59
+ # SupportedStyles: space, no_space, compact
60
+ # SupportedStylesForEmptyBraces: space, no_space
61
+ Layout/SpaceInsideHashLiteralBraces:
62
+ Exclude:
63
+ - 'spec/atol/request/get_token_spec.rb'
64
+
65
+ # Offense count: 2
66
+ # Cop supports --auto-correct.
67
+ # Configuration parameters: EnforcedStyle.
68
+ # SupportedStyles: final_newline, final_blank_line
69
+ Layout/TrailingBlankLines:
70
+ Exclude:
71
+ - 'lib/atol.rb'
72
+ - 'lib/atol/request.rb'
73
+
74
+ # Offense count: 1
75
+ # Cop supports --auto-correct.
76
+ Layout/TrailingWhitespace:
77
+ Exclude:
78
+ - 'lib/atol/request/post_document.rb'
79
+
80
+ # Offense count: 1
81
+ # Cop supports --auto-correct.
82
+ # Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
83
+ Lint/UnusedBlockArgument:
84
+ Exclude:
85
+ - 'lib/atol/transaction/get_token.rb'
86
+
87
+ # Offense count: 2
88
+ Lint/UselessAssignment:
89
+ Exclude:
90
+ - 'lib/atol/request/post_document/sell/body.rb'
91
+ - 'spec/atol/request/post_document_spec.rb'
92
+
93
+ # Offense count: 6
94
+ Metrics/AbcSize:
95
+ Max: 22
96
+
97
+ # Offense count: 16
98
+ # Configuration parameters: CountComments, ExcludedMethods.
99
+ Metrics/BlockLength:
100
+ Max: 193
101
+
102
+ # Offense count: 1
103
+ Metrics/CyclomaticComplexity:
104
+ Max: 7
105
+
106
+ # Offense count: 1
107
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
108
+ # URISchemes: http, https
109
+ Metrics/LineLength:
110
+ Max: 125
111
+
112
+ # Offense count: 6
113
+ # Configuration parameters: CountComments.
114
+ Metrics/MethodLength:
115
+ Max: 20
116
+
117
+ # Offense count: 3
118
+ # Configuration parameters: CountKeywordArgs.
119
+ Metrics/ParameterLists:
120
+ Max: 6
121
+
122
+ # Offense count: 1
123
+ Metrics/PerceivedComplexity:
124
+ Max: 9
125
+
126
+ # Offense count: 1
127
+ # Cop supports --auto-correct.
128
+ Style/BlockComments:
129
+ Exclude:
130
+ - 'spec/spec_helper.rb'
131
+
132
+ # Offense count: 1
133
+ # Cop supports --auto-correct.
134
+ # Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods.
135
+ # SupportedStyles: line_count_based, semantic, braces_for_chaining
136
+ # ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
137
+ # FunctionalMethods: let, let!, subject, watch
138
+ # IgnoredMethods: lambda, proc, it
139
+ Style/BlockDelimiters:
140
+ Exclude:
141
+ - 'spec/atol/request/post_document/sell/body_spec.rb'
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
+ # Offense count: 1
153
+ # Cop supports --auto-correct.
154
+ # Configuration parameters: AutoCorrect, EnforcedStyle.
155
+ # SupportedStyles: nested, compact
156
+ Style/ClassAndModuleChildren:
157
+ Exclude:
158
+ - 'spec/factories/atol/config.rb'
159
+
160
+ # Offense count: 2
161
+ # Configuration parameters: MinBodyLength.
162
+ Style/GuardClause:
163
+ Exclude:
164
+ - 'lib/atol/request/get_token.rb'
165
+
166
+ # Offense count: 1
167
+ # Cop supports --auto-correct.
168
+ # Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
169
+ # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
170
+ Style/HashSyntax:
171
+ Exclude:
172
+ - 'Rakefile'
173
+
174
+ # Offense count: 2
175
+ # Cop supports --auto-correct.
176
+ # Configuration parameters: EnforcedStyle.
177
+ # SupportedStyles: line_count_dependent, lambda, literal
178
+ Style/Lambda:
179
+ Exclude:
180
+ - 'spec/atol/request/post_document_spec.rb'
181
+
182
+ # Offense count: 2
183
+ # Cop supports --auto-correct.
184
+ Style/MutableConstant:
185
+ Exclude:
186
+ - 'lib/atol/request/post_document/item/body.rb'
187
+
188
+ # Offense count: 2
189
+ # Cop supports --auto-correct.
190
+ # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
191
+ # SupportedStyles: single_quotes, double_quotes
192
+ Style/StringLiterals:
193
+ Exclude:
194
+ - 'spec/atol/request/get_document_state_spec.rb'
195
+ - 'spec/atol/request/get_token_spec.rb'
196
+
197
+ # Offense count: 2
198
+ # Cop supports --auto-correct.
199
+ # Configuration parameters: MinSize, WordRegex.
200
+ # SupportedStyles: percent, brackets
201
+ Style/WordArray:
202
+ EnforcedStyle: brackets
@@ -2,7 +2,11 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.5.0
5
- before_install: bundle install
5
+ before_install:
6
+ - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
7
+ - gem install -v 1.16.4 bundler --no-rdoc --no-ri
8
+ - bundle install
6
9
  cache: bundler
7
10
  script:
8
- - rspec
11
+ - rubocop
12
+ - rspec
data/Gemfile CHANGED
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
  gemspec
3
5
 
6
+ gem 'rubocop', require: false
7
+
4
8
  group :test do
5
9
  gem 'coveralls', require: false
6
10
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- atol (0.5.0)
4
+ atol (0.5.1)
5
5
  anyway_config (~> 1.0)
6
6
 
7
7
  GEM
@@ -76,7 +76,7 @@ DEPENDENCIES
76
76
  coveralls
77
77
  rake (~> 10.0)
78
78
  rspec (~> 3.0)
79
- rubocop (~> 0.52)
79
+ rubocop
80
80
  webmock (~> 3.0)
81
81
 
82
82
  BUNDLED WITH
data/README.md CHANGED
@@ -30,9 +30,11 @@ $ bundle install
30
30
 
31
31
  Для обращения к сервису необходимы данные учетной записи.
32
32
 
33
- При инициализации приложение попытается найти необходимые параметры в константе ENV.
33
+ При инициализации приложение попытается найти необходимые параметры в константе `ENV`.
34
34
 
35
- Для корректной инициализации потребуются следующие переменные окружения:
35
+ Для корректной работы потребуются следующие переменные окружения.
36
+
37
+ **Все переменные являются обязательными**.
36
38
 
37
39
  ```bash
38
40
  # .env
@@ -41,21 +43,58 @@ ATOL_LOGIN=example-login
41
43
  ATOL_PASSWORD=example-password
42
44
  ATOL_PAYMENT_ADDRESS="г. Москва, ул. Ленина, д.1 к.2"
43
45
  ATOL_GROUP_CODE=example-group-code
46
+ ATOL_DEFAULT_SNO=esn
47
+ ATOL_DEFAULT_TAX=vat18
48
+ ATOL_CALLBACK_URL=https://www.example.com/callback_path
49
+ ATOL_COMPANY_EMAIL=example@email.com
50
+ ATOL_DEFAULT_PAYMENT_TYPE=1
44
51
  ```
45
52
 
46
- Для Rails-приложений так же можно создать файл инициализации и задать параметры непосредственно в коде:
53
+ Значения `ATOL_INN`, `ATOL_LOGIN`, `ATOL_PASSWORD`, `ATOL_PAYMENT_ADDRESS` и `ATOL_GROUP_CODE` вы получаете при регистрации в сервисе.
54
+
55
+ `ATOL_DEFAULT_SNO` - система налогообложения. Возможные значения:
56
+ 1) "osn" – общая СН;
57
+ 2) "usn_income" – упрощенная СН (доходы);
58
+ 3) "usn_income_outcome" – упрощенная СН (доходы минус расходы);
59
+ 4) "envd" – единый налог на вмененный доход;
60
+ 5) "esn" – единый сельскохозяйственный налог;
61
+ 6) "patent" – патентная СН.
62
+
63
+ `ATOL_DEFAULT_TAX` - номер налога в ККТ. Возможные значения:
64
+ 1) "none" – без НДС;
65
+ 2) "vat0" – НДС по ставке 0%;
66
+ 3) "vat10" – НДС чека по ставке 10%;
67
+ 4) "vat18" – НДС чека по ставке 18%;
68
+ 5) "vat110" – НДС чека по расчетной ставке 10/110;
69
+ 6) "vat118" – НДС чека по расчетной ставке 18/118.
70
+
71
+ `ATOL_CALLBACK_URL` - адрес, по которому сервис будет отправлять информацию после создания чека.
47
72
 
73
+ `ATOL_DEFAULT_PAYMENT_TYPE` - вид оплаты. Возможные значения:
74
+ 1) "1" – электронный;
75
+ 2) "2" – "9" – расширенные типы оплаты. Для каждого фискального типа оплаты можно указать расширенный тип оплаты.
76
+
77
+ `ATOL_COMPANY_EMAIL` - адрес электронной почты вашей компании.
78
+
79
+ ### Конфигурация в инициализаторе
80
+
81
+ Для Rails-приложений так же можно создать файл инициализации и задать параметры непосредственно в коде:
48
82
 
49
83
  ```ruby
50
84
  # config/initializers/atol.rb
51
85
 
52
86
  Rails.application.config.after_initialize do
53
87
  Atol.config.tap do |config|
54
- config.inn = '123456789010'
55
- config.login = 'example-login'
56
- config.password = 'example-password'
57
- config.payment_address = 'г. Москва, ул. Ленина, д.1 к.2'
58
- config.group_code = 'example-group-code'
88
+ config.inn = '123456789010'
89
+ config.login = 'example-login'
90
+ config.password = 'example-password'
91
+ config.payment_address = 'г. Москва, ул. Ленина, д.1 к.2'
92
+ config.group_code = 'example-group-code'
93
+ config.default_sno = 'esn'
94
+ config.default_tax = 'vat18'
95
+ config.callback_url = 'https://www.example.com/callback_path'
96
+ config.company_email = 'example@email.com'
97
+ config.default_payment_type = '1'
59
98
  end
60
99
  end
61
100
  ```
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path('../lib', __FILE__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'atol/version'
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'atol/version'
2
4
  require 'atol/config'
3
5
  require 'atol/request'
4
6
  require 'atol/transaction'
5
7
 
6
8
  module Atol
7
- URL = "https://online.atol.ru/possystem/#{Atol::Version::API}".freeze
8
- ENCODING = 'utf-8'.freeze
9
- TIMESTAMP_FORMAT = '%d.%m.%Y %H:%M:%S'.freeze
9
+ URL = "https://online.atol.ru/possystem/#{Atol::Version::API}"
10
+ ENCODING = 'utf-8'
11
+ TIMESTAMP_FORMAT = '%d.%m.%Y %H:%M:%S'
10
12
 
11
13
  class << self
12
14
  attr_writer :config
@@ -16,4 +18,3 @@ module Atol
16
18
  end
17
19
  end
18
20
  end
19
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'anyway'
2
4
  require 'net/http'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Atol
2
4
  class MissingConfigError < StandardError; end
3
5
  class AuthBadRequestError < StandardError; end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'atol/request/get_token'
2
4
  require 'atol/request/post_document'
3
- require 'atol/request/get_document_state'
5
+ require 'atol/request/get_document_state'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'atol'
2
4
  require 'atol/errors'
3
5
  require 'net/http'
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'atol'
2
4
  require 'atol/errors'
3
5
 
4
6
  module Atol
5
7
  module Request
6
8
  class GetToken
7
- PATH = '/getToken'.freeze
9
+ PATH = '/getToken'
8
10
 
9
11
  def initialize(config: nil)
10
12
  @config = config || Atol.config
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'atol'
2
4
  require 'atol/errors'
3
5
  require 'atol/request/post_document/item/body'
@@ -35,7 +37,7 @@ module Atol
35
37
  res = http_client.start(uri.hostname, uri.port, use_ssl: true) do |http|
36
38
  http.request(req)
37
39
  end
38
-
40
+
39
41
  @res_logger.call(res) if @res_logger.respond_to?(:call)
40
42
 
41
43
  res
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'atol/errors'
2
4
 
3
5
  module Atol
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'atol/errors'
2
4
 
3
5
  module Atol
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'atol/transaction/get_token'
2
4
  require 'atol/transaction/post_document'
3
5
  require 'atol/transaction/get_document_state'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'atol/request/get_document_state'
2
4
  require 'atol/errors'
3
5
 
@@ -13,7 +15,7 @@ module Atol
13
15
  def call
14
16
  request = Atol::Request::GetDocumentState.new(@params)
15
17
  response = request.call
16
- encoded_body = response.body.force_encoding(Atol::ENCODING)
18
+ encoded_body = response.body.dup.force_encoding(Atol::ENCODING)
17
19
  json = JSON.parse(encoded_body)
18
20
 
19
21
  if response.code == '200' && json['error'].nil?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'atol/request/get_token'
2
4
  require 'atol/errors'
3
5
 
@@ -10,28 +12,24 @@ module Atol
10
12
  end
11
13
 
12
14
  def call
13
- @config.req_tries_number.times do |i|
15
+ @config.req_tries_number.times do
14
16
  request = Atol::Request::GetToken.new(config: @config)
15
17
  response = request.call
16
- encoded_body = response.body.encode(Atol::ENCODING)
18
+ encoded_body = response.body.dup.force_encoding(Atol::ENCODING)
17
19
  json = JSON.parse(encoded_body)
18
20
 
19
21
  case response.code
20
22
  when '200'
21
23
  return json['token']
22
24
  when '400'
23
- case json['code']
24
- when 19
25
- raise Atol::AuthUserOrPasswordError
26
- when 17
27
- raise Atol::AuthBadRequestError
28
- end
25
+ raise Atol::AuthBadRequestError
26
+ when '401'
27
+ raise Atol::AuthUserOrPasswordError
29
28
  when '500'
30
29
  next
31
30
  end
31
+ raise "#{response.code} #{response.body}"
32
32
  end
33
-
34
- raise "#{response.code} #{response.body}"
35
33
  end
36
34
  end
37
35
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'atol/request/post_document'
2
4
  require 'atol/errors'
3
5
 
@@ -20,7 +22,7 @@ module Atol
20
22
  def call
21
23
  request = Atol::Request::PostDocument.new(@params)
22
24
  response = request.call
23
- encoded_body = response.body.force_encoding(Atol::ENCODING)
25
+ encoded_body = response.body.dup.force_encoding(Atol::ENCODING)
24
26
  json = JSON.parse(encoded_body)
25
27
 
26
28
  if response.code == '200' && json['error'].nil?
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Atol
2
4
  module Version
3
- API = 'v4'.freeze
4
- LIB = '0.5.0'.freeze
5
+ API = 'v4'
6
+ LIB = '0.5.1'
5
7
  end
6
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.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GeorgeGorbanev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-26 00:00:00.000000000 Z
11
+ date: 2020-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: anyway_config
@@ -103,6 +103,8 @@ extra_rdoc_files: []
103
103
  files:
104
104
  - ".gitignore"
105
105
  - ".rspec"
106
+ - ".rubocop.yml"
107
+ - ".rubocop_todo.yml"
106
108
  - ".travis.yml"
107
109
  - Gemfile
108
110
  - Gemfile.lock
@@ -144,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
146
  version: '0'
145
147
  requirements: []
146
148
  rubyforge_project:
147
- rubygems_version: 2.6.14
149
+ rubygems_version: 2.7.3
148
150
  signing_key:
149
151
  specification_version: 4
150
152
  summary: ATOL KaaS client for Ruby