straddle_pay 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cea0fc12d897f53acbe7d6d8d16f3b9be978e688603d3d6ba47228fc51ac5364
4
- data.tar.gz: 8ddb9535d91df18cfef8bc5ded89dc1fe73d0f12f762e9e95b0b14e9c95b754b
3
+ metadata.gz: 35b268470e5133d654d67346a63b4f4894e8c0e2eef3dba5a9d96fed73597ed1
4
+ data.tar.gz: 9283c984a2a944ad673a3a3aa2d851d1ed9b62b76268472e38858be35317616a
5
5
  SHA512:
6
- metadata.gz: 797ba62b6cbe4024e39c930411ed8a0298c1f691b7b2d0156429c98dddc15a930886d55bed9377535838dfcddb69fa7e6e62348256d80b59ee33320e96684051
7
- data.tar.gz: 8f4a5ae928ff8213d04367eaaed803b34cd4ce4cc20fead2fd2605741b5cbe9f118824fef28ba947156c4979302b33b9f8b747e94b4565229f564130e2280a8b
6
+ metadata.gz: f69d2db69c73cf79d3a88cc1c9be12f0a2bcd7490e30dd8bda952a1f7564c11bfe502268330345ca4ef34ca0c8a10a2d7ec5d776f4676bc2dd26a2f9e185b568
7
+ data.tar.gz: f38ef5de026721e84cad8e04cfe3843355d465e6df7af0168bd393a6f9422df6eef40396ada24a209c1f9830448a3c5d10811b479325aab03da436771ae14330
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [0.3.0] - 2026-02-20
2
+
3
+ ### Changed
4
+ - Replace `base_url` with `environment: :sandbox/:production` as primary config
5
+ - `STRADDLE_ENVIRONMENT` env var replaces `STRADDLE_BASE_URL` for environment selection
6
+ - `base_url` remains as escape hatch for custom URLs
7
+ - `ENVIRONMENTS` hash replaces `SANDBOX_URL`/`PRODUCTION_URL` constants
8
+ - Client accepts `environment:` param for per-instance override
9
+
10
+ ## [0.2.0] - 2026-02-20
11
+
12
+ ### Added
13
+ - Webhook signature verification following Svix protocol
14
+
1
15
  ## [0.1.5] - 2026-02-20
2
16
 
3
17
  ### Fixed
data/README.md CHANGED
@@ -19,36 +19,36 @@ Configure once:
19
19
 
20
20
  ```ruby
21
21
  StraddlePay.configure do |config|
22
- config.api_key = ENV.fetch("STRADDLE_API_KEY")
23
- config.base_url = StraddlePay::Config::PRODUCTION_URL # default: sandbox
22
+ config.api_key = ENV.fetch("STRADDLE_API_KEY")
23
+ config.environment = :production # default: :sandbox
24
24
  end
25
25
  ```
26
26
 
27
+ Or via environment variables:
28
+
29
+ ```sh
30
+ STRADDLE_API_KEY=sk_live_...
31
+ STRADDLE_ENVIRONMENT=production
32
+ ```
33
+
27
34
  Per-instance overrides:
28
35
 
29
36
  ```ruby
30
37
  client = StraddlePay::Client.new(
31
38
  api_key: "sk_different_key",
32
- base_url: "https://production.straddle.com"
39
+ environment: :production
33
40
  )
34
41
  ```
35
42
 
36
- ### Environments
37
-
38
- | Environment | URL |
39
- |-------------|-----|
40
- | Sandbox (default) | `https://sandbox.straddle.com` |
41
- | Production | `https://production.straddle.com` |
42
-
43
43
  ### Rails
44
44
 
45
45
  Create `config/initializers/straddle_pay.rb`:
46
46
 
47
47
  ```ruby
48
48
  StraddlePay.configure do |config|
49
- config.api_key = Rails.application.credentials.straddle_api_key
50
- config.base_url = StraddlePay::Config::PRODUCTION_URL
51
- config.logger = Rails.logger
49
+ config.api_key = Rails.application.credentials.straddle_api_key
50
+ config.environment = :production
51
+ config.logger = Rails.logger
52
52
  end
53
53
  ```
54
54
 
@@ -16,15 +16,16 @@ module StraddlePay
16
16
  attr_reader :base_url
17
17
 
18
18
  # @param api_key [String, nil] override global API key
19
- # @param base_url [String, nil] override global base URL
19
+ # @param environment [Symbol, nil] :sandbox or :production (overrides global environment)
20
+ # @param base_url [String, nil] custom base URL (takes precedence over environment)
20
21
  # @param logger [Logger, nil] override global logger
21
22
  # @param open_timeout [Integer, nil] connection open timeout in seconds
22
23
  # @param read_timeout [Integer, nil] response read timeout in seconds
23
24
  # @raise [ArgumentError] if no API key is configured
24
- def initialize(api_key: nil, base_url: nil, logger: nil, open_timeout: nil, read_timeout: nil)
25
+ def initialize(api_key: nil, environment: nil, base_url: nil, logger: nil, open_timeout: nil, read_timeout: nil)
25
26
  configuration = StraddlePay.config
