diff --git a/models/payment_log.xlsx b/models/payment_log.xlsx index d559b3a..ed3bae7 100644 Binary files a/models/payment_log.xlsx and b/models/payment_log.xlsx differ diff --git a/unipay/init.py b/unipay/init.py index d10f142..add3965 100644 --- a/unipay/init.py +++ b/unipay/init.py @@ -124,17 +124,7 @@ async def refund_payment(request, params_kw=None): exception(f'query_payment():{params_kw}, {e}') raise e -# 回调入口:你可把厂商回调用各自 endpoint 再转发到这里,或在厂商控制台按各自 URL 配置 -async def payment_notify_handle(request, data): - logid = data.params.out_trade_no - pl = PaymentLog(request._run_ns) - plog = await pl.payed_log(logid) - await unipay_accounting(request, data) - if provider == "wechat": - return {"code":"SUCCESS", "message":"OK"} - else: - return "OK" - +# 微信支付回调入口 async def wechat_notify(request): debug("wechat notify called .......") provider = 'wechat' @@ -142,18 +132,23 @@ async def wechat_notify(request): e = Exception(f'{provider} cannot pay') exception(f'{e}') return + data = None try: data = await PROVIDERS[provider].handle_notify(request) except Exception as e: e = Exception(f'{provider} cannot pay') exception(f'{e}') return + if data is None: + return {"code":"SUCCESS", "message":"OK"} + debug(f'{data=}') try: - await unipay_accounting(request, data) + await unipay_accounting(request, data.data) except Exception as e: exception(f'{e}') return {"code":"SUCCESS", "message":"OK"} +# 支付宝回调入口 async def alipay_notify(request): debug("alipay notify called .......") provider = 'alipay' diff --git a/unipay/providers/alipay.py b/unipay/providers/alipay.py index ac3130d..215cfc7 100644 --- a/unipay/providers/alipay.py +++ b/unipay/providers/alipay.py @@ -159,16 +159,17 @@ class AlipayGateway(Gateway): # 退款 # ============================================================================== - async def refund(self, *, out_trade_no: str, refund_amount: str, out_request_no: str) -> Dict[str, Any]: + async def refund(self, payload:DictObject) -> Dict[str, Any]: """ out_request_no 必须全局唯一(一个退款请求一个编号) """ self.setup_session() biz_content = { - "out_trade_no": out_trade_no, - "refund_amount": refund_amount, - "out_request_no": out_request_no + "out_trade_no": payload.origin_id, + "refund_amount": payload.refund_amount, + "out_request_no": payload.out_trade_no + "notify_url": payload.notify_url } params = { @@ -217,5 +218,10 @@ class AlipayGateway(Gateway): "provider": "alipay", "data": params, } - return DictObject(**ret) + ret = DictObject(**ret) + ret.data.action = 'UNKOWN' + if ret.data.notify_type == 'trade_status_sync': + ret.data.action = 'RECHARGE' + if ret.data.notify_type == 'refund_status_sync': + ret.data.action = 'RECHARGE_REVERSE'