3.1 KiB
3.1 KiB
ChargeController plan
Scope
- Controller:
app/Http/Controllers/Api/Finance/ChargeController.php - Purpose: list charges for a parent and manage extra/event charges (create/cancel/apply/mark paid).
- Primary dependency:
App\Services\Billing\ChargeService - Resources:
ChargeListResource(for list responses)ChargeActionResource(for mutation responses)
Routes
All routes are under:
- Base prefix:
/api/v1/finance/fees/charges
Endpoints:
GET /api/v1/finance/fees/charges/→indexPOST /api/v1/finance/fees/charges/extra→storeExtraPOST /api/v1/finance/fees/charges/event→storeEventPOST /api/v1/finance/fees/charges/extra/{id}/cancel→cancelExtraPOST /api/v1/finance/fees/charges/extra/{id}/apply→applyExtraPOST /api/v1/finance/fees/charges/event/{id}/cancel→cancelEventPOST /api/v1/finance/fees/charges/event/{id}/mark-paid→markEventPaid
Authentication & authorization
storeExtra/storeEventrequire an authenticated user id (checked byauthenticatedUserIdOrUnauthorized()).- Other endpoints currently do not call the helper; authorization is expected to be enforced by surrounding route middleware and/or service-layer checks.
Requests/validation
index:ChargeListRequest(parent_idrequired; optionalschool_year)storeExtra:StoreExtraChargeRequest(+ addscreated_byfrom authenticated user)storeEvent:StoreEventChargeRequest(+ addscreated_by)applyExtra:ApplyExtraChargeRequest(invoice_id)markEventPaid:MarkEventChargePaidRequest(paid, optionalpayment_id)cancelEvent: uses rawRequestwith query booleanissue_credit(default true)
Response shapes
Legacy { ok: ... } shape:
index:{ ok:true, charges: ChargeListResource }
- Mutations:
{ ok:(bool), charge: ChargeActionResource }- HTTP status:
- Create success:
201 - Duplicate charge success-case:
409(whenerror === "duplicate_charge") - Validation/business failure:
422 - Cancel/apply/mark-paid:
200when ok, else422
- Create success:
Side effects
storeExtra/storeEventattachcreated_byfor auditing.cancelEventoptionally issues credits (controlled viaissue_creditquery flag).markEventPaidcan link to apayment_idwhen supplied.
Error handling expectations
storeExtra/storeEventcatch unexpected exceptions:- return
500{ ok:false, message:"Unable to create ... charge." }
- return
- Unauthorized (store endpoints) returns:
401{ ok:false, message:"Unauthorized." }
Test plan (feature)
- Listing:
- Returns
ChargeListResourcepayload for a parent with charges.
- Returns
- Create extra/event:
- Unauthenticated → 401.
- Valid payload → 201 and ok true.
- Duplicate charge → 409.
- Service exception → 500.
- Apply extra:
- Valid invoice id applies charge → 200.
- Invalid invoice/charge → 422.
- Cancel:
- Extra cancel → 200/422 depending on service result.
- Event cancel with
issue_credit=falsebehaves accordingly.
- Mark paid:
- Toggle paid true/false; supports payment_id link.