Passed
Push — master ( cc57e9...222a59 )
by Brian
09:42
created
templates/payment-forms/elements/date.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -12,58 +12,58 @@
 block discarded – undo
12 12
 $label       = empty( $label ) ? '' : wp_kses_post( $label );
13 13
 $label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) );
14 14
 if ( ! empty( $required ) ) {
15
-	$label .= "<span class='text-danger'> *</span>";
15
+    $label .= "<span class='text-danger'> *</span>";
16 16
 }
17 17
 
18 18
 $disable_dates = array();
19 19
 
20 20
 if ( ! empty( $disabled_dates ) ) {
21
-	$disabled_dates = preg_replace( '/\s+/', '', $disabled_dates );
22
-	$disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates );
23
-	$disabled_dates = array_filter( explode( ',', $disabled_dates ) );
21
+    $disabled_dates = preg_replace( '/\s+/', '', $disabled_dates );
22
+    $disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates );
23
+    $disabled_dates = array_filter( explode( ',', $disabled_dates ) );
24 24
 
25
-	foreach ( $disabled_dates as $disabled_date ) {
25
+    foreach ( $disabled_dates as $disabled_date ) {
26 26
 
27
-		$disabled_date = trim( $disabled_date );
27
+        $disabled_date = trim( $disabled_date );
28 28
 
29
-		if ( false === strpos( $disabled_date, '|' ) ) {
30
-			$disable_dates[] = $disabled_date;
31
-			continue;
32
-		}
29
+        if ( false === strpos( $disabled_date, '|' ) ) {
30
+            $disable_dates[] = $disabled_date;
31
+            continue;
32
+        }
33 33
 
34
-		$disabled_date   = explode( '|', $disabled_date );
35
-		$disable_dates[] = array(
36
-			'from' => trim( $disabled_date[0] ),
37
-			'to'   => trim( $disabled_date[1] ),
38
-		);
34
+        $disabled_date   = explode( '|', $disabled_date );
35
+        $disable_dates[] = array(
36
+            'from' => trim( $disabled_date[0] ),
37
+            'to'   => trim( $disabled_date[1] ),
38
+        );
39 39
 
40
-	}
40
+    }
41 41
 
42 42
 }
43 43
 
44 44
 $options = array(
45
-	'data-default-date' => empty( 'default_date' ) ? false : $default_date,
46
-	'data-min-date'     => empty( 'min_date' ) ? false : $min_date,
47
-	'data-max-date'     => empty( 'max_date' ) ? false : $max_date,
48
-	'data-mode'         => empty( 'mode' ) ? 'single' : $mode,
49
-	'data-alt-format'   => get_option( 'date_format', 'F j, Y' ),
50
-	'data-date-format'  => 'Y-m-d',
51
-	'data-alt-input'    => 'true',
52
-	'data-disable_alt'  => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ),
53
-	'data-disable_days_alt'  => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ),
45
+    'data-default-date' => empty( 'default_date' ) ? false : $default_date,
46
+    'data-min-date'     => empty( 'min_date' ) ? false : $min_date,
47
+    'data-max-date'     => empty( 'max_date' ) ? false : $max_date,
48
+    'data-mode'         => empty( 'mode' ) ? 'single' : $mode,
49
+    'data-alt-format'   => get_option( 'date_format', 'F j, Y' ),
50
+    'data-date-format'  => 'Y-m-d',
51
+    'data-alt-input'    => 'true',
52
+    'data-disable_alt'  => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ),
53
+    'data-disable_days_alt'  => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ),
54 54
 );
55 55
 
56 56
 echo aui()->input(
57
-	array(
58
-		'name'             => esc_attr( $id ),
59
-		'id'               => esc_attr( $id ) . uniqid( '_' ),
60
-		'placeholder'      => empty( $placeholder ) ? '' : esc_attr( $placeholder ),
61
-		'required'         => ! empty( $required ),
62
-		'label'            => $label,
63
-		'label_type'       => 'vertical',
64
-		'help_text'        => empty( $description ) ? '' : wp_kses_post( $description ),
65
-		'type'             => 'datepicker',
66
-		'class'            => $label_class . ' getpaid-init-flatpickr flatpickr-input',
67
-		'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ),
68
-	)
57
+    array(
58
+        'name'             => esc_attr( $id ),
59
+        'id'               => esc_attr( $id ) . uniqid( '_' ),
60
+        'placeholder'      => empty( $placeholder ) ? '' : esc_attr( $placeholder ),
61
+        'required'         => ! empty( $required ),
62
+        'label'            => $label,
63
+        'label_type'       => 'vertical',
64
+        'help_text'        => empty( $description ) ? '' : wp_kses_post( $description ),
65
+        'type'             => 'datepicker',
66
+        'class'            => $label_class . ' getpaid-init-flatpickr flatpickr-input',
67
+        'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ),
68
+    )
69 69
 );
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -7,34 +7,34 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12
-$label       = empty( $label ) ? '' : wp_kses_post( $label );
13
-$label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) );
14
-if ( ! empty( $required ) ) {
12
+$label       = empty($label) ? '' : wp_kses_post($label);
13
+$label_class = sanitize_key(preg_replace('/[^A-Za-z0-9_-]/', '-', $label));
14
+if (!empty($required)) {
15 15
 	$label .= "<span class='text-danger'> *</span>";
16 16
 }
17 17
 
18 18
 $disable_dates = array();
19 19
 
20
-if ( ! empty( $disabled_dates ) ) {
21
-	$disabled_dates = preg_replace( '/\s+/', '', $disabled_dates );
22
-	$disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates );
23
-	$disabled_dates = array_filter( explode( ',', $disabled_dates ) );
20
+if (!empty($disabled_dates)) {
21
+	$disabled_dates = preg_replace('/\s+/', '', $disabled_dates);
22
+	$disabled_dates = str_ireplace('today', current_time('Y-m-d'), $disabled_dates);
23
+	$disabled_dates = array_filter(explode(',', $disabled_dates));
24 24
 
25
-	foreach ( $disabled_dates as $disabled_date ) {
25
+	foreach ($disabled_dates as $disabled_date) {
26 26
 
27
-		$disabled_date = trim( $disabled_date );
27
+		$disabled_date = trim($disabled_date);
28 28
 
29
-		if ( false === strpos( $disabled_date, '|' ) ) {
29
+		if (false === strpos($disabled_date, '|')) {
30 30
 			$disable_dates[] = $disabled_date;
31 31
 			continue;
32 32
 		}
33 33
 
34
-		$disabled_date   = explode( '|', $disabled_date );
34
+		$disabled_date   = explode('|', $disabled_date);
35 35
 		$disable_dates[] = array(
36
-			'from' => trim( $disabled_date[0] ),
37
-			'to'   => trim( $disabled_date[1] ),
36
+			'from' => trim($disabled_date[0]),
37
+			'to'   => trim($disabled_date[1]),
38 38
 		);
39 39
 
40 40
 	}
@@ -42,28 +42,28 @@  discard block
 block discarded – undo
42 42
 }
43 43
 
44 44
 $options = array(
45
-	'data-default-date' => empty( 'default_date' ) ? false : $default_date,
46
-	'data-min-date'     => empty( 'min_date' ) ? false : $min_date,
47
-	'data-max-date'     => empty( 'max_date' ) ? false : $max_date,
48
-	'data-mode'         => empty( 'mode' ) ? 'single' : $mode,
49
-	'data-alt-format'   => get_option( 'date_format', 'F j, Y' ),
45
+	'data-default-date' => empty('default_date') ? false : $default_date,
46
+	'data-min-date'     => empty('min_date') ? false : $min_date,
47
+	'data-max-date'     => empty('max_date') ? false : $max_date,
48
+	'data-mode'         => empty('mode') ? 'single' : $mode,
49
+	'data-alt-format'   => get_option('date_format', 'F j, Y'),
50 50
 	'data-date-format'  => 'Y-m-d',
51 51
 	'data-alt-input'    => 'true',
52
-	'data-disable_alt'  => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ),
53
-	'data-disable_days_alt'  => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ),
52
+	'data-disable_alt'  => empty($disabled_dates) ? false : wp_json_encode($disable_dates),
53
+	'data-disable_days_alt'  => empty($disable_days) ? false : wp_json_encode(wp_parse_id_list($disable_days)),
54 54
 );
55 55
 
56 56
 echo aui()->input(
57 57
 	array(
58
-		'name'             => esc_attr( $id ),
59
-		'id'               => esc_attr( $id ) . uniqid( '_' ),
60
-		'placeholder'      => empty( $placeholder ) ? '' : esc_attr( $placeholder ),
61
-		'required'         => ! empty( $required ),
58
+		'name'             => esc_attr($id),
59
+		'id'               => esc_attr($id) . uniqid('_'),
60
+		'placeholder'      => empty($placeholder) ? '' : esc_attr($placeholder),
61
+		'required'         => !empty($required),
62 62
 		'label'            => $label,
63 63
 		'label_type'       => 'vertical',
64
-		'help_text'        => empty( $description ) ? '' : wp_kses_post( $description ),
64
+		'help_text'        => empty($description) ? '' : wp_kses_post($description),
65 65
 		'type'             => 'datepicker',
66 66
 		'class'            => $label_class . ' getpaid-init-flatpickr flatpickr-input',
67
-		'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ),
67
+		'extra_attributes' => array_filter(apply_filters('getpaid_date_field_attributes', $options)),
68 68
 	)
69 69
 );
Please login to merge, or discard this patch.
templates/payment-forms-admin/edit/date.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -7,104 +7,104 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 ?>
13 13
 
14 14
 <div class='form-group'>
15 15
 	<label class="d-block">
16
-		<span><?php esc_html_e( 'Field Label', 'invoicing' ); ?></span>
16
+		<span><?php esc_html_e('Field Label', 'invoicing'); ?></span>
17 17
 		<input v-model='active_form_element.label' class='form-control' type="text"/>
18 18
 	</label>
19 19
 </div>
20 20
 
21 21
 <div class='form-group'>
22 22
 	<label class="d-block">
23
-		<span><?php esc_html_e( 'Default Date', 'invoicing' ); ?></span>
24
-		<?php echo wpi_help_tip( sprintf( __( 'You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing' ), current_time( 'Y-m-d' ) ), false, true ); ?>
25
-		<input v-model='active_form_element.default_date' placeholder="<?php esc_attr_e( 'None', 'invoicing' ); ?>" class='form-control' type="text"/>
23
+		<span><?php esc_html_e('Default Date', 'invoicing'); ?></span>
24
+		<?php echo wpi_help_tip(sprintf(__('You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing'), current_time('Y-m-d')), false, true); ?>
25
+		<input v-model='active_form_element.default_date' placeholder="<?php esc_attr_e('None', 'invoicing'); ?>" class='form-control' type="text"/>
26 26
 	</label>
27 27
 </div>
28 28
 
29 29
 <div class='form-group'>
30 30
 	<label class="d-block">
31
-		<span><?php esc_html_e( 'Minimum Date', 'invoicing' ); ?></span>
32
-		<?php echo wpi_help_tip( sprintf( __( 'You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing' ), current_time( 'Y-m-d' ) ), false, true ); ?>
33
-		<input v-model='active_form_element.min_date' placeholder="<?php esc_attr_e( 'None', 'invoicing' ); ?>" class='form-control' type="text"/>
34
-		<small class="form-text text-muted"><?php _e( 'Specify the minimum/earliest date (inclusively) allowed for selection.', 'invoicing' ); ?></small>
31
+		<span><?php esc_html_e('Minimum Date', 'invoicing'); ?></span>
32
+		<?php echo wpi_help_tip(sprintf(__('You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing'), current_time('Y-m-d')), false, true); ?>
33
+		<input v-model='active_form_element.min_date' placeholder="<?php esc_attr_e('None', 'invoicing'); ?>" class='form-control' type="text"/>
34
+		<small class="form-text text-muted"><?php _e('Specify the minimum/earliest date (inclusively) allowed for selection.', 'invoicing'); ?></small>
35 35
 	</label>
36 36
 </div>
37 37
 
38 38
 <div class='form-group'>
39 39
 	<label class="d-block">
40
-		<span><?php esc_html_e( 'Maximum Date', 'invoicing' ); ?></span>
41
-		<?php echo wpi_help_tip( sprintf( __( 'You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing' ), current_time( 'Y-m-d' ) ), false, true ); ?>
42
-		<input v-model='active_form_element.max_date' placeholder="<?php esc_attr_e( 'None', 'invoicing' ); ?>" class='form-control' type="text"/>
43
-		<small class="form-text text-muted"><?php _e( 'Specify the maximum/latest date (inclusively) allowed for selection.', 'invoicing' ); ?></small>
40
+		<span><?php esc_html_e('Maximum Date', 'invoicing'); ?></span>
41
+		<?php echo wpi_help_tip(sprintf(__('You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing'), current_time('Y-m-d')), false, true); ?>
42
+		<input v-model='active_form_element.max_date' placeholder="<?php esc_attr_e('None', 'invoicing'); ?>" class='form-control' type="text"/>
43
+		<small class="form-text text-muted"><?php _e('Specify the maximum/latest date (inclusively) allowed for selection.', 'invoicing'); ?></small>
44 44
 	</label>
45 45
 </div>
46 46
 
47 47
 <div class='form-group'>
48 48
 	<label class="d-block">
49
-		<span><?php esc_html_e( 'Disabled Dates', 'invoicing' ); ?></span>
50
-		<?php echo wpi_help_tip( sprintf( __( 'You can use the shortcut "today" or enter dates matching the format Y-m-d, e.g %s', 'invoicing' ), current_time( 'Y-m-d' ) ), false, true ); ?>
51
-		<input v-model='active_form_element.disabled_dates' placeholder="<?php echo esc_attr( sprintf( __( 'For example, %s', 'invoicing' ), 'today,2025-04-01|2025-05-01,2025-09-01|2025-12-01' ) ); ?>" class='form-control' type="text"/>
52
-		<small class="form-text text-muted"><?php _e( 'Specify the dates to ignore. Use commas to separate dates and "|" to separate date ranges.', 'invoicing' ); ?></small>
49
+		<span><?php esc_html_e('Disabled Dates', 'invoicing'); ?></span>
50
+		<?php echo wpi_help_tip(sprintf(__('You can use the shortcut "today" or enter dates matching the format Y-m-d, e.g %s', 'invoicing'), current_time('Y-m-d')), false, true); ?>
51
+		<input v-model='active_form_element.disabled_dates' placeholder="<?php echo esc_attr(sprintf(__('For example, %s', 'invoicing'), 'today,2025-04-01|2025-05-01,2025-09-01|2025-12-01')); ?>" class='form-control' type="text"/>
52
+		<small class="form-text text-muted"><?php _e('Specify the dates to ignore. Use commas to separate dates and "|" to separate date ranges.', 'invoicing'); ?></small>
53 53
 	</label>
54 54
 </div>
55 55
 
56 56
 <div class='form-group'>
57 57
 	<label class="d-block">
58
-		<span><?php esc_html_e( 'Disable Days', 'invoicing' ) ?></span>
58
+		<span><?php esc_html_e('Disable Days', 'invoicing') ?></span>
59 59
 		<gpselect2 class='form-control custom-select' v-model='active_form_element.disable_days' multiple>
60
-			<option value='0'><?php esc_html_e( 'Sundays', 'invoicing' ); ?></option>
61
-			<option value='1'><?php esc_html_e( 'Mondays', 'invoicing' ); ?></option>
62
-			<option value='2'><?php esc_html_e( 'Tuesdays', 'invoicing' ); ?></option>
63
-			<option value='3'><?php esc_html_e( 'Wednesdays', 'invoicing' ); ?></option>
64
-			<option value='4'><?php esc_html_e( 'Thursdays', 'invoicing' ); ?></option>
65
-			<option value='5'><?php esc_html_e( 'Fridays', 'invoicing' ); ?></option>
66
-			<option value='6'><?php esc_html_e( 'Saturdays', 'invoicing' ); ?></option>
60
+			<option value='0'><?php esc_html_e('Sundays', 'invoicing'); ?></option>
61
+			<option value='1'><?php esc_html_e('Mondays', 'invoicing'); ?></option>
62
+			<option value='2'><?php esc_html_e('Tuesdays', 'invoicing'); ?></option>
63
+			<option value='3'><?php esc_html_e('Wednesdays', 'invoicing'); ?></option>
64
+			<option value='4'><?php esc_html_e('Thursdays', 'invoicing'); ?></option>
65
+			<option value='5'><?php esc_html_e('Fridays', 'invoicing'); ?></option>
66
+			<option value='6'><?php esc_html_e('Saturdays', 'invoicing'); ?></option>
67 67
 		</gpselect2>
68
-		<small class="form-text text-muted"><?php _e( 'Optionally specify the days of the week to disable.', 'invoicing' ); ?></small>
68
+		<small class="form-text text-muted"><?php _e('Optionally specify the days of the week to disable.', 'invoicing'); ?></small>
69 69
 	</label>
70 70
 </div>
71 71
 
72 72
 <div class='form-group'>
73 73
 	<label class="d-block">
74
-		<span><?php esc_html_e( 'Mode', 'invoicing' ) ?></span>
74
+		<span><?php esc_html_e('Mode', 'invoicing') ?></span>
75 75
 		<select class='form-control custom-select' v-model='active_form_element.mode'>
76
-			<option value='single'><?php esc_html_e( 'Users can only select a single date', 'invoicing' ); ?></option>
77
-			<option value='range'><?php esc_html_e( 'Users can select a date range', 'invoicing' ); ?></option>
78
-			<option value='multiple'><?php esc_html_e( 'Users can select multiple dates', 'invoicing' ); ?></option>
76
+			<option value='single'><?php esc_html_e('Users can only select a single date', 'invoicing'); ?></option>
77
+			<option value='range'><?php esc_html_e('Users can select a date range', 'invoicing'); ?></option>
78
+			<option value='multiple'><?php esc_html_e('Users can select multiple dates', 'invoicing'); ?></option>
79 79
 		</select>
80 80
 	</label>
81 81
 </div>
82 82
 
83 83
 <div class='form-group'>
84 84
 	<label class="d-block">
85
-		<span><?php esc_html_e( 'Help Text', 'invoicing' ); ?></span>
86
-		<textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea>
87
-		<small class="form-text text-muted"><?php _e( 'HTML is allowed', 'invoicing' ); ?></small>
85
+		<span><?php esc_html_e('Help Text', 'invoicing'); ?></span>
86
+		<textarea placeholder='<?php esc_attr_e('Add some help text for this field', 'invoicing'); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea>
87
+		<small class="form-text text-muted"><?php _e('HTML is allowed', 'invoicing'); ?></small>
88 88
 	</label>
89 89
 </div>
90 90
 
91 91
 <div class='form-group form-check'>
92 92
 	<input :id="active_form_element.id + '_edit'" v-model='active_form_element.required' type='checkbox' class='form-check-input' />
93
-	<label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e( 'Is this field required?', 'invoicing' ); ?></label>
93
+	<label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e('Is this field required?', 'invoicing'); ?></label>
94 94
 </div>
95 95
 
96 96
 <div class='form-group form-check'>
97 97
 	<input :id="active_form_element.id + '_add_meta'" v-model='active_form_element.add_meta' type='checkbox' class='form-check-input' />
98
-	<label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e( 'Show this field in receipts and emails?', 'invoicing' ); ?></label>
98
+	<label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e('Show this field in receipts and emails?', 'invoicing'); ?></label>
99 99
 </div>
100 100
 
101 101
 <hr class='featurette-divider mt-4'>
102 102
 
103 103
 <div class='form-group'>
104 104
 	<label class="d-block">
105
-		<span><?php esc_html_e( 'Email Merge Tag', 'invoicing' ); ?></span>
105
+		<span><?php esc_html_e('Email Merge Tag', 'invoicing'); ?></span>
106 106
 		<input :value='active_form_element.label | formatMergeTag' class='form-control bg-white' type="text" readonly onclick="this.select()" />
107
-		<span class="form-text text-muted"><?php esc_html_e( 'You can use this merge tag in notification emails', 'invoicing' ); ?></span>
107
+		<span class="form-text text-muted"><?php esc_html_e('You can use this merge tag in notification emails', 'invoicing'); ?></span>
108 108
 	</label>
109 109
 </div>
110 110
 
Please login to merge, or discard this patch.
templates/invoice/line-totals.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -9,26 +9,26 @@  discard block
 block discarded – undo
9 9
  * @var WPInv_Invoice $invoice
10 10
  */
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 // Totals rows.
15
-$totals = getpaid_invoice_totals_rows( $invoice );
15
+$totals = getpaid_invoice_totals_rows($invoice);
16 16
 
17
-do_action( 'getpaid_before_invoice_line_totals', $invoice, $totals );
17
+do_action('getpaid_before_invoice_line_totals', $invoice, $totals);
18 18
 
19 19
 ?>
20 20
 <div class='getpaid-invoice-line-totals'>
21 21
     <div class="row">
22 22
         <div class="col-12 offset-sm-6 col-sm-6 border-sm-left pl-sm-0">
23 23
 
24
-            <?php foreach ( $totals as $key => $label ) : ?>
24
+            <?php foreach ($totals as $key => $label) : ?>
25 25
 
26
-                <div class="getpaid-invoice-line-totals-col <?php echo sanitize_html_class( $key ); ?>">
26
+                <div class="getpaid-invoice-line-totals-col <?php echo sanitize_html_class($key); ?>">
27 27
 
28 28
                     <div class="form-row">
29 29
 
30 30
                         <div class="col-8 getpaid-invoice-line-totals-label">
31
-                            <?php echo esc_html( $label ); ?>
31
+                            <?php echo esc_html($label); ?>
32 32
                         </div>
33 33
 
34 34
                         <div class="col-4 getpaid-invoice-line-totals-value pl-0">
@@ -36,15 +36,15 @@  discard block
 block discarded – undo
36 36
                             <?php
37 37
 
38 38
                                 // Total tax.
39
-                                if ( 'tax' == $key ) {
40
-                                    echo wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() );
39
+                                if ('tax' == $key) {
40
+                                    echo wpinv_price($invoice->get_total_tax(), $invoice->get_currency());
41 41
 
42
-                                    if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) {
42
+                                    if (wpinv_use_taxes() && !$invoice->get_disable_taxes()) {
43 43
 
44 44
                                         $taxes = $invoice->get_total_tax();
45
-                                        if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) {
45
+                                        if (empty($taxes) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) {
46 46
                                             echo ' <em class="text-muted small">';
47
-                                            _x( '(Reverse charged)','This is a legal term for reverse charging tax in the EU', 'invoicing' );
47
+                                            _x('(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing');
48 48
                                             echo '</em>';
49 49
                                         }
50 50
 
@@ -53,32 +53,32 @@  discard block
 block discarded – undo
53 53
                                 }
54 54
 
55 55
                                 // Total Fee.
56
-                                if ( 'fee' == $key ) {
57
-                                    echo wpinv_price( $invoice->get_total_fees(), $invoice->get_currency() );
56
+                                if ('fee' == $key) {
57
+                                    echo wpinv_price($invoice->get_total_fees(), $invoice->get_currency());
58 58
                                 }
59 59
 
60 60
                                 // Total discount.
61
-                                if ( 'discount' == $key ) {
62
-                                    echo wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() );
61
+                                if ('discount' == $key) {
62
+                                    echo wpinv_price($invoice->get_total_discount(), $invoice->get_currency());
63 63
                                 }
64 64
 
65 65
                                 // Shipping.
66
-                                if ( 'shipping' == $key ) {
67
-                                    echo wpinv_price( $invoice->get_shipping(), $invoice->get_currency() );
66
+                                if ('shipping' == $key) {
67
+                                    echo wpinv_price($invoice->get_shipping(), $invoice->get_currency());
68 68
                                 }
69 69
 
70 70
                                 // Sub total.
71
-                                if ( 'subtotal' == $key ) {
72
-                                    echo wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() );
71
+                                if ('subtotal' == $key) {
72
+                                    echo wpinv_price($invoice->get_subtotal(), $invoice->get_currency());
73 73
                                 }
74 74
 
75 75
                                 // Total.
76
-                                if ( 'total' == $key ) {
77
-                                    echo wpinv_price( $invoice->get_total(), $invoice->get_currency() );
76
+                                if ('total' == $key) {
77
+                                    echo wpinv_price($invoice->get_total(), $invoice->get_currency());
78 78
                                 }
79 79
  
80 80
                                 // Fires when printing a cart total.
81
-                                do_action( "getpaid_invoice_cart_totals_$key", $invoice );
81
+                                do_action("getpaid_invoice_cart_totals_$key", $invoice);
82 82
 
83 83
                             ?>
84 84
 
@@ -92,4 +92,4 @@  discard block
 block discarded – undo
92 92
     </div>
93 93
 </div> <!-- end .getpaid-invoice-line-totals -->
94 94
 
95
-<?php do_action(  'getpaid_after_invoice_line_totals', $invoice, $totals ); ?>
95
+<?php do_action('getpaid_after_invoice_line_totals', $invoice, $totals); ?>
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 2 patches
Indentation   +862 added lines, -862 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,203 +10,203 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form_Submission {
11 11
 
12 12
     /**
13
-	 * Submission ID
14
-	 *
15
-	 * @var string
16
-	 */
17
-	public $id = null;
18
-
19
-	/**
20
-	 * The raw submission data.
21
-	 *
22
-	 * @var array
23
-	 */
24
-	protected $data = null;
25
-
26
-	/**
27
-	 * Submission totals
28
-	 *
29
-	 * @var array
30
-	 */
31
-	protected $totals = array(
32
-
33
-		'subtotal'      => array(
34
-			'initial'   => 0,
35
-			'recurring' => 0,
36
-		),
37
-
38
-		'discount'      => array(
39
-			'initial'   => 0,
40
-			'recurring' => 0,
41
-		),
42
-
43
-		'fees'          => array(
44
-			'initial'   => 0,
45
-			'recurring' => 0,
46
-		),
47
-
48
-		'taxes'         => array(
49
-			'initial'   => 0,
50
-			'recurring' => 0,
51
-		),
52
-
53
-		'shipping'         => array(
54
-			'initial'   => 0,
55
-			'recurring' => 0,
56
-		),
57
-
58
-	);
59
-
60
-	/**
61
-	 * Sets the associated payment form.
62
-	 *
63
-	 * @var GetPaid_Payment_Form
64
-	 */
13
+     * Submission ID
14
+     *
15
+     * @var string
16
+     */
17
+    public $id = null;
18
+
19
+    /**
20
+     * The raw submission data.
21
+     *
22
+     * @var array
23
+     */
24
+    protected $data = null;
25
+
26
+    /**
27
+     * Submission totals
28
+     *
29
+     * @var array
30
+     */
31
+    protected $totals = array(
32
+
33
+        'subtotal'      => array(
34
+            'initial'   => 0,
35
+            'recurring' => 0,
36
+        ),
37
+
38
+        'discount'      => array(
39
+            'initial'   => 0,
40
+            'recurring' => 0,
41
+        ),
42
+
43
+        'fees'          => array(
44
+            'initial'   => 0,
45
+            'recurring' => 0,
46
+        ),
47
+
48
+        'taxes'         => array(
49
+            'initial'   => 0,
50
+            'recurring' => 0,
51
+        ),
52
+
53
+        'shipping'         => array(
54
+            'initial'   => 0,
55
+            'recurring' => 0,
56
+        ),
57
+
58
+    );
59
+
60
+    /**
61
+     * Sets the associated payment form.
62
+     *
63
+     * @var GetPaid_Payment_Form
64
+     */
65 65
     protected $payment_form = null;
66 66
 
67 67
     /**
68
-	 * The country for the submission.
69
-	 *
70
-	 * @var string
71
-	 */
72
-	public $country = null;
73
-
74
-    /**
75
-	 * The state for the submission.
76
-	 *
77
-	 * @since 1.0.19
78
-	 * @var string
79
-	 */
80
-	public $state = null;
81
-
82
-	/**
83
-	 * The invoice associated with the submission.
84
-	 *
85
-	 * @var WPInv_Invoice
86
-	 */
87
-	protected $invoice = null;
88
-
89
-	/**
90
-	 * The recurring item for the submission.
91
-	 *
92
-	 * @var int
93
-	 */
94
-	public $has_recurring = 0;
95
-
96
-	/**
97
-	 * An array of fees for the submission.
98
-	 *
99
-	 * @var array
100
-	 */
101
-	protected $fees = array();
102
-
103
-	/**
104
-	 * An array of discounts for the submission.
105
-	 *
106
-	 * @var array
107
-	 */
108
-	protected $discounts = array();
109
-
110
-	/**
111
-	 * An array of taxes for the submission.
112
-	 *
113
-	 * @var array
114
-	 */
115
-	protected $taxes = array();
116
-
117
-	/**
118
-	 * An array of items for the submission.
119
-	 *
120
-	 * @var GetPaid_Form_Item[]
121
-	 */
122
-	protected $items = array();
123
-
124
-	/**
125
-	 * The last error.
126
-	 *
127
-	 * @var string
128
-	 */
129
-	public $last_error = null;
130
-
131
-	/**
132
-	 * The last error code.
133
-	 *
134
-	 * @var string
135
-	 */
136
-	public $last_error_code = null;
137
-
138
-    /**
139
-	 * Class constructor.
140
-	 *
141
-	 */
142
-	public function __construct() {
143
-
144
-		// Set the state and country to the default state and country.
145
-		$this->country = wpinv_default_billing_country();
146
-		$this->state   = wpinv_get_default_state();
147
-
148
-		// Do we have an actual submission?
149
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
150
-			$this->load_data( $_POST );
151
-		}
152
-
153
-	}
154
-
155
-	/**
156
-	 * Loads submission data.
157
-	 *
158
-	 * @param array $data
159
-	 */
160
-	public function load_data( $data ) {
161
-
162
-		// Remove slashes from the submitted data...
163
-		$data       = wp_kses_post_deep( wp_unslash( $data ) );
164
-
165
-		// Allow plugins to filter the data.
166
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
167
-
168
-		// Cache it...
169
-		$this->data = $data;
170
-
171
-		// Then generate a unique id from the data.
172
-		$this->id   = md5( wp_json_encode( $data ) );
173
-
174
-		// Finally, process the submission.
175
-		try {
176
-
177
-			// Each process is passed an instance of the class (with reference)
178
-			// and should throw an Exception whenever it encounters one.
179
-			$processors = apply_filters(
180
-				'getpaid_payment_form_submission_processors',
181
-				array(
182
-					array( $this, 'process_payment_form' ),
183
-					array( $this, 'process_invoice' ),
184
-					array( $this, 'process_fees' ),
185
-					array( $this, 'process_items' ),
186
-					array( $this, 'process_discount' ),
187
-					array( $this, 'process_taxes' ),
188
-				),
189
-				$this		
190
-			);
191
-
192
-			foreach ( $processors as $processor ) {
193
-				call_user_func_array( $processor, array( &$this ) );
194
-			}
195
-
196
-		} catch( GetPaid_Payment_Exception $e ) {
197
-			$this->last_error      = $e->getMessage();
198
-			$this->last_error_code = $e->getErrorCode();
199
-		} catch ( Exception $e ) {
200
-			$this->last_error      = $e->getMessage();
201
-			$this->last_error_code = $e->getCode();
202
-		}
203
-
204
-		// Fired when we are done processing a submission.
205
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
206
-
207
-	}
208
-
209
-	/*
68
+     * The country for the submission.
69
+     *
70
+     * @var string
71
+     */
72
+    public $country = null;
73
+
74
+    /**
75
+     * The state for the submission.
76
+     *
77
+     * @since 1.0.19
78
+     * @var string
79
+     */
80
+    public $state = null;
81
+
82
+    /**
83
+     * The invoice associated with the submission.
84
+     *
85
+     * @var WPInv_Invoice
86
+     */
87
+    protected $invoice = null;
88
+
89
+    /**
90
+     * The recurring item for the submission.
91
+     *
92
+     * @var int
93
+     */
94
+    public $has_recurring = 0;
95
+
96
+    /**
97
+     * An array of fees for the submission.
98
+     *
99
+     * @var array
100
+     */
101
+    protected $fees = array();
102
+
103
+    /**
104
+     * An array of discounts for the submission.
105
+     *
106
+     * @var array
107
+     */
108
+    protected $discounts = array();
109
+
110
+    /**
111
+     * An array of taxes for the submission.
112
+     *
113
+     * @var array
114
+     */
115
+    protected $taxes = array();
116
+
117
+    /**
118
+     * An array of items for the submission.
119
+     *
120
+     * @var GetPaid_Form_Item[]
121
+     */
122
+    protected $items = array();
123
+
124
+    /**
125
+     * The last error.
126
+     *
127
+     * @var string
128
+     */
129
+    public $last_error = null;
130
+
131
+    /**
132
+     * The last error code.
133
+     *
134
+     * @var string
135
+     */
136
+    public $last_error_code = null;
137
+
138
+    /**
139
+     * Class constructor.
140
+     *
141
+     */
142
+    public function __construct() {
143
+
144
+        // Set the state and country to the default state and country.
145
+        $this->country = wpinv_default_billing_country();
146
+        $this->state   = wpinv_get_default_state();
147
+
148
+        // Do we have an actual submission?
149
+        if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
150
+            $this->load_data( $_POST );
151
+        }
152
+
153
+    }
154
+
155
+    /**
156
+     * Loads submission data.
157
+     *
158
+     * @param array $data
159
+     */
160
+    public function load_data( $data ) {
161
+
162
+        // Remove slashes from the submitted data...
163
+        $data       = wp_kses_post_deep( wp_unslash( $data ) );
164
+
165
+        // Allow plugins to filter the data.
166
+        $data       = apply_filters( 'getpaid_submission_data', $data, $this );
167
+
168
+        // Cache it...
169
+        $this->data = $data;
170
+
171
+        // Then generate a unique id from the data.
172
+        $this->id   = md5( wp_json_encode( $data ) );
173
+
174
+        // Finally, process the submission.
175
+        try {
176
+
177
+            // Each process is passed an instance of the class (with reference)
178
+            // and should throw an Exception whenever it encounters one.
179
+            $processors = apply_filters(
180
+                'getpaid_payment_form_submission_processors',
181
+                array(
182
+                    array( $this, 'process_payment_form' ),
183
+                    array( $this, 'process_invoice' ),
184
+                    array( $this, 'process_fees' ),
185
+                    array( $this, 'process_items' ),
186
+                    array( $this, 'process_discount' ),
187
+                    array( $this, 'process_taxes' ),
188
+                ),
189
+                $this		
190
+            );
191
+
192
+            foreach ( $processors as $processor ) {
193
+                call_user_func_array( $processor, array( &$this ) );
194
+            }
195
+
196
+        } catch( GetPaid_Payment_Exception $e ) {
197
+            $this->last_error      = $e->getMessage();
198
+            $this->last_error_code = $e->getErrorCode();
199
+        } catch ( Exception $e ) {
200
+            $this->last_error      = $e->getMessage();
201
+            $this->last_error_code = $e->getCode();
202
+        }
203
+
204
+        // Fired when we are done processing a submission.
205
+        do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
206
+
207
+    }
208
+
209
+    /*
210 210
 	|--------------------------------------------------------------------------
211 211
 	| Payment Forms.
212 212
 	|--------------------------------------------------------------------------
@@ -215,39 +215,39 @@  discard block
 block discarded – undo
215 215
 	| submission has an active payment form etc.
216 216
     */
217 217
 
218
-	/**
219
-	 * Prepares the submission's payment form.
220
-	 *
221
-	 * @since 1.0.19
222
-	 */
223
-	public function process_payment_form() {
218
+    /**
219
+     * Prepares the submission's payment form.
220
+     *
221
+     * @since 1.0.19
222
+     */
223
+    public function process_payment_form() {
224 224
 
225
-		// Every submission needs an active payment form.
226
-		if ( empty( $this->data['form_id'] ) ) {
227
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
228
-		}
225
+        // Every submission needs an active payment form.
226
+        if ( empty( $this->data['form_id'] ) ) {
227
+            throw new Exception( __( 'Missing payment form', 'invoicing' ) );
228
+        }
229 229
 
230
-		// Fetch the payment form.
231
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
230
+        // Fetch the payment form.
231
+        $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
232 232
 
233
-		if ( ! $this->payment_form->is_active() ) {
234
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
235
-		}
233
+        if ( ! $this->payment_form->is_active() ) {
234
+            throw new Exception( __( 'Payment form not active', 'invoicing' ) );
235
+        }
236 236
 
237
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
238
-	}
237
+        do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
238
+    }
239 239
 
240 240
     /**
241
-	 * Returns the payment form.
242
-	 *
243
-	 * @since 1.0.19
244
-	 * @return GetPaid_Payment_Form
245
-	 */
246
-	public function get_payment_form() {
247
-		return $this->payment_form;
248
-	}
241
+     * Returns the payment form.
242
+     *
243
+     * @since 1.0.19
244
+     * @return GetPaid_Payment_Form
245
+     */
246
+    public function get_payment_form() {
247
+        return $this->payment_form;
248
+    }
249 249
 
250
-	/*
250
+    /*
251 251
 	|--------------------------------------------------------------------------
252 252
 	| Invoices.
253 253
 	|--------------------------------------------------------------------------
@@ -256,84 +256,84 @@  discard block
 block discarded – undo
256 256
 	| might be for an existing invoice.
257 257
 	*/
258 258
 
259
-	/**
260
-	 * Prepares the submission's invoice.
261
-	 *
262
-	 * @since 1.0.19
263
-	 */
264
-	public function process_invoice() {
259
+    /**
260
+     * Prepares the submission's invoice.
261
+     *
262
+     * @since 1.0.19
263
+     */
264
+    public function process_invoice() {
265 265
 
266
-		// Abort if there is no invoice.
267
-		if ( empty( $this->data['invoice_id'] ) ) {
268
-			return;
269
-		}
266
+        // Abort if there is no invoice.
267
+        if ( empty( $this->data['invoice_id'] ) ) {
268
+            return;
269
+        }
270 270
 
271
-		// If the submission is for an existing invoice, ensure that it exists
272
-		// and that it is not paid for.
273
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
271
+        // If the submission is for an existing invoice, ensure that it exists
272
+        // and that it is not paid for.
273
+        $invoice = wpinv_get_invoice( $this->data['invoice_id'] );
274 274
 
275 275
         if ( empty( $invoice ) ) {
276
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
277
-		}
276
+            throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
277
+        }
278 278
 
279
-		if ( $invoice->is_paid() ) {
280
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
281
-		}
279
+        if ( $invoice->is_paid() ) {
280
+            throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
281
+        }
282 282
 
283
-		$this->payment_form->invoice = $invoice;
284
-		if ( ! $this->payment_form->is_default() ) {
283
+        $this->payment_form->invoice = $invoice;
284
+        if ( ! $this->payment_form->is_default() ) {
285 285
 
286
-			$items    = array();
287
-			$item_ids = array();
286
+            $items    = array();
287
+            $item_ids = array();
288 288
 	
289
-			foreach ( $invoice->get_items() as $item ) {
290
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
291
-					$item_ids[] = $item->get_id();
292
-					$items[]    = $item;
293
-				}
294
-			}
289
+            foreach ( $invoice->get_items() as $item ) {
290
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
291
+                    $item_ids[] = $item->get_id();
292
+                    $items[]    = $item;
293
+                }
294
+            }
295 295
 	
296
-			foreach ( $this->payment_form->get_items() as $item ) {
297
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
298
-					$item_ids[] = $item->get_id();
299
-					$items[]    = $item;
300
-				}
301
-			}
296
+            foreach ( $this->payment_form->get_items() as $item ) {
297
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
298
+                    $item_ids[] = $item->get_id();
299
+                    $items[]    = $item;
300
+                }
301
+            }
302 302
 	
303
-			$this->payment_form->set_items( $items );
303
+            $this->payment_form->set_items( $items );
304 304
 	
305
-		} else {
306
-			$this->payment_form->set_items( $invoice->get_items() );
307
-		}
308
-
309
-		$this->country = $invoice->get_country();
310
-		$this->state   = $invoice->get_state();
311
-		$this->invoice = $invoice;
312
-
313
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
314
-	}
315
-
316
-	/**
317
-	 * Returns the associated invoice.
318
-	 *
319
-	 * @since 1.0.19
320
-	 * @return WPInv_Invoice
321
-	 */
322
-	public function get_invoice() {
323
-		return $this->invoice;
324
-	}
325
-
326
-	/**
327
-	 * Checks whether there is an invoice associated with this submission.
328
-	 *
329
-	 * @since 1.0.19
330
-	 * @return bool
331
-	 */
332
-	public function has_invoice() {
333
-		return ! empty( $this->invoice );
334
-	}
335
-
336
-	/*
305
+        } else {
306
+            $this->payment_form->set_items( $invoice->get_items() );
307
+        }
308
+
309
+        $this->country = $invoice->get_country();
310
+        $this->state   = $invoice->get_state();
311
+        $this->invoice = $invoice;
312
+
313
+        do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
314
+    }
315
+
316
+    /**
317
+     * Returns the associated invoice.
318
+     *
319
+     * @since 1.0.19
320
+     * @return WPInv_Invoice
321
+     */
322
+    public function get_invoice() {
323
+        return $this->invoice;
324
+    }
325
+
326
+    /**
327
+     * Checks whether there is an invoice associated with this submission.
328
+     *
329
+     * @since 1.0.19
330
+     * @return bool
331
+     */
332
+    public function has_invoice() {
333
+        return ! empty( $this->invoice );
334
+    }
335
+
336
+    /*
337 337
 	|--------------------------------------------------------------------------
338 338
 	| Items.
339 339
 	|--------------------------------------------------------------------------
@@ -342,129 +342,129 @@  discard block
 block discarded – undo
342 342
 	| recurring item. But can have an unlimited number of non-recurring items.
343 343
 	*/
344 344
 
345
-	/**
346
-	 * Prepares the submission's items.
347
-	 *
348
-	 * @since 1.0.19
349
-	 */
350
-	public function process_items() {
351
-
352
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
353
-
354
-		foreach ( $processor->items as $item ) {
355
-			$this->add_item( $item );
356
-		}
357
-
358
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
359
-	}
360
-
361
-	/**
362
-	 * Adds an item to the submission.
363
-	 *
364
-	 * @since 1.0.19
365
-	 * @param GetPaid_Form_Item $item
366
-	 */
367
-	public function add_item( $item ) {
368
-
369
-		// Make sure that it is available for purchase.
370
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
371
-			return;
372
-		}
373
-
374
-		// Each submission can only contain one recurring item.
375
-		if ( $item->is_recurring() ) {
376
-			$this->has_recurring = $item->get_id();
377
-		}
378
-
379
-		// Update the items and totals.
380
-		$this->items[ $item->get_id() ]         = $item;
381
-		$this->totals['subtotal']['initial']   += $item->get_sub_total();
382
-		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
383
-
384
-	}
385
-
386
-	/**
387
-	 * Removes a specific item.
388
-	 * 
389
-	 * You should not call this method after the discounts and taxes
390
-	 * have been calculated.
391
-	 *
392
-	 * @since 1.0.19
393
-	 */
394
-	public function remove_item( $item_id ) {
395
-
396
-		if ( isset( $this->items[ $item_id ] ) ) {
397
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
398
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
399
-
400
-			if ( $this->items[ $item_id ]->is_recurring() ) {
401
-				$this->has_recurring = 0;
402
-			}
403
-
404
-			unset( $this->items[ $item_id ] );
405
-		}
406
-
407
-	}
408
-
409
-	/**
410
-	 * Returns the subtotal.
411
-	 *
412
-	 * @since 1.0.19
413
-	 */
414
-	public function get_subtotal() {
415
-
416
-		if ( wpinv_prices_include_tax() ) {
417
-			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
418
-		}
419
-
420
-		return $this->totals['subtotal']['initial'];
421
-	}
422
-
423
-	/**
424
-	 * Returns the recurring subtotal.
425
-	 *
426
-	 * @since 1.0.19
427
-	 */
428
-	public function get_recurring_subtotal() {
429
-
430
-		if ( wpinv_prices_include_tax() ) {
431
-			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
432
-		}
433
-
434
-		return $this->totals['subtotal']['recurring'];
435
-	}
436
-
437
-	/**
438
-	 * Returns all items.
439
-	 *
440
-	 * @since 1.0.19
441
-	 * @return GetPaid_Form_Item[]
442
-	 */
443
-	public function get_items() {
444
-		return $this->items;
445
-	}
446
-
447
-	/**
448
-	 * Checks if there's a single subscription group in the submission.
449
-	 *
450
-	 * @since 2.3.0
451
-	 * @return bool
452
-	 */
453
-	public function has_subscription_group() {
454
-		return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
455
-	}
456
-
457
-	/**
458
-	 * Checks if there are multipe subscription groups in the submission.
459
-	 *
460
-	 * @since 2.3.0
461
-	 * @return bool
462
-	 */
463
-	public function has_multiple_subscription_groups() {
464
-		return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
465
-	}
466
-
467
-	/*
345
+    /**
346
+     * Prepares the submission's items.
347
+     *
348
+     * @since 1.0.19
349
+     */
350
+    public function process_items() {
351
+
352
+        $processor = new GetPaid_Payment_Form_Submission_Items( $this );
353
+
354
+        foreach ( $processor->items as $item ) {
355
+            $this->add_item( $item );
356
+        }
357
+
358
+        do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
359
+    }
360
+
361
+    /**
362
+     * Adds an item to the submission.
363
+     *
364
+     * @since 1.0.19
365
+     * @param GetPaid_Form_Item $item
366
+     */
367
+    public function add_item( $item ) {
368
+
369
+        // Make sure that it is available for purchase.
370
+        if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
371
+            return;
372
+        }
373
+
374
+        // Each submission can only contain one recurring item.
375
+        if ( $item->is_recurring() ) {
376
+            $this->has_recurring = $item->get_id();
377
+        }
378
+
379
+        // Update the items and totals.
380
+        $this->items[ $item->get_id() ]         = $item;
381
+        $this->totals['subtotal']['initial']   += $item->get_sub_total();
382
+        $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
383
+
384
+    }
385
+
386
+    /**
387
+     * Removes a specific item.
388
+     * 
389
+     * You should not call this method after the discounts and taxes
390
+     * have been calculated.
391
+     *
392
+     * @since 1.0.19
393
+     */
394
+    public function remove_item( $item_id ) {
395
+
396
+        if ( isset( $this->items[ $item_id ] ) ) {
397
+            $this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
398
+            $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
399
+
400
+            if ( $this->items[ $item_id ]->is_recurring() ) {
401
+                $this->has_recurring = 0;
402
+            }
403
+
404
+            unset( $this->items[ $item_id ] );
405
+        }
406
+
407
+    }
408
+
409
+    /**
410
+     * Returns the subtotal.
411
+     *
412
+     * @since 1.0.19
413
+     */
414
+    public function get_subtotal() {
415
+
416
+        if ( wpinv_prices_include_tax() ) {
417
+            return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
418
+        }
419
+
420
+        return $this->totals['subtotal']['initial'];
421
+    }
422
+
423
+    /**
424
+     * Returns the recurring subtotal.
425
+     *
426
+     * @since 1.0.19
427
+     */
428
+    public function get_recurring_subtotal() {
429
+
430
+        if ( wpinv_prices_include_tax() ) {
431
+            return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
432
+        }
433
+
434
+        return $this->totals['subtotal']['recurring'];
435
+    }
436
+
437
+    /**
438
+     * Returns all items.
439
+     *
440
+     * @since 1.0.19
441
+     * @return GetPaid_Form_Item[]
442
+     */
443
+    public function get_items() {
444
+        return $this->items;
445
+    }
446
+
447
+    /**
448
+     * Checks if there's a single subscription group in the submission.
449
+     *
450
+     * @since 2.3.0
451
+     * @return bool
452
+     */
453
+    public function has_subscription_group() {
454
+        return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
455
+    }
456
+
457
+    /**
458
+     * Checks if there are multipe subscription groups in the submission.
459
+     *
460
+     * @since 2.3.0
461
+     * @return bool
462
+     */
463
+    public function has_multiple_subscription_groups() {
464
+        return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
465
+    }
466
+
467
+    /*
468 468
 	|--------------------------------------------------------------------------
469 469
 	| Taxes
470 470
 	|--------------------------------------------------------------------------
@@ -473,128 +473,128 @@  discard block
 block discarded – undo
473 473
 	| or only one-time.
474 474
     */
