From e7cd4ff9ba10aca5baef9c4310d19cdd60372198 Mon Sep 17 00:00:00 2001 From: xingyy <64720302+Concur-max@users.noreply.github.com> Date: Sun, 2 Mar 2025 11:19:45 +0800 Subject: [PATCH] =?UTF-8?q?refactor(payment):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E6=B5=81=E7=A8=8B=E5=92=8C=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 authStore 中的 payUid 和 checkoutSessionUrl - 更新 checkoutPage 组件,使用路由参数传递支付相关信息- 修改 payment 页面逻辑,适应新的支付流程 - 删除未使用的 payment/checkoutPage 组件 --- app/pages/checkoutPage/index.vue | 21 +- app/pages/collectCode/payment/index.vue | 12 +- app/pages/payment/checkoutPage/index.vue | 373 ----------------------- app/pages/payment/index.vue | 14 +- app/stores/auth/index.js | 2 - 5 files changed, 27 insertions(+), 395 deletions(-) delete mode 100644 app/pages/payment/checkoutPage/index.vue diff --git a/app/pages/checkoutPage/index.vue b/app/pages/checkoutPage/index.vue index 6e085ca..4b871c7 100644 --- a/app/pages/checkoutPage/index.vue +++ b/app/pages/checkoutPage/index.vue @@ -3,7 +3,6 @@ import { onMounted, ref } from 'vue' import {authStore} from "~/stores/auth/index.js"; import {orderQuery} from "~/api/goods/index.js"; import { WebSocketClient } from '@/utils/websocket' -const {checkoutSessionUrl,payUid}= authStore() const config = useRuntimeConfig() definePageMeta({ layout: 'default', @@ -11,7 +10,7 @@ definePageMeta({ }) const stripe = Stripe(config.public.NUXT_PUBLIC_PKEY) - +const route = useRoute() const baseURL = config.public.NUXT_PUBLIC_API_BASE const items = [{ id: "xl-tshirt", amount: 1000 }] const elements = ref(null) @@ -24,16 +23,16 @@ const router = useRouter() const startPolling = () => { pollTimer = setInterval(async () => { const res = await orderQuery({ - orderNo: payUid.value + orderNo: route.query.payUid }) if (res.status === 0) { if (res.data.status !== 3) { clearInterval(pollTimer) clearTimeout(timeoutTimer) router.replace({ - path: '/payment/result', + path: route.query.returnUrl, query: { - orderNo: payUid.value + orderNo: route.query.payUid } }) } @@ -51,15 +50,15 @@ const watchWebSocket = () => { config.public.NUXT_PUBLIC_SOCKET_URL ) const ws = wsClient.connect('/api/v1/order/ws/v2', { - PayUid: payUid.value, + PayUid: route.query.payUid, }) ws.onOpen(() => { }) ws.onMessage((event) => { router.replace({ - path: '/payment/result', + path: route.query.returnUrl, query: { - orderNo: payUid.value + orderNo: route.query.payUid } }) }) @@ -67,9 +66,7 @@ const watchWebSocket = () => { }) } async function initialize() { - const clientSecret = checkoutSessionUrl.value - - + const clientSecret = route.query.stripeKey const appearance = { theme: 'stripe', } @@ -92,7 +89,7 @@ async function handleSubmit(e) { const { error } = await stripe.confirmPayment({ elements: elements.value, confirmParams: { - return_url: `${baseURL}/payment/result?orderNo=${payUid.value}`, + return_url: `${baseURL}/payment/result?orderNo=${route.query.payUid}`, }, }) diff --git a/app/pages/collectCode/payment/index.vue b/app/pages/collectCode/payment/index.vue index f830004..28f5b91 100644 --- a/app/pages/collectCode/payment/index.vue +++ b/app/pages/collectCode/payment/index.vue @@ -43,8 +43,16 @@ const confirmPay = async () => { if (res.status === 0) { codePKey.value=res.data.checkoutSessionUrl codePayUid.value=res.data.payUid - router.push('/collectCode/payment/checkoutPage') - // window.location.href = res.data.checkoutSessionUrl + checkoutSessionUrl.value=res.data.checkoutSessionUrl + payUid.value=res.data.payUid + router.push({ + path:'/checkoutPage', + query:{ + payUid:res.data.payUid, + returnUrl:'/collectCode/payment/result', + stripeKey:res.data.checkoutSessionUrl + } + }) } diff --git a/app/pages/payment/checkoutPage/index.vue b/app/pages/payment/checkoutPage/index.vue deleted file mode 100644 index f4251e3..0000000 --- a/app/pages/payment/checkoutPage/index.vue +++ /dev/null @@ -1,373 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/pages/payment/index.vue b/app/pages/payment/index.vue index 2e4e4a2..618afc4 100644 --- a/app/pages/payment/index.vue +++ b/app/pages/payment/index.vue @@ -41,14 +41,16 @@ const confirmPay=async ()=>{ }) if (res.status===0){ - - // if (res.status===0){ - // window.location.href=res.data.checkoutSessionUrl - // } - checkoutSessionUrl.value=res.data.checkoutSessionUrl payUid.value=res.data.payUid - router.push('/checkoutPage') + router.push({ + path:'/checkoutPage', + query:{ + payUid:res.data.payUid, + returnUrl:'/payment/result', + stripeKey:res.data.checkoutSessionUrl + } + }) } } const handleInput = (e) => { diff --git a/app/stores/auth/index.js b/app/stores/auth/index.js index 5b1ca8b..bd6739d 100644 --- a/app/stores/auth/index.js +++ b/app/stores/auth/index.js @@ -15,8 +15,6 @@ export const authStore = createGlobalState(() => { buyUid:'', auctionArtworkUuid:'' }) - const router=useRouter() - const config = useRuntimeConfig() const payUid=useLocalStorage('payUid','') return{ payUid,