PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Events / Order / OrderPaid.php

OrderPaid.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Events/Order/OrderPaid.php

82 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 OrderPaid extends EventDispatcher
12 {
13
14 public string $hook = 'fluent_cart/order_paid';
15 protected array $listeners = [
16 Listeners\Order\OrderPaid::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 public ?OrderTransaction $transaction;
33
34 public function __construct(Order $order, $customer = null, $transaction = null)
35 {
36 $this->order = $order;
37 $this->order->load('customer', 'order_items', 'shipping_address', 'billing_address');
38 $this->customer = $customer;
39 $this->transaction = $transaction;
40 }
41
42 public function toArray(): array
43 {
44 return [
45 'order' => $this->order,
46 'customer' => $this->customer ?? null,
47 'transaction' => $this->transaction ?? null
48 ];
49 }
50
51 public function getActivityEventModel()
52 {
53 return $this->order;
54 }
55
56 public function beforeDispatch()
57 {
58 if (!$this->order->receipt_number) {
59 $this->order = $this->order->generateReceiptNumber();
60 }
61 }
62
63 public function afterDispatch()
64 {
65 /**
66 * 3rd party devs: Please do not use this hook to add any action that
67 * use: fluent_cart/order_paid_done
68 */
69 $id = as_enqueue_async_action('fluent_cart/order_paid_async_private_handle', [
70 [
71 'order_id' => $this->order->id
72 ]
73 ], 'fluent-cart');
74
75 if ($id) {
76 $this->order->updateMeta('action_scheduler_id', $id);
77 }
78
79 }
80
81 }
82