56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
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,
|
|
TRON: metadata.wallets.TRON?.address,
|
|
BITCOIN: metadata.wallets.BITCOIN?.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 });
|
|
}
|
|
}
|