475 475
 
476
-	/**
477
-	 * Prepares the submission's taxes.
478
-	 *
479
-	 * @since 1.0.19
480
-	 */
481
-	public function process_taxes() {
482
-
483
-		// Abort if we're not using taxes.
484
-		if ( ! $this->use_taxes() ) {
485
-			return;
486
-		}
487
-
488
-		// If a custom country && state has been passed in, use it to calculate taxes.
489
-		$country = $this->get_field( 'wpinv_country', 'billing' );
490
-		if ( ! empty( $country ) ) {
491
-			$this->country = $country;
492
-		}
493
-
494
-		$state = $this->get_field( 'wpinv_state', 'billing' );
495
-		if ( ! empty( $state ) ) {
496
-			$this->state = $state;
497
-		}
498
-
499
-		// Confirm if the provided country and the ip country are similar.
500
-		$address_confirmed = $this->get_field( 'confirm-address' );
501
-		if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
502
-			throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
503
-		}
504
-
505
-		// Abort if the country is not taxable.
506
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
507
-			return;
508
-		}
509
-
510
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
511
-
512
-		foreach ( $processor->taxes as $tax ) {
513
-			$this->add_tax( $tax );
514
-		}
515
-
516
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
517
-	}
518
-
519
-	/**
520
-	 * Adds a tax to the submission.
521
-	 *
522
-	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
523
-	 * @since 1.0.19
524
-	 */
525
-	public function add_tax( $tax ) {
526
-
527
-		if ( wpinv_round_tax_per_tax_rate() ) {
528
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
529
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
530
-		}
531
-
532
-		$this->taxes[ $tax['name'] ]         = $tax;
533
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
534
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
535
-
536
-	}
537
-
538
-	/**
539
-	 * Removes a specific tax.
540
-	 *
541
-	 * @since 1.0.19
542
-	 */
543
-	public function remove_tax( $tax_name ) {
544
-
545
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
546
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
547
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
548
-			unset( $this->taxes[ $tax_name ] );
549
-		}
550
-
551
-	}
552
-
553
-	/**
554
-	 * Whether or not we'll use taxes for the submission.
555
-	 *
556
-	 * @since 1.0.19
557
-	 */
558
-	public function use_taxes() {
559
-
560
-		$use_taxes = wpinv_use_taxes();
561
-
562
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
563
-			$use_taxes = false;
564
-		}
565
-
566
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
567
-
568
-	}
569
-
570
-	/**
571
-	 * Returns the tax.
572
-	 *
573
-	 * @since 1.0.19
574
-	 */
575
-	public function get_tax() {
576
-		return $this->totals['taxes']['initial'];
577
-	}
578
-
579
-	/**
580
-	 * Returns the recurring tax.
581
-	 *
582
-	 * @since 1.0.19
583
-	 */
584
-	public function get_recurring_tax() {
585
-		return $this->totals['taxes']['recurring'];
586
-	}
587
-
588
-	/**
589
-	 * Returns all taxes.
590
-	 *
591
-	 * @since 1.0.19
592
-	 */
593
-	public function get_taxes() {
594
-		return $this->taxes;
595
-	}
596
-
597
-	/*
476
+    /**
477
+     * Prepares the submission's taxes.
478
+     *
479
+     * @since 1.0.19
480
+     */
481
+    public function process_taxes() {
482
+
483
+        // Abort if we're not using taxes.
484
+        if ( ! $this->use_taxes() ) {
485
+            return;
486
+        }
487
+
488
+        // If a custom country && state has been passed in, use it to calculate taxes.
489
+        $country = $this->get_field( 'wpinv_country', 'billing' );
490
+        if ( ! empty( $country ) ) {
491
+            $this->country = $country;
492
+        }
493
+
494
+        $state = $this->get_field( 'wpinv_state', 'billing' );
495
+        if ( ! empty( $state ) ) {
496
+            $this->state = $state;
497
+        }
498
+
499
+        // Confirm if the provided country and the ip country are similar.
500
+        $address_confirmed = $this->get_field( 'confirm-address' );
501
+        if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
502
+            throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
503
+        }
504
+
505
+        // Abort if the country is not taxable.
506
+        if ( ! wpinv_is_country_taxable( $this->country ) ) {
507
+            return;
508
+        }
509
+
510
+        $processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
511
+
512
+        foreach ( $processor->taxes as $tax ) {
513
+            $this->add_tax( $tax );
514
+        }
515
+
516
+        do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
517
+    }
518
+
519
+    /**
520
+     * Adds a tax to the submission.
521
+     *
522
+     * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
523
+     * @since 1.0.19
524
+     */
525
+    public function add_tax( $tax ) {
526
+
527
+        if ( wpinv_round_tax_per_tax_rate() ) {
528
+            $tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
529
+            $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
530
+        }
531
+
532
+        $this->taxes[ $tax['name'] ]         = $tax;
533
+        $this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
534
+        $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
535
+
536
+    }
537
+
538
+    /**
539
+     * Removes a specific tax.
540
+     *
541
+     * @since 1.0.19
542
+     */
543
+    public function remove_tax( $tax_name ) {
544
+
545
+        if ( isset( $this->taxes[ $tax_name ] ) ) {
546
+            $this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
547
+            $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
548
+            unset( $this->taxes[ $tax_name ] );
549
+        }
550
+
551
+    }
552
+
553
+    /**
554
+     * Whether or not we'll use taxes for the submission.
555
+     *
556
+     * @since 1.0.19
557
+     */
558
+    public function use_taxes() {
559
+
560
+        $use_taxes = wpinv_use_taxes();
561
+
562
+        if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
563
+            $use_taxes = false;
564
+        }
565
+
566
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
567
+
568
+    }
569
+
570
+    /**
571
+     * Returns the tax.
572
+     *
573
+     * @since 1.0.19
574
+     */
575
+    public function get_tax() {
576
+        return $this->totals['taxes']['initial'];
577
+    }
578
+
579
+    /**
580
+     * Returns the recurring tax.
581
+     *
582
+     * @since 1.0.19
583
+     */
584
+    public function get_recurring_tax() {
585
+        return $this->totals['taxes']['recurring'];
586
+    }
587
+
588
+    /**
589
+     * Returns all taxes.
590
+     *
591
+     * @since 1.0.19
592
+     */
593
+    public function get_taxes() {
594
+        return $this->taxes;
595
+    }
596
+
597
+    /*
598 598
 	|--------------------------------------------------------------------------
599 599
 	| Discounts
600 600
 	|--------------------------------------------------------------------------
@@ -603,99 +603,99 @@  discard block
 block discarded – undo
603 603
 	| or only one-time. They also do not have to come from a discount code.
604 604
     */
605 605
 
606
-	/**
607
-	 * Prepares the submission's discount.
608
-	 *
609
-	 * @since 1.0.19
610
-	 */
611
-	public function process_discount() {
612
-
613
-		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
614
-		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
615
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
616
-
617
-		foreach ( $processor->discounts as $discount ) {
618
-			$this->add_discount( $discount );
619
-		}
620
-
621
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
622
-	}
623
-
624
-	/**
625
-	 * Adds a discount to the submission.
626
-	 *
627
-	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
628
-	 * @since 1.0.19
629
-	 */
630
-	public function add_discount( $discount ) {
631
-		$this->discounts[ $discount['name'] ]   = $discount;
632
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
633
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
634
-	}
635
-
636
-	/**
637
-	 * Removes a discount from the submission.
638
-	 *
639
-	 * @since 1.0.19
640
-	 */
641
-	public function remove_discount( $name ) {
642
-
643
-		if ( isset( $this->discounts[ $name ] ) ) {
644
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
645
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
646
-			unset( $this->discounts[ $name ] );
647
-		}
648
-
649
-	}
650
-
651
-	/**
652
-	 * Checks whether there is a discount code associated with this submission.
653
-	 *
654
-	 * @since 1.0.19
655
-	 * @return bool
656
-	 */
657
-	public function has_discount_code() {
658
-		return ! empty( $this->discounts['discount_code'] );
659
-	}
660
-
661
-	/**
662
-	 * Returns the discount code.
663
-	 *
664
-	 * @since 1.0.19
665
-	 * @return string
666
-	 */
667
-	public function get_discount_code() {
668
-		return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
669
-	}
670
-
671
-	/**
672
-	 * Returns the discount.
673
-	 *
674
-	 * @since 1.0.19
675
-	 */
676
-	public function get_discount() {
677
-		return $this->totals['discount']['initial'];
678
-	}
679
-
680
-	/**
681
-	 * Returns the recurring discount.
682
-	 *
683
-	 * @since 1.0.19
684
-	 */
685
-	public function get_recurring_discount() {
686
-		return $this->totals['discount']['recurring'];
687
-	}
688
-
689
-	/**
690
-	 * Returns all discounts.
691
-	 *
692
-	 * @since 1.0.19
693
-	 */
694
-	public function get_discounts() {
695
-		return $this->discounts;
696
-	}
697
-
698
-	/*
606
+    /**
607
+     * Prepares the submission's discount.
608
+     *
609
+     * @since 1.0.19
610
+     */
611
+    public function process_discount() {
612
+
613
+        $initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
614
+        $recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
615
+        $processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
616
+
617
+        foreach ( $processor->discounts as $discount ) {
618
+            $this->add_discount( $discount );
619
+        }
620
+
621
+        do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
622
+    }
623
+
624
+    /**
625
+     * Adds a discount to the submission.
626
+     *
627
+     * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
628
+     * @since 1.0.19
629
+     */
630
+    public function add_discount( $discount ) {
631
+        $this->discounts[ $discount['name'] ]   = $discount;
632
+        $this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
633
+        $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
634
+    }
635
+
636
+    /**
637
+     * Removes a discount from the submission.
638
+     *
639
+     * @since 1.0.19
640
+     */
641
+    public function remove_discount( $name ) {
642
+
643
+        if ( isset( $this->discounts[ $name ] ) ) {
644
+            $this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
645
+            $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
646
+            unset( $this->discounts[ $name ] );
647
+        }
648
+
649
+    }
650
+
651
+    /**
652
+     * Checks whether there is a discount code associated with this submission.
653
+     *
654
+     * @since 1.0.19
655
+     * @return bool
656
+     */
657
+    public function has_discount_code() {
658
+        return ! empty( $this->discounts['discount_code'] );
659
+    }
660
+
661
+    /**
662
+     * Returns the discount code.
663
+     *
664
+     * @since 1.0.19
665
+     * @return string
666
+     */
667
+    public function get_discount_code() {
668
+        return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
669
+    }
670
+
671
+    /**
672
+     * Returns the discount.
673
+     *
674
+     * @since 1.0.19
675
+     */
676
+    public function get_discount() {
677
+        return $this->totals['discount']['initial'];
678
+    }
679
+
680
+    /**
681
+     * Returns the recurring discount.
682
+     *
683
+     * @since 1.0.19
684
+     */
685
+    public function get_recurring_discount() {
686
+        return $this->totals['discount']['recurring'];
687
+    }
688
+
689
+    /**
690
+     * Returns all discounts.
691
+     *
692
+     * @since 1.0.19
693
+     */
694
+    public function get_discounts() {
695
+        return $this->discounts;
696
+    }
697
+
698
+    /*
699 699
 	|--------------------------------------------------------------------------
700 700
 	| Fees
701 701
 	|--------------------------------------------------------------------------
@@ -705,100 +705,100 @@  discard block
 block discarded – undo
705 705
 	| fees.
706 706
     */
707 707
 
708
-	/**
709
-	 * Prepares the submission's fees.
710
-	 *
711
-	 * @since 1.0.19
712
-	 */
713
-	public function process_fees() {
714
-
715
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
716
-
717
-		foreach ( $fees_processor->fees as $fee ) {
718
-			$this->add_fee( $fee );
719
-		}
720
-
721
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
722
-	}
723
-
724
-	/**
725
-	 * Adds a fee to the submission.
726
-	 *
727
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
728
-	 * @since 1.0.19
729
-	 */
730
-	public function add_fee( $fee ) {
731
-
732
-		if ( $fee['name'] == 'shipping' ) {
733
-			$this->totals['shipping']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
734
-			$this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
735
-			return;
736
-		}
737
-
738
-		$this->fees[ $fee['name'] ]         = $fee;
739
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
740
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
741
-
742
-	}
743
-
744
-	/**
745
-	 * Removes a fee from the submission.
746
-	 *
747
-	 * @since 1.0.19
748
-	 */
749
-	public function remove_fee( $name ) {
750
-
751
-		if ( isset( $this->fees[ $name ] ) ) {
752
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
753
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
754
-			unset( $this->fees[ $name ] );
755
-		}
756
-
757
-		if ( 'shipping' == $name ) {
758
-			$this->totals['shipping']['initial']   = 0;
759
-			$this->totals['shipping']['recurring'] = 0;
760
-		}
761
-
762
-	}
763
-
764
-	/**
765
-	 * Returns the fees.
766
-	 *
767
-	 * @since 1.0.19
768
-	 */
769
-	public function get_fee() {
770
-		return $this->totals['fees']['initial'];
771
-	}
772
-
773
-	/**
774
-	 * Returns the recurring fees.
775
-	 *
776
-	 * @since 1.0.19
777
-	 */
778
-	public function get_recurring_fee() {
779
-		return $this->totals['fees']['recurring'];
780
-	}
781
-
782
-	/**
783
-	 * Returns all fees.
784
-	 *
785
-	 * @since 1.0.19
786
-	 */
787
-	public function get_fees() {
788
-		return $this->fees;
789
-	}
790
-
791
-	/**
792
-	 * Checks if there are any fees for the form.
793
-	 *
794
-	 * @return bool
795
-	 * @since 1.0.19
796
-	 */
797
-	public function has_fees() {
798
-		return count( $this->fees ) !== 0;
799
-	}
800
-
801
-	/*
708
+    /**
709
+     * Prepares the submission's fees.
710
+     *
711
+     * @since 1.0.19
712
+     */
713
+    public function process_fees() {
714
+
715
+        $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
716
+
717
+        foreach ( $fees_processor->fees as $fee ) {
718
+            $this->add_fee( $fee );
719
+        }
720
+
721
+        do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
722
+    }
723
+
724
+    /**
725
+     * Adds a fee to the submission.
726
+     *
727
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
728
+     * @since 1.0.19
729
+     */
730
+    public function add_fee( $fee ) {
731
+
732
+        if ( $fee['name'] == 'shipping' ) {
733
+            $this->totals['shipping']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
734
+            $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
735
+            return;
736
+        }
737
+
738
+        $this->fees[ $fee['name'] ]         = $fee;
739
+        $this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
740
+        $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
741
+
742
+    }
743
+
744
+    /**
745
+     * Removes a fee from the submission.
746
+     *
747
+     * @since 1.0.19
748
+     */
749
+    public function remove_fee( $name ) {
750
+
751
+        if ( isset( $this->fees[ $name ] ) ) {
752
+            $this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
753
+            $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
754
+            unset( $this->fees[ $name ] );
755
+        }
756
+
757
+        if ( 'shipping' == $name ) {
758
+            $this->totals['shipping']['initial']   = 0;
759
+            $this->totals['shipping']['recurring'] = 0;
760
+        }
761
+
762
+    }
763
+
764
+    /**
765
+     * Returns the fees.
766
+     *
767
+     * @since 1.0.19
768
+     */
769
+    public function get_fee() {
770
+        return $this->totals['fees']['initial'];
771
+    }
772
+
773
+    /**
774
+     * Returns the recurring fees.
775
+     *
776
+     * @since 1.0.19
777
+     */
778
+    public function get_recurring_fee() {
779
+        return $this->totals['fees']['recurring'];
780
+    }
781
+
782
+    /**
783
+     * Returns all fees.
784
+     *
785
+     * @since 1.0.19
786
+     */
787
+    public function get_fees() {
788
+        return $this->fees;
789
+    }
790
+
791
+    /**
792
+     * Checks if there are any fees for the form.
793
+     *
794
+     * @return bool
795
+     * @since 1.0.19
796
+     */
797
+    public function has_fees() {
798
+        return count( $this->fees ) !== 0;
799
+    }
800
+
801
+    /*
802 802
 	|--------------------------------------------------------------------------
803 803
 	| MISC
804 804
 	|--------------------------------------------------------------------------
@@ -806,147 +806,147 @@  discard block
 block discarded – undo
806 806
 	| Extra submission functions.
807 807
     */
808 808
 
809
-	/**
810
-	 * Returns the shipping amount.
811
-	 *
812
-	 * @since 1.0.19
813
-	 */
814
-	public function get_shipping() {
815
-		return $this->totals['shipping']['initial'];
816
-	}
817
-
818
-	/**
819
-	 * Returns the recurring shipping.
820
-	 *
821
-	 * @since 1.0.19
822
-	 */
823
-	public function get_recurring_shipping() {
824
-		return $this->totals['shipping']['recurring'];
825
-	}
826
-
827
-	/**
828
-	 * Checks if there are any shipping fees for the form.
829
-	 *
830
-	 * @return bool
831
-	 * @since 1.0.19
832
-	 */
833
-	public function has_shipping() {
834
-		return apply_filters( 'getpaid_payment_form_has_shipping', false, $this );
835
-	}
836
-
837
-	/**
838
-	 * Checks if this is the initial fetch.
839
-	 *
840
-	 * @return bool
841
-	 * @since 1.0.19
842
-	 */
843
-	public function is_initial_fetch() {
844
-		return empty( $this->data['initial_state'] );
845
-	}
846
-
847
-	/**
848
-	 * Returns the total amount to collect for this submission.
849
-	 *
850
-	 * @since 1.0.19
851
-	 */
852
-	public function get_total() {
853
-		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount();
854
-		return max( $total, 0 );
855
-	}
856
-
857
-	/**
858
-	 * Returns the recurring total amount to collect for this submission.
859
-	 *
860
-	 * @since 1.0.19
861
-	 */
862
-	public function get_recurring_total() {
863
-		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount();
864
-		return max( $total, 0 );
865
-	}
866
-
867
-	/**
868
-	 * Whether payment details should be collected for this submission.
869
-	 *
870
-	 * @since 1.0.19
871
-	 */
872
-	public function should_collect_payment_details() {
873
-		$initial   = $this->get_total();
874
-		$recurring = $this->get_recurring_total();
875
-
876
-		if ( $this->has_recurring == 0 ) {
877
-			$recurring = 0;
878
-		}
879
-
880
-		$collect = $initial > 0 || $recurring > 0;
881
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
882
-	}
883
-
884
-	/**
885
-	 * Returns the billing email of the user.
886
-	 *
887
-	 * @since 1.0.19
888
-	 */
889
-	public function get_billing_email() {
890
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
891
-	}
892
-
893
-	/**
894
-	 * Checks if the submitter has a billing email.
895
-	 *
896
-	 * @since 1.0.19
897
-	 */
898
-	public function has_billing_email() {
899
-		$billing_email = $this->get_billing_email();
900
-		return ! empty( $billing_email ) && is_email( $billing_email );
901
-	}
902
-
903
-	/**
904
-	 * Returns the appropriate currency for the submission.
905
-	 *
906
-	 * @since 1.0.19
907
-	 * @return string
908
-	 */
909
-	public function get_currency() {
910
-		return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
911
-    }
912
-
913
-    /**
914
-	 * Returns the raw submission data.
915
-	 *
916
-	 * @since 1.0.19
917
-	 * @return array
918
-	 */
919
-	public function get_data() {
920
-		return $this->data;
921
-	}
922
-
923
-	/**
924
-	 * Returns a field from the submission data
925
-	 *
926
-	 * @param string $field
927
-	 * @since 1.0.19
928
-	 * @return mixed|null
929
-	 */
930
-	public function get_field( $field, $sub_array_key = null ) {
931
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
932
-	}
933
-
934
-	/**
935
-	 * Checks if a required field is set.
936
-	 *
937
-	 * @since 1.0.19
938
-	 */
939
-	public function is_required_field_set( $field ) {
940
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
941
-	}
942
-
943
-	/**
944
-	 * Formats an amount
945
-	 *
946
-	 * @since 1.0.19
947
-	 */
948
-	public function format_amount( $amount ) {
949
-		return wpinv_price( $amount, $this->get_currency() );
950
-	}
809
+    /**
810
+     * Returns the shipping amount.
811
+     *
812
+     * @since 1.0.19
813
+     */
814
+    public function get_shipping() {
815
+        return $this->totals['shipping']['initial'];
816
+    }
817
+
818
+    /**
819
+     * Returns the recurring shipping.
820
+     *
821
+     * @since 1.0.19
822
+     */
823
+    public function get_recurring_shipping() {
824
+        return $this->totals['shipping']['recurring'];
825
+    }
826
+
827
+    /**
828
+     * Checks if there are any shipping fees for the form.
829
+     *
830
+     * @return bool
831
+     * @since 1.0.19
832
+     */
833
+    public function has_shipping() {
834
+        return apply_filters( 'getpaid_payment_form_has_shipping', false, $this );
835
+    }
836
+
837
+    /**
838
+     * Checks if this is the initial fetch.
839
+     *
840
+     * @return bool
841
+     * @since 1.0.19
842
+     */
843
+    public function is_initial_fetch() {
844
+        return empty( $this->data['initial_state'] );
845
+    }
846
+
847
+    /**
848
+     * Returns the total amount to collect for this submission.
849
+     *
850
+     * @since 1.0.19
851
+     */
852
+    public function get_total() {
853
+        $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount();
854
+        return max( $total, 0 );
855
+    }
856
+
857
+    /**
858
+     * Returns the recurring total amount to collect for this submission.
859
+     *
860
+     * @since 1.0.19
861
+     */
862
+    public function get_recurring_total() {
863
+        $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount();
864
+        return max( $total, 0 );
865
+    }
866
+
867
+    /**
868
+     * Whether payment details should be collected for this submission.
869
+     *
870
+     * @since 1.0.19
871
+     */
872
+    public function should_collect_payment_details() {
873
+        $initial   = $this->get_total();
874
+        $recurring = $this->get_recurring_total();
875
+
876
+        if ( $this->has_recurring == 0 ) {
877
+            $recurring = 0;
878
+        }
879
+
880
+        $collect = $initial > 0 || $recurring > 0;
881
+        return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
882
+    }
883
+
884
+    /**
885
+     * Returns the billing email of the user.
886
+     *
887
+     * @since 1.0.19
888
+     */
889
+    public function get_billing_email() {
890
+        return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
891
+    }
892
+
893
+    /**
894
+     * Checks if the submitter has a billing email.
895
+     *
896
+     * @since 1.0.19
897
+     */
898
+    public function has_billing_email() {
899
+        $billing_email = $this->get_billing_email();
900
+        return ! empty( $billing_email ) && is_email( $billing_email );
901
+    }
902
+
903
+    /**
904
+     * Returns the appropriate currency for the submission.
905
+     *
906
+     * @since 1.0.19
907
+     * @return string
908
+     */
909
+    public function get_currency() {
910
+        return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
911
+    }
912
+
913
+    /**
914
+     * Returns the raw submission data.
915
+     *
916
+     * @since 1.0.19
917
+     * @return array
918
+     */
919
+    public function get_data() {
920
+        return $this->data;
921
+    }
922
+
923
+    /**
924
+     * Returns a field from the submission data
925
+     *
926
+     * @param string $field
927
+     * @since 1.0.19
928
+     * @return mixed|null
929
+     */
930
+    public function get_field( $field, $sub_array_key = null ) {
931
+        return getpaid_get_array_field( $this->data, $field, $sub_array_key );
932
+    }
933
+
934
+    /**
935
+     * Checks if a required field is set.
936
+     *
937
+     * @since 1.0.19
938
+     */
939
+    public function is_required_field_set( $field ) {
940
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
941
+    }
942
+
943
+    /**
944
+     * Formats an amount
945
+     *
946
+     * @since 1.0.19
947
+     */
948
+    public function format_amount( $amount ) {
949
+        return wpinv_price( $amount, $this->get_currency() );
950
+    }
951 951
 
