payanyway 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/payanyway/factories/payment_url_factory.rb +5 -52
- data/lib/payanyway/factories/query_params_factory.rb +57 -0
- data/lib/payanyway/factories/widget_url_factory.rb +12 -0
- data/lib/payanyway/gateway.rb +5 -1
- data/lib/payanyway/version.rb +1 -1
- data/spec/internal/config/payanyway.yml +1 -0
- data/spec/lib/payanyway/factories/{payment_url_factory_spec.rb → query_params_factory_spec.rb} +3 -3
- data/spec/lib/payanyway/gateway_spec.rb +8 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f21fd360b24af27284a7454e590e7d8a728d8f86
|
4
|
+
data.tar.gz: 397e913d3e2d7ff45bdb47194a3586a9dc4097b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5206c312a90c926b6d547332343326972ba2681ae6bbfe7b7eaf642ce0078538d3bdefbdde8735d6a1e2b30997659b8bfed4e61c3bb9683322b9344a4087cbd4
|
7
|
+
data.tar.gz: b54db4f2f3cf498a6a715536282febe168dc73658f4f1dd3043997d8c5bd3a7a1322c5f715dbfa57c35a9a66b8c21f579c0d590734350e59b4c7184b5c195976
|
data/README.md
CHANGED
@@ -13,6 +13,7 @@
|
|
13
13
|
- [Подключение](#setup)
|
14
14
|
- [Использование](#usage)
|
15
15
|
- [Запрос на оплату](#payment_url)
|
16
|
+
- [Получение URL для отображения виджета оплаты](#widget_url)
|
16
17
|
- [Специальные URL'ы](#special_urls)
|
17
18
|
- [Check URL](#check_url)
|
18
19
|
- [Return URL и InProgress URL](#return_url)
|
@@ -101,6 +102,15 @@ production: <<: *config
|
|
101
102
|
Payanyway::Gateway.payment_url(params, use_signature = true)
|
102
103
|
```
|
103
104
|
|
105
|
+
###<a name="widget_url"></a> Получение URL для отображения виджета оплаты
|
106
|
+
|
107
|
+
Чтобы получить ссылку на виджет для оплаты заказа пользователем,
|
108
|
+
используйте хелпер
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
Payanyway::Gateway.widget_url(params, use_signature = true)
|
112
|
+
```
|
113
|
+
|
104
114
|
Описание всех возможных параметров запроса (ключей params) находится [здесь](#params).
|
105
115
|
|
106
116
|
Если в настройках счета в системе **moneta.ru** выставлен флаг «Можно переопределять настройки в URL», то можно так же передавать
|
@@ -1,58 +1,11 @@
|
|
1
1
|
module Payanyway
|
2
2
|
module Factories
|
3
3
|
class PaymentUrlFactory
|
4
|
-
|
5
|
-
|
6
|
-
'
|
7
|
-
|
8
|
-
|
9
|
-
'MNT_TRANSACTION_ID' => :transaction_id,
|
10
|
-
'MNT_AMOUNT' => :amount,
|
11
|
-
'MNT_DESCRIPTION' => :description,
|
12
|
-
'MNT_SUBSCRIBER_ID' => :subscriber_id,
|
13
|
-
|
14
|
-
'MNT_SUCCESS_URL' => :success_url,
|
15
|
-
'MNT_INPROGRESS_URL' => :in_progress_url,
|
16
|
-
'MNT_FAIL_URL' => :fail_url,
|
17
|
-
'MNT_RETURN_URL' => :return_url,
|
18
|
-
|
19
|
-
'MNT_CUSTOM1' => :custom1,
|
20
|
-
'MNT_CUSTOM2' => :custom2,
|
21
|
-
'MNT_CUSTOM3' => :custom3,
|
22
|
-
|
23
|
-
'moneta.locale' => :locale,
|
24
|
-
'paymentSystem.limitIds' => :payment_system_limit_ids,
|
25
|
-
|
26
|
-
# Дополнительные параметры запроса на оплату
|
27
|
-
'followup' => :followup,
|
28
|
-
'paymentSystem.unitId' => :payment_system_unit_id,
|
29
|
-
'javascriptEnabled' => :javascript_enabled,
|
30
|
-
'paymentSystem.accountId' => :payment_system_account_id
|
31
|
-
# 'MNT_SIGNATURE' => добавляется при use_signature == true
|
32
|
-
}.to_settings
|
33
|
-
|
34
|
-
class << self
|
35
|
-
def build(params, use_signature)
|
36
|
-
params_for_moneta = prepare_params(params, use_signature)
|
37
|
-
query_params = params_for_moneta.to_a.map { |option| option.map{ |opt| CGI::escape(opt.to_s) }.join('=') }.join('&')
|
38
|
-
|
39
|
-
"#{ Payanyway::Gateway.config['payment_url'] }?#{ query_params }"
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def prepare_params(params, use_signature)
|
45
|
-
params_for_moneta = PARAMS.configure_by(params)
|
46
|
-
params_for_moneta = Payanyway::Gateway.config_for_moneta.merge(params_for_moneta)
|
47
|
-
|
48
|
-
use_signature ? add_signature(params_for_moneta) : params_for_moneta
|
49
|
-
end
|
50
|
-
|
51
|
-
def add_signature(params_for_moneta)
|
52
|
-
params_for_moneta.merge({
|
53
|
-
'MNT_SIGNATURE' => Payanyway::Helpers::SignatureGenerate.for_url(params_for_moneta)
|
54
|
-
})
|
55
|
-
end
|
4
|
+
def self.build(params, use_signature)
|
5
|
+
[
|
6
|
+
Payanyway::Gateway.config['payment_url'],
|
7
|
+
Payanyway::Factories::QueryParamsFactory.build(params, use_signature)
|
8
|
+
].join('?')
|
56
9
|
end
|
57
10
|
end
|
58
11
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Payanyway
|
2
|
+
module Factories
|
3
|
+
class QueryParamsFactory
|
4
|
+
PARAMS = {
|
5
|
+
'MNT_ID' => :moneta_id,
|
6
|
+
'MNT_TEST_MODE' => :test_mode,
|
7
|
+
'MNT_CURRENCY_CODE' => :currency,
|
8
|
+
|
9
|
+
'MNT_TRANSACTION_ID' => :transaction_id,
|
10
|
+
'MNT_AMOUNT' => :amount,
|
11
|
+
'MNT_DESCRIPTION' => :description,
|
12
|
+
'MNT_SUBSCRIBER_ID' => :subscriber_id,
|
13
|
+
|
14
|
+
'MNT_SUCCESS_URL' => :success_url,
|
15
|
+
'MNT_INPROGRESS_URL' => :in_progress_url,
|
16
|
+
'MNT_FAIL_URL' => :fail_url,
|
17
|
+
'MNT_RETURN_URL' => :return_url,
|
18
|
+
|
19
|
+
'MNT_CUSTOM1' => :custom1,
|
20
|
+
'MNT_CUSTOM2' => :custom2,
|
21
|
+
'MNT_CUSTOM3' => :custom3,
|
22
|
+
|
23
|
+
'moneta.locale' => :locale,
|
24
|
+
'paymentSystem.limitIds' => :payment_system_limit_ids,
|
25
|
+
|
26
|
+
# Дополнительные параметры запроса на оплату
|
27
|
+
'followup' => :followup,
|
28
|
+
'paymentSystem.unitId' => :payment_system_unit_id,
|
29
|
+
'javascriptEnabled' => :javascript_enabled,
|
30
|
+
'paymentSystem.accountId' => :payment_system_account_id
|
31
|
+
# 'MNT_SIGNATURE' => добавляется при use_signature == true
|
32
|
+
}.to_settings
|
33
|
+
|
34
|
+
class << self
|
35
|
+
def build(params, use_signature)
|
36
|
+
params_for_moneta = prepare_params(params, use_signature)
|
37
|
+
params_for_moneta.to_a.map { |option| option.map{ |opt| CGI::escape(opt.to_s) }.join('=') }.join('&')
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def prepare_params(params, use_signature)
|
43
|
+
params_for_moneta = PARAMS.configure_by(params)
|
44
|
+
params_for_moneta = Payanyway::Gateway.config_for_moneta.merge(params_for_moneta)
|
45
|
+
|
46
|
+
use_signature ? add_signature(params_for_moneta) : params_for_moneta
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_signature(params_for_moneta)
|
50
|
+
params_for_moneta.merge({
|
51
|
+
'MNT_SIGNATURE' => Payanyway::Helpers::SignatureGenerate.for_url(params_for_moneta)
|
52
|
+
})
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Payanyway
|
2
|
+
module Factories
|
3
|
+
class WidgetUrlFactory
|
4
|
+
def self.build(params, use_signature)
|
5
|
+
[
|
6
|
+
Payanyway::Gateway.config['widget_url'],
|
7
|
+
Payanyway::Factories::QueryParamsFactory.build(params, use_signature)
|
8
|
+
].join('?')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/payanyway/gateway.rb
CHANGED
@@ -50,6 +50,10 @@ module Payanyway
|
|
50
50
|
Payanyway::Factories::PaymentUrlFactory.build(params, use_signature)
|
51
51
|
end
|
52
52
|
|
53
|
+
def widget_url(params, use_signature = true)
|
54
|
+
Payanyway::Factories::WidgetUrlFactory.build(params, use_signature)
|
55
|
+
end
|
56
|
+
|
53
57
|
class << self
|
54
58
|
extend Forwardable
|
55
59
|
def_delegators(:instance, *Payanyway::Gateway.instance_methods(false))
|
@@ -61,4 +65,4 @@ module Payanyway
|
|
61
65
|
YAML.load(File.read(File.join(Rails.root, 'config/payanyway.yml')))[@env]
|
62
66
|
end
|
63
67
|
end
|
64
|
-
end
|
68
|
+
end
|
data/lib/payanyway/version.rb
CHANGED
data/spec/lib/payanyway/factories/{payment_url_factory_spec.rb → query_params_factory_spec.rb}
RENAMED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'uri'
|
2
2
|
|
3
|
-
describe Payanyway::Factories::
|
3
|
+
describe Payanyway::Factories::QueryParamsFactory do
|
4
4
|
subject do
|
5
|
-
|
5
|
+
built_params = described_class.build(params, false)
|
6
6
|
|
7
|
-
Hash[ URI.decode_www_form(
|
7
|
+
Hash[ URI.decode_www_form(built_params) ]
|
8
8
|
end
|
9
9
|
|
10
10
|
context 'when reset urls' do
|
@@ -29,4 +29,12 @@ describe Payanyway::Gateway do
|
|
29
29
|
it { is_expected.to eq('https://demo.moneta.ru/assistant.htm?MNT_ID=54321&MNT_CURRENCY_CODE=RUB&MNT_TEST_MODE=1&MNT_AMOUNT=120.25&MNT_TRANSACTION_ID=FF790ABCD') }
|
30
30
|
end
|
31
31
|
end
|
32
|
+
|
33
|
+
describe '#widget_url' do
|
34
|
+
let(:params) { { amount: '120.25', transaction_id: 'FF790ABCD' } }
|
35
|
+
|
36
|
+
subject { described_class.widget_url(params, false) }
|
37
|
+
|
38
|
+
it { is_expected.to eq('https://demo.moneta.ru/assistant.widget?MNT_ID=141290&MNT_CURRENCY_CODE=RUB&MNT_TEST_MODE=1&MNT_AMOUNT=120.25&MNT_TRANSACTION_ID=FF790ABCD') }
|
39
|
+
end
|
32
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: payanyway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ssnikolay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -169,6 +169,8 @@ files:
|
|
169
169
|
- lib/payanyway/controller.rb
|
170
170
|
- lib/payanyway/engine.rb
|
171
171
|
- lib/payanyway/factories/payment_url_factory.rb
|
172
|
+
- lib/payanyway/factories/query_params_factory.rb
|
173
|
+
- lib/payanyway/factories/widget_url_factory.rb
|
172
174
|
- lib/payanyway/gateway.rb
|
173
175
|
- lib/payanyway/helpers/settings.rb
|
174
176
|
- lib/payanyway/helpers/signature_generator.rb
|
@@ -184,7 +186,7 @@ files:
|
|
184
186
|
- spec/internal/app/controllers/application_controller.rb
|
185
187
|
- spec/internal/app/controllers/payanyway_controller.rb
|
186
188
|
- spec/internal/config/payanyway.yml
|
187
|
-
- spec/lib/payanyway/factories/
|
189
|
+
- spec/lib/payanyway/factories/query_params_factory_spec.rb
|
188
190
|
- spec/lib/payanyway/gateway_spec.rb
|
189
191
|
- spec/lib/payanyway/helpers/signature_generator_spec.rb
|
190
192
|
- spec/lib/payanyway/request/base_spec.rb
|
@@ -222,7 +224,7 @@ test_files:
|
|
222
224
|
- spec/internal/app/controllers/application_controller.rb
|
223
225
|
- spec/internal/app/controllers/payanyway_controller.rb
|
224
226
|
- spec/internal/config/payanyway.yml
|
225
|
-
- spec/lib/payanyway/factories/
|
227
|
+
- spec/lib/payanyway/factories/query_params_factory_spec.rb
|
226
228
|
- spec/lib/payanyway/gateway_spec.rb
|
227
229
|
- spec/lib/payanyway/helpers/signature_generator_spec.rb
|
228
230
|
- spec/lib/payanyway/request/base_spec.rb
|