zai_payment 2.3.0 → 2.3.2

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: b74d44b6fb3083a1ffacfdad938d1ead025a6c7ae327a69f0b0a20c0c9bf217c
4
- data.tar.gz: 06e0c28b63d871523e65095953450519e6eb81d02c22c2154cc453977936274b
3
+ metadata.gz: bd5b738eff97b239ed278c2a96ce7b6e10383ca9401089648a9d390e2d29495f
4
+ data.tar.gz: 74831747ccf4bd3c901474d5ba082cac2297f801249fd5d02e8b923821d8c3b2
5
5
  SHA512:
6
- metadata.gz: cd47c060b0f3f8e42e3ddae83b3bef226fd5d963fafce84a37edb42b38a2f0662ce8b56f4cee4bdec33683c8d1cf0b86150d54fe232b4e9fb4659adf9939b100
7
- data.tar.gz: 57141c543bac064b1f93ec8733fc4f354056ba698cbdc87ae22d80c30fc08ed4949ec22577fe10b35efea829594b10df87dcb82aa63b35d1a2b5aec00e2186dd
6
+ metadata.gz: 5a66826701b65f29051a6b1244201bc3201b5b333e9253f184c46fb0494110dafd15fe53a4b02081c6e7f58f3e373a30ad82b17b9deacf4d25c43d9373499de7
7
+ data.tar.gz: '096136afbb0dbe39d25960c73f9d1c16649614dd657b74d24fb9dc54ad5f025683640fbe283fa890e2d48d33e152ad3e55bea7426e7bb07361eee1742d4c13f7'
data/badges/coverage.json CHANGED
@@ -1 +1 @@
1
- {"schemaVersion": 1, "label": "coverage", "message": "97.15%", "color": "brightgreen"}
1
+ {"schemaVersion": 1, "label": "coverage", "message": "96.2%", "color": "brightgreen"}
data/changelog.md CHANGED
@@ -1,4 +1,35 @@
1
1
  ## [Released]
2
+ ## [2.3.2] - 2025-10-29
3
+ ### Fixed
4
+ - **Timeout Error Handling**: Improved handling of timeout errors to prevent crashes
5
+ - Added explicit rescue for `Net::ReadTimeout` and `Net::OpenTimeout` errors
6
+ - Previously, these errors could sometimes bypass Faraday's error handling and crash the application
7
+ - Now properly converts all timeout errors to `Errors::TimeoutError` with descriptive messages
8
+ - Fixes issue: "Request timed out: Net::ReadTimeout with #<TCPSocket:(closed)>"
9
+
10
+ ### Changed
11
+ - **Increased Default Timeouts**: Adjusted default timeout values for better reliability
12
+ - Default `timeout` increased from 10 to 30 seconds (general request timeout)
13
+ - Added separate `read_timeout` configuration (default: 30 seconds)
14
+ - `open_timeout` remains at 10 seconds (connection establishment)
15
+ - Users can still customize timeouts via configuration:
16
+ ```ruby
17
+ ZaiPayment.configure do |config|
18
+ config.timeout = 60 # Custom general timeout
19
+ config.read_timeout = 60 # Custom read timeout
20
+ config.open_timeout = 15 # Custom open timeout
21
+ end
22
+ ```
23
+
24
+ ## [2.3.1] - 2025-10-28
25
+ ### Fixed
26
+ - **Token Refresh Bug**: Fixed authentication token not being refreshed after expiration
27
+ - Previously, the Authorization header was set once when the connection was created
28
+ - After ~1 hour, tokens would expire and subsequent API calls would fail with `UnauthorizedError`
29
+ - Now, the Authorization header is set dynamically on each request, ensuring fresh tokens are always used
30
+ - The `TokenProvider` automatically refreshes expired tokens, preventing authentication errors
31
+ - Fixes issue where some APIs would work while others failed after token expiration
32
+
2
33
  ## [2.3.0] - 2025-10-28
3
34
  ### Added
