| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Events\Order; |
| 4 |
|
| 5 |
use FluentCart\App\Events\EventDispatcher; |
| 6 |
use FluentCart\App\Listeners; |
| 7 |
use FluentCart\App\Models\Customer; |
| 8 |
use FluentCart\App\Models\Order; |
| 9 |
use FluentCart\App\Models\OrderTransaction; |
| 10 |
|
| 11 |
class OrderPaymentFailed extends EventDispatcher |
| 12 |
{ |
| 13 |
|
| 14 |
public string $hook = 'fluent_cart/order_payment_failed'; |
| 15 |
protected array $listeners = [ |
| 16 |
Listeners\Order\OrderPaymentFailed::class, |
| 17 |
]; |
| 18 |
|
| 19 |
/** |
| 20 |
* @var Order $order |
| 21 |
*/ |
| 22 |
public Order $order; |
| 23 |
|
| 24 |
/** |
| 25 |
* @var Customer|null $customer |
| 26 |
*/ |
| 27 |
public ?Customer $customer; |
| 28 |
|
| 29 |
/** |
| 30 |
* @var OrderTransaction|null $transaction |
| 31 |
*/ |
| 32 |
|
| 33 |
/** |
| 34 |
* @var string|null $oldStatus |
| 35 |
*/ |
| 36 |
public ?string $oldStatus; |
| 37 |
|
| 38 |
/** |
| 39 |
* @var string|null $newStatus |
| 40 |
*/ |
| 41 |
public ?string $newStatus; |
| 42 |
|
| 43 |
/** |
| 44 |
* @var string|null $reason |
| 45 |
*/ |
| 46 |
public ?string $reason; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public ?OrderTransaction $transaction; |
| 51 |
|
| 52 |
public function __construct(Order $order, $transaction = null, $oldStatus = null, $newStatus = null, $reason = null) |
| 53 |
{ |
| 54 |
$this->order = $order; |
| 55 |
$this->order->load('customer', 'order_items', 'shipping_address', 'billing_address'); |
| 56 |
$this->customer = $order->customer; |
| 57 |
$this->transaction = $transaction; |
| 58 |
$this->oldStatus = $oldStatus; |
| 59 |
$this->newStatus = $newStatus; |
| 60 |
$this->reason = $reason; |
| 61 |
} |
| 62 |
|
| 63 |
public function toArray(): array |
| 64 |
{ |
| 65 |
return [ |
| 66 |
'order' => $this->order, |
| 67 |
'customer' => $this->customer ?? null, |
| 68 |
'transaction' => $this->transaction ?? null, |
| 69 |
'old_status' => $this->oldStatus, |
| 70 |
'new_status' => $this->newStatus, |
| 71 |
'reason' => $this->reason, |
| 72 |
]; |
| 73 |
} |
| 74 |
|
| 75 |
public function getActivityEventModel() |
| 76 |
{ |
| 77 |
return $this->order; |
| 78 |
} |
| 79 |
|
| 80 |
public function beforeDispatch() |
| 81 |
{ |
| 82 |
// Add any pre-dispatch logic here if needed |
| 83 |
} |
| 84 |
|
| 85 |
public function afterDispatch() |
| 86 |
{ |
| 87 |
// to do: maybe add some logic here |
| 88 |
|
| 89 |
} |
| 90 |
|
| 91 |
} |
| 92 |
|
| 93 |
|