Skip to content

Commit 0bfb2db

Browse files
Add Python example
1 parent de1a827 commit 0bfb2db

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

server-partner-program/purchase-webhooks.mdx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ value should be checked prior to accepting the webhook.
2121
This value is generated by computing a SHA256 HMAC hash of the body of the webhook. The secret to verify with will be provided to you as part
2222
of the setup process.
2323

24-
<Tabs items={['Node.js']}>
24+
<Tabs items={['Node.js', 'Python']}>
2525
<Tab>
2626
```javascript
2727
const signatureSecret = process.env.LUNAR_CLIENT_WEBHOOK_SECRET;
@@ -33,6 +33,22 @@ of the setup process.
3333
.digest("hex");
3434
```
3535
</Tab>
36+
<Tab>
37+
```python
38+
import os
39+
import hmac
40+
import hashlib
41+
42+
signature_secret = os.getenv('LUNAR_CLIENT_WEBHOOK_SECRET')
43+
body = ... # This must be the raw body of the webhook. Parsing as JSON and re-serializing can create differences in whitespace.
44+
45+
expected_signature = hmac.new(
46+
signature_secret.encode('utf-8'),
47+
body.encode('utf-8'),
48+
hashlib.sha256
49+
).hexdigest()
50+
```
51+
</Tab>
3652
</Tabs>
3753

3854
## Webhook Types

0 commit comments

Comments
 (0)