buckaruby 1.1.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,10 +2,10 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Buckaruby::Gateway do
5
+ RSpec.describe Buckaruby::Gateway do
6
6
  describe 'initialization' do
7
7
  describe 'bad parameters' do
8
- it 'should raise an exception when creating a new instance with invalid parameters' do
8
+ it 'raises an exception when creating a new instance with invalid parameters' do
9
9
  expect {
10
10
  Buckaruby::Gateway.new
11
11
  }.to raise_error(ArgumentError)
@@ -29,9 +29,20 @@ describe Buckaruby::Gateway do
29
29
 
30
30
  it { expect(subject).to be_an_instance_of(Buckaruby::Gateway) }
31
31
 
32
+ describe '#payment_methods' do
33
+ before do
34
+ stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequestSpecification").to_return(body: File.read("spec/fixtures/responses/specify_transaction_success.txt"))
35
+ end
36
+
37
+ it 'returns the payment methods enabled by Buckaroo and supported by this library' do
38
+ payment_methods = subject.payment_methods
39
+ expect(payment_methods).to eq([Buckaruby::PaymentMethod::IDEAL, Buckaruby::PaymentMethod::VISA])
40
+ end
41
+ end
42
+
32
43
  describe '#issuers' do
33
44
  context 'when no or false parameters are passed' do
34
- it 'should raise an ArgumentError' do
45
+ it 'raises an ArgumentError' do
35
46
  expect { subject.issuers }.to raise_error(ArgumentError)
36
47
  expect { subject.issuers(:wrong) }.to raise_error(ArgumentError)
37
48
  end
@@ -39,18 +50,20 @@ describe Buckaruby::Gateway do
39
50
 
40
51
  context 'when ideal is passed' do
41
52
  let(:issuers) { subject.issuers(Buckaruby::PaymentMethod::IDEAL) }
53
+
42
54
  it { expect(issuers.length).to be > 0 }
43
55
  it { expect(issuers).to include("INGBNL2A" => "ING") }
44
56
  end
45
57
 
46
58
  context 'when ideal processing is passed' do
47
59
  let(:issuers) { subject.issuers(Buckaruby::PaymentMethod::IDEAL_PROCESSING) }
60
+
48
61
  it { expect(issuers.length).to be > 0 }
49
62
  it { expect(issuers).to include("RABONL2U" => "Rabobank") }
50
63
  end
51
64
 
52
65
  context 'when visa, mastercard, maestro, bankcontact, sepa direct debit or paypal is passed' do
53
- it 'should raise an ArgumentError' do
66
+ it 'raises an ArgumentError' do
54
67
  expect { subject.issuers(Buckaruby::PaymentMethod::VISA) }.to raise_error(ArgumentError)
55
68
  expect { subject.issuers(Buckaruby::PaymentMethod::MASTER_CARD) }.to raise_error(ArgumentError)
56
69
  expect { subject.issuers(Buckaruby::PaymentMethod::MAESTRO) }.to raise_error(ArgumentError)
@@ -62,11 +75,11 @@ describe Buckaruby::Gateway do
62
75
  end
63
76
 
64
77
  describe '#setup_transaction' do
65
- before(:each) do
78
+ before do
66
79
  stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequest").to_return(body: File.read("spec/fixtures/responses/setup_transaction_success.txt"))
67
80
  end
68
81
 
69
- it 'should raise an exception when initiating a transaction with missing parameters' do
82
+ it 'raises an exception when initiating a transaction with missing parameters' do
70
83
  expect {
71
84
  subject.setup_transaction(amount: 10)
72
85
  }.to raise_error(ArgumentError)
@@ -84,7 +97,7 @@ describe Buckaruby::Gateway do
84
97
  }.to raise_error(ArgumentError)
85
98
  end
86
99
 
87
- it 'should raise an exception when initiating a transaction with invalid amount' do
100
+ it 'raises an exception when initiating a transaction with invalid amount' do
88
101
  expect {
89
102
  subject.setup_transaction(amount: 0, payment_method: Buckaruby::PaymentMethod::IDEAL, payment_issuer: Buckaruby::Ideal::ISSUERS.keys.first, invoicenumber: "12345", return_url: "http://www.return.url/")
90
103
  }.to raise_error(ArgumentError)
@@ -94,19 +107,19 @@ describe Buckaruby::Gateway do
94
107
  }.to raise_error(ArgumentError)
95
108
  end
96
109
 
97
- it 'should raise an exception when initiating a transaction with invalid payment method' do
110
+ it 'raises an exception when initiating a transaction with invalid payment method' do
98
111
  expect {
99
112
  subject.setup_transaction(amount: 10, payment_method: "abc", payment_issuer: Buckaruby::Ideal::ISSUERS.keys.first, invoicenumber: "12345", return_url: "http://www.return.url/")
100
113
  }.to raise_error(ArgumentError)
101
114
  end
102
115
 
103
- it 'should raise an exception when initiating a transaction with invalid payment issuer' do
116
+ it 'raises an exception when initiating a transaction with invalid payment issuer' do
104
117
  expect {
105
118
  subject.setup_transaction(amount: 10, payment_method: Buckaruby::PaymentMethod::IDEAL, payment_issuer: "abc", invoicenumber: "12345", return_url: "http://www.return.url/")
106
119
  }.to raise_error(ArgumentError)
