From 09a8452f81cc8fa7166b9b75efdfbd76d9fb31ec Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Thu, 21 Oct 2021 16:38:12 +0530 Subject: [PATCH] order module update --- dist/resources/orders.js | 17 +++++++++++++++++ lib/resources/orders.js | 15 +++++++++++++++ test/resources/orders.spec.js | 27 +++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/dist/resources/orders.js b/dist/resources/orders.js index 2a02c0f0..8b41364f 100644 --- a/dist/resources/orders.js +++ b/dist/resources/orders.js @@ -86,6 +86,23 @@ module.exports = function (api) { data: data }, callback); }, + edit: function edit(orderId) { + var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var callback = arguments[2]; + var notes = params.notes; + + + if (!orderId) { + throw new Error('`order_id` is mandatory'); + } + + var data = Object.assign(normalizeNotes(notes)); + + return api.patch({ + url: '/orders/' + orderId, + data: data + }, callback); + }, fetchPayments: function fetchPayments(orderId, callback) { if (!orderId) { throw new Error('`order_id` is mandatory'); diff --git a/lib/resources/orders.js b/lib/resources/orders.js index 4fa7bb10..ad9030a6 100644 --- a/lib/resources/orders.js +++ b/lib/resources/orders.js @@ -65,6 +65,21 @@ module.exports = function (api) { data }, callback) }, + + 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 + }, callback) + }, fetchPayments(orderId, callback) { if (!orderId) { diff --git a/test/resources/orders.spec.js b/test/resources/orders.spec.js index ac8f6d02..b88bf72d 100644 --- a/test/resources/orders.spec.js +++ b/test/resources/orders.spec.js @@ -188,4 +188,31 @@ describe('ORDERS', () => { }) }) }) + + describe('edit order', () => { + it('edit order', (done) => { + let orderId = 'order_sometestId' + + let params = { + notes: { + note1: 'This is note1', + note2: 'This is note2' + } + } + + mocker.mock({ + url: `/orders/${orderId}`, + method : 'PATCH' + }) + + rzpInstance.orders.edit(orderId, params).then((response) => { + assert.equal( + response.__JUST_FOR_TESTS__.url, + `/v1/orders/${orderId}`, + 'Request url formed correctly' + ) + done() + }) + }) + }) })