Class: Tencentpay::Request
- Inherits:
-
Object
- Object
- Tencentpay::Request
- Defined in:
- lib/tencentpay/request.rb
Constant Summary collapse
- GATEWAY_URL =
"http://service.tenpay.com/cgi-bin/v3.0/payservice.cgi"
Instance Method Summary collapse
-
#initialize(desc, sp_billno, total_fee, return_url, bank_type = 0, spbill_create_ip = '', attach = nil) ⇒ Request
constructor
A new instance of Request.
- #params ⇒ Object
- #sign ⇒ Object
- #sign_params ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(desc, sp_billno, total_fee, return_url, bank_type = 0, spbill_create_ip = '', attach = nil) ⇒ Request
Returns a new instance of Request.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/tencentpay/request.rb', line 5 def initialize(desc, sp_billno, total_fee, return_url, bank_type = 0, spbill_create_ip = '', attach = nil) @cmdno = 1 @date = Date.today.strftime("%Y%m%d") @bank_type = bank_type @desc = desc = Tenpay::Config. @key = Tenpay::Config.key @sp_billno = sp_billno.to_i @transaction_id = "%s%s%010d" % [, @date, @sp_billno] @total_fee = total_fee.to_i @fee_type = 1 @return_url = return_url @attach = attach || '' @spbill_create_ip = (RAILS_ENV == 'production' ? spbill_create_ip : '') @cs = "utf-8" end |
Instance Method Details
#params ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/tencentpay/request.rb', line 39 def params str = "cmdno=#{@cmdno}&date=#{@date}&bargainor_id=#{@bargainor_id}&transaction_id=#{@transaction_id}" + "&sp_billno=#{@sp_billno}&total_fee=#{@total_fee}&fee_type=#{@fee_type}" + "&return_url=#{@return_url}&attach=#{CGI.escape(@attach)}&desc=#{CGI.escape(@desc)}" str << "&spbill_create_ip=#{@spbill_create_ip}" if @spbill_create_ip.present? str end |
#sign ⇒ Object
27 28 29 |
# File 'lib/tencentpay/request.rb', line 27 def sign @sign ||= Digest::MD5.hexdigest(sign_params).lowcase end |
#sign_params ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/tencentpay/request.rb', line 31 def sign_params str = "cmdno=#{@cmdno}&date=#{@date}&bargainor_id=#{@bargainor_id}&transaction_id=#{@transaction_id}" + "&sp_billno=#{@sp_billno}&total_fee=#{@total_fee}&fee_type=#{@fee_type}" + "&return_url=#{@return_url}&attach=#{CGI.escape(@attach)}" str << "&spbill_create_ip=#{@spbill_create_ip}" if @spbill_create_ip.present? str << "&key=#{@key}" end |
#url ⇒ Object
47 48 49 |
# File 'lib/tencentpay/request.rb', line 47 def url "#{GATEWAY_URL}?#{params}&sign=#{sign}" end |