Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update webhook example to use async/await #92

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ const app = express()

// Create a `POST` endpoint to accept webhooks sent by Paddle.
// We need `raw` request body to validate the integrity. Use express raw middleware to ensure express doesn't convert the request body to JSON.
app.post('/webhooks', express.raw({ type: 'application/json' }), (req: Request, res: Response) => {
app.post('/webhooks', express.raw({ type: 'application/json' }), async (req: Request, res: Response) => {
const signature = (req.headers['paddle-signature'] as string) || '';
// req.body should be of type `buffer`, convert to string before passing it to `unmarshal`.
// If express returned a JSON, remove any other middleware that might have processed raw request to object
Expand All @@ -265,7 +265,7 @@ app.post('/webhooks', express.raw({ type: 'application/json' }), (req: Request,
try {
if (signature && rawRequestBody) {
// The `unmarshal` function will validate the integrity of the webhook and return an entity
const eventData = paddle.webhooks.unmarshal(rawRequestBody, secretKey, signature);
const eventData = await paddle.webhooks.unmarshal(rawRequestBody, secretKey, signature);
switch (eventData.eventType) {
case EventName.ProductUpdated:
console.log(`Product ${eventData.data.id} was updated`);
Expand Down
Loading