Skip to main content

BEpusdt 支付网关 Python SDK - 支持 USDT/TRX/USDC 多链支付

Project description

❗️声明:本 SDK 为 BEpusdt 支付网关的非官方 Python 客户端库,仅供学习研究使用。使用本项目请遵守当地法律法规,任何违法违规使用产生的后果由使用者自行承担。


BEpusdt Python SDK

PyPI version Python Support License: MIT BEpusdt

🪧 介绍

BEpusdt 支付网关的 Python SDK,让 Python 开发者能够快速集成 USDT/TRX/USDC 加密货币支付功能。

✨ 特性

  • 🎯 简单易用 - 几行代码即可集成
  • 🔐 自动签名 - 内置签名生成和验证
  • 🌐 多链支持 - 支持 10+ 区块链网络
  • 💰 多币种 - USDT、USDC、TRX、ETH、BNB
  • 🔄 自动重试 - 网络错误自动重试,提升成功率
  • 📱 二维码生成 - 一键生成收款地址二维码
  • 📝 类型提示 - 完整的 IDE 智能提示
  • 生产就绪 - 经过真实环境测试
  • 🔄 完全兼容 - 完整支持 BEpusdt API

🌟 支持的网络

USDT

🔥 主流网络:Tron (TRC20) · Ethereum (ERC20) · BSC (BEP20) · Polygon
⚡ 其他网络:Arbitrum · Solana · Aptos · X-Layer · Plasma

USDC

🔥 主流网络:Tron (TRC20) · Ethereum (ERC20) · BSC (BEP20) · Polygon
⚡ 其他网络:Arbitrum · Solana · Aptos · X-Layer · Base

其他

💎 TRX (Tron) · ETH (Ethereum) · BNB (BSC)

📦 安装

pip install bepusdt

# 如需二维码功能
pip install bepusdt[qrcode]

🚀 快速开始

from bepusdt import BEpusdtClient, TradeType

# 初始化客户端(支持自动重试)
client = BEpusdtClient(
    api_url="https://your-bepusdt-server.com",
    api_token="your-api-token",
    max_retries=3  # 可选:网络错误自动重试3次
)

# 创建订单
order = client.create_order(
    order_id="ORDER_001",
    amount=10.0,
    notify_url="https://your-domain.com/notify",
    trade_type=TradeType.USDT_TRC20
)

print(f"💰 支付金额: {order.actual_amount} USDT")
print(f"📍 收款地址: {order.token}")
print(f"🔗 支付链接: {order.payment_url}")

📖 文档

🔧 核心功能

错误处理

SDK 会自动处理网络错误和服务器临时故障:

from bepusdt.exceptions import ServerError, NetworkError, TimeoutError

try:
    order = client.create_order(...)
except ServerError as e:
    # 服务器错误 5xx(已自动重试)
    print(f"服务器错误: {e}")
except NetworkError as e:
    # 网络连接失败(已自动重试)
    print(f"网络错误: {e}")
except TimeoutError as e:
    # 请求超时(已自动重试)
    print(f"超时: {e}")

自动重试配置:

client = BEpusdtClient(
    api_url="https://your-server.com",
    api_token="your-api-token",
    max_retries=3,      # 最多重试 3 次
    retry_delay=1.0     # 初始延迟 1 秒(指数退避)
)

创建订单

order = client.create_order(
    order_id="ORDER_001",
    amount=10.0,
    notify_url="https://your-domain.com/notify",
    redirect_url="https://your-domain.com/success",
    trade_type=TradeType.USDT_TRC20
)

查询订单

order = client.query_order(trade_id="xxx")
if order.status == OrderStatus.SUCCESS:
    print("✅ 支付成功")

验证回调

@app.route('/notify', methods=['POST'])
def notify():
    data = request.get_json(silent=True)
    if not client.verify_callback(data):
        return "fail", 400

    # 签名只证明回调来自 BEpusdt。
    # 发货前仍需查询本地订单并校验 order_id、amount、status 状态流转,
    # 再用数据库唯一约束或事务确保 trade_id/block_transaction_id 只处理一次。
    if data["status"] == 2 and mark_order_paid_once(data):
        deliver_order(data["order_id"])

    return "ok", 200

生成二维码

# 创建订单后生成收款地址二维码
order = client.create_order(...)

# 方式1:保存为图片文件
qr = order.generate_qrcode()
qr.save("payment_qr.png")

# 方式2:获取 Base64(用于 API 返回)
qr_base64 = order.get_qrcode_base64()

# 方式3:获取 Data URI(直接用于 HTML img src)
data_uri = order.get_qrcode_data_uri()
# <img src="{data_uri}">

🏝️ 交流反馈

🙏 感谢

  • BEpusdt - 优秀的 USDT 支付网关
  • Epusdt - BEpusdt 的前身

🔗 相关链接

📄 许可证

MIT License

📢 声明

本项目仅供学习研究使用,使用过程中请遵守当地法律法规,任何违法违规使用产生的后果由使用者自行承担。


Made with ❤️ for BEpusdt community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bepusdt-0.3.9.tar.gz (26.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bepusdt-0.3.9-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file bepusdt-0.3.9.tar.gz.

File metadata

  • Download URL: bepusdt-0.3.9.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bepusdt-0.3.9.tar.gz
Algorithm Hash digest
SHA256 6d6874dd385b211365f03f922f43154c82d300743e0a7bb71276847dbc04f633
MD5 79655203e17a009e3b23ba38536c7ec6
BLAKE2b-256 00910ef3b20d7eaead5cbfa3ac9ed6b0fb6c36362438b5aeea252ad5850127df

See more details on using hashes here.

File details

Details for the file bepusdt-0.3.9-py3-none-any.whl.

File metadata

  • Download URL: bepusdt-0.3.9-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bepusdt-0.3.9-py3-none-any.whl
Algorithm Hash digest
SHA256 fcfd1c261cfdbd118f13c6e4cd5d1070d4f879d67f33395bd8cf75cbdcf22cb9
MD5 17625ec32f1bb7380aa128180820a360
BLAKE2b-256 cdb05ebb3ab821a7b31269c178edec66d1520c496b36bca99c9d6d3742ec1e36

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page