wechat-pay 1.0.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wechat-pay/direct.rb +564 -562
- data/lib/wechat-pay/ecommerce/combine_order.rb +224 -221
- data/lib/wechat-pay/ecommerce/order.rb +173 -173
- data/lib/wechat-pay/version.rb +1 -1
- metadata +16 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62c4aa7b22ada0f4b3251fdc6b28ba32620ca5149e7d999c458543a805dbcbef
|
4
|
+
data.tar.gz: d7f4b63d6e82df69d440154b233776e6a289b875a0ca81107440816732ec3dff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eddf42af769b7cf7781b991780b11deabe060e1bf4f2f86250e4a910b7483cafc779731ac03e12a6cc2ff9b9b97f81ff0e0ee8a83a177d5488d8ce68b727f6f0
|
7
|
+
data.tar.gz: 8a53231c6e6ead3ea36dffa157eba6bfeb73ae94762789d1261d852f92a60925764be70d9d1f8bf33b59a39aebc20fcff21b909e361cd64dc30621ea40f68ad9
|
data/lib/wechat-pay/direct.rb
CHANGED
@@ -7,585 +7,587 @@ module WechatPay
|
|
7
7
|
module Direct
|
8
8
|
include WechatPayHelper
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
#
|
188
|
-
|
189
|
-
#
|
190
|
-
|
191
|
-
def invoke_combine_transactions_in_native(params)
|
192
|
-
WechatPay::Ecommerce.invoke_combine_transactions_in_native(params)
|
193
|
-
end
|
194
|
-
|
195
|
-
QUERY_COMBINE_ORDER_FIELDS = %i[combine_out_trade_no].freeze # :nodoc:
|
196
|
-
#
|
197
|
-
# 合单查询
|
198
|
-
#
|
199
|
-
# TODO: 与电商平台相同,稍后重构
|
200
|
-
#
|
201
|
-
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_11.shtml
|
202
|
-
#
|
203
|
-
# ``` ruby
|
204
|
-
# WechatPay::Direct.query_order(combine_out_trade_no: 'C202104302474')
|
205
|
-
# ```
|
206
|
-
#
|
207
|
-
def query_combine_order(params)
|
208
|
-
combine_out_trade_no = params.delete(:combine_out_trade_no)
|
209
|
-
|
210
|
-
url = "/v3/combine-transactions/out-trade-no/#{combine_out_trade_no}"
|
211
|
-
|
212
|
-
method = 'GET'
|
213
|
-
|
214
|
-
make_request(
|
215
|
-
method: method,
|
216
|
-
path: url,
|
217
|
-
extra_headers: {
|
218
|
-
'Content-Type' => 'application/x-www-form-urlencoded'
|
219
|
-
}
|
220
|
-
)
|
221
|
-
end
|
222
|
-
|
223
|
-
CLOSE_COMBINE_ORDER_FIELDS = %i[combine_out_trade_no sub_orders].freeze # :nodoc:
|
224
|
-
#
|
225
|
-
# 关闭合单
|
226
|
-
#
|
227
|
-
# TODO: 与电商平台相同,稍后重构
|
228
|
-
#
|
229
|
-
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_11.shtml
|
230
|
-
#
|
231
|
-
# ``` ruby
|
232
|
-
# WechatPay::Direct.close_combine_order(combine_out_trade_no: 'C202104302474')
|
233
|
-
# ```
|
234
|
-
def close_combine_order(params)
|
235
|
-
combine_out_trade_no = params.delete(:combine_out_trade_no)
|
236
|
-
|
237
|
-
url = "/v3/combine-transactions/out-trade-no/#{combine_out_trade_no}/close"
|
238
|
-
|
239
|
-
payload = {
|
240
|
-
combine_appid: WechatPay.app_id
|
241
|
-
}.merge(params)
|
242
|
-
|
243
|
-
payload_json = payload.to_json
|
244
|
-
|
245
|
-
method = 'POST'
|
246
|
-
|
247
|
-
make_request(
|
248
|
-
method: method,
|
249
|
-
for_sign: payload_json,
|
250
|
-
payload: payload_json,
|
251
|
-
path: url
|
252
|
-
)
|
253
|
-
end
|
254
|
-
|
255
|
-
INVOKE_TRANSACTIONS_IN_JS_FIELDS = %i[description out_trade out_trade_no payer amount notify_url].freeze # :nodoc:
|
256
|
-
#
|
257
|
-
# 直连js下单
|
258
|
-
#
|
259
|
-
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml
|
260
|
-
#
|
261
|
-
# Example:
|
262
|
-
#
|
263
|
-
# ``` ruby
|
264
|
-
# params = {
|
265
|
-
# appid: 'Your Open id',
|
266
|
-
# mchid: 'Your Mch id'',
|
267
|
-
# description: '回流',
|
268
|
-
# out_trade_no: 'Checking',
|
269
|
-
# payer: {
|
270
|
-
# openid: 'oly6s5c'
|
271
|
-
# },
|
272
|
-
# amount: {
|
273
|
-
# total: 1
|
274
|
-
# },
|
275
|
-
# notify_url: ENV['NOTIFICATION_URL']
|
276
|
-
# }
|
277
|
-
#
|
278
|
-
# WechatPay::Direct.invoke_transactions_in_js(params)
|
279
|
-
# ```
|
280
|
-
def invoke_transactions_in_js(params)
|
281
|
-
direct_transactions_method_by_suffix('jsapi', params)
|
282
|
-
end
|
283
|
-
|
284
|
-
INVOKE_TRANSACTIONS_IN_MINIPROGRAM_FIELDS = %i[description out_trade out_trade_no payer amount notify_url].freeze # :nodoc:
|
285
|
-
#
|
286
|
-
# 直连小程序下单
|
287
|
-
#
|
288
|
-
# Document:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_1.shtml
|
289
|
-
#
|
290
|
-
# Example:
|
291
|
-
#
|
292
|
-
# ``` ruby
|
293
|
-
# params = {
|
294
|
-
# appid: 'Your Open id',
|
295
|
-
# mchid: 'Your Mch id'',
|
296
|
-
# description: '回流',
|
297
|
-
# out_trade_no: 'Checking',
|
298
|
-
# payer: {
|
299
|
-
# openid: 'oly6s5c'
|
300
|
-
# },
|
301
|
-
# amount: {
|
302
|
-
# total: 1
|
303
|
-
# },
|
304
|
-
# notify_url: ENV['NOTIFICATION_URL']
|
305
|
-
# }
|
306
|
-
#
|
307
|
-
# WechatPay::Direct.invoke_transactions_in_miniprogram(params)
|
308
|
-
# ```
|
309
|
-
def invoke_transactions_in_miniprogram(params)
|
310
|
-
direct_transactions_method_by_suffix('jsapi', params)
|
10
|
+
##
|
11
|
+
# :singleton-method: invoke_combine_transactions_in_app
|
12
|
+
#
|
13
|
+
# 直连合单app下单
|
14
|
+
#
|
15
|
+
#
|
16
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_1.shtml
|
17
|
+
#
|
18
|
+
# Example:
|
19
|
+
#
|
20
|
+
# ``` ruby
|
21
|
+
# params = {
|
22
|
+
# combine_out_trade_no: 'combine_out_trade_no',
|
23
|
+
# combine_payer_info: {
|
24
|
+
# openid: 'client open id'
|
25
|
+
# },
|
26
|
+
# sub_orders: [
|
27
|
+
# {
|
28
|
+
# mchid: 'mchid',
|
29
|
+
# sub_mchid: 'sub mchid',
|
30
|
+
# attach: 'attach',
|
31
|
+
# amount: {
|
32
|
+
# total_amount: 100,
|
33
|
+
# currency: 'CNY'
|
34
|
+
# },
|
35
|
+
# out_trade_no: 'out_trade_no',
|
36
|
+
# description: 'description'
|
37
|
+
# }
|
38
|
+
# ],
|
39
|
+
# notify_url: 'the_url'
|
40
|
+
# }
|
41
|
+
#
|
42
|
+
# WechatPay::Direct.invoke_combine_transactions_in_app(params)
|
43
|
+
# ```
|
44
|
+
|
45
|
+
##
|
46
|
+
# :singleton-method: invoke_combine_transactions_in_js
|
47
|
+
#
|
48
|
+
# js合单
|
49
|
+
#
|
50
|
+
# 直连合单js下单
|
51
|
+
#
|
52
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_3.shtml
|
53
|
+
#
|
54
|
+
# Example:
|
55
|
+
#
|
56
|
+
# ``` ruby
|
57
|
+
# params = {
|
58
|
+
# combine_out_trade_no: 'combine_out_trade_no',
|
59
|
+
# combine_payer_info: {
|
60
|
+
# openid: 'client open id'
|
61
|
+
# },
|
62
|
+
# sub_orders: [
|
63
|
+
# {
|
64
|
+
# mchid: 'mchid',
|
65
|
+
# sub_mchid: 'sub mchid',
|
66
|
+
# attach: 'attach',
|
67
|
+
# amount: {
|
68
|
+
# total_amount: 100,
|
69
|
+
# currency: 'CNY'
|
70
|
+
# },
|
71
|
+
# out_trade_no: 'out_trade_no',
|
72
|
+
# description: 'description'
|
73
|
+
# }
|
74
|
+
# ],
|
75
|
+
# notify_url: 'the_url'
|
76
|
+
# }
|
77
|
+
#
|
78
|
+
# WechatPay::Direct.invoke_combine_transactions_in_js(params)
|
79
|
+
# ```
|
80
|
+
|
81
|
+
##
|
82
|
+
# :singleton-method: invoke_combine_transactions_in_h5
|
83
|
+
#
|
84
|
+
# 直连合单h5下单
|
85
|
+
#
|
86
|
+
# TODO: 与电商平台类似,只是参数不同,稍后重构
|
87
|
+
#
|
88
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_2.shtml
|
89
|
+
#
|
90
|
+
# Example:
|
91
|
+
#
|
92
|
+
# ``` ruby
|
93
|
+
# params = {
|
94
|
+
# combine_out_trade_no: 'combine_out_trade_no',
|
95
|
+
# sub_orders: [
|
96
|
+
# {
|
97
|
+
# mchid: 'mchid',
|
98
|
+
# sub_mchid: 'sub mchid',
|
99
|
+
# attach: 'attach',
|
100
|
+
# amount: {
|
101
|
+
# total_amount: 100,
|
102
|
+
# currency: 'CNY'
|
103
|
+
# },
|
104
|
+
# out_trade_no: 'out_trade_no',
|
105
|
+
# description: 'description'
|
106
|
+
# }
|
107
|
+
# ],
|
108
|
+
# notify_url: 'the_url'
|
109
|
+
# }
|
110
|
+
#
|
111
|
+
# WechatPay::Direct.invoke_combine_transactions_in_h5(params)
|
112
|
+
# ```
|
113
|
+
|
114
|
+
##
|
115
|
+
# :singleton-method: invoke_combine_transactions_in_miniprogram
|
116
|
+
#
|
117
|
+
# 直连合单小程序下单
|
118
|
+
#
|
119
|
+
#
|
120
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_4.shtml
|
121
|
+
#
|
122
|
+
# Example:
|
123
|
+
#
|
124
|
+
# ``` ruby
|
125
|
+
# params = {
|
126
|
+
# combine_out_trade_no: 'combine_out_trade_no',
|
127
|
+
# combine_payer_info: {
|
128
|
+
# openid: 'client open id'
|
129
|
+
# },
|
130
|
+
# sub_orders: [
|
131
|
+
# {
|
132
|
+
# mchid: 'mchid',
|
133
|
+
# sub_mchid: 'sub mchid',
|
134
|
+
# attach: 'attach',
|
135
|
+
# amount: {
|
136
|
+
# total_amount: 100,
|
137
|
+
# currency: 'CNY'
|
138
|
+
# },
|
139
|
+
# out_trade_no: 'out_trade_no',
|
140
|
+
# description: 'description'
|
141
|
+
# }
|
142
|
+
# ],
|
143
|
+
# notify_url: 'the_url'
|
144
|
+
# }
|
145
|
+
#
|
146
|
+
# WechatPay::Direct.invoke_combine_transactions_in_miniprogram(params)
|
147
|
+
# ```
|
148
|
+
|
149
|
+
##
|
150
|
+
# :singleton-method: invoke_combine_transactions_in_native
|
151
|
+
#
|
152
|
+
# 直连合单native下单
|
153
|
+
#
|
154
|
+
#
|
155
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_5.shtml
|
156
|
+
#
|
157
|
+
# Example:
|
158
|
+
#
|
159
|
+
# ``` ruby
|
160
|
+
# params = {
|
161
|
+
# combine_out_trade_no: 'combine_out_trade_no',
|
162
|
+
# sub_orders: [
|
163
|
+
# {
|
164
|
+
# mchid: 'mchid',
|
165
|
+
# sub_mchid: 'sub mchid',
|
166
|
+
# attach: 'attach',
|
167
|
+
# amount: {
|
168
|
+
# total_amount: 100,
|
169
|
+
# currency: 'CNY'
|
170
|
+
# },
|
171
|
+
# out_trade_no: 'out_trade_no',
|
172
|
+
# description: 'description'
|
173
|
+
# }
|
174
|
+
# ],
|
175
|
+
# notify_url: 'the_url'
|
176
|
+
# }
|
177
|
+
#
|
178
|
+
# WechatPay::Direct.invoke_combine_transactions_in_native(params)
|
179
|
+
# ```
|
180
|
+
{
|
181
|
+
js: 'jsapi',
|
182
|
+
app: 'app',
|
183
|
+
h5: 'h5',
|
184
|
+
native: 'native',
|
185
|
+
miniprogram: 'jsapi'
|
186
|
+
}.each do |key, _value|
|
187
|
+
const_set("INVOKE_COMBINE_TRANSACTIONS_IN_#{key.upcase}_FIELDS",
|
188
|
+
%i[combine_out_trade_no scene_info sub_orders notify_url].freeze)
|
189
|
+
define_singleton_method("invoke_combine_transactions_in_#{key}") do |params|
|
190
|
+
WechatPay::Ecommerce.send("invoke_combine_transactions_in_#{key}", params)
|
311
191
|
end
|
192
|
+
end
|
312
193
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
end
|
194
|
+
QUERY_COMBINE_ORDER_FIELDS = %i[combine_out_trade_no].freeze # :nodoc:
|
195
|
+
#
|
196
|
+
# 合单查询
|
197
|
+
#
|
198
|
+
# TODO: 与电商平台相同,稍后重构
|
199
|
+
#
|
200
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_11.shtml
|
201
|
+
#
|
202
|
+
# ``` ruby
|
203
|
+
# WechatPay::Direct.query_order(combine_out_trade_no: 'C202104302474')
|
204
|
+
# ```
|
205
|
+
#
|
206
|
+
def self.query_combine_order(params)
|
207
|
+
combine_out_trade_no = params.delete(:combine_out_trade_no)
|
208
|
+
|
209
|
+
url = "/v3/combine-transactions/out-trade-no/#{combine_out_trade_no}"
|
210
|
+
|
211
|
+
method = 'GET'
|
212
|
+
|
213
|
+
make_request(
|
214
|
+
method: method,
|
215
|
+
path: url,
|
216
|
+
extra_headers: {
|
217
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
218
|
+
}
|
219
|
+
)
|
220
|
+
end
|
341
221
|
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
222
|
+
CLOSE_COMBINE_ORDER_FIELDS = %i[combine_out_trade_no sub_orders].freeze # :nodoc:
|
223
|
+
#
|
224
|
+
# 关闭合单
|
225
|
+
#
|
226
|
+
# TODO: 与电商平台相同,稍后重构
|
227
|
+
#
|
228
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_11.shtml
|
229
|
+
#
|
230
|
+
# ``` ruby
|
231
|
+
# WechatPay::Direct.close_combine_order(combine_out_trade_no: 'C202104302474')
|
232
|
+
# ```
|
233
|
+
def self.close_combine_order(params)
|
234
|
+
combine_out_trade_no = params.delete(:combine_out_trade_no)
|
235
|
+
|
236
|
+
url = "/v3/combine-transactions/out-trade-no/#{combine_out_trade_no}/close"
|
237
|
+
|
238
|
+
payload = {
|
239
|
+
combine_appid: WechatPay.app_id
|
240
|
+
}.merge(params)
|
241
|
+
|
242
|
+
payload_json = payload.to_json
|
243
|
+
|
244
|
+
method = 'POST'
|
245
|
+
|
246
|
+
make_request(
|
247
|
+
method: method,
|
248
|
+
for_sign: payload_json,
|
249
|
+
payload: payload_json,
|
250
|
+
path: url
|
251
|
+
)
|
252
|
+
end
|
370
253
|
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
254
|
+
##
|
255
|
+
# :singleton-method: invoke_transactions_in_js
|
256
|
+
#
|
257
|
+
# 直连js下单
|
258
|
+
#
|
259
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml
|
260
|
+
#
|
261
|
+
# Example:
|
262
|
+
#
|
263
|
+
# ``` ruby
|
264
|
+
# params = {
|
265
|
+
# appid: 'Your Open id',
|
266
|
+
# mchid: 'Your Mch id'',
|
267
|
+
# description: '回流',
|
268
|
+
# out_trade_no: 'Checking',
|
269
|
+
# payer: {
|
270
|
+
# openid: 'oly6s5c'
|
271
|
+
# },
|
272
|
+
# amount: {
|
273
|
+
# total: 1
|
274
|
+
# },
|
275
|
+
# notify_url: ENV['NOTIFICATION_URL']
|
276
|
+
# }
|
277
|
+
#
|
278
|
+
# WechatPay::Direct.invoke_transactions_in_js(params)
|
279
|
+
# ```
|
280
|
+
|
281
|
+
##
|
282
|
+
# :singleton-method: invoke_transactions_in_miniprogram
|
283
|
+
#
|
284
|
+
# 直连小程序下单
|
285
|
+
#
|
286
|
+
# Document:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_1.shtml
|
287
|
+
#
|
288
|
+
# Example:
|
289
|
+
#
|
290
|
+
# ``` ruby
|
291
|
+
# params = {
|
292
|
+
# appid: 'Your Open id',
|
293
|
+
# mchid: 'Your Mch id'',
|
294
|
+
# description: '回流',
|
295
|
+
# out_trade_no: 'Checking',
|
296
|
+
# payer: {
|
297
|
+
# openid: 'oly6s5c'
|
298
|
+
# },
|
299
|
+
# amount: {
|
300
|
+
# total: 1
|
301
|
+
# },
|
302
|
+
# notify_url: ENV['NOTIFICATION_URL']
|
303
|
+
# }
|
304
|
+
#
|
305
|
+
# WechatPay::Direct.invoke_transactions_in_miniprogram(params)
|
306
|
+
# ```
|
307
|
+
|
308
|
+
##
|
309
|
+
# :singleton-method: invoke_transactions_in_app
|
310
|
+
#
|
311
|
+
# 直连APP下单
|
312
|
+
#
|
313
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_2_1.shtml
|
314
|
+
#
|
315
|
+
# Example:
|
316
|
+
#
|
317
|
+
# ``` ruby
|
318
|
+
# params = {
|
319
|
+
# appid: 'Your Open id',
|
320
|
+
# mchid: 'Your Mch id'',
|
321
|
+
# description: '回流',
|
322
|
+
# out_trade_no: 'Checking',
|
323
|
+
# payer: {
|
324
|
+
# openid: 'oly6s5c'
|
325
|
+
# },
|
326
|
+
# amount: {
|
327
|
+
# total: 1
|
328
|
+
# },
|
329
|
+
# notify_url: ENV['NOTIFICATION_URL']
|
330
|
+
# }
|
331
|
+
#
|
332
|
+
# WechatPay::Direct.invoke_transactions_in_app(params)
|
333
|
+
# ```
|
334
|
+
|
335
|
+
##
|
336
|
+
# :singleton-method: invoke_transactions_in_h5
|
337
|
+
#
|
338
|
+
# 直连h5下单
|
339
|
+
#
|
340
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_1.shtml
|
341
|
+
#
|
342
|
+
# Example:
|
343
|
+
#
|
344
|
+
# ```
|
345
|
+
# params = {
|
346
|
+
# appid: 'Your Open id',
|
347
|
+
# mchid: 'Your Mch id'',
|
348
|
+
# description: '回流',
|
349
|
+
# out_trade_no: 'Checking',
|
350
|
+
# payer: {
|
351
|
+
# openid: 'oly6s5c'
|
352
|
+
# },
|
353
|
+
# amount: {
|
354
|
+
# total: 1
|
355
|
+
# },
|
356
|
+
# notify_url: ENV['NOTIFICATION_URL']
|
357
|
+
# }
|
358
|
+
#
|
359
|
+
# WechatPay::Direct.invoke_transactions_in_h5(params)
|
360
|
+
# ```
|
361
|
+
|
362
|
+
##
|
363
|
+
# :singleton-method: invoke_transactions_in_native
|
364
|
+
#
|
365
|
+
# 直连native下单
|
366
|
+
#
|
367
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_1.shtml
|
368
|
+
#
|
369
|
+
# Example:
|
370
|
+
#
|
371
|
+
# ``` ruby
|
372
|
+
# params = {
|
373
|
+
# appid: 'Your Open id',
|
374
|
+
# mchid: 'Your Mch id'',
|
375
|
+
# description: '回流',
|
376
|
+
# out_trade_no: 'Checking',
|
377
|
+
# payer: {
|
378
|
+
# openid: 'oly6s5c'
|
379
|
+
# },
|
380
|
+
# amount: {
|
381
|
+
# total: 1
|
382
|
+
# },
|
383
|
+
# notify_url: ENV['NOTIFICATION_URL']
|
384
|
+
# }
|
385
|
+
#
|
386
|
+
# WechatPay::Direct.invoke_transactions_in_native(params)
|
387
|
+
# ```
|
388
|
+
{
|
389
|
+
js: 'jsapi',
|
390
|
+
app: 'app',
|
391
|
+
h5: 'h5',
|
392
|
+
miniprogram: 'jsapi',
|
393
|
+
native: 'native'
|
394
|
+
}.each do |key, value|
|
395
|
+
const_set("INVOKE_TRANSACTIONS_IN_#{key.upcase}_FIELDS", %i[description out_trade out_trade_no payer amount notify_url].freeze)
|
396
|
+
define_singleton_method "invoke_transactions_in_#{key}" do |params|
|
397
|
+
direct_transactions_method_by_suffix(value, params)
|
439
398
|
end
|
399
|
+
end
|
440
400
|
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
401
|
+
QUERY_ORDER_FIELDS = %i[out_trade_no transaction_id].freeze # :nodoc:
|
402
|
+
#
|
403
|
+
# 直连订单查询
|
404
|
+
#
|
405
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_2.shtml
|
406
|
+
#
|
407
|
+
# Example:
|
408
|
+
#
|
409
|
+
# ``` ruby
|
410
|
+
# WechatPay::Direct.query_order(transaction_id: '4323400972202104305133344444') # by transaction_id
|
411
|
+
# WechatPay::Direct.query_order(out_trade_no: 'N202104302474') # by out_trade_no
|
412
|
+
# ```
|
413
|
+
#
|
414
|
+
def self.query_order(params)
|
415
|
+
if params[:transaction_id]
|
416
|
+
params.delete(:out_trade_no)
|
417
|
+
transaction_id = params.delete(:transaction_id)
|
418
|
+
path = "/v3/pay/transactions/id/#{transaction_id}"
|
419
|
+
else
|
420
|
+
params.delete(:transaction_id)
|
454
421
|
out_trade_no = params.delete(:out_trade_no)
|
455
|
-
|
456
|
-
params = params.merge({
|
457
|
-
mchid: WechatPay.mch_id
|
458
|
-
})
|
459
|
-
|
460
|
-
method = 'POST'
|
461
|
-
|
462
|
-
make_request(
|
463
|
-
method: method,
|
464
|
-
path: url,
|
465
|
-
for_sign: params.to_json,
|
466
|
-
payload: params.to_json
|
467
|
-
)
|
422
|
+
path = "/v3/pay/transactions/out-trade-no/#{out_trade_no}"
|
468
423
|
end
|
469
424
|
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
#
|
474
|
-
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_9.shtml
|
475
|
-
#
|
476
|
-
# Example:
|
477
|
-
#
|
478
|
-
# ``` ruby
|
479
|
-
# WechatPay::Direct.invoke_refund(transaction_id: '4323400972202104305131070170', total: 1, refund: 1, out_refund_no: 'R10000')
|
480
|
-
# WechatPay::Direct.invoke_refund(out_trade_no: 'N2021', total: 1, refund: 1, out_refund_no: 'R10000').body
|
481
|
-
# ```
|
482
|
-
def invoke_refund(params)
|
483
|
-
url = '/v3/refund/domestic/refunds'
|
484
|
-
method = 'POST'
|
485
|
-
amount = {
|
486
|
-
refund: params.delete(:refund),
|
487
|
-
total: params.delete(:total),
|
488
|
-
currency: 'CNY'
|
489
|
-
}
|
425
|
+
params = params.merge({
|
426
|
+
mchid: WechatPay.mch_id
|
427
|
+
})
|
490
428
|
|
491
|
-
|
492
|
-
|
493
|
-
|
429
|
+
method = 'GET'
|
430
|
+
query = build_query(params)
|
431
|
+
url = "#{path}?#{query}"
|
494
432
|
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
QUERY_REFUND_FIELDS = %i[sub_mchid refund_id out_refund_no].freeze # :nodoc:
|
504
|
-
#
|
505
|
-
# 直连退款查询
|
506
|
-
#
|
507
|
-
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_10.shtml
|
508
|
-
#
|
509
|
-
# Example:
|
510
|
-
#
|
511
|
-
# ``` ruby
|
512
|
-
# WechatPay::Direct.query_refund(out_refund_no: 'R10000')
|
513
|
-
# ```
|
514
|
-
#
|
515
|
-
def query_refund(params)
|
516
|
-
out_refund_no = params.delete(:out_refund_no)
|
517
|
-
url = "/v3/refund/domestic/refunds/#{out_refund_no}"
|
518
|
-
|
519
|
-
method = 'GET'
|
433
|
+
make_request(
|
434
|
+
method: method,
|
435
|
+
path: url,
|
436
|
+
extra_headers: {
|
437
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
438
|
+
}
|
439
|
+
)
|
440
|
+
end
|
520
441
|
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
442
|
+
CLOSE_ORDER_FIELDS = %i[out_trade_no].freeze # :nodoc:
|
443
|
+
#
|
444
|
+
# 关闭订单
|
445
|
+
#
|
446
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_3.shtml
|
447
|
+
#
|
448
|
+
# Example:
|
449
|
+
#
|
450
|
+
# ``` ruby
|
451
|
+
# WechatPay::Direct.close_order(out_trade_no: 'N3344445')
|
452
|
+
# ```
|
453
|
+
#
|
454
|
+
def self.close_order(params)
|
455
|
+
out_trade_no = params.delete(:out_trade_no)
|
456
|
+
url = "/v3/pay/transactions/out-trade-no/#{out_trade_no}/close"
|
457
|
+
params = params.merge({
|
458
|
+
mchid: WechatPay.mch_id
|
459
|
+
})
|
460
|
+
|
461
|
+
method = 'POST'
|
462
|
+
|
463
|
+
make_request(
|
464
|
+
method: method,
|
465
|
+
path: url,
|
466
|
+
for_sign: params.to_json,
|
467
|
+
payload: params.to_json
|
468
|
+
)
|
469
|
+
end
|
529
470
|
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
471
|
+
INVOKE_REFUND_FIELDS = %i[transaction_id out_trade_no out_refund_no amount].freeze # :nodoc:
|
472
|
+
#
|
473
|
+
# 退款申请
|
474
|
+
#
|
475
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_9.shtml
|
476
|
+
#
|
477
|
+
# Example:
|
478
|
+
#
|
479
|
+
# ``` ruby
|
480
|
+
# WechatPay::Direct.invoke_refund(transaction_id: '4323400972202104305131070170', total: 1, refund: 1, out_refund_no: 'R10000')
|
481
|
+
# WechatPay::Direct.invoke_refund(out_trade_no: 'N2021', total: 1, refund: 1, out_refund_no: 'R10000').body
|
482
|
+
# ```
|
483
|
+
def self.invoke_refund(params)
|
484
|
+
url = '/v3/refund/domestic/refunds'
|
485
|
+
method = 'POST'
|
486
|
+
amount = {
|
487
|
+
refund: params.delete(:refund),
|
488
|
+
total: params.delete(:total),
|
489
|
+
currency: 'CNY'
|
490
|
+
}
|
491
|
+
|
492
|
+
params = params.merge({
|
493
|
+
amount: amount
|
494
|
+
})
|
495
|
+
|
496
|
+
make_request(
|
497
|
+
path: url,
|
498
|
+
method: method,
|
499
|
+
for_sign: params.to_json,
|
500
|
+
payload: params.to_json
|
501
|
+
)
|
502
|
+
end
|
549
503
|
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
504
|
+
QUERY_REFUND_FIELDS = %i[sub_mchid refund_id out_refund_no].freeze # :nodoc:
|
505
|
+
#
|
506
|
+
# 直连退款查询
|
507
|
+
#
|
508
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_10.shtml
|
509
|
+
#
|
510
|
+
# Example:
|
511
|
+
#
|
512
|
+
# ``` ruby
|
513
|
+
# WechatPay::Direct.query_refund(out_refund_no: 'R10000')
|
514
|
+
# ```
|
515
|
+
#
|
516
|
+
def self.query_refund(params)
|
517
|
+
out_refund_no = params.delete(:out_refund_no)
|
518
|
+
url = "/v3/refund/domestic/refunds/#{out_refund_no}"
|
519
|
+
|
520
|
+
method = 'GET'
|
521
|
+
|
522
|
+
make_request(
|
523
|
+
method: method,
|
524
|
+
path: url,
|
525
|
+
extra_headers: {
|
526
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
527
|
+
}
|
528
|
+
)
|
529
|
+
end
|
558
530
|
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
531
|
+
TRADEBILL_FIELDS = [:bill_date].freeze # :nodoc:
|
532
|
+
#
|
533
|
+
# 直连申请交易账单
|
534
|
+
#
|
535
|
+
# Todo: 跟商户平台接口相同
|
536
|
+
#
|
537
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_6.shtml
|
538
|
+
#
|
539
|
+
# Example:
|
540
|
+
#
|
541
|
+
# ``` ruby
|
542
|
+
# WechatPay::direct.tradebill(bill_date: '2021-04-30')
|
543
|
+
# ```
|
544
|
+
def self.tradebill(params)
|
545
|
+
path = '/v3/bill/tradebill'
|
546
|
+
method = 'GET'
|
547
|
+
|
548
|
+
query = build_query(params)
|
549
|
+
url = "#{path}?#{query}"
|
550
|
+
|
551
|
+
make_request(
|
552
|
+
path: url,
|
553
|
+
method: method,
|
554
|
+
extra_headers: {
|
555
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
556
|
+
}
|
557
|
+
)
|
558
|
+
end
|
579
559
|
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
560
|
+
FUNDFLOWBILL_FIELDS = [:bill_date].freeze # :nodoc:
|
561
|
+
#
|
562
|
+
# 申请资金账单
|
563
|
+
#
|
564
|
+
# Todo: 跟商户平台接口相同
|
565
|
+
#
|
566
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_7.shtml
|
567
|
+
#
|
568
|
+
# Example:
|
569
|
+
#
|
570
|
+
# ``` ruby
|
571
|
+
# WechatPay::Direct.fundflowbill(bill_date: '2021-04-30')
|
572
|
+
# ```
|
573
|
+
#
|
574
|
+
def self.fundflowbill(params)
|
575
|
+
path = '/v3/bill/fundflowbill'
|
576
|
+
method = 'GET'
|
577
|
+
|
578
|
+
query = build_query(params)
|
579
|
+
url = "#{path}?#{query}"
|
580
|
+
|
581
|
+
make_request(
|
582
|
+
path: url,
|
583
|
+
method: method,
|
584
|
+
extra_headers: {
|
585
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
586
|
+
}
|
587
|
+
)
|
588
|
+
end
|
588
589
|
|
590
|
+
class << self
|
589
591
|
private
|
590
592
|
|
591
593
|
def direct_transactions_method_by_suffix(suffix, params)
|