-
Notifications
You must be signed in to change notification settings - Fork 0
/
Payout.js
93 lines (76 loc) · 2.1 KB
/
Payout.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
const Xendit = require('xendit-node')
const { secretKey } = require('./general/general')
const readline = require('readline')
const payment = new Xendit({
secretKey
})
const { Payout } = payment
const payout = new Payout({})
const read = readline.createInterface({
input: process.stdin,
output: process.stdout
})
let email
let description
let amount
const inputs = []
console.log('Enter your email, amount :')
read.prompt()
read.on('line', data => {
inputs.push(data)
}).on('close', async () => {
email = inputs[0]
amount = inputs[1]
const data = {
externalID: `sample-external-id-${Date.now().toString()}`,
amount,
email
}
console.log('-----Data to be requested-----')
console.log(data)
const respCreatePayout = await createPayoutPayment(data)
console.log(respCreatePayout)
console.log(`-----Get Data of ID ${respCreatePayout.id}-----`)
const respGetPayout = await getPayoutDataById(respCreatePayout.id)
console.log(respGetPayout)
console.log(`-----Void Data of ID ${respCreatePayout.id}-----`)
const respVoidPayout = await voidPayoutDataById(respCreatePayout.id)
console.log(respVoidPayout)
process.exit(0)
})
async function createPayoutPayment(payoutData){
return new Promise(((resolve, reject) => {
payout.createPayout(payoutData)
.then(r => {
resolve(r)
})
.catch(err => {
console.log(err)
reject(err)
})
}))
}
async function getPayoutDataById(id){
return new Promise((resolve, reject) => {
payout.getPayout({id})
.then((res) => {
resolve(res)
})
.catch((err) => {
console.log(err)
reject(err)
})
})
}
async function voidPayoutDataById(id){
return new Promise((resolve, reject) => {
payout.voidPayout({id})
.then((res) => {
resolve(res)
})
.catch((err) => {
console.log(err)
reject(err)
})
})
}