race condition fixed, payment inside
This commit is contained in:
@@ -43,11 +43,31 @@ export async function GET(request: NextRequest) {
|
||||
const pendingOrders = pendingRows as any[]
|
||||
const sales = salesRows as any[]
|
||||
|
||||
if (pendingOrders.length === 0 && sales.length === 0) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Payment not found' },
|
||||
{ status: 404 }
|
||||
)
|
||||
// Check if pending order exists and if sale exists
|
||||
const hasPendingOrder = pendingOrders.length > 0
|
||||
const hasSale = sales.length > 0
|
||||
|
||||
// If pending order is gone and sale exists, payment was processed
|
||||
if (!hasPendingOrder && hasSale) {
|
||||
return NextResponse.json({
|
||||
payment_id,
|
||||
status: 'completed',
|
||||
payment_status: 'completed',
|
||||
has_pending_order: false,
|
||||
has_sale: true,
|
||||
sale: sales[0],
|
||||
})
|
||||
}
|
||||
|
||||
// If both are gone, payment was cancelled or expired
|
||||
if (!hasPendingOrder && !hasSale) {
|
||||
return NextResponse.json({
|
||||
payment_id,
|
||||
status: 'cancelled',
|
||||
payment_status: 'cancelled',
|
||||
has_pending_order: false,
|
||||
has_sale: false,
|
||||
})
|
||||
}
|
||||
|
||||
// Get NOWPayments config (testnet or production)
|
||||
@@ -82,6 +102,8 @@ export async function GET(request: NextRequest) {
|
||||
pay_currency: paymentStatus.pay_currency,
|
||||
price_amount: paymentStatus.price_amount,
|
||||
price_currency: paymentStatus.price_currency,
|
||||
has_pending_order: hasPendingOrder,
|
||||
has_sale: hasSale,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error checking payment status:', error)
|
||||
|
||||
Reference in New Issue
Block a user