From 55b038576e077d3a99fedea82110c7ffb9ecbcb6 Mon Sep 17 00:00:00 2001 From: geekguy Date: Mon, 15 Jul 2019 23:23:27 +0530 Subject: [PATCH] add support for 0 amount emandate order --- dist/resources/orders.js | 6 ++++-- lib/resources/orders.js | 5 +++-- test/resources/orders.spec.js | 12 ++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/dist/resources/orders.js b/dist/resources/orders.js index 9bf5b24f..daa4670d 100644 --- a/dist/resources/orders.js +++ b/dist/resources/orders.js @@ -64,11 +64,12 @@ module.exports = function (api) { receipt = params.receipt, payment_capture = params.payment_capture, notes = params.notes, - otherParams = _objectWithoutProperties(params, ['amount', 'currency', 'receipt', 'payment_capture', 'notes']); + method = params.method, + otherParams = _objectWithoutProperties(params, ['amount', 'currency', 'receipt', 'payment_capture', 'notes', 'method']); currency = currency || 'INR'; - if (!amount) { + if (!(amount || method === 'emandate' && amount === 0)) { throw new Error('`amount` is mandatory'); } @@ -80,6 +81,7 @@ module.exports = function (api) { amount: amount, currency: currency, receipt: receipt, + method: method, payment_capture: normalizeBoolean(payment_capture) }, otherParams), normalizeNotes(notes)); diff --git a/lib/resources/orders.js b/lib/resources/orders.js index 8e2bc155..30afc140 100644 --- a/lib/resources/orders.js +++ b/lib/resources/orders.js @@ -43,11 +43,11 @@ module.exports = function (api) { }, create(params = {}, callback) { - let { amount, currency, receipt, payment_capture, notes, + let { amount, currency, receipt, payment_capture, notes, method, ...otherParams } = params currency = currency || 'INR' - if (!amount) { + if (!(amount || (method === 'emandate' && amount === 0))) { throw new Error('`amount` is mandatory') } @@ -59,6 +59,7 @@ module.exports = function (api) { amount, currency, receipt, + method, payment_capture: normalizeBoolean(payment_capture), ...otherParams }, normalizeNotes(notes)) diff --git a/test/resources/orders.spec.js b/test/resources/orders.spec.js index 021f83d5..1c66542c 100644 --- a/test/resources/orders.spec.js +++ b/test/resources/orders.spec.js @@ -104,6 +104,18 @@ describe('ORDERS', () => { 'Should throw exception when amount is not provided' ) + try { + rzpInstance.orders.create({ + method: 'emandate', + }) + } catch (e) { + assert.equal( + e.message, + '`amount` is mandatory', + 'Should throw exception when amount is not provided with emandate method' + ) + } + try { rzpInstance.orders.create({ amount: 100