sbrf_merchant 2.0.1 → 3.0.0

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: faada4cbbe623865c865d04992845d0c1a1e805c03c03b126d627c1263aa9484
4
- data.tar.gz: ae29ef50e146c42ae8ad65c9121607b2d5b106c11f047a96bf188d88f9334c26
3
+ metadata.gz: 7e42a848b5a67244c5552ee10258612a6c2be0ce73ad3927051e52c1e8776fe0
4
+ data.tar.gz: 5588f6e57acb32f4104660251285a942cf199859374676352f947f29f1b62d03
5
5
  SHA512:
6
- metadata.gz: 1ffda247254ac00d4c2ff5181afde604c5cfd204c2f679e3b8a7948a851785a3c96bb91f291fd6d4155773b7696703cb64ffced0fdb14e6597aaf0c96781147b
7
- data.tar.gz: f9960bb76468d78f4bb049c796553bec9c2c17a849ed5fdf56cda9db3a6dfdb868c57fab06a10e6bcf1a635d67afecf9899f17e1cc7b3945b5d6348adc201544
6
+ metadata.gz: 120dfd1f558921d0c8dd6fdf444151301241366eee65734dccf7e8140ea6fc09e6accc7a844c8b6837a8e2d87a1929f97b39d817b9244c97ab702d62e4f8e7bb
7
+ data.tar.gz: '098e739143b5da07dd5638300cff26291ca1ffeddcc43670492db091213184dff71d07c8c52570b3f858d31dd4453a6b6389034dd37a04219ce5d800b569a71e'
data/README.md CHANGED
@@ -25,7 +25,7 @@ Ruby клиент для работы с платёжным шлюзом Сбе
25
25
 
26
26
  ```ruby
27
27
  # Gemfile
28
- gem 'sbrf_merchant', '~> 2.0.0`
28
+ gem 'sbrf_merchant'
29
29
  ```
30
30
  ## Документация
31
31
  - [Site(RU)](https://securepayments.sberbank.ru/wiki/doku.php/integration:api:start)
@@ -34,35 +34,31 @@ gem 'sbrf_merchant', '~> 2.0.0`
34
34
  ## Использование
35
35
  ### Пример регистрации заказа
36
36
  ```ruby
37
- # Перед использованием необходимо проинициализировать библиотеку.
38
- SbrfMerchant.configure do |config|
39
- config.user_name = '<Merchant Username>'
40
- config.password = '<Merchant Password>'
41
- config.host = '<Sberbank API Host>'
42
- end
43
-
44
- # или
45
-
46
- SbrfMerchant.configuration = SbrfMerchant::Configuration.new(
47
- host: '<Sberbank API Host>',
37
+ # Cоздаем клиент
38
+ client = SBRF::Api::Client.new(
48
39
  user_name: '<Merchant Username>',
49
- password: '<Merchant Password>'
40
+ password: '<Merchant Password>',
41
+ host: '<Sberbank API Host>' # например https://3dsec.sberbank.ru'
50
42
  )
51
43
 
52
-
53
- # Cоздаем клиент
54
- client = SbrfMerchant::Api::Client.new
55
-
56
44
  # Вызываем метод API.
57
45
  # :register - название метода согласно документации Cбербанка в snake_case.
58
- # Далее параметры запроса. Имена передаются в snake_case, перед отправкой запроса все параметры приведутся к camelCase.
59
- response = client.call(:register, amount: 100, order_number: SecureRandom.hex, return_url: 'localhost:3000')
46
+ # Далее параметры запроса. Имена передаются в snake_case,
47
+ # перед отправкой запроса все параметры приведутся к camelCase.
48
+
49
+ params = {
50
+ amount: 100,
51
+ order_number: "something_unique_string",
52
+ return_url: 'localhost:3000'
53
+ }
54
+ response = client.call(:register, params)
55
+
60
56
  response.success? # => true
61
- # В ответе имена возвращаются в snake_case
57
+ # В ответе доступ к атрибутам в snake_case
62
58
  response.order_id #<order-id>
63
59
 
64
60
  ```
65
61
  ## Copyright
66
- Copyright (c) 2018 Eugene Kozlov. See [LICENSE][] for details.
62
+ Copyright (c) 2018 Eugene Kozlov.
67
63
 
68
64
  [license]: LICENSE.md
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
data/lib/sbrf_merchant.rb CHANGED
@@ -1,24 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sbrf_merchant/api/client'
2
4
 
3
5
  module SbrfMerchant
4
- class << self
5
- attr_accessor :configuration
6
-
7
- def configure
8
- self.configuration ||= Configuration.new
9
- yield(configuration)
10
- end
11
- end
12
-
13
- class Configuration
14
- attr_accessor :host, :user_name, :password
15
-
16
- def initialize(host: nil, user_name: nil, password: nil)
17
- @host = host
18
- @user_name = user_name
19
- @password = password
20
- end
21
- end
22
6
  end
23
7
 
24
8
  Sberbank = SbrfMerchant
@@ -1,50 +1,51 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sbrf_merchant/api/response/body_postprocessor'
2
4
  require 'sbrf_merchant/api/request/body_preprocessor'
5
+ require 'sbrf_merchant/api/request/uri_builder'
3
6
  require 'sbrf_merchant/utils/http/client'
4
- require 'sbrf_merchant/utils/string/to_camel_case'
5
7
 
6
8
  module SbrfMerchant
7
9
  module Api
