removed unnecessary route
This commit is contained in:
parent
6524ea415e
commit
59871fc66f
@ -1,70 +0,0 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { createClient } from '@supabase/supabase-js';
|
||||
import nodemailer from 'nodemailer';
|
||||
|
||||
const supabase = createClient(
|
||||
process.env.SUPABASE_URL!,
|
||||
process.env.SUPABASE_SERVICE_ROLE_KEY!
|
||||
);
|
||||
|
||||
const emailUser = process.env.EMAIL_USER!;
|
||||
const emailPass = process.env.EMAIL_PASS!;
|
||||
const businessEmail = process.env.BUSINESS_EMAIL!;
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
try {
|
||||
const { gpuId, userEmail, txSignature, amountSol, status } = await req.json();
|
||||
|
||||
if (!gpuId || !userEmail || !amountSol || !status) {
|
||||
return NextResponse.json({ error: 'Missing required fields' }, { status: 400 });
|
||||
}
|
||||
|
||||
if (!['pending', 'success', 'failed'].includes(status)) {
|
||||
return NextResponse.json({ error: 'Invalid status value' }, { status: 400 });
|
||||
}
|
||||
|
||||
const { error } = await supabase.from('orders').insert({
|
||||
gpu_id: gpuId,
|
||||
user_email: userEmail,
|
||||
amount_sol: amountSol,
|
||||
sol_tx_signature: txSignature || null,
|
||||
status,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
console.error('[Supabase error]', error);
|
||||
return NextResponse.json({ error: 'Database error' }, { status: 500 });
|
||||
}
|
||||
|
||||
// Send confirmation email
|
||||
const transporter = nodemailer.createTransport({
|
||||
service: 'gmail',
|
||||
auth: {
|
||||
user: emailUser,
|
||||
pass: emailPass,
|
||||
},
|
||||
});
|
||||
|
||||
await transporter.sendMail({
|
||||
from: `"GPU Store" <${emailUser}>`,
|
||||
to: userEmail,
|
||||
subject: `GPU Payment ${status === 'success' ? 'Confirmed' : 'Attempted'}`,
|
||||
html: `
|
||||
<p>Hi,</p>
|
||||
<p>Your order for GPU ID <strong>${gpuId}</strong> has status: <strong>${status}</strong>.</p>
|
||||
<p>Amount: ${amountSol} SOL</p>
|
||||
${
|
||||
txSignature
|
||||
? `<p>Transaction: <a href="https://solscan.io/tx/${txSignature}" target="_blank">${txSignature}</a></p>`
|
||||
: '<p>No transaction was recorded.</p>'
|
||||
}
|
||||
<p>Thank you for using our platform.</p>
|
||||
`,
|
||||
});
|
||||
|
||||
return NextResponse.json({ message: 'Order recorded and email sent' });
|
||||
} catch (err: any) {
|
||||
console.error('[Order API Error]', err);
|
||||
return NextResponse.json({ error: 'Server error' }, { status: 500 });
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user