107
120
  end
108
121
 
109
- it 'should raise a ConnectionException when connection the Buckaroo fails' do
122
+ it 'raises a ConnectionException when connection the Buckaroo fails' do
110
123
  stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequest").to_raise(Errno::ECONNREFUSED)
111
124
 
112
125
  expect {
@@ -114,7 +127,7 @@ describe Buckaruby::Gateway do
114
127
  }.to raise_error(Buckaruby::ConnectionException)
115
128
  end
116
129
 
117
- it 'should raise an InvalidResponseException when Buckaroo returns an invalid response' do
130
+ it 'raises an InvalidResponseException when Buckaroo returns an invalid response' do
118
131
  stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequest").to_return(status: 500)
119
132
 
120
133
  expect {
@@ -122,7 +135,7 @@ describe Buckaruby::Gateway do
122
135
  }.to raise_error(Buckaruby::InvalidResponseException)
123
136
  end
124
137
 
125
- it 'should raise an ApiException when API result Fail is returned' do
138
+ it 'raises an ApiException when API result Fail is returned' do
126
139
  stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequest").to_return(body: "BRQ_APIRESULT=Fail&BRQ_APIERRORMESSAGE=Invalid+request")
127
140
 
128
141
  expect {
@@ -130,60 +143,63 @@ describe Buckaruby::Gateway do
130
143
  }.to raise_error(Buckaruby::ApiException)
131
144
  end
132
145
 
133
- describe 'should initiate a transaction when amount is integer, decimal or string' do
146
+ describe 'initiates a transaction when amount is integer, decimal or string' do
134
147
  context 'when amount is an integer' do
135
148
  let(:response) { subject.setup_transaction(amount: 10, payment_method: Buckaruby::PaymentMethod::IDEAL, payment_issuer: Buckaruby::Ideal::ISSUERS.keys.first, invoicenumber: "12345", return_url: "http://www.return.url/") }
149
+
136
150
  it { expect(response).to be_an_instance_of(Buckaruby::SetupTransactionResponse) }
137
151
  it { expect(response.transaction_id).to eq("41C48B55FA9164E123CC73B1157459E840BE5D24") }
138
- it { expect(response.redirect_url).to be }
152
+ it { expect(response.redirect_url).not_to be nil }
139
153
  end
140
154
 
141
155
  context 'when amount is a decimal' do
142
156
  let(:response) { subject.setup_transaction(amount: 10.50, payment_method: Buckaruby::PaymentMethod::IDEAL, payment_issuer: Buckaruby::Ideal::ISSUERS.keys.first, invoicenumber: "12345", return_url: "http://www.return.url/") }
157
+
143
158
  it { expect(response).to be_an_instance_of(Buckaruby::SetupTransactionResponse) }
144
159
  it { expect(response.transaction_id).to eq("41C48B55FA9164E123CC73B1157459E840BE5D24") }
145
- it { expect(response.redirect_url).to be }
160
+ it { expect(response.redirect_url).not_to be nil }
146
161
  end
147
162
 
148
163
  context 'when amount is a string' do
149
164
  let(:response) { subject.setup_transaction(amount: '10', payment_method: Buckaruby::PaymentMethod::IDEAL, payment_issuer: Buckaruby::Ideal::ISSUERS.keys.first, invoicenumber: "12345", return_url: "http://www.return.url/") }
165
+
150
166
  it { expect(response).to be_an_instance_of(Buckaruby::SetupTransactionResponse) }
151
167
  it { expect(response.transaction_id).to eq("41C48B55FA9164E123CC73B1157459E840BE5D24") }
152
- it { expect(response.redirect_url).to be }
168
+ it { expect(response.redirect_url).not_to be nil }
153
169
  end
154
170
  end
155
171
 
156
- it 'should initiate a transaction for payment method ideal' do
172
+ it 'initiates a transaction for payment method ideal' do
157
173
  response = subject.setup_transaction(amount: 10, payment_method: Buckaruby::PaymentMethod::IDEAL, payment_issuer: Buckaruby::Ideal::ISSUERS.keys.first, invoicenumber: "12345", return_url: "http://www.return.url/")
158
174
  expect(response).to be_an_instance_of(Buckaruby::SetupTransactionResponse)
159
175
  expect(response.transaction_id).to eq("41C48B55FA9164E123CC73B1157459E840BE5D24")
160
176
  expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::PENDING)
161
- expect(response.redirect_url).to be
177
+ expect(response.redirect_url).not_to be nil
162
178
  expect(response.timestamp).to be_an_instance_of(Time)
163
179
  expect(response.to_h).to be_an_instance_of(Hash)
164
180
  end
165
181
 
166
- it 'should initiate a transaction for payment method visa' do
182
+ it 'initiates a transaction for payment method visa' do
167
183
  response = subject.setup_transaction(amount: 10, payment_method: Buckaruby::PaymentMethod::VISA, invoicenumber: "12345", return_url: "http://www.return.url/")
168
184
  expect(response).to be_an_instance_of(Buckaruby::SetupTransactionResponse)
169
185
  expect(response.transaction_id).to eq("41C48B55FA9164E123CC73B1157459E840BE5D24")
170
186
  expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::PENDING)
