Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xendit-node

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xendit-node

NodeJS client for Xendit API

  • 0.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.5K
decreased by-6.02%
Maintainers
1
Weekly downloads
 
Created
Source

Xendit API Node.js Client

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 credt cards info should be done on client side with Xendit.js.

API Documentation

Please check Xendit Docs

Installation

npm install --save xendit-node

Usage

For the full documentation, please refer to Xendit Node Client Docs

Configure package with your account's API keys

const Xendit = require('xendit-node');
const x = new Xendit({
  publicKey: 'xnd_public...',
  secretKey: 'xnd_...',
});

Card Services

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}`);
  });
Methods
  • Create token
card.createToken(data: {
  cardNumber: string;
  expMonth: string;
  expYear: string;
  cardCVN: string;
  isSingleUse: boolean;
  amount?: number;
  shouldAuthenticate?: boolean;
})
  • Create charge
card.createCharge(data: {
  tokenID: string;
  externalID: string;
  amount?: number;
  authID?: string;
  cardCVN?: string;
  capture?: boolean;
  descriptor?: string;
})
  • Capture charge
card.captureCharge(data: {
  chargeID: string;
  amount: number;
})
  • Get charge
card.getCharge(data: { chargeID: string })
  • Create Authentication
card.createAuthetication(data: {
  amount: number;
  tokenID: string;
})
  • Create authorization
card.createAuthorization(data: {
  tokenID: string;
  externalID: string;
  amount?: number;
  authID?: string;
  cardCVN?: string;
  descriptor?: string;
})
  • Reverse authorization
card.reverseAuthorization(data: {
  chargeID: string;
  externalID: string;
})
  • Create refund
card.createRefund(data: {
  chargeID: string;
  amount: number;
  externalID: string;
  xIdempotencyKey?: string;
})

Virtual Account Services

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}`);
  });
Methods
  • Get banks with available virtual account service
va.getVABanks();
  • Create a fixed virtual account
va.createFixedVA(data: {
  externalID: string;
  bankCode: string;
  name: string;
  virtualAccNumber?: string;
  suggestedAmt?: number;
  isClosed?: boolean;
  expectedAmt?: number;
  expirationDate?: Date;
  isSingleUse?: boolean;
  description?: string;
})
  • Get details of your fixed virtual account
va.getFixedVA(data: { id: string })
  • Update details of your fixed virtual account
va.updateFixedVA(data: {
  id: string;
  suggestedAmt?: number;
  expectedAmt?: number;
  expirationDate?: Date;
  isSingleUse?: boolean;
  description?: string;
})
  • Get details of a VA payment
va.getVAPayment(data: { paymentID: string })

paymentID: ID of the payment that you obtained from your callback

Disbursement Services

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}`);
  });
Methods
  • Get banks with available disbursement service
d.getBanks();
  • Create a disbursement
d.create(data: {
  externalID: string;
  bankCode: string;
  accountHolderName: string;
  accountNumber: string;
  description: string;
  amount: number;
  emailTo?: string[];
  emailCC?: string[];
  emailBCC?: string[];
  xIdempotencyKey?: string;
})
  • Create a batch of disbursements
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;
})
  • Get a disbursement by ID
d.getByID(data: { disbursementID: string })
  • Get a disbursement by external ID
d.getByExtID(data: { externalID: string })

Contributing

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.

Keywords

FAQs

Package last updated on 26 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc