Class: Tencentpay::Response

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Response

Returns a new instance of Response.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tencentpay/response.rb', line 5

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 = Tenpay::Config.bargainor_id
  @key = Tenpay::Config.key
end

Instance Attribute Details

#attachObject (readonly)

Returns the value of attribute attach.



3
4
5
# File 'lib/tencentpay/response.rb', line 3

def attach
  @attach
end

#sp_billnoObject (readonly)

Returns the value of attribute sp_billno.



3
4
5
# File 'lib/tencentpay/response.rb', line 3

def sp_billno
  @sp_billno
end

#total_feeObject (readonly)

Returns the value of attribute total_fee.



3
4
5
# File 'lib/tencentpay/response.rb', line 3

def total_fee
  @total_fee
end

Class Method Details

.show_html(show_url) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/tencentpay/response.rb', line 35

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

Instance Method Details

#sign_paramsObject



29
30
31
32
33
# File 'lib/tencentpay/response.rb', line 29

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

#successful?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/tencentpay/response.rb', line 21

def successful?
  @pay_result == '0' && valid_sign?
end

#valid_sign?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/tencentpay/response.rb', line 25

def valid_sign?
  @sign == Digest::MD5.hexdigest(sign_params).lowcase
end