Class: PaymentKit::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_idObject

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
end

#api_hostObject

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_urlObject

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_retriesObject

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_timeoutObject

TCP connect timeout, in seconds.



28
29
30
# File 'lib/payment_kit/configuration.rb', line 28

def open_timeout
  @open_timeout
end

#read_timeoutObject

Response read timeout, in seconds.



31
32
33
# File 'lib/payment_kit/configuration.rb', line 31

def read_timeout
  @read_timeout
end

#secret_keyObject

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_secretsObject

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.
  @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_urlObject

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?()

  "#{host}/#{}"
end

#signing_secretObject

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_urlObject

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