1212
This commit is contained in:
parent
38fc5d78ca
commit
437e74ee86
@ -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,14 +73,17 @@ async function handleSubmit(e) {
|
||||
},
|
||||
})
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
function showMessage(messageText) {
|
||||
paymentMessage.value = messageText
|
||||
|
Loading…
Reference in New Issue
Block a user