PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.15
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.15
6.2.15 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 All 197 releases
← All changes | app/Modules/Payments/Classes/PaymentEntries.php +56 -57 6.2.9 → 6.2.15 View file →
@@ -21,9 +21,8 @@
21 21 add_action('fluentform/render_payment_entries', array($this, 'loadApp'));
22 22 add_action('wp_ajax_fluentform_get_payments', array($this, 'getPayments'));
23 23 add_action('wp_ajax_fluentform-do_entry_bulk_actions_payment', array($this, 'handleBulkAction'));
24 24 add_action('wp_ajax_fluentform_get_all_payments_entries_filters', array($this, 'getFilters'));
25 -
26 25 }
27 26
28 27 public function loadApp()
29 28 {
@@ -39,9 +38,9 @@
39 38 'Use fluentform/global_menu instead of fluentform_global_menu.'
40 39 );
41 40 do_action('fluentform/global_menu');
42 41 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $settingsUrl is escaped via esc_url
43 - echo '<div id="ff_payment_entries"><ff-payment-entries settings_url="'.esc_url($settingsUrl).'"></ff-payment-entries><global-search></global-search></div>';
42 + echo '<div id="ff_payment_entries"><ff-payment-entries settings_url="' . esc_url($settingsUrl) . '"></ff-payment-entries><global-search></global-search></div>';
44 43 }
45 44
46 45 public function getPayments()
47 46 {
@@ -46,9 +45,9 @@
46 45 public function getPayments()
47 46 {
48 47 $request = wpFluentForm()->request;
49 48 $attributes = $request->all();
50 -
49 +
51 50 // Sanitize request data
52 51 $sanitizeMap = [
53 52 'form_id' => function ($value) {
54 53 return Acl::normalizeFormId($value);
@@ -58,32 +57,32 @@
58 57 'payment_types' => 'sanitize_text_field',
59 58 'payment_methods' => 'sanitize_text_field',
60 59 ];
61 60 $attributes = fluentform_backend_sanitizer($attributes, $sanitizeMap);
62 -
61 +
63 62 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verified by Acl::verify() below
64 63 Acl::verify('fluentform_view_payments', ArrayHelper::get($attributes, 'form_id'));
65 64 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verified by Acl::verify() above
66 65 $perPage = ArrayHelper::get($attributes, 'per_page', 10);
67 - if(!$perPage) {
66 + if (!$perPage) {
68 67 $perPage = 10;
69 68 }
70 69 $paymentsQuery = Transaction::select([
71 - 'fluentform_transactions.id',
72 - 'fluentform_transactions.form_id',
73 - 'fluentform_transactions.submission_id',
74 - 'fluentform_transactions.transaction_type',
75 - 'fluentform_transactions.payment_method',
76 - 'fluentform_transactions.payment_mode',
77 - 'fluentform_transactions.charge_id',
78 - 'fluentform_transactions.card_brand',
79 - 'fluentform_transactions.payment_total',
80 - 'fluentform_transactions.created_at',
81 - 'fluentform_transactions.payer_name',
82 - 'fluentform_transactions.status',
83 - 'fluentform_transactions.currency',
84 - 'fluentform_forms.title'
85 - ])
70 + 'fluentform_transactions.id',
71 + 'fluentform_transactions.form_id',
72 + 'fluentform_transactions.submission_id',
73 + 'fluentform_transactions.transaction_type',
74 + 'fluentform_transactions.payment_method',
75 + 'fluentform_transactions.payment_mode',
76 + 'fluentform_transactions.charge_id',
77 + 'fluentform_transactions.card_brand',
78 + 'fluentform_transactions.payment_total',
79 + 'fluentform_transactions.created_at',
80 + 'fluentform_transactions.payer_name',
81 + 'fluentform_transactions.status',
82 + 'fluentform_transactions.currency',
83 + 'fluentform_forms.title',
84 + ])
86 85 ->join('fluentform_forms', 'fluentform_forms.id', '=', 'fluentform_transactions.form_id')
87 86 ->orderBy('fluentform_transactions.id', 'DESC');
88 87
89 88 if ($selectedFormId = ArrayHelper::get($attributes, 'form_id')) {
@@ -91,9 +90,9 @@
91 90 }
92 91
93 92 $allowFormIds = apply_filters('fluentform/current_user_allowed_forms', false);
94 93 if (false !== $allowFormIds && is_array($allowFormIds)) {
95 - $paymentsQuery = $paymentsQuery->whereIn('fluentform_transactions.form_id', $allowFormIds ?: [0]);
94 + $paymentsQuery = $paymentsQuery->whereIn('fluentform_transactions.form_id', $allowFormIds ? $allowFormIds : [0]);
96 95 }
97 96 if ($paymentStatus = ArrayHelper::get($attributes, 'payment_statuses')) {
98 97 $paymentsQuery = $paymentsQuery->where('fluentform_transactions.status', $paymentStatus);
99 98 }
@@ -107,10 +106,10 @@
107 106
108 107 $payments = $paymentsPaginate->items();
109 108 foreach ($payments as $payment) {
110 109 $payment->formatted_payment_total = PaymentHelper::formatMoney($payment->payment_total, $payment->currency);
111 - $payment->entry_url = admin_url('admin.php?page=fluent_forms&route=entries&form_id='.$payment->form_id.'#/entries/'.$payment->submission_id);
112 - if($payment->payment_method == 'test') {
110 + $payment->entry_url = admin_url('admin.php?page=fluent_forms&route=entries&form_id=' . $payment->form_id . '#/entries/' . $payment->submission_id);
111 + if ('test' == $payment->payment_method) {
113 112 $payment->payment_method = 'offline';
114 113 }
115 114 }
116 115 wp_send_json_success([
@@ -117,20 +116,21 @@
117 116 'payments' => $payments,
118 117 'total' => $paymentsPaginate->total(),
119 118 'current_page' => $paymentsPaginate->currentPage(),
120 119 'per_page' => $paymentsPaginate->perPage(),
121 - 'last_page' => $paymentsPaginate->lastPage()
120 + 'last_page' => $paymentsPaginate->lastPage(),
122 121 ]);
122 + }
123 123
124 - }
125 -
126 124 public function handleBulkAction()
127 125 {
126 + Acl::verify('fluentform_manage_payments');
127 +
128 128 $request = wpFluentForm()->request;
129 129 $attributes = $request->all();
130 -
130 +
131 131 $sanitizeMap = [
132 - 'entries' => function($value) {
132 + 'entries' => function ($value) {
133 133 if (is_array($value)) {
134 134 return array_map('intval', $value);
135 135 }
136 136 return [];
@@ -137,21 +137,21 @@
137 137 },
138 138 'action_type' => 'sanitize_text_field',
139 139 ];
140 140 $attributes = fluentform_backend_sanitizer($attributes, $sanitizeMap);
141 -
141 +
142 142 $entries = ArrayHelper::get($attributes, 'entries', []);
143 143 $actionType = ArrayHelper::get($attributes, 'action_type');
144 144 if (!$actionType || !count($entries)) {
145 145 wp_send_json_error([
146 - 'message' => __('Please select entries & action first', 'fluentform')
146 + 'message' => __('Please select entries & action first', 'fluentform'),
147 147 ], 400);
148 148 }
149 -
150 - $message = __("Invalid action", 'fluentform');
149 +
150 + $message = __('Invalid action', 'fluentform');
151 151 $statusCode = 400;
152 152 // permanently delete payment entries from transactions
153 - if ($actionType == 'delete_items') {
153 + if ('delete_items' == $actionType) {
154 154 // get submission ids to delete order items
155 155 $transactionData = Transaction::select(['id', 'form_id', 'submission_id'])
156 156 ->whereIn('id', $entries)
157 157 ->get();
@@ -171,9 +171,9 @@
171 171 do_action_deprecated(
172 172 'fluentform_before_entry_payment_deleted',
173 173 [
174 174 $entries,
175 - $transactionData
175 + $transactionData,
176 176 ],
177 177 FLUENTFORM_FRAMEWORK_UPGRADE,
178 178 'fluentform/before_entry_payment_deleted',
179 179 'Use fluentform/before_entry_payment_deleted instead of fluentform_before_entry_payment_deleted.'
@@ -178,9 +178,9 @@
178 178 'fluentform/before_entry_payment_deleted',
179 179 'Use fluentform/before_entry_payment_deleted instead of fluentform_before_entry_payment_deleted.'
180 180 );
181 181 do_action('fluentform/before_entry_payment_deleted', $entries, $transactionData);
182 -
182 +
183 183 //delete data from transaction table
184 184 Transaction::whereIn('id', $entries)->delete();
185 185
186 186 //delete data from order table
@@ -187,11 +187,11 @@
187 187 OrderItem::whereIn('submission_id', $submission_ids)->delete();
188 188
189 189 // delete data from subscriptions table
190 190 Subscription::whereIn('submission_id', $submission_ids)->delete();
191 -
191 +
192 192 //add log in each form that payment record has been deleted
193 - foreach ($transactionData as $data){
193 + foreach ($transactionData as $data) {
194 194 $logData = [
195 195 'parent_source_id' => $data->form_id,
196 196 'source_type' => 'submission_item',
197 197 'source_id' => $data->submission_id,
@@ -205,9 +205,9 @@
205 205 do_action_deprecated(
206 206 'fluentform_after_entry_payment_deleted',
207 207 [
208 208 $entries,
209 - $transactionData
209 + $transactionData,
210 210 ],
211 211 FLUENTFORM_FRAMEWORK_UPGRADE,
212 212 'fluentform/after_entry_payment_deleted',
213 213 'Use fluentform/after_entry_payment_deleted instead of fluentform_after_entry_payment_deleted.'
@@ -214,23 +214,23 @@
214 214 );
215 215 do_action('fluentform/after_entry_payment_deleted', $entries, $transactionData);
216 216 $message = __('Selected entries successfully deleted', 'fluentform');
217 217 $statusCode = 200;
218 -
218 +
219 219 } catch (\Exception $exception) {
220 220 $message = $exception->getMessage();
221 221 $statusCode = 400;
222 222 }
223 223 }
224 -
224 +
225 225 wp_send_json_success([
226 - 'message' => $message
226 + 'message' => $message,
227 227 ], $statusCode);
228 228 }
229 229
230 230 private function authorizeTransactionForms($transactionData)
231 231 {
232 - Acl::verify('fluentform_forms_manager');
232 + Acl::verify('fluentform_manage_payments');
233 233
234 234 $formIds = [];
235 235
236 236 foreach ($transactionData as $transaction) {
@@ -237,11 +237,11 @@
237 237 $formIds[(int) $transaction->form_id] = true;
238 238 }
239 239
240 240 foreach (array_keys($formIds) as $formId) {
241 - if (!Acl::hasPermission('fluentform_forms_manager', $formId)) {
241 + if (!Acl::hasPermission('fluentform_manage_payments', $formId)) {
242 242 wp_send_json_error([
243 - 'message' => __('You do not have permission to perform this action.', 'fluentform')
243 + 'message' => __('You do not have permission to perform this action.', 'fluentform'),
244 244 ], 422);
245 245 }
246 246 }
247 247 }
@@ -268,9 +268,9 @@
268 268 if ($selectedFormId) {
269 269 $transactionTypesQuery = $transactionTypesQuery->where('form_id', $selectedFormId);
270 270 }
271 271 if (false !== $allowFormIds && is_array($allowFormIds)) {
272 - $transactionTypesQuery = $transactionTypesQuery->whereIn('form_id', $allowFormIds ?: [0]);
272 + $transactionTypesQuery = $transactionTypesQuery->whereIn('form_id', $allowFormIds ? $allowFormIds : [0]);
273 273 }
274 274
275 275 $transactionTypes = $transactionTypesQuery
276 276 ->groupBy('transaction_type')
@@ -279,26 +279,26 @@
279 279 $transactionTypeLabels = [
280 280 'onetime' => __('Charge', 'fluentform'),
281 281 'refund' => __('Refund', 'fluentform'),
282 282 'subscription' => __('Subscription', 'fluentform'),
283 - 'renewal' => __('Renewal', 'fluentform')
283 + 'renewal' => __('Renewal', 'fluentform'),
284 284 ];
285 -
285 +
286 286 $formattedTransactionTypes = [];
287 287 foreach ($transactionTypes as $type) {
288 288 $label = ArrayHelper::get($transactionTypeLabels, $type->transaction_type, ucfirst($type->transaction_type));
289 289 $formattedTransactionTypes[] = [
290 290 'value' => $label,
291 - 'key' => $type->transaction_type
291 + 'key' => $type->transaction_type,
292 292 ];
293 293 }
294 -
294 +
295 295 $statusesQuery = Transaction::select('status');
296 296 if ($selectedFormId) {
297 297 $statusesQuery = $statusesQuery->where('form_id', $selectedFormId);
298 298 }
299 299 if (false !== $allowFormIds && is_array($allowFormIds)) {
300 - $statusesQuery = $statusesQuery->whereIn('form_id', $allowFormIds ?: [0]);
300 + $statusesQuery = $statusesQuery->whereIn('form_id', $allowFormIds ? $allowFormIds : [0]);
301 301 }
302 302
303 303 $statuses = $statusesQuery
304 304 ->groupBy('status')
@@ -315,9 +315,9 @@
315 315 if ($selectedFormId) {
316 316 $formsQuery = $formsQuery->where('fluentform_transactions.form_id', $selectedFormId);
317 317 }
318 318 if (false !== $allowFormIds && is_array($allowFormIds)) {
319 - $formsQuery = $formsQuery->whereIn('fluentform_transactions.form_id', $allowFormIds ?: [0]);
319 + $formsQuery = $formsQuery->whereIn('fluentform_transactions.form_id', $allowFormIds ? $allowFormIds : [0]);
320 320 }
321 321
322 322 $forms = $formsQuery
323 323 ->groupBy('fluentform_transactions.form_id')
@@ -328,9 +328,9 @@
328 328 $formattedForms = [];
329 329 foreach ($forms as $form) {
330 330 $formattedForms[] = [
331 331 'form_id' => $form->form_id,
332 - 'title' => $form->title
332 + 'title' => $form->title,
333 333 ];
334 334 }
335 335
336 336 $paymentMethodsQuery = Transaction::select('payment_method');
@@ -337,9 +337,9 @@
337 337 if ($selectedFormId) {
338 338 $paymentMethodsQuery = $paymentMethodsQuery->where('form_id', $selectedFormId);
339 339 }
340 340 if (false !== $allowFormIds && is_array($allowFormIds)) {
341 - $paymentMethodsQuery = $paymentMethodsQuery->whereIn('form_id', $allowFormIds ?: [0]);
341 + $paymentMethodsQuery = $paymentMethodsQuery->whereIn('form_id', $allowFormIds ? $allowFormIds : [0]);
342 342 }
343 343
344 344 $paymentMethods = $paymentMethodsQuery
345 345 ->groupBy('payment_method')
@@ -346,18 +346,18 @@
346 346 ->get();
347 347
348 348 $formattedMethods = [];
349 349 foreach ($paymentMethods as $method) {
350 - if(!$method->payment_method){
350 + if (!$method->payment_method) {
351 351 continue;
352 352 }
353 - if ($method->payment_method == 'test') {
353 + if ('test' == $method->payment_method) {
354 354 $formattedMethods[] = ['value' => __('Offline', 'fluentform'), 'key' => $method->payment_method];
355 355 } else {
356 356 $formattedMethods[] = ['value' => ucfirst($method->payment_method), 'key' => $method->payment_method];
357 357 }
358 358 }
359 -
359 +
360 360 wp_send_json_success([
361 361 'available_payment_types' => $formattedTransactionTypes,
362 362 'available_statuses' => $formattedStatuses,
363 363 'available_forms' => $formattedForms,
@@ -362,7 +362,6 @@
362 362 'available_statuses' => $formattedStatuses,
363 363 'available_forms' => $formattedForms,
364 364 'available_methods' => array_filter($formattedMethods),
365 365 ]);
366 -
367 366 }
368 367 }