crypto_pay_api package

Submodules

crypto_pay_api.api module

class crypto_pay_api.api.CryptoPay(token, client=None)

Bases: object

base_url = 'https://pay.crypt.bot/api/'
create_invoice(asset, amount, description=None, hidden_message=None, paid_btn_name=None, paid_btn_url=None, payload=None, allow_comments=None, allow_anonymous=None, expires_in=None)

Use this method to create a new invoice. On success, returns an object of the created invoice.

Parameters
  • asset (Asset) – Currency code. Supported assets: “BTC”, “TON”, “ETH” (testnet only), “USDT”, “USDC” and “BUSD”.

  • amount (str) – Amount of the invoice in float. For example: 125.50

  • description (Optional[str]) – Description for the invoice. User will see this description when they pay the invoice. Up to 1024 characters.

  • hidden_message (Optional[str]) – Text of the message that will be shown to a user after the invoice is paid. Up to 2o48 characters.

  • paid_btn_name (Optional[Button]) – Name of the button that will be shown to a user after the invoice is paid.

  • paid_btn_url (Optional[str]) – 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 (Optional[str]) – Any data you want to attach to the invoice (for example, user ID, payment ID, ect). Up to 4kb.

  • allow_comments (Optional[bool]) – Allow a user to add a comment to the payment. Default is true.

  • allow_anonymous (Optional[bool]) – Allow a user to pay the invoice anonymously. Default is true.

  • expires_in (Optional[int]) – You can set a payment time limit for the invoice in seconds. Values between 1-2678400 are accepted.

Return type

Invoice

get_balance()

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

Returns

id

get_currencies()

Use this method to get a list of supported currencies. Returns array of currencies.

Returns

get_exchange_rates()

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

Returns

get_invoices(asset=None, invoice_ids=None, status=None, offset=None, count=None)

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

Parameters
  • asset (Optional[Asset]) – Currency codes separated by comma. Supported assets: “BTC”, “TON”, “ETH” (testnet only), “USDT”, “USDC” and “BUSD”. Defaults to all assets.

  • invoice_ids (Optional[str]) – Invoice IDs separated by comma.

  • status (Optional[Status]) – Status of invoices to be returned. Available statuses: “active” and “paid”. Defaults to all statuses.

  • offset (Optional[int]) – Offset needed to return a specific subset of invoices. Default is 0.

  • count (Optional[int]) – Number of invoices to be returned. Values between 1-1000 are accepted. Defaults to 100.

Return type

List[Invoice]

get_me()

Use this method to test your app’s authentication token. Requires no parameters. On success, returns basic information about an app.

Returns

transfer(user_id, asset, amount, spend_id, comment=None, disable_send_notification=None)

Use this method to send coins from your app’s balance to a user. On success, returns object of completed transfer.

Parameters
  • user_id (int) – Telegram user ID. User must have previously used @CryptoBot (@CryptoTestnetBot for testnet).

  • asset (Asset) – Currency code. Supported assets: “BTC”, “TON”, “ETH” (testnet only), “USDT”, “USDC” and “BUSD”.

  • amount (str) – Amount of the transfer in float. Min $0.1. For example: 125.50

  • spend_id (str) – Unique ID to make your request idempotent and ensure that only one of the transfers with the same spend_id will be accepted by Crypto Pay API. This parameter is useful when the transfer should be retried (i.e. request timeout, connection reset, 500 HTTP status, etc). It can be some unique withdrawal identifier for example. Up to 64 symbols.

  • comment (Optional[str]) – Comment for the transfer. Users will see this comment when they receive a notification about the transfer. Up to 1024 symbols.

  • disable_send_notification (Optional[bool]) – Pass true if the user should not receive a notification about the transfer. Default is false.

Return type

Transfer

Returns

crypto_pay_api.client module

class crypto_pay_api.client.ApiClient(base_url, token)

Bases: crypto_pay_api.client.Client

get(method, **params)
class crypto_pay_api.client.Client

Bases: object

static fetch(url, headers, params)

crypto_pay_api.enums module

class crypto_pay_api.enums.Asset(value)

Bases: strenum.StrEnum

An enumeration.

BTC = 'BTC'
BUSD = 'BUSD'
ETH = 'ETH'
TON = 'TON'
USDC = 'USDC'
USDT = 'USDT'
class crypto_pay_api.enums.Button(value)

Bases: strenum.StrEnum

An enumeration.

CALLBACK = 'callback'
OPEN_BOT = 'openBot'
OPEN_CHANNEL = 'openChannel'
VIEW_ITEM = 'viewItem'
class crypto_pay_api.enums.Status(value)

Bases: strenum.StrEnum

An enumeration.

ACTIVE = 'active'
PAID = 'paid'

crypto_pay_api.items module

class crypto_pay_api.items.Invoice(invoice_id, status, hash, asset, amount, pay_url, description, created_at, allow_comments, allow_anonymous, expiration_date, paid_at, paid_anonymously, comment, hidden_message, payload, paid_btn_name, paid_btn_url)

Bases: object

Invoice object.

Parameters
  • invoice_id (int) – Unique ID for this invoice.

  • status (str) – Status of the invoice, can be either “active”, “paid” or “expired”.

  • hash (str) – Hash of the invoice.

  • asset (str) – Currency code. Currently, can be “BTC”, “TON”, “ETH” (testnet only), “USDT”, “USDC” or “BUSD”.

  • amount (str) – Amount of the invoice.

  • pay_url (str) – URL should be presented to the user to pay the invoice.

  • description (Optional[str]) – Description for this invoice.

  • created_at (str) – (str): Date the invoice was created in ISO 8601 format.

  • allow_comments (bool) – (str): True, if the user can add comment to the payment.

  • allow_anonymous (bool) – (Optional[str]): True, if the user can pay the invoice anonymously.

  • expiration_date (Optional[str]) – (Optional[str]): Date the invoice was paid in Unix time.

  • paid_at (Optional[str]) – (Optional[str]): Date the invoice was paid in Unix time.

  • paid_anonymously (Optional[bool]) – (Optional[bool]): True, if the invoice was paid anonymously.

  • comment (Optional[str]) – (Optional[str]): Comment to the payment from the user.

  • hidden_message (Optional[str]) – (Optional[str]): Text of the hidden message for this invoice.

  • payload (Optional[str]) – (Optional[str]): Previously provided data for this invoice.

  • paid_btn_name (Optional[str]) – (Optional[str]): Name of the button, can be “viewItem”, “openChannel”, “openChannel” or “callback”.

  • paid_btn_url (Optional[str]) – (Optional[str]): URL of the button.

class crypto_pay_api.items.Transfer(transfer_id, user_id, asset, amount, status, completed_at, comment)

Bases: object

Transfer object.

Parameters
  • transfer_id (int) – (int): Unique ID for this transfer.

  • user_id (str) – (str): Telegram user ID the transfer was sent to.

  • asset (str) – (str): Currency code. Currently, can be “BTC”, “TON”, “ETH” (testnet only), “USDT”, “USDC” or “BUSD”.

  • amount (str) – (str): Amount of the transfer.

  • status (str) – (str): Status of the transfer, can be “completed”.

  • completed_at (str) – (str): Date the transfer was completed in ISO 8601 format.

  • comment (Optional[str]) – (Optional[str]): Comment for this transfer.

Module contents