alipay 0.3.1 → 0.4.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: 1d0263d712442ba533d3fb7cca219555ba9da7b6
4
- data.tar.gz: 84207578dd886906c9c6c682e637a56d0f247081
3
+ metadata.gz: c8ae97dc76dc98045ecff6a9e98ad1dca72a6d8e
4
+ data.tar.gz: 82a2d12669ddf0a1ece485b56db7591f503c166b
5
5
  SHA512:
6
- metadata.gz: a198e204920d8b1c04ff4d4aa970524702478adeac9fcf61b4f0074c75eca23fab9c80b3009cb6324367d62cc3a06363bc74c9de7be7efb64c098da9b66b8fce
7
- data.tar.gz: 49556906be591bef1d1b9a54ba61a91e6ea0712d96beca27fd988937221a48b7139681cccf8564ebc8f291bbb5444d88aa505525173175321b09539209d82c73
6
+ metadata.gz: 27f157fc206253037e9753eb450f0a17f05ee8cb88d599f1a8f33be5166a1ccf481a4e9a8227f7e4fb223b6d6359b0d5fef34653d32a7fcea729cd199a6e67ec
7
+ data.tar.gz: 5b876eb6dcac358e66bed557dc1acfc72bf3110b274a48cae55174496d7779b4cde89f85949c7e37d94e7267a837d8dfb76d8d133a38f43c373f905277041074
@@ -1,3 +1,7 @@
1
+ ## v0.4.0 (2015-01-23)
2
+
3
+ - Add `single_trade_query` service. #19
4
+
1
5
  ## v0.3.1 (2015-01-15)
2
6
 
3
7
  - Fix xml encoding #18
data/README.md CHANGED
@@ -45,8 +45,8 @@ Alipay.seller_email = 'YOUR_SELLER_EMAIL'
45
45
 
46
46
  ```ruby
47
47
  options = {
48
- :out_trade_no => 'YOUR_ORDER_ID', # 20130801000001
49
- :subject => 'YOUR_ORDER_SUBJECCT', # Writings.io Base Account x 12
48
+ :out_trade_no => 'YOUR_ORDER_ID',
49
+ :subject => 'YOUR_ORDER_SUBJECCT',
50
50
  :logistics_type => 'DIRECT',
51
51
  :logistics_fee => '0',
52
52
  :logistics_payment => 'SELLER_PAY',
@@ -128,6 +128,18 @@ If Alipay fail to close trade, this method will return XML similar to:
128
128
  </alipay>
129
129
  ```
130
130
 
