fix addup
This commit is contained in:
parent
ace22f60a9
commit
4c953dbe5f
@ -195,47 +195,22 @@ export default function CreditsPage() {
|
|||||||
|
|
||||||
setIsTopUpLoading(true)
|
setIsTopUpLoading(true)
|
||||||
try {
|
try {
|
||||||
// 首先检查是否是开发环境
|
// 统一使用 Stripe 支付
|
||||||
const isDevelopment = process.env.NODE_ENV === 'development'
|
const response = await fetch('/api/credits/stripe-topup', {
|
||||||
|
method: 'POST',
|
||||||
if (isDevelopment) {
|
headers: {
|
||||||
// 开发环境:使用模拟充值
|
'Content-Type': 'application/json',
|
||||||
const response = await fetch('/api/credits/topup', {
|
},
|
||||||
method: 'POST',
|
body: JSON.stringify({ amount }),
|
||||||
headers: {
|
})
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ amount }),
|
|
||||||
})
|
|
||||||
|
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
|
|
||||||
if (response.ok && data.success) {
|
if (response.ok && data.success && data.sessionUrl) {
|
||||||
alert(`Successfully topped up $${amount}!`)
|
// 重定向到 Stripe Checkout
|
||||||
setShowTopUpModal(false)
|
window.location.href = data.sessionUrl
|
||||||
setTopUpAmount('')
|
|
||||||
loadCreditData()
|
|
||||||
} else {
|
|
||||||
alert(data.error || 'Failed to process top-up')
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// 生产环境:使用 Stripe
|
alert(data.error || 'Failed to create payment session')
|
||||||
const response = await fetch('/api/credits/stripe-topup', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ amount }),
|
|
||||||
})
|
|
||||||
|
|
||||||
const data = await response.json()
|
|
||||||
|
|
||||||
if (response.ok && data.success && data.sessionUrl) {
|
|
||||||
// 重定向到 Stripe Checkout
|
|
||||||
window.location.href = data.sessionUrl
|
|
||||||
} else {
|
|
||||||
alert(data.error || 'Failed to create payment session')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Top-up error:', error)
|
console.error('Top-up error:', error)
|
||||||
|
Loading…
Reference in New Issue
Block a user