class Stripe::StripeConfiguration

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.

Attributes

api_base[R]
api_key[RW]
api_version[RW]
ca_bundle_path[R]
client_id[RW]
connect_base[R]
enable_telemetry[RW]
initial_network_retry_delay[R]
log_level[R]
logger[RW]
max_network_retries[R]
max_network_retry_delay[R]
open_timeout[R]
proxy[R]
read_timeout[R]
stripe_account[RW]
uploads_base[R]
verify_ssl_certs[R]
write_timeout[R]

Public Class Methods

new() click to toggle source
# File lib/stripe/stripe_configuration.rb, line 65
def initialize
  @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
setup() { |instance| ... } click to toggle source
# File lib/stripe/stripe_configuration.rb, line 49
def self.setup
  new.tap do |instance|
    yield(instance) if block_given?
  end
end

Public Instance Methods

api_base=(api_base) click to toggle source
# File lib/stripe/stripe_configuration.rb, line 151
def api_base=(api_base)
  @api_base = api_base
  StripeClient.clear_all_connection_managers(config: self)
end
ca_bundle_path=(path) click to toggle source
# File lib/stripe/stripe_configuration.rb, line 156
def ca_bundle_path=(path)
  @ca_bundle_path = path

  # empty this field so a new store is initialized
  @ca_store = nil

  StripeClient.clear_all_connection_managers(config: self)
end
ca_store() click to toggle source

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.

# File lib/stripe/stripe_configuration.rb, line 174
def ca_store
  @ca_store ||= begin
                  store = OpenSSL::X509::Store.new
                  store.add_file(ca_bundle_path)
                  store
                end
end
connect_base=(connect_base) click to toggle source
# File lib/stripe/stripe_configuration.rb, line 146
def connect_base=(connect_base)
  @connect_base = connect_base
  StripeClient.clear_all_connection_managers(config: self)
end
enable_telemetry?() click to toggle source
# File lib/stripe/stripe_configuration.rb, line 182
def enable_telemetry?
  enable_telemetry
end
initial_network_retry_delay=(val) click to toggle source
# File lib/stripe/stripe_configuration.rb, line 108
def initial_network_retry_delay=(val)
  @initial_network_retry_delay = val.to_i
end
key() click to toggle source

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

# File lib/stripe/stripe_configuration.rb, line 188
def key
  instance_variables
    .collect { |variable| instance_variable_get(variable) }
    .join
end
log_level=(val) click to toggle source
# File lib/stripe/stripe_configuration.rb, line 83
def log_level=(val)
  # Backwards compatibility for values that we briefly allowed
  if val == "debug"
    val = Stripe::LEVEL_DEBUG
  elsif val == "info"
    val = Stripe::LEVEL_INFO
  end

  levels = [Stripe::LEVEL_INFO, Stripe::LEVEL_DEBUG, Stripe::LEVEL_ERROR]

  if !val.nil? && !levels.include?(val)
    raise ArgumentError,
          "log_level should only be set to `nil`, `debug` or `info`"
  end
  @log_level = val
end
max_network_retries=(val) click to toggle source
# File lib/stripe/stripe_configuration.rb, line 100
def max_network_retries=(val)
  @max_network_retries = val.to_i
end
max_network_retry_delay=(val) click to toggle source
# File lib/stripe/stripe_configuration.rb, line 104
def max_network_retry_delay=(val)
  @max_network_retry_delay = val.to_i
end
open_timeout=(open_timeout) click to toggle source
# File lib/stripe/stripe_configuration.rb, line 112
def open_timeout=(open_timeout)
  @open_timeout = open_timeout
  StripeClient.clear_all_connection_managers(config: self)
end
proxy=(proxy) click to toggle source
# File lib/stripe/stripe_configuration.rb, line 131
def proxy=(proxy)
  @proxy = proxy
  StripeClient.clear_all_connection_managers(config: self)
end
read_timeout=(read_timeout) click to toggle source
# File lib/stripe/stripe_configuration.rb, line 117
def read_timeout=(read_timeout)
  @read_timeout = read_timeout
  StripeClient.clear_all_connection_managers(config: self)
end
reverse_duplicate_merge(hash) click to toggle source

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

# File lib/stripe/stripe_configuration.rb, line 57
def reverse_duplicate_merge(hash)
  dup.tap do |instance|
    hash.each do |option, value|
      instance.public_send("#{option}=", value)
    end
  end
end
uploads_base=(uploads_base) click to toggle source
# File lib/stripe/stripe_configuration.rb, line 141
def uploads_base=(uploads_base)
  @uploads_base = uploads_base
  StripeClient.clear_all_connection_managers(config: self)
end
verify_ssl_certs=(verify_ssl_certs) click to toggle source
# File lib/stripe/stripe_configuration.rb, line 136
def verify_ssl_certs=(verify_ssl_certs)
  @verify_ssl_certs = verify_ssl_certs
  StripeClient.clear_all_connection_managers(config: self)
end
write_timeout=(write_timeout) click to toggle source
# File lib/stripe/stripe_configuration.rb, line 122
def write_timeout=(write_timeout)
  unless Net::HTTP.instance_methods.include?(:write_timeout=)
    raise NotImplementedError
  end

  @write_timeout = write_timeout
  StripeClient.clear_all_connection_managers(config: self)
end