Refactor: Fully migrated to direct PostgreSQL, implemented Public API v1, fixed Vercel deployment conflicts, and updated documentation
This commit is contained in:
53
app/api/transactions/[id]/details/route.ts
Normal file
53
app/api/transactions/[id]/details/route.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { db } from '@/lib/db';
|
||||
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
context: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await context.params;
|
||||
|
||||
if (!id) {
|
||||
return NextResponse.json({ error: 'Missing session ID' }, { status: 400 });
|
||||
}
|
||||
|
||||
const result = await db.query(`
|
||||
SELECT t.*, m.name as merchant_name
|
||||
FROM transactions t
|
||||
JOIN merchants m ON t.merchant_id = m.id
|
||||
WHERE t.id = $1
|
||||
LIMIT 1
|
||||
`, [id]);
|
||||
|
||||
if (result.rows.length === 0) {
|
||||
return NextResponse.json({ error: 'Transaction not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
const tx = result.rows[0];
|
||||
const metadata = tx.metadata || {};
|
||||
|
||||
return NextResponse.json({
|
||||
id: tx.id,
|
||||
amount: Number(tx.amount),
|
||||
currency: tx.currency,
|
||||
status: tx.status,
|
||||
customer_name: tx.customer_name,
|
||||
ref_id: tx.source_ref_id,
|
||||
merchant_name: tx.merchant_name,
|
||||
callback_url: tx.callback_url,
|
||||
// Only expose public wallet addresses, not private keys
|
||||
wallets: metadata.wallets ? {
|
||||
EVM: metadata.wallets.EVM?.address,
|
||||
SOLANA: metadata.wallets.SOLANA?.address
|
||||
} : null,
|
||||
clientSecret: tx.stripe_pi_id, // For Stripe/Mock
|
||||
nextAction: metadata.nextAction || 'none',
|
||||
redirectUrl: metadata.redirectUrl || '',
|
||||
provider: tx.provider
|
||||
});
|
||||
|
||||
} catch (error: any) {
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user