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.
@@ -2,243 +2,246 @@
2
2
 
3
3
  module WechatPay
4
4
  module Ecommerce
5
- class<<self
6
- INVOKE_COMBINE_TRANSACTIONS_IN_NATIVE_FIELDS = %i[combine_out_trade_no combine_payer_info sub_orders notify_url].freeze # :nodoc:
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
- # ```
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
- INVOKE_COMBINE_TRANSACTIONS_IN_H5_FIELDS = %i[combine_out_trade_no combine_payer_info sub_orders notify_url].freeze # :nodoc:
43
- #
44
- # h5合单
45
- #
46
- # Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_2.shtml
47
- #
48
- # Example:
49
- #
50
- # ``` ruby
51
- # params = {
52
- # combine_out_trade_no: 'combine_out_trade_no',
53
- # combine_payer_info: {
54
- # openid: 'client open id'
55
- # },
56
- # sub_orders: [
57
- # {
58
- # mchid: 'mchid',
59
- # sub_mchid: 'sub mchid',
60
- # attach: 'attach',
61
- # amount: {
62
- # total_amount: 100,
63
- # currency: 'CNY'
64
- # },
65
- # out_trade_no: 'out_trade_no',
66
- # description: 'description'
67
- # }
68
- # ],
69
- # notify_url: 'the_url'
70
- # }
71
- #
72
- # WechatPay::Ecommerce.invoke_combine_transactions_in_h5(params)
73
- # ```
74
- def invoke_combine_transactions_in_h5(params)
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
- INVOKE_COMBINE_TRANSACTIONS_IN_APP_FIELDS = %i[combine_out_trade_no combine_payer_info sub_orders notify_url].freeze # :nodoc:
79
- #
80
- # app合单
81
- #
82
- # Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_1.shtml
83
- #
84
- # Example:
85
- #
86
- # ``` ruby
87
- # params = {
88
- # combine_out_trade_no: 'combine_out_trade_no',
89
- # combine_payer_info: {
90
- # openid: 'client open id'
91
- # },
92
- # sub_orders: [
93
- # {
94
- # mchid: 'mchid',
95
- # sub_mchid: 'sub mchid',
96
- # attach: 'attach',
97
- # amount: {
98
- # total_amount: 100,
99
- # currency: 'CNY'
100
- # },
101
- # out_trade_no: 'out_trade_no',
102
- # description: 'description'
103
- # }
104
- # ],
105
- # notify_url: 'the_url'
106
- # }
107
- #
108
- # WechatPay::Ecommerce.invoke_combine_transactions_in_app(params)
109
- # ```
110
- def invoke_combine_transactions_in_app(params)
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
- INVOKE_COMBINE_TRANSACTIONS_IN_JS_FIELDS = %i[combine_out_trade_no combine_payer_info sub_orders notify_url].freeze # :nodoc:
115
- #
116
- # js合单
117
- #
118
- # Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_3.shtml
119
- #
120
- # Example:
121
- #
122
- # ``` ruby
123
- # params = {
124
- # combine_out_trade_no: 'combine_out_trade_no',
125
- # combine_payer_info: {
126
- # openid: 'client open id'
127
- # },
128
- # sub_orders: [
129
- # {
130
- # mchid: 'mchid',
131
- # sub_mchid: 'sub mchid',
132
- # attach: 'attach',
133
- # amount: {
134
- # total_amount: 100,
135
- # currency: 'CNY'
136
- # },
137
- # out_trade_no: 'out_trade_no',
138
- # description: 'description'
139
- # }
140
- # ],
141
- # notify_url: 'the_url'
142
- # }
143
- #
144
- # WechatPay::Ecommerce.invoke_combine_transactions_in_js(params)
145
- # ```
146
- def invoke_combine_transactions_in_js(params)
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
- INVOKE_COMBINE_TRANSACTIONS_IN_MINIPROGRAM_FIELDS = %i[combine_out_trade_no combine_payer_info sub_orders notify_url].freeze # :nodoc:
151
- #
152
- # 小程序合单
153
- #
154
- # Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_4.shtml
155
- #
156
- # Example:
157
- #
158
- # ``` ruby
159
- # params = {
160
- # combine_out_trade_no: 'combine_out_trade_no',
161
- # combine_payer_info: {
162
- # openid: 'client open id'
163
- # },
164
- # sub_orders: [
165
- # {
166
- # mchid: 'mchid',
167
- # sub_mchid: 'sub mchid',
168
- # attach: 'attach',
169
- # amount: {
170
- # total_amount: 100,
171
- # currency: 'CNY'
172
- # },
173
- # out_trade_no: 'out_trade_no',
174
- # description: 'description'
175
- # }
176
- # ],
177
- # notify_url: 'the_url'
178
- # }
179
- #
180
- # WechatPay::Ecommerce.invoke_combine_transactions_in_miniprogram(params)
181
- # ```
182
- def invoke_combine_transactions_in_miniprogram(params)
183
- combine_transactions_method_by_suffix('jsapi', params)
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
- QUERY_COMBINE_ORDER_FIELDS = %i[combine_out_trade_no].freeze # :nodoc:
187
- #
188
- # 合单查询
189
- #
190
- # Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_11.shtml
191
- #
192
- # ``` ruby
193
- # WechatPay::Ecommerce.query_order(combine_out_trade_no: 'C202104302474')
194
- # ```
195
- #
196
- def query_combine_order(params)
197
- combine_out_trade_no = params.delete(:combine_out_trade_no)
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
- url = "/v3/combine-transactions/out-trade-no/#{combine_out_trade_no}"
201
+ url = "/v3/combine-transactions/out-trade-no/#{combine_out_trade_no}"
200
202
 
201
- method = 'GET'
203
+ method = 'GET'
202
204
 
203
- make_request(
204
- method: method,
205
- path: url,
206
- extra_headers: {
207
- 'Content-Type' => 'application/x-www-form-urlencoded'
208
- }
209
- )
210
- end
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
- CLOSE_COMBINE_ORDER_FIELDS = %i[combine_out_trade_no sub_orders].freeze # :nodoc:
213
- #
214
- # 关闭合单
215
- #
216
- # Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_11.shtml
217
- #
218
- # ``` ruby
219
- # WechatPay::Ecommerce.close_combine_order(combine_out_trade_no: 'C202104302474')
220
- # ```
221
- def close_combine_order(params)
222
- combine_out_trade_no = params.delete(:combine_out_trade_no)
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
- url = "/v3/combine-transactions/out-trade-no/#{combine_out_trade_no}/close"
226
+ url = "/v3/combine-transactions/out-trade-no/#{combine_out_trade_no}/close"
225
227
 
226
- payload = {
227
- combine_appid: WechatPay.app_id
228
- }.merge(params)
228
+ payload = {
229
+ combine_appid: WechatPay.app_id
230
+ }.merge(params)
229
231
 
230
- payload_json = payload.to_json
232
+ payload_json = payload.to_json
231
233
 
232
- method = 'POST'
234
+ method = 'POST'
233
235
 
234
- make_request(
235
- method: method,
236
- for_sign: payload_json,
237
- payload: payload_json,
238
- path: url
239
- )
240
- end
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)