fingertips-adyen 0.3.8.20100929 → 0.3.8.20100930
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.
- data/adyen.gemspec +9 -8
- data/lib/adyen/api.rb +169 -22
- data/lib/adyen.rb +1 -1
- data/spec/api_spec.rb +206 -131
- metadata +4 -4
data/adyen.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
|
-
s.name = '
|
3
|
-
s.version = "0.3.8
|
4
|
-
s.date = "2010-09-
|
2
|
+
s.name = 'adyen'
|
3
|
+
s.version = "0.3.8"
|
4
|
+
s.date = "2010-09-23"
|
5
5
|
|
6
6
|
s.summary = "Integrate Adyen payment services in your Ruby on Rails application."
|
7
7
|
s.description = <<-EOS
|
@@ -13,22 +13,23 @@ Gem::Specification.new do |s|
|
|
13
13
|
|
14
14
|
s.authors = ['Willem van Bergen', 'Michel Barbosa', 'Stefan Borsje', 'Eloy Duran']
|
15
15
|
s.email = ['willem@vanbergen.org', 'cicaboo@gmail.com', 'mail@sborsje.nl', 'eloy.de.enige@gmail.com']
|
16
|
-
s.homepage = 'http://
|
16
|
+
s.homepage = 'http://github.com/wvanbergen/adyen/wiki'
|
17
17
|
|
18
18
|
s.add_development_dependency('rake')
|
19
19
|
s.add_development_dependency('rspec', '>= 1.1.4')
|
20
|
-
s.add_development_dependency('git', '>= 1.1.0')
|
21
|
-
s.add_development_dependency('gemcutter')
|
22
20
|
|
23
21
|
# Drop or make runtime dependency.
|
24
22
|
s.add_development_dependency('activerecord')
|
23
|
+
s.add_development_dependency('handsoap')
|
25
24
|
s.add_development_dependency('nokogiri')
|
26
25
|
|
26
|
+
s.requirements << 'Handsoap is required for accessing the SOAP services. See http://github.com/troelskn/handsoap.'
|
27
27
|
s.requirements << 'ActiveRecord is required for storing the notifications in your database.'
|
28
28
|
|
29
29
|
s.rdoc_options << '--title' << s.name << '--main' << 'README.rdoc' << '--line-numbers' << '--inline-source'
|
30
30
|
s.extra_rdoc_files = ['README.rdoc']
|
31
31
|
|
32
|
-
s.files = %w(spec/spec_helper.rb spec/adyen_spec.rb lib/adyen/form.rb .gitignore spec/notification_spec.rb lib/adyen/
|
33
|
-
s.test_files = %w(spec/adyen_spec.rb spec/notification_spec.rb spec/
|
32
|
+
s.files = %w(spec/spec_helper.rb spec/adyen_spec.rb lib/adyen/form.rb .gitignore spec/notification_spec.rb lib/adyen/soap.rb LICENSE spec/soap_spec.rb init.rb adyen.gemspec Rakefile spec/form_spec.rb README.rdoc lib/adyen/notification.rb lib/adyen/formatter.rb tasks/github-gem.rake lib/adyen/encoding.rb TODO lib/adyen/matchers.rb lib/adyen.rb)
|
33
|
+
s.test_files = %w(spec/adyen_spec.rb spec/notification_spec.rb spec/soap_spec.rb spec/form_spec.rb)
|
34
34
|
end
|
35
|
+
|
data/lib/adyen/api.rb
CHANGED
@@ -22,16 +22,19 @@ module Adyen
|
|
22
22
|
# Shortcut methods
|
23
23
|
#
|
24
24
|
|
25
|
-
def self.authorise_payment(params
|
25
|
+
def self.authorise_payment(params)
|
26
26
|
PaymentService.new(params).authorise_payment
|
27
27
|
end
|
28
28
|
|
29
|
-
def self.authorise_recurring_payment(params
|
29
|
+
def self.authorise_recurring_payment(params)
|
30
30
|
PaymentService.new(params).authorise_recurring_payment
|
31
31
|
end
|
32
32
|
|
33
|
-
def self.disable_recurring_contract(
|
34
|
-
RecurringService.new(
|
33
|
+
def self.disable_recurring_contract(shopper_reference, recurring_detail_reference = nil)
|
34
|
+
RecurringService.new({
|
35
|
+
:shopper => { :reference => shopper_reference },
|
36
|
+
:recurring_detail_reference => recurring_detail_reference
|
37
|
+
}).disable
|
35
38
|
end
|
36
39
|
|
37
40
|
# TODO: the rest
|
@@ -44,8 +47,12 @@ module Adyen
|
|
44
47
|
# from http://curl.haxx.se/ca/cacert.pem
|
45
48
|
CACERT = File.expand_path('../../../support/cacert.pem', __FILE__)
|
46
49
|
|
47
|
-
|
48
|
-
|
50
|
+
class << self
|
51
|
+
attr_accessor :stubbed_response
|
52
|
+
|
53
|
+
def endpoint
|
54
|
+
@endpoint ||= URI.parse(const_get('ENDPOINT_URI') % Adyen.environment)
|
55
|
+
end
|
49
56
|
end
|
50
57
|
|
51
58
|
attr_reader :params
|
@@ -55,19 +62,24 @@ module Adyen
|
|
55
62
|
end
|
56
63
|
|
57
64
|
def call_webservice_action(action, data, response_class)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
65
|
+
if response = self.class.stubbed_response
|
66
|
+
self.class.stubbed_response = nil
|
67
|
+
response
|
68
|
+
else
|
69
|
+
endpoint = self.class.endpoint
|
70
|
+
|
71
|
+
post = Net::HTTP::Post.new(endpoint.path, 'Accept' => 'text/xml', 'Content-Type' => 'text/xml; charset=utf-8', 'SOAPAction' => action)
|
72
|
+
post.basic_auth(API.username, API.password)
|
73
|
+
post.body = data
|
74
|
+
|
75
|
+
request = Net::HTTP.new(endpoint.host, endpoint.port)
|
76
|
+
request.use_ssl = true
|
77
|
+
request.ca_file = CACERT
|
78
|
+
request.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
79
|
+
|
80
|
+
request.start do |http|
|
81
|
+
response_class.new(http.request(post))
|
82
|
+
end
|
71
83
|
end
|
72
84
|
end
|
73
85
|
end
|
@@ -179,6 +191,38 @@ module Adyen
|
|
179
191
|
class PaymentService < SimpleSOAPClient
|
180
192
|
ENDPOINT_URI = 'https://pal-%s.adyen.com/pal/servlet/soap/Payment'
|
181
193
|
|
194
|
+
class << self
|
195
|
+
def success_stub
|
196
|
+
http_response = Net::HTTPOK.new('1.1', '200', 'OK')
|
197
|
+
def http_response.body; AUTHORISE_RESPONSE; end
|
198
|
+
AuthorizationResponse.new(http_response)
|
199
|
+
end
|
200
|
+
|
201
|
+
def refused_stub
|
202
|
+
http_response = Net::HTTPOK.new('1.1', '200', 'OK')
|
203
|
+
def http_response.body; AUTHORISATION_REFUSED_RESPONSE; end
|
204
|
+
AuthorizationResponse.new(http_response)
|
205
|
+
end
|
206
|
+
|
207
|
+
def invalid_stub
|
208
|
+
http_response = Net::HTTPOK.new('1.1', '200', 'OK')
|
209
|
+
def http_response.body; AUTHORISATION_REQUEST_INVALID_RESPONSE; end
|
210
|
+
AuthorizationResponse.new(http_response)
|
211
|
+
end
|
212
|
+
|
213
|
+
def stub_success!
|
214
|
+
@stubbed_response = success_stub
|
215
|
+
end
|
216
|
+
|
217
|
+
def stub_refused!
|
218
|
+
@stubbed_response = refused_stub
|
219
|
+
end
|
220
|
+
|
221
|
+
def stub_invalid!
|
222
|
+
@stubbed_response = invalid_stub
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
182
226
|
def authorise_payment
|
183
227
|
make_payment_request(authorise_payment_request_body)
|
184
228
|
end
|
@@ -255,8 +299,12 @@ module Adyen
|
|
255
299
|
!fault_message.nil?
|
256
300
|
end
|
257
301
|
|
258
|
-
def error
|
259
|
-
|
302
|
+
def error(prefix = nil)
|
303
|
+
if error = ERRORS[fault_message]
|
304
|
+
prefix ? ["#{prefix}_#{error[0]}".to_sym, error[1]] : error
|
305
|
+
else
|
306
|
+
[:base, fault_message]
|
307
|
+
end
|
260
308
|
end
|
261
309
|
|
262
310
|
def params
|
@@ -273,7 +321,10 @@ module Adyen
|
|
273
321
|
private
|
274
322
|
|
275
323
|
def fault_message
|
276
|
-
@fault_message ||=
|
324
|
+
@fault_message ||= begin
|
325
|
+
message = xml_querier.text('//soap:Fault/faultstring')
|
326
|
+
message unless message.empty?
|
327
|
+
end
|
277
328
|
end
|
278
329
|
end
|
279
330
|
end
|
@@ -281,6 +332,18 @@ module Adyen
|
|
281
332
|
class RecurringService < SimpleSOAPClient
|
282
333
|
ENDPOINT_URI = 'https://pal-%s.adyen.com/pal/servlet/soap/Recurring'
|
283
334
|
|
335
|
+
class << self
|
336
|
+
def disabled_stub
|
337
|
+
http_response = Net::HTTPOK.new('1.1', '200', 'OK')
|
338
|
+
def http_response.body; DISABLE_RESPONSE % DisableResponse::DISABLED_RESPONSES.first; end
|
339
|
+
DisableResponse.new(http_response)
|
340
|
+
end
|
341
|
+
|
342
|
+
def stub_disabled!
|
343
|
+
@stubbed_response = disabled_stub
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
284
347
|
# TODO: rename to list_details and make shortcut method take the only necessary param
|
285
348
|
def list
|
286
349
|
call_webservice_action('listRecurringDetails', list_request_body, ListResponse)
|
@@ -304,8 +367,16 @@ module Adyen
|
|
304
367
|
end
|
305
368
|
|
306
369
|
class DisableResponse < Response
|
370
|
+
DISABLED_RESPONSES = %w{ [detail-successfully-disabled] [all-details-successfully-disabled] }
|
371
|
+
|
307
372
|
response_attrs :response
|
308
373
|
|
374
|
+
def success?
|
375
|
+
super && DISABLED_RESPONSES.include?(params[:response])
|
376
|
+
end
|
377
|
+
|
378
|
+
alias disabled? success?
|
379
|
+
|
309
380
|
def params
|
310
381
|
@params ||= { :response => xml_querier.text('//recurring:disableResponse/recurring:result/recurring:response') }
|
311
382
|
end
|
@@ -429,6 +500,65 @@ EOS
|
|
429
500
|
:email => ' <payment:shopperEmail>%s</payment:shopperEmail>',
|
430
501
|
:ip => ' <payment:shopperIP>%s</payment:shopperIP>',
|
431
502
|
}
|
503
|
+
|
504
|
+
# Test responses
|
505
|
+
|
506
|
+
AUTHORISE_RESPONSE = <<EOS
|
507
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
508
|
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
509
|
+
<soap:Body>
|
510
|
+
<ns1:authoriseResponse xmlns:ns1="http://payment.services.adyen.com">
|
511
|
+
<ns1:paymentResult>
|
512
|
+
<additionalData xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
|
513
|
+
<authCode xmlns="http://payment.services.adyen.com">1234</authCode>
|
514
|
+
<dccAmount xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
|
515
|
+
<dccSignature xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
|
516
|
+
<fraudResult xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
|
517
|
+
<issuerUrl xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
|
518
|
+
<md xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
|
519
|
+
<paRequest xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
|
520
|
+
<pspReference xmlns="http://payment.services.adyen.com">9876543210987654</pspReference>
|
521
|
+
<refusalReason xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
|
522
|
+
<resultCode xmlns="http://payment.services.adyen.com">Authorised</resultCode>
|
523
|
+
</ns1:paymentResult>
|
524
|
+
</ns1:authoriseResponse>
|
525
|
+
</soap:Body>
|
526
|
+
</soap:Envelope>
|
527
|
+
EOS
|
528
|
+
|
529
|
+
AUTHORISATION_REFUSED_RESPONSE = <<EOS
|
530
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
531
|
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
532
|
+
<soap:Body>
|
533
|
+
<ns1:authoriseResponse xmlns:ns1="http://payment.services.adyen.com">
|
534
|
+
<ns1:paymentResult>
|
535
|
+
<additionalData xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
|
536
|
+
<authCode xmlns="http://payment.services.adyen.com">1234</authCode>
|
537
|
+
<dccAmount xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
|
538
|
+
<dccSignature xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
|
539
|
+
<fraudResult xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
|
540
|
+
<issuerUrl xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
|
541
|
+
<md xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
|
542
|
+
<paRequest xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
|
543
|
+
<pspReference xmlns="http://payment.services.adyen.com">9876543210987654</pspReference>
|
544
|
+
<refusalReason xmlns="http://payment.services.adyen.com">You need to actually own money.</refusalReason>
|
545
|
+
<resultCode xmlns="http://payment.services.adyen.com">Refused</resultCode>
|
546
|
+
</ns1:paymentResult>
|
547
|
+
</ns1:authoriseResponse>
|
548
|
+
</soap:Body>
|
549
|
+
</soap:Envelope>
|
550
|
+
EOS
|
551
|
+
|
552
|
+
AUTHORISATION_REQUEST_INVALID_RESPONSE = <<EOS
|
553
|
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
554
|
+
<soap:Body>
|
555
|
+
<soap:Fault>
|
556
|
+
<faultcode>soap:Server</faultcode>
|
557
|
+
<faultstring>validation 101 Invalid card number</faultstring>
|
558
|
+
</soap:Fault>
|
559
|
+
</soap:Body>
|
560
|
+
</soap:Envelope>
|
561
|
+
EOS
|
432
562
|
end
|
433
563
|
|
434
564
|
class RecurringService
|
@@ -466,6 +596,23 @@ EOS
|
|
466
596
|
|
467
597
|
RECURRING_DETAIL_PARTIAL = <<EOS
|
468
598
|
<recurring:recurringDetailReference>%s</recurring:recurringDetailReference>
|
599
|
+
EOS
|
600
|
+
|
601
|
+
# Test responses
|
602
|
+
|
603
|
+
DISABLE_RESPONSE = <<EOS
|
604
|
+
<?xml version="1.0"?>
|
605
|
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
606
|
+
<soap:Body>
|
607
|
+
<ns1:disableResponse xmlns:ns1="http://recurring.services.adyen.com">
|
608
|
+
<ns1:result>
|
609
|
+
<response xmlns="http://recurring.services.adyen.com">
|
610
|
+
%s
|
611
|
+
</response>
|
612
|
+
</ns1:result>
|
613
|
+
</ns1:disableResponse>
|
614
|
+
</soap:Body>
|
615
|
+
</soap:Envelope>
|
469
616
|
EOS
|
470
617
|
end
|
471
618
|
end
|
data/lib/adyen.rb
CHANGED
@@ -13,7 +13,7 @@ module Adyen
|
|
13
13
|
# Version constant for the Adyen plugin.
|
14
14
|
# DO NOT CHANGE THIS VALUE BY HAND. It will be updated automatically by
|
15
15
|
# the gem:release rake task.
|
16
|
-
VERSION = "0.3.8.
|
16
|
+
VERSION = "0.3.8.20100930"
|
17
17
|
|
18
18
|
# Loads configuration settings from a Hash.
|
19
19
|
#
|
data/spec/api_spec.rb
CHANGED
@@ -285,175 +285,193 @@ describe Adyen::API do
|
|
285
285
|
Adyen::API.authorise_recurring_payment(:reference => 'order-id')
|
286
286
|
end
|
287
287
|
|
288
|
-
it "performs a `disable recurring contract' request" do
|
288
|
+
it "performs a `disable recurring contract' request for all details" do
|
289
289
|
recurring = mock('RecurringService')
|
290
|
-
Adyen::API::RecurringService.should_receive(:new).
|
290
|
+
Adyen::API::RecurringService.should_receive(:new).
|
291
|
+
with(:shopper => { :reference => 'user-id' }, :recurring_detail_reference => nil).
|
292
|
+
and_return(recurring)
|
291
293
|
recurring.should_receive(:disable)
|
292
|
-
Adyen::API.disable_recurring_contract(
|
294
|
+
Adyen::API.disable_recurring_contract('user-id')
|
295
|
+
end
|
296
|
+
|
297
|
+
it "performs a `disable recurring contract' request for a specific detail" do
|
298
|
+
recurring = mock('RecurringService')
|
299
|
+
Adyen::API::RecurringService.should_receive(:new).
|
300
|
+
with(:shopper => { :reference => 'user-id' }, :recurring_detail_reference => 'detail-id').
|
301
|
+
and_return(recurring)
|
302
|
+
recurring.should_receive(:disable)
|
303
|
+
Adyen::API.disable_recurring_contract('user-id', 'detail-id')
|
293
304
|
end
|
294
305
|
end
|
295
306
|
|
296
307
|
describe Adyen::API::PaymentService do
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
:
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
:
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
:
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
#:start_year => ,
|
320
|
-
}
|
308
|
+
before do
|
309
|
+
@params = {
|
310
|
+
:reference => 'order-id',
|
311
|
+
:amount => {
|
312
|
+
:currency => 'EUR',
|
313
|
+
:value => '1234',
|
314
|
+
},
|
315
|
+
:shopper => {
|
316
|
+
:email => 's.hopper@example.com',
|
317
|
+
:reference => 'user-id',
|
318
|
+
:ip => '61.294.12.12',
|
319
|
+
},
|
320
|
+
:card => {
|
321
|
+
:expiry_month => 12,
|
322
|
+
:expiry_year => 2012,
|
323
|
+
:holder_name => 'Simon わくわく Hopper',
|
324
|
+
:number => '4444333322221111',
|
325
|
+
:cvc => '737',
|
326
|
+
# Maestro UK/Solo only
|
327
|
+
#:issue_number => ,
|
328
|
+
#:start_month => ,
|
329
|
+
#:start_year => ,
|
321
330
|
}
|
322
|
-
|
331
|
+
}
|
332
|
+
@payment = Adyen::API::PaymentService.new(@params)
|
333
|
+
end
|
334
|
+
|
335
|
+
describe "authorise_payment_request_body" do
|
336
|
+
before :all do
|
337
|
+
@method = :authorise_payment_request_body
|
323
338
|
end
|
324
339
|
|
325
|
-
|
326
|
-
|
327
|
-
|
340
|
+
it_should_behave_like "payment requests"
|
341
|
+
|
342
|
+
it "includes the creditcard details" do
|
343
|
+
xpath('./payment:card') do |card|
|
344
|
+
# there's no reason why Nokogiri should escape these characters, but as long as they're correct
|
345
|
+
card.text('./payment:holderName').should == 'Simon わくわく Hopper'
|
346
|
+
card.text('./payment:number').should == '4444333322221111'
|
347
|
+
card.text('./payment:cvc').should == '737'
|
348
|
+
card.text('./payment:expiryMonth').should == '12'
|
349
|
+
card.text('./payment:expiryYear').should == '2012'
|
328
350
|
end
|
351
|
+
end
|
329
352
|
|
330
|
-
|
353
|
+
it "formats the creditcard’s expiry month as a two digit number" do
|
354
|
+
@payment.params[:card][:expiry_month] = 6
|
355
|
+
text('./payment:card/payment:expiryMonth').should == '06'
|
356
|
+
end
|
331
357
|
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
358
|
+
it "includes the necessary recurring contract info if the `:recurring' param is truthful" do
|
359
|
+
xpath('./payment:recurring/payment:contract').should be_empty
|
360
|
+
@payment.params[:recurring] = true
|
361
|
+
text('./payment:recurring/payment:contract').should == 'RECURRING'
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
describe "authorise_payment" do
|
366
|
+
before do
|
367
|
+
stub_net_http(AUTHORISE_RESPONSE)
|
368
|
+
@response = @payment.authorise_payment
|
369
|
+
@request, @post = Net::HTTP.posted
|
370
|
+
end
|
371
|
+
|
372
|
+
after do
|
373
|
+
Net::HTTP.stubbing_enabled = false
|
374
|
+
end
|
342
375
|
|
343
|
-
|
344
|
-
|
345
|
-
|
376
|
+
it "posts the body generated for the given parameters" do
|
377
|
+
@post.body.should == @payment.authorise_payment_request_body
|
378
|
+
end
|
379
|
+
|
380
|
+
it "posts to the correct SOAP action" do
|
381
|
+
@post.soap_action.should == 'authorise'
|
382
|
+
end
|
383
|
+
|
384
|
+
for_each_xml_backend do
|
385
|
+
it "returns a hash with parsed response details" do
|
386
|
+
@payment.authorise_payment.params.should == {
|
387
|
+
:psp_reference => '9876543210987654',
|
388
|
+
:result_code => 'Authorised',
|
389
|
+
:auth_code => '1234',
|
390
|
+
:refusal_reason => ''
|
391
|
+
}
|
346
392
|
end
|
393
|
+
end
|
347
394
|
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
395
|
+
it_should_have_shortcut_methods_for_params_on_the_response
|
396
|
+
|
397
|
+
describe "with a authorized response" do
|
398
|
+
it "returns that the request was authorised" do
|
399
|
+
@response.should be_success
|
400
|
+
@response.should be_authorized
|
352
401
|
end
|
353
402
|
end
|
354
403
|
|
355
|
-
describe "
|
404
|
+
describe "with a `declined' response" do
|
356
405
|
before do
|
357
|
-
stub_net_http(
|
406
|
+
stub_net_http(AUTHORISATION_DECLINED_RESPONSE)
|
358
407
|
@response = @payment.authorise_payment
|
359
|
-
@request, @post = Net::HTTP.posted
|
360
408
|
end
|
361
409
|
|
362
|
-
|
363
|
-
|
410
|
+
it "returns that the request was not authorised" do
|
411
|
+
@response.should_not be_success
|
412
|
+
@response.should_not be_authorized
|
364
413
|
end
|
414
|
+
end
|
365
415
|
|
366
|
-
|
367
|
-
|
416
|
+
describe "with a `invalid' response" do
|
417
|
+
before do
|
418
|
+
stub_net_http(AUTHORISE_REQUEST_INVALID_RESPONSE % 'validation 101 Invalid card number')
|
419
|
+
@response = @payment.authorise_payment
|
368
420
|
end
|
369
421
|
|
370
|
-
it "
|
371
|
-
@
|
422
|
+
it "returns that the request was not authorised" do
|
423
|
+
@response.should_not be_success
|
424
|
+
@response.should_not be_authorized
|
372
425
|
end
|
373
426
|
|
374
|
-
|
375
|
-
|
376
|
-
@payment.authorise_payment.params.should == {
|
377
|
-
:psp_reference => '9876543210987654',
|
378
|
-
:result_code => 'Authorised',
|
379
|
-
:auth_code => '1234',
|
380
|
-
:refusal_reason => ''
|
381
|
-
}
|
382
|
-
end
|
427
|
+
it "it returns that the request was invalid" do
|
428
|
+
@response.should be_invalid_request
|
383
429
|
end
|
384
430
|
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
431
|
+
it "returns creditcard validation errors" do
|
432
|
+
[
|
433
|
+
["validation 101 Invalid card number", [:number, 'is not a valid creditcard number']],
|
434
|
+
["validation 103 CVC is not the right length", [:cvc, 'is not the right length']],
|
435
|
+
["validation 128 Card Holder Missing", [:holder_name, 'can’t be blank']],
|
436
|
+
["validation Couldn't parse expiry year", [:expiry_year, 'could not be recognized']],
|
437
|
+
["validation Expiry month should be between 1 and 12 inclusive", [:expiry_month, 'could not be recognized']],
|
438
|
+
].each do |message, error|
|
439
|
+
response_with_fault_message(message).error.should == error
|
391
440
|
end
|
392
441
|
end
|
393
442
|
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
@response = @payment.authorise_payment
|
398
|
-
end
|
399
|
-
|
400
|
-
it "returns that the request was not authorised" do
|
401
|
-
@response.should_not be_success
|
402
|
-
@response.should_not be_authorized
|
403
|
-
end
|
443
|
+
it "returns any other fault messages on `base'" do
|
444
|
+
message = "validation 130 Reference Missing"
|
445
|
+
response_with_fault_message(message).error.should == [:base, message]
|
404
446
|
end
|
405
447
|
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
it "returns that the request was not authorised" do
|
413
|
-
@response.should_not be_success
|
414
|
-
@response.should_not be_authorized
|
415
|
-
end
|
416
|
-
|
417
|
-
it "it returns that the request was invalid" do
|
418
|
-
@response.should be_invalid_request
|
419
|
-
end
|
420
|
-
|
421
|
-
it "returns creditcard validation errors" do
|
422
|
-
[
|
423
|
-
["validation 101 Invalid card number", [:number, 'is not a valid creditcard number']],
|
424
|
-
["validation 103 CVC is not the right length", [:cvc, 'is not the right length']],
|
425
|
-
["validation 128 Card Holder Missing", [:holder_name, 'can’t be blank']],
|
426
|
-
["validation Couldn't parse expiry year", [:expiry_year, 'could not be recognized']],
|
427
|
-
["validation Expiry month should be between 1 and 12 inclusive", [:expiry_month, 'could not be recognized']],
|
428
|
-
].each do |message, error|
|
429
|
-
response_with_fault_message(message).error.should == error
|
430
|
-
end
|
431
|
-
end
|
432
|
-
|
433
|
-
it "returns any other fault messages on `base'" do
|
434
|
-
message = "validation 130 Reference Missing"
|
435
|
-
response_with_fault_message(message).error.should == [:base, message]
|
448
|
+
it "prepends the error attribute with the given prefix, except for :base" do
|
449
|
+
[
|
450
|
+
["validation 101 Invalid card number", [:card_number, 'is not a valid creditcard number']],
|
451
|
+
["validation 130 Reference Missing", [:base, "validation 130 Reference Missing"]],
|
452
|
+
].each do |message, error|
|
453
|
+
response_with_fault_message(message).error(:card).should == error
|
436
454
|
end
|
455
|
+
end
|
437
456
|
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
end
|
457
|
+
it "returns the original message corresponding to the given attribute and message" do
|
458
|
+
[
|
459
|
+
["validation 101 Invalid card number", [:number, 'is not a valid creditcard number']],
|
460
|
+
["validation 103 CVC is not the right length", [:cvc, 'is not the right length']],
|
461
|
+
["validation 128 Card Holder Missing", [:holder_name, 'can’t be blank']],
|
462
|
+
["validation Couldn't parse expiry year", [:expiry_year, 'could not be recognized']],
|
463
|
+
["validation Expiry month should be between 1 and 12 inclusive", [:expiry_month, 'could not be recognized']],
|
464
|
+
["validation 130 Reference Missing", [:base, 'validation 130 Reference Missing']],
|
465
|
+
].each do |expected, attr_and_message|
|
466
|
+
Adyen::API::PaymentService::AuthorizationResponse.original_fault_message_for(*attr_and_message).should == expected
|
449
467
|
end
|
468
|
+
end
|
450
469
|
|
451
|
-
|
470
|
+
private
|
452
471
|
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
end
|
472
|
+
def response_with_fault_message(message)
|
473
|
+
stub_net_http(AUTHORISE_REQUEST_INVALID_RESPONSE % message)
|
474
|
+
@response = @payment.authorise_payment
|
457
475
|
end
|
458
476
|
end
|
459
477
|
|
@@ -520,6 +538,40 @@ describe Adyen::API do
|
|
520
538
|
end
|
521
539
|
end
|
522
540
|
|
541
|
+
describe "test helpers that stub responses" do
|
542
|
+
after do
|
543
|
+
Net::HTTP.stubbing_enabled = false
|
544
|
+
end
|
545
|
+
|
546
|
+
it "returns an `authorized' response" do
|
547
|
+
stub_net_http(AUTHORISATION_DECLINED_RESPONSE)
|
548
|
+
Adyen::API::PaymentService.stub_success!
|
549
|
+
@payment.authorise_payment.should be_authorized
|
550
|
+
|
551
|
+
@payment.authorise_payment.should_not be_authorized
|
552
|
+
end
|
553
|
+
|
554
|
+
it "returns a `refused' response" do
|
555
|
+
stub_net_http(AUTHORISE_RESPONSE)
|
556
|
+
Adyen::API::PaymentService.stub_refused!
|
557
|
+
response = @payment.authorise_payment
|
558
|
+
response.should_not be_authorized
|
559
|
+
response.should_not be_invalid_request
|
560
|
+
|
561
|
+
@payment.authorise_payment.should be_authorized
|
562
|
+
end
|
563
|
+
|
564
|
+
it "returns a `invalid request' response" do
|
565
|
+
stub_net_http(AUTHORISE_RESPONSE)
|
566
|
+
Adyen::API::PaymentService.stub_invalid!
|
567
|
+
response = @payment.authorise_payment
|
568
|
+
response.should_not be_authorized
|
569
|
+
response.should be_invalid_request
|
570
|
+
|
571
|
+
@payment.authorise_payment.should be_authorized
|
572
|
+
end
|
573
|
+
end
|
574
|
+
|
523
575
|
private
|
524
576
|
|
525
577
|
def node_for_current_method
|
@@ -642,7 +694,7 @@ describe Adyen::API do
|
|
642
694
|
|
643
695
|
describe "disable" do
|
644
696
|
before do
|
645
|
-
stub_net_http(DISABLE_RESPONSE)
|
697
|
+
stub_net_http(DISABLE_RESPONSE % '[detail-successfully-disabled]')
|
646
698
|
@response = @recurring.disable
|
647
699
|
@request, @post = Net::HTTP.posted
|
648
700
|
end
|
@@ -659,6 +711,16 @@ describe Adyen::API do
|
|
659
711
|
@post.soap_action.should == 'disable'
|
660
712
|
end
|
661
713
|
|
714
|
+
it "returns whether or not it was disabled" do
|
715
|
+
@response.should be_success
|
716
|
+
@response.should be_disabled
|
717
|
+
|
718
|
+
stub_net_http(DISABLE_RESPONSE % '[all-details-successfully-disabled]')
|
719
|
+
@response = @recurring.disable
|
720
|
+
@response.should be_success
|
721
|
+
@response.should be_disabled
|
722
|
+
end
|
723
|
+
|
662
724
|
for_each_xml_backend do
|
663
725
|
it "returns a hash with parsed response details" do
|
664
726
|
@recurring.disable.params.should == { :response => '[detail-successfully-disabled]' }
|
@@ -668,6 +730,19 @@ describe Adyen::API do
|
|
668
730
|
it_should_have_shortcut_methods_for_params_on_the_response
|
669
731
|
end
|
670
732
|
end
|
733
|
+
|
734
|
+
describe "test helpers that stub responses" do
|
735
|
+
after do
|
736
|
+
Net::HTTP.stubbing_enabled = false
|
737
|
+
end
|
738
|
+
|
739
|
+
it "returns a `disabled' response" do
|
740
|
+
stub_net_http(DISABLE_RESPONSE % 'nope')
|
741
|
+
Adyen::API::RecurringService.stub_disabled!
|
742
|
+
@recurring.disable.should be_disabled
|
743
|
+
@recurring.disable.should_not be_disabled
|
744
|
+
end
|
745
|
+
end
|
671
746
|
end
|
672
747
|
end
|
673
748
|
|
@@ -787,7 +862,7 @@ DISABLE_RESPONSE = <<EOS
|
|
787
862
|
<ns1:disableResponse xmlns:ns1="http://recurring.services.adyen.com">
|
788
863
|
<ns1:result>
|
789
864
|
<response xmlns="http://recurring.services.adyen.com">
|
790
|
-
|
865
|
+
%s
|
791
866
|
</response>
|
792
867
|
</ns1:result>
|
793
868
|
</ns1:disableResponse>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fingertips-adyen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 40201971
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
9
|
- 8
|
10
|
-
-
|
11
|
-
version: 0.3.8.
|
10
|
+
- 20100930
|
11
|
+
version: 0.3.8.20100930
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Willem van Bergen
|
@@ -19,7 +19,7 @@ autorequire:
|
|
19
19
|
bindir: bin
|
20
20
|
cert_chain: []
|
21
21
|
|
22
|
-
date: 2010-09-
|
22
|
+
date: 2010-09-30 00:00:00 +02:00
|
23
23
|
default_executable:
|
24
24
|
dependencies:
|
25
25
|
- !ruby/object:Gem::Dependency
|