Skip to content

Commit

Permalink
Merge pull request #164 from jmxendit/feat/Add-Support-For-Klikpay
Browse files Browse the repository at this point in the history
Feat/add support for klikpay
  • Loading branch information
mesmur authored Jul 15, 2022
2 parents 172ddcb + 29705c0 commit 8242f6e
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 12 deletions.
4 changes: 4 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 @@ -1359,6 +1360,8 @@ dd.createDirectDebitPayment(data: {
basket?: Basket[];
device?: object;
metadata?: object;
successRedirectUrl?: string;
failureRedirectUrl?: string;
});
```

Expand All @@ -1368,6 +1371,7 @@ dd.createDirectDebitPayment(data: {
dd.validateOTPforPayment(data: {
directDebitID: string;
otpCode: string;
apiVersion?: string;
})
```

Expand Down
2 changes: 1 addition & 1 deletion integration_test/card.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
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: 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.4",
"version": "1.21.5",
"description": "NodeJS client for Xendit API",
"main": "index.js",
"types": "index.d.ts",
Expand Down
4 changes: 4 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 @@ -24,11 +25,14 @@ export function createDirectDebitPayment(data: {
basket?: Basket[];
device?: object;
metadata?: object;
successRedirectUrl?: string;
failureRedirectUrl?: string;
}): Promise<object>;

export function validateOTPforPayment(data: {
directDebitID: string;
otpCode: string;
apiVersion?: string;
}): Promise<object>;

export function getDirectDebitPaymentStatusByID(data: {
Expand Down
30 changes: 21 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 All @@ -28,6 +33,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,
Expand Down Expand Up @@ -56,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
1 change: 1 addition & 0 deletions src/direct_debit/payment_method.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function createPaymentMethod(data) {
type: data.type,
properties: {
id: data.properties.id,
channel_code: data.properties.channelCode,
},
metadata: data.metadata,
}),
Expand Down
3 changes: 2 additions & 1 deletion src/ewallet/payment_method.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ enum PaymentMethodType {
}

interface PaymentMethodProperties {
id: string;
id?: string;
channelCode?: string;
}

export function createPaymentMethod(data: {
Expand Down

0 comments on commit 8242f6e

Please sign in to comment.