jdpay 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6ec31d9771e22fdd3030e3bda86d6aead0632998
4
+ data.tar.gz: 23fbf0018d9e831a09ff890dd1ff0ba069d59d40
5
+ SHA512:
6
+ metadata.gz: 72d2ff2bbce889934299a613cfb37f836db2df5a987300d61f4b0d326eabf614a6420bf7c8c9931629619a23977bc56738a1dda560e3ab9ebea9eb897ebfeb00
7
+ data.tar.gz: 9bd84ae9f8c89e4ddc97a46fbb2dbcc5f0a975ba0267d8f850c3384eafab6aae7f4422e519a083140915ea8f4a0c465b99abde11d9046866918f07244badea10
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/db/*.sqlite3-journal
6
+ test/dummy/log/*.log
7
+ test/dummy/tmp/
8
+ test/dummy/.sass-cache
9
+ *.gem
10
+ *.rbc
11
+ .bundle
12
+ .config
13
+ .yardoc
14
+ Gemfile.lock
15
+ tmp
16
+ test/tmp
17
+ test/version_tmp
18
+ .idea
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ before_install:
3
+ - gem install bundler
4
+ rvm:
5
+ - 2.1.0
6
+ - 2.2.5
7
+ - 2.3.0
8
+ - 2.4.0
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at hemengzhi88@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jd_pay.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Genkin He
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,361 @@
1
+ # JdPay
2
+
3
+ A unofficial jd_pay ruby gem.
4
+ Thanks for [alipay](https://github.com/chloerei/alipay) and [wx_pay](https://github.com/jasl/wx_pay)
5
+
6
+ JdPay official document: http://payapi.jd.com/.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'jdpay'
14
+ ```
15
+
16
+ or development version
17
+
18
+ ```ruby
19
+ gem 'jdpay', :github => 'genkin-he/jd_pay'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ ```sh
25
+ $ bundle
26
+ ```
27
+
28
+ ## Configuration
29
+
30
+ ```ruby
31
+ # NOTE: 京东支付与京东付款码支付是两套账号密钥.
32
+ # 京东支付配置
33
+ JdPay.mch_id = 'YOUR_MERCHANT_NUM'
34
+ JdPay.des_key = 'YOUR_3DES_KEY'
35
+ JdPay.md5_key = 'YOUR_MD5_KEY'
36
+ JdPay.pri_key = 'YOUR_RSA_PRIVATE_KEY'
37
+ # 京东付款码支付配置
38
+ JdPay.qr_mch_id = 'YOUR_MERCHANT_NUM'
39
+ JdPay.qr_des_key = 'YOUR_3DES_KEY'
40
+ JdPay.qr_pri_key = 'YOUR_RSA_PRIVATE_KEY'
41
+
42
+ #JdPay.pub_key = 'JDPAY_RSA_PUBLIC_KEY'
43
+ #JdPay.debug_mode = true # Enable parameter check. Default is true.
44
+ ```
45
+
46
+ You can set default key, or pass a key directly to service method:
47
+
48
+ ```ruby
49
+ Service.uniorder({
50
+ tradeNum: 'TRADE_NUM',
51
+ }, {
52
+ mch_id: 'YOUR_MERCHANT_NUM',
53
+ des_key: 'YOUR_3DES_KEY',
54
+ md5_key: 'YOUR_MD5_KEY',
55
+ pri_key: 'YOUR_RSA_PRIVATE_KEY'
56
+ })
57
+ ```
58
+
59
+ ## Service(京东支付账户)
60
+ Check **[JdPay official document](http://payapi.jd.com/)** for detailed request params and return fields
61
+
62
+ ### 统一下单接口
63
+
64
+ #### Name && Description
65
+ > 商户系统先调用该接口在京东支付服务后台生成交易单,再按扫码、APP等不同场景发起支付
66
+
67
+ ```ruby
68
+ uniorder
69
+ ```
70
+ #### Definition
71
+
72
+ ```ruby
73
+ JdPay::Service.uniorder(params, options = {})
74
+ ```
75
+ #### Example
76
+
77
+ ```ruby
78
+ # required fields
79
+ # [:tradeNum, :tradeName, :amount, :orderType, :notifyUrl, :userId]
80
+ params = {
81
+ tradeNum: '123456780',
82
+ tradeName: '测试商品',
83
+ amount: '1',
84
+ orderType: '0',
85
+ notifyUrl: 'http://making.dev/notify',
86
+ userId: '123456780'
87
+ }
88
+ result = JdPay::Service.uniorder(params)
89
+
90
+ # Used for app
91
+ signData = JdPay::Sign.md5_sign(result['jdpay']['orderId'], options)
92
+ ```
93
+ ### 在线支付接口PC
94
+ #### Name && Description
95
+ > 支付请求接口提供给商户向京东支付服务发送支付请求数据集合,京东支付服务会根据请求数据验证商户身份,以及验证支付信息是否被篡改。验证通过后,京东支付服务会在当前页面弹出支付页面弹框。
96
+
97
+ ```ruby
98
+ pc_pay
99
+ ```
100
+ #### Definition
101
+
102
+ ```ruby
103
+ JdPay::Service.pc_pay(params, options = {})
104
+ ```
105
+ #### Example
106
+ ```ruby
107
+ # required keys
108
+ # [:tradeNum, :tradeName, :amount, :orderType, :notifyUrl, :callbackUrl, :userId]
109
+ params = {
110
+ tradeNum: '12345678',
111
+ tradeName: '测试商品',
112
+ amount: '1',
113
+ orderType: '0',
114
+ notifyUrl: 'http://making.dev/notify',
115
+ callbackUrl: 'http://frontend.com/return',
116
+ userId: "0000001"
117
+ }
118
+ JdPay::Service.pc_pay(params)
119
+ ```
120
+ ### 在线支付接口H5
121
+ #### Name && Description
122
+ > 在线支付接口的手机版本,用法参照在线支付PC接口,不再赘述。
123
+
124
+ ```ruby
125
+ h5_pay
126
+ ```
127
+ #### Definition
128
+
129
+ ```ruby
130
+ JdPay::Service.pc_pay(params, options = {})
131
+ ```
132
+
133
+ ### 交易查询接口
134
+ #### Name && Description
135
+ > 交易查询接口是为了处理商户服务器长时间没有接收到支付结果的情况设计的。一般情况,支付结果会通过前端同步返回和京东支付服务器的异步通知发送到商户服务。但是为避免特殊情况商户服务器仍然没有接收到支付结果,这时候商户服务可以通过主动查询交易结果的接口查询支付状态。
136
+
137
+ ```ruby
138
+ query
139
+ ```
140
+ #### Definition
141
+
142
+ ```ruby
143
+ JdPay::Service.query(params, options = {})
144
+ ```
145
+ #### Example
146
+
147
+ ```ruby
148
+ # required keys:
149
+ # cost trade query [:tradeNum, :tradeType]
150
+ # refund trade query [:tradeNum, :oTradeNum, :tradeType]
151
+ params = {
152
+ tradeNum: '12345678',
153
+ tradeType: '1',
154
+ oTradeNum: "12345677",
155
+ }
156
+ JdPay::Service.query(params)
157
+ ```
158
+
159
+ ### 退款申请接口
160
+ #### Name && Description
161
+ > 退款申请接口提供给商户发起自动退款的能力。如果用户在商户系统下单支付以后发起退款,商户验证通过之后可以自动发起退款请求。同时京东支付商户管理后台提供手动退款的功能。
162
+
163
+ ```ruby
164
+ refund
165
+ ```
166
+ #### Definition
167
+
168
+ ```ruby
169
+ JdPay::Service.refund(params, options = {})
170
+ ```
171
+ #### Example
172
+
173
+ ```ruby
174
+ # refund required keys [:tradeNum, :oTradeNum, :amount, :notifyUrl]
175
+ params = {
176
+ tradeNum: '12345678',
177
+ oTradeNum: "12345677",
178
+ amount: '1',
179
+ notifyUrl: 'http://making.dev/notify',
180
+ }
181
+ JdPay::Service.refund(params)
182
+ ```
183
+
184
+ ### 撤销申请接口
185
+ #### Name && Description
186
+ > 撤销申请接口提供给商户发起自动撤销的能力。对于未支付的订单撤销后不可再次支付,对于支付成功的订单则发起退款。
187
+
188
+ ```ruby
189
+ revoke
190
+ ```
191
+ #### Definition
192
+
193
+ ```ruby
194
+ JdPay::Service.revoke(params, options = {})
195
+ ```
196
+ #### Example
197
+
198
+ ```ruby
199
+ # revoke required keys [:tradeNum, :oTradeNum, :amount, :notifyUrl]
200
+ params = {
201
+ tradeNum: '12345678',
202
+ oTradeNum: "12345677",
203
+ amount: '1',
204
+ }
205
+ JdPay::Service.revoke(params)
206
+ ```
207
+ ### 异步通知解密验签
208
+ #### Name && Description
209
+ > 商户后台将收到的京东异步通知XML内容解密及验签.
210
+
211
+ ```ruby
212
+ notify_verify
213
+ ```
214
+ #### Definition
215
+
216
+ ```ruby
217
+ JdPay::Service.notify_verify(xml_str, options = {})
218
+ ```
219
+ #### Example
220
+
221
+ ```ruby
222
+ # notify_verify required xml_str
223
+ notyfy_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hiOTVmM2ExMDk1NzFlZDE5NTZhMzM5MjI1Mjk3NmVlMjYwODJjOWMyNjUyMDllMzE4ZTBmMTY0MDgzYTU0ODMyOTFmNTFhMTcyMGYwMTQwOTg1NjdkYjZkZGZhZjI5NzE1ZTA5YjFhNDczNjZkNTY3MDYwZDRmZmIzZjVjNjgyZTczZjFmNjJmY2YxYWE1NDAxZDk4NDE0NjdhZDE5OTMxZGZkZDdjNWI0YzZlNTkzNjU3OGRkZTA1MmNhM2JiZDhmYjg3NWE3NDY2NjA0YTU0M2ExOWNiZjQyNzlhM2UyMDc3MzI3YjI3NWFlYjQ3ZmU3NjMyZTAxN2E4ZmZkY2UyZjg3M2I2ZTcwYTE4Y2MzNWE3YjFiNmZjYzJkY2E4MjNkZGNmNmFhOWRlZWQzYjE3NTI5MGQ5NDZkMTQ5NmFhZjJiOGM0OGEwNzU3OGM4ODIzZTVhNTU2YjU1OTk5ZTJiMjEwYmYzMjFmN2M5MmU3Yzc2NjJiMzdmNmI1Y2JjNjFiYjllYjY0Zjc3NWMwMDVlNGY4YmVjNzhmZWNmZGFmNWJkNjc2ODY1ZTAwYzllODRkNjg2ZDNmZTBjOTJiOTYwMjlmMWIxYThjMzQzYmE3YzkxNTUzMDI4OTBjYzU0YTJiMGM2Yjg1ZTQ=</encrypt>
233
+ </jdpay>
234
+ EOF
235
+
236
+ JdPay::Service.notify_verify(notyfy_xml)
237
+ ```
238
+ ### 用户关系查询接口
239
+ #### Name && Description
240
+ > 若商户用户与京东用户关联,下次支付时可跳过身份识别环境进行支付。此接口提供了用户关系查询功能。
241
+
242
+ ```ruby
243
+ user_relation
244
+ ```
245
+ #### Definition
246
+
247
+ ```ruby
248
+ JdPay::Service.user_relation(params, options = {})
249
+ ```
250
+ #### Example
251
+
252
+ ```ruby
253
+ # refund required keys [:userId]
254
+ params = { userId: '12345678' }
255
+ JdPay::Service.user_relation(params)
256
+ ```
257
+ ### 用户关系解绑接口
258
+ #### Name && Description
259
+ > 解绑用户关系,解绑后,用户下一次支付,需重新通过手机等登录方式进行身份验证。
260
+
261
+ ```ruby
262
+ cancel_user
263
+ ```
264
+ #### Definition
265
+
266
+ ```ruby
267
+ JdPay::Service.cancel_user(params, options = {})
268
+ ```
269
+ #### Example
270
+
271
+ ```ruby
272
+ # refund required keys [:userId]
273
+ params = { userId: '12345678' }
274
+ JdPay::Service.cancel_user(params)
275
+ ```
276
+ ## QrService(京东付款码账户)
277
+
278
+ ### 京东付款码支付接口
279
+
280
+ #### Name && Description
281
+ > 付款码支付接口用于客户使用付款码支付时,商户使用扫码枪完成一键下单并支付功能。在支付过程中对支付请求进行校验后,完成支付流程。
282
+
283
+ ```ruby
284
+ qrcode_pay
285
+ ```
286
+ #### Definition
287
+
288
+ ```ruby
289
+ JdPay::QrService.qrcode_pay(params, options = {})
290
+ ```
291
+ #### Example
292
+
293
+ ```ruby
294
+ # required fields
295
+ # [:tradeNum, :tradeName, :amount, :device, :token]
296
+ params = {
297
+ tradeNum: '123456780',
298
+ tradeName: '测试商品',
299
+ amount: '1',
300
+ device: '0001',
301
+ token: '2563256985478547856'
302
+ }
303
+ JdPay::QrService.qrcode_pay(params)
304
+ ```
305
+ ### 京东付款码交易查询
306
+ #### Definition
307
+
308
+ ```ruby
309
+ JdPay::QrService.query(params, options = {})
310
+ ```
311
+ #### Example
312
+
313
+ ```ruby
314
+ # refer to:JdPay::Service.query(params, options = {})
315
+ ```
316
+ ### 京东付款码交易退款
317
+ #### Definition
318
+
319
+ ```ruby
320
+ JdPay::QrService.refund(params, options = {})
321
+ ```
322
+ #### Example
323
+
324
+ ```ruby
325
+ # refer to:JdPay::Service.refund(params, options = {})
326
+ ```
327
+ ### 京东付款码异步通知解密验签
328
+ #### Definition
329
+
330
+ ```ruby
331
+ JdPay::QrService.notify_verify(params, options = {})
332
+ ```
333
+ #### Example
334
+
335
+ ```ruby
336
+ # refer to:JdPay::Service.notify_verify(params, options = {})
337
+ ```
338
+ ## Contributing
339
+
340
+ Bug report or pull request are welcome.
341
+
342
+ ### Make a pull request
343
+
344
+ 1. Fork it
345
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
346
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
347
+ 4. Push to the branch (`git push origin my-new-feature`)
348
+ 5. Create new Pull Request
349
+
350
+ Please write unit test with your code if necessary.
351
+
352
+ ## License
353
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
354
+
355
+ ## Donate
356
+ Donate to maintainer let him make this gem better.
357
+
358
+ [donate link](https://ruby-china.org/hemengzhi88).<br/>
359
+
360
+ <img src="https://raw.githubusercontent.com/genkin-he/md_photos/master/alipay.jpg" alt="alipay" width="200" align='left'>
361
+ <img src="https://raw.githubusercontent.com/genkin-he/md_photos/master/wx_pay.png" alt="wx_pay" width="220" align='left'>