Class: Braintree::Configuration
- Inherits:
-
Object
- Object
- Braintree::Configuration
- Defined in:
- lib/braintree/configuration.rb
Constant Summary collapse
- API_VERSION =
"6"
- DEFAULT_ENDPOINT =
"api"
- GRAPHQL_API_VERSION =
NEXT_MAJOR_VERSION update to the latest version of GraphQL API
"2018-09-10"
- READABLE_ATTRIBUTES =
[ :merchant_id, :public_key, :private_key, :client_id, :client_secret, :access_token, :environment ]
- NON_REQUIRED_READABLE_ATTRIBUTES =
[ :proxy_address, :proxy_port, :proxy_user, :proxy_pass, :ssl_version ]
- WRITABLE_ATTRIBUTES =
[ :custom_user_agent, :endpoint, :http_open_timeout, :http_read_timeout, :logger, :merchant_id, :public_key, :private_key, :environment, :proxy_address, :proxy_port, :proxy_user, :proxy_pass, :ssl_version ]
Class Method Summary collapse
- ._default_logger ⇒ Object
- .environment=(env) ⇒ Object
- .expectant_reader(*attributes) ⇒ Object
- .gateway ⇒ Object
- .http_open_timeout ⇒ Object
- .http_read_timeout ⇒ Object
- .instantiate ⇒ Object
- .logger ⇒ Object
- .sha256_signature_service ⇒ Object
- .signature_service ⇒ Object
Instance Method Summary collapse
- #_check_for_mixed_credentials(options) ⇒ Object
- #_check_for_mixed_environment(options_environment, token_environment) ⇒ Object
- #api_version ⇒ Object
- #assert_has_access_token_or_keys ⇒ Object
- #assert_has_client_credentials ⇒ Object
- #auth_url ⇒ Object
- #base_merchant_path ⇒ Object
- #base_merchant_url ⇒ Object
- #base_url ⇒ Object
- #ca_file ⇒ Object
- #client_credentials? ⇒ Boolean
- #endpoint ⇒ Object
- #graphql_api_version ⇒ Object
- #graphql_base_url ⇒ Object
- #graphql_client ⇒ Object
- #graphql_port ⇒ Object
- #graphql_server ⇒ Object
- #http ⇒ Object
- #http_open_timeout ⇒ Object
- #http_read_timeout ⇒ Object
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #inspect ⇒ Object
- #logger ⇒ Object
- #port ⇒ Object
- #protocol ⇒ Object
- #server ⇒ Object
- #sha256_signature_service ⇒ Object
- #signature_service ⇒ Object
- #ssl? ⇒ Boolean
- #user_agent ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Configuration
Returns a new instance of Configuration.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/braintree/configuration.rb', line 113 def initialize( = {}) WRITABLE_ATTRIBUTES.each do |attr| instance_variable_set "@#{attr}", [attr] end @environment = @environment.to_sym if @environment _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]) _check_for_mixed_environment([:environment], parser.environment) @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
288 289 290 291 292 |
# File 'lib/braintree/configuration.rb', line 288 def self._default_logger logger = Logger.new(STDOUT) logger.level = Logger::INFO logger end |
.environment=(env) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/braintree/configuration.rb', line 62 def self.environment=(env) env = env.to_sym unless [:development, :qa, :sandbox, :production].include?(env) raise ArgumentError, "#{env.inspect} is not a valid environment" end @environment = env end |
.expectant_reader(*attributes) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/braintree/configuration.rb', line 51 def self.expectant_reader(*attributes) 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} needs to be set") if attribute_value.nil? || attribute_value.to_s.empty? attribute_value end end end |
.gateway ⇒ Object
70 71 72 |
# File 'lib/braintree/configuration.rb', line 70 def self.gateway Braintree::Gateway.new(instantiate) end |
.http_open_timeout ⇒ Object
93 94 95 |
# File 'lib/braintree/configuration.rb', line 93 def self.http_open_timeout @http_open_timeout ||= 60 end |
.http_read_timeout ⇒ Object
97 98 99 |
# File 'lib/braintree/configuration.rb', line 97 def self.http_read_timeout @http_read_timeout ||= 60 end |
.instantiate ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/braintree/configuration.rb', line 74 def self.instantiate 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, :proxy_address => proxy_address, :proxy_port => proxy_port, :proxy_user => proxy_user, :proxy_pass => proxy_pass, :ssl_version => ssl_version, ) end |
.logger ⇒ Object
101 102 103 |
# File 'lib/braintree/configuration.rb', line 101 def self.logger @logger ||= _default_logger end |
.sha256_signature_service ⇒ Object
109 110 111 |
# File 'lib/braintree/configuration.rb', line 109 def self.sha256_signature_service instantiate.sha256_signature_service end |
.signature_service ⇒ Object
105 106 107 |
# File 'lib/braintree/configuration.rb', line 105 def self.signature_service instantiate.signature_service end |
Instance Method Details
#_check_for_mixed_credentials(options) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/braintree/configuration.rb', line 141 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 |
#_check_for_mixed_environment(options_environment, token_environment) ⇒ Object
155 156 157 158 159 |
# File 'lib/braintree/configuration.rb', line 155 def _check_for_mixed_environment(, token_environment) if && .to_sym != token_environment.to_sym warn "Braintree::Gateway should not be initialized with mixed environments: environment parameter and access_token do not match, environment from access_token is used." end end |
#api_version ⇒ Object
161 162 163 |
# File 'lib/braintree/configuration.rb', line 161 def api_version API_VERSION end |
#assert_has_access_token_or_keys ⇒ Object
308 309 310 311 312 |
# File 'lib/braintree/configuration.rb', line 308 def assert_has_access_token_or_keys if (public_key.nil? || private_key.nil?) && access_token.nil? raise ConfigurationError.new("Braintree::Gateway access_token or public_key and private_key are required.") end end |
#assert_has_client_credentials ⇒ Object
302 303 304 305 306 |
# File 'lib/braintree/configuration.rb', line 302 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
261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/braintree/configuration.rb', line 261 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
169 170 171 |
# File 'lib/braintree/configuration.rb', line 169 def base_merchant_path "/merchants/#{merchant_id}" end |
#base_merchant_url ⇒ Object
181 182 183 |
# File 'lib/braintree/configuration.rb', line 181 def base_merchant_url "#{base_url}#{base_merchant_path}" end |
#base_url ⇒ Object
173 174 175 |
# File 'lib/braintree/configuration.rb', line 173 def base_url "#{protocol}://#{server}:#{port}" end |
#ca_file ⇒ Object
185 186 187 |
# File 'lib/braintree/configuration.rb', line 185 def ca_file File.(File.join(File.dirname(__FILE__), "..", "ssl", "api_braintreegateway_com.ca.crt")) end |
#client_credentials? ⇒ Boolean
298 299 300 |
# File 'lib/braintree/configuration.rb', line 298 def client_credentials? !client_id.nil? end |
#endpoint ⇒ Object
189 190 191 |
# File 'lib/braintree/configuration.rb', line 189 def endpoint @endpoint || DEFAULT_ENDPOINT end |
#graphql_api_version ⇒ Object
165 166 167 |
# File 'lib/braintree/configuration.rb', line 165 def graphql_api_version GRAPHQL_API_VERSION end |
#graphql_base_url ⇒ Object
177 178 179 |
# File 'lib/braintree/configuration.rb', line 177 def graphql_base_url "#{protocol}://#{graphql_server}:#{graphql_port}/graphql" end |
#graphql_client ⇒ Object
197 198 199 |
# File 'lib/braintree/configuration.rb', line 197 def graphql_client GraphQLClient.new(self) end |
#graphql_port ⇒ Object
214 215 216 217 218 219 220 221 |
# File 'lib/braintree/configuration.rb', line 214 def graphql_port case @environment when :development, :integration ENV["GRAPHQL_PORT"] || 8080 when :production, :qa, :sandbox 443 end end |
#graphql_server ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/braintree/configuration.rb', line 248 def graphql_server case @environment when :development, :integration ENV["GRAPHQL_HOST"] || "graphql.bt.local" when :production "payments.braintree-api.com" when :qa "payments-qa.dev.braintree-api.com" when :sandbox "payments.sandbox.braintree-api.com" end end |
#http ⇒ Object
193 194 195 |
# File 'lib/braintree/configuration.rb', line 193 def http Http.new(self) end |
#http_open_timeout ⇒ Object
227 228 229 |
# File 'lib/braintree/configuration.rb', line 227 def http_open_timeout @http_open_timeout end |
#http_read_timeout ⇒ Object
231 232 233 |
# File 'lib/braintree/configuration.rb', line 231 def http_read_timeout @http_read_timeout end |
#inspect ⇒ Object
294 295 296 |
# File 'lib/braintree/configuration.rb', line 294 def inspect super.gsub(/@private_key=\".*\"/, '@private_key="[FILTERED]"') end |
#logger ⇒ Object
201 202 203 |
# File 'lib/braintree/configuration.rb', line 201 def logger @logger ||= self.class._default_logger end |
#port ⇒ Object
205 206 207 208 209 210 211 212 |
# File 'lib/braintree/configuration.rb', line 205 def port case @environment when :development, :integration ENV["GATEWAY_PORT"] || 3000 when :production, :qa, :sandbox 443 end end |
#protocol ⇒ Object
223 224 225 |
# File 'lib/braintree/configuration.rb', line 223 def protocol ssl? ? "https" : "http" end |
#server ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/braintree/configuration.rb', line 235 def server case @environment when :development, :integration ENV["GATEWAY_HOST"] || "localhost" when :production "#{endpoint}.braintreegateway.com" when :qa "gateway.qa2.braintreepayments.com" when :sandbox "api.sandbox.braintreegateway.com" end end |
#sha256_signature_service ⇒ Object
318 319 320 |
# File 'lib/braintree/configuration.rb', line 318 def sha256_signature_service @sha256_signature_service ||= SignatureService.new(@private_key, SHA256Digest) end |
#signature_service ⇒ Object
314 315 316 |
# File 'lib/braintree/configuration.rb', line 314 def signature_service @signature_service ||= SignatureService.new(@private_key) end |
#ssl? ⇒ Boolean
274 275 276 277 278 279 280 281 |
# File 'lib/braintree/configuration.rb', line 274 def ssl? case @environment when :development, :integration false when :production, :qa, :sandbox true end end |