sberbank-acquiring 0.1.0 → 0.2.0

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
2
  SHA1:
3
- metadata.gz: 7f8468504447448f4c59173b580560f9a320ead9
4
- data.tar.gz: 1eb948165621a4bb2cf43e426243b8366f1d7694
3
+ metadata.gz: ccbf57e377afcb8ff803721cd4babfa79b4d65a2
4
+ data.tar.gz: 53e128c622fcb4b1d251c9f5a68dba55cb0e5a47
5
5
  SHA512:
6
- metadata.gz: 445a28f80ae3fc93ff514e89ff9720dbd8539705b338638c09e83977fa826ded919a303f38d19bc78ad0e978363160ca4b915b2b3caaae0e752afc10baf340b7
7
- data.tar.gz: b720936ba81b9e777da382c4fa2bbbc3db768a02af4e819c7595fae38c5a8792fb15c7cc1b175bfc0858abac0b9a3d2370741dbbb652a1ca9fe2331c19c0d525
6
+ metadata.gz: d663c70963ef9ee8d7ac1876957b2e771da19b5b07c75a4ba3e59ed4b943b3e6c451298a179a684b6aa8a9ee6ce703a9523b80b5ce44991ca91ec9dc7f810afe
7
+ data.tar.gz: b1e55b21521a2c4a5f29fa75718047132d16c365f0b49aa6d707ab1756852227fcb88ce4d111442d67797327aa5a04fbfab38290ea25dbdab81dadc1ea49d26e
data/.travis.yml CHANGED
@@ -9,3 +9,4 @@ rvm:
9
9
  - 2.6.0
10
10
  - jruby
11
11
  before_install: gem install bundler -v 1.16.2
12
+ cache: bundler
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 - 2019-01-27
4
+ ### Added
5
+ - Changelog
6
+ - Asymmetric key request checksum validation
7
+ - `AbstractChecksumValidator`
8
+
9
+ ### Changed
10
+ - Inherited `SymmetricKeyChecksumValidator` and `AsymmetricKeyChecksumValidator` from `AbstractChecksumValidator`
11
+
12
+ ## 0.1.0 - 2018-12-10
13
+ ### Added
14
+ - Running key (documented) requests against remote API
15
+ - Running any requests against remote API
16
+ - Symmetric key request checksum validation
17
+ - Test and Production environments support
data/README.md CHANGED
@@ -1,18 +1,23 @@
1
- # Sberbank::Acquiring
1
+ # 💳 Sberbank::Acquiring
2
2
 
