Package: telepay
Python SDK for the TelePay APIOfficial TelePay client library for the Python language, so you can easely process cryptocurrency payments using the REST API.InstallationInstall the package with pip:pipinstalltelepayOr usingPoetry:poetryaddtelepayUsing the libraryRefer to theTelePay Docsand follow thefirst steps guide, you'll get your TelePay account and API key.To make requests to the TelePay API, you need to import a client. We have two clients:TelePaySyncClient: make requests synchronously.TelePayAsyncClientmake requests asynchronously.Import and use the clientfromtelepay.v1importTelePaySyncClient,TelePayAsyncClientclient=TelePaySyncClient(secret_api_key)client=TelePayAsyncClient(secret_api_key)Use the client as a context managerWe recommend using the client as a context manager, like this:withTelePaySyncClient(secret_api_key)asclient:# use the client...orasyncwithTelePayAsyncClient(secret_api_key)asclient:# use the client...API endpointsThe API endpoints are documented in theTelePay documentation, refer to that pages to know more about them.To manage the requests, if the client is async, you should use theawaitkeyword, like this:response=awaitclient.method(...)Wheremethodis the endpoint method.get_meInfo about the current merchant.Read docsaccount=client.get_me()get_balanceGet your merchant wallet assets with corresponding balance.Read docswallets=client.get_balance()Or get a specific wallet balance by specifying theasset,blockchainandnetwork.wallet=client.get_balance(asset='TON',blockchain='TON',network='network')Assetsget_assetGet asset details.Read docsasset=client.get_asset(asset='TON',blockchain='TON')get_assetsGet assets suported by TelePay.Read docsassets=client.get_assets()Invoicesget_invoiceGet invoice details, by its number.Read docsinvoice=client.get_invoice(number)get_invoicesGet your merchant invoices.Read docsinvoices=client.get_invoices()create_invoiceCreates an invoice, associated to your merchant.Read docsinvoice=client.create_invoice(asset='TON',blockchain='TON',network='mainnet',amount=1,description='Product',metadata={'color':'red','size':'large',},success_url='https://example.com/success',cancel_url='https://example.com/cancel',expires_at=30)cancel_invoiceCancel invoice, by its number.Read docsinvoice=client.cancel_invoice(number)delete_invoiceDelete invoice, by its number.Read docsstatus=client.delete_invoice(number)TransferstransferTransfer funds between internal wallets. Off-chain operation.Read docsstatus=client.transfer(asset='TON',blockchain='TON',network='mainnet',amount=1,username='test',message='Thanks')Withdrawalsget_withdraw_minimumObtains minimum amount required to withdraw funds on a given asset.Read docsminimum=client.get_withdraw_minimum(asset='TON',blockchain='TON',network='mainnet',)get_withdraw_feeGet estimated withdraw fee, composed of blockchain fee and processing fee.Read docsfees=client.get_withdraw_fee(to_address='EQCKYK7bYBt1t8UmdhImrbiSzC5ijfo_H3Zc_Hk8ksRpOkOk',asset='TON',blockchain='TON',network='mainnet',amount=1,message='test')withdrawWithdraw funds from merchant wallet to external wallet. On-chain operation.Read docsstatus=client.withdraw(to_address='EQCKYK7bYBt1t8UmdhImrbiSzC5ijfo_H3Zc_Hk8ksRpOkOk',asset='TON',blockchain='TON',network='mainnet',amount=1,message='test')WebhooksWebhooks allows you to get updates delivered to your app server whenever we have events on our side. We will send a POST request over HTTPS, with serialized JSON data of the event, to the endpoint defined by you in the Developers > Webhooks section, in your merchant dashboard.Read more in the docs.get_webhookGet webhook details, by its id.Read docsclient.get_webhook(id)get_webhooksGet your merchant webhooks.Read docswebhooks=client.get_webhooks()create_webhookCreate a webhook.Read docswebhook=client.create_webhook(url='https://example.com',secret='hello',events=['all'],active=True)update_webhookUpdate a webhook.Read docswebhook=client.update_webhook(url='https://example.com',secret='hello',events=['invoice.completed'],active=True)activate_webhookActivate a webhook, by its id.Read docsclient.activate_webhook(id)deactivate_webhookDeactivate a webhook, by its id.Read docsclient.deactivate_webhook(id)delete_webhookDelete a webhook, by its id.Read docsclient.deactivate_webhook(id)Webhook utilsThetelepay.v1.webhooksmodule contains utilities to manage webhooks received on your side.get_signature(data, secret): Returns a webhook signature, used to verify data integrity of the webhook. This is optional, but highly recommended.TelePayWebhookListener: A lightweight webhook listener, to receive webhooks from TelePay. You could build your own, like using django views, flask views, or any other web framework. Your choice.Example usingTelePayWebhookListenerfromtelepay.v1.webhooksimportTelePayWebhookListenerdefcallback(headers,data):print("Executing callback...")# do your stuff herelistener=TelePayWebhookListener(secret="SECRET",callback=callback,host="localhost",port=5000,url="/webhook",log_level="error",)listener.listen()Running the listener will output something like this:Modify the listener parameters to your needs, knowing this:secret: A secret token that your side knows and it's configured in the webhook definition, on the TelePay dashboard.callback: The callback function that is called when new webhook arrives, receiving it's HTTP headers and data.host: The host on which the listener will be running.port: The port on which the listener will be exposed.url: The webhook url, which is secret and should only be known by your app and TelePay. Otherwise, it could lead to security issues.log_level: The listener logger level, like"error","info"or"debug".Contributors ✨The library is made by (emoji key):Carlos Lugones💻Luis Diaz💻Reinier Hernández💻This project follows theall-contributorsspecification. Contributions of any kind welcome!