Skip to content

Commit 2b06ab2

Browse files
Merge pull request #129 from xendit/feat/customer-service-api-versioning+ewallet-tokenization-flow
Feat/customer service api versioning+ewallet tokenization flow
2 parents 83b75fc + 26fd647 commit 2b06ab2

27 files changed

Lines changed: 1240 additions & 554 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules/
22
.env
33
.nyc_output
44
coverage
5+
.vscode/

README.md

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Xendit API Node.js Client
22

3-
![](https://github.com/xendit/xendit-node/workflows/Code%20Linting/badge.svg)
4-
![](https://github.com/xendit/xendit-node/workflows/Integration%20Tests/badge.svg)
3+
![Code Linting Badge](https://github.com/xendit/xendit-node/workflows/Code%20Linting/badge.svg)
4+
![Integration Tests Badge](https://github.com/xendit/xendit-node/workflows/Integration%20Tests/badge.svg)
55
[![Coverage Status](https://coveralls.io/repos/github/xendit/xendit-node/badge.svg)](https://coveralls.io/github/xendit/xendit-node)
66

77
This library is the abstraction of Xendit API for access from applications written with server-side Javascript.
@@ -51,9 +51,15 @@ For PCI compliance to be maintained, tokenization of credit cards info should be
5151
+ [Get a payout](#get-a-payout)
5252
+ [Void a payout](#void-a-payout)
5353
* [EWallet Services](#ewallet-services)
54+
+ [Create payment](#create-payment)
55+
+ [Get payment](#get-payment)
5456
+ [Create an ewallet charge](#create-an-ewallet-charge)
5557
+ [Get an ewallet charge status](#get-an-ewallet-charge-status)
5658
+ [Void an ewallet charge](#void-an-ewallet-charge)
59+
+ [Initialize tokenization](#initialize-tokenization)
60+
+ [Unlink tokenization](#unlink-tokenization)
61+
+ [Create payment method](#create-payment-method)
62+
+ [Get payment methods by customer ID](#get-payment-methods-by-customer-id)
5763
* [Balance Services](#balance-services)
5864
+ [Get balance](#get-balance)
5965
* [Retail Outlet Services](#retail-outlet-services)
@@ -74,8 +80,8 @@ For PCI compliance to be maintained, tokenization of credit cards info should be
7480
+ [Initialize linked account tokenization](#initialize-linked-account-tokenization)
7581
+ [Validate OTP for Linked Account Token](#validate-otp-for-linked-account-token)
7682
+ [Retrieve accessible accounts by linked account token](#retrieve-accessible-accounts-by-linked-account-token)
77-
+ [Create payment method](#create-payment-method)
78-
+ [Get payment methods by customer ID](#get-payment-methods-by-customer-id)
83+
+ [Create payment method](#create-payment-method-1)
84+
+ [Get payment methods by customer ID](#get-payment-methods-by-customer-id-1)
7985
+ [Create direct debit payment](#create-direct-debit-payment)
8086
+ [Validate OTP for direct debit payment](#validate-otp-for-direct-debit-payment)
8187
+ [Get direct debit payment status by ID](#get-direct-debit-payment-status-by-id)
@@ -659,6 +665,31 @@ ew.createEWalletCharge({
659665

660666
Refer to [Xendit API Reference](https://developers.xendit.co/api-reference/#ewallets) for more info about methods' parameters
661667

668+
#### Create payment
669+
670+
```ts
671+
ew.createPayment(data: {
672+
externalID: string;
673+
amount: number;
674+
phone?: string;
675+
expirationDate?: Date;
676+
callbackURL?: string;
677+
redirectURL?: string;
678+
items?: PaymentItem[];
679+
ewalletType: CreateSupportWalletTypes;
680+
xApiVersion?: string;
681+
})
682+
```
683+
684+
#### Get payment
685+
686+
```ts
687+
ew.getPayment(data: {
688+
externalID: string;
689+
ewalletType: GetSupportWalletTypes;
690+
})
691+
```
692+
662693
#### Create an ewallet charge
663694

664695
```ts
@@ -696,6 +727,44 @@ ew.voidEWalletCharge(data: {
696727
})
697728
```
698729

730+
#### Initialize tokenization
731+
732+
```ts
733+
ew.initializeTokenization(data: {
734+
customerID: string;
735+
channelCode: ChannelCode;
736+
properties?: OnlineBankingAccessProperties;
737+
metadata?: object;
738+
})
739+
```
740+
741+
#### Unlink tokenization
742+
743+
```ts
744+
ew.unlinkTokenization(data: {
745+
linkedAccTokenID: string;
746+
})
747+
```
748+
749+
#### Create payment method
750+
751+
```ts
752+
ew.createPaymentMethod(data: {
753+
customerID: string;
754+
type: PaymentMethodType;
755+
properties: PaymentMethodProperties;
756+
metadata?: object;
757+
})
758+
```
759+
760+
#### Get payment methods by customer ID
761+
762+
```ts
763+
ew.getPaymentMethodsByCustomerID(data: {
764+
customerID: string;
765+
})
766+
```
767+
699768
### Balance Services
700769

701770
Instanitiate Balance service using constructor that has been injected with Xendit keys

examples/with_async/customer.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@ const c = new Customer({});
1414
middleName: 'middle',
1515
surname: 'surname',
1616
addresses: [],
17+
apiVersion: '2020-05-19',
1718
});
1819
console.log('created customer', customer); // eslint-disable-line no-console
1920

20-
customer = await c.getCustomer({ id: customer.id });
21+
customer = await c.getCustomer({
22+
id: customer.id,
23+
apiVersion: '2020-05-19',
24+
});
2125
// eslint-disable-next-line no-console
2226
console.log('retrieved customer', customer);
2327

2428
const customers = await c.getCustomerByReferenceID({
2529
referenceID: customer.reference_id,
30+
apiVersion: '2020-05-19',
2631
});
2732
// eslint-disable-next-line no-console
2833
console.log('retrieved customers', customers);
@@ -45,6 +50,7 @@ const c = new Customer({});
4550
city: 'Jakarta',
4651
},
4752
],
53+
apiVersion: '2020-05-19',
4854
});
4955
console.log('updated customer', customer); //eslint-disable-line no-console
5056
} catch (e) {

examples/with_async/ewallet.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
const x = require('../xendit');
22

3-
const EWallet = x.EWallet;
3+
const { EWallet, Customer } = x;
44
const ew = new EWallet({});
5+
const c = new Customer({});
6+
7+
/*
8+
* The entire EWallet tokenization flow, at this time,
9+
* cannot be replicated through an example
10+
* This is because of the system design,
11+
* once a token is created it has
12+
* to be verified manually by using the authorizer url.
13+
* Subsequent methods `create payment method`,
14+
* `get payment by ID`, and `unlink tokenization`
15+
* can only be carried out after the manual authorization
16+
*/
517

618
(async function() {
719
try {
@@ -64,6 +76,31 @@ const ew = new EWallet({});
6476
// eslint-disable-next-line no-console
6577
console.log('voided ewallet payment charge:', voidedCharge);
6678

79+
let customer = await c.createCustomer({
80+
referenceID: new Date().toISOString(),
81+
givenNames: 'customer 1',
82+
email: 'customer@website.com',
83+
mobileNumber: '+6281212345678',
84+
description: 'dummy customer',
85+
middleName: 'middle',
86+
surname: 'surname',
87+
addresses: [],
88+
apiVersion: '2020-05-19',
89+
});
90+
// eslint-disable-next-line no-console
91+
console.log('created customer', customer);
92+
93+
let tokenization = await ew.initializeTokenization({
94+
customerID: customer.id,
95+
channelCode: 'PH_GRABPAY',
96+
properties: {
97+
successRedirectURL: 'https://www.google.com',
98+
failureRedirectURL: 'https://www.google.com',
99+
callbackURL: 'https://www.google.com',
100+
},
101+
});
102+
// eslint-disable-next-line no-console
103+
console.log('initialized tokenization', tokenization);
67104
process.exit(0);
68105
} catch (e) {
69106
console.error(e); // eslint-disable-line no-console

examples/with_promises/customer.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,23 @@ c.createCustomer({
1212
middleName: 'middle',
1313
surname: 'surname',
1414
addresses: [],
15+
apiVersion: '2020-05-19',
1516
})
1617
.then(r => {
1718
console.log('created customer', r); // eslint-disable-line no-console
1819
return r;
1920
})
20-
.then(r => c.getCustomer({ id: r.id }))
21+
.then(r => c.getCustomer({ id: r.id, apiVersion: '2020-05-19' }))
2122
.then(r => {
2223
console.log('retrieved customer', r); // eslint-disable-line no-console
2324
return r;
2425
})
25-
.then(r => c.getCustomerByReferenceID({ referenceID: r.reference_id }))
26+
.then(r =>
27+
c.getCustomerByReferenceID({
28+
referenceID: r.reference_id,
29+
apiVersion: '2020-05-19',
30+
}),
31+
)
2632
.then(r => {
2733
console.log('retrieved customers', r); // eslint-disable-line no-console
2834
return r[0];
@@ -46,6 +52,7 @@ c.createCustomer({
4652
city: 'Jakarta',
4753
},
4854
],
55+
apiVersion: '2020-05-19',
4956
}),
5057
)
5158
.then(r => {

examples/with_promises/ewallet.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
const x = require('../xendit');
22

3-
const EWallet = x.EWallet;
3+
const { EWallet, Customer } = x;
44
const ew = new EWallet({});
5+
const c = new Customer({});
6+
7+
/*
8+
* The entire EWallet tokenization flow, at this time,
9+
* cannot be replicated through an example
10+
* This is because of the system design,
11+
* once a token is created it has
12+
* to be verified manually by using the authorizer url.
13+
* Subsequent methods `create payment method`,
14+
* `get payment by ID`, and `unlink tokenization`
15+
* can only be carried out after the manual authorization
16+
*/
517

618
ew.createPayment({
719
externalID: Date.now().toString(),
@@ -80,6 +92,40 @@ ew.createPayment({
8092
console.log('voided ewallet payment charge:', r);
8193
return r;
8294
})
95+
.then(() =>
96+
c.createCustomer({
97+
referenceID: new Date().toISOString(),
98+
givenNames: 'customer 1',
99+
email: 'customer@website.com',
100+
mobileNumber: '+6281212345678',
101+
description: 'dummy customer',
102+
middleName: 'middle',
103+
surname: 'surname',
104+
addresses: [],
105+
apiVersion: '2020-05-19',
106+
}),
107+
)
108+
.then(r => {
109+
// eslint-disable-next-line no-console
110+
console.log('created customer:', r);
111+
return r;
112+
})
113+
.then(r =>
114+
ew.initializeTokenization({
115+
customerID: r.id,
116+
channelCode: 'PH_GRABPAY',
117+
properties: {
118+
successRedirectURL: 'https://www.google.com',
119+
failureRedirectURL: 'https://www.google.com',
120+
callbackURL: 'https://www.google.com',
121+
},
122+
}),
123+
)
124+
.then(r => {
125+
// eslint-disable-next-line no-console
126+
console.log('initialized tokenization:', r);
127+
return r;
128+
})
83129
.catch(e => {
84130
console.error(e); // eslint-disable-line no-console
85131
process.exit(1);

integration_test/ewallet.test.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
const x = require('./xendit.test');
22

3-
const { EWallet } = x;
3+
const { EWallet, Customer } = x;
44
const ew = new EWallet({});
5+
const c = new Customer({});
6+
7+
/*
8+
* The entire EWallet tokenization flow, at this time,
9+
* cannot be replicated through an integration test
10+
* This is because of the system design,
11+
* once a token is created it has
12+
* to be verified manually by using the authorizer url.
13+
* Subsequent methods `create payment method`,
14+
* `get payment by ID`, and `unlink tokenization`
15+
* can only be carried out after the manual authorization
16+
*/
517

618
module.exports = function() {
719
return ew
@@ -57,6 +69,30 @@ module.exports = function() {
5769
chargeID: r.id,
5870
}),
5971
)
72+
.then(() =>
73+
c.createCustomer({
74+
referenceID: new Date().toISOString(),
75+
givenNames: 'Test Customer',
76+
email: 'customer_test@website.com',
77+
mobileNumber: '+6281212345678',
78+
description: 'dummy customer',
79+
middleName: 'middle',
80+
surname: 'surname',
81+
addresses: [],
82+
apiVersion: '2020-05-19',
83+
}),
84+
)
85+
.then(r =>
86+
ew.initializeTokenization({
87+
customerID: r.id,
88+
channelCode: 'PH_GRABPAY',
89+
properties: {
90+
successRedirectURL: 'https://www.google.com',
91+
failureRedirectURL: 'https://www.google.com',
92+
callbackURL: 'https://www.google.com',
93+
},
94+
}),
95+
)
6096
.then(() => {
6197
// eslint-disable-next-line no-console
6298
console.log('EWallet integration test done...');

integration_test/va.test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ const x = require('./xendit.test');
22

33
const VirtualAcc = x.VirtualAcc;
44
const va = new VirtualAcc({});
5-
function sleepFor(sleepDuration){
5+
function sleepFor(sleepDuration) {
66
var now = new Date().getTime();
7-
while(new Date().getTime() < now + sleepDuration){ /* Do nothing */ }
7+
while (new Date().getTime() < now + sleepDuration) {
8+
/* Do nothing */
9+
}
810
}
9-
module.exports = function () {
11+
module.exports = function() {
1012
return va
1113
.getVABanks()
1214
.then(banks => {
@@ -20,7 +22,7 @@ module.exports = function () {
2022
})
2123
.then(({ id }) => {
2224
sleepFor(3000);
23-
return va.getFixedVA({ id })
25+
return va.getFixedVA({ id });
2426
})
2527
.then(({ id }) => {
2628
sleepFor(5000);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xendit-node",
3-
"version": "1.19.3",
3+
"version": "1.19.4",
44
"description": "NodeJS client for Xendit API",
55
"main": "index.js",
66
"types": "index.d.ts",

0 commit comments

Comments
 (0)