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,185 +2,185 @@
|
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
112
|
-
#
|
113
|
-
|
114
|
-
def invoke_transactions_in_h5(params)
|
115
|
-
transactions_method_by_suffix('h5', params)
|
116
|
-
end
|
117
|
-
|
118
|
-
QUERY_ORDER_FIELDS = %i[sub_mchid out_trade_no transaction_id].freeze # :nodoc:
|
119
|
-
#
|
120
|
-
# 订单查询
|
121
|
-
#
|
122
|
-
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_5.shtml
|
123
|
-
#
|
124
|
-
# ``` ruby
|
125
|
-
# WechatPay::Ecommerce.query_order(sub_mchid: '16000008', transaction_id: '4323400972202104305133344444') # by transaction_id
|
126
|
-
# WechatPay::Ecommerce.query_order(sub_mchid: '16000008', out_trade_no: 'N202104302474') # by out_trade_no
|
127
|
-
# ```
|
128
|
-
#
|
129
|
-
def query_order(params)
|
130
|
-
if params[:transaction_id]
|
131
|
-
params.delete(:out_trade_no)
|
132
|
-
transaction_id = params.delete(:transaction_id)
|
133
|
-
path = "/v3/pay/partner/transactions/id/#{transaction_id}"
|
134
|
-
else
|
135
|
-
params.delete(:transaction_id)
|
136
|
-
out_trade_no = params.delete(:out_trade_no)
|
137
|
-
path = "/v3/pay/partner/transactions/out-trade-no/#{out_trade_no}"
|
138
|
-
end
|
139
|
-
|
140
|
-
params = params.merge({
|
141
|
-
sp_mchid: WechatPay.mch_id
|
142
|
-
})
|
143
|
-
|
144
|
-
method = 'GET'
|
145
|
-
query = build_query(params)
|
146
|
-
url = "#{path}?#{query}"
|
147
|
-
|
148
|
-
make_request(
|
149
|
-
method: method,
|
150
|
-
path: url,
|
151
|
-
extra_headers: {
|
152
|
-
'Content-Type' => 'application/x-www-form-urlencoded'
|
153
|
-
}
|
154
|
-
)
|
5
|
+
##
|
6
|
+
# :singleton-method: invoke_transactions_in_js
|
7
|
+
# js下单
|
8
|
+
#
|
9
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_2.shtml
|
10
|
+
#
|
11
|
+
# Example:
|
12
|
+
#
|
13
|
+
# ```
|
14
|
+
# params = {
|
15
|
+
# description: 'pay',
|
16
|
+
# out_trade_no: 'Order Number',
|
17
|
+
# payer: {
|
18
|
+
# sp_openid: 'wechat open id'
|
19
|
+
# },
|
20
|
+
# amount: {
|
21
|
+
# total: 10
|
22
|
+
# },
|
23
|
+
# sub_mchid: 'Your sub mchid',
|
24
|
+
# notify_url: 'the url'
|
25
|
+
# }
|
26
|
+
#
|
27
|
+
# WechatPay::Ecommerce.invoke_transactions_in_js(params)
|
28
|
+
# ```
|
29
|
+
|
30
|
+
##
|
31
|
+
# :singleton-method: invoke_transactions_in_app
|
32
|
+
#
|
33
|
+
# App下单
|
34
|
+
#
|
35
|
+
# https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_1.shtml
|
36
|
+
#
|
37
|
+
# Example:
|
38
|
+
#
|
39
|
+
# ```
|
40
|
+
# params = {
|
41
|
+
# description: 'pay',
|
42
|
+
# out_trade_no: 'Order Number',
|
43
|
+
# payer: {
|
44
|
+
# sp_openid: 'wechat open id'
|
45
|
+
# },
|
46
|
+
# amount: {
|
47
|
+
# total: 10
|
48
|
+
# },
|
49
|
+
# sub_mchid: 'Your sub mchid',
|
50
|
+
# notify_url: 'the url'
|
51
|
+
# }
|
52
|
+
#
|
53
|
+
# WechatPay::Ecommerce.invoke_transactions_in_app(params)
|
54
|
+
# ```
|
55
|
+
|
56
|
+
##
|
57
|
+
# :singleton-method: invoke_transactions_in_h5
|
58
|
+
#
|
59
|
+
# h5下单
|
60
|
+
#
|
61
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_4.shtml
|
62
|
+
#
|
63
|
+
# Example:
|
64
|
+
#
|
65
|
+
# ``` ruby
|
66
|
+
# params = {
|
67
|
+
# description: 'pay',
|
68
|
+
# out_trade_no: 'Order Number',
|
69
|
+
# amount: {
|
70
|
+
# total: 10
|
71
|
+
# },
|
72
|
+
# sub_mchid: 'Your sub mchid',
|
73
|
+
# notify_url: 'the url'
|
74
|
+
# }
|
75
|
+
#
|
76
|
+
# WechatPay::Ecommerce.invoke_transactions_in_h5(params)
|
77
|
+
# ```
|
78
|
+
|
79
|
+
##
|
80
|
+
# :singleton-method: invoke_transactions_in_miniprogram
|
81
|
+
#
|
82
|
+
# 小程序下单
|
83
|
+
#
|
84
|
+
# Document:
|
85
|
+
#
|
86
|
+
# Example:
|
87
|
+
#
|
88
|
+
# ```
|
89
|
+
# params = {
|
90
|
+
# description: 'pay',
|
91
|
+
# out_trade_no: 'Order Number',
|
92
|
+
# payer: {
|
93
|
+
# sp_openid: 'wechat open id'
|
94
|
+
# },
|
95
|
+
# amount: {
|
96
|
+
# total: 10
|
97
|
+
# },
|
98
|
+
# sub_mchid: 'Your sub mchid',
|
99
|
+
# notify_url: 'the url'
|
100
|
+
# }
|
101
|
+
#
|
102
|
+
# WechatPay::Ecommerce.invoke_transactions_in_miniprogram(params)
|
103
|
+
# ```
|
104
|
+
{
|
105
|
+
js: 'jsapi',
|
106
|
+
app: 'app',
|
107
|
+
h5: 'h5',
|
108
|
+
miniprogram: 'jsapi'
|
109
|
+
}.each do |key, value|
|
110
|
+
const_set("INVOKE_TRANSACTIONS_IN_#{key.upcase}_FIELDS",
|
111
|
+
%i[sub_mchid description out_trade_no notify_url amount].freeze)
|
112
|
+
define_singleton_method("invoke_transactions_in_#{key}") do |params|
|
113
|
+
transactions_method_by_suffix(value, params)
|
155
114
|
end
|
115
|
+
end
|
156
116
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
117
|
+
QUERY_ORDER_FIELDS = %i[sub_mchid out_trade_no transaction_id].freeze # :nodoc:
|
118
|
+
#
|
119
|
+
# 订单查询
|
120
|
+
#
|
121
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_5.shtml
|
122
|
+
#
|
123
|
+
# ``` ruby
|
124
|
+
# WechatPay::Ecommerce.query_order(sub_mchid: '16000008', transaction_id: '4323400972202104305133344444') # by transaction_id
|
125
|
+
# WechatPay::Ecommerce.query_order(sub_mchid: '16000008', out_trade_no: 'N202104302474') # by out_trade_no
|
126
|
+
# ```
|
127
|
+
#
|
128
|
+
def self.query_order(params)
|
129
|
+
if params[:transaction_id]
|
130
|
+
params.delete(:out_trade_no)
|
131
|
+
transaction_id = params.delete(:transaction_id)
|
132
|
+
path = "/v3/pay/partner/transactions/id/#{transaction_id}"
|
133
|
+
else
|
134
|
+
params.delete(:transaction_id)
|
168
135
|
out_trade_no = params.delete(:out_trade_no)
|
169
|
-
|
170
|
-
|
171
|
-
sp_mchid: WechatPay.mch_id
|
172
|
-
})
|
136
|
+
path = "/v3/pay/partner/transactions/out-trade-no/#{out_trade_no}"
|
137
|
+
end
|
173
138
|
|
174
|
-
|
139
|
+
params = params.merge({
|
140
|
+
sp_mchid: WechatPay.mch_id
|
141
|
+
})
|
142
|
+
|
143
|
+
method = 'GET'
|
144
|
+
query = build_query(params)
|
145
|
+
url = "#{path}?#{query}"
|
146
|
+
|
147
|
+
make_request(
|
148
|
+
method: method,
|
149
|
+
path: url,
|
150
|
+
extra_headers: {
|
151
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
152
|
+
}
|
153
|
+
)
|
154
|
+
end
|
175
155
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
156
|
+
CLOSE_ORDER_FIELDS = %i[sub_mchid out_trade_no].freeze # :nodoc:
|
157
|
+
#
|
158
|
+
# 关闭订单
|
159
|
+
#
|
160
|
+
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_6.shtml
|
161
|
+
#
|
162
|
+
# ``` ruby
|
163
|
+
# WechatPay::Ecommerce.close_order(sub_mchid: '16000008', out_trade_no: 'N3344445')
|
164
|
+
# ```
|
165
|
+
#
|
166
|
+
def self.close_order(params)
|
167
|
+
out_trade_no = params.delete(:out_trade_no)
|
168
|
+
url = "/v3/pay/partner/transactions/out-trade-no/#{out_trade_no}/close"
|
169
|
+
params = params.merge({
|
170
|
+
sp_mchid: WechatPay.mch_id
|
171
|
+
})
|
172
|
+
|
173
|
+
method = 'POST'
|
174
|
+
|
175
|
+
make_request(
|
176
|
+
method: method,
|
177
|
+
path: url,
|
178
|
+
for_sign: params.to_json,
|
179
|
+
payload: params.to_json
|
180
|
+
)
|
181
|
+
end
|
183
182
|
|
183
|
+
class << self
|
184
184
|
private
|
185
185
|
|
186
186
|
def transactions_method_by_suffix(suffix, params)
|
data/lib/wechat-pay/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wechat-pay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lanzhiheng
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -51,39 +51,39 @@ dependencies:
|
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '2.0'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
-
name:
|
54
|
+
name: rake
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
57
|
- - "~>"
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version:
|
59
|
+
version: '13.0'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 13.0.3
|
60
63
|
type: :development
|
61
64
|
prerelease: false
|
62
65
|
version_requirements: !ruby/object:Gem::Requirement
|
63
66
|
requirements:
|
64
67
|
- - "~>"
|
65
68
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
69
|
+
version: '13.0'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 13.0.3
|
67
73
|
- !ruby/object:Gem::Dependency
|
68
|
-
name:
|
74
|
+
name: rspec
|
69
75
|
requirement: !ruby/object:Gem::Requirement
|
70
76
|
requirements:
|
71
77
|
- - "~>"
|
72
78
|
- !ruby/object:Gem::Version
|
73
|
-
version:
|
74
|
-
- - ">="
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: 13.0.3
|
79
|
+
version: 3.10.0
|
77
80
|
type: :development
|
78
81
|
prerelease: false
|
79
82
|
version_requirements: !ruby/object:Gem::Requirement
|
80
83
|
requirements:
|
81
84
|
- - "~>"
|
82
85
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
84
|
-
- - ">="
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
version: 13.0.3
|
86
|
+
version: 3.10.0
|
87
87
|
description: A simple Wechat pay ruby gem in api V3.
|
88
88
|
email: lanzhihengrj@gmail.com
|
89
89
|
executables: []
|
@@ -106,11 +106,10 @@ files:
|
|
106
106
|
- lib/wechat-pay/helper.rb
|
107
107
|
- lib/wechat-pay/sign.rb
|
108
108
|
- lib/wechat-pay/version.rb
|
109
|
-
homepage: https://
|
109
|
+
homepage: https://github.com/lanzhiheng/wechat-pay/
|
110
110
|
licenses:
|
111
111
|
- MIT
|
112
|
-
metadata:
|
113
|
-
source_code_uri: https://github.com/lanzhiheng/wechat-pay
|
112
|
+
metadata: {}
|
114
113
|
post_install_message:
|
115
114
|
rdoc_options: []
|
116
115
|
require_paths:
|