feat(collectCode): 更新支付功能

- 使用 codeAuthStore 替代 authStore
- 修改支付相关变量和路由
- 在支付成功
This commit is contained in:
xingyy 2025-02-28 20:42:21 +08:00
parent 09bbd9ae14
commit 4b7a7ce285
2 changed files with 9 additions and 6 deletions

View File

@ -1,10 +1,11 @@
<script setup> <script setup>
import { onMounted, ref } from 'vue' import { onMounted, ref } from 'vue'
import {authStore} from "~/stores/auth/index.js"; import {codeAuthStore} from "@/stores-collect-code/auth/index.js";
import {useRuntimeConfig} from "#app"; import {useRuntimeConfig} from "#app";
import {orderQuery} from "~/api/goods/index.js"; import {orderQuery} from "~/api/goods/index.js";
const {checkoutSessionUrl,payUid}= authStore() const {codePKey,codePayUid} = codeAuthStore()
const config = useRuntimeConfig() const config = useRuntimeConfig()
definePageMeta({ definePageMeta({
layout: 'default', layout: 'default',
title: 'Stripe支付' title: 'Stripe支付'
@ -20,7 +21,7 @@ const isLoading = ref(false)
const showSpinner = ref(false) const showSpinner = ref(false)
async function initialize() { async function initialize() {
const clientSecret = checkoutSessionUrl.value const clientSecret = codePKey.value
console.log('clientSecret',clientSecret); console.log('clientSecret',clientSecret);
const appearance = { const appearance = {
@ -46,13 +47,13 @@ async function handleSubmit(e) {
const startPolling = () => { const startPolling = () => {
pollTimer = setInterval(async () => { pollTimer = setInterval(async () => {
const res = await orderQuery({ const res = await orderQuery({
orderNo: payUid.value orderNo: codePayUid.value
}) })
if (res.status === 0) { if (res.status === 0) {
if (res.data.status !== 3) { if (res.data.status !== 3) {
clearInterval(pollTimer) clearInterval(pollTimer)
clearTimeout(timeoutTimer) clearTimeout(timeoutTimer)
window.location.href = `${baseURL}/payment/result?orderNo=${payUid.value}` window.location.href = `${baseURL}/collectCode/payment/result?orderNo=${codePayUid.value}`
} }
} }
}, 1000) }, 1000)
@ -69,7 +70,7 @@ async function handleSubmit(e) {
const { error } = await stripe.confirmPayment({ const { error } = await stripe.confirmPayment({
elements: elements.value, elements: elements.value,
confirmParams: { confirmParams: {
return_url: `${baseURL}/payment/result?orderNo=${payUid.value}`, return_url: `${baseURL}/collectCode/payment/result?orderNo=${codePayUid.value}`,
}, },
}) })

View File

@ -19,6 +19,7 @@ const changePayStatus = () => {
payStatus.value = payStatus.value === 0 ? 1 : 0 payStatus.value = payStatus.value === 0 ? 1 : 0
} }
const amount = ref('') const amount = ref('')
const router = useRouter()
const confirmPay = async () => { const confirmPay = async () => {
if (payStatus.value === 1 && !amount.value) { if (payStatus.value === 1 && !amount.value) {
message.warning(t('collectCode.payment.enterAmount')) message.warning(t('collectCode.payment.enterAmount'))
@ -42,6 +43,7 @@ const confirmPay = async () => {
if (res.status === 0) { if (res.status === 0) {
codePKey.value=res.data.checkoutSessionUrl codePKey.value=res.data.checkoutSessionUrl
codePayUid.value=res.data.payUid codePayUid.value=res.data.payUid
router.push('/collectCode/payment/checkoutPage')
// window.location.href = res.data.checkoutSessionUrl // window.location.href = res.data.checkoutSessionUrl
console.log('res',res); console.log('res',res);