Completed
Push — master ( c72cea...2f3eab )
by Stiofan
18s
created
includes/class-wpinv-reports.php 1 patch
Spacing   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -21,68 +21,68 @@  discard block
 block discarded – undo
21 21
     public function init() {
22 22
         global $wp_filesystem;
23 23
 
24
-        if ( empty( $wp_filesystem ) ) {
25
-            require_once( ABSPATH . '/wp-admin/includes/file.php' );
24
+        if (empty($wp_filesystem)) {
25
+            require_once(ABSPATH . '/wp-admin/includes/file.php');
26 26
             WP_Filesystem();
27 27
             global $wp_filesystem;
28 28
         }
29 29
         $this->wp_filesystem    = $wp_filesystem;
30 30
         
31 31
         $this->export_dir       = $this->export_location();
32
-        $this->export_url       = $this->export_location( true );
32
+        $this->export_url       = $this->export_location(true);
33 33
         $this->export           = 'invoicing';
34 34
         $this->filetype         = 'csv';
35 35
         $this->per_page         = 20;
36 36
         
37
-        do_action( 'wpinv_class_reports_init', $this );
37
+        do_action('wpinv_class_reports_init', $this);
38 38
     }
39 39
     
40 40
     public function includes() {
41
-        do_action( 'wpinv_class_reports_includes', $this );
41
+        do_action('wpinv_class_reports_includes', $this);
42 42
     }
43 43
     
44 44
     public function actions() {
45
-        if ( is_admin() ) {
46
-            add_action( 'admin_menu', array( $this, 'add_submenu' ), 10 );
47
-            add_action( 'wpinv_reports_tab_export', array( $this, 'export' ) );
48
-            add_action( 'wp_ajax_wpinv_ajax_export', array( $this, 'ajax_export' ) );
45
+        if (is_admin()) {
46
+            add_action('admin_menu', array($this, 'add_submenu'), 10);
47
+            add_action('wpinv_reports_tab_export', array($this, 'export'));
48
+            add_action('wp_ajax_wpinv_ajax_export', array($this, 'ajax_export'));
49 49
             
50 50
             // Export Invoices.
51
-            add_action( 'wpinv_export_set_params_invoices', array( $this, 'set_invoices_export' ) );
52
-            add_filter( 'wpinv_export_get_columns_invoices', array( $this, 'get_invoices_columns' ) );
53
-            add_filter( 'wpinv_export_get_data_invoices', array( $this, 'get_invoices_data' ) );
54
-            add_filter( 'wpinv_get_export_status_invoices', array( $this, 'invoices_export_status' ) );
51
+            add_action('wpinv_export_set_params_invoices', array($this, 'set_invoices_export'));
52
+            add_filter('wpinv_export_get_columns_invoices', array($this, 'get_invoices_columns'));
53
+            add_filter('wpinv_export_get_data_invoices', array($this, 'get_invoices_data'));
54
+            add_filter('wpinv_get_export_status_invoices', array($this, 'invoices_export_status'));
55 55
         }
56
-        do_action( 'wpinv_class_reports_actions', $this );
56
+        do_action('wpinv_class_reports_actions', $this);
57 57
     }
58 58
     
59 59
     public function add_submenu() {
60 60
         global $wpi_reports_page;
61
-        $wpi_reports_page = add_submenu_page( 'wpinv', __( 'Reports', 'invoicing' ), __( 'Reports', 'invoicing' ), 'manage_options', 'wpinv-reports', array( $this, 'reports_page' ) );
61
+        $wpi_reports_page = add_submenu_page('wpinv', __('Reports', 'invoicing'), __('Reports', 'invoicing'), 'manage_options', 'wpinv-reports', array($this, 'reports_page'));
62 62
     }
63 63
     
64 64
     public function reports_page() {
65
-        if ( !wp_script_is( 'postbox', 'enqueued' ) ) {
66
-            wp_enqueue_script( 'postbox' );
65
+        if (!wp_script_is('postbox', 'enqueued')) {
66
+            wp_enqueue_script('postbox');
67 67
         }
68
-        if ( !wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) {
69
-            wp_enqueue_script( 'jquery-ui-datepicker' );
68
+        if (!wp_script_is('jquery-ui-datepicker', 'enqueued')) {
69
+            wp_enqueue_script('jquery-ui-datepicker');
70 70
         }
71 71
         
72
-        $current_page = admin_url( 'admin.php?page=wpinv-reports' );
73
-        $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'export';
72
+        $current_page = admin_url('admin.php?page=wpinv-reports');
73
+        $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'export';
74 74
         ?>
75 75
         <div class="wrap wpi-reports-wrap">
76
-            <h1><?php echo esc_html( __( 'Reports', 'invoicing' ) ); ?></h1>
76
+            <h1><?php echo esc_html(__('Reports', 'invoicing')); ?></h1>
77 77
             <h2 class="nav-tab-wrapper wp-clearfix">
78
-                <a href="<?php echo add_query_arg( array( 'tab' => 'export', 'settings-updated' => false ), $current_page ); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Export', 'invoicing' ); ?></a>
79
-                <?php do_action( 'wpinv_reports_page_tabs' ); ;?>
78
+                <a href="<?php echo add_query_arg(array('tab' => 'export', 'settings-updated' => false), $current_page); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e('Export', 'invoicing'); ?></a>
79
+                <?php do_action('wpinv_reports_page_tabs'); ;?>
80 80
             </h2>
81 81
             <div class="wpi-reports-content wpi-reports-<?php echo $active_tab; ?>">
82 82
             <?php
83
-                do_action( 'wpinv_reports_page_top' );
84
-                do_action( 'wpinv_reports_tab_' . $active_tab );
85
-                do_action( 'wpinv_reports_page_bottom' );
83
+                do_action('wpinv_reports_page_top');
84
+                do_action('wpinv_reports_tab_' . $active_tab);
85
+                do_action('wpinv_reports_page_bottom');
86 86
             ?>
87 87
         </div>
88 88
         <?php
@@ -90,97 +90,97 @@  discard block
 block discarded – undo
90 90
     
91 91
     public function export() {
92 92
         $statuses = wpinv_get_invoice_statuses();
93
-        $statuses = array_merge( array( 'any' => __( 'All Statuses', 'invoicing' ) ), $statuses );
93
+        $statuses = array_merge(array('any' => __('All Statuses', 'invoicing')), $statuses);
94 94
         ?>
95 95
         <div class="metabox-holder">
96 96
             <div id="post-body">
97 97
                 <div id="post-body-content">
98
-                    <?php do_action( 'wpinv_reports_tab_export_content_top' ); ?>
98
+                    <?php do_action('wpinv_reports_tab_export_content_top'); ?>
99 99
                     
100 100
                     <div class="postbox wpi-export-invoices">
101
-                        <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Invoices','invoicing' ); ?></span></h2>
101
+                        <h2 class="hndle ui-sortabled-handle"><span><?php _e('Invoices', 'invoicing'); ?></span></h2>
102 102
                         <div class="inside">
103
-                            <p><?php _e( 'Download a CSV of all payment invoices.', 'invoicing' ); ?></p>
103
+                            <p><?php _e('Download a CSV of all payment invoices.', 'invoicing'); ?></p>
104 104
                             <form id="wpi-export-invoices" class="wpi-export-form" method="post">
105
-                                <?php echo wpinv_html_date_field( array( 
105
+                                <?php echo wpinv_html_date_field(array( 
106 106
                                     'id' => 'wpi_export_from_date', 
107 107
                                     'name' => 'from_date',
108 108
                                     'data' => array(
109 109
                                         'dateFormat' => 'yy-mm-dd'
110 110
                                     ),
111
-                                    'placeholder' => __( 'From date', 'invoicing' ) )
111
+                                    'placeholder' => __('From date', 'invoicing') )
112 112
                                 ); ?>
113
-                                <?php echo wpinv_html_date_field( array( 
113
+                                <?php echo wpinv_html_date_field(array( 
114 114
                                     'id' => 'wpi_export_to_date',
115 115
                                     'name' => 'to_date',
116 116
                                     'data' => array(
117 117
                                         'dateFormat' => 'yy-mm-dd'
118 118
                                     ),
119
-                                    'placeholder' => __( 'To date', 'invoicing' ) )
119
+                                    'placeholder' => __('To date', 'invoicing') )
120 120
                                 ); ?>
121 121
                                 <span id="wpinv-status-wrap">
122
-                                <?php echo wpinv_html_select( array(
122
+                                <?php echo wpinv_html_select(array(
123 123
                                     'options'          => $statuses,
124 124
                                     'name'             => 'status',
125 125
                                     'id'               => 'wpi_export_status',
126 126
                                     'show_option_all'  => false,
127 127
                                     'show_option_none' => false,
128 128
                                     'class'            => '',
129
-                                ) ); ?>
130
-                                <?php wp_nonce_field( 'wpi_ajax_export', 'wpi_ajax_export' ); ?>
129
+                                )); ?>
130
+                                <?php wp_nonce_field('wpi_ajax_export', 'wpi_ajax_export'); ?>
131 131
                                 </span>
132 132
                                 <span id="wpinv-submit-wrap">
133 133
                                     <input type="hidden" value="invoices" name="export" />
134
-                                    <input type="submit" value="<?php _e( 'Generate CSV', 'invoicing' ); ?>" class="button-primary" />
134
+                                    <input type="submit" value="<?php _e('Generate CSV', 'invoicing'); ?>" class="button-primary" />
135 135
                                 </span>
136 136
                             </form>
137 137
                         </div>
138 138
                     </div>
139 139
                     
140
-                    <?php do_action( 'wpinv_reports_tab_export_content_bottom' ); ?>
140
+                    <?php do_action('wpinv_reports_tab_export_content_bottom'); ?>
141 141
                 </div>
142 142
             </div>
143 143
         </div>
144 144
         <?php
145 145
     }
146 146
     
147
-    public function export_location( $relative = false ) {
147
+    public function export_location($relative = false) {
148 148
         $upload_dir         = wp_upload_dir();
149
-        $export_location    = $relative ? trailingslashit( $upload_dir['baseurl'] ) . 'cache' : trailingslashit( $upload_dir['basedir'] ) . 'cache';
150
-        $export_location    = apply_filters( 'wpinv_export_location', $export_location, $relative );
149
+        $export_location    = $relative ? trailingslashit($upload_dir['baseurl']) . 'cache' : trailingslashit($upload_dir['basedir']) . 'cache';
150
+        $export_location    = apply_filters('wpinv_export_location', $export_location, $relative);
151 151
         
152
-        return trailingslashit( $export_location );
152
+        return trailingslashit($export_location);
153 153
     }
154 154
     
155 155
     public function check_export_location() {
156 156
         try {
157
-            if ( empty( $this->wp_filesystem ) ) {
158
-                return __( 'Filesystem ERROR: Could not access filesystem.', 'invoicing' );
157
+            if (empty($this->wp_filesystem)) {
158
+                return __('Filesystem ERROR: Could not access filesystem.', 'invoicing');
159 159
             }
160 160
 
161
-            if ( is_wp_error( $this->wp_filesystem ) ) {
162
-                return __( 'Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing' );
161
+            if (is_wp_error($this->wp_filesystem)) {
162
+                return __('Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing');
163 163
             }
164 164
         
165
-            $is_dir         = $this->wp_filesystem->is_dir( $this->export_dir );
166
-            $is_writeable   = $is_dir && is_writeable( $this->export_dir );
165
+            $is_dir         = $this->wp_filesystem->is_dir($this->export_dir);
166
+            $is_writeable   = $is_dir && is_writeable($this->export_dir);
167 167
             
168
-            if ( $is_dir && $is_writeable ) {
168
+            if ($is_dir && $is_writeable) {
169 169
                return true;
170
-            } else if ( $is_dir && !$is_writeable ) {
171
-               if ( !$this->wp_filesystem->chmod( $this->export_dir, FS_CHMOD_DIR ) ) {
172
-                   return wp_sprintf( __( 'Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing' ), $this->export_dir );
170
+            } else if ($is_dir && !$is_writeable) {
171
+               if (!$this->wp_filesystem->chmod($this->export_dir, FS_CHMOD_DIR)) {
172
+                   return wp_sprintf(__('Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing'), $this->export_dir);
173 173
                }
174 174
                
175 175
                return true;
176 176
             } else {
177
-                if ( !$this->wp_filesystem->mkdir( $this->export_dir, FS_CHMOD_DIR ) ) {
178
-                    return wp_sprintf( __( 'Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing' ), $this->export_dir );
177
+                if (!$this->wp_filesystem->mkdir($this->export_dir, FS_CHMOD_DIR)) {
178
+                    return wp_sprintf(__('Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing'), $this->export_dir);
179 179
                 }
180 180
                 
181 181
                 return true;
182 182
             }
183
-        } catch ( Exception $e ) {
183
+        } catch (Exception $e) {
184 184
             return $e->getMessage();
185 185
         }
186 186
     }
@@ -188,130 +188,130 @@  discard block
 block discarded – undo
188 188
     public function ajax_export() {
189 189
         $response               = array();
190 190
         $response['success']    = false;
191
-        $response['msg']        = __( 'Invalid export request found.', 'invoicing' );
191
+        $response['msg']        = __('Invalid export request found.', 'invoicing');
192 192
         
193
-        if ( empty( $_POST['data'] ) || !current_user_can( 'manage_options' ) ) {
194
-            wp_send_json( $response );
193
+        if (empty($_POST['data']) || !current_user_can('manage_options')) {
194
+            wp_send_json($response);
195 195
         }
196 196
 
197
-        parse_str( $_POST['data'], $data );
197
+        parse_str($_POST['data'], $data);
198 198
         
199
-        $data['step']   = !empty( $_POST['step'] ) ? absint( $_POST['step'] ) : 1;
199
+        $data['step'] = !empty($_POST['step']) ? absint($_POST['step']) : 1;
200 200
 
201 201
         $_REQUEST = (array)$data;
202
-        if ( !( !empty( $_REQUEST['wpi_ajax_export'] ) && wp_verify_nonce( $_REQUEST['wpi_ajax_export'], 'wpi_ajax_export' ) ) ) {
203
-            $response['msg']    = __( 'Security check failed.', 'invoicing' );
204
-            wp_send_json( $response );
202
+        if (!(!empty($_REQUEST['wpi_ajax_export']) && wp_verify_nonce($_REQUEST['wpi_ajax_export'], 'wpi_ajax_export'))) {
203
+            $response['msg'] = __('Security check failed.', 'invoicing');
204
+            wp_send_json($response);
205 205
         }
206 206
         
207
-        if ( ( $error = $this->check_export_location( true ) ) !== true ) {
208
-            $response['msg'] = __( 'Filesystem ERROR: ' . $error, 'invoicing' );
209
-            wp_send_json( $response );
207
+        if (($error = $this->check_export_location(true)) !== true) {
208
+            $response['msg'] = __('Filesystem ERROR: ' . $error, 'invoicing');
209
+            wp_send_json($response);
210 210
         }
211 211
                         
212
-        $this->set_export_params( $_REQUEST );
212
+        $this->set_export_params($_REQUEST);
213 213
         
214 214
         $return = $this->process_export_step();
215 215
         $done   = $this->get_export_status();
216 216
         
217
-        if ( $return ) {
217
+        if ($return) {
218 218
             $this->step += 1;
219 219
             
220 220
             $response['success']    = true;
221 221
             $response['msg']        = '';
222 222
             
223
-            if ( $done >= 100 ) {
223
+            if ($done >= 100) {
224 224
                 $this->step     = 'done';
225
-                $new_filename   = 'wpi-' . $this->export . '-' . date( 'y-m-d-H-i' ) . '.' . $this->filetype;
225
+                $new_filename   = 'wpi-' . $this->export . '-' . date('y-m-d-H-i') . '.' . $this->filetype;
226 226
                 $new_file       = $this->export_dir . $new_filename;
227 227
                 
228
-                if ( file_exists( $this->file ) ) {
229
-                    $this->wp_filesystem->move( $this->file, $new_file, true );
228
+                if (file_exists($this->file)) {
229
+                    $this->wp_filesystem->move($this->file, $new_file, true);
230 230
                 }
231 231
                 
232
-                if ( file_exists( $new_file ) ) {
233
-                    $response['data']['file'] = array( 'u' => $this->export_url . $new_filename, 's' => size_format( filesize( $new_file ), 2 ) );
232
+                if (file_exists($new_file)) {
233
+                    $response['data']['file'] = array('u' => $this->export_url . $new_filename, 's' => size_format(filesize($new_file), 2));
234 234
                 }
235 235
             }
236 236
             
237 237
             $response['data']['step']   = $this->step;
238 238
             $response['data']['done']   = $done;
239 239
         } else {
240
-            $response['msg']    = __( 'No data found for export.', 'invoicing' );
240
+            $response['msg'] = __('No data found for export.', 'invoicing');
241 241
         }
242 242
 
243
-        wp_send_json( $response );
243
+        wp_send_json($response);
244 244
     }
245 245
     
246
-    public function set_export_params( $request ) {
246
+    public function set_export_params($request) {
247 247
         $this->empty    = false;
248
-        $this->step     = !empty( $request['step'] ) ? absint( $request['step'] ) : 1;
249
-        $this->export   = !empty( $request['export'] ) ? $request['export'] : $this->export;
248
+        $this->step     = !empty($request['step']) ? absint($request['step']) : 1;
249
+        $this->export   = !empty($request['export']) ? $request['export'] : $this->export;
250 250
         $this->filename = 'wpi-' . $this->export . '-' . $request['wpi_ajax_export'] . '.' . $this->filetype;
251 251
         $this->file     = $this->export_dir . $this->filename;
252 252
         
253
-        do_action( 'wpinv_export_set_params_' . $this->export, $request );
253
+        do_action('wpinv_export_set_params_' . $this->export, $request);
254 254
     }
255 255
     
256 256
     public function get_columns() {
257 257
         $columns = array(
258
-            'id'   => __( 'ID',   'invoicing' ),
259
-            'date' => __( 'Date', 'invoicing' )
258
+            'id'   => __('ID', 'invoicing'),
259
+            'date' => __('Date', 'invoicing')
260 260
         );
261 261
         
262
-        return apply_filters( 'wpinv_export_get_columns_' . $this->export, $columns );
262
+        return apply_filters('wpinv_export_get_columns_' . $this->export, $columns);
263 263
     }
264 264
     
265 265
     protected function get_export_file() {
266 266
         $file = '';
267 267
 
268
-        if ( $this->wp_filesystem->exists( $this->file ) ) {
269
-            $file = $this->wp_filesystem->get_contents( $this->file );
268
+        if ($this->wp_filesystem->exists($this->file)) {
269
+            $file = $this->wp_filesystem->get_contents($this->file);
270 270
         } else {
271
-            $this->wp_filesystem->put_contents( $this->file, '' );
271
+            $this->wp_filesystem->put_contents($this->file, '');
272 272
         }
273 273
 
274 274
         return $file;
275 275
     }
276 276
     
277
-    protected function attach_export_data( $data = '' ) {
278
-        $filedata   = $this->get_export_file();
279
-        $filedata   .= $data;
277
+    protected function attach_export_data($data = '') {
278
+        $filedata = $this->get_export_file();
279
+        $filedata .= $data;
280 280
         
281
-        $this->wp_filesystem->put_contents( $this->file, $filedata );
281
+        $this->wp_filesystem->put_contents($this->file, $filedata);
282 282
 
283
-        $rows       = file( $this->file, FILE_SKIP_EMPTY_LINES );
283
+        $rows       = file($this->file, FILE_SKIP_EMPTY_LINES);
284 284
         $columns    = $this->get_columns();
285
-        $columns    = empty( $columns ) ? 0 : 1;
285
+        $columns    = empty($columns) ? 0 : 1;
286 286
 
287
-        $this->empty = count( $rows ) == $columns ? true : false;
287
+        $this->empty = count($rows) == $columns ? true : false;
288 288
     }
289 289
     
290 290
     public function print_columns() {
291 291
         $column_data    = '';
292 292
         $columns        = $this->get_columns();
293 293
         $i              = 1;
294
-        foreach( $columns as $key => $column ) {
295
-            $column_data .= '"' . addslashes( $column ) . '"';
296
-            $column_data .= $i == count( $columns ) ? '' : ',';
294
+        foreach ($columns as $key => $column) {
295
+            $column_data .= '"' . addslashes($column) . '"';
296
+            $column_data .= $i == count($columns) ? '' : ',';
297 297
             $i++;
298 298
         }
299 299
         $column_data .= "\r\n";
300 300
 
301
-        $this->attach_export_data( $column_data );
301
+        $this->attach_export_data($column_data);
302 302
 
303 303
         return $column_data;
304 304
     }
305 305
     
306 306
     public function process_export_step() {
307
-        if ( $this->step < 2 ) {
308
-            @unlink( $this->file );
307
+        if ($this->step < 2) {
308
+            @unlink($this->file);
309 309
             $this->print_columns();
310 310
         }
311 311
         
312 312
         $return = $this->print_rows();
313 313
         
314
-        if ( $return ) {
314
+        if ($return) {
315 315
             return true;
316 316
         } else {
317 317
             return false;
@@ -320,23 +320,23 @@  discard block
 block discarded – undo
320 320
     
321 321
     public function get_export_status() {
322 322
         $status = 100;
323
-        return apply_filters( 'wpinv_get_export_status_' . $this->export, $status );
323
+        return apply_filters('wpinv_get_export_status_' . $this->export, $status);
324 324
     }
325 325
     
326 326
     public function get_export_data() {
327 327
         $data = array(
328 328
             0 => array(
329 329
                 'id'   => '',
330
-                'data' => date( 'F j, Y' )
330
+                'data' => date('F j, Y')
331 331
             ),
332 332
             1 => array(
333 333
                 'id'   => '',
334
-                'data' => date( 'F j, Y' )
334
+                'data' => date('F j, Y')
335 335
             )
336 336
         );
337 337
 
338
-        $data = apply_filters( 'wpinv_export_get_data', $data );
339
-        $data = apply_filters( 'wpinv_export_get_data_' . $this->export, $data );
338
+        $data = apply_filters('wpinv_export_get_data', $data);
339
+        $data = apply_filters('wpinv_export_get_data_' . $this->export, $data);
340 340
 
341 341
         return $data;
342 342
     }
@@ -346,20 +346,20 @@  discard block
 block discarded – undo
346 346
         $data       = $this->get_export_data();
347 347
         $columns    = $this->get_columns();
348 348
 
349
-        if ( $data ) {
350
-            foreach ( $data as $row ) {
349
+        if ($data) {
350
+            foreach ($data as $row) {
351 351
                 $i = 1;
352
-                foreach ( $row as $key => $column ) {
353
-                    if ( array_key_exists( $key, $columns ) ) {
354
-                        $row_data .= '"' . addslashes( preg_replace( "/\"/","'", $column ) ) . '"';
355
-                        $row_data .= $i == count( $columns ) ? '' : ',';
352
+                foreach ($row as $key => $column) {
353
+                    if (array_key_exists($key, $columns)) {
354
+                        $row_data .= '"' . addslashes(preg_replace("/\"/", "'", $column)) . '"';
355
+                        $row_data .= $i == count($columns) ? '' : ',';
356 356
                         $i++;
357 357
                     }
358 358
                 }
359 359
                 $row_data .= "\r\n";
360 360
             }
361 361
 
362
-            $this->attach_export_data( $row_data );
362
+            $this->attach_export_data($row_data);
363 363
 
364 364
             return $row_data;
365 365
         }
@@ -368,46 +368,46 @@  discard block
 block discarded – undo
368 368
     }
369 369
     
370 370
     // Export Invoices.
371
-    public function set_invoices_export( $request ) {
372
-        $this->from_date    = isset( $request['from_date'] ) ? sanitize_text_field( $request['from_date'] ) : '';
373
-        $this->to_date      = isset( $request['to_date'] ) ? sanitize_text_field( $request['to_date'] ) : '';
374
-        $this->status       = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'publich';
371
+    public function set_invoices_export($request) {
372
+        $this->from_date    = isset($request['from_date']) ? sanitize_text_field($request['from_date']) : '';
373
+        $this->to_date      = isset($request['to_date']) ? sanitize_text_field($request['to_date']) : '';
374
+        $this->status       = isset($request['status']) ? sanitize_text_field($request['status']) : 'publich';
375 375
     }
376 376
     
377
-    public function get_invoices_columns( $columns = array() ) {
377
+    public function get_invoices_columns($columns = array()) {
378 378
         $columns = array(
379
-            'id'            => __( 'ID',   'invoicing' ),
380
-            'number'        => __( 'Number',   'invoicing' ),
381
-            'date'          => __( 'Date', 'invoicing' ),
382
-            'amount'        => __( 'Amount', 'invoicing' ),
383
-            'status_nicename'  => __( 'Status Nicename', 'invoicing' ),
384
-            'status'        => __( 'Status', 'invoicing' ),
385
-            'tax'           => __( 'Tax', 'invoicing' ),
386
-            'discount'      => __( 'Discount', 'invoicing' ),
387
-            'user_id'       => __( 'User ID', 'invoicing' ),
388
-            'email'         => __( 'Email', 'invoicing' ),
389
-            'first_name'    => __( 'First Name', 'invoicing' ),
390
-            'last_name'     => __( 'Last Name', 'invoicing' ),
391
-            'address'       => __( 'Address', 'invoicing' ),
392
-            'city'          => __( 'City', 'invoicing' ),
393
-            'state'         => __( 'State', 'invoicing' ),
394
-            'country'       => __( 'Country', 'invoicing' ),
395
-            'zip'           => __( 'Zipcode', 'invoicing' ),
396
-            'phone'         => __( 'Phone', 'invoicing' ),
397
-            'company'       => __( 'Company', 'invoicing' ),
398
-            'vat_number'    => __( 'Vat Number', 'invoicing' ),
399
-            'ip'            => __( 'IP', 'invoicing' ),
400
-            'gateway'       => __( 'Gateway', 'invoicing' ),
401
-            'gateway_nicename'       => __( 'Gateway Nicename', 'invoicing' ),
402
-            'transaction_id'=> __( 'Transaction ID', 'invoicing' ),
403
-            'currency'      => __( 'Currency', 'invoicing' ),
404
-            'due_date'      => __( 'Due Date', 'invoicing' ),
379
+            'id'            => __('ID', 'invoicing'),
380
+            'number'        => __('Number', 'invoicing'),
381
+            'date'          => __('Date', 'invoicing'),
382
+            'amount'        => __('Amount', 'invoicing'),
383
+            'status_nicename'  => __('Status Nicename', 'invoicing'),
384
+            'status'        => __('Status', 'invoicing'),
385
+            'tax'           => __('Tax', 'invoicing'),
386
+            'discount'      => __('Discount', 'invoicing'),
387
+            'user_id'       => __('User ID', 'invoicing'),
388
+            'email'         => __('Email', 'invoicing'),
389
+            'first_name'    => __('First Name', 'invoicing'),
390
+            'last_name'     => __('Last Name', 'invoicing'),
391
+            'address'       => __('Address', 'invoicing'),
392
+            'city'          => __('City', 'invoicing'),
393
+            'state'         => __('State', 'invoicing'),
394
+            'country'       => __('Country', 'invoicing'),
395
+            'zip'           => __('Zipcode', 'invoicing'),
396
+            'phone'         => __('Phone', 'invoicing'),
397
+            'company'       => __('Company', 'invoicing'),
398
+            'vat_number'    => __('Vat Number', 'invoicing'),
399
+            'ip'            => __('IP', 'invoicing'),
400
+            'gateway'       => __('Gateway', 'invoicing'),
401
+            'gateway_nicename'       => __('Gateway Nicename', 'invoicing'),
402
+            'transaction_id'=> __('Transaction ID', 'invoicing'),
403
+            'currency'      => __('Currency', 'invoicing'),
404
+            'due_date'      => __('Due Date', 'invoicing'),
405 405
         );
406 406
 
407 407
         return $columns;
408 408
     }
409 409
         
410
-    public function get_invoices_data( $response = array() ) {
410
+    public function get_invoices_data($response = array()) {
411 411
         $args = array(
412 412
             'limit'    => $this->per_page,
413 413
             'page'     => $this->step,
@@ -415,35 +415,35 @@  discard block
 block discarded – undo
415 415
             'orderby'  => 'date',
416 416
         );
417 417
         
418
-        if ( $this->status != 'any' ) {
418
+        if ($this->status != 'any') {
419 419
             $args['status'] = $this->status;
420 420
         }
421 421
 
422
-        if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) {
422
+        if (!empty($this->from_date) || !empty($this->to_date)) {
423 423
             $args['date_query'] = array(
424 424
                 array(
425
-                    'after'     => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ),
426
-                    'before'    => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ),
425
+                    'after'     => date('Y-n-d 00:00:00', strtotime($this->from_date)),
426
+                    'before'    => date('Y-n-d 23:59:59', strtotime($this->to_date)),
427 427
                     'inclusive' => true
428 428
                 )
429 429
             );
430 430
         }
431 431
 
432
-        $invoices = wpinv_get_invoices( $args );
432
+        $invoices = wpinv_get_invoices($args);
433 433
         
434 434
         $data = array();
435 435
         
436
-        if ( !empty( $invoices ) ) {
437
-            foreach ( $invoices as $invoice ) {
436
+        if (!empty($invoices)) {
437
+            foreach ($invoices as $invoice) {
438 438
                 $row = array(
439 439
                     'id'            => $invoice->ID,
440 440
                     'number'        => $invoice->get_number(),
441
-                    'date'          => $invoice->get_invoice_date( false ),
442
-                    'amount'        => wpinv_round_amount( $invoice->get_total() ),
443
-                    'status_nicename' => $invoice->get_status( true ),
441
+                    'date'          => $invoice->get_invoice_date(false),
442
+                    'amount'        => wpinv_round_amount($invoice->get_total()),
443
+                    'status_nicename' => $invoice->get_status(true),
444 444
                     'status'        => $invoice->get_status(),
445
-                    'tax'           => $invoice->get_tax() > 0 ? wpinv_round_amount( $invoice->get_tax() ) : '',
446
-                    'discount'      => $invoice->get_discount() > 0 ? wpinv_round_amount( $invoice->get_discount() ) : '',
445
+                    'tax'           => $invoice->get_tax() > 0 ? wpinv_round_amount($invoice->get_tax()) : '',
446
+                    'discount'      => $invoice->get_discount() > 0 ? wpinv_round_amount($invoice->get_discount()) : '',
447 447
                     'user_id'       => $invoice->get_user_id(),
448 448
                     'email'         => $invoice->get_email(),
449 449
                     'first_name'    => $invoice->get_first_name(),
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
                     'due_date'      => $invoice->needs_payment() ? $invoice->get_due_date() : '',
465 465
                 );
466 466
                 
467
-                $data[] = apply_filters( 'wpinv_export_invoice_row', $row, $invoice );
467
+                $data[] = apply_filters('wpinv_export_invoice_row', $row, $invoice);
468 468
             }
469 469
 
470 470
             return $data;
@@ -480,29 +480,29 @@  discard block
 block discarded – undo
480 480
             'return'   => 'ids',
481 481
         );
482 482
         
483
-        if ( $this->status != 'any' ) {
483
+        if ($this->status != 'any') {
484 484
             $args['status'] = $this->status;
485 485
         }
486 486
 
487
-        if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) {
487
+        if (!empty($this->from_date) || !empty($this->to_date)) {
488 488
             $args['date_query'] = array(
489 489
                 array(
490
-                    'after'     => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ),
491
-                    'before'    => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ),
490
+                    'after'     => date('Y-n-d 00:00:00', strtotime($this->from_date)),
491
+                    'before'    => date('Y-n-d 23:59:59', strtotime($this->to_date)),
492 492
                     'inclusive' => true
493 493
                 )
494 494
             );
495 495
         }
496 496
 
497
-        $invoices   = wpinv_get_invoices( $args );
498
-        $total      = !empty( $invoices ) ? count( $invoices ) : 0;
497
+        $invoices   = wpinv_get_invoices($args);
498
+        $total      = !empty($invoices) ? count($invoices) : 0;
499 499
         $status     = 100;
500 500
 
501
-        if ( $total > 0 ) {
502
-            $status = ( ( $this->per_page * $this->step ) / $total ) * 100;
501
+        if ($total > 0) {
502
+            $status = (($this->per_page * $this->step) / $total) * 100;
503 503
         }
504 504
 
505
-        if ( $status > 100 ) {
505
+        if ($status > 100) {
506 506
             $status = 100;
507 507
         }
508 508
 
Please login to merge, or discard this patch.
includes/gateways/authorizenet.php 1 patch
Spacing   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -1,60 +1,60 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_filter( 'wpinv_authorizenet_support_subscription', '__return_true' );
5
+add_filter('wpinv_authorizenet_support_subscription', '__return_true');
6 6
 
7
-function wpinv_authorizenet_cc_form( $invoice_id ) {
8
-    $invoice = wpinv_get_invoice( $invoice_id );
9
-    $cc_owner = !empty( $invoice ) ? esc_attr( $invoice->get_user_full_name() ) : '';
7
+function wpinv_authorizenet_cc_form($invoice_id) {
8
+    $invoice = wpinv_get_invoice($invoice_id);
9
+    $cc_owner = !empty($invoice) ? esc_attr($invoice->get_user_full_name()) : '';
10 10
     ?>
11 11
     <div id="authorizenet_cc_form" class="form-horizontal wpi-cc-form panel panel-default">
12
-        <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Card Details', 'invoicing' ) ;?></h3></div>
12
+        <div class="panel-heading"><h3 class="panel-title"><?php _e('Card Details', 'invoicing'); ?></h3></div>
13 13
         <div class="panel-body">
14 14
             <div class="form-group required">
15
-              <label for="auth-input-cc-owner" class="col-sm-4 control-label"><?php _e( 'Card Owner', 'invoicing' ) ;?></label>
15
+              <label for="auth-input-cc-owner" class="col-sm-4 control-label"><?php _e('Card Owner', 'invoicing'); ?></label>
16 16
               <div class="col-sm-8">
17
-                <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e( 'Card Owner', 'invoicing' ) ;?>" value="<?php echo $cc_owner;?>" name="authorizenet[cc_owner]">
17
+                <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e('Card Owner', 'invoicing'); ?>" value="<?php echo $cc_owner; ?>" name="authorizenet[cc_owner]">
18 18
               </div>
19 19
             </div>
20 20
             <div class="form-group required">
21
-              <label for="auth-input-cc-number" class="col-sm-4 control-label"><?php _e( 'Card Number', 'invoicing' ) ;?></label>
21
+              <label for="auth-input-cc-number" class="col-sm-4 control-label"><?php _e('Card Number', 'invoicing'); ?></label>
22 22
               <div class="col-sm-8">
23
-                <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e( 'Card Number', 'invoicing' ) ;?>" value="" name="authorizenet[cc_number]">
23
+                <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e('Card Number', 'invoicing'); ?>" value="" name="authorizenet[cc_number]">
24 24
               </div>
25 25
             </div>
26 26
             <div class="form-group required">
27
-              <label for="auth-input-cc-expire-date" class="col-sm-4 control-label"><?php _e( 'Card Expiry Date', 'invoicing' ) ;?></label>
27
+              <label for="auth-input-cc-expire-date" class="col-sm-4 control-label"><?php _e('Card Expiry Date', 'invoicing'); ?></label>
28 28
               <div class="col-sm-2">
29 29
                 <select class="form-control" id="auth-input-cc-expire-date" name="authorizenet[cc_expire_month]">
30
-                    <?php for ( $i = 1; $i <= 12; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
31
-                    <option value="<?php echo $value;?>"><?php echo $value;?></option>
30
+                    <?php for ($i = 1; $i <= 12; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
31
+                    <option value="<?php echo $value; ?>"><?php echo $value; ?></option>
32 32
                     <?php } ?>
33 33
                 </select>
34 34
                </div>
35 35
                <div class="col-sm-2">
36 36
                 <select class="form-control" name="authorizenet[cc_expire_year]">
37
-                    <?php $year = date( 'Y' ); for ( $i = $year; $i <= ( $year + 10 ); $i++ ) { ?>
38
-                    <option value="<?php echo $i;?>"><?php echo $i;?></option>
37
+                    <?php $year = date('Y'); for ($i = $year; $i <= ($year + 10); $i++) { ?>
38
+                    <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
39 39
                     <?php } ?>
40 40
                 </select>
41 41
               </div>
42 42
             </div>
43 43
             <div class="form-group required">
44
-              <label for="auth-input-cc-cvv2" class="col-sm-4 control-label"><?php _e( 'Card Security Code (CVV2)', 'invoicing' ) ;?></label>
44
+              <label for="auth-input-cc-cvv2" class="col-sm-4 control-label"><?php _e('Card Security Code (CVV2)', 'invoicing'); ?></label>
45 45
               <div class="col-sm-8">
46
-                <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e( 'Card Security Code (CVV2)', 'invoicing' ) ;?>" value="" name="authorizenet[cc_cvv2]"">
46
+                <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e('Card Security Code (CVV2)', 'invoicing'); ?>" value="" name="authorizenet[cc_cvv2]"">
47 47
               </div>
48 48
             </div>
49 49
       </div>
50 50
     </div>
51 51
     <?php
52 52
 }
53
-add_action( 'wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1 );
53
+add_action('wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1);
54 54
 
55
-function wpinv_process_authorizenet_payment( $purchase_data ) {
56
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
57
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_process_authorizenet_payment($purchase_data) {
56
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
57
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
     
60 60
     // Collect payment data
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
     );
73 73
 
74 74
     // Record the pending payment
75
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
75
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
76 76
 
77
-    if ( !empty( $invoice ) ) {
78
-        $authorizenet_card  = !empty( $_POST['authorizenet'] ) ? $_POST['authorizenet'] : array();
77
+    if (!empty($invoice)) {
78
+        $authorizenet_card  = !empty($_POST['authorizenet']) ? $_POST['authorizenet'] : array();
79 79
         $card_defaults      = array(
80 80
             'cc_owner'          => $invoice->get_user_full_name(),
81 81
             'cc_number'         => false,
@@ -83,27 +83,27 @@  discard block
 block discarded – undo
83 83
             'cc_expire_year'    => false,
84 84
             'cc_cvv2'           => false,
85 85
         );
86
-        $authorizenet_card = wp_parse_args( $authorizenet_card, $card_defaults );
86
+        $authorizenet_card = wp_parse_args($authorizenet_card, $card_defaults);
87 87
         
88
-        if ( empty( $authorizenet_card['cc_owner'] ) ) {
89
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
88
+        if (empty($authorizenet_card['cc_owner'])) {
89
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
90 90
         }
91
-        if ( empty( $authorizenet_card['cc_number'] ) ) {
92
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
91
+        if (empty($authorizenet_card['cc_number'])) {
92
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
93 93
         }
94
-        if ( empty( $authorizenet_card['cc_expire_month'] ) ) {
95
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
94
+        if (empty($authorizenet_card['cc_expire_month'])) {
95
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
96 96
         }
97
-        if ( empty( $authorizenet_card['cc_expire_year'] ) ) {
98
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
97
+        if (empty($authorizenet_card['cc_expire_year'])) {
98
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
99 99
         }
100
-        if ( empty( $authorizenet_card['cc_cvv2'] ) ) {
101
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
100
+        if (empty($authorizenet_card['cc_cvv2'])) {
101
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
102 102
         }
103 103
         
104 104
         $errors = wpinv_get_errors();
105 105
     
106
-        if ( empty( $errors ) ) {
106
+        if (empty($errors)) {
107 107
             $invoice_id = $invoice->ID;
108 108
             $quantities_enabled = wpinv_item_quantities_enabled();
109 109
             $use_taxes          = wpinv_use_taxes();
@@ -112,141 +112,141 @@  discard block
 block discarded – undo
112 112
             $authorizeAIM->first_name       = $invoice->get_first_name();
113 113
             $authorizeAIM->last_name        = $invoice->get_last_name();
114 114
             $authorizeAIM->company          = $invoice->company;
115
-            $authorizeAIM->address          = wp_strip_all_tags( $invoice->get_address(), true );
115
+            $authorizeAIM->address          = wp_strip_all_tags($invoice->get_address(), true);
116 116
             $authorizeAIM->city             = $invoice->city;
117 117
             $authorizeAIM->state            = $invoice->state;
118 118
             $authorizeAIM->zip              = $invoice->zip;
119 119
             $authorizeAIM->country          = $invoice->country;
120 120
             $authorizeAIM->phone            = $invoice->phone;
121 121
             $authorizeAIM->email            = $invoice->get_email();
122
-            $authorizeAIM->amount           = wpinv_sanitize_amount( $invoice->get_total() );
123
-            $authorizeAIM->card_num         = str_replace( ' ', '', sanitize_text_field( $authorizenet_card['cc_number'] ) );
124
-            $authorizeAIM->exp_date         = sanitize_text_field( $authorizenet_card['cc_expire_month'] ) . sanitize_text_field( $authorizenet_card['cc_expire_year'] );
125
-            $authorizeAIM->card_code        = sanitize_text_field( $authorizenet_card['cc_cvv2'] );
122
+            $authorizeAIM->amount           = wpinv_sanitize_amount($invoice->get_total());
123
+            $authorizeAIM->card_num         = str_replace(' ', '', sanitize_text_field($authorizenet_card['cc_number']));
124
+            $authorizeAIM->exp_date         = sanitize_text_field($authorizenet_card['cc_expire_month']) . sanitize_text_field($authorizenet_card['cc_expire_year']);
125
+            $authorizeAIM->card_code        = sanitize_text_field($authorizenet_card['cc_cvv2']);
126 126
             $authorizeAIM->invoice_num      = $invoice->ID;
127 127
             
128 128
             $item_desc = array();
129
-            foreach ( $invoice->get_cart_details() as $item ) {            
130
-                $quantity       = $quantities_enabled && !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1;
131
-                $item_desc[]    = $item['name'] . ' (' . $quantity . 'x ' . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')';
129
+            foreach ($invoice->get_cart_details() as $item) {            
130
+                $quantity       = $quantities_enabled && !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1;
131
+                $item_desc[]    = $item['name'] . ' (' . $quantity . 'x ' . wpinv_price(wpinv_format_amount($item['item_price'])) . ')';
132 132
                 
133
-                $authorizeAIM->addLineItem( $item['id'], $item['name'], '', $quantity, $item['item_price'], ( $use_taxes && !empty( $item['tax'] ) && $item['tax'] > 0 ? 'Y' : 'N' ) );
133
+                $authorizeAIM->addLineItem($item['id'], $item['name'], '', $quantity, $item['item_price'], ($use_taxes && !empty($item['tax']) && $item['tax'] > 0 ? 'Y' : 'N'));
134 134
             }
135 135
             
136
-            $item_desc = '#' . $invoice->get_number() . ': ' . implode( ', ', $item_desc );
136
+            $item_desc = '#' . $invoice->get_number() . ': ' . implode(', ', $item_desc);
137 137
             
138
-            if ( $use_taxes && $invoice->get_tax() > 0 ) {
139
-                $authorizeAIM->tax  = $invoice->get_tax();
138
+            if ($use_taxes && $invoice->get_tax() > 0) {
139
+                $authorizeAIM->tax = $invoice->get_tax();
140 140
                 
141
-                $item_desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) );
141
+                $item_desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true));
142 142
             }
143 143
             
144
-            if ( $invoice->get_discount() > 0 ) {
145
-                $item_desc .= ', ' . wp_sprintf( __( 'Discount: %s', 'invoicing' ), $invoice->get_discount( true ) );
144
+            if ($invoice->get_discount() > 0) {
145
+                $item_desc .= ', ' . wp_sprintf(__('Discount: %s', 'invoicing'), $invoice->get_discount(true));
146 146
             }
147 147
             
148
-            $authorizeAIM->description  = html_entity_decode( $item_desc , ENT_QUOTES, 'UTF-8' );
148
+            $authorizeAIM->description = html_entity_decode($item_desc, ENT_QUOTES, 'UTF-8');
149 149
             
150 150
             $is_recurring = $invoice->is_recurring(); // Recurring payment.
151 151
             
152
-            if ( $is_recurring ) {
152
+            if ($is_recurring) {
153 153
                 $authorizeAIM->recurring_billing = true;
154 154
             }
155 155
             
156 156
             try {
157
-                if ( $is_recurring ) {
157
+                if ($is_recurring) {
158 158
                     $response = $authorizeAIM->authorizeOnly();
159 159
                 } else {
160 160
                     $response = $authorizeAIM->authorizeAndCapture();
161 161
                 }
162 162
                 
163
-                if ( $response->approved || $response->held ) {
164
-                    if ( $response->approved ) {
165
-                        wpinv_update_payment_status( $invoice_id, 'publish' );
163
+                if ($response->approved || $response->held) {
164
+                    if ($response->approved) {
165
+                        wpinv_update_payment_status($invoice_id, 'publish');
166 166
                     }
167
-                    wpinv_set_payment_transaction_id( $invoice_id, $response->transaction_id );
167
+                    wpinv_set_payment_transaction_id($invoice_id, $response->transaction_id);
168 168
                     
169
-                    $message = wp_sprintf( __( 'Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing' ), $response->response_reason_text, $response->transaction_id, strtoupper( $response->transaction_type ), $response->authorization_code );
169
+                    $message = wp_sprintf(__('Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing'), $response->response_reason_text, $response->transaction_id, strtoupper($response->transaction_type), $response->authorization_code);
170 170
                     
171
-                    wpinv_insert_payment_note( $invoice_id, $message );
171
+                    wpinv_insert_payment_note($invoice_id, $message);
172 172
                     
173
-                    do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card );
173
+                    do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card);
174 174
                     
175 175
                     wpinv_clear_errors();
176 176
                     wpinv_empty_cart();
177 177
                     
178
-                    wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
178
+                    wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
179 179
                 } else {
180
-                    if ( !empty( $response->response_reason_text ) ) {
181
-                        $error = __( $response->response_reason_text, 'invoicing' );
182
-                    } else if ( !empty( $response->error_message ) ) {
183
-                        $error = __( $response->error_message, 'invoicing' );
180
+                    if (!empty($response->response_reason_text)) {
181
+                        $error = __($response->response_reason_text, 'invoicing');
182
+                    } else if (!empty($response->error_message)) {
183
+                        $error = __($response->error_message, 'invoicing');
184 184
                     } else {
185
-                        $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) );
185
+                        $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true));
186 186
                     } 
187 187
                     
188
-                    $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error );
188
+                    $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error);
189 189
                     
190
-                    wpinv_set_error( 'payment_error', $error );
191
-                    wpinv_record_gateway_error( $error, $response );
192
-                    wpinv_insert_payment_note( $invoice_id, $error );
190
+                    wpinv_set_error('payment_error', $error);
191
+                    wpinv_record_gateway_error($error, $response);
192
+                    wpinv_insert_payment_note($invoice_id, $error);
193 193
                     
194
-                    wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
194
+                    wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
195 195
                 }
196
-            } catch ( AuthorizeNetException $e ) {
197
-                wpinv_set_error( 'request_error', $e->getMessage() );
198
-                wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) );
199
-                wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
196
+            } catch (AuthorizeNetException $e) {
197
+                wpinv_set_error('request_error', $e->getMessage());
198
+                wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage()));
199
+                wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
200 200
             }
201 201
         } else {
202
-            wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
202
+            wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
203 203
         }
204 204
     } else {
205
-        wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing' ), print_r( $payment_data, true ) ), $invoice );
206
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
205
+        wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing'), print_r($payment_data, true)), $invoice);
206
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
207 207
     }
208 208
 }
209
-add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' );
209
+add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment');
210 210
 
211
-function wpinv_authorizenet_cancel_subscription( $subscription_id = '' ) {
212
-    if ( empty( $subscription_id ) ) {
211
+function wpinv_authorizenet_cancel_subscription($subscription_id = '') {
212
+    if (empty($subscription_id)) {
213 213
         return false;
214 214
     }
215 215
     
216 216
     try {
217 217
         $authnetXML = wpinv_authorizenet_XML();
218
-        $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription_id ) );
218
+        $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription_id));
219 219
 
220 220
         return $authnetXML->isSuccessful();
221
-    } catch( Exception $e ) {
222
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
221
+    } catch (Exception $e) {
222
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
223 223
     }
224 224
     
225 225
     return false;
226 226
 }
227 227
 
228
-function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) {
229
-    $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' );
230
-    if ( empty( $authorizenet_md5_hash ) ) {
228
+function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) {
229
+    $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash');
230
+    if (empty($authorizenet_md5_hash)) {
231 231
         return true;
232 232
     }
233 233
     
234
-    $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) );
234
+    $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount));
235 235
     
236
-    return hash_equals( $compare_md5, $md5_hash );
236
+    return hash_equals($compare_md5, $md5_hash);
237 237
 }
238 238
 
239 239
 function wpinv_authorizenet_AIM() {
240
-    if ( !class_exists( 'AuthorizeNetException' ) ) {
241
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
240
+    if (!class_exists('AuthorizeNetException')) {
241
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
242 242
     }
243 243
     
244
-    $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) );
244
+    $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'));
245 245
     
246
-    if ( wpinv_is_test_mode( 'authorizenet' ) ) {
247
-        $authorizeAIM->setSandbox( true );
246
+    if (wpinv_is_test_mode('authorizenet')) {
247
+        $authorizeAIM->setSandbox(true);
248 248
     } else {
249
-        $authorizeAIM->setSandbox( false );
249
+        $authorizeAIM->setSandbox(false);
250 250
     }
251 251
     
252 252
     $authorizeAIM->customer_ip = wpinv_get_ip();
@@ -255,164 +255,164 @@  discard block
 block discarded – undo
255 255
 }
256 256
 
257 257
 function wpinv_authorizenet_XML() {
258
-    if ( !class_exists( 'AuthnetXML' ) ) {
259
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
258
+    if (!class_exists('AuthnetXML')) {
259
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
260 260
     }
261 261
     
262
-    $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) );
262
+    $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool)wpinv_is_test_mode('authorizenet'));
263 263
     
264 264
     return $authnetXML;
265 265
 }
266 266
 
267
-function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) {
268
-    if ( empty( $response ) || empty( $invoice ) ) {
267
+function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) {
268
+    if (empty($response) || empty($invoice)) {
269 269
         return false;
270 270
     }
271 271
     
272
-    if ( !empty( $response->approved ) ) {
273
-        $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info );
272
+    if (!empty($response->approved)) {
273
+        $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info);
274 274
 
275
-        if ( !empty( $subscription ) && $subscription->isSuccessful() ) {
276
-            do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' );
275
+        if (!empty($subscription) && $subscription->isSuccessful()) {
276
+            do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet');
277 277
             
278
-            wpinv_authorizenet_subscription_record_signup( $subscription, $invoice );
278
+            wpinv_authorizenet_subscription_record_signup($subscription, $invoice);
279 279
             
280
-            do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' );
280
+            do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet');
281 281
         } else {
282
-            if ( isset( $subscription->messages->message ) ) {
282
+            if (isset($subscription->messages->message)) {
283 283
                 $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text;
284
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' );
284
+                wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing');
285 285
             } else {
286
-                $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' );
287
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error );
286
+                $error = __('Your subscription cannot be created due to an error.', 'invoicing');
287
+                wpinv_set_error('wpinv_authorize_recurring_error', $error);
288 288
             }
289 289
             
290
-            wpinv_record_gateway_error( $error, $subscription );
290
+            wpinv_record_gateway_error($error, $subscription);
291 291
             
292
-            wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ) );
292
+            wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error));
293 293
         }
294 294
     }
295 295
 }
296
-add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 );
296
+add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3);
297 297
 
298
-function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) {
299
-    if ( empty( $invoice ) ) {
298
+function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) {
299
+    if (empty($invoice)) {
300 300
         return false;
301 301
     }
302 302
     
303
-    $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response );
303
+    $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response);
304 304
     
305 305
     try {
306 306
         $authnetXML = wpinv_authorizenet_XML();
307
-        $authnetXML->ARBCreateSubscriptionRequest( $params );
308
-    } catch( Exception $e ) {
307
+        $authnetXML->ARBCreateSubscriptionRequest($params);
308
+    } catch (Exception $e) {
309 309
         $authnetXML = array();
310
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
310
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
311 311
     }
312 312
     
313 313
     return $authnetXML;
314 314
 }
315 315
 
316
-function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) {
317
-    if ( empty( $invoice ) ) {
316
+function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) {
317
+    if (empty($invoice)) {
318 318
         return false;
319 319
     }
320 320
     
321
-    $subscription_item = $invoice->get_recurring( true );
322
-    if ( empty( $subscription_item ) ) {
321
+    $subscription_item = $invoice->get_recurring(true);
322
+    if (empty($subscription_item)) {
323 323
         return false;
324 324
     }
325 325
     
326
-    $card_details       = wpinv_authorizenet_generate_card_info( $card_info );
326
+    $card_details       = wpinv_authorizenet_generate_card_info($card_info);
327 327
     $subscription_name  = $invoice->get_subscription_name();
328
-    $initial_amount     = wpinv_round_amount( $invoice->get_total() );
329
-    $recurring_amount   = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) );
328
+    $initial_amount     = wpinv_round_amount($invoice->get_total());
329
+    $recurring_amount   = wpinv_round_amount($invoice->get_recurring_details('total'));
330 330
     $interval           = $subscription_item->get_recurring_interval();
331 331
     $period             = $subscription_item->get_recurring_period();
332 332
     $bill_times         = (int)$subscription_item->get_recurring_limit();
333 333
     $bill_times         = $bill_times > 0 ? $bill_times : 9999;
334 334
     
335
-    $time_period        = wpinv_authorizenet_get_time_period( $interval, $period );
335
+    $time_period        = wpinv_authorizenet_get_time_period($interval, $period);
336 336
     $interval           = $time_period['interval'];
337 337
     $period             = $time_period['period'];
338 338
     
339 339
     $current_tz = date_default_timezone_get();
340
-    date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
341
-    $today = date( 'Y-m-d' );
342
-    date_default_timezone_set( $current_tz );
340
+    date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
341
+    $today = date('Y-m-d');
342
+    date_default_timezone_set($current_tz);
343 343
     
344 344
     $free_trial = $invoice->is_free_trial();
345
-    if ( $free_trial && $subscription_item->has_free_trial() ) {
345
+    if ($free_trial && $subscription_item->has_free_trial()) {
346 346
         $trial_interval    = $subscription_item->get_trial_interval();
347
-        $trial_period      = $subscription_item->get_trial_period( true );
347
+        $trial_period      = $subscription_item->get_trial_period(true);
348 348
     }
349 349
     
350 350
     $subscription = array();
351 351
     $subscription['name'] = $subscription_name;
352 352
     
353 353
     $subscription['paymentSchedule'] = array(
354
-        'interval'         => array( 'length' => $interval, 'unit' => $period ),
354
+        'interval'         => array('length' => $interval, 'unit' => $period),
355 355
         'startDate'        => $today,
356 356
         'totalOccurrences' => $bill_times,
357
-        'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0,
357
+        'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0,
358 358
     );
359 359
     
360 360
     $subscription['amount'] = $recurring_amount;
361 361
     $subscription['trialAmount'] = $initial_amount;
362
-    $subscription['payment'] = array( 'creditCard' => $card_details );
363
-    $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() );
364
-    $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone );
362
+    $subscription['payment'] = array('creditCard' => $card_details);
363
+    $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number());
364
+    $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone);
365 365
     
366 366
     $subscription['billTo'] = array(
367 367
         'firstName' => $invoice->get_first_name(),
368 368
         'lastName'  => $invoice->get_last_name(),
369 369
         'company'   => $invoice->company,
370
-        'address'   => wp_strip_all_tags( $invoice->get_address(), true ),
370
+        'address'   => wp_strip_all_tags($invoice->get_address(), true),
371 371
         'city'      => $invoice->city,
372 372
         'state'     => $invoice->state,
373 373
         'zip'       => $invoice->zip,
374 374
         'country'   => $invoice->country,
375 375
     );
376 376
     
377
-    $params = array( 'subscription' => $subscription );
377
+    $params = array('subscription' => $subscription);
378 378
     
379
-    return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response );
379
+    return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response);
380 380
 }
381 381
 
382
-function wpinv_authorizenet_generate_card_info( $card_info = array() ) {
383
-    $card_defaults      = array(
382
+function wpinv_authorizenet_generate_card_info($card_info = array()) {
383
+    $card_defaults = array(
384 384
         'cc_owner'          => null,
385 385
         'cc_number'         => null,
386 386
         'cc_expire_month'   => null,
387 387
         'cc_expire_year'    => null,
388 388
         'cc_cvv2'           => null,
389 389
     );
390
-    $card_info = wp_parse_args( $card_info, $card_defaults );
390
+    $card_info = wp_parse_args($card_info, $card_defaults);
391 391
         
392 392
     $card_details = array(
393
-        'cardNumber'     => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ),
394
-        'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ),
395
-        'cardCode'       => sanitize_text_field( $card_info['cc_cvv2'] ),
393
+        'cardNumber'     => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])),
394
+        'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']),
395
+        'cardCode'       => sanitize_text_field($card_info['cc_cvv2']),
396 396
     );
397 397
 
398 398
     return $card_details;
399 399
 }
400 400
 
401
-function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) {
402
-    if ( empty( $invoice ) || empty( $subscription ) ) {
401
+function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) {
402
+    if (empty($invoice) || empty($subscription)) {
403 403
         return false;
404 404
     }
405 405
     
406
-    $subscription_item = $invoice->get_recurring( true );
407
-    if ( empty( $subscription_item ) ) {
406
+    $subscription_item = $invoice->get_recurring(true);
407
+    if (empty($subscription_item)) {
408 408
         return false;
409 409
     }
410 410
     
411 411
     $invoice_id         = $invoice->ID;
412 412
     $subscriptionId     = (array)$subscription->subscriptionId;
413
-    $subscription_id    = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $invoice_id;
413
+    $subscription_id    = !empty($subscriptionId[0]) ? $subscriptionId[0] : $invoice_id;
414 414
 
415
-    wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ) );
415
+    wpinv_insert_payment_note($invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id));
416 416
     
417 417
     $status = $invoice->is_free_trial() && $subscription_item->has_free_trial() ? 'trialing' : 'active';
418 418
     
@@ -420,16 +420,16 @@  discard block
 block discarded – undo
420 420
         'profile_id'        => $subscription_id,
421 421
         'item_id'           => $subscription_item->ID,
422 422
         'initial_amount'    => $invoice->get_total(),
423
-        'recurring_amount'  => $invoice->get_recurring_details( 'total' ),
423
+        'recurring_amount'  => $invoice->get_recurring_details('total'),
424 424
         'period'            => $subscription_item->get_recurring_period(),
425 425
         'interval'          => $subscription_item->get_recurring_interval(),
426 426
         'bill_times'        => $subscription_item->get_recurring_limit(),
427
-        'expiration'        => $invoice->get_new_expiration( $subscription_item->ID ),
427
+        'expiration'        => $invoice->get_new_expiration($subscription_item->ID),
428 428
         'status'            => $status,
429
-        'created'           => current_time( 'mysql', 0 )
429
+        'created'           => current_time('mysql', 0)
430 430
     );
431 431
     
432
-    if ( $invoice->is_free_trial() && $subscription_item->has_free_trial() ) {
432
+    if ($invoice->is_free_trial() && $subscription_item->has_free_trial()) {
433 433
         $args['trial_period']      = $subscription_item->get_trial_period();
434 434
         $args['trial_interval']    = $subscription_item->get_trial_interval();
435 435
     } else {
@@ -437,58 +437,58 @@  discard block
 block discarded – undo
437 437
         $args['trial_interval']    = 0;
438 438
     }
439 439
     
440
-    return $invoice->update_subscription( $args );
440
+    return $invoice->update_subscription($args);
441 441
 }
442 442
 
443
-function wpinv_authorizenet_validate_checkout( $valid_data, $post ) {
444
-    if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) {
443
+function wpinv_authorizenet_validate_checkout($valid_data, $post) {
444
+    if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') {
445 445
         $error = false;
446 446
         
447
-        if ( empty( $post['authorizenet']['cc_owner'] ) ) {
447
+        if (empty($post['authorizenet']['cc_owner'])) {
448 448
             $error = true;
449
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
449
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
450 450
         }
451
-        if ( empty( $post['authorizenet']['cc_number'] ) ) {
451
+        if (empty($post['authorizenet']['cc_number'])) {
452 452
             $error = true;
453
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
453
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
454 454
         }
455
-        if ( empty( $post['authorizenet']['cc_expire_month'] ) ) {
455
+        if (empty($post['authorizenet']['cc_expire_month'])) {
456 456
             $error = true;
457
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
457
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
458 458
         }
459
-        if ( empty( $post['authorizenet']['cc_expire_year'] ) ) {
459
+        if (empty($post['authorizenet']['cc_expire_year'])) {
460 460
             $error = true;
461
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
461
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
462 462
         }
463
-        if ( empty( $post['authorizenet']['cc_cvv2'] ) ) {
463
+        if (empty($post['authorizenet']['cc_cvv2'])) {
464 464
             $error = true;
465
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
465
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
466 466
         }
467 467
         
468
-        if ( $error ) {
468
+        if ($error) {
469 469
             return;
470 470
         }
471 471
         
472 472
         $invoice = wpinv_get_invoice_cart();
473 473
         
474
-        if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) {
475
-            $subscription_item = $invoice->get_recurring( true );
474
+        if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) {
475
+            $subscription_item = $invoice->get_recurring(true);
476 476
             
477 477
             $interval   = $subscription_item->get_recurring_interval();
478 478
             $period     = $subscription_item->get_recurring_period();
479 479
             
480
-            if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) {
481
-                wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) );
480
+            if ($period == 'D' && ($interval < 7 || $interval > 365)) {
481
+                wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing'));
482 482
             }
483 483
         }
484 484
     }
485 485
 }
486
-add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 );
486
+add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2);
487 487
 
488
-function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) {
489
-    $subscription_interval = absint( $subscription_interval );
488
+function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) {
489
+    $subscription_interval = absint($subscription_interval);
490 490
 
491
-    switch( $subscription_period ) {
491
+    switch ($subscription_period) {
492 492
         case 'W':
493 493
         case 'week':
494 494
         case 'weeks':
@@ -498,14 +498,14 @@  discard block
 block discarded – undo
498 498
         case 'M':
499 499
         case 'month':
500 500
         case 'months':
501
-            if ( $subscription_interval > 12 ) {
501
+            if ($subscription_interval > 12) {
502 502
                 $subscription_interval = 12;
503 503
             }
504 504
             
505 505
             $interval = $subscription_interval;
506 506
             $period   = 'months';
507 507
             
508
-            if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) {
508
+            if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) {
509 509
                 $interval = $subscription_interval * 30;
510 510
                 $period   = 'days';
511 511
             }
@@ -522,40 +522,40 @@  discard block
 block discarded – undo
522 522
             break;
523 523
     }
524 524
 
525
-    return compact( 'interval', 'period' );
525
+    return compact('interval', 'period');
526 526
 }
527 527
 
528 528
 function wpinv_authorizenet_process_ipn() {
529
-    if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) {
529
+    if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) {
530 530
         return;
531 531
     }
532 532
     
533
-    $subscription_id = intval( $_POST['x_subscription_id'] );
533
+    $subscription_id = intval($_POST['x_subscription_id']);
534 534
     
535
-    if ( $subscription_id ) {
536
-        $transaction_id = sanitize_text_field( $_POST['x_trans_id'] );
537
-        $renewal_amount = sanitize_text_field( $_POST['x_amount'] );
538
-        $response_code  = intval( $_POST['x_response_code'] );
539
-        $reason_code    = intval( $_POST['x_response_reason_code'] );
535
+    if ($subscription_id) {
536
+        $transaction_id = sanitize_text_field($_POST['x_trans_id']);
537
+        $renewal_amount = sanitize_text_field($_POST['x_amount']);
538
+        $response_code  = intval($_POST['x_response_code']);
539
+        $reason_code    = intval($_POST['x_response_reason_code']);
540 540
 
541
-        if ( 1 == $response_code ) {
541
+        if (1 == $response_code) {
542 542
             // Approved
543
-            do_action( 'wpinv_authorizenet_renewal_payment', $transaction_id );
544
-        } else if ( 2 == $response_code ) {
543
+            do_action('wpinv_authorizenet_renewal_payment', $transaction_id);
544
+        } else if (2 == $response_code) {
545 545
             // Declined
546
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id );
547
-            do_action( 'wpinv_authorizenet_renewal_error', $transaction_id );
548
-        } else if ( 3 == $response_code || 8 == $reason_code ) {
546
+            do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id);
547
+            do_action('wpinv_authorizenet_renewal_error', $transaction_id);
548
+        } else if (3 == $response_code || 8 == $reason_code) {
549 549
             // An expired card
550
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id );
551
-            do_action( 'wpinv_authorizenet_renewal_payment_error', $transaction_id );
550
+            do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id);
551
+            do_action('wpinv_authorizenet_renewal_payment_error', $transaction_id);
552 552
 
553 553
         } else {
554 554
             // Other Error
555
-            do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription );
555
+            do_action('wpinv_authorizenet_renewal_payment_error', $subscription);
556 556
         }
557 557
         
558 558
         exit;
559 559
     }
560 560
 }
561
-add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' );
562 561
\ No newline at end of file
562
+add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn');
563 563
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/paypal.php 1 patch
Spacing   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_action( 'wpinv_paypal_cc_form', '__return_false' );
6
-add_filter( 'wpinv_paypal_support_subscription', '__return_true' );
5
+add_action('wpinv_paypal_cc_form', '__return_false');
6
+add_filter('wpinv_paypal_support_subscription', '__return_true');
7 7
 
8
-function wpinv_process_paypal_payment( $purchase_data ) {
9
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
10
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
8
+function wpinv_process_paypal_payment($purchase_data) {
9
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
10
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
11 11
     }
12 12
 
13 13
     // Collect payment data
@@ -21,34 +21,34 @@  discard block
 block discarded – undo
21 21
         'user_info'     => $purchase_data['user_info'],
22 22
         'cart_details'  => $purchase_data['cart_details'],
23 23
         'gateway'       => 'paypal',
24
-        'status'        => !empty( $purchase_data['buy_now'] ) ? 'private' : 'pending'
24
+        'status'        => !empty($purchase_data['buy_now']) ? 'private' : 'pending'
25 25
     );
26 26
 
27 27
     // Record the pending payment
28
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
28
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
29 29
 
30 30
     // Check payment
31
-    if ( ! $invoice ) {
31
+    if (!$invoice) {
32 32
         // Record the error
33
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $payment );
33
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing'), json_encode($payment_data)), $payment);
34 34
         // Problems? send back
35
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
35
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
36 36
     } else {
37 37
         // Only send to PayPal if the pending payment is created successfully
38
-        $listener_url = wpinv_get_ipn_url( 'paypal' );
38
+        $listener_url = wpinv_get_ipn_url('paypal');
39 39
 
40 40
         // Get the success url
41
-        $return_url = add_query_arg( array(
41
+        $return_url = add_query_arg(array(
42 42
                 'payment-confirm' => 'paypal',
43 43
                 'invoice-id' => $invoice->ID
44
-            ), get_permalink( wpinv_get_option( 'success_page', false ) ) );
44
+            ), get_permalink(wpinv_get_option('success_page', false)));
45 45
 
46 46
         // Get the PayPal redirect uri
47
-        $paypal_redirect = trailingslashit( wpinv_get_paypal_redirect() ) . '?';
47
+        $paypal_redirect = trailingslashit(wpinv_get_paypal_redirect()) . '?';
48 48
 
49 49
         // Setup PayPal arguments
50 50
         $paypal_args = array(
51
-            'business'      => wpinv_get_option( 'paypal_email', false ),
51
+            'business'      => wpinv_get_option('paypal_email', false),
52 52
             'email'         => $invoice->get_email(),
53 53
             'first_name'    => $invoice->get_first_name(),
54 54
             'last_name'     => $invoice->get_last_name(),
@@ -57,13 +57,13 @@  discard block
 block discarded – undo
57 57
             'shipping'      => '0',
58 58
             'no_note'       => '1',
59 59
             'currency_code' => wpinv_get_currency(),
60
-            'charset'       => get_bloginfo( 'charset' ),
60
+            'charset'       => get_bloginfo('charset'),
61 61
             'custom'        => $invoice->ID,
62 62
             'rm'            => '2',
63 63
             'return'        => $return_url,
64
-            'cancel_return' => wpinv_get_failed_transaction_uri( '?invoice-id=' . $invoice->ID ),
64
+            'cancel_return' => wpinv_get_failed_transaction_uri('?invoice-id=' . $invoice->ID),
65 65
             'notify_url'    => $listener_url,
66
-            'cbt'           => get_bloginfo( 'name' ),
66
+            'cbt'           => get_bloginfo('name'),
67 67
             'bn'            => 'WPInvoicing_SP',
68 68
 	        'lc'            => 'US' // this will force paypal site to english
69 69
         );
@@ -79,57 +79,57 @@  discard block
 block discarded – undo
79 79
             'upload' => '1'
80 80
         );
81 81
 
82
-        $paypal_args = array_merge( $paypal_extra_args, $paypal_args );
82
+        $paypal_args = array_merge($paypal_extra_args, $paypal_args);
83 83
 
84 84
         // Add cart items
85 85
         $i = 1;
86
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
87
-            foreach ( $purchase_data['cart_details'] as $item ) {
86
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
87
+            foreach ($purchase_data['cart_details'] as $item) {
88 88
                 $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1;
89
-                $item_amount = round( $item['subtotal'] / $item['quantity'], 2 );
89
+                $item_amount = round($item['subtotal'] / $item['quantity'], 2);
90 90
 
91
-                if ( $item_amount <= 0 ) {
91
+                if ($item_amount <= 0) {
92 92
                     $item_amount = 0;
93 93
                 }
94 94
 
95
-                $paypal_args['item_number_' . $i ]      = $item['id'];
96
-                $paypal_args['item_name_' . $i ]        = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) );
97
-                $paypal_args['quantity_' . $i ]         = $item['quantity'];
98
-                $paypal_args['amount_' . $i ]           = $item_amount;
99
-                $paypal_args['discount_amount_' . $i ]  = $item['discount'];
95
+                $paypal_args['item_number_' . $i]      = $item['id'];
96
+                $paypal_args['item_name_' . $i]        = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8'));
97
+                $paypal_args['quantity_' . $i]         = $item['quantity'];
98
+                $paypal_args['amount_' . $i]           = $item_amount;
99
+                $paypal_args['discount_amount_' . $i]  = $item['discount'];
100 100
 
101 101
                 $i++;
102 102
             }
103 103
         }
104 104
 
105 105
         // Add taxes to the cart
106
-        if ( wpinv_use_taxes() ) {
107
-            $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float)$invoice->get_tax() );
106
+        if (wpinv_use_taxes()) {
107
+            $paypal_args['tax_cart'] = wpinv_sanitize_amount((float)$invoice->get_tax());
108 108
         }
109 109
 
110
-        $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice );
110
+        $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice);
111 111
 
112 112
         // Build query
113
-        $paypal_redirect .= http_build_query( $paypal_args );
113
+        $paypal_redirect .= http_build_query($paypal_args);
114 114
 
115 115
         // Fix for some sites that encode the entities
116
-        $paypal_redirect = str_replace( '&amp;', '&', $paypal_redirect );
116
+        $paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
117 117
 
118 118
         // Get rid of cart contents
119 119
         wpinv_empty_cart();
120 120
         
121 121
         // Redirect to PayPal
122
-        wp_redirect( $paypal_redirect );
122
+        wp_redirect($paypal_redirect);
123 123
         exit;
124 124
     }
125 125
 }
126
-add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' );
126
+add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment');
127 127
 
128
-function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) {
129
-    if ( $invoice->is_recurring() && $item_id = $invoice->get_recurring() ) {
130
-        $item   = new WPInv_Item( $item_id );
128
+function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) {
129
+    if ($invoice->is_recurring() && $item_id = $invoice->get_recurring()) {
130
+        $item = new WPInv_Item($item_id);
131 131
         
132
-        if ( empty( $item ) ) {
132
+        if (empty($item)) {
133 133
             return $paypal_args;
134 134
         }
135 135
 
@@ -137,24 +137,24 @@  discard block
 block discarded – undo
137 137
         $interval           = $item->get_recurring_interval();
138 138
         $bill_times         = (int)$item->get_recurring_limit();
139 139
         
140
-        $initial_amount     = wpinv_round_amount( $invoice->get_total() );
141
-        $recurring_amount   = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) );
140
+        $initial_amount     = wpinv_round_amount($invoice->get_total());
141
+        $recurring_amount   = wpinv_round_amount($invoice->get_recurring_details('total'));
142 142
         
143 143
         $paypal_args['cmd'] = '_xclick-subscriptions';
144 144
         $paypal_args['sra'] = '1';
145 145
         $paypal_args['src'] = '1';
146 146
         
147 147
         // Set item description
148
-        $paypal_args['item_name']   = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( array( 'id' => $item->ID ) ), ENT_COMPAT, 'UTF-8' ) );
148
+        $paypal_args['item_name'] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name(array('id' => $item->ID)), ENT_COMPAT, 'UTF-8'));
149 149
         
150
-        if ( $invoice->is_free_trial() && $item->has_free_trial() ) {
150
+        if ($invoice->is_free_trial() && $item->has_free_trial()) {
151 151
             $paypal_args['a1']  = $initial_amount;
152 152
             $paypal_args['p1']  = $item->get_trial_interval();
153 153
             $paypal_args['t1']  = $item->get_trial_period();
154 154
             
155 155
             // Set the recurring amount
156 156
             $paypal_args['a3']  = $recurring_amount;
157
-        } else if ( $initial_amount != $recurring_amount && $bill_times != 1 ) {
157
+        } else if ($initial_amount != $recurring_amount && $bill_times != 1) {
158 158
             $paypal_args['a1']  = $initial_amount;
159 159
             $paypal_args['p1']  = $interval;
160 160
             $paypal_args['t1']  = $period;
@@ -162,63 +162,63 @@  discard block
 block discarded – undo
162 162
             // Set the recurring amount
163 163
             $paypal_args['a3']  = $recurring_amount;
164 164
             
165
-            if ( $bill_times > 1 ) {
165
+            if ($bill_times > 1) {
166 166
                 $bill_times--;
167 167
             }
168 168
         } else {
169
-            $paypal_args['a3']  = $initial_amount;
169
+            $paypal_args['a3'] = $initial_amount;
170 170
         }
171 171
         
172 172
         $paypal_args['p3']  = $interval;
173 173
         $paypal_args['t3']  = $period;
174 174
         
175
-        if ( $bill_times > 1 ) {
175
+        if ($bill_times > 1) {
176 176
             // Make sure it's not over the max of 52
177
-            $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
177
+            $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
178 178
         }
179 179
                 
180 180
         // Remove cart items
181 181
         $i = 1;
182
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
183
-            foreach ( $purchase_data['cart_details'] as $item ) {                
184
-                if ( isset( $paypal_args['item_number_' . $i] ) ) {
185
-                    unset( $paypal_args['item_number_' . $i] );
182
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
183
+            foreach ($purchase_data['cart_details'] as $item) {                
184
+                if (isset($paypal_args['item_number_' . $i])) {
185
+                    unset($paypal_args['item_number_' . $i]);
186 186
                 }
187
-                if ( isset( $paypal_args['item_name_' . $i] ) ) {
188
-                    unset( $paypal_args['item_name_' . $i] );
187
+                if (isset($paypal_args['item_name_' . $i])) {
188
+                    unset($paypal_args['item_name_' . $i]);
189 189
                 }
190
-                if ( isset( $paypal_args['quantity_' . $i] ) ) {
191
-                    unset( $paypal_args['quantity_' . $i] );
190
+                if (isset($paypal_args['quantity_' . $i])) {
191
+                    unset($paypal_args['quantity_' . $i]);
192 192
                 }
193
-                if ( isset( $paypal_args['amount_' . $i] ) ) {
194
-                    unset( $paypal_args['amount_' . $i] );
193
+                if (isset($paypal_args['amount_' . $i])) {
194
+                    unset($paypal_args['amount_' . $i]);
195 195
                 }
196
-                if ( isset( $paypal_args['discount_amount_' . $i] ) ) {
197
-                    unset( $paypal_args['discount_amount_' . $i] );
196
+                if (isset($paypal_args['discount_amount_' . $i])) {
197
+                    unset($paypal_args['discount_amount_' . $i]);
198 198
                 }
199 199
 
200 200
                 $i++;
201 201
             }
202 202
         }
203 203
         
204
-        if ( isset( $paypal_args['tax_cart'] ) ) {
205
-            unset( $paypal_args['tax_cart'] );
204
+        if (isset($paypal_args['tax_cart'])) {
205
+            unset($paypal_args['tax_cart']);
206 206
         }
207 207
                 
208
-        if ( isset( $paypal_args['upload'] ) ) {
209
-            unset( $paypal_args['upload'] );
208
+        if (isset($paypal_args['upload'])) {
209
+            unset($paypal_args['upload']);
210 210
         }
211 211
         
212
-        $paypal_args = apply_filters( 'wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice );
212
+        $paypal_args = apply_filters('wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice);
213 213
     }
214 214
     
215 215
     return $paypal_args;
216 216
 }
217
-add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 );
217
+add_filter('wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3);
218 218
 
219 219
 function wpinv_process_paypal_ipn() {
220 220
 	// Check the request method is POST
221
-	if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
221
+	if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
222 222
 		return;
223 223
 	}
224 224
 
@@ -226,11 +226,11 @@  discard block
 block discarded – undo
226 226
 	$post_data = '';
227 227
 
228 228
 	// Fallback just in case post_max_size is lower than needed
229
-	if ( ini_get( 'allow_url_fopen' ) ) {
230
-		$post_data = file_get_contents( 'php://input' );
229
+	if (ini_get('allow_url_fopen')) {
230
+		$post_data = file_get_contents('php://input');
231 231
 	} else {
232 232
 		// If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
233
-		ini_set( 'post_max_size', '12M' );
233
+		ini_set('post_max_size', '12M');
234 234
 	}
235 235
 	// Start the encoded data collection with notification command
236 236
 	$encoded_data = 'cmd=_notify-validate';
@@ -239,43 +239,43 @@  discard block
 block discarded – undo
239 239
 	$arg_separator = wpinv_get_php_arg_separator_output();
240 240
 
241 241
 	// Verify there is a post_data
242
-	if ( $post_data || strlen( $post_data ) > 0 ) {
242
+	if ($post_data || strlen($post_data) > 0) {
243 243
 		// Append the data
244
-		$encoded_data .= $arg_separator.$post_data;
244
+		$encoded_data .= $arg_separator . $post_data;
245 245
 	} else {
246 246
 		// Check if POST is empty
247
-		if ( empty( $_POST ) ) {
247
+		if (empty($_POST)) {
248 248
 			// Nothing to do
249 249
 			return;
250 250
 		} else {
251 251
 			// Loop through each POST
252
-			foreach ( $_POST as $key => $value ) {
252
+			foreach ($_POST as $key => $value) {
253 253
 				// Encode the value and append the data
254
-				$encoded_data .= $arg_separator."$key=" . urlencode( $value );
254
+				$encoded_data .= $arg_separator . "$key=" . urlencode($value);
255 255
 			}
256 256
 		}
257 257
 	}
258 258
 
259 259
 	// Convert collected post data to an array
260
-	parse_str( $encoded_data, $encoded_data_array );
260
+	parse_str($encoded_data, $encoded_data_array);
261 261
 
262
-	foreach ( $encoded_data_array as $key => $value ) {
263
-		if ( false !== strpos( $key, 'amp;' ) ) {
264
-			$new_key = str_replace( '&amp;', '&', $key );
265
-			$new_key = str_replace( 'amp;', '&' , $new_key );
262
+	foreach ($encoded_data_array as $key => $value) {
263
+		if (false !== strpos($key, 'amp;')) {
264
+			$new_key = str_replace('&amp;', '&', $key);
265
+			$new_key = str_replace('amp;', '&', $new_key);
266 266
 
267
-			unset( $encoded_data_array[ $key ] );
268
-			$encoded_data_array[ $new_key ] = $value;
267
+			unset($encoded_data_array[$key]);
268
+			$encoded_data_array[$new_key] = $value;
269 269
 		}
270 270
 	}
271 271
 
272 272
 	// Get the PayPal redirect uri
273
-	$paypal_redirect = wpinv_get_paypal_redirect( true );
273
+	$paypal_redirect = wpinv_get_paypal_redirect(true);
274 274
 
275
-	if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
275
+	if (!wpinv_get_option('disable_paypal_verification', false)) {
276 276
 		// Validate the IPN
277 277
 
278
-		$remote_post_vars      = array(
278
+		$remote_post_vars = array(
279 279
 			'method'           => 'POST',
280 280
 			'timeout'          => 45,
281 281
 			'redirection'      => 5,
@@ -293,21 +293,21 @@  discard block
 block discarded – undo
293 293
 		);
294 294
 
295 295
 		// Get response
296
-		$api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
296
+		$api_response = wp_remote_post(wpinv_get_paypal_redirect(), $remote_post_vars);
297 297
 
298
-		if ( is_wp_error( $api_response ) ) {
299
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
298
+		if (is_wp_error($api_response)) {
299
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response)));
300 300
 			return; // Something went wrong
301 301
 		}
302 302
 
303
-		if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
304
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
303
+		if ($api_response['body'] !== 'VERIFIED' && wpinv_get_option('disable_paypal_verification', false)) {
304
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response)));
305 305
 			return; // Response not okay
306 306
 		}
307 307
 	}
308 308
 
309 309
 	// Check if $post_data_array has been populated
310
-	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
310
+	if (!is_array($encoded_data_array) && !empty($encoded_data_array))
311 311
 		return;
312 312
 
313 313
 	$defaults = array(
@@ -315,215 +315,215 @@  discard block
 block discarded – undo
315 315
 		'payment_status' => ''
316 316
 	);
317 317
 
318
-	$encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
318
+	$encoded_data_array = wp_parse_args($encoded_data_array, $defaults);
319 319
 
320
-	$invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
320
+	$invoice_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0;
321 321
     
322
-	wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
322
+	wpinv_error_log($encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__);
323 323
 
324
-	if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
324
+	if (has_action('wpinv_paypal_' . $encoded_data_array['txn_type'])) {
325 325
 		// Allow PayPal IPN types to be processed separately
326
-		do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
326
+		do_action('wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id);
327 327
 	} else {
328 328
 		// Fallback to web accept just in case the txn_type isn't present
329
-		do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
329
+		do_action('wpinv_paypal_web_accept', $encoded_data_array, $invoice_id);
330 330
 	}
331 331
 	exit;
332 332
 }
333
-add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' );
333
+add_action('wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn');
334 334
 
335
-function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) {
336
-	if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
335
+function wpinv_process_paypal_web_accept_and_cart($data, $invoice_id) {
336
+	if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') {
337 337
 		return;
338 338
 	}
339 339
 
340
-	if( empty( $invoice_id ) ) {
340
+	if (empty($invoice_id)) {
341 341
 		return;
342 342
 	}
343 343
 
344 344
 	// Collect payment details
345
-	$purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
345
+	$purchase_key   = isset($data['invoice']) ? $data['invoice'] : $data['item_number'];
346 346
 	$paypal_amount  = $data['mc_gross'];
347
-	$payment_status = strtolower( $data['payment_status'] );
348
-	$currency_code  = strtolower( $data['mc_currency'] );
349
-	$business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
350
-	$payment_meta   = wpinv_get_invoice_meta( $invoice_id );
347
+	$payment_status = strtolower($data['payment_status']);
348
+	$currency_code  = strtolower($data['mc_currency']);
349
+	$business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']);
350
+	$payment_meta   = wpinv_get_invoice_meta($invoice_id);
351 351
 
352
-	if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
352
+	if (wpinv_get_payment_gateway($invoice_id) != 'paypal') {
353 353
 		return; // this isn't a PayPal standard IPN
354 354
 	}
355 355
 
356 356
 	// Verify payment recipient
357
-	if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
358
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
359
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
360
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ) );
357
+	if (strcasecmp($business_email, trim(wpinv_get_option('paypal_email', false))) != 0) {
358
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
359
+		wpinv_update_payment_status($invoice_id, 'wpi-failed');
360
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid PayPal business email.', 'invoicing'));
361 361
 		return;
362 362
 	}
363 363
 
364 364
 	// Verify payment currency
365
-	if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
366
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
367
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
368
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ) );
365
+	if ($currency_code != strtolower($payment_meta['currency'])) {
366
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
367
+		wpinv_update_payment_status($invoice_id, 'wpi-failed');
368
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid currency in PayPal IPN.', 'invoicing'));
369 369
 		return;
370 370
 	}
371 371
 
372
-	if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
372
+	if (!wpinv_get_payment_user_email($invoice_id)) {
373 373
 		// This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
374 374
 		// No email associated with purchase, so store from PayPal
375
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
375
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_email', $data['payer_email']);
376 376
 
377 377
 		// Setup and store the customer's details
378 378
 		$user_info = array(
379 379
 			'user_id'    => '-1',
380
-			'email'      => sanitize_text_field( $data['payer_email'] ),
381
-			'first_name' => sanitize_text_field( $data['first_name'] ),
382
-			'last_name'  => sanitize_text_field( $data['last_name'] ),
380
+			'email'      => sanitize_text_field($data['payer_email']),
381
+			'first_name' => sanitize_text_field($data['first_name']),
382
+			'last_name'  => sanitize_text_field($data['last_name']),
383 383
 			'discount'   => '',
384 384
 		);
385
-		$user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
386
-		$user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
387
-		$user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
388
-		$user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
389
-		$user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
385
+		$user_info['address'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false;
386
+		$user_info['city']    = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false;
387
+		$user_info['state']   = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false;
388
+		$user_info['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false;
389
+		$user_info['zip']     = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false;
390 390
 
391 391
 		$payment_meta['user_info'] = $user_info;
392
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
392
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_payment_meta', $payment_meta);
393 393
 	}
394 394
 
395
-	if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
395
+	if ($payment_status == 'refunded' || $payment_status == 'reversed') {
396 396
 		// Process a refund
397
-		wpinv_process_paypal_refund( $data, $invoice_id );
397
+		wpinv_process_paypal_refund($data, $invoice_id);
398 398
 	} else {
399
-		if ( get_post_status( $invoice_id ) == 'publish' ) {
399
+		if (get_post_status($invoice_id) == 'publish') {
400 400
 			return; // Only paid payments once
401 401
 		}
402 402
 
403 403
 		// Retrieve the total purchase amount (before PayPal)
404
-		$payment_amount = wpinv_payment_total( $invoice_id );
404
+		$payment_amount = wpinv_payment_total($invoice_id);
405 405
 
406
-		if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
406
+		if (number_format((float)$paypal_amount, 2) < number_format((float)$payment_amount, 2)) {
407 407
 			// The prices don't match
408
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
409
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
410
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ) );
408
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
409
+			wpinv_update_payment_status($invoice_id, 'wpi-failed');
410
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid amount in PayPal IPN.', 'invoicing'));
411 411
 			return;
412 412
 		}
413
-		if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
413
+		if ($purchase_key != wpinv_get_payment_key($invoice_id)) {
414 414
 			// Purchase keys don't match
415
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
416
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
417
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ) );
415
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
416
+			wpinv_update_payment_status($invoice_id, 'wpi-failed');
417
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing'));
418 418
 			return;
419 419
 		}
420 420
 
421
-		if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
422
-			wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ) );
423
-			wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
424
-			wpinv_update_payment_status( $invoice_id, 'publish' );
425
-		} else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
421
+		if ('complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode('paypal')) {
422
+			wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $data['txn_id']));
423
+			wpinv_set_payment_transaction_id($invoice_id, $data['txn_id']);
424
+			wpinv_update_payment_status($invoice_id, 'publish');
425
+		} else if ('pending' == $payment_status && isset($data['pending_reason'])) {
426 426
 			// Look for possible pending reasons, such as an echeck
427 427
 			$note = '';
428 428
 
429
-			switch( strtolower( $data['pending_reason'] ) ) {
429
+			switch (strtolower($data['pending_reason'])) {
430 430
 				case 'echeck' :
431
-					$note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
431
+					$note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing');
432 432
 					break;
433 433
 				
434 434
                 case 'address' :
435
-					$note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
435
+					$note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing');
436 436
 					break;
437 437
 				
438 438
                 case 'intl' :
439
-					$note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
439
+					$note = __('Payment must be accepted manually through PayPal due to international account regulations', 'invoicing');
440 440
 					break;
441 441
 				
442 442
                 case 'multi-currency' :
443
-					$note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
443
+					$note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing');
444 444
 					break;
445 445
 				
446 446
                 case 'paymentreview' :
447 447
                 case 'regulatory_review' :
448
-					$note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
448
+					$note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing');
449 449
 					break;
450 450
 				
451 451
                 case 'unilateral' :
452
-					$note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
452
+					$note = __('Payment was sent to non-confirmed or non-registered email address.', 'invoicing');
453 453
 					break;
454 454
 				
455 455
                 case 'upgrade' :
456
-					$note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
456
+					$note = __('PayPal account must be upgraded before this payment can be accepted', 'invoicing');
457 457
 					break;
458 458
 				
459 459
                 case 'verify' :
460
-					$note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
460
+					$note = __('PayPal account is not verified. Verify account in order to accept this payment', 'invoicing');
461 461
 					break;
462 462
 
463 463
 				case 'other' :
464
-					$note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
464
+					$note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing');
465 465
 					break;
466 466
 			}
467 467
 
468
-			if ( ! empty( $note ) ) {
469
-				wpinv_insert_payment_note( $invoice_id, $note );
468
+			if (!empty($note)) {
469
+				wpinv_insert_payment_note($invoice_id, $note);
470 470
 			}
471 471
 		} else {
472
-			wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ) );
472
+			wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal IPN has been received with invalid payment status: %s', 'invoicing'), $payment_status));
473 473
 		}
474 474
 	}
475 475
 }
476
-add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 );
476
+add_action('wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2);
477 477
 
478 478
 // Process PayPal subscription sign ups
479
-add_action( 'wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup' );
479
+add_action('wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup');
480 480
 
481 481
 // Process PayPal subscription payments
482
-add_action( 'wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment' );
482
+add_action('wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment');
483 483
 
484 484
 // Process PayPal subscription cancellations
485
-add_action( 'wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel' );
485
+add_action('wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel');
486 486
 
487 487
 // Process PayPal subscription end of term notices
488
-add_action( 'wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot' );
488
+add_action('wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot');
489 489
 
490 490
 // Process PayPal payment failed
491
-add_action( 'wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed' );
491
+add_action('wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed');
492 492
 
493 493
 
494 494
 /**
495 495
  * Process the subscription started IPN.
496 496
  */
497
-function wpinv_process_paypal_subscr_signup( $ipn_data ) {
498
-    $parent_invoice_id = absint( $ipn_data['custom'] );
499
-    if( empty( $parent_invoice_id ) ) {
497
+function wpinv_process_paypal_subscr_signup($ipn_data) {
498
+    $parent_invoice_id = absint($ipn_data['custom']);
499
+    if (empty($parent_invoice_id)) {
500 500
         return;
501 501
     }
502 502
 
503
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
504
-    if ( empty( $invoice ) ) {
503
+    $invoice = wpinv_get_invoice($parent_invoice_id);
504
+    if (empty($invoice)) {
505 505
         return;
506 506
     }
507 507
 
508
-    if ( $invoice->is_free_trial() && !empty( $ipn_data['invoice'] ) ) {
509
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Invoice ID: %s', 'invoicing' ) , $ipn_data['invoice'] ) );
510
-        wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['invoice'] );
508
+    if ($invoice->is_free_trial() && !empty($ipn_data['invoice'])) {
509
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Invoice ID: %s', 'invoicing'), $ipn_data['invoice']));
510
+        wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['invoice']);
511 511
     }
512 512
     
513
-    wpinv_update_payment_status( $parent_invoice_id, 'publish' );
513
+    wpinv_update_payment_status($parent_invoice_id, 'publish');
514 514
     sleep(1);
515
-    wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ) );
515
+    wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']));
516 516
     
517
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
518
-    if ( false === $subscription ) {
517
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
518
+    if (false === $subscription) {
519 519
         return;
520 520
     }
521 521
 
522
-    $cart_details   = $invoice->cart_details;
522
+    $cart_details = $invoice->cart_details;
523 523
 
524
-    if ( !empty( $cart_details ) ) {
525
-        foreach ( $cart_details as $cart_item ) {
526
-            $item = new WPInv_Item( $cart_item['id'] );
524
+    if (!empty($cart_details)) {
525
+        foreach ($cart_details as $cart_item) {
526
+            $item = new WPInv_Item($cart_item['id']);
527 527
             
528 528
             $status = $invoice->is_free_trial() && $item->has_free_trial() ? 'trialing' : 'active';
529 529
             
@@ -532,15 +532,15 @@  discard block
 block discarded – undo
532 532
                 'status'            => $status,
533 533
                 'period'            => $item->get_recurring_period(),
534 534
                 'initial_amount'    => $invoice->get_total(),
535
-                'recurring_amount'  => $invoice->get_recurring_details( 'total' ),
535
+                'recurring_amount'  => $invoice->get_recurring_details('total'),
536 536
                 'interval'          => $item->get_recurring_interval(),
537 537
                 'bill_times'        => $item->get_recurring_limit(),
538
-                'expiration'        => $invoice->get_new_expiration( $cart_item['id'] ),
538
+                'expiration'        => $invoice->get_new_expiration($cart_item['id']),
539 539
                 'profile_id'        => $ipn_data['subscr_id'],
540
-                'created'           => date_i18n( 'Y-m-d H:i:s', strtotime( $ipn_data['subscr_date'] ) )
540
+                'created'           => date_i18n('Y-m-d H:i:s', strtotime($ipn_data['subscr_date']))
541 541
             );
542 542
             
543
-            if ( $item->has_free_trial() ) {
543
+            if ($item->has_free_trial()) {
544 544
                 $args['trial_period']      = $item->get_trial_period();
545 545
                 $args['trial_interval']    = $item->get_trial_interval();
546 546
             } else {
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
             }
550 550
             
551 551
 
552
-            $subscription->update_subscription( $args );
552
+            $subscription->update_subscription($args);
553 553
         }
554 554
     }
555 555
 }
@@ -557,39 +557,39 @@  discard block
 block discarded – undo
557 557
 /**
558 558
  * Process the subscription payment received IPN.
559 559
  */
560
-function wpinv_process_paypal_subscr_payment( $ipn_data ) {
561
-    $parent_invoice_id = absint( $ipn_data['custom'] );
560
+function wpinv_process_paypal_subscr_payment($ipn_data) {
561
+    $parent_invoice_id = absint($ipn_data['custom']);
562 562
     
563
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
564
-    if ( false === $subscription ) {
563
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
564
+    if (false === $subscription) {
565 565
         return;
566 566
     }
567 567
     
568
-    $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id );
569
-    $signup_date    = strtotime( $subscription->get_subscription_created() );
570
-    $today          = date_i18n( 'Y-m-d', $signup_date ) == date_i18n( 'Y-m-d', strtotime( $ipn_data['payment_date'] ) );
568
+    $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id);
569
+    $signup_date    = strtotime($subscription->get_subscription_created());
570
+    $today          = date_i18n('Y-m-d', $signup_date) == date_i18n('Y-m-d', strtotime($ipn_data['payment_date']));
571 571
 
572 572
     // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet.
573
-    if ( $today && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) {
574
-        wpinv_update_payment_status( $parent_invoice_id, 'publish' );
573
+    if ($today && (!$transaction_id || $transaction_id == $parent_invoice_id)) {
574
+        wpinv_update_payment_status($parent_invoice_id, 'publish');
575 575
         sleep(1);
576 576
         
577 577
         // This is the very first payment
578
-        wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] );
579
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) );
578
+        wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']);
579
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']));
580 580
         return;
581 581
     }
582 582
     
583
-    if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) {
583
+    if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) {
584 584
         return; // Payment already recorded
585 585
     }
586 586
 
587
-    $currency_code = strtolower( $ipn_data['mc_currency'] );
587
+    $currency_code = strtolower($ipn_data['mc_currency']);
588 588
 
589 589
     // verify details
590
-    if ( $currency_code != strtolower( wpinv_get_currency() ) ) {
590
+    if ($currency_code != strtolower(wpinv_get_currency())) {
591 591
         // the currency code is invalid
592
-        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) );
592
+        wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data)));
593 593
         return;
594 594
     }
595 595
 
@@ -598,11 +598,11 @@  discard block
 block discarded – undo
598 598
         'transaction_id' => $ipn_data['txn_id']
599 599
     );
600 600
     
601
-    $invoice = wpinv_recurring_add_subscription_payment( $parent_invoice_id, $args );
601
+    $invoice = wpinv_recurring_add_subscription_payment($parent_invoice_id, $args);
602 602
     
603
-    if ( !empty( $invoice ) ) {
603
+    if (!empty($invoice)) {
604 604
         sleep(1);
605
-        wpinv_insert_payment_note( $invoice->ID, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) );
605
+        wpinv_insert_payment_note($invoice->ID, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']));
606 606
 
607 607
         $invoice->renew_subscription();
608 608
     }
@@ -611,10 +611,10 @@  discard block
 block discarded – undo
611 611
 /**
612 612
  * Process the subscription canceled IPN.
613 613
  */
614
-function wpinv_process_paypal_subscr_cancel( $ipn_data ) {
615
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
614
+function wpinv_process_paypal_subscr_cancel($ipn_data) {
615
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
616 616
 
617
-    if( false === $subscription ) {
617
+    if (false === $subscription) {
618 618
         return;
619 619
     }
620 620
 
@@ -624,10 +624,10 @@  discard block
 block discarded – undo
624 624
 /**
625 625
  * Process the subscription expired IPN.
626 626
  */
627
-function wpinv_process_paypal_subscr_eot( $ipn_data ) {
628
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
627
+function wpinv_process_paypal_subscr_eot($ipn_data) {
628
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
629 629
 
630
-    if( false === $subscription ) {
630
+    if (false === $subscription) {
631 631
         return;
632 632
     }
633 633
 
@@ -637,45 +637,45 @@  discard block
 block discarded – undo
637 637
 /**
638 638
  * Process the subscription payment failed IPN.
639 639
  */
640
-function wpinv_process_paypal_subscr_failed( $ipn_data ) {
641
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
640
+function wpinv_process_paypal_subscr_failed($ipn_data) {
641
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
642 642
 
643
-    if( false === $subscription ) {
643
+    if (false === $subscription) {
644 644
         return;
645 645
     }
646 646
 
647 647
     $subscription->failing_subscription();
648 648
 
649
-    do_action( 'wpinv_recurring_payment_failed', $subscription );
649
+    do_action('wpinv_recurring_payment_failed', $subscription);
650 650
 }
651 651
 
652 652
 /**
653 653
  * Retrieve the subscription this IPN notice is for.
654 654
  */
655
-function wpinv_get_paypal_subscription( $ipn_data = array() ) {
656
-    $parent_invoice_id = absint( $ipn_data['custom'] );
655
+function wpinv_get_paypal_subscription($ipn_data = array()) {
656
+    $parent_invoice_id = absint($ipn_data['custom']);
657 657
 
658
-    if( empty( $parent_invoice_id ) ) {
658
+    if (empty($parent_invoice_id)) {
659 659
         return false;
660 660
     }
661 661
 
662
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
663
-    if ( empty( $invoice ) ) {
662
+    $invoice = wpinv_get_invoice($parent_invoice_id);
663
+    if (empty($invoice)) {
664 664
         return false;
665 665
     }
666 666
 
667
-    $subscription = wpinv_get_subscription( $ipn_data['subscr_id'], true );
667
+    $subscription = wpinv_get_subscription($ipn_data['subscr_id'], true);
668 668
 
669
-    if ( empty( $subscription ) ) {
670
-        $subs         = wpinv_get_subscriptions( array( 'parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1 ) );
671
-        $subscription = reset( $subs );
669
+    if (empty($subscription)) {
670
+        $subs         = wpinv_get_subscriptions(array('parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1));
671
+        $subscription = reset($subs);
672 672
 
673
-        if ( $subscription && $subscription->ID > 0 ) {
673
+        if ($subscription && $subscription->ID > 0) {
674 674
             // Update the profile ID so it is set for future renewals
675
-            $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) );
675
+            $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id'])));
676 676
         } else {
677 677
             $subscription = $invoice;
678
-            $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) );
678
+            $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id'])));
679 679
             // No subscription found with a matching payment ID, bail
680 680
             //return false;
681 681
         }
@@ -685,39 +685,39 @@  discard block
 block discarded – undo
685 685
 
686 686
 }
687 687
 
688
-function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) {
688
+function wpinv_process_paypal_refund($data, $invoice_id = 0) {
689 689
 	// Collect payment details
690 690
 
691
-	if( empty( $invoice_id ) ) {
691
+	if (empty($invoice_id)) {
692 692
 		return;
693 693
 	}
694 694
 
695
-	if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
695
+	if (get_post_status($invoice_id) == 'wpi-refunded') {
696 696
 		return; // Only refund payments once
697 697
 	}
698 698
 
699
-	$payment_amount = wpinv_payment_total( $invoice_id );
699
+	$payment_amount = wpinv_payment_total($invoice_id);
700 700
 	$refund_amount  = $data['mc_gross'] * -1;
701 701
 
702
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
703
-		wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Partial PayPal refund processed: %s', 'invoicing' ), $data['parent_txn_id'] ) );
702
+	if (number_format((float)$refund_amount, 2) < number_format((float)$payment_amount, 2)) {
703
+		wpinv_insert_payment_note($invoice_id, sprintf(__('Partial PayPal refund processed: %s', 'invoicing'), $data['parent_txn_id']));
704 704
 		return; // This is a partial refund
705 705
 	}
706 706
 
707
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ) );
708
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ) );
709
-	wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
707
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code']));
708
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id']));
709
+	wpinv_update_payment_status($invoice_id, 'wpi-refunded');
710 710
 }
711 711
 
712
-function wpinv_get_paypal_redirect( $ssl_check = false ) {
713
-    if ( is_ssl() || ! $ssl_check ) {
712
+function wpinv_get_paypal_redirect($ssl_check = false) {
713
+    if (is_ssl() || !$ssl_check) {
714 714
         $protocol = 'https://';
715 715
     } else {
716 716
         $protocol = 'http://';
717 717
     }
718 718
 
719 719
     // Check the current payment mode
720
-    if ( wpinv_is_test_mode( 'paypal' ) ) {
720
+    if (wpinv_is_test_mode('paypal')) {
721 721
         // Test mode
722 722
         $paypal_uri = $protocol . 'www.sandbox.paypal.com/cgi-bin/webscr';
723 723
     } else {
@@ -725,67 +725,67 @@  discard block
 block discarded – undo
725 725
         $paypal_uri = $protocol . 'www.paypal.com/cgi-bin/webscr';
726 726
     }
727 727
 
728
-    return apply_filters( 'wpinv_paypal_uri', $paypal_uri );
728
+    return apply_filters('wpinv_paypal_uri', $paypal_uri);
729 729
 }
730 730
 
731
-function wpinv_paypal_success_page_content( $content ) {
731
+function wpinv_paypal_success_page_content($content) {
732 732
     global $wpi_invoice;
733 733
     
734 734
     $session = wpinv_get_checkout_session();
735 735
 
736
-    if ( empty( $_GET['invoice-id'] ) && empty( $session['invoice_key'] )  ) {
736
+    if (empty($_GET['invoice-id']) && empty($session['invoice_key'])) {
737 737
         return $content;
738 738
     }
739 739
 
740
-    $invoice_id = !empty( $_GET['invoice-id'] ) ? absint( $_GET['invoice-id'] ) : wpinv_get_invoice_id_by_key( $session['invoice_key'] );
740
+    $invoice_id = !empty($_GET['invoice-id']) ? absint($_GET['invoice-id']) : wpinv_get_invoice_id_by_key($session['invoice_key']);
741 741
 
742
-    if ( empty(  $invoice_id ) ) {
742
+    if (empty($invoice_id)) {
743 743
         return $content;
744 744
     }
745 745
 
746
-    $wpi_invoice = wpinv_get_invoice( $invoice_id );
746
+    $wpi_invoice = wpinv_get_invoice($invoice_id);
747 747
     
748
-    if ( !empty( $wpi_invoice ) && 'pending' == $wpi_invoice->status ) {
748
+    if (!empty($wpi_invoice) && 'pending' == $wpi_invoice->status) {
749 749
         // Payment is still pending so show processing indicator to fix the Race Condition, issue #
750 750
         ob_start();
751
-        wpinv_get_template_part( 'wpinv-payment-processing' );
751
+        wpinv_get_template_part('wpinv-payment-processing');
752 752
         $content = ob_get_clean();
753 753
     }
754 754
 
755 755
     return $content;
756 756
 }
757
-add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' );
757
+add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content');
758 758
 
759
-function wpinv_paypal_get_transaction_id( $invoice_id ) {
759
+function wpinv_paypal_get_transaction_id($invoice_id) {
760 760
     $transaction_id = '';
761
-    $notes = wpinv_get_invoice_notes( $invoice_id );
761
+    $notes = wpinv_get_invoice_notes($invoice_id);
762 762
 
763
-    foreach ( $notes as $note ) {
764
-        if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) {
763
+    foreach ($notes as $note) {
764
+        if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) {
765 765
             $transaction_id = $match[1];
766 766
             continue;
767 767
         }
768 768
     }
769 769
 
770
-    return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id );
770
+    return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id);
771 771
 }
772
-add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 );
772
+add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1);
773 773
 
774
-function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) {
775
-    if ( $invoice->is_free_trial() || $transaction_id == $invoice_id ) { // Free trial does not have transaction at PayPal.
774
+function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) {
775
+    if ($invoice->is_free_trial() || $transaction_id == $invoice_id) { // Free trial does not have transaction at PayPal.
776 776
         $transaction_url = $invoice->get_view_url();
777 777
     } else {
778
-        $sandbox = wpinv_is_test_mode( 'paypal' ) ? '.sandbox' : '';
778
+        $sandbox = wpinv_is_test_mode('paypal') ? '.sandbox' : '';
779 779
         $transaction_url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=' . $transaction_id;
780 780
     }
781 781
 
782
-    $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>';
782
+    $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>';
783 783
 
784
-    return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice );
784
+    return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice);
785 785
 }
786
-add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 );
786
+add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3);
787 787
 
788 788
 function wpinv_gateway_paypal_button_label($label) {
789
-    return __( 'Proceed to PayPal', 'invoicing' );
789
+    return __('Proceed to PayPal', 'invoicing');
790 790
 }
791
-add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 );
792 791
\ No newline at end of file
792
+add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1);
793 793
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Spacing   +252 added lines, -252 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
6
-    if( empty( $field ) || empty( $value ) ) {
5
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
6
+    if (empty($field) || empty($value)) {
7 7
         return false;
8 8
     }
9 9
     
10 10
     $posts = array();
11 11
 
12
-    switch( strtolower( $field ) ) {
12
+    switch (strtolower($field)) {
13 13
         case 'id':
14
-            $item = get_post( $value );
14
+            $item = get_post($value);
15 15
 
16
-            if( get_post_type( $item ) != 'wpi_item' ) {
16
+            if (get_post_type($item) != 'wpi_item') {
17 17
                 return false;
18 18
             }
19 19
 
@@ -21,16 +21,16 @@  discard block
 block discarded – undo
21 21
 
22 22
         case 'slug':
23 23
         case 'name':
24
-            $posts = get_posts( array(
24
+            $posts = get_posts(array(
25 25
                 'post_type'      => 'wpi_item',
26 26
                 'name'           => $value,
27 27
                 'posts_per_page' => 1,
28 28
                 'post_status'    => 'any'
29
-            ) );
29
+            ));
30 30
 
31 31
             break;
32 32
         case 'package_id':
33
-            $posts = get_posts( array(
33
+            $posts = get_posts(array(
34 34
                 'post_type'      => 'wpi_item',
35 35
                 'posts_per_page' => 1,
36 36
                 'post_status'    => 'any',
@@ -46,11 +46,11 @@  discard block
 block discarded – undo
46 46
                         'value' => 'package',
47 47
                     )
48 48
                 )
49
-            ) );
49
+            ));
50 50
             
51 51
             break;
52 52
         case 'item_id':
53
-            if ( empty( $value ) ) {
53
+            if (empty($value)) {
54 54
                 return false;
55 55
             }
56 56
             
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
                 'key'   => '_wpinv_post_id',
60 60
                 'value' => $value,
61 61
             );
62
-            if ( !empty( $type ) ) {
62
+            if (!empty($type)) {
63 63
                 $meta_query[] = array(
64 64
                     'key'   => '_wpinv_type',
65 65
                     'value' => $type,
@@ -72,14 +72,14 @@  discard block
 block discarded – undo
72 72
                 'post_status'    => 'any',
73 73
                 'orderby'        => 'ID',
74 74
                 'order'          => 'ASC',
75
-                'meta_query'     => array( $meta_query )
75
+                'meta_query'     => array($meta_query)
76 76
             );
77 77
             
78
-            $posts = get_posts( $args );
78
+            $posts = get_posts($args);
79 79
 
80 80
             break;
81 81
         case 'custom':
82
-            if ( empty( $value ) || empty( $type ) ) {
82
+            if (empty($value) || empty($type)) {
83 83
                 return false;
84 84
             }
85 85
             
@@ -99,10 +99,10 @@  discard block
 block discarded – undo
99 99
                 'post_status'    => 'any',
100 100
                 'orderby'        => 'ID',
101 101
                 'order'          => 'ASC',
102
-                'meta_query'     => array( $meta_query )
102
+                'meta_query'     => array($meta_query)
103 103
             );
104 104
             
105
-            $posts = get_posts( $args );
105
+            $posts = get_posts($args);
106 106
 
107 107
             break;
108 108
 
@@ -110,17 +110,17 @@  discard block
 block discarded – undo
110 110
             return false;
111 111
     }
112 112
     
113
-    if ( !empty( $posts[0] ) ) {
114
-        return new WPInv_Item( $posts[0]->ID );
113
+    if (!empty($posts[0])) {
114
+        return new WPInv_Item($posts[0]->ID);
115 115
     }
116 116
 
117 117
     return false;
118 118
 }
119 119
 
120
-function wpinv_get_item( $item = 0 ) {
121
-    if ( is_numeric( $item ) ) {
122
-        $item = get_post( $item );
123
-        if ( ! $item || 'wpi_item' !== $item->post_type )
120
+function wpinv_get_item($item = 0) {
121
+    if (is_numeric($item)) {
122
+        $item = get_post($item);
123
+        if (!$item || 'wpi_item' !== $item->post_type)
124 124
             return null;
125 125
         return $item;
126 126
     }
@@ -133,136 +133,136 @@  discard block
 block discarded – undo
133 133
 
134 134
     $item = get_posts($args);
135 135
 
136
-    if ( $item ) {
136
+    if ($item) {
137 137
         return $item[0];
138 138
     }
139 139
 
140 140
     return null;
141 141
 }
142 142
 
143
-function wpinv_is_free_item( $item_id = 0 ) {
144
-    if( empty( $item_id ) ) {
143
+function wpinv_is_free_item($item_id = 0) {
144
+    if (empty($item_id)) {
145 145
         return false;
146 146
     }
147 147
 
148
-    $item = new WPInv_Item( $item_id );
148
+    $item = new WPInv_Item($item_id);
149 149
     
150 150
     return $item->is_free();
151 151
 }
152 152
 
153
-function wpinv_get_item_price( $item_id = 0 ) {
154
-    if( empty( $item_id ) ) {
153
+function wpinv_get_item_price($item_id = 0) {
154
+    if (empty($item_id)) {
155 155
         return false;
156 156
     }
157 157
 
158
-    $item = new WPInv_Item( $item_id );
158
+    $item = new WPInv_Item($item_id);
159 159
     
160 160
     return $item->get_price();
161 161
 }
162 162
 
163
-function wpinv_is_recurring_item( $item_id = 0 ) {
164
-    if( empty( $item_id ) ) {
163
+function wpinv_is_recurring_item($item_id = 0) {
164
+    if (empty($item_id)) {
165 165
         return false;
166 166
     }
167 167
 
168
-    $item = new WPInv_Item( $item_id );
168
+    $item = new WPInv_Item($item_id);
169 169
     
170 170
     return $item->is_recurring();
171 171
 }
172 172
 
173
-function wpinv_item_price( $item_id = 0 ) {
174
-    if( empty( $item_id ) ) {
173
+function wpinv_item_price($item_id = 0) {
174
+    if (empty($item_id)) {
175 175
         return false;
176 176
     }
177 177
 
178
-    $price = wpinv_get_item_price( $item_id );
179
-    $price = wpinv_price( wpinv_format_amount( $price ) );
178
+    $price = wpinv_get_item_price($item_id);
179
+    $price = wpinv_price(wpinv_format_amount($price));
180 180
     
181
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
181
+    return apply_filters('wpinv_item_price', $price, $item_id);
182 182
 }
183 183
 
184
-function wpinv_item_show_price( $item_id = 0, $echo = true ) {
185
-    if ( empty( $item_id ) ) {
184
+function wpinv_item_show_price($item_id = 0, $echo = true) {
185
+    if (empty($item_id)) {
186 186
         $item_id = get_the_ID();
187 187
     }
188 188
 
189
-    $price = wpinv_item_price( $item_id );
189
+    $price = wpinv_item_price($item_id);
190 190
 
191
-    $price           = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id );
191
+    $price           = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id);
192 192
     $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>';
193
-    $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price );
193
+    $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price);
194 194
 
195
-    if ( $echo ) {
195
+    if ($echo) {
196 196
         echo $formatted_price;
197 197
     } else {
198 198
         return $formatted_price;
199 199
     }
200 200
 }
201 201
 
202
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
203
-    if ( is_null( $amount_override ) ) {
204
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
202
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
203
+    if (is_null($amount_override)) {
204
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
205 205
     } else {
206 206
         $original_price = $amount_override;
207 207
     }
208 208
     
209 209
     $price = $original_price;
210 210
 
211
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
211
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
212 212
 }
213 213
 
214
-function wpinv_item_cpt_singular_name( $item_id ) {
215
-    if( empty( $item_id ) ) {
214
+function wpinv_item_cpt_singular_name($item_id) {
215
+    if (empty($item_id)) {
216 216
         return false;
217 217
     }
218 218
 
219
-    $item = new WPInv_Item( $item_id );
219
+    $item = new WPInv_Item($item_id);
220 220
     
221 221
     return $item->get_cpt_singular_name();
222 222
 }
223 223
 
224 224
 function wpinv_get_item_types() {
225 225
     $item_types = array(
226
-            'custom'    => __( 'Standard', 'invoicing' ),
227
-            'fee'       => __( 'Fee', 'invoicing' ),
226
+            'custom'    => __('Standard', 'invoicing'),
227
+            'fee'       => __('Fee', 'invoicing'),
228 228
         );
229
-    return apply_filters( 'wpinv_get_item_types', $item_types );
229
+    return apply_filters('wpinv_get_item_types', $item_types);
230 230
 }
231 231
 
232 232
 function wpinv_item_types() {
233 233
     $item_types = wpinv_get_item_types();
234 234
     
235
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
235
+    return (!empty($item_types) ? array_keys($item_types) : array());
236 236
 }
237 237
 
238
-function wpinv_get_item_type( $item_id ) {
239
-    if( empty( $item_id ) ) {
238
+function wpinv_get_item_type($item_id) {
239
+    if (empty($item_id)) {
240 240
         return false;
241 241
     }
242 242
 
243
-    $item = new WPInv_Item( $item_id );
243
+    $item = new WPInv_Item($item_id);
244 244
     
245 245
     return $item->get_type();
246 246
 }
247 247
 
248
-function wpinv_item_type( $item_id ) {
248
+function wpinv_item_type($item_id) {
249 249
     $item_types = wpinv_get_item_types();
250 250
     
251
-    $item_type = wpinv_get_item_type( $item_id );
251
+    $item_type = wpinv_get_item_type($item_id);
252 252
     
253
-    if ( empty( $item_type ) ) {
253
+    if (empty($item_type)) {
254 254
         $item_type = '-';
255 255
     }
256 256
     
257
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
257
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
258 258
 
259
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
259
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
260 260
 }
261 261
 
262
-function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) {
262
+function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) {
263 263
     global $wpinv_logs;
264 264
     
265
-    if ( empty( $wpinv_logs ) ) {
265
+    if (empty($wpinv_logs)) {
266 266
         return false;
267 267
     }
268 268
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
         'log_type'		=> 'wpi_item'
272 272
     );
273 273
 
274
-    $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1;
274
+    $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1;
275 275
 
276 276
     $log_meta = array(
277 277
         'user_info'	=> $user_info,
@@ -281,247 +281,247 @@  discard block
 block discarded – undo
281 281
         'invoice_id'=> $invoice_id,
282 282
     );
283 283
 
284
-    $wpinv_logs->insert_log( $log_data, $log_meta );
284
+    $wpinv_logs->insert_log($log_data, $log_meta);
285 285
 }
286 286
 
287
-function wpinv_remove_item_logs_on_delete( $item_id = 0 ) {
288
-    if ( 'wpi_item' !== get_post_type( $item_id ) )
287
+function wpinv_remove_item_logs_on_delete($item_id = 0) {
288
+    if ('wpi_item' !== get_post_type($item_id))
289 289
         return;
290 290
 
291 291
     global $wpinv_logs;
292 292
     
293
-    if ( empty( $wpinv_logs ) ) {
293
+    if (empty($wpinv_logs)) {
294 294
         return false;
295 295
     }
296 296
 
297 297
     // Remove all log entries related to this item
298
-    $wpinv_logs->delete_logs( $item_id );
298
+    $wpinv_logs->delete_logs($item_id);
299 299
 }
300
-add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' );
300
+add_action('delete_post', 'wpinv_remove_item_logs_on_delete');
301 301
 
302
-function wpinv_get_random_item( $post_ids = true ) {
303
-    wpinv_get_random_items( 1, $post_ids );
302
+function wpinv_get_random_item($post_ids = true) {
303
+    wpinv_get_random_items(1, $post_ids);
304 304
 }
305 305
 
306
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
307
-    if ( $post_ids ) {
308
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
306
+function wpinv_get_random_items($num = 3, $post_ids = true) {
307
+    if ($post_ids) {
308
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
309 309
     } else {
310
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
310
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
311 311
     }
312 312
     
313
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
313
+    $args = apply_filters('wpinv_get_random_items', $args);
314 314
     
315
-    return get_posts( $args );
315
+    return get_posts($args);
316 316
 }
317 317
 
318
-function wpinv_get_item_token( $url = '' ) {
318
+function wpinv_get_item_token($url = '') {
319 319
     $args    = array();
320
-    $hash    = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' );
321
-    $secret  = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) );
320
+    $hash    = apply_filters('wpinv_get_url_token_algorithm', 'sha256');
321
+    $secret  = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt()));
322 322
 
323
-    $parts   = parse_url( $url );
323
+    $parts   = parse_url($url);
324 324
     $options = array();
325 325
 
326
-    if ( isset( $parts['query'] ) ) {
327
-        wp_parse_str( $parts['query'], $query_args );
326
+    if (isset($parts['query'])) {
327
+        wp_parse_str($parts['query'], $query_args);
328 328
 
329
-        if ( ! empty( $query_args['o'] ) ) {
330
-            $options = explode( ':', rawurldecode( $query_args['o'] ) );
329
+        if (!empty($query_args['o'])) {
330
+            $options = explode(':', rawurldecode($query_args['o']));
331 331
 
332
-            if ( in_array( 'ip', $options ) ) {
332
+            if (in_array('ip', $options)) {
333 333
                 $args['ip'] = wpinv_get_ip();
334 334
             }
335 335
 
336
-            if ( in_array( 'ua', $options ) ) {
336
+            if (in_array('ua', $options)) {
337 337
                 $ua = wpinv_get_user_agent();
338
-                $args['user_agent'] = rawurlencode( $ua );
338
+                $args['user_agent'] = rawurlencode($ua);
339 339
             }
340 340
         }
341 341
     }
342 342
 
343
-    $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options );
343
+    $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options);
344 344
 
345 345
     $args['secret'] = $secret;
346 346
     $args['token']  = false;
347 347
 
348
-    $url   = add_query_arg( $args, $url );
349
-    $parts = parse_url( $url );
348
+    $url   = add_query_arg($args, $url);
349
+    $parts = parse_url($url);
350 350
 
351
-    if ( ! isset( $parts['path'] ) ) {
351
+    if (!isset($parts['path'])) {
352 352
         $parts['path'] = '';
353 353
     }
354 354
 
355
-    $token = md5( $parts['path'] . '?' . $parts['query'] );
355
+    $token = md5($parts['path'] . '?' . $parts['query']);
356 356
 
357 357
     return $token;
358 358
 }
359 359
 
360
-function wpinv_validate_url_token( $url = '' ) {
360
+function wpinv_validate_url_token($url = '') {
361 361
     $ret   = false;
362
-    $parts = parse_url( $url );
362
+    $parts = parse_url($url);
363 363
 
364
-    if ( isset( $parts['query'] ) ) {
365
-        wp_parse_str( $parts['query'], $query_args );
364
+    if (isset($parts['query'])) {
365
+        wp_parse_str($parts['query'], $query_args);
366 366
 
367
-        $allowed = apply_filters( 'wpinv_url_token_allowed_params', array(
367
+        $allowed = apply_filters('wpinv_url_token_allowed_params', array(
368 368
             'item',
369 369
             'ttl',
370 370
             'token'
371
-        ) );
371
+        ));
372 372
 
373 373
         $remove = array();
374 374
 
375
-        foreach( $query_args as $key => $value ) {
376
-            if( false === in_array( $key, $allowed ) ) {
375
+        foreach ($query_args as $key => $value) {
376
+            if (false === in_array($key, $allowed)) {
377 377
                 $remove[] = $key;
378 378
             }
379 379
         }
380 380
 
381
-        if( ! empty( $remove ) ) {
382
-            $url = remove_query_arg( $remove, $url );
381
+        if (!empty($remove)) {
382
+            $url = remove_query_arg($remove, $url);
383 383
         }
384 384
 
385
-        if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) {
386
-            wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
385
+        if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) {
386
+            wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403));
387 387
         }
388 388
 
389
-        if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) {
389
+        if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) {
390 390
             $ret = true;
391 391
         }
392 392
 
393 393
     }
394 394
 
395
-    return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args );
395
+    return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args);
396 396
 }
397 397
 
398
-function wpinv_item_in_cart( $item_id = 0, $options = array() ) {
398
+function wpinv_item_in_cart($item_id = 0, $options = array()) {
399 399
     $cart_items = wpinv_get_cart_contents();
400 400
 
401 401
     $ret = false;
402 402
 
403
-    if ( is_array( $cart_items ) ) {
404
-        foreach ( $cart_items as $item ) {
405
-            if ( $item['id'] == $item_id ) {
403
+    if (is_array($cart_items)) {
404
+        foreach ($cart_items as $item) {
405
+            if ($item['id'] == $item_id) {
406 406
                 $ret = true;
407 407
                 break;
408 408
             }
409 409
         }
410 410
     }
411 411
 
412
-    return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options );
412
+    return (bool)apply_filters('wpinv_item_in_cart', $ret, $item_id, $options);
413 413
 }
414 414
 
415
-function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) {
415
+function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) {
416 416
     $tax = 0;
417
-    if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) {
418
-        $country = !empty( $_POST['country'] ) ? $_POST['country'] : false;
419
-        $state   = isset( $_POST['state'] ) ? $_POST['state'] : '';
417
+    if (!wpinv_item_is_tax_exclusive($item_id)) {
418
+        $country = !empty($_POST['country']) ? $_POST['country'] : false;
419
+        $state   = isset($_POST['state']) ? $_POST['state'] : '';
420 420
 
421
-        $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id );
421
+        $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id);
422 422
     }
423 423
 
424
-    return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options );
424
+    return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options);
425 425
 }
426 426
 
427
-function wpinv_cart_item_price( $item ) {
427
+function wpinv_cart_item_price($item) {
428 428
     $use_taxes  = wpinv_use_taxes();
429
-    $item_id    = isset( $item['id'] ) ? $item['id'] : 0;
430
-    $price      = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0;
431
-    $options    = isset( $item['options'] ) ? $item['options'] : array();
432
-    $price_id   = isset( $options['price_id'] ) ? $options['price_id'] : false;
433
-    $tax        = wpinv_price( wpinv_format_amount( $item['tax'] ) );
434
-    
435
-    if ( !wpinv_is_free_item( $item_id, $price_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) {
436
-        if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) {
429
+    $item_id    = isset($item['id']) ? $item['id'] : 0;
430
+    $price      = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0;
431
+    $options    = isset($item['options']) ? $item['options'] : array();
432
+    $price_id   = isset($options['price_id']) ? $options['price_id'] : false;
433
+    $tax        = wpinv_price(wpinv_format_amount($item['tax']));
434
+    
435
+    if (!wpinv_is_free_item($item_id, $price_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 ) );
445
+    $price = wpinv_price(wpinv_format_amount($price));
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 ) {
451
-    $subtotal   = isset( $item['subtotal'] ) ? $item['subtotal'] : 0;
452
-    $subtotal   = wpinv_price( wpinv_format_amount( $subtotal ) );
450
+function wpinv_cart_item_subtotal($item) {
451
+    $subtotal   = isset($item['subtotal']) ? $item['subtotal'] : 0;
452
+    $subtotal   = wpinv_price(wpinv_format_amount($subtotal));
453 453
 
454
-    return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item );
454
+    return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item);
455 455
 }
456 456
 
457
-function wpinv_cart_item_tax( $item ) {
457
+function wpinv_cart_item_tax($item) {
458 458
     $tax        = '';
459 459
     $tax_rate   = '';
460 460
     
461
-    if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) {
462
-        $tax      = wpinv_price( wpinv_format_amount( $item['tax'] ) );
463
-        $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100;
464
-        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate ) : '';
461
+    if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) {
462
+        $tax      = wpinv_price(wpinv_format_amount($item['tax']));
463
+        $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100;
464
+        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate) : '';
465 465
         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : '';
466 466
     }
467 467
     
468
-    $tax        = $tax . $tax_rate;
468
+    $tax = $tax . $tax_rate;
469 469
     
470
-    if ( $tax === '' ) {
470
+    if ($tax === '') {
471 471
         $tax = 0; // Zero tax
472 472
     }
473 473
 
474
-    return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item );
474
+    return apply_filters('wpinv_cart_item_tax_label', $tax, $item);
475 475
 }
476 476
 
477
-function wpinv_get_cart_item_price( $item_id = 0, $options = array(), $remove_tax_from_inclusive = false ) {
477
+function wpinv_get_cart_item_price($item_id = 0, $options = array(), $remove_tax_from_inclusive = false) {
478 478
     $price = 0;
479
-    $variable_prices = wpinv_has_variable_prices( $item_id );
479
+    $variable_prices = wpinv_has_variable_prices($item_id);
480 480
 
481
-    if ( $variable_prices ) {
482
-        $prices = wpinv_get_variable_prices( $item_id );
481
+    if ($variable_prices) {
482
+        $prices = wpinv_get_variable_prices($item_id);
483 483
 
484
-        if ( $prices ) {
485
-            if( ! empty( $options ) ) {
486
-                $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false;
484
+        if ($prices) {
485
+            if (!empty($options)) {
486
+                $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false;
487 487
             } else {
488 488
                 $price = false;
489 489
             }
490 490
         }
491 491
     }
492 492
 
493
-    if( ! $variable_prices || false === $price ) {
493
+    if (!$variable_prices || false === $price) {
494 494
         // Get the standard Item price if not using variable prices
495
-        $price = wpinv_get_item_price( $item_id );
495
+        $price = wpinv_get_item_price($item_id);
496 496
     }
497 497
 
498
-    if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) {
499
-        $price -= wpinv_get_cart_item_tax( $item_id, $price, $options );
498
+    if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) {
499
+        $price -= wpinv_get_cart_item_tax($item_id, $price, $options);
500 500
     }
501 501
 
502
-    return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $options );
502
+    return apply_filters('wpinv_cart_item_price', $price, $item_id, $options);
503 503
 }
504 504
 
505
-function wpinv_get_cart_item_price_id( $item = array() ) {
506
-    if( isset( $item['item_number'] ) ) {
507
-        $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null;
505
+function wpinv_get_cart_item_price_id($item = array()) {
506
+    if (isset($item['item_number'])) {
507
+        $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null;
508 508
     } else {
509
-        $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null;
509
+        $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null;
510 510
     }
511 511
     return $price_id;
512 512
 }
513 513
 
514
-function wpinv_get_cart_item_price_name( $item = array() ) {
515
-    $price_id = (int)wpinv_get_cart_item_price_id( $item );
516
-    $prices   = wpinv_get_variable_prices( $item['id'] );
517
-    $name     = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : '';
518
-    return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item );
514
+function wpinv_get_cart_item_price_name($item = array()) {
515
+    $price_id = (int)wpinv_get_cart_item_price_id($item);
516
+    $prices   = wpinv_get_variable_prices($item['id']);
517
+    $name     = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : '';
518
+    return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item);
519 519
 }
520 520
 
521
-function wpinv_get_cart_item_name( $item = array() ) {
522
-    $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] );
521
+function wpinv_get_cart_item_name($item = array()) {
522
+    $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']);
523 523
 
524
-    if ( empty( $item_title ) ) {
524
+    if (empty($item_title)) {
525 525
         $item_title = $item['id'];
526 526
     }
527 527
 
@@ -531,23 +531,23 @@  discard block
 block discarded – undo
531 531
     }
532 532
     */
533 533
 
534
-    return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item );
534
+    return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item);
535 535
 }
536 536
 
537
-function wpinv_has_variable_prices( $item_id = 0 ) {
537
+function wpinv_has_variable_prices($item_id = 0) {
538 538
     return false;
539 539
 }
540 540
 
541
-function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) {
541
+function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) {
542 542
     $cart_items = wpinv_get_cart_contents();
543 543
 
544
-    if ( !is_array( $cart_items ) ) {
544
+    if (!is_array($cart_items)) {
545 545
         return false; // Empty cart
546 546
     } else {
547
-        foreach ( $cart_items as $position => $item ) {
548
-            if ( $item['id'] == $item_id ) {
549
-                if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) {
550
-                    if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) {
547
+        foreach ($cart_items as $position => $item) {
548
+            if ($item['id'] == $item_id) {
549
+                if (isset($options['price_id']) && isset($item['options']['price_id'])) {
550
+                    if ((int)$options['price_id'] == (int)$item['options']['price_id']) {
551 551
                         return $position;
552 552
                     }
553 553
                 } else {
@@ -560,80 +560,80 @@  discard block
 block discarded – undo
560 560
     return false; // Not found
561 561
 }
562 562
 
563
-function wpinv_get_cart_item_quantity( $item ) {
564
-    if ( wpinv_item_quantities_enabled() ) {
565
-        $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
563
+function wpinv_get_cart_item_quantity($item) {
564
+    if (wpinv_item_quantities_enabled()) {
565
+        $quantity = !empty($item['quantity']) && (int)$item['quantity'] > 0 ? absint($item['quantity']) : 1;
566 566
     } else {
567 567
         $quantity = 1;
568 568
     }
569 569
     
570
-    if ( $quantity < 1 ) {
570
+    if ($quantity < 1) {
571 571
         $quantity = 1;
572 572
     }
573 573
     
574
-    return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item );
574
+    return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item);
575 575
 }
576 576
 
577
-function wpinv_get_item_suffix( $item, $html = true ) {
578
-    if ( empty( $item ) ) {
577
+function wpinv_get_item_suffix($item, $html = true) {
578
+    if (empty($item)) {
579 579
         return NULL;
580 580
     }
581 581
     
582
-    if ( is_int( $item ) ) {
583
-        $item = new WPInv_Item( $item );
582
+    if (is_int($item)) {
583
+        $item = new WPInv_Item($item);
584 584
     }
585 585
     
586
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
586
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
587 587
         return NULL;
588 588
     }
589 589
     
590
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
590
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
591 591
     
592
-    if ( !$html && $suffix ) {
593
-        $suffix = strip_tags( $suffix );
592
+    if (!$html && $suffix) {
593
+        $suffix = strip_tags($suffix);
594 594
     }
595 595
     
596
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
596
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
597 597
 }
598 598
 
599
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
600
-    if ( empty( $item ) ) {
599
+function wpinv_remove_item($item = 0, $force_delete = false) {
600
+    if (empty($item)) {
601 601
         return NULL;
602 602
     }
603 603
     
604
-    if ( is_int( $item ) ) {
605
-        $item = new WPInv_Item( $item );
604
+    if (is_int($item)) {
605
+        $item = new WPInv_Item($item);
606 606
     }
607 607
     
608
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
608
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
609 609
         return NULL;
610 610
     }
611 611
     
612
-    do_action( 'wpinv_pre_delete_item', $item );
612
+    do_action('wpinv_pre_delete_item', $item);
613 613
 
614
-    wp_delete_post( $item->ID, $force_delete );
614
+    wp_delete_post($item->ID, $force_delete);
615 615
 
616
-    do_action( 'wpinv_post_delete_item', $item );
616
+    do_action('wpinv_post_delete_item', $item);
617 617
 }
618 618
 
619
-function wpinv_can_delete_item( $post_id ) {
620
-    $return = current_user_can( 'manage_options' ) ? true : false;
619
+function wpinv_can_delete_item($post_id) {
620
+    $return = current_user_can('manage_options') ? true : false;
621 621
     
622
-    if ( $return && wpinv_item_in_use( $post_id ) ) {
622
+    if ($return && wpinv_item_in_use($post_id)) {
623 623
         $return = false; // Don't delete item already use in invoices.
624 624
     }
625 625
     
626
-    return apply_filters( 'wpinv_can_delete_item', $return, $post_id );
626
+    return apply_filters('wpinv_can_delete_item', $return, $post_id);
627 627
 }
628 628
 
629 629
 function wpinv_admin_action_delete() {
630 630
     $screen = get_current_screen();
631 631
     
632
-    if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) {
632
+    if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) {
633 633
         $post_ids = array();
634 634
         
635
-        foreach ( $_REQUEST['post'] as $post_id ) {
636
-            if ( !wpinv_can_delete_item( $post_id ) ) {
635
+        foreach ($_REQUEST['post'] as $post_id) {
636
+            if (!wpinv_can_delete_item($post_id)) {
637 637
                 continue;
638 638
             }
639 639
             
@@ -643,83 +643,83 @@  discard block
 block discarded – undo
643 643
         $_REQUEST['post'] = $post_ids;
644 644
     }
645 645
 }
646
-add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 );
647
-add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 );
646
+add_action('admin_action_trash', 'wpinv_admin_action_delete', -10);
647
+add_action('admin_action_delete', 'wpinv_admin_action_delete', -10);
648 648
 
649
-function wpinv_check_delete_item( $check, $post, $force_delete ) {
650
-    if ( $post->post_type == 'wpi_item' ) {
651
-        if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) {
649
+function wpinv_check_delete_item($check, $post, $force_delete) {
650
+    if ($post->post_type == 'wpi_item') {
651
+        if ($force_delete && !wpinv_can_delete_item($post->ID)) {
652 652
             return true;
653 653
         }
654 654
     }
655 655
     
656 656
     return $check;
657 657
 }
658
-add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 );
658
+add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3);
659 659
 
660
-function wpinv_item_in_use( $item_id ) {
660
+function wpinv_item_in_use($item_id) {
661 661
     global $wpdb, $wpi_items_in_use;
662 662
     
663
-    if ( !$item_id > 0 ) {
663
+    if (!$item_id > 0) {
664 664
         return false;
665 665
     }
666 666
     
667
-    if ( !empty( $wpi_items_in_use ) ) {
668
-        if ( isset( $wpi_items_in_use[$item_id] ) ) {
667
+    if (!empty($wpi_items_in_use)) {
668
+        if (isset($wpi_items_in_use[$item_id])) {
669 669
             return $wpi_items_in_use[$item_id];
670 670
         }
671 671
     } else {
672 672
         $wpi_items_in_use = array();
673 673
     }
674 674
     
675
-    $statuses   = array_keys( wpinv_get_invoice_statuses( true ) );
675
+    $statuses = array_keys(wpinv_get_invoice_statuses(true));
676 676
     
677
-    $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 )";
678
-    $in_use = $wpdb->get_var( $query ) > 0 ? true : false;
677
+    $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 )";
678
+    $in_use = $wpdb->get_var($query) > 0 ? true : false;
679 679
     
680 680
     $wpi_items_in_use[$item_id] = $in_use;
681 681
     
682 682
     return $in_use;
683 683
 }
684 684
 
685
-function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) {
685
+function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) {
686 686
     // Set some defaults
687 687
     $defaults = array(
688
-        'type'               => 'custom',                                                // Optional. Item type. Default 'custom'.
689
-        'item_id'            => 0,                                                       // Required. Any integer number. Must be unique within item type.
690
-        'title'              => '',                                                      // Required. Item title.
691
-        'price'              => '0.00',                                                  // Optional. Item price. Default '0.00'.
692
-        'status'             => 'pending',                                               // Optional. pending, publish
693
-        'vat_rule'           => 'digital',                                               // Optional. digital => Digital item, physical => Physical item
694
-        'cpt_singular_name'  => '',                                                      // Optional. Sub title for item. Should be singular.
695
-        'cpt_name'           => '',                                                      // Optional. Sub title for item. Should be plural.
696
-        'is_recurring'       => 0,                                                       // Optional. 1 => Allow recurring or 0 => Don't allow recurring
697
-        'recurring_period'   => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
698
-        'recurring_interval' => 0,                                                       // Optional. Integer value between 1 - 90.
699
-        'recurring_limit'    => 0,                                                       // Optional. Any integer number. 0 for recurring forever until cancelled.
700
-        'free_trial'         => 0,                                                       // Optional. 1 => Allow free trial or 0 => Don't free trial
701
-        'trial_period'       => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
702
-        'trial_interval'     => 0,                                                       // Optional. Any integer number.
703
-        'excerpt'            => '',                                                      // Optional. Item short description
688
+        'type'               => 'custom', // Optional. Item type. Default 'custom'.
689
+        'item_id'            => 0, // Required. Any integer number. Must be unique within item type.
690
+        'title'              => '', // Required. Item title.
691
+        'price'              => '0.00', // Optional. Item price. Default '0.00'.
692
+        'status'             => 'pending', // Optional. pending, publish
693
+        'vat_rule'           => 'digital', // Optional. digital => Digital item, physical => Physical item
694
+        'cpt_singular_name'  => '', // Optional. Sub title for item. Should be singular.
695
+        'cpt_name'           => '', // Optional. Sub title for item. Should be plural.
696
+        'is_recurring'       => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring
697
+        'recurring_period'   => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
698
+        'recurring_interval' => 0, // Optional. Integer value between 1 - 90.
699
+        'recurring_limit'    => 0, // Optional. Any integer number. 0 for recurring forever until cancelled.
700
+        'free_trial'         => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial
701
+        'trial_period'       => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
702
+        'trial_interval'     => 0, // Optional. Any integer number.
703
+        'excerpt'            => '', // Optional. Item short description
704 704
     );
705 705
     
706
-    $data = wp_parse_args( $args, $defaults );
706
+    $data = wp_parse_args($args, $defaults);
707 707
     
708
-    if ( empty( $data['item_id'] ) ) {
709
-        if ( $wp_error ) {
710
-            return new WP_Error( 'invalid_item_id', __( 'Invalid item ID.' ) );
708
+    if (empty($data['item_id'])) {
709
+        if ($wp_error) {
710
+            return new WP_Error('invalid_item_id', __('Invalid item ID.'));
711 711
         } else {
712 712
             return false;
713 713
         }
714 714
     }
715 715
     
716
-    if ( empty( $data['type'] ) ) {
716
+    if (empty($data['type'])) {
717 717
         $data['type'] = 'custom';
718 718
     }
719 719
     
720
-    $item = wpinv_get_item_by( 'item_id', $data['item_id'], $data['type'] );
720
+    $item = wpinv_get_item_by('item_id', $data['item_id'], $data['type']);
721 721
         
722
-    if ( !$force_update && !empty( $item ) ) {
722
+    if (!$force_update && !empty($item)) {
723 723
         return $item;
724 724
     }
725 725
         
@@ -728,18 +728,18 @@  discard block
 block discarded – undo
728 728
     $meta['post_id']            = $data['item_id'];
729 729
     $meta['cpt_singular_name']  = $data['cpt_singular_name'];
730 730
     $meta['cpt_name']           = $data['cpt_name'];
731
-    $meta['price']              = wpinv_round_amount( $data['price'] );
731
+    $meta['price']              = wpinv_round_amount($data['price']);
732 732
     $meta['vat_rule']           = $data['vat_rule'];
733 733
     $meta['vat_class']          = '_standard';
734 734
     
735
-    if ( !empty( $data['is_recurring'] ) ) {
735
+    if (!empty($data['is_recurring'])) {
736 736
         $meta['is_recurring']       = $data['is_recurring'];
737 737
         $meta['recurring_period']   = $data['recurring_period'];
738
-        $meta['recurring_interval'] = absint( $data['recurring_interval'] );
739
-        $meta['recurring_limit']    = absint( $data['recurring_limit'] );
738
+        $meta['recurring_interval'] = absint($data['recurring_interval']);
739
+        $meta['recurring_limit']    = absint($data['recurring_limit']);
740 740
         $meta['free_trial']         = $data['free_trial'];
741 741
         $meta['trial_period']       = $data['trial_period'];
742
-        $meta['trial_interval']     = absint( $data['trial_interval'] );
742
+        $meta['trial_interval']     = absint($data['trial_interval']);
743 743
     } else {
744 744
         $meta['is_recurring']       = 0;
745 745
         $meta['recurring_period']   = '';
@@ -750,18 +750,18 @@  discard block
 block discarded – undo
750 750
         $meta['trial_interval']     = '';
751 751
     }
752 752
     
753
-    $post_data  = array( 
753
+    $post_data = array( 
754 754
         'post_title'    => $data['title'],
755 755
         'post_excerpt'  => $data['excerpt'],
756 756
         'post_status'   => $data['status'],
757 757
         'meta'          => $meta
758 758
     );
759 759
 
760
-    if ( !empty( $item ) ) {
761
-        $item->update( $post_data, $wp_error );
760
+    if (!empty($item)) {
761
+        $item->update($post_data, $wp_error);
762 762
     } else {
763 763
         $item = new WPInv_Item();
764
-        $item->create( $post_data, $wp_error );
764
+        $item->create($post_data, $wp_error);
765 765
     }
766 766
     
767 767
     return $item;
Please login to merge, or discard this patch.
includes/class-wpinv-api.php 1 patch
Spacing   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -7,22 +7,22 @@  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
 class WPInv_API {
15 15
     protected $post_type = 'wpi_invoice';
16 16
     
17
-    public function __construct( $params = array() ) {
17
+    public function __construct($params = array()) {
18 18
     }
19
-    public function insert_invoice( $data ) {
19
+    public function insert_invoice($data) {
20 20
         global $wpdb;
21 21
         //wpinv_transaction_query( 'start' );
22 22
 
23 23
         try {
24
-            if ( ! isset( $data['invoice'] ) ) {
25
-                throw new WPInv_API_Exception( 'wpinv_api_missing_invoice_data', sprintf( __( 'No %1$s data specified to create %1$s', 'invoicing' ), 'invoice' ), 400 );
24
+            if (!isset($data['invoice'])) {
25
+                throw new WPInv_API_Exception('wpinv_api_missing_invoice_data', sprintf(__('No %1$s data specified to create %1$s', 'invoicing'), 'invoice'), 400);
26 26
             }
27 27
 
28 28
             $data = $data['invoice'];
@@ -32,37 +32,37 @@  discard block
 block discarded – undo
32 32
                 //throw new WPInv_API_Exception( 'wpinv_api_user_cannot_create_invoice', __( 'You do not have permission to create invoices', 'invoicing' ), 401 );
33 33
             //}
34 34
 
35
-            $data = apply_filters( 'wpinv_api_create_invoice_data', $data, $this );
35
+            $data = apply_filters('wpinv_api_create_invoice_data', $data, $this);
36 36
 
37
-            $invoice = wpinv_insert_invoice( $data );
38
-            if ( is_wp_error( $invoice ) ) {
39
-                throw new WPInv_API_Exception( 'wpinv_api_cannot_create_invoice', sprintf( __( 'Cannot create invoice: %s', 'invoicing' ), implode( ', ', $invoice->get_error_messages() ) ), 400 );
37
+            $invoice = wpinv_insert_invoice($data);
38
+            if (is_wp_error($invoice)) {
39
+                throw new WPInv_API_Exception('wpinv_api_cannot_create_invoice', sprintf(__('Cannot create invoice: %s', 'invoicing'), implode(', ', $invoice->get_error_messages())), 400);
40 40
             }
41 41
 
42 42
             // HTTP 201 Created
43
-            $this->send_status( 201 );
43
+            $this->send_status(201);
44 44
 
45
-            do_action( 'wpinv_api_create_invoice', $invoice->ID, $data, $this );
45
+            do_action('wpinv_api_create_invoice', $invoice->ID, $data, $this);
46 46
 
47 47
             //wpinv_transaction_query( 'commit' );
48 48
 
49
-            return wpinv_get_invoice( $invoice->ID );
49
+            return wpinv_get_invoice($invoice->ID);
50 50
 
51
-        } catch ( WPInv_API_Exception $e ) {
51
+        } catch (WPInv_API_Exception $e) {
52 52
 
53 53
             //wpinv_transaction_query( 'rollback' );
54 54
 
55
-            return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
55
+            return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
56 56
         }
57 57
     }
58 58
     
59
-    public function create_invoice( $data ) {
59
+    public function create_invoice($data) {
60 60
         global $wpdb;
61 61
         //wpinv_transaction_query( 'start' );
62 62
 
63 63
         try {
64
-            if ( ! isset( $data['invoice'] ) ) {
65
-                throw new WPInv_API_Exception( 'wpinv_api_missing_invoice_data', sprintf( __( 'No %1$s data specified to create %1$s', 'invoicing' ), 'invoice' ), 400 );
64
+            if (!isset($data['invoice'])) {
65
+                throw new WPInv_API_Exception('wpinv_api_missing_invoice_data', sprintf(__('No %1$s data specified to create %1$s', 'invoicing'), 'invoice'), 400);
66 66
             }
67 67
 
68 68
             $data = $data['invoice'];
@@ -72,111 +72,111 @@  discard block
 block discarded – undo
72 72
                 //throw new WPInv_API_Exception( 'wpinv_api_user_cannot_create_invoice', __( 'You do not have permission to create invoices', 'invoicing' ), 401 );
73 73
             //}
74 74
 
75
-            $data = apply_filters( 'wpinv_api_create_invoice_data', $data, $this );
75
+            $data = apply_filters('wpinv_api_create_invoice_data', $data, $this);
76 76
 
77 77
             // default invoice args, note that status is checked for validity in wpinv_create_invoice()
78 78
             $default_invoice_args = array(
79
-                'status'        => isset( $data['status'] ) ? $data['status'] : '',
80
-                'user_note'     => isset( $data['note'] ) ? $data['note'] : null,
81
-                'invoice_id'    => isset( $data['invoice_id'] ) ? (int)$data['invoice_id'] : 0,
79
+                'status'        => isset($data['status']) ? $data['status'] : '',
80
+                'user_note'     => isset($data['note']) ? $data['note'] : null,
81
+                'invoice_id'    => isset($data['invoice_id']) ? (int)$data['invoice_id'] : 0,
82 82
             );
83 83
 
84 84
             // if creating invoice for existing user
85
-            if ( ! empty( $data['user_id'] ) ) {
85
+            if (!empty($data['user_id'])) {
86 86
                 // make sure user exists
87
-                if ( false === get_user_by( 'id', $data['user_id'] ) ) {
88
-                    throw new WPInv_API_Exception( 'wpinv_api_invalid_user_id', __( 'User ID is invalid', 'invoicing' ), 400 );
87
+                if (false === get_user_by('id', $data['user_id'])) {
88
+                    throw new WPInv_API_Exception('wpinv_api_invalid_user_id', __('User ID is invalid', 'invoicing'), 400);
89 89
                 }
90 90
 
91 91
                 $default_invoice_args['user_id'] = $data['user_id'];
92 92
             }
93 93
 
94 94
             // create the pending invoice
95
-            $invoice = $this->create_base_invoice( $default_invoice_args, $data );
95
+            $invoice = $this->create_base_invoice($default_invoice_args, $data);
96 96
 
97
-            if ( is_wp_error( $invoice ) ) {
98
-                throw new WPInv_API_Exception( 'wpinv_api_cannot_create_invoice', sprintf( __( 'Cannot create invoice: %s', 'invoicing' ), implode( ', ', $invoice->get_error_messages() ) ), 400 );
97
+            if (is_wp_error($invoice)) {
98
+                throw new WPInv_API_Exception('wpinv_api_cannot_create_invoice', sprintf(__('Cannot create invoice: %s', 'invoicing'), implode(', ', $invoice->get_error_messages())), 400);
99 99
             }
100 100
             
101 101
             // Add note
102
-            if ( !empty( $data['user_note'] ) ) {
103
-                $invoice->add_note( $data['user_note'], true );
102
+            if (!empty($data['user_note'])) {
103
+                $invoice->add_note($data['user_note'], true);
104 104
             }
105 105
             
106
-            if ( !empty( $data['private_note'] ) ) {
107
-                $invoice->add_note( $data['private_note'] );
106
+            if (!empty($data['private_note'])) {
107
+                $invoice->add_note($data['private_note']);
108 108
             }
109 109
 
110 110
             // billing address
111
-            $invoice = $this->set_billing_details( $invoice, $data );
111
+            $invoice = $this->set_billing_details($invoice, $data);
112 112
             
113 113
             // items
114
-            $invoice = $this->set_discount( $invoice, $data );
114
+            $invoice = $this->set_discount($invoice, $data);
115 115
 
116 116
             // items
117
-            $invoice = $this->set_items( $invoice, $data );
117
+            $invoice = $this->set_items($invoice, $data);
118 118
 
119 119
             // payment method (and payment_complete() if `paid` == true)
120
-            if ( isset( $data['payment_details'] ) && is_array( $data['payment_details'] ) ) {
120
+            if (isset($data['payment_details']) && is_array($data['payment_details'])) {
121 121
                 // method ID & title are required
122
-                if ( empty( $data['payment_details']['method_id'] ) || empty( $data['payment_details']['method_title'] ) ) {
123
-                    throw new WPInv_API_Exception( 'wpinv_invalid_payment_details', __( 'Payment method ID and title are required', 'invoicing' ), 400 );
122
+                if (empty($data['payment_details']['method_id']) || empty($data['payment_details']['method_title'])) {
123
+                    throw new WPInv_API_Exception('wpinv_invalid_payment_details', __('Payment method ID and title are required', 'invoicing'), 400);
124 124
                 }
125 125
                 
126 126
                  // set invoice currency
127
-                if ( isset( $data['payment_details']['currency'] ) ) {
128
-                    if ( ! array_key_exists( $data['payment_details']['currency'], wpinv_get_currencies() ) ) {
129
-                        throw new WPInv_API_Exception( 'wpinv_invalid_invoice_currency', __( 'Provided invoice currency is invalid', 'invoicing' ), 400 );
127
+                if (isset($data['payment_details']['currency'])) {
128
+                    if (!array_key_exists($data['payment_details']['currency'], wpinv_get_currencies())) {
129
+                        throw new WPInv_API_Exception('wpinv_invalid_invoice_currency', __('Provided invoice currency is invalid', 'invoicing'), 400);
130 130
                     }
131 131
 
132
-                    update_post_meta( $invoice->ID, '_wpinv_currency', $data['payment_details']['currency'] );
132
+                    update_post_meta($invoice->ID, '_wpinv_currency', $data['payment_details']['currency']);
133 133
                     
134 134
                     $invoice->currency = $data['payment_details']['currency'];
135 135
                 }
136 136
                 
137
-                update_post_meta( $invoice->ID, '_wpinv_gateway', $data['payment_details']['method_id'] );
138
-                update_post_meta( $invoice->ID, '_wpinv_gateway_title', $data['payment_details']['method_title'] );
137
+                update_post_meta($invoice->ID, '_wpinv_gateway', $data['payment_details']['method_id']);
138
+                update_post_meta($invoice->ID, '_wpinv_gateway_title', $data['payment_details']['method_title']);
139 139
                 
140 140
                 $invoice->gateway = $data['payment_details']['method_id'];
141 141
                 $invoice->gateway_title = $data['payment_details']['method_title'];
142 142
 
143 143
                 // mark as paid if set
144
-                if ( isset( $data['payment_details']['paid'] ) && true === $data['payment_details']['paid'] ) {
144
+                if (isset($data['payment_details']['paid']) && true === $data['payment_details']['paid']) {
145 145
                     //$invoice->payment_complete( isset( $data['payment_details']['transaction_id'] ) ? $data['payment_details']['transaction_id'] : $invoice->ID );
146 146
                 }
147 147
             }
148 148
           
149 149
             // set invoice meta
150
-            if ( isset( $data['invoice_meta'] ) && is_array( $data['invoice_meta'] ) ) {
151
-                $this->set_invoice_meta( $invoice->ID, $data['invoice_meta'] );
150
+            if (isset($data['invoice_meta']) && is_array($data['invoice_meta'])) {
151
+                $this->set_invoice_meta($invoice->ID, $data['invoice_meta']);
152 152
             }
153 153
 
154 154
             // HTTP 201 Created
155
-            $this->send_status( 201 );
155
+            $this->send_status(201);
156 156
 
157
-            do_action( 'wpinv_api_create_invoice', $invoice->ID, $data, $this );
157
+            do_action('wpinv_api_create_invoice', $invoice->ID, $data, $this);
158 158
 
159 159
             //wpinv_transaction_query( 'commit' );
160 160
 
161
-            return wpinv_get_invoice( $invoice->ID );
161
+            return wpinv_get_invoice($invoice->ID);
162 162
 
163
-        } catch ( WPInv_API_Exception $e ) {
163
+        } catch (WPInv_API_Exception $e) {
164 164
 
165 165
             //wpinv_transaction_query( 'rollback' );
166 166
 
167
-            return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
167
+            return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
168 168
         }
169 169
     }
170 170
     
171
-    public function send_status( $code ) {
172
-        status_header( $code );
171
+    public function send_status($code) {
172
+        status_header($code);
173 173
     }
174 174
     
175
-    protected function create_base_invoice( $args, $data ) {
176
-        return wpinv_create_invoice( $args, $data );
175
+    protected function create_base_invoice($args, $data) {
176
+        return wpinv_create_invoice($args, $data);
177 177
     }
178 178
     
179
-    protected function set_billing_details( $invoice, $data ) {
179
+    protected function set_billing_details($invoice, $data) {
180 180
         $address_fields = array(
181 181
             'user_id',
182 182
             'first_name',
@@ -195,66 +195,66 @@  discard block
 block discarded – undo
195 195
         $billing_details = array();
196 196
         $user_id = $invoice->get_user_id();
197 197
         
198
-        foreach ( $address_fields as $field ) {
199
-            if ( isset( $data['billing_details'][ $field ] ) ) {
200
-                $value = sanitize_text_field( $data['billing_details'][ $field ] );
198
+        foreach ($address_fields as $field) {
199
+            if (isset($data['billing_details'][$field])) {
200
+                $value = sanitize_text_field($data['billing_details'][$field]);
201 201
                 
202
-                if ( $field == 'country' && empty( $value ) ) {
203
-                    if ( !empty( $invoice->country ) ) {
202
+                if ($field == 'country' && empty($value)) {
203
+                    if (!empty($invoice->country)) {
204 204
                         $value = $invoice->country;
205 205
                     } else {
206
-                        $value = wpinv_default_billing_country( '', $user_id );
206
+                        $value = wpinv_default_billing_country('', $user_id);
207 207
                     }
208 208
                 }
209 209
                 
210
-                if ( $field == 'state' && empty( $value ) ) {
211
-                    if ( !empty( $invoice->state ) ) {
210
+                if ($field == 'state' && empty($value)) {
211
+                    if (!empty($invoice->state)) {
212 212
                         $value = $invoice->state;
213 213
                     } else {
214 214
                         $value = wpinv_get_default_state();
215 215
                     }
216 216
                 }
217 217
                 
218
-                $invoice->set( $field, $value );
218
+                $invoice->set($field, $value);
219 219
                 
220
-                update_post_meta( $invoice->ID, '_wpinv_' . $field, $value );
220
+                update_post_meta($invoice->ID, '_wpinv_' . $field, $value);
221 221
             }
222 222
         }
223 223
         
224 224
         return $invoice;
225 225
     }
226 226
     
227
-    protected function set_discount( $invoice, $data ) {
228
-        if ( isset( $data['discount'] ) ) {
229
-            $invoice->set( 'discount', wpinv_round_amount( $data['discount'] ) );
227
+    protected function set_discount($invoice, $data) {
228
+        if (isset($data['discount'])) {
229
+            $invoice->set('discount', wpinv_round_amount($data['discount']));
230 230
             
231
-            update_post_meta( $invoice->ID, '_wpinv_discount', wpinv_round_amount( $data['discount'] ) );
231
+            update_post_meta($invoice->ID, '_wpinv_discount', wpinv_round_amount($data['discount']));
232 232
             
233
-            if ( isset( $data['discount_code'] ) ) {
234
-                $invoice->set( 'discount_code', $data['discount_code'] );
233
+            if (isset($data['discount_code'])) {
234
+                $invoice->set('discount_code', $data['discount_code']);
235 235
                 
236
-                update_post_meta( $invoice->ID, '_wpinv_discount_code', $data['discount_code'] );
236
+                update_post_meta($invoice->ID, '_wpinv_discount_code', $data['discount_code']);
237 237
             }
238 238
         }
239 239
         
240 240
         return $invoice;
241 241
     }
242 242
     
243
-    protected function set_items( $invoice, $data ) {
244
-        if ( !empty( $data['items'] ) && is_array( $data['items'] ) ) {
243
+    protected function set_items($invoice, $data) {
244
+        if (!empty($data['items']) && is_array($data['items'])) {
245 245
             $items_array = array();
246 246
            
247
-            if ( !empty( $invoice->country ) ) {
247
+            if (!empty($invoice->country)) {
248 248
                 $country = $invoice->country;
249
-            } else if ( !empty( $data['billing_details']['country'] ) ) {
249
+            } else if (!empty($data['billing_details']['country'])) {
250 250
                 $country = $data['billing_details']['country'];
251 251
             } else {
252
-                $country = wpinv_default_billing_country( '', $invoice->get_user_id() );
252
+                $country = wpinv_default_billing_country('', $invoice->get_user_id());
253 253
             }
254 254
             
255
-            if ( !empty( $invoice->state ) ) {
255
+            if (!empty($invoice->state)) {
256 256
                 $state = $invoice->state;
257
-            } else if ( !empty( $data['billing_details']['state'] ) ) {
257
+            } else if (!empty($data['billing_details']['state'])) {
258 258
                 $state = $data['billing_details']['state'];
259 259
             } else {
260 260
                 $state = wpinv_get_default_state();
@@ -263,54 +263,54 @@  discard block
 block discarded – undo
263 263
             $_POST['country']   = $country;
264 264
             $_POST['state']     = $state;
265 265
             
266
-            $rate = wpinv_get_tax_rate( $country, $state, 'global' );
266
+            $rate = wpinv_get_tax_rate($country, $state, 'global');
267 267
             
268 268
             $total_tax = 0;
269
-            foreach ( $data['items'] as $item ) {
270
-                $id                 = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
271
-                $title              = isset( $item['title'] ) ? sanitize_text_field( $item['title'] ) : '';
272
-                $desc               = isset( $item['description'] ) ? sanitize_text_field( $item['description'] ) : '';
273
-                $amount             = isset( $item['amount'] ) ? wpinv_round_amount( $item['amount'] ) : 0;
269
+            foreach ($data['items'] as $item) {
270
+                $id                 = isset($item['id']) ? sanitize_text_field($item['id']) : '';
271
+                $title              = isset($item['title']) ? sanitize_text_field($item['title']) : '';
272
+                $desc               = isset($item['description']) ? sanitize_text_field($item['description']) : '';
273
+                $amount             = isset($item['amount']) ? wpinv_round_amount($item['amount']) : 0;
274 274
                 
275
-                if ( !empty( $item['vat_rates_class'] ) ) {
275
+                if (!empty($item['vat_rates_class'])) {
276 276
                     $vat_rates_class = $item['vat_rates_class'];
277 277
                 } else {
278 278
                     $vat_rates_class = '_standard';
279 279
                 }
280
-                $vat_rate = wpinv_get_tax_rate( $country, $state, $id );
280
+                $vat_rate = wpinv_get_tax_rate($country, $state, $id);
281 281
                 
282
-                $tax = $amount > 0 ? ( $amount * 0.01 * (float)$vat_rate ) : 0;
282
+                $tax = $amount > 0 ? ($amount * 0.01 * (float)$vat_rate) : 0;
283 283
                 $total_tax += $tax;
284 284
                 
285 285
                 $items_array[] = array(
286 286
                     'id'                => $id,
287
-                    'title'             => esc_html( $title ),
288
-                    'description'       => esc_html( $desc ),
289
-                    'amount'            => $amount > 0 ? wpinv_round_amount( $amount ) : 0,
290
-                    'subtotal'          => $amount > 0 ? wpinv_round_amount( $amount ) : 0,
287
+                    'title'             => esc_html($title),
288
+                    'description'       => esc_html($desc),
289
+                    'amount'            => $amount > 0 ? wpinv_round_amount($amount) : 0,
290
+                    'subtotal'          => $amount > 0 ? wpinv_round_amount($amount) : 0,
291 291
                     'vat_rates_class'   => $vat_rates_class,
292
-                    'vat_rate'          => $vat_rate > 0 ? wpinv_round_amount( $vat_rate ) : 0,
293
-                    'tax'               => $tax > 0 ? wpinv_round_amount( $tax ) : 0,
292
+                    'vat_rate'          => $vat_rate > 0 ? wpinv_round_amount($vat_rate) : 0,
293
+                    'tax'               => $tax > 0 ? wpinv_round_amount($tax) : 0,
294 294
                 );
295 295
             }
296 296
 
297
-            update_post_meta( $invoice->ID, '_wpinv_tax', wpinv_round_amount( $total_tax ) );
298
-            $invoice->set( 'tax', wpinv_round_amount( $total_tax ) );
297
+            update_post_meta($invoice->ID, '_wpinv_tax', wpinv_round_amount($total_tax));
298
+            $invoice->set('tax', wpinv_round_amount($total_tax));
299 299
             
300
-            $items_array = apply_filters( 'wpinv_save_invoice_items', $items_array, $data['items'], $invoice );
300
+            $items_array = apply_filters('wpinv_save_invoice_items', $items_array, $data['items'], $invoice);
301 301
             
302
-            $invoice->set( 'items', $items_array );
303
-            update_post_meta( $invoice->ID, '_wpinv_items', $items_array );
302
+            $invoice->set('items', $items_array);
303
+            update_post_meta($invoice->ID, '_wpinv_items', $items_array);
304 304
         }
305 305
         
306 306
         return $invoice;
307 307
     }
308 308
     
309
-    protected function set_invoice_meta( $invoice_id, $invoice_meta ) {
310
-        foreach ( $invoice_meta as $meta_key => $meta_value ) {
309
+    protected function set_invoice_meta($invoice_id, $invoice_meta) {
310
+        foreach ($invoice_meta as $meta_key => $meta_value) {
311 311
 
312
-            if ( is_string( $meta_key) && ! is_protected_meta( $meta_key ) && is_scalar( $meta_value ) ) {
313
-                update_post_meta( $invoice_id, $meta_key, $meta_value );
312
+            if (is_string($meta_key) && !is_protected_meta($meta_key) && is_scalar($meta_value)) {
313
+                update_post_meta($invoice_id, $meta_key, $meta_value);
314 314
             }
315 315
         }
316 316
     }
@@ -320,9 +320,9 @@  discard block
 block discarded – undo
320 320
 class WPInv_API_Exception extends Exception {
321 321
     protected $error_code;
322 322
 
323
-    public function __construct( $error_code, $error_message, $http_status_code ) {
323
+    public function __construct($error_code, $error_message, $http_status_code) {
324 324
         $this->error_code = $error_code;
325
-        parent::__construct( $error_message, $http_status_code );
325
+        parent::__construct($error_message, $http_status_code);
326 326
     }
327 327
 
328 328
     public function getErrorCode() {
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Spacing   +788 added lines, -788 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  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
 final class WPInv_Invoice {
15
-    public $ID  = 0;
15
+    public $ID = 0;
16 16
     public $title;
17 17
     public $post_type;
18 18
     
@@ -65,17 +65,17 @@  discard block
 block discarded – undo
65 65
     public $full_name = '';
66 66
     public $parent_invoice = 0;
67 67
     
68
-    public function __construct( $invoice_id = false ) {
69
-        if( empty( $invoice_id ) ) {
68
+    public function __construct($invoice_id = false) {
69
+        if (empty($invoice_id)) {
70 70
             return false;
71 71
         }
72 72
 
73
-        $this->setup_invoice( $invoice_id );
73
+        $this->setup_invoice($invoice_id);
74 74
     }
75 75
 
76
-    public function get( $key ) {
77
-        if ( method_exists( $this, 'get_' . $key ) ) {
78
-            $value = call_user_func( array( $this, 'get_' . $key ) );
76
+    public function get($key) {
77
+        if (method_exists($this, 'get_' . $key)) {
78
+            $value = call_user_func(array($this, 'get_' . $key));
79 79
         } else {
80 80
             $value = $this->$key;
81 81
         }
@@ -83,52 +83,52 @@  discard block
 block discarded – undo
83 83
         return $value;
84 84
     }
85 85
 
86
-    public function set( $key, $value ) {
87
-        $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
86
+    public function set($key, $value) {
87
+        $ignore = array('items', 'cart_details', 'fees', '_ID');
88 88
 
89
-        if ( $key === 'status' ) {
89
+        if ($key === 'status') {
90 90
             $this->old_status = $this->status;
91 91
         }
92 92
 
93
-        if ( ! in_array( $key, $ignore ) ) {
94
-            $this->pending[ $key ] = $value;
93
+        if (!in_array($key, $ignore)) {
94
+            $this->pending[$key] = $value;
95 95
         }
96 96
 
97
-        if( '_ID' !== $key ) {
97
+        if ('_ID' !== $key) {
98 98
             $this->$key = $value;
99 99
         }
100 100
     }
101 101
 
102
-    public function _isset( $name ) {
103
-        if ( property_exists( $this, $name) ) {
104
-            return false === empty( $this->$name );
102
+    public function _isset($name) {
103
+        if (property_exists($this, $name)) {
104
+            return false === empty($this->$name);
105 105
         } else {
106 106
             return null;
107 107
         }
108 108
     }
109 109
 
110
-    private function setup_invoice( $invoice_id ) {
110
+    private function setup_invoice($invoice_id) {
111 111
         $this->pending = array();
112 112
 
113
-        if ( empty( $invoice_id ) ) {
113
+        if (empty($invoice_id)) {
114 114
             return false;
115 115
         }
116 116
 
117
-        $invoice = get_post( $invoice_id );
117
+        $invoice = get_post($invoice_id);
118 118
 
119
-        if( !$invoice || is_wp_error( $invoice ) ) {
119
+        if (!$invoice || is_wp_error($invoice)) {
120 120
             return false;
121 121
         }
122 122
 
123
-        if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) {
123
+        if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) {
124 124
             return false;
125 125
         }
126 126
 
127
-        do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id );
127
+        do_action('wpinv_pre_setup_invoice', $this, $invoice_id);
128 128
         
129 129
         // Primary Identifier
130
-        $this->ID              = absint( $invoice_id );
131
-        $this->post_type            = $invoice->post_type;
130
+        $this->ID = absint($invoice_id);
131
+        $this->post_type = $invoice->post_type;
132 132
         
133 133
         // We have a payment, get the generic payment_meta item to reduce calls to it
134 134
         $this->payment_meta    = $this->get_meta();
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
         $this->post_status     = $this->status;
140 140
         $this->mode            = $this->setup_mode();
141 141
         $this->parent_invoice  = $invoice->post_parent;
142
-        $this->post_name       = $this->setup_post_name( $invoice );
142
+        $this->post_name       = $this->setup_post_name($invoice);
143 143
         $this->status_nicename = $this->setup_status_nicename();
144 144
 
145 145
         // Items
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
         
162 162
         // User based
163 163
         $this->ip              = $this->setup_ip();
164
-        $this->user_id         = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id();
165
-        $this->email           = get_the_author_meta( 'email', $this->user_id );
164
+        $this->user_id         = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id();
165
+        $this->email           = get_the_author_meta('email', $this->user_id);
166 166
         
167 167
         $this->user_info       = $this->setup_user_info();
168 168
                 
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
         $this->company         = $this->user_info['company'];
172 172
         $this->vat_number      = $this->user_info['vat_number'];
173 173
         $this->vat_rate        = $this->user_info['vat_rate'];
174
-        $this->adddress_confirmed  = $this->user_info['adddress_confirmed'];
174
+        $this->adddress_confirmed = $this->user_info['adddress_confirmed'];
175 175
         $this->address         = $this->user_info['address'];
176 176
         $this->city            = $this->user_info['city'];
177 177
         $this->country         = $this->user_info['country'];
@@ -186,48 +186,48 @@  discard block
 block discarded – undo
186 186
         // Other Identifiers
187 187
         $this->key             = $this->setup_invoice_key();
188 188
         $this->number          = $this->setup_invoice_number();
189
-        $this->title           = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number;
189
+        $this->title           = !empty($invoice->post_title) ? $invoice->post_title : $this->number;
190 190
         
191
-        $this->full_name       = trim( $this->first_name . ' '. $this->last_name );
191
+        $this->full_name       = trim($this->first_name . ' ' . $this->last_name);
192 192
         
193 193
         // Allow extensions to add items to this object via hook
194
-        do_action( 'wpinv_setup_invoice', $this, $invoice_id );
194
+        do_action('wpinv_setup_invoice', $this, $invoice_id);
195 195
 
196 196
         return true;
197 197
     }
198 198
     
199 199
     private function setup_status_nicename() {
200
-        $all_invoice_statuses  = wpinv_get_invoice_statuses();
200
+        $all_invoice_statuses = wpinv_get_invoice_statuses();
201 201
         
202
-        $status = array_key_exists( $this->status, $all_invoice_statuses ) ? $all_invoice_statuses[$this->status] : ucfirst( $this->status );
202
+        $status = array_key_exists($this->status, $all_invoice_statuses) ? $all_invoice_statuses[$this->status] : ucfirst($this->status);
203 203
 
204 204
         return $status;
205 205
     }
206 206
     
207
-    private function setup_post_name( $post = NULL ) {
207
+    private function setup_post_name($post = NULL) {
208 208
         $post_name = '';
209 209
         
210
-        if ( !empty( $post ) ) {
211
-            if( !empty( $post->post_name ) ) {
210
+        if (!empty($post)) {
211
+            if (!empty($post->post_name)) {
212 212
                 $post_name = $post->post_name;
213
-            } else if ( !empty( $post->ID ) && !empty( $post->post_title ) ) {
214
-                $post_name = sanitize_title( $post->post_title );
213
+            } else if (!empty($post->ID) && !empty($post->post_title)) {
214
+                $post_name = sanitize_title($post->post_title);
215 215
                 
216 216
                 global $wpdb;
217
-                $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
217
+                $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID));
218 218
             }
219 219
         }
220 220
 
221
-        $this->post_name   = $post_name;
221
+        $this->post_name = $post_name;
222 222
     }
223 223
     
224 224
     private function setup_due_date() {
225
-        $due_date = $this->get_meta( '_wpinv_due_date' );
225
+        $due_date = $this->get_meta('_wpinv_due_date');
226 226
         
227
-        if ( empty( $due_date ) ) {
228
-            $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) );
229
-            $due_date = date_i18n( 'Y-m-d', $overdue_time );
230
-        } else if ( $due_date == 'none' ) {
227
+        if (empty($due_date)) {
228
+            $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days')));
229
+            $due_date = date_i18n('Y-m-d', $overdue_time);
230
+        } else if ($due_date == 'none') {
231 231
             $due_date = '';
232 232
         }
233 233
         
@@ -235,63 +235,63 @@  discard block
 block discarded – undo
235 235
     }
236 236
     
237 237
     private function setup_completed_date() {
238
-        $invoice = get_post( $this->ID );
238
+        $invoice = get_post($this->ID);
239 239
 
240
-        if ( 'pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) {
240
+        if ('pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) {
241 241
             return false; // This invoice was never paid
242 242
         }
243 243
 
244
-        $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date;
244
+        $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date;
245 245
 
246 246
         return $date;
247 247
     }
248 248
     
249 249
     private function setup_cart_details() {
250
-        $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array();
250
+        $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array();
251 251
         return $cart_details;
252 252
     }
253 253
     
254 254
     public function array_convert() {
255
-        return get_object_vars( $this );
255
+        return get_object_vars($this);
256 256
     }
257 257
     
258 258
     private function setup_items() {
259
-        $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array();
259
+        $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array();
260 260
         return $items;
261 261
     }
262 262
     
263 263
     private function setup_fees() {
264
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
264
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
265 265
         return $payment_fees;
266 266
     }
267 267
         
268 268
     private function setup_currency() {
269
-        $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this );
269
+        $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this);
270 270
         return $currency;
271 271
     }
272 272
     
273 273
     private function setup_discount() {
274 274
         //$discount = $this->get_meta( '_wpinv_discount', true );
275
-        $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total );
276
-        if ( $discount < 0 ) {
275
+        $discount = (float)$this->subtotal - ((float)$this->total - (float)$this->tax - (float)$this->fees_total);
276
+        if ($discount < 0) {
277 277
             $discount = 0;
278 278
         }
279
-        $discount = wpinv_round_amount( $discount );
279
+        $discount = wpinv_round_amount($discount);
280 280
         
281 281
         return $discount;
282 282
     }
283 283
     
284 284
     private function setup_discount_code() {
285
-        $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true );
285
+        $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true);
286 286
         return $discount_code;
287 287
     }
288 288
     
289 289
     private function setup_tax() {
290
-        $tax = $this->get_meta( '_wpinv_tax', true );
290
+        $tax = $this->get_meta('_wpinv_tax', true);
291 291
 
292 292
         // We don't have tax as it's own meta and no meta was passed
293
-        if ( '' === $tax ) {            
294
-            $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0;
293
+        if ('' === $tax) {            
294
+            $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0;
295 295
         }
296 296
 
297 297
         return $tax;
@@ -301,9 +301,9 @@  discard block
 block discarded – undo
301 301
         $subtotal     = 0;
302 302
         $cart_details = $this->cart_details;
303 303
 
304
-        if ( is_array( $cart_details ) ) {
305
-            foreach ( $cart_details as $item ) {
306
-                if ( isset( $item['subtotal'] ) ) {
304
+        if (is_array($cart_details)) {
305
+            foreach ($cart_details as $item) {
306
+                if (isset($item['subtotal'])) {
307 307
                     $subtotal += $item['subtotal'];
308 308
                 }
309 309
             }
@@ -317,18 +317,18 @@  discard block
 block discarded – undo
317 317
     }
318 318
     
319 319
     private function setup_discounts() {
320
-        $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array();
320
+        $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array();
321 321
         return $discounts;
322 322
     }
323 323
     
324 324
     private function setup_total() {
325
-        $amount = $this->get_meta( '_wpinv_total', true );
325
+        $amount = $this->get_meta('_wpinv_total', true);
326 326
 
327
-        if ( empty( $amount ) && '0.00' != $amount ) {
328
-            $meta   = $this->get_meta( '_wpinv_payment_meta', true );
329
-            $meta   = maybe_unserialize( $meta );
327
+        if (empty($amount) && '0.00' != $amount) {
328
+            $meta   = $this->get_meta('_wpinv_payment_meta', true);
329
+            $meta   = maybe_unserialize($meta);
330 330
 
331
-            if ( isset( $meta['amount'] ) ) {
331
+            if (isset($meta['amount'])) {
332 332
                 $amount = $meta['amount'];
333 333
             }
334 334
         }
@@ -337,13 +337,13 @@  discard block
 block discarded – undo
337 337
     }
338 338
     
339 339
     private function setup_mode() {
340
-        return $this->get_meta( '_wpinv_mode' );
340
+        return $this->get_meta('_wpinv_mode');
341 341
     }
342 342
 
343 343
     private function setup_gateway() {
344
-        $gateway = $this->get_meta( '_wpinv_gateway' );
344
+        $gateway = $this->get_meta('_wpinv_gateway');
345 345
         
346
-        if ( empty( $gateway ) && 'publish' === $this->status ) {
346
+        if (empty($gateway) && 'publish' === $this->status) {
347 347
             $gateway = 'manual';
348 348
         }
349 349
         
@@ -351,23 +351,23 @@  discard block
 block discarded – undo
351 351
     }
352 352
     
353 353
     private function setup_gateway_title() {
354
-        $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway );
354
+        $gateway_title = wpinv_get_gateway_checkout_label($this->gateway);
355 355
         return $gateway_title;
356 356
     }
357 357
 
358 358
     private function setup_transaction_id() {
359
-        $transaction_id = $this->get_meta( '_wpinv_transaction_id' );
359
+        $transaction_id = $this->get_meta('_wpinv_transaction_id');
360 360
 
361
-        if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) {
361
+        if (empty($transaction_id) || (int)$transaction_id === (int)$this->ID) {
362 362
             $gateway        = $this->gateway;
363
-            $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID );
363
+            $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID);
364 364
         }
365 365
 
366 366
         return $transaction_id;
367 367
     }
368 368
 
369 369
     private function setup_ip() {
370
-        $ip = $this->get_meta( '_wpinv_user_ip' );
370
+        $ip = $this->get_meta('_wpinv_user_ip');
371 371
         return $ip;
372 372
     }
373 373
 
@@ -377,62 +377,62 @@  discard block
 block discarded – undo
377 377
     ///}
378 378
         
379 379
     private function setup_first_name() {
380
-        $first_name = $this->get_meta( '_wpinv_first_name' );
380
+        $first_name = $this->get_meta('_wpinv_first_name');
381 381
         return $first_name;
382 382
     }
383 383
     
384 384
     private function setup_last_name() {
385
-        $last_name = $this->get_meta( '_wpinv_last_name' );
385
+        $last_name = $this->get_meta('_wpinv_last_name');
386 386
         return $last_name;
387 387
     }
388 388
     
389 389
     private function setup_company() {
390
-        $company = $this->get_meta( '_wpinv_company' );
390
+        $company = $this->get_meta('_wpinv_company');
391 391
         return $company;
392 392
     }
393 393
     
394 394
     private function setup_vat_number() {
395
-        $vat_number = $this->get_meta( '_wpinv_vat_number' );
395
+        $vat_number = $this->get_meta('_wpinv_vat_number');
396 396
         return $vat_number;
397 397
     }
398 398
     
399 399
     private function setup_vat_rate() {
400
-        $vat_rate = $this->get_meta( '_wpinv_vat_rate' );
400
+        $vat_rate = $this->get_meta('_wpinv_vat_rate');
401 401
         return $vat_rate;
402 402
     }
403 403
     
404 404
     private function setup_adddress_confirmed() {
405
-        $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' );
405
+        $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed');
406 406
         return $adddress_confirmed;
407 407
     }
408 408
     
409 409
     private function setup_phone() {
410
-        $phone = $this->get_meta( '_wpinv_phone' );
410
+        $phone = $this->get_meta('_wpinv_phone');
411 411
         return $phone;
412 412
     }
413 413
     
414 414
     private function setup_address() {
415
-        $address = $this->get_meta( '_wpinv_address', true );
415
+        $address = $this->get_meta('_wpinv_address', true);
416 416
         return $address;
417 417
     }
418 418
     
419 419
     private function setup_city() {
420
-        $city = $this->get_meta( '_wpinv_city', true );
420
+        $city = $this->get_meta('_wpinv_city', true);
421 421
         return $city;
422 422
     }
423 423
     
424 424
     private function setup_country() {
425
-        $country = $this->get_meta( '_wpinv_country', true );
425
+        $country = $this->get_meta('_wpinv_country', true);
426 426
         return $country;
427 427
     }
428 428
     
429 429
     private function setup_state() {
430
-        $state = $this->get_meta( '_wpinv_state', true );
430
+        $state = $this->get_meta('_wpinv_state', true);
431 431
         return $state;
432 432
     }
433 433
     
434 434
     private function setup_zip() {
435
-        $zip = $this->get_meta( '_wpinv_zip', true );
435
+        $zip = $this->get_meta('_wpinv_zip', true);
436 436
         return $zip;
437 437
     }
438 438
 
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
             'user_id'        => $this->user_id,
442 442
             'first_name'     => $this->first_name,
443 443
             'last_name'      => $this->last_name,
444
-            'email'          => get_the_author_meta( 'email', $this->user_id ),
444
+            'email'          => get_the_author_meta('email', $this->user_id),
445 445
             'phone'          => $this->phone,
446 446
             'address'        => $this->address,
447 447
             'city'           => $this->city,
@@ -456,12 +456,12 @@  discard block
 block discarded – undo
456 456
         );
457 457
         
458 458
         $user_info = array();
459
-        if ( isset( $this->payment_meta['user_info'] ) ) {
460
-            $user_info = maybe_unserialize( $this->payment_meta['user_info'] );
459
+        if (isset($this->payment_meta['user_info'])) {
460
+            $user_info = maybe_unserialize($this->payment_meta['user_info']);
461 461
             
462
-            if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) {
462
+            if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) {
463 463
                 $this->user_id = $post->post_author;
464
-                $this->email = get_the_author_meta( 'email', $this->user_id );
464
+                $this->email = get_the_author_meta('email', $this->user_id);
465 465
                 
466 466
                 $user_info['user_id'] = $this->user_id;
467 467
                 $user_info['email'] = $this->email;
@@ -470,13 +470,13 @@  discard block
 block discarded – undo
470 470
             }
471 471
         }
472 472
         
473
-        $user_info    = wp_parse_args( $user_info, $defaults );
473
+        $user_info = wp_parse_args($user_info, $defaults);
474 474
         
475 475
         // Get the user, but only if it's been created
476
-        $user = get_userdata( $this->user_id );
476
+        $user = get_userdata($this->user_id);
477 477
         
478
-        if ( !empty( $user ) && $user->ID > 0 ) {
479
-            if ( empty( $user_info ) ) {
478
+        if (!empty($user) && $user->ID > 0) {
479
+            if (empty($user_info)) {
480 480
                 $user_info = array(
481 481
                     'user_id'    => $user->ID,
482 482
                     'first_name' => $user->first_name,
@@ -485,23 +485,23 @@  discard block
 block discarded – undo
485 485
                     'discount'   => '',
486 486
                 );
487 487
             } else {
488
-                foreach ( $user_info as $key => $value ) {
489
-                    if ( ! empty( $value ) ) {
488
+                foreach ($user_info as $key => $value) {
489
+                    if (!empty($value)) {
490 490
                         continue;
491 491
                     }
492 492
 
493
-                    switch( $key ) {
493
+                    switch ($key) {
494 494
                         case 'user_id':
495
-                            $user_info[ $key ] = $user->ID;
495
+                            $user_info[$key] = $user->ID;
496 496
                             break;
497 497
                         case 'first_name':
498
-                            $user_info[ $key ] = $user->first_name;
498
+                            $user_info[$key] = $user->first_name;
499 499
                             break;
500 500
                         case 'last_name':
501
-                            $user_info[ $key ] = $user->last_name;
501
+                            $user_info[$key] = $user->last_name;
502 502
                             break;
503 503
                         case 'email':
504
-                            $user_info[ $key ] = $user->user_email;
504
+                            $user_info[$key] = $user->user_email;
505 505
                             break;
506 506
                     }
507 507
                 }
@@ -512,16 +512,16 @@  discard block
 block discarded – undo
512 512
     }
513 513
 
514 514
     private function setup_invoice_key() {
515
-        $key = $this->get_meta( '_wpinv_key', true );
515
+        $key = $this->get_meta('_wpinv_key', true);
516 516
         
517 517
         return $key;
518 518
     }
519 519
 
520 520
     private function setup_invoice_number() {
521
-        $number = $this->get_meta( '_wpinv_number', true );
521
+        $number = $this->get_meta('_wpinv_number', true);
522 522
 
523
-        if ( !$number ) {
524
-            $number = wpinv_format_invoice_number( $this->ID );
523
+        if (!$number) {
524
+            $number = wpinv_format_invoice_number($this->ID);
525 525
         }
526 526
 
527 527
         return $number;
@@ -532,18 +532,18 @@  discard block
 block discarded – undo
532 532
 
533 533
         if ($number = $this->get_number()) {
534 534
             $invoice_title = $number;
535
-        } else if ( ! empty( $this->ID ) ) {
536
-            $invoice_title = wpinv_format_invoice_number( $this->ID );
535
+        } else if (!empty($this->ID)) {
536
+            $invoice_title = wpinv_format_invoice_number($this->ID);
537 537
         } else {
538
-            $invoice_title = wpinv_format_invoice_number( 0 );
538
+            $invoice_title = wpinv_format_invoice_number(0);
539 539
         }
540 540
 
541
-        if ( empty( $this->key ) ) {
541
+        if (empty($this->key)) {
542 542
             $this->key = self::generate_key();
543 543
             $this->pending['key'] = $this->key;
544 544
         }
545 545
 
546
-        if ( empty( $this->ip ) ) {
546
+        if (empty($this->ip)) {
547 547
             $this->ip = wpinv_get_ip();
548 548
             $this->pending['ip'] = $this->ip;
549 549
         }
@@ -575,75 +575,75 @@  discard block
 block discarded – undo
575 575
             'fees'         => $this->fees,
576 576
         );
577 577
         
578
-        $post_name      = sanitize_title( $invoice_title );
578
+        $post_name = sanitize_title($invoice_title);
579 579
 
580 580
         $post_data = array(
581 581
                         'post_title'    => $invoice_title,
582 582
                         'post_status'   => $this->status,
583 583
                         'post_author'   => $this->user_id,
584 584
                         'post_type'     => $this->post_type,
585
-                        'post_date'     => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ),
586
-                        'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ),
585
+                        'post_date'     => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'),
586
+                        'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1),
587 587
                         'post_parent'   => $this->parent_invoice,
588 588
                     );
589
-        $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this );
589
+        $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this);
590 590
 
591 591
         // Create a blank invoice
592
-        if ( !empty( $this->ID ) ) {
592
+        if (!empty($this->ID)) {
593 593
             $args['ID']         = $this->ID;
594 594
             $args['post_name']  = $post_name;
595 595
             
596
-            $invoice_id = wp_update_post( $args );
596
+            $invoice_id = wp_update_post($args);
597 597
         } else {
598
-            $invoice_id = wp_insert_post( $args );
598
+            $invoice_id = wp_insert_post($args);
599 599
             
600
-            $post_title = wpinv_format_invoice_number( $invoice_id );
600
+            $post_title = wpinv_format_invoice_number($invoice_id);
601 601
             global $wpdb;
602
-            $wpdb->update( $wpdb->posts, array( 'post_title' => $post_title, 'post_name' => sanitize_title( $post_title ) ), array( 'ID' => $invoice_id ) );
603
-            clean_post_cache( $invoice_id );
602
+            $wpdb->update($wpdb->posts, array('post_title' => $post_title, 'post_name' => sanitize_title($post_title)), array('ID' => $invoice_id));
603
+            clean_post_cache($invoice_id);
604 604
         }
605 605
 
606
-        if ( !empty( $invoice_id ) ) {             
606
+        if (!empty($invoice_id)) {             
607 607
             $this->ID  = $invoice_id;
608 608
             $this->_ID = $invoice_id;
609 609
             
610 610
             ///$this->pending['user_id'] = $this->user_id;
611
-            if ( isset( $this->pending['number'] ) ) {
611
+            if (isset($this->pending['number'])) {
612 612
                 $this->pending['number'] = $post_name;
613 613
             }
614 614
             
615
-            $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data );
616
-            if ( ! empty( $this->payment_meta['fees'] ) ) {
617
-                $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] );
618
-                foreach( $this->fees as $fee ) {
619
-                    $this->increase_fees( $fee['amount'] );
615
+            $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data);
616
+            if (!empty($this->payment_meta['fees'])) {
617
+                $this->fees = array_merge($this->fees, $this->payment_meta['fees']);
618
+                foreach ($this->fees as $fee) {
619
+                    $this->increase_fees($fee['amount']);
620 620
                 }
621 621
             }
622 622
 
623
-            $this->update_meta( '_wpinv_payment_meta', $this->payment_meta );            
623
+            $this->update_meta('_wpinv_payment_meta', $this->payment_meta);            
624 624
             $this->new = true;
625 625
         }
626 626
 
627 627
         return $this->ID;
628 628
     }
629 629
 
630
-    public function save( $setup = false ) {
630
+    public function save($setup = false) {
631 631
         global $wpi_session;
632 632
         
633 633
         $saved = false;
634
-        if ( empty( $this->items ) ) {
634
+        if (empty($this->items)) {
635 635
             return $saved; // Don't save empty invoice.
636 636
         }
637 637
         
638
-        if ( empty( $this->key ) ) {
638
+        if (empty($this->key)) {
639 639
             $this->key = self::generate_key();
640 640
             $this->pending['key'] = $this->key;
641 641
         }
642 642
         
643
-        if ( empty( $this->ID ) ) {
643
+        if (empty($this->ID)) {
644 644
             $invoice_id = $this->insert_invoice();
645 645
 
646
-            if ( false === $invoice_id ) {
646
+            if (false === $invoice_id) {
647 647
                 $saved = false;
648 648
             } else {
649 649
                 $this->ID = $invoice_id;
@@ -651,27 +651,27 @@  discard block
 block discarded – undo
651 651
         }        
652 652
 
653 653
         // If we have something pending, let's save it
654
-        if ( !empty( $this->pending ) ) {
654
+        if (!empty($this->pending)) {
655 655
             $total_increase = 0;
656 656
             $total_decrease = 0;
657 657
 
658
-            foreach ( $this->pending as $key => $value ) {
659
-                switch( $key ) {
658
+            foreach ($this->pending as $key => $value) {
659
+                switch ($key) {
660 660
                     case 'items':
661 661
                         // Update totals for pending items
662
-                        foreach ( $this->pending[ $key ] as $item ) {
663
-                            switch( $item['action'] ) {
662
+                        foreach ($this->pending[$key] as $item) {
663
+                            switch ($item['action']) {
664 664
                                 case 'add':
665 665
                                     $price = $item['price'];
666 666
                                     $taxes = $item['tax'];
667 667
 
668
-                                    if ( 'publish' === $this->status ) {
668
+                                    if ('publish' === $this->status) {
669 669
                                         $total_increase += $price;
670 670
                                     }
671 671
                                     break;
672 672
 
673 673
                                 case 'remove':
674
-                                    if ( 'publish' === $this->status ) {
674
+                                    if ('publish' === $this->status) {
675 675
                                         $total_decrease += $item['price'];
676 676
                                     }
677 677
                                     break;
@@ -679,16 +679,16 @@  discard block
 block discarded – undo
679 679
                         }
680 680
                         break;
681 681
                     case 'fees':
682
-                        if ( 'publish' !== $this->status ) {
682
+                        if ('publish' !== $this->status) {
683 683
                             break;
684 684
                         }
685 685
 
686
-                        if ( empty( $this->pending[ $key ] ) ) {
686
+                        if (empty($this->pending[$key])) {
687 687
                             break;
688 688
                         }
689 689
 
690
-                        foreach ( $this->pending[ $key ] as $fee ) {
691
-                            switch( $fee['action'] ) {
690
+                        foreach ($this->pending[$key] as $fee) {
691
+                            switch ($fee['action']) {
692 692
                                 case 'add':
693 693
                                     $total_increase += $fee['amount'];
694 694
                                     break;
@@ -700,86 +700,86 @@  discard block
 block discarded – undo
700 700
                         }
701 701
                         break;
702 702
                     case 'status':
703
-                        $this->update_status( $this->status );
703
+                        $this->update_status($this->status);
704 704
                         break;
705 705
                     case 'gateway':
706
-                        $this->update_meta( '_wpinv_gateway', $this->gateway );
706
+                        $this->update_meta('_wpinv_gateway', $this->gateway);
707 707
                         break;
708 708
                     case 'mode':
709
-                        $this->update_meta( '_wpinv_mode', $this->mode );
709
+                        $this->update_meta('_wpinv_mode', $this->mode);
710 710
                         break;
711 711
                     case 'transaction_id':
712
-                        $this->update_meta( '_wpinv_transaction_id', $this->transaction_id );
712
+                        $this->update_meta('_wpinv_transaction_id', $this->transaction_id);
713 713
                         break;
714 714
                     case 'ip':
715
-                        $this->update_meta( '_wpinv_user_ip', $this->ip );
715
+                        $this->update_meta('_wpinv_user_ip', $this->ip);
716 716
                         break;
717 717
                     ///case 'user_id':
718 718
                         ///$this->update_meta( '_wpinv_user_id', $this->user_id );
719 719
                         ///$this->user_info['user_id'] = $this->user_id;
720 720
                         ///break;
721 721
                     case 'first_name':
722
-                        $this->update_meta( '_wpinv_first_name', $this->first_name );
722
+                        $this->update_meta('_wpinv_first_name', $this->first_name);
723 723
                         $this->user_info['first_name'] = $this->first_name;
724 724
                         break;
725 725
                     case 'last_name':
726
-                        $this->update_meta( '_wpinv_last_name', $this->last_name );
726
+                        $this->update_meta('_wpinv_last_name', $this->last_name);
727 727
                         $this->user_info['last_name'] = $this->last_name;
728 728
                         break;
729 729
                     case 'phone':
730
-                        $this->update_meta( '_wpinv_phone', $this->phone );
730
+                        $this->update_meta('_wpinv_phone', $this->phone);
731 731
                         $this->user_info['phone'] = $this->phone;
732 732
                         break;
733 733
                     case 'address':
734
-                        $this->update_meta( '_wpinv_address', $this->address );
734
+                        $this->update_meta('_wpinv_address', $this->address);
735 735
                         $this->user_info['address'] = $this->address;
736 736
                         break;
737 737
                     case 'city':
738
-                        $this->update_meta( '_wpinv_city', $this->city );
738
+                        $this->update_meta('_wpinv_city', $this->city);
739 739
                         $this->user_info['city'] = $this->city;
740 740
                         break;
741 741
                     case 'country':
742
-                        $this->update_meta( '_wpinv_country', $this->country );
742
+                        $this->update_meta('_wpinv_country', $this->country);
743 743
                         $this->user_info['country'] = $this->country;
744 744
                         break;
745 745
                     case 'state':
746
-                        $this->update_meta( '_wpinv_state', $this->state );
746
+                        $this->update_meta('_wpinv_state', $this->state);
747 747
                         $this->user_info['state'] = $this->state;
748 748
                         break;
749 749
                     case 'zip':
750
-                        $this->update_meta( '_wpinv_zip', $this->zip );
750
+                        $this->update_meta('_wpinv_zip', $this->zip);
751 751
                         $this->user_info['zip'] = $this->zip;
752 752
                         break;
753 753
                     case 'company':
754
-                        $this->update_meta( '_wpinv_company', $this->company );
754
+                        $this->update_meta('_wpinv_company', $this->company);
755 755
                         $this->user_info['company'] = $this->company;
756 756
                         break;
757 757
                     case 'vat_number':
758
-                        $this->update_meta( '_wpinv_vat_number', $this->vat_number );
758
+                        $this->update_meta('_wpinv_vat_number', $this->vat_number);
759 759
                         $this->user_info['vat_number'] = $this->vat_number;
760 760
                         
761
-                        $vat_info = $wpi_session->get( 'user_vat_data' );
762
-                        if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) {
763
-                            $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false;
764
-                            $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed );
761
+                        $vat_info = $wpi_session->get('user_vat_data');
762
+                        if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) {
763
+                            $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
764
+                            $this->update_meta('_wpinv_adddress_confirmed', (bool)$adddress_confirmed);
765 765
                             $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed;
766 766
                         }
767 767
     
768 768
                         break;
769 769
                     case 'vat_rate':
770
-                        $this->update_meta( '_wpinv_vat_rate', $this->vat_rate );
770
+                        $this->update_meta('_wpinv_vat_rate', $this->vat_rate);
771 771
                         $this->user_info['vat_rate'] = $this->vat_rate;
772 772
                         break;
773 773
                     case 'adddress_confirmed':
774
-                        $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed );
774
+                        $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed);
775 775
                         $this->user_info['adddress_confirmed'] = $this->adddress_confirmed;
776 776
                         break;
777 777
                     
778 778
                     case 'key':
779
-                        $this->update_meta( '_wpinv_key', $this->key );
779
+                        $this->update_meta('_wpinv_key', $this->key);
780 780
                         break;
781 781
                     case 'number':
782
-                        $this->update_meta( '_wpinv_number', $this->number );
782
+                        $this->update_meta('_wpinv_number', $this->number);
783 783
                         break;
784 784
                     case 'date':
785 785
                         $args = array(
@@ -788,34 +788,34 @@  discard block
 block discarded – undo
788 788
                             'edit_date' => true,
789 789
                         );
790 790
 
791
-                        wp_update_post( $args );
791
+                        wp_update_post($args);
792 792
                         break;
793 793
                     case 'due_date':
794
-                        if ( empty( $this->due_date ) ) {
794
+                        if (empty($this->due_date)) {
795 795
                             $this->due_date = 'none';
796 796
                         }
797 797
                         
798
-                        $this->update_meta( '_wpinv_due_date', $this->due_date );
798
+                        $this->update_meta('_wpinv_due_date', $this->due_date);
799 799
                         break;
800 800
                     case 'completed_date':
801
-                        $this->update_meta( '_wpinv_completed_date', $this->completed_date );
801
+                        $this->update_meta('_wpinv_completed_date', $this->completed_date);
802 802
                         break;
803 803
                     case 'discounts':
804
-                        if ( ! is_array( $this->discounts ) ) {
805
-                            $this->discounts = explode( ',', $this->discounts );
804
+                        if (!is_array($this->discounts)) {
805
+                            $this->discounts = explode(',', $this->discounts);
806 806
                         }
807 807
 
808
-                        $this->user_info['discount'] = implode( ',', $this->discounts );
808
+                        $this->user_info['discount'] = implode(',', $this->discounts);
809 809
                         break;
810 810
                         
811 811
                     //case 'tax':
812 812
                         //$this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
813 813
                         //break;
814 814
                     case 'discount':
815
-                        $this->update_meta( '_wpinv_discount', wpinv_round_amount( $this->discount ) );
815
+                        $this->update_meta('_wpinv_discount', wpinv_round_amount($this->discount));
816 816
                         break;
817 817
                     case 'discount_code':
818
-                        $this->update_meta( '_wpinv_discount_code', $this->discount_code );
818
+                        $this->update_meta('_wpinv_discount_code', $this->discount_code);
819 819
                         break;
820 820
                     //case 'fees':
821 821
                         //$this->update_meta( '_wpinv_fees', $this->fees );
@@ -825,19 +825,19 @@  discard block
 block discarded – undo
825 825
                             'ID'          => $this->ID,
826 826
                             'post_parent' => $this->parent_invoice,
827 827
                         );
828
-                        wp_update_post( $args );
828
+                        wp_update_post($args);
829 829
                         break;
830 830
                     default:
831
-                        do_action( 'wpinv_save', $this, $key );
831
+                        do_action('wpinv_save', $this, $key);
832 832
                         break;
833 833
                 }
834 834
             }       
835 835
 
836
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
837
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
838
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
836
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
837
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
838
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
839 839
             
840
-            $this->items    = array_values( $this->items );
840
+            $this->items = array_values($this->items);
841 841
             
842 842
             $new_meta = array(
843 843
                 'items'         => $this->items,
@@ -848,12 +848,12 @@  discard block
 block discarded – undo
848 848
             );
849 849
             
850 850
             $meta        = $this->get_meta();
851
-            $merged_meta = array_merge( $meta, $new_meta );
851
+            $merged_meta = array_merge($meta, $new_meta);
852 852
 
853 853
             // Only save the payment meta if it's changed
854
-            if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) {
855
-                $updated     = $this->update_meta( '_wpinv_payment_meta', $merged_meta );
856
-                if ( false !== $updated ) {
854
+            if (md5(serialize($meta)) !== md5(serialize($merged_meta))) {
855
+                $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta);
856
+                if (false !== $updated) {
857 857
                     $saved = true;
858 858
                 }
859 859
             }
@@ -861,15 +861,15 @@  discard block
 block discarded – undo
861 861
             $this->pending = array();
862 862
             $saved         = true;
863 863
         } else {
864
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
865
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
866
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
864
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
865
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
866
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
867 867
         }
868 868
         
869
-        do_action( 'wpinv_invoice_save', $this, $saved );
869
+        do_action('wpinv_invoice_save', $this, $saved);
870 870
 
871
-        if ( true === $saved || $setup ) {
872
-            $this->setup_invoice( $this->ID );
871
+        if (true === $saved || $setup) {
872
+            $this->setup_invoice($this->ID);
873 873
         }
874 874
         
875 875
         $this->refresh_item_ids();
@@ -877,7 +877,7 @@  discard block
 block discarded – undo
877 877
         return $saved;
878 878
     }
879 879
     
880
-    public function add_fee( $args, $global = true ) {
880
+    public function add_fee($args, $global = true) {
881 881
         $default_args = array(
882 882
             'label'       => '',
883 883
             'amount'      => 0,
@@ -887,75 +887,75 @@  discard block
 block discarded – undo
887 887
             'item_id'     => 0,
888 888
         );
889 889
 
890
-        $fee = wp_parse_args( $args, $default_args );
890
+        $fee = wp_parse_args($args, $default_args);
891 891
         
892
-        if ( !empty( $fee['label'] ) ) {
892
+        if (!empty($fee['label'])) {
893 893
             return false;
894 894
         }
895 895
         
896
-        $fee['id']  = sanitize_title( $fee['label'] );
896
+        $fee['id'] = sanitize_title($fee['label']);
897 897
         
898
-        $this->fees[]               = $fee;
898
+        $this->fees[] = $fee;
899 899
         
900 900
         $added_fee               = $fee;
901 901
         $added_fee['action']     = 'add';
902 902
         $this->pending['fees'][] = $added_fee;
903
-        reset( $this->fees );
903
+        reset($this->fees);
904 904
 
905
-        $this->increase_fees( $fee['amount'] );
905
+        $this->increase_fees($fee['amount']);
906 906
         return true;
907 907
     }
908 908
 
909
-    public function remove_fee( $key ) {
909
+    public function remove_fee($key) {
910 910
         $removed = false;
911 911
 
912
-        if ( is_numeric( $key ) ) {
913
-            $removed = $this->remove_fee_by( 'index', $key );
912
+        if (is_numeric($key)) {
913
+            $removed = $this->remove_fee_by('index', $key);
914 914
         }
915 915
 
916 916
         return $removed;
917 917
     }
918 918
 
919
-    public function remove_fee_by( $key, $value, $global = false ) {
920
-        $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(
919
+    public function remove_fee_by($key, $value, $global = false) {
920
+        $allowed_fee_keys = apply_filters('wpinv_fee_keys', array(
921 921
             'index', 'label', 'amount', 'type',
922
-        ) );
922
+        ));
923 923
 
924
-        if ( ! in_array( $key, $allowed_fee_keys ) ) {
924
+        if (!in_array($key, $allowed_fee_keys)) {
925 925
             return false;
926 926
         }
927 927
 
928 928
         $removed = false;
929
-        if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) {
930
-            $removed_fee             = $this->fees[ $value ];
929
+        if ('index' === $key && array_key_exists($value, $this->fees)) {
930
+            $removed_fee             = $this->fees[$value];
931 931
             $removed_fee['action']   = 'remove';
932 932
             $this->pending['fees'][] = $removed_fee;
933 933
 
934
-            $this->decrease_fees( $removed_fee['amount'] );
934
+            $this->decrease_fees($removed_fee['amount']);
935 935
 
936
-            unset( $this->fees[ $value ] );
936
+            unset($this->fees[$value]);
937 937
             $removed = true;
938
-        } else if ( 'index' !== $key ) {
939
-            foreach ( $this->fees as $index => $fee ) {
940
-                if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) {
938
+        } else if ('index' !== $key) {
939
+            foreach ($this->fees as $index => $fee) {
940
+                if (isset($fee[$key]) && $fee[$key] == $value) {
941 941
                     $removed_fee             = $fee;
942 942
                     $removed_fee['action']   = 'remove';
943 943
                     $this->pending['fees'][] = $removed_fee;
944 944
 
945
-                    $this->decrease_fees( $removed_fee['amount'] );
945
+                    $this->decrease_fees($removed_fee['amount']);
946 946
 
947
-                    unset( $this->fees[ $index ] );
947
+                    unset($this->fees[$index]);
948 948
                     $removed = true;
949 949
 
950
-                    if ( false === $global ) {
950
+                    if (false === $global) {
951 951
                         break;
952 952
                     }
953 953
                 }
954 954
             }
955 955
         }
956 956
 
957
-        if ( true === $removed ) {
958
-            $this->fees = array_values( $this->fees );
957
+        if (true === $removed) {
958
+            $this->fees = array_values($this->fees);
959 959
         }
960 960
 
961 961
         return $removed;
@@ -963,35 +963,35 @@  discard block
 block discarded – undo
963 963
 
964 964
     
965 965
 
966
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
966
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
967 967
         // Bail if no note specified
968
-        if( !$note ) {
968
+        if (!$note) {
969 969
             return false;
970 970
         }
971 971
 
972
-        if ( empty( $this->ID ) )
972
+        if (empty($this->ID))
973 973
             return false;
974 974
         
975
-        if ( ( ( is_user_logged_in() && current_user_can( 'manage_options' ) ) || $added_by_user ) && !$system ) {
976
-            $user                 = get_user_by( 'id', get_current_user_id() );
975
+        if (((is_user_logged_in() && current_user_can('manage_options')) || $added_by_user) && !$system) {
976
+            $user                 = get_user_by('id', get_current_user_id());
977 977
             $comment_author       = $user->display_name;
978 978
             $comment_author_email = $user->user_email;
979 979
         } else {
980
-            $comment_author       = __( 'System', 'invoicing' );
981
-            $comment_author_email = strtolower( __( 'System', 'invoicing' ) ) . '@';
982
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
983
-            $comment_author_email = sanitize_email( $comment_author_email );
980
+            $comment_author       = __('System', 'invoicing');
981
+            $comment_author_email = strtolower(__('System', 'invoicing')) . '@';
982
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
983
+            $comment_author_email = sanitize_email($comment_author_email);
984 984
         }
985 985
 
986
-        do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type );
986
+        do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type);
987 987
 
988
-        $note_id = wp_insert_comment( wp_filter_comment( array(
988
+        $note_id = wp_insert_comment(wp_filter_comment(array(
989 989
             'comment_post_ID'      => $this->ID,
990 990
             'comment_content'      => $note,
991 991
             'comment_agent'        => 'GeoDirectory',
992 992
             'user_id'              => is_admin() ? get_current_user_id() : 0,
993
-            'comment_date'         => current_time( 'mysql' ),
994
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
993
+            'comment_date'         => current_time('mysql'),
994
+            'comment_date_gmt'     => current_time('mysql', 1),
995 995
             'comment_approved'     => 1,
996 996
             'comment_parent'       => 0,
997 997
             'comment_author'       => $comment_author,
@@ -999,53 +999,53 @@  discard block
 block discarded – undo
999 999
             'comment_author_url'   => '',
1000 1000
             'comment_author_email' => $comment_author_email,
1001 1001
             'comment_type'         => 'wpinv_note'
1002
-        ) ) );
1002
+        )));
1003 1003
 
1004
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note );
1004
+        do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note);
1005 1005
         
1006
-        if ( $customer_type ) {
1007
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
1006
+        if ($customer_type) {
1007
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
1008 1008
 
1009
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) );
1009
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note));
1010 1010
         }
1011 1011
 
1012 1012
         return $note_id;
1013 1013
     }
1014 1014
 
1015
-    private function increase_subtotal( $amount = 0.00 ) {
1016
-        $amount          = (float) $amount;
1015
+    private function increase_subtotal($amount = 0.00) {
1016
+        $amount          = (float)$amount;
1017 1017
         $this->subtotal += $amount;
1018
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1018
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1019 1019
 
1020 1020
         $this->recalculate_total();
1021 1021
     }
1022 1022
 
1023
-    private function decrease_subtotal( $amount = 0.00 ) {
1024
-        $amount          = (float) $amount;
1023
+    private function decrease_subtotal($amount = 0.00) {
1024
+        $amount          = (float)$amount;
1025 1025
         $this->subtotal -= $amount;
1026
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1026
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1027 1027
 
1028
-        if ( $this->subtotal < 0 ) {
1028
+        if ($this->subtotal < 0) {
1029 1029
             $this->subtotal = 0;
1030 1030
         }
1031 1031
 
1032 1032
         $this->recalculate_total();
1033 1033
     }
1034 1034
 
1035
-    private function increase_fees( $amount = 0.00 ) {
1035
+    private function increase_fees($amount = 0.00) {
1036 1036
         $amount            = (float)$amount;
1037 1037
         $this->fees_total += $amount;
1038
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1038
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1039 1039
 
1040 1040
         $this->recalculate_total();
1041 1041
     }
1042 1042
 
1043
-    private function decrease_fees( $amount = 0.00 ) {
1044
-        $amount            = (float) $amount;
1043
+    private function decrease_fees($amount = 0.00) {
1044
+        $amount            = (float)$amount;
1045 1045
         $this->fees_total -= $amount;
1046
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1046
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1047 1047
 
1048
-        if ( $this->fees_total < 0 ) {
1048
+        if ($this->fees_total < 0) {
1049 1049
             $this->fees_total = 0;
1050 1050
         }
1051 1051
 
@@ -1056,54 +1056,54 @@  discard block
 block discarded – undo
1056 1056
         global $wpi_nosave;
1057 1057
         
1058 1058
         $this->total = $this->subtotal + $this->tax + $this->fees_total;
1059
-        $this->total = wpinv_round_amount( $this->total );
1059
+        $this->total = wpinv_round_amount($this->total);
1060 1060
         
1061
-        do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave );
1061
+        do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave);
1062 1062
     }
1063 1063
     
1064
-    public function increase_tax( $amount = 0.00 ) {
1065
-        $amount       = (float) $amount;
1064
+    public function increase_tax($amount = 0.00) {
1065
+        $amount       = (float)$amount;
1066 1066
         $this->tax   += $amount;
1067 1067
 
1068 1068
         $this->recalculate_total();
1069 1069
     }
1070 1070
 
1071
-    public function decrease_tax( $amount = 0.00 ) {
1072
-        $amount     = (float) $amount;
1071
+    public function decrease_tax($amount = 0.00) {
1072
+        $amount     = (float)$amount;
1073 1073
         $this->tax -= $amount;
1074 1074
 
1075
-        if ( $this->tax < 0 ) {
1075
+        if ($this->tax < 0) {
1076 1076
             $this->tax = 0;
1077 1077
         }
1078 1078
 
1079 1079
         $this->recalculate_total();
1080 1080
     }
1081 1081
 
1082
-    public function update_status( $new_status = false, $note = '', $manual = false ) {
1083
-        $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID );
1082
+    public function update_status($new_status = false, $note = '', $manual = false) {
1083
+        $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID);
1084 1084
         
1085
-        if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses() ) ) ) {
1085
+        if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses()))) {
1086 1086
             return false; // Don't permit status changes that aren't changes
1087 1087
         }
1088 1088
 
1089
-        $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status );
1089
+        $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status);
1090 1090
         $updated = false;
1091 1091
 
1092
-        if ( $do_change ) {
1093
-            do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status );
1092
+        if ($do_change) {
1093
+            do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status);
1094 1094
 
1095 1095
             $update_post_data                   = array();
1096 1096
             $update_post_data['ID']             = $this->ID;
1097 1097
             $update_post_data['post_status']    = $new_status;
1098
-            $update_post_data['edit_date']      = current_time( 'mysql', 0 );
1099
-            $update_post_data['edit_date_gmt']  = current_time( 'mysql', 1 );
1098
+            $update_post_data['edit_date']      = current_time('mysql', 0);
1099
+            $update_post_data['edit_date_gmt']  = current_time('mysql', 1);
1100 1100
             
1101
-            $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID );
1101
+            $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID);
1102 1102
 
1103
-            $updated = wp_update_post( $update_post_data );     
1103
+            $updated = wp_update_post($update_post_data);     
1104 1104
            
1105 1105
             // Process any specific status functions
1106
-            switch( $new_status ) {
1106
+            switch ($new_status) {
1107 1107
                 case 'wpi-refunded':
1108 1108
                     $this->process_refund();
1109 1109
                     break;
@@ -1116,9 +1116,9 @@  discard block
 block discarded – undo
1116 1116
             }
1117 1117
             
1118 1118
             // Status was changed.
1119
-            do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status );
1120
-            do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status );
1121
-            do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status );
1119
+            do_action('wpinv_status_' . $new_status, $this->ID, $old_status);
1120
+            do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status);
1121
+            do_action('wpinv_update_status', $this->ID, $new_status, $old_status);
1122 1122
         }
1123 1123
 
1124 1124
         return $updated;
@@ -1132,72 +1132,72 @@  discard block
 block discarded – undo
1132 1132
         $this->save();
1133 1133
     }
1134 1134
 
1135
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
1136
-        if ( empty( $meta_key ) ) {
1135
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
1136
+        if (empty($meta_key)) {
1137 1137
             return false;
1138 1138
         }
1139 1139
 
1140
-        if ( $meta_key == 'key' || $meta_key == 'date' ) {
1140
+        if ($meta_key == 'key' || $meta_key == 'date') {
1141 1141
             $current_meta = $this->get_meta();
1142
-            $current_meta[ $meta_key ] = $meta_value;
1142
+            $current_meta[$meta_key] = $meta_value;
1143 1143
 
1144 1144
             $meta_key     = '_wpinv_payment_meta';
1145 1145
             $meta_value   = $current_meta;
1146 1146
         }
1147 1147
 
1148
-        $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID );
1148
+        $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID);
1149 1149
         
1150
-        if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) {
1150
+        if ($meta_key == '_wpinv_completed_date' && !empty($meta_value)) {
1151 1151
             $args = array(
1152 1152
                 'ID'                => $this->ID,
1153 1153
                 'post_date'         => $meta_value,
1154 1154
                 'edit_date'         => true,
1155
-                'post_date_gmt'     => get_gmt_from_date( $meta_value ),
1155
+                'post_date_gmt'     => get_gmt_from_date($meta_value),
1156 1156
                 'post_modified'     => $meta_value,
1157
-                'post_modified_gmt' => get_gmt_from_date( $meta_value )
1157
+                'post_modified_gmt' => get_gmt_from_date($meta_value)
1158 1158
             );
1159
-            wp_update_post( $args );
1159
+            wp_update_post($args);
1160 1160
         }
1161 1161
         
1162
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
1162
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
1163 1163
     }
1164 1164
 
1165 1165
     private function process_refund() {
1166 1166
         $process_refund = true;
1167 1167
 
1168 1168
         // If the payment was not in publish, don't decrement stats as they were never incremented
1169
-        if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) {
1169
+        if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) {
1170 1170
             $process_refund = false;
1171 1171
         }
1172 1172
 
1173 1173
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1174
-        $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this );
1174
+        $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this);
1175 1175
 
1176
-        if ( false === $process_refund ) {
1176
+        if (false === $process_refund) {
1177 1177
             return;
1178 1178
         }
1179 1179
 
1180
-        do_action( 'wpinv_pre_refund_invoice', $this );
1180
+        do_action('wpinv_pre_refund_invoice', $this);
1181 1181
         
1182
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this );
1183
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this );
1184
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this );
1182
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this);
1183
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this);
1184
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this);
1185 1185
         
1186
-        do_action( 'wpinv_post_refund_invoice', $this );
1186
+        do_action('wpinv_post_refund_invoice', $this);
1187 1187
     }
1188 1188
 
1189 1189
     private function process_failure() {
1190 1190
         $discounts = $this->discounts;
1191
-        if ( empty( $discounts ) ) {
1191
+        if (empty($discounts)) {
1192 1192
             return;
1193 1193
         }
1194 1194
 
1195
-        if ( ! is_array( $discounts ) ) {
1196
-            $discounts = array_map( 'trim', explode( ',', $discounts ) );
1195
+        if (!is_array($discounts)) {
1196
+            $discounts = array_map('trim', explode(',', $discounts));
1197 1197
         }
1198 1198
 
1199
-        foreach ( $discounts as $discount ) {
1200
-            wpinv_decrease_discount_usage( $discount );
1199
+        foreach ($discounts as $discount) {
1200
+            wpinv_decrease_discount_usage($discount);
1201 1201
         }
1202 1202
     }
1203 1203
     
@@ -1205,92 +1205,92 @@  discard block
 block discarded – undo
1205 1205
         $process_pending = true;
1206 1206
 
1207 1207
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1208
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'pending' != $this->status ) {
1208
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'pending' != $this->status) {
1209 1209
             $process_pending = false;
1210 1210
         }
1211 1211
 
1212 1212
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1213
-        $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this );
1213
+        $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this);
1214 1214
 
1215
-        if ( false === $process_pending ) {
1215
+        if (false === $process_pending) {
1216 1216
             return;
1217 1217
         }
1218 1218
 
1219
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this );
1220
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this );
1221
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this );
1219
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this);
1220
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this);
1221
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this);
1222 1222
 
1223 1223
         $this->completed_date = '';
1224
-        $this->update_meta( '_wpinv_completed_date', '' );
1224
+        $this->update_meta('_wpinv_completed_date', '');
1225 1225
     }
1226 1226
     
1227 1227
     // get data
1228
-    public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) {
1229
-        $meta = get_post_meta( $this->ID, $meta_key, $single );
1228
+    public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) {
1229
+        $meta = get_post_meta($this->ID, $meta_key, $single);
1230 1230
 
1231
-        if ( $meta_key === '_wpinv_payment_meta' ) {
1231
+        if ($meta_key === '_wpinv_payment_meta') {
1232 1232
 
1233
-            if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is.
1233
+            if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is.
1234 1234
 
1235
-            if ( empty( $meta['key'] ) ) {
1235
+            if (empty($meta['key'])) {
1236 1236
                 $meta['key'] = $this->setup_invoice_key();
1237 1237
             }
1238 1238
 
1239
-            if ( empty( $meta['date'] ) ) {
1240
-                $meta['date'] = get_post_field( 'post_date', $this->ID );
1239
+            if (empty($meta['date'])) {
1240
+                $meta['date'] = get_post_field('post_date', $this->ID);
1241 1241
             }
1242 1242
         }
1243 1243
 
1244
-        $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID );
1244
+        $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID);
1245 1245
 
1246
-        return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key );
1246
+        return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key);
1247 1247
     }
1248 1248
     
1249 1249
     public function get_description() {
1250
-        $post = get_post( $this->ID );
1250
+        $post = get_post($this->ID);
1251 1251
         
1252
-        $description = !empty( $post ) ? $post->post_content : '';
1253
-        return apply_filters( 'wpinv_get_description', $description, $this->ID, $this );
1252
+        $description = !empty($post) ? $post->post_content : '';
1253
+        return apply_filters('wpinv_get_description', $description, $this->ID, $this);
1254 1254
     }
1255 1255
     
1256
-    public function get_status( $nicename = false ) {
1257
-        if ( !$nicename ) {
1256
+    public function get_status($nicename = false) {
1257
+        if (!$nicename) {
1258 1258
             $status = $this->status;
1259 1259
         } else {
1260 1260
             $status = $this->status_nicename;
1261 1261
         }
1262 1262
         
1263
-        return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this );
1263
+        return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this);
1264 1264
     }
1265 1265
     
1266 1266
     public function get_cart_details() {
1267
-        return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this );
1267
+        return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this);
1268 1268
     }
1269 1269
     
1270
-    public function get_subtotal( $currency = false ) {
1271
-        $subtotal = wpinv_round_amount( $this->subtotal );
1270
+    public function get_subtotal($currency = false) {
1271
+        $subtotal = wpinv_round_amount($this->subtotal);
1272 1272
         
1273
-        if ( $currency ) {
1274
-            $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() );
1273
+        if ($currency) {
1274
+            $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency());
1275 1275
         }
1276 1276
         
1277
-        return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency );
1277
+        return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency);
1278 1278
     }
1279 1279
     
1280
-    public function get_total( $currency = false ) {        
1281
-        if ( $this->is_free_trial() ) {
1282
-            $total = wpinv_round_amount( 0 );
1280
+    public function get_total($currency = false) {        
1281
+        if ($this->is_free_trial()) {
1282
+            $total = wpinv_round_amount(0);
1283 1283
         } else {
1284
-            $total = wpinv_round_amount( $this->total );
1284
+            $total = wpinv_round_amount($this->total);
1285 1285
         }
1286
-        if ( $currency ) {
1287
-            $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() );
1286
+        if ($currency) {
1287
+            $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency());
1288 1288
         }
1289 1289
         
1290
-        return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency );
1290
+        return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency);
1291 1291
     }
1292 1292
     
1293
-    public function get_recurring_details( $field = '', $currency = false ) {        
1293
+    public function get_recurring_details($field = '', $currency = false) {        
1294 1294
         $data                 = array();
1295 1295
         $data['cart_details'] = $this->cart_details;
1296 1296
         $data['subtotal']     = $this->get_subtotal();
@@ -1298,45 +1298,45 @@  discard block
 block discarded – undo
1298 1298
         $data['tax']          = $this->get_tax();
1299 1299
         $data['total']        = $this->get_total();
1300 1300
     
1301
-        if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) {
1301
+        if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) {
1302 1302
             $is_free_trial = $this->is_free_trial();
1303
-            $discounts = $this->get_discounts( true );
1303
+            $discounts = $this->get_discounts(true);
1304 1304
             
1305
-            if ( $is_free_trial || !empty( $discounts ) ) {
1305
+            if ($is_free_trial || !empty($discounts)) {
1306 1306
                 $first_use_only = false;
1307 1307
                 
1308
-                if ( !empty( $discounts ) ) {
1309
-                    foreach ( $discounts as $key => $code ) {
1310
-                        if ( wpinv_discount_is_recurring( $code, true ) ) {
1308
+                if (!empty($discounts)) {
1309
+                    foreach ($discounts as $key => $code) {
1310
+                        if (wpinv_discount_is_recurring($code, true)) {
1311 1311
                             $first_use_only = true;
1312 1312
                             break;
1313 1313
                         }
1314 1314
                     }
1315 1315
                 }
1316 1316
                     
1317
-                if ( !$first_use_only ) {
1318
-                    $data['subtotal'] = wpinv_round_amount( $this->subtotal );
1319
-                    $data['discount'] = wpinv_round_amount( $this->discount );
1320
-                    $data['tax']      = wpinv_round_amount( $this->tax );
1321
-                    $data['total']    = wpinv_round_amount( $this->total );
1317
+                if (!$first_use_only) {
1318
+                    $data['subtotal'] = wpinv_round_amount($this->subtotal);
1319
+                    $data['discount'] = wpinv_round_amount($this->discount);
1320
+                    $data['tax']      = wpinv_round_amount($this->tax);
1321
+                    $data['total']    = wpinv_round_amount($this->total);
1322 1322
                 } else {
1323 1323
                     $cart_subtotal   = 0;
1324 1324
                     $cart_discount   = 0;
1325 1325
                     $cart_tax        = 0;
1326 1326
 
1327
-                    foreach ( $this->cart_details as $key => $item ) {
1328
-                        $item_quantity  = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1329
-                        $item_subtotal  = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1327
+                    foreach ($this->cart_details as $key => $item) {
1328
+                        $item_quantity  = $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1329
+                        $item_subtotal  = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1330 1330
                         $item_discount  = 0;
1331
-                        $item_tax       = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0;
1331
+                        $item_tax       = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float)$item['vat_rate']) : 0;
1332 1332
                         
1333
-                        if ( wpinv_prices_include_tax() ) {
1334
-                            $item_subtotal -= wpinv_round_amount( $item_tax );
1333
+                        if (wpinv_prices_include_tax()) {
1334
+                            $item_subtotal -= wpinv_round_amount($item_tax);
1335 1335
                         }
1336 1336
                         
1337 1337
                         $item_total     = $item_subtotal - $item_discount + $item_tax;
1338 1338
                         // Do not allow totals to go negative
1339
-                        if ( $item_total < 0 ) {
1339
+                        if ($item_total < 0) {
1340 1340
                             $item_total = 0;
1341 1341
                         }
1342 1342
                         
@@ -1344,107 +1344,107 @@  discard block
 block discarded – undo
1344 1344
                         $cart_discount  += (float)($item_discount);
1345 1345
                         $cart_tax       += (float)($item_tax);
1346 1346
                         
1347
-                        $data['cart_details'][$key]['discount']   = wpinv_round_amount( $item_discount );
1348
-                        $data['cart_details'][$key]['tax']        = wpinv_round_amount( $item_tax );
1349
-                        $data['cart_details'][$key]['price']      = wpinv_round_amount( $item_total );
1347
+                        $data['cart_details'][$key]['discount']   = wpinv_round_amount($item_discount);
1348
+                        $data['cart_details'][$key]['tax']        = wpinv_round_amount($item_tax);
1349
+                        $data['cart_details'][$key]['price']      = wpinv_round_amount($item_total);
1350 1350
                     }
1351 1351
                     
1352
-                    $data['subtotal'] = wpinv_round_amount( $cart_subtotal );
1353
-                    $data['discount'] = wpinv_round_amount( $cart_discount );
1354
-                    $data['tax']      = wpinv_round_amount( $cart_tax );
1355
-                    $data['total']    = wpinv_round_amount( $data['subtotal'] + $data['tax'] );
1352
+                    $data['subtotal'] = wpinv_round_amount($cart_subtotal);
1353
+                    $data['discount'] = wpinv_round_amount($cart_discount);
1354
+                    $data['tax']      = wpinv_round_amount($cart_tax);
1355
+                    $data['total']    = wpinv_round_amount($data['subtotal'] + $data['tax']);
1356 1356
                 }
1357 1357
             }
1358 1358
         }
1359 1359
         
1360
-        $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency );
1360
+        $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency);
1361 1361
 
1362
-        if ( isset( $data[$field] ) ) {
1363
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1362
+        if (isset($data[$field])) {
1363
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1364 1364
         }
1365 1365
         
1366 1366
         return $data;
1367 1367
     }
1368 1368
     
1369
-    public function get_final_tax( $currency = false ) {        
1370
-        $final_total = wpinv_round_amount( $this->tax );
1371
-        if ( $currency ) {
1372
-            $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() );
1369
+    public function get_final_tax($currency = false) {        
1370
+        $final_total = wpinv_round_amount($this->tax);
1371
+        if ($currency) {
1372
+            $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency());
1373 1373
         }
1374 1374
         
1375
-        return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );
1375
+        return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency);
1376 1376
     }
1377 1377
     
1378
-    public function get_discounts( $array = false ) {
1378
+    public function get_discounts($array = false) {
1379 1379
         $discounts = $this->discounts;
1380
-        if ( $array && $discounts ) {
1381
-            $discounts = explode( ',', $discounts );
1380
+        if ($array && $discounts) {
1381
+            $discounts = explode(',', $discounts);
1382 1382
         }
1383
-        return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );
1383
+        return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array);
1384 1384
     }
1385 1385
     
1386
-    public function get_discount( $currency = false, $dash = false ) {
1387
-        if ( !empty( $this->discounts ) ) {
1386
+    public function get_discount($currency = false, $dash = false) {
1387
+        if (!empty($this->discounts)) {
1388 1388
             global $ajax_cart_details;
1389 1389
             $ajax_cart_details = $this->get_cart_details();
1390 1390
 
1391
-            $this->discount = wpinv_get_cart_items_discount_amount( $this->items , $this->discounts );
1391
+            $this->discount = wpinv_get_cart_items_discount_amount($this->items, $this->discounts);
1392 1392
         }
1393
-        $discount   = wpinv_round_amount( $this->discount );
1393
+        $discount   = wpinv_round_amount($this->discount);
1394 1394
         $dash       = $dash && $discount > 0 ? '&ndash;' : '';
1395 1395
         
1396
-        if ( $currency ) {
1397
-            $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() );
1396
+        if ($currency) {
1397
+            $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency());
1398 1398
         }
1399 1399
         
1400
-        $discount   = $dash . $discount;
1400
+        $discount = $dash . $discount;
1401 1401
         
1402
-        return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );
1402
+        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash);
1403 1403
     }
1404 1404
     
1405 1405
     public function get_discount_code() {
1406 1406
         return $this->discount_code;
1407 1407
     }
1408 1408
     
1409
-    public function get_tax( $currency = false ) {
1410
-        $tax = wpinv_round_amount( $this->tax );
1409
+    public function get_tax($currency = false) {
1410
+        $tax = wpinv_round_amount($this->tax);
1411 1411
         
1412
-        if ( $currency ) {
1413
-            $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() );
1412
+        if ($currency) {
1413
+            $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency());
1414 1414
         }
1415 1415
         
1416
-        return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );
1416
+        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency);
1417 1417
     }
1418 1418
     
1419
-    public function get_fees( $type = 'all' ) {
1420
-        $fees    = array();
1419
+    public function get_fees($type = 'all') {
1420
+        $fees = array();
1421 1421
 
1422
-        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) {
1423
-            foreach ( $this->fees as $fee ) {
1424
-                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1422
+        if (!empty($this->fees) && is_array($this->fees)) {
1423
+            foreach ($this->fees as $fee) {
1424
+                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) {
1425 1425
                     continue;
1426 1426
                 }
1427 1427
 
1428
-                $fee['label'] = stripslashes( $fee['label'] );
1429
-                $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );
1430
-                $fees[]    = $fee;
1428
+                $fee['label'] = stripslashes($fee['label']);
1429
+                $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());
1430
+                $fees[] = $fee;
1431 1431
             }
1432 1432
         }
1433 1433
 
1434
-        return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );
1434
+        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this);
1435 1435
     }
1436 1436
     
1437
-    public function get_fees_total( $type = 'all' ) {
1438
-        $fees_total = (float) 0.00;
1437
+    public function get_fees_total($type = 'all') {
1438
+        $fees_total = (float)0.00;
1439 1439
 
1440
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
1441
-        if ( ! empty( $payment_fees ) ) {
1442
-            foreach ( $payment_fees as $fee ) {
1443
-                $fees_total += (float) $fee['amount'];
1440
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
1441
+        if (!empty($payment_fees)) {
1442
+            foreach ($payment_fees as $fee) {
1443
+                $fees_total += (float)$fee['amount'];
1444 1444
             }
1445 1445
         }
1446 1446
 
1447
-        return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );
1447
+        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this);
1448 1448
         /*
1449 1449
         $fees = $this->get_fees( $type );
1450 1450
 
@@ -1464,116 +1464,116 @@  discard block
 block discarded – undo
1464 1464
     }
1465 1465
 
1466 1466
     public function get_user_id() {
1467
-        return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );
1467
+        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this);
1468 1468
     }
1469 1469
     
1470 1470
     public function get_first_name() {
1471
-        return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );
1471
+        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this);
1472 1472
     }
1473 1473
     
1474 1474
     public function get_last_name() {
1475
-        return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );
1475
+        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this);
1476 1476
     }
1477 1477
     
1478 1478
     public function get_user_full_name() {
1479
-        return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1479
+        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this);
1480 1480
     }
1481 1481
     
1482 1482
     public function get_user_info() {
1483
-        return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1483
+        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this);
1484 1484
     }
1485 1485
     
1486 1486
     public function get_email() {
1487
-        return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1487
+        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this);
1488 1488
     }
1489 1489
     
1490 1490
     public function get_address() {
1491
-        return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );
1491
+        return apply_filters('wpinv_address', $this->address, $this->ID, $this);
1492 1492
     }
1493 1493
     
1494 1494
     public function get_phone() {
1495
-        return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );
1495
+        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this);
1496 1496
     }
1497 1497
     
1498 1498
     public function get_number() {
1499
-        return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );
1499
+        return apply_filters('wpinv_number', $this->number, $this->ID, $this);
1500 1500
     }
1501 1501
     
1502 1502
     public function get_items() {
1503
-        return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );
1503
+        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this);
1504 1504
     }
1505 1505
     
1506 1506
     public function get_key() {
1507
-        return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );
1507
+        return apply_filters('wpinv_key', $this->key, $this->ID, $this);
1508 1508
     }
1509 1509
     
1510 1510
     public function get_transaction_id() {
1511
-        return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );
1511
+        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this);
1512 1512
     }
1513 1513
     
1514 1514
     public function get_gateway() {
1515
-        return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );
1515
+        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this);
1516 1516
     }
1517 1517
     
1518 1518
     public function get_gateway_title() {
1519
-        $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );
1519
+        $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);
1520 1520
         
1521
-        return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );
1521
+        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this);
1522 1522
     }
1523 1523
     
1524 1524
     public function get_currency() {
1525
-        return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1525
+        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this);
1526 1526
     }
1527 1527
     
1528 1528
     public function get_created_date() {
1529
-        return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1529
+        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this);
1530 1530
     }
1531 1531
     
1532
-    public function get_due_date( $display = false ) {
1533
-        $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1532
+    public function get_due_date($display = false) {
1533
+        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this);
1534 1534
         
1535
-        if ( !$display || empty( $due_date ) ) {
1535
+        if (!$display || empty($due_date)) {
1536 1536
             return $due_date;
1537 1537
         }
1538 1538
         
1539
-        return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) );
1539
+        return date_i18n(get_option('date_format'), strtotime($due_date));
1540 1540
     }
1541 1541
     
1542 1542
     public function get_completed_date() {
1543
-        return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );
1543
+        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this);
1544 1544
     }
1545 1545
     
1546
-    public function get_invoice_date( $formatted = true ) {
1546
+    public function get_invoice_date($formatted = true) {
1547 1547
         $date_completed = $this->completed_date;
1548 1548
         $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
1549 1549
         
1550
-        if ( $invoice_date == '' ) {
1550
+        if ($invoice_date == '') {
1551 1551
             $date_created   = $this->date;
1552 1552
             $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';
1553 1553
         }
1554 1554
         
1555
-        if ( $formatted && $invoice_date ) {
1556
-            $invoice_date   = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
1555
+        if ($formatted && $invoice_date) {
1556
+            $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date));
1557 1557
         }
1558 1558
 
1559
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
1559
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
1560 1560
     }
1561 1561
     
1562 1562
     public function get_ip() {
1563
-        return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );
1563
+        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this);
1564 1564
     }
1565 1565
         
1566
-    public function has_status( $status ) {
1567
-        return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );
1566
+    public function has_status($status) {
1567
+        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status);
1568 1568
     }
1569 1569
     
1570
-    public function add_item( $item_id = 0, $args = array() ) {
1570
+    public function add_item($item_id = 0, $args = array()) {
1571 1571
         global $wpi_current_id, $wpi_item_id;
1572 1572
         
1573
-        $item = new WPInv_Item( $item_id );
1573
+        $item = new WPInv_Item($item_id);
1574 1574
 
1575 1575
         // Bail if this post isn't a item
1576
-        if( !$item || $item->post_type !== 'wpi_item' ) {
1576
+        if (!$item || $item->post_type !== 'wpi_item') {
1577 1577
             return false;
1578 1578
         }
1579 1579
         
@@ -1591,8 +1591,8 @@  discard block
 block discarded – undo
1591 1591
             'fees'      => array()
1592 1592
         );
1593 1593
 
1594
-        $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );
1595
-        $args['quantity']   = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;
1594
+        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults);
1595
+        $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;
1596 1596
 
1597 1597
         $wpi_current_id         = $this->ID;
1598 1598
         $wpi_item_id            = $item->ID;
@@ -1604,19 +1604,19 @@  discard block
 block discarded – undo
1604 1604
         $found_cart_key         = false;
1605 1605
         
1606 1606
         if ($has_quantities) {
1607
-            $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1607
+            $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1608 1608
             
1609
-            foreach ( $this->items as $key => $cart_item ) {
1610
-                if ( (int)$item_id !== (int)$cart_item['id'] ) {
1609
+            foreach ($this->items as $key => $cart_item) {
1610
+                if ((int)$item_id !== (int)$cart_item['id']) {
1611 1611
                     continue;
1612 1612
                 }
1613 1613
 
1614
-                $this->items[ $key ]['quantity'] += $args['quantity'];
1614
+                $this->items[$key]['quantity'] += $args['quantity'];
1615 1615
                 break;
1616 1616
             }
1617 1617
             
1618
-            foreach ( $this->cart_details as $cart_key => $cart_item ) {
1619
-                if ( $item_id != $cart_item['id'] ) {
1618
+            foreach ($this->cart_details as $cart_key => $cart_item) {
1619
+                if ($item_id != $cart_item['id']) {
1620 1620
                     continue;
1621 1621
                 }
1622 1622
 
@@ -1628,29 +1628,29 @@  discard block
 block discarded – undo
1628 1628
         if ($has_quantities && $found_cart_key !== false) {
1629 1629
             $cart_item          = $this->cart_details[$found_cart_key];
1630 1630
             $item_price         = $cart_item['item_price'];
1631
-            $quantity           = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1632
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1631
+            $quantity           = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1632
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1633 1633
             
1634 1634
             $new_quantity       = $quantity + $args['quantity'];
1635 1635
             $subtotal           = $item_price * $new_quantity;
1636 1636
             
1637 1637
             $args['quantity']   = $new_quantity;
1638
-            $discount           = !empty( $args['discount'] ) ? $args['discount'] : 0;
1639
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1638
+            $discount           = !empty($args['discount']) ? $args['discount'] : 0;
1639
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1640 1640
             
1641 1641
             $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;
1642 1642
             $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;
1643 1643
             // The total increase equals the number removed * the item_price
1644
-            $total_increased    = wpinv_round_amount( $item_price );
1644
+            $total_increased    = wpinv_round_amount($item_price);
1645 1645
             
1646
-            if ( wpinv_prices_include_tax() ) {
1647
-                $subtotal -= wpinv_round_amount( $tax );
1646
+            if (wpinv_prices_include_tax()) {
1647
+                $subtotal -= wpinv_round_amount($tax);
1648 1648
             }
1649 1649
 
1650
-            $total              = $subtotal - $discount + $tax;
1650
+            $total = $subtotal - $discount + $tax;
1651 1651
 
1652 1652
             // Do not allow totals to go negative
1653
-            if( $total < 0 ) {
1653
+            if ($total < 0) {
1654 1654
                 $total = 0;
1655 1655
             }
1656 1656
             
@@ -1666,20 +1666,20 @@  discard block
 block discarded – undo
1666 1666
             $this->cart_details[$found_cart_key] = $cart_item;
1667 1667
         } else {
1668 1668
             // Allow overriding the price
1669
-            if( false !== $args['item_price'] ) {
1669
+            if (false !== $args['item_price']) {
1670 1670
                 $item_price = $args['item_price'];
1671 1671
             } else {
1672
-                $item_price = wpinv_get_item_price( $item->ID );
1672
+                $item_price = wpinv_get_item_price($item->ID);
1673 1673
             }
1674 1674
 
1675 1675
             // Sanitizing the price here so we don't have a dozen calls later
1676
-            $item_price = wpinv_sanitize_amount( $item_price );
1677
-            $subtotal   = wpinv_round_amount( $item_price * $args['quantity'] );
1676
+            $item_price = wpinv_sanitize_amount($item_price);
1677
+            $subtotal   = wpinv_round_amount($item_price * $args['quantity']);
1678 1678
         
1679
-            $discount   = !empty( $args['discount'] ) ? $args['discount'] : 0;
1680
-            $tax_class  = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';
1681
-            $tax_rate   = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;
1682
-            $tax        = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1679
+            $discount   = !empty($args['discount']) ? $args['discount'] : 0;
1680
+            $tax_class  = !empty($args['vat_class']) ? $args['vat_class'] : '';
1681
+            $tax_rate   = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;
1682
+            $tax        = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1683 1683
 
1684 1684
             // Setup the items meta item
1685 1685
             $new_item = array(
@@ -1687,28 +1687,28 @@  discard block
 block discarded – undo
1687 1687
                 'quantity' => $args['quantity'],
1688 1688
             );
1689 1689
 
1690
-            $this->items[]  = $new_item;
1690
+            $this->items[] = $new_item;
1691 1691
 
1692
-            if ( wpinv_prices_include_tax() ) {
1693
-                $subtotal -= wpinv_round_amount( $tax );
1692
+            if (wpinv_prices_include_tax()) {
1693
+                $subtotal -= wpinv_round_amount($tax);
1694 1694
             }
1695 1695
 
1696
-            $total      = $subtotal - $discount + $tax;
1696
+            $total = $subtotal - $discount + $tax;
1697 1697
 
1698 1698
             // Do not allow totals to go negative
1699
-            if( $total < 0 ) {
1699
+            if ($total < 0) {
1700 1700
                 $total = 0;
1701 1701
             }
1702 1702
         
1703 1703
             $this->cart_details[] = array(
1704 1704
                 'name'        => !empty($args['name']) ? $args['name'] : $item->get_name(),
1705 1705
                 'id'          => $item->ID,
1706
-                'item_price'  => wpinv_round_amount( $item_price ),
1706
+                'item_price'  => wpinv_round_amount($item_price),
1707 1707
                 'quantity'    => $args['quantity'],
1708 1708
                 'discount'    => $discount,
1709
-                'subtotal'    => wpinv_round_amount( $subtotal ),
1710
-                'tax'         => wpinv_round_amount( $tax ),
1711
-                'price'       => wpinv_round_amount( $total ),
1709
+                'subtotal'    => wpinv_round_amount($subtotal),
1710
+                'tax'         => wpinv_round_amount($tax),
1711
+                'price'       => wpinv_round_amount($total),
1712 1712
                 'vat_rate'    => $tax_rate,
1713 1713
                 'vat_class'   => $tax_class,
1714 1714
                 'meta'        => $args['meta'],
@@ -1718,69 +1718,69 @@  discard block
 block discarded – undo
1718 1718
             $subtotal = $subtotal - $discount;
1719 1719
         }
1720 1720
         
1721
-        $added_item = end( $this->cart_details );
1722
-        $added_item['action']  = 'add';
1721
+        $added_item = end($this->cart_details);
1722
+        $added_item['action'] = 'add';
1723 1723
         
1724 1724
         $this->pending['items'][] = $added_item;
1725 1725
         
1726
-        $this->increase_subtotal( $subtotal );
1727
-        $this->increase_tax( $tax );
1726
+        $this->increase_subtotal($subtotal);
1727
+        $this->increase_tax($tax);
1728 1728
 
1729 1729
         return true;
1730 1730
     }
1731 1731
     
1732
-    public function remove_item( $item_id, $args = array() ) {
1732
+    public function remove_item($item_id, $args = array()) {
1733 1733
         // Set some defaults
1734 1734
         $defaults = array(
1735 1735
             'quantity'   => 1,
1736 1736
             'item_price' => false,
1737 1737
             'cart_index' => false,
1738 1738
         );
1739
-        $args = wp_parse_args( $args, $defaults );
1739
+        $args = wp_parse_args($args, $defaults);
1740 1740
 
1741 1741
         // Bail if this post isn't a item
1742
-        if ( get_post_type( $item_id ) !== 'wpi_item' ) {
1742
+        if (get_post_type($item_id) !== 'wpi_item') {
1743 1743
             return false;
1744 1744
         }
1745 1745
         
1746
-        $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1746
+        $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1747 1747
 
1748
-        foreach ( $this->items as $key => $item ) {
1749
-            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) {
1748
+        foreach ($this->items as $key => $item) {
1749
+            if (!empty($item['id']) && (int)$item_id !== (int)$item['id']) {
1750 1750
                 continue;
1751 1751
             }
1752 1752
 
1753
-            if ( false !== $args['cart_index'] ) {
1754
-                $cart_index = absint( $args['cart_index'] );
1755
-                $cart_item  = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;
1753
+            if (false !== $args['cart_index']) {
1754
+                $cart_index = absint($args['cart_index']);
1755
+                $cart_item  = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;
1756 1756
 
1757
-                if ( ! empty( $cart_item ) ) {
1757
+                if (!empty($cart_item)) {
1758 1758
                     // If the cart index item isn't the same item ID, don't remove it
1759
-                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) {
1759
+                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) {
1760 1760
                         continue;
1761 1761
                     }
1762 1762
                 }
1763 1763
             }
1764 1764
 
1765
-            $item_quantity = $this->items[ $key ]['quantity'];
1766
-            if ( $item_quantity > $args['quantity'] ) {
1767
-                $this->items[ $key ]['quantity'] -= $args['quantity'];
1765
+            $item_quantity = $this->items[$key]['quantity'];
1766
+            if ($item_quantity > $args['quantity']) {
1767
+                $this->items[$key]['quantity'] -= $args['quantity'];
1768 1768
                 break;
1769 1769
             } else {
1770
-                unset( $this->items[ $key ] );
1770
+                unset($this->items[$key]);
1771 1771
                 break;
1772 1772
             }
1773 1773
         }
1774 1774
 
1775 1775
         $found_cart_key = false;
1776
-        if ( false === $args['cart_index'] ) {
1777
-            foreach ( $this->cart_details as $cart_key => $item ) {
1778
-                if ( $item_id != $item['id'] ) {
1776
+        if (false === $args['cart_index']) {
1777
+            foreach ($this->cart_details as $cart_key => $item) {
1778
+                if ($item_id != $item['id']) {
1779 1779
                     continue;
1780 1780
                 }
1781 1781
 
1782
-                if ( false !== $args['item_price'] ) {
1783
-                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) {
1782
+                if (false !== $args['item_price']) {
1783
+                    if (isset($item['item_price']) && (float)$args['item_price'] != (float)$item['item_price']) {
1784 1784
                         continue;
1785 1785
                     }
1786 1786
                 }
@@ -1789,13 +1789,13 @@  discard block
 block discarded – undo
1789 1789
                 break;
1790 1790
             }
1791 1791
         } else {
1792
-            $cart_index = absint( $args['cart_index'] );
1792
+            $cart_index = absint($args['cart_index']);
1793 1793
 
1794
-            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) {
1794
+            if (!array_key_exists($cart_index, $this->cart_details)) {
1795 1795
                 return false; // Invalid cart index passed.
1796 1796
             }
1797 1797
 
1798
-            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) {
1798
+            if ((int)$this->cart_details[$cart_index]['id'] > 0 && (int)$this->cart_details[$cart_index]['id'] !== (int)$item_id) {
1799 1799
                 return false; // We still need the proper Item ID to be sure.
1800 1800
             }
1801 1801
 
@@ -1803,41 +1803,41 @@  discard block
 block discarded – undo
1803 1803
         }
1804 1804
         
1805 1805
         $cart_item  = $this->cart_details[$found_cart_key];
1806
-        $quantity   = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1806
+        $quantity   = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1807 1807
         
1808
-        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) {
1808
+        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) {
1809 1809
             return false; // Invoice must contain at least one item.
1810 1810
         }
1811 1811
         
1812
-        $discounts  = $this->get_discounts();
1812
+        $discounts = $this->get_discounts();
1813 1813
         
1814
-        if ( $quantity > $args['quantity'] ) {
1814
+        if ($quantity > $args['quantity']) {
1815 1815
             $item_price         = $cart_item['item_price'];
1816
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1816
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1817 1817
             
1818
-            $new_quantity       = max( $quantity - $args['quantity'], 1);
1818
+            $new_quantity       = max($quantity - $args['quantity'], 1);
1819 1819
             $subtotal           = $item_price * $new_quantity;
1820 1820
             
1821 1821
             $args['quantity']   = $new_quantity;
1822
-            $discount           = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1823
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1822
+            $discount           = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1823
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1824 1824
             
1825
-            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0;
1825
+            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float)$cart_item['discount'] / $quantity)) : 0;
1826 1826
             $discount_decrease  = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; 
1827
-            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0;
1827
+            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float)$cart_item['tax'] / $quantity)) : 0;
1828 1828
             $tax_decrease       = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;
1829 1829
             
1830 1830
             // The total increase equals the number removed * the item_price
1831
-            $total_decrease     = wpinv_round_amount( $item_price );
1831
+            $total_decrease     = wpinv_round_amount($item_price);
1832 1832
             
1833
-            if ( wpinv_prices_include_tax() ) {
1834
-                $subtotal -= wpinv_round_amount( $tax );
1833
+            if (wpinv_prices_include_tax()) {
1834
+                $subtotal -= wpinv_round_amount($tax);
1835 1835
             }
1836 1836
 
1837
-            $total              = $subtotal - $discount + $tax;
1837
+            $total = $subtotal - $discount + $tax;
1838 1838
 
1839 1839
             // Do not allow totals to go negative
1840
-            if( $total < 0 ) {
1840
+            if ($total < 0) {
1841 1841
                 $total = 0;
1842 1842
             }
1843 1843
             
@@ -1856,16 +1856,16 @@  discard block
 block discarded – undo
1856 1856
             
1857 1857
             $this->cart_details[$found_cart_key] = $cart_item;
1858 1858
             
1859
-            $remove_item = end( $this->cart_details );
1859
+            $remove_item = end($this->cart_details);
1860 1860
         } else {
1861 1861
             $item_price     = $cart_item['item_price'];
1862
-            $discount       = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1863
-            $tax            = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;
1862
+            $discount       = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1863
+            $tax            = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;
1864 1864
         
1865
-            $subtotal_decrease  = ( $item_price * $quantity ) - $discount;
1865
+            $subtotal_decrease  = ($item_price * $quantity) - $discount;
1866 1866
             $tax_decrease       = $tax;
1867 1867
 
1868
-            unset( $this->cart_details[$found_cart_key] );
1868
+            unset($this->cart_details[$found_cart_key]);
1869 1869
             
1870 1870
             $remove_item             = $args;
1871 1871
             $remove_item['id']       = $item_id;
@@ -1876,8 +1876,8 @@  discard block
 block discarded – undo
1876 1876
         $remove_item['action']      = 'remove';
1877 1877
         $this->pending['items'][]   = $remove_item;
1878 1878
                
1879
-        $this->decrease_subtotal( $subtotal_decrease );
1880
-        $this->decrease_tax( $tax_decrease );
1879
+        $this->decrease_subtotal($subtotal_decrease);
1880
+        $this->decrease_tax($tax_decrease);
1881 1881
         
1882 1882
         return true;
1883 1883
     }
@@ -1885,7 +1885,7 @@  discard block
 block discarded – undo
1885 1885
     public function update_items($temp = false) {
1886 1886
         global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;
1887 1887
         
1888
-        if ( !empty( $this->cart_details ) ) {
1888
+        if (!empty($this->cart_details)) {
1889 1889
             $wpi_nosave             = $temp;
1890 1890
             $cart_subtotal          = 0;
1891 1891
             $cart_discount          = 0;
@@ -1895,41 +1895,41 @@  discard block
 block discarded – undo
1895 1895
             $_POST['wpinv_country'] = $this->country;
1896 1896
             $_POST['wpinv_state']   = $this->state;
1897 1897
             
1898
-            foreach ( $this->cart_details as $key => $item ) {
1898
+            foreach ($this->cart_details as $key => $item) {
1899 1899
                 $item_price = $item['item_price'];
1900
-                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1901
-                $amount     = wpinv_round_amount( $item_price * $quantity );
1900
+                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1901
+                $amount     = wpinv_round_amount($item_price * $quantity);
1902 1902
                 $subtotal   = $item_price * $quantity;
1903 1903
                 
1904 1904
                 $wpi_current_id         = $this->ID;
1905 1905
                 $wpi_item_id            = $item['id'];
1906 1906
                 
1907
-                $discount   = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );
1907
+                $discount   = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());
1908 1908
                 
1909
-                $tax_rate   = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );
1910
-                $tax_class  = $wpinv_euvat->get_item_class( $wpi_item_id );
1911
-                $tax        = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1909
+                $tax_rate   = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);
1910
+                $tax_class  = $wpinv_euvat->get_item_class($wpi_item_id);
1911
+                $tax        = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1912 1912
 
1913
-                if ( wpinv_prices_include_tax() ) {
1914
-                    $subtotal -= wpinv_round_amount( $tax );
1913
+                if (wpinv_prices_include_tax()) {
1914
+                    $subtotal -= wpinv_round_amount($tax);
1915 1915
                 }
1916 1916
 
1917
-                $total      = $subtotal - $discount + $tax;
1917
+                $total = $subtotal - $discount + $tax;
1918 1918
 
1919 1919
                 // Do not allow totals to go negative
1920
-                if( $total < 0 ) {
1920
+                if ($total < 0) {
1921 1921
                     $total = 0;
1922 1922
                 }
1923 1923
 
1924 1924
                 $cart_details[] = array(
1925 1925
                     'id'          => $item['id'],
1926 1926
                     'name'        => $item['name'],
1927
-                    'item_price'  => wpinv_round_amount( $item_price ),
1927
+                    'item_price'  => wpinv_round_amount($item_price),
1928 1928
                     'quantity'    => $quantity,
1929 1929
                     'discount'    => $discount,
1930
-                    'subtotal'    => wpinv_round_amount( $subtotal ),
1931
-                    'tax'         => wpinv_round_amount( $tax ),
1932
-                    'price'       => wpinv_round_amount( $total ),
1930
+                    'subtotal'    => wpinv_round_amount($subtotal),
1931
+                    'tax'         => wpinv_round_amount($tax),
1932
+                    'price'       => wpinv_round_amount($total),
1933 1933
                     'vat_rate'    => $tax_rate,
1934 1934
                     'vat_class'   => $tax_class,
1935 1935
                     'meta'        => isset($item['meta']) ? $item['meta'] : array(),
@@ -1940,9 +1940,9 @@  discard block
 block discarded – undo
1940 1940
                 $cart_discount  += (float)($discount);
1941 1941
                 $cart_tax       += (float)($tax);
1942 1942
             }
1943
-            $this->subtotal = wpinv_round_amount( $cart_subtotal );
1944
-            $this->tax      = wpinv_round_amount( $cart_tax );
1945
-            $this->discount = wpinv_round_amount( $cart_discount );
1943
+            $this->subtotal = wpinv_round_amount($cart_subtotal);
1944
+            $this->tax      = wpinv_round_amount($cart_tax);
1945
+            $this->discount = wpinv_round_amount($cart_discount);
1946 1946
             
1947 1947
             $this->recalculate_total();
1948 1948
             
@@ -1954,221 +1954,221 @@  discard block
 block discarded – undo
1954 1954
     
1955 1955
     public function recalculate_totals($temp = false) {        
1956 1956
         $this->update_items($temp);
1957
-        $this->save( true );
1957
+        $this->save(true);
1958 1958
         
1959 1959
         return $this;
1960 1960
     }
1961 1961
     
1962 1962
     public function needs_payment() {
1963
-        $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'pending' ), $this );
1963
+        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('pending'), $this);
1964 1964
 
1965
-        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() ) ) {
1965
+        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free())) {
1966 1966
             $needs_payment = true;
1967 1967
         } else {
1968 1968
             $needs_payment = false;
1969 1969
         }
1970 1970
 
1971
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );
1971
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses);
1972 1972
     }
1973 1973
     
1974
-    public function get_checkout_payment_url( $on_checkout = false, $secret = false ) {
1974
+    public function get_checkout_payment_url($on_checkout = false, $secret = false) {
1975 1975
         $pay_url = wpinv_get_checkout_uri();
1976 1976
 
1977
-        if ( is_ssl() ) {
1978
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
1977
+        if (is_ssl()) {
1978
+            $pay_url = str_replace('http:', 'https:', $pay_url);
1979 1979
         }
1980 1980
         
1981 1981
         $key = $this->get_key();
1982 1982
 
1983
-        if ( $on_checkout ) {
1984
-            $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );
1983
+        if ($on_checkout) {
1984
+            $pay_url = add_query_arg('invoice_key', $key, $pay_url);
1985 1985
         } else {
1986
-            $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );
1986
+            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url);
1987 1987
         }
1988 1988
         
1989
-        if ( $secret ) {
1990
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );
1989
+        if ($secret) {
1990
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url);
1991 1991
         }
1992 1992
 
1993
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this );
1993
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this);
1994 1994
     }
1995 1995
     
1996
-    public function get_view_url( $secret = false ) {
1997
-        $print_url = get_permalink( $this->ID );
1996
+    public function get_view_url($secret = false) {
1997
+        $print_url = get_permalink($this->ID);
1998 1998
         
1999
-        if ( $secret ) {
2000
-            $print_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $print_url );
1999
+        if ($secret) {
2000
+            $print_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $print_url);
2001 2001
         }
2002 2002
 
2003
-        return apply_filters( 'wpinv_get_view_url', $print_url, $this );
2003
+        return apply_filters('wpinv_get_view_url', $print_url, $this);
2004 2004
     }
2005 2005
     
2006
-    public function generate_key( $string = '' ) {
2007
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2008
-        return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) );  // Unique key
2006
+    public function generate_key($string = '') {
2007
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2008
+        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key
2009 2009
     }
2010 2010
     
2011 2011
     public function is_recurring() {
2012
-        if ( empty( $this->cart_details ) ) {
2012
+        if (empty($this->cart_details)) {
2013 2013
             return false;
2014 2014
         }
2015 2015
         
2016 2016
         $has_subscription = false;
2017
-        foreach( $this->cart_details as $cart_item ) {
2018
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2017
+        foreach ($this->cart_details as $cart_item) {
2018
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2019 2019
                 $has_subscription = true;
2020 2020
                 break;
2021 2021
             }
2022 2022
         }
2023 2023
         
2024
-        if ( count( $this->cart_details ) > 1 ) {
2024
+        if (count($this->cart_details) > 1) {
2025 2025
             $has_subscription = false;
2026 2026
         }
2027 2027
 
2028
-        return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );
2028
+        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details);
2029 2029
     }
2030 2030
     
2031 2031
     public function is_free_trial() {
2032 2032
         $is_free_trial = false;
2033 2033
         
2034
-        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) {
2035
-            if ( !empty( $item ) && $item->has_free_trial() ) {
2034
+        if ($this->is_parent() && $item = $this->get_recurring(true)) {
2035
+            if (!empty($item) && $item->has_free_trial()) {
2036 2036
                 $is_free_trial = true;
2037 2037
             }
2038 2038
         }
2039 2039
 
2040
-        return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details );
2040
+        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details);
2041 2041
     }
2042 2042
     
2043
-    public function get_recurring( $object = false ) {
2043
+    public function get_recurring($object = false) {
2044 2044
         $item = NULL;
2045 2045
         
2046
-        if ( empty( $this->cart_details ) ) {
2046
+        if (empty($this->cart_details)) {
2047 2047
             return $item;
2048 2048
         }
2049 2049
         
2050
-        foreach( $this->cart_details as $cart_item ) {
2051
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2050
+        foreach ($this->cart_details as $cart_item) {
2051
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2052 2052
                 $item = $cart_item['id'];
2053 2053
                 break;
2054 2054
             }
2055 2055
         }
2056 2056
         
2057
-        if ( $object ) {
2058
-            $item = $item ? new WPInv_Item( $item ) : NULL;
2057
+        if ($object) {
2058
+            $item = $item ? new WPInv_Item($item) : NULL;
2059 2059
             
2060
-            apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );
2060
+            apply_filters('wpinv_invoice_get_recurring_item', $item, $this);
2061 2061
         }
2062 2062
 
2063
-        return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );
2063
+        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this);
2064 2064
     }
2065 2065
     
2066 2066
     public function get_subscription_name() {
2067
-        $item = $this->get_recurring( true );
2067
+        $item = $this->get_recurring(true);
2068 2068
         
2069
-        if ( empty( $item ) ) {
2069
+        if (empty($item)) {
2070 2070
             return NULL;
2071 2071
         }
2072 2072
         
2073
-        if ( !($name = $item->get_name()) ) {
2073
+        if (!($name = $item->get_name())) {
2074 2074
             $name = $item->post_name;
2075 2075
         }
2076 2076
 
2077
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2077
+        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this);
2078 2078
     }
2079 2079
         
2080 2080
     public function get_expiration() {
2081
-        $expiration = $this->get_meta( '_wpinv_subscr_expiration', true );
2081
+        $expiration = $this->get_meta('_wpinv_subscr_expiration', true);
2082 2082
         return $expiration;
2083 2083
     }
2084 2084
     
2085
-    public function get_cancelled_date( $formatted = true ) {
2086
-        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta( '_wpinv_subscr_cancelled_on', true ) : '';
2085
+    public function get_cancelled_date($formatted = true) {
2086
+        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta('_wpinv_subscr_cancelled_on', true) : '';
2087 2087
         
2088
-        if ( $formatted && $cancelled_date ) {
2089
-            $cancelled_date = date_i18n( get_option( 'date_format' ), strtotime( $cancelled_date ) );
2088
+        if ($formatted && $cancelled_date) {
2089
+            $cancelled_date = date_i18n(get_option('date_format'), strtotime($cancelled_date));
2090 2090
         }
2091 2091
         
2092 2092
         return $cancelled_date;
2093 2093
     }
2094 2094
     
2095
-    public function get_trial_end_date( $formatted = true ) {
2096
-        if ( !$this->is_free_trial() || !$this->is_paid() ) {
2095
+    public function get_trial_end_date($formatted = true) {
2096
+        if (!$this->is_free_trial() || !$this->is_paid()) {
2097 2097
             return NULL;
2098 2098
         }
2099 2099
         
2100
-        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta( '_wpinv_subscr_trial_end', true ) : '';
2100
+        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta('_wpinv_subscr_trial_end', true) : '';
2101 2101
         
2102
-        if ( empty( $trial_end_date ) ) {
2103
-            $trial_start_time = strtotime( $this->get_subscription_start() );
2104
-            $trial_start_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2102
+        if (empty($trial_end_date)) {
2103
+            $trial_start_time = strtotime($this->get_subscription_start());
2104
+            $trial_start_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2105 2105
             
2106
-            $trial_end_date = date_i18n( 'Y-m-d H:i:s', $trial_start_time );
2106
+            $trial_end_date = date_i18n('Y-m-d H:i:s', $trial_start_time);
2107 2107
         }
2108 2108
         
2109
-        if ( $formatted && $trial_end_date ) {
2110
-            $trial_end_date = date_i18n( get_option( 'date_format' ), strtotime( $trial_end_date ) );
2109
+        if ($formatted && $trial_end_date) {
2110
+            $trial_end_date = date_i18n(get_option('date_format'), strtotime($trial_end_date));
2111 2111
         }
2112 2112
         
2113 2113
         return $trial_end_date;
2114 2114
     }
2115 2115
     
2116
-    public function get_subscription_created( $default = true ) {
2117
-        $created = $this->get_meta( '_wpinv_subscr_created', true );
2116
+    public function get_subscription_created($default = true) {
2117
+        $created = $this->get_meta('_wpinv_subscr_created', true);
2118 2118
         
2119
-        if ( empty( $created ) && $default ) {
2119
+        if (empty($created) && $default) {
2120 2120
             $created = $this->date;
2121 2121
         }
2122 2122
         return $created;
2123 2123
     }
2124 2124
     
2125
-    public function get_subscription_start( $formatted = true ) {
2126
-        if ( !$this->is_paid() ) {
2125
+    public function get_subscription_start($formatted = true) {
2126
+        if (!$this->is_paid()) {
2127 2127
             return '-';
2128 2128
         }
2129
-        $start   = $this->get_subscription_created();
2129
+        $start = $this->get_subscription_created();
2130 2130
         
2131
-        if ( $formatted ) {
2132
-            $date = date_i18n( get_option( 'date_format' ), strtotime( $start ) );
2131
+        if ($formatted) {
2132
+            $date = date_i18n(get_option('date_format'), strtotime($start));
2133 2133
         } else {
2134
-            $date = date_i18n( 'Y-m-d H:i:s', strtotime( $start ) );
2134
+            $date = date_i18n('Y-m-d H:i:s', strtotime($start));
2135 2135
         }
2136 2136
 
2137 2137
         return $date;
2138 2138
     }
2139 2139
     
2140
-    public function get_subscription_end( $formatted = true ) {
2141
-        if ( !$this->is_paid() ) {
2140
+    public function get_subscription_end($formatted = true) {
2141
+        if (!$this->is_paid()) {
2142 2142
             return '-';
2143 2143
         }
2144 2144
         $start          = $this->get_subscription_created();
2145 2145
         $interval       = $this->get_subscription_interval();
2146
-        $period         = $this->get_subscription_period( true );
2146
+        $period         = $this->get_subscription_period(true);
2147 2147
         $bill_times     = (int)$this->get_bill_times();
2148 2148
         
2149
-        if ( $bill_times == 0 ) {
2150
-            return $formatted ? __( 'Until cancelled', 'invoicing' ) : $bill_times;
2149
+        if ($bill_times == 0) {
2150
+            return $formatted ? __('Until cancelled', 'invoicing') : $bill_times;
2151 2151
         }
2152 2152
         
2153
-        $total_period = $start . '+' . ( $interval * $bill_times ) . ' ' . $period;
2153
+        $total_period = $start . '+' . ($interval * $bill_times) . ' ' . $period;
2154 2154
         
2155
-        $end_time = strtotime( $start . '+' . ( $interval * $bill_times ) . ' ' . $period );
2155
+        $end_time = strtotime($start . '+' . ($interval * $bill_times) . ' ' . $period);
2156 2156
         
2157
-        if ( $this->is_free_trial() ) {
2158
-            $end_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2157
+        if ($this->is_free_trial()) {
2158
+            $end_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2159 2159
         }
2160 2160
         
2161
-        if ( $formatted ) {
2162
-            $date = date_i18n( get_option( 'date_format' ), $end_time );
2161
+        if ($formatted) {
2162
+            $date = date_i18n(get_option('date_format'), $end_time);
2163 2163
         } else {
2164
-            $date = date_i18n( 'Y-m-d H:i:s', $end_time );
2164
+            $date = date_i18n('Y-m-d H:i:s', $end_time);
2165 2165
         }
2166 2166
 
2167 2167
         return $date;
2168 2168
     }
2169 2169
     
2170 2170
     public function get_expiration_time() {
2171
-        return strtotime( $this->get_expiration(), current_time( 'timestamp' ) );
2171
+        return strtotime($this->get_expiration(), current_time('timestamp'));
2172 2172
     }
2173 2173
     
2174 2174
     public function get_original_invoice_id() {        
@@ -2180,125 +2180,125 @@  discard block
 block discarded – undo
2180 2180
         return $subscription_data['bill_times'];
2181 2181
     }
2182 2182
 
2183
-    public function get_child_payments( $self = false ) {
2184
-        $invoices = get_posts( array(
2183
+    public function get_child_payments($self = false) {
2184
+        $invoices = get_posts(array(
2185 2185
             'post_type'         => $this->post_type,
2186 2186
             'post_parent'       => (int)$this->ID,
2187 2187
             'posts_per_page'    => '999',
2188
-            'post_status'       => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
2188
+            'post_status'       => array('publish', 'wpi-processing', 'wpi-renewal'),
2189 2189
             'orderby'           => 'ID',
2190 2190
             'order'             => 'DESC',
2191 2191
             'fields'            => 'ids'
2192
-        ) );
2192
+        ));
2193 2193
         
2194
-        if ( $this->is_free_trial() ) {
2194
+        if ($this->is_free_trial()) {
2195 2195
             $self = false;
2196 2196
         }
2197 2197
         
2198
-        if ( $self && $this->is_paid() ) {
2199
-            if ( !empty( $invoices ) ) {
2198
+        if ($self && $this->is_paid()) {
2199
+            if (!empty($invoices)) {
2200 2200
                 $invoices[] = (int)$this->ID;
2201 2201
             } else {
2202
-                $invoices = array( $this->ID );
2202
+                $invoices = array($this->ID);
2203 2203
             }
2204 2204
             
2205
-            $invoices = array_unique( $invoices );
2205
+            $invoices = array_unique($invoices);
2206 2206
         }
2207 2207
 
2208 2208
         return $invoices;
2209 2209
     }
2210 2210
 
2211
-    public function get_total_payments( $self = true ) {
2212
-        return count( $this->get_child_payments( $self ) );
2211
+    public function get_total_payments($self = true) {
2212
+        return count($this->get_child_payments($self));
2213 2213
     }
2214 2214
     
2215
-    public function get_subscriptions( $limit = -1 ) {
2216
-        $subscriptions = wpinv_get_subscriptions( array( 'parent_invoice_id' => $this->ID, 'numberposts' => $limit ) );
2215
+    public function get_subscriptions($limit = -1) {
2216
+        $subscriptions = wpinv_get_subscriptions(array('parent_invoice_id' => $this->ID, 'numberposts' => $limit));
2217 2217
 
2218 2218
         return $subscriptions;
2219 2219
     }
2220 2220
     
2221 2221
     public function get_subscription_id() {
2222
-        $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );
2222
+        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true);
2223 2223
         
2224
-        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) {
2225
-            $parent_invoice = wpinv_get_invoice( $this->parent_invoice );
2224
+        if (empty($subscription_id) && !empty($this->parent_invoice)) {
2225
+            $parent_invoice = wpinv_get_invoice($this->parent_invoice);
2226 2226
             
2227
-            $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );
2227
+            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true);
2228 2228
         }
2229 2229
         
2230 2230
         return $subscription_id;
2231 2231
     }
2232 2232
     
2233 2233
     public function get_subscription_status() {
2234
-        $subscription_status = $this->get_meta( '_wpinv_subscr_status', true );
2234
+        $subscription_status = $this->get_meta('_wpinv_subscr_status', true);
2235 2235
 
2236
-        if ( empty( $subscription_status ) ) {
2236
+        if (empty($subscription_status)) {
2237 2237
             $status = 'pending';
2238 2238
             
2239
-            if ( $this->is_paid() ) {        
2239
+            if ($this->is_paid()) {        
2240 2240
                 $bill_times   = (int)$this->get_bill_times();
2241 2241
                 $times_billed = (int)$this->get_total_payments();
2242
-                $expiration = $this->get_subscription_end( false );
2243
-                $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime( date_i18n( 'Y-m-d', strtotime( $expiration ) ) ) < strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) ) ? true : false;
2242
+                $expiration = $this->get_subscription_end(false);
2243
+                $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime(date_i18n('Y-m-d', strtotime($expiration))) < strtotime(date_i18n('Y-m-d', current_time('timestamp'))) ? true : false;
2244 2244
                 
2245
-                if ( (int)$bill_times == 0 ) {
2245
+                if ((int)$bill_times == 0) {
2246 2246
                     $status = $expired ? 'expired' : 'active';
2247
-                } else if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2247
+                } else if ($bill_times > 0 && $times_billed >= $bill_times) {
2248 2248
                     $status = 'completed';
2249
-                } else if ( $expired ) {
2249
+                } else if ($expired) {
2250 2250
                     $status = 'expired';
2251
-                } else if ( $bill_times > 0 ) {
2251
+                } else if ($bill_times > 0) {
2252 2252
                     $status = 'active';
2253 2253
                 } else {
2254 2254
                     $status = 'pending';
2255 2255
                 }
2256 2256
             }
2257 2257
             
2258
-            if ( $status && $status != $subscription_status ) {
2258
+            if ($status && $status != $subscription_status) {
2259 2259
                 $subscription_status = $status;
2260 2260
                 
2261
-                $this->update_meta( '_wpinv_subscr_status', $status );
2261
+                $this->update_meta('_wpinv_subscr_status', $status);
2262 2262
             }
2263 2263
         }
2264 2264
         
2265 2265
         return $subscription_status;
2266 2266
     }
2267 2267
     
2268
-    public function get_subscription_status_label( $status = '' ) {
2269
-        $status = !empty( $status ) ? $status : $this->get_subscription_status();
2268
+    public function get_subscription_status_label($status = '') {
2269
+        $status = !empty($status) ? $status : $this->get_subscription_status();
2270 2270
 
2271
-        switch( $status ) {
2271
+        switch ($status) {
2272 2272
             case 'active' :
2273
-                $status_label = __( 'Active', 'invoicing' );
2273
+                $status_label = __('Active', 'invoicing');
2274 2274
                 break;
2275 2275
 
2276 2276
             case 'cancelled' :
2277
-                $status_label = __( 'Cancelled', 'invoicing' );
2277
+                $status_label = __('Cancelled', 'invoicing');
2278 2278
                 break;
2279 2279
                 
2280 2280
             case 'completed' :
2281
-                $status_label = __( 'Completed', 'invoicing' );
2281
+                $status_label = __('Completed', 'invoicing');
2282 2282
                 break;
2283 2283
 
2284 2284
             case 'expired' :
2285
-                $status_label = __( 'Expired', 'invoicing' );
2285
+                $status_label = __('Expired', 'invoicing');
2286 2286
                 break;
2287 2287
 
2288 2288
             case 'pending' :
2289
-                $status_label = __( 'Pending', 'invoicing' );
2289
+                $status_label = __('Pending', 'invoicing');
2290 2290
                 break;
2291 2291
 
2292 2292
             case 'failing' :
2293
-                $status_label = __( 'Failing', 'invoicing' );
2293
+                $status_label = __('Failing', 'invoicing');
2294 2294
                 break;
2295 2295
                 
2296 2296
             case 'stopped' :
2297
-                $status_label = __( 'Stopped', 'invoicing' );
2297
+                $status_label = __('Stopped', 'invoicing');
2298 2298
                 break;
2299 2299
                 
2300 2300
             case 'trialing' :
2301
-                $status_label = __( 'Trialing', 'invoicing' );
2301
+                $status_label = __('Trialing', 'invoicing');
2302 2302
                 break;
2303 2303
 
2304 2304
             default:
@@ -2309,26 +2309,26 @@  discard block
 block discarded – undo
2309 2309
         return $status_label;
2310 2310
     }
2311 2311
     
2312
-    public function get_subscription_period( $full = false ) {
2313
-        $period = $this->get_meta( '_wpinv_subscr_period', true );
2312
+    public function get_subscription_period($full = false) {
2313
+        $period = $this->get_meta('_wpinv_subscr_period', true);
2314 2314
         
2315 2315
         // Fix period for old invoices
2316
-        if ( $period == 'day' ) {
2316
+        if ($period == 'day') {
2317 2317
             $period = 'D';
2318
-        } else if ( $period == 'week' ) {
2318
+        } else if ($period == 'week') {
2319 2319
             $period = 'W';
2320
-        } else if ( $period == 'month' ) {
2320
+        } else if ($period == 'month') {
2321 2321
             $period = 'M';
2322
-        } else if ( $period == 'year' ) {
2322
+        } else if ($period == 'year') {
2323 2323
             $period = 'Y';
2324 2324
         }
2325 2325
         
2326
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2326
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2327 2327
             $period = 'D';
2328 2328
         }
2329 2329
         
2330
-        if ( $full ) {
2331
-            switch( $period ) {
2330
+        if ($full) {
2331
+            switch ($period) {
2332 2332
                 case 'D':
2333 2333
                     $period = 'day';
2334 2334
                 break;
@@ -2348,39 +2348,39 @@  discard block
 block discarded – undo
2348 2348
     }
2349 2349
     
2350 2350
     public function get_subscription_interval() {
2351
-        $interval = (int)$this->get_meta( '_wpinv_subscr_interval', true );
2351
+        $interval = (int)$this->get_meta('_wpinv_subscr_interval', true);
2352 2352
         
2353
-        if ( !$interval > 0 ) {
2353
+        if (!$interval > 0) {
2354 2354
             $interval = 1;
2355 2355
         }
2356 2356
         
2357 2357
         return $interval;
2358 2358
     }
2359 2359
     
2360
-    public function get_subscription_trial_period( $full = false ) {
2361
-        if ( !$this->is_free_trial() ) {
2360
+    public function get_subscription_trial_period($full = false) {
2361
+        if (!$this->is_free_trial()) {
2362 2362
             return '';
2363 2363
         }
2364 2364
         
2365
-        $period = $this->get_meta( '_wpinv_subscr_trial_period', true );
2365
+        $period = $this->get_meta('_wpinv_subscr_trial_period', true);
2366 2366
         
2367 2367
         // Fix period for old invoices
2368
-        if ( $period == 'day' ) {
2368
+        if ($period == 'day') {
2369 2369
             $period = 'D';
2370
-        } else if ( $period == 'week' ) {
2370
+        } else if ($period == 'week') {
2371 2371
             $period = 'W';
2372
-        } else if ( $period == 'month' ) {
2372
+        } else if ($period == 'month') {
2373 2373
             $period = 'M';
2374
-        } else if ( $period == 'year' ) {
2374
+        } else if ($period == 'year') {
2375 2375
             $period = 'Y';
2376 2376
         }
2377 2377
         
2378
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2378
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2379 2379
             $period = 'D';
2380 2380
         }
2381 2381
         
2382
-        if ( $full ) {
2383
-            switch( $period ) {
2382
+        if ($full) {
2383
+            switch ($period) {
2384 2384
                 case 'D':
2385 2385
                     $period = 'day';
2386 2386
                 break;
@@ -2400,13 +2400,13 @@  discard block
 block discarded – undo
2400 2400
     }
2401 2401
     
2402 2402
     public function get_subscription_trial_interval() {
2403
-        if ( !$this->is_free_trial() ) {
2403
+        if (!$this->is_free_trial()) {
2404 2404
             return 0;
2405 2405
         }
2406 2406
         
2407
-        $interval = (int)$this->get_meta( '_wpinv_subscr_trial_interval', true );
2407
+        $interval = (int)$this->get_meta('_wpinv_subscr_trial_interval', true);
2408 2408
         
2409
-        if ( !$interval > 0 ) {
2409
+        if (!$interval > 0) {
2410 2410
             $interval = 1;
2411 2411
         }
2412 2412
         
@@ -2418,8 +2418,8 @@  discard block
 block discarded – undo
2418 2418
             'status' => 'failing'
2419 2419
         );
2420 2420
 
2421
-        if ( $this->update_subscription( $args ) ) {
2422
-            do_action( 'wpinv_subscription_failing', $this->ID, $this );
2421
+        if ($this->update_subscription($args)) {
2422
+            do_action('wpinv_subscription_failing', $this->ID, $this);
2423 2423
             return true;
2424 2424
         }
2425 2425
 
@@ -2431,8 +2431,8 @@  discard block
 block discarded – undo
2431 2431
             'status' => 'stopped'
2432 2432
         );
2433 2433
 
2434
-        if ( $this->update_subscription( $args ) ) {
2435
-            do_action( 'wpinv_subscription_stopped', $this->ID, $this );
2434
+        if ($this->update_subscription($args)) {
2435
+            do_action('wpinv_subscription_stopped', $this->ID, $this);
2436 2436
             return true;
2437 2437
         }
2438 2438
 
@@ -2444,8 +2444,8 @@  discard block
 block discarded – undo
2444 2444
             'status' => 'active'
2445 2445
         );
2446 2446
 
2447
-        if ( $this->update_subscription( $args ) ) {
2448
-            do_action( 'wpinv_subscription_restarted', $this->ID, $this );
2447
+        if ($this->update_subscription($args)) {
2448
+            do_action('wpinv_subscription_restarted', $this->ID, $this);
2449 2449
             return true;
2450 2450
         }
2451 2451
 
@@ -2457,23 +2457,23 @@  discard block
 block discarded – undo
2457 2457
             'status' => 'cancelled'
2458 2458
         );
2459 2459
 
2460
-        if ( $this->update_subscription( $args ) ) {
2461
-            if ( is_user_logged_in() ) {
2462
-                $userdata = get_userdata( get_current_user_id() );
2460
+        if ($this->update_subscription($args)) {
2461
+            if (is_user_logged_in()) {
2462
+                $userdata = get_userdata(get_current_user_id());
2463 2463
                 $user     = $userdata->user_login;
2464 2464
             } else {
2465
-                $user = __( 'gateway', 'invoicing' );
2465
+                $user = __('gateway', 'invoicing');
2466 2466
             }
2467 2467
             
2468 2468
             $subscription_id = $this->get_subscription_id();
2469
-            if ( !$subscription_id ) {
2469
+            if (!$subscription_id) {
2470 2470
                 $subscription_id = $this->ID;
2471 2471
             }
2472 2472
 
2473
-            $note = sprintf( __( 'Subscription %s has been cancelled by %s', 'invoicing' ), $subscription_id, $user );
2474
-            $this->add_note( $note );
2473
+            $note = sprintf(__('Subscription %s has been cancelled by %s', 'invoicing'), $subscription_id, $user);
2474
+            $this->add_note($note);
2475 2475
 
2476
-            do_action( 'wpinv_subscription_cancelled', $this->ID, $this );
2476
+            do_action('wpinv_subscription_cancelled', $this->ID, $this);
2477 2477
             return true;
2478 2478
         }
2479 2479
 
@@ -2481,11 +2481,11 @@  discard block
 block discarded – undo
2481 2481
     }
2482 2482
 
2483 2483
     public function can_cancel() {
2484
-        return apply_filters( 'wpinv_subscription_can_cancel', false, $this );
2484
+        return apply_filters('wpinv_subscription_can_cancel', false, $this);
2485 2485
     }
2486 2486
     
2487
-    public function add_subscription( $data = array() ) {
2488
-        if ( empty( $this->ID ) ) {
2487
+    public function add_subscription($data = array()) {
2488
+        if (empty($this->ID)) {
2489 2489
             return false;
2490 2490
         }
2491 2491
 
@@ -2504,85 +2504,85 @@  discard block
 block discarded – undo
2504 2504
             'profile_id'        => '',
2505 2505
         );
2506 2506
 
2507
-        $args = wp_parse_args( $data, $defaults );
2507
+        $args = wp_parse_args($data, $defaults);
2508 2508
 
2509
-        if ( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2510
-            if ( 'active' == $args['status'] || $args['status'] == 'trialing' ) {
2509
+        if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2510
+            if ('active' == $args['status'] || $args['status'] == 'trialing') {
2511 2511
                 $args['status'] = 'expired';
2512 2512
             }
2513 2513
         }
2514 2514
 
2515
-        do_action( 'wpinv_subscription_pre_create', $args, $data, $this );
2515
+        do_action('wpinv_subscription_pre_create', $args, $data, $this);
2516 2516
         
2517
-        if ( !empty( $args ) ) {
2518
-            foreach ( $args as $key => $value ) {
2519
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2517
+        if (!empty($args)) {
2518
+            foreach ($args as $key => $value) {
2519
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2520 2520
             }
2521 2521
         }
2522 2522
 
2523
-        do_action( 'wpinv_subscription_post_create', $args, $data, $this );
2523
+        do_action('wpinv_subscription_post_create', $args, $data, $this);
2524 2524
 
2525 2525
         return true;
2526 2526
     }
2527 2527
     
2528
-    public function update_subscription( $args = array() ) {
2529
-        if ( empty( $this->ID ) ) {
2528
+    public function update_subscription($args = array()) {
2529
+        if (empty($this->ID)) {
2530 2530
             return false;
2531 2531
         }
2532 2532
 
2533
-        if ( !empty( $args['expiration'] ) && $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2534
-            if ( !isset( $args['status'] ) || ( isset( $args['status'] ) && ( 'active' == $args['status'] || $args['status'] == 'trialing' ) ) ) {
2533
+        if (!empty($args['expiration']) && $args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2534
+            if (!isset($args['status']) || (isset($args['status']) && ('active' == $args['status'] || $args['status'] == 'trialing'))) {
2535 2535
                 $args['status'] = 'expired';
2536 2536
             }
2537 2537
         }
2538 2538
 
2539
-        if ( isset( $args['status'] ) && $args['status'] == 'cancelled' && empty( $args['cancelled_on'] ) ) {
2540
-            $args['cancelled_on'] = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
2539
+        if (isset($args['status']) && $args['status'] == 'cancelled' && empty($args['cancelled_on'])) {
2540
+            $args['cancelled_on'] = date_i18n('Y-m-d H:i:s', current_time('timestamp'));
2541 2541
         }
2542 2542
 
2543
-        do_action( 'wpinv_subscription_pre_update', $args, $this );
2543
+        do_action('wpinv_subscription_pre_update', $args, $this);
2544 2544
         
2545
-        if ( !empty( $args ) ) {
2546
-            foreach ( $args as $key => $value ) {
2547
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2545
+        if (!empty($args)) {
2546
+            foreach ($args as $key => $value) {
2547
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2548 2548
             }
2549 2549
         }
2550 2550
 
2551
-        do_action( 'wpinv_subscription_post_update', $args, $this );
2551
+        do_action('wpinv_subscription_post_update', $args, $this);
2552 2552
 
2553 2553
         return true;
2554 2554
     }
2555 2555
     
2556 2556
     public function renew_subscription() {
2557 2557
         $parent_invoice = $this->get_parent_payment();
2558
-        $parent_invoice = empty( $parent_invoice ) ? $this : $parent_invoice;
2558
+        $parent_invoice = empty($parent_invoice) ? $this : $parent_invoice;
2559 2559
         
2560
-        $current_time   = current_time( 'timestamp' );
2560
+        $current_time   = current_time('timestamp');
2561 2561
         $start          = $this->get_subscription_created();
2562
-        $start          = $start ? strtotime( $start ) : $current_time;
2562
+        $start          = $start ? strtotime($start) : $current_time;
2563 2563
         $expires        = $this->get_expiration_time();
2564 2564
         
2565
-        if ( !$expires ) {
2566
-            $expires    = strtotime( '+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period( true ), $start );
2565
+        if (!$expires) {
2566
+            $expires    = strtotime('+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period(true), $start);
2567 2567
         }
2568 2568
         
2569
-        $expiration     = date_i18n( 'Y-m-d 23:59:59', $expires );
2570
-        $expiration     = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this );
2569
+        $expiration     = date_i18n('Y-m-d 23:59:59', $expires);
2570
+        $expiration     = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this);
2571 2571
         $bill_times     = $parent_invoice->get_bill_times();
2572 2572
         $times_billed   = $parent_invoice->get_total_payments();
2573 2573
         
2574
-        if ( $parent_invoice->get_subscription_status() == 'trialing' && ( $times_billed > 0 || strtotime( date_i18n( 'Y-m-d' ) ) < strtotime( $parent_invoice->get_trial_end_date( false ) ) ) ) {
2574
+        if ($parent_invoice->get_subscription_status() == 'trialing' && ($times_billed > 0 || strtotime(date_i18n('Y-m-d')) < strtotime($parent_invoice->get_trial_end_date(false)))) {
2575 2575
             $args = array(
2576 2576
                 'status'     => 'active',
2577 2577
             );
2578 2578
 
2579
-            $parent_invoice->update_subscription( $args );
2579
+            $parent_invoice->update_subscription($args);
2580 2580
         }
2581 2581
         
2582
-        do_action( 'wpinv_subscription_pre_renew', $this->ID, $expiration, $this );
2582
+        do_action('wpinv_subscription_pre_renew', $this->ID, $expiration, $this);
2583 2583
 
2584
-        $status       = 'active';
2585
-        if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2584
+        $status = 'active';
2585
+        if ($bill_times > 0 && $times_billed >= $bill_times) {
2586 2586
             $this->complete_subscription();
2587 2587
             $status = 'completed';
2588 2588
         }
@@ -2592,10 +2592,10 @@  discard block
 block discarded – undo
2592 2592
             'status'     => $status,
2593 2593
         );
2594 2594
 
2595
-        $this->update_subscription( $args );
2595
+        $this->update_subscription($args);
2596 2596
 
2597
-        do_action( 'wpinv_subscription_post_renew', $this->ID, $expiration, $this );
2598
-        do_action( 'wpinv_recurring_set_subscription_status', $this->ID, $status, $this );
2597
+        do_action('wpinv_subscription_post_renew', $this->ID, $expiration, $this);
2598
+        do_action('wpinv_recurring_set_subscription_status', $this->ID, $status, $this);
2599 2599
     }
2600 2600
     
2601 2601
     public function complete_subscription() {
@@ -2603,8 +2603,8 @@  discard block
 block discarded – undo
2603 2603
             'status' => 'completed'
2604 2604
         );
2605 2605
 
2606
-        if ( $this->update_subscription( $args ) ) {
2607
-            do_action( 'wpinv_subscription_completed', $this->ID, $this );
2606
+        if ($this->update_subscription($args)) {
2607
+            do_action('wpinv_subscription_completed', $this->ID, $this);
2608 2608
         }
2609 2609
     }
2610 2610
     
@@ -2613,44 +2613,44 @@  discard block
 block discarded – undo
2613 2613
             'status' => 'expired'
2614 2614
         );
2615 2615
 
2616
-        if ( $this->update_subscription( $args ) ) {
2617
-            do_action( 'wpinv_subscription_expired', $this->ID, $this );
2616
+        if ($this->update_subscription($args)) {
2617
+            do_action('wpinv_subscription_expired', $this->ID, $this);
2618 2618
         }
2619 2619
     }
2620 2620
 
2621 2621
     public function get_cancel_url() {
2622
-        $url = wp_nonce_url( add_query_arg( array( 'wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID ) ), 'wpinv-recurring-cancel' );
2622
+        $url = wp_nonce_url(add_query_arg(array('wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID)), 'wpinv-recurring-cancel');
2623 2623
 
2624
-        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
2624
+        return apply_filters('wpinv_subscription_cancel_url', $url, $this);
2625 2625
     }
2626 2626
 
2627 2627
     public function can_update() {
2628
-        return apply_filters( 'wpinv_subscription_can_update', false, $this );
2628
+        return apply_filters('wpinv_subscription_can_update', false, $this);
2629 2629
     }
2630 2630
 
2631 2631
     public function get_update_url() {
2632
-        $url = add_query_arg( array( 'action' => 'update', 'sub_id' => $this->ID ) );
2632
+        $url = add_query_arg(array('action' => 'update', 'sub_id' => $this->ID));
2633 2633
 
2634
-        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
2634
+        return apply_filters('wpinv_subscription_update_url', $url, $this);
2635 2635
     }
2636 2636
 
2637 2637
     public function is_parent() {
2638
-        $is_parent = empty( $this->parent_invoice ) ? true : false;
2638
+        $is_parent = empty($this->parent_invoice) ? true : false;
2639 2639
 
2640
-        return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );
2640
+        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this);
2641 2641
     }
2642 2642
     
2643 2643
     public function is_renewal() {
2644 2644
         $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;
2645 2645
 
2646
-        return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );
2646
+        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this);
2647 2647
     }
2648 2648
     
2649 2649
     public function get_parent_payment() {
2650 2650
         $parent_payment = NULL;
2651 2651
         
2652
-        if ( $this->is_renewal() ) {
2653
-            $parent_payment = wpinv_get_invoice( $this->parent_invoice );
2652
+        if ($this->is_renewal()) {
2653
+            $parent_payment = wpinv_get_invoice($this->parent_invoice);
2654 2654
         }
2655 2655
         
2656 2656
         return $parent_payment;
@@ -2661,100 +2661,100 @@  discard block
 block discarded – undo
2661 2661
         
2662 2662
         $subscription_status = $this->get_subscription_status();
2663 2663
 
2664
-        if( ! $this->is_subscription_expired() && ( $subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing' ) ) {
2664
+        if (!$this->is_subscription_expired() && ($subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing')) {
2665 2665
             $ret = true;
2666 2666
         }
2667 2667
 
2668
-        return apply_filters( 'wpinv_subscription_is_active', $ret, $this->ID, $this );
2668
+        return apply_filters('wpinv_subscription_is_active', $ret, $this->ID, $this);
2669 2669
     }
2670 2670
 
2671 2671
     public function is_subscription_expired() {
2672 2672
         $ret = false;
2673 2673
         $subscription_status = $this->get_subscription_status();
2674 2674
 
2675
-        if ( $subscription_status == 'expired' ) {
2675
+        if ($subscription_status == 'expired') {
2676 2676
             $ret = true;
2677
-        } else if ( 'active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status ) {
2677
+        } else if ('active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status) {
2678 2678
             $ret        = false;
2679 2679
             $expiration = $this->get_expiration_time();
2680 2680
 
2681
-            if ( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) {
2681
+            if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) {
2682 2682
                 $ret = true;
2683 2683
 
2684
-                if ( 'active' === $subscription_status || 'trialing' === $subscription_status ) {
2684
+                if ('active' === $subscription_status || 'trialing' === $subscription_status) {
2685 2685
                     $this->expire_subscription();
2686 2686
                 }
2687 2687
             }
2688 2688
         }
2689 2689
 
2690
-        return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->ID, $this );
2690
+        return apply_filters('wpinv_subscription_is_expired', $ret, $this->ID, $this);
2691 2691
     }
2692 2692
     
2693
-    public function get_new_expiration( $item_id = 0, $trial = true ) {
2694
-        $item   = new WPInv_Item( $item_id );
2693
+    public function get_new_expiration($item_id = 0, $trial = true) {
2694
+        $item   = new WPInv_Item($item_id);
2695 2695
         $interval = $item->get_recurring_interval();
2696
-        $period = $item->get_recurring_period( true );
2696
+        $period = $item->get_recurring_period(true);
2697 2697
         
2698
-        $expiration_time = strtotime( '+' . $interval . ' ' . $period );
2698
+        $expiration_time = strtotime('+' . $interval . ' ' . $period);
2699 2699
         
2700
-        if ( $trial && $this->is_free_trial() && $item->has_free_trial() ) {
2701
-            $expiration_time += ( wpinv_period_in_days( $item->get_trial_interval(), $item->get_trial_period() ) * DAY_IN_SECONDS ) ;
2700
+        if ($trial && $this->is_free_trial() && $item->has_free_trial()) {
2701
+            $expiration_time += (wpinv_period_in_days($item->get_trial_interval(), $item->get_trial_period()) * DAY_IN_SECONDS);
2702 2702
         }
2703 2703
 
2704
-        return date_i18n( 'Y-m-d 23:59:59', $expiration_time );
2704
+        return date_i18n('Y-m-d 23:59:59', $expiration_time);
2705 2705
     }
2706 2706
     
2707
-    public function get_subscription_data( $filed = '' ) {
2708
-        $fields = array( 'item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on' );
2707
+    public function get_subscription_data($filed = '') {
2708
+        $fields = array('item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on');
2709 2709
         
2710 2710
         $subscription_meta = array();
2711
-        foreach ( $fields as $field ) {
2712
-            $subscription_meta[ $field ] = $this->get_meta( '_wpinv_subscr_' . $field );
2711
+        foreach ($fields as $field) {
2712
+            $subscription_meta[$field] = $this->get_meta('_wpinv_subscr_' . $field);
2713 2713
         }
2714 2714
         
2715
-        $item = $this->get_recurring( true );
2715
+        $item = $this->get_recurring(true);
2716 2716
         
2717
-        if ( !empty( $item ) ) {
2718
-            if ( empty( $subscription_meta['item_id'] ) ) {
2717
+        if (!empty($item)) {
2718
+            if (empty($subscription_meta['item_id'])) {
2719 2719
                 $subscription_meta['item_id'] = $item->ID;
2720 2720
             }
2721
-            if ( empty( $subscription_meta['period'] ) ) {
2721
+            if (empty($subscription_meta['period'])) {
2722 2722
                 $subscription_meta['period'] = $item->get_recurring_period();
2723 2723
             }
2724
-            if ( empty( $subscription_meta['interval'] ) ) {
2724
+            if (empty($subscription_meta['interval'])) {
2725 2725
                 $subscription_meta['interval'] = $item->get_recurring_interval();
2726 2726
             }
2727
-            if ( $item->has_free_trial() ) {
2728
-                if ( empty( $subscription_meta['trial_period'] ) ) {
2727
+            if ($item->has_free_trial()) {
2728
+                if (empty($subscription_meta['trial_period'])) {
2729 2729
                     $subscription_meta['trial_period'] = $item->get_trial_period();
2730 2730
                 }
2731
-                if ( empty( $subscription_meta['trial_interval'] ) ) {
2731
+                if (empty($subscription_meta['trial_interval'])) {
2732 2732
                     $subscription_meta['trial_interval'] = $item->get_trial_interval();
2733 2733
                 }
2734 2734
             } else {
2735 2735
                 $subscription_meta['trial_period']      = '';
2736 2736
                 $subscription_meta['trial_interval']    = 0;
2737 2737
             }
2738
-            if ( !$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0 ) {
2738
+            if (!$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0) {
2739 2739
                 $subscription_meta['bill_times'] = $item->get_recurring_limit();
2740 2740
             }
2741
-            if ( $subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '' ) {
2742
-                $subscription_meta['initial_amount']    = wpinv_round_amount( $this->get_total() );
2743
-                $subscription_meta['recurring_amount']  = wpinv_round_amount( $this->get_recurring_details( 'total' ) );
2741
+            if ($subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '') {
2742
+                $subscription_meta['initial_amount']    = wpinv_round_amount($this->get_total());
2743
+                $subscription_meta['recurring_amount']  = wpinv_round_amount($this->get_recurring_details('total'));
2744 2744
             }
2745 2745
         }
2746 2746
         
2747
-        if ( $filed === '' ) {
2748
-            return apply_filters( 'wpinv_get_invoice_subscription_data', $subscription_meta, $this );
2747
+        if ($filed === '') {
2748
+            return apply_filters('wpinv_get_invoice_subscription_data', $subscription_meta, $this);
2749 2749
         }
2750 2750
         
2751
-        $value = isset( $subscription_meta[$filed] ) ? $subscription_meta[$filed] : '';
2751
+        $value = isset($subscription_meta[$filed]) ? $subscription_meta[$filed] : '';
2752 2752
         
2753
-        return apply_filters( 'wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this );
2753
+        return apply_filters('wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this);
2754 2754
     }
2755 2755
     
2756 2756
     public function is_paid() {
2757
-        if ( $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
2757
+        if ($this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'))) {
2758 2758
             return true;
2759 2759
         }
2760 2760
         
@@ -2764,15 +2764,15 @@  discard block
 block discarded – undo
2764 2764
     public function is_free() {
2765 2765
         $is_free = false;
2766 2766
         
2767
-        if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) {
2768
-            if ( $this->is_parent() && $this->is_recurring() ) {
2769
-                $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true;
2767
+        if (!((float)wpinv_round_amount($this->get_total()) > 0)) {
2768
+            if ($this->is_parent() && $this->is_recurring()) {
2769
+                $is_free = (float)wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true;
2770 2770
             } else {
2771 2771
                 $is_free = true;
2772 2772
             }
2773 2773
         }
2774 2774
         
2775
-        return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2775
+        return apply_filters('wpinv_invoice_is_free', $is_free, $this);
2776 2776
     }
2777 2777
     
2778 2778
     public function has_vat() {
@@ -2780,28 +2780,28 @@  discard block
 block discarded – undo
2780 2780
         
2781 2781
         $requires_vat = false;
2782 2782
         
2783
-        if ( $this->country ) {
2783
+        if ($this->country) {
2784 2784
             $wpi_country        = $this->country;
2785 2785
             
2786
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2786
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2787 2787
         }
2788 2788
         
2789
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2789
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2790 2790
     }
2791 2791
     
2792 2792
     public function refresh_item_ids() {
2793 2793
         $item_ids = array();
2794 2794
         
2795
-        if ( !empty( $this->cart_details ) ) {
2796
-            foreach ( $this->cart_details as $key => $item ) {
2797
-                if ( !empty( $item['id'] ) ) {
2795
+        if (!empty($this->cart_details)) {
2796
+            foreach ($this->cart_details as $key => $item) {
2797
+                if (!empty($item['id'])) {
2798 2798
                     $item_ids[] = $item['id'];
2799 2799
                 }
2800 2800
             }
2801 2801
         }
2802 2802
         
2803
-        $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';
2803
+        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : '';
2804 2804
         
2805
-        update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );
2805
+        update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);
2806 2806
     }
2807 2807
 }
Please login to merge, or discard this patch.
includes/wpinv-tax-functions.php 1 patch
Spacing   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -1,121 +1,121 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 function wpinv_use_taxes() {
8
-    $ret = wpinv_get_option( 'enable_taxes', false );
8
+    $ret = wpinv_get_option('enable_taxes', false);
9 9
     
10
-    return (bool) apply_filters( 'wpinv_use_taxes', $ret );
10
+    return (bool)apply_filters('wpinv_use_taxes', $ret);
11 11
 }
12 12
 
13 13
 function wpinv_get_tax_rates() {
14
-    $rates = get_option( 'wpinv_tax_rates', array() );
14
+    $rates = get_option('wpinv_tax_rates', array());
15 15
     
16
-    return apply_filters( 'wpinv_get_tax_rates', $rates );
16
+    return apply_filters('wpinv_get_tax_rates', $rates);
17 17
 }
18 18
 
19
-function wpinv_get_tax_rate( $country = false, $state = false, $item_id = 0 ) {
19
+function wpinv_get_tax_rate($country = false, $state = false, $item_id = 0) {
20 20
     global $wpinv_euvat, $wpi_tax_rates, $wpi_userID;
21
-    $wpi_tax_rates = !empty( $wpi_tax_rates ) ? $wpi_tax_rates : array();
21
+    $wpi_tax_rates = !empty($wpi_tax_rates) ? $wpi_tax_rates : array();
22 22
     
23
-    if ( !empty( $wpi_tax_rates ) && !empty( $item_id ) && isset( $wpi_tax_rates[$item_id] ) ) {
23
+    if (!empty($wpi_tax_rates) && !empty($item_id) && isset($wpi_tax_rates[$item_id])) {
24 24
         return $wpi_tax_rates[$item_id];
25 25
     }
26 26
     
27
-    if ( !$wpinv_euvat->item_is_taxable( $item_id, $country, $state ) ) {
27
+    if (!$wpinv_euvat->item_is_taxable($item_id, $country, $state)) {
28 28
         $wpi_tax_rates[$item_id] = 0;
29 29
         return 0;
30 30
     }
31 31
     
32 32
     $is_global = false;
33
-    if ( $item_id == 'global' ) {
33
+    if ($item_id == 'global') {
34 34
         $is_global = true;
35 35
         $item_id = 0;
36 36
     }
37 37
     
38
-    $rate           = (float)wpinv_get_option( 'tax_rate', 0 );
39
-    $user_address   = wpinv_get_user_address( $wpi_userID );
38
+    $rate           = (float)wpinv_get_option('tax_rate', 0);
39
+    $user_address   = wpinv_get_user_address($wpi_userID);
40 40
     
41
-    if( empty( $country ) ) {
42
-        if( !empty( $_POST['wpinv_country'] ) ) {
41
+    if (empty($country)) {
42
+        if (!empty($_POST['wpinv_country'])) {
43 43
             $country = $_POST['wpinv_country'];
44
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
44
+        } elseif (!empty($_POST['wpinv_country'])) {
45 45
             $country = $_POST['wpinv_country'];
46
-        } elseif( !empty( $_POST['country'] ) ) {
46
+        } elseif (!empty($_POST['country'])) {
47 47
             $country = $_POST['country'];
48
-        } elseif( is_user_logged_in() && !empty( $user_address ) ) {
48
+        } elseif (is_user_logged_in() && !empty($user_address)) {
49 49
             $country = $user_address['country'];
50 50
         }
51
-        $country = !empty( $country ) ? $country : wpinv_get_default_country();
51
+        $country = !empty($country) ? $country : wpinv_get_default_country();
52 52
     }
53 53
 
54
-    if( empty( $state ) ) {
55
-        if( !empty( $_POST['wpinv_state'] ) ) {
54
+    if (empty($state)) {
55
+        if (!empty($_POST['wpinv_state'])) {
56 56
             $state = $_POST['wpinv_state'];
57
-        } elseif( !empty( $_POST['wpinv_state'] ) ) {
57
+        } elseif (!empty($_POST['wpinv_state'])) {
58 58
             $state = $_POST['wpinv_state'];
59
-        } elseif( !empty( $_POST['state'] ) ) {
59
+        } elseif (!empty($_POST['state'])) {
60 60
             $state = $_POST['state'];
61
-        } elseif( is_user_logged_in() && !empty( $user_address ) ) {
61
+        } elseif (is_user_logged_in() && !empty($user_address)) {
62 62
             $state = $user_address['state'];
63 63
         }
64
-        $state = !empty( $state ) ? $state : wpinv_get_default_state();
64
+        $state = !empty($state) ? $state : wpinv_get_default_state();
65 65
     }
66 66
     
67
-    if( !empty( $country ) ) {
68
-        $tax_rates   = wpinv_get_tax_rates();
67
+    if (!empty($country)) {
68
+        $tax_rates = wpinv_get_tax_rates();
69 69
 
70
-        if( !empty( $tax_rates ) ) {
70
+        if (!empty($tax_rates)) {
71 71
             // Locate the tax rate for this country / state, if it exists
72
-            foreach( $tax_rates as $key => $tax_rate ) {
73
-                if( $country != $tax_rate['country'] )
72
+            foreach ($tax_rates as $key => $tax_rate) {
73
+                if ($country != $tax_rate['country'])
74 74
                     continue;
75 75
 
76
-                if( !empty( $tax_rate['global'] ) ) {
77
-                    if( !empty( $tax_rate['rate'] ) ) {
78
-                        $rate = number_format( $tax_rate['rate'], 4 );
76
+                if (!empty($tax_rate['global'])) {
77
+                    if (!empty($tax_rate['rate'])) {
78
+                        $rate = number_format($tax_rate['rate'], 4);
79 79
                     }
80 80
                 } else {
81 81
 
82
-                    if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
82
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
83 83
                         continue;
84 84
 
85 85
                     $state_rate = $tax_rate['rate'];
86
-                    if( 0 !== $state_rate || !empty( $state_rate ) ) {
87
-                        $rate = number_format( $state_rate, 4 );
86
+                    if (0 !== $state_rate || !empty($state_rate)) {
87
+                        $rate = number_format($state_rate, 4);
88 88
                     }
89 89
                 }
90 90
             }
91 91
         }
92 92
     }
93 93
     
94
-    $rate = apply_filters( 'wpinv_tax_rate', $rate, $country, $state, $item_id );
94
+    $rate = apply_filters('wpinv_tax_rate', $rate, $country, $state, $item_id);
95 95
     
96
-    if ( !empty( $item_id ) ) {
96
+    if (!empty($item_id)) {
97 97
         $wpi_tax_rates[$item_id] = $rate;
98
-    } else if ( $is_global ) {
98
+    } else if ($is_global) {
99 99
         $wpi_tax_rates['global'] = $rate;
100 100
     }
101 101
     
102 102
     return $rate;
103 103
 }
104 104
 
105
-function wpinv_get_formatted_tax_rate( $country = false, $state = false, $item_id ) {
106
-    $rate = wpinv_get_tax_rate( $country, $state, $item_id );
107
-    $rate = round( $rate, 4 );
105
+function wpinv_get_formatted_tax_rate($country = false, $state = false, $item_id) {
106
+    $rate = wpinv_get_tax_rate($country, $state, $item_id);
107
+    $rate = round($rate, 4);
108 108
     $formatted = $rate .= '%';
109
-    return apply_filters( 'wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id );
109
+    return apply_filters('wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id);
110 110
 }
111 111
 
112
-function wpinv_calculate_tax( $amount = 0, $country = false, $state = false, $item_id = 0 ) {
113
-    $rate = wpinv_get_tax_rate( $country, $state, $item_id );
112
+function wpinv_calculate_tax($amount = 0, $country = false, $state = false, $item_id = 0) {
113
+    $rate = wpinv_get_tax_rate($country, $state, $item_id);
114 114
     $tax  = 0.00;
115 115
 
116
-    if ( wpinv_use_taxes() ) {        
117
-        if ( wpinv_prices_include_tax() ) {
118
-            $pre_tax = ( $amount / ( ( 1 + $rate ) * 0.01 ) );
116
+    if (wpinv_use_taxes()) {        
117
+        if (wpinv_prices_include_tax()) {
118
+            $pre_tax = ($amount / ((1 + $rate) * 0.01));
119 119
             $tax     = $amount - $pre_tax;
120 120
         } else {
121 121
             $tax = $amount * $rate * 0.01;
@@ -123,46 +123,46 @@  discard block
 block discarded – undo
123 123
 
124 124
     }
125 125
 
126
-    return apply_filters( 'wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id );
126
+    return apply_filters('wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id);
127 127
 }
128 128
 
129 129
 function wpinv_prices_include_tax() {
130 130
     return false; // TODO
131
-    $ret = ( wpinv_get_option( 'prices_include_tax', false ) == 'yes' && wpinv_use_taxes() );
131
+    $ret = (wpinv_get_option('prices_include_tax', false) == 'yes' && wpinv_use_taxes());
132 132
 
133
-    return apply_filters( 'wpinv_prices_include_tax', $ret );
133
+    return apply_filters('wpinv_prices_include_tax', $ret);
134 134
 }
135 135
 
136
-function wpinv_sales_tax_for_year( $year = null ) {
137
-    return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) );
136
+function wpinv_sales_tax_for_year($year = null) {
137
+    return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year)));
138 138
 }
139 139
 
140
-function wpinv_get_sales_tax_for_year( $year = null ) {
140
+function wpinv_get_sales_tax_for_year($year = null) {
141 141
     global $wpdb;
142 142
 
143 143
     // Start at zero
144 144
     $tax = 0;
145 145
 
146
-    if ( ! empty( $year ) ) {
146
+    if (!empty($year)) {
147 147
         $args = array(
148 148
             'post_type'      => 'wpi_invoice',
149
-            'post_status'    => array( 'publish' ),
149
+            'post_status'    => array('publish'),
150 150
             'posts_per_page' => -1,
151 151
             'year'           => $year,
152 152
             'fields'         => 'ids'
153 153
         );
154 154
 
155
-        $payments    = get_posts( $args );
156
-        $payment_ids = implode( ',', $payments );
155
+        $payments    = get_posts($args);
156
+        $payment_ids = implode(',', $payments);
157 157
 
158
-        if ( count( $payments ) > 0 ) {
158
+        if (count($payments) > 0) {
159 159
             $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )";
160
-            $tax = $wpdb->get_var( $sql );
160
+            $tax = $wpdb->get_var($sql);
161 161
         }
162 162
 
163 163
     }
164 164
 
165
-    return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year );
165
+    return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year);
166 166
 }
167 167
 
168 168
 function wpinv_is_cart_taxed() {
@@ -171,33 +171,33 @@  discard block
 block discarded – undo
171 171
 
172 172
 function wpinv_prices_show_tax_on_checkout() {
173 173
     return false; // TODO
174
-    $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() );
174
+    $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes());
175 175
 
176
-    return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret );
176
+    return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret);
177 177
 }
178 178
 
179 179
 function wpinv_display_tax_rate() {
180
-    $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false );
180
+    $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false);
181 181
 
182
-    return apply_filters( 'wpinv_display_tax_rate', $ret );
182
+    return apply_filters('wpinv_display_tax_rate', $ret);
183 183
 }
184 184
 
185 185
 function wpinv_cart_needs_tax_address_fields() {
186
-    if( !wpinv_is_cart_taxed() )
186
+    if (!wpinv_is_cart_taxed())
187 187
         return false;
188 188
 
189
-    return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' );
189
+    return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields');
190 190
 }
191 191
 
192
-function wpinv_item_is_tax_exclusive( $item_id = 0 ) {
193
-    $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false );
194
-    return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id );
192
+function wpinv_item_is_tax_exclusive($item_id = 0) {
193
+    $ret = (bool)get_post_meta($item_id, '_wpinv_tax_exclusive', false);
194
+    return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id);
195 195
 }
196 196
 
197
-function wpinv_currency_decimal_filter( $decimals = 2 ) {
197
+function wpinv_currency_decimal_filter($decimals = 2) {
198 198
     $currency = wpinv_get_currency();
199 199
 
200
-    switch ( $currency ) {
200
+    switch ($currency) {
201 201
         case 'RIAL' :
202 202
         case 'JPY' :
203 203
         case 'TWD' :
@@ -206,48 +206,48 @@  discard block
 block discarded – undo
206 206
             break;
207 207
     }
208 208
 
209
-    return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency );
209
+    return apply_filters('wpinv_currency_decimal_count', $decimals, $currency);
210 210
 }
211 211
 
212 212
 function wpinv_tax_amount() {
213 213
     $output = 0.00;
214 214
     
215
-    return apply_filters( 'wpinv_tax_amount', $output );
215
+    return apply_filters('wpinv_tax_amount', $output);
216 216
 }
217 217
 
218 218
 function wpinv_recalculated_tax() {
219
-    define( 'WPINV_RECALCTAX', true );
219
+    define('WPINV_RECALCTAX', true);
220 220
 }
221
-add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1 );
221
+add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1);
222 222
 
223
-function wpinv_recalculate_tax( $return = false ) {
223
+function wpinv_recalculate_tax($return = false) {
224 224
     $invoice_id = (int)wpinv_get_invoice_cart_id();
225
-    if ( empty( $invoice_id ) ) {
225
+    if (empty($invoice_id)) {
226 226
         return false;
227 227
     }
228 228
     
229
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
229
+    $invoice = wpinv_get_invoice_cart($invoice_id);
230 230
 
231
-    if ( empty( $invoice ) ) {
231
+    if (empty($invoice)) {
232 232
         return false;
233 233
     }
234 234
 
235
-    if ( empty( $_POST['country'] ) ) {
235
+    if (empty($_POST['country'])) {
236 236
         $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
237 237
     }
238 238
         
239 239
     $invoice->country = sanitize_text_field($_POST['country']);
240
-    $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
240
+    $invoice->set('country', sanitize_text_field($_POST['country']));
241 241
     if (isset($_POST['state'])) {
242 242
         $invoice->state = sanitize_text_field($_POST['state']);
243
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
243
+        $invoice->set('state', sanitize_text_field($_POST['state']));
244 244
     }
245 245
 
246 246
     $invoice->cart_details  = wpinv_get_cart_content_details();
247 247
     
248
-    $subtotal               = wpinv_get_cart_subtotal( $invoice->cart_details );
249
-    $tax                    = wpinv_get_cart_tax( $invoice->cart_details );
250
-    $total                  = wpinv_get_cart_total( $invoice->cart_details );
248
+    $subtotal               = wpinv_get_cart_subtotal($invoice->cart_details);
249
+    $tax                    = wpinv_get_cart_tax($invoice->cart_details);
250
+    $total                  = wpinv_get_cart_total($invoice->cart_details);
251 251
 
252 252
     $invoice->tax           = $tax;
253 253
     $invoice->subtotal      = $subtotal;
@@ -255,61 +255,61 @@  discard block
 block discarded – undo
255 255
 
256 256
     $invoice->save();
257 257
     
258
-    if ( $invoice->is_free_trial() ) {
258
+    if ($invoice->is_free_trial()) {
259 259
         $total = 0;
260 260
     }
261 261
     
262 262
     $response = array(
263
-        'total'        => html_entity_decode( wpinv_price( wpinv_format_amount( $total ) ), ENT_COMPAT, 'UTF-8' ),
263
+        'total'        => html_entity_decode(wpinv_price(wpinv_format_amount($total)), ENT_COMPAT, 'UTF-8'),
264 264
         'total_raw'    => $total,
265
-        'free'         => !( (float)$total > 0 ) && $invoice->is_free() ? true : false,
266
-        'html'         => wpinv_checkout_cart( $invoice->cart_details, false ),
265
+        'free'         => !((float)$total > 0) && $invoice->is_free() ? true : false,
266
+        'html'         => wpinv_checkout_cart($invoice->cart_details, false),
267 267
     );
268 268
     
269
-    if ( $return ) {
269
+    if ($return) {
270 270
         return $response;
271 271
     }
272 272
 
273
-    wp_send_json( $response );
273
+    wp_send_json($response);
274 274
 }
275
-add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax' );
276
-add_action( 'wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax' );
275
+add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax');
276
+add_action('wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax');
277 277
 
278 278
 // VAT Settings
279
-function wpinv_vat_rate_add_callback( $args ) {
279
+function wpinv_vat_rate_add_callback($args) {
280 280
     ?>
281
-    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e( 'Add', 'invoicing' );?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
281
+    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
282 282
     <?php
283 283
 }
284 284
 
285
-function wpinv_vat_rate_delete_callback( $args ) {
285
+function wpinv_vat_rate_delete_callback($args) {
286 286
     global $wpinv_euvat;
287 287
     
288 288
     $vat_classes = $wpinv_euvat->get_rate_classes();
289
-    $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '';
290
-    if ( isset( $vat_classes[$vat_class] ) ) {
289
+    $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '';
290
+    if (isset($vat_classes[$vat_class])) {
291 291
     ?>
292
-    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf( esc_attr__( 'Delete class "%s"', 'invoicing' ), $vat_classes[$vat_class] );?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
292
+    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf(esc_attr__('Delete class "%s"', 'invoicing'), $vat_classes[$vat_class]); ?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
293 293
     <?php
294 294
     }
295 295
 }
296 296
 
297
-function wpinv_vat_rates_callback( $args ) {
297
+function wpinv_vat_rates_callback($args) {
298 298
     global $wpinv_euvat;
299 299
     
300 300
     $vat_classes    = $wpinv_euvat->get_rate_classes();
301
-    $vat_class      = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard';
301
+    $vat_class      = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard';
302 302
     
303 303
     $eu_states      = $wpinv_euvat->get_eu_states();
304 304
     $countries      = wpinv_get_country_list();
305 305
     $vat_groups     = $wpinv_euvat->get_vat_groups();
306
-    $rates          = $wpinv_euvat->get_vat_rates( $vat_class );
306
+    $rates          = $wpinv_euvat->get_vat_rates($vat_class);
307 307
     ob_start();
308 308
 ?>
309 309
 </td><tr>
310 310
     <td colspan="2" class="wpinv_vat_tdbox">
311
-    <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" />
312
-    <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p>
311
+    <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" />
312
+    <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p>
313 313
     <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts">
314 314
         <colgroup>
315 315
             <col width="50px" />
@@ -321,43 +321,43 @@  discard block
 block discarded – undo
321 321
         </colgroup>
322 322
         <thead>
323 323
             <tr>
324
-                <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th>
325
-                <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th>
326
-                <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> 
327
-                <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th>
328
-                <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th>
324
+                <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th>
325
+                <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th>
326
+                <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> 
327
+                <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th>
328
+                <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th>
329 329
             </tr>
330 330
         </thead>
331 331
         <tbody>
332
-        <?php if( !empty( $eu_states ) ) { ?>
332
+        <?php if (!empty($eu_states)) { ?>
333 333
         <?php 
334
-        foreach ( $eu_states as $state ) { 
335
-            $country_name = isset( $countries[$state] ) ? $countries[$state] : '';
334
+        foreach ($eu_states as $state) { 
335
+            $country_name = isset($countries[$state]) ? $countries[$state] : '';
336 336
             
337 337
             // Filter the rate for each country
338
-            $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } );
338
+            $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } );
339 339
             
340 340
             // If one does not exist create a default
341
-            $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array();
341
+            $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array();
342 342
             
343
-            $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true;
344
-            $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : '';
345
-            $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : '';
346
-            $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' );
343
+            $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true;
344
+            $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : '';
345
+            $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : '';
346
+            $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced');
347 347
         ?>
348 348
         <tr>
349 349
             <td class="wpinv_vat_country"><?php echo $state; ?><input type="hidden" name="vat_rates[<?php echo $state; ?>][country]" value="<?php echo $state; ?>" /><input type="hidden" name="vat_rates[<?php echo $state; ?>][state]" value="" /></td>
350 350
             <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td>
351 351
             <td class="wpinv_vat_global">
352
-                <input type="checkbox" name="vat_rates[<?php echo $state;?>][global]" id="vat_rates[<?php echo $state;?>][global]" value="1" <?php checked( true, $vat_global );?> disabled="disabled" />
353
-                <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
354
-                <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" />
352
+                <input type="checkbox" name="vat_rates[<?php echo $state; ?>][global]" id="vat_rates[<?php echo $state; ?>][global]" value="1" <?php checked(true, $vat_global); ?> disabled="disabled" />
353
+                <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
354
+                <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" />
355 355
             </td>
356
-            <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state;?>][rate]" value="<?php echo $vat_rate; ?>" /></td>
357
-            <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td>
356
+            <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state; ?>][rate]" value="<?php echo $vat_rate; ?>" /></td>
357
+            <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td>
358 358
             <td class="wpinv_vat_group">
359 359
             <?php
360
-            echo wpinv_html_select( array(
360
+            echo wpinv_html_select(array(
361 361
                                         'name'             => 'vat_rates[' . $state . '][group]',
362 362
                                         'selected'         => $vat_group,
363 363
                                         'id'               => 'vat_rates[' . $state . '][group]',
@@ -367,14 +367,14 @@  discard block
 block discarded – undo
367 367
                                         'chosen'           => false,
368 368
                                         'show_option_all'  => false,
369 369
                                         'show_option_none' => false
370
-                                    ) );
370
+                                    ));
371 371
             ?>
372 372
             </td>
373 373
         </tr>
374 374
         <?php } ?>
375 375
         <tr>
376 376
             <td colspan="6" style="background-color:#fafafa;">
377
-                <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e( 'Update EU VAT Rates', 'invoicing' ); ?>" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span>
377
+                <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e('Update EU VAT Rates', 'invoicing'); ?>" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span>
378 378
             </td>
379 379
         </tr>
380 380
         <?php } ?>
@@ -386,35 +386,35 @@  discard block
 block discarded – undo
386 386
     echo $content;
387 387
 }
388 388
 
389
-function wpinv_vat_number_callback( $args ) {
389
+function wpinv_vat_number_callback($args) {
390 390
     global $wpinv_euvat;
391 391
     
392 392
     $vat_number     = $wpinv_euvat->get_vat_number();
393 393
     $vat_valid      = $wpinv_euvat->is_vat_validated();
394 394
 
395
-    $size           = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular';
396
-    $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' );
395
+    $size           = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
396
+    $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing');
397 397
     $disabled       = $vat_valid ? 'disabled="disabled"' : " ";
398 398
     
399
-    $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr( stripslashes( $vat_number ) ) . '"/>';
400
-    $html .= '<span>&nbsp;<input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__( 'Validate VAT Number', 'invoicing' ) . '" /></span>';
399
+    $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr(stripslashes($vat_number)) . '"/>';
400
+    $html .= '<span>&nbsp;<input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__('Validate VAT Number', 'invoicing') . '" /></span>';
401 401
     $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>';
402
-    $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __( 'Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing' ).'</p>' . '</label>';
403
-    $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">';
402
+    $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __('Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing') . '</p>' . '</label>';
403
+    $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">';
404 404
 
405 405
     echo $html;
406 406
 }
407 407
 
408
-function wpinv_eu_fallback_rate_callback( $args ) {
408
+function wpinv_eu_fallback_rate_callback($args) {
409 409
     global $wpinv_options;
410 410
 
411
-    $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' );
412
-    $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small';
411
+    $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : '');
412
+    $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small';
413 413
     
414
-    $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '" />';
415
-    $html .= '<span>&nbsp;<input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>';
416
-    $html .= '<span>&nbsp;<input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>';
417
-    $html .= '<span>&nbsp;<input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__( 'Update EU VAT Rates', 'invoicing' ) . '" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span>';
414
+    $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '" />';
415
+    $html .= '<span>&nbsp;<input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>';
416
+    $html .= '<span>&nbsp;<input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>';
417
+    $html .= '<span>&nbsp;<input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__('Update EU VAT Rates', 'invoicing') . '" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span>';
418 418
     $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>';
419 419
     echo $html;
420 420
     ?>
@@ -422,36 +422,36 @@  discard block
 block discarded – undo
422 422
     <?php
423 423
 }
424 424
 
425
-function wpinv_vat_ip_lookup_callback( $args ) {
425
+function wpinv_vat_ip_lookup_callback($args) {
426 426
     global $wpinv_options, $wpinv_euvat;
427 427
 
428
-    $value =  isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ]  : ( isset( $args['std'] ) ? $args['std'] : 'default' );
428
+    $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : 'default');
429 429
     
430 430
     $options = array();
431
-    if ( function_exists( 'geoip_country_code_by_name' ) ) {
432
-        $options['geoip'] = __( 'PHP GeoIP extension', 'invoicing' );
431
+    if (function_exists('geoip_country_code_by_name')) {
432
+        $options['geoip'] = __('PHP GeoIP extension', 'invoicing');
433 433
     }
434 434
     
435 435
     $geoip2_database = $wpinv_euvat->geoip2_country_dbfile();
436 436
     
437
-    if ( !function_exists( 'bcadd' ) ) {
438
-        $geoip2_message = __( 'GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing' );
437
+    if (!function_exists('bcadd')) {
438
+        $geoip2_message = __('GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing');
439 439
     } else {
440
-        $geoip2_message = ini_get('safe_mode') ? __( 'GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing' ) : '';
440
+        $geoip2_message = ini_get('safe_mode') ? __('GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing') : '';
441 441
     }
442 442
     
443
-    if ( $geoip2_database !== false && empty( $geoip2_message ) ) {
444
-        $options['geoip2'] = __( 'GeoIP2 Database', 'invoicing' );
443
+    if ($geoip2_database !== false && empty($geoip2_message)) {
444
+        $options['geoip2'] = __('GeoIP2 Database', 'invoicing');
445 445
     }
446 446
     
447
-    if ( function_exists( 'simplexml_load_file' ) ) {
448
-        $options['geoplugin'] = __( 'geoPlugin Web Service', 'invoicing' );
447
+    if (function_exists('simplexml_load_file')) {
448
+        $options['geoplugin'] = __('geoPlugin Web Service', 'invoicing');
449 449
     }
450 450
     
451
-    $options['site']    = __( 'Use default country', 'invoicing' );
452
-    $options['default'] = __( 'Auto', 'invoicing' );
451
+    $options['site']    = __('Use default country', 'invoicing');
452
+    $options['default'] = __('Auto', 'invoicing');
453 453
 
454
-    $html = wpinv_html_select( array(
454
+    $html = wpinv_html_select(array(
455 455
         'name'             => "wpinv_settings[{$args['id']}]",
456 456
         'selected'         => $value,
457 457
         'id'               => "wpinv_settings[{$args['id']}]",
@@ -464,23 +464,23 @@  discard block
 block discarded – undo
464 464
     ));
465 465
     
466 466
     $desc = '<label for="wpinv_settings[' . $args['id'] . ']">';
467
-    $desc .= __( 'Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing' );
467
+    $desc .= __('Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing');
468 468
     $desc .= '<p>';
469
-    if ( empty( $geoip2_message ) ) {
470
-        if ( $geoip2_database ) {
469
+    if (empty($geoip2_message)) {
470
+        if ($geoip2_database) {
471 471
             $last_updated = '';
472
-            if ( $time_updated = wpinv_get_option( 'wpinv_geoip2_date_updated' ) ) {
473
-                $date_updated = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time_updated );
474
-                $last_updated = '<br>' . sprintf( __( 'The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing' ), $date_updated );
472
+            if ($time_updated = wpinv_get_option('wpinv_geoip2_date_updated')) {
473
+                $date_updated = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time_updated);
474
+                $last_updated = '<br>' . sprintf(__('The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing'), $date_updated);
475 475
             }
476
-            $desc .= __(  'GeoIP2 database exists:', 'invoicing' ) . $last_updated . '&nbsp;<input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __( 'Update GeoIP2 database now (~55MB)', 'invoicing' ) . '"></input>';
476
+            $desc .= __('GeoIP2 database exists:', 'invoicing') . $last_updated . '&nbsp;<input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __('Update GeoIP2 database now (~55MB)', 'invoicing') . '"></input>';
477 477
         } else {
478
-            $desc .= __( 'GeoIP2 database does not exist:', 'invoicing' ) . '&nbsp;<input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __( 'Download GeoIP2 database now', 'invoicing' ) . ' (~53MB)"></input><br>' . __(  'After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing' );
478
+            $desc .= __('GeoIP2 database does not exist:', 'invoicing') . '&nbsp;<input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __('Download GeoIP2 database now', 'invoicing') . ' (~53MB)"></input><br>' . __('After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing');
479 479
         }
480 480
     } else {
481 481
         $desc .= $geoip2_message;
482 482
     }
483
-    $desc .= '</p><p>'. __( 'GeoPlugin is a great free service please consider supporting them: ', 'invoicing' ) . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>';
483
+    $desc .= '</p><p>' . __('GeoPlugin is a great free service please consider supporting them: ', 'invoicing') . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>';
484 484
     $desc .= '</label>';
485 485
     
486 486
     $html .= $desc;
Please login to merge, or discard this patch.
includes/wpinv-gateway-functions.php 1 patch
Spacing   +252 added lines, -252 removed lines patch added patch discarded remove patch
@@ -7,206 +7,206 @@  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
 function wpinv_get_payment_gateways() {
15 15
     // Default, built-in gateways
16 16
     $gateways = array(
17 17
         'paypal' => array(
18
-            'admin_label'    => __( 'PayPal Standard', 'invoicing' ),
19
-            'checkout_label' => __( 'PayPal Standard', 'invoicing' ),
18
+            'admin_label'    => __('PayPal Standard', 'invoicing'),
19
+            'checkout_label' => __('PayPal Standard', 'invoicing'),
20 20
             'ordering'       => 1,
21 21
         ),
22 22
         'authorizenet' => array(
23
-            'admin_label'    => __( 'Authorize.Net (AIM)', 'invoicing' ),
24
-            'checkout_label' => __( 'Authorize.Net - Credit Card / Debit Card', 'invoicing' ),
23
+            'admin_label'    => __('Authorize.Net (AIM)', 'invoicing'),
24
+            'checkout_label' => __('Authorize.Net - Credit Card / Debit Card', 'invoicing'),
25 25
             'ordering'       => 4,
26 26
         ),
27 27
         'worldpay' => array(
28
-            'admin_label'    => __( 'Worldpay', 'invoicing' ),
29
-            'checkout_label' => __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ),
28
+            'admin_label'    => __('Worldpay', 'invoicing'),
29
+            'checkout_label' => __('Worldpay - Credit Card / Debit Card', 'invoicing'),
30 30
             'ordering'       => 5,
31 31
         ),
32 32
         'bank_transfer' => array(
33
-            'admin_label'    => __( 'Pre Bank Transfer', 'invoicing' ),
34
-            'checkout_label' => __( 'Pre Bank Transfer', 'invoicing' ),
33
+            'admin_label'    => __('Pre Bank Transfer', 'invoicing'),
34
+            'checkout_label' => __('Pre Bank Transfer', 'invoicing'),
35 35
             'ordering'       => 11,
36 36
         ),
37 37
         'manual' => array(
38
-            'admin_label'    => __( 'Test Payment', 'invoicing' ),
39
-            'checkout_label' => __( 'Test Payment', 'invoicing' ),
38
+            'admin_label'    => __('Test Payment', 'invoicing'),
39
+            'checkout_label' => __('Test Payment', 'invoicing'),
40 40
             'ordering'       => 12,
41 41
         ),
42 42
     );
43 43
 
44
-    return apply_filters( 'wpinv_payment_gateways', $gateways );
44
+    return apply_filters('wpinv_payment_gateways', $gateways);
45 45
 }
46 46
 
47
-function wpinv_payment_gateway_titles( $all_gateways ) {
47
+function wpinv_payment_gateway_titles($all_gateways) {
48 48
     global $wpinv_options;
49 49
     
50 50
     $gateways = array();
51
-    foreach ( $all_gateways as $key => $gateway ) {
52
-        if ( !empty( $wpinv_options[$key . '_title'] ) ) {
53
-            $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' );
51
+    foreach ($all_gateways as $key => $gateway) {
52
+        if (!empty($wpinv_options[$key . '_title'])) {
53
+            $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing');
54 54
         }
55 55
         
56
-        $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' );
56
+        $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : '');
57 57
     }
58 58
 
59
-    asort( $gateways );
59
+    asort($gateways);
60 60
     
61
-    foreach ( $gateways as $gateway => $key ) {
61
+    foreach ($gateways as $gateway => $key) {
62 62
         $gateways[$gateway] = $all_gateways[$gateway];
63 63
     }
64 64
     
65 65
     return $gateways;
66 66
 }
67
-add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 );
67
+add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1);
68 68
 
69
-function wpinv_get_enabled_payment_gateways( $sort = false ) {
69
+function wpinv_get_enabled_payment_gateways($sort = false) {
70 70
     $gateways = wpinv_get_payment_gateways();
71
-    $enabled  = wpinv_get_option( 'gateways', false );
71
+    $enabled  = wpinv_get_option('gateways', false);
72 72
 
73 73
     $gateway_list = array();
74 74
 
75
-    foreach ( $gateways as $key => $gateway ) {
76
-        if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) {
77
-            $gateway_list[ $key ] = $gateway;
75
+    foreach ($gateways as $key => $gateway) {
76
+        if (isset($enabled[$key]) && $enabled[$key] == 1) {
77
+            $gateway_list[$key] = $gateway;
78 78
         }
79 79
     }
80 80
 
81
-    if ( true === $sort ) {
82
-        uasort( $gateway_list, 'wpinv_sort_gateway_order' );
81
+    if (true === $sort) {
82
+        uasort($gateway_list, 'wpinv_sort_gateway_order');
83 83
         
84 84
         // Reorder our gateways so the default is first
85 85
         $default_gateway_id = wpinv_get_default_gateway();
86 86
 
87
-        if ( wpinv_is_gateway_active( $default_gateway_id ) ) {
88
-            $default_gateway    = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] );
89
-            unset( $gateway_list[ $default_gateway_id ] );
87
+        if (wpinv_is_gateway_active($default_gateway_id)) {
88
+            $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]);
89
+            unset($gateway_list[$default_gateway_id]);
90 90
 
91
-            $gateway_list = array_merge( $default_gateway, $gateway_list );
91
+            $gateway_list = array_merge($default_gateway, $gateway_list);
92 92
         }
93 93
     }
94 94
 
95
-    return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list );
95
+    return apply_filters('wpinv_enabled_payment_gateways', $gateway_list);
96 96
 }
97 97
 
98
-function wpinv_sort_gateway_order( $a, $b ) {
98
+function wpinv_sort_gateway_order($a, $b) {
99 99
     return $a['ordering'] - $b['ordering'];
100 100
 }
101 101
 
102
-function wpinv_is_gateway_active( $gateway ) {
102
+function wpinv_is_gateway_active($gateway) {
103 103
     $gateways = wpinv_get_enabled_payment_gateways();
104 104
 
105
-    $ret = is_array($gateways) && $gateway ?  array_key_exists( $gateway, $gateways ) : false;
105
+    $ret = is_array($gateways) && $gateway ? array_key_exists($gateway, $gateways) : false;
106 106
 
107
-    return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways );
107
+    return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways);
108 108
 }
109 109
 
110 110
 function wpinv_get_default_gateway() {
111
-    $default = wpinv_get_option( 'default_gateway', 'paypal' );
111
+    $default = wpinv_get_option('default_gateway', 'paypal');
112 112
 
113
-    if ( !wpinv_is_gateway_active( $default ) ) {
113
+    if (!wpinv_is_gateway_active($default)) {
114 114
         $gateways = wpinv_get_enabled_payment_gateways();
115
-        $gateways = array_keys( $gateways );
116
-        $default  = reset( $gateways );
115
+        $gateways = array_keys($gateways);
116
+        $default  = reset($gateways);
117 117
     }
118 118
 
119
-    return apply_filters( 'wpinv_default_gateway', $default );
119
+    return apply_filters('wpinv_default_gateway', $default);
120 120
 }
121 121
 
122
-function wpinv_get_gateway_admin_label( $gateway ) {
122
+function wpinv_get_gateway_admin_label($gateway) {
123 123
     $gateways = wpinv_get_payment_gateways();
124
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway;
125
-    $payment  = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false;
124
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway;
125
+    $payment  = isset($_GET['id']) ? absint($_GET['id']) : false;
126 126
 
127
-    if( $gateway == 'manual' && $payment ) {
128
-        if( wpinv_get_payment_amount( $payment ) == 0 ) {
129
-            $label = __( 'Manual Payment', 'invoicing' );
127
+    if ($gateway == 'manual' && $payment) {
128
+        if (wpinv_get_payment_amount($payment) == 0) {
129
+            $label = __('Manual Payment', 'invoicing');
130 130
         }
131 131
     }
132 132
 
133
-    return apply_filters( 'wpinv_gateway_admin_label', $label, $gateway );
133
+    return apply_filters('wpinv_gateway_admin_label', $label, $gateway);
134 134
 }
135 135
 
136
-function wpinv_get_gateway_description( $gateway ) {
136
+function wpinv_get_gateway_description($gateway) {
137 137
     global $wpinv_options;
138 138
 
139
-    $description = isset( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : '';
139
+    $description = isset($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : '';
140 140
 
141
-    return apply_filters( 'wpinv_gateway_description', $description, $gateway );
141
+    return apply_filters('wpinv_gateway_description', $description, $gateway);
142 142
 }
143 143
 
144
-function wpinv_get_gateway_button_label( $gateway ) {
145
-    return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' );
144
+function wpinv_get_gateway_button_label($gateway) {
145
+    return apply_filters('wpinv_gateway_' . $gateway . '_button_label', '');
146 146
 }
147 147
 
148
-function wpinv_get_gateway_checkout_label( $gateway ) {
148
+function wpinv_get_gateway_checkout_label($gateway) {
149 149
     $gateways = wpinv_get_payment_gateways();
150
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway;
150
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway;
151 151
 
152
-    if( $gateway == 'manual' ) {
153
-        $label = __( 'Manual Payment', 'invoicing' );
152
+    if ($gateway == 'manual') {
153
+        $label = __('Manual Payment', 'invoicing');
154 154
     }
155 155
 
156
-    return apply_filters( 'wpinv_gateway_checkout_label', $label, $gateway );
156
+    return apply_filters('wpinv_gateway_checkout_label', $label, $gateway);
157 157
 }
158 158
 
159
-function wpinv_settings_sections_gateways( $settings ) {
159
+function wpinv_settings_sections_gateways($settings) {
160 160
     $gateways = wpinv_get_payment_gateways();
161 161
     
162 162
     if (!empty($gateways)) {
163
-        foreach  ($gateways as $key => $gateway) {
163
+        foreach ($gateways as $key => $gateway) {
164 164
             $settings[$key] = $gateway['admin_label'];
165 165
         }
166 166
     }
167 167
     
168 168
     return $settings;    
169 169
 }
170
-add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 );
170
+add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1);
171 171
 
172
-function wpinv_settings_gateways( $settings ) {
172
+function wpinv_settings_gateways($settings) {
173 173
     $gateways = wpinv_get_payment_gateways();
174 174
     
175 175
     if (!empty($gateways)) {
176
-        foreach  ($gateways as $key => $gateway) {
176
+        foreach ($gateways as $key => $gateway) {
177 177
             $setting = array();
178 178
             $setting[$key . '_header'] = array(
179 179
                     'id'   => 'gateway_header',
180
-                    'name' => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>',
180
+                    'name' => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>',
181 181
                     'custom' => $key,
182 182
                     'type' => 'gateway_header',
183 183
                 );
184 184
             $setting[$key . '_active'] = array(
185 185
                     'id'   => $key . '_active',
186
-                    'name' => __( 'Active', 'invoicing' ),
187
-                    'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ),
186
+                    'name' => __('Active', 'invoicing'),
187
+                    'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']),
188 188
                     'type' => 'checkbox',
189 189
                 );
190 190
                 
191 191
             $setting[$key . '_title'] = array(
192 192
                     'id'   => $key . '_title',
193
-                    'name' => __( 'Title', 'invoicing' ),
194
-                    'desc' => __( 'This controls the title which the user sees during checkout.', 'invoicing' ),
193
+                    'name' => __('Title', 'invoicing'),
194
+                    'desc' => __('This controls the title which the user sees during checkout.', 'invoicing'),
195 195
                     'type' => 'text',
196 196
                     'std' => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : ''
197 197
                 );
198 198
             
199 199
             $setting[$key . '_desc'] = array(
200 200
                     'id'   => $key . '_desc',
201
-                    'name' => __( 'Description', 'invoicing' ),
202
-                    'desc' => __( 'This controls the description which the user sees during checkout.', 'invoicing' ),
201
+                    'name' => __('Description', 'invoicing'),
202
+                    'desc' => __('This controls the description which the user sees during checkout.', 'invoicing'),
203 203
                     'type' => 'text',
204 204
                     'size' => 'large'
205 205
                 );
206 206
                 
207 207
             $setting[$key . '_ordering'] = array(
208 208
                     'id'   => $key . '_ordering',
209
-                    'name' => __( 'Display Order', 'invoicing' ),
209
+                    'name' => __('Display Order', 'invoicing'),
210 210
                     'type' => 'number',
211 211
                     'size' => 'small',
212 212
                     'std'  => isset($gateway['ordering']) ? $gateway['ordering'] : '10',
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
                     'step' => '1'
216 216
                 );
217 217
                 
218
-            $setting = apply_filters( 'wpinv_gateway_settings', $setting, $key );
219
-            $setting = apply_filters( 'wpinv_gateway_settings_' . $key, $setting );
218
+            $setting = apply_filters('wpinv_gateway_settings', $setting, $key);
219
+            $setting = apply_filters('wpinv_gateway_settings_' . $key, $setting);
220 220
             
221 221
             $settings[$key] = $setting;
222 222
         }
@@ -224,106 +224,106 @@  discard block
 block discarded – undo
224 224
     
225 225
     return $settings;    
226 226
 }
227
-add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 );
227
+add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1);
228 228
 
229
-function wpinv_gateway_header_callback( $args ) {
230
-    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />';
229
+function wpinv_gateway_header_callback($args) {
230
+    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />';
231 231
 }
232 232
 
233
-function wpinv_get_gateway_supports( $gateway ) {
233
+function wpinv_get_gateway_supports($gateway) {
234 234
     $gateways = wpinv_get_enabled_payment_gateways();
235
-    $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array();
236
-    return apply_filters( 'wpinv_gateway_supports', $supports, $gateway );
235
+    $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array();
236
+    return apply_filters('wpinv_gateway_supports', $supports, $gateway);
237 237
 }
238 238
 
239
-function wpinv_gateway_supports_buy_now( $gateway ) {
240
-    $supports = wpinv_get_gateway_supports( $gateway );
241
-    $ret = in_array( 'buy_now', $supports );
242
-    return apply_filters( 'wpinv_gateway_supports_buy_now', $ret, $gateway );
239
+function wpinv_gateway_supports_buy_now($gateway) {
240
+    $supports = wpinv_get_gateway_supports($gateway);
241
+    $ret = in_array('buy_now', $supports);
242
+    return apply_filters('wpinv_gateway_supports_buy_now', $ret, $gateway);
243 243
 }
244 244
 
245 245
 function wpinv_shop_supports_buy_now() {
246 246
     $gateways = wpinv_get_enabled_payment_gateways();
247 247
     $ret      = false;
248 248
 
249
-    if ( !wpinv_use_taxes()  && $gateways ) {
250
-        foreach ( $gateways as $gateway_id => $gateway ) {
251
-            if ( wpinv_gateway_supports_buy_now( $gateway_id ) ) {
249
+    if (!wpinv_use_taxes() && $gateways) {
250
+        foreach ($gateways as $gateway_id => $gateway) {
251
+            if (wpinv_gateway_supports_buy_now($gateway_id)) {
252 252
                 $ret = true;
253 253
                 break;
254 254
             }
255 255
         }
256 256
     }
257 257
 
258
-    return apply_filters( 'wpinv_shop_supports_buy_now', $ret );
258
+    return apply_filters('wpinv_shop_supports_buy_now', $ret);
259 259
 }
260 260
 
261
-function wpinv_send_to_gateway( $gateway, $payment_data ) {
262
-    $payment_data['gateway_nonce'] = wp_create_nonce( 'wpi-gateway' );
261
+function wpinv_send_to_gateway($gateway, $payment_data) {
262
+    $payment_data['gateway_nonce'] = wp_create_nonce('wpi-gateway');
263 263
 
264 264
     // $gateway must match the ID used when registering the gateway
265
-    do_action( 'wpinv_gateway_' . $gateway, $payment_data );
265
+    do_action('wpinv_gateway_' . $gateway, $payment_data);
266 266
 }
267 267
 
268 268
 function wpinv_show_gateways() {
269 269
     $gateways = wpinv_get_enabled_payment_gateways();
270 270
     $show_gateways = false;
271 271
 
272
-    $chosen_gateway = isset( $_GET['payment-mode'] ) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode'] ) : false;
272
+    $chosen_gateway = isset($_GET['payment-mode']) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode']) : false;
273 273
 
274
-    if ( count( $gateways ) > 1 && empty( $chosen_gateway ) ) {
274
+    if (count($gateways) > 1 && empty($chosen_gateway)) {
275 275
         $show_gateways = true;
276
-        if ( wpinv_get_cart_total() <= 0 ) {
276
+        if (wpinv_get_cart_total() <= 0) {
277 277
             $show_gateways = false;
278 278
         }
279 279
     }
280 280
     
281
-    if ( !$show_gateways && wpinv_cart_has_recurring_item() ) {
281
+    if (!$show_gateways && wpinv_cart_has_recurring_item()) {
282 282
         $show_gateways = true;
283 283
     }
284 284
 
285
-    return apply_filters( 'wpinv_show_gateways', $show_gateways );
285
+    return apply_filters('wpinv_show_gateways', $show_gateways);
286 286
 }
287 287
 
288
-function wpinv_get_chosen_gateway( $invoice_id = 0 ) {
289
-	$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
288
+function wpinv_get_chosen_gateway($invoice_id = 0) {
289
+	$gateways = array_keys(wpinv_get_enabled_payment_gateways());
290 290
 
291 291
     $chosen = false;
292
-    if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) {
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 );
298
+	if (false !== $chosen) {
299
+		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen);
300 300
 	}
301 301
 
302
-	if ( ! empty ( $chosen ) ) {
303
-		$enabled_gateway = urldecode( $chosen );
304
-	} else if (  !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) {
302
+	if (!empty ($chosen)) {
303
+		$enabled_gateway = urldecode($chosen);
304
+	} else if (!empty($invoice) && (float)$invoice->get_subtotal() <= 0) {
305 305
 		$enabled_gateway = 'manual';
306 306
 	} else {
307 307
 		$enabled_gateway = wpinv_get_default_gateway();
308 308
 	}
309 309
     
310
-    if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) {
311
-        if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){
310
+    if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) {
311
+        if (wpinv_is_gateway_active(wpinv_get_default_gateway())) {
312 312
             $enabled_gateway = wpinv_get_default_gateway();
313
-        }else{
313
+        } else {
314 314
             $enabled_gateway = $gateways[0];
315 315
         }
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
-function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) {
323
-    return wpinv_error_log( $message, $title );
322
+function wpinv_record_gateway_error($title = '', $message = '', $parent = 0) {
323
+    return wpinv_error_log($message, $title);
324 324
 }
325 325
 
326
-function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) {
326
+function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') {
327 327
 	$ret  = 0;
328 328
 	$args = array(
329 329
 		'meta_key'    => '_wpinv_gateway',
@@ -334,48 +334,48 @@  discard block
 block discarded – undo
334 334
 		'fields'      => 'ids'
335 335
 	);
336 336
 
337
-	$payments = new WP_Query( $args );
337
+	$payments = new WP_Query($args);
338 338
 
339
-	if( $payments )
339
+	if ($payments)
340 340
 		$ret = $payments->post_count;
341 341
 	return $ret;
342 342
 }
343 343
 
344
-function wpinv_settings_update_gateways( $input ) {
344
+function wpinv_settings_update_gateways($input) {
345 345
     global $wpinv_options;
346 346
     
347
-    if ( !empty( $input['save_gateway'] ) ) {
348
-        $gateways = wpinv_get_option( 'gateways', false );
347
+    if (!empty($input['save_gateway'])) {
348
+        $gateways = wpinv_get_option('gateways', false);
349 349
         $gateways = !empty($gateways) ? $gateways : array();
350 350
         $gateway = $input['save_gateway'];
351 351
         
352
-        if ( !empty( $input[$gateway . '_active'] ) ) {
352
+        if (!empty($input[$gateway . '_active'])) {
353 353
             $gateways[$gateway] = 1;
354 354
         } else {
355
-            if ( isset( $gateways[$gateway] ) ) {
356
-                unset( $gateways[$gateway] );
355
+            if (isset($gateways[$gateway])) {
356
+                unset($gateways[$gateway]);
357 357
             }
358 358
         }
359 359
         
360 360
         $input['gateways'] = $gateways;
361 361
     }
362 362
     
363
-    if ( !empty( $input['default_gateway'] ) ) {
363
+    if (!empty($input['default_gateway'])) {
364 364
         $gateways = wpinv_get_payment_gateways();
365 365
         
366
-        foreach ( $gateways as $key => $gateway ) {
367
-            $active   = 0;
368
-            if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) {
366
+        foreach ($gateways as $key => $gateway) {
367
+            $active = 0;
368
+            if (!empty($input['gateways']) && !empty($input['gateways'][$key])) {
369 369
                 $active = 1;
370 370
             }
371 371
             
372 372
             $input[$key . '_active'] = $active;
373 373
             
374
-            if ( empty( $wpinv_options[$key . '_title'] ) ) {
374
+            if (empty($wpinv_options[$key . '_title'])) {
375 375
                 $input[$key . '_title'] = $gateway['checkout_label'];
376 376
             }
377 377
             
378
-            if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) {
378
+            if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) {
379 379
                 $input[$key . '_ordering'] = $gateway['ordering'];
380 380
             }
381 381
         }
@@ -383,26 +383,26 @@  discard block
 block discarded – undo
383 383
     
384 384
     return $input;
385 385
 }
386
-add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 );
386
+add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1);
387 387
 
388 388
 // PayPal Standard settings
389
-function wpinv_gateway_settings_paypal( $setting ) {    
390
-    $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
389
+function wpinv_gateway_settings_paypal($setting) {    
390
+    $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
391 391
     
392 392
     $setting['paypal_sandbox'] = array(
393 393
             'type' => 'checkbox',
394 394
             'id'   => 'paypal_sandbox',
395
-            'name' => __( 'PayPal Sandbox', 'invoicing' ),
396
-            'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ),
395
+            'name' => __('PayPal Sandbox', 'invoicing'),
396
+            'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'),
397 397
             'std'  => 1
398 398
         );
399 399
         
400 400
     $setting['paypal_email'] = array(
401 401
             'type' => 'text',
402 402
             'id'   => 'paypal_email',
403
-            'name' => __( 'PayPal Email', 'invoicing' ),
404
-            'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ),
405
-            'std' => __( '[email protected]', 'invoicing' ),
403
+            'name' => __('PayPal Email', 'invoicing'),
404
+            'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'),
405
+            'std' => __('[email protected]', 'invoicing'),
406 406
         );
407 407
     /*
408 408
     $setting['paypal_ipn_url'] = array(
@@ -416,116 +416,116 @@  discard block
 block discarded – undo
416 416
         
417 417
     return $setting;
418 418
 }
419
-add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 );
419
+add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1);
420 420
 
421 421
 // Pre Bank Transfer settings
422
-function wpinv_gateway_settings_bank_transfer( $setting ) {
423
-    $setting['bank_transfer_desc']['std'] = __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' );
422
+function wpinv_gateway_settings_bank_transfer($setting) {
423
+    $setting['bank_transfer_desc']['std'] = __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing');
424 424
     
425 425
     $setting['bank_transfer_ac_name'] = array(
426 426
             'type' => 'text',
427 427
             'id' => 'bank_transfer_ac_name',
428
-            'name' => __( 'Account Name', 'invoicing' ),
429
-            'desc' => __( 'Enter the bank account name to which you want to transfer payment.', 'invoicing' ),
430
-            'std'  =>  __( 'Mr. John Martin', 'invoicing' ),
428
+            'name' => __('Account Name', 'invoicing'),
429
+            'desc' => __('Enter the bank account name to which you want to transfer payment.', 'invoicing'),
430
+            'std'  =>  __('Mr. John Martin', 'invoicing'),
431 431
         );
432 432
     
433 433
     $setting['bank_transfer_ac_no'] = array(
434 434
             'type' => 'text',
435 435
             'id' => 'bank_transfer_ac_no',
436
-            'name' => __( 'Account Number', 'invoicing' ),
437
-            'desc' => __( 'Enter your bank account number.', 'invoicing' ),
438
-            'std'  =>  __( 'TEST1234567890', 'invoicing' ),
436
+            'name' => __('Account Number', 'invoicing'),
437
+            'desc' => __('Enter your bank account number.', 'invoicing'),
438
+            'std'  =>  __('TEST1234567890', 'invoicing'),
439 439
         );
440 440
     
441 441
     $setting['bank_transfer_bank_name'] = array(
442 442
             'type' => 'text',
443 443
             'id'   => 'bank_transfer_bank_name',
444
-            'name' => __( 'Bank Name', 'invoicing' ),
445
-            'desc' => __( 'Enter the bank name to which you want to transfer payment.', 'invoicing' ),
446
-            'std' => __( 'ICICI Bank', 'invoicing' ),
444
+            'name' => __('Bank Name', 'invoicing'),
445
+            'desc' => __('Enter the bank name to which you want to transfer payment.', 'invoicing'),
446
+            'std' => __('ICICI Bank', 'invoicing'),
447 447
         );
448 448
     
449 449
     $setting['bank_transfer_ifsc'] = array(
450 450
             'type' => 'text',
451 451
             'id'   => 'bank_transfer_ifsc',
452
-            'name' => __( 'IFSC code', 'invoicing' ),
453
-            'desc' => __( 'Enter your bank IFSC code.', 'invoicing' ),
454
-            'std'  =>  __( 'ICIC0001234', 'invoicing' ),
452
+            'name' => __('IFSC code', 'invoicing'),
453
+            'desc' => __('Enter your bank IFSC code.', 'invoicing'),
454
+            'std'  =>  __('ICIC0001234', 'invoicing'),
455 455
         );
456 456
         
457 457
     $setting['bank_transfer_iban'] = array(
458 458
             'type' => 'text',
459 459
             'id'   => 'bank_transfer_iban',
460
-            'name' => __( 'IBAN', 'invoicing' ),
461
-            'desc' => __( 'Enter your International Bank Account Number(IBAN).', 'invoicing' ),
462
-            'std'  =>  __( 'GB29NWBK60161331926819', 'invoicing' ),
460
+            'name' => __('IBAN', 'invoicing'),
461
+            'desc' => __('Enter your International Bank Account Number(IBAN).', 'invoicing'),
462
+            'std'  =>  __('GB29NWBK60161331926819', 'invoicing'),
463 463
         );
464 464
         
465 465
     $setting['bank_transfer_bic'] = array(
466 466
             'type' => 'text',
467 467
             'id'   => 'bank_transfer_bic',
468
-            'name' => __( 'BIC/Swift code', 'invoicing' ),
469
-            'std'  =>  __( 'ICICGB2L129', 'invoicing' ),
468
+            'name' => __('BIC/Swift code', 'invoicing'),
469
+            'std'  =>  __('ICICGB2L129', 'invoicing'),
470 470
         );
471 471
         
472 472
     $setting['bank_transfer_info'] = array(
473 473
             'id'   => 'bank_transfer_info',
474
-            'name' => __( 'Instructions', 'invoicing' ),
475
-            'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ),
474
+            'name' => __('Instructions', 'invoicing'),
475
+            'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'),
476 476
             'type' => 'textarea',
477
-            'std' => __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ),
477
+            'std' => __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'),
478 478
             'cols' => 37,
479 479
             'rows' => 5
480 480
         );
481 481
         
482 482
     return $setting;
483 483
 }
484
-add_filter( 'wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1 );
484
+add_filter('wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1);
485 485
 
486 486
 // Authorize.Net settings
487
-function wpinv_gateway_settings_authorizenet( $setting ) {
488
-    $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __( '( currencies supported: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing' );
489
-    $setting['authorizenet_desc']['std'] = __( 'Pay using a Authorize.Net to process credit card / debit card transactions.', 'invoicing' );
487
+function wpinv_gateway_settings_authorizenet($setting) {
488
+    $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __('( currencies supported: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing');
489
+    $setting['authorizenet_desc']['std'] = __('Pay using a Authorize.Net to process credit card / debit card transactions.', 'invoicing');
490 490
     
491 491
     $setting['authorizenet_sandbox'] = array(
492 492
             'type' => 'checkbox',
493 493
             'id'   => 'authorizenet_sandbox',
494
-            'name' => __( 'Authorize.Net Test Mode', 'invoicing' ),
495
-            'desc' => __( 'Enable Authorize.Net test mode to test payments.', 'invoicing' ),
494
+            'name' => __('Authorize.Net Test Mode', 'invoicing'),
495
+            'desc' => __('Enable Authorize.Net test mode to test payments.', 'invoicing'),
496 496
             'std'  => 1
497 497
         );
498 498
         
499 499
     $setting['authorizenet_login_id'] = array(
500 500
             'type' => 'text',
501 501
             'id'   => 'authorizenet_login_id',
502
-            'name' => __( 'API Login ID', 'invoicing' ),
503
-            'desc' => __( 'API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing' ),
502
+            'name' => __('API Login ID', 'invoicing'),
503
+            'desc' => __('API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing'),
504 504
             'std' => '2j4rBekUnD',
505 505
         );
506 506
     
507 507
     $setting['authorizenet_transaction_key'] = array(
508 508
             'type' => 'text',
509 509
             'id'   => 'authorizenet_transaction_key',
510
-            'name' => __( 'Transaction Key', 'invoicing' ),
511
-            'desc' => __( 'Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing' ),
510
+            'name' => __('Transaction Key', 'invoicing'),
511
+            'desc' => __('Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing'),
512 512
             'std' => '4vyBUOJgR74679xa',
513 513
         );
514 514
         
515 515
     $setting['authorizenet_md5_hash'] = array(
516 516
             'type' => 'text',
517 517
             'id'   => 'authorizenet_md5_hash',
518
-            'name' => __( 'MD5-Hash', 'invoicing' ),
519
-            'desc' => __( 'The MD5 Hash security feature allows you to authenticate transaction responses from the Authorize.Net. If you are accepting recurring payments then md5 hash will helps to validate response from Authorize.net. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing' ),
518
+            'name' => __('MD5-Hash', 'invoicing'),
519
+            'desc' => __('The MD5 Hash security feature allows you to authenticate transaction responses from the Authorize.Net. If you are accepting recurring payments then md5 hash will helps to validate response from Authorize.net. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing'),
520 520
             'std' => '',
521 521
         );
522 522
         
523 523
     $setting['authorizenet_ipn_url'] = array(
524 524
             'type' => 'ipn_url',
525 525
             'id'   => 'authorizenet_ipn_url',
526
-            'name' => __( 'Silent Post URL', 'invoicing' ),
527
-            'std' => wpinv_get_ipn_url( 'authorizenet' ),
528
-            'desc' => __( 'If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing' ),
526
+            'name' => __('Silent Post URL', 'invoicing'),
527
+            'std' => wpinv_get_ipn_url('authorizenet'),
528
+            'desc' => __('If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing'),
529 529
             'size' => 'large',
530 530
             'custom' => 'authorizenet',
531 531
             'readonly' => true
@@ -533,25 +533,25 @@  discard block
 block discarded – undo
533 533
         
534 534
     return $setting;
535 535
 }
536
-add_filter( 'wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1 );
536
+add_filter('wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1);
537 537
 
538 538
 // Worldpay settings
539
-function wpinv_gateway_settings_worldpay( $setting ) {
540
-    $setting['worldpay_desc']['std'] = __( 'Pay using a Worldpay account to process credit card / debit card transactions.', 'invoicing' );
539
+function wpinv_gateway_settings_worldpay($setting) {
540
+    $setting['worldpay_desc']['std'] = __('Pay using a Worldpay account to process credit card / debit card transactions.', 'invoicing');
541 541
     
542 542
     $setting['worldpay_sandbox'] = array(
543 543
             'type' => 'checkbox',
544 544
             'id'   => 'worldpay_sandbox',
545
-            'name' => __( 'Worldpay Test Mode', 'invoicing' ),
546
-            'desc' => __( 'This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing' ),
545
+            'name' => __('Worldpay Test Mode', 'invoicing'),
546
+            'desc' => __('This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing'),
547 547
             'std'  => 1
548 548
         );
549 549
         
550 550
     $setting['worldpay_instId'] = array(
551 551
             'type' => 'text',
552 552
             'id'   => 'worldpay_instId',
553
-            'name' => __( 'Installation Id', 'invoicing' ),
554
-            'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ),
553
+            'name' => __('Installation Id', 'invoicing'),
554
+            'desc' => __('Your installation id. Ex: 211616', 'invoicing'),
555 555
             'std' => '211616',
556 556
         );
557 557
     /*
@@ -567,9 +567,9 @@  discard block
 block discarded – undo
567 567
     $setting['worldpay_ipn_url'] = array(
568 568
             'type' => 'ipn_url',
569 569
             'id'   => 'worldpay_ipn_url',
570
-            'name' => __( 'Worldpay Callback Url', 'invoicing' ),
571
-            'std' => wpinv_get_ipn_url( 'worldpay' ),
572
-            'desc' => wp_sprintf( __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing' ), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url( 'worldpay' ) . '</font>', '<font style="color:#000;font-style:normal">&lt;wpdisplay item=MC_callback&gt;</font>' ),
570
+            'name' => __('Worldpay Callback Url', 'invoicing'),
571
+            'std' => wpinv_get_ipn_url('worldpay'),
572
+            'desc' => wp_sprintf(__('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing'), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url('worldpay') . '</font>', '<font style="color:#000;font-style:normal">&lt;wpdisplay item=MC_callback&gt;</font>'),
573 573
             'size' => 'large',
574 574
             'custom' => 'worldpay',
575 575
             'readonly' => true
@@ -577,94 +577,94 @@  discard block
 block discarded – undo
577 577
         
578 578
     return $setting;
579 579
 }
580
-add_filter( 'wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1 );
580
+add_filter('wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1);
581 581
 
582
-function wpinv_ipn_url_callback( $args ) {    
583
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
582
+function wpinv_ipn_url_callback($args) {    
583
+    $sanitize_id = wpinv_sanitize_key($args['id']);
584 584
     
585 585
     $attrs = $args['readonly'] ? ' readonly' : '';
586 586
 
587
-    $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">';
588
-    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">'  . $args['desc'] . '</label>';
587
+    $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">';
588
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>';
589 589
 
590 590
     echo $html;
591 591
 }
592 592
 
593
-function wpinv_is_test_mode( $gateway = '' ) {
594
-    if ( empty( $gateway ) ) {
593
+function wpinv_is_test_mode($gateway = '') {
594
+    if (empty($gateway)) {
595 595
         return false;
596 596
     }
597 597
     
598
-    $is_test_mode = wpinv_get_option( $gateway . '_sandbox', false );
598
+    $is_test_mode = wpinv_get_option($gateway . '_sandbox', false);
599 599
     
600
-    return apply_filters( 'wpinv_is_test_mode', $is_test_mode, $gateway );
600
+    return apply_filters('wpinv_is_test_mode', $is_test_mode, $gateway);
601 601
 }
602 602
 
603
-function wpinv_get_ipn_url( $gateway = '', $args = array() ) {
604
-    $data = array( 'wpi-listener' => 'IPN' );
603
+function wpinv_get_ipn_url($gateway = '', $args = array()) {
604
+    $data = array('wpi-listener' => 'IPN');
605 605
     
606
-    if ( !empty( $gateway ) ) {
607
-        $data['wpi-gateway'] = wpinv_sanitize_key( $gateway );
606
+    if (!empty($gateway)) {
607
+        $data['wpi-gateway'] = wpinv_sanitize_key($gateway);
608 608
     }
609 609
     
610
-    $args = !empty( $args ) && is_array( $args ) ? array_merge( $data, $args ) : $data;
610
+    $args = !empty($args) && is_array($args) ? array_merge($data, $args) : $data;
611 611
     
612
-    $ipn_url = add_query_arg( $args,  home_url( 'index.php' ) );
612
+    $ipn_url = add_query_arg($args, home_url('index.php'));
613 613
     
614
-    return apply_filters( 'wpinv_ipn_url', $ipn_url );
614
+    return apply_filters('wpinv_ipn_url', $ipn_url);
615 615
 }
616 616
 
617 617
 function wpinv_listen_for_payment_ipn() {
618 618
     // Regular PayPal IPN
619
-    if ( isset( $_GET['wpi-listener'] ) && $_GET['wpi-listener'] == 'IPN' ) {
620
-        do_action( 'wpinv_verify_payment_ipn' );
619
+    if (isset($_GET['wpi-listener']) && $_GET['wpi-listener'] == 'IPN') {
620
+        do_action('wpinv_verify_payment_ipn');
621 621
         
622
-        if ( !empty( $_GET['wpi-gateway'] ) ) {
623
-            wpinv_error_log( sanitize_text_field( $_GET['wpi-gateway'] ), 'wpinv_listen_for_payment_ipn()', __FILE__, __LINE__ );
624
-            do_action( 'wpinv_verify_' . sanitize_text_field( $_GET['wpi-gateway'] ) . '_ipn' );
622
+        if (!empty($_GET['wpi-gateway'])) {
623
+            wpinv_error_log(sanitize_text_field($_GET['wpi-gateway']), 'wpinv_listen_for_payment_ipn()', __FILE__, __LINE__);
624
+            do_action('wpinv_verify_' . sanitize_text_field($_GET['wpi-gateway']) . '_ipn');
625 625
         }
626 626
     }
627 627
 }
628
-add_action( 'init', 'wpinv_listen_for_payment_ipn' );
628
+add_action('init', 'wpinv_listen_for_payment_ipn');
629 629
 
630 630
 function wpinv_get_bank_instructions() {
631
-    $bank_instructions = wpinv_get_option( 'bank_transfer_info' );
631
+    $bank_instructions = wpinv_get_option('bank_transfer_info');
632 632
     
633
-    return apply_filters( 'wpinv_bank_instructions', $bank_instructions );
633
+    return apply_filters('wpinv_bank_instructions', $bank_instructions);
634 634
 }
635 635
 
636
-function wpinv_get_bank_info( $filtered = false ) {
636
+function wpinv_get_bank_info($filtered = false) {
637 637
     $bank_fields = array(
638
-        'bank_transfer_ac_name' => __( 'Account Name', 'invoicing' ),
639
-        'bank_transfer_ac_no' => __( 'Account Number', 'invoicing' ),
640
-        'bank_transfer_bank_name' => __( 'Bank Name', 'invoicing' ),
641
-        'bank_transfer_ifsc' => __( 'IFSC code', 'invoicing' ),
642
-        'bank_transfer_iban' => __( 'IBAN', 'invoicing' ),
643
-        'bank_transfer_bic' => __( 'BIC/Swift code', 'invoicing' )
638
+        'bank_transfer_ac_name' => __('Account Name', 'invoicing'),
639
+        'bank_transfer_ac_no' => __('Account Number', 'invoicing'),
640
+        'bank_transfer_bank_name' => __('Bank Name', 'invoicing'),
641
+        'bank_transfer_ifsc' => __('IFSC code', 'invoicing'),
642
+        'bank_transfer_iban' => __('IBAN', 'invoicing'),
643
+        'bank_transfer_bic' => __('BIC/Swift code', 'invoicing')
644 644
     );
645 645
     
646 646
     $bank_info = array();
647
-    foreach ( $bank_fields as $field => $label ) {
648
-        if ( $filtered && !( $value = wpinv_get_option( $field ) ) ) {
647
+    foreach ($bank_fields as $field => $label) {
648
+        if ($filtered && !($value = wpinv_get_option($field))) {
649 649
             continue;
650 650
         }
651 651
         
652
-        $bank_info[$field] = array( 'label' => $label, 'value' => $value );
652
+        $bank_info[$field] = array('label' => $label, 'value' => $value);
653 653
     }
654 654
     
655
-    return apply_filters( 'wpinv_bank_info', $bank_info, $filtered );
655
+    return apply_filters('wpinv_bank_info', $bank_info, $filtered);
656 656
 }
657 657
 
658
-function wpinv_process_before_send_to_gateway( $invoice, $invoice_data = array() ) {
659
-    if ( !empty( $invoice ) && $invoice->is_recurring() && $subscription_item = $invoice->get_recurring( true ) ) {        
658
+function wpinv_process_before_send_to_gateway($invoice, $invoice_data = array()) {
659
+    if (!empty($invoice) && $invoice->is_recurring() && $subscription_item = $invoice->get_recurring(true)) {        
660 660
         $args                          = array();
661 661
         $args['item_id']               = $subscription_item->ID;
662
-        $args['initial_amount']        = wpinv_round_amount( $invoice->get_total() );
663
-        $args['recurring_amount']      = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) );
662
+        $args['initial_amount']        = wpinv_round_amount($invoice->get_total());
663
+        $args['recurring_amount']      = wpinv_round_amount($invoice->get_recurring_details('total'));
664 664
         $args['currency']              = $invoice->get_currency();
665 665
         $args['period']                = $subscription_item->get_recurring_period();
666 666
         $args['interval']              = $subscription_item->get_recurring_interval();
667
-        if ( $subscription_item->has_free_trial() ) {
667
+        if ($subscription_item->has_free_trial()) {
668 668
             $args['trial_period']      = $subscription_item->get_trial_period();
669 669
             $args['trial_interval']    = $subscription_item->get_trial_interval();
670 670
         } else {
@@ -673,25 +673,25 @@  discard block
 block discarded – undo
673 673
         }
674 674
         $args['bill_times']            = (int)$subscription_item->get_recurring_limit();
675 675
         
676
-        $invoice->update_subscription( $args );
676
+        $invoice->update_subscription($args);
677 677
     }
678 678
 }
679
-add_action( 'wpinv_checkout_before_send_to_gateway', 'wpinv_process_before_send_to_gateway', 10, 2 );
679
+add_action('wpinv_checkout_before_send_to_gateway', 'wpinv_process_before_send_to_gateway', 10, 2);
680 680
 
681
-function wpinv_get_post_data( $method = 'request' ) {
681
+function wpinv_get_post_data($method = 'request') {
682 682
     $data       = array();
683 683
     $request    = $_REQUEST;
684 684
     
685
-    if ( $method == 'post' ) {
686
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
685
+    if ($method == 'post') {
686
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
687 687
             return $data;
688 688
         }
689 689
         
690 690
         $request = $_POST;
691 691
     }
692 692
     
693
-    if ( $method == 'get' ) {
694
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET' ) {
693
+    if ($method == 'get') {
694
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET') {
695 695
             return $data;
696 696
         }
697 697
         
@@ -702,11 +702,11 @@  discard block
 block discarded – undo
702 702
     $post_data = '';
703 703
     
704 704
     // Fallback just in case post_max_size is lower than needed
705
-    if ( ini_get( 'allow_url_fopen' ) ) {
706
-        $post_data = file_get_contents( 'php://input' );
705
+    if (ini_get('allow_url_fopen')) {
706
+        $post_data = file_get_contents('php://input');
707 707
     } else {
708 708
         // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
709
-        ini_set( 'post_max_size', '12M' );
709
+        ini_set('post_max_size', '12M');
710 710
     }
711 711
     // Start the encoded data collection with notification command
712 712
     $encoded_data = 'cmd=_notify-validate';
@@ -715,58 +715,58 @@  discard block
 block discarded – undo
715 715
     $arg_separator = wpinv_get_php_arg_separator_output();
716 716
 
717 717
     // Verify there is a post_data
718
-    if ( $post_data || strlen( $post_data ) > 0 ) {
718
+    if ($post_data || strlen($post_data) > 0) {
719 719
         // Append the data
720 720
         $encoded_data .= $arg_separator . $post_data;
721 721
     } else {
722 722
         // Check if POST is empty
723
-        if ( empty( $request ) ) {
723
+        if (empty($request)) {
724 724
             // Nothing to do
725 725
             return;
726 726
         } else {
727 727
             // Loop through each POST
728
-            foreach ( $request as $key => $value ) {
728
+            foreach ($request as $key => $value) {
729 729
                 // Encode the value and append the data
730
-                $encoded_data .= $arg_separator . "$key=" . urlencode( $value );
730
+                $encoded_data .= $arg_separator . "$key=" . urlencode($value);
731 731
             }
732 732
         }
733 733
     }
734 734
 
735 735
     // Convert collected post data to an array
736
-    parse_str( $encoded_data, $data );
736
+    parse_str($encoded_data, $data);
737 737
 
738
-    foreach ( $data as $key => $value ) {
739
-        if ( false !== strpos( $key, 'amp;' ) ) {
740
-            $new_key = str_replace( '&amp;', '&', $key );
741
-            $new_key = str_replace( 'amp;', '&' , $new_key );
738
+    foreach ($data as $key => $value) {
739
+        if (false !== strpos($key, 'amp;')) {
740
+            $new_key = str_replace('&amp;', '&', $key);
741
+            $new_key = str_replace('amp;', '&', $new_key);
742 742
 
743
-            unset( $data[ $key ] );
744
-            $data[ $new_key ] = sanitize_text_field( $value );
743
+            unset($data[$key]);
744
+            $data[$new_key] = sanitize_text_field($value);
745 745
         }
746 746
     }
747 747
     
748 748
     return $data;
749 749
 }
750 750
 
751
-function wpinv_gateway_support_subscription( $gateway ) {
751
+function wpinv_gateway_support_subscription($gateway) {
752 752
     $return = false;
753 753
     
754
-    if ( wpinv_is_gateway_active( $gateway ) ) {
755
-        $return = apply_filters( 'wpinv_' . $gateway . '_support_subscription', false );
754
+    if (wpinv_is_gateway_active($gateway)) {
755
+        $return = apply_filters('wpinv_' . $gateway . '_support_subscription', false);
756 756
     }
757 757
     
758 758
     return $return;
759 759
 }
760 760
 
761
-function wpinv_payment_gateways_on_cart( $gateways = array() ) {
762
-    if ( !empty( $gateways ) && wpinv_cart_has_recurring_item() ) {
763
-        foreach ( $gateways as $gateway => $info ) {
764
-            if ( !wpinv_gateway_support_subscription( $gateway ) ) {
765
-                unset( $gateways[$gateway] );
761
+function wpinv_payment_gateways_on_cart($gateways = array()) {
762
+    if (!empty($gateways) && wpinv_cart_has_recurring_item()) {
763
+        foreach ($gateways as $gateway => $info) {
764
+            if (!wpinv_gateway_support_subscription($gateway)) {
765
+                unset($gateways[$gateway]);
766 766
             }
767 767
         }
768 768
     }
769 769
     
770 770
     return $gateways;
771 771
 }
772
-add_filter( 'wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1 );
773 772
\ No newline at end of file
773
+add_filter('wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1);
774 774
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-gd-functions.php 1 patch
Spacing   +341 added lines, -341 removed lines patch added patch discarded remove patch
@@ -1,23 +1,23 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 function wpinv_gd_active() {
8
-    return (bool)defined( 'GEODIRECTORY_VERSION' );
8
+    return (bool)defined('GEODIRECTORY_VERSION');
9 9
 }
10 10
 
11 11
 function wpinv_pm_active() {
12
-    return (bool)wpinv_gd_active() && (bool)defined( 'GEODIRPAYMENT_VERSION' );
12
+    return (bool)wpinv_gd_active() && (bool)defined('GEODIRPAYMENT_VERSION');
13 13
 }
14 14
 
15
-function wpinv_is_gd_post_type( $post_type ) {
15
+function wpinv_is_gd_post_type($post_type) {
16 16
     global $gd_posttypes;
17 17
     
18
-    $gd_posttypes = !empty( $gd_posttypes ) && is_array( $gd_posttypes ) ? $gd_posttypes : geodir_get_posttypes();
18
+    $gd_posttypes = !empty($gd_posttypes) && is_array($gd_posttypes) ? $gd_posttypes : geodir_get_posttypes();
19 19
     
20
-    if ( !empty( $post_type ) && !empty( $gd_posttypes ) && in_array( $post_type, $gd_posttypes ) ) {
20
+    if (!empty($post_type) && !empty($gd_posttypes) && in_array($post_type, $gd_posttypes)) {
21 21
         return true;
22 22
     }
23 23
     
@@ -29,10 +29,10 @@  discard block
 block discarded – undo
29 29
         return;
30 30
     }
31 31
     
32
-    if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
32
+    if (!(defined('DOING_AJAX') && DOING_AJAX)) {
33 33
         // Add  fields for force upgrade
34
-        if ( defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column') ) {
35
-            geodir_add_column_if_not_exist( INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0' );
34
+        if (defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column')) {
35
+            geodir_add_column_if_not_exist(INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0');
36 36
             
37 37
             update_option('wpinv_gdp_column', '1');
38 38
         }
@@ -40,39 +40,39 @@  discard block
 block discarded – undo
40 40
         wpinv_merge_gd_packages_to_items();
41 41
     }
42 42
 }
43
-add_action( 'admin_init', 'wpinv_geodir_integration' );
43
+add_action('admin_init', 'wpinv_geodir_integration');
44 44
 
45
-function wpinv_get_gdp_package_type( $item_types ) {
46
-    if ( wpinv_pm_active() ) {
47
-        $item_types['package'] = __( 'Package', 'invoicing' );
45
+function wpinv_get_gdp_package_type($item_types) {
46
+    if (wpinv_pm_active()) {
47
+        $item_types['package'] = __('Package', 'invoicing');
48 48
     }
49 49
         
50 50
     return $item_types;
51 51
 }
52
-add_filter( 'wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1 );
52
+add_filter('wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1);
53 53
 
54 54
 function wpinv_update_package_item($package_id) {
55 55
     return wpinv_merge_gd_package_to_item($package_id, true);
56 56
 }
57 57
 add_action('geodir_after_save_package', 'wpinv_update_package_item', 10, 1);
58 58
 
59
-function wpinv_merge_gd_packages_to_items( $force = false ) {    
60
-    if ( $merged = get_option( 'wpinv_merge_gd_packages' ) && !$force ) {
59
+function wpinv_merge_gd_packages_to_items($force = false) {    
60
+    if ($merged = get_option('wpinv_merge_gd_packages') && !$force) {
61 61
         return true;
62 62
     }
63 63
 
64
-    if(!function_exists('geodir_package_list_info')){
64
+    if (!function_exists('geodir_package_list_info')) {
65 65
         return false;
66 66
     }
67 67
     
68 68
     $packages = geodir_package_list_info();
69 69
     
70
-    foreach ( $packages as $key => $package ) {
71
-        wpinv_merge_gd_package_to_item( $package->pid, $force, $package );
70
+    foreach ($packages as $key => $package) {
71
+        wpinv_merge_gd_package_to_item($package->pid, $force, $package);
72 72
     }
73 73
     
74
-    if ( !$merged ) {
75
-        update_option( 'wpinv_merge_gd_packages', 1 );
74
+    if (!$merged) {
75
+        update_option('wpinv_merge_gd_packages', 1);
76 76
     }
77 77
     
78 78
     return true;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 
102 102
     $package = empty($package) ? geodir_get_package_info_by_id($package_id, '') : $package;
103 103
 
104
-    if ( empty($package) || !wpinv_is_gd_post_type( $package->post_type ) ) {
104
+    if (empty($package) || !wpinv_is_gd_post_type($package->post_type)) {
105 105
         return false;
106 106
     }
107 107
         
@@ -111,17 +111,17 @@  discard block
 block discarded – undo
111 111
     $meta['post_type']          = $package->post_type;
112 112
     $meta['cpt_singular_name']  = get_post_type_singular_label($package->post_type);
113 113
     $meta['cpt_name']           = get_post_type_plural_label($package->post_type);
114
-    $meta['price']              = wpinv_round_amount( $package->amount );
114
+    $meta['price']              = wpinv_round_amount($package->amount);
115 115
     $meta['vat_rule']           = 'digital';
116 116
     $meta['vat_class']          = '_standard';
117 117
     
118
-    if ( !empty( $package->sub_active ) ) {
119
-        $sub_num_trial_days = absint( $package->sub_num_trial_days );
118
+    if (!empty($package->sub_active)) {
119
+        $sub_num_trial_days = absint($package->sub_num_trial_days);
120 120
         
121 121
         $meta['is_recurring']       = 1;
122 122
         $meta['recurring_period']   = $package->sub_units;
123
-        $meta['recurring_interval'] = absint( $package->sub_units_num );
124
-        $meta['recurring_limit']    = absint( $package->sub_units_num_times );
123
+        $meta['recurring_interval'] = absint($package->sub_units_num);
124
+        $meta['recurring_limit']    = absint($package->sub_units_num_times);
125 125
         $meta['free_trial']         = $sub_num_trial_days > 0 ? 1 : 0;
126 126
         $meta['trial_period']       = $package->sub_num_trial_units;
127 127
         $meta['trial_interval']     = $sub_num_trial_days;
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
         $meta['trial_interval']     = '';
136 136
     }
137 137
     
138
-    $data  = array( 
138
+    $data = array( 
139 139
         'post_title'    => $package->title,
140 140
         'post_excerpt'  => $package->title_desc,
141 141
         'post_status'   => $package->status == 1 ? 'publish' : 'pending',
@@ -152,48 +152,48 @@  discard block
 block discarded – undo
152 152
     return $item;
153 153
 }
154 154
 
155
-function wpinv_gdp_to_wpi_gateway( $payment_method ) {
156
-    switch( $payment_method ) {
155
+function wpinv_gdp_to_wpi_gateway($payment_method) {
156
+    switch ($payment_method) {
157 157
         case 'prebanktransfer':
158 158
             $gateway = 'bank_transfer';
159 159
         break;
160 160
         default:
161
-            $gateway = empty( $payment_method ) ? 'manual' : $payment_method;
161
+            $gateway = empty($payment_method) ? 'manual' : $payment_method;
162 162
         break;
163 163
     }
164 164
     
165
-    return apply_filters( 'wpinv_gdp_to_wpi_gateway', $gateway, $payment_method );
165
+    return apply_filters('wpinv_gdp_to_wpi_gateway', $gateway, $payment_method);
166 166
 }
167 167
 
168
-function wpinv_gdp_to_wpi_gateway_title( $payment_method ) {
169
-    $gateway = wpinv_gdp_to_wpi_gateway( $payment_method );
168
+function wpinv_gdp_to_wpi_gateway_title($payment_method) {
169
+    $gateway = wpinv_gdp_to_wpi_gateway($payment_method);
170 170
     
171
-    $gateway_title = wpinv_get_gateway_checkout_label( $gateway );
171
+    $gateway_title = wpinv_get_gateway_checkout_label($gateway);
172 172
     
173
-    if ( $gateway == $gateway_title ) {
174
-        $gateway_title = geodir_payment_method_title( $gateway );
173
+    if ($gateway == $gateway_title) {
174
+        $gateway_title = geodir_payment_method_title($gateway);
175 175
     }
176 176
     
177
-    return apply_filters( 'wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method );
177
+    return apply_filters('wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method);
178 178
 }
179 179
 
180 180
 function wpinv_print_checkout_errors() {
181 181
     global $wpi_session;
182 182
     wpinv_print_errors();
183 183
 }
184
-add_action( 'geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10 );
184
+add_action('geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10);
185 185
 
186
-function wpinv_cpt_save( $invoice_id, $update = false, $pre_status = NULL ) {
186
+function wpinv_cpt_save($invoice_id, $update = false, $pre_status = NULL) {
187 187
     global $wpi_nosave, $wpi_zero_tax, $wpi_gdp_inv_merge;
188 188
     
189
-    $invoice_info = geodir_get_invoice( $invoice_id );
189
+    $invoice_info = geodir_get_invoice($invoice_id);
190 190
     
191
-    $wpi_invoice_id  = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : 0;
191
+    $wpi_invoice_id  = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : 0;
192 192
     
193 193
     if (!empty($invoice_info)) {
194
-        $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice( $wpi_invoice_id ) : NULL;
194
+        $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice($wpi_invoice_id) : NULL;
195 195
         
196
-        if ( !empty( $wpi_invoice ) ) { // update invoice
196
+        if (!empty($wpi_invoice)) { // update invoice
197 197
             $save = false;
198 198
             if ($invoice_info->coupon_code !== $wpi_invoice->discount_code || (float)$invoice_info->discount < (float)$wpi_invoice->discount || (float)$invoice_info->discount > (float)$wpi_invoice->discount) {
199 199
                 $save = true;
@@ -203,16 +203,16 @@  discard block
 block discarded – undo
203 203
             
204 204
             if ($invoice_info->paymentmethod !== $wpi_invoice->gateway) {
205 205
                 $save = true;
206
-                $gateway = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : '';
207
-                $gateway = wpinv_gdp_to_wpi_gateway( $gateway );
208
-                $gateway_title = wpinv_gdp_to_wpi_gateway_title( $gateway );
209
-                $wpi_invoice->set('gateway', $gateway );
210
-                $wpi_invoice->set('gateway_title', $gateway_title );
206
+                $gateway = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : '';
207
+                $gateway = wpinv_gdp_to_wpi_gateway($gateway);
208
+                $gateway_title = wpinv_gdp_to_wpi_gateway_title($gateway);
209
+                $wpi_invoice->set('gateway', $gateway);
210
+                $wpi_invoice->set('gateway_title', $gateway_title);
211 211
             }
212 212
             
213
-            if ( ( $status = wpinv_gdp_to_wpi_status( $invoice_info->status ) ) !== $wpi_invoice->status ) {
213
+            if (($status = wpinv_gdp_to_wpi_status($invoice_info->status)) !== $wpi_invoice->status) {
214 214
                 $save = true;
215
-                $wpi_invoice->set( 'status', $status );
215
+                $wpi_invoice->set('status', $status);
216 216
             }
217 217
             
218 218
             if ($save) {
@@ -223,37 +223,37 @@  discard block
 block discarded – undo
223 223
             
224 224
             return $wpi_invoice;
225 225
         } else { // create invoice
226
-            $user_info = get_userdata( $invoice_info->user_id );
226
+            $user_info = get_userdata($invoice_info->user_id);
227 227
             
228
-            if ( !empty( $pre_status ) ) {
228
+            if (!empty($pre_status)) {
229 229
                 $invoice_info->status = $pre_status;
230 230
             }
231
-            $status = wpinv_gdp_to_wpi_status( $invoice_info->status );
231
+            $status = wpinv_gdp_to_wpi_status($invoice_info->status);
232 232
             
233 233
             $wpi_zero_tax = false;
234 234
             
235
-            if ( $wpi_gdp_inv_merge && in_array( $status, array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
235
+            if ($wpi_gdp_inv_merge && in_array($status, array('publish', 'wpi-processing', 'wpi-renewal'))) {
236 236
                 $wpi_zero_tax = true;
237 237
             }
238 238
             
239 239
             $invoice_data                   = array();
240 240
             $invoice_data['invoice_id']     = $wpi_invoice_id;
241 241
             $invoice_data['status']         = $status;
242
-            if ( $update ) {
242
+            if ($update) {
243 243
                 //$invoice_data['private_note']   = __( 'Invoice was updated.', 'invoicing' );
244 244
             } else {
245
-                $invoice_data['private_note']   = wp_sprintf( __( 'Invoice was created with status %s.', 'invoicing' ), wpinv_status_nicename( $status ) );
245
+                $invoice_data['private_note'] = wp_sprintf(__('Invoice was created with status %s.', 'invoicing'), wpinv_status_nicename($status));
246 246
             }
247 247
             $invoice_data['user_id']        = $invoice_info->user_id;
248 248
             $invoice_data['created_via']    = 'API';
249 249
             
250
-            if ( !empty( $invoice_info->date ) ) {
251
-                $invoice_data['created_date']   = $invoice_info->date;
250
+            if (!empty($invoice_info->date)) {
251
+                $invoice_data['created_date'] = $invoice_info->date;
252 252
             }
253 253
             
254
-            $paymentmethod = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : '';
255
-            $paymentmethod = wpinv_gdp_to_wpi_gateway( $paymentmethod );
256
-            $payment_method_title = wpinv_gdp_to_wpi_gateway_title( $paymentmethod );
254
+            $paymentmethod = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : '';
255
+            $paymentmethod = wpinv_gdp_to_wpi_gateway($paymentmethod);
256
+            $payment_method_title = wpinv_gdp_to_wpi_gateway_title($paymentmethod);
257 257
             
258 258
             $invoice_data['payment_details'] = array( 
259 259
                 'gateway'           => $paymentmethod, 
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
                 'paid'              => $status === 'publish' ? true : false
263 263
             );
264 264
             
265
-            $user_address = wpinv_get_user_address( $invoice_info->user_id, false );
265
+            $user_address = wpinv_get_user_address($invoice_info->user_id, false);
266 266
             
267 267
             $invoice_data['user_info'] = array( 
268 268
                 'user_id'       => $invoice_info->user_id, 
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
             
286 286
             $post_item = wpinv_get_gd_package_item($invoice_info->package_id);
287 287
             
288
-            if ( !empty( $post_item ) ) {
289
-                $cart_details  = array();
288
+            if (!empty($post_item)) {
289
+                $cart_details = array();
290 290
                 $cart_details[] = array(
291 291
                     'id'                => $post_item->ID,
292 292
                     'name'              => $post_item->get_name(),
@@ -299,19 +299,19 @@  discard block
 block discarded – undo
299 299
                                         ),
300 300
                 );
301 301
                 
302
-                $invoice_data['cart_details']  = $cart_details;
302
+                $invoice_data['cart_details'] = $cart_details;
303 303
             }
304 304
 
305
-            $data = array( 'invoice' => $invoice_data );
305
+            $data = array('invoice' => $invoice_data);
306 306
 
307 307
             $wpinv_api = new WPInv_API();
308
-            $data = $wpinv_api->insert_invoice( $data );
308
+            $data = $wpinv_api->insert_invoice($data);
309 309
             
310
-            if ( is_wp_error( $data ) ) {
311
-                wpinv_error_log( 'WPInv_Invoice: ' . $data->get_error_message() );
310
+            if (is_wp_error($data)) {
311
+                wpinv_error_log('WPInv_Invoice: ' . $data->get_error_message());
312 312
             } else {
313
-                if ( !empty( $data ) ) {
314
-                    update_post_meta( $data->ID, '_wpinv_gdp_id', $invoice_id );
313
+                if (!empty($data)) {
314
+                    update_post_meta($data->ID, '_wpinv_gdp_id', $invoice_id);
315 315
 
316 316
                     global $wpi_userID, $wpinv_ip_address_country;
317 317
                     
@@ -319,21 +319,21 @@  discard block
 block discarded – undo
319 319
                     
320 320
                     $data_session                   = array();
321 321
                     $data_session['invoice_id']     = $data->ID;
322
-                    $data_session['cart_discounts'] = $data->get_discounts( true );
322
+                    $data_session['cart_discounts'] = $data->get_discounts(true);
323 323
                     
324
-                    wpinv_set_checkout_session( $data_session );
324
+                    wpinv_set_checkout_session($data_session);
325 325
                     
326 326
                     $wpi_userID         = (int)$data->get_user_id();
327 327
                     $_POST['country']   = !empty($data->country) ? $data->country : wpinv_get_default_country();
328 328
                         
329
-                    $data->country      = sanitize_text_field( $_POST['country'] );
330
-                    $data->set( 'country', sanitize_text_field( $_POST['country'] ) );
329
+                    $data->country      = sanitize_text_field($_POST['country']);
330
+                    $data->set('country', sanitize_text_field($_POST['country']));
331 331
                     
332 332
                     $wpinv_ip_address_country = $data->country;
333 333
                     
334 334
                     $data = $data->recalculate_totals(true);
335 335
                     
336
-                    wpinv_set_checkout_session( $checkout_session );
336
+                    wpinv_set_checkout_session($checkout_session);
337 337
                     
338 338
                     $update_data = array();
339 339
                     $update_data['tax_amount'] = $data->get_tax();
@@ -341,14 +341,14 @@  discard block
 block discarded – undo
341 341
                     $update_data['invoice_id'] = $data->ID;
342 342
                     
343 343
                     global $wpdb;
344
-                    $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $invoice_id ) );
344
+                    $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $invoice_id));
345 345
                     
346 346
                     return $data;
347 347
                 } else {
348
-                    if ( $update ) {
349
-                        wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to update invoice.', 'invoicing' ) );
348
+                    if ($update) {
349
+                        wpinv_error_log('WPInv_Invoice: ' . __('Fail to update invoice.', 'invoicing'));
350 350
                     } else {
351
-                        wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to create invoice.', 'invoicing' ) );
351
+                        wpinv_error_log('WPInv_Invoice: ' . __('Fail to create invoice.', 'invoicing'));
352 352
                     }
353 353
                 }
354 354
             }
@@ -359,59 +359,59 @@  discard block
 block discarded – undo
359 359
 }
360 360
 add_action('geodir_payment_invoice_created', 'wpinv_cpt_save', 11, 3);
361 361
 
362
-function wpinv_cpt_update( $invoice_id ) {
363
-    return wpinv_cpt_save( $invoice_id, true );
362
+function wpinv_cpt_update($invoice_id) {
363
+    return wpinv_cpt_save($invoice_id, true);
364 364
 }
365 365
 add_action('geodir_payment_invoice_updated', 'wpinv_cpt_update', 11, 1);
366 366
 
367
-function wpinv_payment_status_changed( $invoice_id, $new_status, $old_status = 'pending', $subscription = false ) {
368
-    $invoice_info = geodir_get_invoice( $invoice_id );
369
-    if ( empty( $invoice_info ) ) {
367
+function wpinv_payment_status_changed($invoice_id, $new_status, $old_status = 'pending', $subscription = false) {
368
+    $invoice_info = geodir_get_invoice($invoice_id);
369
+    if (empty($invoice_info)) {
370 370
         return false;
371 371
     }
372 372
 
373
-    $invoice = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL;
374
-    if ( !empty( $invoice ) ) {
373
+    $invoice = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL;
374
+    if (!empty($invoice)) {
375 375
         $new_status = wpinv_gdp_to_wpi_status($new_status);
376
-        $invoice    = wpinv_update_payment_status( $invoice->ID, $new_status );
376
+        $invoice    = wpinv_update_payment_status($invoice->ID, $new_status);
377 377
     } else {
378
-        $invoice = wpinv_cpt_save( $invoice_id );
378
+        $invoice = wpinv_cpt_save($invoice_id);
379 379
     }
380 380
     
381 381
     return $invoice;
382 382
 }
383
-add_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 );
383
+add_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4);
384 384
 
385
-function wpinv_transaction_details_note( $invoice_id, $html ) {
386
-    $invoice_info = geodir_get_invoice( $invoice_id );
387
-    if ( empty( $invoice_info ) ) {
385
+function wpinv_transaction_details_note($invoice_id, $html) {
386
+    $invoice_info = geodir_get_invoice($invoice_id);
387
+    if (empty($invoice_info)) {
388 388
         return false;
389 389
     }
390 390
 
391
-    $wpi_invoice_id = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : NULL;
391
+    $wpi_invoice_id = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : NULL;
392 392
     
393
-    if ( !$wpi_invoice_id ) {
394
-        $invoice = wpinv_cpt_save( $invoice_id, false, $old_status );
393
+    if (!$wpi_invoice_id) {
394
+        $invoice = wpinv_cpt_save($invoice_id, false, $old_status);
395 395
         
396
-        if ( !empty( $invoice ) ) {
396
+        if (!empty($invoice)) {
397 397
             $wpi_invoice_id = $invoice->ID;
398 398
         }
399 399
     }
400 400
 
401
-    $invoice = wpinv_get_invoice( $wpi_invoice_id );
401
+    $invoice = wpinv_get_invoice($wpi_invoice_id);
402 402
     
403
-    if ( empty( $invoice ) ) {
403
+    if (empty($invoice)) {
404 404
         return false;
405 405
     }
406 406
     
407
-    return $invoice->add_note( $html, true );
407
+    return $invoice->add_note($html, true);
408 408
 }
409
-add_action( 'geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2 );
409
+add_action('geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2);
410 410
 
411
-function wpinv_gdp_to_wpi_status( $status ) {
411
+function wpinv_gdp_to_wpi_status($status) {
412 412
     $inv_status = $status ? $status : 'pending';
413 413
     
414
-    switch ( $status ) {
414
+    switch ($status) {
415 415
         case 'confirmed':
416 416
             $inv_status = 'publish';
417 417
         break;
@@ -420,10 +420,10 @@  discard block
 block discarded – undo
420 420
     return $inv_status;
421 421
 }
422 422
 
423
-function wpinv_wpi_to_gdp_status( $status ) {
423
+function wpinv_wpi_to_gdp_status($status) {
424 424
     $inv_status = $status ? $status : 'pending';
425 425
     
426
-    switch ( $status ) {
426
+    switch ($status) {
427 427
         case 'publish':
428 428
         case 'wpi-processing':
429 429
         case 'wpi-renewal':
@@ -434,102 +434,102 @@  discard block
 block discarded – undo
434 434
     return $inv_status;
435 435
 }
436 436
 
437
-function wpinv_wpi_to_gdp_id( $invoice_id ) {
437
+function wpinv_wpi_to_gdp_id($invoice_id) {
438 438
     global $wpdb;
439 439
     
440
-    return $wpdb->get_var( $wpdb->prepare( "SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array( (int)$invoice_id ) ) );
440
+    return $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array((int)$invoice_id)));
441 441
 }
442 442
 
443
-function wpinv_gdp_to_wpi_id( $invoice_id ) {
444
-    $invoice = geodir_get_invoice( $invoice_id );    
445
-    return ( empty( $invoice->invoice_id ) ? $invoice->invoice_id : false);
443
+function wpinv_gdp_to_wpi_id($invoice_id) {
444
+    $invoice = geodir_get_invoice($invoice_id);    
445
+    return (empty($invoice->invoice_id) ? $invoice->invoice_id : false);
446 446
 }
447 447
 
448
-function wpinv_to_gdp_recalculate_total( $invoice, $wpi_nosave ) {
448
+function wpinv_to_gdp_recalculate_total($invoice, $wpi_nosave) {
449 449
     global $wpdb;
450 450
     
451
-    if ( !empty( $wpi_nosave ) ) {
451
+    if (!empty($wpi_nosave)) {
452 452
         return;
453 453
     }
454 454
     
455
-    $gdp_invoice_id = wpinv_wpi_to_gdp_id( $invoice->ID );
455
+    $gdp_invoice_id = wpinv_wpi_to_gdp_id($invoice->ID);
456 456
     
457
-    if ( $gdp_invoice_id > 0 ) {
457
+    if ($gdp_invoice_id > 0) {
458 458
         $update_data = array();
459 459
         $update_data['tax_amount']      = $invoice->tax;
460 460
         $update_data['paied_amount']    = $invoice->total;
461 461
         $update_data['discount']        = $invoice->discount;
462 462
         $update_data['coupon_code']     = $invoice->discount_code;
463 463
         
464
-        $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $gdp_invoice_id ) );
464
+        $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $gdp_invoice_id));
465 465
     }
466 466
     
467 467
     return;
468 468
 }
469 469
 //add_action( 'wpinv_invoice_recalculate_total', 'wpinv_to_gdp_recalculate_total', 10, 2 );
470 470
 
471
-function wpinv_gdp_to_wpi_invoice( $invoice_id ) {
472
-    $invoice = geodir_get_invoice( $invoice_id );
473
-    if ( empty( $invoice->invoice_id ) ) {
471
+function wpinv_gdp_to_wpi_invoice($invoice_id) {
472
+    $invoice = geodir_get_invoice($invoice_id);
473
+    if (empty($invoice->invoice_id)) {
474 474
         return false;
475 475
     }
476 476
     
477
-    return wpinv_get_invoice( $invoice->invoice_id );
477
+    return wpinv_get_invoice($invoice->invoice_id);
478 478
 }
479 479
 
480
-function wpinv_payment_set_coupon_code( $status, $invoice_id, $coupon_code ) {
481
-    $invoice = wpinv_gdp_to_wpi_invoice( $invoice_id );
482
-    if ( empty( $invoice ) ) {
480
+function wpinv_payment_set_coupon_code($status, $invoice_id, $coupon_code) {
481
+    $invoice = wpinv_gdp_to_wpi_invoice($invoice_id);
482
+    if (empty($invoice)) {
483 483
         return $status;
484 484
     }
485 485
 
486
-    if ( $status === 1 || $status === 0 ) {
487
-        if ( $status === 1 ) {
488
-            $discount = geodir_get_discount_amount( $coupon_code, $invoice->get_subtotal() );
486
+    if ($status === 1 || $status === 0) {
487
+        if ($status === 1) {
488
+            $discount = geodir_get_discount_amount($coupon_code, $invoice->get_subtotal());
489 489
         } else {
490 490
             $discount = '';
491 491
             $coupon_code = '';
492 492
         }
493 493
         
494
-        $invoice->set( 'discount', $discount );
495
-        $invoice->set( 'discount_code', $coupon_code );
494
+        $invoice->set('discount', $discount);
495
+        $invoice->set('discount_code', $coupon_code);
496 496
         $invoice->save();
497 497
         $invoice->recalculate_total();
498 498
     }
499 499
     
500 500
     return $status;
501 501
 }
502
-add_filter( 'geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3 );
502
+add_filter('geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3);
503 503
 
504
-function wpinv_insert_invoice( $invoice_data = array() ) {
505
-    if ( empty( $invoice_data ) ) {
504
+function wpinv_insert_invoice($invoice_data = array()) {
505
+    if (empty($invoice_data)) {
506 506
         return false;
507 507
     }
508 508
     
509
-    if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) {
510
-        return new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast on item.', 'invoicing' ) );
509
+    if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) {
510
+        return new WP_Error('wpinv_invalid_items', __('Invoice must have atleast on item.', 'invoicing'));
511 511
     }
512 512
 
513 513
     // default invoice args, note that status is checked for validity in wpinv_create_invoice()
514 514
     $default_args = array(
515
-        'status'        => !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending',
516
-        'user_note'     => !empty( $invoice_data['note'] ) ? $invoice_data['note'] : null,
517
-        'invoice_id'    => !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0,
518
-        'user_id'       => !empty( $invoice_data['user_id'] ) ? (int)$invoice_data['user_id'] : get_current_user_id(),
515
+        'status'        => !empty($invoice_data['status']) ? $invoice_data['status'] : 'pending',
516
+        'user_note'     => !empty($invoice_data['note']) ? $invoice_data['note'] : null,
517
+        'invoice_id'    => !empty($invoice_data['invoice_id']) ? (int)$invoice_data['invoice_id'] : 0,
518
+        'user_id'       => !empty($invoice_data['user_id']) ? (int)$invoice_data['user_id'] : get_current_user_id(),
519 519
     );
520 520
 
521
-    $invoice = wpinv_create_invoice( $default_args, $invoice_data );
522
-    if ( is_wp_error( $invoice ) ) {
521
+    $invoice = wpinv_create_invoice($default_args, $invoice_data);
522
+    if (is_wp_error($invoice)) {
523 523
         return $invoice;
524 524
     }
525 525
 
526
-    $gateway = !empty( $invoice_data['gateway'] ) ? $invoice_data['gateway'] : '';
527
-    $gateway = empty( $gateway ) && isset( $_POST['gateway'] ) ? $_POST['gateway'] : $gateway;
526
+    $gateway = !empty($invoice_data['gateway']) ? $invoice_data['gateway'] : '';
527
+    $gateway = empty($gateway) && isset($_POST['gateway']) ? $_POST['gateway'] : $gateway;
528 528
     
529
-    if ( !empty( $gateway ) ) {
530
-        $gateway = wpinv_gdp_to_wpi_gateway( $gateway );
529
+    if (!empty($gateway)) {
530
+        $gateway = wpinv_gdp_to_wpi_gateway($gateway);
531 531
         $invoice_data['payment_details']['gateway'] = $gateway;
532
-        $invoice_data['payment_details']['gateway_title'] = wpinv_gdp_to_wpi_gateway_title( $gateway );
532
+        $invoice_data['payment_details']['gateway_title'] = wpinv_gdp_to_wpi_gateway_title($gateway);
533 533
     }
534 534
     
535 535
     $user_info = array(
@@ -550,67 +550,67 @@  discard block
 block discarded – undo
550 550
         'discount'       => array(),
551 551
     );
552 552
     
553
-    $user_info    = wp_parse_args( $invoice_data['user_info'], $user_info );
553
+    $user_info = wp_parse_args($invoice_data['user_info'], $user_info);
554 554
     
555 555
     $payment_details = array();
556
-    if ( !empty( $invoice_data['payment_details'] ) ) {
556
+    if (!empty($invoice_data['payment_details'])) {
557 557
         $payment_details = array(
558 558
             'gateway'           => 'manual',
559
-            'gateway_title'     => __( 'Manual Payment', 'invoicing' ),
559
+            'gateway_title'     => __('Manual Payment', 'invoicing'),
560 560
             'currency'          => geodir_get_currency_type(),
561 561
             'paid'              => false,
562 562
             'transaction_id'    => '',
563 563
         );
564
-        $payment_details = wp_parse_args( $invoice_data['payment_details'], $payment_details );
564
+        $payment_details = wp_parse_args($invoice_data['payment_details'], $payment_details);
565 565
     }
566
-    $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending' ) );
567
-    if ( !empty( $payment_details ) ) {
568
-        $invoice->set( 'currency', $payment_details['currency'] );
569
-        $invoice->set( 'gateway', $payment_details['gateway'] );
570
-        $invoice->set( 'gateway_title', $payment_details['gateway_title'] );
571
-        $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
566
+    $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'pending'));
567
+    if (!empty($payment_details)) {
568
+        $invoice->set('currency', $payment_details['currency']);
569
+        $invoice->set('gateway', $payment_details['gateway']);
570
+        $invoice->set('gateway_title', $payment_details['gateway_title']);
571
+        $invoice->set('transaction_id', $payment_details['transaction_id']);
572 572
     }
573 573
 
574
-    $invoice->set( 'user_info', $user_info );
574
+    $invoice->set('user_info', $user_info);
575 575
     ///$invoice->set( 'user_id', $user_info['user_id'] );
576 576
     ///$invoice->set( 'email', $user_info['email'] );
577
-    $invoice->set( 'first_name', $user_info['first_name'] );
578
-    $invoice->set( 'last_name', $user_info['last_name'] );
579
-    $invoice->set( 'address', $user_info['address'] );
580
-    $invoice->set( 'company', $user_info['company'] );
581
-    $invoice->set( 'vat_number', $user_info['vat_number'] );
582
-    $invoice->set( 'phone', $user_info['phone'] );
583
-    $invoice->set( 'city', $user_info['city'] );
584
-    $invoice->set( 'country', $user_info['country'] );
585
-    $invoice->set( 'state', $user_info['state'] );
586
-    $invoice->set( 'zip', $user_info['zip'] );
587
-    $invoice->set( 'discounts', ( !empty( $user_info['discount'] ) ? $user_info['discount'] : array() ) );
588
-    $invoice->set( 'ip', wpinv_get_ip() );
589
-    if ( !empty( $invoice_data['invoice_key'] ) ) {
590
-        $invoice->set( 'key', $invoice_data['invoice_key'] );
577
+    $invoice->set('first_name', $user_info['first_name']);
578
+    $invoice->set('last_name', $user_info['last_name']);
579
+    $invoice->set('address', $user_info['address']);
580
+    $invoice->set('company', $user_info['company']);
581
+    $invoice->set('vat_number', $user_info['vat_number']);
582
+    $invoice->set('phone', $user_info['phone']);
583
+    $invoice->set('city', $user_info['city']);
584
+    $invoice->set('country', $user_info['country']);
585
+    $invoice->set('state', $user_info['state']);
586
+    $invoice->set('zip', $user_info['zip']);
587
+    $invoice->set('discounts', (!empty($user_info['discount']) ? $user_info['discount'] : array()));
588
+    $invoice->set('ip', wpinv_get_ip());
589
+    if (!empty($invoice_data['invoice_key'])) {
590
+        $invoice->set('key', $invoice_data['invoice_key']);
591 591
     }
592
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
593
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
592
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
593
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
594 594
     
595 595
     // Add note
596
-    if ( !empty( $invoice_data['user_note'] ) ) {
597
-        $invoice->add_note( $invoice_data['user_note'], true );
596
+    if (!empty($invoice_data['user_note'])) {
597
+        $invoice->add_note($invoice_data['user_note'], true);
598 598
     }
599 599
     
600
-    if ( !empty( $invoice_data['private_note'] ) ) {
601
-        $invoice->add_note( $invoice_data['private_note'] );
600
+    if (!empty($invoice_data['private_note'])) {
601
+        $invoice->add_note($invoice_data['private_note']);
602 602
     }
603 603
     
604
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) {
605
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
606
-            $item_id    = !empty( $item['id'] ) ? $item['id'] : 0;
607
-            $quantity   = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
608
-            $name       = !empty( $item['name'] ) ? $item['name'] : '';
609
-            $item_price = isset( $item['item_price'] ) ? $item['item_price'] : '';
604
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) {
605
+        foreach ($invoice_data['cart_details'] as $key => $item) {
606
+            $item_id    = !empty($item['id']) ? $item['id'] : 0;
607
+            $quantity   = !empty($item['quantity']) ? $item['quantity'] : 1;
608
+            $name       = !empty($item['name']) ? $item['name'] : '';
609
+            $item_price = isset($item['item_price']) ? $item['item_price'] : '';
610 610
             
611
-            $post_item  = new WPInv_Item( $item_id );
612
-            if ( !empty( $post_item ) ) {
613
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
611
+            $post_item  = new WPInv_Item($item_id);
612
+            if (!empty($post_item)) {
613
+                $name       = !empty($name) ? $name : $post_item->get_name();
614 614
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
615 615
             } else {
616 616
                 continue;
@@ -620,33 +620,33 @@  discard block
 block discarded – undo
620 620
                 'name'          => $name,
621 621
                 'quantity'      => $quantity,
622 622
                 'item_price'    => $item_price,
623
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
624
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
625
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
626
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
623
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
624
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
625
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
626
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
627 627
             );
628 628
 
629
-            $invoice->add_item( $item_id, $args );
629
+            $invoice->add_item($item_id, $args);
630 630
         }
631 631
     }
632 632
 
633
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
633
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
634 634
 
635
-    if ( isset( $invoice_data['post_date'] ) ) {
636
-        $invoice->set( 'date', $invoice_data['post_date'] );
635
+    if (isset($invoice_data['post_date'])) {
636
+        $invoice->set('date', $invoice_data['post_date']);
637 637
     }
638 638
 
639
-    $number = wpinv_format_invoice_number( $invoice->ID );
640
-    $invoice->set( 'number', $number );
641
-    update_option( 'wpinv_last_invoice_number', $number );
639
+    $number = wpinv_format_invoice_number($invoice->ID);
640
+    $invoice->set('number', $number);
641
+    update_option('wpinv_last_invoice_number', $number);
642 642
     
643 643
     $invoice->save();
644 644
     
645
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
645
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
646 646
 
647
-    if ( ! empty( $invoice->ID ) ) {
647
+    if (!empty($invoice->ID)) {
648 648
         // payment method (and payment_complete() if `paid` == true)
649
-        if ( !empty( $payment_details['paid'] ) ) {
649
+        if (!empty($payment_details['paid'])) {
650 650
             //$invoice->payment_complete( !empty( $payment_details['transaction_id'] ) ? $payment_details['transaction_id'] : $invoice->ID );
651 651
         }
652 652
             
@@ -663,158 +663,158 @@  discard block
 block discarded – undo
663 663
     }
664 664
     ?>
665 665
     <tr>
666
-        <td><?php _e( 'Merge Price Packages', 'invoicing' ); ?></td>
667
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing' ); ?></p></td>
668
-        <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
666
+        <td><?php _e('Merge Price Packages', 'invoicing'); ?></td>
667
+        <td><p><?php _e('Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing'); ?></p></td>
668
+        <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
669 669
     </tr>
670 670
     <tr>
671
-        <td><?php _e( 'Merge Invoices', 'invoicing' ); ?></td>
672
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing' ); ?></p></td>
673
-        <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
671
+        <td><?php _e('Merge Invoices', 'invoicing'); ?></td>
672
+        <td><p><?php _e('Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing'); ?></p></td>
673
+        <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
674 674
     </tr>
675 675
 	<tr>
676
-        <td><?php _e( 'Fix Taxes for Merged Invoices', 'invoicing' ); ?></td>
677
-        <td><p><?php _e( 'Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing' ); ?></p></td>
678
-        <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
676
+        <td><?php _e('Fix Taxes for Merged Invoices', 'invoicing'); ?></td>
677
+        <td><p><?php _e('Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing'); ?></p></td>
678
+        <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
679 679
     </tr>
680 680
     <tr>
681
-        <td><?php _e( 'Merge Coupons', 'invoicing' ); ?></td>
682
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing' ); ?></p></td>
683
-        <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
681
+        <td><?php _e('Merge Coupons', 'invoicing'); ?></td>
682
+        <td><p><?php _e('Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing'); ?></p></td>
683
+        <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
684 684
     </tr>
685 685
     <?php
686 686
 }
687
-add_action( 'wpinv_tools_row', 'wpinv_merge_gd_invoices', 10 );
687
+add_action('wpinv_tools_row', 'wpinv_merge_gd_invoices', 10);
688 688
 
689 689
 function wpinv_tool_merge_packages() {
690 690
     $packages = geodir_package_list_info();
691 691
     
692 692
     $count = 0;
693 693
     
694
-    if ( !empty( $packages ) ) {
694
+    if (!empty($packages)) {
695 695
         $success = true;
696 696
         
697
-        foreach ( $packages as $key => $package ) {
697
+        foreach ($packages as $key => $package) {
698 698
             $item = wpinv_get_item_by('package_id', $package->pid);
699
-            if ( !empty( $item ) ) {
699
+            if (!empty($item)) {
700 700
                 continue;
701 701
             }
702 702
             
703
-            $merged = wpinv_merge_gd_package_to_item( $package->pid, false, $package );
703
+            $merged = wpinv_merge_gd_package_to_item($package->pid, false, $package);
704 704
             
705
-            if ( !empty( $merged ) ) {
706
-                wpinv_error_log( 'Package merge S : ' . $package->pid );
705
+            if (!empty($merged)) {
706
+                wpinv_error_log('Package merge S : ' . $package->pid);
707 707
                 $count++;
708 708
             } else {
709
-                wpinv_error_log( 'Package merge F : ' . $package->pid );
709
+                wpinv_error_log('Package merge F : ' . $package->pid);
710 710
             }
711 711
         }
712 712
         
713
-        if ( $count > 0 ) {
714
-            $message = sprintf( _n( 'Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing' ), $count );
713
+        if ($count > 0) {
714
+            $message = sprintf(_n('Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing'), $count);
715 715
         } else {
716
-            $message = __( 'No price packages merged.', 'invoicing' );
716
+            $message = __('No price packages merged.', 'invoicing');
717 717
         }
718 718
     } else {
719 719
         $success = false;
720
-        $message = __( 'No price packages found to merge!', 'invoicing' );
720
+        $message = __('No price packages found to merge!', 'invoicing');
721 721
     }
722 722
     
723 723
     $response = array();
724 724
     $response['success'] = $success;
725 725
     $response['data']['message'] = $message;
726
-    wp_send_json( $response );
726
+    wp_send_json($response);
727 727
 }
728
-add_action( 'wpinv_tool_merge_packages', 'wpinv_tool_merge_packages' );
728
+add_action('wpinv_tool_merge_packages', 'wpinv_tool_merge_packages');
729 729
 
730 730
 function wpinv_tool_merge_invoices() {
731 731
     global $wpdb, $wpi_gdp_inv_merge, $wpi_tax_rates;
732 732
     
733 733
     $sql = "SELECT `gdi`.`id`, `gdi`.`date`, `gdi`.`date_updated` FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NULL ORDER BY `gdi`.`id` ASC";
734
-    $items = $wpdb->get_results( $sql );
734
+    $items = $wpdb->get_results($sql);
735 735
     
736 736
     $count = 0;
737 737
     
738
-    if ( !empty( $items ) ) {
738
+    if (!empty($items)) {
739 739
         $success = true;
740 740
         $wpi_gdp_inv_merge = true;
741 741
         
742
-        foreach ( $items as $item ) {
742
+        foreach ($items as $item) {
743 743
             $wpi_tax_rates = NULL;
744 744
             
745
-            $wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'" );
745
+            $wpdb->query("UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'");
746 746
             
747
-            $merged = wpinv_cpt_save( $item->id );
747
+            $merged = wpinv_cpt_save($item->id);
748 748
             
749
-            if ( !empty( $merged ) && !empty( $merged->ID ) ) {
749
+            if (!empty($merged) && !empty($merged->ID)) {
750 750
                 $count++;
751 751
                 
752 752
                 //$wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = '" . $merged->ID . "' WHERE id = '" . $item->id . "'" );
753 753
                 
754
-                $post_date = !empty( $item->date ) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time( 'mysql' );
755
-                $post_date_gmt = get_gmt_from_date( $post_date );
756
-                $post_modified = !empty( $item->date_updated ) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date;
757
-                $post_modified_gmt = get_gmt_from_date( $post_modified );
754
+                $post_date = !empty($item->date) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time('mysql');
755
+                $post_date_gmt = get_gmt_from_date($post_date);
756
+                $post_modified = !empty($item->date_updated) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date;
757
+                $post_modified_gmt = get_gmt_from_date($post_modified);
758 758
                 
759
-                $wpdb->update( $wpdb->posts, array( 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt ), array( 'ID' => $merged->ID ) );
759
+                $wpdb->update($wpdb->posts, array('post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt), array('ID' => $merged->ID));
760 760
                 
761
-                if ( $merged->is_paid() ) {
762
-                    update_post_meta( $merged->ID, '_wpinv_completed_date', $post_modified );
761
+                if ($merged->is_paid()) {
762
+                    update_post_meta($merged->ID, '_wpinv_completed_date', $post_modified);
763 763
                 }
764 764
                 
765
-                clean_post_cache( $merged->ID );
765
+                clean_post_cache($merged->ID);
766 766
                 
767
-                wpinv_error_log( 'Invoice merge S : ' . $item->id . ' => ' . $merged->ID );
767
+                wpinv_error_log('Invoice merge S : ' . $item->id . ' => ' . $merged->ID);
768 768
             } else {
769
-                wpinv_error_log( 'Invoice merge F : ' . $item->id );
769
+                wpinv_error_log('Invoice merge F : ' . $item->id);
770 770
             }
771 771
         }
772 772
         
773 773
         $wpi_gdp_inv_merge = false;
774 774
         
775
-        if ( $count > 0 ) {
776
-            $message = sprintf( _n( 'Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing' ), $count );
775
+        if ($count > 0) {
776
+            $message = sprintf(_n('Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing'), $count);
777 777
         } else {
778
-            $message = __( 'No invoices merged.', 'invoicing' );
778
+            $message = __('No invoices merged.', 'invoicing');
779 779
         }
780 780
     } else {
781 781
         $success = false;
782
-        $message = __( 'No invoices found to merge!', 'invoicing' );
782
+        $message = __('No invoices found to merge!', 'invoicing');
783 783
     }
784 784
     
785 785
     $response = array();
786 786
     $response['success'] = $success;
787 787
     $response['data']['message'] = $message;
788
-    wp_send_json( $response );
788
+    wp_send_json($response);
789 789
 }
790
-add_action( 'wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices' );
790
+add_action('wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices');
791 791
 
792 792
 function wpinv_tool_merge_coupons() {
793 793
     global $wpdb;
794 794
     
795 795
     $sql = "SELECT * FROM `" . COUPON_TABLE . "` WHERE `coupon_code` IS NOT NULL AND `coupon_code` != '' ORDER BY `cid` ASC";
796
-    $items = $wpdb->get_results( $sql );
796
+    $items = $wpdb->get_results($sql);
797 797
     $count = 0;
798 798
     
799
-    if ( !empty( $items ) ) {
799
+    if (!empty($items)) {
800 800
         $success = true;
801 801
         
802
-        foreach ( $items as $item ) {
803
-            if ( wpinv_get_discount_by_code( $item->coupon_code ) ) {
802
+        foreach ($items as $item) {
803
+            if (wpinv_get_discount_by_code($item->coupon_code)) {
804 804
                 continue;
805 805
             }
806 806
             
807 807
             $args = array(
808 808
                 'post_type'   => 'wpi_discount',
809 809
                 'post_title'  => $item->coupon_code,
810
-                'post_status' => !empty( $item->status ) ? 'publish' : 'pending'
810
+                'post_status' => !empty($item->status) ? 'publish' : 'pending'
811 811
             );
812 812
 
813
-            $merged = wp_insert_post( $args );
813
+            $merged = wp_insert_post($args);
814 814
             
815 815
             $item_id = $item->cid;
816 816
             
817
-            if ( $merged ) {
817
+            if ($merged) {
818 818
                 $meta = array(
819 819
                     'code'              => $item->coupon_code,
820 820
                     'type'              => $item->discount_type != 'per' ? 'flat' : 'percent',
@@ -822,65 +822,65 @@  discard block
 block discarded – undo
822 822
                     'max_uses'          => (int)$item->usage_limit,
823 823
                     'uses'              => (int)$item->usage_count,
824 824
                 );
825
-                wpinv_store_discount( $merged, $meta, get_post( $merged ) );
825
+                wpinv_store_discount($merged, $meta, get_post($merged));
826 826
                 
827 827
                 $count++;
828 828
                 
829
-                wpinv_error_log( 'Coupon merge S : ' . $item_id . ' => ' . $merged );
829
+                wpinv_error_log('Coupon merge S : ' . $item_id . ' => ' . $merged);
830 830
             } else {
831
-                wpinv_error_log( 'Coupon merge F : ' . $item_id );
831
+                wpinv_error_log('Coupon merge F : ' . $item_id);
832 832
             }
833 833
         }
834 834
         
835
-        if ( $count > 0 ) {
836
-            $message = sprintf( _n( 'Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing' ), $count );
835
+        if ($count > 0) {
836
+            $message = sprintf(_n('Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing'), $count);
837 837
         } else {
838
-            $message = __( 'No coupons merged.', 'invoicing' );
838
+            $message = __('No coupons merged.', 'invoicing');
839 839
         }
840 840
     } else {
841 841
         $success = false;
842
-        $message = __( 'No coupons found to merge!', 'invoicing' );
842
+        $message = __('No coupons found to merge!', 'invoicing');
843 843
     }
844 844
     
845 845
     $response = array();
846 846
     $response['success'] = $success;
847 847
     $response['data']['message'] = $message;
848
-    wp_send_json( $response );
848
+    wp_send_json($response);
849 849
 }
850
-add_action( 'wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons' );
850
+add_action('wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons');
851 851
 
852
-function wpinv_gdp_to_wpi_currency( $value, $option = '' ) {
852
+function wpinv_gdp_to_wpi_currency($value, $option = '') {
853 853
     return wpinv_get_currency();
854 854
 }
855
-add_filter( 'pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2 );
855
+add_filter('pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2);
856 856
 
857
-function wpinv_gdp_to_wpi_currency_sign( $value, $option = '' ) {
857
+function wpinv_gdp_to_wpi_currency_sign($value, $option = '') {
858 858
     return wpinv_currency_symbol();
859 859
 }
860
-add_filter( 'pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2 );
860
+add_filter('pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2);
861 861
 
862
-function wpinv_gdp_to_wpi_display_price( $price, $amount, $display = true , $decimal_sep, $thousand_sep ) {
863
-    if ( !$display ) {
864
-        $price = wpinv_round_amount( $amount );
862
+function wpinv_gdp_to_wpi_display_price($price, $amount, $display = true, $decimal_sep, $thousand_sep) {
863
+    if (!$display) {
864
+        $price = wpinv_round_amount($amount);
865 865
     } else {
866
-        $price = wpinv_price( wpinv_format_amount( $amount ) );
866
+        $price = wpinv_price(wpinv_format_amount($amount));
867 867
     }
868 868
     
869 869
     return $price;
870 870
 }
871
-add_filter( 'geodir_payment_price' , 'wpinv_gdp_to_wpi_display_price', 10000, 5 );
871
+add_filter('geodir_payment_price', 'wpinv_gdp_to_wpi_display_price', 10000, 5);
872 872
 
873
-function wpinv_gdp_to_inv_checkout_redirect( $redirect_url ) {
873
+function wpinv_gdp_to_inv_checkout_redirect($redirect_url) {
874 874
     $invoice_id         = geodir_payment_cart_id();
875
-    $invoice_info       = geodir_get_invoice( $invoice_id );
876
-    $wpi_invoice        = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL;
875
+    $invoice_info       = geodir_get_invoice($invoice_id);
876
+    $wpi_invoice        = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL;
877 877
     
878
-    if ( !( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) ) {
879
-        $wpi_invoice_id = wpinv_cpt_save( $invoice_id );
880
-        $wpi_invoice    = wpinv_get_invoice( $wpi_invoice_id );
878
+    if (!(!empty($wpi_invoice) && !empty($wpi_invoice->ID))) {
879
+        $wpi_invoice_id = wpinv_cpt_save($invoice_id);
880
+        $wpi_invoice    = wpinv_get_invoice($wpi_invoice_id);
881 881
     }
882 882
     
883
-    if ( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) {
883
+    if (!empty($wpi_invoice) && !empty($wpi_invoice->ID)) {
884 884
         
885 885
         // Clear cart
886 886
         geodir_payment_clear_cart();
@@ -890,121 +890,121 @@  discard block
 block discarded – undo
890 890
     
891 891
     return $redirect_url;
892 892
 }
893
-add_filter( 'geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1 );
893
+add_filter('geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1);
894 894
 
895
-function wpinv_gdp_dashboard_invoice_history_link( $dashboard_links ) {    
896
-    if ( get_current_user_id() ) {        
897
-        $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url( wpinv_get_history_page_uri() ) . '">' . __( 'My Invoice History', 'invoicing' ) . '</a></li>';
895
+function wpinv_gdp_dashboard_invoice_history_link($dashboard_links) {    
896
+    if (get_current_user_id()) {        
897
+        $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url(wpinv_get_history_page_uri()) . '">' . __('My Invoice History', 'invoicing') . '</a></li>';
898 898
     }
899 899
 
900 900
     return $dashboard_links;
901 901
 }
902
-add_action( 'geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link' );
903
-remove_action( 'geodir_dashboard_links', 'geodir_payment_invoices_list_page_link' );
902
+add_action('geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link');
903
+remove_action('geodir_dashboard_links', 'geodir_payment_invoices_list_page_link');
904 904
 
905
-function wpinv_wpi_to_gdp_update_status( $invoice_id, $new_status, $old_status ) {
905
+function wpinv_wpi_to_gdp_update_status($invoice_id, $new_status, $old_status) {
906 906
     if (!defined('GEODIRPAYMENT_VERSION')) {
907 907
         return false;
908 908
     }
909 909
     
910
-    $invoice    = wpinv_get_invoice( $invoice_id );
911
-    if ( empty( $invoice ) ) {
910
+    $invoice = wpinv_get_invoice($invoice_id);
911
+    if (empty($invoice)) {
912 912
         return false;
913 913
     }
914 914
     
915
-    remove_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 );
915
+    remove_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4);
916 916
     
917
-    $invoice_id = wpinv_wpi_to_gdp_id( $invoice_id );
918
-    $new_status = wpinv_wpi_to_gdp_status( $new_status );
917
+    $invoice_id = wpinv_wpi_to_gdp_id($invoice_id);
918
+    $new_status = wpinv_wpi_to_gdp_status($new_status);
919 919
     
920
-    geodir_update_invoice_status( $invoice_id, $new_status, $invoice->is_recurring() );
920
+    geodir_update_invoice_status($invoice_id, $new_status, $invoice->is_recurring());
921 921
 }
922
-add_action( 'wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3 );
922
+add_action('wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3);
923 923
 
924
-function wpinv_gdp_to_wpi_delete_package( $gd_package_id ) {
925
-    $item = wpinv_get_item_by( 'package_id', $gd_package_id );
924
+function wpinv_gdp_to_wpi_delete_package($gd_package_id) {
925
+    $item = wpinv_get_item_by('package_id', $gd_package_id);
926 926
     
927
-    if ( !empty( $item ) ) {
928
-        wpinv_remove_item( $item, true );
927
+    if (!empty($item)) {
928
+        wpinv_remove_item($item, true);
929 929
     }
930 930
 }
931
-add_action( 'geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1 ) ;
931
+add_action('geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1);
932 932
 
933
-function wpinv_can_delete_package_item( $return, $post_id ) {
934
-    if ( $return && function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && $package_id = get_post_meta( $post_id, '_wpinv_package_id', true ) ) {
935
-        $gd_package = geodir_get_package_info_by_id( $package_id, '' );
933
+function wpinv_can_delete_package_item($return, $post_id) {
934
+    if ($return && function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && $package_id = get_post_meta($post_id, '_wpinv_package_id', true)) {
935
+        $gd_package = geodir_get_package_info_by_id($package_id, '');
936 936
         
937
-        if ( !empty( $gd_package ) ) {
937
+        if (!empty($gd_package)) {
938 938
             $return = false;
939 939
         }
940 940
     }
941 941
 
942 942
     return $return;
943 943
 }
944
-add_filter( 'wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2 );
944
+add_filter('wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2);
945 945
 
946
-function wpinv_package_item_classes( $classes, $class, $post_id ) {
946
+function wpinv_package_item_classes($classes, $class, $post_id) {
947 947
     global $typenow;
948 948
 
949
-    if ( $typenow == 'wpi_item' && in_array( 'wpi-gd-package', $classes ) ) {
950
-        if ( wpinv_item_in_use( $post_id ) ) {
949
+    if ($typenow == 'wpi_item' && in_array('wpi-gd-package', $classes)) {
950
+        if (wpinv_item_in_use($post_id)) {
951 951
             $classes[] = 'wpi-inuse-pkg';
952
-        } else if ( !( function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && geodir_get_package_info_by_id( (int)get_post_meta( $post_id, '_wpinv_package_id', true ), '' ) ) ) {
952
+        } else if (!(function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && geodir_get_package_info_by_id((int)get_post_meta($post_id, '_wpinv_package_id', true), ''))) {
953 953
             $classes[] = 'wpi-delete-pkg';
954 954
         }
955 955
     }
956 956
 
957 957
     return $classes;
958 958
 }
959
-add_filter( 'post_class', 'wpinv_package_item_classes', 10, 3 );
959
+add_filter('post_class', 'wpinv_package_item_classes', 10, 3);
960 960
 
961
-function wpinv_gdp_package_type_info( $post ) {
962
-    if ( wpinv_pm_active() ) {
963
-        ?><p class="wpi-m0"><?php _e( 'Package: GeoDirectory price packages items.', 'invoicing' );?></p>
961
+function wpinv_gdp_package_type_info($post) {
962
+    if (wpinv_pm_active()) {
963
+        ?><p class="wpi-m0"><?php _e('Package: GeoDirectory price packages items.', 'invoicing'); ?></p>
964 964
         <?php
965 965
     }
966 966
 }
967
-add_action( 'wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1 ) ;
967
+add_action('wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1);
968 968
 
969
-function wpinv_gdp_to_gdi_set_zero_tax( $is_taxable, $item_id, $country , $state ) {
969
+function wpinv_gdp_to_gdi_set_zero_tax($is_taxable, $item_id, $country, $state) {
970 970
     global $wpi_zero_tax;
971 971
 
972
-    if ( $wpi_zero_tax ) {
972
+    if ($wpi_zero_tax) {
973 973
         $is_taxable = false;
974 974
     }
975 975
 
976 976
     return $is_taxable;
977 977
 }
978
-add_action( 'wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4 ) ;
978
+add_action('wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4);
979 979
 
980 980
 function wpinv_tool_merge_fix_taxes() {
981 981
     global $wpdb;
982 982
     
983 983
 	$sql = "SELECT DISTINCT p.ID FROM `" . $wpdb->posts . "` AS p LEFT JOIN " . $wpdb->postmeta . " AS pm ON pm.post_id = p.ID WHERE p.post_type = 'wpi_item' AND pm.meta_key = '_wpinv_type' AND pm.meta_value = 'package'";
984
-	$items = $wpdb->get_results( $sql );
984
+	$items = $wpdb->get_results($sql);
985 985
 	
986
-	if ( !empty( $items ) ) {
987
-		foreach ( $items as $item ) {
988
-			if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) {
989
-				update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' );
986
+	if (!empty($items)) {
987
+		foreach ($items as $item) {
988
+			if (get_post_meta($item->ID, '_wpinv_vat_class', true) == '_exempt') {
989
+				update_post_meta($item->ID, '_wpinv_vat_class', '_standard');
990 990
 			}
991 991
 		}
992 992
 	}
993 993
 		
994 994
     $sql = "SELECT `p`.`ID`, gdi.id AS gdp_id FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NOT NULL AND p.post_status NOT IN( 'publish', 'wpi-processing', 'wpi-renewal' ) ORDER BY `gdi`.`id` ASC";
995
-    $items = $wpdb->get_results( $sql );
995
+    $items = $wpdb->get_results($sql);
996 996
 	
997
-	if ( !empty( $items ) ) {
997
+	if (!empty($items)) {
998 998
 		$success = false;
999
-        $message = __( 'Taxes fixed for non-paid merged GD invoices.', 'invoicing' );
999
+        $message = __('Taxes fixed for non-paid merged GD invoices.', 'invoicing');
1000 1000
 		
1001 1001
 		global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates;
1002 1002
 		
1003
-		foreach ( $items as $item ) {
1003
+		foreach ($items as $item) {
1004 1004
 			$wpi_tax_rates = NULL;               
1005 1005
 			$data = wpinv_get_invoice($item->ID);
1006 1006
 
1007
-			if ( empty( $data ) ) {
1007
+			if (empty($data)) {
1008 1008
 				continue;
1009 1009
 			}
1010 1010
 			
@@ -1012,51 +1012,51 @@  discard block
 block discarded – undo
1012 1012
 			
1013 1013
 			$data_session                   = array();
1014 1014
 			$data_session['invoice_id']     = $data->ID;
1015
-			$data_session['cart_discounts'] = $data->get_discounts( true );
1015
+			$data_session['cart_discounts'] = $data->get_discounts(true);
1016 1016
 			
1017
-			wpinv_set_checkout_session( $data_session );
1017
+			wpinv_set_checkout_session($data_session);
1018 1018
 			
1019 1019
 			$wpi_userID         = (int)$data->get_user_id();
1020 1020
 			$_POST['country']   = !empty($data->country) ? $data->country : wpinv_get_default_country();
1021 1021
 				
1022
-			$data->country      = sanitize_text_field( $_POST['country'] );
1023
-			$data->set( 'country', sanitize_text_field( $_POST['country'] ) );
1022
+			$data->country      = sanitize_text_field($_POST['country']);
1023
+			$data->set('country', sanitize_text_field($_POST['country']));
1024 1024
 			
1025 1025
 			$wpinv_ip_address_country = $data->country;
1026 1026
 			
1027 1027
 			$data->recalculate_totals(true);
1028 1028
 			
1029
-			wpinv_set_checkout_session( $checkout_session );
1029
+			wpinv_set_checkout_session($checkout_session);
1030 1030
 			
1031 1031
 			$update_data = array();
1032 1032
 			$update_data['tax_amount'] = $data->get_tax();
1033 1033
 			$update_data['paied_amount'] = $data->get_total();
1034 1034
 			$update_data['invoice_id'] = $data->ID;
1035 1035
 			
1036
-			$wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) );
1036
+			$wpdb->update(INVOICE_TABLE, $update_data, array('id' => $item->gdp_id));
1037 1037
 		}
1038 1038
 	} else {
1039 1039
         $success = false;
1040
-        $message = __( 'No invoices found to fix taxes!', 'invoicing' );
1040
+        $message = __('No invoices found to fix taxes!', 'invoicing');
1041 1041
     }
1042 1042
 	
1043 1043
 	$response = array();
1044 1044
     $response['success'] = $success;
1045 1045
     $response['data']['message'] = $message;
1046
-    wp_send_json( $response );
1046
+    wp_send_json($response);
1047 1047
 }
1048
-add_action( 'wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes' );
1049
-remove_action( 'geodir_before_detail_fields' , 'geodir_build_coupon', 2 );
1048
+add_action('wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes');
1049
+remove_action('geodir_before_detail_fields', 'geodir_build_coupon', 2);
1050 1050
 
1051
-function wpinv_wpi_to_gdp_handle_subscription_cancel( $invoice_id, $invoice ) {
1052
-    if ( wpinv_pm_active() && !empty( $invoice ) && $invoice->is_recurring() ) {
1053
-        if ( $invoice->is_renewal() ) {
1051
+function wpinv_wpi_to_gdp_handle_subscription_cancel($invoice_id, $invoice) {
1052
+    if (wpinv_pm_active() && !empty($invoice) && $invoice->is_recurring()) {
1053
+        if ($invoice->is_renewal()) {
1054 1054
             $invoice = $invoice->get_parent_payment();
1055 1055
         }
1056 1056
         
1057
-        if ( !empty( $invoice ) ) {
1058
-            wpinv_wpi_to_gdp_update_status( $invoice->ID, 'wpi-cancelled', $invoice->get_status() );
1057
+        if (!empty($invoice)) {
1058
+            wpinv_wpi_to_gdp_update_status($invoice->ID, 'wpi-cancelled', $invoice->get_status());
1059 1059
         }
1060 1060
     }
1061 1061
 }
1062
-add_action( 'wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2 );
1063 1062
\ No newline at end of file
1063
+add_action('wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2);
1064 1064
\ No newline at end of file
Please login to merge, or discard this patch.