Skip to content

Commit

Permalink
New eWallets API (#74)
Browse files Browse the repository at this point in the history
* Implement new eWallets API

* Fix typo

* Change URLs values

* Change business id value

* Update README.md for new ewallet library

* Separate new ewallet endpoints into separate methods

* Update README.md with new ewallet methods

* Add header fields for ewallet

* Update README with header fields in ewallet service
  • Loading branch information
glendaesutanto committed Feb 25, 2021
1 parent 658e81a commit af9273c
Show file tree
Hide file tree
Showing 8 changed files with 418 additions and 30 deletions.
56 changes: 29 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ For PCI compliance to be maintained, tokenization of credit cards info should be
+ [Get a payout](#get-a-payout)
+ [Void a payout](#void-a-payout)
* [EWallet Services](#ewallet-services)
+ [Create an ewallet payment](#create-an-ewallet-payment)
+ [Get an ewallet Payment Status](#get-an-ewallet-payment-status)
+ [Create an ewallet charge](#create-an-ewallet-charge)
+ [Get an ewallet charge status](#get-an-ewallet-charge-status)
* [Balance Services](#balance-services)
+ [Get balance](#get-balance)
* [Retail Outlet Services](#retail-outlet-services)
Expand Down Expand Up @@ -606,48 +606,50 @@ const ewalletSpecificOptions = {};
const ew = new EWallet(ewalletSpecificOptions);
```

Example: Create an ewallet payment
Example: Create an ewallet charge

```js
ew.createPayment({
externalID: 'my-ovo-payment',
amount: 1,
phone: '081234567890',
ewalletType: EWallet.Type.OVO,
ew.createEWalletCharge({
referenceID: 'test-reference-id',
currency: 'IDR',
amount: 50000,
checkoutMethod: 'ONE_TIME_PAYMENT',
channelCode: 'ID_SHOPEEPAY',
channelProperties: {
successRedirectURL: 'https://yourwebsite.com/order/123',
},
}).then(r => {
console.log('create ewallet payment detail:', r);
console.log('created ewallet payment charge:', r);
return r;
});
```

Refer to [Xendit API Reference](https://xendit.github.io/apireference/#ewallets) for more info about methods' parameters

#### Create an ewallet payment
#### Create an ewallet charge

```ts
ew.createPayment(data: {
externalID: string;
ew.createEWalletCharge(data: {
referenceID: string;
currency: Currency;
amount: number;
phone?: string;
expirationDate?: Date;
callbackURL?: string;
redirectURL?: string;
items?: Array<{
id: string;
name: string;
price: number;
quantity: number;
}>;
ewalletType: CreateSupportWalletTypes;
checkoutMethod: string;
channelCode?: ChannelCode;
channelProperties?: OVOChannelProps | PaymayaChannelProps | OtherChannelProps;
customerID?: string;
basket?: Basket[];
metadata?: object;
forUserID?: string;
withFeeRule?: string;
})
```

#### Get an ewallet Payment Status
#### Get an ewallet charge status

```ts
ew.getPayment(data: {
externalID: string:
ewalletType: GetSupportWalletTypes;
ew.getEWalletChargeStatus(data: {
chargeID: string;
forUserID?: string;
})
```

Expand Down
39 changes: 38 additions & 1 deletion examples/with_async/ewallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const ew = new EWallet({});
ewalletType: EWallet.Type.OVO,
});
// eslint-disable-next-line no-console
console.log('create payment detail:', payment);
console.log('created payment detail:', payment);

const retrievedPayment = await ew.getPayment({
externalID: payment.external_id,
Expand All @@ -21,6 +21,43 @@ const ew = new EWallet({});
// eslint-disable-next-line no-console
console.log('EWallet payment detail:', retrievedPayment);

const charge = await ew.createEWalletCharge({
referenceID: 'test-reference-id',
currency: 'IDR',
amount: 1688,
checkoutMethod: 'ONE_TIME_PAYMENT',
channelCode: 'ID_SHOPEEPAY',
channelProperties: {
successRedirectURL: 'https://yourwebsite.com/order/123',
},
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',
},
});
// eslint-disable-next-line no-console
console.log('created ewallet payment charge:', charge);

const retrievedCharge = await ew.getEWalletChargeStatus({
chargeID: charge.id,
});
// eslint-disable-next-line no-console
console.log('retrieved ewallet payment charge:', retrievedCharge);

process.exit(0);
} catch (e) {
console.error(e); // eslint-disable-line no-console
Expand Down
51 changes: 49 additions & 2 deletions examples/with_promises/ewallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ ew.createPayment({
ewalletType: EWallet.Type.OVO,
})
.then(r => {
console.log('create payment detail:', r); // eslint-disable-line no-console
// eslint-disable-next-line no-console
console.log('created payment detail:', r);
return r;
})
.then(({ external_id, ewallet_type }) =>
Expand All @@ -20,7 +21,53 @@ ew.createPayment({
}),
)
.then(r => {
console.log('EWallet payment detail:', r); // eslint-disable-line no-console
// eslint-disable-next-line no-console
console.log('EWallet payment detail:', r);
return r;
})
.then(() =>
ew.createEWalletCharge({
referenceID: 'test-reference-id',
currency: 'IDR',
amount: 1688,
checkoutMethod: 'ONE_TIME_PAYMENT',
channelCode: 'ID_SHOPEEPAY',
channelProperties: {
successRedirectURL: 'https://yourwebsite.com/order/123',
},
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',
},
}),
)
.then(r => {
// eslint-disable-next-line no-console
console.log('created ewallet payment charge:', r);
return r;
})
.then(r =>
ew.getEWalletChargeStatus({
chargeID: r.id,
}),
)
.then(r => {
// eslint-disable-next-line no-console
console.log('retrieved ewallet payment charge:', r);
return r;
})
.catch(e => {
Expand Down
35 changes: 35 additions & 0 deletions integration_test/ewallet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,41 @@ module.exports = function() {
ewalletType: ewallet_type,
}),
)
.then(() =>
ew.createEWalletCharge({
referenceID: 'test-reference-id',
currency: 'IDR',
amount: 1688,
checkoutMethod: 'ONE_TIME_PAYMENT',
channelCode: 'ID_SHOPEEPAY',
channelProperties: {
successRedirectURL: 'https://yourwebsite.com/order/123',
},
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',
},
}),
)
.then(r =>
ew.getEWalletChargeStatus({
chargeID: r.id,
}),
)
.then(() => {
// eslint-disable-next-line no-console
console.log('EWallet integration test done...');
Expand Down
61 changes: 61 additions & 0 deletions src/ewallet/ewallet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,47 @@ interface PaymentItem {
quantity: number;
}

enum Currency {
IDR = 'IDR',
PHP = 'PHP',
}

enum ChannelCode {
ID_OVO = 'ID_OVO',
ID_DANA = 'ID_DANA',
ID_LINKAJA = 'ID_LINKAJA',
ID_SHOPEEPAY = 'ID_SHOPEEPAY',
PH_PAYMAYA = 'PH_PAYMAYA',
}

interface OVOChannelProps {
mobileNumber: string;
}

interface PaymayaChannelProps {
successRedirectURL: string;
failureRedirectURL: string;
cancelRedirectURL: string;
}

interface OtherChannelProps {
successRedirectURL: string;
}

interface Basket {
referenceID: string;
name: string;
category: string;
currency: string;
price: number;
quantity: number;
type: string;
url?: string;
description?: string;
subCategory?: string;
metadata?: object;
}

export = class EWallet {
constructor({});
static _constructorWithInjectedXenditOpts: (
Expand All @@ -43,4 +84,24 @@ export = class EWallet {
externalID: string;
ewalletType: GetSupportWalletTypes;
}): Promise<object>;
createEWalletCharge(data: {
referenceID: string;
currency: Currency;
amount: number;
checkoutMethod: string;
channelCode?: ChannelCode;
channelProperties?:
| OVOChannelProps
| PaymayaChannelProps
| OtherChannelProps;
customerID?: string;
basket?: Basket[];
metadata?: object;
forUserID?: string;
withFeeRule?: string;
}): Promise<object>;
getEWalletChargeStatus(data: {
chargeID: string;
forUserID?: string;
}): Promise<object>;
};
Loading

0 comments on commit af9273c

Please sign in to comment.