From 437e74ee869d69a360c6c5e58eb803f33ce2e1ef Mon Sep 17 00:00:00 2001 From: xingyy <64720302+Concur-max@users.noreply.github.com> Date: Fri, 28 Feb 2025 19:29:43 +0800 Subject: [PATCH] 1212 --- app/pages/payment/checkoutPage/index.vue | 42 ++++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/app/pages/payment/checkoutPage/index.vue b/app/pages/payment/checkoutPage/index.vue index a087f7c..2ff0fc6 100644 --- a/app/pages/payment/checkoutPage/index.vue +++ b/app/pages/payment/checkoutPage/index.vue @@ -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) {