Class: Stripe::StripeConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/stripe/stripe_configuration.rb

Overview

Configurable options:

ca_bundle_path=

The location of a file containing a bundle of CA certificates. By default the library will use an included bundle that can successfully validate Stripe certificates.

log_level=

When set prompts the library to log some extra information to $stdout and $stderr about what it’s doing. For example, it’ll produce information about requests, responses, and errors that are received. Valid log levels are ‘debug` and `info`, with `debug` being a little more verbose in places.

Use of this configuration is only useful when ‘.logger` is not set. When it is, the decision what levels to print is entirely deferred to the logger.

logger=

The logger should support the same interface as the ‘Logger` class that’s part of Ruby’s standard library (hint, anything in ‘Rails.logger` will likely be suitable).

If ‘.logger` is set, the value of `.log_level` is ignored. The decision on what levels to print is entirely deferred to the logger.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStripeConfiguration

Returns a new instance of StripeConfiguration.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/stripe/stripe_configuration.rb', line 53

def initialize
  @api_version = ApiVersion::CURRENT
  @ca_bundle_path = Stripe::DEFAULT_CA_BUNDLE_PATH
  @enable_telemetry = true
  @verify_ssl_certs = true

  @max_network_retries = 2
  @initial_network_retry_delay = 0.5
  @max_network_retry_delay = 5

  @open_timeout = 30
  @read_timeout = 80
  @write_timeout = 30

  @api_base = DEFAULT_API_BASE
  @connect_base = DEFAULT_CONNECT_BASE
  @uploads_base = DEFAULT_UPLOAD_BASE
  @meter_events_base = DEFAULT_METER_EVENTS_BASE
  @base_addresses = { api: @api_base, connect: @connect_base, files: @uploads_base, events: @meter_events_base }
end

Instance Attribute Details

#api_baseObject

Returns the value of attribute api_base.



30
31
32
# File 'lib/stripe/stripe_configuration.rb', line 30

def api_base
  @api_base
end

#api_keyObject

Returns the value of attribute api_key.



28
29
30
# File 'lib/stripe/stripe_configuration.rb', line 28

def api_key
  @api_key
end

#api_versionObject

Returns the value of attribute api_version.



28
29
30
# File 'lib/stripe/stripe_configuration.rb', line 28

def api_version
  @api_version
end

#base_addressesObject (readonly)

Returns the value of attribute base_addresses.



30
31
32
# File 'lib/stripe/stripe_configuration.rb', line 30

def base_addresses
  @base_addresses
end

#ca_bundle_pathObject

Returns the value of attribute ca_bundle_path.



30
31
32
# File 'lib/stripe/stripe_configuration.rb', line 30

def ca_bundle_path
  @ca_bundle_path
end

#client_idObject

Returns the value of attribute client_id.



28
29
30
# File 'lib/stripe/stripe_configuration.rb', line 28

def client_id
  @client_id
end

#connect_baseObject

Returns the value of attribute connect_base.



30
31
32
# File 'lib/stripe/stripe_configuration.rb', line 30

def connect_base
  @connect_base
end

#enable_telemetryObject

Returns the value of attribute enable_telemetry.



28
29
30
# File 'lib/stripe/stripe_configuration.rb', line 28

def enable_telemetry
  @enable_telemetry
end

#initial_network_retry_delayObject

Returns the value of attribute initial_network_retry_delay.



30
31
32
# File 'lib/stripe/stripe_configuration.rb', line 30

def initial_network_retry_delay
  @initial_network_retry_delay
end

#log_levelObject

Returns the value of attribute log_level.



30
31
32
# File 'lib/stripe/stripe_configuration.rb', line 30

def log_level
  @log_level
end

#loggerObject

Returns the value of attribute logger.



28
29
30
# File 'lib/stripe/stripe_configuration.rb', line 28

def logger
  @logger
end

#max_network_retriesObject

Returns the value of attribute max_network_retries.



30
31
32
# File 'lib/stripe/stripe_configuration.rb', line 30

def max_network_retries
  @max_network_retries
end

#max_network_retry_delayObject

Returns the value of attribute max_network_retry_delay.



30
31
32
# File 'lib/stripe/stripe_configuration.rb', line 30

def max_network_retry_delay
  @max_network_retry_delay
end

#meter_events_baseObject

Returns the value of attribute meter_events_base.



30
31
32
# File 'lib/stripe/stripe_configuration.rb', line 30

def meter_events_base
  @meter_events_base
end

#open_timeoutObject

Returns the value of attribute open_timeout.



30
31
32
# File 'lib/stripe/stripe_configuration.rb', line 30

def open_timeout
  @open_timeout
end

#proxyObject

Returns the value of attribute proxy.



30
31
32
# File 'lib/stripe/stripe_configuration.rb', line 30

def proxy
  @proxy
end

#read_timeoutObject

Returns the value of attribute read_timeout.



30
31
32
# File 'lib/stripe/stripe_configuration.rb', line 30

def read_timeout
  @read_timeout
end

#stripe_accountObject

Returns the value of attribute stripe_account.



28
29
30
# File 'lib/stripe/stripe_configuration.rb', line 28

def 
  @stripe_account
end

#stripe_contextObject

Returns the value of attribute stripe_context.



28
29
30
# File 'lib/stripe/stripe_configuration.rb', line 28

def stripe_context
  @stripe_context
end

#uploads_baseObject

Returns the value of attribute uploads_base.



30
31
32
# File 'lib/stripe/stripe_configuration.rb', line 30

def uploads_base
  @uploads_base
end

#verify_ssl_certsObject

Returns the value of attribute verify_ssl_certs.



30
31
32
# File 'lib/stripe/stripe_configuration.rb', line 30

def verify_ssl_certs
  @verify_ssl_certs
end

#write_timeoutObject

Returns the value of attribute write_timeout.



30
31
32
# File 'lib/stripe/stripe_configuration.rb', line 30

def write_timeout
  @write_timeout
end

Class Method Details

.setupObject



34
35
36
37
38
# File 'lib/stripe/stripe_configuration.rb', line 34

def self.setup
  new.tap do |instance|
    yield(instance) if block_given?
  end
end

Instance Method Details

#ca_storeObject

A certificate store initialized from the the bundle in #ca_bundle_path and which is used to validate TLS on every request.

This was added to the give the gem “pseudo thread safety” in that it seems when initiating many parallel requests marshaling the certificate store is the most likely point of failure (see issue #382). Any program attempting to leverage this pseudo safety should make a call to this method (i.e. ‘Stripe.ca_store`) in their initialization code because it marshals lazily and is itself not thread safe.



