sbrf_merchant 1.0.0 → 2.0.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 +5 -5
- data/README.md +28 -60
- data/lib/sbrf_merchant.rb +15 -14
- data/lib/sbrf_merchant/api/client.rb +34 -26
- data/lib/sbrf_merchant/api/request/body_preprocessor.rb +12 -0
- data/lib/sbrf_merchant/api/response/append_success_flag_to_hash.rb +15 -0
- data/lib/sbrf_merchant/api/response/body_postprocessor.rb +20 -0
- data/lib/sbrf_merchant/utils/hash/to_camel_case_keys.rb +9 -0
- data/lib/sbrf_merchant/utils/hash/to_snake_case_keys.rb +9 -0
- data/lib/sbrf_merchant/utils/high_order_functions/compose.rb +11 -0
- data/lib/sbrf_merchant/utils/http/client.rb +16 -0
- data/lib/sbrf_merchant/utils/json/to_hash_parser.rb +9 -0
- data/lib/sbrf_merchant/utils/json/to_object_parser.rb +13 -0
- data/lib/sbrf_merchant/utils/string/to_camel_case.rb +11 -0
- data/lib/sbrf_merchant/version.rb +1 -1
- metadata +47 -26
- data/.editorconfig +0 -12
- data/.gitignore +0 -11
- data/.rspec +0 -3
- data/.travis.yml +0 -18
- data/CHANGELOG.md +0 -13
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -6
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/lib/sbrf_merchant/api/action.rb +0 -13
- data/lib/sbrf_merchant/api/error_code.rb +0 -7
- data/lib/sbrf_merchant/api/order_status.rb +0 -13
- data/lib/sbrf_merchant/order.rb +0 -84
- data/lib/sbrf_merchant/response/base.rb +0 -20
- data/lib/sbrf_merchant/response/create_order.rb +0 -17
- data/lib/sbrf_merchant/response/order_status.rb +0 -70
- data/sbrf_merchant.gemspec +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: faada4cbbe623865c865d04992845d0c1a1e805c03c03b126d627c1263aa9484
|
4
|
+
data.tar.gz: ae29ef50e146c42ae8ad65c9121607b2d5b106c11f047a96bf188d88f9334c26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ffda247254ac00d4c2ff5181afde604c5cfd204c2f679e3b8a7948a851785a3c96bb91f291fd6d4155773b7696703cb64ffced0fdb14e6597aaf0c96781147b
|
7
|
+
data.tar.gz: f9960bb76468d78f4bb049c796553bec9c2c17a849ed5fdf56cda9db3a6dfdb868c57fab06a10e6bcf1a635d67afecf9899f17e1cc7b3945b5d6348adc201544
|
data/README.md
CHANGED
@@ -10,8 +10,8 @@ Ruby клиент для работы с платёжным шлюзом Сбе
|
|
10
10
|
|
11
11
|
Ключевые особенности:
|
12
12
|
- Простой (~200 LOC).
|
13
|
-
-
|
14
|
-
- Написан в ОО стиле без "магии".
|
13
|
+
- Расширяемый из коробки. Если В API появится новый метод то данный клиент будет его поддерживать без каких либо правок в исходный код
|
14
|
+
- Написан в ОО + ФП стиле без "магии". Легко встроится в ваши сервисные объекты и юнит тесты
|
15
15
|
|
16
16
|
## Установка
|
17
17
|
|
@@ -25,74 +25,42 @@ Ruby клиент для работы с платёжным шлюзом Сбе
|
|
25
25
|
|
26
26
|
```ruby
|
27
27
|
# Gemfile
|
28
|
-
gem 'sbrf_merchant'
|
28
|
+
gem 'sbrf_merchant', '~> 2.0.0`
|
29
29
|
```
|
30
|
+
## Документация
|
31
|
+
- [Site(RU)](https://securepayments.sberbank.ru/wiki/doku.php/integration:api:start)
|
32
|
+
- [PDF(RU)](http://cs.petrsu.ru/~vadim/sd2018/Merchant-Manual-SBRF.pdf)
|
30
33
|
|
31
|
-
##
|
32
|
-
|
34
|
+
## Использование
|
35
|
+
### Пример регистрации заказа
|
33
36
|
```ruby
|
37
|
+
# Перед использованием необходимо проинициализировать библиотеку.
|
34
38
|
SbrfMerchant.configure do |config|
|
35
|
-
config.
|
39
|
+
config.user_name = '<Merchant Username>'
|
36
40
|
config.password = '<Merchant Password>'
|
37
41
|
config.host = '<Sberbank API Host>'
|
38
42
|
end
|
39
|
-
```
|
40
|
-
## Документация
|
41
|
-
- [Site(RU)](https://securepayments.sberbank.ru/wiki/doku.php/integration:api:start)
|
42
|
-
- [PDF(RU)](http://cs.petrsu.ru/~vadim/sd2018/Merchant-Manual-SBRF.pdf)
|
43
|
-
## Использование
|
44
|
-
### Терминология
|
45
43
|
|
46
|
-
|
47
|
-
- **orderNumber** - ID заказа в Вашей системе
|
44
|
+
# или
|
48
45
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
require 'securerandom'
|
67
|
-
order = SbrfMerchant::Order.new(orderNumber: SecureRandom.hex)
|
68
|
-
response = order.register_one_stage(amount: 10000, returnUrl: 'http:/localhost:3000')
|
46
|
+
SbrfMerchant.configuration = SbrfMerchant::Configuration.new(
|
47
|
+
host: '<Sberbank API Host>',
|
48
|
+
user_name: '<Merchant Username>',
|
49
|
+
password: '<Merchant Password>'
|
50
|
+
)
|
51
|
+
|
52
|
+
|
53
|
+
# Cоздаем клиент
|
54
|
+
client = SbrfMerchant::Api::Client.new
|
55
|
+
|
56
|
+
# Вызываем метод API.
|
57
|
+
# :register - название метода согласно документации Cбербанка в snake_case.
|
58
|
+
# Далее параметры запроса. Имена передаются в snake_case, перед отправкой запроса все параметры приведутся к camelCase.
|
59
|
+
response = client.call(:register, amount: 100, order_number: SecureRandom.hex, return_url: 'localhost:3000')
|
60
|
+
response.success? # => true
|
61
|
+
# В ответе имена возвращаются в snake_case
|
62
|
+
response.order_id #<order-id>
|
69
63
|
|
70
|
-
order.orderId # "<orderId>"
|
71
|
-
response.success? # true
|
72
|
-
response.formUrl # "https://3dsec.sberbank.ru/payment/merchants/sbersafe/payment_ru.html?mdOrder=<orderId>"
|
73
|
-
```
|
74
|
-
Для создания двустадийного заказа используте метод ```register_two_stage```
|
75
|
-
#### Статус заказа
|
76
|
-
```ruby
|
77
|
-
response = order.get_info
|
78
|
-
response.not_paid? # true or false
|
79
|
-
```
|
80
|
-
#### Возврат средств
|
81
|
-
```ruby
|
82
|
-
refund_amount = 1000
|
83
|
-
response = order.refund(refund_amount)
|
84
|
-
response.success? # true or false
|
85
|
-
```
|
86
|
-
#### Отмена заказа
|
87
|
-
```ruby
|
88
|
-
response = order.cancel
|
89
|
-
response.success? # true or false
|
90
|
-
```
|
91
|
-
#### Завершение заказа (двухстадийная оплата)
|
92
|
-
```ruby
|
93
|
-
complete_amount = 1000
|
94
|
-
response = order.complete(complete_amount)
|
95
|
-
response.success? # true or false
|
96
64
|
```
|
97
65
|
## Copyright
|
98
66
|
Copyright (c) 2018 Eugene Kozlov. See [LICENSE][] for details.
|
data/lib/sbrf_merchant.rb
CHANGED
@@ -1,24 +1,25 @@
|
|
1
|
-
require 'sbrf_merchant/
|
1
|
+
require 'sbrf_merchant/api/client'
|
2
2
|
|
3
3
|
module SbrfMerchant
|
4
4
|
class << self
|
5
5
|
attr_accessor :configuration
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.api_client
|
9
|
-
SbrfMerchant::Api::Client.new(
|
10
|
-
host: SbrfMerchant.configuration.host,
|
11
|
-
userName: SbrfMerchant.configuration.userName,
|
12
|
-
password: SbrfMerchant.configuration.password
|
13
|
-
)
|
14
|
-
end
|
15
6
|
|
16
|
-
|
17
|
-
|
18
|
-
|
7
|
+
def configure
|
8
|
+
self.configuration ||= Configuration.new
|
9
|
+
yield(configuration)
|
10
|
+
end
|
19
11
|
end
|
20
12
|
|
21
13
|
class Configuration
|
22
|
-
attr_accessor :host, :
|
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
|
23
21
|
end
|
24
22
|
end
|
23
|
+
|
24
|
+
Sberbank = SbrfMerchant
|
25
|
+
SBRF = SbrfMerchant
|
@@ -1,42 +1,50 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require '
|
1
|
+
require 'sbrf_merchant/api/response/body_postprocessor'
|
2
|
+
require 'sbrf_merchant/api/request/body_preprocessor'
|
3
|
+
require 'sbrf_merchant/utils/http/client'
|
4
|
+
require 'sbrf_merchant/utils/string/to_camel_case'
|
4
5
|
|
5
6
|
module SbrfMerchant
|
6
7
|
module Api
|
7
8
|
class Client
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
attr_reader :config,
|
10
|
+
:response_body_postprocessor,
|
11
|
+
:http_client,
|
12
|
+
:method_name_converter,
|
13
|
+
:request_body_preprocessor
|
14
|
+
|
15
|
+
def initialize(
|
16
|
+
config: SbrfMerchant.configuration,
|
17
|
+
response_body_postprocessor: SbrfMerchant::Api::Response::BodyPostProcessor,
|
18
|
+
request_body_preprocessor: SbrfMerchant::Api::Request::BodyPreProcessor,
|
19
|
+
http_client: SbrfMerchant::Utils::Http::Client,
|
20
|
+
method_name_converter: SbrfMerchant::Utils::String::ToCamelCase
|
21
|
+
)
|
22
|
+
@config = config
|
23
|
+
@response_body_postprocessor = response_body_postprocessor
|
24
|
+
@http_client = http_client
|
25
|
+
@method_name_converter = method_name_converter
|
26
|
+
@request_body_preprocessor = request_body_preprocessor
|
14
27
|
end
|
15
28
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
29
|
+
def call(method, **params)
|
30
|
+
prepared_params = request_body_preprocessor.call(auth_params.merge(params))
|
31
|
+
response = http_client.call(uri(method), prepared_params)
|
19
32
|
|
20
|
-
|
21
|
-
|
22
|
-
def parse_response_body(response)
|
23
|
-
JSON.parse(response.body, symbolize_names: true)
|
33
|
+
response_body_postprocessor.call(response.body)
|
24
34
|
end
|
25
35
|
|
26
|
-
|
27
|
-
uri = URI.join(host, path)
|
36
|
+
private
|
28
37
|
|
29
|
-
|
30
|
-
|
31
|
-
end
|
38
|
+
def auth_params
|
39
|
+
{ user_name: config.user_name, password: config.password }
|
32
40
|
end
|
33
41
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
42
|
+
def uri(method)
|
43
|
+
URI.join(
|
44
|
+
config.host,
|
45
|
+
'/payment/rest/',
|
46
|
+
method_name_converter.call(method.to_s) + '.do'
|
38
47
|
)
|
39
|
-
request
|
40
48
|
end
|
41
49
|
end
|
42
50
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'sbrf_merchant/utils/high_order_functions/compose'
|
2
|
+
require 'sbrf_merchant/utils/hash/to_camel_case_keys'
|
3
|
+
|
4
|
+
module SbrfMerchant
|
5
|
+
module Api
|
6
|
+
module Request
|
7
|
+
BodyPreProcessor = SbrfMerchant::Utils::HighOrderFunctions::Compose.call(
|
8
|
+
SbrfMerchant::Utils::Hash::ToCamelCaseKeys
|
9
|
+
)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module SbrfMerchant
|
4
|
+
module Api
|
5
|
+
module Response
|
6
|
+
AppendSuccessFlagToHash = lambda do |hash|
|
7
|
+
hash.merge(success?: IsSuccess.call(hash))
|
8
|
+
end
|
9
|
+
|
10
|
+
IsSuccess = lambda do |hash|
|
11
|
+
!hash[:form_url].nil? || hash[:error_code] == '0'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'sbrf_merchant/utils/high_order_functions/compose'
|
2
|
+
require 'sbrf_merchant/utils/json/to_hash_parser'
|
3
|
+
require 'sbrf_merchant/utils/json/to_object_parser'
|
4
|
+
require 'sbrf_merchant/utils/hash/to_snake_case_keys'
|
5
|
+
require 'sbrf_merchant/api/response/append_success_flag_to_hash'
|
6
|
+
require 'json/ext'
|
7
|
+
|
8
|
+
module SbrfMerchant
|
9
|
+
module Api
|
10
|
+
module Response
|
11
|
+
BodyPostProcessor = SbrfMerchant::Utils::HighOrderFunctions::Compose.call(
|
12
|
+
SbrfMerchant::Utils::JSON::ToHashParser,
|
13
|
+
SbrfMerchant::Utils::Hash::ToSnakeCaseKeys,
|
14
|
+
SbrfMerchant::Api::Response::AppendSuccessFlagToHash,
|
15
|
+
->(hash) { JSON.dump(hash) },
|
16
|
+
SbrfMerchant::Utils::JSON::ToObjectParser.call(OpenStruct)
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module SbrfMerchant
|
4
|
+
module Utils
|
5
|
+
module Http
|
6
|
+
Client = lambda do |uri, params|
|
7
|
+
request = ::Net::HTTP::Post.new(uri)
|
8
|
+
request.set_form_data(params)
|
9
|
+
|
10
|
+
::Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
11
|
+
http.request(request)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sbrf_merchant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Kozlov
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pry
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: awrence
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: json
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +122,20 @@ dependencies:
|
|
108
122
|
- - ">="
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: plissken
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
111
139
|
description: Sberbank Merchant API Client for Ruby
|
112
140
|
email:
|
113
141
|
- kozlovea8@gmail.com
|
@@ -115,29 +143,22 @@ executables: []
|
|
115
143
|
extensions: []
|
116
144
|
extra_rdoc_files: []
|
117
145
|
files:
|
118
|
-
- ".editorconfig"
|
119
|
-
- ".gitignore"
|
120
|
-
- ".rspec"
|
121
|
-
- ".travis.yml"
|
122
|
-
- CHANGELOG.md
|
123
|
-
- CODE_OF_CONDUCT.md
|
124
|
-
- Gemfile
|
125
146
|
- LICENSE.txt
|
126
147
|
- README.md
|
127
148
|
- Rakefile
|
128
|
-
- bin/console
|
129
|
-
- bin/setup
|
130
149
|
- lib/sbrf_merchant.rb
|
131
|
-
- lib/sbrf_merchant/api/action.rb
|
132
150
|
- lib/sbrf_merchant/api/client.rb
|
133
|
-
- lib/sbrf_merchant/api/
|
134
|
-
- lib/sbrf_merchant/api/
|
135
|
-
- lib/sbrf_merchant/
|
136
|
-
- lib/sbrf_merchant/
|
137
|
-
- lib/sbrf_merchant/
|
138
|
-
- lib/sbrf_merchant/
|
151
|
+
- lib/sbrf_merchant/api/request/body_preprocessor.rb
|
152
|
+
- lib/sbrf_merchant/api/response/append_success_flag_to_hash.rb
|
153
|
+
- lib/sbrf_merchant/api/response/body_postprocessor.rb
|
154
|
+
- lib/sbrf_merchant/utils/hash/to_camel_case_keys.rb
|
155
|
+
- lib/sbrf_merchant/utils/hash/to_snake_case_keys.rb
|
156
|
+
- lib/sbrf_merchant/utils/high_order_functions/compose.rb
|
157
|
+
- lib/sbrf_merchant/utils/http/client.rb
|
158
|
+
- lib/sbrf_merchant/utils/json/to_hash_parser.rb
|
159
|
+
- lib/sbrf_merchant/utils/json/to_object_parser.rb
|
160
|
+
- lib/sbrf_merchant/utils/string/to_camel_case.rb
|
139
161
|
- lib/sbrf_merchant/version.rb
|
140
|
-
- sbrf_merchant.gemspec
|
141
162
|
homepage: https://github.com/abstractart/sbrf_merchant
|
142
163
|
licenses:
|
143
164
|
- MIT
|
@@ -150,7 +171,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
171
|
requirements:
|
151
172
|
- - ">="
|
152
173
|
- !ruby/object:Gem::Version
|
153
|
-
version: 2.
|
174
|
+
version: 2.2.0
|
154
175
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
176
|
requirements:
|
156
177
|
- - ">="
|
@@ -158,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
179
|
version: '0'
|
159
180
|
requirements: []
|
160
181
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.6
|
182
|
+
rubygems_version: 2.7.6
|
162
183
|
signing_key:
|
163
184
|
specification_version: 4
|
164
185
|
summary: Sberbank Merchant
|
data/.editorconfig
DELETED
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
sudo: false
|
2
|
-
env:
|
3
|
-
global:
|
4
|
-
- CC_TEST_REPORTER_ID=9735ef84689218db8e96c19956062b07b3f300af987cfb6817765cc12c542c97
|
5
|
-
language: ruby
|
6
|
-
rvm:
|
7
|
-
- 2.5.1
|
8
|
-
before_install: gem install bundler -v 1.16.5
|
9
|
-
notifications:
|
10
|
-
- false
|
11
|
-
before_script:
|
12
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
13
|
-
- chmod +x ./cc-test-reporter
|
14
|
-
- ./cc-test-reporter before-build
|
15
|
-
scripts:
|
16
|
-
- bundle exec rspec spec
|
17
|
-
after_script:
|
18
|
-
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/CHANGELOG.md
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# Changelog 1.0.0
|
2
|
-
- Replace Order::OneStage class with Order class
|
3
|
-
- Add methods for working with two stage orders
|
4
|
-
# Changelog 0.2.0
|
5
|
-
- Replace external gems with Ruby standard library features
|
6
|
-
# Changelog 0.1.3
|
7
|
-
- Fix unexpected behaviour in Response::Base#success?
|
8
|
-
|
9
|
-
# Changelog 0.1.2
|
10
|
-
- Fix errors in Response::OrderStatus
|
11
|
-
|
12
|
-
# Changelog 0.1.1
|
13
|
-
- Add support of OneStage Order (register, cancel, refund, status)
|
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
-
orientation.
|
11
|
-
|
12
|
-
## Our Standards
|
13
|
-
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
15
|
-
include:
|
16
|
-
|
17
|
-
* Using welcoming and inclusive language
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
* Gracefully accepting constructive criticism
|
20
|
-
* Focusing on what is best for the community
|
21
|
-
* Showing empathy towards other community members
|
22
|
-
|
23
|
-
Examples of unacceptable behavior by participants include:
|
24
|
-
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
-
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
30
|
-
address, without explicit permission
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
-
professional setting
|
33
|
-
|
34
|
-
## Our Responsibilities
|
35
|
-
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
38
|
-
response to any instances of unacceptable behavior.
|
39
|
-
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
-
threatening, offensive, or harmful.
|
45
|
-
|
46
|
-
## Scope
|
47
|
-
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
-
when an individual is representing the project or its community. Examples of
|
50
|
-
representing a project or community include using an official project e-mail
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
53
|
-
further defined and clarified by project maintainers.
|
54
|
-
|
55
|
-
## Enforcement
|
56
|
-
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at kozlovea8@gmail.com. All
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
63
|
-
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
66
|
-
members of the project's leadership.
|
67
|
-
|
68
|
-
## Attribution
|
69
|
-
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
-
|
73
|
-
[homepage]: http://contributor-covenant.org
|
74
|
-
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'sbrf_merchant'
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require 'irb'
|
14
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
module SbrfMerchant
|
2
|
-
module Api
|
3
|
-
module Action
|
4
|
-
REST = '/payment/rest/'.freeze
|
5
|
-
REFUND_ORDER = "#{REST}refund.do".freeze
|
6
|
-
REGISTER_ORDER = "#{REST}register.do".freeze
|
7
|
-
ORDER_STATUS = "#{REST}getOrderStatusExtended.do".freeze
|
8
|
-
CANCEL_ORDER = "#{REST}reverse.do".freeze
|
9
|
-
REGISTER_PRE_AUTH = "#{REST}registerPreAuth.do".freeze
|
10
|
-
COMPLETE_ORDER = "#{REST}deposit.do".freeze
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/lib/sbrf_merchant/order.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
require 'sbrf_merchant/api/client'
|
2
|
-
require 'sbrf_merchant/api/action'
|
3
|
-
require 'sbrf_merchant/response/base'
|
4
|
-
require 'sbrf_merchant/response/create_order'
|
5
|
-
require 'sbrf_merchant/response/order_status'
|
6
|
-
|
7
|
-
module SbrfMerchant
|
8
|
-
class Order
|
9
|
-
attr_reader :api_client, :orderId, :orderNumber
|
10
|
-
|
11
|
-
def initialize(orderId: nil, orderNumber: nil, api_client: SbrfMerchant.api_client)
|
12
|
-
@orderId = orderId
|
13
|
-
@orderNumber = orderNumber
|
14
|
-
@api_client = api_client
|
15
|
-
end
|
16
|
-
|
17
|
-
def register_one_stage(**args)
|
18
|
-
register(SbrfMerchant::Api::Action::REGISTER_ORDER, args)
|
19
|
-
end
|
20
|
-
|
21
|
-
def register_two_stage(**args)
|
22
|
-
register(SbrfMerchant::Api::Action::REGISTER_PRE_AUTH, args)
|
23
|
-
end
|
24
|
-
|
25
|
-
def get_info
|
26
|
-
Response::OrderStatus.new(
|
27
|
-
api_client.process_request(
|
28
|
-
SbrfMerchant::Api::Action::ORDER_STATUS,
|
29
|
-
default_request_params
|
30
|
-
)
|
31
|
-
)
|
32
|
-
end
|
33
|
-
|
34
|
-
def cancel
|
35
|
-
Response::Base.new(
|
36
|
-
api_client.process_request(
|
37
|
-
SbrfMerchant::Api::Action::CANCEL_ORDER,
|
38
|
-
default_request_params
|
39
|
-
)
|
40
|
-
)
|
41
|
-
end
|
42
|
-
|
43
|
-
def refund(amount)
|
44
|
-
Response::Base.new(
|
45
|
-
api_client.process_request(
|
46
|
-
SbrfMerchant::Api::Action::REFUND_ORDER,
|
47
|
-
default_request_params.merge(amount: amount)
|
48
|
-
)
|
49
|
-
)
|
50
|
-
end
|
51
|
-
|
52
|
-
def complete(amount)
|
53
|
-
Response::Base.new(
|
54
|
-
api_client.process_request(
|
55
|
-
SbrfMerchant::Api::Action::COMPLETE_ORDER,
|
56
|
-
default_request_params.merge(amount: amount)
|
57
|
-
)
|
58
|
-
)
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
def default_request_params
|
64
|
-
params = {}
|
65
|
-
|
66
|
-
params[:orderId] = orderId if orderId
|
67
|
-
params[:orderNumber] = orderNumber if orderNumber
|
68
|
-
|
69
|
-
params
|
70
|
-
end
|
71
|
-
|
72
|
-
def register(path, args)
|
73
|
-
response = Response::CreateOrder.new(
|
74
|
-
api_client.process_request(
|
75
|
-
path,
|
76
|
-
args.merge(default_request_params)
|
77
|
-
)
|
78
|
-
)
|
79
|
-
@orderId = response.orderId
|
80
|
-
|
81
|
-
response
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'sbrf_merchant/api/error_code'
|
2
|
-
|
3
|
-
module SbrfMerchant
|
4
|
-
module Response
|
5
|
-
class Base
|
6
|
-
attr_reader :errorCode, :errorMessage
|
7
|
-
|
8
|
-
def initialize(args = {})
|
9
|
-
@errorCode = args[:errorCode]
|
10
|
-
@errorMessage = args[:errorMessage]
|
11
|
-
end
|
12
|
-
|
13
|
-
def success?
|
14
|
-
return false unless errorCode
|
15
|
-
|
16
|
-
errorCode.to_i == SbrfMerchant::Api::ErrorCode::SUCCESS
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module SbrfMerchant
|
2
|
-
module Response
|
3
|
-
class CreateOrder < Response::Base
|
4
|
-
attr_reader :formUrl, :orderId
|
5
|
-
|
6
|
-
def initialize(args = {})
|
7
|
-
super(args)
|
8
|
-
@formUrl = args[:formUrl]
|
9
|
-
@orderId = args[:orderId]
|
10
|
-
end
|
11
|
-
|
12
|
-
def success?
|
13
|
-
!formUrl.nil? && !orderId.nil?
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'sbrf_merchant/api/order_status'
|
2
|
-
|
3
|
-
module SbrfMerchant
|
4
|
-
module Response
|
5
|
-
class OrderStatus < Response::Base
|
6
|
-
AVAILABLE_FIELDS = %i[
|
7
|
-
orderNumber
|
8
|
-
orderStatus
|
9
|
-
actionCode
|
10
|
-
actionCodeDescription
|
11
|
-
amount
|
12
|
-
currency
|
13
|
-
date
|
14
|
-
ip
|
15
|
-
merchantOrderParams
|
16
|
-
attributes
|
17
|
-
cardAuthInfo
|
18
|
-
authDateTime
|
19
|
-
terminalId
|
20
|
-
authRefnum
|
21
|
-
paymentAmountInfo
|
22
|
-
bankInfo
|
23
|
-
].freeze
|
24
|
-
|
25
|
-
attr_reader(*AVAILABLE_FIELDS)
|
26
|
-
|
27
|
-
def initialize(args = {})
|
28
|
-
super(args)
|
29
|
-
|
30
|
-
AVAILABLE_FIELDS.each do |field|
|
31
|
-
instance_variable_set("@#{field}", args[field]) unless args[field].nil?
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def not_paid?
|
36
|
-
status_equals?(SbrfMerchant::Api::OrderStatus::NOT_PAID)
|
37
|
-
end
|
38
|
-
|
39
|
-
def preauthorized?
|
40
|
-
status_equals?(SbrfMerchant::Api::OrderStatus::PREAUTHORIZED_AMOUNT_HOLD)
|
41
|
-
end
|
42
|
-
|
43
|
-
def completed?
|
44
|
-
status_equals?(SbrfMerchant::Api::OrderStatus::COMPLETED)
|
45
|
-
end
|
46
|
-
|
47
|
-
def cancelled?
|
48
|
-
status_equals?(SbrfMerchant::Api::OrderStatus::CANCEL)
|
49
|
-
end
|
50
|
-
|
51
|
-
def refunded?
|
52
|
-
status_equals?(SbrfMerchant::Api::OrderStatus::REFUND)
|
53
|
-
end
|
54
|
-
|
55
|
-
def auth_on_bank_issuer_side?
|
56
|
-
status_equals?(SbrfMerchant::Api::OrderStatus::AUTH_ON_BANK_ISSUER_SIDE)
|
57
|
-
end
|
58
|
-
|
59
|
-
def rejected?
|
60
|
-
status_equals?(SbrfMerchant::Api::OrderStatus::REJECTED)
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def status_equals?(status)
|
66
|
-
orderStatus == status
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
data/sbrf_merchant.gemspec
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
lib = File.expand_path('lib', __dir__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require 'sbrf_merchant/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = 'sbrf_merchant'
|
7
|
-
spec.version = SbrfMerchant::VERSION
|
8
|
-
spec.authors = ['Eugene Kozlov']
|
9
|
-
spec.email = ['kozlovea8@gmail.com']
|
10
|
-
|
11
|
-
spec.summary = 'Sberbank Merchant'
|
12
|
-
spec.description = 'Sberbank Merchant API Client for Ruby'
|
13
|
-
spec.homepage = 'https://github.com/abstractart/sbrf_merchant'
|
14
|
-
spec.license = 'MIT'
|
15
|
-
spec.required_ruby_version = '>= 2.1.0'
|
16
|
-
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
-
f.match(%r{^(test|spec|features)/})
|
19
|
-
end
|
20
|
-
spec.bindir = 'exe'
|
21
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
-
spec.require_paths = ['lib']
|
23
|
-
|
24
|
-
spec.add_development_dependency 'bundler', '~> 1.16'
|
25
|
-
spec.add_development_dependency 'pry'
|
26
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
-
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
-
spec.add_development_dependency 'simplecov'
|
29
|
-
spec.add_development_dependency 'simplecov-console'
|
30
|
-
|
31
|
-
spec.add_runtime_dependency 'json'
|
32
|
-
end
|