修复支付取消的调用和规定时间内更新订单支付状态

This commit is contained in:
Eamon-meng
2025-08-16 11:41:07 +08:00
parent 1baa7c94dc
commit 99c3b9914e
7 changed files with 105 additions and 98 deletions

View File

@@ -1,5 +1,5 @@
'use client'
import {Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle} from '@/components/ui/dialog'
import {Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTitle} from '@/components/ui/dialog'
import {Button} from '@/components/ui/button'
import balance from './_assets/balance.svg'
import Image from 'next/image'
@@ -39,13 +39,14 @@ export default function Pay(props: PayProps) {
const method = props.method === 'alipay'
? TradeMethod.SftAlipay
: TradeMethod.SftWechat
const res = {
const req = {
...props.resource,
payment_method: method,
payment_platform: platform,
}
const resp = await prepareResource(res)
const resp = await prepareResource(req)
if (!resp.success) {
toast.error(`创建订单失败: ${resp.message}`)
setOpen(false)
@@ -62,10 +63,9 @@ export default function Pay(props: PayProps) {
})
}
const onSubmit = async () => {
const purchase = async (showFail: boolean) => {
try {
let resp: Awaited<ReturnType<typeof completeResource>> | Awaited<ReturnType<typeof createResource>>
if (props.method === 'balance') {
resp = await createResource(props.resource)
}
@@ -79,22 +79,26 @@ export default function Pay(props: PayProps) {
throw new Error('支付信息不存在')
}
if (!resp.success) throw new Error(resp.message)
if (!resp.success) {
throw new Error(resp.message)
}
setOpen(false)
setTrade(null)
toast.success('购买成功', {
action: {
label: '去提取',
onClick: () => router.push('/admin/extract'),
},
})
setOpen(false)
await refreshProfile()
refreshProfile()
}
catch (e) {
toast.error('购买失败', {
description: (e as Error).message,
})
if (showFail) {
toast.error('购买失败', {
description: (e as Error).message,
})
}
}
}
@@ -164,38 +168,25 @@ export default function Pay(props: PayProps) {
<DialogFooter>
<Button
disabled={!balanceEnough}
onClick={onSubmit}
onClick={() => purchase(true)}
>
</Button>
<Button theme="outline" onClick={() => setOpen(false)}>
</Button>
<DialogClose asChild>
<Button theme="outline" onClick={() => setOpen(false)}>
</Button>
</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
)}
{/* 支付宝/微信支付使用公共组件 */}
{/* 支付宝/微信支付 */}
{props.method !== 'balance' && trade && (
<PaymentModal
{...trade}
onConfirm={async () => {
try {
const resp = await completeResource({trade_no: trade.inner_no, method: trade.method})
if (!resp.success) {
throw new Error(resp.message)
}
toast.success('支付成功')
setTrade(null)
setOpen(false)
refreshProfile()
}
catch (e) {
toast.error('支付验证失败', {description: (e as Error).message})
}
}}
onConfirm={purchase}
onClose={() => {
setTrade(null)
setOpen(false)