Class: PaypalAdaptive::Config

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(env = nil) ⇒ Config

Returns a new instance of Config.



17
18
19
20
21
22
23
24
25
26
# File 'lib/config.rb', line 17

def initialize(env=nil)
  if env
    #non-rails env
    @config_filepath = "../config/paypal_adaptive.yml"
    load(env)
  else
    @config_filepath = File.join(Rails.root, "config/paypal_adaptive.yml")
    load(Rails.env)
  end
end

Instance Attribute Details

#api_base_urlObject

Returns the value of attribute api_base_url.



15
16
17
# File 'lib/config.rb', line 15

def api_base_url
  @api_base_url
end

#config_filepathObject

Returns the value of attribute config_filepath.



15
16
17
# File 'lib/config.rb', line 15

def config_filepath
  @config_filepath
end

#headersObject

Returns the value of attribute headers.



15
16
17
# File 'lib/config.rb', line 15

def headers
  @headers
end

#paypal_base_urlObject

Returns the value of attribute paypal_base_url.



15
16
17
# File 'lib/config.rb', line 15

def paypal_base_url
  @paypal_base_url
end

Instance Method Details

#load(rails_env) ⇒ Object



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
# File 'lib/config.rb', line 28

def load(rails_env)
  config= YAML.load_file(@config_filepath)[rails_env]

  if config["retain_requests_for_test"] == true
    @retain_requests_for_test = true
  else
    pp_env = config['environment'].to_sym

    @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-SECURITY-SIGNATURE" => config['signature'],
      "X-PAYPAL-APPLICATION-ID" => config['application_id'],
      "X-PAYPAL-REQUEST-DATA-FORMAT" => "JSON",
      "X-PAYPAL-RESPONSE-DATA-FORMAT" => "JSON",
      "X-PAYPAL-DEVICE-IPADDRESS" => "0.0.0.0"
    }

    if config['environment'] == 'sandbox'
      @headers.merge!("X-PAYPAL-SANDBOX-EMAIL-ADDRESS" => "[email protected]")
    end
  end
end

#retain_requests_for_test?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/config.rb', line 54

def retain_requests_for_test?
  !!@retain_requests_for_test
end