Skip to content

Commit

Permalink
Add apiversion header for trident support
Browse files Browse the repository at this point in the history
  • Loading branch information
jmxendit committed Jul 15, 2022
1 parent 6f1bc43 commit 29705c0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,7 @@ dd.getPaymentMethodsByCustomerID(data: {
```ts
dd.createDirectDebitPayment(data: {
idempotencyKey: string;
apiVersion?: string;
referenceID: string;
paymentMethodID: string;
currency: string;
Expand All @@ -1370,6 +1371,7 @@ dd.createDirectDebitPayment(data: {
dd.validateOTPforPayment(data: {
directDebitID: string;
otpCode: string;
apiVersion?: string;
})
```

Expand Down
2 changes: 2 additions & 0 deletions integration_test/direct_debit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -96,6 +97,7 @@ module.exports = function() {
dd.validateOTPforPayment({
directDebitID: r.id,
otpCode: '222000',
apiVersion: null,
}),
)
.then(r =>
Expand Down
2 changes: 2 additions & 0 deletions src/direct_debit/direct_debit_payment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface Basket {

export function createDirectDebitPayment(data: {
idempotencyKey: string;
apiVersion?: string;
referenceID: string;
paymentMethodID: string;
currency: string;
Expand All @@ -31,6 +32,7 @@ export function createDirectDebitPayment(data: {
export function validateOTPforPayment(data: {
directDebitID: string;
otpCode: string;
apiVersion?: string;
}): Promise<object>;

export function getDirectDebitPaymentStatusByID(data: {
Expand Down
28 changes: 19 additions & 9 deletions src/direct_debit/direct_debit_payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}),
Expand Down

0 comments on commit 29705c0

Please sign in to comment.