Completed
Push — master ( 260ce8...60cf75 )
by Brian
21s queued 16s
created
includes/wpinv-gateway-functions.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -286,26 +286,26 @@  discard block
 block discarded – undo
286 286
 }
287 287
 
288 288
 function wpinv_get_chosen_gateway( $invoice_id = 0 ) {
289
-	$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
289
+    $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
290 290
 
291 291
     $chosen = false;
292 292
     if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) {
293 293
         $chosen = $invoice->get_gateway();
294 294
     }
295 295
 
296
-	$chosen   = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen;
296
+    $chosen   = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen;
297 297
 
298
-	if ( false !== $chosen ) {
299
-		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen );
300
-	}
298
+    if ( false !== $chosen ) {
299
+        $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen );
300
+    }
301 301
 
302
-	if ( ! empty ( $chosen ) ) {
303
-		$enabled_gateway = urldecode( $chosen );
304
-	} else if (  !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) {
305
-		$enabled_gateway = 'manual';
306
-	} else {
307
-		$enabled_gateway = wpinv_get_default_gateway();
308
-	}
302
+    if ( ! empty ( $chosen ) ) {
303
+        $enabled_gateway = urldecode( $chosen );
304
+    } else if (  !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) {
305
+        $enabled_gateway = 'manual';
306
+    } else {
307
+        $enabled_gateway = wpinv_get_default_gateway();
308
+    }
309 309
     
310 310
     if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) {
311 311
         if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 
317 317
     }
318 318
 
319
-	return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway );
319
+    return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway );
320 320
 }
321 321
 
322 322
 function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) {
@@ -324,21 +324,21 @@  discard block
 block discarded – undo
324 324
 }
325 325
 
326 326
 function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) {
327
-	$ret  = 0;
328
-	$args = array(
329
-		'meta_key'    => '_wpinv_gateway',
330
-		'meta_value'  => $gateway_id,
331
-		'nopaging'    => true,
332
-		'post_type'   => 'wpi_invoice',
333
-		'post_status' => $status,
334
-		'fields'      => 'ids'
335
-	);
336
-
337
-	$payments = new WP_Query( $args );
338
-
339
-	if( $payments )
340
-		$ret = $payments->post_count;
341
-	return $ret;
327
+    $ret  = 0;
328
+    $args = array(
329
+        'meta_key'    => '_wpinv_gateway',
330
+        'meta_value'  => $gateway_id,
331
+        'nopaging'    => true,
332
+        'post_type'   => 'wpi_invoice',
333
+        'post_status' => $status,
334
+        'fields'      => 'ids'
335
+    );
336
+
337
+    $payments = new WP_Query( $args );
338
+
339
+    if( $payments )
340
+        $ret = $payments->post_count;
341
+    return $ret;
342 342
 }
343 343
 