952 952
 }
Please login to merge, or discard this patch.
Spacing   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
 		$this->state   = wpinv_get_default_state();
147 147
 
148 148
 		// Do we have an actual submission?
149
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
150
-			$this->load_data( $_POST );
149
+		if (isset($_POST['getpaid_payment_form_submission'])) {
150
+			$this->load_data($_POST);
151 151
 		}
152 152
 
153 153
 	}
@@ -157,19 +157,19 @@  discard block
 block discarded – undo
157 157
 	 *
158 158
 	 * @param array $data
159 159
 	 */
160
-	public function load_data( $data ) {
160
+	public function load_data($data) {
161 161
 
162 162
 		// Remove slashes from the submitted data...
163
-		$data       = wp_kses_post_deep( wp_unslash( $data ) );
163
+		$data       = wp_kses_post_deep(wp_unslash($data));
164 164
 
165 165
 		// Allow plugins to filter the data.
166
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
166
+		$data       = apply_filters('getpaid_submission_data', $data, $this);
167 167
 
168 168
 		// Cache it...
169 169
 		$this->data = $data;
170 170
 
171 171
 		// Then generate a unique id from the data.
172
-		$this->id   = md5( wp_json_encode( $data ) );
172
+		$this->id   = md5(wp_json_encode($data));
173 173
 
174 174
 		// Finally, process the submission.
175 175
 		try {
@@ -179,30 +179,30 @@  discard block
 block discarded – undo
179 179
 			$processors = apply_filters(
180 180
 				'getpaid_payment_form_submission_processors',
181 181
 				array(
182
-					array( $this, 'process_payment_form' ),
183
-					array( $this, 'process_invoice' ),
184
-					array( $this, 'process_fees' ),
185
-					array( $this, 'process_items' ),
186
-					array( $this, 'process_discount' ),
187
-					array( $this, 'process_taxes' ),
182
+					array($this, 'process_payment_form'),
183
+					array($this, 'process_invoice'),
184
+					array($this, 'process_fees'),
185
+					array($this, 'process_items'),
186
+					array($this, 'process_discount'),
187
+					array($this, 'process_taxes'),
188 188
 				),
189 189
 				$this		
190 190
 			);
191 191
 
192
-			foreach ( $processors as $processor ) {
193
-				call_user_func_array( $processor, array( &$this ) );
192
+			foreach ($processors as $processor) {
193
+				call_user_func_array($processor, array(&$this));
194 194
 			}
195 195
 
196
-		} catch( GetPaid_Payment_Exception $e ) {
196
+		} catch (GetPaid_Payment_Exception $e) {
197 197
 			$this->last_error      = $e->getMessage();
198 198
 			$this->last_error_code = $e->getErrorCode();
199
-		} catch ( Exception $e ) {
199
+		} catch (Exception $e) {
200 200
 			$this->last_error      = $e->getMessage();
201 201
 			$this->last_error_code = $e->getCode();
202 202
 		}
203 203
 
204 204
 		// Fired when we are done processing a submission.
205
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
205
+		do_action_ref_array('getpaid_process_submission', array(&$this));
206 206
 
207 207
 	}
208 208
 
@@ -223,18 +223,18 @@  discard block
 block discarded – undo
223 223
 	public function process_payment_form() {
224 224
 
225 225
 		// Every submission needs an active payment form.
226
-		if ( empty( $this->data['form_id'] ) ) {
227
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
226
+		if (empty($this->data['form_id'])) {
227
+			throw new Exception(__('Missing payment form', 'invoicing'));
228 228
 		}
229 229
 
230 230
 		// Fetch the payment form.
231
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
231
+		$this->payment_form = new GetPaid_Payment_Form($this->data['form_id']);
232 232
 
233
-		if ( ! $this->payment_form->is_active() ) {
234
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
233
+		if (!$this->payment_form->is_active()) {
234
+			throw new Exception(__('Payment form not active', 'invoicing'));
235 235
 		}
236 236
 
237
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
237
+		do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this));
238 238
 	}
239 239
 
240 240
     /**
@@ -264,53 +264,53 @@  discard block
 block discarded – undo
264 264
 	public function process_invoice() {
265 265
 
266 266
 		// Abort if there is no invoice.
267
-		if ( empty( $this->data['invoice_id'] ) ) {
267
+		if (empty($this->data['invoice_id'])) {
268 268
 			return;
269 269
 		}
270 270
 
271 271
 		// If the submission is for an existing invoice, ensure that it exists
272 272
 		// and that it is not paid for.
273
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
273
+		$invoice = wpinv_get_invoice($this->data['invoice_id']);
274 274
 
275
-        if ( empty( $invoice ) ) {
276
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
275
+        if (empty($invoice)) {
276
+			throw new Exception(__('Invalid invoice', 'invoicing'));
277 277
 		}
278 278
 
279
-		if ( $invoice->is_paid() ) {
280
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
279
+		if ($invoice->is_paid()) {
280
+			throw new Exception(__('This invoice is already paid for.', 'invoicing'));
281 281
 		}
282 282
 
283 283
 		$this->payment_form->invoice = $invoice;
284
-		if ( ! $this->payment_form->is_default() ) {
284
+		if (!$this->payment_form->is_default()) {
285 285
 
286 286
 			$items    = array();
287 287
 			$item_ids = array();
288 288
 	
289
-			foreach ( $invoice->get_items() as $item ) {
290
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
289
+			foreach ($invoice->get_items() as $item) {
290
+				if (!in_array($item->get_id(), $item_ids)) {
291 291
 					$item_ids[] = $item->get_id();
292 292
 					$items[]    = $item;
293 293
 				}
294 294
 			}
295 295
 	
296
-			foreach ( $this->payment_form->get_items() as $item ) {
297
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
296
+			foreach ($this->payment_form->get_items() as $item) {
297
+				if (!in_array($item->get_id(), $item_ids)) {
298 298
 					$item_ids[] = $item->get_id();
299 299
 					$items[]    = $item;
300 300
 				}
301 301
 			}
302 302
 	
303
-			$this->payment_form->set_items( $items );
303
+			$this->payment_form->set_items($items);
304 304
 	
305 305
 		} else {
306
-			$this->payment_form->set_items( $invoice->get_items() );
306
+			$this->payment_form->set_items($invoice->get_items());
307 307
 		}
308 308
 
309 309
 		$this->country = $invoice->get_country();
310 310
 		$this->state   = $invoice->get_state();
311 311
 		$this->invoice = $invoice;
312 312
 
313
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
313
+		do_action_ref_array('getpaid_submissions_process_invoice', array(&$this));
314 314
 	}
315 315
 
316 316
 	/**
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 	 * @return bool
331 331
 	 */
332 332
 	public function has_invoice() {
333
-		return ! empty( $this->invoice );
333
+		return !empty($this->invoice);
334 334
 	}
335 335
 
336 336
 	/*
@@ -349,13 +349,13 @@  discard block
 block discarded – undo
349 349
 	 */
350 350
 	public function process_items() {
351 351
 
352
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
352
+		$processor = new GetPaid_Payment_Form_Submission_Items($this);
353 353
 
354
-		foreach ( $processor->items as $item ) {
355
-			$this->add_item( $item );
354
+		foreach ($processor->items as $item) {
355
+			$this->add_item($item);
356 356
 		}
357 357
 
358
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
358
+		do_action_ref_array('getpaid_submissions_process_items', array(&$this));
359 359
 	}
360 360
 
361 361
 	/**
@@ -364,20 +364,20 @@  discard block
 block discarded – undo
364 364
 	 * @since 1.0.19
365 365
 	 * @param GetPaid_Form_Item $item
366 366
 	 */
367
-	public function add_item( $item ) {
367
+	public function add_item($item) {
368 368
 
369 369
 		// Make sure that it is available for purchase.
370
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
370
+		if (!$item->can_purchase() || isset($this->items[$item->get_id()])) {
371 371
 			return;
372 372
 		}
373 373
 
374 374
 		// Each submission can only contain one recurring item.
375
-		if ( $item->is_recurring() ) {
375
+		if ($item->is_recurring()) {
376 376
 			$this->has_recurring = $item->get_id();
377 377
 		}
378 378
 
379 379
 		// Update the items and totals.
380
-		$this->items[ $item->get_id() ]         = $item;
380
+		$this->items[$item->get_id()]         = $item;
381 381
 		$this->totals['subtotal']['initial']   += $item->get_sub_total();
382 382
 		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
383 383
 
@@ -391,17 +391,17 @@  discard block
 block discarded – undo
391 391
 	 *
392 392
 	 * @since 1.0.19
393 393
 	 */
394
-	public function remove_item( $item_id ) {
394
+	public function remove_item($item_id) {
395 395
 
396
-		if ( isset( $this->items[ $item_id ] ) ) {
397
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
398
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
396
+		if (isset($this->items[$item_id])) {
397
+			$this->totals['subtotal']['initial']   -= $this->items[$item_id]->get_sub_total();
398
+			$this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total();
399 399
 
400
-			if ( $this->items[ $item_id ]->is_recurring() ) {
400
+			if ($this->items[$item_id]->is_recurring()) {
401 401
 				$this->has_recurring = 0;
402 402
 			}
403 403
 
404
-			unset( $this->items[ $item_id ] );
404
+			unset($this->items[$item_id]);
405 405
 		}
406 406
 
407 407
 	}
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
 	 */
414 414
 	public function get_subtotal() {
415 415
 
416
-		if ( wpinv_prices_include_tax() ) {
416
+		if (wpinv_prices_include_tax()) {
417 417
 			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
418 418
 		}
419 419
 
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
 	 */
428 428
 	public function get_recurring_subtotal() {
429 429
 
430
-		if ( wpinv_prices_include_tax() ) {
430
+		if (wpinv_prices_include_tax()) {
431 431
 			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
432 432
 		}
433 433
 
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
 	 * @return bool
452 452
 	 */
453 453
 	public function has_subscription_group() {
454
-		return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
454
+		return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this));
455 455
 	}
456 456
 
457 457
 	/**
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 	 * @return bool
462 462
 	 */
463 463
 	public function has_multiple_subscription_groups() {
464
-		return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
464
+		return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this));
465 465
 	}
466 466
 
467 467
 	/*
@@ -481,39 +481,39 @@  discard block
 block discarded – undo
481 481
 	public function process_taxes() {
482 482
 
483 483
 		// Abort if we're not using taxes.
484
-		if ( ! $this->use_taxes() ) {
484
+		if (!$this->use_taxes()) {
485 485
 			return;
486 486
 		}
487 487
 
488 488
 		// If a custom country && state has been passed in, use it to calculate taxes.
489
-		$country = $this->get_field( 'wpinv_country', 'billing' );
490
-		if ( ! empty( $country ) ) {
489
+		$country = $this->get_field('wpinv_country', 'billing');
490
+		if (!empty($country)) {
491 491
 			$this->country = $country;
492 492
 		}
493 493
 
494
-		$state = $this->get_field( 'wpinv_state', 'billing' );
495
-		if ( ! empty( $state ) ) {
494
+		$state = $this->get_field('wpinv_state', 'billing');
495
+		if (!empty($state)) {
496 496
 			$this->state = $state;
497 497
 		}
498 498
 
499 499
 		// Confirm if the provided country and the ip country are similar.
500
-		$address_confirmed = $this->get_field( 'confirm-address' );
501
-		if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
502
-			throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
500
+		$address_confirmed = $this->get_field('confirm-address');
501
+		if (isset($_POST['billing']['country']) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) {
502
+			throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing'));
503 503
 		}
504 504
 
505 505
 		// Abort if the country is not taxable.
506
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
506
+		if (!wpinv_is_country_taxable($this->country)) {
507 507
 			return;
508 508
 		}
509 509
 
510
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
510
+		$processor = new GetPaid_Payment_Form_Submission_Taxes($this);
511 511
 
512
-		foreach ( $processor->taxes as $tax ) {
513
-			$this->add_tax( $tax );
512
+		foreach ($processor->taxes as $tax) {
513
+			$this->add_tax($tax);
514 514
 		}
515 515
 
516
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
516
+		do_action_ref_array('getpaid_submissions_process_taxes', array(&$this));
517 517
 	}
518 518
 
519 519
 	/**
@@ -522,16 +522,16 @@  discard block
 block discarded – undo
522 522
 	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
523 523
 	 * @since 1.0.19
524 524
 	 */
525
-	public function add_tax( $tax ) {
525
+	public function add_tax($tax) {
526 526
 
527
-		if ( wpinv_round_tax_per_tax_rate() ) {
528
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
529
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
527
+		if (wpinv_round_tax_per_tax_rate()) {
528
+			$tax['initial_tax']   = wpinv_round_amount($tax['initial_tax']);
529
+			$tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']);
530 530
 		}
531 531
 
532
-		$this->taxes[ $tax['name'] ]         = $tax;
533
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
534
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
532
+		$this->taxes[$tax['name']]         = $tax;
533
+		$this->totals['taxes']['initial']   += wpinv_sanitize_amount($tax['initial_tax']);
534
+		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']);
535 535
 
536 536
 	}
537 537
 
@@ -540,12 +540,12 @@  discard block
 block discarded – undo
540 540
 	 *
541 541
 	 * @since 1.0.19
542 542
 	 */
543
-	public function remove_tax( $tax_name ) {
543
+	public function remove_tax($tax_name) {
544 544
 
545
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
546
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
547
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
548
-			unset( $this->taxes[ $tax_name ] );
545
+		if (isset($this->taxes[$tax_name])) {
546
+			$this->totals['taxes']['initial']   -= $this->taxes[$tax_name]['initial_tax'];
547
+			$this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax'];
548
+			unset($this->taxes[$tax_name]);
549 549
 		}
550 550
 
551 551
 	}
@@ -559,11 +559,11 @@  discard block
 block discarded – undo
559 559
 
560 560
 		$use_taxes = wpinv_use_taxes();
561 561
 
562
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
562
+		if ($this->has_invoice() && !$this->invoice->is_taxable()) {
563 563
 			$use_taxes = false;
564 564
 		}
565 565
 
566
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
566
+		return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this);
567 567
 
568 568
 	}
569 569
 
@@ -612,13 +612,13 @@  discard block
 block discarded – undo
612 612
 
613 613
 		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
614 614
 		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
615
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
615
+		$processor        = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total);
616 616
 
617
-		foreach ( $processor->discounts as $discount ) {
618
-			$this->add_discount( $discount );
617
+		foreach ($processor->discounts as $discount) {
618
+			$this->add_discount($discount);
619 619
 		}
620 620
 
621
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
621
+		do_action_ref_array('getpaid_submissions_process_discounts', array(&$this));
622 622
 	}
623 623
 
624 624
 	/**
@@ -627,10 +627,10 @@  discard block
 block discarded – undo
627 627
 	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
628 628
 	 * @since 1.0.19
629 629
 	 */
630
-	public function add_discount( $discount ) {
631
-		$this->discounts[ $discount['name'] ]   = $discount;
632
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
633
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
630
+	public function add_discount($discount) {
631
+		$this->discounts[$discount['name']]   = $discount;
632
+		$this->totals['discount']['initial']   += wpinv_sanitize_amount($discount['initial_discount']);
633
+		$this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']);
634 634
 	}
635 635
 
636 636
 	/**
@@ -638,12 +638,12 @@  discard block
 block discarded – undo
638 638
 	 *
639 639
 	 * @since 1.0.19
640 640
 	 */
641
-	public function remove_discount( $name ) {
641
+	public function remove_discount($name) {
642 642
 
643
-		if ( isset( $this->discounts[ $name ] ) ) {
644
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
645
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
646
-			unset( $this->discounts[ $name ] );
643
+		if (isset($this->discounts[$name])) {
644
+			$this->totals['discount']['initial']   -= $this->discounts[$name]['initial_discount'];
645
+			$this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount'];
646
+			unset($this->discounts[$name]);
647 647
 		}
648 648
 
649 649
 	}
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
 	 * @return bool
656 656
 	 */
657 657
 	public function has_discount_code() {
658
-		return ! empty( $this->discounts['discount_code'] );
658
+		return !empty($this->discounts['discount_code']);
659 659
 	}
660 660
 
661 661
 	/**
@@ -712,13 +712,13 @@  discard block
 block discarded – undo
712 712
 	 */
713 713
 	public function process_fees() {
714 714
 
715
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
715
+		$fees_processor = new GetPaid_Payment_Form_Submission_Fees($this);
716 716
 
717
-		foreach ( $fees_processor->fees as $fee ) {
718
-			$this->add_fee( $fee );
717
+		foreach ($fees_processor->fees as $fee) {
718
+			$this->add_fee($fee);
719 719
 		}
720 720
 
721
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
721
+		do_action_ref_array('getpaid_submissions_process_fees', array(&$this));
722 722
 	}
723 723
 
724 724
 	/**
@@ -727,17 +727,17 @@  discard block
 block discarded – undo
727 727
 	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
728 728
 	 * @since 1.0.19
729 729
 	 */
730
-	public function add_fee( $fee ) {
730
+	public function add_fee($fee) {
731 731
 
732
-		if ( $fee['name'] == 'shipping' ) {
733
-			$this->totals['shipping']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
734
-			$this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
732
+		if ($fee['name'] == 'shipping') {
733
+			$this->totals['shipping']['initial']   += wpinv_sanitize_amount($fee['initial_fee']);
734
+			$this->totals['shipping']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']);
735 735
 			return;
736 736
 		}
737 737
 
738
-		$this->fees[ $fee['name'] ]         = $fee;
739
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
740
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
738
+		$this->fees[$fee['name']]         = $fee;
739
+		$this->totals['fees']['initial']   += wpinv_sanitize_amount($fee['initial_fee']);
740
+		$this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']);
741 741
 
742 742
 	}
743 743
 
@@ -746,15 +746,15 @@  discard block
 block discarded – undo
746 746
 	 *
747 747
 	 * @since 1.0.19
748 748
 	 */
749
-	public function remove_fee( $name ) {
749
+	public function remove_fee($name) {
750 750
 
751
-		if ( isset( $this->fees[ $name ] ) ) {
752
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
753
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
754
-			unset( $this->fees[ $name ] );
751
+		if (isset($this->fees[$name])) {
752
+			$this->totals['fees']['initial']   -= $this->fees[$name]['initial_fee'];
753
+			$this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee'];
754
+			unset($this->fees[$name]);
755 755
 		}
756 756
 
757
-		if ( 'shipping' == $name ) {
757
+		if ('shipping' == $name) {
758 758
 			$this->totals['shipping']['initial']   = 0;
759 759
 			$this->totals['shipping']['recurring'] = 0;
760 760
 		}
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
 	 * @since 1.0.19
796 796
 	 */
797 797
 	public function has_fees() {
798
-		return count( $this->fees ) !== 0;
798
+		return count($this->fees) !== 0;
799 799
 	}
800 800
 
801 801
 	/*
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
 	 * @since 1.0.19
832 832
 	 */
833 833
 	public function has_shipping() {
834
-		return apply_filters( 'getpaid_payment_form_has_shipping', false, $this );
834
+		return apply_filters('getpaid_payment_form_has_shipping', false, $this);
835 835
 	}
836 836
 
837 837
 	/**
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
 	 * @since 1.0.19
842 842
 	 */
843 843
 	public function is_initial_fetch() {
844
-		return empty( $this->data['initial_state'] );
844
+		return empty($this->data['initial_state']);
845 845
 	}
846 846
 
847 847
 	/**
@@ -851,7 +851,7 @@  discard block
 block discarded – undo
851 851
 	 */
852 852
 	public function get_total() {
853 853
 		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount();
854
-		return max( $total, 0 );
854
+		return max($total, 0);
855 855
 	}
856 856
 
857 857
 	/**
@@ -861,7 +861,7 @@  discard block
 block discarded – undo
861 861
 	 */
862 862
 	public function get_recurring_total() {
863 863
 		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount();
864
-		return max( $total, 0 );
864
+		return max($total, 0);
865 865
 	}
866 866
 
867 867
 	/**
@@ -873,12 +873,12 @@  discard block
 block discarded – undo
873 873
 		$initial   = $this->get_total();
874 874
 		$recurring = $this->get_recurring_total();
875 875
 
876
-		if ( $this->has_recurring == 0 ) {
876
+		if ($this->has_recurring == 0) {
877 877
 			$recurring = 0;
878 878
 		}
879 879
 
880 880
 		$collect = $initial > 0 || $recurring > 0;
881
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
881
+		return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this);
882 882
 	}
883 883
 
884 884
 	/**
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
 	 * @since 1.0.19
888 888
 	 */
889 889
 	public function get_billing_email() {
890
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
890
+		return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this);
891 891
 	}
892 892
 
893 893
 	/**
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
 	 */
898 898
 	public function has_billing_email() {
899 899
 		$billing_email = $this->get_billing_email();
900
-		return ! empty( $billing_email ) && is_email( $billing_email );
900
+		return !empty($billing_email) && is_email($billing_email);
901 901
 	}
902 902
 
903 903
 	/**
@@ -927,8 +927,8 @@  discard block
 block discarded – undo
927 927
 	 * @since 1.0.19
928 928
 	 * @return mixed|null
929 929
 	 */
930
-	public function get_field( $field, $sub_array_key = null ) {
931
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
930
+	public function get_field($field, $sub_array_key = null) {
931
+		return getpaid_get_array_field($this->data, $field, $sub_array_key);
932 932
 	}
933 933
 
934 934
 	/**
@@ -936,8 +936,8 @@  discard block
 block discarded – undo
936 936
 	 *
937 937
 	 * @since 1.0.19
938 938
 	 */
939
-	public function is_required_field_set( $field ) {
940
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
939
+	public function is_required_field_set($field) {
940
+		return empty($field['required']) || !empty($this->data[$field['id']]);
941 941
 	}
942 942
 
943 943
 	/**
@@ -945,8 +945,8 @@  discard block
 block discarded – undo
945 945
 	 *
946 946
 	 * @since 1.0.19
947 947
 	 */
948
-	public function format_amount( $amount ) {
949
-		return wpinv_price( $amount, $this->get_currency() );
948
+	public function format_amount($amount) {
949
+		return wpinv_price($amount, $this->get_currency());
950 950
 	}
951 951
 
952 952
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 2 patches
Indentation   +301 added lines, -301 removed lines patch added patch discarded remove patch
@@ -12,184 +12,184 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 * 
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Prepare the invoice.
39
-		$items      = $this->get_submission_items();
40
-		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving();
43
-
44
-		$this->prepare_billing_info( $invoice );
45
-
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
47
-
48
-		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
50
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     * 
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Prepare the invoice.
39
+        $items      = $this->get_submission_items();
40
+        $invoice    = $this->get_submission_invoice();
41
+        $invoice    = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared   = $this->prepare_submission_data_for_saving();
43
+
44
+        $this->prepare_billing_info( $invoice );
45
+
46
+        $shipping   = $this->prepare_shipping_info( $invoice );
47
+
48
+        // Save the invoice.
49
+        $invoice->set_is_viewed( true );
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
-		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
57
-	}
55
+        // Send to the gateway.
56
+        $this->post_process_submission( $invoice, $prepared, $shipping );
57
+    }
58 58
 
59
-	/**
60
-	 * Validates the submission.
61
-	 *
62
-	 */
63
-	protected function validate_submission() {
59
+    /**
60
+     * Validates the submission.
61
+     *
62
+     */
63
+    protected function validate_submission() {
64 64
 
65
-		$submission = $this->payment_form_submission;
66
-		$data       = $submission->get_data();
65
+        $submission = $this->payment_form_submission;
66
+        $data       = $submission->get_data();
67 67
 
68
-		// Do we have an error?
68
+        // Do we have an error?
69 69
         if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
70
+            wp_send_json_error( $submission->last_error );
71 71
         }
72 72
 
73
-		// We need a billing email.
73
+        // We need a billing email.
74 74
         if ( ! $submission->has_billing_email() ) {
75 75
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
76
-		}
76
+        }
77 77
 
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' ) );
81
-		}
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' ) );
81
+        }
82 82
 
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' ) );
86
-		}
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' ) );
86
+        }
87 87
 
88
-		// Clear any existing errors.
89
-		wpinv_clear_errors();
88
+        // Clear any existing errors.
89
+        wpinv_clear_errors();
90 90
 
91
-		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
91
+        // Allow themes and plugins to hook to errors
92
+        do_action( 'getpaid_checkout_error_checks', $submission );
93 93
 
94
-		// Do we have any errors?
94
+        // Do we have any errors?
95 95
         if ( wpinv_get_errors() ) {
96 96
             wp_send_json_error( getpaid_get_errors_html() );
97
-		}
97
+        }
98 98
 
99
-	}
99
+    }
100 100
 
101
-	/**
102
-	 * Retrieves submission items.
103
-	 *
104
-	 * @return GetPaid_Form_Item[]
105
-	 */
106
-	protected function get_submission_items() {
101
+    /**
102
+     * Retrieves submission items.
103
+     *
104
+     * @return GetPaid_Form_Item[]
105
+     */
106
+    protected function get_submission_items() {
107 107
 
108
-		$items = $this->payment_form_submission->get_items();
108
+        $items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111 111
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112 112
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
113
-		}
114
-
115
-		return $items;
116
-	}
117
-
118
-	/**
119
-	 * Retrieves submission invoice.
120
-	 *
121
-	 * @return WPInv_Invoice
122
-	 */
123
-	protected function get_submission_invoice() {
124
-		$submission = $this->payment_form_submission;
125
-
126
-		if ( ! $submission->has_invoice() ) {
127
-			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
129
-			return $invoice;
130 113
         }
131 114
 
132
-		$invoice = $submission->get_invoice();
115
+        return $items;
116
+    }
117
+
118
+    /**
119
+     * Retrieves submission invoice.
120
+     *
121
+     * @return WPInv_Invoice
122
+     */
123
+    protected function get_submission_invoice() {
124
+        $submission = $this->payment_form_submission;
125
+
126
+        if ( ! $submission->has_invoice() ) {
127
+            $invoice = new WPInv_Invoice();
128
+            $invoice->set_created_via( 'payment_form' );
129
+            return $invoice;
130
+        }
131
+
132
+        $invoice = $submission->get_invoice();
133 133
 
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' ) );
137
-		}
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' ) );
137
+        }
138 138
 
139
-		return $invoice;
140
-	}
139
+        return $invoice;
140
+    }
141 141
 
142
-	/**
143
-	 * Processes the submission invoice.
144
-	 *
145
-	 * @param WPInv_Invoice $invoice
146
-	 * @param GetPaid_Form_Item[] $items
147
-	 * @return WPInv_Invoice
148
-	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
142
+    /**
143
+     * Processes the submission invoice.
144
+     *
145
+     * @param WPInv_Invoice $invoice
146
+     * @param GetPaid_Form_Item[] $items
147
+     * @return WPInv_Invoice
148
+     */
149
+    protected function process_submission_invoice( $invoice, $items ) {
150 150
 
151
-		$submission = $this->payment_form_submission;
151
+        $submission = $this->payment_form_submission;
152 152
 
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_payment_form( absint( $submission->get_payment_form()->get_id() ) );
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_payment_form( absint( $submission->get_payment_form()->get_id() ) );
157 157
         $invoice->set_items( $items );
158 158
         $invoice->set_fees( $submission->get_fees() );
159 159
         $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
-		$invoice->set_currency( $submission->get_currency() );
160
+        $invoice->set_discounts( $submission->get_discounts() );
161
+        $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
+        $invoice->set_currency( $submission->get_currency() );
163 163
 
164
-		if ( $submission->has_shipping() ) {
165
-			$invoice->set_shipping( $submission->get_shipping() );
166
-		}
164
+        if ( $submission->has_shipping() ) {
165
+            $invoice->set_shipping( $submission->get_shipping() );
166
+        }
167 167
 
168
-		$address_confirmed = $submission->get_field( 'confirm-address' );
169
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
168
+        $address_confirmed = $submission->get_field( 'confirm-address' );
169
+        $invoice->set_address_confirmed( ! empty( $address_confirmed ) );
170 170
 
171
-		if ( $submission->has_discount_code() ) {
171
+        if ( $submission->has_discount_code() ) {
172 172
             $invoice->set_discount_code( $submission->get_discount_code() );
173
-		}
174
-
175
-		getpaid_maybe_add_default_address( $invoice );
176
-		return $invoice;
177
-	}
178
-
179
-	/**
180
-	 * Retrieves the submission's customer.
181
-	 *
182
-	 * @return int The customer id.
183
-	 */
184
-	protected function get_submission_customer() {
185
-		$submission = $this->payment_form_submission;
186
-
187
-		// If this is an existing invoice...
188
-		if ( $submission->has_invoice() ) {
189
-			return $submission->get_invoice()->get_user_id();
190
-		}
191
-
192
-		// (Maybe) create the user.
173
+        }
174
+
175
+        getpaid_maybe_add_default_address( $invoice );
176
+        return $invoice;
177
+    }
178
+
179
+    /**
180
+     * Retrieves the submission's customer.
181
+     *
182
+     * @return int The customer id.
183
+     */
184
+    protected function get_submission_customer() {
185
+        $submission = $this->payment_form_submission;
186
+
187
+        // If this is an existing invoice...
188
+        if ( $submission->has_invoice() ) {
189
+            return $submission->get_invoice()->get_user_id();
190
+        }
191
+
192
+        // (Maybe) create the user.
193 193
         $user = get_current_user_id();
194 194
 
195 195
         if ( empty( $user ) ) {
@@ -199,11 +199,11 @@  discard block
 block discarded – undo
199 199
         if ( empty( $user ) ) {
200 200
             $user = wpinv_create_user( $submission->get_billing_email() );
201 201
 
202
-			// (Maybe) send new user notification.
203
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
204
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
205
-				wp_send_new_user_notifications( $user, 'user' );
206
-			}
202
+            // (Maybe) send new user notification.
203
+            $should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
204
+            if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
205
+                wp_send_new_user_notifications( $user, 'user' );
206
+            }
207 207
 
208 208
         }
209 209
 
@@ -213,49 +213,49 @@  discard block
 block discarded – undo
213 213
 
214 214
         if ( is_numeric( $user ) ) {
215 215
             return $user;
216
-		}
216
+        }
217 217
 
218
-		return $user->ID;
218
+        return $user->ID;
219 219
 
220
-	}
220
+    }
221 221
 
222
-	/**
222
+    /**
223 223
      * Prepares submission data for saving to the database.
224 224
      *
225
-	 * @return array
225
+     * @return array
226 226
      */
227 227
     public function prepare_submission_data_for_saving() {
228 228
 
229
-		$submission = $this->payment_form_submission;
229
+        $submission = $this->payment_form_submission;
230 230
 
231
-		// Prepared submission details.
231
+        // Prepared submission details.
232 232
         $prepared = array(
233
-			'all'  => array(),
234
-			'meta' => array(),
235
-		);
233
+            'all'  => array(),
234
+            'meta' => array(),
235
+        );
236 236
 
237 237
         // Raw submission details.
238
-		$data     = $submission->get_data();
238
+        $data     = $submission->get_data();
239 239
 
240
-		// Loop through the submitted details.
240
+        // Loop through the submitted details.
241 241
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
242 242
 
243
-			// Skip premade fields.
243
+            // Skip premade fields.
244 244
             if ( ! empty( $field['premade'] ) ) {
245 245
                 continue;
246 246
             }
247 247
 
248
-			// Ensure address is provided.
249
-			if ( $field['type'] == 'address' ) {
248
+            // Ensure address is provided.
249
+            if ( $field['type'] == 'address' ) {
250 250
                 $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
251 251
 
252
-				foreach ( $field['fields'] as $address_field ) {
252
+                foreach ( $field['fields'] as $address_field ) {
253 253
 
254
-					if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
255
-						wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
256
-					}
254
+                    if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
255
+                        wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
256
+                    }
257 257
 
258
-				}
258
+                }
259 259
 
260 260
             }
261 261
 
@@ -267,31 +267,31 @@  discard block
 block discarded – undo
267 267
             // Handle misc fields.
268 268
             if ( isset( $data[ $field['id'] ] ) ) {
269 269
 
270
-				// Uploads.
271
-				if ( $field['type'] == 'file_upload' ) {
272
-					$max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
270
+                // Uploads.
271
+                if ( $field['type'] == 'file_upload' ) {
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' ) );
276
-					}
274
+                    if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
275
+                        wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
276
+                    }
277 277
 
278
-					$value = array();
278
+                    $value = array();
279 279
 
280
-					foreach ( $data[ $field['id'] ] as $url => $name ) {
281
-						$value[] = sprintf(
282
-							'<a href="%s" target="_blank">%s</a>',
283
-							esc_url_raw( $url ),
284
-							esc_html( $name )
285
-						);
286
-					}
280
+                    foreach ( $data[ $field['id'] ] as $url => $name ) {
281
+                        $value[] = sprintf(
282
+                            '<a href="%s" target="_blank">%s</a>',
283
+                            esc_url_raw( $url ),
284
+                            esc_html( $name )
285
+                        );
286
+                    }
287 287
 
288
-					$value = implode( ' | ', $value );
288
+                    $value = implode( ' | ', $value );
289 289
 
290
-				} else if ( $field['type'] == 'checkbox' ) {
291
-					$value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
292
-				} else {
293
-					$value = wp_kses_post( $data[ $field['id'] ] );
294
-				}
290
+                } else if ( $field['type'] == 'checkbox' ) {
291
+                    $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
292
+                } else {
293
+                    $value = wp_kses_post( $data[ $field['id'] ] );
294
+                }
295 295
 
296 296
                 $label = $field['id'];
297 297
 
@@ -299,190 +299,190 @@  discard block
 block discarded – undo
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 );
304
-				}
305
-				$prepared['all'][ 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
+                }
305
+                $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
306 306
 
307 307
             }
308 308
 
309
-		}
309
+        }
310 310
 
