vaulted_billing 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/LICENSE +19 -0
  2. data/lib/vaulted_billing/gateways/bogus.rb +2 -0
  3. data/lib/vaulted_billing/version.rb +1 -1
  4. data/spec/certification/ipcommerce/README.md +9 -0
  5. data/spec/certification/ipcommerce/TODO.md +1 -0
  6. data/spec/certification/ipcommerce/host_capture_ecommerce.rb +318 -0
  7. data/spec/certification/ipcommerce/ipcommerce_transaction.rb +28 -0
  8. data/spec/certification/ipcommerce/terminal_capture_ecommerce.rb +298 -0
  9. data/spec/config.example.yml +18 -0
  10. data/spec/factories/credit_cards.rb +38 -0
  11. data/spec/factories/customers.rb +7 -0
  12. data/spec/factories/sequences.rb +22 -0
  13. data/spec/fixtures/net/authorize_net_cim/add_customer/failure.yml +38 -0
  14. data/spec/fixtures/net/authorize_net_cim/add_customer/success.yml +39 -0
  15. data/spec/fixtures/net/authorize_net_cim/add_customer_credit_card/failure.yml +83 -0
  16. data/spec/fixtures/net/authorize_net_cim/add_customer_credit_card/success.yml +81 -0
  17. data/spec/fixtures/net/authorize_net_cim/authorize/failure.yml +121 -0
  18. data/spec/fixtures/net/authorize_net_cim/authorize/success.yml +121 -0
  19. data/spec/fixtures/net/authorize_net_cim/capture/failure.yml +161 -0
  20. data/spec/fixtures/net/authorize_net_cim/capture/success.yml +160 -0
  21. data/spec/fixtures/net/authorize_net_cim/purchase/failure.yml +122 -0
  22. data/spec/fixtures/net/authorize_net_cim/purchase/success.yml +122 -0
  23. data/spec/fixtures/net/authorize_net_cim/refund/failure.yml +123 -0
  24. data/spec/fixtures/net/authorize_net_cim/refund/failure_2.yml +43 -0
  25. data/spec/fixtures/net/authorize_net_cim/remove_customer/failure.yml +76 -0
  26. data/spec/fixtures/net/authorize_net_cim/remove_customer/success.yml +75 -0
  27. data/spec/fixtures/net/authorize_net_cim/remove_customer_credit_card/failure.yml +156 -0
  28. data/spec/fixtures/net/authorize_net_cim/remove_customer_credit_card/success.yml +118 -0
  29. data/spec/fixtures/net/authorize_net_cim/update_customer/failure.yml +77 -0
  30. data/spec/fixtures/net/authorize_net_cim/update_customer/success.yml +76 -0
  31. data/spec/fixtures/net/authorize_net_cim/update_customer_credit_card/failure.yml +125 -0
  32. data/spec/fixtures/net/authorize_net_cim/update_customer_credit_card/success.yml +124 -0
  33. data/spec/fixtures/net/authorize_net_cim/void/success.yml +159 -0
  34. data/spec/fixtures/net/ipcommerce/add_customer_credit_card/failure.yml +53 -0
  35. data/spec/fixtures/net/ipcommerce/add_customer_credit_card/success.yml +103 -0
  36. data/spec/fixtures/net/ipcommerce/authorize/existing/failure.yml +51 -0
  37. data/spec/fixtures/net/ipcommerce/authorize/existing/success.yml +105 -0
  38. data/spec/fixtures/net/ipcommerce/authorize/new/avs/bad_format.yml +53 -0
  39. data/spec/fixtures/net/ipcommerce/authorize/new/avs/issuer_not_certified.yml +53 -0
  40. data/spec/fixtures/net/ipcommerce/authorize/new/avs/match.yml +53 -0
  41. data/spec/fixtures/net/ipcommerce/authorize/new/avs/no_match.yml +53 -0
  42. data/spec/fixtures/net/ipcommerce/authorize/new/avs/no_response_from_card_association.yml +53 -0
  43. data/spec/fixtures/net/ipcommerce/authorize/new/avs/not_included.yml +53 -0
  44. data/spec/fixtures/net/ipcommerce/authorize/new/avs/not_sent.yml +53 -0
  45. data/spec/fixtures/net/ipcommerce/authorize/new/avs/not_verified.yml +53 -0
  46. data/spec/fixtures/net/ipcommerce/authorize/new/cvv/invalid.yml +53 -0
  47. data/spec/fixtures/net/ipcommerce/authorize/new/cvv/issuer_not_certified.yml +53 -0
  48. data/spec/fixtures/net/ipcommerce/authorize/new/cvv/no_code_present.yml +53 -0
  49. data/spec/fixtures/net/ipcommerce/authorize/new/cvv/no_match.yml +53 -0
  50. data/spec/fixtures/net/ipcommerce/authorize/new/cvv/no_response.yml +53 -0
  51. data/spec/fixtures/net/ipcommerce/authorize/new/cvv/not_applicable.yml +53 -0
  52. data/spec/fixtures/net/ipcommerce/authorize/new/cvv/not_processed.yml +53 -0
  53. data/spec/fixtures/net/ipcommerce/authorize/new/cvv/should_have_been_present.yml +53 -0
  54. data/spec/fixtures/net/ipcommerce/authorize/new/failure.yml +53 -0
  55. data/spec/fixtures/net/ipcommerce/authorize/new/success.yml +53 -0
  56. data/spec/fixtures/net/ipcommerce/capture/failure.yml +78 -0
  57. data/spec/fixtures/net/ipcommerce/capture/invalid.yml +78 -0
  58. data/spec/fixtures/net/ipcommerce/capture/success.yml +78 -0
  59. data/spec/fixtures/net/ipcommerce/failover.yml +53 -0
  60. data/spec/fixtures/net/ipcommerce/purchase/existing/failure.yml +51 -0
  61. data/spec/fixtures/net/ipcommerce/purchase/existing/success.yml +105 -0
  62. data/spec/fixtures/net/ipcommerce/purchase/new/failure.yml +53 -0
  63. data/spec/fixtures/net/ipcommerce/purchase/new/success.yml +53 -0
  64. data/spec/fixtures/net/ipcommerce/refund/failure.yml +78 -0
  65. data/spec/fixtures/net/ipcommerce/refund/success.yml +80 -0
  66. data/spec/fixtures/net/ipcommerce/update_customer_credit_card/failure.yml +53 -0
  67. data/spec/fixtures/net/ipcommerce/update_customer_credit_card/success.yml +103 -0
  68. data/spec/fixtures/net/ipcommerce/void/failure.yml +78 -0
  69. data/spec/fixtures/net/ipcommerce/void/success.yml +78 -0
  70. data/spec/fixtures/net/nmi_customer_vault/add_customer_credit_card/failure.yml +26 -0
  71. data/spec/fixtures/net/nmi_customer_vault/add_customer_credit_card/success.yml +26 -0
  72. data/spec/fixtures/net/nmi_customer_vault/authorize/decline.yml +51 -0
  73. data/spec/fixtures/net/nmi_customer_vault/authorize/success.yml +51 -0
  74. data/spec/fixtures/net/nmi_customer_vault/capture/failure.yml +76 -0
  75. data/spec/fixtures/net/nmi_customer_vault/capture/success.yml +76 -0
  76. data/spec/fixtures/net/nmi_customer_vault/purchase/decline.yml +51 -0
  77. data/spec/fixtures/net/nmi_customer_vault/purchase/success.yml +51 -0
  78. data/spec/fixtures/net/nmi_customer_vault/refund/failure.yml +101 -0
  79. data/spec/fixtures/net/nmi_customer_vault/remove_customer_credit_card/failure.yml +26 -0
  80. data/spec/fixtures/net/nmi_customer_vault/remove_customer_credit_card/success.yml +51 -0
  81. data/spec/fixtures/net/nmi_customer_vault/update_customer_credit_card/success.yml +51 -0
  82. data/spec/fixtures/net/nmi_customer_vault/void/failure.yml +26 -0
  83. data/spec/fixtures/net/nmi_customer_vault/void/success.yml +76 -0
  84. data/spec/models/vaulted_billing/configuration_spec.rb +62 -0
  85. data/spec/models/vaulted_billing/core_ext/hash_spec.rb +47 -0
  86. data/spec/models/vaulted_billing/credit_card_spec.rb +61 -0
  87. data/spec/models/vaulted_billing/gateway_spec.rb +115 -0
  88. data/spec/models/vaulted_billing/http_spec.rb +154 -0
  89. data/spec/models/vaulted_billing/transaction_spec.rb +60 -0
  90. data/spec/models/vaulted_billing_spec.rb +16 -0
  91. data/spec/requests/authorize_net_cim_spec.rb +506 -0
  92. data/spec/requests/bogus_spec.rb +144 -0
  93. data/spec/requests/ipcommerce_spec.rb +518 -0
  94. data/spec/requests/nmi_customer_vault_spec.rb +390 -0
  95. data/spec/spec_helper.rb +12 -0
  96. data/spec/support/_vaulted_billing.rb +8 -0
  97. data/spec/support/factory_girl.rb +5 -0
  98. data/spec/support/faker.rb +1 -0
  99. data/spec/support/helpers.rb +46 -0
  100. data/spec/support/logging.rb +2 -0
  101. data/spec/support/test_exception.rb +1 -0
  102. data/spec/support/vcr.rb +49 -0
  103. data/spec/support/webmock.rb +7 -0
  104. metadata +312 -37
