bigcharger 0.1.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.
@@ -0,0 +1,591 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require File.dirname(__FILE__) + '/../lib/bigcharger'
3
+
4
+ describe BigCharger do
5
+ include BigChargerSpecHelpers
6
+
7
+ before(:all) do
8
+ @customer_id = '87654321'
9
+ @username = 'test@eway.com.au'
10
+ @password = 'test123'
11
+ @test_customer_id = '9876543211000'
12
+ @test_customer_ref = 'Test 123'
13
+ @client = BigCharger.new(@customer_id, @username, @password)
14
+ @endpoint = BigCharger::ENDPOINT
15
+ @namespace = BigCharger::SERVICE_NAMESPACE
16
+
17
+ # DEBUG
18
+ # @client.logger = Logger.new(STDOUT)
19
+ end
20
+
21
+ describe '#create_customer' do
22
+ before(:all) do
23
+ @customer = {
24
+ 'CustomerRef' => 'Test 123',
25
+ 'Title' => 'Mr.',
26
+ 'FirstName' => 'Jo',
27
+ 'LastName' => 'Smith',
28
+ 'Company' => 'company',
29
+ 'JobDesc' => 'Analyst',
30
+ 'Email' => 'test@eway.com.au',
31
+ 'Address' => '15 Dundas Court',
32
+ 'Suburb' => 'phillip',
33
+ 'State' => 'act',
34
+ 'PostCode' => '2606',
35
+ 'Country' => 'au',
36
+ 'Phone' => '02111111111',
37
+ 'Mobile' => '04111111111',
38
+ 'Fax' => '111122222',
39
+ 'URL' => 'http://eway.com.au',
40
+ 'Comments' => 'Comments',
41
+ 'CCNameOnCard' => 'Jo Smith',
42
+ 'CCNumber' => '444433XXXXXX1111',
43
+ 'CCExpiryMonth' => '08',
44
+ 'CCExpiryYear' => '15'
45
+ }
46
+ end
47
+
48
+ describe 'success scenario' do
49
+ after(:all) { WebMock.reset! }
50
+
51
+ it 'should make a request to the eWAY endpoint' do
52
+ stub_request(:post, @endpoint)
53
+ .to_return(
54
+ :status => 200,
55
+ :body => message(:create_customer_response)
56
+ )
57
+ @client.create_customer(@customer)
58
+ end
59
+
60
+ it 'should use the correct headers' do
61
+ stub_request(:post, @endpoint)
62
+ .with(:headers => {
63
+ 'SOAPAction' => "#{@namespace}/CreateCustomer",
64
+ 'Content-Type' => 'text/xml'
65
+ })
66
+ @client.create_customer(@customer)
67
+ end
68
+
69
+ it 'should pass the correct content within the request' do
70
+ stub_request(:post, @endpoint)
71
+ .with(:body => message(:create_customer_request))
72
+ @client.create_customer(@customer)
73
+ end
74
+
75
+ it 'should return the correct ID' do
76
+ stub_request(:post, @endpoint)
77
+ .to_return(
78
+ :status => 200,
79
+ :body => message(:create_customer_response)
80
+ )
81
+ response = @client.create_customer(@customer)
82
+ response.should == @test_customer_id
83
+ end
84
+ end
85
+
86
+ describe 'failure scenarios' do
87
+ it 'should raise an error when a fault is returned' do
88
+ stub_request(:post, @endpoint)
89
+ .to_return(
90
+ :status => [500, 'Internal Server Error'],
91
+ :body => message(:fault_response)
92
+ )
93
+ expect {
94
+ @client.create_customer(@customer)
95
+ }.to raise_error(BigCharger::Error, 'eWAY server responded with "Login failed." (soap:Client)')
96
+ end
97
+
98
+ it 'should raise an error when the server returns a failure response code' do
99
+ stub_request(:post, @endpoint)
100
+ .to_return(
101
+ :status => [400, 'Bad Request']
102
+ )
103
+ expect {
104
+ @client.create_customer(@customer)
105
+ }.to raise_error(BigCharger::Error, 'eWAY server responded with "Bad Request" (400)')
106
+ end
107
+ end
108
+ end
109
+
110
+ describe '#process_payment' do
111
+ before(:all) do
112
+ @amount = 1000
113
+ @invoice_ref = 'INV-80123'
114
+ @invoice_desc = 'Payment for services rendered'
115
+ end
116
+
117
+ describe 'success scenario' do
118
+ after(:all) { WebMock.reset! }
119
+
120
+ it 'should make a request to the eWAY endpoint' do
121
+ stub_request(:post, @endpoint)
122
+ .to_return(
123
+ :status => 200,
124
+ :body => message(:process_payment_response)
125
+ )
126
+ @client.process_payment(@test_customer_id, @amount, @invoice_ref, @invoice_desc)
127
+ end
128
+
129
+ it 'should use the correct headers' do
130
+ stub_request(:post, @endpoint)
131
+ .with(:headers => {
132
+ 'SOAPAction' => "#{@namespace}/ProcessPayment",
133
+ 'Content-Type' => 'text/xml'
134
+ })
135
+ @client.process_payment(@test_customer_id, @amount, @invoice_ref, @invoice_desc)
136
+ end
137
+
138
+ it 'should pass the correct content within the request' do
139
+ stub_request(:post, @endpoint)
140
+ .with(:body => message(:process_payment_request))
141
+ @client.process_payment(@test_customer_id, @amount, @invoice_ref, @invoice_desc)
142
+ end
143
+
144
+ it 'should return the correct response' do
145
+ stub_request(:post, @endpoint)
146
+ .to_return(
147
+ :status => 200,
148
+ :body => message(:process_payment_response)
149
+ )
150
+ response = @client.process_payment(@test_customer_id, @amount, @invoice_ref, @invoice_desc)
151
+
152
+ response['ewayTrxnError'].should == '00,Transaction Approved(Test Gateway)'
153
+ response['ewayTrxnStatus'].should == 'True'
154
+ response['ewayTrxnNumber'].should == '1011634'
155
+ response['ewayReturnAmount'].should == '1000'
156
+ response['ewayAuthCode'].should == '123456'
157
+ end
158
+ end
159
+
160
+ describe 'failure scenarios' do
161
+ it 'should raise an error when a fault is returned' do
162
+ stub_request(:post, @endpoint)
163
+ .to_return(
164
+ :status => [500, 'Internal Server Error'],
165
+ :body => message(:fault_response)
166
+ )
167
+ expect {
168
+ @client.process_payment(@test_customer_id, @amount, @invoice_ref, @invoice_desc)
169
+ }.to raise_error(BigCharger::Error, 'eWAY server responded with "Login failed." (soap:Client)')
170
+ end
171
+
172
+ it 'should raise an error when the server returns a failure response code' do
173
+ stub_request(:post, @endpoint)
174
+ .to_return(
175
+ :status => [400, 'Bad Request']
176
+ )
177
+ expect {
178
+ @client.process_payment(@test_customer_id, @amount, @invoice_ref, @invoice_desc)
179
+ }.to raise_error(BigCharger::Error, 'eWAY server responded with "Bad Request" (400)')
180
+ end
181
+ end
182
+ end
183
+
184
+ describe '#process_payment_with_cvn' do
185
+ before(:all) do
186
+ @amount = 1000
187
+ @cvn = '123'
188
+ @invoice_ref = 'INV-80123'
189
+ @invoice_desc = 'Payment for services rendered'
190
+ end
191
+
192
+ describe 'success scenario' do
193
+ after(:all) { WebMock.reset! }
194
+
195
+ it 'should make a request to the eWAY endpoint' do
196
+ stub_request(:post, @endpoint)
197
+ .to_return(
198
+ :status => 200,
199
+ :body => message(:process_payment_with_cvn_response)
200
+ )
201
+ @client.process_payment_with_cvn(@test_customer_id, @amount, @cvn, @invoice_ref, @invoice_desc)
202
+ end
203
+
204
+ it 'should use the correct headers' do
205
+ stub_request(:post, @endpoint)
206
+ .with(:headers => {
207
+ 'SOAPAction' => "#{@namespace}/ProcessPaymentWithCVN",
208
+ 'Content-Type' => 'text/xml'
209
+ })
210
+ @client.process_payment_with_cvn(@test_customer_id, @amount, @cvn, @invoice_ref, @invoice_desc)
211
+ end
212
+
213
+ it 'should pass the correct content within the request' do
214
+ stub_request(:post, @endpoint)
215
+ .with(:body => message(:process_payment_with_cvn_request))
216
+ @client.process_payment_with_cvn(@test_customer_id, @amount, @cvn, @invoice_ref, @invoice_desc)
217
+ end
218
+
219
+ it 'should return the correct response' do
220
+ stub_request(:post, @endpoint)
221
+ .to_return(
222
+ :status => 200,
223
+ :body => message(:process_payment_with_cvn_response)
224
+ )
225
+ response = @client.process_payment_with_cvn(@test_customer_id, @amount, @cvn, @invoice_ref, @invoice_desc)
226
+
227
+ response['ewayTrxnError'].should == '00,Transaction Approved(Test CVN Gateway)'
228
+ response['ewayTrxnStatus'].should == 'True'
229
+ response['ewayTrxnNumber'].should == '21803'
230
+ response['ewayReturnAmount'].should == '1000'
231
+ response['ewayAuthCode'].should == '123456'
232
+ end
233
+ end
234
+
235
+ describe 'failure scenarios' do
236
+ it 'should raise an error when a fault is returned' do
237
+ stub_request(:post, @endpoint)
238
+ .to_return(
239
+ :status => [500, 'Internal Server Error'],
240
+ :body => message(:fault_response)
241
+ )
242
+ expect {
243
+ @client.process_payment_with_cvn(@test_customer_id, @amount, @cvn, @invoice_ref, @invoice_desc)
244
+ }.to raise_error(BigCharger::Error, 'eWAY server responded with "Login failed." (soap:Client)')
245
+ end
246
+
247
+ it 'should raise an error when the server returns a failure response code' do
248
+ stub_request(:post, @endpoint)
249
+ .to_return(
250
+ :status => [400, 'Bad Request']
251
+ )
252
+ expect {
253
+ @client.process_payment_with_cvn(@test_customer_id, @amount, @cvn, @invoice_ref, @invoice_desc)
254
+ }.to raise_error(BigCharger::Error, 'eWAY server responded with "Bad Request" (400)')
255
+ end
256
+ end
257
+ end
258
+
259
+ describe '#query_customer' do
260
+ describe 'success scenarios' do
261
+ after(:all) { WebMock.reset! }
262
+
263
+ it 'should make a request to the eWAY endpoint' do
264
+ stub_request(:post, @endpoint)
265
+ .to_return(
266
+ :status => 200,
267
+ :body => message(:query_customer_response)
268
+ )
269
+ @client.query_customer(@test_customer_id)
270
+ end
271
+
272
+ it 'should use the correct headers' do
273
+ stub_request(:post, @endpoint)
274
+ .with(:headers => {
275
+ 'SOAPAction' => "#{@namespace}/QueryCustomer",
276
+ 'Content-Type' => 'text/xml'
277
+ })
278
+ @client.query_customer(@test_customer_id)
279
+ end
280
+
281
+ it 'should pass the correct content within the request' do
282
+ stub_request(:post, @endpoint)
283
+ .with(:body => message(:query_customer_request))
284
+ @client.query_customer(@test_customer_id)
285
+ end
286
+
287
+ it 'should return the correct response' do
288
+ stub_request(:post, @endpoint)
289
+ .to_return(
290
+ :status => 200,
291
+ :body => message(:query_customer_response)
292
+ )
293
+ response = @client.query_customer(@test_customer_id)
294
+
295
+ response['ManagedCustomerID'].should == '9876543211000'
296
+ response['CustomerRef'].should == 'Test 123'
297
+ response['CustomerTitle'].should == 'Mr.'
298
+ response['CustomerFirstName'].should == 'Jo'
299
+ response['CustomerLastName'].should == 'Smith'
300
+ response['CustomerCompany'].should == 'company'
301
+ response['CustomerJobDesc'].should be_nil
302
+ response['CustomerEmail'].should == 'test@eway.com.au'
303
+ response['CustomerAddress'].should == '15 Dundas Court'
304
+ response['CustomerSuburb'].should == 'phillip'
305
+ response['CustomerState'].should == 'act'
306
+ response['CustomerPostCode'].should == '2606'
307
+ response['CustomerCountry'].should == 'au'
308
+ response['CustomerPhone1'].should == '02111111111'
309
+ response['CustomerPhone2'].should == '04111111111'
310
+ response['CustomerFax'].should == '111122222'
311
+ response['CustomerURL'].should == 'http://eway.com.au'
312
+ response['CustomerComments'].should == 'Comments'
313
+ response['CCName'].should == 'Jo Smith'
314
+ response['CCNumber'].should == '444433XXXXXX1111'
315
+ response['CCExpiryMonth'].should == '08'
316
+ response['CCExpiryYear'].should == '15'
317
+ end
318
+ end
319
+
320
+ describe 'failure scenarios' do
321
+ it 'should raise an error when a fault is returned' do
322
+ stub_request(:post, @endpoint)
323
+ .to_return(
324
+ :status => [500, 'Internal Server Error'],
325
+ :body => message(:fault_response)
326
+ )
327
+ expect {
328
+ @client.query_customer(@test_customer_id)
329
+ }.to raise_error(BigCharger::Error, 'eWAY server responded with "Login failed." (soap:Client)')
330
+ end
331
+
332
+ it 'should raise an error when the server returns a failure response code' do
333
+ stub_request(:post, @endpoint)
334
+ .to_return(
335
+ :status => [400, 'Bad Request']
336
+ )
337
+ expect {
338
+ @client.query_customer(@test_customer_id)
339
+ }.to raise_error(BigCharger::Error, 'eWAY server responded with "Bad Request" (400)')
340
+ end
341
+ end
342
+ end
343
+
344
+ describe '#query_customer_by_reference' do
345
+ describe 'success scenarios' do
346
+ after(:all) { WebMock.reset! }
347
+
348
+ it 'should make a request to the eWAY endpoint' do
349
+ stub_request(:post, @endpoint)
350
+ .to_return(
351
+ :status => 200,
352
+ :body => message(:query_customer_by_reference_response)
353
+ )
354
+ @client.query_customer_by_reference(@test_customer_ref)
355
+ end
356
+
357
+ it 'should use the correct headers' do
358
+ stub_request(:post, @endpoint)
359
+ .with(:headers => {
360
+ 'SOAPAction' => "#{@namespace}/QueryCustomerByReference",
361
+ 'Content-Type' => 'text/xml'
362
+ })
363
+ @client.query_customer_by_reference(@test_customer_ref)
364
+ end
365
+
366
+ it 'should pass the correct content within the request' do
367
+ stub_request(:post, @endpoint)
368
+ .with(:body => message(:query_customer_by_reference_request))
369
+ @client.query_customer_by_reference(@test_customer_ref)
370
+ end
371
+
372
+ it 'should return the correct response' do
373
+ stub_request(:post, @endpoint)
374
+ .to_return(
375
+ :status => 200,
376
+ :body => message(:query_customer_by_reference_response)
377
+ )
378
+ response = @client.query_customer_by_reference(@test_customer_ref)
379
+
380
+ response['ManagedCustomerID'].should == '9876543211000'
381
+ response['CustomerRef'].should == 'TEST 123'
382
+ response['CustomerTitle'].should == 'Mr.'
383
+ response['CustomerFirstName'].should == 'Jo'
384
+ response['CustomerLastName'].should == 'Smith'
385
+ response['CustomerCompany'].should == 'company'
386
+ response['CustomerJobDesc'].should be_nil
387
+ response['CustomerEmail'].should == 'test@eway.com.au'
388
+ response['CustomerAddress'].should == '15 Dundas Court'
389
+ response['CustomerSuburb'].should == 'phillip'
390
+ response['CustomerState'].should == 'act'
391
+ response['CustomerPostCode'].should == '2606'
392
+ response['CustomerCountry'].should == 'au'
393
+ response['CustomerPhone1'].should == '02111111111'
394
+ response['CustomerPhone2'].should == '04111111111'
395
+ response['CustomerFax'].should == '111122222'
396
+ response['CustomerURL'].should == 'http://eway.com.au'
397
+ response['CustomerComments'].should == 'Comments'
398
+ response['CCName'].should == 'Jo Smith'
399
+ response['CCNumber'].should == '444433XXXXXX1111'
400
+ response['CCExpiryMonth'].should == '08'
401
+ response['CCExpiryYear'].should == '15'
402
+ end
403
+ end
404
+
405
+ describe 'failure scenarios' do
406
+ it 'should raise an error when a fault is returned' do
407
+ stub_request(:post, @endpoint)
408
+ .to_return(
409
+ :status => [500, 'Internal Server Error'],
410
+ :body => message(:fault_response)
411
+ )
412
+ expect {
413
+ @client.query_customer_by_reference(@test_customer_ref)
414
+ }.to raise_error(BigCharger::Error, 'eWAY server responded with "Login failed." (soap:Client)')
415
+ end
416
+
417
+ it 'should raise an error when the server returns a failure response code' do
418
+ stub_request(:post, @endpoint)
419
+ .to_return(
420
+ :status => [400, 'Bad Request']
421
+ )
422
+ expect {
423
+ @client.query_customer_by_reference(@test_customer_ref)
424
+ }.to raise_error(BigCharger::Error, 'eWAY server responded with "Bad Request" (400)')
425
+ end
426
+ end
427
+ end
428
+
429
+ describe '#query_payment' do
430
+ describe 'success scenarios' do
431
+ after(:all) { WebMock.reset! }
432
+
433
+ it 'should make a request to the eWAY endpoint' do
434
+ stub_request(:post, @endpoint)
435
+ .to_return(
436
+ :status => 200,
437
+ :body => message(:query_payment_response)
438
+ )
439
+ @client.query_payment(@test_customer_id)
440
+ end
441
+
442
+ it 'should use the correct headers' do
443
+ stub_request(:post, @endpoint)
444
+ .with(:headers => {
445
+ 'SOAPAction' => "#{@namespace}/QueryPayment",
446
+ 'Content-Type' => 'text/xml'
447
+ })
448
+ @client.query_payment(@test_customer_id)
449
+ end
450
+
451
+ it 'should pass the correct content within the request' do
452
+ stub_request(:post, @endpoint)
453
+ .with(:body => message(:query_payment_request))
454
+ @client.query_payment(@test_customer_id)
455
+ end
456
+
457
+ it 'should return the correct response' do
458
+ stub_request(:post, @endpoint)
459
+ .to_return(
460
+ :status => 200,
461
+ :body => message(:query_payment_response)
462
+ )
463
+ response = @client.query_payment(@test_customer_id)
464
+
465
+ response.size.should == 2
466
+ response[0]['TotalAmount'].should == '1000'
467
+ response[0]['Result'].should == '1'
468
+ response[0]['ResponseText'].should == 'Approved'
469
+ response[0]['TransactionDate'].should == '2012-02-16T00:00:00+11:00'
470
+ response[0]['ewayTrxnNumber'].should == '1'
471
+ response[1]['TotalAmount'].should == '1008'
472
+ response[1]['Result'].should == '1'
473
+ response[1]['ResponseText'].should == 'Approved'
474
+ response[1]['TransactionDate'].should == '2012-02-16T00:00:00+11:00'
475
+ response[1]['ewayTrxnNumber'].should == '2'
476
+ end
477
+ end
478
+
479
+ describe 'failure scenarios' do
480
+ it 'should raise an error when a fault is returned' do
481
+ stub_request(:post, @endpoint)
482
+ .to_return(
483
+ :status => [500, 'Internal Server Error'],
484
+ :body => message(:fault_response)
485
+ )
486
+ expect {
487
+ @client.query_payment(@test_customer_id)
488
+ }.to raise_error(BigCharger::Error, 'eWAY server responded with "Login failed." (soap:Client)')
489
+ end
490
+
491
+ it 'should raise an error when the server returns a failure response code' do
492
+ stub_request(:post, @endpoint)
493
+ .to_return(
494
+ :status => [400, 'Bad Request']
495
+ )
496
+ expect {
497
+ @client.query_payment(@test_customer_id)
498
+ }.to raise_error(BigCharger::Error, 'eWAY server responded with "Bad Request" (400)')
499
+ end
500
+ end
501
+ end
502
+
503
+ describe '#update_customer' do
504
+ before(:all) do
505
+ @customer = {
506
+ 'CustomerRef' => 'Test 123',
507
+ 'Title' => 'Mr.',
508
+ 'FirstName' => 'Jo',
509
+ 'LastName' => 'Smith',
510
+ 'Company' => 'company',
511
+ 'JobDesc' => 'Analyst',
512
+ 'Email' => 'test@eway.com.au',
513
+ 'Address' => '15 Dundas Court',
514
+ 'Suburb' => 'phillip',
515
+ 'State' => 'act',
516
+ 'PostCode' => '2606',
517
+ 'Country' => 'au',
518
+ 'Phone' => '02111111111',
519
+ 'Mobile' => '04111111111',
520
+ 'Fax' => '111122222',
521
+ 'URL' => 'http://eway.com.au',
522
+ 'Comments' => 'Comments',
523
+ 'CCNameOnCard' => 'Jo Smith',
524
+ 'CCNumber' => '444433XXXXXX1111',
525
+ 'CCExpiryMonth' => '08',
526
+ 'CCExpiryYear' => '15'
527
+ }
528
+ end
529
+
530
+ describe 'success scenario' do
531
+ after(:all) { WebMock.reset! }
532
+
533
+ it 'should make a request to the eWAY endpoint' do
534
+ stub_request(:post, @endpoint)
535
+ .to_return(
536
+ :status => 200,
537
+ :body => message(:update_customer_response)
538
+ )
539
+ @client.update_customer(@test_customer_id, @customer)
540
+ end
541
+
542
+ it 'should use the correct headers' do
543
+ stub_request(:post, @endpoint)
544
+ .with(:headers => {
545
+ 'SOAPAction' => "#{@namespace}/UpdateCustomer",
546
+ 'Content-Type' => 'text/xml'
547
+ })
548
+ @client.update_customer(@test_customer_id, @customer)
549
+ end
550
+
551
+ it 'should pass the correct content within the request' do
552
+ stub_request(:post, @endpoint)
553
+ .with(:body => message(:update_customer_request))
554
+ @client.update_customer(@test_customer_id, @customer)
555
+ end
556
+
557
+ it 'should return the correct response' do
558
+ stub_request(:post, @endpoint)
559
+ .to_return(
560
+ :status => 200,
561
+ :body => message(:update_customer_response)
562
+ )
563
+ response = @client.update_customer(@test_customer_id, @customer)
564
+ response.should be_true
565
+ end
566
+ end
567
+
568
+ describe 'failure scenarios' do
569
+ it 'should raise an error when a fault is returned' do
570
+ stub_request(:post, @endpoint)
571
+ .to_return(
572
+ :status => [500, 'Internal Server Error'],
573
+ :body => message(:fault_response)
574
+ )
575
+ expect {
576
+ @client.update_customer(@test_customer_id, @customer)
577
+ }.to raise_error(BigCharger::Error, 'eWAY server responded with "Login failed." (soap:Client)')
578
+ end
579
+
580
+ it 'should raise an error when the server returns a failure response code' do
581
+ stub_request(:post, @endpoint)
582
+ .to_return(
583
+ :status => [400, 'Bad Request']
584
+ )
585
+ expect {
586
+ @client.update_customer(@test_customer_id, @customer)
587
+ }.to raise_error(BigCharger::Error, 'eWAY server responded with "Bad Request" (400)')
588
+ end
589
+ end
590
+ end
591
+ end