unipay/unipay/core.py
2025-12-04 18:28:17 +08:00

45 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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