Skip to content

Webhooks

Webhooks allow Paylinker to automatically notify your server when specific events occur in your account. This is crucial for handling asynchronous events like successful payments, refunds, or subscription renewals.

When to use Webhooks?

Use webhooks when you need to:

  • Provision services or ship goods after a successful payment.
  • Revoke access when a subscription is cancelled.
  • Update financial records after a refund.

Configure Webhook

  1. Log in to Paylinker Dashboard.
  2. Go to Developers > Webhooks.
  3. Click Add Endpoint.
  4. Enter your server URL (e.g., https://api.yoursite.com/webhooks/paylinker).
  5. Select the events you want to listen to (or select "All Events").

Verify Signatures

To ensure the request is from Paylinker, verify the signature in the header.

javascript
const webhookSecret = 'whsec_...'; // From Dashboard

app.post('/webhook', express.raw({type: 'application/json'}), (request, response) => {
  const sig = request.headers['paylinker-signature'];

  let event;

  try {
    event = Paylinker.webhooks.constructEvent(request.body, sig, webhookSecret);
  } catch (err) {
    response.status(400).send(`Webhook Error: ${err.message}`);
    return;
  }

  // Handle the event
  switch (event.type) {
    case 'payment_intent.succeeded':
      const paymentIntent = event.data.object;
      // Fulfill the purchase...
      break;
    default:
      console.log(`Unhandled event type ${event.type}`);
  }

  response.send();
});

Released under the MIT License.