Skip to content

Commit

Permalink
Virtual accounts with test cases (#13)
Browse files Browse the repository at this point in the history
* added virtual accounts api

* Virtual Accounts unit tests

* Added promise polyfill

* Updated readme and wiki

* Bumped the version to 1.4.0
  • Loading branch information
rzpamidi authored and pronav committed Aug 18, 2017
1 parent 0b0b009 commit 7aa567f
Show file tree
Hide file tree
Showing 12 changed files with 3,743 additions and 36 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ instance.payments.all({

- [Transfers](https://github.com/razorpay/razorpay-node/wiki#transfers)

- [Virtual Accounts](https://github.com/razorpay/razorpay-node/wiki#virtual-accounts)
---


Expand Down
11 changes: 6 additions & 5 deletions lib/razorpay.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ class Razorpay {

addResources() {
Object.assign(this, {
payments: require('./resources/payments')(this.api),
refunds: require('./resources/refunds')(this.api),
orders: require('./resources/orders')(this.api),
customers: require('./resources/customers')(this.api),
transfers: require('./resources/transfers')(this.api)
payments : require('./resources/payments')(this.api),
refunds : require('./resources/refunds')(this.api),
orders : require('./resources/orders')(this.api),
customers : require('./resources/customers')(this.api),
transfers : require('./resources/transfers')(this.api),
virtualAccounts: require('./resources/virtualAccounts')(this.api),
})
}
}
Expand Down
75 changes: 75 additions & 0 deletions lib/resources/virtualAccounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"use strict";

const Promise = require("promise");
const { normalizeDate, normalizeNotes } = require('../utils/razorpay-utils');

module.exports = function (api) {
return {
all(params = {}, callback) {
let { from, to, count, skip } = params
let url = '/virtual_accounts'

if (from) {
from = normalizeDate(from)
}

if (to) {
to = normalizeDate(to)
}

count = Number(count) || 10
skip = Number(skip) || 0

return api.get({
url,
data: {
from,
to,
count,
skip
}
}, callback)
},

fetch(virtualAccountId, callback) {

if (!virtualAccountId) {

return Promise.reject('`virtual_account_id` is mandatory');
}

let url = `/virtual_accounts/${virtualAccountId}`

return api.get({
url
}, callback)
},

create(params, callback) {
let { notes, ...rest } = params
let data = Object.assign(rest, normalizeNotes(notes))

return api.post({
url: '/virtual_accounts',
data
}, callback)
},

close(virtualAccountId, callback) {

if (!virtualAccountId) {

return Promise.reject('`virtual_account_id` is mandatory');
}

let data = {
status: 'closed'
}

return api.patch({
url: `/virtual_accounts/${virtualAccountId}`,
data
}, callback)
},
}
}
Loading

0 comments on commit 7aa567f

Please sign in to comment.