=begin Nicepay Ruby Bindings Have a Nicepay! =end require 'rubygems' if RUBY_VERSION < '1.9' require 'rest-client' require 'json' require 'digest' require "retries" require 'nicepay/api' require 'nicepay/version' module Nicepay @i_mid = 'IONPAYTEST' @merchant_key = '33F49GnCMS1mFYlGXisbUDzVf2ATWCl9k3R++d5hDd3Frmuos/XLx8XhXpe+LDYAbpGKZYSwtlyyLOtS/8aD7A==' @callback_url = 'http://httpresponder.com/nicepay' @db_process_url = 'http://httpresponder.com/nicepay' @requestParam = Hash.new() @cart = Hash.new {|h,k| h[k]=[]} @item = Array.new() @max_retry = 10 @connection_timeout = 20 @read_timeout = 20 #Static REQ_VA_URL = 'https://www.nicepay.co.id/nicepay/api/onePass.do' REQ_CC_URL = 'https://www.nicepay.co.id/nicepay/api/orderRegist.do' CANCEL_VA_URL = 'https://www.nicepay.co.id/nicepay/api/onePassAllCancel.do' CHECK_STATUS_URL = 'https://www.nicepay.co.id/nicepay/api/onePassStatus.do' def self.callBackUrl @callback_url end def self.dbProcessUrl @db_process_url end def self.merchantKey @merchant_key end def self.iMid @i_mid end def self.max_retry @max_retry end def self.connection_timeout @connection_timeout end def self.read_timeout @read_timeout end def self.callBackUrl=(callback_url) @callback_url = callback_url true end def self.dbProcessUrl=(db_process_url) @db_process_url = db_process_url true end def self.merchantKey=(merchant_key) @merchant_key = merchant_key true end def self.iMid=(i_mid) @i_mid = i_mid true end def self.setRequestParam(paramName, paramValue) self.requestParam[paramName] = paramValue true end def self.param(name) self.requestParam[name] end def self.requestParam @requestParam end def self.merchantToken sha256 = Digest::SHA256.new @merchantToken = sha256.hexdigest (self.iMid.to_s + \ self.param('referenceNo').to_s + \ self.param('amt').to_s + \ self.merchantKey.to_s) end def self.merchantTokenC sha256 = Digest::SHA256.new @merchantToken = sha256.hexdigest (self.iMid.to_s + \ self.param('tXid').to_s + \ self.param('amt').to_s + \ self.merchantKey.to_s) end def self.addCart(image, name, detail, amt) self.cart['item'] << { img_url: image , goods_name: name, goods_detail: detail, goods_amt: amt} self.cart['count'] = self.cart['item'].count end def self.cart @cart end def self.cartData @cartData = self.cart.to_json end def self.oneLiner(string) @oneLiner= string.gsub(/\s+/, "") end def self.flushParam @requestParam = nil end def self.dumpParameters @dumpedParameters = "\n///// [POST] Request Parameter Dump /////\n\n" @requestParam.each do |key, value| @dumpedParameters += key.to_s + ' = ' + value.to_s + "\n\n" end @dumpedParameters end def self.autoCountTotal items = self.cart['item'] total = 0 items.each do |key, value| total += key[:goods_amt].to_i end @autoCountTotal = total end def self.vaExpiryDate(day) d = Date.today @vaExpiryDate = (d + day).strftime("%Y%m%d") end def self.vaExpiryTime t = Time.now @vaExpiryTime = t.strftime("%H%M%S") end def self.userIp # @userIP = request.remote_ip @userIp = '127.0.0.1' end end