Class: Kuaiqian::Response

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

Constant Summary collapse

BANK_NAMES =
{'ICBC' => '中国工商银行', 'CMB' => '招商银行', 'CCB' => '中国建设银行',
'ABC' => '中国农业银行', 'BOC_SH' => '中国银行(上海)', 'BOC_GZ' => '中国银行(广州)',
'SPDB' => '上海浦东发展银行', 'BCOM' => '交通银行', 'CMBC' => '中国民生银行',
'SDB' => '深圳发展银行', 'GDB' => '广东发展银行', 'CITIC' => '中信银行',
'HXB' => '华夏银行', 'CIB' => '兴业银行', 'GZRCC' => '广州市农村信用合作社',
'GZCB' => '广州市商业银行', 'SHRCC' => '上海农村商业银行', 'CPSRB' => '中国邮政储蓄',
'CEB' => '中国光大银行', 'BOB' => '北京银行', 'CBHB' => '渤海银行', 
'BJRCB' => '北京农村商业银行', 'CNPY' => '中国银联'}
SIGN_PARAMS =
%w(merchantAcctId version language signType  payType bankId orderId orderTime orderAmount dealId bankDealId dealTime payAmount fee ext1 ext2  payResult errCode key)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Response

Returns a new instance of Response.



19
20
21
# File 'lib/kuaiqian/response.rb', line 19

def initialize(params)
  @params = params
end

Instance Attribute Details

#attachObject (readonly)

Returns the value of attribute attach.



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

def attach
  @attach
end

#order_idObject (readonly)

Returns the value of attribute order_id.



7
8
9
# File 'lib/kuaiqian/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/kuaiqian/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/kuaiqian/response.rb', line 7

def total_fee
  @total_fee
end

Instance Method Details

#bank_deal_idObject



47
# File 'lib/kuaiqian/response.rb', line 47

def bank_deal_id;     @params[:bankDealId]; end

#bank_idObject



58
# File 'lib/kuaiqian/response.rb', line 58

def bank_id;          @params[:bankId]; end

#bank_nameObject



59
# File 'lib/kuaiqian/response.rb', line 59

def bank_name;        BANK_NAMES[bank_id]; end

#deal_idObject



46
# File 'lib/kuaiqian/response.rb', line 46

def deal_id;          @params[:dealId]; end

#deal_timeObject



48
# File 'lib/kuaiqian/response.rb', line 48

def deal_time;        @params[:dealTime]; end

#err_codeObject



55
# File 'lib/kuaiqian/response.rb', line 55

def err_code;         @params[:errCode]; end

#ext1Object



52
# File 'lib/kuaiqian/response.rb', line 52

def ext1;             @params[:ext1]; end

#ext2Object



53
# File 'lib/kuaiqian/response.rb', line 53

def ext2;             @params[:ext2]; end

#feeObject



50
# File 'lib/kuaiqian/response.rb', line 50

def fee;              @params[:fee]; end

#keyObject



42
# File 'lib/kuaiqian/response.rb', line 42

def key;              Kuaiqian::Config.key; end

#languageObject



39
# File 'lib/kuaiqian/response.rb', line 39

def language;         @params[:language]; end

#merchant_acct_idObject



41
# File 'lib/kuaiqian/response.rb', line 41

def merchant_acct_id; @params[:merchantAcctId]; end

#order_amountObject



44
# File 'lib/kuaiqian/response.rb', line 44

def order_amount;     @params[:orderAmount]; end

#order_timeObject



45
# File 'lib/kuaiqian/response.rb', line 45

def order_time;       @params[:orderTime]; end

#pay_amountObject



49
# File 'lib/kuaiqian/response.rb', line 49

def pay_amount;       @params[:payAmount]; end

#pay_resultObject



54
# File 'lib/kuaiqian/response.rb', line 54

def pay_result;       @params[:payResult]; end

#pay_typeObject



57
# File 'lib/kuaiqian/response.rb', line 57

def pay_type;         @params[:payType]; end

#sign_msgObject



56
# File 'lib/kuaiqian/response.rb', line 56

def sign_msg;         @params[:signMsg]; end

#sign_paramsObject



31
32
33
34
35
36
# File 'lib/kuaiqian/response.rb', line 31

def sign_params
  SIGN_PARAMS.map do |param|
    value = send(param.underscore)
    value == '' ? nil : "#{param}=#{value}" 
  end.compact.join('&')
end

#sign_typeObject



40
# File 'lib/kuaiqian/response.rb', line 40

def sign_type;        @params[:signType]; end

#successful?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/kuaiqian/response.rb', line 23

def successful?
  pay_result == '10' && valid_sign?
end

#valid_sign?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/kuaiqian/response.rb', line 27

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

#versionObject



38
# File 'lib/kuaiqian/response.rb', line 38

def version;          @params[:version]; end