PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.6
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.6
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.6, at app/Modules/Payments/Classes/PaymentReceipt.php

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