Skip to content

Commit

Permalink
Merge pull request #141 from xendit/fix/addForUserIdOnDisbursement
Browse files Browse the repository at this point in the history
add forUserId on disbrusement
  • Loading branch information
xen-HendryZheng authored Feb 22, 2022
2 parents 41acabf + f05add3 commit c70af51
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 41 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ d.create(data: {
emailCC?: string[];
emailBCC?: string[];
xIdempotencyKey?: string;
forUserID?: string;
withFeeRule?: string;
})
```

Expand All @@ -415,6 +417,8 @@ d.createBatch(data: {
emailTo?: string[];
emailCC?: string[];
emailBCC?: string[];
forUserID?: string;
withFeeRule?: string;
}>;
xIdempotencyKey?: string;
})
Expand Down
1 change: 1 addition & 0 deletions examples/with_async/disbursement.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const d = new Disbursement({});
accountNumber: '1234567890',
description: `purchase paid from ${banks[0].name}`,
amount: 10000,
forUserID: 'for-user-id-test',
});
// eslint-disable-next-line no-console
console.log('disbursement created:', disb);
Expand Down
66 changes: 26 additions & 40 deletions integration_test/ewallet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,34 @@ const c = new Customer({});

module.exports = function() {
return ew
.createPayment({
externalID: Date.now().toString(),
amount: 1,
phone: '081234567890',
ewalletType: EWallet.Type.OVO,
})
.then(({ external_id, ewallet_type }) =>
ew.getPayment({
externalID: external_id,
ewalletType: ewallet_type,
}),
)
.then(() =>
ew.createEWalletCharge({
referenceID: Date.now().toString(),
currency: 'IDR',
amount: 1688,
checkoutMethod: 'ONE_TIME_PAYMENT',
channelCode: 'ID_OVO',
channelProperties: {
mobileNumber: '+6281234567890',
},
basket: [
{
referenceID: 'basket-product-ref-id',
name: 'product name',
category: 'mechanics',
currency: 'IDR',
price: 50000,
quantity: 5,
type: 'wht',
subCategory: 'evr',
metadata: {
meta: 'data',
},
.createEWalletCharge({
referenceID: Date.now().toString(),
currency: 'IDR',
amount: 1688,
checkoutMethod: 'ONE_TIME_PAYMENT',
channelCode: 'ID_OVO',
channelProperties: {
mobileNumber: '+6281234567890',
},
basket: [
{
referenceID: 'basket-product-ref-id',
name: 'product name',
category: 'mechanics',
currency: 'IDR',
price: 50000,
quantity: 5,
type: 'wht',
subCategory: 'evr',
metadata: {
meta: 'data',
},
],
metadata: {
meta2: 'data2',
},
}),
)
],
metadata: {
meta2: 'data2',
},
})
.then(r =>
ew.getEWalletChargeStatus({
chargeID: r.id,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "xendit-node",
"version": "1.19.9",
"version": "1.20.1",
"description": "NodeJS client for Xendit API",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test": "mocha test/**/*.test.js",
"test:integration": "node integration_test",
"lint": "eslint index.js ./**/*.{js,ts}",
"lint:fix": "eslint index.js ./**/*.{js,ts} --fix",
"format": "prettier --config .prettierrc --write index.js ./**/*.{js,json,ts}",
"gentoc": "markdown-toc -i README.md",
"release": "np",
Expand Down
15 changes: 15 additions & 0 deletions src/disbursement/disburse.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ function create(data) {
data.xIdempotencyKey,
);

if (data && data.forUserID) {
headers['for-user-id'] = data.forUserID;
}

if (data && data.withFeeRule) {
headers['with-fee-rule'] = data.withFeeRule;
}

fetchWithHTTPErr(`${this.API_ENDPOINT}/disbursements`, {
method: 'POST',
headers,
Expand Down Expand Up @@ -55,6 +63,13 @@ function createBatch(data) {
this.opts.secretKey,
data.xIdempotencyKey,
);
if (data && data.forUserID) {
headers['for-user-id'] = data.forUserID;
}

if (data && data.withFeeRule) {
headers['with-fee-rule'] = data.withFeeRule;
}

fetchWithHTTPErr(`${this.API_ENDPOINT}/batch_disbursements`, {
method: 'POST',
Expand Down

0 comments on commit c70af51

Please sign in to comment.