171
- expect(response.redirect_url).to be
187
+ expect(response.redirect_url).not_to be nil
172
188
  expect(response.timestamp).to be_an_instance_of(Time)
173
189
  expect(response.to_h).to be_an_instance_of(Hash)
174
190
  end
175
191
 
176
- it 'should initiate a transaction for payment method mastercard' do
192
+ it 'initiates a transaction for payment method mastercard' do
177
193
  response = subject.setup_transaction(amount: 10, payment_method: Buckaruby::PaymentMethod::MASTER_CARD, invoicenumber: "12345", return_url: "http://www.return.url/")
178
194
  expect(response).to be_an_instance_of(Buckaruby::SetupTransactionResponse)
179
195
  expect(response.transaction_id).to eq("41C48B55FA9164E123CC73B1157459E840BE5D24")
180
196
  expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::PENDING)
181
- expect(response.redirect_url).to be
197
+ expect(response.redirect_url).not_to be nil
182
198
  expect(response.timestamp).to be_an_instance_of(Time)
183
199
  expect(response.to_h).to be_an_instance_of(Hash)
184
200
  end
185
201
 
186
- it 'should initiate a transaction for payment method sepa direct debit' do
202
+ it 'initiates a transaction for payment method sepa direct debit' do
187
203
  response = subject.setup_transaction(amount: 10, payment_method: Buckaruby::PaymentMethod::SEPA_DIRECT_DEBIT, invoicenumber: "12345", return_url: "http://www.return.url/", account_iban: "NL13TEST0123456789", account_name: "J. Tester", mandate_reference: "00P12345", collect_date: Date.new(2016, 1, 1))
188
204
  expect(response).to be_an_instance_of(Buckaruby::SetupTransactionResponse)
189
205
  expect(response.transaction_id).to eq("41C48B55FA9164E123CC73B1157459E840BE5D24")
@@ -192,23 +208,57 @@ describe Buckaruby::Gateway do
192
208
  expect(response.to_h).to be_an_instance_of(Hash)
193
209
  end
194
210
 
195
- it 'should initiate a transaction for payment method paypal' do
211
+ it 'initiates a transaction for payment method paypal' do
196
212
  response = subject.setup_transaction(amount: 10, payment_method: Buckaruby::PaymentMethod::PAYPAL, invoicenumber: "12345", return_url: "http://www.return.url/")
197
213
  expect(response).to be_an_instance_of(Buckaruby::SetupTransactionResponse)
198
214
  expect(response.transaction_id).to eq("41C48B55FA9164E123CC73B1157459E840BE5D24")
199
215
  expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::PENDING)
200
- expect(response.redirect_url).to be
216
+ expect(response.redirect_url).not_to be nil
201
217
  expect(response.timestamp).to be_an_instance_of(Time)
202
218
  expect(response.to_h).to be_an_instance_of(Hash)
203
219
  end
