NodeJS

Nusagate SDK Support for NodeJS Client

Requirement

Installation

Use at least NodeJS version 16 and after it is installed run this command on top of your project :

npm install nusagate-nodejs --save

Authentication

const apiKey = 'YOUR_API_KEY';
const secretKey = 'YOUR_SECRET_KEY';

const headers = { auth: { username: apiKey, password: secretKey } };

const response = await axios.get(
        `${this.getBaseUrl()}/v1/invoices/${id}`,
        header,
);

Using SDK

If you're using software development kit you don't need to be worry about the auth & client request

const Nusagate = require('nusagate-nodejs');

const nusagateClient = new Nusagate({
  isProduction: false,
  apiKey: 'YOUR_API_KEY',
  secretKey: 'YOUR_SECRET_KEY',
});

Get Available Currency

SDK for Get Available Currency API

nusagateClient.availableCurrency()
.then((data) => {
  console.log('Data : ', data)
})
.catch((error) => {
  console.log('Error : ' , JSON.parse(error.message))
});

Create Invoice

SDK for Create Invoice API

const payload = {
  externalId: 'HEHE-00011',
  description: 'hehe...',
  price: 560000,
  dueDate: '2022-05-26T19:26:07.255Z',
  email: 'john@gmail.com',
  phoneNumber: '62813123...',
};

const response = await nusagateClient.createInvoice(payload).then((data) => {
  console.log('Data : ', data)
})
.catch((error) => {
  console.log('Error : ' , JSON.parse(error.message))
});

Get List Invoice

SDK for Get List Invoice API

const query = {
  page: 1,
  perPage: 2,
  fromDate: '2022-04-26T19:26:07.255Z',
  toDate: '2022-05-26T19:26:07.255Z',
  orderBy: 'DESC',
  sortBy: 'createdAt',
  status: 'UNPAID', // status: ['PAID', 'UNPAID', 'VOID', 'COMPLETED']
  search: '',
};

// get invoice list
nusagateClient
  .getInvoices(query)
  .then((data) => {
    console.log('data:', data);
  })
  .catch((error) => {
    console.log('Error occured:', JSON.parse(error.message));
  });

Get Detail Invoice

SDK for Get Detail Invoice API

const invoiceId = 'INVOICE-ID';

nusagateClient
  .getInvoiceById(invoiceId)
  .then((data) => {
    console.log('data:', data);
  })
  .catch((error) => {
    console.log('Error occured:', JSON.parse(error.message));
  });

Void Invoice

SDK for Void Invoice API

const invoiceId = 'INVOICE-ID';

nusagateClient
  .voidInvoice(invoiceId)
  .then((data) => {
    console.log('data:', data);
  })
  .catch((error) => {
    console.log('Error occured:', JSON.parse(error.message));
  });

Create Transfer

SDK for Create Transfer API

const payload = {
  externalId: 'EXAMPLE_EXTERNAL_ID',
  address: 'TUe4Uat7JFXj9zG8...',
  amount: 169,
  currencyCode: 'TRX',
};

nusagateClient
  .createTransfer(payload)
  .then((data) => {
    console.log('data:', data);
  })
  .catch((error) => {
    console.log('Error occured:', JSON.parse(error.message));
  });

Get List Transfer

SDK for Get List Transfer API

const payload = {
  externalId: 'EXAMPLE_EXTERNAL_ID',
  address: 'TUe4Uat7JFXj9zG8...',
  amount: 169,
  currencyCode: 'TRX',
};

nusagateClient
  .createTransfer(payload)
  .then((data) => {
    console.log('data:', data);
  })
  .catch((error) => {
    console.log('Error occured:', JSON.parse(error.message));
  });

Get Detail Transfer

SDK for Get Detail Transfer API

const transferId = 'INVOICE-ID';

nusagateClient
  .getTransferById('5a54a11d-ffda-46cd-b389-fc602b9fdb41')
  .then((data) => {
    console.log('data:', data);
  })
  .catch((error) => {
    console.log('Error occured:', JSON.parse(error.message));
  });

Last updated