PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.4
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.4
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Modules / Payments / Classes / PaymentReceipt.php

PaymentReceipt.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.4, at app/Modules/Payments/Classes/PaymentReceipt.php

348 lines 10.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Modules\Payments\Classes;
4
5 if (!defined('ABSPATH')) {
6 exit; // Exit if accessed directly.
7 }
8
9 use FluentForm\App\Modules\Payments\Orders\OrderData;
10 use FluentForm\App\Modules\Payments\PaymentHelper;
11
12 class PaymentReceipt
13 {
14
15 private $entry;
16
17 private $orderItems = null;
18
19 private $subscriptions = null;
20 private $subscriptionTotal = null;
21
22 private $discountItems = null;
23
24 public function __construct($entry)
25 {
26 $this->entry = $entry;
27 }
28
29 public function getItem($property)
30 {
31 $methodMaps = [
32 'receipt' => 'renderReceipt',
33 'summary' => 'paymentInfo',
34 'summary_list' => 'paymentInfoTable',
35 'order_items' => 'itemDetails',
36 'subscription_items' => 'subscriptionDetails'
37 ];
38
39 $submissionMaps = [
40 'payment_status',
41 'payment_total',
42 'payment_method'
43 ];
44
45 if(isset($methodMaps[$property])) {
46 $html = $this->{$methodMaps[$property]}();
47 $html .= $this->loadCss();
48 return $html;
49 }
50
51 if(in_array($property, $submissionMaps)) {
52 return $this->getSubmissionValue($property);
53 }
54
55 return '';
56
57 }
58
59 public function getSubmissionValue($property)
60 {
61 if($property == 'payment_total') {
62 return OrderData::getTotalPaid($this->entry);
63 }
64
65 $value = '';
66 if(property_exists($this->entry, $property)) {
67 $value = $this->entry->{$property};
68 }
69
70 if($property == 'payment_method' && $value == 'test') {
71 return __('Offline', 'fluentform');
72 }
73
74 return ucfirst($value);
75 }
76
77 public function getOrderItems()
78 {
79 if (!is_null($this->orderItems)) {
80 return $this->orderItems;
81 }
82
83 $this->orderItems = OrderData::getOrderItems($this->entry);
84 return $this->orderItems;
85 }
86
87 private function getSubscriptions()
88 {
89 if (!is_null($this->subscriptions)) {
90 return $this->subscriptions;
91 }
92
93 list($subscriptions, $total) = OrderData::getSubscriptionsAndPaymentTotal($this->entry);
94
95 $this->subscriptions = $subscriptions;
96 $this->subscriptionTotal = PaymentHelper::formatMoney($total, $this->entry->currency);
97
98 return $this->subscriptions;
99 }
100
101 public function getDiscountItems()
102 {
103 if (!is_null($this->discountItems)) {
104 return $this->discountItems;
105 }
106
107 $this->discountItems = OrderData::getDiscounts($this->entry);
108 return $this->discountItems;
109 }
110
111 public function renderReceipt()
112 {
113 $submission = $this->entry;
114
115 if (!$submission) {
116 return '<p class="ff_invalid_receipt">' . __('Invalid submission. No receipt found', 'fluentform') . '</p>';
117 }
118
119 $html = $this->beforePaymentReceipt();
120
121 $html .= $this->paymentInfo();
122
123 if (count($this->getOrderItems())) {
124 $html .= '<h4>' . __('Order Details', 'fluentform') . '</h4>';
125 $html .= $this->itemDetails();
126 }
127
128 if (count($this->getSubscriptions())) {
129 $html .= '<h4>' . __('Subscriptions', 'fluentform') . '</h4>';
130 $html .= $this->subscriptionDetails();
131 }
132
133 $html .= $this->customerDetails();
134 $html .= $this->afterPaymentReceipt();
135 $html .= $this->loadCss();
136 return $html;
137 }
138
139 private function beforePaymentReceipt()
140 {
141 ob_start();
142 echo '<div class="ff_payment_receipt">';
143 do_action_deprecated(
144 'fluentform_payment_receipt_before_content',
145 [
146 $this->entry
147 ],
148 FLUENTFORM_FRAMEWORK_UPGRADE,
149 'fluentform/payment_receipt_before_content',
150 'Use fluentform/payment_receipt_before_content instead of fluentform_partial_submission_step_completed.'
151 );
152 do_action('fluentform/payment_receipt_before_content', $this->entry);
153 return ob_get_clean();
154 }
155
156 private function afterPaymentReceipt()
157 {
158 ob_start();
159 do_action_deprecated(
160 'fluentform_payment_receipt_after_content',
161 [
162 $this->entry
163 ],
164 FLUENTFORM_FRAMEWORK_UPGRADE,
165 'fluentform/payment_receipt_after_content',
166 'Use fluentform/payment_receipt_after_content instead of fluentform_payment_receipt_after_content.'
167 );
168 do_action('fluentform/payment_receipt_after_content', $this->entry);
169 echo '</div>';
170 return ob_get_clean();
171 }
172
173
174 private function paymentInfo()
175 {
176 $preRender = apply_filters_deprecated(
177 'fluentform_payment_receipt_pre_render_payment_info',
178 [
179 '',
180 $this->entry
181 ],
182 FLUENTFORM_FRAMEWORK_UPGRADE,
183 'fluentform/payment_receipt_pre_render_payment_info',
184 'Use fluentform/payment_receipt_pre_render_payment_info instead of fluentform_payment_receipt_pre_render_payment_info.'
185 );
186 $preRender = apply_filters('fluentform/payment_receipt_pre_render_payment_info', $preRender, $this->entry);
187 if ($preRender) {
188 return $preRender;
189 }
190
191 $orderItems = $this->getOrderItems();
192 $subscriptions = $this->getSubscriptions();
193
194 if (!count($orderItems) && !count($subscriptions)) {
195 return;
196 }
197
198 $submission = $this->entry;
199
200 if($submission->payment_method == 'test') {
201 $submission->payment_method = __('Offline', 'fluentform');
202 }
203
204 $discountItems = $this->getDiscountItems();
205
206 return $this->loadView('payment_info', array(
207 'submission' => $submission,
208 'items' => $orderItems,
209 'discount_items' => $discountItems,
210 'totalPaid' => OrderData::getTotalPaid($submission)
211 ));
212 }
213
214 private function paymentInfoTable()
215 {
216 $preRender = apply_filters_deprecated(
217 'fluentform_payment_receipt_pre_render_payment_info_list',
218 [
219 '',
220 $this->entry
221 ],
222 FLUENTFORM_FRAMEWORK_UPGRADE,
223 'fluentform/payment_receipt_pre_render_payment_info_list',
224 'Use fluentform/payment_receipt_pre_render_payment_info_list instead of fluentform_payment_receipt_pre_render_payment_info_list.'
225 );
226 $preRender = apply_filters('fluentform/payment_receipt_pre_render_payment_info_list', $preRender, $this->entry);
227 if ($preRender) {
228 return $preRender;
229 }
230
231 $orderItems = $this->getOrderItems();
232
233 if (!count($orderItems)) {
234 return '';
235 }
236
237 $discountItems = $this->getDiscountItems();
238
239 return $this->loadView('payment_info_list', array(
240 'submission' => $this->entry,
241 'items' => $orderItems,
242 'orderTotal' => OrderData::calculateOrderItemsTotal($orderItems, true, $this->entry->currency, $discountItems)
243 ));
244 }
245
246
247 private function itemDetails()
248 {
249 $orderItems = $this->getOrderItems();
250 $preRender = apply_filters_deprecated(
251 'fluentform_payment_receipt_pre_render_item_details',
252 [
253 '',
254 $this->entry,
255 $orderItems
256 ],
257 FLUENTFORM_FRAMEWORK_UPGRADE,
258 'fluentform/payment_receipt_pre_render_item_details',
259 'Use fluentform/payment_receipt_pre_render_item_details instead of fluentform_payment_receipt_pre_render_item_details.'
260 );
261 $preRender = apply_filters('fluentform/payment_receipt_pre_render_item_details', $preRender, $this->entry, $orderItems);
262 if ($preRender) {
263 return $preRender;
264 }
265
266 if (!count($orderItems)) {
267 return '';
268 }
269
270 $discountItems = $this->getDiscountItems();
271
272 return $this->loadView('order_items_table', array(
273 'submission' => $this->entry,
274 'items' => $orderItems,
275 'discount_items' => $discountItems,
276 'subTotal' => OrderData::calculateOrderItemsTotal($orderItems, true, $this->entry->currency),
277 'orderTotal' => OrderData::calculateOrderItemsTotal($orderItems, true, $this->entry->currency, $discountItems)
278 ));
279 }
280
281 private function customerDetails()
282 {
283 $preRender = apply_filters_deprecated(
284 'fluentform_payment_receipt_pre_render_submission_details',
285 [
286 '',
287 $this->entry
288 ],
289 FLUENTFORM_FRAMEWORK_UPGRADE,
290 'fluentform/payment_receipt_pre_render_submission_details',
291 'Use fluentform/payment_receipt_pre_render_submission_details instead of fluentform_payment_receipt_pre_render_submission_details.'
292 );
293 $preRender = apply_filters('fluentform/payment_receipt_pre_render_submission_details', $preRender, $this->entry);
294 if ($preRender) {
295 return $preRender;
296 }
297
298 $transactions = OrderData::getTransactions($this->entry->id);
299 if (!$transactions || empty($transactions[0])) {
300 return;
301 }
302
303 $transaction = $transactions[0];
304
305 return $this->loadView('customer_details', array(
306 'submission' => $this->entry,
307 'transaction' => $transaction
308 ));
309 }
310
311 private function loadCss()
312 {
313 return $this->loadView('custom_css', array('submission' => $this->entry));
314 }
315
316 public function loadView($fileName, $data)
317 {
318 return PaymentHelper::loadView($fileName, $data);
319 }
320
321 private function subscriptionDetails()
322 {
323 $subscriptions = $this->getSubscriptions();
324 $preRender = apply_filters_deprecated(
325 'fluentform_payment_receipt_pre_render_subscription_details',
326 [
327 '',
328 $this->entry,
329 $subscriptions
330 ],
331 FLUENTFORM_FRAMEWORK_UPGRADE,
332 'fluentform/payment_receipt_pre_render_subscription_details',
333 'Use fluentform/payment_receipt_pre_render_subscription_details instead of fluentform_payment_receipt_pre_render_subscription_details.'
334 );
335 $preRender = apply_filters('fluentform/payment_receipt_pre_render_subscription_details', $preRender, $this->entry, $subscriptions);
336
337 if ($preRender) {
338 return $preRender;
339 }
340
341 return $this->loadView('subscriptions_table', array(
342 'submission' => $this->entry,
343 'subscriptions' => $subscriptions,
344 'orderTotal' => $this->subscriptionTotal
345 ));
346 }
347 }
348