Skip to content

Commit

Permalink
Merge pull request #154 from jmxendit/feat/dd-debit-card-support
Browse files Browse the repository at this point in the history
Add support for other debit card and device field
  • Loading branch information
xen-HendryZheng authored Apr 25, 2022
2 parents 8f75523 + b900d4b commit 1ca4fcf
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 21 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,7 @@ dd.initializeTokenization(data: {
customerID: string;
channelCode: ChannelCode;
properties?: DebitCardProperties | OnlineBankingAccessProperties;
device?: object;
metadata?: object;
});
```
Expand Down Expand Up @@ -1355,6 +1356,7 @@ dd.createDirectDebitPayment(data: {
enableOTP?: boolean;
description?: string;
basket?: Basket[];
device?: object;
metadata?: object;
});
```
Expand Down
22 changes: 18 additions & 4 deletions integration_test/retail_outlet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ const x = require('./xendit.test');

const RetailOutlet = x.RetailOutlet;
const ro = new RetailOutlet({});

function sleepFor(sleepDuration) {
var now = new Date().getTime();
while (new Date().getTime() < now + sleepDuration) {
/* Do nothing */
}
}
module.exports = function() {
return ro
.createFixedPaymentCode({
Expand All @@ -11,8 +16,14 @@ module.exports = function() {
name: 'Ervan Adetya',
expectedAmt: 10000,
})
.then(({ id }) => ro.getFixedPaymentCode({ id }))
.then(({ id }) => ro.updateFixedPaymentCode({ id: id, expectedAmt: 12000 }))
.then(({ id }) => {
sleepFor(3000);
return ro.getFixedPaymentCode({ id });
})
.then(({ id }) => {
sleepFor(3000);
return ro.updateFixedPaymentCode({ id: id, expectedAmt: 12000 });
})
.then(({ id, payment_code }) =>
Promise.all([
id,
Expand All @@ -23,7 +34,10 @@ module.exports = function() {
}),
]),
)
.then(([id]) => ro.getPaymentsByFixedPaymentCodeId({ id }))
.then(([id]) => {
sleepFor(3000);
return ro.getPaymentsByFixedPaymentCodeId({ id });
})
.then(() => {
// eslint-disable-next-line no-console
console.log('Retail outlet integration test done...');
Expand Down
23 changes: 20 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.21.1",
"version": "1.21.2",
"description": "NodeJS client for Xendit API",
"main": "index.js",
"types": "index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/direct_debit/direct_debit_payment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function createDirectDebitPayment(data: {
enableOTP?: boolean;
description?: string;
basket?: Basket[];
device?: object;
metadata?: object;
}): Promise<object>;

Expand Down
1 change: 1 addition & 0 deletions src/direct_debit/direct_debit_payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function createDirectDebitPayment(data) {
callback_url: data.callbackURL,
enable_otp: data.enableOTP,
description: data.description,
device: data.channelCode === 'BCA_ONEKLIK' ? data.device : undefined,
basket: data.basket
? data.basket.map(product => ({
reference_id: product.referenceID,
Expand Down
2 changes: 2 additions & 0 deletions src/direct_debit/linked_account.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface DebitCardProperties {

interface OnlineBankingAccessProperties {
successRedirectURL: string;
accountMobileNumber?: string;
failureRedirectURL?: string;
callbackURL?: string;
}
Expand All @@ -20,6 +21,7 @@ export function initializeTokenization(data: {
customerID: string;
channelCode: ChannelCode;
properties?: DebitCardProperties | OnlineBankingAccessProperties;
device?: object;
metadata?: object;
}): Promise<object>;

Expand Down
40 changes: 27 additions & 13 deletions src/direct_debit/linked_account.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,41 @@ function initializeTokenization(data) {
body: JSON.stringify({
customer_id: data.customerID,
channel_code: data.channelCode,
properties:
data.channelCode === 'DC_BRI'
? {
account_mobile_number: data.properties.accountMobileNumber,
card_last_four: data.properties.cardLastFour,
card_expiry: data.properties.cardExpiry,
account_email: data.properties.accountEmail,
}
: {
success_redirect_url: data.properties.successRedirectURL,
failure_redirect_url: data.properties.failureRedirectURL,
callback_url: data.properties.callbackURL,
},
properties: getProperties(data),
metadata: data.metadata,
device: data.device,
}),
})
.then(resolve)
.catch(reject);
});
}

function getProperties(data) {
if (data.channelCode === 'DC_BRI') {
return {
account_mobile_number: data.properties.accountMobileNumber,
card_last_four: data.properties.cardLastFour,
card_expiry: data.properties.cardExpiry,
account_email: data.properties.accountEmail,
};
} else if (data.channelCode === 'BCA_ONEKLIK') {
return {
account_mobile_number: data.properties.accountMobileNumber,
success_redirect_url: data.properties.successRedirectURL,
failure_redirect_url: data.properties.failureRedirectURL,
callback_url: data.properties.callbackURL,
};
} else {
return {
account_mobile_number: data.properties.accountMobileNumber,
success_redirect_url: data.properties.successRedirectURL,
failure_redirect_url: data.properties.failureRedirectURL,
callback_url: data.properties.callbackURL,
};
}
}

function validateOTPforLinkedAccount(data) {
return promWithJsErr((resolve, reject) => {
const compulsoryFields = ['tokenID', 'otpCode'];
Expand Down

0 comments on commit 1ca4fcf

Please sign in to comment.