Feat: Payment Restructuring to be fully event-driven
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Order\Listeners;
|
||||
|
||||
use Lunar\Models\Order;
|
||||
use Modules\Core\Payment\Events\OrderPaymentStatusResolved;
|
||||
|
||||
/**
|
||||
* The only place an Order's status column is written in reaction to a
|
||||
* payment outcome — Payment dispatches OrderPaymentStatusResolved with
|
||||
* what the status should become, never touching the Order model itself;
|
||||
* this listener, living in Order's own module, is what applies it.
|
||||
*
|
||||
* Loads and saves the model (not a bulk ::whereKey()->update()) so
|
||||
* Order::observe()'s updated() hook fires and OrderStatusUpdated goes out
|
||||
* the same as any other status write — see that event's own docblock for
|
||||
* why it's meant to fire "regardless of what wrote it."
|
||||
*/
|
||||
class ApplyResolvedPaymentStatus
|
||||
{
|
||||
public function handle(OrderPaymentStatusResolved $event): void
|
||||
{
|
||||
$order = Order::findOrFail($event->orderId);
|
||||
$order->update(['status' => $event->status]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user