220
+
221
+ it 'initiates a transaction for payment method sofort' do
222
+ response = subject.setup_transaction(amount: 10, payment_method: Buckaruby::PaymentMethod::SOFORT, invoicenumber: "12345", return_url: "http://www.return.url/")
223
+ expect(response).to be_an_instance_of(Buckaruby::SetupTransactionResponse)
224
+ expect(response.transaction_id).to eq("41C48B55FA9164E123CC73B1157459E840BE5D24")
225
+ expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::PENDING)
226
+ expect(response.redirect_url).not_to be nil
227
+ expect(response.timestamp).to be_an_instance_of(Time)
228
+ expect(response.to_h).to be_an_instance_of(Hash)
229
+ end
230
+
231
+ context 'with custom variables' do
232
+ it 'sends the custom variables with the request' do
233
+ response = subject.setup_transaction(amount: 10, payment_method: Buckaruby::PaymentMethod::IDEAL, payment_issuer: "ABNANL2A", invoicenumber: "12345", return_url: "http://www.return.url/", custom: { foo: :bar, quux: "42" })
234
+ expect(response).to be_an_instance_of(Buckaruby::SetupTransactionResponse)
235
+ expect(response.custom[:foo]).to eq("bar")
236
+ expect(response.custom[:quux]).to eq("42")
237
+
238
+ expect(WebMock).to have_requested(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequest")
239
+ .with(body: "brq_websitekey=12345678&brq_payment_method=ideal&brq_culture=nl-NL&brq_currency=EUR&brq_amount=10.0&brq_invoicenumber=12345&brq_service_ideal_action=Pay&brq_service_ideal_issuer=ABNANL2A&brq_service_ideal_version=2&brq_return=http%3A%2F%2Fwww.return.url%2F&cust_foo=bar&cust_quux=42&add_buckaruby=Buckaruby+#{Buckaruby::VERSION}&brq_signature=93952aef5786f00f62e4aa33597672845b2ac8dd")
240
+ end
241
+ end
242
+
243
+ context 'with additional variables' do
244
+ it 'sends the additional variables with the request' do
245
+ response = subject.setup_transaction(amount: 10, payment_method: Buckaruby::PaymentMethod::IDEAL, payment_issuer: "ABNANL2A", invoicenumber: "12345", return_url: "http://www.return.url/", additional: { myreference: "12345" })
246
+ expect(response).to be_an_instance_of(Buckaruby::SetupTransactionResponse)
247
+ expect(response.additional[:buckaruby]).to eq("1.2.0")
248
+ expect(response.additional[:myreference]).to eq("12345")
249
+
250
+ expect(WebMock).to have_requested(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequest")
251
+ .with(body: "brq_websitekey=12345678&brq_payment_method=ideal&brq_culture=nl-NL&brq_currency=EUR&brq_amount=10.0&brq_invoicenumber=12345&brq_service_ideal_action=Pay&brq_service_ideal_issuer=ABNANL2A&brq_service_ideal_version=2&brq_return=http%3A%2F%2Fwww.return.url%2F&add_myreference=12345&add_buckaruby=Buckaruby+#{Buckaruby::VERSION}&brq_signature=b7332fefcf5a9aeb02b9c242ef52eaad118e2da4")
252
+ end
253
+ end
204
254
  end
205
255
 
206
256
  describe '#recurrent_transaction' do
207
- before(:each) do
257
+ before do
208
258
  stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequest").to_return(body: File.read("spec/fixtures/responses/recurrent_transaction_success.txt"))
209
259
  end
210
260
 
211
- it 'should raise an exception when initiating a recurrent transaction with missing parameters' do
261
+ it 'raises an exception when initiating a recurrent transaction with missing parameters' do
212
262
  expect {
213
263
  subject.recurrent_transaction(amount: 10)
214
264
  }.to raise_error(ArgumentError)
@@ -222,13 +272,13 @@ describe Buckaruby::Gateway do
222
272
  }.to raise_error(ArgumentError)
223
273
  end
224
274
 
225
- it 'should raise an exception when initiating a transaction with invalid payment method' do
275
+ it 'raises an exception when initiating a transaction with invalid payment method' do
226
276
  expect {
227
277
  subject.recurrent_transaction(amount: 10, payment_method: Buckaruby::PaymentMethod::IDEAL, invoicenumber: "12345", transaction_id: "12345")
228
278
  }.to raise_error(ArgumentError)
229
279
  end
230
280
 
231
- it 'should initiate a recurrent transaction for payment method visa' do
281
+ it 'initiates a recurrent transaction for payment method visa' do
232
282
  response = subject.recurrent_transaction(amount: 10, payment_method: Buckaruby::PaymentMethod::VISA, invoicenumber: "12345", transaction_id: "12345")
233
283
  expect(response).to be_an_instance_of(Buckaruby::RecurrentTransactionResponse)
234
284
  expect(response.transaction_id).to eq("41C48B55FA9164E123CC73B1157459E840BE5D24")
@@ -241,20 +291,20 @@ describe Buckaruby::Gateway do
241
291
  end
242
292
 
243
293
  describe '#refundable?' do
244
- it 'should raise an exception when required parameters are missing' do
294
+ it 'raises an exception when required parameters are missing' do
245
295
  expect {
246
296
  subject.refundable?
247
297
  }.to raise_error(ArgumentError)
248
298
  end
249
299
 
250
- it 'should return true when the transaction is refundable' do
300
+ it 'returns true when the transaction is refundable' do
251
301
  stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=RefundInfo").to_return(body: File.read("spec/fixtures/responses/refund_info_success.txt"))
252
302
 
253
303
  response = subject.refundable?(transaction_id: "41C48B55FA9164E123CC73B1157459E840BE5D24")
254
304
  expect(response).to be true
255
305
  end
256
306
 
257
- it 'should return false when the transaction was not found' do
307
+ it 'returns false when the transaction was not found' do
258
308
  stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=RefundInfo").to_return(body: File.read("spec/fixtures/responses/refund_info_error.txt"))
259
309
 
260
310
  response = subject.refundable?(transaction_id: "41C48B55FA9164E123CC73B1157459E840BE5D24")
@@ -263,13 +313,13 @@ describe Buckaruby::Gateway do
263
313
  end
264
314
 
265
315
  describe '#refund_transaction' do
266
- it 'should raise an exception when required parameters are missing' do
316
+ it 'raises an exception when required parameters are missing' do
267
317
  expect {
268
318
  subject.refund_transaction
269
319
  }.to raise_error(ArgumentError)
270
320
  end
271
321
 
272
- it 'should raise an exception when the transaction is not refundable' do
322
+ it 'raises an exception when the transaction is not refundable' do
273
323
  stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=RefundInfo").to_return(body: File.read("spec/fixtures/responses/refund_info_error.txt"))
274
324
 
275
325
  expect {
@@ -277,7 +327,7 @@ describe Buckaruby::Gateway do
277
327
  }.to raise_error(Buckaruby::NonRefundableTransactionException)
278
328
  end
279
329
 
280
- it 'should refund the transaction' do
330
+ it 'refunds the transaction' do
281
331
  stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=RefundInfo").to_return(body: File.read("spec/fixtures/responses/refund_info_success.txt"))
282
332
  stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequest").to_return(body: File.read("spec/fixtures/responses/refund_transaction_success.txt"))
283
333
 
@@ -295,11 +345,11 @@ describe Buckaruby::Gateway do
295
345
  end
296
346
 
297
347
  describe '#status' do
298
- before(:each) do
348
+ before do
299
349
  stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionStatus").to_return(body: File.read("spec/fixtures/responses/status_success.txt"))
300
350
  end
301
351
 
302
- it 'should raise an exception when required parameters are missing' do
352
+ it 'raises an exception when required parameters are missing' do
303
353
  expect {
304
354
  subject.status
305
355
  }.to raise_error(ArgumentError)
@@ -307,7 +357,7 @@ describe Buckaruby::Gateway do
307
357
 
308
358
  it { expect(subject.status(transaction_id: "41C48B55FA9164E123CC73B1157459E840BE5D24")).to be_an_instance_of(Buckaruby::StatusResponse) }
309
359
 
310
- it 'should return transaction status' do
360
+ it 'returns transaction status' do
311
361
  response = subject.status(transaction_id: "41C48B55FA9164E123CC73B1157459E840BE5D24")
312
362
  expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::SUCCESS)