131
+ ## Single trade query
132
+
133
+ The parameters same as [Close trade](#user-content-close-trade)
134
+
135
+ ```ruby
136
+ Alipay::Service.single_trade_query(
137
+ :trade_no => 'TRADE_NO',
138
+ :out_order_no => 'the-out-order-no'
139
+ )
140
+ # => '<?xml version="1.0" encoding="utf-8"?><alipay><is_success>T</is_success><request><param name="trade_no">TRADE_NO</param><param name="_input_charset">utf-8</param><param name="service">single_trade_query</param><param name="partner">PARTNER</param></request><response><trade><additional_trade_status>DAEMON_CONFIRM_CLOSE</additional_trade_status><buyer_email>foo@gmail.com</buyer_email><buyer_id>BUYER_ID</buyer_id><discount>0.00</discount><flag_trade_locked>0</flag_trade_locked><gmt_close>2015-01-20 02:37:00</gmt_close><gmt_create>2015-01-20 02:17:00</gmt_create><gmt_last_modified_time>2015-01-20 02:37:00</gmt_last_modified_time><is_total_fee_adjust>F</is_total_fee_adjust><operator_role>B</operator_role><out_trade_no>OUT_TRADE_NO</out_trade_no><payment_type>1</payment_type><price>640.00</price><quantity>1</quantity><seller_email>bar@example.com</seller_email><seller_id>SELLER_ID</seller_id><subject>YOUR ORDER SUBJECT</subject><to_buyer_fee>0.00</to_buyer_fee><to_seller_fee>0.00</to_seller_fee><total_fee>640.00</total_fee><trade_no>TRADE_NO</trade_no><trade_status>TRADE_CLOSED</trade_status><use_coupon>F</use_coupon></trade></response><sign>SIGN</sign><sign_type>MD5</sign_type></alipay>'
141
+ ```
142
+
131
143
  ### Refund
132
144
 
133
145
  ```ruby
@@ -114,6 +114,7 @@ module Alipay
114
114
  end
115
115
 
116
116
  CLOSE_TRADE_REQUIRED_OPTIONS = %w( service partner _input_charset)
117
+ CLOSE_TRADE_REQUIRED_OPTIONAL_OPTIONS = %w( trade_no out_order_no )
117
118
  def self.close_trade(options)
118
119
  options = {
119
120
  'service' => 'close_trade',
@@ -122,10 +123,22 @@ module Alipay
122
123
  }.merge(Utils.stringify_keys(options))
123
124
 
124
125
  check_required_options(options, CLOSE_TRADE_REQUIRED_OPTIONS)
126
+ check_optional_options(options, CLOSE_TRADE_REQUIRED_OPTIONAL_OPTIONS)
125
127
 
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
128
+ open("#{GATEWAY_URL}?#{query_string(options)}").read
129
+ end
130
+
131
+ SINGLE_TRADE_QUERY_OPTIONS = %w( service partner _input_charset)
132
+ SINGLE_TRADE_QUERY_OPTIONAL_OPTIONS = %w( trade_no out_order_no )
133
+ def self.single_trade_query(options)
134
+ options = {
135
+ "service" => 'single_trade_query',
136
+ "_input_charset" => "utf-8",
137
+ "partner" => Alipay.pid,
138
+ }.merge(Utils.stringify_keys(options))
139
+
140
+ check_required_options(options, SINGLE_TRADE_QUERY_OPTIONS)
141
+ check_optional_options(options, SINGLE_TRADE_QUERY_OPTIONAL_OPTIONS)
129
142
 
130
143
  open("#{GATEWAY_URL}?#{query_string(options)}").read
131
144
  end
@@ -141,5 +154,9 @@ module Alipay
141
154
  warn("Ailpay Warn: missing required option: #{name}") unless options.has_key?(name)
142
155
  end
143
156
  end
157
+
158
+ def self.check_optional_options(options, names)
159
+ warn("Ailpay Warn: must specify either #{names.join(' or ')}") if names.all? {|name| options[name].nil? }
160
+ end
144
161
  end
145
162
  end
@@ -1,3 +1,3 @@
1
1
  module Alipay
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -81,6 +81,58 @@ class Alipay::ServiceTest < Test::Unit::TestCase
81
81
  )
82
82
  end
83
83
 
84
+ def test_single_trade_query
85
+ response_body = <<-EOF
86
+ <?xml version="1.0" encoding="utf-8"?>
87
+ <alipay>
88
+ <is_success>T</is_success>
89
+ <request>
90
+ <param name="trade_no">20150123123123</param>
91
+ <param name="_input_charset">utf-8</param>
92
+ <param name="service">single_trade_query</param>
93
+ <param name="partner">PARTNER</param>
94
+ </request>
95
+ <response>
96
+ <trade>
97
+ <additional_trade_status>DAEMON_CONFIRM_CLOSE</additional_trade_status>
98
+ <buyer_email>foo@gmail.com</buyer_email>
99
+ <buyer_id>BUYER_ID</buyer_id>
100
+ <discount>0.00</discount>
101
+ <flag_trade_locked>0</flag_trade_locked>
102
+ <gmt_close>2015-01-20 02:37:00</gmt_close>
103
+ <gmt_create>2015-01-20 02:17:00</gmt_create>
104
+ <gmt_last_modified_time>2015-01-20 02:37:00</gmt_last_modified_time>
105
+ <is_total_fee_adjust>F</is_total_fee_adjust>
106
+ <operator_role>B</operator_role>
107
+ <out_trade_no>OUT_TRADE_NO</out_trade_no>
108
+ <payment_type>1</payment_type>
109
+ <price>640.00</price>
110
+ <quantity>1</quantity>
111
+ <seller_email>bar@gmail.com</seller_email>
112
+ <seller_id>SELLER_ID</seller_id>
113
+ <subject>ORDER SUBJECT</subject>
114
+ <to_buyer_fee>0.00</to_buyer_fee>
115
+ <to_seller_fee>0.00</to_seller_fee>
116
+ <total_fee>640.00</total_fee>
117
+ <trade_no>TRADE_NO</trade_no>
118
+ <trade_status>TRADE_CLOSED</trade_status>
119
+ <use_coupon>F</use_coupon>
120
+ </trade></response>
121
+ <sign>SIGN</sign>
122
+ <sign_type>MD5</sign_type>
123
+ </alipay>
124
+ EOF
125
+ FakeWeb.register_uri(
126
+ :get,
127
+ %r|https://mapi\.alipay\.com/gateway\.do.*|,
128
+ :body => response_body
129
+ )
130
+
131
+ assert_equal response_body, Alipay::Service.single_trade_query(
132
+ :out_order_no => 'the-out-order-no'
133
+ )
134
+ end
135
+
84
136
  def test_should_send_goods_confirm_by_platform
85
137
  body = <<-EOF
86
138
  <?xml version="1.0" encoding="utf-8"?>
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.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-15 00:00:00.000000000 Z
11
+ date: 2015-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler