Class: Chinapay::Response::Tencent

Inherits:
Object
  • Object
show all
Defined in:
lib/chinapay/response/tencent.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Tencent



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/chinapay/response/tencent.rb', line 7

def initialize(params)
  @cmdno = params["cmdno"] || ''
  @pay_result = params["pay_result"] || ''
  @date = params["date"] || ''
  @transaction_id = params["transaction_id"] || ''
  @sp_billno = (params["sp_billno"] || '').to_i
  @total_fee = params["total_fee"] || ''
  @fee_type = params["fee_type"] || ''
  @attach = params["attach"] || ''

  @sign = params["sign"] || ''

  @bargainor_id = Chinapay.config["tencent"]["parter"]
  @key = Chinapay.config["tencent"]["key"]

  @pay_type = "财付通"
end

Instance Attribute Details

#attachObject (readonly)

Returns the value of attribute attach.



5
6
7
# File 'lib/chinapay/response/tencent.rb', line 5

def attach
  @attach
end

#pay_typeObject (readonly)

Returns the value of attribute pay_type.



5
6
7
# File 'lib/chinapay/response/tencent.rb', line 5

def pay_type
  @pay_type
end

#total_feeObject (readonly)

Returns the value of attribute total_fee.



5
6
7
# File 'lib/chinapay/response/tencent.rb', line 5

def total_fee
  @total_fee
end

#trade_noObject (readonly)

Returns the value of attribute trade_no.



5
6
7
# File 'lib/chinapay/response/tencent.rb', line 5

def trade_no
  @trade_no
end

Instance Method Details

#sign_paramsObject



37
38
39
40
41
# File 'lib/chinapay/response/tencent.rb', line 37

def sign_params
  "cmdno=#{@cmdno}&pay_result=#{@pay_result}&date=#{@date}&transaction_id=#{@transaction_id}" +
    "&sp_billno=#{@sp_billno}&total_fee=#{@total_fee}&fee_type=#{@fee_type}" +
    "&attach=#{CGI.escape(@attach)}&key=#{@key}"
end

#success_response(redirect_url = "") ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/chinapay/response/tencent.rb', line 43

def success_response(redirect_url = "")
  strHtml = <<-EOF
  <html>
  <head>
  <meta name="TENCENT_ONLINE_PAYMENT" content="China TENCENT">
  <script language="javascript">
  window.location.href='#{redirect_url}';
  </script>
  </head>
  <body></body>
  </html>
  EOF
end

#successful?Boolean



33
34
35
# File 'lib/chinapay/response/tencent.rb', line 33

def successful?
  @pay_result == '0' && @sign.downcase == Digest::MD5.hexdigest(sign_params).downcase
end