56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import sys
|
|
import os
|
|
from datetime import datetime
|
|
|
|
# 添加项目根目录到 Python 路径
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from utils.upay import Upay
|
|
|
|
def main():
|
|
"""
|
|
UPay 创建订单示例
|
|
"""
|
|
# 初始化 UPay 客户端
|
|
upay = Upay()
|
|
|
|
# 生成唯一的商户订单号
|
|
merchant_order_no = f"Order{datetime.now().strftime('%Y%m%d%H%M%S')}"
|
|
|
|
# 订单参数
|
|
order_params = {
|
|
'merchant_order_no': merchant_order_no,
|
|
'chain_type': '1', # 1: 波场TRC20
|
|
'fiat_amount': '50.00', # 法币金额
|
|
'fiat_currency': 'USD', # 美元
|
|
'notify_url': 'https://your-domain.com/callback', # 回调地址
|
|
'attach': 'custom_data_123', # 自定义数据
|
|
'product_name': 'T-shirt', # 商品名称
|
|
'redirect_url': 'https://your-domain.com/success' # 成功跳转地址
|
|
}
|
|
|
|
print("正在创建订单...")
|
|
print(f"商户订单号: {merchant_order_no}")
|
|
|
|
# 创建订单
|
|
result = upay.create_order(**order_params)
|
|
|
|
# 处理结果
|
|
if 'code' in result and result['code'] == 200:
|
|
data = result['data']
|
|
print("\n✅ 订单创建成功!")
|
|
print(f"UPay 订单号: {data['orderNo']}")
|
|
print(f"汇率: {data['exchangeRate']}")
|
|
print(f"加密货币金额: {data['crypto']} USDT")
|
|
print(f"订单状态: {data['status']}")
|
|
print(f"收银台链接: {data['payUrl']}")
|
|
print("\n用户可以通过收银台链接进行支付")
|
|
else:
|
|
print("\n❌ 订单创建失败!")
|
|
print(f"错误信息: {result}")
|
|
|
|
if __name__ == "__main__":
|
|
main() |