313
363
  expect(response.transaction_type).to eq(Buckaruby::TransactionType::PAYMENT)
@@ -319,7 +369,7 @@ describe Buckaruby::Gateway do
319
369
  expect(response.to_h).to be_an_instance_of(Hash)
320
370
  end
321
371
 
322
- it 'should include account iban, bic and name for an ideal response' do
372
+ it 'includes account iban, bic and name for an ideal response' do
323
373
  response = subject.status(transaction_id: "41C48B55FA9164E123CC73B1157459E840BE5D24")
324
374
  expect(response.account_iban).to eq("NL44RABO0123456789")
325
375
  expect(response.account_bic).to eq("RABONL2U")
@@ -328,20 +378,20 @@ describe Buckaruby::Gateway do
328
378
  end
329
379
 
330
380
  describe '#cancellable?' do
331
- it 'should raise an exception when required parameters are missing' do
381
+ it 'raises an exception when required parameters are missing' do
332
382
  expect {
333
383
  subject.cancellable?
334
384
  }.to raise_error(ArgumentError)
335
385
  end
336
386
 
337
- it 'should return true when the transaction is cancellable' do
387
+ it 'returns true when the transaction is cancellable' do
338
388
  stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionStatus").to_return(body: File.read("spec/fixtures/responses/status_cancellable.txt"))
339
389
 
340
390
  response = subject.cancellable?(transaction_id: "41C48B55FA9164E123CC73B1157459E840BE5D24")
341
391
  expect(response).to be true
342
392
  end
343
393
 
344
- it 'should return false when the transaction is not cancellable' do
394
+ it 'returns false when the transaction is not cancellable' do
345
395
  stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionStatus").to_return(body: File.read("spec/fixtures/responses/status_noncancellable.txt"))
346
396
 
347
397
  response = subject.cancellable?(transaction_id: "41C48B55FA9164E123CC73B1157459E840BE5D24")
@@ -350,13 +400,13 @@ describe Buckaruby::Gateway do
350
400
  end
351
401
 
352
402
  describe '#cancel_transaction' do
353
- it 'should raise an exception when required parameters are missing' do
403
+ it 'raises an exception when required parameters are missing' do
354
404
  expect {
355
405
  subject.cancel_transaction
356
406
  }.to raise_error(ArgumentError)
357
407
  end
358
408
 
359
- it 'should raise an exception when the transaction is not cancellable' do
409
+ it 'raises an exception when the transaction is not cancellable' do
360
410
  stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionStatus").to_return(body: File.read("spec/fixtures/responses/status_noncancellable.txt"))
361
411
 
362
412
  expect {
@@ -364,7 +414,7 @@ describe Buckaruby::Gateway do
364
414
  }.to raise_error(Buckaruby::NonCancellableTransactionException)
365
415
  end
366
416
 
367
- it 'should cancel the transaction' do
417
+ it 'cancels the transaction' do
368
418
  stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionStatus").to_return(body: File.read("spec/fixtures/responses/status_cancellable.txt"))
369
419
  stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=CancelTransaction").to_return(body: File.read("spec/fixtures/responses/cancel_success.txt"))
370
420
 
@@ -373,26 +423,56 @@ describe Buckaruby::Gateway do
373
423
  end
374
424
  end
375
425
 
426
+ describe '#specify_transaction' do
427
+ before do
428
+ stub_request(:post, "https://testcheckout.buckaroo.nl/nvp/?op=TransactionRequestSpecification").to_return(body: File.read("spec/fixtures/responses/specify_transaction_success.txt"))
429
+ end
430
+
431
+ it 'retrieves the specification for setting up a transaction' do
432
+ response = subject.specify_transaction
433
+ expect(response).to be_an_instance_of(Buckaruby::TransactionSpecificationResponse)
434
+
435
+ services = response.services
436
+ expect(services).to be_an_instance_of(Array)
437
+ expect(services.length).to eq(2)
438
+
439
+ service = services.last
440
+ expect(service).to be_an_instance_of(Buckaruby::Support::CaseInsensitiveHash)
441
+ expect(service[:name]).to eq(Buckaruby::PaymentMethod::VISA)
442
+ expect(service[:description]).to eq("Visa")
443
+ expect(service[:version]).to eq("1")
444
+
445
+ currencies = service[:supportedcurrencies]
446
+ expect(currencies).to be_an_instance_of(Array)
447
+ expect(currencies.length).to eq(21)
448
+
449
+ currency = currencies.last
450
+ expect(currency).to be_an_instance_of(Buckaruby::Support::CaseInsensitiveHash)
451
+ expect(currency[:name]).to eq("US Dollar")
452
+ expect(currency[:code]).to eq(Buckaruby::Currency::US_DOLLAR)
453
+ end
454
+ end
455
+
376
456
  describe '#callback' do
