Class: PaypalAdaptive::Config
- Inherits:
-
Object
- Object
- PaypalAdaptive::Config
- Defined in:
- lib/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.
-
#config_filepath ⇒ Object
Returns the value of attribute config_filepath.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#paypal_base_url ⇒ Object
Returns the value of attribute paypal_base_url.
-
#ssl_ca_cert_path ⇒ Object
Returns the value of attribute ssl_ca_cert_path.
-
#ssl_cert_file ⇒ Object
Returns the value of attribute ssl_cert_file.
Instance Method Summary collapse
-
#initialize(env = nil, config_override = nil) ⇒ Config
constructor
A new instance of Config.
- #load(environment, config_override) ⇒ Object
- #retain_requests_for_test? ⇒ Boolean
Constructor Details
#initialize(env = nil, config_override = nil) ⇒ Config
Returns a new instance of Config.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/config.rb', line 20 def initialize(env=nil, config_override=nil) if env #non-rails env @config_filepath = File.join(File.dirname(__FILE__), "..", "config", "paypal_adaptive.yml") load(env, config_override) else @config_filepath = File.join(Rails.root, "config", "paypal_adaptive.yml") load(Rails.env, config_override) end end |
Instance Attribute Details
#api_base_url ⇒ Object
Returns the value of attribute api_base_url.
18 19 20 |
# File 'lib/config.rb', line 18 def api_base_url @api_base_url end |
#config_filepath ⇒ Object
Returns the value of attribute config_filepath.
18 19 20 |
# File 'lib/config.rb', line 18 def config_filepath @config_filepath end |
#headers ⇒ Object
Returns the value of attribute headers.
18 19 20 |
# File 'lib/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/config.rb', line 18 def paypal_base_url @paypal_base_url end |
#ssl_ca_cert_path ⇒ Object
Returns the value of attribute ssl_ca_cert_path.
18 19 20 |
# File 'lib/config.rb', line 18 def ssl_ca_cert_path @ssl_ca_cert_path end |
#ssl_cert_file ⇒ Object
Returns the value of attribute ssl_cert_file.
18 19 20 |
# File 'lib/config.rb', line 18 def ssl_cert_file @ssl_cert_file end |
Instance Method Details
#load(environment, config_override) ⇒ Object
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 59 60 61 62 63 64 65 66 67 |
# File 'lib/config.rb', line 31 def load(environment, config_override) config = YAML.load(ERB.new(File.new(@config_filepath).read).result)[environment] config.merge!(config_override) unless config_override.nil? if config["retain_requests_for_test"] == true @retain_requests_for_test = true else pp_env = config['environment'].to_sym @ssl_ca_cert_path = nil @ssl_cert_file = nil @paypal_base_url = PAYPAL_BASE_URL_MAPPING[pp_env] @api_base_url = API_BASE_URL_MAPPING[pp_env] @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" } if config['ssl_cert_file'] && config['ssl_cert_file'].length > 0 @ssl_cert_file = config['ssl_cert_file'] end if File.exists?("/etc/ssl/certs") @ssl_ca_cert_path = "/etc/ssl/certs" else @ssl_ca_cert_path = File.join(File.dirname(__FILE__), "..", "cacert.pem") end @headers.merge!({ "X-PAYPAL-SECURITY-SIGNATURE" => config['signature'] }) if @ssl_cert_file.blank? end end |
#retain_requests_for_test? ⇒ Boolean
69 70 71 |
# File 'lib/config.rb', line 69 def retain_requests_for_test? !!@retain_requests_for_test end |