fenghe-auction/server/middleware/stripe.ts

25 lines
822 B
TypeScript
Raw Permalink Normal View History

2025-04-10 07:47:40 +00:00
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) {
throw createError({
statusCode: 500,
message: '创建支付意向失败'
})
}
}
})