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.



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

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

  @max_network_retries = 0
  @initial_network_retry_delay = 0.5
  @max_network_retry_delay = 2

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

  @api_base = "https://api.stripe.com"
  @connect_base = "https://connect.stripe.com"
  @uploads_base = "https://files.stripe.com"
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

#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

#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

#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

rubocop:enable Layout/LineLength



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

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.



162
163
164
165
166
167
168
# File 'lib/stripe/stripe_configuration.rb', line 162

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)


170
171
172
# File 'lib/stripe/stripe_configuration.rb', line 170

def enable_telemetry?
  enable_telemetry
end

#keyObject

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



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

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



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

def reverse_duplicate_merge(hash)
  dup.tap do |instance|
    hash.each do |option, value|
      instance.public_send("#{option}=", value)
    end
  end
end