You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+35-15Lines changed: 35 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -200,27 +200,47 @@ card = client.cards.create(
200
200
)
201
201
```
202
202
203
-
## Webhook Verification
203
+
## Webhooks
204
204
205
-
We provide helper methods for verifying that a webhook request came from Lithic, and not a malicious third party.
205
+
Lithic uses webhooks to notify your application when events happen. The library provides signature verification via the optional `standardwebhooks` package.
206
206
207
-
You can use `lithic.webhooks.verify_signature(body: string, headers, secret?) -> None` or `lithic.webhooks.unwrap(body: string, headers, secret?) -> Payload`,
208
-
both of which will raise an error if the signature is invalid.
207
+
### Parsing and verifying webhooks
209
208
210
-
Note that the "body" parameter must be the raw JSON string sent from the server (do not parse it first).
211
-
The `.unwrap()` method can parse this JSON for you into a `Payload` object.
209
+
```py
210
+
from lithic.types import CardCreatedWebhookEvent
211
+
212
+
# Verifies signature and returns typed event
213
+
event = client.webhooks.parse(
214
+
request.body, # raw request body as string
215
+
headers=request.headers,
216
+
secret=os.environ["LITHIC_WEBHOOK_SECRET"] # optional, reads from env by default
217
+
)
218
+
219
+
# Use isinstance to narrow the type
220
+
ifisinstance(event, CardCreatedWebhookEvent):
221
+
print(f"Card created: {event.card_token}")
222
+
```
223
+
224
+
### Parsing without verification
225
+
226
+
```py
227
+
# Parse only - skips signature verification (not recommended for production)
0 commit comments