Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/api/core/types/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export enum WebhookEvents {
INVOICE_PAID = 'invoice.paid',
INVOICE_VOIDED = 'invoice.voided',
PAYMENT_SUCCEEDED = 'payment.succeeded',
INVOICE_SENT = 'invoice.sent',
}
35 changes: 35 additions & 0 deletions src/app/api/quickbooks/webhook/webhook.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
case WebhookEvents.PAYMENT_SUCCEEDED:
return await this.handlePaymentSucceeded(payload, qbTokenInfo)

case WebhookEvents.INVOICE_SENT:
return await this.handleInvoiceSent(payload, qbTokenInfo)

default:
console.error('WebhookService#handleWebhookEvent | Unknown event type')
}
Expand Down Expand Up @@ -376,6 +379,38 @@
}
}

private async handleInvoiceSent(
payload: unknown,
qbTokenInfo: IntuitAPITokensType,
) {
console.info('###### INVOICE SENT ######')
const parsedPayload = InvoiceCreatedResponseSchema.safeParse(payload)
if (!parsedPayload.success || !parsedPayload.data) {
console.error(
'WebhookService#handleInvoiceSent | Could not parse invoice response',
)
return
}
const parsedInvoiceResource = parsedPayload.data

try {
validateAccessToken(qbTokenInfo)
const invoiceService = new InvoiceService(this.user)
await invoiceService.webhookInvoiceCreated(parsedInvoiceResource, qbTokenInfo)

Check failure on line 399 in src/app/api/quickbooks/webhook/webhook.service.ts

View workflow job for this annotation

GitHub Actions / Run linters

Replace `parsedInvoiceResource,·qbTokenInfo` with `⏎········parsedInvoiceResource,⏎········qbTokenInfo,⏎······`
} catch (error: unknown) {
await this.pushFailedInvoiceToSyncLog(
EventType.CREATED,
parsedInvoiceResource.data.id,
parsedInvoiceResource.data.number,
parsedInvoiceResource.data.total,
getMessageAndCodeFromError(error),
)
console.error(
`WebhookService#handleInvoiceSent :: Error | Portal Id: ${this.user.workspaceId} | Invoice: ${parsedInvoiceResource.data.id}`,
)
}
}

private async handlePaymentSucceeded(
payload: unknown,
qbTokenInfo: IntuitAPITokensType,
Expand Down
Loading