Skip to main content

Epusdt 商户支付 Python SDK,支持 GMPay、EPay 兼容接入与回调验签

Project description

epusdt Python SDK

PyPI version Python versions License

适用于 GMWalletApp/epusdt 商户公开支付接口的 Python SDK,提供同步与异步两套客户端,支持 GMPay 下单、EPay submit.php 兼容接入、订单查询、回调验签和收款二维码生成。

当前版本只封装商户公开支付能力,不包含后台管理接口。

相关链接

已支持功能

  • GMPay 创建订单
  • 支付配置查询
  • 收银台订单查询
  • 支付状态查询
  • 切换网络 / 币种
  • 手动提交交易哈希补单
  • EPay submit.php 兼容接入
  • GMPay / EPay 回调验签
  • 订单二维码生成
  • 同步 EpusdtClient
  • 异步 AsyncEpusdtClient

安装

直接安装:

pip install epusdt

需要二维码功能:

pip install epusdt[qrcode]

升级到最新版:

pip install --upgrade epusdt

本地开发安装:

pip install -e .

补充说明:

  • base_url 推荐填写网关根地址,例如 https://pay.example.com
  • 如果你手里只有 EPay 地址,也可以直接填写 /payments/epay/v1/order/create-transaction 或完整 submit.php 地址,SDK 会自动识别
  • amount / money 支持 intfloatDecimal 和数字字符串
  • 同步场景使用 EpusdtClient
  • FastAPI、异步任务队列或高并发接口建议使用 AsyncEpusdtClient

快速开始

同步客户端

from epusdt import EpusdtClient

with EpusdtClient(
    base_url="https://pay.example.com",
    pid="1000",
    secret_key="epusdt_secret_key",
) as client:
    order = client.create_order(
        order_id="ORD202606240001",
        amount=100,
        currency="cny",
        token="USDT",
        network="tron",
        notify_url="https://merchant.example.com/notify",
        redirect_url="https://merchant.example.com/return",
        name="会员充值",
    )

    print(order.trade_id)
    print(order.payment_url)
    print(order.actual_amount)

异步客户端

import asyncio

from epusdt import AsyncEpusdtClient


async def main() -> None:
    async with AsyncEpusdtClient(
        base_url="https://pay.example.com",
        pid="1000",
        secret_key="epusdt_secret_key",
    ) as client:
        order = await client.create_order(
            order_id="ORD202606240099",
            amount=100,
            currency="cny",
            token="USDT",
            network="tron",
            notify_url="https://merchant.example.com/notify",
            redirect_url="https://merchant.example.com/return",
            name="会员充值",
        )

        print(order.trade_id)
        print(order.payment_url)


asyncio.run(main())

常见用法

查询支付配置

config = client.get_public_config()

for asset in config.supported_assets:
    print(asset.network, asset.tokens)

创建待选网络订单

placeholder = client.create_order(
    order_id="ORD202606240002",
    amount=88.5,
    currency="cny",
    notify_url="https://merchant.example.com/notify",
)

selected = client.switch_network(
    trade_id=placeholder.trade_id,
    token="USDT",
    network="solana",
)

print(selected.trade_id)
print(selected.receive_address)

查询订单和支付状态

checkout = client.get_checkout("20260523171652123456001")
status = client.check_status("20260523171652123456001")

print(checkout.payment_type)
print(status.status)

EPay 兼容接入

构造跳转地址:

url = client.build_epay_redirect_url(
    out_trade_no="ORD202606240003",
    money=100,
    notify_url="https://merchant.example.com/notify",
    return_url="https://merchant.example.com/return",
    name="会员充值",
)

print(url)

直接请求网关并获取收银台地址:

redirect = client.create_epay_order(
    out_trade_no="ORD202606240003",
    money=100,
    notify_url="https://merchant.example.com/notify",
    return_url="https://merchant.example.com/return",
)

print(redirect.checkout_url)

手动补单

result = client.submit_tx_hash(
    trade_id="20260523171652123456001",
    block_transaction_id="0xabc123",
)

print(result.status)
print(result.block_transaction_id)

回调验签

GMPay JSON 回调:

payload = {
    "pid": "1000",
    "trade_id": "20260523171652123456001",
    "order_id": "ORD202605230001",
    "amount": 100,
    "actual_amount": 14.29,
    "receive_address": "TTestTronAddress001",
    "token": "USDT",
    "block_transaction_id": "0xabc123",
    "status": 2,
    "signature": "a1b2c3",
}

callback = client.parse_gmpay_callback(payload)
print(callback.trade_id)

EPay GET 回调:

params = {
    "pid": "1000",
    "trade_no": "20260523171652123456001",
    "out_trade_no": "ORD202605230001",
    "type": "alipay",
    "name": "会员充值",
    "money": "100.0000",
    "trade_status": "TRADE_SUCCESS",
    "sign": "a1b2c3",
    "sign_type": "MD5",
}

callback = client.parse_epay_callback(params)
print(callback.out_trade_no)

生成二维码

order = client.get_checkout("20260523171652123456001")

image = order.generate_qrcode()
image.save("epusdt-payment.png")

示例代码

  • examples/basic_usage.py:基础下单示例
  • examples/async_basic_usage.py:异步基础下单示例
  • examples/flask_example.py:Flask 创建订单与回调处理示例
  • examples/fastapi_example.py:FastAPI 异步创建订单与回调处理示例

API 一览

  • AsyncEpusdtClient(...)
  • create_order(...)
  • get_public_config()
  • get_checkout(trade_id)
  • check_status(trade_id)
  • switch_network(trade_id, token, network)
  • submit_tx_hash(trade_id, block_transaction_id)
  • build_epay_params(...)
  • build_epay_redirect_url(...)
  • create_epay_order(...)
  • verify_gmpay_callback(payload)
  • verify_epay_callback(params)
  • parse_gmpay_callback(payload)
  • parse_epay_callback(params)

适用范围

当前版本面向 epusdt 商户公开支付接口,适合以下接入场景:

  • 服务端创建订单
  • 前端收银台支付
  • EPay 兼容接入
  • 支付回调验签
  • Flask / Django 等同步项目
  • FastAPI / 异步任务队列项目

验证情况

  • 单元测试通过
  • 构建通过
  • 干净虚拟环境安装通过
  • 安装后导入通过
  • 二维码功能烟测通过
  • 已完成线上网关联调验证
  • 同步与异步客户端都已覆盖测试

开发

python -m venv .venv
. .venv/bin/activate
pip install -U pip build pytest
pip install -e .
pytest
python -m build

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

epusdt-0.2.5.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

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

epusdt-0.2.5-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file epusdt-0.2.5.tar.gz.

File metadata

  • Download URL: epusdt-0.2.5.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for epusdt-0.2.5.tar.gz
Algorithm Hash digest
SHA256 107e494ce568239869ae4be9abf49af58615abf26e107d0369cce877ff1f156b
MD5 5f1b00536f142026b1f8b549599cc77d
BLAKE2b-256 3a26a0c7f42b94bbe6581cf6c3b7650ed69150bfd2f9f34393540d8af61f1bcb

See more details on using hashes here.

File details

Details for the file epusdt-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: epusdt-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for epusdt-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d00721f0fd2f6310185b151ab36dd48c05532eece49d8f8b9911e5cef62dae08
MD5 6021d20750256840407016098886d877
BLAKE2b-256 9d4854a635dcbaece3ec29ef1fc787e0ea7fbe6e45eacd83096ebbf3be76f433

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