telepay-node v1.1.0
NodeJS SDK for the TelePay API
Official TelePay client library for NodeJS, so you can easily process cryptocurrency payments using the REST API.
Installation
Install the package using npm:
npm install telepay-node
Install the package using yarn:
yarn add telepay-node
Using the library
Import and construct a client
import { TelepayClient } from 'telepay-node';
const telepayClient: TelepayClient = new TelepayClient(process.env['TELEPAY_SECRET_KEY']);
Telepay API Endpoints
The API endpoints are documented in the TelePay documentation.
/getMe
Info about the current merchant. Read docs
const response = await telepayClient.getMe();
// or
telepayClient.getMe()
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/getBalance GET
Get your merchant wallet assets with corresponding balance. Read docs
const response = await telepayClient.getAllBalances();
// or
telepayClient.getAllBalances()
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/getBalance POST
Get your merchant wallet assets with corresponding balance. Read docs
const data: GetOneBalanceBody = {
asset: 'TON',
blockchain: 'TON',
network: Network.testnet
}
const response = await telepayClient.getOneBalance(data);
// or
telepayClient.getOneBalance(data)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/getAsset
Get asset details. Read docs
const data: GetOneAssetBody = {
asset: 'TON',
network: Network.testnet,
blockchain: 'TON'
};
const response = await telepayClient.getAsset(data);
// or
telepayClient.getAsset(data)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/getAssets
Get assets supported by TelePay. Read docs
const response = await telepayClient.getAssets();
// or
telepayClient.getAssets()
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/getInvoices
Get your merchant invoices. Read docs
const response = await telepayClient.getInvoices();
// or
telepayClient.getInvoices()
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/getInvoice
Get invoice details, by ID. Read docs
const response = await telepayClient.getInvoice(invoiceNumber);
// or
telepayClient.getInvoice(invoiceNumber)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/createInvoice
Creates an invoice, associated to your merchant. Read docs
const data: CreateInvoiceBody = {
asset: 'TON',
amount: 100,
network: Network.testnet,
blockchain: 'TON'
};
const response = await telepayClient.createInvoice(data);
// or
telepayClient.createInvoice(data)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/cancelInvoice
Cancel invoice, by its number. Read docs
const invoiceNumber: string = 'TEST1234';
const response = await telepayClient.cancelInvoice(invoiceNumber);
// or
telepayClient.cancelInvoice(invoiceNumber)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/deleteInvoice
Delete invoice, by its number. Read docs
const invoiceNumber: string = 'TEST1234';
const response = await telepayClient.deleteInvoice(invoiceNumber);
// or
telepayClient.deleteInvoice(invoiceNumber)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/transfer
Transfer funds between internal wallets. Off-chain operation. Read docs
const data: TransferBody = {
amount: 10,
username: 'TEST_USERNAME',
asset: 'TON',
network: Network.testnet,
blockchain: 'TON'
};
const response = await telepayClient.transfer(data);
// or
telepayClient.transfer(data)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/getWithdrawMinimum
Obtains minimum amount required to withdraw funds on a given asset. Read docs
const data: GetWithdrawMinimumBody = {
asset: 'TON',
network: Network.testnet,
blockchain: 'TON'
};
const response = await telepayClient.getWithdrawMinimum(data);
// or
telepayClient.getWithdrawMinimum(data)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/getWithdrawFee
Get estimated withdraw fee, composed of blockchain fee and processing fee. Read docs
const data: WithdrawBody = {
amount: 10,
to_address: 'TEST_TON_WALLET',
asset: 'TON',
network: Network.testnet,
blockchain: 'TON'
};
const response = await telepayClient.getWithdrawFee(data);
// or
telepayClient.getWithdrawFee(data)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/withdraw
Withdraw funds from merchant wallet to external wallet. On-chain operation. Read docs
const data: WithdrawBody = {
amount: 10,
to_address: 'TEST_TON_WALLET',
asset: 'TON',
network: Network.testnet,
blockchain: 'TON'
};
const response = await telepayClient.withdraw(data);
// or
telepayClient.withdraw(data)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/createWebhook
Create a new webhook. Read docs
const data: WebhookBody = {
url: 'https://api.example.com/webhook',
active: true,
events: [WebhookEvents.Completed, WebhookEvents.Cancelled],
secret: '<SECRET>'
};
const response = await telepayClient.createWebhook(data);
// or
telepayClient.createWebhook(data)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/getWebhook
Get webhook details. Read docs
const webhook_id = 123;
const response = await telepayClient.getWebhook(webhook_id);
// or
telepayClient.getWebhook(webhook_id)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/getWebhook
Get webhooks. Read docs
const response = await telepayClient.getWebhooks();
// or
telepayClient.getWebhooks()
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/updateWebhook
Update a webhook. Read docs
const webhook_id = 123;
const data: WebhookBody = {
url: 'https://api.example.com/webhook',
active: true,
events: [WebhookEvents.Expired, WebhookEvents.Deleted],
secret: '<SECRET>'
};
const response = await telepayClient.updateWebhook(webhook_id, data);
// or
telepayClient.updateWebhook(webhook_id, data)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/activateWebhook
Activates a webhook. Read docs
const webhook_id = 123;
const data: StatusWebhookBody = {
asset: 'TON',
network: Network.testnet,
blockchain: 'TON'
};
const response = await telepayClient.activateWebhook(webhook_id, data);
// or
telepayClient.activateWebhook(webhook_id, data)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/deactivateWebhook
Deactivates a webhook. Read docs
const webhook_id = 123;
const data: StatusWebhookBody = {
asset: 'TON',
network: Network.testnet,
blockchain: 'TON'
};
const response = await telepayClient.deactivateWebhook(webhook_id, data);
// or
telepayClient.deactivateWebhook(webhook_id, data)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
/deleteWebhook
Deletes a webhook. Read docs
const webhook_id = 123;
const response = await telepayClient.deleteWebhook(webhook_id);
// or
telepayClient.deleteWebhook(webhook_id, data)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
Extra feature
Generic function for perform requests to any endpoint
const method: ApiMeth = 'GET';
const endpoint: ApiEndpoint = '/getMe';
const response = await telepayClient.genericRequest(method, endpoint);
// or
telepayClient.genericRequest(method, endpoint)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
Contributors ✨
The library is made by (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!