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.



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

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.



17
18
19
# File 'lib/config.rb', line 17

def api_base_url
  @api_base_url
end

#config_filepathObject

Returns the value of attribute config_filepath.



17
18
19
# File 'lib/config.rb', line 17

def config_filepath
  @config_filepath
end

#headersObject

Returns the value of attribute headers.



17
18
19
# File 'lib/config.rb', line 17

def headers
  @headers
end

#paypal_base_urlObject

Returns the value of attribute paypal_base_url.



17
18
19
# File 'lib/config.rb', line 17

def paypal_base_url
  @paypal_base_url
end

Instance Method Details

#load(rails_env) ⇒ Object



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

def load(rails_env)
  config = YAML.load(ERB.new(File.new(@config_filepath).read).result)[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"
    }

    @headers["X-PAYPAL-SANDBOX-EMAIL-ADDRESS"] = config['sandbox_email'] if pp_env == :sandbox
    @headers["X-PAYPAL-MERCHANT-REFERRAL-BONUS-ID"] = config['merchant_referral_bonus_id'] if config['merchant_referral_bonus_id']
    
  end
end

#retain_requests_for_test?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/config.rb', line 56

def retain_requests_for_test?
  !!@retain_requests_for_test
end