class PayPal::SDK::Core::Config

Config class is used to hold the configurations.

Examples

# To load configurations from file
Config.load('config/paypal.yml', 'development')

# Get configuration
Config.config   # load default configuration
Config.config(:development) # load development configuration
Config.config(:development, :app_id => "XYZ") # Override configuration

# Read configuration attributes
config = Config.config
config.username
config.endpoint

Attributes

app_id[RW]
cert_path[RW]
client_id[RW]
client_secret[RW]
device_ipaddress[RW]
end_point=[RW]
endpoint[RW]
http_proxy[RW]
http_timeout[RW]
ipn_end_point=[RW]
ipn_endpoint[RW]
merchant_end_point=[RW]
merchant_endpoint[RW]
mode[RW]
openid_client_id[RW]
openid_client_secret[RW]
openid_endpoint[RW]
openid_redirect_uri[RW]
password[RW]
platform_end_point=[RW]
platform_endpoint[RW]
rest_end_point[RW]
rest_end_point=[RW]
rest_endpoint[RW]
rest_token_end_point[RW]
rest_token_end_point=[RW]
rest_token_endpoint[RW]
sandbox_email_address[RW]
signature[RW]
subject[RW]
token[RW]
token_secret[RW]
username[RW]
verbose_logging[RW]

Public Class Methods

config(env = default_environment, override_configuration = {}) click to toggle source

Create or Load Config object based on given environment and configurations.

Attributes

  • env (Optional) – Environment name

  • override_configuration (Optional) – Override the configuration given in file.

Example

Config.config
Config.config(:development)
Config.config(:development, { :app_id => "XYZ" })
# File lib/paypal-sdk/core/config.rb, line 195
def config(env = default_environment, override_configuration = {})
  if env.is_a? Hash
    override_configuration = env
    env = default_environment
  end
  if override_configuration.nil? or override_configuration.empty?
    default_config(env)
  else
    default_config(env).dup.merge!(override_configuration)
  end
end
configurations() click to toggle source

Get raw configurations in Hash format.

# File lib/paypal-sdk/core/config.rb, line 227
def configurations
  @@configurations ||= read_configurations
end
configurations=(configs) click to toggle source

Set configuration

# File lib/paypal-sdk/core/config.rb, line 232
def configurations=(configs)
  @@config_cache   = {}
  @@configurations = configs && Hash[configs.map{|k,v| [k.to_s, v] }]
end
configure(options = {}, &block) click to toggle source
# File lib/paypal-sdk/core/config.rb, line 176
def configure(options = {}, &block)
  begin
    self.config.merge!(options)
  rescue Errno::ENOENT
    self.configurations = { default_environment => options }
  end
  block.call(self.config) if block
  self.config
end
Also aliased as: set_config
default_config(env = nil) click to toggle source
# File lib/paypal-sdk/core/config.rb, line 207
def default_config(env = nil)
  env = (env || default_environment).to_s
  if configurations[env]
    @@config_cache[env] ||= new(configurations[env])
  else
    raise Exceptions::MissingConfig.new("Configuration[#{env}] NotFound")
  end
end
default_environment() click to toggle source

Get default environment name

# File lib/paypal-sdk/core/config.rb, line 167
def default_environment
  @@default_environment ||= ENV['PAYPAL_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV'] || "development"
end
default_environment=(env) click to toggle source

Set default environment

# File lib/paypal-sdk/core/config.rb, line 172
def default_environment=(env)
  @@default_environment = env.to_s
end
load(file_name, default_env = default_environment) click to toggle source

Load configurations from file

Arguments

  • file_nameConfiguration file path

  • default_environment (Optional) – default environment configuration to load

Example

Config.load('config/paypal.yml', 'development')
# File lib/paypal-sdk/core/config.rb, line 159
def load(file_name, default_env = default_environment)
  @@config_cache        = {}
  @@configurations      = read_configurations(file_name)
  @@default_environment = default_env
  config
end
logger() click to toggle source

Get logger

# File lib/paypal-sdk/core/config.rb, line 222
def logger
  Logging.logger
end
logger=(logger) click to toggle source

Set logger

# File lib/paypal-sdk/core/config.rb, line 217
def logger=(logger)
  Logging.logger = logger
end
new(options) click to toggle source

Create Config object

Options(Hash)

  • username – Username

  • password – Password

  • signature (Optional if certificate present) – Signature

  • app_id – Application ID

  • cert_path (Optional if signature present) – Certificate file path

# File lib/paypal-sdk/core/config.rb, line 100
def initialize(options)
  merge!(options)
end
set_config(options = {}, &block)
Alias for: configure

Private Class Methods

read_configurations(file_name = "config/paypal.yml") click to toggle source

Read configurations from the given file name

Arguments

# File lib/paypal-sdk/core/config.rb, line 241
def read_configurations(file_name = "config/paypal.yml")
  erb = ERB.new(File.read(file_name))
  erb.filename = file_name
  YAML.load(erb.result)
end

Public Instance Methods

ca_file=(ca_file) click to toggle source
# File lib/paypal-sdk/core/config.rb, line 125
def ca_file=(ca_file)
  logger.warn '`ca_file=` is deprecated, Please configure `ca_file=` under `ssl_options`'
  self.ssl_options = { :ca_file => ca_file }
end
dev_central_url=(dev_central_url) click to toggle source
# File lib/paypal-sdk/core/config.rb, line 112
def dev_central_url=(dev_central_url)
  logger.warn '`dev_central_url=` is deprecated.'
end
http_verify_mode=(verify_mode) click to toggle source
# File lib/paypal-sdk/core/config.rb, line 130
def http_verify_mode=(verify_mode)
  logger.warn '`http_verify_mode=` is deprecated, Please configure `verify_mode=` under `ssl_options`'
  self.ssl_options = { :verify_mode => verify_mode }
end
logfile=(filename) click to toggle source
# File lib/paypal-sdk/core/config.rb, line 104
def logfile=(filename)
  logger.warn '`logfile=` is deprecated, Please use `PayPal::SDK::Core::Config.logger = Logger.new(STDERR)`'
end
merge!(options) click to toggle source

Override configurations

# File lib/paypal-sdk/core/config.rb, line 136
def merge!(options)
  options.each do |key, value|
    send("#{key}=", value)
  end
  self
end
redirect_url=(redirect_url) click to toggle source
# File lib/paypal-sdk/core/config.rb, line 108
def redirect_url=(redirect_url)
  logger.warn '`redirect_url=` is deprecated.'
end
required!(*names) click to toggle source

Validate required configuration

# File lib/paypal-sdk/core/config.rb, line 144
def required!(*names)
  names = names.select{|name| send(name).nil? }
  raise MissingConfig.new("Required configuration(#{names.join(", ")})") if names.any?
end
ssl_options() click to toggle source
# File lib/paypal-sdk/core/config.rb, line 116
def ssl_options
  @ssl_options ||= {}.freeze
end
ssl_options=(options) click to toggle source
# File lib/paypal-sdk/core/config.rb, line 120
def ssl_options=(options)
  options = Hash[options.map{|key, value| [key.to_sym, value] }]
  @ssl_options = ssl_options.merge(options).freeze
end