311
-		return $prepared;
311
+        return $prepared;
312 312
 
313
-	}
313
+    }
314 314
 
315
-	/**
315
+    /**
316 316
      * Retrieves address details.
317 317
      *
318
-	 * @return array
319
-	 * @param WPInv_Invoice $invoice
320
-	 * @param string $type
318
+     * @return array
319
+     * @param WPInv_Invoice $invoice
320
+     * @param string $type
321 321
      */
322 322
     public function prepare_address_details( $invoice, $type = 'billing' ) {
323 323
 
324
-		$data     = $this->payment_form_submission->get_data();
325
-		$type     = sanitize_key( $type );
326
-		$address  = array();
327
-		$prepared = array();
324
+        $data     = $this->payment_form_submission->get_data();
325
+        $type     = sanitize_key( $type );
326
+        $address  = array();
327
+        $prepared = array();
328 328
 
329
-		if ( ! empty( $data[ $type ] ) ) {
330
-			$address = $data[ $type ];
331
-		}
329
+        if ( ! empty( $data[ $type ] ) ) {
330
+            $address = $data[ $type ];
331
+        }
332 332
 
333
-		// Clean address details.
334
-		foreach ( $address as $key => $value ) {
335
-			$key             = sanitize_key( $key );
336
-			$key             = str_replace( 'wpinv_', '', $key );
337
-			$value           = wpinv_clean( $value );
338
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
339
-		}
333
+        // Clean address details.
334
+        foreach ( $address as $key => $value ) {
335
+            $key             = sanitize_key( $key );
336
+            $key             = str_replace( 'wpinv_', '', $key );
337
+            $value           = wpinv_clean( $value );
338
+            $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
339
+        }
340 340
 
341
-		// Filter address details.
342
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
341
+        // Filter address details.
342
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
343 343
 
344
-		// Remove non-whitelisted values.
345
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
344
+        // Remove non-whitelisted values.
345
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
346 346
 
347
-	}
347
+    }
348 348
 
349
-	/**
349
+    /**
350 350
      * Prepares the billing details.
351 351
      *
352
-	 * @return array
353
-	 * @param WPInv_Invoice $invoice
352
+     * @return array
353
+     * @param WPInv_Invoice $invoice
354 354
      */
355 355
     protected function prepare_billing_info( &$invoice ) {
356 356
 
357
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
357
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
358 358
 
359
-		// Update the invoice with the billing details.
360
-		$invoice->set_props( $billing_address );
359
+        // Update the invoice with the billing details.
360
+        $invoice->set_props( $billing_address );
361 361
 
362
-	}
362
+    }
363 363
 
364
-	/**
364
+    /**
365 365
      * Prepares the shipping details.
366 366
      *
367
-	 * @return array
368
-	 * @param WPInv_Invoice $invoice
367
+     * @return array
368
+     * @param WPInv_Invoice $invoice
369 369
      */
370 370
     protected function prepare_shipping_info( $invoice ) {
371 371
 
372
-		$data = $this->payment_form_submission->get_data();
372
+        $data = $this->payment_form_submission->get_data();
373 373
 
374
-		if ( empty( $data['same-shipping-address'] ) ) {
375
-			return $this->prepare_address_details( $invoice, 'shipping' );
376
-		}
374
+        if ( empty( $data['same-shipping-address'] ) ) {
375
+            return $this->prepare_address_details( $invoice, 'shipping' );
376
+        }
377 377
 
378
-		return $this->prepare_address_details( $invoice, 'billing' );
378
+        return $this->prepare_address_details( $invoice, 'billing' );
379 379
 
380
-	}
380
+    }
381 381
 
382
-	/**
383
-	 * Confirms the submission is valid and send users to the gateway.
384
-	 *
385
-	 * @param WPInv_Invoice $invoice
386
-	 * @param array $prepared_payment_form_data
387
-	 * @param array $shipping
388
-	 */
389
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
382
+    /**
383
+     * Confirms the submission is valid and send users to the gateway.
384
+     *
385
+     * @param WPInv_Invoice $invoice
386
+     * @param array $prepared_payment_form_data
387
+     * @param array $shipping
388
+     */
389
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
390 390
 
391
-		// Ensure the invoice exists.
391
+        // Ensure the invoice exists.
392 392
         if ( ! $invoice->exists() ) {
393 393
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
394 394
         }
395 395
 
396
-		// Save payment form data.
397
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
396
+        // Save payment form data.
397
+        $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
398 398
         delete_post_meta( $invoice->get_id(), 'payment_form_data' );
399
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
400
-		if ( ! empty( $prepared_payment_form_data ) ) {
399
+        delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
400
+        if ( ! empty( $prepared_payment_form_data ) ) {
401 401
 
402
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
403
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
404
-			}
402
+            if ( ! empty( $prepared_payment_form_data['all'] ) ) {
403
+                update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
404
+            }
405 405
 
406
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
407
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
408
-			}
406
+            if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
407
+                update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
408
+            }
409 409
 
410
-		}
410
+        }
411 411
 
412
-		// Save payment form data.
413
-		$shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
412
+        // Save payment form data.
413
+        $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
414 414
         if ( ! empty( $shipping ) ) {
415 415
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
416
-		}
416
+        }
417 417
 
418
-		// Backwards compatibility.
418
+        // Backwards compatibility.
419 419
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
420 420
 
421
-		$this->process_payment( $invoice );
421
+        $this->process_payment( $invoice );
422 422
 
423 423
         // If we are here, there was an error.
424
-		wpinv_send_back_to_checkout( $invoice );
424
+        wpinv_send_back_to_checkout( $invoice );
425 425
 
426
-	}
426
+    }
427 427
 
428
-	/**
429
-	 * Processes the actual payment.
430
-	 *
431
-	 * @param WPInv_Invoice $invoice
432
-	 */
433
-	protected function process_payment( $invoice ) {
428
+    /**
429
+     * Processes the actual payment.
430
+     *
431
+     * @param WPInv_Invoice $invoice
432
+     */
433
+    protected function process_payment( $invoice ) {
434 434
 
435
-		// Clear any checkout errors.
436
-		wpinv_clear_errors();
435
+        // Clear any checkout errors.
436
+        wpinv_clear_errors();
437 437
 
438
-		// No need to send free invoices to the gateway.
439
-		if ( $invoice->is_free() ) {
440
-			$this->process_free_payment( $invoice );
441
-		}
438
+        // No need to send free invoices to the gateway.
439
+        if ( $invoice->is_free() ) {
440
+            $this->process_free_payment( $invoice );
441
+        }
442 442
 
443
-		$submission = $this->payment_form_submission;
443
+        $submission = $this->payment_form_submission;
444 444
 
445
-		// Fires before sending to the gateway.
446
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
445
+        // Fires before sending to the gateway.
446
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
447 447
 
448
-		// Allow the sumission data to be modified before it is sent to the gateway.
449
-		$submission_data    = $submission->get_data();
450
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
451
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
448
+        // Allow the sumission data to be modified before it is sent to the gateway.
449
+        $submission_data    = $submission->get_data();
450
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
451
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
452 452
 
453
-		// Validate the currency.
454
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
455
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
456
-		}
453
+        // Validate the currency.
454
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
455
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
456
+        }
457 457
 
458
-		// Check to see if we have any errors.
459
-		if ( wpinv_get_errors() ) {
460
-			wpinv_send_back_to_checkout( $invoice );
461
-		}
458
+        // Check to see if we have any errors.
459
+        if ( wpinv_get_errors() ) {
460
+            wpinv_send_back_to_checkout( $invoice );
461
+        }
462 462
 
463
-		// Send info to the gateway for payment processing
464
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
463
+        // Send info to the gateway for payment processing
464
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
465 465
 
466
-		// Backwards compatibility.
467
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
466
+        // Backwards compatibility.
467
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
468 468
 
469
-	}
469
+    }
470 470
 
471
-	/**
472
-	 * Marks the invoice as paid in case the checkout is free.
473
-	 *
474
-	 * @param WPInv_Invoice $invoice
475
-	 */
476
-	protected function process_free_payment( $invoice ) {
471
+    /**
472
+     * Marks the invoice as paid in case the checkout is free.
473
+     *
474
+     * @param WPInv_Invoice $invoice
475
+     */
476
+    protected function process_free_payment( $invoice ) {
477 477
 
478
-		$invoice->set_gateway( 'none' );
479
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
480
-		$invoice->mark_paid();
481
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
478
+        $invoice->set_gateway( 'none' );
479
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
480
+        $invoice->mark_paid();
481
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
482 482
 
483
-	}
483
+    }
484 484
 
485
-	/**
485
+    /**
486 486
      * Sends a redrect response to payment details.
487 487
      *
488 488
      */
Please login to merge, or discard this patch.
Spacing   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,33 +146,33 @@  discard block
 block discarded – undo
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_payment_form( absint( $submission->get_payment_form()->get_id() ) );
157
-        $invoice->set_items( $items );
158
-        $invoice->set_fees( $submission->get_fees() );
159
-        $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
-		$invoice->set_currency( $submission->get_currency() );
163
-
164
-		if ( $submission->has_shipping() ) {
165
-			$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_payment_form(absint($submission->get_payment_form()->get_id()));
157
+        $invoice->set_items($items);
158
+        $invoice->set_fees($submission->get_fees());
159
+        $invoice->set_taxes($submission->get_taxes());
160
+		$invoice->set_discounts($submission->get_discounts());
161
+		$invoice->set_gateway($submission->get_field('wpi-gateway'));
162
+		$invoice->set_currency($submission->get_currency());
163
+
164
+		if ($submission->has_shipping()) {
165
+			$invoice->set_shipping($submission->get_shipping());
166 166
 		}
167 167
 
168
-		$address_confirmed = $submission->get_field( 'confirm-address' );
169
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
168
+		$address_confirmed = $submission->get_field('confirm-address');
169
+		$invoice->set_address_confirmed(!empty($address_confirmed));
170 170
 
171
-		if ( $submission->has_discount_code() ) {
172
-            $invoice->set_discount_code( $submission->get_discount_code() );
171
+		if ($submission->has_discount_code()) {
172
+            $invoice->set_discount_code($submission->get_discount_code());
173 173
 		}
174 174
 
175
-		getpaid_maybe_add_default_address( $invoice );
175
+		getpaid_maybe_add_default_address($invoice);
176 176
 		return $invoice;
177 177
 	}
178 178
 
@@ -185,33 +185,33 @@  discard block
 block discarded – undo
185 185
 		$submission = $this->payment_form_submission;
186 186
 
187 187
 		// If this is an existing invoice...
188
-		if ( $submission->has_invoice() ) {
188
+		if ($submission->has_invoice()) {
189 189
 			return $submission->get_invoice()->get_user_id();
190 190
 		}
191 191
 
192 192
 		// (Maybe) create the user.
193 193
         $user = get_current_user_id();
194 194
 
195
-        if ( empty( $user ) ) {
196
-            $user = get_user_by( 'email', $submission->get_billing_email() );
195
+        if (empty($user)) {
196
+            $user = get_user_by('email', $submission->get_billing_email());
197 197
         }
198 198
 
199
-        if ( empty( $user ) ) {
200
-            $user = wpinv_create_user( $submission->get_billing_email() );
199
+        if (empty($user)) {
200
+            $user = wpinv_create_user($submission->get_billing_email());
201 201
 
202 202
 			// (Maybe) send new user notification.
203
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
204
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
205
-				wp_send_new_user_notifications( $user, 'user' );
203
+			$should_send_notification = wpinv_get_option('disable_new_user_emails');
204
+			if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification), $user)) {
205
+				wp_send_new_user_notifications($user, 'user');
206 206
 			}
207 207
 
208 208
         }
209 209
 
210
-        if ( is_wp_error( $user ) ) {
211
-            wp_send_json_error( $user->get_error_message() );
210
+        if (is_wp_error($user)) {
211
+            wp_send_json_error($user->get_error_message());
212 212
         }
213 213
 
214
-        if ( is_numeric( $user ) ) {
214
+        if (is_numeric($user)) {
215 215
             return $user;
216 216
 		}
217 217
 
@@ -235,24 +235,24 @@  discard block
 block discarded – undo
235 235
 		);
236 236
 
237 237
         // Raw submission details.
238
-		$data     = $submission->get_data();
238
+		$data = $submission->get_data();
239 239
 
240 240
 		// Loop through the submitted details.
241
-        foreach ( $submission->get_payment_form()->get_elements() as $field ) {
241
+        foreach ($submission->get_payment_form()->get_elements() as $field) {
242 242
 
243 243
 			// Skip premade fields.
244
-            if ( ! empty( $field['premade'] ) ) {
244
+            if (!empty($field['premade'])) {
245 245
                 continue;
246 246
             }
247 247
 
248 248
 			// Ensure address is provided.
249
-			if ( $field['type'] == 'address' ) {
250
-                $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
249
+			if ($field['type'] == 'address') {
250
+                $address_type = isset($field['address_type']) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
251 251
 
252
-				foreach ( $field['fields'] as $address_field ) {
252
+				foreach ($field['fields'] as $address_field) {
253 253
 
254
-					if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
255
-						wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
254
+					if (!empty($address_field['visible']) && !empty($address_field['required']) && '' === trim($_POST[$address_type][$address_field['name']])) {
255
+						wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
256 256
 					}
257 257
 
258 258
 				}
@@ -260,49 +260,49 @@  discard block
 block discarded – undo
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 ( $field['type'] == 'file_upload' ) {
272
-					$max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
271
+				if ($field['type'] == 'file_upload') {
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
-				} else if ( $field['type'] == 'checkbox' ) {
291
-					$value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
290
+				} else if ($field['type'] == 'checkbox') {
291
+					$value = isset($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
 
@@ -319,30 +319,30 @@  discard block
 block discarded – undo
319 319
 	 * @param WPInv_Invoice $invoice
320 320
 	 * @param string $type
321 321
      */
322
-    public function prepare_address_details( $invoice, $type = 'billing' ) {
322
+    public function prepare_address_details($invoice, $type = 'billing') {
323 323
 
324 324
 		$data     = $this->payment_form_submission->get_data();
325
-		$type     = sanitize_key( $type );
325
+		$type     = sanitize_key($type);
326 326
 		$address  = array();
327 327
 		$prepared = array();
328 328
 
329
-		if ( ! empty( $data[ $type ] ) ) {
330
-			$address = $data[ $type ];
329
+		if (!empty($data[$type])) {
330
+			$address = $data[$type];
331 331
 		}
332 332
 
333 333
 		// Clean address details.
334
-		foreach ( $address as $key => $value ) {
335
-			$key             = sanitize_key( $key );
336
-			$key             = str_replace( 'wpinv_', '', $key );
337
-			$value           = wpinv_clean( $value );
338
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
334
+		foreach ($address as $key => $value) {
335
+			$key             = sanitize_key($key);
336
+			$key             = str_replace('wpinv_', '', $key);
337
+			$value           = wpinv_clean($value);
338
+			$prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice);
339 339
 		}
340 340
 
341 341
 		// Filter address details.
342
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
342
+		$prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice);
343 343
 
344 344
 		// Remove non-whitelisted values.
345
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
345
+		return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY);
346 346
 
347 347
 	}
348 348
 
@@ -352,12 +352,12 @@  discard block
 block discarded – undo
352 352
 	 * @return array
353 353
 	 * @param WPInv_Invoice $invoice
354 354
      */
355
-    protected function prepare_billing_info( &$invoice ) {
355
+    protected function prepare_billing_info(&$invoice) {
356 356
 
357
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
357
+		$billing_address = $this->prepare_address_details($invoice, 'billing');
358 358
 
359 359
 		// Update the invoice with the billing details.
360
-		$invoice->set_props( $billing_address );
360
+		$invoice->set_props($billing_address);
361 361
 
362 362
 	}
363 363
 
@@ -367,15 +367,15 @@  discard block
 block discarded – undo
367 367
 	 * @return array
368 368
 	 * @param WPInv_Invoice $invoice
369 369
      */
370
-    protected function prepare_shipping_info( $invoice ) {
370
+    protected function prepare_shipping_info($invoice) {
371 371
 
372 372
 		$data = $this->payment_form_submission->get_data();
373 373
 
374
-		if ( empty( $data['same-shipping-address'] ) ) {
375
-			return $this->prepare_address_details( $invoice, 'shipping' );
374
+		if (empty($data['same-shipping-address'])) {
375
+			return $this->prepare_address_details($invoice, 'shipping');
376 376
 		}
377 377
 
378
-		return $this->prepare_address_details( $invoice, 'billing' );
378
+		return $this->prepare_address_details($invoice, 'billing');
379 379
 
380 380
 	}
381 381
 
@@ -386,42 +386,42 @@  discard block
 block discarded – undo
386 386
 	 * @param array $prepared_payment_form_data
387 387
 	 * @param array $shipping
388 388
 	 */
389
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
389
+	protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) {
390 390
 
391 391
 		// Ensure the invoice exists.
392
-        if ( ! $invoice->exists() ) {
393
-            wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
392
+        if (!$invoice->exists()) {
393
+            wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing'));
394 394
         }
395 395
 
396 396
 		// Save payment form data.
397
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
398
-        delete_post_meta( $invoice->get_id(), 'payment_form_data' );
399
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
400
-		if ( ! empty( $prepared_payment_form_data ) ) {
397
+		$prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice);
398
+        delete_post_meta($invoice->get_id(), 'payment_form_data');
399
+		delete_post_meta($invoice->get_id(), 'additional_meta_data');
400
+		if (!empty($prepared_payment_form_data)) {
401 401
 
402
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
403
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
402
+			if (!empty($prepared_payment_form_data['all'])) {
403
+				update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']);
404 404
 			}
405 405
 
406
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
407
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
406
+			if (!empty($prepared_payment_form_data['meta'])) {
407
+				update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']);
408 408
 			}
409 409
 
410 410
 		}
411 411
 
412 412
 		// Save payment form data.
413
-		$shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
414
-        if ( ! empty( $shipping ) ) {
415
-            update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
413
+		$shipping = apply_filters('getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission);
414
+        if (!empty($shipping)) {
415
+            update_post_meta($invoice->get_id(), 'shipping_address', $shipping);
416 416
 		}
417 417
 
418 418
 		// Backwards compatibility.
419
-        add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
419
+        add_filter('wp_redirect', array($this, 'send_redirect_response'));
420 420
 
421
-		$this->process_payment( $invoice );
421
+		$this->process_payment($invoice);
422 422
 
423 423
         // If we are here, there was an error.
424
-		wpinv_send_back_to_checkout( $invoice );
424
+		wpinv_send_back_to_checkout($invoice);
425 425
 
426 426
 	}
427 427
 
@@ -430,41 +430,41 @@  discard block
 block discarded – undo
430 430
 	 *
431 431
 	 * @param WPInv_Invoice $invoice
432 432
 	 */
433
-	protected function process_payment( $invoice ) {
433
+	protected function process_payment($invoice) {
434 434
 
435 435
 		// Clear any checkout errors.
436 436
 		wpinv_clear_errors();
437 437
 
438 438
 		// No need to send free invoices to the gateway.
439
-		if ( $invoice->is_free() ) {
440
-			$this->process_free_payment( $invoice );
439
+		if ($invoice->is_free()) {
440
+			$this->process_free_payment($invoice);
441 441
 		}
442 442
 
443 443
 		$submission = $this->payment_form_submission;
444 444
 
445 445
 		// Fires before sending to the gateway.
446
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
446
+		do_action('getpaid_checkout_before_gateway', $invoice, $submission);
447 447
 
448 448
 		// Allow the sumission data to be modified before it is sent to the gateway.
449 449
 		$submission_data    = $submission->get_data();
450
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
451
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
450
+		$submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice);
451
+		$submission_data    = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice);
452 452
 
453 453
 		// Validate the currency.
454
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
455
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
454
+		if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) {
455
+			wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support this currency', 'invoicing'));
456 456
 		}
457 457
 
458 458
 		// Check to see if we have any errors.
459
-		if ( wpinv_get_errors() ) {
460
-			wpinv_send_back_to_checkout( $invoice );
459
+		if (wpinv_get_errors()) {
460
+			wpinv_send_back_to_checkout($invoice);
461 461
 		}
462 462
 
463 463
 		// Send info to the gateway for payment processing
464
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
464
+		do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission);
465 465
 
466 466
 		// Backwards compatibility.
467
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
467
+		wpinv_send_to_gateway($submission_gateway, $invoice);
468 468
 
469 469
 	}
470 470
 
@@ -473,12 +473,12 @@  discard block
 block discarded – undo
473 473
 	 *
474 474
 	 * @param WPInv_Invoice $invoice
475 475
 	 */
476
-	protected function process_free_payment( $invoice ) {
476
+	protected function process_free_payment($invoice) {
477 477
 
478
-		$invoice->set_gateway( 'none' );
479
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
478
+		$invoice->set_gateway('none');
479
+		$invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true);
480 480
 		$invoice->mark_paid();
481
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
481
+		wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
482 482
 
483 483
 	}
484 484
 
@@ -486,9 +486,9 @@  discard block
 block discarded – undo
486 486
      * Sends a redrect response to payment details.
487 487
      *
488 488
      */
489
-    public function send_redirect_response( $url ) {
490
-        $url = urlencode( $url );
491
-        wp_send_json_success( $url );
489
+    public function send_redirect_response($url) {
490
+        $url = urlencode($url);
491
+        wp_send_json_success($url);
492 492
     }
493 493
 
494 494
 }
Please login to merge, or discard this patch.
invoicing.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,16 +19,16 @@  discard block
 block discarded – undo
19 19
 
20 20
 // Define constants.
21 21
 if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) {
22
-	define( 'WPINV_PLUGIN_FILE', __FILE__ );
22
+    define( 'WPINV_PLUGIN_FILE', __FILE__ );
23 23
 }
24 24
 
25 25
 if ( ! defined( 'WPINV_VERSION' ) ) {
26
-	define( 'WPINV_VERSION', '2.5.10' );
26
+    define( 'WPINV_VERSION', '2.5.10' );
27 27
 }
28 28
 
29 29
 // Include the main Invoicing class.
30 30
 if ( ! class_exists( 'WPInv_Plugin', false ) ) {
31
-	require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
31
+    require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
32 32
 }
33 33
 
34 34
 /**
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
         $GLOBALS['invoicing'] = new WPInv_Plugin();
44 44
     }
45 45
 
46
-	return $GLOBALS['invoicing'];
46
+    return $GLOBALS['invoicing'];
47 47
 }
48 48
 
49 49
 /**
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -15,20 +15,20 @@  discard block
 block discarded – undo
15 15
  * @package GetPaid
16 16
  */
17 17
 
18
-defined( 'ABSPATH' ) || exit;
18
+defined('ABSPATH') || exit;
19 19
 
20 20
 // Define constants.
21
-if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) {
22
-	define( 'WPINV_PLUGIN_FILE', __FILE__ );
21
+if (!defined('WPINV_PLUGIN_FILE')) {
22
+	define('WPINV_PLUGIN_FILE', __FILE__);
23 23
 }
24 24
 
25
-if ( ! defined( 'WPINV_VERSION' ) ) {
26
-	define( 'WPINV_VERSION', '2.5.10' );
25
+if (!defined('WPINV_VERSION')) {
26
+	define('WPINV_VERSION', '2.5.10');
27 27
 }
28 28
 
29 29
 // Include the main Invoicing class.
30
-if ( ! class_exists( 'WPInv_Plugin', false ) ) {
31
-	require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
30
+if (!class_exists('WPInv_Plugin', false)) {
31
+	require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/class-wpinv.php';
32 32
 }
33 33
 
34 34
 /**
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
  */
40 40
 function getpaid() {
41 41
 
42
-    if ( empty( $GLOBALS['invoicing'] ) ) {
42
+    if (empty($GLOBALS['invoicing'])) {
43 43
         $GLOBALS['invoicing'] = new WPInv_Plugin();
44 44
     }
45 45
 
@@ -52,9 +52,9 @@  discard block
 block discarded – undo
52 52
  * @since  2.0.8
53 53
  */
54 54
 function getpaid_deactivation_hook() {
55
-    update_option( 'wpinv_flush_permalinks', 1 );
55
+    update_option('wpinv_flush_permalinks', 1);
56 56
 }
57
-register_deactivation_hook( __FILE__, 'getpaid_deactivation_hook' );
57
+register_deactivation_hook(__FILE__, 'getpaid_deactivation_hook');
58 58
 
59 59
 /**
60 60
  * @deprecated
@@ -64,4 +64,4 @@  discard block
 block discarded – undo
64 64
 }
65 65
 
66 66
 // Kickstart the plugin.
67
-add_action( 'plugins_loaded', 'getpaid', -100 );
67
+add_action('plugins_loaded', 'getpaid', -100);
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway-ipn-handler.php 2 patches
Indentation   +390 added lines, -390 removed lines patch added patch discarded remove patch
@@ -12,474 +12,474 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Paypal_Gateway_IPN_Handler {
14 14
 
15
-	/**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
20
-	protected $id = 'paypal';
21
-
22
-	/**
23
-	 * Payment method object.
24
-	 *
25
-	 * @var GetPaid_Paypal_Gateway
26
-	 */
27
-	protected $gateway;
28
-
29
-	/**
30
-	 * Class constructor.
31
-	 *
32
-	 * @param GetPaid_Paypal_Gateway $gateway
33
-	 */
34
-	public function __construct( $gateway ) {
35
-		$this->gateway = $gateway;
36
-		$this->verify_ipn();
37
-	}
38
-
39
-	/**
40
-	 * Processes ipns and marks payments as complete.
41
-	 *
42
-	 * @return void
43
-	 */
44
-	public function verify_ipn() {
45
-
46
-		wpinv_error_log( 'GetPaid PayPal IPN Handler', false );
47
-
48
-		// Validate the IPN.
49
-		if ( empty( $_POST ) || ! $this->validate_ipn() ) {
50
-			wp_die( 'PayPal IPN Request Failure', 500 );
51
-		}
52
-
53
-		// Process the IPN.
54
-		$posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
55
-		$invoice = $this->get_ipn_invoice( $posted );
56
-
57
-		// Abort if it was not paid by our gateway.
58
-		if ( $this->id != $invoice->get_gateway() ) {
59
-			wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false );
60
-			wp_die( 'Invoice not paid via PayPal', 200 );
61
-		}
62
-
63
-		$posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : '';
64
-		$posted['txn_type']       = sanitize_key( strtolower( $posted['txn_type'] ) );
65
-
66
-		wpinv_error_log( 'Payment status:' . $posted['payment_status'], false );
67
-		wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false );
68
-
69
-		if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) {
70
-			call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted );
71
-			wpinv_error_log( 'Done processing IPN', false );
72
-			wp_die( 'Processed', 200 );
73
-		}
74
-
75
-		wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false );
76
-		wp_die( 'Unsupported IPN type', 200 );
77
-
78
-	}
79
-
80
-	/**
81
-	 * Retrieves IPN Invoice.
82
-	 *
83
-	 * @param array $posted
84
-	 * @return WPInv_Invoice
85
-	 */
86
-	protected function get_ipn_invoice( $posted ) {
87
-
88
-		wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false );
89
-
90
-		if ( ! empty( $posted['custom'] ) ) {
91
-			$invoice = new WPInv_Invoice( $posted['custom'] );
92
-
93
-			if ( $invoice->exists() ) {
94
-				wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false );
95
-				return $invoice;
96
-			}
97
-
98
-		}
99
-
100
-		wpinv_error_log( 'Could not retrieve the associated invoice.', false );
101
-		wp_die( 'Could not retrieve the associated invoice.', 200 );
102
-	}
103
-
104
-	/**
105
-	 * Check PayPal IPN validity.
106
-	 */
107
-	protected function validate_ipn() {
108
-
109
-		wpinv_error_log( 'Validating PayPal IPN response', false );
110
-
111
-		// Retrieve the associated invoice.
112
-		$posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
113
-		$invoice = $this->get_ipn_invoice( $posted );
114
-
115
-		if ( $this->gateway->is_sandbox( $invoice ) ) {
116
-			wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false );
117
-		}
118
-
119
-		// Validate the IPN.
120
-		$posted['cmd'] = '_notify-validate';
121
-
122
-		// Send back post vars to paypal.
123
-		$params = array(
124
-			'body'        => $posted,
125
-			'timeout'     => 60,
126
-			'httpversion' => '1.1',
127
-			'compress'    => false,
128
-			'decompress'  => false,
129
-			'user-agent'  => 'GetPaid/' . WPINV_VERSION,
130
-		);
131
-
132
-		// Post back to get a response.
133
-		$response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params );
134
-
135
-		// Check to see if the request was valid.
136
-		if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) {
137
-			wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false );
138
-			return true;
139
-		}
140
-
141
-		if ( is_wp_error( $response ) ) {
142
-			wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' );
143
-			return false;
144
-		}
15
+    /**
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20
+    protected $id = 'paypal';
21
+
22
+    /**
23
+     * Payment method object.
24
+     *
25
+     * @var GetPaid_Paypal_Gateway
26
+     */
27
+    protected $gateway;
28
+
29
+    /**
30
+     * Class constructor.
31
+     *
32
+     * @param GetPaid_Paypal_Gateway $gateway
33
+     */
34
+    public function __construct( $gateway ) {
35
+        $this->gateway = $gateway;
36
+        $this->verify_ipn();
37
+    }
38
+
39
+    /**
40
+     * Processes ipns and marks payments as complete.
41
+     *
42
+     * @return void
43
+     */
44
+    public function verify_ipn() {
45
+
46
+        wpinv_error_log( 'GetPaid PayPal IPN Handler', false );
47
+
48
+        // Validate the IPN.
49
+        if ( empty( $_POST ) || ! $this->validate_ipn() ) {
50
+            wp_die( 'PayPal IPN Request Failure', 500 );
51
+        }
52
+
53
+        // Process the IPN.
54
+        $posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
55
+        $invoice = $this->get_ipn_invoice( $posted );
56
+
57
+        // Abort if it was not paid by our gateway.
58
+        if ( $this->id != $invoice->get_gateway() ) {
59
+            wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false );
60
+            wp_die( 'Invoice not paid via PayPal', 200 );
61
+        }
62
+
63
+        $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : '';
64
+        $posted['txn_type']       = sanitize_key( strtolower( $posted['txn_type'] ) );
65
+
66
+        wpinv_error_log( 'Payment status:' . $posted['payment_status'], false );
67
+        wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false );
68
+
69
+        if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) {
70
+            call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted );
71
+            wpinv_error_log( 'Done processing IPN', false );
72
+            wp_die( 'Processed', 200 );
73
+        }
74
+
75
+        wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false );
76
+        wp_die( 'Unsupported IPN type', 200 );
77
+
78
+    }
79
+
80
+    /**
81
+     * Retrieves IPN Invoice.
82
+     *
83
+     * @param array $posted
84
+     * @return WPInv_Invoice
85
+     */
86
+    protected function get_ipn_invoice( $posted ) {
87
+
88
+        wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false );
89
+
90
+        if ( ! empty( $posted['custom'] ) ) {
91
+            $invoice = new WPInv_Invoice( $posted['custom'] );
92
+
93
+            if ( $invoice->exists() ) {
94
+                wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false );
95
+                return $invoice;
96
+            }
97
+
98
+        }
99
+
100
+        wpinv_error_log( 'Could not retrieve the associated invoice.', false );
101
+        wp_die( 'Could not retrieve the associated invoice.', 200 );
102
+    }
103
+
104
+    /**
105
+     * Check PayPal IPN validity.
106
+     */
107
+    protected function validate_ipn() {
108
+
109
+        wpinv_error_log( 'Validating PayPal IPN response', false );
110
+
111
+        // Retrieve the associated invoice.
112
+        $posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
113
+        $invoice = $this->get_ipn_invoice( $posted );
114
+
115
+        if ( $this->gateway->is_sandbox( $invoice ) ) {
116
+            wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false );
117
+        }
118
+
119
+        // Validate the IPN.
120
+        $posted['cmd'] = '_notify-validate';
121
+
122
+        // Send back post vars to paypal.
123
+        $params = array(
124
+            'body'        => $posted,
125
+            'timeout'     => 60,
126
+            'httpversion' => '1.1',
127
+            'compress'    => false,
128
+            'decompress'  => false,
129
+            'user-agent'  => 'GetPaid/' . WPINV_VERSION,
130
+        );
131
+
132
+        // Post back to get a response.
133
+        $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params );
134
+
135
+        // Check to see if the request was valid.
136
+        if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) {
137
+            wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false );
138
+            return true;
139
+        }
140
+
141
+        if ( is_wp_error( $response ) ) {
142
+            wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' );
143
+            return false;
144
+        }
145 145
 
146
-		wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' );
147
-		return false;
148
-
149
-	}
146
+        wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' );
147
+        return false;
148
+
149
+    }
150 150
 
151
-	/**
152
-	 * Check currency from IPN matches the invoice.
153
-	 *
154
-	 * @param WPInv_Invoice $invoice          Invoice object.
155
-	 * @param string   $currency currency to validate.
156
-	 */
157
-	protected function validate_ipn_currency( $invoice, $currency ) {
151
+    /**
152
+     * Check currency from IPN matches the invoice.
153
+     *
154
+     * @param WPInv_Invoice $invoice          Invoice object.
155
+     * @param string   $currency currency to validate.
156
+     */
157
+    protected function validate_ipn_currency( $invoice, $currency ) {
158 158
 
159
-		if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) {
159
+        if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) {
160 160
 
161
-			/* translators: %s: currency code. */
162
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) );
161
+            /* translators: %s: currency code. */
162
+            $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) );
163 163
 
