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.
@@ -1,85 +1,84 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WechatPay
4
+ # 补差相关
4
5
  module Ecommerce
5
- class << self
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 request_subsidies(params)
19
- url = '/v3/ecommerce/subsidies/create'
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
- payload_json = params.to_json
22
+ payload_json = params.to_json
23
23
 
24
- make_request(
25
- method: method,
26
- path: url,
27
- for_sign: payload_json,
28
- payload: payload_json
29
- )
30
- end
24
+ make_request(
25
+ method: method,
26
+ path: url,
27
+ for_sign: payload_json,
28
+ payload: payload_json
29
+ )
30
+ end
31
31
 
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
- # ```
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
- def return_subsidies(params)
45
- url = '/v3/ecommerce/subsidies/return'
46
- method = 'POST'
44
+ def self.return_subsidies(params)
45
+ url = '/v3/ecommerce/subsidies/return'
46
+ method = 'POST'
47
47
 
48
- payload_json = params.to_json
48
+ payload_json = params.to_json
49
49
 
50
- make_request(
51
- method: method,
52
- path: url,
53
- for_sign: payload_json,
54
- payload: payload_json
55
- )
56
- end
50
+ make_request(
51
+ method: method,
52
+ path: url,
53
+ for_sign: payload_json,
54
+ payload: payload_json
55
+ )
56
+ end
57
57
 
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 cancel_subsidies(params)
71
- url = '/v3/ecommerce/subsidies/cancel'
72
- method = 'POST'
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
- payload_json = params.to_json
74
+ payload_json = params.to_json
75
75
 
76
- make_request(
77
- method: method,
78
- path: url,
79
- for_sign: payload_json,
80
- payload: payload_json
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
- class<<self
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 withdraw(params)
19
- url = '/v3/ecommerce/fund/withdraw'
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
- make_request(
23
- method: method,
24
- path: url,
25
- for_sign: params.to_json,
26
- payload: params.to_json
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
- 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 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
- method = 'GET'
55
- query = build_query(params)
56
- url = "#{path}?#{query}"
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
- make_request(
59
- method: method,
60
- path: url,
61
- extra_headers: {
62
- 'Content-Type' => 'application/x-www-form-urlencoded'
63
- }
64
- )
65
- end
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
- 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 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
- make_request(
85
- method: method,
86
- path: url,
87
- for_sign: params.to_json,
88
- payload: params.to_json
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
- 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 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
- method = 'GET'
117
-
118
- make_request(
119
- method: method,
120
- path: url,
121
- extra_headers: {
122
- 'Content-Type' => 'application/x-www-form-urlencoded'
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
- 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 download_exception_withdraw_file(params)
137
- bill_type = params.delete(:bill_type)
138
- path = "/v3/merchant/fund/withdraw/bill-type/#{bill_type}"
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
- method = 'GET'
140
+ method = 'GET'
141
141
 
142
- query = build_query(params)
143
- url = "#{path}?#{query}"
142
+ query = build_query(params)
143
+ url = "#{path}?#{query}"
144
144
 
145
- make_request(
146
- method: method,
147
- path: url,
148
- extra_headers: {
149
- 'Content-Type' => 'application/x-www-form-urlencoded'
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WechatPay
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.8'
5
5
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+
5
+ require 'wechat-pay/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = 'wechat-pay'
9
+ s.version = WechatPay::VERSION
10
+ s.summary = 'Wechat Pay in api V3'
11
+ s.description = 'A simple Wechat pay ruby gem in api V3.'
12
+ s.authors = ['lanzhiheng']
13
+ s.email = 'lanzhihengrj@gmail.com'
14
+ s.files = `git ls-files -z`.split("\x0").reject do |f|
15
+ f.match(%r{^(test|spec|features)/})
16
+ end
17
+ s.required_ruby_version = '>= 2.6'
18
+ s.require_paths = ['lib']
19
+ s.homepage = 'https://github.com/lanzhiheng/wechat-pay/'
20
+ s.license = 'MIT'
21
+
22
+ s.add_runtime_dependency 'activesupport', '>= 3.2', '~> 6.0.0'
23
+ s.add_runtime_dependency 'rest-client', '~> 2.0', '>= 2.0.0'
24
+ s.add_development_dependency 'rake', '~> 13.0', '>= 13.0.3'
25
+ s.add_development_dependency 'rspec', '~> 3.10.0'
26
+ s.add_development_dependency 'rubocop', '~> 1.14.0'
27
+ end