Skip to content

IIAPI Webhooks

IIAPI receives webhook notifications from T-VAN providers about invoice status changes.

Overview

Webhook Endpoint

POST /api/iiapi/webhook

Event Types

EventDescription
INVOICE_SIGNEDT-VAN signed the invoice
INVOICE_SENTInvoice sent to CQT
INVOICE_ACCEPTEDCQT accepted invoice
INVOICE_REJECTEDCQT rejected invoice

Webhook Payload

typescript
interface IIAPIWebhookPayload {
  event: 'INVOICE_SIGNED' | 'INVOICE_SENT' | 'INVOICE_ACCEPTED' | 'INVOICE_REJECTED';
  invoiceId: string;
  invoiceNumber: string;
  status: string;
  provider: string;
  timestamp: string;
  data: {
    // Event-specific data
  };
}

Handle Webhook

typescript
// Configure webhook handler
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;
    }
  },
}

Rejection Handling

When CQT rejects an invoice:

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

  // Log rejection
  await auditService.logRejection({
    invoiceId: data.invoiceId,
    reason,
    errorCode,
  });

  // Attempt auto-correction if possible
  if (errorCode === 'INVALID_TAX_CODE') {
    // Lookup correct tax code
    const correctedTaxCode = await tvanService.lookupTaxCode(originalTaxCode);
    // Update and resubmit
  }
}

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