Class: Kuaiqian::Request

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

Constant Summary collapse

GATEWAY_URL =
"https://www.99bill.com/gateway/recvMerchantInfoAction.htm"
PARAMS =
%w(inputCharset bgUrl version language signType merchantAcctId payerName payerContactType payerContact orderId orderAmount orderTime productName productNum productId productDesc ext1 ext2 payType redoFlag pid)

Instance Method Summary collapse

Constructor Details

#initialize(product_name, order_id, order_time, total_fee, return_url, pay_type = '00', attach = nil, payer_name = '用户') ⇒ Request

Returns a new instance of Request.



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

def initialize(product_name, order_id, order_time, total_fee, 
                return_url, pay_type='00', attach=nil, payer_name='用户')
  @bank_type = 0
  @fee_type = 1
  
  @order_id = order_id.to_s
  @total_fee = total_fee.to_i.to_s
  @order_time = order_time.strftime("%Y%m%d%H%M%S")
  @product_name = product_name

  @pay_type = pay_type
  @return_url = return_url
  @ext1 = attach || ''
  
  @payer_name = payer_name
end

Instance Method Details

#bg_urlObject



32
# File 'lib/kuaiqian/request.rb', line 32

def bg_url; @return_url; end

#ext1Object



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

def ext1; @ext1; end

#ext2Object



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

def ext2; ''; end

#html_paramsObject



66
67
68
69
70
71
# File 'lib/kuaiqian/request.rb', line 66

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

#input_charsetObject



31
# File 'lib/kuaiqian/request.rb', line 31

def input_charset; '1'; end

#keyObject



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

def key; Kuaiqian::Config.key; end

#languageObject



35
# File 'lib/kuaiqian/request.rb', line 35

def language; '1'; end

#merchant_acct_idObject



37
# File 'lib/kuaiqian/request.rb', line 37

def merchant_acct_id; Kuaiqian::Config.spid; end

#order_amountObject



43
# File 'lib/kuaiqian/request.rb', line 43

def order_amount; @total_fee; end

#order_idObject



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

def order_id; @order_id; end

#order_timeObject



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

def order_time; @order_time; end

#page_urlObject



33
# File 'lib/kuaiqian/request.rb', line 33

def page_url; ''; end

#pay_typeObject



51
# File 'lib/kuaiqian/request.rb', line 51

def pay_type; @pay_type; end

#payer_contactObject



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

def payer_contact; ''; end

#payer_contact_typeObject



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

def payer_contact_type; '1'; end

#payer_nameObject



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

def payer_name; @payer_name; end

#pidObject



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

def pid; ''; end

#product_descObject



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

def product_desc; ''; end

#product_idObject



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

def product_id; ''; end

#product_nameObject



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

def product_name; @product_name; end

#product_numObject



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

def product_num; '1'; end

#redo_flagObject



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

def redo_flag; "0"; end

#sign_msgObject



62
63
64
# File 'lib/kuaiqian/request.rb', line 62

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

#sign_paramsObject



55
56
57
58
59
60
# File 'lib/kuaiqian/request.rb', line 55

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

#sign_typeObject



36
# File 'lib/kuaiqian/request.rb', line 36

def sign_type; '1'; end

#urlObject



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

def url
  "#{GATEWAY_URL}?#{html_params}&signMsg=#{sign_msg}"
end

#versionObject



34
# File 'lib/kuaiqian/request.rb', line 34

def version; 'v2.0'; end