xendit-node
Advanced tools
Comparing version 0.3.0 to 1.0.0
# CHANGELOG | ||
## 2020-01-08 | ||
- [#31](https://github.com/xendit/xendit-node/pull/31) Add xendit tracking headers | ||
- [#32](https://github.com/xendit/xendit-node/pull/32) Add examples with async/await | ||
- [#28](https://github.com/xendit/xendit-node/pull/28) Touch up README pre-launch | ||
## 2020-01-07 | ||
- [#30](https://github.com/xendit/xendit-node/pull/30) Remove `publicKey` from options | ||
- [#29](https://github.com/xendit/xendit-node/pull/29) Add linting for ts files into CI | ||
## 2020-01-03 | ||
- [#23](https://github.com/xendit/xendit-node/pull/23) (feature) Balance | ||
- [#24](https://github.com/xendit/xendit-node/pull/24s) (feature) Retail Outlet | ||
## 2019-12-29 | ||
@@ -4,0 +20,0 @@ |
@@ -8,3 +8,2 @@ // For actual usage, this should be require('xendit-node') | ||
const x = new Xendit({ | ||
publicKey: process.env.PUBLIC_KEY, | ||
secretKey: process.env.SECRET_KEY, | ||
@@ -11,0 +10,0 @@ xenditURL: process.env.XENDIT_URL, |
@@ -9,2 +9,4 @@ console.log('Starting integration test...'); // eslint-disable-line no-console | ||
require('./recurring.test')(), | ||
require('./balance.test')(), | ||
require('./retail_outlet.test')(), | ||
]) | ||
@@ -11,0 +13,0 @@ .then(() => { |
@@ -8,3 +8,2 @@ // For actual usage, this should be require('xendit-node') | ||
const x = new Xendit({ | ||
publicKey: process.env.PUBLIC_KEY, | ||
secretKey: process.env.SECRET_KEY, | ||
@@ -11,0 +10,0 @@ xenditURL: process.env.XENDIT_URL, |
{ | ||
"name": "xendit-node", | ||
"version": "0.3.0", | ||
"version": "1.0.0", | ||
"description": "NodeJS client for Xendit API", | ||
@@ -9,4 +9,4 @@ "main": "index.js", | ||
"test:integration": "node integration_test", | ||
"lint": "eslint index.js ./src/**/*.{js,ts}", | ||
"format": "prettier --config .prettierrc --write index.js ./src/**/*.{js,json,ts}", | ||
"lint": "eslint index.js ./**/*.{js,ts}", | ||
"format": "prettier --config .prettierrc --write index.js ./**/*.{js,json,ts}", | ||
"gentoc": "markdown-toc -i README.md", | ||
@@ -13,0 +13,0 @@ "release": "np" |
298
README.md
@@ -5,2 +5,4 @@ # Xendit API Node.js Client | ||
[![NPM](https://nodei.co/npm/xendit-node.png)](https://nodei.co/npm/xendit-node/) | ||
**Note**: This library is only meant for usage from server-side with Xendit secret API key. | ||
@@ -15,15 +17,44 @@ 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). | ||
* [Card Services](#card-services) | ||
+ [Methods](#methods) | ||
+ [Create charge](#create-charge) | ||
+ [Capture charge](#capture-charge) | ||
+ [Get charge](#get-charge) | ||
+ [Create authorization](#create-authorization) | ||
+ [Reverse authorization](#reverse-authorization) | ||
+ [Create refund](#create-refund) | ||
* [Virtual Account Services](#virtual-account-services) | ||
+ [Methods](#methods-1) | ||
+ [Get banks with available virtual account service](#get-banks-with-available-virtual-account-service) | ||
+ [Create a fixed virtual account](#create-a-fixed-virtual-account) | ||
+ [Get details of your fixed virtual account](#get-details-of-your-fixed-virtual-account) | ||
+ [Update details of your fixed virtual account](#update-details-of-your-fixed-virtual-account) | ||
+ [Get details of a VA payment](#get-details-of-a-va-payment) | ||
* [Disbursement Services](#disbursement-services) | ||
+ [Methods](#methods-2) | ||
+ [Get banks with available disbursement service](#get-banks-with-available-disbursement-service) | ||
+ [Create a disbursement](#create-a-disbursement) | ||
+ [Create a batch of disbursements](#create-a-batch-of-disbursements) | ||
+ [Get a disbursement by ID](#get-a-disbursement-by-id) | ||
* [Invoice Services](#invoice-services) | ||
+ [Methods](#methods-3) | ||
+ [Create an invoice](#create-an-invoice) | ||
+ [Get an invoice](#get-an-invoice) | ||
+ [Expire an invoice](#expire-an-invoice) | ||
+ [Get all invoices](#get-all-invoices) | ||
* [Recurring Payments Services](#recurring-payments-services) | ||
+ [Methods](#methods-4) | ||
+ [Create recurring payment](#create-recurring-payment) | ||
+ [Get recurring payment](#get-recurring-payment) | ||
+ [Edit recurring payment](#edit-recurring-payment) | ||
+ [Stop recurring payment](#stop-recurring-payment) | ||
+ [Pause recurring payment](#pause-recurring-payment) | ||
+ [Resume recurring payment](#resume-recurring-payment) | ||
* [Payout Services](#payout-services) | ||
+ [Methods](#methods-5) | ||
+ [Create a payout](#create-a-payout) | ||
+ [Get a payout](#get-a-payout) | ||
+ [Void a payout](#void-a-payout) | ||
* [EWallet Services](#ewallet-services) | ||
+ [Methods](#methods-6) | ||
+ [Create an ewallet payment](#create-an-ewallet-payment) | ||
+ [Get an ewallet Payment Status](#get-an-ewallet-payment-status) | ||
* [Balance Services](#balance-services) | ||
+ [Get balance](#get-balance) | ||
* [Retail Outlet Services](#retail-outlet-services) | ||
+ [Create fixed payment code](#create-fixed-payment-code) | ||
+ [Get fixed payment code](#get-fixed-payment-code) | ||
+ [Update fixed payment code](#update-fixed-payment-code) | ||
- [Contributing](#contributing) | ||
@@ -45,4 +76,2 @@ | ||
For the full documentation, please refer to [Xendit Node Client Docs](https://docs.xendit.co/en/libraries/xendit-node) | ||
Configure package with your account's API keys | ||
@@ -53,3 +82,2 @@ | ||
const x = new Xendit({ | ||
publicKey: 'xnd_public...', | ||
secretKey: 'xnd_...', | ||
@@ -59,2 +87,7 @@ }); | ||
Usage examples: | ||
- With promises, please check [here](./examples/with_promises) | ||
- With async/await, please check [here](./examples/with_async) | ||
### Card Services | ||
@@ -86,5 +119,5 @@ | ||
#### Methods | ||
Refer to [Xendit API Reference](https://xendit.github.io/apireference/#credit-cards) for more info about methods' parameters | ||
- Create charge | ||
#### Create charge | ||
@@ -103,3 +136,3 @@ ```ts | ||
- Capture charge | ||
#### Capture charge | ||
@@ -113,3 +146,3 @@ ```ts | ||
- Get charge | ||
#### Get charge | ||
@@ -120,3 +153,3 @@ ```ts | ||
- Create authorization | ||
#### Create authorization | ||
@@ -134,3 +167,3 @@ ```ts | ||
- Reverse authorization | ||
#### Reverse authorization | ||
@@ -144,3 +177,3 @@ ```ts | ||
- Create refund | ||
#### Create refund | ||
@@ -182,5 +215,5 @@ ```ts | ||
#### Methods | ||
Refer to [Xendit API Reference](https://xendit.github.io/apireference/#virtual-accounts) for more info about methods' parameters | ||
- Get banks with available virtual account service | ||
#### Get banks with available virtual account service | ||
@@ -191,3 +224,3 @@ ```ts | ||
- Create a fixed virtual account | ||
#### Create a fixed virtual account | ||
@@ -209,3 +242,3 @@ ```ts | ||
- Get details of your fixed virtual account | ||
#### Get details of your fixed virtual account | ||
@@ -216,3 +249,3 @@ ```ts | ||
- Update details of your fixed virtual account | ||
#### Update details of your fixed virtual account | ||
@@ -230,3 +263,3 @@ ```ts | ||
- Get details of a VA payment | ||
#### Get details of a VA payment | ||
@@ -268,5 +301,5 @@ ```ts | ||
#### Methods | ||
Refer to [Xendit API Reference](https://xendit.github.io/apireference/#disbursements) for more info about methods' parameters | ||
- Get banks with available disbursement service | ||
#### Get banks with available disbursement service | ||
@@ -277,3 +310,3 @@ ```ts | ||
- Create a disbursement | ||
#### Create a disbursement | ||
@@ -295,3 +328,3 @@ ```ts | ||
- Create a batch of disbursements | ||
#### Create a batch of disbursements | ||
@@ -316,3 +349,3 @@ ```ts | ||
- Get a disbursement by ID | ||
#### Get a disbursement by ID | ||
@@ -352,24 +385,24 @@ ```ts | ||
#### Methods | ||
Refer to [Xendit API Reference](https://xendit.github.io/apireference/#invoices) for more info about methods' parameters | ||
- Create an invoice | ||
#### Create an invoice | ||
```ts | ||
i.createInvoice(data: { | ||
externalID: string; | ||
payerEmail: string; | ||
description: string; | ||
amount: number; | ||
shouldSendEmail?: boolean; | ||
callbackVirtualAccountID?: string; | ||
invoiceDuration?: number; | ||
successRedirectURL?: string; | ||
failureRedirectURL?: string; | ||
paymentMethods?: string[]; | ||
currency?: string; | ||
midLabel?: string; | ||
}) | ||
externalID: string; | ||
payerEmail: string; | ||
description: string; | ||
amount: number; | ||
shouldSendEmail?: boolean; | ||
callbackVirtualAccountID?: string; | ||
invoiceDuration?: number; | ||
successRedirectURL?: string; | ||
failureRedirectURL?: string; | ||
paymentMethods?: string[]; | ||
currency?: string; | ||
midLabel?: string; | ||
}) | ||
``` | ||
- Get an invoice | ||
#### Get an invoice | ||
@@ -380,3 +413,3 @@ ```ts | ||
- Expire an invoice | ||
#### Expire an invoice | ||
@@ -387,20 +420,20 @@ ```ts | ||
- Get all invoices | ||
#### Get all invoices | ||
```ts | ||
i.getAllInvoices(data?: { | ||
statuses?: string[]; | ||
limit?: number; | ||
createdAfter?: Date; | ||
createdBefore?: Date; | ||
paidAfter?: Date; | ||
paidBefore?: Date; | ||
expiredAfter?: Date; | ||
expiredBefore?: Date; | ||
lastInvoiceID?: string; | ||
clientTypes?: string[]; | ||
paymentChannels?: string[]; | ||
onDemandLink?: string; | ||
recurringPaymentID?: string; | ||
}) | ||
statuses?: string[]; | ||
limit?: number; | ||
createdAfter?: Date; | ||
createdBefore?: Date; | ||
paidAfter?: Date; | ||
paidBefore?: Date; | ||
expiredAfter?: Date; | ||
expiredBefore?: Date; | ||
lastInvoiceID?: string; | ||
clientTypes?: string[]; | ||
paymentChannels?: string[]; | ||
onDemandLink?: string; | ||
recurringPaymentID?: string; | ||
}) | ||
``` | ||
@@ -439,5 +472,5 @@ | ||
#### Methods | ||
Refer to [Xendit API Reference](https://xendit.github.io/apireference/#recurring-payments) for more info about methods' parameters | ||
- Create recurring payment | ||
#### Create recurring payment | ||
@@ -462,12 +495,12 @@ ```ts | ||
chargeImmediately?: boolean; | ||
}): Promise<object>; | ||
}) | ||
``` | ||
- Get recurring payment | ||
#### Get recurring payment | ||
```ts | ||
rp.getPayment(data: { id: string }): Promise<object>; | ||
rp.getPayment(data: { id: string }) | ||
``` | ||
- Edit recurring payment | ||
#### Edit recurring payment | ||
@@ -484,21 +517,21 @@ ```ts | ||
missedPaymentAction?: Action; | ||
}): Promise<object>; | ||
}) | ||
``` | ||
- Stop recurring payment | ||
#### Stop recurring payment | ||
```ts | ||
rp.stopPayment(data: { id: string }): Promise<object>; | ||
rp.stopPayment(data: { id: string }) | ||
``` | ||
- Pause recurring payment | ||
#### Pause recurring payment | ||
```ts | ||
rp.pausePayment(data: { id: string }): Promise<object>; | ||
rp.pausePayment(data: { id: string }) | ||
``` | ||
- Resume recurring payment | ||
#### Resume recurring payment | ||
```ts | ||
rp.resumePayment(data: { id: string }): Promise<object>; | ||
rp.resumePayment(data: { id: string }) | ||
``` | ||
@@ -527,5 +560,5 @@ | ||
#### Methods | ||
Refer to [Xendit API Reference](https://xendit.github.io/apireference/#payouts) for more info about methods' parameters | ||
- Create a payout | ||
#### Create a payout | ||
@@ -536,3 +569,3 @@ ```ts | ||
- Get a payout | ||
#### Get a payout | ||
@@ -543,3 +576,3 @@ ```ts | ||
- Void a payout | ||
#### Void a payout | ||
@@ -564,16 +597,16 @@ ```ts | ||
ew.createPayment({ | ||
externalID: 'my-ovo-payment', | ||
amount: 1, | ||
phone: '081234567890', | ||
ewalletType: EWallet.Type.OVO, | ||
}) | ||
.then(r => { | ||
console.log('create ewallet payment detail:', r); | ||
return r; | ||
}) | ||
externalID: 'my-ovo-payment', | ||
amount: 1, | ||
phone: '081234567890', | ||
ewalletType: EWallet.Type.OVO, | ||
}).then(r => { | ||
console.log('create ewallet payment detail:', r); | ||
return r; | ||
}); | ||
``` | ||
#### Methods | ||
Refer to [Xendit API Reference](https://xendit.github.io/apireference/#ewallets) for more info about methods' parameters | ||
- Create an ewallet payment | ||
#### Create an ewallet payment | ||
```ts | ||
@@ -597,3 +630,4 @@ ew.createPayment(data: { | ||
- Get an ewallet Payment Status | ||
#### Get an ewallet Payment Status | ||
```ts | ||
@@ -606,2 +640,86 @@ ew.getPayment(data: { | ||
### Balance Services | ||
Instanitiate Balance service using constructor that has been injected with Xendit keys | ||
```js | ||
const { Balance } = x; | ||
const balanceSpecificOptions = {}; | ||
const i = new Balance(balanceSpecificOptions); | ||
``` | ||
Example: Get balance of holding account | ||
```js | ||
b.getBalance({ | ||
accountType: Balance.AccountType.Holding, | ||
}).then(({ balance }) => { | ||
console.log('Holding balance amount:', balance); | ||
}); | ||
``` | ||
Refer to [Xendit API Reference](https://xendit.github.io/apireference/#balances) for more info about methods' parameters | ||
#### Get balance | ||
```ts | ||
b.getBalance(data: { accountType: AccountType }) | ||
``` | ||
### Retail Outlet Services | ||
Instanitiate Retail outlet service using constructor that has been injected with Xendit keys | ||
```js | ||
const { RetailOutlet } = x; | ||
const retailOutletSpecificOptions = {}; | ||
const ro = new RetailOutlet(retailOutletSpecificOptions); | ||
``` | ||
Example: Example: Create a fixed payment code | ||
```js | ||
ro.createFixedPaymentCode({ | ||
externalID: '123', | ||
retailOutletName: 'ALFAMART', | ||
name: 'Ervan Adetya', | ||
expectedAmt: 10000, | ||
}).then(({ id }) => { | ||
console.log(`Fixed Payment Code created with ID: ${id}`); | ||
}); | ||
``` | ||
Refer to [Xendit API Reference](https://xendit.github.io/apireference/#retail-outlets) for more info about methods' parameters | ||
#### Create fixed payment code | ||
```ts | ||
ro.createFixedPaymentCode(data: { | ||
externalID: string; | ||
retailOutletName: string; | ||
name: string; | ||
expectedAmt: number; | ||
paymentCode?: string; | ||
expirationDate?: Date; | ||
isSingleUse?: boolean; | ||
}) | ||
``` | ||
#### Get fixed payment code | ||
```ts | ||
ro.getFixedPaymentCode(data: { id: string }) | ||
``` | ||
#### Update fixed payment code | ||
```ts | ||
ro.updateFixedPaymentCode(data: { | ||
id: string | ||
name?: string; | ||
expectedAmt?: number; | ||
expirationDate?: Date; | ||
}) | ||
``` | ||
## Contributing | ||
@@ -625,1 +743,3 @@ | ||
Please make sure they pass before making commits/pushes. | ||
For any requests, bug or comments, please [open an issue](https://github.com/xendit/xendit-node/issues) or [submit a pull request](https://github.com/xendit/xendit-node/pulls). |
@@ -1,4 +0,5 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
function f(args: any): Promise<object>; | ||
import { RequestInit } from 'node-fetch'; | ||
function f(endpointURL: string, opts: RequestInit): Promise<object>; | ||
export = f; |
const fetch = require('node-fetch'); | ||
module.exports = function() { | ||
const _args = arguments; | ||
module.exports = function(endpointURL, opts) { | ||
return new Promise((resolve, reject) => { | ||
try { | ||
fetch(..._args) | ||
opts.headers = injectTrackingHeaders(opts.headers); | ||
fetch(endpointURL, opts) | ||
.then(res => { | ||
@@ -31,1 +30,12 @@ if (res.status < 200 || res.status > 299) { | ||
}; | ||
const clientVersion = require('../../package.json').version; | ||
function injectTrackingHeaders(headers) { | ||
// Making this function pure - not affecting the original headers object | ||
// This assignment also handles undefined/null values of headers arg | ||
const injectedHeaders = Object.assign({}, headers); | ||
injectedHeaders['xendit-lib'] = 'node'; | ||
injectedHeaders['xendit-lib-ver'] = clientVersion; | ||
return injectedHeaders; | ||
} |
export interface XenditOptions { | ||
publicKey: string; | ||
secretKey: string; | ||
xenditURL?: string; | ||
} |
@@ -10,2 +10,4 @@ import Errors from './errors'; | ||
import { EWalletService } from './ewallet'; | ||
import { BalanceServices } from './balance'; | ||
import { RetailOutletService } from './retail_outlet'; | ||
@@ -22,2 +24,4 @@ export = class Xendit { | ||
EWallet: typeof EWalletService; | ||
Balance: typeof BalanceServices; | ||
RetailOutlet: typeof RetailOutletService; | ||
}; |
@@ -8,2 +8,4 @@ const { CardService } = require('./card'); | ||
const { EWalletService } = require('./ewallet'); | ||
const { BalanceServices } = require('./balance'); | ||
const { RetailOutletService } = require('./retail_outlet'); | ||
const Errors = require('./errors'); | ||
@@ -13,3 +15,2 @@ | ||
let { | ||
publicKey, // customer's public API key | ||
secretKey, // customer's secret API key | ||
@@ -22,3 +23,3 @@ xenditURL, // should there be a need to override API base URL | ||
this.opts = { publicKey, secretKey, xenditURL }; | ||
this.opts = { secretKey, xenditURL }; | ||
this.Card = CardService._constructorWithInjectedXenditOpts(this.opts); | ||
@@ -35,2 +36,6 @@ this.VirtualAcc = VAService._constructorWithInjectedXenditOpts(this.opts); | ||
this.EWallet = EWalletService._constructorWithInjectedXenditOpts(this.opts); | ||
this.Balance = BalanceServices._constructorWithInjectedXenditOpts(this.opts); | ||
this.RetailOutlet = RetailOutletService._constructorWithInjectedXenditOpts( | ||
this.opts, | ||
); | ||
} | ||
@@ -37,0 +42,0 @@ |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
92533
99
2336
0
713
4