diff --git a/app/api-collect-code/goods/index.js b/app/api-collect-code/goods/index.js index 60a5206..f95a0e3 100644 --- a/app/api-collect-code/goods/index.js +++ b/app/api-collect-code/goods/index.js @@ -56,7 +56,7 @@ export async function offlineQrcode(data) { export async function createOrder(data) { return await request( { - url:'/api/v1/offlineQrcode/createOrder', + url:'/api/v1/offlineQrcode/createOrder/V2', method: 'POST', data }) diff --git a/app/components/StripeCheckout.vue b/app/components/StripeCheckout.vue new file mode 100644 index 0000000..7af9d93 --- /dev/null +++ b/app/components/StripeCheckout.vue @@ -0,0 +1,280 @@ + + + + + \ No newline at end of file diff --git a/app/pages/collectCode/payment/checkoutPage/index.vue b/app/pages/collectCode/payment/checkoutPage/index.vue new file mode 100644 index 0000000..08ddea6 --- /dev/null +++ b/app/pages/collectCode/payment/checkoutPage/index.vue @@ -0,0 +1,373 @@ + + + + + \ No newline at end of file diff --git a/app/pages/collectCode/payment/index.vue b/app/pages/collectCode/payment/index.vue index b3b408e..9223795 100644 --- a/app/pages/collectCode/payment/index.vue +++ b/app/pages/collectCode/payment/index.vue @@ -10,7 +10,7 @@ import {codeAuthStore} from "~/stores-collect-code/auth/index.js"; import {useI18n} from "vue-i18n"; const {t} = useI18n(); -const {checkoutSessionUrl,qrUid,qrData} = codeAuthStore() +const {checkoutSessionUrl,qrUid,qrData,codePKey,codePayUid} = codeAuthStore() const payStatus = ref(0) definePageMeta({ i18n: 'payment.title' @@ -40,7 +40,11 @@ const confirmPay = async () => { testReturnEndPoint: '/collectCode/payment/result' }) if (res.status === 0) { - window.location.href = res.data.checkoutSessionUrl + codePKey.value=res.data.checkoutSessionUrl + codePayUid.value=res.data.payUid + // window.location.href = res.data.checkoutSessionUrl + console.log('res',res); + } } @@ -75,8 +79,8 @@ const handleInput = (e) => { {{ qrData?.leftPrice }}
- +
{{ payStatus === 1 ? $t('collectCode.payment.fullPayment') : $t('collectCode.payment.partialPayment') }}
diff --git a/app/pages/payment/checkoutPage/index.vue b/app/pages/payment/checkoutPage/index.vue index 2ff0fc6..08ddea6 100644 --- a/app/pages/payment/checkoutPage/index.vue +++ b/app/pages/payment/checkoutPage/index.vue @@ -55,7 +55,7 @@ async function handleSubmit(e) { window.location.href = `${baseURL}/payment/result?orderNo=${payUid.value}` } } - }, 1000) // 每3秒轮询一次 + }, 1000) timeoutTimer = setTimeout(() => { clearInterval(pollTimer) diff --git a/app/stores-collect-code/auth/index.js b/app/stores-collect-code/auth/index.js index cad4d3f..987f9d4 100644 --- a/app/stores-collect-code/auth/index.js +++ b/app/stores-collect-code/auth/index.js @@ -26,7 +26,11 @@ export const codeAuthStore = createGlobalState(() => { currency:'' }) const qrData=useLocalStorage('qrData',{}) + const codePKey=useLocalStorage('codePKey','') + const codePayUid=useLocalStorage('codePayUid','') return{ + codePKey, + codePayUid, qrData, qrUid, cpayment, diff --git a/i18n/locales/en-US.json b/i18n/locales/en-US.json index 3a2ffbd..a1c81ee 100644 --- a/i18n/locales/en-US.json +++ b/i18n/locales/en-US.json @@ -423,7 +423,7 @@ "fullPayment": "Pay in Full", "partialPayment": "Partial Payment", "confirmPayment": "Confirm Payment", - "maxAmount": "Maximum {currency}{price}", + "maxAmount": "most", "enterAmount": "Please enter amount", "exceedTotal": "Cannot exceed total amount" }, diff --git a/i18n/locales/ja-JP.json b/i18n/locales/ja-JP.json index d6f053a..2309fb0 100644 --- a/i18n/locales/ja-JP.json +++ b/i18n/locales/ja-JP.json @@ -423,7 +423,7 @@ "fullPayment": "全額支払い", "partialPayment": "一部支払い", "confirmPayment": "支払い確認", - "maxAmount": "最大 {currency}{price}", + "maxAmount": "ほとんど", "enterAmount": "金額を入力してください", "exceedTotal": "合計金額を超えることはできません" }, diff --git a/i18n/locales/zh-CN.json b/i18n/locales/zh-CN.json index 60e8d0f..4bdc15a 100644 --- a/i18n/locales/zh-CN.json +++ b/i18n/locales/zh-CN.json @@ -426,7 +426,8 @@ "confirmPayment": "确认支付", "text1": "最多", "enterAmount": "请输入金额", - "exceedTotal": "不得高于全部金额" + "exceedTotal": "不得高于全部金额", + "maxAmount": "最多" }, "signature": { "resultText": "领取您的专属号牌", diff --git a/i18n/locales/zh-TW.json b/i18n/locales/zh-TW.json index aa08434..7d7509d 100644 --- a/i18n/locales/zh-TW.json +++ b/i18n/locales/zh-TW.json @@ -423,7 +423,7 @@ "fullPayment": "支付全部", "partialPayment": "支付部分", "confirmPayment": "確認支付", - "maxAmount": "最多{currency}{price}", + "maxAmount": "最多", "enterAmount": "請輸入金額", "exceedTotal": "不得高於全部金額" }, diff --git a/server/middleware/stripe.ts b/server/middleware/stripe.ts new file mode 100644 index 0000000..050c241 --- /dev/null +++ b/server/middleware/stripe.ts @@ -0,0 +1,26 @@ +export default defineEventHandler(async (event) => { + const url = getRequestURL(event) + + // 只处理 create-payment-intent 请求 + if (url.pathname === '/create-payment-intent' && event.method === 'POST') { + try { + const body = await readBody(event) + const { items } = body + + // 计算总金额 + const amount = items.reduce((total: number, item: any) => total + item.amount, 0) + + // 模拟创建支付意向的响应 + // 注意:clientSecret 格式应该类似于 'pi_xxxxx_secret_xxxxx' + return { + clientSecret: `pi_${Math.random().toString(36).substring(2)}_secret_${Math.random().toString(36).substring(2)}` + } + } catch (error) { + console.error('Create payment intent error:', error) + throw createError({ + statusCode: 500, + message: '创建支付意向失败' + }) + } + } +}) \ No newline at end of file