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 / Subscription / SubscriptionEOT.php

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

75 lines 1.7 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\Subscription;
4
5 use FluentCart\App\Events\EventDispatcher;
6 use FluentCart\App\Models\Order;
7 use FluentCart\App\Models\Subscription;
8
9 class SubscriptionEOT extends EventDispatcher
10 {
11
12 public string $hook = 'fluent_cart/subscription_eot';
13 protected array $listeners = [];
14
15 /**
16 * @var Subscription
17 */
18 public Subscription $subscription;
19
20 /**
21 * @var Order
22 */
23 public Order $order;
24
25 public function __construct(Subscription $subscription, Order $order)
26 {
27 $this->subscription = $subscription;
28 $this->order = $order;
29 $this->order->load('customer');
30 }
31
32
33 public function toArray(): array
34 {
35 return [
36 'subscription' => $this->subscription,
37 'order' => $this->order,
38 'customer' => $this->order->customer ?? [],
39 ];
40 }
41
42 public function beforeDispatch()
43 {
44 $result = $this->subscription->cancelRemoteSubscription([
45 'reason' => 'end_of_term',
46 'fire_hooks' => false,
47 'effective_from' => 'immediately',
48 ]);
49
50 if (is_wp_error($result)) {
51 fluent_cart_add_log(
52 'Remote subscription cancellation failed on EOT',
53 'Subscription #' . $this->subscription->id . ': ' . $result->get_error_message(),
54 'error',
55 [
56 'module' => 'subscription',
57 'module_id' => $this->subscription->id
58 ]
59 );
60 }
61 }
62
63 public function getActivityEventModel()
64 {
65 return $this->subscription;
66 }
67
68 public function shouldCreateActivity(): bool
69 {
70 return true;
71 }
72
73 }
74
75