fix: honor ENABLED_PAYMENT_TYPES in user config api

Co-authored-by: gopkg-dev <58848833+gopkg-dev@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-03-14 13:49:40 +00:00
parent ae3aa2e0e4
commit 1f2d0499ed
2 changed files with 124 additions and 3 deletions

View File

@@ -7,6 +7,20 @@ import { getPaymentDisplayInfo } from '@/lib/pay-utils';
import { resolveLocale } from '@/lib/locale';
import { getSystemConfig } from '@/lib/system-config';
function resolveEnabledPaymentTypes(supportedTypes: string[], configuredTypes: string | undefined): string[] {
if (configuredTypes === undefined) return supportedTypes;
const configuredTypeSet = new Set(
configuredTypes
.split(',')
.map((type) => type.trim())
.filter(Boolean),
);
if (configuredTypeSet.size === 0) return supportedTypes;
return supportedTypes.filter((type) => configuredTypeSet.has(type));
}
export async function GET(request: NextRequest) {
const locale = resolveLocale(request.nextUrl.searchParams.get('lang'));
const userId = Number(request.nextUrl.searchParams.get('user_id'));
@@ -40,12 +54,14 @@ export async function GET(request: NextRequest) {
const env = getEnv();
initPaymentProviders();
const enabledTypes = paymentRegistry.getSupportedTypes();
const [user, methodLimits, balanceDisabledVal] = await Promise.all([
const supportedTypes = paymentRegistry.getSupportedTypes();
const [user, configuredEnabledTypes, balanceDisabledVal] = await Promise.all([
getUser(userId),
queryMethodLimits(enabledTypes),
getSystemConfig('ENABLED_PAYMENT_TYPES'),
getSystemConfig('BALANCE_PAYMENT_DISABLED'),
]);
const enabledTypes = resolveEnabledPaymentTypes(supportedTypes, configuredEnabledTypes);
const methodLimits = await queryMethodLimits(enabledTypes);
const balanceDisabled = balanceDisabledVal === 'true';
// 收集 sublabel 覆盖