worldpay 1.0.6 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 035b83919e61de6a530c882706c513391dd2fa9a
4
- data.tar.gz: 8d4c3e3d0226219f72464e4305ac3495dc9e8143
3
+ metadata.gz: eee0db6849c02df70489b192a32233a483e59879
4
+ data.tar.gz: 173aebc6ea7f5f2fcb5ba25c35276aa5e039770f
5
5
  SHA512:
6
- metadata.gz: 97ac464d180ba7b8963f54f1081f24039cb3832fce88b97e5532f0dc134ef63419680fc9c23344867d2b5c87aae057ca969dabc73d3719b363975911dabd219b
7
- data.tar.gz: 9ed4b54692604b6b5c21f7f44cf25ebc597fcdd3fe9df24eb992a0cfd2c1da56e9189ce7e75442fb4568aa15b25044343f1064bafe67b005c2a03f6d28ce6e32
6
+ metadata.gz: a9e7eda93ecf9485f4761c0f4d2c3989195f81d5456a391355a6ebd62fd1e61e020e2719611b64b83ffda68c2d8293dc2acd137348c752c6fb780be9ba8f8544
7
+ data.tar.gz: bc4cb570ac6766a3631628a2105a7b67cf1231fb680bf61c0c4d8a0d4742f11617015c86f84efb1e431516075a2dab6208a5dbfbae3b45a08c3e6916e8787be4
@@ -6,319 +6,399 @@ require "json"
6
6
 
7
7
  class Worldpay
8
8
 
