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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 978e78088d3672cd1d0b6e37b8a51f6c9002a1b4
4
- data.tar.gz: 9f402cc6683399d4c1f34f68f4c02178098fae1c
3
+ metadata.gz: 40b69167296fd37ae3156d644cc9385a83a8cd70
4
+ data.tar.gz: ae11063ac2e002a8cfd7702e2c2448ad7391c02e
5
5
  SHA512:
6
- metadata.gz: ed7cff2b51e5956b7722aeb03e6dacbe229aa66eb41a3255da4e5f622cd3f5709ad2ec6c2e7dd77328fff194d6251280b69b227a6986ba639406ec5dc6958d67
7
- data.tar.gz: aa09190134db6e38026334933fd1aba11642b03be9ccaf364bef736adfa1bb398e4efa9a8c0d59abbf60deb68212de85e8ccdd709ff16f0df1e0a861c64f8fd7
6
+ metadata.gz: 49a87f61bec986be2b647ad42e19a5ff9ef0782f97c06e515d66f9141d77cb90a7e923e896825cd30388424c0a865ea60b7d7c5bb5fa976eefdfaf6ee5785c8c
7
+ data.tar.gz: 71ac45ccbfca7517a3e9c950131c7cd78315962a4edd644ba69690701c7b86e13eed82ab8fcca5e51c7a1bee3368e339701ff7a8830ca21002f40983bbc594b1
@@ -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
- if Sign.verify?(params)
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
- open("#{GATEWAY}?#{Utils.make_query_string(params)}").read.include? SUCCESS_STR
15
- else
16
- false
17
- end
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
@@ -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 subject return_url notify_url partner out_trade_no total_fee fee_type spbill_create_ip)
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',
@@ -1,3 +1,3 @@
1
1
  module JaslTenpay
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -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}&notify_id=123456789012345678901234567890&sign=E040AFBCBC409EA0C62CF0F11CF0BAA4"
36
50
  end
37
51
 
38
- def test_verify_notify_when_true
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 test_verify_notify_when_false
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.1
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-09-26 00:00:00.000000000 Z
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: '1.3'
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: '1.3'
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.0.3
96
+ rubygems_version: 2.1.11
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: An unofficial simple tenpay gem