A parent registers once and manages lessons for one or more children, who need no login of their own. A child is a real wp_users row with the student role but no usable login — so student_id keeps meaning "a WordPress user" on every table, and booking, credits, policies and enrolments work unchanged. A us_guardians link table maps guardian to child. The signup form gains a parent/guardian tick that reveals a block per child, with the account-signup questions asked per child rather than per guardian — they describe the student, not the account holder. Signup policies are recorded once per child with the guardian as the acceptor, which is the record that actually means something. A family that half-creates is rolled back entirely rather than leaving a guardian who cannot re-register. The booking and enrolment forms gain a "Who is this for?" picker listing children first, so the default selection is never the parent — booking for the wrong child is correctable, quietly billing a parent for their kid's lesson is not. POST /bookings and POST /enrollments take an optional student_id honoured only for that child's guardian; anything else is a 403. That check is the authorisation boundary of the feature. Payments and credits gain a payer: the charge names the child it was for and the guardian who owes it, so per-child reporting is unchanged while notices, receipts and the payment step reach the parent. Credit is held by the payer, so one child's cancellation can settle a sibling's charge, and the daily billing scan sends a guardian one notice covering every child. Closes #132 Co-Authored-By: Claude Opus 5 <[email protected]>
65 lines
3.4 KiB
PHP
65 lines
3.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular;
|
|
|
|
use Unsupervised\Schedular\Availability\AvailabilityEndpoint;
|
|
use Unsupervised\Schedular\Availability\AvailabilityRepository;
|
|
use Unsupervised\Schedular\Availability\WindowValidator;
|
|
use Unsupervised\Schedular\Booking\BookingEndpoint;
|
|
use Unsupervised\Schedular\Booking\BookingRepository;
|
|
use Unsupervised\Schedular\Booking\CancellationPolicy;
|
|
use Unsupervised\Schedular\GroupClass\EnrollmentEndpoint;
|
|
use Unsupervised\Schedular\GroupClass\GroupAccessRepository;
|
|
use Unsupervised\Schedular\GroupClass\EnrollmentRepository;
|
|
use Unsupervised\Schedular\Guardian\GuardianService;
|
|
use Unsupervised\Schedular\Offering\OfferingEndpoint;
|
|
use Unsupervised\Schedular\Offering\OfferingRepository;
|
|
use Unsupervised\Schedular\Payment\PaymentEndpoint;
|
|
use Unsupervised\Schedular\Payment\PaymentService;
|
|
use Unsupervised\Schedular\Payment\StudioSettings;
|
|
use Unsupervised\Schedular\Policy\PolicyEndpoint;
|
|
use Unsupervised\Schedular\Policy\PolicyRepository;
|
|
use Unsupervised\Schedular\Policy\PolicyService;
|
|
use Unsupervised\Schedular\Policy\PolicyVersionRepository;
|
|
use Unsupervised\Schedular\Registration\QuestionEndpoint;
|
|
use Unsupervised\Schedular\Registration\QuestionRepository;
|
|
use Unsupervised\Schedular\Registration\RegistrationGate;
|
|
|
|
class RestRegistrar {
|
|
|
|
public const NAMESPACE = 'us-scheduler/v1';
|
|
|
|
private AvailabilityEndpoint $availabilityEndpoint;
|
|
private BookingEndpoint $bookingEndpoint;
|
|
private OfferingEndpoint $offeringEndpoint;
|
|
private QuestionEndpoint $questionEndpoint;
|
|
private PolicyEndpoint $policyEndpoint;
|
|
private EnrollmentEndpoint $enrollmentEndpoint;
|
|
private PaymentEndpoint $paymentEndpoint;
|
|
|
|
public function __construct( AvailabilityRepository $availability, BookingRepository $bookings, OfferingRepository $offerings, QuestionRepository $questions, PolicyRepository $policies, PolicyVersionRepository $policyVersions, PolicyService $policyService, RegistrationGate $gate, EnrollmentRepository $enrollments, GroupAccessRepository $groupAccess, PaymentService $paymentService, GuardianService $guardians ) {
|
|
$this->availabilityEndpoint = new AvailabilityEndpoint( $availability, new WindowValidator( $offerings ) );
|
|
$this->bookingEndpoint = new BookingEndpoint( $availability, $bookings, $offerings, $gate, $paymentService, new CancellationPolicy( new StudioSettings() ), $guardians );
|
|
$this->offeringEndpoint = new OfferingEndpoint( $offerings, $groupAccess );
|
|
$this->questionEndpoint = new QuestionEndpoint( $questions, $offerings );
|
|
$this->policyEndpoint = new PolicyEndpoint( $policies, $policyVersions, $policyService );
|
|
$this->enrollmentEndpoint = new EnrollmentEndpoint( $enrollments, $offerings, $gate, $paymentService, $groupAccess, $guardians );
|
|
$this->paymentEndpoint = new PaymentEndpoint( $paymentService );
|
|
}
|
|
|
|
public function register(): void {
|
|
add_action( 'rest_api_init', [ $this, 'registerRoutes' ] );
|
|
}
|
|
|
|
public function registerRoutes(): void {
|
|
$this->availabilityEndpoint->registerRoutes( self::NAMESPACE );
|
|
$this->bookingEndpoint->registerRoutes( self::NAMESPACE );
|
|
$this->offeringEndpoint->registerRoutes( self::NAMESPACE );
|
|
$this->questionEndpoint->registerRoutes( self::NAMESPACE );
|
|
$this->policyEndpoint->registerRoutes( self::NAMESPACE );
|
|
$this->enrollmentEndpoint->registerRoutes( self::NAMESPACE );
|
|
$this->paymentEndpoint->registerRoutes( self::NAMESPACE );
|
|
}
|
|
}
|