wechat-pay 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/{test.yml → code_quality.yml} +2 -0
- data/.rubocop.yml +21 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +0 -1
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/lib/wechat-pay.rb +3 -1
- data/lib/wechat-pay/direct.rb +81 -323
- 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 +42 -176
- data/lib/wechat-pay/ecommerce/order.rb +33 -105
- 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 +3 -2
- metadata +19 -3
@@ -1,85 +1,84 @@
|
|
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 = 'POST'
|
6
|
+
REQUEST_SUBSIDIES_FIELDS = %i[sub_mchid transaction_id amount description].freeze # :nodoc:
|
7
|
+
#
|
8
|
+
# 请求补差
|
9
|
+
#
|
10
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_5_1.shtml
|
11
|
+
#
|
12
|
+
# Example:
|
13
|
+
#
|
14
|
+
# ``` ruby
|
15
|
+
# WechatPay::Ecommerce.request_subsidies(sub_mchid: '16000000', transaction_id: '4323400972202104305131070170', amount: 1, description: '订单补差')
|
16
|
+
# ```
|
17
|
+
#
|
18
|
+
def self.request_subsidies(params)
|
19
|
+
url = '/v3/ecommerce/subsidies/create'
|
20
|
+
method = 'POST'
|
21
21
|
|
22
|
-
|
22
|
+
payload_json = params.to_json
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
make_request(
|
25
|
+
method: method,
|
26
|
+
path: url,
|
27
|
+
for_sign: payload_json,
|
28
|
+
payload: payload_json
|
29
|
+
)
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
32
|
+
RETURN_SUBSIDIES_FIELDS = %i[sub_mchid transaction_id amount description out_order_no].freeze # :nodoc:
|
33
|
+
#
|
34
|
+
# 补差回退
|
35
|
+
#
|
36
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_5_2.shtml
|
37
|
+
#
|
38
|
+
# Example:
|
39
|
+
#
|
40
|
+
# ``` ruby
|
41
|
+
# WechatPay::Ecommerce.return_subsidies(sub_mchid: '16000000', transaction_id: '4323400972202104305131070170', amount: 1, description: '订单补差', out_order_no: 'P103333')
|
42
|
+
# ```
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
def self.return_subsidies(params)
|
45
|
+
url = '/v3/ecommerce/subsidies/return'
|
46
|
+
method = 'POST'
|
47
47
|
|
48
|
-
|
48
|
+
payload_json = params.to_json
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
make_request(
|
51
|
+
method: method,
|
52
|
+
path: url,
|
53
|
+
for_sign: payload_json,
|
54
|
+
payload: payload_json
|
55
|
+
)
|
56
|
+
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
58
|
+
CANCEL_SUBSIDIES_FIELDS = %i[sub_mchid transaction_id description].freeze # :nodoc:
|
59
|
+
#
|
60
|
+
# 取消补差
|
61
|
+
#
|
62
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_5_3.shtml
|
63
|
+
#
|
64
|
+
# Example:
|
65
|
+
#
|
66
|
+
# ``` ruby
|
67
|
+
# WechatPay::Ecommerce.return_subsidies(sub_mchid: '1600000', transaction_id: '4323400972202104305131070170', amount: 1, description: '订单补差', out_order_no: 'P103333')
|
68
|
+
# ```
|
69
|
+
#
|
70
|
+
def self.cancel_subsidies(params)
|
71
|
+
url = '/v3/ecommerce/subsidies/cancel'
|
72
|
+
method = 'POST'
|
73
73
|
|
74
|
-
|
74
|
+
payload_json = params.to_json
|
75
75
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
76
|
+
make_request(
|
77
|
+
method: method,
|
78
|
+
path: url,
|
79
|
+
for_sign: payload_json,
|
80
|
+
payload: payload_json
|
81
|
+
)
|
83
82
|
end
|
84
83
|
end
|
85
84
|
end
|
@@ -1,155 +1,154 @@
|
|
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 = 'POST'
|
6
|
+
WITHDRAW_FIELDS = %i[sub_mchid out_request_no amount].freeze # :nodoc:
|
7
|
+
#
|
8
|
+
# 二级商户提现
|
9
|
+
#
|
10
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_2.shtml
|
11
|
+
#
|
12
|
+
# Example:
|
13
|
+
#
|
14
|
+
# ``` ruby
|
15
|
+
# WechatPay::Ecommerce.withdraw(sub_mchid: '160000', out_request_no: 'P10000', amount: 1)
|
16
|
+
# ```
|
17
|
+
#
|
18
|
+
def self.withdraw(params)
|
19
|
+
url = '/v3/ecommerce/fund/withdraw'
|
20
|
+
method = 'POST'
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
make_request(
|
23
|
+
method: method,
|
24
|
+
path: url,
|
25
|
+
for_sign: params.to_json,
|
26
|
+
payload: params.to_json
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
QUERY_WITHDRAW_FIELDS = %i[withdraw_id out_request_no sub_mchid].freeze # :nodoc:
|
31
|
+
#
|
32
|
+
# 二级商户提现查询
|
33
|
+
#
|
34
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_3.shtml
|
35
|
+
#
|
36
|
+
# Example:
|
37
|
+
#
|
38
|
+
# ``` ruby
|
39
|
+
# WechatPay::Ecommerce.query_withdraw(withdraw_id: '335556', sub_mchid: '160000')
|
40
|
+
# WechatPay::Ecommerce.query_withdraw(out_request_no: 'P1000', sub_mchid: '160000')
|
41
|
+
# ```
|
42
|
+
#
|
43
|
+
def self.query_withdraw(params)
|
44
|
+
if params[:withdraw_id]
|
45
|
+
params.delete(:out_request_no)
|
46
|
+
withdraw_id = params.delete(:withdraw_id)
|
47
|
+
path = "/v3/ecommerce/fund/withdraw/#{withdraw_id}"
|
48
|
+
else
|
49
|
+
params.delete(:withdraw_id)
|
50
|
+
out_request_no = params.delete(:out_request_no)
|
51
|
+
path = "/v3/ecommerce/fund/withdraw/out-request-no/#{out_request_no}"
|
28
52
|
end
|
29
53
|
|
30
|
-
|
31
|
-
|
32
|
-
#
|
33
|
-
#
|
34
|
-
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_3.shtml
|
35
|
-
#
|
36
|
-
# Example:
|
37
|
-
#
|
38
|
-
# ``` ruby
|
39
|
-
# WechatPay::Ecommerce.query_withdraw(withdraw_id: '335556', sub_mchid: '160000')
|
40
|
-
# WechatPay::Ecommerce.query_withdraw(out_request_no: 'P1000', sub_mchid: '160000')
|
41
|
-
# ```
|
42
|
-
#
|
43
|
-
def query_withdraw(params)
|
44
|
-
if params[:withdraw_id]
|
45
|
-
params.delete(:out_request_no)
|
46
|
-
withdraw_id = params.delete(:withdraw_id)
|
47
|
-
path = "/v3/ecommerce/fund/withdraw/#{withdraw_id}"
|
48
|
-
else
|
49
|
-
params.delete(:withdraw_id)
|
50
|
-
out_request_no = params.delete(:out_request_no)
|
51
|
-
path = "/v3/ecommerce/fund/withdraw/out-request-no/#{out_request_no}"
|
52
|
-
end
|
54
|
+
method = 'GET'
|
55
|
+
query = build_query(params)
|
56
|
+
url = "#{path}?#{query}"
|
53
57
|
|
54
|
-
|
55
|
-
|
56
|
-
url
|
58
|
+
make_request(
|
59
|
+
method: method,
|
60
|
+
path: url,
|
61
|
+
extra_headers: {
|
62
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
63
|
+
}
|
64
|
+
)
|
65
|
+
end
|
57
66
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
67
|
+
PLATFORM_WITHDRAW_FIELDS = %i[out_request_no amount account_type].freeze # :nodoc:
|
68
|
+
#
|
69
|
+
# 电商平台提现
|
70
|
+
#
|
71
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_5.shtml
|
72
|
+
#
|
73
|
+
# Example:
|
74
|
+
#
|
75
|
+
# ``` ruby
|
76
|
+
# WechatPay::Ecommerce.platform_withdraw(out_request_no: 'P10000', amount: 1, account_type: 'BASIC')
|
77
|
+
# WechatPay::Ecommerce.platform_withdraw(out_request_no: 'P10000', amount: 1, account_type: 'FEES')
|
78
|
+
# ```
|
79
|
+
#
|
80
|
+
def self.platform_withdraw(params)
|
81
|
+
url = '/v3/merchant/fund/withdraw'
|
82
|
+
method = 'POST'
|
66
83
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
#
|
75
|
-
# ``` ruby
|
76
|
-
# WechatPay::Ecommerce.platform_withdraw(out_request_no: 'P10000', amount: 1, account_type: 'BASIC')
|
77
|
-
# WechatPay::Ecommerce.platform_withdraw(out_request_no: 'P10000', amount: 1, account_type: 'FEES')
|
78
|
-
# ```
|
79
|
-
#
|
80
|
-
def platform_withdraw(params)
|
81
|
-
url = '/v3/merchant/fund/withdraw'
|
82
|
-
method = 'POST'
|
84
|
+
make_request(
|
85
|
+
method: method,
|
86
|
+
path: url,
|
87
|
+
for_sign: params.to_json,
|
88
|
+
payload: params.to_json
|
89
|
+
)
|
90
|
+
end
|
83
91
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
92
|
+
QUERY_PLATFORM_WITHDRAW_FIELDS = %i[withdraw_id out_request_no].freeze # :nodoc:
|
93
|
+
#
|
94
|
+
# 商户平台提现查询
|
95
|
+
#
|
96
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_6.shtml
|
97
|
+
#
|
98
|
+
# Example:
|
99
|
+
#
|
100
|
+
# ``` ruby
|
101
|
+
# WechatPay::Ecommerce.query_platform_withdraw(out_request_no: 'P1000')
|
102
|
+
# WechatPay::Ecommerce.query_platform_withdraw(withdraw_id: '12313153')
|
103
|
+
# ```
|
104
|
+
#
|
105
|
+
def self.query_platform_withdraw(params)
|
106
|
+
if params[:withdraw_id]
|
107
|
+
params.delete(:out_request_no)
|
108
|
+
withdraw_id = params.delete(:withdraw_id)
|
109
|
+
url = "/v3/merchant/fund/withdraw/withdraw-id/#{withdraw_id}"
|
110
|
+
else
|
111
|
+
params.delete(:withdraw_id)
|
112
|
+
out_request_no = params.delete(:out_request_no)
|
113
|
+
url = "/v3/merchant/fund/withdraw/out-request-no/#{out_request_no}"
|
90
114
|
end
|
91
115
|
|
92
|
-
|
93
|
-
#
|
94
|
-
# 商户平台提现查询
|
95
|
-
#
|
96
|
-
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_6.shtml
|
97
|
-
#
|
98
|
-
# Example:
|
99
|
-
#
|
100
|
-
# ``` ruby
|
101
|
-
# WechatPay::Ecommerce.query_platform_withdraw(out_request_no: 'P1000')
|
102
|
-
# WechatPay::Ecommerce.query_platform_withdraw(withdraw_id: '12313153')
|
103
|
-
# ```
|
104
|
-
#
|
105
|
-
def query_platform_withdraw(params)
|
106
|
-
if params[:withdraw_id]
|
107
|
-
params.delete(:out_request_no)
|
108
|
-
withdraw_id = params.delete(:withdraw_id)
|
109
|
-
url = "/v3/merchant/fund/withdraw/withdraw-id/#{withdraw_id}"
|
110
|
-
else
|
111
|
-
params.delete(:withdraw_id)
|
112
|
-
out_request_no = params.delete(:out_request_no)
|
113
|
-
url = "/v3/merchant/fund/withdraw/out-request-no/#{out_request_no}"
|
114
|
-
end
|
116
|
+
method = 'GET'
|
115
117
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
)
|
125
|
-
end
|
118
|
+
make_request(
|
119
|
+
method: method,
|
120
|
+
path: url,
|
121
|
+
extra_headers: {
|
122
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
123
|
+
}
|
124
|
+
)
|
125
|
+
end
|
126
126
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
127
|
+
DOWNLOAD_EXCEPTION_WITHDRAW_FILE = %i[bill_type bill_date].freeze # :nodoc:
|
128
|
+
#
|
129
|
+
# 按日下载提现异常文件
|
130
|
+
#
|
131
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_4.shtml
|
132
|
+
#
|
133
|
+
# ``` ruby
|
134
|
+
# WechatPay::Ecommerce.download_exception_withdraw_file(bill_type: 'NO_SUCC', bill_date: '2021-05-10')
|
135
|
+
# ```
|
136
|
+
def self.download_exception_withdraw_file(params)
|
137
|
+
bill_type = params.delete(:bill_type)
|
138
|
+
path = "/v3/merchant/fund/withdraw/bill-type/#{bill_type}"
|
139
139
|
|
140
|
-
|
140
|
+
method = 'GET'
|
141
141
|
|
142
|
-
|
143
|
-
|
142
|
+
query = build_query(params)
|
143
|
+
url = "#{path}?#{query}"
|
144
144
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
end
|
145
|
+
make_request(
|
146
|
+
method: method,
|
147
|
+
path: url,
|
148
|
+
extra_headers: {
|
149
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
150
|
+
}
|
151
|
+
)
|
153
152
|
end
|
154
153
|
end
|
155
154
|
end
|
data/lib/wechat-pay/version.rb
CHANGED
data/wechat-pay.gemspec
CHANGED
@@ -11,10 +11,10 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.description = 'A simple Wechat pay ruby gem in api V3.'
|
12
12
|
s.authors = ['lanzhiheng']
|
13
13
|
s.email = 'lanzhihengrj@gmail.com'
|
14
|
-
s.files
|
14
|
+
s.files = `git ls-files -z`.split("\x0").reject do |f|
|
15
15
|
f.match(%r{^(test|spec|features)/})
|
16
16
|
end
|
17
|
-
s.required_ruby_version = '>= 2.
|
17
|
+
s.required_ruby_version = '>= 2.6'
|
18
18
|
s.require_paths = ['lib']
|
19
19
|
s.homepage = 'https://github.com/lanzhiheng/wechat-pay/'
|
20
20
|
s.license = 'MIT'
|
@@ -23,4 +23,5 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_runtime_dependency 'rest-client', '~> 2.0', '>= 2.0.0'
|
24
24
|
s.add_development_dependency 'rake', '~> 13.0', '>= 13.0.3'
|
25
25
|
s.add_development_dependency 'rspec', '~> 3.10.0'
|
26
|
+
s.add_development_dependency 'rubocop', '~> 1.14.0'
|
26
27
|
end
|