-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from razorpay/item_sdk
Node-sdk Item
- Loading branch information
Showing
7 changed files
with
515 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
'use strict'; | ||
|
||
var _require = require('../utils/razorpay-utils'), | ||
normalizeDate = _require.normalizeDate, | ||
normalizeBoolean = _require.normalizeBoolean; | ||
|
||
module.exports = function (api) { | ||
return { | ||
all: function all() { | ||
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var callback = arguments[1]; | ||
var from = params.from, | ||
to = params.to, | ||
count = params.count, | ||
skip = params.skip, | ||
authorized = params.authorized, | ||
receipt = params.receipt; | ||
|
||
|
||
if (from) { | ||
from = normalizeDate(from); | ||
} | ||
|
||
if (to) { | ||
to = normalizeDate(to); | ||
} | ||
|
||
count = Number(count) || 10; | ||
skip = Number(skip) || 0; | ||
authorized = normalizeBoolean(authorized); | ||
|
||
return api.get({ | ||
url: '/items', | ||
data: { | ||
from: from, | ||
to: to, | ||
count: count, | ||
skip: skip, | ||
authorized: authorized, | ||
receipt: receipt | ||
} | ||
}, callback); | ||
}, | ||
fetch: function fetch(itemId, callback) { | ||
if (!itemId) { | ||
throw new Error('`item_id` is mandatory'); | ||
} | ||
|
||
return api.get({ | ||
url: '/items/' + itemId | ||
}, callback); | ||
}, | ||
create: function create() { | ||
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var callback = arguments[1]; | ||
var amount = params.amount, | ||
currency = params.currency, | ||
description = params.description; | ||
|
||
currency = currency || 'INR'; | ||
|
||
if (!amount) { | ||
throw new Error('`amount` is mandatory'); | ||
} | ||
|
||
var data = Object.assign({ | ||
amount: amount, | ||
currency: currency, | ||
description: description | ||
}); | ||
|
||
return api.post({ | ||
url: '/items', | ||
data: data | ||
}, callback); | ||
}, | ||
edit: function edit(itemId) { | ||
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var callback = arguments[2]; | ||
|
||
|
||
if (!itemId) { | ||
throw new Error('`item_id` is mandatory'); | ||
} | ||
|
||
return api.patch({ | ||
url: '/items/' + itemId, | ||
data: params | ||
}, callback); | ||
}, | ||
|
||
|
||
delete: function _delete(itemId, callback) { | ||
|
||
if (!itemId) { | ||
throw new Error('`item_id` is mandatory'); | ||
} | ||
|
||
return api.delete({ | ||
url: '/items/' + itemId | ||
}, callback); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
## items | ||
|
||
### Create item | ||
|
||
```js | ||
instance.Items.create({ | ||
"name": "Book / English August", | ||
"description": "An indian story, Booker prize winner.", | ||
"amount": 20000, | ||
"currency": "INR" | ||
}); | ||
``` | ||
|
||
**Parameters:** | ||
|
||
| Name | Type | Description | | ||
|-----------------|---------|------------------------------------------------------------------------------| | ||
| name* | string | Name of the item. | | ||
| description | string | A brief description of the item. | | ||
| amount | integer | Amount of the order to be paid | | ||
| currency | string | Currency of the order. Currently only `INR` is supported. | | ||
|
||
**Response:** | ||
```json | ||
{ | ||
"id": "item_7Oxp4hmm6T4SCn", | ||
"active": true, | ||
"name": "Book / English August", | ||
"description": "An indian story, Booker prize winner.", | ||
"amount": 20000, | ||
"currency": "INR" | ||
} | ||
``` | ||
|
||
------------------------------------------------------------------------------------------------------- | ||
|
||
### Fetch all items | ||
|
||
```js | ||
instance.Items.all(options) | ||
``` | ||
**Parameters:** | ||
|
||
| Name | Type | Description | | ||
|-------|-----------|--------------------------------------------------| | ||
| from | timestamp | timestamp after which the item were created | | ||
| to | timestamp | timestamp before which the item were created | | ||
| count | integer | number of item to fetch (default: 10) | | ||
| skip | integer | number of item to be skipped (default: 0) | | ||
| name | string | Name of the item. | | ||
| description | string | A brief description of the item. | | ||
| amount | integer | Amount of the order to be paid | | ||
| currency | string | Currency of the order. Currently only `INR` is supported. | | ||
| active | boolean | Possible values is `0` or `1` | | ||
|
||
**Response:** | ||
```json | ||
{ | ||
"entity": "collection", | ||
"count": 3, | ||
"items": [ | ||
{ | ||
"id": "item_7Oy8OMV6BdEAac", | ||
"active": true, | ||
"name": "Book / Ignited Minds", | ||
"description": null, | ||
"amount": 15000, | ||
"currency": "INR" | ||
}, | ||
{ | ||
"id": "item_7Oxp4hmm6T4SCn", | ||
"active": true, | ||
"name": "Book / English August", | ||
"description": "An indian story, Booker prize winner.", | ||
"amount": 20000, | ||
"currency": "INR" | ||
}, | ||
{ | ||
"id": "item_7OxoGnoxCuUKbo", | ||
"active": true, | ||
"name": "Book / English August", | ||
"description": null, | ||
"amount": 20000, | ||
"currency": "INR" | ||
} | ||
] | ||
} | ||
``` | ||
------------------------------------------------------------------------------------------------------- | ||
### Fetch particular item | ||
|
||
```js | ||
instance.Items.fetch(itemId) | ||
``` | ||
**Parameters** | ||
|
||
| Name | Type | Description | | ||
|----------|--------|-------------------------------------| | ||
| itemId* | string | The id of the item to be fetched | | ||
|
||
**Response:** | ||
```json | ||
{ | ||
"id": "item_7Oxp4hmm6T4SCn", | ||
"active": true, | ||
"name": "Book / English August", | ||
"description": "An indian story, Booker prize winner.", | ||
"amount": 20000, | ||
"currency": "INR" | ||
} | ||
``` | ||
|
||
------------------------------------------------------------------------------------------------------- | ||
|
||
### Update item | ||
|
||
```js | ||
instance.Items.edit({ | ||
"name": "Book / Ignited Minds - Updated name!", | ||
"description": "New descirption too. :).", | ||
"amount": 20000, | ||
"currency": "INR", | ||
"active": true | ||
}) | ||
``` | ||
**Parameters** | ||
|
||
| Name | Type | Description | | ||
|----------|--------|-------------------------------------| | ||
| itemId* | string | The id of the item to be fetched | | ||
| name | string | Name of the item. | | ||
| description | string | A brief description of the item. | | ||
| amount | integer | Amount of the order to be paid | | ||
| currency | string | Currency of the order. Currently only `INR` is supported. | | ||
| active | boolean | Possible values is `0` or `1` | | ||
|
||
**Response:** | ||
```json | ||
{ | ||
"id": "item_7Oy8OMV6BdEAac", | ||
"active": true, | ||
"name": "Book / Ignited Minds - Updated name!", | ||
"description": "New descirption too. :)", | ||
"amount": 15000, | ||
"currency": "INR" | ||
} | ||
``` | ||
------------------------------------------------------------------------------------------------------- | ||
### Delete item | ||
|
||
```js | ||
instance.Items.delete(itemId) | ||
``` | ||
**Parameters** | ||
|
||
| Name | Type | Description | | ||
|----------|--------|-------------------------------------| | ||
| itemId* | string | The id of the item to be fetched | | ||
|
||
**Response:** | ||
```json | ||
[] | ||
``` | ||
------------------------------------------------------------------------------------------------------- | ||
|
||
**PN: * indicates mandatory fields** | ||
<br> | ||
<br> | ||
**For reference click [here](https://razorpay.com/docs/api/items)** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
'use strict' | ||
|
||
const { normalizeDate, normalizeBoolean } = require('../utils/razorpay-utils') | ||
|
||
module.exports = function (api) { | ||
return { | ||
all(params = {}, callback) { | ||
let { from, to, count, skip, authorized, receipt } = params | ||
|
||
if (from) { | ||
from = normalizeDate(from) | ||
} | ||
|
||
if (to) { | ||
to = normalizeDate(to) | ||
} | ||
|
||
count = Number(count) || 10 | ||
skip = Number(skip) || 0 | ||
authorized = normalizeBoolean(authorized) | ||
|
||
return api.get({ | ||
url: '/items', | ||
data: { | ||
from, | ||
to, | ||
count, | ||
skip, | ||
authorized, | ||
receipt | ||
} | ||
}, callback) | ||
}, | ||
|
||
fetch(itemId, callback) { | ||
if (!itemId) { | ||
throw new Error('`item_id` is mandatory') | ||
} | ||
|
||
return api.get({ | ||
url: `/items/${itemId}` | ||
}, callback) | ||
}, | ||
|
||
create(params = {}, callback) { | ||
let { amount, currency, description } = params | ||
currency = currency || 'INR' | ||
|
||
if (!amount) { | ||
throw new Error('`amount` is mandatory') | ||
} | ||
|
||
let data = Object.assign({ | ||
amount, | ||
currency, | ||
description | ||
}) | ||
|
||
return api.post({ | ||
url: '/items', | ||
data | ||
}, callback) | ||
}, | ||
|
||
edit(itemId, params = {}, callback) { | ||
|
||
if (!itemId) { | ||
throw new Error('`item_id` is mandatory') | ||
} | ||
|
||
return api.patch({ | ||
url: `/items/${itemId}`, | ||
data : params | ||
}, callback) | ||
}, | ||
|
||
delete: function _delete(itemId, callback) { | ||
|
||
if (!itemId) { | ||
throw new Error('`item_id` is mandatory'); | ||
} | ||
|
||
return api.delete({ | ||
url: '/items/' + itemId | ||
}, callback); | ||
} | ||
} | ||
} |
Oops, something went wrong.