Initial commit

This commit is contained in:
KabundiNjuki
2026-10-05 16:40:36 +03:00
commit ff743a1397
108 changed files with 15390 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
import { NextResponse } from 'next/server'
import { FrappeError, METHODS, frappeCall } from '@/lib/lukenya-api'
// Polled by /payment/return. The backend checks with Paystack itself before answering,
// so the browser being sent back here never confirms a payment on its own.
export async function GET(req: Request) {
const reference = new URL(req.url).searchParams.get('reference') || ''
if (!/^[A-Za-z0-9._-]{4,100}$/.test(reference)) {
return NextResponse.json({ error: 'Missing or invalid payment reference.' }, { status: 400 })
}
try {
const result = await frappeCall<Record<string, unknown>>(METHODS.paymentStatus, { args: { reference } })
return NextResponse.json(result, { headers: { 'Cache-Control': 'no-store' } })
} catch (err) {
const status = (err as FrappeError).status
if (status === 404) return NextResponse.json({ error: 'We could not find this payment.' }, { status: 404 })
// The server re-checks with Paystack in the background; keep the runner on the waiting screen.
return NextResponse.json({ status: 'Pending' }, { headers: { 'Cache-Control': 'no-store' } })
}
}