From 09bbd9ae14e82090b57b779eceb136ce46f1b201 Mon Sep 17 00:00:00 2001
From: xingyy <64720302+Concur-max@users.noreply.github.com>
Date: Fri, 28 Feb 2025 20:30:45 +0800
Subject: [PATCH] 12
---
app/api-collect-code/goods/index.js | 2 +-
app/components/StripeCheckout.vue | 280 +++++++++++++
.../payment/checkoutPage/index.vue | 373 ++++++++++++++++++
app/pages/collectCode/payment/index.vue | 12 +-
app/pages/payment/checkoutPage/index.vue | 2 +-
app/stores-collect-code/auth/index.js | 4 +
i18n/locales/en-US.json | 2 +-
i18n/locales/ja-JP.json | 2 +-
i18n/locales/zh-CN.json | 3 +-
i18n/locales/zh-TW.json | 2 +-
server/middleware/stripe.ts | 26 ++
11 files changed, 698 insertions(+), 10 deletions(-)
create mode 100644 app/components/StripeCheckout.vue
create mode 100644 app/pages/collectCode/payment/checkoutPage/index.vue
create mode 100644 server/middleware/stripe.ts
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