2.3.0 • Published 2 years ago

@dotred/crypto-pay v2.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@dotred/crypto-pay

  • Crypto Pay is a payment system based on @CryptoBot, which allows you to accept payments
    in cryptocurrency using the API.
  • @dotred/crypto-pay - is a wrapper over the Crypto Pay API, which makes it easier to interact with the API

Updates

2.2.0 1. Removed: getPayments & confirmPayment.

Documentation

1. Installation

To install the library, you need to run the following commands: Supported node versions: 12.22.7+

  1. if you are use npm -
npm install @dotred/crypto-pay  
  1. if you are use yarn -
yarn add @dotred/crypto-pay  

2. Creating token

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.

3. Creating pay-instance

To start interacting with the API, you need to create a pay-instance. To do this, import the standard method from the library and call it by passing the previously received token

CommonJS example

const { Asset, createPayInstance } = require('@dotred/crypto-pay');
const instance = createPayInstance('3323:AAlJ6KtPZCeXz8TVEQNX0lMhAldmclcmtnv', 'test');
const workWithInvoices = async () => {
  await instance.createInvoice({ asset: Asset.BTC, amount: '0.00005', });
  await instance.createInvoice({ asset: Asset.BTC, amount: '0.000045', });
  await instance.createInvoice({ asset: Asset.TON, amount: '12', });
  const invoices = await instance.getInvoices();
  console.log(invoices);
}
workWithInvoices().then().catch();   

TypeScript example

import createPayInstance, { CryptoPay } from '@dotred/crypto-pay';

// You can create instance using function
const instance = createPayInstance('your_token');
// or class
const instance = new CryptoPay('your_token')

// If you want to use Testnet, you must pass the network type as the second parameter 
const instance = createPayInstance('your_token', 'test');   

4. Using example

Let's create some invoices and get only BTC invoices

import createPayInstance, { Asset } from '@dotred/crypto-pay';

const instance = createPayInstance('3138:AAGcw73KFgcqcQ2Sl4sktL2WHuUgAvPpWKh', 'test');
const workWithInvoices = async () => {
  await instance.createInvoice({ asset: Asset.BTC, amount: '0.00005', });
  await instance.createInvoice({ asset: Asset.BTC, amount: '0.000045', });
  await instance.createInvoice({ asset: Asset.TON, amount: '12', });
  const invoices = await instance.getInvoices({ asset: Asset.BTC });
  console.log(invoices);
}

workWithInvoices().then().catch();   

5. API Reference

All methods are asynchronous (exception: createPayInstance)

createPayInstance (Default export)

Use this method to create a new pay-instance. Returns an object containing all the methods listed below

  • token (string)
    Your application token
  • net ("main" | "test")
    Net type. "main" - Mainnet, "test" - "Testnet"

getMe

A simple method for testing your app's authentication token. Requires no parameters. Returns basic information about the app.

createInvoice

Use this method to create a new invoice. Returns object of created invoice.

  • 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) default - callback
    Optional. Paid button name. This button will be shown when your invoice was paid. Supported names: viewItem - View Item
    openChannel - Open Channel
    openBot - Open Bot
    callback - 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 1kb)
    Optional. Some data. User ID, payment id, or any data you want to attach to the invoice.

getInvoices

Use this method to get invoices of your app. On success, the returns array of invoices.

  • asset (Asset)
    Optional. Currency code. Supported assets: BTC, TON, ETH (only testnet), USDT, USDC, BUSD. Default: all assets.
  • invoiceids (Array<string | number>)
    _Optional.
    Array of strings, numbers, or numbers and strings together.
  • status (Status)
    Optional. Status of invoices. Available statusses: active or paid. Default: all statusses.
  • offset (number)
    Optional. Offset needed to return a specific subset of invoices. Default 0.
  • count (number)
    Optional. Number of invoices to return. Default 100, max 1000.

getPayments

Use this method to get paid and unconfirmed invoices of your app. On success, the returns array of paid and
unconfirmed
invoices.

  • offset (number)
    Optional. Offset needed to return a specific subset of invoices. Default 0.
  • count (number)
    Optional. Number of invoices to return. Default 100, max 1000.

confirmPayment

Use this method to confirm paid invoice for your app. On success, the return confirmed invoice.

  • invoice_id (number)
    Invoice ID you want to confirm.

getBalance

Use this method to get balance of your app. Returns array of assets.

getExchangeRates

Use this method to get exchange rates of supported currencies. Returns array of currencies.

getCurrencies

Use this method to supported currencies. Returns array of currencies.

6. Types

Asset

enum: BTC, TON, ETH, USDT, USDC, BUSD

Status

enum: ACTIVE, PAID

2.3.0

2 years ago

2.2.0

2 years ago

2.1.7

2 years ago

2.1.6

2 years ago

2.1.5

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.10

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago