atol 0.4.2 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e641c3da1fd82f9b25d4d6f7945758211f2a304c
4
- data.tar.gz: ffa5be8712a96c1fa5767289e5fb26735ecfd573
2
+ SHA256:
3
+ metadata.gz: 75da4c224db9bbd13b7688b43902da591c3ebad3aea5a9fdd0e74b9331de1222
4
+ data.tar.gz: 22d9c1141823538a4fe595dbbefe0d82f33dd3e91635379abd48697729a7160c
5
5
  SHA512:
6
- metadata.gz: 8af070acadff92c07ea6bb74e21ea48b6ac78b94baea32edab622a60b44b3e53ca745a1033611c847cdf508bef08adc708626b37d1d80f6548471ccd580faa1b
7
- data.tar.gz: 8d6c72068f8ba205e7260ce7f1f22beb6e365406a16171e11c0157f88cc536a3b74747947b9c906c6e77142d32456cb6d935c38be52a442a5739f34b2558811f
6
+ metadata.gz: ea585b8d278bb75b6f4ae5f2ff358846337ea9ae4994dd4c3359d1edaf83997d29fe702a925d94bf11465543c332a40a346336e62432e083d12ff954859e866f
7
+ data.tar.gz: ed192a02125f15b2d9e4abe6003d89bad567e8a9e997ccd5b42627c527e34bbeff506cc19b84ce9a16c7b0a5399940ff1626b0be6e535d640d7e2de4ade7423e
@@ -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,193 @@
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/FirstHashElementIndentation:
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/TrailingEmptyLines:
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: 1
144
+ # Cop supports --auto-correct.
145
+ # Configuration parameters: AutoCorrect, EnforcedStyle.
146
+ # SupportedStyles: nested, compact
147
+ Style/ClassAndModuleChildren:
148
+ Exclude:
149
+ - 'spec/factories/atol/config.rb'
150
+
151
+ # Offense count: 2
152
+ # Configuration parameters: MinBodyLength.
153
+ Style/GuardClause:
154
+ Exclude:
155
+ - 'lib/atol/request/get_token.rb'
156
+
157
+ # Offense count: 1
158
+ # Cop supports --auto-correct.
159
+ # Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
160
+ # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
161
+ Style/HashSyntax:
162
+ Exclude:
163
+ - 'Rakefile'
164
+
165
+ # Offense count: 2
166
+ # Cop supports --auto-correct.
167
+ # Configuration parameters: EnforcedStyle.
168
+ # SupportedStyles: line_count_dependent, lambda, literal
169
+ Style/Lambda:
170
+ Exclude:
171
+ - 'spec/atol/request/post_document_spec.rb'
172
+
173
+ # Offense count: 2
174
+ # Cop supports --auto-correct.
175
+ Style/MutableConstant:
176
+ Exclude:
177
+ - 'lib/atol/request/post_document/item/body.rb'
178
+
179
+ # Offense count: 2
180
+ # Cop supports --auto-correct.
181
+ # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
182
+ # SupportedStyles: single_quotes, double_quotes
183
+ Style/StringLiterals:
184
+ Exclude:
185
+ - 'spec/atol/request/get_document_state_spec.rb'
186
+ - 'spec/atol/request/get_token_spec.rb'
187
+
188
+ # Offense count: 2
189
+ # Cop supports --auto-correct.
190
+ # Configuration parameters: MinSize, WordRegex.
191
+ # SupportedStyles: percent, brackets
192
+ Style/WordArray:
193
+ 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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
  gemspec
3
5
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- atol (0.4.2)
4
+ atol (0.7.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
- rake (10.5.0)
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)
@@ -74,10 +79,10 @@ DEPENDENCIES
74
79
  atol!
75
80
  bundler (~> 1.15)
76
81
  coveralls
77
- rake (~> 10.0)
82
+ rake (~> 13.0)
78
83
  rspec (~> 3.0)
