Files
sub2apipay/src/app/api/limits/route.ts

32 lines
1.0 KiB
TypeScript
Raw Normal View History

import { NextResponse } from 'next/server';
import { queryMethodLimits } from '@/lib/order/limits';
import { initPaymentProviders, paymentRegistry } from '@/lib/payment';
/**
* GET /api/limits
* 使
*
* Response:
* {
* methods: {
* alipay: { dailyLimit: 10000, used: 3500, remaining: 6500, available: true },
* wxpay: { dailyLimit: 10000, used: 10000, remaining: 0, available: false },
* stripe: { dailyLimit: 0, used: 500, remaining: null, available: true }
* },
* resetAt: "2026-03-02T00:00:00.000Z" // UTC 次日零点(限额重置时间)
* }
*/
export async function GET() {
initPaymentProviders();
const types = paymentRegistry.getSupportedTypes();
const todayStart = new Date();
todayStart.setUTCHours(0, 0, 0, 0);
const resetAt = new Date(todayStart);
resetAt.setUTCDate(resetAt.getUTCDate() + 1);
const methods = await queryMethodLimits(types);
return NextResponse.json({ methods, resetAt });
}