alipay 0.7.1 → 0.8.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: 2ab4182025a5c424e036fc878d9a2ff04f200ee0
4
- data.tar.gz: 617a08da13708da51031f937dd28afebcf22b45b
3
+ metadata.gz: d3edec82f680c00773ce90092f2fa9b0d53ad176
4
+ data.tar.gz: 5657552ff665d594f71babfe43ac4f5da535e580
5
5
  SHA512:
6
- metadata.gz: ed830a42c1b9126097d744f5eb7502265f235bf9420f2c93149c2325d7d6325b48e6265e5c18f7aea855700e094bd13e21a8a850aa4133b19b128ec24efe66d8
7
- data.tar.gz: d643dbe25d39935f954002ce4ebf476545bb41b25a06e1fda0b764058139d97e3b5233ded2d7f5d69ff3f1542474bc2fb51bf235d7f41b10e2e1163bbe0eaad4
6
+ metadata.gz: 3a3bfcb3f8dab931dd2ffef9d2304fd5155b5665dd73f0ae32d72ee823d049c9146142c8f2a331af4eb8c075a89fb9e6ddee51a0641ee00bc9108680aa38ef77
7
+ data.tar.gz: 12de1a73d39b7e660a143c9f72e1e8f06e95b92c136b6ebd5200fed63282d5007a9caf8e4070c0f904954f3aab56cbafce0aab35c89b9e40a19748c0c27604d9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v0.8.0 (2015-07-20)
2
+
3
+ - Add `Alipay::Mobile::Service.mobile_security_pay_string` method, thanks @Sen #49
4
+ - Remove `Alipay::Service.mobile_security_pay_url` #49
5
+
1
6
  ## v0.7.1 (2015-04-10)
2
7
 
3
8
  - Don't warning when `rmb_fee` is used in forex_refund_url method.
data/README.md CHANGED
@@ -110,7 +110,8 @@ Alipay::Service.send_goods_confirm_by_platform({ARGUMENTS}, {OPTIONS})
110
110
  ```ruby
111
111
  Alipay::Service.send_goods_confirm_by_platform(
112
112
  trade_no: '201504010000001',
113
- logistics_name: 'example.com'
113
+ logistics_name: 'example.com',
114
+ transport_type: 'DIRECT'
114
115
  )
115
116
  # => '<!xml version="1.0" encoding="utf-8"?><alipay><is_success>T</is_success></alipay>'
116
117
  ```
