Class: Braintree::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/braintree/configuration.rb

Overview

Constant Summary

API_VERSION =

:nodoc:

"4"
DEFAULT_ENDPOINT =

:nodoc:

"api"

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration



59
60
61
62
63
64
65
# File 'lib/braintree/configuration.rb', line 59

def initialize(options = {})
  [:endpoint, :environment, :public_key, :private_key, :custom_user_agent, :logger].each do |attr|
    instance_variable_set "@#{attr}", options[attr]
  end

  @merchant_id = options[:merchant_id] || options[:partner_id]
end

Class Attribute Details

.custom_user_agent=(value) ⇒ Object (writeonly)

Sets the attribute custom_user_agent



8
9
10
# File 'lib/braintree/configuration.rb', line 8

def custom_user_agent=(value)
  @custom_user_agent = value
end

.endpoint=(value) ⇒ Object (writeonly)

Sets the attribute endpoint



8
9
10
# File 'lib/braintree/configuration.rb', line 8

def endpoint=(value)
  @endpoint = value
end

.loggerObject



47
48
49
# File 'lib/braintree/configuration.rb', line 47

def self.logger
  @logger ||= _default_logger
end

.merchant_id=(value) ⇒ Object (writeonly)

Sets the attribute merchant_id



8
9
10
# File 'lib/braintree/configuration.rb', line 8

def merchant_id=(value)
  @merchant_id = value
end

.private_key=(value) ⇒ Object (writeonly)

Sets the attribute private_key



8
9
10
# File 'lib/braintree/configuration.rb', line 8

def private_key=(value)
  @private_key = value
end

.public_key=(value) ⇒ Object (writeonly)

Sets the attribute public_key



8
9
10
# File 'lib/braintree/configuration.rb', line 8

def public_key=(value)
  @public_key = value
end

Instance Attribute Details

#merchant_idObject (readonly)

Returns the value of attribute merchant_id



10
11
12
# File 'lib/braintree/configuration.rb', line 10

def merchant_id
  @merchant_id
end

#private_keyObject (readonly)

Returns the value of attribute private_key



10
11
12
# File 'lib/braintree/configuration.rb', line 10

def private_key
  @private_key
end

#public_keyObject (readonly)

Returns the value of attribute public_key



10
11
12
# File 'lib/braintree/configuration.rb', line 10

def public_key
  @public_key
end

Class Method Details

._default_loggerObject

:nodoc:



148
149
150
151
152
# File 'lib/braintree/configuration.rb', line 148

def self._default_logger # :nodoc:
  logger = Logger.new(STDOUT)
  logger.level = Logger::INFO
  logger
end

.environment=(env) ⇒ Object

Sets the Braintree environment to use. Valid values are :sandbox and :production



24
25
26
27
28
29
# File 'lib/braintree/configuration.rb', line 24

def self.environment=(env)
  unless [:development, :qa, :sandbox, :production].include?(env)
    raise ArgumentError, "#{env.inspect} is not a valid environment"
  end
  @environment = env
end

.expectant_reader(*attributes) ⇒ Object

:nodoc:



12
13
14
15
16
17
18
19
20
# File 'lib/braintree/configuration.rb', line 12

def self.expectant_reader(*attributes) # :nodoc:
  attributes.each do |attribute|
    (class << self; self; end).send(:define_method, attribute) do
      attribute_value = instance_variable_get("@#{attribute}")
      raise ConfigurationError.new(attribute.to_s, "needs to be set") unless attribute_value
      attribute_value
    end
  end
end

.gatewayObject

:nodoc:



31
32
33
# File 'lib/braintree/configuration.rb', line 31

def self.gateway # :nodoc:
  Braintree::Gateway.new(instantiate)
end

.instantiateObject

:nodoc:



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/braintree/configuration.rb', line 35

def self.instantiate # :nodoc:
  config = new(
    :custom_user_agent => @custom_user_agent,
    :endpoint => @endpoint,
    :environment => environment,
    :logger => logger,
    :merchant_id => merchant_id,
    :private_key => private_key,
    :public_key => public_key
  )
end

