From 0b4f68f315164061943f5f7f01c98b8f00bc103d Mon Sep 17 00:00:00 2001 From: vinothksekar <132795481+vinothksekar@users.noreply.github.com> Date: Fri, 3 Jul 2026 07:44:42 +0530 Subject: [PATCH] Normalize from/to dates in QR code, settlement and refund list endpoints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `qrCode.all`, `qrCode.fetchAllPayments`, `settlements.all`, `settlements.fetchAllOndemandSettlement` and `payments.fetchMultipleRefund` destructured `{ from, to, count, skip }` from params and then spread them back into the request as `{ ...params, from, to, count, skip }` — a no-op that never called `normalizeDate`. As a result these endpoints did not convert `from`/`to` Date objects / date strings into epoch seconds the way every other list endpoint (orders.all, payments.all, items.all, invoices.all, addons.all) does, so passing a human date silently sent an unconverted value to the API. Normalize `from`/`to` via normalizeDate in these five methods (added the util import to qrCode.js and settlements.js). normalizeDate passes numeric timestamps through unchanged, so this is backward compatible for callers already sending epoch seconds. Added regression tests asserting the dates are converted (they fail without this change). Co-Authored-By: Claude Opus 4.8 --- lib/resources/payments.js | 8 ++++ lib/resources/qrCode.js | 22 ++++++++++- lib/resources/settlements.js | 22 ++++++++++- test/resources/payments.spec.js | 31 ++++++++++++++++ test/resources/qrCode.spec.js | 43 ++++++++++++++++++++++ test/resources/settlements.spec.js | 59 ++++++++++++++++++++++++++++++ 6 files changed, 181 insertions(+), 4 deletions(-) diff --git a/lib/resources/payments.js b/lib/resources/payments.js index f4550398..e703be86 100644 --- a/lib/resources/payments.js +++ b/lib/resources/payments.js @@ -141,6 +141,14 @@ module.exports = function (api) { let { from, to, count, skip } = params, url = `${BASE_URL}/${paymentId}/refunds`; + if (from) { + from = normalizeDate(from) + } + + if (to) { + to = normalizeDate(to) + } + return api.get({ url, data: { diff --git a/lib/resources/qrCode.js b/lib/resources/qrCode.js index 05247777..21696d1f 100644 --- a/lib/resources/qrCode.js +++ b/lib/resources/qrCode.js @@ -1,5 +1,7 @@ 'use strict' +const { normalizeDate } = require('../utils/razorpay-utils') + module.exports = function (api) { const BASE_URL = "/payments/qr_codes"; @@ -36,7 +38,15 @@ module.exports = function (api) { let { from, to, count, skip } = params, url = BASE_URL; - + + if (from) { + from = normalizeDate(from) + } + + if (to) { + to = normalizeDate(to) + } + return api.get({ url, data: { @@ -61,7 +71,15 @@ module.exports = function (api) { let { from, to, count, skip } = params, url = `${BASE_URL}/${qrCodeId}/payments`; - + + if (from) { + from = normalizeDate(from) + } + + if (to) { + to = normalizeDate(to) + } + return api.get({ url, data: { diff --git a/lib/resources/settlements.js b/lib/resources/settlements.js index d881311a..ed521cdd 100644 --- a/lib/resources/settlements.js +++ b/lib/resources/settlements.js @@ -1,5 +1,7 @@ 'use strict' +const { normalizeDate } = require('../utils/razorpay-utils') + module.exports = function (api) { const BASE_URL = "/settlements"; @@ -36,7 +38,15 @@ module.exports = function (api) { let { from, to, count, skip } = params, url = BASE_URL; - + + if (from) { + from = normalizeDate(from) + } + + if (to) { + to = normalizeDate(to) + } + return api.get({ url, data: { @@ -109,7 +119,15 @@ module.exports = function (api) { let expand ; let { from, to, count, skip } = params, url = `${BASE_URL}/ondemand`; - + + if (from) { + from = normalizeDate(from) + } + + if (to) { + to = normalizeDate(to) + } + if(params.hasOwnProperty("expand[]")) { expand = { "expand[]" : params["expand[]"] } } diff --git a/test/resources/payments.spec.js b/test/resources/payments.spec.js index 9bf2fb60..c0c0a34f 100644 --- a/test/resources/payments.spec.js +++ b/test/resources/payments.spec.js @@ -72,6 +72,37 @@ describe('PAYMENTS', () => { }) }) + describe('Fetch multiple refunds for a payment', () => { + it('`From` & `To` dates are converted to seconds', (done) => { + let fromDate = 'Aug 25, 2016' + let toDate = 'Aug 30, 2016' + let fromDateInSecs = getDateInSecs(fromDate) + let toDateInSecs = getDateInSecs(toDate) + + mocker.mock({ + url: `/payments/${TEST_PAYMENT_ID}/refunds` + }) + + rzpInstance.payments.fetchMultipleRefund(TEST_PAYMENT_ID, { + from: fromDate, + to: toDate, + count: 25, + skip: 5 + }).then((response) => { + assert.ok(equal( + response.__JUST_FOR_TESTS__.requestQueryParams, + { + from: fromDateInSecs, + to: toDateInSecs, + count: 25, + skip: 5 + } + ), 'from & to dates are converted to seconds') + done() + }) + }) + }) + describe('Payment fetch', () => { it('Throw error when paymentId is not provided', () => { assert.throws( diff --git a/test/resources/qrCode.spec.js b/test/resources/qrCode.spec.js index 8fde5e26..3186980d 100644 --- a/test/resources/qrCode.spec.js +++ b/test/resources/qrCode.spec.js @@ -336,5 +336,48 @@ describe('QRCODE ', () => { mockerParams, methodArgs }); + + it('`From` & `To` dates are converted to seconds', (done) => { + let fromDate = 'Aug 25, 2016' + let toDate = 'Aug 30, 2016' + let fromDateInSecs = getDateInSecs(fromDate) + let toDateInSecs = getDateInSecs(toDate) + + mocker.mock({ + url: `${SUB_PATH}/${TEST_QRCODE_ID}/payments` + }) + + rzpInstance.qrCode.fetchAllPayments(TEST_QRCODE_ID, { + from: fromDate, + to: toDate + }).then((response) => { + assert.equal(response.__JUST_FOR_TESTS__.requestQueryParams.from, fromDateInSecs) + assert.equal(response.__JUST_FOR_TESTS__.requestQueryParams.to, toDateInSecs) + done() + }) + }); + }); + + describe("Fetch all QrCode date normalization", () => { + + it('`From` & `To` dates are converted to seconds', (done) => { + let fromDate = 'Aug 25, 2016' + let toDate = 'Aug 30, 2016' + let fromDateInSecs = getDateInSecs(fromDate) + let toDateInSecs = getDateInSecs(toDate) + + mocker.mock({ + url: SUB_PATH + }) + + rzpInstance.qrCode.all({ + from: fromDate, + to: toDate + }).then((response) => { + assert.equal(response.__JUST_FOR_TESTS__.requestQueryParams.from, fromDateInSecs) + assert.equal(response.__JUST_FOR_TESTS__.requestQueryParams.to, toDateInSecs) + done() + }) + }); }); }); \ No newline at end of file diff --git a/test/resources/settlements.spec.js b/test/resources/settlements.spec.js index 8da6af6c..5ad48fda 100644 --- a/test/resources/settlements.spec.js +++ b/test/resources/settlements.spec.js @@ -4,6 +4,8 @@ const chai = require('chai') const { assert } = chai const rzpInstance = require('../razorpay') const mocker = require('../mocker') +const equal = require('deep-equal') +const { getDateInSecs } = require('../../dist/utils/razorpay-utils') const { runCallbackCheckTest, runParamsCheckTest } = require("../../dist/utils/predefined-tests.js"); @@ -119,6 +121,35 @@ describe("Fetch all settlements", () => { mockerParams, methodArgs }); + + it('`From` & `To` dates are converted to seconds', (done) => { + let fromDate = 'Aug 25, 2016' + let toDate = 'Aug 30, 2016' + let fromDateInSecs = getDateInSecs(fromDate) + let toDateInSecs = getDateInSecs(toDate) + + mocker.mock({ + url: SUB_PATH + }) + + rzpInstance.settlements.all({ + from: fromDate, + to: toDate, + count: 25, + skip: 5 + }).then((response) => { + assert.ok(equal( + response.__JUST_FOR_TESTS__.requestQueryParams, + { + from: fromDateInSecs, + to: toDateInSecs, + count: 25, + skip: 5 + } + ), 'from & to dates are converted to seconds') + done() + }) + }); }); describe("Settlement report for a month", () => { @@ -192,6 +223,34 @@ describe("Fetch all settlements", () => { mockerParams, methodArgs }); + + it('`From` & `To` dates are converted to seconds', (done) => { + let fromDate = 'Aug 25, 2016' + let toDate = 'Aug 30, 2016' + let fromDateInSecs = getDateInSecs(fromDate) + let toDateInSecs = getDateInSecs(toDate) + + mocker.mock({ + url: `${SUB_PATH}/ondemand` + }) + + rzpInstance.settlements.fetchAllOndemandSettlement({ + from: fromDate, + to: toDate, + count: 25, + skip: 5 + }).then((response) => { + assert.ok(equal( + response.__JUST_FOR_TESTS__.requestQueryParams.from, + fromDateInSecs + ), 'from date is converted to seconds') + assert.ok(equal( + response.__JUST_FOR_TESTS__.requestQueryParams.to, + toDateInSecs + ), 'to date is converted to seconds') + done() + }) + }); }); });