4
35
  - **User Management API Enhancement**: Added search parameter to list users endpoint
@@ -53,6 +53,7 @@ module ZaiPayment
53
53
  def request(method, path, params: {}, body: {})
54
54
  response = connection.public_send(method) do |req|
55
55
  req.url path
56
+ req.headers['Authorization'] = token_provider.bearer_token
56
57
  req.params = params if params.any?
57
58
  req.body = body if body.any?
58
59
  end
@@ -60,6 +61,8 @@ module ZaiPayment
60
61
  Response.new(response)
61
62
  rescue Faraday::Error => e
62
63
  handle_faraday_error(e)
64
+ rescue Net::ReadTimeout, Net::OpenTimeout => e
65
+ handle_net_timeout_error(e)
63
66
  end
64
67
 
65
68
  def connection
@@ -81,7 +84,7 @@ module ZaiPayment
81
84
  end
82
85
 
83
86
  def apply_headers(faraday)
84
- faraday.headers['Authorization'] = token_provider.bearer_token
87
+ # Authorization header is set per-request to ensure fresh tokens
85
88
  faraday.headers['Content-Type'] = 'application/json'
86
89
  faraday.headers['Accept'] = 'application/json'
87
90
  end
@@ -92,8 +95,13 @@ module ZaiPayment
92
95
  end
93
96
 
94
97
  def apply_timeouts(faraday)
95
- faraday.options.timeout = config.timeout if config.timeout
96
- faraday.options.open_timeout = config.open_timeout if config.open_timeout
98
+ set_timeout_option(faraday, :timeout, config.timeout)
99
+ set_timeout_option(faraday, :open_timeout, config.open_timeout)
100
+ set_timeout_option(faraday, :read_timeout, config.read_timeout)
101
+ end
102
+
103
+ def set_timeout_option(faraday, option, value)
104
+ faraday.options.public_send("#{option}=", value) if value
97
105
  end
98
106
 
99
107
  def base_url
@@ -119,5 +127,9 @@ module ZaiPayment
119
127
  raise Errors::ApiError, "Request failed: #{error.message}"
120
128
  end
121
129
  end
130
+
131
+ def handle_net_timeout_error(error)
132
+ raise Errors::TimeoutError, "Request timed out: #{error.class.name} with #{error.message}"
133
+ end
122
134
  end
123
135
  end
@@ -3,15 +3,16 @@
3
3
  module ZaiPayment
4
4
  class Config
5
5
  attr_accessor :environment, :client_id, :client_secret, :scope,
6
- :timeout, :open_timeout
6
+ :timeout, :open_timeout, :read_timeout
7
7
 
8
8
  def initialize
9
9
  @environment = :prelive # or :production
10
10
  @client_id = nil
11
11
  @client_secret = nil
12
12
  @scope = nil
13
- @timeout = 10
14
- @open_timeout = 10
13
+ @timeout = 30 # General timeout - increased from 10 to 30 seconds
14
+ @open_timeout = 10 # Connection open timeout
15
+ @read_timeout = 30 # Read timeout - new separate configuration
15
16
  end
16
17
 
17
18
  def validate!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZaiPayment
4
- VERSION = '2.3.0'
4
+ VERSION = '2.3.2'
5
5
  end
data/readme.md CHANGED
@@ -53,6 +53,11 @@ ZaiPayment.configure do |c|
53
53
  c.client_id = ENV.fetch("ZAI_CLIENT_ID")
54
54
  c.client_secret = ENV.fetch("ZAI_CLIENT_SECRET")
55
55
  c.scope = ENV.fetch("ZAI_OAUTH_SCOPE")
56
+
57
+ # Optional: Configure timeout settings (defaults shown)
58
+ c.timeout = 30 # General request timeout in seconds
59
+ c.open_timeout = 10 # Connection open timeout in seconds
60
+ c.read_timeout = 30 # Read timeout in seconds
56
61
  end
57
62
  ```
58
63
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zai_payment
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eddy Jaga