alipay 0.12.0 → 0.13.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: a6c47eb0017c87754f2dfbe7725e7f12532740db
4
- data.tar.gz: 4db8b524aa7e1eaaa3436fa5137f8e72d2b487b4
3
+ metadata.gz: 50fd317ffe0f09e6373ee108b7c639a86b26124b
4
+ data.tar.gz: 59797caf889f4329bef61678c54f554725882f79
5
5
  SHA512:
6
- metadata.gz: 0818757fdbbbe1d3785fab7c18c4eec38ef00d24fa41c7607ad407f843aff3d1363500cd30fa2d20d407153f839c4cb434457a22b8053af6670d0599713cfbaf
7
- data.tar.gz: fd2402ebf88fa4da70d6fb9365368a71a1cd7e882761ace065445cebce017ae8c6787edf6d6a5254e89d21885fd71b5a19210dc6705419d5550de052a834907a
6
+ metadata.gz: e268d0cab27568b13cecb7c3e9b4ad0e8598fbc06cd58b4dc2269baae4b6dd9961363a8c6ccee9ecfac204688df62d327ec409e751cc499820bddc2251f7deff
7
+ data.tar.gz: 2b7cadd3ef6b1eb7192f8c0d541538a660a14433e296c6525da160ce9dec294f5bdcaad8a86b399e407b909337bd2e549315b404fa0e231bea3240c5cf61a270
@@ -1,5 +1,9 @@
1
1
  ## master
2
2
 
3
+ ## v0.13.0 (2016-12-24)
4
+
5
+ 1 Add `Alipay::App::Service.alipay_trade_app_pay` method, thanks @FX-HAO #64
6
+
3
7
  ## v0.12.0 (2016-03-07)
4
8
 
5
9
  - Add `Alipay::Service::batch_trans_notify_url` method, thanks @ryancheung #58