8
10
  class Client
9
- attr_reader :config,
11
+ attr_reader :user_name,
12
+ :password,
13
+ :host,
10
14
  :response_body_postprocessor,
11
15
  :http_client,
12
- :method_name_converter,
16
+ :uri_builder,
13
17
  :request_body_preprocessor
14
18
 
15
19
  def initialize(
16
- config: SbrfMerchant.configuration,
20
+ user_name:,
21
+ password:,
22
+ host:,
17
23
  response_body_postprocessor: SbrfMerchant::Api::Response::BodyPostProcessor,
18
24
  request_body_preprocessor: SbrfMerchant::Api::Request::BodyPreProcessor,
19
25
  http_client: SbrfMerchant::Utils::Http::Client,
20
- method_name_converter: SbrfMerchant::Utils::String::ToCamelCase
26
+ uri_builder: SbrfMerchant::Api::Request::UriBuilder
21
27
  )
22
- @config = config
28
+ @user_name = user_name
29
+ @password = password
30
+ @host = host
23
31
  @response_body_postprocessor = response_body_postprocessor
24
32
  @http_client = http_client
25
- @method_name_converter = method_name_converter
33
+ @uri_builder = uri_builder
26
34
  @request_body_preprocessor = request_body_preprocessor
27
35
  end
28
36
 
29
- def call(method, **params)
37
+ def call(method_name, **params)
30
38
  prepared_params = request_body_preprocessor.call(auth_params.merge(params))
31
- response = http_client.call(uri(method), prepared_params)
39
+ uri = uri_builder.call(host, method_name)
32
40
 
41
+ response = http_client.call(uri, prepared_params)
33
42
  response_body_postprocessor.call(response.body)
34
43
  end
35
44
 
36
45
  private
37
46
 
38
47
  def auth_params
39
- { user_name: config.user_name, password: config.password }
40
- end
41
-
42
- def uri(method)
43
- URI.join(
44
- config.host,
45
- '/payment/rest/',
46
- method_name_converter.call(method.to_s) + '.do'
47
- )
48
+ { user_name: user_name, password: password }
48
49
  end
49
50
  end
50
51
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sbrf_merchant/utils/high_order_functions/compose'
2
4
  require 'sbrf_merchant/utils/hash/to_camel_case_keys'
3
5
 
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+ require 'sbrf_merchant/utils/string/to_camel_case'
5
+
6
+ module SbrfMerchant
7
+ module Api
8
+ module Request
9
+ UriBuilderConstructor = lambda do |method_name_converter|
10
+ lambda do |host, method_name|
11
+ URI.join(
12
+ host,
13
+ '/payment/rest/',
14
+ method_name_converter.call(method_name.to_s) + '.do'
15
+ )
16
+ end
17
+ end
18
+
19
+ UriBuilder = UriBuilderConstructor.call(SbrfMerchant::Utils::String::ToCamelCase)
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ostruct'
2
4
 
3
5
  module SbrfMerchant
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sbrf_merchant/utils/high_order_functions/compose'
2
4
  require 'sbrf_merchant/utils/json/to_hash_parser'
3
5
  require 'sbrf_merchant/utils/json/to_object_parser'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'awrence'
2
4
 
3
5
  module SbrfMerchant
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'plissken'
2
4
 
3
5
  module SbrfMerchant
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SbrfMerchant
2
4
  module Utils
3
5
  module HighOrderFunctions
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/http'
2
4
 
3
5
  module SbrfMerchant
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json/ext'
2
4
 
3
5
  module SbrfMerchant
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json/ext'
2
4
 
3
5
  module SbrfMerchant
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SbrfMerchant
2
4
  module Utils
3
5
  module String
4
6
  ToCamelCase = lambda do |str|
5
7
  str.split('_').inject('') do |buffer, e|
6
- buffer << (buffer.empty? ? e : e.capitalize!)
8
+ buffer + (buffer.empty? ? e : e.capitalize)
7
9
  end
8
10
  end
9
11
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SbrfMerchant
2
- VERSION = '2.0.1'.freeze
4
+ VERSION = '3.0.0'
3
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sbrf_merchant
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugene Kozlov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-12 00:00:00.000000000 Z
11
+ date: 2019-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -149,6 +149,7 @@ files:
149
149
  - lib/sbrf_merchant.rb
150
150
  - lib/sbrf_merchant/api/client.rb
151
151
  - lib/sbrf_merchant/api/request/body_preprocessor.rb
152
+ - lib/sbrf_merchant/api/request/uri_builder.rb
152
153
  - lib/sbrf_merchant/api/response/append_success_flag_to_hash.rb
153
154
  - lib/sbrf_merchant/api/response/body_postprocessor.rb
154
155
  - lib/sbrf_merchant/utils/hash/to_camel_case_keys.rb
@@ -171,15 +172,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
172
  requirements:
172
173
  - - ">="
173
174
  - !ruby/object:Gem::Version
174
- version: 2.2.0
175
+ version: 2.3.0
175
176
  required_rubygems_version: !ruby/object:Gem::Requirement
176
177
  requirements:
177
178
  - - ">="
178
179
  - !ruby/object:Gem::Version
179
180
  version: '0'
180
181
  requirements: []
181
- rubyforge_project:
182
- rubygems_version: 2.7.6
182
+ rubygems_version: 3.0.3
183
183
  signing_key:
184
184
  specification_version: 4
185
185
  summary: Sberbank Merchant