alipay 0.6.0.beta3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1b40064ee7facb241d38d98705e5906f3a3f0dc
4
- data.tar.gz: e5c62d859db374245b62359e9a76809cb62d8978
3
+ metadata.gz: 5d5f4d314f9fb4867e21f408875ef8e7a50e6579
4
+ data.tar.gz: c1d5d4d2838f56161d45c3e658a7b1d36c7416ae
5
5
  SHA512:
6
- metadata.gz: d0b965d472f626fa8ad8379501ee3bbd1047f4f0a3c4bf57abfa8513861efdaf1ed4c497aa0e879c5fa7861457142e10c8d4bbdf40d72593afd95b2931f43b3d
7
- data.tar.gz: 39877c9ae0e517cb47d4dc9609a78a81d47a10751ced9c3836e446369a3f53bb505fb4089fa8784c63fb40728a9f9a88a5cc634d7ad8ecdc95ab2c374259af38
6
+ metadata.gz: 86934d7c497a1dd1878a77b8b631c412bbbf7ac75f136f2140887c729d7fe69b0854ca1e677600a065b889a88a5173479866eb9c93bc80cdf53810085e64df1c
7
+ data.tar.gz: 11c4634fd023d90e2ec98b41f597b1ba18d81de9a54d430fffa7116d258017d700873afd73f0cb8295ea51947566ab9d6d61901ceec1788ba318302495142ede
data/CHANGELOG.md CHANGED
@@ -1,9 +1,15 @@
1
- ## v0.6.0.beta3 (2015-04-02)
1
+ ## v.0.6.0
2
2
 
3
- - Don't raise exception when sign_type error in Sign.verify?.
4
- - Fixed gmt_return timezone to +08:00.
3
+ New API:
5
4
 
6
- ## v0.6.0.beta2 (2015-04-01)
5
+ - Add Alipay::Service.mobile_security_pay_url.
6
+ - All service methods accept `options` args to config pid, seller_email and key.
7
+
8
+ New Config:
9
+
10
+ - Add `Alipay.sign_type`, default is 'MD5', allow: 'MD5', 'RSA'. 'DSA' is not implemented yet.
11
+
12
+ Break Changes:
7
13
 
8
14
  - Move `Alipay::Service::Wap` to `Alipay::Wap::Service`
9
15
  - Move `Alipay::Sign::Wap` to `Alipay::Wap::Sign`
@@ -11,21 +17,14 @@
11
17
  - Rename `Alipay::Service.create_forex_single_refund_url` to `Alipay::Service.forex_refund_url`
12
18
  - Rename `Alipay::Service.create_forex_trade` to `Alipay::Service.create_forex_trade_url`
13
19
  - Rename `Alipay::Service.create_refund_url` to `Alipay::Service.refund_fastpay_by_platform_pwd_url`
14
- - All service methods accept `options` args to config pid, seller_email and key.
15
-
16
- ## v0.6.0.beta1 (2015-03-26)
17
-
18
- Usage:
20
+ - Rename `Service::Wap.auth_and_execute` to `Service::Wap::Service.auth_and_execute_url`
19
21
 
20
- - Add `Alipay.sign_type`, default is 'MD5', 'RSA' and 'DSA' will implemented in the future.
21
- - Remove `Sign::App.verify?`, use `Sign.verify_rsa?` instead.
22
- - Remove `Notify::App.verify?`, use `Notify.verify?` instead.
23
- - Rename `Service::Wap.auth_and_execute` to `Service::Wap.auth_and_execute_url`
22
+ Now `Alipay::Sign.verify?` and `Alipay::Wap::Sign.verify?` detect sign_type by params.
24
23
 
25
24
  Development:
26
25
 
27
26
  - Update Test::Unit to Minitest.
28
- - Fxied test case data.
27
+ - Use fxied test data.
29
28
 
30
29
  ## v0.5.0 (2015-03-09)
31
30
 
data/README.md CHANGED
@@ -4,20 +4,12 @@ A unofficial alipay ruby gem.
4
4
 
5
5
  Alipay official document: https://b.alipay.com/order/techService.htm .
6
6
 
