# unipay/core.py from abc import ABC, abstractmethod from typing import Any, Dict class GatewayError(Exception): pass class Gateway(ABC): """ 抽象统一支付网关接口。 实现应异步(aiohttp)。 """ @abstractmethod async def create_payment(self, payload: Dict[str, Any]) -> Dict[str, Any]: """ 创建支付订单。 payload 包含:amount, currency, subject/description, return_url, notify_url, customer/context 等 返回标准字典,包含至少:{"provider":"wechat|alipay|paypal|stripe", "data": {...}} """ raise NotImplementedError @abstractmethod async def refund(self, payload: Dict[str, Any]) -> Dict[str, Any]: """ 发起退款。 payload 内常见字段:out_trade_no, out_refund_no, amount, total_amount, reason """ raise NotImplementedError @abstractmethod async def query(self, payload: Dict[str, Any]) -> Dict[str, Any]: """ 查询订单或退款状态。 """ raise NotImplementedError @abstractmethod async def handle_notify(self, headers: Dict[str,str], body: str) -> Dict[str, Any]: """ 验签并解密回调,返回解密后的标准 dict(包括 out_trade_no, status, attach 等) """ raise NotImplementedError