Files
soul/app/api/payment/callback/route.ts

47 lines
1.3 KiB
TypeScript
Raw Normal View History

import { type NextRequest, NextResponse } from "next/server"
export async function POST(request: NextRequest) {
try {
const body = await request.json()
const { orderId, status, transactionId, amount, paymentMethod, signature } = body
console.log("[v0] Payment callback received:", {
orderId,
status,
transactionId,
amount,
paymentMethod,
})
// In production:
// 1. Verify signature from payment gateway
// 2. Update order status in database
// 3. Grant user access to content
// 4. Calculate and distribute referral commission
// Mock signature verification
// const isValid = verifySignature(body, signature)
// For now, accept all callbacks
const isValid = true
if (!isValid) {
return NextResponse.json({ code: 403, message: "签名验证失败" }, { status: 403 })
}
// Update order status
if (status === "success") {
// Grant access
console.log("[v0] Payment successful, granting access for order:", orderId)
}
return NextResponse.json({
code: 0,
message: "回调处理成功",
})
} catch (error) {
console.error("[v0] Payment callback error:", error)
return NextResponse.json({ code: 500, message: "服务器错误" }, { status: 500 })
}
}