adyen 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +2 -2
- data/LICENSE +1 -1
- data/README.rdoc +4 -0
- data/Rakefile +7 -5
- data/adyen.gemspec +2 -0
- data/lib/adyen/api.rb +66 -6
- data/lib/adyen/api/payment_service.rb +69 -2
- data/lib/adyen/api/recurring_service.rb +1 -1
- data/lib/adyen/api/templates/payment_service.rb +31 -1
- data/lib/adyen/api/xml_querier.rb +1 -1
- data/lib/adyen/form.rb +3 -0
- data/lib/adyen/formatter.rb +10 -4
- data/lib/adyen/matchers.rb +3 -7
- data/lib/adyen/version.rb +1 -1
- data/spec/api/api_spec.rb +23 -10
- data/spec/api/payment_service_spec.rb +29 -1
- data/spec/api/response_spec.rb +2 -2
- data/spec/api/simple_soap_client_spec.rb +1 -1
- data/spec/api/spec_helper.rb +12 -0
- data/spec/functional/api_spec.rb +61 -55
- data/test/adyen_test.rb +31 -0
- data/test/form_test.rb +220 -0
- data/test/test_helper.rb +24 -0
- metadata +36 -8
- data/.kick +0 -35
- data/TODO +0 -16
- data/spec/adyen_spec.rb +0 -44
- data/spec/form_spec.rb +0 -318
data/lib/adyen/version.rb
CHANGED
data/spec/api/api_spec.rb
CHANGED
@@ -22,7 +22,8 @@ describe Adyen::API do
|
|
22
22
|
:shopper => { :reference => 'user-id', :email => 's.hopper@example.com' },
|
23
23
|
:card => { :expiry_month => 12, :expiry_year => 2012, :holder_name => "Simon Hopper", :number => '4444333322221111', :cvc => '737' },
|
24
24
|
:recurring => false,
|
25
|
-
:fraud_offset => nil
|
25
|
+
:fraud_offset => nil,
|
26
|
+
:instant_capture => false
|
26
27
|
)
|
27
28
|
Adyen::API.authorise_payment('order-id',
|
28
29
|
{ :currency => 'EUR', :value => 1234 },
|
@@ -38,14 +39,16 @@ describe Adyen::API do
|
|
38
39
|
:shopper => { :reference => 'user-id', :email => 's.hopper@example.com' },
|
39
40
|
:card => { :expiry_month => 12, :expiry_year => 2012, :holder_name => "Simon Hopper", :number => '4444333322221111', :cvc => '737' },
|
40
41
|
:recurring => false,
|
41
|
-
:fraud_offset => -100
|
42
|
+
:fraud_offset => -100,
|
43
|
+
:instant_capture => false
|
42
44
|
)
|
43
45
|
Adyen::API.authorise_payment('order-id',
|
44
46
|
{ :currency => 'EUR', :value => 1234 },
|
45
47
|
{ :reference => 'user-id', :email => 's.hopper@example.com' },
|
46
48
|
{ :expiry_month => 12, :expiry_year => 2012, :holder_name => "Simon Hopper", :number => '4444333322221111', :cvc => '737' },
|
47
49
|
false,
|
48
|
-
-100
|
50
|
+
-100,
|
51
|
+
false
|
49
52
|
)
|
50
53
|
end
|
51
54
|
|
@@ -56,13 +59,16 @@ describe Adyen::API do
|
|
56
59
|
:shopper => { :reference => 'user-id', :email => 's.hopper@example.com' },
|
57
60
|
:card => { :expiry_month => 12, :expiry_year => 2012, :holder_name => "Simon Hopper", :number => '4444333322221111', :cvc => '737' },
|
58
61
|
:recurring => true,
|
59
|
-
:fraud_offset => nil
|
62
|
+
:fraud_offset => nil,
|
63
|
+
:instant_capture => false,
|
60
64
|
)
|
61
65
|
Adyen::API.authorise_payment('order-id',
|
62
66
|
{ :currency => 'EUR', :value => 1234 },
|
63
67
|
{ :reference => 'user-id', :email => 's.hopper@example.com' },
|
64
68
|
{ :expiry_month => 12, :expiry_year => 2012, :holder_name => "Simon Hopper", :number => '4444333322221111', :cvc => '737' },
|
65
|
-
true
|
69
|
+
true,
|
70
|
+
nil,
|
71
|
+
false
|
66
72
|
)
|
67
73
|
end
|
68
74
|
|
@@ -72,6 +78,7 @@ describe Adyen::API do
|
|
72
78
|
:amount => { :currency => 'EUR', :value => 1234 },
|
73
79
|
:shopper => { :reference => 'user-id', :email => 's.hopper@example.com' },
|
74
80
|
:recurring_detail_reference => 'LATEST',
|
81
|
+
:instant_capture => false,
|
75
82
|
:fraud_offset => nil
|
76
83
|
)
|
77
84
|
Adyen::API.authorise_recurring_payment('order-id',
|
@@ -86,6 +93,7 @@ describe Adyen::API do
|
|
86
93
|
:amount => { :currency => 'EUR', :value => 1234 },
|
87
94
|
:shopper => { :reference => 'user-id', :email => 's.hopper@example.com' },
|
88
95
|
:recurring_detail_reference => 'recurring-detail-reference',
|
96
|
+
:instant_capture => false,
|
89
97
|
:fraud_offset => nil
|
90
98
|
)
|
91
99
|
Adyen::API.authorise_recurring_payment('order-id',
|
@@ -101,13 +109,15 @@ describe Adyen::API do
|
|
101
109
|
:amount => { :currency => 'EUR', :value => 1234 },
|
102
110
|
:shopper => { :reference => 'user-id', :email => 's.hopper@example.com' },
|
103
111
|
:recurring_detail_reference => 'recurring-detail-reference',
|
104
|
-
:fraud_offset => 50
|
112
|
+
:fraud_offset => 50,
|
113
|
+
:instant_capture => false
|
105
114
|
)
|
106
115
|
Adyen::API.authorise_recurring_payment('order-id',
|
107
116
|
{ :currency => 'EUR', :value => 1234 },
|
108
117
|
{ :reference => 'user-id', :email => 's.hopper@example.com' },
|
109
118
|
'recurring-detail-reference',
|
110
|
-
50
|
119
|
+
50,
|
120
|
+
false
|
111
121
|
)
|
112
122
|
end
|
113
123
|
|
@@ -118,7 +128,8 @@ describe Adyen::API do
|
|
118
128
|
:shopper => { :reference => 'user-id', :email => 's.hopper@example.com' },
|
119
129
|
:card => { :cvc => '737' },
|
120
130
|
:recurring_detail_reference => 'recurring-detail-reference',
|
121
|
-
:fraud_offset => nil
|
131
|
+
:fraud_offset => nil,
|
132
|
+
:instant_capture => false
|
122
133
|
)
|
123
134
|
Adyen::API.authorise_one_click_payment('order-id',
|
124
135
|
{ :currency => 'EUR', :value => 1234 },
|
@@ -135,14 +146,16 @@ describe Adyen::API do
|
|
135
146
|
:shopper => { :reference => 'user-id', :email => 's.hopper@example.com' },
|
136
147
|
:card => { :cvc => '737' },
|
137
148
|
:recurring_detail_reference => 'recurring-detail-reference',
|
138
|
-
:fraud_offset => -10
|
149
|
+
:fraud_offset => -10,
|
150
|
+
:instant_capture => false,
|
139
151
|
)
|
140
152
|
Adyen::API.authorise_one_click_payment('order-id',
|
141
153
|
{ :currency => 'EUR', :value => 1234 },
|
142
154
|
{ :reference => 'user-id', :email => 's.hopper@example.com' },
|
143
155
|
{ :cvc => '737' },
|
144
156
|
'recurring-detail-reference',
|
145
|
-
-10
|
157
|
+
-10,
|
158
|
+
false
|
146
159
|
)
|
147
160
|
end
|
148
161
|
|
@@ -121,7 +121,7 @@ describe Adyen::API::PaymentService do
|
|
121
121
|
it_should_validate_request_parameters :merchant_account,
|
122
122
|
:reference,
|
123
123
|
:amount => [:currency, :value],
|
124
|
-
:card => [:holder_name, :number, :
|
124
|
+
:card => [:holder_name, :number, :expiry_year, :expiry_month]
|
125
125
|
|
126
126
|
it_should_validate_request_param(:shopper) do
|
127
127
|
@payment.params[:recurring] = true
|
@@ -162,6 +162,34 @@ describe Adyen::API::PaymentService do
|
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
165
|
+
describe_response_from :generate_billet, BILLET_RECEIVED_RESPONSE do
|
166
|
+
it_should_return_params_for_each_xml_backend({
|
167
|
+
:psp_reference => "8814038837489129",
|
168
|
+
:result_code => "Received",
|
169
|
+
:billet_url => "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"
|
170
|
+
})
|
171
|
+
|
172
|
+
describe "with a received billet" do
|
173
|
+
it "returns that the request was successful" do
|
174
|
+
@response.should be_success
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe_response_from :generate_billet, BILLET_REFUSED_RESPONSE do
|
180
|
+
it_should_return_params_for_each_xml_backend({
|
181
|
+
:psp_reference => "8514038928235061",
|
182
|
+
:result_code => "Refused",
|
183
|
+
:billet_url => ""
|
184
|
+
})
|
185
|
+
|
186
|
+
describe "with a received billet" do
|
187
|
+
it "returns that the request was successful" do
|
188
|
+
@response.should_not be_success
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
165
193
|
describe_response_from :authorise_payment, AUTHORISE_RESPONSE do
|
166
194
|
it_should_return_params_for_each_xml_backend({
|
167
195
|
:psp_reference => '9876543210987654',
|
data/spec/api/response_spec.rb
CHANGED
@@ -41,7 +41,7 @@ describe Adyen::API::Response do
|
|
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?.should
|
44
|
+
@response.server_error?.should be true
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -53,7 +53,7 @@ describe Adyen::API::Response do
|
|
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?.should
|
56
|
+
@response.server_error?.should be false
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
data/spec/api/spec_helper.rb
CHANGED
@@ -449,3 +449,15 @@ CAPTURE_RESPONSE = <<EOS
|
|
449
449
|
</soap:Body>
|
450
450
|
</soap:Envelope>
|
451
451
|
EOS
|
452
|
+
|
453
|
+
BILLET_RECEIVED_RESPONSE = <<EOS
|
454
|
+
<?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>
|
458
|
+
EOS
|
459
|
+
|
460
|
+
BILLET_REFUSED_RESPONSE = <<EOS
|
461
|
+
<?xml version="1.0"?>
|
462
|
+
<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' xsi:nil='true' /><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'>8514038928235061</pspReference><refusalReason xmlns='http://payment.services.adyen.com'>102 Unable to determine variant</refusalReason><resultCode xmlns='http://payment.services.adyen.com'>Refused</resultCode></ns1:paymentResult></ns1:authoriseResponse></soap:Body></soap:Envelope>
|
463
|
+
EOS
|
data/spec/functional/api_spec.rb
CHANGED
@@ -19,64 +19,67 @@ if File.exist?(API_SPEC_INITIALIZER)
|
|
19
19
|
Net::HTTP.stubbing_enabled = true
|
20
20
|
end
|
21
21
|
|
22
|
+
it "performs a payment request" do
|
23
|
+
@payment_response.should be_authorized
|
24
|
+
@payment_response.psp_reference.should_not be_empty
|
25
|
+
end
|
26
|
+
|
22
27
|
def perform_payment_request
|
23
28
|
Adyen::API.authorise_payment(
|
24
29
|
@order_id,
|
25
30
|
{ :currency => 'EUR', :value => '1234' },
|
26
31
|
{ :email => "#{@user_id}@example.com", :reference => @user_id },
|
27
|
-
{ :expiry_month =>
|
32
|
+
{ :expiry_month => '08', :expiry_year => '2018', :holder_name => "Simon #{@user_id} Hopper", :number => '4111111111111111', :cvc => '737' },
|
28
33
|
true
|
29
34
|
)
|
30
35
|
end
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
#response.recurring_detail_reference.should_not be_empty
|
79
|
-
#end
|
37
|
+
it "performs a recurring payment request" do
|
38
|
+
response = Adyen::API.authorise_recurring_payment(
|
39
|
+
@order_id,
|
40
|
+
{ :currency => 'EUR', :value => '1234' },
|
41
|
+
{ :email => "#{@user_id}@example.com", :reference => @user_id }
|
42
|
+
)
|
43
|
+
response.should be_authorized
|
44
|
+
response.psp_reference.should_not be_empty
|
45
|
+
end
|
46
|
+
|
47
|
+
it "performs a one-click payment request" do
|
48
|
+
detail = Adyen::API.list_recurring_details(@user_id).references.last
|
49
|
+
response = Adyen::API.authorise_one_click_payment(
|
50
|
+
@order_id,
|
51
|
+
{ :currency => 'EUR', :value => '1234' },
|
52
|
+
{ :email => "#{@user_id}@example.com", :reference => @user_id },
|
53
|
+
{ :cvc => '737' },
|
54
|
+
detail
|
55
|
+
)
|
56
|
+
response.should be_authorized
|
57
|
+
response.psp_reference.should_not be_empty
|
58
|
+
end
|
59
|
+
|
60
|
+
it "stores the provided ELV account details" do
|
61
|
+
response = Adyen::API.store_recurring_token(
|
62
|
+
{ :email => "#{@user_id}@example.com", :reference => @user_id },
|
63
|
+
{ :bank_location => "Berlin", :bank_name => "TestBank", :bank_location_id => "12345678", :holder_name => "Simon #{@user_id} Hopper", :number => "1234567890" }
|
64
|
+
)
|
65
|
+
response.should be_stored
|
66
|
+
response.recurring_detail_reference.should_not be_empty
|
67
|
+
end
|
68
|
+
|
69
|
+
it "stores the provided creditcard details" do
|
70
|
+
response = Adyen::API.store_recurring_token(
|
71
|
+
{ :email => "#{@user_id}@example.com", :reference => @user_id },
|
72
|
+
{ :expiry_month => '08', :expiry_year => '2018', :holder_name => "Simon #{@user_id} Hopper", :number => '4111111111111111' }
|
73
|
+
)
|
74
|
+
response.should be_stored
|
75
|
+
response.recurring_detail_reference.should_not be_empty
|
76
|
+
end
|
77
|
+
|
78
|
+
it "disables a recurring contract" do
|
79
|
+
response = Adyen::API.disable_recurring_contract(@user_id)
|
80
|
+
response.should be_success
|
81
|
+
response.should be_disabled
|
82
|
+
end
|
80
83
|
|
81
84
|
it "captures a payment" do
|
82
85
|
response = Adyen::API.capture_payment(@payment_response.psp_reference, { :currency => 'EUR', :value => '1234' })
|
@@ -98,12 +101,15 @@ if File.exist?(API_SPEC_INITIALIZER)
|
|
98
101
|
response.should be_success
|
99
102
|
end
|
100
103
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
104
|
+
it "generates a billet" do
|
105
|
+
response = Adyen::API.generate_billet("{\"user_id\":66722,\"order_id\":6863}#signup",
|
106
|
+
{ currency: "BRL", value: 1000 },
|
107
|
+
{ first_name: "Jow", last_name: "Silver" },
|
108
|
+
"19762003691",
|
109
|
+
"boletobancario_santander",
|
110
|
+
"2014-07-16T18:16:11Z")
|
111
|
+
response.should be_success
|
112
|
+
end
|
107
113
|
end
|
108
114
|
|
109
115
|
else
|
data/test/adyen_test.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class AdyenTest < Minitest::Test
|
5
|
+
def test_hmac_base64_encoding
|
6
|
+
encoded_str = Adyen::Encoding.hmac_base64('bla', 'bla')
|
7
|
+
assert_equal '6nItEkVpIYF+i1RwrEyQ7RHmrfU=', encoded_str
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_gzip_base64_encoding
|
11
|
+
encoded_str = Adyen::Encoding.gzip_base64('bla')
|
12
|
+
assert_equal 32, encoded_str.length
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_date_formatting
|
16
|
+
assert_match /^\d{4}-\d{2}-\d{2}$/, Adyen::Formatter::DateTime.fmt_date(Date.today)
|
17
|
+
assert_equal '2009-01-01', Adyen::Formatter::DateTime.fmt_date('2009-01-01')
|
18
|
+
|
19
|
+
assert_raises(ArgumentError) { Adyen::Formatter::DateTime.fmt_date('2009-1-1') }
|
20
|
+
assert_raises(ArgumentError) { Adyen::Formatter::DateTime.fmt_time(20090101) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_timestamp_formatting
|
24
|
+
assert_match /^\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}Z$/, Adyen::Formatter::DateTime.fmt_time(Time.now)
|
25
|
+
assert_match /^\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}Z$/, Adyen::Formatter::DateTime.fmt_time(DateTime.now)
|
26
|
+
assert_equal '2009-01-01T11:11:11Z', Adyen::Formatter::DateTime.fmt_time('2009-01-01T11:11:11Z')
|
27
|
+
|
28
|
+
assert_raises(ArgumentError) { Adyen::Formatter::DateTime.fmt_time('2009-01-01 11:11:11') }
|
29
|
+
assert_raises(ArgumentError) { Adyen::Formatter::DateTime.fmt_time(20090101111111) }
|
30
|
+
end
|
31
|
+
end
|
data/test/form_test.rb
ADDED
@@ -0,0 +1,220 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FormTest < Minitest::Test
|
4
|
+
include Adyen::Matchers
|
5
|
+
include Adyen::Test::EachXMLBackend
|
6
|
+
|
7
|
+
def setup
|
8
|
+
Adyen.configuration.default_form_params[:merchant_account] = 'TestMerchant'
|
9
|
+
Adyen.configuration.register_form_skin(:testing, '4aD37dJA', 'Kah942*$7sdp0)')
|
10
|
+
Adyen.configuration.register_form_skin(:other, 'sk1nC0de', 'shared_secret', merchant_account: 'OtherMerchant')
|
11
|
+
|
12
|
+
# Use autodetection for the environment unless otherwise specified
|
13
|
+
Adyen.configuration.environment = nil
|
14
|
+
Adyen.configuration.payment_flow = :select
|
15
|
+
Adyen.configuration.payment_flow_domain = nil
|
16
|
+
|
17
|
+
@payment_attributes = {
|
18
|
+
:skin => :testing,
|
19
|
+
:currency_code => 'GBP',
|
20
|
+
:payment_amount => 10000,
|
21
|
+
:merchant_reference => 'Internet Order 12345',
|
22
|
+
:ship_before_date => '2007-10-20',
|
23
|
+
:session_validity => '2007-10-11T11:00:00Z',
|
24
|
+
:billing_address => {
|
25
|
+
:street => 'Alexanderplatz',
|
26
|
+
:house_number_or_name => '0815',
|
27
|
+
:city => 'Berlin',
|
28
|
+
:postal_code => '10119',
|
29
|
+
:state_or_province => 'Berlin',
|
30
|
+
:country => 'Germany',
|
31
|
+
},
|
32
|
+
:shopper => {
|
33
|
+
:telephone_number => '1234512345',
|
34
|
+
:first_name => 'John',
|
35
|
+
:last_name => 'Doe',
|
36
|
+
:social_security_number => '123-45-1234'
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
@recurring_payment_attributes = @payment_attributes.merge(
|
41
|
+
:skin => :other,
|
42
|
+
:recurring_contract => 'DEFAULT',
|
43
|
+
:shopper_reference => 'grasshopper52',
|
44
|
+
:shopper_email => 'gras.shopper@somewhere.org'
|
45
|
+
)
|
46
|
+
|
47
|
+
Adyen::Form.do_parameter_transformations!(@payment_attributes)
|
48
|
+
Adyen::Form.do_parameter_transformations!(@recurring_payment_attributes)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_autodetected_redirect_url
|
52
|
+
assert_equal 'https://test.adyen.com/hpp/select.shtml', Adyen::Form.url
|
53
|
+
|
54
|
+
Adyen.configuration.stubs(:autodetect_environment).returns('live')
|
55
|
+
assert_equal 'https://live.adyen.com/hpp/select.shtml', Adyen::Form.url
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_explicit_redirect_url
|
59
|
+
assert_equal 'https://live.adyen.com/hpp/select.shtml', Adyen::Form.url(:live)
|
60
|
+
assert_equal 'https://test.adyen.com/hpp/select.shtml', Adyen::Form.url(:test)
|
61
|
+
|
62
|
+
Adyen.configuration.environment = :live
|
63
|
+
assert_equal 'https://live.adyen.com/hpp/select.shtml', Adyen::Form.url
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_redirect_url_for_different_payment_flows
|
67
|
+
Adyen.configuration.payment_flow = :select
|
68
|
+
assert_equal 'https://test.adyen.com/hpp/select.shtml', Adyen::Form.url
|
69
|
+
|
70
|
+
Adyen.configuration.payment_flow = :pay
|
71
|
+
assert_equal 'https://test.adyen.com/hpp/pay.shtml', Adyen::Form.url
|
72
|
+
|
73
|
+
Adyen.configuration.payment_flow = :details
|
74
|
+
assert_equal 'https://test.adyen.com/hpp/details.shtml', Adyen::Form.url
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_redirect_url_for_custom_domain
|
78
|
+
Adyen.configuration.payment_flow_domain = "checkout.mydomain.com"
|
79
|
+
assert_equal 'https://checkout.mydomain.com/hpp/select.shtml', Adyen::Form.url
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_redirect_url_generation
|
83
|
+
attributes = {
|
84
|
+
:currency_code => 'GBP', :payment_amount => 10000, :ship_before_date => Date.today,
|
85
|
+
:merchant_reference => 'Internet Order 12345', :skin => :testing, :session_validity => Time.now + 3600
|
86
|
+
}
|
87
|
+
|
88
|
+
redirect_uri = URI(Adyen::Form.redirect_url(attributes))
|
89
|
+
assert_match %r[^#{Adyen::Form.url}], redirect_uri.to_s
|
90
|
+
|
91
|
+
params = CGI.parse(redirect_uri.query)
|
92
|
+
attributes.each do |key, value|
|
93
|
+
assert_equal value.to_s, params[Adyen::Form.camelize(key).to_s].first
|
94
|
+
end
|
95
|
+
|
96
|
+
assert params.key?('merchantSig'), "Expected a merchantSig parameter to be set"
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_payment_methods_url_generation
|
100
|
+
attributes = {
|
101
|
+
:currency_code => 'GBP', :payment_amount => 10000, :ship_before_date => Date.today,
|
102
|
+
:merchant_reference => 'Internet Order 12345', :skin => :testing, :session_validity => Time.now + 3600
|
103
|
+
}
|
104
|
+
|
105
|
+
redirect_uri = URI(Adyen::Form.payment_methods_url(attributes))
|
106
|
+
assert_match %r[^#{Adyen::Form.url(nil, :directory)}], redirect_uri.to_s
|
107
|
+
|
108
|
+
params = CGI.parse(redirect_uri.query)
|
109
|
+
attributes.each do |key, value|
|
110
|
+
assert_equal value.to_s, params[Adyen::Form.camelize(key).to_s].first
|
111
|
+
end
|
112
|
+
|
113
|
+
assert params.key?('merchantSig'), "Expected a merchantSig parameter to be set"
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_redirect_signature_string
|
117
|
+
signature_string = Adyen::Form.calculate_signature_string(@payment_attributes)
|
118
|
+
assert_equal "10000GBP2007-10-20Internet Order 123454aD37dJATestMerchant2007-10-11T11:00:00Z", signature_string
|
119
|
+
|
120
|
+
signature_string = Adyen::Form.calculate_signature_string(@payment_attributes.merge(:merchant_return_data => 'testing123'))
|
121
|
+
assert_equal "10000GBP2007-10-20Internet Order 123454aD37dJATestMerchant2007-10-11T11:00:00Ztesting123", signature_string
|
122
|
+
|
123
|
+
signature_string = Adyen::Form.calculate_signature_string(@recurring_payment_attributes)
|
124
|
+
assert_equal "10000GBP2007-10-20Internet Order 12345sk1nC0deOtherMerchant2007-10-11T11:00:00Zgras.shopper@somewhere.orggrasshopper52DEFAULT", signature_string
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_redirect_signature
|
128
|
+
assert_equal 'x58ZcRVL1H6y+XSeBGrySJ9ACVo=', Adyen::Form.calculate_signature(@payment_attributes)
|
129
|
+
assert_equal 'EZtZS/33I6qsXptTfRIFMJxeKFE=', Adyen::Form.calculate_signature(@recurring_payment_attributes)
|
130
|
+
|
131
|
+
@payment_attributes.delete(:shared_secret)
|
132
|
+
assert_raises(ArgumentError) { Adyen::Form.calculate_signature(@payment_attributes) }
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_shopper_signature
|
136
|
+
signature_string = Adyen::Form.calculate_shopper_signature_string(@payment_attributes[:shopper])
|
137
|
+
assert_equal "JohnDoe1234512345", signature_string
|
138
|
+
assert_equal 'rb2GEs1kGKuLh255a3QRPBYXmsQ=', Adyen::Form.calculate_shopper_signature(@payment_attributes)
|
139
|
+
|
140
|
+
@payment_attributes.delete(:shared_secret)
|
141
|
+
assert_raises(ArgumentError) { Adyen::Form.calculate_shopper_signature(@payment_attributes) }
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_billing_address_signature
|
145
|
+
signature_string = Adyen::Form.calculate_billing_address_signature_string(@payment_attributes[:billing_address])
|
146
|
+
assert_equal "Alexanderplatz0815Berlin10119BerlinGermany", signature_string
|
147
|
+
assert_equal '5KQb7VJq4cz75cqp11JDajntCY4=', Adyen::Form.calculate_billing_address_signature(@payment_attributes)
|
148
|
+
|
149
|
+
@payment_attributes.delete(:shared_secret)
|
150
|
+
assert_raises(ArgumentError) { Adyen::Form.calculate_billing_address_signature(@payment_attributes) }
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_billing_address_and_shopper_signature_in_redirect_url
|
154
|
+
get_params = CGI.parse(URI(Adyen::Form.redirect_url(@payment_attributes)).query)
|
155
|
+
assert_equal '5KQb7VJq4cz75cqp11JDajntCY4=', get_params['billingAddressSig'].first
|
156
|
+
assert_equal 'rb2GEs1kGKuLh255a3QRPBYXmsQ=', get_params['shopperSig'].first
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_redirect_signature_check
|
160
|
+
params = {
|
161
|
+
:authResult => 'AUTHORISED', :pspReference => '1211992213193029',
|
162
|
+
:merchantReference => 'Internet Order 12345', :skinCode => '4aD37dJA',
|
163
|
+
:merchantSig => 'ytt3QxWoEhAskUzUne0P5VA9lPw='
|
164
|
+
}
|
165
|
+
|
166
|
+
assert_equal params[:merchantSig], Adyen::Form.redirect_signature(params)
|
167
|
+
|
168
|
+
assert Adyen::Form.redirect_signature_check(params) # shared secret from registered skin
|
169
|
+
assert Adyen::Form.redirect_signature_check(params, 'Kah942*$7sdp0)') # explicitly provided shared secret
|
170
|
+
|
171
|
+
refute Adyen::Form.redirect_signature_check(params.merge(skinCode: 'sk1nC0de'))
|
172
|
+
refute Adyen::Form.redirect_signature_check(params, 'wrong_shared_secret')
|
173
|
+
|
174
|
+
refute Adyen::Form.redirect_signature_check(params.merge(pspReference: 'tampered'))
|
175
|
+
refute Adyen::Form.redirect_signature_check(params.merge(merchantSig: 'tampered'))
|
176
|
+
|
177
|
+
assert_raises(ArgumentError) { Adyen::Form.redirect_signature_check(nil) }
|
178
|
+
assert_raises(ArgumentError) { Adyen::Form.redirect_signature_check({}) }
|
179
|
+
assert_raises(ArgumentError) { Adyen::Form.redirect_signature_check(params.delete(:skinCode)) }
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_flatten
|
183
|
+
parameters = { 'billingAddress.street' => 'My Street' }
|
184
|
+
assert_equal parameters, Adyen::Form.flatten(:billing_address => { :street => 'My Street'})
|
185
|
+
assert_equal Hash.new, Adyen::Form.flatten(nil)
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_hidden_payment_form_fields
|
189
|
+
payment_snippet = <<-HTML
|
190
|
+
<form action="#{CGI.escapeHTML(Adyen::Form.url)}" method="post">
|
191
|
+
#{Adyen::Form.hidden_fields(@payment_attributes)}
|
192
|
+
</form>
|
193
|
+
HTML
|
194
|
+
|
195
|
+
for_each_xml_backend do
|
196
|
+
assert_adyen_single_payment_form payment_snippet,
|
197
|
+
merchantAccount: 'TestMerchant',
|
198
|
+
currencyCode: 'GBP',
|
199
|
+
paymentAmount: '10000',
|
200
|
+
skinCode: '4aD37dJA'
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_hidden_recurring_payment_form_fields
|
205
|
+
recurring_snippet = <<-HTML
|
206
|
+
<form action="#{CGI.escapeHTML(Adyen::Form.url)}" method="post">
|
207
|
+
#{Adyen::Form.hidden_fields(@recurring_payment_attributes)}
|
208
|
+
</form>
|
209
|
+
HTML
|
210
|
+
|
211
|
+
for_each_xml_backend do
|
212
|
+
assert_adyen_recurring_payment_form recurring_snippet,
|
213
|
+
merchantAccount: 'OtherMerchant',
|
214
|
+
currencyCode: 'GBP',
|
215
|
+
paymentAmount: '10000',
|
216
|
+
recurringContract: 'DEFAULT',
|
217
|
+
skinCode: 'sk1nC0de'
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|