-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cards.js
68 lines (57 loc) · 1.45 KB
/
Cards.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
const Xendit = require('xendit-node')
const { secretKey } = require('./general/general')
const readline = require('readline')
const payment = new Xendit({
secretKey
})
const { Card } = payment
const card = new Card({})
const read = readline.createInterface({
input: process.stdin,
output: process.stdout
})
let tokenId
let authId
let amount
const inputs = []
console.log('Put in order tokenId, authId, amount')
read.prompt()
read.on('line', data => {
inputs.push(data)
}).on('close', async () => {
tokenId = inputs[0]
authId = inputs[1]
amount = inputs[2]
const data = {
externalID: `sample-external-id-${Date.now().toString()}`,
tokenID: tokenId,
amount: amount,
authID: authId
}
console.log('-----Data to be requested-----')
console.log(data)
const resp = await createCharge(data)
console.log(resp)
process.exit(0)
})
async function createAuthorization(authorizationData) {
return new Promise((resolve, reject) => {
card.createAuthorization(authorizationData)
.then(r => {
resolve(r)
}).catch(err => {
reject(err)
})
})
}
async function createCharge(chargeData){
return new Promise(((resolve, reject) => {
card.createCharge(chargeData)
.then(r => {
resolve(r)
})
.catch(err => {
reject(err)
})
}))
}