Skip to content

Commit 05abadc

Browse files
author
Dan Billson
authored
docs: update webhook example to use async/await (#92)
1 parent c7cb61a commit 05abadc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ const app = express()
254254

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

0 commit comments

Comments
 (0)