Passed
Push — master ( b4ab02...d1178c )
by Brian
11:00 queued 04:56
created
includes/admin/class-getpaid-post-types-admin.php 1 patch
Indentation   +604 added lines, -604 removed lines patch added patch discarded remove patch
@@ -13,602 +13,602 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Post_Types_Admin {
14 14
 
15 15
     /**
16
-	 * Hook in methods.
17
-	 */
18
-	public static function init() {
19
-
20
-		// Init metaboxes.
21
-		GetPaid_Metaboxes::init();
22
-
23
-		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
-
26
-		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
-
29
-		// Invoice table columns.
30
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
31
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
32
-
33
-		// Items table columns.
34
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
35
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
36
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
37
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
38
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
39
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
40
-
41
-		// Payment forms columns.
42
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
43
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
44
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
45
-
46
-		// Discount table columns.
47
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
48
-
49
-		// Deleting posts.
50
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
51
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
52
-	}
53
-
54
-	/**
55
-	 * Post updated messages.
56
-	 */
57
-	public static function post_updated_messages( $messages ) {
58
-		global $post;
59
-
60
-		$messages['wpi_discount'] = array(
61
-			0   => '',
62
-			1   => __( 'Discount updated.', 'invoicing' ),
63
-			2   => __( 'Custom field updated.', 'invoicing' ),
64
-			3   => __( 'Custom field deleted.', 'invoicing' ),
65
-			4   => __( 'Discount updated.', 'invoicing' ),
66
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
67
-			6   => __( 'Discount updated.', 'invoicing' ),
68
-			7   => __( 'Discount saved.', 'invoicing' ),
69
-			8   => __( 'Discount submitted.', 'invoicing' ),
70
-			9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
71
-			10  => __( 'Discount draft updated.', 'invoicing' ),
72
-		);
73
-
74
-		$messages['wpi_payment_form'] = array(
75
-			0   => '',
76
-			1   => __( 'Payment Form updated.', 'invoicing' ),
77
-			2   => __( 'Custom field updated.', 'invoicing' ),
78
-			3   => __( 'Custom field deleted.', 'invoicing' ),
79
-			4   => __( 'Payment Form updated.', 'invoicing' ),
80
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
81
-			6   => __( 'Payment Form updated.', 'invoicing' ),
82
-			7   => __( 'Payment Form saved.', 'invoicing' ),
83
-			8   => __( 'Payment Form submitted.', 'invoicing' ),
84
-			9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
85
-			10  => __( 'Payment Form draft updated.', 'invoicing' ),
86
-		);
87
-
88
-		return $messages;
89
-
90
-	}
91
-
92
-	/**
93
-	 * Post row actions.
94
-	 */
95
-	public static function post_row_actions( $actions, $post ) {
96
-
97
-		$post = get_post( $post );
98
-
99
-		// We do not want to edit the default payment form.
100
-		if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
101
-			unset( $actions['trash'] );
102
-			unset( $actions['inline hide-if-no-js'] );
103
-		}
104
-
105
-		return $actions;
106
-	}
107
-
108
-	/**
109
-	 * Returns an array of invoice table columns.
110
-	 */
111
-	public static function invoice_columns( $columns ) {
112
-
113
-		$columns = array(
114
-			'cb'                => $columns['cb'],
115
-			'number'            => __( 'Invoice', 'invoicing' ),
116
-			'customer'          => __( 'Customer', 'invoicing' ),
117
-			'invoice_date'      => __( 'Date', 'invoicing' ),
118
-			'amount'            => __( 'Amount', 'invoicing' ),
119
-			'recurring'         => __( 'Recurring', 'invoicing' ),
120
-			'status'            => __( 'Status', 'invoicing' ),
121
-			'wpi_actions'       => __( 'Actions', 'invoicing' ),
122
-		);
123
-
124
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
125
-	}
126
-
127
-	/**
128
-	 * Displays invoice table columns.
129
-	 */
130
-	public static function display_invoice_columns( $column_name, $post_id ) {
131
-
132
-		$invoice = new WPInv_Invoice( $post_id );
133
-
134
-		switch ( $column_name ) {
135
-
136
-			case 'invoice_date' :
137
-				$date_time = sanitize_text_field( $invoice->get_created_date() );
138
-				$date      = mysql2date( get_option( 'date_format' ), $date_time );
139
-				echo "<span title='$date_time'>$date</span>";
140
-				break;
141
-
142
-			case 'amount' :
143
-
144
-				$amount = $invoice->get_total();
145
-				$formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() );
146
-
147
-				if ( $invoice->is_refunded() ) {
148
-					$refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() );
149
-					echo "<del>$formated_amount</del><ins>$refunded_amount</ins>";
150
-				} else {
151
-
152
-					$discount = $invoice->get_total_discount();
153
-
154
-					if ( ! empty( $discount ) ) {
155
-						$new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() );
156
-						echo "<del>$new_amount</del><ins>$formated_amount</ins>";
157
-					} else {
158
-						echo $formated_amount;
159
-					}
160
-
161
-				}
162
-
163
-				break;
164
-
165
-			case 'status' :
166
-				$status       = sanitize_text_field( $invoice->get_status() );
167
-				$status_label = sanitize_text_field( $invoice->get_status_nicename() );
168
-
169
-				// If it is paid, show the gateway title.
170
-				if ( $invoice->is_paid() ) {
171
-					$gateway = sanitize_text_field( $invoice->get_gateway_title() );
172
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
16
+     * Hook in methods.
17
+     */
18
+    public static function init() {
173 19
 
174
-					echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
175
-				} else {
176
-					echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
177
-				}
20
+        // Init metaboxes.
21
+        GetPaid_Metaboxes::init();
178 22
 
179
-				// If it is not paid, display the overdue and view status.
180
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
23
+        // Filter the post updated messages.
24
+        add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
181 25
 
182
-					// Invoice view status.
183
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
184
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
185
-					} else {
186
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
187
-					}
26
+        // Filter post actions.
27
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
188 28
 
189
-					// Display the overview status.
190
-					if ( wpinv_get_option( 'overdue_active' ) ) {
191
-						$due_date = $invoice->get_due_date();
29
+        // Invoice table columns.
30
+        add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
31
+        add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
192 32
 
193
-						if ( ! empty( $due_date ) ) {
194
-							$date = mysql2date( get_option( 'date_format' ), $due_date );
195
-							$date = wp_sprintf( __( 'Due %s', 'invoicing' ), $date );
196
-							echo "<p class='description' style='color: #888;' title='$due_date'>$date</p>";
197
-						}
198
-					}
33
+        // Items table columns.
34
+        add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
35
+        add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
36
+        add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
37
+        add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
38
+        add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
39
+        add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
199 40
 
200
-				}
41
+        // Payment forms columns.
42
+        add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
43
+        add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
44
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
201 45
 
202
-				break;
46
+        // Discount table columns.
47
+        add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
203 48
 
204
-			case 'recurring':
49
+        // Deleting posts.
50
+        add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
51
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
52
+    }
205 53
 
206
-				if ( $invoice->is_recurring() ) {
207
-					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
208
-				} else {
209
-					echo '<i class="fa fa-times" style="color:#616161;"></i>';
210
-				}
211
-				break;
54
+    /**
55
+     * Post updated messages.
56
+     */
57
+    public static function post_updated_messages( $messages ) {
58
+        global $post;
59
+
60
+        $messages['wpi_discount'] = array(
61
+            0   => '',
62
+            1   => __( 'Discount updated.', 'invoicing' ),
63
+            2   => __( 'Custom field updated.', 'invoicing' ),
64
+            3   => __( 'Custom field deleted.', 'invoicing' ),
65
+            4   => __( 'Discount updated.', 'invoicing' ),
66
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
67
+            6   => __( 'Discount updated.', 'invoicing' ),
68
+            7   => __( 'Discount saved.', 'invoicing' ),
69
+            8   => __( 'Discount submitted.', 'invoicing' ),
70
+            9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
71
+            10  => __( 'Discount draft updated.', 'invoicing' ),
72
+        );
73
+
74
+        $messages['wpi_payment_form'] = array(
75
+            0   => '',
76
+            1   => __( 'Payment Form updated.', 'invoicing' ),
77
+            2   => __( 'Custom field updated.', 'invoicing' ),
78
+            3   => __( 'Custom field deleted.', 'invoicing' ),
79
+            4   => __( 'Payment Form updated.', 'invoicing' ),
80
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
81
+            6   => __( 'Payment Form updated.', 'invoicing' ),
82
+            7   => __( 'Payment Form saved.', 'invoicing' ),
83
+            8   => __( 'Payment Form submitted.', 'invoicing' ),
84
+            9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
85
+            10  => __( 'Payment Form draft updated.', 'invoicing' ),
86
+        );
87
+
88
+        return $messages;
89
+
90
+    }
91
+
92
+    /**
93
+     * Post row actions.
94
+     */
95
+    public static function post_row_actions( $actions, $post ) {
96
+
97
+        $post = get_post( $post );
98
+
99
+        // We do not want to edit the default payment form.
100
+        if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
101
+            unset( $actions['trash'] );
102
+            unset( $actions['inline hide-if-no-js'] );
103
+        }
104
+
105
+        return $actions;
106
+    }
107
+
108
+    /**
109
+     * Returns an array of invoice table columns.
110
+     */
111
+    public static function invoice_columns( $columns ) {
112
+
113
+        $columns = array(
114
+            'cb'                => $columns['cb'],
115
+            'number'            => __( 'Invoice', 'invoicing' ),
116
+            'customer'          => __( 'Customer', 'invoicing' ),
117
+            'invoice_date'      => __( 'Date', 'invoicing' ),
118
+            'amount'            => __( 'Amount', 'invoicing' ),
119
+            'recurring'         => __( 'Recurring', 'invoicing' ),
120
+            'status'            => __( 'Status', 'invoicing' ),
121
+            'wpi_actions'       => __( 'Actions', 'invoicing' ),
122
+        );
123
+
124
+        return apply_filters( 'wpi_invoice_table_columns', $columns );
125
+    }
126
+
127
+    /**
128
+     * Displays invoice table columns.
129
+     */
130
+    public static function display_invoice_columns( $column_name, $post_id ) {
131
+
132
+        $invoice = new WPInv_Invoice( $post_id );
133
+
134
+        switch ( $column_name ) {
135
+
136
+            case 'invoice_date' :
137
+                $date_time = sanitize_text_field( $invoice->get_created_date() );
138
+                $date      = mysql2date( get_option( 'date_format' ), $date_time );
139
+                echo "<span title='$date_time'>$date</span>";
140
+                break;
141
+
142
+            case 'amount' :
143
+
144
+                $amount = $invoice->get_total();
145
+                $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() );
146
+
147
+                if ( $invoice->is_refunded() ) {
148
+                    $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() );
149
+                    echo "<del>$formated_amount</del><ins>$refunded_amount</ins>";
150
+                } else {
151
+
152
+                    $discount = $invoice->get_total_discount();
153
+
154
+                    if ( ! empty( $discount ) ) {
155
+                        $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() );
156
+                        echo "<del>$new_amount</del><ins>$formated_amount</ins>";
157
+                    } else {
158
+                        echo $formated_amount;
159
+                    }
160
+
161
+                }
162
+
163
+                break;
164
+
165
+            case 'status' :
166
+                $status       = sanitize_text_field( $invoice->get_status() );
167
+                $status_label = sanitize_text_field( $invoice->get_status_nicename() );
168
+
169
+                // If it is paid, show the gateway title.
170
+                if ( $invoice->is_paid() ) {
171
+                    $gateway = sanitize_text_field( $invoice->get_gateway_title() );
172
+                    $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
212 173
 
213
-			case 'number' :
174
+                    echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
175
+                } else {
176
+                    echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
177
+                }
214 178
 
215
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
216
-				$invoice_number  = sanitize_text_field( $invoice->get_number() );
217
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
179
+                // If it is not paid, display the overdue and view status.
180
+                if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
218 181
 
219
-				echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
182
+                    // Invoice view status.
183
+                    if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
184
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
185
+                    } else {
186
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
187
+                    }
220 188
 
221
-				break;
189
+                    // Display the overview status.
190
+                    if ( wpinv_get_option( 'overdue_active' ) ) {
191
+                        $due_date = $invoice->get_due_date();
222 192
 
223
-			case 'customer' :
193
+                        if ( ! empty( $due_date ) ) {
194
+                            $date = mysql2date( get_option( 'date_format' ), $due_date );
195
+                            $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $date );
196
+                            echo "<p class='description' style='color: #888;' title='$due_date'>$date</p>";
197
+                        }
198
+                    }
199
+
200
+                }
201
+
202
+                break;
203
+
204
+            case 'recurring':
205
+
206
+                if ( $invoice->is_recurring() ) {
207
+                    echo '<i class="fa fa-check" style="color:#43850a;"></i>';
208
+                } else {
209
+                    echo '<i class="fa fa-times" style="color:#616161;"></i>';
210
+                }
211
+                break;
212
+
213
+            case 'number' :
214
+
215
+                $edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
216
+                $invoice_number  = sanitize_text_field( $invoice->get_number() );
217
+                $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
218
+
219
+                echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
220
+
221
+                break;
222
+
223
+            case 'customer' :
224 224
 	
225
-				$customer_name = $invoice->get_user_full_name();
225
+                $customer_name = $invoice->get_user_full_name();
226 226
 	
227
-				if ( empty( $customer_name ) ) {
228
-					$customer_name = $invoice->get_email();
229
-				}
227
+                if ( empty( $customer_name ) ) {
228
+                    $customer_name = $invoice->get_email();
229
+                }
230 230
 	
231
-				if ( ! empty( $customer_name ) ) {
232
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
233
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
234
-					echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
235
-				} else {
236
-					echo '<div>&mdash;</div>';
237
-				}
238
-
239
-				break;
240
-
241
-			case 'wpi_actions' :
242
-
243
-				if ( ! $invoice->is_draft() ) {
244
-					$url    = esc_url( $invoice->get_view_url() );
245
-					$print  = esc_attr__( 'Print invoice', 'invoicing' );
246
-					echo "&nbsp;<a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>";
247
-				}
248
-
249
-				if ( $invoice->get_email() ) {
250
-					$url    = esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $invoice->get_id() ) ) );
251
-					$send   = esc_attr__( 'Send invoice to customer', 'invoicing' );
252
-					echo "&nbsp;&nbsp;<a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>";
253
-				}
231
+                if ( ! empty( $customer_name ) ) {
232
+                    $customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
233
+                    $view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
234
+                    echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
235
+                } else {
236
+                    echo '<div>&mdash;</div>';
237
+                }
238
+
239
+                break;
240
+
241
+            case 'wpi_actions' :
242
+
243
+                if ( ! $invoice->is_draft() ) {
244
+                    $url    = esc_url( $invoice->get_view_url() );
245
+                    $print  = esc_attr__( 'Print invoice', 'invoicing' );
246
+                    echo "&nbsp;<a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>";
247
+                }
248
+
249
+                if ( $invoice->get_email() ) {
250
+                    $url    = esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $invoice->get_id() ) ) );
251
+                    $send   = esc_attr__( 'Send invoice to customer', 'invoicing' );
252
+                    echo "&nbsp;&nbsp;<a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>";
253
+                }
254 254
 				
255
-				break;
256
-		}
255
+                break;
256
+        }
257 257
 
258
-	}
258
+    }
259 259
 
260
-	/**
261
-	 * Returns an array of payment forms table columns.
262
-	 */
263
-	public static function payment_form_columns( $columns ) {
260
+    /**
261
+     * Returns an array of payment forms table columns.
262
+     */
263
+    public static function payment_form_columns( $columns ) {
264 264
 
265
-		$columns = array(
266
-			'cb'                => $columns['cb'],
267
-			'title'             => __( 'Name', 'invoicing' ),
268
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
269
-			'earnings'          => __( 'Revenue', 'invoicing' ),
270
-			'refunds'           => __( 'Refunded', 'invoicing' ),
271
-			'items'             => __( 'Items', 'invoicing' ),
272
-			'date'              => __( 'Date', 'invoicing' ),
273
-		);
265
+        $columns = array(
266
+            'cb'                => $columns['cb'],
267
+            'title'             => __( 'Name', 'invoicing' ),
268
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
269
+            'earnings'          => __( 'Revenue', 'invoicing' ),
270
+            'refunds'           => __( 'Refunded', 'invoicing' ),
271
+            'items'             => __( 'Items', 'invoicing' ),
272
+            'date'              => __( 'Date', 'invoicing' ),
273
+        );
274 274
 
275
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
275
+        return apply_filters( 'wpi_payment_form_table_columns', $columns );
276 276
 
277
-	}
277
+    }
278 278
 
279
-	/**
280
-	 * Displays payment form table columns.
281
-	 */
282
-	public static function display_payment_form_columns( $column_name, $post_id ) {
279
+    /**
280
+     * Displays payment form table columns.
281
+     */
282
+    public static function display_payment_form_columns( $column_name, $post_id ) {
283 283
 
284
-		// Retrieve the payment form.
285
-		$form = new GetPaid_Payment_Form( $post_id );
284
+        // Retrieve the payment form.
285
+        $form = new GetPaid_Payment_Form( $post_id );
286 286
 
287
-		switch ( $column_name ) {
287
+        switch ( $column_name ) {
288 288
 
289
-			case 'earnings' :
290
-				echo wpinv_price( wpinv_format_amount( $form->get_earned() ) );
291
-				break;
289
+            case 'earnings' :
290
+                echo wpinv_price( wpinv_format_amount( $form->get_earned() ) );
291
+                break;
292 292
 
293
-			case 'refunds' :
294
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
295
-				break;
293
+            case 'refunds' :
294
+                echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
295
+                break;
296 296
 
297
-			case 'refunds' :
298
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
299
-				break;
297
+            case 'refunds' :
298
+                echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
299
+                break;
300 300
 
301
-			case 'shortcode' :
301
+            case 'shortcode' :
302 302
 
303
-				if ( $form->is_default() ) {
304
-					echo '&mdash;';
305
-				} else {
306
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
307
-				}
303
+                if ( $form->is_default() ) {
304
+                    echo '&mdash;';
305
+                } else {
306
+                    echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
307
+                }
308 308
 
309
-				break;
309
+                break;
310 310
 
311
-			case 'items' :
311
+            case 'items' :
312 312
 
313
-				$items = $form->get_items();
313
+                $items = $form->get_items();
314 314
 
315
-				if ( $form->is_default() || empty( $items ) ) {
316
-					echo '&mdash;';
317
-					return;
318
-				}
315
+                if ( $form->is_default() || empty( $items ) ) {
316
+                    echo '&mdash;';
317
+                    return;
318
+                }
319 319
 
320
-				$_items = array();
320
+                $_items = array();
321 321
 
322
-				foreach ( $items as $item ) {
323
-					$url = $item->get_edit_url();
322
+                foreach ( $items as $item ) {
323
+                    $url = $item->get_edit_url();
324 324
 
325
-					if ( empty( $url ) ) {
326
-						$_items[] = sanitize_text_field( $item->get_name() );
327
-					} else {
328
-						$_items[] = sprintf(
329
-							'<a href="%s">%s</a>',
330
-							esc_url( $url ),
331
-							sanitize_text_field( $item->get_name() )
332
-						);
333
-					}
325
+                    if ( empty( $url ) ) {
326
+                        $_items[] = sanitize_text_field( $item->get_name() );
327
+                    } else {
328
+                        $_items[] = sprintf(
329
+                            '<a href="%s">%s</a>',
330
+                            esc_url( $url ),
331
+                            sanitize_text_field( $item->get_name() )
332
+                        );
333
+                    }
334 334
 
335
-				}
335
+                }
336 336
 
337
-				echo implode( '<br>', $_items );
337
+                echo implode( '<br>', $_items );
338 338
 
339
-				break;
339
+                break;
340 340
 
341
-		}
341
+        }
342 342
 
343
-	}
343
+    }
344 344
 
345
-	/**
346
-	 * Filters post states.
347
-	 */
348
-	public static function filter_payment_form_state( $post_states, $post ) {
345
+    /**
346
+     * Filters post states.
347
+     */
348
+    public static function filter_payment_form_state( $post_states, $post ) {
349 349
 
350
-		if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
351
-			$post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
352
-		}
350
+        if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
351
+            $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
352
+        }
353 353
 	
354
-		return $post_states;
354
+        return $post_states;
355 355
 
356
-	}
356
+    }
357 357
 
358
-	/**
359
-	 * Returns an array of coupon table columns.
360
-	 */
361
-	public static function discount_columns( $columns ) {
362
-
363
-		$columns = array(
364
-			'cb'                => $columns['cb'],
365
-			'title'             => __( 'Name', 'invoicing' ),
366
-			'code'              => __( 'Code', 'invoicing' ),
367
-			'amount'            => __( 'Amount', 'invoicing' ),
368
-			'usage'             => __( 'Usage / Limit', 'invoicing' ),
369
-			'start_date'        => __( 'Start Date', 'invoicing' ),
370
-			'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
371
-		);
358
+    /**
359
+     * Returns an array of coupon table columns.
360
+     */
361
+    public static function discount_columns( $columns ) {
362
+
363
+        $columns = array(
364
+            'cb'                => $columns['cb'],
365
+            'title'             => __( 'Name', 'invoicing' ),
366
+            'code'              => __( 'Code', 'invoicing' ),
367
+            'amount'            => __( 'Amount', 'invoicing' ),
368
+            'usage'             => __( 'Usage / Limit', 'invoicing' ),
369
+            'start_date'        => __( 'Start Date', 'invoicing' ),
370
+            'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
371
+        );
372
+
373
+        return apply_filters( 'wpi_discount_table_columns', $columns );
374
+    }
372 375
 
373
-		return apply_filters( 'wpi_discount_table_columns', $columns );
374
-	}
376
+    /**
377
+     * Filters post states.
378
+     */
379
+    public static function filter_discount_state( $post_states, $post ) {
375 380
 
376
-	/**
377
-	 * Filters post states.
378
-	 */
379
-	public static function filter_discount_state( $post_states, $post ) {
381
+        if ( 'wpi_discount' == $post->post_type ) {
380 382
 
381
-		if ( 'wpi_discount' == $post->post_type ) {
383
+            $discount = new WPInv_Discount( $post );
382 384
 
383
-			$discount = new WPInv_Discount( $post );
385
+            $status = $discount->is_expired() ? 'expired' : $discount->get_status();
384 386
 
385
-			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
387
+            if ( $status != 'publish' ) {
388
+                return array(
389
+                    'discount_status' => wpinv_discount_status( $status ),
390
+                );
391
+            }
386 392
 
387
-			if ( $status != 'publish' ) {
388
-				return array(
389
-					'discount_status' => wpinv_discount_status( $status ),
390
-				);
391
-			}
393
+            return array();
392 394
 
393
-			return array();
395
+        }
394 396
 
395
-		}
397
+        return $post_states;
396 398
 
397
-		return $post_states;
399
+    }
398 400
 
399
-	}
401
+    /**
402
+     * Returns an array of items table columns.
403
+     */
404
+    public static function item_columns( $columns ) {
405
+        global $wpinv_euvat;
406
+
407
+        $columns = array(
408
+            'cb'                => $columns['cb'],
409
+            'title'             => __( 'Name', 'invoicing' ),
410
+            'price'             => __( 'Price', 'invoicing' ),
411
+            'vat_rule'          => __( 'VAT rule', 'invoicing' ),
412
+            'vat_class'         => __( 'VAT class', 'invoicing' ),
413
+            'type'              => __( 'Type', 'invoicing' ),
414
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
415
+        );
416
+
417
+        if ( ! $wpinv_euvat->allow_vat_rules() ) {
418
+            unset( $columns['vat_rule'] );
419
+        }
400 420
 
401
-	/**
402
-	 * Returns an array of items table columns.
403
-	 */
404
-	public static function item_columns( $columns ) {
405
-		global $wpinv_euvat;
421
+        if ( ! $wpinv_euvat->allow_vat_classes() ) {
422
+            unset( $columns['vat_class'] );
423
+        }
406 424
 
407
-		$columns = array(
408
-			'cb'                => $columns['cb'],
409
-			'title'             => __( 'Name', 'invoicing' ),
410
-			'price'             => __( 'Price', 'invoicing' ),
411
-			'vat_rule'          => __( 'VAT rule', 'invoicing' ),
412
-			'vat_class'         => __( 'VAT class', 'invoicing' ),
413
-			'type'              => __( 'Type', 'invoicing' ),
414
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
415
-		);
425
+        return apply_filters( 'wpi_item_table_columns', $columns );
426
+    }
416 427
 
417
-		if ( ! $wpinv_euvat->allow_vat_rules() ) {
418
-			unset( $columns['vat_rule'] );
419
-		}
428
+    /**
429
+     * Returns an array of sortable items table columns.
430
+     */
431
+    public static function sortable_item_columns( $columns ) {
432
+
433
+        return array_merge(
434
+            $columns,
435
+            array(
436
+                'price'     => 'price',
437
+                'vat_rule'  => 'vat_rule',
438
+                'vat_class' => 'vat_class',
439
+                'type'      => 'type',
440
+            )
441
+        );
442
+
443
+    }
420 444
 
421
-		if ( ! $wpinv_euvat->allow_vat_classes() ) {
422
-			unset( $columns['vat_class'] );
423
-		}
445
+    /**
446
+     * Displays items table columns.
447
+     */
448
+    public static function display_item_columns( $column_name, $post_id ) {
449
+        global $wpinv_euvat;
424 450
 
425
-		return apply_filters( 'wpi_item_table_columns', $columns );
426
-	}
451
+        $item = new WPInv_Item( $post_id );
427 452
 
428
-	/**
429
-	 * Returns an array of sortable items table columns.
430
-	 */
431
-	public static function sortable_item_columns( $columns ) {
453
+        switch ( $column_name ) {
432 454
 
433
-		return array_merge(
434
-			$columns,
435
-			array(
436
-				'price'     => 'price',
437
-				'vat_rule'  => 'vat_rule',
438
-				'vat_class' => 'vat_class',
439
-				'type'      => 'type',
440
-			)
441
-		);
455
+            case 'price' :
442 456
 
443
-	}
457
+                if ( ! $item->is_recurring() ) {
458
+                    echo $item->get_the_price();
459
+                    break;
460
+                }
444 461
 
445
-	/**
446
-	 * Displays items table columns.
447
-	 */
448
-	public static function display_item_columns( $column_name, $post_id ) {
449
-		global $wpinv_euvat;
462
+                $price = wp_sprintf(
463
+                    __( '%s / %s', 'invoicing' ),
464
+                    $item->get_the_price(),
465
+                    WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_recurring_period(), $item->get_recurring_interval() )
466
+                );
450 467
 
451
-		$item = new WPInv_Item( $post_id );
468
+                if ( $item->get_the_price() == $item->get_the_initial_price() ) {
469
+                    echo $price;
470
+                    break;
471
+                }
452 472
 
453
-		switch ( $column_name ) {
473
+                echo $item->get_the_initial_price();
454 474
 
455
-			case 'price' :
475
+                echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
476
+                break;
456 477
 
457
-				if ( ! $item->is_recurring() ) {
458
-					echo $item->get_the_price();
459
-					break;
460
-				}
478
+            case 'vat_rule' :
479
+                echo $wpinv_euvat->item_rule_label( $item->get_id() );
480
+                break;
461 481
 
462
-				$price = wp_sprintf(
463
-					__( '%s / %s', 'invoicing' ),
464
-					$item->get_the_price(),
465
-					WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_recurring_period(), $item->get_recurring_interval() )
466
-				);
482
+            case 'vat_class' :
483
+                echo $wpinv_euvat->item_class_label( $item->get_id() );
484
+                break;
467 485
 
468
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
469
-					echo $price;
470
-					break;
471
-				}
486
+            case 'shortcode' :
487
+                echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
488
+                break;
472 489
 
473
-				echo $item->get_the_initial_price();
490
+            case 'type' :
491
+                echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
492
+                break;
474 493
 
475
-				echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
476
-				break;
494
+        }
477 495
 
478
-			case 'vat_rule' :
479
-				echo $wpinv_euvat->item_rule_label( $item->get_id() );
480
-				break;
496
+    }
481 497
 
482
-			case 'vat_class' :
483
-				echo $wpinv_euvat->item_class_label( $item->get_id() );
484
-				break;
498
+    /**
499
+     * Lets users filter items using taxes.
500
+     */
501
+    public static function add_item_filters( $post_type ) {
502
+        global $wpinv_euvat;
503
+
504
+        // Abort if we're not dealing with items.
505
+        if ( $post_type != 'wpi_item' ) {
506
+            return;
507
+        }
485 508
 
486
-			case 'shortcode' :
487
-				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
488
-				break;
509
+        // Filter by vat rules.
510
+        if ( $wpinv_euvat->allow_vat_rules() ) {
511
+	
512
+            // Sanitize selected vat rule.
513
+            $vat_rule   = '';
514
+            if ( isset( $_GET['vat_rule'] ) && array_key_exists(  $_GET['vat_rule'], $wpinv_euvat->get_rules() ) ) {
515
+                $vat_rule   =  $_GET['vat_rule'];
516
+            }
517
+
518
+            // Filter by VAT rule.
519
+            echo wpinv_html_select(
520
+                array(
521
+                    'options'          => array_merge(
522
+                        array(
523
+                            '' => __( 'All VAT rules', 'invoicing' )
524
+                        ),
525
+                        $wpinv_euvat->get_rules()
526
+                    ),
527
+                    'name'             => 'vat_rule',
528
+                    'id'               => 'vat_rule',
529
+                    'selected'         => $vat_rule,
530
+                    'show_option_all'  => false,
531
+                    'show_option_none' => false,
532
+                    'class'            => 'gdmbx2-text-medium',
533
+                )
534
+            );
489 535
 
490
-			case 'type' :
491
-				echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
492
-				break;
536
+            // Filter by VAT class.
537
+        }
493 538
 
494
-		}
495
-
496
-	}
497
-
498
-	/**
499
-	 * Lets users filter items using taxes.
500
-	 */
501
-	public static function add_item_filters( $post_type ) {
502
-		global $wpinv_euvat;
503
-
504
-		// Abort if we're not dealing with items.
505
-		if ( $post_type != 'wpi_item' ) {
506
-			return;
507
-		}
508
-
509
-		// Filter by vat rules.
510
-		if ( $wpinv_euvat->allow_vat_rules() ) {
511
-	
512
-			// Sanitize selected vat rule.
513
-			$vat_rule   = '';
514
-			if ( isset( $_GET['vat_rule'] ) && array_key_exists(  $_GET['vat_rule'], $wpinv_euvat->get_rules() ) ) {
515
-				$vat_rule   =  $_GET['vat_rule'];
516
-			}
517
-
518
-			// Filter by VAT rule.
519
-			echo wpinv_html_select(
520
-				array(
521
-					'options'          => array_merge(
522
-						array(
523
-							'' => __( 'All VAT rules', 'invoicing' )
524
-						),
525
-						$wpinv_euvat->get_rules()
526
-					),
527
-					'name'             => 'vat_rule',
528
-					'id'               => 'vat_rule',
529
-					'selected'         => $vat_rule,
530
-					'show_option_all'  => false,
531
-					'show_option_none' => false,
532
-					'class'            => 'gdmbx2-text-medium',
533
-				)
534
-			);
535
-
536
-			// Filter by VAT class.
537
-		}
538
-
539
-		// Filter by vat class.
540
-		if ( $wpinv_euvat->allow_vat_classes() ) {
539
+        // Filter by vat class.
540
+        if ( $wpinv_euvat->allow_vat_classes() ) {
541 541
 	
542
-			// Sanitize selected vat rule.
543
-			$vat_class   = '';
544
-			if ( isset( $_GET['vat_class'] ) && array_key_exists(  $_GET['vat_class'], $wpinv_euvat->get_all_classes() ) ) {
545
-				$vat_class   =  $_GET['vat_class'];
546
-			}
547
-
548
-			echo wpinv_html_select(
549
-				array(
550
-					'options'          => array_merge(
551
-						array(
552
-							'' => __( 'All VAT classes', 'invoicing' )
553
-						),
554
-						$wpinv_euvat->get_all_classes()
555
-					),
556
-					'name'             => 'vat_class',
557
-					'id'               => 'vat_class',
558
-					'selected'         => $vat_class,
559
-					'show_option_all'  => false,
560
-					'show_option_none' => false,
561
-					'class'            => 'gdmbx2-text-medium',
562
-				)
563
-			);
564
-
565
-		}
566
-
567
-		// Filter by item type.
568
-		$type   = '';
569
-		if( isset( $_GET['type'] ) && array_key_exists(  $_GET['type'], wpinv_get_item_types() ) ) {
570
-			$type   =  $_GET['type'];
571
-		}
572
-
573
-		echo wpinv_html_select(
574
-			array(
575
-				'options'          => array_merge(
576
-					array(
577
-						'' => __( 'All item types', 'invoicing' )
578
-					),
579
-					wpinv_get_item_types()
580
-				),
581
-				'name'             => 'type',
582
-				'id'               => 'type',
583
-				'selected'         => $type,
584
-				'show_option_all'  => false,
585
-				'show_option_none' => false,
586
-				'class'            => 'gdmbx2-text-medium',
587
-			)
588
-		);
589
-
590
-	}
591
-
592
-	/**
593
-	 * Filters the item query.
594
-	 */
595
-	public static function filter_item_query( $query ) {
596
-
597
-		// modify the query only if it admin and main query.
598
-		if ( ! ( is_admin() && $query->is_main_query() ) ){ 
599
-			return $query;
600
-		}
601
-
602
-		// we want to modify the query for our items.
603
-		if ( 'wpi_item' != $query->query['post_type'] ){
604
-			return $query;
605
-		}
606
-
607
-		if ( empty( $query->query_vars['meta_query'] ) ) {
608
-			$query->query_vars['meta_query'] = array();
609
-		}
610
-
611
-		// Filter vat rule type
542
+            // Sanitize selected vat rule.
543
+            $vat_class   = '';
544
+            if ( isset( $_GET['vat_class'] ) && array_key_exists(  $_GET['vat_class'], $wpinv_euvat->get_all_classes() ) ) {
545
+                $vat_class   =  $_GET['vat_class'];
546
+            }
547
+
548
+            echo wpinv_html_select(
549
+                array(
550
+                    'options'          => array_merge(
551
+                        array(
552
+                            '' => __( 'All VAT classes', 'invoicing' )
553
+                        ),
554
+                        $wpinv_euvat->get_all_classes()
555
+                    ),
556
+                    'name'             => 'vat_class',
557
+                    'id'               => 'vat_class',
558
+                    'selected'         => $vat_class,
559
+                    'show_option_all'  => false,
560
+                    'show_option_none' => false,
561
+                    'class'            => 'gdmbx2-text-medium',
562
+                )
563
+            );
564
+
565
+        }
566
+
567
+        // Filter by item type.
568
+        $type   = '';
569
+        if( isset( $_GET['type'] ) && array_key_exists(  $_GET['type'], wpinv_get_item_types() ) ) {
570
+            $type   =  $_GET['type'];
571
+        }
572
+
573
+        echo wpinv_html_select(
574
+            array(
575
+                'options'          => array_merge(
576
+                    array(
577
+                        '' => __( 'All item types', 'invoicing' )
578
+                    ),
579
+                    wpinv_get_item_types()
580
+                ),
581
+                'name'             => 'type',
582
+                'id'               => 'type',
583
+                'selected'         => $type,
584
+                'show_option_all'  => false,
585
+                'show_option_none' => false,
586
+                'class'            => 'gdmbx2-text-medium',
587
+            )
588
+        );
589
+
590
+    }
591
+
592
+    /**
593
+     * Filters the item query.
594
+     */
595
+    public static function filter_item_query( $query ) {
596
+
597
+        // modify the query only if it admin and main query.
598
+        if ( ! ( is_admin() && $query->is_main_query() ) ){ 
599
+            return $query;
600
+        }
601
+
602
+        // we want to modify the query for our items.
603
+        if ( 'wpi_item' != $query->query['post_type'] ){
604
+            return $query;
605
+        }
606
+
607
+        if ( empty( $query->query_vars['meta_query'] ) ) {
608
+            $query->query_vars['meta_query'] = array();
609
+        }
610
+
611
+        // Filter vat rule type
612 612
         if ( ! empty( $_GET['vat_rule'] ) ) {
613 613
             $query->query_vars['meta_query'][] = array(
614 614
                 'key'     => '_wpinv_vat_rule',
@@ -633,94 +633,94 @@  discard block
 block discarded – undo
633 633
                 'value'   => sanitize_text_field( $_GET['type'] ),
634 634
                 'compare' => '='
635 635
             );
636
-		}
637
-
638
-	}
639
-
640
-	/**
641
-	 * Reorders items.
642
-	 */
643
-	public static function reorder_items( $vars ) {
644
-		global $typenow;
645
-
646
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
647
-			return $vars;
648
-		}
649
-
650
-		// By item type.
651
-		if ( 'type' == $vars['orderby'] ) {
652
-			return array_merge(
653
-				$vars,
654
-				array(
655
-					'meta_key' => '_wpinv_type',
656
-					'orderby'  => 'meta_value'
657
-				)
658
-			);
659
-		}
660
-
661
-		// By vat class.
662
-		if ( 'vat_class' == $vars['orderby'] ) {
663
-			return array_merge(
664
-				$vars,
665
-				array(
666
-					'meta_key' => '_wpinv_vat_class',
667
-					'orderby'  => 'meta_value'
668
-				)
669
-			);
670
-		}
671
-
672
-		// By vat rule.
673
-		if ( 'vat_rule' == $vars['orderby'] ) {
674
-			return array_merge(
675
-				$vars,
676
-				array(
677
-					'meta_key' => '_wpinv_vat_rule',
678
-					'orderby'  => 'meta_value'
679
-				)
680
-			);
681
-		}
682
-
683
-		// By price.
684
-		if ( 'price' == $vars['orderby'] ) {
685
-			return array_merge(
686
-				$vars,
687
-				array(
688
-					'meta_key' => '_wpinv_price',
689
-					'orderby'  => 'meta_value_num'
690
-				)
691
-			);
692
-		}
693
-
694
-		return $vars;
695
-
696
-	}
697
-
698
-	/**
699
-	 * Fired when deleting a post.
700
-	 */
701
-	public static function delete_post( $post_id ) {
702
-
703
-		switch ( get_post_type( $post_id ) ) {
704
-
705
-			case 'wpi_item' :
706
-				do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
707
-				break;
708
-
709
-			case 'wpi_payment_form' :
710
-				do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
711
-				break;
712
-
713
-			case 'wpi_discount' :
714
-				do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
715
-				break;
716
-
717
-			case 'wpi_invoice' :
718
-				$invoice = new WPInv_Invoice( $post_id );
719
-				do_action( "getpaid_before_delete_invoice", $invoice );
720
-				$invoice->get_data_store()->delete_items( $invoice );
721
-				$invoice->get_data_store()->delete_special_fields( $invoice );
722
-				break;
723
-		}
724
-	}
636
+        }
637
+
638
+    }
639
+
640
+    /**
641
+     * Reorders items.
642
+     */
643
+    public static function reorder_items( $vars ) {
644
+        global $typenow;
645
+
646
+        if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
647
+            return $vars;
648
+        }
649
+
650
+        // By item type.
651
+        if ( 'type' == $vars['orderby'] ) {
652
+            return array_merge(
653
+                $vars,
654
+                array(
655
+                    'meta_key' => '_wpinv_type',
656
+                    'orderby'  => 'meta_value'
657
+                )
658
+            );
659
+        }
660
+
661
+        // By vat class.
662
+        if ( 'vat_class' == $vars['orderby'] ) {
663
+            return array_merge(
664
+                $vars,
665
+                array(
666
+                    'meta_key' => '_wpinv_vat_class',
667
+                    'orderby'  => 'meta_value'
668
+                )
669
+            );
670
+        }
671
+
672
+        // By vat rule.
673
+        if ( 'vat_rule' == $vars['orderby'] ) {
674
+            return array_merge(
675
+                $vars,
676
+                array(
677
+                    'meta_key' => '_wpinv_vat_rule',
678
+                    'orderby'  => 'meta_value'
679
+                )
680
+            );
681
+        }
682
+
683
+        // By price.
684
+        if ( 'price' == $vars['orderby'] ) {
685
+            return array_merge(
686
+                $vars,
687
+                array(
688
+                    'meta_key' => '_wpinv_price',
689
+                    'orderby'  => 'meta_value_num'
690
+                )
691
+            );
692
+        }
693
+
694
+        return $vars;
695
+
696
+    }
697
+
698
+    /**
699
+     * Fired when deleting a post.
700
+     */
701
+    public static function delete_post( $post_id ) {
702
+
703
+        switch ( get_post_type( $post_id ) ) {
704
+
705
+            case 'wpi_item' :
706
+                do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
707
+                break;
708
+
709
+            case 'wpi_payment_form' :
710
+                do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
711
+                break;
712
+
713
+            case 'wpi_discount' :
714
+                do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
715
+                break;
716
+
717
+            case 'wpi_invoice' :
718
+                $invoice = new WPInv_Invoice( $post_id );
719
+                do_action( "getpaid_before_delete_invoice", $invoice );
720
+                $invoice->get_data_store()->delete_items( $invoice );
721
+                $invoice->get_data_store()->delete_special_fields( $invoice );
722
+                break;
723
+        }
724
+    }
725 725
 
726 726
 }
Please login to merge, or discard this patch.
includes/admin/subscriptions.php 1 patch
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -8,23 +8,23 @@  discard block
 block discarded – undo
8 8
  */
9 9
 function wpinv_subscriptions_page() {
10 10
 
11
-	if ( ! empty( $_GET['id'] ) ) {
11
+    if ( ! empty( $_GET['id'] ) ) {
12 12
 
13 13
         wpinv_recurring_subscription_details();
14 14
 
15
-		return;
15
+        return;
16 16
 
17
-	}
18
-	?>
17
+    }
18
+    ?>
19 19
 	<div class="wrap">
20 20
 
21 21
 		<h1>
22 22
 			<?php _e( 'Subscriptions', 'invoicing' ); ?>
23 23
 		</h1>
24 24
 		<?php
25
-		$subscribers_table = new WPInv_Subscription_Lists_Table();
26
-		$subscribers_table->prepare_items();
27
-		?>
25
+        $subscribers_table = new WPInv_Subscription_Lists_Table();
26
+        $subscribers_table->prepare_items();
27
+        ?>
28 28
 
29 29
 		<form id="subscribers-filter" class="bsui" method="get">
30 30
 
@@ -46,25 +46,25 @@  discard block
 block discarded – undo
46 46
  */
47 47
 function wpinv_recurring_subscription_details() {
48 48
 
49
-	$render = true;
49
+    $render = true;
50 50
 
51
-	if ( ! current_user_can( 'manage_invoicing' ) ) {
52
-		die( __( 'You are not permitted to view this data.', 'invoicing' ) );
53
-	}
51
+    if ( ! current_user_can( 'manage_invoicing' ) ) {
52
+        die( __( 'You are not permitted to view this data.', 'invoicing' ) );
53
+    }
54 54
 
55
-	if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) {
55
+    if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) {
56 56
         die( __( 'Invalid subscription ID Provided.', 'invoicing' ) );
57
-	}
57
+    }
58 58
 
59
-	$sub_id  = (int) $_GET['id'];
60
-	$sub     = new WPInv_Subscription( $sub_id );
61
-	$parent  = new WPInv_Invoice( $sub->parent_payment_id );
59
+    $sub_id  = (int) $_GET['id'];
60
+    $sub     = new WPInv_Subscription( $sub_id );
61
+    $parent  = new WPInv_Invoice( $sub->parent_payment_id );
62 62
 
63
-	if ( empty( $sub ) ) {
64
-		die( __( 'Invalid subscription ID Provided.', 'invoicing' ) );
65
-	}
63
+    if ( empty( $sub ) ) {
64
+        die( __( 'Invalid subscription ID Provided.', 'invoicing' ) );
65
+    }
66 66
 
67
-	?>
67
+    ?>
68 68
 	<div class="wrap">
69 69
 		<h2><?php _e( 'Subscription Details', 'invoicing' ); ?></h2>
70 70
 
@@ -88,11 +88,11 @@  discard block
 block discarded – undo
88 88
 										</td>
89 89
 										<td>
90 90
 											<?php
91
-											$frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $sub->period, $sub->frequency );
92
-											$billing   = wpinv_price( wpinv_format_amount( $sub->recurring_amount ), $parent->get_currency() ) . ' / ' . $frequency;
93
-											$initial   = wpinv_price( wpinv_format_amount( $sub->initial_amount ), $parent->get_currency() );
94
-											printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing );
95
-											?>
91
+                                            $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $sub->period, $sub->frequency );
92
+                                            $billing   = wpinv_price( wpinv_format_amount( $sub->recurring_amount ), $parent->get_currency() ) . ' / ' . $frequency;
93
+                                            $initial   = wpinv_price( wpinv_format_amount( $sub->initial_amount ), $parent->get_currency() );
94
+                                            printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing );
95
+                                            ?>
96 96
 										</td>
97 97
 									</tr>
98 98
 									<tr>
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
 
135 135
                                             ?>
136 136
 											<a href="<?php echo esc_url( add_query_arg( array(
137
-													'post'   => $sub->product_id,
138
-													'action' => 'edit'
139
-												), admin_url( 'post.php' ) ) ); ?>" target="_blank"><?php _e( 'View Item', 'invoicing' ) ; ?></a>
137
+                                                    'post'   => $sub->product_id,
138
+                                                    'action' => 'edit'
139
+                                                ), admin_url( 'post.php' ) ) ); ?>" target="_blank"><?php _e( 'View Item', 'invoicing' ) ; ?></a>
140 140
 										</td>
141 141
 									</tr>
142 142
 									<tr>
@@ -299,56 +299,56 @@  discard block
 block discarded – undo
299 299
  */
300 300
 function wpinv_recurring_process_subscription_update() {
301 301
 
302
-	if( empty( $_POST['sub_id'] ) ) {
303
-		return;
304
-	}
302
+    if( empty( $_POST['sub_id'] ) ) {
303
+        return;
304
+    }
305 305
 
306
-	if( empty( $_POST['wpinv_update_subscription'] ) ) {
307
-		return;
308
-	}
306
+    if( empty( $_POST['wpinv_update_subscription'] ) ) {
307
+        return;
308
+    }
309 309
 
310
-	if( ! current_user_can( 'manage_invoicing') ) {
311
-		return;
312
-	}
310
+    if( ! current_user_can( 'manage_invoicing') ) {
311
+        return;
312
+    }
313 313
 
314
-	if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) {
315
-		wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
316
-	}
314
+    if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) {
315
+        wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
316
+    }
317 317
 
318
-	$profile_id      = sanitize_text_field( $_POST['profile_id'] );
319
-	$transaction_id  = sanitize_text_field( $_POST['transaction_id'] );
320
-	$product_id      = absint( $_POST['product_id'] );
321
-	$subscription    = new WPInv_Subscription( absint( $_POST['sub_id'] ) );
322
-	$subscription->update( array(
323
-		'status'         => sanitize_text_field( $_POST['status'] ),
324
-		'profile_id'     => $profile_id,
325
-		'product_id'     => $product_id,
326
-		'transaction_id' => $transaction_id,
327
-	) );
318
+    $profile_id      = sanitize_text_field( $_POST['profile_id'] );
319
+    $transaction_id  = sanitize_text_field( $_POST['transaction_id'] );
320
+    $product_id      = absint( $_POST['product_id'] );
321
+    $subscription    = new WPInv_Subscription( absint( $_POST['sub_id'] ) );
322
+    $subscription->update( array(
323
+        'status'         => sanitize_text_field( $_POST['status'] ),
324
+        'profile_id'     => $profile_id,
325
+        'product_id'     => $product_id,
326
+        'transaction_id' => $transaction_id,
327
+    ) );
328 328
 
329
-	$status = sanitize_text_field( $_POST['status'] );
329
+    $status = sanitize_text_field( $_POST['status'] );
330 330
 
331
-	switch( $status ) {
331
+    switch( $status ) {
332 332
 
333
-		case 'cancelled' :
333
+        case 'cancelled' :
334 334
 
335
-			$subscription->cancel();
336
-			break;
335
+            $subscription->cancel();
336
+            break;
337 337
 
338
-		case 'expired' :
338
+        case 'expired' :
339 339
 
340
-			$subscription->expire();
341
-			break;
340
+            $subscription->expire();
341
+            break;
342 342
 
343
-		case 'completed' :
343
+        case 'completed' :
344 344
 
345
-			$subscription->complete();
346
-			break;
345
+            $subscription->complete();
346
+            break;
347 347
 
348
-	}
348
+    }
349 349
 
350
-	wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=updated&id=' . $subscription->id ) );
351
-	exit;
350
+    wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=updated&id=' . $subscription->id ) );
351
+    exit;
352 352
 
353 353
 }
354 354
 add_action( 'admin_init', 'wpinv_recurring_process_subscription_update', 1 );
@@ -362,30 +362,30 @@  discard block
 block discarded – undo
362 362
  */
363 363
 function wpinv_recurring_process_subscription_deletion() {
364 364
 
365
-	if( empty( $_POST['sub_id'] ) ) {
366
-		return;
367
-	}
365
+    if( empty( $_POST['sub_id'] ) ) {
366
+        return;
367
+    }
368 368
 
369
-	if( empty( $_POST['wpinv_delete_subscription'] ) ) {
370
-		return;
371
-	}
369
+    if( empty( $_POST['wpinv_delete_subscription'] ) ) {
370
+        return;
371
+    }
372 372
 
373
-	if( ! current_user_can( 'manage_invoicing') ) {
374
-		return;
375
-	}
373
+    if( ! current_user_can( 'manage_invoicing') ) {
374
+        return;
375
+    }
376 376
 
377
-	if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) {
378
-		wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
379
-	}
377
+    if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) {
378
+        wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
379
+    }
380 380
 
381
-	$subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) );
381
+    $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) );
382 382
 
383
-	delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' );
383
+    delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' );
384 384
 
385
-	$subscription->delete();
385
+    $subscription->delete();
386 386
 
387
-	wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) );
388
-	exit;
387
+    wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) );
388
+    exit;
389 389
 
390 390
 }
391 391
 add_action( 'admin_init', 'wpinv_recurring_process_subscription_deletion', 2 );
Please login to merge, or discard this patch.
includes/admin/class-wpinv-subscriptions-list-table.php 1 patch
Indentation   +409 added lines, -409 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 if ( ! defined( 'ABSPATH' ) ) exit;
7 7
 
8 8
 if ( ! class_exists( 'WP_List_Table' ) ) {
9
-	include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
9
+    include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
10 10
 }
11 11
 
12 12
 /**
@@ -14,415 +14,415 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class WPInv_Subscription_Lists_Table extends WP_List_Table {
16 16
 
17
-	/**
18
-	 * URL of this page
19
-	 *
20
-	 * @var   string
21
-	 * @since 1.0.19
22
-	 */
23
-	public $base_url;
24
-
25
-	/**
26
-	 * Query
27
-	 *
28
-	 * @var   GetPaid_Subscriptions_Query
29
-	 * @since 1.0.19
30
-	 */
31
-	public $query;
32
-
33
-	/**
34
-	 * Total subscriptions
35
-	 *
36
-	 * @var   string
37
-	 * @since 1.0.0
38
-	 */
39
-	public $total_count;
40
-
41
-	/**
42
-	 * Current status subscriptions
43
-	 *
44
-	 * @var   string
45
-	 * @since 1.0.0
46
-	 */
47
-	public $current_total_count;
48
-
49
-	/**
50
-	 * Status counts
51
-	 *
52
-	 * @var   array
53
-	 * @since 1.0.19
54
-	 */
55
-	public $status_counts;
56
-
57
-	/**
58
-	 * Number of results to show per page
59
-	 *
60
-	 * @var   int
61
-	 * @since 1.0.0
62
-	 */
63
-	public $per_page = 10;
64
-
65
-	/**
66
-	 *  Constructor function.
67
-	 */
68
-	public function __construct() {
69
-
70
-		parent::__construct(
71
-			array(
72
-				'singular' => 'subscription',
73
-				'plural'   => 'subscriptions',
74
-			)
75
-		);
76
-
77
-		$this->process_bulk_action();
78
-
79
-		$this->prepare_query();
80
-
81
-		$this->base_url = remove_query_arg( 'status' );
82
-
83
-	}
84
-
85
-	/**
86
-	 *  Prepares the display query
87
-	 */
88
-	public function prepare_query() {
89
-
90
-		// Prepare query args.
91
-		$query = array(
92
-			'number'  => $this->per_page,
93
-			'paged'   => $this->get_paged(),
94
-			'status'  => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all',
95
-			'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id',
96
-			'order'   => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC',
97
-		);
98
-
99
-		// Prepare class properties.
100
-		$this->query               = new GetPaid_Subscriptions_Query( $query );
101
-		$this->total_count         = $this->query->get_total();
102
-		$this->current_total_count = $this->query->get_total();
103
-		$this->items               = $this->query->get_results();
104
-		$this->status_counts       = getpaid_get_subscription_status_counts( $query );
105
-
106
-		if ( 'all' != $query['status'] ) {
107
-			unset( $query['status'] );
108
-			$this->total_count   = getpaid_get_subscriptions( $query, 'count' );
109
-		}
110
-
111
-	}
112
-
113
-	/**
114
-	 * Gets the list of views available on this table.
115
-	 *
116
-	 * The format is an associative array:
117
-	 * - `'id' => 'link'`
118
-	 *
119
-	 * @since 1.0.0
120
-	 *
121
-	 * @return array
122
-	 */
123
-	protected function get_views() {
124
-
125
-		$current  = isset( $_GET['status'] ) ? $_GET['status'] : 'all';
126
-		$views    = array(
127
-
128
-			'all' => sprintf(
129
-				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
130
-				esc_url( add_query_arg( 'status', false, $this->base_url ) ),
131
-				$current === 'all' ? ' class="current"' : '',
132
-				__('All','invoicing' ),
133
-				$this->total_count
134
-			)
135
-
136
-		);
137
-
138
-		foreach ( array_filter( $this->status_counts ) as $status => $count ) {
139
-
140
-			$views[ $status ] = sprintf(
141
-				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
142
-				esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
143
-				$current === $status ? ' class="current"' : '',
144
-				sanitize_text_field( getpaid_get_subscription_status_label( $status ) ),
145
-				$count
146
-			);
147
-
148
-		}
149
-
150
-		return $views;
151
-
152
-	}
153
-
154
-	/**
155
-	 * Render most columns
156
-	 *
157
-	 * @access      private
158
-	 * @since       1.0.0
159
-	 * @return      string
160
-	 */
161
-	public function column_default( $item, $column_name ) {
162
-		return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
163
-	}
164
-
165
-	/**
166
-	 * This is how checkbox column renders.
167
-	 *
168
-	 * @param WPInv_Subscription $item
169
-	 * @return string
170
-	 */
171
-	public function column_cb( $item ) {
172
-		return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
173
-	}
174
-
175
-	/**
176
-	 * Status column
177
-	 *
178
-	 * @param WPInv_Subscription $item
179
-	 * @since       1.0.0
180
-	 * @return      string
181
-	 */
182
-	public function column_status( $item ) {
183
-		return $item->get_status_label_html();
184
-	}
185
-
186
-	/**
187
-	 * Subscription column
188
-	 *
189
-	 * @param WPInv_Subscription $item
190
-	 * @since       1.0.0
191
-	 * @return      string
192
-	 */
193
-	public function column_subscription( $item ) {
194
-
195
-		$username = __( '(Missing User)', 'invoicing' );
196
-
197
-		$user = get_userdata( $item->get_customer_id() );
198
-		if ( $user ) {
199
-
200
-			$username = sprintf(
201
-				'<a href="user-edit.php?user_id=%s">%s</a>',
202
-				absint( $user->ID ),
203
-				! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
204
-			);
205
-
206
-		}
207
-
208
-		// translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
209
-		$column_content = sprintf(
210
-			_x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
211
-			'<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
212
-			'<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>',
213
-			$username
214
-		);
215
-
216
-		$row_actions = array();
217
-
218
-		// View subscription.
219
-		$view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ));
220
-		$row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
221
-
222
-		// View invoice.
223
-		$invoice = get_post( $item->get_product_id() );
224
-
225
-		if ( ! empty( $invoice ) ) {
226
-			$view_url    = get_edit_post_link( $invoice );
227
-			$row_actions['invoice'] = '<a href="' . $view_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
228
-		}
229
-
230
-		$row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
231
-
232
-		return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
233
-	}
234
-
235
-	/**
236
-	 * Renewal date column
237
-	 *
238
-	 * @param WPInv_Subscription $item
239
-	 * @since       1.0.0
240
-	 * @return      string
241
-	 */
242
-	public function column_renewal_date( $item ) {
243
-
244
-		$expiration = $item->get_expiration();
245
-		if ( ! $item->is_active() || empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
246
-			return "&mdash;";
247
-		}
248
-
249
-		return date_i18n( get_option( 'date_format' ), strtotime( $expiration ) );
17
+    /**
18
+     * URL of this page
19
+     *
20
+     * @var   string
21
+     * @since 1.0.19
22
+     */
23
+    public $base_url;
24
+
25
+    /**
26
+     * Query
27
+     *
28
+     * @var   GetPaid_Subscriptions_Query
29
+     * @since 1.0.19
30
+     */
31
+    public $query;
32
+
33
+    /**
34
+     * Total subscriptions
35
+     *
36
+     * @var   string
37
+     * @since 1.0.0
38
+     */
39
+    public $total_count;
40
+
41
+    /**
42
+     * Current status subscriptions
43
+     *
44
+     * @var   string
45
+     * @since 1.0.0
46
+     */
47
+    public $current_total_count;
48
+
49
+    /**
50
+     * Status counts
51
+     *
52
+     * @var   array
53
+     * @since 1.0.19
54
+     */
55
+    public $status_counts;
56
+
57
+    /**
58
+     * Number of results to show per page
59
+     *
60
+     * @var   int
61
+     * @since 1.0.0
62
+     */
63
+    public $per_page = 10;
64
+
65
+    /**
66
+     *  Constructor function.
67
+     */
68
+    public function __construct() {
69
+
70
+        parent::__construct(
71
+            array(
72
+                'singular' => 'subscription',
73
+                'plural'   => 'subscriptions',
74
+            )
75
+        );
76
+
77
+        $this->process_bulk_action();
78
+
79
+        $this->prepare_query();
80
+
81
+        $this->base_url = remove_query_arg( 'status' );
82
+
83
+    }
84
+
85
+    /**
86
+     *  Prepares the display query
87
+     */
88
+    public function prepare_query() {
89
+
90
+        // Prepare query args.
91
+        $query = array(
92
+            'number'  => $this->per_page,
93
+            'paged'   => $this->get_paged(),
94
+            'status'  => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all',
95
+            'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id',
96
+            'order'   => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC',
97
+        );
98
+
99
+        // Prepare class properties.
100
+        $this->query               = new GetPaid_Subscriptions_Query( $query );
101
+        $this->total_count         = $this->query->get_total();
102
+        $this->current_total_count = $this->query->get_total();
103
+        $this->items               = $this->query->get_results();
104
+        $this->status_counts       = getpaid_get_subscription_status_counts( $query );
105
+
106
+        if ( 'all' != $query['status'] ) {
107
+            unset( $query['status'] );
108
+            $this->total_count   = getpaid_get_subscriptions( $query, 'count' );
109
+        }
110
+
111
+    }
112
+
113
+    /**
114
+     * Gets the list of views available on this table.
115
+     *
116
+     * The format is an associative array:
117
+     * - `'id' => 'link'`
118
+     *
119
+     * @since 1.0.0
120
+     *
121
+     * @return array
122
+     */
123
+    protected function get_views() {
124
+
125
+        $current  = isset( $_GET['status'] ) ? $_GET['status'] : 'all';
126
+        $views    = array(
127
+
128
+            'all' => sprintf(
129
+                '<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
130
+                esc_url( add_query_arg( 'status', false, $this->base_url ) ),
131
+                $current === 'all' ? ' class="current"' : '',
132
+                __('All','invoicing' ),
133
+                $this->total_count
134
+            )
135
+
136
+        );
137
+
138
+        foreach ( array_filter( $this->status_counts ) as $status => $count ) {
139
+
140
+            $views[ $status ] = sprintf(
141
+                '<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
142
+                esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
143
+                $current === $status ? ' class="current"' : '',
144
+                sanitize_text_field( getpaid_get_subscription_status_label( $status ) ),
145
+                $count
146
+            );
147
+
148
+        }
149
+
150
+        return $views;
151
+
152
+    }
153
+
154
+    /**
155
+     * Render most columns
156
+     *
157
+     * @access      private
158
+     * @since       1.0.0
159
+     * @return      string
160
+     */
161
+    public function column_default( $item, $column_name ) {
162
+        return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
163
+    }
164
+
165
+    /**
166
+     * This is how checkbox column renders.
167
+     *
168
+     * @param WPInv_Subscription $item
169
+     * @return string
170
+     */
171
+    public function column_cb( $item ) {
172
+        return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
173
+    }
174
+
175
+    /**
176
+     * Status column
177
+     *
178
+     * @param WPInv_Subscription $item
179
+     * @since       1.0.0
180
+     * @return      string
181
+     */
182
+    public function column_status( $item ) {
183
+        return $item->get_status_label_html();
184
+    }
185
+
186
+    /**
187
+     * Subscription column
188
+     *
189
+     * @param WPInv_Subscription $item
190
+     * @since       1.0.0
191
+     * @return      string
192
+     */
193
+    public function column_subscription( $item ) {
194
+
195
+        $username = __( '(Missing User)', 'invoicing' );
196
+
197
+        $user = get_userdata( $item->get_customer_id() );
198
+        if ( $user ) {
199
+
200
+            $username = sprintf(
201
+                '<a href="user-edit.php?user_id=%s">%s</a>',
202
+                absint( $user->ID ),
203
+                ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
204
+            );
205
+
206
+        }
207
+
208
+        // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
209
+        $column_content = sprintf(
210
+            _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
211
+            '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
212
+            '<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>',
213
+            $username
214
+        );
215
+
216
+        $row_actions = array();
217
+
218
+        // View subscription.
219
+        $view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ));
220
+        $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
221
+
222
+        // View invoice.
223
+        $invoice = get_post( $item->get_product_id() );
224
+
225
+        if ( ! empty( $invoice ) ) {
226
+            $view_url    = get_edit_post_link( $invoice );
227
+            $row_actions['invoice'] = '<a href="' . $view_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
228
+        }
229
+
230
+        $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
231
+
232
+        return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
233
+    }
234
+
235
+    /**
236
+     * Renewal date column
237
+     *
238
+     * @param WPInv_Subscription $item
239
+     * @since       1.0.0
240
+     * @return      string
241
+     */
242
+    public function column_renewal_date( $item ) {
243
+
244
+        $expiration = $item->get_expiration();
245
+        if ( ! $item->is_active() || empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
246
+            return "&mdash;";
247
+        }
248
+
249
+        return date_i18n( get_option( 'date_format' ), strtotime( $expiration ) );
250 250
 		
251
-	}
252
-
253
-	/**
254
-	 * Start date column
255
-	 *
256
-	 * @param WPInv_Subscription $item
257
-	 * @since       1.0.0
258
-	 * @return      string
259
-	 */
260
-	public function column_start_date( $item ) {
261
-
262
-		$created = $item->get_date_created();
263
-		if ( empty( $created ) || '0000-00-00 00:00:00' == $created ) {
264
-			return "&mdash;";
265
-		}
266
-
267
-		return date_i18n( get_option( 'date_format' ), strtotime( $created ) );
268
-
269
-	}
270
-
271
-	/**
272
-	 * Amount column
273
-	 *
274
-	 * @param WPInv_Subscription $item
275
-	 * @since       1.0.19
276
-	 * @return      string
277
-	 */
278
-	public function column_amount( $item ) {
279
-
280
-		$initial   = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $item->get_initial_amount() ) ), $item->get_parent_payment()->get_currency() );
281
-		$recurring = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $item->get_recurring_amount() ) ), $item->get_parent_payment()->get_currency() );
282
-		$period    = 1 == $item->get_frequency() ? getpaid_get_subscription_period_label( $item->get_period() ) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_period(),$item->get_frequency() );
283
-
284
-		if ( $item->has_trial_period() ) {
285
-
286
-			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
287
-			$amount = sprintf(
288
-				_x( '%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
289
-				$initial,
290
-				sanitize_text_field( $item->get_trial_period() ),
291
-				$recurring,
292
-				sanitize_text_field( strtolower( $period ) )
293
-			);
294
-
295
-		} else if ( $initial != $recurring ) {
251
+    }
252
+
253
+    /**
254
+     * Start date column
255
+     *
256
+     * @param WPInv_Subscription $item
257
+     * @since       1.0.0
258
+     * @return      string
259
+     */
260
+    public function column_start_date( $item ) {
261
+
262
+        $created = $item->get_date_created();
263
+        if ( empty( $created ) || '0000-00-00 00:00:00' == $created ) {
264
+            return "&mdash;";
265
+        }
266
+
267
+        return date_i18n( get_option( 'date_format' ), strtotime( $created ) );
268
+
269
+    }
270
+
271
+    /**
272
+     * Amount column
273
+     *
274
+     * @param WPInv_Subscription $item
275
+     * @since       1.0.19
276
+     * @return      string
277
+     */
278
+    public function column_amount( $item ) {
279
+
280
+        $initial   = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $item->get_initial_amount() ) ), $item->get_parent_payment()->get_currency() );
281
+        $recurring = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $item->get_recurring_amount() ) ), $item->get_parent_payment()->get_currency() );
282
+        $period    = 1 == $item->get_frequency() ? getpaid_get_subscription_period_label( $item->get_period() ) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_period(),$item->get_frequency() );
283
+
284
+        if ( $item->has_trial_period() ) {
285
+
286
+            // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
287
+            $amount = sprintf(
288
+                _x( '%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
289
+                $initial,
290
+                sanitize_text_field( $item->get_trial_period() ),
291
+                $recurring,
292
+                sanitize_text_field( strtolower( $period ) )
293
+            );
294
+
295
+        } else if ( $initial != $recurring ) {
296 296
 			
297
-			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring perio
298
-			$amount = sprintf(
299
-				_x( 'Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing' ),
300
-				$initial,
301
-				$recurring,
302
-				sanitize_text_field( strtolower( $period ) )
303
-			);
304
-
305
-		} else {
306
-
307
-			// translators: $1: is the recurring amount, $2: is the recurring period
308
-			$amount = sprintf(
309
-				_x( '%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing' ),
310
-				$initial,
311
-				sanitize_text_field( strtolower( $period ) )
312
-			);
313
-
314
-		}
315
-
316
-		return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
317
-	}
318
-
319
-	/**
320
-	 * Billing Times column
321
-	 *
322
-	 * @param WPInv_Subscription $item
323
-	 * @since       1.0.0
324
-	 * @return      string
325
-	 */
326
-	public function column_renewals( $item ) {
327
-		$max_bills = $item->get_bill_times();
328
-		return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
329
-	}
330
-
331
-	/**
332
-	 * Product ID column
333
-	 *
334
-	 * @param WPInv_Subscription $item
335
-	 * @since       1.0.0
336
-	 * @return      string
337
-	 */
338
-	function column_item( $item ) {
339
-		$_item = get_post( $item->get_product_id() );
340
-
341
-		if ( ! empty( $_item ) ) {
342
-			$link = get_edit_post_link( $_item );
343
-			$link = esc_url( $link );
344
-			$name = esc_html( get_the_title( $_item ) );
345
-			return "<a href='$link'>$name</a>";
346
-		} else {
347
-			return sprintf( __( 'Item #%s', 'invoicing' ), $item->get_product_id() );
348
-		}
349
-
350
-	}
351
-
352
-	/**
353
-	 * Retrieve the current page number
354
-	 *
355
-	 * @return      int
356
-	 */
357
-	public function get_paged() {
358
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
359
-	}
360
-
361
-	/**
362
-	 * Setup the final data for the table
363
-	 *
364
-	 */
365
-	public function prepare_items() {
366
-
367
-		$columns  = $this->get_columns();
368
-		$hidden   = array();
369
-		$sortable = $this->get_sortable_columns();
370
-
371
-		$this->_column_headers = array( $columns, $hidden, $sortable );
372
-
373
-		$this->set_pagination_args(
374
-			array(
375
-			'total_items' => $this->current_total_count,
376
-			'per_page'    => $this->per_page,
377
-			'total_pages' => ceil( $this->current_total_count / $this->per_page )
378
-			)
379
-		);
380
-	}
381
-
382
-	/**
383
-	 * Table columns
384
-	 *
385
-	 * @return array
386
-	 */
387
-	public function get_columns(){
388
-		$columns = array(
389
-			'cb'                => '<input type="checkbox" />',
390
-			'subscription'      => __( 'Subscription', 'invoicing' ),
391
-			'start_date'        => __( 'Start Date', 'invoicing' ),
392
-			'renewal_date'      => __( 'Next Payment', 'invoicing' ),
393
-			'renewals'          => __( 'Renewals', 'invoicing' ),
394
-			'item'              => __( 'Item', 'invoicing' ),
395
-			'status'            => __( 'Status', 'invoicing' ),
396
-		);
397
-
398
-		return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
399
-	}
400
-
401
-	/**
402
-	 * Sortable table columns.
403
-	 *
404
-	 * @return array
405
-	 */
406
-	public function get_sortable_columns() {
407
-		$sortable = array(
408
-			'subscription' => array( 'id', true ),
409
-			'start_date'   => array( 'created', true ),
410
-			'renewal_date' => array( 'expiration', true ),
411
-			'renewals'     => array( 'bill_times', true ),
412
-			'item'         => array( 'product_id', true ),
413
-			'status'       => array( 'status', true ),
414
-		);
415
-
416
-		return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
417
-	}
418
-
419
-	/**
420
-	 * Whether the table has items to display or not
421
-	 *
422
-	 * @return bool
423
-	 */
424
-	public function has_items() {
425
-		return ! empty( $this->current_total_count );
426
-	}
297
+            // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring perio
298
+            $amount = sprintf(
299
+                _x( 'Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing' ),
300
+                $initial,
301
+                $recurring,
302
+                sanitize_text_field( strtolower( $period ) )
303
+            );
304
+
305
+        } else {
306
+
307
+            // translators: $1: is the recurring amount, $2: is the recurring period
308
+            $amount = sprintf(
309
+                _x( '%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing' ),
310
+                $initial,
311
+                sanitize_text_field( strtolower( $period ) )
312
+            );
313
+
314
+        }
315
+
316
+        return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
317
+    }
318
+
319
+    /**
320
+     * Billing Times column
321
+     *
322
+     * @param WPInv_Subscription $item
323
+     * @since       1.0.0
324
+     * @return      string
325
+     */
326
+    public function column_renewals( $item ) {
327
+        $max_bills = $item->get_bill_times();
328
+        return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
329
+    }
330
+
331
+    /**
332
+     * Product ID column
333
+     *
334
+     * @param WPInv_Subscription $item
335
+     * @since       1.0.0
336
+     * @return      string
337
+     */
338
+    function column_item( $item ) {
339
+        $_item = get_post( $item->get_product_id() );
340
+
341
+        if ( ! empty( $_item ) ) {
342
+            $link = get_edit_post_link( $_item );
343
+            $link = esc_url( $link );
344
+            $name = esc_html( get_the_title( $_item ) );
345
+            return "<a href='$link'>$name</a>";
346
+        } else {
347
+            return sprintf( __( 'Item #%s', 'invoicing' ), $item->get_product_id() );
348
+        }
349
+
350
+    }
351
+
352
+    /**
353
+     * Retrieve the current page number
354
+     *
355
+     * @return      int
356
+     */
357
+    public function get_paged() {
358
+        return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
359
+    }
360
+
361
+    /**
362
+     * Setup the final data for the table
363
+     *
364
+     */
365
+    public function prepare_items() {
366
+
367
+        $columns  = $this->get_columns();
368
+        $hidden   = array();
369
+        $sortable = $this->get_sortable_columns();
370
+
371
+        $this->_column_headers = array( $columns, $hidden, $sortable );
372
+
373
+        $this->set_pagination_args(
374
+            array(
375
+            'total_items' => $this->current_total_count,
376
+            'per_page'    => $this->per_page,
377
+            'total_pages' => ceil( $this->current_total_count / $this->per_page )
378
+            )
379
+        );
380
+    }
381
+
382
+    /**
383
+     * Table columns
384
+     *
385
+     * @return array
386
+     */
387
+    public function get_columns(){
388
+        $columns = array(
389
+            'cb'                => '<input type="checkbox" />',
390
+            'subscription'      => __( 'Subscription', 'invoicing' ),
391
+            'start_date'        => __( 'Start Date', 'invoicing' ),
392
+            'renewal_date'      => __( 'Next Payment', 'invoicing' ),
393
+            'renewals'          => __( 'Renewals', 'invoicing' ),
394
+            'item'              => __( 'Item', 'invoicing' ),
395
+            'status'            => __( 'Status', 'invoicing' ),
396
+        );
397
+
398
+        return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
399
+    }
400
+
401
+    /**
402
+     * Sortable table columns.
403
+     *
404
+     * @return array
405
+     */
406
+    public function get_sortable_columns() {
407
+        $sortable = array(
408
+            'subscription' => array( 'id', true ),
409
+            'start_date'   => array( 'created', true ),
410
+            'renewal_date' => array( 'expiration', true ),
411
+            'renewals'     => array( 'bill_times', true ),
412
+            'item'         => array( 'product_id', true ),
413
+            'status'       => array( 'status', true ),
414
+        );
415
+
416
+        return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
417
+    }
418
+
419
+    /**
420
+     * Whether the table has items to display or not
421
+     *
422
+     * @return bool
423
+     */
424
+    public function has_items() {
425
+        return ! empty( $this->current_total_count );
426
+    }
427 427
 
428 428
 }
Please login to merge, or discard this patch.
includes/wpinv-subscription.php 1 patch
Indentation   +948 added lines, -948 removed lines patch added patch discarded remove patch
@@ -15,127 +15,127 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class WPInv_Subscription extends GetPaid_Data {
17 17
 
18
-	/**
19
-	 * Which data store to load.
20
-	 *
21
-	 * @var string
22
-	 */
23
-	protected $data_store_name = 'subscription';
24
-
25
-	/**
26
-	 * This is the name of this object type.
27
-	 *
28
-	 * @var string
29
-	 */
30
-	protected $object_type = 'subscription';
31
-
32
-	/**
33
-	 * Item Data array. This is the core item data exposed in APIs.
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array(
39
-		'customer_id'       => 0,
40
-		'frequency'         => 1,
41
-		'period'            => 'D',
42
-		'initial_amount'    => null,
43
-		'recurring_amount'  => null,
44
-		'bill_times'        => 0,
45
-		'transaction_id'    => '',
46
-		'parent_payment_id' => null,
47
-		'product_id'        => 0,
48
-		'created'           => '0000-00-00 00:00:00',
49
-		'expiration'        => '0000-00-00 00:00:00',
50
-		'trial_period'      => null,
51
-		'status'            => 'pending',
52
-		'profile_id'        => '',
53
-		'gateway'           => '',
54
-		'customer'          => '',
55
-	);
56
-
57
-	/**
58
-	 * Stores the status transition information.
59
-	 *
60
-	 * @since 1.0.19
61
-	 * @var bool
62
-	 */
63
-	protected $status_transition = false;
64
-
65
-	private $subs_db;
66
-
67
-	/**
68
-	 * Get the subscription if ID is passed, otherwise the subscription is new and empty.
69
-	 *
70
-	 * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
71
-	 * @param  bool $deprecated
72
-	 */
73
-	function __construct( $subscription = 0, $deprecated = false ) {
74
-
75
-		parent::__construct( $subscription );
76
-
77
-		if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
78
-			$this->set_id( $subscription );
79
-		} elseif ( $subscription instanceof self ) {
80
-			$this->set_id( $subscription->get_id() );
81
-		} elseif ( ! empty( $subscription->id ) ) {
82
-			$this->set_id( $subscription->id );
83
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
84
-			$this->set_id( $subscription_id );
85
-		} else {
86
-			$this->set_object_read( true );
87
-		}
88
-
89
-		// Load the datastore.
90
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
91
-
92
-		if ( $this->get_id() > 0 ) {
93
-			$this->data_store->read( $this );
94
-		}
95
-
96
-	}
97
-
98
-	/**
99
-	 * Given an invoice id, profile id, transaction id, it returns the subscription's id.
100
-	 *
101
-	 *
102
-	 * @static
103
-	 * @param string $value
104
-	 * @param string $field Either invoice_id, transaction_id or profile_id.
105
-	 * @since 1.0.19
106
-	 * @return int
107
-	 */
108
-	public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
18
+    /**
19
+     * Which data store to load.
20
+     *
21
+     * @var string
22
+     */
23
+    protected $data_store_name = 'subscription';
24
+
25
+    /**
26
+     * This is the name of this object type.
27
+     *
28
+     * @var string
29
+     */
30
+    protected $object_type = 'subscription';
31
+
32
+    /**
33
+     * Item Data array. This is the core item data exposed in APIs.
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array(
39
+        'customer_id'       => 0,
40
+        'frequency'         => 1,
41
+        'period'            => 'D',
42
+        'initial_amount'    => null,
43
+        'recurring_amount'  => null,
44
+        'bill_times'        => 0,
45
+        'transaction_id'    => '',
46
+        'parent_payment_id' => null,
47
+        'product_id'        => 0,
48
+        'created'           => '0000-00-00 00:00:00',
49
+        'expiration'        => '0000-00-00 00:00:00',
50
+        'trial_period'      => null,
51
+        'status'            => 'pending',
52
+        'profile_id'        => '',
53
+        'gateway'           => '',
54
+        'customer'          => '',
55
+    );
56
+
57
+    /**
58
+     * Stores the status transition information.
59
+     *
60
+     * @since 1.0.19
61
+     * @var bool
62
+     */
63
+    protected $status_transition = false;
64
+
65
+    private $subs_db;
66
+
67
+    /**
68
+     * Get the subscription if ID is passed, otherwise the subscription is new and empty.
69
+     *
70
+     * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
71
+     * @param  bool $deprecated
72
+     */
73
+    function __construct( $subscription = 0, $deprecated = false ) {
74
+
75
+        parent::__construct( $subscription );
76
+
77
+        if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
78
+            $this->set_id( $subscription );
79
+        } elseif ( $subscription instanceof self ) {
80
+            $this->set_id( $subscription->get_id() );
81
+        } elseif ( ! empty( $subscription->id ) ) {
82
+            $this->set_id( $subscription->id );
83
+        } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
84
+            $this->set_id( $subscription_id );
85
+        } else {
86
+            $this->set_object_read( true );
87
+        }
88
+
89
+        // Load the datastore.
90
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
91
+
92
+        if ( $this->get_id() > 0 ) {
93
+            $this->data_store->read( $this );
94
+        }
95
+
96
+    }
97
+
98
+    /**
99
+     * Given an invoice id, profile id, transaction id, it returns the subscription's id.
100
+     *
101
+     *
102
+     * @static
103
+     * @param string $value
104
+     * @param string $field Either invoice_id, transaction_id or profile_id.
105
+     * @since 1.0.19
106
+     * @return int
107
+     */
108
+    public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
109 109
         global $wpdb;
110 110
 
111
-		// Trim the value.
112
-		$value = trim( $value );
111
+        // Trim the value.
112
+        $value = trim( $value );
113 113
 
114
-		if ( empty( $value ) ) {
115
-			return 0;
116
-		}
114
+        if ( empty( $value ) ) {
115
+            return 0;
116
+        }
117 117
 
118
-		if ( 'invoice_id' == $field ) {
119
-			$field = 'parent_payment_id';
120
-		}
118
+        if ( 'invoice_id' == $field ) {
119
+            $field = 'parent_payment_id';
120
+        }
121 121
 
122 122
         // Valid fields.
123 123
         $fields = array(
124
-			'parent_payment_id',
125
-			'transaction_id',
126
-			'profile_id'
127
-		);
128
-
129
-		// Ensure a field has been passed.
130
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
131
-			return 0;
132
-		}
133
-
134
-		// Maybe retrieve from the cache.
135
-		$subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
136
-		if ( ! empty( $subscription_id ) ) {
137
-			return $subscription_id;
138
-		}
124
+            'parent_payment_id',
125
+            'transaction_id',
126
+            'profile_id'
127
+        );
128
+
129
+        // Ensure a field has been passed.
130
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
131
+            return 0;
132
+        }
133
+
134
+        // Maybe retrieve from the cache.
135
+        $subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
136
+        if ( ! empty( $subscription_id ) ) {
137
+            return $subscription_id;
138
+        }
139 139
 
140 140
         // Fetch from the db.
141 141
         $table            = $wpdb->prefix . 'wpinv_subscriptions';
@@ -143,34 +143,34 @@  discard block
 block discarded – undo
143 143
             $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
144 144
         );
145 145
 
146
-		if ( empty( $subscription_id ) ) {
147
-			return 0;
148
-		}
146
+        if ( empty( $subscription_id ) ) {
147
+            return 0;
148
+        }
149 149
 
150
-		// Update the cache with our data.
151
-		wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
150
+        // Update the cache with our data.
151
+        wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
152 152
 
153
-		return $subscription_id;
154
-	}
153
+        return $subscription_id;
154
+    }
155 155
 
156
-	/**
156
+    /**
157 157
      * Clears the subscription's cache.
158 158
      */
159 159
     public function clear_cache() {
160
-		wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
161
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
162
-		wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
163
-		wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
164
-	}
160
+        wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
161
+        wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
162
+        wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
163
+        wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
164
+    }
165 165
 
166
-	/**
166
+    /**
167 167
      * Checks if a subscription key is set.
168 168
      */
169 169
     public function _isset( $key ) {
170 170
         return isset( $this->data[$key] ) || method_exists( $this, "get_$key" );
171
-	}
171
+    }
172 172
 
173
-	/*
173
+    /*
174 174
 	|--------------------------------------------------------------------------
175 175
 	| CRUD methods
176 176
 	|--------------------------------------------------------------------------
@@ -179,57 +179,57 @@  discard block
 block discarded – undo
179 179
 	|
180 180
     */
181 181
 
182
-	/*
182
+    /*
183 183
 	|--------------------------------------------------------------------------
184 184
 	| Getters
185 185
 	|--------------------------------------------------------------------------
186 186
 	*/
187 187
 
188
-	/**
189
-	 * Get customer id.
190
-	 *
191
-	 * @since 1.0.19
192
-	 * @param  string $context View or edit context.
193
-	 * @return int
194
-	 */
195
-	public function get_customer_id( $context = 'view' ) {
196
-		return (int) $this->get_prop( 'customer_id', $context );
197
-	}
198
-
199
-	/**
200
-	 * Get customer information.
201
-	 *
202
-	 * @since 1.0.19
203
-	 * @param  string $context View or edit context.
204
-	 * @return WP_User|false WP_User object on success, false on failure.
205
-	 */
206
-	public function get_customer( $context = 'view' ) {
207
-		return get_userdata( $this->get_customer_id( $context ) );
208
-	}
209
-
210
-	/**
211
-	 * Get parent invoice id.
212
-	 *
213
-	 * @since 1.0.19
214
-	 * @param  string $context View or edit context.
215
-	 * @return int
216
-	 */
217
-	public function get_parent_invoice_id( $context = 'view' ) {
218
-		return (int) $this->get_prop( 'parent_payment_id', $context );
219
-	}
220
-
221
-	/**
222
-	 * Alias for self::get_parent_invoice_id().
223
-	 *
224
-	 * @since 1.0.19
225
-	 * @param  string $context View or edit context.
226
-	 * @return int
227
-	 */
188
+    /**
189
+     * Get customer id.
190
+     *
191
+     * @since 1.0.19
192
+     * @param  string $context View or edit context.
193
+     * @return int
194
+     */
195
+    public function get_customer_id( $context = 'view' ) {
196
+        return (int) $this->get_prop( 'customer_id', $context );
197
+    }
198
+
199
+    /**
200
+     * Get customer information.
201
+     *
202
+     * @since 1.0.19
203
+     * @param  string $context View or edit context.
204
+     * @return WP_User|false WP_User object on success, false on failure.
205
+     */
206
+    public function get_customer( $context = 'view' ) {
207
+        return get_userdata( $this->get_customer_id( $context ) );
208
+    }
209
+
210
+    /**
211
+     * Get parent invoice id.
212
+     *
213
+     * @since 1.0.19
214
+     * @param  string $context View or edit context.
215
+     * @return int
216
+     */
217
+    public function get_parent_invoice_id( $context = 'view' ) {
218
+        return (int) $this->get_prop( 'parent_payment_id', $context );
219
+    }
220
+
221
+    /**
222
+     * Alias for self::get_parent_invoice_id().
223
+     *
224
+     * @since 1.0.19
225
+     * @param  string $context View or edit context.
226
+     * @return int
227
+     */
228 228
     public function get_parent_payment_id( $context = 'view' ) {
229 229
         return $this->get_parent_invoice_id( $context );
230
-	}
230
+    }
231 231
 
232
-	/**
232
+    /**
233 233
      * Alias for self::get_parent_invoice_id().
234 234
      *
235 235
      * @since  1.0.0
@@ -239,390 +239,390 @@  discard block
 block discarded – undo
239 239
         return $this->get_parent_invoice_id( $context );
240 240
     }
241 241
 
242
-	/**
243
-	 * Get parent invoice.
244
-	 *
245
-	 * @since 1.0.19
246
-	 * @param  string $context View or edit context.
247
-	 * @return WPInv_Invoice
248
-	 */
249
-	public function get_parent_invoice( $context = 'view' ) {
250
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
251
-	}
252
-
253
-	/**
254
-	 * Alias for self::get_parent_invoice().
255
-	 *
256
-	 * @since 1.0.19
257
-	 * @param  string $context View or edit context.
258
-	 * @return WPInv_Invoice
259
-	 */
242
+    /**
243
+     * Get parent invoice.
244
+     *
245
+     * @since 1.0.19
246
+     * @param  string $context View or edit context.
247
+     * @return WPInv_Invoice
248
+     */
249
+    public function get_parent_invoice( $context = 'view' ) {
250
+        return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
251
+    }
252
+
253
+    /**
254
+     * Alias for self::get_parent_invoice().
255
+     *
256
+     * @since 1.0.19
257
+     * @param  string $context View or edit context.
258
+     * @return WPInv_Invoice
259
+     */
260 260
     public function get_parent_payment( $context = 'view' ) {
261 261
         return $this->get_parent_invoice( $context );
262
-	}
263
-
264
-	/**
265
-	 * Get subscription's product id.
266
-	 *
267
-	 * @since 1.0.19
268
-	 * @param  string $context View or edit context.
269
-	 * @return int
270
-	 */
271
-	public function get_product_id( $context = 'view' ) {
272
-		return (int) $this->get_prop( 'product_id', $context );
273
-	}
274
-
275
-	/**
276
-	 * Get the subscription product.
277
-	 *
278
-	 * @since 1.0.19
279
-	 * @param  string $context View or edit context.
280
-	 * @return WPInv_Item
281
-	 */
282
-	public function get_product( $context = 'view' ) {
283
-		return new WPInv_Item( $this->get_product_id( $context ) );
284
-	}
285
-
286
-	/**
287
-	 * Get parent invoice's gateway.
288
-	 *
289
-	 * Here for backwards compatibility.
290
-	 *
291
-	 * @since 1.0.19
292
-	 * @param  string $context View or edit context.
293
-	 * @return string
294
-	 */
295
-	public function get_gateway( $context = 'view' ) {
296
-		return $this->get_parent_invoice( $context )->get_gateway();
297
-	}
298
-
299
-	/**
300
-	 * Get the period of a renewal.
301
-	 *
302
-	 * @since 1.0.19
303
-	 * @param  string $context View or edit context.
304
-	 * @return string
305
-	 */
306
-	public function get_period( $context = 'view' ) {
307
-		return $this->get_prop( 'period', $context );
308
-	}
309
-
310
-	/**
311
-	 * Get number of periods each renewal is valid for.
312
-	 *
313
-	 * @since 1.0.19
314
-	 * @param  string $context View or edit context.
315
-	 * @return int
316
-	 */
317
-	public function get_frequency( $context = 'view' ) {
318
-		return (int) $this->get_prop( 'frequency', $context );
319
-	}
320
-
321
-	/**
322
-	 * Get the initial amount for the subscription.
323
-	 *
324
-	 * @since 1.0.19
325
-	 * @param  string $context View or edit context.
326
-	 * @return float
327
-	 */
328
-	public function get_initial_amount( $context = 'view' ) {
329
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
330
-	}
331
-
332
-	/**
333
-	 * Get the recurring amount for the subscription.
334
-	 *
335
-	 * @since 1.0.19
336
-	 * @param  string $context View or edit context.
337
-	 * @return float
338
-	 */
339
-	public function get_recurring_amount( $context = 'view' ) {
340
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
341
-	}
342
-
343
-	/**
344
-	 * Get number of times that this subscription can be renewed.
345
-	 *
346
-	 * @since 1.0.19
347
-	 * @param  string $context View or edit context.
348
-	 * @return int
349
-	 */
350
-	public function get_bill_times( $context = 'view' ) {
351
-		return (int) $this->get_prop( 'bill_times', $context );
352
-	}
353
-
354
-	/**
355
-	 * Get transaction id of this subscription's parent invoice.
356
-	 *
357
-	 * @since 1.0.19
358
-	 * @param  string $context View or edit context.
359
-	 * @return string
360
-	 */
361
-	public function get_transaction_id( $context = 'view' ) {
362
-		return $this->get_prop( 'transaction_id', $context );
363
-	}
364
-
365
-	/**
366
-	 * Get the date that the subscription was created.
367
-	 *
368
-	 * @since 1.0.19
369
-	 * @param  string $context View or edit context.
370
-	 * @return string
371
-	 */
372
-	public function get_created( $context = 'view' ) {
373
-		return $this->get_prop( 'created', $context );
374
-	}
375
-
376
-	/**
377
-	 * Alias for self::get_created().
378
-	 *
379
-	 * @since 1.0.19
380
-	 * @param  string $context View or edit context.
381
-	 * @return string
382
-	 */
383
-	public function get_date_created( $context = 'view' ) {
384
-		return $this->get_created( $context );
385
-	}
386
-
387
-	/**
388
-	 * Retrieves the creation date in a timestamp
389
-	 *
390
-	 * @since  1.0.0
391
-	 * @return int
392
-	 */
393
-	public function get_time_created() {
394
-		$created = $this->get_date_created();
395
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
396
-	}
397
-
398
-	/**
399
-	 * Get GMT date when the subscription was created.
400
-	 *
401
-	 * @since 1.0.19
402
-	 * @param  string $context View or edit context.
403
-	 * @return string
404
-	 */
405
-	public function get_date_created_gmt( $context = 'view' ) {
262
+    }
263
+
264
+    /**
265
+     * Get subscription's product id.
266
+     *
267
+     * @since 1.0.19
268
+     * @param  string $context View or edit context.
269
+     * @return int
270
+     */
271
+    public function get_product_id( $context = 'view' ) {
272
+        return (int) $this->get_prop( 'product_id', $context );
273
+    }
274
+
275
+    /**
276
+     * Get the subscription product.
277
+     *
278
+     * @since 1.0.19
279
+     * @param  string $context View or edit context.
280
+     * @return WPInv_Item
281
+     */
282
+    public function get_product( $context = 'view' ) {
283
+        return new WPInv_Item( $this->get_product_id( $context ) );
284
+    }
285
+
286
+    /**
287
+     * Get parent invoice's gateway.
288
+     *
289
+     * Here for backwards compatibility.
290
+     *
291
+     * @since 1.0.19
292
+     * @param  string $context View or edit context.
293
+     * @return string
294
+     */
295
+    public function get_gateway( $context = 'view' ) {
296
+        return $this->get_parent_invoice( $context )->get_gateway();
297
+    }
298
+
299
+    /**
300
+     * Get the period of a renewal.
301
+     *
302
+     * @since 1.0.19
303
+     * @param  string $context View or edit context.
304
+     * @return string
305
+     */
306
+    public function get_period( $context = 'view' ) {
307
+        return $this->get_prop( 'period', $context );
308
+    }
309
+
310
+    /**
311
+     * Get number of periods each renewal is valid for.
312
+     *
313
+     * @since 1.0.19
314
+     * @param  string $context View or edit context.
315
+     * @return int
316
+     */
317
+    public function get_frequency( $context = 'view' ) {
318
+        return (int) $this->get_prop( 'frequency', $context );
319
+    }
320
+
321
+    /**
322
+     * Get the initial amount for the subscription.
323
+     *
324
+     * @since 1.0.19
325
+     * @param  string $context View or edit context.
326
+     * @return float
327
+     */
328
+    public function get_initial_amount( $context = 'view' ) {
329
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
330
+    }
331
+
332
+    /**
333
+     * Get the recurring amount for the subscription.
334
+     *
335
+     * @since 1.0.19
336
+     * @param  string $context View or edit context.
337
+     * @return float
338
+     */
339
+    public function get_recurring_amount( $context = 'view' ) {
340
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
341
+    }
342
+
343
+    /**
344
+     * Get number of times that this subscription can be renewed.
345
+     *
346
+     * @since 1.0.19
347
+     * @param  string $context View or edit context.
348
+     * @return int
349
+     */
350
+    public function get_bill_times( $context = 'view' ) {
351
+        return (int) $this->get_prop( 'bill_times', $context );
352
+    }
353
+
354
+    /**
355
+     * Get transaction id of this subscription's parent invoice.
356
+     *
357
+     * @since 1.0.19
358
+     * @param  string $context View or edit context.
359
+     * @return string
360
+     */
361
+    public function get_transaction_id( $context = 'view' ) {
362
+        return $this->get_prop( 'transaction_id', $context );
363
+    }
364
+
365
+    /**
366
+     * Get the date that the subscription was created.
367
+     *
368
+     * @since 1.0.19
369
+     * @param  string $context View or edit context.
370
+     * @return string
371
+     */
372
+    public function get_created( $context = 'view' ) {
373
+        return $this->get_prop( 'created', $context );
374
+    }
375
+
376
+    /**
377
+     * Alias for self::get_created().
378
+     *
379
+     * @since 1.0.19
380
+     * @param  string $context View or edit context.
381
+     * @return string
382
+     */
383
+    public function get_date_created( $context = 'view' ) {
384
+        return $this->get_created( $context );
385
+    }
386
+
387
+    /**
388
+     * Retrieves the creation date in a timestamp
389
+     *
390
+     * @since  1.0.0
391
+     * @return int
392
+     */
393
+    public function get_time_created() {
394
+        $created = $this->get_date_created();
395
+        return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
396
+    }
397
+
398
+    /**
399
+     * Get GMT date when the subscription was created.
400
+     *
401
+     * @since 1.0.19
402
+     * @param  string $context View or edit context.
403
+     * @return string
404
+     */
405
+    public function get_date_created_gmt( $context = 'view' ) {
406 406
         $date = $this->get_date_created( $context );
407 407
 
408 408
         if ( $date ) {
409 409
             $date = get_gmt_from_date( $date );
410 410
         }
411
-		return $date;
412
-	}
413
-
414
-	/**
415
-	 * Get the date that the subscription will renew.
416
-	 *
417
-	 * @since 1.0.19
418
-	 * @param  string $context View or edit context.
419
-	 * @return string
420
-	 */
421
-	public function get_next_renewal_date( $context = 'view' ) {
422
-		return $this->get_prop( 'expiration', $context );
423
-	}
424
-
425
-	/**
426
-	 * Alias for self::get_next_renewal_date().
427
-	 *
428
-	 * @since 1.0.19
429
-	 * @param  string $context View or edit context.
430
-	 * @return string
431
-	 */
432
-	public function get_expiration( $context = 'view' ) {
433
-		return $this->get_next_renewal_date( $context );
434
-	}
435
-
436
-	/**
437
-	 * Retrieves the expiration date in a timestamp
438
-	 *
439
-	 * @since  1.0.0
440
-	 * @return int
441
-	 */
442
-	public function get_expiration_time() {
443
-		$expiration = $this->get_expiration();
444
-
445
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
446
-			return current_time( 'timestamp' );
447
-		}
448
-
449
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
450
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
451
-	}
452
-
453
-	/**
454
-	 * Get GMT date when the subscription will renew.
455
-	 *
456
-	 * @since 1.0.19
457
-	 * @param  string $context View or edit context.
458
-	 * @return string
459
-	 */
460
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
411
+        return $date;
412
+    }
413
+
414
+    /**
415
+     * Get the date that the subscription will renew.
416
+     *
417
+     * @since 1.0.19
418
+     * @param  string $context View or edit context.
419
+     * @return string
420
+     */
421
+    public function get_next_renewal_date( $context = 'view' ) {
422
+        return $this->get_prop( 'expiration', $context );
423
+    }
424
+
425
+    /**
426
+     * Alias for self::get_next_renewal_date().
427
+     *
428
+     * @since 1.0.19
429
+     * @param  string $context View or edit context.
430
+     * @return string
431
+     */
432
+    public function get_expiration( $context = 'view' ) {
433
+        return $this->get_next_renewal_date( $context );
434
+    }
435
+
436
+    /**
437
+     * Retrieves the expiration date in a timestamp
438
+     *
439
+     * @since  1.0.0
440
+     * @return int
441
+     */
442
+    public function get_expiration_time() {
443
+        $expiration = $this->get_expiration();
444
+
445
+        if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
446
+            return current_time( 'timestamp' );
447
+        }
448
+
449
+        $expiration = strtotime( $expiration, current_time( 'timestamp' ) );
450
+        return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
451
+    }
452
+
453
+    /**
454
+     * Get GMT date when the subscription will renew.
455
+     *
456
+     * @since 1.0.19
457
+     * @param  string $context View or edit context.
458
+     * @return string
459
+     */
460
+    public function get_next_renewal_date_gmt( $context = 'view' ) {
461 461
         $date = $this->get_next_renewal_date( $context );
462 462
 
463 463
         if ( $date ) {
464 464
             $date = get_gmt_from_date( $date );
465 465
         }
466
-		return $date;
467
-	}
468
-
469
-	/**
470
-	 * Get the subscription's trial period.
471
-	 *
472
-	 * @since 1.0.19
473
-	 * @param  string $context View or edit context.
474
-	 * @return string
475
-	 */
476
-	public function get_trial_period( $context = 'view' ) {
477
-		return $this->get_prop( 'trial_period', $context );
478
-	}
479
-
480
-	/**
481
-	 * Get the subscription's status.
482
-	 *
483
-	 * @since 1.0.19
484
-	 * @param  string $context View or edit context.
485
-	 * @return string
486
-	 */
487
-	public function get_status( $context = 'view' ) {
488
-		return $this->get_prop( 'status', $context );
489
-	}
490
-
491
-	/**
492
-	 * Get the subscription's profile id.
493
-	 *
494
-	 * @since 1.0.19
495
-	 * @param  string $context View or edit context.
496
-	 * @return string
497
-	 */
498
-	public function get_profile_id( $context = 'view' ) {
499
-		return $this->get_prop( 'profile_id', $context );
500
-	}
501
-
502
-	/*
466
+        return $date;
467
+    }
468
+
469
+    /**
470
+     * Get the subscription's trial period.
471
+     *
472
+     * @since 1.0.19
473
+     * @param  string $context View or edit context.
474
+     * @return string
475
+     */
476
+    public function get_trial_period( $context = 'view' ) {
477
+        return $this->get_prop( 'trial_period', $context );
478
+    }
479
+
480
+    /**
481
+     * Get the subscription's status.
482
+     *
483
+     * @since 1.0.19
484
+     * @param  string $context View or edit context.
485
+     * @return string
486
+     */
487
+    public function get_status( $context = 'view' ) {
488
+        return $this->get_prop( 'status', $context );
489
+    }
490
+
491
+    /**
492
+     * Get the subscription's profile id.
493
+     *
494
+     * @since 1.0.19
495
+     * @param  string $context View or edit context.
496
+     * @return string
497
+     */
498
+    public function get_profile_id( $context = 'view' ) {
499
+        return $this->get_prop( 'profile_id', $context );
500
+    }
501
+
502
+    /*
503 503
 	|--------------------------------------------------------------------------
504 504
 	| Setters
505 505
 	|--------------------------------------------------------------------------
506 506
 	*/
507 507
 
508
-	/**
509
-	 * Set customer id.
510
-	 *
511
-	 * @since 1.0.19
512
-	 * @param  int $value The customer's id.
513
-	 */
514
-	public function set_customer_id( $value ) {
515
-		$this->set_prop( 'customer_id', (int) $value );
516
-	}
517
-
518
-	/**
519
-	 * Set parent invoice id.
520
-	 *
521
-	 * @since 1.0.19
522
-	 * @param  int $value The parent invoice id.
523
-	 */
524
-	public function set_parent_invoice_id( $value ) {
525
-		$this->set_prop( 'parent_payment_id', (int) $value );
526
-	}
527
-
528
-	/**
529
-	 * Alias for self::set_parent_invoice_id().
530
-	 *
531
-	 * @since 1.0.19
532
-	 * @param  int $value The parent invoice id.
533
-	 */
508
+    /**
509
+     * Set customer id.
510
+     *
511
+     * @since 1.0.19
512
+     * @param  int $value The customer's id.
513
+     */
514
+    public function set_customer_id( $value ) {
515
+        $this->set_prop( 'customer_id', (int) $value );
516
+    }
517
+
518
+    /**
519
+     * Set parent invoice id.
520
+     *
521
+     * @since 1.0.19
522
+     * @param  int $value The parent invoice id.
523
+     */
524
+    public function set_parent_invoice_id( $value ) {
525
+        $this->set_prop( 'parent_payment_id', (int) $value );
526
+    }
527
+
528
+    /**
529
+     * Alias for self::set_parent_invoice_id().
530
+     *
531
+     * @since 1.0.19
532
+     * @param  int $value The parent invoice id.
533
+     */
534 534
     public function set_parent_payment_id( $value ) {
535 535
         $this->set_parent_invoice_id( $value );
536
-	}
536
+    }
537 537
 
538
-	/**
538
+    /**
539 539
      * Alias for self::set_parent_invoice_id().
540 540
      *
541 541
      * @since 1.0.19
542
-	 * @param  int $value The parent invoice id.
542
+     * @param  int $value The parent invoice id.
543 543
      */
544 544
     public function set_original_payment_id( $value ) {
545 545
         $this->set_parent_invoice_id( $value );
546
-	}
547
-
548
-	/**
549
-	 * Set subscription's product id.
550
-	 *
551
-	 * @since 1.0.19
552
-	 * @param  int $value The subscription product id.
553
-	 */
554
-	public function set_product_id( $value ) {
555
-		$this->set_prop( 'product_id', (int) $value );
556
-	}
557
-
558
-	/**
559
-	 * Set the period of a renewal.
560
-	 *
561
-	 * @since 1.0.19
562
-	 * @param  string $value The renewal period.
563
-	 */
564
-	public function set_period( $value ) {
565
-		$this->set_prop( 'period', $value );
566
-	}
567
-
568
-	/**
569
-	 * Set number of periods each renewal is valid for.
570
-	 *
571
-	 * @since 1.0.19
572
-	 * @param  int $value The subscription frequency.
573
-	 */
574
-	public function set_frequency( $value ) {
575
-		$value = empty( $value ) ? 1 : (int) $value;
576
-		$this->set_prop( 'frequency', absint( $value ) );
577
-	}
578
-
579
-	/**
580
-	 * Set the initial amount for the subscription.
581
-	 *
582
-	 * @since 1.0.19
583
-	 * @param  float $value The initial subcription amount.
584
-	 */
585
-	public function set_initial_amount( $value ) {
586
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
587
-	}
588
-
589
-	/**
590
-	 * Set the recurring amount for the subscription.
591
-	 *
592
-	 * @since 1.0.19
593
-	 * @param  float $value The recurring subcription amount.
594
-	 */
595
-	public function set_recurring_amount( $value ) {
596
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
597
-	}
598
-
599
-	/**
600
-	 * Set number of times that this subscription can be renewed.
601
-	 *
602
-	 * @since 1.0.19
603
-	 * @param  int $value Bill times.
604
-	 */
605
-	public function set_bill_times( $value ) {
606
-		$this->set_prop( 'bill_times', (int) $value );
607
-	}
608
-
609
-	/**
610
-	 * Get transaction id of this subscription's parent invoice.
611
-	 *
612
-	 * @since 1.0.19
613
-	 * @param string $value Bill times.
614
-	 */
615
-	public function set_transaction_id( $value ) {
616
-		$this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
617
-	}
618
-
619
-	/**
620
-	 * Set date when this subscription started.
621
-	 *
622
-	 * @since 1.0.19
623
-	 * @param string $value strtotime compliant date.
624
-	 */
625
-	public function set_created( $value ) {
546
+    }
547
+
548
+    /**
549
+     * Set subscription's product id.
550
+     *
551
+     * @since 1.0.19
552
+     * @param  int $value The subscription product id.
553
+     */
554
+    public function set_product_id( $value ) {
555
+        $this->set_prop( 'product_id', (int) $value );
556
+    }
557
+
558
+    /**
559
+     * Set the period of a renewal.
560
+     *
561
+     * @since 1.0.19
562
+     * @param  string $value The renewal period.
563
+     */
564
+    public function set_period( $value ) {
565
+        $this->set_prop( 'period', $value );
566
+    }
567
+
568
+    /**
569
+     * Set number of periods each renewal is valid for.
570
+     *
571
+     * @since 1.0.19
572
+     * @param  int $value The subscription frequency.
573
+     */
574
+    public function set_frequency( $value ) {
575
+        $value = empty( $value ) ? 1 : (int) $value;
576
+        $this->set_prop( 'frequency', absint( $value ) );
577
+    }
578
+
579
+    /**
580
+     * Set the initial amount for the subscription.
581
+     *
582
+     * @since 1.0.19
583
+     * @param  float $value The initial subcription amount.
584
+     */
585
+    public function set_initial_amount( $value ) {
586
+        $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
587
+    }
588
+
589
+    /**
590
+     * Set the recurring amount for the subscription.
591
+     *
592
+     * @since 1.0.19
593
+     * @param  float $value The recurring subcription amount.
594
+     */
595
+    public function set_recurring_amount( $value ) {
596
+        $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
597
+    }
598
+
599
+    /**
600
+     * Set number of times that this subscription can be renewed.
601
+     *
602
+     * @since 1.0.19
603
+     * @param  int $value Bill times.
604
+     */
605
+    public function set_bill_times( $value ) {
606
+        $this->set_prop( 'bill_times', (int) $value );
607
+    }
608
+
609
+    /**
610
+     * Get transaction id of this subscription's parent invoice.
611
+     *
612
+     * @since 1.0.19
613
+     * @param string $value Bill times.
614
+     */
615
+    public function set_transaction_id( $value ) {
616
+        $this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
617
+    }
618
+
619
+    /**
620
+     * Set date when this subscription started.
621
+     *
622
+     * @since 1.0.19
623
+     * @param string $value strtotime compliant date.
624
+     */
625
+    public function set_created( $value ) {
626 626
         $date = strtotime( $value );
627 627
 
628 628
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -630,94 +630,94 @@  discard block
 block discarded – undo
630 630
             return;
631 631
         }
632 632
 
633
-		$this->set_prop( 'created', '' );
633
+        $this->set_prop( 'created', '' );
634 634
 
635
-	}
635
+    }
636 636
 
637
-	/**
638
-	 * Alias for self::set_created().
639
-	 *
640
-	 * @since 1.0.19
641
-	 * @param string $value strtotime compliant date.
642
-	 */
643
-	public function set_date_created( $value ) {
644
-		$this->set_created( $value );
637
+    /**
638
+     * Alias for self::set_created().
639
+     *
640
+     * @since 1.0.19
641
+     * @param string $value strtotime compliant date.
642
+     */
643
+    public function set_date_created( $value ) {
644
+        $this->set_created( $value );
645 645
     }
646 646
 
647
-	/**
648
-	 * Set the date that the subscription will renew.
649
-	 *
650
-	 * @since 1.0.19
651
-	 * @param string $value strtotime compliant date.
652
-	 */
653
-	public function set_next_renewal_date( $value ) {
654
-		$date = strtotime( $value );
647
+    /**
648
+     * Set the date that the subscription will renew.
649
+     *
650
+     * @since 1.0.19
651
+     * @param string $value strtotime compliant date.
652
+     */
653
+    public function set_next_renewal_date( $value ) {
654
+        $date = strtotime( $value );
655 655
 
656 656
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
657 657
             $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
658 658
             return;
659
-		}
660
-
661
-		$this->set_prop( 'expiration', '' );
662
-
663
-	}
664
-
665
-	/**
666
-	 * Alias for self::set_next_renewal_date().
667
-	 *
668
-	 * @since 1.0.19
669
-	 * @param string $value strtotime compliant date.
670
-	 */
671
-	public function set_expiration( $value ) {
672
-		$this->set_next_renewal_date( $value );
673
-    }
674
-
675
-	/**
676
-	 * Set the subscription's trial period.
677
-	 *
678
-	 * @since 1.0.19
679
-	 * @param string $value trial period e.g 1 year.
680
-	 */
681
-	public function set_trial_period( $value ) {
682
-		$this->set_prop( 'trial_period', $value );
683
-	}
684
-
685
-	/**
686
-	 * Set the subscription's status.
687
-	 *
688
-	 * @since 1.0.19
689
-	 * @param string $new_status    New subscription status.
690
-	 */
691
-	public function set_status( $new_status ) {
692
-
693
-		// Abort if this is not a valid status;
694
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
695
-			return;
696
-		}
697
-
698
-		$old_status = $this->get_status();
699
-		$this->set_prop( 'status', $new_status );
700
-
701
-		if ( true === $this->object_read && $old_status !== $new_status ) {
702
-			$this->status_transition = array(
703
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
704
-				'to'     => $new_status,
705
-			);
706
-		}
707
-
708
-	}
709
-
710
-	/**
711
-	 * Set the subscription's (remote) profile id.
712
-	 *
713
-	 * @since 1.0.19
714
-	 * @param  string $value the remote profile id.
715
-	 */
716
-	public function set_profile_id( $value ) {
717
-		$this->set_prop( 'profile_id', sanitize_text_field( $value ) );
718
-	}
719
-
720
-	/*
659
+        }
660
+
661
+        $this->set_prop( 'expiration', '' );
662
+
663
+    }
664
+
665
+    /**
666
+     * Alias for self::set_next_renewal_date().
667
+     *
668
+     * @since 1.0.19
669
+     * @param string $value strtotime compliant date.
670
+     */
671
+    public function set_expiration( $value ) {
672
+        $this->set_next_renewal_date( $value );
673
+    }
674
+
675
+    /**
676
+     * Set the subscription's trial period.
677
+     *
678
+     * @since 1.0.19
679
+     * @param string $value trial period e.g 1 year.
680
+     */
681
+    public function set_trial_period( $value ) {
682
+        $this->set_prop( 'trial_period', $value );
683
+    }
684
+
685
+    /**
686
+     * Set the subscription's status.
687
+     *
688
+     * @since 1.0.19
689
+     * @param string $new_status    New subscription status.
690
+     */
691
+    public function set_status( $new_status ) {
692
+
693
+        // Abort if this is not a valid status;
694
+        if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
695
+            return;
696
+        }
697
+
698
+        $old_status = $this->get_status();
699
+        $this->set_prop( 'status', $new_status );
700
+
701
+        if ( true === $this->object_read && $old_status !== $new_status ) {
702
+            $this->status_transition = array(
703
+                'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
704
+                'to'     => $new_status,
705
+            );
706
+        }
707
+
708
+    }
709
+
710
+    /**
711
+     * Set the subscription's (remote) profile id.
712
+     *
713
+     * @since 1.0.19
714
+     * @param  string $value the remote profile id.
715
+     */
716
+    public function set_profile_id( $value ) {
717
+        $this->set_prop( 'profile_id', sanitize_text_field( $value ) );
718
+    }
719
+
720
+    /*
721 721
 	|--------------------------------------------------------------------------
722 722
 	| Boolean methods
723 723
 	|--------------------------------------------------------------------------
@@ -726,45 +726,45 @@  discard block
 block discarded – undo
726 726
 	|
727 727
 	*/
728 728
 
729
-	/**
729
+    /**
730 730
      * Checks if the subscription has a given status.
731
-	 *
732
-	 * @param string|array String or array of strings to check for.
733
-	 * @return bool
731
+     *
732
+     * @param string|array String or array of strings to check for.
733
+     * @return bool
734 734
      */
735 735
     public function has_status( $status ) {
736 736
         return in_array( $this->get_status(), wpinv_parse_list( $status ) );
737
-	}
737
+    }
738 738
 
739
-	/**
739
+    /**
740 740
      * Checks if the subscription has a trial period.
741
-	 *
742
-	 * @return bool
741
+     *
742
+     * @return bool
743 743
      */
744 744
     public function has_trial_period() {
745
-		$period = $this->get_trial_period();
745
+        $period = $this->get_trial_period();
746 746
         return ! empty( $period );
747
-	}
748
-
749
-	/**
750
-	 * Is the subscription active?
751
-	 *
752
-	 * @return bool
753
-	 */
754
-	public function is_active() {
755
-		return $this->has_status( 'active trialling' ) && $this->get_expiration_time() > current_time( 'mysql' );
756
-	}
757
-
758
-	/**
759
-	 * Is the subscription expired?
760
-	 *
761
-	 * @return bool
762
-	 */
763
-	public function is_expired() {
764
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
765
-	}
766
-
767
-	/*
747
+    }
748
+
749
+    /**
750
+     * Is the subscription active?
751
+     *
752
+     * @return bool
753
+     */
754
+    public function is_active() {
755
+        return $this->has_status( 'active trialling' ) && $this->get_expiration_time() > current_time( 'mysql' );
756
+    }
757
+
758
+    /**
759
+     * Is the subscription expired?
760
+     *
761
+     * @return bool
762
+     */
763
+    public function is_expired() {
764
+        return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
765
+    }
766
+
767
+    /*
768 768
 	|--------------------------------------------------------------------------
769 769
 	| Additional methods
770 770
 	|--------------------------------------------------------------------------
@@ -773,27 +773,27 @@  discard block
 block discarded – undo
773 773
 	|
774 774
 	*/
775 775
 
776
-	/**
777
-	 * Backwards compatibilty.
778
-	 */
779
-	public function create( $data = array() ) {
776
+    /**
777
+     * Backwards compatibilty.
778
+     */
779
+    public function create( $data = array() ) {
780 780
 
781
-		// Set the properties.
782
-		if ( is_array( $data ) ) {
783
-			$this->set_props( $data );
784
-		}
781
+        // Set the properties.
782
+        if ( is_array( $data ) ) {
783
+            $this->set_props( $data );
784
+        }
785 785
 
786
-		// Save the item.
787
-		return $this->save();
786
+        // Save the item.
787
+        return $this->save();
788 788
 
789
-	}
789
+    }
790 790
 
791
-	/**
792
-	 * Backwards compatibilty.
793
-	 */
794
-	public function update( $args = array() ) {
795
-		return $this->create( $args );
796
-	}
791
+    /**
792
+     * Backwards compatibilty.
793
+     */
794
+    public function update( $args = array() ) {
795
+        return $this->create( $args );
796
+    }
797 797
 
798 798
     /**
799 799
      * Retrieve renewal payments for a subscription
@@ -803,15 +803,15 @@  discard block
 block discarded – undo
803 803
      */
804 804
     public function get_child_payments() {
805 805
         return get_posts(
806
-			array(
807
-            	'post_parent'    => $this->get_parent_payment_id(),
808
-            	'numberposts'    => -1,
809
-            	'post_status'    => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
810
-            	'orderby'        => 'ID',
811
-            	'order'          => 'DESC',
812
-            	'post_type'      => 'wpi_invoice'
813
-			)
814
-		);
806
+            array(
807
+                'post_parent'    => $this->get_parent_payment_id(),
808
+                'numberposts'    => -1,
809
+                'post_status'    => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
810
+                'orderby'        => 'ID',
811
+                'order'          => 'DESC',
812
+                'post_type'      => 'wpi_invoice'
813
+            )
814
+        );
815 815
     }
816 816
 
817 817
     /**
@@ -821,16 +821,16 @@  discard block
 block discarded – undo
821 821
      * @return int
822 822
      */
823 823
     public function get_total_payments() {
824
-		global $wpdb;
824
+        global $wpdb;
825 825
 
826
-		$count = $wpdb->get_var(
827
-			$wpdb->prepare(
828
-				"SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
829
-				$this->get_parent_invoice_id()
830
-			)
831
-		);
826
+        $count = $wpdb->get_var(
827
+            $wpdb->prepare(
828
+                "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
829
+                $this->get_parent_invoice_id()
830
+            )
831
+        );
832 832
 
833
-		// Maybe include parent invoice.
833
+        // Maybe include parent invoice.
834 834
         if ( ! $this->has_status( 'pending' ) ) {
835 835
             $count++;
836 836
         }
@@ -859,57 +859,57 @@  discard block
 block discarded – undo
859 859
      *
860 860
      * @since  2.4
861 861
      * @param  array $args Array of values for the payment, including amount and transaction ID
862
-	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
862
+     * @param  WPInv_Invoice $invoice If adding an existing invoice.
863 863
      * @return bool
864 864
      */
865 865
     public function add_payment( $args = array(), $invoice = false ) {
866 866
 
867
-		// Process each payment once.
867
+        // Process each payment once.
868 868
         if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
869 869
             return false;
870 870
         }
871 871
 
872
-		// Are we creating a new invoice?
873
-		if ( empty( $invoice ) ) {
874
-			$invoice = $this->create_payment();
872
+        // Are we creating a new invoice?
873
+        if ( empty( $invoice ) ) {
874
+            $invoice = $this->create_payment();
875 875
 
876
-			if ( empty( $invoice ) ) {
877
-				return false;
878
-			}
876
+            if ( empty( $invoice ) ) {
877
+                return false;
878
+            }
879 879
 
880
-			$invoice->set_status( 'wpi-renewal' );
880
+            $invoice->set_status( 'wpi-renewal' );
881 881
 
882
-		}
882
+        }
883 883
 
884
-		// Maybe set a transaction id.
885
-		if ( ! empty( $args['transaction_id'] ) ) {
886
-			$invoice->set_transaction_id( $args['transaction_id'] );
887
-		}
884
+        // Maybe set a transaction id.
885
+        if ( ! empty( $args['transaction_id'] ) ) {
886
+            $invoice->set_transaction_id( $args['transaction_id'] );
887
+        }
888 888
 
889
-		// Set the completed date.
890
-		$invoice->set_completed_date( current_time( 'mysql' ) );
889
+        // Set the completed date.
890
+        $invoice->set_completed_date( current_time( 'mysql' ) );
891 891
 
892
-		// And the gateway.
893
-		if ( ! empty( $args['gateway'] ) ) {
894
-			$invoice->set_gateway( $args['gateway'] );
895
-		}
892
+        // And the gateway.
893
+        if ( ! empty( $args['gateway'] ) ) {
894
+            $invoice->set_gateway( $args['gateway'] );
895
+        }
896 896
 
897
-		$invoice->save();
897
+        $invoice->save();
898 898
 
899
-		if ( ! $invoice->get_id() ) {
900
-			return 0;
901
-		}
899
+        if ( ! $invoice->get_id() ) {
900
+            return 0;
901
+        }
902 902
 
903
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
904
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
903
+        do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
904
+        do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
905 905
         do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
906 906
 
907 907
         update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
908 908
 
909 909
         return $invoice->get_id();
910
-	}
910
+    }
911 911
 
912
-	/**
912
+    /**
913 913
      * Creates a new invoice and returns it.
914 914
      *
915 915
      * @since  1.0.19
@@ -917,103 +917,103 @@  discard block
 block discarded – undo
917 917
      */
918 918
     public function create_payment() {
919 919
 
920
-		$parent_invoice = $this->get_parent_payment();
921
-
922
-		if ( ! $parent_invoice->get_id() ) {
923
-			return false;
924
-		}
925
-
926
-		// Duplicate the parent invoice.
927
-		$invoice = new WPInv_Invoice();
928
-		$invoice->set_props( $parent_invoice->get_data() );
929
-		$invoice->set_id( 0 );
930
-		$invoice->set_parent_id( $parent_invoice->get_id() );
931
-		$invoice->set_transaction_id( '' );
932
-		$invoice->set_key( $invoice->generate_key( 'renewal_' ) );
933
-		$invoice->set_number( '' );
934
-		$invoice->set_completed_date( '' );
935
-		$invoice->set_status( 'wpi-pending' );
936
-		$invoice->recalculate_total();
937
-		$invoice->save();
938
-
939
-		return $invoice->get_id() ? $invoice : false;
940
-    }
941
-
942
-	/**
943
-	 * Renews or completes a subscription
944
-	 *
945
-	 * @since  1.0.0
946
-	 * @return int The subscription's id
947
-	 */
948
-	public function renew() {
949
-
950
-		// Complete subscription if applicable
951
-		if ( $this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times() ) {
952
-			return $this->complete();
953
-		}
954
-
955
-		// Calculate new expiration
956
-		$frequency      = $this->get_frequency();
957
-		$period         = $this->get_period();
958
-		$new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
959
-
960
-		$this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
961
-		$this->set_status( 'active' );
962
-		return $this->save();
963
-
964
-		do_action( 'getpaid_subscription_renewed', $this );
965
-
966
-	}
967
-
968
-	/**
969
-	 * Marks a subscription as completed
970
-	 *
971
-	 * Subscription is completed when the number of payments matches the billing_times field
972
-	 *
973
-	 * @since  1.0.0
974
-	 * @return int|bool Subscription id or false if the subscription is cancelled.
975
-	 */
976
-	public function complete() {
977
-
978
-		// Only mark a subscription as complete if it's not already cancelled.
979
-		if ( $this->has_status( 'cancelled' ) ) {
980
-			return false;
981
-		}
982
-
983
-		$this->set_status( 'completed' );
984
-		return $this->save();
985
-
986
-	}
987
-
988
-	/**
989
-	 * Marks a subscription as expired
990
-	 *
991
-	 * @since  1.0.0
992
-	 * @param  bool $check_expiration
993
-	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
994
-	 */
995
-	public function expire( $check_expiration = false ) {
996
-
997
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
998
-			// Do not mark as expired since real expiration date is in the future
999
-			return false;
1000
-		}
1001
-
1002
-		$this->set_status( 'expired' );
1003
-		return $this->save();
1004
-
1005
-	}
1006
-
1007
-	/**
1008
-	 * Marks a subscription as failing
1009
-	 *
1010
-	 * @since  2.4.2
1011
-	 * @return int Subscription id.
1012
-	 */
1013
-	public function failing() {
1014
-		$this->set_status( 'failing' );
1015
-		return $this->save();
1016
-	}
920
+        $parent_invoice = $this->get_parent_payment();
921
+
922
+        if ( ! $parent_invoice->get_id() ) {
923
+            return false;
924
+        }
925
+
926
+        // Duplicate the parent invoice.
927
+        $invoice = new WPInv_Invoice();
928
+        $invoice->set_props( $parent_invoice->get_data() );
929
+        $invoice->set_id( 0 );
930
+        $invoice->set_parent_id( $parent_invoice->get_id() );
931
+        $invoice->set_transaction_id( '' );
932
+        $invoice->set_key( $invoice->generate_key( 'renewal_' ) );
933
+        $invoice->set_number( '' );
934
+        $invoice->set_completed_date( '' );
935
+        $invoice->set_status( 'wpi-pending' );
936
+        $invoice->recalculate_total();
937
+        $invoice->save();
938
+
939
+        return $invoice->get_id() ? $invoice : false;
940
+    }
941
+
942
+    /**
943
+     * Renews or completes a subscription
944
+     *
945
+     * @since  1.0.0
946
+     * @return int The subscription's id
947
+     */
948
+    public function renew() {
949
+
950
+        // Complete subscription if applicable
951
+        if ( $this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times() ) {
952
+            return $this->complete();
953
+        }
954
+
955
+        // Calculate new expiration
956
+        $frequency      = $this->get_frequency();
957
+        $period         = $this->get_period();
958
+        $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
959
+
960
+        $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
961
+        $this->set_status( 'active' );
962
+        return $this->save();
963
+
964
+        do_action( 'getpaid_subscription_renewed', $this );
965
+
966
+    }
967
+
968
+    /**
969
+     * Marks a subscription as completed
970
+     *
971
+     * Subscription is completed when the number of payments matches the billing_times field
972
+     *
973
+     * @since  1.0.0
974
+     * @return int|bool Subscription id or false if the subscription is cancelled.
975
+     */
976
+    public function complete() {
977
+
978
+        // Only mark a subscription as complete if it's not already cancelled.
979
+        if ( $this->has_status( 'cancelled' ) ) {
980
+            return false;
981
+        }
982
+
983
+        $this->set_status( 'completed' );
984
+        return $this->save();
985
+
986
+    }
987
+
988
+    /**
989
+     * Marks a subscription as expired
990
+     *
991
+     * @since  1.0.0
992
+     * @param  bool $check_expiration
993
+     * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
994
+     */
995
+    public function expire( $check_expiration = false ) {
996
+
997
+        if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
998
+            // Do not mark as expired since real expiration date is in the future
999
+            return false;
1000
+        }
1001
+
1002
+        $this->set_status( 'expired' );
1003
+        return $this->save();
1004
+
1005
+    }
1006
+
1007
+    /**
1008
+     * Marks a subscription as failing
1009
+     *
1010
+     * @since  2.4.2
1011
+     * @return int Subscription id.
1012
+     */
1013
+    public function failing() {
1014
+        $this->set_status( 'failing' );
1015
+        return $this->save();
1016
+    }
1017 1017
 
1018 1018
     /**
1019 1019
      * Marks a subscription as cancelled
@@ -1022,19 +1022,19 @@  discard block
 block discarded – undo
1022 1022
      * @return int Subscription id.
1023 1023
      */
1024 1024
     public function cancel() {
1025
-		$this->set_status( 'cancelled' );
1026
-		return $this->save();
1025
+        $this->set_status( 'cancelled' );
1026
+        return $this->save();
1027 1027
     }
1028 1028
 
1029
-	/**
1030
-	 * Determines if a subscription can be cancelled both locally and with a payment processor.
1031
-	 *
1032
-	 * @since  1.0.0
1033
-	 * @return bool
1034
-	 */
1035
-	public function can_cancel() {
1036
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1037
-	}
1029
+    /**
1030
+     * Determines if a subscription can be cancelled both locally and with a payment processor.
1031
+     *
1032
+     * @since  1.0.0
1033
+     * @return bool
1034
+     */
1035
+    public function can_cancel() {
1036
+        return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1037
+    }
1038 1038
 
1039 1039
     /**
1040 1040
      * Returns an array of subscription statuses that can be cancelled
@@ -1047,82 +1047,82 @@  discard block
 block discarded – undo
1047 1047
         return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1048 1048
     }
1049 1049
 
1050
-	/**
1051
-	 * Retrieves the URL to cancel subscription
1052
-	 *
1053
-	 * @since  1.0.0
1054
-	 * @return string
1055
-	 */
1056
-	public function get_cancel_url() {
1057
-		$url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->get_id() ) ), 'wpinv-recurring-cancel' );
1058
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1059
-	}
1060
-
1061
-	/**
1062
-	 * Determines if subscription can be manually renewed
1063
-	 *
1064
-	 * This method is filtered by payment gateways in order to return true on subscriptions
1065
-	 * that can be renewed manually
1066
-	 *
1067
-	 * @since  2.5
1068
-	 * @return bool
1069
-	 */
1070
-	public function can_renew() {
1071
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1072
-	}
1073
-
1074
-	/**
1075
-	 * Retrieves the URL to renew a subscription
1076
-	 *
1077
-	 * @since  2.5
1078
-	 * @return string
1079
-	 */
1080
-	public function get_renew_url() {
1081
-		$url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'wpinv-recurring-renew' );
1082
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1083
-	}
1084
-
1085
-	/**
1086
-	 * Determines if subscription can have their payment method updated
1087
-	 *
1088
-	 * @since  1.0.0
1089
-	 * @return bool
1090
-	 */
1091
-	public function can_update() {
1092
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1093
-	}
1094
-
1095
-	/**
1096
-	 * Retrieves the URL to update subscription
1097
-	 *
1098
-	 * @since  1.0.0
1099
-	 * @return string
1100
-	 */
1101
-	public function get_update_url() {
1102
-		$url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1103
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1104
-	}
1105
-
1106
-	/**
1107
-	 * Retrieves the subscription status label
1108
-	 *
1109
-	 * @since  1.0.0
1110
-	 * @return string
1111
-	 */
1112
-	public function get_status_label() {
1113
-		return getpaid_get_subscription_status_label( $this->get_status() );
1114
-	}
1115
-
1116
-	/**
1117
-	 * Retrieves the subscription status class
1118
-	 *
1119
-	 * @since  1.0.19
1120
-	 * @return string
1121
-	 */
1122
-	public function get_status_class() {
1123
-		$statuses = getpaid_get_subscription_status_classes();
1124
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary';
1125
-	}
1050
+    /**
1051
+     * Retrieves the URL to cancel subscription
1052
+     *
1053
+     * @since  1.0.0
1054
+     * @return string
1055
+     */
1056
+    public function get_cancel_url() {
1057
+        $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->get_id() ) ), 'wpinv-recurring-cancel' );
1058
+        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1059
+    }
1060
+
1061
+    /**
1062
+     * Determines if subscription can be manually renewed
1063
+     *
1064
+     * This method is filtered by payment gateways in order to return true on subscriptions
1065
+     * that can be renewed manually
1066
+     *
1067
+     * @since  2.5
1068
+     * @return bool
1069
+     */
1070
+    public function can_renew() {
1071
+        return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1072
+    }
1073
+
1074
+    /**
1075
+     * Retrieves the URL to renew a subscription
1076
+     *
1077
+     * @since  2.5
1078
+     * @return string
1079
+     */
1080
+    public function get_renew_url() {
1081
+        $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'wpinv-recurring-renew' );
1082
+        return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1083
+    }
1084
+
1085
+    /**
1086
+     * Determines if subscription can have their payment method updated
1087
+     *
1088
+     * @since  1.0.0
1089
+     * @return bool
1090
+     */
1091
+    public function can_update() {
1092
+        return apply_filters( 'wpinv_subscription_can_update', false, $this );
1093
+    }
1094
+
1095
+    /**
1096
+     * Retrieves the URL to update subscription
1097
+     *
1098
+     * @since  1.0.0
1099
+     * @return string
1100
+     */
1101
+    public function get_update_url() {
1102
+        $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1103
+        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1104
+    }
1105
+
1106
+    /**
1107
+     * Retrieves the subscription status label
1108
+     *
1109
+     * @since  1.0.0
1110
+     * @return string
1111
+     */
1112
+    public function get_status_label() {
1113
+        return getpaid_get_subscription_status_label( $this->get_status() );
1114
+    }
1115
+
1116
+    /**
1117
+     * Retrieves the subscription status class
1118
+     *
1119
+     * @since  1.0.19
1120
+     * @return string
1121
+     */
1122
+    public function get_status_class() {
1123
+        $statuses = getpaid_get_subscription_status_classes();
1124
+        return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary';
1125
+    }
1126 1126
 
1127 1127
     /**
1128 1128
      * Retrieves the subscription status label
@@ -1132,11 +1132,11 @@  discard block
 block discarded – undo
1132 1132
      */
1133 1133
     public function get_status_label_html() {
1134 1134
 
1135
-		$status_label = sanitize_text_field( $this->get_status_label() );
1136
-		$class        = esc_attr( $this->get_status_class() );
1137
-		$status       = sanitize_html_class( $this->get_status_label() );
1135
+        $status_label = sanitize_text_field( $this->get_status_label() );
1136
+        $class        = esc_attr( $this->get_status_class() );
1137
+        $status       = sanitize_html_class( $this->get_status_label() );
1138 1138
 
1139
-		return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>";
1139
+        return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>";
1140 1140
     }
1141 1141
 
1142 1142
     /**
@@ -1147,63 +1147,63 @@  discard block
 block discarded – undo
1147 1147
      * @return bool
1148 1148
      */
1149 1149
     public function payment_exists( $txn_id = '' ) {
1150
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1150
+        $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1151 1151
         return ! empty( $invoice_id );
1152
-	}
1153
-
1154
-	/**
1155
-	 * Handle the status transition.
1156
-	 */
1157
-	protected function status_transition() {
1158
-		$status_transition = $this->status_transition;
1159
-
1160
-		// Reset status transition variable.
1161
-		$this->status_transition = false;
1162
-
1163
-		if ( $status_transition ) {
1164
-			try {
1165
-
1166
-				// Fire a hook for the status change.
1167
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1168
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1169
-
1170
-				if ( ! empty( $status_transition['from'] ) ) {
1171
-
1172
-					/* translators: 1: old subscription status 2: new subscription status */
1173
-					$transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1174
-
1175
-					// Fire another hook.
1176
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1177
-					do_action( 'getpaid_subscription_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
1178
-
1179
-					// Note the transition occurred.
1180
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1181
-
1182
-				} else {
1183
-					/* translators: %s: new invoice status */
1184
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1185
-
1186
-					// Note the transition occurred.
1187
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1188
-
1189
-				}
1190
-			} catch ( Exception $e ) {
1191
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1192
-			}
1193
-		}
1194
-
1195
-	}
1196
-
1197
-	/**
1198
-	 * Save data to the database.
1199
-	 *
1200
-	 * @since 1.0.19
1201
-	 * @return int subscription ID
1202
-	 */
1203
-	public function save() {
1204
-		parent::save();
1205
-		$this->status_transition();
1206
-		return $this->get_id();
1207
-	}
1152
+    }
1153
+
1154
+    /**
1155
+     * Handle the status transition.
1156
+     */
1157
+    protected function status_transition() {
1158
+        $status_transition = $this->status_transition;
1159
+
1160
+        // Reset status transition variable.
1161
+        $this->status_transition = false;
1162
+
1163
+        if ( $status_transition ) {
1164
+            try {
1165
+
1166
+                // Fire a hook for the status change.
1167
+                do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1168
+                do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1169
+
1170
+                if ( ! empty( $status_transition['from'] ) ) {
1171
+
1172
+                    /* translators: 1: old subscription status 2: new subscription status */
1173
+                    $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1174
+
1175
+                    // Fire another hook.
1176
+                    do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1177
+                    do_action( 'getpaid_subscription_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
1178
+
1179
+                    // Note the transition occurred.
1180
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1181
+
1182
+                } else {
1183
+                    /* translators: %s: new invoice status */
1184
+                    $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1185
+
1186
+                    // Note the transition occurred.
1187
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1188
+
1189
+                }
1190
+            } catch ( Exception $e ) {
1191
+                $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1192
+            }
1193
+        }
1194
+
1195
+    }
1196
+
1197
+    /**
1198
+     * Save data to the database.
1199
+     *
1200
+     * @since 1.0.19
1201
+     * @return int subscription ID
1202
+     */
1203
+    public function save() {
1204
+        parent::save();
1205
+        $this->status_transition();
1206
+        return $this->get_id();
1207
+    }
1208 1208
 
1209 1209
 }
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Indentation   +2230 added lines, -2230 removed lines patch added patch discarded remove patch
@@ -14,30 +14,30 @@  discard block
 block discarded – undo
14 14
 class WPInv_Invoice extends GetPaid_Data {
15 15
 
16 16
     /**
17
-	 * Which data store to load.
18
-	 *
19
-	 * @var string
20
-	 */
17
+     * Which data store to load.
18
+     *
19
+     * @var string
20
+     */
21 21
     protected $data_store_name = 'invoice';
22 22
 
23 23
     /**
24
-	 * This is the name of this object type.
25
-	 *
26
-	 * @var string
27
-	 */
24
+     * This is the name of this object type.
25
+     *
26
+     * @var string
27
+     */
28 28
     protected $object_type = 'invoice';
29 29
 
30 30
     /**
31
-	 * Item Data array. This is the core item data exposed in APIs.
32
-	 *
33
-	 * @since 1.0.19
34
-	 * @var array
35
-	 */
36
-	protected $data = array(
37
-		'parent_id'            => 0,
38
-		'status'               => 'wpi-pending',
39
-		'version'              => '',
40
-		'date_created'         => null,
31
+     * Item Data array. This is the core item data exposed in APIs.
32
+     *
33
+     * @since 1.0.19
34
+     * @var array
35
+     */
36
+    protected $data = array(
37
+        'parent_id'            => 0,
38
+        'status'               => 'wpi-pending',
39
+        'version'              => '',
40
+        'date_created'         => null,
41 41
         'date_modified'        => null,
42 42
         'due_date'             => null,
43 43
         'completed_date'       => null,
@@ -79,20 +79,20 @@  discard block
 block discarded – undo
79 79
         'transaction_id'       => '',
80 80
         'currency'             => '',
81 81
         'disable_taxes'        => false,
82
-		'subscription_id'      => null,
83
-		'is_viewed'            => false,
84
-		'email_cc'             => '',
85
-		'template'             => 'quantity', // hours, amount only
82
+        'subscription_id'      => null,
83
+        'is_viewed'            => false,
84
+        'email_cc'             => '',
85
+        'template'             => 'quantity', // hours, amount only
86 86
     );
87 87
 
88 88
     /**
89
-	 * Stores meta in cache for future reads.
90
-	 *
91
-	 * A group must be set to to enable caching.
92
-	 *
93
-	 * @var string
94
-	 */
95
-	protected $cache_group = 'getpaid_invoices';
89
+     * Stores meta in cache for future reads.
90
+     *
91
+     * A group must be set to to enable caching.
92
+     *
93
+     * @var string
94
+     */
95
+    protected $cache_group = 'getpaid_invoices';
96 96
 
97 97
     /**
98 98
      * Stores a reference to the original WP_Post object
@@ -106,104 +106,104 @@  discard block
 block discarded – undo
106 106
      *
107 107
      * @var int
108 108
      */
109
-	protected $recurring_item = null;
109
+    protected $recurring_item = null;
110 110
 
111
-	/**
111
+    /**
112 112
      * Stores an array of item totals.
113
-	 *
114
-	 * e.g $totals['discount'] = array(
115
-	 * 		'initial'   => 10,
116
-	 * 		'recurring' => 10,
117
-	 * )
113
+     *
114
+     * e.g $totals['discount'] = array(
115
+     * 		'initial'   => 10,
116
+     * 		'recurring' => 10,
117
+     * )
118 118
      *
119 119
      * @var array
120 120
      */
121
-	protected $totals = array();
121
+    protected $totals = array();
122 122
 
123
-	/**
124
-	 * Stores the status transition information.
125
-	 *
126
-	 * @since 1.0.19
127
-	 * @var bool
128
-	 */
129
-	protected $status_transition = false;
123
+    /**
124
+     * Stores the status transition information.
125
+     *
126
+     * @since 1.0.19
127
+     * @var bool
128
+     */
129
+    protected $status_transition = false;
130 130
 
131 131
     /**
132
-	 * Get the invoice if ID is passed, otherwise the invoice is new and empty.
133
-	 *
134
-	 * @param  int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read.
135
-	 */
132
+     * Get the invoice if ID is passed, otherwise the invoice is new and empty.
133
+     *
134
+     * @param  int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read.
135
+     */
136 136
     public function __construct( $invoice = false ) {
137 137
 
138 138
         parent::__construct( $invoice );
139 139
 
140
-		if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) {
141
-			$this->set_id( $invoice );
142
-		} elseif ( $invoice instanceof self ) {
143
-			$this->set_id( $invoice->get_id() );
144
-		} elseif ( ! empty( $invoice->ID ) ) {
145
-			$this->set_id( $invoice->ID );
146
-		} elseif ( is_array( $invoice ) ) {
147
-			$this->set_props( $invoice );
148
-
149
-			if ( isset( $invoice['ID'] ) ) {
150
-				$this->set_id( $invoice['ID'] );
151
-			}
152
-
153
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) {
154
-			$this->set_id( $invoice_id );
155
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) {
156
-			$this->set_id( $invoice_id );
157
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) {
158
-			$this->set_id( $invoice_id );
159
-		}else {
160
-			$this->set_object_read( true );
161
-		}
140
+        if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) {
141
+            $this->set_id( $invoice );
142
+        } elseif ( $invoice instanceof self ) {
143
+            $this->set_id( $invoice->get_id() );
144
+        } elseif ( ! empty( $invoice->ID ) ) {
145
+            $this->set_id( $invoice->ID );
146
+        } elseif ( is_array( $invoice ) ) {
147
+            $this->set_props( $invoice );
148
+
149
+            if ( isset( $invoice['ID'] ) ) {
150
+                $this->set_id( $invoice['ID'] );
151
+            }
152
+
153
+        } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) {
154
+            $this->set_id( $invoice_id );
155
+        } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) {
156
+            $this->set_id( $invoice_id );
157
+        } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) {
158
+            $this->set_id( $invoice_id );
159
+        }else {
160
+            $this->set_object_read( true );
161
+        }
162 162
 
163 163
         // Load the datastore.
164
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
164
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
165 165
 
166
-		if ( $this->get_id() > 0 ) {
166
+        if ( $this->get_id() > 0 ) {
167 167
             $this->post = get_post( $this->get_id() );
168 168
             $this->ID   = $this->get_id();
169
-			$this->data_store->read( $this );
169
+            $this->data_store->read( $this );
170 170
         }
171 171
 
172 172
     }
173 173
 
174 174
     /**
175
-	 * Given an invoice key/number, it returns its id.
176
-	 *
177
-	 *
178
-	 * @static
179
-	 * @param string $value The invoice key or number
180
-	 * @param string $field Either key, transaction_id or number.
181
-	 * @since 1.0.15
182
-	 * @return int
183
-	 */
184
-	public static function get_invoice_id_by_field( $value, $field = 'key' ) {
175
+     * Given an invoice key/number, it returns its id.
176
+     *
177
+     *
178
+     * @static
179
+     * @param string $value The invoice key or number
180
+     * @param string $field Either key, transaction_id or number.
181
+     * @since 1.0.15
182
+     * @return int
183
+     */
184
+    public static function get_invoice_id_by_field( $value, $field = 'key' ) {
185 185
         global $wpdb;
186 186
 
187
-		// Trim the value.
188
-		$value = trim( $value );
187
+        // Trim the value.
188
+        $value = trim( $value );
189 189
 
190
-		if ( empty( $value ) ) {
191
-			return 0;
192
-		}
190
+        if ( empty( $value ) ) {
191
+            return 0;
192
+        }
193 193
 
194 194
         // Valid fields.
195 195
         $fields = array( 'key', 'number', 'transaction_id' );
196 196
 
197
-		// Ensure a field has been passed.
198
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
199
-			return 0;
200
-		}
197
+        // Ensure a field has been passed.
198
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
199
+            return 0;
200
+        }
201 201
 
202
-		// Maybe retrieve from the cache.
203
-		$invoice_id   = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" );
204
-		if ( false !== $invoice_id ) {
205
-			return $invoice_id;
206
-		}
202
+        // Maybe retrieve from the cache.
203
+        $invoice_id   = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" );
204
+        if ( false !== $invoice_id ) {
205
+            return $invoice_id;
206
+        }
207 207
 
208 208
         // Fetch from the db.
209 209
         $table       = $wpdb->prefix . 'getpaid_invoices';
@@ -211,10 +211,10 @@  discard block
 block discarded – undo
211 211
             $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
212 212
         );
213 213
 
214
-		// Update the cache with our data
215
-		wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" );
214
+        // Update the cache with our data
215
+        wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" );
216 216
 
217
-		return $invoice_id;
217
+        return $invoice_id;
218 218
     }
219 219
 
220 220
     /**
@@ -240,73 +240,73 @@  discard block
 block discarded – undo
240 240
     */
241 241
 
242 242
     /**
243
-	 * Get parent invoice ID.
244
-	 *
245
-	 * @since 1.0.19
246
-	 * @param  string $context View or edit context.
247
-	 * @return int
248
-	 */
249
-	public function get_parent_id( $context = 'view' ) {
250
-		return (int) $this->get_prop( 'parent_id', $context );
243
+     * Get parent invoice ID.
244
+     *
245
+     * @since 1.0.19
246
+     * @param  string $context View or edit context.
247
+     * @return int
248
+     */
249
+    public function get_parent_id( $context = 'view' ) {
250
+        return (int) $this->get_prop( 'parent_id', $context );
251 251
     }
252 252
 
253 253
     /**
254
-	 * Get parent invoice.
255
-	 *
256
-	 * @since 1.0.19
257
-	 * @return WPInv_Invoice
258
-	 */
254
+     * Get parent invoice.
255
+     *
256
+     * @since 1.0.19
257
+     * @return WPInv_Invoice
258
+     */
259 259
     public function get_parent_payment() {
260 260
         return new WPInv_Invoice( $this->get_parent_id() );
261 261
     }
262 262
 
263 263
     /**
264
-	 * Alias for self::get_parent_payment().
265
-	 *
266
-	 * @since 1.0.19
267
-	 * @return WPInv_Invoice
268
-	 */
264
+     * Alias for self::get_parent_payment().
265
+     *
266
+     * @since 1.0.19
267
+     * @return WPInv_Invoice
268
+     */
269 269
     public function get_parent() {
270 270
         return $this->get_parent_payment();
271 271
     }
272 272
 
273 273
     /**
274
-	 * Get invoice status.
275
-	 *
276
-	 * @since 1.0.19
277
-	 * @param  string $context View or edit context.
278
-	 * @return string
279
-	 */
280
-	public function get_status( $context = 'view' ) {
281
-		return $this->get_prop( 'status', $context );
282
-	}
274
+     * Get invoice status.
275
+     *
276
+     * @since 1.0.19
277
+     * @param  string $context View or edit context.
278
+     * @return string
279
+     */
280
+    public function get_status( $context = 'view' ) {
281
+        return $this->get_prop( 'status', $context );
282
+    }
283 283
 	
284
-	/**
285
-	 * Retrieves an array of possible invoice statuses.
286
-	 *
287
-	 * @since 1.0.19
288
-	 * @return array
289
-	 */
290
-	public function get_all_statuses() {
291
-
292
-		$statuses = wpinv_get_invoice_statuses( true, true, $this );
293
-
294
-		// For backwards compatibility.
295
-		if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) {
284
+    /**
285
+     * Retrieves an array of possible invoice statuses.
286
+     *
287
+     * @since 1.0.19
288
+     * @return array
289
+     */
290
+    public function get_all_statuses() {
291
+
292
+        $statuses = wpinv_get_invoice_statuses( true, true, $this );
293
+
294
+        // For backwards compatibility.
295
+        if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) {
296 296
             $statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
297
-		}
297
+        }
298 298
 
299
-		return $statuses;
299
+        return $statuses;
300 300
     }
301 301
 
302 302
     /**
303
-	 * Get invoice status nice name.
304
-	 *
305
-	 * @since 1.0.19
306
-	 * @return string
307
-	 */
303
+     * Get invoice status nice name.
304
+     *
305
+     * @since 1.0.19
306
+     * @return string
307
+     */
308 308
     public function get_status_nicename() {
309
-		$statuses = $this->get_all_statuses();
309
+        $statuses = $this->get_all_statuses();
310 310
 
311 311
         $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status();
312 312
 
@@ -314,20 +314,20 @@  discard block
 block discarded – undo
314 314
     }
315 315
 
316 316
     /**
317
-	 * Get plugin version when the invoice was created.
318
-	 *
319
-	 * @since 1.0.19
320
-	 * @param  string $context View or edit context.
321
-	 * @return string
322
-	 */
323
-	public function get_version( $context = 'view' ) {
324
-		return $this->get_prop( 'version', $context );
325
-	}
317
+     * Get plugin version when the invoice was created.
318
+     *
319
+     * @since 1.0.19
320
+     * @param  string $context View or edit context.
321
+     * @return string
322
+     */
323
+    public function get_version( $context = 'view' ) {
324
+        return $this->get_prop( 'version', $context );
325
+    }
326 326
 
327
-	/**
328
-	 * @deprecated
329
-	 */
330
-	public function get_invoice_date( $formatted = true ) {
327
+    /**
328
+     * @deprecated
329
+     */
330
+    public function get_invoice_date( $formatted = true ) {
331 331
         $date_completed = $this->get_date_completed();
332 332
         $invoice_date   = $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
333 333
 
@@ -344,187 +344,187 @@  discard block
 block discarded – undo
344 344
     }
345 345
 
346 346
     /**
347
-	 * Get date when the invoice was created.
348
-	 *
349
-	 * @since 1.0.19
350
-	 * @param  string $context View or edit context.
351
-	 * @return string
352
-	 */
353
-	public function get_date_created( $context = 'view' ) {
354
-		return $this->get_prop( 'date_created', $context );
355
-	}
347
+     * Get date when the invoice was created.
348
+     *
349
+     * @since 1.0.19
350
+     * @param  string $context View or edit context.
351
+     * @return string
352
+     */
353
+    public function get_date_created( $context = 'view' ) {
354
+        return $this->get_prop( 'date_created', $context );
355
+    }
356 356
 	
357
-	/**
358
-	 * Alias for self::get_date_created().
359
-	 *
360
-	 * @since 1.0.19
361
-	 * @param  string $context View or edit context.
362
-	 * @return string
363
-	 */
364
-	public function get_created_date( $context = 'view' ) {
365
-		return $this->get_date_created( $context );
366
-    }
367
-
368
-    /**
369
-	 * Get GMT date when the invoice was created.
370
-	 *
371
-	 * @since 1.0.19
372
-	 * @param  string $context View or edit context.
373
-	 * @return string
374
-	 */
375
-	public function get_date_created_gmt( $context = 'view' ) {
357
+    /**
358
+     * Alias for self::get_date_created().
359
+     *
360
+     * @since 1.0.19
361
+     * @param  string $context View or edit context.
362
+     * @return string
363
+     */
364
+    public function get_created_date( $context = 'view' ) {
365
+        return $this->get_date_created( $context );
366
+    }
367
+
368
+    /**
369
+     * Get GMT date when the invoice was created.
370
+     *
371
+     * @since 1.0.19
372
+     * @param  string $context View or edit context.
373
+     * @return string
374
+     */
375
+    public function get_date_created_gmt( $context = 'view' ) {
376 376
         $date = $this->get_date_created( $context );
377 377
 
378 378
         if ( $date ) {
379 379
             $date = get_gmt_from_date( $date );
380 380
         }
381
-		return $date;
381
+        return $date;
382 382
     }
383 383
 
384 384
     /**
385
-	 * Get date when the invoice was last modified.
386
-	 *
387
-	 * @since 1.0.19
388
-	 * @param  string $context View or edit context.
389
-	 * @return string
390
-	 */
391
-	public function get_date_modified( $context = 'view' ) {
392
-		return $this->get_prop( 'date_modified', $context );
393
-	}
385
+     * Get date when the invoice was last modified.
386
+     *
387
+     * @since 1.0.19
388
+     * @param  string $context View or edit context.
389
+     * @return string
390
+     */
391
+    public function get_date_modified( $context = 'view' ) {
392
+        return $this->get_prop( 'date_modified', $context );
393
+    }
394 394
 
395
-	/**
396
-	 * Alias for self::get_date_modified().
397
-	 *
398
-	 * @since 1.0.19
399
-	 * @param  string $context View or edit context.
400
-	 * @return string
401
-	 */
402
-	public function get_modified_date( $context = 'view' ) {
403
-		return $this->get_date_modified( $context );
395
+    /**
396
+     * Alias for self::get_date_modified().
397
+     *
398
+     * @since 1.0.19
399
+     * @param  string $context View or edit context.
400
+     * @return string
401
+     */
402
+    public function get_modified_date( $context = 'view' ) {
403
+        return $this->get_date_modified( $context );
404 404
     }
405 405
 
406 406
     /**
407
-	 * Get GMT date when the invoice was last modified.
408
-	 *
409
-	 * @since 1.0.19
410
-	 * @param  string $context View or edit context.
411
-	 * @return string
412
-	 */
413
-	public function get_date_modified_gmt( $context = 'view' ) {
407
+     * Get GMT date when the invoice was last modified.
408
+     *
409
+     * @since 1.0.19
410
+     * @param  string $context View or edit context.
411
+     * @return string
412
+     */
413
+    public function get_date_modified_gmt( $context = 'view' ) {
414 414
         $date = $this->get_date_modified( $context );
415 415
 
416 416
         if ( $date ) {
417 417
             $date = get_gmt_from_date( $date );
418 418
         }
419
-		return $date;
419
+        return $date;
420 420
     }
421 421
 
422 422
     /**
423
-	 * Get the invoice due date.
424
-	 *
425
-	 * @since 1.0.19
426
-	 * @param  string $context View or edit context.
427
-	 * @return string
428
-	 */
429
-	public function get_due_date( $context = 'view' ) {
430
-		return $this->get_prop( 'due_date', $context );
423
+     * Get the invoice due date.
424
+     *
425
+     * @since 1.0.19
426
+     * @param  string $context View or edit context.
427
+     * @return string
428
+     */
429
+    public function get_due_date( $context = 'view' ) {
430
+        return $this->get_prop( 'due_date', $context );
431 431
     }
432 432
 
433 433
     /**
434
-	 * Alias for self::get_due_date().
435
-	 *
436
-	 * @since 1.0.19
437
-	 * @param  string $context View or edit context.
438
-	 * @return string
439
-	 */
440
-	public function get_date_due( $context = 'view' ) {
441
-		return $this->get_due_date( $context );
434
+     * Alias for self::get_due_date().
435
+     *
436
+     * @since 1.0.19
437
+     * @param  string $context View or edit context.
438
+     * @return string
439
+     */
440
+    public function get_date_due( $context = 'view' ) {
441
+        return $this->get_due_date( $context );
442 442
     }
443 443
 
444 444
     /**
445
-	 * Get the invoice GMT due date.
446
-	 *
447
-	 * @since 1.0.19
448
-	 * @param  string $context View or edit context.
449
-	 * @return string
450
-	 */
451
-	public function get_due_date_gmt( $context = 'view' ) {
445
+     * Get the invoice GMT due date.
446
+     *
447
+     * @since 1.0.19
448
+     * @param  string $context View or edit context.
449
+     * @return string
450
+     */
451
+    public function get_due_date_gmt( $context = 'view' ) {
452 452
         $date = $this->get_due_date( $context );
453 453
 
454 454
         if ( $date ) {
455 455
             $date = get_gmt_from_date( $date );
456 456
         }
457
-		return $date;
457
+        return $date;
458 458
     }
459 459
 
460 460
     /**
461
-	 * Alias for self::get_due_date_gmt().
462
-	 *
463
-	 * @since 1.0.19
464
-	 * @param  string $context View or edit context.
465
-	 * @return string
466
-	 */
467
-	public function get_gmt_date_due( $context = 'view' ) {
468
-		return $this->get_due_date_gmt( $context );
461
+     * Alias for self::get_due_date_gmt().
462
+     *
463
+     * @since 1.0.19
464
+     * @param  string $context View or edit context.
465
+     * @return string
466
+     */
467
+    public function get_gmt_date_due( $context = 'view' ) {
468
+        return $this->get_due_date_gmt( $context );
469 469
     }
470 470
 
471 471
     /**
472
-	 * Get date when the invoice was completed.
473
-	 *
474
-	 * @since 1.0.19
475
-	 * @param  string $context View or edit context.
476
-	 * @return string
477
-	 */
478
-	public function get_completed_date( $context = 'view' ) {
479
-		return $this->get_prop( 'completed_date', $context );
472
+     * Get date when the invoice was completed.
473
+     *
474
+     * @since 1.0.19
475
+     * @param  string $context View or edit context.
476
+     * @return string
477
+     */
478
+    public function get_completed_date( $context = 'view' ) {
479
+        return $this->get_prop( 'completed_date', $context );
480 480
     }
481 481
 
482 482
     /**
483
-	 * Alias for self::get_completed_date().
484
-	 *
485
-	 * @since 1.0.19
486
-	 * @param  string $context View or edit context.
487
-	 * @return string
488
-	 */
489
-	public function get_date_completed( $context = 'view' ) {
490
-		return $this->get_completed_date( $context );
483
+     * Alias for self::get_completed_date().
484
+     *
485
+     * @since 1.0.19
486
+     * @param  string $context View or edit context.
487
+     * @return string
488
+     */
489
+    public function get_date_completed( $context = 'view' ) {
490
+        return $this->get_completed_date( $context );
491 491
     }
492 492
 
493 493
     /**
494
-	 * Get GMT date when the invoice was was completed.
495
-	 *
496
-	 * @since 1.0.19
497
-	 * @param  string $context View or edit context.
498
-	 * @return string
499
-	 */
500
-	public function get_completed_date_gmt( $context = 'view' ) {
494
+     * Get GMT date when the invoice was was completed.
495
+     *
496
+     * @since 1.0.19
497
+     * @param  string $context View or edit context.
498
+     * @return string
499
+     */
500
+    public function get_completed_date_gmt( $context = 'view' ) {
501 501
         $date = $this->get_completed_date( $context );
502 502
 
503 503
         if ( $date ) {
504 504
             $date = get_gmt_from_date( $date );
505 505
         }
506
-		return $date;
506
+        return $date;
507 507
     }
508 508
 
509 509
     /**
510
-	 * Alias for self::get_completed_date_gmt().
511
-	 *
512
-	 * @since 1.0.19
513
-	 * @param  string $context View or edit context.
514
-	 * @return string
515
-	 */
516
-	public function get_gmt_completed_date( $context = 'view' ) {
517
-		return $this->get_completed_date_gmt( $context );
510
+     * Alias for self::get_completed_date_gmt().
511
+     *
512
+     * @since 1.0.19
513
+     * @param  string $context View or edit context.
514
+     * @return string
515
+     */
516
+    public function get_gmt_completed_date( $context = 'view' ) {
517
+        return $this->get_completed_date_gmt( $context );
518 518
     }
519 519
 
520 520
     /**
521
-	 * Get the invoice number.
522
-	 *
523
-	 * @since 1.0.19
524
-	 * @param  string $context View or edit context.
525
-	 * @return string
526
-	 */
527
-	public function get_number( $context = 'view' ) {
521
+     * Get the invoice number.
522
+     *
523
+     * @since 1.0.19
524
+     * @param  string $context View or edit context.
525
+     * @return string
526
+     */
527
+    public function get_number( $context = 'view' ) {
528 528
         $number = $this->get_prop( 'number', $context );
529 529
 
530 530
         if ( empty( $number ) ) {
@@ -532,17 +532,17 @@  discard block
 block discarded – undo
532 532
             $this->set_number( $number );
533 533
         }
534 534
 
535
-		return $number;
535
+        return $number;
536 536
     }
537 537
 
538 538
     /**
539
-	 * Get the invoice key.
540
-	 *
541
-	 * @since 1.0.19
542
-	 * @param  string $context View or edit context.
543
-	 * @return string
544
-	 */
545
-	public function get_key( $context = 'view' ) {
539
+     * Get the invoice key.
540
+     *
541
+     * @since 1.0.19
542
+     * @param  string $context View or edit context.
543
+     * @return string
544
+     */
545
+    public function get_key( $context = 'view' ) {
546 546
         $key = $this->get_prop( 'key', $context );
547 547
 
548 548
         if ( empty( $key ) ) {
@@ -550,24 +550,24 @@  discard block
 block discarded – undo
550 550
             $this->set_key( $key );
551 551
         }
552 552
 
553
-		return $key;
553
+        return $key;
554 554
     }
555 555
 
556 556
     /**
557
-	 * Get the invoice type.
558
-	 *
559
-	 * @since 1.0.19
560
-	 * @param  string $context View or edit context.
561
-	 * @return string
562
-	 */
563
-	public function get_type( $context = 'view' ) {
557
+     * Get the invoice type.
558
+     *
559
+     * @since 1.0.19
560
+     * @param  string $context View or edit context.
561
+     * @return string
562
+     */
563
+    public function get_type( $context = 'view' ) {
564 564
         return $this->get_prop( 'type', $context );
565
-	}
565
+    }
566 566
 
567
-	/**
568
-	 * @deprecated
569
-	 */
570
-	public function get_invoice_quote_type( $post_id ) {
567
+    /**
568
+     * @deprecated
569
+     */
570
+    public function get_invoice_quote_type( $post_id ) {
571 571
         if ( empty( $post_id ) ) {
572 572
             return '';
573 573
         }
@@ -584,35 +584,35 @@  discard block
 block discarded – undo
584 584
     }
585 585
 
586 586
     /**
587
-	 * Get the invoice post type.
588
-	 *
589
-	 * @since 1.0.19
590
-	 * @param  string $context View or edit context.
591
-	 * @return string
592
-	 */
593
-	public function get_post_type( $context = 'view' ) {
587
+     * Get the invoice post type.
588
+     *
589
+     * @since 1.0.19
590
+     * @param  string $context View or edit context.
591
+     * @return string
592
+     */
593
+    public function get_post_type( $context = 'view' ) {
594 594
         return $this->get_prop( 'post_type', $context );
595 595
     }
596 596
 
597 597
     /**
598
-	 * Get the invoice mode.
599
-	 *
600
-	 * @since 1.0.19
601
-	 * @param  string $context View or edit context.
602
-	 * @return string
603
-	 */
604
-	public function get_mode( $context = 'view' ) {
598
+     * Get the invoice mode.
599
+     *
600
+     * @since 1.0.19
601
+     * @param  string $context View or edit context.
602
+     * @return string
603
+     */
604
+    public function get_mode( $context = 'view' ) {
605 605
         return $this->get_prop( 'mode', $context );
606 606
     }
607 607
 
608 608
     /**
609
-	 * Get the invoice path.
610
-	 *
611
-	 * @since 1.0.19
612
-	 * @param  string $context View or edit context.
613
-	 * @return string
614
-	 */
615
-	public function get_path( $context = 'view' ) {
609
+     * Get the invoice path.
610
+     *
611
+     * @since 1.0.19
612
+     * @param  string $context View or edit context.
613
+     * @return string
614
+     */
615
+    public function get_path( $context = 'view' ) {
616 616
         $path = $this->get_prop( 'path', $context );
617 617
 
618 618
         if ( empty( $path ) ) {
@@ -620,73 +620,73 @@  discard block
 block discarded – undo
620 620
             $path   = sanitize_title( $prefix . $this->get_id() );
621 621
         }
622 622
 
623
-		return $path;
623
+        return $path;
624 624
     }
625 625
 
626 626
     /**
627
-	 * Get the invoice name/title.
628
-	 *
629
-	 * @since 1.0.19
630
-	 * @param  string $context View or edit context.
631
-	 * @return string
632
-	 */
633
-	public function get_name( $context = 'view' ) {
627
+     * Get the invoice name/title.
628
+     *
629
+     * @since 1.0.19
630
+     * @param  string $context View or edit context.
631
+     * @return string
632
+     */
633
+    public function get_name( $context = 'view' ) {
634 634
         $name = $this->get_prop( 'title', $context );
635 635
 
636
-		return empty( $name ) ? $this->get_number( $context ) : $name;
636
+        return empty( $name ) ? $this->get_number( $context ) : $name;
637 637
     }
638 638
 
639 639
     /**
640
-	 * Alias of self::get_name().
641
-	 *
642
-	 * @since 1.0.19
643
-	 * @param  string $context View or edit context.
644
-	 * @return string
645
-	 */
646
-	public function get_title( $context = 'view' ) {
647
-		return $this->get_name( $context );
640
+     * Alias of self::get_name().
641
+     *
642
+     * @since 1.0.19
643
+     * @param  string $context View or edit context.
644
+     * @return string
645
+     */
646
+    public function get_title( $context = 'view' ) {
647
+        return $this->get_name( $context );
648 648
     }
649 649
 
650 650
     /**
651
-	 * Get the invoice description.
652
-	 *
653
-	 * @since 1.0.19
654
-	 * @param  string $context View or edit context.
655
-	 * @return string
656
-	 */
657
-	public function get_description( $context = 'view' ) {
658
-		return $this->get_prop( 'description', $context );
651
+     * Get the invoice description.
652
+     *
653
+     * @since 1.0.19
654
+     * @param  string $context View or edit context.
655
+     * @return string
656
+     */
657
+    public function get_description( $context = 'view' ) {
658
+        return $this->get_prop( 'description', $context );
659 659
     }
660 660
 
661 661
     /**
662
-	 * Alias of self::get_description().
663
-	 *
664
-	 * @since 1.0.19
665
-	 * @param  string $context View or edit context.
666
-	 * @return string
667
-	 */
668
-	public function get_excerpt( $context = 'view' ) {
669
-		return $this->get_description( $context );
662
+     * Alias of self::get_description().
663
+     *
664
+     * @since 1.0.19
665
+     * @param  string $context View or edit context.
666
+     * @return string
667
+     */
668
+    public function get_excerpt( $context = 'view' ) {
669
+        return $this->get_description( $context );
670 670
     }
671 671
 
672 672
     /**
673
-	 * Alias of self::get_description().
674
-	 *
675
-	 * @since 1.0.19
676
-	 * @param  string $context View or edit context.
677
-	 * @return string
678
-	 */
679
-	public function get_summary( $context = 'view' ) {
680
-		return $this->get_description( $context );
673
+     * Alias of self::get_description().
674
+     *
675
+     * @since 1.0.19
676
+     * @param  string $context View or edit context.
677
+     * @return string
678
+     */
679
+    public function get_summary( $context = 'view' ) {
680
+        return $this->get_description( $context );
681 681
     }
682 682
 
683 683
     /**
684
-	 * Returns the user info.
685
-	 *
686
-	 * @since 1.0.19
684
+     * Returns the user info.
685
+     *
686
+     * @since 1.0.19
687 687
      * @param  string $context View or edit context.
688
-	 * @return array
689
-	 */
688
+     * @return array
689
+     */
690 690
     public function get_user_info( $context = 'view' ) {
691 691
 
692 692
         $user_info = array(
@@ -703,605 +703,605 @@  discard block
 block discarded – undo
703 703
             'company'    => $this->get_company( $context ),
704 704
             'vat_number' => $this->get_vat_number( $context ),
705 705
             'discount'   => $this->get_discount_code( $context ),
706
-		);
706
+        );
707 707
 
708
-		return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this );
708
+        return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this );
709 709
 
710 710
     }
711 711
 
712 712
     /**
713
-	 * Get the customer id.
714
-	 *
715
-	 * @since 1.0.19
716
-	 * @param  string $context View or edit context.
717
-	 * @return int
718
-	 */
719
-	public function get_author( $context = 'view' ) {
720
-		return (int) $this->get_prop( 'author', $context );
713
+     * Get the customer id.
714
+     *
715
+     * @since 1.0.19
716
+     * @param  string $context View or edit context.
717
+     * @return int
718
+     */
719
+    public function get_author( $context = 'view' ) {
720
+        return (int) $this->get_prop( 'author', $context );
721 721
     }
722 722
 
723 723
     /**
724
-	 * Alias of self::get_author().
725
-	 *
726
-	 * @since 1.0.19
727
-	 * @param  string $context View or edit context.
728
-	 * @return int
729
-	 */
730
-	public function get_user_id( $context = 'view' ) {
731
-		return $this->get_author( $context );
724
+     * Alias of self::get_author().
725
+     *
726
+     * @since 1.0.19
727
+     * @param  string $context View or edit context.
728
+     * @return int
729
+     */
730
+    public function get_user_id( $context = 'view' ) {
731
+        return $this->get_author( $context );
732 732
     }
733 733
 
734
-     /**
735
-	 * Alias of self::get_author().
736
-	 *
737
-	 * @since 1.0.19
738
-	 * @param  string $context View or edit context.
739
-	 * @return int
740
-	 */
741
-	public function get_customer_id( $context = 'view' ) {
742
-		return $this->get_author( $context );
734
+        /**
735
+         * Alias of self::get_author().
736
+         *
737
+         * @since 1.0.19
738
+         * @param  string $context View or edit context.
739
+         * @return int
740
+         */
741
+    public function get_customer_id( $context = 'view' ) {
742
+        return $this->get_author( $context );
743 743
     }
744 744
 
745 745
     /**
746
-	 * Get the customer's ip.
747
-	 *
748
-	 * @since 1.0.19
749
-	 * @param  string $context View or edit context.
750
-	 * @return string
751
-	 */
752
-	public function get_ip( $context = 'view' ) {
753
-		return $this->get_prop( 'user_ip', $context );
746
+     * Get the customer's ip.
747
+     *
748
+     * @since 1.0.19
749
+     * @param  string $context View or edit context.
750
+     * @return string
751
+     */
752
+    public function get_ip( $context = 'view' ) {
753
+        return $this->get_prop( 'user_ip', $context );
754 754
     }
755 755
 
756 756
     /**
757
-	 * Alias of self::get_ip().
758
-	 *
759
-	 * @since 1.0.19
760
-	 * @param  string $context View or edit context.
761
-	 * @return string
762
-	 */
763
-	public function get_user_ip( $context = 'view' ) {
764
-		return $this->get_ip( $context );
757
+     * Alias of self::get_ip().
758
+     *
759
+     * @since 1.0.19
760
+     * @param  string $context View or edit context.
761
+     * @return string
762
+     */
763
+    public function get_user_ip( $context = 'view' ) {
764
+        return $this->get_ip( $context );
765 765
     }
766 766
 
767
-     /**
768
-	 * Alias of self::get_ip().
769
-	 *
770
-	 * @since 1.0.19
771
-	 * @param  string $context View or edit context.
772
-	 * @return string
773
-	 */
774
-	public function get_customer_ip( $context = 'view' ) {
775
-		return $this->get_ip( $context );
767
+        /**
768
+         * Alias of self::get_ip().
769
+         *
770
+         * @since 1.0.19
771
+         * @param  string $context View or edit context.
772
+         * @return string
773
+         */
774
+    public function get_customer_ip( $context = 'view' ) {
775
+        return $this->get_ip( $context );
776 776
     }
777 777
 
778 778
     /**
779
-	 * Get the customer's first name.
780
-	 *
781
-	 * @since 1.0.19
782
-	 * @param  string $context View or edit context.
783
-	 * @return string
784
-	 */
785
-	public function get_first_name( $context = 'view' ) {
786
-		return $this->get_prop( 'first_name', $context );
779
+     * Get the customer's first name.
780
+     *
781
+     * @since 1.0.19
782
+     * @param  string $context View or edit context.
783
+     * @return string
784
+     */
785
+    public function get_first_name( $context = 'view' ) {
786
+        return $this->get_prop( 'first_name', $context );
787 787
     }
788 788
 
789 789
     /**
790
-	 * Alias of self::get_first_name().
791
-	 *
792
-	 * @since 1.0.19
793
-	 * @param  string $context View or edit context.
794
-	 * @return int
795
-	 */
796
-	public function get_user_first_name( $context = 'view' ) {
797
-		return $this->get_first_name( $context );
790
+     * Alias of self::get_first_name().
791
+     *
792
+     * @since 1.0.19
793
+     * @param  string $context View or edit context.
794
+     * @return int
795
+     */
796
+    public function get_user_first_name( $context = 'view' ) {
797
+        return $this->get_first_name( $context );
798 798
     }
799 799
 
800
-     /**
801
-	 * Alias of self::get_first_name().
802
-	 *
803
-	 * @since 1.0.19
804
-	 * @param  string $context View or edit context.
805
-	 * @return int
806
-	 */
807
-	public function get_customer_first_name( $context = 'view' ) {
808
-		return $this->get_first_name( $context );
800
+        /**
801
+         * Alias of self::get_first_name().
802
+         *
803
+         * @since 1.0.19
804
+         * @param  string $context View or edit context.
805
+         * @return int
806
+         */
807
+    public function get_customer_first_name( $context = 'view' ) {
808
+        return $this->get_first_name( $context );
809 809
     }
810 810
 
811 811
     /**
812
-	 * Get the customer's last name.
813
-	 *
814
-	 * @since 1.0.19
815
-	 * @param  string $context View or edit context.
816
-	 * @return string
817
-	 */
818
-	public function get_last_name( $context = 'view' ) {
819
-		return $this->get_prop( 'last_name', $context );
812
+     * Get the customer's last name.
813
+     *
814
+     * @since 1.0.19
815
+     * @param  string $context View or edit context.
816
+     * @return string
817
+     */
818
+    public function get_last_name( $context = 'view' ) {
819
+        return $this->get_prop( 'last_name', $context );
820 820
     }
821 821
 
822 822
     /**
823
-	 * Alias of self::get_last_name().
824
-	 *
825
-	 * @since 1.0.19
826
-	 * @param  string $context View or edit context.
827
-	 * @return int
828
-	 */
829
-	public function get_user_last_name( $context = 'view' ) {
830
-		return $this->get_last_name( $context );
823
+     * Alias of self::get_last_name().
824
+     *
825
+     * @since 1.0.19
826
+     * @param  string $context View or edit context.
827
+     * @return int
828
+     */
829
+    public function get_user_last_name( $context = 'view' ) {
830
+        return $this->get_last_name( $context );
831 831
     }
832 832
 
833 833
     /**
834
-	 * Alias of self::get_last_name().
835
-	 *
836
-	 * @since 1.0.19
837
-	 * @param  string $context View or edit context.
838
-	 * @return int
839
-	 */
840
-	public function get_customer_last_name( $context = 'view' ) {
841
-		return $this->get_last_name( $context );
834
+     * Alias of self::get_last_name().
835
+     *
836
+     * @since 1.0.19
837
+     * @param  string $context View or edit context.
838
+     * @return int
839
+     */
840
+    public function get_customer_last_name( $context = 'view' ) {
841
+        return $this->get_last_name( $context );
842 842
     }
843 843
 
844 844
     /**
845
-	 * Get the customer's full name.
846
-	 *
847
-	 * @since 1.0.19
848
-	 * @param  string $context View or edit context.
849
-	 * @return string
850
-	 */
851
-	public function get_full_name( $context = 'view' ) {
852
-		return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
845
+     * Get the customer's full name.
846
+     *
847
+     * @since 1.0.19
848
+     * @param  string $context View or edit context.
849
+     * @return string
850
+     */
851
+    public function get_full_name( $context = 'view' ) {
852
+        return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
853 853
     }
854 854
 
855 855
     /**
856
-	 * Alias of self::get_full_name().
857
-	 *
858
-	 * @since 1.0.19
859
-	 * @param  string $context View or edit context.
860
-	 * @return int
861
-	 */
862
-	public function get_user_full_name( $context = 'view' ) {
863
-		return $this->get_full_name( $context );
856
+     * Alias of self::get_full_name().
857
+     *
858
+     * @since 1.0.19
859
+     * @param  string $context View or edit context.
860
+     * @return int
861
+     */
862
+    public function get_user_full_name( $context = 'view' ) {
863
+        return $this->get_full_name( $context );
864 864
     }
865 865
 
866 866
     /**
867
-	 * Alias of self::get_full_name().
868
-	 *
869
-	 * @since 1.0.19
870
-	 * @param  string $context View or edit context.
871
-	 * @return int
872
-	 */
873
-	public function get_customer_full_name( $context = 'view' ) {
874
-		return $this->get_full_name( $context );
867
+     * Alias of self::get_full_name().
868
+     *
869
+     * @since 1.0.19
870
+     * @param  string $context View or edit context.
871
+     * @return int
872
+     */
873
+    public function get_customer_full_name( $context = 'view' ) {
874
+        return $this->get_full_name( $context );
875 875
     }
876 876
 
877 877
     /**
878
-	 * Get the customer's phone number.
879
-	 *
880
-	 * @since 1.0.19
881
-	 * @param  string $context View or edit context.
882
-	 * @return string
883
-	 */
884
-	public function get_phone( $context = 'view' ) {
885
-		return $this->get_prop( 'phone', $context );
878
+     * Get the customer's phone number.
879
+     *
880
+     * @since 1.0.19
881
+     * @param  string $context View or edit context.
882
+     * @return string
883
+     */
884
+    public function get_phone( $context = 'view' ) {
885
+        return $this->get_prop( 'phone', $context );
886 886
     }
887 887
 
888 888
     /**
889
-	 * Alias of self::get_phone().
890
-	 *
891
-	 * @since 1.0.19
892
-	 * @param  string $context View or edit context.
893
-	 * @return int
894
-	 */
895
-	public function get_phone_number( $context = 'view' ) {
896
-		return $this->get_phone( $context );
889
+     * Alias of self::get_phone().
890
+     *
891
+     * @since 1.0.19
892
+     * @param  string $context View or edit context.
893
+     * @return int
894
+     */
895
+    public function get_phone_number( $context = 'view' ) {
896
+        return $this->get_phone( $context );
897 897
     }
898 898
 
899 899
     /**
900
-	 * Alias of self::get_phone().
901
-	 *
902
-	 * @since 1.0.19
903
-	 * @param  string $context View or edit context.
904
-	 * @return int
905
-	 */
906
-	public function get_user_phone( $context = 'view' ) {
907
-		return $this->get_phone( $context );
900
+     * Alias of self::get_phone().
901
+     *
902
+     * @since 1.0.19
903
+     * @param  string $context View or edit context.
904
+     * @return int
905
+     */
906
+    public function get_user_phone( $context = 'view' ) {
907
+        return $this->get_phone( $context );
908 908
     }
909 909
 
910 910
     /**
911
-	 * Alias of self::get_phone().
912
-	 *
913
-	 * @since 1.0.19
914
-	 * @param  string $context View or edit context.
915
-	 * @return int
916
-	 */
917
-	public function get_customer_phone( $context = 'view' ) {
918
-		return $this->get_phone( $context );
911
+     * Alias of self::get_phone().
912
+     *
913
+     * @since 1.0.19
914
+     * @param  string $context View or edit context.
915
+     * @return int
916
+     */
917
+    public function get_customer_phone( $context = 'view' ) {
918
+        return $this->get_phone( $context );
919 919
     }
920 920
 
921 921
     /**
922
-	 * Get the customer's email address.
923
-	 *
924
-	 * @since 1.0.19
925
-	 * @param  string $context View or edit context.
926
-	 * @return string
927
-	 */
928
-	public function get_email( $context = 'view' ) {
929
-		return $this->get_prop( 'email', $context );
922
+     * Get the customer's email address.
923
+     *
924
+     * @since 1.0.19
925
+     * @param  string $context View or edit context.
926
+     * @return string
927
+     */
928
+    public function get_email( $context = 'view' ) {
929
+        return $this->get_prop( 'email', $context );
930 930
     }
931 931
 
932 932
     /**
933
-	 * Alias of self::get_email().
934
-	 *
935
-	 * @since 1.0.19
936
-	 * @param  string $context View or edit context.
937
-	 * @return string
938
-	 */
939
-	public function get_email_address( $context = 'view' ) {
940
-		return $this->get_email( $context );
933
+     * Alias of self::get_email().
934
+     *
935
+     * @since 1.0.19
936
+     * @param  string $context View or edit context.
937
+     * @return string
938
+     */
939
+    public function get_email_address( $context = 'view' ) {
940
+        return $this->get_email( $context );
941 941
     }
942 942
 
943 943
     /**
944
-	 * Alias of self::get_email().
945
-	 *
946
-	 * @since 1.0.19
947
-	 * @param  string $context View or edit context.
948
-	 * @return int
949
-	 */
950
-	public function get_user_email( $context = 'view' ) {
951
-		return $this->get_email( $context );
944
+     * Alias of self::get_email().
945
+     *
946
+     * @since 1.0.19
947
+     * @param  string $context View or edit context.
948
+     * @return int
949
+     */
950
+    public function get_user_email( $context = 'view' ) {
951
+        return $this->get_email( $context );
952 952
     }
953 953
 
954 954
     /**
955
-	 * Alias of self::get_email().
956
-	 *
957
-	 * @since 1.0.19
958
-	 * @param  string $context View or edit context.
959
-	 * @return int
960
-	 */
961
-	public function get_customer_email( $context = 'view' ) {
962
-		return $this->get_email( $context );
955
+     * Alias of self::get_email().
956
+     *
957
+     * @since 1.0.19
958
+     * @param  string $context View or edit context.
959
+     * @return int
960
+     */
961
+    public function get_customer_email( $context = 'view' ) {
962
+        return $this->get_email( $context );
963 963
     }
964 964
 
965 965
     /**
966
-	 * Get the customer's country.
967
-	 *
968
-	 * @since 1.0.19
969
-	 * @param  string $context View or edit context.
970
-	 * @return string
971
-	 */
972
-	public function get_country( $context = 'view' ) {
973
-		$country = $this->get_prop( 'country', $context );
974
-		return empty( $country ) ? wpinv_get_default_country() : $country;
966
+     * Get the customer's country.
967
+     *
968
+     * @since 1.0.19
969
+     * @param  string $context View or edit context.
970
+     * @return string
971
+     */
972
+    public function get_country( $context = 'view' ) {
973
+        $country = $this->get_prop( 'country', $context );
974
+        return empty( $country ) ? wpinv_get_default_country() : $country;
975 975
     }
976 976
 
977 977
     /**
978
-	 * Alias of self::get_country().
979
-	 *
980
-	 * @since 1.0.19
981
-	 * @param  string $context View or edit context.
982
-	 * @return int
983
-	 */
984
-	public function get_user_country( $context = 'view' ) {
985
-		return $this->get_country( $context );
978
+     * Alias of self::get_country().
979
+     *
980
+     * @since 1.0.19
981
+     * @param  string $context View or edit context.
982
+     * @return int
983
+     */
984
+    public function get_user_country( $context = 'view' ) {
985
+        return $this->get_country( $context );
986 986
     }
987 987
 
988 988
     /**
989
-	 * Alias of self::get_country().
990
-	 *
991
-	 * @since 1.0.19
992
-	 * @param  string $context View or edit context.
993
-	 * @return int
994
-	 */
995
-	public function get_customer_country( $context = 'view' ) {
996
-		return $this->get_country( $context );
989
+     * Alias of self::get_country().
990
+     *
991
+     * @since 1.0.19
992
+     * @param  string $context View or edit context.
993
+     * @return int
994
+     */
995
+    public function get_customer_country( $context = 'view' ) {
996
+        return $this->get_country( $context );
997 997
     }
998 998
 
999 999
     /**
1000
-	 * Get the customer's state.
1001
-	 *
1002
-	 * @since 1.0.19
1003
-	 * @param  string $context View or edit context.
1004
-	 * @return string
1005
-	 */
1006
-	public function get_state( $context = 'view' ) {
1007
-		$state = $this->get_prop( 'state', $context );
1008
-		return empty( $state ) ? wpinv_get_default_state() : $state;
1000
+     * Get the customer's state.
1001
+     *
1002
+     * @since 1.0.19
1003
+     * @param  string $context View or edit context.
1004
+     * @return string
1005
+     */
1006
+    public function get_state( $context = 'view' ) {
1007
+        $state = $this->get_prop( 'state', $context );
1008
+        return empty( $state ) ? wpinv_get_default_state() : $state;
1009 1009
     }
1010 1010
 
1011 1011
     /**
1012
-	 * Alias of self::get_state().
1013
-	 *
1014
-	 * @since 1.0.19
1015
-	 * @param  string $context View or edit context.
1016
-	 * @return int
1017
-	 */
1018
-	public function get_user_state( $context = 'view' ) {
1019
-		return $this->get_state( $context );
1012
+     * Alias of self::get_state().
1013
+     *
1014
+     * @since 1.0.19
1015
+     * @param  string $context View or edit context.
1016
+     * @return int
1017
+     */
1018
+    public function get_user_state( $context = 'view' ) {
1019
+        return $this->get_state( $context );
1020 1020
     }
1021 1021
 
1022 1022
     /**
1023
-	 * Alias of self::get_state().
1024
-	 *
1025
-	 * @since 1.0.19
1026
-	 * @param  string $context View or edit context.
1027
-	 * @return int
1028
-	 */
1029
-	public function get_customer_state( $context = 'view' ) {
1030
-		return $this->get_state( $context );
1023
+     * Alias of self::get_state().
1024
+     *
1025
+     * @since 1.0.19
1026
+     * @param  string $context View or edit context.
1027
+     * @return int
1028
+     */
1029
+    public function get_customer_state( $context = 'view' ) {
1030
+        return $this->get_state( $context );
1031 1031
     }
1032 1032
 
1033 1033
     /**
1034
-	 * Get the customer's city.
1035
-	 *
1036
-	 * @since 1.0.19
1037
-	 * @param  string $context View or edit context.
1038
-	 * @return string
1039
-	 */
1040
-	public function get_city( $context = 'view' ) {
1041
-		return $this->get_prop( 'city', $context );
1034
+     * Get the customer's city.
1035
+     *
1036
+     * @since 1.0.19
1037
+     * @param  string $context View or edit context.
1038
+     * @return string
1039
+     */
1040
+    public function get_city( $context = 'view' ) {
1041
+        return $this->get_prop( 'city', $context );
1042 1042
     }
1043 1043
 
1044 1044
     /**
1045
-	 * Alias of self::get_city().
1046
-	 *
1047
-	 * @since 1.0.19
1048
-	 * @param  string $context View or edit context.
1049
-	 * @return string
1050
-	 */
1051
-	public function get_user_city( $context = 'view' ) {
1052
-		return $this->get_city( $context );
1045
+     * Alias of self::get_city().
1046
+     *
1047
+     * @since 1.0.19
1048
+     * @param  string $context View or edit context.
1049
+     * @return string
1050
+     */
1051
+    public function get_user_city( $context = 'view' ) {
1052
+        return $this->get_city( $context );
1053 1053
     }
1054 1054
 
1055 1055
     /**
1056
-	 * Alias of self::get_city().
1057
-	 *
1058
-	 * @since 1.0.19
1059
-	 * @param  string $context View or edit context.
1060
-	 * @return string
1061
-	 */
1062
-	public function get_customer_city( $context = 'view' ) {
1063
-		return $this->get_city( $context );
1056
+     * Alias of self::get_city().
1057
+     *
1058
+     * @since 1.0.19
1059
+     * @param  string $context View or edit context.
1060
+     * @return string
1061
+     */
1062
+    public function get_customer_city( $context = 'view' ) {
1063
+        return $this->get_city( $context );
1064 1064
     }
1065 1065
 
1066 1066
     /**
1067
-	 * Get the customer's zip.
1068
-	 *
1069
-	 * @since 1.0.19
1070
-	 * @param  string $context View or edit context.
1071
-	 * @return string
1072
-	 */
1073
-	public function get_zip( $context = 'view' ) {
1074
-		return $this->get_prop( 'zip', $context );
1067
+     * Get the customer's zip.
1068
+     *
1069
+     * @since 1.0.19
1070
+     * @param  string $context View or edit context.
1071
+     * @return string
1072
+     */
1073
+    public function get_zip( $context = 'view' ) {
1074
+        return $this->get_prop( 'zip', $context );
1075 1075
     }
1076 1076
 
1077 1077
     /**
1078
-	 * Alias of self::get_zip().
1079
-	 *
1080
-	 * @since 1.0.19
1081
-	 * @param  string $context View or edit context.
1082
-	 * @return string
1083
-	 */
1084
-	public function get_user_zip( $context = 'view' ) {
1085
-		return $this->get_zip( $context );
1078
+     * Alias of self::get_zip().
1079
+     *
1080
+     * @since 1.0.19
1081
+     * @param  string $context View or edit context.
1082
+     * @return string
1083
+     */
1084
+    public function get_user_zip( $context = 'view' ) {
1085
+        return $this->get_zip( $context );
1086 1086
     }
1087 1087
 
1088 1088
     /**
1089
-	 * Alias of self::get_zip().
1090
-	 *
1091
-	 * @since 1.0.19
1092
-	 * @param  string $context View or edit context.
1093
-	 * @return string
1094
-	 */
1095
-	public function get_customer_zip( $context = 'view' ) {
1096
-		return $this->get_zip( $context );
1089
+     * Alias of self::get_zip().
1090
+     *
1091
+     * @since 1.0.19
1092
+     * @param  string $context View or edit context.
1093
+     * @return string
1094
+     */
1095
+    public function get_customer_zip( $context = 'view' ) {
1096
+        return $this->get_zip( $context );
1097 1097
     }
1098 1098
 
1099 1099
     /**
1100
-	 * Get the customer's company.
1101
-	 *
1102
-	 * @since 1.0.19
1103
-	 * @param  string $context View or edit context.
1104
-	 * @return string
1105
-	 */
1106
-	public function get_company( $context = 'view' ) {
1107
-		return $this->get_prop( 'company', $context );
1100
+     * Get the customer's company.
1101
+     *
1102
+     * @since 1.0.19
1103
+     * @param  string $context View or edit context.
1104
+     * @return string
1105
+     */
1106
+    public function get_company( $context = 'view' ) {
1107
+        return $this->get_prop( 'company', $context );
1108 1108
     }
1109 1109
 
1110 1110
     /**
1111
-	 * Alias of self::get_company().
1112
-	 *
1113
-	 * @since 1.0.19
1114
-	 * @param  string $context View or edit context.
1115
-	 * @return string
1116
-	 */
1117
-	public function get_user_company( $context = 'view' ) {
1118
-		return $this->get_company( $context );
1111
+     * Alias of self::get_company().
1112
+     *
1113
+     * @since 1.0.19
1114
+     * @param  string $context View or edit context.
1115
+     * @return string
1116
+     */
1117
+    public function get_user_company( $context = 'view' ) {
1118
+        return $this->get_company( $context );
1119 1119
     }
1120 1120
 
1121 1121
     /**
1122
-	 * Alias of self::get_company().
1123
-	 *
1124
-	 * @since 1.0.19
1125
-	 * @param  string $context View or edit context.
1126
-	 * @return string
1127
-	 */
1128
-	public function get_customer_company( $context = 'view' ) {
1129
-		return $this->get_company( $context );
1122
+     * Alias of self::get_company().
1123
+     *
1124
+     * @since 1.0.19
1125
+     * @param  string $context View or edit context.
1126
+     * @return string
1127
+     */
1128
+    public function get_customer_company( $context = 'view' ) {
1129
+        return $this->get_company( $context );
1130 1130
     }
1131 1131
 
1132 1132
     /**
1133
-	 * Get the customer's vat number.
1134
-	 *
1135
-	 * @since 1.0.19
1136
-	 * @param  string $context View or edit context.
1137
-	 * @return string
1138
-	 */
1139
-	public function get_vat_number( $context = 'view' ) {
1140
-		return $this->get_prop( 'vat_number', $context );
1133
+     * Get the customer's vat number.
1134
+     *
1135
+     * @since 1.0.19
1136
+     * @param  string $context View or edit context.
1137
+     * @return string
1138
+     */
1139
+    public function get_vat_number( $context = 'view' ) {
1140
+        return $this->get_prop( 'vat_number', $context );
1141 1141
     }
1142 1142
 
1143 1143
     /**
1144
-	 * Alias of self::get_vat_number().
1145
-	 *
1146
-	 * @since 1.0.19
1147
-	 * @param  string $context View or edit context.
1148
-	 * @return string
1149
-	 */
1150
-	public function get_user_vat_number( $context = 'view' ) {
1151
-		return $this->get_vat_number( $context );
1144
+     * Alias of self::get_vat_number().
1145
+     *
1146
+     * @since 1.0.19
1147
+     * @param  string $context View or edit context.
1148
+     * @return string
1149
+     */
1150
+    public function get_user_vat_number( $context = 'view' ) {
1151
+        return $this->get_vat_number( $context );
1152 1152
     }
1153 1153
 
1154 1154
     /**
1155
-	 * Alias of self::get_vat_number().
1156
-	 *
1157
-	 * @since 1.0.19
1158
-	 * @param  string $context View or edit context.
1159
-	 * @return string
1160
-	 */
1161
-	public function get_customer_vat_number( $context = 'view' ) {
1162
-		return $this->get_vat_number( $context );
1155
+     * Alias of self::get_vat_number().
1156
+     *
1157
+     * @since 1.0.19
1158
+     * @param  string $context View or edit context.
1159
+     * @return string
1160
+     */
1161
+    public function get_customer_vat_number( $context = 'view' ) {
1162
+        return $this->get_vat_number( $context );
1163 1163
     }
1164 1164
 
1165 1165
     /**
1166
-	 * Get the customer's vat rate.
1167
-	 *
1168
-	 * @since 1.0.19
1169
-	 * @param  string $context View or edit context.
1170
-	 * @return string
1171
-	 */
1172
-	public function get_vat_rate( $context = 'view' ) {
1173
-		return $this->get_prop( 'vat_rate', $context );
1166
+     * Get the customer's vat rate.
1167
+     *
1168
+     * @since 1.0.19
1169
+     * @param  string $context View or edit context.
1170
+     * @return string
1171
+     */
1172
+    public function get_vat_rate( $context = 'view' ) {
1173
+        return $this->get_prop( 'vat_rate', $context );
1174
+    }
1175
+
1176
+    /**
1177
+     * Alias of self::get_vat_rate().
1178
+     *
1179
+     * @since 1.0.19
1180
+     * @param  string $context View or edit context.
1181
+     * @return string
1182
+     */
1183
+    public function get_user_vat_rate( $context = 'view' ) {
1184
+        return $this->get_vat_rate( $context );
1185
+    }
1186
+
1187
+    /**
1188
+     * Alias of self::get_vat_rate().
1189
+     *
1190
+     * @since 1.0.19
1191
+     * @param  string $context View or edit context.
1192
+     * @return string
1193
+     */
1194
+    public function get_customer_vat_rate( $context = 'view' ) {
1195
+        return $this->get_vat_rate( $context );
1196
+    }
1197
+
1198
+    /**
1199
+     * Get the customer's address.
1200
+     *
1201
+     * @since 1.0.19
1202
+     * @param  string $context View or edit context.
1203
+     * @return string
1204
+     */
1205
+    public function get_address( $context = 'view' ) {
1206
+        return $this->get_prop( 'address', $context );
1207
+    }
1208
+
1209
+    /**
1210
+     * Alias of self::get_address().
1211
+     *
1212
+     * @since 1.0.19
1213
+     * @param  string $context View or edit context.
1214
+     * @return string
1215
+     */
1216
+    public function get_user_address( $context = 'view' ) {
1217
+        return $this->get_address( $context );
1218
+    }
1219
+
1220
+    /**
1221
+     * Alias of self::get_address().
1222
+     *
1223
+     * @since 1.0.19
1224
+     * @param  string $context View or edit context.
1225
+     * @return string
1226
+     */
1227
+    public function get_customer_address( $context = 'view' ) {
1228
+        return $this->get_address( $context );
1229
+    }
1230
+
1231
+    /**
1232
+     * Get whether the customer has viewed the invoice or not.
1233
+     *
1234
+     * @since 1.0.19
1235
+     * @param  string $context View or edit context.
1236
+     * @return bool
1237
+     */
1238
+    public function get_is_viewed( $context = 'view' ) {
1239
+        return (bool) $this->get_prop( 'is_viewed', $context );
1174 1240
     }
1175 1241
 
1176 1242
     /**
1177
-	 * Alias of self::get_vat_rate().
1178
-	 *
1179
-	 * @since 1.0.19
1180
-	 * @param  string $context View or edit context.
1181
-	 * @return string
1182
-	 */
1183
-	public function get_user_vat_rate( $context = 'view' ) {
1184
-		return $this->get_vat_rate( $context );
1243
+     * Get other recipients for invoice communications.
1244
+     *
1245
+     * @since 1.0.19
1246
+     * @param  string $context View or edit context.
1247
+     * @return bool
1248
+     */
1249
+    public function get_email_cc( $context = 'view' ) {
1250
+        return $this->get_prop( 'email_cc', $context );
1185 1251
     }
1186 1252
 
1187 1253
     /**
1188
-	 * Alias of self::get_vat_rate().
1189
-	 *
1190
-	 * @since 1.0.19
1191
-	 * @param  string $context View or edit context.
1192
-	 * @return string
1193
-	 */
1194
-	public function get_customer_vat_rate( $context = 'view' ) {
1195
-		return $this->get_vat_rate( $context );
1254
+     * Get invoice template.
1255
+     *
1256
+     * @since 1.0.19
1257
+     * @param  string $context View or edit context.
1258
+     * @return bool
1259
+     */
1260
+    public function get_template( $context = 'view' ) {
1261
+        return $this->get_prop( 'template', $context );
1196 1262
     }
1197 1263
 
1198 1264
     /**
1199
-	 * Get the customer's address.
1200
-	 *
1201
-	 * @since 1.0.19
1202
-	 * @param  string $context View or edit context.
1203
-	 * @return string
1204
-	 */
1205
-	public function get_address( $context = 'view' ) {
1206
-		return $this->get_prop( 'address', $context );
1207
-    }
1208
-
1209
-    /**
1210
-	 * Alias of self::get_address().
1211
-	 *
1212
-	 * @since 1.0.19
1213
-	 * @param  string $context View or edit context.
1214
-	 * @return string
1215
-	 */
1216
-	public function get_user_address( $context = 'view' ) {
1217
-		return $this->get_address( $context );
1218
-    }
1219
-
1220
-    /**
1221
-	 * Alias of self::get_address().
1222
-	 *
1223
-	 * @since 1.0.19
1224
-	 * @param  string $context View or edit context.
1225
-	 * @return string
1226
-	 */
1227
-	public function get_customer_address( $context = 'view' ) {
1228
-		return $this->get_address( $context );
1229
-    }
1230
-
1231
-    /**
1232
-	 * Get whether the customer has viewed the invoice or not.
1233
-	 *
1234
-	 * @since 1.0.19
1235
-	 * @param  string $context View or edit context.
1236
-	 * @return bool
1237
-	 */
1238
-	public function get_is_viewed( $context = 'view' ) {
1239
-		return (bool) $this->get_prop( 'is_viewed', $context );
1240
-	}
1241
-
1242
-	/**
1243
-	 * Get other recipients for invoice communications.
1244
-	 *
1245
-	 * @since 1.0.19
1246
-	 * @param  string $context View or edit context.
1247
-	 * @return bool
1248
-	 */
1249
-	public function get_email_cc( $context = 'view' ) {
1250
-		return $this->get_prop( 'email_cc', $context );
1251
-	}
1252
-
1253
-	/**
1254
-	 * Get invoice template.
1255
-	 *
1256
-	 * @since 1.0.19
1257
-	 * @param  string $context View or edit context.
1258
-	 * @return bool
1259
-	 */
1260
-	public function get_template( $context = 'view' ) {
1261
-		return $this->get_prop( 'template', $context );
1262
-	}
1263
-
1264
-	/**
1265
-	 * Get whether the customer has confirmed their address.
1266
-	 *
1267
-	 * @since 1.0.19
1268
-	 * @param  string $context View or edit context.
1269
-	 * @return bool
1270
-	 */
1271
-	public function get_address_confirmed( $context = 'view' ) {
1272
-		return (bool) $this->get_prop( 'address_confirmed', $context );
1273
-    }
1274
-
1275
-    /**
1276
-	 * Alias of self::get_address_confirmed().
1277
-	 *
1278
-	 * @since 1.0.19
1279
-	 * @param  string $context View or edit context.
1280
-	 * @return bool
1281
-	 */
1282
-	public function get_user_address_confirmed( $context = 'view' ) {
1283
-		return $this->get_address_confirmed( $context );
1284
-    }
1285
-
1286
-    /**
1287
-	 * Alias of self::get_address().
1288
-	 *
1289
-	 * @since 1.0.19
1290
-	 * @param  string $context View or edit context.
1291
-	 * @return bool
1292
-	 */
1293
-	public function get_customer_address_confirmed( $context = 'view' ) {
1294
-		return $this->get_address_confirmed( $context );
1295
-    }
1296
-
1297
-    /**
1298
-	 * Get the invoice subtotal.
1299
-	 *
1300
-	 * @since 1.0.19
1301
-	 * @param  string $context View or edit context.
1302
-	 * @return float
1303
-	 */
1304
-	public function get_subtotal( $context = 'view' ) {
1265
+     * Get whether the customer has confirmed their address.
1266
+     *
1267
+     * @since 1.0.19
1268
+     * @param  string $context View or edit context.
1269
+     * @return bool
1270
+     */
1271
+    public function get_address_confirmed( $context = 'view' ) {
1272
+        return (bool) $this->get_prop( 'address_confirmed', $context );
1273
+    }
1274
+
1275
+    /**
1276
+     * Alias of self::get_address_confirmed().
1277
+     *
1278
+     * @since 1.0.19
1279
+     * @param  string $context View or edit context.
1280
+     * @return bool
1281
+     */
1282
+    public function get_user_address_confirmed( $context = 'view' ) {
1283
+        return $this->get_address_confirmed( $context );
1284
+    }
1285
+
1286
+    /**
1287
+     * Alias of self::get_address().
1288
+     *
1289
+     * @since 1.0.19
1290
+     * @param  string $context View or edit context.
1291
+     * @return bool
1292
+     */
1293
+    public function get_customer_address_confirmed( $context = 'view' ) {
1294
+        return $this->get_address_confirmed( $context );
1295
+    }
1296
+
1297
+    /**
1298
+     * Get the invoice subtotal.
1299
+     *
1300
+     * @since 1.0.19
1301
+     * @param  string $context View or edit context.
1302
+     * @return float
1303
+     */
1304
+    public function get_subtotal( $context = 'view' ) {
1305 1305
         $subtotal = (float) $this->get_prop( 'subtotal', $context );
1306 1306
 
1307 1307
         // Backwards compatibility.
@@ -1313,165 +1313,165 @@  discard block
 block discarded – undo
1313 1313
     }
1314 1314
 
1315 1315
     /**
1316
-	 * Get the invoice discount total.
1317
-	 *
1318
-	 * @since 1.0.19
1319
-	 * @param  string $context View or edit context.
1320
-	 * @return float
1321
-	 */
1322
-	public function get_total_discount( $context = 'view' ) {
1323
-		return (float) $this->get_prop( 'total_discount', $context );
1316
+     * Get the invoice discount total.
1317
+     *
1318
+     * @since 1.0.19
1319
+     * @param  string $context View or edit context.
1320
+     * @return float
1321
+     */
1322
+    public function get_total_discount( $context = 'view' ) {
1323
+        return (float) $this->get_prop( 'total_discount', $context );
1324 1324
     }
1325 1325
 
1326 1326
     /**
1327
-	 * Get the invoice tax total.
1328
-	 *
1329
-	 * @since 1.0.19
1330
-	 * @param  string $context View or edit context.
1331
-	 * @return float
1332
-	 */
1333
-	public function get_total_tax( $context = 'view' ) {
1334
-		return (float) $this->get_prop( 'total_tax', $context );
1335
-	}
1327
+     * Get the invoice tax total.
1328
+     *
1329
+     * @since 1.0.19
1330
+     * @param  string $context View or edit context.
1331
+     * @return float
1332
+     */
1333
+    public function get_total_tax( $context = 'view' ) {
1334
+        return (float) $this->get_prop( 'total_tax', $context );
1335
+    }
1336 1336
 
1337
-	/**
1338
-	 * @deprecated
1339
-	 */
1340
-	public function get_final_tax( $currency = false ) {
1341
-		$tax = $this->get_total_tax();
1337
+    /**
1338
+     * @deprecated
1339
+     */
1340
+    public function get_final_tax( $currency = false ) {
1341
+        $tax = $this->get_total_tax();
1342 1342
 
1343 1343
         if ( $currency ) {
1344
-			return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() );
1344
+            return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() );
1345 1345
         }
1346 1346
 
1347 1347
         return $tax;
1348 1348
     }
1349 1349
 
1350 1350
     /**
1351
-	 * Get the invoice fees total.
1352
-	 *
1353
-	 * @since 1.0.19
1354
-	 * @param  string $context View or edit context.
1355
-	 * @return float
1356
-	 */
1357
-	public function get_total_fees( $context = 'view' ) {
1358
-		return (float) $this->get_prop( 'total_fees', $context );
1351
+     * Get the invoice fees total.
1352
+     *
1353
+     * @since 1.0.19
1354
+     * @param  string $context View or edit context.
1355
+     * @return float
1356
+     */
1357
+    public function get_total_fees( $context = 'view' ) {
1358
+        return (float) $this->get_prop( 'total_fees', $context );
1359 1359
     }
1360 1360
 
1361 1361
     /**
1362
-	 * Alias for self::get_total_fees().
1363
-	 *
1364
-	 * @since 1.0.19
1365
-	 * @param  string $context View or edit context.
1366
-	 * @return float
1367
-	 */
1368
-	public function get_fees_total( $context = 'view' ) {
1369
-		return $this->get_total_fees( $context );
1362
+     * Alias for self::get_total_fees().
1363
+     *
1364
+     * @since 1.0.19
1365
+     * @param  string $context View or edit context.
1366
+     * @return float
1367
+     */
1368
+    public function get_fees_total( $context = 'view' ) {
1369
+        return $this->get_total_fees( $context );
1370 1370
     }
1371 1371
 
1372 1372
     /**
1373
-	 * Get the invoice total.
1374
-	 *
1375
-	 * @since 1.0.19
1373
+     * Get the invoice total.
1374
+     *
1375
+     * @since 1.0.19
1376 1376
      * @return float
1377
-	 */
1378
-	public function get_total() {
1379
-		$total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total();
1380
-		return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this  );
1381
-	}
1377
+     */
1378
+    public function get_total() {
1379
+        $total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total();
1380
+        return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this  );
1381
+    }
1382 1382
 	
1383
-	/**
1384
-	 * Get the invoice totals.
1385
-	 *
1386
-	 * @since 1.0.19
1383
+    /**
1384
+     * Get the invoice totals.
1385
+     *
1386
+     * @since 1.0.19
1387 1387
      * @return float
1388
-	 */
1389
-	public function get_totals() {
1390
-		return $this->totals;
1388
+     */
1389
+    public function get_totals() {
1390
+        return $this->totals;
1391 1391
     }
1392 1392
 
1393 1393
     /**
1394
-	 * Get the initial invoice total.
1395
-	 *
1396
-	 * @since 1.0.19
1394
+     * Get the initial invoice total.
1395
+     *
1396
+     * @since 1.0.19
1397 1397
      * @param  string $context View or edit context.
1398 1398
      * @return float
1399
-	 */
1399
+     */
1400 1400
     public function get_initial_total() {
1401 1401
 
1402
-		if ( empty( $this->totals ) ) {
1403
-			$this->recalculate_total();
1404
-		}
1402
+        if ( empty( $this->totals ) ) {
1403
+            $this->recalculate_total();
1404
+        }
1405 1405
 
1406
-		$tax      = $this->totals['tax']['initial'];
1407
-		$fee      = $this->totals['fee']['initial'];
1408
-		$discount = $this->totals['discount']['initial'];
1409
-		$subtotal = $this->totals['subtotal']['initial'];
1410
-		$total    = $tax + $fee - $discount + $subtotal;
1406
+        $tax      = $this->totals['tax']['initial'];
1407
+        $fee      = $this->totals['fee']['initial'];
1408
+        $discount = $this->totals['discount']['initial'];
1409
+        $subtotal = $this->totals['subtotal']['initial'];
1410
+        $total    = $tax + $fee - $discount + $subtotal;
1411 1411
 
1412
-		if ( 0 > $total ) {
1413
-			$total = 0;
1414
-		}
1412
+        if ( 0 > $total ) {
1413
+            $total = 0;
1414
+        }
1415 1415
 
1416 1416
         return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this );
1417
-	}
1417
+    }
1418 1418
 
1419
-	/**
1420
-	 * Get the recurring invoice total.
1421
-	 *
1422
-	 * @since 1.0.19
1419
+    /**
1420
+     * Get the recurring invoice total.
1421
+     *
1422
+     * @since 1.0.19
1423 1423
      * @param  string $context View or edit context.
1424 1424
      * @return float
1425
-	 */
1425
+     */
1426 1426
     public function get_recurring_total() {
1427 1427
 
1428
-		if ( empty( $this->totals ) ) {
1429
-			$this->recalculate_total();
1430
-		}
1428
+        if ( empty( $this->totals ) ) {
1429
+            $this->recalculate_total();
1430
+        }
1431 1431
 
1432
-		$tax      = $this->totals['tax']['recurring'];
1433
-		$fee      = $this->totals['fee']['recurring'];
1434
-		$discount = $this->totals['discount']['recurring'];
1435
-		$subtotal = $this->totals['subtotal']['recurring'];
1436
-		$total    = $tax + $fee - $discount + $subtotal;
1432
+        $tax      = $this->totals['tax']['recurring'];
1433
+        $fee      = $this->totals['fee']['recurring'];
1434
+        $discount = $this->totals['discount']['recurring'];
1435
+        $subtotal = $this->totals['subtotal']['recurring'];
1436
+        $total    = $tax + $fee - $discount + $subtotal;
1437 1437
 
1438
-		if ( 0 > $total ) {
1439
-			$total = 0;
1440
-		}
1438
+        if ( 0 > $total ) {
1439
+            $total = 0;
1440
+        }
1441 1441
 
1442 1442
         return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this );
1443
-	}
1443
+    }
1444 1444
 
1445
-	/**
1446
-	 * Returns recurring payment details.
1447
-	 *
1448
-	 * @since 1.0.19
1445
+    /**
1446
+     * Returns recurring payment details.
1447
+     *
1448
+     * @since 1.0.19
1449 1449
      * @param  string $field Optionally provide a field to return.
1450
-	 * @param string $currency Whether to include the currency.
1450
+     * @param string $currency Whether to include the currency.
1451 1451
      * @return float
1452
-	 */
1452
+     */
1453 1453
     public function get_recurring_details( $field = '', $currency = false ) {
1454 1454
 
1455
-		// Maybe recalculate totals.
1456
-		if ( empty( $this->totals ) ) {
1457
-			$this->recalculate_total();
1458
-		}
1455
+        // Maybe recalculate totals.
1456
+        if ( empty( $this->totals ) ) {
1457
+            $this->recalculate_total();
1458
+        }
1459 1459
 
1460
-		// Prepare recurring totals.
1460
+        // Prepare recurring totals.
1461 1461
         $data = apply_filters(
1462
-			'wpinv_get_invoice_recurring_details',
1463
-			array(
1464
-				'cart_details' => $this->get_cart_details(),
1465
-				'subtotal'     => $this->totals['subtotal']['recurring'],
1466
-				'discount'     => $this->totals['discount']['recurring'],
1467
-				'tax'          => $this->totals['tax']['recurring'],
1468
-				'fee'          => $this->totals['fee']['recurring'],
1469
-				'total'        => $this->get_recurring_total(),
1470
-			),
1471
-			$this,
1472
-			$field,
1473
-			$currency
1474
-		);
1462
+            'wpinv_get_invoice_recurring_details',
1463
+            array(
1464
+                'cart_details' => $this->get_cart_details(),
1465
+                'subtotal'     => $this->totals['subtotal']['recurring'],
1466
+                'discount'     => $this->totals['discount']['recurring'],
1467
+                'tax'          => $this->totals['tax']['recurring'],
1468
+                'fee'          => $this->totals['fee']['recurring'],
1469
+                'total'        => $this->get_recurring_total(),
1470
+            ),
1471
+            $this,
1472
+            $field,
1473
+            $currency
1474
+        );
1475 1475
 
1476 1476
         if ( isset( $data[$field] ) ) {
1477 1477
             return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
@@ -1481,145 +1481,145 @@  discard block
 block discarded – undo
1481 1481
     }
1482 1482
 
1483 1483
     /**
1484
-	 * Get the invoice fees.
1485
-	 *
1486
-	 * @since 1.0.19
1487
-	 * @param  string $context View or edit context.
1488
-	 * @return array
1489
-	 */
1490
-	public function get_fees( $context = 'view' ) {
1491
-		return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1484
+     * Get the invoice fees.
1485
+     *
1486
+     * @since 1.0.19
1487
+     * @param  string $context View or edit context.
1488
+     * @return array
1489
+     */
1490
+    public function get_fees( $context = 'view' ) {
1491
+        return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1492 1492
     }
1493 1493
 
1494 1494
     /**
1495
-	 * Get the invoice discounts.
1496
-	 *
1497
-	 * @since 1.0.19
1498
-	 * @param  string $context View or edit context.
1499
-	 * @return array
1500
-	 */
1501
-	public function get_discounts( $context = 'view' ) {
1502
-		return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1495
+     * Get the invoice discounts.
1496
+     *
1497
+     * @since 1.0.19
1498
+     * @param  string $context View or edit context.
1499
+     * @return array
1500
+     */
1501
+    public function get_discounts( $context = 'view' ) {
1502
+        return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1503 1503
     }
1504 1504
 
1505 1505
     /**
1506
-	 * Get the invoice taxes.
1507
-	 *
1508
-	 * @since 1.0.19
1509
-	 * @param  string $context View or edit context.
1510
-	 * @return array
1511
-	 */
1512
-	public function get_taxes( $context = 'view' ) {
1513
-		return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1506
+     * Get the invoice taxes.
1507
+     *
1508
+     * @since 1.0.19
1509
+     * @param  string $context View or edit context.
1510
+     * @return array
1511
+     */
1512
+    public function get_taxes( $context = 'view' ) {
1513
+        return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1514 1514
     }
1515 1515
 
1516 1516
     /**
1517
-	 * Get the invoice items.
1518
-	 *
1519
-	 * @since 1.0.19
1520
-	 * @param  string $context View or edit context.
1521
-	 * @return GetPaid_Form_Item[]
1522
-	 */
1523
-	public function get_items( $context = 'view' ) {
1517
+     * Get the invoice items.
1518
+     *
1519
+     * @since 1.0.19
1520
+     * @param  string $context View or edit context.
1521
+     * @return GetPaid_Form_Item[]
1522
+     */
1523
+    public function get_items( $context = 'view' ) {
1524 1524
         return $this->get_prop( 'items', $context );
1525 1525
     }
1526 1526
 
1527 1527
     /**
1528
-	 * Get the invoice's payment form.
1529
-	 *
1530
-	 * @since 1.0.19
1531
-	 * @param  string $context View or edit context.
1532
-	 * @return int
1533
-	 */
1534
-	public function get_payment_form( $context = 'view' ) {
1535
-		return intval( $this->get_prop( 'payment_form', $context ) );
1528
+     * Get the invoice's payment form.
1529
+     *
1530
+     * @since 1.0.19
1531
+     * @param  string $context View or edit context.
1532
+     * @return int
1533
+     */
1534
+    public function get_payment_form( $context = 'view' ) {
1535
+        return intval( $this->get_prop( 'payment_form', $context ) );
1536 1536
     }
1537 1537
 
1538 1538
     /**
1539
-	 * Get the invoice's submission id.
1540
-	 *
1541
-	 * @since 1.0.19
1542
-	 * @param  string $context View or edit context.
1543
-	 * @return string
1544
-	 */
1545
-	public function get_submission_id( $context = 'view' ) {
1546
-		return $this->get_prop( 'submission_id', $context );
1539
+     * Get the invoice's submission id.
1540
+     *
1541
+     * @since 1.0.19
1542
+     * @param  string $context View or edit context.
1543
+     * @return string
1544
+     */
1545
+    public function get_submission_id( $context = 'view' ) {
1546
+        return $this->get_prop( 'submission_id', $context );
1547 1547
     }
1548 1548
 
1549 1549
     /**
1550
-	 * Get the invoice's discount code.
1551
-	 *
1552
-	 * @since 1.0.19
1553
-	 * @param  string $context View or edit context.
1554
-	 * @return string
1555
-	 */
1556
-	public function get_discount_code( $context = 'view' ) {
1557
-		return $this->get_prop( 'discount_code', $context );
1550
+     * Get the invoice's discount code.
1551
+     *
1552
+     * @since 1.0.19
1553
+     * @param  string $context View or edit context.
1554
+     * @return string
1555
+     */
1556
+    public function get_discount_code( $context = 'view' ) {
1557
+        return $this->get_prop( 'discount_code', $context );
1558 1558
     }
1559 1559
 
1560 1560
     /**
1561
-	 * Get the invoice's gateway.
1562
-	 *
1563
-	 * @since 1.0.19
1564
-	 * @param  string $context View or edit context.
1565
-	 * @return string
1566
-	 */
1567
-	public function get_gateway( $context = 'view' ) {
1568
-		return $this->get_prop( 'gateway', $context );
1561
+     * Get the invoice's gateway.
1562
+     *
1563
+     * @since 1.0.19
1564
+     * @param  string $context View or edit context.
1565
+     * @return string
1566
+     */
1567
+    public function get_gateway( $context = 'view' ) {
1568
+        return $this->get_prop( 'gateway', $context );
1569 1569
     }
1570 1570
 
1571 1571
     /**
1572
-	 * Get the invoice's gateway display title.
1573
-	 *
1574
-	 * @since 1.0.19
1575
-	 * @return string
1576
-	 */
1572
+     * Get the invoice's gateway display title.
1573
+     *
1574
+     * @since 1.0.19
1575
+     * @return string
1576
+     */
1577 1577
     public function get_gateway_title() {
1578 1578
         $title =  wpinv_get_gateway_checkout_label( $this->get_gateway() );
1579 1579
         return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this );
1580 1580
     }
1581 1581
 
1582 1582
     /**
1583
-	 * Get the invoice's transaction id.
1584
-	 *
1585
-	 * @since 1.0.19
1586
-	 * @param  string $context View or edit context.
1587
-	 * @return string
1588
-	 */
1589
-	public function get_transaction_id( $context = 'view' ) {
1590
-		return $this->get_prop( 'transaction_id', $context );
1583
+     * Get the invoice's transaction id.
1584
+     *
1585
+     * @since 1.0.19
1586
+     * @param  string $context View or edit context.
1587
+     * @return string
1588
+     */
1589
+    public function get_transaction_id( $context = 'view' ) {
1590
+        return $this->get_prop( 'transaction_id', $context );
1591 1591
     }
1592 1592
 
1593 1593
     /**
1594
-	 * Get the invoice's currency.
1595
-	 *
1596
-	 * @since 1.0.19
1597
-	 * @param  string $context View or edit context.
1598
-	 * @return string
1599
-	 */
1600
-	public function get_currency( $context = 'view' ) {
1594
+     * Get the invoice's currency.
1595
+     *
1596
+     * @since 1.0.19
1597
+     * @param  string $context View or edit context.
1598
+     * @return string
1599
+     */
1600
+    public function get_currency( $context = 'view' ) {
1601 1601
         $currency = $this->get_prop( 'currency', $context );
1602 1602
         return empty( $currency ) ? wpinv_get_currency() : $currency;
1603 1603
     }
1604 1604
 
1605 1605
     /**
1606
-	 * Checks if we are charging taxes for this invoice.
1607
-	 *
1608
-	 * @since 1.0.19
1609
-	 * @param  string $context View or edit context.
1610
-	 * @return bool
1611
-	 */
1612
-	public function get_disable_taxes( $context = 'view' ) {
1606
+     * Checks if we are charging taxes for this invoice.
1607
+     *
1608
+     * @since 1.0.19
1609
+     * @param  string $context View or edit context.
1610
+     * @return bool
1611
+     */
1612
+    public function get_disable_taxes( $context = 'view' ) {
1613 1613
         return (bool) $this->get_prop( 'disable_taxes', $context );
1614 1614
     }
1615 1615
 
1616 1616
     /**
1617
-	 * Retrieves the remote subscription id for an invoice.
1618
-	 *
1619
-	 * @since 1.0.19
1620
-	 * @param  string $context View or edit context.
1621
-	 * @return int
1622
-	 */
1617
+     * Retrieves the remote subscription id for an invoice.
1618
+     *
1619
+     * @since 1.0.19
1620
+     * @param  string $context View or edit context.
1621
+     * @return int
1622
+     */
1623 1623
     public function get_subscription_id( $context = 'view' ) {
1624 1624
         $subscription_id = $this->get_prop( 'subscription_id', $context );
1625 1625
 
@@ -1632,12 +1632,12 @@  discard block
 block discarded – undo
1632 1632
     }
1633 1633
 
1634 1634
     /**
1635
-	 * Retrieves the payment meta for an invoice.
1636
-	 *
1637
-	 * @since 1.0.19
1638
-	 * @param  string $context View or edit context.
1639
-	 * @return array
1640
-	 */
1635
+     * Retrieves the payment meta for an invoice.
1636
+     *
1637
+     * @since 1.0.19
1638
+     * @param  string $context View or edit context.
1639
+     * @return array
1640
+     */
1641 1641
     public function get_payment_meta( $context = 'view' ) {
1642 1642
 
1643 1643
         return array(
@@ -1657,11 +1657,11 @@  discard block
 block discarded – undo
1657 1657
     }
1658 1658
 
1659 1659
     /**
1660
-	 * Retrieves the cart details for an invoice.
1661
-	 *
1662
-	 * @since 1.0.19
1663
-	 * @return array
1664
-	 */
1660
+     * Retrieves the cart details for an invoice.
1661
+     *
1662
+     * @since 1.0.19
1663
+     * @return array
1664
+     */
1665 1665
     public function get_cart_details() {
1666 1666
         $items        = $this->get_items();
1667 1667
         $cart_details = array();
@@ -1671,16 +1671,16 @@  discard block
 block discarded – undo
1671 1671
         }
1672 1672
 
1673 1673
         return $cart_details;
1674
-	}
1674
+    }
1675 1675
 
1676
-	/**
1677
-	 * Retrieves the recurring item.
1678
-	 *
1679
-	 * @return null|GetPaid_Form_Item|int
1680
-	 */
1681
-	public function get_recurring( $object = false ) {
1676
+    /**
1677
+     * Retrieves the recurring item.
1678
+     *
1679
+     * @return null|GetPaid_Form_Item|int
1680
+     */
1681
+    public function get_recurring( $object = false ) {
1682 1682
 
1683
-		// Are we returning an object?
1683
+        // Are we returning an object?
1684 1684
         if ( $object ) {
1685 1685
             return $this->get_item( $this->recurring_item );
1686 1686
         }
@@ -1688,100 +1688,100 @@  discard block
 block discarded – undo
1688 1688
         return $this->recurring_item;
1689 1689
     }
1690 1690
 
1691
-	/**
1692
-	 * Retrieves the subscription name.
1693
-	 *
1694
-	 * @since 1.0.19
1695
-	 * @return string
1696
-	 */
1697
-	public function get_subscription_name() {
1691
+    /**
1692
+     * Retrieves the subscription name.
1693
+     *
1694
+     * @since 1.0.19
1695
+     * @return string
1696
+     */
1697
+    public function get_subscription_name() {
1698 1698
 
1699
-		// Retrieve the recurring name
1699
+        // Retrieve the recurring name
1700 1700
         $item = $this->get_recurring( true );
1701 1701
 
1702
-		// Abort if it does not exist.
1702
+        // Abort if it does not exist.
1703 1703
         if ( empty( $item ) ) {
1704 1704
             return '';
1705 1705
         }
1706 1706
 
1707
-		// Return the item name.
1707
+        // Return the item name.
1708 1708
         return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this );
1709
-	}
1710
-
1711
-	/**
1712
-	 * Retrieves the view url.
1713
-	 *
1714
-	 * @since 1.0.19
1715
-	 * @return string
1716
-	 */
1717
-	public function get_view_url() {
1709
+    }
1710
+
1711
+    /**
1712
+     * Retrieves the view url.
1713
+     *
1714
+     * @since 1.0.19
1715
+     * @return string
1716
+     */
1717
+    public function get_view_url() {
1718 1718
         $invoice_url = get_permalink( $this->get_id() );
1719
-		$invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1719
+        $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1720 1720
         return apply_filters( 'wpinv_get_view_url', $invoice_url, $this );
1721
-	}
1721
+    }
1722 1722
 
1723
-	/**
1724
-	 * Retrieves the payment url.
1725
-	 *
1726
-	 * @since 1.0.19
1727
-	 * @return string
1728
-	 */
1729
-	public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1723
+    /**
1724
+     * Retrieves the payment url.
1725
+     *
1726
+     * @since 1.0.19
1727
+     * @return string
1728
+     */
1729
+    public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1730 1730
 
1731
-		// Retrieve the checkout url.
1731
+        // Retrieve the checkout url.
1732 1732
         $pay_url = wpinv_get_checkout_uri();
1733 1733
 
1734
-		// Maybe force ssl.
1734
+        // Maybe force ssl.
1735 1735
         if ( is_ssl() ) {
1736 1736
             $pay_url = str_replace( 'http:', 'https:', $pay_url );
1737 1737
         }
1738 1738
 
1739
-		// Add the invoice key.
1740
-		$pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1739
+        // Add the invoice key.
1740
+        $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1741 1741
 
1742
-		// (Maybe?) add a secret
1742
+        // (Maybe?) add a secret
1743 1743
         if ( $secret ) {
1744 1744
             $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url );
1745 1745
         }
1746 1746
 
1747 1747
         return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret );
1748
-	}
1748
+    }
1749 1749
 	
1750
-	/**
1751
-	 * Retrieves the receipt url.
1752
-	 *
1753
-	 * @since 1.0.19
1754
-	 * @return string
1755
-	 */
1756
-	public function get_receipt_url() {
1757
-
1758
-		// Retrieve the checkout url.
1750
+    /**
1751
+     * Retrieves the receipt url.
1752
+     *
1753
+     * @since 1.0.19
1754
+     * @return string
1755
+     */
1756
+    public function get_receipt_url() {
1757
+
1758
+        // Retrieve the checkout url.
1759 1759
         $receipt_url = wpinv_get_success_page_uri();
1760 1760
 
1761
-		// Maybe force ssl.
1761
+        // Maybe force ssl.
1762 1762
         if ( is_ssl() ) {
1763 1763
             $receipt_url = str_replace( 'http:', 'https:', $receipt_url );
1764 1764
         }
1765 1765
 
1766
-		// Add the invoice key.
1767
-		$receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url );
1766
+        // Add the invoice key.
1767
+        $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url );
1768 1768
 
1769 1769
         return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this );
1770 1770
     }
1771 1771
 
1772 1772
     /**
1773
-	 * Magic method for accessing invoice properties.
1774
-	 *
1775
-	 * @since 1.0.15
1776
-	 * @access public
1777
-	 *
1778
-	 * @param string $key Discount data to retrieve
1779
-	 * @param  string $context View or edit context.
1780
-	 * @return mixed Value of the given invoice property (if set).
1781
-	 */
1782
-	public function get( $key, $context = 'view' ) {
1773
+     * Magic method for accessing invoice properties.
1774
+     *
1775
+     * @since 1.0.15
1776
+     * @access public
1777
+     *
1778
+     * @param string $key Discount data to retrieve
1779
+     * @param  string $context View or edit context.
1780
+     * @return mixed Value of the given invoice property (if set).
1781
+     */
1782
+    public function get( $key, $context = 'view' ) {
1783 1783
         return $this->get_prop( $key, $context );
1784
-	}
1784
+    }
1785 1785
 
1786 1786
     /*
1787 1787
 	|--------------------------------------------------------------------------
@@ -1794,130 +1794,130 @@  discard block
 block discarded – undo
1794 1794
     */
1795 1795
 
1796 1796
     /**
1797
-	 * Magic method for setting invoice properties.
1798
-	 *
1799
-	 * @since 1.0.19
1800
-	 * @access public
1801
-	 *
1802
-	 * @param string $key Discount data to retrieve
1803
-	 * @param  mixed $value new value.
1804
-	 * @return mixed Value of the given invoice property (if set).
1805
-	 */
1806
-	public function set( $key, $value ) {
1797
+     * Magic method for setting invoice properties.
1798
+     *
1799
+     * @since 1.0.19
1800
+     * @access public
1801
+     *
1802
+     * @param string $key Discount data to retrieve
1803
+     * @param  mixed $value new value.
1804
+     * @return mixed Value of the given invoice property (if set).
1805
+     */
1806
+    public function set( $key, $value ) {
1807 1807
 
1808 1808
         $setter = "set_$key";
1809 1809
         if ( is_callable( array( $this, $setter ) ) ) {
1810 1810
             $this->{$setter}( $value );
1811 1811
         }
1812 1812
 
1813
-	}
1813
+    }
1814 1814
 
1815
-	/**
1816
-	 * Sets item status.
1817
-	 *
1818
-	 * @since 1.0.19
1819
-	 * @param string $new_status    New status.
1820
-	 * @param string $note          Optional note to add.
1821
-	 * @param bool   $manual_update Is this a manual status change?.
1822
-	 * @return array details of change.
1823
-	 */
1824
-	public function set_status( $new_status, $note = '', $manual_update = false ) {
1825
-		$old_status = $this->get_status();
1815
+    /**
1816
+     * Sets item status.
1817
+     *
1818
+     * @since 1.0.19
1819
+     * @param string $new_status    New status.
1820
+     * @param string $note          Optional note to add.
1821
+     * @param bool   $manual_update Is this a manual status change?.
1822
+     * @return array details of change.
1823
+     */
1824
+    public function set_status( $new_status, $note = '', $manual_update = false ) {
1825
+        $old_status = $this->get_status();
1826 1826
 
1827
-		$statuses = $this->get_all_statuses();
1827
+        $statuses = $this->get_all_statuses();
1828 1828
 
1829
-		if ( isset( $statuses[ 'draft' ] ) ) {
1830
-			unset( $statuses[ 'draft' ] );
1831
-		}
1829
+        if ( isset( $statuses[ 'draft' ] ) ) {
1830
+            unset( $statuses[ 'draft' ] );
1831
+        }
1832 1832
 
1833
-		$this->set_prop( 'status', $new_status );
1833
+        $this->set_prop( 'status', $new_status );
1834 1834
 
1835
-		// If setting the status, ensure it's set to a valid status.
1836
-		if ( true === $this->object_read ) {
1835
+        // If setting the status, ensure it's set to a valid status.
1836
+        if ( true === $this->object_read ) {
1837 1837
 
1838
-			// Only allow valid new status.
1839
-			if ( ! array_key_exists( $new_status, $statuses ) ) {
1840
-				$new_status = 'wpi-pending';
1841
-			}
1838
+            // Only allow valid new status.
1839
+            if ( ! array_key_exists( $new_status, $statuses ) ) {
1840
+                $new_status = 'wpi-pending';
1841
+            }
1842 1842
 
1843
-			// If the old status is set but unknown (e.g. draft) assume its pending for action usage.
1844
-			if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) {
1845
-				$old_status = 'wpi-pending';
1846
-			}
1843
+            // If the old status is set but unknown (e.g. draft) assume its pending for action usage.
1844
+            if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) {
1845
+                $old_status = 'wpi-pending';
1846
+            }
1847 1847
 
1848
-			// Paid - Renewal (i.e when duplicating a parent invoice )
1849
-			if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) {
1850
-				$old_status = 'wpi-pending';
1851
-			}
1848
+            // Paid - Renewal (i.e when duplicating a parent invoice )
1849
+            if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) {
1850
+                $old_status = 'wpi-pending';
1851
+            }
1852 1852
 
1853
-		}
1853
+        }
1854 1854
 
1855
-		if ( true === $this->object_read && $old_status !== $new_status ) {
1856
-			$this->status_transition = array(
1857
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
1858
-				'to'     => $new_status,
1859
-				'note'   => $note,
1860
-				'manual' => (bool) $manual_update,
1861
-			);
1855
+        if ( true === $this->object_read && $old_status !== $new_status ) {
1856
+            $this->status_transition = array(
1857
+                'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
1858
+                'to'     => $new_status,
1859
+                'note'   => $note,
1860
+                'manual' => (bool) $manual_update,
1861
+            );
1862 1862
 
1863
-			if ( $manual_update ) {
1864
-				do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
1865
-			}
1863
+            if ( $manual_update ) {
1864
+                do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
1865
+            }
1866 1866
 
1867
-			$this->maybe_set_date_paid();
1867
+            $this->maybe_set_date_paid();
1868 1868
 
1869
-		}
1869
+        }
1870 1870
 
1871
-		return array(
1872
-			'from' => $old_status,
1873
-			'to'   => $new_status,
1874
-		);
1875
-	}
1871
+        return array(
1872
+            'from' => $old_status,
1873
+            'to'   => $new_status,
1874
+        );
1875
+    }
1876 1876
 
1877
-	/**
1878
-	 * Maybe set date paid.
1879
-	 *
1880
-	 * Sets the date paid variable when transitioning to the payment complete
1881
-	 * order status.
1882
-	 *
1883
-	 * @since 1.0.19
1884
-	 */
1885
-	public function maybe_set_date_paid() {
1877
+    /**
1878
+     * Maybe set date paid.
1879
+     *
1880
+     * Sets the date paid variable when transitioning to the payment complete
1881
+     * order status.
1882
+     *
1883
+     * @since 1.0.19
1884
+     */
1885
+    public function maybe_set_date_paid() {
1886 1886
 
1887
-		if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
1888
-			$this->set_date_completed( current_time( 'mysql' ) );
1889
-		}
1890
-	}
1887
+        if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
1888
+            $this->set_date_completed( current_time( 'mysql' ) );
1889
+        }
1890
+    }
1891 1891
 
1892 1892
     /**
1893
-	 * Set parent invoice ID.
1894
-	 *
1895
-	 * @since 1.0.19
1896
-	 */
1897
-	public function set_parent_id( $value ) {
1898
-		if ( $value && ( $value === $this->get_id() ) ) {
1899
-			return;
1900
-		}
1901
-		$this->set_prop( 'parent_id', absint( $value ) );
1893
+     * Set parent invoice ID.
1894
+     *
1895
+     * @since 1.0.19
1896
+     */
1897
+    public function set_parent_id( $value ) {
1898
+        if ( $value && ( $value === $this->get_id() ) ) {
1899
+            return;
1900
+        }
1901
+        $this->set_prop( 'parent_id', absint( $value ) );
1902 1902
     }
1903 1903
 
1904 1904
     /**
1905
-	 * Set plugin version when the invoice was created.
1906
-	 *
1907
-	 * @since 1.0.19
1908
-	 */
1909
-	public function set_version( $value ) {
1910
-		$this->set_prop( 'version', $value );
1905
+     * Set plugin version when the invoice was created.
1906
+     *
1907
+     * @since 1.0.19
1908
+     */
1909
+    public function set_version( $value ) {
1910
+        $this->set_prop( 'version', $value );
1911 1911
     }
1912
-
1913
-    /**
1914
-	 * Set date when the invoice was created.
1915
-	 *
1916
-	 * @since 1.0.19
1917
-	 * @param string $value Value to set.
1912
+
1913
+    /**
1914
+     * Set date when the invoice was created.
1915
+     *
1916
+     * @since 1.0.19
1917
+     * @param string $value Value to set.
1918 1918
      * @return bool Whether or not the date was set.
1919
-	 */
1920
-	public function set_date_created( $value ) {
1919
+     */
1920
+    public function set_date_created( $value ) {
1921 1921
         $date = strtotime( $value );
1922 1922
 
1923 1923
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -1930,13 +1930,13 @@  discard block
 block discarded – undo
1930 1930
     }
1931 1931
 
1932 1932
     /**
1933
-	 * Set date invoice due date.
1934
-	 *
1935
-	 * @since 1.0.19
1936
-	 * @param string $value Value to set.
1933
+     * Set date invoice due date.
1934
+     *
1935
+     * @since 1.0.19
1936
+     * @param string $value Value to set.
1937 1937
      * @return bool Whether or not the date was set.
1938
-	 */
1939
-	public function set_due_date( $value ) {
1938
+     */
1939
+    public function set_due_date( $value ) {
1940 1940
         $date = strtotime( $value );
1941 1941
 
1942 1942
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -1944,29 +1944,29 @@  discard block
 block discarded – undo
1944 1944
             return true;
1945 1945
         }
1946 1946
 
1947
-		$this->set_prop( 'due_date', '' );
1947
+        $this->set_prop( 'due_date', '' );
1948 1948
         return false;
1949 1949
 
1950 1950
     }
1951 1951
 
1952 1952
     /**
1953
-	 * Alias of self::set_due_date().
1954
-	 *
1955
-	 * @since 1.0.19
1956
-	 * @param  string $value New name.
1957
-	 */
1958
-	public function set_date_due( $value ) {
1959
-		$this->set_due_date( $value );
1953
+     * Alias of self::set_due_date().
1954
+     *
1955
+     * @since 1.0.19
1956
+     * @param  string $value New name.
1957
+     */
1958
+    public function set_date_due( $value ) {
1959
+        $this->set_due_date( $value );
1960 1960
     }
1961 1961
 
1962 1962
     /**
1963
-	 * Set date invoice was completed.
1964
-	 *
1965
-	 * @since 1.0.19
1966
-	 * @param string $value Value to set.
1963
+     * Set date invoice was completed.
1964
+     *
1965
+     * @since 1.0.19
1966
+     * @param string $value Value to set.
1967 1967
      * @return bool Whether or not the date was set.
1968
-	 */
1969
-	public function set_completed_date( $value ) {
1968
+     */
1969
+    public function set_completed_date( $value ) {
1970 1970
         $date = strtotime( $value );
1971 1971
 
1972 1972
         if ( $date && $value !== '0000-00-00 00:00:00'  ) {
@@ -1974,29 +1974,29 @@  discard block
 block discarded – undo
1974 1974
             return true;
1975 1975
         }
1976 1976
 
1977
-		$this->set_prop( 'completed_date', '' );
1977
+        $this->set_prop( 'completed_date', '' );
1978 1978
         return false;
1979 1979
 
1980 1980
     }
1981 1981
 
1982 1982
     /**
1983
-	 * Alias of self::set_completed_date().
1984
-	 *
1985
-	 * @since 1.0.19
1986
-	 * @param  string $value New name.
1987
-	 */
1988
-	public function set_date_completed( $value ) {
1989
-		$this->set_completed_date( $value );
1983
+     * Alias of self::set_completed_date().
1984
+     *
1985
+     * @since 1.0.19
1986
+     * @param  string $value New name.
1987
+     */
1988
+    public function set_date_completed( $value ) {
1989
+        $this->set_completed_date( $value );
1990 1990
     }
1991 1991
 
1992 1992
     /**
1993
-	 * Set date when the invoice was last modified.
1994
-	 *
1995
-	 * @since 1.0.19
1996
-	 * @param string $value Value to set.
1993
+     * Set date when the invoice was last modified.
1994
+     *
1995
+     * @since 1.0.19
1996
+     * @param string $value Value to set.
1997 1997
      * @return bool Whether or not the date was set.
1998
-	 */
1999
-	public function set_date_modified( $value ) {
1998
+     */
1999
+    public function set_date_modified( $value ) {
2000 2000
         $date = strtotime( $value );
2001 2001
 
2002 2002
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -2004,706 +2004,706 @@  discard block
 block discarded – undo
2004 2004
             return true;
2005 2005
         }
2006 2006
 
2007
-		$this->set_prop( 'date_modified', '' );
2007
+        $this->set_prop( 'date_modified', '' );
2008 2008
         return false;
2009 2009
 
2010 2010
     }
2011 2011
 
2012 2012
     /**
2013
-	 * Set the invoice number.
2014
-	 *
2015
-	 * @since 1.0.19
2016
-	 * @param  string $value New number.
2017
-	 */
2018
-	public function set_number( $value ) {
2013
+     * Set the invoice number.
2014
+     *
2015
+     * @since 1.0.19
2016
+     * @param  string $value New number.
2017
+     */
2018
+    public function set_number( $value ) {
2019 2019
         $number = sanitize_text_field( $value );
2020
-		$this->set_prop( 'number', $number );
2020
+        $this->set_prop( 'number', $number );
2021 2021
     }
2022 2022
 
2023 2023
     /**
2024
-	 * Set the invoice type.
2025
-	 *
2026
-	 * @since 1.0.19
2027
-	 * @param  string $value Type.
2028
-	 */
2029
-	public function set_type( $value ) {
2024
+     * Set the invoice type.
2025
+     *
2026
+     * @since 1.0.19
2027
+     * @param  string $value Type.
2028
+     */
2029
+    public function set_type( $value ) {
2030 2030
         $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) );
2031
-		$this->set_prop( 'type', $type );
2032
-	}
2031
+        $this->set_prop( 'type', $type );
2032
+    }
2033 2033
 
2034 2034
     /**
2035
-	 * Set the invoice post type.
2036
-	 *
2037
-	 * @since 1.0.19
2038
-	 * @param  string $value Post type.
2039
-	 */
2040
-	public function set_post_type( $value ) {
2035
+     * Set the invoice post type.
2036
+     *
2037
+     * @since 1.0.19
2038
+     * @param  string $value Post type.
2039
+     */
2040
+    public function set_post_type( $value ) {
2041 2041
         if ( getpaid_is_invoice_post_type( $value ) ) {
2042
-			$this->set_type( $value );
2042
+            $this->set_type( $value );
2043 2043
             $this->set_prop( 'post_type', $value );
2044 2044
         }
2045 2045
     }
2046 2046
 
2047 2047
     /**
2048
-	 * Set the invoice key.
2049
-	 *
2050
-	 * @since 1.0.19
2051
-	 * @param  string $value New key.
2052
-	 */
2053
-	public function set_key( $value ) {
2048
+     * Set the invoice key.
2049
+     *
2050
+     * @since 1.0.19
2051
+     * @param  string $value New key.
2052
+     */
2053
+    public function set_key( $value ) {
2054 2054
         $key = sanitize_text_field( $value );
2055
-		$this->set_prop( 'key', $key );
2055
+        $this->set_prop( 'key', $key );
2056 2056
     }
2057 2057
 
2058 2058
     /**
2059
-	 * Set the invoice mode.
2060
-	 *
2061
-	 * @since 1.0.19
2062
-	 * @param  string $value mode.
2063
-	 */
2064
-	public function set_mode( $value ) {
2059
+     * Set the invoice mode.
2060
+     *
2061
+     * @since 1.0.19
2062
+     * @param  string $value mode.
2063
+     */
2064
+    public function set_mode( $value ) {
2065 2065
         if ( ! in_array( $value, array( 'live', 'test' ) ) ) {
2066 2066
             $this->set_prop( 'value', $value );
2067 2067
         }
2068 2068
     }
2069 2069
 
2070 2070
     /**
2071
-	 * Set the invoice path.
2072
-	 *
2073
-	 * @since 1.0.19
2074
-	 * @param  string $value path.
2075
-	 */
2076
-	public function set_path( $value ) {
2071
+     * Set the invoice path.
2072
+     *
2073
+     * @since 1.0.19
2074
+     * @param  string $value path.
2075
+     */
2076
+    public function set_path( $value ) {
2077 2077
         $this->set_prop( 'path', $value );
2078 2078
     }
2079 2079
 
2080 2080
     /**
2081
-	 * Set the invoice name.
2082
-	 *
2083
-	 * @since 1.0.19
2084
-	 * @param  string $value New name.
2085
-	 */
2086
-	public function set_name( $value ) {
2081
+     * Set the invoice name.
2082
+     *
2083
+     * @since 1.0.19
2084
+     * @param  string $value New name.
2085
+     */
2086
+    public function set_name( $value ) {
2087 2087
         $name = sanitize_text_field( $value );
2088
-		$this->set_prop( 'name', $name );
2088
+        $this->set_prop( 'name', $name );
2089 2089
     }
2090 2090
 
2091 2091
     /**
2092
-	 * Alias of self::set_name().
2093
-	 *
2094
-	 * @since 1.0.19
2095
-	 * @param  string $value New name.
2096
-	 */
2097
-	public function set_title( $value ) {
2098
-		$this->set_name( $value );
2092
+     * Alias of self::set_name().
2093
+     *
2094
+     * @since 1.0.19
2095
+     * @param  string $value New name.
2096
+     */
2097
+    public function set_title( $value ) {
2098
+        $this->set_name( $value );
2099 2099
     }
2100 2100
 
2101 2101
     /**
2102
-	 * Set the invoice description.
2103
-	 *
2104
-	 * @since 1.0.19
2105
-	 * @param  string $value New description.
2106
-	 */
2107
-	public function set_description( $value ) {
2102
+     * Set the invoice description.
2103
+     *
2104
+     * @since 1.0.19
2105
+     * @param  string $value New description.
2106
+     */
2107
+    public function set_description( $value ) {
2108 2108
         $description = wp_kses_post( $value );
2109
-		return $this->set_prop( 'description', $description );
2109
+        return $this->set_prop( 'description', $description );
2110 2110
     }
2111 2111
 
2112 2112
     /**
2113
-	 * Alias of self::set_description().
2114
-	 *
2115
-	 * @since 1.0.19
2116
-	 * @param  string $value New description.
2117
-	 */
2118
-	public function set_excerpt( $value ) {
2119
-		$this->set_description( $value );
2113
+     * Alias of self::set_description().
2114
+     *
2115
+     * @since 1.0.19
2116
+     * @param  string $value New description.
2117
+     */
2118
+    public function set_excerpt( $value ) {
2119
+        $this->set_description( $value );
2120 2120
     }
2121 2121
 
2122 2122
     /**
2123
-	 * Alias of self::set_description().
2124
-	 *
2125
-	 * @since 1.0.19
2126
-	 * @param  string $value New description.
2127
-	 */
2128
-	public function set_summary( $value ) {
2129
-		$this->set_description( $value );
2123
+     * Alias of self::set_description().
2124
+     *
2125
+     * @since 1.0.19
2126
+     * @param  string $value New description.
2127
+     */
2128
+    public function set_summary( $value ) {
2129
+        $this->set_description( $value );
2130 2130
     }
2131 2131
 
2132 2132
     /**
2133
-	 * Set the receiver of the invoice.
2134
-	 *
2135
-	 * @since 1.0.19
2136
-	 * @param  int $value New author.
2137
-	 */
2138
-	public function set_author( $value ) {
2139
-		$user = get_user_by( 'id', (int) $value );
2133
+     * Set the receiver of the invoice.
2134
+     *
2135
+     * @since 1.0.19
2136
+     * @param  int $value New author.
2137
+     */
2138
+    public function set_author( $value ) {
2139
+        $user = get_user_by( 'id', (int) $value );
2140 2140
 
2141
-		if ( $user && $user->ID ) {
2142
-			$this->set_prop( 'author', $user->ID );
2143
-			$this->set_prop( 'email', $user->user_email );
2144
-		}
2141
+        if ( $user && $user->ID ) {
2142
+            $this->set_prop( 'author', $user->ID );
2143
+            $this->set_prop( 'email', $user->user_email );
2144
+        }
2145 2145
 		
2146 2146
     }
2147 2147
 
2148 2148
     /**
2149
-	 * Alias of self::set_author().
2150
-	 *
2151
-	 * @since 1.0.19
2152
-	 * @param  int $value New user id.
2153
-	 */
2154
-	public function set_user_id( $value ) {
2155
-		$this->set_author( $value );
2149
+     * Alias of self::set_author().
2150
+     *
2151
+     * @since 1.0.19
2152
+     * @param  int $value New user id.
2153
+     */
2154
+    public function set_user_id( $value ) {
2155
+        $this->set_author( $value );
2156 2156
     }
2157 2157
 
2158 2158
     /**
2159
-	 * Alias of self::set_author().
2160
-	 *
2161
-	 * @since 1.0.19
2162
-	 * @param  int $value New user id.
2163
-	 */
2164
-	public function set_customer_id( $value ) {
2165
-		$this->set_author( $value );
2159
+     * Alias of self::set_author().
2160
+     *
2161
+     * @since 1.0.19
2162
+     * @param  int $value New user id.
2163
+     */
2164
+    public function set_customer_id( $value ) {
2165
+        $this->set_author( $value );
2166 2166
     }
2167 2167
 
2168 2168
     /**
2169
-	 * Set the customer's ip.
2170
-	 *
2171
-	 * @since 1.0.19
2172
-	 * @param  string $value ip address.
2173
-	 */
2174
-	public function set_ip( $value ) {
2175
-		$this->set_prop( 'ip', $value );
2169
+     * Set the customer's ip.
2170
+     *
2171
+     * @since 1.0.19
2172
+     * @param  string $value ip address.
2173
+     */
2174
+    public function set_ip( $value ) {
2175
+        $this->set_prop( 'ip', $value );
2176 2176
     }
2177 2177
 
2178 2178
     /**
2179
-	 * Alias of self::set_ip().
2180
-	 *
2181
-	 * @since 1.0.19
2182
-	 * @param  string $value ip address.
2183
-	 */
2184
-	public function set_user_ip( $value ) {
2185
-		$this->set_ip( $value );
2179
+     * Alias of self::set_ip().
2180
+     *
2181
+     * @since 1.0.19
2182
+     * @param  string $value ip address.
2183
+     */
2184
+    public function set_user_ip( $value ) {
2185
+        $this->set_ip( $value );
2186 2186
     }
2187 2187
 
2188 2188
     /**
2189
-	 * Set the customer's first name.
2190
-	 *
2191
-	 * @since 1.0.19
2192
-	 * @param  string $value first name.
2193
-	 */
2194
-	public function set_first_name( $value ) {
2195
-		$this->set_prop( 'first_name', $value );
2189
+     * Set the customer's first name.
2190
+     *
2191
+     * @since 1.0.19
2192
+     * @param  string $value first name.
2193
+     */
2194
+    public function set_first_name( $value ) {
2195
+        $this->set_prop( 'first_name', $value );
2196
+    }
2197
+
2198
+    /**
2199
+     * Alias of self::set_first_name().
2200
+     *
2201
+     * @since 1.0.19
2202
+     * @param  string $value first name.
2203
+     */
2204
+    public function set_user_first_name( $value ) {
2205
+        $this->set_first_name( $value );
2206
+    }
2207
+
2208
+    /**
2209
+     * Alias of self::set_first_name().
2210
+     *
2211
+     * @since 1.0.19
2212
+     * @param  string $value first name.
2213
+     */
2214
+    public function set_customer_first_name( $value ) {
2215
+        $this->set_first_name( $value );
2196 2216
     }
2197 2217
 
2198 2218
     /**
2199
-	 * Alias of self::set_first_name().
2200
-	 *
2201
-	 * @since 1.0.19
2202
-	 * @param  string $value first name.
2203
-	 */
2204
-	public function set_user_first_name( $value ) {
2205
-		$this->set_first_name( $value );
2219
+     * Set the customer's last name.
2220
+     *
2221
+     * @since 1.0.19
2222
+     * @param  string $value last name.
2223
+     */
2224
+    public function set_last_name( $value ) {
2225
+        $this->set_prop( 'last_name', $value );
2226
+    }
2227
+
2228
+    /**
2229
+     * Alias of self::set_last_name().
2230
+     *
2231
+     * @since 1.0.19
2232
+     * @param  string $value last name.
2233
+     */
2234
+    public function set_user_last_name( $value ) {
2235
+        $this->set_last_name( $value );
2206 2236
     }
2207 2237
 
2208 2238
     /**
2209
-	 * Alias of self::set_first_name().
2210
-	 *
2211
-	 * @since 1.0.19
2212
-	 * @param  string $value first name.
2213
-	 */
2214
-	public function set_customer_first_name( $value ) {
2215
-		$this->set_first_name( $value );
2239
+     * Alias of self::set_last_name().
2240
+     *
2241
+     * @since 1.0.19
2242
+     * @param  string $value last name.
2243
+     */
2244
+    public function set_customer_last_name( $value ) {
2245
+        $this->set_last_name( $value );
2216 2246
     }
2217 2247
 
2218 2248
     /**
2219
-	 * Set the customer's last name.
2220
-	 *
2221
-	 * @since 1.0.19
2222
-	 * @param  string $value last name.
2223
-	 */
2224
-	public function set_last_name( $value ) {
2225
-		$this->set_prop( 'last_name', $value );
2249
+     * Set the customer's phone number.
2250
+     *
2251
+     * @since 1.0.19
2252
+     * @param  string $value phone.
2253
+     */
2254
+    public function set_phone( $value ) {
2255
+        $this->set_prop( 'phone', $value );
2226 2256
     }
2227 2257
 
2228 2258
     /**
2229
-	 * Alias of self::set_last_name().
2230
-	 *
2231
-	 * @since 1.0.19
2232
-	 * @param  string $value last name.
2233
-	 */
2234
-	public function set_user_last_name( $value ) {
2235
-		$this->set_last_name( $value );
2259
+     * Alias of self::set_phone().
2260
+     *
2261
+     * @since 1.0.19
2262
+     * @param  string $value phone.
2263
+     */
2264
+    public function set_user_phone( $value ) {
2265
+        $this->set_phone( $value );
2236 2266
     }
2237 2267
 
2238 2268
     /**
2239
-	 * Alias of self::set_last_name().
2240
-	 *
2241
-	 * @since 1.0.19
2242
-	 * @param  string $value last name.
2243
-	 */
2244
-	public function set_customer_last_name( $value ) {
2245
-		$this->set_last_name( $value );
2269
+     * Alias of self::set_phone().
2270
+     *
2271
+     * @since 1.0.19
2272
+     * @param  string $value phone.
2273
+     */
2274
+    public function set_customer_phone( $value ) {
2275
+        $this->set_phone( $value );
2246 2276
     }
2247 2277
 
2248 2278
     /**
2249
-	 * Set the customer's phone number.
2250
-	 *
2251
-	 * @since 1.0.19
2252
-	 * @param  string $value phone.
2253
-	 */
2254
-	public function set_phone( $value ) {
2255
-		$this->set_prop( 'phone', $value );
2279
+     * Alias of self::set_phone().
2280
+     *
2281
+     * @since 1.0.19
2282
+     * @param  string $value phone.
2283
+     */
2284
+    public function set_phone_number( $value ) {
2285
+        $this->set_phone( $value );
2256 2286
     }
2257 2287
 
2258 2288
     /**
2259
-	 * Alias of self::set_phone().
2260
-	 *
2261
-	 * @since 1.0.19
2262
-	 * @param  string $value phone.
2263
-	 */
2264
-	public function set_user_phone( $value ) {
2265
-		$this->set_phone( $value );
2289
+     * Set the customer's email address.
2290
+     *
2291
+     * @since 1.0.19
2292
+     * @param  string $value email address.
2293
+     */
2294
+    public function set_email( $value ) {
2295
+        $this->set_prop( 'email', $value );
2266 2296
     }
2267 2297
 
2268 2298
     /**
2269
-	 * Alias of self::set_phone().
2270
-	 *
2271
-	 * @since 1.0.19
2272
-	 * @param  string $value phone.
2273
-	 */
2274
-	public function set_customer_phone( $value ) {
2275
-		$this->set_phone( $value );
2299
+     * Alias of self::set_email().
2300
+     *
2301
+     * @since 1.0.19
2302
+     * @param  string $value email address.
2303
+     */
2304
+    public function set_user_email( $value ) {
2305
+        $this->set_email( $value );
2276 2306
     }
2277 2307
 
2278 2308
     /**
2279
-	 * Alias of self::set_phone().
2280
-	 *
2281
-	 * @since 1.0.19
2282
-	 * @param  string $value phone.
2283
-	 */
2284
-	public function set_phone_number( $value ) {
2285
-		$this->set_phone( $value );
2309
+     * Alias of self::set_email().
2310
+     *
2311
+     * @since 1.0.19
2312
+     * @param  string $value email address.
2313
+     */
2314
+    public function set_email_address( $value ) {
2315
+        $this->set_email( $value );
2286 2316
     }
2287 2317
 
2288 2318
     /**
2289
-	 * Set the customer's email address.
2290
-	 *
2291
-	 * @since 1.0.19
2292
-	 * @param  string $value email address.
2293
-	 */
2294
-	public function set_email( $value ) {
2295
-		$this->set_prop( 'email', $value );
2319
+     * Alias of self::set_email().
2320
+     *
2321
+     * @since 1.0.19
2322
+     * @param  string $value email address.
2323
+     */
2324
+    public function set_customer_email( $value ) {
2325
+        $this->set_email( $value );
2296 2326
     }
2297 2327
 
2298 2328
     /**
2299
-	 * Alias of self::set_email().
2300
-	 *
2301
-	 * @since 1.0.19
2302
-	 * @param  string $value email address.
2303
-	 */
2304
-	public function set_user_email( $value ) {
2305
-		$this->set_email( $value );
2329
+     * Set the customer's country.
2330
+     *
2331
+     * @since 1.0.19
2332
+     * @param  string $value country.
2333
+     */
2334
+    public function set_country( $value ) {
2335
+        $this->set_prop( 'country', $value );
2306 2336
     }
2307 2337
 
2308 2338
     /**
2309
-	 * Alias of self::set_email().
2310
-	 *
2311
-	 * @since 1.0.19
2312
-	 * @param  string $value email address.
2313
-	 */
2314
-	public function set_email_address( $value ) {
2315
-		$this->set_email( $value );
2339
+     * Alias of self::set_country().
2340
+     *
2341
+     * @since 1.0.19
2342
+     * @param  string $value country.
2343
+     */
2344
+    public function set_user_country( $value ) {
2345
+        $this->set_country( $value );
2316 2346
     }
2317 2347
 
2318 2348
     /**
2319
-	 * Alias of self::set_email().
2320
-	 *
2321
-	 * @since 1.0.19
2322
-	 * @param  string $value email address.
2323
-	 */
2324
-	public function set_customer_email( $value ) {
2325
-		$this->set_email( $value );
2349
+     * Alias of self::set_country().
2350
+     *
2351
+     * @since 1.0.19
2352
+     * @param  string $value country.
2353
+     */
2354
+    public function set_customer_country( $value ) {
2355
+        $this->set_country( $value );
2326 2356
     }
2327 2357
 
2328 2358
     /**
2329
-	 * Set the customer's country.
2330
-	 *
2331
-	 * @since 1.0.19
2332
-	 * @param  string $value country.
2333
-	 */
2334
-	public function set_country( $value ) {
2335
-		$this->set_prop( 'country', $value );
2359
+     * Set the customer's state.
2360
+     *
2361
+     * @since 1.0.19
2362
+     * @param  string $value state.
2363
+     */
2364
+    public function set_state( $value ) {
2365
+        $this->set_prop( 'state', $value );
2336 2366
     }
2337 2367
 
2338 2368
     /**
2339
-	 * Alias of self::set_country().
2340
-	 *
2341
-	 * @since 1.0.19
2342
-	 * @param  string $value country.
2343
-	 */
2344
-	public function set_user_country( $value ) {
2345
-		$this->set_country( $value );
2369
+     * Alias of self::set_state().
2370
+     *
2371
+     * @since 1.0.19
2372
+     * @param  string $value state.
2373
+     */
2374
+    public function set_user_state( $value ) {
2375
+        $this->set_state( $value );
2346 2376
     }
2347 2377
 
2348 2378
     /**
2349
-	 * Alias of self::set_country().
2350
-	 *
2351
-	 * @since 1.0.19
2352
-	 * @param  string $value country.
2353
-	 */
2354
-	public function set_customer_country( $value ) {
2355
-		$this->set_country( $value );
2379
+     * Alias of self::set_state().
2380
+     *
2381
+     * @since 1.0.19
2382
+     * @param  string $value state.
2383
+     */
2384
+    public function set_customer_state( $value ) {
2385
+        $this->set_state( $value );
2356 2386
     }
2357 2387
 
2358 2388
     /**
2359
-	 * Set the customer's state.
2360
-	 *
2361
-	 * @since 1.0.19
2362
-	 * @param  string $value state.
2363
-	 */
2364
-	public function set_state( $value ) {
2365
-		$this->set_prop( 'state', $value );
2389
+     * Set the customer's city.
2390
+     *
2391
+     * @since 1.0.19
2392
+     * @param  string $value city.
2393
+     */
2394
+    public function set_city( $value ) {
2395
+        $this->set_prop( 'city', $value );
2366 2396
     }
2367 2397
 
2368 2398
     /**
2369
-	 * Alias of self::set_state().
2370
-	 *
2371
-	 * @since 1.0.19
2372
-	 * @param  string $value state.
2373
-	 */
2374
-	public function set_user_state( $value ) {
2375
-		$this->set_state( $value );
2399
+     * Alias of self::set_city().
2400
+     *
2401
+     * @since 1.0.19
2402
+     * @param  string $value city.
2403
+     */
2404
+    public function set_user_city( $value ) {
2405
+        $this->set_city( $value );
2376 2406
     }
2377 2407
 
2378 2408
     /**
2379
-	 * Alias of self::set_state().
2380
-	 *
2381
-	 * @since 1.0.19
2382
-	 * @param  string $value state.
2383
-	 */
2384
-	public function set_customer_state( $value ) {
2385
-		$this->set_state( $value );
2409
+     * Alias of self::set_city().
2410
+     *
2411
+     * @since 1.0.19
2412
+     * @param  string $value city.
2413
+     */
2414
+    public function set_customer_city( $value ) {
2415
+        $this->set_city( $value );
2386 2416
     }
2387 2417
 
2388 2418
     /**
2389
-	 * Set the customer's city.
2390
-	 *
2391
-	 * @since 1.0.19
2392
-	 * @param  string $value city.
2393
-	 */
2394
-	public function set_city( $value ) {
2395
-		$this->set_prop( 'city', $value );
2419
+     * Set the customer's zip code.
2420
+     *
2421
+     * @since 1.0.19
2422
+     * @param  string $value zip.
2423
+     */
2424
+    public function set_zip( $value ) {
2425
+        $this->set_prop( 'zip', $value );
2396 2426
     }
2397 2427
 
2398 2428
     /**
2399
-	 * Alias of self::set_city().
2400
-	 *
2401
-	 * @since 1.0.19
2402
-	 * @param  string $value city.
2403
-	 */
2404
-	public function set_user_city( $value ) {
2405
-		$this->set_city( $value );
2429
+     * Alias of self::set_zip().
2430
+     *
2431
+     * @since 1.0.19
2432
+     * @param  string $value zip.
2433
+     */
2434
+    public function set_user_zip( $value ) {
2435
+        $this->set_zip( $value );
2406 2436
     }
2407 2437
 
2408 2438
     /**
2409
-	 * Alias of self::set_city().
2410
-	 *
2411
-	 * @since 1.0.19
2412
-	 * @param  string $value city.
2413
-	 */
2414
-	public function set_customer_city( $value ) {
2415
-		$this->set_city( $value );
2439
+     * Alias of self::set_zip().
2440
+     *
2441
+     * @since 1.0.19
2442
+     * @param  string $value zip.
2443
+     */
2444
+    public function set_customer_zip( $value ) {
2445
+        $this->set_zip( $value );
2416 2446
     }
2417 2447
 
2418 2448
     /**
2419
-	 * Set the customer's zip code.
2420
-	 *
2421
-	 * @since 1.0.19
2422
-	 * @param  string $value zip.
2423
-	 */
2424
-	public function set_zip( $value ) {
2425
-		$this->set_prop( 'zip', $value );
2449
+     * Set the customer's company.
2450
+     *
2451
+     * @since 1.0.19
2452
+     * @param  string $value company.
2453
+     */
2454
+    public function set_company( $value ) {
2455
+        $this->set_prop( 'company', $value );
2426 2456
     }
2427 2457
 
2428 2458
     /**
2429
-	 * Alias of self::set_zip().
2430
-	 *
2431
-	 * @since 1.0.19
2432
-	 * @param  string $value zip.
2433
-	 */
2434
-	public function set_user_zip( $value ) {
2435
-		$this->set_zip( $value );
2459
+     * Alias of self::set_company().
2460
+     *
2461
+     * @since 1.0.19
2462
+     * @param  string $value company.
2463
+     */
2464
+    public function set_user_company( $value ) {
2465
+        $this->set_company( $value );
2436 2466
     }
2437 2467
 
2438 2468
     /**
2439
-	 * Alias of self::set_zip().
2440
-	 *
2441
-	 * @since 1.0.19
2442
-	 * @param  string $value zip.
2443
-	 */
2444
-	public function set_customer_zip( $value ) {
2445
-		$this->set_zip( $value );
2469
+     * Alias of self::set_company().
2470
+     *
2471
+     * @since 1.0.19
2472
+     * @param  string $value company.
2473
+     */
2474
+    public function set_customer_company( $value ) {
2475
+        $this->set_company( $value );
2446 2476
     }
2447 2477
 
2448 2478
     /**
2449
-	 * Set the customer's company.
2450
-	 *
2451
-	 * @since 1.0.19
2452
-	 * @param  string $value company.
2453
-	 */
2454
-	public function set_company( $value ) {
2455
-		$this->set_prop( 'company', $value );
2479
+     * Set the customer's var number.
2480
+     *
2481
+     * @since 1.0.19
2482
+     * @param  string $value var number.
2483
+     */
2484
+    public function set_vat_number( $value ) {
2485
+        $this->set_prop( 'vat_number', $value );
2456 2486
     }
2457 2487
 
2458 2488
     /**
2459
-	 * Alias of self::set_company().
2460
-	 *
2461
-	 * @since 1.0.19
2462
-	 * @param  string $value company.
2463
-	 */
2464
-	public function set_user_company( $value ) {
2465
-		$this->set_company( $value );
2489
+     * Alias of self::set_vat_number().
2490
+     *
2491
+     * @since 1.0.19
2492
+     * @param  string $value var number.
2493
+     */
2494
+    public function set_user_vat_number( $value ) {
2495
+        $this->set_vat_number( $value );
2466 2496
     }
2467 2497
 
2468 2498
     /**
2469
-	 * Alias of self::set_company().
2470
-	 *
2471
-	 * @since 1.0.19
2472
-	 * @param  string $value company.
2473
-	 */
2474
-	public function set_customer_company( $value ) {
2475
-		$this->set_company( $value );
2499
+     * Alias of self::set_vat_number().
2500
+     *
2501
+     * @since 1.0.19
2502
+     * @param  string $value var number.
2503
+     */
2504
+    public function set_customer_vat_number( $value ) {
2505
+        $this->set_vat_number( $value );
2476 2506
     }
2477 2507
 
2478 2508
     /**
2479
-	 * Set the customer's var number.
2480
-	 *
2481
-	 * @since 1.0.19
2482
-	 * @param  string $value var number.
2483
-	 */
2484
-	public function set_vat_number( $value ) {
2485
-		$this->set_prop( 'vat_number', $value );
2509
+     * Set the customer's vat rate.
2510
+     *
2511
+     * @since 1.0.19
2512
+     * @param  string $value var rate.
2513
+     */
2514
+    public function set_vat_rate( $value ) {
2515
+        $this->set_prop( 'vat_rate', $value );
2486 2516
     }
2487 2517
 
2488 2518
     /**
2489
-	 * Alias of self::set_vat_number().
2490
-	 *
2491
-	 * @since 1.0.19
2492
-	 * @param  string $value var number.
2493
-	 */
2494
-	public function set_user_vat_number( $value ) {
2495
-		$this->set_vat_number( $value );
2519
+     * Alias of self::set_vat_rate().
2520
+     *
2521
+     * @since 1.0.19
2522
+     * @param  string $value var number.
2523
+     */
2524
+    public function set_user_vat_rate( $value ) {
2525
+        $this->set_vat_rate( $value );
2496 2526
     }
2497 2527
 
2498 2528
     /**
2499
-	 * Alias of self::set_vat_number().
2500
-	 *
2501
-	 * @since 1.0.19
2502
-	 * @param  string $value var number.
2503
-	 */
2504
-	public function set_customer_vat_number( $value ) {
2505
-		$this->set_vat_number( $value );
2529
+     * Alias of self::set_vat_rate().
2530
+     *
2531
+     * @since 1.0.19
2532
+     * @param  string $value var number.
2533
+     */
2534
+    public function set_customer_vat_rate( $value ) {
2535
+        $this->set_vat_rate( $value );
2506 2536
     }
2507 2537
 
2508 2538
     /**
2509
-	 * Set the customer's vat rate.
2510
-	 *
2511
-	 * @since 1.0.19
2512
-	 * @param  string $value var rate.
2513
-	 */
2514
-	public function set_vat_rate( $value ) {
2515
-		$this->set_prop( 'vat_rate', $value );
2539
+     * Set the customer's address.
2540
+     *
2541
+     * @since 1.0.19
2542
+     * @param  string $value address.
2543
+     */
2544
+    public function set_address( $value ) {
2545
+        $this->set_prop( 'address', $value );
2516 2546
     }
2517 2547
 
2518 2548
     /**
2519
-	 * Alias of self::set_vat_rate().
2520
-	 *
2521
-	 * @since 1.0.19
2522
-	 * @param  string $value var number.
2523
-	 */
2524
-	public function set_user_vat_rate( $value ) {
2525
-		$this->set_vat_rate( $value );
2549
+     * Alias of self::set_address().
2550
+     *
2551
+     * @since 1.0.19
2552
+     * @param  string $value address.
2553
+     */
2554
+    public function set_user_address( $value ) {
2555
+        $this->set_address( $value );
2526 2556
     }
2527 2557
 
2528 2558
     /**
2529
-	 * Alias of self::set_vat_rate().
2530
-	 *
2531
-	 * @since 1.0.19
2532
-	 * @param  string $value var number.
2533
-	 */
2534
-	public function set_customer_vat_rate( $value ) {
2535
-		$this->set_vat_rate( $value );
2559
+     * Alias of self::set_address().
2560
+     *
2561
+     * @since 1.0.19
2562
+     * @param  string $value address.
2563
+     */
2564
+    public function set_customer_address( $value ) {
2565
+        $this->set_address( $value );
2536 2566
     }
2537 2567
 
2538 2568
     /**
2539
-	 * Set the customer's address.
2540
-	 *
2541
-	 * @since 1.0.19
2542
-	 * @param  string $value address.
2543
-	 */
2544
-	public function set_address( $value ) {
2545
-		$this->set_prop( 'address', $value );
2569
+     * Set whether the customer has viewed the invoice or not.
2570
+     *
2571
+     * @since 1.0.19
2572
+     * @param  int|bool $value confirmed.
2573
+     */
2574
+    public function set_is_viewed( $value ) {
2575
+        $this->set_prop( 'is_viewed', $value );
2546 2576
     }
2547 2577
 
2548 2578
     /**
2549
-	 * Alias of self::set_address().
2550
-	 *
2551
-	 * @since 1.0.19
2552
-	 * @param  string $value address.
2553
-	 */
2554
-	public function set_user_address( $value ) {
2555
-		$this->set_address( $value );
2579
+     * Set extra email recipients.
2580
+     *
2581
+     * @since 1.0.19
2582
+     * @param  string $value email recipients.
2583
+     */
2584
+    public function set_email_cc( $value ) {
2585
+        $this->set_prop( 'email_cc', $value );
2556 2586
     }
2557 2587
 
2558 2588
     /**
2559
-	 * Alias of self::set_address().
2560
-	 *
2561
-	 * @since 1.0.19
2562
-	 * @param  string $value address.
2563
-	 */
2564
-	public function set_customer_address( $value ) {
2565
-		$this->set_address( $value );
2589
+     * Set the invoice template.
2590
+     *
2591
+     * @since 1.0.19
2592
+     * @param  string $value email recipients.
2593
+     */
2594
+    public function set_template( $value ) {
2595
+        if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2596
+            $this->set_prop( 'template', $value );
2597
+        }
2566 2598
     }
2567 2599
 
2568 2600
     /**
2569
-	 * Set whether the customer has viewed the invoice or not.
2570
-	 *
2571
-	 * @since 1.0.19
2572
-	 * @param  int|bool $value confirmed.
2573
-	 */
2574
-	public function set_is_viewed( $value ) {
2575
-		$this->set_prop( 'is_viewed', $value );
2576
-	}
2577
-
2578
-	/**
2579
-	 * Set extra email recipients.
2580
-	 *
2581
-	 * @since 1.0.19
2582
-	 * @param  string $value email recipients.
2583
-	 */
2584
-	public function set_email_cc( $value ) {
2585
-		$this->set_prop( 'email_cc', $value );
2586
-	}
2587
-
2588
-	/**
2589
-	 * Set the invoice template.
2590
-	 *
2591
-	 * @since 1.0.19
2592
-	 * @param  string $value email recipients.
2593
-	 */
2594
-	public function set_template( $value ) {
2595
-		if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2596
-			$this->set_prop( 'template', $value );
2597
-		}
2598
-	}
2599
-
2600
-	/**
2601
-	 * Set the customer's address confirmed status.
2602
-	 *
2603
-	 * @since 1.0.19
2604
-	 * @param  int|bool $value confirmed.
2605
-	 */
2606
-	public function set_address_confirmed( $value ) {
2607
-		$this->set_prop( 'address_confirmed', $value );
2601
+     * Set the customer's address confirmed status.
2602
+     *
2603
+     * @since 1.0.19
2604
+     * @param  int|bool $value confirmed.
2605
+     */
2606
+    public function set_address_confirmed( $value ) {
2607
+        $this->set_prop( 'address_confirmed', $value );
2608 2608
     }
2609 2609
 
2610 2610
     /**
2611
-	 * Alias of self::set_address_confirmed().
2612
-	 *
2613
-	 * @since 1.0.19
2614
-	 * @param  int|bool $value confirmed.
2615
-	 */
2616
-	public function set_user_address_confirmed( $value ) {
2617
-		$this->set_address_confirmed( $value );
2611
+     * Alias of self::set_address_confirmed().
2612
+     *
2613
+     * @since 1.0.19
2614
+     * @param  int|bool $value confirmed.
2615
+     */
2616
+    public function set_user_address_confirmed( $value ) {
2617
+        $this->set_address_confirmed( $value );
2618 2618
     }
2619 2619
 
2620 2620
     /**
2621
-	 * Alias of self::set_address_confirmed().
2622
-	 *
2623
-	 * @since 1.0.19
2624
-	 * @param  int|bool $value confirmed.
2625
-	 */
2626
-	public function set_customer_address_confirmed( $value ) {
2627
-		$this->set_address_confirmed( $value );
2621
+     * Alias of self::set_address_confirmed().
2622
+     *
2623
+     * @since 1.0.19
2624
+     * @param  int|bool $value confirmed.
2625
+     */
2626
+    public function set_customer_address_confirmed( $value ) {
2627
+        $this->set_address_confirmed( $value );
2628 2628
     }
2629 2629
 
2630 2630
     /**
2631
-	 * Set the invoice sub total.
2632
-	 *
2633
-	 * @since 1.0.19
2634
-	 * @param  float $value sub total.
2635
-	 */
2636
-	public function set_subtotal( $value ) {
2637
-		$this->set_prop( 'subtotal', $value );
2631
+     * Set the invoice sub total.
2632
+     *
2633
+     * @since 1.0.19
2634
+     * @param  float $value sub total.
2635
+     */
2636
+    public function set_subtotal( $value ) {
2637
+        $this->set_prop( 'subtotal', $value );
2638 2638
     }
2639 2639
 
2640 2640
     /**
2641
-	 * Set the invoice discount amount.
2642
-	 *
2643
-	 * @since 1.0.19
2644
-	 * @param  float $value discount total.
2645
-	 */
2646
-	public function set_total_discount( $value ) {
2647
-		$this->set_prop( 'total_discount', $value );
2641
+     * Set the invoice discount amount.
2642
+     *
2643
+     * @since 1.0.19
2644
+     * @param  float $value discount total.
2645
+     */
2646
+    public function set_total_discount( $value ) {
2647
+        $this->set_prop( 'total_discount', $value );
2648 2648
     }
2649 2649
 
2650 2650
     /**
2651
-	 * Alias of self::set_total_discount().
2652
-	 *
2653
-	 * @since 1.0.19
2654
-	 * @param  float $value discount total.
2655
-	 */
2656
-	public function set_discount( $value ) {
2657
-		$this->set_total_discount( $value );
2651
+     * Alias of self::set_total_discount().
2652
+     *
2653
+     * @since 1.0.19
2654
+     * @param  float $value discount total.
2655
+     */
2656
+    public function set_discount( $value ) {
2657
+        $this->set_total_discount( $value );
2658 2658
     }
2659 2659
 
2660 2660
     /**
2661
-	 * Set the invoice tax amount.
2662
-	 *
2663
-	 * @since 1.0.19
2664
-	 * @param  float $value tax total.
2665
-	 */
2666
-	public function set_total_tax( $value ) {
2667
-		$this->set_prop( 'total_tax', $value );
2661
+     * Set the invoice tax amount.
2662
+     *
2663
+     * @since 1.0.19
2664
+     * @param  float $value tax total.
2665
+     */
2666
+    public function set_total_tax( $value ) {
2667
+        $this->set_prop( 'total_tax', $value );
2668 2668
     }
2669 2669
 
2670 2670
     /**
2671
-	 * Alias of self::set_total_tax().
2672
-	 *
2673
-	 * @since 1.0.19
2674
-	 * @param  float $value tax total.
2675
-	 */
2676
-	public function set_tax_total( $value ) {
2677
-		$this->set_total_tax( $value );
2671
+     * Alias of self::set_total_tax().
2672
+     *
2673
+     * @since 1.0.19
2674
+     * @param  float $value tax total.
2675
+     */
2676
+    public function set_tax_total( $value ) {
2677
+        $this->set_total_tax( $value );
2678 2678
     }
2679 2679
 
2680 2680
     /**
2681
-	 * Set the invoice fees amount.
2682
-	 *
2683
-	 * @since 1.0.19
2684
-	 * @param  float $value fees total.
2685
-	 */
2686
-	public function set_total_fees( $value ) {
2687
-		$this->set_prop( 'total_fees', $value );
2681
+     * Set the invoice fees amount.
2682
+     *
2683
+     * @since 1.0.19
2684
+     * @param  float $value fees total.
2685
+     */
2686
+    public function set_total_fees( $value ) {
2687
+        $this->set_prop( 'total_fees', $value );
2688 2688
     }
2689 2689
 
2690 2690
     /**
2691
-	 * Alias of self::set_total_fees().
2692
-	 *
2693
-	 * @since 1.0.19
2694
-	 * @param  float $value fees total.
2695
-	 */
2696
-	public function set_fees_total( $value ) {
2697
-		$this->set_total_fees( $value );
2691
+     * Alias of self::set_total_fees().
2692
+     *
2693
+     * @since 1.0.19
2694
+     * @param  float $value fees total.
2695
+     */
2696
+    public function set_fees_total( $value ) {
2697
+        $this->set_total_fees( $value );
2698 2698
     }
2699 2699
 
2700 2700
     /**
2701
-	 * Set the invoice fees.
2702
-	 *
2703
-	 * @since 1.0.19
2704
-	 * @param  array $value fees.
2705
-	 */
2706
-	public function set_fees( $value ) {
2701
+     * Set the invoice fees.
2702
+     *
2703
+     * @since 1.0.19
2704
+     * @param  array $value fees.
2705
+     */
2706
+    public function set_fees( $value ) {
2707 2707
 
2708 2708
         $this->set_prop( 'fees', array() );
2709 2709
 
@@ -2721,23 +2721,23 @@  discard block
 block discarded – undo
2721 2721
     }
2722 2722
 
2723 2723
     /**
2724
-	 * Set the invoice taxes.
2725
-	 *
2726
-	 * @since 1.0.19
2727
-	 * @param  array $value taxes.
2728
-	 */
2729
-	public function set_taxes( $value ) {
2730
-		$this->set_prop( 'taxes', $value );
2724
+     * Set the invoice taxes.
2725
+     *
2726
+     * @since 1.0.19
2727
+     * @param  array $value taxes.
2728
+     */
2729
+    public function set_taxes( $value ) {
2730
+        $this->set_prop( 'taxes', $value );
2731 2731
     }
2732 2732
 
2733 2733
     /**
2734
-	 * Set the invoice discounts.
2735
-	 *
2736
-	 * @since 1.0.19
2737
-	 * @param  array $value discounts.
2738
-	 */
2739
-	public function set_discounts( $value ) {
2740
-		$this->set_prop( 'discounts', array() );
2734
+     * Set the invoice discounts.
2735
+     *
2736
+     * @since 1.0.19
2737
+     * @param  array $value discounts.
2738
+     */
2739
+    public function set_discounts( $value ) {
2740
+        $this->set_prop( 'discounts', array() );
2741 2741
 
2742 2742
         // Ensure that we have an array.
2743 2743
         if ( ! is_array( $value ) ) {
@@ -2752,12 +2752,12 @@  discard block
 block discarded – undo
2752 2752
     }
2753 2753
 
2754 2754
     /**
2755
-	 * Set the invoice items.
2756
-	 *
2757
-	 * @since 1.0.19
2758
-	 * @param  GetPaid_Form_Item[] $value items.
2759
-	 */
2760
-	public function set_items( $value ) {
2755
+     * Set the invoice items.
2756
+     *
2757
+     * @since 1.0.19
2758
+     * @param  GetPaid_Form_Item[] $value items.
2759
+     */
2760
+    public function set_items( $value ) {
2761 2761
 
2762 2762
         // Remove existing items.
2763 2763
         $this->set_prop( 'items', array() );
@@ -2774,85 +2774,85 @@  discard block
 block discarded – undo
2774 2774
     }
2775 2775
 
2776 2776
     /**
2777
-	 * Set the payment form.
2778
-	 *
2779
-	 * @since 1.0.19
2780
-	 * @param  int $value payment form.
2781
-	 */
2782
-	public function set_payment_form( $value ) {
2783
-		$this->set_prop( 'payment_form', $value );
2777
+     * Set the payment form.
2778
+     *
2779
+     * @since 1.0.19
2780
+     * @param  int $value payment form.
2781
+     */
2782
+    public function set_payment_form( $value ) {
2783
+        $this->set_prop( 'payment_form', $value );
2784 2784
     }
2785 2785
 
2786 2786
     /**
2787
-	 * Set the submission id.
2788
-	 *
2789
-	 * @since 1.0.19
2790
-	 * @param  string $value submission id.
2791
-	 */
2792
-	public function set_submission_id( $value ) {
2793
-		$this->set_prop( 'submission_id', $value );
2787
+     * Set the submission id.
2788
+     *
2789
+     * @since 1.0.19
2790
+     * @param  string $value submission id.
2791
+     */
2792
+    public function set_submission_id( $value ) {
2793
+        $this->set_prop( 'submission_id', $value );
2794 2794
     }
2795 2795
 
2796 2796
     /**
2797
-	 * Set the discount code.
2798
-	 *
2799
-	 * @since 1.0.19
2800
-	 * @param  string $value discount code.
2801
-	 */
2802
-	public function set_discount_code( $value ) {
2803
-		$this->set_prop( 'discount_code', $value );
2797
+     * Set the discount code.
2798
+     *
2799
+     * @since 1.0.19
2800
+     * @param  string $value discount code.
2801
+     */
2802
+    public function set_discount_code( $value ) {
2803
+        $this->set_prop( 'discount_code', $value );
2804 2804
     }
2805 2805
 
2806 2806
     /**
2807
-	 * Set the gateway.
2808
-	 *
2809
-	 * @since 1.0.19
2810
-	 * @param  string $value gateway.
2811
-	 */
2812
-	public function set_gateway( $value ) {
2813
-		$this->set_prop( 'gateway', $value );
2807
+     * Set the gateway.
2808
+     *
2809
+     * @since 1.0.19
2810
+     * @param  string $value gateway.
2811
+     */
2812
+    public function set_gateway( $value ) {
2813
+        $this->set_prop( 'gateway', $value );
2814 2814
     }
2815 2815
 
2816 2816
     /**
2817
-	 * Set the transaction id.
2818
-	 *
2819
-	 * @since 1.0.19
2820
-	 * @param  string $value transaction id.
2821
-	 */
2822
-	public function set_transaction_id( $value ) {
2823
-		if ( ! empty( $value ) ) {
2824
-			$this->set_prop( 'transaction_id', $value );
2825
-		}
2817
+     * Set the transaction id.
2818
+     *
2819
+     * @since 1.0.19
2820
+     * @param  string $value transaction id.
2821
+     */
2822
+    public function set_transaction_id( $value ) {
2823
+        if ( ! empty( $value ) ) {
2824
+            $this->set_prop( 'transaction_id', $value );
2825
+        }
2826 2826
     }
2827 2827
 
2828 2828
     /**
2829
-	 * Set the currency id.
2830
-	 *
2831
-	 * @since 1.0.19
2832
-	 * @param  string $value currency id.
2833
-	 */
2834
-	public function set_currency( $value ) {
2835
-		$this->set_prop( 'currency', $value );
2829
+     * Set the currency id.
2830
+     *
2831
+     * @since 1.0.19
2832
+     * @param  string $value currency id.
2833
+     */
2834
+    public function set_currency( $value ) {
2835
+        $this->set_prop( 'currency', $value );
2836 2836
     }
2837 2837
 
2838
-	/**
2839
-	 * Set whether to disable taxes.
2840
-	 *
2841
-	 * @since 1.0.19
2842
-	 * @param  bool $value value.
2843
-	 */
2844
-	public function set_disable_taxes( $value ) {
2845
-		$this->set_prop( 'disable_taxes', (bool) $value );
2846
-	}
2838
+    /**
2839
+     * Set whether to disable taxes.
2840
+     *
2841
+     * @since 1.0.19
2842
+     * @param  bool $value value.
2843
+     */
2844
+    public function set_disable_taxes( $value ) {
2845
+        $this->set_prop( 'disable_taxes', (bool) $value );
2846
+    }
2847 2847
 
2848 2848
     /**
2849
-	 * Set the subscription id.
2850
-	 *
2851
-	 * @since 1.0.19
2852
-	 * @param  string $value subscription id.
2853
-	 */
2854
-	public function set_subscription_id( $value ) {
2855
-		$this->set_prop( 'subscription_id', $value );
2849
+     * Set the subscription id.
2850
+     *
2851
+     * @since 1.0.19
2852
+     * @param  string $value subscription id.
2853
+     */
2854
+    public function set_subscription_id( $value ) {
2855
+        $this->set_prop( 'subscription_id', $value );
2856 2856
     }
2857 2857
 
2858 2858
     /*
@@ -2891,12 +2891,12 @@  discard block
 block discarded – undo
2891 2891
      */
2892 2892
     public function is_taxable() {
2893 2893
         return ! $this->get_disable_taxes();
2894
-	}
2894
+    }
2895 2895
 
2896
-	/**
2897
-	 * @deprecated
2898
-	 */
2899
-	public function has_vat() {
2896
+    /**
2897
+     * @deprecated
2898
+     */
2899
+    public function has_vat() {
2900 2900
         global $wpinv_euvat, $wpi_country;
2901 2901
 
2902 2902
         $requires_vat = false;
@@ -2907,17 +2907,17 @@  discard block
 block discarded – undo
2907 2907
         }
2908 2908
 
2909 2909
         return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2910
-	}
2910
+    }
2911 2911
 
2912
-	/**
2913
-	 * Checks to see if the invoice requires payment.
2914
-	 */
2915
-	public function is_free() {
2912
+    /**
2913
+     * Checks to see if the invoice requires payment.
2914
+     */
2915
+    public function is_free() {
2916 2916
         $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 );
2917 2917
 
2918
-		if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) {
2919
-			$is_free = false;
2920
-		}
2918
+        if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) {
2919
+            $is_free = false;
2920
+        }
2921 2921
 
2922 2922
         return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2923 2923
     }
@@ -2928,46 +2928,46 @@  discard block
 block discarded – undo
2928 2928
     public function is_paid() {
2929 2929
         $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
2930 2930
         return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
2931
-	}
2931
+    }
2932 2932
 
2933
-	/**
2933
+    /**
2934 2934
      * Checks if the invoice needs payment.
2935 2935
      */
2936
-	public function needs_payment() {
2937
-		$needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free();
2936
+    public function needs_payment() {
2937
+        $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free();
2938 2938
         return apply_filters( 'wpinv_needs_payment', $needs_payment, $this );
2939 2939
     }
2940 2940
 
2941
-	/**
2941
+    /**
2942 2942
      * Checks if the invoice is refunded.
2943 2943
      */
2944
-	public function is_refunded() {
2944
+    public function is_refunded() {
2945 2945
         $is_refunded = $this->has_status( 'wpi-refunded' );
2946 2946
         return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
2947
-	}
2947
+    }
2948 2948
 
2949
-	/**
2949
+    /**
2950 2950
      * Checks if the invoice is held.
2951 2951
      */
2952
-	public function is_held() {
2952
+    public function is_held() {
2953 2953
         $is_held = $this->has_status( 'wpi-onhold' );
2954 2954
         return apply_filters( 'wpinv_invoice_is_held', $is_held, $this );
2955
-	}
2955
+    }
2956 2956
 
2957
-	/**
2957
+    /**
2958 2958
      * Checks if the invoice is due.
2959 2959
      */
2960
-	public function is_due() {
2961
-		$due_date = $this->get_due_date();
2962
-		return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date );
2963
-	}
2960
+    public function is_due() {
2961
+        $due_date = $this->get_due_date();
2962
+        return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date );
2963
+    }
2964 2964
 
2965
-	/**
2965
+    /**
2966 2966
      * Checks if the invoice is draft.
2967 2967
      */
2968
-	public function is_draft() {
2968
+    public function is_draft() {
2969 2969
         return $this->has_status( 'draft, auto-draft' );
2970
-	}
2970
+    }
2971 2971
 
2972 2972
     /**
2973 2973
      * Checks if the invoice has a given status.
@@ -2975,9 +2975,9 @@  discard block
 block discarded – undo
2975 2975
     public function has_status( $status ) {
2976 2976
         $status = wpinv_parse_list( $status );
2977 2977
         return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status );
2978
-	}
2978
+    }
2979 2979
 
2980
-	/**
2980
+    /**
2981 2981
      * Checks if the invoice is of a given type.
2982 2982
      */
2983 2983
     public function is_type( $type ) {
@@ -3000,25 +3000,25 @@  discard block
 block discarded – undo
3000 3000
      */
3001 3001
     public function has_free_trial() {
3002 3002
         return $this->is_recurring() && 0 == $this->get_initial_total();
3003
-	}
3003
+    }
3004 3004
 
3005
-	/**
3005
+    /**
3006 3006
      * @deprecated
3007 3007
      */
3008 3008
     public function is_free_trial() {
3009 3009
         $this->has_free_trial();
3010 3010
     }
3011 3011
 
3012
-	/**
3012
+    /**
3013 3013
      * Check if the initial payment if 0.
3014 3014
      *
3015 3015
      */
3016
-	public function is_initial_free() {
3016
+    public function is_initial_free() {
3017 3017
         $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 );
3018 3018
         return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this );
3019 3019
     }
3020 3020
 	
3021
-	/**
3021
+    /**
3022 3022
      * Check if the recurring item has a free trial.
3023 3023
      *
3024 3024
      */
@@ -3031,21 +3031,21 @@  discard block
 block discarded – undo
3031 3031
 
3032 3032
         $item = $this->get_recurring( true );
3033 3033
         return $item->has_free_trial();
3034
-	}
3034
+    }
3035 3035
 
3036
-	/**
3036
+    /**
3037 3037
      * Check if the free trial is a result of a discount.
3038 3038
      */
3039 3039
     public function is_free_trial_from_discount() {
3040
-		return $this->has_free_trial() && ! $this->item_has_free_trial();
3041
-	}
3040
+        return $this->has_free_trial() && ! $this->item_has_free_trial();
3041
+    }
3042 3042
 	
3043
-	/**
3043
+    /**
3044 3044
      * @deprecated
3045 3045
      */
3046 3046
     public function discount_first_payment_only() {
3047 3047
 
3048
-		$discount_code = $this->get_discount_code();
3048
+        $discount_code = $this->get_discount_code();
3049 3049
         if ( empty( $this->discount_code ) || ! $this->is_recurring() ) {
3050 3050
             return true;
3051 3051
         }
@@ -3076,28 +3076,28 @@  discard block
 block discarded – undo
3076 3076
      */
3077 3077
     public function add_item( $item ) {
3078 3078
 
3079
-		if ( is_array( $item ) ) {
3080
-			$item = $this->process_array_item( $item );
3081
-		}
3079
+        if ( is_array( $item ) ) {
3080
+            $item = $this->process_array_item( $item );
3081
+        }
3082 3082
 
3083
-		if ( is_numeric( $item ) ) {
3084
-			$item = new GetPaid_Form_Item( $item );
3085
-		}
3083
+        if ( is_numeric( $item ) ) {
3084
+            $item = new GetPaid_Form_Item( $item );
3085
+        }
3086 3086
 
3087 3087
         // Make sure that it is available for purchase.
3088
-		if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
3089
-			return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
3088
+        if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
3089
+            return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
3090 3090
         }
3091 3091
 
3092 3092
         // Do we have a recurring item?
3093
-		if ( $item->is_recurring() ) {
3093
+        if ( $item->is_recurring() ) {
3094 3094
 
3095
-			// An invoice can only contain one recurring item.
3096
-			if ( ! empty( $this->recurring_item  && $this->recurring_item != (int) $item->get_id() ) ) {
3097
-				return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) );
3098
-			}
3095
+            // An invoice can only contain one recurring item.
3096
+            if ( ! empty( $this->recurring_item  && $this->recurring_item != (int) $item->get_id() ) ) {
3097
+                return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) );
3098
+            }
3099 3099
 
3100
-			$this->recurring_item = $item->get_id();
3100
+            $this->recurring_item = $item->get_id();
3101 3101
         }
3102 3102
 
3103 3103
         // Invoice id.
@@ -3108,60 +3108,60 @@  discard block
 block discarded – undo
3108 3108
         $items[ (int) $item->get_id() ] = $item;
3109 3109
 
3110 3110
         $this->set_prop( 'items', $items );
3111
-		return true;
3112
-	}
3111
+        return true;
3112
+    }
3113 3113
 	
3114
-	/**
3115
-	 * Converts an array to an item.
3116
-	 *
3117
-	 * @since 1.0.19
3118
-	 * @return GetPaid_Form_Item
3119
-	 */
3120
-	protected function process_array_item( $array ) {
3121
-
3122
-		$item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0;
3123
-		$item    = new GetPaid_Form_Item( $item_id );
3124
-
3125
-		// Set item data.
3126
-		foreach( array( 'name', 'price', 'description' ) as $key ) {
3127
-			if ( isset( $array[ "item_$key" ] ) ) {
3128
-				$method = "set_$key";
3129
-				$item->$method( $array[ "item_$key" ] );
3130
-			}
3131
-		}
3132
-
3133
-		if ( isset( $array['quantity'] ) ) {
3134
-			$item->set_quantity( $array['quantity'] );
3135
-		}
3136
-
3137
-		// Set item meta.
3138
-		if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) {
3139
-			$item->set_item_meta( $array['meta'] );
3140
-		}
3141
-
3142
-		return $item;
3143
-
3144
-	}
3145
-
3146
-    /**
3147
-	 * Retrieves a specific item.
3148
-	 *
3149
-	 * @since 1.0.19
3150
-	 */
3151
-	public function get_item( $item_id ) {
3152
-		$items   = $this->get_items();
3153
-		$item_id = (int) $item_id;
3154
-		return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null;
3155
-    }
3156
-
3157
-    /**
3158
-	 * Removes a specific item.
3159
-	 *
3160
-	 * @since 1.0.19
3161
-	 */
3162
-	public function remove_item( $item_id ) {
3163
-		$items   = $this->get_items();
3164
-		$item_id = (int) $item_id;
3114
+    /**
3115
+     * Converts an array to an item.
3116
+     *
3117
+     * @since 1.0.19
3118
+     * @return GetPaid_Form_Item
3119
+     */
3120
+    protected function process_array_item( $array ) {
3121
+
3122
+        $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0;
3123
+        $item    = new GetPaid_Form_Item( $item_id );
3124
+
3125
+        // Set item data.
3126
+        foreach( array( 'name', 'price', 'description' ) as $key ) {
3127
+            if ( isset( $array[ "item_$key" ] ) ) {
3128
+                $method = "set_$key";
3129
+                $item->$method( $array[ "item_$key" ] );
3130
+            }
3131
+        }
3132
+
3133
+        if ( isset( $array['quantity'] ) ) {
3134
+            $item->set_quantity( $array['quantity'] );
3135
+        }
3136
+
3137
+        // Set item meta.
3138
+        if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) {
3139
+            $item->set_item_meta( $array['meta'] );
3140
+        }
3141
+
3142
+        return $item;
3143
+
3144
+    }
3145
+
3146
+    /**
3147
+     * Retrieves a specific item.
3148
+     *
3149
+     * @since 1.0.19
3150
+     */
3151
+    public function get_item( $item_id ) {
3152
+        $items   = $this->get_items();
3153
+        $item_id = (int) $item_id;
3154
+        return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null;
3155
+    }
3156
+
3157
+    /**
3158
+     * Removes a specific item.
3159
+     *
3160
+     * @since 1.0.19
3161
+     */
3162
+    public function remove_item( $item_id ) {
3163
+        $items   = $this->get_items();
3164
+        $item_id = (int) $item_id;
3165 3165
 
3166 3166
         if ( $item_id == $this->recurring_item ) {
3167 3167
             $this->recurring_item = null;
@@ -3188,38 +3188,38 @@  discard block
 block discarded – undo
3188 3188
         if ( isset( $fees[ $fee ] ) && isset( $fees[ $fee ]['amount'] ) ) {
3189 3189
 
3190 3190
             $amount = $fees[ $fee ]['amount'] += $amount;
3191
-			$fees[ $fee ] = array(
3192
-				'amount'    => $amount,
3191
+            $fees[ $fee ] = array(
3192
+                'amount'    => $amount,
3193 3193
                 'recurring' => (bool) $recurring,
3194 3194
             );
3195 3195
 
3196
-		} else {
3197
-			$fees[ $fee ] = array(
3196
+        } else {
3197
+            $fees[ $fee ] = array(
3198 3198
                 'amount'    => $amount,
3199 3199
                 'recurring' => (bool) $recurring,
3200 3200
             );
3201
-		}
3201
+        }
3202 3202
 
3203 3203
         $this->set_prop( 'fees', $fee );
3204 3204
 
3205 3205
     }
3206 3206
 
3207 3207
     /**
3208
-	 * Retrieves a specific fee.
3209
-	 *
3210
-	 * @since 1.0.19
3211
-	 */
3212
-	public function get_fee( $fee ) {
3208
+     * Retrieves a specific fee.
3209
+     *
3210
+     * @since 1.0.19
3211
+     */
3212
+    public function get_fee( $fee ) {
3213 3213
         $fees = $this->get_fees();
3214
-		return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3214
+        return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3215 3215
     }
3216 3216
 
3217 3217
     /**
3218
-	 * Removes a specific fee.
3219
-	 *
3220
-	 * @since 1.0.19
3221
-	 */
3222
-	public function remove_fee( $fee ) {
3218
+     * Removes a specific fee.
3219
+     *
3220
+     * @since 1.0.19
3221
+     */
3222
+    public function remove_fee( $fee ) {
3223 3223
         $fees = $this->get_fees();
3224 3224
         if ( isset( $fees[ $fee ] ) ) {
3225 3225
             unset( $fees[ $fee ] );
@@ -3242,44 +3242,44 @@  discard block
 block discarded – undo
3242 3242
         if ( isset( $discounts[ $discount ] ) && isset( $discounts[ $discount ]['amount'] ) ) {
3243 3243
 
3244 3244
             $amount = $discounts[ $discount ]['amount'] += $amount;
3245
-			$discounts[ $discount ] = array(
3245
+            $discounts[ $discount ] = array(
3246 3246
                 'amount'    => $amount,
3247 3247
                 'recurring' => (bool) $recurring,
3248 3248
             );
3249 3249
 
3250
-		} else {
3251
-			$discounts[ $discount ] = array(
3250
+        } else {
3251
+            $discounts[ $discount ] = array(
3252 3252
                 'amount'    => $amount,
3253 3253
                 'recurring' => (bool) $recurring,
3254 3254
             );
3255
-		}
3255
+        }
3256 3256
 
3257 3257
         $this->set_prop( 'discounts', $discount );
3258 3258
 
3259 3259
     }
3260 3260
 
3261 3261
     /**
3262
-	 * Retrieves a specific discount.
3263
-	 *
3264
-	 * @since 1.0.19
3265
-	 */
3266
-	public function get_discount( $discount = false ) {
3262
+     * Retrieves a specific discount.
3263
+     *
3264
+     * @since 1.0.19
3265
+     */
3266
+    public function get_discount( $discount = false ) {
3267 3267
 
3268
-		// Backwards compatibilty.
3269
-		if ( empty( $discount ) ) {
3270
-			return $this->get_total_discount();
3271
-		}
3268
+        // Backwards compatibilty.
3269
+        if ( empty( $discount ) ) {
3270
+            return $this->get_total_discount();
3271
+        }
3272 3272
 
3273 3273
         $discounts = $this->get_discounts();
3274
-		return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3274
+        return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3275 3275
     }
3276 3276
 
3277 3277
     /**
3278
-	 * Removes a specific discount.
3279
-	 *
3280
-	 * @since 1.0.19
3281
-	 */
3282
-	public function remove_discount( $discount ) {
3278
+     * Removes a specific discount.
3279
+     *
3280
+     * @since 1.0.19
3281
+     */
3282
+    public function remove_discount( $discount ) {
3283 3283
         $discounts = $this->get_discounts();
3284 3284
         if ( isset( $discounts[ $discount ] ) ) {
3285 3285
             unset( $discounts[ $discount ] );
@@ -3305,44 +3305,44 @@  discard block
 block discarded – undo
3305 3305
         if ( isset( $taxes[ $tax ] ) && isset( $taxes[ $tax ]['amount'] ) ) {
3306 3306
 
3307 3307
             $amount = $taxes[ $tax ]['amount'] += $amount;
3308
-			$taxes[ $tax ] = array(
3308
+            $taxes[ $tax ] = array(
3309 3309
                 'amount'    => $amount,
3310 3310
                 'recurring' => (bool) $recurring,
3311 3311
             );
3312 3312
 
3313
-		} else {
3314
-			$taxes[ $tax ] = array(
3313
+        } else {
3314
+            $taxes[ $tax ] = array(
3315 3315
                 'amount'    => $amount,
3316 3316
                 'recurring' => (bool) $recurring,
3317 3317
             );
3318
-		}
3318
+        }
3319 3319
 
3320 3320
         $this->set_prop( 'taxes', $tax );
3321 3321
 
3322 3322
     }
3323 3323
 
3324 3324
     /**
3325
-	 * Retrieves a specific tax.
3326
-	 *
3327
-	 * @since 1.0.19
3328
-	 */
3329
-	public function get_tax( $tax = null ) {
3325
+     * Retrieves a specific tax.
3326
+     *
3327
+     * @since 1.0.19
3328
+     */
3329
+    public function get_tax( $tax = null ) {
3330 3330
 
3331
-		// Backwards compatility.
3332
-		if ( empty( $tax ) ) {
3333
-			return $this->get_total_tax();
3334
-		}
3331
+        // Backwards compatility.
3332
+        if ( empty( $tax ) ) {
3333
+            return $this->get_total_tax();
3334
+        }
3335 3335
 
3336 3336
         $taxes = $this->get_taxes();
3337
-		return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3337
+        return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3338 3338
     }
3339 3339
 
3340 3340
     /**
3341
-	 * Removes a specific tax.
3342
-	 *
3343
-	 * @since 1.0.19
3344
-	 */
3345
-	public function remove_tax( $tax ) {
3341
+     * Removes a specific tax.
3342
+     *
3343
+     * @since 1.0.19
3344
+     */
3345
+    public function remove_tax( $tax ) {
3346 3346
         $taxes = $this->get_discounts();
3347 3347
         if ( isset( $taxes[ $tax ] ) ) {
3348 3348
             unset( $taxes[ $tax ] );
@@ -3351,160 +3351,160 @@  discard block
 block discarded – undo
3351 3351
     }
3352 3352
 
3353 3353
     /**
3354
-	 * Recalculates the invoice subtotal.
3355
-	 *
3356
-	 * @since 1.0.19
3357
-	 * @return float The recalculated subtotal
3358
-	 */
3359
-	public function recalculate_subtotal() {
3354
+     * Recalculates the invoice subtotal.
3355
+     *
3356
+     * @since 1.0.19
3357
+     * @return float The recalculated subtotal
3358
+     */
3359
+    public function recalculate_subtotal() {
3360 3360
         $items     = $this->get_items();
3361
-		$subtotal  = 0;
3362
-		$recurring = 0;
3361
+        $subtotal  = 0;
3362
+        $recurring = 0;
3363 3363
 
3364 3364
         foreach ( $items as $item ) {
3365
-			$subtotal  += $item->get_sub_total();
3366
-			$recurring += $item->get_recurring_sub_total();
3365
+            $subtotal  += $item->get_sub_total();
3366
+            $recurring += $item->get_recurring_sub_total();
3367 3367
         }
3368 3368
 
3369
-		if ( $this->is_renewal() ) {
3370
-			$this->set_subtotal( $recurring );
3371
-		} else {
3372
-			$this->set_subtotal( $subtotal );
3373
-		}
3369
+        if ( $this->is_renewal() ) {
3370
+            $this->set_subtotal( $recurring );
3371
+        } else {
3372
+            $this->set_subtotal( $subtotal );
3373
+        }
3374 3374
 
3375
-		$this->totals['subtotal'] = array(
3376
-			'initial'   => $subtotal,
3377
-			'recurring' => $recurring,
3378
-		);
3375
+        $this->totals['subtotal'] = array(
3376
+            'initial'   => $subtotal,
3377
+            'recurring' => $recurring,
3378
+        );
3379 3379
 
3380 3380
         return $this->is_renewal() ? $recurring : $subtotal;
3381 3381
     }
3382 3382
 
3383 3383
     /**
3384
-	 * Recalculates the invoice discount total.
3385
-	 *
3386
-	 * @since 1.0.19
3387
-	 * @return float The recalculated discount
3388
-	 */
3389
-	public function recalculate_total_discount() {
3384
+     * Recalculates the invoice discount total.
3385
+     *
3386
+     * @since 1.0.19
3387
+     * @return float The recalculated discount
3388
+     */
3389
+    public function recalculate_total_discount() {
3390 3390
         $discounts = $this->get_discounts();
3391
-		$discount  = 0;
3392
-		$recurring = 0;
3391
+        $discount  = 0;
3392
+        $recurring = 0;
3393 3393
 
3394 3394
         foreach ( $discounts as $data ) {
3395 3395
 
3396
-			if ( $data['recurring'] ) {
3397
-				$recurring += $data['amount'];
3398
-			} else {
3399
-				$discount += $data['amount'];
3400
-			}
3396
+            if ( $data['recurring'] ) {
3397
+                $recurring += $data['amount'];
3398
+            } else {
3399
+                $discount += $data['amount'];
3400
+            }
3401 3401
 
3402
-		}
3402
+        }
3403 3403
 
3404
-		if ( $this->is_renewal() ) {
3405
-			$this->set_total_discount( $recurring );
3406
-		} else {
3407
-			$this->set_total_discount( $discount );
3408
-		}
3404
+        if ( $this->is_renewal() ) {
3405
+            $this->set_total_discount( $recurring );
3406
+        } else {
3407
+            $this->set_total_discount( $discount );
3408
+        }
3409 3409
 
3410
-		$this->totals['discount'] = array(
3411
-			'initial'   => $discount,
3412
-			'recurring' => $recurring,
3413
-		);
3410
+        $this->totals['discount'] = array(
3411
+            'initial'   => $discount,
3412
+            'recurring' => $recurring,
3413
+        );
3414 3414
 
3415
-		return $this->is_renewal() ? $recurring : $discount;
3415
+        return $this->is_renewal() ? $recurring : $discount;
3416 3416
 
3417 3417
     }
3418 3418
 
3419 3419
     /**
3420
-	 * Recalculates the invoice tax total.
3421
-	 *
3422
-	 * @since 1.0.19
3423
-	 * @return float The recalculated tax
3424
-	 */
3425
-	public function recalculate_total_tax() {
3420
+     * Recalculates the invoice tax total.
3421
+     *
3422
+     * @since 1.0.19
3423
+     * @return float The recalculated tax
3424
+     */
3425
+    public function recalculate_total_tax() {
3426 3426
         $taxes     = $this->get_taxes();
3427
-		$tax       = 0;
3428
-		$recurring = 0;
3427
+        $tax       = 0;
3428
+        $recurring = 0;
3429 3429
 
3430 3430
         foreach ( $taxes as $data ) {
3431 3431
 
3432
-			if ( $data['recurring'] ) {
3433
-				$recurring += $data['amount'];
3434
-			} else {
3435
-				$tax += $data['amount'];
3436
-			}
3432
+            if ( $data['recurring'] ) {
3433
+                $recurring += $data['amount'];
3434
+            } else {
3435
+                $tax += $data['amount'];
3436
+            }
3437 3437
 
3438
-		}
3438
+        }
3439 3439
 
3440
-		if ( $this->is_renewal() ) {
3441
-			$this->set_total_tax( $recurring );
3442
-		} else {
3443
-			$this->set_total_tax( $tax );
3444
-		}
3440
+        if ( $this->is_renewal() ) {
3441
+            $this->set_total_tax( $recurring );
3442
+        } else {
3443
+            $this->set_total_tax( $tax );
3444
+        }
3445 3445
 
3446
-		$this->totals['tax'] = array(
3447
-			'initial'   => $tax,
3448
-			'recurring' => $recurring,
3449
-		);
3446
+        $this->totals['tax'] = array(
3447
+            'initial'   => $tax,
3448
+            'recurring' => $recurring,
3449
+        );
3450 3450
 
3451
-		return $this->is_renewal() ? $recurring : $tax;
3451
+        return $this->is_renewal() ? $recurring : $tax;
3452 3452
 
3453 3453
     }
3454 3454
 
3455 3455
     /**
3456
-	 * Recalculates the invoice fees total.
3457
-	 *
3458
-	 * @since 1.0.19
3459
-	 * @return float The recalculated fee
3460
-	 */
3461
-	public function recalculate_total_fees() {
3462
-		$fees      = $this->get_fees();
3463
-		$fee       = 0;
3464
-		$recurring = 0;
3456
+     * Recalculates the invoice fees total.
3457
+     *
3458
+     * @since 1.0.19
3459
+     * @return float The recalculated fee
3460
+     */
3461
+    public function recalculate_total_fees() {
3462
+        $fees      = $this->get_fees();
3463
+        $fee       = 0;
3464
+        $recurring = 0;
3465 3465
 
3466 3466
         foreach ( $fees as $data ) {
3467 3467
 
3468
-			if ( $data['recurring'] ) {
3469
-				$recurring += $data['amount'];
3470
-			} else {
3471
-				$fee += $data['amount'];
3472
-			}
3468
+            if ( $data['recurring'] ) {
3469
+                $recurring += $data['amount'];
3470
+            } else {
3471
+                $fee += $data['amount'];
3472
+            }
3473 3473
 
3474
-		}
3474
+        }
3475 3475
 
3476 3476
         if ( $this->is_renewal() ) {
3477
-			$this->set_total_fees( $recurring );
3478
-		} else {
3479
-			$this->set_total_fees( $fee );
3480
-		}
3477
+            $this->set_total_fees( $recurring );
3478
+        } else {
3479
+            $this->set_total_fees( $fee );
3480
+        }
3481 3481
 
3482
-		$this->totals['fee'] = array(
3483
-			'initial'   => $fee,
3484
-			'recurring' => $recurring,
3485
-		);
3482
+        $this->totals['fee'] = array(
3483
+            'initial'   => $fee,
3484
+            'recurring' => $recurring,
3485
+        );
3486 3486
 
3487 3487
         $this->set_total_fees( $fee );
3488 3488
         return $this->is_renewal() ? $recurring : $fee;
3489 3489
     }
3490 3490
 
3491 3491
     /**
3492
-	 * Recalculates the invoice total.
3493
-	 *
3494
-	 * @since 1.0.19
3492
+     * Recalculates the invoice total.
3493
+     *
3494
+     * @since 1.0.19
3495 3495
      * @return float The invoice total
3496
-	 */
3497
-	public function recalculate_total() {
3496
+     */
3497
+    public function recalculate_total() {
3498 3498
         $this->recalculate_subtotal();
3499 3499
         $this->recalculate_total_fees();
3500 3500
         $this->recalculate_total_discount();
3501 3501
         $this->recalculate_total_tax();
3502
-		return $this->get_total();
3503
-	}
3502
+        return $this->get_total();
3503
+    }
3504 3504
 
3505
-	/**
3506
-	 * @deprecated
3507
-	 */
3505
+    /**
3506
+     * @deprecated
3507
+     */
3508 3508
     public function recalculate_totals( $temp = false ) {
3509 3509
         $this->update_items( $temp );
3510 3510
         $this->save( true );
@@ -3522,7 +3522,7 @@  discard block
 block discarded – undo
3522 3522
      * Adds a note to an invoice.
3523 3523
      *
3524 3524
      * @param string $note The note being added.
3525
-	 * @return int|false The new note's ID on success, false on failure.
3525
+     * @return int|false The new note's ID on success, false on failure.
3526 3526
      *
3527 3527
      */
3528 3528
     public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
@@ -3532,23 +3532,23 @@  discard block
 block discarded – undo
3532 3532
             return false;
3533 3533
         }
3534 3534
 
3535
-		// If this is an admin comment or it has been added by the user.
3536
-		if ( is_user_logged_in() && ( wpinv_current_user_can_manage_invoicing() || $added_by_user ) ) {
3537
-			$user         = get_user_by( 'id', get_current_user_id() );
3535
+        // If this is an admin comment or it has been added by the user.
3536
+        if ( is_user_logged_in() && ( wpinv_current_user_can_manage_invoicing() || $added_by_user ) ) {
3537
+            $user         = get_user_by( 'id', get_current_user_id() );
3538 3538
             $author       = $user->display_name;
3539 3539
             $author_email = $user->user_email;
3540
-		} 
3540
+        } 
3541 3541
 
3542
-		if ( $system ) {
3543
-			$author       = 'System';
3542
+        if ( $system ) {
3543
+            $author       = 'System';
3544 3544
             $author_email = '[email protected]';
3545
-		}
3545
+        }
3546 3546
 
3547
-		return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type );
3547
+        return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type );
3548 3548
 
3549
-	}
3549
+    }
3550 3550
 
3551
-	/**
3551
+    /**
3552 3552
      * Generates a unique key for the invoice.
3553 3553
      */
3554 3554
     public function generate_key( $string = '' ) {
@@ -3568,106 +3568,106 @@  discard block
 block discarded – undo
3568 3568
             $number = wpinv_get_next_invoice_number( $this->post_type );
3569 3569
         }
3570 3570
 
3571
-		$number = wpinv_format_invoice_number( $number, $this->post_type );
3571
+        $number = wpinv_format_invoice_number( $number, $this->post_type );
3572 3572
 
3573
-		return $number;
3574
-	}
3573
+        return $number;
3574
+    }
3575 3575
 
3576
-	/**
3577
-	 * Handle the status transition.
3578
-	 */
3579
-	protected function status_transition() {
3580
-		$status_transition = $this->status_transition;
3576
+    /**
3577
+     * Handle the status transition.
3578
+     */
3579
+    protected function status_transition() {
3580
+        $status_transition = $this->status_transition;
3581 3581
 
3582
-		// Reset status transition variable.
3583
-		$this->status_transition = false;
3582
+        // Reset status transition variable.
3583
+        $this->status_transition = false;
3584 3584
 
3585
-		if ( $status_transition ) {
3586
-			try {
3585
+        if ( $status_transition ) {
3586
+            try {
3587 3587
 
3588
-				// Fire a hook for the status change.
3589
-				do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
3588
+                // Fire a hook for the status change.
3589
+                do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
3590 3590
 
3591
-				// @deprecated this is deprecated and will be removed in the future.
3592
-				do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3591
+                // @deprecated this is deprecated and will be removed in the future.
3592
+                do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3593 3593
 
3594
-				if ( ! empty( $status_transition['from'] ) ) {
3594
+                if ( ! empty( $status_transition['from'] ) ) {
3595 3595
 
3596
-					/* translators: 1: old invoice status 2: new invoice status */
3597
-					$transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) );
3596
+                    /* translators: 1: old invoice status 2: new invoice status */
3597
+                    $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) );
3598 3598
 
3599
-					// Fire another hook.
3600
-					do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
3601
-					do_action( 'getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
3599
+                    // Fire another hook.
3600
+                    do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
3601
+                    do_action( 'getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
3602 3602
 
3603
-					// @deprecated this is deprecated and will be removed in the future.
3604
-					do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3603
+                    // @deprecated this is deprecated and will be removed in the future.
3604
+                    do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3605 3605
 
3606
-					// Note the transition occurred.
3607
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3606
+                    // Note the transition occurred.
3607
+                    $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3608 3608
 
3609
-					// Work out if this was for a payment, and trigger a payment_status hook instead.
3610
-					if (
3611
-						in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded' ), true )
3612
-						&& in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3613
-					) {
3614
-						do_action( 'getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition );
3615
-					}
3616
-				} else {
3617
-					/* translators: %s: new invoice status */
3618
-					$transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) );
3609
+                    // Work out if this was for a payment, and trigger a payment_status hook instead.
3610
+                    if (
3611
+                        in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded' ), true )
3612
+                        && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3613
+                    ) {
3614
+                        do_action( 'getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition );
3615
+                    }
3616
+                } else {
3617
+                    /* translators: %s: new invoice status */
3618
+                    $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) );
3619 3619
 
3620
-					// Note the transition occurred.
3621
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3620
+                    // Note the transition occurred.
3621
+                    $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3622 3622
 
3623
-				}
3624
-			} catch ( Exception $e ) {
3625
-				$this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3626
-			}
3627
-		}
3628
-	}
3623
+                }
3624
+            } catch ( Exception $e ) {
3625
+                $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3626
+            }
3627
+        }
3628
+    }
3629 3629
 
3630
-	/**
3631
-	 * Updates an invoice status.
3632
-	 */
3633
-	public function update_status( $new_status = false, $note = '', $manual = false ) {
3630
+    /**
3631
+     * Updates an invoice status.
3632
+     */
3633
+    public function update_status( $new_status = false, $note = '', $manual = false ) {
3634 3634
 
3635
-		// Fires before updating a status.
3636
-		do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) );
3635
+        // Fires before updating a status.
3636
+        do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) );
3637 3637
 
3638
-		// Update the status.
3639
-		$this->set_status( $new_status, $note, $manual );
3638
+        // Update the status.
3639
+        $this->set_status( $new_status, $note, $manual );
3640 3640
 
3641
-		// Save the order.
3642
-		return $this->save();
3641
+        // Save the order.
3642
+        return $this->save();
3643 3643
 
3644
-	}
3644
+    }
3645 3645
 
3646
-	/**
3647
-	 * @deprecated
3648
-	 */
3649
-	public function refresh_item_ids() {
3646
+    /**
3647
+     * @deprecated
3648
+     */
3649
+    public function refresh_item_ids() {
3650 3650
         $item_ids = implode( ',', array_unique( array_keys( $this->get_items() ) ) );
3651 3651
         update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids );
3652
-	}
3652
+    }
3653 3653
 
3654
-	/**
3655
-	 * @deprecated
3656
-	 */
3657
-	public function update_items( $temp = false ) {
3654
+    /**
3655
+     * @deprecated
3656
+     */
3657
+    public function update_items( $temp = false ) {
3658 3658
 
3659
-		$this->set_items( $this->get_items() );
3659
+        $this->set_items( $this->get_items() );
3660 3660
 
3661
-		if ( ! $temp ) {
3662
-			$this->save();
3663
-		}
3661
+        if ( ! $temp ) {
3662
+            $this->save();
3663
+        }
3664 3664
 
3665 3665
         return $this;
3666
-	}
3666
+    }
3667 3667
 
3668
-	/**
3669
-	 * @deprecated
3670
-	 */
3668
+    /**
3669
+     * @deprecated
3670
+     */
3671 3671
     public function validate_discount() {
3672 3672
 
3673 3673
         $discount_code = $this->get_discount_code();
@@ -3683,86 +3683,86 @@  discard block
 block discarded – undo
3683 3683
 
3684 3684
     }
3685 3685
 
3686
-	/**
3687
-	 * Refunds an invoice.
3688
-	 */
3686
+    /**
3687
+     * Refunds an invoice.
3688
+     */
3689 3689
     public function refund() {
3690
-		$this->set_status( 'wpi-refunded' );
3690
+        $this->set_status( 'wpi-refunded' );
3691 3691
         $this->save();
3692
-	}
3692
+    }
3693 3693
 
3694
-	/**
3695
-	 * Marks an invoice as paid.
3696
-	 * 
3697
-	 * @param string $transaction_id
3698
-	 */
3694
+    /**
3695
+     * Marks an invoice as paid.
3696
+     * 
3697
+     * @param string $transaction_id
3698
+     */
3699 3699
     public function mark_paid( $transaction_id = null, $note = '' ) {
3700 3700
 
3701
-		// Set the transaction id.
3702
-		if ( empty( $transaction_id ) ) {
3703
-			$transaction_id = $this->generate_key('trans_');
3704
-		}
3701
+        // Set the transaction id.
3702
+        if ( empty( $transaction_id ) ) {
3703
+            $transaction_id = $this->generate_key('trans_');
3704
+        }
3705 3705
 
3706
-		if ( ! $this->get_transaction_id() ) {
3707
-			$this->set_transaction_id( $transaction_id );
3708
-		}
3706
+        if ( ! $this->get_transaction_id() ) {
3707
+            $this->set_transaction_id( $transaction_id );
3708
+        }
3709 3709
 
3710
-		if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) {
3711
-			return $this->save();
3712
-		}
3710
+        if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) {
3711
+            return $this->save();
3712
+        }
3713 3713
 
3714
-		// Set the completed date.
3715
-		$this->set_date_completed( current_time( 'mysql' ) );
3714
+        // Set the completed date.
3715
+        $this->set_date_completed( current_time( 'mysql' ) );
3716 3716
 
3717
-		// Set the new status.
3718
-		if ( $this->is_renewal() ) {
3717
+        // Set the new status.
3718
+        if ( $this->is_renewal() ) {
3719 3719
 
3720
-			$_note = sprintf(
3721
-				__( 'Renewed via %s', 'invoicing' ),
3722
-				$this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3723
-			);
3720
+            $_note = sprintf(
3721
+                __( 'Renewed via %s', 'invoicing' ),
3722
+                $this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3723
+            );
3724 3724
 
3725
-			if ( 'none' == $this->get_gateway() ) {
3726
-				$_note = $note;
3727
-			}
3725
+            if ( 'none' == $this->get_gateway() ) {
3726
+                $_note = $note;
3727
+            }
3728 3728
 
3729
-			$this->set_status( 'wpi-renewal', $_note );
3729
+            $this->set_status( 'wpi-renewal', $_note );
3730 3730
 
3731
-		} else {
3731
+        } else {
3732 3732
 
3733
-			$_note = sprintf(
3734
-				__( 'Paid via %s', 'invoicing' ),
3735
-				$this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3736
-			);
3733
+            $_note = sprintf(
3734
+                __( 'Paid via %s', 'invoicing' ),
3735
+                $this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3736
+            );
3737 3737
 
3738
-			if ( 'none' == $this->get_gateway() ) {
3739
-				$_note = $note;
3740
-			}
3738
+            if ( 'none' == $this->get_gateway() ) {
3739
+                $_note = $note;
3740
+            }
3741 3741
 
3742
-			$this->set_status( 'publish',$_note );
3742
+            $this->set_status( 'publish',$_note );
3743 3743
 
3744
-		}
3744
+        }
3745 3745
 
3746
-		// Set checkout mode.
3747
-		$mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live';
3748
-		$this->set_mode( $mode );
3746
+        // Set checkout mode.
3747
+        $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live';
3748
+        $this->set_mode( $mode );
3749 3749
 
3750
-		// Save the invoice.
3750
+        // Save the invoice.
3751 3751
         $this->save();
3752
-	}
3753
-
3754
-
3755
-	/**
3756
-	 * Save data to the database.
3757
-	 *
3758
-	 * @since 1.0.19
3759
-	 * @return int invoice ID
3760
-	 */
3761
-	public function save() {
3762
-		$this->maybe_set_date_paid();
3763
-		parent::save();
3764
-		$this->status_transition();
3765
-		return $this->get_id();
3766
-	}
3752
+    }
3753
+
3754
+
3755
+    /**
3756
+     * Save data to the database.
3757
+     *
3758
+     * @since 1.0.19
3759
+     * @return int invoice ID
3760
+     */
3761
+    public function save() {
3762
+        $this->maybe_set_date_paid();
3763
+        parent::save();
3764
+        $this->status_transition();
3765
+        return $this->get_id();
3766
+    }
3767 3767
 
3768 3768
 }
Please login to merge, or discard this patch.