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, }),