Skip to content

Feature/webhook delivery retry 102#104

Merged
Cedarich merged 4 commits intoZyntariHQ:mainfrom
EDOHWARES:feature/webhook-delivery-retry-102
Mar 7, 2026
Merged

Feature/webhook delivery retry 102#104
Cedarich merged 4 commits intoZyntariHQ:mainfrom
EDOHWARES:feature/webhook-delivery-retry-102

Conversation

@EDOHWARES
Copy link
Copy Markdown
Contributor

Description

Addresses the requirement for adding a persistent queue to deliver webhooks when an invoice status changes (e.g. paid, expired).

Resolves #102

Changes Made

  • Prisma Schema Updates: Extends the User map by appending webhookUrl and an optional webhookSecret. Adds a new table mapped natively as webhook_deliveries (WebhookDelivery), linked to existing Invoices, and configured carefully to track queues, processing logic metrics, and timestamps (lastAttemptAt/nextAttemptAt).
  • Webhook Queue Logic:
    • Added @nestjs/schedule to run a chron polling cycle polling queued deliveries every 1 minute.
    • Implemented the exponential backoff algorithm up to 5 progressive interval retries (Math.pow(2, attempts)) to throttle requests fairly in outage windows.
    • Integrated idempotency keys out of the box (x-idempotency-key) directly calculated off of specific internal delivery IDs bounds to its count iterations.
  • HMAC Signatures: Configures delivery using HMAC-SHA256 logic parsing x-invoisio-signature through standard node crypto utilizing the User supplied secret securely.
  • Invoice Hooks: The Webhooks Module dependency is cleanly injected directly into updateStatus and markAsPaid to enqueue payloads tracking the underlying invoice transitions (including tx_hash).
  • Test Scripts: All unit tests model HTTP request failures testing WebhooksService: Backoffs, max retries threshold caps (abandoning gracefully after 5 counts log-wise), omitting deliveries cleanly if blank webhooks rules apply, and ensuring successful delivery mutations check out correctly.

Testing Instructions

  • Re-generate prisma and apply database updates locally with migrations via .env URLs.
  • Start server watch mode.
  • Modify the test records to incorporate webhook hooks, alter states on those particular IDs to confirm that network queue executions and background retries reflect precisely on local tables or through standard request mocks.

Checklist

  • Adds persistent webhook payloads queue on invoice updates
  • Implements correct exponential backoff to handle failures up to 5 retries.
  • Generates expected metadata schema mapping attributes and keys
  • HMAC-SHA256 signature verification integrated using node internals
  • Includes unit tests coverage
  • Code passes ESLint formatting correctly natively without conflict overheads

@EDOHWARES
Copy link
Copy Markdown
Contributor Author

@Cedarich , pls review

@EDOHWARES
Copy link
Copy Markdown
Contributor Author

@Cedarich , lint error fixed!

Copy link
Copy Markdown
Contributor

@Cedarich Cedarich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Cedarich Cedarich merged commit bf0fe97 into ZyntariHQ:main Mar 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Webhook delivery retry queue for invoice status changes

2 participants