Class: Nicepay::Api::CheckStatus

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

Instance Method Summary collapse

Constructor Details

#initialize(parameters) ⇒ CheckStatus

Returns a new instance of CheckStatus.



187
188
189
190
191
192
193
194
195
196
# File 'lib/nicepay/api.rb', line 187

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

Instance Method Details

#checkParametersObject



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/nicepay/api.rb', line 210

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



227
228
229
230
231
232
233
# File 'lib/nicepay/api.rb', line 227

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



206
207
208
# File 'lib/nicepay/api.rb', line 206

def errorMsg
    @errorMsg = errorMsg
end

#parametersObject



198
199
200
# File 'lib/nicepay/api.rb', line 198

def parameters
    @parameters
end

#parametersToCheckObject



202
203
204
# File 'lib/nicepay/api.rb', line 202

def parametersToCheck
    @parametersToCheck
end

#responseObject



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/nicepay/api.rb', line 235

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