Add refund action to booking list/detail with full-refund toggle
- New RefundBookingTableAction on the booking list row and detail page, refunding a Confirmed booking directly via RefundBookingAction — no need to hunt up its Payment on the Refunds resource first. - Payment::refundableBalance() extracted from RefundBookingAction's private balance check so both refund forms can display and cap against it. - RefundBookingAction::resolveRefundablePayment() made public for the same reason (round-trip leg resolution reused by the UI). - Both refund forms (ProcessRefundAction and the new booking action) gain a "Full refund" toggle, on by default, which refunds the payment's whole remaining balance without requiring a manually typed amount. Turning it off reveals an amount field capped at the refundable balance.
This commit is contained in:
@@ -77,7 +77,7 @@ test('the process action is visible to a user with process_refunds', function ()
|
||||
->assertActionVisible('process');
|
||||
});
|
||||
|
||||
test('processing a refund via the action calls RefundBookingAction and cancels the booking', function () {
|
||||
test('processing a partial refund via the action calls RefundBookingAction and cancels the booking', function () {
|
||||
$admin = User::factory()->create()->givePermissionTo(['view_payments', 'process_refunds']);
|
||||
$this->actingAs($admin);
|
||||
|
||||
@@ -92,13 +92,64 @@ test('processing a refund via the action calls RefundBookingAction and cancels t
|
||||
Livewire::test(ListRefunds::class)
|
||||
->callAction('process', data: [
|
||||
'payment_id' => $payment->id,
|
||||
'amount' => 15000,
|
||||
'full_refund' => false,
|
||||
'amount' => 5000,
|
||||
'reason' => 'customer requested cancellation',
|
||||
])
|
||||
->assertNotified();
|
||||
|
||||
expect($booking->refresh()->status)->toBe(BookingStatus::Cancelled)
|
||||
->and(Refund::where('payment_id', $payment->id)->where('status', RefundStatus::Completed)->exists())->toBeTrue();
|
||||
->and(Refund::where('payment_id', $payment->id)->where('status', RefundStatus::Completed)->where('amount', 5000)->exists())->toBeTrue();
|
||||
});
|
||||
|
||||
test('the full refund toggle refunds the payment\'s whole refundable balance without an amount input', function () {
|
||||
$admin = User::factory()->create()->givePermissionTo(['view_payments', 'process_refunds']);
|
||||
$this->actingAs($admin);
|
||||
|
||||
$booking = Booking::factory()->create(['status' => BookingStatus::Confirmed, 'price' => 15000]);
|
||||
$payment = Payment::factory()->completed()->create([
|
||||
'booking_id' => $booking->id,
|
||||
'gateway' => PaymentMethod::KbzMiniApp,
|
||||
'amount' => 15000,
|
||||
'gateway_transaction_id' => 'EVB-FILAMENT-FULL-1',
|
||||
]);
|
||||
|
||||
Livewire::test(ListRefunds::class)
|
||||
->callAction('process', data: [
|
||||
'payment_id' => $payment->id,
|
||||
'full_refund' => true,
|
||||
'reason' => 'customer requested cancellation',
|
||||
])
|
||||
->assertNotified();
|
||||
|
||||
expect(Refund::where('payment_id', $payment->id)->where('status', RefundStatus::Completed)->where('amount', 15000)->exists())->toBeTrue();
|
||||
});
|
||||
|
||||
test('the full refund toggle defaults to on', function () {
|
||||
$admin = User::factory()->create()->givePermissionTo(['view_payments', 'process_refunds']);
|
||||
$this->actingAs($admin);
|
||||
|
||||
Livewire::test(ListRefunds::class)
|
||||
->mountAction('process')
|
||||
->assertActionDataSet(['full_refund' => true]);
|
||||
});
|
||||
|
||||
test('turning the full refund toggle off requires an amount', function () {
|
||||
$admin = User::factory()->create()->givePermissionTo(['view_payments', 'process_refunds']);
|
||||
$this->actingAs($admin);
|
||||
|
||||
$payment = Payment::factory()->completed()->create([
|
||||
'gateway' => PaymentMethod::KbzMiniApp,
|
||||
'amount' => 15000,
|
||||
]);
|
||||
|
||||
Livewire::test(ListRefunds::class)
|
||||
->callAction('process', data: [
|
||||
'payment_id' => $payment->id,
|
||||
'full_refund' => false,
|
||||
'reason' => 'reason',
|
||||
])
|
||||
->assertHasFormErrors(['amount' => 'required']);
|
||||
});
|
||||
|
||||
test('a non-completed payment is not offered in the process action\'s payment select', function () {
|
||||
@@ -151,3 +202,27 @@ test('a payment whose booking has been soft-deleted is not offered in the proces
|
||||
|
||||
expect(Refund::where('payment_id', $payment->id)->exists())->toBeFalse();
|
||||
});
|
||||
|
||||
test('the process action\'s amount field is capped at the selected payment\'s refundable balance', function () {
|
||||
$admin = User::factory()->create()->givePermissionTo(['view_payments', 'process_refunds']);
|
||||
$this->actingAs($admin);
|
||||
|
||||
$booking = Booking::factory()->create(['status' => BookingStatus::Confirmed, 'price' => 15000]);
|
||||
$payment = Payment::factory()->completed()->create([
|
||||
'booking_id' => $booking->id,
|
||||
'gateway' => PaymentMethod::KbzMiniApp,
|
||||
'amount' => 15000,
|
||||
'gateway_transaction_id' => 'EVB-FILAMENT-MAX-1',
|
||||
]);
|
||||
|
||||
Livewire::test(ListRefunds::class)
|
||||
->callAction('process', data: [
|
||||
'payment_id' => $payment->id,
|
||||
'full_refund' => false,
|
||||
'amount' => 15000.01,
|
||||
'reason' => 'reason',
|
||||
])
|
||||
->assertHasFormErrors(['amount' => 'max']);
|
||||
|
||||
expect(Refund::where('payment_id', $payment->id)->exists())->toBeFalse();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user