@@ -0,0 +1,506 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe VaultedBilling::Gateways::AuthorizeNetCim do
4
+ let(:gateway) { VaultedBilling.gateway(:authorize_net_cim).new }
5
+
6
+ it 'uses the correct test uri' do
7
+ gateway.use_test_uri = true
8
+ gateway.uri.to_s.should == 'https://apitest.authorize.net/xml/v1/request.api'
9
+ end
10
+
11
+ it 'uses the correct live uri' do
12
+ gateway.use_test_uri = false
13
+ gateway.uri.to_s.should == 'https://api.authorize.net/xml/v1/request.api'
14
+ end
15
+
16
+ context 'add_customer' do
17
+ context 'with a successful result' do
18
+ use_vcr_cassette 'authorize_net_cim/add_customer/success'
19
+ let(:customer) { Factory.build(:customer) }
20
+ subject { gateway.add_customer(customer) }
21
+ it_should_behave_like 'a customer request'
22
+
23
+ it 'is successful' do
24
+ should be_success
25
+ end
26
+
27
+ its(:response_message) { should == 'Successful.' }
28
+ its(:error_code) { should be_nil }
29
+ end
30
+
31
+ context 'with an unsuccessful result' do
32
+ use_vcr_cassette 'authorize_net_cim/add_customer/failure'
33
+ let(:customer) { VaultedBilling::Customer.new }
34
+ subject { gateway.add_customer(customer) }
35
+
36
+ it 'returns a Customer' do
37
+ subject.should be_kind_of VaultedBilling::Customer
38
+ end
39
+
40
+ it 'is unsuccessful' do
41
+ should_not be_success
42
+ end
43
+
44
+ its(:response_message) { should == 'One or more fields in the profile must contain a value.' }
45
+ its(:error_code) { should == 'E00041' }
46
+ end
47
+
48
+ request_exception_context do
49
+ let(:customer) { VaultedBilling::Customer.new }
50
+ subject { gateway.add_customer(customer) }
51
+ it_should_behave_like 'a failed connection attempt'
52
+ end
53
+ end
54
+
55
+ context 'update_customer' do
56
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
57
+
58
+ context 'with a successful result' do
59
+ use_vcr_cassette 'authorize_net_cim/update_customer/success'
60
+ subject { customer.email = 'updated@example.com'; gateway.update_customer(customer) }
61
+
62
+ it_should_behave_like 'a customer request'
63
+
64
+ it 'returns the given customer' do
65
+ should == customer
66
+ end
67
+
68
+ it 'is successful' do
69
+ should be_success
70
+ end
71
+
72
+ its(:response_message) { should == 'Successful.' }
73
+ its(:error_code) { should be_nil }
74
+ end
75
+
76
+ context 'with an unsuccessful result' do
77
+ use_vcr_cassette 'authorize_net_cim/update_customer/failure'
78
+ subject { customer.vault_id = '1234567890'; gateway.update_customer(customer) }
79
+
80
+ it 'returns a Customer' do
81
+ subject.should be_kind_of VaultedBilling::Customer
82
+ end
83
+
84
+ it 'is unsuccessful' do
85
+ should_not be_success
86
+ end
87
+
88
+ its(:response_message) { should == %|The record cannot be found.| }
89
+ its(:error_code) { should == 'E00040' }
90
+ end
91
+
92
+ request_exception_context do
93
+ subject { customer.vault_id = '1234567890'; gateway.update_customer(customer) }
94
+ it_should_behave_like 'a failed connection attempt'
95
+ end
96
+ end
97
+
98
+ context 'remove_customer' do
99
+ context 'with a successful result' do
100
+ use_vcr_cassette 'authorize_net_cim/remove_customer/success'
101
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
102
+ subject { gateway.remove_customer(customer) }
103
+
104
+ it_should_behave_like 'a customer request'
105
+
106
+ it 'returns the given customer' do
107
+ subject.should == customer
108
+ end
109
+
110
+ it 'is successful' do
111
+ should be_success
112
+ end
113
+ end
114
+
115
+ context 'with an unsuccessful result' do
116
+ use_vcr_cassette 'authorize_net_cim/remove_customer/failure'
117
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
118
+ subject { customer.vault_id = '1234567890'; gateway.remove_customer(customer) }
119
+
120
+ it_should_behave_like 'a customer request'
121
+
122
+ it 'returns the given customer' do
123
+ subject.should == customer
124
+ end
125
+
126
+ it 'is unsuccessful' do
127
+ should_not be_success
128
+ end
129
+ end
130
+
131
+ request_exception_context do
132
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
133
+ subject { customer.vault_id = '1234567890'; gateway.remove_customer(customer) }
134
+ it_should_behave_like 'a failed connection attempt'
135
+ end
136
+ end
137
+
138
+ context 'add_customer_credit_card' do
139
+ context 'with a successful result' do
140
+ use_vcr_cassette 'authorize_net_cim/add_customer_credit_card/success'
141
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
142
+ let(:credit_card) { Factory.build(:credit_card) }
143
+ subject { gateway.add_customer_credit_card(customer, credit_card) }
144
+
145
+ it_should_behave_like 'a credit card request'
146
+
147
+ it 'is successful' do
148
+ should be_success
149
+ end
150
+ end
151
+
152
+ context 'with an unsuccessful result' do
153
+ use_vcr_cassette 'authorize_net_cim/add_customer_credit_card/failure'
154
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
155
+ let(:credit_card) { Factory.build(:credit_card, :card_number => nil) }
156
+ subject { gateway.add_customer_credit_card(customer, credit_card) }
157
+
158
+ it 'returns a credit card' do
159
+ subject.should be_kind_of VaultedBilling::CreditCard
160
+ end
161
+
162
+ it 'is unsuccessful' do
163
+ should_not be_success
164
+ end
165
+ end
166
+
167
+ request_exception_context do
168
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
169
+ let(:credit_card) { Factory.build(:credit_card, :card_number => nil) }
170
+ subject { gateway.add_customer_credit_card(customer, credit_card) }
171
+ it_should_behave_like 'a failed connection attempt'
172
+ end
173
+ end
174
+
175
+ context 'update_customer_credit_card' do
176
+ context 'with a successful result' do
177
+ use_vcr_cassette 'authorize_net_cim/update_customer_credit_card/success'
178
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
179
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
180
+ subject { credit_card.expires_on += 365; gateway.update_customer_credit_card(customer, credit_card) }
181
+
182
+ it_should_behave_like 'a credit card request'
183
+
184
+ it 'returns the given credit card' do
185
+ subject.should == credit_card
186
+ end
187
+
188
+ it 'is successful' do
189
+ should be_success
190
+ end
191
+ end
192
+
193
+ context 'with an unsuccessful result' do
194
+ use_vcr_cassette 'authorize_net_cim/update_customer_credit_card/failure'
195
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
196
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
197
+ subject { credit_card.card_number = '123456'; gateway.update_customer_credit_card(customer, credit_card) }
198
+
199
+ it_should_behave_like 'a credit card request'
200
+
201
+ it 'returns the given credit card' do
202
+ subject.should == credit_card
203
+ end
204
+
205
+ it 'is unsuccessful' do
206
+ should_not be_success
207
+ end
208
+ end
209
+
210
+ request_exception_context do
211
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
212
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
213
+ subject { credit_card.card_number = '123456'; gateway.update_customer_credit_card(customer, credit_card) }
214
+ it_should_behave_like 'a failed connection attempt'
215
+ end
216
+ end
217
+
218
+ context 'remove_customer_credit_card' do
219
+ context 'with a successful result' do
220
+ use_vcr_cassette 'authorize_net_cim/remove_customer_credit_card/success'
221
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
222
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
223
+ subject { gateway.remove_customer_credit_card(customer, credit_card) }
224
+
225
+ it_should_behave_like 'a credit card request'
226
+
227
+ it 'is successful' do
228
+ should be_success
229
+ end
230
+ end
231
+
232
+ context 'with an unsuccessful result' do
233
+ use_vcr_cassette 'authorize_net_cim/remove_customer_credit_card/failure'
234
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
235
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
236
+ subject do
237
+ gateway.remove_customer_credit_card(customer, credit_card)
238
+ gateway.remove_customer_credit_card(customer, credit_card)
239
+ end
240
+
241
+ it_should_behave_like 'a credit card request'
242
+
243
+ it 'is unsuccessful' do
244
+ should_not be_success
245
+ end
246
+ end
247
+
248
+ request_exception_context do
249
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
250
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
251
+ subject do
252
+ gateway.remove_customer_credit_card(customer, credit_card)
253
+ gateway.remove_customer_credit_card(customer, credit_card)
254
+ end
255
+ it_should_behave_like 'a failed connection attempt'
256
+ end
257
+ end
258
+
259
+ context 'authorize' do
260
+ context 'with a successful result' do
261
+ use_vcr_cassette 'authorize_net_cim/authorize/success'
262
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
263
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
264
+ subject { gateway.authorize(customer, credit_card, 10.00) }
265
+
266
+ it_should_behave_like 'a transaction request'
267
+
268
+ it { should be_success }
269
+ its(:masked_card_number) { should be_present }
270
+ end
271
+
272
+ context 'with an unsuccessful result' do
273
+ use_vcr_cassette 'authorize_net_cim/authorize/failure'
274
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
275
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
276
+ subject { gateway.authorize(customer, credit_card, 0.00) }
277
+
278
+ it 'returns a transaction' do
279
+ subject.should be_kind_of VaultedBilling::Transaction
280
+ end
281
+
282
+ it { should_not be_success }
283
+ its(:masked_card_number) { should be_blank }
284
+ its(:message) { should =~ /invalid according to its datatype/ }
285
+ its(:code) { should == 'E00003' }
286
+ end
287
+
288
+ request_exception_context do
289
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
290
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
291
+ subject { gateway.authorize(customer, credit_card, 1.00) }
292
+ it_should_behave_like 'a failed connection attempt'
293
+
294
+ it 'reports a transaction exception' do
295
+ subject.message.should == 'There was a problem communicating with the card processor.'
296
+ end
297
+ end
298
+ end
299
+
300
+ context 'purchase' do
301
+ context 'with a successful result' do
302
+ use_vcr_cassette 'authorize_net_cim/purchase/success'
303
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
304
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
305
+ subject { gateway.purchase(customer, credit_card, 5.00) }
306
+
307
+ it_should_behave_like 'a transaction request'
308
+
309
+ it { should be_success }
310
+ its(:masked_card_number) { should be_present }
311
+ end
312
+
313
+ context 'with an unsuccessful result' do
314
+ use_vcr_cassette 'authorize_net_cim/purchase/failure'
315
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
316
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
317
+ subject { gateway.purchase(customer, credit_card, 0.00) }
318
+
319
+ it 'returns a transaction' do
320
+ subject.should be_kind_of VaultedBilling::Transaction
321
+ end
322
+
323
+ it { should_not be_success }
324
+ its(:masked_card_number) { should be_blank }
325
+ end
326
+
327
+ request_exception_context do
328
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
329
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
330
+ subject { gateway.purchase(customer, credit_card, 1.00) }
331
+ it_should_behave_like 'a failed connection attempt'
332
+
333
+ it 'reports a transaction exception' do
334
+ subject.message.should == 'There was a problem communicating with the card processor.'
335
+ end
336
+ end
337
+ end
338
+
339
+ context 'capture' do
340
+ context 'with a successful result' do
341
+ use_vcr_cassette 'authorize_net_cim/capture/success'
342
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
343
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
344
+ subject do
345
+ auth_transaction = gateway.authorize(customer, credit_card, 10.00)
346
+ gateway.capture(auth_transaction.id, 10.00)
347
+ end
348
+
349
+ it_should_behave_like 'a transaction request'
350
+ it { should be_success }
351
+ its(:masked_card_number) { should be_present }
352
+ end
353
+
354
+ context 'with an unsuccessful result' do
355
+ use_vcr_cassette 'authorize_net_cim/capture/failure'
356
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
357
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
358
+ subject do
359
+ auth_transaction = gateway.authorize(customer, credit_card, 10.00)
360
+ gateway.capture(auth_transaction.id, 11.00)
361
+ end
362
+
363
+ it_should_behave_like 'a transaction request'
364
+ it { should_not be_success }
365
+ its(:masked_card_number) { should be_blank }
366
+ end
367
+
368
+ request_exception_context do
369
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
370
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
371
+ subject do
372
+ auth_transaction = gateway.authorize(customer, credit_card, 10.00)
373
+ gateway.capture(auth_transaction.id, 11.00)
374
+ end
375
+ it_should_behave_like 'a failed connection attempt'
376
+
377
+ it 'reports a transaction exception' do
378
+ subject.message.should == 'There was a problem communicating with the card processor.'
379
+ end
380
+ end
381
+ end
382
+
383
+ context 'refund' do
384
+ context 'with a successful result' do
385
+ before(:each) { pending 'Refund requires a settled transaction to operate against.' }
386
+ subject do
387
+ customer = credit_card = purchase_transaction = nil
388
+
389
+ use_cached_requests(:scope => 'authorize_net_cim/refund/success') do
390
+ customer = gateway.add_customer(Factory.build(:customer))
391
+ credit_card = gateway.add_customer_credit_card(customer, Factory.build(:credit_card))
392
+ purchase_transaction = gateway.purchase(customer, credit_card, 10.00)
393
+ end
394
+
395
+ use_cached_requests(:scope => 'authorize_net_cim/refund/success_2') do
396
+ gateway.refund(purchase_transaction.id, 3.00, :masked_card_number => purchase_transaction.masked_card_number)
397
+ end
398
+ end
399
+
400
+ it_should_behave_like 'a transaction request'
401
+ it { should be_success }
402
+ its(:masked_card_number) { should be_present }
403
+ end
404
+
405
+ context 'with an unsuccessful result' do
406
+ subject do
407
+ customer = credit_card = purchase_transaction = nil
408
+
409
+ use_cached_requests(:scope => 'authorize_net_cim/refund/failure') do
410
+ customer = gateway.add_customer(Factory.build(:customer))
411
+ credit_card = gateway.add_customer_credit_card(customer, Factory.build(:credit_card))
412
+ purchase_transaction = gateway.purchase(customer, credit_card, 10.00)
413
+ end
414
+
415
+ use_cached_requests(:scope => 'authorize_net_cim/refund/failure_2') do
416
+ gateway.refund(purchase_transaction.id, 12.00, :masked_card_number => purchase_transaction.masked_card_number)
417
+ end
418
+ end
419
+
420
+ it_should_behave_like 'a transaction request'
421
+ it { should_not be_success }
422
+ its(:masked_card_number) { should be_present }
423
+ end
424
+
425
+ request_exception_context do
426
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
427
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
428
+ subject do
429
+ gateway.refund('123456', 10.00)
430
+ end
431
+ it_should_behave_like 'a failed connection attempt'
432
+
433
+ it 'reports a transaction exception' do
434
+ subject.message.should == 'There was a problem communicating with the card processor.'
435
+ end
436
+ end
437
+ end
438
+
439
+ context 'void' do
440
+ context 'with a successful result' do
441
+ use_vcr_cassette 'authorize_net_cim/void/success'
442
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
443
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
444
+ subject do
445
+ auth_transaction = gateway.authorize(customer, credit_card, 10.00)
446
+ gateway.void(auth_transaction.id)
447
+ end
448
+
449
+ it_should_behave_like 'a transaction request'
450
+ it { should be_success }
451
+ its(:masked_card_number) { should be_present }
452
+ end
453
+
454
+ context 'with an unsuccessful result' do
455
+ use_vcr_cassette 'authorize_net_cim/void/failure'
456
+ before(:each) { pending 'Figure out how to force an failing VOID request.' }
457
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
458
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
459
+ subject do
460
+ purchase_transaction = gateway.purchase(customer, credit_card, 10.00)
461
+ gateway.void(purchase_transaction.id)
462
+ end
463
+
464
+ it_should_behave_like 'a transaction request'
465
+ it { should_not be_success }
466
+ its(:masked_card_number) { should be_blank }
467
+ end
468
+
469
+ request_exception_context do
470
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
471
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
472
+ subject do
473
+ auth_transaction = gateway.authorize(customer, credit_card, 10.00)
474
+ gateway.void(auth_transaction.id)
475
+ end
476
+ it_should_behave_like 'a failed connection attempt'
477
+
478
+ it 'reports a transaction exception' do
479
+ subject.message.should == 'There was a problem communicating with the card processor.'
480
+ end
481
+ end
482
+ end
483
+
484
+ context 'with raw_options' do
485
+ context 'with a successful result' do
486
+ use_vcr_cassette 'authorize_net_cim/authorize/success'
487
+ let(:gateway) { VaultedBilling.gateway(:authorize_net_cim).new(:username => 'LOGIN', :password => 'PASSWORD', :raw_options => 'x_duplicate_window=3').tap { |g| g.use_test_uri = true } }
488
+ let(:customer) { gateway.add_customer(Factory.build(:customer)) }
489
+ let(:credit_card) { gateway.add_customer_credit_card(customer, Factory.build(:credit_card)) }
490
+
491
+ it 'includes the options in the request' do
492
+ customer
493
+ credit_card
494
+
495
+ http = stub("http")
496
+ http.should_receive(:post).
497
+ with(%r{<extraOptions>x_duplicate_window=3</extraOptions>}m).
498
+ and_raise(TestException)
499
+ gateway.should_receive(:http).
500
+ and_return(http)
501
+ expect { gateway.authorize(customer, credit_card, 10.00) }.
502
+ to raise_error(TestException)
503
+ end
504
+ end
505
+ end
506
+ end