adyen 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/adyen.gemspec +2 -2
- data/lib/adyen.rb +24 -1
- data/lib/adyen/form.rb +9 -2
- data/spec/adyen_spec.rb +38 -5
- data/spec/spec_helper.rb +1 -0
- metadata +2 -2
data/adyen.gemspec
CHANGED
data/lib/adyen.rb
CHANGED
@@ -1,4 +1,27 @@
|
|
1
1
|
module Adyen
|
2
|
+
|
3
|
+
# Loads configuration settings from a Hash.
|
4
|
+
#
|
5
|
+
# This method is called recursively for every module. The second
|
6
|
+
# argument is used to denote the current working module.
|
7
|
+
def self.load_config(hash, mod = Adyen)
|
8
|
+
hash.each do |key, value|
|
9
|
+
if key.to_s =~ /^[a-z]/ && mod.respond_to?(:"#{key}=")
|
10
|
+
mod.send(:"#{key}=", value)
|
11
|
+
elsif key.to_s =~ /^[A-Z]/
|
12
|
+
begin
|
13
|
+
submodule = mod.const_get(key)
|
14
|
+
rescue LoadError => e
|
15
|
+
raise "Unknown Adyen module to configure: #{mod.name}::#{key}"
|
16
|
+
end
|
17
|
+
self.load_config(value, submodule)
|
18
|
+
else
|
19
|
+
raise "Unknown configuration variable: '#{key}' for #{mod}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# The Rails environment for which to use to Adyen "live" environment.
|
2
25
|
LIVE_RAILS_ENVIRONMENTS = ['production']
|
3
26
|
|
4
27
|
# Setter voor the current Adyen environment.
|
@@ -22,7 +45,7 @@ module Adyen
|
|
22
45
|
def self.const_missing(sym)
|
23
46
|
require "adyen/#{sym.to_s.downcase}"
|
24
47
|
return Adyen.const_get(sym)
|
25
|
-
rescue
|
48
|
+
rescue Exception => e
|
26
49
|
super(sym)
|
27
50
|
end
|
28
51
|
end
|
data/lib/adyen/form.rb
CHANGED
@@ -13,12 +13,19 @@ module Adyen
|
|
13
13
|
@skins ||= {}
|
14
14
|
end
|
15
15
|
|
16
|
+
def self.skins=(hash)
|
17
|
+
@skins = hash.inject({}) do |skins, (name, skin)|
|
18
|
+
skins[name.to_sym] = skin.merge(:name => name.to_sym)
|
19
|
+
skins
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
16
23
|
def self.register_skin(name, skin_code, shared_secret)
|
17
|
-
self.skins[name] = {:name => name, :skin_code => skin_code, :shared_secret => shared_secret }
|
24
|
+
self.skins[name.to_sym] = {:name => name.to_sym, :skin_code => skin_code, :shared_secret => shared_secret }
|
18
25
|
end
|
19
26
|
|
20
27
|
def self.skin_by_name(skin_name)
|
21
|
-
self.skins[skin_name]
|
28
|
+
self.skins[skin_name.to_sym]
|
22
29
|
end
|
23
30
|
|
24
31
|
def self.skin_by_code(skin_code)
|
data/spec/adyen_spec.rb
CHANGED
@@ -1,17 +1,50 @@
|
|
1
1
|
require "#{File.dirname(__FILE__)}/spec_helper.rb"
|
2
2
|
|
3
3
|
describe Adyen do
|
4
|
+
|
5
|
+
describe '.load_config' do
|
6
|
+
|
7
|
+
it "should set the environment correctly from the gonfiguration" do
|
8
|
+
Adyen.load_config(:environment => 'from_config')
|
9
|
+
Adyen.environment.should == 'from_config'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should recursively set settings for submodules" do
|
13
|
+
Adyen.load_config(:SOAP => { :username => 'foo', :password => 'bar' },
|
14
|
+
:Form => { :default_parameters => { :merchant_account => 'us' }})
|
15
|
+
Adyen::SOAP.username.should == 'foo'
|
16
|
+
Adyen::SOAP.password.should == 'bar'
|
17
|
+
Adyen::Form.default_parameters.should == { :merchant_account => 'us' }
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise an error when using a non-existing module" do
|
21
|
+
lambda { Adyen.load_config(:Unknown => { :a => 'b' }) }.should raise_error
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should raise an error when using a non-existing setting" do
|
25
|
+
lambda { Adyen.load_config(:blah => 1234) }.should raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should set skins from a hash configuration" do
|
29
|
+
Adyen.load_config(:Form => {:skins => {
|
30
|
+
:first => { :skin_code => '1234', :shared_secret => 'abcd' },
|
31
|
+
:second => { :skin_code => '5678', :shared_secret => 'efgh' }}})
|
32
|
+
|
33
|
+
Adyen::Form.skins.should == {
|
34
|
+
:first => {:skin_code => "1234", :name => :first, :shared_secret => "abcd" },
|
35
|
+
:second => {:skin_code => "5678", :name => :second, :shared_secret => "efgh" }}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
4
39
|
describe Adyen::Encoding do
|
5
40
|
it "should a hmac_base64 correcly" do
|
6
41
|
encoded_str = Adyen::Encoding.hmac_base64('bla', 'bla')
|
7
|
-
encoded_str.
|
8
|
-
encoded_str.size.should == 28
|
42
|
+
encoded_str.should == '6nItEkVpIYF+i1RwrEyQ7RHmrfU='
|
9
43
|
end
|
10
44
|
|
11
45
|
it "should gzip_base64 correcly" do
|
12
46
|
encoded_str = Adyen::Encoding.gzip_base64('bla')
|
13
|
-
encoded_str.
|
14
|
-
encoded_str.size.should == 32
|
47
|
+
encoded_str.length.should == 32
|
15
48
|
end
|
16
49
|
end
|
17
50
|
|
@@ -50,4 +83,4 @@ describe Adyen do
|
|
50
83
|
Adyen::Formatter::Price.from_cents(1234).should be_kind_of(BigDecimal)
|
51
84
|
end
|
52
85
|
end
|
53
|
-
end
|
86
|
+
end
|
data/spec/spec_helper.rb
CHANGED
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: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Willem van Bergen
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-11
|
13
|
+
date: 2009-12-11 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|