forked from xendit/xendit-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard.js
41 lines (35 loc) · 1.21 KB
/
card.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
const x = require('../xendit');
const Card = x.Card;
const card = new Card({});
// These IDs should be obtained using Xendit.js
// https://docs.xendit.co/xenpayments/payments-credit-cards-overview/credit-cards-integration-and-testing/collecting-card-details-tokenization/index.html
const tokenID = '5e0461a86113354249aab7ec';
const authID = '5e0461a96113354249aab7ee';
(async function() {
try {
const charge = await card.createCharge({
tokenID,
authID,
amount: 10000,
// eslint-disable-next-line max-len
externalID: Date.now().toString(), // use your system's ID of the transaction
capture: false,
});
console.log('charge created:', charge); // eslint-disable-line no-console
const capture = await card.captureCharge({
chargeID: id,
amount: 10000,
});
console.log('charge captured:', capture); // eslint-disable-line no-console
const refund = await card.createRefund({
chargeID: id,
externalID: external_id,
amount: 5000,
});
console.log('refund created:', refund); // eslint-disable-line no-console
process.exit(0);
} catch (e) {
console.error(e); // eslint-disable-line no-console
process.exit(1);
}
})();