Skip to content

Commit

Permalink
add support for 0 amount - emandate order (#91)
Browse files Browse the repository at this point in the history
add support for 0 amount - emandate order

Co-authored-by: Umang Galaiya <[email protected]>
  • Loading branch information
Umang Galaiya authored Aug 12, 2019
2 parents e0ad3b9 + ac7313f commit fbd34a4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
6 changes: 4 additions & 2 deletions dist/resources/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand All @@ -80,6 +81,7 @@ module.exports = function (api) {
amount: amount,
currency: currency,
receipt: receipt,
method: method,
payment_capture: normalizeBoolean(payment_capture)
}, otherParams), normalizeNotes(notes));

Expand Down
5 changes: 3 additions & 2 deletions lib/resources/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}

Expand All @@ -59,6 +59,7 @@ module.exports = function (api) {
amount,
currency,
receipt,
method,
payment_capture: normalizeBoolean(payment_capture),
...otherParams
}, normalizeNotes(notes))
Expand Down
12 changes: 12 additions & 0 deletions test/resources/orders.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fbd34a4

Please sign in to comment.