Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ewallets endpoints #20

Merged
merged 68 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
0abfd72
Add init e-wallet client
ErvanAdetya Dec 26, 2019
1fecdfc
Add get ovo payment status by external id
ErvanAdetya Dec 26, 2019
873377b
Export ovo payment function
ErvanAdetya Dec 26, 2019
a7a03cd
Add create dana payment function
ErvanAdetya Dec 26, 2019
4dc4c3b
Add get Dana Payment Status By External ID
ErvanAdetya Dec 26, 2019
8fe4ccb
Implemen dana payment
ErvanAdetya Dec 26, 2019
bf01289
Add create link aja payment function
ErvanAdetya Dec 26, 2019
eb5e2f0
Impement link aja payment
ErvanAdetya Dec 26, 2019
52825b2
Add ewallet service
ErvanAdetya Dec 26, 2019
20bc5ed
Implement ewallet service
ErvanAdetya Dec 26, 2019
8310f68
Add e wallet to xendit ts
ErvanAdetya Dec 26, 2019
9859f5c
remove _transformEWalletForRequestBody
ErvanAdetya Dec 26, 2019
4d31e39
Fix bad data passing
ErvanAdetya Dec 26, 2019
13bf214
Add OVO.d.ts
ErvanAdetya Dec 26, 2019
5504f4b
Add dana.d.ts
ErvanAdetya Dec 26, 2019
ba96724
Add linkaja.d.ts
ErvanAdetya Dec 26, 2019
45837ed
Add ewallet.d.ts
ErvanAdetya Dec 26, 2019
c01ec3b
[Fix] Bad parameter passing
ErvanAdetya Dec 26, 2019
b7279cb
[Fix] Bad parameter passing
ErvanAdetya Dec 26, 2019
2697690
[Fix] Remove unuser var
ErvanAdetya Dec 26, 2019
cbc2f77
[Test] OVO Integration test
ErvanAdetya Dec 26, 2019
c0a69f8
[Fix] Bad parameter passing
ErvanAdetya Dec 26, 2019
601b6b5
[Test] Get OVO payment status
ErvanAdetya Dec 26, 2019
bd97b43
[Fix] Wrong Url
ErvanAdetya Dec 27, 2019
e8be9ef
[Fix] bad logic
ErvanAdetya Dec 27, 2019
45f8866
Add dana example
ErvanAdetya Dec 28, 2019
440a53c
Add linkAja example
ErvanAdetya Dec 28, 2019
00ce8d2
[Fix] linter
ErvanAdetya Dec 28, 2019
9b5b0e5
[Fix] Remove unneeded function
ErvanAdetya Dec 28, 2019
d615a8d
[Fix] Missing Header
ErvanAdetya Dec 28, 2019
ff11173
[Update] Restruct OVO Payment
ErvanAdetya Dec 29, 2019
77e8c33
[Update] Restruct Ewallet
ErvanAdetya Dec 29, 2019
2d92a7a
[Update] Rename variable
ErvanAdetya Dec 29, 2019
599f2f6
Add Link Aja test
ErvanAdetya Dec 29, 2019
c2bacf1
[Update] Add dana test
ErvanAdetya Dec 29, 2019
79d9c28
[Fix] make dana expiration date as optional
ErvanAdetya Dec 29, 2019
af0d66e
[Update] Improve unit test
ErvanAdetya Dec 29, 2019
d74acec
[Update] Change phone number
ErvanAdetya Dec 29, 2019
881a7c8
[Update] Add Ewallets documentation
ErvanAdetya Dec 29, 2019
ec1ff4e
[Fix] Readme indentation
ErvanAdetya Dec 29, 2019
c2a2cd3
[Fix] Readme indentation
ErvanAdetya Dec 29, 2019
a359e54
[Fix] Readme indentation
ErvanAdetya Dec 29, 2019
54b8497
[Fix] TS Linter
ErvanAdetya Dec 29, 2019
1b0d1ec
[Fix] Ewallet integration test
ErvanAdetya Dec 29, 2019
cef6cff
[Update] Simplify Ewallet Service
ErvanAdetya Dec 29, 2019
99b815c
[Update] Delete Unused OVO flie
ErvanAdetya Dec 29, 2019
aad8143
Remove unused test file
ErvanAdetya Dec 29, 2019
471cb06
[Update] Delete Unused Dana flie
ErvanAdetya Dec 29, 2019
42cdbf2
[Update] Delete Unused linkaja flie
ErvanAdetya Dec 29, 2019
8c66873
[Update] Simplify query string
ErvanAdetya Dec 29, 2019
8fb497e
[Update] Remove Granular Ewallet type from readme
ErvanAdetya Dec 29, 2019
25fb4b7
[Fix] Delete unused var
ErvanAdetya Dec 29, 2019
ce756f9
[Update] Add enum for ewallet type
ErvanAdetya Dec 29, 2019
8d3072b
[Update] Ewallet unit test
ErvanAdetya Dec 29, 2019
8bb5e32
[Fix] Wrong Parameter
ErvanAdetya Dec 29, 2019
2ba6514
[Fix] Wrong method calling
ErvanAdetya Dec 29, 2019
f01706c
[Fix] Change method params calling
ErvanAdetya Dec 29, 2019
92c4987
[Update] Improve ewallet unit test
ErvanAdetya Dec 29, 2019
a9329a2
[Fix] Wrong ExpirationDate Type
ErvanAdetya Dec 29, 2019
6cc5c0b
[Fix] Wrong method calling in readme
ErvanAdetya Dec 29, 2019
93549ca
[Update] Change integration test with dana
ErvanAdetya Dec 29, 2019
11428cc
[Fix] EWallet Integration Test Params
ErvanAdetya Dec 29, 2019
5584dfb
feat(ewallet) add EWalletType static prop
stanleynguyen Dec 30, 2019
238735e
feat(ewallet) Shorten EWallet Type prop name
stanleynguyen Dec 30, 2019
3dfa782
fix(xendit.d.ts) Fix Xendit Ewallet prop declaration
stanleynguyen Dec 30, 2019
36dbbcb
chore(changelog) Add project CHANGELOG.md
stanleynguyen Jan 3, 2020
bb9287c
feat(ewallet) Improve ewallet validation guard
stanleynguyen Jan 3, 2020
ce3e5de
(refactor) Remove ewallet from integration tests
stanleynguyen Jan 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ For PCI compliance to be maintained, tokenization of credt cards info should be
+ [Methods](#methods-4)
* [Payout Services](#payout-services)
+ [Methods](#methods-5)
* [EWallet Services](#ewallet-services)
+ [Methods](#methods-6)
- [Contributing](#contributing)

<!-- tocstop -->
Expand Down Expand Up @@ -516,6 +518,60 @@ p.getPayout(data: { id: string })
p.voidPayout(data: { id: string })
```

### EWallet Services

Instanitiate EWallet service using constructor that has been injected with Xendit keys

```js
const { EWallet } = x;
const ewalletSpecificOptions = {};
const ew = new EWallet(ewalletSpecificOptions);
```

Example: Create an ewallet payment

```js
ew.createPayment({
externalID: 'my-ovo-payment',
amount: 1,
phone: '081234567890',
ewalletType: EWallet.EWalletType.OVO,
})
.then(r => {
console.log('create ewallet payment detail:', r);
return r;
})
```

#### Methods

- Create an ewallet payment
```ts
ew.createPayment(data: {
externalID: string;
amount: number;
phone?: string;
expirationDate?: Date;
callbackURL?: string;
redirectURL?: string;
items?: Array<{
id: string;
name: string;
price: number;
quantity: number;
}>;
ewalletType: CreateSupportWalletTypes;
})
```

- Get an ewallet Payment Status
```ts
ew.getPayment(data: {
externalID: string:
ewalletType: GetSupportWalletTypes;
})
```

## Contributing

Running test suite
Expand Down
29 changes: 29 additions & 0 deletions examples/ewallet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const x = require('./xendit');

const EWallet = x.EWallet;
const ew = new EWallet({});

ew.createPayment({
externalID: new Date(),
amount: 1,
phone: '081234567890',
ewalletType: EWallet.EWalletType.OVO,
})
.then(r => {
console.log('create payment detail:', r); // eslint-disable-line no-console
return r;
})
.then(({ external_id, ewallet_type }) =>
ew.ovo.getPaymentStatusByExtID({
externalID: external_id,
ewalletType: ewallet_type,
}),
)
.then(r => {
console.log('EWallet payment detail:', r); // eslint-disable-line no-console
return r;
})
.catch(e => {
console.error(e); // eslint-disable-line no-console
process.exit(1);
});
26 changes: 26 additions & 0 deletions integration_test/ewallet.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const x = require('./xendit.test');

const { EWallet } = x;
const ew = new EWallet({});

module.exports = function() {
return ew
.createPayment({
externalID: Date.now().toString(),
amount: 11000,
expirationDate: '2020-02-20T00:00:00.000Z',
callbackURL: 'https://my-shop.com/callbacks',
redirectURL: 'https://my-shop.com/home',
ewalletType: EWallet.EWalletType.Dana,
})
.then(r =>
ew.getPayment({
externalID: r.external_id,
ewalletType: r.ewallet_type,
}),
)
.then(() => {
// eslint-disable-next-line no-console
console.log('EWallet integration test done...');
});
};
1 change: 1 addition & 0 deletions integration_test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Promise.all([
require('./va.test')(),
require('./payout.test')(),
require('./recurring.test')(),
require('./ewallet.test')(),
])
.then(() => {
// eslint-disable-next-line no-console
Expand Down
45 changes: 45 additions & 0 deletions src/ewallet/ewallet.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { XenditOptions } from '../xendit_opts';

enum CreateSupportWalletTypes {
OVO = 'OVO',
Dana = 'DANA',
Linkaja = 'LINKAJA',
}

enum GetSupportWalletTypes {
OVO = 'OVO',
Dana = 'DANA',
}

interface PaymentItem {
id: string;
name: string;
price: number;
quantity: number;
}

export = class EWallet {
constructor({});
static _constructorWithInjectedXenditOpts: (
opts: XenditOptions,
) => typeof EWallet;
static EwalletType: {
OVO: string;
Dana: string;
LinkAja: string;
};
createPayment(data: {
externalID: string;
amount: number;
phone?: string;
expirationDate?: Date;
callbackURL?: string;
redirectURL?: string;
items?: PaymentItem[];
ewalletType: CreateSupportWalletTypes;
}): Promise<object>;
getPayment(data: {
externalID: string;
ewalletType: GetSupportWalletTypes;
}): Promise<object>;
};
110 changes: 110 additions & 0 deletions src/ewallet/ewallet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
const {
promWithJsErr,
Auth,
Validate,
fetchWithHTTPErr,
queryStringWithoutUndefined,
} = require('../utils');

const EWALLET_PATH = '/ewallets';

function EWallet(options) {
let aggOpts = options;
if (EWallet._injectedOpts && Object.keys(EWallet._injectedOpts).length > 0) {
aggOpts = Object.assign({}, options, EWallet._injectedOpts);
}

this.opts = aggOpts;
this.API_ENDPOINT = this.opts.xenditURL + EWALLET_PATH;
}

EWallet._injectedOpts = {};
EWallet._constructorWithInjectedXenditOpts = function(options) {
EWallet._injectedOpts = options;
return EWallet;
};
EWallet.EWalletType = {
OVO: 'OVO',
Dana: 'DANA',
LinkAja: 'LINKAJA',
};

EWallet.prototype.createPayment = function(data) {
return promWithJsErr((resolve, reject) => {
let compulsoryFields = ['ewalletType'];

if (data.ewalletType) {
switch (data.ewalletType) {
case 'OVO':
compulsoryFields = ['externalID', 'amount', 'phone', 'ewalletType'];
break;
case 'DANA':
compulsoryFields = [
'externalID',
'amount',
'callbackURL',
'redirectURL',
'ewalletType',
];
break;
case 'LINKAJA':
compulsoryFields = [
'externalID',
'phone',
'amount',
'items',
'callbackURL',
'redirectURL',
'ewalletType',
];
break;
}
}

Validate.rejectOnMissingFields(compulsoryFields, data, reject);

fetchWithHTTPErr(this.API_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: Auth.basicAuthHeader(this.opts.secretKey),
},
body: JSON.stringify({
external_id: data.externalID,
amount: data.amount,
phone: data.phone,
expiration_date: data.expirationDate,
callback_url: data.callbackURL,
redirect_url: data.redirectURL,
items: data.items,
ewallet_type: data.ewalletType,
}),
})
.then(resolve)
.catch(reject);
});
};

EWallet.prototype.getPayment = function(data) {
return promWithJsErr((resolve, reject) => {
Validate.rejectOnMissingFields(['externalID', 'ewalletType'], data, reject);

const queryStr = data
? queryStringWithoutUndefined({
external_id: data.externalID,
ewallet_type: data.ewalletType,
})
: '';

fetchWithHTTPErr(`${this.API_ENDPOINT}?${queryStr}`, {
method: 'GET',
headers: {
Authorization: Auth.basicAuthHeader(this.opts.secretKey),
},
})
.then(resolve)
.catch(reject);
});
};

module.exports = EWallet;
3 changes: 3 additions & 0 deletions src/ewallet/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const EWalletService = require('./ewallet');

module.exports = { EWalletService };
2 changes: 2 additions & 0 deletions src/xendit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { InvoiceService } from './invoice';
import { PayoutService } from './payout';
import { RecurringPayment } from './recurring';
import { XenditOptions } from './xendit_opts';
import { EWalletService } from './ewallet';

export = class Xendit {
constructor(opts: XenditOptions);
Expand All @@ -16,4 +17,5 @@ export = class Xendit {
Invoice: typeof InvoiceService;
Payout: typeof PayoutService;
RecurringPayment: typeof RecurringPayment;
EWalletService: typeof EWalletService;
};
2 changes: 2 additions & 0 deletions src/xendit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { DisbursementService } = require('./disbursement');
const { InvoiceService } = require('./invoice');
const { PayoutService } = require('./payout');
const { RecurringPayment } = require('./recurring');
const { EWalletService } = require('./ewallet');
const Errors = require('./errors');

function Xendit(options) {
Expand All @@ -27,6 +28,7 @@ function Xendit(options) {
this.RecurringPayment = RecurringPayment._constructorWithInjectedXenditOpts(
this.opts,
);
this.EWallet = EWalletService._constructorWithInjectedXenditOpts(this.opts);
}

Xendit.Errors = Errors;
Expand Down
54 changes: 54 additions & 0 deletions test/ewallet/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const OVO_EWALLET_TYPE = 'OVO';
const DANA_EWALLET_TYPE = 'DANA';
const LINKAJA_EWALLET_TYPE = 'LINKAJA';

const EXT_ID = '123';
const PHONE = '081234567890';
const AMOUNT = 10000;
const CALLBACK_URL = 'https://yourwebsite.com/callback';
const REDIRECT_URL = 'https://yourwebsite.com/order/123';
const ITEMS = [
{
id: '123123',
name: 'Phone Case',
price: 100000,
quantity: 1,
},
{
id: '345678',
name: 'Powerbank',
price: 200000,
quantity: 1,
},
];

const VALID_CREATE_OVO_RESPONSE = {
transaction_date: String(new Date()),
amount: AMOUNT,
external_id: EXT_ID,
ewallet_type: OVO_EWALLET_TYPE,
business_id: '12121212',
};

const VALID_GET_OVO_PAYMENT_STATUS_RESPONSE = {
external_id: EXT_ID,
amount: AMOUNT,
transaction_date: String(new Date()),
business_id: '12121212',
ewallet_type: OVO_EWALLET_TYPE,
status: 'COMPLETED',
};

module.exports = {
OVO_EWALLET_TYPE,
DANA_EWALLET_TYPE,
LINKAJA_EWALLET_TYPE,
EXT_ID,
PHONE,
AMOUNT,
CALLBACK_URL,
REDIRECT_URL,
ITEMS,
VALID_CREATE_OVO_RESPONSE,
VALID_GET_OVO_PAYMENT_STATUS_RESPONSE,
};
Loading