Class: Tenpay::Request

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

Constant Summary collapse

GATEWAY_URL =
"https://www.tenpay.com/cgi-bin/v1.0/pay_gate.cgi"

Instance Method Summary collapse

Constructor Details

#initialize(description, order_id, created_at, total_fee, return_url, purchaser_ip = '', attach = nil) ⇒ Request

Returns a new instance of Request.



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

def initialize(description, order_id, created_at, total_fee, 
                return_url, purchaser_ip='', attach=nil)
  @cmdno = 1
  @date  = created_at.strftime("%Y%m%d")
  @bank_type = 0
  @fee_type = 1
  
  @desc = Iconv.iconv('gbk', 'utf-8', description).join
  @spid = Tenpay::Config.spid
  @key = Tenpay::Config.key
  
  @order_id = order_id.to_i
  @total_fee = total_fee.to_i
  @return_url = return_url
  @attach = attach || 'nil'
  
  @purchaser_ip = (RAILS_ENV == 'production' ? purchaser_ip : '')
end

Instance Method Details

#paramsObject



40
41
42
# File 'lib/tenpay/request.rb', line 40

def params
  @params ||= generate_params
end

#signObject



32
33
34
# File 'lib/tenpay/request.rb', line 32

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

#sign_paramsObject



36
37
38
# File 'lib/tenpay/request.rb', line 36

def sign_params
  @sign_params ||= generate_sign_params
end

#transaction_idObject



28
29
30
# File 'lib/tenpay/request.rb', line 28

def transaction_id
  @transaction_id ||= "%s%s%010d" % [@spid, @date, @order_id]
end

#urlObject



44
45
46
# File 'lib/tenpay/request.rb', line 44

def url
  "#{GATEWAY_URL}?#{params}&sign=#{sign}"
end