Introduction

Webhooks are a way for Swervpay to provide real-time data to your application. They are HTTP callbacks that receive notification messages for events. When an event occurs, Swervpay sends an HTTP POST request to the webhook’s configured URL. Your endpoint should respond with a 2xx status code to indicate that the event has been successfully received.

Creating a Webhook

You can create a webhook from the dashboard.

Authentication

All webhook requests include a X-SWERV-SECRET header for verification. It should match the secret generated when creating the webhook.

const secret = process.env.SWERVPAY_SECRET;

function verifyWebhook(req, res, next) {
  if (req.headers['X-SWERV-SECRET'] !== secret) {
    return res.status(401).json({
      message: "Unauthorized request."
    });
  }
  next();
}

router.post('/webhook', verifyWebhook, (req, res) => {
  const webhook = req.body;
  switch(webhook.event) {
    case "card.created":
  
    break;
  }
  return res.sendStatus(200);
});

Retry

If a webhook fails, you have two main options to retry the failed delivery: