adyen 0.3.8 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. data/.gitignore +4 -0
  2. data/.kick +35 -0
  3. data/LICENSE +3 -2
  4. data/README.rdoc +8 -4
  5. data/Rakefile +10 -0
  6. data/TODO +14 -4
  7. data/adyen.gemspec +9 -15
  8. data/lib/adyen.rb +10 -59
  9. data/lib/adyen/api.rb +281 -0
  10. data/lib/adyen/api/cacert.pem +3509 -0
  11. data/lib/adyen/api/payment_service.rb +258 -0
  12. data/lib/adyen/api/recurring_service.rb +126 -0
  13. data/lib/adyen/api/response.rb +54 -0
  14. data/lib/adyen/api/simple_soap_client.rb +118 -0
  15. data/lib/adyen/api/templates/payment_service.rb +103 -0
  16. data/lib/adyen/api/templates/recurring_service.rb +34 -0
  17. data/lib/adyen/api/test_helpers.rb +133 -0
  18. data/lib/adyen/api/xml_querier.rb +94 -0
  19. data/lib/adyen/configuration.rb +139 -0
  20. data/lib/adyen/form.rb +37 -109
  21. data/lib/adyen/formatter.rb +0 -10
  22. data/lib/adyen/matchers.rb +1 -1
  23. data/lib/adyen/notification_generator.rb +30 -0
  24. data/lib/adyen/railtie.rb +13 -0
  25. data/lib/adyen/templates/notification_migration.rb +29 -0
  26. data/lib/adyen/templates/notification_model.rb +70 -0
  27. data/spec/adyen_spec.rb +3 -45
  28. data/spec/api/api_spec.rb +139 -0
  29. data/spec/api/payment_service_spec.rb +439 -0
  30. data/spec/api/recurring_service_spec.rb +105 -0
  31. data/spec/api/response_spec.rb +35 -0
  32. data/spec/api/simple_soap_client_spec.rb +91 -0
  33. data/spec/api/spec_helper.rb +417 -0
  34. data/spec/api/test_helpers_spec.rb +83 -0
  35. data/spec/form_spec.rb +27 -23
  36. data/spec/functional/api_spec.rb +90 -0
  37. data/spec/functional/initializer.rb.sample +3 -0
  38. data/spec/spec_helper.rb +5 -5
  39. data/tasks/github-gem.rake +49 -55
  40. data/yard_extensions.rb +16 -0
  41. metadata +63 -82
  42. data/init.rb +0 -1
  43. data/lib/adyen/notification.rb +0 -151
  44. data/lib/adyen/soap.rb +0 -649
  45. data/spec/notification_spec.rb +0 -97
  46. data/spec/soap_spec.rb +0 -340
