Skip to main content

Python SDK for GMWalletApp/epusdt GMPay and EPay integrations

Project description

Epusdt Python SDK

epusdt 的 Python SDK,按 GMWalletApp/epusdt 当前公开支付接口实现。

当前已覆盖的商户接入能力:

  • POST /payments/gmpay/v1/order/create-transaction
  • GET /payments/gmpay/v1/config
  • GET /pay/checkout-counter-resp/{trade_id}
  • GET /pay/check-status/{trade_id}
  • POST /pay/switch-network
  • POST /pay/submit-tx-hash/{trade_id}
  • GET/POST /payments/epay/v1/order/create-transaction/submit.php
  • GMPay / EPay 两套回调验签

安装

当前版本已经把包名配置为 epusdt,但还没有发布到 PyPI。

所以现在可用的安装方式是:

pip install git+https://github.com/Yufeifeio/epusdt-python-sdk.git

如果要启用二维码功能:

pip install "epusdt[qrcode] @ git+https://github.com/Yufeifeio/epusdt-python-sdk.git"

如果以后发布到 PyPI,就可以直接使用:

pip install epusdt
pip install epusdt[qrcode]
pip install --upgrade epusdt

本地开发安装:

pip install -e .

功能说明

  • 使用 pid + secret_key
  • 主下单入口是 GMPay v1
  • 支持创建 status=4 占位订单
  • 支持后续 switch-network
  • 支持 submit-tx-hash 手动补单
  • 支持 EPay submit.php 重定向模式
  • 支持 GMPay JSON 回调验签
  • 支持 EPay GET 回调验签
  • 支持二维码生成功能(可选依赖)

快速开始

from epusdt import EpusdtClient

client = EpusdtClient(
    base_url="https://pay.example.com",
    pid="1000",
    secret_key="epusdt_secret_key",
)

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="VIP",
)

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

占位订单

如果你要先创建订单,再让用户在收银台选择网络和币种:

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

print(placeholder.status)   # OrderStatus.WAITING_SELECTION
print(placeholder.trade_id)

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

EPay 兼容模式

构造 submit.php 跳转地址:

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="VIP",
)

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": "VIP",
    "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")

base64_data = order.get_qrcode_base64()
data_uri = order.get_qrcode_data_uri()

API 一览

  • 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)

开发

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.0.tar.gz (16.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.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: epusdt-0.2.0.tar.gz
  • Upload date:
  • Size: 16.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.0.tar.gz
Algorithm Hash digest
SHA256 10e0f1628df7c7f489441ad07e39f9ba5db2d65d0c79cb9e4530eed74b2ddab8
MD5 e2c1dcac13bffbbaaf423fb936c7112e
BLAKE2b-256 b725c636948ee091277570c1dd6b4f86d9d07a3885f235c634ff67dfcc3b7a90

See more details on using hashes here.

File details

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

File metadata

  • Download URL: epusdt-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.4 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a9a42aba73312a8d8669a356794b1a45d54546124234451cd017bdc56e6cbeb
MD5 b521e1aaa804d9f7f310d5cfa22079df
BLAKE2b-256 3b374b931e1627284c601f25f9f8edb728d2e096033844ed494e4bd94d0b2cf8

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