Class: Braintree::Configuration
- Inherits:
-
Object
- Object
- Braintree::Configuration
- Defined in:
- lib/braintree/configuration.rb
Constant Summary collapse
- API_VERSION =
:nodoc:
"4"- DEFAULT_ENDPOINT =
:nodoc:
"api"- READABLE_ATTRIBUTES =
[ :merchant_id, :public_key, :private_key, :client_id, :client_secret, :access_token, :environment, ]
- WRITABLE_ATTRIBUTES =
[ :custom_user_agent, :endpoint, :http_open_timeout, :http_read_timeout, :logger, :merchant_id, :public_key, :private_key, :environment, ]
Class Method Summary collapse
-
._default_logger ⇒ Object
:nodoc:.
-
.environment=(env) ⇒ Object
Sets the Braintree environment to use.
-
.expectant_reader(*attributes) ⇒ Object
:nodoc:.
-
.gateway ⇒ Object
:nodoc:.
- .http_open_timeout ⇒ Object
- .http_read_timeout ⇒ Object
-
.instantiate ⇒ Object
:nodoc:.
- .logger ⇒ Object
- .sha256_signature_service ⇒ Object
- .signature_service ⇒ Object
Instance Method Summary collapse
- #_check_for_mixed_credentials(options) ⇒ Object
-
#api_version ⇒ Object
:nodoc:.
- #assert_has_access_token_or_keys ⇒ Object
- #assert_has_client_credentials ⇒ Object
- #auth_url ⇒ Object
-
#base_merchant_path ⇒ Object
:nodoc:.
-
#base_merchant_url ⇒ Object
:nodoc:.
- #base_url ⇒ Object
-
#ca_file ⇒ Object
:nodoc:.
- #client_credentials? ⇒ Boolean
- #endpoint ⇒ Object
-
#http ⇒ Object
:nodoc:.
- #http_open_timeout ⇒ Object
- #http_read_timeout ⇒ Object
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #inspect ⇒ Object
- #logger ⇒ Object
-
#port ⇒ Object
:nodoc:.
-
#protocol ⇒ Object
:nodoc:.
-
#server ⇒ Object
:nodoc:.
- #sha256_signature_service ⇒ Object
- #signature_service ⇒ Object
-
#ssl? ⇒ Boolean
:nodoc:.
-
#user_agent ⇒ Object
:nodoc:.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Returns a new instance of Configuration.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/braintree/configuration.rb', line 90 def initialize( = {}) WRITABLE_ATTRIBUTES.each do |attr| instance_variable_set "@#{attr}", [attr] end _check_for_mixed_credentials() parser = Braintree::CredentialsParser.new if [:client_id] || [:client_secret] parser.parse_client_credentials([:client_id], [:client_secret]) @client_id = parser.client_id @client_secret = parser.client_secret @environment = parser.environment elsif [:access_token] parser.parse_access_token([:access_token]) @access_token = parser.access_token @environment = parser.environment @merchant_id = parser.merchant_id else @merchant_id = [:merchant_id] || [:partner_id] end end |
Class Method Details
._default_logger ⇒ Object
:nodoc:
220 221 222 223 224 |
# File 'lib/braintree/configuration.rb', line 220 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
45 46 47 48 49 50 |
# File 'lib/braintree/configuration.rb', line 45 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:
33 34 35 36 37 38 39 40 41 |
# File 'lib/braintree/configuration.rb', line 33 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("Braintree::Configuration.#{attribute.to_s} needs to be set") unless attribute_value attribute_value end end end |
.gateway ⇒ Object
:nodoc:
52 53 54 |
# File 'lib/braintree/configuration.rb', line 52 def self.gateway # :nodoc: Braintree::Gateway.new(instantiate) end |
.http_open_timeout ⇒ Object
70 71 72 |
# File 'lib/braintree/configuration.rb', line 70 def self.http_open_timeout @http_open_timeout ||= 60 end |
.http_read_timeout ⇒ Object
74 75 76 |
# File 'lib/braintree/configuration.rb', line 74 def self.http_read_timeout @http_read_timeout ||= 60 end |
.instantiate ⇒ Object
:nodoc:
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/braintree/configuration.rb', line 56 def self.instantiate # :nodoc: config = new( :custom_user_agent => @custom_user_agent, :endpoint => @endpoint, :environment => environment, :http_open_timeout => http_open_timeout, :http_read_timeout => http_read_timeout, :logger => logger, :merchant_id => merchant_id, :private_key => private_key, :public_key => public_key ) end |
.logger ⇒ Object
78 79 80 |
# File 'lib/braintree/configuration.rb', line 78 def self.logger @logger ||= _default_logger end |
.sha256_signature_service ⇒ Object
86 87 88 |
# File 'lib/braintree/configuration.rb', line 86 def self.sha256_signature_service instantiate.sha256_signature_service end |
.signature_service ⇒ Object
82 83 84 |
# File 'lib/braintree/configuration.rb', line 82 def self.signature_service instantiate.signature_service end |
Instance Method Details
#_check_for_mixed_credentials(options) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/braintree/configuration.rb', line 113 def _check_for_mixed_credentials() if ([:client_id] || [:client_secret]) && ([:public_key] || [:private_key]) raise ConfigurationError.new("Braintree::Gateway cannot be initialized with mixed credential types: client_id and client_secret mixed with public_key and private_key.") end if ([:client_id] || [:client_secret]) && ([:access_token]) raise ConfigurationError.new("Braintree::Gateway cannot be initialized with mixed credential types: client_id and client_secret mixed with access_token.") end if ([:public_key] || [:private_key]) && ([:access_token]) raise ConfigurationError.new("Braintree::Gateway cannot be initialized with mixed credential types: public_key and private_key mixed with access_token.") end end |
#api_version ⇒ Object
:nodoc:
127 128 129 |
# File 'lib/braintree/configuration.rb', line 127 def api_version # :nodoc: API_VERSION end |
#assert_has_access_token_or_keys ⇒ Object
240 241 242 243 244 |
# File 'lib/braintree/configuration.rb', line 240 def assert_has_access_token_or_keys if (public_key.nil? || private_key.nil?) && access_token.nil? raise ConfigurationError.new("Braintree::Gateway public_key and private_key are required.") end end |
#assert_has_client_credentials ⇒ Object
234 235 236 237 238 |
# File 'lib/braintree/configuration.rb', line 234 def assert_has_client_credentials if client_id.nil? || client_secret.nil? raise ConfigurationError.new("Braintree::Gateway client_id and client_secret are required.") end end |
#auth_url ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/braintree/configuration.rb', line 193 def auth_url case @environment when :development, :integration "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_path ⇒ Object
:nodoc:
131 132 133 |
# File 'lib/braintree/configuration.rb', line 131 def base_merchant_path # :nodoc: "/merchants/#{merchant_id}" end |
#base_merchant_url ⇒ Object
:nodoc:
139 140 141 |
# File 'lib/braintree/configuration.rb', line 139 def base_merchant_url # :nodoc: "#{base_url}#{base_merchant_path}" end |
#base_url ⇒ Object
135 136 137 |
# File 'lib/braintree/configuration.rb', line 135 def base_url "#{protocol}://#{server}:#{port}" end |
#ca_file ⇒ Object
:nodoc:
143 144 145 |
# File 'lib/braintree/configuration.rb', line 143 def ca_file # :nodoc: File.(File.join(File.dirname(__FILE__), "..", "ssl", "api_braintreegateway_com.ca.crt")) end |
#client_credentials? ⇒ Boolean
230 231 232 |
# File 'lib/braintree/configuration.rb', line 230 def client_credentials? !client_id.nil? end |
#endpoint ⇒ Object
147 148 149 |
# File 'lib/braintree/configuration.rb', line 147 def endpoint @endpoint || DEFAULT_ENDPOINT end |
#http ⇒ Object
:nodoc:
151 152 153 |
# File 'lib/braintree/configuration.rb', line 151 def http # :nodoc: Http.new(self) end |
#http_open_timeout ⇒ Object
172 173 174 |
# File 'lib/braintree/configuration.rb', line 172 def http_open_timeout @http_open_timeout end |
#http_read_timeout ⇒ Object
176 177 178 |
# File 'lib/braintree/configuration.rb', line 176 def http_read_timeout @http_read_timeout end |
#inspect ⇒ Object
226 227 228 |
# File 'lib/braintree/configuration.rb', line 226 def inspect super.gsub(/@private_key=\".*\"/, '@private_key="[FILTERED]"') end |
#logger ⇒ Object
155 156 157 |
# File 'lib/braintree/configuration.rb', line 155 def logger @logger ||= self.class._default_logger end |
#port ⇒ Object
:nodoc:
159 160 161 162 163 164 165 166 |
# File 'lib/braintree/configuration.rb', line 159 def port # :nodoc: case @environment when :development, :integration ENV['GATEWAY_PORT'] || 3000 when :production, :qa, :sandbox 443 end end |
#protocol ⇒ Object
:nodoc:
168 169 170 |
# File 'lib/braintree/configuration.rb', line 168 def protocol # :nodoc: ssl? ? "https" : "http" end |
#server ⇒ Object
:nodoc:
180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/braintree/configuration.rb', line 180 def server # :nodoc: case @environment when :development, :integration "localhost" when :production "#{endpoint}.braintreegateway.com" when :qa "gateway.qa.braintreepayments.com" when :sandbox "api.sandbox.braintreegateway.com" end end |
#sha256_signature_service ⇒ Object
250 251 252 |
# File 'lib/braintree/configuration.rb', line 250 def sha256_signature_service @sha256_signature_service ||= SignatureService.new(@private_key, SHA256Digest) end |
#signature_service ⇒ Object
246 247 248 |
# File 'lib/braintree/configuration.rb', line 246 def signature_service @signature_service ||= SignatureService.new(@private_key) end |
#ssl? ⇒ Boolean
:nodoc:
206 207 208 209 210 211 212 213 |
# File 'lib/braintree/configuration.rb', line 206 def ssl? # :nodoc: case @environment when :development, :integration false when :production, :qa, :sandbox true end end |