Let parents register once and book for their children
CI / Tests (PHP 8.2) (pull_request) Successful in 42s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m45s
CI / Build Plugin Zip (pull_request) Skipped
CI / Tests (PHP 8.1) (pull_request) Failing after 52s
CI / No Debug Code (pull_request) Successful in 2s
CI / PHPStan (pull_request) Successful in 2m52s
CI / Coding Standards (pull_request) Successful in 2m57s
CI / Tests (PHP 8.2) (pull_request) Successful in 42s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m45s
CI / Build Plugin Zip (pull_request) Skipped
CI / Tests (PHP 8.1) (pull_request) Failing after 52s
CI / No Debug Code (pull_request) Successful in 2s
CI / PHPStan (pull_request) Successful in 2m52s
CI / Coding Standards (pull_request) Successful in 2m57s
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]>
This commit is contained in:
@@ -42,7 +42,7 @@ class CreditRepositoryTest extends TestCase
|
||||
);
|
||||
$this->db->insert_id = 300;
|
||||
|
||||
$credit = new Credit(5, 33.0, 33.0, 'CAD', 12, 77, 'Credit for cancelled lesson #77');
|
||||
$credit = new Credit(5, 33.0, 33.0, currency: 'CAD', sourcePaymentId: 12, sourceLessonId: 77, reason: 'Credit for cancelled lesson #77');
|
||||
self::assertSame(300, $this->repo->insert($credit));
|
||||
}
|
||||
|
||||
@@ -108,4 +108,67 @@ class CreditRepositoryTest extends TestCase
|
||||
|
||||
$this->repo->consume(5, 0.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* The balance is keyed on the payer, not the student, so a guardian's
|
||||
* account carries the credits every one of their children earned.
|
||||
*/
|
||||
public function testAvailableBalanceQueriesThePayer(): void
|
||||
{
|
||||
$this->db->shouldReceive('prepare')
|
||||
->once()
|
||||
->with(Mockery::on(static fn (string $sql): bool => str_contains($sql, 'payer_id = %d')), 'wp_us_credits', 5, Credit::STATUS_AVAILABLE)
|
||||
->andReturn('sql');
|
||||
$this->db->shouldReceive('get_var')->once()->with('sql')->andReturn('60.00');
|
||||
|
||||
self::assertSame(60.0, $this->repo->availableBalance(5));
|
||||
}
|
||||
|
||||
public function testFindAvailableByPayerReturnsCreditsOldestFirst(): void
|
||||
{
|
||||
$this->db->shouldReceive('prepare')
|
||||
->once()
|
||||
->with(Mockery::on(static fn (string $sql): bool => str_contains($sql, 'payer_id = %d')), 'wp_us_credits', 5, Credit::STATUS_AVAILABLE)
|
||||
->andReturn('sql');
|
||||
$this->db->shouldReceive('get_results')->once()->with('sql')->andReturn([
|
||||
(object) ['id' => '1', 'student_id' => '42', 'payer_id' => '5', 'amount' => '10.00', 'remaining' => '10.00', 'currency' => 'CAD', 'source_payment_id' => null, 'source_lesson_id' => null, 'reason' => null, 'status' => Credit::STATUS_AVAILABLE, 'created_at' => '2026-07-01 09:00:00', 'updated_at' => null],
|
||||
]);
|
||||
|
||||
$credits = $this->repo->findAvailableByPayer(5);
|
||||
|
||||
self::assertCount(1, $credits);
|
||||
self::assertSame(42, $credits[0]->studentId);
|
||||
self::assertSame(5, $credits[0]->payerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rows written before guardian accounts existed carry payer_id 0; the
|
||||
* installer points them at the student who was always the payer.
|
||||
*/
|
||||
public function testBackfillPayerIdsPointsLegacyRowsAtTheStudent(): void
|
||||
{
|
||||
$this->db->shouldReceive('prepare')
|
||||
->once()
|
||||
->with('UPDATE %i SET payer_id = student_id WHERE payer_id = 0', 'wp_us_credits')
|
||||
->andReturn('sql');
|
||||
$this->db->shouldReceive('query')->once()->with('sql');
|
||||
|
||||
$this->repo->backfillPayerIds();
|
||||
}
|
||||
|
||||
public function testInsertDefaultsThePayerToTheStudent(): void
|
||||
{
|
||||
Functions\when('current_time')->justReturn('2026-06-08 12:00:00');
|
||||
|
||||
$this->db->shouldReceive('insert')
|
||||
->once()
|
||||
->with(
|
||||
'wp_us_credits',
|
||||
Mockery::on(static fn (array $d): bool => $d['student_id'] === 5 && $d['payer_id'] === 5),
|
||||
Mockery::type('array')
|
||||
);
|
||||
$this->db->insert_id = 301;
|
||||
|
||||
self::assertSame(301, $this->repo->insert(new Credit(5, 10.0, 10.0)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user