Handling Webhooks
Learn how to receive and process webhook notifications from Pyramid.
Setup
Register your webhook endpoint in the Pyramid dashboard or via the API. Make sure your endpoint is publicly accessible and returns a 200 status code.
Handling Webhooks
Example webhook handler in Node.js:
app.post('/webhooks/pyramid', (req, res) => {
const event = req.body;
// Verify signature (see below)
switch (event.type) {
case 'transaction.completed':
// Handle completed transaction
console.log('Transaction completed:', event.data);
break;
case 'transaction.failed':
// Handle failed transaction
console.log('Transaction failed:', event.data);
break;
}
res.status(200).send('OK');
});Signature Verification
Always verify webhook signatures to ensure requests are from Pyramid:
const crypto = require('crypto');
function verifySignature(payload, signature, secret) {
const hmac = crypto.createHmac('sha256', secret);
const digest = hmac.update(payload).digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(digest)
);
}