chan_pay 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d7c70b34dbd0487cd8238f9399de59df96fb316
4
- data.tar.gz: f81dd32e452c871df1d20f581871f547434cf3a3
3
+ metadata.gz: b3d9ed83edfada8388e102fcd1345977c5cf9108
4
+ data.tar.gz: d9b0a665d39ed30a1600844cfd1ec8ff87a28b9c
5
5
  SHA512:
6
- metadata.gz: 2e49ecda7d3418f8539d51b30a0f743bb405b856d5f7a0b291c8cc500ebf244a7f3537f412fb9f8f00a130eb1efecc40c581c2ee15ec05cb80ba13b2cba66fad
7
- data.tar.gz: d245c4b2650720f459cc110efbba8ce9c1490d645bfccee9656a57c8133d0227cd50fb29555f56b2f2d2aabb51102fcc85d557cb459cc752fea9d6bef17caed8
6
+ metadata.gz: 122a3f26eefd382947f1b2dacd3cc6c18bbefdbb75f1fe71c5bbffc3ab238e42d73eeded8c7c5c0181acf48725a48dd6d5698595a3745b3060c945e65b9778ab
7
+ data.tar.gz: ed1397100c2a5f4d73aa66db390305b7b475d471615b9fee0bea1370d8a84edc9653763b1b7e9aaeec717da4a8017afdc5f8a4f7a651aefda32143d80acb70ec
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+
3
+ # 4.2.13 商户余额查询
4
+
5
+ module ChanPay
6
+ module Api
7
+ module QueryBalance
8
+
9
+ SERVICE_NAME = 'cjt_dsf'
10
+
11
+ # 商户余额查询
12
+ #
13
+ # @param flow_id [String] 订单号(需要保证唯一)
14
+ #
15
+ # @return [Hash] 返回结果集
16
+ #
17
+ def query_balance(flow_id)
18
+ params = {
19
+ :TransCode => 'C00005',
20
+ :OutTradeNo => flow_id,
21
+ }
22
+
23
+ response = Http.post(@partner_id, @private_key, @public_key, @server_uri, SERVICE_NAME, params)
24
+
25
+ {
26
+ result: response[:AcceptStatus],
27
+ balance: response[:RecBalance].to_f,
28
+ }
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -8,14 +8,48 @@ module ChanPay
8
8
 
9
9
  SERVICE_NAME = 'nmg_api_query_trade'
10
10
 
11
- def query_order(flow_id, vendor_order_id)
11
+ # 确认收货接口
12
+ #
13
+ # @param flow_id [String] 订单号(需要保证唯一)
14
+ # @param ori_flow_id [String] 原业务订单号
15
+ #
16
+ # @return [Hash] 返回结果集
17
+ #
18
+ def query_order(flow_id, ori_flow_id)
12
19
  params = {
13
20
  :TrxId => flow_id,
14
- :OrderTrxId => vendor_order_id,
21
+ :OrderTrxId => ori_flow_id,
15
22
  :TradeType => 'pay_order',
16
23
  }
17
24
 
18
25
  response = Http.post(@partner_id, @private_key, @public_key, @server_uri, SERVICE_NAME, params)
26
+
27
+ res = {
28
+ result: 'P', # 默认 pending
29
+ msg: response[:RetMsg],
30
+ ret_code: response[:RetCode],
31
+ flow_id: response[:TrxId],
32
+ vendor_order_id: response[:OrderTrxid],
33
+ extension: response[:Extension],
34
+ log: [params.to_json, response.to_json],
35
+ }
36
+
37
+ # 因为是查询,所以如果受理失败,状态还是按 P
38
+ if response[:AcceptStatus] == 'F'
39
+ res[:result] = 'P'
40
+ end
41
+
42
+ # 受理成功但是结果失败
43
+ if response[:AcceptStatus] == 'S' && response[:Status] == 'F'
44
+ res[:result] = 'F'
45
+ end
46
+
47
+ # 受理成功并且结果成功,才是成功
48
+ if response[:AcceptStatus] == 'S' && response[:Status] == 'S'
49
+ res[:result] = 'S'
50
+ end
51
+
52
+ res
19
53
  end
