|
|
import express from 'express'; |
|
|
import { telegrafBots } from '../models'; |
|
|
import { createLogger } from '../utils/logger'; |
|
|
|
|
|
const logger = createLogger('PaymentWebhooks'); |
|
|
const router = express.Router(); |
|
|
|
|
|
|
|
|
const bot = Array.from(telegrafBots.values())[0]; |
|
|
|
|
|
|
|
|
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 }); |
|
|
} |
|
|
}); |
|
|
|
|
|
|
|
|
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 }); |
|
|
} |
|
|
}); |
|
|
|
|
|
|
|
|
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; |