3
3
  [![Build Status](https://travis-ci.org/panasyuk/sberbank-acquiring.svg?branch=master)](https://travis-ci.org/panasyuk/sberbank-acquiring)
4
4
 
5
+ 🔻Ruby Version 2.1 - 2.6 (+ JRuby)
6
+ 🎈Никаких сторонних зависимостей
7
+
5
8
  ## Описание
6
9
 
7
10
  GEM sberbank-acquiring предоставляет функциональность для взаимодействия с API эквайринга банка Сбербанк. Он использует RESTful API эквайринга Сбербанка.
8
11
 
9
- Перед тем, как приступить к использованию этого гема, автор настоятельно рекомендует (хотя бы бегло) ознакомиться с официальной [документацией к JSON API эквайринга Сбербанка](https://securepayments.sberbank.ru/wiki/doku.php/integration:api:start), а так же [Wiki](https://github.com/panasyuk/sberbank-acquiring/wiki), кому интересно
12
+ Перед тем, как приступить к использованию этого гема, автор настоятельно рекомендует (хотя бы бегло) ознакомиться с официальной [документацией к JSON API эквайринга Сбербанка](https://securepayments.sberbank.ru/wiki/doku.php/integration:api:start#%D0%B8%D0%BD%D1%82%D0%B5%D1%80%D1%84%D0%B5%D0%B9%D1%81_rest), а так же [Wiki](https://github.com/panasyuk/sberbank-acquiring/wiki), кому интересно
10
13
 
11
14
  ## Установка
12
15
 
13
16
  ```ruby
14
17
  # Gemfile
15
18
  gem 'sberbank-acquiring', github: 'panasyuk/sberbank-acquiring'
19
+ # или
20
+ gem 'sberbank-acquiring', '~> 0.1.0'
16
21
  ```
17
22
 
18
23
  ## Использование
@@ -162,12 +167,29 @@ API эквайринга Сбербанка поддерживает два ви
162
167
 
163
168
  ```ruby
164
169
  # params = {}
165
- symmetric_key = '20546026a3675994185a132875efe41a'
170
+ key = '20546026a3675994185a132875efe41a'
171
+
172
+ callback_params = params.dup
173
+ checksum = callback_params.delete('checksum')
174
+
175
+ validator = Sberbank::Acquiring::SymmetricKeyChecksumValidator.new(key)
176
+ if validator.validate(checksum, callback_params)
177
+ # запрос успешно прошел валидацию, контрольная сумма верна
178
+ else
179
+ # запрос не может быть обработан, так как контрольная сумма неверна
180
+ end
181
+ ```
182
+
183
+ #### Асимметричный ключ
184
+
185
+ ```ruby
186
+ # params = {}
187
+ pem = File.read('< путь до файла сертификата >')
166
188
 
167
189
  callback_params = params.dup
168
190
  checksum = callback_params.delete('checksum')
169
191
 
170
- validator = Sberbank::Acquiring::SymmetricKeyChecksumValidator.new(symmetric_key)
192
+ validator = Sberbank::Acquiring::AsymmetricKeyChecksumValidator.new(pem)
171
193
  if validator.validate(checksum, callback_params)
172
194
  # запрос успешно прошел валидацию, контрольная сумма верна
173
195
  else
@@ -181,9 +203,7 @@ end
181
203
 
182
204
  ## TODO
183
205
 
184
- 1. Добавить проверку Callback-уведомлений для асимметричного ключа
185
- 2. v0.1.0
186
- 3. Добавить API для того чтобы сделать удобнее отправку заказов по ФФД 1.05. Примерный API:
206
+ 1. Добавить API для того чтобы сделать удобнее отправку заказов по ФФД 1.05. Примерный API:
187
207
  ```ruby
188
208
  sberbank_order = SBRF::Acquiring::Order.new(
189
209
  number: 'order#1',
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sberbank
4
+ module Acquiring
5
+ class AbstractChecksumValidator
6
+ def initialize(key, digest = digest_class.new)
7
+ @key = key
8
+ @digest = digest
9
+ end
10
+
11
+ def validate(checksum, params)
12
+ raise NotImplementedError
13
+ end
14
+
15
+ private
16
+
17
+ def digest_class
18
+ OpenSSL::Digest::SHA256
19
+ end
20
+
21
+ def generate_digest_data(params)
22
+ params.
23
+ keys.
24
+ sort { |a, b| a.to_s <=> b.to_s }.
25
+ map { |param_key| "#{param_key};#{params[param_key]};" }.
26
+ join
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sberbank
4
+ module Acquiring
5
+ class AsymmetricKeyChecksumValidator < AbstractChecksumValidator
6
+ def validate(checksum, params = {})
7
+ certificate.public_key.verify(
8
+ @digest,
9
+ [checksum].pack('H*'),
10
+ generate_digest_data(params)
11
+ )
12
+ end
13
+
14
+ private
15
+
16
+ def certificate
17
+ @certificate ||= OpenSSL::X509::Certificate.new(@key)
18
+ end
19
+
20
+ def digest_class
21
+ OpenSSL::Digest::SHA512
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,17 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'openssl'
4
-
5
3
  module Sberbank
6
4
  module Acquiring
7
- class SymmetricKeyChecksumValidator
8
- DIGEST_CLASS = OpenSSL::Digest::SHA256
9
-
10
- def initialize(key, digest = DIGEST_CLASS.new)
11
- @key = key
12
- @digest = digest
13
- end
14
-
5
+ class SymmetricKeyChecksumValidator < AbstractChecksumValidator
15
6
  def validate(checksum, params = {})
16
7
  checksum == calculate_checksum(generate_digest_data(params))
17
8
  end
@@ -19,16 +10,6 @@ module Sberbank
19
10
  def calculate_checksum(data)
20
11
  OpenSSL::HMAC.hexdigest(@digest, @key, data).upcase!
21
12
  end
22
-
23
- private
24
-
25
- def generate_digest_data(params)
26
- params.
27
- keys.
28
- sort { |a, b| a.to_s <=> b.to_s }.
29
- map { |param_key| "#{param_key};#{params[param_key]};" }.
30
- join
31
- end
32
13
  end
33
14
  end
34
15
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sberbank
4
4
  module Acquiring
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
@@ -1,23 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'openssl'
3
4
  require 'sberbank/acquiring/version'
4
5
  require 'sberbank/acquiring/response'
5
6
  require 'sberbank/acquiring/request'
6
7
  require 'sberbank/acquiring/command_parameters_convertor'
7
8
  require 'sberbank/acquiring/command_response_decorator'
8
9
  require 'sberbank/acquiring/client'
10
+ require 'sberbank/acquiring/abstract_checksum_validator'
9
11
  require 'sberbank/acquiring/symmetric_key_checksum_validator'
12
+ require 'sberbank/acquiring/asymmetric_key_checksum_validator'
10
13
 
11
14
  module Sberbank
12
15
  module Acquiring
13
16
  # Order statuses according to https://securepayments.sberbank.ru/wiki/doku.php/integration:api:rest:requests:getorderstatusextended
14
- ORDER_NOT_PAID = 0 # order is registered but not paid
15
- ORDER_HOLDED = 1 # pre-auth amount is holded (for 2-step payments)
17
+ ORDER_NOT_PAID = 0 # order is registered but not paid
18
+ ORDER_HOLDED = 1 # pre-auth amount is holded (for 2-step payments)
16
19
  ORDER_AUTHORIZED = 2 # order amount is fully authorized
17
- ORDER_CANCELLED = 3 # authorization is cancelled
18
- ORDER_REFUNDED = 4 # transaction amount was refunded
19
- ORDER_PENDING = 5 # authorization pending
20
- ORDER_REJECTED = 6 # authorization rejected
20
+ ORDER_CANCELLED = 3 # authorization is cancelled
21
+ ORDER_REFUNDED = 4 # transaction amount was refunded
22
+ ORDER_PENDING = 5 # authorization pending
23
+ ORDER_REJECTED = 6 # authorization rejected
21
24
 
22
25
  OPERATION_SUCCEEDED = 1
23
26
  OPERATION_FAILED = 0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sberbank-acquiring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksandr Panasyuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-10 00:00:00.000000000 Z
11
+ date: 2019-01-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This is an implementation of Sberbank Acuiring API client
14
14
  email:
@@ -19,8 +19,8 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - ".gitignore"
21
21
  - ".ruby-gemset"
22
- - ".ruby-version"
23
22
  - ".travis.yml"
23
+ - CHANGELOG.md
24
24
  - Gemfile
25
25
  - LICENSE.txt
26
26
  - README.md
@@ -28,6 +28,8 @@ files:
28
28
  - bin/console
29
29
  - bin/setup
30
30
  - lib/sberbank/acquiring.rb
31
+ - lib/sberbank/acquiring/abstract_checksum_validator.rb
32
+ - lib/sberbank/acquiring/asymmetric_key_checksum_validator.rb
31
33
  - lib/sberbank/acquiring/client.rb
32
34
  - lib/sberbank/acquiring/command_parameters_convertor.rb
33
35
  - lib/sberbank/acquiring/command_response_decorator.rb
@@ -56,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
58
  version: '0'
57
59
  requirements: []
58
60
  rubyforge_project:
59
- rubygems_version: 2.4.8
61
+ rubygems_version: 2.6.12
60
62
  signing_key:
61
63
  specification_version: 4
62
64
  summary: GEM that makes integration of Sberbank Acquiring easier
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.1.10