@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @since 2.0.0 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * GetPaid REST date based controller class. |
@@ -43,26 +43,26 @@ discard block |
||
43 | 43 | * @param WP_REST_Request $request Request object. |
44 | 44 | * @return array The appropriate date range. |
45 | 45 | */ |
46 | - public function get_date_range( $request ) { |
|
46 | + public function get_date_range($request) { |
|
47 | 47 | |
48 | 48 | // Check if the period is x_days. |
49 | - if ( preg_match( '/^(\d+)_days$/', $request['period'], $matches ) ) { |
|
50 | - $date_range = $this->get_x_days_date_range( absint( $matches[1] ) ); |
|
51 | - } elseif ( is_callable( array( $this, 'get_' . $request['period'] . '_date_range' ) ) ) { |
|
52 | - $date_range = call_user_func( array( $this, 'get_' . $request['period'] . '_date_range' ), $request ); |
|
49 | + if (preg_match('/^(\d+)_days$/', $request['period'], $matches)) { |
|
50 | + $date_range = $this->get_x_days_date_range(absint($matches[1])); |
|
51 | + } elseif (is_callable(array($this, 'get_' . $request['period'] . '_date_range'))) { |
|
52 | + $date_range = call_user_func(array($this, 'get_' . $request['period'] . '_date_range'), $request); |
|
53 | 53 | } else { |
54 | 54 | $request['period'] = '7_days'; |
55 | 55 | $date_range = $this->get_x_days_date_range(); |
56 | 56 | } |
57 | 57 | |
58 | 58 | // 3 months max for day view. |
59 | - $before = strtotime( $date_range['before'] ); |
|
60 | - $after = strtotime( $date_range['after'] ); |
|
61 | - if ( floor( ( $before - $after ) / MONTH_IN_SECONDS ) > 2 ) { |
|
59 | + $before = strtotime($date_range['before']); |
|
60 | + $after = strtotime($date_range['after']); |
|
61 | + if (floor(($before - $after) / MONTH_IN_SECONDS) > 2) { |
|
62 | 62 | $this->groupby = 'month'; |
63 | 63 | } |
64 | 64 | |
65 | - $this->prepare_interval( $date_range ); |
|
65 | + $this->prepare_interval($date_range); |
|
66 | 66 | |
67 | 67 | return $date_range; |
68 | 68 | |
@@ -74,25 +74,25 @@ discard block |
||
74 | 74 | * @param array $range Date range. |
75 | 75 | * @return array The appropriate date range. |
76 | 76 | */ |
77 | - public function prepare_interval( $range ) { |
|
77 | + public function prepare_interval($range) { |
|
78 | 78 | |
79 | - $before = strtotime( $range['before'] ); |
|
80 | - $after = strtotime( $range['after'] ); |
|
81 | - if ( 'day' === $this->groupby ) { |
|
82 | - $difference = max( DAY_IN_SECONDS, ( DAY_IN_SECONDS + $before - $after ) ); // Prevent division by 0; |
|
83 | - $this->interval = absint( ceil( max( 1, $difference / DAY_IN_SECONDS ) ) ); |
|
79 | + $before = strtotime($range['before']); |
|
80 | + $after = strtotime($range['after']); |
|
81 | + if ('day' === $this->groupby) { |
|
82 | + $difference = max(DAY_IN_SECONDS, (DAY_IN_SECONDS + $before - $after)); // Prevent division by 0; |
|
83 | + $this->interval = absint(ceil(max(1, $difference / DAY_IN_SECONDS))); |
|
84 | 84 | return; |
85 | 85 | } |
86 | 86 | |
87 | 87 | $this->interval = 0; |
88 | - $min_date = strtotime( gmdate( 'Y-m-01', $after ) ); |
|
88 | + $min_date = strtotime(gmdate('Y-m-01', $after)); |
|
89 | 89 | |
90 | - while ( $min_date <= $before ) { |
|
91 | - $this->interval ++; |
|
92 | - $min_date = strtotime( '+1 MONTH', $min_date ); |
|
90 | + while ($min_date <= $before) { |
|
91 | + $this->interval++; |
|
92 | + $min_date = strtotime('+1 MONTH', $min_date); |
|
93 | 93 | } |
94 | 94 | |
95 | - $this->interval = max( 1, $this->interval ); |
|
95 | + $this->interval = max(1, $this->interval); |
|
96 | 96 | |
97 | 97 | } |
98 | 98 | |
@@ -102,27 +102,27 @@ discard block |
||
102 | 102 | * @param WP_REST_Request $request Request object. |
103 | 103 | * @return array The appropriate date range. |
104 | 104 | */ |
105 | - public function get_custom_date_range( $request ) { |
|
105 | + public function get_custom_date_range($request) { |
|
106 | 106 | |
107 | - $after = max( strtotime( '-20 years' ), strtotime( sanitize_text_field( $request['after'] ) ) ); |
|
108 | - $before = gmdate( 'Y-m-d' ); |
|
107 | + $after = max(strtotime('-20 years'), strtotime(sanitize_text_field($request['after']))); |
|
108 | + $before = gmdate('Y-m-d'); |
|
109 | 109 | |
110 | - if ( ! empty( $request['before'] ) ) { |
|
111 | - $before = min( strtotime( $before ), strtotime( sanitize_text_field( $request['before'] ) ) ); |
|
110 | + if (!empty($request['before'])) { |
|
111 | + $before = min(strtotime($before), strtotime(sanitize_text_field($request['before']))); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | // Set the previous date range. |
115 | 115 | $difference = $before - $after; |
116 | 116 | $this->previous_range = array( |
117 | 117 | 'period' => 'custom', |
118 | - 'before' => gmdate( 'Y-m-d', $before - $difference - DAY_IN_SECONDS ), |
|
119 | - 'after' => gmdate( 'Y-m-d', $after - $difference - DAY_IN_SECONDS ), |
|
118 | + 'before' => gmdate('Y-m-d', $before - $difference - DAY_IN_SECONDS), |
|
119 | + 'after' => gmdate('Y-m-d', $after - $difference - DAY_IN_SECONDS), |
|
120 | 120 | ); |
121 | 121 | |
122 | 122 | // Generate the report. |
123 | 123 | return array( |
124 | - 'before' => gmdate( 'Y-m-d', $before ), |
|
125 | - 'after' => gmdate( 'Y-m-d', $after ), |
|
124 | + 'before' => gmdate('Y-m-d', $before), |
|
125 | + 'after' => gmdate('Y-m-d', $after), |
|
126 | 126 | ); |
127 | 127 | |
128 | 128 | } |
@@ -141,8 +141,8 @@ discard block |
||
141 | 141 | |
142 | 142 | // Generate the report. |
143 | 143 | return array( |
144 | - 'before' => gmdate( 'Y-m-d' ), |
|
145 | - 'after' => gmdate( 'Y-m-d' ), |
|
144 | + 'before' => gmdate('Y-m-d'), |
|
145 | + 'after' => gmdate('Y-m-d'), |
|
146 | 146 | ); |
147 | 147 | |
148 | 148 | } |
@@ -157,14 +157,14 @@ discard block |
||
157 | 157 | // Set the previous date range. |
158 | 158 | $this->previous_range = array( |
159 | 159 | 'period' => 'custom', |
160 | - 'before' => gmdate( 'Y-m-d', strtotime( '-2 days' ) ), |
|
161 | - 'after' => gmdate( 'Y-m-d', strtotime( '-2 days' ) ), |
|
160 | + 'before' => gmdate('Y-m-d', strtotime('-2 days')), |
|
161 | + 'after' => gmdate('Y-m-d', strtotime('-2 days')), |
|
162 | 162 | ); |
163 | 163 | |
164 | 164 | // Generate the report. |
165 | 165 | return array( |
166 | - 'before' => gmdate( 'Y-m-d', strtotime( '-1 day' ) ), |
|
167 | - 'after' => gmdate( 'Y-m-d', strtotime( '-1 day' ) ), |
|
166 | + 'before' => gmdate('Y-m-d', strtotime('-1 day')), |
|
167 | + 'after' => gmdate('Y-m-d', strtotime('-1 day')), |
|
168 | 168 | ); |
169 | 169 | |
170 | 170 | } |
@@ -182,10 +182,10 @@ discard block |
||
182 | 182 | ); |
183 | 183 | |
184 | 184 | // Generate the report. |
185 | - $week_starts = absint( get_option( 'start_of_week' ) ); |
|
185 | + $week_starts = absint(get_option('start_of_week')); |
|
186 | 186 | return array( |
187 | - 'before' => gmdate( 'Y-m-d' ), |
|
188 | - 'after' => gmdate( 'Y-m-d', strtotime( 'next Sunday -' . ( 7 - $week_starts ) . ' days' ) ), |
|
187 | + 'before' => gmdate('Y-m-d'), |
|
188 | + 'after' => gmdate('Y-m-d', strtotime('next Sunday -' . (7 - $week_starts) . ' days')), |
|
189 | 189 | ); |
190 | 190 | } |
191 | 191 | |
@@ -196,19 +196,19 @@ discard block |
||
196 | 196 | */ |
197 | 197 | public function get_last_week_date_range() { |
198 | 198 | |
199 | - $week_starts = absint( get_option( 'start_of_week' ) ); |
|
200 | - $week_starts = strtotime( 'last Sunday -' . ( 7 - $week_starts ) . ' days' ); |
|
199 | + $week_starts = absint(get_option('start_of_week')); |
|
200 | + $week_starts = strtotime('last Sunday -' . (7 - $week_starts) . ' days'); |
|
201 | 201 | $date_range = array( |
202 | - 'before' => gmdate( 'Y-m-d', $week_starts + 6 * DAY_IN_SECONDS ), |
|
203 | - 'after' => gmdate( 'Y-m-d', $week_starts ), |
|
202 | + 'before' => gmdate('Y-m-d', $week_starts + 6 * DAY_IN_SECONDS), |
|
203 | + 'after' => gmdate('Y-m-d', $week_starts), |
|
204 | 204 | ); |
205 | 205 | |
206 | 206 | // Set the previous date range. |
207 | 207 | $week_starts = $week_starts - 7 * DAY_IN_SECONDS; |
208 | 208 | $this->previous_range = array( |
209 | 209 | 'period' => 'custom', |
210 | - 'before' => gmdate( 'Y-m-d', $week_starts + 6 * DAY_IN_SECONDS ), |
|
211 | - 'after' => gmdate( 'Y-m-d', $week_starts ), |
|
210 | + 'before' => gmdate('Y-m-d', $week_starts + 6 * DAY_IN_SECONDS), |
|
211 | + 'after' => gmdate('Y-m-d', $week_starts), |
|
212 | 212 | ); |
213 | 213 | |
214 | 214 | // Generate the report. |
@@ -220,13 +220,13 @@ discard block |
||
220 | 220 | * |
221 | 221 | * @return array The appropriate date range. |
222 | 222 | */ |
223 | - public function get_x_days_date_range( $days = 7 ) { |
|
223 | + public function get_x_days_date_range($days = 7) { |
|
224 | 224 | |
225 | 225 | $days--; |
226 | 226 | |
227 | - $date_range = array( |
|
228 | - 'before' => gmdate( 'Y-m-d' ), |
|
229 | - 'after' => gmdate( 'Y-m-d', strtotime( "-$days days" ) ), |
|
227 | + $date_range = array( |
|
228 | + 'before' => gmdate('Y-m-d'), |
|
229 | + 'after' => gmdate('Y-m-d', strtotime("-$days days")), |
|
230 | 230 | ); |
231 | 231 | |
232 | 232 | $days++; |
@@ -234,8 +234,8 @@ discard block |
||
234 | 234 | // Set the previous date range. |
235 | 235 | $this->previous_range = array( |
236 | 236 | 'period' => 'custom', |
237 | - 'before' => gmdate( 'Y-m-d', strtotime( $date_range['before'] ) - $days * DAY_IN_SECONDS ), |
|
238 | - 'after' => gmdate( 'Y-m-d', strtotime( $date_range['after'] ) - $days * DAY_IN_SECONDS ), |
|
237 | + 'before' => gmdate('Y-m-d', strtotime($date_range['before']) - $days * DAY_IN_SECONDS), |
|
238 | + 'after' => gmdate('Y-m-d', strtotime($date_range['after']) - $days * DAY_IN_SECONDS), |
|
239 | 239 | ); |
240 | 240 | |
241 | 241 | // Generate the report. |
@@ -256,8 +256,8 @@ discard block |
||
256 | 256 | |
257 | 257 | // Generate the report. |
258 | 258 | return array( |
259 | - 'after' => gmdate( 'Y-m-01' ), |
|
260 | - 'before' => gmdate( 'Y-m-t' ), |
|
259 | + 'after' => gmdate('Y-m-01'), |
|
260 | + 'before' => gmdate('Y-m-t'), |
|
261 | 261 | ); |
262 | 262 | |
263 | 263 | } |
@@ -272,14 +272,14 @@ discard block |
||
272 | 272 | // Set the previous date range. |
273 | 273 | $this->previous_range = array( |
274 | 274 | 'period' => 'custom', |
275 | - 'after' => gmdate( 'Y-m-01', strtotime( '-2 months' ) ), |
|
276 | - 'before' => gmdate( 'Y-m-t', strtotime( '-2 months' ) ), |
|
275 | + 'after' => gmdate('Y-m-01', strtotime('-2 months')), |
|
276 | + 'before' => gmdate('Y-m-t', strtotime('-2 months')), |
|
277 | 277 | ); |
278 | 278 | |
279 | 279 | // Generate the report. |
280 | 280 | return array( |
281 | - 'after' => gmdate( 'Y-m-01', strtotime( 'last month' ) ), |
|
282 | - 'before' => gmdate( 'Y-m-t', strtotime( 'last month' ) ), |
|
281 | + 'after' => gmdate('Y-m-01', strtotime('last month')), |
|
282 | + 'before' => gmdate('Y-m-t', strtotime('last month')), |
|
283 | 283 | ); |
284 | 284 | |
285 | 285 | } |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | */ |
292 | 292 | public function get_quarters() { |
293 | 293 | |
294 | - $year = (int) gmdate( 'Y' ); |
|
294 | + $year = (int) gmdate('Y'); |
|
295 | 295 | $last_year = (int) $year - 1; |
296 | 296 | return array( |
297 | 297 | |
@@ -340,9 +340,9 @@ discard block |
||
340 | 340 | */ |
341 | 341 | public function get_quarter() { |
342 | 342 | |
343 | - $month = (int) gmdate( 'n' ); |
|
344 | - $quarters = array( 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4 ); |
|
345 | - return $quarters[ $month - 1 ]; |
|
343 | + $month = (int) gmdate('n'); |
|
344 | + $quarters = array(1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4); |
|
345 | + return $quarters[$month - 1]; |
|
346 | 346 | |
347 | 347 | } |
348 | 348 | |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | // Generate the report. |
362 | 362 | $quarter = $this->get_quarter(); |
363 | 363 | $quarters = $this->get_quarters(); |
364 | - return $quarters[ $quarter + 1 ]; |
|
364 | + return $quarters[$quarter + 1]; |
|
365 | 365 | |
366 | 366 | } |
367 | 367 | |
@@ -377,12 +377,12 @@ discard block |
||
377 | 377 | |
378 | 378 | // Set the previous date range. |
379 | 379 | $this->previous_range = array_merge( |
380 | - $quarters[ $quarter - 1 ], |
|
381 | - array( 'period' => 'custom' ) |
|
380 | + $quarters[$quarter - 1], |
|
381 | + array('period' => 'custom') |
|
382 | 382 | ); |
383 | 383 | |
384 | 384 | // Generate the report. |
385 | - return $quarters[ $quarter ]; |
|
385 | + return $quarters[$quarter]; |
|
386 | 386 | |
387 | 387 | } |
388 | 388 | |
@@ -400,8 +400,8 @@ discard block |
||
400 | 400 | |
401 | 401 | // Generate the report. |
402 | 402 | return array( |
403 | - 'after' => gmdate( 'Y-01-01' ), |
|
404 | - 'before' => gmdate( 'Y-12-31' ), |
|
403 | + 'after' => gmdate('Y-01-01'), |
|
404 | + 'before' => gmdate('Y-12-31'), |
|
405 | 405 | ); |
406 | 406 | |
407 | 407 | } |
@@ -416,14 +416,14 @@ discard block |
||
416 | 416 | // Set the previous date range. |
417 | 417 | $this->previous_range = array( |
418 | 418 | 'period' => 'custom', |
419 | - 'after' => gmdate( 'Y-01-01', strtotime( '-2 years' ) ), |
|
420 | - 'before' => gmdate( 'Y-12-31', strtotime( '-2 years' ) ), |
|
419 | + 'after' => gmdate('Y-01-01', strtotime('-2 years')), |
|
420 | + 'before' => gmdate('Y-12-31', strtotime('-2 years')), |
|
421 | 421 | ); |
422 | 422 | |
423 | 423 | // Generate the report. |
424 | 424 | return array( |
425 | - 'after' => gmdate( 'Y-01-01', strtotime( 'last year' ) ), |
|
426 | - 'before' => gmdate( 'Y-12-31', strtotime( 'last year' ) ), |
|
425 | + 'after' => gmdate('Y-01-01', strtotime('last year')), |
|
426 | + 'before' => gmdate('Y-12-31', strtotime('last year')), |
|
427 | 427 | ); |
428 | 428 | |
429 | 429 | } |
@@ -435,20 +435,20 @@ discard block |
||
435 | 435 | * @param string $date_field The date field. |
436 | 436 | * @return string The appropriate SQL. |
437 | 437 | */ |
438 | - public function get_date_range_sql( $request, $date_field ) { |
|
438 | + public function get_date_range_sql($request, $date_field) { |
|
439 | 439 | global $wpdb; |
440 | 440 | |
441 | 441 | $sql = '1=1'; |
442 | - $range = $this->get_date_range( $request ); |
|
442 | + $range = $this->get_date_range($request); |
|
443 | 443 | |
444 | - if ( ! empty( $range['after'] ) ) { |
|
444 | + if (!empty($range['after'])) { |
|
445 | 445 | $sql .= ' AND ' . $wpdb->prepare( |
446 | 446 | "$date_field >= %s", |
447 | 447 | $range['after'] |
448 | 448 | ); |
449 | 449 | } |
450 | 450 | |
451 | - if ( ! empty( $range['before'] ) ) { |
|
451 | + if (!empty($range['before'])) { |
|
452 | 452 | $sql .= ' AND ' . $wpdb->prepare( |
453 | 453 | "$date_field <= %s", |
454 | 454 | $range['before'] |
@@ -465,9 +465,9 @@ discard block |
||
465 | 465 | * @param string $date_field The date field. |
466 | 466 | * @return string The appropriate SQL. |
467 | 467 | */ |
468 | - public function get_group_by_sql( $date_field ) { |
|
468 | + public function get_group_by_sql($date_field) { |
|
469 | 469 | |
470 | - if ( 'day' === $this->groupby ) { |
|
470 | + if ('day' === $this->groupby) { |
|
471 | 471 | return "YEAR($date_field), MONTH($date_field), DAY($date_field)"; |
472 | 472 | } |
473 | 473 | |
@@ -481,30 +481,30 @@ discard block |
||
481 | 481 | */ |
482 | 482 | public function get_collection_params() { |
483 | 483 | return array( |
484 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
484 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
485 | 485 | 'period' => array( |
486 | - 'description' => __( 'Limit to results of a specific period.', 'invoicing' ), |
|
486 | + 'description' => __('Limit to results of a specific period.', 'invoicing'), |
|
487 | 487 | 'type' => 'string', |
488 | - 'enum' => array( 'custom', 'today', 'yesterday', 'week', 'last_week', '7_days', '30_days', '60_days', '90_days', '180_days', 'month', 'last_month', 'quarter', 'last_quarter', 'year', 'last_year', 'quarter', 'last_quarter' ), |
|
488 | + 'enum' => array('custom', 'today', 'yesterday', 'week', 'last_week', '7_days', '30_days', '60_days', '90_days', '180_days', 'month', 'last_month', 'quarter', 'last_quarter', 'year', 'last_year', 'quarter', 'last_quarter'), |
|
489 | 489 | 'validate_callback' => 'rest_validate_request_arg', |
490 | 490 | 'sanitize_callback' => 'sanitize_text_field', |
491 | 491 | 'default' => '7_days', |
492 | 492 | ), |
493 | 493 | 'after' => array( |
494 | 494 | /* translators: %s: date format */ |
495 | - 'description' => sprintf( __( 'Limit to results after a specific date, the date needs to be in the %s format.', 'invoicing' ), 'YYYY-MM-DD' ), |
|
495 | + 'description' => sprintf(__('Limit to results after a specific date, the date needs to be in the %s format.', 'invoicing'), 'YYYY-MM-DD'), |
|
496 | 496 | 'type' => 'string', |
497 | 497 | 'validate_callback' => 'rest_validate_request_arg', |
498 | 498 | 'sanitize_callback' => 'sanitize_text_field', |
499 | - 'default' => gmdate( 'Y-m-d', strtotime( '-7 days' ) ), |
|
499 | + 'default' => gmdate('Y-m-d', strtotime('-7 days')), |
|
500 | 500 | ), |
501 | 501 | 'before' => array( |
502 | 502 | /* translators: %s: date format */ |
503 | - 'description' => sprintf( __( 'Limit to results before a specific date, the date needs to be in the %s format.', 'invoicing' ), 'YYYY-MM-DD' ), |
|
503 | + 'description' => sprintf(__('Limit to results before a specific date, the date needs to be in the %s format.', 'invoicing'), 'YYYY-MM-DD'), |
|
504 | 504 | 'type' => 'string', |
505 | 505 | 'validate_callback' => 'rest_validate_request_arg', |
506 | 506 | 'sanitize_callback' => 'sanitize_text_field', |
507 | - 'default' => gmdate( 'Y-m-d' ), |
|
507 | + 'default' => gmdate('Y-m-d'), |
|
508 | 508 | ), |
509 | 509 | ); |
510 | 510 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Main Checkout Class. |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @param GetPaid_Payment_Form_Submission $submission |
24 | 24 | */ |
25 | - public function __construct( $submission ) { |
|
25 | + public function __construct($submission) { |
|
26 | 26 | $this->payment_form_submission = $submission; |
27 | 27 | } |
28 | 28 | |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | // Prepare the invoice. |
39 | 39 | $items = $this->get_submission_items(); |
40 | 40 | $invoice = $this->get_submission_invoice(); |
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
41 | + $invoice = $this->process_submission_invoice($invoice, $items); |
|
42 | 42 | $prepared = $this->prepare_submission_data_for_saving(); |
43 | 43 | |
44 | - $this->prepare_billing_info( $invoice ); |
|
44 | + $this->prepare_billing_info($invoice); |
|
45 | 45 | |
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
46 | + $shipping = $this->prepare_shipping_info($invoice); |
|
47 | 47 | |
48 | 48 | // Save the invoice. |
49 | - $invoice->set_is_viewed( true ); |
|
49 | + $invoice->set_is_viewed(true); |
|
50 | 50 | $invoice->recalculate_total(); |
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action('getpaid_checkout_invoice_updated', $invoice); |
|
54 | 54 | |
55 | 55 | // Send to the gateway. |
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
56 | + $this->post_process_submission($invoice, $prepared, $shipping); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -66,34 +66,34 @@ discard block |
||
66 | 66 | $data = $submission->get_data(); |
67 | 67 | |
68 | 68 | // Do we have an error? |
69 | - if ( ! empty( $submission->last_error ) ) { |
|
70 | - wp_send_json_error( $submission->last_error ); |
|
69 | + if (!empty($submission->last_error)) { |
|
70 | + wp_send_json_error($submission->last_error); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // We need a billing email. |
74 | - if ( ! $submission->has_billing_email() ) { |
|
75 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
74 | + if (!$submission->has_billing_email()) { |
|
75 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Non-recurring gateways should not be allowed to process recurring invoices. |
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
79 | + if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) { |
|
80 | + wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing')); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | // Ensure the gateway is active. |
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
84 | + if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) { |
|
85 | + wp_send_json_error(__('The selected payment gateway is not active', 'invoicing')); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // Clear any existing errors. |
89 | 89 | wpinv_clear_errors(); |
90 | 90 | |
91 | 91 | // Allow themes and plugins to hook to errors |
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
92 | + do_action('getpaid_checkout_error_checks', $submission); |
|
93 | 93 | |
94 | 94 | // Do we have any errors? |
95 | - if ( wpinv_get_errors() ) { |
|
96 | - wp_send_json_error( getpaid_get_errors_html() ); |
|
95 | + if (wpinv_get_errors()) { |
|
96 | + wp_send_json_error(getpaid_get_errors_html()); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | $items = $this->payment_form_submission->get_items(); |
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | - if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
|
112 | - wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
|
111 | + if (empty($items) && !$this->payment_form_submission->has_fees()) { |
|
112 | + wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing')); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | return $items; |
@@ -123,17 +123,17 @@ discard block |
||
123 | 123 | protected function get_submission_invoice() { |
124 | 124 | $submission = $this->payment_form_submission; |
125 | 125 | |
126 | - if ( ! $submission->has_invoice() ) { |
|
126 | + if (!$submission->has_invoice()) { |
|
127 | 127 | $invoice = new WPInv_Invoice(); |
128 | - $invoice->set_created_via( 'payment_form' ); |
|
128 | + $invoice->set_created_via('payment_form'); |
|
129 | 129 | return $invoice; |
130 | 130 | } |
131 | 131 | |
132 | 132 | $invoice = $submission->get_invoice(); |
133 | 133 | |
134 | 134 | // Make sure that it is neither paid or refunded. |
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
135 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
136 | + wp_send_json_error(__('This invoice has already been paid for.', 'invoicing')); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $invoice; |
@@ -146,34 +146,34 @@ discard block |
||
146 | 146 | * @param GetPaid_Form_Item[] $items |
147 | 147 | * @return WPInv_Invoice |
148 | 148 | */ |
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
149 | + protected function process_submission_invoice($invoice, $items) { |
|
150 | 150 | |
151 | 151 | $submission = $this->payment_form_submission; |
152 | 152 | |
153 | 153 | // Set-up the invoice details. |
154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | - $invoice->set_submission_id( $submission->id ); |
|
157 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
158 | - $invoice->set_items( $items ); |
|
159 | - $invoice->set_fees( $submission->get_fees() ); |
|
160 | - $invoice->set_taxes( $submission->get_taxes() ); |
|
161 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
162 | - $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
163 | - $invoice->set_currency( $submission->get_currency() ); |
|
164 | - |
|
165 | - if ( $submission->has_shipping() ) { |
|
166 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
154 | + $invoice->set_email(sanitize_email($submission->get_billing_email())); |
|
155 | + $invoice->set_user_id($this->get_submission_customer()); |
|
156 | + $invoice->set_submission_id($submission->id); |
|
157 | + $invoice->set_payment_form(absint($submission->get_payment_form()->get_id())); |
|
158 | + $invoice->set_items($items); |
|
159 | + $invoice->set_fees($submission->get_fees()); |
|
160 | + $invoice->set_taxes($submission->get_taxes()); |
|
161 | + $invoice->set_discounts($submission->get_discounts()); |
|
162 | + $invoice->set_gateway($submission->get_field('wpi-gateway')); |
|
163 | + $invoice->set_currency($submission->get_currency()); |
|
164 | + |
|
165 | + if ($submission->has_shipping()) { |
|
166 | + $invoice->set_shipping($submission->get_shipping()); |
|
167 | 167 | } |
168 | 168 | |
169 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
170 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
169 | + $address_confirmed = $submission->get_field('confirm-address'); |
|
170 | + $invoice->set_address_confirmed(!empty($address_confirmed)); |
|
171 | 171 | |
172 | - if ( $submission->has_discount_code() ) { |
|
173 | - $invoice->set_discount_code( $submission->get_discount_code() ); |
|
172 | + if ($submission->has_discount_code()) { |
|
173 | + $invoice->set_discount_code($submission->get_discount_code()); |
|
174 | 174 | } |
175 | 175 | |
176 | - getpaid_maybe_add_default_address( $invoice ); |
|
176 | + getpaid_maybe_add_default_address($invoice); |
|
177 | 177 | return $invoice; |
178 | 178 | } |
179 | 179 | |
@@ -186,34 +186,34 @@ discard block |
||
186 | 186 | $submission = $this->payment_form_submission; |
187 | 187 | |
188 | 188 | // If this is an existing invoice... |
189 | - if ( $submission->has_invoice() ) { |
|
189 | + if ($submission->has_invoice()) { |
|
190 | 190 | return $submission->get_invoice()->get_user_id(); |
191 | 191 | } |
192 | 192 | |
193 | 193 | // (Maybe) create the user. |
194 | 194 | $user = get_current_user_id(); |
195 | 195 | |
196 | - if ( empty( $user ) ) { |
|
197 | - $user = get_user_by( 'email', $submission->get_billing_email() ); |
|
196 | + if (empty($user)) { |
|
197 | + $user = get_user_by('email', $submission->get_billing_email()); |
|
198 | 198 | } |
199 | 199 | |
200 | - if ( empty( $user ) ) { |
|
201 | - $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
202 | - $name = implode( '', array_filter( $name ) ); |
|
203 | - $user = wpinv_create_user( $submission->get_billing_email(), $name ); |
|
200 | + if (empty($user)) { |
|
201 | + $name = array($submission->get_field('wpinv_first_name', 'billing'), $submission->get_field('wpinv_last_name', 'billing')); |
|
202 | + $name = implode('', array_filter($name)); |
|
203 | + $user = wpinv_create_user($submission->get_billing_email(), $name); |
|
204 | 204 | |
205 | 205 | // (Maybe) send new user notification. |
206 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
207 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
208 | - wp_send_new_user_notifications( $user, 'user' ); |
|
206 | + $should_send_notification = wpinv_get_option('disable_new_user_emails'); |
|
207 | + if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification), $user)) { |
|
208 | + wp_send_new_user_notifications($user, 'user'); |
|
209 | 209 | } |
210 | 210 | } |
211 | 211 | |
212 | - if ( is_wp_error( $user ) ) { |
|
213 | - wp_send_json_error( $user->get_error_message() ); |
|
212 | + if (is_wp_error($user)) { |
|
213 | + wp_send_json_error($user->get_error_message()); |
|
214 | 214 | } |
215 | 215 | |
216 | - if ( is_numeric( $user ) ) { |
|
216 | + if (is_numeric($user)) { |
|
217 | 217 | return $user; |
218 | 218 | } |
219 | 219 | |
@@ -237,72 +237,72 @@ discard block |
||
237 | 237 | ); |
238 | 238 | |
239 | 239 | // Raw submission details. |
240 | - $data = $submission->get_data(); |
|
240 | + $data = $submission->get_data(); |
|
241 | 241 | |
242 | 242 | // Loop through the submitted details. |
243 | - foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
|
243 | + foreach ($submission->get_payment_form()->get_elements() as $field) { |
|
244 | 244 | |
245 | 245 | // Skip premade fields. |
246 | - if ( ! empty( $field['premade'] ) ) { |
|
246 | + if (!empty($field['premade'])) { |
|
247 | 247 | continue; |
248 | 248 | } |
249 | 249 | |
250 | 250 | // Ensure address is provided. |
251 | - if ( 'address' === $field['type'] ) { |
|
252 | - $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
|
251 | + if ('address' === $field['type']) { |
|
252 | + $address_type = isset($field['address_type']) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
|
253 | 253 | |
254 | - foreach ( $field['fields'] as $address_field ) { |
|
254 | + foreach ($field['fields'] as $address_field) { |
|
255 | 255 | |
256 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
257 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
256 | + if (!empty($address_field['visible']) && !empty($address_field['required']) && '' === trim($_POST[$address_type][$address_field['name']])) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
257 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
258 | 258 | } |
259 | 259 | } |
260 | 260 | } |
261 | 261 | |
262 | 262 | // If it is required and not set, abort. |
263 | - if ( ! $submission->is_required_field_set( $field ) ) { |
|
264 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
263 | + if (!$submission->is_required_field_set($field)) { |
|
264 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | // Handle misc fields. |
268 | - if ( isset( $data[ $field['id'] ] ) ) { |
|
268 | + if (isset($data[$field['id']])) { |
|
269 | 269 | |
270 | 270 | // Uploads. |
271 | - if ( 'file_upload' === $field['type'] ) { |
|
272 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
271 | + if ('file_upload' === $field['type']) { |
|
272 | + $max_file_num = empty($field['max_file_num']) ? 1 : absint($field['max_file_num']); |
|
273 | 273 | |
274 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
275 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
274 | + if (count($data[$field['id']]) > $max_file_num) { |
|
275 | + wp_send_json_error(__('Maximum number of allowed files exceeded.', 'invoicing')); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | $value = array(); |
279 | 279 | |
280 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
280 | + foreach ($data[$field['id']] as $url => $name) { |
|
281 | 281 | $value[] = sprintf( |
282 | 282 | '<a href="%s" target="_blank">%s</a>', |
283 | - esc_url_raw( $url ), |
|
284 | - esc_html( $name ) |
|
283 | + esc_url_raw($url), |
|
284 | + esc_html($name) |
|
285 | 285 | ); |
286 | 286 | } |
287 | 287 | |
288 | - $value = implode( ' | ', $value ); |
|
288 | + $value = implode(' | ', $value); |
|
289 | 289 | |
290 | - } elseif ( 'checkbox' === $field['type'] ) { |
|
291 | - $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
290 | + } elseif ('checkbox' === $field['type']) { |
|
291 | + $value = !empty($data[$field['id']]) ? __('Yes', 'invoicing') : __('No', 'invoicing'); |
|
292 | 292 | } else { |
293 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
293 | + $value = wp_kses_post($data[$field['id']]); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | $label = $field['id']; |
297 | 297 | |
298 | - if ( isset( $field['label'] ) ) { |
|
298 | + if (isset($field['label'])) { |
|
299 | 299 | $label = $field['label']; |
300 | 300 | } |
301 | 301 | |
302 | - if ( ! empty( $field['add_meta'] ) ) { |
|
303 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
302 | + if (!empty($field['add_meta'])) { |
|
303 | + $prepared['meta'][wpinv_clean($label)] = wp_kses_post_deep($value); |
|
304 | 304 | } |
305 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
305 | + $prepared['all'][wpinv_clean($label)] = wp_kses_post_deep($value); |
|
306 | 306 | |
307 | 307 | } |
308 | 308 | } |
@@ -318,30 +318,30 @@ discard block |
||
318 | 318 | * @param WPInv_Invoice $invoice |
319 | 319 | * @param string $type |
320 | 320 | */ |
321 | - public function prepare_address_details( $invoice, $type = 'billing' ) { |
|
321 | + public function prepare_address_details($invoice, $type = 'billing') { |
|
322 | 322 | |
323 | 323 | $data = $this->payment_form_submission->get_data(); |
324 | - $type = sanitize_key( $type ); |
|
324 | + $type = sanitize_key($type); |
|
325 | 325 | $address = array(); |
326 | 326 | $prepared = array(); |
327 | 327 | |
328 | - if ( ! empty( $data[ $type ] ) ) { |
|
329 | - $address = $data[ $type ]; |
|
328 | + if (!empty($data[$type])) { |
|
329 | + $address = $data[$type]; |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | // Clean address details. |
333 | - foreach ( $address as $key => $value ) { |
|
334 | - $key = sanitize_key( $key ); |
|
335 | - $key = str_replace( 'wpinv_', '', $key ); |
|
336 | - $value = wpinv_clean( $value ); |
|
337 | - $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
333 | + foreach ($address as $key => $value) { |
|
334 | + $key = sanitize_key($key); |
|
335 | + $key = str_replace('wpinv_', '', $key); |
|
336 | + $value = wpinv_clean($value); |
|
337 | + $prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | // Filter address details. |
341 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
341 | + $prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice); |
|
342 | 342 | |
343 | 343 | // Remove non-whitelisted values. |
344 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
344 | + return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY); |
|
345 | 345 | |
346 | 346 | } |
347 | 347 | |
@@ -351,12 +351,12 @@ discard block |
||
351 | 351 | * @return array |
352 | 352 | * @param WPInv_Invoice $invoice |
353 | 353 | */ |
354 | - protected function prepare_billing_info( &$invoice ) { |
|
354 | + protected function prepare_billing_info(&$invoice) { |
|
355 | 355 | |
356 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
356 | + $billing_address = $this->prepare_address_details($invoice, 'billing'); |
|
357 | 357 | |
358 | 358 | // Update the invoice with the billing details. |
359 | - $invoice->set_props( $billing_address ); |
|
359 | + $invoice->set_props($billing_address); |
|
360 | 360 | |
361 | 361 | } |
362 | 362 | |
@@ -366,15 +366,15 @@ discard block |
||
366 | 366 | * @return array |
367 | 367 | * @param WPInv_Invoice $invoice |
368 | 368 | */ |
369 | - protected function prepare_shipping_info( $invoice ) { |
|
369 | + protected function prepare_shipping_info($invoice) { |
|
370 | 370 | |
371 | 371 | $data = $this->payment_form_submission->get_data(); |
372 | 372 | |
373 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
374 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
373 | + if (empty($data['same-shipping-address'])) { |
|
374 | + return $this->prepare_address_details($invoice, 'shipping'); |
|
375 | 375 | } |
376 | 376 | |
377 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
377 | + return $this->prepare_address_details($invoice, 'billing'); |
|
378 | 378 | |
379 | 379 | } |
380 | 380 | |
@@ -385,45 +385,45 @@ discard block |
||
385 | 385 | * @param array $prepared_payment_form_data |
386 | 386 | * @param array $shipping |
387 | 387 | */ |
388 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
388 | + protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) { |
|
389 | 389 | |
390 | 390 | // Ensure the invoice exists. |
391 | - if ( ! $invoice->exists() ) { |
|
392 | - wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
|
391 | + if (!$invoice->exists()) { |
|
392 | + wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing')); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | // Save payment form data. |
396 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
397 | - delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
|
398 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
399 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
396 | + $prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice); |
|
397 | + delete_post_meta($invoice->get_id(), 'payment_form_data'); |
|
398 | + delete_post_meta($invoice->get_id(), 'additional_meta_data'); |
|
399 | + if (!empty($prepared_payment_form_data)) { |
|
400 | 400 | |
401 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
402 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
401 | + if (!empty($prepared_payment_form_data['all'])) { |
|
402 | + update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']); |
|
403 | 403 | } |
404 | 404 | |
405 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
406 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
405 | + if (!empty($prepared_payment_form_data['meta'])) { |
|
406 | + update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']); |
|
407 | 407 | } |
408 | 408 | } |
409 | 409 | |
410 | 410 | // Save payment form data. |
411 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
412 | - if ( ! empty( $shipping ) ) { |
|
413 | - update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
|
411 | + $shipping = apply_filters('getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission); |
|
412 | + if (!empty($shipping)) { |
|
413 | + update_post_meta($invoice->get_id(), 'shipping_address', $shipping); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | // Backwards compatibility. |
417 | - add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
|
417 | + add_filter('wp_redirect', array($this, 'send_redirect_response')); |
|
418 | 418 | |
419 | 419 | try { |
420 | - $this->process_payment( $invoice ); |
|
421 | - } catch ( Exception $e ) { |
|
422 | - wpinv_set_error( 'payment_error', $e->getMessage() ); |
|
420 | + $this->process_payment($invoice); |
|
421 | + } catch (Exception $e) { |
|
422 | + wpinv_set_error('payment_error', $e->getMessage()); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | // If we are here, there was an error. |
426 | - wpinv_send_back_to_checkout( $invoice ); |
|
426 | + wpinv_send_back_to_checkout($invoice); |
|
427 | 427 | |
428 | 428 | } |
429 | 429 | |
@@ -432,41 +432,41 @@ discard block |
||
432 | 432 | * |
433 | 433 | * @param WPInv_Invoice $invoice |
434 | 434 | */ |
435 | - protected function process_payment( $invoice ) { |
|
435 | + protected function process_payment($invoice) { |
|
436 | 436 | |
437 | 437 | // Clear any checkout errors. |
438 | 438 | wpinv_clear_errors(); |
439 | 439 | |
440 | 440 | // No need to send free invoices to the gateway. |
441 | - if ( $invoice->is_free() ) { |
|
442 | - $this->process_free_payment( $invoice ); |
|
441 | + if ($invoice->is_free()) { |
|
442 | + $this->process_free_payment($invoice); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | $submission = $this->payment_form_submission; |
446 | 446 | |
447 | 447 | // Fires before sending to the gateway. |
448 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
448 | + do_action('getpaid_checkout_before_gateway', $invoice, $submission); |
|
449 | 449 | |
450 | 450 | // Allow the sumission data to be modified before it is sent to the gateway. |
451 | 451 | $submission_data = $submission->get_data(); |
452 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
453 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
452 | + $submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice); |
|
453 | + $submission_data = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice); |
|
454 | 454 | |
455 | 455 | // Validate the currency. |
456 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
457 | - wpinv_set_error( 'invalid_currency' ); |
|
456 | + if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) { |
|
457 | + wpinv_set_error('invalid_currency'); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | // Check to see if we have any errors. |
461 | - if ( wpinv_get_errors() ) { |
|
462 | - wpinv_send_back_to_checkout( $invoice ); |
|
461 | + if (wpinv_get_errors()) { |
|
462 | + wpinv_send_back_to_checkout($invoice); |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | // Send info to the gateway for payment processing |
466 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
466 | + do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission); |
|
467 | 467 | |
468 | 468 | // Backwards compatibility. |
469 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
469 | + wpinv_send_to_gateway($submission_gateway, $invoice); |
|
470 | 470 | |
471 | 471 | } |
472 | 472 | |
@@ -475,12 +475,12 @@ discard block |
||
475 | 475 | * |
476 | 476 | * @param WPInv_Invoice $invoice |
477 | 477 | */ |
478 | - protected function process_free_payment( $invoice ) { |
|
478 | + protected function process_free_payment($invoice) { |
|
479 | 479 | |
480 | - $invoice->set_gateway( 'none' ); |
|
481 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
480 | + $invoice->set_gateway('none'); |
|
481 | + $invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true); |
|
482 | 482 | $invoice->mark_paid(); |
483 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
483 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
484 | 484 | |
485 | 485 | } |
486 | 486 | |
@@ -488,9 +488,9 @@ discard block |
||
488 | 488 | * Sends a redrect response to payment details. |
489 | 489 | * |
490 | 490 | */ |
491 | - public function send_redirect_response( $url ) { |
|
492 | - $url = rawurlencode( $url ); |
|
493 | - wp_send_json_success( $url ); |
|
491 | + public function send_redirect_response($url) { |
|
492 | + $url = rawurlencode($url); |
|
493 | + wp_send_json_success($url); |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | } |