Class: CmbPay::PayMessage
- Inherits:
-
Object
- Object
- CmbPay::PayMessage
- Defined in:
- lib/cmb_pay/message/pay_message.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
实际支付金额(由支付命令送来).
-
#bank_date ⇒ Object
readonly
银行主机交易日期.
-
#bank_serial_no ⇒ Object
readonly
银行流水号.
-
#bill_no ⇒ Object
readonly
订单号(由支付命令送来);.
-
#branch_id ⇒ Object
readonly
优惠金额,格式:xxxx.xx,当有优惠的时候, 实际用户支付的是amount - discount_amt的金额到商户账号。.
-
#co_no ⇒ Object
readonly
商户号,6位长数字,由银行在商户开户时确定.
-
#date ⇒ Object
readonly
订单下单日期(由支付命令送来).
-
#discount_amt ⇒ Object
readonly
Returns the value of attribute discount_amt.
-
#discount_flag ⇒ Object
readonly
当前订单是否有优惠,Y:有优惠 N:无优惠。.
-
#merchant_para ⇒ Object
readonly
商户自定义传递参数(由支付命令送来).
-
#msg ⇒ Object
readonly
银行通知用户支付结构消息.
-
#query_string ⇒ Object
readonly
原始的query_string.
-
#signature ⇒ Object
readonly
通知命令签名.
-
#succeed ⇒ Object
readonly
消息成功失败,成功为‘Y’,失败为‘N’.
Instance Method Summary collapse
- #amount_cents ⇒ Object
- #discount? ⇒ Boolean
- #discount_amount_cents ⇒ Object
-
#initialize(query_string) ⇒ PayMessage
constructor
A new instance of PayMessage.
- #merchant_params ⇒ Object
- #order_date ⇒ Object
- #payment_date ⇒ Object
- #succeed? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(query_string) ⇒ PayMessage
Returns a new instance of PayMessage.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cmb_pay/message/pay_message.rb', line 22 def initialize(query_string) query_string = URI.encode_www_form(query_string) if query_string.is_a? Hash @query_string = query_string params = URI.decode_www_form(query_string).to_h @succeed = params['Succeed'] @co_no = params['CoNo'] @bill_no = params['BillNo'] @amount = params['Amount'] @date = params['Date'] @merchant_para = params['MerchantPara'] @msg = params['Msg'] @discount_flag = params['DiscountFlag'] @discount_amt = params['DiscountAmt'] # 银行通知用户的支付结果消息。信息的前38个字符格式为:4位分行号+6位商户号+8位银行接受交易的日期+20位银行流水号; # 可以利用交易日期+银行流水号+订单号对该订单进行结帐处理 msg = params['Msg'][0..37] @branch_id = msg[0..3] @co_no ||= msg[4..9] @bank_date = msg[10..17] @bank_serial_no = msg[18..37] @signature = params['Signature'] end |
Instance Attribute Details
#amount ⇒ Object (readonly)
实际支付金额(由支付命令送来)
6 7 8 |
# File 'lib/cmb_pay/message/pay_message.rb', line 6 def amount @amount end |
#bank_date ⇒ Object (readonly)
银行主机交易日期
15 16 17 |
# File 'lib/cmb_pay/message/pay_message.rb', line 15 def bank_date @bank_date end |
#bank_serial_no ⇒ Object (readonly)
银行流水号
16 17 18 |
# File 'lib/cmb_pay/message/pay_message.rb', line 16 def bank_serial_no @bank_serial_no end |
#bill_no ⇒ Object (readonly)
订单号(由支付命令送来);
5 6 7 |
# File 'lib/cmb_pay/message/pay_message.rb', line 5 def bill_no @bill_no end |
#branch_id ⇒ Object (readonly)
优惠金额,格式:xxxx.xx,当有优惠的时候,实际用户支付的是amount - discount_amt的金额到商户账号。
14 15 16 |
# File 'lib/cmb_pay/message/pay_message.rb', line 14 def branch_id @branch_id end |
#co_no ⇒ Object (readonly)
商户号,6位长数字,由银行在商户开户时确定
4 5 6 |
# File 'lib/cmb_pay/message/pay_message.rb', line 4 def co_no @co_no end |
#date ⇒ Object (readonly)
订单下单日期(由支付命令送来)
7 8 9 |
# File 'lib/cmb_pay/message/pay_message.rb', line 7 def date @date end |
#discount_amt ⇒ Object (readonly)
Returns the value of attribute discount_amt.
11 12 13 |
# File 'lib/cmb_pay/message/pay_message.rb', line 11 def discount_amt @discount_amt end |
#discount_flag ⇒ Object (readonly)
当前订单是否有优惠,Y:有优惠 N:无优惠。
10 11 12 |
# File 'lib/cmb_pay/message/pay_message.rb', line 10 def discount_flag @discount_flag end |
#merchant_para ⇒ Object (readonly)
商户自定义传递参数(由支付命令送来)
8 9 10 |
# File 'lib/cmb_pay/message/pay_message.rb', line 8 def merchant_para @merchant_para end |
#msg ⇒ Object (readonly)
银行通知用户支付结构消息
9 10 11 |
# File 'lib/cmb_pay/message/pay_message.rb', line 9 def msg @msg end |
#query_string ⇒ Object (readonly)
原始的query_string
20 21 22 |
# File 'lib/cmb_pay/message/pay_message.rb', line 20 def query_string @query_string end |
#signature ⇒ Object (readonly)
通知命令签名
18 19 20 |
# File 'lib/cmb_pay/message/pay_message.rb', line 18 def signature @signature end |
#succeed ⇒ Object (readonly)
消息成功失败,成功为‘Y’,失败为‘N’
3 4 5 |
# File 'lib/cmb_pay/message/pay_message.rb', line 3 def succeed @succeed end |
Instance Method Details
#amount_cents ⇒ Object
61 62 63 |
# File 'lib/cmb_pay/message/pay_message.rb', line 61 def amount_cents (amount.to_f * 100).to_i end |
#discount? ⇒ Boolean
57 58 59 |
# File 'lib/cmb_pay/message/pay_message.rb', line 57 def discount? discount_flag == 'Y' end |
#discount_amount_cents ⇒ Object
65 66 67 |
# File 'lib/cmb_pay/message/pay_message.rb', line 65 def discount_amount_cents (discount_amt.to_f * 100).to_i end |
#merchant_params ⇒ Object
77 78 79 |
# File 'lib/cmb_pay/message/pay_message.rb', line 77 def merchant_params URI.decode_www_form(merchant_para.tr('|', '&')).to_h end |
#order_date ⇒ Object
69 70 71 |
# File 'lib/cmb_pay/message/pay_message.rb', line 69 def order_date Date.strptime(date, '%Y%m%d') end |
#payment_date ⇒ Object
73 74 75 |
# File 'lib/cmb_pay/message/pay_message.rb', line 73 def payment_date Date.strptime(bank_date, '%Y%m%d') end |
#succeed? ⇒ Boolean
53 54 55 |
# File 'lib/cmb_pay/message/pay_message.rb', line 53 def succeed? succeed == 'Y' end |
#valid? ⇒ Boolean
49 50 51 |
# File 'lib/cmb_pay/message/pay_message.rb', line 49 def valid? Sign::Sha1WithRsa.verify(query_string) end |