chan_pay 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +35 -11
- data/chan_pay.gemspec +1 -1
- data/lib/chan_pay/api/query_order.rb +4 -2
- data/lib/chan_pay/api/query_quick_order.rb +45 -0
- data/lib/chan_pay/api/quick_draw.rb +60 -0
- data/lib/chan_pay/api/sms_pay_request.rb +1 -1
- data/lib/chan_pay/api/{quick_pay.rb → withhold_pay.rb} +3 -3
- data/lib/chan_pay/client.rb +8 -3
- data/lib/chan_pay/http/ret_code.rb +37 -4
- data/lib/chan_pay/version.rb +1 -1
- data/lib/chan_pay.rb +10 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b660e51012104b31a2a35ef0125c38529d2892d
|
4
|
+
data.tar.gz: bbc38f701057995bacae192f2a213f5937af6494
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b83041be93f3df9426f921a8d811c9afe2bf45af5b225f7a53d488b48a1d33bdd88461c026333b28997adb673edae36d6a5ba51ee46d856f27e10370445f0b07
|
7
|
+
data.tar.gz: 90d589f11edd3f67c205de143389cc6eebdb921866c45f3551fbdfe172e9b26a32ef94077ccf91c90e46f3c7306430cd025379f084769f7f6a95b96cfa2f7391
|
data/README.md
CHANGED
@@ -1,39 +1,63 @@
|
|
1
1
|
# ChanPay
|
2
2
|
|
3
|
-
|
3
|
+
用友畅捷支付 API ruby sdk,目前提供以下接口
|
4
4
|
|
5
|
-
|
5
|
+
1. 直接支付请求接口
|
6
|
+
2. 支付确认接口
|
7
|
+
3. 短信验证码重发接口
|
8
|
+
4. 确认收货接口
|
9
|
+
5. 商户余额查询
|
10
|
+
6. 快捷代扣请求接口
|
6
11
|
|
7
|
-
##
|
12
|
+
## 安装
|
8
13
|
|
9
|
-
|
14
|
+
Gemfile 中增加:
|
10
15
|
|
11
16
|
```ruby
|
12
17
|
gem 'chan_pay'
|
13
18
|
```
|
14
19
|
|
15
|
-
|
20
|
+
然后执行命令:
|
16
21
|
|
17
22
|
$ bundle
|
18
23
|
|
19
|
-
|
24
|
+
或者直接安装:
|
20
25
|
|
21
26
|
$ gem install chan_pay
|
22
27
|
|
23
|
-
##
|
28
|
+
## 快速指南
|
24
29
|
|
25
|
-
|
30
|
+
1. 初始化
|
26
31
|
|
27
|
-
|
32
|
+
```ruby
|
33
|
+
client = ChanPay::Client.new(
|
34
|
+
partner_id: partner_id,
|
35
|
+
seller_id: seller_id,
|
36
|
+
server_url: server_url,
|
37
|
+
private_key: private_key,
|
38
|
+
public_key: public_key,
|
39
|
+
)
|
40
|
+
```
|
28
41
|
|
29
|
-
|
42
|
+
2. 调用各个 api,比如查询接口:
|
30
43
|
|
31
|
-
|
44
|
+
```ruby
|
45
|
+
client.query_balance(商户自定义唯一订单号)
|
46
|
+
```
|
32
47
|
|
33
48
|
## Contributing
|
34
49
|
|
35
50
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/chan_pay. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
51
|
|
52
|
+
## Make a pull request
|
53
|
+
|
54
|
+
1. Fork it
|
55
|
+
2. Create your feature branch (git checkout -b my-new-feature)
|
56
|
+
3. Commit your changes (git commit -am 'Add some feature')
|
57
|
+
4. Push to the branch (git push origin my-new-feature)
|
58
|
+
5. Create new Pull Request
|
59
|
+
6. Please write unit test with your code if necessary.
|
60
|
+
|
37
61
|
|
38
62
|
## License
|
39
63
|
|
data/chan_pay.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["tony@omniaccount.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{"畅捷支付"}
|
13
|
-
spec.description = %q{"畅捷支付"}
|
13
|
+
spec.description = %q{"畅捷支付SDK"}
|
14
14
|
spec.homepage = "https://github.com/omniaccountcorp/chan_pay"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -22,13 +22,15 @@ module ChanPay
|
|
22
22
|
:TradeType => 'pay_order',
|
23
23
|
}
|
24
24
|
|
25
|
-
response = Http.post(@partner_id,
|
25
|
+
response = Http.post(@partner_id,
|
26
|
+
@private_key, @public_key, @server_uri,
|
27
|
+
SERVICE_NAME, params)
|
26
28
|
|
27
29
|
res = {
|
28
30
|
result: 'P', # 默认 pending
|
29
31
|
msg: response[:RetMsg],
|
30
32
|
ret_code: response[:RetCode],
|
31
|
-
flow_id:
|
33
|
+
flow_id: flow_id,
|
32
34
|
vendor_order_id: response[:OrderTrxid],
|
33
35
|
extension: response[:Extension],
|
34
36
|
log: [params.to_json, response.to_json],
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# 查询代付代收订单
|
4
|
+
|
5
|
+
module ChanPay
|
6
|
+
module Api
|
7
|
+
module QueryQuickOrder
|
8
|
+
|
9
|
+
SERVICE_NAME = 'cjt_dsf'
|
10
|
+
|
11
|
+
def query_quick_order(flow_id, ori_flow_id)
|
12
|
+
params = {
|
13
|
+
:TransCode => 'C00000',
|
14
|
+
:OutTradeNo => flow_id,
|
15
|
+
:OriOutTradeNo => ori_flow_id,
|
16
|
+
}
|
17
|
+
|
18
|
+
response = Http.post(@partner_id, @private_key, @public_key, @server_uri, SERVICE_NAME, params)
|
19
|
+
|
20
|
+
res = {
|
21
|
+
result: 'P', # 默认 pending
|
22
|
+
msg: response[:OriginalErrorMessage] || response[:PlatformErrorMessage],
|
23
|
+
ret_code: response[:OriginalRetCode],
|
24
|
+
flow_id: flow_id,
|
25
|
+
vendor_order_id: response[:FlowNo],
|
26
|
+
log: [params.to_json, response.to_json],
|
27
|
+
}
|
28
|
+
|
29
|
+
# AcceptStatus 是请求是否成功, PlatformRetCode 是畅捷支付是否受理成功了,OriginalRetCode 是否交易成功,只要看 OriginalRetCode 是否成功即可
|
30
|
+
|
31
|
+
# 受理成功但是结果失败
|
32
|
+
if response[:AcceptStatus] == 'S' && Http::OriginalRetCode.query_quick_order_fail?(response[:OriginalRetCode])
|
33
|
+
res[:result] = 'F'
|
34
|
+
end
|
35
|
+
|
36
|
+
if response[:AcceptStatus] == 'S' && Http::OriginalRetCode.success?(response[:OriginalRetCode])
|
37
|
+
res[:result] = 'S'
|
38
|
+
end
|
39
|
+
|
40
|
+
res
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# 单笔同步代付
|
4
|
+
|
5
|
+
module ChanPay
|
6
|
+
module Api
|
7
|
+
module QuickDraw
|
8
|
+
|
9
|
+
SERVICE_NAME = 'cjt_dsf'
|
10
|
+
|
11
|
+
def quick_draw(flow_id,
|
12
|
+
bank_business_name, card_id, true_name,
|
13
|
+
money,
|
14
|
+
business_type='0')
|
15
|
+
|
16
|
+
params = {
|
17
|
+
:TransCode => 'T10000',
|
18
|
+
:OutTradeNo => flow_id,
|
19
|
+
:BusinessType => business_type, # 0=私人,1=公司
|
20
|
+
:BankCommonName => bank_business_name,
|
21
|
+
:AcctNo => card_id,
|
22
|
+
:AcctName => true_name,
|
23
|
+
:TransAmt => money,
|
24
|
+
}
|
25
|
+
|
26
|
+
# 这里是明文参数输出
|
27
|
+
puts "\n[#{SERVICE_NAME}] 请求参数为:\n#{params.inspect}"
|
28
|
+
|
29
|
+
# 敏感字段加密
|
30
|
+
params[:AcctNo] = Encrypt::RSA.encrypt(@public_key, card_id)
|
31
|
+
params[:AcctName] = Encrypt::RSA.encrypt(@public_key, true_name)
|
32
|
+
|
33
|
+
response = Http.post(@partner_id, @private_key, @public_key, @server_uri, SERVICE_NAME, params)
|
34
|
+
|
35
|
+
res = {
|
36
|
+
result: 'P', # 默认 pending
|
37
|
+
msg: response[:OriginalErrorMessage],
|
38
|
+
ret_code: response[:OriginalRetCode],
|
39
|
+
flow_id: flow_id,
|
40
|
+
vendor_order_id: response[:FlowNo],
|
41
|
+
log: [params.to_json, response.to_json],
|
42
|
+
}
|
43
|
+
|
44
|
+
# AcceptStatus 是请求是否成功, PlatformRetCode 是畅捷支付是否受理成功了,OriginalRetCode 是否交易成功,只要看 OriginalRetCode 是否成功即可
|
45
|
+
|
46
|
+
# 受理失败 || 受理成功但是结果失败
|
47
|
+
if response[:AcceptStatus] == 'F' || (response[:AcceptStatus] == 'S' && Http::OriginalRetCode.quick_draw_fail?(response[:OriginalRetCode]))
|
48
|
+
res[:result] = 'F'
|
49
|
+
end
|
50
|
+
|
51
|
+
if response[:AcceptStatus] == 'S' && Http::OriginalRetCode.success?(response[:OriginalRetCode])
|
52
|
+
res[:result] = 'S'
|
53
|
+
end
|
54
|
+
|
55
|
+
res
|
56
|
+
end
|
57
|
+
|
58
|
+
end # module QuickPay
|
59
|
+
end # module Api
|
60
|
+
end # module Chanpay
|
@@ -55,7 +55,7 @@ module ChanPay
|
|
55
55
|
result: 'P', # 默认 pending
|
56
56
|
msg: response[:RetMsg],
|
57
57
|
ret_code: response[:RetCode],
|
58
|
-
flow_id:
|
58
|
+
flow_id: flow_id,
|
59
59
|
vendor_order_id: response[:OrderTrxid],
|
60
60
|
extension: response[:Extension],
|
61
61
|
log: [params.to_json, response.to_json],
|
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
module ChanPay
|
6
6
|
module Api
|
7
|
-
module
|
7
|
+
module WithholdPay
|
8
8
|
|
9
9
|
SERVICE_NAME = 'nmg_api_quickpay_withhold'
|
10
10
|
|
@@ -19,7 +19,7 @@ module ChanPay
|
|
19
19
|
#
|
20
20
|
# @return [Hash] 返回结果集
|
21
21
|
#
|
22
|
-
def
|
22
|
+
def withhold_pay(flow_id, card_id, identity_id, true_name, phone, money)
|
23
23
|
|
24
24
|
params = {
|
25
25
|
:TrxId => flow_id.to_s, # 最长 32 位唯一订单号
|
@@ -52,7 +52,7 @@ module ChanPay
|
|
52
52
|
result: 'P', # 默认 pending
|
53
53
|
msg: response[:RetMsg],
|
54
54
|
ret_code: response[:RetCode],
|
55
|
-
flow_id:
|
55
|
+
flow_id: flow_id,
|
56
56
|
vendor_order_id: response[:OrderTrxid],
|
57
57
|
extension: response[:Extension],
|
58
58
|
log: [params.to_json, response.to_json],
|
data/lib/chan_pay/client.rb
CHANGED
@@ -5,12 +5,17 @@
|
|
5
5
|
module ChanPay
|
6
6
|
class Client
|
7
7
|
|
8
|
-
|
9
|
-
include ChanPay::Api::QueryOrder
|
10
|
-
include ChanPay::Api::QueryBalance
|
8
|
+
# 快捷支付的 api
|
11
9
|
include ChanPay::Api::SmsPayRequest
|
12
10
|
include ChanPay::Api::SmsPayConfirm
|
13
11
|
include ChanPay::Api::SmsPayResend
|
12
|
+
include ChanPay::Api::WithholdPay
|
13
|
+
include ChanPay::Api::QueryOrder
|
14
|
+
# 代付代扣的 api
|
15
|
+
include ChanPay::Api::QuickDraw
|
16
|
+
include ChanPay::Api::QueryQuickOrder
|
17
|
+
# 通用 api
|
18
|
+
include ChanPay::Api::QueryBalance
|
14
19
|
|
15
20
|
def initialize(options_arg)
|
16
21
|
options = Utils.symbolize_keys(options_arg)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
module ChanPay
|
3
3
|
module Http
|
4
|
-
module RetCode
|
5
4
|
|
5
|
+
module RetCode
|
6
6
|
UNKNOWN_ERROR = 'UNKNOWN_ERROR'
|
7
7
|
NET_TIMEOUT = 'NET_TIMEOUT'
|
8
8
|
|
@@ -14,7 +14,40 @@ module ChanPay
|
|
14
14
|
:Status => "F", # 业务失败
|
15
15
|
}
|
16
16
|
end
|
17
|
-
|
18
17
|
end
|
19
|
-
|
20
|
-
|
18
|
+
|
19
|
+
module OriginalRetCode
|
20
|
+
Codes = {
|
21
|
+
"000000" => "成功",
|
22
|
+
"111111" => "失败",
|
23
|
+
"000001" => "未知",
|
24
|
+
"000002" => "已发送",
|
25
|
+
"000004" => "已受理",
|
26
|
+
"000005" => "错误",
|
27
|
+
"000006" => "未受理",
|
28
|
+
"000010" => "超时",
|
29
|
+
"000050" => "重复",
|
30
|
+
"900001" => "无对应批次信息",
|
31
|
+
"900002" => "批次下无明细信息",
|
32
|
+
"900003" => "无对应明细",
|
33
|
+
}
|
34
|
+
|
35
|
+
def self.success?(code)
|
36
|
+
['000000'].include?(code.to_s)
|
37
|
+
end
|
38
|
+
|
39
|
+
# 同步代付错误代码
|
40
|
+
def self.quick_draw_fail?(code)
|
41
|
+
['111111', '000005', '000006', '000010', '000050'].include?(code.to_s)
|
42
|
+
end
|
43
|
+
|
44
|
+
# 订单错误代码
|
45
|
+
# TODO(tony): 还需和用友畅捷支付的人沟通确认
|
46
|
+
def self.query_quick_order_fail?(code)
|
47
|
+
['111111'].include?(code.to_s)
|
48
|
+
end
|
49
|
+
|
50
|
+
end # OriginalRetCode
|
51
|
+
|
52
|
+
end # Http
|
53
|
+
end # ChanPay
|
data/lib/chan_pay/version.rb
CHANGED
data/lib/chan_pay.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
require "uri"
|
2
3
|
require "net/http"
|
3
4
|
require "json"
|
@@ -6,16 +7,24 @@ require "base64"
|
|
6
7
|
|
7
8
|
require "chan_pay/version"
|
8
9
|
require "chan_pay/utils"
|
10
|
+
# 加密验签
|
9
11
|
require "chan_pay/sign/rsa"
|
10
12
|
require "chan_pay/encrypt/rsa"
|
13
|
+
# 通信
|
11
14
|
require "chan_pay/http/ret_code"
|
12
15
|
require "chan_pay/http/communicate"
|
16
|
+
# 快捷支付的 api
|
13
17
|
require "chan_pay/api/sms_pay_request"
|
14
18
|
require "chan_pay/api/sms_pay_confirm"
|
15
19
|
require "chan_pay/api/sms_pay_resend"
|
16
|
-
require "chan_pay/api/
|
20
|
+
require "chan_pay/api/withhold_pay"
|
17
21
|
require "chan_pay/api/query_order"
|
22
|
+
# 代付代扣的 api
|
23
|
+
require "chan_pay/api/quick_draw"
|
24
|
+
require "chan_pay/api/query_quick_order"
|
25
|
+
# 通用 api
|
18
26
|
require "chan_pay/api/query_balance"
|
27
|
+
|
19
28
|
require "chan_pay/client"
|
20
29
|
|
21
30
|
module ChanPay
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chan_pay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tony
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
description: '"畅捷支付"'
|
55
|
+
description: '"畅捷支付SDK"'
|
56
56
|
email:
|
57
57
|
- tony@omniaccount.com
|
58
58
|
executables: []
|
@@ -73,10 +73,12 @@ files:
|
|
73
73
|
- lib/chan_pay.rb
|
74
74
|
- lib/chan_pay/api/query_balance.rb
|
75
75
|
- lib/chan_pay/api/query_order.rb
|
76
|
-
- lib/chan_pay/api/
|
76
|
+
- lib/chan_pay/api/query_quick_order.rb
|
77
|
+
- lib/chan_pay/api/quick_draw.rb
|
77
78
|
- lib/chan_pay/api/sms_pay_confirm.rb
|
78
79
|
- lib/chan_pay/api/sms_pay_request.rb
|
79
80
|
- lib/chan_pay/api/sms_pay_resend.rb
|
81
|
+
- lib/chan_pay/api/withhold_pay.rb
|
80
82
|
- lib/chan_pay/client.rb
|
81
83
|
- lib/chan_pay/encrypt/rsa.rb
|
82
84
|
- lib/chan_pay/http/communicate.rb
|