2026-01-21 15:49:12 +08:00
|
|
|
/**
|
|
|
|
|
* 支付回调接口
|
|
|
|
|
* 开发: 卡若
|
|
|
|
|
* 技术支持: 存客宝
|
|
|
|
|
*/
|
2026-01-09 11:58:08 +08:00
|
|
|
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
|
|
|
|
|
|
2026-01-21 15:49:12 +08:00
|
|
|
console.log("[Karuo] Payment callback received:", {
|
2026-01-09 11:58:08 +08:00
|
|
|
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
|
2026-01-21 15:49:12 +08:00
|
|
|
console.log("[Karuo] Payment successful, granting access for order:", orderId)
|
2026-01-09 11:58:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NextResponse.json({
|
|
|
|
|
code: 0,
|
|
|
|
|
message: "回调处理成功",
|
|
|
|
|
})
|
|
|
|
|
} catch (error) {
|
2026-01-21 15:49:12 +08:00
|
|
|
console.error("[Karuo] Payment callback error:", error)
|
2026-01-09 11:58:08 +08:00
|
|
|
return NextResponse.json({ code: 500, message: "服务器错误" }, { status: 500 })
|
|
|
|
|
}
|
|
|
|
|
}
|