module Nicepay module Api class RequestVa def initialize(parameters) @parameters = parameters @parametersToCheck = Array[ 'iMid', 'payMethod', 'bankCd', 'goodsNm', 'description', 'referenceNo', 'cartData', 'amt', 'currency', 'billingNm', 'billingPhone', 'billingEmail', 'billingAddr', 'billingCity', 'billingState', 'billingPostCd', 'billingCountry', 'userIP', 'dbProcessUrl', 'callBackUrl', 'vat', 'fee', 'notaxAmt', 'merchantToken' ] end def parameters @parameters end def parametersToCheck @parametersToCheck end def errorMsg @errorMsg = errorMsg end def checkParameters @parametersToCheck.each do |param| if @parameters[param] == nil @errorMsg = "\nUndefined mandatory parameter `" + \ param + \ '` please set param using Nicepay.setRequestParam(\'' + \ param + \ '\', \''+ param +' value\')' @checkParameters = false break else @checkParameters = true end end @checkParameters end def dumpParameters @dumpedParameters = "\n///// [POST] Request Parameter Dump /////\n\n" @parameters.each do |key, value| @dumpedParameters += key.to_s + ' = ' + value.to_s + "\n\n" end @dumpedParameters end def response if self.checkParameters == true with_retries(:max_tries => Nicepay.max_retry, :rescue => RestClient::Exception) do @response = RestClient::Request.execute( :method => :post, :url => Nicepay::REQ_VA_URL, :payload => @parameters, :timeout => Nicepay.read_timeout, :open_timeout => Nicepay.connection_timeout ) end @result = JSON.parse(@response) else puts @errorMsg puts self.dumpParameters abort('Exit') end end end class ChargeCard def initialize(parameters) @parameters = parameters @parametersToCheck = Array[ 'iMid', 'payMethod', 'instmntType', 'instmntMon', 'goodsNm', 'description', 'referenceNo', 'cartData', 'amt', 'currency', 'billingNm', 'billingPhone', 'billingEmail', 'billingAddr', 'billingCity', 'billingState', 'billingPostCd', 'billingCountry', 'userIP', 'dbProcessUrl', 'callBackUrl', 'vat', 'fee', 'notaxAmt', 'merchantToken' ] end def parameters @parameters end def parametersToCheck @parametersToCheck end def errorMsg @errorMsg = errorMsg end def checkParameters @parametersToCheck.each do |param| if @parameters[param] == nil @errorMsg = "\nUndefined mandatory parameter `" + \ param + \ '` please set param using Nicepay.setRequestParam(\'' + \ param + \ '\', \''+ param +' value\')' @checkParameters = false break else @checkParameters = true end end @checkParameters end def dumpParameters @dumpedParameters = "\n///// [POST] Request Parameter Dump /////\n\n" @parameters.each do |key, value| @dumpedParameters += key.to_s + ' = ' + value.to_s + "\n\n" end @dumpedParameters end def response if self.checkParameters == true with_retries(:max_tries => Nicepay.max_retry, :rescue => RestClient::Exception) do @response = RestClient::Request.execute( :method => :post, :url => Nicepay::REQ_CC_URL, :payload => @parameters, :timeout => Nicepay.read_timeout, :open_timeout => Nicepay.connection_timeout ) end @response[0..3]='' @response = JSON.parse(@response) @result = @response["data"] else puts @errorMsg puts self.dumpParameters abort('Exit') end end end class CheckStatus def initialize(parameters) @parameters = parameters @parametersToCheck = Array[ 'iMid', 'referenceNo', 'amt', 'tXid', 'merchantToken' ] end def parameters @parameters end def parametersToCheck @parametersToCheck end def errorMsg @errorMsg = errorMsg end def checkParameters @parametersToCheck.each do |param| if @parameters[param] == nil @errorMsg = "\nUndefined mandatory parameter `" + \ param + \ '` please set param using Nicepay.setRequestParam(\'' + \ param + \ '\', \''+ param +' value\')' @checkParameters = false break else @checkParameters = true end end @checkParameters end def dumpParameters @dumpedParameters = "\n///// [POST] Request Parameter Dump /////\n\n" @parameters.each do |key, value| @dumpedParameters += key.to_s + ' = ' + value.to_s + "\n\n" end @dumpedParameters end def response if self.checkParameters == true with_retries(:max_tries => Nicepay.max_retry, :rescue => RestClient::Exception) do @response = RestClient::Request.execute( :method => :post, :url => Nicepay::CHECK_STATUS_URL, :payload => @parameters, :timeout => Nicepay.read_timeout, :open_timeout => Nicepay.connection_timeout ) end @response = JSON.parse(@response) @result = @response else puts @errorMsg puts self.dumpParameters abort('Exit') end end end class CancelVa def initialize(parameters) @parameters = parameters @parametersToCheck = Array[ 'iMid', 'payMethod', # 'referenceNo', 'amt', 'tXid', 'merchantToken', 'cancelType' ] end def parameters @parameters end def parametersToCheck @parametersToCheck end def errorMsg @errorMsg = errorMsg end def checkParameters @parametersToCheck.each do |param| if @parameters[param] == nil @errorMsg = "\nUndefined mandatory parameter `" + \ param + \ '` please set param using Nicepay.setRequestParam(\'' + \ param + \ '\', \''+ param +' value\')' @checkParameters = false break else @checkParameters = true end end @checkParameters end def dumpParameters @dumpedParameters = "\n///// [POST] Request Parameter Dump /////\n\n" @parameters.each do |key, value| @dumpedParameters += key.to_s + ' = ' + value.to_s + "\n\n" end @dumpedParameters end def response if self.checkParameters == true with_retries(:max_tries => Nicepay.max_retry, :rescue => RestClient::Exception) do @response = RestClient::Request.execute( :method => :post, :url => Nicepay::CANCEL_VA_URL, :payload => @parameters, :timeout => Nicepay.read_timeout, :open_timeout => Nicepay.connection_timeout ) end @response = JSON.parse(@response) @result = @response else puts @errorMsg puts self.dumpParameters abort('Exit') end end end end end