From 85e2fc768d99277ce7d6a218043e5e42e7aae338 Mon Sep 17 00:00:00 2001 From: Ankit Das <89454448+ankitdas13@users.noreply.github.com> Date: Wed, 16 Aug 2023 13:17:45 +0530 Subject: [PATCH 1/3] Close disclosed data (#373) --- documents/payment.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documents/payment.md b/documents/payment.md index 743df19..e963e29 100644 --- a/documents/payment.md +++ b/documents/payment.md @@ -200,7 +200,7 @@ instance.orders.fetchPayments(orderId) "wallet": null, "vpa": null, "email": "gaurav.kumar@example.com", - "contact": "9364591752", + "contact": "+919999999999", "fee": 70, "tax": 10, "error_code": null, From 6672b524a5e00125396cc0b1b6613ff72361f1d8 Mon Sep 17 00:00:00 2001 From: Ankit Das <89454448+ankitdas13@users.noreply.github.com> Date: Wed, 16 Aug 2023 18:34:08 +0530 Subject: [PATCH 2/3] fix : Encoded type to body (#369) --- lib/api.js | 28 +++++++------------ lib/resources/accounts.js | 14 +++------- lib/resources/customers.js | 12 ++------- lib/resources/fundAccount.js | 2 -- lib/resources/invoices.js | 18 ++++--------- lib/resources/items.js | 26 +++++------------- lib/resources/orders.js | 19 ++++--------- lib/resources/paymentLink.js | 9 ++----- lib/resources/payments.js | 32 ++++------------------ lib/resources/plans.js | 9 +++---- lib/resources/products.js | 14 ++-------- lib/resources/qrCode.js | 13 ++------- lib/resources/refunds.js | 6 +---- lib/resources/settlements.js | 14 ++-------- lib/resources/stakeholders.js | 37 +++----------------------- lib/resources/subscriptions.js | 20 +++----------- lib/resources/tokens.js | 5 +--- lib/resources/transfers.js | 26 ++++-------------- lib/resources/virtualAccounts.js | 5 +--- lib/types/api.d.ts | 6 +++++ test/mocker.js | 2 +- test/resources/customers.spec.js | 11 +++++--- test/resources/invoices.spec.js | 4 +-- test/resources/orders.spec.js | 12 +++++---- test/resources/payments.spec.js | 24 +++++++++++------ test/resources/plans.spec.js | 2 +- test/resources/subscriptions.spec.js | 4 +-- test/resources/transfers.spec.js | 20 +++++++++----- test/resources/virtualAccounts.spec.js | 7 ++--- 29 files changed, 119 insertions(+), 282 deletions(-) diff --git a/lib/api.js b/lib/api.js index 8159fb7..ba733e5 100644 --- a/lib/api.js +++ b/lib/api.js @@ -70,42 +70,32 @@ class API { post(params, cb) { let request = { url: this.getEntityUrl(params), - form: params.data + body: params.data }; - - if (params.hasOwnProperty('formData')) { - delete request['form']; - request.formData = params.formData; - } return nodeify(this.rq.post(request).catch(normalizeError), cb); } - postBody(params, cb) { + // postFormData method for file uploads. + postFormData(params, cb){ let request = { - url: this.getEntityUrl(params), - body: params.data - }; - return nodeify(this.rq.post(request).catch(normalizeError), cb); + url: this.getEntityUrl(params), + formData: params.formData + }; + return nodeify(this.rq.post(request).catch(normalizeError), cb); } put(params, cb) { return nodeify(this.rq.put({ url: this.getEntityUrl(params), - form: params.data + body: params.data }).catch(normalizeError), cb) } patch(params, cb) { let request = { url: this.getEntityUrl(params), - form: params.data + body: params.data }; - - if(params.data.hasOwnProperty("isbody")) { - delete request['form']; - delete params.data.isbody; - request.body = params.data; - } return nodeify(this.rq.patch(request).catch(normalizeError), cb); } diff --git a/lib/resources/accounts.js b/lib/resources/accounts.js index 95d3076..e682bf4 100644 --- a/lib/resources/accounts.js +++ b/lib/resources/accounts.js @@ -1,31 +1,23 @@ 'use strict'; -const { normalizeNotes } = require('../utils/razorpay-utils') - module.exports = function (api) { const BASE_URL = "/accounts"; return { create(params, callback) { - let { notes, ...rest } = params - let data = Object.assign(rest, normalizeNotes(notes)); - return api.post({ version: 'v2', url: `${BASE_URL}`, - data: data + data: params }, callback); }, edit(accountId, params, callback) { - let { notes, ...rest } = params - let data = Object.assign(rest, normalizeNotes(notes)); - return api.patch({ version: 'v2', url: `${BASE_URL}/${accountId}`, - data: data + data: params }, callback); }, @@ -44,7 +36,7 @@ module.exports = function (api) { }, uploadAccountDoc(accountId, params, callback) { - return api.post({ + return api.postFormData({ version: 'v2', url: `${BASE_URL}/${accountId}/documents`, formData: params diff --git a/lib/resources/customers.js b/lib/resources/customers.js index d8a9510..2ea7d24 100644 --- a/lib/resources/customers.js +++ b/lib/resources/customers.js @@ -1,26 +1,18 @@ 'use strict' -const { normalizeNotes, normalizeBoolean } = require('../utils/razorpay-utils') - module.exports = function (api) { return { create(params, callback) { - let { notes, ...rest } = params - let data = Object.assign(rest, normalizeNotes(notes)) - return api.post({ url: '/customers', - data + data: params }, callback) }, edit(customerId, params, callback) { - let { notes, ...rest } = params - let data = Object.assign(rest, normalizeNotes(notes)) - return api.put({ url: `/customers/${customerId}`, - data + data: params }, callback) }, diff --git a/lib/resources/fundAccount.js b/lib/resources/fundAccount.js index a0bc634..9805909 100644 --- a/lib/resources/fundAccount.js +++ b/lib/resources/fundAccount.js @@ -1,7 +1,5 @@ 'use strict' -const { normalizeNotes } = require('../utils/razorpay-utils') - module.exports = function (api) { return { create(params, callback) { diff --git a/lib/resources/invoices.js b/lib/resources/invoices.js index cd09634..d60665e 100644 --- a/lib/resources/invoices.js +++ b/lib/resources/invoices.js @@ -5,7 +5,7 @@ */ const Promise = require("promise"), - { normalizeDate, normalizeNotes, normalizeBoolean } = require('../utils/razorpay-utils'); + { normalizeDate } = require('../utils/razorpay-utils'); module.exports = function invoicesApi (api) { @@ -32,16 +32,10 @@ module.exports = function invoicesApi (api) { * @return {Promise} */ - let url = BASE_URL, - { notes, partial_payment, ...rest } = params - - let data = Object.assign({ - partial_payment: normalizeBoolean(partial_payment), - ...rest - }, normalizeNotes(notes)) + let url = BASE_URL; return api.post({ url, - data + data: params }, callback) }, @@ -57,9 +51,7 @@ module.exports = function invoicesApi (api) { * @return {Promise} */ - let url = `${BASE_URL}/${invoiceId}`, - { notes, ...rest } = params, - data = Object.assign(rest, normalizeNotes(notes)); + let url = `${BASE_URL}/${invoiceId}`; if (!invoiceId) { @@ -68,7 +60,7 @@ module.exports = function invoicesApi (api) { return api.patch({ url, - data + data: params }, callback); }, diff --git a/lib/resources/items.js b/lib/resources/items.js index 9398b91..29bec2c 100644 --- a/lib/resources/items.js +++ b/lib/resources/items.js @@ -1,6 +1,6 @@ 'use strict' -const { normalizeDate, normalizeBoolean } = require('../utils/razorpay-utils') +const { normalizeDate } = require('../utils/razorpay-utils') module.exports = function (api) { return { @@ -17,7 +17,6 @@ module.exports = function (api) { count = Number(count) || 10 skip = Number(skip) || 0 - authorized = normalizeBoolean(authorized) return api.get({ url: '/items', @@ -43,11 +42,7 @@ module.exports = function (api) { }, create(params = {}, callback) { - var name = params.name; - var amount = params.amount; - var currency = params.currency; - var description = params.description; - + let { amount, currency , ...rest } = params currency = currency || 'INR' if (!amount) { @@ -55,12 +50,10 @@ module.exports = function (api) { } let data = Object.assign({ - name, - amount, currency, - description + amount, + ...rest }) - return api.post({ url: '/items', data @@ -73,17 +66,10 @@ module.exports = function (api) { throw new Error('`item_id` is mandatory') } - let url = `/items/${itemId}`, - { active, ...rest } = params - - let data = Object.assign({ - active: normalizeBoolean(active), - ...rest - }) - + let url = `/items/${itemId}`; return api.patch({ url, - data + data: params }, callback) }, diff --git a/lib/resources/orders.js b/lib/resources/orders.js index f6e00b8..b1bc20c 100644 --- a/lib/resources/orders.js +++ b/lib/resources/orders.js @@ -1,6 +1,6 @@ 'use strict' -const { normalizeDate, normalizeBoolean, normalizeNotes } = require('../utils/razorpay-utils') +const { normalizeDate } = require('../utils/razorpay-utils') module.exports = function (api) { return { @@ -22,7 +22,7 @@ module.exports = function (api) { count = Number(count) || 10 skip = Number(skip) || 0 - authorized = normalizeBoolean(authorized) + authorized = authorized return api.get({ url: '/orders', @@ -49,19 +49,13 @@ module.exports = function (api) { }, create(params = {}, callback) { - let { amount, currency, receipt, partial_payment,payment_capture, notes, method, - ...otherParams } = params + let { currency, ...otherParams } = params currency = currency || 'INR' let data = Object.assign({ - amount, currency, - receipt, - method, - partial_payment: normalizeBoolean(partial_payment), - payment_capture: normalizeBoolean(payment_capture), ...otherParams - }, normalizeNotes(notes)) + }) return api.post({ url: '/orders', @@ -70,17 +64,14 @@ module.exports = function (api) { }, edit(orderId, params = {}, callback) { - let { notes } = params if (!orderId) { throw new Error('`order_id` is mandatory') } - let data = Object.assign(normalizeNotes(notes)) - return api.patch({ url: `/orders/${orderId}`, - data + data: params }, callback) }, diff --git a/lib/resources/paymentLink.js b/lib/resources/paymentLink.js index 51bd227..459346f 100644 --- a/lib/resources/paymentLink.js +++ b/lib/resources/paymentLink.js @@ -26,7 +26,7 @@ module.exports = function paymentLinkApi (api) { */ let url = BASE_URL; - return api.postBody({ + return api.post({ url, data: params }, callback) @@ -115,14 +115,9 @@ module.exports = function paymentLinkApi (api) { }, edit(paymentLinkId, params, callback) { - let rest = params; - var isbody = true - - var data = {isbody, ...rest}; - return api.patch({ url: `${BASE_URL}/${paymentLinkId}`, - data + data: params }, callback) }, diff --git a/lib/resources/payments.js b/lib/resources/payments.js index 9a7d29e..dcd6b26 100644 --- a/lib/resources/payments.js +++ b/lib/resources/payments.js @@ -2,7 +2,7 @@ const Promise = require("promise"); -const { normalizeDate, normalizeBoolean, normalizeNotes } = require('../utils/razorpay-utils') +const { normalizeDate } = require('../utils/razorpay-utils') const ID_REQUIRED_MSG = '`payment_id` is mandatory', BASE_URL = '/payments'; @@ -102,40 +102,29 @@ module.exports = function (api) { }, callback); }, createRecurringPayment(params, callback) { - let { notes, ...rest } = params - let data = Object.assign(rest, normalizeNotes(notes)) - return api.post({ url: `${BASE_URL}/create/recurring`, - data + data: params }, callback) }, edit(paymentId, params = {}, callback) { - let { notes } = params - if (!paymentId) { throw new Error('`payment_id` is mandatory') } - let data = Object.assign(normalizeNotes(notes)) - return api.patch({ url: `${BASE_URL}/${paymentId}`, - data + data: params }, callback) }, refund(paymentId, params = {}, callback) { - let { notes, ...otherParams } = params - if (!paymentId) { throw new Error('`payment_id` is mandatory') } - - let data = Object.assign(otherParams, normalizeNotes(notes)) return api.post({ url: `${BASE_URL}/${paymentId}/refund`, - data + data: params }, callback) }, @@ -204,20 +193,9 @@ module.exports = function (api) { if (!paymentId) { throw new Error('`payment_id` is mandatory') } - - let { notes, ...otherParams } = params - - let data = Object.assign(otherParams, normalizeNotes(notes)) - - if (data.transfers) { - let transfers = data.transfers - transfers.forEach(function (transfer) { - transfer.on_hold = normalizeBoolean(!!transfer.on_hold); - }) - } return api.post({ url: `${BASE_URL}/${paymentId}/transfers`, - data + data: params }, callback) }, diff --git a/lib/resources/plans.js b/lib/resources/plans.js index 0f87100..f123096 100644 --- a/lib/resources/plans.js +++ b/lib/resources/plans.js @@ -5,7 +5,7 @@ */ const Promise = require("promise"), - { normalizeDate, normalizeNotes } = require('../utils/razorpay-utils'); + { normalizeDate } = require('../utils/razorpay-utils'); module.exports = function plansApi (api) { @@ -25,13 +25,10 @@ module.exports = function plansApi (api) { * @return {Promise} */ - let url = BASE_URL, - {notes, ...rest} = params, - data = Object.assign(rest, normalizeNotes(notes)); - + let url = BASE_URL; return api.post({ url, - data + data: params }, callback); }, diff --git a/lib/resources/products.js b/lib/resources/products.js index 9e5327f..6f51d78 100644 --- a/lib/resources/products.js +++ b/lib/resources/products.js @@ -1,33 +1,23 @@ 'use strict'; -const { normalizeBoolean } = require('../utils/razorpay-utils') - module.exports = function (api) { const BASE_URL = "/accounts"; return { requestProductConfiguration(accountId, params, callback) { - - let { tnc_accepted, ...rest } = params - let data = Object.assign({tnc_accepted: normalizeBoolean(tnc_accepted), ...rest}) - return api.post({ version: 'v2', url: `${BASE_URL}/${accountId}/products`, - data: data + data: params }, callback); }, edit(accountId, productId, params, callback) { - - let { tnc_accepted, ...rest } = params - let data = Object.assign({tnc_accepted: normalizeBoolean(tnc_accepted), ...rest}) - return api.patch({ version: 'v2', url: `${BASE_URL}/${accountId}/products/${productId}`, - data: data + data: params }, callback); }, diff --git a/lib/resources/qrCode.js b/lib/resources/qrCode.js index 14cf331..0524777 100644 --- a/lib/resources/qrCode.js +++ b/lib/resources/qrCode.js @@ -1,8 +1,5 @@ 'use strict' -const { normalizeBoolean } = require('../../dist/utils/razorpay-utils'); -const { normalizeNotes } = require('../utils/razorpay-utils') - module.exports = function (api) { const BASE_URL = "/payments/qr_codes"; @@ -19,17 +16,11 @@ module.exports = function (api) { * @return {Promise} */ - let url = BASE_URL, - {notes, fixed_amount, ...rest} = params; - - let data = Object.assign({ - fixed_amount: normalizeBoolean(fixed_amount), - ...rest - },normalizeNotes(notes)); + let url = BASE_URL; return api.post({ url, - data + data: params }, callback); }, all (params={}, callback) { diff --git a/lib/resources/refunds.js b/lib/resources/refunds.js index 9c8c39d..fd83c28 100644 --- a/lib/resources/refunds.js +++ b/lib/resources/refunds.js @@ -34,17 +34,13 @@ module.exports = function (api) { }, callback) }, edit(refundId, params, callback) { - let { notes } = params - if (!refundId) { throw new Error('refund Id is mandatory') } - let data = Object.assign(normalizeNotes(notes)) - return api.patch({ url: `/refunds/${refundId}`, - data + data: params }, callback) }, fetch(refundId, params = {}, callback) { diff --git a/lib/resources/settlements.js b/lib/resources/settlements.js index be47cd1..d881311 100644 --- a/lib/resources/settlements.js +++ b/lib/resources/settlements.js @@ -1,8 +1,5 @@ 'use strict' -const { normalizeBoolean } = require('../../dist/utils/razorpay-utils'); -const { normalizeNotes } = require('../utils/razorpay-utils') - module.exports = function (api) { const BASE_URL = "/settlements"; @@ -19,18 +16,11 @@ module.exports = function (api) { * @return {Promise} */ - let url = `${BASE_URL}/ondemand`, - {notes, settle_full_balance, ...rest} = params; - - - let data = Object.assign({ - settle_full_balance: normalizeBoolean(settle_full_balance), - ...rest - },normalizeNotes(notes)); + let url = `${BASE_URL}/ondemand`; return api.post({ url, - data + data: params }, callback); }, all (params={}, callback) { diff --git a/lib/resources/stakeholders.js b/lib/resources/stakeholders.js index d75649b..6b7ed5c 100644 --- a/lib/resources/stakeholders.js +++ b/lib/resources/stakeholders.js @@ -1,54 +1,23 @@ 'use strict'; -const { normalizeNotes, normalizeBoolean } = require('../utils/razorpay-utils') - module.exports = function (api) { const BASE_URL = "/accounts"; return { create(accountId, params, callback) { - - let { relationship, notes, ...rest } = params - - if(params.hasOwnProperty('relationship')){ - if(params.relationship.hasOwnProperty('executive')){ - relationship.executive = normalizeBoolean(params.relationship.executive) - } - - if(params.relationship.hasOwnProperty('director')){ - relationship.director = normalizeBoolean(params.relationship.director) - } - } - - let data = Object.assign({relationship: relationship}, normalizeNotes(notes), rest); - return api.post({ version: 'v2', url: `${BASE_URL}/${accountId}/stakeholders`, - data: data + data: params }, callback); }, edit(accountId, stakeholderId, params, callback) { - let { notes, relationship, ...rest } = params - - if(params.hasOwnProperty('relationship')){ - if(params.relationship.hasOwnProperty('executive')){ - relationship.executive = normalizeBoolean(params.relationship.executive) - } - - if(params.relationship.hasOwnProperty('director')){ - relationship.director = normalizeBoolean(params.relationship.director) - } - } - - let data = Object.assign({relationship: relationship}, normalizeNotes(notes), rest); - return api.patch({ version: 'v2', url: `${BASE_URL}/${accountId}/stakeholders/${stakeholderId}`, - data: data + data: params }, callback); }, @@ -67,7 +36,7 @@ module.exports = function (api) { }, uploadStakeholderDoc(accountId, stakeholderId, params, callback) { - return api.post({ + return api.postFormData({ version: 'v2', url: `${BASE_URL}/${accountId}/stakeholders/${stakeholderId}/documents`, formData: params diff --git a/lib/resources/subscriptions.js b/lib/resources/subscriptions.js index affbf31..8bf9410 100644 --- a/lib/resources/subscriptions.js +++ b/lib/resources/subscriptions.js @@ -5,7 +5,7 @@ */ const Promise = require("promise"), - { normalizeDate, normalizeNotes, normalizeBoolean } = require('../utils/razorpay-utils'); + { normalizeDate } = require('../utils/razorpay-utils'); module.exports = function subscriptionsApi (api) { @@ -25,13 +25,11 @@ module.exports = function subscriptionsApi (api) { * @return {Promise} */ - let url = BASE_URL, - {notes, ...rest} = params, - data = Object.assign(rest, normalizeNotes(notes)); + let url = BASE_URL; return api.post({ url, - data + data: params }, callback); }, @@ -286,8 +284,6 @@ module.exports = function subscriptionsApi (api) { }, callback); }, createRegistrationLink : function createRegistrationLink(params = {}, callback) { - let { email_notify, sms_notify, receipt, notes, ...otherParams } = params - /* * Creates a Registration Link * @@ -296,17 +292,9 @@ module.exports = function subscriptionsApi (api) { * * @return {Promise} */ - - let data = Object.assign({ - email_notify: normalizeBoolean(email_notify), - sms_notify: normalizeBoolean(sms_notify), - receipt : receipt, - ...otherParams - }, normalizeNotes(notes)) - return api.post({ url: '/subscription_registration/auth_links', - data + data: params }, callback) } }; diff --git a/lib/resources/tokens.js b/lib/resources/tokens.js index 28e939b..7f15088 100644 --- a/lib/resources/tokens.js +++ b/lib/resources/tokens.js @@ -8,12 +8,9 @@ module.exports = function (api) { return { create(params, callback) { - let { notes, ...rest } = params - let data = Object.assign(rest, normalizeNotes(notes)); - return api.post({ url: `${BASE_URL}`, - data: data + data: params }, callback); }, diff --git a/lib/resources/transfers.js b/lib/resources/transfers.js index 69c363f..b378f60 100644 --- a/lib/resources/transfers.js +++ b/lib/resources/transfers.js @@ -1,6 +1,6 @@ "use strict"; -const { normalizeDate, normalizeBoolean, normalizeNotes } = require('../utils/razorpay-utils'); +const { normalizeDate } = require('../utils/razorpay-utils'); module.exports = function (api) { return { @@ -49,30 +49,16 @@ module.exports = function (api) { }, create(params, callback) { - let { notes, ...rest } = params - let data = Object.assign(rest, normalizeNotes(notes)) - - if (data.on_hold) { - data.on_hold = normalizeBoolean(data.on_hold) - } - return api.post({ url: '/transfers', - data + data: params }, callback) }, edit(transferId, params, callback) { - let { notes, ...rest } = params - let data = Object.assign(rest, normalizeNotes(notes)) - - if (typeof data.on_hold !== "undefined") { - data.on_hold = normalizeBoolean(data.on_hold) - } - return api.patch({ url: `/transfers/${transferId}`, - data + data: params }, callback) }, @@ -81,13 +67,11 @@ module.exports = function (api) { throw new Error('`transfer_id` is mandatory') } - let { notes, ...rest } = params - let data = Object.assign(rest, normalizeNotes(notes)) - let url = `/transfers/${transferId}/reversals` + let url = `/transfers/${transferId}/reversals`; return api.post({ url, - data + data: params }, callback) }, diff --git a/lib/resources/virtualAccounts.js b/lib/resources/virtualAccounts.js index a6eb49f..9390077 100644 --- a/lib/resources/virtualAccounts.js +++ b/lib/resources/virtualAccounts.js @@ -50,12 +50,9 @@ module.exports = function (api) { }, create(params={}, callback) { - let { notes, ...rest } = params - let data = Object.assign(rest, normalizeNotes(notes)) - return api.post({ url: BASE_URL, - data + data: params }, callback) }, diff --git a/lib/types/api.d.ts b/lib/types/api.d.ts index 1a7e461..5530f2f 100644 --- a/lib/types/api.d.ts +++ b/lib/types/api.d.ts @@ -12,6 +12,9 @@ interface IPayload { url: string; data?: T; formData?: T; + qs?: T; + form?: T; + body?: T; } export type INotify = 'email' | 'sms' @@ -78,6 +81,9 @@ declare class API { patch(params: IPayload): Promise patch(params: IPayload, callback: (err: INormalizeError, data: V) => void): void + postFormData(params: IPayload): Promise + postFormData(params: IPayload, callback: (err: INormalizeError, data: V) => void): void + delete(params: IPayload): Promise delete(params: IPayload, callback: (err: INormalizeError, data: V) => void): void } diff --git a/test/mocker.js b/test/mocker.js index ed578ba..f0e26a9 100644 --- a/test/mocker.js +++ b/test/mocker.js @@ -40,7 +40,7 @@ Mocker.prototype.mock = function(params) { url, method, requestQueryParams, - requestBody: parseReqBody(requestBody, ignoreParseBody), + requestBody, headers: this.req.headers } } diff --git a/test/resources/customers.spec.js b/test/resources/customers.spec.js index 3387274..c7a9bad 100644 --- a/test/resources/customers.spec.js +++ b/test/resources/customers.spec.js @@ -23,8 +23,10 @@ describe('CUSTOMERS', () => { name: 'test', email: 'test@razorpay.com', contact: '123456789', - 'notes[note1]': 'This is note1', - 'notes[note2]': 'This is note2' + notes: { + note1: 'This is note1', + note2: 'This is note2' + } } mocker.mock({ @@ -38,7 +40,6 @@ describe('CUSTOMERS', () => { '/v1/customers', 'Create customer request url formed' ) - assert.ok( equal( response.__JUST_FOR_TESTS__.requestBody, @@ -65,7 +66,9 @@ describe('CUSTOMERS', () => { name: 'test', email: 'test@razorpay.com', contact: '123456789', - 'notes[note1]': 'This is note1' + notes: { + note1: 'This is note1' + } } mocker.mock({ diff --git a/test/resources/invoices.spec.js b/test/resources/invoices.spec.js index b1984f4..801e6c2 100644 --- a/test/resources/invoices.spec.js +++ b/test/resources/invoices.spec.js @@ -53,7 +53,7 @@ describe("INVOICES", () => { expectedParams = { param1: params.param1, param2: params.param2, - ...(normalizeNotes(params.notes)) + notes: {"something": "something else"} }, methodArgs = [params], methodName = "create", @@ -84,7 +84,7 @@ describe("INVOICES", () => { expectedParams = { param1: params.param1, param2: params.param2, - ...(normalizeNotes(params.notes)) + notes: {"something": "something else"} }, methodArgs = [TEST_INVOICE_ID, params], mockerParams = { diff --git a/test/resources/orders.spec.js b/test/resources/orders.spec.js index 78c1fda..1f242de 100644 --- a/test/resources/orders.spec.js +++ b/test/resources/orders.spec.js @@ -43,13 +43,13 @@ describe('ORDERS', () => { } mocker.mock({ - url: '/orders' + url: '/orders', }) rzpInstance.orders.all({ from: fromDate, to: toDate, - authorized: true, + authorized: 1, receipt: 'testreceiptid', count: 25, skip: 5 @@ -58,7 +58,7 @@ describe('ORDERS', () => { response.__JUST_FOR_TESTS__.requestQueryParams, expectedParams ), 'from & to dates are converted to ms & authorized to binary') - + assert.equal( response.__JUST_FOR_TESTS__.url, `/v1/orders?from=${fromDateInSecs}&to=${toDateInSecs}&count=25&skip=5&authorized=1&receipt=testreceiptid`, @@ -131,8 +131,10 @@ describe('ORDERS', () => { receipt: receipt, currency: 'INR', partial_payment: true, - 'notes[note1]': 'This is note1', - 'notes[note2]': 'This is note2' + notes: { + note1: 'This is note1', + note2: 'This is note2' + } } ), 'All params are passed in request body' diff --git a/test/resources/payments.spec.js b/test/resources/payments.spec.js index ebbb4c1..9bf2fb6 100644 --- a/test/resources/payments.spec.js +++ b/test/resources/payments.spec.js @@ -236,8 +236,10 @@ describe('PAYMENTS', () => { response.__JUST_FOR_TESTS__.requestBody, { amount: refundAmount, - 'notes[note1]': 'This is note1', - 'notes[note2]': 'This is note2' + notes: { + note1: 'This is note1', + note2: 'This is note2' + } } ), 'Amount & notes are passed in request body' @@ -287,12 +289,18 @@ describe('PAYMENTS', () => { equal( response.__JUST_FOR_TESTS__.requestBody, { - 'transfers[0][account]': 'acc_7jO4N6LScw5CEG', - 'transfers[0][amount]': 100, - 'transfers[0][currency]': 'INR', - 'transfers[0][on_hold]': 1, - 'notes[note1]': 'This is note1', - 'notes[note2]': 'This is note2' + transfers: [ + { + account: 'acc_7jO4N6LScw5CEG', + amount: 100, + currency: 'INR', + on_hold: true + } + ], + notes: { + note1: 'This is note1', + note2: 'This is note2' + } } ), 'Correct params are passed in request body' diff --git a/test/resources/plans.spec.js b/test/resources/plans.spec.js index 3fa9a0b..abe00fd 100644 --- a/test/resources/plans.spec.js +++ b/test/resources/plans.spec.js @@ -52,7 +52,7 @@ describe("PLANS", () => { expectedParams = { param1: params.param1, param2: params.param2, - ...(normalizeNotes(params.notes)) + notes:{"something": "something else"} }, methodArgs = [params], methodName = "create", diff --git a/test/resources/subscriptions.spec.js b/test/resources/subscriptions.spec.js index 3c2529c..a39bbd0 100644 --- a/test/resources/subscriptions.spec.js +++ b/test/resources/subscriptions.spec.js @@ -53,7 +53,7 @@ describe("SUBSCRIPTIONS", () => { expectedParams = { param1: params.param1, param2: params.param2, - ...(normalizeNotes(params.notes)) + notes: {"something": "something else"} }, methodArgs = [params], methodName = "create", @@ -482,7 +482,7 @@ describe("SUBSCRIPTIONS", () => { expectedParams = { param1: params.param1, param2: params.param2, - ...(normalizeNotes(params.notes)) + notes: {"something": "something else"} }, methodArgs = [params], methodName = "createRegistrationLink", diff --git a/test/resources/transfers.spec.js b/test/resources/transfers.spec.js index 405d200..f186f22 100644 --- a/test/resources/transfers.spec.js +++ b/test/resources/transfers.spec.js @@ -23,8 +23,10 @@ describe('TRANSFERS', () => { account: 'acc_7jO4N6LScw5CEG', amount: 100, currency: 'INR', - 'notes[note1]': 'This is note1', - 'notes[note2]': 'This is note2' + notes: { + note1: 'This is note1', + note2: 'This is note2' + } } mocker.mock({ @@ -59,8 +61,10 @@ describe('TRANSFERS', () => { } let expectedParams = { - 'notes[note1]': 'This is note1', - 'notes[note2]': 'This is note2' + notes: { + note1: 'This is note1', + note2: 'This is note2' + } } mocker.mock({ @@ -96,7 +100,9 @@ describe('TRANSFERS', () => { let expectedParams = { on_hold: 1, - 'notes[note1]': 'This is note1' + notes: { + note1: 'This is note1' + } } mocker.mock({ @@ -135,7 +141,9 @@ describe('TRANSFERS', () => { let expectedParams = { amount: 100, currency: 'INR', - 'notes[note1]': 'This is note1' + notes: { + note1: 'This is note1' + } } mocker.mock({ diff --git a/test/resources/virtualAccounts.spec.js b/test/resources/virtualAccounts.spec.js index f1f0323..e3fa0fc 100644 --- a/test/resources/virtualAccounts.spec.js +++ b/test/resources/virtualAccounts.spec.js @@ -143,12 +143,10 @@ describe("VIRTUAL_ACCOUNTS", () => { it ("Create Virtual Account", (done) => { const params = { - notes : {"comment": "My notes"}, param1: "param1", param2: "param2" - }, {notes, ...rest} = params; - + }; mocker.mock({ url : `${SUB_PATH}`, method: "POST" @@ -157,8 +155,7 @@ describe("VIRTUAL_ACCOUNTS", () => { rzpInstance.virtualAccounts.create(params).then((response) => { assert.ok(equal( - response.__JUST_FOR_TESTS__.requestBody, - Object.assign(rest, normalizeNotes(notes))), + response.__JUST_FOR_TESTS__.requestBody,params), "Params matched, and notes normalized" ); From 753c07b6f2bea6c784c9866ad39fe761d93ed9ad Mon Sep 17 00:00:00 2001 From: Ankit Das <89454448+ankitdas13@users.noreply.github.com> Date: Wed, 16 Aug 2023 18:37:07 +0530 Subject: [PATCH 3/3] Changelog encodetype (#374) --- CHANGELOG.md | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cad697..60888eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 2.9.2 - 2023-08-16 +chore: Changed Content-Type of all APIs from application/x-www-form-urlencoded to application/json + ## 2.9.1 - 2023-07-18 fix: A bug in the “Create Payment Link” request has been fixed. diff --git a/package.json b/package.json index 26bd7a5..87f63ee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "razorpay", - "version": "2.9.1", + "version": "2.9.2", "description": "Official Node SDK for Razorpay API", "main": "dist/razorpay", "typings": "dist/razorpay",