data/README.md CHANGED
@@ -9,7 +9,7 @@ Alipay official document: https://b.alipay.com/order/techService.htm .
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'alipay', '~> 0.12.0'
12
+ gem 'alipay', '~> 0.13.0'
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -534,6 +534,58 @@ Alipay::Mobile::Service.mobile_securitypay_pay_string(
534
534
 
535
535
  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 .
536
536
 
537
+ ### APP支付接口
538
+
539
+ #### Name
540
+
541
+ ```ruby
542
+ alipay.trade.app.pay
543
+ ```
544
+
545
+ #### Definition
546
+
547
+ ```ruby
548
+ Alipay::App::Service.alipay_trade_app_pay({ARGUMENTS}, {OPTIONS})
549
+ ```
550
+
551
+ #### Example
552
+
553
+ ```ruby
554
+ biz_content = {
555
+ 'body': body, 'out_trade_no': out_trade_no, 'passback_params': passback_params,
556
+ 'product_code': 'QUICK_MSECURITY_PAY', 'subject': subject, 'total_amount': total_amount
557
+ }.to_json
558
+
559
+ Alipay::App::Service.alipay_trade_app_pay(
560
+ notify_url: 'https://example.com/orders/20150401000-0001/notify',
561
+ app_id: '1234567890',
562
+ biz_content: biz_content
563
+ )
564
+ # => service="alipay.trade.app.pay"&_input_charset="utf-8"&partner=...
565
+ ```
566
+
567
+ #### ARGUMENTS
568
+
569
+ | Key | Requirement | Description |
570
+ | --- | ----------- | ----------- |
571
+ | app_id | required | Application-assigned id |
572
+ | out_trade_no | required | Order number in your application. |
573
+ | notify_url | required | Alipay asyn notify url. |
574
+ | subject | required | Order subject. |
575
+ | total_amount | required | Order total price. |
576
+ | body | required | Order body, less than 512 bytes. |
577
+ | biz_content | required | A list of business parameters |
578
+
579
+ \* This service only support RSA sign_type.
580
+
581
+ This is not a complete list of arguments, please read official document: https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.vwh1xQ&treeId=193&articleId=105465&docType=1 .
582
+
583
+ #### APP支付验证通知
584
+
585
+ ```ruby
586
+ Alipay::App::Sign.verify?(params)
587
+ ```
588
+
537
589
  ## Wap::Service
538
590
 
539
591
  ### 授权接口
@@ -13,6 +13,8 @@ require 'alipay/wap/notify'
13
13
  require 'alipay/wap/sign'
14
14
  require 'alipay/mobile/service'
15
15
  require 'alipay/mobile/sign'
16
+ require 'alipay/app/service'
17
+ require 'alipay/app/sign'
16
18
 
17
19
  module Alipay
18
20
  @debug_mode = true
@@ -0,0 +1,27 @@
1
+ module Alipay
2
+ module App
3
+ module Service
4
+ ALIPAY_TRADE_APP_PAY_REQUIRED_PARAMS = %w( app_id biz_content notify_url )
5
+
6
+ def self.alipay_trade_app_pay(params, options = {})
7
+ params = Utils.stringify_keys(params)
8
+ Alipay::Service.check_required_params(params, ALIPAY_TRADE_APP_PAY_REQUIRED_PARAMS)
9
+ key = options[:key] || Alipay.key
10
+
11
+ params = {
12
+ 'method' => 'alipay.trade.app.pay',
13
+ 'charset' => 'utf-8',
14
+ 'version' => '1.0',
15
+ 'timestamp' => Time.now.utc.strftime('%Y-%m-%d %H:%M:%S').to_s,
16
+ 'sign_type' => 'RSA'
17
+ }.merge(params)
18
+
19
+ string = Alipay::App::Sign.params_to_sorted_string(params)
20
+ sign = CGI.escape(Alipay::Sign::RSA.sign(key, string))
21
+ encoded_string = Alipay::App::Sign.params_to_encoded_string(params)
22
+
23
+ %Q(#{encoded_string}&sign=#{sign})
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,39 @@
1
+ require 'erb'
2
+
3
+ module Alipay
4
+ module App
5
+ module Sign
6
+ ALIPAY_RSA_PUBLIC_KEY = <<-EOF
7
+ -----BEGIN PUBLIC KEY-----
8
+ MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDI6d306Q8fIfCOaTXyiUeJHkr
9
+ IvYISRcc73s3vF1ZT7XN8RNPwJxo8pWaJMmvyTn9N4HQ632qJBVHf8sxHi/fEsra
10
+ prwCtzvzQETrNRwVxLO5jVmRGi60j8Ue1efIlzPXV9je9mkjzOmdssymZkh2QhUr
11
+ CmZYI/FCEa3/cNMW0QIDAQAB
12
+ -----END PUBLIC KEY-----
13
+ EOF
14
+
15
+ def self.verify?(params)
16
+ params = ::Alipay::Utils.stringify_keys(params)
17
+
18
+ sign_type = params.delete('sign_type')
19
+ sign = params.delete('sign')
20
+ string = ::Alipay::Sign.params_to_string(params)
21
+
22
+ case sign_type
23
+ when 'RSA'
24
+ ::Alipay::Sign::RSA.verify?(ALIPAY_RSA_PUBLIC_KEY, string, sign)
25
+ else
26
+ false
27
+ end
28
+ end
29
+
30
+ def self.params_to_sorted_string(params)
31
+ params.sort.map { |key, value| %Q(#{key}=#{value.to_s}) }.join('&')
32
+ end
33
+
34
+ def self.params_to_encoded_string(params)
35
+ params.sort.map { |key, value| %Q(#{key}=#{ERB::Util.url_encode(value.to_s)}) }.join('&')
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module Alipay
2
- VERSION = "0.12.0"
2
+ VERSION = "0.13.0"
3
3
  end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ class Alipay::Mobile::ServiceTest < Minitest::Test
4
+ def test_mobile_securitypay_pay_string
5
+ assert_equal %q(app_id=2015052600090779&biz_content=%7B%3Atimeout_express%3D%3E%2230m%22%2C%20%3Aseller_id%3D%3E%22%22%2C%20%3Aproduct_code%3D%3E%22QUICK_MSECURITY_PAY%22%2C%20%3Atotal_amount%3D%3E%220.01%22%2C%20%3Asubject%3D%3E%221%22%2C%20%3Abody%3D%3E%22%E6%88%91%E6%98%AF%E6%B5%8B%E8%AF%95%E6%95%B0%E6%8D%AE%22%2C%20%3Aout_trade_no%3D%3E%22IQJZSRC1YMQB5HU%22%7D&charset=utf-8&format=json&method=alipay.trade.app.pay&notify_url=http%3A%2F%2Fdomain.merchant.com%2Fpayment_notify&sign_type=RSA&timestamp=2016-08-25%2020%3A26%3A31&version=1.0&sign=lT%2BwWRpKYDP4QLm8Ore6ngGQv8aHGPw1OuI2e8pRf5aWO55sTAYqN01uJyKDe3Swzat8UYdvby8o9haA3LPQibYXB2sezkZxOBHpfdKVRjXe0u9qTMlACAQUQLQeXQFNfcWRgKUGNLMHARv7ajqz8tCnDN2B3mlAmKs0r4qb6IM%3D), Alipay::App::Service.alipay_trade_app_pay({
6
+ app_id: '2015052600090779',
7
+ biz_content: {:timeout_express=>"30m",:seller_id=>"",:product_code=>"QUICK_MSECURITY_PAY",:total_amount=>"0.01",:subject=>"1",:body=>"我是测试数据",:out_trade_no=>"IQJZSRC1YMQB5HU"},
8
+ charset: 'utf-8',
9
+ format: 'json',
10
+ method: 'alipay.trade.app.pay',
11
+ notify_url: 'http://domain.merchant.com/payment_notify',
12
+ sign_type: 'RSA',
13
+ timestamp: '2016-08-25 20:26:31',
14
+ version: '1.0'
15
+ }, {
16
+ sign_type: 'RSA',
17
+ key: TEST_RSA_PRIVATE_KEY
18
+ })
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+
3
+ class Alipay::App::SignTest < Minitest::Test
4
+ def test_params_to_sorted_string
5
+ assert_equal %q(a=2&b=1), Alipay::App::Sign.params_to_sorted_string(b: 1, a: 2)
6
+ end
7
+
8
+ def test_params_to_encoded_string
9
+ assert_equal %q(biz_content=%7B%3Aname%3D%3E%22%E9%A1%BA%E9%81%93%22%7D&out_trade_no=MEM1234567&total_amount=0.01), Alipay::App::Sign.params_to_encoded_string(
10
+ biz_content: {:name=>'顺道'},
11
+ out_trade_no: 'MEM1234567',
12
+ total_amount: '0.01'
13
+ )
14
+ end
15
+ end
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.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-07 00:00:00.000000000 Z
11
+ date: 2016-12-24 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/app/service.rb
86
+ - lib/alipay/app/sign.rb
85
87
  - lib/alipay/mobile/service.rb
86
88
  - lib/alipay/mobile/sign.rb
87
89
  - lib/alipay/notify.rb
@@ -95,6 +97,8 @@ files:
95
97
  - lib/alipay/wap/notify.rb
96
98
  - lib/alipay/wap/service.rb
97
99
  - lib/alipay/wap/sign.rb
100
+ - test/alipay/app/service_test.rb
101
+ - test/alipay/app/sign_test.rb
98
102
  - test/alipay/mobile/service_test.rb
99
103
  - test/alipay/mobile/sign_test.rb
100
104
  - test/alipay/notify_test.rb
@@ -128,11 +132,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
132
  version: '0'
129
133
  requirements: []
130
134
  rubyforge_project:
131
- rubygems_version: 2.5.1
135
+ rubygems_version: 2.5.2
132
136
  signing_key:
133
137
  specification_version: 4
134
138
  summary: An unofficial simple alipay gem
135
139
  test_files:
140
+ - test/alipay/app/service_test.rb
141
+ - test/alipay/app/sign_test.rb
136
142
  - test/alipay/mobile/service_test.rb
137
143
  - test/alipay/mobile/sign_test.rb
138
144
  - test/alipay/notify_test.rb