Apply available credit to any at-booking charge, not just scheduled
CI / Coding Standards (pull_request) Successful in 31s
CI / Tests (PHP 8.2) (pull_request) Successful in 30s
CI / Tests (PHP 8.3) (pull_request) Successful in 31s
CI / No Debug Code (pull_request) Successful in 5s
CI / Tests (PHP 8.1) (pull_request) Successful in 43s
CI / Tests (PHP 8.5) (pull_request) Successful in 42s
CI / Static Analysis (pull_request) Successful in 56s
CI / Build Plugin Zip (pull_request) Skipped
CI / Coding Standards (pull_request) Successful in 31s
CI / Tests (PHP 8.2) (pull_request) Successful in 30s
CI / Tests (PHP 8.3) (pull_request) Successful in 31s
CI / No Debug Code (pull_request) Successful in 5s
CI / Tests (PHP 8.1) (pull_request) Successful in 43s
CI / Tests (PHP 8.5) (pull_request) Successful in 42s
CI / Static Analysis (pull_request) Successful in 56s
CI / Build Plugin Zip (pull_request) Skipped
A payer's account credit should offset any charge raised at booking, so drop the scheduled-only guard. Covers the one-time pay-now flow too. Co-authored-by: anthropic/claude-opus-4-8
This commit is contained in:
co-authored by
anthropic/claude-opus-4-8
parent
e3ab7973d6
commit
362980d008
@@ -196,8 +196,8 @@ class LessonBooker {
|
|||||||
payerId: $payerId
|
payerId: $payerId
|
||||||
);
|
);
|
||||||
|
|
||||||
// Apply any available credit to a scheduled charge raised at booking.
|
// Apply any available credit to a charge raised at booking.
|
||||||
if ( $offering->isScheduledBilling() && null !== $payment && null !== $payment->id && Payment::STATUS_PENDING === $payment->status ) {
|
if ( null !== $payment && null !== $payment->id && Payment::STATUS_PENDING === $payment->status ) {
|
||||||
$this->payments->applyCredits( $payerId, [ $payment ] );
|
$this->payments->applyCredits( $payerId, [ $payment ] );
|
||||||
$payment = $this->payments->findPayment( (int) $payment->id ) ?? $payment;
|
$payment = $this->payments->findPayment( (int) $payment->id ) ?? $payment;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,12 @@ class AdminBookingTest extends TestCase
|
|||||||
$this->bookings = Mockery::mock(BookingRepository::class);
|
$this->bookings = Mockery::mock(BookingRepository::class);
|
||||||
$this->offerings = Mockery::mock(OfferingRepository::class);
|
$this->offerings = Mockery::mock(OfferingRepository::class);
|
||||||
$this->payments = Mockery::mock(PaymentService::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 = Mockery::mock(GuardianService::class);
|
||||||
$this->guardians->shouldReceive('payerFor')->andReturnUsing(static fn (int $id): int => $id)->byDefault();
|
$this->guardians->shouldReceive('payerFor')->andReturnUsing(static fn (int $id): int => $id)->byDefault();
|
||||||
|
|
||||||
|
|||||||
@@ -57,9 +57,9 @@ class BookingEndpointTest extends TestCase
|
|||||||
// Crediting a cancelled paid lesson is exercised in dedicated tests; other
|
// Crediting a cancelled paid lesson is exercised in dedicated tests; other
|
||||||
// cancellation paths simply allow the call.
|
// cancellation paths simply allow the call.
|
||||||
$this->payments->shouldReceive('creditForCancelledLesson')->andReturn(null)->byDefault();
|
$this->payments->shouldReceive('creditForCancelledLesson')->andReturn(null)->byDefault();
|
||||||
// A charge-at-booking scheduled lesson (an add-on to an already-billed month)
|
// A charge raised at booking applies the payer's credit before it settles.
|
||||||
// applies the payer's credit before it settles. The default holds no balance
|
// The default holds no balance and re-reads the same payment; the
|
||||||
// and re-reads the same payment; the same-month-rebook test overrides both.
|
// same-month-rebook test overrides both.
|
||||||
$this->payments->shouldReceive('applyCredits')->andReturn([])->byDefault();
|
$this->payments->shouldReceive('applyCredits')->andReturn([])->byDefault();
|
||||||
$this->payments->shouldReceive('findPayment')->andReturnUsing(
|
$this->payments->shouldReceive('findPayment')->andReturnUsing(
|
||||||
static fn (int $id): ?Payment => null
|
static fn (int $id): ?Payment => null
|
||||||
|
|||||||
Reference in New Issue
Block a user