175
176
177
178
179
180
181
# File 'lib/stripe/stripe_configuration.rb', line 175

def ca_store
  @ca_store ||= begin
    store = OpenSSL::X509::Store.new
    store.add_file(ca_bundle_path)
    store
  end
end

#enable_telemetry?Boolean

Returns:

  • (Boolean)


183
184
185
# File 'lib/stripe/stripe_configuration.rb', line 183

def enable_telemetry?
  enable_telemetry
end

#keyObject

Generates a deterministic key to identify configuration objects with identical configuration values.



189
190
191
192
193
# File 'lib/stripe/stripe_configuration.rb', line 189

def key
  instance_variables
    .collect { |variable| instance_variable_get(variable) }
    .join
end

#reverse_duplicate_merge(hash) ⇒ Object

Create a new config based off an existing one. This is useful when the caller wants to override the global configuration



42
43
44
45
46
47
48
49
50
51
# File 'lib/stripe/stripe_configuration.rb', line 42

def reverse_duplicate_merge(hash)
  dup.tap do |instance|
    hash.each do |option, value|
      instance.public_send("#{option}=", value)
    end
    instance.send("instance_variable_set", "@base_addresses",
                  { api: instance.api_base, connect: instance.connect_base,
                    files: instance.uploads_base, meter_events: instance.meter_events_base, })
  end
end