26
- @api_key = api_key || configuration.api_key
27
- @base_url = base_url || configuration.base_url
27
+ @api_key = api_key || configuration.api_key
28
+ @base_url = base_url || resolve_base_url(environment, configuration)
28
29
  @logger = logger || configuration.logger
29
30
  @open_timeout = open_timeout || configuration.open_timeout
30
31
  @read_timeout = read_timeout || configuration.read_timeout
@@ -97,6 +98,16 @@ module StraddlePay
97
98
 
98
99
  private
99
100
 
101
+ def resolve_base_url(environment, configuration)
102
+ if environment
103
+ Config::ENVIRONMENTS.fetch(environment.to_sym) do
104
+ raise ArgumentError, "Unknown environment: #{environment}"
105
+ end
106
+ else
107
+ configuration.base_url
108
+ end
109
+ end
110
+
100
111
  def request(method, path, body: nil, params: nil, headers: {})
101
112
  response = connection.public_send(method, path) do |req|
102
113
  apply_headers(req, headers)
@@ -7,32 +7,49 @@ module StraddlePay
7
7
  #
8
8
  # @example
9
9
  # StraddlePay.configure do |config|
10
- # config.api_key = "sk_test_..."
11
- # config.base_url = StraddlePay::Config::PRODUCTION_URL
12
- # config.logger = Rails.logger
10
+ # config.api_key = "sk_test_..."
11
+ # config.environment = :production
12
+ # config.logger = Rails.logger
13
13
  # end
14
14
  class Config
15
- # @return [String] Sandbox API base URL
16
- SANDBOX_URL = "https://sandbox.straddle.com"
17
- # @return [String] Production API base URL
18
- PRODUCTION_URL = "https://production.straddle.com"
15
+ ENVIRONMENTS = {
16
+ sandbox: "https://sandbox.straddle.com",
17
+ production: "https://production.straddle.com"
18
+ }.freeze
19
19
 
20
20
  # @return [String, nil] API key for authentication
21
21
  attr_accessor :api_key
22
- # @return [String] Base URL for API requests (default: sandbox)
23
- attr_accessor :base_url
24
22
  # @return [Integer] Connection open timeout in seconds (default: 5)
25
23
  attr_accessor :open_timeout
26
24
  # @return [Integer] Response read timeout in seconds (default: 30)
27
25
  attr_accessor :read_timeout
28
26
  # @return [Logger] Logger instance
29
27
  attr_writer :logger
28
+ # @return [String, nil] Custom base URL override (takes precedence over environment)
29
+ attr_writer :base_url
30
+
31
+ # @return [Symbol] API environment (:sandbox or :production)
32
+ attr_reader :environment
30
33
 
31
34
  def initialize
32
35
  @api_key = ENV.fetch("STRADDLE_API_KEY", nil)
33
- @base_url = ENV.fetch("STRADDLE_BASE_URL", SANDBOX_URL)
36
+ @environment = ENV.fetch("STRADDLE_ENVIRONMENT", "sandbox").to_sym
37
+ @base_url = ENV.fetch("STRADDLE_BASE_URL", nil)
34
38
  @open_timeout = integer_or_default("STRADDLE_OPEN_TIMEOUT", 5)
35
39
  @read_timeout = integer_or_default("STRADDLE_READ_TIMEOUT", 30)
40
+ validate_environment!
41
+ end
42
+
43
+ # @param value [Symbol, String] :sandbox or :production
44
+ # @raise [ArgumentError] if value is not a known environment
45
+ def environment=(value)
46
+ @environment = value.to_sym
47
+ validate_environment!
48
+ end
49
+
50
+ # @return [String] resolved base URL (custom override or environment-derived)
51
+ def base_url
52
+ @base_url || ENVIRONMENTS.fetch(@environment)
36
53
  end
37
54
 
38
55
  # @return [Logger] configured logger, falls back to Rails.logger or $stderr
@@ -42,6 +59,13 @@ module StraddlePay
42
59
 
43
60
  private
44
61
 
62
+ def validate_environment!
63
+ return if ENVIRONMENTS.key?(@environment)
64
+
65
+ raise ArgumentError,
66
+ "Unknown environment: #{@environment}. Must be one of: #{ENVIRONMENTS.keys.join(", ")}"
67
+ end
68
+
45
69
  def integer_or_default(key, default)
46
70
  Integer(ENV.fetch(key, default))
47
71
  rescue StandardError
@@ -2,5 +2,5 @@
2
2
 
3
3
  module StraddlePay
4
4
  # @return [String] current gem version
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
  end
data/lib/straddle_pay.rb CHANGED
@@ -6,8 +6,8 @@ require_relative "straddle_pay/version"
6
6
  #
7
7
  # @example Global configuration
8
8
  # StraddlePay.configure do |config|
9
- # config.api_key = ENV.fetch("STRADDLE_API_KEY")
10
- # config.base_url = StraddlePay::Config::PRODUCTION_URL
9
+ # config.api_key = ENV.fetch("STRADDLE_API_KEY")
10
+ # config.environment = :production
11
11
  # end
12
12
  #
13
13
  # @example Per-instance client
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: straddle_pay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dpaluy