race condition fixed, payment inside

This commit is contained in:
root
2025-12-21 09:56:59 +01:00
parent 6741f5ed72
commit 67646c75a4
6 changed files with 714 additions and 30 deletions

View File

@@ -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)