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,185 +2,185 @@
2
2
 
3
3
  module WechatPay
4
4
  module Ecommerce
5
- class << self
6
- INVOKE_TRANSACTIONS_IN_JS_FIELDS = %i[sub_mchid description out_trade_no notify_url amount].freeze # :nodoc:
7
- #
8
- # js下单
9
- #
10
- # Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_2.shtml
11
- #
12
- # Example:
13
- #
14
- # ```
15
- # params = {
16
- # description: 'pay',
17
- # out_trade_no: 'Order Number',
18
- # payer: {
19
- # sp_openid: 'wechat open id'
20
- # },
21
- # amount: {
22
- # total: 10
23
- # },
24
- # sub_mchid: 'Your sub mchid',
25
- # notify_url: 'the url'
26
- # }
27
- #
28
- # WechatPay::Ecommerce.invoke_transactions_in_app(params)
29
- # ```
30
- def invoke_transactions_in_js(params)
31
- transactions_method_by_suffix('jsapi', params)
32
- end
33
-
34
- INVOKE_TRANSACTIONS_IN_MINIPROGRAM_FIELDS = %i[sub_mchid description out_trade_no notify_url amount].freeze # :nodoc:
35
- #
36
- # 小程序下单
37
- #
38
- # Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_3.shtml
39
- #
40
- # Example:
41
- #
42
- # ```
43
- # params = {
44
- # description: 'pay',
45
- # out_trade_no: 'Order Number',
46
- # payer: {
47
- # sp_openid: 'wechat open id'
48
- # },
49
- # amount: {
50
- # total: 10
51
- # },
52
- # sub_mchid: 'Your sub mchid',
53
- # notify_url: 'the url'
54
- # }
55
- #
56
- # WechatPay::Ecommerce.invoke_transactions_in_miniprogram(params)
57
- # ```
58
- def invoke_transactions_in_miniprogram(params)
59
- transactions_method_by_suffix('jsapi', params)
60
- end
61
-
62
- INVOKE_TRANSACTIONS_IN_APP_FIELDS = %i[sub_mchid description out_trade_no notify_url amount].freeze # :nodoc:
63
- #
64
- # App下单
65
- #
66
- # https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_1.shtml
67
- #
68
- # Example:
69
- #
70
- # ```
71
- # params = {
72
- # description: 'pay',
73
- # out_trade_no: 'Order Number',
74
- # payer: {
75
- # sp_openid: 'wechat open id'
76
- # },
77
- # amount: {
78
- # total: 10
79
- # },
80
- # sub_mchid: 'Your sub mchid',
81
- # notify_url: 'the url'
82
- # }
83
- #
84
- # WechatPay::Ecommerce.invoke_transactions_in_miniprogram(params)
85
- # ```
86
- def invoke_transactions_in_app(params)
87
- transactions_method_by_suffix('app', params)
88
- end
89
-
90
- INVOKE_TRANSACTIONS_IN_H5_FIELDS = %i[sub_mchid description out_trade_no notify_url amount].freeze # :nodoc:
91
- #
92
- # h5下单
93
- #
94
- # Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_4.shtml
95
- #
96
- # Example:
97
- #
98
- # ``` ruby
99
- # params = {
100
- # description: 'pay',
101
- # out_trade_no: 'Order Number',
102
- # payer: {
103
- # sp_openid: 'wechat open id'
104
- # },
105
- # amount: {
106
- # total: 10
107
- # },
108
- # sub_mchid: 'Your sub mchid',
109
- # notify_url: 'the url'
110
- # }
111
- #
112
- # WechatPay::Ecommerce.invoke_transactions_in_h5(params)
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
- CLOSE_ORDER_FIELDS = %i[sub_mchid out_trade_no].freeze # :nodoc:
158
- #
159
- # 关闭订单
160
- #
161
- # Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_6.shtml
162
- #
163
- # ``` ruby
164
- # WechatPay::Ecommerce.close_order(sub_mchid: '16000008', out_trade_no: 'N3344445')
165
- # ```
166
- #
167
- def close_order(params)
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
- url = "/v3/pay/partner/transactions/out-trade-no/#{out_trade_no}/close"
170
- params = params.merge({
171
- sp_mchid: WechatPay.mch_id
172
- })
136
+ path = "/v3/pay/partner/transactions/out-trade-no/#{out_trade_no}"
137
+ end
173
138
 
174
- method = 'POST'
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
- make_request(
177
- method: method,
178
- path: url,
179
- for_sign: params.to_json,
180
- payload: params.to_json
181
- )
182
- end
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)
@@ -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.3'
5
5
  end
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.1
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-13 00:00:00.000000000 Z
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: minitest
54
+ name: rake
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
- version: 5.14.4
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: 5.14.4
69
+ version: '13.0'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 13.0.3
67
73
  - !ruby/object:Gem::Dependency
68
- name: rake
74
+ name: rspec
69
75
  requirement: !ruby/object:Gem::Requirement
70
76
  requirements:
71
77
  - - "~>"
72
78
  - !ruby/object:Gem::Version
73
- version: '13.0'
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: '13.0'
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://rubygems.org/gems/wechat-pay
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: