PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.3
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.3
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.5.3, at app/Services/Email/EmailPreviewService.php

209 lines 7.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 __construct()
69 {
70 $this->created_at = DateTime::gmtNow();
71 }
72
73 public function getPaymentMethodText()
74 {
75 return 'card';
76 }
77 };
78 }
79
80 private function getDummyOrder(): object
81 {
82 $customer = $this->getDummyCustomer();
83 $transaction = $this->getDummyTransaction();
84
85 return new class($customer, $transaction, new Collection()) {
86 public $id = 1001;
87 public $uuid = 'preview-order-uuid';
88 public $invoice_no = 'FC-1001';
89 public $customer;
90 public $order_items;
91 public $subscriptions;
92 public $orderTaxRates;
93 public $billing_address;
94 public $shipping_address;
95 public $fulfillment_type = 'digital';
96 public $subtotal = 4900;
97 public $manual_discount_total = 0;
98 public $coupon_discount_total = 0;
99 public $shipping_tax = 0;
100 public $shipping_total = 0;
101 public $tax_total = 0;
102 public $tax_behavior = 2;
103 public $total_amount = 4900;
104 public $total_paid = 0;
105 public $total_refund = 0;
106 public $payment_status = 'pending';
107 private $latestTransaction;
108
109 public function __construct($customer, $transaction, $emptyCollection)
110 {
111 $this->customer = $customer;
112 $this->latestTransaction = $transaction;
113 $this->order_items = new Collection([
114 [
115 'post_title' => 'Sample Product',
116 'quantity' => 1,
117 'title' => 'Standard Plan',
118 'payment_type' => 'onetime',
119 'payment_info' => '',
120 'formatted_total' => '$49.00',
121 'package_info' => __('Package: Medium Box · 30 × 20 × 15 cm · Wt: 2 kg · Shipping wt: 2.5 kg', 'fluent-cart'),
122 'other_info' => [
123 'package_name' => 'Medium Box',
124 'package_type' => 'box',
125 'package_length' => 30,
126 'package_width' => 20,
127 'package_height' => 15,
128 'package_dimension_unit' => 'cm',
129 'weight' => 2,
130 'weight_unit' => 'kg',
131 'package_weight' => 0.5,
132 'package_weight_unit' => 'kg',
133 'package_slug' => 'medium-box',
134 ],
135 ],
136 ]);
137 $this->subscriptions = $emptyCollection;
138 $this->orderTaxRates = $emptyCollection;
139 $this->billing_address = null;
140 $this->shipping_address = null;
141 }
142
143 public function getViewUrl($type = 'customer')
144 {
145 return '#';
146 }
147
148 public function getLatestTransaction()
149 {
150 return $this->latestTransaction;
151 }
152
153 public function getDownloads($scope = 'email')
154 {
155 return [];
156 }
157
158 public function getLicenses($with = ['product', 'productVariant'])
159 {
160 return new Collection([]);
161 }
162 };
163 }
164
165 private function getDummySubscription($order): object
166 {
167 $customer = $order->customer ?? $this->getDummyCustomer();
168 $transaction = $this->getDummyTransaction();
169
170 return new class($customer, $transaction, $order) {
171 public $id = 2001;
172 public $uuid = 'preview-subscription-uuid';
173 public $item_name = 'Sample Subscription';
174 public $billing_interval = 'yearly';
175 public $next_billing_date;
176 public $recurring_total = 4900;
177 public $status = 'active';
178 public $trial_ends_at;
179 public $customer;
180 public $order;
181 private $latestTransaction;
182
183 public function __construct($customer, $transaction, $order)
184 {
185 $this->customer = $customer;
186 $this->latestTransaction = $transaction;
187 $this->order = $order;
188 $this->next_billing_date = \FluentCart\App\Services\DateTime\DateTime::gmtNow()->addDays(30)->format('Y-m-d H:i:s');
189 $this->trial_ends_at = \FluentCart\App\Services\DateTime\DateTime::gmtNow()->addDays(3)->format('Y-m-d H:i:s');
190 }
191
192 public function getLatestTransaction()
193 {
194 return $this->latestTransaction;
195 }
196
197 public function getViewUrl($type = 'customer')
198 {
199 return '#';
200 }
201
202 public function getReactivateUrl()
203 {
204 return '#';
205 }
206 };
207 }
208 }
209