20
54
 
21
55
  end
@@ -46,24 +46,6 @@ module ChanPay
46
46
  params[:CstmrNm] = Encrypt::RSA.encrypt(@public_key, true_name)
47
47
  params[:MobNo] = Encrypt::RSA.encrypt(@public_key, phone)
48
48
 
49
- # api 返回
50
- # TrxId, 商户网站唯一订单号, String(32)
51
- # OrderTrxId, 畅捷流水号, String(32)
52
- # Status, 订单状态, String(2), S:成功,F:失败;P:处理中
53
- # RetCode, 业务返回码, String(64)
54
- # RetMsg, 返回描述, String (200)
55
- # Extension, 扩展字段, String(4000), json格式
56
- # 例子:
57
- # {:AcceptStatus=>"S",
58
- # :InputCharset=>"UTF-8",
59
- # :OrderTrxid=>"101150831263182558262",
60
- # :PartnerId=>"200001280051",
61
- # :RetCode=>"S0001",
62
- # :RetMsg=>"受理成功",
63
- # :Status=>"S",
64
- # :TradeDate=>"20171018",
65
- # :TradeTime=>"154354",
66
- # :TrxId=>"1508312631562"}
67
49
  response = Http.post(@partner_id, @private_key, @public_key, @server_uri, SERVICE_NAME, params)
68
50
 
