Skip to content

Commit 6672b52

Browse files
authored
fix : Encoded type to body (#369)
1 parent 85e2fc7 commit 6672b52

29 files changed

+119
-282
lines changed

lib/api.js

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,42 +70,32 @@ class API {
7070
post(params, cb) {
7171
let request = {
7272
url: this.getEntityUrl(params),
73-
form: params.data
73+
body: params.data
7474
};
75-
76-
if (params.hasOwnProperty('formData')) {
77-
delete request['form'];
78-
request.formData = params.formData;
79-
}
8075
return nodeify(this.rq.post(request).catch(normalizeError), cb);
8176
}
8277

83-
postBody(params, cb) {
78+
// postFormData method for file uploads.
79+
postFormData(params, cb){
8480
let request = {
85-
url: this.getEntityUrl(params),
86-
body: params.data
87-
};
88-
return nodeify(this.rq.post(request).catch(normalizeError), cb);
81+
url: this.getEntityUrl(params),
82+
formData: params.formData
83+
};
84+
return nodeify(this.rq.post(request).catch(normalizeError), cb);
8985
}
9086

9187
put(params, cb) {
9288
return nodeify(this.rq.put({
9389
url: this.getEntityUrl(params),
94-
form: params.data
90+
body: params.data
9591
}).catch(normalizeError), cb)
9692
}
9793

9894
patch(params, cb) {
9995
let request = {
10096
url: this.getEntityUrl(params),
101-
form: params.data
97+
body: params.data
10298
};
103-
104-
if(params.data.hasOwnProperty("isbody")) {
105-
delete request['form'];
106-
delete params.data.isbody;
107-
request.body = params.data;
108-
}
10999
return nodeify(this.rq.patch(request).catch(normalizeError), cb);
110100
}
111101

lib/resources/accounts.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
11
'use strict';
22

3-
const { normalizeNotes } = require('../utils/razorpay-utils')
4-
53
module.exports = function (api) {
64

75
const BASE_URL = "/accounts";
86

97
return {
108
create(params, callback) {
11-
let { notes, ...rest } = params
12-
let data = Object.assign(rest, normalizeNotes(notes));
13-
149
return api.post({
1510
version: 'v2',
1611
url: `${BASE_URL}`,
17-
data: data
12+
data: params
1813
}, callback);
1914
},
2015

2116
edit(accountId, params, callback) {
22-
let { notes, ...rest } = params
23-
let data = Object.assign(rest, normalizeNotes(notes));
24-
2517
return api.patch({
2618
version: 'v2',
2719
url: `${BASE_URL}/${accountId}`,
28-
data: data
20+
data: params
2921
}, callback);
3022
},
3123

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

4638
uploadAccountDoc(accountId, params, callback) {
47-
return api.post({
39+
return api.postFormData({
4840
version: 'v2',
4941
url: `${BASE_URL}/${accountId}/documents`,
5042
formData: params

lib/resources/customers.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
11
'use strict'
22

3-
const { normalizeNotes, normalizeBoolean } = require('../utils/razorpay-utils')
4-
53
module.exports = function (api) {
64
return {
75
create(params, callback) {
8-
let { notes, ...rest } = params
9-
let data = Object.assign(rest, normalizeNotes(notes))
10-
116
return api.post({
127
url: '/customers',
13-
data
8+
data: params
149
}, callback)
1510
},
1611

1712
edit(customerId, params, callback) {
18-
let { notes, ...rest } = params
19-
let data = Object.assign(rest, normalizeNotes(notes))
20-
2113
return api.put({
2214
url: `/customers/${customerId}`,
23-
data
15+
data: params
2416
}, callback)
2517
},
2618

lib/resources/fundAccount.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict'
22

3-
const { normalizeNotes } = require('../utils/razorpay-utils')
4-
53
module.exports = function (api) {
64
return {
75
create(params, callback) {

lib/resources/invoices.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

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

1010
module.exports = function invoicesApi (api) {
1111

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

35-
let url = BASE_URL,
36-
{ notes, partial_payment, ...rest } = params
37-
38-
let data = Object.assign({
39-
partial_payment: normalizeBoolean(partial_payment),
40-
...rest
41-
}, normalizeNotes(notes))
35+
let url = BASE_URL;
4236
return api.post({
4337
url,
44-
data
38+
data: params
4539
}, callback)
4640
},
4741

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

60-
let url = `${BASE_URL}/${invoiceId}`,
61-
{ notes, ...rest } = params,
62-
data = Object.assign(rest, normalizeNotes(notes));
54+
let url = `${BASE_URL}/${invoiceId}`;
6355

6456
if (!invoiceId) {
6557

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

6961
return api.patch({
7062
url,
71-
data
63+
data: params
7264
}, callback);
7365
},
7466

lib/resources/items.js

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

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

55
module.exports = function (api) {
66
return {
@@ -17,7 +17,6 @@ module.exports = function (api) {
1717

1818
count = Number(count) || 10
1919
skip = Number(skip) || 0
20-
authorized = normalizeBoolean(authorized)
2120

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

4544
create(params = {}, callback) {
46-
var name = params.name;
47-
var amount = params.amount;
48-
var currency = params.currency;
49-
var description = params.description;
50-
45+
let { amount, currency , ...rest } = params
5146
currency = currency || 'INR'
5247

5348
if (!amount) {
5449
throw new Error('`amount` is mandatory')
5550
}
5651

5752
let data = Object.assign({
58-
name,
59-
amount,
6053
currency,
61-
description
54+
amount,
55+
...rest
6256
})
63-
6457
return api.post({
6558
url: '/items',
6659
data
@@ -73,17 +66,10 @@ module.exports = function (api) {
7366
throw new Error('`item_id` is mandatory')
7467
}
7568

76-
let url = `/items/${itemId}`,
77-
{ active, ...rest } = params
78-
79-
let data = Object.assign({
80-
active: normalizeBoolean(active),
81-
...rest
82-
})
83-
69+
let url = `/items/${itemId}`;
8470
return api.patch({
8571
url,
86-
data
72+
data: params
8773
}, callback)
8874
},
8975

lib/resources/orders.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

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

55
module.exports = function (api) {
66
return {
@@ -22,7 +22,7 @@ module.exports = function (api) {
2222

2323
count = Number(count) || 10
2424
skip = Number(skip) || 0
25-
authorized = normalizeBoolean(authorized)
25+
authorized = authorized
2626

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

5151
create(params = {}, callback) {
52-
let { amount, currency, receipt, partial_payment,payment_capture, notes, method,
53-
...otherParams } = params
52+
let { currency, ...otherParams } = params
5453
currency = currency || 'INR'
5554

5655
let data = Object.assign({
57-
amount,
5856
currency,
59-
receipt,
60-
method,
61-
partial_payment: normalizeBoolean(partial_payment),
62-
payment_capture: normalizeBoolean(payment_capture),
6357
...otherParams
64-
}, normalizeNotes(notes))
58+
})
6559

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

7266
edit(orderId, params = {}, callback) {
73-
let { notes } = params
7467

7568
if (!orderId) {
7669
throw new Error('`order_id` is mandatory')
7770
}
7871

79-
let data = Object.assign(normalizeNotes(notes))
80-
8172
return api.patch({
8273
url: `/orders/${orderId}`,
83-
data
74+
data: params
8475
}, callback)
8576
},
8677

lib/resources/paymentLink.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = function paymentLinkApi (api) {
2626
*/
2727

2828
let url = BASE_URL;
29-
return api.postBody({
29+
return api.post({
3030
url,
3131
data: params
3232
}, callback)
@@ -115,14 +115,9 @@ module.exports = function paymentLinkApi (api) {
115115
},
116116

117117
edit(paymentLinkId, params, callback) {
118-
let rest = params;
119-
var isbody = true
120-
121-
var data = {isbody, ...rest};
122-
123118
return api.patch({
124119
url: `${BASE_URL}/${paymentLinkId}`,
125-
data
120+
data: params
126121
}, callback)
127122
},
128123

0 commit comments

Comments
 (0)