28 lines
692 B
PHP
28 lines
692 B
PHP
<?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);
|
|
}
|
|
}
|
|
}
|