@@ -121,6 +122,7 @@ Alipay::Service.send_goods_confirm_by_platform(
121
122
  | --- | ----------- | ----------- |
122
123
  | trade_no | required | Trade number in Alipay system, should get from notify message. |
123
124
  | logistics_name | required | Logistics Name. |
125
+ | transport_type/create_transport_type | required | Allowed values: POST, EXPRESS, EMS, DIRECT. |
124
126
 
125
127
  This is not a complete list of arguments, please read official document: http://download.alipay.com/public/api/base/alipayescow.zip .
126
128
 
@@ -360,7 +362,33 @@ Alipay::Service.forex_refund_url(
360
362
 
361
363
  \* Auto set Time.now if not set.
362
364
 
363
- ### 快捷支付(无线)
365
+ ### 验证通知
366
+
367
+ #### Name
368
+
369
+ ```ruby
370
+ notify_verify
371
+ ```
372
+
373
+ #### Definition
374
+
375
+ ```ruby
376
+ Alipay::Notify.verify?({PARAMS}, {OPTIONS})
377
+ ```
378
+
379
+ #### Example
380
+
381
+ ```ruby
382
+ # Rails
383
+ # params except :controller_name, :action_name, :host, etc.
384
+ notify_params = params.except(*request.path_parameters.keys)
385
+
386
+ Alipay::Notify.verify?(notify_params)
387
+ ```
388
+
389
+ ## Mobile::Service
390
+
391
+ ### 移动支付接口
364
392
 
365
393
  #### Name
366
394
 
@@ -371,19 +399,20 @@ mobile.securitypay.pay
371
399
  #### Definition
372
400
 
373
401
  ```ruby
374
- Alipay::Service.mobile_security_pay_url({ARGUMENTS}, {OPTIONS})
402
+ Alipay::Mobile::Service.mobile_security_pay_string({ARGUMENTS}, {OPTIONS})
375
403
  ```
376
404
 
377
405
  #### Example
378
406
 
379
407
  ```ruby
380
- Alipay::Service.mobile_security_pay_url(
408
+ Alipay::Mobile::Service.mobile_security_pay_string(
381
409
  out_trade_no: '20150401000-0001',
382
410
  notify_url: 'https://example.com/orders/20150401000-0001/notify'
383
411
  subject: 'subject',
384
412
  total_fee: '10.00',
385
413
  body: 'text'
386
414
  )
415
+ # => service="mobile.securitypay.pay"&_input_charset="utf-8"&partner=...
387
416
  ```
388
417
 
389
418
  #### ARGUMENTS
@@ -400,30 +429,6 @@ Alipay::Service.mobile_security_pay_url(
400
429
 
401
430
  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
431
 
403
- ### 验证通知
404
-
405
- #### Name
406
-
407
- ```ruby
408
- notify_verify
409
- ```
410
-
411
- #### Definition
412
-
413
- ```ruby
414
- Alipay::Notify.verify?({PARAMS}, {OPTIONS})
415
- ```
416
-
417
- #### Example
418
-
419
- ```ruby
420
- # Rails
421
- # params except :controller_name, :action_name, :host, etc.
422
- notify_params = params.except(*request.path_parameters.keys)
423
-
424
- Alipay::Notify.verify?(notify_params)
425
- ```
426
-
427
432
  ## Wap::Service
428
433
 
429
434
  ### 授权接口
@@ -485,13 +490,13 @@ alipay.wap.auth.authAndExecute
485
490
  #### Definition
486
491
 
487
492
  ```ruby
488
- Alipay::Wap::Service.auth_and_execute({ARGUMENTS}, {OPTIONS})
493
+ Alipay::Wap::Service.auth_and_execute_url({ARGUMENTS}, {OPTIONS})
489
494
  ```
490
495
 
491
496
  #### Example
492
497
 
493
498
  ```ruby
494
- Alipay::Wap::Service.auth_and_execute(request_token: token)
499
+ Alipay::Wap::Service.auth_and_execute_url(request_token: token)
495
500
  ```
496
501
  #### ARGUMENTS
497
502
 
data/lib/alipay.rb CHANGED
@@ -11,6 +11,8 @@ require 'alipay/notify'
11
11
  require 'alipay/wap/service'
12
12
  require 'alipay/wap/notify'
13
13
  require 'alipay/wap/sign'
14
+ require 'alipay/mobile/service'
15
+ require 'alipay/mobile/sign'
14
16
 
15
17
  module Alipay
16
18
  @debug_mode = true
@@ -0,0 +1,27 @@
1
+ module Alipay
2
+ module Mobile
3
+ module Service
4
+ MOBILE_SECURITY_PAY_REQUIRED_PARAMS = %w( notify_url out_trade_no subject total_fee body )
5
+ def self.mobile_securitypay_pay_string(params, options = {})
6
+ params = Utils.stringify_keys(params)
7
+ Alipay::Service.check_required_params(params, MOBILE_SECURITY_PAY_REQUIRED_PARAMS)
8
+ sign_type = options[:sign_type] || Alipay.sign_type
9
+ key = options[:key] || Alipay.key
10
+ raise ArgumentError, "only support RSA sign_type" if sign_type != 'RSA'
11
+
12
+ params = {
13
+ 'service' => 'mobile.securitypay.pay',
14
+ '_input_charset' => 'utf-8',
15
+ 'partner' => options[:pid] || Alipay.pid,
16
+ 'seller_id' => options[:pid] || Alipay.pid,
17
+ 'payment_type' => '1'
18
+ }.merge(params)
19
+
20
+ string = Alipay::Mobile::Sign.params_to_string(params)
21
+ sign = CGI.escape(Alipay::Sign::RSA.sign(key, string))
22
+
23
+ %Q(#{string}&sign="#{sign}"&sign_type="RSA")
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ module Alipay
2
+ module Mobile
3
+ module Sign
4
+ def self.params_to_string(params)
5
+ params.map { |key, value| %Q(#{key}="#{value}") }.join('&')
6
+ end
7
+ end
8
+ end
9
+ end
@@ -162,24 +162,6 @@ module Alipay
162
162
  Net::HTTP.get(request_uri(params, options))
163
163
  end
164
164
 
165
- MOBILD_SECURITY_PAY_REQUIRED_PARAMS = %w( notify_url out_trade_no subject total_fee body )
166
- def self.mobile_security_pay_url(params, options = {})
167
- params = Utils.stringify_keys(params)
168
- check_required_params(params, MOBILD_SECURITY_PAY_REQUIRED_PARAMS)
169
- sign_type = options[:sign_type] || Alipay.sign_type
170
- raise ArgumentError, "only support RSA sign_type" if sign_type != 'RSA'
171
-
172
- params = {
173
- 'service' => 'mobile.securitypay.pay',
174
- '_input_charset' => 'utf-8',
175
- 'partner' => options[:pid] || Alipay.pid,
176
- 'seller_id' => options[:pid] || Alipay.pid,
177
- 'payment_type' => '1'
178
- }.merge(params)
179
-
180
- request_uri(params, options).to_s
181
- end
182
-
183
165
  def self.request_uri(params, options = {})
184
166
  uri = URI(GATEWAY_URL)
185
167
  uri.query = URI.encode_www_form(sign_params(params, options))
@@ -6,12 +6,12 @@ module Alipay
6
6
  class RSA
7
7
  def self.sign(key, string)
8
8
  rsa = OpenSSL::PKey::RSA.new(key)
9
- Base64.encode64(rsa.sign('sha1', string))
9
+ Base64.strict_encode64(rsa.sign('sha1', string))
10
10
  end
11
11
 
12
12
  def self.verify?(key, string, sign)
13
13
  rsa = OpenSSL::PKey::RSA.new(key)
14
- rsa.verify('sha1', Base64.decode64(sign), string)
14
+ rsa.verify('sha1', Base64.strict_decode64(sign), string)
15
15
  end
16
16
  end
17
17
  end
@@ -1,3 +1,3 @@
1
1
  module Alipay
2
- VERSION = "0.7.1"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -17,7 +17,7 @@ Udmh5Ua2xg6IEfk493VQIDAQAB
17
17
 
18
18
  case params['sec_id']
19
19
  when 'MD5'
20
- key = options[:pid] || Alipay.key
20
+ key = options[:key] || Alipay.key
21
21
  ::Alipay::Sign::MD5.verify?(key, string, sign)
22
22
  when '0001' # RSA
23
23
  ::Alipay::Sign::RSA.verify?(ALIPAY_RSA_PUBLIC_KEY, string, sign)
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ class Alipay::Mobile::ServiceTest < Minitest::Test
4
+ def test_mobile_securitypay_pay_string
5
+ assert_equal %q(service="mobile.securitypay.pay"&_input_charset="utf-8"&partner="1000000000000000"&seller_id="1000000000000000"&payment_type="1"&out_trade_no="1"&notify_url="/some_url"&subject="subject"&total_fee="0.01"&body="test"&sign="if1qjK4qnT7eQ5fw%2BBddHhO1LY6iuPY9Xmhkx81YKuCdceKWBdv798j%2BrxF9ZAhNW4Y3TMURm%2BXpgxhOh8lj8vorFup%2BMJ6fe2rXRWgxFhK9B8xuP2XH%2F3878g6d8Jq2D2gINTgDDL7%2BB5%2FIWWlwInas40cQTsVngG8mWkzB788%3D"&sign_type="RSA"), Alipay::Mobile::Service.mobile_securitypay_pay_string({
6
+ out_trade_no: '1',
7
+ notify_url: '/some_url',
8
+ subject: 'subject',
9
+ total_fee: '0.01',
10
+ body: 'test'
11
+ }, {
12
+ sign_type: 'RSA',
13
+ key: TEST_RSA_PRIVATE_KEY
14
+ })
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class Alipay::Mobile::SignTest < Minitest::Test
4
+ def test_params_to_string
5
+ assert_equal %q(a="1"&b="2"), Alipay::Mobile::Sign.params_to_string(a: 1, b: 2)
6
+ end
7
+ end
@@ -165,17 +165,4 @@ class Alipay::ServiceTest < Minitest::Test
165
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?service=mobile.securitypay.pay&_input_charset=utf-8&partner=1000000000000000&seller_id=1000000000000000&payment_type=1&out_trade_no=1&notify_url=%2Fsome_url&subject=subject&total_fee=0.01&body=test&sign_type=RSA&sign=EuHBKhLyXFBFM28s8nNM45r4gIWccPijVl8SHAmRaAC11wFNRiOfc3jEzJYJ%0A%2FADJNytARSNVSu3vXvRWhsNDHE9%2F%2BkFRckoXjjC10IApWa8bN7%2ByfHQk2w88%0AkDEVfv9Z%2F0t%2B8yHZD0Po4OBBHoEC9d%2FodPZYBElfcQvJ5vilQsc%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
181
168
  end
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  class Alipay::Sign::RSATest < Minitest::Test
4
4
  def setup
5
5
  @string = "partner=123&service=test"
6
- @sign = "TaVXdP/0ia5NxIv9T76v6vGOrtgoaFrwnchKIWP9PQeX1UkUVxaq6ejDFmXF\nrFR+Plk+E/XzfV2DYJSVt0Am0qJRSgeg+PuvK+yWGCGm9GJgUJlS4Eyta3g+\n8DWwRWTjUyh5yzlf9JoSnbNjYpBolnMRD7B/u1JLkTMJuMx2TVM=\n"
6
+ @sign = "TaVXdP/0ia5NxIv9T76v6vGOrtgoaFrwnchKIWP9PQeX1UkUVxaq6ejDFmXFrFR+Plk+E/XzfV2DYJSVt0Am0qJRSgeg+PuvK+yWGCGm9GJgUJlS4Eyta3g+8DWwRWTjUyh5yzlf9JoSnbNjYpBolnMRD7B/u1JLkTMJuMx2TVM="
7
7
  end
8
8
 
9
9
  def test_sign
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.7.1
4
+ version: 0.8.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-10 00:00:00.000000000 Z
11
+ date: 2015-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -82,6 +82,8 @@ files:
82
82
  - Rakefile
83
83
  - alipay.gemspec
84
84
  - lib/alipay.rb
85
+ - lib/alipay/mobile/service.rb
86
+ - lib/alipay/mobile/sign.rb
85
87
  - lib/alipay/notify.rb
86
88
  - lib/alipay/service.rb
87
89
  - lib/alipay/sign.rb
@@ -93,6 +95,8 @@ files:
93
95
  - lib/alipay/wap/notify.rb
94
96
  - lib/alipay/wap/service.rb
95
97
  - lib/alipay/wap/sign.rb
98
+ - test/alipay/mobile/service_test.rb
99
+ - test/alipay/mobile/sign_test.rb
96
100
  - test/alipay/notify_test.rb
97
101
  - test/alipay/service_test.rb
98
102
  - test/alipay/sign/md5_test.rb
@@ -124,11 +128,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
128
  version: '0'
125
129
  requirements: []
126
130
  rubyforge_project:
127
- rubygems_version: 2.4.5
131
+ rubygems_version: 2.4.7
128
132
  signing_key:
129
133
  specification_version: 4
130
134
  summary: An unofficial simple alipay gem
131
135
  test_files:
136
+ - test/alipay/mobile/service_test.rb
137
+ - test/alipay/mobile/sign_test.rb
132
138
  - test/alipay/notify_test.rb
133
139
  - test/alipay/service_test.rb
134
140
  - test/alipay/sign/md5_test.rb