79
- rubocop (~> 0.52)
84
+ rubocop (~> 0.90)
80
85
  webmock (~> 3.0)
81
86
 
82
87
  BUNDLED WITH
83
- 1.16.4
88
+ 1.17.3
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,27 +43,77 @@ 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` - адрес, по которому сервис будет отправлять информацию после создания чека.
72
+
73
+ `ATOL_DEFAULT_PAYMENT_TYPE` - вид оплаты. Возможные значения:
74
+ 1) "1" – электронный;
75
+ 2) "2" – "9" – расширенные типы оплаты. Для каждого фискального типа оплаты можно указать расширенный тип оплаты.
47
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
  ```
62
101
 
63
102
  Для объектов конфигурации используется класс унаследованный от класса из гема [anyway-config](https://github.com/palkan/anyway_config). Другие способы задания конфигурации можно найти в его документации.
64
103
 
104
+ ### Использование тестового окружения АТОЛ
105
+
106
+ АТОЛ предоставляет тестовую среду для отработки интеграции. Данные для авторизации в тестовой среде можно найти в [библиотеке документации АТОЛ Онлайн](https://online.atol.ru/lib/), пункт ["Параметры тестовой среды"](https://online.atol.ru/files/ffd/test_sreda.txt)
107
+
108
+ URL тестовой среды необходимо указывать в конфигурации. При использовании переменных окружения вам необходимо задать переменную `ATOL_API_URL`.
109
+
110
+ ```bash
111
+ # .env
112
+ ATOL_API_URL=https://testonline.atol.ru/possystem/v4
113
+ ```
114
+
115
+ > _Внимание! При создании чеков в тестовой среде АТОЛ будет отправлять письма на электронную почту покупателя._
116
+
65
117
  #### Прокси
66
118
 
67
119
  Объект конфигурации позволяет задать прокси для http-запросов:
@@ -106,12 +158,32 @@ body = Atol::Request::PostDocument::Sell::Body.new(
106
158
 
107
159
  Для создания `items` можно использовать класс `Atol::Request::PostDocument::Item::Body`.
108
160
 
109
- Его конструктор принимает обязательные аргументы `name`, `price` и опциональный `quantity` (по умолчанию 1).
161
+ Его конструктор принимает обязательные аргументы `name`, `price`, `payment_method`, `payment_object` и опциональный `quantity` (по умолчанию 1).
162
+
163
+ Допустимые значения `payment_method`:
164
+ ```ruby
165
+ [
166
+ 'full_prepayment', 'prepayment', 'advance', 'full_payment',
167
+ 'partial_payment', 'credit', 'credit_payment'
168
+ ]
169
+ ```
170
+ Допустимые значения `payment_object`:
171
+ ```ruby
172
+ [
173
+ 'commodity', 'excise', 'job', 'service', 'gambling_bet', 'gambling_prize',
174
+ 'lottery', 'lottery_prize', 'intellectual_activity', 'payment','agent_commission',
175
+ 'composite', 'another'
176
+ ]
177
+ ```
178
+
179
+ Например:
110
180
 
111
181
  ```ruby
112
182
  item = Atol::Request::PostDocument::Item::Body.new(
113
183
  name: 'product name',
114
184
  price: 100,
185
+ payment_method: 'full_payment',
186
+ payment_object: 'service',
115
187
  quantity: 2
116
188
  ).to_h
117
189
  ```
@@ -126,15 +198,21 @@ body = Atol::Request::PostDocument::Sell::Body.new(
126
198
  Atol::Request::PostDocument::Item::Body.new(
127
199
  name: 'number 9',
128
200
  price: 50,
201
+ payment_method: 'full_payment',
202
+ payment_object: 'service',
129
203
  quantity: 2
130
204
  ).to_h,
131
205
  Atol::Request::PostDocument::Item::Body.new(
132
206
  name: 'number 9 large',
133
- price: 100
207
+ price: 100,
208
+ payment_method: 'full_payment',
209
+ payment_object: 'service'
134
210
  ).to_h,
135
211
  Atol::Request::PostDocument::Item::Body.new(
136
212
  name: 'number 6',
137
- price: 60
213
+ price: 60,
214
+ payment_method: 'full_payment',
215
+ payment_object: 'service'
138
216
  ).to_h
139
217
  ]
140
218
  ).to_json
@@ -143,28 +221,28 @@ body = Atol::Request::PostDocument::Sell::Body.new(
143
221
  Результат:
144
222
  ```json
145
223
 
146
- {
147
- "receipt":{
148
- "attributes":{
224
+ {
225
+ "receipt":{
226
+ "attributes":{
149
227
  "sno":"usn_income_outcome",
150
228
  "email":"example@example.com"
151
229
  },
152
- "items":[
153
- {
230
+ "items":[
231
+ {
154
232
  "name":"number 9",
155
233
  "price":50.0,
156
234
  "quantity":2.0,
157
235
  "sum":100.0,
158
236
  "tax":"none"
159
237
  },
160
- {
238
+ {
161
239
  "name":"number 9 large",
162
240
  "price":100.0,
163
241
  "quantity":1.0,
164
242
  "sum":100.0,
165
243
  "tax":"none"
166
244
  },
167
- {
245
+ {
168
246
  "name":"number 6",
169
247
  "price":60.0,
170
248
  "quantity":1.0,
@@ -172,15 +250,15 @@ body = Atol::Request::PostDocument::Sell::Body.new(
172
250
  "tax":"none"
173
251
  }
174
252
  ],
175
- "payments":[
176
- {
253
+ "payments":[
254
+ {
177
255
  "sum":260.0,
178
256
  "type":1
179
257
  }
180
258
  ],
181
259
  "total":260.0
182
260
  },
183
- "service":{
261
+ "service":{
184
262
  "inn":"123456789010",
185
263
  "payment_address":"г. Москва, ул. Ленина, д.1 к.2"
186
264
  },
@@ -1,18 +1,21 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'atol/version'
4
6
 
5
7
  Gem::Specification.new do |spec|
6
- spec.name = 'atol'
7
- spec.version = Atol::Version::LIB
8
- spec.authors = ['GeorgeGorbanev']
9
- 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']
10
12
 
11
- spec.summary = 'ATOL KaaS client for Ruby'
12
- spec.homepage = 'https://github.com/sputnik8/atol-rb'
13
- 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'
14
17
 
15
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
19
  f.match(%r{^(test|spec|features)/})
17
20
  end
18
21
 
@@ -23,8 +26,8 @@ Gem::Specification.new do |spec|
23
26
  spec.add_dependency 'anyway_config', '~> 1.0'
24
27
 
25
28
  spec.add_development_dependency 'bundler', '~> 1.15'
26
- spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rake', '~> 13.0'
27
30
  spec.add_development_dependency 'rspec', '~> 3.0'
28
- spec.add_development_dependency 'rubocop', '~> 0.52'
31
+ spec.add_development_dependency 'rubocop', '~> 0.90'
29
32
  spec.add_development_dependency 'webmock', '~> 3.0'
30
33
  end
@@ -1,12 +1,13 @@
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
+ ENCODING = 'utf-8'
10
+ TIMESTAMP_FORMAT = '%d.%m.%Y %H:%M:%S'
10
11
 
11
12
  class << self
12
13
  attr_writer :config
@@ -16,4 +17,3 @@ module Atol
16
17
  end
17
18
  end
18
19
  end
19
-
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'anyway'
2
4
  require 'net/http'
5
+ require 'atol/version'
3
6
 
4
7
  module Atol
5
8
  class Config < Anyway::Config
@@ -14,6 +17,7 @@ module Atol
14
17
  :company_email,
15
18
  req_tries_number: 3,
16
19
  default_payment_type: 1,
17
- http_client: Net::HTTP
20
+ http_client: Net::HTTP,
21
+ api_url: "https://online.atol.ru/possystem/#{Atol::Version::API}"
18
22
  end
19
23
  end
@@ -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
@@ -5,46 +7,28 @@ module Atol
5
7
  class ConfigExpectedError < StandardError; end
6
8
  class UnknownOperationError < StandardError; end
7
9
  class BadJSONError < StandardError; end
8
- class IncomingBadRequestError < StandardError; end
9
10
  class IncomingOperationNotSupportError < StandardError; end
10
11
  class IncomingMissingTokenError < StandardError; end
11
- class IncomingNotExistTokenError < StandardError; end
12
12
  class IncomingExpiredTokenError < StandardError; end
13
13
  class IncomingExistExternalIdError < StandardError; end
14
14
  class GroupCodeToTokenError < StandardError; end
15
- class IsNullExternalIdError < StandardError; end
16
15
  class EmptyClientContactError < StandardError; end
17
16
  class EmptySellItemsError < StandardError; end
18
- class IncomingQueueTimeoutError < StandardError; end
19
17
  class IncomingValidationError < StandardError; end
20
- class IncomingQueueError < StandardError; end
21
- class StateBadRequestError < StandardError; end
22
- class StateMissingTokenError < StandardError; end
23
- class StateNotExistTokenError < StandardError; end
24
- class StateExpiredTokenError < StandardError; end
25
18
  class StateMissingUuidError < StandardError; end
26
19
  class StateNotFoundError < StandardError; end
27
20
  class ZeroItemQuantityError < StandardError; end
28
21
 
29
22
  ERRORS = Hash[
30
- 1 => BadJSONError,
31
- 2 => IncomingBadRequestError,
32
- 3 => IncomingOperationNotSupportError,
33
- 4 => IncomingMissingTokenError,
34
- 5 => IncomingNotExistTokenError,
35
- 6 => IncomingExpiredTokenError,
36
- 7 => IncomingQueueTimeoutError,
37
- 8 => IncomingValidationError,
38
- 9 => IncomingQueueError,
39
- 10 => IncomingExistExternalIdError,
40
- 11 => StateBadRequestError,
41
- 12 => StateMissingTokenError,
42
- 13 => StateNotExistTokenError,
43
- 14 => StateExpiredTokenError,
44
- 15 => StateMissingUuidError,
45
- 16 => StateNotFoundError,
46
- 22 => GroupCodeToTokenError,
47
- 23 => IsNullExternalIdError,
23
+ 0 => BadJSONError,
24
+ 10 => IncomingMissingTokenError,
25
+ 11 => IncomingExpiredTokenError,
26
+ 20 => GroupCodeToTokenError,
27
+ 30 => StateMissingUuidError,
28
+ 31 => IncomingOperationNotSupportError,
29
+ 32 => IncomingValidationError,
30
+ 33 => IncomingExistExternalIdError,
31
+ 34 => StateNotFoundError,
48
32
  -3804 => ZeroItemQuantityError
49
33
  ].freeze
50
34
  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'
@@ -9,13 +11,14 @@ module Atol
9
11
  @config = config || Atol.config
10
12
  raise(Atol::ConfigExpectedError) unless @config.is_a?(Atol::Config)
11
13
  raise(Atol::MissingConfigError, 'group_code missing') if @config.group_code.nil?
14
+
12
15
  @token = token
13
16
  @uuid = uuid
14
17
  end
15
18
 
16
19
  def call
17
20
  http_client = @config.http_client
18
- uri = URI("#{Atol::URL}/#{@config.group_code}/report/#{@uuid}")
21
+ uri = URI("#{@config.api_url}/#{@config.group_code}/report/#{@uuid}")
19
22
  http = http_client.new(uri.host, uri.port)
20
23
  http.use_ssl = true
21
24
  http.get(uri.request_uri, 'Token' => @token)
@@ -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
@@ -26,7 +28,7 @@ module Atol
26
28
  end
27
29
 
28
30
  def call
29
- uri = URI(Atol::URL + PATH)
31
+ uri = URI(@config.api_url + PATH)
30
32
  uri.query = URI.encode_www_form(login: @login, pass: @password)
31
33
 
32
34
  http = @http_client.new(uri.host, uri.port)
@@ -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'
@@ -25,7 +27,7 @@ module Atol
25
27
 
26
28
  def call
27
29
  http_client = @config.http_client
28
- uri = URI("#{Atol::URL}/#{@config.group_code}/#{@operation}")
30
+ uri = URI("#{@config.api_url}/#{@config.group_code}/#{@operation}")
29
31
  req_headers = HEADERS.merge('Token' => @token)
30
32
  req = http_client::Post.new(uri, req_headers)
31
33
  req.body = @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
@@ -5,20 +7,40 @@ module Atol
5
7
  class PostDocument
6
8
  module Item
7
9
  class Body
8
- def initialize(name:, price:, quantity: 1, config: nil)
9
- raise Atol::ZeroItemQuantityError if quantity.to_i.zero?
10
+ BadPaymentMethodError = Class.new(StandardError)
11
+ BadPaymentObjectError = Class.new(StandardError)
12
+
13
+ PAYMENT_METHODS = [
14
+ 'full_prepayment', 'prepayment', 'advance', 'full_payment',
15
+ 'partial_payment', 'credit', 'credit_payment'
16
+ ]
17
+
18
+ PAYMENT_OBJECTS = [
19
+ 'commodity', 'excise', 'job', 'service', 'gambling_bet', 'gambling_prize',
20
+ 'lottery', 'lottery_prize', 'intellectual_activity', 'payment', 'agent_commission',
21
+ 'composite', 'another'
22
+ ]
23
+
24
+ attr_accessor :config, :name, :price, :quantity, :payment_method, :payment_object
25
+
26
+ def initialize(config: nil, name:, price:, quantity: 1, payment_method:, payment_object:)
27
+ raise Atol::ZeroItemQuantityError if quantity.to_f.zero?
28
+ raise BadPaymentMethodError unless PAYMENT_METHODS.include?(payment_method.to_s)
29
+ raise BadPaymentObjectError unless PAYMENT_OBJECTS.include?(payment_object.to_s)
10
30
 
11
- @config = config || Atol.config
12
- @name = name
13
- @price = price.to_f
14
- @quantity = quantity.to_f
31
+ self.config = config || Atol.config
32
+ self.name = name
33
+ self.price = price.to_f
34
+ self.quantity = quantity.to_f
35
+ self.payment_method = payment_method.to_s
36
+ self.payment_object = payment_object.to_s
15
37
  end
16
38
 
17
39
  def to_h
18
40
  body.clone
19
41
  end
20
42
 
21
- def to_json
43
+ def to_json(*_args)
22
44
  body.to_json
23
45
  end
24
46
 
@@ -26,11 +48,13 @@ module Atol
26
48
 
27
49
  def body
28
50
  @body ||= {
29
- name: @name,
30
- price: @price,
31
- quantity: @quantity,
32
- sum: (@price * @quantity).round(2),
33
- tax: @config.default_tax
51
+ name: name,
52
+ price: price,
53
+ quantity: quantity,
54
+ sum: (price * quantity).round(2),
55
+ tax: config.default_tax,
56
+ payment_method: payment_method,
57
+ payment_object: payment_object
34
58
  }
35
59
  end
36
60
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'atol/errors'
2
4
 
3
5
  module Atol
@@ -20,24 +22,23 @@ module Atol
20
22
  body.clone
21
23
  end
22
24
 
23
- def to_json
25
+ def to_json(*_args)
24
26
  body.to_json
25
27
  end
26
28
 
27
29
  private
28
30
 
29
31
  def body
30
- @body ||= body_template.tap do |result|
32
+ body_template.tap do |result|
33
+ receipt = result[:receipt]
34
+ client = receipt[:client]
31
35
  result[:external_id] = @external_id
32
- result[:receipt][:client][:email] = @email unless @email.empty?
33
- result[:receipt][:client][:phone] = @phone unless @phone.empty?
36
+ client[:email] = @email unless @email.empty?
37
+ client[:phone] = @phone unless @phone.empty?
34
38
  result[:service][:callback_url] = @config.callback_url if @config.callback_url
35
39
 
36
- total = @items.inject(0) { |sum, item| sum += item[:sum] }
37
-
38
- result[:receipt][:total] = total
39
- result[:receipt][:payments][0][:sum] = total
40
- result[:receipt][:items] = @items
40
+ receipt[:total] = receipt[:payments][0][:sum] = total
41
+ receipt[:items] = @items
41
42
  end
42
43
  end
43
44
 
@@ -63,6 +64,10 @@ module Atol
63
64
  timestamp: Time.now.strftime(Atol::TIMESTAMP_FORMAT)
64
65
  }
65
66
  end
67
+
68
+ def total
69
+ @total ||= @items.inject(0) { |sum, item| sum += item[:sum] }
70
+ end
66
71
  end
67
72
  end
68
73
  end
@@ -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
 
@@ -7,13 +9,14 @@ module Atol
7
9
  def initialize(uuid:, token:, config: nil)
8
10
  @config = config || Atol.config
9
11
  raise(Atol::ConfigExpectedError) unless @config.is_a?(Atol::Config)
12
+
10
13
  @params = { uuid: uuid, token: token, config: @config }
11
14
  end
12
15
 
13
16
  def call
14
17
  request = Atol::Request::GetDocumentState.new(@params)
15
18
  response = request.call
16
- encoded_body = response.body.force_encoding(Atol::ENCODING)
19
+ encoded_body = response.body.dup.force_encoding(Atol::ENCODING)
17
20
  json = JSON.parse(encoded_body)
18
21
 
19
22
  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
 
@@ -7,6 +9,7 @@ module Atol
7
9
  def initialize(operation:, token:, body:, config: nil, req_logger: nil, res_logger: nil)
8
10
  @config = config || Atol.config
9
11
  raise(Atol::ConfigExpectedError) unless @config.is_a?(Atol::Config)
12
+
10
13
  @params = {
11
14
  operation: operation,
12
15
  token: token,
@@ -20,7 +23,7 @@ module Atol
20
23
  def call
21
24
  request = Atol::Request::PostDocument.new(@params)
22
25
  response = request.call
23
- encoded_body = response.body.force_encoding(Atol::ENCODING)
26
+ encoded_body = response.body.dup.force_encoding(Atol::ENCODING)
24
27
  json = JSON.parse(encoded_body)
25
28
 
26
29
  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.4.2'.freeze
5
+ API = 'v4'
6
+ LIB = '0.7.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.4.2
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GeorgeGorbanev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-16 00:00:00.000000000 Z
11
+ date: 2020-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: anyway_config
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -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
@@ -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
@@ -136,15 +138,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
138
  requirements:
137
139
  - - ">="
138
140
  - !ruby/object:Gem::Version
139
- version: '0'
141
+ version: 2.5.0
140
142
  required_rubygems_version: !ruby/object:Gem::Requirement
141
143
  requirements:
142
144
  - - ">="
143
145
  - !ruby/object:Gem::Version
144
146
  version: '0'
145
147
  requirements: []
146
- rubyforge_project:
147
- rubygems_version: 2.6.14
148
+ rubygems_version: 3.0.3
148
149
  signing_key:
149
150
  specification_version: 4
150
151
  summary: ATOL KaaS client for Ruby