class Vnpay::Url
Attributes
callback_url[RW]
ip_address[RW]
order_info[RW]
Public Class Methods
new(order_info, ip_address, callback)
click to toggle source
# File lib/vnpay/url.rb, line 5 def initialize(order_info, ip_address, callback) @order_info = order_info @ip_address = ip_address @callback_url = callback_url end
Public Instance Methods
generate()
click to toggle source
# File lib/vnpay/url.rb, line 11 def generate raise "OrderInfo missing attributes" unless order_info.valid? config.payment_url + query_string + "&vnp_SecureHashType=MD5&vnp_SecureHash=#{secure_hash}" end
Private Instance Methods
config()
click to toggle source
# File lib/vnpay/url.rb, line 44 def config @config ||= Vnpay::Config.configuration end
initiate_request()
click to toggle source
# File lib/vnpay/url.rb, line 27 def initiate_request { vnp_Amount: order_info.amount.to_i * 100, vnp_Command: 'pay', vnp_CreateDate: order_info.created_at.to_i, vnp_CurrCode: 'VND', vnp_IpAddr: ip_address, vnp_Locale: 'vn', vnp_OrderInfo: order_info.description.to_s, vnp_OrderType: order_info.order_type.to_s, vnp_ReturnUrl: callback_url, vnp_TmnCode: config.website_code, vnp_TxnRef: order_info.payment_ref.to_s, vnp_Version: "2.0.0" } end
query_string()
click to toggle source
# File lib/vnpay/url.rb, line 18 def query_string initiate_request.map { |k, v| "#{url_encode(k)}=#{url_encode(v)}" }.join('&') end
secure_hash()
click to toggle source
# File lib/vnpay/url.rb, line 22 def secure_hash data = initiate_request.sort.map { |k, v| "#{k}=#{v}" }.join('&') Digest::MD5.hexdigest(config.secret_key + data) end
url_encode(string)
click to toggle source
# File lib/vnpay/url.rb, line 48 def url_encode(string) Rack::Utils.escape(string) end