377
- it 'should raise an exception when parameters are missing' do
457
+ it 'raises an exception when parameters are missing' do
378
458
  expect {
379
459
  subject.callback
380
460
  }.to raise_error(ArgumentError)
381
461
  end
382
462
 
383
- it 'should raise an exception when parameter is an empty Hash' do
463
+ it 'raises an exception when parameter is an empty Hash' do
384
464
  expect {
385
465
  subject.callback({})
386
466
  }.to raise_error(ArgumentError)
387
467
  end
388
468
 
389
- it 'should raise an exception when parameter is an empty String' do
469
+ it 'raises an exception when parameter is an empty String' do
390
470
  expect {
391
471
  subject.callback("")
392
472
  }.to raise_error(ArgumentError)
393
473
  end
394
474
 
395
- it 'should raise a SignatureException when the signature is invalid' do
475
+ it 'raises a SignatureException when the signature is invalid' do
396
476
  params = File.read("spec/fixtures/responses/callback_invalid_signature.txt")
397
477
 
398
478
  expect {
@@ -400,36 +480,38 @@ describe Buckaruby::Gateway do
400
480
  }.to raise_error(Buckaruby::SignatureException, "Sent signature (abcdefgh1234567890abcdefgh1234567890) doesn't match generated signature (0a74bba15fccd8094f33678c001b44851643876d)")
401
481
  end
402
482
 
403
- it 'should return the status when the signature is valid' do
483
+ it 'returns the status when the signature is valid' do
404
484
  params = File.read("spec/fixtures/responses/callback_valid_signature.txt")
405
485
 
406
486
  response = subject.callback(params)
407
487
  expect(response).to be_an_instance_of(Buckaruby::CallbackResponse)
408
- expect(response.transaction_status).to be
409
- expect(response.transaction_type).to be
410
- expect(response.payment_method).to be
411
- expect(response.payment_id).to be
412
- expect(response.invoicenumber).to be
488
+ expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::SUCCESS)
489
+ expect(response.transaction_type).to eq(Buckaruby::TransactionType::PAYMENT)
490
+ expect(response.payment_method).to eq(Buckaruby::PaymentMethod::IDEAL)
491
+ expect(response.transaction_id).to eq("41C48B55FA9164E123CC73B1157459E840BE5D24")
492
+ expect(response.payment_id).to eq("E86256B2787EE7FF0C33D0D4C6159CD922227B79")
493
+ expect(response.invoicenumber).to eq("12345")
413
494
  expect(response.timestamp).to be_an_instance_of(Time)
414
495
  expect(response.to_h).to be_an_instance_of(Hash)
415
496
  end
416
497
 
417
- it 'should accept a Hash as parameters' do
498
+ it 'accepts a Hash as parameters' do
418
499
  params = { "brq_amount" => "10.00", "brq_currency" => "EUR", "brq_customer_name" => "J. de Tester", "brq_description" => "Test", "brq_invoicenumber" => "12345", "brq_mutationtype" => "Collecting", "brq_payer_hash" => "e02377112efcd30bb7420bb1b9855a3778864572", "brq_payment" => "E86256B2787EE7FF0C33D0D4C6159CD922227B79", "brq_service_ideal_consumerbic" => "RABONL2U", "brq_service_ideal_consumeriban" => "NL44RABO0123456789", "brq_service_ideal_consumerissuer" => "Rabobank", "brq_service_ideal_consumername" => "J. de Tester", "brq_statuscode" => "190", "brq_statuscode_detail" => "S001", "brq_statusmessage" => "Transaction successfully processed", "brq_test" => "true", "brq_timestamp" => "2014-11-05 13:10:42", "brq_transaction_method" => "ideal", "brq_transaction_type" => "C021", "brq_transactions" => "41C48B55FA9164E123CC73B1157459E840BE5D24", "brq_websitekey" => "12345678", "brq_signature" => "0a74bba15fccd8094f33678c001b44851643876d" }
419
500
 
420
501
  response = subject.callback(params)
421
502
  expect(response).to be_an_instance_of(Buckaruby::CallbackResponse)
422
- expect(response.transaction_status).to be
423
- expect(response.transaction_type).to be
424
- expect(response.payment_method).to be
425
- expect(response.payment_id).to be
426
- expect(response.invoicenumber).to be
503
+ expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::SUCCESS)
504
+ expect(response.transaction_type).to eq(Buckaruby::TransactionType::PAYMENT)
505
+ expect(response.payment_method).to eq(Buckaruby::PaymentMethod::IDEAL)
506
+ expect(response.transaction_id).to eq("41C48B55FA9164E123CC73B1157459E840BE5D24")
507
+ expect(response.payment_id).to eq("E86256B2787EE7FF0C33D0D4C6159CD922227B79")
508
+ expect(response.invoicenumber).to eq("12345")
427
509
  expect(response.timestamp).to be_an_instance_of(Time)
428
510
  expect(response.to_h).to be_an_instance_of(Hash)
