alipay 0.0.1 → 0.0.2
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/README.md +15 -8
- data/alipay.gemspec +1 -1
- data/lib/alipay/notify.rb +2 -2
- data/lib/alipay/service.rb +26 -26
- data/lib/alipay/sign.rb +3 -3
- data/lib/alipay/utils.rb +2 -2
- data/lib/alipay/version.rb +1 -1
- data/test/alipay/utils_test.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88d669e91705790c16000241168d66901de8d477
|
4
|
+
data.tar.gz: 9c99d503d9f08840a5d4184a5eac0289e15bfe59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f01a960ef34e8742828c63691ed400d96318585db592f03fae3d633d2b081a632764fc1c56a78852becba9239c64a5c53874b66ee49ebd9e46b0243b2c1a37d
|
7
|
+
data.tar.gz: 81b2d0743a4f7904002c523cf2a67196b1fe5615b59200808d910a719185b22a662ee3d26cb90f9545c8893d938bf7015c7628abc01283f5ba77fb474729f08e
|
data/README.md
CHANGED
@@ -6,14 +6,20 @@ It contain this API:
|
|
6
6
|
|
7
7
|
* Generate payment url
|
8
8
|
* Send goods
|
9
|
-
* Verify
|
9
|
+
* Verify notify
|
10
10
|
|
11
|
-
Please read alipay official document first: https://b.alipay.com/order/techService.htm
|
11
|
+
Please read alipay official document first: https://b.alipay.com/order/techService.htm .
|
12
12
|
|
13
13
|
## Installation
|
14
14
|
|
15
15
|
Add this line to your application's Gemfile:
|
16
16
|
|
17
|
+
```ruby
|
18
|
+
gem 'alipay', '~> 0.0.2'
|
19
|
+
```
|
20
|
+
|
21
|
+
or development version
|
22
|
+
|
17
23
|
```ruby
|
18
24
|
gem 'alipay', :github => 'chloerei/alipay'
|
19
25
|
```
|
@@ -26,7 +32,7 @@ $ bundle
|
|
26
32
|
|
27
33
|
## Usage
|
28
34
|
|
29
|
-
###
|
35
|
+
### Config
|
30
36
|
|
31
37
|
```ruby
|
32
38
|
Alipay.pid = 'YOUR_PID'
|
@@ -66,7 +72,7 @@ Current support three payment type:
|
|
66
72
|
|
67
73
|
```ruby
|
68
74
|
options = {
|
69
|
-
:trade_no => '
|
75
|
+
:trade_no => 'TRADE_NO',
|
70
76
|
:logistics_name => 'writings.io',
|
71
77
|
:transport_type => 'DIRECT'
|
72
78
|
}
|
@@ -75,13 +81,14 @@ Alipay::Service.send_goods_confirm_by_platform(options)
|
|
75
81
|
# => '<!xml version="1.0" encoding="utf-8"?><alipay><is_success>T</is_success></alipay>'
|
76
82
|
```
|
77
83
|
|
78
|
-
### Verify
|
84
|
+
### Verify notify
|
79
85
|
|
80
86
|
```ruby
|
81
|
-
#
|
87
|
+
# example in rails
|
82
88
|
# The notify url MUST be set when generate payment url
|
83
89
|
def alipay_notify
|
84
|
-
|
90
|
+
# except :controller_name, :action_name, :host, etc.
|
91
|
+
notify_params = params.except(*request.path_parameters.keys)
|
85
92
|
if Alipay::Notify.verify?(notify_params)
|
86
93
|
# valid notify, code your business logic.
|
87
94
|
render :text => 'success'
|
@@ -93,7 +100,7 @@ end
|
|
93
100
|
|
94
101
|
## Contributing
|
95
102
|
|
96
|
-
Bug report or pull request
|
103
|
+
Bug report or pull request are welcome.
|
97
104
|
|
98
105
|
### Make a pull request
|
99
106
|
|
data/alipay.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["chloerei@gmail.com"]
|
11
11
|
spec.description = %q{An unofficial simple alipay gem}
|
12
12
|
spec.summary = %q{An unofficial simple alipay gem}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/chloerei/alipay"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
data/lib/alipay/notify.rb
CHANGED
@@ -2,8 +2,8 @@ module Alipay
|
|
2
2
|
class Notify
|
3
3
|
def self.verify?(params)
|
4
4
|
if Sign.verify?(params)
|
5
|
-
params = Utils.
|
6
|
-
open("https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}¬ify_id=#{CGI.escape params[
|
5
|
+
params = Utils.stringify_keys(params)
|
6
|
+
open("https://mapi.alipay.com/gateway.do?service=notify_verify&partner=#{Alipay.pid}¬ify_id=#{CGI.escape params['notify_id'].to_s}").read == 'true'
|
7
7
|
else
|
8
8
|
false
|
9
9
|
end
|
data/lib/alipay/service.rb
CHANGED
@@ -9,12 +9,12 @@ module Alipay
|
|
9
9
|
# alipayescow
|
10
10
|
def self.create_partner_trade_by_buyer_url(options)
|
11
11
|
options = {
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
}.merge(Utils.
|
12
|
+
'service' => 'create_partner_trade_by_buyer',
|
13
|
+
'_input_charset' => 'utf-8',
|
14
|
+
'partner' => Alipay.pid,
|
15
|
+
'seller_email' => Alipay.seller_email,
|
16
|
+
'payment_type' => '1'
|
17
|
+
}.merge(Utils.stringify_keys(options))
|
18
18
|
|
19
19
|
check_required_options(options, TRADE_CREATE_BY_BUYER_REQUIRED_OPTIONS)
|
20
20
|
|
@@ -25,12 +25,12 @@ module Alipay
|
|
25
25
|
# alipaydualfun
|
26
26
|
def self.trade_create_by_buyer_url(options = {})
|
27
27
|
options = {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
}.merge(Utils.
|
28
|
+
'service' => 'trade_create_by_buyer',
|
29
|
+
'_input_charset' => 'utf-8',
|
30
|
+
'partner' => Alipay.pid,
|
31
|
+
'seller_email' => Alipay.seller_email,
|
32
|
+
'payment_type' => '1'
|
33
|
+
}.merge(Utils.stringify_keys(options))
|
34
34
|
|
35
35
|
check_required_options(options, TRADE_CREATE_BY_BUYER_REQUIRED_OPTIONS)
|
36
36
|
|
@@ -41,16 +41,16 @@ module Alipay
|
|
41
41
|
# direct
|
42
42
|
def self.create_direct_pay_by_user_url(options)
|
43
43
|
options = {
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
}.merge(Utils.
|
44
|
+
'service' => 'create_direct_pay_by_user',
|
45
|
+
'_input_charset' => 'utf-8',
|
46
|
+
'partner' => Alipay.pid,
|
47
|
+
'seller_email' => Alipay.seller_email,
|
48
|
+
'payment_type' => '1'
|
49
|
+
}.merge(Utils.stringify_keys(options))
|
50
50
|
|
51
51
|
check_required_options(options, CREATE_DIRECT_PAY_BY_USER_REQUIRED_OPTIONS)
|
52
52
|
|
53
|
-
if options[
|
53
|
+
if options['total_fee'].nil? and (options['price'].nil? || options['quantity'].nil?)
|
54
54
|
warn("Ailpay Warn: total_fee or (price && quantiry) must have one")
|
55
55
|
end
|
56
56
|
|
@@ -60,14 +60,14 @@ module Alipay
|
|
60
60
|
SEND_GOODS_CONFIRM_BY_PLATFORM_REQUIRED_OPTIONS = %w( service partner _input_charset trade_no logistics_name )
|
61
61
|
def self.send_goods_confirm_by_platform(options)
|
62
62
|
options = {
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
}.merge(Utils.
|
63
|
+
'service' => 'send_goods_confirm_by_platform',
|
64
|
+
'partner' => Alipay.pid,
|
65
|
+
'_input_charset' => 'utf-8'
|
66
|
+
}.merge(Utils.stringify_keys(options))
|
67
67
|
|
68
68
|
check_required_options(options, SEND_GOODS_CONFIRM_BY_PLATFORM_REQUIRED_OPTIONS)
|
69
69
|
|
70
|
-
if options[
|
70
|
+
if options['transport_type'].nil? and options['create_transport_type'].nil?
|
71
71
|
warn("Ailpay Warn: transport_type or create_transport_type must have one")
|
72
72
|
end
|
73
73
|
|
@@ -75,14 +75,14 @@ module Alipay
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def self.query_string(options)
|
78
|
-
options.merge(
|
78
|
+
options.merge('sign_type' => 'MD5', 'sign' => Alipay::Sign.generate(options)).map do |key, value|
|
79
79
|
"#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}"
|
80
80
|
end.join('&')
|
81
81
|
end
|
82
82
|
|
83
83
|
def self.check_required_options(options, names)
|
84
84
|
names.each do |name|
|
85
|
-
warn("Ailpay Warn: missing required option: #{name}") unless options.has_key?(name
|
85
|
+
warn("Ailpay Warn: missing required option: #{name}") unless options.has_key?(name)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
data/lib/alipay/sign.rb
CHANGED
@@ -11,9 +11,9 @@ module Alipay
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.verify?(params)
|
14
|
-
params = Utils.
|
15
|
-
params.delete(
|
16
|
-
sign = params.delete(
|
14
|
+
params = Utils.stringify_keys(params)
|
15
|
+
params.delete('sign_type')
|
16
|
+
sign = params.delete('sign')
|
17
17
|
|
18
18
|
generate(params) == sign
|
19
19
|
end
|
data/lib/alipay/utils.rb
CHANGED
data/lib/alipay/version.rb
CHANGED
data/test/alipay/utils_test.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class Alipay::UtilsTest < Test::Unit::TestCase
|
4
|
-
def
|
4
|
+
def test_stringify_keys
|
5
5
|
hash = { 'a' => 1, :b => 2 }
|
6
|
-
assert_equal({
|
6
|
+
assert_equal({ 'a' => 1, 'b' => 2 }.sort, Alipay::Utils.stringify_keys(hash).sort)
|
7
7
|
end
|
8
8
|
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.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rei
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,7 +76,7 @@ files:
|
|
76
76
|
- test/alipay/sign_test.rb
|
77
77
|
- test/alipay/utils_test.rb
|
78
78
|
- test/test_helper.rb
|
79
|
-
homepage:
|
79
|
+
homepage: https://github.com/chloerei/alipay
|
80
80
|
licenses:
|
81
81
|
- MIT
|
82
82
|
metadata: {}
|