-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
103 lines (97 loc) · 2.33 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const axios = require('axios')
const {
RAZORPAY_KEY_ID,
RAZORPAY_KEY_SECRET,
RAZORPAY_PAYOUT_ACCOUNT,
RAZORPAY_PAYOUT_MODE,
RAZORPAY_PAYOUT_QUEUE,
} = process.env
const BASE_URL = `https://${RAZORPAY_KEY_ID}:${RAZORPAY_KEY_SECRET}@api.razorpay.com/v1`
exports.createContact = ({ name, email, contact, type }) => {
console.log(`[ RZPX ] Contact - Create`)
return new Promise((resolve, reject) => {
axios
.post(BASE_URL + '/contacts', { name, email, contact, type })
.then((response) => {
resolve(response.data)
})
.catch((err) => {
reject(err.response.data)
})
})
}
exports.updateContact = (contact_id, { name, email, contact, type }) => {
console.log(`[ RZPX ] Contact - Update`)
return new Promise((resolve, reject) => {
axios
.patch(BASE_URL + '/contacts/' + contact_id, {
name,
email,
contact,
type,
})
.then((response) => {
resolve(response.data)
})
.catch((err) => {
reject(err.response.data)
})
})
}
exports.createBankAccount = (contact_id, { name, account_number, ifsc }) => {
console.log(`[ RZPX ] Account - Create`)
return new Promise((resolve, reject) => {
axios
.post(BASE_URL + '/fund_accounts', {
contact_id,
account_type: 'bank_account',
bank_account: {
name,
account_number,
ifsc,
},
})
.then((response) => {
resolve(response.data)
})
.catch((err) => {
reject(err.response.data)
})
})
}
exports.createPayout = ({
fund_account_id,
amount,
purpose,
narration,
idempotencyToken,
}) => {
console.log(`[ RZPX ] Payout - Create`)
return new Promise((resolve, reject) => {
axios
.post(
BASE_URL + '/payouts',
{
account_number: RAZORPAY_PAYOUT_ACCOUNT,
fund_account_id,
amount,
currency: 'INR',
purpose,
mode: RAZORPAY_PAYOUT_MODE,
queue_if_low_balance: Boolean(RAZORPAY_PAYOUT_QUEUE),
narration,
},
{
headers: {
'X-Payout-Idempotency': idempotencyToken,
},
}
)
.then((response) => {
resolve(response.data)
})
.catch((err) => {
reject(err.response.data)
})
})
}