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 17, 2024
1 parent 9033f1c commit c58b3d4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,18 @@ const Transaction = mongoose.model('Transaction', transactionSchema);
// 實現 getTransactionDetails 函數
async function getTransactionDetails(transactionId) {
try {
const transaction = await Transaction.findOne({ transactionId }); // 查詢交易
return transaction; // 返回查詢到的交易資料
const transaction = await Transaction.findOne({ transactionId });
if (!transaction) {
console.log('未找到交易資料,transactionId:', transactionId);
}
return transaction;
} catch (error) {
console.error('查詢交易資料錯誤:', error);
return null; // 返回 null 以便上層處理
return null;
}
}


// LINE Pay API 配置
const channelID = '2006462420';
const channelSecret = '8c832c018d09a8be1738b32a3be1ee0a';
Expand Down Expand Up @@ -288,6 +292,8 @@ app.post('/api/create-payment', async (req, res) => {
currency,
status: '待處理' // 或根據實際情況設置狀態
});

console.log('儲存交易資料:', transaction);
await transaction.save();

res.json({ returnUrl: response.data.info.paymentUrl.web });
Expand All @@ -310,7 +316,7 @@ app.get('/api/transaction', async (req, res) => {

// 查詢交易細節
const transactionDetails = await getTransactionDetails(transactionId);

console.log('查詢的 transactionId:', transactionId);
if (transactionDetails) {
// 根據交易狀態決定是否重定向
if (transactionDetails.status === '成功') {
Expand Down

0 comments on commit c58b3d4

Please sign in to comment.