- src/payments: provider registry and PaymentProvider interface (createCheckout, verifyWebhook/parseWebhook, getTransaction, refund, listTransactions as capabilities), Yoco as the first provider. All four direct Yoco checkout calls go through payments.createCheckout. - Webhook split into the provider part (signature, parsing) and shared processing; same URL (/api/webhooks/yoco), same behaviour. - YocoTransaction renamed in place to ProviderTransaction (+ provider, unique per provider + externalId); Payment.provider added and backfilled to "yoco". Payment.method stays the wallet type so cashups are unchanged. - Site settings → Payments: Enabled toggle and order per provider; Yoco's settings shown while it's enabled. R15 minimum for all online payments. - New endpoint names (/api/payments/checkout, /api/provider-transactions); the old /yoco-checkout and /yoco-transactions paths still work. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
44 lines
1.9 KiB
JavaScript
44 lines
1.9 KiB
JavaScript
const express = require('express');
|
|
const router = express.Router();
|
|
const {
|
|
createPayment,
|
|
getPayments,
|
|
getUserPayments,
|
|
getPaymentById,
|
|
getPaymentsByRegistration,
|
|
getPaymentsByEvent,
|
|
assignDonationToRegistration,
|
|
unassignDonationFromRegistration,
|
|
createCheckout,
|
|
sendPaymentLink,
|
|
createRefund,
|
|
getPaymentStats,
|
|
sendReceipt,
|
|
} = require('../controllers/paymentController');
|
|
const { listPaymentProviders, getPaymentProviderSettings, updatePaymentProviderSettings } = require('../controllers/paymentProvidersController');
|
|
const { protect, supervisor, staff, admin} = require('../middleware/authMiddleware');
|
|
|
|
// Protected routes
|
|
router.post('/', protect, supervisor, createPayment);
|
|
router.get('/providers', listPaymentProviders);
|
|
router.get('/providers/settings', protect, admin, getPaymentProviderSettings);
|
|
router.put('/providers/settings', protect, admin, updatePaymentProviderSettings);
|
|
router.post('/checkout', protect, createCheckout);
|
|
router.post('/checkout/send', protect, supervisor, sendPaymentLink);
|
|
// Older names, kept for existing clients
|
|
router.post('/yoco-checkout', protect, createCheckout);
|
|
router.post('/yoco-checkout/send', protect, supervisor, sendPaymentLink);
|
|
router.get('/mypayments', protect, getUserPayments);
|
|
router.post('/:id/send-receipt', protect, sendReceipt);
|
|
router.get('/:id', protect, getPaymentById);
|
|
router.get('/registration/:registrationId', protect, getPaymentsByRegistration);
|
|
|
|
// Admin/Staff routes
|
|
router.get('/', protect, supervisor, getPayments);
|
|
router.get('/event/:eventId', protect, staff, getPaymentsByEvent);
|
|
router.put('/assign-donation', protect, supervisor, assignDonationToRegistration);
|
|
router.post('/unassign-donation', protect, supervisor, unassignDonationFromRegistration);
|
|
router.post('/refund', protect, supervisor, createRefund);
|
|
router.get('/admin/stats', protect, admin, getPaymentStats);
|
|
|
|
module.exports = router; |