buyer data

This commit is contained in:
root
2025-12-21 11:12:02 +01:00
parent 67646c75a4
commit 514e04f43d
6 changed files with 359 additions and 23 deletions

View File

@@ -22,12 +22,25 @@ export async function POST(request: NextRequest) {
const buyer_id = parseInt(buyerIdCookie, 10)
const body = await request.json()
const { drop_id, size, pay_currency } = body
const { drop_id, size, pay_currency, buyer_data_id } = body
// Validate required fields
if (!drop_id || !size) {
if (!drop_id || !size || !buyer_data_id) {
return NextResponse.json(
{ error: 'Missing required fields: drop_id, size' },
{ error: 'Missing required fields: drop_id, size, and buyer_data_id' },
{ status: 400 }
)
}
// Verify buyer_data_id exists and belongs to the buyer
const [buyerDataRows] = await pool.execute(
'SELECT id FROM buyer_data WHERE id = ? AND buyer_id = ?',
[buyer_data_id, buyer_id]
)
const buyerData = buyerDataRows as any[]
if (buyerData.length === 0) {
return NextResponse.json(
{ error: 'Invalid buyer_data_id or buyer_data does not belong to user' },
{ status: 400 }
)
}
@@ -176,8 +189,8 @@ export async function POST(request: NextRequest) {
// Store pending order with expiration time (atomically reserves inventory)
// payment.payment_id is the NOWPayments payment ID
await connection.execute(
'INSERT INTO pending_orders (payment_id, order_id, drop_id, buyer_id, size, price_amount, price_currency, expires_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
[payment.payment_id, orderId, drop_id, buyer_id, size, priceAmount, nowPaymentsConfig.currency, expiresAt]
'INSERT INTO pending_orders (payment_id, order_id, drop_id, buyer_id, buyer_data_id, size, price_amount, price_currency, expires_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)',
[payment.payment_id, orderId, drop_id, buyer_id, buyer_data_id, size, priceAmount, nowPaymentsConfig.currency, expiresAt]
)
// Commit transaction - inventory is now reserved