429
511
  end
430
512
 
431
- context 'payment response' do
432
- it 'should set the success status when payment status is success' do
513
+ context 'when callback is a payment response' do
514
+ it 'sets the success status when payment status is success' do
433
515
  params = File.read("spec/fixtures/responses/callback_payment_success.txt")
434
516
 
435
517
  response = subject.callback(params)
@@ -443,7 +525,7 @@ describe Buckaruby::Gateway do
443
525
  expect(response.to_h).to be_an_instance_of(Hash)
444
526
  end
445
527
 
446
- it 'should set the failed status when payment status is failed' do
528
+ it 'sets the failed status when payment status is failed' do
447
529
  params = File.read("spec/fixtures/responses/callback_payment_failed.txt")
448
530
 
449
531
  response = subject.callback(params)
@@ -457,7 +539,7 @@ describe Buckaruby::Gateway do
457
539
  expect(response.to_h).to be_an_instance_of(Hash)
458
540
  end
459
541
 
460
- it 'should set the rejected status when payment status is rejected' do
542
+ it 'sets the rejected status when payment status is rejected' do
461
543
  params = File.read("spec/fixtures/responses/callback_payment_rejected.txt")
462
544
 
463
545
  response = subject.callback(params)
@@ -471,7 +553,7 @@ describe Buckaruby::Gateway do
471
553
  expect(response.to_h).to be_an_instance_of(Hash)
472
554
  end
473
555
 
474
- it 'should set the cancelled status when payment status is cancelled' do
556
+ it 'sets the cancelled status when payment status is cancelled' do
475
557
  params = File.read("spec/fixtures/responses/callback_payment_cancelled.txt")
476
558
 
477
559
  response = subject.callback(params)
@@ -485,7 +567,7 @@ describe Buckaruby::Gateway do
485
567
  expect(response.to_h).to be_an_instance_of(Hash)
486
568
  end
487
569
 
488
- it 'should set the pending status when payment status is pending' do
570
+ it 'sets the pending status when payment status is pending' do
489
571
  params = File.read("spec/fixtures/responses/callback_payment_pending.txt")
490
572
 
491
573
  response = subject.callback(params)
@@ -499,7 +581,7 @@ describe Buckaruby::Gateway do
499
581
  expect(response.to_h).to be_an_instance_of(Hash)
500
582
  end
501
583
 
502
- it 'should include account iban, bic and name for an ideal response' do
584
+ it 'includes account iban, bic and name for an ideal response' do
503
585
  params = File.read("spec/fixtures/responses/callback_payment_success.txt")
504
586
 
505
587
  response = subject.callback(params)
@@ -513,7 +595,7 @@ describe Buckaruby::Gateway do
513
595
  expect(response.to_h).to be_an_instance_of(Hash)
514
596
  end
515
597
 
516
- it 'should include account iban, name, mandate reference and collect date for a sepa direct debit response' do
598
+ it 'includes account iban, name, mandate reference and collect date for a sepa direct debit response' do
517
599
  params = File.read("spec/fixtures/responses/callback_payment_sepa.txt")
518
600
 
519
601
  response = subject.callback(params)
@@ -531,7 +613,7 @@ describe Buckaruby::Gateway do
531
613
  expect(response.to_h).to be_an_instance_of(Hash)
532
614
  end
533
615
 
534
- it 'should return transaction type payment when cancelling a visa or mastercard transaction (empty transaction type)' do
616
+ it 'returns transaction type payment when cancelling a visa or mastercard transaction (empty transaction type)' do
535
617
  params = File.read("spec/fixtures/responses/callback_payment_empty_transaction_type.txt")
536
618
 
537
619
  response = subject.callback(params)
@@ -542,10 +624,52 @@ describe Buckaruby::Gateway do
542
624
  expect(response.timestamp).to be_an_instance_of(Time)
543
625
  expect(response.to_h).to be_an_instance_of(Hash)
544
626
  end
