This commit is contained in:
xingyy 2025-02-28 19:29:43 +08:00
parent 38fc5d78ca
commit 437e74ee86

View File

@ -2,6 +2,7 @@
import { onMounted, ref } from 'vue'
import {authStore} from "~/stores/auth/index.js";
import {useRuntimeConfig} from "#app";
import {orderQuery} from "~/api/goods/index.js";
const {checkoutSessionUrl,payUid}= authStore()
const config = useRuntimeConfig()
definePageMeta({
@ -39,6 +40,32 @@ async function handleSubmit(e) {
e.preventDefault()
setLoading(true)
let pollTimer = null
let timeoutTimer = null
const startPolling = () => {
pollTimer = setInterval(async () => {
const res = await orderQuery({
orderNo: payUid.value
})
if (res.status === 0) {
if (res.data.status !== 3) {
clearInterval(pollTimer)
clearTimeout(timeoutTimer)
window.location.href = `${baseURL}/payment/result?orderNo=${payUid.value}`
}
}
}, 1000) // 3
timeoutTimer = setTimeout(() => {
clearInterval(pollTimer)
showMessage('支付超时,请重试')
setLoading(false)
}, 180000) // 3
}
startPolling()
const { error } = await stripe.confirmPayment({
elements: elements.value,
confirmParams: {
@ -46,13 +73,16 @@ async function handleSubmit(e) {
},
})
if (error.type === "card_error" || error.type === "validation_error") {
showMessage(error.message)
} else {
showMessage("An unexpected error occurred.")
if (error) {
clearInterval(pollTimer)
clearTimeout(timeoutTimer)
if (error.type === "card_error" || error.type === "validation_error") {
showMessage(error.message)
} else {
showMessage("An unexpected error occurred.")
}
setLoading(false)
}
setLoading(false)
}
function showMessage(messageText) {