PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.21
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.21
1.6.5 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 All 48 releases
fluent-cart / app / Services / Email / EmailPreviewService.php

EmailPreviewService.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.21, at app/Services/Email/EmailPreviewService.php

190 lines 6.3 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\Services\Email;
4
5 use FluentCart\App\Services\DateTime\DateTime;
6 use FluentCart\Framework\Support\Collection;
7 use FluentCart\Framework\Support\Str;
8
9 class EmailPreviewService
10 {
11 public function getPreviewData(string $template): array
12 {
13 $order = $this->getDummyOrder();
14 $subscription = $this->getDummySubscription($order);
15 $customer = $order->customer;
16 $transaction = $order->getLatestTransaction();
17
18 $previewData = [
19 'order' => $order,
20 'subscription' => $subscription,
21 'customer' => $customer,
22 'transaction' => $transaction,
23 'reminder' => [
24 'stage' => 'before_0',
25 'due_at' => DateTime::gmtNow()->addDays(2)->format('Y-m-d H:i:s'),
26 'due_amount' => 4900,
27 'payment_link' => '#',
28 'order_ref' => $order->invoice_no,
29 'billing_date' => DateTime::gmtNow()->addDays(30)->format('Y-m-d H:i:s'),
30 'trial_end_date' => DateTime::gmtNow()->addDays(3)->format('Y-m-d H:i:s'),
31 ],
32 ];
33
34 if (Str::startsWith($template, 'subscription.')) {
35 $previewData['transaction'] = $subscription->getLatestTransaction();
36
37 if (Str::contains($template, 'trial_end')) {
38 $previewData['reminder']['stage'] = 'trial_end_3';
39 }
40
41 if (Str::contains($template, 'canceled')) {
42 $previewData['reason'] = __('canceled on customer request', 'fluent-cart');
43 $previewData['subscription'] = $this->getDummySubscription($previewData['order']);
44 }
45 }
46
47 return $previewData;
48 }
49
50 private function getDummyCustomer(): object
51 {
52 return (object) [
53 'full_name' => 'John Doe',
54 'first_name' => 'John',
55 'last_name' => 'Doe',
56 'email' => '[email protected]',
57 ];
58 }
59
60 private function getDummyTransaction(): object
61 {
62 return new class {
63 public $created_at = '';
64 public $total = 4900;
65 public $vendor_charge_id = 'ch_preview_123';
66 public $order = null;
67
68 public function getPaymentMethodText()
69 {
70 return 'card';
71 }
72 };
73 }
74
75 private function getDummyOrder(): object
76 {
77 $customer = $this->getDummyCustomer();
78 $transaction = $this->getDummyTransaction();
79
80 return new class($customer, $transaction, new Collection()) {
81 public $id = 1001;
82 public $uuid = 'preview-order-uuid';
83 public $invoice_no = 'FC-1001';
84 public $customer;
85 public $order_items;
86 public $subscriptions;
87 public $orderTaxRates;
88 public $billing_address;
89 public $shipping_address;
90 public $fulfillment_type = 'digital';
91 public $subtotal = 4900;
92 public $manual_discount_total = 0;
93 public $coupon_discount_total = 0;
94 public $shipping_tax = 0;
95 public $shipping_total = 0;
96 public $tax_total = 0;
97 public $tax_behavior = 2;
98 public $total_amount = 4900;
99 public $total_paid = 0;
100 public $total_refund = 0;
101 public $payment_status = 'pending';
102 private $latestTransaction;
103
104 public function __construct($customer, $transaction, $emptyCollection)
105 {
106 $this->customer = $customer;
107 $this->latestTransaction = $transaction;
108 $this->order_items = new Collection([
109 [
110 'post_title' => 'Sample Product',
111 'quantity' => 1,
112 'title' => 'Standard Plan',
113 'payment_type' => 'onetime',
114 'payment_info' => '',
115 'formatted_total' => '$49.00',
116 ],
117 ]);
118 $this->subscriptions = $emptyCollection;
119 $this->orderTaxRates = $emptyCollection;
120 $this->billing_address = null;
121 $this->shipping_address = null;
122 }
123
124 public function getViewUrl($type = 'customer')
125 {
126 return '#';
127 }
128
129 public function getLatestTransaction()
130 {
131 return $this->latestTransaction;
132 }
133
134 public function getDownloads($scope = 'email')
135 {
136 return [];
137 }
138
139 public function getLicenses($with = ['product', 'productVariant'])
140 {
141 return new Collection([]);
142 }
143 };
144 }
145
146 private function getDummySubscription($order): object
147 {
148 $customer = $order->customer ?? $this->getDummyCustomer();
149 $transaction = $this->getDummyTransaction();
150
151 return new class($customer, $transaction, $order) {
152 public $id = 2001;
153 public $uuid = 'preview-subscription-uuid';
154 public $item_name = 'Sample Subscription';
155 public $billing_interval = 'yearly';
156 public $next_billing_date;
157 public $recurring_total = 4900;
158 public $status = 'active';
159 public $trial_ends_at;
160 public $customer;
161 public $order;
162 private $latestTransaction;
163
164 public function __construct($customer, $transaction, $order)
165 {
166 $this->customer = $customer;
167 $this->latestTransaction = $transaction;
168 $this->order = $order;
169 $this->next_billing_date = \FluentCart\App\Services\DateTime\DateTime::gmtNow()->addDays(30)->format('Y-m-d H:i:s');
170 $this->trial_ends_at = \FluentCart\App\Services\DateTime\DateTime::gmtNow()->addDays(3)->format('Y-m-d H:i:s');
171 }
172
173 public function getLatestTransaction()
174 {
175 return $this->latestTransaction;
176 }
177
178 public function getViewUrl($type = 'customer')
179 {
180 return '#';
181 }
182
183 public function getReactivateUrl()
184 {
185 return '#';
186 }
187 };
188 }
189 }
190