buyer data
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user