344 344
 function wpinv_settings_update_gateways( $input ) {
Please login to merge, or discard this patch.
Spacing   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Contains gateway functions.
4 4
  *
5 5
  */
6
-defined( 'ABSPATH' ) || exit;
6
+defined('ABSPATH') || exit;
7 7
 
8 8
 /**
9 9
  * Returns an array of payment gateways.
@@ -11,141 +11,141 @@  discard block
 block discarded – undo
11 11
  * @return array
12 12
  */
13 13
 function wpinv_get_payment_gateways() {
14
-    return apply_filters( 'wpinv_payment_gateways', array() );
14
+    return apply_filters('wpinv_payment_gateways', array());
15 15
 }
16 16
 
17
-function wpinv_payment_gateway_titles( $all_gateways ) {
17
+function wpinv_payment_gateway_titles($all_gateways) {
18 18
     global $wpinv_options;
19 19
 
20 20
     $gateways = array();
21
-    foreach ( $all_gateways as $key => $gateway ) {
22
-        if ( !empty( $wpinv_options[$key . '_title'] ) ) {
23
-            $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' );
21
+    foreach ($all_gateways as $key => $gateway) {
22
+        if (!empty($wpinv_options[$key . '_title'])) {
23
+            $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing');
24 24
         }
25 25
 
26
-        $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' );
26
+        $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : '');
27 27
     }
28 28
 
29
-    asort( $gateways );
29
+    asort($gateways);
30 30
 
31
-    foreach ( $gateways as $gateway => $key ) {
31
+    foreach ($gateways as $gateway => $key) {
32 32
         $gateways[$gateway] = $all_gateways[$gateway];
33 33
     }
34 34
 
35 35
     return $gateways;
36 36
 }
37
-add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 );
37
+add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1);
38 38
 
39
-function wpinv_get_enabled_payment_gateways( $sort = false ) {
39
+function wpinv_get_enabled_payment_gateways($sort = false) {
40 40
     $gateways = wpinv_get_payment_gateways();
41
-    $enabled  = wpinv_get_option( 'gateways', false );
41
+    $enabled  = wpinv_get_option('gateways', false);
42 42
 
43 43
     $gateway_list = array();
44 44
 
45
-    foreach ( $gateways as $key => $gateway ) {
46
-        if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) {
47
-            $gateway_list[ $key ] = $gateway;
45
+    foreach ($gateways as $key => $gateway) {
46
+        if (isset($enabled[$key]) && $enabled[$key] == 1) {
47
+            $gateway_list[$key] = $gateway;
48 48
         }
49 49
     }
50 50
 
51
-    if ( true === $sort ) {
52
-        uasort( $gateway_list, 'wpinv_sort_gateway_order' );
51
+    if (true === $sort) {
52
+        uasort($gateway_list, 'wpinv_sort_gateway_order');
53 53
         
54 54
         // Reorder our gateways so the default is first
55 55
         $default_gateway_id = wpinv_get_default_gateway();
56 56
 
57
-        if ( wpinv_is_gateway_active( $default_gateway_id ) ) {
58
-            $default_gateway    = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] );
59
-            unset( $gateway_list[ $default_gateway_id ] );
57
+        if (wpinv_is_gateway_active($default_gateway_id)) {
58
+            $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]);
59
+            unset($gateway_list[$default_gateway_id]);
60 60
 
61
-            $gateway_list = array_merge( $default_gateway, $gateway_list );
61
+            $gateway_list = array_merge($default_gateway, $gateway_list);
62 62
         }
63 63
     }
64 64
 
65
-    return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list );
65
+    return apply_filters('wpinv_enabled_payment_gateways', $gateway_list);
66 66
 }
67 67
 
68
-function wpinv_sort_gateway_order( $a, $b ) {
68
+function wpinv_sort_gateway_order($a, $b) {
69 69
     return $a['ordering'] - $b['ordering'];
70 70
 }
71 71
 
72
-function wpinv_is_gateway_active( $gateway ) {
72
+function wpinv_is_gateway_active($gateway) {
73 73
     $gateways = wpinv_get_enabled_payment_gateways();
74 74
 
75
-    $ret = is_array($gateways) && $gateway ?  array_key_exists( $gateway, $gateways ) : false;
75
+    $ret = is_array($gateways) && $gateway ?  array_key_exists($gateway, $gateways) : false;
76 76
 
77
-    return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways );
77
+    return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways);
78 78
 }
79 79
 
80 80
 function wpinv_get_default_gateway() {
81
-    $default = wpinv_get_option( 'default_gateway', 'paypal' );
81
+    $default = wpinv_get_option('default_gateway', 'paypal');
82 82
 
83
-    if ( !wpinv_is_gateway_active( $default ) ) {
83
+    if (!wpinv_is_gateway_active($default)) {
84 84
         $gateways = wpinv_get_enabled_payment_gateways();
85
-        $gateways = array_keys( $gateways );
86
-        $default  = reset( $gateways );
85
+        $gateways = array_keys($gateways);
86
+        $default  = reset($gateways);
87 87
     }
88 88
 
89
-    return apply_filters( 'wpinv_default_gateway', $default );
89
+    return apply_filters('wpinv_default_gateway', $default);
90 90
 }
91 91
 
92
-function wpinv_get_gateway_admin_label( $gateway ) {
92
+function wpinv_get_gateway_admin_label($gateway) {
93 93
     $gateways = wpinv_get_payment_gateways();
94
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway;
95
-    $payment  = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false;
94
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway;
95
+    $payment  = isset($_GET['id']) ? absint($_GET['id']) : false;
96 96
 
97
-    if( $gateway == 'manual' && $payment ) {
98
-        if( !( (float)wpinv_payment_total( $payment ) > 0 ) ) {
99
-            $label = __( 'Free Purchase', 'invoicing' );
97
+    if ($gateway == 'manual' && $payment) {
98
+        if (!((float) wpinv_payment_total($payment) > 0)) {
99
+            $label = __('Free Purchase', 'invoicing');
100 100
         }
101 101
     }
102 102
 
103
-    return apply_filters( 'wpinv_gateway_admin_label', $label, $gateway );
103
+    return apply_filters('wpinv_gateway_admin_label', $label, $gateway);
104 104
 }
105 105
 
106
-function wpinv_get_gateway_description( $gateway ) {
106
+function wpinv_get_gateway_description($gateway) {
107 107
     global $wpinv_options;
108 108
 
109
-    $description = ! empty( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : '';
109
+    $description = !empty($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : '';
110 110
 
111
-    return apply_filters( 'wpinv_gateway_description', $description, $gateway );
111
+    return apply_filters('wpinv_gateway_description', $description, $gateway);
112 112
 }
113 113
 
114
-function wpinv_get_gateway_button_label( $gateway ) {
115
-    return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' );
114
+function wpinv_get_gateway_button_label($gateway) {
115
+    return apply_filters('wpinv_gateway_' . $gateway . '_button_label', '');
116 116
 }
117 117
 
118
-function wpinv_get_gateway_checkout_label( $gateway ) {
118
+function wpinv_get_gateway_checkout_label($gateway) {
119 119
     $gateways = wpinv_get_payment_gateways();
120
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway;
120
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway;
121 121
 
122
-    if ( $gateway == 'none' ) {
123
-        $label = __( 'None', 'invoicing' );
122
+    if ($gateway == 'none') {
123
+        $label = __('None', 'invoicing');
124 124
     }
125 125
 
126
-    return apply_filters( 'wpinv_gateway_checkout_label', ucfirst( $label ), $gateway );
126
+    return apply_filters('wpinv_gateway_checkout_label', ucfirst($label), $gateway);
127 127
 }
128 128
 
129
-function wpinv_settings_sections_gateways( $settings ) {
129
+function wpinv_settings_sections_gateways($settings) {
130 130
     $gateways = wpinv_get_payment_gateways();
131 131
     
132 132
     if (!empty($gateways)) {
133
-        foreach  ($gateways as $key => $gateway) {
133
+        foreach ($gateways as $key => $gateway) {
134 134
             $settings[$key] = $gateway['admin_label'];
135 135
         }
136 136
     }
137 137
     
138 138
     return $settings;    
139 139
 }
140
-add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 );
140
+add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1);
141 141
 
142 142
 /**
143 143
  * Adds GateWay settings.
144 144
  */
145
-function wpinv_settings_gateways( $settings ) {
145
+function wpinv_settings_gateways($settings) {
146 146
 
147 147
     // Loop through each gateway.
148
-    foreach  ( wpinv_get_payment_gateways() as $key => $gateway ) {
148
+    foreach (wpinv_get_payment_gateways() as $key => $gateway) {
149 149
 
150 150
         $gateway_settings = array(
151 151
 
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
             "{$key}_header" => array(
154 154
 
155 155
                 'id'     => "{$key}_gateway_header",
156
-                'name'   => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>',
156
+                'name'   => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>',
157 157
                 'custom' => $key,
158 158
                 'type'   => 'gateway_header',
159 159
 
@@ -162,56 +162,56 @@  discard block
 block discarded – undo
162 162
             // Activate/Deactivate a gateway.
163 163
             "{$key}_active" => array(
164 164
                 'id'   => $key . '_active',
165
-                'name' => __( 'Activate', 'invoicing' ),
166
-                'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ),
165
+                'name' => __('Activate', 'invoicing'),
166
+                'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']),
167 167
                 'type' => 'checkbox',
168 168
             ),
169 169
 
170 170
             // Activate/Deactivate sandbox.
171 171
             "{$key}_sandbox" => array(
172 172
                 'id'   => $key . '_sandbox',
173
-                'name' => __( 'Sandbox', 'invoicing' ),
174
-                'desc' => __( 'Enable sandbox to test payments', 'invoicing' ),
173
+                'name' => __('Sandbox', 'invoicing'),
174
+                'desc' => __('Enable sandbox to test payments', 'invoicing'),
175 175
                 'type' => 'checkbox',
176 176
             ),
177 177
 
178 178
             // Checkout title.
179 179
             "{$key}_title" => array(
180 180
                 'id'   => $key . '_title',
181
-                'name' => __( 'Checkout Title', 'invoicing' ),
182
-                'std'  => isset( $gateway['checkout_label'] ) ? $gateway['checkout_label'] : '',
181
+                'name' => __('Checkout Title', 'invoicing'),
182
+                'std'  => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : '',
183 183
                 'type' => 'text',
184 184
             ),
185 185
 
186 186
             // Checkout description.
187 187
             "{$key}_desc" => array(
188 188
                 'id'   => $key . '_desc',
189
-                'name' => __( 'Checkout Description', 'invoicing' ),
190
-                'std'  => apply_filters( "getpaid_default_{$key}_checkout_description", '' ),
189
+                'name' => __('Checkout Description', 'invoicing'),
190
+                'std'  => apply_filters("getpaid_default_{$key}_checkout_description", ''),
191 191
                 'type' => 'text',
192 192
             ),
193 193
 
194 194
             // Checkout order.
195 195
             "{$key}_ordering" => array(
196 196
                 'id'   => $key . '_ordering',
197
-                'name' => __( 'Priority', 'invoicing' ),
198
-                'std'  => apply_filters( "getpaid_default_{$key}_checkout_description", '' ),
197
+                'name' => __('Priority', 'invoicing'),
198
+                'std'  => apply_filters("getpaid_default_{$key}_checkout_description", ''),
199 199
                 'type' => 'number',
200 200
                 'step' => '1',
201 201
                 'min'  => '-100000',
202 202
                 'max'  => '100000',
203
-                'std'  => isset( $gateway['ordering'] ) ? $gateway['ordering'] : '10',
203
+                'std'  => isset($gateway['ordering']) ? $gateway['ordering'] : '10',
204 204
             ),
205 205
 
206 206
         );
207 207
 
208 208
         // Maybe remove the sandbox.
209
-        if ( ! apply_filters( "wpinv_{$key}_supports_sandbox", false ) ) {
210
-            unset( $gateway_settings["{$key}_sandbox"] );
209
+        if (!apply_filters("wpinv_{$key}_supports_sandbox", false)) {
210
+            unset($gateway_settings["{$key}_sandbox"]);
211 211
         }
212 212
   
213
-        $gateway_settings = apply_filters( 'wpinv_gateway_settings', $gateway_settings, $key, $gateway );
214
-        $gateway_settings = apply_filters( 'wpinv_gateway_settings_' . $key, $gateway_settings, $gateway );
213
+        $gateway_settings = apply_filters('wpinv_gateway_settings', $gateway_settings, $key, $gateway);
214
+        $gateway_settings = apply_filters('wpinv_gateway_settings_' . $key, $gateway_settings, $gateway);
215 215
         
216 216
         $settings[$key] = $gateway_settings;
217 217
     }
@@ -219,57 +219,57 @@  discard block
 block discarded – undo
219 219
     return $settings;
220 220
 
221 221
 }
222
-add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 );
222
+add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1);
223 223
 
224
-function wpinv_gateway_header_callback( $args ) {
225
-    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />';
224
+function wpinv_gateway_header_callback($args) {
225
+    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />';
226 226
 }
227 227
 
228
-function wpinv_get_gateway_supports( $gateway ) {
228
+function wpinv_get_gateway_supports($gateway) {
229 229
     $gateways = wpinv_get_enabled_payment_gateways();
230
-    $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array();
231
-    return apply_filters( 'wpinv_gateway_supports', $supports, $gateway );
230
+    $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array();
231
+    return apply_filters('wpinv_gateway_supports', $supports, $gateway);
232 232
 }
233 233
 
234
-function wpinv_get_chosen_gateway( $invoice_id = 0 ) {
235
-	$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
234
+function wpinv_get_chosen_gateway($invoice_id = 0) {
235
+	$gateways = array_keys(wpinv_get_enabled_payment_gateways());
236 236
 
237 237
     $chosen = false;
238
-    if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) {
238
+    if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) {
239 239
         $chosen = $invoice->get_gateway();
240 240
     }
241 241
 
242
-	$chosen   = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen;
242
+	$chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen;
243 243
 
244
-	if ( false !== $chosen ) {
245
-		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen );
244
+	if (false !== $chosen) {
245
+		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen);
246 246
 	}
247 247
 
248
-	if ( ! empty ( $chosen ) ) {
249
-		$enabled_gateway = urldecode( $chosen );
250
-	} else if (  !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) {
248
+	if (!empty ($chosen)) {
249
+		$enabled_gateway = urldecode($chosen);
250
+	} else if (!empty($invoice) && (float) $invoice->get_subtotal() <= 0) {
251 251
 		$enabled_gateway = 'manual';
252 252
 	} else {
253 253
 		$enabled_gateway = wpinv_get_default_gateway();
254 254
 	}
255 255
     
256
-    if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) {
257
-        if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){
256
+    if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) {
257
+        if (wpinv_is_gateway_active(wpinv_get_default_gateway())) {
258 258
             $enabled_gateway = wpinv_get_default_gateway();
259
-        }else{
259
+        } else {
260 260
             $enabled_gateway = $gateways[0];
261 261
         }
262 262
 
263 263
     }
264 264
 
265
-	return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway );
265
+	return apply_filters('wpinv_chosen_gateway', $enabled_gateway);
266 266
 }
267 267
 
268
-function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) {
269
-    return wpinv_error_log( $message, $title );
268
+function wpinv_record_gateway_error($title = '', $message = '', $parent = 0) {
269
+    return wpinv_error_log($message, $title);
270 270
 }
271 271
 
272
-function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) {
272
+function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') {
273 273
 	$ret  = 0;
274 274
 	$args = array(
275 275
 		'meta_key'    => '_wpinv_gateway',
@@ -280,48 +280,48 @@  discard block
 block discarded – undo
280 280
 		'fields'      => 'ids'
281 281
 	);
282 282
 
283
-	$payments = new WP_Query( $args );
283
+	$payments = new WP_Query($args);
284 284
 
285
-	if( $payments )
285
+	if ($payments)
286 286
 		$ret = $payments->post_count;
287 287
 	return $ret;
288 288
 }
289 289
 
290
-function wpinv_settings_update_gateways( $input ) {
290
+function wpinv_settings_update_gateways($input) {
291 291
     global $wpinv_options;
292 292
     
293
-    if ( !empty( $input['save_gateway'] ) ) {
294
-        $gateways = wpinv_get_option( 'gateways', false );
293
+    if (!empty($input['save_gateway'])) {
294
+        $gateways = wpinv_get_option('gateways', false);
295 295
         $gateways = !empty($gateways) ? $gateways : array();
296 296
         $gateway = $input['save_gateway'];
297 297
         
298
-        if ( !empty( $input[$gateway . '_active'] ) ) {
298
+        if (!empty($input[$gateway . '_active'])) {
299 299
             $gateways[$gateway] = 1;
300 300
         } else {
301
-            if ( isset( $gateways[$gateway] ) ) {
302
-                unset( $gateways[$gateway] );
301
+            if (isset($gateways[$gateway])) {
302
+                unset($gateways[$gateway]);
303 303
             }
304 304
         }
305 305
         
306 306
         $input['gateways'] = $gateways;
307 307
     }
308 308
     
309
-    if ( !empty( $input['default_gateway'] ) ) {
309
+    if (!empty($input['default_gateway'])) {
310 310
         $gateways = wpinv_get_payment_gateways();
311 311
         
312
-        foreach ( $gateways as $key => $gateway ) {
313
-            $active   = 0;
314
-            if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) {
312
+        foreach ($gateways as $key => $gateway) {
313
+            $active = 0;
314
+            if (!empty($input['gateways']) && !empty($input['gateways'][$key])) {
315 315
                 $active = 1;
316 316
             }
317 317
             
318 318
             $input[$key . '_active'] = $active;
319 319
             
320
-            if ( empty( $wpinv_options[$key . '_title'] ) ) {
320
+            if (empty($wpinv_options[$key . '_title'])) {
321 321
                 $input[$key . '_title'] = $gateway['checkout_label'];
322 322
             }
323 323
             
324
-            if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) {
324
+            if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) {
325 325
                 $input[$key . '_ordering'] = $gateway['ordering'];
326 326
             }
327 327
         }
@@ -329,27 +329,27 @@  discard block
 block discarded – undo
329 329
     
330 330
     return $input;
331 331
 }
332
-add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 );
332
+add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1);
333 333
 
334 334
 // PayPal Standard settings
335
-function wpinv_gateway_settings_paypal( $setting ) {    
336
-    $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing' );
337
-    $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
335
+function wpinv_gateway_settings_paypal($setting) {    
336
+    $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __('( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing');
337
+    $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
338 338
     
339 339
     $setting['paypal_sandbox'] = array(
340 340
             'type' => 'checkbox',
341 341
             'id'   => 'paypal_sandbox',
342
-            'name' => __( 'PayPal Sandbox', 'invoicing' ),
343
-            'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ),
342
+            'name' => __('PayPal Sandbox', 'invoicing'),
343
+            'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'),
344 344
             'std'  => 1
345 345
         );
346 346
         
347 347
     $setting['paypal_email'] = array(
348 348
             'type' => 'text',
349 349
             'id'   => 'paypal_email',
350
-            'name' => __( 'PayPal Email', 'invoicing' ),
351
-            'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ),
352
-            'std' => __( '[email protected]', 'invoicing' ),
350
+            'name' => __('PayPal Email', 'invoicing'),
351
+            'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'),
352
+            'std' => __('[email protected]', 'invoicing'),
353 353
         );
354 354
     /*
355 355
     $setting['paypal_ipn_url'] = array(
@@ -363,18 +363,18 @@  discard block
 block discarded – undo
363 363
         
364 364
     return $setting;
365 365
 }
366
-add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 );
366
+add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1);
367 367
 
368 368
 /**
369 369
  * Displays the ipn url field.
370 370
  */
371
-function wpinv_ipn_url_callback( $args ) {
372
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
371
+function wpinv_ipn_url_callback($args) {
372
+    $sanitize_id = wpinv_sanitize_key($args['id']);
373 373
     
374 374
     $attrs = $args['readonly'] ? ' readonly' : '';
375 375
 
376
-    $html = '<input class="regular-text" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" onClick="this.select()">';
377
-    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">'  . $args['desc'] . '</label>';
376
+    $html = '<input class="regular-text" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" onClick="this.select()">';
377
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>';
378 378
 
379 379
     echo $html;
380 380
 }
@@ -386,9 +386,9 @@  discard block
 block discarded – undo
386 386
  * 
387 387
  * @return bool
388 388
  */
389
-function wpinv_is_test_mode( $gateway = '' ) {
390
-    $sandbox = empty( $gateway ) ? false : wpinv_get_option( "{$gateway}_sandbox", false );
391
-    return apply_filters( 'wpinv_is_test_mode', $sandbox, $gateway );
389
+function wpinv_is_test_mode($gateway = '') {
390
+    $sandbox = empty($gateway) ? false : wpinv_get_option("{$gateway}_sandbox", false);
391
+    return apply_filters('wpinv_is_test_mode', $sandbox, $gateway);
392 392
 }
393 393
 
394 394
 /**
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
  * 
400 400
  * @return string
401 401
  */
402
-function wpinv_get_ipn_url( $gateway = false, $args = array() ) {
402
+function wpinv_get_ipn_url($gateway = false, $args = array()) {
403 403
     $args = wp_parse_args(
404 404
         array(
405 405
             'wpi-listener' => 'IPN',
@@ -408,37 +408,37 @@  discard block
 block discarded – undo
408 408
         $args
409 409
     );
410 410
 
411
-    return apply_filters( 'wpinv_ipn_url', add_query_arg( $args,  home_url( 'index.php' ) ), $gateway, $args );
411
+    return apply_filters('wpinv_ipn_url', add_query_arg($args, home_url('index.php')), $gateway, $args);
412 412
 
413 413
 }
414 414
 
415 415
 /**
416 416
  * Retrieves request data with slashes removed slashes.
417 417
  */
418
-function wpinv_get_post_data( $method = 'request' ) {
418
+function wpinv_get_post_data($method = 'request') {
419 419
 
420
-    if ( $method == 'post' ) {
421
-        return wp_unslash( $_POST );
420
+    if ($method == 'post') {
421
+        return wp_unslash($_POST);
422 422
     }
423 423
 
424
-    if ( $method == 'get' ) {
425
-        return wp_unslash( $_GET );
424
+    if ($method == 'get') {
425
+        return wp_unslash($_GET);
426 426
     }
427 427
 
428
-    return wp_unslash( $_REQUEST );
428
+    return wp_unslash($_REQUEST);
429 429
   
430 430
 }
431 431
 
432 432
 /**
433 433
  * Checks if a given gateway supports subscription payments.
434 434
  */
435
-function wpinv_gateway_support_subscription( $gateway ) {
435
+function wpinv_gateway_support_subscription($gateway) {
436 436
     $supports = false;
437 437
 
438
-    if ( wpinv_is_gateway_active( $gateway ) ) {
439
-        $supports = apply_filters( 'wpinv_' . $gateway . '_support_subscription', $supports );
438
+    if (wpinv_is_gateway_active($gateway)) {
439
+        $supports = apply_filters('wpinv_' . $gateway . '_support_subscription', $supports);
440 440
 
441
-        $supports = apply_filters( 'getapid_gateway_supports_subscription', $supports, $gateway );
441
+        $supports = apply_filters('getapid_gateway_supports_subscription', $supports, $gateway);
442 442
     }
443 443
 
444 444
     return $supports;
@@ -450,14 +450,14 @@  discard block
 block discarded – undo
450 450
  * @param array $gateways an array of gateways.
451 451
  * @param GetPaid_Payment_Form $form payment form.
452 452
  */
453
-function wpinv_payment_gateways_on_cart( $gateways, $form ) {
453
+function wpinv_payment_gateways_on_cart($gateways, $form) {
454 454
 
455
-    if ( $form->is_recurring() ) {
455
+    if ($form->is_recurring()) {
456 456
 
457
-        foreach ( array_keys( $gateways ) as $gateway ) {
457
+        foreach (array_keys($gateways) as $gateway) {
458 458
 
459
-            if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
460
-                unset( $gateways[$gateway] );
459
+            if (!wpinv_gateway_support_subscription($gateway)) {
460
+                unset($gateways[$gateway]);
461 461
             }
462 462
 
463 463
         }
@@ -466,4 +466,4 @@  discard block
 block discarded – undo
466 466
 
467 467
     return $gateways;
468 468
 }
469
-add_filter( 'getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2 );
469
+add_filter('getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2);
Please login to merge, or discard this patch.
includes/wpinv-address-functions.php 1 patch
Spacing   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 
15 15
 function wpinv_get_default_country() {
16
-	$country = wpinv_get_option( 'default_country', 'UK' );
16
+	$country = wpinv_get_option('default_country', 'UK');
17 17
 
18
-	return apply_filters( 'wpinv_default_country', $country );
18
+	return apply_filters('wpinv_default_country', $country);
19 19
 }
20 20
 
21 21
 /**
@@ -24,59 +24,59 @@  discard block
 block discarded – undo
24 24
  * @param string $country The country code to sanitize
25 25
  * @return array
26 26
  */
27
-function wpinv_sanitize_country( $country ) {
27
+function wpinv_sanitize_country($country) {
28 28
 
29 29
 	// Enure the country is specified
30
-    if ( empty( $country ) ) {
30
+    if (empty($country)) {
31 31
         $country = wpinv_get_default_country();
32 32
     }
33
-    return trim( wpinv_utf8_strtoupper( $country ) );
33
+    return trim(wpinv_utf8_strtoupper($country));
34 34
 
35 35
 }
36 36
 
37
-function wpinv_is_base_country( $country ) {
37
+function wpinv_is_base_country($country) {
38 38
     $base_country = wpinv_get_default_country();
39 39
     
40
-    if ( $base_country === 'UK' ) {
40
+    if ($base_country === 'UK') {
41 41
         $base_country = 'GB';
42 42
     }
43
-    if ( $country == 'UK' ) {
43
+    if ($country == 'UK') {
44 44
         $country = 'GB';
45 45
     }
46 46
 
47
-    return ( $country && $country === $base_country ) ? true : false;
47
+    return ($country && $country === $base_country) ? true : false;
48 48
 }
49 49
 
50
-function wpinv_country_name( $country_code = '' ) { 
50
+function wpinv_country_name($country_code = '') { 
51 51
     $countries = wpinv_get_country_list();
52 52
     $country_code = $country_code == 'UK' ? 'GB' : $country_code;
53
-    $country = isset( $countries[$country_code] ) ? $countries[$country_code] : $country_code;
53
+    $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code;
54 54
 
55
-    return apply_filters( 'wpinv_country_name', $country, $country_code );
55
+    return apply_filters('wpinv_country_name', $country, $country_code);
56 56
 }
57 57
 
58 58
 function wpinv_get_default_state() {
59
-	$state = wpinv_get_option( 'default_state', false );
59
+	$state = wpinv_get_option('default_state', false);
60 60
 
61
-	return apply_filters( 'wpinv_default_state', $state );
61
+	return apply_filters('wpinv_default_state', $state);
62 62
 }
63 63
 
64
-function wpinv_state_name( $state_code = '', $country_code = '' ) {
64
+function wpinv_state_name($state_code = '', $country_code = '') {
65 65
     $state = $state_code;
66 66
     
67
-    if ( !empty( $country_code ) ) {
68
-        $states = wpinv_get_country_states( $country_code );
67
+    if (!empty($country_code)) {
68
+        $states = wpinv_get_country_states($country_code);
69 69
         
70
-        $state = !empty( $states ) && isset( $states[$state_code] ) ? $states[$state_code] : $state;
70
+        $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state;
71 71
     }
72 72
 
73
-    return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code );
73
+    return apply_filters('wpinv_state_name', $state, $state_code, $country_code);
74 74
 }
75 75
 
76 76
 function wpinv_store_address() {
77
-    $address = wpinv_get_option( 'store_address', '' );
77
+    $address = wpinv_get_option('store_address', '');
78 78
 
79
-    return apply_filters( 'wpinv_store_address', $address );
79
+    return apply_filters('wpinv_store_address', $address);
80 80
 }
81 81
 
82 82
 /**
@@ -84,24 +84,24 @@  discard block
 block discarded – undo
84 84
  *
85 85
  * @param WPInv_Invoice $invoice
86 86
  */
87
-function getpaid_maybe_add_default_address( &$invoice ) {
87
+function getpaid_maybe_add_default_address(&$invoice) {
88 88
 
89 89
     $user_id = $invoice->get_user_id();
90 90
 
91 91
     // Abort if the invoice belongs to no one.
92
-    if ( empty( $user_id ) ) {
92
+    if (empty($user_id)) {
93 93
         return;
94 94
     }
95 95
 
96 96
     // Fill in defaults whenever necessary.
97
-    foreach ( wpinv_get_user_address( $user_id ) as $key => $value ) {
97
+    foreach (wpinv_get_user_address($user_id) as $key => $value) {
98 98
 
99
-        if ( is_callable( $invoice, "get_$key" ) ) {
100
-            $current = call_user_func( array( $invoice, "get_$key" ) );
99
+        if (is_callable($invoice, "get_$key")) {
100
+            $current = call_user_func(array($invoice, "get_$key"));
101 101
 
102
-            if ( empty( $current ) ) {
102
+            if (empty($current)) {
103 103
                 $method = "set_$key";
104
-                $invoice->$method( $value );
104
+                $invoice->$method($value);
105 105
             }
106 106
 
107 107
         }
@@ -140,24 +140,24 @@  discard block
 block discarded – undo
140 140
  *
141 141
  * @param WPInv_Invoice $invoice
142 142
  */
143
-function getpaid_save_invoice_user_address( $invoice ) {
143
+function getpaid_save_invoice_user_address($invoice) {
144 144
 
145 145
     // Retrieve the invoice.
146
-    $invoice = wpinv_get_invoice( $invoice );
146
+    $invoice = wpinv_get_invoice($invoice);
147 147
 
148 148
     // Abort if it does not exist.
149
-    if ( empty( $invoice ) ) {
149
+    if (empty($invoice)) {
150 150
         return;
151 151
     }
152 152
 
153
-    foreach ( getpaid_user_address_fields() as $field ) {
153
+    foreach (getpaid_user_address_fields() as $field) {
154 154
 
155
-        if ( is_callable( array( $invoice, "get_$field" ) ) ) {
156
-            $value = call_user_func( array( $invoice, "get_$field" ) );
155
+        if (is_callable(array($invoice, "get_$field"))) {
156
+            $value = call_user_func(array($invoice, "get_$field"));
157 157
 
158 158
             // Only save if it is not empty.
159
-            if ( ! empty( $value ) ) {
160
-                update_user_meta( $invoice->get_user_id(), '_wpinv_' . $field, $value );
159
+            if (!empty($value)) {
160
+                update_user_meta($invoice->get_user_id(), '_wpinv_' . $field, $value);
161 161
             }
162 162
 
163 163
         }
@@ -165,8 +165,8 @@  discard block
 block discarded – undo
165 165
     }
166 166
 
167 167
 }
168
-add_action( 'getpaid_new_invoice', 'getpaid_save_invoice_user_address' );
169
-add_action( 'getpaid_update_invoice', 'getpaid_save_invoice_user_address' );
168
+add_action('getpaid_new_invoice', 'getpaid_save_invoice_user_address');
169
+add_action('getpaid_update_invoice', 'getpaid_save_invoice_user_address');
170 170
 
171 171
 /**
172 172
  * Retrieves a saved user address.
@@ -175,14 +175,14 @@  discard block
 block discarded – undo
175 175
  * @param bool $with_default Whether or not we should use the default country and state.
176 176
  * @return array
177 177
  */
178
-function wpinv_get_user_address( $user_id = 0, $with_default = true ) {
178
+function wpinv_get_user_address($user_id = 0, $with_default = true) {
179 179
 
180 180
     // Prepare the user id.
181
-    $user_id   = empty( $user_id ) ? get_current_user_id() : $user_id;
182
-    $user_info = get_userdata( $user_id );
181
+    $user_id   = empty($user_id) ? get_current_user_id() : $user_id;
182
+    $user_info = get_userdata($user_id);
183 183
 
184 184
     // Abort if non exists.
185
-    if ( empty( $user_info ) ) {
185
+    if (empty($user_info)) {
186 186
         return array();
187 187
     }
188 188
 
@@ -192,27 +192,27 @@  discard block
 block discarded – undo
192 192
         'email'   => $user_info->user_email,
193 193
     );
194 194
 
195
-    foreach ( getpaid_user_address_fields() as $field ) {
196
-        $address[$field] = getpaid_get_user_address_field( $user_id, $field );
195
+    foreach (getpaid_user_address_fields() as $field) {
196
+        $address[$field] = getpaid_get_user_address_field($user_id, $field);
197 197
     }
198 198
 
199
-    if ( ! $with_default ) {
199
+    if (!$with_default) {
200 200
         return $address;
201 201
     }
202 202
 
203
-    if ( isset( $address['first_name'] ) && empty( $address['first_name'] ) ) {
203
+    if (isset($address['first_name']) && empty($address['first_name'])) {
204 204
         $address['first_name'] = $user_info->first_name;
205 205
     }
206 206
 
207
-    if ( isset( $address['last_name'] ) && empty( $address['last_name'] ) ) {
207
+    if (isset($address['last_name']) && empty($address['last_name'])) {
208 208
         $address['last_name'] = $user_info->last_name;
209 209
     }
210 210
 
211
-    if ( isset( $address['state'] ) && empty( $address['state'] ) ) {
211
+    if (isset($address['state']) && empty($address['state'])) {
212 212
         $address['state'] = wpinv_get_default_state();
213 213
     }
214 214
 
215
-    if ( isset( $address['country'] ) && empty( $address['country'] ) ) {
215
+    if (isset($address['country']) && empty($address['country'])) {
216 216
         $address['country'] = wpinv_get_default_country();
217 217
     }
218 218
 
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
  * @param string $field The field to use.
227 227
  * @return string|null
228 228
  */
229
-function getpaid_get_user_address_field( $user_id, $field ) {
229
+function getpaid_get_user_address_field($user_id, $field) {
230 230
 
231 231
     $prefixes = array(
232 232
         '_wpinv_',
@@ -234,15 +234,15 @@  discard block
 block discarded – undo
234 234
         ''
235 235
     );
236 236
 
237
-    foreach ( $prefixes as $prefix ) {
237
+    foreach ($prefixes as $prefix) {
238 238
 
239 239
         // Meta table.
240
-        $value = get_user_meta( $user_id, $prefix . $field, true );
240
+        $value = get_user_meta($user_id, $prefix . $field, true);
241 241
         
242 242
         // UWP table.
243
-        $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value;
243
+        $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value;
244 244
 
245
-        if ( ! empty( $value ) ) {
245
+        if (!empty($value)) {
246 246
             return $value;
247 247
         }
248 248
 
@@ -259,16 +259,16 @@  discard block
 block discarded – undo
259 259
  * @param string $return What to return.
260 260
  * @return array
261 261
  */
262
-function wpinv_get_continents( $return = 'all' ) {
262
+function wpinv_get_continents($return = 'all') {
263 263
 
264
-    $continents = wpinv_get_data( 'continents' );
264
+    $continents = wpinv_get_data('continents');
265 265
 
266
-    switch( $return ) {
266
+    switch ($return) {
267 267
         case 'name' :
268
-            return wp_list_pluck( $continents, 'name' );
268
+            return wp_list_pluck($continents, 'name');
269 269
             break;
270 270
         case 'countries' :
271
-            return wp_list_pluck( $continents, 'countries' );
271
+            return wp_list_pluck($continents, 'countries');
272 272
             break;
273 273
         default :
274 274
             return $continents;
@@ -284,12 +284,12 @@  discard block
 block discarded – undo
284 284
  * @param string $country Country code. If no code is specified, defaults to the default country.
285 285
  * @return string
286 286
  */
287
-function wpinv_get_continent_code_for_country( $country = false ) {
287
+function wpinv_get_continent_code_for_country($country = false) {
288 288
 
289
-    $country = wpinv_sanitize_country( $country );
289
+    $country = wpinv_sanitize_country($country);
290 290
     
291
-	foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
292
-		if ( false !== array_search( $country, $countries, true ) ) {
291
+	foreach (wpinv_get_continents('countries') as $continent_code => $countries) {
292
+		if (false !== array_search($country, $countries, true)) {
293 293
 			return $continent_code;
294 294
 		}
295 295
 	}
@@ -305,13 +305,13 @@  discard block
 block discarded – undo
305 305
  * @param string $country Country code. If no code is specified, defaults to the default country.
306 306
  * @return array
307 307
  */
308
-function wpinv_get_country_calling_code( $country = null) {
308
+function wpinv_get_country_calling_code($country = null) {
309 309
 
310
-    $country = wpinv_sanitize_country( $country );
311
-    $codes   = wpinv_get_data( 'phone-codes' );
312
-    $code    = isset( $codes[ $country ] ) ? $codes[ $country ] : '';
310
+    $country = wpinv_sanitize_country($country);
311
+    $codes   = wpinv_get_data('phone-codes');
312
+    $code    = isset($codes[$country]) ? $codes[$country] : '';
313 313
 
314
-    if ( is_array( $code ) ) {
314
+    if (is_array($code)) {
315 315
         return $code[0];
316 316
     }
317 317
     return $code;
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
  * @param bool $first_empty Whether or not the first item in the list should be empty
325 325
  * @return array
326 326
  */
327
-function wpinv_get_country_list( $first_empty = false ) {
328
-    return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty );
327
+function wpinv_get_country_list($first_empty = false) {
328
+    return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty);
329 329
 }
330 330
 
331 331
 /**
@@ -335,22 +335,22 @@  discard block
 block discarded – undo
335 335
  * @param bool $first_empty Whether or not the first item in the list should be empty
336 336
  * @return array
337 337
  */
338
-function wpinv_get_country_states( $country = null, $first_empty = false ) {
338
+function wpinv_get_country_states($country = null, $first_empty = false) {
339 339
     
340 340
     // Prepare the country.
341
-    $country = wpinv_sanitize_country( $country );
341
+    $country = wpinv_sanitize_country($country);
342 342
 
343 343
     // Fetch all states.
344
-    $all_states = wpinv_get_data( 'states' );
344
+    $all_states = wpinv_get_data('states');
345 345
 
346 346
     // Fetch the specified country's states.
347
-    $states     = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array() ;
348
-    $states     = apply_filters( "wpinv_{$country}_states", $states );
349
-    $states     = apply_filters( 'wpinv_country_states', $states, $country );
347
+    $states     = isset($all_states[$country]) ? $all_states[$country] : array();
348
+    $states     = apply_filters("wpinv_{$country}_states", $states);
349
+    $states     = apply_filters('wpinv_country_states', $states, $country);
350 350
 
351
-    asort( $states );
351
+    asort($states);
352 352
      
353
-    return wpinv_maybe_add_empty_option( $states, $first_empty );
353
+    return wpinv_maybe_add_empty_option($states, $first_empty);
354 354
 }
355 355
 
356 356
 /**
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
  * @return array
361 361
  */
362 362
 function wpinv_get_us_states_list() {
363
-    return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) );
363
+    return apply_filters('wpinv_usa_states', wpinv_get_country_states('US'));
364 364
 }
365 365
 
366 366
 /**
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
  * @return array
371 371
  */
372 372
 function wpinv_get_canada_states_list() {
373
-    return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) );
373
+    return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA'));
374 374
 }
375 375
 
376 376
 /**
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
  * @return array
381 381
  */
382 382
 function wpinv_get_australia_states_list() {
383
-    return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) );
383
+    return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU'));
384 384
 }
385 385
 
386 386
 /**
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
  * @return array
391 391
  */
392 392
 function wpinv_get_bangladesh_states_list() {
393
-    return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) );
393
+    return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD'));
394 394
 }
395 395
 
396 396
 /**
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
  * @return array
401 401
  */
402 402
 function wpinv_get_brazil_states_list() {
403
-    return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) );
403
+    return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR'));
404 404
 }
405 405
 
406 406
 /**
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
  * @return array
411 411
  */
412 412
 function wpinv_get_bulgaria_states_list() {
413
-    return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) );
413
+    return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG'));
414 414
 }
415 415
 
416 416
 /**
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
  * @return array
421 421
  */
422 422
 function wpinv_get_hong_kong_states_list() {
423
-    return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) );
423
+    return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK'));
424 424
 }
425 425
 
426 426
 /**
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
  * @return array
431 431
  */
432 432
 function wpinv_get_hungary_states_list() {
433
-    return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) );
433
+    return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU'));
434 434
 }
435 435
 
436 436
 /**
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
  * @return array
441 441
  */
442 442
 function wpinv_get_japan_states_list() {
443
-    return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) );
443
+    return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP'));
444 444
 }
445 445
 
446 446
 /**
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
  * @return array
451 451
  */
452 452
 function wpinv_get_china_states_list() {
453
-    return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) );
453
+    return apply_filters('wpinv_china_states', wpinv_get_country_states('CN'));
454 454
 }
455 455
 
456 456
 /**
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
  * @return array
461 461
  */
462 462
 function wpinv_get_new_zealand_states_list() {
463
-    return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) );
463
+    return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ'));
464 464
 }
465 465
 
466 466
 /**
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
  * @return array
471 471
  */
472 472
 function wpinv_get_peru_states_list() {
473
-    return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) );
473
+    return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE'));
474 474
 }
475 475
 
476 476
 /**
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
  * @return array
481 481
  */
482 482
 function wpinv_get_indonesia_states_list() {
483
-    return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) );
483
+    return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID'));
484 484
 }
485 485
 
486 486
 /**
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
  * @return array
491 491
  */
492 492
 function wpinv_get_india_states_list() {
493
-    return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) );
493
+    return apply_filters('wpinv_india_states', wpinv_get_country_states('IN'));
494 494
 }
495 495
 
496 496
 /**
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
  * @return array
501 501
  */
502 502
 function wpinv_get_iran_states_list() {
503
-    return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) );
503
+    return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR'));
504 504
 }
505 505
 
506 506
 /**
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
  * @return array
511 511
  */
512 512
 function wpinv_get_italy_states_list() {
513
-    return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) );
513
+    return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT'));
514 514
 }
515 515
 
516 516
 /**
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
  * @return array
521 521
  */
522 522
 function wpinv_get_malaysia_states_list() {
523
-    return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) );
523
+    return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY'));
524 524
 }
525 525
 
526 526
 /**
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
  * @return array
531 531
  */
532 532
 function wpinv_get_mexico_states_list() {
533
-    return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) );
533
+    return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX'));
534 534
 }
535 535
 
536 536
 /**
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
  * @return array
541 541
  */
542 542
 function wpinv_get_nepal_states_list() {
543
-    return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) );
543
+    return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP'));
544 544
 }
545 545
 
546 546
 /**
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
  * @return array
551 551
  */
552 552
 function wpinv_get_south_africa_states_list() {
553
-    return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) );
553
+    return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA'));
554 554
 }
555 555
 
556 556
 /**
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
  * @return array
561 561
  */
562 562
 function wpinv_get_thailand_states_list() {
563
-    return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) );
563
+    return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH'));
564 564
 }
565 565
 
566 566
 /**
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
  * @return array
571 571
  */
572 572
 function wpinv_get_turkey_states_list() {
573
-    return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) );
573
+    return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR'));
574 574
 }
575 575
 
576 576
 /**
@@ -580,28 +580,28 @@  discard block
 block discarded – undo
580 580
  * @return array
581 581
  */
582 582
 function wpinv_get_spain_states_list() {
583
-    return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) );
583
+    return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES'));
584 584
 }
585 585
 
586 586
 function wpinv_get_states_field() {
587
-	if( empty( $_POST['country'] ) ) {
587
+	if (empty($_POST['country'])) {
588 588
 		$_POST['country'] = wpinv_get_default_country();
589 589
 	}
590
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
590
+	$states = wpinv_get_country_states(sanitize_text_field($_POST['country']));
591 591
 
592
-	if( !empty( $states ) ) {
593
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
592
+	if (!empty($states)) {
593
+		$sanitized_field_name = sanitize_text_field($_POST['field_name']);
594 594
         
595 595
         $args = array(
596 596
 			'name'    => $sanitized_field_name,
597 597
 			'id'      => $sanitized_field_name,
598 598
 			'class'   => $sanitized_field_name . 'custom-select wpinv-select wpi_select2',
599
-			'options' => array_merge( array( '' => '' ), $states ),
599
+			'options' => array_merge(array('' => ''), $states),
600 600
 			'show_option_all'  => false,
601 601
 			'show_option_none' => false
602 602
 		);
603 603
 
604
-		$response = wpinv_html_select( $args );
604
+		$response = wpinv_html_select($args);
605 605
 
606 606
 	} else {
607 607
 		$response = 'nostates';
@@ -610,10 +610,10 @@  discard block
 block discarded – undo
610 610
 	return $response;
611 611
 }
612 612
 
613
-function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
614
-    $country = !empty( $country ) ? $country : wpinv_get_default_country();
613
+function wpinv_default_billing_country($country = '', $user_id = 0) {
614
+    $country = !empty($country) ? $country : wpinv_get_default_country();
615 615
     
616
-    return apply_filters( 'wpinv_default_billing_country', $country, $user_id );
616
+    return apply_filters('wpinv_default_billing_country', $country, $user_id);
617 617
 }
618 618
 
619 619
 /**
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
  */
626 626
 function wpinv_get_address_formats() {
627 627
 
628
-		return apply_filters( 'wpinv_localisation_address_formats',
628
+		return apply_filters('wpinv_localisation_address_formats',
629 629
 			array(
630 630
 				'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}",
631 631
 				'AU'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}",
@@ -674,9 +674,9 @@  discard block
 block discarded – undo
674 674
  * @see `wpinv_get_invoice_address_replacements`
675 675
  * @return string
676 676
  */
677
-function wpinv_get_full_address_format( $country = false) {
677
+function wpinv_get_full_address_format($country = false) {
678 678
 
679
-    if( empty( $country ) ) {
679
+    if (empty($country)) {
680 680
         $country = wpinv_get_default_country();
681 681
     }
682 682
 
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
 	$formats = wpinv_get_address_formats();
685 685
 
686 686
 	// Get format for the specified country.
687
-	$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
687
+	$format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default'];
688 688
     
689 689
     /**
690 690
 	 * Filters the address format to use on Invoices.
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
 	 * @param string $format  The address format to use.
697 697
      * @param string $country The country who's address format is being retrieved.
698 698
 	 */
699
-    return apply_filters( 'wpinv_get_full_address_format', $format, $country );
699
+    return apply_filters('wpinv_get_full_address_format', $format, $country);
700 700
 }
701 701
 
702 702
 /**
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
  * @param array $billing_details customer's billing details
708 708
  * @return array
709 709
  */
710
-function wpinv_get_invoice_address_replacements( $billing_details ) {
710
+function wpinv_get_invoice_address_replacements($billing_details) {
711 711
 
712 712
     $default_args = array(
713 713
         'address'           => '',
@@ -720,22 +720,22 @@  discard block
 block discarded – undo
720 720
 		'company'           => '',
721 721
     );
722 722
 
723
-    $args    = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' );
723
+    $args    = map_deep(wp_parse_args($billing_details, $default_args), 'trim');
724 724
     $state   = $args['state'];
725 725
     $country = $args['country'];
726 726
 
727 727
     // Handle full country name.
728
-    $full_country = empty( $country ) ? $country : wpinv_country_name( $country );
728
+    $full_country = empty($country) ? $country : wpinv_country_name($country);
729 729
 
730 730
     // Handle full state name.
731
-    $full_state   = ( $country && $state ) ?  wpinv_state_name( $state, $country ) : $state;
731
+    $full_state   = ($country && $state) ?  wpinv_state_name($state, $country) : $state;
732 732
 
733 733
     $args['postcode']    = $args['zip'];
734 734
     $args['name']        = $args['first_name'] . ' ' . $args['last_name'];
735 735
     $args['state']       = $full_state;
736 736
     $args['state_code']  = $state;
737 737
     $args['country']     = $full_country;
738
-    $args['country_code']= $country;
738
+    $args['country_code'] = $country;
739 739
 
740 740
     /**
741 741
 	 * Filters the address format replacements to use on Invoices.
@@ -746,14 +746,14 @@  discard block
 block discarded – undo
746 746
 	 * @param array $replacements  The address replacements to use.
747 747
      * @param array $billing_details  The billing details to use.
748 748
 	 */
749
-    $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details );
749
+    $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details);
750 750
 
751 751
     $return = array();
752 752
 
753
-    foreach( $replacements as $key => $value ) {
754
-        $value  = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : '';
753
+    foreach ($replacements as $key => $value) {
754
+        $value = is_scalar($value) ? trim(sanitize_text_field($value)) : '';
755 755
         $return['{{' . $key . '}}'] = $value;
756
-        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper( $value );
756
+        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value);
757 757
     }
758 758
 
759 759
     return $return;
@@ -767,6 +767,6 @@  discard block
 block discarded – undo
767 767
  * @since 1.0.14
768 768
  * @return string
769 769
  */
770
-function wpinv_trim_formatted_address_line( $line ) {
771
-	return trim( $line, ', ' );
770
+function wpinv_trim_formatted_address_line($line) {
771
+	return trim($line, ', ');
772 772
 }
773 773
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-payment-form-elements.php 1 patch
Spacing   +311 added lines, -311 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) {
3
+if (!defined('ABSPATH')) {
4 4
     exit; // Exit if accessed directly
5 5
 }
6 6
 
@@ -13,15 +13,15 @@  discard block
 block discarded – undo
13 13
 
14 14
     public function __construct() {
15 15
 
16
-        foreach( $this->get_elements() as $element ) {
16
+        foreach ($this->get_elements() as $element) {
17 17
             $element = $element['type'];
18 18
 
19
-            if ( method_exists( $this, "render_{$element}_template" ) ) {
20
-                add_action( 'wpinv_payment_form_render_element_template', array( $this, "render_{$element}_template" ), 10, 2 );
19
+            if (method_exists($this, "render_{$element}_template")) {
20
+                add_action('wpinv_payment_form_render_element_template', array($this, "render_{$element}_template"), 10, 2);
21 21
             }
22 22
 
23
-            if ( method_exists( $this, "edit_{$element}_template" ) ) {
24
-                add_action( 'wpinv_payment_form_edit_element_template', array( $this, "edit_{$element}_template" ), 10, 2 );
23
+            if (method_exists($this, "edit_{$element}_template")) {
24
+                add_action('wpinv_payment_form_edit_element_template', array($this, "edit_{$element}_template"), 10, 2);
25 25
             }
26 26
 
27 27
 
@@ -34,20 +34,20 @@  discard block
 block discarded – undo
34 34
      */
35 35
     public function get_elements() {
36 36
 
37
-        if ( ! empty( $this->elements ) ) {
37
+        if (!empty($this->elements)) {
38 38
             return $this->elements;
39 39
         }
40 40
 
41
-        $this->elements = wpinv_get_data( 'payment-form-elements' );
41
+        $this->elements = wpinv_get_data('payment-form-elements');
42 42
 
43
-        $this->elements = apply_filters( 'wpinv_filter_core_payment_form_elements', $this->elements );
43
+        $this->elements = apply_filters('wpinv_filter_core_payment_form_elements', $this->elements);
44 44
         return $this->elements;
45 45
     }
46 46
 
47 47
     /**
48 48
      * Returns the restrict markup.
49 49
      */
50
-    public function get_restrict_markup( $field, $field_type ) {
50
+    public function get_restrict_markup($field, $field_type) {
51 51
         $restrict = "$field.type=='$field_type'";
52 52
         return "v-if=\"$restrict\"";
53 53
     }
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
     /**
56 56
      * Renders the gateway select element template.
57 57
      */
58
-    public function render_gateway_select_template( $field ) {
59
-        $restrict = $this->get_restrict_markup( $field, 'gateway_select' );
60
-        $text     = __( 'The gateway select box will appear hear', 'invoicing' );
58
+    public function render_gateway_select_template($field) {
59
+        $restrict = $this->get_restrict_markup($field, 'gateway_select');
60
+        $text     = __('The gateway select box will appear hear', 'invoicing');
61 61
         echo "
62 62
             <div $restrict class='alert alert-info' role='alert'>
63 63
                 <span>$text</span>
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
     /**
69 69
      * Renders the edit gateway select element template.
70 70
      */
71
-    public function edit_gateway_select_template( $field ) {
72
-        $restrict = $this->get_restrict_markup( $field, 'gateway_select' );
73
-        $label    = __( 'The gateway select text', 'invoicing' );
71
+    public function edit_gateway_select_template($field) {
72
+        $restrict = $this->get_restrict_markup($field, 'gateway_select');
73
+        $label    = __('The gateway select text', 'invoicing');
74 74
         $id       = $field . '.id + "_edit"';
75 75
         echo "
76 76
             <div $restrict>
@@ -86,10 +86,10 @@  discard block
 block discarded – undo
86 86
     /**
87 87
      * Renders the ip address element template.
88 88
      */
89
-    public function render_ip_address_template( $field ) {
90
-        $restrict   = $this->get_restrict_markup( $field, 'ip_address' );
91
-        $ip_address = sanitize_text_field( wpinv_get_ip() );
92
-        $url        = esc_url( getpaid_ip_location_url( $ip_address ) );
89
+    public function render_ip_address_template($field) {
90
+        $restrict   = $this->get_restrict_markup($field, 'ip_address');
91
+        $ip_address = sanitize_text_field(wpinv_get_ip());
92
+        $url        = esc_url(getpaid_ip_location_url($ip_address));
93 93
 
94 94
         echo "
95 95
             <div $restrict class='getpaid-ip-info'>
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
     /**
103 103
      * Renders the edit ip address element template.
104 104
      */
105
-    public function edit_ip_address_template( $field ) {
106
-        $restrict = $this->get_restrict_markup( $field, 'ip_address' );
107
-        $label    = __( 'The IP Address text', 'invoicing' );
105
+    public function edit_ip_address_template($field) {
106
+        $restrict = $this->get_restrict_markup($field, 'ip_address');
107
+        $label    = __('The IP Address text', 'invoicing');
108 108
         $id       = $field . '.id + "_edit"';
109 109
         echo "
110 110
             <div $restrict>
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
     /**
121 121
      * Renders the total payable element template.
122 122
      */
123
-    public function render_total_payable_template( $field ) {
124
-        $restrict = $this->get_restrict_markup( $field, 'total_payable' );
125
-        $text     = __( 'The total payable amount will appear here', 'invoicing' );
123
+    public function render_total_payable_template($field) {
124
+        $restrict = $this->get_restrict_markup($field, 'total_payable');
125
+        $text     = __('The total payable amount will appear here', 'invoicing');
126 126
         echo "
127 127
             <div $restrict class='alert alert-info' role='alert'>
128 128
                 <span>$text</span>
@@ -133,9 +133,9 @@  discard block
 block discarded – undo
133 133
     /**
134 134
      * Renders the edit total payable element template.
135 135
      */
136
-    public function edit_total_payable_template( $field ) {
137
-        $restrict = $this->get_restrict_markup( $field, 'total_payable' );
138
-        $label    = __( 'The total payable text', 'invoicing' );
136
+    public function edit_total_payable_template($field) {
137
+        $restrict = $this->get_restrict_markup($field, 'total_payable');
138
+        $label    = __('The total payable text', 'invoicing');
139 139
         $id       = $field . '.id + "_edit"';
140 140
         echo "
141 141
             <div $restrict>
@@ -151,18 +151,18 @@  discard block
 block discarded – undo
151 151
     /**
152 152
      * Renders the title element template.
153 153
      */
154
-    public function render_heading_template( $field ) {
155
-        $restrict = $this->get_restrict_markup( $field, 'heading' );
154
+    public function render_heading_template($field) {
155
+        $restrict = $this->get_restrict_markup($field, 'heading');
156 156
         echo "<component :is='$field.level' $restrict v-html='$field.text'></component>";
157 157
     }
158 158
 
159 159
     /**
160 160
      * Renders the edit title element template.
161 161
      */
162
-    public function edit_heading_template( $field ) {
163
-        $restrict = $this->get_restrict_markup( $field, 'heading' );
164
-        $label    = __( 'Heading', 'invoicing' );
165
-        $label2   = __( 'Select Heading Level', 'invoicing' );
162
+    public function edit_heading_template($field) {
163
+        $restrict = $this->get_restrict_markup($field, 'heading');
164
+        $label    = __('Heading', 'invoicing');
165
+        $label2   = __('Select Heading Level', 'invoicing');
166 166
         $id       = $field . '.id + "_edit"';
167 167
         $id2      = $field . '.id + "_edit2"';
168 168
 
@@ -194,8 +194,8 @@  discard block
 block discarded – undo
194 194
     /**
195 195
      * Renders a paragraph element template.
196 196
      */
197
-    public function render_paragraph_template( $field ) {
198
-        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
197
+    public function render_paragraph_template($field) {
198
+        $restrict = $this->get_restrict_markup($field, 'paragraph');
199 199
         $label    = "$field.text";
200 200
         echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>";
201 201
     }
@@ -203,9 +203,9 @@  discard block
 block discarded – undo
203 203
     /**
204 204
      * Renders the edit paragraph element template.
205 205
      */
206
-    public function edit_paragraph_template( $field ) {
207
-        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
208
-        $label    = __( 'Enter your text', 'invoicing' );
206
+    public function edit_paragraph_template($field) {
207
+        $restrict = $this->get_restrict_markup($field, 'paragraph');
208
+        $label    = __('Enter your text', 'invoicing');
209 209
         $id       = $field . '.id + "_edit"';
210 210
         echo "
211 211
             <div $restrict>
@@ -221,8 +221,8 @@  discard block
 block discarded – undo
221 221
     /**
222 222
      * Renders the text element template.
223 223
      */
224
-    public function render_text_template( $field ) {
225
-        $restrict = $this->get_restrict_markup( $field, 'text' );
224
+    public function render_text_template($field) {
225
+        $restrict = $this->get_restrict_markup($field, 'text');
226 226
         $label    = "$field.label";
227 227
         echo "
228 228
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -237,56 +237,56 @@  discard block
 block discarded – undo
237 237
     /**
238 238
      * Renders the edit price select element template.
239 239
      */
240
-    public function edit_price_select_template( $field ) {
241
-        $restrict = $this->get_restrict_markup( $field, 'price_select' );
240
+    public function edit_price_select_template($field) {
241
+        $restrict = $this->get_restrict_markup($field, 'price_select');
242 242
         
243
-        $label3   = __( 'Help text', 'invoicing' );
244
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
243
+        $label3   = __('Help text', 'invoicing');
244
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
245 245
         $id3      = $field . '.id + "_edit3"';
246
-        $label6   = __( 'Options', 'invoicing' );
246
+        $label6   = __('Options', 'invoicing');
247 247
         $id6      = $field . '.id + "_edit5"';
248 248
         ?>
249 249
             <div <?php echo $restrict; ?>>
250
-                <small class='form-text text-muted mb-2'><?php _e( 'This amount will be added to the total amount for this form', 'invoicing' ); ?></small>
250
+                <small class='form-text text-muted mb-2'><?php _e('This amount will be added to the total amount for this form', 'invoicing'); ?></small>
251 251
                 <div class='form-group'>
252 252
                     <label class="d-block">
253
-                        <span><?php _e( 'Field Label', 'invoicing' ); ?></span>
253
+                        <span><?php _e('Field Label', 'invoicing'); ?></span>
254 254
                         <input v-model='<?php echo $field; ?>.label' class='form-control' />
255 255
                     </label>
256 256
                 </div>
257 257
 
258 258
                 <div class='form-group' v-if="<?php echo $field; ?>.select_type=='select'">
259 259
                     <label class="d-block">
260
-                        <span><?php _e( 'Placeholder text', 'invoicing' ); ?></span>
260
+                        <span><?php _e('Placeholder text', 'invoicing'); ?></span>
261 261
                         <input v-model='<?php echo $field; ?>.placeholder' class='form-control' />
262 262
                     </label>
263 263
                 </div>
264 264
 
265 265
                 <div class='form-group'>
266 266
                     <label class="d-block">
267
-                        <span><?php _e( 'Select Type', 'invoicing' ); ?></span>
267
+                        <span><?php _e('Select Type', 'invoicing'); ?></span>
268 268
                         <select class='form-control custom-select' v-model='<?php echo $field; ?>.select_type'>
269
-                            <option value='select'><?php _e( 'Dropdown', 'invoicing' ) ?></option>
270
-                            <option value='checkboxes'><?php _e( 'Checkboxes', 'invoicing' ) ?></option>
271
-                            <option value='radios'><?php _e( 'Radio Buttons', 'invoicing' ) ?></option>
272
-                            <option value='buttons'><?php _e( 'Buttons', 'invoicing' ) ?></option>
273
-                            <option value='circles'><?php _e( 'Circles', 'invoicing' ) ?></option>
269
+                            <option value='select'><?php _e('Dropdown', 'invoicing') ?></option>
270
+                            <option value='checkboxes'><?php _e('Checkboxes', 'invoicing') ?></option>
271
+                            <option value='radios'><?php _e('Radio Buttons', 'invoicing') ?></option>
272
+                            <option value='buttons'><?php _e('Buttons', 'invoicing') ?></option>
273
+                            <option value='circles'><?php _e('Circles', 'invoicing') ?></option>
274 274
                         </select>
275 275
                     </label>
276 276
                 </div>
277 277
 
278 278
                 <div class='form-group'>
279 279
                     <label class="d-block">
280
-                        <span><?php _e( 'Options', 'invoicing' ); ?></span>
280
+                        <span><?php _e('Options', 'invoicing'); ?></span>
281 281
                         <textarea placeholder='Basic|10,Pro|99,Business|199' v-model='<?php echo $field; ?>.options' class='form-control' rows='3'></textarea>
282
-                        <small class='form-text text-muted mb-2'><?php _e( 'Use commas to separate options and pipes to separate a label and its price. Do not include a currency symbol in the price.', 'invoicing' ); ?></small>
282
+                        <small class='form-text text-muted mb-2'><?php _e('Use commas to separate options and pipes to separate a label and its price. Do not include a currency symbol in the price.', 'invoicing'); ?></small>
283 283
                     </label>
284 284
                 </div>
285 285
 
286 286
                 <div class='form-group'>
287 287
                     <label class="d-block">
288
-                        <span><?php _e( 'Help Text', 'invoicing' ); ?></span>
289
-                        <textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='<?php echo $field; ?>.description' class='form-control' rows='3'></textarea>
288
+                        <span><?php _e('Help Text', 'invoicing'); ?></span>
289
+                        <textarea placeholder='<?php esc_attr_e('Add some help text for this field', 'invoicing'); ?>' v-model='<?php echo $field; ?>.description' class='form-control' rows='3'></textarea>
290 290
                     </label>
291 291
                 </div>
292 292
             </div>
@@ -297,8 +297,8 @@  discard block
 block discarded – undo
297 297
     /**
298 298
      * Renders the price select element template.
299 299
      */
300
-    public function render_price_select_template( $field ) {
301
-        $restrict = $this->get_restrict_markup( $field, 'price_select' );
300
+    public function render_price_select_template($field) {
301
+        $restrict = $this->get_restrict_markup($field, 'price_select');
302 302
         ?>
303 303
             <div <?php echo $restrict; ?> class='wpinv-payment-form-field-preview'>
304 304
                 <div class='wpinv-payment-form-field-preview-overlay'></div>
@@ -306,24 +306,24 @@  discard block
 block discarded – undo
306 306
                 <label>{{<?php echo $field; ?>.label}}</label>
307 307
 
308 308
                 <!-- Buttons -->
309
-                <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="buttons"' class="getpaid-price-buttons">
310
-                    <span v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index">
311
-                        <input type="radio" :id="<?php echo esc_attr( $field ); ?>.id + index" :checked="index==0" />
312
-                        <label :for="<?php echo esc_attr( $field ); ?>.id + index" class="rounded">{{option | optionize}}</label>
309
+                <div v-if='<?php echo esc_attr($field); ?>.select_type=="buttons"' class="getpaid-price-buttons">
310
+                    <span v-for="(option, index) in <?php echo esc_attr($field); ?>.options.split(',')" :key="index">
311
+                        <input type="radio" :id="<?php echo esc_attr($field); ?>.id + index" :checked="index==0" />
312
+                        <label :for="<?php echo esc_attr($field); ?>.id + index" class="rounded">{{option | optionize}}</label>
313 313
                     </span>
314 314
                 </div>
315 315
 
316 316
                 <!-- Circles -->
317
-                <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="circles"' class="getpaid-price-buttons getpaid-price-circles">
318
-                    <span v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index">
319
-                        <input type="radio" :id="<?php echo esc_attr( $field ); ?>.id + index" :checked="index==0" />
320
-                        <label :for="<?php echo esc_attr( $field ); ?>.id + index"><span>{{option | optionize}}</span></label>
317
+                <div v-if='<?php echo esc_attr($field); ?>.select_type=="circles"' class="getpaid-price-buttons getpaid-price-circles">
318
+                    <span v-for="(option, index) in <?php echo esc_attr($field); ?>.options.split(',')" :key="index">
319
+                        <input type="radio" :id="<?php echo esc_attr($field); ?>.id + index" :checked="index==0" />
320
+                        <label :for="<?php echo esc_attr($field); ?>.id + index"><span>{{option | optionize}}</span></label>
321 321
                     </span>
322 322
                 </div>
323 323
 
324 324
                 <!-- Radios -->
325
-                <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="radios"'>
326
-                    <div v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index">
325
+                <div v-if='<?php echo esc_attr($field); ?>.select_type=="radios"'>
326
+                    <div v-for="(option, index) in <?php echo esc_attr($field); ?>.options.split(',')" :key="index">
327 327
                         <label>
328 328
                             <input type="radio" :checked="index==0" />
329 329
                             <span>{{option | optionize}}</span>
@@ -332,8 +332,8 @@  discard block
 block discarded – undo
332 332
                 </div>
333 333
 
334 334
                 <!-- Checkboxes -->
335
-                <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="checkboxes"'>
336
-                    <div v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index">
335
+                <div v-if='<?php echo esc_attr($field); ?>.select_type=="checkboxes"'>
336
+                    <div v-for="(option, index) in <?php echo esc_attr($field); ?>.options.split(',')" :key="index">
337 337
                         <label>
338 338
                             <input type="checkbox" :checked="index==0" />
339 339
                             <span>{{option | optionize}}</span>
@@ -342,15 +342,15 @@  discard block
 block discarded – undo
342 342
                 </div>
343 343
 
344 344
                 <!-- Select -->
345
-                <select v-if='<?php echo esc_attr( $field ); ?>.select_type=="select"' class='form-control custom-select'>
346
-                    <option v-if="<?php echo esc_attr( $field ); ?>.placeholder" selected="selected">
347
-                        {{<?php echo esc_attr( $field ); ?>.placeholder}}
345
+                <select v-if='<?php echo esc_attr($field); ?>.select_type=="select"' class='form-control custom-select'>
346
+                    <option v-if="<?php echo esc_attr($field); ?>.placeholder" selected="selected">
347
+                        {{<?php echo esc_attr($field); ?>.placeholder}}
348 348
                     </option>
349
-                    <option v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index">
349
+                    <option v-for="(option, index) in <?php echo esc_attr($field); ?>.options.split(',')" :key="index">
350 350
                         {{option | optionize}}
351 351
                     </option>
352 352
                 </select>
353
-                <small v-if='<?php echo esc_attr( $field ); ?>.description' class='form-text text-muted' v-html='<?php echo esc_attr( $field ); ?>.description'></small>
353
+                <small v-if='<?php echo esc_attr($field); ?>.description' class='form-text text-muted' v-html='<?php echo esc_attr($field); ?>.description'></small>
354 354
             </div>
355 355
 
356 356
         <?php
@@ -359,17 +359,17 @@  discard block
 block discarded – undo
359 359
     /**
360 360
      * Renders the edit price input element template.
361 361
      */
362
-    public function edit_price_input_template( $field ) {
363
-        $restrict = $this->get_restrict_markup( $field, 'price_input' );
364
-        $label    = __( 'Field Label', 'invoicing' );
362
+    public function edit_price_input_template($field) {
363
+        $restrict = $this->get_restrict_markup($field, 'price_input');
364
+        $label    = __('Field Label', 'invoicing');
365 365
         $id       = $field . '.id + "_edit"';
366
-        $label2   = __( 'Placeholder text', 'invoicing' );
366
+        $label2   = __('Placeholder text', 'invoicing');
367 367
         $id2      = $field . '.id + "_edit2"';
368
-        $label3   = __( 'Help text', 'invoicing' );
369
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
368
+        $label3   = __('Help text', 'invoicing');
369
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
370 370
         $id3      = $field . '.id + "_edit3"';
371
-        $label5   = __( 'The amount that users add to this field will be added to the total amount', 'invoicing' );
372
-        $label6   = __( 'Default Amount', 'invoicing' );
371
+        $label5   = __('The amount that users add to this field will be added to the total amount', 'invoicing');
372
+        $label6   = __('Default Amount', 'invoicing');
373 373
         $id6      = $field . '.id + "_edit5"';
374 374
         echo "
375 375
             <div $restrict>
@@ -397,16 +397,16 @@  discard block
 block discarded – undo
397 397
     /**
398 398
      * Renders the edit text element template.
399 399
      */
400
-    public function edit_text_template( $field ) {
401
-        $restrict = $this->get_restrict_markup( $field, 'text' );
402
-        $label    = __( 'Field Label', 'invoicing' );
400
+    public function edit_text_template($field) {
401
+        $restrict = $this->get_restrict_markup($field, 'text');
402
+        $label    = __('Field Label', 'invoicing');
403 403
         $id       = $field . '.id + "_edit"';
404
-        $label2   = __( 'Placeholder text', 'invoicing' );
404
+        $label2   = __('Placeholder text', 'invoicing');
405 405
         $id2      = $field . '.id + "_edit2"';
406
-        $label3   = __( 'Help text', 'invoicing' );
407
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
406
+        $label3   = __('Help text', 'invoicing');
407
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
408 408
         $id3      = $field . '.id + "_edit3"';
409
-        $label5   = __( 'Is this field required?', 'invoicing' );
409
+        $label5   = __('Is this field required?', 'invoicing');
410 410
         $id4      = $field . '.id + "_edit4"';
411 411
         echo "
412 412
             <div $restrict>
@@ -434,8 +434,8 @@  discard block
 block discarded – undo
434 434
     /**
435 435
      * Renders the textarea element template.
436 436
      */
437
-    public function render_textarea_template( $field ) {
438
-        $restrict = $this->get_restrict_markup( $field, 'textarea' );
437
+    public function render_textarea_template($field) {
438
+        $restrict = $this->get_restrict_markup($field, 'textarea');
439 439
         $label    = "$field.label";
440 440
         echo "
441 441
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -450,16 +450,16 @@  discard block
 block discarded – undo
450 450
     /**
451 451
      * Renders the edit textarea element template.
452 452
      */
453
-    public function edit_textarea_template( $field ) {
454
-        $restrict = $this->get_restrict_markup( $field, 'textarea' );
455
-        $label    = __( 'Field Label', 'invoicing' );
453
+    public function edit_textarea_template($field) {
454
+        $restrict = $this->get_restrict_markup($field, 'textarea');
455
+        $label    = __('Field Label', 'invoicing');
456 456
         $id       = $field . '.id + "_edit"';
457
-        $label2   = __( 'Placeholder text', 'invoicing' );
457
+        $label2   = __('Placeholder text', 'invoicing');
458 458
         $id2      = $field . '.id + "_edit2"';
459
-        $label3   = __( 'Help text', 'invoicing' );
460
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
459
+        $label3   = __('Help text', 'invoicing');
460
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
461 461
         $id3      = $field . '.id + "_edit3"';
462
-        $label5   = __( 'Is this field required?', 'invoicing' );
462
+        $label5   = __('Is this field required?', 'invoicing');
463 463
         $id4      = $field . '.id + "_edit4"';
464 464
         echo "
465 465
             <div $restrict>
@@ -487,8 +487,8 @@  discard block
 block discarded – undo
487 487
     /**
488 488
      * Renders the select element template.
489 489
      */
490
-    public function render_select_template( $field ) {
491
-        $restrict    = $this->get_restrict_markup( $field, 'select' );
490
+    public function render_select_template($field) {
491
+        $restrict    = $this->get_restrict_markup($field, 'select');
492 492
         $label       = "$field.label";
493 493
         $placeholder = "$field.placeholder";
494 494
         $id          = $field . '.id';
@@ -508,18 +508,18 @@  discard block
 block discarded – undo
508 508
     /**
509 509
      * Renders the edit select element template.
510 510
      */
511
-    public function edit_select_template( $field ) {
512
-        $restrict = $this->get_restrict_markup( $field, 'select' );
513
-        $label    = __( 'Field Label', 'invoicing' );
511
+    public function edit_select_template($field) {
512
+        $restrict = $this->get_restrict_markup($field, 'select');
513
+        $label    = __('Field Label', 'invoicing');
514 514
         $id       = $field . '.id + "_edit"';
515
-        $label2   = __( 'Placeholder text', 'invoicing' );
515
+        $label2   = __('Placeholder text', 'invoicing');
516 516
         $id2      = $field . '.id + "_edit2"';
517
-        $label3   = __( 'Help text', 'invoicing' );
518
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
517
+        $label3   = __('Help text', 'invoicing');
518
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
519 519
         $id3      = $field . '.id + "_edit3"';
520
-        $label5   = __( 'Is this field required?', 'invoicing' );
520
+        $label5   = __('Is this field required?', 'invoicing');
521 521
         $id4      = $field . '.id + "_edit4"';
522
-        $label6   = __( 'Available Options', 'invoicing' );
522
+        $label6   = __('Available Options', 'invoicing');
523 523
         echo "
524 524
             <div $restrict>
525 525
                 <div class='form-group'>
@@ -557,8 +557,8 @@  discard block
 block discarded – undo
557 557
     /**
558 558
      * Renders the checkbox element template.
559 559
      */
560
-    public function render_checkbox_template( $field ) {
561
-        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
560
+    public function render_checkbox_template($field) {
561
+        $restrict = $this->get_restrict_markup($field, 'checkbox');
562 562
         echo "
563 563
             <div class='form-check' $restrict>
564 564
                 <div class='wpinv-payment-form-field-preview-overlay'></div>
@@ -572,14 +572,14 @@  discard block
 block discarded – undo
572 572
     /**
573 573
      * Renders the edit checkbox element template.
574 574
      */
575
-    public function edit_checkbox_template( $field ) {
576
-        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
577
-        $label    = __( 'Field Label', 'invoicing' );
575
+    public function edit_checkbox_template($field) {
576
+        $restrict = $this->get_restrict_markup($field, 'checkbox');
577
+        $label    = __('Field Label', 'invoicing');
578 578
         $id       = $field . '.id + "_edit"';
579
-        $label2   = __( 'Help text', 'invoicing' );
580
-        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
579
+        $label2   = __('Help text', 'invoicing');
580
+        $label3   = esc_attr__('Add some help text for this field', 'invoicing');
581 581
         $id2      = $field . '.id + "_edit2"';
582
-        $label4   = __( 'Is this field required?', 'invoicing' );
582
+        $label4   = __('Is this field required?', 'invoicing');
583 583
         $id3      = $field . '.id + "_edit3"';
584 584
         echo "
585 585
             <div $restrict>
@@ -603,8 +603,8 @@  discard block
 block discarded – undo
603 603
     /**
604 604
      * Renders the radio element template.
605 605
      */
606
-    public function render_radio_template( $field ) {
607
-        $restrict    = $this->get_restrict_markup( $field, 'radio' );
606
+    public function render_radio_template($field) {
607
+        $restrict    = $this->get_restrict_markup($field, 'radio');
608 608
         $label       = "$field.label";
609 609
         $id          = $field . '.id';
610 610
         echo "
@@ -623,16 +623,16 @@  discard block
 block discarded – undo
623 623
     /**
624 624
      * Renders the edit radio element template.
625 625
      */
626
-    public function edit_radio_template( $field ) {
627
-        $restrict = $this->get_restrict_markup( $field, 'radio' );
628
-        $label    = __( 'Field Label', 'invoicing' );
626
+    public function edit_radio_template($field) {
627
+        $restrict = $this->get_restrict_markup($field, 'radio');
628
+        $label    = __('Field Label', 'invoicing');
629 629
         $id       = $field . '.id + "_edit"';
630
-        $label2   = __( 'Help text', 'invoicing' );
631
-        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
630
+        $label2   = __('Help text', 'invoicing');
631
+        $label3   = esc_attr__('Add some help text for this field', 'invoicing');
632 632
         $id2      = $field . '.id + "_edit3"';
633
-        $label4   = __( 'Is this field required?', 'invoicing' );
633
+        $label4   = __('Is this field required?', 'invoicing');
634 634
         $id3      = $field . '.id + "_edit4"';
635
-        $label5   = __( 'Available Options', 'invoicing' );
635
+        $label5   = __('Available Options', 'invoicing');
636 636
         echo "
637 637
             <div $restrict>
638 638
                 <div class='form-group'>
@@ -666,8 +666,8 @@  discard block
 block discarded – undo
666 666
     /**
667 667
      * Renders the address element template.
668 668
      */
669
-    public function render_address_template( $field ) {
670
-        $restrict    = $this->get_restrict_markup( $field, 'address' );
669
+    public function render_address_template($field) {
670
+        $restrict = $this->get_restrict_markup($field, 'address');
671 671
 
672 672
         echo "
673 673
             <div class='wpinv-address-wrapper' $restrict>
@@ -689,13 +689,13 @@  discard block
 block discarded – undo
689 689
     /**
690 690
      * Renders the edit address element template.
691 691
      */
692
-    public function edit_address_template( $field ) {
693
-        $restrict  = $this->get_restrict_markup( $field, 'address' );
694
-        $label     = __( 'Field Label', 'invoicing' );
695
-        $label2    = __( 'Placeholder', 'invoicing' );
696
-        $label3    = __( 'Description', 'invoicing' );
697
-        $label4    = __( 'Is required', 'invoicing' );
698
-        $label5    = __( 'Is visible', 'invoicing' );
692
+    public function edit_address_template($field) {
693
+        $restrict  = $this->get_restrict_markup($field, 'address');
694
+        $label     = __('Field Label', 'invoicing');
695
+        $label2    = __('Placeholder', 'invoicing');
696
+        $label3    = __('Description', 'invoicing');
697
+        $label4    = __('Is required', 'invoicing');
698
+        $label5    = __('Is visible', 'invoicing');
699 699
         $id        = $field . '.id + "_edit_label"';
700 700
         $id2       = $field . '.id + "_edit_placeholder"';
701 701
         $id3       = $field . '.id + "_edit_description"';
@@ -763,8 +763,8 @@  discard block
 block discarded – undo
763 763
     /**
764 764
      * Renders the email element template.
765 765
      */
766
-    public function render_email_template( $field ) {
767
-        $restrict = $this->get_restrict_markup( $field, 'email' );
766
+    public function render_email_template($field) {
767
+        $restrict = $this->get_restrict_markup($field, 'email');
768 768
         $label    = "$field.label";
769 769
         echo "
770 770
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -779,8 +779,8 @@  discard block
 block discarded – undo
779 779
     /**
780 780
      * Renders the billing_email element template.
781 781
      */
782
-    public function render_billing_email_template( $field ) {
783
-        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
782
+    public function render_billing_email_template($field) {
783
+        $restrict = $this->get_restrict_markup($field, 'billing_email');
784 784
         $label    = "$field.label";
785 785
         echo "
786 786
             <div $restrict>
@@ -794,16 +794,16 @@  discard block
 block discarded – undo
794 794
     /**
795 795
      * Renders the edit email element template.
796 796
      */
797
-    public function edit_email_template( $field ) {
798
-        $restrict = $this->get_restrict_markup( $field, 'email' );
799
-        $label    = __( 'Field Label', 'invoicing' );
797
+    public function edit_email_template($field) {
798
+        $restrict = $this->get_restrict_markup($field, 'email');
799
+        $label    = __('Field Label', 'invoicing');
800 800
         $id       = $field . '.id + "_edit"';
801
-        $label2   = __( 'Placeholder text', 'invoicing' );
801
+        $label2   = __('Placeholder text', 'invoicing');
802 802
         $id2      = $field . '.id + "_edit2"';
803
-        $label3   = __( 'Help text', 'invoicing' );
804
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
803
+        $label3   = __('Help text', 'invoicing');
804
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
805 805
         $id3      = $field . '.id + "_edit3"';
806
-        $label5   = __( 'Is this field required?', 'invoicing' );
806
+        $label5   = __('Is this field required?', 'invoicing');
807 807
         $id4      = $field . '.id + "_edit4"';
808 808
         echo "
809 809
             <div $restrict>
@@ -831,16 +831,16 @@  discard block
 block discarded – undo
831 831
     /**
832 832
      * Renders the edit billing_email element template.
833 833
      */
834
-    public function edit_billing_email_template( $field ) {
835
-        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
836
-        $label    = __( 'Field Label', 'invoicing' );
834
+    public function edit_billing_email_template($field) {
835
+        $restrict = $this->get_restrict_markup($field, 'billing_email');
836
+        $label    = __('Field Label', 'invoicing');
837 837
         $id       = $field . '.id + "_edit"';
838
-        $label2   = __( 'Placeholder text', 'invoicing' );
838
+        $label2   = __('Placeholder text', 'invoicing');
839 839
         $id2      = $field . '.id + "_edit2"';
840
-        $label3   = __( 'Help text', 'invoicing' );
841
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
840
+        $label3   = __('Help text', 'invoicing');
841
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
842 842
         $id3      = $field . '.id + "_edit3"';
843
-        $label5   = __( 'Is this field required?', 'invoicing' );
843
+        $label5   = __('Is this field required?', 'invoicing');
844 844
         $id4      = $field . '.id + "_edit4"';
845 845
         echo "
846 846
             <div $restrict>
@@ -864,8 +864,8 @@  discard block
 block discarded – undo
864 864
     /**
865 865
      * Renders the website element template.
866 866
      */
867
-    public function render_website_template( $field ) {
868
-        $restrict = $this->get_restrict_markup( $field, 'website' );
867
+    public function render_website_template($field) {
868
+        $restrict = $this->get_restrict_markup($field, 'website');
869 869
         $label    = "$field.label";
870 870
         echo "
871 871
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -880,16 +880,16 @@  discard block
 block discarded – undo
880 880
     /**
881 881
      * Renders the edit website element template.
882 882
      */
883
-    public function edit_website_template( $field ) {
884
-        $restrict = $this->get_restrict_markup( $field, 'website' );
885
-        $label    = __( 'Field Label', 'invoicing' );
883
+    public function edit_website_template($field) {
884
+        $restrict = $this->get_restrict_markup($field, 'website');
885
+        $label    = __('Field Label', 'invoicing');
886 886
         $id       = $field . '.id + "_edit"';
887
-        $label2   = __( 'Placeholder text', 'invoicing' );
887
+        $label2   = __('Placeholder text', 'invoicing');
888 888
         $id2      = $field . '.id + "_edit2"';
889
-        $label3   = __( 'Help text', 'invoicing' );
890
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
889
+        $label3   = __('Help text', 'invoicing');
890
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
891 891
         $id3      = $field . '.id + "_edit3"';
892
-        $label5   = __( 'Is this field required?', 'invoicing' );
892
+        $label5   = __('Is this field required?', 'invoicing');
893 893
         $id4      = $field . '.id + "_edit4"';
894 894
         echo "
895 895
             <div $restrict>
@@ -917,8 +917,8 @@  discard block
 block discarded – undo
917 917
     /**
918 918
      * Renders the date element template.
919 919
      */
920
-    public function render_date_template( $field ) {
921
-        $restrict = $this->get_restrict_markup( $field, 'date' );
920
+    public function render_date_template($field) {
921
+        $restrict = $this->get_restrict_markup($field, 'date');
922 922
         $label    = "$field.label";
923 923
         echo "
924 924
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -933,14 +933,14 @@  discard block
 block discarded – undo
933 933
     /**
934 934
      * Renders the edit date element template.
935 935
      */
936
-    public function edit_date_template( $field ) {
937
-        $restrict = $this->get_restrict_markup( $field, 'date' );
938
-        $label    = __( 'Field Label', 'invoicing' );
936
+    public function edit_date_template($field) {
937
+        $restrict = $this->get_restrict_markup($field, 'date');
938
+        $label    = __('Field Label', 'invoicing');
939 939
         $id       = $field . '.id + "_edit"';
940
-        $label3   = __( 'Help text', 'invoicing' );
941
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
940
+        $label3   = __('Help text', 'invoicing');
941
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
942 942
         $id3      = $field . '.id + "_edit3"';
943
-        $label5   = __( 'Is this field required?', 'invoicing' );
943
+        $label5   = __('Is this field required?', 'invoicing');
944 944
         $id4      = $field . '.id + "_edit4"';
945 945
         echo "
946 946
             <div $restrict>
@@ -964,8 +964,8 @@  discard block
 block discarded – undo
964 964
     /**
965 965
      * Renders the time element template.
966 966
      */
967
-    public function render_time_template( $field ) {
968
-        $restrict = $this->get_restrict_markup( $field, 'time' );
967
+    public function render_time_template($field) {
968
+        $restrict = $this->get_restrict_markup($field, 'time');
969 969
         $label    = "$field.label";
970 970
         echo "
971 971
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -980,14 +980,14 @@  discard block
 block discarded – undo
980 980
     /**
981 981
      * Renders the edit time element template.
982 982
      */
983
-    public function edit_time_template( $field ) {
984
-        $restrict = $this->get_restrict_markup( $field, 'time' );
985
-        $label    = __( 'Field Label', 'invoicing' );
983
+    public function edit_time_template($field) {
984
+        $restrict = $this->get_restrict_markup($field, 'time');
985
+        $label    = __('Field Label', 'invoicing');
986 986
         $id       = $field . '.id + "_edit"';
987
-        $label3   = __( 'Help text', 'invoicing' );
988
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
987
+        $label3   = __('Help text', 'invoicing');
988
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
989 989
         $id3      = $field . '.id + "_edit3"';
990
-        $label5   = __( 'Is this field required?', 'invoicing' );
990
+        $label5   = __('Is this field required?', 'invoicing');
991 991
         $id4      = $field . '.id + "_edit4"';
992 992
         echo "
993 993
             <div $restrict>
@@ -1011,8 +1011,8 @@  discard block
 block discarded – undo
1011 1011
     /**
1012 1012
      * Renders the number element template.
1013 1013
      */
1014
-    public function render_number_template( $field ) {
1015
-        $restrict = $this->get_restrict_markup( $field, 'number' );
1014
+    public function render_number_template($field) {
1015
+        $restrict = $this->get_restrict_markup($field, 'number');
1016 1016
         $label    = "$field.label";
1017 1017
         echo "
1018 1018
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -1027,16 +1027,16 @@  discard block
 block discarded – undo
1027 1027
     /**
1028 1028
      * Renders the edit number element template.
1029 1029
      */
1030
-    public function edit_number_template( $field ) {
1031
-        $restrict = $this->get_restrict_markup( $field, 'number' );
1032
-        $label    = __( 'Field Label', 'invoicing' );
1030
+    public function edit_number_template($field) {
1031
+        $restrict = $this->get_restrict_markup($field, 'number');
1032
+        $label    = __('Field Label', 'invoicing');
1033 1033
         $id       = $field . '.id + "_edit"';
1034
-        $label2   = __( 'Placeholder text', 'invoicing' );
1034
+        $label2   = __('Placeholder text', 'invoicing');
1035 1035
         $id2      = $field . '.id + "_edit2"';
1036
-        $label3   = __( 'Help text', 'invoicing' );
1037
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1036
+        $label3   = __('Help text', 'invoicing');
1037
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
1038 1038
         $id3      = $field . '.id + "_edit3"';
1039
-        $label5   = __( 'Is this field required?', 'invoicing' );
1039
+        $label5   = __('Is this field required?', 'invoicing');
1040 1040
         $id4      = $field . '.id + "_edit4"';
1041 1041
         echo "
1042 1042
             <div $restrict>
@@ -1064,16 +1064,16 @@  discard block
 block discarded – undo
1064 1064
     /**
1065 1065
      * Renders the separator element template.
1066 1066
      */
1067
-    public function render_separator_template( $field ) {
1068
-        $restrict = $this->get_restrict_markup( $field, 'separator' );
1067
+    public function render_separator_template($field) {
1068
+        $restrict = $this->get_restrict_markup($field, 'separator');
1069 1069
         echo "<hr class='featurette-divider' $restrict>";
1070 1070
     }
1071 1071
 
1072 1072
     /**
1073 1073
      * Renders the pay button element template.
1074 1074
      */
1075
-    public function render_pay_button_template( $field ) {
1076
-        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1075
+    public function render_pay_button_template($field) {
1076
+        $restrict = $this->get_restrict_markup($field, 'pay_button');
1077 1077
         $label    = "$field.label";
1078 1078
         echo "
1079 1079
             <div $restrict>
@@ -1086,14 +1086,14 @@  discard block
 block discarded – undo
1086 1086
     /**
1087 1087
      * Renders the pay button element template.
1088 1088
      */
1089
-    public function edit_pay_button_template( $field ) {
1090
-        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1091
-        $label    = __( 'Button Text', 'invoicing' );
1089
+    public function edit_pay_button_template($field) {
1090
+        $restrict = $this->get_restrict_markup($field, 'pay_button');
1091
+        $label    = __('Button Text', 'invoicing');
1092 1092
         $id       = $field . '.id + "_edit"';
1093
-        $label2   = __( 'Help text', 'invoicing' );
1094
-        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1093
+        $label2   = __('Help text', 'invoicing');
1094
+        $label3   = esc_attr__('Add some help text for this field', 'invoicing');
1095 1095
         $id2      = $field . '.id + "_edit2"';
1096
-        $label4   = esc_attr__( 'Button Type', 'invoicing' );
1096
+        $label4   = esc_attr__('Button Type', 'invoicing');
1097 1097
         $id3      = $field . '.id + "_edit3"';
1098 1098
 
1099 1099
         echo "
@@ -1110,15 +1110,15 @@  discard block
 block discarded – undo
1110 1110
                     <label :for='$id3'>$label4</label>
1111 1111
 
1112 1112
                     <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1113
-                        <option value='btn-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1114
-                        <option value='btn-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1115
-                        <option value='btn-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1116
-                        <option value='btn-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1117
-                        <option value='btn-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1118
-                        <option value='btn-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1119
-                        <option value='btn-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1120
-                        <option value='btn-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1121
-                        <option value='btn-link'>"      . __( 'Link', 'invoicing' ) ."</option>
1113
+                        <option value='btn-primary'>" . __('Primary', 'invoicing') . "</option>
1114
+                        <option value='btn-secondary'>" . __('Secondary', 'invoicing') . "</option>
1115
+                        <option value='btn-success'>"   . __('Success', 'invoicing') . "</option>
1116
+                        <option value='btn-danger'>"    . __('Danger', 'invoicing') . "</option>
1117
+                        <option value='btn-warning'>"   . __('Warning', 'invoicing') . "</option>
1118
+                        <option value='btn-info'>"      . __('Info', 'invoicing') . "</option>
1119
+                        <option value='btn-light'>"     . __('Light', 'invoicing') . "</option>
1120
+                        <option value='btn-dark'>"      . __('Dark', 'invoicing') . "</option>
1121
+                        <option value='btn-link'>"      . __('Link', 'invoicing') . "</option>
1122 1122
                     </select>
1123 1123
                 </div>
1124 1124
             </div>
@@ -1129,8 +1129,8 @@  discard block
 block discarded – undo
1129 1129
     /**
1130 1130
      * Renders the alert element template.
1131 1131
      */
1132
-    public function render_alert_template( $field ) {
1133
-        $restrict = $this->get_restrict_markup( $field, 'alert' );
1132
+    public function render_alert_template($field) {
1133
+        $restrict = $this->get_restrict_markup($field, 'alert');
1134 1134
         $text     = "$field.text";
1135 1135
         echo "
1136 1136
             <div $restrict class='alert' :class='$field.class' role='alert'>
@@ -1145,14 +1145,14 @@  discard block
 block discarded – undo
1145 1145
     /**
1146 1146
      * Renders the alert element template.
1147 1147
      */
1148
-    public function edit_alert_template( $field ) {
1149
-        $restrict = $this->get_restrict_markup( $field, 'alert' );
1150
-        $label    = __( 'Alert Text', 'invoicing' );
1151
-        $label2   = esc_attr__( 'Enter your alert text here', 'invoicing' );
1148
+    public function edit_alert_template($field) {
1149
+        $restrict = $this->get_restrict_markup($field, 'alert');
1150
+        $label    = __('Alert Text', 'invoicing');
1151
+        $label2   = esc_attr__('Enter your alert text here', 'invoicing');
1152 1152
         $id       = $field . '.id + "_edit"';
1153
-        $label3   = __( 'Is Dismissible?', 'invoicing' );
1153
+        $label3   = __('Is Dismissible?', 'invoicing');
1154 1154
         $id2      = $field . '.id + "_edit2"';
1155
-        $label4   = esc_attr__( 'Alert Type', 'invoicing' );
1155
+        $label4   = esc_attr__('Alert Type', 'invoicing');
1156 1156
         $id3      = $field . '.id + "_edit3"';
1157 1157
         echo "
1158 1158
             <div $restrict>
@@ -1168,14 +1168,14 @@  discard block
 block discarded – undo
1168 1168
                     <label :for='$id3'>$label4</label>
1169 1169
 
1170 1170
                     <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1171
-                        <option value='alert-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1172
-                        <option value='alert-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1173
-                        <option value='alert-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1174
-                        <option value='alert-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1175
-                        <option value='alert-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1176
-                        <option value='alert-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1177
-                        <option value='alert-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1178
-                        <option value='alert-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1171
+                        <option value='alert-primary'>" . __('Primary', 'invoicing') . "</option>
1172
+                        <option value='alert-secondary'>" . __('Secondary', 'invoicing') . "</option>
1173
+                        <option value='alert-success'>"   . __('Success', 'invoicing') . "</option>
1174
+                        <option value='alert-danger'>"    . __('Danger', 'invoicing') . "</option>
1175
+                        <option value='alert-warning'>"   . __('Warning', 'invoicing') . "</option>
1176
+                        <option value='alert-info'>"      . __('Info', 'invoicing') . "</option>
1177
+                        <option value='alert-light'>"     . __('Light', 'invoicing') . "</option>
1178
+                        <option value='alert-dark'>"      . __('Dark', 'invoicing') . "</option>
1179 1179
                     </select>
1180 1180
                 </div>
1181 1181
             </div>
@@ -1186,8 +1186,8 @@  discard block
 block discarded – undo
1186 1186
     /**
1187 1187
      * Renders the discount element template.
1188 1188
      */
1189
-    public function render_discount_template( $field ) {
1190
-        $restrict  = $this->get_restrict_markup( $field, 'discount' );
1189
+    public function render_discount_template($field) {
1190
+        $restrict = $this->get_restrict_markup($field, 'discount');
1191 1191
         ?>
1192 1192
 
1193 1193
             <div <?php echo $restrict; ?> class="discount_field border rounded p-3 wpinv-payment-form-field-preview">
@@ -1205,12 +1205,12 @@  discard block
 block discarded – undo
1205 1205
     /**
1206 1206
      * Renders the discount element template.
1207 1207
      */
1208
-    public function edit_discount_template( $field ) {
1209
-        $restrict = $this->get_restrict_markup( $field, 'discount' );
1210
-        $label    = __( 'Discount Input Placeholder', 'invoicing' );
1211
-        $label2   = __( 'Help Text', 'invoicing' );
1212
-        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1213
-        $label4   = __( 'Button Text', 'invoicing' );
1208
+    public function edit_discount_template($field) {
1209
+        $restrict = $this->get_restrict_markup($field, 'discount');
1210
+        $label    = __('Discount Input Placeholder', 'invoicing');
1211
+        $label2   = __('Help Text', 'invoicing');
1212
+        $label3   = esc_attr__('Add some help text for this field', 'invoicing');
1213
+        $label4   = __('Button Text', 'invoicing');
1214 1214
         $id       = $field . '.id + "_edit"';
1215 1215
         $id2      = $field . '.id + "_edit2"';
1216 1216
         $id3      = $field . '.id + "_edit3"';
@@ -1239,17 +1239,17 @@  discard block
 block discarded – undo
1239 1239
     /**
1240 1240
      * Renders the items element template.
1241 1241
      */
1242
-    public function render_items_template( $field ) {
1243
-        $restrict  = $this->get_restrict_markup( $field, 'items' );
1242
+    public function render_items_template($field) {
1243
+        $restrict = $this->get_restrict_markup($field, 'items');
1244 1244
         ?>
1245 1245
 
1246 1246
         <div <?php echo $restrict; ?> class='item_totals'>
1247 1247
             <div v-if='!is_default'>
1248
-                <div v-if='! canCheckoutSeveralSubscriptions(<?php echo $field; ?>)' class='alert alert-info' role='alert'><?php _e( 'Item totals will appear here. Click to set items.', 'invoicing' ) ?></div>
1249
-                <div v-if='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)' class='alert alert-danger' role='alert'><?php _e( 'Your form allows customers to buy several recurring items. This is not supported and might lead to unexpected behaviour.', 'invoicing' ); ?></div>
1248
+                <div v-if='! canCheckoutSeveralSubscriptions(<?php echo $field; ?>)' class='alert alert-info' role='alert'><?php _e('Item totals will appear here. Click to set items.', 'invoicing') ?></div>
1249
+                <div v-if='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)' class='alert alert-danger' role='alert'><?php _e('Your form allows customers to buy several recurring items. This is not supported and might lead to unexpected behaviour.', 'invoicing'); ?></div>
1250 1250
             </div>
1251 1251
             <div v-if='is_default'>
1252
-                <div class='alert alert-info' role='alert'><?php _e( 'Item totals will appear here.', 'invoicing' ) ?></div>
1252
+                <div class='alert alert-info' role='alert'><?php _e('Item totals will appear here.', 'invoicing') ?></div>
1253 1253
             </div>
1254 1254
         </div>
1255 1255
 
@@ -1259,25 +1259,25 @@  discard block
 block discarded – undo
1259 1259
     /**
1260 1260
      * Renders the items element template.
1261 1261
      */
1262
-    public function edit_items_template( $field ) {
1262
+    public function edit_items_template($field) {
1263 1263
         global $wpinv_euvat, $post;
1264 1264
 
1265
-        $restrict = $this->get_restrict_markup( $field, 'items' );
1265
+        $restrict = $this->get_restrict_markup($field, 'items');
1266 1266
         $id2      = $field . '.id + "_edit2"';
1267 1267
         $id3      = $field . '.id + "_edit3"';
1268 1268
 
1269 1269
         // Item types.
1270
-        $item_types = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );
1270
+        $item_types = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post);
1271 1271
 
1272 1272
         ?>
1273 1273
         <div <?php echo $restrict; ?>>
1274 1274
             <div v-if="!is_default">
1275 1275
                 <label class='form-group'>
1276 1276
                     <input v-model='<?php echo $field; ?>.hide_cart' type='checkbox' />
1277
-                    <span class='form-check-label'><?php _e( 'Hide cart details', 'invoicing' ); ?></span>
1277
+                    <span class='form-check-label'><?php _e('Hide cart details', 'invoicing'); ?></span>
1278 1278
                 </label>
1279 1279
 
1280
-                <div class="mb-1"><?php _e( 'Form Items', 'invoicing' ); ?></div>
1280
+                <div class="mb-1"><?php _e('Form Items', 'invoicing'); ?></div>
1281 1281
                 <draggable v-model='form_items' group='selectable_form_items'>
1282 1282
                     <div class='wpinv-available-items-editor' v-for='(item, index) in form_items' :class="'item_' + item.id" :key="item.id">
1283 1283
 
@@ -1295,35 +1295,35 @@  discard block
 block discarded – undo
1295 1295
 
1296 1296
                                 <div class="form-group" v-if="! item.new">
1297 1297
                                     <span class='form-text'>
1298
-                                        <a target="_blank" :href="'<?php echo esc_url( admin_url( '/post.php?action=edit&post' ) ) ?>=' + item.id">
1299
-                                            <?php _e( 'Edit the item name, price and other details', 'invoicing' ); ?>
1298
+                                        <a target="_blank" :href="'<?php echo esc_url(admin_url('/post.php?action=edit&post')) ?>=' + item.id">
1299
+                                            <?php _e('Edit the item name, price and other details', 'invoicing'); ?>
1300 1300
                                         </a>
1301 1301
                                     </span>
1302 1302
                                 </div>
1303 1303
 
1304 1304
                                 <div class='form-group' v-if="item.new">
1305 1305
                                     <label class='mb-0 w-100'>
1306
-                                        <span><?php _e( 'Item Name', 'invoicing' ); ?></span>
1306
+                                        <span><?php _e('Item Name', 'invoicing'); ?></span>
1307 1307
                                         <input v-model='item.title' type='text' class='w-100'/>
1308 1308
                                     </label>
1309 1309
                                 </div>
1310 1310
 
1311 1311
                                 <div class='form-group'  v-if="item.new">
1312 1312
                                     <label class='mb-0 w-100'>
1313
-                                        <span v-if='!item.custom_price'><?php _e( 'Item Price', 'invoicing' ); ?></span>
1314
-                                        <span v-if='item.custom_price'><?php _e( 'Recommended Price', 'invoicing' ); ?></span>
1313
+                                        <span v-if='!item.custom_price'><?php _e('Item Price', 'invoicing'); ?></span>
1314
+                                        <span v-if='item.custom_price'><?php _e('Recommended Price', 'invoicing'); ?></span>
1315 1315
                                         <input v-model='item.price' type='text' class='w-100'/>
1316 1316
                                     </label>
1317 1317
                                 </div>
1318 1318
 
1319 1319
                                 <div class='form-group' v-if='item.new'>
1320 1320
                                     <label :for="'edit_item_type' + item.id" class='mb-0 w-100'>
1321
-                                        <span><?php _e( 'Item Type', 'invoicing' ); ?></span>
1321
+                                        <span><?php _e('Item Type', 'invoicing'); ?></span>
1322 1322
                                         <select class='w-100' v-model='item.type'>
1323 1323
                                             <?php
1324
-                                                foreach ( $item_types as $type => $_label ) {
1325
-                                                    $type  = esc_attr( $type );
1326
-                                                    $_label = esc_html( $_label );
1324
+                                                foreach ($item_types as $type => $_label) {
1325
+                                                    $type = esc_attr($type);
1326
+                                                    $_label = esc_html($_label);
1327 1327
                                                     echo "<option value='$type'>$_label</type>";
1328 1328
                                                 }
1329 1329
                                             ?>
@@ -1332,71 +1332,71 @@  discard block
 block discarded – undo
1332 1332
                                 </div>
1333 1333
 
1334 1334
                                 <div v-if='item.new'>
1335
-                                    <?php if ( $wpinv_euvat->allow_vat_rules() ) : ?>
1335
+                                    <?php if ($wpinv_euvat->allow_vat_rules()) : ?>
1336 1336
                                         <div class='form-group'>
1337
-                                            <label class='w-100 mb-0'><?php _e( 'VAT Rule', 'invoicing' ) ; ?>
1337
+                                            <label class='w-100 mb-0'><?php _e('VAT Rule', 'invoicing'); ?>
1338 1338
                                                 <select class='w-100' v-model='item.rule'>
1339 1339
                                                     <?php
1340
-                                                        foreach ( $wpinv_euvat->get_rules() as $type => $_label ) {
1341
-                                                            $type  = esc_attr( $type );
1342
-                                                            $_label = esc_html( $_label );
1340
+                                                        foreach ($wpinv_euvat->get_rules() as $type => $_label) {
1341
+                                                            $type = esc_attr($type);
1342
+                                                            $_label = esc_html($_label);
1343 1343
                                                             echo "<option value='$type'>$_label</type>";
1344 1344
                                                         }
1345 1345
                                                     ?>
1346 1346
                                                 </select>
1347 1347
                                             </label>
1348 1348
                                         </div>
1349
-                                    <?php endif;?>
1349
+                                    <?php endif; ?>
1350 1350
 
1351
-                                    <?php if ( $wpinv_euvat->allow_vat_classes() ) : ?>
1351
+                                    <?php if ($wpinv_euvat->allow_vat_classes()) : ?>
1352 1352
                                         <div class='form-group'>
1353
-                                            <label class='w-100 mb-0'><?php _e( 'VAT class', 'invoicing' ) ; ?>
1353
+                                            <label class='w-100 mb-0'><?php _e('VAT class', 'invoicing'); ?>
1354 1354
                                                 <select class='w-100' v-model='item.class'>
1355 1355
                                                     <?php
1356
-                                                        foreach ( $wpinv_euvat->get_all_classes() as $type => $_label ) {
1357
-                                                            $type  = esc_attr( $type );
1358
-                                                            $_label = esc_html( $_label );
1356
+                                                        foreach ($wpinv_euvat->get_all_classes() as $type => $_label) {
1357
+                                                            $type = esc_attr($type);
1358
+                                                            $_label = esc_html($_label);
1359 1359
                                                             echo "<option value='$type'>$_label</type>"; 
1360 1360
                                                         }
1361 1361
                                                     ?>
1362 1362
                                                 </select>
1363 1363
                                             </label>
1364 1364
                                         </div>
1365
-                                    <?php endif;?>
1365
+                                    <?php endif; ?>
1366 1366
                                                         
1367 1367
                                 </div>
1368 1368
 
1369 1369
                                 <label v-if='item.new' class='form-group'>
1370 1370
                                     <input v-model='item.custom_price' type='checkbox' />
1371
-                                    <span class='form-check-label'><?php _e( 'Allow users to pay what they want', 'invoicing' ); ?></span>
1371
+                                    <span class='form-check-label'><?php _e('Allow users to pay what they want', 'invoicing'); ?></span>
1372 1372
                                 </label>
1373 1373
 
1374 1374
                                 <div class='form-group' v-if='item.new && item.custom_price'>
1375 1375
                                     <label class='mb-0 w-100'>
1376
-                                        <span><?php _e( 'Minimum Price', 'invoicing' ); ?></span>
1376
+                                        <span><?php _e('Minimum Price', 'invoicing'); ?></span>
1377 1377
                                         <input placeholder='0.00' v-model='item.minimum_price' class='w-100' />
1378
-                                        <small class='form-text text-muted'><?php _e( 'Enter the minimum price that a user can pay', 'invoicing' ); ?></small>
1378
+                                        <small class='form-text text-muted'><?php _e('Enter the minimum price that a user can pay', 'invoicing'); ?></small>
1379 1379
                                     </label>
1380 1380
                                 </div>
1381 1381
 
1382 1382
                                 <label class='form-group'>
1383 1383
                                     <input v-model='item.allow_quantities' type='checkbox' />
1384
-                                    <span><?php _e( 'Allow users to buy several quantities', 'invoicing' ); ?></span>
1384
+                                    <span><?php _e('Allow users to buy several quantities', 'invoicing'); ?></span>
1385 1385
                                 </label>
1386 1386
 
1387 1387
                                 <label class='form-group'>
1388 1388
                                     <input v-model='item.required' type='checkbox' />
1389
-                                    <span><?php _e( 'This item is required', 'invoicing' ); ?></span>
1389
+                                    <span><?php _e('This item is required', 'invoicing'); ?></span>
1390 1390
                                 </label>
1391 1391
 
1392 1392
                                 <div class='form-group'>
1393 1393
                                     <label class="mb-0 w-100">
1394
-                                        <span><?php _e( 'Item Description', 'invoicing' ); ?></span>
1394
+                                        <span><?php _e('Item Description', 'invoicing'); ?></span>
1395 1395
                                         <textarea v-model='item.description' class='w-100'></textarea>
1396 1396
                                     </label>
1397 1397
                                 </div>
1398 1398
 
1399
-                                    <button type='button' class='button button-link button-link-delete' @click.prevent='removeItem(item)'><?php _e( 'Delete Item', 'invoicing' ); ?></button>
1399
+                                    <button type='button' class='button button-link button-link-delete' @click.prevent='removeItem(item)'><?php _e('Delete Item', 'invoicing'); ?></button>
1400 1400
 
1401 1401
                                 </div>
1402 1402
                             </div>
@@ -1404,36 +1404,36 @@  discard block
 block discarded – undo
1404 1404
                         </div>
1405 1405
                 </draggable>
1406 1406
 
1407
-                <small v-if='! form_items.length' class='form-text text-danger'><?php _e( 'You have not set up any items. Please select an item below or create a new item.', 'invoicing' ); ?></small>
1407
+                <small v-if='! form_items.length' class='form-text text-danger'><?php _e('You have not set up any items. Please select an item below or create a new item.', 'invoicing'); ?></small>
1408 1408
 
1409 1409
                 <div class='form-group mt-2'>
1410 1410
 
1411 1411
                     <select class='w-100' style="padding: 6px 24px 6px 8px; border-color: #e0e0e0;" v-model='selected_item' @change='addSelectedItem'>
1412
-                        <option value=''><?php _e( 'Select an item to add...', 'invoicing' ) ?></option>
1412
+                        <option value=''><?php _e('Select an item to add...', 'invoicing') ?></option>
1413 1413
                         <option v-for='(item, index) in all_items' :value='index'>{{item.title}}</option>
1414 1414
                     </select>
1415 1415
 
1416 1416
                 </div>
1417 1417
 
1418 1418
                 <div class='form-group'>
1419
-                    <button @click.prevent='addNewItem' class="button button-link"><?php _e( 'Or create a new item.', 'invoicing' ) ?></button>
1419
+                    <button @click.prevent='addNewItem' class="button button-link"><?php _e('Or create a new item.', 'invoicing') ?></button>
1420 1420
                 </div>
1421 1421
 
1422 1422
                 <div class='form-group mt-5'>
1423
-                    <label :for='<?php echo $id2; ?>'><?php _e( 'Let customers...', 'invoicing' ) ?></label>
1423
+                    <label :for='<?php echo $id2; ?>'><?php _e('Let customers...', 'invoicing') ?></label>
1424 1424
 
1425 1425
                     <select class='w-100' style="padding: 6px 24px 6px 8px; border-color: #e0e0e0;" :id='<?php echo $id2; ?>' v-model='<?php echo $field; ?>.items_type'>
1426
-                        <option value='total' :disabled='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)'><?php _e( 'Buy all items on the list', 'invoicing' ); ?></option>
1427
-                        <option value='radio'><?php _e( 'Select a single item from the list', 'invoicing' ); ?></option>
1428
-                        <option value='checkbox' :disabled='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)'><?php _e( 'Select one or more items on the list', 'invoicing' ) ;?></option>
1429
-                        <option value='select'><?php _e( 'Select a single item from a dropdown', 'invoicing' ); ?></option>
1426
+                        <option value='total' :disabled='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)'><?php _e('Buy all items on the list', 'invoicing'); ?></option>
1427
+                        <option value='radio'><?php _e('Select a single item from the list', 'invoicing'); ?></option>
1428
+                        <option value='checkbox' :disabled='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)'><?php _e('Select one or more items on the list', 'invoicing'); ?></option>
1429
+                        <option value='select'><?php _e('Select a single item from a dropdown', 'invoicing'); ?></option>
1430 1430
                     </select>
1431 1431
 
1432 1432
                 </div>
1433 1433
             </div>
1434 1434
             <div class='form-group'>
1435
-                <label :for='<?php echo $id3; ?>'><?php _e( 'Help Text', 'invoicing' ); ?></label>
1436
-                <textarea placeholder='<?php esc_attr_e( 'Add some help text for this element', 'invoicing' ); ?>' :id='<?php echo $id3; ?>' v-model='<?php echo $field; ?>.description' class='form-control' rows='3'></textarea>
1435
+                <label :for='<?php echo $id3; ?>'><?php _e('Help Text', 'invoicing'); ?></label>
1436
+                <textarea placeholder='<?php esc_attr_e('Add some help text for this element', 'invoicing'); ?>' :id='<?php echo $id3; ?>' v-model='<?php echo $field; ?>.description' class='form-control' rows='3'></textarea>
1437 1437
             </div>
1438 1438
 
1439 1439
         </div>
@@ -1452,7 +1452,7 @@  discard block
 block discarded – undo
1452 1452
             'orderby'        => 'title',
1453 1453
             'order'          => 'ASC',
1454 1454
             'posts_per_page' => -1,
1455
-            'post_status'    => array( 'publish' ),
1455
+            'post_status'    => array('publish'),
1456 1456
             'meta_query'     => array(
1457 1457
                 array(
1458 1458
                     'key'       => '_wpinv_type',
@@ -1462,15 +1462,15 @@  discard block
 block discarded – undo
1462 1462
             )
1463 1463
         );
1464 1464
 
1465
-        $items = get_posts( apply_filters( 'getpaid_payment_form_item_dropdown_query_args', $item_args ) );
1465
+        $items = get_posts(apply_filters('getpaid_payment_form_item_dropdown_query_args', $item_args));
1466 1466
 
1467
-        if ( empty( $items ) ) {
1467
+        if (empty($items)) {
1468 1468
             return array();
1469 1469
         }
1470 1470
 
1471
-        $options    = array();
1472
-        foreach ( $items as $item ) {
1473
-            $item      = new GetPaid_Form_Item( $item );
1471
+        $options = array();
1472
+        foreach ($items as $item) {
1473
+            $item      = new GetPaid_Form_Item($item);
1474 1474
             $options[] = $item->prepare_data_for_use();
1475 1475
         }
1476 1476
         return $options;
@@ -1480,39 +1480,39 @@  discard block
 block discarded – undo
1480 1480
     /**
1481 1481
      * Returns an array of items for the currently being edited form.
1482 1482
      */
1483
-    public function get_form_items( $id = false ) {
1484
-        $form = new GetPaid_Payment_Form( $id );
1483
+    public function get_form_items($id = false) {
1484
+        $form = new GetPaid_Payment_Form($id);
1485 1485
 
1486 1486
         // Is this a default form?
1487
-        if ( $form->is_default() ) {
1487
+        if ($form->is_default()) {
1488 1488
             return array();
1489 1489
         }
1490 1490
 
1491
-        return $form->get_items( 'view', 'arrays' );
1491
+        return $form->get_items('view', 'arrays');
1492 1492
     }
1493 1493
 
1494 1494
     /**
1495 1495
      * Converts form items for use.
1496 1496
      */
1497
-    public function convert_checkout_items( $items, $invoice ) {
1497
+    public function convert_checkout_items($items, $invoice) {
1498 1498
 
1499 1499
         $converted = array();
1500
-        foreach ( $items as $item ) {
1500
+        foreach ($items as $item) {
1501 1501
 
1502 1502
             $item_id = $item['id'];
1503
-            $_item   = new WPInv_Item( $item_id );
1503
+            $_item   = new WPInv_Item($item_id);
1504 1504
 
1505
-            if( ! $_item ) {
1505
+            if (!$_item) {
1506 1506
                 continue;
1507 1507
             }
1508 1508
 
1509 1509
             $converted[] = array(
1510
-                'title'            => esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $_item ),
1510
+                'title'            => esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($_item),
1511 1511
                 'id'               => $item['id'],
1512 1512
                 'price'            => $item['subtotal'],
1513 1513
                 'custom_price'     => $_item->get_is_dynamic_pricing(),
1514 1514
                 'recurring'        => $_item->is_recurring(),
1515
-                'description'      => apply_filters( 'wpinv_checkout_cart_line_item_summary', '', $item, $_item, $invoice ),
1515
+                'description'      => apply_filters('wpinv_checkout_cart_line_item_summary', '', $item, $_item, $invoice),
1516 1516
                 'minimum_price'    => $_item->get_minimum_price(),
1517 1517
                 'allow_quantities' => false,
1518 1518
                 'quantity'         => $item['quantity'],
@@ -1526,27 +1526,27 @@  discard block
 block discarded – undo
1526 1526
     /**
1527 1527
      * Converts an array of id => quantity for use.
1528 1528
      */
1529
-    public function convert_normal_items( $items ) {
1529
+    public function convert_normal_items($items) {
1530 1530
 
1531 1531
         $converted = array();
1532
-        foreach ( $items as $item_id => $quantity ) {
1532
+        foreach ($items as $item_id => $quantity) {
1533 1533
 
1534
-            $item   = new WPInv_Item( $item_id );
1534
+            $item = new WPInv_Item($item_id);
1535 1535
 
1536
-            if( ! $item ) {
1536
+            if (!$item) {
1537 1537
                 continue;
1538 1538
             }
1539 1539
 
1540 1540
             $converted[] = array(
1541
-                'title'            => esc_html( $item->get_name() ) . wpinv_get_item_suffix( $item ),
1541
+                'title'            => esc_html($item->get_name()) . wpinv_get_item_suffix($item),
1542 1542
                 'id'               => $item_id,
1543 1543
                 'price'            => $item->get_price(),
1544 1544
                 'custom_price'     => $item->get_is_dynamic_pricing(),
1545 1545
                 'recurring'        => $item->is_recurring(),
1546 1546
                 'description'      => $item->get_summary(),
1547 1547
                 'minimum_price'    => $item->get_minimum_price(),
1548
-                'allow_quantities' => ! empty( $quantity ),
1549
-                'quantity'         => empty( $quantity ) ? 1 : $quantity,
1548
+                'allow_quantities' => !empty($quantity),
1549
+                'quantity'         => empty($quantity) ? 1 : $quantity,
1550 1550
                 'required'         => true,
1551 1551
             );
1552 1552
 
@@ -1559,19 +1559,19 @@  discard block
 block discarded – undo
1559 1559
     /**
1560 1560
      * Returns an array of elements for the currently being edited form.
1561 1561
      */
1562
-    public function get_form_elements( $id = false ) {
1562
+    public function get_form_elements($id = false) {
1563 1563
 
1564
-        if ( empty( $id ) ) {
1565
-            return wpinv_get_data( 'sample-payment-form' );
1564
+        if (empty($id)) {
1565
+            return wpinv_get_data('sample-payment-form');
1566 1566
         }
1567 1567
         
1568
-        $form_elements = get_post_meta( $id, 'wpinv_form_elements', true );
1568
+        $form_elements = get_post_meta($id, 'wpinv_form_elements', true);
1569 1569
 
1570
-        if ( is_array( $form_elements ) ) {
1570
+        if (is_array($form_elements)) {
1571 1571
             return $form_elements;
1572 1572
         }
1573 1573
 
1574
-        return wpinv_get_data( 'sample-payment-form' );
1574
+        return wpinv_get_data('sample-payment-form');
1575 1575
     }
1576 1576
 
1577 1577
 }
Please login to merge, or discard this patch.
includes/deprecated-functions.php 1 patch
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * @deprecated
@@ -19,48 +19,48 @@  discard block
 block discarded – undo
19 19
  * @deprecated
20 20
  */
21 21
 function wpinv_get_invoice_cart() {
22
-    return wpinv_get_invoice( getpaid_get_current_invoice_id() );
22
+    return wpinv_get_invoice(getpaid_get_current_invoice_id());
23 23
 }
24 24
 
25 25
 /**
26 26
  * @deprecated
27 27
  */
28
-function wpinv_get_invoice_description( $invoice ) {
29
-    $invoice = new WPInv_Invoice( $invoice );
28
+function wpinv_get_invoice_description($invoice) {
29
+    $invoice = new WPInv_Invoice($invoice);
30 30
     return $invoice->get_description();
31 31
 }
32 32
 
33 33
 /**
34 34
  * @deprecated
35 35
  */
36
-function wpinv_get_invoice_currency_code( $invoice ) {
37
-    $invoice = new WPInv_Invoice( $invoice );
36
+function wpinv_get_invoice_currency_code($invoice) {
37
+    $invoice = new WPInv_Invoice($invoice);
38 38
     return $invoice->get_currency();
39 39
 }
40 40
 
41 41
 /**
42 42
  * @deprecated
43 43
  */
44
-function wpinv_get_payment_user_email( $invoice ) {
45
-    $invoice = new WPInv_Invoice( $invoice );
44
+function wpinv_get_payment_user_email($invoice) {
45
+    $invoice = new WPInv_Invoice($invoice);
46 46
     return $invoice->get_email();
47 47
 }
48 48
 
49 49
 /**
50 50
  * @deprecated
51 51
  */
52
-function wpinv_get_user_id( $invoice ) {
53
-    $invoice = new WPInv_Invoice( $invoice );
52
+function wpinv_get_user_id($invoice) {
53
+    $invoice = new WPInv_Invoice($invoice);
54 54
     return $invoice->get_user_id();
55 55
 }
56 56
 
57 57
 /**
58 58
  * @deprecated
59 59
  */
60
-function wpinv_get_invoice_status( $invoice, $return_label = false ) {
61
-    $invoice = new WPInv_Invoice( $invoice );
60
+function wpinv_get_invoice_status($invoice, $return_label = false) {
61
+    $invoice = new WPInv_Invoice($invoice);
62 62
     
63
-    if ( $return_label ) {
63
+    if ($return_label) {
64 64
         return $invoice->get_status_nicename();
65 65
     }
66 66
 
@@ -70,10 +70,10 @@  discard block
 block discarded – undo
70 70
 /**
71 71
  * @deprecated
72 72
  */
73
-function wpinv_get_payment_gateway( $invoice, $return_label = false ) {
74
-    $invoice = new WPInv_Invoice( $invoice );
73
+function wpinv_get_payment_gateway($invoice, $return_label = false) {
74
+    $invoice = new WPInv_Invoice($invoice);
75 75
 
76
-    if ( $return_label ) {
76
+    if ($return_label) {
77 77
         return $invoice->get_gateway_title();
78 78
     }
79 79
 
@@ -83,75 +83,75 @@  discard block
 block discarded – undo
83 83
 /**
84 84
  * @deprecated
85 85
  */
86
-function wpinv_get_payment_gateway_name( $invoice ) {
87
-    return wpinv_get_payment_gateway( $invoice, true );
86
+function wpinv_get_payment_gateway_name($invoice) {
87
+    return wpinv_get_payment_gateway($invoice, true);
88 88
 }
89 89
 
90 90
 /**
91 91
  * @deprecated
92 92
  */
93
-function wpinv_get_payment_transaction_id( $invoice ) {
94
-    $invoice = new WPInv_Invoice( $invoice );
93
+function wpinv_get_payment_transaction_id($invoice) {
94
+    $invoice = new WPInv_Invoice($invoice);
95 95
     return $invoice->get_transaction_id();
96 96
 }
97 97
 
98 98
 /**
99 99
  * @deprecated
100 100
  */
101
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
102
-    $invoice = new WPInv_Invoice( $invoice_id );
103
-    return $invoice->get_meta( $meta_key, $single );
101
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
102
+    $invoice = new WPInv_Invoice($invoice_id);
103
+    return $invoice->get_meta($meta_key, $single);
104 104
 }
105 105
 
106 106
 /**
107 107
  * @deprecated
108 108
  */
109
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '' ) {
110
-    $invoice = new WPInv_Invoice( $invoice_id );
111
-    return $invoice->update_meta_data( $meta_key, $meta_value );
109
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '') {
110
+    $invoice = new WPInv_Invoice($invoice_id);
111
+    return $invoice->update_meta_data($meta_key, $meta_value);
112 112
 }
113 113
 
114 114
 /**
115 115
  * @deprecated
116 116
  */
117
-function wpinv_get_items( $invoice = 0 ) {
118
-    $invoice = new WPInv_Invoice( $invoice );
117
+function wpinv_get_items($invoice = 0) {
118
+    $invoice = new WPInv_Invoice($invoice);
119 119
     return $invoice->get_items();
120 120
 }
121 121
 
122 122
 /**
123 123
  * @deprecated
124 124
  */
125
-function wpinv_get_fees( $invoice = 0 ) {
126
-    $invoice = new WPInv_Invoice( $invoice );
125
+function wpinv_get_fees($invoice = 0) {
126
+    $invoice = new WPInv_Invoice($invoice);
127 127
     return $invoice->get_fees();
128 128
 }
129 129
 
130 130
 /**
131 131
  * @deprecated
132 132
  */
133
-function wpinv_get_invoice_ip( $invoice ) {
134
-    $invoice = new WPInv_Invoice( $invoice );
133
+function wpinv_get_invoice_ip($invoice) {
134
+    $invoice = new WPInv_Invoice($invoice);
135 135
     return $invoice->get_ip();
136 136
 }
137 137
 
138 138
 /**
139 139
  * @deprecated
140 140
  */
141
-function wpinv_get_invoice_user_info( $invoice ) {
142
-    $invoice = new WPInv_Invoice( $invoice );
141
+function wpinv_get_invoice_user_info($invoice) {
142
+    $invoice = new WPInv_Invoice($invoice);
143 143
     return $invoice->get_user_info();
144 144
 }
145 145
 
146 146
 /**
147 147
  * @deprecated
148 148
  */
149
-function wpinv_subtotal( $invoice = 0, $currency = false ) {
150
-    $invoice  = new WPInv_Invoice( $invoice );
149
+function wpinv_subtotal($invoice = 0, $currency = false) {
150
+    $invoice  = new WPInv_Invoice($invoice);
151 151
     $subtotal = $invoice->get_subtotal();
152 152
 
153
-    if ( $currency ) {
154
-        return wpinv_price( wpinv_format_amount( $subtotal ), $invoice->get_currency() );
153
+    if ($currency) {
154
+        return wpinv_price(wpinv_format_amount($subtotal), $invoice->get_currency());
155 155
     }
156 156
 
157 157
     return $subtotal;
@@ -160,12 +160,12 @@  discard block
 block discarded – undo
160 160
 /**
161 161
  * @deprecated
162 162
  */
163
-function wpinv_tax( $invoice = 0, $currency = false ) {
164
-    $invoice  = new WPInv_Invoice( $invoice );
163
+function wpinv_tax($invoice = 0, $currency = false) {
164
+    $invoice  = new WPInv_Invoice($invoice);
165 165
     $tax      = $invoice->get_total_tax();
166 166
 
167
-    if ( $currency ) {
168
-        return wpinv_price( wpinv_format_amount( $tax ), $invoice->get_currency() );
167
+    if ($currency) {
168
+        return wpinv_price(wpinv_format_amount($tax), $invoice->get_currency());
169 169
     }
170 170
 
171 171
     return $tax;
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
 /**
175 175
  * @deprecated
176 176
  */
177
-function wpinv_discount( $invoice = 0, $currency = false, $deprecated ) {
178
-    $invoice  = new WPInv_Invoice( $invoice );
177
+function wpinv_discount($invoice = 0, $currency = false, $deprecated) {
178
+    $invoice  = new WPInv_Invoice($invoice);
179 179
     $discount = $invoice->get_total_discount();
180 180
 
181
-    if ( $currency ) {
182
-        return wpinv_price( wpinv_format_amount( $discount ), $invoice->get_currency() );
181
+    if ($currency) {
182
+        return wpinv_price(wpinv_format_amount($discount), $invoice->get_currency());
183 183
     }
184 184
 
185 185
     return $discount;
@@ -188,20 +188,20 @@  discard block
 block discarded – undo
188 188
 /**
189 189
  * @deprecated
190 190
  */
191
-function wpinv_discount_code( $invoice = 0 ) {
192
-    $invoice = new WPInv_Invoice( $invoice );
191
+function wpinv_discount_code($invoice = 0) {
192
+    $invoice = new WPInv_Invoice($invoice);
193 193
     return $invoice->get_discount_code();
194 194
 }
195 195
 
196 196
 /**
197 197
  * @deprecated
198 198
  */
199
-function wpinv_payment_total( $invoice = 0, $currency = false ) {
200
-    $invoice  = new WPInv_Invoice( $invoice );
199
+function wpinv_payment_total($invoice = 0, $currency = false) {
200
+    $invoice = new WPInv_Invoice($invoice);
201 201
     $total = $invoice->get_total();
202 202
 
203
-    if ( $currency ) {
204
-        return wpinv_price( wpinv_format_amount( $total ), $invoice->get_currency() );
203
+    if ($currency) {
204
+        return wpinv_price(wpinv_format_amount($total), $invoice->get_currency());
205 205
     }
206 206
 
207 207
     return $total;
@@ -210,51 +210,51 @@  discard block
 block discarded – undo
210 210
 /**
211 211
  * @deprecated
212 212
  */
213
-function wpinv_get_date_created( $invoice = 0, $format = '' ) {
214
-    $invoice = new WPInv_Invoice( $invoice );
213
+function wpinv_get_date_created($invoice = 0, $format = '') {
214
+    $invoice = new WPInv_Invoice($invoice);
215 215
 
216
-    $format         = ! empty( $format ) ? $format : get_option( 'date_format' );
216
+    $format         = !empty($format) ? $format : get_option('date_format');
217 217
     $date_created   = $invoice->get_created_date();
218 218
 
219
-    return empty( $date_created ) ? date_i18n( $format, strtotime( $date_created ) ) : '';
219
+    return empty($date_created) ? date_i18n($format, strtotime($date_created)) : '';
220 220
 }
221 221
 
222 222
 /**
223 223
  * @deprecated
224 224
  */
225
-function wpinv_get_invoice_date( $invoice = 0, $format = '' ) {
226
-    wpinv_get_date_created( $invoice, $format );
225
+function wpinv_get_invoice_date($invoice = 0, $format = '') {
226
+    wpinv_get_date_created($invoice, $format);
227 227
 }
228 228
 
229 229
 /**
230 230
  * @deprecated
231 231
  */
232
-function wpinv_get_invoice_vat_number( $invoice = 0 ) {
233
-    $invoice = new WPInv_Invoice( $invoice );
232
+function wpinv_get_invoice_vat_number($invoice = 0) {
233
+    $invoice = new WPInv_Invoice($invoice);
234 234
     return $invoice->get_vat_number();
235 235
 }
236 236
 
237 237
 /**
238 238
  * @deprecated
239 239
  */
240
-function wpinv_insert_payment_note( $invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) {
241
-    $invoice = new WPInv_Invoice( $invoice );
242
-    return $invoice->add_note( $note, $user_type, $added_by_user, $system );
240
+function wpinv_insert_payment_note($invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) {
241
+    $invoice = new WPInv_Invoice($invoice);
242
+    return $invoice->add_note($note, $user_type, $added_by_user, $system);
243 243
 }
244 244
 
245 245
 /**
246 246
  * @deprecated
247 247
  */
248
-function wpinv_get_payment_key( $invoice = 0 ) {
249
-	$invoice = new WPInv_Invoice( $invoice );
248
+function wpinv_get_payment_key($invoice = 0) {
249
+	$invoice = new WPInv_Invoice($invoice);
250 250
     return $invoice->get_key();
251 251
 }
252 252
 
253 253
 /**
254 254
  * @deprecated
255 255
  */
256
-function wpinv_get_invoice_number( $invoice = 0 ) {
257
-    $invoice = new WPInv_Invoice( $invoice );
256
+function wpinv_get_invoice_number($invoice = 0) {
257
+    $invoice = new WPInv_Invoice($invoice);
258 258
     return $invoice->get_number();
259 259
 }
260 260
 
@@ -401,9 +401,9 @@  discard block
 block discarded – undo
401 401
 /**
402 402
  * @deprecated
403 403
  */
404
-function wpinv_update_payment_status( $invoice, $new_status = 'publish' ) {    
405
-    $invoice = new WPInv_Invoice( $invoice );
406
-    return $invoice->update_status( $new_status );
404
+function wpinv_update_payment_status($invoice, $new_status = 'publish') {    
405
+    $invoice = new WPInv_Invoice($invoice);
406
+    return $invoice->update_status($new_status);
407 407
 }
408 408
 
409 409
 /**
@@ -456,22 +456,22 @@  discard block
 block discarded – undo
456 456
 /**
457 457
  * @deprecated
458 458
  */
459
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
459
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
460 460
 
461 461
     // Fetch the invoice.
462
-    $invoice = new WPInv_Invoice( $invoice_id );
462
+    $invoice = new WPInv_Invoice($invoice_id);
463 463
 
464
-    if ( 0 ==  $invoice->get_id() ) {
464
+    if (0 == $invoice->get_id()) {
465 465
         return false;
466 466
     }
467 467
 
468 468
     // Prepare the transaction id.
469
-    if ( empty( $transaction_id ) ) {
469
+    if (empty($transaction_id)) {
470 470
         $transaction_id = $invoice_id;
471 471
     }
472 472
 
473 473
     // Set the transaction id;
474
-    $invoice->set_transaction_id( apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice ) );
474
+    $invoice->set_transaction_id(apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice));
475 475
 
476 476
     // Save the invoice.
477 477
     return $invoice->save();
@@ -484,12 +484,12 @@  discard block
 block discarded – undo
484 484
  * @param WPInv_Invoice $invoice
485 485
  * @param string $gateway
486 486
  */
487
-function wpinv_send_to_gateway( $gateway, $invoice ) {
487
+function wpinv_send_to_gateway($gateway, $invoice) {
488 488
 
489 489
     $payment_data = array(
490 490
         'invoice_id'        => $invoice->get_id(),
491 491
         'items'             => $invoice->get_cart_details(),
492
-        'cart_discounts'    => array( $invoice->get_discount_code() ),
492
+        'cart_discounts'    => array($invoice->get_discount_code()),
493 493
         'fees'              => $invoice->get_total_fees(),
494 494
         'subtotal'          => $invoice->get_subtotal(),
495 495
         'discount'          => $invoice->get_total_discount(),
@@ -497,16 +497,16 @@  discard block
 block discarded – undo
497 497
         'price'             => $invoice->get_total(),
498 498
         'invoice_key'       => $invoice->get_key(),
499 499
         'user_email'        => $invoice->get_email(),
500
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
500
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
501 501
         'user_info'         => $invoice->get_user_info(),
502
-        'post_data'         => stripslashes_deep( $_POST ),
502
+        'post_data'         => stripslashes_deep($_POST),
503 503
         'cart_details'      => $invoice->get_cart_details(),
504 504
         'gateway'           => $gateway,
505 505
         'card_info'         => array(),
506 506
         'gateway_nonce'     => wp_create_nonce('wpi-gateway'),
507 507
     );
508 508
 
509
-    do_action( 'wpinv_gateway_' . $gateway, $payment_data );
509
+    do_action('wpinv_gateway_' . $gateway, $payment_data);
510 510
 }
511 511
 
512 512
 /**
@@ -519,10 +519,10 @@  discard block
 block discarded – undo
519 519
 /**
520 520
  * @deprecated
521 521
  */
522
-function wpinv_die( $message = '', $title = '', $status = 400 ) {
523
-    add_filter( 'wp_die_ajax_handler', 'wpinv_die_handler', 10, 3 );
524
-    add_filter( 'wp_die_handler', 'wpinv_die_handler', 10, 3 );
525
-    wp_die( $message, $title, array( 'response' => $status ));
522
+function wpinv_die($message = '', $title = '', $status = 400) {
523
+    add_filter('wp_die_ajax_handler', 'wpinv_die_handler', 10, 3);
524
+    add_filter('wp_die_handler', 'wpinv_die_handler', 10, 3);
525
+    wp_die($message, $title, array('response' => $status));
526 526
 }
527 527
 
528 528
 /**
@@ -640,14 +640,14 @@  discard block
 block discarded – undo
640 640
 /**
641 641
  * @deprecated
642 642
  */
643
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
644
-    return empty( $status_display ) ? sanitize_text_field( $status ) : sanitize_text_field( $status_display );
643
+function wpinv_invoice_status_label($status, $status_display = '') {
644
+    return empty($status_display) ? sanitize_text_field($status) : sanitize_text_field($status_display);
645 645
 }
646 646
 
647 647
 /**
648 648
  * @deprecated
649 649
  */
650
-function wpinv_clean_invoice_number( $number ) {
650
+function wpinv_clean_invoice_number($number) {
651 651
     return $number;
652 652
 }
653 653
 
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Spacing   +268 added lines, -268 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * WPInv_Ajax class.
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 	 * Hook in ajax handlers.
18 18
 	 */
19 19
 	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
20
+		add_action('init', array(__CLASS__, 'define_ajax'), 0);
21
+		add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
22 22
 		self::add_ajax_events();
23 23
     }
24 24
 
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	 */
28 28
 	public static function define_ajax() {
29 29
 
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+		if (!empty($_GET['wpinv-ajax'])) {
31
+			getpaid_maybe_define_constant('DOING_AJAX', true);
32
+			getpaid_maybe_define_constant('WPInv_DOING_AJAX', true);
33
+			if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
34
+				/** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
35 35
 			}
36 36
 			$GLOBALS['wpdb']->hide_errors();
37 37
 		}
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	 * @since 1.0.18
45 45
 	 */
46 46
 	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
47
+		if (!headers_sent()) {
48 48
 			send_origin_headers();
49 49
 			send_nosniff_header();
50 50
 			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
51
+			header('Content-Type: text/html; charset=' . get_option('blog_charset'));
52
+			header('X-Robots-Tag: noindex');
53
+			status_header(200);
54 54
 		}
55 55
     }
56 56
     
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
 	public static function do_wpinv_ajax() {
61 61
 		global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
63
+		if (!empty($_GET['wpinv-ajax'])) {
64
+			$wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax'])));
65 65
 		}
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+		$action = $wp_query->get('wpinv-ajax');
68 68
 
69
-		if ( $action ) {
69
+		if ($action) {
70 70
 			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
71
+			$action = sanitize_text_field($action);
72
+			do_action('wpinv_ajax_' . $action);
73 73
 			wp_die();
74 74
 		}
75 75
 
@@ -103,36 +103,36 @@  discard block
 block discarded – undo
103 103
             'ip_geolocation'              => true,
104 104
         );
105 105
 
106
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
107
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
108
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
106
+        foreach ($ajax_events as $ajax_event => $nopriv) {
107
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
108
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
109 109
 
110
-            if ( $nopriv ) {
111
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
112
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
113
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
110
+            if ($nopriv) {
111
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
112
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
113
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
114 114
             }
115 115
         }
116 116
     }
117 117
     
118 118
     public static function add_note() {
119
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
119
+        check_ajax_referer('add-invoice-note', '_nonce');
120 120
 
121
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
121
+        if (!wpinv_current_user_can_manage_invoicing()) {
122 122
             die(-1);
123 123
         }
124 124
 
125
-        $post_id   = absint( $_POST['post_id'] );
126
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
127
-        $note_type = sanitize_text_field( $_POST['note_type'] );
125
+        $post_id   = absint($_POST['post_id']);
126
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
127
+        $note_type = sanitize_text_field($_POST['note_type']);
128 128
 
129 129
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
130 130
 
131
-        if ( $post_id > 0 ) {
132
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
131
+        if ($post_id > 0) {
132
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
133 133
 
134
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
135
-                wpinv_get_invoice_note_line_item( $note_id );
134
+            if ($note_id > 0 && !is_wp_error($note_id)) {
135
+                wpinv_get_invoice_note_line_item($note_id);
136 136
             }
137 137
         }
138 138
 
@@ -140,16 +140,16 @@  discard block
 block discarded – undo
140 140
     }
141 141
 
142 142
     public static function delete_note() {
143
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
143
+        check_ajax_referer('delete-invoice-note', '_nonce');
144 144
 
145
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
145
+        if (!wpinv_current_user_can_manage_invoicing()) {
146 146
             die(-1);
147 147
         }
148 148
 
149
-        $note_id = (int)$_POST['note_id'];
149
+        $note_id = (int) $_POST['note_id'];
150 150
 
151
-        if ( $note_id > 0 ) {
152
-            wp_delete_comment( $note_id, true );
151
+        if ($note_id > 0) {
152
+            wp_delete_comment($note_id, true);
153 153
         }
154 154
 
155 155
         die();
@@ -167,34 +167,34 @@  discard block
 block discarded – undo
167 167
     public static function get_billing_details() {
168 168
 
169 169
         // Verify nonce.
170
-        check_ajax_referer( 'wpinv-nonce' );
170
+        check_ajax_referer('wpinv-nonce');
171 171
 
172 172
         // Can the user manage the plugin?
173
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
173
+        if (!wpinv_current_user_can_manage_invoicing()) {
174 174
             die(-1);
175 175
         }
176 176
 
177 177
         // Do we have a user id?
178 178
         $user_id = $_GET['user_id'];
179 179
 
180
-        if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
180
+        if (empty($user_id) || !is_numeric($user_id)) {
181 181
             die(-1);
182 182
         }
183 183
 
184 184
         // Fetch the billing details.
185
-        $billing_details    = wpinv_get_user_address( $user_id );
186
-        $billing_details    = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id );
185
+        $billing_details    = wpinv_get_user_address($user_id);
186
+        $billing_details    = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id);
187 187
 
188 188
         // unset the user id and email.
189
-        $to_ignore = array( 'user_id', 'email' );
189
+        $to_ignore = array('user_id', 'email');
190 190
 
191
-        foreach ( $to_ignore as $key ) {
192
-            if ( isset( $billing_details[ $key ] ) ) {
193
-                unset( $billing_details[ $key ] );
191
+        foreach ($to_ignore as $key) {
192
+            if (isset($billing_details[$key])) {
193
+                unset($billing_details[$key]);
194 194
             }
195 195
         }
196 196
 
197
-        wp_send_json_success( $billing_details );
197
+        wp_send_json_success($billing_details);
198 198
 
199 199
     }
200 200
 
@@ -204,47 +204,47 @@  discard block
 block discarded – undo
204 204
     public static function check_new_user_email() {
205 205
 
206 206
         // Verify nonce.
207
-        check_ajax_referer( 'wpinv-nonce' );
207
+        check_ajax_referer('wpinv-nonce');
208 208
 
209 209
         // Can the user manage the plugin?
210
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
210
+        if (!wpinv_current_user_can_manage_invoicing()) {
211 211
             die(-1);
212 212
         }
213 213
 
214 214
         // We need an email address.
215
-        if ( empty( $_GET['email'] ) ) {
216
-            _e( "Provide the new user's email address", 'invoicing' );
215
+        if (empty($_GET['email'])) {
216
+            _e("Provide the new user's email address", 'invoicing');
217 217
             exit;
218 218
         }
219 219
 
220 220
         // Ensure the email is valid.
221
-        $email = sanitize_text_field( $_GET['email'] );
222
-        if ( ! is_email( $email ) ) {
223
-            _e( 'Invalid email address', 'invoicing' );
221
+        $email = sanitize_text_field($_GET['email']);
222
+        if (!is_email($email)) {
223
+            _e('Invalid email address', 'invoicing');
224 224
             exit;
225 225
         }
226 226
 
227 227
         // And it does not exist.
228
-        if ( email_exists( $email ) ) {
229
-            _e( 'A user with this email address already exists', 'invoicing' );
228
+        if (email_exists($email)) {
229
+            _e('A user with this email address already exists', 'invoicing');
230 230
             exit;
231 231
         }
232 232
 
233
-        wp_send_json_success( true );
233
+        wp_send_json_success(true);
234 234
     }
235 235
     
236 236
     public static function run_tool() {
237
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
238
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
237
+        check_ajax_referer('wpinv-nonce', '_nonce');
238
+        if (!wpinv_current_user_can_manage_invoicing()) {
239 239
             die(-1);
240 240
         }
241 241
         
242
-        $tool = sanitize_text_field( $_POST['tool'] );
242
+        $tool = sanitize_text_field($_POST['tool']);
243 243
         
244
-        do_action( 'wpinv_run_tool' );
244
+        do_action('wpinv_run_tool');
245 245
         
246
-        if ( !empty( $tool ) ) {
247
-            do_action( 'wpinv_tool_' . $tool );
246
+        if (!empty($tool)) {
247
+            do_action('wpinv_tool_' . $tool);
248 248
         }
249 249
     }
250 250
 
@@ -254,30 +254,30 @@  discard block
 block discarded – undo
254 254
     public static function get_payment_form() {
255 255
 
256 256
         // Check nonce.
257
-        if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'getpaid_ajax_form' ) ) {
258
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
257
+        if (!isset($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], 'getpaid_ajax_form')) {
258
+            _e('Error: Reload the page and try again.', 'invoicing');
259 259
             exit;
260 260
         }
261 261
 
262 262
         // Is the request set up correctly?
263
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
263
+		if (empty($_GET['form']) && empty($_GET['item'])) {
264 264
 			echo aui()->alert(
265 265
 				array(
266 266
 					'type'    => 'warning',
267
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
267
+					'content' => __('No payment form or item provided', 'invoicing'),
268 268
 				)
269 269
             );
270 270
             exit;
271 271
         }
272 272
 
273 273
         // Payment form or button?
274
-		if ( ! empty( $_GET['form'] ) ) {
275
-            getpaid_display_payment_form( $_GET['form'] );
276
-		} else if( ! empty( $_GET['invoice'] ) ) {
277
-		    echo getpaid_display_invoice_payment_form( $_GET['invoice'] );
274
+		if (!empty($_GET['form'])) {
275
+            getpaid_display_payment_form($_GET['form']);
276
+		} else if (!empty($_GET['invoice'])) {
277
+		    echo getpaid_display_invoice_payment_form($_GET['invoice']);
278 278
         } else {
279
-			$items = getpaid_convert_items_to_array( $_GET['item'] );
280
-		    getpaid_display_item_payment_form( $items );
279
+			$items = getpaid_convert_items_to_array($_GET['item']);
280
+		    getpaid_display_item_payment_form($items);
281 281
         }
282 282
 
283 283
         exit;
@@ -292,17 +292,17 @@  discard block
 block discarded – undo
292 292
     public static function payment_form() {
293 293
 
294 294
         // Check nonce.
295
-        check_ajax_referer( 'getpaid_form_nonce' );
295
+        check_ajax_referer('getpaid_form_nonce');
296 296
 
297 297
         // ... form fields...
298
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
299
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
298
+        if (empty($_POST['getpaid_payment_form_submission'])) {
299
+            _e('Error: Reload the page and try again.', 'invoicing');
300 300
             exit;
301 301
         }
302 302
 
303 303
         // Process the payment form.
304
-        $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' );
305
-        $checkout       = new $checkout_class( new GetPaid_Payment_Form_Submission() );
304
+        $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout');
305
+        $checkout       = new $checkout_class(new GetPaid_Payment_Form_Submission());
306 306
         $checkout->process_checkout();
307 307
 
308 308
         exit;
@@ -316,51 +316,51 @@  discard block
 block discarded – undo
316 316
     public static function get_payment_form_states_field() {
317 317
         global $invoicing;
318 318
 
319
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
319
+        if (empty($_GET['country']) || empty($_GET['form'])) {
320 320
             exit;
321 321
         }
322 322
 
323
-        $elements = $invoicing->form_elements->get_form_elements( $_GET['form'] );
323
+        $elements = $invoicing->form_elements->get_form_elements($_GET['form']);
324 324
 
325
-        if ( empty( $elements ) ) {
325
+        if (empty($elements)) {
326 326
             exit;
327 327
         }
328 328
 
329 329
         $address_fields = array();
330
-        foreach ( $elements as $element ) {
331
-            if ( 'address' === $element['type'] ) {
330
+        foreach ($elements as $element) {
331
+            if ('address' === $element['type']) {
332 332
                 $address_fields = $element;
333 333
                 break;
334 334
             }
335 335
         }
336 336
 
337
-        if ( empty( $address_fields ) ) {
337
+        if (empty($address_fields)) {
338 338
             exit;
339 339
         }
340 340
 
341
-        foreach( $address_fields['fields'] as $address_field ) {
341
+        foreach ($address_fields['fields'] as $address_field) {
342 342
 
343
-            if ( 'wpinv_state' == $address_field['name'] ) {
343
+            if ('wpinv_state' == $address_field['name']) {
344 344
 
345 345
                 $label = $address_field['label'];
346 346
 
347
-                if ( ! empty( $address_field['required'] ) ) {
347
+                if (!empty($address_field['required'])) {
348 348
                     $label .= "<span class='text-danger'> *</span>";
349 349
                 }
350 350
 
351
-                $states = wpinv_get_country_states( $_GET['country'] );
351
+                $states = wpinv_get_country_states($_GET['country']);
352 352
 
353
-                if ( ! empty( $states ) ) {
353
+                if (!empty($states)) {
354 354
 
355 355
                     $html = aui()->select(
356 356
                             array(
357 357
                                 'options'          => $states,
358
-                                'name'             => esc_attr( $address_field['name'] ),
359
-                                'id'               => esc_attr( $address_field['name'] ),
360
-                                'placeholder'      => esc_attr( $address_field['placeholder'] ),
358
+                                'name'             => esc_attr($address_field['name']),
359
+                                'id'               => esc_attr($address_field['name']),
360
+                                'placeholder'      => esc_attr($address_field['placeholder']),
361 361
                                 'required'         => (bool) $address_field['required'],
362 362
                                 'no_wrap'          => true,
363
-                                'label'            => wp_kses_post( $label ),
363
+                                'label'            => wp_kses_post($label),
364 364
                                 'select2'          => false,
365 365
                             )
366 366
                         );
@@ -369,10 +369,10 @@  discard block
 block discarded – undo
369 369
 
370 370
                     $html = aui()->input(
371 371
                             array(
372
-                                'name'       => esc_attr( $address_field['name'] ),
373
-                                'id'         => esc_attr( $address_field['name'] ),
372
+                                'name'       => esc_attr($address_field['name']),
373
+                                'id'         => esc_attr($address_field['name']),
374 374
                                 'required'   => (bool) $address_field['required'],
375
-                                'label'      => wp_kses_post( $label ),
375
+                                'label'      => wp_kses_post($label),
376 376
                                 'no_wrap'    => true,
377 377
                                 'type'       => 'text',
378 378
                             )
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 
381 381
                 }
382 382
 
383
-                wp_send_json_success( str_replace( 'sr-only', '', $html ) );
383
+                wp_send_json_success(str_replace('sr-only', '', $html));
384 384
                 exit;
385 385
 
386 386
             }
@@ -396,56 +396,56 @@  discard block
 block discarded – undo
396 396
     public static function recalculate_invoice_totals() {
397 397
 
398 398
         // Verify nonce.
399
-        check_ajax_referer( 'wpinv-nonce' );
399
+        check_ajax_referer('wpinv-nonce');
400 400
 
401
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
401
+        if (!wpinv_current_user_can_manage_invoicing()) {
402 402
             exit;
403 403
         }
404 404
 
405 405
         // We need an invoice.
406
-        if ( empty( $_POST['post_id'] ) ) {
406
+        if (empty($_POST['post_id'])) {
407 407
             exit;
408 408
         }
409 409
 
410 410
         // Fetch the invoice.
411
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
411
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
412 412
 
413 413
         // Ensure it exists.
414
-        if ( ! $invoice->get_id() ) {
414
+        if (!$invoice->get_id()) {
415 415
             exit;
416 416
         }
417 417
 
418 418
         // Maybe set the country, state, currency.
419
-        foreach ( array( 'country', 'state', 'currency' ) as $key ) {
420
-            if ( isset( $_POST[ $key ] ) ) {
419
+        foreach (array('country', 'state', 'currency') as $key) {
420
+            if (isset($_POST[$key])) {
421 421
                 $method = "set_$key";
422
-                $invoice->$method( $_POST[ $key ] );
422
+                $invoice->$method($_POST[$key]);
423 423
             }
424 424
         }
425 425
 
426 426
         // Maybe disable taxes.
427
-        $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) );
427
+        $invoice->set_disable_taxes(!empty($_POST['taxes']));
428 428
 
429 429
         // Recalculate totals.
430 430
         $invoice->recalculate_total();
431 431
 
432
-        $total = wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() );
432
+        $total = wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency());
433 433
 
434
-        if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) {
435
-            $recurring_total = wpinv_price( wpinv_format_amount( $invoice->get_recurring_total() ), $invoice->get_currency() );
436
-            $total          .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>';
434
+        if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) {
435
+            $recurring_total = wpinv_price(wpinv_format_amount($invoice->get_recurring_total()), $invoice->get_currency());
436
+            $total          .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>';
437 437
         }
438 438
 
439 439
         $totals = array(
440
-            'subtotal' => wpinv_price( wpinv_format_amount( $invoice->get_subtotal() ), $invoice->get_currency() ),
441
-            'discount' => wpinv_price( wpinv_format_amount( $invoice->get_total_discount() ), $invoice->get_currency() ),
442
-            'tax'      => wpinv_price( wpinv_format_amount( $invoice->get_total_tax() ), $invoice->get_currency() ),
440
+            'subtotal' => wpinv_price(wpinv_format_amount($invoice->get_subtotal()), $invoice->get_currency()),
441
+            'discount' => wpinv_price(wpinv_format_amount($invoice->get_total_discount()), $invoice->get_currency()),
442
+            'tax'      => wpinv_price(wpinv_format_amount($invoice->get_total_tax()), $invoice->get_currency()),
443 443
             'total'    => $total,
444 444
         );
445 445
 
446
-        $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice );
446
+        $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice);
447 447
 
448
-        wp_send_json_success( compact( 'totals' ) );
448
+        wp_send_json_success(compact('totals'));
449 449
     }
450 450
 
451 451
     /**
@@ -454,33 +454,33 @@  discard block
 block discarded – undo
454 454
     public static function get_invoice_items() {
455 455
 
456 456
         // Verify nonce.
457
-        check_ajax_referer( 'wpinv-nonce' );
457
+        check_ajax_referer('wpinv-nonce');
458 458
 
459
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
459
+        if (!wpinv_current_user_can_manage_invoicing()) {
460 460
             exit;
461 461
         }
462 462
 
463 463
         // We need an invoice and items.
464
-        if ( empty( $_POST['post_id'] ) ) {
464
+        if (empty($_POST['post_id'])) {
465 465
             exit;
466 466
         }
467 467
 
468 468
         // Fetch the invoice.
469
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
469
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
470 470
 
471 471
         // Ensure it exists.
472
-        if ( ! $invoice->get_id() ) {
472
+        if (!$invoice->get_id()) {
473 473
             exit;
474 474
         }
475 475
 
476 476
         // Return an array of invoice items.
477 477
         $items = array();
478 478
 
479
-        foreach ( $invoice->get_items() as $item_id => $item ) {
480
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
479
+        foreach ($invoice->get_items() as $item_id => $item) {
480
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
481 481
         }
482 482
 
483
-        wp_send_json_success( compact( 'items' ) );
483
+        wp_send_json_success(compact('items'));
484 484
     }
485 485
 
486 486
     /**
@@ -489,50 +489,50 @@  discard block
 block discarded – undo
489 489
     public static function edit_invoice_item() {
490 490
 
491 491
         // Verify nonce.
492
-        check_ajax_referer( 'wpinv-nonce' );
492
+        check_ajax_referer('wpinv-nonce');
493 493
 
494
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
494
+        if (!wpinv_current_user_can_manage_invoicing()) {
495 495
             exit;
496 496
         }
497 497
 
498 498
         // We need an invoice and item details.
499
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
499
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
500 500
             exit;
501 501
         }
502 502
 
503 503
         // Fetch the invoice.
504
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
504
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
505 505
 
506 506
         // Ensure it exists and its not been paid for.
507
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
507
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
508 508
             exit;
509 509
         }
510 510
 
511 511
         // Format the data.
512
-        $data = wp_list_pluck( $_POST['data'], 'value', 'field' );
512
+        $data = wp_list_pluck($_POST['data'], 'value', 'field');
513 513
 
514 514
         // Ensure that we have an item id.
515
-        if ( empty( $data['id'] ) ) {
515
+        if (empty($data['id'])) {
516 516
             exit;
517 517
         }
518 518
 
519 519
         // Abort if the invoice does not have the specified item.
520
-        $item = $invoice->get_item( (int) $data['id'] );
520
+        $item = $invoice->get_item((int) $data['id']);
521 521
 
522
-        if ( empty( $item ) ) {
522
+        if (empty($item)) {
523 523
             exit;
524 524
         }
525 525
 
526 526
         // Update the item.
527
-        $item->set_price( $data['price'] );
528
-        $item->set_name( $data['name'] );
529
-        $item->set_description( $data['description'] );
530
-        $item->set_quantity( $data['quantity'] );
527
+        $item->set_price($data['price']);
528
+        $item->set_name($data['name']);
529
+        $item->set_description($data['description']);
530
+        $item->set_quantity($data['quantity']);
531 531
 
532 532
         // Add it to the invoice.
533
-        $error = $invoice->add_item( $item );
533
+        $error = $invoice->add_item($item);
534 534
         $alert = false;
535
-        if ( is_wp_error( $error ) ) {
535
+        if (is_wp_error($error)) {
536 536
             $alert = $error->get_error_message();
537 537
         }
538 538
 
@@ -545,11 +545,11 @@  discard block
 block discarded – undo
545 545
         // Return an array of invoice items.
546 546
         $items = array();
547 547
 
548
-        foreach ( $invoice->get_items() as $item_id => $item ) {
549
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
548
+        foreach ($invoice->get_items() as $item_id => $item) {
549
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
550 550
         }
551 551
 
552
-        wp_send_json_success( compact( 'items', 'alert' ) );
552
+        wp_send_json_success(compact('items', 'alert'));
553 553
     }
554 554
 
555 555
     /**
@@ -558,33 +558,33 @@  discard block
 block discarded – undo
558 558
     public static function remove_invoice_item() {
559 559
 
560 560
         // Verify nonce.
561
-        check_ajax_referer( 'wpinv-nonce' );
561
+        check_ajax_referer('wpinv-nonce');
562 562
 
563
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
563
+        if (!wpinv_current_user_can_manage_invoicing()) {
564 564
             exit;
565 565
         }
566 566
 
567 567
         // We need an invoice and an item.
568
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
568
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
569 569
             exit;
570 570
         }
571 571
 
572 572
         // Fetch the invoice.
573
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
573
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
574 574
 
575 575
         // Ensure it exists and its not been paid for.
576
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
576
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
577 577
             exit;
578 578
         }
579 579
 
580 580
         // Abort if the invoice does not have the specified item.
581
-        $item = $invoice->get_item( (int) $_POST['item_id'] );
581
+        $item = $invoice->get_item((int) $_POST['item_id']);
582 582
 
583
-        if ( empty( $item ) ) {
583
+        if (empty($item)) {
584 584
             exit;
585 585
         }
586 586
 
587
-        $invoice->remove_item( (int) $_POST['item_id'] );
587
+        $invoice->remove_item((int) $_POST['item_id']);
588 588
 
589 589
         // Update totals.
590 590
         $invoice->recalculate_total();
@@ -595,11 +595,11 @@  discard block
 block discarded – undo
595 595
         // Return an array of invoice items.
596 596
         $items = array();
597 597
 
598
-        foreach ( $invoice->get_items() as $item_id => $item ) {
599
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
598
+        foreach ($invoice->get_items() as $item_id => $item) {
599
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
600 600
         }
601 601
 
602
-        wp_send_json_success( compact( 'items' ) );
602
+        wp_send_json_success(compact('items'));
603 603
     }
604 604
 
605 605
     /**
@@ -608,39 +608,39 @@  discard block
 block discarded – undo
608 608
     public static function add_invoice_items() {
609 609
 
610 610
         // Verify nonce.
611
-        check_ajax_referer( 'wpinv-nonce' );
611
+        check_ajax_referer('wpinv-nonce');
612 612
 
613
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
613
+        if (!wpinv_current_user_can_manage_invoicing()) {
614 614
             exit;
615 615
         }
616 616
 
617 617
         // We need an invoice and items.
618
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) {
618
+        if (empty($_POST['post_id']) || empty($_POST['items'])) {
619 619
             exit;
620 620
         }
621 621
 
622 622
         // Fetch the invoice.
623
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
623
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
624 624
         $alert   = false;
625 625
 
626 626
         // Ensure it exists and its not been paid for.
627
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
627
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
628 628
             exit;
629 629
         }
630 630
 
631 631
         // Add the items.
632
-        foreach ( $_POST['items'] as $data ) {
632
+        foreach ($_POST['items'] as $data) {
633 633
 
634
-            $item = new GetPaid_Form_Item( $data[ 'id' ] );
634
+            $item = new GetPaid_Form_Item($data['id']);
635 635
 
636
-            if ( is_numeric( $data[ 'qty' ] ) && (int) $data[ 'qty' ] > 0 ) {
637
-                $item->set_quantity( $data[ 'qty' ] );
636
+            if (is_numeric($data['qty']) && (int) $data['qty'] > 0) {
637
+                $item->set_quantity($data['qty']);
638 638
             }
639 639
 
640
-            if ( $item->get_id() > 0 ) {
641
-                $error = $invoice->add_item( $item );
640
+            if ($item->get_id() > 0) {
641
+                $error = $invoice->add_item($item);
642 642
 
643
-                if ( is_wp_error( $error ) ) {
643
+                if (is_wp_error($error)) {
644 644
                     $alert = $error->get_error_message();
645 645
                 }
646 646
 
@@ -655,11 +655,11 @@  discard block
 block discarded – undo
655 655
         // Return an array of invoice items.
656 656
         $items = array();
657 657
 
658
-        foreach ( $invoice->get_items() as $item_id => $item ) {
659
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
658
+        foreach ($invoice->get_items() as $item_id => $item) {
659
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
660 660
         }
661 661
 
662
-        wp_send_json_success( compact( 'items', 'alert' ) );
662
+        wp_send_json_success(compact('items', 'alert'));
663 663
     }
664 664
 
665 665
     /**
@@ -668,15 +668,15 @@  discard block
 block discarded – undo
668 668
     public static function get_invoicing_items() {
669 669
 
670 670
         // Verify nonce.
671
-        check_ajax_referer( 'wpinv-nonce' );
671
+        check_ajax_referer('wpinv-nonce');
672 672
 
673
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
673
+        if (!wpinv_current_user_can_manage_invoicing()) {
674 674
             exit;
675 675
         }
676 676
 
677 677
         // We need a search term.
678
-        if ( empty( $_GET['search'] ) ) {
679
-            wp_send_json_success( array() );
678
+        if (empty($_GET['search'])) {
679
+            wp_send_json_success(array());
680 680
         }
681 681
 
682 682
         // Retrieve items.
@@ -685,8 +685,8 @@  discard block
 block discarded – undo
685 685
             'orderby'        => 'title',
686 686
             'order'          => 'ASC',
687 687
             'posts_per_page' => -1,
688
-            'post_status'    => array( 'publish' ),
689
-            's'              => trim( $_GET['search'] ),
688
+            'post_status'    => array('publish'),
689
+            's'              => trim($_GET['search']),
690 690
             'meta_query'     => array(
691 691
                 array(
692 692
                     'key'       => '_wpinv_type',
@@ -696,18 +696,18 @@  discard block
 block discarded – undo
696 696
             )
697 697
         );
698 698
 
699
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
699
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
700 700
         $data  = array();
701 701
 
702
-        foreach ( $items as $item ) {
703
-            $item      = new GetPaid_Form_Item( $item );
702
+        foreach ($items as $item) {
703
+            $item = new GetPaid_Form_Item($item);
704 704
             $data[] = array(
705 705
                 'id'   => $item->get_id(),
706 706
                 'text' => $item->get_name()
707 707
             );
708 708
         }
709 709
 
710
-        wp_send_json_success( $data );
710
+        wp_send_json_success($data);
711 711
 
712 712
     }
713 713
 
@@ -717,24 +717,24 @@  discard block
 block discarded – undo
717 717
     public static function get_aui_states_field() {
718 718
 
719 719
         // Verify nonce.
720
-        check_ajax_referer( 'wpinv-nonce' );
720
+        check_ajax_referer('wpinv-nonce');
721 721
 
722 722
         // We need a country.
723
-        if ( empty( $_GET['country'] ) ) {
723
+        if (empty($_GET['country'])) {
724 724
             exit;
725 725
         }
726 726
 
727
-        $states = wpinv_get_country_states( trim( $_GET['country'] ) );
728
-        $state  = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state();
727
+        $states = wpinv_get_country_states(trim($_GET['country']));
728
+        $state  = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state();
729 729
 
730
-        if ( empty( $states ) ) {
730
+        if (empty($states)) {
731 731
 
732 732
             $html = aui()->input(
733 733
                 array(
734 734
                     'type'        => 'text',
735 735
                     'id'          => 'wpinv_state',
736 736
                     'name'        => 'wpinv_state',
737
-                    'label'       => __( 'State', 'invoicing' ),
737
+                    'label'       => __('State', 'invoicing'),
738 738
                     'label_type'  => 'vertical',
739 739
                     'placeholder' => 'Liège',
740 740
                     'class'       => 'form-control-sm',
@@ -748,9 +748,9 @@  discard block
 block discarded – undo
748 748
                 array(
749 749
                     'id'          => 'wpinv_state',
750 750
                     'name'        => 'wpinv_state',
751
-                    'label'       => __( 'State', 'invoicing' ),
751
+                    'label'       => __('State', 'invoicing'),
752 752
                     'label_type'  => 'vertical',
753
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
753
+                    'placeholder' => __('Select a state', 'invoicing'),
754 754
                     'class'       => 'form-control-sm',
755 755
                     'value'       => $state,
756 756
                     'options'     => $states,
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
         wp_send_json_success(
765 765
             array(
766 766
                 'html'   => $html,
767
-                'select' => ! empty ( $states )
767
+                'select' => !empty ($states)
768 768
             )
769 769
         );
770 770
 
@@ -778,46 +778,46 @@  discard block
 block discarded – undo
778 778
     public static function ip_geolocation() {
779 779
 
780 780
         // Check nonce.
781
-        check_ajax_referer( 'getpaid-ip-location' );
781
+        check_ajax_referer('getpaid-ip-location');
782 782
 
783 783
         // IP address.
784
-        if ( empty( $_GET['ip'] ) || ! rest_is_ip_address( $_GET['ip'] ) ) {
785
-            _e( 'Invalid IP Address.', 'invoicing' );
784
+        if (empty($_GET['ip']) || !rest_is_ip_address($_GET['ip'])) {
785
+            _e('Invalid IP Address.', 'invoicing');
786 786
             exit;
787 787
         }
788 788
 
789 789
         // Retrieve location info.
790
-        $location = getpaid_geolocate_ip_address( $_GET['ip'] );
790
+        $location = getpaid_geolocate_ip_address($_GET['ip']);
791 791
 
792
-        if ( empty( $location ) ) {
793
-            _e( 'Unable to find geolocation for the IP Address.', 'invoicing' );
792
+        if (empty($location)) {
793
+            _e('Unable to find geolocation for the IP Address.', 'invoicing');
794 794
             exit;
795 795
         }
796 796
 
797 797
         // Sorry.
798
-        extract( $location );
798
+        extract($location);
799 799
 
800 800
         // Prepare the address.
801 801
         $content = '';
802 802
 
803
-        if ( ! empty( $location['city'] ) ) {
804
-            $content .=  $location['city']  . ', ';
803
+        if (!empty($location['city'])) {
804
+            $content .= $location['city'] . ', ';
805 805
         }
806 806
         
807
-        if ( ! empty( $location['region'] ) ) {
808
-            $content .=  $location['region']  . ', ';
807
+        if (!empty($location['region'])) {
808
+            $content .= $location['region'] . ', ';
809 809
         }
810 810
         
811
-        $content .=  $location['country'] . ' (' . $location['iso'] . ')';
811
+        $content .= $location['country'] . ' (' . $location['iso'] . ')';
812 812
 
813 813
         $location['address'] = $content;
814 814
 
815
-        $content  = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $content ) . '</p>';
816
-        $content .= '<p>'. $location['credit'] . '</p>';
815
+        $content  = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $content) . '</p>';
816
+        $content .= '<p>' . $location['credit'] . '</p>';
817 817
 
818 818
         $location['content'] = $content;
819 819
 
820
-        wpinv_get_template( 'geolocation.php', $location );
820
+        wpinv_get_template('geolocation.php', $location);
821 821
 
822 822
         exit;
823 823
     }
@@ -830,11 +830,11 @@  discard block
 block discarded – undo
830 830
     public static function payment_form_refresh_prices() {
831 831
 
832 832
         // Check nonce.
833
-        check_ajax_referer( 'getpaid_form_nonce' );
833
+        check_ajax_referer('getpaid_form_nonce');
834 834
 
835 835
         // ... form fields...
836
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
837
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
836
+        if (empty($_POST['getpaid_payment_form_submission'])) {
837
+            _e('Error: Reload the page and try again.', 'invoicing');
838 838
             exit;
839 839
         }
840 840
 
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
         $submission = new GetPaid_Payment_Form_Submission();
843 843
 
844 844
         // Do we have an error?
845
-        if ( ! empty( $submission->last_error ) ) {
845
+        if (!empty($submission->last_error)) {
846 846
             echo $submission->last_error;
847 847
             exit;
848 848
         }
@@ -855,43 +855,43 @@  discard block
 block discarded – undo
855 855
             'is_free'       => $submission->get_payment_details(),
856 856
 
857 857
             'totals'        => array(
858
-                'subtotal'  => wpinv_price( wpinv_format_amount( $submission->subtotal_amount ), $submission->get_currency() ),
859
-                'discount'  => wpinv_price( wpinv_format_amount( $submission->get_total_discount() ), $submission->get_currency() ),
860
-                'fees'      => wpinv_price( wpinv_format_amount( $submission->get_total_fees() ), $submission->get_currency() ),
861
-                'tax'       => wpinv_price( wpinv_format_amount( $submission->get_total_tax() ), $submission->get_currency() ),
862
-                'total'     => wpinv_price( wpinv_format_amount( $submission->get_total() ), $submission->get_currency() ),
858
+                'subtotal'  => wpinv_price(wpinv_format_amount($submission->subtotal_amount), $submission->get_currency()),
859
+                'discount'  => wpinv_price(wpinv_format_amount($submission->get_total_discount()), $submission->get_currency()),
860
+                'fees'      => wpinv_price(wpinv_format_amount($submission->get_total_fees()), $submission->get_currency()),
861
+                'tax'       => wpinv_price(wpinv_format_amount($submission->get_total_tax()), $submission->get_currency()),
862
+                'total'     => wpinv_price(wpinv_format_amount($submission->get_total()), $submission->get_currency()),
863 863
             ),
864 864
 
865 865
             'texts'         => array(
866
-                '.getpaid-checkout-total-payable' => wpinv_price( wpinv_format_amount( $submission->get_total() ), $submission->get_currency() ),
866
+                '.getpaid-checkout-total-payable' => wpinv_price(wpinv_format_amount($submission->get_total()), $submission->get_currency()),
867 867
             )
868 868
 
869 869
         );
870 870
 
871 871
         // Add items.
872 872
         $items = $submission->get_items();
873
-        if ( ! empty( $items ) ) {
873
+        if (!empty($items)) {
874 874
             $result['items'] = array();
875 875
 
876
-            foreach( $items as $item_id => $item ) {
877
-                $result['items']["$item_id"] = wpinv_price( wpinv_format_amount( $item->get_price() * $item->get_quantity() ) );
876
+            foreach ($items as $item_id => $item) {
877
+                $result['items']["$item_id"] = wpinv_price(wpinv_format_amount($item->get_price() * $item->get_quantity()));
878 878
             }
879 879
         }
880 880
 
881 881
         // Add invoice.
882
-        if ( $submission->has_invoice() ) {
882
+        if ($submission->has_invoice()) {
883 883
             $result['invoice'] = $submission->get_invoice()->ID;
884 884
         }
885 885
 
886 886
         // Add discount code.
887
-        if ( $submission->has_discount_code() ) {
887
+        if ($submission->has_discount_code()) {
888 888
             $result['discount_code'] = $submission->get_discount_code();
889 889
         }
890 890
 
891 891
         // Filter the result.
892
-        $result = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $result, $submission );
892
+        $result = apply_filters('getpaid_payment_form_ajax_refresh_prices', $result, $submission);
893 893
 
894
-        wp_send_json_success( $result );
894
+        wp_send_json_success($result);
895 895
     }
896 896
 
897 897
     /**
@@ -902,53 +902,53 @@  discard block
 block discarded – undo
902 902
     public static function buy_items() {
903 903
         $user_id = get_current_user_id();
904 904
 
905
-        if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page
906
-            wp_send_json( array(
907
-                'success' => wp_login_url( wp_get_referer() )
908
-            ) );
905
+        if (empty($user_id)) { // If not logged in then lets redirect to the login page
906
+            wp_send_json(array(
907
+                'success' => wp_login_url(wp_get_referer())
908
+            ));
909 909
         } else {
910 910
             // Only check nonce if logged in as it could be cached when logged out.
911
-            if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) {
912
-                wp_send_json( array(
913
-                    'error' => __( 'Security checks failed.', 'invoicing' )
914
-                ) );
911
+            if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) {
912
+                wp_send_json(array(
913
+                    'error' => __('Security checks failed.', 'invoicing')
914
+                ));
915 915
                 wp_die();
916 916
             }
917 917
 
918 918
             // allow to set a custom price through post_id
919 919
             $items = $_POST['items'];
920
-            $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0;
921
-            $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0;
920
+            $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0;
921
+            $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0;
922 922
 
923 923
             $cart_items = array();
924
-            if ( $items ) {
925
-                $items = explode( ',', $items );
924
+            if ($items) {
925
+                $items = explode(',', $items);
926 926
 
927
-                foreach( $items as $item ) {
927
+                foreach ($items as $item) {
928 928
                     $item_id = $item;
929 929
                     $quantity = 1;
930 930
 
931
-                    if ( strpos( $item, '|' ) !== false ) {
932
-                        $item_parts = explode( '|', $item );
931
+                    if (strpos($item, '|') !== false) {
932
+                        $item_parts = explode('|', $item);
933 933
                         $item_id = $item_parts[0];
934 934
                         $quantity = $item_parts[1];
935 935
                     }
936 936
 
937
-                    if ( $item_id && $quantity ) {
937
+                    if ($item_id && $quantity) {
938 938
                         $cart_items_arr = array(
939
-                            'id'            => (int)$item_id,
940
-                            'quantity'      => (int)$quantity
939
+                            'id'            => (int) $item_id,
940
+                            'quantity'      => (int) $quantity
941 941
                         );
942 942
 
943 943
                         // If there is a related post id then add it to meta
944
-                        if ( $related_post_id ) {
944
+                        if ($related_post_id) {
945 945
                             $cart_items_arr['meta'] = array(
946 946
                                 'post_id'   => $related_post_id
947 947
                             );
948 948
                         }
949 949
 
950 950
                         // If there is a custom price then set it.
951
-                        if ( $custom_item_price ) {
951
+                        if ($custom_item_price) {
952 952
                             $cart_items_arr['custom_price'] = $custom_item_price;
953 953
                         }
954 954
 
@@ -964,37 +964,37 @@  discard block
 block discarded – undo
964 964
              * @param int $related_post_id The related post id if any.
965 965
              * @since 1.0.0
966 966
              */
967
-            $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id );
967
+            $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id);
968 968
 
969 969
             // Make sure its not in the cart already, if it is then redirect to checkout.
970 970
             $cart_invoice = wpinv_get_invoice_cart();
971 971
 
972
-            if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) {
973
-                wp_send_json( array(
972
+            if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) {
973
+                wp_send_json(array(
974 974
                     'success' =>  $cart_invoice->get_checkout_payment_url()
975
-                ) );
975
+                ));
976 976
                 wp_die();
977 977
             }
978 978
 
979 979
             // Check if user has invoice with same items waiting to be paid.
980
-            $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' );
981
-            if ( !empty( $user_invoices ) ) {
982
-                foreach( $user_invoices as $user_invoice ) {
980
+            $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending');
981
+            if (!empty($user_invoices)) {
982
+                foreach ($user_invoices as $user_invoice) {
983 983
                     $user_cart_details = array();
984
-                    $invoice  = wpinv_get_invoice( $user_invoice->ID );
984
+                    $invoice = wpinv_get_invoice($user_invoice->ID);
985 985
                     $cart_details = $invoice->get_cart_details();
986 986
 
987
-                    if ( !empty( $cart_details ) ) {
988
-                        foreach ( $cart_details as $invoice_item ) {
987
+                    if (!empty($cart_details)) {
988
+                        foreach ($cart_details as $invoice_item) {
989 989
                             $ii_arr = array();
990
-                            $ii_arr['id'] = (int)$invoice_item['id'];
991
-                            $ii_arr['quantity'] = (int)$invoice_item['quantity'];
990
+                            $ii_arr['id'] = (int) $invoice_item['id'];
991
+                            $ii_arr['quantity'] = (int) $invoice_item['quantity'];
992 992
 
993
-                            if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) {
993
+                            if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) {
994 994
                                 $ii_arr['meta'] = $invoice_item['meta'];
995 995
                             }
996 996
 
997
-                            if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) {
997
+                            if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) {
998 998
                                 $ii_arr['custom_price'] = $invoice_item['custom_price'];
999 999
                             }
1000 1000
 
@@ -1002,17 +1002,17 @@  discard block
 block discarded – undo
1002 1002
                         }
1003 1003
                     }
1004 1004
 
1005
-                    if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) {
1006
-                        wp_send_json( array(
1005
+                    if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) {
1006
+                        wp_send_json(array(
1007 1007
                             'success' =>  $invoice->get_checkout_payment_url()
1008
-                        ) );
1008
+                        ));
1009 1009
                         wp_die();
1010 1010
                     }
1011 1011
                 }
1012 1012
             }
1013 1013
 
1014 1014
             // Create invoice and send user to checkout
1015
-            if ( !empty( $cart_items ) ) {
1015
+            if (!empty($cart_items)) {
1016 1016
                 $invoice_data = array(
1017 1017
                     'status'        =>  'wpi-pending',
1018 1018
                     'created_via'   =>  'wpi',
@@ -1020,21 +1020,21 @@  discard block
 block discarded – undo
1020 1020
                     'cart_details'  =>  $cart_items,
1021 1021
                 );
1022 1022
 
1023
-                $invoice = wpinv_insert_invoice( $invoice_data, true );
1023
+                $invoice = wpinv_insert_invoice($invoice_data, true);
1024 1024
 
1025
-                if ( !empty( $invoice ) && isset( $invoice->ID ) ) {
1026
-                    wp_send_json( array(
1025
+                if (!empty($invoice) && isset($invoice->ID)) {
1026
+                    wp_send_json(array(
1027 1027
                         'success' =>  $invoice->get_checkout_payment_url()
1028
-                    ) );
1028
+                    ));
1029 1029
                 } else {
1030
-                    wp_send_json( array(
1031
-                        'error' => __( 'Invoice failed to create', 'invoicing' )
1032
-                    ) );
1030
+                    wp_send_json(array(
1031
+                        'error' => __('Invoice failed to create', 'invoicing')
1032
+                    ));
1033 1033
                 }
1034 1034
             } else {
1035
-                wp_send_json( array(
1036
-                    'error' => __( 'Items not valid.', 'invoicing' )
1037
-                ) );
1035
+                wp_send_json(array(
1036
+                    'error' => __('Items not valid.', 'invoicing')
1037
+                ));
1038 1038
             }
1039 1039
         }
1040 1040
 
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Spacing   +261 added lines, -261 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Retrieves an item by it's ID.
@@ -14,9 +14,9 @@  discard block
 block discarded – undo
14 14
  * @param int the item ID to retrieve.
15 15
  * @return WPInv_Item|false
16 16
  */
17
-function wpinv_get_item_by_id( $id ) {
18
-    $item = wpinv_get_item( $id );
19
-    return empty( $item ) || $id != $item->get_id() ? false : $item;
17
+function wpinv_get_item_by_id($id) {
18
+    $item = wpinv_get_item($id);
19
+    return empty($item) || $id != $item->get_id() ? false : $item;
20 20
 }
21 21
 
22 22
 /**
@@ -24,14 +24,14 @@  discard block
 block discarded – undo
24 24
  * 
25 25
  * @return WPInv_Item|false
26 26
  */
27
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
27
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
28 28
 
29
-    if ( 'id' == strtolower( $field ) ) {
30
-        return wpinv_get_item_by_id( $field );
29
+    if ('id' == strtolower($field)) {
30
+        return wpinv_get_item_by_id($field);
31 31
     }
32 32
 
33
-    $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type );
34
-    return $id ? wpinv_get_item( $id ) : false;
33
+    $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type);
34
+    return $id ? wpinv_get_item($id) : false;
35 35
 
36 36
 }
37 37
 
@@ -41,22 +41,22 @@  discard block
 block discarded – undo
41 41
  * @param int|WPInv_Item the item to retrieve.
42 42
  * @return WPInv_Item|false
43 43
  */
44
-function wpinv_get_item( $item = 0 ) {
44
+function wpinv_get_item($item = 0) {
45 45
     
46
-    if ( empty( $item ) ) {
46
+    if (empty($item)) {
47 47
         return false;
48 48
     }
49 49
 
50
-    $item = new WPInv_Item( $item );
50
+    $item = new WPInv_Item($item);
51 51
     return $item->get_id() ? $item : false;
52 52
 
53 53
 }
54 54
 
55
-function wpinv_get_all_items( $args = array() ) {
55
+function wpinv_get_all_items($args = array()) {
56 56
 
57
-    $args = wp_parse_args( $args, array(
58
-        'status'         => array( 'publish' ),
59
-        'limit'          => get_option( 'posts_per_page' ),
57
+    $args = wp_parse_args($args, array(
58
+        'status'         => array('publish'),
59
+        'limit'          => get_option('posts_per_page'),
60 60
         'page'           => 1,
61 61
         'exclude'        => array(),
62 62
         'orderby'        => 'date',
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
         'meta_query'     => array(),
66 66
         'return'         => 'objects',
67 67
         'paginate'       => false,
68
-    ) );
68
+    ));
69 69
 
70 70
     $wp_query_args = array(
71 71
         'post_type'      => 'wpi_item',
@@ -75,26 +75,26 @@  discard block
 block discarded – undo
75 75
         'fields'         => 'ids',
76 76
         'orderby'        => $args['orderby'],
77 77
         'order'          => $args['order'],
78
-        'paged'          => absint( $args['page'] ),
78
+        'paged'          => absint($args['page']),
79 79
     );
80 80
 
81
-    if ( ! empty( $args['exclude'] ) ) {
82
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
81
+    if (!empty($args['exclude'])) {
82
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
83 83
     }
84 84
 
85
-    if ( ! $args['paginate' ] ) {
85
+    if (!$args['paginate']) {
86 86
         $wp_query_args['no_found_rows'] = true;
87 87
     }
88 88
 
89
-    if ( ! empty( $args['search'] ) ) {
89
+    if (!empty($args['search'])) {
90 90
         $wp_query_args['s'] = $args['search'];
91 91
     }
92 92
 
93
-    if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) {
94
-        $types = wpinv_parse_list( $args['type'] );
93
+    if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) {
94
+        $types = wpinv_parse_list($args['type']);
95 95
         $wp_query_args['meta_query'][] = array(
96 96
             'key'     => '_wpinv_type',
97
-            'value'   => implode( ',', $types ),
97
+            'value'   => implode(',', $types),
98 98
             'compare' => 'IN',
99 99
         );
100 100
     }
@@ -102,17 +102,17 @@  discard block
 block discarded – undo
102 102
     $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args);
103 103
 
104 104
     // Get results.
105
-    $items = new WP_Query( $wp_query_args );
105
+    $items = new WP_Query($wp_query_args);
106 106
 
107
-    if ( 'objects' === $args['return'] ) {
108
-        $return = array_map( 'wpinv_get_item_by_id', $items->posts );
109
-    } elseif ( 'self' === $args['return'] ) {
107
+    if ('objects' === $args['return']) {
108
+        $return = array_map('wpinv_get_item_by_id', $items->posts);
109
+    } elseif ('self' === $args['return']) {
110 110
         return $items;
111 111
     } else {
112 112
         $return = $items->posts;
113 113
     }
114 114
 
115
-    if ( $args['paginate' ] ) {
115
+    if ($args['paginate']) {
116 116
         return (object) array(
117 117
             'items'      => $return,
118 118
             'total'         => $items->found_posts,
@@ -124,12 +124,12 @@  discard block
 block discarded – undo
124 124
 
125 125
 }
126 126
 
127
-function wpinv_is_free_item( $item_id = 0 ) {
128
-    if( empty( $item_id ) ) {
127
+function wpinv_is_free_item($item_id = 0) {
128
+    if (empty($item_id)) {
129 129
         return false;
130 130
     }
131 131
 
132
-    $item = new WPInv_Item( $item_id );
132
+    $item = new WPInv_Item($item_id);
133 133
     
134 134
     return $item->is_free();
135 135
 }
@@ -139,128 +139,128 @@  discard block
 block discarded – undo
139 139
  * 
140 140
  * @param WP_Post|WPInv_Item|Int $item The item to check for.
141 141
  */
142
-function wpinv_item_is_editable( $item = 0 ) {
142
+function wpinv_item_is_editable($item = 0) {
143 143
 
144 144
     // Fetch the item.
145
-    $item = new WPInv_Item( $item );
145
+    $item = new WPInv_Item($item);
146 146
 
147 147
     // Check if it is editable.
148 148
     return $item->is_editable();
149 149
 }
150 150
 
151
-function wpinv_get_item_price( $item_id = 0 ) {
152
-    if( empty( $item_id ) ) {
151
+function wpinv_get_item_price($item_id = 0) {
152
+    if (empty($item_id)) {
153 153
         return false;
154 154
     }
155 155
 
156
-    $item = new WPInv_Item( $item_id );
156
+    $item = new WPInv_Item($item_id);
157 157
     
158 158
     return $item->get_price();
159 159
 }
160 160
 
161
-function wpinv_is_recurring_item( $item_id = 0 ) {
162
-    if( empty( $item_id ) ) {
161
+function wpinv_is_recurring_item($item_id = 0) {
162
+    if (empty($item_id)) {
163 163
         return false;
164 164
     }
165 165
 
166
-    $item = new WPInv_Item( $item_id );
166
+    $item = new WPInv_Item($item_id);
167 167
     
168 168
     return $item->is_recurring();
169 169
 }
170 170
 
171
-function wpinv_item_price( $item_id = 0 ) {
172
-    if( empty( $item_id ) ) {
171
+function wpinv_item_price($item_id = 0) {
172
+    if (empty($item_id)) {
173 173
         return false;
174 174
     }
175 175
 
176
-    $price = wpinv_get_item_price( $item_id );
177
-    $price = wpinv_price( wpinv_format_amount( $price ) );
176
+    $price = wpinv_get_item_price($item_id);
177
+    $price = wpinv_price(wpinv_format_amount($price));
178 178
     
179
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
179
+    return apply_filters('wpinv_item_price', $price, $item_id);
180 180
 }
181 181
 
182
-function wpinv_item_show_price( $item_id = 0, $echo = true ) {
183
-    if ( empty( $item_id ) ) {
182
+function wpinv_item_show_price($item_id = 0, $echo = true) {
183
+    if (empty($item_id)) {
184 184
         $item_id = get_the_ID();
185 185
     }
186 186
 
187
-    $price = wpinv_item_price( $item_id );
187
+    $price = wpinv_item_price($item_id);
188 188
 
189
-    $price           = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id );
189
+    $price           = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id);
190 190
     $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>';
191
-    $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price );
191
+    $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price);
192 192
 
193
-    if ( $echo ) {
193
+    if ($echo) {
194 194
         echo $formatted_price;
195 195
     } else {
196 196
         return $formatted_price;
197 197
     }
198 198
 }
199 199
 
200
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
201
-    if ( is_null( $amount_override ) ) {
202
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
200
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
201
+    if (is_null($amount_override)) {
202
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
203 203
     } else {
204 204
         $original_price = $amount_override;
205 205
     }
206 206
     
207 207
     $price = $original_price;
208 208
 
209
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
209
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
210 210
 }
211 211
 
212
-function wpinv_item_custom_singular_name( $item_id ) {
213
-    if( empty( $item_id ) ) {
212
+function wpinv_item_custom_singular_name($item_id) {
213
+    if (empty($item_id)) {
214 214
         return false;
215 215
     }
216 216
 
217
-    $item = new WPInv_Item( $item_id );
217
+    $item = new WPInv_Item($item_id);
218 218
     
219 219
     return $item->get_custom_singular_name();
220 220
 }
221 221
 
222 222
 function wpinv_get_item_types() {
223 223
     $item_types = array(
224
-            'custom'    => __( 'Standard', 'invoicing' ),
225
-            'fee'       => __( 'Fee', 'invoicing' ),
224
+            'custom'    => __('Standard', 'invoicing'),
225
+            'fee'       => __('Fee', 'invoicing'),
226 226
         );
227
-    return apply_filters( 'wpinv_get_item_types', $item_types );
227
+    return apply_filters('wpinv_get_item_types', $item_types);
228 228
 }
229 229
 
230 230
 function wpinv_item_types() {
231 231
     $item_types = wpinv_get_item_types();
232 232
     
233
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
233
+    return (!empty($item_types) ? array_keys($item_types) : array());
234 234
 }
235 235
 
236
-function wpinv_get_item_type( $item_id ) {
237
-    if( empty( $item_id ) ) {
236
+function wpinv_get_item_type($item_id) {
237
+    if (empty($item_id)) {
238 238
         return false;
239 239
     }
240 240
 
241
-    $item = new WPInv_Item( $item_id );
241
+    $item = new WPInv_Item($item_id);
242 242
     
243 243
     return $item->get_type();
244 244
 }
245 245
 
246
-function wpinv_item_type( $item_id ) {
246
+function wpinv_item_type($item_id) {
247 247
     $item_types = wpinv_get_item_types();
248 248
     
249
-    $item_type = wpinv_get_item_type( $item_id );
249
+    $item_type = wpinv_get_item_type($item_id);
250 250
     
251
-    if ( empty( $item_type ) ) {
251
+    if (empty($item_type)) {
252 252
         $item_type = '-';
253 253
     }
254 254
     
255
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
255
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
256 256
 
257
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
257
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
258 258
 }
259 259
 
260
-function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) {
260
+function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) {
261 261
     global $wpinv_logs;
262 262
     
263
-    if ( empty( $wpinv_logs ) ) {
263
+    if (empty($wpinv_logs)) {
264 264
         return false;
265 265
     }
266 266
 
@@ -269,278 +269,278 @@  discard block
 block discarded – undo
269 269
         'log_type'		=> 'wpi_item'
270 270
     );
271 271
 
272
-    $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1;
272
+    $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1;
273 273
 
274 274
     $log_meta = array(
275 275
         'user_info'	=> $user_info,
276 276
         'user_id'	=> $user_id,
277
-        'file_id'	=> (int)$file_id,
277
+        'file_id'	=> (int) $file_id,
278 278
         'ip'		=> $ip,
279 279
         'invoice_id'=> $invoice_id,
280 280
     );
281 281
 
282
-    $wpinv_logs->insert_log( $log_data, $log_meta );
282
+    $wpinv_logs->insert_log($log_data, $log_meta);
283 283
 }
284 284
 
285
-function wpinv_remove_item_logs_on_delete( $item_id = 0 ) {
286
-    if ( 'wpi_item' !== get_post_type( $item_id ) )
285
+function wpinv_remove_item_logs_on_delete($item_id = 0) {
286
+    if ('wpi_item' !== get_post_type($item_id))
287 287
         return;
288 288
 
289 289
     global $wpinv_logs;
290 290
     
291
-    if ( empty( $wpinv_logs ) ) {
291
+    if (empty($wpinv_logs)) {
292 292
         return false;
293 293
     }
294 294
 
295 295
     // Remove all log entries related to this item
296
-    $wpinv_logs->delete_logs( $item_id );
296
+    $wpinv_logs->delete_logs($item_id);
297 297
 }
298
-add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' );
298
+add_action('delete_post', 'wpinv_remove_item_logs_on_delete');
299 299
 
300
-function wpinv_get_random_item( $post_ids = true ) {
301
-    wpinv_get_random_items( 1, $post_ids );
300
+function wpinv_get_random_item($post_ids = true) {
301
+    wpinv_get_random_items(1, $post_ids);
302 302
 }
303 303
 
304
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
305
-    if ( $post_ids ) {
306
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
304
+function wpinv_get_random_items($num = 3, $post_ids = true) {
305
+    if ($post_ids) {
306
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
307 307
     } else {
308
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
308
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
309 309
     }
310 310
     
311
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
311
+    $args = apply_filters('wpinv_get_random_items', $args);
312 312
     
313
-    return get_posts( $args );
313
+    return get_posts($args);
314 314
 }
315 315
 
316
-function wpinv_get_item_token( $url = '' ) {
316
+function wpinv_get_item_token($url = '') {
317 317
     $args    = array();
318
-    $hash    = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' );
319
-    $secret  = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) );
318
+    $hash    = apply_filters('wpinv_get_url_token_algorithm', 'sha256');
319
+    $secret  = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt()));
320 320
 
321
-    $parts   = parse_url( $url );
321
+    $parts   = parse_url($url);
322 322
     $options = array();
323 323
 
324
-    if ( isset( $parts['query'] ) ) {
325
-        wp_parse_str( $parts['query'], $query_args );
324
+    if (isset($parts['query'])) {
325
+        wp_parse_str($parts['query'], $query_args);
326 326
 
327
-        if ( ! empty( $query_args['o'] ) ) {
328
-            $options = explode( ':', rawurldecode( $query_args['o'] ) );
327
+        if (!empty($query_args['o'])) {
328
+            $options = explode(':', rawurldecode($query_args['o']));
329 329
 
330
-            if ( in_array( 'ip', $options ) ) {
330
+            if (in_array('ip', $options)) {
331 331
                 $args['ip'] = wpinv_get_ip();
332 332
             }
333 333
 
334
-            if ( in_array( 'ua', $options ) ) {
334
+            if (in_array('ua', $options)) {
335 335
                 $ua = wpinv_get_user_agent();
336
-                $args['user_agent'] = rawurlencode( $ua );
336
+                $args['user_agent'] = rawurlencode($ua);
337 337
             }
338 338
         }
339 339
     }
340 340
 
341
-    $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options );
341
+    $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options);
342 342
 
343 343
     $args['secret'] = $secret;
344 344
     $args['token']  = false;
345 345
 
346
-    $url   = add_query_arg( $args, $url );
347
-    $parts = parse_url( $url );
346
+    $url   = add_query_arg($args, $url);
347
+    $parts = parse_url($url);
348 348
 
349
-    if ( ! isset( $parts['path'] ) ) {
349
+    if (!isset($parts['path'])) {
350 350
         $parts['path'] = '';
351 351
     }
352 352
 
353
-    $token = md5( $parts['path'] . '?' . $parts['query'] );
353
+    $token = md5($parts['path'] . '?' . $parts['query']);
354 354
 
355 355
     return $token;
356 356
 }
357 357
 
358
-function wpinv_validate_url_token( $url = '' ) {
358
+function wpinv_validate_url_token($url = '') {
359 359
     $ret   = false;
360
-    $parts = parse_url( $url );
360
+    $parts = parse_url($url);
361 361
 
362
-    if ( isset( $parts['query'] ) ) {
363
-        wp_parse_str( $parts['query'], $query_args );
362
+    if (isset($parts['query'])) {
363
+        wp_parse_str($parts['query'], $query_args);
364 364
 
365
-        $allowed = apply_filters( 'wpinv_url_token_allowed_params', array(
365
+        $allowed = apply_filters('wpinv_url_token_allowed_params', array(
366 366
             'item',
367 367
             'ttl',
368 368
             'token'
369
-        ) );
369
+        ));
370 370
 
371 371
         $remove = array();
372 372
 
373
-        foreach( $query_args as $key => $value ) {
374
-            if( false === in_array( $key, $allowed ) ) {
373
+        foreach ($query_args as $key => $value) {
374
+            if (false === in_array($key, $allowed)) {
375 375
                 $remove[] = $key;
376 376
             }
377 377
         }
378 378
 
379
-        if( ! empty( $remove ) ) {
380
-            $url = remove_query_arg( $remove, $url );
379
+        if (!empty($remove)) {
380
+            $url = remove_query_arg($remove, $url);
381 381
         }
382 382
 
383
-        if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) {
384
-            wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
383
+        if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) {
384
+            wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403));
385 385
         }
386 386
 
387
-        if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) {
387
+        if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) {
388 388
             $ret = true;
389 389
         }
390 390
 
391 391
     }
392 392
 
393
-    return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args );
393
+    return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args);
394 394
 }
395 395
 
396
-function wpinv_item_in_cart( $item_id = 0, $options = array() ) {
396
+function wpinv_item_in_cart($item_id = 0, $options = array()) {
397 397
     $cart_items = wpinv_get_cart_contents();
398 398
 
399 399
     $ret = false;
400 400
 
401
-    if ( is_array( $cart_items ) ) {
402
-        foreach ( $cart_items as $item ) {
403
-            if ( $item['id'] == $item_id ) {
401
+    if (is_array($cart_items)) {
402
+        foreach ($cart_items as $item) {
403
+            if ($item['id'] == $item_id) {
404 404
                 $ret = true;
405 405
                 break;
406 406
             }
407 407
         }
408 408
     }
409 409
 
410
-    return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options );
410
+    return (bool) apply_filters('wpinv_item_in_cart', $ret, $item_id, $options);
411 411
 }
412 412
 
413
-function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) {
413
+function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) {
414 414
     $tax = 0;
415
-    if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) {
416
-        $country = !empty( $_POST['country'] ) ? $_POST['country'] : false;
417
-        $state   = isset( $_POST['state'] ) ? $_POST['state'] : '';
415
+    if (!wpinv_item_is_tax_exclusive($item_id)) {
416
+        $country = !empty($_POST['country']) ? $_POST['country'] : false;
417
+        $state   = isset($_POST['state']) ? $_POST['state'] : '';
418 418
 
419
-        $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id );
419
+        $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id);
420 420
     }
421 421
 
422
-    return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options );
422
+    return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options);
423 423
 }
424 424
 
425
-function wpinv_cart_item_price( $item, $currency = '' ) {
425
+function wpinv_cart_item_price($item, $currency = '') {
426 426
 
427
-    if( empty( $currency ) ) {
427
+    if (empty($currency)) {
428 428
         $currency = wpinv_get_currency();
429 429
     }
430 430
 
431
-    $item_id    = isset( $item['id'] ) ? $item['id'] : 0;
432
-    $price      = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0;
433
-    $tax        = wpinv_price( wpinv_format_amount( $item['tax'] ) );
431
+    $item_id    = isset($item['id']) ? $item['id'] : 0;
432
+    $price      = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0;
433
+    $tax        = wpinv_price(wpinv_format_amount($item['tax']));
434 434
     
435
-    if ( !wpinv_is_free_item( $item_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) {
436
-        if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) {
435
+    if (!wpinv_is_free_item($item_id) && !wpinv_item_is_tax_exclusive($item_id)) {
436
+        if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) {
437 437
             $price += $tax;
438 438
         }
439 439
         
440
-        if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) {
440
+        if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) {
441 441
             $price -= $tax;
442 442
         }        
443 443
     }
444 444
 
445
-    $price = wpinv_price( wpinv_format_amount( $price ), $currency );
445
+    $price = wpinv_price(wpinv_format_amount($price), $currency);
446 446
 
447
-    return apply_filters( 'wpinv_cart_item_price_label', $price, $item );
447
+    return apply_filters('wpinv_cart_item_price_label', $price, $item);
448 448
 }
449 449
 
450
-function wpinv_cart_item_subtotal( $item, $currency = '' ) {
450
+function wpinv_cart_item_subtotal($item, $currency = '') {
451 451
 
452
-    if( empty( $currency ) ) {
452
+    if (empty($currency)) {
453 453
         $currency = wpinv_get_currency();
454 454
     }
455 455
 
456
-    $subtotal   = isset( $item['subtotal'] ) ? $item['subtotal'] : 0;
457
-    $subtotal   = wpinv_price( wpinv_format_amount( $subtotal ), $currency );
456
+    $subtotal   = isset($item['subtotal']) ? $item['subtotal'] : 0;
457
+    $subtotal   = wpinv_price(wpinv_format_amount($subtotal), $currency);
458 458
 
459
-    return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item );
459
+    return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item);
460 460
 }
461 461
 
462
-function wpinv_cart_item_tax( $item, $currency = '' ) {
462
+function wpinv_cart_item_tax($item, $currency = '') {
463 463
     $tax        = '';
464 464
     $tax_rate   = '';
465 465
 
466
-    if( empty( $currency ) ) {
466
+    if (empty($currency)) {
467 467
         $currency = wpinv_get_currency();
468 468
     }
469 469
     
470
-    if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) {
471
-        $tax      = wpinv_price( wpinv_format_amount( $item['tax'] ), $currency );
472
-        $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100;
473
-        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
470
+    if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) {
471
+        $tax      = wpinv_price(wpinv_format_amount($item['tax']), $currency);
472
+        $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100;
473
+        $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : '';
474 474
         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : '';
475 475
     }
476 476
     
477
-    $tax        = $tax . $tax_rate;
477
+    $tax = $tax . $tax_rate;
478 478
     
479
-    if ( $tax === '' ) {
479
+    if ($tax === '') {
480 480
         $tax = 0; // Zero tax
481 481
     }
482 482
 
483
-    return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item );
483
+    return apply_filters('wpinv_cart_item_tax_label', $tax, $item);
484 484
 }
485 485
 
486
-function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) {
486
+function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) {
487 487
     $price = 0;
488 488
     
489 489
     // Set custom price
490
-    if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) {
490
+    if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') {
491 491
         $price = $cart_item['custom_price'];
492 492
     } else {
493
-        $variable_prices = wpinv_has_variable_prices( $item_id );
493
+        $variable_prices = wpinv_has_variable_prices($item_id);
494 494
 
495
-        if ( $variable_prices ) {
496
-            $prices = wpinv_get_variable_prices( $item_id );
495
+        if ($variable_prices) {
496
+            $prices = wpinv_get_variable_prices($item_id);
497 497
 
498
-            if ( $prices ) {
499
-                if( ! empty( $options ) ) {
500
-                    $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false;
498
+            if ($prices) {
499
+                if (!empty($options)) {
500
+                    $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false;
501 501
                 } else {
502 502
                     $price = false;
503 503
                 }
504 504
             }
505 505
         }
506 506
 
507
-        if( ! $variable_prices || false === $price ) {
508
-            if($cart_item['item_price'] > 0){
507
+        if (!$variable_prices || false === $price) {
508
+            if ($cart_item['item_price'] > 0) {
509 509
                 $price = $cart_item['item_price'];
510 510
             } else {
511 511
                 // Get the standard Item price if not using variable prices
512
-                $price = wpinv_get_item_price( $item_id );
512
+                $price = wpinv_get_item_price($item_id);
513 513
             }
514 514
         }
515 515
     }
516 516
 
517
-    if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) {
518
-        $price -= wpinv_get_cart_item_tax( $item_id, $price, $options );
517
+    if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) {
518
+        $price -= wpinv_get_cart_item_tax($item_id, $price, $options);
519 519
     }
520 520
 
521
-    return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive );
521
+    return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive);
522 522
 }
523 523
 
524
-function wpinv_get_cart_item_price_id( $item = array() ) {
525
-    if( isset( $item['item_number'] ) ) {
526
-        $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null;
524
+function wpinv_get_cart_item_price_id($item = array()) {
525
+    if (isset($item['item_number'])) {
526
+        $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null;
527 527
     } else {
528
-        $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null;
528
+        $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null;
529 529
     }
530 530
     return $price_id;
531 531
 }
532 532
 
533
-function wpinv_get_cart_item_price_name( $item = array() ) {
534
-    $price_id = (int)wpinv_get_cart_item_price_id( $item );
535
-    $prices   = wpinv_get_variable_prices( $item['id'] );
536
-    $name     = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : '';
537
-    return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item );
533
+function wpinv_get_cart_item_price_name($item = array()) {
534
+    $price_id = (int) wpinv_get_cart_item_price_id($item);
535
+    $prices   = wpinv_get_variable_prices($item['id']);
536
+    $name     = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : '';
537
+    return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item);
538 538
 }
539 539
 
540
-function wpinv_get_cart_item_name( $item = array() ) {
541
-    $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] );
540
+function wpinv_get_cart_item_name($item = array()) {
541
+    $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']);
542 542
 
543
-    if ( empty( $item_title ) ) {
543
+    if (empty($item_title)) {
544 544
         $item_title = $item['id'];
545 545
     }
546 546
 
@@ -550,23 +550,23 @@  discard block
 block discarded – undo
550 550
     }
551 551
     */
552 552
 
553
-    return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item );
553
+    return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item);
554 554
 }
555 555
 
556
-function wpinv_has_variable_prices( $item_id = 0 ) {
556
+function wpinv_has_variable_prices($item_id = 0) {
557 557
     return false;
558 558
 }
559 559
 
560
-function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) {
560
+function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) {
561 561
     $cart_items = wpinv_get_cart_contents();
562 562
 
563
-    if ( !is_array( $cart_items ) ) {
563
+    if (!is_array($cart_items)) {
564 564
         return false; // Empty cart
565 565
     } else {
566
-        foreach ( $cart_items as $position => $item ) {
567
-            if ( $item['id'] == $item_id ) {
568
-                if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) {
569
-                    if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) {
566
+        foreach ($cart_items as $position => $item) {
567
+            if ($item['id'] == $item_id) {
568
+                if (isset($options['price_id']) && isset($item['options']['price_id'])) {
569
+                    if ((int) $options['price_id'] == (int) $item['options']['price_id']) {
570 570
                         return $position;
571 571
                     }
572 572
                 } else {
@@ -579,80 +579,80 @@  discard block
 block discarded – undo
579 579
     return false; // Not found
580 580
 }
581 581
 
582
-function wpinv_get_cart_item_quantity( $item ) {
583
-    if ( wpinv_item_quantities_enabled() ) {
584
-        $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
582
+function wpinv_get_cart_item_quantity($item) {
583
+    if (wpinv_item_quantities_enabled()) {
584
+        $quantity = !empty($item['quantity']) && (int) $item['quantity'] > 0 ? absint($item['quantity']) : 1;
585 585
     } else {
586 586
         $quantity = 1;
587 587
     }
588 588
     
589
-    if ( $quantity < 1 ) {
589
+    if ($quantity < 1) {
590 590
         $quantity = 1;
591 591
     }
592 592
     
593
-    return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item );
593
+    return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item);
594 594
 }
595 595
 
596
-function wpinv_get_item_suffix( $item, $html = true ) {
597
-    if ( empty( $item ) ) {
596
+function wpinv_get_item_suffix($item, $html = true) {
597
+    if (empty($item)) {
598 598
         return NULL;
599 599
     }
600 600
     
601
-    if ( is_int( $item ) ) {
602
-        $item = new WPInv_Item( $item );
601
+    if (is_int($item)) {
602
+        $item = new WPInv_Item($item);
603 603
     }
604 604
     
605
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
605
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
606 606
         return NULL;
607 607
     }
608 608
     
609
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
609
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
610 610
     
611
-    if ( !$html && $suffix ) {
612
-        $suffix = strip_tags( $suffix );
611
+    if (!$html && $suffix) {
612
+        $suffix = strip_tags($suffix);
613 613
     }
614 614
     
615
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
615
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
616 616
 }
617 617
 
618
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
619
-    if ( empty( $item ) ) {
618
+function wpinv_remove_item($item = 0, $force_delete = false) {
619
+    if (empty($item)) {
620 620
         return NULL;
621 621
     }
622 622
     
623
-    if ( is_int( $item ) ) {
624
-        $item = new WPInv_Item( $item );
623
+    if (is_int($item)) {
624
+        $item = new WPInv_Item($item);
625 625
     }
626 626
     
627
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
627
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
628 628
         return NULL;
629 629
     }
630 630
     
631
-    do_action( 'wpinv_pre_delete_item', $item );
631
+    do_action('wpinv_pre_delete_item', $item);
632 632
 
633
-    wp_delete_post( $item->ID, $force_delete );
633
+    wp_delete_post($item->ID, $force_delete);
634 634
 
635
-    do_action( 'wpinv_post_delete_item', $item );
635
+    do_action('wpinv_post_delete_item', $item);
636 636
 }
637 637
 
638
-function wpinv_can_delete_item( $post_id ) {
638
+function wpinv_can_delete_item($post_id) {
639 639
     $return = wpinv_current_user_can_manage_invoicing() ? true : false;
640 640
     
641
-    if ( $return && wpinv_item_in_use( $post_id ) ) {
641
+    if ($return && wpinv_item_in_use($post_id)) {
642 642
         $return = false; // Don't delete item already use in invoices.
643 643
     }
644 644
     
645
-    return apply_filters( 'wpinv_can_delete_item', $return, $post_id );
645
+    return apply_filters('wpinv_can_delete_item', $return, $post_id);
646 646
 }
647 647
 
648 648
 function wpinv_admin_action_delete() {
649 649
     $screen = get_current_screen();
650 650
     
651
-    if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) {
651
+    if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) {
652 652
         $post_ids = array();
653 653
         
654
-        foreach ( $_REQUEST['post'] as $post_id ) {
655
-            if ( !wpinv_can_delete_item( $post_id ) ) {
654
+        foreach ($_REQUEST['post'] as $post_id) {
655
+            if (!wpinv_can_delete_item($post_id)) {
656 656
                 continue;
657 657
             }
658 658
             
@@ -662,39 +662,39 @@  discard block
 block discarded – undo
662 662
         $_REQUEST['post'] = $post_ids;
663 663
     }
664 664
 }
665
-add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 );
666
-add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 );
665
+add_action('admin_action_trash', 'wpinv_admin_action_delete', -10);
666
+add_action('admin_action_delete', 'wpinv_admin_action_delete', -10);
667 667
 
668
-function wpinv_check_delete_item( $check, $post, $force_delete ) {
669
-    if ( $post->post_type == 'wpi_item' ) {
670
-        if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) {
668
+function wpinv_check_delete_item($check, $post, $force_delete) {
669
+    if ($post->post_type == 'wpi_item') {
670
+        if ($force_delete && !wpinv_can_delete_item($post->ID)) {
671 671
             return true;
672 672
         }
673 673
     }
674 674
     
675 675
     return $check;
676 676
 }
677
-add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 );
677
+add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3);
678 678
 
679
-function wpinv_item_in_use( $item_id ) {
679
+function wpinv_item_in_use($item_id) {
680 680
     global $wpdb, $wpi_items_in_use;
681 681
     
682
-    if ( !$item_id > 0 ) {
682
+    if (!$item_id > 0) {
683 683
         return false;
684 684
     }
685 685
     
686
-    if ( !empty( $wpi_items_in_use ) ) {
687
-        if ( isset( $wpi_items_in_use[$item_id] ) ) {
686
+    if (!empty($wpi_items_in_use)) {
687
+        if (isset($wpi_items_in_use[$item_id])) {
688 688
             return $wpi_items_in_use[$item_id];
689 689
         }
690 690
     } else {
691 691
         $wpi_items_in_use = array();
692 692
     }
693 693
     
694
-    $statuses   = array_keys( wpinv_get_invoice_statuses( true, true ) );
694
+    $statuses = array_keys(wpinv_get_invoice_statuses(true, true));
695 695
     
696
-    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
697
-    $in_use = $wpdb->get_var( $query ) > 0 ? true : false;
696
+    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int) $item_id . "', pm.meta_value )";
697
+    $in_use = $wpdb->get_var($query) > 0 ? true : false;
698 698
     
699 699
     $wpi_items_in_use[$item_id] = $in_use;
700 700
     
@@ -737,45 +737,45 @@  discard block
 block discarded – undo
737 737
  * @param bool $wp_error whether or not to return a WP_Error on failure.
738 738
  * @return bool|WP_Error|WPInv_Item
739 739
  */
740
-function wpinv_create_item( $args = array(), $wp_error = false ) {
740
+function wpinv_create_item($args = array(), $wp_error = false) {
741 741
 
742 742
     // Prepare the item.
743
-    if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) {
744
-        $type = empty( $args['type'] ) ? 'custom' : $args['type'];
745
-        $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type );
743
+    if (!empty($args['custom_id']) && empty($args['ID'])) {
744
+        $type = empty($args['type']) ? 'custom' : $args['type'];
745
+        $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type);
746 746
 
747
-        if ( ! empty( $item ) ) {
747
+        if (!empty($item)) {
748 748
             $args['ID'] = $item->get_id();
749 749
         }
750 750
 
751 751
     }
752 752
 
753 753
     // Do we have an item?
754
-    if ( ! empty( $args['ID'] ) ) {
755
-        $item = new WPInv_Item( $args['ID'] );
754
+    if (!empty($args['ID'])) {
755
+        $item = new WPInv_Item($args['ID']);
756 756
     } else {
757 757
         $item = new WPInv_Item();
758 758
     }
759 759
 
760 760
     // Do we have an error?
761
-    if ( ! empty( $item->last_error ) ) {
762
-        return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false;
761
+    if (!empty($item->last_error)) {
762
+        return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false;
763 763
     }
764 764
 
765 765
     // Update item props.
766
-    $item->set_props( $args );
766
+    $item->set_props($args);
767 767
 
768 768
     // Save the item.
769 769
     $item->save();
770 770
 
771 771
     // Do we have an error?
772
-    if ( ! empty( $item->last_error ) ) {
773
-        return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false;
772
+    if (!empty($item->last_error)) {
773
+        return $wp_error ? new WP_Error('not_saved', $item->last_error) : false;
774 774
     }
775 775
 
776 776
     // Was the item saved?
777
-    if ( ! $item->get_id() ) {
778
-        return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false;
777
+    if (!$item->get_id()) {
778
+        return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false;
779 779
     }
780 780
 
781 781
     return $item;
@@ -787,14 +787,14 @@  discard block
 block discarded – undo
787 787
  * 
788 788
  * @see wpinv_create_item()
789 789
  */
790
-function wpinv_update_item( $args = array(), $wp_error = false ) {
791
-    return wpinv_create_item( $args, $wp_error );
790
+function wpinv_update_item($args = array(), $wp_error = false) {
791
+    return wpinv_create_item($args, $wp_error);
792 792
 }
793 793
 
794 794
 /**
795 795
  * Sanitizes a recurring period
796 796
  */
797
-function getpaid_sanitize_recurring_period( $period, $full = false ) {
797
+function getpaid_sanitize_recurring_period($period, $full = false) {
798 798
 
799 799
     $periods = array(
800 800
         'D' => 'day',
@@ -803,11 +803,11 @@  discard block
 block discarded – undo
803 803
         'Y' => 'year',
804 804
     );
805 805
 
806
-    if ( ! isset( $periods[ $period ] ) ) {
806
+    if (!isset($periods[$period])) {
807 807
         $period = 'D';
808 808
     }
809 809
 
810
-    return $full ? $periods[ $period ] : $period;
810
+    return $full ? $periods[$period] : $period;
811 811
 
812 812
 }
813 813
 
@@ -816,27 +816,27 @@  discard block
 block discarded – undo
816 816
  * 
817 817
  * @param WPInv_Item $item
818 818
  */
819
-function getpaid_item_recurring_price_help_text( $item, $currency = '' ) {
819
+function getpaid_item_recurring_price_help_text($item, $currency = '') {
820 820
 
821 821
     // Abort if it is not recurring.
822
-    if ( ! $item->is_recurring() ) {
822
+    if (!$item->is_recurring()) {
823 823
         return '';
824 824
     }
825 825
 
826
-    $initial_price   = wpinv_price( wpinv_sanitize_amount( $item->get_initial_price() ), $currency );
827
-    $recurring_price = wpinv_price( wpinv_sanitize_amount( $item->get_recurring_price() ), $currency );
828
-    $period          = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' );
826
+    $initial_price   = wpinv_price(wpinv_sanitize_amount($item->get_initial_price()), $currency);
827
+    $recurring_price = wpinv_price(wpinv_sanitize_amount($item->get_recurring_price()), $currency);
828
+    $period          = getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '');
829 829
 
830 830
     // For free trial items.
831
-    if ( $item->has_free_trial() ) {
832
-        $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() );
831
+    if ($item->has_free_trial()) {
832
+        $trial_period = getpaid_get_subscription_period_label($item->get_trial_period(), $item->get_trial_interval());
833 833
 
834
-        if ( 0 == $item->get_initial_price() ) {
834
+        if (0 == $item->get_initial_price()) {
835 835
 
836 836
             return sprintf(
837 837
 
838 838
                 // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period
839
-                _x( 'Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ),
839
+                _x('Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing'),
840 840
                 $trial_period,
841 841
                 $recurring_price,
842 842
                 $period
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
         return sprintf(
849 849
 
850 850
             // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period
851
-            _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ),
851
+            _x('%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing'),
852 852
             $initial_price,
853 853
             $trial_period,
854 854
             $recurring_price,
@@ -858,12 +858,12 @@  discard block
 block discarded – undo
858 858
 
859 859
     }
860 860
 
861
-    if ( $initial_price == $recurring_price ) {
861
+    if ($initial_price == $recurring_price) {
862 862
 
863 863
         return sprintf(
864 864
 
865 865
             // translators: $1: is the recurring price, $2: is the susbcription period
866
-            _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ),
866
+            _x('%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing'),
867 867
             $recurring_price,
868 868
             $period
869 869
 
@@ -874,7 +874,7 @@  discard block
 block discarded – undo
874 874
     return sprintf(
875 875
 
876 876
         // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period
877
-        _x( 'Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ),
877
+        _x('Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing'),
878 878
         $initial_price,
879 879
         $recurring_price,
880 880
         $period
Please login to merge, or discard this patch.
includes/class-getpaid-checkout.php 2 patches
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -12,168 +12,168 @@  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
-		// Get the items and 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( $invoice );
43
-
44
-		// Save the invoice.
45
-		$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
+        // Get the items and 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( $invoice );
43
+
44
+        // Save the invoice.
45
+        $invoice->recalculate_total();
46 46
         $invoice->save();
47 47
 
48
-		// Send to the gateway.
49
-		$this->post_process_submission( $invoice, $prepared );
50
-	}
48
+        // Send to the gateway.
49
+        $this->post_process_submission( $invoice, $prepared );
50
+    }
51 51
 
52
-	/**
53
-	 * Validates the submission.
54
-	 *
55
-	 */
56
-	protected function validate_submission() {
52
+    /**
53
+     * Validates the submission.
54
+     *
55
+     */
56
+    protected function validate_submission() {
57 57
 
58
-		$submission = $this->payment_form_submission;
59
-		$data       = $submission->get_data();
58
+        $submission = $this->payment_form_submission;
59
+        $data       = $submission->get_data();
60 60
 
61
-		// Do we have an error?
61
+        // Do we have an error?
62 62
         if ( ! empty( $submission->last_error ) ) {
63
-			wp_send_json_error( $submission->last_error );
63
+            wp_send_json_error( $submission->last_error );
64 64
         }
65 65
 
66
-		// We need a billing email.
66
+        // We need a billing email.
67 67
         if ( ! $submission->has_billing_email() || ! is_email( $submission->get_billing_email() ) ) {
68 68
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
69
-		}
69
+        }
70 70
 
71
-		// Non-recurring gateways should not be allowed to process recurring invoices.
72
-		if ( $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
73
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payment.', 'invoicing' ) );
74
-		}
71
+        // Non-recurring gateways should not be allowed to process recurring invoices.
72
+        if ( $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
73
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payment.', 'invoicing' ) );
74
+        }
75 75
 	
76
-		// Ensure the gateway is active.
77
-		if ( ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
78
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
79
-		}
76
+        // Ensure the gateway is active.
77
+        if ( ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
78
+            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
79
+        }
80 80
 
81
-		// Clear any existing errors.
82
-		wpinv_clear_errors();
81
+        // Clear any existing errors.
82
+        wpinv_clear_errors();
83 83
 		
84
-		// Allow themes and plugins to hook to errors
85
-		do_action( 'getpaid_checkout_error_checks', $submission );
84
+        // Allow themes and plugins to hook to errors
85
+        do_action( 'getpaid_checkout_error_checks', $submission );
86 86
 		
87
-		// Do we have any errors?
87
+        // Do we have any errors?
88 88
         if ( wpinv_get_errors() ) {
89 89
             wp_send_json_error( getpaid_get_errors_html() );
90
-		}
90
+        }
91 91
 
92
-	}
92
+    }
93 93
 
94
-	/**
95
-	 * Retrieves submission items.
96
-	 *
97
-	 * @return GetPaid_Form_Item[]
98
-	 */
99
-	protected function get_submission_items() {
94
+    /**
95
+     * Retrieves submission items.
96
+     *
97
+     * @return GetPaid_Form_Item[]
98
+     */
99
+    protected function get_submission_items() {
100 100
 
101
-		$items = $this->payment_form_submission->get_items();
101
+        $items = $this->payment_form_submission->get_items();
102 102
 
103 103
         // Ensure that we have items.
104 104
         if ( empty( $items ) && 0 == count( $this->payment_form_submission->get_fees() ) ) {
105 105
             wp_send_json_error( __( 'Please select at least one item.', 'invoicing' ) );
106
-		}
106
+        }
107 107
 
108
-		return $items;
109
-	}
108
+        return $items;
109
+    }
110 110
 
111
-	/**
112
-	 * Retrieves submission invoice.
113
-	 *
114
-	 * @return WPInv_Invoice
115
-	 */
116
-	protected function get_submission_invoice() {
117
-		$submission = $this->payment_form_submission;
111
+    /**
112
+     * Retrieves submission invoice.
113
+     *
114
+     * @return WPInv_Invoice
115
+     */
116
+    protected function get_submission_invoice() {
117
+        $submission = $this->payment_form_submission;
118 118
 
119
-		if ( ! $submission->has_invoice() ) {
120
-			return new WPInv_Invoice();
119
+        if ( ! $submission->has_invoice() ) {
120
+            return new WPInv_Invoice();
121 121
         }
122 122
 
123
-		$invoice = $submission->get_invoice();
123
+        $invoice = $submission->get_invoice();
124 124
 
125
-		// Make sure that it is neither paid or refunded.
126
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
127
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
128
-		}
125
+        // Make sure that it is neither paid or refunded.
126
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
127
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
128
+        }
129 129
 
130
-		return $invoice;
131
-	}
130
+        return $invoice;
131
+    }
132 132
 
133
-	/**
134
-	 * Processes the submission invoice.
135
-	 *
136
-	 * @param WPInv_Invoice $invoice
137
-	 * @param GetPaid_Form_Item[] $items
138
-	 * @return WPInv_Invoice
139
-	 */
140
-	protected function process_submission_invoice( $invoice, $items ) {
133
+    /**
134
+     * Processes the submission invoice.
135
+     *
136
+     * @param WPInv_Invoice $invoice
137
+     * @param GetPaid_Form_Item[] $items
138
+     * @return WPInv_Invoice
139
+     */
140
+    protected function process_submission_invoice( $invoice, $items ) {
141 141
 
142
-		$submission = $this->payment_form_submission;
143
-		$data       = $submission->get_data();
142
+        $submission = $this->payment_form_submission;
143
+        $data       = $submission->get_data();
144 144
 
145
-		// Set-up the invoice details.
146
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
147
-		$invoice->set_user_id( $this->get_submission_customer() );
148
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
145
+        // Set-up the invoice details.
146
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
147
+        $invoice->set_user_id( $this->get_submission_customer() );
148
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
149 149
         $invoice->set_items( $items );
150 150
         $invoice->set_fees( $submission->get_fees() );
151 151
         $invoice->set_taxes( $submission->get_taxes() );
152
-		$invoice->set_discounts( $submission->get_discounts() );
153
-		$invoice->set_gateway( $data['wpi-gateway'] );
152
+        $invoice->set_discounts( $submission->get_discounts() );
153
+        $invoice->set_gateway( $data['wpi-gateway'] );
154 154
 
155
-		if ( $submission->has_discount_code() ) {
155
+        if ( $submission->has_discount_code() ) {
156 156
             $invoice->set_discount_code( $submission->get_discount_code() );
157
-		}
158
-
159
-		getpaid_maybe_add_default_address( $invoice );
160
-		return $invoice;
161
-	}
162
-
163
-	/**
164
-	 * Retrieves the submission's customer.
165
-	 *
166
-	 * @return int The customer id.
167
-	 */
168
-	protected function get_submission_customer() {
169
-		$submission = $this->payment_form_submission;
170
-
171
-		// If this is an existing invoice...
172
-		if ( $submission->has_invoice() ) {
173
-			return $submission->get_invoice()->get_user_id();
174
-		}
175
-
176
-		// (Maybe) create the user.
157
+        }
158
+
159
+        getpaid_maybe_add_default_address( $invoice );
160
+        return $invoice;
161
+    }
162
+
163
+    /**
164
+     * Retrieves the submission's customer.
165
+     *
166
+     * @return int The customer id.
167
+     */
168
+    protected function get_submission_customer() {
169
+        $submission = $this->payment_form_submission;
170
+
171
+        // If this is an existing invoice...
172
+        if ( $submission->has_invoice() ) {
173
+            return $submission->get_invoice()->get_user_id();
174
+        }
175
+
176
+        // (Maybe) create the user.
177 177
         $user = get_current_user_id();
178 178
 
179 179
         if ( empty( $user ) ) {
@@ -190,31 +190,31 @@  discard block
 block discarded – undo
190 190
 
191 191
         if ( is_numeric( $user ) ) {
192 192
             return $user;
193
-		}
193
+        }
194 194
 
195
-		return $user->ID;
195
+        return $user->ID;
196 196
 
197
-	}
197
+    }
198 198
 
199
-	/**
199
+    /**
200 200
      * Prepares submission data for saving to the database.
201 201
      *
202
-	 * @param WPInv_Invoice $invoice
202
+     * @param WPInv_Invoice $invoice
203 203
      */
204 204
     public function prepare_submission_data_for_saving( &$invoice ) {
205 205
 
206
-		$submission = $this->payment_form_submission;
206
+        $submission = $this->payment_form_submission;
207 207
 
208
-		// Prepared submission details.
208
+        // Prepared submission details.
209 209
         $prepared = array();
210 210
 
211 211
         // Raw submission details.
212
-		$data = $submission->get_data();
212
+        $data = $submission->get_data();
213 213
 		
214
-		// Loop throught the submitted details.
214
+        // Loop throught the submitted details.
215 215
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
216 216
 
217
-			// Skip premade fields.
217
+            // Skip premade fields.
218 218
             if ( ! empty( $field['premade'] ) ) {
219 219
                 continue;
220 220
             }
@@ -257,26 +257,26 @@  discard block
 block discarded – undo
257 257
                 $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] );
258 258
             }
259 259
 
260
-		}
260
+        }
261 261
 		
262
-		return $prepared;
262
+        return $prepared;
263 263
 
264
-	}
264
+    }
265 265
 
266
-	/**
267
-	 * Confirms the submission is valid and send users to the gateway.
268
-	 *
269
-	 * @param WPInv_Invoice $invoice
270
-	 * @param array $prepared_payment_form_data
271
-	 */
272
-	protected function post_process_submission( $invoice, $prepared_payment_form_data ) {
266
+    /**
267
+     * Confirms the submission is valid and send users to the gateway.
268
+     *
269
+     * @param WPInv_Invoice $invoice
270
+     * @param array $prepared_payment_form_data
271
+     */
272
+    protected function post_process_submission( $invoice, $prepared_payment_form_data ) {
273 273
 
274
-		// Ensure the invoice exists.
274
+        // Ensure the invoice exists.
275 275
         if ( $invoice->get_id() == 0 ) {
276 276
             wp_send_json_error( __( 'An error occured while saving your invoice.', 'invoicing' ) );
277 277
         }
278 278
 
279
-		// Was this invoice created via the payment form?
279
+        // Was this invoice created via the payment form?
280 280
         if ( ! $this->payment_form_submission->has_invoice() ) {
281 281
             update_post_meta( $invoice->get_id(), 'wpinv_created_via', 'payment_form' );
282 282
         }
@@ -284,66 +284,66 @@  discard block
 block discarded – undo
284 284
         // Save payment form data.
285 285
         if ( ! empty( $prepared_payment_form_data ) ) {
286 286
             update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
287
-		}
287
+        }
288 288
 
289
-		// Backwards compatibility.
289
+        // Backwards compatibility.
290 290
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
291
-		add_action( 'wpinv_pre_send_back_to_checkout', array( $this, 'checkout_error' ) );
291
+        add_action( 'wpinv_pre_send_back_to_checkout', array( $this, 'checkout_error' ) );
292 292
 
293
-		$this->process_payment( $invoice );
293
+        $this->process_payment( $invoice );
294 294
 
295 295
         // If we are here, there was an error.
296
-		$this->checkout_error();
296
+        $this->checkout_error();
297 297
 
298
-	}
298
+    }
299 299
 
300
-	/**
301
-	 * Processes the actual payment.
302
-	 *
303
-	 * @param WPInv_Invoice $invoice
304
-	 */
305
-	protected function process_payment( $invoice ) {
300
+    /**
301
+     * Processes the actual payment.
302
+     *
303
+     * @param WPInv_Invoice $invoice
304
+     */
305
+    protected function process_payment( $invoice ) {
306 306
 
307
-		$submission = $this->payment_form_submission;
307
+        $submission = $this->payment_form_submission;
308 308
 
309
-		// No need to send free invoices to the gateway.
310
-		if ( $invoice->is_free() ) {
311
-			$invoice->set_gateway( 'none' );
312
-			$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
313
-			$invoice->mark_paid();
314
-			wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
315
-		}
309
+        // No need to send free invoices to the gateway.
310
+        if ( $invoice->is_free() ) {
311
+            $invoice->set_gateway( 'none' );
312
+            $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
313
+            $invoice->mark_paid();
314
+            wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
315
+        }
316 316
 
317
-		// Clear any checkout errors.
318
-		wpinv_clear_errors();
317
+        // Clear any checkout errors.
318
+        wpinv_clear_errors();
319 319
 
320
-		// Fires before sending to the gateway.
321
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
320
+        // Fires before sending to the gateway.
321
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
322 322
 
323
-		// Allow the sumission data to be modified before it is sent to the gateway.
324
-		$submission_data    = $submission->get_data();
325
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
326
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
323
+        // Allow the sumission data to be modified before it is sent to the gateway.
324
+        $submission_data    = $submission->get_data();
325
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
326
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
327 327
 
328
-		// Validate the currency.
329
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
330
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) );
331
-		}
328
+        // Validate the currency.
329
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
330
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) );
331
+        }
332 332
 
333
-		// Check to see if we have any errors.
334
-		if ( wpinv_get_errors() ) {
335
-			wpinv_send_back_to_checkout();
336
-		}
333
+        // Check to see if we have any errors.
334
+        if ( wpinv_get_errors() ) {
335
+            wpinv_send_back_to_checkout();
336
+        }
337 337
 
338
-		// Send info to the gateway for payment processing
339
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
338
+        // Send info to the gateway for payment processing
339
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
340 340
 
341
-		// Backwards compatibility.
342
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
341
+        // Backwards compatibility.
342
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
343 343
 
344
-	}
344
+    }
345 345
 
346
-	/**
346
+    /**
347 347
      * Sends a redrect response to payment details.
348 348
      *
349 349
      */
@@ -361,10 +361,10 @@  discard block
 block discarded – undo
361 361
         // Do we have any errors?
362 362
         if ( wpinv_get_errors() ) {
363 363
             wp_send_json_error( getpaid_get_errors_html() );
364
-		}
364
+        }
365 365
 
366 366
         wp_send_json_error( __( 'An error occured while processing your payment. Please try again.', 'invoicing' ) );
367 367
 
368
-	}
368
+    }
369 369
 
370 370
 }
Please login to merge, or discard this patch.
Spacing   +87 added lines, -87 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,15 +38,15 @@  discard block
 block discarded – undo
38 38
 		// Get the items and invoice.
39 39
 		$items      = $this->get_submission_items();
40 40
 		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving( $invoice );
41
+		$invoice    = $this->process_submission_invoice($invoice, $items);
42
+		$prepared   = $this->prepare_submission_data_for_saving($invoice);
43 43
 
44 44
 		// Save the invoice.
45 45
 		$invoice->recalculate_total();
46 46
         $invoice->save();
47 47
 
48 48
 		// Send to the gateway.
49
-		$this->post_process_submission( $invoice, $prepared );
49
+		$this->post_process_submission($invoice, $prepared);
50 50
 	}
51 51
 
52 52
 	/**
@@ -59,34 +59,34 @@  discard block
 block discarded – undo
59 59
 		$data       = $submission->get_data();
60 60
 
61 61
 		// Do we have an error?
62
-        if ( ! empty( $submission->last_error ) ) {
63
-			wp_send_json_error( $submission->last_error );
62
+        if (!empty($submission->last_error)) {
63
+			wp_send_json_error($submission->last_error);
64 64
         }
65 65
 
66 66
 		// We need a billing email.
67
-        if ( ! $submission->has_billing_email() || ! is_email( $submission->get_billing_email() ) ) {
68
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
67
+        if (!$submission->has_billing_email() || !is_email($submission->get_billing_email())) {
68
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
69 69
 		}
70 70
 
71 71
 		// Non-recurring gateways should not be allowed to process recurring invoices.
72
-		if ( $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
73
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payment.', 'invoicing' ) );
72
+		if ($submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) {
73
+			wp_send_json_error(__('The selected payment gateway does not support subscription payment.', 'invoicing'));
74 74
 		}
75 75
 	
76 76
 		// Ensure the gateway is active.
77
-		if ( ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
78
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
77
+		if (!wpinv_is_gateway_active($data['wpi-gateway'])) {
78
+			wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing'));
79 79
 		}
80 80
 
81 81
 		// Clear any existing errors.
82 82
 		wpinv_clear_errors();
83 83
 		
84 84
 		// Allow themes and plugins to hook to errors
85
-		do_action( 'getpaid_checkout_error_checks', $submission );
85
+		do_action('getpaid_checkout_error_checks', $submission);
86 86
 		
87 87
 		// Do we have any errors?
88
-        if ( wpinv_get_errors() ) {
89
-            wp_send_json_error( getpaid_get_errors_html() );
88
+        if (wpinv_get_errors()) {
89
+            wp_send_json_error(getpaid_get_errors_html());
90 90
 		}
91 91
 
92 92
 	}
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 		$items = $this->payment_form_submission->get_items();
102 102
 
103 103
         // Ensure that we have items.
104
-        if ( empty( $items ) && 0 == count( $this->payment_form_submission->get_fees() ) ) {
105
-            wp_send_json_error( __( 'Please select at least one item.', 'invoicing' ) );
104
+        if (empty($items) && 0 == count($this->payment_form_submission->get_fees())) {
105
+            wp_send_json_error(__('Please select at least one item.', 'invoicing'));
106 106
 		}
107 107
 
108 108
 		return $items;
@@ -116,15 +116,15 @@  discard block
 block discarded – undo
116 116
 	protected function get_submission_invoice() {
117 117
 		$submission = $this->payment_form_submission;
118 118
 
119
-		if ( ! $submission->has_invoice() ) {
119
+		if (!$submission->has_invoice()) {
120 120
 			return new WPInv_Invoice();
121 121
         }
122 122
 
123 123
 		$invoice = $submission->get_invoice();
124 124
 
125 125
 		// Make sure that it is neither paid or refunded.
126
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
127
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
126
+		if ($invoice->is_paid() || $invoice->is_refunded()) {
127
+			wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
128 128
 		}
129 129
 
130 130
 		return $invoice;
@@ -137,26 +137,26 @@  discard block
 block discarded – undo
137 137
 	 * @param GetPaid_Form_Item[] $items
138 138
 	 * @return WPInv_Invoice
139 139
 	 */
140
-	protected function process_submission_invoice( $invoice, $items ) {
140
+	protected function process_submission_invoice($invoice, $items) {
141 141
 
142 142
 		$submission = $this->payment_form_submission;
143 143
 		$data       = $submission->get_data();
144 144
 
145 145
 		// Set-up the invoice details.
146
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
147
-		$invoice->set_user_id( $this->get_submission_customer() );
148
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
149
-        $invoice->set_items( $items );
150
-        $invoice->set_fees( $submission->get_fees() );
151
-        $invoice->set_taxes( $submission->get_taxes() );
152
-		$invoice->set_discounts( $submission->get_discounts() );
153
-		$invoice->set_gateway( $data['wpi-gateway'] );
154
-
155
-		if ( $submission->has_discount_code() ) {
156
-            $invoice->set_discount_code( $submission->get_discount_code() );
146
+		$invoice->set_email(sanitize_email($submission->get_billing_email()));
147
+		$invoice->set_user_id($this->get_submission_customer());
148
+		$invoice->set_payment_form(absint($submission->get_payment_form()->get_id()));
149
+        $invoice->set_items($items);
150
+        $invoice->set_fees($submission->get_fees());
151
+        $invoice->set_taxes($submission->get_taxes());
152
+		$invoice->set_discounts($submission->get_discounts());
153
+		$invoice->set_gateway($data['wpi-gateway']);
154
+
155
+		if ($submission->has_discount_code()) {
156
+            $invoice->set_discount_code($submission->get_discount_code());
157 157
 		}
158 158
 
159
-		getpaid_maybe_add_default_address( $invoice );
159
+		getpaid_maybe_add_default_address($invoice);
160 160
 		return $invoice;
161 161
 	}
162 162
 
@@ -169,26 +169,26 @@  discard block
 block discarded – undo
169 169
 		$submission = $this->payment_form_submission;
170 170
 
171 171
 		// If this is an existing invoice...
172
-		if ( $submission->has_invoice() ) {
172
+		if ($submission->has_invoice()) {
173 173
 			return $submission->get_invoice()->get_user_id();
174 174
 		}
175 175
 
176 176
 		// (Maybe) create the user.
177 177
         $user = get_current_user_id();
178 178
 
179
-        if ( empty( $user ) ) {
180
-            $user = get_user_by( 'email', $submission->get_billing_email() );
179
+        if (empty($user)) {
180
+            $user = get_user_by('email', $submission->get_billing_email());
181 181
         }
182 182
 
183
-        if ( empty( $user ) ) {
184
-            $user = wpinv_create_user( $submission->get_billing_email() );
183
+        if (empty($user)) {
184
+            $user = wpinv_create_user($submission->get_billing_email());
185 185
         }
186 186
 
187
-        if ( is_wp_error( $user ) ) {
188
-            wp_send_json_error( $user->get_error_message() );
187
+        if (is_wp_error($user)) {
188
+            wp_send_json_error($user->get_error_message());
189 189
         }
190 190
 
191
-        if ( is_numeric( $user ) ) {
191
+        if (is_numeric($user)) {
192 192
             return $user;
193 193
 		}
194 194
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
      *
202 202
 	 * @param WPInv_Invoice $invoice
203 203
      */
204
-    public function prepare_submission_data_for_saving( &$invoice ) {
204
+    public function prepare_submission_data_for_saving(&$invoice) {
205 205
 
206 206
 		$submission = $this->payment_form_submission;
207 207
 
@@ -212,49 +212,49 @@  discard block
 block discarded – undo
212 212
 		$data = $submission->get_data();
213 213
 		
214 214
 		// Loop throught the submitted details.
215
-        foreach ( $submission->get_payment_form()->get_elements() as $field ) {
215
+        foreach ($submission->get_payment_form()->get_elements() as $field) {
216 216
 
217 217
 			// Skip premade fields.
218
-            if ( ! empty( $field['premade'] ) ) {
218
+            if (!empty($field['premade'])) {
219 219
                 continue;
220 220
             }
221 221
 
222 222
             // If it is required and not set, abort.
223
-            if ( ! $submission->is_required_field_set( $field ) ) {
224
-                wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) );
223
+            if (!$submission->is_required_field_set($field)) {
224
+                wp_send_json_error(__('Some required fields are not set.', 'invoicing'));
225 225
             }
226 226
 
227 227
             // Handle address fields.
228
-            if ( $field['type'] == 'address' ) {
228
+            if ($field['type'] == 'address') {
229 229
 
230
-                foreach ( $field['fields'] as $address_field ) {
230
+                foreach ($field['fields'] as $address_field) {
231 231
 
232 232
                     // skip if it is not visible.
233
-                    if ( empty( $address_field['visible'] ) ) {
233
+                    if (empty($address_field['visible'])) {
234 234
                         continue;
235 235
                     }
236 236
 
237 237
                     // If it is required and not set, abort
238
-                    if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) {
239
-                        wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) );
238
+                    if (!empty($address_field['required']) && empty($data[$address_field['name']])) {
239
+                        wp_send_json_error(__('Some required fields are not set.', 'invoicing'));
240 240
                     }
241 241
 
242
-                    if ( isset( $data[ $address_field['name'] ] ) ) {
243
-                        $name   = str_replace( 'wpinv_', '', $address_field['name'] );
242
+                    if (isset($data[$address_field['name']])) {
243
+                        $name   = str_replace('wpinv_', '', $address_field['name']);
244 244
                         $method = "set_$name";
245
-                        $invoice->$method( wpinv_clean( $data[ $address_field['name'] ] ) );
245
+                        $invoice->$method(wpinv_clean($data[$address_field['name']]));
246 246
                     }
247 247
 
248 248
                 }
249 249
 
250
-            } else if ( isset( $data[ $field['id'] ] ) ) {
250
+            } else if (isset($data[$field['id']])) {
251 251
                 $label = $field['id'];
252 252
 
253
-                if ( isset( $field['label'] ) ) {
253
+                if (isset($field['label'])) {
254 254
                     $label = $field['label'];
255 255
                 }
256 256
 
257
-                $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] );
257
+                $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]);
258 258
             }
259 259
 
260 260
 		}
@@ -269,28 +269,28 @@  discard block
 block discarded – undo
269 269
 	 * @param WPInv_Invoice $invoice
270 270
 	 * @param array $prepared_payment_form_data
271 271
 	 */
272
-	protected function post_process_submission( $invoice, $prepared_payment_form_data ) {
272
+	protected function post_process_submission($invoice, $prepared_payment_form_data) {
273 273
 
274 274
 		// Ensure the invoice exists.
275
-        if ( $invoice->get_id() == 0 ) {
276
-            wp_send_json_error( __( 'An error occured while saving your invoice.', 'invoicing' ) );
275
+        if ($invoice->get_id() == 0) {
276
+            wp_send_json_error(__('An error occured while saving your invoice.', 'invoicing'));
277 277
         }
278 278
 
279 279
 		// Was this invoice created via the payment form?
280
-        if ( ! $this->payment_form_submission->has_invoice() ) {
281
-            update_post_meta( $invoice->get_id(), 'wpinv_created_via', 'payment_form' );
280
+        if (!$this->payment_form_submission->has_invoice()) {
281
+            update_post_meta($invoice->get_id(), 'wpinv_created_via', 'payment_form');
282 282
         }
283 283
 
284 284
         // Save payment form data.
285
-        if ( ! empty( $prepared_payment_form_data ) ) {
286
-            update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
285
+        if (!empty($prepared_payment_form_data)) {
286
+            update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data);
287 287
 		}
288 288
 
289 289
 		// Backwards compatibility.
290
-        add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
291
-		add_action( 'wpinv_pre_send_back_to_checkout', array( $this, 'checkout_error' ) );
290
+        add_filter('wp_redirect', array($this, 'send_redirect_response'));
291
+		add_action('wpinv_pre_send_back_to_checkout', array($this, 'checkout_error'));
292 292
 
293
-		$this->process_payment( $invoice );
293
+		$this->process_payment($invoice);
294 294
 
295 295
         // If we are here, there was an error.
296 296
 		$this->checkout_error();
@@ -302,44 +302,44 @@  discard block
 block discarded – undo
302 302
 	 *
303 303
 	 * @param WPInv_Invoice $invoice
304 304
 	 */
305
-	protected function process_payment( $invoice ) {
305
+	protected function process_payment($invoice) {
306 306
 
307 307
 		$submission = $this->payment_form_submission;
308 308
 
309 309
 		// No need to send free invoices to the gateway.
310
-		if ( $invoice->is_free() ) {
311
-			$invoice->set_gateway( 'none' );
312
-			$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
310
+		if ($invoice->is_free()) {
311
+			$invoice->set_gateway('none');
312
+			$invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true);
313 313
 			$invoice->mark_paid();
314
-			wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
314
+			wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
315 315
 		}
316 316
 
317 317
 		// Clear any checkout errors.
318 318
 		wpinv_clear_errors();
319 319
 
320 320
 		// Fires before sending to the gateway.
321
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
321
+		do_action('getpaid_checkout_before_gateway', $invoice, $submission);
322 322
 
323 323
 		// Allow the sumission data to be modified before it is sent to the gateway.
324 324
 		$submission_data    = $submission->get_data();
325
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
326
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
325
+		$submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice);
326
+		$submission_data    = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice);
327 327
 
328 328
 		// Validate the currency.
329
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
330
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) );
329
+		if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) {
330
+			wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support the invoice currency', 'invoicing'));
331 331
 		}
332 332
 
333 333
 		// Check to see if we have any errors.
334
-		if ( wpinv_get_errors() ) {
334
+		if (wpinv_get_errors()) {
335 335
 			wpinv_send_back_to_checkout();
336 336
 		}
337 337
 
338 338
 		// Send info to the gateway for payment processing
339
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
339
+		do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission);
340 340
 
341 341
 		// Backwards compatibility.
342
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
342
+		wpinv_send_to_gateway($submission_gateway, $invoice);
343 343
 
344 344
 	}
345 345
 
@@ -347,9 +347,9 @@  discard block
 block discarded – undo
347 347
      * Sends a redrect response to payment details.
348 348
      *
349 349
      */
350
-    public function send_redirect_response( $url ) {
351
-        $url = urlencode( $url );
352
-        wp_send_json_success( $url );
350
+    public function send_redirect_response($url) {
351
+        $url = urlencode($url);
352
+        wp_send_json_success($url);
353 353
     }
354 354
 
355 355
     /**
@@ -359,11 +359,11 @@  discard block
 block discarded – undo
359 359
     public function checkout_error() {
360 360
 
361 361
         // Do we have any errors?
362
-        if ( wpinv_get_errors() ) {
363
-            wp_send_json_error( getpaid_get_errors_html() );
362
+        if (wpinv_get_errors()) {
363
+            wp_send_json_error(getpaid_get_errors_html());
364 364
 		}
365 365
 
366
-        wp_send_json_error( __( 'An error occured while processing your payment. Please try again.', 'invoicing' ) );
366
+        wp_send_json_error(__('An error occured while processing your payment. Please try again.', 'invoicing'));
367 367
 
368 368
 	}
369 369
 
Please login to merge, or discard this patch.