adyen 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.travis.yml +12 -5
- data/CHANGELOG.md +5 -2
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +4 -0
- data/README.md +0 -2
- data/Rakefile +2 -8
- data/adyen.gemspec +4 -5
- data/lib/adyen/api.rb +14 -10
- data/lib/adyen/api/payment_service.rb +35 -4
- data/lib/adyen/api/templates/payment_service.rb +5 -0
- data/lib/adyen/form.rb +1 -1
- data/lib/adyen/hpp/request.rb +8 -6
- data/lib/adyen/rest.rb +21 -8
- data/lib/adyen/rest/client.rb +13 -0
- data/lib/adyen/templates/notification_migration.rb +1 -1
- data/lib/adyen/templates/notification_model.rb +2 -2
- data/lib/adyen/version.rb +1 -1
- data/{spec/functional/api_spec.rb → test/functional/api_test.rb} +38 -33
- data/{spec → test}/functional/initializer.rb.ci +0 -0
- data/{spec → test}/functional/initializer.rb.sample +0 -0
- data/test/helpers/views/hpp.erb +15 -15
- data/test/test_helper.rb +1 -0
- data/{spec/api/api_spec.rb → test/unit/api/api_test.rb} +7 -7
- data/{spec/api/payment_service_spec.rb → test/unit/api/payment_service_test.rb} +149 -117
- data/{spec/api/recurring_service_spec.rb → test/unit/api/recurring_service_test.rb} +49 -46
- data/{spec/api/response_spec.rb → test/unit/api/response_test.rb} +12 -12
- data/{spec/api/simple_soap_client_spec.rb → test/unit/api/simple_soap_client_test.rb} +27 -30
- data/{spec/api/spec_helper.rb → test/unit/api/test_helper.rb} +44 -35
- data/{spec/api/test_helpers_spec.rb → test/unit/api/test_helpers_test.rb} +11 -11
- data/test/{form_test.rb → unit/form_test.rb} +0 -0
- data/test/unit/hpp/request_test.rb +68 -0
- data/test/{hpp → unit/hpp}/signature_test.rb +0 -0
- data/test/{hpp_test.rb → unit/hpp_test.rb} +0 -0
- data/test/{rest → unit/rest}/signature_test.rb +0 -0
- data/test/{rest_list_recurring_details_response_test.rb → unit/rest_list_recurring_details_response_test.rb} +0 -0
- data/test/{rest_request_test.rb → unit/rest_request_test.rb} +0 -0
- data/test/{rest_response_test.rb → unit/rest_response_test.rb} +0 -0
- data/test/{signature_test.rb → unit/signature_test.rb} +0 -0
- data/test/{util_test.rb → unit/util_test.rb} +0 -0
- metadata +53 -61
- data/spec/spec_helper.rb +0 -8
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
require 'api/
|
2
|
+
require 'unit/api/test_helper'
|
3
3
|
require 'date'
|
4
4
|
|
5
5
|
describe Adyen::API::RecurringService do
|
@@ -46,15 +46,15 @@ describe Adyen::API::RecurringService do
|
|
46
46
|
:shopper => [:reference]
|
47
47
|
|
48
48
|
it "includes the merchant account handle" do
|
49
|
-
text('./recurring:merchantAccount').
|
49
|
+
text('./recurring:merchantAccount').must_equal 'SuperShopper'
|
50
50
|
end
|
51
51
|
|
52
|
-
it "includes the shopper
|
53
|
-
text('./recurring:shopperReference').
|
52
|
+
it "includes the shopper's reference" do
|
53
|
+
text('./recurring:shopperReference').must_equal 'user-id'
|
54
54
|
end
|
55
55
|
|
56
56
|
it "includes the type of contract, which is always `RECURRING'" do
|
57
|
-
text('./recurring:recurring/payment:contract').
|
57
|
+
text('./recurring:recurring/payment:contract').must_equal 'RECURRING'
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -104,17 +104,17 @@ describe Adyen::API::RecurringService do
|
|
104
104
|
})
|
105
105
|
|
106
106
|
it "returns an array with just the detail references" do
|
107
|
-
@response.references.
|
107
|
+
@response.references.must_equal %w{ RecurringDetailReference1 RecurringDetailReference2 RecurringDetailReference3 }
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
111
|
describe_response_from :list, LIST_EMPTY_RESPONSE, 'listRecurringDetails' do
|
112
112
|
it "returns an empty hash when there are no details" do
|
113
|
-
@recurring.list.params.
|
113
|
+
@recurring.list.params.must_equal({})
|
114
114
|
end
|
115
115
|
|
116
116
|
it "returns an empty array when there are no references" do
|
117
|
-
@response.references.
|
117
|
+
@response.references.must_equal []
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
@@ -123,29 +123,32 @@ describe Adyen::API::RecurringService do
|
|
123
123
|
:shopper => [:reference]
|
124
124
|
|
125
125
|
it "includes the merchant account handle" do
|
126
|
-
text('./recurring:merchantAccount').
|
126
|
+
text('./recurring:merchantAccount').must_equal 'SuperShopper'
|
127
127
|
end
|
128
128
|
|
129
|
-
it "includes the shopper
|
130
|
-
text('./recurring:shopperReference').
|
129
|
+
it "includes the shopper's reference" do
|
130
|
+
text('./recurring:shopperReference').must_equal 'user-id'
|
131
131
|
end
|
132
132
|
|
133
|
-
it "
|
134
|
-
xpath('./recurring:recurringDetailReference').
|
133
|
+
it "does not provide a recurring details reference by default" do
|
134
|
+
xpath('./recurring:recurringDetailReference').must_be :empty?
|
135
|
+
end
|
136
|
+
|
137
|
+
it "includes the shopper's recurring detail reference if it is given" do
|
135
138
|
@recurring.params[:recurring_detail_reference] = 'RecurringDetailReference1'
|
136
|
-
text('./recurring:recurringDetailReference').
|
139
|
+
text('./recurring:recurringDetailReference').must_equal 'RecurringDetailReference1'
|
137
140
|
end
|
138
141
|
end
|
139
142
|
|
140
143
|
describe_response_from :disable, (DISABLE_RESPONSE % '[detail-successfully-disabled]'), 'disable' do
|
141
144
|
it "returns whether or not it was disabled" do
|
142
|
-
@response.
|
143
|
-
@response.
|
145
|
+
@response.must_be :success?
|
146
|
+
@response.must_be :disabled?
|
144
147
|
|
145
148
|
stub_net_http(DISABLE_RESPONSE % '[all-details-successfully-disabled]')
|
146
149
|
@response = @recurring.disable
|
147
|
-
@response.
|
148
|
-
@response.
|
150
|
+
@response.must_be :success?
|
151
|
+
@response.must_be :disabled?
|
149
152
|
end
|
150
153
|
|
151
154
|
it_should_return_params_for_each_xml_backend(:response => '[detail-successfully-disabled]')
|
@@ -156,35 +159,35 @@ describe Adyen::API::RecurringService do
|
|
156
159
|
:shopper => [:email, :reference]
|
157
160
|
|
158
161
|
it "includes the merchant account handle" do
|
159
|
-
text('./recurring:merchantAccount').
|
162
|
+
text('./recurring:merchantAccount').must_equal 'SuperShopper'
|
160
163
|
end
|
161
164
|
|
162
|
-
it "includes the shopper
|
163
|
-
text('./recurring:shopperReference').
|
165
|
+
it "includes the shopper's reference" do
|
166
|
+
text('./recurring:shopperReference').must_equal 'user-id'
|
164
167
|
end
|
165
168
|
|
166
|
-
it "includes the shopper
|
167
|
-
text('./recurring:shopperEmail').
|
169
|
+
it "includes the shopper's email" do
|
170
|
+
text('./recurring:shopperEmail').must_equal 's.hopper@example.com'
|
168
171
|
end
|
169
172
|
|
170
173
|
it "includes the creditcard details" do
|
171
174
|
xpath('./recurring:card') do |card|
|
172
175
|
# there's no reason why Nokogiri should escape these characters, but as long as they're correct
|
173
|
-
card.text('./payment:holderName').
|
174
|
-
card.text('./payment:number').
|
175
|
-
card.text('./payment:cvc').
|
176
|
-
card.text('./payment:expiryMonth').
|
177
|
-
card.text('./payment:expiryYear').
|
176
|
+
card.text('./payment:holderName').must_equal 'Simon わくわく Hopper'
|
177
|
+
card.text('./payment:number').must_equal '4444333322221111'
|
178
|
+
card.text('./payment:cvc').must_equal '737'
|
179
|
+
card.text('./payment:expiryMonth').must_equal '12'
|
180
|
+
card.text('./payment:expiryYear').must_equal '2012'
|
178
181
|
end
|
179
182
|
end
|
180
183
|
|
181
|
-
it "formats the creditcard
|
184
|
+
it "formats the creditcard's expiry month as a two digit number" do
|
182
185
|
@recurring.params[:card][:expiry_month] = 6
|
183
|
-
text('./recurring:card/payment:expiryMonth').
|
186
|
+
text('./recurring:card/payment:expiryMonth').must_equal '06'
|
184
187
|
end
|
185
188
|
|
186
189
|
it "includes the necessary recurring and one-click contract info if the `:recurring' param is truthful" do
|
187
|
-
text('./recurring:recurring/payment:contract').
|
190
|
+
text('./recurring:recurring/payment:contract').must_equal 'RECURRING'
|
188
191
|
end
|
189
192
|
end
|
190
193
|
|
@@ -193,42 +196,42 @@ describe Adyen::API::RecurringService do
|
|
193
196
|
:shopper => [:email, :reference]
|
194
197
|
|
195
198
|
it "includes the merchant account handle" do
|
196
|
-
text('./recurring:merchantAccount').
|
199
|
+
text('./recurring:merchantAccount').must_equal 'SuperShopper'
|
197
200
|
end
|
198
201
|
|
199
|
-
it "includes the shopper
|
200
|
-
text('./recurring:shopperReference').
|
202
|
+
it "includes the shopper's reference" do
|
203
|
+
text('./recurring:shopperReference').must_equal 'user-id'
|
201
204
|
end
|
202
205
|
|
203
|
-
it "includes the shopper
|
204
|
-
text('./recurring:shopperEmail').
|
206
|
+
it "includes the shopper's email" do
|
207
|
+
text('./recurring:shopperEmail').must_equal 's.hopper@example.com'
|
205
208
|
end
|
206
209
|
|
207
210
|
it "includes the ELV details" do
|
208
211
|
xpath('./recurring:elv') do |elv|
|
209
212
|
# there's no reason why Nokogiri should escape these characters, but as long as they're correct
|
210
|
-
elv.text('./payment:accountHolderName').
|
211
|
-
elv.text('./payment:bankAccountNumber').
|
212
|
-
elv.text('./payment:bankLocation').
|
213
|
-
elv.text('./payment:bankLocationId').
|
214
|
-
elv.text('./payment:bankName').
|
213
|
+
elv.text('./payment:accountHolderName').must_equal 'Simon わくわく Hopper'
|
214
|
+
elv.text('./payment:bankAccountNumber').must_equal '1234567890'
|
215
|
+
elv.text('./payment:bankLocation').must_equal 'Berlin'
|
216
|
+
elv.text('./payment:bankLocationId').must_equal '12345678'
|
217
|
+
elv.text('./payment:bankName').must_equal 'TestBank'
|
215
218
|
end
|
216
219
|
end
|
217
220
|
|
218
221
|
it "includes the necessary recurring and one-click contract info if the `:recurring' param is truthful" do
|
219
|
-
text('./recurring:recurring/payment:contract').
|
222
|
+
text('./recurring:recurring/payment:contract').must_equal 'RECURRING'
|
220
223
|
end
|
221
224
|
end
|
222
225
|
|
223
226
|
describe_response_from :disable, (DISABLE_RESPONSE % '[detail-successfully-disabled]'), 'disable' do
|
224
227
|
it "returns whether or not it was disabled" do
|
225
|
-
@response.
|
226
|
-
@response.
|
228
|
+
@response.must_be :success?
|
229
|
+
@response.must_be :disabled?
|
227
230
|
|
228
231
|
stub_net_http(DISABLE_RESPONSE % '[all-details-successfully-disabled]')
|
229
232
|
@response = @recurring.disable
|
230
|
-
@response.
|
231
|
-
@response.
|
233
|
+
@response.must_be :success?
|
234
|
+
@response.must_be :disabled?
|
232
235
|
end
|
233
236
|
|
234
237
|
it_should_return_params_for_each_xml_backend(:response => '[detail-successfully-disabled]')
|
@@ -1,23 +1,23 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
require 'api/
|
2
|
+
require 'unit/api/test_helper'
|
3
3
|
|
4
4
|
describe Adyen::API::Response do
|
5
5
|
before do
|
6
6
|
http_response = Net::HTTPOK.new('1.1', '200', 'OK')
|
7
7
|
http_response.add_field('Content-type', 'text/xml')
|
8
|
-
http_response.
|
8
|
+
http_response.stubs(:body).returns(AUTHORISE_RESPONSE)
|
9
9
|
@response = Adyen::API::Response.new(http_response)
|
10
10
|
end
|
11
11
|
|
12
12
|
it "returns a XMLQuerier instance with the response body" do
|
13
|
-
@response.xml_querier.
|
14
|
-
@response.xml_querier.to_s.rstrip.
|
13
|
+
@response.xml_querier.must_be_instance_of(Adyen::API::XMLQuerier)
|
14
|
+
@response.xml_querier.to_s.rstrip.must_equal AUTHORISE_RESPONSE.rstrip
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "with a successful HTTP response" do
|
18
18
|
it "returns that the (HTTP) request was a success" do
|
19
|
-
@response.
|
20
|
-
@response.
|
19
|
+
@response.wont_be :http_failure?
|
20
|
+
@response.must_be :success?
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -28,32 +28,32 @@ describe Adyen::API::Response do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "returns that the (HTTP) request was not a success" do
|
31
|
-
@response.
|
32
|
-
@response.
|
31
|
+
@response.must_be :http_failure?
|
32
|
+
@response.wont_be :success?
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
describe "with a server error HTTP response and _no_ SOAP fault message" do
|
37
37
|
before do
|
38
38
|
http_response = Net::HTTPServerError.new('1.1', '500', 'Internal Server Error')
|
39
|
-
http_response.
|
39
|
+
http_response.stubs(:body).returns(%{<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"><soap:Body></soap:Body></soap:Envelope>})
|
40
40
|
@response = Adyen::API::Response.new(http_response)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "`server_error?` returns that the (HTTP) request did cause a server error" do
|
44
|
-
@response.server_error
|
44
|
+
@response.must_be :server_error?
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
describe "with a server error HTTP response _and_ SOAP fault message" do
|
49
49
|
before do
|
50
50
|
http_response = Net::HTTPServerError.new('1.1', '500', 'Internal Server Error')
|
51
|
-
http_response.
|
51
|
+
http_response.stubs(:body).returns(%{<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"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Illegal argument. For input string: "100.0"</faultstring></soap:Fault></soap:Body></soap:Envelope>})
|
52
52
|
@response = Adyen::API::Response.new(http_response)
|
53
53
|
end
|
54
54
|
|
55
55
|
it "`server_error?` returns that the (HTTP) request did not cause a server error" do
|
56
|
-
@response.server_error
|
56
|
+
@response.wont_be :server_error?
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
require 'api/
|
2
|
+
require 'unit/api/test_helper'
|
3
3
|
|
4
4
|
module APISpecHelper
|
5
5
|
class SOAPClient < Adyen::API::SimpleSOAPClient
|
@@ -16,17 +16,17 @@ describe Adyen::API::SimpleSOAPClient do
|
|
16
16
|
|
17
17
|
it "returns the endpoint, for the current environment, from the ENDPOINT_URI constant" do
|
18
18
|
uri = APISpecHelper::SOAPClient.endpoint
|
19
|
-
uri.scheme.
|
20
|
-
uri.host.
|
21
|
-
uri.path.
|
19
|
+
uri.scheme.must_equal 'https'
|
20
|
+
uri.host.must_equal 'test.example.com'
|
21
|
+
uri.path.must_equal '/soap/Action'
|
22
22
|
end
|
23
23
|
|
24
24
|
it "initializes with the given parameters" do
|
25
|
-
@client.params[:reference].
|
25
|
+
@client.params[:reference].must_equal 'order-id'
|
26
26
|
end
|
27
27
|
|
28
28
|
it "merges the default parameters with the given ones" do
|
29
|
-
@client.params[:merchant_account].
|
29
|
+
@client.params[:merchant_account].must_equal 'SuperShopper'
|
30
30
|
end
|
31
31
|
|
32
32
|
describe "call_webservice_action" do
|
@@ -42,38 +42,36 @@ describe Adyen::API::SimpleSOAPClient do
|
|
42
42
|
|
43
43
|
it "posts to the class's endpoint" do
|
44
44
|
endpoint = APISpecHelper::SOAPClient.endpoint
|
45
|
-
@request.host.
|
46
|
-
@request.port.
|
47
|
-
@post.path.
|
45
|
+
@request.host.must_equal endpoint.host
|
46
|
+
@request.port.must_equal endpoint.port
|
47
|
+
@post.path.must_equal endpoint.path
|
48
48
|
end
|
49
49
|
|
50
50
|
it "makes a request over SSL" do
|
51
|
-
@request.use_ssl
|
51
|
+
@request.must_be :use_ssl?
|
52
52
|
end
|
53
53
|
|
54
54
|
it "verifies certificates" do
|
55
|
-
File.
|
56
|
-
@request.ca_file.
|
57
|
-
@request.verify_mode.
|
55
|
+
File.must_be :exist?, Adyen::API::SimpleSOAPClient::CACERT
|
56
|
+
@request.ca_file.must_equal Adyen::API::SimpleSOAPClient::CACERT
|
57
|
+
@request.verify_mode.must_equal OpenSSL::SSL::VERIFY_PEER
|
58
58
|
end
|
59
59
|
|
60
60
|
it "uses basic-authentication with the credentials set on the Adyen::API module" do
|
61
61
|
username, password = @post.assigned_basic_auth
|
62
|
-
username.
|
63
|
-
password.
|
62
|
+
username.must_equal 'SuperShopper'
|
63
|
+
password.must_equal 'secret'
|
64
64
|
end
|
65
65
|
|
66
66
|
it "sends the proper headers" do
|
67
|
-
@post.header.
|
68
|
-
'accept'
|
69
|
-
'
|
70
|
-
'soapaction' => ['Action']
|
71
|
-
)
|
67
|
+
@post.header.
|
68
|
+
values_at('accept', 'content-type', 'soapaction').
|
69
|
+
must_equal([['text/xml'], ['text/xml; charset=utf-8'], ['Action']])
|
72
70
|
end
|
73
71
|
|
74
72
|
it "returns an Adyen::API::Response instance" do
|
75
|
-
@response.
|
76
|
-
@response.xml_querier.to_s.rstrip.
|
73
|
+
@response.must_be_instance_of(Adyen::API::Response)
|
74
|
+
@response.xml_querier.to_s.rstrip.must_equal AUTHORISE_RESPONSE.rstrip
|
77
75
|
end
|
78
76
|
|
79
77
|
[
|
@@ -84,7 +82,7 @@ describe Adyen::API::SimpleSOAPClient do
|
|
84
82
|
]
|
85
83
|
].each do |label, response, expected_exception|
|
86
84
|
it "raises when the HTTP response is a subclass of #{response.class.name}" do
|
87
|
-
response.
|
85
|
+
response.stubs(:body).returns(%{<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"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Illegal argument. For input string: "100.0"</faultstring></soap:Fault></soap:Body></soap:Envelope>})
|
88
86
|
Net::HTTP.stubbed_response = response
|
89
87
|
|
90
88
|
exception = nil
|
@@ -93,7 +91,7 @@ describe Adyen::API::SimpleSOAPClient do
|
|
93
91
|
rescue expected_exception => e
|
94
92
|
exception = e
|
95
93
|
end
|
96
|
-
exception.message.
|
94
|
+
exception.message.must_equal %{#{label} error occurred while calling SOAP action `Action' on endpoint `https://test.example.com/soap/Action'. Fault message: Illegal argument. For input string: "100.0".}
|
97
95
|
end
|
98
96
|
end
|
99
97
|
|
@@ -107,7 +105,7 @@ describe Adyen::API::SimpleSOAPClient do
|
|
107
105
|
["[505 HTTP Version Not Supported] A server", Net::HTTPBadGateway.new('1.1', '505', 'HTTP Version Not Supported')],
|
108
106
|
].each do |label, response|
|
109
107
|
it "is raised when the HTTP response is a `real` server error by status code" do
|
110
|
-
response.
|
108
|
+
response.stubs(:body).returns(%{<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"><soap:Body></soap:Body></soap:Envelope>})
|
111
109
|
Net::HTTP.stubbed_response = response
|
112
110
|
|
113
111
|
exception = nil
|
@@ -116,17 +114,16 @@ describe Adyen::API::SimpleSOAPClient do
|
|
116
114
|
rescue Adyen::API::SimpleSOAPClient::ServerError => e
|
117
115
|
exception = e
|
118
116
|
end
|
119
|
-
exception.message.
|
117
|
+
exception.message.must_equal %{#{label} error occurred while calling SOAP action `Action' on endpoint `https://test.example.com/soap/Action'.}
|
120
118
|
end
|
121
119
|
end
|
122
120
|
|
123
121
|
it "is not raised when the HTTP response has a 500 status code with a fault message" do
|
124
122
|
response = Net::HTTPServerError.new('1.1', '500', 'Internal Server Error')
|
125
|
-
response.
|
123
|
+
response.stubs(:body).returns(%{<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"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Illegal argument. For input string: "100.0"</faultstring></soap:Fault></soap:Body></soap:Envelope>})
|
126
124
|
|
127
|
-
|
128
|
-
|
129
|
-
end.should_not raise_error
|
125
|
+
@client.call_webservice_action('Action', '<bananas>Yes, please</bananas>', Adyen::API::Response)
|
126
|
+
pass
|
130
127
|
end
|
131
128
|
end
|
132
129
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
require '
|
2
|
+
require 'test_helper'
|
3
3
|
|
4
4
|
require 'adyen/api'
|
5
5
|
|
@@ -31,7 +31,8 @@ module Net
|
|
31
31
|
end
|
32
32
|
|
33
33
|
class << self
|
34
|
-
attr_accessor :
|
34
|
+
attr_accessor :posted, :stubbed_response
|
35
|
+
attr_reader :stubbing_enabled
|
35
36
|
|
36
37
|
def stubbing_enabled=(enabled)
|
37
38
|
reset! if @stubbing_enabled = enabled
|
@@ -53,12 +54,12 @@ module Net
|
|
53
54
|
end
|
54
55
|
|
55
56
|
alias old_request request
|
56
|
-
def request(request)
|
57
|
+
def request(request, body = nil, &block)
|
57
58
|
if Net::HTTP.stubbing_enabled
|
58
59
|
self.class.posted = [self, request]
|
59
60
|
self.class.stubbed_response
|
60
61
|
else
|
61
|
-
old_request(request)
|
62
|
+
old_request(request, body, &block)
|
62
63
|
end
|
63
64
|
end
|
64
65
|
end
|
@@ -82,10 +83,6 @@ module Adyen
|
|
82
83
|
end
|
83
84
|
|
84
85
|
module APISpecHelper
|
85
|
-
def node_for_current_object_and_method
|
86
|
-
Adyen::API::XMLQuerier.xml(@object.send(@method))
|
87
|
-
end
|
88
|
-
|
89
86
|
def xpath(query, &block)
|
90
87
|
node_for_current_method.xpath(query, &block)
|
91
88
|
end
|
@@ -97,7 +94,7 @@ module APISpecHelper
|
|
97
94
|
def stub_net_http(response_body)
|
98
95
|
Net::HTTP.stubbing_enabled = true
|
99
96
|
response = Net::HTTPOK.new('1.1', '200', 'OK')
|
100
|
-
response.
|
97
|
+
response.stubs(:body).returns response_body
|
101
98
|
Net::HTTP.stubbed_response = response
|
102
99
|
end
|
103
100
|
|
@@ -110,24 +107,18 @@ module APISpecHelper
|
|
110
107
|
backends = [Adyen::API::XMLQuerier::NokogiriBackend, Adyen::API::XMLQuerier::REXMLBackend]
|
111
108
|
backends.each do |xml_backend|
|
112
109
|
describe "with a #{xml_backend} backend" do
|
113
|
-
before
|
110
|
+
before do
|
111
|
+
Adyen::API::XMLQuerier.stubs(:default_backend).returns xml_backend.new
|
112
|
+
end
|
114
113
|
instance_eval(&block)
|
115
114
|
end
|
116
115
|
end
|
117
116
|
end
|
118
117
|
|
119
|
-
def it_should_have_shortcut_methods_for_params_on_the_response
|
120
|
-
it "provides shortcut methods, on the response object, for all entries in the #params hash" do
|
121
|
-
@response.params.each do |key, value|
|
122
|
-
@response.send(key).should == value
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
118
|
def it_should_return_params_for_each_xml_backend(params)
|
128
119
|
for_each_xml_backend do
|
129
120
|
it "returns a hash with parsed response details" do
|
130
|
-
@object.send(@method).params.
|
121
|
+
@object.send(@method).params.must_equal params
|
131
122
|
end
|
132
123
|
end
|
133
124
|
end
|
@@ -150,8 +141,8 @@ module APISpecHelper
|
|
150
141
|
|
151
142
|
def it_should_validate_request_param(name, &block)
|
152
143
|
it "validates the `#{name}' request parameter" do
|
153
|
-
instance_eval
|
154
|
-
lambda {
|
144
|
+
instance_eval(&block)
|
145
|
+
lambda { current_object_method_result }.must_raise(ArgumentError)
|
155
146
|
end
|
156
147
|
end
|
157
148
|
|
@@ -170,14 +161,18 @@ module APISpecHelper
|
|
170
161
|
end
|
171
162
|
|
172
163
|
it "posts the body generated for the given parameters" do
|
173
|
-
@post.body.
|
164
|
+
@post.body.must_equal Adyen::API::SimpleSOAPClient::ENVELOPE % @object.send("#{@method}_request_body")
|
174
165
|
end
|
175
166
|
|
176
167
|
it "posts to the correct SOAP action" do
|
177
|
-
@post.soap_action.
|
168
|
+
@post.soap_action.must_equal soap_action
|
178
169
|
end
|
179
170
|
|
180
|
-
|
171
|
+
it "provides shortcut methods, on the response object, for all entries in the #params hash" do
|
172
|
+
params = @response.params
|
173
|
+
result = params.keys.map { |key| @response.send(key) }
|
174
|
+
result.must_equal params.values
|
175
|
+
end
|
181
176
|
|
182
177
|
instance_eval(&block)
|
183
178
|
end
|
@@ -186,33 +181,49 @@ module APISpecHelper
|
|
186
181
|
def describe_request_body_of(method, xpath = nil, &block)
|
187
182
|
method = "#{method}_request_body"
|
188
183
|
describe(method) do
|
184
|
+
prepare_request_body_specs(method, xpath)
|
189
185
|
before { @method = method }
|
190
|
-
if xpath
|
191
|
-
define_method(:node_for_current_method) do
|
192
|
-
node_for_current_object_and_method.xpath(xpath)
|
193
|
-
end
|
194
|
-
end
|
195
186
|
instance_eval(&block)
|
196
187
|
end
|
197
188
|
end
|
198
189
|
|
199
190
|
def describe_modification_request_body_of(method, camelized_method = nil, &block)
|
200
|
-
|
191
|
+
xpath = "//payment:#{camelized_method || method}/payment:modificationRequest"
|
192
|
+
method = "#{method}_request_body"
|
193
|
+
describe method do
|
194
|
+
prepare_request_body_specs(method, xpath)
|
195
|
+
|
201
196
|
before do
|
197
|
+
@method = method
|
202
198
|
@payment.params[:psp_reference] = 'original-psp-reference'
|
203
199
|
end
|
204
200
|
|
205
201
|
it "includes the merchant account" do
|
206
|
-
text('./payment:merchantAccount').
|
202
|
+
text('./payment:merchantAccount').must_equal 'SuperShopper'
|
207
203
|
end
|
208
204
|
|
209
205
|
it "includes the payment (PSP) reference of the payment to refund" do
|
210
|
-
text('./payment:originalReference').
|
206
|
+
text('./payment:originalReference').must_equal 'original-psp-reference'
|
211
207
|
end
|
212
208
|
|
213
209
|
instance_eval(&block) if block_given?
|
214
210
|
end
|
215
211
|
end
|
212
|
+
|
213
|
+
def prepare_request_body_specs(method, xpath)
|
214
|
+
let(:current_object_method_result) { @object.send(method) }
|
215
|
+
|
216
|
+
let(:node_for_current_object_and_method) do
|
217
|
+
Adyen::API::XMLQuerier.xml(current_object_method_result)
|
218
|
+
end
|
219
|
+
|
220
|
+
if xpath
|
221
|
+
let(:node_for_current_method) do
|
222
|
+
node_for_current_object_and_method.xpath(xpath)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
216
227
|
end
|
217
228
|
end
|
218
229
|
|
@@ -452,9 +463,7 @@ EOS
|
|
452
463
|
|
453
464
|
BILLET_RECEIVED_RESPONSE = <<EOS
|
454
465
|
<?xml version="1.0"?>
|
455
|
-
<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">
|
456
|
-
<soap:Body>
|
457
|
-
<ns1:authoriseResponse xmlns:ns1="http://payment.services.adyen.com"><ns1:paymentResult><additionalData xmlns="http://payment.services.adyen.com"><entry><key xsi:type="xsd:string">boletobancario.url</key><value xsi:type="xsd:string">https://test.adyen.com/hpp/generationBoleto.shtml?data=AgABAQBdYDe9OqdseA79Rfexm2Lz8fRQ1bWqkLhBCf1fHhQEif7bsRKi0otq%2B1ekMAdMIZUiVXeR3QFrAOA8Zy4tpiNLhkMq6f7W2zFqYhVWrByqxQnbQTYuX2FWI7tsu7Vb0MnyOvFfFdFtaxzImZYCli%2BMrqaAJ5HI9ap3egeqBQIsRI%2Fj0zWsu2EGN16lGbwFOLyxl%2By0Pc5jazTo8rnBA7OVPGDIu7Qt%2F2DYIMcB6PXou5W3aJoTC4SldhNdobVqgWUtES8NsWdOYbLGa6I%2BjSwEFXvxyTXwtw4J2E%2BE7ux1UhBiZRj66lMbcvaYlfnR2xWbA%2BKmdLrVvuXTroEHKQ%2B1C%2FuyGuiOk3SmGq6TMgOyCEt%2BmG%2Bq6z5jDi%2BnYLtlLQU4ccMOujgWMfGkViC%2FXDUlqYjKbn8NHwPwoPcelpf1zCDCe%2Fvu6NBTVQbEXbE0oV0j2MT1tLlMdf08iUsDThuQ3MlJbE8VbTMlttOFqoyXhBjepQ42C1eXfswSz1gsZlHanBCTiw1pB69vkvfWPf5IdUSx1cpEr9LJ9PSz%2FeHxEhq%2B8ZdWzrybXqRbEl2mUjLeyhMNuiE%3D</value></entry><entry><key xsi:type="xsd:string">boletobancario.data</key><value xsi:type="xsd:string">AgABAQBdYDe9OqdseA79Rfexm2Lz8fRQ1bWqkLhBCf1fHhQEif7bsRKi0otq+1ekMAdMIZUiVXeR3QFrAOA8Zy4tpiNLhkMq6f7W2zFqYhVWrByqxQnbQTYuX2FWI7tsu7Vb0MnyOvFfFdFtaxzImZYCli+MrqaAJ5HI9ap3egeqBQIsRI/j0zWsu2EGN16lGbwFOLyxl+y0Pc5jazTo8rnBA7OVPGDIu7Qt/2DYIMcB6PXou5W3aJoTC4SldhNdobVqgWUtES8NsWdOYbLGa6I+jSwEFXvxyTXwtw4J2E+E7ux1UhBiZRj66lMbcvaYlfnR2xWbA+KmdLrVvuXTroEHKQ+1C/uyGuiOk3SmGq6TMgOyCEt+mG+q6z5jDi+nYLtlLQU4ccMOujgWMfGkViC/XDUlqYjKbn8NHwPwoPcelpf1zCDCe/vu6NBTVQbEXbE0oV0j2MT1tLlMdf08iUsDThuQ3MlJbE8VbTMlttOFqoyXhBjepQ42C1eXfswSz1gsZlHanBCTiw1pB69vkvfWPf5IdUSx1cpEr9LJ9PSz/eHxEhq+8ZdWzrybXqRbEl2mUjLeyhMNuiE=</value></entry><entry><key xsi:type="xsd:string">boletobancario.expirationDate</key><value xsi:type="xsd:string">2014-07-17</value></entry><entry><key xsi:type="xsd:string">boletobancario.dueDate</key><value xsi:type="xsd:string">2014-07-02</value></entry></additionalData><authCode xmlns="http://payment.services.adyen.com" xsi:nil="true" /><dccAmount xmlns="http://payment.services.adyen.com" xsi:nil="true" /><dccSignature xmlns="http://payment.services.adyen.com" xsi:nil="true" /><fraudResult xmlns="http://payment.services.adyen.com" xsi:nil="true" /><issuerUrl xmlns="http://payment.services.adyen.com" xsi:nil="true" /><md xmlns="http://payment.services.adyen.com" xsi:nil="true" /><paRequest xmlns="http://payment.services.adyen.com" xsi:nil="true" /><pspReference xmlns="http://payment.services.adyen.com">8814038837489129</pspReference><refusalReason xmlns="http://payment.services.adyen.com" xsi:nil="true" /><resultCode xmlns="http://payment.services.adyen.com">Received</resultCode></ns1:paymentResult></ns1:authoriseResponse></soap:Body></soap:Envelope>
|
466
|
+
<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"><soap:Body><ns1:authoriseResponse xmlns:ns1="http://payment.services.adyen.com"><ns1:paymentResult><additionalData xmlns="http://payment.services.adyen.com"><entry><key xsi:type="xsd:string">boletobancario.barCodeReference</key><value xsi:type="xsd:string">03399.33335 33887.371731 37772.301026 8 69200000009314</value></entry><entry><key xsi:type="xsd:string">boletobancario.data</key><value xsi:type="xsd:string">BQABAQA8M3ewKqDwrdIK+q9mDvlF+X0IszPCAG9Tg2jmOJn0/m6T+PABVpyI8/hFeY3xTN3B7yEffj6ehx0ADQh5sLT9ndkqu1UuHTZjlxBiJ9UcMOAl8rkPSLEJU1Dw1tLWGQ7PKRqB8bv3k/VbPGliXZVxEvzxAOZdZ1dpHeVZfA1XT8a9+ZQtJFPAHOhgYpPBmYkiVnavJfwbNMKddQY0CZxC1V2Hndx9yDl/S0IJ1hLgiwxr8eE6QkeDBYZ5uKKyiIVpPxKwDe1o3sq2v76s7cQvdfGn/mAr6jWiNl+rQU92/YlFuR4rHhZdOyUkNofTeTRcpuSaTsK1L9MS1UNqTAWbEMmlqUgNZ6B7HtiYP61sbMIAAECcYbKVpl+RN3hpP3HqHc0/xkOShfnE4bYOtDGVDMf4dt9kAM6+XDOyk8iu//dbHvrZnenLFsKhcdDEjiXRrLHMVxQI9BN/5Yy4hnGN7k/XI1mANMhNpKWLdPBCt94GzaiI830xKsh5KlgFrenU+4x2p0pbeAQUokTLKHEUUzmNmlplxhADBHmTAEwC0vbbGjWFh3PS0zGRwas2TpLNRtQznTmdfoI7j0dlSVHCQQ==</value></entry><entry><key xsi:type="xsd:string">boletobancario.dueDate</key><value xsi:type="xsd:string">2016-09-17</value></entry><entry><key xsi:type="xsd:string">boletobancario.url</key><value xsi:type="xsd:string">https://test.adyen.com/hpp/generationBoleto.shtml?data=BQABAQA8M3ewKqDwrdIK%2Bq9mDvlF%2BX0IszPCAG9Tg2jmOJn0%2Fm6T%2BPABVpyI8%2FhFeY3xTN3B7yEffj6ehx0ADQh5sLT9ndkqu1UuHTZjlxBiJ9UcMOAl8rkPSLEJU1Dw1tLWGQ7PKRqB8bv3k%2FVbPGliXZVxEvzxAOZdZ1dpHeVZfA1XT8a9%2BZQtJFPAHOhgYpPBmYkiVnavJfwbNMKddQY0CZxC1V2Hndx9yDl%2FS0IJ1hLgiwxr8eE6QkeDBYZ5uKKyiIVpPxKwDe1o3sq2v76s7cQvdfGn%2FmAr6jWiNl%2BrQU92%2FYlFuR4rHhZdOyUkNofTeTRcpuSaTsK1L9MS1UNqTAWbEMmlqUgNZ6B7HtiYP61sbMIAAECcYbKVpl%2BRN3hpP3HqHc0%2FxkOShfnE4bYOtDGVDMf4dt9kAM6%2BXDOyk8iu%2F%2FdbHvrZnenLFsKhcdDEjiXRrLHMVxQI9BN%2F5Yy4hnGN7k%2FXI1mANMhNpKWLdPBCt94GzaiI830xKsh5KlgFrenU%2B4x2p0pbeAQUokTLKHEUUzmNmlplxhADBHmTAEwC0vbbGjWFh3PS0zGRwas2TpLNRtQznTmdfoI7j0dlSVHCQQ%3D%3D</value></entry><entry><key xsi:type="xsd:string">boletobancario.expirationDate</key><value xsi:type="xsd:string">2016-10-02</value></entry></additionalData><authCode xmlns="http://payment.services.adyen.com" xsi:nil="true"/><dccAmount xmlns="http://payment.services.adyen.com" xsi:nil="true"/><dccSignature xmlns="http://payment.services.adyen.com" xsi:nil="true"/><fraudResult xmlns="http://payment.services.adyen.com" xsi:nil="true"/><issuerUrl xmlns="http://payment.services.adyen.com" xsi:nil="true"/><md xmlns="http://payment.services.adyen.com" xsi:nil="true"/><paRequest xmlns="http://payment.services.adyen.com" xsi:nil="true"/><pspReference xmlns="http://payment.services.adyen.com">8814737173377729</pspReference><refusalReason xmlns="http://payment.services.adyen.com" xsi:nil="true"/><resultCode xmlns="http://payment.services.adyen.com">Received</resultCode></ns1:paymentResult></ns1:authoriseResponse></soap:Body></soap:Envelope>
|
458
467
|
EOS
|
459
468
|
|
460
469
|
BILLET_REFUSED_RESPONSE = <<EOS
|