Skip to content

Commit

Permalink
Merge pull request #129 from xendit/feat/customer-service-api-version…
Browse files Browse the repository at this point in the history
…ing+ewallet-tokenization-flow

Feat/customer service api versioning+ewallet tokenization flow
  • Loading branch information
xen-HendryZheng authored Jan 12, 2022
2 parents 83b75fc + 26fd647 commit 2b06ab2
Show file tree
Hide file tree
Showing 27 changed files with 1,240 additions and 554 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
.env
.nyc_output
coverage
.vscode/
77 changes: 73 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Xendit API Node.js Client

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

This library is the abstraction of Xendit API for access from applications written with server-side Javascript.
Expand Down Expand Up @@ -51,9 +51,15 @@ For PCI compliance to be maintained, tokenization of credit cards info should be
+ [Get a payout](#get-a-payout)
+ [Void a payout](#void-a-payout)
* [EWallet Services](#ewallet-services)
+ [Create payment](#create-payment)
+ [Get payment](#get-payment)
+ [Create an ewallet charge](#create-an-ewallet-charge)
+ [Get an ewallet charge status](#get-an-ewallet-charge-status)
+ [Void an ewallet charge](#void-an-ewallet-charge)
+ [Initialize tokenization](#initialize-tokenization)
+ [Unlink tokenization](#unlink-tokenization)
+ [Create payment method](#create-payment-method)
+ [Get payment methods by customer ID](#get-payment-methods-by-customer-id)
* [Balance Services](#balance-services)
+ [Get balance](#get-balance)
* [Retail Outlet Services](#retail-outlet-services)
Expand All @@ -74,8 +80,8 @@ For PCI compliance to be maintained, tokenization of credit cards info should be
+ [Initialize linked account tokenization](#initialize-linked-account-tokenization)
+ [Validate OTP for Linked Account Token](#validate-otp-for-linked-account-token)
+ [Retrieve accessible accounts by linked account token](#retrieve-accessible-accounts-by-linked-account-token)
+ [Create payment method](#create-payment-method)
+ [Get payment methods by customer ID](#get-payment-methods-by-customer-id)
+ [Create payment method](#create-payment-method-1)
+ [Get payment methods by customer ID](#get-payment-methods-by-customer-id-1)
+ [Create direct debit payment](#create-direct-debit-payment)
+ [Validate OTP for direct debit payment](#validate-otp-for-direct-debit-payment)
+ [Get direct debit payment status by ID](#get-direct-debit-payment-status-by-id)
Expand Down Expand Up @@ -659,6 +665,31 @@ ew.createEWalletCharge({

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

#### Create payment

```ts
ew.createPayment(data: {
externalID: string;
amount: number;
phone?: string;
expirationDate?: Date;
callbackURL?: string;
redirectURL?: string;
items?: PaymentItem[];
ewalletType: CreateSupportWalletTypes;
xApiVersion?: string;
})
```

#### Get payment

```ts
ew.getPayment(data: {
externalID: string;
ewalletType: GetSupportWalletTypes;
})
```

#### Create an ewallet charge

```ts
Expand Down Expand Up @@ -696,6 +727,44 @@ ew.voidEWalletCharge(data: {
})
```

#### Initialize tokenization

```ts
ew.initializeTokenization(data: {
customerID: string;
channelCode: ChannelCode;
properties?: OnlineBankingAccessProperties;
metadata?: object;
})
```

#### Unlink tokenization

```ts
ew.unlinkTokenization(data: {
linkedAccTokenID: string;
})
```

#### Create payment method

```ts
ew.createPaymentMethod(data: {
customerID: string;
type: PaymentMethodType;
properties: PaymentMethodProperties;
metadata?: object;
})
```

#### Get payment methods by customer ID

```ts
ew.getPaymentMethodsByCustomerID(data: {
customerID: string;
})
```

### Balance Services

Instanitiate Balance service using constructor that has been injected with Xendit keys
Expand Down
8 changes: 7 additions & 1 deletion examples/with_async/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ const c = new Customer({});
middleName: 'middle',
surname: 'surname',
addresses: [],
apiVersion: '2020-05-19',
});
console.log('created customer', customer); // eslint-disable-line no-console

customer = await c.getCustomer({ id: customer.id });
customer = await c.getCustomer({
id: customer.id,
apiVersion: '2020-05-19',
});
// eslint-disable-next-line no-console
console.log('retrieved customer', customer);

const customers = await c.getCustomerByReferenceID({
referenceID: customer.reference_id,
apiVersion: '2020-05-19',
});
// eslint-disable-next-line no-console
console.log('retrieved customers', customers);
Expand All @@ -45,6 +50,7 @@ const c = new Customer({});
city: 'Jakarta',
},
],
apiVersion: '2020-05-19',
});
console.log('updated customer', customer); //eslint-disable-line no-console
} catch (e) {
Expand Down
39 changes: 38 additions & 1 deletion examples/with_async/ewallet.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
const x = require('../xendit');

const EWallet = x.EWallet;
const { EWallet, Customer } = x;
const ew = new EWallet({});
const c = new Customer({});

/*
* The entire EWallet tokenization flow, at this time,
* cannot be replicated through an example
* This is because of the system design,
* once a token is created it has
* to be verified manually by using the authorizer url.
* Subsequent methods `create payment method`,
* `get payment by ID`, and `unlink tokenization`
* can only be carried out after the manual authorization
*/

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

let customer = await c.createCustomer({
referenceID: new Date().toISOString(),
givenNames: 'customer 1',
email: '[email protected]',
mobileNumber: '+6281212345678',
description: 'dummy customer',
middleName: 'middle',
surname: 'surname',
addresses: [],
apiVersion: '2020-05-19',
});
// eslint-disable-next-line no-console
console.log('created customer', customer);

let tokenization = await ew.initializeTokenization({
customerID: customer.id,
channelCode: 'PH_GRABPAY',
properties: {
successRedirectURL: 'https://www.google.com',
failureRedirectURL: 'https://www.google.com',
callbackURL: 'https://www.google.com',
},
});
// eslint-disable-next-line no-console
console.log('initialized tokenization', tokenization);
process.exit(0);
} catch (e) {
console.error(e); // eslint-disable-line no-console
Expand Down
11 changes: 9 additions & 2 deletions examples/with_promises/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@ c.createCustomer({
middleName: 'middle',
surname: 'surname',
addresses: [],
apiVersion: '2020-05-19',
})
.then(r => {
console.log('created customer', r); // eslint-disable-line no-console
return r;
})
.then(r => c.getCustomer({ id: r.id }))
.then(r => c.getCustomer({ id: r.id, apiVersion: '2020-05-19' }))
.then(r => {
console.log('retrieved customer', r); // eslint-disable-line no-console
return r;
})
.then(r => c.getCustomerByReferenceID({ referenceID: r.reference_id }))
.then(r =>
c.getCustomerByReferenceID({
referenceID: r.reference_id,
apiVersion: '2020-05-19',
}),
)
.then(r => {
console.log('retrieved customers', r); // eslint-disable-line no-console
return r[0];
Expand All @@ -46,6 +52,7 @@ c.createCustomer({
city: 'Jakarta',
},
],
apiVersion: '2020-05-19',
}),
)
.then(r => {
Expand Down
48 changes: 47 additions & 1 deletion examples/with_promises/ewallet.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
const x = require('../xendit');

const EWallet = x.EWallet;
const { EWallet, Customer } = x;
const ew = new EWallet({});
const c = new Customer({});

/*
* The entire EWallet tokenization flow, at this time,
* cannot be replicated through an example
* This is because of the system design,
* once a token is created it has
* to be verified manually by using the authorizer url.
* Subsequent methods `create payment method`,
* `get payment by ID`, and `unlink tokenization`
* can only be carried out after the manual authorization
*/

ew.createPayment({
externalID: Date.now().toString(),
Expand Down Expand Up @@ -80,6 +92,40 @@ ew.createPayment({
console.log('voided ewallet payment charge:', r);
return r;
})
.then(() =>
c.createCustomer({
referenceID: new Date().toISOString(),
givenNames: 'customer 1',
email: '[email protected]',
mobileNumber: '+6281212345678',
description: 'dummy customer',
middleName: 'middle',
surname: 'surname',
addresses: [],
apiVersion: '2020-05-19',
}),
)
.then(r => {
// eslint-disable-next-line no-console
console.log('created customer:', r);
return r;
})
.then(r =>
ew.initializeTokenization({
customerID: r.id,
channelCode: 'PH_GRABPAY',
properties: {
successRedirectURL: 'https://www.google.com',
failureRedirectURL: 'https://www.google.com',
callbackURL: 'https://www.google.com',
},
}),
)
.then(r => {
// eslint-disable-next-line no-console
console.log('initialized tokenization:', r);
return r;
})
.catch(e => {
console.error(e); // eslint-disable-line no-console
process.exit(1);
Expand Down
38 changes: 37 additions & 1 deletion integration_test/ewallet.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
const x = require('./xendit.test');

const { EWallet } = x;
const { EWallet, Customer } = x;
const ew = new EWallet({});
const c = new Customer({});

/*
* The entire EWallet tokenization flow, at this time,
* cannot be replicated through an integration test
* This is because of the system design,
* once a token is created it has
* to be verified manually by using the authorizer url.
* Subsequent methods `create payment method`,
* `get payment by ID`, and `unlink tokenization`
* can only be carried out after the manual authorization
*/

module.exports = function() {
return ew
Expand Down Expand Up @@ -57,6 +69,30 @@ module.exports = function() {
chargeID: r.id,
}),
)
.then(() =>
c.createCustomer({
referenceID: new Date().toISOString(),
givenNames: 'Test Customer',
email: '[email protected]',
mobileNumber: '+6281212345678',
description: 'dummy customer',
middleName: 'middle',
surname: 'surname',
addresses: [],
apiVersion: '2020-05-19',
}),
)
.then(r =>
ew.initializeTokenization({
customerID: r.id,
channelCode: 'PH_GRABPAY',
properties: {
successRedirectURL: 'https://www.google.com',
failureRedirectURL: 'https://www.google.com',
callbackURL: 'https://www.google.com',
},
}),
)
.then(() => {
// eslint-disable-next-line no-console
console.log('EWallet integration test done...');
Expand Down
10 changes: 6 additions & 4 deletions integration_test/va.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ const x = require('./xendit.test');

const VirtualAcc = x.VirtualAcc;
const va = new VirtualAcc({});
function sleepFor(sleepDuration){
function sleepFor(sleepDuration) {
var now = new Date().getTime();
while(new Date().getTime() < now + sleepDuration){ /* Do nothing */ }
while (new Date().getTime() < now + sleepDuration) {
/* Do nothing */
}
}
module.exports = function () {
module.exports = function() {
return va
.getVABanks()
.then(banks => {
Expand All @@ -20,7 +22,7 @@ module.exports = function () {
})
.then(({ id }) => {
sleepFor(3000);
return va.getFixedVA({ id })
return va.getFixedVA({ id });
})
.then(({ id }) => {
sleepFor(5000);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xendit-node",
"version": "1.19.3",
"version": "1.19.4",
"description": "NodeJS client for Xendit API",
"main": "index.js",
"types": "index.d.ts",
Expand Down
Loading

0 comments on commit 2b06ab2

Please sign in to comment.