Skip to content
Closed
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
8 changes: 8 additions & 0 deletions lib/resources/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
22 changes: 20 additions & 2 deletions lib/resources/qrCode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const { normalizeDate } = require('../utils/razorpay-utils')

module.exports = function (api) {

const BASE_URL = "/payments/qr_codes";
Expand Down Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down
22 changes: 20 additions & 2 deletions lib/resources/settlements.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const { normalizeDate } = require('../utils/razorpay-utils')

module.exports = function (api) {

const BASE_URL = "/settlements";
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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[]"] }
}
Expand Down
31 changes: 31 additions & 0 deletions test/resources/payments.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
43 changes: 43 additions & 0 deletions test/resources/qrCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
});
});
});
59 changes: 59 additions & 0 deletions test/resources/settlements.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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()
})
});
});
});