Skip to content

Commit

Permalink
Merge branch 'master' of github.com:razorpay/razorpay-node
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitdas13 committed Dec 20, 2023
2 parents 6e34066 + 753c07b commit dc9f386
Show file tree
Hide file tree
Showing 32 changed files with 124 additions and 284 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 2.9.2 - 2023-08-16
chore: Changed Content-Type of all APIs from application/x-www-form-urlencoded to application/json

## 2.9.1 - 2023-07-18

fix: A bug in the “Create Payment Link” request has been fixed.
Expand Down
2 changes: 1 addition & 1 deletion documents/payment.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ instance.orders.fetchPayments(orderId)
"wallet": null,
"vpa": null,
"email": "[email protected]",
"contact": "9364591752",
"contact": "+919999999999",
"fee": 70,
"tax": 10,
"error_code": null,
Expand Down
28 changes: 9 additions & 19 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,42 +70,32 @@ class API {
post(params, cb) {
let request = {
url: this.getEntityUrl(params),
form: params.data
body: params.data
};

if (params.hasOwnProperty('formData')) {
delete request['form'];
request.formData = params.formData;
}
return nodeify(this.rq.post(request).catch(normalizeError), cb);
}

postBody(params, cb) {
// postFormData method for file uploads.
postFormData(params, cb){
let request = {
url: this.getEntityUrl(params),
body: params.data
};
return nodeify(this.rq.post(request).catch(normalizeError), cb);
url: this.getEntityUrl(params),
formData: params.formData
};
return nodeify(this.rq.post(request).catch(normalizeError), cb);
}

put(params, cb) {
return nodeify(this.rq.put({
url: this.getEntityUrl(params),
form: params.data
body: params.data
}).catch(normalizeError), cb)
}

patch(params, cb) {
let request = {
url: this.getEntityUrl(params),
form: params.data
body: params.data
};

if(params.data.hasOwnProperty("isbody")) {
delete request['form'];
delete params.data.isbody;
request.body = params.data;
}
return nodeify(this.rq.patch(request).catch(normalizeError), cb);
}

Expand Down
14 changes: 3 additions & 11 deletions lib/resources/accounts.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
'use strict';

const { normalizeNotes } = require('../utils/razorpay-utils')

module.exports = function (api) {

const BASE_URL = "/accounts";

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

return api.post({
version: 'v2',
url: `${BASE_URL}`,
data: data
data: params
}, callback);
},

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

return api.patch({
version: 'v2',
url: `${BASE_URL}/${accountId}`,
data: data
data: params
}, callback);
},

Expand All @@ -44,7 +36,7 @@ module.exports = function (api) {
},

uploadAccountDoc(accountId, params, callback) {
return api.post({
return api.postFormData({
version: 'v2',
url: `${BASE_URL}/${accountId}/documents`,
formData: params
Expand Down
12 changes: 2 additions & 10 deletions lib/resources/customers.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
'use strict'

const { normalizeNotes, normalizeBoolean } = require('../utils/razorpay-utils')

module.exports = function (api) {
return {
create(params, callback) {
let { notes, ...rest } = params
let data = Object.assign(rest, normalizeNotes(notes))

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

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

return api.put({
url: `/customers/${customerId}`,
data
data: params
}, callback)
},

Expand Down
2 changes: 0 additions & 2 deletions lib/resources/fundAccount.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

const { normalizeNotes } = require('../utils/razorpay-utils')

module.exports = function (api) {
return {
create(params, callback) {
Expand Down
18 changes: 5 additions & 13 deletions lib/resources/invoices.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

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

module.exports = function invoicesApi (api) {

Expand All @@ -32,16 +32,10 @@ module.exports = function invoicesApi (api) {
* @return {Promise}
*/

let url = BASE_URL,
{ notes, partial_payment, ...rest } = params

let data = Object.assign({
partial_payment: normalizeBoolean(partial_payment),
...rest
}, normalizeNotes(notes))
let url = BASE_URL;
return api.post({
url,
data
data: params
}, callback)
},

Expand All @@ -57,9 +51,7 @@ module.exports = function invoicesApi (api) {
* @return {Promise}
*/

let url = `${BASE_URL}/${invoiceId}`,
{ notes, ...rest } = params,
data = Object.assign(rest, normalizeNotes(notes));
let url = `${BASE_URL}/${invoiceId}`;

if (!invoiceId) {

Expand All @@ -68,7 +60,7 @@ module.exports = function invoicesApi (api) {

return api.patch({
url,
data
data: params
}, callback);
},

Expand Down
26 changes: 6 additions & 20 deletions lib/resources/items.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { normalizeDate, normalizeBoolean } = require('../utils/razorpay-utils')
const { normalizeDate } = require('../utils/razorpay-utils')

module.exports = function (api) {
return {
Expand All @@ -17,7 +17,6 @@ module.exports = function (api) {

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

return api.get({
url: '/items',
Expand All @@ -43,24 +42,18 @@ module.exports = function (api) {
},

create(params = {}, callback) {
var name = params.name;
var amount = params.amount;
var currency = params.currency;
var description = params.description;

let { amount, currency , ...rest } = params
currency = currency || 'INR'

if (!amount) {
throw new Error('`amount` is mandatory')
}

let data = Object.assign({
name,
amount,
currency,
description
amount,
...rest
})

return api.post({
url: '/items',
data
Expand All @@ -73,17 +66,10 @@ module.exports = function (api) {
throw new Error('`item_id` is mandatory')
}

let url = `/items/${itemId}`,
{ active, ...rest } = params

let data = Object.assign({
active: normalizeBoolean(active),
...rest
})

let url = `/items/${itemId}`;
return api.patch({
url,
data
data: params
}, callback)
},

Expand Down
19 changes: 5 additions & 14 deletions lib/resources/orders.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { normalizeDate, normalizeBoolean, normalizeNotes } = require('../utils/razorpay-utils')
const { normalizeDate } = require('../utils/razorpay-utils')

module.exports = function (api) {
return {
Expand All @@ -22,7 +22,7 @@ module.exports = function (api) {

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

return api.get({
url: '/orders',
Expand All @@ -49,19 +49,13 @@ module.exports = function (api) {
},

create(params = {}, callback) {
let { amount, currency, receipt, partial_payment,payment_capture, notes, method,
...otherParams } = params
let { currency, ...otherParams } = params
currency = currency || 'INR'

let data = Object.assign({
amount,
currency,
receipt,
method,
partial_payment: normalizeBoolean(partial_payment),
payment_capture: normalizeBoolean(payment_capture),
...otherParams
}, normalizeNotes(notes))
})

return api.post({
url: '/orders',
Expand All @@ -70,17 +64,14 @@ module.exports = function (api) {
},

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
data: params
}, callback)
},

Expand Down
9 changes: 2 additions & 7 deletions lib/resources/paymentLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function paymentLinkApi (api) {
*/

let url = BASE_URL;
return api.postBody({
return api.post({
url,
data: params
}, callback)
Expand Down Expand Up @@ -115,14 +115,9 @@ module.exports = function paymentLinkApi (api) {
},

edit(paymentLinkId, params, callback) {
let rest = params;
var isbody = true

var data = {isbody, ...rest};

return api.patch({
url: `${BASE_URL}/${paymentLinkId}`,
data
data: params
}, callback)
},

Expand Down
Loading

0 comments on commit dc9f386

Please sign in to comment.