164
-			wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true );
165
-		}
164
+            wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true );
165
+        }
166 166
 
167
-		wpinv_error_log( $currency, 'Validated IPN Currency', false );
168
-	}
167
+        wpinv_error_log( $currency, 'Validated IPN Currency', false );
168
+    }
169 169
 
170
-	/**
171
-	 * Check payment amount from IPN matches the invoice.
172
-	 *
173
-	 * @param WPInv_Invoice $invoice          Invoice object.
174
-	 * @param float   $amount amount to validate.
175
-	 */
176
-	protected function validate_ipn_amount( $invoice, $amount ) {
177
-		if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) {
170
+    /**
171
+     * Check payment amount from IPN matches the invoice.
172
+     *
173
+     * @param WPInv_Invoice $invoice          Invoice object.
174
+     * @param float   $amount amount to validate.
175
+     */
176
+    protected function validate_ipn_amount( $invoice, $amount ) {
177
+        if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) {
178 178
 
179
-			/* translators: %s: Amount. */
180
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) );
179
+            /* translators: %s: Amount. */
180
+            $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) );
181 181
 
182
-			wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true );
183
-		}
182
+            wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true );
183
+        }
184 184
 
185
-		wpinv_error_log( $amount, 'Validated IPN Amount', false );
186
-	}
185
+        wpinv_error_log( $amount, 'Validated IPN Amount', false );
186
+    }
187 187
 
188
-	/**
189
-	 * Verify receiver email from PayPal.
190
-	 *
191
-	 * @param WPInv_Invoice $invoice          Invoice object.
192
-	 * @param string   $receiver_email Email to validate.
193
-	 */
194
-	protected function validate_ipn_receiver_email( $invoice, $receiver_email ) {
195
-		$paypal_email = wpinv_get_option( 'paypal_email' );
188
+    /**
189
+     * Verify receiver email from PayPal.
190
+     *
191
+     * @param WPInv_Invoice $invoice          Invoice object.
192
+     * @param string   $receiver_email Email to validate.
193
+     */
194
+    protected function validate_ipn_receiver_email( $invoice, $receiver_email ) {
195
+        $paypal_email = wpinv_get_option( 'paypal_email' );
196 196
 
197
-		if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) {
198
-			wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" );
197
+        if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) {
198
+            wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" );
199 199
 
200
-			/* translators: %s: email address . */
201
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) );
200
+            /* translators: %s: email address . */
201
+            $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) );
202 202
 
203
-			return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true );
204
-		}
203
+            return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true );
204
+        }
205 205
 
206
-		wpinv_error_log( 'Validated PayPal Email', false );
207
-	}
206
+        wpinv_error_log( 'Validated PayPal Email', false );
207
+    }
208 208
 
209
-	/**
210
-	 * Handles one time payments.
211
-	 *
212
-	 * @param WPInv_Invoice $invoice  Invoice object.
213
-	 * @param array    $posted Posted data.
214
-	 */
215
-	protected function ipn_txn_web_accept( $invoice, $posted ) {
209
+    /**
210
+     * Handles one time payments.
211
+     *
212
+     * @param WPInv_Invoice $invoice  Invoice object.
213
+     * @param array    $posted Posted data.
214
+     */
215
+    protected function ipn_txn_web_accept( $invoice, $posted ) {
216 216
 
217
-		// Collect payment details
218
-		$payment_status = strtolower( $posted['payment_status'] );
219
-		$business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
217
+        // Collect payment details
218
+        $payment_status = strtolower( $posted['payment_status'] );
219
+        $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
220 220
 
221
-		$this->validate_ipn_receiver_email( $invoice, $business_email );
222
-		$this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
221
+        $this->validate_ipn_receiver_email( $invoice, $business_email );
222
+        $this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
223 223
 
224
-		// Update the transaction id.
225
-		if ( ! empty( $posted['txn_id'] ) ) {
226
-			$invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) );
227
-			$invoice->save();
228
-		}
224
+        // Update the transaction id.
225
+        if ( ! empty( $posted['txn_id'] ) ) {
226
+            $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) );
227
+            $invoice->save();
228
+        }
229 229
 
230
-		$invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) );
230
+        $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) );
231 231
 
232
-		// Process a refund.
233
-		if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
232
+        // Process a refund.
233
+        if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
234 234
 
235
-			update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 );
235
+            update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 );
236 236
 
237
-			if ( ! $invoice->is_refunded() ) {
238
-				$invoice->update_status( 'wpi-refunded', $posted['reason_code'] );
239
-			}
237
+            if ( ! $invoice->is_refunded() ) {
238
+                $invoice->update_status( 'wpi-refunded', $posted['reason_code'] );
239
+            }
240 240
 
241
-			return wpinv_error_log( $posted['reason_code'], false );
242
-		}
241
+            return wpinv_error_log( $posted['reason_code'], false );
242
+        }
243 243
 
244
-		// Process payments.
245
-		if ( $payment_status == 'completed' ) {
244
+        // Process payments.
245
+        if ( $payment_status == 'completed' ) {
246 246
 
247
-			if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) {
248
-				return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false );
249
-			}
247
+            if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) {
248
+                return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false );
249
+            }
250 250
 
251
-			$this->validate_ipn_amount( $invoice, $posted['mc_gross'] );
251
+            $this->validate_ipn_amount( $invoice, $posted['mc_gross'] );
252 252
 
253
-			$note = '';
253
+            $note = '';
254 254
 
255
-			if ( ! empty( $posted['mc_fee'] ) ) {
256
-				$note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) );
257
-			}
255
+            if ( ! empty( $posted['mc_fee'] ) ) {
256
+                $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) );
257
+            }
258 258
 
259
-			if ( ! empty( $posted['payer_status'] ) ) {
260
-				$note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) );
261
-			}
259
+            if ( ! empty( $posted['payer_status'] ) ) {
260
+                $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) );
261
+            }
262 262
 
263
-			$invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) );
264
-			return wpinv_error_log( 'Invoice marked as paid.', false );
263
+            $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) );
264
+            return wpinv_error_log( 'Invoice marked as paid.', false );
265 265
 
266
-		}
266
+        }
267 267
 
268
-		// Pending payments.
269
-		if ( $payment_status == 'pending' ) {
268
+        // Pending payments.
269
+        if ( $payment_status == 'pending' ) {
270 270
 
271
-			/* translators: %s: pending reason. */
272
-			$invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) );
271
+            /* translators: %s: pending reason. */
272
+            $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) );
273 273
 
274
-			return wpinv_error_log( 'Invoice marked as "payment held".', false );
275
-		}
274
+            return wpinv_error_log( 'Invoice marked as "payment held".', false );
275
+        }
276 276
 
277
-		/* translators: %s: payment status. */
278
-		$invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) );
277
+        /* translators: %s: payment status. */
278
+        $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) );
279 279
 
280
-	}
280
+    }
281 281
 
282
-	/**
283
-	 * Handles one time payments.
284
-	 *
285
-	 * @param WPInv_Invoice $invoice  Invoice object.
286
-	 * @param array    $posted Posted data.
287
-	 */
288
-	protected function ipn_txn_cart( $invoice, $posted ) {
289
-		$this->ipn_txn_web_accept( $invoice, $posted );
290
-	}
282
+    /**
283
+     * Handles one time payments.
284
+     *
285
+     * @param WPInv_Invoice $invoice  Invoice object.
286
+     * @param array    $posted Posted data.
287
+     */
288
+    protected function ipn_txn_cart( $invoice, $posted ) {
289
+        $this->ipn_txn_web_accept( $invoice, $posted );
290
+    }
291 291
 
292
-	/**
293
-	 * Handles subscription sign ups.
294
-	 *
295
-	 * @param WPInv_Invoice $invoice  Invoice object.
296
-	 * @param array    $posted Posted data.
297
-	 */
298
-	protected function ipn_txn_subscr_signup( $invoice, $posted ) {
292
+    /**
293
+     * Handles subscription sign ups.
294
+     *
295
+     * @param WPInv_Invoice $invoice  Invoice object.
296
+     * @param array    $posted Posted data.
297
+     */
298
+    protected function ipn_txn_subscr_signup( $invoice, $posted ) {
299 299
 
300
-		wpinv_error_log( 'Processing subscription signup', false );
300
+        wpinv_error_log( 'Processing subscription signup', false );
301 301
 
302
-		// Make sure the invoice has a subscription.
303
-		$subscription = getpaid_get_invoice_subscription( $invoice );
302
+        // Make sure the invoice has a subscription.
303
+        $subscription = getpaid_get_invoice_subscription( $invoice );
304 304
 
305
-		if ( empty( $subscription ) ) {
306
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
307
-		}
305
+        if ( empty( $subscription ) ) {
306
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
307
+        }
308 308
 
309
-		wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
309
+        wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
310 310
 
311
-		// Validate the IPN.
312
-		$business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
313
-		$this->validate_ipn_receiver_email( $invoice, $business_email );
314
-		$this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
311
+        // Validate the IPN.
312
+        $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
313
+        $this->validate_ipn_receiver_email( $invoice, $business_email );
314
+        $this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
315 315
 
316
-		// Activate the subscription.
317
-		$duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
318
-		$subscription->set_date_created( current_time( 'mysql' ) );
319
-		$subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) );
320
-		$subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) );
321
-		$subscription->activate();
316
+        // Activate the subscription.
317
+        $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
318
+        $subscription->set_date_created( current_time( 'mysql' ) );
319
+        $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) );
320
+        $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) );
321
+        $subscription->activate();
322 322
 
323
-		// Set the transaction id.
324
-		if ( ! empty( $posted['txn_id'] ) ) {
325
-			$invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
326
-			$invoice->set_transaction_id( $posted['txn_id'] );
327
-		}
323
+        // Set the transaction id.
324
+        if ( ! empty( $posted['txn_id'] ) ) {
325
+            $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
326
+            $invoice->set_transaction_id( $posted['txn_id'] );
327
+        }
328 328
 
329
-		// Update the payment status.
330
-		$invoice->mark_paid();
329
+        // Update the payment status.
330
+        $invoice->mark_paid();
331 331
 
332
-		$invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
332
+        $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
333 333
 
334
-		wpinv_error_log( 'Subscription started.', false );
335
-	}
334
+        wpinv_error_log( 'Subscription started.', false );
335
+    }
336 336
 
337
-	/**
338
-	 * Handles subscription renewals.
339
-	 *
340
-	 * @param WPInv_Invoice $invoice  Invoice object.
341
-	 * @param array    $posted Posted data.
342
-	 */
343
-	protected function ipn_txn_subscr_payment( $invoice, $posted ) {
337
+    /**
338
+     * Handles subscription renewals.
339
+     *
340
+     * @param WPInv_Invoice $invoice  Invoice object.
341
+     * @param array    $posted Posted data.
342
+     */
343
+    protected function ipn_txn_subscr_payment( $invoice, $posted ) {
344 344
 
345
-		// Make sure the invoice has a subscription.
346
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
345
+        // Make sure the invoice has a subscription.
346
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
347 347
 
348
-		if ( empty( $subscription ) ) {
349
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
350
-		}
348
+        if ( empty( $subscription ) ) {
349
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
350
+        }
351 351
 
352
-		wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
352
+        wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
353 353
 
354
-		// PayPal sends a subscr_payment for the first payment too.
355
-		$date_completed = getpaid_format_date( $invoice->get_date_completed() );
356
-		$date_created   = getpaid_format_date( $invoice->get_date_created() );
357
-		$today_date     = getpaid_format_date( current_time( 'mysql' ) );
358
-		$payment_date   = getpaid_format_date( $posted['payment_date'] );
359
-		$subscribe_date = getpaid_format_date( $subscription->get_date_created() );
360
-		$dates          = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) );
354
+        // PayPal sends a subscr_payment for the first payment too.
355
+        $date_completed = getpaid_format_date( $invoice->get_date_completed() );
356
+        $date_created   = getpaid_format_date( $invoice->get_date_created() );
357
+        $today_date     = getpaid_format_date( current_time( 'mysql' ) );
358
+        $payment_date   = getpaid_format_date( $posted['payment_date'] );
359
+        $subscribe_date = getpaid_format_date( $subscription->get_date_created() );
360
+        $dates          = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) );
361 361
 
362
-		foreach( $dates as $date ) {
362
+        foreach( $dates as $date ) {
363 363
 
364
-			if ( $date !== $today_date && $date !== $payment_date ) {
365
-				continue;
366
-			}
364
+            if ( $date !== $today_date && $date !== $payment_date ) {
365
+                continue;
366
+            }
367 367
 
368
-			if ( ! empty( $posted['txn_id'] ) ) {
369
-				$invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) );	
370
-				$invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true );
371
-			}
368
+            if ( ! empty( $posted['txn_id'] ) ) {
369
+                $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) );	
370
+                $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true );
371
+            }
372 372
 
373
-			return $invoice->mark_paid();
374
-
375
-		}
373
+            return $invoice->mark_paid();
374
+
375
+        }
376 376
 
377
-		wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false );
378
-
379
-		// Abort if the payment is already recorded.
380
-		if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) {
381
-			return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false );
382
-		}
383
-
384
-		$args = array(
385
-			'transaction_id' => $posted['txn_id'],
386
-			'gateway'        => $this->id,
387
-		);
388
-
389
-		$invoice = wpinv_get_invoice( $subscription->add_payment( $args ) );
377
+        wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false );
378
+
379
+        // Abort if the payment is already recorded.
380
+        if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) {
381
+            return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false );
382
+        }
383
+
384
+        $args = array(
385
+            'transaction_id' => $posted['txn_id'],
386
+            'gateway'        => $this->id,
387
+        );
388
+
389
+        $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) );
390 390
 
391
-		if ( empty( $invoice ) ) {
392
-			return;
393
-		}
391
+        if ( empty( $invoice ) ) {
392
+            return;
393
+        }
394 394
 
395
-		$invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
396
-		$invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
395
+        $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
396
+        $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
397 397
 
398
-		$subscription->renew();
399
-		wpinv_error_log( 'Subscription renewed.', false );
398
+        $subscription->renew();
399
+        wpinv_error_log( 'Subscription renewed.', false );
400 400
 
401
-	}
401
+    }
402 402
 
403
-	/**
404
-	 * Handles subscription cancelations.
405
-	 *
406
-	 * @param WPInv_Invoice $invoice  Invoice object.
407
-	 */
408
-	protected function ipn_txn_subscr_cancel( $invoice ) {
403
+    /**
404
+     * Handles subscription cancelations.
405
+     *
406
+     * @param WPInv_Invoice $invoice  Invoice object.
407
+     */
408
+    protected function ipn_txn_subscr_cancel( $invoice ) {
409 409
 
410
-		// Make sure the invoice has a subscription.
411
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
412
-
413
-		if ( empty( $subscription ) ) {
414
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
415
-		}
416
-
417
-		wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false );
418
-		$subscription->cancel();
419
-		wpinv_error_log( 'Subscription cancelled.', false );
410
+        // Make sure the invoice has a subscription.
411
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
412
+
413
+        if ( empty( $subscription ) ) {
414
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
415
+        }
416
+
417
+        wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false );
418
+        $subscription->cancel();
419
+        wpinv_error_log( 'Subscription cancelled.', false );
420 420
 
421
-	}
421
+    }
422 422
 
423
-	/**
424
-	 * Handles subscription completions.
425
-	 *
426
-	 * @param WPInv_Invoice $invoice  Invoice object.
427
-	 * @param array    $posted Posted data.
428
-	 */
429
-	protected function ipn_txn_subscr_eot( $invoice ) {
423
+    /**
424
+     * Handles subscription completions.
425
+     *
426
+     * @param WPInv_Invoice $invoice  Invoice object.
427
+     * @param array    $posted Posted data.
428
+     */
429
+    protected function ipn_txn_subscr_eot( $invoice ) {
430 430
 
431
-		// Make sure the invoice has a subscription.
432
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
431
+        // Make sure the invoice has a subscription.
432
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
433 433
 
434
-		if ( empty( $subscription ) ) {
435
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
436
-		}
434
+        if ( empty( $subscription ) ) {
435
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
436
+        }
437 437
 
438
-		wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false );
439
-		$subscription->complete();
440
-		wpinv_error_log( 'Subscription completed.', false );
438
+        wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false );
439
+        $subscription->complete();
440
+        wpinv_error_log( 'Subscription completed.', false );
441 441
 
442
-	}
442
+    }
443 443
 
444
-	/**
445
-	 * Handles subscription fails.
446
-	 *
447
-	 * @param WPInv_Invoice $invoice  Invoice object.
448
-	 * @param array    $posted Posted data.
449
-	 */
450
-	protected function ipn_txn_subscr_failed( $invoice ) {
444
+    /**
445
+     * Handles subscription fails.
446
+     *
447
+     * @param WPInv_Invoice $invoice  Invoice object.
448
+     * @param array    $posted Posted data.
449
+     */
450
+    protected function ipn_txn_subscr_failed( $invoice ) {
451 451
 
452
-		// Make sure the invoice has a subscription.
453
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
452
+        // Make sure the invoice has a subscription.
453
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
454 454
 
455
-		if ( empty( $subscription ) ) {
456
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
457
-		}
455
+        if ( empty( $subscription ) ) {
456
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
457
+        }
458 458
 
459
-		wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false );
460
-		$subscription->failing();
461
-		wpinv_error_log( 'Subscription marked as failing.', false );
459
+        wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false );
460
+        $subscription->failing();
461
+        wpinv_error_log( 'Subscription marked as failing.', false );
462 462
 
463
-	}
463
+    }
464 464
 
465
-	/**
466
-	 * Handles subscription suspensions.
467
-	 *
468
-	 * @param WPInv_Invoice $invoice  Invoice object.
469
-	 * @param array    $posted Posted data.
470
-	 */
471
-	protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) {
465
+    /**
466
+     * Handles subscription suspensions.
467
+     *
468
+     * @param WPInv_Invoice $invoice  Invoice object.
469
+     * @param array    $posted Posted data.
470
+     */
471
+    protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) {
472 472
 
473
-		// Make sure the invoice has a subscription.
474
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
473
+        // Make sure the invoice has a subscription.
474
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
475 475
 
476
-		if ( empty( $subscription ) ) {
477
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
478
-		}
479
-
480
-		wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false );
481
-		$subscription->cancel();
482
-		wpinv_error_log( 'Subscription cancelled.', false );
483
-	}
476
+        if ( empty( $subscription ) ) {
477
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
478
+        }
479
+
480
+        wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false );
481
+        $subscription->cancel();
482
+        wpinv_error_log( 'Subscription cancelled.', false );
483
+    }
484 484
 
485 485
 }
Please login to merge, or discard this patch.
Spacing   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Paypal Payment Gateway IPN handler class.
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	 *
32 32
 	 * @param GetPaid_Paypal_Gateway $gateway
33 33
 	 */
34
-	public function __construct( $gateway ) {
34
+	public function __construct($gateway) {
35 35
 		$this->gateway = $gateway;
36 36
 		$this->verify_ipn();
37 37
 	}
@@ -43,37 +43,37 @@  discard block
 block discarded – undo
43 43
 	 */
44 44
 	public function verify_ipn() {
45 45
 
46
-		wpinv_error_log( 'GetPaid PayPal IPN Handler', false );
46
+		wpinv_error_log('GetPaid PayPal IPN Handler', false);
47 47
 
48 48
 		// Validate the IPN.
49
-		if ( empty( $_POST ) || ! $this->validate_ipn() ) {
50
-			wp_die( 'PayPal IPN Request Failure', 500 );
49
+		if (empty($_POST) || !$this->validate_ipn()) {
50
+			wp_die('PayPal IPN Request Failure', 500);
51 51
 		}
52 52
 
53 53
 		// Process the IPN.
54
-		$posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
55
-		$invoice = $this->get_ipn_invoice( $posted );
54
+		$posted  = wp_kses_post_deep(wp_unslash($_POST));
55
+		$invoice = $this->get_ipn_invoice($posted);
56 56
 
57 57
 		// Abort if it was not paid by our gateway.
58
-		if ( $this->id != $invoice->get_gateway() ) {
59
-			wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false );
60
-			wp_die( 'Invoice not paid via PayPal', 200 );
58
+		if ($this->id != $invoice->get_gateway()) {
59
+			wpinv_error_log('Aborting, Invoice was not paid via PayPal', false);
60
+			wp_die('Invoice not paid via PayPal', 200);
61 61
 		}
62 62
 
63
-		$posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : '';
64
-		$posted['txn_type']       = sanitize_key( strtolower( $posted['txn_type'] ) );
63
+		$posted['payment_status'] = isset($posted['payment_status']) ? sanitize_key(strtolower($posted['payment_status'])) : '';
64
+		$posted['txn_type']       = sanitize_key(strtolower($posted['txn_type']));
65 65
 
66
-		wpinv_error_log( 'Payment status:' . $posted['payment_status'], false );
67
-		wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false );
66
+		wpinv_error_log('Payment status:' . $posted['payment_status'], false);
67
+		wpinv_error_log('IPN Type:' . $posted['txn_type'], false);
68 68
 
69
-		if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) {
70
-			call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted );
71
-			wpinv_error_log( 'Done processing IPN', false );
72
-			wp_die( 'Processed', 200 );
69
+		if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) {
70
+			call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted);
71
+			wpinv_error_log('Done processing IPN', false);
72
+			wp_die('Processed', 200);
73 73
 		}
74 74
 
75
-		wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false );
76
-		wp_die( 'Unsupported IPN type', 200 );
75
+		wpinv_error_log('Aborting, Unsupported IPN type:' . $posted['txn_type'], false);
76
+		wp_die('Unsupported IPN type', 200);
77 77
 
78 78
 	}
79 79
 
@@ -83,22 +83,22 @@  discard block
 block discarded – undo
83 83
 	 * @param array $posted
84 84
 	 * @return WPInv_Invoice
85 85
 	 */
86
-	protected function get_ipn_invoice( $posted ) {
86
+	protected function get_ipn_invoice($posted) {
87 87
 
88
-		wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false );
88
+		wpinv_error_log('Retrieving PayPal IPN Response Invoice', false);
89 89
 
90
-		if ( ! empty( $posted['custom'] ) ) {
91
-			$invoice = new WPInv_Invoice( $posted['custom'] );
90
+		if (!empty($posted['custom'])) {
91
+			$invoice = new WPInv_Invoice($posted['custom']);
92 92
 
93
-			if ( $invoice->exists() ) {
94
-				wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false );
93
+			if ($invoice->exists()) {
94
+				wpinv_error_log('Found invoice #' . $invoice->get_number(), false);
95 95
 				return $invoice;
96 96
 			}
97 97
 
98 98
 		}
99 99
 
100
-		wpinv_error_log( 'Could not retrieve the associated invoice.', false );
101
-		wp_die( 'Could not retrieve the associated invoice.', 200 );
100
+		wpinv_error_log('Could not retrieve the associated invoice.', false);
101
+		wp_die('Could not retrieve the associated invoice.', 200);
102 102
 	}
103 103
 
104 104
 	/**
@@ -106,14 +106,14 @@  discard block
 block discarded – undo
106 106
 	 */
107 107
 	protected function validate_ipn() {
108 108
 
109
-		wpinv_error_log( 'Validating PayPal IPN response', false );
109
+		wpinv_error_log('Validating PayPal IPN response', false);
110 110
 
111 111
 		// Retrieve the associated invoice.
112
-		$posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
113
-		$invoice = $this->get_ipn_invoice( $posted );
112
+		$posted  = wp_kses_post_deep(wp_unslash($_POST));
113
+		$invoice = $this->get_ipn_invoice($posted);
114 114
 
115
-		if ( $this->gateway->is_sandbox( $invoice ) ) {
116
-			wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false );
115
+		if ($this->gateway->is_sandbox($invoice)) {
116
+			wpinv_error_log($posted, 'Invoice was processed in sandbox hence logging the posted data', false);
117 117
 		}
118 118
 
119 119
 		// Validate the IPN.
@@ -130,20 +130,20 @@  discard block
 block discarded – undo
130 130
 		);
131 131
 
132 132
 		// Post back to get a response.
133
-		$response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params );
133
+		$response = wp_safe_remote_post($this->gateway->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params);
134 134
 
135 135
 		// Check to see if the request was valid.
136
-		if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) {
137
-			wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false );
136
+		if (!is_wp_error($response) && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) {
137
+			wpinv_error_log('Received valid response from PayPal IPN: ' . $response['body'], false);
138 138
 			return true;
139 139
 		}
140 140
 
141
-		if ( is_wp_error( $response ) ) {
142
-			wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' );
141
+		if (is_wp_error($response)) {
142
+			wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN');
143 143
 			return false;
144 144
 		}
145 145
 
146
-		wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' );
146
+		wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN');
147 147
 		return false;
148 148
 
149 149
 	}
@@ -154,17 +154,17 @@  discard block
 block discarded – undo
154 154
 	 * @param WPInv_Invoice $invoice          Invoice object.
155 155
 	 * @param string   $currency currency to validate.
156 156
 	 */
157
-	protected function validate_ipn_currency( $invoice, $currency ) {
157
+	protected function validate_ipn_currency($invoice, $currency) {
158 158
 
159
-		if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) {
159
+		if (strtolower($invoice->get_currency()) !== strtolower($currency)) {
160 160
 
161 161
 			/* translators: %s: currency code. */
162
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) );
162
+			$invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency));
163 163
 
164
-			wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true );
164
+			wpinv_error_log("Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true);
165 165
 		}
166 166
 
167
-		wpinv_error_log( $currency, 'Validated IPN Currency', false );
167
+		wpinv_error_log($currency, 'Validated IPN Currency', false);
168 168
 	}
169 169
 
170 170
 	/**
@@ -173,16 +173,16 @@  discard block
 block discarded – undo
173 173
 	 * @param WPInv_Invoice $invoice          Invoice object.
174 174
 	 * @param float   $amount amount to validate.
175 175
 	 */
176
-	protected function validate_ipn_amount( $invoice, $amount ) {
177
-		if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) {
176
+	protected function validate_ipn_amount($invoice, $amount) {
177
+		if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) {
178 178
 
179 179
 			/* translators: %s: Amount. */
180
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) );
180
+			$invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount));
181 181
 
182
-			wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true );
182
+			wpinv_error_log("Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true);
183 183
 		}
184 184
 
185
-		wpinv_error_log( $amount, 'Validated IPN Amount', false );
185
+		wpinv_error_log($amount, 'Validated IPN Amount', false);
186 186
 	}
187 187
 
188 188
 	/**
@@ -191,19 +191,19 @@  discard block
 block discarded – undo
191 191
 	 * @param WPInv_Invoice $invoice          Invoice object.
192 192
 	 * @param string   $receiver_email Email to validate.
193 193
 	 */
194
-	protected function validate_ipn_receiver_email( $invoice, $receiver_email ) {
195
-		$paypal_email = wpinv_get_option( 'paypal_email' );
194
+	protected function validate_ipn_receiver_email($invoice, $receiver_email) {
195
+		$paypal_email = wpinv_get_option('paypal_email');
196 196
 
197
-		if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) {
198
-			wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" );
197
+		if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) {
198
+			wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}");
199 199
 
200 200
 			/* translators: %s: email address . */
201
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) );
201
+			$invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email));
202 202
 
203
-			return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true );
203
+			return wpinv_error_log("IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true);
204 204
 		}
205 205
 
206
-		wpinv_error_log( 'Validated PayPal Email', false );
206
+		wpinv_error_log('Validated PayPal Email', false);
207 207
 	}
208 208
 
209 209
 	/**
@@ -212,70 +212,70 @@  discard block
 block discarded – undo
212 212
 	 * @param WPInv_Invoice $invoice  Invoice object.
213 213
 	 * @param array    $posted Posted data.
214 214
 	 */
215
-	protected function ipn_txn_web_accept( $invoice, $posted ) {
215
+	protected function ipn_txn_web_accept($invoice, $posted) {
216 216
 
217 217
 		// Collect payment details
218
-		$payment_status = strtolower( $posted['payment_status'] );
219
-		$business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
218
+		$payment_status = strtolower($posted['payment_status']);
219
+		$business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']);
220 220
 
221
-		$this->validate_ipn_receiver_email( $invoice, $business_email );
222
-		$this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
221
+		$this->validate_ipn_receiver_email($invoice, $business_email);
222
+		$this->validate_ipn_currency($invoice, $posted['mc_currency']);
223 223
 
224 224
 		// Update the transaction id.
225
-		if ( ! empty( $posted['txn_id'] ) ) {
226
-			$invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) );
225
+		if (!empty($posted['txn_id'])) {
226
+			$invoice->set_transaction_id(wpinv_clean($posted['txn_id']));
227 227
 			$invoice->save();
228 228
 		}
229 229
 
230
-		$invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) );
230
+		$invoice->add_system_note(__('Processing invoice IPN', 'invoicing'));
231 231
 
232 232
 		// Process a refund.
233
-		if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
233
+		if ($payment_status == 'refunded' || $payment_status == 'reversed') {
234 234
 
235
-			update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 );
235
+			update_post_meta($invoice->get_id(), 'refunded_remotely', 1);
236 236
 
237
-			if ( ! $invoice->is_refunded() ) {
238
-				$invoice->update_status( 'wpi-refunded', $posted['reason_code'] );
237
+			if (!$invoice->is_refunded()) {
238
+				$invoice->update_status('wpi-refunded', $posted['reason_code']);
239 239
 			}
240 240
 
241
-			return wpinv_error_log( $posted['reason_code'], false );
241
+			return wpinv_error_log($posted['reason_code'], false);
242 242
 		}
243 243
 
244 244
 		// Process payments.
245
-		if ( $payment_status == 'completed' ) {
245
+		if ($payment_status == 'completed') {
246 246
 
247
-			if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) {
248
-				return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false );
247
+			if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) {
248
+				return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false);
249 249
 			}
250 250
 
251
-			$this->validate_ipn_amount( $invoice, $posted['mc_gross'] );
251
+			$this->validate_ipn_amount($invoice, $posted['mc_gross']);
252 252
 
253 253
 			$note = '';
254 254
 
255
-			if ( ! empty( $posted['mc_fee'] ) ) {
256
-				$note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) );
255
+			if (!empty($posted['mc_fee'])) {
256
+				$note = sprintf(__('PayPal Transaction Fee %s.', 'invoicing'), sanitize_text_field($posted['mc_fee']));
257 257
 			}
258 258
 
259
-			if ( ! empty( $posted['payer_status'] ) ) {
260
-				$note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) );
259
+			if (!empty($posted['payer_status'])) {
260
+				$note = ' ' . sprintf(__('Buyer status %s.', 'invoicing'), sanitize_text_field($posted['payer_status']));
261 261
 			}
262 262
 
263
-			$invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) );
264
-			return wpinv_error_log( 'Invoice marked as paid.', false );
263
+			$invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note));
264
+			return wpinv_error_log('Invoice marked as paid.', false);
265 265
 
266 266
 		}
267 267
 
268 268
 		// Pending payments.
269
-		if ( $payment_status == 'pending' ) {
269
+		if ($payment_status == 'pending') {
270 270
 
271 271
 			/* translators: %s: pending reason. */
272
-			$invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) );
272
+			$invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason']));
273 273
 
274
-			return wpinv_error_log( 'Invoice marked as "payment held".', false );
274
+			return wpinv_error_log('Invoice marked as "payment held".', false);
275 275
 		}
276 276
 
277 277
 		/* translators: %s: payment status. */
278
-		$invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) );
278
+		$invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status'])));
279 279
 
280 280
 	}
281 281
 
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
 	 * @param WPInv_Invoice $invoice  Invoice object.
286 286
 	 * @param array    $posted Posted data.
287 287
 	 */
288
-	protected function ipn_txn_cart( $invoice, $posted ) {
289
-		$this->ipn_txn_web_accept( $invoice, $posted );
288
+	protected function ipn_txn_cart($invoice, $posted) {
289
+		$this->ipn_txn_web_accept($invoice, $posted);
290 290
 	}
291 291
 
292 292
 	/**
@@ -295,43 +295,43 @@  discard block
 block discarded – undo
295 295
 	 * @param WPInv_Invoice $invoice  Invoice object.
296 296
 	 * @param array    $posted Posted data.
297 297
 	 */
298
-	protected function ipn_txn_subscr_signup( $invoice, $posted ) {
298
+	protected function ipn_txn_subscr_signup($invoice, $posted) {
299 299
 
300
-		wpinv_error_log( 'Processing subscription signup', false );
300
+		wpinv_error_log('Processing subscription signup', false);
301 301
 
302 302
 		// Make sure the invoice has a subscription.
303
-		$subscription = getpaid_get_invoice_subscription( $invoice );
303
+		$subscription = getpaid_get_invoice_subscription($invoice);
304 304
 
305
-		if ( empty( $subscription ) ) {
306
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
305
+		if (empty($subscription)) {
306
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
307 307
 		}
308 308
 
309
-		wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
309
+		wpinv_error_log('Found subscription #' . $subscription->get_id(), false);
310 310
 
311 311
 		// Validate the IPN.
312
-		$business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
313
-		$this->validate_ipn_receiver_email( $invoice, $business_email );
314
-		$this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
312
+		$business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']);
313
+		$this->validate_ipn_receiver_email($invoice, $business_email);
314
+		$this->validate_ipn_currency($invoice, $posted['mc_currency']);
315 315
 
316 316
 		// Activate the subscription.
317
-		$duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
318
-		$subscription->set_date_created( current_time( 'mysql' ) );
319
-		$subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) );
320
-		$subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) );
317
+		$duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
318
+		$subscription->set_date_created(current_time('mysql'));
319
+		$subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration)));
320
+		$subscription->set_profile_id(sanitize_text_field($posted['subscr_id']));
321 321
 		$subscription->activate();
322 322
 
323 323
 		// Set the transaction id.
324
-		if ( ! empty( $posted['txn_id'] ) ) {
325
-			$invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
326
-			$invoice->set_transaction_id( $posted['txn_id'] );
324
+		if (!empty($posted['txn_id'])) {
325
+			$invoice->add_note(sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true);
326
+			$invoice->set_transaction_id($posted['txn_id']);
327 327
 		}
328 328
 
329 329
 		// Update the payment status.
330 330
 		$invoice->mark_paid();
331 331
 
332
-		$invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
332
+		$invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true);
333 333
 
334
-		wpinv_error_log( 'Subscription started.', false );
334
+		wpinv_error_log('Subscription started.', false);
335 335
 	}
336 336
 
