From ee098fb1d383c4837f0a5ed9928458b523806cd1 Mon Sep 17 00:00:00 2001 From: JM Date: Mon, 25 Apr 2022 10:34:29 +0800 Subject: [PATCH 1/6] Add support for other debit card and device field --- src/direct_debit/direct_debit_payment.js | 1 + src/direct_debit/linked_account.js | 39 ++++++++++++++++-------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/direct_debit/direct_debit_payment.js b/src/direct_debit/direct_debit_payment.js index a39ea4a..9de5fa2 100644 --- a/src/direct_debit/direct_debit_payment.js +++ b/src/direct_debit/direct_debit_payment.js @@ -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 : null, basket: data.basket ? data.basket.map(product => ({ reference_id: product.referenceID, diff --git a/src/direct_debit/linked_account.js b/src/direct_debit/linked_account.js index 41d5fb8..246ead0 100644 --- a/src/direct_debit/linked_account.js +++ b/src/direct_debit/linked_account.js @@ -14,20 +14,9 @@ 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) @@ -35,6 +24,30 @@ function initializeTokenization(data) { }); } +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 { + 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']; From 49c910fb35bcbac9e992f4113b4d6e2a18f53be6 Mon Sep 17 00:00:00 2001 From: JM Date: Mon, 25 Apr 2022 11:34:31 +0800 Subject: [PATCH 2/6] Fix failing test --- src/direct_debit/direct_debit_payment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/direct_debit/direct_debit_payment.js b/src/direct_debit/direct_debit_payment.js index 9de5fa2..c5615a3 100644 --- a/src/direct_debit/direct_debit_payment.js +++ b/src/direct_debit/direct_debit_payment.js @@ -27,7 +27,7 @@ function createDirectDebitPayment(data) { callback_url: data.callbackURL, enable_otp: data.enableOTP, description: data.description, - device: data.channelCode === 'BCA_ONEKLIK' ? data.device : null, + device: data.channelCode === 'BCA_ONEKLIK' ? data.device : undefined, basket: data.basket ? data.basket.map(product => ({ reference_id: product.referenceID, From 78d3706a9ec9fc2a51c6a403ad248b5766d5c1fe Mon Sep 17 00:00:00 2001 From: JM Date: Mon, 25 Apr 2022 14:55:08 +0800 Subject: [PATCH 3/6] Bump package version and added new option to readme --- README.md | 2 ++ package.json | 2 +- src/direct_debit/direct_debit_payment.d.ts | 1 + src/direct_debit/linked_account.d.ts | 2 ++ src/direct_debit/linked_account.js | 1 + 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ef967fa..5a95d83 100644 --- a/README.md +++ b/README.md @@ -1302,6 +1302,7 @@ dd.initializeTokenization(data: { customerID: string; channelCode: ChannelCode; properties?: DebitCardProperties | OnlineBankingAccessProperties; + device?: object; metadata?: object; }); ``` @@ -1355,6 +1356,7 @@ dd.createDirectDebitPayment(data: { enableOTP?: boolean; description?: string; basket?: Basket[]; + device?: object; metadata?: object; }); ``` diff --git a/package.json b/package.json index b94ff20..889959e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/direct_debit/direct_debit_payment.d.ts b/src/direct_debit/direct_debit_payment.d.ts index cf9bb90..942fdca 100644 --- a/src/direct_debit/direct_debit_payment.d.ts +++ b/src/direct_debit/direct_debit_payment.d.ts @@ -22,6 +22,7 @@ export function createDirectDebitPayment(data: { enableOTP?: boolean; description?: string; basket?: Basket[]; + device?: object; metadata?: object; }): Promise; diff --git a/src/direct_debit/linked_account.d.ts b/src/direct_debit/linked_account.d.ts index b01ac44..c37022f 100644 --- a/src/direct_debit/linked_account.d.ts +++ b/src/direct_debit/linked_account.d.ts @@ -12,6 +12,7 @@ interface DebitCardProperties { interface OnlineBankingAccessProperties { successRedirectURL: string; + accountMobileNumber?: string; failureRedirectURL?: string; callbackURL?: string; } @@ -20,6 +21,7 @@ export function initializeTokenization(data: { customerID: string; channelCode: ChannelCode; properties?: DebitCardProperties | OnlineBankingAccessProperties; + device?: object; metadata?: object; }): Promise; diff --git a/src/direct_debit/linked_account.js b/src/direct_debit/linked_account.js index 246ead0..71d5ca5 100644 --- a/src/direct_debit/linked_account.js +++ b/src/direct_debit/linked_account.js @@ -41,6 +41,7 @@ function getProperties(data) { }; } 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, From 04a286101d099dbbc2e7e290cf002c3e8d9f5c14 Mon Sep 17 00:00:00 2001 From: JM Date: Mon, 25 Apr 2022 17:26:10 +0800 Subject: [PATCH 4/6] package lock --- package-lock.json | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index d7c1aa9..1b7861a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,16 @@ { "name": "xendit-node", - "version": "1.21.0", + "version": "1.21.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "xendit-node", - "version": "1.20.1", + "version": "1.21.2", "license": "MIT", "dependencies": { - "node-fetch": "^2.6.1" + "node-fetch": "^2.6.1", + "xendit-node": "^1.21.1" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^2.13.0", @@ -9454,6 +9455,14 @@ "node": ">=8" } }, + "node_modules/xendit-node": { + "version": "1.21.1", + "resolved": "https://registry.npmjs.org/xendit-node/-/xendit-node-1.21.1.tgz", + "integrity": "sha512-lWNW49JmNRxHMkuMqn7jGCe36H2kA4xDCWBV3lECOG1ZayTyzHdHya47wL7x7N1rwjK6/DgoM6Z2gw8wVbNjyA==", + "dependencies": { + "node-fetch": "^2.6.1" + } + }, "node_modules/xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", @@ -16627,6 +16636,14 @@ "integrity": "sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q==", "dev": true }, + "xendit-node": { + "version": "1.21.1", + "resolved": "https://registry.npmjs.org/xendit-node/-/xendit-node-1.21.1.tgz", + "integrity": "sha512-lWNW49JmNRxHMkuMqn7jGCe36H2kA4xDCWBV3lECOG1ZayTyzHdHya47wL7x7N1rwjK6/DgoM6Z2gw8wVbNjyA==", + "requires": { + "node-fetch": "^2.6.1" + } + }, "xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", From a6d0d89cb398fcd8770a1a4baeabe7aa1c4812e7 Mon Sep 17 00:00:00 2001 From: Hendry Zheng Date: Mon, 25 Apr 2022 17:13:56 +0700 Subject: [PATCH 5/6] Update retail outlet integration test add sleep --- integration_test/retail_outlet.test.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/integration_test/retail_outlet.test.js b/integration_test/retail_outlet.test.js index 91338ca..3557dad 100644 --- a/integration_test/retail_outlet.test.js +++ b/integration_test/retail_outlet.test.js @@ -2,8 +2,13 @@ const x = require('./xendit.test'); const RetailOutlet = x.RetailOutlet; const ro = new RetailOutlet({}); - -module.exports = function() { +function sleepFor(sleepDuration) { + var now = new Date().getTime(); + while (new Date().getTime() < now + sleepDuration) { + /* Do nothing */ + } +} +module.exports = function () { return ro .createFixedPaymentCode({ externalID: '123', @@ -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, @@ -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...'); From b900d4b8f92e36a6a0c5a65855d6397533db6a7b Mon Sep 17 00:00:00 2001 From: Hendry Zheng Date: Mon, 25 Apr 2022 17:18:03 +0700 Subject: [PATCH 6/6] update lint fix --- integration_test/retail_outlet.test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/integration_test/retail_outlet.test.js b/integration_test/retail_outlet.test.js index 3557dad..af82f1c 100644 --- a/integration_test/retail_outlet.test.js +++ b/integration_test/retail_outlet.test.js @@ -8,7 +8,7 @@ function sleepFor(sleepDuration) { /* Do nothing */ } } -module.exports = function () { +module.exports = function() { return ro .createFixedPaymentCode({ externalID: '123', @@ -18,11 +18,11 @@ module.exports = function () { }) .then(({ id }) => { sleepFor(3000); - return ro.getFixedPaymentCode({ id }) + return ro.getFixedPaymentCode({ id }); }) .then(({ id }) => { sleepFor(3000); - return ro.updateFixedPaymentCode({ id: id, expectedAmt: 12000 }) + return ro.updateFixedPaymentCode({ id: id, expectedAmt: 12000 }); }) .then(({ id, payment_code }) => Promise.all([ @@ -34,9 +34,9 @@ module.exports = function () { }), ]), ) - .then(([id]) => { + .then(([id]) => { sleepFor(3000); - return ro.getPaymentsByFixedPaymentCodeId({ id }) + return ro.getPaymentsByFixedPaymentCodeId({ id }); }) .then(() => { // eslint-disable-next-line no-console