fix topup msg
This commit is contained in:
parent
8c12ec72a1
commit
ace22f60a9
@ -145,7 +145,7 @@
|
|||||||
"topUp": "Top Up",
|
"topUp": "Top Up",
|
||||||
"enterAmount": "Enter amount to top up",
|
"enterAmount": "Enter amount to top up",
|
||||||
"quickAmounts": "Quick amounts",
|
"quickAmounts": "Quick amounts",
|
||||||
"topUpNote": "Note: This is a development environment. No real payment will be processed.",
|
"topUpNote": "For any top-up issues, please contact qsongtianlun@gmail.com",
|
||||||
"processing": "Processing...",
|
"processing": "Processing...",
|
||||||
"topUpNow": "Top Up Now",
|
"topUpNow": "Top Up Now",
|
||||||
"cancel": "Cancel",
|
"cancel": "Cancel",
|
||||||
|
@ -145,7 +145,7 @@
|
|||||||
"topUp": "充值",
|
"topUp": "充值",
|
||||||
"enterAmount": "请输入充值金额",
|
"enterAmount": "请输入充值金额",
|
||||||
"quickAmounts": "快捷金额",
|
"quickAmounts": "快捷金额",
|
||||||
"topUpNote": "注意:这是开发环境,不会进行真实的支付处理。",
|
"topUpNote": "充值遇到任何问题,请联系邮箱 qsongtianlun@gmail.com",
|
||||||
"processing": "处理中...",
|
"processing": "处理中...",
|
||||||
"topUpNow": "立即充值",
|
"topUpNow": "立即充值",
|
||||||
"cancel": "取消",
|
"cancel": "取消",
|
||||||
@ -447,7 +447,6 @@
|
|||||||
"runName": "运行名称",
|
"runName": "运行名称",
|
||||||
"cannotEditExecutedRun": "已运行的记录无法编辑",
|
"cannotEditExecutedRun": "已运行的记录无法编辑",
|
||||||
"runUpdated": "运行记录更新成功",
|
"runUpdated": "运行记录更新成功",
|
||||||
"selectModel": "选择模型",
|
|
||||||
"execute": "执行",
|
"execute": "执行",
|
||||||
"executing": "执行中...",
|
"executing": "执行中...",
|
||||||
"generating": "生成中...",
|
"generating": "生成中...",
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
import { NextResponse } from 'next/server'
|
import { NextResponse } from 'next/server'
|
||||||
import { createServerSupabaseClient } from '@/lib/supabase-server'
|
import { createServerSupabaseClient } from '@/lib/supabase-server'
|
||||||
import { addCredit } from '@/lib/services/credit'
|
|
||||||
import { prisma } from '@/lib/prisma'
|
|
||||||
|
|
||||||
export async function POST(request: Request) {
|
export async function POST(request: Request) {
|
||||||
try {
|
try {
|
||||||
@ -31,53 +29,15 @@ export async function POST(request: Request) {
|
|||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否是开发环境
|
// 统一重定向到 Stripe 支付
|
||||||
const isDevelopment = process.env.NODE_ENV === 'development'
|
return NextResponse.json(
|
||||||
|
{
|
||||||
if (isDevelopment) {
|
success: false,
|
||||||
// 开发环境:模拟充值成功
|
message: 'Please use Stripe payment',
|
||||||
console.log(`🧪 Development mode: Simulating top-up of $${amount} for user ${user.id}`)
|
redirectTo: '/api/credits/stripe-topup'
|
||||||
|
},
|
||||||
// 确保用户存在于数据库中
|
{ status: 200 }
|
||||||
await prisma.user.upsert({
|
)
|
||||||
where: { id: user.id },
|
|
||||||
update: {
|
|
||||||
email: user.email || '',
|
|
||||||
updatedAt: new Date()
|
|
||||||
},
|
|
||||||
create: {
|
|
||||||
id: user.id,
|
|
||||||
email: user.email || '',
|
|
||||||
username: user.user_metadata?.username || null,
|
|
||||||
subscriptionPlanId: 'free',
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const creditTransaction = await addCredit(
|
|
||||||
user.id,
|
|
||||||
amount,
|
|
||||||
'user_purchase',
|
|
||||||
`Development top-up: $${amount}`,
|
|
||||||
)
|
|
||||||
|
|
||||||
return NextResponse.json({
|
|
||||||
success: true,
|
|
||||||
message: `Successfully topped up $${amount}`,
|
|
||||||
transaction: creditTransaction
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
// 生产环境:重定向到 Stripe 支付
|
|
||||||
return NextResponse.json(
|
|
||||||
{
|
|
||||||
success: false,
|
|
||||||
message: 'Please use Stripe payment for production',
|
|
||||||
redirectTo: '/api/credits/stripe-topup'
|
|
||||||
},
|
|
||||||
{ status:200 }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Top-up failed:', error)
|
console.error('Top-up failed:', error)
|
||||||
|
Loading…
Reference in New Issue
Block a user