2026-03-01 03:04:24 +08:00
|
|
|
import { NextRequest } from 'next/server';
|
|
|
|
|
import { handlePaymentNotify } from '@/lib/order/service';
|
2026-03-01 17:58:08 +08:00
|
|
|
import { EasyPayProvider } from '@/lib/easy-pay/provider';
|
|
|
|
|
|
|
|
|
|
const easyPayProvider = new EasyPayProvider();
|
2026-03-01 03:04:24 +08:00
|
|
|
|
|
|
|
|
export async function GET(request: NextRequest) {
|
|
|
|
|
try {
|
2026-03-01 17:58:08 +08:00
|
|
|
const rawBody = request.nextUrl.searchParams.toString();
|
|
|
|
|
const headers: Record<string, string> = {};
|
|
|
|
|
request.headers.forEach((value, key) => {
|
|
|
|
|
headers[key] = value;
|
|
|
|
|
});
|
2026-03-01 03:04:24 +08:00
|
|
|
|
2026-03-01 17:58:08 +08:00
|
|
|
const notification = await easyPayProvider.verifyNotification(rawBody, headers);
|
|
|
|
|
const success = await handlePaymentNotify(notification, easyPayProvider.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' },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|