Class: Tenpay::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Response

Returns a new instance of Response.



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

def initialize(params)
  @cmdno = params[:cmdno] || ''
  @date = params[:date] || ''
  @fee_type = params[:fee_type] || ''
  @pay_info = params[:pay_info] || ''
  @pay_result = params[:pay_result] || ''
  @pay_time = Time.at((params[:pay_time] || '0').to_i)
  @sign = params[:sign] || ''
  @order_id = (params[:sp_billno] || '').to_i
  @transaction_id = params[:transaction_id] || ''
  @total_fee = params[:total_fee] || ''
  @attach = params[:attach] || ''
  
  @spid = Tenpay::Config.spid
  @key = Tenpay::Config.key
end

Instance Attribute Details

#attachObject (readonly)

Returns the value of attribute attach.



7
8
9
# File 'lib/tenpay/response.rb', line 7

def attach
  @attach
end

#order_idObject (readonly)

Returns the value of attribute order_id.



7
8
9
# File 'lib/tenpay/response.rb', line 7

def order_id
  @order_id
end

#pay_timeObject (readonly)

Returns the value of attribute pay_time.



7
8
9
# File 'lib/tenpay/response.rb', line 7

def pay_time
  @pay_time
end

#total_feeObject (readonly)

Returns the value of attribute total_fee.



7
8
9
# File 'lib/tenpay/response.rb', line 7

def total_fee
  @total_fee
end

Instance Method Details

#successful?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/tenpay/response.rb', line 26

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

#valid_sign?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/tenpay/response.rb', line 30

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