Class: PaymentKit::Configuration
- Inherits:
-
Object
- Object
- PaymentKit::Configuration
- Defined in:
- lib/payment_kit/configuration.rb
Overview
Settings shared between global configuration and per-client overrides.
Constant Summary collapse
- DEFAULT_API_HOST =
API host root, without the account segment.
"https://app.paymentkit.com/api"- DEFAULT_OPEN_TIMEOUT =
TCP connect timeout, in seconds.
10- DEFAULT_READ_TIMEOUT =
Response read timeout, in seconds.
30- DEFAULT_MAX_RETRIES =
Attempts made after a transient failure before giving up.
2
Instance Attribute Summary collapse
-
#account_id ⇒ Object
Account external id (+acc_prod_...+), used as the API path prefix.
-
#api_host ⇒ Object
API host root; defaults to DEFAULT_API_HOST.
-
#base_url ⇒ Object
Full base URL override.
-
#max_retries ⇒ Object
Attempts made after a transient failure before giving up.
-
#open_timeout ⇒ Object
TCP connect timeout, in seconds.
-
#read_timeout ⇒ Object
Response read timeout, in seconds.
-
#secret_key ⇒ Object
Server secret token (+st_prod_...+).
-
#signing_secrets ⇒ Object
Webhook signing secrets (+whsec_...+), tried in order during rotation.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
Builds a configuration with the DEFAULT_* values and no credentials.
-
#initialize_copy(other) ⇒ Object
:nodoc:.
-
#merge(**overrides) ⇒ Object
Merge keyword overrides into a duplicate configuration.
-
#resolved_base_url ⇒ Object
Base URL every account-scoped request is sent to: an explicit
base_urlwhen set, otherwise {api_host}/{account_id}. -
#signing_secret ⇒ Object
Singular accessor for the first signing secret.
-
#signing_secret=(value) ⇒ Object
Assigns a single signing secret, replacing any already configured.
-
#unscoped_base_url ⇒ Object
Base for endpoints that are not account-scoped (e.g. the customer portal surface).
Constructor Details
#initialize ⇒ Configuration
Builds a configuration with the DEFAULT_* values and no credentials.
40 41 42 43 44 45 46 |
# File 'lib/payment_kit/configuration.rb', line 40 def initialize @api_host = DEFAULT_API_HOST @open_timeout = DEFAULT_OPEN_TIMEOUT @read_timeout = DEFAULT_READ_TIMEOUT @max_retries = DEFAULT_MAX_RETRIES @signing_secrets = nil end |
Instance Attribute Details
#account_id ⇒ Object
Account external id (+acc_prod_...+), used as the API path prefix.
19 20 21 |
# File 'lib/payment_kit/configuration.rb', line 19 def account_id @account_id end |
#api_host ⇒ Object
API host root; defaults to DEFAULT_API_HOST.
22 23 24 |
# File 'lib/payment_kit/configuration.rb', line 22 def api_host @api_host end |
#base_url ⇒ Object
Full base URL override. When set, account_id is not appended.
25 26 27 |
# File 'lib/payment_kit/configuration.rb', line 25 def base_url @base_url end |
#max_retries ⇒ Object
Attempts made after a transient failure before giving up.
34 35 36 |
# File 'lib/payment_kit/configuration.rb', line 34 def max_retries @max_retries end |
#open_timeout ⇒ Object
TCP connect timeout, in seconds.
28 29 30 |
# File 'lib/payment_kit/configuration.rb', line 28 def open_timeout @open_timeout end |
#read_timeout ⇒ Object
Response read timeout, in seconds.
31 32 33 |
# File 'lib/payment_kit/configuration.rb', line 31 def read_timeout @read_timeout end |
#secret_key ⇒ Object
Server secret token (+st_prod_...+). Never expose this in a browser.
16 17 18 |
# File 'lib/payment_kit/configuration.rb', line 16 def secret_key @secret_key end |
#signing_secrets ⇒ Object
Webhook signing secrets (+whsec_...+), tried in order during rotation.
37 38 39 |
# File 'lib/payment_kit/configuration.rb', line 37 def signing_secrets @signing_secrets end |
Instance Method Details
#initialize_copy(other) ⇒ Object
:nodoc:
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/payment_kit/configuration.rb', line 48 def initialize_copy(other) # :nodoc: super @secret_key = other.secret_key @account_id = other.account_id @api_host = other.api_host @base_url = other.base_url @open_timeout = other.open_timeout @read_timeout = other.read_timeout @max_retries = other.max_retries @signing_secrets = other.signing_secrets&.dup end |
#merge(**overrides) ⇒ Object
Merge keyword overrides into a duplicate configuration.
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/payment_kit/configuration.rb', line 71 def merge(**overrides) dup.tap do |config| overrides.each do |key, value| next if value.nil? writer = "#{key}=" raise ArgumentError, "Unknown configuration option: #{key}" unless config.respond_to?(writer) config.public_send(writer, value) end end end |
#resolved_base_url ⇒ Object
Base URL every account-scoped request is sent to: an explicit base_url
when set, otherwise {api_host}/{account_id}.
Raises InvalidRequestError when neither is configured.
88 89 90 91 92 93 94 95 |
# File 'lib/payment_kit/configuration.rb', line 88 def resolved_base_url return base_url.to_s.chomp("/") if present?(base_url) host = (api_host || DEFAULT_API_HOST).to_s.chomp("/") raise InvalidRequestError, "PaymentKit account_id is not configured" if blank?(account_id) "#{host}/#{account_id}" end |
#signing_secret ⇒ Object
Singular accessor for the first signing secret.
61 62 63 |
# File 'lib/payment_kit/configuration.rb', line 61 def signing_secret Array(signing_secrets).compact.first end |
#signing_secret=(value) ⇒ Object
Assigns a single signing secret, replacing any already configured.
66 67 68 |
# File 'lib/payment_kit/configuration.rb', line 66 def signing_secret=(value) @signing_secrets = value.nil? ? nil : Array(value) end |
#unscoped_base_url ⇒ Object
Base for endpoints that are not account-scoped (e.g. the customer portal
surface). An explicit base_url wins, since the account segment cannot be
reliably stripped back off it.
100 101 102 103 104 |
# File 'lib/payment_kit/configuration.rb', line 100 def unscoped_base_url return base_url.to_s.chomp("/") if present?(base_url) (api_host || DEFAULT_API_HOST).to_s.chomp("/") end |