cmb_pay 0.2.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fe2d640abbeff5dae77c2c7147635c7d0f2ecf2
4
- data.tar.gz: 34ca1429ed56ba1837adc383a9a407021b035b30
3
+ metadata.gz: 19a26d9fd5d53fda1e1ed76c238698f1ed5c89c8
4
+ data.tar.gz: c20644e92e5f1495888d1977e6a2f172f655ffdb
5
5
  SHA512:
6
- metadata.gz: 752436a710d15cf097a43e01924757089c928fae8d4504c66e8f80a0f7df3118a2c7508830a387f82bf5f89225e5cac5f61787c20a34720c2d7bbe9f7e4e5fa7
7
- data.tar.gz: 00b0c256eb70de481ee01005f1ef428fe1ca19cf9eea9638ef12a657169d09ecf0fd2305ce9c481b1489d66934a1376ef54104e79d9c06ea6bb8a1e36073e03c
6
+ metadata.gz: f69018d96dcc1320f6282a13f7146bc3020ab8d4d714fd331fbe3e45205db1552de9330de4745a279524b2ee6385fcd9a85e3d3b827456cae7f332eae9dfef4a
7
+ data.tar.gz: d0ab70616384d7b3266b7a56736753187ecb567d4fc365e7ff57f78c1ca8cd281b6a27bd19cd7d44df0160d62ed7f21c507996083f5d3cfbe5bcefc737c18d85
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -14,15 +14,17 @@ module CmbPay
14
14
  autoload(:BillRecordsMessage, File.expand_path('cmb_pay/message/bill_records_message', __dir__))
15
15
 
16
16
  class << self
17
- attr_accessor :branch_id # 开户分行号
18
- attr_accessor :co_no # 支付商户号/收单商户号
19
- attr_accessor :co_key # 商户校验码/商户密钥,测试环境为空
20
- attr_accessor :mch_no # 协议商户企业编号,或者说是8位虚拟企业网银编号
21
- attr_accessor :operator # 操作员号,一般是9999
22
- attr_accessor :operator_password # 操作员的密码,默认是支付商户号,但建议修改。
23
- attr_accessor :expire_in_minutes # 会话有效时间
24
- attr_accessor :environment # 调用的招商银行支付环境,默认生产,测试填test
25
- attr_accessor :default_payee_id # 默认收款方的用户标识
17
+ attr_accessor :branch_id # 开户分行号
18
+ attr_accessor :co_no # 支付商户号/收单商户号
19
+ attr_accessor :co_key # 商户校验码/商户密钥,测试环境为空
20
+ attr_accessor :mch_no # 协议商户企业编号,或者说是8位虚拟企业网银编号
21
+ attr_accessor :operator # 操作员号,一般是9999
22
+ attr_accessor :operator_password # 操作员的密码,默认是支付商户号,但建议修改。
23
+ attr_accessor :expire_in_minutes # 会话有效时间
24
+ attr_accessor :environment # 调用的招商银行支付环境,默认生产,测试填test
25
+ attr_accessor :default_payee_id # 默认收款方的用户标识
26
+ attr_accessor :default_goods_type # 默认收款方的商品类型
27
+ attr_accessor :one_cent_as_newspaper # 仅支付一分钱,商品类型直接归类到书报杂志,方便在生产上做快速测试和对账,默认启用
26
28
  end
27
29
  @co_key = ''
28
30
  @mch_no = ''
@@ -30,6 +32,7 @@ module CmbPay
30
32
  @operator_password = ''
31
33
  @expire_in_minutes = 30
32
34
  @environment = :production
35
+ @one_cent_as_newspaper = true
33
36
 
34
37
  SUPPORTED_BANK = {
35
38
  '招商银行' => nil,
@@ -60,6 +63,40 @@ module CmbPay
60
63
  '上海银行' => 313
61
64
  }.freeze
62
65
 
66
+ GOODS_TYPE = {
67
+ '网上支付' => 54_011_600,
68
+ '充值缴费' => 54_011_610,
69
+ '彩票' => 54_011_611,
70
+ '话费' => 54_011_612,
71
+ '虚拟商品' => 54_011_620,
72
+ '游戏点卡' => 54_011_621,
73
+ '旅游出行' => 54_010_6,
74
+ '酒店' => 54_010_650,
75
+ '机票' => 54_010_651,
76
+ '服装' => 54_010_5,
77
+ '文化教育' => 54_011_630,
78
+ '书报杂志' => 54_011_631,
79
+ '考试培训' => 54_011_632,
80
+ '数码产品' => 54_011_640,
81
+ '护肤化妆' => 54_010_7,
82
+ '母婴用品' => 54_011_650,
83
+ '生活日用' => 54_010_111,
84
+ '食品' => 54_010_112,
85
+ '汽车费用' => 54_010_2,
86
+ '信用卡还款' => 54_010_306, # 此商品类型只允许使用借记卡支付
87
+ '保险' => 54_011_1,
88
+ '家居物品' => 54_011_2,
89
+ '医疗保健' => 54_012_2,
90
+ '礼品' => 54_012_3,
91
+ '办公设备' => 54_011_660,
92
+ '家用电器' => 54_011_670,
93
+ '体育用品' => 54_011_680,
94
+ '娱乐休闲' => 54_010_8,
95
+ '网络服务' => 54_011_690,
96
+ '收藏爱好' => 54_011_691,
97
+ '投资理财' => 54_011_692
98
+ }.freeze
99
+
63
100
  def self.uri_of_pre_pay_euserp(payer_id:, bill_no:, amount_in_cents:, merchant_url:, merchant_para: nil,
64
101
  protocol:, merchant_ret_url:, merchant_ret_para: nil,
65
102
  options: {})
