Skip to content

Commit c40835b

Browse files
feat(api): add webhook schemas to SDKs - add parse and parse_unsafe
chore: replace custom webhook signature verification with standardwebhooks
1 parent 7458692 commit c40835b

File tree

186 files changed

+20928
-30
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+20928
-30
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 176
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/lithic%2Flithic-abe6a4f82f696099fa8ecb1cc44f08979e17d56578ae7ea68b0e9182e21df508.yml
33
openapi_spec_hash: d2ce51592a9a234c6f34a1168a31f91f
4-
config_hash: 739714a3fead0b26ee3a3b7bc51081f6
4+
config_hash: 2b2786c821f62db49cc630ba45329336

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ group :development, :test do
2222
gem "minitest-hooks"
2323
gem "minitest-proveit"
2424
gem "minitest-rg"
25+
gem "standardwebhooks", "~> 1.0", github: "standard-webhooks/standard-webhooks", glob: "libraries/ruby/*.gemspec"
2526
gem "webmock"
2627
end
2728

Gemfile.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ GIT
88
rbs
99
syntax_tree (>= 2.0.1)
1010

11+
GIT
12+
remote: https://github.com/standard-webhooks/standard-webhooks.git
13+
revision: a173a6c0125ca2b9245bf5ea3f1c61384ccc10a2
14+
glob: libraries/ruby/*.gemspec
15+
specs:
16+
standardwebhooks (1.0.0)
17+
1118
PATH
1219
remote: .
1320
specs:
@@ -214,6 +221,7 @@ DEPENDENCIES
214221
redcarpet
215222
rubocop
216223
sorbet
224+
standardwebhooks (~> 1.0)!
217225
steep
218226
syntax_tree
219227
syntax_tree-rbs!

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,41 @@ if page.next_page?
6464
end
6565
```
6666

67+
### Webhooks
68+
69+
Lithic uses webhooks to notify your application when events happen. The library provides signature verification via the optional `standardwebhooks` gem.
70+
71+
#### Parsing and verifying webhooks
72+
73+
```ruby
74+
# Verifies signature and returns typed event
75+
event = lithic.webhooks.parse(
76+
request.body.read,
77+
headers: request.headers,
78+
secret: ENV["LITHIC_WEBHOOK_SECRET"] # optional, reads from env by default
79+
)
80+
81+
case event
82+
when Lithic::Models::CardCreatedWebhookEvent
83+
puts("Card created: #{event.data.token}")
84+
end
85+
```
86+
87+
#### Parsing without verification
88+
89+
```ruby
90+
# Parse only - skips signature verification (not recommended for production)
91+
event = lithic.webhooks.parse_unsafe(request.body.read)
92+
```
93+
94+
#### Installing standardwebhooks (optional)
95+
96+
To use signature verification, install from GitHub:
97+
98+
```ruby
99+
gem "standardwebhooks", "~> 1.0", github: "standard-webhooks/standard-webhooks", glob: "libraries/ruby/*.gemspec"
100+
```
101+
67102
### Handling errors
68103

69104
When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of `Lithic::Errors::APIError` will be thrown:

lib/lithic.rb

Lines changed: 74 additions & 17 deletions
Large diffs are not rendered by default.

lib/lithic/client.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ class Client < Lithic::Internal::Transport::BaseClient
119119
# @return [Lithic::Resources::AccountActivity]
120120
attr_reader :account_activity
121121

122+
# @return [Lithic::Resources::Webhooks]
123+
attr_reader :webhooks
124+
122125
# Status of api
123126
#
124127
# @overload api_status(request_options: {})
@@ -225,6 +228,7 @@ def initialize(
225228
@fraud = Lithic::Resources::Fraud.new(client: self)
226229
@network_programs = Lithic::Resources::NetworkPrograms.new(client: self)
227230
@account_activity = Lithic::Resources::AccountActivity.new(client: self)
231+
@webhooks = Lithic::Resources::Webhooks.new(client: self)
228232
end
229233
end
230234
end

lib/lithic/errors.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,5 +224,20 @@ class RateLimitError < Lithic::Errors::APIStatusError
224224
class InternalServerError < Lithic::Errors::APIStatusError
225225
HTTP_STATUS = (500..)
226226
end
227+
228+
class MissingDependencyError < Lithic::Errors::Error
229+
# @api private
230+
#
231+
# @param gem_name [String]
232+
# @param feature [String]
233+
def initialize(gem_name:, feature:)
234+
message = [
235+
"The '#{gem_name}' gem is required to use #{feature}.",
236+
"Install it with: gem install #{gem_name}",
237+
"Or add it to your Gemfile: gem '#{gem_name}'"
238+
].join("\n")
239+
super(message)
240+
end
241+
end
227242
end
228243
end

0 commit comments

Comments
 (0)