forked from xendit/xendit-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirect_debit.js
More file actions
123 lines (112 loc) · 3.54 KB
/
Copy pathdirect_debit.js
File metadata and controls
123 lines (112 loc) · 3.54 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
const x = require('../xendit');
const { DirectDebit, Customer } = x;
const dd = new DirectDebit({});
const c = new Customer({});
(async function() {
try {
let customer = await c.createCustomer({
referenceID: new Date().toISOString(),
givenNames: 'customer 1',
email: 'customer@website.com',
mobileNumber: '+6281212345678',
description: 'dummy customer',
middleName: 'middle',
surname: 'surname',
addresses: [],
apiVersion: '2020-05-19',
});
let tokenization = await dd.initializeTokenization({
customerID: customer.id,
channelCode: 'DC_BRI',
properties: {
accountMobileNumber: '+62818555988',
cardLastFour: '8888',
cardExpiry: '06/24',
accountEmail: 'test.email@xendit.co',
},
});
// eslint-disable-next-line no-console
console.log('initialized tokenization', tokenization);
let validateOTP = await dd.validateOTPforLinkedAccount({
tokenID: tokenization.id,
otpCode: '333000',
});
// eslint-disable-next-line no-console
console.log('validated account', validateOTP);
let accounts = await dd.retrieveAccountsByTokenID({
tokenID: tokenization.id,
});
// eslint-disable-next-line no-console
console.log('retrieved accounts', accounts);
let paymentMethod = await dd.createPaymentMethod({
customerID: customer.id,
type: 'DEBIT_CARD',
properties: {
id: accounts[0].id,
},
});
// eslint-disable-next-line no-console
console.log('created payment method', paymentMethod);
let paymentMethods = await dd.getPaymentMethodsByCustomerID({
customerID: customer.id,
});
// eslint-disable-next-line no-console
console.log('retrieved payment methods', paymentMethods);
let ddPayment = await dd.createDirectDebitPayment({
idempotencyKey: new Date().toISOString(),
referenceID: 'merchant-ref-id-ex-1',
paymentMethodID: paymentMethod.id,
currency: 'IDR',
amount: 15000,
callbackURL: 'https://payment-callback-listener/',
enableOTP: true,
basket: [
{
referenceID: 'product-ref-id-ex-1',
name: 'product 1',
market: 'ID',
type: 'good type',
description: 'good quality',
category: 'category',
subCategory: 'subcategory',
price: '10000',
url: 'https://product-url/',
metadata: {
meta: 'data',
},
quantity: 15,
},
{
referenceID: 'product-ref-id-ex-2',
name: 'product 2',
market: 'ID',
type: 'good type',
},
],
metadata: {
meta: 'data',
},
});
// eslint-disable-next-line no-console
console.log('created direct debit payment', ddPayment);
validateOTP = await dd.validateOTPforPayment({
directDebitID: ddPayment.id,
otpCode: '222000',
});
// eslint-disable-next-line no-console
console.log('validated payment', validateOTP);
ddPayment = await dd.getDirectDebitPaymentStatusByID({
directDebitID: ddPayment.id,
});
// eslint-disable-next-line no-console
console.log('retrieved direct debit payment', ddPayment);
let ddPayments = await dd.getDirectDebitPaymentStatusByReferenceID({
referenceID: ddPayment.reference_id,
});
// eslint-disable-next-line no-console
console.log('retrieved direct debit payments', ddPayments);
} catch (e) {
console.error(e); // eslint-disable-line no-console
process.exit(1);
}
})();