Skip to content

A self-hosted UPI & COD payment gateway with zero per-transaction platform fees, universal JavaScript checkout integration, dynamic QR payments, WhatsApp OTP authentication, and automated payment verification.

JavaScript

fix(webhooks): scope durable delivery cleanup to each outcome

generaltony007459ac78dc838
diff --git a/packages/core/src/webhook-engine.js b/packages/core/src/webhook-engine.js
index 9e4eb89..980aef5 100644
--- a/packages/core/src/webhook-engine.js
+++ b/packages/core/src/webhook-engine.js
@@ -105,8 +105,8 @@ export class WebhookEngine {
// is missing or unsafe, KEEP that entry instead of recording an irrecoverable
// synthetic failure row; the operator can repair configuration and replay.
const isOutboxed = Boolean(this.db.queryOne(
- 'SELECT payment_id FROM payment_webhook_outbox WHERE payment_id = ?',
- [session.id]
+ 'SELECT payment_id FROM payment_webhook_outbox WHERE payment_id = ? AND event_type = ?',
+ [session.id, publicOutcome]
));
// Direct non-outboxed dispatches still write an auditable failure record.
@@ -210,7 +210,7 @@ export class WebhookEngine {
}
// Outbox cleanup commits together with durable delivery preparation.
- this.db.execute('DELETE FROM payment_webhook_outbox WHERE payment_id = ?', [session.id]);
+ this.db.execute('DELETE FROM payment_webhook_outbox WHERE payment_id = ? AND event_type = ?', [session.id, publicOutcome]);
const signature = generateHmac(payloadString, merchant.webhookSecret);
const timestampedSignature = generateHmac(`${timestamp}.${payloadString}`, merchant.webhookSecret);
@@ -231,7 +231,7 @@ export class WebhookEngine {
// that row and skip the fetch — every first dispatch returned
// { delivered: false, status: null, error: null } because of that re-query.
if (isOutboxed) {
- this.db.execute('DELETE FROM payment_webhook_outbox WHERE payment_id = ?', [session.id]);
+ this.db.execute('DELETE FROM payment_webhook_outbox WHERE payment_id = ? AND event_type = ?', [session.id, publicOutcome]);
}
let responseStatus = null;