Feature: Order Service Provider, Order Events Observers
This commit is contained in:
@@ -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