diff --git a/backend/app.js b/backend/app.js index c6f8b28..65892e3 100644 --- a/backend/app.js +++ b/backend/app.js @@ -232,19 +232,22 @@ async function sendLineMessage(userId, message) { const channelID = '2006462420'; const channelSecret = '8c832c018d09a8be1738b32a3be1ee0a'; +// 生成唯一 ID 的函數 +const generateUniqueId = (prefix) => `${prefix}_${Date.now()}_${Math.floor(Math.random() * 1000)}`; + // 創建支付的 API app.post('/api/create-payment', async (req, res) => { const paymentData = { amount: 1000, currency: 'TWD', - orderId: `o_${Date.now()}`, // 生成唯一的訂單 ID + orderId: generateUniqueId('order'), // 生成唯一的訂單 ID packages: [ { - id: `p_${Date.now()}`, // 生成唯一的套餐 ID + id: generateUniqueId('package'), // 生成唯一的套餐 ID amount: 1000, products: [ { - id: `pr_${Date.now()}`, // 生成唯一的商品 ID + id: generateUniqueId('product'), // 生成唯一的商品 ID name: '商品名稱', quantity: 1, price: 1000, @@ -263,6 +266,7 @@ app.post('/api/create-payment', async (req, res) => { }, }); + console.log('API Response:', response.data); if (response.data && response.data.info && response.data.info.paymentUrl) { res.json({ returnUrl: response.data.info.paymentUrl.web }); } else { @@ -279,3 +283,4 @@ app.post('/api/create-payment', async (req, res) => { }); } }); +