This commit is contained in:
yumoqing 2025-12-18 14:16:35 +08:00
parent 64a2a89929
commit 3c94e3c7a4
3 changed files with 11 additions and 16 deletions

View File

@ -124,18 +124,13 @@ async def refund_payment(request, params_kw=None):
raise e
# 回调入口:你可把厂商回调用各自 endpoint 再转发到这里,或在厂商控制台按各自 URL 配置
async def payment_notify(request, params_kw=None):
if params_kw is None:
params_kw = request.params_kw
provider = params_kw.provider
async def payment_notify(request, provider, params_kw):
if PROVIDERS[provider] is None:
e = Exception(f'{provider} cannot pay')
exception(f'{e}')
return
try:
headers = dict(request.headers)
body = await request.text()
data = await PROVIDERS[provider].handle_notify(headers, body)
data = await PROVIDERS[provider].handle_notify(request, params_kw)
except Exception as e:
e = Exception(f'{provider} cannot pay')
exception(f'{e}')

View File

@ -60,6 +60,7 @@ class PaymentLog:
async with self.db.sqlorContext(dbname) as sor:
ns = {
"id": logid,
"payment_status":'1',
"payed_timestamp": timestampstr()
}
await sor.U('payment_log', ns)
@ -76,18 +77,18 @@ async def unipay_accounting(request, data):
db = DBPools()
dbname = env.get_module_dbname('unipay')
async with db.sqlorContext(dbname) as sor:
recs = await sor.R('payment_log', {'id', logid})
recs = await sor.R('payment_log', {'id': logid})
if len(recs) < 1:
e = Exception(f'{logid} not found {data=}')
exception(f'{e}')
raise e
r = recs[0]
if r.status == '2':
e = Exception(f'{logid} payment_log status({r.status}) is already accounted')
if r.payment_status == '2':
e = Exception(f'{logid} payment_log status({r.payment_status}) is already accounted')
exception(f'{e}')
return True
if r.status != '1':
e = Exception(f'{logid} payment_log status({r.status}) not correct')
if r.payment_status != '1':
e = Exception(f'{logid} payment_log status({r.payment_status}) not correct')
exception(f'{e}')
return False
await env.recharge_accounting(sor,
@ -99,7 +100,7 @@ async def unipay_accounting(request, data):
r.pay_feerate
)
await sor.U('payment_log', {'id': logid,
'status': '2',
'payment_status': '2',
'channel_trade_id': trade_id
})

View File

@ -192,13 +192,12 @@ class AlipayGateway(Gateway):
# 回调 / 异步通知(验签)
# ==============================================================================
async def handle_notify(self, request) -> Dict[str, Any]:
async def handle_notify(self, request, params) -> Dict[str, Any]:
"""
支付宝异步通知验签
"""
self.setup_session()
form = await request.post()
params = dict(form)
"""
sign = params.pop("sign", None)
sign_type = params.pop("sign_type", None)