bot-me / src /api /paymentWebhooks.ts
Mohammed Foud
allh
80d4bc1
import express from 'express';
import { telegrafBots } from '../models';
import { createLogger } from '../utils/logger';
const logger = createLogger('PaymentWebhooks');
const router = express.Router();
// Get the first bot instance from the map
const bot = Array.from(telegrafBots.values())[0];
// PayPal webhook endpoint
router.post('/paypal', async (req, res) => {
try {
const { paymentId, status } = req.body;
await bot.emit('webhook:paypal', { paymentId, status });
res.json({ success: true });
} catch (error) {
logger.error('PayPal webhook error:', error);
res.status(500).json({ success: false, error: error.message });
}
});
// Crypto webhook endpoint
router.post('/crypto', async (req, res) => {
try {
const { paymentId, status } = req.body;
await bot.emit('webhook:crypto', { paymentId, status });
res.json({ success: true });
} catch (error) {
logger.error('Crypto webhook error:', error);
res.status(500).json({ success: false, error: error.message });
}
});
// Admin payment verification endpoint
router.post('/admin', async (req, res) => {
try {
const { paymentId, status } = req.body;
await bot.emit('webhook:admin', { paymentId, status });
res.json({ success: true });
} catch (error) {
logger.error('Admin webhook error:', error);
res.status(500).json({ success: false, error: error.message });
}
});
export default router;