337 337
 	/**
@@ -340,45 +340,45 @@  discard block
 block discarded – undo
340 340
 	 * @param WPInv_Invoice $invoice  Invoice object.
341 341
 	 * @param array    $posted Posted data.
342 342
 	 */
343
-	protected function ipn_txn_subscr_payment( $invoice, $posted ) {
343
+	protected function ipn_txn_subscr_payment($invoice, $posted) {
344 344
 
345 345
 		// Make sure the invoice has a subscription.
346
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
346
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
347 347
 
348
-		if ( empty( $subscription ) ) {
349
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
348
+		if (empty($subscription)) {
349
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
350 350
 		}
351 351
 
352
-		wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
352
+		wpinv_error_log('Found subscription #' . $subscription->get_id(), false);
353 353
 
354 354
 		// PayPal sends a subscr_payment for the first payment too.
355
-		$date_completed = getpaid_format_date( $invoice->get_date_completed() );
356
-		$date_created   = getpaid_format_date( $invoice->get_date_created() );
357
-		$today_date     = getpaid_format_date( current_time( 'mysql' ) );
358
-		$payment_date   = getpaid_format_date( $posted['payment_date'] );
359
-		$subscribe_date = getpaid_format_date( $subscription->get_date_created() );
360
-		$dates          = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) );
355
+		$date_completed = getpaid_format_date($invoice->get_date_completed());
356
+		$date_created   = getpaid_format_date($invoice->get_date_created());
357
+		$today_date     = getpaid_format_date(current_time('mysql'));
358
+		$payment_date   = getpaid_format_date($posted['payment_date']);
359
+		$subscribe_date = getpaid_format_date($subscription->get_date_created());
360
+		$dates          = array_filter(compact('date_completed', 'date_created', 'subscribe_date'));
361 361
 
362
-		foreach( $dates as $date ) {
362
+		foreach ($dates as $date) {
363 363
 
364
-			if ( $date !== $today_date && $date !== $payment_date ) {
364
+			if ($date !== $today_date && $date !== $payment_date) {
365 365
 				continue;
366 366
 			}
367 367
 
368
-			if ( ! empty( $posted['txn_id'] ) ) {
369
-				$invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) );	
370
-				$invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true );
368
+			if (!empty($posted['txn_id'])) {
369
+				$invoice->set_transaction_id(sanitize_text_field($posted['txn_id']));	
370
+				$invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), sanitize_text_field($posted['txn_id'])), false, false, true);
371 371
 			}
372 372
 
373 373
 			return $invoice->mark_paid();
374 374
 
375 375
 		}
376 376
 
377
-		wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false );
377
+		wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false);
378 378
 
379 379
 		// Abort if the payment is already recorded.
380
-		if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) {
381
-			return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false );
380
+		if (wpinv_get_id_by_transaction_id($posted['txn_id'])) {
381
+			return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false);
382 382
 		}
383 383
 
384 384
 		$args = array(
@@ -386,17 +386,17 @@  discard block
 block discarded – undo
386 386
 			'gateway'        => $this->id,
387 387
 		);
388 388
 
389
-		$invoice = wpinv_get_invoice( $subscription->add_payment( $args ) );
389
+		$invoice = wpinv_get_invoice($subscription->add_payment($args));
390 390
 
391
-		if ( empty( $invoice ) ) {
391
+		if (empty($invoice)) {
392 392
 			return;
393 393
 		}
394 394
 
395
-		$invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
396
-		$invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
395
+		$invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true);
396
+		$invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true);
397 397
 
398 398
 		$subscription->renew();
399
-		wpinv_error_log( 'Subscription renewed.', false );
399
+		wpinv_error_log('Subscription renewed.', false);
400 400
 
401 401
 	}
402 402
 
@@ -405,18 +405,18 @@  discard block
 block discarded – undo
405 405
 	 *
406 406
 	 * @param WPInv_Invoice $invoice  Invoice object.
407 407
 	 */
408
-	protected function ipn_txn_subscr_cancel( $invoice ) {
408
+	protected function ipn_txn_subscr_cancel($invoice) {
409 409
 
410 410
 		// Make sure the invoice has a subscription.
411
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
411
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
412 412
 
413
-		if ( empty( $subscription ) ) {
414
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
413
+		if (empty($subscription)) {
414
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
415 415
 		}
416 416
 
417
-		wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false );
417
+		wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id(), false);
418 418
 		$subscription->cancel();
419
-		wpinv_error_log( 'Subscription cancelled.', false );
419
+		wpinv_error_log('Subscription cancelled.', false);
420 420
 
421 421
 	}
422 422
 
@@ -426,18 +426,18 @@  discard block
 block discarded – undo
426 426
 	 * @param WPInv_Invoice $invoice  Invoice object.
427 427
 	 * @param array    $posted Posted data.
428 428
 	 */
429
-	protected function ipn_txn_subscr_eot( $invoice ) {
429
+	protected function ipn_txn_subscr_eot($invoice) {
430 430
 
431 431
 		// Make sure the invoice has a subscription.
432
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
432
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
433 433
 
434
-		if ( empty( $subscription ) ) {
435
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
434
+		if (empty($subscription)) {
435
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
436 436
 		}
437 437
 
438
-		wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false );
438
+		wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id(), false);
439 439
 		$subscription->complete();
440
-		wpinv_error_log( 'Subscription completed.', false );
440
+		wpinv_error_log('Subscription completed.', false);
441 441
 
442 442
 	}
443 443
 
@@ -447,18 +447,18 @@  discard block
 block discarded – undo
447 447
 	 * @param WPInv_Invoice $invoice  Invoice object.
448 448
 	 * @param array    $posted Posted data.
449 449
 	 */
450
-	protected function ipn_txn_subscr_failed( $invoice ) {
450
+	protected function ipn_txn_subscr_failed($invoice) {
451 451
 
452 452
 		// Make sure the invoice has a subscription.
453
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
453
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
454 454
 
455
-		if ( empty( $subscription ) ) {
456
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
455
+		if (empty($subscription)) {
456
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
457 457
 		}
458 458
 
459
-		wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false );
459
+		wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id(), false);
460 460
 		$subscription->failing();
461
-		wpinv_error_log( 'Subscription marked as failing.', false );
461
+		wpinv_error_log('Subscription marked as failing.', false);
462 462
 
463 463
 	}
464 464
 
@@ -468,18 +468,18 @@  discard block
 block discarded – undo
468 468
 	 * @param WPInv_Invoice $invoice  Invoice object.
469 469
 	 * @param array    $posted Posted data.
470 470
 	 */
471
-	protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) {
471
+	protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment($invoice) {
472 472
 
473 473
 		// Make sure the invoice has a subscription.
474
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
474
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
475 475
 
476
-		if ( empty( $subscription ) ) {
477
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
476
+		if (empty($subscription)) {
477
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
478 478
 		}
479 479
 
480
-		wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false );
480
+		wpinv_error_log('Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false);
481 481
 		$subscription->cancel();
482
-		wpinv_error_log( 'Subscription cancelled.', false );
482
+		wpinv_error_log('Subscription cancelled.', false);
483 483
 	}
484 484
 
485 485
 }
Please login to merge, or discard this patch.
includes/admin/subscriptions.php 2 patches
Indentation   +429 added lines, -429 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
  */
15 15
 function wpinv_subscriptions_page() {
16 16
 
17
-	?>
17
+    ?>
18 18
 
19 19
 	<div class="wrap">
20 20
 		<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
@@ -22,27 +22,27 @@  discard block
 block discarded – undo
22 22
 
23 23
 			<?php
24 24
 
25
-				// Verify user permissions.
26
-				if ( ! wpinv_current_user_can_manage_invoicing() ) {
25
+                // Verify user permissions.
26
+                if ( ! wpinv_current_user_can_manage_invoicing() ) {
27 27
 
28
-					echo aui()->alert(
29
-						array(
30
-							'type'    => 'danger',
31
-							'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
32
-						)
33
-					);
28
+                    echo aui()->alert(
29
+                        array(
30
+                            'type'    => 'danger',
31
+                            'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
32
+                        )
33
+                    );
34 34
 
35
-				} else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
35
+                } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
36 36
 
37
-					// Display a single subscription.
38
-					wpinv_recurring_subscription_details();
39
-				} else {
37
+                    // Display a single subscription.
38
+                    wpinv_recurring_subscription_details();
39
+                } else {
40 40
 
41
-					// Display a list of available subscriptions.
42
-					getpaid_print_subscriptions_list();
43
-				}
41
+                    // Display a list of available subscriptions.
42
+                    getpaid_print_subscriptions_list();
43
+                }
44 44
 
45
-			?>
45
+            ?>
46 46
 
47 47
 		</div>
48 48
 	</div>
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
  */
60 60
 function getpaid_print_subscriptions_list() {
61 61
 
62
-	$subscribers_table = new WPInv_Subscriptions_List_Table();
63
-	$subscribers_table->prepare_items();
62
+    $subscribers_table = new WPInv_Subscriptions_List_Table();
63
+    $subscribers_table->prepare_items();
64 64
 
65
-	?>
65
+    ?>
66 66
 	<?php $subscribers_table->views(); ?>
67 67
 	<form id="subscribers-filter" class="bsui" method="get">
68 68
 		<input type="hidden" name="page" value="wpinv-subscriptions" />
@@ -81,41 +81,41 @@  discard block
 block discarded – undo
81 81
  */
82 82
 function wpinv_recurring_subscription_details() {
83 83
 
84
-	// Fetch the subscription.
85
-	$sub = new WPInv_Subscription( (int) $_GET['id'] );
86
-	if ( ! $sub->exists() ) {
84
+    // Fetch the subscription.
85
+    $sub = new WPInv_Subscription( (int) $_GET['id'] );
86
+    if ( ! $sub->exists() ) {
87 87
 
88
-		echo aui()->alert(
89
-			array(
90
-				'type'    => 'danger',
91
-				'content' => __( 'Subscription not found.', 'invoicing' ),
92
-			)
93
-		);
88
+        echo aui()->alert(
89
+            array(
90
+                'type'    => 'danger',
91
+                'content' => __( 'Subscription not found.', 'invoicing' ),
92
+            )
93
+        );
94 94
 
95
-		return;
96
-	}
95
+        return;
96
+    }
97 97
 
98
-	// Use metaboxes to display the subscription details.
99
-	add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' );
100
-	add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
98
+    // Use metaboxes to display the subscription details.
99
+    add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' );
100
+    add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
101 101
 
102
-	$subscription_id     = $sub->get_id();
103
-	$subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() );
104
-	$subscription_group  = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
102
+    $subscription_id     = $sub->get_id();
103
+    $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() );
104
+    $subscription_group  = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
105 105
 
106
-	if ( 1 < count( $subscription_groups ) ) {
107
-		add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' );
108
-	}
106
+    if ( 1 < count( $subscription_groups ) ) {
107
+        add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' );
108
+    }
109 109
 
110
-	if ( ! empty( $subscription_group ) ) {
111
-		add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' );
112
-	}
110
+    if ( ! empty( $subscription_group ) ) {
111
+        add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' );
112
+    }
113 113
 
114
-	add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
114
+    add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
115 115
 
116
-	do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
116
+    do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
117 117
 
118
-	?>
118
+    ?>
119 119
 
120 120
 		<form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>">
121 121
 
@@ -155,45 +155,45 @@  discard block
 block discarded – undo
155 155
  */
156 156
 function getpaid_admin_subscription_details_metabox( $sub ) {
157 157
 
158
-	// Subscription items.
159
-	$subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() );
160
-	$items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
161
-
162
-	// Prepare subscription detail columns.
163
-	$fields = apply_filters(
164
-		'getpaid_subscription_admin_page_fields',
165
-		array(
166
-			'subscription'   => __( 'Subscription', 'invoicing' ),
167
-			'customer'       => __( 'Customer', 'invoicing' ),
168
-			'amount'         => __( 'Amount', 'invoicing' ),
169
-			'start_date'     => __( 'Start Date', 'invoicing' ),
170
-			'renews_on'      => __( 'Next Payment', 'invoicing' ),
171
-			'renewals'       => __( 'Payments', 'invoicing' ),
172
-			'item'           => _n( 'Item', 'Items', $items_count,  'invoicing' ),
173
-			'gateway'        => __( 'Payment Method', 'invoicing' ),
174
-			'profile_id'     => __( 'Profile ID', 'invoicing' ),
175
-			'status'         => __( 'Status', 'invoicing' ),
176
-		)
177
-	);
178
-
179
-	if ( ! $sub->is_active() ) {
180
-
181
-		if ( isset( $fields['renews_on'] ) ) {
182
-			unset( $fields['renews_on'] );
183
-		}
184
-
185
-		if ( isset( $fields['gateway'] ) ) {
186
-			unset( $fields['gateway'] );
187
-		}
188
-
189
-	}
190
-
191
-	$profile_id = $sub->get_profile_id();
192
-	if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
193
-		unset( $fields['profile_id'] );
194
-	}
195
-
196
-	?>
158
+    // Subscription items.
159
+    $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() );
160
+    $items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
161
+
162
+    // Prepare subscription detail columns.
163
+    $fields = apply_filters(
164
+        'getpaid_subscription_admin_page_fields',
165
+        array(
166
+            'subscription'   => __( 'Subscription', 'invoicing' ),
167
+            'customer'       => __( 'Customer', 'invoicing' ),
168
+            'amount'         => __( 'Amount', 'invoicing' ),
169
+            'start_date'     => __( 'Start Date', 'invoicing' ),
170
+            'renews_on'      => __( 'Next Payment', 'invoicing' ),
171
+            'renewals'       => __( 'Payments', 'invoicing' ),
172
+            'item'           => _n( 'Item', 'Items', $items_count,  'invoicing' ),
173
+            'gateway'        => __( 'Payment Method', 'invoicing' ),
174
+            'profile_id'     => __( 'Profile ID', 'invoicing' ),
175
+            'status'         => __( 'Status', 'invoicing' ),
176
+        )
177
+    );
178
+
179
+    if ( ! $sub->is_active() ) {
180
+
181
+        if ( isset( $fields['renews_on'] ) ) {
182
+            unset( $fields['renews_on'] );
183
+        }
184
+
185
+        if ( isset( $fields['gateway'] ) ) {
186
+            unset( $fields['gateway'] );
187
+        }
188
+
189
+    }
190
+
191
+    $profile_id = $sub->get_profile_id();
192
+    if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
193
+        unset( $fields['profile_id'] );
194
+    }
195
+
196
+    ?>
197 197
 
198 198
 		<table class="table table-borderless" style="font-size: 14px;">
199 199
 			<tbody>
@@ -227,20 +227,20 @@  discard block
 block discarded – undo
227 227
  */
228 228
 function getpaid_admin_subscription_metabox_display_customer( $subscription ) {
229 229
 
230
-	$username = __( '(Missing User)', 'invoicing' );
230
+    $username = __( '(Missing User)', 'invoicing' );
231 231
 
232
-	$user = get_userdata( $subscription->get_customer_id() );
233
-	if ( $user ) {
232
+    $user = get_userdata( $subscription->get_customer_id() );
233
+    if ( $user ) {
234 234
 
235
-		$username = sprintf(
236
-			'<a href="user-edit.php?user_id=%s">%s</a>',
237
-			absint( $user->ID ),
238
-			! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email )
239
-		);
235
+        $username = sprintf(
236
+            '<a href="user-edit.php?user_id=%s">%s</a>',
237
+            absint( $user->ID ),
238
+            ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email )
239
+        );
240 240
 
241
-	}
241
+    }
242 242
 
243
-	echo  $username;
243
+    echo  $username;
244 244
 }
245 245
 add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' );
246 246
 
@@ -250,8 +250,8 @@  discard block
 block discarded – undo
250 250
  * @param WPInv_Subscription $subscription
251 251
  */
252 252
 function getpaid_admin_subscription_metabox_display_amount( $subscription ) {
253
-	$amount    = wp_kses_post( getpaid_get_formatted_subscription_amount( $subscription ) );
254
-	echo "<span>$amount</span>";
253
+    $amount    = wp_kses_post( getpaid_get_formatted_subscription_amount( $subscription ) );
254
+    echo "<span>$amount</span>";
255 255
 }
256 256
 add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' );
257 257
 
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
  * @param WPInv_Subscription $subscription
262 262
  */
263 263
 function getpaid_admin_subscription_metabox_display_id( $subscription ) {
264
-	echo  '#' . absint( $subscription->get_id() );
264
+    echo  '#' . absint( $subscription->get_id() );
265 265
 }
266 266
 add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' );
267 267
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
  * @param WPInv_Subscription $subscription
272 272
  */
273 273
 function getpaid_admin_subscription_metabox_display_start_date( $subscription ) {
274
-	echo getpaid_format_date_value( $subscription->get_date_created() );
274
+    echo getpaid_format_date_value( $subscription->get_date_created() );
275 275
 }
276 276
 add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' );
277 277
 
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
  * @param WPInv_Subscription $subscription
282 282
  */
283 283
 function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) {
284
-	echo getpaid_format_date_value( $subscription->get_expiration() );
284
+    echo getpaid_format_date_value( $subscription->get_expiration() );
285 285
 }
286 286
 add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' );
287 287
 
@@ -291,8 +291,8 @@  discard block
 block discarded – undo
291 291
  * @param WPInv_Subscription $subscription
292 292
  */
293 293
 function getpaid_admin_subscription_metabox_display_renewals( $subscription ) {
294
-	$max_bills = $subscription->get_bill_times();
295
-	echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
294
+    $max_bills = $subscription->get_bill_times();
295
+    echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
296 296
 }
297 297
 add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' );
298 298
 /**
@@ -303,13 +303,13 @@  discard block
 block discarded – undo
303 303
  */
304 304
 function getpaid_admin_subscription_metabox_display_item( $subscription, $subscription_group = false ) {
305 305
 
306
-	if ( empty( $subscription_group ) ) {
307
-		echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() );
308
-		return;
309
-	}
306
+    if ( empty( $subscription_group ) ) {
307
+        echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() );
308
+        return;
309
+    }
310 310
 
311
-	$markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
312
-	echo implode( ' | ', $markup );
311
+    $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
312
+    echo implode( ' | ', $markup );
313 313
 
314 314
 }
315 315
 add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2 );
@@ -321,13 +321,13 @@  discard block
 block discarded – undo
321 321
  */
322 322
 function getpaid_admin_subscription_metabox_display_gateway( $subscription ) {
323 323
 
324
-	$gateway = $subscription->get_gateway();
324
+    $gateway = $subscription->get_gateway();
325 325
 
326
-	if ( ! empty( $gateway ) ) {
327
-		echo esc_html( wpinv_get_gateway_admin_label( $gateway ) );
328
-	} else {
329
-		echo "&mdash;";
330
-	}
326
+    if ( ! empty( $gateway ) ) {
327
+        echo esc_html( wpinv_get_gateway_admin_label( $gateway ) );
328
+    } else {
329
+        echo "&mdash;";
330
+    }
331 331
 
332 332
 }
333 333
 add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' );
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
  * @param WPInv_Subscription $subscription
339 339
  */
340 340
 function getpaid_admin_subscription_metabox_display_status( $subscription ) {
341
-	echo $subscription->get_status_label_html();
341
+    echo $subscription->get_status_label_html();
342 342
 }
343 343
 add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' );
344 344
 
@@ -349,29 +349,29 @@  discard block
 block discarded – undo
349 349
  */
350 350
 function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) {
351 351
 
352
-	$profile_id = $subscription->get_profile_id();
353
-
354
-	$input = aui()->input(
355
-		array(
356
-			'type'        => 'text',
357
-			'id'          => 'wpinv_subscription_profile_id',
358
-			'name'        => 'wpinv_subscription_profile_id',
359
-			'label'       => __( 'Profile Id', 'invoicing' ),
360
-			'label_type'  => 'hidden',
361
-			'placeholder' => __( 'Profile Id', 'invoicing' ),
362
-			'value'       => esc_attr( $profile_id ),
363
-			'input_group_right' => '',
364
-			'no_wrap'     => true,
365
-		)
366
-	);
367
-
368
-	echo str_ireplace( 'form-control', 'regular-text', $input );
369
-
370
-	$url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription );
371
-	if ( ! empty( $url ) ) {
372
-		$url = esc_url_raw( $url );
373
-		echo '&nbsp;<a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
374
-	}
352
+    $profile_id = $subscription->get_profile_id();
353
+
354
+    $input = aui()->input(
355
+        array(
356
+            'type'        => 'text',
357
+            'id'          => 'wpinv_subscription_profile_id',
358
+            'name'        => 'wpinv_subscription_profile_id',
359
+            'label'       => __( 'Profile Id', 'invoicing' ),
360
+            'label_type'  => 'hidden',
361
+            'placeholder' => __( 'Profile Id', 'invoicing' ),
362
+            'value'       => esc_attr( $profile_id ),
363
+            'input_group_right' => '',
364
+            'no_wrap'     => true,
365
+        )
366
+    );
367
+
368
+    echo str_ireplace( 'form-control', 'regular-text', $input );
369
+
370
+    $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription );
371
+    if ( ! empty( $url ) ) {
372
+        $url = esc_url_raw( $url );
373
+        echo '&nbsp;<a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
374
+    }
375 375
 
376 376
 }
377 377
 add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' );
@@ -383,39 +383,39 @@  discard block
 block discarded – undo
383 383
  */
384 384
 function getpaid_admin_subscription_update_metabox( $subscription ) {
385 385
 
386
-	?>
386
+    ?>
387 387
 	<div class="mt-3">
388 388
 
389 389
 		<?php
390
-			echo aui()->select(
391
-				array(
392
-					'options'          => getpaid_get_subscription_statuses(),
393
-					'name'             => 'subscription_status',
394
-					'id'               => 'subscription_status_update_select',
395
-					'required'         => true,
396
-					'no_wrap'          => false,
397
-					'label'            => __( 'Subscription Status', 'invoicing' ),
398
-					'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
399
-					'select2'          => true,
400
-					'value'            => $subscription->get_status( 'edit' ),
401
-				)
402
-			);
403
-		?>
390
+            echo aui()->select(
391
+                array(
392
+                    'options'          => getpaid_get_subscription_statuses(),
393
+                    'name'             => 'subscription_status',
394
+                    'id'               => 'subscription_status_update_select',
395
+                    'required'         => true,
396
+                    'no_wrap'          => false,
397
+                    'label'            => __( 'Subscription Status', 'invoicing' ),
398
+                    'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
399
+                    'select2'          => true,
400
+                    'value'            => $subscription->get_status( 'edit' ),
401
+                )
402
+            );
403
+        ?>
404 404
 
405 405
 		<div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;">
406 406
 
407 407
 		<?php
408
-			submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
408
+            submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
409 409
 
410
-			$url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
411
-			$anchor = __( 'Renew Subscription', 'invoicing' );
412
-			$title  = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' );
410
+            $url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
411
+            $anchor = __( 'Renew Subscription', 'invoicing' );
412
+            $title  = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' );
413 413
 
414
-			if ( $subscription->is_active() ) {
415
-				echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
416
-			}
414
+            if ( $subscription->is_active() ) {
415
+                echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
416
+            }
417 417
 
418
-	echo '</div></div>';
418
+    echo '</div></div>';
419 419
 }
420 420
 
421 421
 /**
@@ -426,33 +426,33 @@  discard block
 block discarded – undo
426 426
  */
427 427
 function getpaid_admin_subscription_invoice_details_metabox( $subscription, $strict = true ) {
428 428
 
429
-	$columns = apply_filters(
430
-		'getpaid_subscription_related_invoices_columns',
431
-		array(
432
-			'invoice'      => __( 'Invoice', 'invoicing' ),
433
-			'relationship' => __( 'Relationship', 'invoicing' ),
434
-			'date'         => __( 'Date', 'invoicing' ),
435
-			'status'       => __( 'Status', 'invoicing' ),
436
-			'total'        => __( 'Total', 'invoicing' ),
437
-		),
438
-		$subscription
439
-	);
440
-
441
-	// Prepare the invoices.
442
-	$payments = $subscription->get_child_payments( ! is_admin() );
443
-	$parent   = $subscription->get_parent_invoice();
444
-
445
-	if ( $parent->exists() ) {
446
-		$payments = array_merge( array( $parent ), $payments );
447
-	}
448
-
449
-	$table_class = 'w-100 bg-white';
450
-
451
-	if ( ! is_admin() ) {
452
-		$table_class = 'table table-bordered';
453
-	}
454
-
455
-	?>
429
+    $columns = apply_filters(
430
+        'getpaid_subscription_related_invoices_columns',
431
+        array(
432
+            'invoice'      => __( 'Invoice', 'invoicing' ),
433
+            'relationship' => __( 'Relationship', 'invoicing' ),
434
+            'date'         => __( 'Date', 'invoicing' ),
435
+            'status'       => __( 'Status', 'invoicing' ),
436
+            'total'        => __( 'Total', 'invoicing' ),
437
+        ),
438
+        $subscription
439
+    );
440
+
441
+    // Prepare the invoices.
442
+    $payments = $subscription->get_child_payments( ! is_admin() );
443
+    $parent   = $subscription->get_parent_invoice();
444
+
445
+    if ( $parent->exists() ) {
446
+        $payments = array_merge( array( $parent ), $payments );
447
+    }
448
+
449
+    $table_class = 'w-100 bg-white';
450
+
451
+    if ( ! is_admin() ) {
452
+        $table_class = 'table table-bordered';
453
+    }
454
+
455
+    ?>
456 456
 		<div class="m-0" style="overflow: auto;">
457 457
 
458 458
 			<table class="<?php echo $table_class; ?>">
@@ -460,14 +460,14 @@  discard block
 block discarded – undo
460 460
 				<thead>
461 461
 					<tr>
462 462
 						<?php
463
-							foreach ( $columns as $key => $label ) {
464
-								$key   = esc_attr( $key );
465
-								$label = esc_html( $label );
466
-								$class = 'text-left';
467
-
468
-								echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
469
-							}
470
-						?>
463
+                            foreach ( $columns as $key => $label ) {
464
+                                $key   = esc_attr( $key );
465
+                                $label = esc_html( $label );
466
+                                $class = 'text-left';
467
+
468
+                                echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
469
+                            }
470
+                        ?>
471 471
 					</tr>
472 472
 				</thead>
473 473
 
@@ -483,73 +483,73 @@  discard block
 block discarded – undo
483 483
 
484 484
 					<?php
485 485
 
486
-						foreach( $payments as $payment ) :
486
+                        foreach( $payments as $payment ) :
487 487
 
488
-							// Ensure that we have an invoice.
489
-							$payment = new WPInv_Invoice( $payment );
488
+                            // Ensure that we have an invoice.
489
+                            $payment = new WPInv_Invoice( $payment );
490 490
 
491
-							// Abort if the invoice is invalid...
492
-							if ( ! $payment->exists() ) {
493
-								continue;
494
-							}
491
+                            // Abort if the invoice is invalid...
492
+                            if ( ! $payment->exists() ) {
493
+                                continue;
494
+                            }
495 495
 
496
-							// ... or belongs to a different subscription.
497
-							if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) {
498
-								continue;
499
-							}
496
+                            // ... or belongs to a different subscription.
497
+                            if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) {
498
+                                continue;
499
+                            }
500 500
 
501
-							echo '<tr>';
501
+                            echo '<tr>';
502 502
 
503
-								foreach ( array_keys( $columns ) as $key ) {
503
+                                foreach ( array_keys( $columns ) as $key ) {
504 504
 
505
-									$class = 'text-left';
505
+                                    $class = 'text-left';
506 506
 
507
-									echo "<td class='p-2 $class'>";
507
+                                    echo "<td class='p-2 $class'>";
508 508
 
509
-										switch( $key ) {
509
+                                        switch( $key ) {
510 510
 
511
-											case 'total':
512
-												echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>';
513
-												break;
511
+                                            case 'total':
512
+                                                echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>';
513
+                                                break;
514 514
 
515
-											case 'relationship':
516
-												echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
517
-												break;
515
+                                            case 'relationship':
516
+                                                echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
517
+                                                break;
518 518
 
519
-											case 'date':
520
-												echo getpaid_format_date_value( $payment->get_date_created() );
521
-												break;
519
+                                            case 'date':
520
+                                                echo getpaid_format_date_value( $payment->get_date_created() );
521
+                                                break;
522 522
 
523
-											case 'status':
523
+                                            case 'status':
524 524
 
525
-												$status = $payment->get_status_nicename();
526
-												if ( is_admin() ) {
527
-													$status = $payment->get_status_label_html();
528
-												}
525
+                                                $status = $payment->get_status_nicename();
526
+                                                if ( is_admin() ) {
527
+                                                    $status = $payment->get_status_label_html();
528
+                                                }
529 529
 
530
-												echo $status;
531
-												break;
530
+                                                echo $status;
531
+                                                break;
532 532
 
533
-											case 'invoice':
534
-												$link    = esc_url( get_edit_post_link( $payment->get_id() ) );
533
+                                            case 'invoice':
534
+                                                $link    = esc_url( get_edit_post_link( $payment->get_id() ) );
535 535
 
536
-												if ( ! is_admin() ) {
537
-													$link = esc_url( $payment->get_view_url() );
538
-												}
536
+                                                if ( ! is_admin() ) {
537
+                                                    $link = esc_url( $payment->get_view_url() );
538
+                                                }
539 539
 
540
-												$invoice = esc_html( $payment->get_number() );
541
-												echo "<a href='$link'>$invoice</a>";
542
-												break;
543
-										}
540
+                                                $invoice = esc_html( $payment->get_number() );
541
+                                                echo "<a href='$link'>$invoice</a>";
542
+                                                break;
543
+                                        }
544 544
 
545
-									echo '</td>';
545
+                                    echo '</td>';
546 546
 
547
-								}
547
+                                }
548 548
 
549
-							echo '</tr>';
549
+                            echo '</tr>';
550 550
 
551
-						endforeach;
552
-					?>
551
+                        endforeach;
552
+                    ?>
553 553
 
554 554
 				</tbody>
555 555
 
@@ -567,42 +567,42 @@  discard block
 block discarded – undo
567 567
  */
568 568
 function getpaid_admin_subscription_item_details_metabox( $subscription ) {
569 569
 
570
-	// Fetch the subscription group.
571
-	$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() );
570
+    // Fetch the subscription group.
571
+    $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() );
572 572
 
573
-	if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) {
574
-		return;
575
-	}
573
+    if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) {
574
+        return;
575
+    }
576 576
 
577
-	// Prepare table columns.
578
-	$columns = apply_filters(
579
-		'getpaid_subscription_item_details_columns',
580
-		array(
581
-			'item_name'    => __( 'Item', 'invoicing' ),
582
-			'price'        => __( 'Price', 'invoicing' ),
583
-			'tax'          => __( 'Tax', 'invoicing' ),
584
-			'discount'     => __( 'Discount', 'invoicing' ),
585
-			//'initial'      => __( 'Initial Amount', 'invoicing' ),
586
-			'recurring'    => __( 'Subtotal', 'invoicing' ),
587
-		),
588
-		$subscription
589
-	);
577
+    // Prepare table columns.
578
+    $columns = apply_filters(
579
+        'getpaid_subscription_item_details_columns',
580
+        array(
581
+            'item_name'    => __( 'Item', 'invoicing' ),
582
+            'price'        => __( 'Price', 'invoicing' ),
583
+            'tax'          => __( 'Tax', 'invoicing' ),
584
+            'discount'     => __( 'Discount', 'invoicing' ),
585
+            //'initial'      => __( 'Initial Amount', 'invoicing' ),
586
+            'recurring'    => __( 'Subtotal', 'invoicing' ),
587
+        ),
588
+        $subscription
589
+    );
590 590
 
591
-	// Prepare the invoices.
591
+    // Prepare the invoices.
592 592
 
593
-	$invoice = $subscription->get_parent_invoice();
593
+    $invoice = $subscription->get_parent_invoice();
594 594
 
595
-	if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) {
596
-		unset( $columns['tax'] );
597
-	}
595
+    if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) {
596
+        unset( $columns['tax'] );
597
+    }
598 598
 
599
-	$table_class = 'w-100 bg-white';
599
+    $table_class = 'w-100 bg-white';
600 600
 
601
-	if ( ! is_admin() ) {
602
-		$table_class = 'table table-bordered';
603
-	}
601
+    if ( ! is_admin() ) {
602
+        $table_class = 'table table-bordered';
603
+    }
604 604
 
605
-	?>
605
+    ?>
606 606
 		<div class="m-0" style="overflow: auto;">
607 607
 
608 608
 			<table class="<?php echo $table_class; ?>">
@@ -611,14 +611,14 @@  discard block
 block discarded – undo
611 611
 					<tr>
612 612
 						<?php
613 613
 
614
-							foreach ( $columns as $key => $label ) {
615
-								$key   = esc_attr( $key );
616
-								$label = esc_html( $label );
617
-								$class = 'text-left';
614
+                            foreach ( $columns as $key => $label ) {
615
+                                $key   = esc_attr( $key );
616
+                                $label = esc_html( $label );
617
+                                $class = 'text-left';
618 618
 
619
-								echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
620
-							}
621
-						?>
619
+                                echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
620
+                            }
621
+                        ?>
622 622
 					</tr>
623 623
 				</thead>
624 624
 
@@ -626,106 +626,106 @@  discard block
 block discarded – undo
626 626
 
627 627
 					<?php
628 628
 
629
-						foreach( $subscription_group['items'] as $subscription_group_item ) :
629
+                        foreach( $subscription_group['items'] as $subscription_group_item ) :
630 630
 
631
-							echo '<tr>';
631
+                            echo '<tr>';
632 632
 
633
-								foreach ( array_keys( $columns ) as $key ) {
633
+                                foreach ( array_keys( $columns ) as $key ) {
634 634
 
635
-									$class = 'text-left';
635
+                                    $class = 'text-left';
636 636
 
637
-									echo "<td class='p-2 $class'>";
637
+                                    echo "<td class='p-2 $class'>";
638 638
 
639
-										switch( $key ) {
639
+                                        switch( $key ) {
640 640
 
641
-											case 'item_name':
642
-												$item_name = get_the_title( $subscription_group_item['item_id'] );
643
-												$item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name;
641
+                                            case 'item_name':
642
+                                                $item_name = get_the_title( $subscription_group_item['item_id'] );
643
+                                                $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name;
644 644
 
645
-												if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) {
646
-													echo esc_html( $item_name );
647
-												} else {
648
-													printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] );
649
-												}
645
+                                                if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) {
646
+                                                    echo esc_html( $item_name );
647
+                                                } else {
648
+                                                    printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] );
649
+                                                }
650 650
 
651
-												break;
651
+                                                break;
652 652
 
653
-											case 'price':
654
-												echo wpinv_price( $subscription_group_item['item_price'], $invoice->get_currency() );
655
-												break;
653
+                                            case 'price':
654
+                                                echo wpinv_price( $subscription_group_item['item_price'], $invoice->get_currency() );
655
+                                                break;
656 656
 
