2026-03-01 03:04:24 +08:00
|
|
|
import { NextRequest } from 'next/server';
|
|
|
|
|
import { handlePaymentNotify } from '@/lib/order/service';
|
2026-03-07 04:15:54 +08:00
|
|
|
import { paymentRegistry } from '@/lib/payment';
|
|
|
|
|
import type { PaymentType } from '@/lib/payment';
|
|
|
|
|
import { extractHeaders } from '@/lib/utils/api';
|
2026-03-01 03:04:24 +08:00
|
|
|
|
|
|
|
|
export async function GET(request: NextRequest) {
|
|
|
|
|
try {
|
2026-03-07 04:15:54 +08:00
|
|
|
// EasyPay 注册为 'alipay' 和 'wxpay' 类型,任一均可获取同一 provider 实例
|
|
|
|
|
const provider = paymentRegistry.getProvider('alipay' as PaymentType);
|
2026-03-01 17:58:08 +08:00
|
|
|
const rawBody = request.nextUrl.searchParams.toString();
|
2026-03-07 04:15:54 +08:00
|
|
|
const headers = extractHeaders(request);
|
2026-03-01 03:04:24 +08:00
|
|
|
|
2026-03-07 04:15:54 +08:00
|
|
|
const notification = await provider.verifyNotification(rawBody, headers);
|
|
|
|
|
if (!notification) {
|
|
|
|
|
return new Response('success', { headers: { 'Content-Type': 'text/plain' } });
|
|
|
|
|
}
|
|
|
|
|
const success = await handlePaymentNotify(notification, provider.name);
|
2026-03-01 03:04:24 +08:00
|
|
|
return new Response(success ? 'success' : 'fail', {
|
|
|
|
|
headers: { 'Content-Type': 'text/plain' },
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('EasyPay notify error:', error);
|
|
|
|
|
return new Response('fail', {
|
|
|
|
|
headers: { 'Content-Type': 'text/plain' },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|