Passed
Pull Request — master (#47)
by Kiran
04:02
created
includes/admin/class-wpinv-subscriptions-list-table.php 1 patch
Spacing   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@  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
 
6 6
 // Load WP_List_Table if not loaded
7
-if ( ! class_exists( 'WP_List_Table' ) ) {
7
+if (!class_exists('WP_List_Table')) {
8 8
     require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
9 9
 }
10 10
 
@@ -26,14 +26,14 @@  discard block
 block discarded – undo
26 26
     public $stopped_count   = 0;
27 27
     public $trialling_count = 0;
28 28
 
29
-    function __construct(){
29
+    function __construct() {
30 30
         global $status, $page;
31 31
 
32
-        parent::__construct( array(
32
+        parent::__construct(array(
33 33
             'singular'  => 'subscription',
34 34
             'plural'    => 'subscriptions',
35 35
             'ajax'      => false
36
-        ) );
36
+        ));
37 37
 
38 38
         $this->get_subscription_counts();
39 39
 
@@ -48,28 +48,28 @@  discard block
 block discarded – undo
48 48
      */
49 49
     public function get_views() {
50 50
 
51
-        $current         = isset( $_GET['status'] ) ? $_GET['status'] : '';
52
-        $total_count     = '&nbsp;<span class="count">(' . $this->total_count    . ')</span>';
51
+        $current         = isset($_GET['status']) ? $_GET['status'] : '';
52
+        $total_count     = '&nbsp;<span class="count">(' . $this->total_count . ')</span>';
53 53
         $active_count    = '&nbsp;<span class="count">(' . $this->active_count . ')</span>';
54 54
         $pending_count   = '&nbsp;<span class="count">(' . $this->pending_count . ')</span>';
55
-        $expired_count   = '&nbsp;<span class="count">(' . $this->expired_count  . ')</span>';
55
+        $expired_count   = '&nbsp;<span class="count">(' . $this->expired_count . ')</span>';
56 56
         $completed_count = '&nbsp;<span class="count">(' . $this->completed_count . ')</span>';
57
-        $trialling_count  = '&nbsp;<span class="count">(' . $this->trialling_count   . ')</span>';
58
-        $cancelled_count = '&nbsp;<span class="count">(' . $this->cancelled_count   . ')</span>';
59
-        $failing_count   = '&nbsp;<span class="count">(' . $this->failing_count   . ')</span>';
57
+        $trialling_count = '&nbsp;<span class="count">(' . $this->trialling_count . ')</span>';
58
+        $cancelled_count = '&nbsp;<span class="count">(' . $this->cancelled_count . ')</span>';
59
+        $failing_count   = '&nbsp;<span class="count">(' . $this->failing_count . ')</span>';
60 60
 
61 61
         $views = array(
62
-            'all'       => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','easy-digital-downloads' ) . $total_count ),
63
-            'active'    => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','easy-digital-downloads' ) . $active_count ),
64
-            'pending'   => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','easy-digital-downloads' ) . $pending_count ),
65
-            'expired'   => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','easy-digital-downloads' ) . $expired_count ),
66
-            'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','easy-digital-downloads' ) . $completed_count ),
67
-            'trialling'  => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','easy-digital-downloads' ) . $trialling_count ),
68
-            'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','easy-digital-downloads' ) . $cancelled_count ),
69
-            'failing'   => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','easy-digital-downloads' ) . $failing_count ),
62
+            'all'       => sprintf('<a href="%s"%s>%s</a>', remove_query_arg(array('status', 'paged')), $current === 'all' || $current == '' ? ' class="current"' : '', __('All', 'easy-digital-downloads') . $total_count),
63
+            'active'    => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'active', 'paged' => FALSE)), $current === 'active' ? ' class="current"' : '', __('Active', 'easy-digital-downloads') . $active_count),
64
+            'pending'   => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'pending', 'paged' => FALSE)), $current === 'pending' ? ' class="current"' : '', __('Pending', 'easy-digital-downloads') . $pending_count),
65
+            'expired'   => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'expired', 'paged' => FALSE)), $current === 'expired' ? ' class="current"' : '', __('Expired', 'easy-digital-downloads') . $expired_count),
66
+            'completed' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'completed', 'paged' => FALSE)), $current === 'completed' ? ' class="current"' : '', __('Completed', 'easy-digital-downloads') . $completed_count),
67
+            'trialling'  => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'trialling', 'paged' => FALSE)), $current === 'trialling' ? ' class="current"' : '', __('Trialling', 'easy-digital-downloads') . $trialling_count),
68
+            'cancelled' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'cancelled', 'paged' => FALSE)), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled', 'easy-digital-downloads') . $cancelled_count),
69
+            'failing'   => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'failing', 'paged' => FALSE)), $current === 'failing' ? ' class="current"' : '', __('Failing', 'easy-digital-downloads') . $failing_count),
70 70
         );
71 71
 
72
-        return apply_filters( 'edd_recurring_subscriptions_table_views', $views );
72
+        return apply_filters('edd_recurring_subscriptions_table_views', $views);
73 73
     }
74 74
 
75 75
     /**
@@ -83,27 +83,27 @@  discard block
 block discarded – undo
83 83
      *
84 84
      * @return void
85 85
      */
