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,