app.post('/spankpay/callback', async (req, res) => { const sig = req.headers['x-spankpay-signature'] // ... validate signature ... try { const firstUse = await redis.set(`spankpay-webhook:${sig}`, '1', { // The nx - Not Exists - flag ensures the key can only be set once nx: true, // The ex - EXpire - flag ensures the key will expire after an hour ex: 60 * 60, }) if (!firstUse) return res.json({ received: true }) // ... handle webhook ... } catch (e) { // If there is an error, clear the flag so that the webhook // will be processed on a subsequent request. // NOTE: your application must be careful not to leave the // webhook in a partially processed state, otherwise // there may be inconsistencies when it is retried. await redis.del(`spankpay-webhook:${sig}`) throw e } return res.json({ received: true }) })
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter