Feature: Order Service Provider, Order Events Observers
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Order\Observers;
|
||||
|
||||
use Lunar\Models\Order;
|
||||
use Modules\Core\Order\Events\OrderStatusUpdated;
|
||||
|
||||
class OrderObserver
|
||||
{
|
||||
public function updated(Order $order): void
|
||||
{
|
||||
if (! $order->wasChanged('status')) {
|
||||
return;
|
||||
}
|
||||
|
||||
OrderStatusUpdated::dispatch(
|
||||
$order,
|
||||
$order->getOriginal('status'),
|
||||
$order->status,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Order\Observers;
|
||||
|
||||
use Lunar\Models\Transaction;
|
||||
use Modules\Core\Order\Events\OrderCaptured;
|
||||
use Modules\Core\Order\Events\OrderRefunded;
|
||||
|
||||
class TransactionObserver
|
||||
{
|
||||
public function saved(Transaction $transaction): void
|
||||
{
|
||||
if (! $transaction->success) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($transaction->type === 'refund' && $transaction->wasRecentlyCreated) {
|
||||
OrderRefunded::dispatch($transaction->order, $transaction);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($transaction->type === 'capture' && $transaction->wasChanged('type')) {
|
||||
OrderCaptured::dispatch($transaction->order, $transaction);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user