Archived
Events, payments, registrations, scan locks and tickets marked; list controllers filtered (registrations, payments, tickets, scans, stats, coupons, scheduled messages, form responses, funnel). Owner-or-staff routes check staff against the record's event (ownerOk). Scanner names the campus of another campus's ticket. Route test passes; unit tests for the rules. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
54 lines
3.2 KiB
JavaScript
54 lines
3.2 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, getPayPage, choosePayProvider, listOpenCheckouts, checkCheckoutStatus } = require('../controllers/paymentProvidersController');
|
|
const { protect, supervisor, staff, admin} = require('../middleware/authMiddleware');
|
|
const { scopeEvent, scopeBody, scopeList, unscopedOnly } = require('../utils/campusScope');
|
|
|
|
// Campus-scoped staff: payments follow their registration's or event's campus. Door payments for
|
|
// church-wide events are allowed; refunds of them aren't (need 'manage'); a payment or donation
|
|
// not linked to any event is for admins and unscoped supervisors (orphan 'deny').
|
|
const paymentTarget = scopeBody([['registrationId', 'registration'], ['eventId', 'event']], { orphan: 'deny' });
|
|
|
|
// Protected routes
|
|
router.post('/', protect, supervisor, paymentTarget, createPayment);
|
|
router.get('/providers', listPaymentProviders);
|
|
router.get('/pay/:id', getPayPage);
|
|
router.post('/pay/:id', choosePayProvider);
|
|
router.get('/checkouts/open', protect, supervisor, unscopedOnly, listOpenCheckouts);
|
|
router.post('/checkouts/check', protect, supervisor, unscopedOnly, checkCheckoutStatus);
|
|
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, scopeBody([['registrationId', 'registration']]), sendPaymentLink);
|
|
// Older names, kept for existing clients
|
|
router.post('/yoco-checkout', protect, createCheckout);
|
|
router.post('/yoco-checkout/send', protect, supervisor, scopeBody([['registrationId', 'registration']]), sendPaymentLink);
|
|
router.get('/mypayments', protect, getUserPayments);
|
|
router.post('/:id/send-receipt', protect, scopeEvent({ resolve: 'payment', ownerOk: true }), sendReceipt);
|
|
router.get('/:id', protect, scopeEvent({ resolve: 'payment', ownerOk: true }), getPaymentById);
|
|
router.get('/registration/:registrationId', protect, scopeEvent({ resolve: 'registration', from: req => req.params.registrationId, ownerOk: true }), getPaymentsByRegistration);
|
|
|
|
// Admin/Staff routes
|
|
router.get('/', protect, supervisor, scopeList, getPayments);
|
|
router.get('/event/:eventId', protect, staff, scopeEvent(), getPaymentsByEvent);
|
|
router.put('/assign-donation', protect, supervisor, scopeBody([['paymentId', 'payment']], { orphan: 'deny' }), scopeBody([['registrationId', 'registration']]), assignDonationToRegistration);
|
|
router.post('/unassign-donation', protect, supervisor, scopeBody([['legId', 'payment']], { orphan: 'deny' }), unassignDonationFromRegistration);
|
|
router.post('/refund', protect, supervisor, scopeBody([['paymentId', 'payment'], ['registrationId', 'registration']], { need: 'manage', orphan: 'deny' }), createRefund);
|
|
router.get('/admin/stats', protect, admin, getPaymentStats);
|
|
|
|
module.exports = router; |