@@ -1,97 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Adyen::Notification do
4
-
5
- before(:all) do
6
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
7
-
8
- ActiveRecord::Migration.verbose = false
9
- Adyen::Notification::Migration.up
10
- end
11
-
12
- after(:all) do
13
- Adyen::Notification::Migration.down
14
- end
15
-
16
- describe Adyen::Notification::HttpPost do
17
-
18
- describe 'receiving payment authorization notification' do
19
-
20
- before(:each) do
21
- @request = mock('request')
22
- @request.stub!(:params).and_return({
23
- "merchantAccountCode"=>"FloorPlannerNL", "eventCode"=>"AUTHORISATION",
24
- "paymentMethod"=>"mc", "eventDate"=>"2009-08-10T09:00:08.04Z",
25
- "operations"=>"CANCEL,CAPTURE,REFUND", "merchantReference"=>"4",
26
- "action"=>"process_adyen", "live"=>"false", "controller"=>"payment_notifications",
27
- "value"=>"2500", "success"=>"false", "reason"=>"10676:1111:12/2012",
28
- "originalReference"=>"", "pspReference"=>"8712498948081194", "currency"=>"USD"})
29
-
30
- @notification = Adyen::Notification::HttpPost.log(@request)
31
- end
32
-
33
- after(:each) { @notification.destroy }
34
-
35
- it "should have saved the notification record" do
36
- @notification.should_not be_new_record
37
- end
38
-
39
- it "should be an authorization" do
40
- @notification.should be_authorisation
41
- end
42
-
43
- it "should convert the amount to a bigdecimal" do
44
- @notification.value.should eql(BigDecimal.new('25.00'))
45
- end
46
-
47
- it "should convert live to a boolean" do
48
- @notification.should_not be_live
49
- end
50
-
51
- it "should convert success to a boolean" do
52
- @notification.should_not be_success
53
- end
54
-
55
- it "should not be a successfull authorization" do
56
- @notification.should_not be_successful_authorization
57
- end
58
-
59
- it "should convert the eventDate" do
60
- @notification.event_date.should be_kind_of(Time)
61
- end
62
-
63
- it "should convert the empty original reference to NULL" do
64
- @notification.original_reference.should be_nil
65
- end
66
- end
67
-
68
- context 'duplicate detection' do
69
- before(:each) do
70
-
71
- @fields = { "merchantAccountCode"=>"FloorPlannerNL", "eventCode"=>"AUTHORISATION",
72
- "paymentMethod"=>"mc", "eventDate"=>"2009-08-10T09:00:08.04Z",
73
- "operations"=>"CANCEL,CAPTURE,REFUND", "merchantReference"=>"4",
74
- "action"=>"process_adyen", "live"=>"false", "controller"=>"payment_notifications",
75
- "value"=>"2500", "success"=>"false", "reason"=>"10676:1111:12/2012",
76
- "originalReference"=>"", "pspReference"=>"8712498948081194", "currency"=>"USD"}
77
-
78
- @request = mock('request')
79
- @request.stub!(:params).and_return(@fields)
80
- @notification = Adyen::Notification::HttpPost.log(@request)
81
- end
82
-
83
- after(:each) { @notification.destroy }
84
-
85
- it "should raise an error on a duplicate notification" do
86
- lambda { Adyen::Notification::HttpPost.log(@request) }.should raise_error(ActiveRecord::RecordInvalid)
87
- end
88
-
89
- it "should not raise an error on a when success is set to true" do
90
- second_request = mock('request')
91
- second_request.stub!(:params).and_return(@fields.merge('success' => 'true'))
92
- lambda { Adyen::Notification::HttpPost.log(second_request) }.should_not raise_error
93
- end
94
-
95
- end
96
- end
97
- end
@@ -1,340 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Adyen::SOAP::PaymentService do
4
-
5
- describe '#authorise' do
6
- before(:all) do
7
- setup_mock_driver(<<-XML)
8
- <?xml version="1.0" encoding="UTF-8"?>
9
- <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">
10
- <soap:Body>
11
- <ns1:authoriseResponse xmlns:ns1="http://payment.services.adyen.com">
12
- <ns1:paymentResult>
13
- <additionalData xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
14
- <authCode xmlns="http://payment.services.adyen.com">1234</authCode>
15
- <dccAmount xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
16
- <dccSignature xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
17
- <fraudResult xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
18
- <issuerUrl xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
19
- <md xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
20
- <paRequest xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
21
- <pspReference xmlns="http://payment.services.adyen.com">9876543210987654</pspReference>
22
- <refusalReason xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
23
- <resultCode xmlns="http://payment.services.adyen.com">Authorised</resultCode>
24
- </ns1:paymentResult>
25
- </ns1:authoriseResponse>
26
- </soap:Body>
27
- </soap:Envelope>
28
- XML
29
-
30
- @response = Adyen::SOAP::PaymentService.authorise({
31
- :selected_recurring_detail_reference => '6543210987654321',
32
- :merchant_account => 'YourMerchantAccount',
33
- :currency => 'EUR',
34
- :value => '1000',
35
- :reference => '1234567890123456',
36
- :shopper_email => 'user@example.com',
37
- :shopper_reference => '1'
38
- })
39
- end
40
-
41
- context 'request' do
42
- before(:all) do
43
- @root_node = get_last_request_body.xpath('//payment:authorise/payment:paymentRequest', ns)
44
- end
45
-
46
- it 'should setup a paymentRequest' do
47
- @root_node.should_not be_empty
48
- end
49
-
50
- it 'should provide an selectedRecurringDetailReference' do
51
- @root_node.xpath('./payment:selectedRecurringDetailReference/text()', ns).to_s.should == '6543210987654321'
52
- end
53
-
54
- it 'should provide a merchantAccount' do
55
- @root_node.xpath('./payment:merchantAccount/text()', ns).to_s.should == 'YourMerchantAccount'
56
- end
57
-
58
- it 'should provide a currency' do
59
- @root_node.xpath('./payment:amount/common:currency/text()', ns).to_s.should == 'EUR'
60
- end
61
-
62
- it 'should provide a value' do
63
- @root_node.xpath('./payment:amount/common:value/text()', ns).to_s.should == '1000'
64
- end
65
-
66
- it 'should provide a reference' do
67
- @root_node.xpath('./payment:reference/text()', ns).to_s.should == '1234567890123456'
68
- end
69
-
70
- it 'should provide a shopperEmail' do
71
- @root_node.xpath('./payment:shopperEmail/text()', ns).to_s.should == 'user@example.com'
72
- end
73
-
74
- it 'should provide a shopperReference' do
75
- @root_node.xpath('./payment:shopperReference/text()', ns).to_s.should == '1'
76
- end
77
- end
78
-
79
- context 'response' do
80
- it 'should get a authorised resultcode' do
81
- @response[:result_code].should == 'Authorised'
82
- end
83
-
84
- it 'should get a new psp reference' do
85
- @response[:psp_reference].should == '9876543210987654'
86
- end
87
-
88
- it 'should get an authCode' do
89
- @response[:auth_code].should == '1234'
90
- end
91
- end
92
- end
93
-
94
- describe '#capture' do
95
- before(:all) do
96
- setup_mock_driver(<<-XML)
97
- <?xml version="1.0" encoding="UTF-8"?>
98
- <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">
99
- <soap:Body>
100
- <ns1:captureResponse xmlns:ns1="http://payment.services.adyen.com">
101
- <ns1:captureResult>
102
- <pspReference xmlns="http://payment.services.adyen.com">9876543210987654</pspReference>
103
- <response xmlns="http://payment.services.adyen.com">[capture-received]</response>
104
- </ns1:captureResult>
105
- </ns1:captureResponse>
106
- </soap:Body>
107
- </soap:Envelope>
108
- XML
109
-
110
- @response = Adyen::SOAP::PaymentService.capture({
111
- :merchant_account => 'YourMerchantAccount',
112
- :original_reference => '1234567890123456',
113
- :currency => 'EUR',
114
- :value => '1000'
115
- })
116
- end
117
-
118
- context 'request' do
119
- before(:all) do
120
- @root_node = get_last_request_body.xpath('//payment:capture/payment:modificationRequest', ns)
121
- end
122
-
123
- it 'should setup a modificationRequest' do
124
- @root_node.should_not be_empty
125
- end
126
-
127
- it 'should provide a merchantAccount' do
128
- @root_node.xpath('./payment:merchantAccount/text()', ns).to_s.should == 'YourMerchantAccount'
129
- end
130
-
131
- it 'should provide an originalReference' do
132
- @root_node.xpath('./payment:originalReference/text()', ns).to_s.should == '1234567890123456'
133
- end
134
-
135
- it 'should provide a currency' do
136
- @root_node.xpath('./payment:modificationAmount/common:currency/text()', ns).to_s.should == 'EUR'
137
- end
138
-
139
- it 'should provide a value' do
140
- @root_node.xpath('./payment:modificationAmount/common:value/text()', ns).to_s.should == '1000'
141
- end
142
- end
143
-
144
- context 'response' do
145
- it 'should get a capture-received message' do
146
- @response[:response].should == '[capture-received]'
147
- end
148
-
149
- it 'should get a new psp reference' do
150
- @response[:psp_reference].should == '9876543210987654'
151
- end
152
- end
153
- end
154
-
155
- describe "#cancel" do
156
- before(:all) do
157
- setup_mock_driver(<<-XML)
158
- <?xml version="1.0" encoding="UTF-8"?>
159
- <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">
160
- <soap:Body>
161
- <ns1:cancelResponse xmlns:ns1="http://payment.services.adyen.com">
162
- <ns1:cancelResult>
163
- <pspReference xmlns="http://payment.services.adyen.com">9876543210987654</pspReference>
164
- <response xmlns="http://payment.services.adyen.com">[cancel-received]</response>
165
- </ns1:cancelResult>
166
- </ns1:cancelResponse>
167
- </soap:Body>
168
- </soap:Envelope>
169
- XML
170
-
171
- @response = Adyen::SOAP::PaymentService.cancel({
172
- :merchant_account => 'YourMerchantAccount',
173
- :original_reference => '1234567890123456'
174
- })
175
- end
176
-
177
- context 'request' do
178
- before(:all) do
179
- @root_node = get_last_request_body.xpath('//payment:cancel/payment:modificationRequest', ns)
180
- end
181
-
182
- it 'should setup a modificationRequest' do
183
- @root_node.should_not be_empty
184
- end
185
-
186
- it 'should provide a merchantAccount' do
187
- @root_node.xpath('./payment:merchantAccount/text()', ns).to_s.should == 'YourMerchantAccount'
188
- end
189
-
190
- it 'should provide an originalReference' do
191
- @root_node.xpath('./payment:originalReference/text()', ns).to_s.should == '1234567890123456'
192
- end
193
- end
194
-
195
- context 'response' do
196
- it 'should get a cancel-received message' do
197
- @response[:response].should == '[cancel-received]'
198
- end
199
-
200
- it 'should get a new psp reference' do
201
- @response[:psp_reference].should == '9876543210987654'
202
- end
203
- end
204
- end
205
-
206
- describe "#refund" do
207
- before(:all) do
208
- setup_mock_driver(<<-XML)
209
- <?xml version="1.0" encoding="UTF-8"?>
210
- <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">
211
- <soap:Body>
212
- <ns1:refundResponse xmlns:ns1="http://payment.services.adyen.com">
213
- <ns1:refundResult>
214
- <pspReference xmlns="http://payment.services.adyen.com">9876543210987654</pspReference>
215
- <response xmlns="http://payment.services.adyen.com">[refund-received]</response>
216
- </ns1:refundResult>
217
- </ns1:refundResponse>
218
- </soap:Body>
219
- </soap:Envelope>
220
- XML
221
-
222
- @response = Adyen::SOAP::PaymentService.refund({
223
- :merchant_account => 'YourMerchantAccount',
224
- :currency => 'EUR',
225
- :value => '1000'
226
- })
227
- end
228
-
229
- context 'request' do
230
- before(:all) do
231
- @root_node = get_last_request_body.xpath('//payment:refund/payment:modificationRequest', ns)
232
- end
233
-
234
- it 'should setup a modificationRequest' do
235
- @root_node.should_not be_empty
236
- end
237
-
238
- it 'should provide a merchantAccount' do
239
- @root_node.xpath('./payment:merchantAccount/text()', ns).to_s.should == 'YourMerchantAccount'
240
- end
241
-
242
- it 'should provide a currency' do
243
- @root_node.xpath('./payment:modificationAmount/common:currency/text()', ns).to_s.should == 'EUR'
244
- end
245
-
246
- it 'should provide a value' do
247
- @root_node.xpath('./payment:modificationAmount/common:value/text()', ns).to_s.should == '1000'
248
- end
249
- end
250
-
251
- context 'response' do
252
- it 'should get a refund-received message' do
253
- @response[:response].should == '[refund-received]'
254
- end
255
-
256
- it 'should get a new psp reference' do
257
- @response[:psp_reference].should == '9876543210987654'
258
- end
259
- end
260
- end
261
-
262
- describe "#cancel_or_refund" do
263
- before(:all) do
264
- setup_mock_driver(<<-XML)
265
- <?xml version="1.0" encoding="UTF-8"?>
266
- <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">
267
- <soap:Body>
268
- <ns1:cancelOrRefundResponse xmlns:ns1="http://payment.services.adyen.com">
269
- <ns1:cancelOrRefundResult>
270
- <pspReference xmlns="http://payment.services.adyen.com">9876543210987654</pspReference>
271
- <response xmlns="http://payment.services.adyen.com">[cancelOrRefund-received]</response>
272
- </ns1:cancelOrRefundResult>
273
- </ns1:cancelOrRefundResponse>
274
- </soap:Body>
275
- </soap:Envelope>
276
- XML
277
-
278
- @response = Adyen::SOAP::PaymentService.cancel_or_refund({
279
- :merchant_account => 'YourMerchantAccount',
280
- :original_reference => '1234567890123456'
281
- })
282
- end
283
-
284
- context 'request' do
285
- before(:all) do
286
- @root_node = get_last_request_body.xpath('//payment:cancelOrRefund/payment:modificationRequest', ns)
287
- end
288
-
289
- it 'should setup a modificationRequest' do
290
- @root_node.should_not be_empty
291
- end
292
-
293
- it 'should provide a merchantAccount' do
294
- @root_node.xpath('./payment:merchantAccount/text()', ns).to_s.should == 'YourMerchantAccount'
295
- end
296
-
297
- it 'should provide an originalReference' do
298
- @root_node.xpath('./payment:originalReference/text()', ns).to_s.should == '1234567890123456'
299
- end
300
- end
301
-
302
- context 'response' do
303
- it 'should get a cancelOrRefund-received message' do
304
- @response[:response].should == '[cancelOrRefund-received]'
305
- end
306
-
307
- it 'should get a new psp reference' do
308
- @response[:psp_reference].should == '9876543210987654'
309
- end
310
- end
311
- end
312
-
313
- private
314
-
315
- def setup_mock_driver(content)
316
- Handsoap::Http.drivers[:mock] = Handsoap::Http::Drivers::MockDriver.new({
317
- :status => 200,
318
- :headers => [
319
- 'Date: Sat, 09 Jan 2010 01:14:41 GMT',
320
- 'Server: Apache',
321
- 'Content-Type: text/xml;charset=UTF-8'
322
- ].join("\r\n"),
323
- :content => content.strip
324
- })
325
- Handsoap.http_driver = :mock
326
- end
327
-
328
- def get_last_request_body
329
- Nokogiri::XML::Document.parse(Handsoap::Http.drivers[:mock].last_request.body)
330
- end
331
-
332
- def ns
333
- {
334
- 'payment' => 'http://payment.services.adyen.com',
335
- 'recurring' => 'http://recurring.services.adyen.com',
336
- 'common' => 'http://common.services.adyen.com'
337
- }
338
- end
339
-
340
- end