unitpay 0.2 → 1.0.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: 6b2151fbaa10bcb948b81ed8a60251191f76072a
4
- data.tar.gz: 343b94025ae0549e871b8c898c774fc2b44deba8
3
+ metadata.gz: a28c1859c1ef131cc7118cdbbd555cc7b06855e7
4
+ data.tar.gz: 508c16d2a0b4bf63b405119c9c1bcfc58eab2529
5
5
  SHA512:
6
- metadata.gz: b7428b3732a1a5758e980ef6d5289545862293127849a06bd1d2263b498db0093bf7ec2ba63899a2258b953c87f3615385bc41d5622a77daed0cfb78d9c56b7f
7
- data.tar.gz: a52d8aec1065f3f6ae18deb8a5db4423198959d08c8a5a16a71e9664714d989a6802b01804c98104f974d47d8bd8adac6014315a4b0c1d28714026f4a5ed9b97
6
+ metadata.gz: f78db710b3b230e3be7d7ab232821890b27831a546aa6338976df483315f66615cae19834c6bd6909d5b783080286cada168e5206123c2ce099fc58fd990f141
7
+ data.tar.gz: 28b557d8bbfd3fe5594db24fc72eee568188dbf3df914f91623400807853a671763c428e1825c5f3418202a4b4ca7f4d1b08e8135a72c1615fefe869b68d053d
@@ -9,7 +9,7 @@ module Unitpay
9
9
  class RuntimeException < StandardError; end
10
10
 
11
11
  def notify
12
- if service.valid_notify_sign?(params[:params])
12
+ if service.valid_action_signature?(params[:method], params[:params])
13
13
  send(params[:method])
14
14
  success_request
15
15
  else
@@ -19,12 +19,12 @@ module Unitpay
19
19
  main_params(sum, account, desc).merge(publicKey: public_key)
20
20
  end
21
21
 
22
- def valid_sign?(current_sign, sum, account, desc)
22
+ def valid_signature?(current_sign, sum, account, desc)
23
23
  current_sign == calculate_sign(sum, account, desc)
24
24
  end
25
25
 
26
- def valid_notify_sign?(params)
27
- params[:sign] == calculate_notify_sign(params)
26
+ def valid_action_signature?(method, params)
27
+ params[:signature] == calculate_action_sign(method, params)
28
28
  end
29
29
 
30
30
  private
@@ -32,17 +32,26 @@ module Unitpay
32
32
  attr_reader :public_key, :secret_key, :currency, :use_sign
33
33
 
34
34
  def calculate_sign(sum, account, desc)
35
- Digest::MD5.hexdigest( [account, currency, desc, sum, secret_key].join )
35
+ signature_of([ account, currency, desc, sum, secret_key ])
36
36
  end
37
37
 
38
- def calculate_notify_sign(params)
39
- params.delete(:sign)
40
- values = Hash[ params.sort ].values + [ secret_key ]
41
- Digest::MD5.hexdigest(values.join)
38
+ def calculate_action_sign(method, params)
39
+ sign_params = params.dup
40
+ sign_params.delete(:sign)
41
+ sign_params.delete(:signature)
42
+
43
+ values = Hash[ sign_params.sort ].values + [ secret_key ]
44
+ values.unshift(method)
45
+
46
+ signature_of(values)
42
47
  end
43
48
 
49
+ def signature_of(arr)
50
+ Digest::SHA256.hexdigest(arr.join('{up}'))
51
+ end
52
+
44
53
  def main_params(sum, account, desc)
45
- sign = use_sign ? { sign: calculate_sign(sum, account, desc) } : {}
54
+ sign = use_sign ? { signature: calculate_sign(sum, account, desc) } : {}
46
55
 
47
56
  {
48
57
  sum: sum,
@@ -1,3 +1,3 @@
1
1
  module Unitpay
2
- VERSION = '0.2'
2
+ VERSION = '1.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unitpay
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ssnikolay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-04 00:00:00.000000000 Z
11
+ date: 2016-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  version: '0'
138
138
  requirements: []
139
139
  rubyforge_project:
140
- rubygems_version: 2.4.5.1
140
+ rubygems_version: 2.4.6
141
141
  signing_key:
142
142
  specification_version: 4
143
143
  summary: Gem для подключения к платежной системе unitpay.ru