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(security): repair PR #36 merge defects

rishabh43d13817d5f6
diff --git a/apps/payment-api/src/routes/checkout.routes.js b/apps/payment-api/src/routes/checkout.routes.js
index 2482533..ab65b87 100644
--- a/apps/payment-api/src/routes/checkout.routes.js
+++ b/apps/payment-api/src/routes/checkout.routes.js
@@ -1577,6 +1577,21 @@ export function registerCheckoutRoutes(server, ctx) {
const sourceSession = (conflictingSessionId ? ctx.sessionRepo.findById(conflictingSessionId) : null) || targetSession;
const customerId = body?.customerId || sourceSession?.customerId || targetSession.customerId || null;
+ // A settled order must not be restarted. The restarted session deliberately reuses the
+ // merchant's order reference, and the unique (merchant_id, order_id) index rejects a
+ // second row for an order that already succeeded — which surfaced as a 500. Refuse with a
+ // clear conflict instead of attempting the duplicate.
+ const paidSession = [sourceSession, targetSession].find(s => s && s.status === PaymentStatus.SUCCESS);
+ if (paidSession) {
+ HttpServer.json(res, 409, {
+ error: 'ORDER_ALREADY_PAID',
+ message: 'This order has already been paid and cannot be restarted.',
+ orderId: paidSession.orderId,
+ status: PaymentStatus.SUCCESS
+ });
+ return;
+ }
+
// 1. Identify ALL sessions on old/other devices that must be cancelled
const sessionsToTerminate = new Map();
diff --git a/packages/core/src/webhook-engine.js b/packages/core/src/webhook-engine.js
index d545662..58946b5 100644
--- a/packages/core/src/webhook-engine.js
+++ b/packages/core/src/webhook-engine.js
@@ -229,7 +229,11 @@ export class WebhookEngine {
}
const timestamp = Date.now().toString();
- const signature = generateHmac(`${timestamp}.${item.payload}`, merchant.webhookSecret);
+ // The signature must cover exactly the transmitted body, using the same formula as
+ // dispatch(). Signing `${timestamp}.${payload}` here meant a retried delivery carried a
+ // different MAC than the first attempt, so the merchant's verification (HMAC over the
+ // raw body, per the documented contract) rejected every retry.
+ const signature = generateHmac(item.payload, merchant.webhookSecret);
let isSuccess = false;
let respStatus = null;