alipay 0.5.0 → 0.6.0.beta1
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 +4 -4
- data/CHANGELOG.md +14 -0
- data/alipay.gemspec +1 -0
- data/lib/alipay.rb +8 -5
- data/lib/alipay/notify.rb +1 -19
- data/lib/alipay/notify/wap.rb +12 -0
- data/lib/alipay/service.rb +18 -14
- data/lib/alipay/service/wap.rb +11 -10
- data/lib/alipay/sign.rb +49 -34
- data/lib/alipay/sign/wap.rb +17 -0
- data/lib/alipay/version.rb +1 -1
- data/test/alipay/notify/wap_test.rb +1 -1
- data/test/alipay/notify_test.rb +4 -3
- data/test/alipay/service/wap_test.rb +5 -5
- data/test/alipay/service_test.rb +25 -23
- data/test/alipay/sign/wap_test.rb +1 -1
- data/test/alipay/sign_test.rb +9 -5
- data/test/alipay/utils_test.rb +1 -1
- data/test/alipay_test.rb +11 -0
- data/test/test_helper.rb +4 -5
- metadata +23 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bab9b64bdcabb60a0b79b493c3e78593a054d7c1
|
4
|
+
data.tar.gz: 07a77403d825afd35f50c31ddbc37ab8233db8eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de941fe25b59b27f1945a216c70e6e9324564dfe222414dbcb4ed48a2df4c0fb485424d533c50c7f1aaed32a7c6f7b04f72839cf1e49cefe7ffcb204a4d035c2
|
7
|
+
data.tar.gz: e27a47136177767eb98388791d2887b8ab8c4260920b6f220fe14cb13cf0760edc5969961ba785c2bc0f5478c840a64f1cf382c5d9b0f1cd16233bfd8c21497a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## v0.6.0-beta1
|
2
|
+
|
3
|
+
Usage:
|
4
|
+
|
5
|
+
- Add `Alipay.sign_type`, default is 'MD5', 'RSA' and 'DSA' will implemented in the future.
|
6
|
+
- Remove `Sign::App.verify?`, use `Sign.verify_rsa?` instead.
|
7
|
+
- Remove `Notify::App.verify?`, use `Notify.verify?` instead.
|
8
|
+
- Rename `Service::Wap.auth_and_execute` to `Service::Wap.auth_and_execute_url`
|
9
|
+
|
10
|
+
Development:
|
11
|
+
|
12
|
+
- Update Test::Unit to Minitest.
|
13
|
+
- Fxied test case data.
|
14
|
+
|
1
15
|
## v0.5.0 (2015-03-09)
|
2
16
|
|
3
17
|
- Add `forex_single_refund` service.
|
data/alipay.gemspec
CHANGED
data/lib/alipay.rb
CHANGED
@@ -1,19 +1,22 @@
|
|
1
|
+
require 'net/http'
|
1
2
|
require 'alipay/version'
|
2
3
|
require 'alipay/utils'
|
3
4
|
require 'alipay/sign'
|
5
|
+
require 'alipay/sign/wap'
|
4
6
|
require 'alipay/service'
|
5
7
|
require 'alipay/service/wap'
|
6
8
|
require 'alipay/notify'
|
9
|
+
require 'alipay/notify/wap'
|
7
10
|
|
8
11
|
module Alipay
|
12
|
+
@debug_mode = true
|
13
|
+
@sign_type = 'MD5'
|
14
|
+
|
9
15
|
class << self
|
10
|
-
attr_accessor :pid
|
11
|
-
attr_accessor :key
|
12
|
-
attr_accessor :seller_email
|
13
|
-
attr_writer :debug_mode
|
16
|
+
attr_accessor :pid, :key, :seller_email, :sign_type, :debug_mode
|
14
17
|
|
15
18
|
def debug_mode?
|
16
|
-
|
19
|
+
!!@debug_mode
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
data/lib/alipay/notify.rb
CHANGED
@@ -1,30 +1,12 @@
|
|
1
1
|
module Alipay
|
2
2
|
module Notify
|
3
|
-
module Wap
|
4
|
-
def self.verify?(params)
|
5
|
-
params = Utils.stringify_keys(params)
|
6
|
-
notify_id = params['notify_data'].scan(/\<notify_id\>(.*)\<\/notify_id\>/).flatten.first
|
7
|
-
|
8
|
-
Sign::Wap.verify?(params) && Notify.verify_notify_id?(notify_id)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
module App
|
13
|
-
def self.verify?(params)
|
14
|
-
params = Utils.stringify_keys(params)
|
15
|
-
Sign::App.verify?(params) && Notify.verify_notify_id?(params['notify_id'])
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
3
|
def self.verify?(params)
|
20
4
|
params = Utils.stringify_keys(params)
|
21
5
|
Sign.verify?(params) && verify_notify_id?(params['notify_id'])
|
22
6
|
end
|
23
7
|
|
24
|
-
private
|
25
|
-
|
26
8
|
def self.verify_notify_id?(notify_id)
|
27
|
-
|
9
|
+
Net::HTTP.get(URI("https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}¬ify_id=#{CGI.escape(notify_id.to_s)}")) == 'true'
|
28
10
|
end
|
29
11
|
end
|
30
12
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Alipay
|
2
|
+
module Notify
|
3
|
+
module Wap
|
4
|
+
def self.verify?(params)
|
5
|
+
params = Utils.stringify_keys(params)
|
6
|
+
notify_id = params['notify_data'].scan(/\<notify_id\>(.*)\<\/notify_id\>/).flatten.first
|
7
|
+
|
8
|
+
Sign::Wap.verify?(params) && Notify.verify_notify_id?(notify_id)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/alipay/service.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'cgi'
|
2
|
-
require 'open-uri'
|
3
2
|
|
4
3
|
module Alipay
|
5
4
|
module Service
|
@@ -18,7 +17,7 @@ module Alipay
|
|
18
17
|
|
19
18
|
check_required_options(options, CREATE_PARTNER_TRADE_BY_BUYER_REQUIRED_OPTIONS)
|
20
19
|
|
21
|
-
|
20
|
+
request_uri(options).to_s
|
22
21
|
end
|
23
22
|
|
24
23
|
TRADE_CREATE_BY_BUYER_REQUIRED_OPTIONS = %w( service partner _input_charset out_trade_no subject payment_type logistics_type logistics_fee logistics_payment seller_email price quantity )
|
@@ -34,7 +33,7 @@ module Alipay
|
|
34
33
|
|
35
34
|
check_required_options(options, TRADE_CREATE_BY_BUYER_REQUIRED_OPTIONS)
|
36
35
|
|
37
|
-
|
36
|
+
request_uri(options).to_s
|
38
37
|
end
|
39
38
|
|
40
39
|
CREATE_DIRECT_PAY_BY_USER_REQUIRED_OPTIONS = %w( service partner _input_charset out_trade_no subject payment_type seller_email )
|
@@ -54,7 +53,7 @@ module Alipay
|
|
54
53
|
warn("Ailpay Warn: total_fee or (price && quantiry) must have one")
|
55
54
|
end
|
56
55
|
|
57
|
-
|
56
|
+
request_uri(options).to_s
|
58
57
|
end
|
59
58
|
|
60
59
|
CREATE_REFUND_URL_REQUIRED_OPTIONS = %w( batch_no data notify_url )
|
@@ -79,7 +78,7 @@ module Alipay
|
|
79
78
|
'detail_data' => detail_data # 转换后的单笔数据集字符串
|
80
79
|
}.merge(options)
|
81
80
|
|
82
|
-
|
81
|
+
request_uri(options).to_s
|
83
82
|
end
|
84
83
|
|
85
84
|
CREATE_FOREX_SINGLE_REFUND_URL_REQUIRED_OPTIONS = %w( out_return_no out_trade_no return_amount currency reason )
|
@@ -98,7 +97,7 @@ module Alipay
|
|
98
97
|
|
99
98
|
check_required_options(options, CREATE_FOREX_SINGLE_REFUND_URL_REQUIRED_OPTIONS)
|
100
99
|
|
101
|
-
|
100
|
+
request_uri(options).to_s
|
102
101
|
end
|
103
102
|
|
104
103
|
SEND_GOODS_CONFIRM_BY_PLATFORM_REQUIRED_OPTIONS = %w( service partner _input_charset trade_no logistics_name )
|
@@ -115,7 +114,7 @@ module Alipay
|
|
115
114
|
warn("Ailpay Warn: transport_type or create_transport_type must have one")
|
116
115
|
end
|
117
116
|
|
118
|
-
|
117
|
+
Net::HTTP.get(request_uri(options))
|
119
118
|
end
|
120
119
|
|
121
120
|
CREATE_FOREX_TRADE_REQUIRED_OPTIONS = %w(service partner _input_charset notify_url subject out_trade_no currency total_fee)
|
@@ -129,7 +128,7 @@ module Alipay
|
|
129
128
|
|
130
129
|
check_required_options(options, CREATE_FOREX_TRADE_REQUIRED_OPTIONS)
|
131
130
|
|
132
|
-
|
131
|
+
request_uri(options).to_s
|
133
132
|
end
|
134
133
|
|
135
134
|
CLOSE_TRADE_REQUIRED_OPTIONS = %w( service partner _input_charset)
|
@@ -144,7 +143,7 @@ module Alipay
|
|
144
143
|
check_required_options(options, CLOSE_TRADE_REQUIRED_OPTIONS)
|
145
144
|
check_optional_options(options, CLOSE_TRADE_REQUIRED_OPTIONAL_OPTIONS)
|
146
145
|
|
147
|
-
|
146
|
+
Net::HTTP.get(request_uri(options))
|
148
147
|
end
|
149
148
|
|
150
149
|
SINGLE_TRADE_QUERY_OPTIONS = %w( service partner _input_charset)
|
@@ -159,13 +158,18 @@ module Alipay
|
|
159
158
|
check_required_options(options, SINGLE_TRADE_QUERY_OPTIONS)
|
160
159
|
check_optional_options(options, SINGLE_TRADE_QUERY_OPTIONAL_OPTIONS)
|
161
160
|
|
162
|
-
|
161
|
+
Net::HTTP.get(request_uri(options))
|
163
162
|
end
|
164
163
|
|
165
|
-
def self.
|
166
|
-
|
167
|
-
|
168
|
-
|
164
|
+
def self.request_uri(options)
|
165
|
+
uri = URI(GATEWAY_URL)
|
166
|
+
uri.query = URI.encode_www_form(sign_params(options))
|
167
|
+
uri
|
168
|
+
end
|
169
|
+
|
170
|
+
def self.sign_params(params)
|
171
|
+
params = params.merge('sign_type' => Alipay.sign_type) if params['sign_type'].nil?
|
172
|
+
params.merge('sign' => Alipay::Sign.generate(params))
|
169
173
|
end
|
170
174
|
|
171
175
|
def self.check_required_options(options, names)
|
data/lib/alipay/service/wap.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
|
3
1
|
module Alipay
|
4
2
|
module Service
|
5
3
|
module Wap
|
@@ -32,13 +30,13 @@ module Alipay
|
|
32
30
|
|
33
31
|
Alipay::Service.check_required_options(options, WAP_TRADE_REQUIRED_OPTIONS)
|
34
32
|
|
35
|
-
xml =
|
33
|
+
xml = Net::HTTP.get(request_uri(options))
|
36
34
|
CGI.unescape(xml).scan(/\<request_token\>(.*)\<\/request_token\>/).flatten.first
|
37
35
|
end
|
38
36
|
|
39
37
|
AUTH_AND_EXECUTE_REQUIRED_OPTIONS = %w( service format v partner )
|
40
38
|
|
41
|
-
def self.
|
39
|
+
def self.auth_and_execute_url(options)
|
42
40
|
options = Utils.stringify_keys(options)
|
43
41
|
Alipay::Service.check_required_options(options, ['request_token'])
|
44
42
|
|
@@ -53,15 +51,18 @@ module Alipay
|
|
53
51
|
}.merge(options)
|
54
52
|
|
55
53
|
Alipay::Service.check_required_options(options, AUTH_AND_EXECUTE_REQUIRED_OPTIONS)
|
56
|
-
|
54
|
+
request_uri(options).to_s
|
57
55
|
end
|
58
56
|
|
59
|
-
def self.
|
60
|
-
|
57
|
+
def self.request_uri(options)
|
58
|
+
uri = URI(GATEWAY_URL)
|
59
|
+
uri.query = URI.encode_www_form(sign_params(options))
|
60
|
+
uri
|
61
|
+
end
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
def self.sign_params(params)
|
64
|
+
sign_type = (params['sec_id'] ||= Alipay.sign_type)
|
65
|
+
params.merge('sign' => Alipay::Sign.generate(params.merge('sign_type' => sign_type)))
|
65
66
|
end
|
66
67
|
end
|
67
68
|
end
|
data/lib/alipay/sign.rb
CHANGED
@@ -5,53 +5,68 @@ require 'base64'
|
|
5
5
|
module Alipay
|
6
6
|
module Sign
|
7
7
|
def self.generate(params)
|
8
|
-
query = params.sort.map { |item| item.join('=') }.join('&')
|
9
|
-
Digest::MD5.hexdigest("#{query}#{Alipay.key}")
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.verify?(params)
|
13
8
|
params = Utils.stringify_keys(params)
|
14
|
-
params.delete('sign_type')
|
15
|
-
|
9
|
+
sign_type = params.delete('sign_type') || Alipay.sign_type
|
10
|
+
key = params.delete('key') || Alipay.key
|
16
11
|
|
17
|
-
|
12
|
+
case sign_type
|
13
|
+
when 'MD5'
|
14
|
+
generate_md5(key, params)
|
15
|
+
when 'RSA'
|
16
|
+
raise NotImplementedError, "RSA sign is unimplemented"
|
17
|
+
when 'DSA'
|
18
|
+
raise NotImplementedError, "DSA sign is unimplemented"
|
19
|
+
else
|
20
|
+
raise ArgumentError, "wrong sign_type #{sign_type}, allow values: 'MD5', 'RSA', 'DSA'"
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
|
-
|
21
|
-
|
24
|
+
def self.generate_md5(key, params)
|
25
|
+
Digest::MD5.hexdigest("#{params_to_string(params)}#{key}")
|
26
|
+
end
|
22
27
|
|
23
|
-
|
24
|
-
|
28
|
+
def self.params_to_string(params)
|
29
|
+
params.sort.map { |item| item.join('=') }.join('&')
|
30
|
+
end
|
25
31
|
|
26
|
-
|
27
|
-
|
28
|
-
|
32
|
+
def self.verify?(params)
|
33
|
+
params = Utils.stringify_keys(params)
|
34
|
+
|
35
|
+
sign_type = params.delete('sign_type')
|
29
36
|
|
30
|
-
|
37
|
+
case sign_type
|
38
|
+
when 'MD5'
|
39
|
+
verify_md5?(params)
|
40
|
+
when 'RSA'
|
41
|
+
verify_rsa?(params)
|
42
|
+
when 'DSA'
|
43
|
+
raise NotImplementedError, "DSA verify is unimplemented"
|
44
|
+
else
|
45
|
+
raise ArgumentError, "wrong sign_type #{sign_type}, allow values: 'MD5', 'RSA', 'DSA'"
|
31
46
|
end
|
32
47
|
end
|
33
48
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
"B/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5Ksi\n" \
|
40
|
-
"NG9zpgmLCUYuLkxpLQIDAQAB\n" \
|
41
|
-
"-----END PUBLIC KEY-----"
|
42
|
-
|
43
|
-
def self.verify?(params)
|
44
|
-
params = Utils.stringify_keys(params)
|
49
|
+
def self.verify_md5?(params)
|
50
|
+
key = params.delete('key') || Alipay.key
|
51
|
+
sign = params.delete('sign')
|
52
|
+
generate_md5(key, params) == sign
|
53
|
+
end
|
45
54
|
|
46
|
-
|
47
|
-
|
55
|
+
ALIPAY_RSA_PUBLIC_KEY = <<-EOF
|
56
|
+
-----BEGIN PUBLIC KEY-----
|
57
|
+
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRA
|
58
|
+
FljhNhgPdyPuBV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQE
|
59
|
+
B/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5Ksi
|
60
|
+
NG9zpgmLCUYuLkxpLQIDAQAB
|
61
|
+
-----END PUBLIC KEY-----
|
62
|
+
EOF
|
48
63
|
|
49
|
-
|
50
|
-
|
51
|
-
|
64
|
+
def self.verify_rsa?(params)
|
65
|
+
pkey = OpenSSL::PKey::RSA.new(ALIPAY_RSA_PUBLIC_KEY)
|
66
|
+
digest = OpenSSL::Digest::SHA1.new
|
67
|
+
sign = params.delete('sign')
|
52
68
|
|
53
|
-
|
54
|
-
end
|
69
|
+
pkey.verify(digest, Base64.decode64(sign), params_to_string(params))
|
55
70
|
end
|
56
71
|
end
|
57
72
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Alipay
|
2
|
+
module Sign
|
3
|
+
module Wap
|
4
|
+
SORTED_VERIFY_PARAMS = %w( service v sec_id notify_data )
|
5
|
+
|
6
|
+
def self.verify?(params)
|
7
|
+
params = Utils.stringify_keys(params)
|
8
|
+
|
9
|
+
query = SORTED_VERIFY_PARAMS.map do |key|
|
10
|
+
"#{key}=#{params[key]}"
|
11
|
+
end.join('&')
|
12
|
+
|
13
|
+
params['sign'] == Digest::MD5.hexdigest("#{query}#{Alipay.key}")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/alipay/version.rb
CHANGED
data/test/alipay/notify_test.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class Alipay::NotifyTest < Test
|
3
|
+
class Alipay::NotifyTest < Minitest::Test
|
4
4
|
def setup
|
5
5
|
@options = {
|
6
|
-
:notify_id => '1234'
|
6
|
+
:notify_id => '1234',
|
7
|
+
:sign_type => 'MD5'
|
7
8
|
}
|
8
|
-
@sign_options = @options.merge(:
|
9
|
+
@sign_options = @options.merge(:sign => Alipay::Sign.generate(@options))
|
9
10
|
end
|
10
11
|
|
11
12
|
def test_unsign_notify
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class Alipay::Service::WapTest < Test
|
3
|
+
class Alipay::Service::WapTest < Minitest::Test
|
4
4
|
def test_trade_create_direct_token
|
5
5
|
token = 'REQUEST_TOKEN'
|
6
6
|
body = <<-EOS
|
@@ -26,15 +26,15 @@ class Alipay::Service::WapTest < Test::Unit::TestCase
|
|
26
26
|
assert_equal token, Alipay::Service::Wap.trade_create_direct_token(
|
27
27
|
:req_data => {
|
28
28
|
:out_trade_no => '1',
|
29
|
-
:subject => '
|
29
|
+
:subject => 'subject',
|
30
30
|
:total_fee => '0.01',
|
31
|
-
:call_back_url => '
|
31
|
+
:call_back_url => 'https://example.com/call_back'
|
32
32
|
}
|
33
33
|
)
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
36
|
+
def test_auth_and_execute_url
|
37
37
|
options = { :request_token => 'token_test' }
|
38
|
-
|
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::Service::Wap.auth_and_execute_url(options)
|
39
39
|
end
|
40
40
|
end
|
data/test/alipay/service_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class Alipay::ServiceTest < Test
|
3
|
+
class Alipay::ServiceTest < Minitest::Test
|
4
4
|
def test_generate_create_partner_trade_by_buyer_url
|
5
5
|
options = {
|
6
6
|
:out_trade_no => '1',
|
@@ -11,7 +11,8 @@ class Alipay::ServiceTest < Test::Unit::TestCase
|
|
11
11
|
:price => '0.01',
|
12
12
|
:quantity => 1
|
13
13
|
}
|
14
|
-
|
14
|
+
|
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)
|
15
16
|
end
|
16
17
|
|
17
18
|
def test_generate_trade_create_by_buyer_url
|
@@ -24,7 +25,7 @@ class Alipay::ServiceTest < Test::Unit::TestCase
|
|
24
25
|
:price => '0.01',
|
25
26
|
:quantity => 1
|
26
27
|
}
|
27
|
-
|
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)
|
28
29
|
end
|
29
30
|
|
30
31
|
def test_generate_create_direct_pay_by_user_url
|
@@ -34,7 +35,7 @@ class Alipay::ServiceTest < Test::Unit::TestCase
|
|
34
35
|
:price => '0.01',
|
35
36
|
:quantity => 1
|
36
37
|
}
|
37
|
-
|
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)
|
38
39
|
end
|
39
40
|
|
40
41
|
def test_generate_create_refund_url
|
@@ -44,34 +45,35 @@ class Alipay::ServiceTest < Test::Unit::TestCase
|
|
44
45
|
:reason => 'test'
|
45
46
|
}]
|
46
47
|
options = {
|
47
|
-
:batch_no
|
48
|
-
:data
|
49
|
-
:notify_url
|
48
|
+
:batch_no => '123456789',
|
49
|
+
:data => data,
|
50
|
+
:notify_url => '/some_url',
|
51
|
+
:refund_date => '2015-01-01 00:00:00'
|
50
52
|
}
|
51
|
-
|
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¬ify_url=%2Fsome_url&sign_type=MD5&sign=3f5be5655b513334460a511e74a9ae57", Alipay::Service.create_refund_url(options)
|
52
54
|
end
|
53
55
|
|
54
56
|
def test_generate_create_forex_single_refund_url
|
55
57
|
options = {
|
56
58
|
:out_return_no => '1',
|
57
59
|
:out_trade_no => '12345678980',
|
58
|
-
:return_amount => 0.01,
|
60
|
+
:return_amount => '0.01',
|
59
61
|
:currency => 'USD',
|
60
|
-
:reason => '
|
62
|
+
:reason => 'reason',
|
63
|
+
:gmt_return => '2015-01-01 00:00:00'
|
61
64
|
}
|
62
|
-
|
65
|
+
assert_equal 'https://mapi.alipay.com/gateway.do?service=forex_refund&partner=1000000000000000&_input_charset=utf-8&gmt_return=2015-01-01+00%3A00%3A00&out_return_no=1&out_trade_no=12345678980&return_amount=0.01¤cy=USD&reason=reason&sign_type=MD5&sign=123c50e884e560801fee8b73f1ac6172', Alipay::Service.create_forex_single_refund_url(options)
|
63
66
|
end
|
64
67
|
|
65
68
|
def test_generate_create_forex_trade
|
66
69
|
options = {
|
67
|
-
:notify_url => 'https://
|
68
|
-
:return_url => 'https://writings.io/orders/20130801000001',
|
70
|
+
:notify_url => 'https://example.com/notify',
|
69
71
|
:subject => 'test',
|
70
72
|
:out_trade_no => '1',
|
71
73
|
:currency => 'EUR',
|
72
|
-
:total_fee => '0.
|
74
|
+
:total_fee => '0.01',
|
73
75
|
}
|
74
|
-
|
76
|
+
assert_equal 'https://mapi.alipay.com/gateway.do?service=create_forex_trade&_input_charset=utf-8&partner=1000000000000000&seller_email=admin%40example.com¬ify_url=https%3A%2F%2Fexample.com%2Fnotify&subject=test&out_trade_no=1¤cy=EUR&total_fee=0.01&sign_type=MD5&sign=495a0e610134aa33f6ce021f8b8c6c8d', Alipay::Service.create_forex_trade(options)
|
75
77
|
end
|
76
78
|
|
77
79
|
def test_close_trade
|
@@ -88,7 +90,7 @@ class Alipay::ServiceTest < Test::Unit::TestCase
|
|
88
90
|
)
|
89
91
|
|
90
92
|
assert_equal response_body, Alipay::Service.close_trade(
|
91
|
-
:out_order_no => '
|
93
|
+
:out_order_no => '1'
|
92
94
|
)
|
93
95
|
end
|
94
96
|
|
@@ -106,7 +108,7 @@ class Alipay::ServiceTest < Test::Unit::TestCase
|
|
106
108
|
<response>
|
107
109
|
<trade>
|
108
110
|
<additional_trade_status>DAEMON_CONFIRM_CLOSE</additional_trade_status>
|
109
|
-
<buyer_email>
|
111
|
+
<buyer_email>buyer@example.com</buyer_email>
|
110
112
|
<buyer_id>BUYER_ID</buyer_id>
|
111
113
|
<discount>0.00</discount>
|
112
114
|
<flag_trade_locked>0</flag_trade_locked>
|
@@ -115,11 +117,11 @@ class Alipay::ServiceTest < Test::Unit::TestCase
|
|
115
117
|
<gmt_last_modified_time>2015-01-20 02:37:00</gmt_last_modified_time>
|
116
118
|
<is_total_fee_adjust>F</is_total_fee_adjust>
|
117
119
|
<operator_role>B</operator_role>
|
118
|
-
<out_trade_no>
|
120
|
+
<out_trade_no>1</out_trade_no>
|
119
121
|
<payment_type>1</payment_type>
|
120
122
|
<price>640.00</price>
|
121
123
|
<quantity>1</quantity>
|
122
|
-
<seller_email>
|
124
|
+
<seller_email>seller@example.com</seller_email>
|
123
125
|
<seller_id>SELLER_ID</seller_id>
|
124
126
|
<subject>ORDER SUBJECT</subject>
|
125
127
|
<to_buyer_fee>0.00</to_buyer_fee>
|
@@ -140,7 +142,7 @@ class Alipay::ServiceTest < Test::Unit::TestCase
|
|
140
142
|
)
|
141
143
|
|
142
144
|
assert_equal response_body, Alipay::Service.single_trade_query(
|
143
|
-
:out_trade_no => '
|
145
|
+
:out_trade_no => '1'
|
144
146
|
)
|
145
147
|
end
|
146
148
|
|
@@ -158,9 +160,9 @@ class Alipay::ServiceTest < Test::Unit::TestCase
|
|
158
160
|
)
|
159
161
|
|
160
162
|
assert_equal body, Alipay::Service.send_goods_confirm_by_platform(
|
161
|
-
:trade_no => '
|
162
|
-
:logistics_name => '
|
163
|
-
:transport_type => '
|
163
|
+
:trade_no => 'trade_no',
|
164
|
+
:logistics_name => 'example.com',
|
165
|
+
:transport_type => 'DIRECT'
|
164
166
|
)
|
165
167
|
end
|
166
168
|
end
|
data/test/alipay/sign_test.rb
CHANGED
@@ -1,23 +1,27 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class Alipay::SignTest < Test
|
3
|
+
class Alipay::SignTest < Minitest::Test
|
4
4
|
def setup
|
5
5
|
@params = {
|
6
6
|
:service => 'test',
|
7
7
|
:partner => '123'
|
8
8
|
}
|
9
|
-
@
|
9
|
+
@md5_sign = 'bbd13b52823b576291595f472ebcfbc2'
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_generate_sign
|
13
|
-
assert_equal @
|
13
|
+
assert_equal @md5_sign, Alipay::Sign.generate(@params)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_generate_md5_sign
|
17
|
+
assert_equal @md5_sign, Alipay::Sign.generate_md5(Alipay.key, @params)
|
14
18
|
end
|
15
19
|
|
16
20
|
def test_verify_sign
|
17
|
-
assert Alipay::Sign.verify?(@params.merge(:sign => @
|
21
|
+
assert Alipay::Sign.verify?(@params.merge(:sign_type => 'MD5', :sign => @md5_sign))
|
18
22
|
end
|
19
23
|
|
20
24
|
def test_verify_sign_when_fails
|
21
|
-
assert !Alipay::Sign.verify?(@params.merge(:danger => 'danger', :sign => @
|
25
|
+
assert !Alipay::Sign.verify?(@params.merge(:danger => 'danger', :sign_type => 'MD5', :sign => @md5_sign))
|
22
26
|
end
|
23
27
|
end
|
data/test/alipay/utils_test.rb
CHANGED
data/test/alipay_test.rb
ADDED
data/test/test_helper.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
require '
|
1
|
+
require 'minitest/autorun'
|
2
2
|
require 'alipay'
|
3
3
|
require 'fakeweb'
|
4
4
|
|
5
|
-
Alipay.pid = '
|
6
|
-
Alipay.key = '
|
7
|
-
Alipay.seller_email = '
|
8
|
-
Alipay.debug_mode = true
|
5
|
+
Alipay.pid = '1000000000000000'
|
6
|
+
Alipay.key = '10000000000000000000000000000000'
|
7
|
+
Alipay.seller_email = 'admin@example.com'
|
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.
|
4
|
+
version: 0.6.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rei
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: fakeweb
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,9 +82,11 @@ files:
|
|
68
82
|
- alipay.gemspec
|
69
83
|
- lib/alipay.rb
|
70
84
|
- lib/alipay/notify.rb
|
85
|
+
- lib/alipay/notify/wap.rb
|
71
86
|
- lib/alipay/service.rb
|
72
87
|
- lib/alipay/service/wap.rb
|
73
88
|
- lib/alipay/sign.rb
|
89
|
+
- lib/alipay/sign/wap.rb
|
74
90
|
- lib/alipay/utils.rb
|
75
91
|
- lib/alipay/version.rb
|
76
92
|
- test/alipay/notify/wap_test.rb
|
@@ -80,6 +96,7 @@ files:
|
|
80
96
|
- test/alipay/sign/wap_test.rb
|
81
97
|
- test/alipay/sign_test.rb
|
82
98
|
- test/alipay/utils_test.rb
|
99
|
+
- test/alipay_test.rb
|
83
100
|
- test/test_helper.rb
|
84
101
|
homepage: https://github.com/chloerei/alipay
|
85
102
|
licenses:
|
@@ -96,12 +113,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
113
|
version: '0'
|
97
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
115
|
requirements:
|
99
|
-
- - "
|
116
|
+
- - ">"
|
100
117
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
118
|
+
version: 1.3.1
|
102
119
|
requirements: []
|
103
120
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.4.5
|
105
122
|
signing_key:
|
106
123
|
specification_version: 4
|
107
124
|
summary: An unofficial simple alipay gem
|
@@ -113,5 +130,5 @@ test_files:
|
|
113
130
|
- test/alipay/sign/wap_test.rb
|
114
131
|
- test/alipay/sign_test.rb
|
115
132
|
- test/alipay/utils_test.rb
|
133
|
+
- test/alipay_test.rb
|
116
134
|
- test/test_helper.rb
|
117
|
-
has_rdoc:
|