alipay 0.2.0 → 0.3.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: a82251b3f0f9bf268033359506be8a6f6057498f
4
- data.tar.gz: 9942b8e00d07cba64b1e911395a5a74b1936184b
3
+ metadata.gz: dbf13c5cf133ea25199a7ed7e051c1f6546d5e04
4
+ data.tar.gz: a4fc849d912fd9090a679b88f602d186940acb3c
5
5
  SHA512:
6
- metadata.gz: 4983fcb2e960b7e6ccc9ad3bc16d1c4c625b963eaffafa45938be676f3b1119790019ead77a0278eaddcedf8b4c4b66a030dc6c30c727871e1ca46744742524c
7
- data.tar.gz: b44a46ab7f5fd8b465375965ab99546e5bda8f2c32c9ab8ea455e8d2a6a39124f537695cfd4b7cb04914f187e741413abac32dbaad779307ed8c89604386e32d
6
+ metadata.gz: 1209e5d64b493f3cd0e3fcc8a511bfef6f9146eff3b0df5f139bb0451b5af707c8fc0d5376574f31da6b3aa765792c426cfd70512dbf61be09f67953c5764040
7
+ data.tar.gz: e19ff49a78fb10d7d5c394b7deff1295405dea96425b58e422347931a8ab112c980d1e839d55d74a262718cdb41c33a075494fbb68fbfd8eca0a542fd53b370f
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
+ ## v0.3.0 (2014-12-10)
2
+
3
+ - Add `close_trade` service. by @linjunpop #16
4
+
1
5
  ## v0.2.0 (2014-12-03)
2
6
 
3
- - Add `create_forex_trade` service. by @christophe-dufour
7
+ - Add `create_forex_trade` service. by @christophe-dufour #15
4
8
 
5
9
  ## v0.1.0 (2014-06-15)
6
10
 
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
@@ -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)}"
@@ -1,3 +1,3 @@
1
1
  module Alipay
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -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.2.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-03 00:00:00.000000000 Z
11
+ date: 2014-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler