Class: PaypalAdaptive::Config
- Inherits:
-
Object
- Object
- PaypalAdaptive::Config
- Defined in:
- lib/paypal_adaptive/config.rb
Constant Summary collapse
- PAYPAL_BASE_URL_MAPPING =
{ :production => "https://www.paypal.com", :sandbox => "https://www.sandbox.paypal.com", :beta_sandbox => "https://www.beta-sandbox.paypal.com" }
- API_BASE_URL_MAPPING =
{ :production => "https://svcs.paypal.com", :sandbox => "https://svcs.sandbox.paypal.com", :beta_sandbox => "https://svcs.beta-sandbox.paypal.com" }
Instance Attribute Summary collapse
-
#api_base_url ⇒ Object
Returns the value of attribute api_base_url.
-
#api_cert_file ⇒ Object
Returns the value of attribute api_cert_file.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#paypal_base_url ⇒ Object
Returns the value of attribute paypal_base_url.
-
#ssl_cert_file ⇒ Object
Returns the value of attribute ssl_cert_file.
-
#ssl_cert_path ⇒ Object
Returns the value of attribute ssl_cert_path.
-
#verify_mode ⇒ Object
Returns the value of attribute verify_mode.
Instance Method Summary collapse
- #config_filepath ⇒ Object
-
#initialize(env = nil, config_override = {}) ⇒ Config
constructor
A new instance of Config.
- #retain_requests_for_test? ⇒ Boolean
- #validate_config(config) ⇒ Object
Constructor Details
#initialize(env = nil, config_override = {}) ⇒ Config
Returns a new instance of Config.
21 22 23 24 25 26 27 28 29 30 31 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 |
# File 'lib/paypal_adaptive/config.rb', line 21 def initialize(env=nil, config_override={}) config = YAML.load(ERB.new(File.new(config_filepath).read).result)[env] raise "Could not load settings from config file" unless config config.merge!(config_override) unless config_override.nil? validate_config(config) if config["retain_requests_for_test"] == true @retain_requests_for_test = true else pp_env = config['environment'].to_sym @ssl_cert_path = nil @ssl_cert_file = nil @api_cert_file = nil @paypal_base_url = PAYPAL_BASE_URL_MAPPING[pp_env] @api_base_url = API_BASE_URL_MAPPING[pp_env] # http.rb requires headers to be strings. Protect against ints in paypal_adaptive.yml config.update(config){ |key,v| v.to_s } @headers = { "X-PAYPAL-SECURITY-USERID" => config['username'], "X-PAYPAL-SECURITY-PASSWORD" => config['password'], "X-PAYPAL-APPLICATION-ID" => config['application_id'], "X-PAYPAL-REQUEST-DATA-FORMAT" => "JSON", "X-PAYPAL-RESPONSE-DATA-FORMAT" => "JSON" } @headers.merge!({"X-PAYPAL-SECURITY-SIGNATURE" => config['signature']}) if config['signature'] @ssl_cert_path = config['ssl_cert_path'] unless config['ssl_cert_path'].nil? || config['ssl_cert_path'].length == 0 @ssl_cert_file = config['ssl_cert_file'] unless config['ssl_cert_file'].nil? || config['ssl_cert_file'].length == 0 @api_cert_file = config['api_cert_file'] unless config['api_cert_file'].nil? || config['api_cert_file'].length == 0 @verify_mode = if pp_env == :sandbox OpenSSL::SSL::VERIFY_NONE else OpenSSL::SSL::VERIFY_PEER end end end |
Instance Attribute Details
#api_base_url ⇒ Object
Returns the value of attribute api_base_url.
18 19 20 |
# File 'lib/paypal_adaptive/config.rb', line 18 def api_base_url @api_base_url end |
#api_cert_file ⇒ Object
Returns the value of attribute api_cert_file.
18 19 20 |
# File 'lib/paypal_adaptive/config.rb', line 18 def api_cert_file @api_cert_file end |
#headers ⇒ Object
Returns the value of attribute headers.
18 19 20 |
# File 'lib/paypal_adaptive/config.rb', line 18 def headers @headers end |
#paypal_base_url ⇒ Object
Returns the value of attribute paypal_base_url.
18 19 20 |
# File 'lib/paypal_adaptive/config.rb', line 18 def paypal_base_url @paypal_base_url end |
#ssl_cert_file ⇒ Object
Returns the value of attribute ssl_cert_file.
18 19 20 |
# File 'lib/paypal_adaptive/config.rb', line 18 def ssl_cert_file @ssl_cert_file end |
#ssl_cert_path ⇒ Object
Returns the value of attribute ssl_cert_path.
18 19 20 |
# File 'lib/paypal_adaptive/config.rb', line 18 def ssl_cert_path @ssl_cert_path end |
#verify_mode ⇒ Object
Returns the value of attribute verify_mode.
18 19 20 |
# File 'lib/paypal_adaptive/config.rb', line 18 def verify_mode @verify_mode end |
Instance Method Details
#config_filepath ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/paypal_adaptive/config.rb', line 68 def config_filepath if defined?(Rails) Rails.root.join("config", "paypal_adaptive.yml") else File.join(File.dirname(__FILE__), "..", "..", "config", "paypal_adaptive.yml") end end |
#retain_requests_for_test? ⇒ Boolean
76 77 78 |
# File 'lib/paypal_adaptive/config.rb', line 76 def retain_requests_for_test? !!@retain_requests_for_test end |
#validate_config(config) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/paypal_adaptive/config.rb', line 60 def validate_config(config) raise "No username in paypal_adaptive.yml specified." unless config['username'] raise "No password in paypal_adaptive.yml specified." unless config['password'] raise "No application_id in paypal_adaptive.yml specified." unless config['application_id'] true end |