.sha256_signature_serviceObject



55
56
57
# File 'lib/braintree/configuration.rb', line 55

def self.sha256_signature_service
  instantiate.sha256_signature_service
end

.signature_serviceObject



51
52
53
# File 'lib/braintree/configuration.rb', line 51

def self.signature_service
  instantiate.signature_service
end

Instance Method Details

#api_versionObject

:nodoc:



67
68
69
# File 'lib/braintree/configuration.rb', line 67

def api_version # :nodoc:
  API_VERSION
end

#auth_urlObject



121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/braintree/configuration.rb', line 121

def auth_url
  case @environment
  when :development
    "http://auth.venmo.dev:9292"
  when :production
    "https://auth.venmo.com"
  when :qa
    "https://auth.venmo.qa2.braintreegateway.com"
  when :sandbox
    "https://auth.venmo.sandbox.braintreegateway.com"
  end
end

#base_merchant_pathObject

:nodoc:



71
72
73
# File 'lib/braintree/configuration.rb', line 71

def base_merchant_path # :nodoc:
  "/merchants/#{merchant_id}"
end

#base_merchant_urlObject

:nodoc:



75
76
77
# File 'lib/braintree/configuration.rb', line 75

def base_merchant_url # :nodoc:
  "#{protocol}://#{server}:#{port}#{base_merchant_path}"
end

#ca_fileObject

:nodoc:



79
80
81
# File 'lib/braintree/configuration.rb', line 79

def ca_file # :nodoc:
  File.expand_path(File.join(File.dirname(__FILE__), "..", "ssl", "api_braintreegateway_com.ca.crt"))
end

#endpointObject



83
84
85
# File 'lib/braintree/configuration.rb', line 83

def endpoint
  @endpoint || DEFAULT_ENDPOINT
end

#httpObject

:nodoc:



87
88
89
# File 'lib/braintree/configuration.rb', line 87

def http # :nodoc:
  Http.new(self)
end

#inspectObject



154
155
156
# File 'lib/braintree/configuration.rb', line 154

def inspect
  super.gsub(/@private_key=\".*\"/, '@private_key="[FILTERED]"')
end

#loggerObject



91
92
93
# File 'lib/braintree/configuration.rb', line 91

def logger
  @logger ||= self.class._default_logger
end

#portObject

:nodoc:



95
96
97
98
99
100
101
102
# File 'lib/braintree/configuration.rb', line 95

def port # :nodoc:
  case @environment
  when :development
    ENV['GATEWAY_PORT'] || 3000
  when :production, :qa, :sandbox
    443
  end
end

#protocolObject

:nodoc:



104
105
106
# File 'lib/braintree/configuration.rb', line 104

def protocol # :nodoc:
  ssl? ? "https" : "http"
end

#serverObject

:nodoc:



108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/braintree/configuration.rb', line 108

def server # :nodoc:
  case @environment
  when :development
    "localhost"
  when :production
    "#{endpoint}.braintreegateway.com"
  when :qa
    "gateway.qa.braintreepayments.com"
  when :sandbox
    "api.sandbox.braintreegateway.com"
  end
end

#sha256_signature_serviceObject



162
163
164
# File 'lib/braintree/configuration.rb', line 162

def sha256_signature_service
  @sha256_signature_service ||= SignatureService.new(@private_key, SHA256Digest)
end

#signature_serviceObject



158
159
160
# File 'lib/braintree/configuration.rb', line 158

def signature_service
  @signature_service ||= SignatureService.new(@private_key)
end

#ssl?Boolean

:nodoc:



134
135
136
137
138
139
140
141
# File 'lib/braintree/configuration.rb', line 134

def ssl? # :nodoc:
  case @environment
  when :development
    false
  when :production, :qa, :sandbox
    true
  end
end

#user_agentObject

:nodoc:



143
144
145
146
# File 'lib/braintree/configuration.rb', line 143

def user_agent # :nodoc:
  base_user_agent = "Braintree Ruby Gem #{Braintree::Version::String}"
  @custom_user_agent ? "#{base_user_agent} (#{@custom_user_agent})" : base_user_agent
end