feat: migrate payment provider to easy-pay, add order history and refund support
- Replace zpay with easy-pay payment provider (new lib/easy-pay/ module) - Add order history page for users (pay/orders) - Add GET /api/orders/my endpoint to list user's own orders - Add GET /api/users/[id] endpoint for sub2api user lookup - Add order status tracking module (lib/order/status.ts) - Update config to support easy-pay credentials (merchant ID, key, gateway) - Update PaymentForm and PaymentQRCode components for easy-pay flow - Update pay page and admin page with new order management UI - Update order service to support easy-pay, cancellation, and refund
This commit is contained in:
42
src/lib/order/timeout.ts
Normal file
42
src/lib/order/timeout.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { prisma } from '@/lib/db';
|
||||
|
||||
const INTERVAL_MS = 30_000; // 30 seconds
|
||||
let timer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
export async function expireOrders(): Promise<number> {
|
||||
const result = await prisma.order.updateMany({
|
||||
where: {
|
||||
status: 'PENDING',
|
||||
expiresAt: { lt: new Date() },
|
||||
},
|
||||
data: { status: 'EXPIRED' },
|
||||
});
|
||||
|
||||
if (result.count > 0) {
|
||||
console.log(`Expired ${result.count} orders`);
|
||||
}
|
||||
|
||||
return result.count;
|
||||
}
|
||||
|
||||
export function startTimeoutScheduler(): void {
|
||||
if (timer) return;
|
||||
|
||||
// Run immediately on startup
|
||||
expireOrders().catch(console.error);
|
||||
|
||||
// Then run every 30 seconds
|
||||
timer = setInterval(() => {
|
||||
expireOrders().catch(console.error);
|
||||
}, INTERVAL_MS);
|
||||
|
||||
console.log('Order timeout scheduler started');
|
||||
}
|
||||
|
||||
export function stopTimeoutScheduler(): void {
|
||||
if (timer) {
|
||||
clearInterval(timer);
|
||||
timer = null;
|
||||
console.log('Order timeout scheduler stopped');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user