API Reference - SpankPay Developer Documentation
Sat Sep 10 2022 19:27:53 GMT+0000 (Coordinated Universal Time)
Saved by
@JohnnyBGoode
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 })
})
content_copyCOPY
https://docs.spankpay.com/api-reference/
Comments