This library is the abstraction of Xendit API for access from applications written with server-side Javascript.
Note: This library is only meant for usage from server-side with Xendit secret API key. For PCI compliance to be maintained, tokenization of credit cards info should be done on client side with Xendit.js.
- API Documentation
- Installation
- Usage
- Contributing
Please check Xendit API Reference.
npm install --save xendit-node
Configure package with your account's secret key obtained from your Xendit Dashboard.
const Xendit = require('xendit-node');
const x = new Xendit({
secretKey: 'xnd_...',
});
Usage examples:
Instanitiate Card service using constructor that has been injected with Xendit keys
const { Card } = x;
const cardSpecificOptions = {};
const card = new Card(cardSpecificOptions);
Example: Capturing a charge
card
.captureCharge({
chargeID: 'charge-id-from-create-charge-endpoint',
externalID: 'your-system-tracking-id',
})
.then(({ id }) => {
console.log(`Charge created with ID: ${id}`);
})
.catch(e => {
console.error(`Charge creation failed with message: ${e.message}`);
});
Refer to Xendit API Reference for more info about methods' parameters
card.createCharge(data: {
tokenID: string;
externalID: string;
amount?: number;
authID?: string;
cardCVN?: string;
capture?: boolean;
descriptor?: string;
})
card.captureCharge(data: {
chargeID: string;
amount: number;
})
card.getCharge(data: { chargeID: string })
card.createAuthorization(data: {
tokenID: string;
externalID: string;
amount?: number;
authID?: string;
cardCVN?: string;
descriptor?: string;
})
card.reverseAuthorization(data: {
chargeID: string;
externalID: string;
})
card.createRefund(data: {
chargeID: string;
amount: number;
externalID: string;
xIdempotencyKey?: string;
})
Instanitiate VA service using constructor that has been injected with Xendit keys
const { VirtualAcc } = x;
const vaSpecificOptions = {};
const va = new VirtualAcc(vaSpecificOptions);
Example: Create a fixed virtual account
va.createFixedVA({
externalID: 'your-external-id',
bankCode: 'BCA',
name: 'Stanley Nguyen',
})
.then(({ id }) => {
console.log(`Fixed VA created with ID: ${id}`);
})
.catch(e => {
console.error(`VA creation failed with message: ${e.message}`);
});
Refer to Xendit API Reference for more info about methods' parameters
va.getVABanks();
va.createFixedVA(data: {
externalID: string;
bankCode: string;
name: string;
virtualAccNumber?: string;
suggestedAmt?: number;
isClosed?: boolean;
expectedAmt?: number;
expirationDate?: Date;
isSingleUse?: boolean;
description?: string;
})
va.getFixedVA(data: { id: string })
va.updateFixedVA(data: {
id: string;
suggestedAmt?: number;
expectedAmt?: number;
expirationDate?: Date;
isSingleUse?: boolean;
description?: string;
})
va.getVAPayment(data: { paymentID: string })
paymentID
: ID of the payment that you obtained from your callback
Instanitiate Disbursement service using constructor that has been injected with Xendit keys
const { Disbursement } = x;
const disbursementSpecificOptions = {};
const d = new Disbursement(disbursementSpecificOptions);
Example: Create a disbursement
d.create({
externalID: 'your-external-tracking-ID',
bankCode: 'BCA',
accountHolderName: 'Stan',
accountNumber: '1234567890',
description: 'Payment for nasi padang',
amount: 10000,
})
.then(({ id }) => {
console.log(`Disbursement created with ID: ${id}`);
})
.catch(e => {
console.error(`Disbursement creation failed with message: ${e.message}`);
});
Refer to Xendit API Reference for more info about methods' parameters
d.getBanks();
d.create(data: {
externalID: string;
bankCode: string;
accountHolderName: string;
accountNumber: string;
description: string;
amount: number;
emailTo?: string[];
emailCC?: string[];
emailBCC?: string[];
xIdempotencyKey?: string;
})
d.createBatch(data: {
reference: string;
disbursements: Array<{
externalID: string;
bankCode: string;
accountHolderName: string;
accountNumber: string;
description: string;
amount: number;
emailTo?: string[];
emailCC?: string[];
emailBCC?: string[];
}>;
xIdempotencyKey?: string;
})
d.getByID(data: { disbursementID: string })
- Get a disbursement by external ID
d.getByExtID(data: { externalID: string })
Instanitiate Invoice service using constructor that has been injected with Xendit keys
const { Invoice } = x;
const invoiceSpecificOptions = {};
const i = new Invoice(invoiceSpecificOptions);
Example: Create an invoice
i.createInvoice({
externalID: 'your-external-id',
payerEmail: 'stanley@xendit.co',
description: 'Invoice for Shoes Purchase',
amount: 100000,
}).then(({ id }) => {
console.log(`Invoice created with ID: ${id}`);
});
Refer to Xendit API Reference for more info about methods' parameters
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;
})
i.getInvoice(data: { invoiceID: string })
i.expireInvoice(data: { invoiceID: string })
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;
})
Instanitiate Recurring Payments service using constructor that has been injected with Xendit keys
const { RecurringPayment } = x;
const rpSpecificOptions = {};
const rp = new RecurringPayment(rpSpecificOptions);
Example: Create a recurring payment
rp.createPayment({
externalID: '123',
payerEmail: 'stanley@xendit.co',
description: 'Payment for something',
amount: 10000,
interval: RecurringPayment.Interval.Month,
intervalCount: 1,
})
.then(({ id }) => {
console.log(`Recurring payment created with ID: ${id}`);
})
.catch(e => {
console.error(
`Recurring payment creation failed with message: ${e.message}`,
);
});
Refer to Xendit API Reference for more info about methods' parameters
rp.createPayment(data: {
externalID: string;
payerEmail: string;
description: string;
amount: number;
interval: Interval;
intervalCount: number;
totalRecurrence?: number;
invoiceDuration?: number;
shouldSendEmail?: boolean;
missedPaymentAction?: Action;
creditCardToken?: string;
startDate?: Date;
successRedirectURL?: string;
failureRedirectURL?: string;
recharge?: boolean;
chargeImmediately?: boolean;
})
rp.getPayment(data: { id: string })
rp.editPayment(data: {
id: string;
amount?: number;
creditCardToken?: string;
interval?: Interval;
intervalCount?: number;
shouldSendEmail?: boolean;
invoiceDuration?: number;
missedPaymentAction?: Action;
})
rp.stopPayment(data: { id: string })
rp.pausePayment(data: { id: string })
rp.resumePayment(data: { id: string })
Instanitiate Payout service using constructor that has been injected with Xendit keys
const { Payout } = x;
const payoutSpecificOptions = {};
const p = new Payout(payoutSpecificOptions);
Example: Create a payout
p.createPayout({
externalID: 'your-external-id',
amount: 100000,
}).then(({ id }) => {
console.log(`Invoice created with ID: ${id}`);
});
Refer to Xendit API Reference for more info about methods' parameters
p.createPayout(data: { externalID: string; amount: string })
p.getPayout(data: { id: string })
p.voidPayout(data: { id: string })
Instanitiate EWallet service using constructor that has been injected with Xendit keys
const { EWallet } = x;
const ewalletSpecificOptions = {};
const ew = new EWallet(ewalletSpecificOptions);
Example: Create an ewallet payment
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;
});
Refer to Xendit API Reference for more info about methods' parameters
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;
})
ew.getPayment(data: {
externalID: string:
ewalletType: GetSupportWalletTypes;
})
Instanitiate Balance service using constructor that has been injected with Xendit keys
const { Balance } = x;
const balanceSpecificOptions = {};
const i = new Balance(balanceSpecificOptions);
Example: Get balance of holding account
b.getBalance({
accountType: Balance.AccountType.Holding,
}).then(({ balance }) => {
console.log('Holding balance amount:', balance);
});
Refer to Xendit API Reference for more info about methods' parameters
b.getBalance(data: { accountType: AccountType })
Instanitiate Retail outlet service using constructor that has been injected with Xendit keys
const { RetailOutlet } = x;
const retailOutletSpecificOptions = {};
const ro = new RetailOutlet(retailOutletSpecificOptions);
Example: Example: Create a fixed payment code
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 for more info about methods' parameters
ro.createFixedPaymentCode(data: {
externalID: string;
retailOutletName: string;
name: string;
expectedAmt: number;
paymentCode?: string;
expirationDate?: Date;
isSingleUse?: boolean;
})
ro.getFixedPaymentCode(data: { id: string })
ro.updateFixedPaymentCode(data: {
id: string
name?: string;
expectedAmt?: number;
expirationDate?: Date;
})
Running test suite
npm install
npm run test
Running examples
cp .env.sample .env # then fill in required environment variables
node examples/card.js # or whichever example you would like to run
There are a commit hook to run linting and formatting and push hook to run all tests. Please make sure they pass before making commits/pushes.
For any requests, bug or comments, please open an issue or submit a pull request.