Class: Nicepay::Api::RequestVa

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

Instance Method Summary collapse

Constructor Details

#initialize(parameters) ⇒ RequestVa

Returns a new instance of RequestVa.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/nicepay/api.rb', line 6

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

Instance Method Details

#checkParametersObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/nicepay/api.rb', line 48

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



65
66
67
68
69
70
71
# File 'lib/nicepay/api.rb', line 65

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



44
45
46
# File 'lib/nicepay/api.rb', line 44

def errorMsg
    @errorMsg = errorMsg
end

#parametersObject



36
37
38
# File 'lib/nicepay/api.rb', line 36

def parameters
    @parameters
end

#parametersToCheckObject



40
41
42
# File 'lib/nicepay/api.rb', line 40

def parametersToCheck
    @parametersToCheck
end

#responseObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/nicepay/api.rb', line 73

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