657
-											case 'tax':
658
-												echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() );
659
-												break;
657
+                                            case 'tax':
658
+                                                echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() );
659
+                                                break;
660 660
 
661
-											case 'discount':
662
-												echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() );
663
-												break;
661
+                                            case 'discount':
662
+                                                echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() );
663
+                                                break;
664 664
 
665
-											case 'initial':
666
-												echo wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() );
667
-												break;
665
+                                            case 'initial':
666
+                                                echo wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() );
667
+                                                break;
668 668
 
669
-											case 'recurring':
670
-												echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>';
671
-												break;
669
+                                            case 'recurring':
670
+                                                echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>';
671
+                                                break;
672 672
 
673
-										}
673
+                                        }
674 674
 
675
-									echo '</td>';
675
+                                    echo '</td>';
676 676
 
677
-								}
677
+                                }
678 678
 
679
-							echo '</tr>';
679
+                            echo '</tr>';
680 680
 
681
-						endforeach;
681
+                        endforeach;
682 682
 
683
-						foreach( $subscription_group['fees'] as $subscription_group_fee ) :
683
+                        foreach( $subscription_group['fees'] as $subscription_group_fee ) :
684 684
 
685
-							echo '<tr>';
685
+                            echo '<tr>';
686 686
 
687
-								foreach ( array_keys( $columns ) as $key ) {
687
+                                foreach ( array_keys( $columns ) as $key ) {
688 688
 
689
-									$class = 'text-left';
689
+                                    $class = 'text-left';
690 690
 
691
-									echo "<td class='p-2 $class'>";
691
+                                    echo "<td class='p-2 $class'>";
692 692
 
693
-										switch( $key ) {
693
+                                        switch( $key ) {
694 694
 
695
-											case 'item_name':
696
-												echo esc_html( $subscription_group_fee['name'] );
697
-												break;
695
+                                            case 'item_name':
696
+                                                echo esc_html( $subscription_group_fee['name'] );
697
+                                                break;
698 698
 
699
-											case 'price':
700
-												echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
701
-												break;
699
+                                            case 'price':
700
+                                                echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
701
+                                                break;
702 702
 
703
-											case 'tax':
704
-												echo "&mdash;";
705
-												break;
703
+                                            case 'tax':
704
+                                                echo "&mdash;";
705
+                                                break;
706 706
 
707
-											case 'discount':
708
-												echo "&mdash;";
709
-												break;
707
+                                            case 'discount':
708
+                                                echo "&mdash;";
709
+                                                break;
710 710
 
711
-											case 'initial':
712
-												echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
713
-												break;
711
+                                            case 'initial':
712
+                                                echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
713
+                                                break;
714 714
 
715
-											case 'recurring':
716
-												echo '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>';
717
-												break;
715
+                                            case 'recurring':
716
+                                                echo '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>';
717
+                                                break;
718 718
 
719
-										}
719
+                                        }
720 720
 
721
-									echo '</td>';
721
+                                    echo '</td>';
722 722
 
723
-								}
723
+                                }
724 724
 
725
-							echo '</tr>';
725
+                            echo '</tr>';
726 726
 
727
-						endforeach;
728
-					?>
727
+                        endforeach;
728
+                    ?>
729 729
 
730 730
 				</tbody>
731 731
 
@@ -744,38 +744,38 @@  discard block
 block discarded – undo
744 744
  */
745 745
 function getpaid_admin_subscription_related_subscriptions_metabox( $subscription, $skip_current = true ) {
746 746
 
747
-	// Fetch the subscription groups.
748
-	$subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() );
749
-
750
-	if ( empty( $subscription_groups ) ) {
751
-		return;
752
-	}
753
-
754
-	// Prepare table columns.
755
-	$columns = apply_filters(
756
-		'getpaid_subscription_related_subscriptions_columns',
757
-		array(
758
-			'subscription'      => __( 'Subscription', 'invoicing' ),
759
-			'start_date'        => __( 'Start Date', 'invoicing' ),
760
-			'renewal_date'      => __( 'Next Payment', 'invoicing' ),
761
-			'renewals'          => __( 'Payments', 'invoicing' ),
762
-			'item'              => __( 'Items', 'invoicing' ),
763
-			'status'            => __( 'Status', 'invoicing' ),
764
-		),
765
-		$subscription
766
-	);
767
-
768
-	if ( $subscription->get_status() == 'pending' ) {
769
-		unset( $columns['start_date'], $columns['renewal_date'] );
770
-	}
771
-
772
-	$table_class = 'w-100 bg-white';
773
-
774
-	if ( ! is_admin() ) {
775
-		$table_class = 'table table-bordered';
776
-	}
777
-
778
-	?>
747
+    // Fetch the subscription groups.
748
+    $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() );
749
+
750
+    if ( empty( $subscription_groups ) ) {
751
+        return;
752
+    }
753
+
754
+    // Prepare table columns.
755
+    $columns = apply_filters(
756
+        'getpaid_subscription_related_subscriptions_columns',
757
+        array(
758
+            'subscription'      => __( 'Subscription', 'invoicing' ),
759
+            'start_date'        => __( 'Start Date', 'invoicing' ),
760
+            'renewal_date'      => __( 'Next Payment', 'invoicing' ),
761
+            'renewals'          => __( 'Payments', 'invoicing' ),
762
+            'item'              => __( 'Items', 'invoicing' ),
763
+            'status'            => __( 'Status', 'invoicing' ),
764
+        ),
765
+        $subscription
766
+    );
767
+
768
+    if ( $subscription->get_status() == 'pending' ) {
769
+        unset( $columns['start_date'], $columns['renewal_date'] );
770
+    }
771
+
772
+    $table_class = 'w-100 bg-white';
773
+
774
+    if ( ! is_admin() ) {
775
+        $table_class = 'table table-bordered';
776
+    }
777
+
778
+    ?>
779 779
 		<div class="m-0" style="overflow: auto;">
780 780
 
781 781
 			<table class="<?php echo $table_class; ?>">
@@ -784,14 +784,14 @@  discard block
 block discarded – undo
784 784
 					<tr>
785 785
 						<?php
786 786
 
787
-							foreach ( $columns as $key => $label ) {
788
-								$key   = esc_attr( $key );
789
-								$label = esc_html( $label );
790
-								$class = 'text-left';
787
+                            foreach ( $columns as $key => $label ) {
788
+                                $key   = esc_attr( $key );
789
+                                $label = esc_html( $label );
790
+                                $class = 'text-left';
791 791
 
792
-								echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
793
-							}
794
-						?>
792
+                                echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
793
+                            }
794
+                        ?>
795 795
 					</tr>
796 796
 				</thead>
797 797
 
@@ -799,74 +799,74 @@  discard block
 block discarded – undo
799 799
 
800 800
 					<?php
801 801
 
802
-						foreach( $subscription_groups as $subscription_group ) :
802
+                        foreach( $subscription_groups as $subscription_group ) :
803 803
 
804
-							// Do not list current subscription.
805
-							if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) {
806
-								continue;
807
-							}
804
+                            // Do not list current subscription.
805
+                            if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) {
806
+                                continue;
807
+                            }
808 808
 
809
-							// Ensure the subscription exists.
810
-							$_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] );
809
+                            // Ensure the subscription exists.
810
+                            $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] );
811 811
 
812
-							if ( ! $_suscription->exists() ) {
813
-								continue;
814
-							}
812
+                            if ( ! $_suscription->exists() ) {
813
+                                continue;
814
+                            }
815 815
 
816
-							echo '<tr>';
816
+                            echo '<tr>';
817 817
 
818
-								foreach ( array_keys( $columns ) as $key ) {
818
+                                foreach ( array_keys( $columns ) as $key ) {
819 819
 
820
-									$class = 'text-left';
820
+                                    $class = 'text-left';
821 821
 
822
-									echo "<td class='p-2 $class'>";
822
+                                    echo "<td class='p-2 $class'>";
823 823
 
824
-										switch( $key ) {
824
+                                        switch( $key ) {
825 825
 
826
-											case 'status':
827
-												echo $_suscription->get_status_label_html();
828
-												break;
826
+                                            case 'status':
827
+                                                echo $_suscription->get_status_label_html();
828
+                                                break;
829 829
 
830
-											case 'item':
831
-												$markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
832
-												echo implode( ' | ', $markup );
833
-												break;
830
+                                            case 'item':
831
+                                                $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
832
+                                                echo implode( ' | ', $markup );
833
+                                                break;
834 834
 
835
-											case 'renewals':
836
-												$max_bills = $_suscription->get_bill_times();
837
-												echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
838
-												break;
835
+                                            case 'renewals':
836
+                                                $max_bills = $_suscription->get_bill_times();
837
+                                                echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
838
+                                                break;
839 839
 
840
-											case 'renewal_date':
841
-												echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "&mdash;";
842
-												break;
840
+                                            case 'renewal_date':
841
+                                                echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "&mdash;";
842
+                                                break;
843 843
 
844
-											case 'start_date':
845
-												echo 'pending' == $_suscription->get_status() ? "&mdash;" : getpaid_format_date_value( $_suscription->get_date_created() );
846
-												break;
844
+                                            case 'start_date':
845
+                                                echo 'pending' == $_suscription->get_status() ? "&mdash;" : getpaid_format_date_value( $_suscription->get_date_created() );
846
+                                                break;
847 847
 
848
-											case 'subscription':
849
-												$url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url();
850
-												printf(
851
-													'%1$s#%2$s%3$s',
852
-													'<a href="' . esc_url( $url ) . '">',
853
-													'<strong>' . intval( $_suscription->get_id() ) . '</strong>',
854
-													'</a>'
855
-												);
848
+                                            case 'subscription':
849
+                                                $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url();
850
+                                                printf(
851
+                                                    '%1$s#%2$s%3$s',
852
+                                                    '<a href="' . esc_url( $url ) . '">',
853
+                                                    '<strong>' . intval( $_suscription->get_id() ) . '</strong>',
854
+                                                    '</a>'
855
+                                                );
856 856
 
857
-												echo WPInv_Subscriptions_List_Table::column_amount( $_suscription );
858
-												break;
857
+                                                echo WPInv_Subscriptions_List_Table::column_amount( $_suscription );
858
+                                                break;
859 859
 
860
-										}
860
+                                        }
861 861
 
862
-									echo '</td>';
862
+                                    echo '</td>';
863 863
 
864
-								}
864
+                                }
865 865
 
866
-							echo '</tr>';
866
+                            echo '</tr>';
867 867
 
868
-						endforeach;
869
-					?>
868
+                        endforeach;
869
+                    ?>
870 870
 
871 871
 				</tbody>
872 872
 
Please login to merge, or discard this patch.
Spacing   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Contains functions that display the subscriptions admin page.
4 4
  */
5 5
 
6
-defined( 'ABSPATH' ) || exit;
6
+defined('ABSPATH') || exit;
7 7
 
8 8
 /**
9 9
  * Render the Subscriptions page
@@ -17,22 +17,22 @@  discard block
 block discarded – undo
17 17
 	?>
18 18
 
19 19
 	<div class="wrap">
20
-		<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
20
+		<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
21 21
 		<div class="bsui">
22 22
 
23 23
 			<?php
24 24
 
25 25
 				// Verify user permissions.
26
-				if ( ! wpinv_current_user_can_manage_invoicing() ) {
26
+				if (!wpinv_current_user_can_manage_invoicing()) {
27 27
 
28 28
 					echo aui()->alert(
29 29
 						array(
30 30
 							'type'    => 'danger',
31
-							'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
31
+							'content' => __('You are not permitted to view this page.', 'invoicing'),
32 32
 						)
33 33
 					);
34 34
 
35
-				} else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
35
+				} else if (!empty($_GET['id']) && is_numeric($_GET['id'])) {
36 36
 
37 37
 					// Display a single subscription.
38 38
 					wpinv_recurring_subscription_details();
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	<?php $subscribers_table->views(); ?>
67 67
 	<form id="subscribers-filter" class="bsui" method="get">
68 68
 		<input type="hidden" name="page" value="wpinv-subscriptions" />
69
-		<?php $subscribers_table->search_box( __( 'Search Subscriptions', 'invoicing' ), 'getpaid-search-subscriptions' ); ?>
69
+		<?php $subscribers_table->search_box(__('Search Subscriptions', 'invoicing'), 'getpaid-search-subscriptions'); ?>
70 70
 		<?php $subscribers_table->display(); ?>
71 71
 	</form>
72 72
 	<?php
@@ -82,13 +82,13 @@  discard block
 block discarded – undo
82 82
 function wpinv_recurring_subscription_details() {
83 83
 
84 84
 	// Fetch the subscription.
85
-	$sub = new WPInv_Subscription( (int) $_GET['id'] );
86
-	if ( ! $sub->exists() ) {
85
+	$sub = new WPInv_Subscription((int) $_GET['id']);
86
+	if (!$sub->exists()) {
87 87
 
88 88
 		echo aui()->alert(
89 89
 			array(
90 90
 				'type'    => 'danger',
91
-				'content' => __( 'Subscription not found.', 'invoicing' ),
91
+				'content' => __('Subscription not found.', 'invoicing'),
92 92
 			)
93 93
 		);
94 94
 
@@ -96,45 +96,45 @@  discard block
 block discarded – undo
96 96
 	}
97 97
 
98 98
 	// Use metaboxes to display the subscription details.
99
-	add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' );
100
-	add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
99
+	add_meta_box('getpaid_admin_subscription_details_metabox', __('Subscription Details', 'invoicing'), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high');
100
+	add_meta_box('getpaid_admin_subscription_update_metabox', __('Change Status', 'invoicing'), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side');
101 101
 
102 102
 	$subscription_id     = $sub->get_id();
103
-	$subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() );
104
-	$subscription_group  = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
103
+	$subscription_groups = getpaid_get_invoice_subscription_groups($sub->get_parent_invoice_id());
104
+	$subscription_group  = wp_list_filter($subscription_groups, compact('subscription_id'));
105 105
 
106
-	if ( 1 < count( $subscription_groups ) ) {
107
-		add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' );
106
+	if (1 < count($subscription_groups)) {
107
+		add_meta_box('getpaid_admin_subscription_related_subscriptions_metabox', __('Related Subscriptions', 'invoicing'), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced');
108 108
 	}
109 109
 
110
-	if ( ! empty( $subscription_group ) ) {
111
-		add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' );
110
+	if (!empty($subscription_group)) {
111
+		add_meta_box('getpaid_admin_subscription_item_details_metabox', __('Subscription Items', 'invoicing'), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low');
112 112
 	}
113 113
 
114
-	add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
114
+	add_meta_box('getpaid_admin_subscription_invoice_details_metabox', __('Related Invoices', 'invoicing'), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced');
115 115
 
116
-	do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
116
+	do_action('getpaid_admin_single_subscription_register_metabox', $sub);
117 117
 
118 118
 	?>
119 119
 
120
-		<form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>">
120
+		<form method="post" action="<?php echo admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($sub->get_id())); ?>">
121 121
 
122
-			<?php wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); ?>
123
-			<?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
124
-			<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
122
+			<?php wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); ?>
123
+			<?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); ?>
124
+			<?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); ?>
125 125
 			<input type="hidden" name="getpaid-admin-action" value="update_single_subscription" />
126
-			<input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id() ;?>" />
126
+			<input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id(); ?>" />
127 127
 
128 128
 			<div id="poststuff">
129 129
 				<div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
130 130
 
131 131
 					<div id="postbox-container-1" class="postbox-container">
132
-						<?php do_meta_boxes( get_current_screen(), 'side', $sub ); ?>
132
+						<?php do_meta_boxes(get_current_screen(), 'side', $sub); ?>
133 133
 					</div>
134 134
 
135 135
 					<div id="postbox-container-2" class="postbox-container">
136
-						<?php do_meta_boxes( get_current_screen(), 'normal', $sub ); ?>
137
-						<?php do_meta_boxes( get_current_screen(), 'advanced', $sub ); ?>
136
+						<?php do_meta_boxes(get_current_screen(), 'normal', $sub); ?>
137
+						<?php do_meta_boxes(get_current_screen(), 'advanced', $sub); ?>
138 138
 					</div>
139 139
 
140 140
 				</div>
@@ -153,44 +153,44 @@  discard block
 block discarded – undo
153 153
  *
154 154
  * @param WPInv_Subscription $sub
155 155
  */
