wechat-pay 1.0.1 → 1.0.3
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 +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
@@ -2,243 +2,246 @@
|
|
2
2
|
|
3
3
|
module WechatPay
|
4
4
|
module Ecommerce
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
def invoke_combine_transactions_in_native(params)
|
39
|
-
combine_transactions_method_by_suffix('native', params)
|
40
|
-
end
|
5
|
+
##
|
6
|
+
# :singleton-method: invoke_combine_transactions_in_native
|
7
|
+
#
|
8
|
+
# native合单
|
9
|
+
#
|
10
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_5.shtml
|
11
|
+
#
|
12
|
+
# Example:
|
13
|
+
#
|
14
|
+
# ``` ruby
|
15
|
+
# params = {
|
16
|
+
# combine_out_trade_no: 'combine_out_trade_no',
|
17
|
+
# combine_payer_info: {
|
18
|
+
# openid: 'client open id'
|
19
|
+
# },
|
20
|
+
# sub_orders: [
|
21
|
+
# {
|
22
|
+
# mchid: 'mchid',
|
23
|
+
# sub_mchid: 'sub mchid',
|
24
|
+
# attach: 'attach',
|
25
|
+
# amount: {
|
26
|
+
# total_amount: 100,
|
27
|
+
# currency: 'CNY'
|
28
|
+
# },
|
29
|
+
# out_trade_no: 'out_trade_no',
|
30
|
+
# description: 'description'
|
31
|
+
# }
|
32
|
+
# ],
|
33
|
+
# notify_url: 'the_url'
|
34
|
+
# }
|
35
|
+
#
|
36
|
+
# WechatPay::Ecommerce.invoke_combine_transactions_in_native(params)
|
37
|
+
# ```
|
41
38
|
|
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
|
-
combine_transactions_method_by_suffix('h5', params)
|
76
|
-
end
|
39
|
+
##
|
40
|
+
# :singleton-method: invoke_combine_transactions_in_h5
|
41
|
+
#
|
42
|
+
# h5合单
|
43
|
+
#
|
44
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_2.shtml
|
45
|
+
#
|
46
|
+
# Example:
|
47
|
+
#
|
48
|
+
# ``` ruby
|
49
|
+
# params = {
|
50
|
+
# combine_out_trade_no: 'combine_out_trade_no',
|
51
|
+
# combine_payer_info: {
|
52
|
+
# openid: 'client open id'
|
53
|
+
# },
|
54
|
+
# sub_orders: [
|
55
|
+
# {
|
56
|
+
# mchid: 'mchid',
|
57
|
+
# sub_mchid: 'sub mchid',
|
58
|
+
# attach: 'attach',
|
59
|
+
# amount: {
|
60
|
+
# total_amount: 100,
|
61
|
+
# currency: 'CNY'
|
62
|
+
# },
|
63
|
+
# out_trade_no: 'out_trade_no',
|
64
|
+
# description: 'description'
|
65
|
+
# }
|
66
|
+
# ],
|
67
|
+
# notify_url: 'the_url'
|
68
|
+
# }
|
69
|
+
#
|
70
|
+
# WechatPay::Ecommerce.invoke_combine_transactions_in_h5(params)
|
71
|
+
# ```
|
77
72
|
|
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
|
-
combine_transactions_method_by_suffix('app', params)
|
112
|
-
end
|
73
|
+
##
|
74
|
+
# :singleton-method: invoke_combine_transactions_in_app
|
75
|
+
#
|
76
|
+
# app合单
|
77
|
+
#
|
78
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_1.shtml
|
79
|
+
#
|
80
|
+
# Example:
|
81
|
+
#
|
82
|
+
# ``` ruby
|
83
|
+
# params = {
|
84
|
+
# combine_out_trade_no: 'combine_out_trade_no',
|
85
|
+
# combine_payer_info: {
|
86
|
+
# openid: 'client open id'
|
87
|
+
# },
|
88
|
+
# sub_orders: [
|
89
|
+
# {
|
90
|
+
# mchid: 'mchid',
|
91
|
+
# sub_mchid: 'sub mchid',
|
92
|
+
# attach: 'attach',
|
93
|
+
# amount: {
|
94
|
+
# total_amount: 100,
|
95
|
+
# currency: 'CNY'
|
96
|
+
# },
|
97
|
+
# out_trade_no: 'out_trade_no',
|
98
|
+
# description: 'description'
|
99
|
+
# }
|
100
|
+
# ],
|
101
|
+
# notify_url: 'the_url'
|
102
|
+
# }
|
103
|
+
#
|
104
|
+
# WechatPay::Ecommerce.invoke_combine_transactions_in_app(params)
|
105
|
+
# ```
|
113
106
|
|
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
|
-
combine_transactions_method_by_suffix('jsapi', params)
|
148
|
-
end
|
107
|
+
##
|
108
|
+
# :singleton-method: invoke_combine_transactions_in_app
|
109
|
+
#
|
110
|
+
# js合单
|
111
|
+
#
|
112
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_3.shtml
|
113
|
+
#
|
114
|
+
# Example:
|
115
|
+
#
|
116
|
+
# ``` ruby
|
117
|
+
# params = {
|
118
|
+
# combine_out_trade_no: 'combine_out_trade_no',
|
119
|
+
# combine_payer_info: {
|
120
|
+
# openid: 'client open id'
|
121
|
+
# },
|
122
|
+
# sub_orders: [
|
123
|
+
# {
|
124
|
+
# mchid: 'mchid',
|
125
|
+
# sub_mchid: 'sub mchid',
|
126
|
+
# attach: 'attach',
|
127
|
+
# amount: {
|
128
|
+
# total_amount: 100,
|
129
|
+
# currency: 'CNY'
|
130
|
+
# },
|
131
|
+
# out_trade_no: 'out_trade_no',
|
132
|
+
# description: 'description'
|
133
|
+
# }
|
134
|
+
# ],
|
135
|
+
# notify_url: 'the_url'
|
136
|
+
# }
|
137
|
+
#
|
138
|
+
# WechatPay::Ecommerce.invoke_combine_transactions_in_js(params)
|
139
|
+
# ```
|
149
140
|
|
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
|
-
|
141
|
+
##
|
142
|
+
# :singleton-method: invoke_combine_transactions_in_miniprogram
|
143
|
+
#
|
144
|
+
# 小程序合单
|
145
|
+
#
|
146
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_4.shtml
|
147
|
+
#
|
148
|
+
# Example:
|
149
|
+
#
|
150
|
+
# ``` ruby
|
151
|
+
# params = {
|
152
|
+
# combine_out_trade_no: 'combine_out_trade_no',
|
153
|
+
# combine_payer_info: {
|
154
|
+
# openid: 'client open id'
|
155
|
+
# },
|
156
|
+
# sub_orders: [
|
157
|
+
# {
|
158
|
+
# mchid: 'mchid',
|
159
|
+
# sub_mchid: 'sub mchid',
|
160
|
+
# attach: 'attach',
|
161
|
+
# amount: {
|
162
|
+
# total_amount: 100,
|
163
|
+
# currency: 'CNY'
|
164
|
+
# },
|
165
|
+
# out_trade_no: 'out_trade_no',
|
166
|
+
# description: 'description'
|
167
|
+
# }
|
168
|
+
# ],
|
169
|
+
# notify_url: 'the_url'
|
170
|
+
# }
|
171
|
+
#
|
172
|
+
# WechatPay::Ecommerce.invoke_combine_transactions_in_miniprogram(params)
|
173
|
+
# ```
|
174
|
+
{
|
175
|
+
js: 'jsapi',
|
176
|
+
app: 'app',
|
177
|
+
h5: 'h5',
|
178
|
+
native: 'native',
|
179
|
+
miniprogram: 'jsapi'
|
180
|
+
}.each do |key, value|
|
181
|
+
const_set("INVOKE_COMBINE_TRANSACTIONS_IN_#{key.upcase}_FIELDS",
|
182
|
+
%i[combine_out_trade_no combine_payer_info sub_orders notify_url].freeze)
|
183
|
+
define_singleton_method("invoke_combine_transactions_in_#{key}") do |params|
|
184
|
+
combine_transactions_method_by_suffix(value, params)
|
184
185
|
end
|
186
|
+
end
|
185
187
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
188
|
+
QUERY_COMBINE_ORDER_FIELDS = %i[combine_out_trade_no].freeze # :nodoc:
|
189
|
+
#
|
190
|
+
# 合单查询
|
191
|
+
#
|
192
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_11.shtml
|
193
|
+
#
|
194
|
+
# ``` ruby
|
195
|
+
# WechatPay::Ecommerce.query_order(combine_out_trade_no: 'C202104302474')
|
196
|
+
# ```
|
197
|
+
#
|
198
|
+
def self.query_combine_order(params)
|
199
|
+
combine_out_trade_no = params.delete(:combine_out_trade_no)
|
198
200
|
|
199
|
-
|
201
|
+
url = "/v3/combine-transactions/out-trade-no/#{combine_out_trade_no}"
|
200
202
|
|
201
|
-
|
203
|
+
method = 'GET'
|
202
204
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
205
|
+
make_request(
|
206
|
+
method: method,
|
207
|
+
path: url,
|
208
|
+
extra_headers: {
|
209
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
210
|
+
}
|
211
|
+
)
|
212
|
+
end
|
211
213
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
214
|
+
CLOSE_COMBINE_ORDER_FIELDS = %i[combine_out_trade_no sub_orders].freeze # :nodoc:
|
215
|
+
#
|
216
|
+
# 关闭合单
|
217
|
+
#
|
218
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_11.shtml
|
219
|
+
#
|
220
|
+
# ``` ruby
|
221
|
+
# WechatPay::Ecommerce.close_combine_order(combine_out_trade_no: 'C202104302474')
|
222
|
+
# ```
|
223
|
+
def self.close_combine_order(params)
|
224
|
+
combine_out_trade_no = params.delete(:combine_out_trade_no)
|
223
225
|
|
224
|
-
|
226
|
+
url = "/v3/combine-transactions/out-trade-no/#{combine_out_trade_no}/close"
|
225
227
|
|
226
|
-
|
227
|
-
|
228
|
-
|
228
|
+
payload = {
|
229
|
+
combine_appid: WechatPay.app_id
|
230
|
+
}.merge(params)
|
229
231
|
|
230
|
-
|
232
|
+
payload_json = payload.to_json
|
231
233
|
|
232
|
-
|
234
|
+
method = 'POST'
|
233
235
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
236
|
+
make_request(
|
237
|
+
method: method,
|
238
|
+
for_sign: payload_json,
|
239
|
+
payload: payload_json,
|
240
|
+
path: url
|
241
|
+
)
|
242
|
+
end
|
241
243
|
|
244
|
+
class<<self
|
242
245
|
private
|
243
246
|
|
244
247
|
def combine_transactions_method_by_suffix(suffix, params)
|