Class: Nicepay::Api::CancelVa

Inherits:
Object
  • Object
show all
Defined in:
lib/nicepay/api.rb

Instance Method Summary collapse

Constructor Details

#initialize(parameters) ⇒ CancelVa

Returns a new instance of CancelVa.



257
258
259
260
261
262
263
264
265
266
267
# File 'lib/nicepay/api.rb', line 257

def initialize(parameters)
    @parameters = parameters
    @parametersToCheck = Array[
        'iMid',
        'payMethod',
        'amt',
        'tXid',
        'merchantToken',
        'cancelType'
    ]
end

Instance Method Details

#checkParametersObject



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/nicepay/api.rb', line 281

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

#dumpParametersObject



298
299
300
301
302
303
304
# File 'lib/nicepay/api.rb', line 298

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

#errorMsgObject



277
278
279
# File 'lib/nicepay/api.rb', line 277

def errorMsg
    @errorMsg = errorMsg
end

#parametersObject



269
270
271
# File 'lib/nicepay/api.rb', line 269

def parameters
    @parameters
end

#parametersToCheckObject



273
274
275
# File 'lib/nicepay/api.rb', line 273

def parametersToCheck
    @parametersToCheck
end

#responseObject



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/nicepay/api.rb', line 306

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