@royalf1sh/crypto-pay-api v0.0.10
Crypto Pay API
The most lightweight package without dependencies
Crypto Pay is a payment system based on @CryptoBot, which allows you to accept payments in cryptocurrency using the API.
Tips
Please, use Big.js
or another lib to work with big numbers.
Support
Check the official API docs https://telegra.ph/Crypto-Pay-API-11-25
Message to @CryptoSupportBot If you have a question about API. Or join to official chats @CryptoBotEnglish or @CryptoBotRussian for Russian developers.
Installation
First, you need to create your application and get an API token. Open @CryptoBot or @CryptoTestnetBot (for testnet), send a command /pay
to create a new app and get API Token.
npm i @royalf1sh/crypto-pay-api
Usage
const CryptoPayApi = require('@royalf1sh/crypto-pay-api')
const myCryptoApp = new CryptoPayApi({
url: 'testnet-pay.crypt.bot',
token: <YOUR-TOKEN>
})
Testnet url: testnet-pay.crypt.bot
Mainnet url (disabled now): pay.crypt.bot
Methods
All methods return a promise wich contains an object, which always has a Boolean field
ok
. Ifok
equalstrue
, the request was successful, and the result of the query can be found in theresult
field. In case of an unsuccessful request,ok
equalsfalse
, and the error is explained in theerror
field (e.g. PARAM_SHORT_NAME_REQUIRED).
Webhooks for notifications about payments
getMe
A simple method for testing your app's authentication token. Requires no parameters. Returns basic information about the app.
Example
const me = await myCryptoPay.getMe()
console.log(me)
createInvoice
Use this method to create a new invoice. Returns object of created invoice. Requires object with invoice options as argument.
- asset (String) - Currency code. Supported assets: BTC, TON, ETH (only testnet), USDT, USDC, BUSD
- amount (String)
Amount of the invoice in float. For example:
125.50
- description (String) Optional - Description of the invoice. Up to 1024 symbols
- paid_btn_name (String) Optional - Paid button name. This button will be shown when your invoice was paid. Default is
callback
if you use onlypaid_btn_url
Supported names:viewItem
- View ItemopenChannel
- Open ChannelopenBot
- Open Botcallback
- Return
- paid_btn_url (String) Optional but requried when you use
paid_btn_name
- Paid button URL. You can set any payment success link (for example link on your bot). Start with https or http - payload (String, up to 4kb) Optional - Some data. User ID, payment id, or any data you want to attach to the invoice
- allow_comments (Boolean) Optional - Allow adding comments when paying an invoice. Default is
true
- allow_anonymous (Boolean) Optional - Allow pay invoice as anonymous. Default is
true
Example
const invoice = await myCryptoPay.createInvoice({
asset: 'TON',
amount: 0.05,
description: 'Lorem ipsum dolor',
paid_btn_name: 'viewItem',
paid_btn_url: 'https://ton.org',
payload: JSON.stringify(someData),
allow_comments: true,
allow_anonymous: true
})
console.log(invoice)
getInvoices
Use this method to get invoices of your app. On success, the returns array of invoices. Optional object with options as argument
- asset (String) Optional - Currency code separated by comma. Supported assets: BTC, TON, ETH (only testnet), USDT, USDC, BUSD. Default: all assets.
- invoice_ids (String) Optional - Invoice IDs separated by comma.
- status (String) Optional - Status of invoices. Available statusses:
active
orpaid
. Default: all statusses. - offset (Integer) Optional - Offset needed to return a specific subset of invoices. Default
0
. - count (Integer) Optional - Number of invoices to return. Default
100
, max1000
.
Example
const invoices = await myCryptoPay.getInvoices({
status: 'paid'
})
console.log(invoices)
getBalance
Use this method to get balance of your app. Returns array of assets
Example
const balance = await myCryptoPay.getBalance()
console.log(balance)
getExchangeRates
Use this method to get exchange rates of supported currencies. Returns array of currencies
Example
const exchangeRates = await myCryptoPay.getExchangeRates()
console.log(exchangeRates)
getCurrencies
Use this method to get supported currencies. Returns array of currencies
Example
const currencies = await myCryptoPay.getCurrencies()
console.log(currencies)
Webhooks
Use Webhooks to get updates for the app, it will send an HTTPS POST request to the specified URL, containing a JSON-serialized Update. In case of an unsuccessful request, it will give up after a reasonable amount of attempts.
If you'd like to make sure that the Webhook request comes from Crypto Pay, recommend using a secret path in the URL, e.g. https://www.example.com/<token>
. Since nobody else knows your bot's token, you can be pretty sure it's from cryptopay.
Webhooks will send may at least one time.
How to enable Webhooks?
Open @CryptoBot or @CryptoTestnetBot (for testnet), open your app and tap Webhooks
section to set Webhooks URL
.
Webhooks Updates
- invoice_paid The update send when an invoice was paid by the user. The object includes paid invoice.