Skip to content

Commit

Permalink
Update app.js
Browse files Browse the repository at this point in the history
  • Loading branch information
CYHFREDA authored Oct 16, 2024
1 parent ecb410f commit 908945f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -279,3 +283,4 @@ app.post('/api/create-payment', async (req, res) => {
});
}
});

0 comments on commit 908945f

Please sign in to comment.