7
- Master branch(v0.6.0) is in develop, checkout [v0.5.0](https://github.com/chloerei/alipay/tree/v0.5.0) if you want to use in production.
8
-
9
7
  ## Installation
10
8
 
11
9
  Add this line to your application's Gemfile:
12
10
 
13
11
  ```ruby
14
- gem 'alipay', '~> 0.6.0.beta3'
15
- ```
16
-
17
- or master branch:
18
-
19
- ```ruby
20
- gem 'alipay', github: 'chloerei/alipay'
12
+ gem 'alipay', '~> 0.6.0'
21
13
  ```
22
14
 
23
15
  And then execute:
@@ -368,6 +360,46 @@ Alipay::Service.forex_refund_url(
368
360
 
369
361
  \* Auto set Time.now if not set.
370
362
 
363
+ ### 快捷支付(无线)
364
+
365
+ #### Name
366
+
367
+ ```ruby
368
+ mobile.securitypay.pay
369
+ ```
370
+
371
+ #### Definition
372
+
373
+ ```ruby
374
+ Alipay::Service.mobile_security_pay_url({ARGUMENTS}, {OPTIONS})
375
+ ```
376
+
377
+ #### Example
378
+
379
+ ```ruby
380
+ Alipay::Service.mobile_security_pay_url(
381
+ out_trade_no: '20150401000-0001',
382
+ notify_url: 'https://example.com/orders/20150401000-0001/notify'
383
+ subject: 'subject',
384
+ total_fee: '10.00',
385
+ body: 'text'
386
+ )
387
+ ```
388
+
389
+ #### ARGUMENTS
390
+
391
+ | Key | Requirement | Description |
392
+ | --- | ----------- | ----------- |
393
+ | out_trade_no | required | Order number in your application. |
394
+ | notify_url | required | Alipay asyn notify url. |
395
+ | subject | required | Order subject. |
396
+ | total_fee | required | Order total price. |
397
+ | body | required | Order body, less than 512 bytes. |
398
+
399
+ \* This service only support RSA sign_type.
400
+
401
+ This is not a complete list of arguments, please read official document: http://download.alipay.com/public/api/base/WS_MOBILE_PAY_SDK_BASE.zip .
402
+
371
403
  ### 验证通知
372
404
 
373
405
  #### Name
@@ -163,16 +163,34 @@ module Alipay
163
163
  Net::HTTP.get(request_uri(params, options))
164
164
  end
165
165
 
166
+ MOBILD_SECURITY_PAY_REQUIRED_PARAMS = %w( notify_url out_trade_no subject total_fee body )
167
+ def self.mobile_security_pay_url(params, options = {})
168
+ params = Utils.stringify_keys(params)
169
+ check_required_params(params, MOBILD_SECURITY_PAY_REQUIRED_PARAMS)
170
+ sign_type = options[:sign_type] || Alipay.sign_type
171
+ raise ArgumentError, "only support RSA sign_type" if sign_type != 'RSA'
172
+
173
+ params = {
174
+ '_input_charset' => 'utf-8',
175
+ 'partner' => options[:pid] || Alipay.pid,
176
+ 'seller_id' => options[:seller_email] || Alipay.seller_email,
177
+ 'payment_type' => '1',
178
+ 'service' => 'mobile.securitypay.pay'
179
+ }.merge(params)
180
+
181
+ request_uri(params, options).to_s
182
+ end
183
+
166
184
  def self.request_uri(params, options = {})
167
185
  uri = URI(GATEWAY_URL)
168
186
  uri.query = URI.encode_www_form(sign_params(params, options))
169
187
  uri
170
188
  end
171
189
 
172
- def self.sign_params(params, optinos = {})
190
+ def self.sign_params(params, options = {})
173
191
  params.merge(
174
- 'sign_type' => (optinos[:sign_type] || Alipay.sign_type),
175
- 'sign' => Alipay::Sign.generate(params, optinos)
192
+ 'sign_type' => (options[:sign_type] || Alipay.sign_type),
193
+ 'sign' => Alipay::Sign.generate(params, options)
176
194
  )
177
195
  end
178
196
 
data/lib/alipay/sign.rb CHANGED
@@ -14,7 +14,7 @@ module Alipay
14
14
  when 'DSA'
15
15
  DSA.sign(key, string)
16
16
  else
17
- raise ArgumentError, "[Alipay] Invalid sign_type #{sign_type}, allow value: 'MD5', 'RSA', 'DSA'"
17
+ raise ArgumentError, "invalid sign_type #{sign_type}, allow value: 'MD5', 'RSA', 'DSA'"
18
18
  end
19
19
  end
20
20
 
@@ -2,11 +2,11 @@ module Alipay
2
2
  module Sign
3
3
  class DSA
4
4
  def self.sign(key, string)
5
- raise NotImplementedError, '[Alipay] DSA sign is not implemented'
5
+ raise NotImplementedError, 'DSA sign is not implemented'
6
6
  end
7
7
 
8
8
  def self.verify?(string, sign)
9
- raise NotImplementedError, '[Alipay] DSA verify is not implemented'
9
+ raise NotImplementedError, 'DSA verify is not implemented'
10
10
  end
11
11
  end
12
12
  end
@@ -1,3 +1,3 @@
1
1
  module Alipay
2
- VERSION = "0.6.0.beta3"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -3,27 +3,27 @@ require 'test_helper'
3
3
  class Alipay::NotifyTest < Minitest::Test
4
4
  def setup
5
5
  @params = {
6
- :notify_id => '1234',
6
+ notify_id: '1234',
7
7
  }
8
- @unsign_params = @params.merge(:sign_type => 'MD5', :sign => 'xxxx')
8
+ @unsign_params = @params.merge(sign_type: 'MD5', sign: 'xxxx')
9
9
  @sign_params = @params.merge(
10
- :sign_type => 'MD5',
11
- :sign => '22fc7e38e5acdfede396aa463870d111'
10
+ sign_type: 'MD5',
11
+ sign: '22fc7e38e5acdfede396aa463870d111'
12
12
  )
13
13
  end
14
14
 
15
15
  def test_unsign_notify
16
- FakeWeb.register_uri(:get, "https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}&notify_id=1234", :body => "true")
16
+ FakeWeb.register_uri(:get, "https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}&notify_id=1234", body: "true")
17
17
  assert !Alipay::Notify.verify?(@unsign_params)
18
18
  end
19
19
 
20
20
  def test_verify_notify_when_true
21
- FakeWeb.register_uri(:get, "https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}&notify_id=1234", :body => "true")
21
+ FakeWeb.register_uri(:get, "https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}&notify_id=1234", body: "true")
22
22
  assert Alipay::Notify.verify?(@sign_params)
23
23
  end
24
24
 
25
25
  def test_verify_notify_when_false
26
- FakeWeb.register_uri(:get, "https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}&notify_id=1234", :body => "false")
26
+ FakeWeb.register_uri(:get, "https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}&notify_id=1234", body: "false")
27
27
  assert !Alipay::Notify.verify?(@sign_params)
28
28
  end
29
29
  end
@@ -3,13 +3,13 @@ require 'test_helper'
3
3
  class Alipay::ServiceTest < Minitest::Test
4
4
  def test_generate_create_partner_trade_by_buyer_url
5
5
  options = {
6
- :out_trade_no => '1',
7
- :subject => 'test',
8
- :logistics_type => 'POST',
9
- :logistics_fee => '0',
10
- :logistics_payment => 'SELLER_PAY',
11
- :price => '0.01',
12
- :quantity => 1
6
+ out_trade_no: '1',
7
+ subject: 'test',
8
+ logistics_type: 'POST',
9
+ logistics_fee: '0',
10
+ logistics_payment: 'SELLER_PAY',
11
+ price: '0.01',
12
+ quantity: 1
13
13
  }
14
14
 
15
15
  assert_equal 'https://mapi.alipay.com/gateway.do?service=create_partner_trade_by_buyer&_input_charset=utf-8&partner=1000000000000000&seller_email=admin%40example.com&payment_type=1&out_trade_no=1&subject=test&logistics_type=POST&logistics_fee=0&logistics_payment=SELLER_PAY&price=0.01&quantity=1&sign_type=MD5&sign=09c5d8fd3d7eac18268fffa4cdffd19e', Alipay::Service.create_partner_trade_by_buyer_url(options)
@@ -17,61 +17,61 @@ class Alipay::ServiceTest < Minitest::Test
17
17
 
18
18
  def test_generate_trade_create_by_buyer_url
19
19
  options = {
20
- :out_trade_no => '1',
21
- :subject => 'test',
22
- :logistics_type => 'POST',
23
- :logistics_fee => '0',
24
- :logistics_payment => 'SELLER_PAY',
25
- :price => '0.01',
26
- :quantity => 1
20
+ out_trade_no: '1',
21
+ subject: 'test',
22
+ logistics_type: 'POST',
23
+ logistics_fee: '0',
24
+ logistics_payment: 'SELLER_PAY',
25
+ price: '0.01',
26
+ quantity: 1
27
27
  }
28
28
  assert_equal 'https://mapi.alipay.com/gateway.do?service=trade_create_by_buyer&_input_charset=utf-8&partner=1000000000000000&seller_email=admin%40example.com&payment_type=1&out_trade_no=1&subject=test&logistics_type=POST&logistics_fee=0&logistics_payment=SELLER_PAY&price=0.01&quantity=1&sign_type=MD5&sign=62b029a767accbbd5f3b085da5959506', Alipay::Service.trade_create_by_buyer_url(options)
29
29
  end
30
30
 
31
31
  def test_generate_create_direct_pay_by_user_url
32
32
  options = {
33
- :out_trade_no => '1',
34
- :subject => 'test',
35
- :price => '0.01',
36
- :quantity => 1
33
+ out_trade_no: '1',
34
+ subject: 'test',
35
+ price: '0.01',
36
+ quantity: 1
37
37
  }
38
38
  assert_equal 'https://mapi.alipay.com/gateway.do?service=create_direct_pay_by_user&_input_charset=utf-8&partner=1000000000000000&seller_email=admin%40example.com&payment_type=1&out_trade_no=1&subject=test&price=0.01&quantity=1&sign_type=MD5&sign=51c7f60e85eaff5136600d1942b2744c', Alipay::Service.create_direct_pay_by_user_url(options)
39
39
  end
40
40
 
41
41
  def test_refund_fastpay_by_platform_pwd_url
42
42
  data = [{
43
- :trade_no => '1',
44
- :amount => '0.01',
45
- :reason => 'test'
43
+ trade_no: '1',
44
+ amount: '0.01',
45
+ reason: 'test'
46
46
  }]
47
47
  options = {
48
- :batch_no => '123456789',
49
- :data => data,
50
- :notify_url => '/some_url',
51
- :refund_date => '2015-01-01 00:00:00'
48
+ batch_no: '123456789',
49
+ data: data,
50
+ notify_url: '/some_url',
51
+ refund_date: '2015-01-01 00:00:00'
52
52
  }
53
53
  assert_equal "https://mapi.alipay.com/gateway.do?service=refund_fastpay_by_platform_pwd&_input_charset=utf-8&partner=1000000000000000&seller_email=admin%40example.com&refund_date=2015-01-01+00%3A00%3A00&batch_num=1&detail_data=1%5E0.01%5Etest&batch_no=123456789&notify_url=%2Fsome_url&sign_type=MD5&sign=3f5be5655b513334460a511e74a9ae57", Alipay::Service.refund_fastpay_by_platform_pwd_url(options)
54
54
  end
55
55
 
56
56
  def test_forex_refund_url
57
57
  options = {
58
- :out_return_no => '1',
59
- :out_trade_no => '12345678980',
60
- :return_amount => '0.01',
61
- :currency => 'USD',
62
- :reason => 'reason',
63
- :gmt_return => '20150101000000'
58
+ out_return_no: '1',
59
+ out_trade_no: '12345678980',
60
+ return_amount: '0.01',
61
+ currency: 'USD',
62
+ reason: 'reason',
63
+ gmt_return: '20150101000000'
64
64
  }
65
65
  assert_equal 'https://mapi.alipay.com/gateway.do?service=forex_refund&partner=1000000000000000&_input_charset=utf-8&gmt_return=20150101000000&out_return_no=1&out_trade_no=12345678980&return_amount=0.01&currency=USD&reason=reason&sign_type=MD5&sign=c9681fff5505fe993d1b2b8141308d0d', Alipay::Service.forex_refund_url(options)
66
66
  end
67
67
 
68
68
  def test_generate_create_forex_trade_url
69
69
  options = {
70
- :notify_url => 'https://example.com/notify',
71
- :subject => 'test',
72
- :out_trade_no => '1',
73
- :currency => 'EUR',
74
- :total_fee => '0.01',
70
+ notify_url: 'https://example.com/notify',
71
+ subject: 'test',
72
+ out_trade_no: '1',
73
+ currency: 'EUR',
74
+ total_fee: '0.01',
75
75
  }
76
76
  assert_equal 'https://mapi.alipay.com/gateway.do?service=create_forex_trade&_input_charset=utf-8&partner=1000000000000000&seller_email=admin%40example.com&notify_url=https%3A%2F%2Fexample.com%2Fnotify&subject=test&out_trade_no=1&currency=EUR&total_fee=0.01&sign_type=MD5&sign=495a0e610134aa33f6ce021f8b8c6c8d', Alipay::Service.create_forex_trade_url(options)
77
77
  end
@@ -86,11 +86,11 @@ class Alipay::ServiceTest < Minitest::Test
86
86
  FakeWeb.register_uri(
87
87
  :get,
88
88
  %r|https://mapi\.alipay\.com/gateway\.do.*|,
89
- :body => response_body
89
+ body: response_body
90
90
  )
91
91
 
92
92
  assert_equal response_body, Alipay::Service.close_trade(
93
- :out_order_no => '1'
93
+ out_order_no: '1'
94
94
  )
95
95
  end
96
96
 
@@ -138,11 +138,11 @@ class Alipay::ServiceTest < Minitest::Test
138
138
  FakeWeb.register_uri(
139
139
  :get,
140
140
  %r|https://mapi\.alipay\.com/gateway\.do.*|,
141
- :body => response_body
141
+ body: response_body
142
142
  )
143
143
 
144
144
  assert_equal response_body, Alipay::Service.single_trade_query(
145
- :out_trade_no => '1'
145
+ out_trade_no: '1'
146
146
  )
147
147
  end
148
148
 
@@ -156,13 +156,26 @@ class Alipay::ServiceTest < Minitest::Test
156
156
  FakeWeb.register_uri(
157
157
  :get,
158
158
  %r|https://mapi\.alipay\.com/gateway\.do.*|,
159
- :body => body
159
+ body: body
160
160
  )
161
161
 
162
162
  assert_equal body, Alipay::Service.send_goods_confirm_by_platform(
163
- :trade_no => 'trade_no',
164
- :logistics_name => 'example.com',
165
- :transport_type => 'DIRECT'
163
+ trade_no: 'trade_no',
164
+ logistics_name: 'example.com',
165
+ transport_type: 'DIRECT'
166
166
  )
167
167
  end
168
+
169
+ def test_mobile_security_pay_url
170
+ assert_equal 'https://mapi.alipay.com/gateway.do?_input_charset=utf-8&partner=1000000000000000&seller_id=admin%40example.com&payment_type=1&service=mobile.securitypay.pay&out_trade_no=1&notify_url=%2Fsome_url&subject=subject&total_fee=0.01&body=test&sign_type=RSA&sign=cEpcxOIFtNJwkWL7fJx%2F%2BToy6raiLnVF3L9cBt81rUHmD9Im0pM%2FzTH57Y7v%0AXlKK8OfrM07pOLqD0mrLXsuCUU7C%2B%2BjfwUxcIixSdiwCLEsc36VsJf8Sgrt1%0Azx10SC7y2vd1Cvq0M822O86C%2FESMO1kpIdk%2BgiM%2FhjFCOKZEnLY%3D%0A', Alipay::Service.mobile_security_pay_url({
171
+ out_trade_no: '1',
172
+ notify_url: '/some_url',
173
+ subject: 'subject',
174
+ total_fee: '0.01',
175
+ body: 'test'
176
+ }, {
177
+ sign_type: 'RSA',
178
+ key: TEST_RSA_PRIVATE_KEY
179
+ })
180
+ end
168
181
  end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ class Alipay::Sign::RSATest < Minitest::Test
4
+ def setup
5
+ @string = "partner=123&service=test"
6
+ @sign = "TaVXdP/0ia5NxIv9T76v6vGOrtgoaFrwnchKIWP9PQeX1UkUVxaq6ejDFmXF\nrFR+Plk+E/XzfV2DYJSVt0Am0qJRSgeg+PuvK+yWGCGm9GJgUJlS4Eyta3g+\n8DWwRWTjUyh5yzlf9JoSnbNjYpBolnMRD7B/u1JLkTMJuMx2TVM=\n"
7
+ end
8
+
9
+ def test_sign
10
+ assert_equal @sign, Alipay::Sign::RSA.sign(TEST_RSA_PRIVATE_KEY, @string)
11
+ end
12
+
13
+ def test_verify
14
+ assert Alipay::Sign::RSA.verify?(TEST_RSA_PUBLIC_KEY, @string, @sign)
15
+ end
16
+
17
+ def test_verify_fail_when_sign_not_true
18
+ assert !Alipay::Sign::RSA.verify?(TEST_RSA_PUBLIC_KEY, "danger#{@string}", @sign)
19
+ end
20
+ end
@@ -3,8 +3,8 @@ require 'test_helper'
3
3
  class Alipay::SignTest < Minitest::Test
4
4
  def setup
5
5
  @params = {
6
- :service => 'test',
7
- :partner => '123'
6
+ service: 'test',
7
+ partner: '123'
8
8
  }
9
9
  @md5_sign = 'bbd13b52823b576291595f472ebcfbc2'
10
10
 
@@ -14,17 +14,17 @@ class Alipay::SignTest < Minitest::Test
14
14
 
15
15
  def test_generate_sign
16
16
  assert_equal @md5_sign, Alipay::Sign.generate(@params)
17
- assert_equal @md5_sign_2, Alipay::Sign.generate(@params, {:key => @key_2})
17
+ assert_equal @md5_sign_2, Alipay::Sign.generate(@params, {key: @key_2})
18
18
  end
19
19
 
20
20
  def test_verify_sign
21
- assert Alipay::Sign.verify?(@params.merge(:sign_type => 'MD5', :sign => @md5_sign))
22
- assert Alipay::Sign.verify?(@params.merge(:sign_type => 'MD5', :sign => @md5_sign_2), {:key => @key_2})
21
+ assert Alipay::Sign.verify?(@params.merge(sign_type: 'MD5', sign: @md5_sign))
22
+ assert Alipay::Sign.verify?(@params.merge(sign_type: 'MD5', sign: @md5_sign_2), {key: @key_2})
23
23
  end
24
24
 
25
25
  def test_verify_fail_when_sign_not_true
26
26
  assert !Alipay::Sign.verify?(@params)
27
- assert !Alipay::Sign.verify?(@params.merge(:danger => 'danger', :sign_type => 'MD5', :sign => @md5_sign))
28
- assert !Alipay::Sign.verify?(@params.merge(:sign_type => 'MD5', :sign => 'danger'))
27
+ assert !Alipay::Sign.verify?(@params.merge(danger: 'danger', sign_type: 'MD5', sign: @md5_sign))
28
+ assert !Alipay::Sign.verify?(@params.merge(sign_type: 'MD5', sign: 'danger'))
29
29
  end
30
30
  end
@@ -5,28 +5,28 @@ class Alipay::Wap::NotifyTest < Minitest::Test
5
5
  @notify_id = 'notify_id_test'
6
6
 
7
7
  @notify_params = {
8
- :service => 'alipay.wap.trade.create.direct',
9
- :v => '1.0',
10
- :sec_id => 'MD5',
11
- :notify_data => "<notify><notify_id>#{@notify_id}</notify_id><other_key>other_value</other_key></notify>"
8
+ service: 'alipay.wap.trade.create.direct',
9
+ v: '1.0',
10
+ sec_id: 'MD5',
11
+ notify_data: "<notify><notify_id>#{@notify_id}</notify_id><other_key>other_value</other_key></notify>"
12
12
  }
13
13
 
14
14
  query = [ :service, :v, :sec_id, :notify_data ].map {|key| "#{key}=#{@notify_params[key]}"}.join('&')
15
- @sign_params = @notify_params.merge(:sign => Digest::MD5.hexdigest("#{query}#{Alipay.key}"))
15
+ @sign_params = @notify_params.merge(sign: Digest::MD5.hexdigest("#{query}#{Alipay.key}"))
16
16
  end
17
17
 
18
18
  def test_unsign_notify
19
- FakeWeb.register_uri(:get, "https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}&notify_id=#{@notify_id}", :body => "true")
19
+ FakeWeb.register_uri(:get, "https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}&notify_id=#{@notify_id}", body: "true")
20
20
  assert !Alipay::Wap::Notify.verify?(@notify_params)
21
21
  end
22
22
 
23
23
  def test_verify_notify_when_true
24
- FakeWeb.register_uri(:get, "https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}&notify_id=#{@notify_id}", :body => "true")
24
+ FakeWeb.register_uri(:get, "https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}&notify_id=#{@notify_id}", body: "true")
25
25
  assert Alipay::Wap::Notify.verify?(@sign_params)
26
26
  end
27
27
 
28
28
  def test_verify_notify_when_false
29
- FakeWeb.register_uri(:get, "https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}&notify_id=#{@notify_id}", :body => "false")
29
+ FakeWeb.register_uri(:get, "https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}&notify_id=#{@notify_id}", body: "false")
30
30
  assert !Alipay::Wap::Notify.verify?(@sign_params)
31
31
  end
32
32
  end
@@ -20,21 +20,20 @@ class Alipay::Wap::ServiceTest < Minitest::Test
20
20
  FakeWeb.register_uri(
21
21
  :get,
22
22
  %r|https://wappaygw\.alipay\.com/service/rest\.htm.*|,
23
- :body => body
23
+ body: body
24
24
  )
25
25
 
26
26
  assert_equal token, Alipay::Wap::Service.trade_create_direct_token(
27
- :req_data => {
28
- :out_trade_no => '1',
29
- :subject => 'subject',
30
- :total_fee => '0.01',
31
- :call_back_url => 'https://example.com/call_back'
27
+ req_data: {
28
+ out_trade_no: '1',
29
+ subject: 'subject',
30
+ total_fee: '0.01',
31
+ call_back_url: 'https://example.com/call_back'
32
32
  }
33
33
  )
34
34
  end
35
35
 
36
36
  def test_auth_and_execute_url
37
- params = { :request_token => 'token_test' }
38
- assert_equal 'https://wappaygw.alipay.com/service/rest.htm?service=alipay.wap.auth.authAndExecute&req_data=%3Cauth_and_execute_req%3E%3Crequest_token%3Etoken_test%3C%2Frequest_token%3E%3C%2Fauth_and_execute_req%3E&partner=1000000000000000&format=xml&v=2.0&sec_id=MD5&sign=3efe60d4a9b7960ba599da6764c959df', Alipay::Wap::Service.auth_and_execute_url(params)
37
+ assert_equal 'https://wappaygw.alipay.com/service/rest.htm?service=alipay.wap.auth.authAndExecute&req_data=%3Cauth_and_execute_req%3E%3Crequest_token%3Etoken_test%3C%2Frequest_token%3E%3C%2Fauth_and_execute_req%3E&partner=1000000000000000&format=xml&v=2.0&sec_id=MD5&sign=3efe60d4a9b7960ba599da6764c959df', Alipay::Wap::Service.auth_and_execute_url(request_token: 'token_test')
39
38
  end
40
39
  end
@@ -3,17 +3,17 @@ require 'test_helper'
3
3
  class Alipay::Wap::SignTest < Minitest::Test
4
4
  def setup
5
5
  @params = {
6
- :v => '1.0',
7
- :sec_id => 'MD5',
8
- :service => 'test',
9
- :notify_data => 'notify_data'
6
+ v: '1.0',
7
+ sec_id: 'MD5',
8
+ service: 'test',
9
+ notify_data: 'notify_data'
10
10
  }
11
11
  @sign = Digest::MD5.hexdigest("service=test&v=1.0&sec_id=MD5&notify_data=notify_data#{Alipay.key}")
12
12
  end
13
13
 
14
14
  def test_verify_sign
15
15
  assert !Alipay::Wap::Sign.verify?(@params)
16
- assert !Alipay::Wap::Sign.verify?(@params.merge(:sec_id => 'unknow'))
17
- assert Alipay::Wap::Sign.verify?(@params.merge(:sign => @sign, :whatever => 'x'))
16
+ assert !Alipay::Wap::Sign.verify?(@params.merge(sec_id: 'unknow'))
17
+ assert Alipay::Wap::Sign.verify?(@params.merge(sign: @sign, whatever: 'x'))
18
18
  end
19
19
  end
data/test/test_helper.rb CHANGED
@@ -5,3 +5,31 @@ require 'fakeweb'
5
5
  Alipay.pid = '1000000000000000'
6
6
  Alipay.key = '10000000000000000000000000000000'
7
7
  Alipay.seller_email = 'admin@example.com'
8
+
9
+ TEST_RSA_PUBLIC_KEY = <<EOF
10
+ -----BEGIN PUBLIC KEY-----
11
+ MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCjNVhJf9PYDFN1PFd4SXEvxmjD
12
+ 0dn+xQ4lQu6o8HbGXz4de/RRVTJDL48qwxn81lar5cNSIjbnhDRXm9fZcrzuwbjq
13
+ xXOv2Ov7MZAa/WJEcfvp3XcSgxKPB54FLVvHo/rxuMK2xpps47Lpc7vppkvi3ofb
14
+ XW61S+aT0TWFkUMTnwIDAQAB
15
+ -----END PUBLIC KEY-----
16
+ EOF
17
+
18
+ TEST_RSA_PRIVATE_KEY = <<EOF
19
+ -----BEGIN PRIVATE KEY-----
20
+ MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKM1WEl/09gMU3U8
21
+ V3hJcS/GaMPR2f7FDiVC7qjwdsZfPh179FFVMkMvjyrDGfzWVqvlw1IiNueENFeb
22
+ 19lyvO7BuOrFc6/Y6/sxkBr9YkRx++nddxKDEo8HngUtW8ej+vG4wrbGmmzjsulz
23
+ u+mmS+Leh9tdbrVL5pPRNYWRQxOfAgMBAAECgYB7xOSjOJFK8m4IJi6fRfLULD8e
24
+ 4XHUR1Qm5c9fxpwMbAYLDgmF9HodgV+tKi/3EgTAb4nkK5Y/lH6tQb47ZUvo/lKz
25
+ RlIVZ6Rm76V07g/+5exIZzTyvdD9T2fLeYQwKV/2JYUv0KSYWPvWykdaV4aNkCuw
26
+ mxTUjvhDxK/Ns31CIQJBANI1Y3gGBqbBIN9wxjx3ShBtt/U8YnipUJ92eTI7OU9p
27
+ ZsCIFPoeYG/X40miwDb5ouPnvJTtzuY4PkPokEefN9MCQQDGwurqa8RNK2APA62U
28
+ CdZbJuWimkdHEc53IKvD/l2tWVFqhVAy8bs+3LGzBNfuxUuAxOoQm9n0IVRaH5jn
29
+ l8GFAkEAijuTmsUTsKsGDAmkQvULHnyYYUuBUem92+9TycWKbX9Zk7ipWsWJE2N7
30
+ 0tuU3VISXR7yM1mjGl/YCl4wKvk4AwJAE1DkBY4dkKZTeoIP/2AJXehkzq2Rmb2I
31
+ RBl/t9djgTI58FEuXxUQ7mYCOvSQi5rO4J/CY4TR5KDMksmZUYB1BQJAIEfVDxz4
32
+ 5yoHL7L+6EoC5TWxUxFMN7z7FhObyKeaLKj3inEsbjfcPCA09zPUce0FSKBc/dVh
33
+ DEorJMaPK5vXiA==
34
+ -----END PRIVATE KEY-----
35
+ EOF
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alipay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0.beta3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-02 00:00:00.000000000 Z
11
+ date: 2015-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -96,6 +96,7 @@ files:
96
96
  - test/alipay/notify_test.rb
97
97
  - test/alipay/service_test.rb
98
98
  - test/alipay/sign/md5_test.rb
99
+ - test/alipay/sign/rsa_test.rb
99
100
  - test/alipay/sign_test.rb
100
101
  - test/alipay/utils_test.rb
101
102
  - test/alipay/wap/notify_test.rb
@@ -118,9 +119,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
119
  version: '0'
119
120
  required_rubygems_version: !ruby/object:Gem::Requirement
120
121
  requirements:
121
- - - ">"
122
+ - - ">="
122
123
  - !ruby/object:Gem::Version
123
- version: 1.3.1
124
+ version: '0'
124
125
  requirements: []
125
126
  rubyforge_project:
126
127
  rubygems_version: 2.4.5
@@ -131,6 +132,7 @@ test_files:
131
132
  - test/alipay/notify_test.rb
132
133
  - test/alipay/service_test.rb
133
134
  - test/alipay/sign/md5_test.rb
135
+ - test/alipay/sign/rsa_test.rb
134
136
  - test/alipay/sign_test.rb
135
137
  - test/alipay/utils_test.rb
136
138
  - test/alipay/wap/notify_test.rb