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 43 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
143 changes: 143 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@ This library is the abstraction of Xendit API for access from applications writt
**Note**: This library is only meant for usage from server-side with Xendit secret API key.
For PCI compliance to be maintained, tokenization of credt cards info should be done on client side with [Xendit.js](https://docs.xendit.co/xenpayments/payments-credit-cards-overview/credit-cards-integration-and-testing/collecting-card-details-tokenization/index.html).

<!-- toc depthFrom:2 -->

- [API Documentation](#api-documentation)
- [Installation](#installation)
- [Usage](#usage)
* [Card Services](#card-services)
+ [Methods](#methods)
* [Virtual Account Services](#virtual-account-services)
+ [Methods](#methods-1)
* [Disbursement Services](#disbursement-services)
+ [Methods](#methods-2)
* [Invoice Services](#invoice-services)
+ [Methods](#methods-3)
* [EWallet Services](#ewallet-services)
+ [OVO](#ovo)
- [Methods](#methods-4)
+ [Dana](#dana)
- [Methods](#methods-5)
+ [LinkAja](#linkaja)
- [Methods](#methods-6)
- [Contributing](#contributing)

<!-- toc -->

- [API Documentation](#api-documentation)
Expand All @@ -18,6 +40,13 @@ For PCI compliance to be maintained, tokenization of credt cards info should be
+ [Methods](#methods-2)
* [Invoice Services](#invoice-services)
+ [Methods](#methods-3)
* [EWallet Services](#ewallet-services)
+ [OVO](#ovo)
+ [Methods](#methods-4)
+ [Dana](#dana)
+ [Methods](#methods-5)
+ [LinkAja](#linkaja)
+ [Methods](#methods-6)
- [Contributing](#contributing)

<!-- tocstop -->
Expand Down Expand Up @@ -399,6 +428,120 @@ i.getAllInvoices(data?: {
})
```

### EWallet Services

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

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

- #### OVO

Example: Create an OVO payment

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

#### Methods

- Create an OVO payment
```ts
ew.ovo.createPayment(data: {
externalID: string;
amount: number;
phone: string;
})
```

- Get an OVO Payment Status
```ts
ew.ovo.getPaymentStatusByExtID(data: { externalID: string })
```

- #### Dana

Example: Create a dana payment

```js
ew.dana.createPayment({
externalID: 'my-dana-payment',
amount: 1,
callbackURL: 'https://my-shop.com/callbacks',
redirectURL: 'https://my-shop.com/home',
})
.then(r => {
console.log('create Dana payment detail:', r);
return r;
})
```

#### Methods

- Create an Dana payment
```ts
ew.dana.createPayment(data: {
externalID: string;
amount: number;
expirationDate?: string;
callbackURL: string;
redirectURL: string;
})
```

- #### LinkAja

Example: Create a linkAja payment

```js
ew.linkaja.createPayment({
externalID: 'my-linkaja-payment',
phone: '081234567890',
amount: 30000,
items: [
{
id: '123123',
name: 'Phone Case',
price: 100000,
quantity: 1,
},
{
id: '345678',
name: 'Powerbank',
price: 200000,
quantity: 1,
},
],
callbackURL: 'https://yourwebsite.com/callback',
redirectURL: 'https://yourwebsite.com/home',
})
```

#### Methods

- Create an Dana payment
```ts
ew.linkaja.createPayment(data: {
externalID: string;
phone: string;
amount: number;
items: paymentItem[];
callbackURL: string;
redirectURL: string;
})
```

## Contributing

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

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

ew.ovo
.createPayment({
externalID: new Date(),
amount: 1,
phone: '081234567890',
})
.then(r => {
console.log('create OVO payment detail:', r); // eslint-disable-line no-console
return r;
})
.then(({ external_id }) =>
ew.ovo.getPaymentStatusByExtID({ externalID: external_id }),
)
.then(r => {
console.log('OVO payment status detail:', r); // eslint-disable-line no-console
return r;
})
.catch(e => {
console.error(e); // eslint-disable-line no-console
process.exit(1);
});

ew.dana
.createPayment({
externalID: new Date(),
amount: 1,
callbackURL: 'https://my-shop.com/callbacks',
redirectURL: 'https://my-shop.com/home',
})
.then(r => {
console.log('create dana payment detail:', r); // eslint-disable-line no-console
return r;
})
.then(({ external_id }) =>
ew.dana.getPaymentStatusByExtID({ externalID: external_id }),
)
.then(r => {
console.log('Dana payment status detail:', r); // eslint-disable-line no-console
return r;
})
.catch(e => {
console.error(e); // eslint-disable-line no-console
process.exit(1);
});

ew.linkaja
.createPayment({
externalID: new Date(),
phone: '081234567890',
amount: 30000,
items: [
{
id: '123123',
name: 'Phone Case',
price: 100000,
quantity: 1,
},
{
id: '345678',
name: 'Powerbank',
price: 200000,
quantity: 1,
},
],
callbackURL: 'https://yourwebsite.com/callback',
redirectURL: 'https://yourwebsite.com/home',
})
.then(r => {
console.log('create linkAja payment detail:', r); // eslint-disable-line no-console
return r;
})
.catch(e => {
console.error(e); // eslint-disable-line no-console
process.exit(1);
});
17 changes: 17 additions & 0 deletions integration_test/ewallet.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const x = require('./xendit.test');

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

module.exports = function() {
return e
.createOVOPayment({
externalID: Date.now().toString(),
phone: '081234567890',
amount: 100000,
})
.then(() => {
// eslint-disable-next-line no-console
console.log('Invoice integration test done...');
});
};
17 changes: 17 additions & 0 deletions src/ewallet/dana.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { EWalletOptions } from './ewallet_opts';

export = class OVO {
constructor({});
static _constructorWithInjectedEWalletOpts: (
opts: EWalletOptions,
) => typeof OVO;
createPayment(data: {
externalID: string;
amount: number;
expirationDate?: string;
callbackURL: string;
redirectURL: string;
}): Promise<object>;
getPaymentStatusByExtID(data: { externalID: string }): Promise<object>;
};

67 changes: 67 additions & 0 deletions src/ewallet/dana.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const { Validate, Auth, fetchWithHTTPErr, promWithJsErr } = require('../utils');

const DANA_EWALLET_PATH = '';

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

this.opts = aggOpts;
this.API_ENDPOINT = this.opts.eWalletURL + DANA_EWALLET_PATH;
this.EWALLET_TYPE = 'DANA';
}

Dana._injectedOpts = {};
Dana._constructorWithInjectedEWalletOpts = function(options) {
Dana._injectedOpts = options;
return Dana;
};

Dana.prototype.createPayment = function(data) {
return promWithJsErr((resolve, reject) => {
Validate.rejectOnMissingFields(
['externalID', 'amount', 'callbackURL', 'redirectURL'],
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,
expiration_date: data.expirationDate,
callback_url: data.callbackURL,
redirect_url: data.redirectURL,
ewallet_type: this.EWALLET_TYPE,
}),
})
.then(resolve)
.catch(reject);
});
};

Dana.prototype.getPaymentStatusByExtID = function(data) {
return promWithJsErr((resolve, reject) => {
Validate.rejectOnMissingFields(['externalID'], data, reject);
fetchWithHTTPErr(
`${this.API_ENDPOINT}?external_id=${data.externalID}&ewallet_type=${this.EWALLET_TYPE}`,
{
method: 'GET',
headers: {
Authorization: Auth.basicAuthHeader(this.opts.secretKey),
},
},
)
.then(resolve)
.catch(reject);
});
};

module.exports = Dana;
16 changes: 16 additions & 0 deletions src/ewallet/ewallet.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ovo from './ovo';
import dana from './dana';
import linkaja from './linkaja';
import { XenditOptions } from '../xendit_opts';

export = class EWallet {
constructor({});
static _constructorWithInjectedXenditOpts: (
opts: XenditOptions,
) => typeof EWallet;

ovo: typeof ovo;
createDanaPayment = dana.createPayment;
getDanaPaymentStatusByExtID = dana.getByExtID;
createLinkAjaPayment = linkaja.createPayment;
};
31 changes: 31 additions & 0 deletions src/ewallet/ewallet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const OVO = require('./ovo');
const Dana = require('./dana');
const LinkAja = require('./linkaja');

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.opts.eWalletURL = this.opts.xenditURL + EWALLET_PATH;

let ovo = OVO._constructorWithInjectedEWalletOpts(this.opts);
let dana = Dana._constructorWithInjectedEWalletOpts(this.opts);
let linkaja = LinkAja._constructorWithInjectedEWalletOpts(this.opts);

this.ovo = new ovo({});
this.dana = new dana({});
this.linkaja = new linkaja({});
}

EWallet._injectedOpts = {};
EWallet._constructorWithInjectedXenditOpts = function(options) {
EWallet._injectedOpts = options;
return EWallet;
};

module.exports = EWallet;
Loading