资源 / Webhooks

实时事件通知

当您的 Laabam 账户中发生事件时接收即时通知

实时性

事件发生时立即收到通知

可靠性

具有指数退避的自动重试机制

可监控

跟踪交付状态并调试问题

可用事件

invoice.created

创建新发票时触发

示例载荷:

{
  "invoice_id": "inv_123",
  "status": "draft",
  "amount": 50000
}
invoice.paid

收到发票付款时触发

示例载荷:

{
  "invoice_id": "inv_123",
  "payment_id": "pay_456",
  "amount": 50000
}
customer.created

添加新客户时触发

示例载荷:

{
  "customer_id": "cust_789",
  "name": "John Doe",
  "email": "john@example.com"
}
payment.failed

付款尝试失败时触发

示例载荷:

{
  "payment_id": "pay_456",
  "reason": "insufficient_funds"
}

实现示例

以下是在您的应用程序中处理 webhooks 的方法:

// Webhook endpoint example (Node.js/Express)
const express = require('express');
const app = express();

app.post('/webhooks/laabam', express.json(), (req, res) => {
  const event = req.body;
  
  // Verify webhook signature
  const signature = req.headers['x-laabam-signature'];
  if (!verifySignature(signature, req.body)) {
    return res.status(401).send('Invalid signature');
  }
  
  // Handle different event types
  switch (event.type) {
    case 'invoice.created':
      console.log('New invoice:', event.data.invoice_id);
      // Your business logic here
      break;
      
    case 'invoice.paid':
      console.log('Payment received:', event.data.payment_id);
      // Update your database, send email, etc.
      break;
  }
  
  res.status(200).send('Webhook received');
});

您的 Webhooks

https://api.yoursite.com/webhooks/laabam
激活
invoice.createdinvoice.paid

最后交付

2分钟前

成功率

99.8%

https://staging.yoursite.com/webhooks
激活
customer.createdpayment.failed

最后交付

15分钟前

成功率

100%

Webhook 最佳实践

  • 始终验证 webhook 签名以确保真实性
  • 快速返回 200 状态码以确认接收
  • 在队列中异步处理 webhook 数据
  • 使用 HTTPS 端点确保数据安全
  • 实现幂等性以处理重复事件

开始使用 Webhooks

使用 Laabam webhooks 构建实时集成