wechat-pay 1.0.1 → 1.0.8
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/.github/workflows/code_quality.yml +35 -0
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.rubocop.yml +21 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +15 -0
- data/README.md +92 -0
- data/Rakefile +19 -0
- data/lib/wechat-pay.rb +3 -1
- data/lib/wechat-pay/direct.rb +322 -562
- data/lib/wechat-pay/ecommerce.rb +61 -63
- data/lib/wechat-pay/ecommerce/applyment.rb +177 -178
- data/lib/wechat-pay/ecommerce/balance.rb +100 -101
- data/lib/wechat-pay/ecommerce/bill.rb +1 -0
- data/lib/wechat-pay/ecommerce/combine_order.rb +102 -233
- data/lib/wechat-pay/ecommerce/order.rb +102 -173
- data/lib/wechat-pay/ecommerce/profitsharing.rb +1 -0
- data/lib/wechat-pay/ecommerce/refund.rb +118 -119
- data/lib/wechat-pay/ecommerce/subsidies.rb +68 -69
- data/lib/wechat-pay/ecommerce/withdraw.rb +133 -134
- data/lib/wechat-pay/version.rb +1 -1
- data/wechat-pay.gemspec +27 -0
- metadata +40 -18
- data/lib/set_base_envrionment.rb +0 -8
@@ -1,115 +1,114 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module WechatPay
|
4
|
+
# 余额相关
|
4
5
|
module Ecommerce
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
method = 'GET'
|
6
|
+
QUERY_REALTIME_BALANCE_FIELDS = [:sub_mchid].freeze # :nodoc:
|
7
|
+
#
|
8
|
+
# 余额实时查询
|
9
|
+
#
|
10
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_1.shtml
|
11
|
+
#
|
12
|
+
# Example:
|
13
|
+
#
|
14
|
+
# ``` ruby
|
15
|
+
# WechatPay::Ecommerce.query_realtime_balance(sub_mchid: '1600000')
|
16
|
+
# ```
|
17
|
+
def self.query_realtime_balance(params)
|
18
|
+
sub_mchid = params.delete(:sub_mchid)
|
19
|
+
url = "/v3/ecommerce/fund/balance/#{sub_mchid}"
|
20
|
+
method = 'GET'
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
make_request(
|
23
|
+
path: url,
|
24
|
+
method: method,
|
25
|
+
extra_headers: {
|
26
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
27
|
+
}
|
28
|
+
)
|
29
|
+
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
31
|
+
QUERY_ENDDAY_BALANCE_FIELDS = %i[sub_mchid date].freeze # :nodoc:
|
32
|
+
#
|
33
|
+
# 日终余额查询
|
34
|
+
#
|
35
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_2.shtml
|
36
|
+
#
|
37
|
+
# Example:
|
38
|
+
#
|
39
|
+
# ``` ruby
|
40
|
+
# WechatPay::Ecommerce.query_endday_balance(sub_mchid: '1600000', date: '2019-08-17')
|
41
|
+
# ```
|
42
|
+
def self.query_endday_balance(params)
|
43
|
+
sub_mchid = params.delete(:sub_mchid)
|
44
|
+
path = "/v3/ecommerce/fund/balance/#{sub_mchid}"
|
45
|
+
method = 'GET'
|
46
|
+
query = build_query(params)
|
47
|
+
url = "#{path}?#{query}"
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
49
|
+
make_request(
|
50
|
+
path: url,
|
51
|
+
method: method,
|
52
|
+
extra_headers: {
|
53
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
54
|
+
}
|
55
|
+
)
|
56
|
+
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
58
|
+
QUERY_PLATFORM_REALTIME_BALANCE_FIELDS = %i[account_type].freeze # :nodoc:
|
59
|
+
#
|
60
|
+
# 平台商户实时余额
|
61
|
+
#
|
62
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_3.shtml
|
63
|
+
#
|
64
|
+
# Example:
|
65
|
+
#
|
66
|
+
# ``` ruby
|
67
|
+
# WechatPay::Ecommerce.query_platform_realtime_balance(account_type: 'BASIC') # basic account
|
68
|
+
# WechatPay::Ecommerce.query_platform_realtime_balance(account_type: 'FEES') # fees account
|
69
|
+
# ```
|
70
|
+
#
|
71
|
+
def self.query_platform_realtime_balance(params)
|
72
|
+
account_type = params.delete(:account_type)
|
73
|
+
url = "/v3/merchant/fund/balance/#{account_type}"
|
74
|
+
method = 'GET'
|
75
75
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
76
|
+
make_request(
|
77
|
+
path: url,
|
78
|
+
method: method,
|
79
|
+
extra_headers: {
|
80
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
81
|
+
}
|
82
|
+
)
|
83
|
+
end
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
85
|
+
QUERY_PLATFORM_ENDDAY_BALANCE_FIELDS = %i[account_type date].freeze #:nodoc:
|
86
|
+
#
|
87
|
+
# 平台商户日终余额
|
88
|
+
#
|
89
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_4.shtml
|
90
|
+
#
|
91
|
+
# Example:
|
92
|
+
#
|
93
|
+
# ``` ruby
|
94
|
+
# WechatPay::Ecommerce.query_platform_endday_balance(account_type: 'BASIC')
|
95
|
+
# WechatPay::Ecommerce.query_platform_endday_balance(account_type: 'FEES')
|
96
|
+
# ```
|
97
|
+
#
|
98
|
+
def self.query_platform_endday_balance(params)
|
99
|
+
account_type = params.delete(:account_type)
|
100
|
+
path = "/v3/merchant/fund/dayendbalance/#{account_type}"
|
101
|
+
method = 'GET'
|
102
|
+
query = build_query(params)
|
103
|
+
url = "#{path}?#{query}"
|
104
104
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
end
|
105
|
+
make_request(
|
106
|
+
path: url,
|
107
|
+
method: method,
|
108
|
+
extra_headers: {
|
109
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
110
|
+
}
|
111
|
+
)
|
113
112
|
end
|
114
113
|
end
|
115
114
|
end
|
@@ -1,244 +1,113 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module WechatPay
|
4
|
+
# 合并订单相关
|
4
5
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
77
|
-
|
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
|
113
|
-
|
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
|
149
|
-
|
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)
|
184
|
-
end
|
185
|
-
|
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)
|
198
|
-
|
199
|
-
url = "/v3/combine-transactions/out-trade-no/#{combine_out_trade_no}"
|
200
|
-
|
201
|
-
method = 'GET'
|
202
|
-
|
203
|
-
make_request(
|
204
|
-
method: method,
|
205
|
-
path: url,
|
206
|
-
extra_headers: {
|
207
|
-
'Content-Type' => 'application/x-www-form-urlencoded'
|
208
|
-
}
|
209
|
-
)
|
6
|
+
# @private
|
7
|
+
# @!macro [attach] define_transaction_method
|
8
|
+
# $1合单
|
9
|
+
#
|
10
|
+
# Document: $3
|
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_$1(params)
|
37
|
+
# ```
|
38
|
+
# @!method invoke_combine_transactions_in_$1
|
39
|
+
# @!scope class
|
40
|
+
def self.define_combine_transaction_method(key, value, _document)
|
41
|
+
const_set("INVOKE_COMBINE_TRANSACTIONS_IN_#{key.upcase}_FIELDS",
|
42
|
+
%i[combine_out_trade_no combine_payer_info sub_orders notify_url].freeze)
|
43
|
+
define_singleton_method("invoke_combine_transactions_in_#{key}") do |params|
|
44
|
+
combine_transactions_method_by_suffix(value, params)
|
210
45
|
end
|
46
|
+
end
|
211
47
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
48
|
+
define_combine_transaction_method('js', 'jsapi', 'https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_3.shtml')
|
49
|
+
define_combine_transaction_method('h5', 'h5', 'https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_2.shtml')
|
50
|
+
define_combine_transaction_method('native', 'native', 'https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_5.shtml')
|
51
|
+
define_combine_transaction_method('app', 'app', 'https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_1.shtml')
|
52
|
+
define_combine_transaction_method('miniprogram', 'jsapi', 'https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_4.shtml')
|
53
|
+
|
54
|
+
QUERY_COMBINE_ORDER_FIELDS = %i[combine_out_trade_no].freeze # :nodoc:
|
55
|
+
#
|
56
|
+
# 合单查询
|
57
|
+
#
|
58
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_11.shtml
|
59
|
+
#
|
60
|
+
# ``` ruby
|
61
|
+
# WechatPay::Ecommerce.query_order(combine_out_trade_no: 'C202104302474')
|
62
|
+
# ```
|
63
|
+
#
|
64
|
+
def self.query_combine_order(params)
|
65
|
+
combine_out_trade_no = params.delete(:combine_out_trade_no)
|
66
|
+
|
67
|
+
url = "/v3/combine-transactions/out-trade-no/#{combine_out_trade_no}"
|
68
|
+
|
69
|
+
method = 'GET'
|
70
|
+
|
71
|
+
make_request(
|
72
|
+
method: method,
|
73
|
+
path: url,
|
74
|
+
extra_headers: {
|
75
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
76
|
+
}
|
77
|
+
)
|
78
|
+
end
|
233
79
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
80
|
+
CLOSE_COMBINE_ORDER_FIELDS = %i[combine_out_trade_no sub_orders].freeze # :nodoc:
|
81
|
+
#
|
82
|
+
# 关闭合单
|
83
|
+
#
|
84
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_11.shtml
|
85
|
+
#
|
86
|
+
# ``` ruby
|
87
|
+
# WechatPay::Ecommerce.close_combine_order(combine_out_trade_no: 'C202104302474')
|
88
|
+
# ```
|
89
|
+
def self.close_combine_order(params)
|
90
|
+
combine_out_trade_no = params.delete(:combine_out_trade_no)
|
91
|
+
|
92
|
+
url = "/v3/combine-transactions/out-trade-no/#{combine_out_trade_no}/close"
|
93
|
+
|
94
|
+
payload = {
|
95
|
+
combine_appid: WechatPay.app_id
|
96
|
+
}.merge(params)
|
97
|
+
|
98
|
+
payload_json = payload.to_json
|
99
|
+
|
100
|
+
method = 'POST'
|
101
|
+
|
102
|
+
make_request(
|
103
|
+
method: method,
|
104
|
+
for_sign: payload_json,
|
105
|
+
payload: payload_json,
|
106
|
+
path: url
|
107
|
+
)
|
108
|
+
end
|
241
109
|
|
110
|
+
class<<self
|
242
111
|
private
|
243
112
|
|
244
113
|
def combine_transactions_method_by_suffix(suffix, params)
|