627
+
628
+ it 'sets the transaction type to payment and payment method to VISA for visa callback' do
629
+ params = File.read("spec/fixtures/responses/callback_payment_visa.txt")
630
+
631
+ response = subject.callback(params)
632
+ expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::SUCCESS)
633
+ expect(response.transaction_type).to eq(Buckaruby::TransactionType::PAYMENT)
634
+ expect(response.payment_method).to eq(Buckaruby::PaymentMethod::VISA)
635
+ expect(response.transaction_id).to eq("41C48B55FA9164E123CC73B1157459E840BE5D24")
636
+ expect(response.payment_id).to eq("E86256B2787EE7FF0C33D0D4C6159CD922227B79")
637
+ expect(response.invoicenumber).to eq("12345")
638
+ expect(response.timestamp).to be_an_instance_of(Time)
639
+ expect(response.to_h).to be_an_instance_of(Hash)
640
+ end
641
+
642
+ it 'sets the transaction type to payment and payment method to American Express for amex callback' do
643
+ params = File.read("spec/fixtures/responses/callback_payment_amex.txt")
644
+
645
+ response = subject.callback(params)
646
+ expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::SUCCESS)
647
+ expect(response.transaction_type).to eq(Buckaruby::TransactionType::PAYMENT)
648
+ expect(response.payment_method).to eq(Buckaruby::PaymentMethod::AMERICAN_EXPRESS)
649
+ expect(response.transaction_id).to eq("41C48B55FA9164E123CC73B1157459E840BE5D24")
650
+ expect(response.payment_id).to eq("E86256B2787EE7FF0C33D0D4C6159CD922227B79")
651
+ expect(response.invoicenumber).to eq("12345")
652
+ expect(response.timestamp).to be_an_instance_of(Time)
653
+ expect(response.to_h).to be_an_instance_of(Hash)
654
+ end
655
+
656
+ it 'sets the transaction type to payment and payment method to Sofrt for sort callback' do
657
+ params = File.read("spec/fixtures/responses/callback_payment_sofort.txt")
658
+
659
+ response = subject.callback(params)
660
+ expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::PENDING)
661
+ expect(response.transaction_type).to eq(Buckaruby::TransactionType::PAYMENT)
662
+ expect(response.payment_method).to eq(Buckaruby::PaymentMethod::SOFORT)
663
+ expect(response.transaction_id).to eq("41C48B55FA9164E123CC73B1157459E840BE5D24")
664
+ expect(response.payment_id).to eq("E86256B2787EE7FF0C33D0D4C6159CD922227B79")
665
+ expect(response.invoicenumber).to eq("12345")
666
+ expect(response.timestamp).to be_an_instance_of(Time)
667
+ expect(response.to_h).to be_an_instance_of(Hash)
668
+ end
545
669
  end
546
670
 
547
- context 'payment recurrent response' do
548
- it 'should recognize a visa payment recurrent response' do
671
+ context 'when callback is a payment recurrent response' do
672
+ it 'recognizes a visa payment recurrent response' do
549
673
  params = File.read("spec/fixtures/responses/callback_recurrent_visa.txt")
550
674
 
551
675
  response = subject.callback(params)
@@ -559,7 +683,7 @@ describe Buckaruby::Gateway do
559
683
  expect(response.to_h).to be_an_instance_of(Hash)
560
684
  end
561
685
 
562
- it 'should recognize a sepa direct debit payment recurrent response' do
686
+ it 'recognizes a sepa direct debit payment recurrent response' do
563
687
  params = File.read("spec/fixtures/responses/callback_recurrent_sepa.txt")
564
688
 
565
689
  response = subject.callback(params)
@@ -574,8 +698,8 @@ describe Buckaruby::Gateway do
574
698
  end
575
699
  end
576
700
 
577
- context 'refund response' do
578
- it 'should recognize an ideal refund response' do
701
+ context 'when callback is a refund response' do
702
+ it 'recognizes an ideal refund response' do
579
703
  params = File.read("spec/fixtures/responses/callback_refund_ideal.txt")
580
704
 
581
705
  response = subject.callback(params)
@@ -590,7 +714,7 @@ describe Buckaruby::Gateway do
590
714
  expect(response.to_h).to be_an_instance_of(Hash)
591
715
  end
592
716
 
593
- it 'should recognize a paypal refund response' do
717
+ it 'recognizes a paypal refund response' do
594
718
  params = File.read("spec/fixtures/responses/callback_refund_paypal.txt")
595
719
 
596
720
  response = subject.callback(params)
@@ -604,10 +728,25 @@ describe Buckaruby::Gateway do
604
728
  expect(response.timestamp).to be_an_instance_of(Time)
605
729
  expect(response.to_h).to be_an_instance_of(Hash)
606
730
  end
731
+
732
+ it 'recognizes an amex refund response' do
733
+ params = File.read("spec/fixtures/responses/callback_refund_amex.txt")
734
+
735
+ response = subject.callback(params)
736
+ expect(response.transaction_status).to eq(Buckaruby::TransactionStatus::SUCCESS)
737
+ expect(response.transaction_type).to eq(Buckaruby::TransactionType::REFUND)
738
+ expect(response.payment_method).to eq(Buckaruby::PaymentMethod::AMERICAN_EXPRESS)
739
+ expect(response.transaction_id).to eq("B51118F58785274E117EFE1BF99D4D50CCB96949")
740
+ expect(response.payment_id).to be nil
741
+ expect(response.invoicenumber).to eq("12345")
742
+ expect(response.refund_transaction_id).to eq("41C48B55FA9164E123CC73B1157459E840BE5D24")
743
+ expect(response.timestamp).to be_an_instance_of(Time)
744
+ expect(response.to_h).to be_an_instance_of(Hash)
745
+ end
607
746
  end
608
747
 
609
- context 'reversal response' do
610
- it 'should recognize a sepa direct debit reversal response' do
748
+ context 'when callback is a reversal response' do
749
+ it 'recognizes a sepa direct debit reversal response' do
611
750
  params = File.read("spec/fixtures/responses/callback_reversal_sepa.txt")
612
751
 
613
752
  response = subject.callback(params)
@@ -622,7 +761,7 @@ describe Buckaruby::Gateway do
622
761
  expect(response.to_h).to be_an_instance_of(Hash)
623
762
  end
624
763
 
625
- it 'should recognize a paypal reversal response' do
764
+ it 'recognizes a paypal reversal response' do
626
765
  params = File.read("spec/fixtures/responses/callback_reversal_paypal.txt")
627
766
 
628
767
  response = subject.callback(params)