@@ -186,6 +223,11 @@ module CmbPay
186
223
  cmb_merchant_para = Service.encode_merchant_para(merchant_para)
187
224
  trade_date = options.delete(:trade_date) || Time.now.strftime('%Y%m%d')
188
225
  payee_id = options.delete(:payee_id) || CmbPay.default_payee_id
226
+ goods_type = if amount_in_cents == 1 && CmbPay.one_cent_as_newspaper == true
227
+ '书报杂志'
228
+ else
229
+ options.delete(:goods_type) || CmbPay.default_goods_type
230
+ end
189
231
  random = options.delete(:random)
190
232
  if protocol.is_a?(Hash) && !payer_id.nil?
191
233
  cmb_reserved_xml = "<Protocol><PNo>#{protocol['PNo']}</PNo><TS>#{protocol['TS'] || Time.now.strftime('%Y%m%d%H%M%S')}</TS><MchNo>#{CmbPay.mch_no}</MchNo><Seq>#{protocol['Seq']}</Seq><MUID>#{payer_id}</MUID><URL>#{merchant_url}</URL><Para>#{cmb_merchant_para}</Para></Protocol>"
@@ -197,7 +239,7 @@ module CmbPay
197
239
  branch_id: branch_id, co_no: co_no,
198
240
  bill_no: cmb_bill_no, amount: pay_amount,
199
241
  merchant_para: cmb_merchant_para, merchant_url: merchant_url,
200
- payer_id: payer_id, payee_id: payee_id,
242
+ payer_id: payer_id, payee_id: payee_id, goods_type: encode_goods_type(goods_type),
201
243
  reserved: cmb_reserved_xml)
202
244
  uri_params = {
203
245
  'BranchID' => branch_id,
@@ -220,4 +262,9 @@ module CmbPay
220
262
  return nil if SUPPORTED_BANK[card_bank].nil?
221
263
  "<CardBank>#{format('%04d', SUPPORTED_BANK[card_bank])}</CardBank>"
222
264
  end
265
+
266
+ def self.encode_goods_type(goods_type)
267
+ return goods_type if /^\d+$/ =~ goods_type.to_s
268
+ GOODS_TYPE[goods_type]
269
+ end
223
270
  end
@@ -1,3 +1,3 @@
1
1
  module CmbPay
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmb_pay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Guo
@@ -30,7 +30,7 @@ cert_chain:
30
30
  R5k6Ma92sW8jupX4cqbSu9rntdVQkNRpoHIrfU0MZT0cKsg/D1zMteylxrO3KMsz
31
31
  SPQRv+nrI1J0zevFqb8010heoR8SDyUA0Mm3+Q==
32
32
  -----END CERTIFICATE-----
33
- date: 2016-08-18 00:00:00.000000000 Z
33
+ date: 2016-09-06 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: http
metadata.gz.sig CHANGED
@@ -1,4 +1,2 @@
1
- ��Άu�L&����W���̙ֈ9�m�g��LԲ�=R��Oj�AKMNגY�/"ZQ䐛>��VB��Z
2
- �DI�^v{����b��n�ּ2��Cȡʿ�SD["Fd7�:� ��ߚـ~����fhͧ�"�]��H4
3
- =x�YdP},�i�e��sПY\3�J%�R�ᑩ-�NV�c�s��́���X �W|֮�+��!??��j�r̙� ���-���:�+x�Yżt��=C��
4
- CK�F����
1
+ ���R*��*P��9� ~��G���� ƒ�Su2-�%�IGq����&3E��IpX����6������H���M)���BA ��
2
+ ���d���+�/s2��ZM|]z���F4�\���v�ߧ��6GhC��&h��A����U��;/Υ ~mM<D)%�$;~�i��kdi�!�����e�f&�Dq�]�ĸ���A��Os1t엾��r�A��V���š�>$xq肤+̤�nh���&3UC<