Skip to content

Webhooks IIAPI

IIAPI nhận thông báo webhook từ các nhà cung cấp T-VAN về thay đổi trạng thái hóa đơn.

Tổng quan

Điểm cuối Webhook

POST /api/iiapi/webhook

Các loại Sự kiện

Sự kiệnMô tả
INVOICE_SIGNEDT-VAN đã ký hóa đơn
INVOICE_SENTHóa đơn đã gửi đến CQT
INVOICE_ACCEPTEDCQT đã chấp nhận hóa đơn
INVOICE_REJECTEDCQT đã từ chối hóa đơn

Payload Webhook

typescript
interface IIAPIWebhookPayload {
  event: 'INVOICE_SIGNED' | 'INVOICE_SENT' | 'INVOICE_ACCEPTED' | 'INVOICE_REJECTED';
  invoiceId: string;
  invoiceNumber: string;
  status: string;
  provider: string;
  timestamp: string;
  data: {
    // Dữ liệu cụ thể theo sự kiện
  };
}

Xử lý Webhook

typescript
// Cấu hình trình xử lý webhook
iiApiOptions: {
  enableControllers: true,
  onWebhook: async (event, data) => {
    switch (event) {
      case 'INVOICE_ACCEPTED':
        await saleOrderService.updateInvoiceStatus(data.invoiceId, 'COMPLETED');
        await notificationService.send({
          type: 'INVOICE_READY',
          invoiceNumber: data.invoiceNumber,
        });
        break;

      case 'INVOICE_REJECTED':
        await alertService.notifyAdmin({
          type: 'INVOICE_REJECTION',
          invoiceId: data.invoiceId,
          reason: data.reason,
        });
        break;
    }
  },
}

Xử lý Từ chối

Khi CQT từ chối một hóa đơn:

typescript
if (event === 'INVOICE_REJECTED') {
  const { reason, errorCode, suggestions } = data;

  // Ghi nhật ký từ chối
  await auditService.logRejection({
    invoiceId: data.invoiceId,
    reason,
    errorCode,
  });

  // Cố gắng tự động sửa nếu có thể
  if (errorCode === 'INVALID_TAX_CODE') {
    // Tra cứu mã số thuế đúng
    const correctedTaxCode = await tvanService.lookupTaxCode(originalTaxCode);
    // Cập nhật và gửi lại
  }
}

Liên quan

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.