alipay 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +23 -0
- data/lib/alipay/service.rb +17 -1
- data/lib/alipay/version.rb +1 -1
- data/test/alipay/service_test.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbf13c5cf133ea25199a7ed7e051c1f6546d5e04
|
4
|
+
data.tar.gz: a4fc849d912fd9090a679b88f602d186940acb3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1209e5d64b493f3cd0e3fcc8a511bfef6f9146eff3b0df5f139bb0451b5af707c8fc0d5376574f31da6b3aa765792c426cfd70512dbf61be09f67953c5764040
|
7
|
+
data.tar.gz: e19ff49a78fb10d7d5c394b7deff1295405dea96425b58e422347931a8ab112c980d1e839d55d74a262718cdb41c33a075494fbb68fbfd8eca0a542fd53b370f
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -6,6 +6,7 @@ It contain this API:
|
|
6
6
|
|
7
7
|
* Generate payment url (web, wap)
|
8
8
|
* Send goods
|
9
|
+
* Close trade
|
9
10
|
* Verify notify (web, wap, app)
|
10
11
|
|
11
12
|
Please read alipay official document first: https://b.alipay.com/order/techService.htm .
|
@@ -105,6 +106,28 @@ Alipay::Service.send_goods_confirm_by_platform(options)
|
|
105
106
|
# => '<!xml version="1.0" encoding="utf-8"?><alipay><is_success>T</is_success></alipay>'
|
106
107
|
```
|
107
108
|
|
109
|
+
### Close trade
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
Alipay::Service.close_trade(
|
113
|
+
:trade_no => 'TRADE_NO',
|
114
|
+
:out_order_no => 'the-out-order-no'
|
115
|
+
)
|
116
|
+
# => '<?xml version="1.0" encoding="utf-8"?><alipay><is_success>T</is_success></alipay>'
|
117
|
+
```
|
118
|
+
|
119
|
+
You must specify either `trade_no` or `out_order_no`.
|
120
|
+
|
121
|
+
If Alipay fail to close trade, this method will return XML similar to:
|
122
|
+
|
123
|
+
```xml
|
124
|
+
<?xml version="1.0" encoding="utf-8"?>
|
125
|
+
<alipay>
|
126
|
+
<is_success>F</is_success>
|
127
|
+
<error>TRADE_STATUS_NOT_AVAILD</error>
|
128
|
+
</alipay>
|
129
|
+
```
|
130
|
+
|
108
131
|
### Refund
|
109
132
|
|
110
133
|
```ruby
|
data/lib/alipay/service.rb
CHANGED
@@ -99,7 +99,6 @@ module Alipay
|
|
99
99
|
open("#{GATEWAY_URL}?#{query_string(options)}").read
|
100
100
|
end
|
101
101
|
|
102
|
-
|
103
102
|
CREATE_FOREX_TRADE_REQUIRED_OPTIONS = %w(service partner _input_charset notify_url subject out_trade_no currency total_fee)
|
104
103
|
def self.create_forex_trade(options)
|
105
104
|
options = {
|
@@ -114,6 +113,23 @@ module Alipay
|
|
114
113
|
"#{GATEWAY_URL}?#{query_string(options)}"
|
115
114
|
end
|
116
115
|
|
116
|
+
CLOSE_TRADE_REQUIRED_OPTIONS = %w( service partner _input_charset)
|
117
|
+
def self.close_trade(options)
|
118
|
+
options = {
|
119
|
+
'service' => 'close_trade',
|
120
|
+
'_input_charset' => 'utf-8',
|
121
|
+
'partner' => Alipay.pid
|
122
|
+
}.merge(Utils.stringify_keys(options))
|
123
|
+
|
124
|
+
check_required_options(options, CLOSE_TRADE_REQUIRED_OPTIONS)
|
125
|
+
|
126
|
+
if options['trade_no'].nil? and options['out_order_no'].nil?
|
127
|
+
warn("Ailpay Warn: must specify either trade_no or out_order_no")
|
128
|
+
end
|
129
|
+
|
130
|
+
open("#{GATEWAY_URL}?#{query_string(options)}").read
|
131
|
+
end
|
132
|
+
|
117
133
|
def self.query_string(options)
|
118
134
|
options.merge('sign_type' => 'MD5', 'sign' => Alipay::Sign.generate(options)).map do |key, value|
|
119
135
|
"#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}"
|
data/lib/alipay/version.rb
CHANGED
data/test/alipay/service_test.rb
CHANGED
@@ -63,6 +63,23 @@ class Alipay::ServiceTest < Test::Unit::TestCase
|
|
63
63
|
assert_not_nil Alipay::Service.create_forex_trade(options)
|
64
64
|
end
|
65
65
|
|
66
|
+
def test_close_trade
|
67
|
+
response_body = <<-EOF
|
68
|
+
<?xml version="1.0" encoding="utf-8"?>
|
69
|
+
<alipay>
|
70
|
+
<is_success>T</is_success>
|
71
|
+
</alipay>
|
72
|
+
EOF
|
73
|
+
FakeWeb.register_uri(
|
74
|
+
:get,
|
75
|
+
%r|https://mapi\.alipay\.com/gateway\.do.*|,
|
76
|
+
:body => response_body
|
77
|
+
)
|
78
|
+
|
79
|
+
assert_equal response_body, Alipay::Service.close_trade(
|
80
|
+
:out_order_no => 'the-out-order-no'
|
81
|
+
)
|
82
|
+
end
|
66
83
|
|
67
84
|
def test_should_send_goods_confirm_by_platform
|
68
85
|
body = <<-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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rei
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|