alipay_global 0.0.3 → 0.0.4

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: 8d806d2aa21fbbc9eb231773eb0df9e468add4b0
4
- data.tar.gz: 8b9c2c7df624401147e1d7187400ac912cddd897
3
+ metadata.gz: eddedc835b2bfbb0f10a759faea33ab63e9afd95
4
+ data.tar.gz: 04033f489681672e64d7e653bc312683eaf21d7c
5
5
  SHA512:
6
- metadata.gz: 9e663a7259a74309f6bf10942dce4eaa37c86b2e96e752f6b108d41a79001db77b677c1b2ed37c52b7ca7892da27eda74e52c3f7616e3938390ef04983a73462
7
- data.tar.gz: 27b7cadceb9d7ac35996b3581265fff5542681917eeeba73197280e024b60d93c50721a55be85d47c509a3ea00c95c1c30e8377e6d2eb29c30b1e1ceeb28c721
6
+ metadata.gz: f8706e2ede93062f2472978a777ada9277870d729ec802d5b288428e53dfd0ba2b7bacfff76d2aca4be00a9c57879c3762f012539e6bf3d0be6f4ec261e3bebc
7
+ data.tar.gz: 44cfecd9b76dd39396e98b2ec8c165244da4023fd8e55463be7da28d491452d36b4c0b466a997f232ace4257eee59e87a763309a2fe5f9ceabe653be5d5a6917
data/README.md CHANGED
@@ -103,6 +103,63 @@ AlipayGlobal::Service::Trade.create(
103
103
 
104
104
  \*\*\* Attention2:The request parameters can only be accepted by the Alipay system if they are signed according to the signature mechanism specified in this document.The parameter “timeout_rule”, the default value is 12h. If you want to use this parameter to change timing, you need to contact Alipay technical. Otherwise you will have an error.
105
105
 
106
+ ```ruby
107
+ status
108
+ ```
109
+
110
+ #### Definition
111
+
112
+ ```ruby
113
+ AlipayGlobal::Service::Trade.status({ARGUMENTS})
114
+ ```
115
+
116
+ #### Example
117
+
118
+ ```ruby
119
+ AlipayGlobal::Service::Trade.status(
120
+ out_trade_no: "SAMPLE_TRANSACTION_ID"
121
+ )
122
+ # success => { success: true, message {
123
+ trade_no: "ALIPAYS_INTERNAL_TRADE_NO",
124
+ out_trade_no: "YOUR_TRADE_NO_USED",
125
+ subject: "SUBJECT CONTENT USED IN TRANSACTION",
126
+ trade_status: "WAIT_BUYER_PAY/TRADE_FINISHED/TRADE_CLOSED"
127
+ } }
128
+ # error => { success: false, message: "ERROR_CODE. # See below" }
129
+ #for production
130
+ ```
131
+
132
+ #### ARGUMENTS
133
+
134
+ | Key | Requirement | Data Type | Description |
135
+ | --- | ----------- | --------- | ----------- |
136
+ | out_trade_no | required | string | The ID for the original transaction. |
137
+
138
+ #### RESPONSE
139
+
140
+ ##### Success response
141
+
142
+ | Trade status | Description |
143
+ | ------------ | ----------- |
144
+ | WAIT_BUYER_PAY | The buyer is expected to make the payment |
145
+ | TRADE_FINISHED | The payment has been made, transaction closes. |
146
+ | TRADE_CLOSED | Transaction closed without payment. |
147
+
148
+ ##### Error response
149
+ Shown when there's an issue with the payment uri created or if the transaction does not exist
150
+
151
+ | Error Code | Description |
152
+ | ---------- | ----------- |
153
+ | TRADE_NOT_EXIST | This trade number does not exist in Alipay's transaction DB |
154
+ | ILLEGAL_ARGUMENT | Illegal parameters |
155
+ | ILLEGAL_SIGN | Illegal signature |
156
+ | HASH_NO_PRIVILEGE | No sufficient rights to complete the query |
157
+ | ILLEGAL_SERVICE | Service Parameter is incorrect |
158
+ | ILLEGAL_PARTNER | Incorrect Partner ID |
159
+ | ILLEGAL_SIGN_TYPE | Signature is of wrong type. |
160
+ | ILLEGAL_CHARSET | Illegal charset |
161
+
162
+
106
163
  ```ruby
107
164
  refund
108
165
  ```
@@ -124,7 +181,7 @@ AlipayGlobal::Service::Trade.refund(
124
181
  gmt_return: (Time.parse("2015-03-20 12:00").getlocal("+08:00")).strftime("%Y%m%d%H%M%S"),
125
182
  currency: "USD"
126
183
  )
127
- # => 'https://mapi.alipay.com/gateway.do?service=create_forex_trade...' #for production
184
+ # => 'https://mapi.alipay.net/gateway.do?service=forex_refund...' #for production
128
185
  ```
129
186
 
130
187
  #### ARGUMENTS
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "minitest"
24
24
  spec.add_development_dependency "fakeweb"
25
- spec.add_development_dependency "nokogiri"
26
- spec.add_development_dependency "rest-client", "~> 1.8.0"
25
+ spec.add_dependency "nokogiri"
26
+ spec.add_dependency "rest-client", "~> 1.8.0"
27
27
 
28
- end
28
+ end
@@ -7,6 +7,7 @@ module AlipayGlobal
7
7
  module Service
8
8
  module Trade
9
9
  BOUNDARY = "AaB03x"
10
+ CREATE_QUERY_REQUIRED_PARAMS = %w( out_trade_no )
10
11
  CREATE_TRADE_REQUIRED_PARAMS = %w( notify_url subject out_trade_no currency )
11
12
  CREATE_TRADE_OPTIONAL_PARAMS = %w( return_url body total_fee rmb_fee order_gmt_create order_valid_time timeout_rule auth_token supplier seller_id seller_name seller_industry )
12
13
 
@@ -27,6 +28,32 @@ module AlipayGlobal
27
28
  AlipayGlobal::Service.request_uri(params).to_s
28
29
  end
29
30
 
31
+ def self.status(params)
32
+ resp = Net::HTTP.get(build_query_uri(params))
33
+
34
+ alipay_results = Nokogiri::XML(resp).at_xpath('//alipay')
35
+
36
+ alipay_success = alipay_results.at_xpath('//is_success').content == "T"
37
+
38
+ status_response = process_alipay_trade_response(alipay_success,alipay_results)
39
+
40
+ { success: alipay_success , message: status_response }
41
+ end
42
+
43
+ def self.process_alipay_trade_response(success, alipay_xml)
44
+ if success
45
+ response_xml = alipay_xml.at_xpath('//response').at_xpath('//trade')
46
+ {
47
+ trade_no: response_xml.at_xpath('//trade_no').content,
48
+ out_trade_no: response_xml.at_xpath('//out_trade_no').content,
49
+ subject: response_xml.at_xpath('//subject').content,
50
+ trade_status: response_xml.at_xpath('//trade_status').content
51
+ }
52
+ else
53
+ alipay_xml.at_xpath('//error').content
54
+ end
55
+ end
56
+
30
57
  def self.refund(params)
31
58
  resp = Net::HTTP.get(build_refund_uri(params))
32
59
 
@@ -40,6 +67,7 @@ module AlipayGlobal
40
67
  end
41
68
 
42
69
  def self.batch_refund(refunds)
70
+ #DISABLED
43
71
  file = build_refund_file(refunds)
44
72
 
45
73
  params = {
@@ -49,18 +77,8 @@ module AlipayGlobal
49
77
 
50
78
  uri = AlipayGlobal::Service.request_uri(params)
51
79
 
52
- #p uri.to_s
53
-
54
80
  form_params = { 'partner' => AlipayGlobal.api_partner_id, 'service' => 'forex_refund_file', 'refund_file' => File.read(file.path) }
55
81
 
56
- #IO.read(file.path)
57
-
58
- #p form_params
59
-
60
- #resp = Net::HTTP.post_form(uri, form_params)
61
-
62
- #p resp.body
63
-
64
82
  resp = RestClient.post uri.to_s, :partner => AlipayGlobal.api_partner_id, :file => File.new(file.path, 'rb'), :service => 'forex_refund_file'
65
83
 
66
84
  alipay_resp = Nokogiri::XML(resp.body)
@@ -72,6 +90,19 @@ module AlipayGlobal
72
90
  file.unlink
73
91
  end
74
92
 
93
+ def self.build_query_uri(params)
94
+ params = AlipayGlobal::Utils.stringify_keys(params)
95
+ AlipayGlobal::Service.check_required_params(params, CREATE_QUERY_REQUIRED_PARAMS)
96
+
97
+ params = {
98
+ 'service' => 'single_trade_query',
99
+ '_input_charset' => 'utf-8',
100
+ 'partner' => AlipayGlobal.api_partner_id
101
+ }.merge(params)
102
+
103
+ AlipayGlobal::Service.request_uri(params)
104
+ end
105
+
75
106
  def self.build_refund_file(refunds)
76
107
  file = Tempfile.new(['refund','.txt'])
77
108
  refund_content = AlipayGlobal::Utils.write_refund_content(refunds)
@@ -1,3 +1,3 @@
1
1
  module AlipayGlobal
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -55,6 +55,26 @@ describe "AlipayGlobal::Service::Trade", "Forex trade actions" do
55
55
 
56
56
  end
57
57
 
58
+ describe "#status" do
59
+ it "should reject non-existent trade" do
60
+ params = {
61
+ out_trade_no: "SAMPLE_TRANSACTION_ID"
62
+ }
63
+ expected_result = { success: false, message: "TRADE_NOT_EXIST" }
64
+
65
+ assert_equal "https://mapi.alipay.net/gateway.do?service=single_trade_query&_input_charset=utf-8&partner=2088101122136241&out_trade_no=SAMPLE_TRANSACTION_ID&sign_type=MD5&sign=d4d3825356fd0799ee16829acffc1460", @alipay::Service::Trade.build_query_uri(params).to_s
66
+ assert_equal expected_result, @alipay::Service::Trade.status(params)
67
+ end
68
+
69
+ it "should reject uri with missing out_trade_no" do
70
+ params = { }
71
+ expected_result = { success: false, message: "ILLEGAL_ARGUMENT" }
72
+
73
+ assert_equal "https://mapi.alipay.net/gateway.do?service=single_trade_query&_input_charset=utf-8&partner=2088101122136241&sign_type=MD5&sign=af7007238531b0b0917f3972e24c6c64", @alipay::Service::Trade.build_query_uri(params).to_s
74
+ assert_equal expected_result, @alipay::Service::Trade.status(params)
75
+ end
76
+ end
77
+
58
78
  describe "#refund" do
59
79
  it "should refund correctly for a valid refund url" do
60
80
  params = {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alipay_global
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Melvrick Goh, Ng Junyang, Grzegorz Witek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-20 00:00:00.000000000 Z
11
+ date: 2015-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,7 +73,7 @@ dependencies:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
- type: :development
76
+ type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
@@ -87,7 +87,7 @@ dependencies:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: 1.8.0
90
- type: :development
90
+ type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements: