adyen 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -1
- data/lib/adyen.rb +5 -19
- data/lib/adyen/api.rb +1 -2
- data/lib/adyen/api/recurring_service.rb +1 -5
- data/lib/adyen/api/xml_querier.rb +1 -1
- data/lib/adyen/base.rb +17 -0
- data/lib/adyen/configuration.rb +2 -3
- data/lib/adyen/form.rb +2 -0
- data/lib/adyen/hpp/signature.rb +6 -39
- data/lib/adyen/rest.rb +2 -1
- data/lib/adyen/rest/request.rb +4 -0
- data/lib/adyen/rest/response.rb +2 -0
- data/lib/adyen/rest/signature.rb +27 -0
- data/lib/adyen/signature.rb +76 -0
- data/lib/adyen/version.rb +1 -1
- data/spec/spec_helper.rb +0 -1
- data/test/form_test.rb +6 -5
- data/test/functional/payment_authorisation_api_test.rb +1 -0
- data/test/functional/payment_modification_api_test.rb +1 -0
- data/test/helpers/capybara.rb +12 -0
- data/test/hpp/signature_test.rb +2 -1
- data/test/integration/hpp_integration_test.rb +1 -1
- data/test/integration/payment_using_3d_secure_integration_test.rb +1 -0
- data/test/integration/payment_with_client_side_encryption_integration_test.rb +1 -1
- data/test/rest/signature_test.rb +36 -0
- data/test/rest_list_recurring_details_response_test.rb +1 -0
- data/test/rest_request_test.rb +1 -0
- data/test/rest_response_test.rb +1 -0
- data/test/signature_test.rb +76 -0
- data/test/test_helper.rb +1 -13
- data/test/util_test.rb +4 -3
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b0487de131168302d566b9dbe912c921ebf4b8a
|
4
|
+
data.tar.gz: f9913d706f1280146dfc27c5e6bbcb7f2727ea03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6914750599b1a3ecdabd6d7000dde4ea4c2131f85c691d4d4ad693a6ba8cdbf4b95a2f4cc7a41b54b83ae7351a1bac2b18c6d4eb7fb69f64523e7ee48686994c
|
7
|
+
data.tar.gz: 7401dcb3c7808508fe3da582a172150af1441a3dba9bf7744da5a91b77b78be94c0b75772ed671153258b9c5a429e5b9bdb786960619d8d7216eb5f609912bac
|
data/.travis.yml
CHANGED
@@ -5,15 +5,18 @@ rvm:
|
|
5
5
|
- "2.0"
|
6
6
|
- "2.1"
|
7
7
|
- "2.2"
|
8
|
+
- "2.3.1"
|
9
|
+
- "jruby-9.0"
|
8
10
|
- "ruby-head"
|
9
11
|
- "rbx-2"
|
10
|
-
- "jruby-19mode"
|
11
12
|
- "jruby-head"
|
12
13
|
matrix:
|
13
14
|
allow_failures:
|
14
15
|
- rvm: jruby-head
|
15
16
|
- rvm: ruby-head
|
16
17
|
- rvm: rbx-2
|
18
|
+
before_install:
|
19
|
+
- bundle --version || gem install bundler
|
17
20
|
before_script:
|
18
21
|
- cp spec/functional/initializer.rb.ci spec/functional/initializer.rb
|
19
22
|
env:
|
@@ -22,3 +25,6 @@ env:
|
|
22
25
|
- ADYEN_API_USERNAME: "ws@Company.VanBergen"
|
23
26
|
- ADYEN_API_PASSWORD: "7phtHzbfnzsp"
|
24
27
|
sudo: false
|
28
|
+
branches:
|
29
|
+
only:
|
30
|
+
- master
|
data/lib/adyen.rb
CHANGED
@@ -7,28 +7,14 @@
|
|
7
7
|
# to the Adyen payment system, and generating and checking of signatures.
|
8
8
|
# * {Adyen::API} for communicating with the Adyen SOAP services for issuing
|
9
9
|
# (recurring) payments and recurring contract maintenance.
|
10
|
-
|
11
|
-
|
12
|
-
# Basic exception class for Adyen
|
13
|
-
class Error < ::StandardError
|
14
|
-
end
|
15
|
-
|
16
|
-
# @return [Configuration] The configuration singleton.
|
17
|
-
def self.configuration
|
18
|
-
@configuration ||= Adyen::Configuration.new
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.configuration=(configuration)
|
22
|
-
@configuration = configuration
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
10
|
+
require 'adyen/base'
|
26
11
|
require 'adyen/version'
|
27
|
-
|
28
|
-
require 'adyen/util'
|
29
|
-
require 'adyen/hpp/signature'
|
12
|
+
|
30
13
|
require 'adyen/form'
|
31
14
|
require 'adyen/api'
|
32
15
|
require 'adyen/rest'
|
33
16
|
|
17
|
+
# TODO: Move into main hpp file once it exists
|
18
|
+
require 'adyen/hpp/signature'
|
19
|
+
|
34
20
|
require 'adyen/railtie' if defined?(::Rails) && ::Rails::VERSION::MAJOR >= 3
|
data/lib/adyen/api.rb
CHANGED
@@ -169,12 +169,8 @@ module Adyen
|
|
169
169
|
class StoreTokenResponse < Response
|
170
170
|
response_attrs :response, :recurring_detail_reference
|
171
171
|
|
172
|
-
def recurring_detail_reference
|
173
|
-
params[:recurring_detail_reference]
|
174
|
-
end
|
175
|
-
|
176
172
|
def success?
|
177
|
-
super &&
|
173
|
+
super && response == 'Success'
|
178
174
|
end
|
179
175
|
|
180
176
|
alias_method :stored?, :success?
|
data/lib/adyen/base.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Adyen
|
2
|
+
|
3
|
+
# Basic exception class for Adyen
|
4
|
+
class Error < ::StandardError
|
5
|
+
end
|
6
|
+
|
7
|
+
# @return [Configuration] The configuration singleton.
|
8
|
+
def self.configuration
|
9
|
+
@configuration ||= Adyen::Configuration.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configuration=(configuration)
|
13
|
+
@configuration = configuration
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'adyen/configuration'
|
data/lib/adyen/configuration.rb
CHANGED
@@ -5,6 +5,7 @@ class Adyen::Configuration
|
|
5
5
|
@default_form_params = {}
|
6
6
|
@form_skins = {}
|
7
7
|
@payment_flow = :select
|
8
|
+
@environment = nil
|
8
9
|
end
|
9
10
|
|
10
11
|
# The Rails environment for which to use to Adyen "live" environment.
|
@@ -157,9 +158,7 @@ class Adyen::Configuration
|
|
157
158
|
#
|
158
159
|
# @return [Hash, nil] A hash with the skin information, or nil if not found.
|
159
160
|
def form_skin_by_code(skin_code)
|
160
|
-
|
161
|
-
skin.last
|
162
|
-
end
|
161
|
+
@form_skins.values.find { |skin| skin[:skin_code] == skin_code }
|
163
162
|
end
|
164
163
|
|
165
164
|
# Returns the shared secret belonging to a skin.
|
data/lib/adyen/form.rb
CHANGED
data/lib/adyen/hpp/signature.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'base64'
|
1
|
+
require 'adyen/signature'
|
3
2
|
|
4
3
|
module Adyen
|
5
4
|
module HPP
|
@@ -8,15 +7,13 @@ module Adyen
|
|
8
7
|
extend self
|
9
8
|
|
10
9
|
# Sign the parameters with the given shared secret
|
11
|
-
# @param [Hash] params The set of parameters to sign
|
10
|
+
# @param [Hash] params The set of parameters to sign.
|
12
11
|
# @param [String] shared_secret The shared secret for signing/verification. Can also be sent in the
|
13
12
|
# params hash with the `sharedSecret` key.
|
14
13
|
# @return [Hash] params The params that were passed in plus a new `merchantSig` param
|
15
14
|
def sign(params, shared_secret = nil)
|
16
|
-
|
17
|
-
|
18
|
-
sig = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), Array(shared_secret).pack("H*"), string_to_sign(params))
|
19
|
-
params.merge('merchantSig' => Base64.encode64(sig).strip)
|
15
|
+
params["sharedSecret"] ||= shared_secret
|
16
|
+
params.merge('merchantSig' => Adyen::Signature.sign(params))
|
20
17
|
end
|
21
18
|
|
22
19
|
# Verify the parameters with the given shared secret
|
@@ -26,40 +23,10 @@ module Adyen
|
|
26
23
|
# params hash with the `sharedSecret` key.
|
27
24
|
# @return [Boolean] true if the `merchantSig` in the params matches our calculated signature
|
28
25
|
def verify(params, shared_secret = nil)
|
26
|
+
params["sharedSecret"] ||= shared_secret
|
29
27
|
their_sig = params.delete('merchantSig')
|
30
28
|
raise ArgumentError, "params must include 'merchantSig' for verification" if their_sig.empty?
|
31
|
-
|
32
|
-
secure_compare(their_sig, our_sig)
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def string_to_sign(params)
|
38
|
-
(sorted_keys(params) + sorted_values(params)).map{ |el| escape_value(el) }.join(':')
|
39
|
-
end
|
40
|
-
|
41
|
-
def sorted_keys(hash)
|
42
|
-
hash.sort.map{ |el| el[0] }
|
43
|
-
end
|
44
|
-
|
45
|
-
def sorted_values(hash)
|
46
|
-
hash.sort.map{ |el| el[1] }
|
47
|
-
end
|
48
|
-
|
49
|
-
def escape_value(value)
|
50
|
-
value.gsub(':', '\\:').gsub('\\', '\\\\')
|
51
|
-
end
|
52
|
-
|
53
|
-
# Constant-time compare for two fixed-length strings
|
54
|
-
# Stolen from https://github.com/rails/rails/commit/c8c660002f4b0e9606de96325f20b95248b6ff2d
|
55
|
-
def secure_compare(a, b)
|
56
|
-
return false unless a.bytesize == b.bytesize
|
57
|
-
|
58
|
-
l = a.unpack "C#{a.bytesize}"
|
59
|
-
|
60
|
-
res = 0
|
61
|
-
b.each_byte { |byte| res |= byte ^ l.shift }
|
62
|
-
res == 0
|
29
|
+
Adyen::Signature.verify(params, their_sig)
|
63
30
|
end
|
64
31
|
end
|
65
32
|
end
|
data/lib/adyen/rest.rb
CHANGED
data/lib/adyen/rest/request.rb
CHANGED
data/lib/adyen/rest/response.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'adyen/signature'
|
2
|
+
|
3
|
+
module Adyen
|
4
|
+
module REST
|
5
|
+
# The Signature module can sign and verify HMAC SHA-256 signatures for API
|
6
|
+
module Signature
|
7
|
+
extend self
|
8
|
+
|
9
|
+
# Sign the parameters with the given shared secret
|
10
|
+
# @param [Hash] params The set of parameters to sign. Should sent `sharedSecret` to sign.
|
11
|
+
# @return [String] signature from parameters
|
12
|
+
def sign(params)
|
13
|
+
Adyen::Signature.sign(params, :rest)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Verify the parameters with the given shared secret
|
17
|
+
# @param [Hash] params The set of parameters to verify.
|
18
|
+
# Should include `sharedSecret` param to sign and the `hmacSignature` param to compare with the signature calculated
|
19
|
+
# @return [Boolean] true if the `hmacSignature` in the params matches our calculated signature
|
20
|
+
def verify(params)
|
21
|
+
their_sig = params.delete('hmacSignature')
|
22
|
+
raise ArgumentError, "params must include 'hmacSignature' for verification" if their_sig.empty?
|
23
|
+
Adyen::Signature.verify(params, their_sig, :rest)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
module Adyen
|
5
|
+
# The Signature module generic to sign and verify HMAC SHA-256 signatures
|
6
|
+
module Signature
|
7
|
+
extend self
|
8
|
+
|
9
|
+
# Sign the parameters with the given shared secret
|
10
|
+
# @param [Hash] params The set of parameters to verify. Must include a `shared_secret` param for signing/verification
|
11
|
+
#
|
12
|
+
# @param [String] type The type to sign (:hpp or :rest). Default is :hpp
|
13
|
+
# @return [String] The signature
|
14
|
+
def sign(params, type = :hpp)
|
15
|
+
shared_secret = params.delete('sharedSecret')
|
16
|
+
raise ArgumentError, 'Cannot sign without a shared secret' if shared_secret.nil?
|
17
|
+
sig = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), Array(shared_secret).pack("H*"), string_to_sign(params, type))
|
18
|
+
Base64.encode64(sig).strip
|
19
|
+
end
|
20
|
+
|
21
|
+
# Compare a signature calculated with anoter HMAC Signature
|
22
|
+
# @param [Hash] params The set of parameters to verify. Must include a `shared_secret`
|
23
|
+
# param for signing/verification
|
24
|
+
# @param [String] hmacSignature will be compared to the signature calculated.
|
25
|
+
# @return [Boolean] true if the `hmacSignature` matches our calculated signature
|
26
|
+
def verify(params, hmacSignature, type = :hpp)
|
27
|
+
raise ArgumentError,"hmacSignature cannot be empty for verification" if hmacSignature.empty?
|
28
|
+
our_sig = sign(params, type)
|
29
|
+
secure_compare(hmacSignature, our_sig)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def string_to_sign(params, type)
|
35
|
+
string = ''
|
36
|
+
if type == :hpp
|
37
|
+
string = sorted_keys(params) + sorted_values(params)
|
38
|
+
elsif type == :rest
|
39
|
+
keys = %w(pspReference originalReference merchantAccountCode merchantReference value currency eventCode success)
|
40
|
+
string = sorted_values(params, keys)
|
41
|
+
else
|
42
|
+
raise NotImplementedError, 'Type sign not implemented'
|
43
|
+
end
|
44
|
+
|
45
|
+
string.map{ |el| escape_value(el) }.join(':')
|
46
|
+
end
|
47
|
+
|
48
|
+
def sorted_keys(hash, keys_to_sort = nil)
|
49
|
+
hash.sort.map{ |el| el[0] }
|
50
|
+
end
|
51
|
+
|
52
|
+
def sorted_values(hash, keys_to_sort = nil)
|
53
|
+
if keys_to_sort.is_a? Array
|
54
|
+
keys_to_sort.map { |key| hash[key] }
|
55
|
+
else
|
56
|
+
hash.sort.map{ |el| el[1] }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def escape_value(value)
|
61
|
+
value.gsub(':', '\\:').gsub('\\', '\\\\')
|
62
|
+
end
|
63
|
+
|
64
|
+
# Constant-time compare for two fixed-length strings
|
65
|
+
# Stolen from https://github.com/rails/rails/commit/c8c660002f4b0e9606de96325f20b95248b6ff2d
|
66
|
+
def secure_compare(a, b)
|
67
|
+
return false unless a.bytesize == b.bytesize
|
68
|
+
|
69
|
+
l = a.unpack "C#{a.bytesize}"
|
70
|
+
|
71
|
+
res = 0
|
72
|
+
b.each_byte { |byte| res |= byte ^ l.shift }
|
73
|
+
res == 0
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/adyen/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/test/form_test.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'adyen/form'
|
2
3
|
|
3
4
|
class FormTest < Minitest::Test
|
4
5
|
include Adyen::Matchers
|
@@ -238,23 +239,23 @@ class FormTest < Minitest::Test
|
|
238
239
|
'merchantSig' => 'ytt3QxWoEhAskUzUne0P5VA9lPw='
|
239
240
|
}
|
240
241
|
|
241
|
-
assert_equal params[
|
242
|
+
assert_equal params['merchantSig'], Adyen::Form.redirect_signature(params)
|
242
243
|
|
243
244
|
assert Adyen::Form.redirect_signature_check(params) # shared secret from registered skin
|
244
245
|
assert Adyen::Form.redirect_signature_check(params, 'Kah942*$7sdp0)') # explicitly provided shared secret
|
245
246
|
|
246
|
-
refute Adyen::Form.redirect_signature_check(params.merge(skinCode
|
247
|
+
refute Adyen::Form.redirect_signature_check(params.merge('skinCode' => 'sk1nC0de'))
|
247
248
|
refute Adyen::Form.redirect_signature_check(params, 'wrong_shared_secret')
|
248
249
|
|
249
|
-
refute Adyen::Form.redirect_signature_check(params.merge(pspReference
|
250
|
-
refute Adyen::Form.redirect_signature_check(params.merge(merchantSig
|
250
|
+
refute Adyen::Form.redirect_signature_check(params.merge('pspReference' => 'tampered'))
|
251
|
+
refute Adyen::Form.redirect_signature_check(params.merge('merchantSig' => 'tampered'))
|
251
252
|
|
252
253
|
assert_raises(ArgumentError) { Adyen::Form.redirect_signature_check(nil) }
|
253
254
|
assert_raises(ArgumentError) { Adyen::Form.redirect_signature_check({}) }
|
254
255
|
assert_raises(ArgumentError) { Adyen::Form.redirect_signature_check(params.delete(:skinCode)) }
|
255
256
|
end
|
256
257
|
|
257
|
-
def
|
258
|
+
def test_redirect_signature_check_with_escaped_params
|
258
259
|
Adyen.configuration.register_form_skin(:testing, 'tifSfXeX', 'testing123', :merchant_account => 'VanBergenORG')
|
259
260
|
|
260
261
|
# http://example.com/result?merchantReference=HPP+test+order+%25231&skinCode=tifSfXeX&shopperLocale=en_GB&paymentMethod=visa&authResult=AUTHORISED&pspReference=8814131153369759&merchantSig=il8cjgOiG4N9l2PlSf6h4EVQ6hk%253D
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'helpers/example_server'
|
2
|
+
require 'capybara/dsl'
|
3
|
+
require 'capybara/poltergeist'
|
4
|
+
|
5
|
+
Capybara.register_driver :poltergeist do |app|
|
6
|
+
Capybara::Poltergeist::Driver.new(app, phantomjs_options: ['--ssl-protocol=any'])
|
7
|
+
end
|
8
|
+
|
9
|
+
Capybara.default_driver = :poltergeist
|
10
|
+
Capybara.javascript_driver = :poltergeist
|
11
|
+
Capybara.app = Adyen::ExampleServer
|
12
|
+
|
data/test/hpp/signature_test.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'adyen/hpp/signature'
|
2
3
|
|
3
|
-
class
|
4
|
+
class HPPSignatureTest < Minitest::Test
|
4
5
|
def setup
|
5
6
|
# values from https://docs.adyen.com/pages/viewpage.action?pageId=5376964
|
6
7
|
@shared_secret = "4468D9782DEF54FCD706C9100C71EC43932B1EBC2ACF6BA0560C05AAA7550C48"
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'adyen/rest/signature'
|
3
|
+
|
4
|
+
class RESTSignatureTest < Minitest::Test
|
5
|
+
def setup
|
6
|
+
# values from https://docs.adyen.com/pages/viewpage.action?pageId=5376964
|
7
|
+
|
8
|
+
@expected_sig = 'S+5bAYKLd+L2A07Pal0pG/qBarnInaIe709YNzNcHOA='
|
9
|
+
|
10
|
+
@raw_params = {
|
11
|
+
'hmacSignature' => @expected_sig,
|
12
|
+
'pspReference' => '7914073251449896',
|
13
|
+
'originalReference' => '',
|
14
|
+
'eventCode' => 'AUTHORISATION',
|
15
|
+
'merchantAccountCode' => 'TestMerchant',
|
16
|
+
'merchantReference' => 'TestPayment-1407325143704',
|
17
|
+
'success' => 'true',
|
18
|
+
'value' => '8650',
|
19
|
+
'currency' => 'EUR',
|
20
|
+
'sharedSecret' => '009E9E92268087AAD241638D3325201AFC8AAE6F3DCD369B6D32E87129FFAB10'
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_sign
|
25
|
+
assert_equal @expected_sig, Adyen::REST::Signature.sign(@raw_params)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_verify_succeeds_with_same_secret
|
29
|
+
assert_equal true, Adyen::REST::Signature.verify(@raw_params)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_verification_fails_with_different_secret
|
33
|
+
params = @raw_params.merge('hmacSignature' => '123')
|
34
|
+
assert_equal false, Adyen::REST::Signature.verify(params)
|
35
|
+
end
|
36
|
+
end
|
data/test/rest_request_test.rb
CHANGED
data/test/rest_response_test.rb
CHANGED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'adyen/signature'
|
3
|
+
|
4
|
+
class SignatureTest < Minitest::Test
|
5
|
+
# HPP Signature
|
6
|
+
def hpp_raw_params
|
7
|
+
{
|
8
|
+
'merchantAccount' => 'TestMerchant',
|
9
|
+
'currencyCode' => 'EUR',
|
10
|
+
'paymentAmount' => '199',
|
11
|
+
'sessionValidity' => '2015-06-25T10:31:06Z',
|
12
|
+
'shipBeforeDate' => '2015-07-01',
|
13
|
+
'shopperLocale' => 'en_GB',
|
14
|
+
'merchantReference' => 'SKINTEST-1435226439255',
|
15
|
+
'skinCode' => 'X7hsNDWp',
|
16
|
+
'sharedSecret' => hpp_shared_secret
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def hpp_expected_sig
|
21
|
+
'GJ1asjR5VmkvihDJxCd8yE2DGYOKwWwJCBiV3R51NFg='
|
22
|
+
end
|
23
|
+
|
24
|
+
def hpp_shared_secret
|
25
|
+
'4468D9782DEF54FCD706C9100C71EC43932B1EBC2ACF6BA0560C05AAA7550C48'
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_hpp_sign
|
29
|
+
signed_params = Adyen::Signature.sign(hpp_raw_params)
|
30
|
+
assert_equal hpp_expected_sig, signed_params
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_hpp_verify_succeeds_with_same_secret
|
34
|
+
assert_equal true, Adyen::Signature.verify(hpp_raw_params, hpp_expected_sig)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_hpp_verification_fails_with_different_secret
|
38
|
+
assert_equal false, Adyen::Signature.verify(hpp_raw_params, '1234')
|
39
|
+
end
|
40
|
+
|
41
|
+
# Rest Signature
|
42
|
+
def rest_raw_params
|
43
|
+
{
|
44
|
+
'pspReference' => '7914073251449896',
|
45
|
+
'originalReference' => '',
|
46
|
+
'eventCode' => 'AUTHORISATION',
|
47
|
+
'merchantAccountCode' => 'TestMerchant',
|
48
|
+
'merchantReference' => 'TestPayment-1407325143704',
|
49
|
+
'success' => 'true',
|
50
|
+
'value' => '8650',
|
51
|
+
'currency' => 'EUR',
|
52
|
+
'sharedSecret' => rest_shared_secret
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def rest_expected_sig
|
57
|
+
'S+5bAYKLd+L2A07Pal0pG/qBarnInaIe709YNzNcHOA='
|
58
|
+
end
|
59
|
+
|
60
|
+
def rest_shared_secret
|
61
|
+
'009E9E92268087AAD241638D3325201AFC8AAE6F3DCD369B6D32E87129FFAB10'
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_rest_sign
|
65
|
+
signed_params = Adyen::Signature.sign(rest_raw_params, :rest)
|
66
|
+
assert_equal rest_expected_sig, signed_params
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_rest_verify_succeeds_with_same_secret
|
70
|
+
assert_equal true, Adyen::Signature.verify(rest_raw_params, rest_expected_sig, :rest)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_rest_verification_fails_with_different_secret
|
74
|
+
assert_equal false, Adyen::Signature.verify(rest_raw_params, '1234', :rest)
|
75
|
+
end
|
76
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -2,13 +2,11 @@
|
|
2
2
|
require 'minitest/autorun'
|
3
3
|
require 'minitest/pride'
|
4
4
|
require 'mocha/setup'
|
5
|
-
require 'capybara/poltergeist'
|
6
5
|
|
7
|
-
require 'adyen'
|
6
|
+
require 'adyen/base'
|
8
7
|
require 'adyen/matchers'
|
9
8
|
|
10
9
|
require 'helpers/configure_adyen'
|
11
|
-
require 'helpers/example_server'
|
12
10
|
require 'helpers/test_cards'
|
13
11
|
|
14
12
|
require 'pp'
|
@@ -44,13 +42,3 @@ module Adyen::Test
|
|
44
42
|
end
|
45
43
|
end
|
46
44
|
end
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
Capybara.register_driver :poltergeist do |app|
|
51
|
-
Capybara::Poltergeist::Driver.new(app, phantomjs_options: ['--ssl-protocol=any'])
|
52
|
-
end
|
53
|
-
|
54
|
-
Capybara.default_driver = :poltergeist
|
55
|
-
Capybara.javascript_driver = :poltergeist
|
56
|
-
Capybara.app = Adyen::ExampleServer
|
data/test/util_test.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require 'test_helper'
|
3
|
+
require 'adyen/util'
|
3
4
|
|
4
5
|
class UtilTest < Minitest::Test
|
5
6
|
def test_hmac_base64_encoding
|
@@ -13,7 +14,7 @@ class UtilTest < Minitest::Test
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def test_date_formatting
|
16
|
-
assert_match
|
17
|
+
assert_match(/^\d{4}-\d{2}-\d{2}$/, Adyen::Util.format_date(Date.today))
|
17
18
|
assert_equal '2009-01-01', Adyen::Util.format_date('2009-01-01')
|
18
19
|
|
19
20
|
assert_raises(ArgumentError) { Adyen::Util.format_date('2009-1-1') }
|
@@ -21,8 +22,8 @@ class UtilTest < Minitest::Test
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def test_timestamp_formatting
|
24
|
-
assert_match
|
25
|
-
assert_match
|
25
|
+
assert_match(/^\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}Z$/, Adyen::Util.format_timestamp(Time.now))
|
26
|
+
assert_match(/^\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}Z$/, Adyen::Util.format_timestamp(DateTime.now))
|
26
27
|
assert_equal '2009-01-01T11:11:11Z', Adyen::Util.format_timestamp('2009-01-01T11:11:11Z')
|
27
28
|
|
28
29
|
assert_raises(ArgumentError) { Adyen::Util.format_timestamp('2009-01-01 11:11:11') }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adyen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Willem van Bergen
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-
|
14
|
+
date: 2016-06-15 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rake
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- lib/adyen/api/templates/recurring_service.rb
|
164
164
|
- lib/adyen/api/test_helpers.rb
|
165
165
|
- lib/adyen/api/xml_querier.rb
|
166
|
+
- lib/adyen/base.rb
|
166
167
|
- lib/adyen/configuration.rb
|
167
168
|
- lib/adyen/form.rb
|
168
169
|
- lib/adyen/hpp/signature.rb
|
@@ -177,6 +178,8 @@ files:
|
|
177
178
|
- lib/adyen/rest/modify_payment.rb
|
178
179
|
- lib/adyen/rest/request.rb
|
179
180
|
- lib/adyen/rest/response.rb
|
181
|
+
- lib/adyen/rest/signature.rb
|
182
|
+
- lib/adyen/signature.rb
|
180
183
|
- lib/adyen/templates/notification_migration.rb
|
181
184
|
- lib/adyen/templates/notification_model.rb
|
182
185
|
- lib/adyen/util.rb
|
@@ -195,6 +198,7 @@ files:
|
|
195
198
|
- test/form_test.rb
|
196
199
|
- test/functional/payment_authorisation_api_test.rb
|
197
200
|
- test/functional/payment_modification_api_test.rb
|
201
|
+
- test/helpers/capybara.rb
|
198
202
|
- test/helpers/configure_adyen.rb
|
199
203
|
- test/helpers/example_server.rb
|
200
204
|
- test/helpers/public/adyen.encrypt.js
|
@@ -209,9 +213,11 @@ files:
|
|
209
213
|
- test/integration/hpp_integration_test.rb
|
210
214
|
- test/integration/payment_using_3d_secure_integration_test.rb
|
211
215
|
- test/integration/payment_with_client_side_encryption_integration_test.rb
|
216
|
+
- test/rest/signature_test.rb
|
212
217
|
- test/rest_list_recurring_details_response_test.rb
|
213
218
|
- test/rest_request_test.rb
|
214
219
|
- test/rest_response_test.rb
|
220
|
+
- test/signature_test.rb
|
215
221
|
- test/test_helper.rb
|
216
222
|
- test/util_test.rb
|
217
223
|
- yard_extensions.rb
|
@@ -261,6 +267,7 @@ test_files:
|
|
261
267
|
- test/form_test.rb
|
262
268
|
- test/functional/payment_authorisation_api_test.rb
|
263
269
|
- test/functional/payment_modification_api_test.rb
|
270
|
+
- test/helpers/capybara.rb
|
264
271
|
- test/helpers/configure_adyen.rb
|
265
272
|
- test/helpers/example_server.rb
|
266
273
|
- test/helpers/public/adyen.encrypt.js
|
@@ -275,8 +282,10 @@ test_files:
|
|
275
282
|
- test/integration/hpp_integration_test.rb
|
276
283
|
- test/integration/payment_using_3d_secure_integration_test.rb
|
277
284
|
- test/integration/payment_with_client_side_encryption_integration_test.rb
|
285
|
+
- test/rest/signature_test.rb
|
278
286
|
- test/rest_list_recurring_details_response_test.rb
|
279
287
|
- test/rest_request_test.rb
|
280
288
|
- test/rest_response_test.rb
|
289
|
+
- test/signature_test.rb
|
281
290
|
- test/test_helper.rb
|
282
291
|
- test/util_test.rb
|