- Add Stripe payment provider with Checkout Session flow - Payment provider abstraction layer (EasyPay + Stripe unified interface) - Stripe webhook with proper raw body handling and signature verification - Frontend: Stripe button with URL validation, anti-duplicate click, noopener - Active timeout cancellation: query platform before expiring, recover paid orders - Singleton Stripe client, idempotency keys, Math.round for amounts - Handle async_payment events, return null for unknown webhook events - Set Checkout Session expires_at aligned with order timeout - Add cancelPayment to provider interface (Stripe: sessions.expire, EasyPay: no-op) - Enable stripe in frontend payment type list
32 lines
1009 B
TypeScript
32 lines
1009 B
TypeScript
import { NextResponse } from 'next/server';
|
|
import { getUser } from '@/lib/sub2api/client';
|
|
|
|
export async function GET(_request: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
const { id } = await params;
|
|
const userId = Number(id);
|
|
|
|
if (!Number.isInteger(userId) || userId <= 0) {
|
|
return NextResponse.json({ error: 'Invalid user id' }, { status: 400 });
|
|
}
|
|
|
|
try {
|
|
const user = await getUser(userId);
|
|
const displayName = user.username || user.email || `User #${user.id}`;
|
|
|
|
return NextResponse.json({
|
|
id: user.id,
|
|
username: user.username,
|
|
email: user.email,
|
|
displayName,
|
|
balance: user.balance,
|
|
status: user.status,
|
|
});
|
|
} catch (error) {
|
|
if (error instanceof Error && error.message === 'USER_NOT_FOUND') {
|
|
return NextResponse.json({ error: 'User not found' }, { status: 404 });
|
|
}
|
|
console.error('Get user info error:', error);
|
|
return NextResponse.json({ error: 'Get user info failed' }, { status: 500 });
|
|
}
|
|
}
|