From a3063f444c49b0e6623300e64b1126cf288c4d4d Mon Sep 17 00:00:00 2001 From: JM Date: Fri, 8 Jul 2022 10:26:53 +0800 Subject: [PATCH 1/3] Added support for klikpay payload --- README.md | 2 ++ package.json | 2 +- src/direct_debit/direct_debit_payment.d.ts | 2 ++ src/direct_debit/direct_debit_payment.js | 2 ++ src/direct_debit/payment_method.js | 1 + src/ewallet/payment_method.d.ts | 3 ++- 6 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 000255a..e5d12d4 100644 --- a/README.md +++ b/README.md @@ -1359,6 +1359,8 @@ dd.createDirectDebitPayment(data: { basket?: Basket[]; device?: object; metadata?: object; + successRedirectUrl?: string; + failureRedirectUrl?: string; }); ``` diff --git a/package.json b/package.json index 86c3f2c..3b07bf8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xendit-node", - "version": "1.21.4", + "version": "1.21.5", "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 942fdca..0aa5f0f 100644 --- a/src/direct_debit/direct_debit_payment.d.ts +++ b/src/direct_debit/direct_debit_payment.d.ts @@ -24,6 +24,8 @@ export function createDirectDebitPayment(data: { basket?: Basket[]; device?: object; metadata?: object; + successRedirectUrl?: string; + failureRedirectUrl?: string; }): Promise; export function validateOTPforPayment(data: { diff --git a/src/direct_debit/direct_debit_payment.js b/src/direct_debit/direct_debit_payment.js index c5615a3..c74315d 100644 --- a/src/direct_debit/direct_debit_payment.js +++ b/src/direct_debit/direct_debit_payment.js @@ -28,6 +28,8 @@ function createDirectDebitPayment(data) { enable_otp: data.enableOTP, description: data.description, device: data.channelCode === 'BCA_ONEKLIK' ? data.device : undefined, + success_redirect_url: data.successRedirectUrl, + failure_redirect_url: data.failureRedirectUrl, basket: data.basket ? data.basket.map(product => ({ reference_id: product.referenceID, diff --git a/src/direct_debit/payment_method.js b/src/direct_debit/payment_method.js index b371c66..7a77271 100644 --- a/src/direct_debit/payment_method.js +++ b/src/direct_debit/payment_method.js @@ -16,6 +16,7 @@ function createPaymentMethod(data) { type: data.type, properties: { id: data.properties.id, + channel_code: data.properties.channelCode, }, metadata: data.metadata, }), diff --git a/src/ewallet/payment_method.d.ts b/src/ewallet/payment_method.d.ts index f0b7add..24ccf5a 100644 --- a/src/ewallet/payment_method.d.ts +++ b/src/ewallet/payment_method.d.ts @@ -3,7 +3,8 @@ enum PaymentMethodType { } interface PaymentMethodProperties { - id: string; + id?: string; + channelCode?: string; } export function createPaymentMethod(data: { From 6f1bc43ef0a31f2a2503b857385f565457ea12a1 Mon Sep 17 00:00:00 2001 From: JM Date: Fri, 8 Jul 2022 14:13:20 +0800 Subject: [PATCH 2/3] adjust endtime value for create promotion --- integration_test/card.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_test/card.test.js b/integration_test/card.test.js index 63fbf8c..f589f16 100644 --- a/integration_test/card.test.js +++ b/integration_test/card.test.js @@ -17,7 +17,7 @@ module.exports = function() { minOriginalAmount: 25000, maxDiscountAmount: 5000, startTime: '2022-03-25T00:00:00.000Z', - endTime: '2022-05-25T00:00:00.000Z', + endTime: '2025-05-25T00:00:00.000Z', }), ) .then(() => { From 29705c0499ce388e9459f49756ea3ca85dd3dbff Mon Sep 17 00:00:00 2001 From: JM Date: Fri, 15 Jul 2022 10:08:21 +0800 Subject: [PATCH 3/3] Add apiversion header for trident support --- README.md | 2 ++ integration_test/direct_debit.test.js | 2 ++ src/direct_debit/direct_debit_payment.d.ts | 2 ++ src/direct_debit/direct_debit_payment.js | 28 +++++++++++++++------- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e5d12d4..41a06d5 100644 --- a/README.md +++ b/README.md @@ -1349,6 +1349,7 @@ dd.getPaymentMethodsByCustomerID(data: { ```ts dd.createDirectDebitPayment(data: { idempotencyKey: string; + apiVersion?: string; referenceID: string; paymentMethodID: string; currency: string; @@ -1370,6 +1371,7 @@ dd.createDirectDebitPayment(data: { dd.validateOTPforPayment(data: { directDebitID: string; otpCode: string; + apiVersion?: string; }) ``` diff --git a/integration_test/direct_debit.test.js b/integration_test/direct_debit.test.js index 11107f0..bd8b63a 100644 --- a/integration_test/direct_debit.test.js +++ b/integration_test/direct_debit.test.js @@ -58,6 +58,7 @@ module.exports = function() { .then(r => dd.createDirectDebitPayment({ idempotencyKey: new Date().toISOString(), + apiVersion: null, referenceID: 'merchant-ref-id-ex-1', paymentMethodID: r[0].id, currency: 'IDR', @@ -96,6 +97,7 @@ module.exports = function() { dd.validateOTPforPayment({ directDebitID: r.id, otpCode: '222000', + apiVersion: null, }), ) .then(r => diff --git a/src/direct_debit/direct_debit_payment.d.ts b/src/direct_debit/direct_debit_payment.d.ts index 0aa5f0f..c300158 100644 --- a/src/direct_debit/direct_debit_payment.d.ts +++ b/src/direct_debit/direct_debit_payment.d.ts @@ -14,6 +14,7 @@ interface Basket { export function createDirectDebitPayment(data: { idempotencyKey: string; + apiVersion?: string; referenceID: string; paymentMethodID: string; currency: string; @@ -31,6 +32,7 @@ export function createDirectDebitPayment(data: { export function validateOTPforPayment(data: { directDebitID: string; otpCode: string; + apiVersion?: string; }): Promise; export function getDirectDebitPaymentStatusByID(data: { diff --git a/src/direct_debit/direct_debit_payment.js b/src/direct_debit/direct_debit_payment.js index c74315d..1e94b2c 100644 --- a/src/direct_debit/direct_debit_payment.js +++ b/src/direct_debit/direct_debit_payment.js @@ -12,13 +12,18 @@ function createDirectDebitPayment(data) { ]; Validate.rejectOnMissingFields(compulsoryFields, data, reject); + const headers = { + Authorization: Auth.basicAuthHeader(this.opts.secretKey), + 'Content-Type': 'application/json', + 'Idempotency-key': data.idempotencyKey, + }; + if (data.apiVersion !== null) { + headers['Api-Version'] = data.apiVersion; + } + fetchWithHTTPErr(`${this.API_ENDPOINT}/direct_debits`, { method: 'POST', - headers: { - Authorization: Auth.basicAuthHeader(this.opts.secretKey), - 'Content-Type': 'application/json', - 'Idempotency-key': data.idempotencyKey, - }, + headers, body: JSON.stringify({ reference_id: data.referenceID, payment_method_id: data.paymentMethodID, @@ -58,14 +63,19 @@ function validateOTPforPayment(data) { const compulsoryFields = ['directDebitID', 'otpCode']; Validate.rejectOnMissingFields(compulsoryFields, data, reject); + const headers = { + Authorization: Auth.basicAuthHeader(this.opts.secretKey), + 'Content-Type': 'application/json', + }; + if (data.apiVersion !== null) { + headers['Api-Version'] = data.apiVersion; + } + fetchWithHTTPErr( `${this.API_ENDPOINT}/direct_debits/${data.directDebitID}/validate_otp/`, { method: 'POST', - headers: { - Authorization: Auth.basicAuthHeader(this.opts.secretKey), - 'Content-Type': 'application/json', - }, + headers, body: JSON.stringify({ otp_code: data.otpCode, }),