Passed
Pull Request — master (#126)
by Kiran
03:46
created
templates/wpinv-subscriptions-history.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -29,16 +29,16 @@
 block discarded – undo
29 29
     <table class="table table-bordered table-hover table-responsive wpi-user-subscriptions">
30 30
         <thead>
31 31
         <tr>
32
-            <th class="sub-no"><span class="nobr"><?php _e( 'No.', 'invoicing' ); ?></span></th>
33
-            <th class="sub-amount"><span class="nobr"><?php _e( 'Initial Amount', 'invoicing' ); ?></span></th>
34
-            <th class="sub-cycle"><span class="nobr"><?php _e( 'Billing Cycle', 'invoicing' ); ?></span></th>
35
-            <th class="sub-billed"><span class="nobr"><?php _e( 'Times Billed', 'invoicing' ); ?></span></th>
36
-            <th class="sub-status"><span class="nobr"><?php _e( 'Status', 'invoicing' ); ?></span></th>
37
-            <th class="sub-invoice"><span class="nobr"><?php _e( 'Invoice', 'invoicing' ); ?></span></th>
38
-            <th class="sub-item"><span class="nobr"><?php _e( 'Item', 'invoicing' ); ?></span></th>
39
-            <th class="sub-gateway"><span class="nobr"><?php _e( 'Gateway', 'invoicing' ); ?></span></th>
40
-            <th class="sub-expiry"><span class="nobr"><?php _e( 'Expires On', 'invoicing' ); ?></span></th>
41
-            <th class="sub-actions"><span class="nobr"><?php _e( 'Actions', 'invoicing' ); ?></span></th>
32
+            <th class="sub-no"><span class="nobr"><?php _e('No.', 'invoicing'); ?></span></th>
33
+            <th class="sub-amount"><span class="nobr"><?php _e('Initial Amount', 'invoicing'); ?></span></th>
34
+            <th class="sub-cycle"><span class="nobr"><?php _e('Billing Cycle', 'invoicing'); ?></span></th>
35
+            <th class="sub-billed"><span class="nobr"><?php _e('Times Billed', 'invoicing'); ?></span></th>
36
+            <th class="sub-status"><span class="nobr"><?php _e('Status', 'invoicing'); ?></span></th>
37
+            <th class="sub-invoice"><span class="nobr"><?php _e('Invoice', 'invoicing'); ?></span></th>
38
+            <th class="sub-item"><span class="nobr"><?php _e('Item', 'invoicing'); ?></span></th>
39
+            <th class="sub-gateway"><span class="nobr"><?php _e('Gateway', 'invoicing'); ?></span></th>
40
+            <th class="sub-expiry"><span class="nobr"><?php _e('Expires On', 'invoicing'); ?></span></th>
41
+            <th class="sub-actions"><span class="nobr"><?php _e('Actions', 'invoicing'); ?></span></th>
42 42
         </tr>
43 43
         </thead>
44 44
 
Please login to merge, or discard this patch.
templates/wpinv-invoice-history.php 1 patch
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -1,83 +1,83 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6
-if ( !( $user_id = get_current_user_id() ) ) {
6
+if (!($user_id = get_current_user_id())) {
7 7
     ?>
8
-    <div class="wpinv-empty alert alert-error"><?php _e( 'You are not allowed to access this section', 'invoicing' ) ;?></div>
8
+    <div class="wpinv-empty alert alert-error"><?php _e('You are not allowed to access this section', 'invoicing'); ?></div>
9 9
     <?php
10 10
     return;
11 11
 }
12 12
 
13 13
 global $current_page;
14
-$current_page   = empty( $current_page ) ? 1 : absint( $current_page );
15
-$query          = apply_filters( 'wpinv_user_invoices_query', array( 'user' => $user_id, 'page' => $current_page, 'paginate' => true ) );
16
-$user_invoices  = wpinv_get_invoices( $query );
14
+$current_page   = empty($current_page) ? 1 : absint($current_page);
15
+$query          = apply_filters('wpinv_user_invoices_query', array('user' => $user_id, 'page' => $current_page, 'paginate' => true));
16
+$user_invoices  = wpinv_get_invoices($query);
17 17
 $has_invoices   = 0 < $user_invoices->total;
18 18
     
19
-do_action( 'wpinv_before_user_invoices', $has_invoices ); ?>
19
+do_action('wpinv_before_user_invoices', $has_invoices); ?>
20 20
 
21
-<?php if ( $has_invoices ) { ?>
21
+<?php if ($has_invoices) { ?>
22 22
 	<table class="table table-bordered table-hover table-responsive wpi-user-invoices">
23 23
 		<thead>
24 24
 			<tr>
25
-				<?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
26
-					<th class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>"><span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span></th>
25
+				<?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
26
+					<th class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>"><span class="nobr"><?php echo esc_html($column_name['title']); ?></span></th>
27 27
 				<?php endforeach; ?>
28 28
 			</tr>
29 29
 		</thead>
30 30
 
31 31
 		<tbody>
32
-			<?php foreach ( $user_invoices->invoices as $invoice ) {
32
+			<?php foreach ($user_invoices->invoices as $invoice) {
33 33
 				?>
34 34
 				<tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>">
35
-					<?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
36
-						<td class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>" data-title="<?php echo esc_attr( $column_name['title'] ); ?>">
37
-							<?php if ( has_action( 'wpinv_user_invoices_column_' . $column_id ) ) : ?>
38
-								<?php do_action( 'wpinv_user_invoices_column_' . $column_id, $invoice ); ?>
39
-
40
-							<?php elseif ( 'invoice-number' === $column_id ) : ?>
41
-								<a href="<?php echo esc_url( $invoice->get_view_url() ); ?>">
42
-									<?php echo _x( '#', 'hash before invoice number', 'invoicing' ) . $invoice->get_number(); ?>
35
+					<?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
36
+						<td class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>" data-title="<?php echo esc_attr($column_name['title']); ?>">
37
+							<?php if (has_action('wpinv_user_invoices_column_' . $column_id)) : ?>
38
+								<?php do_action('wpinv_user_invoices_column_' . $column_id, $invoice); ?>
39
+
40
+							<?php elseif ('invoice-number' === $column_id) : ?>
41
+								<a href="<?php echo esc_url($invoice->get_view_url()); ?>">
42
+									<?php echo _x('#', 'hash before invoice number', 'invoicing') . $invoice->get_number(); ?>
43 43
 								</a>
44 44
 
45
-							<?php elseif ( 'created-date' === $column_id ) : $date = wpinv_get_date_created( $invoice->ID ); $dateYMD = wpinv_get_date_created( $invoice->ID, 'Y-m-d H:i:s' ); ?>
46
-								<time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
45
+							<?php elseif ('created-date' === $column_id) : $date = wpinv_get_date_created($invoice->ID); $dateYMD = wpinv_get_date_created($invoice->ID, 'Y-m-d H:i:s'); ?>
46
+								<time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
47 47
 
48
-							<?php elseif ( 'payment-date' === $column_id ) : $date = wpinv_get_invoice_date( $invoice->ID, '', false ); $dateYMD = wpinv_get_invoice_date( $invoice->ID, 'Y-m-d H:i:s', false ); ?>
49
-								<time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
48
+							<?php elseif ('payment-date' === $column_id) : $date = wpinv_get_invoice_date($invoice->ID, '', false); $dateYMD = wpinv_get_invoice_date($invoice->ID, 'Y-m-d H:i:s', false); ?>
49
+								<time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
50 50
 
51
-							<?php elseif ( 'invoice-status' === $column_id ) : ?>
52
-								<?php echo wpinv_invoice_status_label( $invoice_status, $invoice->get_status( true ) ) ; ?>
51
+							<?php elseif ('invoice-status' === $column_id) : ?>
52
+								<?php echo wpinv_invoice_status_label($invoice_status, $invoice->get_status(true)); ?>
53 53
 
54
-							<?php elseif ( 'invoice-total' === $column_id ) : ?>
55
-								<?php echo $invoice->get_total( true ); ?>
54
+							<?php elseif ('invoice-total' === $column_id) : ?>
55
+								<?php echo $invoice->get_total(true); ?>
56 56
 
57
-							<?php elseif ( 'invoice-actions' === $column_id ) : ?>
57
+							<?php elseif ('invoice-actions' === $column_id) : ?>
58 58
 								<?php
59 59
 									$actions = array(
60 60
 										'pay'    => array(
61 61
 											'url'  => $invoice->get_checkout_payment_url(),
62
-											'name' => __( 'Pay Now', 'invoicing' ),
62
+											'name' => __('Pay Now', 'invoicing'),
63 63
                                             'class' => 'btn-success'
64 64
 										),
65 65
                                         'print'   => array(
66 66
 											'url'  => $invoice->get_view_url(),
67
-											'name' => __( 'Print', 'invoicing' ),
67
+											'name' => __('Print', 'invoicing'),
68 68
                                             'class' => 'btn-primary',
69 69
                                             'attrs' => 'target="_blank"'
70 70
 										)
71 71
 									);
72 72
 
73
-									if ( ! $invoice->needs_payment() ) {
74
-										unset( $actions['pay'] );
73
+									if (!$invoice->needs_payment()) {
74
+										unset($actions['pay']);
75 75
 									}
76 76
 
77
-									if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) {
78
-										foreach ( $actions as $key => $action ) {
77
+									if ($actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice)) {
78
+										foreach ($actions as $key => $action) {
79 79
 											$class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
80
-                                            echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>';
80
+                                            echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>';
81 81
 										}
82 82
 									}
83 83
 								?>
@@ -89,9 +89,9 @@  discard block
 block discarded – undo
89 89
 		</tbody>
90 90
 	</table>
91 91
 
92
-	<?php do_action( 'wpinv_before_user_invoices_pagination' ); ?>
92
+	<?php do_action('wpinv_before_user_invoices_pagination'); ?>
93 93
 
94
-	<?php if ( 1 < $user_invoices->max_num_pages ) : ?>
94
+	<?php if (1 < $user_invoices->max_num_pages) : ?>
95 95
 		<div class="invoicing-Pagination">
96 96
 			<?php
97 97
 			$big = 999999;
@@ -103,20 +103,20 @@  discard block
 block discarded – undo
103 103
 			else
104 104
 				$current_page = 1;
105 105
 
106
-			echo paginate_links( array(
107
-				'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
106
+			echo paginate_links(array(
107
+				'base'    => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
108 108
 				'format'  => '?paged=%#%',
109
-				'current' => max( 1, $current_page ),
109
+				'current' => max(1, $current_page),
110 110
 				'total'   => $user_invoices->max_num_pages,
111
-			) );
111
+			));
112 112
 			?>
113 113
 		</div>
114 114
 	<?php endif; ?>
115 115
 
116 116
 <?php } else { ?>
117 117
 	<div class="wpinv-empty alert-info">
118
-		<?php _e( 'No invoice has been made yet.', 'invoicing' ); ?>
118
+		<?php _e('No invoice has been made yet.', 'invoicing'); ?>
119 119
 	</div>
120 120
 <?php } ?>
121 121
 
122
-<?php do_action( 'wpinv_after_user_invoices', $has_invoices ); ?>
122
+<?php do_action('wpinv_after_user_invoices', $has_invoices); ?>
Please login to merge, or discard this patch.
includes/class-wpinv-cache-helper.php 1 patch
Spacing   +36 added lines, -36 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
 
@@ -14,18 +14,18 @@  discard block
 block discarded – undo
14 14
      * Hook in methods.
15 15
      */
16 16
     public static function init() {
17
-        add_action( 'init', array( __CLASS__, 'init_hooks' ), 0 );
18
-        add_action( 'admin_notices', array( __CLASS__, 'notices' ) );
17
+        add_action('init', array(__CLASS__, 'init_hooks'), 0);
18
+        add_action('admin_notices', array(__CLASS__, 'notices'));
19 19
     }
20 20
 
21 21
     public static function init_hooks() {
22
-        if ( false === ( $page_uris = get_transient( 'wpinv_cache_excluded_uris' ) ) ) {
23
-            $checkout_page = wpinv_get_option( 'checkout_page', '' );
24
-            $success_page  = wpinv_get_option( 'success_page', '' );
25
-            $failure_page  = wpinv_get_option( 'failure_page', '' );
26
-            $history_page  = wpinv_get_option( 'invoice_history_page', '' );
27
-            $subscr_page   = wpinv_get_option( 'invoice_subscription_page', '' );
28
-            if ( empty( $checkout_page ) || empty( $success_page ) || empty( $failure_page ) || empty( $history_page ) || empty( $subscr_page ) ) {
22
+        if (false === ($page_uris = get_transient('wpinv_cache_excluded_uris'))) {
23
+            $checkout_page = wpinv_get_option('checkout_page', '');
24
+            $success_page  = wpinv_get_option('success_page', '');
25
+            $failure_page  = wpinv_get_option('failure_page', '');
26
+            $history_page  = wpinv_get_option('invoice_history_page', '');
27
+            $subscr_page   = wpinv_get_option('invoice_subscription_page', '');
28
+            if (empty($checkout_page) || empty($success_page) || empty($failure_page) || empty($history_page) || empty($subscr_page)) {
29 29
                 return;
30 30
             }
31 31
 
@@ -39,34 +39,34 @@  discard block
 block discarded – undo
39 39
             $page_uris[] = 'p=' . $subscr_page;
40 40
 
41 41
             // Exclude permalinks
42
-            $checkout_page  = get_post( $checkout_page );
43
-            $success_page   = get_post( $success_page );
44
-            $failure_page   = get_post( $failure_page );
45
-            $history_page   = get_post( $history_page );
46
-            $subscr_page    = get_post( $subscr_page );
42
+            $checkout_page  = get_post($checkout_page);
43
+            $success_page   = get_post($success_page);
44
+            $failure_page   = get_post($failure_page);
45
+            $history_page   = get_post($history_page);
46
+            $subscr_page    = get_post($subscr_page);
47 47
 
48
-            if ( ! is_null( $checkout_page ) ) {
48
+            if (!is_null($checkout_page)) {
49 49
                 $page_uris[] = '/' . $checkout_page->post_name;
50 50
             }
51
-            if ( ! is_null( $success_page ) ) {
51
+            if (!is_null($success_page)) {
52 52
                 $page_uris[] = '/' . $success_page->post_name;
53 53
             }
54
-            if ( ! is_null( $failure_page ) ) {
54
+            if (!is_null($failure_page)) {
55 55
                 $page_uris[] = '/' . $failure_page->post_name;
56 56
             }
57
-            if ( ! is_null( $history_page ) ) {
57
+            if (!is_null($history_page)) {
58 58
                 $page_uris[] = '/' . $history_page->post_name;
59 59
             }
60
-            if ( ! is_null( $subscr_page ) ) {
60
+            if (!is_null($subscr_page)) {
61 61
                 $page_uris[] = '/' . $subscr_page->post_name;
62 62
             }
63 63
 
64
-            set_transient( 'wpinv_cache_excluded_uris', $page_uris );
64
+            set_transient('wpinv_cache_excluded_uris', $page_uris);
65 65
         }
66 66
 
67
-        if ( is_array( $page_uris ) ) {
68
-            foreach( $page_uris as $uri ) {
69
-                if ( strstr( $_SERVER['REQUEST_URI'], $uri ) ) {
67
+        if (is_array($page_uris)) {
68
+            foreach ($page_uris as $uri) {
69
+                if (strstr($_SERVER['REQUEST_URI'], $uri)) {
70 70
                     self::nocache();
71 71
                     break;
72 72
                 }
@@ -79,14 +79,14 @@  discard block
 block discarded – undo
79 79
      * @access private
80 80
      */
81 81
     private static function nocache() {
82
-        if ( ! defined( 'DONOTCACHEPAGE' ) ) {
83
-            define( "DONOTCACHEPAGE", true );
82
+        if (!defined('DONOTCACHEPAGE')) {
83
+            define("DONOTCACHEPAGE", true);
84 84
         }
85
-        if ( ! defined( 'DONOTCACHEOBJECT' ) ) {
86
-            define( "DONOTCACHEOBJECT", true );
85
+        if (!defined('DONOTCACHEOBJECT')) {
86
+            define("DONOTCACHEOBJECT", true);
87 87
         }
88
-        if ( ! defined( 'DONOTCACHEDB' ) ) {
89
-            define( "DONOTCACHEDB", true );
88
+        if (!defined('DONOTCACHEDB')) {
89
+            define("DONOTCACHEDB", true);
90 90
         }
91 91
         nocache_headers();
92 92
     }
@@ -95,18 +95,18 @@  discard block
 block discarded – undo
95 95
      * notices function.
96 96
      */
97 97
     public static function notices() {
98
-        if ( ! function_exists( 'w3tc_pgcache_flush' ) || ! function_exists( 'w3_instance' ) ) {
98
+        if (!function_exists('w3tc_pgcache_flush') || !function_exists('w3_instance')) {
99 99
             return;
100 100
         }
101 101
 
102
-        $config   = w3_instance( 'W3_Config' );
103
-        $enabled  = $config->get_integer( 'dbcache.enabled' );
104
-        $settings = array_map( 'trim', $config->get_array( 'dbcache.reject.sql' ) );
102
+        $config   = w3_instance('W3_Config');
103
+        $enabled  = $config->get_integer('dbcache.enabled');
104
+        $settings = array_map('trim', $config->get_array('dbcache.reject.sql'));
105 105
 
106
-        if ( $enabled && ! in_array( '_wp_session_', $settings ) ) {
106
+        if ($enabled && !in_array('_wp_session_', $settings)) {
107 107
             ?>
108 108
             <div class="error">
109
-                <p><?php printf( __( 'In order for <strong>database caching</strong> to work with Invoicing you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'invoicing' ), '<code>_wp_session_</code>', admin_url( 'admin.php?page=w3tc_dbcache' ) ); ?></p>
109
+                <p><?php printf(__('In order for <strong>database caching</strong> to work with Invoicing you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'invoicing'), '<code>_wp_session_</code>', admin_url('admin.php?page=w3tc_dbcache')); ?></p>
110 110
             </div>
111 111
             <?php
112 112
         }
Please login to merge, or discard this patch.
includes/wpinv-discount-functions.php 1 patch
Spacing   +470 added lines, -470 removed lines patch added patch discarded remove patch
@@ -7,90 +7,90 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_get_discount_types() {
15 15
     $discount_types = array(
16
-                        'percent'   => __( 'Percentage', 'invoicing' ),
17
-                        'flat'     => __( 'Flat Amount', 'invoicing' ),
16
+                        'percent'   => __('Percentage', 'invoicing'),
17
+                        'flat'     => __('Flat Amount', 'invoicing'),
18 18
                     );
19
-    return (array)apply_filters( 'wpinv_discount_types', $discount_types );
19
+    return (array)apply_filters('wpinv_discount_types', $discount_types);
20 20
 }
21 21
 
22
-function wpinv_get_discount_type_name( $type = '' ) {
22
+function wpinv_get_discount_type_name($type = '') {
23 23
     $types = wpinv_get_discount_types();
24
-    return isset( $types[ $type ] ) ? $types[ $type ] : '';
24
+    return isset($types[$type]) ? $types[$type] : '';
25 25
 }
26 26
 
27
-function wpinv_delete_discount( $data ) {
28
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
29
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
27
+function wpinv_delete_discount($data) {
28
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
29
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
30 30
     }
31 31
 
32
-    if( ! current_user_can( 'manage_options' ) ) {
33
-        wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
32
+    if (!current_user_can('manage_options')) {
33
+        wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
34 34
     }
35 35
 
36 36
     $discount_id = $data['discount'];
37
-    wpinv_remove_discount( $discount_id );
37
+    wpinv_remove_discount($discount_id);
38 38
 }
39
-add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' );
39
+add_action('wpinv_delete_discount', 'wpinv_delete_discount');
40 40
 
41
-function wpinv_activate_discount( $data ) {
42
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
43
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
41
+function wpinv_activate_discount($data) {
42
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
43
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
44 44
     }
45 45
 
46
-    if( ! current_user_can( 'manage_options' ) ) {
47
-        wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
46
+    if (!current_user_can('manage_options')) {
47
+        wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
48 48
     }
49 49
 
50
-    $id = absint( $data['discount'] );
51
-    wpinv_update_discount_status( $id, 'publish' );
50
+    $id = absint($data['discount']);
51
+    wpinv_update_discount_status($id, 'publish');
52 52
 }
53
-add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' );
53
+add_action('wpinv_activate_discount', 'wpinv_activate_discount');
54 54
 
55
-function wpinv_deactivate_discount( $data ) {
56
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
57
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_deactivate_discount($data) {
56
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
57
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
 
60
-    if( ! current_user_can( 'manage_options' ) ) {
61
-        wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) );
60
+    if (!current_user_can('manage_options')) {
61
+        wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403));
62 62
     }
63 63
 
64
-    $id = absint( $data['discount'] );
65
-    wpinv_update_discount_status( $id, 'pending' );
64
+    $id = absint($data['discount']);
65
+    wpinv_update_discount_status($id, 'pending');
66 66
 }
67
-add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' );
67
+add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount');
68 68
 
69
-function wpinv_get_discounts( $args = array() ) {
69
+function wpinv_get_discounts($args = array()) {
70 70
     $defaults = array(
71 71
         'post_type'      => 'wpi_discount',
72 72
         'posts_per_page' => 20,
73 73
         'paged'          => null,
74
-        'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
74
+        'post_status'    => array('publish', 'pending', 'draft', 'expired')
75 75
     );
76 76
 
77
-    $args = wp_parse_args( $args, $defaults );
77
+    $args = wp_parse_args($args, $defaults);
78 78
 
79
-    $discounts = get_posts( $args );
79
+    $discounts = get_posts($args);
80 80
 
81
-    if ( $discounts ) {
81
+    if ($discounts) {
82 82
         return $discounts;
83 83
     }
84 84
 
85
-    if( ! $discounts && ! empty( $args['s'] ) ) {
85
+    if (!$discounts && !empty($args['s'])) {
86 86
         $args['meta_key']     = '_wpi_discount_code';
87 87
         $args['meta_value']   = $args['s'];
88 88
         $args['meta_compare'] = 'LIKE';
89
-        unset( $args['s'] );
90
-        $discounts = get_posts( $args );
89
+        unset($args['s']);
90
+        $discounts = get_posts($args);
91 91
     }
92 92
 
93
-    if( $discounts ) {
93
+    if ($discounts) {
94 94
         return $discounts;
95 95
     }
96 96
 
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 
103 103
     $discounts  = wpinv_get_discounts();
104 104
 
105
-    if ( $discounts) {
106
-        foreach ( $discounts as $discount ) {
107
-            if ( wpinv_is_discount_active( $discount->ID ) ) {
105
+    if ($discounts) {
106
+        foreach ($discounts as $discount) {
107
+            if (wpinv_is_discount_active($discount->ID)) {
108 108
                 $has_active = true;
109 109
                 break;
110 110
             }
@@ -113,38 +113,38 @@  discard block
 block discarded – undo
113 113
     return $has_active;
114 114
 }
115 115
 
116
-function wpinv_get_discount( $discount_id = 0 ) {
117
-    if( empty( $discount_id ) ) {
116
+function wpinv_get_discount($discount_id = 0) {
117
+    if (empty($discount_id)) {
118 118
         return false;
119 119
     }
120 120
     
121
-    if ( get_post_type( $discount_id ) != 'wpi_discount' ) {
121
+    if (get_post_type($discount_id) != 'wpi_discount') {
122 122
         return false;
123 123
     }
124 124
 
125
-    $discount = get_post( $discount_id );
125
+    $discount = get_post($discount_id);
126 126
 
127 127
     return $discount;
128 128
 }
129 129
 
130
-function wpinv_get_discount_by_code( $code = '' ) {
131
-    if( empty( $code ) || ! is_string( $code ) ) {
130
+function wpinv_get_discount_by_code($code = '') {
131
+    if (empty($code) || !is_string($code)) {
132 132
         return false;
133 133
     }
134 134
 
135
-    return wpinv_get_discount_by( 'code', $code );
135
+    return wpinv_get_discount_by('code', $code);
136 136
 }
137 137
 
138
-function wpinv_get_discount_by( $field = '', $value = '' ) {
139
-    if( empty( $field ) || empty( $value ) ) {
138
+function wpinv_get_discount_by($field = '', $value = '') {
139
+    if (empty($field) || empty($value)) {
140 140
         return false;
141 141
     }
142 142
 
143
-    if( ! is_string( $field ) ) {
143
+    if (!is_string($field)) {
144 144
         return false;
145 145
     }
146 146
 
147
-    switch( strtolower( $field ) ) {
147
+    switch (strtolower($field)) {
148 148
 
149 149
         case 'code':
150 150
             $meta_query     = array();
@@ -154,32 +154,32 @@  discard block
 block discarded – undo
154 154
                 'compare' => '='
155 155
             );
156 156
             
157
-            $discount = wpinv_get_discounts( array(
157
+            $discount = wpinv_get_discounts(array(
158 158
                 'posts_per_page' => 1,
159 159
                 'post_status'    => 'any',
160 160
                 'meta_query'     => $meta_query,
161
-            ) );
161
+            ));
162 162
             
163
-            if( $discount ) {
163
+            if ($discount) {
164 164
                 $discount = $discount[0];
165 165
             }
166 166
 
167 167
             break;
168 168
 
169 169
         case 'id':
170
-            $discount = wpinv_get_discount( $value );
170
+            $discount = wpinv_get_discount($value);
171 171
 
172 172
             break;
173 173
 
174 174
         case 'name':
175
-            $discount = get_posts( array(
175
+            $discount = get_posts(array(
176 176
                 'post_type'      => 'wpi_discount',
177 177
                 'name'           => $value,
178 178
                 'posts_per_page' => 1,
179 179
                 'post_status'    => 'any'
180
-            ) );
180
+            ));
181 181
 
182
-            if( $discount ) {
182
+            if ($discount) {
183 183
                 $discount = $discount[0];
184 184
             }
185 185
 
@@ -189,96 +189,96 @@  discard block
 block discarded – undo
189 189
             return false;
190 190
     }
191 191
 
192
-    if( ! empty( $discount ) ) {
192
+    if (!empty($discount)) {
193 193
         return $discount;
194 194
     }
195 195
 
196 196
     return false;
197 197
 }
198 198
 
199
-function wpinv_store_discount( $post_id, $data, $post, $update = false ) {
199
+function wpinv_store_discount($post_id, $data, $post, $update = false) {
200 200
     $meta = array(
201
-        'code'              => isset( $data['code'] )             ? sanitize_text_field( $data['code'] )              : '',
202
-        'type'              => isset( $data['type'] )             ? sanitize_text_field( $data['type'] )              : 'percent',
203
-        'amount'            => isset( $data['amount'] )           ? wpinv_sanitize_amount( $data['amount'] )          : '',
204
-        'start'             => isset( $data['start'] )            ? sanitize_text_field( $data['start'] )             : '',
205
-        'expiration'        => isset( $data['expiration'] )       ? sanitize_text_field( $data['expiration'] )        : '',
206
-        'min_total'         => isset( $data['min_total'] )        ? wpinv_sanitize_amount( $data['min_total'] )       : '',
207
-        'max_total'         => isset( $data['max_total'] )        ? wpinv_sanitize_amount( $data['max_total'] )       : '',
208
-        'max_uses'          => isset( $data['max_uses'] )         ? absint( $data['max_uses'] )                       : '',
209
-        'items'             => isset( $data['items'] )            ? $data['items']                                    : array(),
210
-        'excluded_items'    => isset( $data['excluded_items'] )   ? $data['excluded_items']                           : array(),
211
-        'is_recurring'      => isset( $data['recurring'] )        ? (bool)$data['recurring']                          : false,
212
-        'is_single_use'     => isset( $data['single_use'] )       ? (bool)$data['single_use']                         : false,
213
-        'uses'              => isset( $data['uses'] )             ? (int)$data['uses']                                : false,
201
+        'code'              => isset($data['code']) ? sanitize_text_field($data['code']) : '',
202
+        'type'              => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent',
203
+        'amount'            => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '',
204
+        'start'             => isset($data['start']) ? sanitize_text_field($data['start']) : '',
205
+        'expiration'        => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '',
206
+        'min_total'         => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '',
207
+        'max_total'         => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '',
208
+        'max_uses'          => isset($data['max_uses']) ? absint($data['max_uses']) : '',
209
+        'items'             => isset($data['items']) ? $data['items'] : array(),
210
+        'excluded_items'    => isset($data['excluded_items']) ? $data['excluded_items'] : array(),
211
+        'is_recurring'      => isset($data['recurring']) ? (bool)$data['recurring'] : false,
212
+        'is_single_use'     => isset($data['single_use']) ? (bool)$data['single_use'] : false,
213
+        'uses'              => isset($data['uses']) ? (int)$data['uses'] : false,
214 214
     );
215 215
 
216
-    if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) {
216
+    if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) {
217 217
         $meta['amount'] = 100;
218 218
     }
219 219
 
220
-    if ( !empty( $meta['start'] ) ) {
221
-        $meta['start']      = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['start'] ) );
220
+    if (!empty($meta['start'])) {
221
+        $meta['start'] = date_i18n('Y-m-d H:i:s', strtotime($meta['start']));
222 222
     }
223 223
 
224
-    if ( !empty( $meta['expiration'] ) ) {
225
-        $meta['expiration'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['expiration'] ) );
224
+    if (!empty($meta['expiration'])) {
225
+        $meta['expiration'] = date_i18n('Y-m-d H:i:s', strtotime($meta['expiration']));
226 226
 
227
-        if ( !empty( $meta['start'] ) && strtotime( $meta['start'] ) > strtotime( $meta['expiration'] ) ) {
227
+        if (!empty($meta['start']) && strtotime($meta['start']) > strtotime($meta['expiration'])) {
228 228
             $meta['expiration'] = $meta['start'];
229 229
         }
230 230
     }
231 231
     
232
-    if ( $meta['uses'] === false ) {
233
-        unset( $meta['uses'] );
232
+    if ($meta['uses'] === false) {
233
+        unset($meta['uses']);
234 234
     }
235 235
     
236
-    if ( ! empty( $meta['items'] ) ) {
237
-        foreach ( $meta['items'] as $key => $item ) {
238
-            if ( 0 === intval( $item ) ) {
239
-                unset( $meta['items'][ $key ] );
236
+    if (!empty($meta['items'])) {
237
+        foreach ($meta['items'] as $key => $item) {
238
+            if (0 === intval($item)) {
239
+                unset($meta['items'][$key]);
240 240
             }
241 241
         }
242 242
     }
243 243
     
244
-    if ( ! empty( $meta['excluded_items'] ) ) {
245
-        foreach ( $meta['excluded_items'] as $key => $item ) {
246
-            if ( 0 === intval( $item ) ) {
247
-                unset( $meta['excluded_items'][ $key ] );
244
+    if (!empty($meta['excluded_items'])) {
245
+        foreach ($meta['excluded_items'] as $key => $item) {
246
+            if (0 === intval($item)) {
247
+                unset($meta['excluded_items'][$key]);
248 248
             }
249 249
         }
250 250
     }
251 251
     
252
-    $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post );
252
+    $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post);
253 253
     
254
-    do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post );
254
+    do_action('wpinv_pre_update_discount', $meta, $post_id, $post);
255 255
     
256
-    foreach( $meta as $key => $value ) {
257
-        update_post_meta( $post_id, '_wpi_discount_' . $key, $value );
256
+    foreach ($meta as $key => $value) {
257
+        update_post_meta($post_id, '_wpi_discount_' . $key, $value);
258 258
     }
259 259
     
260
-    do_action( 'wpinv_post_update_discount', $meta, $post_id, $post );
260
+    do_action('wpinv_post_update_discount', $meta, $post_id, $post);
261 261
     
262 262
     return $post_id;
263 263
 }
264 264
 
265
-function wpinv_remove_discount( $discount_id = 0 ) {
266
-    do_action( 'wpinv_pre_delete_discount', $discount_id );
265
+function wpinv_remove_discount($discount_id = 0) {
266
+    do_action('wpinv_pre_delete_discount', $discount_id);
267 267
 
268
-    wp_delete_post( $discount_id, true );
268
+    wp_delete_post($discount_id, true);
269 269
 
270
-    do_action( 'wpinv_post_delete_discount', $discount_id );
270
+    do_action('wpinv_post_delete_discount', $discount_id);
271 271
 }
272 272
 
273
-function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) {
274
-    $discount = wpinv_get_discount(  $code_id );
273
+function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') {
274
+    $discount = wpinv_get_discount($code_id);
275 275
 
276
-    if ( $discount ) {
277
-        do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status );
276
+    if ($discount) {
277
+        do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status);
278 278
 
279
-        wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) );
279
+        wp_update_post(array('ID' => $code_id, 'post_status' => $new_status));
280 280
 
281
-        do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status );
281
+        do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status);
282 282
 
283 283
         return true;
284 284
     }
@@ -286,173 +286,173 @@  discard block
 block discarded – undo
286 286
     return false;
287 287
 }
288 288
 
289
-function wpinv_discount_exists( $code_id ) {
290
-    if ( wpinv_get_discount(  $code_id ) ) {
289
+function wpinv_discount_exists($code_id) {
290
+    if (wpinv_get_discount($code_id)) {
291 291
         return true;
292 292
     }
293 293
 
294 294
     return false;
295 295
 }
296 296
 
297
-function wpinv_is_discount_active( $code_id = null ) {
298
-    $discount = wpinv_get_discount(  $code_id );
297
+function wpinv_is_discount_active($code_id = null) {
298
+    $discount = wpinv_get_discount($code_id);
299 299
     $return   = false;
300 300
 
301
-    if ( $discount ) {
302
-        if ( wpinv_is_discount_expired( $code_id ) ) {
303
-            if( defined( 'DOING_AJAX' ) ) {
304
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) );
301
+    if ($discount) {
302
+        if (wpinv_is_discount_expired($code_id)) {
303
+            if (defined('DOING_AJAX')) {
304
+                wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing'));
305 305
             }
306
-        } elseif ( $discount->post_status == 'publish' ) {
306
+        } elseif ($discount->post_status == 'publish') {
307 307
             $return = true;
308 308
         } else {
309
-            if( defined( 'DOING_AJAX' ) ) {
310
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) );
309
+            if (defined('DOING_AJAX')) {
310
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing'));
311 311
             }
312 312
         }
313 313
     }
314 314
 
315
-    return apply_filters( 'wpinv_is_discount_active', $return, $code_id );
315
+    return apply_filters('wpinv_is_discount_active', $return, $code_id);
316 316
 }
317 317
 
318
-function wpinv_get_discount_code( $code_id = null ) {
319
-    $code = get_post_meta( $code_id, '_wpi_discount_code', true );
318
+function wpinv_get_discount_code($code_id = null) {
319
+    $code = get_post_meta($code_id, '_wpi_discount_code', true);
320 320
 
321
-    return apply_filters( 'wpinv_get_discount_code', $code, $code_id );
321
+    return apply_filters('wpinv_get_discount_code', $code, $code_id);
322 322
 }
323 323
 
324
-function wpinv_get_discount_start_date( $code_id = null ) {
325
-    $start_date = get_post_meta( $code_id, '_wpi_discount_start', true );
324
+function wpinv_get_discount_start_date($code_id = null) {
325
+    $start_date = get_post_meta($code_id, '_wpi_discount_start', true);
326 326
 
327
-    return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id );
327
+    return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id);
328 328
 }
329 329
 
330
-function wpinv_get_discount_expiration( $code_id = null ) {
331
-    $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true );
330
+function wpinv_get_discount_expiration($code_id = null) {
331
+    $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true);
332 332
 
333
-    return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id );
333
+    return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id);
334 334
 }
335 335
 
336
-function wpinv_get_discount_max_uses( $code_id = null ) {
337
-    $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true );
336
+function wpinv_get_discount_max_uses($code_id = null) {
337
+    $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true);
338 338
 
339
-    return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id );
339
+    return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id);
340 340
 }
341 341
 
342
-function wpinv_get_discount_uses( $code_id = null ) {
343
-    $uses = get_post_meta( $code_id, '_wpi_discount_uses', true );
342
+function wpinv_get_discount_uses($code_id = null) {
343
+    $uses = get_post_meta($code_id, '_wpi_discount_uses', true);
344 344
 
345
-    return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id );
345
+    return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id);
346 346
 }
347 347
 
348
-function wpinv_get_discount_min_total( $code_id = null ) {
349
-    $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true );
348
+function wpinv_get_discount_min_total($code_id = null) {
349
+    $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true);
350 350
 
351
-    return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id );
351
+    return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id);
352 352
 }
353 353
 
354
-function wpinv_get_discount_max_total( $code_id = null ) {
355
-    $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true );
354
+function wpinv_get_discount_max_total($code_id = null) {
355
+    $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true);
356 356
 
357
-    return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id );
357
+    return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id);
358 358
 }
359 359
 
360
-function wpinv_get_discount_amount( $code_id = null ) {
361
-    $amount = get_post_meta( $code_id, '_wpi_discount_amount', true );
360
+function wpinv_get_discount_amount($code_id = null) {
361
+    $amount = get_post_meta($code_id, '_wpi_discount_amount', true);
362 362
 
363
-    return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id );
363
+    return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id);
364 364
 }
365 365
 
366
-function wpinv_get_discount_type( $code_id = null, $name = false ) {
367
-    $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) );
366
+function wpinv_get_discount_type($code_id = null, $name = false) {
367
+    $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true));
368 368
     
369
-    if ( $name ) {
370
-        $name = wpinv_get_discount_type_name( $type );
369
+    if ($name) {
370
+        $name = wpinv_get_discount_type_name($type);
371 371
         
372
-        return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id );
372
+        return apply_filters('wpinv_get_discount_type_name', $name, $code_id);
373 373
     }
374 374
 
375
-    return apply_filters( 'wpinv_get_discount_type', $type, $code_id );
375
+    return apply_filters('wpinv_get_discount_type', $type, $code_id);
376 376
 }
377 377
 
378
-function wpinv_discount_status( $status ) {
379
-    switch( $status ){
378
+function wpinv_discount_status($status) {
379
+    switch ($status) {
380 380
         case 'expired' :
381
-            $name = __( 'Expired', 'invoicing' );
381
+            $name = __('Expired', 'invoicing');
382 382
             break;
383 383
         case 'publish' :
384 384
         case 'active' :
385
-            $name = __( 'Active', 'invoicing' );
385
+            $name = __('Active', 'invoicing');
386 386
             break;
387 387
         default :
388
-            $name = __( 'Inactive', 'invoicing' );
388
+            $name = __('Inactive', 'invoicing');
389 389
             break;
390 390
     }
391 391
     return $name;
392 392
 }
393 393
 
394
-function wpinv_get_discount_excluded_items( $code_id = null ) {
395
-    $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true );
394
+function wpinv_get_discount_excluded_items($code_id = null) {
395
+    $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true);
396 396
 
397
-    if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) {
397
+    if (empty($excluded_items) || !is_array($excluded_items)) {
398 398
         $excluded_items = array();
399 399
     }
400 400
 
401
-    return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id );
401
+    return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id);
402 402
 }
403 403
 
404
-function wpinv_get_discount_item_reqs( $code_id = null ) {
405
-    $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true );
404
+function wpinv_get_discount_item_reqs($code_id = null) {
405
+    $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true);
406 406
 
407
-    if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) {
407
+    if (empty($item_reqs) || !is_array($item_reqs)) {
408 408
         $item_reqs = array();
409 409
     }
410 410
 
411
-    return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id );
411
+    return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id);
412 412
 }
413 413
 
414
-function wpinv_get_discount_item_condition( $code_id = 0 ) {
415
-    return get_post_meta( $code_id, '_wpi_discount_item_condition', true );
414
+function wpinv_get_discount_item_condition($code_id = 0) {
415
+    return get_post_meta($code_id, '_wpi_discount_item_condition', true);
416 416
 }
417 417
 
418
-function wpinv_is_discount_not_global( $code_id = 0 ) {
419
-    return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true );
418
+function wpinv_is_discount_not_global($code_id = 0) {
419
+    return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true);
420 420
 }
421 421
 
422
-function wpinv_is_discount_expired( $code_id = null ) {
423
-    $discount = wpinv_get_discount(  $code_id );
422
+function wpinv_is_discount_expired($code_id = null) {
423
+    $discount = wpinv_get_discount($code_id);
424 424
     $return   = false;
425 425
 
426
-    if ( $discount ) {
427
-        $expiration = wpinv_get_discount_expiration( $code_id );
428
-        if ( $expiration ) {
429
-            $expiration = strtotime( $expiration );
430
-            if ( $expiration < current_time( 'timestamp' ) ) {
426
+    if ($discount) {
427
+        $expiration = wpinv_get_discount_expiration($code_id);
428
+        if ($expiration) {
429
+            $expiration = strtotime($expiration);
430
+            if ($expiration < current_time('timestamp')) {
431 431
                 // Discount is expired
432
-                wpinv_update_discount_status( $code_id, 'pending' );
432
+                wpinv_update_discount_status($code_id, 'pending');
433 433
                 $return = true;
434 434
             }
435 435
         }
436 436
     }
437 437
 
438
-    return apply_filters( 'wpinv_is_discount_expired', $return, $code_id );
438
+    return apply_filters('wpinv_is_discount_expired', $return, $code_id);
439 439
 }
440 440
 
441
-function wpinv_is_discount_started( $code_id = null ) {
442
-    $discount = wpinv_get_discount(  $code_id );
441
+function wpinv_is_discount_started($code_id = null) {
442
+    $discount = wpinv_get_discount($code_id);
443 443
     $return   = false;
444 444
 
445
-    if ( $discount ) {
446
-        $start_date = wpinv_get_discount_start_date( $code_id );
445
+    if ($discount) {
446
+        $start_date = wpinv_get_discount_start_date($code_id);
447 447
 
448
-        if ( $start_date ) {
449
-            $start_date = strtotime( $start_date );
448
+        if ($start_date) {
449
+            $start_date = strtotime($start_date);
450 450
 
451
-            if ( $start_date < current_time( 'timestamp' ) ) {
451
+            if ($start_date < current_time('timestamp')) {
452 452
                 // Discount has past the start date
453 453
                 $return = true;
454 454
             } else {
455
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
455
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
456 456
             }
457 457
         } else {
458 458
             // No start date for this discount, so has to be true
@@ -460,159 +460,159 @@  discard block
 block discarded – undo
460 460
         }
461 461
     }
462 462
 
463
-    return apply_filters( 'wpinv_is_discount_started', $return, $code_id );
463
+    return apply_filters('wpinv_is_discount_started', $return, $code_id);
464 464
 }
465 465
 
466
-function wpinv_check_discount_dates( $code_id = null ) {
467
-    $discount = wpinv_get_discount(  $code_id );
466
+function wpinv_check_discount_dates($code_id = null) {
467
+    $discount = wpinv_get_discount($code_id);
468 468
     $return   = false;
469 469
 
470
-    if ( $discount ) {
471
-        $start_date = wpinv_get_discount_start_date( $code_id );
470
+    if ($discount) {
471
+        $start_date = wpinv_get_discount_start_date($code_id);
472 472
 
473
-        if ( $start_date ) {
474
-            $start_date = strtotime( $start_date );
473
+        if ($start_date) {
474
+            $start_date = strtotime($start_date);
475 475
 
476
-            if ( $start_date < current_time( 'timestamp' ) ) {
476
+            if ($start_date < current_time('timestamp')) {
477 477
                 // Discount has past the start date
478 478
                 $return = true;
479 479
             } else {
480
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
480
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
481 481
             }
482 482
         } else {
483 483
             // No start date for this discount, so has to be true
484 484
             $return = true;
485 485
         }
486 486
         
487
-        if ( $return ) {
488
-            $expiration = wpinv_get_discount_expiration( $code_id );
487
+        if ($return) {
488
+            $expiration = wpinv_get_discount_expiration($code_id);
489 489
             
490
-            if ( $expiration ) {
491
-                $expiration = strtotime( $expiration );
492
-                if ( $expiration < current_time( 'timestamp' ) ) {
490
+            if ($expiration) {
491
+                $expiration = strtotime($expiration);
492
+                if ($expiration < current_time('timestamp')) {
493 493
                     // Discount is expired
494
-                    wpinv_update_discount_status( $code_id, 'pending' );
494
+                    wpinv_update_discount_status($code_id, 'pending');
495 495
                     $return = true;
496 496
                 }
497 497
             }
498 498
         }
499 499
     }
500 500
     
501
-    return apply_filters( 'wpinv_check_discount_dates', $return, $code_id );
501
+    return apply_filters('wpinv_check_discount_dates', $return, $code_id);
502 502
 }
503 503
 
504
-function wpinv_is_discount_maxed_out( $code_id = null ) {
505
-    $discount = wpinv_get_discount(  $code_id );
504
+function wpinv_is_discount_maxed_out($code_id = null) {
505
+    $discount = wpinv_get_discount($code_id);
506 506
     $return   = false;
507 507
 
508
-    if ( $discount ) {
509
-        $uses = wpinv_get_discount_uses( $code_id );
508
+    if ($discount) {
509
+        $uses = wpinv_get_discount_uses($code_id);
510 510
         // Large number that will never be reached
511
-        $max_uses = wpinv_get_discount_max_uses( $code_id );
511
+        $max_uses = wpinv_get_discount_max_uses($code_id);
512 512
         // Should never be greater than, but just in case
513
-        if ( $uses >= $max_uses && ! empty( $max_uses ) ) {
513
+        if ($uses >= $max_uses && !empty($max_uses)) {
514 514
             // Discount is maxed out
515
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) );
515
+            wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing'));
516 516
             $return = true;
517 517
         }
518 518
     }
519 519
 
520
-    return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id );
520
+    return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id);
521 521
 }
522 522
 
523
-function wpinv_discount_is_min_met( $code_id = null ) {
524
-    $discount = wpinv_get_discount( $code_id );
523
+function wpinv_discount_is_min_met($code_id = null) {
524
+    $discount = wpinv_get_discount($code_id);
525 525
     $return   = false;
526 526
 
527
-    if ( $discount ) {
528
-        $min         = (float)wpinv_get_discount_min_total( $code_id );
529
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
527
+    if ($discount) {
528
+        $min         = (float)wpinv_get_discount_min_total($code_id);
529
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
530 530
 
531
-        if ( !$min > 0 || $cart_amount >= $min ) {
531
+        if (!$min > 0 || $cart_amount >= $min) {
532 532
             // Minimum has been met
533 533
             $return = true;
534 534
         } else {
535
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) );
535
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($min))));
536 536
         }
537 537
     }
538 538
 
539
-    return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id );
539
+    return apply_filters('wpinv_is_discount_min_met', $return, $code_id);
540 540
 }
541 541
 
542
-function wpinv_discount_is_max_met( $code_id = null ) {
543
-    $discount = wpinv_get_discount( $code_id );
542
+function wpinv_discount_is_max_met($code_id = null) {
543
+    $discount = wpinv_get_discount($code_id);
544 544
     $return   = false;
545 545
 
546
-    if ( $discount ) {
547
-        $max         = (float)wpinv_get_discount_max_total( $code_id );
548
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
546
+    if ($discount) {
547
+        $max         = (float)wpinv_get_discount_max_total($code_id);
548
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
549 549
 
550
-        if ( !$max > 0 || $cart_amount <= $max ) {
550
+        if (!$max > 0 || $cart_amount <= $max) {
551 551
             // Minimum has been met
552 552
             $return = true;
553 553
         } else {
554
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) );
554
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($max))));
555 555
         }
556 556
     }
557 557
 
558
-    return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id );
558
+    return apply_filters('wpinv_is_discount_max_met', $return, $code_id);
559 559
 }
560 560
 
561
-function wpinv_discount_is_single_use( $code_id = 0 ) {
562
-    $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true );
563
-    return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id );
561
+function wpinv_discount_is_single_use($code_id = 0) {
562
+    $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true);
563
+    return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id);
564 564
 }
565 565
 
566
-function wpinv_discount_is_recurring( $code_id = 0, $code = false ) {
567
-    if ( $code ) {
568
-        $discount = wpinv_get_discount_by_code( $code_id );
566
+function wpinv_discount_is_recurring($code_id = 0, $code = false) {
567
+    if ($code) {
568
+        $discount = wpinv_get_discount_by_code($code_id);
569 569
         
570
-        if ( !empty( $discount ) ) {
570
+        if (!empty($discount)) {
571 571
             $code_id = $discount->ID;
572 572
         }
573 573
     }
574 574
     
575
-    $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true );
575
+    $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true);
576 576
     
577
-    return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code );
577
+    return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code);
578 578
 }
579 579
 
580
-function wpinv_discount_item_reqs_met( $code_id = null ) {
581
-    $item_reqs    = wpinv_get_discount_item_reqs( $code_id );
582
-    $condition    = wpinv_get_discount_item_condition( $code_id );
583
-    $excluded_ps  = wpinv_get_discount_excluded_items( $code_id );
580
+function wpinv_discount_item_reqs_met($code_id = null) {
581
+    $item_reqs    = wpinv_get_discount_item_reqs($code_id);
582
+    $condition    = wpinv_get_discount_item_condition($code_id);
583
+    $excluded_ps  = wpinv_get_discount_excluded_items($code_id);
584 584
     $cart_items   = wpinv_get_cart_contents();
585
-    $cart_ids     = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null;
585
+    $cart_ids     = $cart_items ? wp_list_pluck($cart_items, 'id') : null;
586 586
     $ret          = false;
587 587
 
588
-    if ( empty( $item_reqs ) && empty( $excluded_ps ) ) {
588
+    if (empty($item_reqs) && empty($excluded_ps)) {
589 589
         $ret = true;
590 590
     }
591 591
 
592 592
     // Normalize our data for item requirements, exclusions and cart data
593 593
     // First absint the items, then sort, and reset the array keys
594
-    $item_reqs = array_map( 'absint', $item_reqs );
595
-    asort( $item_reqs );
596
-    $item_reqs = array_values( $item_reqs );
594
+    $item_reqs = array_map('absint', $item_reqs);
595
+    asort($item_reqs);
596
+    $item_reqs = array_values($item_reqs);
597 597
 
598
-    $excluded_ps  = array_map( 'absint', $excluded_ps );
599
-    asort( $excluded_ps );
600
-    $excluded_ps  = array_values( $excluded_ps );
598
+    $excluded_ps  = array_map('absint', $excluded_ps);
599
+    asort($excluded_ps);
600
+    $excluded_ps  = array_values($excluded_ps);
601 601
 
602
-    $cart_ids     = array_map( 'absint', $cart_ids );
603
-    asort( $cart_ids );
604
-    $cart_ids     = array_values( $cart_ids );
602
+    $cart_ids     = array_map('absint', $cart_ids);
603
+    asort($cart_ids);
604
+    $cart_ids     = array_values($cart_ids);
605 605
 
606 606
     // Ensure we have requirements before proceeding
607
-    if ( !$ret && ! empty( $item_reqs ) ) {
608
-        switch( $condition ) {
607
+    if (!$ret && !empty($item_reqs)) {
608
+        switch ($condition) {
609 609
             case 'all' :
610 610
                 // Default back to true
611 611
                 $ret = true;
612 612
 
613
-                foreach ( $item_reqs as $item_id ) {
614
-                    if ( !wpinv_item_in_cart( $item_id ) ) {
615
-                        wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
613
+                foreach ($item_reqs as $item_id) {
614
+                    if (!wpinv_item_in_cart($item_id)) {
615
+                        wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
616 616
                         $ret = false;
617 617
                         break;
618 618
                     }
@@ -621,15 +621,15 @@  discard block
 block discarded – undo
621 621
                 break;
622 622
 
623 623
             default : // Any
624
-                foreach ( $item_reqs as $item_id ) {
625
-                    if ( wpinv_item_in_cart( $item_id ) ) {
624
+                foreach ($item_reqs as $item_id) {
625
+                    if (wpinv_item_in_cart($item_id)) {
626 626
                         $ret = true;
627 627
                         break;
628 628
                     }
629 629
                 }
630 630
 
631
-                if( ! $ret ) {
632
-                    wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
631
+                if (!$ret) {
632
+                    wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
633 633
                 }
634 634
 
635 635
                 break;
@@ -638,70 +638,70 @@  discard block
 block discarded – undo
638 638
         $ret = true;
639 639
     }
640 640
 
641
-    if( ! empty( $excluded_ps ) ) {
641
+    if (!empty($excluded_ps)) {
642 642
         // Check that there are items other than excluded ones in the cart
643
-        if( $cart_ids == $excluded_ps ) {
644
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) );
643
+        if ($cart_ids == $excluded_ps) {
644
+            wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing'));
645 645
             $ret = false;
646 646
         }
647 647
     }
648 648
 
649
-    return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition );
649
+    return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition);
650 650
 }
651 651
 
652
-function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) {
652
+function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) {
653 653
     global $wpi_checkout_id;
654 654
     
655 655
     $return = false;
656 656
 
657
-    if ( empty( $code_id ) ) {
658
-        $code_id = wpinv_get_discount_id_by_code( $code );
657
+    if (empty($code_id)) {
658
+        $code_id = wpinv_get_discount_id_by_code($code);
659 659
         
660
-        if( empty( $code_id ) ) {
660
+        if (empty($code_id)) {
661 661
             return false; // No discount was found
662 662
         }
663 663
     }
664 664
 
665
-    if ( wpinv_discount_is_single_use( $code_id ) ) {
665
+    if (wpinv_discount_is_single_use($code_id)) {
666 666
         $payments = array();
667 667
 
668 668
         $user_id = 0;
669
-        if ( is_int( $user ) ) {
670
-            $user_id = absint( $user );
671
-        } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
669
+        if (is_int($user)) {
670
+            $user_id = absint($user);
671
+        } else if (is_email($user) && $user_data = get_user_by('email', $user)) {
672 672
             $user_id = $user_data->ID;
673
-        } else if ( $user_data = get_user_by( 'login', $user ) ) {
673
+        } else if ($user_data = get_user_by('login', $user)) {
674 674
             $user_id = $user_data->ID;
675
-        } else if ( absint( $user ) > 0 ) {
676
-            $user_id = absint( $user );
675
+        } else if (absint($user) > 0) {
676
+            $user_id = absint($user);
677 677
         }
678 678
 
679
-        if ( !empty( $user_id ) ) {
680
-            $query    = array( 'user' => $user_id, 'limit' => false );
681
-            $payments = wpinv_get_invoices( $query ); // Get all payments with matching user id
679
+        if (!empty($user_id)) {
680
+            $query    = array('user' => $user_id, 'limit' => false);
681
+            $payments = wpinv_get_invoices($query); // Get all payments with matching user id
682 682
         }
683 683
 
684
-        if ( $payments ) {
685
-            foreach ( $payments as $payment ) {
684
+        if ($payments) {
685
+            foreach ($payments as $payment) {
686 686
                 // Don't count discount used for current invoice chekcout.
687
-                if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
687
+                if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) {
688 688
                     continue;
689 689
                 }
690 690
                 
691
-                if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) {
691
+                if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) {
692 692
                     continue;
693 693
                 }
694 694
 
695
-                $discounts = $payment->get_discounts( true );
696
-                if ( empty( $discounts ) ) {
695
+                $discounts = $payment->get_discounts(true);
696
+                if (empty($discounts)) {
697 697
                     continue;
698 698
                 }
699 699
 
700
-                $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts;
700
+                $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts;
701 701
 
702
-                if ( !empty( $discounts ) && is_array( $discounts ) ) {
703
-                    if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) {
704
-                        wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) );
702
+                if (!empty($discounts) && is_array($discounts)) {
703
+                    if (in_array(strtolower($code), array_map('strtolower', $discounts))) {
704
+                        wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing'));
705 705
                         $return = true;
706 706
                         break;
707 707
                     }
@@ -710,61 +710,61 @@  discard block
 block discarded – undo
710 710
         }
711 711
     }
712 712
 
713
-    return apply_filters( 'wpinv_is_discount_used', $return, $code, $user );
713
+    return apply_filters('wpinv_is_discount_used', $return, $code, $user);
714 714
 }
715 715
 
716
-function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) {
716
+function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) {
717 717
     $return      = false;
718
-    $discount_id = wpinv_get_discount_id_by_code( $code );
719
-    $user        = trim( $user );
718
+    $discount_id = wpinv_get_discount_id_by_code($code);
719
+    $user        = trim($user);
720 720
 
721
-    if ( wpinv_get_cart_contents() ) {
722
-        if ( $discount_id ) {
721
+    if (wpinv_get_cart_contents()) {
722
+        if ($discount_id) {
723 723
             if (
724
-                wpinv_is_discount_active( $discount_id ) &&
725
-                wpinv_check_discount_dates( $discount_id ) &&
726
-                !wpinv_is_discount_maxed_out( $discount_id ) &&
727
-                !wpinv_is_discount_used( $code, $user, $discount_id ) &&
728
-                wpinv_discount_is_min_met( $discount_id ) &&
729
-                wpinv_discount_is_max_met( $discount_id ) &&
730
-                wpinv_discount_item_reqs_met( $discount_id )
724
+                wpinv_is_discount_active($discount_id) &&
725
+                wpinv_check_discount_dates($discount_id) &&
726
+                !wpinv_is_discount_maxed_out($discount_id) &&
727
+                !wpinv_is_discount_used($code, $user, $discount_id) &&
728
+                wpinv_discount_is_min_met($discount_id) &&
729
+                wpinv_discount_is_max_met($discount_id) &&
730
+                wpinv_discount_item_reqs_met($discount_id)
731 731
             ) {
732 732
                 $return = true;
733 733
             }
734
-        } elseif( $set_error ) {
735
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) );
734
+        } elseif ($set_error) {
735
+            wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing'));
736 736
         }
737 737
     }
738 738
 
739
-    return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user );
739
+    return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user);
740 740
 }
741 741
 
742
-function wpinv_get_discount_id_by_code( $code ) {
743
-    $discount = wpinv_get_discount_by_code( $code );
744
-    if( $discount ) {
742
+function wpinv_get_discount_id_by_code($code) {
743
+    $discount = wpinv_get_discount_by_code($code);
744
+    if ($discount) {
745 745
         return $discount->ID;
746 746
     }
747 747
     return false;
748 748
 }
749 749
 
750
-function wpinv_get_discounted_amount( $code, $base_price ) {
750
+function wpinv_get_discounted_amount($code, $base_price) {
751 751
     $amount      = $base_price;
752
-    $discount_id = wpinv_get_discount_id_by_code( $code );
752
+    $discount_id = wpinv_get_discount_id_by_code($code);
753 753
 
754
-    if( $discount_id ) {
755
-        $type        = wpinv_get_discount_type( $discount_id );
756
-        $rate        = wpinv_get_discount_amount( $discount_id );
754
+    if ($discount_id) {
755
+        $type        = wpinv_get_discount_type($discount_id);
756
+        $rate        = wpinv_get_discount_amount($discount_id);
757 757
 
758
-        if ( $type == 'flat' ) {
758
+        if ($type == 'flat') {
759 759
             // Set amount
760 760
             $amount = $base_price - $rate;
761
-            if ( $amount < 0 ) {
761
+            if ($amount < 0) {
762 762
                 $amount = 0;
763 763
             }
764 764
 
765 765
         } else {
766 766
             // Percentage discount
767
-            $amount = $base_price - ( $base_price * ( $rate / 100 ) );
767
+            $amount = $base_price - ($base_price * ($rate / 100));
768 768
         }
769 769
 
770 770
     } else {
@@ -773,108 +773,108 @@  discard block
 block discarded – undo
773 773
 
774 774
     }
775 775
 
776
-    return apply_filters( 'wpinv_discounted_amount', $amount );
776
+    return apply_filters('wpinv_discounted_amount', $amount);
777 777
 }
778 778
 
779
-function wpinv_increase_discount_usage( $code ) {
779
+function wpinv_increase_discount_usage($code) {
780 780
 
781
-    $id   = wpinv_get_discount_id_by_code( $code );
782
-    $uses = wpinv_get_discount_uses( $id );
781
+    $id   = wpinv_get_discount_id_by_code($code);
782
+    $uses = wpinv_get_discount_uses($id);
783 783
 
784
-    if ( $uses ) {
784
+    if ($uses) {
785 785
         $uses++;
786 786
     } else {
787 787
         $uses = 1;
788 788
     }
789 789
 
790
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
790
+    update_post_meta($id, '_wpi_discount_uses', $uses);
791 791
 
792
-    do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code );
792
+    do_action('wpinv_discount_increase_use_count', $uses, $id, $code);
793 793
 
794 794
     return $uses;
795 795
 
796 796
 }
797 797
 
798
-function wpinv_decrease_discount_usage( $code ) {
798
+function wpinv_decrease_discount_usage($code) {
799 799
 
800
-    $id   = wpinv_get_discount_id_by_code( $code );
801
-    $uses = wpinv_get_discount_uses( $id );
800
+    $id   = wpinv_get_discount_id_by_code($code);
801
+    $uses = wpinv_get_discount_uses($id);
802 802
 
803
-    if ( $uses ) {
803
+    if ($uses) {
804 804
         $uses--;
805 805
     }
806 806
 
807
-    if ( $uses < 0 ) {
807
+    if ($uses < 0) {
808 808
         $uses = 0;
809 809
     }
810 810
 
811
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
811
+    update_post_meta($id, '_wpi_discount_uses', $uses);
812 812
 
813
-    do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code );
813
+    do_action('wpinv_discount_decrease_use_count', $uses, $id, $code);
814 814
 
815 815
     return $uses;
816 816
 
817 817
 }
818 818
 
819
-function wpinv_format_discount_rate( $type, $amount ) {
820
-    if ( $type == 'flat' ) {
821
-        return wpinv_price( wpinv_format_amount( $amount ) );
819
+function wpinv_format_discount_rate($type, $amount) {
820
+    if ($type == 'flat') {
821
+        return wpinv_price(wpinv_format_amount($amount));
822 822
     } else {
823 823
         return $amount . '%';
824 824
     }
825 825
 }
826 826
 
827
-function wpinv_set_cart_discount( $code = '' ) {    
828
-    if ( wpinv_multiple_discounts_allowed() ) {
827
+function wpinv_set_cart_discount($code = '') {    
828
+    if (wpinv_multiple_discounts_allowed()) {
829 829
         // Get all active cart discounts
830 830
         $discounts = wpinv_get_cart_discounts();
831 831
     } else {
832 832
         $discounts = false; // Only one discount allowed per purchase, so override any existing
833 833
     }
834 834
 
835
-    if ( $discounts ) {
836
-        $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) );
837
-        if( false !== $key ) {
838
-            unset( $discounts[ $key ] ); // Can't set the same discount more than once
835
+    if ($discounts) {
836
+        $key = array_search(strtolower($code), array_map('strtolower', $discounts));
837
+        if (false !== $key) {
838
+            unset($discounts[$key]); // Can't set the same discount more than once
839 839
         }
840 840
         $discounts[] = $code;
841 841
     } else {
842 842
         $discounts = array();
843 843
         $discounts[] = $code;
844 844
     }
845
-    $discounts = array_values( $discounts );
845
+    $discounts = array_values($discounts);
846 846
     
847 847
     $data = wpinv_get_checkout_session();
848
-    if ( empty( $data ) ) {
848
+    if (empty($data)) {
849 849
         $data = array();
850 850
     } else {
851
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
852
-            $payment_meta['user_info']['discount']  = implode( ',', $discounts );
853
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
851
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
852
+            $payment_meta['user_info']['discount'] = implode(',', $discounts);
853
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
854 854
         }
855 855
     }
856 856
     $data['cart_discounts'] = $discounts;
857 857
     
858
-    wpinv_set_checkout_session( $data );
858
+    wpinv_set_checkout_session($data);
859 859
     
860 860
     return $discounts;
861 861
 }
862 862
 
863
-function wpinv_unset_cart_discount( $code = '' ) {    
863
+function wpinv_unset_cart_discount($code = '') {    
864 864
     $discounts = wpinv_get_cart_discounts();
865 865
 
866
-    if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) {
867
-        $key = array_search( $code, $discounts );
868
-        unset( $discounts[ $key ] );
866
+    if ($code && !empty($discounts) && in_array($code, $discounts)) {
867
+        $key = array_search($code, $discounts);
868
+        unset($discounts[$key]);
869 869
             
870 870
         $data = wpinv_get_checkout_session();
871 871
         $data['cart_discounts'] = $discounts;
872
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
873
-            $payment_meta['user_info']['discount']  = !empty( $discounts ) ? implode( ',', $discounts ) : '';
874
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
872
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
873
+            $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : '';
874
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
875 875
         }
876 876
         
877
-        wpinv_set_checkout_session( $data );
877
+        wpinv_set_checkout_session($data);
878 878
     }
879 879
 
880 880
     return $discounts;
@@ -883,27 +883,27 @@  discard block
 block discarded – undo
883 883
 function wpinv_unset_all_cart_discounts() {
884 884
     $data = wpinv_get_checkout_session();
885 885
     
886
-    if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
887
-        unset( $data['cart_discounts'] );
886
+    if (!empty($data) && isset($data['cart_discounts'])) {
887
+        unset($data['cart_discounts']);
888 888
         
889
-         wpinv_set_checkout_session( $data );
889
+         wpinv_set_checkout_session($data);
890 890
          return true;
891 891
     }
892 892
     
893 893
     return false;
894 894
 }
895 895
 
896
-function wpinv_get_cart_discounts( $items = array() ) {
896
+function wpinv_get_cart_discounts($items = array()) {
897 897
     $session = wpinv_get_checkout_session();
898 898
     
899
-    $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false;
899
+    $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false;
900 900
     return $discounts;
901 901
 }
902 902
 
903
-function wpinv_cart_has_discounts( $items = array() ) {
903
+function wpinv_cart_has_discounts($items = array()) {
904 904
     $ret = false;
905 905
 
906
-    if ( wpinv_get_cart_discounts( $items ) ) {
906
+    if (wpinv_get_cart_discounts($items)) {
907 907
         $ret = true;
908 908
     }
909 909
     
@@ -914,131 +914,131 @@  discard block
 block discarded – undo
914 914
     }
915 915
     */
916 916
 
917
-    return apply_filters( 'wpinv_cart_has_discounts', $ret );
917
+    return apply_filters('wpinv_cart_has_discounts', $ret);
918 918
 }
919 919
 
920
-function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) {
920
+function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) {
921 921
     $amount = 0.00;
922
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
922
+    $items  = !empty($items) ? $items : wpinv_get_cart_content_details();
923 923
 
924
-    if ( $items ) {
925
-        $discounts = wp_list_pluck( $items, 'discount' );
924
+    if ($items) {
925
+        $discounts = wp_list_pluck($items, 'discount');
926 926
 
927
-        if ( is_array( $discounts ) ) {
928
-            $discounts = array_map( 'floatval', $discounts );
929
-            $amount    = array_sum( $discounts );
927
+        if (is_array($discounts)) {
928
+            $discounts = array_map('floatval', $discounts);
929
+            $amount    = array_sum($discounts);
930 930
         }
931 931
     }
932 932
 
933
-    return apply_filters( 'wpinv_get_cart_discounted_amount', $amount );
933
+    return apply_filters('wpinv_get_cart_discounted_amount', $amount);
934 934
 }
935 935
 
936
-function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) {
937
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
936
+function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) {
937
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
938 938
     
939
-    if ( empty( $discount ) || empty( $items ) ) {
939
+    if (empty($discount) || empty($items)) {
940 940
         return 0;
941 941
     }
942 942
 
943 943
     $amount = 0;
944 944
     
945
-    foreach ( $items as $item ) {
946
-        $amount += wpinv_get_cart_item_discount_amount( $item, $discount );
945
+    foreach ($items as $item) {
946
+        $amount += wpinv_get_cart_item_discount_amount($item, $discount);
947 947
     }
948 948
     
949
-    $amount = wpinv_round_amount( $amount );
949
+    $amount = wpinv_round_amount($amount);
950 950
 
951 951
     return $amount;
952 952
 }
953 953
 
954
-function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) {
954
+function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) {
955 955
     global $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
956 956
     
957 957
     $amount = 0;
958 958
 
959
-    if ( empty( $item ) || empty( $item['id'] ) ) {
959
+    if (empty($item) || empty($item['id'])) {
960 960
         return $amount;
961 961
     }
962 962
 
963
-    if ( empty( $item['quantity'] ) ) {
963
+    if (empty($item['quantity'])) {
964 964
         return $amount;
965 965
     }
966 966
 
967
-    if ( empty( $item['options'] ) ) {
967
+    if (empty($item['options'])) {
968 968
         $item['options'] = array();
969 969
     }
970 970
 
971
-    $price            = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] );
971
+    $price            = wpinv_get_cart_item_price($item['id'], $item, $item['options']);
972 972
     $discounted_price = $price;
973 973
 
974 974
     $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount;
975
-    if ( empty( $discounts ) ) {
975
+    if (empty($discounts)) {
976 976
         return $amount;
977 977
     }
978 978
 
979
-    if ( $discounts ) {
980
-        if ( is_array( $discounts ) ) {
981
-            $discounts = array_values( $discounts );
979
+    if ($discounts) {
980
+        if (is_array($discounts)) {
981
+            $discounts = array_values($discounts);
982 982
         } else {
983
-            $discounts = explode( ',', $discounts );
983
+            $discounts = explode(',', $discounts);
984 984
         }
985 985
     }
986 986
 
987
-    if( $discounts ) {
988
-        foreach ( $discounts as $discount ) {
989
-            $code_id = wpinv_get_discount_id_by_code( $discount );
987
+    if ($discounts) {
988
+        foreach ($discounts as $discount) {
989
+            $code_id = wpinv_get_discount_id_by_code($discount);
990 990
 
991 991
             // Check discount exists
992
-            if( ! $code_id ) {
992
+            if (!$code_id) {
993 993
                 continue;
994 994
             }
995 995
 
996
-            $reqs           = wpinv_get_discount_item_reqs( $code_id );
997
-            $excluded_items = wpinv_get_discount_excluded_items( $code_id );
996
+            $reqs           = wpinv_get_discount_item_reqs($code_id);
997
+            $excluded_items = wpinv_get_discount_excluded_items($code_id);
998 998
 
999 999
             // Make sure requirements are set and that this discount shouldn't apply to the whole cart
1000
-            if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) {
1001
-                foreach ( $reqs as $item_id ) {
1002
-                    if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) {
1003
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1000
+            if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) {
1001
+                foreach ($reqs as $item_id) {
1002
+                    if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) {
1003
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1004 1004
                     }
1005 1005
                 }
1006 1006
             } else {
1007 1007
                 // This is a global cart discount
1008
-                if ( !in_array( $item['id'], $excluded_items ) ) {
1009
-                    if ( 'flat' === wpinv_get_discount_type( $code_id ) ) {
1008
+                if (!in_array($item['id'], $excluded_items)) {
1009
+                    if ('flat' === wpinv_get_discount_type($code_id)) {
1010 1010
                         $items_subtotal    = 0.00;
1011 1011
                         $cart_items        = wpinv_get_cart_contents();
1012 1012
                         
1013
-                        foreach ( $cart_items as $cart_item ) {
1014
-                            if ( ! in_array( $cart_item['id'], $excluded_items ) ) {
1015
-                                $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array();
1016
-                                $item_price      = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options );
1013
+                        foreach ($cart_items as $cart_item) {
1014
+                            if (!in_array($cart_item['id'], $excluded_items)) {
1015
+                                $options = !empty($cart_item['options']) ? $cart_item['options'] : array();
1016
+                                $item_price      = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options);
1017 1017
                                 $items_subtotal += $item_price * $cart_item['quantity'];
1018 1018
                             }
1019 1019
                         }
1020 1020
 
1021
-                        $subtotal_percent  = ( ( $price * $item['quantity'] ) / $items_subtotal );
1022
-                        $code_amount       = wpinv_get_discount_amount( $code_id );
1021
+                        $subtotal_percent  = (($price * $item['quantity']) / $items_subtotal);
1022
+                        $code_amount       = wpinv_get_discount_amount($code_id);
1023 1023
                         $discounted_amount = $code_amount * $subtotal_percent;
1024 1024
                         $discounted_price -= $discounted_amount;
1025 1025
 
1026
-                        $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() );
1026
+                        $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter());
1027 1027
 
1028
-                        if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) {
1028
+                        if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) {
1029 1029
                             $adjustment = $code_amount - $wpinv_flat_discount_total;
1030 1030
                             $discounted_price -= $adjustment;
1031 1031
                         }
1032 1032
                     } else {
1033
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1033
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1034 1034
                     }
1035 1035
                 }
1036 1036
             }
1037 1037
         }
1038 1038
 
1039
-        $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) );
1039
+        $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price));
1040 1040
 
1041
-        if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) {
1041
+        if ('flat' !== wpinv_get_discount_type($code_id)) {
1042 1042
             $amount = $amount * $item['quantity'];
1043 1043
         }
1044 1044
     }
@@ -1046,59 +1046,59 @@  discard block
 block discarded – undo
1046 1046
     return $amount;
1047 1047
 }
1048 1048
 
1049
-function wpinv_cart_discounts_html( $items = array() ) {
1050
-    echo wpinv_get_cart_discounts_html( $items );
1049
+function wpinv_cart_discounts_html($items = array()) {
1050
+    echo wpinv_get_cart_discounts_html($items);
1051 1051
 }
1052 1052
 
1053
-function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) {
1053
+function wpinv_get_cart_discounts_html($items = array(), $discounts = false) {
1054 1054
     global $wpi_cart_columns;
1055 1055
     
1056
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1056
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
1057 1057
     
1058
-    if ( !$discounts ) {
1059
-        $discounts = wpinv_get_cart_discounts( $items );
1058
+    if (!$discounts) {
1059
+        $discounts = wpinv_get_cart_discounts($items);
1060 1060
     }
1061 1061
 
1062
-    if ( !$discounts ) {
1062
+    if (!$discounts) {
1063 1063
         return;
1064 1064
     }
1065 1065
     
1066
-    $discounts = is_array( $discounts ) ? $discounts : array( $discounts );
1066
+    $discounts = is_array($discounts) ? $discounts : array($discounts);
1067 1067
     
1068 1068
     $html = '';
1069 1069
 
1070
-    foreach ( $discounts as $discount ) {
1071
-        $discount_id    = wpinv_get_discount_id_by_code( $discount );
1072
-        $discount_value = wpinv_get_discount_amount( $discount_id );
1073
-        $rate           = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value );
1074
-        $amount         = wpinv_get_cart_items_discount_amount( $items, $discount );
1075
-        $remove_btn     = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1070
+    foreach ($discounts as $discount) {
1071
+        $discount_id    = wpinv_get_discount_id_by_code($discount);
1072
+        $discount_value = wpinv_get_discount_amount($discount_id);
1073
+        $rate           = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value);
1074
+        $amount         = wpinv_get_cart_items_discount_amount($items, $discount);
1075
+        $remove_btn     = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1076 1076
         
1077 1077
         $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">';
1078 1078
         ob_start();
1079
-        do_action( 'wpinv_checkout_table_discount_first', $items );
1079
+        do_action('wpinv_checkout_table_discount_first', $items);
1080 1080
         $html .= ob_get_clean();
1081
-        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>';
1081
+        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>';
1082 1082
         ob_start();
1083
-        do_action( 'wpinv_checkout_table_discount_last', $items );
1083
+        do_action('wpinv_checkout_table_discount_last', $items);
1084 1084
         $html .= ob_get_clean();
1085 1085
         $html .= '</tr>';
1086 1086
     }
1087 1087
 
1088
-    return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate );
1088
+    return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate);
1089 1089
 }
1090 1090
 
1091
-function wpinv_display_cart_discount( $formatted = false, $echo = false ) {
1091
+function wpinv_display_cart_discount($formatted = false, $echo = false) {
1092 1092
     $discounts = wpinv_get_cart_discounts();
1093 1093
 
1094
-    if ( empty( $discounts ) ) {
1094
+    if (empty($discounts)) {
1095 1095
         return false;
1096 1096
     }
1097 1097
 
1098
-    $discount_id  = wpinv_get_discount_id_by_code( $discounts[0] );
1099
-    $amount       = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) );
1098
+    $discount_id  = wpinv_get_discount_id_by_code($discounts[0]);
1099
+    $amount       = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id));
1100 1100
 
1101
-    if ( $echo ) {
1101
+    if ($echo) {
1102 1102
         echo $amount;
1103 1103
     }
1104 1104
 
@@ -1106,135 +1106,135 @@  discard block
 block discarded – undo
1106 1106
 }
1107 1107
 
1108 1108
 function wpinv_remove_cart_discount() {
1109
-    if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) {
1109
+    if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) {
1110 1110
         return;
1111 1111
     }
1112 1112
 
1113
-    do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) );
1113
+    do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id']));
1114 1114
 
1115
-    wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) );
1115
+    wpinv_unset_cart_discount(urldecode($_GET['discount_code']));
1116 1116
 
1117
-    do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) );
1117
+    do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id']));
1118 1118
 
1119
-    wp_redirect( wpinv_get_checkout_uri() ); wpinv_die();
1119
+    wp_redirect(wpinv_get_checkout_uri()); wpinv_die();
1120 1120
 }
1121
-add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' );
1121
+add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount');
1122 1122
 
1123
-function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) {
1123
+function wpinv_maybe_remove_cart_discount($cart_key = 0) {
1124 1124
     $discounts = wpinv_get_cart_discounts();
1125 1125
 
1126
-    if ( !$discounts ) {
1126
+    if (!$discounts) {
1127 1127
         return;
1128 1128
     }
1129 1129
 
1130
-    foreach ( $discounts as $discount ) {
1131
-        if ( !wpinv_is_discount_valid( $discount ) ) {
1132
-            wpinv_unset_cart_discount( $discount );
1130
+    foreach ($discounts as $discount) {
1131
+        if (!wpinv_is_discount_valid($discount)) {
1132
+            wpinv_unset_cart_discount($discount);
1133 1133
         }
1134 1134
     }
1135 1135
 }
1136
-add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' );
1136
+add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount');
1137 1137
 
1138 1138
 function wpinv_multiple_discounts_allowed() {
1139
-    $ret = wpinv_get_option( 'allow_multiple_discounts', false );
1140
-    return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret );
1139
+    $ret = wpinv_get_option('allow_multiple_discounts', false);
1140
+    return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret);
1141 1141
 }
1142 1142
 
1143 1143
 function wpinv_listen_for_cart_discount() {
1144 1144
     global $wpi_session;
1145 1145
     
1146
-    if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) {
1146
+    if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) {
1147 1147
         return;
1148 1148
     }
1149 1149
 
1150
-    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] );
1150
+    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']);
1151 1151
 
1152
-    $wpi_session->set( 'preset_discount', $code );
1152
+    $wpi_session->set('preset_discount', $code);
1153 1153
 }
1154 1154
 //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 );
1155 1155
 
1156 1156
 function wpinv_apply_preset_discount() {
1157 1157
     global $wpi_session;
1158 1158
     
1159
-    $code = $wpi_session->get( 'preset_discount' );
1159
+    $code = $wpi_session->get('preset_discount');
1160 1160
 
1161
-    if ( !$code ) {
1161
+    if (!$code) {
1162 1162
         return;
1163 1163
     }
1164 1164
 
1165
-    if ( !wpinv_is_discount_valid( $code, '', false ) ) {
1165
+    if (!wpinv_is_discount_valid($code, '', false)) {
1166 1166
         return;
1167 1167
     }
1168 1168
     
1169
-    $code = apply_filters( 'wpinv_apply_preset_discount', $code );
1169
+    $code = apply_filters('wpinv_apply_preset_discount', $code);
1170 1170
 
1171
-    wpinv_set_cart_discount( $code );
1171
+    wpinv_set_cart_discount($code);
1172 1172
 
1173
-    $wpi_session->set( 'preset_discount', null );
1173
+    $wpi_session->set('preset_discount', null);
1174 1174
 }
1175 1175
 //add_action( 'init', 'wpinv_apply_preset_discount', 999 );
1176 1176
 
1177
-function wpinv_get_discount_label( $code, $echo = true ) {
1178
-    $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) );
1179
-    $label = apply_filters( 'wpinv_get_discount_label', $label, $code );
1177
+function wpinv_get_discount_label($code, $echo = true) {
1178
+    $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : ''));
1179
+    $label = apply_filters('wpinv_get_discount_label', $label, $code);
1180 1180
 
1181
-    if ( $echo ) {
1181
+    if ($echo) {
1182 1182
         echo $label;
1183 1183
     } else {
1184 1184
         return $label;
1185 1185
     }
1186 1186
 }
1187 1187
 
1188
-function wpinv_cart_discount_label( $code, $rate, $echo = true ) {
1189
-    $label = wp_sprintf( __( '%1$s Discount: %2$s', 'invoicing' ), $rate, $code );
1190
-    $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate );
1188
+function wpinv_cart_discount_label($code, $rate, $echo = true) {
1189
+    $label = wp_sprintf(__('%1$s Discount: %2$s', 'invoicing'), $rate, $code);
1190
+    $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate);
1191 1191
 
1192
-    if ( $echo ) {
1192
+    if ($echo) {
1193 1193
         echo $label;
1194 1194
     } else {
1195 1195
         return $label;
1196 1196
     }
1197 1197
 }
1198 1198
 
1199
-function wpinv_check_delete_discount( $check, $post, $force_delete ) {
1200
-    if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) {
1199
+function wpinv_check_delete_discount($check, $post, $force_delete) {
1200
+    if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) {
1201 1201
         return true;
1202 1202
     }
1203 1203
     
1204 1204
     return $check;
1205 1205
 }
1206
-add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 );
1206
+add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3);
1207 1207
 
1208 1208
 function wpinv_checkout_form_validate_discounts() {
1209 1209
     global $wpi_checkout_id;
1210 1210
     
1211 1211
     $discounts = wpinv_get_cart_discounts();
1212 1212
     
1213
-    if ( !empty( $discounts ) ) {
1213
+    if (!empty($discounts)) {
1214 1214
         $invalid = false;
1215 1215
         
1216
-        foreach ( $discounts as $key => $code ) {
1217
-            if ( !wpinv_is_discount_valid( $code, (int)wpinv_get_user_id( $wpi_checkout_id ) ) ) {
1216
+        foreach ($discounts as $key => $code) {
1217
+            if (!wpinv_is_discount_valid($code, (int)wpinv_get_user_id($wpi_checkout_id))) {
1218 1218
                 $invalid = true;
1219 1219
                 
1220
-                wpinv_unset_cart_discount( $code );
1220
+                wpinv_unset_cart_discount($code);
1221 1221
             }
1222 1222
         }
1223 1223
         
1224
-        if ( $invalid ) {
1224
+        if ($invalid) {
1225 1225
             $errors = wpinv_get_errors();
1226
-            $error  = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : '';
1227
-            $error  .= __( 'The discount has been removed from cart.', 'invoicing' );
1228
-            wpinv_set_error( 'wpinv-discount-error', $error );
1226
+            $error  = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : '';
1227
+            $error .= __('The discount has been removed from cart.', 'invoicing');
1228
+            wpinv_set_error('wpinv-discount-error', $error);
1229 1229
             
1230
-            wpinv_recalculate_tax( true );
1230
+            wpinv_recalculate_tax(true);
1231 1231
         }
1232 1232
     }
1233 1233
 }
1234
-add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 );
1234
+add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10);
1235 1235
 
1236 1236
 function wpinv_discount_amount() {
1237 1237
     $output = 0.00;
1238 1238
     
1239
-    return apply_filters( 'wpinv_discount_amount', $output );
1239
+    return apply_filters('wpinv_discount_amount', $output);
1240 1240
 }
1241 1241
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/manual.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  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_manual_cc_form', '__return_false' );
5
+add_action('wpinv_manual_cc_form', '__return_false');
6 6
 
7
-function wpinv_process_manual_payment( $purchase_data ) {
8
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
9
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
7
+function wpinv_process_manual_payment($purchase_data) {
8
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
9
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
10 10
     }
11 11
 
12 12
     /*
@@ -41,22 +41,22 @@  discard block
 block discarded – undo
41 41
     );
42 42
 
43 43
     // Record the pending payment
44
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
44
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
45 45
     
46
-    if ( !empty( $invoice ) ) {        
47
-        wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() );
48
-        wpinv_update_payment_status( $invoice, 'publish' );
46
+    if (!empty($invoice)) {        
47
+        wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key());
48
+        wpinv_update_payment_status($invoice, 'publish');
49 49
         
50 50
         // Empty the shopping cart
51 51
         wpinv_empty_cart();
52 52
         
53
-        do_action( 'wpinv_send_to_success_page', $invoice->ID, $payment_data );
53
+        do_action('wpinv_send_to_success_page', $invoice->ID, $payment_data);
54 54
         
55
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
55
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
56 56
     } else {
57
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
57
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
58 58
         // If errors are present, send the user back to the purchase page so they can be corrected
59
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
59
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
60 60
     }
61 61
 }
62
-add_action( 'wpinv_gateway_manual', 'wpinv_process_manual_payment' );
63 62
\ No newline at end of file
63
+add_action('wpinv_gateway_manual', 'wpinv_process_manual_payment');
64 64
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/authorizenet.php 1 patch
Spacing   +241 added lines, -241 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-3 control-label"><?php _e( 'Card Owner', 'invoicing' ) ;?></label>
15
+              <label for="auth-input-cc-owner" class="col-sm-3 control-label"><?php _e('Card Owner', 'invoicing'); ?></label>
16 16
               <div class="col-sm-5">
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-3 control-label"><?php _e( 'Card Number', 'invoicing' ) ;?></label>
21
+              <label for="auth-input-cc-number" class="col-sm-3 control-label"><?php _e('Card Number', 'invoicing'); ?></label>
22 22
               <div class="col-sm-5">
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-3 control-label"><?php _e( 'Card Expiry Date', 'invoicing' ) ;?></label>
27
+              <label for="auth-input-cc-expire-date" class="col-sm-3 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-3">
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-3 control-label"><?php _e( 'Card Security Code (CVV2)', 'invoicing' ) ;?></label>
44
+              <label for="auth-input-cc-cvv2" class="col-sm-3 control-label"><?php _e('Card Security Code (CVV2)', 'invoicing'); ?></label>
45 45
               <div class="col-sm-5">
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,178 +83,178 @@  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
-                    wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'Authorize.Net payment response: %s', 'invoicing' ), $response->response_reason_text ), '', '', true );
174
-                    wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'Authorize.Net payment: Transaction ID %s, Transaction Type %s, Authorization Code %s', 'invoicing' ), $response->transaction_id, strtoupper( $response->transaction_type ), $response->authorization_code ), '', '', true );
173
+                    wpinv_insert_payment_note($invoice_id, wp_sprintf(__('Authorize.Net payment response: %s', 'invoicing'), $response->response_reason_text), '', '', true);
174
+                    wpinv_insert_payment_note($invoice_id, wp_sprintf(__('Authorize.Net payment: Transaction ID %s, Transaction Type %s, Authorization Code %s', 'invoicing'), $response->transaction_id, strtoupper($response->transaction_type), $response->authorization_code), '', '', true);
175 175
 
176
-                    do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card );
176
+                    do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card);
177 177
 
178 178
                     wpinv_clear_errors();
179 179
                     wpinv_empty_cart();
180 180
 
181
-                    wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
181
+                    wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
182 182
                 } else {
183
-                    if ( !empty( $response->response_reason_text ) ) {
184
-                        $error = __( $response->response_reason_text, 'invoicing' );
185
-                    } else if ( !empty( $response->error_message ) ) {
186
-                        $error = __( $response->error_message, 'invoicing' );
183
+                    if (!empty($response->response_reason_text)) {
184
+                        $error = __($response->response_reason_text, 'invoicing');
185
+                    } else if (!empty($response->error_message)) {
186
+                        $error = __($response->error_message, 'invoicing');
187 187
                     } else {
188
-                        $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) );
188
+                        $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true));
189 189
                     } 
190 190
 
191
-                    $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error );
191
+                    $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error);
192 192
 
193
-                    wpinv_set_error( 'payment_error', $error );
194
-                    wpinv_record_gateway_error( $error, $response );
195
-                    wpinv_insert_payment_note( $invoice_id, $error, '', '', true );
193
+                    wpinv_set_error('payment_error', $error);
194
+                    wpinv_record_gateway_error($error, $response);
195
+                    wpinv_insert_payment_note($invoice_id, $error, '', '', true);
196 196
 
197
-                    wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
197
+                    wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
198 198
                 }
199
-            } catch ( AuthorizeNetException $e ) {
200
-                wpinv_set_error( 'request_error', $e->getMessage() );
201
-                wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) );
202
-                wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
199
+            } catch (AuthorizeNetException $e) {
200
+                wpinv_set_error('request_error', $e->getMessage());
201
+                wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage()));
202
+                wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
203 203
             }
204 204
         } else {
205
-            wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
205
+            wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
206 206
         }
207 207
     } else {
208
-        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 );
209
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
208
+        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);
209
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
210 210
     }
211 211
 }
212
-add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' );
212
+add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment');
213 213
 
214
-function wpinv_authorizenet_cancel_subscription( $subscription = '' ) {
215
-    if ( empty( $subscription->id ) ) {
214
+function wpinv_authorizenet_cancel_subscription($subscription = '') {
215
+    if (empty($subscription->id)) {
216 216
         return false;
217 217
     }
218 218
 
219 219
     try {
220 220
         $authnetXML = wpinv_authorizenet_XML();
221
-        $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription->id ) );
221
+        $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription->id));
222 222
 
223
-        if ( wpinv_is_test_mode( 'authorizenet' ) ) {
223
+        if (wpinv_is_test_mode('authorizenet')) {
224 224
             return true;
225 225
         }
226 226
 
227 227
         return $authnetXML->isSuccessful();
228
-    } catch( Exception $e ) {
229
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
228
+    } catch (Exception $e) {
229
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
230 230
     }
231 231
 
232 232
     return false;
233 233
 }
234
-add_action( 'wpinv_recurring_cancel_authorizenet_subscription', 'wpinv_authorizenet_cancel_subscription' );
234
+add_action('wpinv_recurring_cancel_authorizenet_subscription', 'wpinv_authorizenet_cancel_subscription');
235 235
 
236
-function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) {
237
-    $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' );
238
-    if ( empty( $authorizenet_md5_hash ) ) {
236
+function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) {
237
+    $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash');
238
+    if (empty($authorizenet_md5_hash)) {
239 239
         return true;
240 240
     }
241 241
 
242
-    $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) );
242
+    $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount));
243 243
 
244
-    return hash_equals( $compare_md5, $md5_hash );
244
+    return hash_equals($compare_md5, $md5_hash);
245 245
 }
246 246
 
247 247
 function wpinv_authorizenet_AIM() {
248
-    if ( !class_exists( 'AuthorizeNetException' ) ) {
249
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
248
+    if (!class_exists('AuthorizeNetException')) {
249
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
250 250
     }
251 251
 
252
-    $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) );
252
+    $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'));
253 253
 
254
-    if ( wpinv_is_test_mode( 'authorizenet' ) ) {
255
-        $authorizeAIM->setSandbox( true );
254
+    if (wpinv_is_test_mode('authorizenet')) {
255
+        $authorizeAIM->setSandbox(true);
256 256
     } else {
257
-        $authorizeAIM->setSandbox( false );
257
+        $authorizeAIM->setSandbox(false);
258 258
     }
259 259
 
260 260
     $authorizeAIM->customer_ip = wpinv_get_ip();
@@ -263,249 +263,249 @@  discard block
 block discarded – undo
263 263
 }
264 264
 
265 265
 function wpinv_authorizenet_XML() {
266
-    if ( !class_exists( 'AuthnetXML' ) ) {
267
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
266
+    if (!class_exists('AuthnetXML')) {
267
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
268 268
     }
269 269
     
270
-    $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) );
270
+    $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool)wpinv_is_test_mode('authorizenet'));
271 271
     
272 272
     return $authnetXML;
273 273
 }
274 274
 
275
-function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) {
276
-    if ( empty( $response ) || empty( $invoice ) ) {
275
+function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) {
276
+    if (empty($response) || empty($invoice)) {
277 277
         return false;
278 278
     }
279 279
 
280
-    if ( $invoice->is_recurring() && !empty( $response->approved ) ) {
281
-        $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info );
280
+    if ($invoice->is_recurring() && !empty($response->approved)) {
281
+        $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info);
282 282
         $success = false;
283
-        if ( wpinv_is_test_mode( 'authorizenet' ) ) {
283
+        if (wpinv_is_test_mode('authorizenet')) {
284 284
             $success = true;
285 285
         } else {
286 286
             $success = $subscription->isSuccessful();
287 287
         }
288 288
 
289
-        if ( !empty( $subscription ) && $success ) {
290
-            do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' );
289
+        if (!empty($subscription) && $success) {
290
+            do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet');
291 291
 
292
-            wpinv_authorizenet_subscription_record_signup( $subscription, $invoice );
292
+            wpinv_authorizenet_subscription_record_signup($subscription, $invoice);
293 293
 
294
-            do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' );
294
+            do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet');
295 295
         } else {
296
-            if ( isset( $subscription->messages->message ) ) {
296
+            if (isset($subscription->messages->message)) {
297 297
                 $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text;
298
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' );
298
+                wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing');
299 299
             } else {
300
-                $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' );
301
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error );
300
+                $error = __('Your subscription cannot be created due to an error.', 'invoicing');
301
+                wpinv_set_error('wpinv_authorize_recurring_error', $error);
302 302
             }
303 303
 
304
-            wpinv_record_gateway_error( $error, $subscription );
304
+            wpinv_record_gateway_error($error, $subscription);
305 305
 
306
-            wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ), '', '', true );
306
+            wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error), '', '', true);
307 307
         }
308 308
     }
309 309
 }
310
-add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 );
310
+add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3);
311 311
 
312
-function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) {
313
-    if ( empty( $invoice ) ) {
312
+function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) {
313
+    if (empty($invoice)) {
314 314
         return false;
315 315
     }
316 316
 
317
-    $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response );
317
+    $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response);
318 318
 
319 319
     try {
320 320
         $authnetXML = wpinv_authorizenet_XML();
321
-        $authnetXML->ARBCreateSubscriptionRequest( $params );
322
-    } catch( Exception $e ) {
321
+        $authnetXML->ARBCreateSubscriptionRequest($params);
322
+    } catch (Exception $e) {
323 323
         $authnetXML = array();
324
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
324
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
325 325
     }
326 326
 
327 327
     return $authnetXML;
328 328
 }
329 329
 
330
-function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) {
331
-    if ( empty( $invoice ) ) {
330
+function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) {
331
+    if (empty($invoice)) {
332 332
         return false;
333 333
     }
334 334
 
335
-    $subscription_item = $invoice->get_recurring( true );
336
-    if ( empty( $subscription_item->ID ) ) {
335
+    $subscription_item = $invoice->get_recurring(true);
336
+    if (empty($subscription_item->ID)) {
337 337
         return false;
338 338
     }
339 339
 
340
-    $item = $invoice->get_recurring( true );
340
+    $item = $invoice->get_recurring(true);
341 341
 
342
-    if ( empty( $item ) ) {
342
+    if (empty($item)) {
343 343
         $name = '';
344 344
     }
345 345
 
346
-    if ( !( $name = $item->get_name() ) ) {
346
+    if (!($name = $item->get_name())) {
347 347
         $name = $item->post_name;
348 348
     }
349 349
 
350
-    $card_details       = wpinv_authorizenet_generate_card_info( $card_info );
350
+    $card_details       = wpinv_authorizenet_generate_card_info($card_info);
351 351
     $subscription_name  = $invoice->get_subscription_name();
352
-    $initial_amount     = wpinv_round_amount( $invoice->get_total() );
353
-    $recurring_amount   = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) );
352
+    $initial_amount     = wpinv_round_amount($invoice->get_total());
353
+    $recurring_amount   = wpinv_round_amount($invoice->get_recurring_details('total'));
354 354
     $interval           = $subscription_item->get_recurring_interval();
355 355
     $period             = $subscription_item->get_recurring_period();
356 356
     $bill_times         = (int)$subscription_item->get_recurring_limit();
357 357
     $bill_times         = $bill_times > 0 ? $bill_times : 9999;
358 358
 
359
-    $time_period        = wpinv_authorizenet_get_time_period( $interval, $period );
359
+    $time_period        = wpinv_authorizenet_get_time_period($interval, $period);
360 360
     $interval           = $time_period['interval'];
361 361
     $period             = $time_period['period'];
362 362
 
363 363
     $current_tz = date_default_timezone_get();
364
-    date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
365
-    $today = date( 'Y-m-d' );
366
-    date_default_timezone_set( $current_tz );
364
+    date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
365
+    $today = date('Y-m-d');
366
+    date_default_timezone_set($current_tz);
367 367
 
368 368
     $free_trial = $invoice->is_free_trial();
369
-    if ( $free_trial && $subscription_item->has_free_trial() ) {
369
+    if ($free_trial && $subscription_item->has_free_trial()) {
370 370
         $trial_interval    = $subscription_item->get_trial_interval();
371
-        $trial_period      = $subscription_item->get_trial_period( true );
371
+        $trial_period      = $subscription_item->get_trial_period(true);
372 372
     }
373 373
 
374 374
     $subscription = array();
375 375
     $subscription['name'] = $subscription_name;
376 376
 
377 377
     $subscription['paymentSchedule'] = array(
378
-        'interval'         => array( 'length' => $interval, 'unit' => $period ),
378
+        'interval'         => array('length' => $interval, 'unit' => $period),
379 379
         'startDate'        => $today,
380 380
         'totalOccurrences' => $bill_times,
381
-        'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0,
381
+        'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0,
382 382
     );
383 383
 
384 384
     $subscription['amount'] = $recurring_amount;
385 385
     $subscription['trialAmount'] = $initial_amount;
386
-    $subscription['payment'] = array( 'creditCard' => $card_details );
387
-    $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() );
388
-    $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone );
386
+    $subscription['payment'] = array('creditCard' => $card_details);
387
+    $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number());
388
+    $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone);
389 389
 
390 390
     $subscription['billTo'] = array(
391 391
         'firstName' => $invoice->get_first_name(),
392 392
         'lastName'  => $invoice->get_last_name(),
393 393
         'company'   => $invoice->company,
394
-        'address'   => wp_strip_all_tags( $invoice->get_address(), true ),
394
+        'address'   => wp_strip_all_tags($invoice->get_address(), true),
395 395
         'city'      => $invoice->city,
396 396
         'state'     => $invoice->state,
397 397
         'zip'       => $invoice->zip,
398 398
         'country'   => $invoice->country,
399 399
     );
400 400
 
401
-    $params = array( 'subscription' => $subscription );
401
+    $params = array('subscription' => $subscription);
402 402
 
403
-    return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response );
403
+    return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response);
404 404
 }
405 405
 
406
-function wpinv_authorizenet_generate_card_info( $card_info = array() ) {
407
-    $card_defaults      = array(
406
+function wpinv_authorizenet_generate_card_info($card_info = array()) {
407
+    $card_defaults = array(
408 408
         'cc_owner'          => null,
409 409
         'cc_number'         => null,
410 410
         'cc_expire_month'   => null,
411 411
         'cc_expire_year'    => null,
412 412
         'cc_cvv2'           => null,
413 413
     );
414
-    $card_info = wp_parse_args( $card_info, $card_defaults );
414
+    $card_info = wp_parse_args($card_info, $card_defaults);
415 415
 
416 416
     $card_details = array(
417
-        'cardNumber'     => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ),
418
-        'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ),
419
-        'cardCode'       => sanitize_text_field( $card_info['cc_cvv2'] ),
417
+        'cardNumber'     => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])),
418
+        'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']),
419
+        'cardCode'       => sanitize_text_field($card_info['cc_cvv2']),
420 420
     );
421 421
 
422 422
     return $card_details;
423 423
 }
424 424
 
425
-function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) {
426
-    $parent_invoice_id = absint( $invoice->ID );
425
+function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) {
426
+    $parent_invoice_id = absint($invoice->ID);
427 427
 
428
-    if( empty( $parent_invoice_id ) ) {
428
+    if (empty($parent_invoice_id)) {
429 429
         return;
430 430
     }
431 431
 
432
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
433
-    if ( empty( $invoice ) ) {
432
+    $invoice = wpinv_get_invoice($parent_invoice_id);
433
+    if (empty($invoice)) {
434 434
         return;
435 435
     }
436 436
 
437 437
     $subscriptionId     = (array)$subscription->subscriptionId;
438
-    $subscription_id    = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $parent_invoice_id;
438
+    $subscription_id    = !empty($subscriptionId[0]) ? $subscriptionId[0] : $parent_invoice_id;
439 439
 
440
-    wpinv_set_payment_transaction_id( $parent_invoice_id, $subscription_id );
440
+    wpinv_set_payment_transaction_id($parent_invoice_id, $subscription_id);
441 441
 
442
-    $subscription = wpinv_get_authorizenet_subscription( $subscription, $parent_invoice_id );
442
+    $subscription = wpinv_get_authorizenet_subscription($subscription, $parent_invoice_id);
443 443
 
444
-    if ( false === $subscription ) {
444
+    if (false === $subscription) {
445 445
         return;
446 446
     }
447 447
 
448 448
     // Set payment to complete
449
-    wpinv_update_payment_status( $subscription->parent_payment_id, 'publish' );
449
+    wpinv_update_payment_status($subscription->parent_payment_id, 'publish');
450 450
     sleep(1);
451
-    wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ), '', '', true );
452
-    update_post_meta($parent_invoice_id,'_wpinv_subscr_profile_id', $subscription_id);
451
+    wpinv_insert_payment_note($parent_invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id), '', '', true);
452
+    update_post_meta($parent_invoice_id, '_wpinv_subscr_profile_id', $subscription_id);
453 453
 
454 454
     $status = 'trialling' == $subscription->status ? 'trialling' : 'active';
455 455
 
456 456
     // Retrieve pending subscription from database and update it's status to active and set proper profile ID
457
-    $subscription->update( array( 'profile_id' => $subscription_id, 'status' => $status ) );
457
+    $subscription->update(array('profile_id' => $subscription_id, 'status' => $status));
458 458
 }
459 459
 
460
-function wpinv_authorizenet_validate_checkout( $valid_data, $post ) {
461
-    if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) {
460
+function wpinv_authorizenet_validate_checkout($valid_data, $post) {
461
+    if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') {
462 462
         $error = false;
463 463
         
464
-        if ( empty( $post['authorizenet']['cc_owner'] ) ) {
464
+        if (empty($post['authorizenet']['cc_owner'])) {
465 465
             $error = true;
466
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
466
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
467 467
         }
468
-        if ( empty( $post['authorizenet']['cc_number'] ) ) {
468
+        if (empty($post['authorizenet']['cc_number'])) {
469 469
             $error = true;
470
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
470
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
471 471
         }
472
-        if ( empty( $post['authorizenet']['cc_expire_month'] ) ) {
472
+        if (empty($post['authorizenet']['cc_expire_month'])) {
473 473
             $error = true;
474
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
474
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
475 475
         }
476
-        if ( empty( $post['authorizenet']['cc_expire_year'] ) ) {
476
+        if (empty($post['authorizenet']['cc_expire_year'])) {
477 477
             $error = true;
478
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
478
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
479 479
         }
480
-        if ( empty( $post['authorizenet']['cc_cvv2'] ) ) {
480
+        if (empty($post['authorizenet']['cc_cvv2'])) {
481 481
             $error = true;
482
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
482
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
483 483
         }
484 484
 
485
-        if ( $error ) {
485
+        if ($error) {
486 486
             return;
487 487
         }
488 488
 
489 489
         $invoice = wpinv_get_invoice_cart();
490 490
 
491
-        if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) {
492
-            $subscription_item = $invoice->get_recurring( true );
491
+        if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) {
492
+            $subscription_item = $invoice->get_recurring(true);
493 493
 
494 494
             $interval   = $subscription_item->get_recurring_interval();
495 495
             $period     = $subscription_item->get_recurring_period();
496 496
 
497
-            if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) {
498
-                wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) );
497
+            if ($period == 'D' && ($interval < 7 || $interval > 365)) {
498
+                wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing'));
499 499
             }
500 500
         }
501 501
     }
502 502
 }
503
-add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 );
503
+add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2);
504 504
 
505
-function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) {
506
-    $subscription_interval = absint( $subscription_interval );
505
+function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) {
506
+    $subscription_interval = absint($subscription_interval);
507 507
 
508
-    switch( $subscription_period ) {
508
+    switch ($subscription_period) {
509 509
         case 'W':
510 510
         case 'week':
511 511
         case 'weeks':
@@ -515,14 +515,14 @@  discard block
 block discarded – undo
515 515
         case 'M':
516 516
         case 'month':
517 517
         case 'months':
518
-            if ( $subscription_interval > 12 ) {
518
+            if ($subscription_interval > 12) {
519 519
                 $subscription_interval = 12;
520 520
             }
521 521
 
522 522
             $interval = $subscription_interval;
523 523
             $period   = 'months';
524 524
             
525
-            if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) {
525
+            if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) {
526 526
                 $interval = $subscription_interval * 30;
527 527
                 $period   = 'days';
528 528
             }
@@ -539,30 +539,30 @@  discard block
 block discarded – undo
539 539
             break;
540 540
     }
541 541
 
542
-    return compact( 'interval', 'period' );
542
+    return compact('interval', 'period');
543 543
 }
544 544
 
545 545
 function wpinv_authorizenet_process_ipn() {
546
-    if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) {
546
+    if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) {
547 547
         return;
548 548
     }
549 549
 
550
-    $subscription_id = !empty( $_POST['x_subscription_id'] ) ? intval( $_POST['x_subscription_id'] ) : false;
550
+    $subscription_id = !empty($_POST['x_subscription_id']) ? intval($_POST['x_subscription_id']) : false;
551 551
 
552
-    if ( $subscription_id ) {
553
-        $response_code  = intval( $_POST['x_response_code'] );
554
-        $reason_code    = intval( $_POST['x_response_reason_code'] );
552
+    if ($subscription_id) {
553
+        $response_code  = intval($_POST['x_response_code']);
554
+        $reason_code    = intval($_POST['x_response_reason_code']);
555 555
 
556
-        $subscription = new WPInv_Subscription( $subscription_id, true );
556
+        $subscription = new WPInv_Subscription($subscription_id, true);
557 557
 
558
-        if ( !$subscription->id ) {
558
+        if (!$subscription->id) {
559 559
             return;
560 560
         }
561 561
 
562
-        if ( 1 == $response_code ) {
562
+        if (1 == $response_code) {
563 563
             // Approved
564
-            $transaction_id = sanitize_text_field( $_POST['x_trans_id'] );
565
-            $renewal_amount = sanitize_text_field( $_POST['x_amount'] );
564
+            $transaction_id = sanitize_text_field($_POST['x_trans_id']);
565
+            $renewal_amount = sanitize_text_field($_POST['x_amount']);
566 566
 
567 567
             $args = array(
568 568
                 'amount'         => $renewal_amount,
@@ -570,63 +570,63 @@  discard block
 block discarded – undo
570 570
                 'gateway'        => 'authorizenet'
571 571
             );
572 572
 
573
-            $subscription->add_payment( $args );
573
+            $subscription->add_payment($args);
574 574
             $subscription->renew();
575 575
 
576
-            do_action( 'wpinv_recurring_authorizenet_silent_post_payment', $subscription );
577
-            do_action( 'wpinv_authorizenet_renewal_payment', $subscription );
578
-        } else if ( 2 == $response_code ) {
576
+            do_action('wpinv_recurring_authorizenet_silent_post_payment', $subscription);
577
+            do_action('wpinv_authorizenet_renewal_payment', $subscription);
578
+        } else if (2 == $response_code) {
579 579
             // Declined
580 580
             $subscription->failing();
581
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $subscription );
582
-            do_action( 'wpinv_authorizenet_renewal_error', $subscription );
583
-        } else if ( 3 == $response_code || 8 == $reason_code ) {
581
+            do_action('wpinv_authorizenet_renewal_payment_failed', $subscription);
582
+            do_action('wpinv_authorizenet_renewal_error', $subscription);
583
+        } else if (3 == $response_code || 8 == $reason_code) {
584 584
             // An expired card
585 585
             $subscription->failing();
586
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $subscription );
587
-            do_action( 'wpinv_authorizenet_renewal_error', $subscription );
586
+            do_action('wpinv_authorizenet_renewal_payment_failed', $subscription);
587
+            do_action('wpinv_authorizenet_renewal_error', $subscription);
588 588
         } else {
589 589
             // Other Error
590
-            do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription );
590
+            do_action('wpinv_authorizenet_renewal_payment_error', $subscription);
591 591
         }
592 592
 
593 593
         exit;
594 594
     }
595 595
 }
596
-add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' );
596
+add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn');
597 597
 
598 598
 /**
599 599
  * Retrieve the subscription
600 600
  */
601
-function wpinv_get_authorizenet_subscription( $subscription_data = array(), $invoice_id ) {
602
-    $parent_invoice_id = absint( $invoice_id );
601
+function wpinv_get_authorizenet_subscription($subscription_data = array(), $invoice_id) {
602
+    $parent_invoice_id = absint($invoice_id);
603 603
 
604
-    if ( empty( $subscription_data ) ) {
604
+    if (empty($subscription_data)) {
605 605
         return false;
606 606
     }
607 607
 
608
-    if ( empty( $parent_invoice_id ) ) {
608
+    if (empty($parent_invoice_id)) {
609 609
         return false;
610 610
     }
611 611
 
612
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
613
-    if ( empty( $invoice ) ) {
612
+    $invoice = wpinv_get_invoice($parent_invoice_id);
613
+    if (empty($invoice)) {
614 614
         return false;
615 615
     }
616 616
 
617 617
     $subscriptionId     = (array)$subscription_data->subscriptionId;
618
-    $subscription_id    = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $parent_invoice_id;
618
+    $subscription_id    = !empty($subscriptionId[0]) ? $subscriptionId[0] : $parent_invoice_id;
619 619
 
620
-    $subscription = new WPInv_Subscription( $subscription_id, true );
620
+    $subscription = new WPInv_Subscription($subscription_id, true);
621 621
 
622
-    if ( ! $subscription || $subscription->id < 1 ) {
622
+    if (!$subscription || $subscription->id < 1) {
623 623
         $subs_db      = new WPInv_Subscriptions_DB;
624
-        $subs         = $subs_db->get_subscriptions( array( 'parent_payment_id' => $parent_invoice_id, 'number' => 1 ) );
625
-        $subscription = reset( $subs );
624
+        $subs         = $subs_db->get_subscriptions(array('parent_payment_id' => $parent_invoice_id, 'number' => 1));
625
+        $subscription = reset($subs);
626 626
 
627
-        if ( $subscription && $subscription->id > 0 ) {
627
+        if ($subscription && $subscription->id > 0) {
628 628
             // Update the profile ID so it is set for future renewals
629
-            $subscription->update( array( 'profile_id' => sanitize_text_field( $subscription_id ) ) );
629
+            $subscription->update(array('profile_id' => sanitize_text_field($subscription_id)));
630 630
         } else {
631 631
             // No subscription found with a matching payment ID, bail
632 632
             return false;
@@ -637,12 +637,12 @@  discard block
 block discarded – undo
637 637
 }
638 638
 
639 639
 function wpinv_is_authorizenet_valid_for_use() {
640
-    return in_array( wpinv_get_currency(), apply_filters( 'wpinv_authorizenet_supported_currencies', array( 'AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'JPY', 'NOK', 'NZD', 'PLN', 'SEK', 'USD', 'ZAR' ) ) );
640
+    return in_array(wpinv_get_currency(), apply_filters('wpinv_authorizenet_supported_currencies', array('AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'JPY', 'NOK', 'NZD', 'PLN', 'SEK', 'USD', 'ZAR')));
641 641
 }
642
-function wpinv_check_authorizenet_currency_support( $gateway_list ) {
643
-    if ( isset( $gateway_list['authorizenet'] ) && ! wpinv_is_authorizenet_valid_for_use() ) {
644
-        unset( $gateway_list['authorizenet'] );
642
+function wpinv_check_authorizenet_currency_support($gateway_list) {
643
+    if (isset($gateway_list['authorizenet']) && !wpinv_is_authorizenet_valid_for_use()) {
644
+        unset($gateway_list['authorizenet']);
645 645
     }
646 646
     return $gateway_list;
647 647
 }
648
-add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1 );
649 648
\ No newline at end of file
649
+add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1);
650 650
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/worldpay.php 1 patch
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  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_worldpay_cc_form', '__return_false' );
5
+add_action('wpinv_worldpay_cc_form', '__return_false');
6 6
 
7
-function wpinv_process_worldpay_payment( $purchase_data ) {
8
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
9
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
7
+function wpinv_process_worldpay_payment($purchase_data) {
8
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
9
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
10 10
     }
11 11
     
12 12
     // Collect payment data
@@ -24,132 +24,132 @@  discard block
 block discarded – undo
24 24
     );
25 25
 
26 26
     // Record the pending payment
27
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
27
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
28 28
     
29
-    if ( !empty( $invoice ) ) {
29
+    if (!empty($invoice)) {
30 30
         $quantities_enabled = wpinv_item_quantities_enabled();
31 31
         
32
-        $instId     = wpinv_get_option( 'worldpay_instId', false );
32
+        $instId     = wpinv_get_option('worldpay_instId', false);
33 33
         $cartId     = $invoice->get_number();
34
-        $testMode   = wpinv_is_test_mode( 'worldpay' ) ? 100 : 0;
34
+        $testMode   = wpinv_is_test_mode('worldpay') ? 100 : 0;
35 35
         $name       = $invoice->get_user_full_name();
36
-        $address    = wp_strip_all_tags( $invoice->get_address(), true );
36
+        $address    = wp_strip_all_tags($invoice->get_address(), true);
37 37
         $postcode   = $invoice->zip;
38 38
         $tel        = $invoice->phone;
39 39
         $email      = $invoice->get_email();
40 40
         $country    = $invoice->country;
41
-        $amount     = wpinv_sanitize_amount( $invoice->get_total() );
41
+        $amount     = wpinv_sanitize_amount($invoice->get_total());
42 42
         $currency   = wpinv_get_currency();
43 43
         
44 44
         $items      = array();
45
-        foreach ( $invoice->get_cart_details() as $item ) {
45
+        foreach ($invoice->get_cart_details() as $item) {
46 46
             $item_desc  = $item['name'];
47
-            $quantity   = !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1;
48
-            $item_desc .= ' (' . ( $quantities_enabled ? $quantity . 'x ' : '' ) . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')';
47
+            $quantity   = !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1;
48
+            $item_desc .= ' (' . ($quantities_enabled ? $quantity . 'x ' : '') . wpinv_price(wpinv_format_amount($item['item_price'])) . ')';
49 49
             
50 50
             $items[] = $item_desc;
51 51
         }
52 52
         
53
-        $desc = implode( ', ', $items );
54
-        if ( wpinv_use_taxes() && $invoice->get_tax() > 0 ) {
55
-            $desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) );
53
+        $desc = implode(', ', $items);
54
+        if (wpinv_use_taxes() && $invoice->get_tax() > 0) {
55
+            $desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true));
56 56
         }
57 57
         
58 58
         $extra_params                   = array();
59 59
         $extra_params['MC_description'] = $desc;
60
-        $extra_params['MC_callback']    = wpinv_get_ipn_url( 'worldpay' );
60
+        $extra_params['MC_callback']    = wpinv_get_ipn_url('worldpay');
61 61
         $extra_params['MC_key']         = $invoice->get_key();
62 62
         $extra_params['MC_invoice_id']  = $invoice->ID;
63 63
         $extra_params['address1']       = $address;
64 64
         $extra_params['town']           = $invoice->city;
65 65
         $extra_params['region']         = $invoice->state;
66
-        $extra_params['amountString']   = $invoice->get_total( true );
67
-        $extra_params['countryString']  = wpinv_country_name( $invoice->country );
66
+        $extra_params['amountString']   = $invoice->get_total(true);
67
+        $extra_params['countryString']  = wpinv_country_name($invoice->country);
68 68
         $extra_params['compName']       = $invoice->company;
69 69
         
70
-        $extra_params   = apply_filters( 'wpinv_worldpay_form_extra_parameters', $extra_params, $invoice );
70
+        $extra_params   = apply_filters('wpinv_worldpay_form_extra_parameters', $extra_params, $invoice);
71 71
         
72
-        $redirect_text  = __( 'Redirecting to Worldpay site, click on button if not redirected.', 'invoicing' );
73
-        $redirect_text  = apply_filters( 'wpinv_worldpay_redirect_text', $redirect_text, $invoice );
72
+        $redirect_text  = __('Redirecting to Worldpay site, click on button if not redirected.', 'invoicing');
73
+        $redirect_text  = apply_filters('wpinv_worldpay_redirect_text', $redirect_text, $invoice);
74 74
         
75 75
         // Empty the shopping cart
76 76
         wpinv_empty_cart();
77 77
         ?>
78 78
 <div class="wpi-worldpay-form" style="padding:20px;font-family:arial,sans-serif;text-align:center;color:#555">
79
-<?php do_action( 'wpinv_worldpay_form_before', $invoice ); ?>
80
-<h3><?php echo $redirect_text ;?></h3>
79
+<?php do_action('wpinv_worldpay_form_before', $invoice); ?>
80
+<h3><?php echo $redirect_text; ?></h3>
81 81
 <form action="<?php echo wpinv_get_worldpay_redirect(); ?>" name="wpi_worldpay_form" method="POST">
82
-    <input type="hidden" value="<?php echo $amount;?>" name="amount">
83
-    <input type="hidden" value="<?php echo esc_attr( $cartId );?>" name="cartId">
84
-    <input type="hidden" value="<?php echo $currency;?>" name="currency">
85
-    <input type="hidden" value="<?php echo $instId;?>" name="instId">
86
-    <input type="hidden" value="<?php echo $testMode;?>" name="testMode">
87
-    <input type="hidden" value="<?php echo esc_attr( $name );?>" name="name">
88
-    <input type="hidden" value="<?php echo esc_attr( $address );?>" name="address">
89
-    <input type="hidden" value="<?php echo esc_attr( $postcode );?>" name="postcode">
90
-    <input type="hidden" value="<?php echo esc_attr( $tel );?>" name="tel">
91
-    <input type="hidden" value="<?php echo esc_attr( $email );?>" name="email">
92
-    <input type="hidden" value="<?php echo esc_attr( $country );?>" name="country">
93
-    <input type="hidden" value="<?php echo esc_attr( $desc );?>" name="desc">
94
-    <?php foreach ( $extra_params as $param => $value ) { ?>
95
-        <?php if ( !empty( $value !== false ) ) { ?>
96
-    <input type="hidden" value="<?php echo esc_attr( $value );?>" name="<?php echo esc_attr( $param );?>">
82
+    <input type="hidden" value="<?php echo $amount; ?>" name="amount">
83
+    <input type="hidden" value="<?php echo esc_attr($cartId); ?>" name="cartId">
84
+    <input type="hidden" value="<?php echo $currency; ?>" name="currency">
85
+    <input type="hidden" value="<?php echo $instId; ?>" name="instId">
86
+    <input type="hidden" value="<?php echo $testMode; ?>" name="testMode">
87
+    <input type="hidden" value="<?php echo esc_attr($name); ?>" name="name">
88
+    <input type="hidden" value="<?php echo esc_attr($address); ?>" name="address">
89
+    <input type="hidden" value="<?php echo esc_attr($postcode); ?>" name="postcode">
90
+    <input type="hidden" value="<?php echo esc_attr($tel); ?>" name="tel">
91
+    <input type="hidden" value="<?php echo esc_attr($email); ?>" name="email">
92
+    <input type="hidden" value="<?php echo esc_attr($country); ?>" name="country">
93
+    <input type="hidden" value="<?php echo esc_attr($desc); ?>" name="desc">
94
+    <?php foreach ($extra_params as $param => $value) { ?>
95
+        <?php if (!empty($value !== false)) { ?>
96
+    <input type="hidden" value="<?php echo esc_attr($value); ?>" name="<?php echo esc_attr($param); ?>">
97 97
         <?php } ?>
98 98
     <?php } ?>
99
-    <?php do_action( 'wpinv_worldpay_form_parameters', $invoice ); ?>
100
-    <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e( 'Pay by Debit/Credit Card (WorldPay)', 'invoicing' ) ;?>">
99
+    <?php do_action('wpinv_worldpay_form_parameters', $invoice); ?>
100
+    <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e('Pay by Debit/Credit Card (WorldPay)', 'invoicing'); ?>">
101 101
 </form>
102 102
 <script type="text/javascript">document.wpi_worldpay_form.submit();</script>
103
-<?php do_action( 'wpinv_worldpay_form_after', $invoice ); ?>
103
+<?php do_action('wpinv_worldpay_form_after', $invoice); ?>
104 104
 </div>
105 105
         <?php
106 106
     } else {
107
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
107
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
108 108
         // If errors are present, send the user back to the purchase page so they can be corrected
109
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
109
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
110 110
     }
111 111
 }
112
-add_action( 'wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment' );
112
+add_action('wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment');
113 113
 
114 114
 function wpinv_get_worldpay_redirect() {
115
-    $redirect = wpinv_is_test_mode( 'worldpay' ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
115
+    $redirect = wpinv_is_test_mode('worldpay') ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
116 116
     
117
-    return apply_filters( 'wpinv_worldpay_redirect', $redirect );
117
+    return apply_filters('wpinv_worldpay_redirect', $redirect);
118 118
 }
119 119
 
120 120
 function wpinv_process_worldpay_ipn() {
121
-    $request = wpinv_get_post_data( 'post' );
121
+    $request = wpinv_get_post_data('post');
122 122
     
123
-    if ( !empty( $request['cartId'] ) && !empty( $request['transStatus'] ) && !empty( $request['installation'] ) && isset( $request['testMode'] ) && isset( $request['MC_invoice_id'] ) && isset( $request['MC_key'] ) ) {
123
+    if (!empty($request['cartId']) && !empty($request['transStatus']) && !empty($request['installation']) && isset($request['testMode']) && isset($request['MC_invoice_id']) && isset($request['MC_key'])) {
124 124
         $invoice_id = $request['MC_invoice_id'];
125 125
         
126
-        if ( $invoice_id == wpinv_get_invoice_id_by_key( $request['MC_key'] ) && $invoice = wpinv_get_invoice( $invoice_id ) ) {
127
-            if ( $request['transStatus'] == 'Y' ) {                
128
-                wpinv_update_payment_status( $invoice_id, 'publish' );
129
-                wpinv_set_payment_transaction_id( $invoice_id, $request['transId'] );
130
-                wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Worldpay Transaction ID: %s', 'invoicing' ), $request['transId'] ) );
126
+        if ($invoice_id == wpinv_get_invoice_id_by_key($request['MC_key']) && $invoice = wpinv_get_invoice($invoice_id)) {
127
+            if ($request['transStatus'] == 'Y') {                
128
+                wpinv_update_payment_status($invoice_id, 'publish');
129
+                wpinv_set_payment_transaction_id($invoice_id, $request['transId']);
130
+                wpinv_insert_payment_note($invoice_id, sprintf(__('Worldpay Transaction ID: %s', 'invoicing'), $request['transId']));
131 131
                 return;
132
-            } else if ( $request['transStatus'] == 'C' ) {
133
-                wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
134
-                wpinv_insert_payment_note( $invoice_id, __( 'Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing' ) );
132
+            } else if ($request['transStatus'] == 'C') {
133
+                wpinv_update_payment_status($invoice_id, 'wpi-failed');
134
+                wpinv_insert_payment_note($invoice_id, __('Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing'));
135 135
                 
136
-                wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing' ), json_encode( $request ) ), $invoice_id );
136
+                wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing'), json_encode($request)), $invoice_id);
137 137
                 return;
138 138
             }
139 139
         }
140 140
     }
141 141
     return;
142 142
 }
143
-add_action( 'wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn' );
143
+add_action('wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn');
144 144
 
145 145
 function wpinv_is_worldpay_valid_for_use() {
146
-    return in_array( wpinv_get_currency(), apply_filters( 'wpinv_worldpay_supported_currencies', array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' )));
146
+    return in_array(wpinv_get_currency(), apply_filters('wpinv_worldpay_supported_currencies', array('AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR')));
147 147
 }
148 148
 
149
-function wpinv_check_worldpay_currency_support( $gateway_list ) {
150
-    if ( isset( $gateway_list['worldpay'] ) && ! wpinv_is_worldpay_valid_for_use() ) {
151
-        unset( $gateway_list['worldpay'] );
149
+function wpinv_check_worldpay_currency_support($gateway_list) {
150
+    if (isset($gateway_list['worldpay']) && !wpinv_is_worldpay_valid_for_use()) {
151
+        unset($gateway_list['worldpay']);
152 152
     }
153 153
     return $gateway_list;
154 154
 }
155
-add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_worldpay_currency_support', 10, 1 );
156 155
\ No newline at end of file
156
+add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_worldpay_currency_support', 10, 1);
157 157
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/paypal.php 2 patches
Indentation   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -218,262 +218,262 @@  discard block
 block discarded – undo
218 218
 add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 );
219 219
 
220 220
 function wpinv_process_paypal_ipn() {
221
-	// Check the request method is POST
222
-	if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
223
-		return;
224
-	}
225
-
226
-	// Set initial post data to empty string
227
-	$post_data = '';
228
-
229
-	// Fallback just in case post_max_size is lower than needed
230
-	if ( ini_get( 'allow_url_fopen' ) ) {
231
-		$post_data = file_get_contents( 'php://input' );
232
-	} else {
233
-		// If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
234
-		ini_set( 'post_max_size', '12M' );
235
-	}
236
-	// Start the encoded data collection with notification command
237
-	$encoded_data = 'cmd=_notify-validate';
238
-
239
-	// Get current arg separator
240
-	$arg_separator = wpinv_get_php_arg_separator_output();
241
-
242
-	// Verify there is a post_data
243
-	if ( $post_data || strlen( $post_data ) > 0 ) {
244
-		// Append the data
245
-		$encoded_data .= $arg_separator.$post_data;
246
-	} else {
247
-		// Check if POST is empty
248
-		if ( empty( $_POST ) ) {
249
-			// Nothing to do
250
-			return;
251
-		} else {
252
-			// Loop through each POST
253
-			foreach ( $_POST as $key => $value ) {
254
-				// Encode the value and append the data
255
-				$encoded_data .= $arg_separator."$key=" . urlencode( $value );
256
-			}
257
-		}
258
-	}
259
-
260
-	// Convert collected post data to an array
261
-	parse_str( $encoded_data, $encoded_data_array );
262
-
263
-	foreach ( $encoded_data_array as $key => $value ) {
264
-		if ( false !== strpos( $key, 'amp;' ) ) {
265
-			$new_key = str_replace( '&amp;', '&', $key );
266
-			$new_key = str_replace( 'amp;', '&' , $new_key );
267
-
268
-			unset( $encoded_data_array[ $key ] );
269
-			$encoded_data_array[ $new_key ] = $value;
270
-		}
271
-	}
272
-
273
-	// Get the PayPal redirect uri
274
-	$paypal_redirect = wpinv_get_paypal_redirect( true );
275
-
276
-	if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
277
-		// Validate the IPN
278
-
279
-		$remote_post_vars      = array(
280
-			'method'           => 'POST',
281
-			'timeout'          => 45,
282
-			'redirection'      => 5,
283
-			'httpversion'      => '1.1',
284
-			'blocking'         => true,
285
-			'headers'          => array(
286
-				'host'         => 'www.paypal.com',
287
-				'connection'   => 'close',
288
-				'content-type' => 'application/x-www-form-urlencoded',
289
-				'post'         => '/cgi-bin/webscr HTTP/1.1',
290
-
291
-			),
292
-			'sslverify'        => false,
293
-			'body'             => $encoded_data_array
294
-		);
295
-
296
-		// Get response
297
-		$api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
298
-
299
-		if ( is_wp_error( $api_response ) ) {
300
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
301
-			return; // Something went wrong
302
-		}
303
-
304
-		if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
305
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
306
-			return; // Response not okay
307
-		}
308
-	}
309
-
310
-	// Check if $post_data_array has been populated
311
-	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
312
-		return;
313
-
314
-	$defaults = array(
315
-		'txn_type'       => '',
316
-		'payment_status' => ''
317
-	);
318
-
319
-	$encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
320
-
321
-	$invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
221
+    // Check the request method is POST
222
+    if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
223
+        return;
224
+    }
225
+
226
+    // Set initial post data to empty string
227
+    $post_data = '';
228
+
229
+    // Fallback just in case post_max_size is lower than needed
230
+    if ( ini_get( 'allow_url_fopen' ) ) {
231
+        $post_data = file_get_contents( 'php://input' );
232
+    } else {
233
+        // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
234
+        ini_set( 'post_max_size', '12M' );
235
+    }
236
+    // Start the encoded data collection with notification command
237
+    $encoded_data = 'cmd=_notify-validate';
238
+
239
+    // Get current arg separator
240
+    $arg_separator = wpinv_get_php_arg_separator_output();
241
+
242
+    // Verify there is a post_data
243
+    if ( $post_data || strlen( $post_data ) > 0 ) {
244
+        // Append the data
245
+        $encoded_data .= $arg_separator.$post_data;
246
+    } else {
247
+        // Check if POST is empty
248
+        if ( empty( $_POST ) ) {
249
+            // Nothing to do
250
+            return;
251
+        } else {
252
+            // Loop through each POST
253
+            foreach ( $_POST as $key => $value ) {
254
+                // Encode the value and append the data
255
+                $encoded_data .= $arg_separator."$key=" . urlencode( $value );
256
+            }
257
+        }
258
+    }
259
+
260
+    // Convert collected post data to an array
261
+    parse_str( $encoded_data, $encoded_data_array );
262
+
263
+    foreach ( $encoded_data_array as $key => $value ) {
264
+        if ( false !== strpos( $key, 'amp;' ) ) {
265
+            $new_key = str_replace( '&amp;', '&', $key );
266
+            $new_key = str_replace( 'amp;', '&' , $new_key );
267
+
268
+            unset( $encoded_data_array[ $key ] );
269
+            $encoded_data_array[ $new_key ] = $value;
270
+        }
271
+    }
272
+
273
+    // Get the PayPal redirect uri
274
+    $paypal_redirect = wpinv_get_paypal_redirect( true );
275
+
276
+    if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
277
+        // Validate the IPN
278
+
279
+        $remote_post_vars      = array(
280
+            'method'           => 'POST',
281
+            'timeout'          => 45,
282
+            'redirection'      => 5,
283
+            'httpversion'      => '1.1',
284
+            'blocking'         => true,
285
+            'headers'          => array(
286
+                'host'         => 'www.paypal.com',
287
+                'connection'   => 'close',
288
+                'content-type' => 'application/x-www-form-urlencoded',
289
+                'post'         => '/cgi-bin/webscr HTTP/1.1',
290
+
291
+            ),
292
+            'sslverify'        => false,
293
+            'body'             => $encoded_data_array
294
+        );
295
+
296
+        // Get response
297
+        $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
298
+
299
+        if ( is_wp_error( $api_response ) ) {
300
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
301
+            return; // Something went wrong
302
+        }
303
+
304
+        if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
305
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
306
+            return; // Response not okay
307
+        }
308
+    }
309
+
310
+    // Check if $post_data_array has been populated
311
+    if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
312
+        return;
313
+
314
+    $defaults = array(
315
+        'txn_type'       => '',
316
+        'payment_status' => ''
317
+    );
318
+
319
+    $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
320
+
321
+    $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
322 322
     
323
-	wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
324
-	wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ );
325
-
326
-	if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
327
-		// Allow PayPal IPN types to be processed separately
328
-		do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
329
-	} else {
330
-		// Fallback to web accept just in case the txn_type isn't present
331
-		do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
332
-	}
333
-	exit;
323
+    wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
324
+    wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ );
325
+
326
+    if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
327
+        // Allow PayPal IPN types to be processed separately
328
+        do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
329
+    } else {
330
+        // Fallback to web accept just in case the txn_type isn't present
331
+        do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
332
+    }
333
+    exit;
334 334
 }
335 335
 add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' );
336 336
 
337 337
 function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) {
338
-	if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
339
-		return;
340
-	}
341
-
342
-	if( empty( $invoice_id ) ) {
343
-		return;
344
-	}
345
-
346
-	// Collect payment details
347
-	$purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
348
-	$paypal_amount  = $data['mc_gross'];
349
-	$payment_status = strtolower( $data['payment_status'] );
350
-	$currency_code  = strtolower( $data['mc_currency'] );
351
-	$business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
352
-	$payment_meta   = wpinv_get_invoice_meta( $invoice_id );
353
-
354
-	if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
355
-		return; // this isn't a PayPal standard IPN
356
-	}
357
-
358
-	// Verify payment recipient
359
-	if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
360
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
361
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
362
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true );
363
-		return;
364
-	}
365
-
366
-	// Verify payment currency
367
-	if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
368
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
369
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
370
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true );
371
-		return;
372
-	}
373
-
374
-	if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
375
-		// This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
376
-		// No email associated with purchase, so store from PayPal
377
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
378
-
379
-		// Setup and store the customer's details
380
-		$user_info = array(
381
-			'user_id'    => '-1',
382
-			'email'      => sanitize_text_field( $data['payer_email'] ),
383
-			'first_name' => sanitize_text_field( $data['first_name'] ),
384
-			'last_name'  => sanitize_text_field( $data['last_name'] ),
385
-			'discount'   => '',
386
-		);
387
-		$user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
388
-		$user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
389
-		$user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
390
-		$user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
391
-		$user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
392
-
393
-		$payment_meta['user_info'] = $user_info;
394
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
395
-	}
396
-
397
-	if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
398
-		// Process a refund
399
-		wpinv_process_paypal_refund( $data, $invoice_id );
400
-	} else {
401
-		if ( get_post_status( $invoice_id ) == 'publish' ) {
402
-			return; // Only paid payments once
403
-		}
404
-
405
-		// Retrieve the total purchase amount (before PayPal)
406
-		$payment_amount = wpinv_payment_total( $invoice_id );
407
-
408
-		if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
409
-			// The prices don't match
410
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
411
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
412
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true );
413
-			return;
414
-		}
415
-		if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
416
-			// Purchase keys don't match
417
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
418
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
419
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true );
420
-			return;
421
-		}
422
-
423
-		if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
424
-			wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true );
425
-			wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
426
-			wpinv_update_payment_status( $invoice_id, 'publish' );
427
-		} else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
428
-			// Look for possible pending reasons, such as an echeck
429
-			$note = '';
430
-
431
-			switch( strtolower( $data['pending_reason'] ) ) {
432
-				case 'echeck' :
433
-					$note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
434
-					break;
338
+    if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
339
+        return;
340
+    }
341
+
342
+    if( empty( $invoice_id ) ) {
343
+        return;
344
+    }
345
+
346
+    // Collect payment details
347
+    $purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
348
+    $paypal_amount  = $data['mc_gross'];
349
+    $payment_status = strtolower( $data['payment_status'] );
350
+    $currency_code  = strtolower( $data['mc_currency'] );
351
+    $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
352
+    $payment_meta   = wpinv_get_invoice_meta( $invoice_id );
353
+
354
+    if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
355
+        return; // this isn't a PayPal standard IPN
356
+    }
357
+
358
+    // Verify payment recipient
359
+    if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
360
+        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
361
+        wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
362
+        wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true );
363
+        return;
364
+    }
365
+
366
+    // Verify payment currency
367
+    if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
368
+        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
369
+        wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
370
+        wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true );
371
+        return;
372
+    }
373
+
374
+    if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
375
+        // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
376
+        // No email associated with purchase, so store from PayPal
377
+        wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
378
+
379
+        // Setup and store the customer's details
380
+        $user_info = array(
381
+            'user_id'    => '-1',
382
+            'email'      => sanitize_text_field( $data['payer_email'] ),
383
+            'first_name' => sanitize_text_field( $data['first_name'] ),
384
+            'last_name'  => sanitize_text_field( $data['last_name'] ),
385
+            'discount'   => '',
386
+        );
387
+        $user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
388
+        $user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
389
+        $user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
390
+        $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
391
+        $user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
392
+
393
+        $payment_meta['user_info'] = $user_info;
394
+        wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
395
+    }
396
+
397
+    if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
398
+        // Process a refund
399
+        wpinv_process_paypal_refund( $data, $invoice_id );
400
+    } else {
401
+        if ( get_post_status( $invoice_id ) == 'publish' ) {
402
+            return; // Only paid payments once
403
+        }
404
+
405
+        // Retrieve the total purchase amount (before PayPal)
406
+        $payment_amount = wpinv_payment_total( $invoice_id );
407
+
408
+        if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
409
+            // The prices don't match
410
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
411
+            wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
412
+            wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true );
413
+            return;
414
+        }
415
+        if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
416
+            // Purchase keys don't match
417
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
418
+            wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
419
+            wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true );
420
+            return;
421
+        }
422
+
423
+        if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
424
+            wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true );
425
+            wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
426
+            wpinv_update_payment_status( $invoice_id, 'publish' );
427
+        } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
428
+            // Look for possible pending reasons, such as an echeck
429
+            $note = '';
430
+
431
+            switch( strtolower( $data['pending_reason'] ) ) {
432
+                case 'echeck' :
433
+                    $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
434
+                    break;
435 435
 				
436 436
                 case 'address' :
437
-					$note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
438
-					break;
437
+                    $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
438
+                    break;
439 439
 				
440 440
                 case 'intl' :
441
-					$note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
442
-					break;
441
+                    $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
442
+                    break;
443 443
 				
444 444
                 case 'multi-currency' :
445
-					$note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
446
-					break;
445
+                    $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
446
+                    break;
447 447
 				
448 448
                 case 'paymentreview' :
449 449
                 case 'regulatory_review' :
450
-					$note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
451
-					break;
450
+                    $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
451
+                    break;
452 452
 				
453 453
                 case 'unilateral' :
454
-					$note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
455
-					break;
454
+                    $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
455
+                    break;
456 456
 				
457 457
                 case 'upgrade' :
458
-					$note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
459
-					break;
458
+                    $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
459
+                    break;
460 460
 				
461 461
                 case 'verify' :
462
-					$note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
463
-					break;
464
-
465
-				case 'other' :
466
-					$note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
467
-					break;
468
-			}
469
-
470
-			if ( ! empty( $note ) ) {
471
-				wpinv_insert_payment_note( $invoice_id, $note, '', '', true );
472
-			}
473
-		} else {
474
-			wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true );
475
-		}
476
-	}
462
+                    $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
463
+                    break;
464
+
465
+                case 'other' :
466
+                    $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
467
+                    break;
468
+            }
469
+
470
+            if ( ! empty( $note ) ) {
471
+                wpinv_insert_payment_note( $invoice_id, $note, '', '', true );
472
+            }
473
+        } else {
474
+            wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true );
475
+        }
476
+    }
477 477
 }
478 478
 add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 );
479 479
 
@@ -661,34 +661,34 @@  discard block
 block discarded – undo
661 661
 }
662 662
 
663 663
 function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) {
664
-	// Collect payment details
664
+    // Collect payment details
665 665
 
666
-	if( empty( $invoice_id ) ) {
667
-		return;
668
-	}
666
+    if( empty( $invoice_id ) ) {
667
+        return;
668
+    }
669 669
 
670
-	if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
671
-		return; // Only refund payments once
672
-	}
670
+    if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
671
+        return; // Only refund payments once
672
+    }
673 673
 
674
-	$payment_amount = wpinv_payment_total( $invoice_id );
675
-	$refund_amount  = $data['mc_gross'] * -1;
674
+    $payment_amount = wpinv_payment_total( $invoice_id );
675
+    $refund_amount  = $data['mc_gross'] * -1;
676 676
 
677
-	do_action( 'wpinv_paypal_refund_request', $data, $invoice_id );
677
+    do_action( 'wpinv_paypal_refund_request', $data, $invoice_id );
678 678
 
679
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
680
-		wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
679
+    if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
680
+        wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
681 681
 
682
-		do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount );
682
+        do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount );
683 683
 
684
-		return; // This is a partial refund
685
-	}
684
+        return; // This is a partial refund
685
+    }
686 686
 
687
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
688
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true );
689
-	wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
687
+    wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
688
+    wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true );
689
+    wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
690 690
 
691
-	do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id );
691
+    do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id );
692 692
 }
693 693
 
694 694
 function wpinv_get_paypal_redirect( $ssl_check = false ) {
Please login to merge, or discard this patch.
Spacing   +262 added lines, -262 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
@@ -25,30 +25,30 @@  discard block
 block discarded – undo
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 ) ), $invoice );
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)), $invoice);
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,16 +57,16 @@  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
-            'landing_page'  => apply_filters( 'wpinv_paypal_standard_landing_page', 'billing', $invoice ), // 'login' or 'billing'. login - PayPal account login, billing - Non-PayPal account.
69
+            'landing_page'  => apply_filters('wpinv_paypal_standard_landing_page', 'billing', $invoice), // 'login' or 'billing'. login - PayPal account login, billing - Non-PayPal account.
70 70
         );
71 71
 
72 72
         $paypal_args['address1'] = $invoice->get_address();
@@ -80,57 +80,57 @@  discard block
 block discarded – undo
80 80
             'upload' => '1'
81 81
         );
82 82
 
83
-        $paypal_args = array_merge( $paypal_extra_args, $paypal_args );
83
+        $paypal_args = array_merge($paypal_extra_args, $paypal_args);
84 84
 
85 85
         // Add cart items
86 86
         $i = 1;
87
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
88
-            foreach ( $purchase_data['cart_details'] as $item ) {
87
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
88
+            foreach ($purchase_data['cart_details'] as $item) {
89 89
                 $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1;
90
-                $item_amount = wpinv_sanitize_amount( $item['subtotal'] / $item['quantity'], 2 );
90
+                $item_amount = wpinv_sanitize_amount($item['subtotal'] / $item['quantity'], 2);
91 91
 
92
-                if ( $item_amount <= 0 ) {
92
+                if ($item_amount <= 0) {
93 93
                     $item_amount = 0;
94 94
                 }
95 95
 
96
-                $paypal_args['item_number_' . $i ]      = $item['id'];
97
-                $paypal_args['item_name_' . $i ]        = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) );
98
-                $paypal_args['quantity_' . $i ]         = $item['quantity'];
99
-                $paypal_args['amount_' . $i ]           = $item_amount;
100
-                $paypal_args['discount_amount_' . $i ]  = wpinv_sanitize_amount( $item['discount'], 2 );
96
+                $paypal_args['item_number_' . $i]      = $item['id'];
97
+                $paypal_args['item_name_' . $i]        = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8'));
98
+                $paypal_args['quantity_' . $i]         = $item['quantity'];
99
+                $paypal_args['amount_' . $i]           = $item_amount;
100
+                $paypal_args['discount_amount_' . $i]  = wpinv_sanitize_amount($item['discount'], 2);
101 101
 
102 102
                 $i++;
103 103
             }
104 104
         }
105 105
 
106 106
         // Add taxes to the cart
107
-        if ( wpinv_use_taxes() ) {
108
-            $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float)$invoice->get_tax(), 2 );
107
+        if (wpinv_use_taxes()) {
108
+            $paypal_args['tax_cart'] = wpinv_sanitize_amount((float)$invoice->get_tax(), 2);
109 109
         }
110 110
 
111
-        $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice );
111
+        $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice);
112 112
 
113 113
         // Build query
114
-        $paypal_redirect .= http_build_query( $paypal_args );
114
+        $paypal_redirect .= http_build_query($paypal_args);
115 115
 
116 116
         // Fix for some sites that encode the entities
117
-        $paypal_redirect = str_replace( '&amp;', '&', $paypal_redirect );
117
+        $paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
118 118
 
119 119
         // Get rid of cart contents
120 120
         wpinv_empty_cart();
121 121
         
122 122
         // Redirect to PayPal
123
-        wp_redirect( $paypal_redirect );
123
+        wp_redirect($paypal_redirect);
124 124
         exit;
125 125
     }
126 126
 }
127
-add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' );
127
+add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment');
128 128
 
129
-function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) {
130
-    if ( $invoice->is_recurring() && $item_id = $invoice->get_recurring() ) {
131
-        $item   = new WPInv_Item( $item_id );
129
+function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) {
130
+    if ($invoice->is_recurring() && $item_id = $invoice->get_recurring()) {
131
+        $item = new WPInv_Item($item_id);
132 132
         
133
-        if ( empty( $item ) ) {
133
+        if (empty($item)) {
134 134
             return $paypal_args;
135 135
         }
136 136
 
@@ -138,24 +138,24 @@  discard block
 block discarded – undo
138 138
         $interval           = $item->get_recurring_interval();
139 139
         $bill_times         = (int)$item->get_recurring_limit();
140 140
         
141
-        $initial_amount     = wpinv_sanitize_amount( $invoice->get_total(), 2 );
142
-        $recurring_amount   = wpinv_sanitize_amount( $invoice->get_recurring_details( 'total' ), 2 );
141
+        $initial_amount     = wpinv_sanitize_amount($invoice->get_total(), 2);
142
+        $recurring_amount   = wpinv_sanitize_amount($invoice->get_recurring_details('total'), 2);
143 143
         
144 144
         $paypal_args['cmd'] = '_xclick-subscriptions';
145 145
         $paypal_args['sra'] = '1';
146 146
         $paypal_args['src'] = '1';
147 147
         
148 148
         // Set item description
149
-        $paypal_args['item_name']   = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( array( 'id' => $item->ID ) ), ENT_COMPAT, 'UTF-8' ) );
149
+        $paypal_args['item_name'] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name(array('id' => $item->ID)), ENT_COMPAT, 'UTF-8'));
150 150
         
151
-        if ( $invoice->is_free_trial() && $item->has_free_trial() ) {
151
+        if ($invoice->is_free_trial() && $item->has_free_trial()) {
152 152
             $paypal_args['a1']  = $initial_amount;
153 153
             $paypal_args['p1']  = $item->get_trial_interval();
154 154
             $paypal_args['t1']  = $item->get_trial_period();
155 155
             
156 156
             // Set the recurring amount
157 157
             $paypal_args['a3']  = $recurring_amount;
158
-        } else if ( $initial_amount != $recurring_amount && $bill_times != 1 ) {
158
+        } else if ($initial_amount != $recurring_amount && $bill_times != 1) {
159 159
             $paypal_args['a1']  = $initial_amount;
160 160
             $paypal_args['p1']  = $interval;
161 161
             $paypal_args['t1']  = $period;
@@ -163,63 +163,63 @@  discard block
 block discarded – undo
163 163
             // Set the recurring amount
164 164
             $paypal_args['a3']  = $recurring_amount;
165 165
             
166
-            if ( $bill_times > 1 ) {
166
+            if ($bill_times > 1) {
167 167
                 $bill_times--;
168 168
             }
169 169
         } else {
170
-            $paypal_args['a3']  = $initial_amount;
170
+            $paypal_args['a3'] = $initial_amount;
171 171
         }
172 172
         
173 173
         $paypal_args['p3']  = $interval;
174 174
         $paypal_args['t3']  = $period;
175 175
         
176
-        if ( $bill_times > 1 ) {
176
+        if ($bill_times > 1) {
177 177
             // Make sure it's not over the max of 52
178
-            $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
178
+            $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
179 179
         }
180 180
                 
181 181
         // Remove cart items
182 182
         $i = 1;
183
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
184
-            foreach ( $purchase_data['cart_details'] as $item ) {                
185
-                if ( isset( $paypal_args['item_number_' . $i] ) ) {
186
-                    unset( $paypal_args['item_number_' . $i] );
183
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
184
+            foreach ($purchase_data['cart_details'] as $item) {                
185
+                if (isset($paypal_args['item_number_' . $i])) {
186
+                    unset($paypal_args['item_number_' . $i]);
187 187
                 }
188
-                if ( isset( $paypal_args['item_name_' . $i] ) ) {
189
-                    unset( $paypal_args['item_name_' . $i] );
188
+                if (isset($paypal_args['item_name_' . $i])) {
189
+                    unset($paypal_args['item_name_' . $i]);
190 190
                 }
191
-                if ( isset( $paypal_args['quantity_' . $i] ) ) {
192
-                    unset( $paypal_args['quantity_' . $i] );
191
+                if (isset($paypal_args['quantity_' . $i])) {
192
+                    unset($paypal_args['quantity_' . $i]);
193 193
                 }
194
-                if ( isset( $paypal_args['amount_' . $i] ) ) {
195
-                    unset( $paypal_args['amount_' . $i] );
194
+                if (isset($paypal_args['amount_' . $i])) {
195
+                    unset($paypal_args['amount_' . $i]);
196 196
                 }
197
-                if ( isset( $paypal_args['discount_amount_' . $i] ) ) {
198
-                    unset( $paypal_args['discount_amount_' . $i] );
197
+                if (isset($paypal_args['discount_amount_' . $i])) {
198
+                    unset($paypal_args['discount_amount_' . $i]);
199 199
                 }
200 200
 
201 201
                 $i++;
202 202
             }
203 203
         }
204 204
         
205
-        if ( isset( $paypal_args['tax_cart'] ) ) {
206
-            unset( $paypal_args['tax_cart'] );
205
+        if (isset($paypal_args['tax_cart'])) {
206
+            unset($paypal_args['tax_cart']);
207 207
         }
208 208
                 
209
-        if ( isset( $paypal_args['upload'] ) ) {
210
-            unset( $paypal_args['upload'] );
209
+        if (isset($paypal_args['upload'])) {
210
+            unset($paypal_args['upload']);
211 211
         }
212 212
         
213
-        $paypal_args = apply_filters( 'wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice );
213
+        $paypal_args = apply_filters('wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice);
214 214
     }
215 215
     
216 216
     return $paypal_args;
217 217
 }
218
-add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 );
218
+add_filter('wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3);
219 219
 
220 220
 function wpinv_process_paypal_ipn() {
221 221
 	// Check the request method is POST
222
-	if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
222
+	if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
223 223
 		return;
224 224
 	}
225 225
 
@@ -227,11 +227,11 @@  discard block
 block discarded – undo
227 227
 	$post_data = '';
228 228
 
229 229
 	// Fallback just in case post_max_size is lower than needed
230
-	if ( ini_get( 'allow_url_fopen' ) ) {
231
-		$post_data = file_get_contents( 'php://input' );
230
+	if (ini_get('allow_url_fopen')) {
231
+		$post_data = file_get_contents('php://input');
232 232
 	} else {
233 233
 		// If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
234
-		ini_set( 'post_max_size', '12M' );
234
+		ini_set('post_max_size', '12M');
235 235
 	}
236 236
 	// Start the encoded data collection with notification command
237 237
 	$encoded_data = 'cmd=_notify-validate';
@@ -240,43 +240,43 @@  discard block
 block discarded – undo
240 240
 	$arg_separator = wpinv_get_php_arg_separator_output();
241 241
 
242 242
 	// Verify there is a post_data
243
-	if ( $post_data || strlen( $post_data ) > 0 ) {
243
+	if ($post_data || strlen($post_data) > 0) {
244 244
 		// Append the data
245
-		$encoded_data .= $arg_separator.$post_data;
245
+		$encoded_data .= $arg_separator . $post_data;
246 246
 	} else {
247 247
 		// Check if POST is empty
248
-		if ( empty( $_POST ) ) {
248
+		if (empty($_POST)) {
249 249
 			// Nothing to do
250 250
 			return;
251 251
 		} else {
252 252
 			// Loop through each POST
253
-			foreach ( $_POST as $key => $value ) {
253
+			foreach ($_POST as $key => $value) {
254 254
 				// Encode the value and append the data
255
-				$encoded_data .= $arg_separator."$key=" . urlencode( $value );
255
+				$encoded_data .= $arg_separator . "$key=" . urlencode($value);
256 256
 			}
257 257
 		}
258 258
 	}
259 259
 
260 260
 	// Convert collected post data to an array
261
-	parse_str( $encoded_data, $encoded_data_array );
261
+	parse_str($encoded_data, $encoded_data_array);
262 262
 
263
-	foreach ( $encoded_data_array as $key => $value ) {
264
-		if ( false !== strpos( $key, 'amp;' ) ) {
265
-			$new_key = str_replace( '&amp;', '&', $key );
266
-			$new_key = str_replace( 'amp;', '&' , $new_key );
263
+	foreach ($encoded_data_array as $key => $value) {
264
+		if (false !== strpos($key, 'amp;')) {
265
+			$new_key = str_replace('&amp;', '&', $key);
266
+			$new_key = str_replace('amp;', '&', $new_key);
267 267
 
268
-			unset( $encoded_data_array[ $key ] );
269
-			$encoded_data_array[ $new_key ] = $value;
268
+			unset($encoded_data_array[$key]);
269
+			$encoded_data_array[$new_key] = $value;
270 270
 		}
271 271
 	}
272 272
 
273 273
 	// Get the PayPal redirect uri
274
-	$paypal_redirect = wpinv_get_paypal_redirect( true );
274
+	$paypal_redirect = wpinv_get_paypal_redirect(true);
275 275
 
276
-	if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
276
+	if (!wpinv_get_option('disable_paypal_verification', false)) {
277 277
 		// Validate the IPN
278 278
 
279
-		$remote_post_vars      = array(
279
+		$remote_post_vars = array(
280 280
 			'method'           => 'POST',
281 281
 			'timeout'          => 45,
282 282
 			'redirection'      => 5,
@@ -294,21 +294,21 @@  discard block
 block discarded – undo
294 294
 		);
295 295
 
296 296
 		// Get response
297
-		$api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
297
+		$api_response = wp_remote_post(wpinv_get_paypal_redirect(), $remote_post_vars);
298 298
 
299
-		if ( is_wp_error( $api_response ) ) {
300
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
299
+		if (is_wp_error($api_response)) {
300
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response)));
301 301
 			return; // Something went wrong
302 302
 		}
303 303
 
304
-		if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
305
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
304
+		if ($api_response['body'] !== 'VERIFIED' && wpinv_get_option('disable_paypal_verification', false)) {
305
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response)));
306 306
 			return; // Response not okay
307 307
 		}
308 308
 	}
309 309
 
310 310
 	// Check if $post_data_array has been populated
311
-	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
311
+	if (!is_array($encoded_data_array) && !empty($encoded_data_array))
312 312
 		return;
313 313
 
314 314
 	$defaults = array(
@@ -316,259 +316,259 @@  discard block
 block discarded – undo
316 316
 		'payment_status' => ''
317 317
 	);
318 318
 
319
-	$encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
319
+	$encoded_data_array = wp_parse_args($encoded_data_array, $defaults);
320 320
 
321
-	$invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
321
+	$invoice_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0;
322 322
     
323
-	wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
324
-	wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ );
323
+	wpinv_error_log($encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__);
324
+	wpinv_error_log($encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__);
325 325
 
326
-	if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
326
+	if (has_action('wpinv_paypal_' . $encoded_data_array['txn_type'])) {
327 327
 		// Allow PayPal IPN types to be processed separately
328
-		do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
328
+		do_action('wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id);
329 329
 	} else {
330 330
 		// Fallback to web accept just in case the txn_type isn't present
331
-		do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
331
+		do_action('wpinv_paypal_web_accept', $encoded_data_array, $invoice_id);
332 332
 	}
333 333
 	exit;
334 334
 }
335
-add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' );
335
+add_action('wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn');
336 336
 
337
-function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) {
338
-	if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
337
+function wpinv_process_paypal_web_accept_and_cart($data, $invoice_id) {
338
+	if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') {
339 339
 		return;
340 340
 	}
341 341
 
342
-	if( empty( $invoice_id ) ) {
342
+	if (empty($invoice_id)) {
343 343
 		return;
344 344
 	}
345 345
 
346 346
 	// Collect payment details
347
-	$purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
347
+	$purchase_key   = isset($data['invoice']) ? $data['invoice'] : $data['item_number'];
348 348
 	$paypal_amount  = $data['mc_gross'];
349
-	$payment_status = strtolower( $data['payment_status'] );
350
-	$currency_code  = strtolower( $data['mc_currency'] );
351
-	$business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
352
-	$payment_meta   = wpinv_get_invoice_meta( $invoice_id );
349
+	$payment_status = strtolower($data['payment_status']);
350
+	$currency_code  = strtolower($data['mc_currency']);
351
+	$business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']);
352
+	$payment_meta   = wpinv_get_invoice_meta($invoice_id);
353 353
 
354
-	if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
354
+	if (wpinv_get_payment_gateway($invoice_id) != 'paypal') {
355 355
 		return; // this isn't a PayPal standard IPN
356 356
 	}
357 357
 
358 358
 	// Verify payment recipient
359
-	if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
360
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
361
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
362
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true );
359
+	if (strcasecmp($business_email, trim(wpinv_get_option('paypal_email', false))) != 0) {
360
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
361
+		wpinv_update_payment_status($invoice_id, 'wpi-failed');
362
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid PayPal business email.', 'invoicing'), '', '', true);
363 363
 		return;
364 364
 	}
365 365
 
366 366
 	// Verify payment currency
367
-	if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
368
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
369
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
370
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true );
367
+	if ($currency_code != strtolower($payment_meta['currency'])) {
368
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
369
+		wpinv_update_payment_status($invoice_id, 'wpi-failed');
370
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid currency in PayPal IPN.', 'invoicing'), '', '', true);
371 371
 		return;
372 372
 	}
373 373
 
374
-	if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
374
+	if (!wpinv_get_payment_user_email($invoice_id)) {
375 375
 		// This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
376 376
 		// No email associated with purchase, so store from PayPal
377
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
377
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_email', $data['payer_email']);
378 378
 
379 379
 		// Setup and store the customer's details
380 380
 		$user_info = array(
381 381
 			'user_id'    => '-1',
382
-			'email'      => sanitize_text_field( $data['payer_email'] ),
383
-			'first_name' => sanitize_text_field( $data['first_name'] ),
384
-			'last_name'  => sanitize_text_field( $data['last_name'] ),
382
+			'email'      => sanitize_text_field($data['payer_email']),
383
+			'first_name' => sanitize_text_field($data['first_name']),
384
+			'last_name'  => sanitize_text_field($data['last_name']),
385 385
 			'discount'   => '',
386 386
 		);
387
-		$user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
388
-		$user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
389
-		$user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
390
-		$user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
391
-		$user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
387
+		$user_info['address'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false;
388
+		$user_info['city']    = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false;
389
+		$user_info['state']   = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false;
390
+		$user_info['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false;
391
+		$user_info['zip']     = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false;
392 392
 
393 393
 		$payment_meta['user_info'] = $user_info;
394
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
394
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_payment_meta', $payment_meta);
395 395
 	}
396 396
 
397
-	if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
397
+	if ($payment_status == 'refunded' || $payment_status == 'reversed') {
398 398
 		// Process a refund
399
-		wpinv_process_paypal_refund( $data, $invoice_id );
399
+		wpinv_process_paypal_refund($data, $invoice_id);
400 400
 	} else {
401
-		if ( get_post_status( $invoice_id ) == 'publish' ) {
401
+		if (get_post_status($invoice_id) == 'publish') {
402 402
 			return; // Only paid payments once
403 403
 		}
404 404
 
405 405
 		// Retrieve the total purchase amount (before PayPal)
406
-		$payment_amount = wpinv_payment_total( $invoice_id );
406
+		$payment_amount = wpinv_payment_total($invoice_id);
407 407
 
408
-		if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
408
+		if (number_format((float)$paypal_amount, 2) < number_format((float)$payment_amount, 2)) {
409 409
 			// The prices don't match
410
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
411
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
412
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true );
410
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
411
+			wpinv_update_payment_status($invoice_id, 'wpi-failed');
412
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid amount in PayPal IPN.', 'invoicing'), '', '', true);
413 413
 			return;
414 414
 		}
415
-		if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
415
+		if ($purchase_key != wpinv_get_payment_key($invoice_id)) {
416 416
 			// Purchase keys don't match
417
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
418
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
419
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true );
417
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
418
+			wpinv_update_payment_status($invoice_id, 'wpi-failed');
419
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing'), '', '', true);
420 420
 			return;
421 421
 		}
422 422
 
423
-		if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
424
-			wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true );
425
-			wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
426
-			wpinv_update_payment_status( $invoice_id, 'publish' );
427
-		} else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
423
+		if ('complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode('paypal')) {
424
+			wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $data['txn_id']), '', '', true);
425
+			wpinv_set_payment_transaction_id($invoice_id, $data['txn_id']);
426
+			wpinv_update_payment_status($invoice_id, 'publish');
427
+		} else if ('pending' == $payment_status && isset($data['pending_reason'])) {
428 428
 			// Look for possible pending reasons, such as an echeck
429 429
 			$note = '';
430 430
 
431
-			switch( strtolower( $data['pending_reason'] ) ) {
431
+			switch (strtolower($data['pending_reason'])) {
432 432
 				case 'echeck' :
433
-					$note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
433
+					$note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing');
434 434
 					break;
435 435
 				
436 436
                 case 'address' :
437
-					$note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
437
+					$note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing');
438 438
 					break;
439 439
 				
440 440
                 case 'intl' :
441
-					$note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
441
+					$note = __('Payment must be accepted manually through PayPal due to international account regulations', 'invoicing');
442 442
 					break;
443 443
 				
444 444
                 case 'multi-currency' :
445
-					$note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
445
+					$note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing');
446 446
 					break;
447 447
 				
448 448
                 case 'paymentreview' :
449 449
                 case 'regulatory_review' :
450
-					$note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
450
+					$note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing');
451 451
 					break;
452 452
 				
453 453
                 case 'unilateral' :
454
-					$note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
454
+					$note = __('Payment was sent to non-confirmed or non-registered email address.', 'invoicing');
455 455
 					break;
456 456
 				
457 457
                 case 'upgrade' :
458
-					$note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
458
+					$note = __('PayPal account must be upgraded before this payment can be accepted', 'invoicing');
459 459
 					break;
460 460
 				
461 461
                 case 'verify' :
462
-					$note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
462
+					$note = __('PayPal account is not verified. Verify account in order to accept this payment', 'invoicing');
463 463
 					break;
464 464
 
465 465
 				case 'other' :
466
-					$note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
466
+					$note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing');
467 467
 					break;
468 468
 			}
469 469
 
470
-			if ( ! empty( $note ) ) {
471
-				wpinv_insert_payment_note( $invoice_id, $note, '', '', true );
470
+			if (!empty($note)) {
471
+				wpinv_insert_payment_note($invoice_id, $note, '', '', true);
472 472
 			}
473 473
 		} else {
474
-			wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true );
474
+			wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal IPN has been received with invalid payment status: %s', 'invoicing'), $payment_status), '', '', true);
475 475
 		}
476 476
 	}
477 477
 }
478
-add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 );
478
+add_action('wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2);
479 479
 
480 480
 // Process PayPal subscription sign ups
481
-add_action( 'wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup' );
481
+add_action('wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup');
482 482
 
483 483
 // Process PayPal subscription payments
484
-add_action( 'wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment' );
484
+add_action('wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment');
485 485
 
486 486
 // Process PayPal subscription cancellations
487
-add_action( 'wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel' );
487
+add_action('wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel');
488 488
 
489 489
 // Process PayPal subscription end of term notices
490
-add_action( 'wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot' );
490
+add_action('wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot');
491 491
 
492 492
 // Process PayPal payment failed
493
-add_action( 'wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed' );
493
+add_action('wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed');
494 494
 
495 495
 
496 496
 /**
497 497
  * Process the subscription started IPN.
498 498
  */
499
-function wpinv_process_paypal_subscr_signup( $ipn_data ) {
500
-    $parent_invoice_id = absint( $ipn_data['custom'] );
501
-    if( empty( $parent_invoice_id ) ) {
499
+function wpinv_process_paypal_subscr_signup($ipn_data) {
500
+    $parent_invoice_id = absint($ipn_data['custom']);
501
+    if (empty($parent_invoice_id)) {
502 502
         return;
503 503
     }
504 504
 
505
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
506
-    if ( empty( $invoice ) ) {
505
+    $invoice = wpinv_get_invoice($parent_invoice_id);
506
+    if (empty($invoice)) {
507 507
         return;
508 508
     }
509 509
 
510
-    if ( $invoice->is_free_trial() && !empty( $ipn_data['invoice'] ) ) {
511
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Invoice ID: %s', 'invoicing' ) , $ipn_data['invoice'] ), '', '', true);
512
-        if ( !empty( $ipn_data['txn_id'] ) ) {
513
-            wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] );
510
+    if ($invoice->is_free_trial() && !empty($ipn_data['invoice'])) {
511
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Invoice ID: %s', 'invoicing'), $ipn_data['invoice']), '', '', true);
512
+        if (!empty($ipn_data['txn_id'])) {
513
+            wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']);
514 514
         }
515 515
     }
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
-    wpinv_update_payment_status( $parent_invoice_id, 'publish' );
522
+    wpinv_update_payment_status($parent_invoice_id, 'publish');
523 523
     sleep(1);
524
-    wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ), '', '', true );
525
-    update_post_meta($parent_invoice_id,'_wpinv_subscr_profile_id', $ipn_data['subscr_id']);
524
+    wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']), '', '', true);
525
+    update_post_meta($parent_invoice_id, '_wpinv_subscr_profile_id', $ipn_data['subscr_id']);
526 526
 
527 527
     $status = 'trialling' == $subscription->status ? 'trialling' : 'active';
528 528
     // Retrieve pending subscription from database and update it's status to active and set proper profile ID
529
-    $subscription->update( array( 'profile_id' => $ipn_data['subscr_id'], 'status' => $status ) );
529
+    $subscription->update(array('profile_id' => $ipn_data['subscr_id'], 'status' => $status));
530 530
 }
531 531
 
532 532
 /**
533 533
  * Process the subscription payment received IPN.
534 534
  */
535
-function wpinv_process_paypal_subscr_payment( $ipn_data ) {
536
-    $parent_invoice_id = absint( $ipn_data['custom'] );
535
+function wpinv_process_paypal_subscr_payment($ipn_data) {
536
+    $parent_invoice_id = absint($ipn_data['custom']);
537 537
 
538
-    $parent_invoice = wpinv_get_invoice( $parent_invoice_id );
539
-    if ( empty( $parent_invoice ) ) {
538
+    $parent_invoice = wpinv_get_invoice($parent_invoice_id);
539
+    if (empty($parent_invoice)) {
540 540
         return;
541 541
     }
542 542
 
543
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
544
-    if ( false === $subscription ) {
543
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
544
+    if (false === $subscription) {
545 545
         return;
546 546
     }
547 547
 
548
-    $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id );
548
+    $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id);
549 549
     $times_billed   = $subscription->get_times_billed();
550 550
 
551 551
     // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet.
552
-    if ( empty( $times_billed ) && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) {
553
-        wpinv_update_payment_status( $parent_invoice_id, 'publish' );
552
+    if (empty($times_billed) && (!$transaction_id || $transaction_id == $parent_invoice_id)) {
553
+        wpinv_update_payment_status($parent_invoice_id, 'publish');
554 554
         sleep(1);
555 555
         
556 556
         // This is the very first payment
557
-        wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] );
558
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true );
557
+        wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']);
558
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true);
559 559
         return;
560 560
     }
561 561
     
562
-    if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) {
562
+    if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) {
563 563
         return; // Payment already recorded
564 564
     }
565 565
 
566
-    $currency_code = strtolower( $ipn_data['mc_currency'] );
566
+    $currency_code = strtolower($ipn_data['mc_currency']);
567 567
 
568 568
     // verify details
569
-    if ( $currency_code != strtolower( wpinv_get_currency() ) ) {
569
+    if ($currency_code != strtolower(wpinv_get_currency())) {
570 570
         // the currency code is invalid
571
-        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) );
571
+        wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data)));
572 572
         return;
573 573
     }
574 574
 
@@ -578,11 +578,11 @@  discard block
 block discarded – undo
578 578
         'gateway'        => 'paypal'
579 579
     );
580 580
     
581
-    $invoice_id = $subscription->add_payment( $args );
581
+    $invoice_id = $subscription->add_payment($args);
582 582
 
583
-    if ( $invoice_id > 0 ) {
584
-        wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true );
585
-        wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ), '', '', true );
583
+    if ($invoice_id > 0) {
584
+        wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true);
585
+        wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']), '', '', true);
586 586
 
587 587
         $subscription->renew();
588 588
     }
@@ -591,10 +591,10 @@  discard block
 block discarded – undo
591 591
 /**
592 592
  * Process the subscription canceled IPN.
593 593
  */
594
-function wpinv_process_paypal_subscr_cancel( $ipn_data ) {
595
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
594
+function wpinv_process_paypal_subscr_cancel($ipn_data) {
595
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
596 596
 
597
-    if( false === $subscription ) {
597
+    if (false === $subscription) {
598 598
         return;
599 599
     }
600 600
 
@@ -604,10 +604,10 @@  discard block
 block discarded – undo
604 604
 /**
605 605
  * Process the subscription expired IPN.
606 606
  */
607
-function wpinv_process_paypal_subscr_eot( $ipn_data ) {
608
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
607
+function wpinv_process_paypal_subscr_eot($ipn_data) {
608
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
609 609
 
610
-    if( false === $subscription ) {
610
+    if (false === $subscription) {
611 611
         return;
612 612
     }
613 613
 
@@ -617,40 +617,40 @@  discard block
 block discarded – undo
617 617
 /**
618 618
  * Process the subscription payment failed IPN.
619 619
  */
620
-function wpinv_process_paypal_subscr_failed( $ipn_data ) {
621
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
620
+function wpinv_process_paypal_subscr_failed($ipn_data) {
621
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
622 622
 
623
-    if( false === $subscription ) {
623
+    if (false === $subscription) {
624 624
         return;
625 625
     }
626 626
 
627 627
     $subscription->failing();
628 628
 
629
-    do_action( 'wpinv_recurring_payment_failed', $subscription );
629
+    do_action('wpinv_recurring_payment_failed', $subscription);
630 630
 }
631 631
 
632 632
 /**
633 633
  * Retrieve the subscription this IPN notice is for.
634 634
  */
635
-function wpinv_get_paypal_subscription( $ipn_data = array() ) {
636
-    $parent_invoice_id = absint( $ipn_data['custom'] );
635
+function wpinv_get_paypal_subscription($ipn_data = array()) {
636
+    $parent_invoice_id = absint($ipn_data['custom']);
637 637
 
638
-    if( empty( $parent_invoice_id ) ) {
638
+    if (empty($parent_invoice_id)) {
639 639
         return false;
640 640
     }
641 641
 
642
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
643
-    if ( empty( $invoice ) ) {
642
+    $invoice = wpinv_get_invoice($parent_invoice_id);
643
+    if (empty($invoice)) {
644 644
         return false;
645 645
     }
646 646
 
647
-    $subscription = new WPInv_Subscription( $ipn_data['subscr_id'], true );
647
+    $subscription = new WPInv_Subscription($ipn_data['subscr_id'], true);
648 648
 
649
-    if ( ! ( ! empty( $subscription ) && $subscription->id > 0 ) ) {
650
-        $subscription = wpinv_get_subscription( $parent_invoice_id );
649
+    if (!(!empty($subscription) && $subscription->id > 0)) {
650
+        $subscription = wpinv_get_subscription($parent_invoice_id);
651 651
 
652
-        if ( ! empty( $subscription ) && $subscription->id > 0 ) {
653
-            $subscription->update( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) );
652
+        if (!empty($subscription) && $subscription->id > 0) {
653
+            $subscription->update(array('profile_id' => sanitize_text_field($ipn_data['subscr_id'])));
654 654
         } else {
655 655
             return false;
656 656
         }
@@ -660,46 +660,46 @@  discard block
 block discarded – undo
660 660
 
661 661
 }
662 662
 
663
-function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) {
663
+function wpinv_process_paypal_refund($data, $invoice_id = 0) {
664 664
 	// Collect payment details
665 665
 
666
-	if( empty( $invoice_id ) ) {
666
+	if (empty($invoice_id)) {
667 667
 		return;
668 668
 	}
669 669
 
670
-	if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
670
+	if (get_post_status($invoice_id) == 'wpi-refunded') {
671 671
 		return; // Only refund payments once
672 672
 	}
673 673
 
674
-	$payment_amount = wpinv_payment_total( $invoice_id );
674
+	$payment_amount = wpinv_payment_total($invoice_id);
675 675
 	$refund_amount  = $data['mc_gross'] * -1;
676 676
 
677
-	do_action( 'wpinv_paypal_refund_request', $data, $invoice_id );
677
+	do_action('wpinv_paypal_refund_request', $data, $invoice_id);
678 678
 
679
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
680
-		wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
679
+	if (number_format((float)$refund_amount, 2) < number_format((float)$payment_amount, 2)) {
680
+		wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing'), (float)$refund_amount . ' ' . $data['mc_currency'], $data['parent_txn_id'], $data['reason_code']), '', '', true);
681 681
 
682
-		do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount );
682
+		do_action('wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount);
683 683
 
684 684
 		return; // This is a partial refund
685 685
 	}
686 686
 
687
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
688
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true );
689
-	wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
687
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code']), '', '', true);
688
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id']), '', '', true);
689
+	wpinv_update_payment_status($invoice_id, 'wpi-refunded');
690 690
 
691
-	do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id );
691
+	do_action('wpinv_paypal_invoice_fully_refunded', $data, $invoice_id);
692 692
 }
693 693
 
694
-function wpinv_get_paypal_redirect( $ssl_check = false ) {
695
-    if ( is_ssl() || ! $ssl_check ) {
694
+function wpinv_get_paypal_redirect($ssl_check = false) {
695
+    if (is_ssl() || !$ssl_check) {
696 696
         $protocol = 'https://';
697 697
     } else {
698 698
         $protocol = 'http://';
699 699
     }
700 700
 
701 701
     // Check the current payment mode
702
-    if ( wpinv_is_test_mode( 'paypal' ) ) {
702
+    if (wpinv_is_test_mode('paypal')) {
703 703
         // Test mode
704 704
         $paypal_uri = $protocol . 'www.sandbox.paypal.com/cgi-bin/webscr';
705 705
     } else {
@@ -707,79 +707,79 @@  discard block
 block discarded – undo
707 707
         $paypal_uri = $protocol . 'www.paypal.com/cgi-bin/webscr';
708 708
     }
709 709
 
710
-    return apply_filters( 'wpinv_paypal_uri', $paypal_uri );
710
+    return apply_filters('wpinv_paypal_uri', $paypal_uri);
711 711
 }
712 712
 
713
-function wpinv_paypal_success_page_content( $content ) {
713
+function wpinv_paypal_success_page_content($content) {
714 714
     global $wpi_invoice;
715 715
     
716 716
     $session = wpinv_get_checkout_session();
717 717
 
718
-    if ( empty( $_GET['invoice-id'] ) && empty( $session['invoice_key'] )  ) {
718
+    if (empty($_GET['invoice-id']) && empty($session['invoice_key'])) {
719 719
         return $content;
720 720
     }
721 721
 
722
-    $invoice_id = !empty( $_GET['invoice-id'] ) ? absint( $_GET['invoice-id'] ) : wpinv_get_invoice_id_by_key( $session['invoice_key'] );
722
+    $invoice_id = !empty($_GET['invoice-id']) ? absint($_GET['invoice-id']) : wpinv_get_invoice_id_by_key($session['invoice_key']);
723 723
 
724
-    if ( empty(  $invoice_id ) ) {
724
+    if (empty($invoice_id)) {
725 725
         return $content;
726 726
     }
727 727
 
728
-    $wpi_invoice = wpinv_get_invoice( $invoice_id );
728
+    $wpi_invoice = wpinv_get_invoice($invoice_id);
729 729
     
730
-    if ( !empty( $wpi_invoice ) && 'wpi-pending' == $wpi_invoice->status ) {
730
+    if (!empty($wpi_invoice) && 'wpi-pending' == $wpi_invoice->status) {
731 731
         // Payment is still pending so show processing indicator to fix the Race Condition, issue #
732 732
         ob_start();
733
-        wpinv_get_template_part( 'wpinv-payment-processing' );
733
+        wpinv_get_template_part('wpinv-payment-processing');
734 734
         $content = ob_get_clean();
735 735
     }
736 736
 
737 737
     return $content;
738 738
 }
739
-add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' );
739
+add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content');
740 740
 
741
-function wpinv_paypal_get_transaction_id( $invoice_id ) {
741
+function wpinv_paypal_get_transaction_id($invoice_id) {
742 742
     $transaction_id = '';
743
-    $notes = wpinv_get_invoice_notes( $invoice_id );
743
+    $notes = wpinv_get_invoice_notes($invoice_id);
744 744
 
745
-    foreach ( $notes as $note ) {
746
-        if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) {
745
+    foreach ($notes as $note) {
746
+        if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) {
747 747
             $transaction_id = $match[1];
748 748
             continue;
749 749
         }
750 750
     }
751 751
 
752
-    return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id );
752
+    return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id);
753 753
 }
754
-add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 );
754
+add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1);
755 755
 
756
-function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) {
757
-    if ( $invoice->is_free_trial() || $transaction_id == $invoice_id ) { // Free trial does not have transaction at PayPal.
756
+function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) {
757
+    if ($invoice->is_free_trial() || $transaction_id == $invoice_id) { // Free trial does not have transaction at PayPal.
758 758
         $transaction_url = $invoice->get_view_url();
759 759
     } else {
760
-        $sandbox = wpinv_is_test_mode( 'paypal' ) ? '.sandbox' : '';
760
+        $sandbox = wpinv_is_test_mode('paypal') ? '.sandbox' : '';
761 761
         $transaction_url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=' . $transaction_id;
762 762
     }
763 763
 
764
-    $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>';
764
+    $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>';
765 765
 
766
-    return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice );
766
+    return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice);
767 767
 }
768
-add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 );
768
+add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3);
769 769
 
770 770
 function wpinv_is_paypal_valid_for_use() {
771
-    return in_array( wpinv_get_currency(), apply_filters( 'wpinv_paypal_supported_currencies', array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ) ) );
771
+    return in_array(wpinv_get_currency(), apply_filters('wpinv_paypal_supported_currencies', array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR')));
772 772
 }
773 773
 
774
-function wpinv_check_paypal_currency_support( $gateway_list ) {
775
-    if ( isset( $gateway_list['paypal'] ) && ! wpinv_is_paypal_valid_for_use() ) {
776
-        unset( $gateway_list['paypal'] );
774
+function wpinv_check_paypal_currency_support($gateway_list) {
775
+    if (isset($gateway_list['paypal']) && !wpinv_is_paypal_valid_for_use()) {
776
+        unset($gateway_list['paypal']);
777 777
     }
778 778
     return $gateway_list;
779 779
 }
780
-add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1 );
780
+add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1);
781 781
 
782
-function wpinv_gateway_paypal_button_label( $label ) {
783
-    return __( 'Proceed to PayPal', 'invoicing' );
782
+function wpinv_gateway_paypal_button_label($label) {
783
+    return __('Proceed to PayPal', 'invoicing');
784 784
 }
785
-add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 );
786 785
\ No newline at end of file
786
+add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1);
787 787
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/bank_transfer.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  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_bank_transfer_cc_form', '__return_false' );
5
+add_action('wpinv_bank_transfer_cc_form', '__return_false');
6 6
 
7
-function wpinv_process_bank_transfer_payment( $purchase_data ) {
8
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
9
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
7
+function wpinv_process_bank_transfer_payment($purchase_data) {
8
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
9
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
10 10
     }
11 11
 
12 12
     // Collect payment data
@@ -24,39 +24,39 @@  discard block
 block discarded – undo
24 24
     );
25 25
 
26 26
     // Record the pending payment
27
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
27
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
28 28
     
29
-    if ( !empty( $invoice ) ) {
30
-        wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() );
31
-        wpinv_update_payment_status( $invoice, 'wpi-pending' );
29
+    if (!empty($invoice)) {
30
+        wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key());
31
+        wpinv_update_payment_status($invoice, 'wpi-pending');
32 32
         
33 33
         // Empty the shopping cart
34 34
         wpinv_empty_cart();
35 35
         
36
-        do_action( 'wpinv_send_to_success_page', $invoice->ID, $payment_data );
36
+        do_action('wpinv_send_to_success_page', $invoice->ID, $payment_data);
37 37
         
38
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
38
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
39 39
     } else {
40
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a bank transfer payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
40
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a bank transfer payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
41 41
         // If errors are present, send the user back to the purchase page so they can be corrected
42
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
42
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
43 43
     }
44 44
 }
45
-add_action( 'wpinv_gateway_bank_transfer', 'wpinv_process_bank_transfer_payment' );
45
+add_action('wpinv_gateway_bank_transfer', 'wpinv_process_bank_transfer_payment');
46 46
 
47
-function wpinv_show_bank_info( $invoice ) {
48
-    if ( !empty( $invoice ) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending' ) {
49
-        $bank_info = wpinv_get_bank_info( true );
47
+function wpinv_show_bank_info($invoice) {
48
+    if (!empty($invoice) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending') {
49
+        $bank_info = wpinv_get_bank_info(true);
50 50
         ?>
51 51
         <div class="wpinv-bank-details">
52
-            <?php if ( $instructions = wpinv_get_bank_instructions() ) { ?>
53
-            <div class="alert bg-info"><?php echo wpautop( wp_kses_post( $instructions ) ); ?></div>
52
+            <?php if ($instructions = wpinv_get_bank_instructions()) { ?>
53
+            <div class="alert bg-info"><?php echo wpautop(wp_kses_post($instructions)); ?></div>
54 54
             <?php } ?>
55
-            <?php if ( !empty( $bank_info ) ) { ?>
56
-            <h3 class="wpinv-bank-t"><?php echo apply_filters( 'wpinv_receipt_bank_details_title', __( 'Our Bank Details', 'invoicing' ) ); ?></h3>
55
+            <?php if (!empty($bank_info)) { ?>
56
+            <h3 class="wpinv-bank-t"><?php echo apply_filters('wpinv_receipt_bank_details_title', __('Our Bank Details', 'invoicing')); ?></h3>
57 57
             <table class="table table-bordered table-sm wpi-bank-details">
58
-                <?php foreach ( $bank_info as $key => $info ) { ?>
59
-                <tr class="wpi-<?php echo sanitize_html_class( $key );?>"><th class="text-left"><?php echo $info['label'] ;?></th><td><?php echo $info['value'] ;?></td></tr>
58
+                <?php foreach ($bank_info as $key => $info) { ?>
59
+                <tr class="wpi-<?php echo sanitize_html_class($key); ?>"><th class="text-left"><?php echo $info['label']; ?></th><td><?php echo $info['value']; ?></td></tr>
60 60
                 <?php } ?>
61 61
             </table>
62 62
             <?php } ?>
@@ -64,26 +64,26 @@  discard block
 block discarded – undo
64 64
         <?php
65 65
     }
66 66
 }
67
-add_action( 'wpinv_before_receipt_details', 'wpinv_show_bank_info', 10, 1 );
67
+add_action('wpinv_before_receipt_details', 'wpinv_show_bank_info', 10, 1);
68 68
 
69
-function wpinv_invoice_print_bank_info( $invoice ) {
70
-    if ( !empty( $invoice ) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending' ) {
69
+function wpinv_invoice_print_bank_info($invoice) {
70
+    if (!empty($invoice) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending') {
71 71
         ?>
72 72
         <div class="row wpinv-bank-info">
73
-            <?php echo wpinv_show_bank_info( $invoice ); ?>
73
+            <?php echo wpinv_show_bank_info($invoice); ?>
74 74
         </div>
75 75
         <?php
76 76
     }
77 77
 }
78
-add_action( 'wpinv_invoice_print_after_top_content', 'wpinv_invoice_print_bank_info', 10, 1 );
78
+add_action('wpinv_invoice_print_after_top_content', 'wpinv_invoice_print_bank_info', 10, 1);
79 79
 
80
-function wpinv_bank_transfer_send_notification( $invoice_ID, $payment_data = array() ) {
81
-    if ( !empty( $payment_data['gateway'] ) && $payment_data['gateway'] == 'bank_transfer' ) {
80
+function wpinv_bank_transfer_send_notification($invoice_ID, $payment_data = array()) {
81
+    if (!empty($payment_data['gateway']) && $payment_data['gateway'] == 'bank_transfer') {
82 82
         // Send invoice to user.
83
-        wpinv_user_invoice_notification( $invoice_ID );
83
+        wpinv_user_invoice_notification($invoice_ID);
84 84
         
85 85
         // Send invoice to admin.
86
-        wpinv_new_invoice_notification( $invoice_ID );
86
+        wpinv_new_invoice_notification($invoice_ID);
87 87
     }
88 88
 }
89
-add_action( 'wpinv_send_to_success_page', 'wpinv_bank_transfer_send_notification', 10, 2 );
90 89
\ No newline at end of file
90
+add_action('wpinv_send_to_success_page', 'wpinv_bank_transfer_send_notification', 10, 2);
91 91
\ No newline at end of file
Please login to merge, or discard this patch.