1212
This commit is contained in:
parent
38fc5d78ca
commit
437e74ee86
@ -2,6 +2,7 @@
|
|||||||
import { onMounted, ref } from 'vue'
|
import { onMounted, ref } from 'vue'
|
||||||
import {authStore} from "~/stores/auth/index.js";
|
import {authStore} from "~/stores/auth/index.js";
|
||||||
import {useRuntimeConfig} from "#app";
|
import {useRuntimeConfig} from "#app";
|
||||||
|
import {orderQuery} from "~/api/goods/index.js";
|
||||||
const {checkoutSessionUrl,payUid}= authStore()
|
const {checkoutSessionUrl,payUid}= authStore()
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
@ -39,6 +40,32 @@ async function handleSubmit(e) {
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
setLoading(true)
|
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({
|
const { error } = await stripe.confirmPayment({
|
||||||
elements: elements.value,
|
elements: elements.value,
|
||||||
confirmParams: {
|
confirmParams: {
|
||||||
@ -46,13 +73,16 @@ async function handleSubmit(e) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
clearInterval(pollTimer)
|
||||||
|
clearTimeout(timeoutTimer)
|
||||||
if (error.type === "card_error" || error.type === "validation_error") {
|
if (error.type === "card_error" || error.type === "validation_error") {
|
||||||
showMessage(error.message)
|
showMessage(error.message)
|
||||||
} else {
|
} else {
|
||||||
showMessage("An unexpected error occurred.")
|
showMessage("An unexpected error occurred.")
|
||||||
}
|
}
|
||||||
|
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showMessage(messageText) {
|
function showMessage(messageText) {
|
||||||
|
Loading…
Reference in New Issue
Block a user