-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
28 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
// payment.js | ||
|
||
// 當用戶點擊支付按鈕時的事件 | ||
// payment.js 當用戶點擊支付按鈕時的事件 | ||
document.getElementById('payButton').addEventListener('click', function() { | ||
// 發送支付請求 | ||
fetch('/api/create-payment') // 替換為您的後端路由 | ||
.then(response => response.json()) | ||
.then(data => { | ||
if (data.returnUrl) { | ||
// 將用戶導向 LINE Pay 的支付頁面 | ||
window.location.href = data.returnUrl; | ||
} else { | ||
alert('支付請求失敗:' + data.message); | ||
} | ||
fetch('/api/create-payment', { // 使用 POST 方法 | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ | ||
productName: '商品名稱', // 這裡填寫商品名稱等必要資料 | ||
amount: 1000 // 這裡填寫支付金額等必要資料 | ||
// 根據你的需求可以添加更多的支付數據 | ||
}) | ||
.catch(error => { | ||
console.error('Error:', error); | ||
}); | ||
}) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error('網絡錯誤:' + response.status); | ||
} | ||
return response.json(); | ||
}) | ||
.then(data => { | ||
if (data.returnUrl) { | ||
// 將用戶導向 LINE Pay 的支付頁面 | ||
window.location.href = data.returnUrl; | ||
} else { | ||
alert('支付請求失敗:' + data.message); | ||
} | ||
}) | ||
.catch(error => { | ||
console.error('Error:', error); | ||
}); | ||
}); |