156
-function getpaid_admin_subscription_details_metabox( $sub ) {
156
+function getpaid_admin_subscription_details_metabox($sub) {
157 157
 
158 158
 	// Subscription items.
159
-	$subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() );
160
-	$items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
159
+	$subscription_group = getpaid_get_invoice_subscription_group($sub->get_parent_invoice_id(), $sub->get_id());
160
+	$items_count        = empty($subscription_group) ? 1 : count($subscription_group['items']);
161 161
 
162 162
 	// Prepare subscription detail columns.
163 163
 	$fields = apply_filters(
164 164
 		'getpaid_subscription_admin_page_fields',
165 165
 		array(
166
-			'subscription'   => __( 'Subscription', 'invoicing' ),
167
-			'customer'       => __( 'Customer', 'invoicing' ),
168
-			'amount'         => __( 'Amount', 'invoicing' ),
169
-			'start_date'     => __( 'Start Date', 'invoicing' ),
170
-			'renews_on'      => __( 'Next Payment', 'invoicing' ),
171
-			'renewals'       => __( 'Payments', 'invoicing' ),
172
-			'item'           => _n( 'Item', 'Items', $items_count,  'invoicing' ),
173
-			'gateway'        => __( 'Payment Method', 'invoicing' ),
174
-			'profile_id'     => __( 'Profile ID', 'invoicing' ),
175
-			'status'         => __( 'Status', 'invoicing' ),
166
+			'subscription'   => __('Subscription', 'invoicing'),
167
+			'customer'       => __('Customer', 'invoicing'),
168
+			'amount'         => __('Amount', 'invoicing'),
169
+			'start_date'     => __('Start Date', 'invoicing'),
170
+			'renews_on'      => __('Next Payment', 'invoicing'),
171
+			'renewals'       => __('Payments', 'invoicing'),
172
+			'item'           => _n('Item', 'Items', $items_count, 'invoicing'),
173
+			'gateway'        => __('Payment Method', 'invoicing'),
174
+			'profile_id'     => __('Profile ID', 'invoicing'),
175
+			'status'         => __('Status', 'invoicing'),
176 176
 		)
177 177
 	);
178 178
 
179
-	if ( ! $sub->is_active() ) {
179
+	if (!$sub->is_active()) {
180 180
 
181
-		if ( isset( $fields['renews_on'] ) ) {
182
-			unset( $fields['renews_on'] );
181
+		if (isset($fields['renews_on'])) {
182
+			unset($fields['renews_on']);
183 183
 		}
184 184
 
185
-		if ( isset( $fields['gateway'] ) ) {
186
-			unset( $fields['gateway'] );
185
+		if (isset($fields['gateway'])) {
186
+			unset($fields['gateway']);
187 187
 		}
188 188
 
189 189
 	}
190 190
 
191 191
 	$profile_id = $sub->get_profile_id();
192
-	if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
193
-		unset( $fields['profile_id'] );
192
+	if (empty($profile_id) && isset($fields['profile_id'])) {
193
+		unset($fields['profile_id']);
194 194
 	}
195 195
 
196 196
 	?>
@@ -198,16 +198,16 @@  discard block
 block discarded – undo
198 198
 		<table class="table table-borderless" style="font-size: 14px;">
199 199
 			<tbody>
200 200
 
201
-				<?php foreach ( $fields as $key => $label ) : ?>
201
+				<?php foreach ($fields as $key => $label) : ?>
202 202
 
203
-					<tr class="getpaid-subscription-meta-<?php echo sanitize_html_class( $key ); ?>">
203
+					<tr class="getpaid-subscription-meta-<?php echo sanitize_html_class($key); ?>">
204 204
 
205 205
 						<th class="w-25" style="font-weight: 500;">
206
-							<?php echo esc_html( $label ); ?>
206
+							<?php echo esc_html($label); ?>
207 207
 						</th>
208 208
 
209 209
 						<td class="w-75 text-muted">
210
-							<?php do_action( 'getpaid_subscription_admin_display_' . sanitize_key( $key ), $sub, $subscription_group ); ?>
210
+							<?php do_action('getpaid_subscription_admin_display_' . sanitize_key($key), $sub, $subscription_group); ?>
211 211
 						</td>
212 212
 
213 213
 					</tr>
@@ -225,129 +225,129 @@  discard block
 block discarded – undo
225 225
  *
226 226
  * @param WPInv_Subscription $subscription
227 227
  */
228
-function getpaid_admin_subscription_metabox_display_customer( $subscription ) {
228
+function getpaid_admin_subscription_metabox_display_customer($subscription) {
229 229
 
230
-	$username = __( '(Missing User)', 'invoicing' );
230
+	$username = __('(Missing User)', 'invoicing');
231 231
 
232
-	$user = get_userdata( $subscription->get_customer_id() );
233
-	if ( $user ) {
232
+	$user = get_userdata($subscription->get_customer_id());
233
+	if ($user) {
234 234
 
235 235
 		$username = sprintf(
236 236
 			'<a href="user-edit.php?user_id=%s">%s</a>',
237
-			absint( $user->ID ),
238
-			! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email )
237
+			absint($user->ID),
238
+			!empty($user->display_name) ? esc_html($user->display_name) : sanitize_email($user->user_email)
239 239
 		);
240 240
 
241 241
 	}
242 242
 
243 243
 	echo  $username;
244 244
 }
245
-add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' );
245
+add_action('getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer');
246 246
 
247 247
 /**
248 248
  * Displays the subscription amount.
249 249
  *
250 250
  * @param WPInv_Subscription $subscription
251 251
  */
252
-function getpaid_admin_subscription_metabox_display_amount( $subscription ) {
253
-	$amount    = wp_kses_post( getpaid_get_formatted_subscription_amount( $subscription ) );
252
+function getpaid_admin_subscription_metabox_display_amount($subscription) {
253
+	$amount = wp_kses_post(getpaid_get_formatted_subscription_amount($subscription));
254 254
 	echo "<span>$amount</span>";
255 255
 }
256
-add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' );
256
+add_action('getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount');
257 257
 
258 258
 /**
259 259
  * Displays the subscription id.
260 260
  *
261 261
  * @param WPInv_Subscription $subscription
262 262
  */
263
-function getpaid_admin_subscription_metabox_display_id( $subscription ) {
264
-	echo  '#' . absint( $subscription->get_id() );
263
+function getpaid_admin_subscription_metabox_display_id($subscription) {
264
+	echo  '#' . absint($subscription->get_id());
265 265
 }
266
-add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' );
266
+add_action('getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id');
267 267
 
268 268
 /**
269 269
  * Displays the subscription renewal date.
270 270
  *
271 271
  * @param WPInv_Subscription $subscription
272 272
  */
273
-function getpaid_admin_subscription_metabox_display_start_date( $subscription ) {
274
-	echo getpaid_format_date_value( $subscription->get_date_created() );
273
+function getpaid_admin_subscription_metabox_display_start_date($subscription) {
274
+	echo getpaid_format_date_value($subscription->get_date_created());
275 275
 }
276
-add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' );
276
+add_action('getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date');
277 277
 
278 278
 /**
279 279
  * Displays the subscription renewal date.
280 280
  *
281 281
  * @param WPInv_Subscription $subscription
282 282
  */
283
-function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) {
284
-	echo getpaid_format_date_value( $subscription->get_expiration() );
283
+function getpaid_admin_subscription_metabox_display_renews_on($subscription) {
284
+	echo getpaid_format_date_value($subscription->get_expiration());
285 285
 }
286
-add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' );
286
+add_action('getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on');
287 287
 
288 288
 /**
289 289
  * Displays the subscription renewal count.
290 290
  *
291 291
  * @param WPInv_Subscription $subscription
292 292
  */
293
-function getpaid_admin_subscription_metabox_display_renewals( $subscription ) {
293
+function getpaid_admin_subscription_metabox_display_renewals($subscription) {
294 294
 	$max_bills = $subscription->get_bill_times();
295
-	echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
295
+	echo $subscription->get_times_billed() . ' / ' . (empty($max_bills) ? "&infin;" : $max_bills);
296 296
 }
297
-add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' );
297
+add_action('getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals');
298 298
 /**
299 299
  * Displays the subscription item.
300 300
  *
301 301
  * @param WPInv_Subscription $subscription
302 302
  * @param false|array $subscription_group
303 303
  */
304
-function getpaid_admin_subscription_metabox_display_item( $subscription, $subscription_group = false ) {
304
+function getpaid_admin_subscription_metabox_display_item($subscription, $subscription_group = false) {
305 305
 
306
-	if ( empty( $subscription_group ) ) {
307
-		echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() );
306
+	if (empty($subscription_group)) {
307
+		echo WPInv_Subscriptions_List_Table::generate_item_markup($subscription->get_product_id());
308 308
 		return;
309 309
 	}
310 310
 
311
-	$markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
312
-	echo implode( ' | ', $markup );
311
+	$markup = array_map(array('WPInv_Subscriptions_List_Table', 'generate_item_markup'), array_keys($subscription_group['items']));
312
+	echo implode(' | ', $markup);
313 313
 
314 314
 }
315
-add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2 );
315
+add_action('getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2);
316 316
 
317 317
 /**
318 318
  * Displays the subscription gateway.
319 319
  *
320 320
  * @param WPInv_Subscription $subscription
321 321
  */
322
-function getpaid_admin_subscription_metabox_display_gateway( $subscription ) {
322
+function getpaid_admin_subscription_metabox_display_gateway($subscription) {
323 323
 
324 324
 	$gateway = $subscription->get_gateway();
325 325
 
326
-	if ( ! empty( $gateway ) ) {
327
-		echo esc_html( wpinv_get_gateway_admin_label( $gateway ) );
326
+	if (!empty($gateway)) {
327
+		echo esc_html(wpinv_get_gateway_admin_label($gateway));
328 328
 	} else {
329 329
 		echo "&mdash;";
330 330
 	}
331 331
 
332 332
 }
333
-add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' );
333
+add_action('getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway');
334 334
 
335 335
 /**
336 336
  * Displays the subscription status.
337 337
  *
338 338
  * @param WPInv_Subscription $subscription
339 339
  */
340
-function getpaid_admin_subscription_metabox_display_status( $subscription ) {
340
+function getpaid_admin_subscription_metabox_display_status($subscription) {
341 341
 	echo $subscription->get_status_label_html();
342 342
 }
343
-add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' );
343
+add_action('getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status');
344 344
 
345 345
 /**
346 346
  * Displays the subscription profile id.
347 347
  *
348 348
  * @param WPInv_Subscription $subscription
349 349
  */
350
-function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) {
350
+function getpaid_admin_subscription_metabox_display_profile_id($subscription) {
351 351
 
352 352
 	$profile_id = $subscription->get_profile_id();
353 353
 
@@ -356,32 +356,32 @@  discard block
 block discarded – undo
356 356
 			'type'        => 'text',
357 357
 			'id'          => 'wpinv_subscription_profile_id',
358 358
 			'name'        => 'wpinv_subscription_profile_id',
359
-			'label'       => __( 'Profile Id', 'invoicing' ),
359
+			'label'       => __('Profile Id', 'invoicing'),
360 360
 			'label_type'  => 'hidden',
361
-			'placeholder' => __( 'Profile Id', 'invoicing' ),
362
-			'value'       => esc_attr( $profile_id ),
361
+			'placeholder' => __('Profile Id', 'invoicing'),
362
+			'value'       => esc_attr($profile_id),
363 363
 			'input_group_right' => '',
364 364
 			'no_wrap'     => true,
365 365
 		)
366 366
 	);
367 367
 
368
-	echo str_ireplace( 'form-control', 'regular-text', $input );
368
+	echo str_ireplace('form-control', 'regular-text', $input);
369 369
 
370
-	$url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription );
371
-	if ( ! empty( $url ) ) {
372
-		$url = esc_url_raw( $url );
373
-		echo '&nbsp;<a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
370
+	$url = apply_filters('getpaid_remote_subscription_profile_url', '', $subscription);
371
+	if (!empty($url)) {
372
+		$url = esc_url_raw($url);
373
+		echo '&nbsp;<a href="' . $url . '" title="' . __('View in Gateway', 'invoicing') . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
374 374
 	}
375 375
 
376 376
 }
377
-add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' );
377
+add_action('getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id');
378 378
 
379 379
 /**
380 380
  * Displays the subscriptions update metabox.
381 381
  *
382 382
  * @param WPInv_Subscription $subscription
383 383
  */
384
-function getpaid_admin_subscription_update_metabox( $subscription ) {
384
+function getpaid_admin_subscription_update_metabox($subscription) {
385 385
 
386 386
 	?>
387 387
 	<div class="mt-3">
@@ -394,10 +394,10 @@  discard block
 block discarded – undo
394 394
 					'id'               => 'subscription_status_update_select',
395 395
 					'required'         => true,
396 396
 					'no_wrap'          => false,
397
-					'label'            => __( 'Subscription Status', 'invoicing' ),
398
-					'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
397
+					'label'            => __('Subscription Status', 'invoicing'),
398
+					'help_text'        => __('Updating the status will trigger related actions and hooks', 'invoicing'),
399 399
 					'select2'          => true,
400
-					'value'            => $subscription->get_status( 'edit' ),
400
+					'value'            => $subscription->get_status('edit'),
401 401
 				)
402 402
 			);
403 403
 		?>
@@ -405,13 +405,13 @@  discard block
 block discarded – undo
405 405
 		<div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;">
406 406
 
407 407
 		<?php
408
-			submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
408
+			submit_button(__('Update', 'invoicing'), 'primary', 'submit', false);
409 409
 
410
-			$url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
411
-			$anchor = __( 'Renew Subscription', 'invoicing' );
412
-			$title  = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' );
410
+			$url    = esc_url(wp_nonce_url(add_query_arg('getpaid-admin-action', 'subscription_manual_renew'), 'getpaid-nonce', 'getpaid-nonce'));
411
+			$anchor = __('Renew Subscription', 'invoicing');
412
+			$title  = esc_attr__('Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing');
413 413
 
414
-			if ( $subscription->is_active() ) {
414
+			if ($subscription->is_active()) {
415 415
 				echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
416 416
 			}
417 417
 
@@ -424,31 +424,31 @@  discard block
 block discarded – undo
424 424
  * @param WPInv_Subscription $subscription
425 425
  * @param bool $strict Whether or not to skip invoices of sibling subscriptions
426 426
  */
427
-function getpaid_admin_subscription_invoice_details_metabox( $subscription, $strict = true ) {
427
+function getpaid_admin_subscription_invoice_details_metabox($subscription, $strict = true) {
428 428
 
429 429
 	$columns = apply_filters(
430 430
 		'getpaid_subscription_related_invoices_columns',
431 431
 		array(
432
-			'invoice'      => __( 'Invoice', 'invoicing' ),
433
-			'relationship' => __( 'Relationship', 'invoicing' ),
434
-			'date'         => __( 'Date', 'invoicing' ),
435
-			'status'       => __( 'Status', 'invoicing' ),
436
-			'total'        => __( 'Total', 'invoicing' ),
432
+			'invoice'      => __('Invoice', 'invoicing'),
433
+			'relationship' => __('Relationship', 'invoicing'),
434
+			'date'         => __('Date', 'invoicing'),
435
+			'status'       => __('Status', 'invoicing'),
436
+			'total'        => __('Total', 'invoicing'),
437 437
 		),
438 438
 		$subscription
439 439
 	);
440 440
 
441 441
 	// Prepare the invoices.
442
-	$payments = $subscription->get_child_payments( ! is_admin() );
442
+	$payments = $subscription->get_child_payments(!is_admin());
443 443
 	$parent   = $subscription->get_parent_invoice();
444 444
 
445
-	if ( $parent->exists() ) {
446
-		$payments = array_merge( array( $parent ), $payments );
445
+	if ($parent->exists()) {
446
+		$payments = array_merge(array($parent), $payments);
447 447
 	}
448 448
 
449 449
 	$table_class = 'w-100 bg-white';
450 450
 
451
-	if ( ! is_admin() ) {
451
+	if (!is_admin()) {
452 452
 		$table_class = 'table table-bordered';
453 453
 	}
454 454
 
@@ -460,9 +460,9 @@  discard block
 block discarded – undo
460 460
 				<thead>
461 461
 					<tr>
462 462
 						<?php
463
-							foreach ( $columns as $key => $label ) {
464
-								$key   = esc_attr( $key );
465
-								$label = esc_html( $label );
463
+							foreach ($columns as $key => $label) {
464
+								$key   = esc_attr($key);
465
+								$label = esc_html($label);
466 466
 								$class = 'text-left';
467 467
 
468 468
 								echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
@@ -473,57 +473,57 @@  discard block
 block discarded – undo
473 473
 
474 474
 				<tbody>
475 475
 
476
-					<?php if ( empty( $payments ) ) : ?>
476
+					<?php if (empty($payments)) : ?>
477 477
 						<tr>
478 478
 							<td colspan="<?php echo count($columns); ?>" class="p-2 text-left text-muted">
479
-								<?php _e( 'This subscription has no invoices.', 'invoicing' ); ?>
479
+								<?php _e('This subscription has no invoices.', 'invoicing'); ?>
480 480
 							</td>
481 481
 						</tr>
482 482
 					<?php endif; ?>
483 483
 
484 484
 					<?php
485 485
 
486
-						foreach( $payments as $payment ) :
486
+						foreach ($payments as $payment) :
487 487
 
488 488
 							// Ensure that we have an invoice.
489
-							$payment = new WPInv_Invoice( $payment );
489
+							$payment = new WPInv_Invoice($payment);
490 490
 
491 491
 							// Abort if the invoice is invalid...
492
-							if ( ! $payment->exists() ) {
492
+							if (!$payment->exists()) {
493 493
 								continue;
494 494
 							}
495 495
 
496 496
 							// ... or belongs to a different subscription.
497
-							if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) {
497
+							if ($strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id()) {
498 498
 								continue;
499 499
 							}
500 500
 
501 501
 							echo '<tr>';
502 502
 
503
-								foreach ( array_keys( $columns ) as $key ) {
503
+								foreach (array_keys($columns) as $key) {
504 504
 
505 505
 									$class = 'text-left';
506 506
 
507 507
 									echo "<td class='p-2 $class'>";
508 508
 
509
-										switch( $key ) {
509
+										switch ($key) {
510 510
 
511 511
 											case 'total':
512
-												echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>';
512
+												echo '<strong>' . wpinv_price($payment->get_total(), $payment->get_currency()) . '</strong>';
513 513
 												break;
514 514
 
515 515
 											case 'relationship':
516
-												echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
516
+												echo $payment->is_renewal() ? __('Renewal Invoice', 'invoicing') : __('Initial Invoice', 'invoicing');
517 517
 												break;
518 518
 
519 519
 											case 'date':
520
-												echo getpaid_format_date_value( $payment->get_date_created() );
520
+												echo getpaid_format_date_value($payment->get_date_created());
521 521
 												break;
522 522
 
523 523
 											case 'status':
524 524
 
525 525
 												$status = $payment->get_status_nicename();
526
-												if ( is_admin() ) {
526
+												if (is_admin()) {
527 527
 													$status = $payment->get_status_label_html();
528 528
 												}
529 529
 
@@ -531,13 +531,13 @@  discard block
 block discarded – undo
531 531
 												break;
532 532
 
533 533
 											case 'invoice':
534
-												$link    = esc_url( get_edit_post_link( $payment->get_id() ) );
534
+												$link = esc_url(get_edit_post_link($payment->get_id()));
535 535
 
536
-												if ( ! is_admin() ) {
537
-													$link = esc_url( $payment->get_view_url() );
536
+												if (!is_admin()) {
537
+													$link = esc_url($payment->get_view_url());
538 538
 												}
539 539
 
540
-												$invoice = esc_html( $payment->get_number() );
540
+												$invoice = esc_html($payment->get_number());
541 541
 												echo "<a href='$link'>$invoice</a>";
542 542
 												break;
543 543
 										}
@@ -565,12 +565,12 @@  discard block
 block discarded – undo
565 565
  *
566 566
  * @param WPInv_Subscription $subscription
567 567
  */
568
-function getpaid_admin_subscription_item_details_metabox( $subscription ) {
568
+function getpaid_admin_subscription_item_details_metabox($subscription) {
569 569
 
570 570
 	// Fetch the subscription group.
571
-	$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() );
571
+	$subscription_group = getpaid_get_invoice_subscription_group($subscription->get_parent_payment_id(), $subscription->get_id());
572 572
 
573
-	if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) {
573
+	if (empty($subscription_group) || empty($subscription_group['items'])) {
574 574
 		return;
575 575
 	}
576 576
 
@@ -578,12 +578,12 @@  discard block
 block discarded – undo
578 578
 	$columns = apply_filters(
579 579
 		'getpaid_subscription_item_details_columns',
580 580
 		array(
581
-			'item_name'    => __( 'Item', 'invoicing' ),
582
-			'price'        => __( 'Price', 'invoicing' ),
583
-			'tax'          => __( 'Tax', 'invoicing' ),
584
-			'discount'     => __( 'Discount', 'invoicing' ),
581
+			'item_name'    => __('Item', 'invoicing'),
582
+			'price'        => __('Price', 'invoicing'),
583
+			'tax'          => __('Tax', 'invoicing'),
584
+			'discount'     => __('Discount', 'invoicing'),
585 585
 			//'initial'      => __( 'Initial Amount', 'invoicing' ),
586
-			'recurring'    => __( 'Subtotal', 'invoicing' ),
586
+			'recurring'    => __('Subtotal', 'invoicing'),
587 587
 		),
588 588
 		$subscription
589 589
 	);
@@ -592,13 +592,13 @@  discard block
 block discarded – undo
592 592
 
593 593
 	$invoice = $subscription->get_parent_invoice();
594 594
 
595
-	if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) {
596
-		unset( $columns['tax'] );
595
+	if ((!wpinv_use_taxes() || !$invoice->is_taxable()) && isset($columns['tax'])) {
596
+		unset($columns['tax']);
597 597
 	}
598 598
 
599 599
 	$table_class = 'w-100 bg-white';
600 600
 
601
-	if ( ! is_admin() ) {
601
+	if (!is_admin()) {
602 602
 		$table_class = 'table table-bordered';
603 603
 	}
604 604
 
@@ -611,9 +611,9 @@  discard block
 block discarded – undo
611 611
 					<tr>
612 612
 						<?php
613 613
 
614
-							foreach ( $columns as $key => $label ) {
615
-								$key   = esc_attr( $key );
616
-								$label = esc_html( $label );
614
+							foreach ($columns as $key => $label) {
615
+								$key   = esc_attr($key);
616
+								$label = esc_html($label);
617 617
 								$class = 'text-left';
618 618
 
619 619
 								echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
@@ -626,48 +626,48 @@  discard block
 block discarded – undo
626 626
 
627 627
 					<?php
628 628
 
629
-						foreach( $subscription_group['items'] as $subscription_group_item ) :
629
+						foreach ($subscription_group['items'] as $subscription_group_item) :
630 630
 
631 631
 							echo '<tr>';
632 632
 
633
-								foreach ( array_keys( $columns ) as $key ) {
633
+								foreach (array_keys($columns) as $key) {
634 634
 
635 635
 									$class = 'text-left';
636 636
 
637 637
 									echo "<td class='p-2 $class'>";
638 638
 
639
-										switch( $key ) {
639
+										switch ($key) {
640 640
 
641 641
 											case 'item_name':
642
-												$item_name = get_the_title( $subscription_group_item['item_id'] );
643
-												$item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name;
642
+												$item_name = get_the_title($subscription_group_item['item_id']);
643
+												$item_name = empty($item_name) ? $subscription_group_item['item_name'] : $item_name;
644 644
 
645
-												if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) {
646
-													echo esc_html( $item_name );
645
+												if ($invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity']) {
646
+													echo esc_html($item_name);
647 647
 												} else {
648
-													printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] );
648
+													printf('%1$s x %2$d', esc_html($item_name), (float) $subscription_group_item['quantity']);
649 649
 												}
650 650
 
651 651
 												break;
652 652
 
653 653
 											case 'price':
654
-												echo wpinv_price( $subscription_group_item['item_price'], $invoice->get_currency() );
654
+												echo wpinv_price($subscription_group_item['item_price'], $invoice->get_currency());
655 655
 												break;
656 656
 
657 657
 											case 'tax':
658
-												echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() );
658
+												echo wpinv_price($subscription_group_item['tax'], $invoice->get_currency());
659 659
 												break;
660 660
 
661 661
 											case 'discount':
662
-												echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() );
662
+												echo wpinv_price($subscription_group_item['discount'], $invoice->get_currency());
663 663
 												break;
664 664
 
665 665
 											case 'initial':
666
-												echo wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() );
666
+												echo wpinv_price($subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency());
667 667
 												break;
668 668
 
669 669
 											case 'recurring':
670
-												echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>';
670
+												echo '<strong>' . wpinv_price($subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency()) . '</strong>';
671 671
 												break;
672 672
 
673 673
 										}
@@ -680,24 +680,24 @@  discard block
 block discarded – undo
680 680
 
681 681
 						endforeach;
682 682
 
683
-						foreach( $subscription_group['fees'] as $subscription_group_fee ) :
683
+						foreach ($subscription_group['fees'] as $subscription_group_fee) :
684 684
 
685 685
 							echo '<tr>';
686 686
 
687
-								foreach ( array_keys( $columns ) as $key ) {
687
+								foreach (array_keys($columns) as $key) {
688 688
 
689 689
 									$class = 'text-left';
690 690
 
691 691
 									echo "<td class='p-2 $class'>";
692 692
 
693
-										switch( $key ) {
693
+										switch ($key) {
694 694
 
695 695
 											case 'item_name':
696
-												echo esc_html( $subscription_group_fee['name'] );
696
+												echo esc_html($subscription_group_fee['name']);
697 697
 												break;
698 698
 
699 699
 											case 'price':
700
-												echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
700
+												echo wpinv_price($subscription_group_fee['initial_fee'], $invoice->get_currency());
701 701
 												break;
702 702
 
703 703
 											case 'tax':
@@ -709,11 +709,11 @@  discard block
 block discarded – undo
709 709
 												break;
710 710
 
711 711
 											case 'initial':
712
-												echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
712
+												echo wpinv_price($subscription_group_fee['initial_fee'], $invoice->get_currency());
713 713
 												break;
714 714
 
715 715
 											case 'recurring':
716
-												echo '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>';
716
+												echo '<strong>' . wpinv_price($subscription_group_fee['recurring_fee'], $invoice->get_currency()) . '</strong>';
717 717
 												break;
718 718
 
719 719
 										}
@@ -742,12 +742,12 @@  discard block
 block discarded – undo
742 742
  * @param WPInv_Subscription $subscription
743 743
  * @param bool $skip_current
744 744
  */
745
-function getpaid_admin_subscription_related_subscriptions_metabox( $subscription, $skip_current = true ) {
745
+function getpaid_admin_subscription_related_subscriptions_metabox($subscription, $skip_current = true) {
746 746
 
747 747
 	// Fetch the subscription groups.
748
-	$subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() );
748
+	$subscription_groups = getpaid_get_invoice_subscription_groups($subscription->get_parent_payment_id());
749 749
 
750
-	if ( empty( $subscription_groups ) ) {
750
+	if (empty($subscription_groups)) {
751 751
 		return;
752 752
 	}
753 753
 
@@ -755,23 +755,23 @@  discard block
 block discarded – undo
755 755
 	$columns = apply_filters(
756 756
 		'getpaid_subscription_related_subscriptions_columns',
757 757
 		array(
758
-			'subscription'      => __( 'Subscription', 'invoicing' ),
759
-			'start_date'        => __( 'Start Date', 'invoicing' ),
760
-			'renewal_date'      => __( 'Next Payment', 'invoicing' ),
761
-			'renewals'          => __( 'Payments', 'invoicing' ),
762
-			'item'              => __( 'Items', 'invoicing' ),
763
-			'status'            => __( 'Status', 'invoicing' ),
758
+			'subscription'      => __('Subscription', 'invoicing'),
759
+			'start_date'        => __('Start Date', 'invoicing'),
760
+			'renewal_date'      => __('Next Payment', 'invoicing'),
761
+			'renewals'          => __('Payments', 'invoicing'),
762
+			'item'              => __('Items', 'invoicing'),
763
+			'status'            => __('Status', 'invoicing'),
764 764
 		),
765 765
 		$subscription
766 766
 	);
767 767
 
768
-	if ( $subscription->get_status() == 'pending' ) {
769
-		unset( $columns['start_date'], $columns['renewal_date'] );
768
+	if ($subscription->get_status() == 'pending') {
769
+		unset($columns['start_date'], $columns['renewal_date']);
770 770
 	}
771 771
 
772 772
 	$table_class = 'w-100 bg-white';
773 773
 
774
-	if ( ! is_admin() ) {
774
+	if (!is_admin()) {
775 775
 		$table_class = 'table table-bordered';
776 776
 	}
777 777
 
@@ -784,9 +784,9 @@  discard block
 block discarded – undo
784 784
 					<tr>
785 785
 						<?php
786 786
 
787
-							foreach ( $columns as $key => $label ) {
788
-								$key   = esc_attr( $key );
789
-								$label = esc_html( $label );
787
+							foreach ($columns as $key => $label) {
788
+								$key   = esc_attr($key);
789
+								$label = esc_html($label);
790 790
 								$class = 'text-left';
791 791
 
792 792
 								echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
@@ -799,62 +799,62 @@  discard block
 block discarded – undo
799 799
 
800 800
 					<?php
801 801
 
802
-						foreach( $subscription_groups as $subscription_group ) :
802
+						foreach ($subscription_groups as $subscription_group) :
803 803
 
804 804
 							// Do not list current subscription.
805
-							if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) {
805
+							if ($skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id()) {
806 806
 								continue;
807 807
 							}
808 808
 
809 809
 							// Ensure the subscription exists.
810
-							$_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] );
810
+							$_suscription = new WPInv_Subscription($subscription_group['subscription_id']);
811 811
 
812
-							if ( ! $_suscription->exists() ) {
812
+							if (!$_suscription->exists()) {
813 813
 								continue;
814 814
 							}
815 815
 
816 816
 							echo '<tr>';
817 817
 
818
-								foreach ( array_keys( $columns ) as $key ) {
818
+								foreach (array_keys($columns) as $key) {
819 819
 
820 820
 									$class = 'text-left';
821 821
 
822 822
 									echo "<td class='p-2 $class'>";
823 823
 
824
-										switch( $key ) {
824
+										switch ($key) {
825 825
 
826 826
 											case 'status':
827 827
 												echo $_suscription->get_status_label_html();
828 828
 												break;
829 829
 
830 830
 											case 'item':
831
-												$markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
832
-												echo implode( ' | ', $markup );
831
+												$markup = array_map(array('WPInv_Subscriptions_List_Table', 'generate_item_markup'), array_keys($subscription_group['items']));
832
+												echo implode(' | ', $markup);
833 833
 												break;
834 834
 
835 835
 											case 'renewals':
836 836
 												$max_bills = $_suscription->get_bill_times();
837
-												echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
837
+												echo $_suscription->get_times_billed() . ' / ' . (empty($max_bills) ? "&infin;" : $max_bills);
838 838
 												break;
839 839
 
840 840
 											case 'renewal_date':
841
-												echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "&mdash;";
841
+												echo $_suscription->is_active() ? getpaid_format_date_value($_suscription->get_expiration()) : "&mdash;";
842 842
 												break;
843 843
 
844 844
 											case 'start_date':
845
-												echo 'pending' == $_suscription->get_status() ? "&mdash;" : getpaid_format_date_value( $_suscription->get_date_created() );
845
+												echo 'pending' == $_suscription->get_status() ? "&mdash;" : getpaid_format_date_value($_suscription->get_date_created());
846 846
 												break;
847 847
 
848 848
 											case 'subscription':
849
-												$url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url();
849
+												$url = is_admin() ? admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($_suscription->get_id())) : $_suscription->get_view_url();
850 850
 												printf(
851 851
 													'%1$s#%2$s%3$s',
852
-													'<a href="' . esc_url( $url ) . '">',
853
-													'<strong>' . intval( $_suscription->get_id() ) . '</strong>',
852
+													'<a href="' . esc_url($url) . '">',
853
+													'<strong>' . intval($_suscription->get_id()) . '</strong>',
854 854
 													'</a>'
855 855
 												);
856 856
 
857
-												echo WPInv_Subscriptions_List_Table::column_amount( $_suscription );
857
+												echo WPInv_Subscriptions_List_Table::column_amount($_suscription);
858 858
 												break;
859 859
 
860 860
 										}
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports-export.php 2 patches
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -12,47 +12,47 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports_Export {
14 14
 
15
-	/**
16
-	 * Displays the reports tab.
17
-	 *
18
-	 */
19
-	public function display() {
20
-
21
-		echo "<div class='row mt-4' style='max-width: 920px;' >";
22
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
23
-			$this->display_post_type_export( $post_type );
24
-		}
25
-		$this->display_subscription_export();
26
-		echo "</div>";
27
-
28
-	}
29
-
30
-	/**
31
-	 * Retrieves the download url.
32
-	 *
33
-	 */
34
-	public function get_download_url( $post_type ) {
35
-
36
-		return wp_nonce_url(
37
-			add_query_arg(
38
-				array(
39
-					'getpaid-admin-action' => 'export_invoices',
40
-					'post_type'            => urlencode( $post_type ),
41
-				)
42
-			),
43
-			'getpaid-nonce',
44
-			'getpaid-nonce'
45
-		);
46
-
47
-	}
48
-
49
-	/**
50
-	 * Displays a single post type export card.
51
-	 *
52
-	 */
53
-	public function display_post_type_export( $post_type ) {
54
-
55
-		?>
15
+    /**
16
+     * Displays the reports tab.
17
+     *
18
+     */
19
+    public function display() {
20
+
21
+        echo "<div class='row mt-4' style='max-width: 920px;' >";
22
+        foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
23
+            $this->display_post_type_export( $post_type );
24
+        }
25
+        $this->display_subscription_export();
26
+        echo "</div>";
27
+
28
+    }
29
+
30
+    /**
31
+     * Retrieves the download url.
32
+     *
33
+     */
34
+    public function get_download_url( $post_type ) {
35
+
36
+        return wp_nonce_url(
37
+            add_query_arg(
38
+                array(
39
+                    'getpaid-admin-action' => 'export_invoices',
40
+                    'post_type'            => urlencode( $post_type ),
41
+                )
42
+            ),
43
+            'getpaid-nonce',
44
+            'getpaid-nonce'
45
+        );
46
+
47
+    }
48
+
49
+    /**
50
+     * Displays a single post type export card.
51
+     *
52
+     */
53
+    public function display_post_type_export( $post_type ) {
54
+
55
+        ?>
56 56
 
57 57
 		<div class="col-12 col-md-6">
58 58
 			<div class="card m-0 p-0" style="max-width:100%">
@@ -60,11 +60,11 @@  discard block
 block discarded – undo
60 60
 				<div class="card-header">
61 61
 					<strong>
62 62
 						<?php
63
-							printf(
64
-								__( 'Export %s', 'invoicing' ),
65
-								sanitize_text_field( getpaid_get_post_type_label( $post_type ) )
66
-							);
67
-						?>
63
+                            printf(
64
+                                __( 'Export %s', 'invoicing' ),
65
+                                sanitize_text_field( getpaid_get_post_type_label( $post_type ) )
66
+                            );
67
+                        ?>
68 68
 					</strong>
69 69
 				</div>
70 70
 
@@ -73,12 +73,12 @@  discard block
 block discarded – undo
73 73
 					<form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>">
74 74
 
75 75
 						<?php
76
-							$this->display_markup( $this->generate_from_date( $post_type ) );
77
-							$this->display_markup( $this->generate_to_date( $post_type ) );
78
-							$this->display_markup( $this->generate_post_status_select( $post_type ) );
79
-							$this->display_markup( $this->generate_file_type_select( $post_type ) );
80
-							submit_button( __( 'Download', 'invoicing' ) );
81
-						?>
76
+                            $this->display_markup( $this->generate_from_date( $post_type ) );
77
+                            $this->display_markup( $this->generate_to_date( $post_type ) );
78
+                            $this->display_markup( $this->generate_post_status_select( $post_type ) );
79
+                            $this->display_markup( $this->generate_file_type_select( $post_type ) );
80
+                            submit_button( __( 'Download', 'invoicing' ) );
81
+                        ?>
82 82
 
83 83
 					</form>
84 84
 
@@ -89,122 +89,122 @@  discard block
 block discarded – undo
89 89
 
90 90
 		<?php
91 91
 
92
-	}
93
-
94
-	/**
95
-	 * Generates the from date input field.
96
-	 *
97
-	 */
98
-	public function generate_from_date( $post_type ) {
99
-
100
-		return aui()->input(
101
-			array(
102
-				'name'       => 'from_date',
103
-				'id'         => esc_attr( "$post_type-from_date" ),
104
-				'placeholder'=> 'yy-mm-dd',
105
-				'label'      => __( 'From Date', 'invoicing' ),
106
-				'label_type' => 'vertical',
107
-				'label_class' => 'd-block',
108
-				'type'       => 'datepicker',
109
-			)
110
-		);
111
-
112
-	}
113
-
114
-	/**
115
-	 * Generates the to date input field.
116
-	 *
117
-	 */
118
-	public function generate_to_date( $post_type ) {
119
-
120
-		return aui()->input(
121
-			array(
122
-				'name'       => 'to_date',
123
-				'id'         => esc_attr( "$post_type-to_date" ),
124
-				'placeholder'=> 'yy-mm-dd',
125
-				'label'      => __( 'To Date', 'invoicing' ),
126
-				'label_type' => 'vertical',
127
-				'label_class' => 'd-block',
128
-				'type'       => 'datepicker',
129
-			)
130
-		);
131
-
132
-	}
133
-
134
-	/**
135
-	 * Generates the to post status select field.
136
-	 *
137
-	 */
138
-	public function generate_post_status_select( $post_type ) {
139
-
140
-		if ( 'subscriptions' === $post_type ) {
141
-			$options = getpaid_get_subscription_statuses();
142
-		} else {
143
-			$options = wpinv_get_invoice_statuses( true, false, $post_type );
144
-		}
145
-
146
-		return aui()->select(
147
-			array(
148
-				'name'        => 'status',
149
-				'id'          => esc_attr( "$post_type-status" ),
150
-				'placeholder' => __( 'All Statuses', 'invoicing' ),
151
-				'label'       => __( 'Status', 'invoicing' ),
152
-				'label_type'  => 'vertical',
153
-				'label_class' => 'd-block',
154
-				'options'     => $options,
155
-			)
156
-		);
157
-
158
-	}
159
-
160
-	/**
161
-	 * Generates the to file type select field.
162
-	 *
163
-	 */
164
-	public function generate_file_type_select( $post_type ) {
165
-
166
-		return aui()->select(
167
-			array(
168
-				'name'        => 'file_type',
169
-				'id'          => esc_attr( "$post_type-file_type" ),
170
-				'placeholder' => __( 'Select File Type', 'invoicing' ),
171
-				'label'       => __( 'Export File', 'invoicing' ),
172
-				'label_type'  => 'vertical',
173
-				'label_class' => 'd-block',
174
-				'options'     => array(
175
-					'csv'  => __( 'CSV', 'invoicing' ),
176
-					'xml'  => __( 'XML', 'invoicing' ),
177
-					'json' => __( 'JSON', 'invoicing' ),
178
-				),
179
-			)
180
-		);
181
-
182
-	}
183
-
184
-	/**
185
-	 * Displays a field's markup.
186
-	 *
187
-	 */
188
-	public function display_markup( $markup ) {
189
-
190
-		echo str_replace(
191
-			array(
192
-				'form-control',
193
-				'custom-select'
194
-			),
195
-			'regular-text',
196
-			$markup
197
-		);
198
-
199
-	}
200
-
201
-	/**
202
-	 * Displays a subscription export card.
203
-	 *
204
-	 */
205
-	public function display_subscription_export() {
206
-
207
-		?>
92
+    }
93
+
94
+    /**
95
+     * Generates the from date input field.
96
+     *
97
+     */
98
+    public function generate_from_date( $post_type ) {
99
+
100
+        return aui()->input(
101
+            array(
102
+                'name'       => 'from_date',
103
+                'id'         => esc_attr( "$post_type-from_date" ),
104
+                'placeholder'=> 'yy-mm-dd',
105
+                'label'      => __( 'From Date', 'invoicing' ),
106
+                'label_type' => 'vertical',
107
+                'label_class' => 'd-block',
108
+                'type'       => 'datepicker',
109
+            )
110
+        );
111
+
112
+    }
113
+
114
+    /**
115
+     * Generates the to date input field.
116
+     *
117
+     */
118
+    public function generate_to_date( $post_type ) {
119
+
120
+        return aui()->input(
121
+            array(
122
+                'name'       => 'to_date',
123
+                'id'         => esc_attr( "$post_type-to_date" ),
124
+                'placeholder'=> 'yy-mm-dd',
125
+                'label'      => __( 'To Date', 'invoicing' ),
126
+                'label_type' => 'vertical',
127
+                'label_class' => 'd-block',
128
+                'type'       => 'datepicker',
129
+            )
130
+        );
131
+
132
+    }
133
+
134
+    /**
135
+     * Generates the to post status select field.
136
+     *
137
+     */
138
+    public function generate_post_status_select( $post_type ) {
139
+
140
+        if ( 'subscriptions' === $post_type ) {
141
+            $options = getpaid_get_subscription_statuses();
142
+        } else {
143
+            $options = wpinv_get_invoice_statuses( true, false, $post_type );
144
+        }
145
+
146
+        return aui()->select(
147
+            array(
148
+                'name'        => 'status',
149
+                'id'          => esc_attr( "$post_type-status" ),
150
+                'placeholder' => __( 'All Statuses', 'invoicing' ),
151
+                'label'       => __( 'Status', 'invoicing' ),
152
+                'label_type'  => 'vertical',
153
+                'label_class' => 'd-block',
154
+                'options'     => $options,
155
+            )
156
+        );
157
+
158
+    }
159
+
160
+    /**
161
+     * Generates the to file type select field.
162
+     *
163
+     */
164
+    public function generate_file_type_select( $post_type ) {
165
+
166
+        return aui()->select(
167
+            array(
168
+                'name'        => 'file_type',
169
+                'id'          => esc_attr( "$post_type-file_type" ),
170
+                'placeholder' => __( 'Select File Type', 'invoicing' ),
171
+                'label'       => __( 'Export File', 'invoicing' ),
172
+                'label_type'  => 'vertical',
173
+                'label_class' => 'd-block',
174
+                'options'     => array(
175
+                    'csv'  => __( 'CSV', 'invoicing' ),
176
+                    'xml'  => __( 'XML', 'invoicing' ),
177
+                    'json' => __( 'JSON', 'invoicing' ),
178
+                ),
179
+            )
180
+        );
181
+
182
+    }
183
+
184
+    /**
185
+     * Displays a field's markup.
186
+     *
187
+     */
188
+    public function display_markup( $markup ) {
189
+
190
+        echo str_replace(
191
+            array(
192
+                'form-control',
193
+                'custom-select'
194
+            ),
195
+            'regular-text',
196
+            $markup
197
+        );
198
+
199
+    }
200
+
201
+    /**
202
+     * Displays a subscription export card.
203
+     *
204
+     */
205
+    public function display_subscription_export() {
206
+
207
+        ?>
208 208
 
209 209
 		<div class="col-12 col-md-6">
210 210
 			<div class="card m-0 p-0" style="max-width:100%">
@@ -220,12 +220,12 @@  discard block
 block discarded – undo
220 220
 					<form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>">
221 221
 
222 222
 						<?php
223
-							$this->display_markup( $this->generate_from_date( 'subscriptions' ) );
224
-							$this->display_markup( $this->generate_to_date( 'subscriptions' ) );
225
-							$this->display_markup( $this->generate_post_status_select( 'subscriptions' ) );
226
-							$this->display_markup( $this->generate_file_type_select( 'subscriptions' ) );
227
-							submit_button( __( 'Download', 'invoicing' ) );
228
-						?>
223
+                            $this->display_markup( $this->generate_from_date( 'subscriptions' ) );
224
+                            $this->display_markup( $this->generate_to_date( 'subscriptions' ) );
225
+                            $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) );
226
+                            $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) );
227
+                            submit_button( __( 'Download', 'invoicing' ) );
228
+                        ?>
229 229
 
230 230
 					</form>
231 231
 
@@ -236,6 +236,6 @@  discard block
 block discarded – undo
236 236
 
237 237
 		<?php
238 238
 
239
-	}
239
+    }
240 240
 
241 241
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Reports_Export Class.
@@ -19,8 +19,8 @@  discard block
 block discarded – undo
19 19
 	public function display() {
20 20
 
21 21
 		echo "<div class='row mt-4' style='max-width: 920px;' >";
22
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
23
-			$this->display_post_type_export( $post_type );
22
+		foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) {
23
+			$this->display_post_type_export($post_type);
24 24
 		}
25 25
 		$this->display_subscription_export();
26 26
 		echo "</div>";
@@ -31,13 +31,13 @@  discard block
 block discarded – undo
31 31
 	 * Retrieves the download url.
32 32
 	 *
33 33
 	 */
34
-	public function get_download_url( $post_type ) {
34
+	public function get_download_url($post_type) {
35 35
 
36 36
 		return wp_nonce_url(
37 37
 			add_query_arg(
38 38
 				array(
39 39
 					'getpaid-admin-action' => 'export_invoices',
40
-					'post_type'            => urlencode( $post_type ),
40
+					'post_type'            => urlencode($post_type),
41 41
 				)
42 42
 			),
43 43
 			'getpaid-nonce',
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 * Displays a single post type export card.
51 51
 	 *
52 52
 	 */
53
-	public function display_post_type_export( $post_type ) {
53
+	public function display_post_type_export($post_type) {
54 54
 
55 55
 		?>
56 56
 
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
 					<strong>
62 62
 						<?php
63 63
 							printf(
64
-								__( 'Export %s', 'invoicing' ),
65
-								sanitize_text_field( getpaid_get_post_type_label( $post_type ) )
64
+								__('Export %s', 'invoicing'),
65
+								sanitize_text_field(getpaid_get_post_type_label($post_type))
66 66
 							);
67 67
 						?>
68 68
 					</strong>
@@ -70,14 +70,14 @@  discard block
 block discarded – undo
70 70
 
71 71
 				<div class="card-body">
72 72
 
73
-					<form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>">
73
+					<form method="post" action="<?php echo esc_url($this->get_download_url($post_type)); ?>">
74 74
 
75 75
 						<?php
76
-							$this->display_markup( $this->generate_from_date( $post_type ) );
77
-							$this->display_markup( $this->generate_to_date( $post_type ) );
78
-							$this->display_markup( $this->generate_post_status_select( $post_type ) );
79
-							$this->display_markup( $this->generate_file_type_select( $post_type ) );
80
-							submit_button( __( 'Download', 'invoicing' ) );
76
+							$this->display_markup($this->generate_from_date($post_type));
77
+							$this->display_markup($this->generate_to_date($post_type));
78
+							$this->display_markup($this->generate_post_status_select($post_type));
79
+							$this->display_markup($this->generate_file_type_select($post_type));
80
+							submit_button(__('Download', 'invoicing'));
81 81
 						?>
82 82
 
83 83
 					</form>
@@ -95,14 +95,14 @@  discard block
 block discarded – undo
95 95
 	 * Generates the from date input field.
96 96
 	 *
97 97
 	 */
98
-	public function generate_from_date( $post_type ) {
98
+	public function generate_from_date($post_type) {
99 99
 
100 100
 		return aui()->input(
101 101
 			array(
102 102
 				'name'       => 'from_date',
103
-				'id'         => esc_attr( "$post_type-from_date" ),
103
+				'id'         => esc_attr("$post_type-from_date"),
104 104
 				'placeholder'=> 'yy-mm-dd',
105
-				'label'      => __( 'From Date', 'invoicing' ),
105
+				'label'      => __('From Date', 'invoicing'),
106 106
 				'label_type' => 'vertical',
107 107
 				'label_class' => 'd-block',
108 108
 				'type'       => 'datepicker',
@@ -115,14 +115,14 @@  discard block
 block discarded – undo
115 115
 	 * Generates the to date input field.
116 116
 	 *
117 117
 	 */
118
-	public function generate_to_date( $post_type ) {
118
+	public function generate_to_date($post_type) {
119 119
 
120 120
 		return aui()->input(
121 121
 			array(
122 122
 				'name'       => 'to_date',
123
-				'id'         => esc_attr( "$post_type-to_date" ),
123
+				'id'         => esc_attr("$post_type-to_date"),
124 124
 				'placeholder'=> 'yy-mm-dd',
125
-				'label'      => __( 'To Date', 'invoicing' ),
125
+				'label'      => __('To Date', 'invoicing'),
126 126
 				'label_type' => 'vertical',
127 127
 				'label_class' => 'd-block',
128 128
 				'type'       => 'datepicker',
@@ -135,20 +135,20 @@  discard block
 block discarded – undo
135 135
 	 * Generates the to post status select field.
136 136
 	 *
137 137
 	 */
138
-	public function generate_post_status_select( $post_type ) {
138
+	public function generate_post_status_select($post_type) {
139 139
 
140
-		if ( 'subscriptions' === $post_type ) {
140
+		if ('subscriptions' === $post_type) {
141 141
 			$options = getpaid_get_subscription_statuses();
142 142
 		} else {
143
-			$options = wpinv_get_invoice_statuses( true, false, $post_type );
143
+			$options = wpinv_get_invoice_statuses(true, false, $post_type);
144 144
 		}
145 145
 
146 146
 		return aui()->select(
147 147
 			array(
148 148
 				'name'        => 'status',
149
-				'id'          => esc_attr( "$post_type-status" ),
150
-				'placeholder' => __( 'All Statuses', 'invoicing' ),
151
-				'label'       => __( 'Status', 'invoicing' ),
149
+				'id'          => esc_attr("$post_type-status"),
150
+				'placeholder' => __('All Statuses', 'invoicing'),
151
+				'label'       => __('Status', 'invoicing'),
152 152
 				'label_type'  => 'vertical',
153 153
 				'label_class' => 'd-block',
154 154
 				'options'     => $options,
@@ -161,20 +161,20 @@  discard block
 block discarded – undo
161 161
 	 * Generates the to file type select field.
162 162
 	 *
163 163
 	 */
164
-	public function generate_file_type_select( $post_type ) {
164
+	public function generate_file_type_select($post_type) {
165 165
 
166 166
 		return aui()->select(
167 167
 			array(
168 168
 				'name'        => 'file_type',
169
-				'id'          => esc_attr( "$post_type-file_type" ),
170
-				'placeholder' => __( 'Select File Type', 'invoicing' ),
171
-				'label'       => __( 'Export File', 'invoicing' ),
169
+				'id'          => esc_attr("$post_type-file_type"),
170
+				'placeholder' => __('Select File Type', 'invoicing'),
171
+				'label'       => __('Export File', 'invoicing'),
172 172
 				'label_type'  => 'vertical',
173 173
 				'label_class' => 'd-block',
174 174
 				'options'     => array(
175
-					'csv'  => __( 'CSV', 'invoicing' ),
176
-					'xml'  => __( 'XML', 'invoicing' ),
177
-					'json' => __( 'JSON', 'invoicing' ),
175
+					'csv'  => __('CSV', 'invoicing'),
176
+					'xml'  => __('XML', 'invoicing'),
177
+					'json' => __('JSON', 'invoicing'),
178 178
 				),
179 179
 			)
180 180
 		);
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 	 * Displays a field's markup.
186 186
 	 *
187 187
 	 */
188
-	public function display_markup( $markup ) {
188
+	public function display_markup($markup) {
189 189
 
190 190
 		echo str_replace(
191 191
 			array(
@@ -211,20 +211,20 @@  discard block
 block discarded – undo
211 211
 
212 212
 				<div class="card-header">
213 213
 					<strong>
214
-						<?php _e( 'Export Subscriptions', 'invoicing' ); ?>
214
+						<?php _e('Export Subscriptions', 'invoicing'); ?>
215 215
 					</strong>
216 216
 				</div>
217 217
 
218 218
 				<div class="card-body">
219 219
 
220
-					<form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>">
220
+					<form method="post" action="<?php echo esc_url($this->get_download_url('subscriptions')); ?>">
221 221
 
222 222
 						<?php
223
-							$this->display_markup( $this->generate_from_date( 'subscriptions' ) );
224
-							$this->display_markup( $this->generate_to_date( 'subscriptions' ) );
225
-							$this->display_markup( $this->generate_post_status_select( 'subscriptions' ) );
226
-							$this->display_markup( $this->generate_file_type_select( 'subscriptions' ) );
227
-							submit_button( __( 'Download', 'invoicing' ) );
223
+							$this->display_markup($this->generate_from_date('subscriptions'));
224
+							$this->display_markup($this->generate_to_date('subscriptions'));
225
+							$this->display_markup($this->generate_post_status_select('subscriptions'));
226
+							$this->display_markup($this->generate_file_type_select('subscriptions'));
227
+							submit_button(__('Download', 'invoicing'));
228 228
 						?>
229 229
 
230 230
 					</form>
Please login to merge, or discard this patch.