lib/adyen.rb in adyen-0.2.3 vs lib/adyen.rb in adyen-0.3.0
- old
+ new
@@ -1,52 +1,70 @@
+# The Adyen module is the container module for all Adyen related functionality,
+# which is implemented in submodules. This module only contains some global
+# configuration methods.
+#
+# The most important submodules are:
+# * {Adyen::Form} for generating payment form fields, generating redirect URLs
+# to the Adyen payment system, and generating and checking of signatures.
+# * {Adyen::Notification} for handling notifications sent by Adyen to your servers.
+# * {Adyen::SOAP} for communicating with the Adyen SOAP services for payment
+# maintenance and issuing recurring payments.
module Adyen
# Loads configuration settings from a Hash.
#
- # This method is called recursively for every module. The second
- # argument is used to denote the current working module.
+ # @param [Hash] hash The (nested Hash) with configuration variables.
+ # @param [Module] mod The current working module. This parameter is used
+ # to recursively traverse the hash for submodules.
+ # @raise [StandardError] An exception is raised of an unkown configuration
+ # setting is encountered in the hash.
def self.load_config(hash, mod = Adyen)
hash.each do |key, value|
if key.to_s =~ /^[a-z]/ && mod.respond_to?(:"#{key}=")
mod.send(:"#{key}=", value)
elsif key.to_s =~ /^[A-Z]/
- begin
- submodule = mod.const_get(key)
- rescue LoadError => e
- raise "Unknown Adyen module to configure: #{mod.name}::#{key}"
- end
- self.load_config(value, submodule)
+ self.load_config(value, mod.const_get(key))
else
raise "Unknown configuration variable: '#{key}' for #{mod}"
end
end
end
# The Rails environment for which to use to Adyen "live" environment.
LIVE_RAILS_ENVIRONMENTS = ['production']
# Setter voor the current Adyen environment.
- # Must be either 'test' or 'live'
+ # @param ['test', 'live'] env The Adyen environment to use
def self.environment=(env)
@environment = env
end
- # Returns the current Adyen environment.
- # Returns either 'test' or 'live'.
+ # Returns the current Adyen environment, either test or live.
+ #
+ # It will return the +override+ value if set, it will return the value set
+ # using {Adyen.environment=} otherwise. If this value also isn't set, the
+ # environemtn is determined with {Adyen.autodetect_environment}.
+ #
+ # @param ['test', 'live'] override An environemt to override the default with.
+ # @return ['test', 'live'] The Adyen environment that is currently being used.
def self.environment(override = nil)
override || @environment || Adyen.autodetect_environment
end
- # Autodetects the Adyen environment based on the RAILS_ENV constant
+ # Autodetects the Adyen environment based on the RAILS_ENV constant.
+ # @return ['test', 'live'] The Adyen environment that corresponds to the Rails environment
def self.autodetect_environment
(defined?(RAILS_ENV) && Adyen::LIVE_RAILS_ENVIRONMENTS.include?(RAILS_ENV.to_s.downcase)) ? 'live' : 'test'
end
# Loads submodules on demand, so that dependencies are not required.
+ # @param [Symbol] sym The name of the submodule
+ # @return [Module] The actual loaded submodule.
+ # @raise [LoadError, NameError] If the submodule cannot be loaded
def self.const_missing(sym)
require "adyen/#{sym.to_s.downcase}"
return Adyen.const_get(sym)
- rescue Exception => e
+ rescue Exception
super(sym)
end
end
require 'adyen/encoding'