Package: pycryptopay-sdk
pyCryptoPayAPICrypto Payis a payment system based on@CryptoBot, which allows you to accept payments in cryptocurrency using the API.This library help you to work withCrypto PayviaCrypto Pay APIin yours Python scripts.Documentation available onEnglish languageДокументация доступна наРусском языкеInstallVia pip:pip install pycryptopay-sdkVia git:pip install git+https://github.com/LulzLoL231/pyCryptoPayAPI.gitVia source,in source folder:pip install ./UsageAPIFirst, you need to create your application and get an API token. Open@CryptoBotor@CryptoTestnetBot(for testnet), send a command/payto create a new app and get API Token.Next step: try to call a simpleget_me()method to check that everything is working well:fromasyncioimportrunfromCryptoPayAPIimportCryptoPaycp=CryptoPay('YOUR_API_TOKEN')print(run(cp.get_me()))# Returns Application object.You can usetestnetfor testing your applications. Defaults ismainnet.fromCryptoPayAPIimportCryptoPaycp=CryptoPay('YOUR_API_TOKEN',testnet=True)You can find all available methods inMethods chapter.Also, you can get supportedassets,paid button namesandinvoice status:fromasyncioimportget_event_loopfromCryptoPayAPIimportCryptoPayfromCryptoPayAPI.schemasimportAssets,PaidButtonNames,InvoiceStatuslp=get_event_loop()cp=CryptoPay('YOUR_API_TOKEN')print(lp.run_until_complete(cp.create_invoice(Assets.USDT,5.25,description='Example page for $5.25!',paid_btn_name=PaidButtonNames.VIEW_ITEM,paid_btn_url='https://example.com')))# Prints information about created invoice.print(lp.run_until_complete(cp.get_invoices(Assets.USDT,status=InvoiceStatus.PAID)))# Prints all paid invoices.WebhooksUse Webhooks to get updates for your app, Crypto Pay will send an HTTPS POST request to the specified URL, containing a JSON-serializedUpdate.Read more about webhooks inCrypto Pay Docs!UseCryptoPay.process_webhook_updatefunction, for processing Crypto Pay requests.Checkwebhook examplefor more info.CryptoPay.process_webhook_updateCoroutine. Processing webhook request, returnsUpdateobject.Arguments:body(bytes) - JSON content from Crypto Pay request in bytes.headers(dict[str, str]) - Request headers.update=awaitcp.process_webhook_update(body,headers)print(f'Recieved{update.payload.amount}{update.payload.asset}!')# Recieved 10.0 ETHLook full code in theexamples.API methodsget_mecreate_invoicetransferget_invoicesget_balancesget_exchange_ratesget_currenciesget_meA simple method for testing your app's authentication token. Requires no parameters. Returns basic information about the app.Returns:Applicationobject.cp.get_me()create_invoiceUse this method to create a new invoice. Returns object of created invoice.Arguments:asset(Assets|str) - Currency code. Supported assets:BTC,TON,ETH(only testnet),USDT,USDC,BUSD.amount(float) - Amount of the invoice in float. For example:125.50description(str) -Optional. Description of the invoice. Up to 1024 symbols.hidden_message(str) -Optional. The message will show when the user pays your invoice.paid_btn_name(PaidButtonName|str) -Optional. Paid button name. This button will be shown when your invoice was paid. Supported names:viewItem- View ItemopenChannel- Open ChannelopenBot- Open Botcallback- Returnpaid_btn_url(str) -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(str, up to 4kb) -Optional. Some data. User ID, payment id, or any data you want to attach to the invoice.allow_comments(bool) -Optional. Allow adding comments when paying an invoice. Default is True.allow_anonymous(bool) -Optional. Allow pay invoice as anonymous. Default is True.expires_in(int) -Optional. You can set the expiration date of the invoice in seconds. Use this period: 1-2678400 seconds.Returns:Invoiceobject of created invoice.cp.create_invoice(Assets.USDT,5.25,description='Example page for $5.25!',paid_btn_name=PaidButtonNames.VIEW_ITEM,paid_btn_url='https://example.com')transferUse this method to send coins from your app to the user. Returns object of completed transfer.Arguments:user_id(int) - Telegram User ID. The user needs to have an account in our bot (send /start if no).asset(Assets) - Currency code. Supported assets:BTC,TON,ETH(only testnet),USDT,USDC,BUSD.amount(float) - Amount of the transfer in float. For example:125.50spend_id(str) - It is used to make your request idempotent. It's guaranteed 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). You can use a withdrawal id or something. Up to 64 symbols.comment(str) -Optional. The comment of the invoice. The comment will show in the notification about the transfer. Up to 1024 symbols.Returns:Transferobject of created transfer.cp.transfer(265300852,Assets.USDT,3.0,'pCBA226ghd',comment='donate')get_invoiceUse this method to get invoices of your app. On success, the returns array ofInvoice.Arguments:asset(Assets) -Optional. Currency code. Supported assets:BTC,TON,ETH(only testnet),USDT,USDC,BUSD. Default: all assets.invoice_ids(str) -Optional. Invoice IDs separated by comma.status(InvoiceStatus) -Optional. Status of invoices. Available statuses: active, paid and expired. Default: all statuses.offset(int) -Optional. Offset needed to return a specific subset of  invoices. Default 0.count(int) -Optional. Number of invoices to return. Default 100, max 1000.Returns: array ofInvoiceobjects.cp.get_invoices(schemas.Assets.USDT,status=schemas.InvoiceStatus.PAID,count=10)get_balanceUse this method to get balance of your app. Returns array of assets.Returns: array ofBalanceobjects.cp.get_balance()get_exchange_ratesUse this method to get exchange rates of supported currencies. Returns array of currencies.Returns: array ofExchangeRateobjects.cp.get_exchange_rates()get_currenciesUse this method to supported currencies. Returns array of currencies.Returns: array ofCurrencyobjects.cp.get_currencies()Constants and schemasfromCryptoBotAPIimportschemasschemas.AssetconstantvalueAssets.BTCBTCAssets.TONTONAssets.ETHETHAssets.USDTUSDTAssets.USDCUSDCAssets.BUSDBUSDschemas.PaidButtonNamesconstantvaluePaidButtonNames.VIEW_ITEMviewItemPaidButtonNames.OPEN_CHANNELopenChannelPaidButtonNames.OPEN_BOTopenBotPaidButtonNames.CALLBACKcallbackschemas.InvoiceStatusconstantvalueInvoiceStatus.ACTIVEactiveInvoiceStatus.PAIDpaidInvoiceStatus.EXPIREDexpiredschemas.Invoicekeytypeinvoice_idintstatusInvoiceStatushashstrassetAssetsamountdecimal.Decimalpay_urlstrdescriptionOptional[str]created_atdatetime.datetimeallow_commentsboolallow_anonymousboolexpiration_dateOptional[datetime.datetime]paid_atOptional[datetime.datetime]paid_anonymouslyOptional[bool]commentOptional[str]hidden_messageOptional[str]payloadOptional[str]paid_btn_nameOptional[PaidButtonNames]paid_btn_urlOptional[str]schemas.Transferkeytypetransfer_idintuser_idintassetAssetsamountdecimal.DecimalstatusLiteral['completed']completed_atdatetime.datetimecommentOptional[str]schemas.Applicationkeytypeapp_idintnamestrpayment_processing_bot_usernamestrschemas.Balancekeytypecurrency_codestravailabledecimal.Decimalschemas.ExchangeRatekeytypeis_validboolsourcestrtargetstrratedecimal.Decimalschemas.Currencykeytypeis_blockchainboolis_stablecoinboolis_fiatboolnamestrcodestrurlOptional[str]decimalsintschemas.UpdateTypeconstantvalueUpdateType.INVOICE_PAIDinvoice_paidschemas.Updatekeytypeupdate_idintupdate_typeUpdateTyperequest_datedatetimepayloadInvoice