Skip to content

Python 集成

請替換示例憑證

下方代碼示例使用了占位值。您必須將它們替換為您的實際憑證:

  • "your-api-key" → 從商戶後台獲取的實際 API Key
  • "your-api-secret" → 從商戶後台獲取的實際 API Secret
  • "1000" → 註冊時獲得的實際 Merchant ID

依賴項

bash
pip install requests

快速開始

python
from stablepay_client import StablePayClient
import time

# 創建客戶端
client = StablePayClient(
    base_url="https://api.paystablecoin.global",
    merchant_id="1000",
    api_key="your-api-key",
    api_secret="your-api-secret"
)

# 創建訂單
order_request = {
    "merchantOrderId": f"M_ORD_{int(time.time() * 1000)}",
    "orderAmount": {
        "value": "99.99",
        "currency": "USD"
    },
    "expiresAt": "2025-12-31T23:59:59Z",
    "returnUrl": "https://yoursite.com/payment/success",
    "paymentMethod": {
        "supportedCurrencies": ["USDT", "USDC"],
        "preferredChain": "TRON"
    }
}

response = client.create_order(order_request)
print(response)

# 查詢訂單
order = client.query_order(f"M_ORD_{int(time.time() * 1000)}")
print(order)

完整示例

完整的 SDK 實現請參見 examples/python/stablepay_client.py

主要特性:

  • 自動簽名計算
  • 支持 POST (創建) 和 GET (查詢) 操作
  • 內置錯誤處理
  • 使用 requests 庫

運行示例:

bash
cd examples/python
python stablepay_client.py

相關文檔

Released under the MIT License.