jasl_tenpay 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jasl_tenpay/notify.rb +11 -11
- data/lib/jasl_tenpay/service.rb +1 -1
- data/lib/jasl_tenpay/version.rb +1 -1
- data/test/jasl_tenpay/notify_test.rb +26 -2
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40b69167296fd37ae3156d644cc9385a83a8cd70
|
4
|
+
data.tar.gz: ae11063ac2e002a8cfd7702e2c2448ad7391c02e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49a87f61bec986be2b647ad42e19a5ff9ef0782f97c06e515d66f9141d77cb90a7e923e896825cd30388424c0a865ea60b7d7c5bb5fa976eefdfaf6ee5785c8c
|
7
|
+
data.tar.gz: 71ac45ccbfca7517a3e9c950131c7cd78315962a4edd644ba69690701c7b86e13eed82ab8fcca5e51c7a1bee3368e339701ff7a8830ca21002f40983bbc594b1
|
data/lib/jasl_tenpay/notify.rb
CHANGED
@@ -2,19 +2,19 @@ module JaslTenpay
|
|
2
2
|
class Notify
|
3
3
|
GATEWAY = 'https://gw.tenpay.com/gateway/simpleverifynotifyid.xml'
|
4
4
|
SUCCESS_STR = '<retcode>0</retcode>'
|
5
|
+
TRADE_STATE_SUCCESS_STR = '<trade_state>0</trade_state>'
|
5
6
|
|
6
|
-
def self.verify?(params)
|
7
|
-
|
8
|
-
params = {
|
9
|
-
'input_charset' => 'UTF-8',
|
10
|
-
'partner' => JaslTenpay.pid,
|
11
|
-
'notify_id' => CGI.escape(params[:notify_id].to_s)
|
12
|
-
}
|
7
|
+
def self.verify?(params, options = {})
|
8
|
+
return false unless Sign.verify?(params)
|
13
9
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
params = {
|
11
|
+
'input_charset' => 'UTF-8',
|
12
|
+
'partner' => JaslTenpay.pid,
|
13
|
+
'notify_id' => CGI.escape(params[:notify_id].to_s)
|
14
|
+
}
|
15
|
+
result = open("#{GATEWAY}?#{Utils.make_query_string(params)}").read
|
16
|
+
|
17
|
+
result.include?(SUCCESS_STR) && (options[:verify_trade_state] ? result.include?(TRADE_STATE_SUCCESS_STR) : true)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/lib/jasl_tenpay/service.rb
CHANGED
@@ -5,7 +5,7 @@ module JaslTenpay
|
|
5
5
|
module Service
|
6
6
|
GATEWAY_URL = 'https://gw.tenpay.com/gateway/pay.htm'
|
7
7
|
|
8
|
-
CREATE_INTERACTIVE_MODE_REQUIRED_OPTIONS = %w(body
|
8
|
+
CREATE_INTERACTIVE_MODE_REQUIRED_OPTIONS = %w(body return_url notify_url partner out_trade_no total_fee fee_type spbill_create_ip)
|
9
9
|
def self.create_interactive_mode_url(options)
|
10
10
|
options = {
|
11
11
|
'input_charset' => 'UTF-8',
|
data/lib/jasl_tenpay/version.rb
CHANGED
@@ -7,6 +7,7 @@ class JaslTenpay::NotifyTest < Test::Unit::TestCase
|
|
7
7
|
<input_charset>UTF-8</input_charset>
|
8
8
|
<partner>2000054321</partner>
|
9
9
|
<retcode>0</retcode>
|
10
|
+
<trade_state>0</trade_state>
|
10
11
|
<retmsg />
|
11
12
|
<sign>1C58B3A778D9F49F3FA91D30E9A831D2</sign>
|
12
13
|
<sign_key_index>1</sign_key_index>
|
@@ -27,6 +28,19 @@ class JaslTenpay::NotifyTest < Test::Unit::TestCase
|
|
27
28
|
</root>
|
28
29
|
XML
|
29
30
|
|
31
|
+
SUCCESS_BUT_TRADE_STATE_FAIL_RETURN = <<-XML
|
32
|
+
<?xml version="1.0" encoding="GBK"?>
|
33
|
+
<root>
|
34
|
+
<input_charset>UTF-8</input_charset>
|
35
|
+
<partner>2000054321</partner>
|
36
|
+
<retcode>0</retcode>
|
37
|
+
<retmsg />
|
38
|
+
<sign>1C58B3A778D9F49F3FA91D30E9A831D2</sign>
|
39
|
+
<sign_key_index>1</sign_key_index>
|
40
|
+
<sign_type>MD5</sign_type>
|
41
|
+
</root>
|
42
|
+
XML
|
43
|
+
|
30
44
|
def setup
|
31
45
|
@options = {
|
32
46
|
:notify_id => '123456789012345678901234567890',
|
@@ -35,13 +49,23 @@ class JaslTenpay::NotifyTest < Test::Unit::TestCase
|
|
35
49
|
@url = "https://gw.tenpay.com/gateway/simpleverifynotifyid.xml?input_charset=UTF-8&partner=#{JaslTenpay.pid}¬ify_id=123456789012345678901234567890&sign=E040AFBCBC409EA0C62CF0F11CF0BAA4"
|
36
50
|
end
|
37
51
|
|
38
|
-
def
|
52
|
+
def test_verify_notify_when_success
|
39
53
|
FakeWeb.register_uri(:get, @url, :body => SUCCESS_RETURN)
|
40
54
|
assert JaslTenpay::Notify.verify?(@options)
|
41
55
|
end
|
42
56
|
|
43
|
-
def
|
57
|
+
def test_verify_notify_when_fail
|
44
58
|
FakeWeb.register_uri(:get, @url, :body => FAIL_RETURN)
|
45
59
|
assert !JaslTenpay::Notify.verify?(@options)
|
46
60
|
end
|
61
|
+
|
62
|
+
def test_verify_notify_with_trade_state_when_success
|
63
|
+
FakeWeb.register_uri(:get, @url, :body => SUCCESS_RETURN)
|
64
|
+
assert JaslTenpay::Notify.verify?(@options, verify_trade_state: true)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_verify_notify_with_trade_state_when_fail
|
68
|
+
FakeWeb.register_uri(:get, @url, :body => SUCCESS_BUT_TRADE_STATE_FAIL_RETURN)
|
69
|
+
assert !JaslTenpay::Notify.verify?(@options, verify_trade_state: true)
|
70
|
+
end
|
47
71
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jasl_tenpay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jasl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-18 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: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.1.11
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: An unofficial simple tenpay gem
|