Revert "Make MarkBookingRefunded synchronous so refunds cancel instantly"
This reverts commit 825320a117.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Modules\Payment\Listeners;
|
namespace Modules\Payment\Listeners;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Modules\Booking\Enums\BookingStatus;
|
use Modules\Booking\Enums\BookingStatus;
|
||||||
use Modules\Payment\Events\RefundProcessed;
|
use Modules\Payment\Events\RefundProcessed;
|
||||||
|
|
||||||
@@ -10,14 +11,8 @@ use Modules\Payment\Events\RefundProcessed;
|
|||||||
* completes (domain.md §5). Guarded the same way as MarkBookingPaid — only
|
* completes (domain.md §5). Guarded the same way as MarkBookingPaid — only
|
||||||
* ever moves a still-confirmed booking, never clobbers one that moved on
|
* ever moves a still-confirmed booking, never clobbers one that moved on
|
||||||
* for another reason.
|
* for another reason.
|
||||||
*
|
|
||||||
* Deliberately synchronous, unlike MarkBookingPaid — a refund is always
|
|
||||||
* initiated from a request that's already waiting on it (the Filament
|
|
||||||
* action or the API endpoint), and staff expect the booking's status to
|
|
||||||
* read Cancelled the instant that request completes, not once a queue
|
|
||||||
* worker gets to it.
|
|
||||||
*/
|
*/
|
||||||
class MarkBookingRefunded
|
class MarkBookingRefunded implements ShouldQueue
|
||||||
{
|
{
|
||||||
public function handle(RefundProcessed $event): void
|
public function handle(RefundProcessed $event): void
|
||||||
{
|
{
|
||||||
@@ -27,6 +22,10 @@ class MarkBookingRefunded
|
|||||||
// pre-redesign rows where booking_id wasn't yet recorded.
|
// pre-redesign rows where booking_id wasn't yet recorded.
|
||||||
$booking = $event->refund->booking ?? $event->refund->payment->booking;
|
$booking = $event->refund->booking ?? $event->refund->payment->booking;
|
||||||
|
|
||||||
|
// Booking uses SoftDeletes — normally unreachable here (a confirmed
|
||||||
|
// booking is never deletable, BookingPolicy::delete), but this
|
||||||
|
// listener is queued, so it's worth guarding against a booking that
|
||||||
|
// vanished between dispatch and execution regardless.
|
||||||
if ($booking === null) {
|
if ($booking === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ test('does not touch a booking that already moved on for another reason', functi
|
|||||||
expect($booking->refresh()->status)->toBe(BookingStatus::Cancelled);
|
expect($booking->refresh()->status)->toBe(BookingStatus::Cancelled);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('does not crash if the booking was soft-deleted before this listener ran', function () {
|
test('does not crash if the booking was soft-deleted before this queued listener ran', function () {
|
||||||
$booking = Booking::factory()->create(['status' => BookingStatus::Confirmed]);
|
$booking = Booking::factory()->create(['status' => BookingStatus::Confirmed]);
|
||||||
$payment = Payment::factory()->completed()->create(['booking_id' => $booking->id, 'gateway' => PaymentMethod::KbzMiniApp]);
|
$payment = Payment::factory()->completed()->create(['booking_id' => $booking->id, 'gateway' => PaymentMethod::KbzMiniApp]);
|
||||||
$refund = Refund::factory()->create(['payment_id' => $payment->id, 'status' => RefundStatus::Completed]);
|
$refund = Refund::factory()->create(['payment_id' => $payment->id, 'status' => RefundStatus::Completed]);
|
||||||
|
|||||||
Reference in New Issue
Block a user