9
- @service_key = ''
10
- @timeout = 0
11
- @disable_ssl = false
12
- @endpoint = ''
13
-
14
- @errors = {}
15
- @raise_errors = true
16
-
17
- @version = '1.0.6'
18
-
19
- @orderTypes = ['ECOM','MOTO','RECURRING']
20
-
21
-
22
- def initialize(service_key='', timeout=3, raise_errors=true)
23
- if service_key.empty?
24
- raise "Please set a Service Key"
25
- else
26
- @service_key = service_key
27
- @timeout = timeout
28
-
29
- @disable_ssl = false
30
- @endpoint = 'api.worldpay.com'
31
-
32
- @errors = {
33
- 'ip' => 'Invalid parameters',
34
- 'cine' => 'php_curl was not found',
35
- 'to' => 'Request timed out',
36
- 'nf' => 'Not found',
37
- 'apierror' => 'API Error',
38
- 'uanv' => 'Worldpay is currently unavailable, please try again later',
39
- 'contact' => 'Error contacting Worldpay, please try again later',
40
- 'ssl' => 'You must enable SSL check in production mode',
41
- 'verify' => 'Worldpay not verifying SSL connection',
42
- 'orderInput' => {
43
- 'token' => 'No token found',
44
- 'orderDescription' => 'No order_description found',
45
- 'amount' => 'No amount found, or it is not a whole number',
46
- 'currencyCode' => 'No currency_code found',
47
- 'name' => 'No name found',
48
- 'billingAddress' => 'No billing_address found'
49
- },
50
- 'notificationPost' => 'Notification Error: Not a post',
51
- 'notificationUnknown' => 'Notification Error: Cannot be processed',
52
- 'capture' => {
53
- 'ordercode' => 'No order code entered'
54
- },
55
- 'refund' => {
56
- 'ordercode' => 'No order code entered'
57
- },
58
- 'json' => 'JSON could not be decoded',
59
- 'key' => 'Please enter your service key',
60
- 'sslerror' => 'Worldpay SSL certificate could not be validated'
61
- }
62
- @raise_errors = raise_errors
63
- end
64
- end
65
-
66
-
67
- def setEndpoint(endpoint)
68
- @endpoint = endpoint
69
- end
70
-
71
-
72
- #Disable SSL Check ~ Use only for testing!
73
- def disableSSLCheck(disable = false)
74
- @disable_ssl = disable
75
-
76
- end
77
-
78
- #Set timeout
79
- def setTimeout(timeout = 3)
80
- @timeout = timeout
81
- end
82
-
83
-
84
- #ERRORS
85
- def onError(error, message=false, code=nil, httpStatusCode=nil, description=nil, customCode=nil)
86
-
87
-
88
- if (@raise_errors)
89
- raise message.to_s
90
- else
91
- p message.to_s
92
- end
93
- end
94
-
95
-
96
-
97
-
98
-
99
- #ORDERS
100
- def checkOrderInput(order)
101
- errors2 = []
102
-
103
- if (!order.any?)
104
- onError('ip')
105
- end
106
- if (order['token']==nil)
107
- errors2 << @errors['orderInput']['token']
108
- end
109
- if (order['orderDescription']==nil)
110
- errors2 << @errors['orderInput']['orderDescription']
111
- end
112
- if (order['amount']==nil)
113
- errors2 << @errors['orderInput']['amount']
114
- end
115
- if (order['currencyCode']==nil)
116
- errors2 << @errors['orderInput']['currencyCode']
117
- end
118
- if (order['name']==nil)
119
- errors2 << @errors['orderInput']['name']
120
- end
121
- if (order['billingAddress']==nil)
122
- errors2 << @errors['orderInput']['billingAddress']
123
- end
124
-
125
- if (errors2.length > 0)
126
- onError('ip', errors2.join(', '))
127
- end
128
- end
129
-
130
- def createOrder(order={})
131
-
132
- self.checkOrderInput(order)
133
-
134
- defaults = {
135
- 'orderType' => 'ECOM', #Order Type: ECOM/MOTO/RECURRING
136
- 'customerIdentifiers' => nil,
137
- 'billingAddress' => nil
138
- }
139
-
140
- order = defaults.merge(order)
141
-
142
- fmt = "%05.2f" % order['amount']
143
- cost_cents = fmt.split('.').join('')
144
-
145
- request = {
146
- 'token' => order['token'],
147
- 'orderDescription' => order['orderDescription'],
148
- 'amount' => cost_cents,
149
- 'is3DSOrder' => order['3DS'],
150
- 'currencyCode' => order['currencyCode'],
151
- 'name' => order['name'],
152
- 'orderType' => order['orderType'] && @orderTypes ? (@orderTypes.include?(order['orderType']) ? order['orderType'] : 'ECOM') : 'ECOM',
153
- 'authorizeOnly' => order['authoriseOnly'] ? true : false,
154
- 'billingAddress' => order['billingAddress'],
155
- 'customerOrderCode' => order['customerOrderCode'],
156
- 'customerIdentifiers' => order['customerIdentifiers']
157
- }
158
-
159
- if(request['is3DSOrder'] == true)
160
- threeDsInfo = {
161
- 'shopperIpAddress' => order['shopperIpAddress'],
162
- 'shopperSessionId' => order['shopperSessionId'],
163
- 'shopperUserAgent' => order['shopperUserAgent'],
164
- 'shopperAcceptHeader' => order['shopperAcceptHeader']
165
- }
166
- request.merge!(threeDsInfo)
167
- end
168
-
169
- response = sendRequest('orders', request.to_json, true)
170
-
171
- if (response['body']['orderCode'])
172
- #success
173
- return response
174
- else
175
- onError('apierror', response.to_s)
176
- end
177
-
178
- end
179
-
180
- def authorise3DSOrder(orderCode, responseCode, threeDsInfo)
181
- request = {
182
- 'threeDSResponseCode' => responseCode,
183
- 'shopperSessionId' => threeDsInfo['shopperSessionId'],
184
- 'shopperAcceptHeader' => threeDsInfo['shopperAcceptHeader'],
185
- 'shopperUserAgent' => threeDsInfo['shopperUserAgent'],
186
- 'shopperIpAddress' => threeDsInfo['shopperIpAddress']
187
- }
188
-
189
- response = sendRequest('orders/'+orderCode, request.to_json, true, 'PUT')
190
-
191
- if (response['body']['orderCode'])
192
- #success
193
- return response
194
- else
195
- onError('apierror', response.to_s)
196
- end
197
- end
198
-
199
- #Capture Authorized Worldpay Order
200
- def captureAuthorisedOrder(orderCode=false, amount=false)
201
- if (orderCode || orderCode.is_a?(String))
202
- #
203
- else
204
- onError('ip', @errors['capture']['ordercode'])
205
- end
206
-
207
- if (amount && amount.is_a?(Integer))
208
- json = {'captureAmount'=>amount}.to_json
209
- end
210
-
211
- sendRequest('orders/'+orderCode+'/capture', (json||false))
212
- end
213
-
214
- #Cancel Authorized Worldpay Order
215
- def cancelAuthorisedOrder(orderCode=false)
216
- if (orderCode || orderCode.is_a?(String))
217
- #
218
- else
219
- onError('ip', @errors['capture']['ordercode'])
220
- end
221
-
222
- sendRequest('orders/'+orderCode, false, false, 'DELETE')
223
- end
224
-
225
-
226
- #Refund Worldpay order
227
- def refundOrder(orderCode=false, amount=false)
228
- if (orderCode==false || orderCode!=orderCode.to_s)
229
- onError('ip', @errors['refund']['ordercode'])
230
- end
231
- if (amount!=false)
232
- json = {'refundAmount'=>amount}.to_json
233
- else
234
- json = false
235
- end
236
- sendRequest('orders/'+orderCode+'/refund', json)
237
- end
238
-
239
-
240
-
241
-
242
-
243
- #REQUESTS
244
- def sendRequest(action='', json=false, expectResponse=false, method='POST')
245
- net = Net::HTTP.new(@endpoint, '443')
246
-
247
- if (method=="POST")
248
- request = Net::HTTP::Post.new('/v1/'+action)
249
- elsif (method=="GET")
250
- request = Net::HTTP::Get.new('/v1/'+action)
251
- elsif (method=="PUT")
252
- request = Net::HTTP::Put.new('/v1/'+action)
253
- elsif (method=="DELETE")
254
- request = Net::HTTP::Delete.new('/v1/'+action)
255
- end
256
-
257
- # ? request = Net::HTTP::Put.new('/v1/'+action)
258
-
259
- net.use_ssl = true
260
- net.verify_mode = @disable_ssl ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
261
-
262
- #request.set_form_data(JSON.parse(json))
263
- if (json != false)
264
- request.body = json
265
- end
266
- request.add_field("Authorization", @service_key)
267
- request.add_field("Content-Type", "application/json")
268
- request.add_field("X-wp-client-user-agent", "os.name="+RUBY_PLATFORM.to_s+";os.version="+RUBY_PLATFORM.to_s+";os.arch="+RUBY_PLATFORM.to_s+";lang.version="+RUBY_VERSION.to_s+";lib.version="+@version.to_s+";api.version=v1;lang=am;owner=worldpay")
269
- if (json != false)
270
- request.add_field("Content-Length", json.length)
271
- end
272
-
273
- net.set_debug_output $stdout #useful to see the raw messages going over the wire
274
- net.read_timeout = @timeout
275
- net.open_timeout = @timeout
276
-
277
- response = net.start do |http|
278
- http.request(request)
279
- end
280
-
281
- return {
282
- "code"=>response.code,
283
- "body"=>(JSON.parse(response.read_body) if response.read_body && response.read_body.length >= 2)
284
- }
285
-
286
- end
287
-
288
-
289
-
290
-
291
-
292
-
293
- #RESPONSES
294
- def handleResponse(response)
295
- response = response.to_json
296
- end
297
-
298
-
299
-
300
-
301
-
302
- #TOKENS
303
- #Get card details from Worldpay token
304
- def getStoredCardDetails(token=false)
305
- if (token==false || token!=token.to_s)
306
- onError('ip', @errors['orderInput']['token'])
307
- end
308
-
309
- response = sendRequest('tokens/'+token, false, true, 'GET')
310
-
311
-
312
- if (response['body']['paymentMethod'])
313
- return response['body']['paymentMethod']
314
- else
315
- #onError('apierror')
316
- return ""
317
- end
318
- end
319
-
320
-
321
-
322
-
9
+ @service_key = ''
10
+ @timeout = 0
11
+ @disable_ssl = false
12
+ @endpoint = ''
13
+
14
+ @errors = {}
15
+ @raise_errors = true
16
+
17
+ @version = '1.0.6'
18
+
19
+ @orderTypes = ['ECOM','MOTO','RECURRING']
20
+
21
+
22
+ def initialize(service_key='', timeout=3, raise_errors=true)
23
+ if service_key.empty?
24
+ raise "Please set a Service Key"
25
+ else
26
+ @service_key = service_key
27
+ @timeout = timeout
28
+
29
+ @disable_ssl = false
30
+ @endpoint = 'https://api.worldpay.com'
31
+
32
+ @errors = {
33
+ 'ip' => 'Invalid parameters',
34
+ 'cine' => 'php_curl was not found',
35
+ 'to' => 'Request timed out',
36
+ 'nf' => 'Not found',
37
+ 'apierror' => 'API Error',
38
+ 'uanv' => 'Worldpay is currently unavailable, please try again later',
39
+ 'contact' => 'Error contacting Worldpay, please try again later',
40
+ 'ssl' => 'You must enable SSL check in production mode',
41
+ 'verify' => 'Worldpay not verifying SSL connection',
42
+ 'orderInput' => {
43
+ 'token' => 'No token found',
44
+ 'orderCode' => 'No order_code entered',
45
+ 'orderDescription' => 'No order_description found',
46
+ 'amount' => 'No amount found, or it is not a whole number',
47
+ 'currencyCode' => 'No currency_code found',
48
+ 'name' => 'No name found',
49
+ 'billingAddress' => 'No billing_address found'
50
+ },
51
+ 'notificationPost' => 'Notification Error: Not a post',
52
+ 'notificationUnknown' => 'Notification Error: Cannot be processed',
53
+ 'capture' => {
54
+ 'ordercode' => 'No order code entered'
55
+ },
56
+ 'refund' => {
57
+ 'ordercode' => 'No order code entered'
58
+ },
59
+ 'json' => 'JSON could not be decoded',
60
+ 'key' => 'Please enter your service key',
61
+ 'sslerror' => 'Worldpay SSL certificate could not be validated'
62
+ }
63
+ @raise_errors = raise_errors
64
+ end
65
+ end
66
+
67
+ def setEndpoint(endpoint)
68
+ @endpoint = endpoint
69
+ end
70
+
71
+ #Disable SSL Check ~ Use only for testing!
72
+ def disableSSLCheck(disable = false)
73
+ @disable_ssl = disable
74
+
75
+ end
76
+
77
+ #Set timeout
78
+ def setTimeout(timeout = 3)
79
+ @timeout = timeout
80
+ end
81
+
82
+ #ERRORS
83
+ def onError(error, message=false, code=nil, httpStatusCode=nil, description=nil, customCode=nil)
84
+
85
+
86
+ if (@raise_errors)
87
+ raise message.to_s
88
+ else
89
+ p message.to_s
90
+ end
91
+ end
92
+
93
+ #ORDERS
94
+ def checkOrderInput(order)
95
+ errors2 = []
96
+
97
+ if (!order.any?)
98
+ onError('ip')
99
+ end
100
+ if (order['token']==nil)
101
+ errors2 << @errors['orderInput']['token']
102
+ end
103
+ if (order['orderDescription']==nil)
104
+ errors2 << @errors['orderInput']['orderDescription']
105
+ end
106
+ if (order['amount']==nil)
107
+ errors2 << @errors['orderInput']['amount']
108
+ end
109
+ if (order['currencyCode']==nil)
110
+ errors2 << @errors['orderInput']['currencyCode']
111
+ end
112
+ if (order['name']==nil)
113
+ errors2 << @errors['orderInput']['name']
114
+ end
115
+ if (order['billingAddress']==nil)
116
+ errors2 << @errors['orderInput']['billingAddress']
117
+ end
118
+
119
+ if (errors2.length > 0)
120
+ onError('ip', errors2.join(', '))
121
+ end
122
+ end
123
+
124
+ def createOrder(order={})
125
+
126
+ self.checkOrderInput(order)
127
+
128
+ defaults = {
129
+ 'orderType' => 'ECOM', #Order Type: ECOM/MOTO/RECURRING
130
+ 'customerIdentifiers' => nil,
131
+ 'billingAddress' => nil,
132
+ 'deliveryAddress' => nil
133
+ }
134
+
135
+ order = defaults.merge(order)
136
+
137
+ fmt = "%05.2f" % order['amount']
138
+ cost_cents = fmt.split('.').join('')
139
+
140
+ _authorizeOnly = false
141
+ if order['authorizeOnly']
142
+ _authorizeOnly = order['authorizeOnly']
143
+ elsif
144
+ order['authoriseOnly']
145
+ _authorizeOnly = order['authoriseOnly']
146
+ end
147
+
148
+ request = {
149
+ 'token' => order['token'],
150
+ 'orderDescription' => order['orderDescription'],
151
+ 'amount' => cost_cents,
152
+ 'is3DSOrder' => order['3DS'],
153
+ 'currencyCode' => order['currencyCode'],
154
+ 'name' => order['name'],
155
+ 'orderType' => order['orderType'] && @orderTypes ? (@orderTypes.include?(order['orderType']) ? order['orderType'] : 'ECOM') : 'ECOM',
156
+ 'authorizeOnly' => _authorizeOnly,
157
+ 'billingAddress' => order['billingAddress'],
158
+ 'deliveryAddress' => order['deliveryAddress'],
159
+ 'customerOrderCode' => order['customerOrderCode'],
160
+ 'customerIdentifiers' => order['customerIdentifiers']
161
+ }
162
+
163
+ if(request['is3DSOrder'] == true)
164
+ threeDsInfo = {
165
+ 'shopperIpAddress' => order['shopperIpAddress'],
166
+ 'shopperSessionId' => order['shopperSessionId'],
167
+ 'shopperUserAgent' => order['shopperUserAgent'],
168
+ 'shopperAcceptHeader' => order['shopperAcceptHeader']
169
+ }
170
+ request.merge!(threeDsInfo)
171
+ end
172
+
173
+ response = sendRequest('orders', request.to_json, true)
174
+
175
+ if (response['body']['orderCode'])
176
+ #success
177
+ return response
178
+ else
179
+ onError('apierror', response.to_s)
180
+ end
181
+
182
+ end
183
+
184
+ def createAPMOrder(order={})
185
+
186
+ self.checkOrderInput(order)
187
+
188
+ defaults = {
189
+ 'deliveryAddress' => nil,
190
+ 'billingAddress' => nil,
191
+ 'successUrl' => nil,
192
+ 'pendingUrl' => nil,
193
+ 'failureUrl' => nil,
194
+ 'cancelUrl' => nil
195
+ }
196
+
197
+ order = defaults.merge(order)
198
+
199
+ fmt = "%05.2f" % order['amount']
200
+ cost_cents = fmt.split('.').join('')
201
+
202
+ request = {
203
+ 'token' => order['token'],
204
+ 'orderDescription' => order['orderDescription'],
205
+ 'amount' => cost_cents,
206
+ 'currencyCode' => order['currencyCode'],
207
+ 'name' => order['name'],
208
+ 'shopperEmailAddress' => order['shopperEmailAddress'],
209
+ 'billingAddress' => order['billingAddress'],
210
+ 'deliveryAddress' => order['deliveryAddress'],
211
+ 'customerOrderCode' => order['customerOrderCode'],
212
+ 'successUrl' => order['successUrl'],
213
+ 'pendingUrl' => order['pendingUrl'],
214
+ 'failureUrl' => order['failureUrl'],
215
+ 'cancelUrl' => order['cancelUrl'],
216
+ 'statementNarrative' => order['statementNarrative'],
217
+ 'settlementCurrency' => order['settlementCurrency'],
218
+ 'customerIdentifiers' => order['customerIdentifiers']
219
+ }
220
+
221
+ response = sendRequest('orders', request.to_json, true)
222
+
223
+ if (response['body']['orderCode'])
224
+ #success
225
+ return response
226
+ else
227
+ onError('apierror', response.to_s)
228
+ end
229
+
230
+ end
231
+
232
+ def authorise3DSOrder(orderCode, responseCode, threeDsInfo)
233
+ request = {
234
+ 'threeDSResponseCode' => responseCode,
235
+ 'shopperSessionId' => threeDsInfo['shopperSessionId'],
236
+ 'shopperAcceptHeader' => threeDsInfo['shopperAcceptHeader'],
237
+ 'shopperUserAgent' => threeDsInfo['shopperUserAgent'],
238
+ 'shopperIpAddress' => threeDsInfo['shopperIpAddress']
239
+ }
240
+
241
+ response = sendRequest('orders/'+orderCode, request.to_json, true, 'PUT')
242
+
243
+ if (response['body']['orderCode'])
244
+ #success
245
+ return response
246
+ else
247
+ onError('apierror', response.to_s)
248
+ end
249
+ end
250
+
251
+ #Capture Authorized Worldpay Order
252
+ def captureAuthorisedOrder(orderCode=false, amount=false)
253
+ if (orderCode || orderCode.is_a?(String))
254
+ #
255
+ else
256
+ onError('ip', @errors['capture']['ordercode'])
257
+ end
258
+
259
+ if (amount && amount.is_a?(Integer))
260
+ json = {'captureAmount'=>amount}.to_json
261
+ end
262
+
263
+ sendRequest('orders/'+orderCode+'/capture', (json||false))
264
+ end
265
+
266
+ #Cancel Authorized Worldpay Order
267
+ def cancelAuthorisedOrder(orderCode=false)
268
+ if (orderCode || orderCode.is_a?(String))
269
+ #
270
+ else
271
+ onError('ip', @errors['capture']['ordercode'])
272
+ end
273
+
274
+ sendRequest('orders/'+orderCode, false, false, 'DELETE')
275
+ end
276
+
277
+ #Refund Worldpay order
278
+ def refundOrder(orderCode=false, amount=false)
279
+ if (orderCode==false || orderCode!=orderCode.to_s)
280
+ onError('ip', @errors['refund']['ordercode'])
281
+ end
282
+ if (amount!=false)
283
+ json = {'refundAmount'=>amount}.to_json
284
+ else
285
+ json = false
286
+ end
287
+ sendRequest('orders/'+orderCode+'/refund', json)
288
+ end
289
+
290
+ #REQUESTS
291
+ def sendRequest(action='', json=false, expectResponse=false, method='POST')
292
+ uri = URI.parse(@endpoint)
293
+
294
+ net = Net::HTTP.new(uri.host, uri.port)
295
+
296
+ if (method=="POST")
297
+ request = Net::HTTP::Post.new('/v1/'+action)
298
+ elsif (method=="GET")
299
+ request = Net::HTTP::Get.new('/v1/'+action)
300
+ elsif (method=="PUT")
301
+ request = Net::HTTP::Put.new('/v1/'+action)
302
+ elsif (method=="DELETE")
303
+ request = Net::HTTP::Delete.new('/v1/'+action)
304
+ end
305
+
306
+ net.use_ssl = true
307
+ net.verify_mode = @disable_ssl ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
308
+
309
+ if (json != false)
310
+ request.body = json
311
+ end
312
+ request.add_field("Authorization", @service_key)
313
+ request.add_field("Content-Type", "application/json")
314
+ request.add_field("X-wp-client-user-agent", "os.name="+RUBY_PLATFORM.to_s+";os.version="+RUBY_PLATFORM.to_s+";os.arch="+RUBY_PLATFORM.to_s+";lang.version="+RUBY_VERSION.to_s+";lib.version="+@version.to_s+";api.version=v1;lang=am;owner=worldpay")
315
+ if (json != false)
316
+ request.add_field("Content-Length", json.length)
317
+ end
318
+
319
+ net.set_debug_output $stdout #useful to see the raw messages going over the wire
320
+ net.read_timeout = @timeout
321
+ net.open_timeout = @timeout
322
+
323
+ result = net.start do |http|
324
+ http.request(request)
325
+ end
326
+
327
+ if (result.read_body && result.read_body.length >= 2)
328
+ response = JSON.parse(result.read_body)
329
+ else
330
+ response = false
331
+ end
332
+
333
+ if (expectResponse && !response.present?)
334
+ onError('uanv', @errors['json'], 503);
335
+ end
336
+
337
+ if (response && response["httpStatusCode"].present?)
338
+
339
+ if (response["httpStatusCode"] != '200')
340
+ onError(
341
+ false,
342
+ response["message"],
343
+ result.code,
344
+ response['httpStatusCode'],
345
+ response['description'],
346
+ response['customCode']
347
+ )
348
+ end
349
+ elsif (expectResponse && result.code != '200')
350
+ # If we expect a result and we have an error
351
+ onError('uanv', @errors['json'], 503)
352
+ elsif (!expectResponse)
353
+ if (result.code != '200')
354
+ onError('apierror', result.read_body, result.code)
355
+ else
356
+ response = true
357
+ end
358
+ end
359
+
360
+ return {
361
+ "code"=>result.code,
362
+ "body"=>response
363
+ }
364
+
365
+ end
366
+
367
+ #RESPONSES
368
+ def handleResponse(response)
369
+ response = response.to_json
370
+ end
371
+
372
+ #TOKENS
373
+ #Get card details from Worldpay token
374
+ def getStoredCardDetails(token=false)
375
+ if (token==false || token!=token.to_s)
376
+ onError('ip', @errors['orderInput']['token'])
377
+ end
378
+
379
+ response = sendRequest('tokens/'+token, false, true, 'GET')
380
+
381
+
382
+ if (response['body']['paymentMethod'])
383
+ return response['body']['paymentMethod']
384
+ else
385
+ return false
386
+ end
387
+ end
388
+
389
+
390
+ def getOrder(orderCode = false)
391
+ if (orderCode==false || !orderCode.present?)
392
+ onError('ip', @errors['orderInput']['orderCode']);
393
+ end
394
+
395
+ response = sendRequest('orders/' + orderCode, false, true, 'GET');
396
+
397
+ if (!response['body']['orderCode'].present?)
398
+ onError('apierror')
399
+ end
400
+
401
+ return response
402
+ end
323
403
 
324
404
  end
Binary file
Binary file
Binary file
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "worldpay"
7
- spec.version = "1.0.6"
7
+ spec.version = "1.2.0"
8
8
  spec.authors = ["Andrew Odendaal, Paul Beckford"]
9
9
  spec.email = ["andrew.odendaal@worldpay.com"]
10
10
  spec.summary = %q{online.worldpay.com ruby lib.}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worldpay
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Odendaal, Paul Beckford
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-27 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -64,6 +64,9 @@ files:
64
64
  - worldpay-1.0.3.gem
65
65
  - worldpay-1.0.4.gem
66
66
  - worldpay-1.0.5.gem
67
+ - worldpay-1.0.6.gem
68
+ - worldpay-1.0.7.gem
69
+ - worldpay-1.1.0.gem
67
70
  - worldpay.gemspec
68
71
  homepage: https://online.worldpay.com
69
72
  licenses: