unitpay 0.0.1 → 0.0.2

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: 6c671ae4e542361a3f78a643f0e9da63ab95c7e8
4
- data.tar.gz: dbe7b09cccdf530d96d48de8c14d79871942fe1f
3
+ metadata.gz: 257e71a55aae731c0562c38c7a23db75c6e67d38
4
+ data.tar.gz: 9b7ba6ffaf048c0c0f4795ff0f1713d1b2a13b1d
5
5
  SHA512:
6
- metadata.gz: 95101e82c2a1c44ca8154a7aad641c7fcc9e654688dc20fef1431d13daa6b5cb39309c9a7c5e3d20b9242f1a26d0c58de1860c6a57e91270a3cf81e55b08c165
7
- data.tar.gz: c0ad05a541e0b3653623b27d7a722e1d40a974ff743402b434a5ccaf31f9c9f395306e27d173e55f3c8ea286b2f2e8eca8d2126b98f544127739ae06823006ac
6
+ metadata.gz: da68e495ff7b77d5a7a4719bbebb283acf2c61af140e0d7b0789062b226c5eeb3175650d7e721db2268df10ecb46cd26fdf9c30bb2682a65f728bfef6785ff48
7
+ data.tar.gz: 54b14a50c8cd1662060d3ce54ba93b528333ccb576ad2a4d5472181dea5bfa1ea20518c9e15a5d62413141d855bb0f1b2e2a1558f3a8c99b0400da63a2104fc3
@@ -1,2 +1,3 @@
1
1
  require 'unitpay/version'
2
+ require 'unitpay/controller'
2
3
  require 'unitpay/service'
@@ -0,0 +1,53 @@
1
+ module Unitpay
2
+ module Controller
3
+ # Skip RequestForgeryProtection
4
+ # skip_before_filter :verify_authenticity_token
5
+
6
+ class ServiceNotImplementedError < StandardError; end
7
+ class PayNotImplementedError < StandardError; end
8
+ class ErrorNotImplementedError < StandardError; end
9
+
10
+ def notify
11
+ if service.valid_notify_sign?(params[:params])
12
+ send(params[:method])
13
+ success_request
14
+ else
15
+ fail_request
16
+ end
17
+ end
18
+
19
+ def success
20
+ warn 'NotImplementedError'
21
+ end
22
+
23
+ def fail
24
+ warn 'NotImplementedError'
25
+ end
26
+
27
+ private
28
+
29
+ def service
30
+ raise ServiceNotImplementedError
31
+ end
32
+
33
+ def check
34
+ warn 'NotImplementedError'
35
+ end
36
+
37
+ def pay
38
+ raise PayNotImplementedError
39
+ end
40
+
41
+ def error
42
+ raise ErrorNotImplementedError
43
+ end
44
+
45
+ def success_request
46
+ render json: { result: { message: 'Запрос успешно обработан' } }
47
+ end
48
+
49
+ def fail_request
50
+ render json: { error: { message: 'Неверная сигнатура' } }
51
+ end
52
+ end
53
+ end
@@ -19,6 +19,10 @@ module Unitpay
19
19
  current_sign == calculate_sign(sum, account, desc)
20
20
  end
21
21
 
22
+ def valid_notify_sign?(params)
23
+ params[:sign] == calculate_notify_sign(params)
24
+ end
25
+
22
26
  private
23
27
 
24
28
  attr_reader :public_key, :secret_key, :currency
@@ -27,6 +31,12 @@ module Unitpay
27
31
  Digest::MD5.hexdigest( [account, currency, desc, sum, secret_key].join )
28
32
  end
29
33
 
34
+ def calculate_notify_sign(params)
35
+ params.delete(:sign)
36
+ values = Hash[ params.sort ].values + [ secret_key ]
37
+ Digest::MD5.hexdigest(values.join)
38
+ end
39
+
30
40
  def main_params(sum, account, desc, use_sign)
31
41
  use_sign = true if use_sign.nil?
32
42
  sign = use_sign ? { sign: calculate_sign(sum, account, desc) } : {}
@@ -1,3 +1,3 @@
1
1
  module Unitpay
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unitpay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ssnikolay
@@ -98,6 +98,7 @@ files:
98
98
  - bin/console
99
99
  - bin/setup
100
100
  - lib/unitpay.rb
101
+ - lib/unitpay/controller.rb
101
102
  - lib/unitpay/service.rb
102
103
  - lib/unitpay/version.rb
103
104
  - unitpay.gemspec