Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@foile/crypto-pay-api
Advanced tools
Readme
Crypto Pay is a payment system based on @CryptoBot, which allows you to accept payments in cryptocurrency using the API.
This library help you to work with Crypto Pay via Crypto Pay API.
npm i @foile/crypto-pay-api
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.
Next step: try to call a simple getMe()
method to check that everything is working welll:
const { CryptoPay } = require('@foile/crypto-pay-api');
const cryptoPay = new CryptoPay(token);
const app = await cryptoPay.getMe();
console.log(app);
You can setup net hostname
(defaults to pay.crypt.bot
) and protocol
in optional param:
const cryptoPay = new CryptoPay(token, {
hostname: 'testnet-pay.crypt.bot',
protocol: 'https'
});
Net | Bot | Hostname |
---|---|---|
mainnet | @CryptoBot | pay.crypt.bot |
testnet | @CryptoTestnetBot | testnet-pay.crypt.bot |
All queries to the Crypto Pay API must be sent over HTTPS
You can find all available methods in next chapter.
Also, you can get supported assets and paid button names:
const { CryptoPay, Assets, PaidButtonNames } = require('@foile/crypto-pay-api');
const cryptoPay = new CryptoPay(token);
cryptoPay.createInvoice(Assets.BTC, 1, {
description: 'kitten',
paid_btn_name: PaidButtonNames.VIEW_ITEM,
paid_btn_url: 'http://placekitten.com/150',
});
Look full code in the examples directory.
Use Webhooks to get updates for the app.
If you'd like to make sure that the Webhook request comes from Crypto Pay, we recommend using a secret path in the URL, e.g. https://www.example.com/<secret>
.
Webhooks will send may at least one time
const cryptoPay = new CryptoPay(token, {
webhook: {
serverHostname: 'localhost',
serverPort: 4200,
path: '/secret-path'
},
});
cryptoPay.on('invoice_paid', update => console.log(update.payload));
You can use pretty simple alias methods named from update names:
cryptoPay.invoicePaid(update => console.log(update.payload));
See all available updates here.
API
Updates
A simple method for testing your app's authentication token. Requires no parameters. Returns basic information about the app.
cryptoPay.getMe();
Use this method to create a new invoice. Returns object of created invoice.
asset (string)
Currency code. Supported assets: BTC
, TON
, ETH
, USDT
, USDC
and BUSD
.
amount (string)
Amount of the invoice in float. For example: 125.50
description (string) Optional. Description for the invoice. User will see this description when they pay the invoice. Up to 1024 characters.
hidden_message (string) Optional. Text of the message that will be shown to a user after the invoice is paid. Up to 2048 characters.
paid_btn_name (string) default - callback
Optional. Name of the button that will be shown to a user after the invoice is paid. Supported names:
viewItem
- View ItemopenChannel
- View ChannelopenBot
- Open Botcallback
- Returnpaid_btn_url (string) Optional Required if paid_btn_name is used. URL to be opened when the button is pressed. You can set any success link (for example, a link to your bot). Starts with https or http.
payload (string) Optional. Any data you want to attach to the invoice (for example, user ID, payment ID, ect). Up to 4kb.
allow_comments (boolean) Optional. Allow a user to add a comment to the payment. Default is true.
allow_anonymous (boolean) Optional. Allow a user to pay the invoice anonymously. Default is true.
expires_in (number) Optional. You can set a payment time limit for the invoice in seconds. Values between 1-2678400 are accepted.
cryptoPay.createInvoice(Assets.BTC, 1, {
description: 'kitten',
paid_btn_name: PaidButtonNames.VIEW_ITEM,
paid_btn_url: 'http://placekitten.com/150',
});
Use this method to send coins from your app to the user. Returns object of completed transfer.
BTC
, TON
, ETH
, USDT
, USDC
and BUSD
.125.50
cryptoPay.transfer(121011054, Assets.ETH, 0.1, 'ZG9uYXRl', { comment: 'donate' });
Use this method to get invoices of your app. On success, the returns array of invoices.
BTC
, TON
, ETH
, USDT
, USDC
and BUSD
. Defaults to all assets.active
and paid
. Defaults to all statuses.cryptoPay.getInvoices({ asset: Assets.BTC, count: 10 });
Use this method to get balance of your app. Returns array of assets.
cryptoPay.getBalance();
Use this method to get exchange rates of supported currencies. Returns array of currencies.
cryptoPay.getExchangeRates();
Use this method to supported currencies. Returns array of currencies.
cryptoPay.getCurrencies();
Adds handler to the choosen update type.
cryptoPay.on('invoice_paid', update => console.log(update.payload));
Adds handler to invoice_paid
update.
cryptoPay.invoicePaid(update => console.log(update.payload));
Adds a one-time handler to the choosen update type.
cryptoPay.once('invoice_paid', update => console.log(update.payload));
Removes the specified listener from the listener array for the event named eventName.
const subscriber = (update) => console.log(update.payload)
cryptoPay.on('invoice_paid', subscriber);
setTimeout(
() => cryptoPay.off('invoice_paid', subscriber),
10000
);
constant | value |
---|---|
Assets.BTC | BTC |
Assets.TON | TON |
Assets.ETH | ETH |
Assets.USDT | USDT |
Assets.USDC | USDC |
Assets.BUSD | BUSD |
constant | value |
---|---|
PaidButtonNames.VIEW_ITEM | viewItem |
PaidButtonNames.OPEN_CHANNEL | openChannel |
PaidButtonNames.OPEN_BOT | openBot |
PaidButtonNames.CALLBACK | callback |
FAQs
Cryptocurrency payment system based on @CryptoBot
The npm package @foile/crypto-pay-api receives a total of 61 weekly downloads. As such, @foile/crypto-pay-api popularity was classified as not popular.
We found that @foile/crypto-pay-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.