86
-    public function search_box( $text, $input_id ) {
86
+    public function search_box($text, $input_id) {
87 87
 
88
-        if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) {
88
+        if (empty($_REQUEST['s']) && !$this->has_items()) {
89 89
             return;
90 90
         }
91 91
 
92 92
         $input_id = $input_id . '-search-input';
93 93
 
94
-        if ( ! empty( $_REQUEST['orderby'] ) ) {
95
-            echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
94
+        if (!empty($_REQUEST['orderby'])) {
95
+            echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />';
96 96
         }
97 97
 
98
-        if ( ! empty( $_REQUEST['order'] ) ) {
99
-            echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
98
+        if (!empty($_REQUEST['order'])) {
99
+            echo '<input type="hidden" name="order" value="' . esc_attr($_REQUEST['order']) . '" />';
100 100
         }
101 101
     ?>
102 102
         <p class="search-box">
103
-            <?php do_action( 'edd_recurring_subscription_search_box' ); ?>
103
+            <?php do_action('edd_recurring_subscription_search_box'); ?>
104 104
             <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
105 105
             <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
106
-            <?php submit_button( $text, 'button', false, false, array('ID' => 'search-submit') ); ?><br/>
106
+            <?php submit_button($text, 'button', false, false, array('ID' => 'search-submit')); ?><br/>
107 107
         </p>
108 108
     <?php
109 109
     }
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
      * @since       2.4
116 116
      * @return      string
117 117
      */
118
-    function column_default( $item, $column_name ) {
118
+    function column_default($item, $column_name) {
119 119
         return $item->$column_name;
120 120
     }
121 121
 
@@ -126,11 +126,11 @@  discard block
 block discarded – undo
126 126
      * @since       2.4
127 127
      * @return      string
128 128
      */
129
-    function column_customer_id( $item ) {
130
-        $subscriber = new EDD_Recurring_Subscriber( $item->customer_id );
131
-        $customer   = ! empty( $subscriber->name ) ? $subscriber->name : $subscriber->email;
129
+    function column_customer_id($item) {
130
+        $subscriber = new EDD_Recurring_Subscriber($item->customer_id);
131
+        $customer   = !empty($subscriber->name) ? $subscriber->name : $subscriber->email;
132 132
 
133
-        return '<a href="' . esc_url( admin_url( 'edit.php?post_type=download&page=edd-customers&view=overview&id=' . $subscriber->id ) ) . '">' . $customer . '</a>';
133
+        return '<a href="' . esc_url(admin_url('edit.php?post_type=download&page=edd-customers&view=overview&id=' . $subscriber->id)) . '">' . $customer . '</a>';
134 134
     }
135 135
 
136 136
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      * @since       2.4
142 142
      * @return      string
143 143
      */
144
-    function column_status( $item ) {
144
+    function column_status($item) {
145 145
         return $item->get_status_label();
146 146
     }
147 147
 
@@ -152,11 +152,11 @@  discard block
 block discarded – undo
152 152
      * @since       2.4
153 153
      * @return      string
154 154
      */
155
-    function column_period( $item ) {
155
+    function column_period($item) {
156 156
 
157
-        $period = EDD_Recurring()->get_pretty_subscription_frequency( $item->period,$item->frequency );
157
+        $period = EDD_Recurring()->get_pretty_subscription_frequency($item->period, $item->frequency);
158 158
 
159
-        return edd_currency_filter( edd_format_amount( $item->recurring_amount ), edd_get_payment_currency_code( $item->parent_payment_id ) ) . ' / ' . $period;
159
+        return edd_currency_filter(edd_format_amount($item->recurring_amount), edd_get_payment_currency_code($item->parent_payment_id)) . ' / ' . $period;
160 160
     }
161 161
 
162 162
     /**
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
      * @since       2.4
167 167
      * @return      string
168 168
      */
169
-    function column_bill_times( $item ) {
170
-        return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? 'Until Cancelled' : $item->bill_times );
169
+    function column_bill_times($item) {
170
+        return $item->get_times_billed() . ' / ' . (($item->bill_times == 0) ? 'Until Cancelled' : $item->bill_times);
171 171
     }
172 172
 
173 173
     /**
@@ -177,8 +177,8 @@  discard block
 block discarded – undo
177 177
      * @since       2.4
178 178
      * @return      string
179 179
      */
180
-    function column_initial_amount( $item ) {
181
-        return edd_currency_filter( edd_format_amount( $item->initial_amount ), edd_get_payment_currency_code( $item->parent_payment_id ) );
180
+    function column_initial_amount($item) {
181
+        return edd_currency_filter(edd_format_amount($item->initial_amount), edd_get_payment_currency_code($item->parent_payment_id));
182 182
     }
183 183
 
184 184
     /**
@@ -188,8 +188,8 @@  discard block
 block discarded – undo
188 188
      * @since       2.4
189 189
      * @return      string
190 190
      */
191
-    function column_renewal_date( $item ) {
192
-        return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'edd-recurring' );
191
+    function column_renewal_date($item) {
192
+        return $renewal_date = !empty($item->expiration) ? date_i18n(get_option('date_format'), strtotime($item->expiration)) : __('N/A', 'edd-recurring');
193 193
     }
194 194
 
195 195
     /**
@@ -199,8 +199,8 @@  discard block
 block discarded – undo
199 199
      * @since       2.4
200 200
      * @return      string
201 201
      */
202
-    function column_parent_payment_id( $item ) {
203
-        return '<a href="' . esc_url( admin_url( 'edit.php?post_type=download&page=edd-payment-history&view=view-order-details&id=' . $item->parent_payment_id ) ) . '">' . edd_get_payment_number( $item->parent_payment_id ) . '</a>';
202
+    function column_parent_payment_id($item) {
203
+        return '<a href="' . esc_url(admin_url('edit.php?post_type=download&page=edd-payment-history&view=view-order-details&id=' . $item->parent_payment_id)) . '">' . edd_get_payment_number($item->parent_payment_id) . '</a>';
204 204
     }
205 205
 
206 206
     /**
@@ -210,8 +210,8 @@  discard block
 block discarded – undo
210 210
      * @since       2.4
211 211
      * @return      string
212 212
      */
213
-    function column_product_id( $item ) {
214
-        return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '">' . get_the_title( $item->product_id ) . '</a>';
213
+    function column_product_id($item) {
214
+        return '<a href="' . esc_url(admin_url('post.php?action=edit&post=' . $item->product_id)) . '">' . get_the_title($item->product_id) . '</a>';
215 215
     }
216 216
 
217 217
     /**
@@ -221,8 +221,8 @@  discard block
 block discarded – undo
221 221
      * @since       2.0
222 222
      * @return      string
223 223
      */
224
-    function column_actions( $item ) {
225
-        return '<a href="' . esc_url( admin_url( 'edit.php?post_type=download&page=edd-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'edd-recurring' ) ) . '">' . __( 'View', 'edd-recurring' ) . '</a>';
224
+    function column_actions($item) {
225
+        return '<a href="' . esc_url(admin_url('edit.php?post_type=download&page=edd-subscriptions&id=' . $item->id)) . '" title="' . esc_attr(__('View or edit subscription', 'edd-recurring')) . '">' . __('View', 'edd-recurring') . '</a>';
226 226
     }
227 227
 
228 228
 
@@ -234,20 +234,20 @@  discard block
 block discarded – undo
234 234
      * @return      array
235 235
      */
236 236
 
237
-    function get_columns(){
237
+    function get_columns() {
238 238
         $columns = array(
239
-            'customer_id'       => __( 'Customer', 'edd-recurring' ),
240
-            'status'            => __( 'Status', 'edd-recurring' ),
241
-            'period'            => __( 'Billing Cycle', 'edd-recurring' ),
242
-            'initial_amount'    => __( 'Initial Amount', 'edd-recurring' ),
243
-            'bill_times'        => __( 'Times Billed', 'edd-recurring' ),
244
-            'renewal_date'      => __( 'Renewal Date', 'edd-recurring' ),
245
-            'parent_payment_id' => __( 'Payment', 'edd-recurring' ),
239
+            'customer_id'       => __('Customer', 'edd-recurring'),
240
+            'status'            => __('Status', 'edd-recurring'),
241
+            'period'            => __('Billing Cycle', 'edd-recurring'),
242
+            'initial_amount'    => __('Initial Amount', 'edd-recurring'),
243
+            'bill_times'        => __('Times Billed', 'edd-recurring'),
244
+            'renewal_date'      => __('Renewal Date', 'edd-recurring'),
245
+            'parent_payment_id' => __('Payment', 'edd-recurring'),
246 246
             'product_id'        => edd_get_label_singular(),
247
-            'actions'           => __( 'Actions', 'edd-recurring' ),
247
+            'actions'           => __('Actions', 'edd-recurring'),
248 248
         );
249 249
 
250
-        return apply_filters( 'edd_report_subscription_columns', $columns );
250
+        return apply_filters('edd_report_subscription_columns', $columns);
251 251
     }
252 252
 
253 253
     /**
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      * @return      int
259 259
      */
260 260
     function get_paged() {
261
-        return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
261
+        return isset($_GET['paged']) ? absint($_GET['paged']) : 1;
262 262
     }
263 263
 
264 264
     public function get_subscription_counts() {
@@ -267,16 +267,16 @@  discard block
 block discarded – undo
267 267
 
268 268
         $db = new EDD_Subscriptions_DB;
269 269
 
270
-        $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : '';
270
+        $search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : '';
271 271
 
272 272
         $this->total_count     = $db->count();
273
-        $this->active_count    = $db->count( array( 'status' => 'active', 'search' => $search ) );
274
-        $this->pending_count   = $db->count( array( 'status' => 'pending', 'search' => $search ) );
275
-        $this->expired_count   = $db->count( array( 'status' => 'expired', 'search' => $search ) );
276
-        $this->trialling_count  = $db->count( array( 'status' => 'trialling', 'search' => $search ) );
277
-        $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) );
278
-        $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) );
279
-        $this->failing_count   = $db->count( array( 'status' => 'failing', 'search' => $search ) );
273
+        $this->active_count    = $db->count(array('status' => 'active', 'search' => $search));
274
+        $this->pending_count   = $db->count(array('status' => 'pending', 'search' => $search));
275
+        $this->expired_count   = $db->count(array('status' => 'expired', 'search' => $search));
276
+        $this->trialling_count = $db->count(array('status' => 'trialling', 'search' => $search));
277
+        $this->cancelled_count = $db->count(array('status' => 'cancelled', 'search' => $search));
278
+        $this->completed_count = $db->count(array('status' => 'completed', 'search' => $search));
279
+        $this->failing_count   = $db->count(array('status' => 'failing', 'search' => $search));
280 280
     }
281 281
 
282 282
     /**
@@ -296,28 +296,28 @@  discard block
 block discarded – undo
296 296
 
297 297
         $columns  = $this->get_columns();
298 298
         $hidden   = array(); // No hidden columns
299
-        $status   = isset( $_GET['status'] ) ? $_GET['status'] : 'any';
299
+        $status   = isset($_GET['status']) ? $_GET['status'] : 'any';
300 300
         $sortable = $this->get_sortable_columns();
301 301
 
302
-        $this->_column_headers = array( $columns, $hidden, $sortable );
302
+        $this->_column_headers = array($columns, $hidden, $sortable);
303 303
 
304 304
         $current_page = $this->get_pagenum();
305 305
 
306 306
         $db     = new EDD_Subscriptions_DB;
307
-        $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : '';
307
+        $search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : '';
308 308
         $args   = array(
309 309
             'number' => $this->per_page,
310
-            'offset' => $this->per_page * ( $this->get_paged() - 1 ),
310
+            'offset' => $this->per_page * ($this->get_paged() - 1),
311 311
             'search' => $search
312 312
         );
313 313
 
314
-        if ( 'any' !== $status ) {
314
+        if ('any' !== $status) {
315 315
             $args['status'] = $status;
316 316
         }
317 317
 
318
-        $this->items = $db->get_subscriptions( $args );
318
+        $this->items = $db->get_subscriptions($args);
319 319
 
320
-        switch ( $status ) {
320
+        switch ($status) {
321 321
             case 'active':
322 322
                 $total_items = $this->active_count;
323 323
                 break;
@@ -345,10 +345,10 @@  discard block
 block discarded – undo
345 345
                 break;
346 346
         }
347 347
 
348
-        $this->set_pagination_args( array(
348
+        $this->set_pagination_args(array(
349 349
             'total_items' => $total_items,
350 350
             'per_page'    => $this->per_page,
351
-            'total_pages' => ceil( $total_items / $this->per_page )
352
-        ) );
351
+            'total_pages' => ceil($total_items / $this->per_page)
352
+        ));
353 353
     }
354 354
 }
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Spacing   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -7,28 +7,28 @@  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_Ajax {
15 15
     public static function init() {
16
-        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
17
-        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
16
+        add_action('init', array(__CLASS__, 'define_ajax'), 0);
17
+        add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
18 18
         self::add_ajax_events();
19 19
     }
20 20
 
21 21
     public static function define_ajax() {
22
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
23
-            if ( ! defined( 'DOING_AJAX' ) ) {
24
-                define( 'DOING_AJAX', true );
22
+        if (!empty($_GET['wpinv-ajax'])) {
23
+            if (!defined('DOING_AJAX')) {
24
+                define('DOING_AJAX', true);
25 25
             }
26
-            if ( ! defined( 'WC_DOING_AJAX' ) ) {
27
-                define( 'WC_DOING_AJAX', true );
26
+            if (!defined('WC_DOING_AJAX')) {
27
+                define('WC_DOING_AJAX', true);
28 28
             }
29 29
             // Turn off display_errors during AJAX events to prevent malformed JSON
30
-            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
31
-                @ini_set( 'display_errors', 0 );
30
+            if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
31
+                @ini_set('display_errors', 0);
32 32
             }
33 33
             $GLOBALS['wpdb']->hide_errors();
34 34
         }
@@ -37,24 +37,24 @@  discard block
 block discarded – undo
37 37
     public static function do_wpinv_ajax() {
38 38
         global $wp_query;
39 39
 
40
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
41
-            $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) );
40
+        if (!empty($_GET['wpinv-ajax'])) {
41
+            $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax']));
42 42
         }
43 43
 
44
-        if ( $action = $wp_query->get( 'wpinv-ajax' ) ) {
44
+        if ($action = $wp_query->get('wpinv-ajax')) {
45 45
             self::wpinv_ajax_headers();
46
-            do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) );
46
+            do_action('wpinv_ajax_' . sanitize_text_field($action));
47 47
             die();
48 48
         }
49 49
     }
50 50
     
51 51
     private static function wpinv_ajax_headers() {
52 52
         send_origin_headers();
53
-        @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
54
-        @header( 'X-Robots-Tag: noindex' );
53
+        @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
54
+        @header('X-Robots-Tag: noindex');
55 55
         send_nosniff_header();
56 56
         nocache_headers();
57
-        status_header( 200 );
57
+        status_header(200);
58 58
     }
59 59
     
60 60
     public static function add_ajax_events() {
@@ -76,39 +76,39 @@  discard block
 block discarded – undo
76 76
             'remove_discount' => false,
77 77
         );
78 78
 
79
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
80
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
79
+        foreach ($ajax_events as $ajax_event => $nopriv) {
80
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
81 81
             
82
-            if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) {
83
-                define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 );
82
+            if (!defined('WPI_AJAX_' . strtoupper($nopriv))) {
83
+                define('WPI_AJAX_' . strtoupper($nopriv), 1);
84 84
             }
85 85
 
86
-            if ( $nopriv ) {
87
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
86
+            if ($nopriv) {
87
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
88 88
 
89
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
89
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
90 90
             }
91 91
         }
92 92
     }
93 93
     
94 94
     public static function add_note() {
95
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
95
+        check_ajax_referer('add-invoice-note', '_nonce');
96 96
 
97
-        if ( !current_user_can( 'manage_options' ) ) {
97
+        if (!current_user_can('manage_options')) {
98 98
             die(-1);
99 99
         }
100 100
 
101
-        $post_id   = absint( $_POST['post_id'] );
102
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
103
-        $note_type = sanitize_text_field( $_POST['note_type'] );
101
+        $post_id   = absint($_POST['post_id']);
102
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
103
+        $note_type = sanitize_text_field($_POST['note_type']);
104 104
 
105 105
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
106 106
 
107
-        if ( $post_id > 0 ) {
108
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
107
+        if ($post_id > 0) {
108
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
109 109
 
110
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
111
-                wpinv_get_invoice_note_line_item( $note_id );
110
+            if ($note_id > 0 && !is_wp_error($note_id)) {
111
+                wpinv_get_invoice_note_line_item($note_id);
112 112
             }
113 113
         }
114 114
 
@@ -116,16 +116,16 @@  discard block
 block discarded – undo
116 116
     }
117 117
 
118 118
     public static function delete_note() {
119
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
119
+        check_ajax_referer('delete-invoice-note', '_nonce');
120 120
 
121
-        if ( !current_user_can( 'manage_options' ) ) {
121
+        if (!current_user_can('manage_options')) {
122 122
             die(-1);
123 123
         }
124 124
 
125 125
         $note_id = (int)$_POST['note_id'];
126 126
 
127
-        if ( $note_id > 0 ) {
128
-            wp_delete_comment( $note_id, true );
127
+        if ($note_id > 0) {
128
+            wp_delete_comment($note_id, true);
129 129
         }
130 130
 
131 131
         die();
@@ -138,8 +138,8 @@  discard block
 block discarded – undo
138 138
     }
139 139
     
140 140
     public static function checkout() {
141
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
142
-            define( 'WPINV_CHECKOUT', true );
141
+        if (!defined('WPINV_CHECKOUT')) {
142
+            define('WPINV_CHECKOUT', true);
143 143
         }
144 144
 
145 145
         wpinv_process_checkout();
@@ -148,53 +148,53 @@  discard block
 block discarded – undo
148 148
     
149 149
     public static function add_invoice_item() {
150 150
         global $wpi_userID, $wpinv_ip_address_country;
151
-        check_ajax_referer( 'invoice-item', '_nonce' );
152
-        if ( !current_user_can( 'manage_options' ) ) {
151
+        check_ajax_referer('invoice-item', '_nonce');
152
+        if (!current_user_can('manage_options')) {
153 153
             die(-1);
154 154
         }
155 155
         
156
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
157
-        $invoice_id = absint( $_POST['invoice_id'] );
156
+        $item_id    = sanitize_text_field($_POST['item_id']);
157
+        $invoice_id = absint($_POST['invoice_id']);
158 158
         
159
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
159
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
160 160
             die();
161 161
         }
162 162
         
163
-        $invoice    = wpinv_get_invoice( $invoice_id );
164
-        if ( empty( $invoice ) ) {
163
+        $invoice = wpinv_get_invoice($invoice_id);
164
+        if (empty($invoice)) {
165 165
             die();
166 166
         }
167 167
         
168
-        if ( $invoice->is_paid() ) {
168
+        if ($invoice->is_paid()) {
169 169
             die(); // Don't allow modify items for paid invoice.
170 170
         }
171 171
         
172
-        if ( !empty( $_POST['user_id'] ) ) {
173
-            $wpi_userID = absint( $_POST['user_id'] ); 
172
+        if (!empty($_POST['user_id'])) {
173
+            $wpi_userID = absint($_POST['user_id']); 
174 174
         }
175 175
 
176
-        $item = new WPInv_Item( $item_id );
177
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
176
+        $item = new WPInv_Item($item_id);
177
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
178 178
             die();
179 179
         }
180 180
         
181 181
         // Validate item before adding to invoice because recurring item must be paid individually.
182
-        if ( !empty( $invoice->cart_details ) ) {
182
+        if (!empty($invoice->cart_details)) {
183 183
             $valid = true;
184 184
             
185
-            if ( $recurring_item = $invoice->get_recurring() ) {
186
-                if ( $recurring_item != $item_id ) {
185
+            if ($recurring_item = $invoice->get_recurring()) {
186
+                if ($recurring_item != $item_id) {
187 187
                     $valid = false;
188 188
                 }
189
-            } else if ( wpinv_is_recurring_item( $item_id ) ) {
189
+            } else if (wpinv_is_recurring_item($item_id)) {
190 190
                 $valid = false;
191 191
             }
192 192
             
193
-            if ( !$valid ) {
193
+            if (!$valid) {
194 194
                 $response               = array();
195 195
                 $response['success']    = false;
196
-                $response['msg']        = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' );
197
-                wp_send_json( $response );
196
+                $response['msg']        = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing');
197
+                wp_send_json($response);
198 198
             }
199 199
         }
200 200
         
@@ -202,9 +202,9 @@  discard block
 block discarded – undo
202 202
         
203 203
         $data                   = array();
204 204
         $data['invoice_id']     = $invoice_id;
205
-        $data['cart_discounts'] = $invoice->get_discounts( true );
205
+        $data['cart_discounts'] = $invoice->get_discounts(true);
206 206
         
207
-        wpinv_set_checkout_session( $data );
207
+        wpinv_set_checkout_session($data);
208 208
         
209 209
         $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1;
210 210
 
@@ -219,21 +219,21 @@  discard block
 block discarded – undo
219 219
             'fees'          => array()
220 220
         );
221 221
 
222
-        $invoice->add_item( $item_id, $args );
222
+        $invoice->add_item($item_id, $args);
223 223
         $invoice->save();
224 224
         
225
-        if ( empty( $_POST['country'] ) ) {
225
+        if (empty($_POST['country'])) {
226 226
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
227 227
         }
228
-        if ( empty( $_POST['state'] ) ) {
228
+        if (empty($_POST['state'])) {
229 229
             $_POST['state'] = $invoice->state;
230 230
         }
231 231
          
232
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
233
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
232
+        $invoice->country   = sanitize_text_field($_POST['country']);
233
+        $invoice->state     = sanitize_text_field($_POST['state']);
234 234
         
235
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
236
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
235
+        $invoice->set('country', sanitize_text_field($_POST['country']));
236
+        $invoice->set('state', sanitize_text_field($_POST['state']));
237 237
         
238 238
         $wpinv_ip_address_country = $invoice->country;
239 239
 
@@ -241,52 +241,52 @@  discard block
 block discarded – undo
241 241
         
242 242
         $response                       = array();
243 243
         $response['success']            = true;
244
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
244
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
245 245
         $response['data']['subtotal']   = $invoice->get_subtotal();
246 246
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
247 247
         $response['data']['tax']        = $invoice->get_tax();
248 248
         $response['data']['taxf']       = $invoice->get_tax(true);
249 249
         $response['data']['discount']   = $invoice->discount;
250
-        $response['data']['discountf']  = wpinv_price( $invoice->discount, $invoice->get_currency() );
250
+        $response['data']['discountf']  = wpinv_price($invoice->discount, $invoice->get_currency());
251 251
         $response['data']['total']      = $invoice->get_total();
252 252
         $response['data']['totalf']     = $invoice->get_total(true);
253 253
         
254 254
         wpinv_set_checkout_session($checkout_session);
255 255
         
256
-        wp_send_json( $response );
256
+        wp_send_json($response);
257 257
     }
258 258
     
259 259
     public static function remove_invoice_item() {
260 260
         global $wpi_userID, $wpinv_ip_address_country;
261 261
         
262
-        check_ajax_referer( 'invoice-item', '_nonce' );
263
-        if ( !current_user_can( 'manage_options' ) ) {
262
+        check_ajax_referer('invoice-item', '_nonce');
263
+        if (!current_user_can('manage_options')) {
264 264
             die(-1);
265 265
         }
266 266
         
267
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
268
-        $invoice_id = absint( $_POST['invoice_id'] );
269
-        $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false;
267
+        $item_id    = sanitize_text_field($_POST['item_id']);
268
+        $invoice_id = absint($_POST['invoice_id']);
269
+        $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false;
270 270
         
271
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
271
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
272 272
             die();
273 273
         }
274 274
 
275
-        $invoice    = wpinv_get_invoice( $invoice_id );
276
-        if ( empty( $invoice ) ) {
275
+        $invoice = wpinv_get_invoice($invoice_id);
276
+        if (empty($invoice)) {
277 277
             die();
278 278
         }
279 279
         
280
-        if ( $invoice->is_paid() ) {
280
+        if ($invoice->is_paid()) {
281 281
             die(); // Don't allow modify items for paid invoice.
282 282
         }
283 283
         
284
-        if ( !empty( $_POST['user_id'] ) ) {
285
-            $wpi_userID = absint( $_POST['user_id'] ); 
284
+        if (!empty($_POST['user_id'])) {
285
+            $wpi_userID = absint($_POST['user_id']); 
286 286
         }
287 287
 
288
-        $item       = new WPInv_Item( $item_id );
289
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
288
+        $item = new WPInv_Item($item_id);
289
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
290 290
             die();
291 291
         }
292 292
         
@@ -294,9 +294,9 @@  discard block
 block discarded – undo
294 294
         
295 295
         $data                   = array();
296 296
         $data['invoice_id']     = $invoice_id;
297
-        $data['cart_discounts'] = $invoice->get_discounts( true );
297
+        $data['cart_discounts'] = $invoice->get_discounts(true);
298 298
         
299
-        wpinv_set_checkout_session( $data );
299
+        wpinv_set_checkout_session($data);
300 300
 
301 301
         $args = array(
302 302
             'id'         => $item_id,
@@ -304,21 +304,21 @@  discard block
 block discarded – undo
304 304
             'cart_index' => $cart_index
305 305
         );
306 306
 
307
-        $invoice->remove_item( $item_id, $args );
307
+        $invoice->remove_item($item_id, $args);
308 308
         $invoice->save();
309 309
         
310
-        if ( empty( $_POST['country'] ) ) {
310
+        if (empty($_POST['country'])) {
311 311
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
312 312
         }
313
-        if ( empty( $_POST['state'] ) ) {
313
+        if (empty($_POST['state'])) {
314 314
             $_POST['state'] = $invoice->state;
315 315
         }
316 316
          
317
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
318
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
317
+        $invoice->country   = sanitize_text_field($_POST['country']);
318
+        $invoice->state     = sanitize_text_field($_POST['state']);
319 319
         
320
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
321
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
320
+        $invoice->set('country', sanitize_text_field($_POST['country']));
321
+        $invoice->set('state', sanitize_text_field($_POST['state']));
322 322
         
323 323
         $wpinv_ip_address_country = $invoice->country;
324 324
         
@@ -326,52 +326,52 @@  discard block
 block discarded – undo
326 326
         
327 327
         $response                       = array();
328 328
         $response['success']            = true;
329
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
329
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
330 330
         $response['data']['subtotal']   = $invoice->get_subtotal();
331 331
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
332 332
         $response['data']['tax']        = $invoice->get_tax();
333 333
         $response['data']['taxf']       = $invoice->get_tax(true);
334 334
         $response['data']['discount']   = $invoice->discount;
335
-        $response['data']['discountf']  = wpinv_price( $invoice->discount, $invoice->get_currency() );
335
+        $response['data']['discountf']  = wpinv_price($invoice->discount, $invoice->get_currency());
336 336
         $response['data']['total']      = $invoice->get_total();
337 337
         $response['data']['totalf']     = $invoice->get_total(true);
338 338
         
339 339
         wpinv_set_checkout_session($checkout_session);
340 340
         
341
-        wp_send_json( $response );
341
+        wp_send_json($response);
342 342
     }
343 343
     
344 344
     public static function create_invoice_item() {
345
-        check_ajax_referer( 'invoice-item', '_nonce' );
346
-        if ( !current_user_can( 'manage_options' ) ) {
345
+        check_ajax_referer('invoice-item', '_nonce');
346
+        if (!current_user_can('manage_options')) {
347 347
             die(-1);
348 348
         }
349 349
         
350
-        $invoice_id = absint( $_POST['invoice_id'] );
350
+        $invoice_id = absint($_POST['invoice_id']);
351 351
 
352 352
         // Find the item
353
-        if ( !is_numeric( $invoice_id ) ) {
353
+        if (!is_numeric($invoice_id)) {
354 354
             die();
355 355
         }        
356 356
         
357
-        $invoice     = wpinv_get_invoice( $invoice_id );
358
-        if ( empty( $invoice ) ) {
357
+        $invoice = wpinv_get_invoice($invoice_id);
358
+        if (empty($invoice)) {
359 359
             die();
360 360
         }
361 361
         
362 362
         // Validate item before adding to invoice because recurring item must be paid individually.
363
-        if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) {
363
+        if (!empty($invoice->cart_details) && $invoice->get_recurring()) {
364 364
             $response               = array();
365 365
             $response['success']    = false;
366
-            $response['msg']        = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' );
367
-            wp_send_json( $response );
366
+            $response['msg']        = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing');
367
+            wp_send_json($response);
368 368
         }        
369 369
         
370 370
         $save_item = $_POST['_wpinv_quick'];
371 371
         
372 372
         $meta               = array();
373 373
         $meta['type']       = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom';
374
-        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0;
374
+        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0;
375 375
         $meta['vat_rule']   = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital';
376 376
         $meta['vat_class']  = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard';
377 377
         
@@ -381,9 +381,9 @@  discard block
 block discarded – undo
381 381
         $data['meta']           = $meta;
382 382
         
383 383
         $item = new WPInv_Item();
384
-        $item->create( $data );
384
+        $item->create($data);
385 385
         
386
-        if ( !empty( $item ) ) {
386
+        if (!empty($item)) {
387 387
             $_POST['item_id']   = $item->ID;
388 388
             $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1;
389 389
             
@@ -393,15 +393,15 @@  discard block
 block discarded – undo
393 393
     }
394 394
     
395 395
     public static function get_billing_details() {
396
-        check_ajax_referer( 'get-billing-details', '_nonce' );
396
+        check_ajax_referer('get-billing-details', '_nonce');
397 397
         
398
-        if ( !current_user_can( 'manage_options' ) ) {
398
+        if (!current_user_can('manage_options')) {
399 399
             die(-1);
400 400
         }
401 401
 
402 402
         $user_id            = (int)$_POST['user_id'];
403 403
         $billing_details    = wpinv_get_user_address($user_id);
404
-        $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
404
+        $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
405 405
         
406 406
         if (isset($billing_details['user_id'])) {
407 407
             unset($billing_details['user_id']);
@@ -415,20 +415,20 @@  discard block
 block discarded – undo
415 415
         $response['success']                    = true;
416 416
         $response['data']['billing_details']    = $billing_details;
417 417
         
418
-        wp_send_json( $response );
418
+        wp_send_json($response);
419 419
     }
420 420
     
421 421
     public static function admin_recalculate_totals() {
422 422
         global $wpi_userID, $wpinv_ip_address_country;
423 423
         
424
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
425
-        if ( !current_user_can( 'manage_options' ) ) {
424
+        check_ajax_referer('wpinv-nonce', '_nonce');
425
+        if (!current_user_can('manage_options')) {
426 426
             die(-1);
427 427
         }
428 428
         
429
-        $invoice_id = absint( $_POST['invoice_id'] );        
430
-        $invoice    = wpinv_get_invoice( $invoice_id );
431
-        if ( empty( $invoice ) ) {
429
+        $invoice_id = absint($_POST['invoice_id']);        
430
+        $invoice    = wpinv_get_invoice($invoice_id);
431
+        if (empty($invoice)) {
432 432
             die();
433 433
         }
434 434
         
@@ -436,23 +436,23 @@  discard block
 block discarded – undo
436 436
         
437 437
         $data                   = array();
438 438
         $data['invoice_id']     = $invoice_id;
439
-        $data['cart_discounts'] = $invoice->get_discounts( true );
439
+        $data['cart_discounts'] = $invoice->get_discounts(true);
440 440
         
441
-        wpinv_set_checkout_session( $data );
441
+        wpinv_set_checkout_session($data);
442 442
         
443
-        if ( !empty( $_POST['user_id'] ) ) {
444
-            $wpi_userID = absint( $_POST['user_id'] ); 
443
+        if (!empty($_POST['user_id'])) {
444
+            $wpi_userID = absint($_POST['user_id']); 
445 445
         }
446 446
         
447
-        if ( empty( $_POST['country'] ) ) {
447
+        if (empty($_POST['country'])) {
448 448
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
449 449
         }
450 450
             
451
-        $invoice->country = sanitize_text_field( $_POST['country'] );
452
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
453
-        if ( isset( $_POST['state'] ) ) {
454
-            $invoice->state = sanitize_text_field( $_POST['state'] );
455
-            $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
451
+        $invoice->country = sanitize_text_field($_POST['country']);
452
+        $invoice->set('country', sanitize_text_field($_POST['country']));
453
+        if (isset($_POST['state'])) {
454
+            $invoice->state = sanitize_text_field($_POST['state']);
455
+            $invoice->set('state', sanitize_text_field($_POST['state']));
456 456
         }
457 457
         
458 458
         $wpinv_ip_address_country = $invoice->country;
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
         
462 462
         $response                       = array();
463 463
         $response['success']            = true;
464
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
464
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
465 465
         $response['data']['subtotal']   = $invoice->get_subtotal();
466 466
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
467 467
         $response['data']['tax']        = $invoice->get_tax();
@@ -473,25 +473,25 @@  discard block
 block discarded – undo
473 473
         
474 474
         wpinv_set_checkout_session($checkout_session);
475 475
         
476
-        wp_send_json( $response );
476
+        wp_send_json($response);
477 477
     }
478 478
     
479 479
     public static function admin_apply_discount() {
480 480
         global $wpi_userID;
481 481
         
482
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
483
-        if ( !current_user_can( 'manage_options' ) ) {
482
+        check_ajax_referer('wpinv-nonce', '_nonce');
483
+        if (!current_user_can('manage_options')) {
484 484
             die(-1);
485 485
         }
486 486
         
487
-        $invoice_id = absint( $_POST['invoice_id'] );
488
-        $discount_code = sanitize_text_field( $_POST['code'] );
489
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
487
+        $invoice_id = absint($_POST['invoice_id']);
488
+        $discount_code = sanitize_text_field($_POST['code']);
489
+        if (empty($invoice_id) || empty($discount_code)) {
490 490
             die();
491 491
         }
492 492
         
493
-        $invoice = wpinv_get_invoice( $invoice_id );
494
-        if ( empty( $invoice ) || ( !empty( $invoice ) && $invoice->is_paid() ) ) {
493
+        $invoice = wpinv_get_invoice($invoice_id);
494
+        if (empty($invoice) || (!empty($invoice) && $invoice->is_paid())) {
495 495
             die();
496 496
         }
497 497
         
@@ -499,49 +499,49 @@  discard block
 block discarded – undo
499 499
         
500 500
         $data                   = array();
501 501
         $data['invoice_id']     = $invoice_id;
502
-        $data['cart_discounts'] = $invoice->get_discounts( true );
502
+        $data['cart_discounts'] = $invoice->get_discounts(true);
503 503
         
504
-        wpinv_set_checkout_session( $data );
504
+        wpinv_set_checkout_session($data);
505 505
         
506 506
         $response               = array();
507 507
         $response['success']    = false;
508
-        $response['msg']        = __( 'This discount is invalid.', 'invoicing' );
508
+        $response['msg']        = __('This discount is invalid.', 'invoicing');
509 509
         $response['data']['code'] = $discount_code;
510 510
         
511
-        if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) {
512
-            $discounts = wpinv_set_cart_discount( $discount_code );
511
+        if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) {
512
+            $discounts = wpinv_set_cart_discount($discount_code);
513 513
             
514 514
             $response['success'] = true;
515
-            $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );
516
-        }  else {
515
+            $response['msg'] = __('Discount has been applied successfully.', 'invoicing');
516
+        } else {
517 517
             $errors = wpinv_get_errors();
518
-            if ( !empty( $errors['wpinv-discount-error'] ) ) {
518
+            if (!empty($errors['wpinv-discount-error'])) {
519 519
                 $response['msg'] = $errors['wpinv-discount-error'];
520 520
             }
521
-            wpinv_unset_error( 'wpinv-discount-error' );
521
+            wpinv_unset_error('wpinv-discount-error');
522 522
         }
523 523
         
524 524
         wpinv_set_checkout_session($checkout_session);
525 525
         
526
-        wp_send_json( $response );
526
+        wp_send_json($response);
527 527
     }
528 528
     
529 529
     public static function admin_remove_discount() {
530 530
         global $wpi_userID;
531 531
         
532
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
533
-        if ( !current_user_can( 'manage_options' ) ) {
532
+        check_ajax_referer('wpinv-nonce', '_nonce');
533
+        if (!current_user_can('manage_options')) {
534 534
             die(-1);
535 535
         }
536 536
         
537
-        $invoice_id = absint( $_POST['invoice_id'] );
538
-        $discount_code = sanitize_text_field( $_POST['code'] );
539
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
537
+        $invoice_id = absint($_POST['invoice_id']);
538
+        $discount_code = sanitize_text_field($_POST['code']);
539
+        if (empty($invoice_id) || empty($discount_code)) {
540 540
             die();
541 541
         }
542 542
         
543
-        $invoice = wpinv_get_invoice( $invoice_id );
544
-        if ( empty( $invoice ) || ( !empty( $invoice ) && $invoice->is_paid() ) ) {
543
+        $invoice = wpinv_get_invoice($invoice_id);
544
+        if (empty($invoice) || (!empty($invoice) && $invoice->is_paid())) {
545 545
             die();
546 546
         }
547 547
         
@@ -549,38 +549,38 @@  discard block
 block discarded – undo
549 549
         
550 550
         $data                   = array();
551 551
         $data['invoice_id']     = $invoice_id;
552
-        $data['cart_discounts'] = $invoice->get_discounts( true );
552
+        $data['cart_discounts'] = $invoice->get_discounts(true);
553 553
         
554
-        wpinv_set_checkout_session( $data );
554
+        wpinv_set_checkout_session($data);
555 555
         
556 556
         $response               = array();
557 557
         $response['success']    = false;
558 558
         $response['msg']        = NULL;
559 559
         
560
-        $discounts  = wpinv_unset_cart_discount( $discount_code );
560
+        $discounts = wpinv_unset_cart_discount($discount_code);
561 561
         $response['success'] = true;
562
-        $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' );
562
+        $response['msg'] = __('Discount has been removed successfully.', 'invoicing');
563 563
         
564 564
         wpinv_set_checkout_session($checkout_session);
565 565
         
566
-        wp_send_json( $response );
566
+        wp_send_json($response);
567 567
     }
568 568
     
569 569
     public static function check_email() {
570
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
571
-        if ( !current_user_can( 'manage_options' ) ) {
570
+        check_ajax_referer('wpinv-nonce', '_nonce');
571
+        if (!current_user_can('manage_options')) {
572 572
             die(-1);
573 573
         }
574 574
         
575
-        $email = sanitize_text_field( $_POST['email'] );
575
+        $email = sanitize_text_field($_POST['email']);
576 576
         
577 577
         $response = array();
578
-        if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) {
578
+        if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) {
579 579
             $user_id            = $user_data->ID;
580 580
             $user_login         = $user_data->user_login;
581 581
             $display_name       = $user_data->display_name ? $user_data->display_name : $user_login;
582 582
             $billing_details    = wpinv_get_user_address($user_id);
583
-            $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
583
+            $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
584 584
             
585 585
             if (isset($billing_details['user_id'])) {
586 586
                 unset($billing_details['user_id']);
@@ -596,31 +596,31 @@  discard block
 block discarded – undo
596 596
             $response['data']['billing_details']    = $billing_details;
597 597
         }
598 598
         
599
-        wp_send_json( $response );
599
+        wp_send_json($response);
600 600
     }
601 601
     
602 602
     public static function run_tool() {
603
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
604
-        if ( !current_user_can( 'manage_options' ) ) {
603
+        check_ajax_referer('wpinv-nonce', '_nonce');
604
+        if (!current_user_can('manage_options')) {
605 605
             die(-1);
606 606
         }
607 607
         
608
-        $tool = sanitize_text_field( $_POST['tool'] );
608
+        $tool = sanitize_text_field($_POST['tool']);
609 609
         
610
-        do_action( 'wpinv_run_tool' );
610
+        do_action('wpinv_run_tool');
611 611
         
612
-        if ( !empty( $tool ) ) {
613
-            do_action( 'wpinv_tool_' . $tool );
612
+        if (!empty($tool)) {
613
+            do_action('wpinv_tool_' . $tool);
614 614
         }
615 615
     }
616 616
     
617 617
     public static function apply_discount() {
618
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
618
+        check_ajax_referer('wpinv-nonce', '_nonce');
619 619
         
620 620
         $response = array();
621 621
         
622
-        if ( isset( $_POST['code'] ) ) {
623
-            $discount_code = sanitize_text_field( $_POST['code'] );
622
+        if (isset($_POST['code'])) {
623
+            $discount_code = sanitize_text_field($_POST['code']);
624 624
 
625 625
             $response['success']        = false;
626 626
             $response['msg']            = '';
@@ -628,14 +628,14 @@  discard block
 block discarded – undo
628 628
             
629 629
             $user = is_user_logged_in() ? get_current_user_id() : '';
630 630
 
631
-            if ( wpinv_is_discount_valid( $discount_code, $user ) ) {
632
-                $discount       = wpinv_get_discount_by_code( $discount_code );
633
-                $discounts      = wpinv_set_cart_discount( $discount_code );
634
-                $amount         = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
635
-                $total          = wpinv_get_cart_total( null, $discounts );
636
-                $cart_totals    = wpinv_recalculate_tax( true );
631
+            if (wpinv_is_discount_valid($discount_code, $user)) {
632
+                $discount       = wpinv_get_discount_by_code($discount_code);
633
+                $discounts      = wpinv_set_cart_discount($discount_code);
634
+                $amount         = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
635
+                $total          = wpinv_get_cart_total(null, $discounts);
636
+                $cart_totals    = wpinv_recalculate_tax(true);
637 637
             
638
-                if ( !empty( $cart_totals ) ) {
638
+                if (!empty($cart_totals)) {
639 639
                     $response['success']        = true;
640 640
                     $response['data']           = $cart_totals;
641 641
                     $response['data']['code']   = $discount_code;
@@ -644,29 +644,29 @@  discard block
 block discarded – undo
644 644
                 }
645 645
             } else {
646 646
                 $errors = wpinv_get_errors();
647
-                $response['msg']  = $errors['wpinv-discount-error'];
648
-                wpinv_unset_error( 'wpinv-discount-error' );
647
+                $response['msg'] = $errors['wpinv-discount-error'];
648
+                wpinv_unset_error('wpinv-discount-error');
649 649
             }
650 650
 
651 651
             // Allow for custom discount code handling
652
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
652
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
653 653
         }
654 654
         
655
-        wp_send_json( $response );
655
+        wp_send_json($response);
656 656
     }
657 657
     
658 658
     public static function remove_discount() {
659
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
659
+        check_ajax_referer('wpinv-nonce', '_nonce');
660 660
         
661 661
         $response = array();
662 662
         
663
-        if ( isset( $_POST['code'] ) ) {
664
-            $discount_code  = sanitize_text_field( $_POST['code'] );
665
-            $discounts      = wpinv_unset_cart_discount( $discount_code );
666
-            $total          = wpinv_get_cart_total( null, $discounts );
667
-            $cart_totals    = wpinv_recalculate_tax( true );
663
+        if (isset($_POST['code'])) {
664
+            $discount_code  = sanitize_text_field($_POST['code']);
665
+            $discounts      = wpinv_unset_cart_discount($discount_code);
666
+            $total          = wpinv_get_cart_total(null, $discounts);
667
+            $cart_totals    = wpinv_recalculate_tax(true);
668 668
             
669
-            if ( !empty( $cart_totals ) ) {
669
+            if (!empty($cart_totals)) {
670 670
                 $response['success']        = true;
671 671
                 $response['data']           = $cart_totals;
672 672
                 $response['data']['code']   = $discount_code;
@@ -675,10 +675,10 @@  discard block
 block discarded – undo
675 675
             }
676 676
             
677 677
             // Allow for custom discount code handling
678
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
678
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
679 679
         }
680 680
         
681
-        wp_send_json( $response );
681
+        wp_send_json($response);
682 682
     }
683 683
 }
684 684
 
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 = wpinv_sanitize_amount( $item['subtotal'] / $item['quantity'], 2 );
89
+                $item_amount = wpinv_sanitize_amount($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 ]  = wpinv_sanitize_amount( $item['discount'], 2 );
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]  = wpinv_sanitize_amount($item['discount'], 2);
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(), 2 );
106
+        if (wpinv_use_taxes()) {
107
+            $paypal_args['tax_cart'] = wpinv_sanitize_amount((float)$invoice->get_tax(), 2);
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_sanitize_amount( $invoice->get_total(), 2 );
141
-        $recurring_amount   = wpinv_sanitize_amount( $invoice->get_recurring_details( 'total' ), 2 );
140
+        $initial_amount     = wpinv_sanitize_amount($invoice->get_total(), 2);
141
+        $recurring_amount   = wpinv_sanitize_amount($invoice->get_recurring_details('total'), 2);
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/gateways/authorizenet.php 1 patch
Spacing   +211 added lines, -211 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,174 +83,174 @@  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();
110 110
             
111 111
             $authorizeAIM = wpinv_authorizenet_AIM();
112
-            $authorizeAIM->first_name       = wpinv_utf8_substr( $invoice->get_first_name(), 0, 50 );
113
-            $authorizeAIM->last_name        = wpinv_utf8_substr( $invoice->get_last_name(), 0, 50 );
114
-            $authorizeAIM->company          = wpinv_utf8_substr( $invoice->company, 0, 50 );
115
-            $authorizeAIM->address          = wpinv_utf8_substr( wp_strip_all_tags( $invoice->get_address(), true ), 0, 60 );
116
-            $authorizeAIM->city             = wpinv_utf8_substr( $invoice->city, 0, 40 );
117
-            $authorizeAIM->state            = wpinv_utf8_substr( $invoice->state, 0, 40 );
118
-            $authorizeAIM->zip              = wpinv_utf8_substr( $invoice->zip, 0, 40 );
119
-            $authorizeAIM->country          = wpinv_utf8_substr( $invoice->country, 0, 60 );
120
-            $authorizeAIM->phone            = wpinv_utf8_substr( $invoice->phone, 0, 25 );
121
-            $authorizeAIM->email            = wpinv_utf8_substr( $invoice->get_email(), 0, 255 );
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'] );
112
+            $authorizeAIM->first_name       = wpinv_utf8_substr($invoice->get_first_name(), 0, 50);
113
+            $authorizeAIM->last_name        = wpinv_utf8_substr($invoice->get_last_name(), 0, 50);
114
+            $authorizeAIM->company          = wpinv_utf8_substr($invoice->company, 0, 50);
115
+            $authorizeAIM->address          = wpinv_utf8_substr(wp_strip_all_tags($invoice->get_address(), true), 0, 60);
116
+            $authorizeAIM->city             = wpinv_utf8_substr($invoice->city, 0, 40);
117
+            $authorizeAIM->state            = wpinv_utf8_substr($invoice->state, 0, 40);
118
+            $authorizeAIM->zip              = wpinv_utf8_substr($invoice->zip, 0, 40);
119
+            $authorizeAIM->country          = wpinv_utf8_substr($invoice->country, 0, 60);
120
+            $authorizeAIM->phone            = wpinv_utf8_substr($invoice->phone, 0, 25);
121
+            $authorizeAIM->email            = wpinv_utf8_substr($invoice->get_email(), 0, 255);
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_name      = wpinv_utf8_substr( $item['name'], 0, 31 );
132
-                $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_name      = wpinv_utf8_substr($item['name'], 0, 31);
132
+                $item_desc[]    = $item_name . ' (' . $quantity . 'x ' . wpinv_price(wpinv_format_amount($item['item_price'])) . ')';
133 133
                 
134
-                $authorizeAIM->addLineItem( $item['id'], $item_name, '', $quantity, $item['item_price'], ( $use_taxes && !empty( $item['tax'] ) && $item['tax'] > 0 ? 'Y' : 'N' ) );
134
+                $authorizeAIM->addLineItem($item['id'], $item_name, '', $quantity, $item['item_price'], ($use_taxes && !empty($item['tax']) && $item['tax'] > 0 ? 'Y' : 'N'));
135 135
             }
136 136
             
137
-            $item_desc = '#' . $invoice->get_number() . ': ' . implode( ', ', $item_desc );
137
+            $item_desc = '#' . $invoice->get_number() . ': ' . implode(', ', $item_desc);
138 138
             
139
-            if ( $use_taxes && $invoice->get_tax() > 0 ) {
140
-                $authorizeAIM->tax  = $invoice->get_tax();
139
+            if ($use_taxes && $invoice->get_tax() > 0) {
140
+                $authorizeAIM->tax = $invoice->get_tax();
141 141
                 
142
-                $item_desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) );
142
+                $item_desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true));
143 143
             }
144 144
             
145
-            if ( $invoice->get_discount() > 0 ) {
146
-                $item_desc .= ', ' . wp_sprintf( __( 'Discount: %s', 'invoicing' ), $invoice->get_discount( true ) );
145
+            if ($invoice->get_discount() > 0) {
146
+                $item_desc .= ', ' . wp_sprintf(__('Discount: %s', 'invoicing'), $invoice->get_discount(true));
147 147
             }
148 148
             
149
-            $item_description = wpinv_utf8_substr( $item_desc, 0, 255 );
150
-            $item_description = html_entity_decode( $item_desc , ENT_QUOTES, 'UTF-8' );
149
+            $item_description = wpinv_utf8_substr($item_desc, 0, 255);
150
+            $item_description = html_entity_decode($item_desc, ENT_QUOTES, 'UTF-8');
151 151
             
152
-            $authorizeAIM->description  = wpinv_utf8_substr( $item_description, 0, 255 );
152
+            $authorizeAIM->description = wpinv_utf8_substr($item_description, 0, 255);
153 153
             
154 154
             $is_recurring = $invoice->is_recurring(); // Recurring payment.
155 155
             
156
-            if ( $is_recurring ) {
156
+            if ($is_recurring) {
157 157
                 $authorizeAIM->recurring_billing = true;
158 158
             }
159 159
             
160 160
             try {
161
-                if ( $is_recurring ) {
161
+                if ($is_recurring) {
162 162
                     $response = $authorizeAIM->authorizeOnly();
163 163
                 } else {
164 164
                     $response = $authorizeAIM->authorizeAndCapture();
165 165
                 }
166 166
                 
167
-                if ( $response->approved || $response->held ) {
168
-                    if ( $response->approved ) {
169
-                        wpinv_update_payment_status( $invoice_id, 'publish' );
167
+                if ($response->approved || $response->held) {
168
+                    if ($response->approved) {
169
+                        wpinv_update_payment_status($invoice_id, 'publish');
170 170
                     }
171
-                    wpinv_set_payment_transaction_id( $invoice_id, $response->transaction_id );
171
+                    wpinv_set_payment_transaction_id($invoice_id, $response->transaction_id);
172 172
                     
173
-                    $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 );
173
+                    $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);
174 174
                     
175
-                    wpinv_insert_payment_note( $invoice_id, $message );
175
+                    wpinv_insert_payment_note($invoice_id, $message);
176 176
                     
177
-                    do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card );
177
+                    do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card);
178 178
                     
179 179
                     wpinv_clear_errors();
180 180
                     wpinv_empty_cart();
181 181
                     
182
-                    wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
182
+                    wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
183 183
                 } else {
184
-                    if ( !empty( $response->response_reason_text ) ) {
185
-                        $error = __( $response->response_reason_text, 'invoicing' );
186
-                    } else if ( !empty( $response->error_message ) ) {
187
-                        $error = __( $response->error_message, 'invoicing' );
184
+                    if (!empty($response->response_reason_text)) {
185
+                        $error = __($response->response_reason_text, 'invoicing');
186
+                    } else if (!empty($response->error_message)) {
187
+                        $error = __($response->error_message, 'invoicing');
188 188
                     } else {
189
-                        $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) );
189
+                        $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true));
190 190
                     } 
191 191
                     
192
-                    $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error );
192
+                    $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error);
193 193
                     
194
-                    wpinv_set_error( 'payment_error', $error );
195
-                    wpinv_record_gateway_error( $error, $response );
196
-                    wpinv_insert_payment_note( $invoice_id, $error );
194
+                    wpinv_set_error('payment_error', $error);
195
+                    wpinv_record_gateway_error($error, $response);
196
+                    wpinv_insert_payment_note($invoice_id, $error);
197 197
                     
198
-                    wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
198
+                    wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
199 199
                 }
200
-            } catch ( AuthorizeNetException $e ) {
201
-                wpinv_set_error( 'request_error', $e->getMessage() );
202
-                wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) );
203
-                wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
200
+            } catch (AuthorizeNetException $e) {
201
+                wpinv_set_error('request_error', $e->getMessage());
202
+                wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage()));
203
+                wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
204 204
             }
205 205
         } else {
206
-            wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
206
+            wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
207 207
         }
208 208
     } else {
209
-        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 );
210
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
209
+        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);
210
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
211 211
     }
212 212
 }
213
-add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' );
213
+add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment');
214 214
 
215
-function wpinv_authorizenet_cancel_subscription( $subscription_id = '' ) {
216
-    if ( empty( $subscription_id ) ) {
215
+function wpinv_authorizenet_cancel_subscription($subscription_id = '') {
216
+    if (empty($subscription_id)) {
217 217
         return false;
218 218
     }
219 219
     
220 220
     try {
221 221
         $authnetXML = wpinv_authorizenet_XML();
222
-        $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription_id ) );
222
+        $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription_id));
223 223
 
224 224
         return $authnetXML->isSuccessful();
225
-    } catch( Exception $e ) {
226
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
225
+    } catch (Exception $e) {
226
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
227 227
     }
228 228
     
229 229
     return false;
230 230
 }
231 231
 
232
-function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) {
233
-    $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' );
234
-    if ( empty( $authorizenet_md5_hash ) ) {
232
+function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) {
233
+    $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash');
234
+    if (empty($authorizenet_md5_hash)) {
235 235
         return true;
236 236
     }
237 237
     
238
-    $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) );
238
+    $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount));
239 239
     
240
-    return hash_equals( $compare_md5, $md5_hash );
240
+    return hash_equals($compare_md5, $md5_hash);
241 241
 }
242 242
 
243 243
 function wpinv_authorizenet_AIM() {
244
-    if ( !class_exists( 'AuthorizeNetException' ) ) {
245
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
244
+    if (!class_exists('AuthorizeNetException')) {
245
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
246 246
     }
247 247
     
248
-    $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) );
248
+    $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'));
249 249
     
250
-    if ( wpinv_is_test_mode( 'authorizenet' ) ) {
251
-        $authorizeAIM->setSandbox( true );
250
+    if (wpinv_is_test_mode('authorizenet')) {
251
+        $authorizeAIM->setSandbox(true);
252 252
     } else {
253
-        $authorizeAIM->setSandbox( false );
253
+        $authorizeAIM->setSandbox(false);
254 254
     }
255 255
     
256 256
     $authorizeAIM->customer_ip = wpinv_get_ip();
@@ -259,164 +259,164 @@  discard block
 block discarded – undo
259 259
 }
260 260
 
261 261
 function wpinv_authorizenet_XML() {
262
-    if ( !class_exists( 'AuthnetXML' ) ) {
263
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
262
+    if (!class_exists('AuthnetXML')) {
263
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
264 264
     }
265 265
     
266
-    $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) );
266
+    $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool)wpinv_is_test_mode('authorizenet'));
267 267
     
268 268
     return $authnetXML;
269 269
 }
270 270
 
271
-function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) {
272
-    if ( empty( $response ) || empty( $invoice ) ) {
271
+function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) {
272
+    if (empty($response) || empty($invoice)) {
273 273
         return false;
274 274
     }
275 275
     
276
-    if ( $invoice->is_recurring() && !empty( $response->approved ) ) {
277
-        $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info );
276
+    if ($invoice->is_recurring() && !empty($response->approved)) {
277
+        $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info);
278 278
 
279
-        if ( !empty( $subscription ) && $subscription->isSuccessful() ) {
280
-            do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' );
279
+        if (!empty($subscription) && $subscription->isSuccessful()) {
280
+            do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet');
281 281
             
282
-            wpinv_authorizenet_subscription_record_signup( $subscription, $invoice );
282
+            wpinv_authorizenet_subscription_record_signup($subscription, $invoice);
283 283
             
284
-            do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' );
284
+            do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet');
285 285
         } else {
286
-            if ( isset( $subscription->messages->message ) ) {
286
+            if (isset($subscription->messages->message)) {
287 287
                 $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text;
288
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' );
288
+                wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing');
289 289
             } else {
290
-                $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' );
291
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error );
290
+                $error = __('Your subscription cannot be created due to an error.', 'invoicing');
291
+                wpinv_set_error('wpinv_authorize_recurring_error', $error);
292 292
             }
293 293
             
294
-            wpinv_record_gateway_error( $error, $subscription );
294
+            wpinv_record_gateway_error($error, $subscription);
295 295
             
296
-            wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ) );
296
+            wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error));
297 297
         }
298 298
     }
299 299
 }
300
-add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 );
300
+add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3);
301 301
 
302
-function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) {
303
-    if ( empty( $invoice ) ) {
302
+function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) {
303
+    if (empty($invoice)) {
304 304
         return false;
305 305
     }
306 306
     
307
-    $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response );
307
+    $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response);
308 308
     
309 309
     try {
310 310
         $authnetXML = wpinv_authorizenet_XML();
311
-        $authnetXML->ARBCreateSubscriptionRequest( $params );
312
-    } catch( Exception $e ) {
311
+        $authnetXML->ARBCreateSubscriptionRequest($params);
312
+    } catch (Exception $e) {
313 313
         $authnetXML = array();
314
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
314
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
315 315
     }
316 316
     
317 317
     return $authnetXML;
318 318
 }
319 319
 
320
-function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) {
321
-    if ( empty( $invoice ) ) {
320
+function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) {
321
+    if (empty($invoice)) {
322 322
         return false;
323 323
     }
324 324
     
325
-    $subscription_item = $invoice->get_recurring( true );
326
-    if ( empty( $subscription_item ) ) {
325
+    $subscription_item = $invoice->get_recurring(true);
326
+    if (empty($subscription_item)) {
327 327
         return false;
328 328
     }
329 329
     
330
-    $card_details       = wpinv_authorizenet_generate_card_info( $card_info );
330
+    $card_details       = wpinv_authorizenet_generate_card_info($card_info);
331 331
     $subscription_name  = $invoice->get_subscription_name();
332
-    $initial_amount     = wpinv_round_amount( $invoice->get_total() );
333
-    $recurring_amount   = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) );
332
+    $initial_amount     = wpinv_round_amount($invoice->get_total());
333
+    $recurring_amount   = wpinv_round_amount($invoice->get_recurring_details('total'));
334 334
     $interval           = $subscription_item->get_recurring_interval();
335 335
     $period             = $subscription_item->get_recurring_period();
336 336
     $bill_times         = (int)$subscription_item->get_recurring_limit();
337 337
     $bill_times         = $bill_times > 0 ? $bill_times : 9999;
338 338
     
339
-    $time_period        = wpinv_authorizenet_get_time_period( $interval, $period );
339
+    $time_period        = wpinv_authorizenet_get_time_period($interval, $period);
340 340
     $interval           = $time_period['interval'];
341 341
     $period             = $time_period['period'];
342 342
     
343 343
     $current_tz = date_default_timezone_get();
344
-    date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
345
-    $today = date( 'Y-m-d' );
346
-    date_default_timezone_set( $current_tz );
344
+    date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
345
+    $today = date('Y-m-d');
346
+    date_default_timezone_set($current_tz);
347 347
     
348 348
     $free_trial = $invoice->is_free_trial();
349
-    if ( $free_trial && $subscription_item->has_free_trial() ) {
349
+    if ($free_trial && $subscription_item->has_free_trial()) {
350 350
         $trial_interval    = $subscription_item->get_trial_interval();
351
-        $trial_period      = $subscription_item->get_trial_period( true );
351
+        $trial_period      = $subscription_item->get_trial_period(true);
352 352
     }
353 353
     
354 354
     $subscription = array();
355 355
     $subscription['name'] = $subscription_name;
356 356
     
357 357
     $subscription['paymentSchedule'] = array(
358
-        'interval'         => array( 'length' => $interval, 'unit' => $period ),
358
+        'interval'         => array('length' => $interval, 'unit' => $period),
359 359
         'startDate'        => $today,
360 360
         'totalOccurrences' => $bill_times,
361
-        'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0,
361
+        'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0,
362 362
     );
363 363
     
364 364
     $subscription['amount'] = $recurring_amount;
365 365
     $subscription['trialAmount'] = $initial_amount;
366
-    $subscription['payment'] = array( 'creditCard' => $card_details );
367
-    $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() );
368
-    $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone );
366
+    $subscription['payment'] = array('creditCard' => $card_details);
367
+    $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number());
368
+    $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone);
369 369
     
370 370
     $subscription['billTo'] = array(
371 371
         'firstName' => $invoice->get_first_name(),
372 372
         'lastName'  => $invoice->get_last_name(),
373 373
         'company'   => $invoice->company,
374
-        'address'   => wp_strip_all_tags( $invoice->get_address(), true ),
374
+        'address'   => wp_strip_all_tags($invoice->get_address(), true),
375 375
         'city'      => $invoice->city,
376 376
         'state'     => $invoice->state,
377 377
         'zip'       => $invoice->zip,
378 378
         'country'   => $invoice->country,
379 379
     );
380 380
     
381
-    $params = array( 'subscription' => $subscription );
381
+    $params = array('subscription' => $subscription);
382 382
     
383
-    return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response );
383
+    return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response);
384 384
 }
385 385
 
386
-function wpinv_authorizenet_generate_card_info( $card_info = array() ) {
387
-    $card_defaults      = array(
386
+function wpinv_authorizenet_generate_card_info($card_info = array()) {
387
+    $card_defaults = array(
388 388
         'cc_owner'          => null,
389 389
         'cc_number'         => null,
390 390
         'cc_expire_month'   => null,
391 391
         'cc_expire_year'    => null,
392 392
         'cc_cvv2'           => null,
393 393
     );
394
-    $card_info = wp_parse_args( $card_info, $card_defaults );
394
+    $card_info = wp_parse_args($card_info, $card_defaults);
395 395
         
396 396
     $card_details = array(
397
-        'cardNumber'     => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ),
398
-        'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ),
399
-        'cardCode'       => sanitize_text_field( $card_info['cc_cvv2'] ),
397
+        'cardNumber'     => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])),
398
+        'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']),
399
+        'cardCode'       => sanitize_text_field($card_info['cc_cvv2']),
400 400
     );
401 401
 
402 402
     return $card_details;
403 403
 }
404 404
 
405
-function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) {
406
-    if ( empty( $invoice ) || empty( $subscription ) ) {
405
+function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) {
406
+    if (empty($invoice) || empty($subscription)) {
407 407
         return false;
408 408
     }
409 409
     
410
-    $subscription_item = $invoice->get_recurring( true );
411
-    if ( empty( $subscription_item ) ) {
410
+    $subscription_item = $invoice->get_recurring(true);
411
+    if (empty($subscription_item)) {
412 412
         return false;
413 413
     }
414 414
     
415 415
     $invoice_id         = $invoice->ID;
416 416
     $subscriptionId     = (array)$subscription->subscriptionId;
417
-    $subscription_id    = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $invoice_id;
417
+    $subscription_id    = !empty($subscriptionId[0]) ? $subscriptionId[0] : $invoice_id;
418 418
 
419
-    wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ) );
419
+    wpinv_insert_payment_note($invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id));
420 420
     
421 421
     $status = $invoice->is_free_trial() && $subscription_item->has_free_trial() ? 'trialing' : 'active';
422 422
     
@@ -424,16 +424,16 @@  discard block
 block discarded – undo
424 424
         'profile_id'        => $subscription_id,
425 425
         'item_id'           => $subscription_item->ID,
426 426
         'initial_amount'    => $invoice->get_total(),
427
-        'recurring_amount'  => $invoice->get_recurring_details( 'total' ),
427
+        'recurring_amount'  => $invoice->get_recurring_details('total'),
428 428
         'period'            => $subscription_item->get_recurring_period(),
429 429
         'interval'          => $subscription_item->get_recurring_interval(),
430 430
         'bill_times'        => $subscription_item->get_recurring_limit(),
431
-        'expiration'        => $invoice->get_new_expiration( $subscription_item->ID ),
431
+        'expiration'        => $invoice->get_new_expiration($subscription_item->ID),
432 432
         'status'            => $status,
433
-        'created'           => current_time( 'mysql', 0 )
433
+        'created'           => current_time('mysql', 0)
434 434
     );
435 435
     
436
-    if ( $invoice->is_free_trial() && $subscription_item->has_free_trial() ) {
436
+    if ($invoice->is_free_trial() && $subscription_item->has_free_trial()) {
437 437
         $args['trial_period']      = $subscription_item->get_trial_period();
438 438
         $args['trial_interval']    = $subscription_item->get_trial_interval();
439 439
     } else {
@@ -441,58 +441,58 @@  discard block
 block discarded – undo
441 441
         $args['trial_interval']    = 0;
442 442
     }
443 443
     
444
-    return $invoice->update_subscription( $args );
444
+    return $invoice->update_subscription($args);
445 445
 }
446 446
 
447
-function wpinv_authorizenet_validate_checkout( $valid_data, $post ) {
448
-    if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) {
447
+function wpinv_authorizenet_validate_checkout($valid_data, $post) {
448
+    if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') {
449 449
         $error = false;
450 450
         
451
-        if ( empty( $post['authorizenet']['cc_owner'] ) ) {
451
+        if (empty($post['authorizenet']['cc_owner'])) {
452 452
             $error = true;
453
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
453
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
454 454
         }
455
-        if ( empty( $post['authorizenet']['cc_number'] ) ) {
455
+        if (empty($post['authorizenet']['cc_number'])) {
456 456
             $error = true;
457
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
457
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
458 458
         }
459
-        if ( empty( $post['authorizenet']['cc_expire_month'] ) ) {
459
+        if (empty($post['authorizenet']['cc_expire_month'])) {
460 460
             $error = true;
461
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
461
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
462 462
         }
463
-        if ( empty( $post['authorizenet']['cc_expire_year'] ) ) {
463
+        if (empty($post['authorizenet']['cc_expire_year'])) {
464 464
             $error = true;
465
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
465
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
466 466
         }
467
-        if ( empty( $post['authorizenet']['cc_cvv2'] ) ) {
467
+        if (empty($post['authorizenet']['cc_cvv2'])) {
468 468
             $error = true;
469
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
469
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
470 470
         }
471 471
         
472
-        if ( $error ) {
472
+        if ($error) {
473 473
             return;
474 474
         }
475 475
         
476 476
         $invoice = wpinv_get_invoice_cart();
477 477
         
478
-        if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) {
479
-            $subscription_item = $invoice->get_recurring( true );
478
+        if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) {
479
+            $subscription_item = $invoice->get_recurring(true);
480 480
             
481 481
             $interval   = $subscription_item->get_recurring_interval();
482 482
             $period     = $subscription_item->get_recurring_period();
483 483
             
484
-            if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) {
485
-                wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) );
484
+            if ($period == 'D' && ($interval < 7 || $interval > 365)) {
485
+                wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing'));
486 486
             }
487 487
         }
488 488
     }
489 489
 }
490
-add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 );
490
+add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2);
491 491
 
492
-function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) {
493
-    $subscription_interval = absint( $subscription_interval );
492
+function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) {
493
+    $subscription_interval = absint($subscription_interval);
494 494
 
495
-    switch( $subscription_period ) {
495
+    switch ($subscription_period) {
496 496
         case 'W':
497 497
         case 'week':
498 498
         case 'weeks':
@@ -502,14 +502,14 @@  discard block
 block discarded – undo
502 502
         case 'M':
503 503
         case 'month':
504 504
         case 'months':
505
-            if ( $subscription_interval > 12 ) {
505
+            if ($subscription_interval > 12) {
506 506
                 $subscription_interval = 12;
507 507
             }
508 508
             
509 509
             $interval = $subscription_interval;
510 510
             $period   = 'months';
511 511
             
512
-            if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) {
512
+            if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) {
513 513
                 $interval = $subscription_interval * 30;
514 514
                 $period   = 'days';
515 515
             }
@@ -526,40 +526,40 @@  discard block
 block discarded – undo
526 526
             break;
527 527
     }
528 528
 
529
-    return compact( 'interval', 'period' );
529
+    return compact('interval', 'period');
530 530
 }
531 531
 
532 532
 function wpinv_authorizenet_process_ipn() {
533
-    if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) {
533
+    if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) {
534 534
         return;
535 535
     }
536 536
     
537
-    $subscription_id = intval( $_POST['x_subscription_id'] );
537
+    $subscription_id = intval($_POST['x_subscription_id']);
538 538
     
539
-    if ( $subscription_id ) {
540
-        $transaction_id = sanitize_text_field( $_POST['x_trans_id'] );
541
-        $renewal_amount = sanitize_text_field( $_POST['x_amount'] );
542
-        $response_code  = intval( $_POST['x_response_code'] );
543
-        $reason_code    = intval( $_POST['x_response_reason_code'] );
539
+    if ($subscription_id) {
540
+        $transaction_id = sanitize_text_field($_POST['x_trans_id']);
541
+        $renewal_amount = sanitize_text_field($_POST['x_amount']);
542
+        $response_code  = intval($_POST['x_response_code']);
543
+        $reason_code    = intval($_POST['x_response_reason_code']);
544 544
 
545
-        if ( 1 == $response_code ) {
545
+        if (1 == $response_code) {
546 546
             // Approved
547
-            do_action( 'wpinv_authorizenet_renewal_payment', $transaction_id );
548
-        } else if ( 2 == $response_code ) {
547
+            do_action('wpinv_authorizenet_renewal_payment', $transaction_id);
548
+        } else if (2 == $response_code) {
549 549
             // Declined
550
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id );
551
-            do_action( 'wpinv_authorizenet_renewal_error', $transaction_id );
552
-        } else if ( 3 == $response_code || 8 == $reason_code ) {
550
+            do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id);
551
+            do_action('wpinv_authorizenet_renewal_error', $transaction_id);
552
+        } else if (3 == $response_code || 8 == $reason_code) {
553 553
             // An expired card
554
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id );
555
-            do_action( 'wpinv_authorizenet_renewal_payment_error', $transaction_id );
554
+            do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id);
555
+            do_action('wpinv_authorizenet_renewal_payment_error', $transaction_id);
556 556
 
557 557
         } else {
558 558
             // Other Error
559
-            do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription );
559
+            do_action('wpinv_authorizenet_renewal_payment_error', $subscription);
560 560
         }
561 561
         
562 562
         exit;
563 563
     }
564 564
 }
565
-add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' );
566 565
\ No newline at end of file
566
+add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn');
567 567
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-subscriptions-db.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
 
@@ -49,15 +49,15 @@  discard block
 block discarded – undo
49 49
             'transaction_id'    => '',
50 50
             'parent_invoice_id' => 0,
51 51
             'item_id'           => 0,
52
-            'created'           => date_i18n( 'Y-m-d H:i:s' ),
53
-            'expiration'        => date_i18n( 'Y-m-d H:i:s' ),
52
+            'created'           => date_i18n('Y-m-d H:i:s'),
53
+            'expiration'        => date_i18n('Y-m-d H:i:s'),
54 54
             'status'            => '',
55 55
             'profile_id'        => '',
56 56
             'notes'             => '',
57 57
         );
58 58
     }
59 59
 
60
-    public function get_subscriptions( $args = array() ) {
60
+    public function get_subscriptions($args = array()) {
61 61
         global $wpdb;
62 62
 
63 63
         $defaults = array(
@@ -69,364 +69,364 @@  discard block
 block discarded – undo
69 69
             'order'        => 'DESC'
70 70
         );
71 71
 
72
-        $args  = wp_parse_args( $args, $defaults );
72
+        $args = wp_parse_args($args, $defaults);
73 73
 
74
-        if ( $args['number'] < 1 ) {
74
+        if ($args['number'] < 1) {
75 75
             $args['number'] = 99999999999999;
76 76
         }
77 77
 
78 78
         $where = ' WHERE 1=1 ';
79 79
 
80
-        if ( ! empty( $args['id'] ) ) {
81
-            if( is_array( $args['id'] ) ) {
82
-                $ids = implode( ',', array_map('intval', $args['id'] ) );
80
+        if (!empty($args['id'])) {
81
+            if (is_array($args['id'])) {
82
+                $ids = implode(',', array_map('intval', $args['id']));
83 83
             } else {
84
-                $ids = intval( $args['id'] );
84
+                $ids = intval($args['id']);
85 85
             }
86 86
 
87 87
             $where .= " AND `id` IN( " . $ids . " ) ";
88 88
         }
89 89
 
90
-        if ( ! empty( $args['item_id'] ) ) {
91
-            if( is_array( $args['item_id'] ) ) {
92
-                $item_ids = implode( ',', array_map('intval', $args['item_id'] ) );
90
+        if (!empty($args['item_id'])) {
91
+            if (is_array($args['item_id'])) {
92
+                $item_ids = implode(',', array_map('intval', $args['item_id']));
93 93
             } else {
94
-                $item_ids = intval( $args['item_id'] );
94
+                $item_ids = intval($args['item_id']);
95 95
             }
96 96
 
97 97
             $where .= " AND `item_id` IN( " . $item_ids . " ) ";
98 98
         }
99 99
 
100
-        if ( ! empty( $args['parent_invoice_id'] ) ) {
101
-            if( is_array( $args['parent_invoice_id'] ) ) {
102
-                $parent_payment_ids = implode( ',', array_map('intval', $args['parent_invoice_id'] ) );
100
+        if (!empty($args['parent_invoice_id'])) {
101
+            if (is_array($args['parent_invoice_id'])) {
102
+                $parent_payment_ids = implode(',', array_map('intval', $args['parent_invoice_id']));
103 103
             } else {
104
-                $parent_payment_ids = intval( $args['parent_invoice_id'] );
104
+                $parent_payment_ids = intval($args['parent_invoice_id']);
105 105
             }
106 106
 
107 107
             $where .= " AND `parent_invoice_id` IN( " . $parent_payment_ids . " ) ";
108 108
         }
109 109
 
110
-        if ( ! empty( $args['transaction_id'] ) ) {
111
-            if( is_array( $args['transaction_id'] ) ) {
112
-                $transaction_ids = implode( "','", array_map('sanitize_text_field', $args['transaction_id'] ) );
110
+        if (!empty($args['transaction_id'])) {
111
+            if (is_array($args['transaction_id'])) {
112
+                $transaction_ids = implode("','", array_map('sanitize_text_field', $args['transaction_id']));
113 113
             } else {
114
-                $transaction_ids = sanitize_text_field( $args['transaction_id'] );
114
+                $transaction_ids = sanitize_text_field($args['transaction_id']);
115 115
             }
116 116
 
117 117
             $where .= " AND `transaction_id` IN ( '" . $transaction_ids . "' ) ";
118 118
         }
119 119
 
120
-        if ( ! empty( $args['user_id'] ) ) {
121
-            if( is_array( $args['user_id'] ) ) {
122
-                $user_ids = implode( ',', array_map('intval', $args['user_id'] ) );
120
+        if (!empty($args['user_id'])) {
121
+            if (is_array($args['user_id'])) {
122
+                $user_ids = implode(',', array_map('intval', $args['user_id']));
123 123
             } else {
124
-                $user_ids = intval( $args['user_id'] );
124
+                $user_ids = intval($args['user_id']);
125 125
             }
126 126
 
127 127
             $where .= " AND `user_id` IN( " . $user_ids . " ) ";
128 128
         }
129 129
 
130
-        if ( ! empty( $args['profile_id'] ) ) {
131
-            if( is_array( $args['profile_id'] ) ) {
132
-                $profile_ids = implode( "','", array_map('sanitize_text_field', $args['profile_id'] ) );
130
+        if (!empty($args['profile_id'])) {
131
+            if (is_array($args['profile_id'])) {
132
+                $profile_ids = implode("','", array_map('sanitize_text_field', $args['profile_id']));
133 133
             } else {
134
-                $profile_ids = sanitize_text_field( $args['profile_id'] );
134
+                $profile_ids = sanitize_text_field($args['profile_id']);
135 135
             }
136 136
 
137 137
             $where .= " AND `profile_id` IN( '" . $profile_ids . "' ) ";
138 138
         }
139 139
 
140
-        if ( ! empty( $args['status'] ) ) {
141
-            if( is_array( $args['status'] ) ) {
142
-                $statuses = implode( "','", array_map( 'sanitize_text_field', $args['status'] ) );
140
+        if (!empty($args['status'])) {
141
+            if (is_array($args['status'])) {
142
+                $statuses = implode("','", array_map('sanitize_text_field', $args['status']));
143 143
             } else {
144
-                $statuses = sanitize_text_field( $args['status'] );
144
+                $statuses = sanitize_text_field($args['status']);
145 145
             }
146 146
 
147 147
             $where .= " AND `status` IN( '" . $statuses . "' ) ";
148 148
         }
149 149
 
150
-        if ( ! empty( $args['date'] ) ) {
151
-            if ( is_array( $args['date'] ) ) {
152
-                if ( ! empty( $args['date']['start'] ) ) {
153
-                    $start = date_i18n( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) );
150
+        if (!empty($args['date'])) {
151
+            if (is_array($args['date'])) {
152
+                if (!empty($args['date']['start'])) {
153
+                    $start = date_i18n('Y-m-d H:i:s', strtotime($args['date']['start']));
154 154
 
155 155
                     $where .= " AND `created` >= '" . $start . "'";
156 156
                 }
157 157
 
158
-                if ( ! empty( $args['date']['end'] ) ) {
159
-                    $end = date_i18n( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) );
158
+                if (!empty($args['date']['end'])) {
159
+                    $end = date_i18n('Y-m-d H:i:s', strtotime($args['date']['end']));
160 160
 
161 161
                     $where .= " AND `created` <= '" . $end . "'";
162 162
                 }
163 163
             } else {
164
-                $year  = date_i18n( 'Y', strtotime( $args['date'] ) );
165
-                $month = date_i18n( 'm', strtotime( $args['date'] ) );
166
-                $day   = date_i18n( 'd', strtotime( $args['date'] ) );
164
+                $year  = date_i18n('Y', strtotime($args['date']));
165
+                $month = date_i18n('m', strtotime($args['date']));
166
+                $day   = date_i18n('d', strtotime($args['date']));
167 167
 
168 168
                 $where .= " AND " . $year . " = YEAR ( created ) AND " . $month . " = MONTH ( created ) AND " . $day . " = DAY ( created )";
169 169
             }
170 170
         }
171 171
 
172
-        if ( ! empty( $args['expiration'] ) ) {
173
-            if ( is_array( $args['expiration'] ) ) {
174
-                if ( ! empty( $args['expiration']['start'] ) ) {
175
-                    $start = date_i18n( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) );
172
+        if (!empty($args['expiration'])) {
173
+            if (is_array($args['expiration'])) {
174
+                if (!empty($args['expiration']['start'])) {
175
+                    $start = date_i18n('Y-m-d H:i:s', strtotime($args['expiration']['start']));
176 176
 
177 177
                     $where .= " AND `expiration` >= '" . $start . "'";
178 178
                 }
179 179
 
180
-                if ( ! empty( $args['expiration']['end'] ) ) {
181
-                    $end = date_i18n( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) );
180
+                if (!empty($args['expiration']['end'])) {
181
+                    $end = date_i18n('Y-m-d H:i:s', strtotime($args['expiration']['end']));
182 182
 
183 183
                     $where .= " AND `expiration` <= '" . $end . "'";
184 184
                 }
185 185
             } else {
186
-                $year  = date_i18n( 'Y', strtotime( $args['expiration'] ) );
187
-                $month = date_i18n( 'm', strtotime( $args['expiration'] ) );
188
-                $day   = date_i18n( 'd', strtotime( $args['expiration'] ) );
186
+                $year  = date_i18n('Y', strtotime($args['expiration']));
187
+                $month = date_i18n('m', strtotime($args['expiration']));
188
+                $day   = date_i18n('d', strtotime($args['expiration']));
189 189
 
190 190
                 $where .= " AND " . $year . " = YEAR ( expiration ) AND " . $month . " = MONTH ( expiration ) AND " . $day . " = DAY ( expiration )";
191 191
             }
192 192
         }
193 193
 
194
-        if ( ! empty( $args['search'] ) ) {
195
-            if ( is_email( $args['search'] ) ) {
196
-                $user = get_user_by( 'email', $args['search'] )
194
+        if (!empty($args['search'])) {
195
+            if (is_email($args['search'])) {
196
+                $user = get_user_by('email', $args['search'])
197 197
                 
198
-                if ( !empty( $user ) && $user->ID > 0 ) {
199
-                    $where .= " AND `user_id` = '" . esc_sql( $user->ID ) . "'";
198
+                if (!empty($user) && $user->ID > 0) {
199
+                    $where .= " AND `user_id` = '" . esc_sql($user->ID) . "'";
200 200
                 }
201 201
 
202
-            } else if( false !== strpos( $args['search'], 'txn:' ) ) {
203
-                $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) );
204
-                $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'";
205
-            } else if ( false !== strpos( $args['search'], 'profile_id:' ) ) {
206
-                $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) );
207
-                $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'";
208
-            } else if ( false !== strpos( $args['search'], 'item_id:' ) ) {
209
-                $args['search'] = trim( str_replace( 'item_id:', '', $args['search'] ) );
210
-                $where .= " AND `item_id` = '" . esc_sql( $args['search'] ) . "'";
211
-            } else if ( false !== strpos( $args['search'], 'user_id:' ) ) {
212
-                $args[ 'search' ] = trim( str_replace( 'user_id:', '', $args[ 'search' ] ) );
213
-                $where .= " AND `user_id` = '" . esc_sql( $args[ 'search' ] ) . "'";
214
-            } else if ( false !== strpos( $args['search'], 'id:' ) ) {
215
-                $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) );
216
-                $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'";
202
+            } else if (false !== strpos($args['search'], 'txn:')) {
203
+                $args['search'] = trim(str_replace('txn:', '', $args['search']));
204
+                $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'";
205
+            } else if (false !== strpos($args['search'], 'profile_id:')) {
206
+                $args['search'] = trim(str_replace('profile_id:', '', $args['search']));
207
+                $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'";
208
+            } else if (false !== strpos($args['search'], 'item_id:')) {
209
+                $args['search'] = trim(str_replace('item_id:', '', $args['search']));
210
+                $where .= " AND `item_id` = '" . esc_sql($args['search']) . "'";
211
+            } else if (false !== strpos($args['search'], 'user_id:')) {
212
+                $args['search'] = trim(str_replace('user_id:', '', $args['search']));
213
+                $where .= " AND `user_id` = '" . esc_sql($args['search']) . "'";
214
+            } else if (false !== strpos($args['search'], 'id:')) {
215
+                $args['search'] = trim(str_replace('id:', '', $args['search']));
216
+                $where .= " AND `id` = '" . esc_sql($args['search']) . "'";
217 217
             } else {
218
-                $item = get_page_by_title( trim( $args['search'] ), OBJECT, 'wpi_item' );
218
+                $item = get_page_by_title(trim($args['search']), OBJECT, 'wpi_item');
219 219
 
220
-                if ( $item ) {
220
+                if ($item) {
221 221
                     $args['search'] = $item->ID;
222
-                    $where .= " AND `item_id` = '" . esc_sql( $args['search'] ) . "'";
222
+                    $where .= " AND `item_id` = '" . esc_sql($args['search']) . "'";
223 223
                 } else {
224
-                    $where .= " AND ( `parent_invoice_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `item_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )";
224
+                    $where .= " AND ( `parent_invoice_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `item_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )";
225 225
                 }
226 226
             }
227 227
         }
228 228
 
229
-        $args['orderby'] = ! array_key_exists( $args['orderby'], $this->get_columns() ) ? 'id' : $args['orderby'];
229
+        $args['orderby'] = !array_key_exists($args['orderby'], $this->get_columns()) ? 'id' : $args['orderby'];
230 230
 
231
-        if ( 'amount' == $args['orderby'] ) {
231
+        if ('amount' == $args['orderby']) {
232 232
             $args['orderby'] = 'amount + 0';
233 233
         }
234 234
 
235
-        $cache_key = md5( 'wpinv_subscriptions_' . serialize( $args ) );
235
+        $cache_key = md5('wpinv_subscriptions_' . serialize($args));
236 236
 
237
-        $subscriptions = wp_cache_get( $cache_key, 'wpi_subscriptions' );
237
+        $subscriptions = wp_cache_get($cache_key, 'wpi_subscriptions');
238 238
 
239
-        $args['orderby'] = esc_sql( $args['orderby'] );
240
-        $args['order']   = esc_sql( $args['order'] );
239
+        $args['orderby'] = esc_sql($args['orderby']);
240
+        $args['order']   = esc_sql($args['order']);
241 241
 
242
-        if ( $subscriptions === false ) {
243
-            $subscriptions = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM  $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint( $args['offset'] ), absint( $args['number'] ) ), OBJECT );
242
+        if ($subscriptions === false) {
243
+            $subscriptions = $wpdb->get_results($wpdb->prepare("SELECT * FROM  $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint($args['offset']), absint($args['number'])), OBJECT);
244 244
 
245
-            if ( ! empty( $subscriptions ) ) {
246
-                foreach( $subscriptions as $key => $subscription ) {
247
-                    $subscriptions[ $key ] = new EDD_Subscription( $subscription );
245
+            if (!empty($subscriptions)) {
246
+                foreach ($subscriptions as $key => $subscription) {
247
+                    $subscriptions[$key] = new EDD_Subscription($subscription);
248 248
                 }
249 249
 
250
-                wp_cache_set( $cache_key, $subscriptions, 'wpi_subscriptions', 3600 );
250
+                wp_cache_set($cache_key, $subscriptions, 'wpi_subscriptions', 3600);
251 251
             }
252 252
         }
253 253
 
254 254
         return $subscriptions;
255 255
     }
256 256
 
257
-    public function count( $args = array() ) {
257
+    public function count($args = array()) {
258 258
         global $wpdb;
259 259
 
260 260
         $where = ' WHERE 1=1 ';
261 261
 
262
-        if ( ! empty( $args['id'] ) ) {
263
-            if( is_array( $args['id'] ) ) {
264
-                $ids = implode( ',', array_map('intval', $args['id'] ) );
262
+        if (!empty($args['id'])) {
263
+            if (is_array($args['id'])) {
264
+                $ids = implode(',', array_map('intval', $args['id']));
265 265
             } else {
266
-                $ids = intval( $args['id'] );
266
+                $ids = intval($args['id']);
267 267
             }
268 268
 
269 269
             $where .= " AND `id` IN( " . $ids . " ) ";
270 270
         }
271 271
 
272
-        if ( ! empty( $args['item_id'] ) ) {
273
-            if( is_array( $args['item_id'] ) ) {
274
-                $item_ids = implode( ',', array_map('intval', $args['item_id'] ) );
272
+        if (!empty($args['item_id'])) {
273
+            if (is_array($args['item_id'])) {
274
+                $item_ids = implode(',', array_map('intval', $args['item_id']));
275 275
             } else {
276
-                $item_ids = intval( $args['item_id'] );
276
+                $item_ids = intval($args['item_id']);
277 277
             }
278 278
 
279 279
             $where .= " AND `item_id` IN( " . $item_ids . " ) ";
280 280
         }
281 281
 
282
-        if ( ! empty( $args['parent_invoice_id'] ) ) {
283
-            if( is_array( $args['parent_invoice_id'] ) ) {
284
-                $parent_payment_ids = implode( ',', array_map('intval', $args['parent_invoice_id'] ) );
282
+        if (!empty($args['parent_invoice_id'])) {
283
+            if (is_array($args['parent_invoice_id'])) {
284
+                $parent_payment_ids = implode(',', array_map('intval', $args['parent_invoice_id']));
285 285
             } else {
286
-                $parent_payment_ids = intval( $args['parent_invoice_id'] );
286
+                $parent_payment_ids = intval($args['parent_invoice_id']);
287 287
             }
288 288
 
289 289
             $where .= " AND `parent_invoice_id` IN( " . $parent_payment_ids . " ) ";
290 290
         }
291 291
 
292
-        if ( ! empty( $args['transaction_id'] ) ) {
293
-            if( is_array( $args['transaction_id'] ) ) {
294
-                $transaction_ids = implode( "','", array_map('sanitize_text_field', $args['transaction_id'] ) );
292
+        if (!empty($args['transaction_id'])) {
293
+            if (is_array($args['transaction_id'])) {
294
+                $transaction_ids = implode("','", array_map('sanitize_text_field', $args['transaction_id']));
295 295
             } else {
296
-                $transaction_ids = sanitize_text_field( $args['transaction_id'] );
296
+                $transaction_ids = sanitize_text_field($args['transaction_id']);
297 297
             }
298 298
 
299 299
             $where .= " AND `transaction_id` IN ( '" . $transaction_ids . "' ) ";
300 300
         }
301 301
 
302
-        if ( ! empty( $args['user_id'] ) ) {
303
-            if( is_array( $args['user_id'] ) ) {
304
-                $user_ids = implode( ',', array_map('intval', $args['user_id'] ) );
302
+        if (!empty($args['user_id'])) {
303
+            if (is_array($args['user_id'])) {
304
+                $user_ids = implode(',', array_map('intval', $args['user_id']));
305 305
             } else {
306
-                $user_ids = intval( $args['user_id'] );
306
+                $user_ids = intval($args['user_id']);
307 307
             }
308 308
 
309 309
             $where .= " AND `user_id` IN( " . $user_ids . " ) ";
310 310
         }
311 311
 
312
-        if ( ! empty( $args['profile_id'] ) ) {
313
-            if( is_array( $args['profile_id'] ) ) {
314
-                $profile_ids = implode( "','", array_map('sanitize_text_field', $args['profile_id'] ) );
312
+        if (!empty($args['profile_id'])) {
313
+            if (is_array($args['profile_id'])) {
314
+                $profile_ids = implode("','", array_map('sanitize_text_field', $args['profile_id']));
315 315
             } else {
316
-                $profile_ids = sanitize_text_field( $args['profile_id'] );
316
+                $profile_ids = sanitize_text_field($args['profile_id']);
317 317
             }
318 318
 
319 319
             $where .= " AND `profile_id` IN( '" . $profile_ids . "' ) ";
320 320
         }
321 321
 
322
-        if ( ! empty( $args['status'] ) ) {
323
-            if( is_array( $args['status'] ) ) {
324
-                $statuses = implode( "','", array_map( 'sanitize_text_field', $args['status'] ) );
322
+        if (!empty($args['status'])) {
323
+            if (is_array($args['status'])) {
324
+                $statuses = implode("','", array_map('sanitize_text_field', $args['status']));
325 325
             } else {
326
-                $statuses = sanitize_text_field( $args['status'] );
326
+                $statuses = sanitize_text_field($args['status']);
327 327
             }
328 328
 
329 329
             $where .= " AND `status` IN( '" . $statuses . "' ) ";
330 330
         }
331 331
 
332
-        if ( ! empty( $args['date'] ) ) {
333
-            if ( is_array( $args['date'] ) ) {
334
-                if ( ! empty( $args['date']['start'] ) ) {
335
-                    $start = date_i18n( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) );
332
+        if (!empty($args['date'])) {
333
+            if (is_array($args['date'])) {
334
+                if (!empty($args['date']['start'])) {
335
+                    $start = date_i18n('Y-m-d H:i:s', strtotime($args['date']['start']));
336 336
 
337 337
                     $where .= " AND `created` >= '" . $start . "'";
338 338
                 }
339 339
 
340
-                if ( ! empty( $args['date']['end'] ) ) {
341
-                    $end = date_i18n( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) );
340
+                if (!empty($args['date']['end'])) {
341
+                    $end = date_i18n('Y-m-d H:i:s', strtotime($args['date']['end']));
342 342
 
343 343
                     $where .= " AND `created` <= '" . $end . "'";
344 344
                 }
345 345
             } else {
346
-                $year  = date_i18n( 'Y', strtotime( $args['date'] ) );
347
-                $month = date_i18n( 'm', strtotime( $args['date'] ) );
348
-                $day   = date_i18n( 'd', strtotime( $args['date'] ) );
346
+                $year  = date_i18n('Y', strtotime($args['date']));
347
+                $month = date_i18n('m', strtotime($args['date']));
348
+                $day   = date_i18n('d', strtotime($args['date']));
349 349
 
350 350
                 $where .= " AND " . $year . " = YEAR ( created ) AND " . $month . " = MONTH ( created ) AND " . $day . " = DAY ( created )";
351 351
             }
352 352
         }
353 353
 
354
-        if ( ! empty( $args['expiration'] ) ) {
355
-            if ( is_array( $args['expiration'] ) ) {
356
-                if ( ! empty( $args['expiration']['start'] ) ) {
357
-                    $start = date_i18n( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) );
354
+        if (!empty($args['expiration'])) {
355
+            if (is_array($args['expiration'])) {
356
+                if (!empty($args['expiration']['start'])) {
357
+                    $start = date_i18n('Y-m-d H:i:s', strtotime($args['expiration']['start']));
358 358
 
359 359
                     $where .= " AND `expiration` >= '" . $start . "'";
360 360
                 }
361 361
 
362
-                if ( ! empty( $args['expiration']['end'] ) ) {
363
-                    $end = date_i18n( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) );
362
+                if (!empty($args['expiration']['end'])) {
363
+                    $end = date_i18n('Y-m-d H:i:s', strtotime($args['expiration']['end']));
364 364
 
365 365
                     $where .= " AND `expiration` <= '" . $end . "'";
366 366
                 }
367 367
             } else {
368
-                $year  = date_i18n( 'Y', strtotime( $args['expiration'] ) );
369
-                $month = date_i18n( 'm', strtotime( $args['expiration'] ) );
370
-                $day   = date_i18n( 'd', strtotime( $args['expiration'] ) );
368
+                $year  = date_i18n('Y', strtotime($args['expiration']));
369
+                $month = date_i18n('m', strtotime($args['expiration']));
370
+                $day   = date_i18n('d', strtotime($args['expiration']));
371 371
 
372 372
                 $where .= " AND " . $year . " = YEAR ( expiration ) AND " . $month . " = MONTH ( expiration ) AND " . $day . " = DAY ( expiration )";
373 373
             }
374 374
         }
375 375
 
376
-        if ( ! empty( $args['search'] ) ) {
377
-            if ( is_email( $args['search'] ) ) {
378
-                $user = get_user_by( 'email', $args['search'] )
376
+        if (!empty($args['search'])) {
377
+            if (is_email($args['search'])) {
378
+                $user = get_user_by('email', $args['search'])
379 379
                 
380
-                if ( !empty( $user ) && $user->ID > 0 ) {
381
-                    $where .= " AND `user_id` = '" . esc_sql( $user->ID ) . "'";
380
+                if (!empty($user) && $user->ID > 0) {
381
+                    $where .= " AND `user_id` = '" . esc_sql($user->ID) . "'";
382 382
                 }
383 383
 
384
-            } else if( false !== strpos( $args['search'], 'txn:' ) ) {
385
-                $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) );
386
-                $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'";
387
-            } else if ( false !== strpos( $args['search'], 'profile_id:' ) ) {
388
-                $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) );
389
-                $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'";
390
-            } else if ( false !== strpos( $args['search'], 'item_id:' ) ) {
391
-                $args['search'] = trim( str_replace( 'item_id:', '', $args['search'] ) );
392
-                $where .= " AND `item_id` = '" . esc_sql( $args['search'] ) . "'";
393
-            } else if ( false !== strpos( $args['search'], 'user_id:' ) ) {
394
-                $args[ 'search' ] = trim( str_replace( 'user_id:', '', $args[ 'search' ] ) );
395
-                $where .= " AND `user_id` = '" . esc_sql( $args[ 'search' ] ) . "'";
396
-            } else if ( false !== strpos( $args['search'], 'id:' ) ) {
397
-                $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) );
398
-                $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'";
384
+            } else if (false !== strpos($args['search'], 'txn:')) {
385
+                $args['search'] = trim(str_replace('txn:', '', $args['search']));
386
+                $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'";
387
+            } else if (false !== strpos($args['search'], 'profile_id:')) {
388
+                $args['search'] = trim(str_replace('profile_id:', '', $args['search']));
389
+                $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'";
390
+            } else if (false !== strpos($args['search'], 'item_id:')) {
391
+                $args['search'] = trim(str_replace('item_id:', '', $args['search']));
392
+                $where .= " AND `item_id` = '" . esc_sql($args['search']) . "'";
393
+            } else if (false !== strpos($args['search'], 'user_id:')) {
394
+                $args['search'] = trim(str_replace('user_id:', '', $args['search']));
395
+                $where .= " AND `user_id` = '" . esc_sql($args['search']) . "'";
396
+            } else if (false !== strpos($args['search'], 'id:')) {
397
+                $args['search'] = trim(str_replace('id:', '', $args['search']));
398
+                $where .= " AND `id` = '" . esc_sql($args['search']) . "'";
399 399
             } else {
400
-                $item = get_page_by_title( trim( $args['search'] ), OBJECT, 'wpi_item' );
400
+                $item = get_page_by_title(trim($args['search']), OBJECT, 'wpi_item');
401 401
 
402
-                if ( $item ) {
402
+                if ($item) {
403 403
                     $args['search'] = $item->ID;
404
-                    $where .= " AND `item_id` = '" . esc_sql( $args['search'] ) . "'";
404
+                    $where .= " AND `item_id` = '" . esc_sql($args['search']) . "'";
405 405
                 } else {
406
-                    $where .= " AND ( `parent_invoice_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `item_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )";
406
+                    $where .= " AND ( `parent_invoice_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `item_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )";
407 407
                 }
408 408
             }
409 409
         }
410 410
 
411
-        $cache_key = md5( 'wpi_subscriptions_count' . serialize( $args ) );
411
+        $cache_key = md5('wpi_subscriptions_count' . serialize($args));
412 412
 
413
-        $count = wp_cache_get( $cache_key, 'wpi_subscriptions' );
413
+        $count = wp_cache_get($cache_key, 'wpi_subscriptions');
414 414
 
415
-        if ( $count === false ) {
415
+        if ($count === false) {
416 416
             $sql   = "SELECT COUNT($this->primary_key) FROM " . $this->table_name . "{$where};";
417
-            $count = $wpdb->get_var( $sql );
417
+            $count = $wpdb->get_var($sql);
418 418
 
419
-            wp_cache_set( $cache_key, $count, 'wpi_subscriptions', 3600 );
419
+            wp_cache_set($cache_key, $count, 'wpi_subscriptions', 3600);
420 420
         }
421 421
 
422
-        return absint( $count );
422
+        return absint($count);
423 423
     }
424 424
 
425 425
     public function create_table() {
426 426
         global $wpdb;
427 427
 
428
-        if ( !function_exists( 'dbDelta' ) ) {
429
-            require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
428
+        if (!function_exists('dbDelta')) {
429
+            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
430 430
         }
431 431
 
432 432
         $sql = "CREATE TABLE " . $this->table_name . " (
@@ -454,8 +454,8 @@  discard block
 block discarded – undo
454 454
             KEY user_and_status ( user_id, status)
455 455
             ) CHARACTER SET utf8 COLLATE utf8_general_ci;";
456 456
 
457
-        dbDelta( $sql );
457
+        dbDelta($sql);
458 458
 
459
-        update_option( $this->table_name . '_db_version', $this->version );
459
+        update_option($this->table_name . '_db_version', $this->version);
460 460
     }
461 461
 }
Please login to merge, or discard this patch.
templates/emails/wpinv-email-invoice-items.php 1 patch
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6 6
 global $wpinv_euvat, $ajax_cart_details;
@@ -11,158 +11,158 @@  discard block
 block discarded – undo
11 11
 $quantities_enabled = wpinv_item_quantities_enabled();
12 12
 $use_taxes          = wpinv_use_taxes();
13 13
 $zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
14
-$tax_label          = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
15
-$tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
14
+$tax_label          = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
15
+$tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
16 16
 
17
-do_action( 'wpinv_before_email_items', $invoice ); ?>
17
+do_action('wpinv_before_email_items', $invoice); ?>
18 18
 <div id="wpinv-email-items">
19
-    <h3 class="wpinv-items-t"><?php echo apply_filters( 'wpinv_email_items_title', __( 'Items', 'invoicing' ) ); ?></h3>
19
+    <h3 class="wpinv-items-t"><?php echo apply_filters('wpinv_email_items_title', __('Items', 'invoicing')); ?></h3>
20 20
     <table id="wpinv_checkout_cart" class="table table-bordered table-hover">
21 21
         <thead>
22 22
             <tr class="wpinv_cart_header_row">
23
-                <?php do_action( 'wpinv_email_items_table_header_first' ); ?>
24
-                <th class="wpinv_cart_item_name text-left"><?php _e( 'Item Name', 'invoicing' ); ?></th>
25
-                <th class="wpinv_cart_item_price text-right"><?php _e( 'Item Price', 'invoicing' ); ?></th>
26
-                <?php if ( $quantities_enabled ) { ?>
27
-                <th class="wpinv_cart_item_qty text-right"><?php _e( 'Qty', 'invoicing' ); ?></th>
23
+                <?php do_action('wpinv_email_items_table_header_first'); ?>
24
+                <th class="wpinv_cart_item_name text-left"><?php _e('Item Name', 'invoicing'); ?></th>
25
+                <th class="wpinv_cart_item_price text-right"><?php _e('Item Price', 'invoicing'); ?></th>
26
+                <?php if ($quantities_enabled) { ?>
27
+                <th class="wpinv_cart_item_qty text-right"><?php _e('Qty', 'invoicing'); ?></th>
28 28
                 <?php } ?>
29
-                <?php if ( !$zero_tax && $use_taxes ) { ?>
29
+                <?php if (!$zero_tax && $use_taxes) { ?>
30 30
                 <th class="wpinv_cart_item_tax text-right"><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></th>
31 31
                 <?php } ?>
32
-                <th class="wpinv_cart_item_subtotal text-right"><?php echo __( 'Item Total', 'invoicing' ) . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
33
-                <?php do_action( 'wpinv_email_items_table_header_last' ); ?>
32
+                <th class="wpinv_cart_item_subtotal text-right"><?php echo __('Item Total', 'invoicing') . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
33
+                <?php do_action('wpinv_email_items_table_header_last'); ?>
34 34
             </tr>
35 35
         </thead>
36 36
         <tbody>
37 37
             <?php
38
-                do_action( 'wpinv_email_items_before' );
39
-                if ( $cart_items ) {
40
-                    foreach ( $cart_items as $key => $item ) {
41
-                        $wpi_item = $item['id'] ? new WPInv_Item( $item['id'] ) : NULL;
38
+                do_action('wpinv_email_items_before');
39
+                if ($cart_items) {
40
+                    foreach ($cart_items as $key => $item) {
41
+                        $wpi_item = $item['id'] ? new WPInv_Item($item['id']) : NULL;
42 42
                     ?>
43
-                    <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr( $key ) . '_' . esc_attr( $item['id'] ); ?>" data-item-id="<?php echo esc_attr( $item['id'] ); ?>">
44
-                        <?php do_action( 'wpinv_email_items_table_body_first', $item ); ?>
43
+                    <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr($key) . '_' . esc_attr($item['id']); ?>" data-item-id="<?php echo esc_attr($item['id']); ?>">
44
+                        <?php do_action('wpinv_email_items_table_body_first', $item); ?>
45 45
                         <td class="wpinv_cart_item_name text-left">
46 46
                             <?php
47
-                                if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $item['id'] ) ) {
47
+                                if (current_theme_supports('post-thumbnails') && has_post_thumbnail($item['id'])) {
48 48
                                     echo '<div class="wpinv_cart_item_image">';
49
-                                        echo get_the_post_thumbnail( $item['id'], apply_filters( 'wpinv_checkout_image_size', array( 25,25 ) ) );
49
+                                        echo get_the_post_thumbnail($item['id'], apply_filters('wpinv_checkout_image_size', array(25, 25)));
50 50
                                     echo '</div>';
51 51
                                 }
52
-                                $item_title = esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $wpi_item );
52
+                                $item_title = esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($wpi_item);
53 53
                                 echo '<span class="wpinv_email_cart_item_title">' . $item_title . '</span>';
54 54
                                 
55 55
                                 $summary = '';
56
-                                if ( !empty( $wpi_item ) && $wpi_item->is_package() && !empty( $item['meta']['post_id'] ) ) {
57
-                                    $post_link = '<a href="' . get_permalink( $item['meta']['post_id'] ) .'" target="_blank">' . (!empty($item['meta']['invoice_title']) ? $item['meta']['invoice_title'] : get_the_title( $item['meta']['post_id']) ) . '</a>';
58
-                                    $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_custom_singular_name(), $post_link );
56
+                                if (!empty($wpi_item) && $wpi_item->is_package() && !empty($item['meta']['post_id'])) {
57
+                                    $post_link = '<a href="' . get_permalink($item['meta']['post_id']) . '" target="_blank">' . (!empty($item['meta']['invoice_title']) ? $item['meta']['invoice_title'] : get_the_title($item['meta']['post_id'])) . '</a>';
58
+                                    $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_custom_singular_name(), $post_link);
59 59
                                 }
60 60
                                 
61
-                                $summary = apply_filters( 'wpinv_email_invoice_line_item_summary', $summary, $item, $wpi_item, $invoice );
62
-                                if ( !empty( $summary ) ) {
61
+                                $summary = apply_filters('wpinv_email_invoice_line_item_summary', $summary, $item, $wpi_item, $invoice);
62
+                                if (!empty($summary)) {
63 63
                                     echo '<p class="small">' . $summary . '</p>';
64 64
                                 }
65 65
     
66
-                                do_action( 'wpinv_email_cart_item_title_after', $item, $key );
66
+                                do_action('wpinv_email_cart_item_title_after', $item, $key);
67 67
                             ?>
68 68
                         </td>
69 69
                         <td class="wpinv_cart_item_price text-right">
70 70
                             <?php 
71
-                            echo wpinv_cart_item_price( $item );
72
-                            do_action( 'wpinv_email_cart_item_price_after', $item, $key );
71
+                            echo wpinv_cart_item_price($item);
72
+                            do_action('wpinv_email_cart_item_price_after', $item, $key);
73 73
                             ?>
74 74
                         </td>
75
-                        <?php if ( $quantities_enabled ) { ?>
75
+                        <?php if ($quantities_enabled) { ?>
76 76
                         <td class="wpinv_cart_item_qty text-right">
77 77
                             <?php
78
-                            echo wpinv_get_cart_item_quantity( $item );
79
-                            do_action( 'wpinv_email_item_quantitiy', $item, $key );
78
+                            echo wpinv_get_cart_item_quantity($item);
79
+                            do_action('wpinv_email_item_quantitiy', $item, $key);
80 80
                             ?>
81 81
                         </td>
82 82
                         <?php } ?>
83
-                        <?php if ( !$zero_tax && $use_taxes ) { ?>
83
+                        <?php if (!$zero_tax && $use_taxes) { ?>
84 84
                         <td class="wpinv_cart_item_tax text-right">
85 85
                             <?php
86
-                            echo wpinv_cart_item_tax( $item );
87
-                            do_action( 'wpinv_email_item_tax', $item, $key );
86
+                            echo wpinv_cart_item_tax($item);
87
+                            do_action('wpinv_email_item_tax', $item, $key);
88 88
                             ?>
89 89
                         </td>
90 90
                         <?php } ?>
91 91
                         <td class="wpinv_cart_item_subtotal text-right">
92 92
                             <?php
93
-                            echo wpinv_cart_item_subtotal( $item );
94
-                            do_action( 'wpinv_email_item_subtotal', $item, $key );
93
+                            echo wpinv_cart_item_subtotal($item);
94
+                            do_action('wpinv_email_item_subtotal', $item, $key);
95 95
                             ?>
96 96
                         </td>
97
-                        <?php do_action( 'wpinv_email_items_table_body_last', $item, $key ); ?>
97
+                        <?php do_action('wpinv_email_items_table_body_last', $item, $key); ?>
98 98
                     </tr>
99 99
                 <?php } ?>
100 100
             <?php } ?>
101
-            <?php do_action( 'wpinv_email_items_middle' ); ?>
102
-            <?php do_action( 'wpinv_email_items_after' ); ?>
101
+            <?php do_action('wpinv_email_items_middle'); ?>
102
+            <?php do_action('wpinv_email_items_after'); ?>
103 103
         </tbody>
104 104
         <tfoot>
105
-            <?php $cart_columns = wpinv_checkout_cart_columns(); if ( $zero_tax && $use_taxes ) { $cart_columns--; } ?>
106
-            <?php if ( has_action( 'wpinv_email_footer_buttons' ) ) { ?>
105
+            <?php $cart_columns = wpinv_checkout_cart_columns(); if ($zero_tax && $use_taxes) { $cart_columns--; } ?>
106
+            <?php if (has_action('wpinv_email_footer_buttons')) { ?>
107 107
                 <tr class="wpinv_cart_footer_row">
108
-                    <?php do_action( 'wpinv_email_items_table_buttons_first', $cart_items ); ?>
109
-                    <td colspan="<?php echo ( $cart_columns ); ?>">
110
-                        <?php do_action( 'wpinv_email_footer_buttons' ); ?>
108
+                    <?php do_action('wpinv_email_items_table_buttons_first', $cart_items); ?>
109
+                    <td colspan="<?php echo ($cart_columns); ?>">
110
+                        <?php do_action('wpinv_email_footer_buttons'); ?>
111 111
                     </td>
112
-                    <?php do_action( 'wpinv_email_items_table_buttons_first', $cart_items ); ?>
112
+                    <?php do_action('wpinv_email_items_table_buttons_first', $cart_items); ?>
113 113
                 </tr>
114 114
             <?php } ?>
115 115
 
116
-            <?php if ( !$zero_tax && $use_taxes && !wpinv_prices_include_tax() && wpinv_is_cart_taxed() ) { ?>
116
+            <?php if (!$zero_tax && $use_taxes && !wpinv_prices_include_tax() && wpinv_is_cart_taxed()) { ?>
117 117
                 <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row">
118
-                    <?php do_action( 'wpinv_email_items_table_subtotal_first', $cart_items ); ?>
119
-                    <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_subtotal_label text-right">
120
-                        <strong><?php _e( 'Sub-Total', 'invoicing' ); ?>:</strong>
118
+                    <?php do_action('wpinv_email_items_table_subtotal_first', $cart_items); ?>
119
+                    <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_subtotal_label text-right">
120
+                        <strong><?php _e('Sub-Total', 'invoicing'); ?>:</strong>
121 121
                     </td>
122 122
                     <td class="wpinv_cart_subtotal text-right">
123
-                        <span class="wpinv_cart_subtotal_amount bold"><?php echo $invoice->get_subtotal( true ); ?></span>
123
+                        <span class="wpinv_cart_subtotal_amount bold"><?php echo $invoice->get_subtotal(true); ?></span>
124 124
                     </td>
125
-                    <?php do_action( 'wpinv_email_items_table_subtotal_last', $cart_items, $invoice ); ?>
125
+                    <?php do_action('wpinv_email_items_table_subtotal_last', $cart_items, $invoice); ?>
126 126
                 </tr>
127 127
             <?php } ?>
128 128
             
129
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
129
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
130 130
                 <tr class="wpinv_cart_footer_row wpinv_cart_discount_row">
131
-                    <?php do_action( 'wpinv_receipt_items_table_discount_first', $cart_items, $invoice ); ?>
132
-                    <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_discount_label text-right">
133
-                        <strong><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</strong>
131
+                    <?php do_action('wpinv_receipt_items_table_discount_first', $cart_items, $invoice); ?>
132
+                    <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_discount_label text-right">
133
+                        <strong><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</strong>
134 134
                     </td>
135 135
                     <td class="wpinv_cart_discount text-right">
136
-                        <span class="wpinv_cart_discount_amount"><?php echo wpinv_discount( $invoice_id, true, true ); ?></span>
136
+                        <span class="wpinv_cart_discount_amount"><?php echo wpinv_discount($invoice_id, true, true); ?></span>
137 137
                     </td>
138
-                    <?php do_action( 'wpinv_receipt_items_table_discount_last', $cart_items, $invoice ); ?>
138
+                    <?php do_action('wpinv_receipt_items_table_discount_last', $cart_items, $invoice); ?>
139 139
                 </tr>
140 140
             <?php } ?>
141 141
 
142
-            <?php if ( !$zero_tax && $use_taxes && wpinv_is_cart_taxed() ) { ?>
142
+            <?php if (!$zero_tax && $use_taxes && wpinv_is_cart_taxed()) { ?>
143 143
                 <tr class="wpinv_cart_footer_row wpinv_cart_tax_row">
144
-                    <?php do_action( 'wpinv_email_items_table_tax_first', $cart_items, $invoice ); ?>
145
-                    <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_tax_label text-right">
144
+                    <?php do_action('wpinv_email_items_table_tax_first', $cart_items, $invoice); ?>
145
+                    <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_tax_label text-right">
146 146
                         <strong><?php echo $tax_label; ?>:</strong>
147 147
                     </td>
148 148
                     <td class="wpinv_cart_tax text-right">
149
-                        <span class="wpinv_cart_tax_amount"><?php echo $invoice->get_tax( true ); ?></span>
149
+                        <span class="wpinv_cart_tax_amount"><?php echo $invoice->get_tax(true); ?></span>
150 150
                     </td>
151
-                    <?php do_action( 'wpinv_email_items_table_tax_last', $cart_items, $invoice ); ?>
151
+                    <?php do_action('wpinv_email_items_table_tax_last', $cart_items, $invoice); ?>
152 152
                 </tr>
153 153
             <?php } ?>
154 154
 
155 155
             <tr class="wpinv_cart_footer_row">
156
-                <?php do_action( 'wpinv_email_items_table_footer_first', $cart_items, $invoice ); ?>
157
-                <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_total_label text-right">
158
-                    <?php echo apply_filters( 'wpinv_email_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?>
156
+                <?php do_action('wpinv_email_items_table_footer_first', $cart_items, $invoice); ?>
157
+                <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_total_label text-right">
158
+                    <?php echo apply_filters('wpinv_email_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?>
159 159
                 </td>
160 160
                 <td class="wpinv_cart_total text-right">
161
-                    <span class="wpinv_cart_amount bold"><?php echo $invoice->get_total( true ); ?></span>
161
+                    <span class="wpinv_cart_amount bold"><?php echo $invoice->get_total(true); ?></span>
162 162
                 </td>
163
-                <?php do_action( 'wpinv_email_items_table_footer_last', $cart_items, $invoice ); ?>
163
+                <?php do_action('wpinv_email_items_table_footer_last', $cart_items, $invoice); ?>
164 164
             </tr>
165 165
         </tfoot>
166 166
     </table>
167 167
 </div>
168
-<?php do_action( 'wpinv_after_email_items', $invoice ); ?>
169 168
\ No newline at end of file
169
+<?php do_action('wpinv_after_email_items', $invoice); ?>
170 170
\ No newline at end of file
Please login to merge, or discard this patch.
templates/wpinv-checkout-cart.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -5,140 +5,140 @@
 block discarded – undo
5 5
 
6 6
 global $wpinv_euvat, $post, $ajax_cart_details, $wpi_cart_columns, $wpi_session;
7 7
 $invoice            = wpinv_get_invoice_cart();
8
-$cart_items         = !empty( $ajax_cart_details ) ? $ajax_cart_details : wpinv_get_cart_content_details();
8
+$cart_items         = !empty($ajax_cart_details) ? $ajax_cart_details : wpinv_get_cart_content_details();
9 9
 $quantities_enabled = wpinv_item_quantities_enabled();
10 10
 $use_taxes          = wpinv_use_taxes();
11 11
 $tax_label          = $wpinv_euvat->tax_label();
12
-$tax_title          = $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
12
+$tax_title          = $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
13 13
 ?>
14 14
 <table id="wpinv_checkout_cart" class="table table-bordered table-hover">
15 15
     <thead>
16 16
         <tr class="wpinv_cart_header_row">
17
-            <?php do_action( 'wpinv_checkout_table_header_first' ); ?>
18
-            <th class="wpinv_cart_item_name text-left"><?php _e( 'Item Name', 'invoicing' ); ?></th>
19
-            <th class="wpinv_cart_item_price text-right"><?php _e( 'Item Price', 'invoicing' ); ?></th>
20
-            <?php if ( $quantities_enabled ) { ?>
21
-            <th class="wpinv_cart_item_qty text-right"><?php _e( 'Qty', 'invoicing' ); ?></th>
17
+            <?php do_action('wpinv_checkout_table_header_first'); ?>
18
+            <th class="wpinv_cart_item_name text-left"><?php _e('Item Name', 'invoicing'); ?></th>
19
+            <th class="wpinv_cart_item_price text-right"><?php _e('Item Price', 'invoicing'); ?></th>
20
+            <?php if ($quantities_enabled) { ?>
21
+            <th class="wpinv_cart_item_qty text-right"><?php _e('Qty', 'invoicing'); ?></th>
22 22
             <?php } ?>
23
-            <?php if ( $use_taxes ) { ?>
23
+            <?php if ($use_taxes) { ?>
24 24
             <th class="wpinv_cart_item_tax text-right"><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></th>
25 25
             <?php } ?>
26
-            <th class="wpinv_cart_item_subtotal text-right"><?php echo __( 'Item Total', 'invoicing' ) . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
27
-            <?php do_action( 'wpinv_checkout_table_header_last' ); ?>
26
+            <th class="wpinv_cart_item_subtotal text-right"><?php echo __('Item Total', 'invoicing') . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
27
+            <?php do_action('wpinv_checkout_table_header_last'); ?>
28 28
         </tr>
29 29
     </thead>
30 30
     <tbody>
31 31
         <?php
32
-            do_action( 'wpinv_cart_items_before' );
32
+            do_action('wpinv_cart_items_before');
33 33
             
34
-            if ( $cart_items ) {
35
-                foreach ( $cart_items as $key => $item ) {
36
-                    $wpi_item = !empty( $item['id'] ) ? new WPInv_Item( $item['id'] ) : NULL;
34
+            if ($cart_items) {
35
+                foreach ($cart_items as $key => $item) {
36
+                    $wpi_item = !empty($item['id']) ? new WPInv_Item($item['id']) : NULL;
37 37
                 ?>
38
-                <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr( $key ) . '_' . esc_attr( $item['id'] ); ?>" data-item-id="<?php echo esc_attr( $item['id'] ); ?>">
39
-                    <?php do_action( 'wpinv_checkout_table_body_first', $item ); ?>
38
+                <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr($key) . '_' . esc_attr($item['id']); ?>" data-item-id="<?php echo esc_attr($item['id']); ?>">
39
+                    <?php do_action('wpinv_checkout_table_body_first', $item); ?>
40 40
                     <td class="wpinv_cart_item_name text-left">
41 41
                         <?php
42
-                            if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $item['id'] ) ) {
42
+                            if (current_theme_supports('post-thumbnails') && has_post_thumbnail($item['id'])) {
43 43
                                 echo '<div class="wpinv_cart_item_image">';
44
-                                    echo get_the_post_thumbnail( $item['id'], apply_filters( 'wpinv_checkout_image_size', array( 25,25 ) ) );
44
+                                    echo get_the_post_thumbnail($item['id'], apply_filters('wpinv_checkout_image_size', array(25, 25)));
45 45
                                 echo '</div>';
46 46
                             }
47
-                            $item_title = esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $wpi_item );
47
+                            $item_title = esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($wpi_item);
48 48
                             echo '<span class="wpinv_checkout_cart_item_title">' . $item_title . '</span>';
49
-                            if ( !empty( $wpi_item ) && $wpi_item->is_package() && !empty( $item['meta']['post_id'] ) ) {
50
-                                $post_link = !empty( $item['meta']['invoice_title'] ) ? $item['meta']['invoice_title'] : get_the_title( $item['meta']['post_id'] );
51
-                                $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_custom_singular_name(), $post_link );
52
-                                echo '<small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>';
49
+                            if (!empty($wpi_item) && $wpi_item->is_package() && !empty($item['meta']['post_id'])) {
50
+                                $post_link = !empty($item['meta']['invoice_title']) ? $item['meta']['invoice_title'] : get_the_title($item['meta']['post_id']);
51
+                                $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_custom_singular_name(), $post_link);
52
+                                echo '<small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>';
53 53
                             }
54
-                            do_action( 'wpinv_checkout_cart_item_title_after', $item, $key );
54
+                            do_action('wpinv_checkout_cart_item_title_after', $item, $key);
55 55
                         ?>
56 56
                     </td>
57 57
                     <td class="wpinv_cart_item_price text-right">
58 58
                         <?php 
59
-                        echo wpinv_cart_item_price( $item );
60
-                        do_action( 'wpinv_checkout_cart_item_price_after', $item, $key );
59
+                        echo wpinv_cart_item_price($item);
60
+                        do_action('wpinv_checkout_cart_item_price_after', $item, $key);
61 61
                         ?>
62 62
                     </td>
63
-                    <?php if ( $quantities_enabled ) { ?>
63
+                    <?php if ($quantities_enabled) { ?>
64 64
                     <td class="wpinv_cart_item_qty text-right">
65 65
                         <?php
66
-                        echo wpinv_get_cart_item_quantity( $item );
67
-                        do_action( 'wpinv_cart_item_quantitiy', $item, $key );
66
+                        echo wpinv_get_cart_item_quantity($item);
67
+                        do_action('wpinv_cart_item_quantitiy', $item, $key);
68 68
                         ?>
69 69
                     </td>
70 70
                     <?php } ?>
71
-                    <?php if ( $use_taxes ) { ?>
71
+                    <?php if ($use_taxes) { ?>
72 72
                     <td class="wpinv_cart_item_tax text-right">
73 73
                         <?php
74
-                        echo wpinv_cart_item_tax( $item );
74
+                        echo wpinv_cart_item_tax($item);
75 75
                         //echo wpinv_get_cart_item_tax( $wpi_item->ID, $subtotal = '', $options = array() );
76
-                        do_action( 'wpinv_cart_item_tax', $item, $key );
76
+                        do_action('wpinv_cart_item_tax', $item, $key);
77 77
                         ?>
78 78
                     </td>
79 79
                     <?php } ?>
80 80
                     <td class="wpinv_cart_item_subtotal text-right">
81 81
                         <?php
82
-                        echo wpinv_cart_item_subtotal( $item );
83
-                        do_action( 'wpinv_cart_item_subtotal', $item, $key );
82
+                        echo wpinv_cart_item_subtotal($item);
83
+                        do_action('wpinv_cart_item_subtotal', $item, $key);
84 84
                         ?>
85 85
                     </td>
86
-                    <?php do_action( 'wpinv_checkout_table_body_last', $item, $key ); ?>
86
+                    <?php do_action('wpinv_checkout_table_body_last', $item, $key); ?>
87 87
                 </tr>
88 88
             <?php } ?>
89 89
         <?php } ?>
90
-        <?php do_action( 'wpinv_cart_items_middle' ); ?>
91
-        <?php do_action( 'wpinv_cart_items_after' ); ?>
90
+        <?php do_action('wpinv_cart_items_middle'); ?>
91
+        <?php do_action('wpinv_cart_items_after'); ?>
92 92
     </tbody>
93 93
     <tfoot>
94 94
         <?php $cart_columns = wpinv_checkout_cart_columns(); ?>
95
-        <?php if ( has_action( 'wpinv_cart_footer_buttons' ) ) { ?>
95
+        <?php if (has_action('wpinv_cart_footer_buttons')) { ?>
96 96
             <tr class="wpinv_cart_footer_row">
97
-                <?php do_action( 'wpinv_checkout_table_buttons_first', $cart_items ); ?>
98
-                <td colspan="<?php echo ( $cart_columns ); ?>">
99
-                    <?php do_action( 'wpinv_cart_footer_buttons' ); ?>
97
+                <?php do_action('wpinv_checkout_table_buttons_first', $cart_items); ?>
98
+                <td colspan="<?php echo ($cart_columns); ?>">
99
+                    <?php do_action('wpinv_cart_footer_buttons'); ?>
100 100
                 </td>
101
-                <?php do_action( 'wpinv_checkout_table_buttons_first', $cart_items ); ?>
101
+                <?php do_action('wpinv_checkout_table_buttons_first', $cart_items); ?>
102 102
             </tr>
103 103
         <?php } ?>
104 104
 
105
-        <?php if ( $use_taxes && !wpinv_prices_include_tax() ) { ?>
106
-            <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if ( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>>
107
-                <?php do_action( 'wpinv_checkout_table_subtotal_first', $cart_items ); ?>
108
-                <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_subtotal_label text-right">
109
-                    <strong><?php _e( 'Sub-Total', 'invoicing' ); ?>:</strong>
105
+        <?php if ($use_taxes && !wpinv_prices_include_tax()) { ?>
106
+            <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if (!wpinv_is_cart_taxed()) echo ' style="display:none;"'; ?>>
107
+                <?php do_action('wpinv_checkout_table_subtotal_first', $cart_items); ?>
108
+                <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_subtotal_label text-right">
109
+                    <strong><?php _e('Sub-Total', 'invoicing'); ?>:</strong>
110 110
                 </td>
111 111
                 <td class="wpinv_cart_subtotal text-right">
112
-                    <span class="wpinv_cart_subtotal_amount bold"><?php echo wpinv_cart_subtotal( $cart_items ); ?></span>
112
+                    <span class="wpinv_cart_subtotal_amount bold"><?php echo wpinv_cart_subtotal($cart_items); ?></span>
113 113
                 </td>
114
-                <?php do_action( 'wpinv_checkout_table_subtotal_last', $cart_items ); ?>
114
+                <?php do_action('wpinv_checkout_table_subtotal_last', $cart_items); ?>
115 115
             </tr>
116 116
         <?php } ?>
117 117
         
118
-        <?php $wpi_cart_columns = $cart_columns - 1; wpinv_cart_discounts_html( $cart_items ); ?>
118
+        <?php $wpi_cart_columns = $cart_columns - 1; wpinv_cart_discounts_html($cart_items); ?>
119 119
 
120
-        <?php if ( $use_taxes ) { ?>
121
-            <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>>
122
-                <?php do_action( 'wpinv_checkout_table_tax_first' ); ?>
123
-                <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_tax_label text-right">
120
+        <?php if ($use_taxes) { ?>
121
+            <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if (!wpinv_is_cart_taxed()) echo ' style="display:none;"'; ?>>
122
+                <?php do_action('wpinv_checkout_table_tax_first'); ?>
123
+                <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_tax_label text-right">
124 124
                     <strong><?php echo $tax_label; ?>:</strong>
125 125
                 </td>
126 126
                 <td class="wpinv_cart_tax text-right">
127
-                    <span class="wpinv_cart_tax_amount" data-tax="<?php echo wpinv_get_cart_tax( $cart_items ); ?>"><?php echo esc_html( wpinv_cart_tax( $cart_items ) ); ?></span>
127
+                    <span class="wpinv_cart_tax_amount" data-tax="<?php echo wpinv_get_cart_tax($cart_items); ?>"><?php echo esc_html(wpinv_cart_tax($cart_items)); ?></span>
128 128
                 </td>
129
-                <?php do_action( 'wpinv_checkout_table_tax_last' ); ?>
129
+                <?php do_action('wpinv_checkout_table_tax_last'); ?>
130 130
             </tr>
131 131
         <?php } ?>
132 132
 
133 133
         <tr class="wpinv_cart_footer_row wpinv_cart_total_row">
134
-            <?php do_action( 'wpinv_checkout_table_footer_first' ); ?>
135
-            <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_total_label text-right">
136
-                <?php echo apply_filters( 'wpinv_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?>
134
+            <?php do_action('wpinv_checkout_table_footer_first'); ?>
135
+            <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_total_label text-right">
136
+                <?php echo apply_filters('wpinv_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?>
137 137
             </td>
138 138
             <td class="wpinv_cart_total text-right">
139
-                <span class="wpinv_cart_amount bold" data-subtotal="<?php echo wpinv_get_cart_total( $cart_items ); ?>" data-total="<?php echo wpinv_get_cart_total( NULL, NULL, $invoice ); ?>"><?php wpinv_cart_total( $cart_items, true, $invoice ); ?></span>
139
+                <span class="wpinv_cart_amount bold" data-subtotal="<?php echo wpinv_get_cart_total($cart_items); ?>" data-total="<?php echo wpinv_get_cart_total(NULL, NULL, $invoice); ?>"><?php wpinv_cart_total($cart_items, true, $invoice); ?></span>
140 140
             </td>
141
-            <?php do_action( 'wpinv_checkout_table_footer_last' ); ?>
141
+            <?php do_action('wpinv_checkout_table_footer_last'); ?>
142 142
         </tr>
143 143
     </tfoot>
144 144
 </table>
Please login to merge, or discard this patch.