69
51
  res = {
@@ -0,0 +1,58 @@
1
+ # coding: utf-8
2
+
3
+ # 4.4.2.6 支付确认接口(API)
4
+
5
+ module ChanPay
6
+ module Api
7
+ module SmsPayConfirm
8
+
9
+ SERVICE_NAME = 'nmg_api_quick_payment_smsconfirm'
10
+
11
+ # 支付确认接口
12
+ #
13
+ # @param flow_id [String] 订单号(需要保证唯一)
14
+ # @param ori_flow_id [String] 原发短信验证码订单号
15
+ # @param sms [String] 验证码
16
+ #
17
+ # @return [Hash] 返回结果集
18
+ #
19
+ def sms_pay_confirm(flow_id, ori_flow_id, sms)
20
+ params = {
21
+ :TrxId => flow_id.to_s, # 最长 32 位唯一订单号
22
+ :OriPayTrxId => ori_flow_id,
23
+ :SmsCode => sms,
24
+ }
25
+
26
+ # 这里是明文参数输出
27
+ puts "\n[#{SERVICE_NAME}] 请求参数为:\n#{params.inspect}"
28
+
29
+ response = Http.post(@partner_id, @private_key, @public_key, @server_uri, SERVICE_NAME, params)
30
+
31
+ res = {
32
+ result: 'P', # 默认 pending
33
+ msg: response[:RetMsg],
34
+ ret_code: response[:RetCode],
35
+ # TODO(tony): 本来这个字段应该是 flow_id,但是目前返回不是,畅捷正在和技术确认中
36
+ # flow_id: response[:TrxId],
37
+ flow_id: flow_id,
38
+ vendor_order_id: response[:OrderTrxid],
39
+ extension: response[:Extension],
40
+ log: [params.to_json, response.to_json],
41
+ }
42
+
43
+ # 受理失败 || 受理成功但是结果失败
44
+ if response[:AcceptStatus] == 'F' || (response[:AcceptStatus] == 'S' && response[:Status] == 'F')
45
+ res[:result] = 'F'
46
+ end
47
+
48
+ # 受理成功并且结果成功,才是成功
49
+ if response[:AcceptStatus] == 'S' && response[:Status] == 'S'
50
+ res[:result] = 'S'
51
+ end
52
+
53
+ res
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,79 @@
1
+ # coding: utf-8
2
+
3
+ # 4.4.2.7 直接支付请求接口(API)
4
+
5
+ module ChanPay
6
+ module Api
7
+ module SmsPayRequest
8
+
9
+ SERVICE_NAME = 'nmg_zft_api_quick_payment'
10
+
11
+ # 快捷直接支付请求接口
12
+ #
13
+ # @param flow_id [String] 订单号(需要保证唯一)
14
+ # @param user_id [String] 唯一用户识别号,比如数据库 ID(但要考虑分布式)
15
+ # @param card_id [String] 支付银行卡号
16
+ # @param identity_id [String] 身份证号
17
+ # @param true_name [String] 真实姓名
18
+ # @param phone [String] 银行卡预留手机号
19
+ # @param money [String] 支付金额(单位:元,精确到 2 位小数点)
20
+ #
21
+ # @return [Hash] 返回结果集
22
+ #
23
+ def sms_pay_request(flow_id, user_id,
24
+ card_id, identity_id, true_name, phone, money)
25
+ params = {
26
+ :TrxId => flow_id.to_s, # 最长 32 位唯一订单号
27
+ :OrdrName => '快捷充值', # 商品名称
28
+ :MerUserId => user_id, # 商户网站用户唯一标识,不建议手机号
29
+ :SellerId => @seller_id, # 畅捷提供的商户编号
30
+ :ExpiredTime => '90m', # 订单有效期
31
+ :BkAcctTp => '01', # 卡类型
32
+ :BkAcctNo => card_id, # 卡号,需要 rsa 加密
33
+ :IDTp => '01', # 证件类型,01 身份证
34
+ :IDNo => identity_id, # 证件号,rsa 加密
35
+ :CstmrNm => true_name, # 持卡人姓名,rsa 加密
36
+ :MobNo => phone, # 银行预留手机号,rsa 加密
37
+ :TradeType => '11', # 交易类型(即时 11 担保 12)
38
+ :TrxAmt => money.to_s, # 交易金额
39
+ # 'NotifyUrl' => '', # 异步通知地址,可空
40
+ # 'Extension' => '', # 扩展字段,可空
41
+ }
42
+
43
+ # 这里是明文参数输出
44
+ puts "\n[#{SERVICE_NAME}] 请求参数为:\n#{params.inspect}"
45
+
46
+ # 敏感字段加密
47
+ params[:BkAcctNo] = Encrypt::RSA.encrypt(@public_key, card_id)
48
+ params[:IDNo] = Encrypt::RSA.encrypt(@public_key, identity_id)
49
+ params[:CstmrNm] = Encrypt::RSA.encrypt(@public_key, true_name)
50
+ params[:MobNo] = Encrypt::RSA.encrypt(@public_key, phone)
51
+
52
+ response = Http.post(@partner_id, @private_key, @public_key, @server_uri, SERVICE_NAME, params)
53
+
54
+ res = {
55
+ result: 'P', # 默认 pending
56
+ msg: response[:RetMsg],
57
+ ret_code: response[:RetCode],
58
+ flow_id: response[:TrxId],
59
+ vendor_order_id: response[:OrderTrxid],
60
+ extension: response[:Extension],
61
+ log: [params.to_json, response.to_json],
62
+ }
63
+
64
+ # 受理失败 || 受理成功但是结果失败
65
+ if response[:AcceptStatus] == 'F' || (response[:AcceptStatus] == 'S' && response[:Status] == 'F')
66
+ res[:result] = 'F'
67
+ end
68
+
69
+ # 受理成功并且结果成功,才是成功
70
+ if response[:AcceptStatus] == 'S' && response[:Status] == 'S'
71
+ res[:result] = 'S'
72
+ end
73
+
74
+ res
75
+ end
76
+
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,57 @@
1
+ # coding: utf-8
2
+
3
+ # 4.4.2.11 短信验证码重发接口
4
+
5
+ module ChanPay
6
+ module Api
7
+ module SmsPayResend
8
+
9
+ SERVICE_NAME = 'nmg_api_quick_payment_resend'
10
+
11
+ # 短信验证码重发接口
12
+ #
13
+ # @param flow_id [String] 订单号(需要保证唯一)
14
+ # @param ori_flow_id [String] 原发短信验证码订单号
15
+ #
16
+ # @return [Hash] 返回结果集
17
+ #
18
+ def sms_pay_resend(flow_id, ori_flow_id)
19
+ params = {
20
+ :TrxId => flow_id.to_s, # 最长 32 位唯一订单号
21
+ :OriTrxId => ori_flow_id,
22
+ :TradeType => 'pay_order',
23
+ }
24
+
25
+ # 这里是明文参数输出
26
+ puts "\n[#{SERVICE_NAME}] 请求参数为:\n#{params.inspect}"
27
+
28
+ response = Http.post(@partner_id, @private_key, @public_key, @server_uri, SERVICE_NAME, params)
29
+
30
+ res = {
31
+ result: 'P', # 默认 pending
32
+ msg: response[:RetMsg],
33
+ ret_code: response[:RetCode],
34
+ # TODO(tony): 本来这个字段应该是 flow_id,但是目前返回不是,畅捷正在和技术确认中
35
+ # flow_id: response[:TrxId],
36
+ flow_id: flow_id,
37
+ vendor_order_id: response[:OrderTrxid],
38
+ extension: response[:Extension],
39
+ log: [params.to_json, response.to_json],
40
+ }
41
+
42
+ # 受理失败 || 受理成功但是结果失败
43
+ if response[:AcceptStatus] == 'F' || (response[:AcceptStatus] == 'S' && response[:Status] == 'F')
44
+ res[:result] = 'F'
45
+ end
46
+
47
+ # 受理成功并且结果成功,才是成功
48
+ if response[:AcceptStatus] == 'S' && response[:Status] == 'S'
49
+ res[:result] = 'S'
50
+ end
51
+
52
+ res
53
+ end
54
+
55
+ end
56
+ end
57
+ end
@@ -7,6 +7,10 @@ module ChanPay
7
7
 
8
8
  include ChanPay::Api::QuickPay
9
9
  include ChanPay::Api::QueryOrder
10
+ include ChanPay::Api::QueryBalance
11
+ include ChanPay::Api::SmsPayRequest
12
+ include ChanPay::Api::SmsPayConfirm
13
+ include ChanPay::Api::SmsPayResend
10
14
 
11
15
  def initialize(options_arg)
12
16
  options = Utils.symbolize_keys(options_arg)
@@ -12,7 +12,9 @@ module ChanPay
12
12
  def self.verify?(key, hash, sign)
13
13
  content = link_hash(hash)
14
14
  rsa = OpenSSL::PKey::RSA.new(key)
15
- rsa.verify('sha1', Base64.strict_decode64(sign), content)
15
+ result = rsa.verify('sha1', Base64.strict_decode64(sign), content)
16
+ puts "\nrsa verify:#{result}; 回过来的 sign 为:#{sign}\n" unless result
17
+ result
16
18
  end
17
19
 
18
20
  private
@@ -1,3 +1,3 @@
1
1
  module ChanPay
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/chan_pay.rb CHANGED
@@ -10,8 +10,12 @@ require "chan_pay/sign/rsa"
10
10
  require "chan_pay/encrypt/rsa"
11
11
  require "chan_pay/http/ret_code"
12
12
  require "chan_pay/http/communicate"
13
+ require "chan_pay/api/sms_pay_request"
14
+ require "chan_pay/api/sms_pay_confirm"
15
+ require "chan_pay/api/sms_pay_resend"
13
16
  require "chan_pay/api/quick_pay"
14
17
  require "chan_pay/api/query_order"
18
+ require "chan_pay/api/query_balance"
15
19
  require "chan_pay/client"
16
20
 
17
21
  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.1.0
4
+ version: 0.2.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-18 00:00:00.000000000 Z
11
+ date: 2017-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,8 +71,12 @@ files:
71
71
  - bin/setup
72
72
  - chan_pay.gemspec
73
73
  - lib/chan_pay.rb
74
+ - lib/chan_pay/api/query_balance.rb
74
75
  - lib/chan_pay/api/query_order.rb
75
76
  - lib/chan_pay/api/quick_pay.rb
77
+ - lib/chan_pay/api/sms_pay_confirm.rb
78
+ - lib/chan_pay/api/sms_pay_request.rb
79
+ - lib/chan_pay/api/sms_pay_resend.rb
76
80
  - lib/chan_pay/client.rb
77
81
  - lib/chan_pay/encrypt/rsa.rb
78
82
  - lib/chan_pay/http/communicate.rb