Apply account credit on same-month rebook; show total credit on student page #202

Merged
thatguygriff merged 6 commits from feature/student-credit-display-and-rebook-fix into main 2026-09-17 18:50:44 +00:00
3 changed files with 11 additions and 5 deletions
Showing only changes of commit 362980d008 - Show all commits
+2 -2
View File
@@ -196,8 +196,8 @@ class LessonBooker {
payerId: $payerId
);
// Apply any available credit to a scheduled charge raised at booking.
if ( $offering->isScheduledBilling() && null !== $payment && null !== $payment->id && Payment::STATUS_PENDING === $payment->status ) {
// Apply any available credit to a charge raised at booking.
if ( null !== $payment && null !== $payment->id && Payment::STATUS_PENDING === $payment->status ) {
$this->payments->applyCredits( $payerId, [ $payment ] );
$payment = $this->payments->findPayment( (int) $payment->id ) ?? $payment;
}
+6
View File
@@ -48,6 +48,12 @@ class AdminBookingTest extends TestCase
$this->bookings = Mockery::mock(BookingRepository::class);
$this->offerings = Mockery::mock(OfferingRepository::class);
$this->payments = Mockery::mock(PaymentService::class);
// A charge raised at booking has the payer's credit applied before it
// settles. The default holds no balance and re-reads the same payment.
$this->payments->shouldReceive('applyCredits')->andReturn([])->byDefault();
$this->payments->shouldReceive('findPayment')->andReturnUsing(
static fn (int $id): ?Payment => null
)->byDefault();
$this->guardians = Mockery::mock(GuardianService::class);
$this->guardians->shouldReceive('payerFor')->andReturnUsing(static fn (int $id): int => $id)->byDefault();
+3 -3
View File
@@ -57,9 +57,9 @@ class BookingEndpointTest extends TestCase
// Crediting a cancelled paid lesson is exercised in dedicated tests; other
// cancellation paths simply allow the call.
$this->payments->shouldReceive('creditForCancelledLesson')->andReturn(null)->byDefault();
// A charge-at-booking scheduled lesson (an add-on to an already-billed month)
// applies the payer's credit before it settles. The default holds no balance
// and re-reads the same payment; the same-month-rebook test overrides both.
// A charge raised at booking applies the payer's credit before it settles.
// The default holds no balance and re-reads the same payment; the
// same-month-rebook test overrides both.
$this->payments->shouldReceive('applyCredits')->andReturn([])->byDefault();
$this->payments->shouldReceive('findPayment')->andReturnUsing(
static fn (int $id): ?Payment => null