Files
Mycontent/app/api/payment/notify/[gateway]/route.js
2025-12-29 14:01:37 +08:00

21 lines
652 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Order } from '../../../../models/Order';
import { connectDB } from '../../../../lib/db';
export async function POST(req, { params }) {
await connectDB();
const { gateway } = await params;
const data = await req.json();
// 根据gateway处理通知并更新订单状态
// 这是一个简化版本实际需要验证签名和处理不同gateway的逻辑
const orderId = data.out_trade_no || data.order_id || data.metadata?.order_id;
if (orderId) {
const order = await Order.findById(orderId);
if (order) {
order.status = 'paid';
await order.save();
}
}
return Response.json({ success: true });
}