Comment on page
NodeJS
Nusagate SDK Support for NodeJS Client
Use at least NodeJS version 16 and after it is installed run this command on top of your project :
npm install nusagate-nodejs --save
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,
);
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',
});
nusagateClient.availableCurrency()
.then((data) => {
console.log('Data : ', data)
})
.catch((error) => {
console.log('Error : ' , JSON.parse(error.message))
});
const payload = {
externalId: 'HEHE-00011',
description: 'hehe...',
price: 560000,
dueDate: '2022-05-26T19:26:07.255Z',
email: '[email protected]',
phoneNumber: '62813123...',
};
const response = await nusagateClient.createInvoice(payload).then((data) => {
console.log('Data : ', data)
})
.catch((error) => {
console.log('Error : ' , JSON.parse(error.message))
});
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));
});
const invoiceId = 'INVOICE-ID';
nusagateClient
.getInvoiceById(invoiceId)
.then((data) => {
console.log('data:', data);
})
.catch((error) => {
console.log('Error occured:', JSON.parse(error.message));
});
const invoiceId = 'INVOICE-ID';
nusagateClient
.voidInvoice(invoiceId)
.then((data) => {
console.log('data:', data);
})
.catch((error) => {
console.log('Error occured:', JSON.parse(error.message));
});
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));
});
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));
});
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 modified 1yr ago