Passed
Push — master ( 72aaeb...55577f )
by Brian
04:34
created
includes/payments/class-getpaid-checkout.php 1 patch
Indentation   +251 added lines, -251 removed lines patch added patch discarded remove patch
@@ -12,180 +12,180 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 * 
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Prepare the invoice.
39
-		$items      = $this->get_submission_items();
40
-		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving();
43
-
44
-		$this->prepare_billing_info( $invoice );
45
-
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
47
-
48
-		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
50
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     * 
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Prepare the invoice.
39
+        $items      = $this->get_submission_items();
40
+        $invoice    = $this->get_submission_invoice();
41
+        $invoice    = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared   = $this->prepare_submission_data_for_saving();
43
+
44
+        $this->prepare_billing_info( $invoice );
45
+
46
+        $shipping   = $this->prepare_shipping_info( $invoice );
47
+
48
+        // Save the invoice.
49
+        $invoice->set_is_viewed( true );
50
+        $invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+        do_action( 'getpaid_checkout_invoice_updated', $invoice );
54 54
 
55
-		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
57
-	}
55
+        // Send to the gateway.
56
+        $this->post_process_submission( $invoice, $prepared, $shipping );
57
+    }
58 58
 
59
-	/**
60
-	 * Validates the submission.
61
-	 *
62
-	 */
63
-	protected function validate_submission() {
59
+    /**
60
+     * Validates the submission.
61
+     *
62
+     */
63
+    protected function validate_submission() {
64 64
 
65
-		$submission = $this->payment_form_submission;
66
-		$data       = $submission->get_data();
65
+        $submission = $this->payment_form_submission;
66
+        $data       = $submission->get_data();
67 67
 
68
-		// Do we have an error?
68
+        // Do we have an error?
69 69
         if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
70
+            wp_send_json_error( $submission->last_error );
71 71
         }
72 72
 
73
-		// We need a billing email.
73
+        // We need a billing email.
74 74
         if ( ! $submission->has_billing_email() ) {
75 75
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
76
-		}
76
+        }
77 77
 
78
-		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
-		}
78
+        // Non-recurring gateways should not be allowed to process recurring invoices.
79
+        if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
+        }
82 82
 
83
-		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
86
-		}
83
+        // Ensure the gateway is active.
84
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
+            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
86
+        }
87 87
 
88
-		// Clear any existing errors.
89
-		wpinv_clear_errors();
88
+        // Clear any existing errors.
89
+        wpinv_clear_errors();
90 90
 
91
-		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
91
+        // Allow themes and plugins to hook to errors
92
+        do_action( 'getpaid_checkout_error_checks', $submission );
93 93
 
94
-		// Do we have any errors?
94
+        // Do we have any errors?
95 95
         if ( wpinv_get_errors() ) {
96 96
             wp_send_json_error( getpaid_get_errors_html() );
97
-		}
97
+        }
98 98
 
99
-	}
99
+    }
100 100
 
101
-	/**
102
-	 * Retrieves submission items.
103
-	 *
104
-	 * @return GetPaid_Form_Item[]
105
-	 */
106
-	protected function get_submission_items() {
101
+    /**
102
+     * Retrieves submission items.
103
+     *
104
+     * @return GetPaid_Form_Item[]
105
+     */
106
+    protected function get_submission_items() {
107 107
 
108
-		$items = $this->payment_form_submission->get_items();
108
+        $items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111 111
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112 112
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
113
-		}
114
-
115
-		return $items;
116
-	}
117
-
118
-	/**
119
-	 * Retrieves submission invoice.
120
-	 *
121
-	 * @return WPInv_Invoice
122
-	 */
123
-	protected function get_submission_invoice() {
124
-		$submission = $this->payment_form_submission;
125
-
126
-		if ( ! $submission->has_invoice() ) {
127
-			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
129
-			return $invoice;
130 113
         }
131 114
 
132
-		$invoice = $submission->get_invoice();
115
+        return $items;
116
+    }
133 117
 
134
-		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
-		}
118
+    /**
119
+     * Retrieves submission invoice.
120
+     *
121
+     * @return WPInv_Invoice
122
+     */
123
+    protected function get_submission_invoice() {
124
+        $submission = $this->payment_form_submission;
138 125
 
139
-		return $invoice;
140
-	}
126
+        if ( ! $submission->has_invoice() ) {
127
+            $invoice = new WPInv_Invoice();
128
+            $invoice->set_created_via( 'payment_form' );
129
+            return $invoice;
130
+        }
141 131
 
142
-	/**
143
-	 * Processes the submission invoice.
144
-	 *
145
-	 * @param WPInv_Invoice $invoice
146
-	 * @param GetPaid_Form_Item[] $items
147
-	 * @return WPInv_Invoice
148
-	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
132
+        $invoice = $submission->get_invoice();
150 133
 
151
-		$submission = $this->payment_form_submission;
152
-		$data       = $submission->get_data();
134
+        // Make sure that it is neither paid or refunded.
135
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
+        }
138
+
139
+        return $invoice;
140
+    }
141
+
142
+    /**
143
+     * Processes the submission invoice.
144
+     *
145
+     * @param WPInv_Invoice $invoice
146
+     * @param GetPaid_Form_Item[] $items
147
+     * @return WPInv_Invoice
148
+     */
149
+    protected function process_submission_invoice( $invoice, $items ) {
153 150
 
154
-		// Set-up the invoice details.
155
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
156
-		$invoice->set_user_id( $this->get_submission_customer() );
157
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
151
+        $submission = $this->payment_form_submission;
152
+        $data       = $submission->get_data();
153
+
154
+        // Set-up the invoice details.
155
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
156
+        $invoice->set_user_id( $this->get_submission_customer() );
157
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
158 158
         $invoice->set_items( $items );
159 159
         $invoice->set_fees( $submission->get_fees() );
160 160
         $invoice->set_taxes( $submission->get_taxes() );
161
-		$invoice->set_discounts( $submission->get_discounts() );
162
-		$invoice->set_gateway( $data['wpi-gateway'] );
161
+        $invoice->set_discounts( $submission->get_discounts() );
162
+        $invoice->set_gateway( $data['wpi-gateway'] );
163 163
 
164
-		$address_confirmed = $submission->get_field( 'confirm-address' );
165
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
164
+        $address_confirmed = $submission->get_field( 'confirm-address' );
165
+        $invoice->set_address_confirmed( ! empty( $address_confirmed ) );
166 166
 
167
-		if ( $submission->has_discount_code() ) {
167
+        if ( $submission->has_discount_code() ) {
168 168
             $invoice->set_discount_code( $submission->get_discount_code() );
169
-		}
170
-
171
-		getpaid_maybe_add_default_address( $invoice );
172
-		return $invoice;
173
-	}
174
-
175
-	/**
176
-	 * Retrieves the submission's customer.
177
-	 *
178
-	 * @return int The customer id.
179
-	 */
180
-	protected function get_submission_customer() {
181
-		$submission = $this->payment_form_submission;
182
-
183
-		// If this is an existing invoice...
184
-		if ( $submission->has_invoice() ) {
185
-			return $submission->get_invoice()->get_user_id();
186
-		}
187
-
188
-		// (Maybe) create the user.
169
+        }
170
+
171
+        getpaid_maybe_add_default_address( $invoice );
172
+        return $invoice;
173
+    }
174
+
175
+    /**
176
+     * Retrieves the submission's customer.
177
+     *
178
+     * @return int The customer id.
179
+     */
180
+    protected function get_submission_customer() {
181
+        $submission = $this->payment_form_submission;
182
+
183
+        // If this is an existing invoice...
184
+        if ( $submission->has_invoice() ) {
185
+            return $submission->get_invoice()->get_user_id();
186
+        }
187
+
188
+        // (Maybe) create the user.
189 189
         $user = get_current_user_id();
190 190
 
191 191
         if ( empty( $user ) ) {
@@ -202,31 +202,31 @@  discard block
 block discarded – undo
202 202
 
203 203
         if ( is_numeric( $user ) ) {
204 204
             return $user;
205
-		}
205
+        }
206 206
 
207
-		return $user->ID;
207
+        return $user->ID;
208 208
 
209
-	}
209
+    }
210 210
 
211
-	/**
211
+    /**
212 212
      * Prepares submission data for saving to the database.
213 213
      *
214
-	 * @return array
214
+     * @return array
215 215
      */
216 216
     public function prepare_submission_data_for_saving() {
217 217
 
218
-		$submission = $this->payment_form_submission;
218
+        $submission = $this->payment_form_submission;
219 219
 
220
-		// Prepared submission details.
220
+        // Prepared submission details.
221 221
         $prepared = array();
222 222
 
223 223
         // Raw submission details.
224
-		$data     = $submission->get_data();
224
+        $data     = $submission->get_data();
225 225
 
226
-		// Loop through the submitted details.
226
+        // Loop through the submitted details.
227 227
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
228 228
 
229
-			// Skip premade fields.
229
+            // Skip premade fields.
230 230
             if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) {
231 231
                 continue;
232 232
             }
@@ -244,176 +244,176 @@  discard block
 block discarded – undo
244 244
                     $label = $field['label'];
245 245
                 }
246 246
 
247
-				$prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
247
+                $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
248 248
 
249 249
             }
250 250
 
251
-		}
251
+        }
252 252
 
253
-		return $prepared;
253
+        return $prepared;
254 254
 
255
-	}
255
+    }
256 256
 
257
-	/**
257
+    /**
258 258
      * Retrieves address details.
259 259
      *
260
-	 * @return array
261
-	 * @param WPInv_Invoice $invoice
262
-	 * @param string $type
260
+     * @return array
261
+     * @param WPInv_Invoice $invoice
262
+     * @param string $type
263 263
      */
264 264
     public function prepare_address_details( $invoice, $type = 'billing' ) {
265 265
 
266
-		$data     = $this->payment_form_submission->get_data();
267
-		$type     = sanitize_key( $type );
268
-		$address  = array();
269
-		$prepared = array();
266
+        $data     = $this->payment_form_submission->get_data();
267
+        $type     = sanitize_key( $type );
268
+        $address  = array();
269
+        $prepared = array();
270 270
 
271
-		if ( ! empty( $data[ $type ] ) ) {
272
-			$address = $data[ $type ];
273
-		}
271
+        if ( ! empty( $data[ $type ] ) ) {
272
+            $address = $data[ $type ];
273
+        }
274 274
 
275
-		// Clean address details.
276
-		foreach ( $address as $key => $value ) {
277
-			$key             = sanitize_key( $key );
278
-			$key             = str_replace( 'wpinv_', '', $key );
279
-			$value           = wpinv_clean( $value );
280
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
281
-		}
275
+        // Clean address details.
276
+        foreach ( $address as $key => $value ) {
277
+            $key             = sanitize_key( $key );
278
+            $key             = str_replace( 'wpinv_', '', $key );
279
+            $value           = wpinv_clean( $value );
280
+            $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
281
+        }
282 282
 
283
-		// Filter address details.
284
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
283
+        // Filter address details.
284
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
285 285
 
286
-		// Remove non-whitelisted values.
287
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
286
+        // Remove non-whitelisted values.
287
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
288 288
 
289
-	}
289
+    }
290 290
 
291
-	/**
291
+    /**
292 292
      * Prepares the billing details.
293 293
      *
294
-	 * @return array
295
-	 * @param WPInv_Invoice $invoice
294
+     * @return array
295
+     * @param WPInv_Invoice $invoice
296 296
      */
297 297
     protected function prepare_billing_info( &$invoice ) {
298 298
 
299
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
299
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
300 300
 
301
-		// Update the invoice with the billing details.
302
-		$invoice->set_props( $billing_address );
301
+        // Update the invoice with the billing details.
302
+        $invoice->set_props( $billing_address );
303 303
 
304
-	}
304
+    }
305 305
 
306
-	/**
306
+    /**
307 307
      * Prepares the shipping details.
308 308
      *
309
-	 * @return array
310
-	 * @param WPInv_Invoice $invoice
309
+     * @return array
310
+     * @param WPInv_Invoice $invoice
311 311
      */
312 312
     protected function prepare_shipping_info( $invoice ) {
313 313
 
314
-		$data = $this->payment_form_submission->get_data();
314
+        $data = $this->payment_form_submission->get_data();
315 315
 
316
-		if ( empty( $data['same-shipping-address'] ) ) {
317
-			return $this->prepare_address_details( $invoice, 'shipping' );
318
-		}
316
+        if ( empty( $data['same-shipping-address'] ) ) {
317
+            return $this->prepare_address_details( $invoice, 'shipping' );
318
+        }
319 319
 
320
-		return $this->prepare_address_details( $invoice, 'billing' );
320
+        return $this->prepare_address_details( $invoice, 'billing' );
321 321
 
322
-	}
322
+    }
323 323
 
324
-	/**
325
-	 * Confirms the submission is valid and send users to the gateway.
326
-	 *
327
-	 * @param WPInv_Invoice $invoice
328
-	 * @param array $prepared_payment_form_data
329
-	 * @param array $shipping
330
-	 */
331
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
324
+    /**
325
+     * Confirms the submission is valid and send users to the gateway.
326
+     *
327
+     * @param WPInv_Invoice $invoice
328
+     * @param array $prepared_payment_form_data
329
+     * @param array $shipping
330
+     */
331
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
332 332
 
333
-		// Ensure the invoice exists.
333
+        // Ensure the invoice exists.
334 334
         if ( ! $invoice->exists() ) {
335 335
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
336 336
         }
337 337
 
338
-		// Save payment form data.
339
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
338
+        // Save payment form data.
339
+        $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
340 340
         if ( ! empty( $prepared_payment_form_data ) ) {
341 341
             update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
342
-		}
342
+        }
343 343
 
344
-		// Save payment form data.
344
+        // Save payment form data.
345 345
         if ( ! empty( $shipping ) ) {
346 346
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
347
-		}
347
+        }
348 348
 
349
-		// Backwards compatibility.
349
+        // Backwards compatibility.
350 350
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
351 351
 
352
-		$this->process_payment( $invoice );
352
+        $this->process_payment( $invoice );
353 353
 
354 354
         // If we are here, there was an error.
355
-		wpinv_send_back_to_checkout( $invoice );
355
+        wpinv_send_back_to_checkout( $invoice );
356 356
 
357
-	}
357
+    }
358 358
 
359
-	/**
360
-	 * Processes the actual payment.
361
-	 *
362
-	 * @param WPInv_Invoice $invoice
363
-	 */
364
-	protected function process_payment( $invoice ) {
359
+    /**
360
+     * Processes the actual payment.
361
+     *
362
+     * @param WPInv_Invoice $invoice
363
+     */
364
+    protected function process_payment( $invoice ) {
365 365
 
366
-		// Clear any checkout errors.
367
-		wpinv_clear_errors();
366
+        // Clear any checkout errors.
367
+        wpinv_clear_errors();
368 368
 
369
-		// No need to send free invoices to the gateway.
370
-		if ( $invoice->is_free() ) {
371
-			$this->process_free_payment( $invoice );
372
-		}
369
+        // No need to send free invoices to the gateway.
370
+        if ( $invoice->is_free() ) {
371
+            $this->process_free_payment( $invoice );
372
+        }
373 373
 
374
-		$submission = $this->payment_form_submission;
374
+        $submission = $this->payment_form_submission;
375 375
 
376
-		// Fires before sending to the gateway.
377
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
376
+        // Fires before sending to the gateway.
377
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
378 378
 
379
-		// Allow the sumission data to be modified before it is sent to the gateway.
380
-		$submission_data    = $submission->get_data();
381
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
382
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
379
+        // Allow the sumission data to be modified before it is sent to the gateway.
380
+        $submission_data    = $submission->get_data();
381
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
382
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
383 383
 
384
-		// Validate the currency.
385
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
386
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
387
-		}
384
+        // Validate the currency.
385
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
386
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
387
+        }
388 388
 
389
-		// Check to see if we have any errors.
390
-		if ( wpinv_get_errors() ) {
391
-			wpinv_send_back_to_checkout( $invoice );
392
-		}
389
+        // Check to see if we have any errors.
390
+        if ( wpinv_get_errors() ) {
391
+            wpinv_send_back_to_checkout( $invoice );
392
+        }
393 393
 
394
-		// Send info to the gateway for payment processing
395
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
394
+        // Send info to the gateway for payment processing
395
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
396 396
 
397
-		// Backwards compatibility.
398
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
397
+        // Backwards compatibility.
398
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
399 399
 
400
-	}
400
+    }
401 401
 
402
-	/**
403
-	 * Marks the invoice as paid in case the checkout is free.
404
-	 *
405
-	 * @param WPInv_Invoice $invoice
406
-	 */
407
-	protected function process_free_payment( $invoice ) {
402
+    /**
403
+     * Marks the invoice as paid in case the checkout is free.
404
+     *
405
+     * @param WPInv_Invoice $invoice
406
+     */
407
+    protected function process_free_payment( $invoice ) {
408 408
 
409
-		$invoice->set_gateway( 'none' );
410
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
411
-		$invoice->mark_paid();
412
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
409
+        $invoice->set_gateway( 'none' );
410
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
411
+        $invoice->mark_paid();
412
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
413 413
 
414
-	}
414
+    }
415 415
 
416
-	/**
416
+    /**
417 417
      * Sends a redrect response to payment details.
418 418
      *
419 419
      */
Please login to merge, or discard this patch.
includes/class-wpinv-item.php 1 patch
Indentation   +732 added lines, -732 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,30 +10,30 @@  discard block
 block discarded – undo
10 10
 class WPInv_Item  extends GetPaid_Data {
11 11
 
12 12
     /**
13
-	 * Which data store to load.
14
-	 *
15
-	 * @var string
16
-	 */
13
+     * Which data store to load.
14
+     *
15
+     * @var string
16
+     */
17 17
     protected $data_store_name = 'item';
18 18
 
19 19
     /**
20
-	 * This is the name of this object type.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $object_type = 'item';
20
+     * This is the name of this object type.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $object_type = 'item';
25 25
 
26 26
     /**
27
-	 * Item Data array. This is the core item data exposed in APIs.
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data = array(
33
-		'parent_id'            => 0,
34
-		'status'               => 'draft',
35
-		'version'              => '',
36
-		'date_created'         => null,
27
+     * Item Data array. This is the core item data exposed in APIs.
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data = array(
33
+        'parent_id'            => 0,
34
+        'status'               => 'draft',
35
+        'version'              => '',
36
+        'date_created'         => null,
37 37
         'date_modified'        => null,
38 38
         'name'                 => '',
39 39
         'description'          => '',
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
     );
59 59
 
60 60
     /**
61
-	 * Stores meta in cache for future reads.
62
-	 *
63
-	 * A group must be set to to enable caching.
64
-	 *
65
-	 * @var string
66
-	 */
67
-	protected $cache_group = 'getpaid_items';
61
+     * Stores meta in cache for future reads.
62
+     *
63
+     * A group must be set to to enable caching.
64
+     *
65
+     * @var string
66
+     */
67
+    protected $cache_group = 'getpaid_items';
68 68
 
69 69
     /**
70 70
      * Stores a reference to the original WP_Post object
@@ -74,37 +74,37 @@  discard block
 block discarded – undo
74 74
     protected $post = null;
75 75
 
76 76
     /**
77
-	 * Get the item if ID is passed, otherwise the item is new and empty.
78
-	 *
79
-	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80
-	 */
81
-	public function __construct( $item = 0 ) {
82
-		parent::__construct( $item );
83
-
84
-		if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
85
-			$this->set_id( $item );
86
-		} elseif ( $item instanceof self ) {
87
-			$this->set_id( $item->get_id() );
88
-		} elseif ( ! empty( $item->ID ) ) {
89
-			$this->set_id( $item->ID );
90
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
91
-			$this->set_id( $item_id );
92
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
93
-			$this->set_id( $item_id );
94
-		} else {
95
-			$this->set_object_read( true );
96
-		}
77
+     * Get the item if ID is passed, otherwise the item is new and empty.
78
+     *
79
+     * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80
+     */
81
+    public function __construct( $item = 0 ) {
82
+        parent::__construct( $item );
83
+
84
+        if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
85
+            $this->set_id( $item );
86
+        } elseif ( $item instanceof self ) {
87
+            $this->set_id( $item->get_id() );
88
+        } elseif ( ! empty( $item->ID ) ) {
89
+            $this->set_id( $item->ID );
90
+        } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
91
+            $this->set_id( $item_id );
92
+        } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
93
+            $this->set_id( $item_id );
94
+        } else {
95
+            $this->set_object_read( true );
96
+        }
97 97
 
98 98
         // Load the datastore.
99
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
99
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
100 100
 
101
-		if ( $this->get_id() > 0 ) {
101
+        if ( $this->get_id() > 0 ) {
102 102
             $this->post = get_post( $this->get_id() );
103 103
             $this->ID   = $this->get_id();
104
-			$this->data_store->read( $this );
104
+            $this->data_store->read( $this );
105 105
         }
106 106
 
107
-	}
107
+    }
108 108
 
109 109
     /*
110 110
 	|--------------------------------------------------------------------------
@@ -122,401 +122,401 @@  discard block
 block discarded – undo
122 122
     */
123 123
 
124 124
     /**
125
-	 * Get parent item ID.
126
-	 *
127
-	 * @since 1.0.19
128
-	 * @param  string $context View or edit context.
129
-	 * @return int
130
-	 */
131
-	public function get_parent_id( $context = 'view' ) {
132
-		return (int) $this->get_prop( 'parent_id', $context );
125
+     * Get parent item ID.
126
+     *
127
+     * @since 1.0.19
128
+     * @param  string $context View or edit context.
129
+     * @return int
130
+     */
131
+    public function get_parent_id( $context = 'view' ) {
132
+        return (int) $this->get_prop( 'parent_id', $context );
133 133
     }
134 134
 
135 135
     /**
136
-	 * Get item status.
137
-	 *
138
-	 * @since 1.0.19
139
-	 * @param  string $context View or edit context.
140
-	 * @return string
141
-	 */
142
-	public function get_status( $context = 'view' ) {
143
-		return $this->get_prop( 'status', $context );
136
+     * Get item status.
137
+     *
138
+     * @since 1.0.19
139
+     * @param  string $context View or edit context.
140
+     * @return string
141
+     */
142
+    public function get_status( $context = 'view' ) {
143
+        return $this->get_prop( 'status', $context );
144 144
     }
145 145
 
146 146
     /**
147
-	 * Get plugin version when the item was created.
148
-	 *
149
-	 * @since 1.0.19
150
-	 * @param  string $context View or edit context.
151
-	 * @return string
152
-	 */
153
-	public function get_version( $context = 'view' ) {
154
-		return $this->get_prop( 'version', $context );
147
+     * Get plugin version when the item was created.
148
+     *
149
+     * @since 1.0.19
150
+     * @param  string $context View or edit context.
151
+     * @return string
152
+     */
153
+    public function get_version( $context = 'view' ) {
154
+        return $this->get_prop( 'version', $context );
155 155
     }
156 156
 
157 157
     /**
158
-	 * Get date when the item was created.
159
-	 *
160
-	 * @since 1.0.19
161
-	 * @param  string $context View or edit context.
162
-	 * @return string
163
-	 */
164
-	public function get_date_created( $context = 'view' ) {
165
-		return $this->get_prop( 'date_created', $context );
158
+     * Get date when the item was created.
159
+     *
160
+     * @since 1.0.19
161
+     * @param  string $context View or edit context.
162
+     * @return string
163
+     */
164
+    public function get_date_created( $context = 'view' ) {
165
+        return $this->get_prop( 'date_created', $context );
166 166
     }
167 167
 
168 168
     /**
169
-	 * Get GMT date when the item was created.
170
-	 *
171
-	 * @since 1.0.19
172
-	 * @param  string $context View or edit context.
173
-	 * @return string
174
-	 */
175
-	public function get_date_created_gmt( $context = 'view' ) {
169
+     * Get GMT date when the item was created.
170
+     *
171
+     * @since 1.0.19
172
+     * @param  string $context View or edit context.
173
+     * @return string
174
+     */
175
+    public function get_date_created_gmt( $context = 'view' ) {
176 176
         $date = $this->get_date_created( $context );
177 177
 
178 178
         if ( $date ) {
179 179
             $date = get_gmt_from_date( $date );
180 180
         }
181
-		return $date;
181
+        return $date;
182 182
     }
183 183
 
184 184
     /**
185
-	 * Get date when the item was last modified.
186
-	 *
187
-	 * @since 1.0.19
188
-	 * @param  string $context View or edit context.
189
-	 * @return string
190
-	 */
191
-	public function get_date_modified( $context = 'view' ) {
192
-		return $this->get_prop( 'date_modified', $context );
185
+     * Get date when the item was last modified.
186
+     *
187
+     * @since 1.0.19
188
+     * @param  string $context View or edit context.
189
+     * @return string
190
+     */
191
+    public function get_date_modified( $context = 'view' ) {
192
+        return $this->get_prop( 'date_modified', $context );
193 193
     }
194 194
 
195 195
     /**
196
-	 * Get GMT date when the item was last modified.
197
-	 *
198
-	 * @since 1.0.19
199
-	 * @param  string $context View or edit context.
200
-	 * @return string
201
-	 */
202
-	public function get_date_modified_gmt( $context = 'view' ) {
196
+     * Get GMT date when the item was last modified.
197
+     *
198
+     * @since 1.0.19
199
+     * @param  string $context View or edit context.
200
+     * @return string
201
+     */
202
+    public function get_date_modified_gmt( $context = 'view' ) {
203 203
         $date = $this->get_date_modified( $context );
204 204
 
205 205
         if ( $date ) {
206 206
             $date = get_gmt_from_date( $date );
207 207
         }
208
-		return $date;
208
+        return $date;
209 209
     }
210 210
 
211 211
     /**
212
-	 * Get the item name.
213
-	 *
214
-	 * @since 1.0.19
215
-	 * @param  string $context View or edit context.
216
-	 * @return string
217
-	 */
218
-	public function get_name( $context = 'view' ) {
219
-		return $this->get_prop( 'name', $context );
212
+     * Get the item name.
213
+     *
214
+     * @since 1.0.19
215
+     * @param  string $context View or edit context.
216
+     * @return string
217
+     */
218
+    public function get_name( $context = 'view' ) {
219
+        return $this->get_prop( 'name', $context );
220 220
     }
221 221
 
222 222
     /**
223
-	 * Alias of self::get_name().
224
-	 *
225
-	 * @since 1.0.19
226
-	 * @param  string $context View or edit context.
227
-	 * @return string
228
-	 */
229
-	public function get_title( $context = 'view' ) {
230
-		return $this->get_name( $context );
223
+     * Alias of self::get_name().
224
+     *
225
+     * @since 1.0.19
226
+     * @param  string $context View or edit context.
227
+     * @return string
228
+     */
229
+    public function get_title( $context = 'view' ) {
230
+        return $this->get_name( $context );
231 231
     }
232 232
 
233 233
     /**
234
-	 * Get the item description.
235
-	 *
236
-	 * @since 1.0.19
237
-	 * @param  string $context View or edit context.
238
-	 * @return string
239
-	 */
240
-	public function get_description( $context = 'view' ) {
241
-		return $this->get_prop( 'description', $context );
234
+     * Get the item description.
235
+     *
236
+     * @since 1.0.19
237
+     * @param  string $context View or edit context.
238
+     * @return string
239
+     */
240
+    public function get_description( $context = 'view' ) {
241
+        return $this->get_prop( 'description', $context );
242 242
     }
243 243
 
244 244
     /**
245
-	 * Alias of self::get_description().
246
-	 *
247
-	 * @since 1.0.19
248
-	 * @param  string $context View or edit context.
249
-	 * @return string
250
-	 */
251
-	public function get_excerpt( $context = 'view' ) {
252
-		return $this->get_description( $context );
245
+     * Alias of self::get_description().
246
+     *
247
+     * @since 1.0.19
248
+     * @param  string $context View or edit context.
249
+     * @return string
250
+     */
251
+    public function get_excerpt( $context = 'view' ) {
252
+        return $this->get_description( $context );
253 253
     }
254 254
 
255 255
     /**
256
-	 * Alias of self::get_description().
257
-	 *
258
-	 * @since 1.0.19
259
-	 * @param  string $context View or edit context.
260
-	 * @return string
261
-	 */
262
-	public function get_summary( $context = 'view' ) {
263
-		return $this->get_description( $context );
256
+     * Alias of self::get_description().
257
+     *
258
+     * @since 1.0.19
259
+     * @param  string $context View or edit context.
260
+     * @return string
261
+     */
262
+    public function get_summary( $context = 'view' ) {
263
+        return $this->get_description( $context );
264 264
     }
265 265
 
266 266
     /**
267
-	 * Get the owner of the item.
268
-	 *
269
-	 * @since 1.0.19
270
-	 * @param  string $context View or edit context.
271
-	 * @return int
272
-	 */
273
-	public function get_author( $context = 'view' ) {
274
-		return (int) $this->get_prop( 'author', $context );
275
-	}
267
+     * Get the owner of the item.
268
+     *
269
+     * @since 1.0.19
270
+     * @param  string $context View or edit context.
271
+     * @return int
272
+     */
273
+    public function get_author( $context = 'view' ) {
274
+        return (int) $this->get_prop( 'author', $context );
275
+    }
276 276
 	
277
-	/**
278
-	 * Alias of self::get_author().
279
-	 *
280
-	 * @since 1.0.19
281
-	 * @param  string $context View or edit context.
282
-	 * @return int
283
-	 */
284
-	public function get_owner( $context = 'view' ) {
285
-		return $this->get_author( $context );
286
-    }
287
-
288
-    /**
289
-	 * Get the price of the item.
290
-	 *
291
-	 * @since 1.0.19
292
-	 * @param  string $context View or edit context.
293
-	 * @return float
294
-	 */
295
-	public function get_price( $context = 'view' ) {
277
+    /**
278
+     * Alias of self::get_author().
279
+     *
280
+     * @since 1.0.19
281
+     * @param  string $context View or edit context.
282
+     * @return int
283
+     */
284
+    public function get_owner( $context = 'view' ) {
285
+        return $this->get_author( $context );
286
+    }
287
+
288
+    /**
289
+     * Get the price of the item.
290
+     *
291
+     * @since 1.0.19
292
+     * @param  string $context View or edit context.
293
+     * @return float
294
+     */
295
+    public function get_price( $context = 'view' ) {
296 296
         return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
297
-	}
297
+    }
298 298
 	
299
-	/**
300
-	 * Get the inital price of the item.
301
-	 *
302
-	 * @since 1.0.19
303
-	 * @param  string $context View or edit context.
304
-	 * @return float
305
-	 */
306
-	public function get_initial_price( $context = 'view' ) {
299
+    /**
300
+     * Get the inital price of the item.
301
+     *
302
+     * @since 1.0.19
303
+     * @param  string $context View or edit context.
304
+     * @return float
305
+     */
306
+    public function get_initial_price( $context = 'view' ) {
307 307
 
308
-		$price = (float) $this->get_price( $context );
308
+        $price = (float) $this->get_price( $context );
309 309
 
310
-		if ( $this->has_free_trial() ) {
311
-			$price = 0;
312
-		}
310
+        if ( $this->has_free_trial() ) {
311
+            $price = 0;
312
+        }
313 313
 
314 314
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) );
315 315
     }
316 316
 
317 317
     /**
318
-	 * Returns a formated price.
319
-	 *
320
-	 * @since 1.0.19
321
-	 * @param  string $context View or edit context.
322
-	 * @return string
323
-	 */
318
+     * Returns a formated price.
319
+     *
320
+     * @since 1.0.19
321
+     * @param  string $context View or edit context.
322
+     * @return string
323
+     */
324 324
     public function get_the_price() {
325 325
         return wpinv_price( $this->get_price() );
326
-	}
327
-
328
-	/**
329
-	 * Returns the formated initial price.
330
-	 *
331
-	 * @since 1.0.19
332
-	 * @param  string $context View or edit context.
333
-	 * @return string
334
-	 */
326
+    }
327
+
328
+    /**
329
+     * Returns the formated initial price.
330
+     *
331
+     * @since 1.0.19
332
+     * @param  string $context View or edit context.
333
+     * @return string
334
+     */
335 335
     public function get_the_initial_price() {
336 336
         return wpinv_price( $this->get_initial_price() );
337 337
     }
338 338
 
339 339
     /**
340
-	 * Get the VAT rule of the item.
341
-	 *
342
-	 * @since 1.0.19
343
-	 * @param  string $context View or edit context.
344
-	 * @return string
345
-	 */
346
-	public function get_vat_rule( $context = 'view' ) {
340
+     * Get the VAT rule of the item.
341
+     *
342
+     * @since 1.0.19
343
+     * @param  string $context View or edit context.
344
+     * @return string
345
+     */
346
+    public function get_vat_rule( $context = 'view' ) {
347 347
         return $this->get_prop( 'vat_rule', $context );
348 348
     }
349 349
 
350 350
     /**
351
-	 * Get the VAT class of the item.
352
-	 *
353
-	 * @since 1.0.19
354
-	 * @param  string $context View or edit context.
355
-	 * @return string
356
-	 */
357
-	public function get_vat_class( $context = 'view' ) {
351
+     * Get the VAT class of the item.
352
+     *
353
+     * @since 1.0.19
354
+     * @param  string $context View or edit context.
355
+     * @return string
356
+     */
357
+    public function get_vat_class( $context = 'view' ) {
358 358
         return $this->get_prop( 'vat_class', $context );
359 359
     }
360 360
 
361 361
     /**
362
-	 * Get the type of the item.
363
-	 *
364
-	 * @since 1.0.19
365
-	 * @param  string $context View or edit context.
366
-	 * @return string
367
-	 */
368
-	public function get_type( $context = 'view' ) {
362
+     * Get the type of the item.
363
+     *
364
+     * @since 1.0.19
365
+     * @param  string $context View or edit context.
366
+     * @return string
367
+     */
368
+    public function get_type( $context = 'view' ) {
369 369
         return $this->get_prop( 'type', $context );
370 370
     }
371 371
 
372 372
     /**
373
-	 * Get the custom id of the item.
374
-	 *
375
-	 * @since 1.0.19
376
-	 * @param  string $context View or edit context.
377
-	 * @return string
378
-	 */
379
-	public function get_custom_id( $context = 'view' ) {
373
+     * Get the custom id of the item.
374
+     *
375
+     * @since 1.0.19
376
+     * @param  string $context View or edit context.
377
+     * @return string
378
+     */
379
+    public function get_custom_id( $context = 'view' ) {
380 380
         return $this->get_prop( 'custom_id', $context );
381 381
     }
382 382
 
383 383
     /**
384
-	 * Get the custom name of the item.
385
-	 *
386
-	 * @since 1.0.19
387
-	 * @param  string $context View or edit context.
388
-	 * @return string
389
-	 */
390
-	public function get_custom_name( $context = 'view' ) {
384
+     * Get the custom name of the item.
385
+     *
386
+     * @since 1.0.19
387
+     * @param  string $context View or edit context.
388
+     * @return string
389
+     */
390
+    public function get_custom_name( $context = 'view' ) {
391 391
         return $this->get_prop( 'custom_name', $context );
392 392
     }
393 393
 
394 394
     /**
395
-	 * Get the custom singular name of the item.
396
-	 *
397
-	 * @since 1.0.19
398
-	 * @param  string $context View or edit context.
399
-	 * @return string
400
-	 */
401
-	public function get_custom_singular_name( $context = 'view' ) {
395
+     * Get the custom singular name of the item.
396
+     *
397
+     * @since 1.0.19
398
+     * @param  string $context View or edit context.
399
+     * @return string
400
+     */
401
+    public function get_custom_singular_name( $context = 'view' ) {
402 402
         return $this->get_prop( 'custom_singular_name', $context );
403 403
     }
404 404
 
405 405
     /**
406
-	 * Checks if an item is editable..
407
-	 *
408
-	 * @since 1.0.19
409
-	 * @param  string $context View or edit context.
410
-	 * @return int
411
-	 */
412
-	public function get_is_editable( $context = 'view' ) {
406
+     * Checks if an item is editable..
407
+     *
408
+     * @since 1.0.19
409
+     * @param  string $context View or edit context.
410
+     * @return int
411
+     */
412
+    public function get_is_editable( $context = 'view' ) {
413 413
         return (int) $this->get_prop( 'is_editable', $context );
414 414
     }
415 415
 
416 416
     /**
417
-	 * Alias of self::get_is_editable().
418
-	 *
419
-	 * @since 1.0.19
420
-	 * @param  string $context View or edit context.
421
-	 * @return int
422
-	 */
423
-	public function get_editable( $context = 'view' ) {
424
-		return $this->get_is_editable( $context );
417
+     * Alias of self::get_is_editable().
418
+     *
419
+     * @since 1.0.19
420
+     * @param  string $context View or edit context.
421
+     * @return int
422
+     */
423
+    public function get_editable( $context = 'view' ) {
424
+        return $this->get_is_editable( $context );
425 425
     }
426 426
 
427 427
     /**
428
-	 * Checks if dynamic pricing is enabled.
429
-	 *
430
-	 * @since 1.0.19
431
-	 * @param  string $context View or edit context.
432
-	 * @return int
433
-	 */
434
-	public function get_is_dynamic_pricing( $context = 'view' ) {
428
+     * Checks if dynamic pricing is enabled.
429
+     *
430
+     * @since 1.0.19
431
+     * @param  string $context View or edit context.
432
+     * @return int
433
+     */
434
+    public function get_is_dynamic_pricing( $context = 'view' ) {
435 435
         return (int) $this->get_prop( 'is_dynamic_pricing', $context );
436 436
     }
437 437
 
438 438
     /**
439
-	 * Returns the minimum price if dynamic pricing is enabled.
440
-	 *
441
-	 * @since 1.0.19
442
-	 * @param  string $context View or edit context.
443
-	 * @return float
444
-	 */
445
-	public function get_minimum_price( $context = 'view' ) {
439
+     * Returns the minimum price if dynamic pricing is enabled.
440
+     *
441
+     * @since 1.0.19
442
+     * @param  string $context View or edit context.
443
+     * @return float
444
+     */
445
+    public function get_minimum_price( $context = 'view' ) {
446 446
         return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
447 447
     }
448 448
 
449 449
     /**
450
-	 * Checks if this is a recurring item.
451
-	 *
452
-	 * @since 1.0.19
453
-	 * @param  string $context View or edit context.
454
-	 * @return int
455
-	 */
456
-	public function get_is_recurring( $context = 'view' ) {
450
+     * Checks if this is a recurring item.
451
+     *
452
+     * @since 1.0.19
453
+     * @param  string $context View or edit context.
454
+     * @return int
455
+     */
456
+    public function get_is_recurring( $context = 'view' ) {
457 457
         return (int) $this->get_prop( 'is_recurring', $context );
458
-	}
458
+    }
459 459
 	
460
-	/**
461
-	 * Get the recurring price of the item.
462
-	 *
463
-	 * @since 1.0.19
464
-	 * @param  string $context View or edit context.
465
-	 * @return float
466
-	 */
467
-	public function get_recurring_price( $context = 'view' ) {
468
-		$price = $this->get_price( $context );
460
+    /**
461
+     * Get the recurring price of the item.
462
+     *
463
+     * @since 1.0.19
464
+     * @param  string $context View or edit context.
465
+     * @return float
466
+     */
467
+    public function get_recurring_price( $context = 'view' ) {
468
+        $price = $this->get_price( $context );
469 469
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
470
-	}
471
-
472
-	/**
473
-	 * Get the formatted recurring price of the item.
474
-	 *
475
-	 * @since 1.0.19
476
-	 * @param  string $context View or edit context.
477
-	 * @return string
478
-	 */
470
+    }
471
+
472
+    /**
473
+     * Get the formatted recurring price of the item.
474
+     *
475
+     * @since 1.0.19
476
+     * @param  string $context View or edit context.
477
+     * @return string
478
+     */
479 479
     public function get_the_recurring_price() {
480 480
         return wpinv_price( $this->get_recurring_price() );
481
-	}
482
-
483
-	/**
484
-	 * Get the first renewal date (in timestamps) of the item.
485
-	 *
486
-	 * @since 1.0.19
487
-	 * @return int
488
-	 */
489
-	public function get_first_renewal_date() {
490
-
491
-		$periods = array(
492
-			'D' => 'days',
493
-			'W' => 'weeks',
494
-			'M' => 'months',
495
-			'Y' => 'years',
496
-		);
497
-
498
-		$period   = $this->get_recurring_period();
499
-		$interval = $this->get_recurring_interval();
500
-
501
-		if ( $this->has_free_trial() ) {
502
-			$period   = $this->get_trial_period();
503
-			$interval = $this->get_trial_interval();
504
-		}
505
-
506
-		$period       = $periods[ $period ];
507
-		$interval     = empty( $interval ) ? 1 : $interval;
508
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
481
+    }
482
+
483
+    /**
484
+     * Get the first renewal date (in timestamps) of the item.
485
+     *
486
+     * @since 1.0.19
487
+     * @return int
488
+     */
489
+    public function get_first_renewal_date() {
490
+
491
+        $periods = array(
492
+            'D' => 'days',
493
+            'W' => 'weeks',
494
+            'M' => 'months',
495
+            'Y' => 'years',
496
+        );
497
+
498
+        $period   = $this->get_recurring_period();
499
+        $interval = $this->get_recurring_interval();
500
+
501
+        if ( $this->has_free_trial() ) {
502
+            $period   = $this->get_trial_period();
503
+            $interval = $this->get_trial_interval();
504
+        }
505
+
506
+        $period       = $periods[ $period ];
507
+        $interval     = empty( $interval ) ? 1 : $interval;
508
+        $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
509 509
         return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
510 510
     }
511 511
 
512 512
     /**
513
-	 * Get the recurring period.
514
-	 *
515
-	 * @since 1.0.19
516
-	 * @param  bool $full Return abbreviation or in full.
517
-	 * @return string
518
-	 */
519
-	public function get_recurring_period( $full = false ) {
513
+     * Get the recurring period.
514
+     *
515
+     * @since 1.0.19
516
+     * @param  bool $full Return abbreviation or in full.
517
+     * @return string
518
+     */
519
+    public function get_recurring_period( $full = false ) {
520 520
         $period = $this->get_prop( 'recurring_period', 'view' );
521 521
 
522 522
         if ( $full && ! is_bool( $full ) ) {
@@ -527,58 +527,58 @@  discard block
 block discarded – undo
527 527
     }
528 528
 
529 529
     /**
530
-	 * Get the recurring interval.
531
-	 *
532
-	 * @since 1.0.19
533
-	 * @param  string $context View or edit context.
534
-	 * @return int
535
-	 */
536
-	public function get_recurring_interval( $context = 'view' ) {
537
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
538
-		return max( 1, $interval );
530
+     * Get the recurring interval.
531
+     *
532
+     * @since 1.0.19
533
+     * @param  string $context View or edit context.
534
+     * @return int
535
+     */
536
+    public function get_recurring_interval( $context = 'view' ) {
537
+        $interval = absint( $this->get_prop( 'recurring_interval', $context ) );
538
+        return max( 1, $interval );
539 539
     }
540 540
 
541 541
     /**
542
-	 * Get the recurring limit.
543
-	 *
544
-	 * @since 1.0.19
545
-	 * @param  string $context View or edit context.
546
-	 * @return int
547
-	 */
548
-	public function get_recurring_limit( $context = 'view' ) {
542
+     * Get the recurring limit.
543
+     *
544
+     * @since 1.0.19
545
+     * @param  string $context View or edit context.
546
+     * @return int
547
+     */
548
+    public function get_recurring_limit( $context = 'view' ) {
549 549
         return (int) $this->get_prop( 'recurring_limit', $context );
550 550
     }
551 551
 
552 552
     /**
553
-	 * Checks if we have a free trial.
554
-	 *
555
-	 * @since 1.0.19
556
-	 * @param  string $context View or edit context.
557
-	 * @return int
558
-	 */
559
-	public function get_is_free_trial( $context = 'view' ) {
553
+     * Checks if we have a free trial.
554
+     *
555
+     * @since 1.0.19
556
+     * @param  string $context View or edit context.
557
+     * @return int
558
+     */
559
+    public function get_is_free_trial( $context = 'view' ) {
560 560
         return (int) $this->get_prop( 'is_free_trial', $context );
561 561
     }
562 562
 
563 563
     /**
564
-	 * Alias for self::get_is_free_trial().
565
-	 *
566
-	 * @since 1.0.19
567
-	 * @param  string $context View or edit context.
568
-	 * @return int
569
-	 */
570
-	public function get_free_trial( $context = 'view' ) {
564
+     * Alias for self::get_is_free_trial().
565
+     *
566
+     * @since 1.0.19
567
+     * @param  string $context View or edit context.
568
+     * @return int
569
+     */
570
+    public function get_free_trial( $context = 'view' ) {
571 571
         return $this->get_is_free_trial( $context );
572 572
     }
573 573
 
574 574
     /**
575
-	 * Get the trial period.
576
-	 *
577
-	 * @since 1.0.19
578
-	 * @param  bool $full Return abbreviation or in full.
579
-	 * @return string
580
-	 */
581
-	public function get_trial_period( $full = false ) {
575
+     * Get the trial period.
576
+     *
577
+     * @since 1.0.19
578
+     * @param  bool $full Return abbreviation or in full.
579
+     * @return string
580
+     */
581
+    public function get_trial_period( $full = false ) {
582 582
         $period = $this->get_prop( 'trial_period', 'view' );
583 583
 
584 584
         if ( $full && ! is_bool( $full ) ) {
@@ -589,104 +589,104 @@  discard block
 block discarded – undo
589 589
     }
590 590
 
591 591
     /**
592
-	 * Get the trial interval.
593
-	 *
594
-	 * @since 1.0.19
595
-	 * @param  string $context View or edit context.
596
-	 * @return int
597
-	 */
598
-	public function get_trial_interval( $context = 'view' ) {
592
+     * Get the trial interval.
593
+     *
594
+     * @since 1.0.19
595
+     * @param  string $context View or edit context.
596
+     * @return int
597
+     */
598
+    public function get_trial_interval( $context = 'view' ) {
599 599
         return (int) $this->get_prop( 'trial_interval', $context );
600
-	}
600
+    }
601 601
 	
602
-	/**
603
-	 * Get the item's edit url.
604
-	 *
605
-	 * @since 1.0.19
606
-	 * @return string
607
-	 */
608
-	public function get_edit_url() {
602
+    /**
603
+     * Get the item's edit url.
604
+     *
605
+     * @since 1.0.19
606
+     * @return string
607
+     */
608
+    public function get_edit_url() {
609 609
         return get_edit_post_link( $this->get_id() );
610
-	}
611
-
612
-	/**
613
-	 * Given an item's name/custom id, it returns its id.
614
-	 *
615
-	 *
616
-	 * @static
617
-	 * @param string $value The item name or custom id.
618
-	 * @param string $field Either name or custom_id.
619
-	 * @param string $type in case you need to search for a given type.
620
-	 * @since 1.0.15
621
-	 * @return int
622
-	 */
623
-	public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
624
-
625
-		// Trim the value.
626
-		$value = sanitize_text_field( $value );
627
-		if ( empty( $value ) ) {
628
-			return 0;
629
-		}
610
+    }
611
+
612
+    /**
613
+     * Given an item's name/custom id, it returns its id.
614
+     *
615
+     *
616
+     * @static
617
+     * @param string $value The item name or custom id.
618
+     * @param string $field Either name or custom_id.
619
+     * @param string $type in case you need to search for a given type.
620
+     * @since 1.0.15
621
+     * @return int
622
+     */
623
+    public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
624
+
625
+        // Trim the value.
626
+        $value = sanitize_text_field( $value );
627
+        if ( empty( $value ) ) {
628
+            return 0;
629
+        }
630 630
 
631 631
         // Valid fields.
632 632
         $fields = array( 'custom_id', 'name', 'slug' );
633 633
 
634
-		// Ensure a field has been passed.
635
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
636
-			return 0;
637
-		}
638
-
639
-		if ( $field == 'name' ) {
640
-			$field = 'slug';
641
-		}
642
-
643
-		// Maybe retrieve from the cache.
644
-		$item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
645
-		if ( ! empty( $item_id ) ) {
646
-			return $item_id;
647
-		}
648
-
649
-		// Fetch from the db.
650
-		$items = array();
651
-		if ( $field == 'slug' ) {
652
-			$items = get_posts(
653
-				array(
654
-					'post_type'      => 'wpi_item',
655
-					'name'           => $value,
656
-					'posts_per_page' => 1,
657
-					'post_status'    => 'any',
658
-				)
659
-			);
660
-		}
661
-
662
-		if ( $field =='custom_id' ) {
663
-			$items = get_posts(
664
-				array(
665
-					'post_type'      => 'wpi_item',
666
-					'posts_per_page' => 1,
667
-					'post_status'    => 'any',
668
-					'meta_query'     => array(
669
-						array(
670
-							'key'   => '_wpinv_type',
671
-                			'value' => $type,
672
-						),
673
-						array(
674
-							'key'   => '_wpinv_custom_id',
675
-                			'value' => $value,
676
-						)
677
-					)
678
-				)
679
-			);
680
-		}
681
-
682
-		if ( empty( $items ) ) {
683
-			return 0;
684
-		}
685
-
686
-		// Update the cache with our data
687
-		wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
688
-
689
-		return $items[0]->ID;
634
+        // Ensure a field has been passed.
635
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
636
+            return 0;
637
+        }
638
+
639
+        if ( $field == 'name' ) {
640
+            $field = 'slug';
641
+        }
642
+
643
+        // Maybe retrieve from the cache.
644
+        $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
645
+        if ( ! empty( $item_id ) ) {
646
+            return $item_id;
647
+        }
648
+
649
+        // Fetch from the db.
650
+        $items = array();
651
+        if ( $field == 'slug' ) {
652
+            $items = get_posts(
653
+                array(
654
+                    'post_type'      => 'wpi_item',
655
+                    'name'           => $value,
656
+                    'posts_per_page' => 1,
657
+                    'post_status'    => 'any',
658
+                )
659
+            );
660
+        }
661
+
662
+        if ( $field =='custom_id' ) {
663
+            $items = get_posts(
664
+                array(
665
+                    'post_type'      => 'wpi_item',
666
+                    'posts_per_page' => 1,
667
+                    'post_status'    => 'any',
668
+                    'meta_query'     => array(
669
+                        array(
670
+                            'key'   => '_wpinv_type',
671
+                            'value' => $type,
672
+                        ),
673
+                        array(
674
+                            'key'   => '_wpinv_custom_id',
675
+                            'value' => $value,
676
+                        )
677
+                    )
678
+                )
679
+            );
680
+        }
681
+
682
+        if ( empty( $items ) ) {
683
+            return 0;
684
+        }
685
+
686
+        // Update the cache with our data
687
+        wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
688
+
689
+        return $items[0]->ID;
690 690
     }
691 691
 
692 692
     /**
@@ -719,52 +719,52 @@  discard block
 block discarded – undo
719 719
     */
720 720
 
721 721
     /**
722
-	 * Set parent order ID.
723
-	 *
724
-	 * @since 1.0.19
725
-	 */
726
-	public function set_parent_id( $value ) {
727
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
728
-			return;
729
-		}
730
-		$this->set_prop( 'parent_id', absint( $value ) );
731
-	}
732
-
733
-    /**
734
-	 * Sets item status.
735
-	 *
736
-	 * @since 1.0.19
737
-	 * @param  string $status New status.
738
-	 * @return array details of change.
739
-	 */
740
-	public function set_status( $status ) {
722
+     * Set parent order ID.
723
+     *
724
+     * @since 1.0.19
725
+     */
726
+    public function set_parent_id( $value ) {
727
+        if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
728
+            return;
729
+        }
730
+        $this->set_prop( 'parent_id', absint( $value ) );
731
+    }
732
+
733
+    /**
734
+     * Sets item status.
735
+     *
736
+     * @since 1.0.19
737
+     * @param  string $status New status.
738
+     * @return array details of change.
739
+     */
740
+    public function set_status( $status ) {
741 741
         $old_status = $this->get_status();
742 742
 
743 743
         $this->set_prop( 'status', $status );
744 744
 
745
-		return array(
746
-			'from' => $old_status,
747
-			'to'   => $status,
748
-		);
745
+        return array(
746
+            'from' => $old_status,
747
+            'to'   => $status,
748
+        );
749 749
     }
750 750
 
751 751
     /**
752
-	 * Set plugin version when the item was created.
753
-	 *
754
-	 * @since 1.0.19
755
-	 */
756
-	public function set_version( $value ) {
757
-		$this->set_prop( 'version', $value );
752
+     * Set plugin version when the item was created.
753
+     *
754
+     * @since 1.0.19
755
+     */
756
+    public function set_version( $value ) {
757
+        $this->set_prop( 'version', $value );
758 758
     }
759 759
 
760 760
     /**
761
-	 * Set date when the item was created.
762
-	 *
763
-	 * @since 1.0.19
764
-	 * @param string $value Value to set.
761
+     * Set date when the item was created.
762
+     *
763
+     * @since 1.0.19
764
+     * @param string $value Value to set.
765 765
      * @return bool Whether or not the date was set.
766
-	 */
767
-	public function set_date_created( $value ) {
766
+     */
767
+    public function set_date_created( $value ) {
768 768
         $date = strtotime( $value );
769 769
 
770 770
         if ( $date ) {
@@ -777,13 +777,13 @@  discard block
 block discarded – undo
777 777
     }
778 778
 
779 779
     /**
780
-	 * Set date when the item was last modified.
781
-	 *
782
-	 * @since 1.0.19
783
-	 * @param string $value Value to set.
780
+     * Set date when the item was last modified.
781
+     *
782
+     * @since 1.0.19
783
+     * @param string $value Value to set.
784 784
      * @return bool Whether or not the date was set.
785
-	 */
786
-	public function set_date_modified( $value ) {
785
+     */
786
+    public function set_date_modified( $value ) {
787 787
         $date = strtotime( $value );
788 788
 
789 789
         if ( $date ) {
@@ -796,115 +796,115 @@  discard block
 block discarded – undo
796 796
     }
797 797
 
798 798
     /**
799
-	 * Set the item name.
800
-	 *
801
-	 * @since 1.0.19
802
-	 * @param  string $value New name.
803
-	 */
804
-	public function set_name( $value ) {
799
+     * Set the item name.
800
+     *
801
+     * @since 1.0.19
802
+     * @param  string $value New name.
803
+     */
804
+    public function set_name( $value ) {
805 805
         $name = sanitize_text_field( $value );
806
-		$this->set_prop( 'name', $name );
806
+        $this->set_prop( 'name', $name );
807 807
     }
808 808
 
809 809
     /**
810
-	 * Alias of self::set_name().
811
-	 *
812
-	 * @since 1.0.19
813
-	 * @param  string $value New name.
814
-	 */
815
-	public function set_title( $value ) {
816
-		$this->set_name( $value );
810
+     * Alias of self::set_name().
811
+     *
812
+     * @since 1.0.19
813
+     * @param  string $value New name.
814
+     */
815
+    public function set_title( $value ) {
816
+        $this->set_name( $value );
817 817
     }
818 818
 
819 819
     /**
820
-	 * Set the item description.
821
-	 *
822
-	 * @since 1.0.19
823
-	 * @param  string $value New description.
824
-	 */
825
-	public function set_description( $value ) {
826
-		$description = wp_kses_post( $value );
827
-		return $this->set_prop( 'description', $description );
820
+     * Set the item description.
821
+     *
822
+     * @since 1.0.19
823
+     * @param  string $value New description.
824
+     */
825
+    public function set_description( $value ) {
826
+        $description = wp_kses_post( $value );
827
+        return $this->set_prop( 'description', $description );
828 828
     }
829 829
 
830 830
     /**
831
-	 * Alias of self::set_description().
832
-	 *
833
-	 * @since 1.0.19
834
-	 * @param  string $value New description.
835
-	 */
836
-	public function set_excerpt( $value ) {
837
-		$this->set_description( $value );
831
+     * Alias of self::set_description().
832
+     *
833
+     * @since 1.0.19
834
+     * @param  string $value New description.
835
+     */
836
+    public function set_excerpt( $value ) {
837
+        $this->set_description( $value );
838 838
     }
839 839
 
840 840
     /**
841
-	 * Alias of self::set_description().
842
-	 *
843
-	 * @since 1.0.19
844
-	 * @param  string $value New description.
845
-	 */
846
-	public function set_summary( $value ) {
847
-		$this->set_description( $value );
841
+     * Alias of self::set_description().
842
+     *
843
+     * @since 1.0.19
844
+     * @param  string $value New description.
845
+     */
846
+    public function set_summary( $value ) {
847
+        $this->set_description( $value );
848 848
     }
849 849
 
850 850
     /**
851
-	 * Set the owner of the item.
852
-	 *
853
-	 * @since 1.0.19
854
-	 * @param  int $value New author.
855
-	 */
856
-	public function set_author( $value ) {
857
-		$this->set_prop( 'author', (int) $value );
858
-	}
851
+     * Set the owner of the item.
852
+     *
853
+     * @since 1.0.19
854
+     * @param  int $value New author.
855
+     */
856
+    public function set_author( $value ) {
857
+        $this->set_prop( 'author', (int) $value );
858
+    }
859 859
 	
860
-	/**
861
-	 * Alias of self::set_author().
862
-	 *
863
-	 * @since 1.0.19
864
-	 * @param  int $value New author.
865
-	 */
866
-	public function set_owner( $value ) {
867
-		$this->set_author( $value );
868
-    }
869
-
870
-    /**
871
-	 * Set the price of the item.
872
-	 *
873
-	 * @since 1.0.19
874
-	 * @param  float $value New price.
875
-	 */
876
-	public function set_price( $value ) {
860
+    /**
861
+     * Alias of self::set_author().
862
+     *
863
+     * @since 1.0.19
864
+     * @param  int $value New author.
865
+     */
866
+    public function set_owner( $value ) {
867
+        $this->set_author( $value );
868
+    }
869
+
870
+    /**
871
+     * Set the price of the item.
872
+     *
873
+     * @since 1.0.19
874
+     * @param  float $value New price.
875
+     */
876
+    public function set_price( $value ) {
877 877
         $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
878 878
     }
879 879
 
880 880
     /**
881
-	 * Set the VAT rule of the item.
882
-	 *
883
-	 * @since 1.0.19
884
-	 * @param  string $value new rule.
885
-	 */
886
-	public function set_vat_rule( $value ) {
881
+     * Set the VAT rule of the item.
882
+     *
883
+     * @since 1.0.19
884
+     * @param  string $value new rule.
885
+     */
886
+    public function set_vat_rule( $value ) {
887 887
         $this->set_prop( 'vat_rule', $value );
888 888
     }
889 889
 
890 890
     /**
891
-	 * Set the VAT class of the item.
892
-	 *
893
-	 * @since 1.0.19
894
-	 * @param  string $value new class.
895
-	 */
896
-	public function set_vat_class( $value ) {
891
+     * Set the VAT class of the item.
892
+     *
893
+     * @since 1.0.19
894
+     * @param  string $value new class.
895
+     */
896
+    public function set_vat_class( $value ) {
897 897
         $this->set_prop( 'vat_class', $value );
898 898
     }
899 899
 
900 900
     /**
901
-	 * Set the type of the item.
902
-	 *
903
-	 * @since 1.0.19
904
-	 * @param  string $value new item type.
905
-	 * @return string
906
-	 */
907
-	public function set_type( $value ) {
901
+     * Set the type of the item.
902
+     *
903
+     * @since 1.0.19
904
+     * @param  string $value new item type.
905
+     * @return string
906
+     */
907
+    public function set_type( $value ) {
908 908
 
909 909
         if ( empty( $value ) ) {
910 910
             $value = 'custom';
@@ -914,132 +914,132 @@  discard block
 block discarded – undo
914 914
     }
915 915
 
916 916
     /**
917
-	 * Set the custom id of the item.
918
-	 *
919
-	 * @since 1.0.19
920
-	 * @param  string $value new custom id.
921
-	 */
922
-	public function set_custom_id( $value ) {
917
+     * Set the custom id of the item.
918
+     *
919
+     * @since 1.0.19
920
+     * @param  string $value new custom id.
921
+     */
922
+    public function set_custom_id( $value ) {
923 923
         $this->set_prop( 'custom_id', $value );
924 924
     }
925 925
 
926 926
     /**
927
-	 * Set the custom name of the item.
928
-	 *
929
-	 * @since 1.0.19
930
-	 * @param  string $value new custom name.
931
-	 */
932
-	public function set_custom_name( $value ) {
927
+     * Set the custom name of the item.
928
+     *
929
+     * @since 1.0.19
930
+     * @param  string $value new custom name.
931
+     */
932
+    public function set_custom_name( $value ) {
933 933
         $this->set_prop( 'custom_name', $value );
934 934
     }
935 935
 
936 936
     /**
937
-	 * Set the custom singular name of the item.
938
-	 *
939
-	 * @since 1.0.19
940
-	 * @param  string $value new custom singular name.
941
-	 */
942
-	public function set_custom_singular_name( $value ) {
937
+     * Set the custom singular name of the item.
938
+     *
939
+     * @since 1.0.19
940
+     * @param  string $value new custom singular name.
941
+     */
942
+    public function set_custom_singular_name( $value ) {
943 943
         $this->set_prop( 'custom_singular_name', $value );
944 944
     }
945 945
 
946 946
     /**
947
-	 * Sets if an item is editable..
948
-	 *
949
-	 * @since 1.0.19
950
-	 * @param  int|bool $value whether or not the item is editable.
951
-	 */
952
-	public function set_is_editable( $value ) {
953
-		$this->set_prop( 'is_editable', (int) $value );
947
+     * Sets if an item is editable..
948
+     *
949
+     * @since 1.0.19
950
+     * @param  int|bool $value whether or not the item is editable.
951
+     */
952
+    public function set_is_editable( $value ) {
953
+        $this->set_prop( 'is_editable', (int) $value );
954 954
     }
955 955
 
956 956
     /**
957
-	 * Sets if dynamic pricing is enabled.
958
-	 *
959
-	 * @since 1.0.19
960
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
961
-	 */
962
-	public function set_is_dynamic_pricing( $value ) {
957
+     * Sets if dynamic pricing is enabled.
958
+     *
959
+     * @since 1.0.19
960
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
961
+     */
962
+    public function set_is_dynamic_pricing( $value ) {
963 963
         $this->set_prop( 'is_dynamic_pricing', (int) $value );
964 964
     }
965 965
 
966 966
     /**
967
-	 * Sets the minimum price if dynamic pricing is enabled.
968
-	 *
969
-	 * @since 1.0.19
970
-	 * @param  float $value minimum price.
971
-	 */
972
-	public function set_minimum_price( $value ) {
967
+     * Sets the minimum price if dynamic pricing is enabled.
968
+     *
969
+     * @since 1.0.19
970
+     * @param  float $value minimum price.
971
+     */
972
+    public function set_minimum_price( $value ) {
973 973
         $this->set_prop( 'minimum_price',  (float) wpinv_sanitize_amount( $value ) );
974 974
     }
975 975
 
976 976
     /**
977
-	 * Sets if this is a recurring item.
978
-	 *
979
-	 * @since 1.0.19
980
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
981
-	 */
982
-	public function set_is_recurring( $value ) {
977
+     * Sets if this is a recurring item.
978
+     *
979
+     * @since 1.0.19
980
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
981
+     */
982
+    public function set_is_recurring( $value ) {
983 983
         $this->set_prop( 'is_recurring', (int) $value );
984 984
     }
985 985
 
986 986
     /**
987
-	 * Set the recurring period.
988
-	 *
989
-	 * @since 1.0.19
990
-	 * @param  string $value new period.
991
-	 */
992
-	public function set_recurring_period( $value ) {
987
+     * Set the recurring period.
988
+     *
989
+     * @since 1.0.19
990
+     * @param  string $value new period.
991
+     */
992
+    public function set_recurring_period( $value ) {
993 993
         $this->set_prop( 'recurring_period', $value );
994 994
     }
995 995
 
996 996
     /**
997
-	 * Set the recurring interval.
998
-	 *
999
-	 * @since 1.0.19
1000
-	 * @param  int $value recurring interval.
1001
-	 */
1002
-	public function set_recurring_interval( $value ) {
997
+     * Set the recurring interval.
998
+     *
999
+     * @since 1.0.19
1000
+     * @param  int $value recurring interval.
1001
+     */
1002
+    public function set_recurring_interval( $value ) {
1003 1003
         return $this->set_prop( 'recurring_interval', (int) $value );
1004 1004
     }
1005 1005
 
1006 1006
     /**
1007
-	 * Get the recurring limit.
1008
-	 * @since 1.0.19
1009
-	 * @param  int $value The recurring limit.
1010
-	 * @return int
1011
-	 */
1012
-	public function set_recurring_limit( $value ) {
1007
+     * Get the recurring limit.
1008
+     * @since 1.0.19
1009
+     * @param  int $value The recurring limit.
1010
+     * @return int
1011
+     */
1012
+    public function set_recurring_limit( $value ) {
1013 1013
         $this->set_prop( 'recurring_limit', (int) $value );
1014 1014
     }
1015 1015
 
1016 1016
     /**
1017
-	 * Checks if we have a free trial.
1018
-	 *
1019
-	 * @since 1.0.19
1020
-	 * @param  int|bool $value whether or not it has a free trial.
1021
-	 */
1022
-	public function set_is_free_trial( $value ) {
1017
+     * Checks if we have a free trial.
1018
+     *
1019
+     * @since 1.0.19
1020
+     * @param  int|bool $value whether or not it has a free trial.
1021
+     */
1022
+    public function set_is_free_trial( $value ) {
1023 1023
         $this->set_prop( 'is_free_trial', (int) $value );
1024 1024
     }
1025 1025
 
1026 1026
     /**
1027
-	 * Set the trial period.
1028
-	 *
1029
-	 * @since 1.0.19
1030
-	 * @param  string $value trial period.
1031
-	 */
1032
-	public function set_trial_period( $value ) {
1027
+     * Set the trial period.
1028
+     *
1029
+     * @since 1.0.19
1030
+     * @param  string $value trial period.
1031
+     */
1032
+    public function set_trial_period( $value ) {
1033 1033
         $this->set_prop( 'trial_period', $value );
1034 1034
     }
1035 1035
 
1036 1036
     /**
1037
-	 * Set the trial interval.
1038
-	 *
1039
-	 * @since 1.0.19
1040
-	 * @param  int $value trial interval.
1041
-	 */
1042
-	public function set_trial_interval( $value ) {
1037
+     * Set the trial interval.
1038
+     *
1039
+     * @since 1.0.19
1040
+     * @param  int $value trial interval.
1041
+     */
1042
+    public function set_trial_interval( $value ) {
1043 1043
         $this->set_prop( 'trial_interval', $value );
1044 1044
     }
1045 1045
 
@@ -1047,17 +1047,17 @@  discard block
 block discarded – undo
1047 1047
      * Create an item. For backwards compatibilty.
1048 1048
      * 
1049 1049
      * @deprecated
1050
-	 * @return int item id
1050
+     * @return int item id
1051 1051
      */
1052 1052
     public function create( $data = array() ) {
1053 1053
 
1054
-		// Set the properties.
1055
-		if ( is_array( $data ) ) {
1056
-			$this->set_props( $data );
1057
-		}
1054
+        // Set the properties.
1055
+        if ( is_array( $data ) ) {
1056
+            $this->set_props( $data );
1057
+        }
1058 1058
 
1059
-		// Save the item.
1060
-		return $this->save();
1059
+        // Save the item.
1060
+        return $this->save();
1061 1061
 
1062 1062
     }
1063 1063
 
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
      * Updates an item. For backwards compatibilty.
1066 1066
      * 
1067 1067
      * @deprecated
1068
-	 * @return int item id
1068
+     * @return int item id
1069 1069
      */
1070 1070
     public function update( $data = array() ) {
1071 1071
         return $this->create( $data );
@@ -1081,93 +1081,93 @@  discard block
 block discarded – undo
1081 1081
 	*/
1082 1082
 
1083 1083
     /**
1084
-	 * Checks whether the item has enabled dynamic pricing.
1085
-	 *
1086
-	 * @since 1.0.19
1087
-	 * @return bool
1088
-	 */
1089
-	public function user_can_set_their_price() {
1084
+     * Checks whether the item has enabled dynamic pricing.
1085
+     *
1086
+     * @since 1.0.19
1087
+     * @return bool
1088
+     */
1089
+    public function user_can_set_their_price() {
1090 1090
         return (bool) $this->get_is_dynamic_pricing();
1091
-	}
1091
+    }
1092 1092
 	
1093
-	/**
1094
-	 * Checks whether the item is recurring.
1095
-	 *
1096
-	 * @since 1.0.19
1097
-	 * @return bool
1098
-	 */
1099
-	public function is_recurring() {
1093
+    /**
1094
+     * Checks whether the item is recurring.
1095
+     *
1096
+     * @since 1.0.19
1097
+     * @return bool
1098
+     */
1099
+    public function is_recurring() {
1100 1100
         return (bool) $this->get_is_recurring();
1101 1101
     }
1102 1102
 
1103 1103
     /**
1104
-	 * Checks whether the item has a free trial.
1105
-	 *
1106
-	 * @since 1.0.19
1107
-	 * @return bool
1108
-	 */
1104
+     * Checks whether the item has a free trial.
1105
+     *
1106
+     * @since 1.0.19
1107
+     * @return bool
1108
+     */
1109 1109
     public function has_free_trial() {
1110 1110
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
1111 1111
         return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
1112 1112
     }
1113 1113
 
1114 1114
     /**
1115
-	 * Checks whether the item is free.
1116
-	 *
1117
-	 * @since 1.0.19
1118
-	 * @return bool
1119
-	 */
1115
+     * Checks whether the item is free.
1116
+     *
1117
+     * @since 1.0.19
1118
+     * @return bool
1119
+     */
1120 1120
     public function is_free() {
1121 1121
         $is_free   = $this->get_price() == 0;
1122 1122
         return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
1123 1123
     }
1124 1124
 
1125 1125
     /**
1126
-	 * Checks the item status against a passed in status.
1127
-	 *
1128
-	 * @param array|string $status Status to check.
1129
-	 * @return bool
1130
-	 */
1131
-	public function has_status( $status ) {
1132
-		$has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1133
-		return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1126
+     * Checks the item status against a passed in status.
1127
+     *
1128
+     * @param array|string $status Status to check.
1129
+     * @return bool
1130
+     */
1131
+    public function has_status( $status ) {
1132
+        $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1133
+        return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1134 1134
     }
1135 1135
 
1136 1136
     /**
1137
-	 * Checks the item type against a passed in types.
1138
-	 *
1139
-	 * @param array|string $type Type to check.
1140
-	 * @return bool
1141
-	 */
1142
-	public function is_type( $type ) {
1143
-		$is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1144
-		return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1145
-	}
1137
+     * Checks the item type against a passed in types.
1138
+     *
1139
+     * @param array|string $type Type to check.
1140
+     * @return bool
1141
+     */
1142
+    public function is_type( $type ) {
1143
+        $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1144
+        return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1145
+    }
1146 1146
 
1147 1147
     /**
1148
-	 * Checks whether the item is editable.
1149
-	 *
1150
-	 * @since 1.0.19
1151
-	 * @return bool
1152
-	 */
1148
+     * Checks whether the item is editable.
1149
+     *
1150
+     * @since 1.0.19
1151
+     * @return bool
1152
+     */
1153 1153
     public function is_editable() {
1154 1154
         $is_editable = $this->get_is_editable();
1155 1155
         return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1156
-	}
1156
+    }
1157 1157
 
1158
-	/**
1159
-	 * Returns an array of cart fees.
1160
-	 */
1161
-	public function get_fees() {
1158
+    /**
1159
+     * Returns an array of cart fees.
1160
+     */
1161
+    public function get_fees() {
1162 1162
         return array();
1163 1163
     }
1164 1164
 
1165 1165
     /**
1166
-	 * Checks whether the item is purchasable.
1167
-	 *
1168
-	 * @since 1.0.19
1169
-	 * @return bool
1170
-	 */
1166
+     * Checks whether the item is purchasable.
1167
+     *
1168
+     * @since 1.0.19
1169
+     * @return bool
1170
+     */
1171 1171
     public function can_purchase() {
1172 1172
         $can_purchase = $this->exists();
1173 1173
 
@@ -1179,11 +1179,11 @@  discard block
 block discarded – undo
1179 1179
     }
1180 1180
 
1181 1181
     /**
1182
-	 * Checks whether the item supports dynamic pricing.
1183
-	 *
1184
-	 * @since 1.0.19
1185
-	 * @return bool
1186
-	 */
1182
+     * Checks whether the item supports dynamic pricing.
1183
+     *
1184
+     * @since 1.0.19
1185
+     * @return bool
1186
+     */
1187 1187
     public function supports_dynamic_pricing() {
1188 1188
         return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1189 1189
     }
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 1 patch
Indentation   +408 added lines, -408 removed lines patch added patch discarded remove patch
@@ -12,472 +12,472 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Invoice_Notification_Emails {
14 14
 
15
-	/**
16
-	 * The array of invoice email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $invoice_actions;
21
-
22
-	/**
23
-	 * Class constructor
24
-	 *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->invoice_actions = apply_filters(
29
-			'getpaid_notification_email_invoice_triggers',
30
-			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
-				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
-				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
-				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
-				'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
-				'getpaid_invoice_status_publish'        => 'completed_invoice',
37
-				'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
-				'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
-				'getpaid_new_customer_note'             => 'user_note',
40
-				'getpaid_daily_maintenance'             => 'overdue',
41
-			)
42
-		);
43
-
44
-		$this->init_hooks();
45
-
46
-	}
47
-
48
-	/**
49
-	 * Registers email hooks.
50
-	 */
51
-	public function init_hooks() {
52
-
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
-
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
58
-		}
59
-	}
60
-
61
-	/**
62
-	 * Registers an email hook for an invoice action.
63
-	 * 
64
-	 * @param string $hook
65
-	 * @param string|array $email_type
66
-	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
68
-
69
-		$email_type = wpinv_parse_list( $email_type );
70
-
71
-		foreach ( $email_type as $type ) {
72
-
73
-			$email = new GetPaid_Notification_Email( $type );
74
-
75
-			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
77
-				continue;
78
-			}
79
-
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
82
-				continue;
83
-			}
84
-
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
-		}
87
-
88
-	}
89
-
90
-	/**
91
-	 * Filters invoice merge tags.
92
-	 *
93
-	 * @param array $merge_tags
94
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
-	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
97
-
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
-			return array_merge(
100
-				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
102
-			);
103
-		}
104
-
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
-			return array_merge(
107
-				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
109
-			);
110
-		}
111
-
112
-		return $merge_tags;
113
-
114
-	}
115
-
116
-	/**
117
-	 * Generates invoice merge tags.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return array
121
-	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
123
-
124
-		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
126
-			return array();
127
-		}
128
-
129
-		$merge_tags = array(
130
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'               => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
-		);
149
-
150
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
-
152
-		if ( is_array( $payment_form_data ) ) {
153
-
154
-			foreach ( $payment_form_data as $label => $value ) {
155
-
156
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
-
159
-				if ( is_scalar ( $value ) ) {
160
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
-				}
162
-
163
-			}
164
-
165
-		}
166
-
167
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
168
-	}
169
-
170
-	/**
171
-	 * Helper function to send an email.
172
-	 *
173
-	 * @param WPInv_Invoice $invoice
174
-	 * @param GetPaid_Notification_Email $email
175
-	 * @param string $type
176
-	 * @param string|array $recipients
177
-	 * @param array $extra_args Extra template args.
178
-	 */
179
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
180
-
181
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
182
-
183
-		if ( apply_filters( 'getpaid_skip_invoice_email', false, $type, $invoice ) ) {
184
-			return;
185
-		}
186
-
187
-		$mailer     = new GetPaid_Notification_Email_Sender();
188
-		$merge_tags = $email->get_merge_tags();
189
-
190
-		$result = $mailer->send(
191
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
192
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
193
-			$email->get_content( $merge_tags, $extra_args ),
194
-			$email->get_attachments()
195
-		);
196
-
197
-		// Maybe send a copy to the admin.
198
-		if ( $email->include_admin_bcc() ) {
199
-			$mailer->send(
200
-				wpinv_get_admin_email(),
201
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
202
-				$email->get_content( $merge_tags ),
203
-				$email->get_attachments()
204
-			);
205
-		}
206
-
207
-		if ( $result ) {
208
-			$invoice->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
209
-		} else {
210
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );	
211
-		}
212
-
213
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
214
-
215
-		return $result;
216
-	}
217
-
218
-	/**
219
-	 * Also send emails to any cc users.
220
-	 *
221
-	 * @param array $recipients
222
-	 * @param GetPaid_Notification_Email $email
223
-	 */
224
-	public function filter_email_recipients( $recipients, $email ) {
225
-
226
-		if ( ! $email->is_admin_email() ) {
227
-			$cc = $email->object->get_email_cc();
228
-
229
-			if ( ! empty( $cc ) ) {
230
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
231
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
232
-			}
15
+    /**
16
+     * The array of invoice email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $invoice_actions;
21
+
22
+    /**
23
+     * Class constructor
24
+     *
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->invoice_actions = apply_filters(
29
+            'getpaid_notification_email_invoice_triggers',
30
+            array(
31
+                'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
+                'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
+                'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
+                'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
+                'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
+                'getpaid_invoice_status_publish'        => 'completed_invoice',
37
+                'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
+                'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
+                'getpaid_new_customer_note'             => 'user_note',
40
+                'getpaid_daily_maintenance'             => 'overdue',
41
+            )
42
+        );
43
+
44
+        $this->init_hooks();
45
+
46
+    }
47
+
48
+    /**
49
+     * Registers email hooks.
50
+     */
51
+    public function init_hooks() {
52
+
53
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
+        add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
+
56
+        foreach ( $this->invoice_actions as $hook => $email_type ) {
57
+            $this->init_email_type_hook( $hook, $email_type );
58
+        }
59
+    }
60
+
61
+    /**
62
+     * Registers an email hook for an invoice action.
63
+     * 
64
+     * @param string $hook
65
+     * @param string|array $email_type
66
+     */
67
+    public function init_email_type_hook( $hook, $email_type ) {
68
+
69
+        $email_type = wpinv_parse_list( $email_type );
70
+
71
+        foreach ( $email_type as $type ) {
72
+
73
+            $email = new GetPaid_Notification_Email( $type );
74
+
75
+            // Abort if it is not active.
76
+            if ( ! $email->is_active() ) {
77
+                continue;
78
+            }
79
+
80
+            if ( method_exists( $this, $type ) ) {
81
+                add_action( $hook, array( $this, $type ), 100, 2 );
82
+                continue;
83
+            }
84
+
85
+            do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
+        }
87
+
88
+    }
89
+
90
+    /**
91
+     * Filters invoice merge tags.
92
+     *
93
+     * @param array $merge_tags
94
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
+     */
96
+    public function invoice_merge_tags( $merge_tags, $object ) {
97
+
98
+        if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
+            return array_merge(
100
+                $merge_tags,
101
+                $this->get_invoice_merge_tags( $object )
102
+            );
103
+        }
104
+
105
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
+            return array_merge(
107
+                $merge_tags,
108
+                $this->get_invoice_merge_tags( $object->get_parent_payment() )
109
+            );
110
+        }
111
+
112
+        return $merge_tags;
113
+
114
+    }
115
+
116
+    /**
117
+     * Generates invoice merge tags.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return array
121
+     */
122
+    public function get_invoice_merge_tags( $invoice ) {
123
+
124
+        // Abort if it does not exist.
125
+        if ( ! $invoice->get_id() ) {
126
+            return array();
127
+        }
128
+
129
+        $merge_tags = array(
130
+            '{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
+            '{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
+            '{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
+            '{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
+            '{email}'               => sanitize_email( $invoice->get_email() ),
135
+            '{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
+            '{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
+            '{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
+            '{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
+            '{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
+            '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
+            '{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
+            '{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
+            '{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
+            '{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
+            '{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
+            '{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
+            '{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
+        );
149
+
150
+        $payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
+
152
+        if ( is_array( $payment_form_data ) ) {
153
+
154
+            foreach ( $payment_form_data as $label => $value ) {
155
+
156
+                $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
+                $value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
+
159
+                if ( is_scalar ( $value ) ) {
160
+                    $merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
+                }
162
+
163
+            }
164
+
165
+        }
166
+
167
+        return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
168
+    }
169
+
170
+    /**
171
+     * Helper function to send an email.
172
+     *
173
+     * @param WPInv_Invoice $invoice
174
+     * @param GetPaid_Notification_Email $email
175
+     * @param string $type
176
+     * @param string|array $recipients
177
+     * @param array $extra_args Extra template args.
178
+     */
179
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
180
+
181
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
182
+
183
+        if ( apply_filters( 'getpaid_skip_invoice_email', false, $type, $invoice ) ) {
184
+            return;
185
+        }
186
+
187
+        $mailer     = new GetPaid_Notification_Email_Sender();
188
+        $merge_tags = $email->get_merge_tags();
189
+
190
+        $result = $mailer->send(
191
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
192
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
193
+            $email->get_content( $merge_tags, $extra_args ),
194
+            $email->get_attachments()
195
+        );
196
+
197
+        // Maybe send a copy to the admin.
198
+        if ( $email->include_admin_bcc() ) {
199
+            $mailer->send(
200
+                wpinv_get_admin_email(),
201
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
202
+                $email->get_content( $merge_tags ),
203
+                $email->get_attachments()
204
+            );
205
+        }
206
+
207
+        if ( $result ) {
208
+            $invoice->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
209
+        } else {
210
+            $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );	
211
+        }
212
+
213
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
214
+
215
+        return $result;
216
+    }
217
+
218
+    /**
219
+     * Also send emails to any cc users.
220
+     *
221
+     * @param array $recipients
222
+     * @param GetPaid_Notification_Email $email
223
+     */
224
+    public function filter_email_recipients( $recipients, $email ) {
225
+
226
+        if ( ! $email->is_admin_email() ) {
227
+            $cc = $email->object->get_email_cc();
228
+
229
+            if ( ! empty( $cc ) ) {
230
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
231
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
232
+            }
233 233
 
234
-		}
234
+        }
235 235
 
236
-		return $recipients;
236
+        return $recipients;
237 237
 
238
-	}
238
+    }
239 239
 
240
-	/**
241
-	 * Sends a new invoice notification.
242
-	 *
243
-	 * @param WPInv_Invoice $invoice
244
-	 */
245
-	public function new_invoice( $invoice ) {
240
+    /**
241
+     * Sends a new invoice notification.
242
+     *
243
+     * @param WPInv_Invoice $invoice
244
+     */
245
+    public function new_invoice( $invoice ) {
246 246
 
247
-		// Only send this email for invoices created via the admin page.
248
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
249
-			return;
250
-		}
247
+        // Only send this email for invoices created via the admin page.
248
+        if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
249
+            return;
250
+        }
251 251
 
252
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
253
-		$recipient = wpinv_get_admin_email();
252
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
253
+        $recipient = wpinv_get_admin_email();
254 254
 
255
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
255
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
256 256
 
257
-	}
257
+    }
258 258
 
259
-	/**
260
-	 * Sends a cancelled invoice notification.
261
-	 *
262
-	 * @param WPInv_Invoice $invoice
263
-	 */
264
-	public function cancelled_invoice( $invoice ) {
259
+    /**
260
+     * Sends a cancelled invoice notification.
261
+     *
262
+     * @param WPInv_Invoice $invoice
263
+     */
264
+    public function cancelled_invoice( $invoice ) {
265 265
 
266
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
267
-		$recipient = wpinv_get_admin_email();
266
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
267
+        $recipient = wpinv_get_admin_email();
268 268
 
269
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
269
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
270 270
 
271
-	}
271
+    }
272 272
 
273
-	/**
274
-	 * Sends a failed invoice notification.
275
-	 *
276
-	 * @param WPInv_Invoice $invoice
277
-	 */
278
-	public function failed_invoice( $invoice ) {
273
+    /**
274
+     * Sends a failed invoice notification.
275
+     *
276
+     * @param WPInv_Invoice $invoice
277
+     */
278
+    public function failed_invoice( $invoice ) {
279 279
 
280
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
281
-		$recipient = wpinv_get_admin_email();
280
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
281
+        $recipient = wpinv_get_admin_email();
282 282
 
283
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
283
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
284 284
 
285
-	}
285
+    }
286 286
 
287
-	/**
288
-	 * Sends a notification whenever an invoice is put on hold.
289
-	 *
290
-	 * @param WPInv_Invoice $invoice
291
-	 */
292
-	public function onhold_invoice( $invoice ) {
287
+    /**
288
+     * Sends a notification whenever an invoice is put on hold.
289
+     *
290
+     * @param WPInv_Invoice $invoice
291
+     */
292
+    public function onhold_invoice( $invoice ) {
293 293
 
294
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
295
-		$recipient = $invoice->get_email();
294
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
295
+        $recipient = $invoice->get_email();
296 296
 
297
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
297
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
298 298
 
299
-	}
299
+    }
300 300
 
301
-	/**
302
-	 * Sends a notification whenever an invoice is marked as processing payment.
303
-	 *
304
-	 * @param WPInv_Invoice $invoice
305
-	 */
306
-	public function processing_invoice( $invoice ) {
301
+    /**
302
+     * Sends a notification whenever an invoice is marked as processing payment.
303
+     *
304
+     * @param WPInv_Invoice $invoice
305
+     */
306
+    public function processing_invoice( $invoice ) {
307 307
 
308
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
309
-		$recipient = $invoice->get_email();
308
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
309
+        $recipient = $invoice->get_email();
310 310
 
311
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
311
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
312 312
 
313
-	}
313
+    }
314 314
 
315
-	/**
316
-	 * Sends a notification whenever an invoice is paid.
317
-	 *
318
-	 * @param WPInv_Invoice $invoice
319
-	 */
320
-	public function completed_invoice( $invoice ) {
315
+    /**
316
+     * Sends a notification whenever an invoice is paid.
317
+     *
318
+     * @param WPInv_Invoice $invoice
319
+     */
320
+    public function completed_invoice( $invoice ) {
321 321
 
322
-		// (Maybe) abort if it is a renewal invoice.
323
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
324
-			return;
325
-		}
322
+        // (Maybe) abort if it is a renewal invoice.
323
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
324
+            return;
325
+        }
326 326
 
327
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
328
-		$recipient = $invoice->get_email();
327
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
328
+        $recipient = $invoice->get_email();
329 329
 
330
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
330
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
331 331
 
332
-	}
332
+    }
333 333
 
334
-	/**
335
-	 * Sends a notification whenever an invoice is refunded.
336
-	 *
337
-	 * @param WPInv_Invoice $invoice
338
-	 */
339
-	public function refunded_invoice( $invoice ) {
334
+    /**
335
+     * Sends a notification whenever an invoice is refunded.
336
+     *
337
+     * @param WPInv_Invoice $invoice
338
+     */
339
+    public function refunded_invoice( $invoice ) {
340 340
 
341
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
342
-		$recipient = $invoice->get_email();
341
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
342
+        $recipient = $invoice->get_email();
343 343
 
344
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
344
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
345 345
 
346
-	}
346
+    }
347 347
 
348
-	/**
349
-	 * Notifies a user about new invoices
350
-	 *
351
-	 * @param WPInv_Invoice $invoice
352
-	 * @param bool $force
353
-	 */
354
-	public function user_invoice( $invoice, $force = false ) {
348
+    /**
349
+     * Notifies a user about new invoices
350
+     *
351
+     * @param WPInv_Invoice $invoice
352
+     * @param bool $force
353
+     */
354
+    public function user_invoice( $invoice, $force = false ) {
355 355
 
356
-		if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
357
-			return;
358
-		}
356
+        if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
357
+            return;
358
+        }
359 359
 
360
-		// Only send this email for invoices created via the admin page.
361
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
362
-			return;
363
-		}
360
+        // Only send this email for invoices created via the admin page.
361
+        if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
362
+            return;
363
+        }
364 364
 
365
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
366
-		$recipient = $invoice->get_email();
365
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
366
+        $recipient = $invoice->get_email();
367 367
 
368
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
368
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
369 369
 
370
-	}
370
+    }
371 371
 
372
-	/**
373
-	 * Checks if an invoice is a payment form invoice.
374
-	 *
375
-	 * @param int $invoice
376
-	 * @return bool
377
-	 */
378
-	public function is_payment_form_invoice( $invoice ) {
379
-		return empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
380
-	}
372
+    /**
373
+     * Checks if an invoice is a payment form invoice.
374
+     *
375
+     * @param int $invoice
376
+     * @return bool
377
+     */
378
+    public function is_payment_form_invoice( $invoice ) {
379
+        return empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
380
+    }
381 381
 
382
-	/**
383
-	 * Notifies admin about new invoice notes
384
-	 *
385
-	 * @param WPInv_Invoice $invoice
386
-	 * @param string $note
387
-	 */
388
-	public function user_note( $invoice, $note ) {
389
-
390
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
391
-		$recipient = $invoice->get_email();
382
+    /**
383
+     * Notifies admin about new invoice notes
384
+     *
385
+     * @param WPInv_Invoice $invoice
386
+     * @param string $note
387
+     */
388
+    public function user_note( $invoice, $note ) {
389
+
390
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
391
+        $recipient = $invoice->get_email();
392 392
 
393
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
394
-
395
-	}
393
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
394
+
395
+    }
396 396
 
397
-	/**
398
-	 * (Force) Sends overdue notices.
399
-	 *
400
-	 * @param WPInv_Invoice $invoice
401
-	 */
402
-	public function force_send_overdue_notice( $invoice ) {
403
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
404
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
405
-	}
406
-
407
-	/**
408
-	 * Sends overdue notices.
409
-	 *
410
-	 * @TODO: Create an invoices query class.
411
-	 */
412
-	public function overdue() {
413
-		global $wpdb;
414
-
415
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
416
-
417
-		// Fetch reminder days.
418
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
419
-
420
-		// Abort if non is set.
421
-		if ( empty( $reminder_days ) ) {
422
-			return;
423
-		}
424
-
425
-		// Retrieve date query.
426
-		$date_query = $this->get_date_query( $reminder_days );
427
-
428
-		// Invoices table.
429
-		$table = $wpdb->prefix . 'getpaid_invoices';
430
-
431
-		// Fetch invoices.
432
-		$invoices  = $wpdb->get_col(
433
-			"SELECT posts.ID FROM $wpdb->posts as posts
397
+    /**
398
+     * (Force) Sends overdue notices.
399
+     *
400
+     * @param WPInv_Invoice $invoice
401
+     */
402
+    public function force_send_overdue_notice( $invoice ) {
403
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
404
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
405
+    }
406
+
407
+    /**
408
+     * Sends overdue notices.
409
+     *
410
+     * @TODO: Create an invoices query class.
411
+     */
412
+    public function overdue() {
413
+        global $wpdb;
414
+
415
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
416
+
417
+        // Fetch reminder days.
418
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
419
+
420
+        // Abort if non is set.
421
+        if ( empty( $reminder_days ) ) {
422
+            return;
423
+        }
424
+
425
+        // Retrieve date query.
426
+        $date_query = $this->get_date_query( $reminder_days );
427
+
428
+        // Invoices table.
429
+        $table = $wpdb->prefix . 'getpaid_invoices';
430
+
431
+        // Fetch invoices.
432
+        $invoices  = $wpdb->get_col(
433
+            "SELECT posts.ID FROM $wpdb->posts as posts
434 434
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
435 435
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
436 436
 
437
-		foreach ( $invoices as $invoice ) {
437
+        foreach ( $invoices as $invoice ) {
438 438
 
439
-			// Only send this email for invoices created via the admin page.
440
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
441
-				$invoice       = new WPInv_Invoice( $invoice );
442
-				$email->object = $invoice;
439
+            // Only send this email for invoices created via the admin page.
440
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
441
+                $invoice       = new WPInv_Invoice( $invoice );
442
+                $email->object = $invoice;
443 443
 
444
-				if ( $invoice->needs_payment() ) {
445
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
446
-				}
444
+                if ( $invoice->needs_payment() ) {
445
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
446
+                }
447 447
 
448
-			}
448
+            }
449 449
 
450
-		}
450
+        }
451 451
 
452
-	}
452
+    }
453 453
 
454
-	/**
455
-	 * Calculates the date query for an invoices query
456
-	 *
457
-	 * @param array $reminder_days
458
-	 * @return string
459
-	 */
460
-	public function get_date_query( $reminder_days ) {
454
+    /**
455
+     * Calculates the date query for an invoices query
456
+     *
457
+     * @param array $reminder_days
458
+     * @return string
459
+     */
460
+    public function get_date_query( $reminder_days ) {
461 461
 
462
-		$date_query = array(
463
-			'relation'  => 'OR'
464
-		);
462
+        $date_query = array(
463
+            'relation'  => 'OR'
464
+        );
465 465
 
466
-		foreach ( $reminder_days as $days ) {
467
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
466
+        foreach ( $reminder_days as $days ) {
467
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
468 468
 
469
-			$date_query[] = array(
470
-				'year'  => $date['year'],
471
-				'month' => $date['month'],
472
-				'day'   => $date['day'],
473
-			);
469
+            $date_query[] = array(
470
+                'year'  => $date['year'],
471
+                'month' => $date['month'],
472
+                'day'   => $date['day'],
473
+            );
474 474
 
475
-		}
475
+        }
476 476
 
477
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
477
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
478 478
 
479
-		return $date_query->get_sql();
479
+        return $date_query->get_sql();
480 480
 
481
-	}
481
+    }
482 482
 
483 483
 }
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Indentation   +2494 added lines, -2494 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,
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
         'subtotal'             => 0,
68 68
         'total_discount'       => 0,
69 69
         'total_tax'            => 0,
70
-		'total_fees'           => 0,
71
-		'total'                => 0,
70
+        'total_fees'           => 0,
71
+        'total'                => 0,
72 72
         'fees'                 => array(),
73 73
         'discounts'            => array(),
74 74
         'taxes'                => array(),
@@ -80,22 +80,22 @@  discard block
 block discarded – undo
80 80
         'transaction_id'       => '',
81 81
         'currency'             => '',
82 82
         'disable_taxes'        => false,
83
-		'subscription_id'      => null,
84
-		'remote_subscription_id' => null,
85
-		'is_viewed'            => false,
86
-		'email_cc'             => '',
87
-		'template'             => 'quantity', // hours, amount only
88
-		'created_via'          => null,
83
+        'subscription_id'      => null,
84
+        'remote_subscription_id' => null,
85
+        'is_viewed'            => false,
86
+        'email_cc'             => '',
87
+        'template'             => 'quantity', // hours, amount only
88
+        'created_via'          => null,
89 89
     );
90 90
 
91 91
     /**
92
-	 * Stores meta in cache for future reads.
93
-	 *
94
-	 * A group must be set to to enable caching.
95
-	 *
96
-	 * @var string
97
-	 */
98
-	protected $cache_group = 'getpaid_invoices';
92
+     * Stores meta in cache for future reads.
93
+     *
94
+     * A group must be set to to enable caching.
95
+     *
96
+     * @var string
97
+     */
98
+    protected $cache_group = 'getpaid_invoices';
99 99
 
100 100
     /**
101 101
      * Stores a reference to the original WP_Post object
@@ -109,111 +109,111 @@  discard block
 block discarded – undo
109 109
      *
110 110
      * @var int
111 111
      */
112
-	protected $recurring_item = null;
112
+    protected $recurring_item = null;
113 113
 
114
-	/**
114
+    /**
115 115
      * Stores an array of item totals.
116
-	 *
117
-	 * e.g $totals['discount'] = array(
118
-	 * 		'initial'   => 10,
119
-	 * 		'recurring' => 10,
120
-	 * )
116
+     *
117
+     * e.g $totals['discount'] = array(
118
+     * 		'initial'   => 10,
119
+     * 		'recurring' => 10,
120
+     * )
121 121
      *
122 122
      * @var array
123 123
      */
124
-	protected $totals = array();
124
+    protected $totals = array();
125 125
 
126
-	/**
126
+    /**
127 127
      * Tax rate.
128
-	 *
128
+     *
129 129
      * @var float
130 130
      */
131
-	protected $tax_rate = 0;
131
+    protected $tax_rate = 0;
132 132
 
133
-	/**
134
-	 * Stores the status transition information.
135
-	 *
136
-	 * @since 1.0.19
137
-	 * @var bool|array
138
-	 */
139
-	protected $status_transition = false;
133
+    /**
134
+     * Stores the status transition information.
135
+     *
136
+     * @since 1.0.19
137
+     * @var bool|array
138
+     */
139
+    protected $status_transition = false;
140 140
 
141 141
     /**
142
-	 * Get the invoice if ID is passed, otherwise the invoice is new and empty.
143
-	 *
144
-	 * @param  int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read.
145
-	 */
142
+     * Get the invoice if ID is passed, otherwise the invoice is new and empty.
143
+     *
144
+     * @param  int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read.
145
+     */
146 146
     public function __construct( $invoice = 0 ) {
147 147
 
148 148
         parent::__construct( $invoice );
149 149
 
150
-		if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) {
151
-			$this->set_id( (int) $invoice );
152
-		} elseif ( $invoice instanceof self ) {
153
-			$this->set_id( $invoice->get_id() );
154
-		} elseif ( ! empty( $invoice->ID ) ) {
155
-			$this->set_id( $invoice->ID );
156
-		} elseif ( is_array( $invoice ) ) {
157
-			$this->set_props( $invoice );
158
-
159
-			if ( isset( $invoice['ID'] ) ) {
160
-				$this->set_id( $invoice['ID'] );
161
-			}
162
-
163
-		} elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) {
164
-			$this->set_id( $invoice_id );
165
-		} elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) {
166
-			$this->set_id( $invoice_id );
167
-		} elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) {
168
-			$this->set_id( $invoice_id );
169
-		} else {
170
-			$this->set_object_read( true );
171
-		}
150
+        if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) {
151
+            $this->set_id( (int) $invoice );
152
+        } elseif ( $invoice instanceof self ) {
153
+            $this->set_id( $invoice->get_id() );
154
+        } elseif ( ! empty( $invoice->ID ) ) {
155
+            $this->set_id( $invoice->ID );
156
+        } elseif ( is_array( $invoice ) ) {
157
+            $this->set_props( $invoice );
158
+
159
+            if ( isset( $invoice['ID'] ) ) {
160
+                $this->set_id( $invoice['ID'] );
161
+            }
162
+
163
+        } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) {
164
+            $this->set_id( $invoice_id );
165
+        } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) {
166
+            $this->set_id( $invoice_id );
167
+        } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) {
168
+            $this->set_id( $invoice_id );
169
+        } else {
170
+            $this->set_object_read( true );
171
+        }
172 172
 
173 173
         // Load the datastore.
174
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
174
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
175 175
 
176
-		if ( $this->get_id() > 0 ) {
176
+        if ( $this->get_id() > 0 ) {
177 177
             $this->post = get_post( $this->get_id() );
178 178
             $this->ID   = $this->get_id();
179
-			$this->data_store->read( $this );
179
+            $this->data_store->read( $this );
180 180
         }
181 181
 
182 182
     }
183 183
 
184 184
     /**
185
-	 * Given an invoice key/number, it returns its id.
186
-	 *
187
-	 *
188
-	 * @static
189
-	 * @param string $value The invoice key or number
190
-	 * @param string $field Either key, transaction_id or number.
191
-	 * @since 1.0.15
192
-	 * @return int
193
-	 */
194
-	public static function get_invoice_id_by_field( $value, $field = 'key' ) {
185
+     * Given an invoice key/number, it returns its id.
186
+     *
187
+     *
188
+     * @static
189
+     * @param string $value The invoice key or number
190
+     * @param string $field Either key, transaction_id or number.
191
+     * @since 1.0.15
192
+     * @return int
193
+     */
194
+    public static function get_invoice_id_by_field( $value, $field = 'key' ) {
195 195
         global $wpdb;
196 196
 
197
-		// Trim the value.
198
-		$value = trim( $value );
197
+        // Trim the value.
198
+        $value = trim( $value );
199 199
 
200
-		if ( empty( $value ) ) {
201
-			return 0;
202
-		}
200
+        if ( empty( $value ) ) {
201
+            return 0;
202
+        }
203 203
 
204 204
         // Valid fields.
205 205
         $fields = array( 'key', 'number', 'transaction_id' );
206 206
 
207
-		// Ensure a field has been passed.
208
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
209
-			return 0;
210
-		}
207
+        // Ensure a field has been passed.
208
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
209
+            return 0;
210
+        }
211 211
 
212
-		// Maybe retrieve from the cache.
213
-		$invoice_id   = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" );
214
-		if ( false !== $invoice_id ) {
215
-			return $invoice_id;
216
-		}
212
+        // Maybe retrieve from the cache.
213
+        $invoice_id   = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" );
214
+        if ( false !== $invoice_id ) {
215
+            return $invoice_id;
216
+        }
217 217
 
218 218
         // Fetch from the db.
219 219
         $table       = $wpdb->prefix . 'getpaid_invoices';
@@ -221,10 +221,10 @@  discard block
 block discarded – undo
221 221
             $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
222 222
         );
223 223
 
224
-		// Update the cache with our data
225
-		wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" );
224
+        // Update the cache with our data
225
+        wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" );
226 226
 
227
-		return $invoice_id;
227
+        return $invoice_id;
228 228
     }
229 229
 
230 230
     /**
@@ -250,83 +250,83 @@  discard block
 block discarded – undo
250 250
     */
251 251
 
252 252
     /**
253
-	 * Get parent invoice ID.
254
-	 *
255
-	 * @since 1.0.19
256
-	 * @param  string $context View or edit context.
257
-	 * @return int
258
-	 */
259
-	public function get_parent_id( $context = 'view' ) {
260
-		return (int) $this->get_prop( 'parent_id', $context );
253
+     * Get parent invoice ID.
254
+     *
255
+     * @since 1.0.19
256
+     * @param  string $context View or edit context.
257
+     * @return int
258
+     */
259
+    public function get_parent_id( $context = 'view' ) {
260
+        return (int) $this->get_prop( 'parent_id', $context );
261 261
     }
262 262
 
263 263
     /**
264
-	 * Get parent invoice.
265
-	 *
266
-	 * @since 1.0.19
267
-	 * @return WPInv_Invoice
268
-	 */
264
+     * Get parent invoice.
265
+     *
266
+     * @since 1.0.19
267
+     * @return WPInv_Invoice
268
+     */
269 269
     public function get_parent_payment() {
270 270
         return new WPInv_Invoice( $this->get_parent_id() );
271 271
     }
272 272
 
273 273
     /**
274
-	 * Alias for self::get_parent_payment().
275
-	 *
276
-	 * @since 1.0.19
277
-	 * @return WPInv_Invoice
278
-	 */
274
+     * Alias for self::get_parent_payment().
275
+     *
276
+     * @since 1.0.19
277
+     * @return WPInv_Invoice
278
+     */
279 279
     public function get_parent() {
280 280
         return $this->get_parent_payment();
281 281
     }
282 282
 
283 283
     /**
284
-	 * Get invoice status.
285
-	 *
286
-	 * @since 1.0.19
287
-	 * @param  string $context View or edit context.
288
-	 * @return string
289
-	 */
290
-	public function get_status( $context = 'view' ) {
291
-		return $this->get_prop( 'status', $context );
292
-	}
284
+     * Get invoice status.
285
+     *
286
+     * @since 1.0.19
287
+     * @param  string $context View or edit context.
288
+     * @return string
289
+     */
290
+    public function get_status( $context = 'view' ) {
291
+        return $this->get_prop( 'status', $context );
292
+    }
293 293
 	
294
-	/**
295
-	 * Retrieves an array of possible invoice statuses.
296
-	 *
297
-	 * @since 1.0.19
298
-	 * @return array
299
-	 */
300
-	public function get_all_statuses() {
301
-		return wpinv_get_invoice_statuses( true, true, $this );
302
-    }
303
-
304
-    /**
305
-	 * Get invoice status nice name.
306
-	 *
307
-	 * @since 1.0.19
308
-	 * @return string
309
-	 */
294
+    /**
295
+     * Retrieves an array of possible invoice statuses.
296
+     *
297
+     * @since 1.0.19
298
+     * @return array
299
+     */
300
+    public function get_all_statuses() {
301
+        return wpinv_get_invoice_statuses( true, true, $this );
302
+    }
303
+
304
+    /**
305
+     * Get invoice status nice name.
306
+     *
307
+     * @since 1.0.19
308
+     * @return string
309
+     */
310 310
     public function get_status_nicename() {
311
-		$statuses = $this->get_all_statuses();
311
+        $statuses = $this->get_all_statuses();
312 312
 
313 313
         $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status();
314 314
 
315 315
         return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this );
316 316
     }
317 317
 
318
-	/**
319
-	 * Retrieves the invoice status class
320
-	 *
321
-	 * @since  1.0.19
322
-	 * @return string
323
-	 */
324
-	public function get_status_class() {
325
-		$statuses = getpaid_get_invoice_status_classes();
326
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
327
-	}
318
+    /**
319
+     * Retrieves the invoice status class
320
+     *
321
+     * @since  1.0.19
322
+     * @return string
323
+     */
324
+    public function get_status_class() {
325
+        $statuses = getpaid_get_invoice_status_classes();
326
+        return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
327
+    }
328 328
 
329
-	/**
329
+    /**
330 330
      * Retrieves the invoice status label html
331 331
      *
332 332
      * @since  1.0.0
@@ -334,263 +334,263 @@  discard block
 block discarded – undo
334 334
      */
335 335
     public function get_status_label_html() {
336 336
 
337
-		$status_label = sanitize_text_field( $this->get_status_nicename() );
338
-		$status       = sanitize_html_class( $this->get_status() );
339
-		$class        = esc_attr( $this->get_status_class() );
337
+        $status_label = sanitize_text_field( $this->get_status_nicename() );
338
+        $status       = sanitize_html_class( $this->get_status() );
339
+        $class        = esc_attr( $this->get_status_class() );
340 340
 
341
-		return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
342
-	}
341
+        return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
342
+    }
343 343
 
344 344
     /**
345
-	 * Get plugin version when the invoice was created.
346
-	 *
347
-	 * @since 1.0.19
348
-	 * @param  string $context View or edit context.
349
-	 * @return string
350
-	 */
351
-	public function get_version( $context = 'view' ) {
352
-		return $this->get_prop( 'version', $context );
353
-	}
345
+     * Get plugin version when the invoice was created.
346
+     *
347
+     * @since 1.0.19
348
+     * @param  string $context View or edit context.
349
+     * @return string
350
+     */
351
+    public function get_version( $context = 'view' ) {
352
+        return $this->get_prop( 'version', $context );
353
+    }
354 354
 
355
-	/**
356
-	 * @deprecated
357
-	 */
358
-	public function get_invoice_date( $format = true ) {
359
-		$date      = getpaid_format_date( $this->get_date_completed() );
360
-		$date      = empty( $date ) ? $this->get_date_created() : $this->get_date_completed();
361
-		$formatted = getpaid_format_date( $date );
355
+    /**
356
+     * @deprecated
357
+     */
358
+    public function get_invoice_date( $format = true ) {
359
+        $date      = getpaid_format_date( $this->get_date_completed() );
360
+        $date      = empty( $date ) ? $this->get_date_created() : $this->get_date_completed();
361
+        $formatted = getpaid_format_date( $date );
362 362
 
363
-		if ( $format ) {
364
-			return $formatted;
365
-		}
363
+        if ( $format ) {
364
+            return $formatted;
365
+        }
366 366
 
367
-		return empty( $formatted ) ? '' : $date;
367
+        return empty( $formatted ) ? '' : $date;
368 368
 
369 369
     }
370 370
 
371 371
     /**
372
-	 * Get date when the invoice was created.
373
-	 *
374
-	 * @since 1.0.19
375
-	 * @param  string $context View or edit context.
376
-	 * @return string
377
-	 */
378
-	public function get_date_created( $context = 'view' ) {
379
-		return $this->get_prop( 'date_created', $context );
380
-	}
372
+     * Get date when the invoice was created.
373
+     *
374
+     * @since 1.0.19
375
+     * @param  string $context View or edit context.
376
+     * @return string
377
+     */
378
+    public function get_date_created( $context = 'view' ) {
379
+        return $this->get_prop( 'date_created', $context );
380
+    }
381 381
 	
382
-	/**
383
-	 * Alias for self::get_date_created().
384
-	 *
385
-	 * @since 1.0.19
386
-	 * @param  string $context View or edit context.
387
-	 * @return string
388
-	 */
389
-	public function get_created_date( $context = 'view' ) {
390
-		return $this->get_date_created( $context );
391
-    }
392
-
393
-    /**
394
-	 * Get GMT date when the invoice was created.
395
-	 *
396
-	 * @since 1.0.19
397
-	 * @param  string $context View or edit context.
398
-	 * @return string
399
-	 */
400
-	public function get_date_created_gmt( $context = 'view' ) {
382
+    /**
383
+     * Alias for self::get_date_created().
384
+     *
385
+     * @since 1.0.19
386
+     * @param  string $context View or edit context.
387
+     * @return string
388
+     */
389
+    public function get_created_date( $context = 'view' ) {
390
+        return $this->get_date_created( $context );
391
+    }
392
+
393
+    /**
394
+     * Get GMT date when the invoice was created.
395
+     *
396
+     * @since 1.0.19
397
+     * @param  string $context View or edit context.
398
+     * @return string
399
+     */
400
+    public function get_date_created_gmt( $context = 'view' ) {
401 401
         $date = $this->get_date_created( $context );
402 402
 
403 403
         if ( $date ) {
404 404
             $date = get_gmt_from_date( $date );
405 405
         }
406
-		return $date;
406
+        return $date;
407 407
     }
408 408
 
409 409
     /**
410
-	 * Get date when the invoice was last modified.
411
-	 *
412
-	 * @since 1.0.19
413
-	 * @param  string $context View or edit context.
414
-	 * @return string
415
-	 */
416
-	public function get_date_modified( $context = 'view' ) {
417
-		return $this->get_prop( 'date_modified', $context );
418
-	}
410
+     * Get date when the invoice was last modified.
411
+     *
412
+     * @since 1.0.19
413
+     * @param  string $context View or edit context.
414
+     * @return string
415
+     */
416
+    public function get_date_modified( $context = 'view' ) {
417
+        return $this->get_prop( 'date_modified', $context );
418
+    }
419 419
 
420
-	/**
421
-	 * Alias for self::get_date_modified().
422
-	 *
423
-	 * @since 1.0.19
424
-	 * @param  string $context View or edit context.
425
-	 * @return string
426
-	 */
427
-	public function get_modified_date( $context = 'view' ) {
428
-		return $this->get_date_modified( $context );
420
+    /**
421
+     * Alias for self::get_date_modified().
422
+     *
423
+     * @since 1.0.19
424
+     * @param  string $context View or edit context.
425
+     * @return string
426
+     */
427
+    public function get_modified_date( $context = 'view' ) {
428
+        return $this->get_date_modified( $context );
429 429
     }
430 430
 
431 431
     /**
432
-	 * Get GMT date when the invoice was last modified.
433
-	 *
434
-	 * @since 1.0.19
435
-	 * @param  string $context View or edit context.
436
-	 * @return string
437
-	 */
438
-	public function get_date_modified_gmt( $context = 'view' ) {
432
+     * Get GMT date when the invoice was last modified.
433
+     *
434
+     * @since 1.0.19
435
+     * @param  string $context View or edit context.
436
+     * @return string
437
+     */
438
+    public function get_date_modified_gmt( $context = 'view' ) {
439 439
         $date = $this->get_date_modified( $context );
440 440
 
441 441
         if ( $date ) {
442 442
             $date = get_gmt_from_date( $date );
443 443
         }
444
-		return $date;
444
+        return $date;
445 445
     }
446 446
 
447 447
     /**
448
-	 * Get the invoice due date.
449
-	 *
450
-	 * @since 1.0.19
451
-	 * @param  string $context View or edit context.
452
-	 * @return string
453
-	 */
454
-	public function get_due_date( $context = 'view' ) {
455
-		return $this->get_prop( 'due_date', $context );
448
+     * Get the invoice due date.
449
+     *
450
+     * @since 1.0.19
451
+     * @param  string $context View or edit context.
452
+     * @return string
453
+     */
454
+    public function get_due_date( $context = 'view' ) {
455
+        return $this->get_prop( 'due_date', $context );
456 456
     }
457 457
 
458 458
     /**
459
-	 * Alias for self::get_due_date().
460
-	 *
461
-	 * @since 1.0.19
462
-	 * @param  string $context View or edit context.
463
-	 * @return string
464
-	 */
465
-	public function get_date_due( $context = 'view' ) {
466
-		return $this->get_due_date( $context );
459
+     * Alias for self::get_due_date().
460
+     *
461
+     * @since 1.0.19
462
+     * @param  string $context View or edit context.
463
+     * @return string
464
+     */
465
+    public function get_date_due( $context = 'view' ) {
466
+        return $this->get_due_date( $context );
467 467
     }
468 468
 
469 469
     /**
470
-	 * Get the invoice GMT due date.
471
-	 *
472
-	 * @since 1.0.19
473
-	 * @param  string $context View or edit context.
474
-	 * @return string
475
-	 */
476
-	public function get_due_date_gmt( $context = 'view' ) {
470
+     * Get the invoice GMT due date.
471
+     *
472
+     * @since 1.0.19
473
+     * @param  string $context View or edit context.
474
+     * @return string
475
+     */
476
+    public function get_due_date_gmt( $context = 'view' ) {
477 477
         $date = $this->get_due_date( $context );
478 478
 
479 479
         if ( $date ) {
480 480
             $date = get_gmt_from_date( $date );
481 481
         }
482
-		return $date;
482
+        return $date;
483 483
     }
484 484
 
485 485
     /**
486
-	 * Alias for self::get_due_date_gmt().
487
-	 *
488
-	 * @since 1.0.19
489
-	 * @param  string $context View or edit context.
490
-	 * @return string
491
-	 */
492
-	public function get_gmt_date_due( $context = 'view' ) {
493
-		return $this->get_due_date_gmt( $context );
486
+     * Alias for self::get_due_date_gmt().
487
+     *
488
+     * @since 1.0.19
489
+     * @param  string $context View or edit context.
490
+     * @return string
491
+     */
492
+    public function get_gmt_date_due( $context = 'view' ) {
493
+        return $this->get_due_date_gmt( $context );
494 494
     }
495 495
 
496 496
     /**
497
-	 * Get date when the invoice was completed.
498
-	 *
499
-	 * @since 1.0.19
500
-	 * @param  string $context View or edit context.
501
-	 * @return string
502
-	 */
503
-	public function get_completed_date( $context = 'view' ) {
504
-		return $this->get_prop( 'completed_date', $context );
497
+     * Get date when the invoice was completed.
498
+     *
499
+     * @since 1.0.19
500
+     * @param  string $context View or edit context.
501
+     * @return string
502
+     */
503
+    public function get_completed_date( $context = 'view' ) {
504
+        return $this->get_prop( 'completed_date', $context );
505 505
     }
506 506
 
507 507
     /**
508
-	 * Alias for self::get_completed_date().
509
-	 *
510
-	 * @since 1.0.19
511
-	 * @param  string $context View or edit context.
512
-	 * @return string
513
-	 */
514
-	public function get_date_completed( $context = 'view' ) {
515
-		return $this->get_completed_date( $context );
508
+     * Alias for self::get_completed_date().
509
+     *
510
+     * @since 1.0.19
511
+     * @param  string $context View or edit context.
512
+     * @return string
513
+     */
514
+    public function get_date_completed( $context = 'view' ) {
515
+        return $this->get_completed_date( $context );
516 516
     }
517 517
 
518 518
     /**
519
-	 * Get GMT date when the invoice was was completed.
520
-	 *
521
-	 * @since 1.0.19
522
-	 * @param  string $context View or edit context.
523
-	 * @return string
524
-	 */
525
-	public function get_completed_date_gmt( $context = 'view' ) {
519
+     * Get GMT date when the invoice was was completed.
520
+     *
521
+     * @since 1.0.19
522
+     * @param  string $context View or edit context.
523
+     * @return string
524
+     */
525
+    public function get_completed_date_gmt( $context = 'view' ) {
526 526
         $date = $this->get_completed_date( $context );
527 527
 
528 528
         if ( $date ) {
529 529
             $date = get_gmt_from_date( $date );
530 530
         }
531
-		return $date;
531
+        return $date;
532 532
     }
533 533
 
534 534
     /**
535
-	 * Alias for self::get_completed_date_gmt().
536
-	 *
537
-	 * @since 1.0.19
538
-	 * @param  string $context View or edit context.
539
-	 * @return string
540
-	 */
541
-	public function get_gmt_completed_date( $context = 'view' ) {
542
-		return $this->get_completed_date_gmt( $context );
535
+     * Alias for self::get_completed_date_gmt().
536
+     *
537
+     * @since 1.0.19
538
+     * @param  string $context View or edit context.
539
+     * @return string
540
+     */
541
+    public function get_gmt_completed_date( $context = 'view' ) {
542
+        return $this->get_completed_date_gmt( $context );
543 543
     }
544 544
 
545 545
     /**
546
-	 * Get the invoice number.
547
-	 *
548
-	 * @since 1.0.19
549
-	 * @param  string $context View or edit context.
550
-	 * @return string
551
-	 */
552
-	public function get_number( $context = 'view' ) {
553
-		$number = $this->get_prop( 'number', $context );
546
+     * Get the invoice number.
547
+     *
548
+     * @since 1.0.19
549
+     * @param  string $context View or edit context.
550
+     * @return string
551
+     */
552
+    public function get_number( $context = 'view' ) {
553
+        $number = $this->get_prop( 'number', $context );
554 554
 
555
-		if ( empty( $number ) ) {
556
-			$number = $this->generate_number();
557
-			$this->set_number( $this->generate_number() );
558
-		}
555
+        if ( empty( $number ) ) {
556
+            $number = $this->generate_number();
557
+            $this->set_number( $this->generate_number() );
558
+        }
559 559
 
560
-		return $number;
560
+        return $number;
561 561
     }
562 562
 
563
-	/**
564
-	 * Set the invoice number.
565
-	 *
566
-	 * @since 1.0.19
567
-	 */
568
-	public function maybe_set_number() {
563
+    /**
564
+     * Set the invoice number.
565
+     *
566
+     * @since 1.0.19
567
+     */
568
+    public function maybe_set_number() {
569 569
         $number = $this->get_number();
570 570
 
571 571
         if ( empty( $number ) || $this->get_id() == $number ) {
572
-			$this->set_number( $this->generate_number() );
572
+            $this->set_number( $this->generate_number() );
573 573
         }
574 574
 
575
-	}
575
+    }
576 576
 
577 577
     /**
578
-	 * Get the invoice key.
579
-	 *
580
-	 * @since 1.0.19
581
-	 * @param  string $context View or edit context.
582
-	 * @return string
583
-	 */
584
-	public function get_key( $context = 'view' ) {
578
+     * Get the invoice key.
579
+     *
580
+     * @since 1.0.19
581
+     * @param  string $context View or edit context.
582
+     * @return string
583
+     */
584
+    public function get_key( $context = 'view' ) {
585 585
         return $this->get_prop( 'key', $context );
586
-	}
587
-
588
-	/**
589
-	 * Set the invoice key.
590
-	 *
591
-	 * @since 1.0.19
592
-	 */
593
-	public function maybe_set_key() {
586
+    }
587
+
588
+    /**
589
+     * Set the invoice key.
590
+     *
591
+     * @since 1.0.19
592
+     */
593
+    public function maybe_set_key() {
594 594
         $key = $this->get_key();
595 595
 
596 596
         if ( empty( $key ) ) {
@@ -601,140 +601,140 @@  discard block
 block discarded – undo
601 601
     }
602 602
 
603 603
     /**
604
-	 * Get the invoice type.
605
-	 *
606
-	 * @since 1.0.19
607
-	 * @param  string $context View or edit context.
608
-	 * @return string
609
-	 */
610
-	public function get_type( $context = 'view' ) {
604
+     * Get the invoice type.
605
+     *
606
+     * @since 1.0.19
607
+     * @param  string $context View or edit context.
608
+     * @return string
609
+     */
610
+    public function get_type( $context = 'view' ) {
611 611
         return $this->get_prop( 'type', $context );
612
-	}
613
-
614
-	/**
615
-	 * Returns the post type name.
616
-	 *
617
-	 * @since 1.0.19
618
-	 * @return string
619
-	 */
620
-	public function get_invoice_quote_type() {
612
+    }
613
+
614
+    /**
615
+     * Returns the post type name.
616
+     *
617
+     * @since 1.0.19
618
+     * @return string
619
+     */
620
+    public function get_invoice_quote_type() {
621 621
         return getpaid_get_post_type_label( $this->get_post_type(), false );
622 622
     }
623 623
 
624 624
     /**
625
-	 * Get the invoice post type label.
626
-	 *
627
-	 * @since 1.0.19
628
-	 * @param  string $context View or edit context.
629
-	 * @return string
630
-	 */
631
-	public function get_label( $context = 'view' ) {
625
+     * Get the invoice post type label.
626
+     *
627
+     * @since 1.0.19
628
+     * @param  string $context View or edit context.
629
+     * @return string
630
+     */
631
+    public function get_label( $context = 'view' ) {
632 632
         return getpaid_get_post_type_label( $this->get_post_type( $context ), false );
633
-	}
634
-
635
-	/**
636
-	 * Get the invoice post type.
637
-	 *
638
-	 * @since 1.0.19
639
-	 * @param  string $context View or edit context.
640
-	 * @return string
641
-	 */
642
-	public function get_post_type( $context = 'view' ) {
633
+    }
634
+
635
+    /**
636
+     * Get the invoice post type.
637
+     *
638
+     * @since 1.0.19
639
+     * @param  string $context View or edit context.
640
+     * @return string
641
+     */
642
+    public function get_post_type( $context = 'view' ) {
643 643
         return $this->get_prop( 'post_type', $context );
644 644
     }
645 645
 
646 646
     /**
647
-	 * Get the invoice mode.
648
-	 *
649
-	 * @since 1.0.19
650
-	 * @param  string $context View or edit context.
651
-	 * @return string
652
-	 */
653
-	public function get_mode( $context = 'view' ) {
647
+     * Get the invoice mode.
648
+     *
649
+     * @since 1.0.19
650
+     * @param  string $context View or edit context.
651
+     * @return string
652
+     */
653
+    public function get_mode( $context = 'view' ) {
654 654
         return $this->get_prop( 'mode', $context );
655 655
     }
656 656
 
657 657
     /**
658
-	 * Get the invoice path.
659
-	 *
660
-	 * @since 1.0.19
661
-	 * @param  string $context View or edit context.
662
-	 * @return string
663
-	 */
664
-	public function get_path( $context = 'view' ) {
658
+     * Get the invoice path.
659
+     *
660
+     * @since 1.0.19
661
+     * @param  string $context View or edit context.
662
+     * @return string
663
+     */
664
+    public function get_path( $context = 'view' ) {
665 665
         $path   = $this->get_prop( 'path', $context );
666
-		$prefix = $this->get_type();
666
+        $prefix = $this->get_type();
667 667
 
668
-		if ( 0 !== strpos( $path, $prefix ) ) {
669
-			$path = sanitize_title(  $prefix . '-' . $this->get_id()  );
670
-			$this->set_path( $path );
671
-		}
668
+        if ( 0 !== strpos( $path, $prefix ) ) {
669
+            $path = sanitize_title(  $prefix . '-' . $this->get_id()  );
670
+            $this->set_path( $path );
671
+        }
672 672
 
673
-		return $path;
673
+        return $path;
674 674
     }
675 675
 
676 676
     /**
677
-	 * Get the invoice name/title.
678
-	 *
679
-	 * @since 1.0.19
680
-	 * @param  string $context View or edit context.
681
-	 * @return string
682
-	 */
683
-	public function get_name( $context = 'view' ) {
677
+     * Get the invoice name/title.
678
+     *
679
+     * @since 1.0.19
680
+     * @param  string $context View or edit context.
681
+     * @return string
682
+     */
683
+    public function get_name( $context = 'view' ) {
684 684
         return $this->get_prop( 'title', $context );
685 685
     }
686 686
 
687 687
     /**
688
-	 * Alias of self::get_name().
689
-	 *
690
-	 * @since 1.0.19
691
-	 * @param  string $context View or edit context.
692
-	 * @return string
693
-	 */
694
-	public function get_title( $context = 'view' ) {
695
-		return $this->get_name( $context );
688
+     * Alias of self::get_name().
689
+     *
690
+     * @since 1.0.19
691
+     * @param  string $context View or edit context.
692
+     * @return string
693
+     */
694
+    public function get_title( $context = 'view' ) {
695
+        return $this->get_name( $context );
696 696
     }
697 697
 
698 698
     /**
699
-	 * Get the invoice description.
700
-	 *
701
-	 * @since 1.0.19
702
-	 * @param  string $context View or edit context.
703
-	 * @return string
704
-	 */
705
-	public function get_description( $context = 'view' ) {
706
-		return $this->get_prop( 'description', $context );
699
+     * Get the invoice description.
700
+     *
701
+     * @since 1.0.19
702
+     * @param  string $context View or edit context.
703
+     * @return string
704
+     */
705
+    public function get_description( $context = 'view' ) {
706
+        return $this->get_prop( 'description', $context );
707 707
     }
708 708
 
709 709
     /**
710
-	 * Alias of self::get_description().
711
-	 *
712
-	 * @since 1.0.19
713
-	 * @param  string $context View or edit context.
714
-	 * @return string
715
-	 */
716
-	public function get_excerpt( $context = 'view' ) {
717
-		return $this->get_description( $context );
710
+     * Alias of self::get_description().
711
+     *
712
+     * @since 1.0.19
713
+     * @param  string $context View or edit context.
714
+     * @return string
715
+     */
716
+    public function get_excerpt( $context = 'view' ) {
717
+        return $this->get_description( $context );
718 718
     }
719 719
 
720 720
     /**
721
-	 * Alias of self::get_description().
722
-	 *
723
-	 * @since 1.0.19
724
-	 * @param  string $context View or edit context.
725
-	 * @return string
726
-	 */
727
-	public function get_summary( $context = 'view' ) {
728
-		return $this->get_description( $context );
721
+     * Alias of self::get_description().
722
+     *
723
+     * @since 1.0.19
724
+     * @param  string $context View or edit context.
725
+     * @return string
726
+     */
727
+    public function get_summary( $context = 'view' ) {
728
+        return $this->get_description( $context );
729 729
     }
730 730
 
731 731
     /**
732
-	 * Returns the user info.
733
-	 *
734
-	 * @since 1.0.19
732
+     * Returns the user info.
733
+     *
734
+     * @since 1.0.19
735 735
      * @param  string $context View or edit context.
736
-	 * @return array
737
-	 */
736
+     * @return array
737
+     */
738 738
     public function get_user_info( $context = 'view' ) {
739 739
 
740 740
         $user_info = array(
@@ -751,616 +751,616 @@  discard block
 block discarded – undo
751 751
             'company'    => $this->get_company( $context ),
752 752
             'vat_number' => $this->get_vat_number( $context ),
753 753
             'discount'   => $this->get_discount_code( $context ),
754
-		);
754
+        );
755 755
 
756
-		return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this );
756
+        return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this );
757 757
 
758 758
     }
759 759
 
760 760
     /**
761
-	 * Get the customer id.
762
-	 *
763
-	 * @since 1.0.19
764
-	 * @param  string $context View or edit context.
765
-	 * @return int
766
-	 */
767
-	public function get_author( $context = 'view' ) {
768
-		return (int) $this->get_prop( 'author', $context );
761
+     * Get the customer id.
762
+     *
763
+     * @since 1.0.19
764
+     * @param  string $context View or edit context.
765
+     * @return int
766
+     */
767
+    public function get_author( $context = 'view' ) {
768
+        return (int) $this->get_prop( 'author', $context );
769 769
     }
770 770
 
771 771
     /**
772
-	 * Alias of self::get_author().
773
-	 *
774
-	 * @since 1.0.19
775
-	 * @param  string $context View or edit context.
776
-	 * @return int
777
-	 */
778
-	public function get_user_id( $context = 'view' ) {
779
-		return $this->get_author( $context );
772
+     * Alias of self::get_author().
773
+     *
774
+     * @since 1.0.19
775
+     * @param  string $context View or edit context.
776
+     * @return int
777
+     */
778
+    public function get_user_id( $context = 'view' ) {
779
+        return $this->get_author( $context );
780 780
     }
781 781
 
782
-     /**
783
-	 * Alias of self::get_author().
784
-	 *
785
-	 * @since 1.0.19
786
-	 * @param  string $context View or edit context.
787
-	 * @return int
788
-	 */
789
-	public function get_customer_id( $context = 'view' ) {
790
-		return $this->get_author( $context );
782
+        /**
783
+         * Alias of self::get_author().
784
+         *
785
+         * @since 1.0.19
786
+         * @param  string $context View or edit context.
787
+         * @return int
788
+         */
789
+    public function get_customer_id( $context = 'view' ) {
790
+        return $this->get_author( $context );
791 791
     }
792 792
 
793 793
     /**
794
-	 * Get the customer's ip.
795
-	 *
796
-	 * @since 1.0.19
797
-	 * @param  string $context View or edit context.
798
-	 * @return string
799
-	 */
800
-	public function get_ip( $context = 'view' ) {
801
-		return $this->get_prop( 'user_ip', $context );
794
+     * Get the customer's ip.
795
+     *
796
+     * @since 1.0.19
797
+     * @param  string $context View or edit context.
798
+     * @return string
799
+     */
800
+    public function get_ip( $context = 'view' ) {
801
+        return $this->get_prop( 'user_ip', $context );
802 802
     }
803 803
 
804 804
     /**
805
-	 * Alias of self::get_ip().
806
-	 *
807
-	 * @since 1.0.19
808
-	 * @param  string $context View or edit context.
809
-	 * @return string
810
-	 */
811
-	public function get_user_ip( $context = 'view' ) {
812
-		return $this->get_ip( $context );
805
+     * Alias of self::get_ip().
806
+     *
807
+     * @since 1.0.19
808
+     * @param  string $context View or edit context.
809
+     * @return string
810
+     */
811
+    public function get_user_ip( $context = 'view' ) {
812
+        return $this->get_ip( $context );
813 813
     }
814 814
 
815
-     /**
816
-	 * Alias of self::get_ip().
817
-	 *
818
-	 * @since 1.0.19
819
-	 * @param  string $context View or edit context.
820
-	 * @return string
821
-	 */
822
-	public function get_customer_ip( $context = 'view' ) {
823
-		return $this->get_ip( $context );
815
+        /**
816
+         * Alias of self::get_ip().
817
+         *
818
+         * @since 1.0.19
819
+         * @param  string $context View or edit context.
820
+         * @return string
821
+         */
822
+    public function get_customer_ip( $context = 'view' ) {
823
+        return $this->get_ip( $context );
824 824
     }
825 825
 
826 826
     /**
827
-	 * Get the customer's first name.
828
-	 *
829
-	 * @since 1.0.19
830
-	 * @param  string $context View or edit context.
831
-	 * @return string
832
-	 */
833
-	public function get_first_name( $context = 'view' ) {
834
-		return $this->get_prop( 'first_name', $context );
827
+     * Get the customer's first name.
828
+     *
829
+     * @since 1.0.19
830
+     * @param  string $context View or edit context.
831
+     * @return string
832
+     */
833
+    public function get_first_name( $context = 'view' ) {
834
+        return $this->get_prop( 'first_name', $context );
835 835
     }
836 836
 
837 837
     /**
838
-	 * Alias of self::get_first_name().
839
-	 *
840
-	 * @since 1.0.19
841
-	 * @param  string $context View or edit context.
842
-	 * @return string
843
-	 */
844
-	public function get_user_first_name( $context = 'view' ) {
845
-		return $this->get_first_name( $context );
838
+     * Alias of self::get_first_name().
839
+     *
840
+     * @since 1.0.19
841
+     * @param  string $context View or edit context.
842
+     * @return string
843
+     */
844
+    public function get_user_first_name( $context = 'view' ) {
845
+        return $this->get_first_name( $context );
846 846
     }
847 847
 
848
-     /**
849
-	 * Alias of self::get_first_name().
850
-	 *
851
-	 * @since 1.0.19
852
-	 * @param  string $context View or edit context.
853
-	 * @return string
854
-	 */
855
-	public function get_customer_first_name( $context = 'view' ) {
856
-		return $this->get_first_name( $context );
848
+        /**
849
+         * Alias of self::get_first_name().
850
+         *
851
+         * @since 1.0.19
852
+         * @param  string $context View or edit context.
853
+         * @return string
854
+         */
855
+    public function get_customer_first_name( $context = 'view' ) {
856
+        return $this->get_first_name( $context );
857 857
     }
858 858
 
859 859
     /**
860
-	 * Get the customer's last name.
861
-	 *
862
-	 * @since 1.0.19
863
-	 * @param  string $context View or edit context.
864
-	 * @return string
865
-	 */
866
-	public function get_last_name( $context = 'view' ) {
867
-		return $this->get_prop( 'last_name', $context );
860
+     * Get the customer's last name.
861
+     *
862
+     * @since 1.0.19
863
+     * @param  string $context View or edit context.
864
+     * @return string
865
+     */
866
+    public function get_last_name( $context = 'view' ) {
867
+        return $this->get_prop( 'last_name', $context );
868 868
     }
869 869
 
870 870
     /**
871
-	 * Alias of self::get_last_name().
872
-	 *
873
-	 * @since 1.0.19
874
-	 * @param  string $context View or edit context.
875
-	 * @return string
876
-	 */
877
-	public function get_user_last_name( $context = 'view' ) {
878
-		return $this->get_last_name( $context );
871
+     * Alias of self::get_last_name().
872
+     *
873
+     * @since 1.0.19
874
+     * @param  string $context View or edit context.
875
+     * @return string
876
+     */
877
+    public function get_user_last_name( $context = 'view' ) {
878
+        return $this->get_last_name( $context );
879 879
     }
880 880
 
881 881
     /**
882
-	 * Alias of self::get_last_name().
883
-	 *
884
-	 * @since 1.0.19
885
-	 * @param  string $context View or edit context.
886
-	 * @return string
887
-	 */
888
-	public function get_customer_last_name( $context = 'view' ) {
889
-		return $this->get_last_name( $context );
882
+     * Alias of self::get_last_name().
883
+     *
884
+     * @since 1.0.19
885
+     * @param  string $context View or edit context.
886
+     * @return string
887
+     */
888
+    public function get_customer_last_name( $context = 'view' ) {
889
+        return $this->get_last_name( $context );
890 890
     }
891 891
 
892 892
     /**
893
-	 * Get the customer's full name.
894
-	 *
895
-	 * @since 1.0.19
896
-	 * @param  string $context View or edit context.
897
-	 * @return string
898
-	 */
899
-	public function get_full_name( $context = 'view' ) {
900
-		return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
893
+     * Get the customer's full name.
894
+     *
895
+     * @since 1.0.19
896
+     * @param  string $context View or edit context.
897
+     * @return string
898
+     */
899
+    public function get_full_name( $context = 'view' ) {
900
+        return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
901 901
     }
902 902
 
903 903
     /**
904
-	 * Alias of self::get_full_name().
905
-	 *
906
-	 * @since 1.0.19
907
-	 * @param  string $context View or edit context.
908
-	 * @return string
909
-	 */
910
-	public function get_user_full_name( $context = 'view' ) {
911
-		return $this->get_full_name( $context );
904
+     * Alias of self::get_full_name().
905
+     *
906
+     * @since 1.0.19
907
+     * @param  string $context View or edit context.
908
+     * @return string
909
+     */
910
+    public function get_user_full_name( $context = 'view' ) {
911
+        return $this->get_full_name( $context );
912 912
     }
913 913
 
914 914
     /**
915
-	 * Alias of self::get_full_name().
916
-	 *
917
-	 * @since 1.0.19
918
-	 * @param  string $context View or edit context.
919
-	 * @return string
920
-	 */
921
-	public function get_customer_full_name( $context = 'view' ) {
922
-		return $this->get_full_name( $context );
915
+     * Alias of self::get_full_name().
916
+     *
917
+     * @since 1.0.19
918
+     * @param  string $context View or edit context.
919
+     * @return string
920
+     */
921
+    public function get_customer_full_name( $context = 'view' ) {
922
+        return $this->get_full_name( $context );
923 923
     }
924 924
 
925 925
     /**
926
-	 * Get the customer's phone number.
927
-	 *
928
-	 * @since 1.0.19
929
-	 * @param  string $context View or edit context.
930
-	 * @return string
931
-	 */
932
-	public function get_phone( $context = 'view' ) {
933
-		return $this->get_prop( 'phone', $context );
926
+     * Get the customer's phone number.
927
+     *
928
+     * @since 1.0.19
929
+     * @param  string $context View or edit context.
930
+     * @return string
931
+     */
932
+    public function get_phone( $context = 'view' ) {
933
+        return $this->get_prop( 'phone', $context );
934 934
     }
935 935
 
936 936
     /**
937
-	 * Alias of self::get_phone().
938
-	 *
939
-	 * @since 1.0.19
940
-	 * @param  string $context View or edit context.
941
-	 * @return string
942
-	 */
943
-	public function get_phone_number( $context = 'view' ) {
944
-		return $this->get_phone( $context );
937
+     * Alias of self::get_phone().
938
+     *
939
+     * @since 1.0.19
940
+     * @param  string $context View or edit context.
941
+     * @return string
942
+     */
943
+    public function get_phone_number( $context = 'view' ) {
944
+        return $this->get_phone( $context );
945 945
     }
946 946
 
947 947
     /**
948
-	 * Alias of self::get_phone().
949
-	 *
950
-	 * @since 1.0.19
951
-	 * @param  string $context View or edit context.
952
-	 * @return string
953
-	 */
954
-	public function get_user_phone( $context = 'view' ) {
955
-		return $this->get_phone( $context );
956
-    }
957
-
948
+     * Alias of self::get_phone().
949
+     *
950
+     * @since 1.0.19
951
+     * @param  string $context View or edit context.
952
+     * @return string
953
+     */
954
+    public function get_user_phone( $context = 'view' ) {
955
+        return $this->get_phone( $context );
956
+    }
957
+
958
+    /**
959
+     * Alias of self::get_phone().
960
+     *
961
+     * @since 1.0.19
962
+     * @param  string $context View or edit context.
963
+     * @return string
964
+     */
965
+    public function get_customer_phone( $context = 'view' ) {
966
+        return $this->get_phone( $context );
967
+    }
968
+
969
+    /**
970
+     * Get the customer's email address.
971
+     *
972
+     * @since 1.0.19
973
+     * @param  string $context View or edit context.
974
+     * @return string
975
+     */
976
+    public function get_email( $context = 'view' ) {
977
+        return $this->get_prop( 'email', $context );
978
+    }
979
+
980
+    /**
981
+     * Alias of self::get_email().
982
+     *
983
+     * @since 1.0.19
984
+     * @param  string $context View or edit context.
985
+     * @return string
986
+     */
987
+    public function get_email_address( $context = 'view' ) {
988
+        return $this->get_email( $context );
989
+    }
990
+
991
+    /**
992
+     * Alias of self::get_email().
993
+     *
994
+     * @since 1.0.19
995
+     * @param  string $context View or edit context.
996
+     * @return string
997
+     */
998
+    public function get_user_email( $context = 'view' ) {
999
+        return $this->get_email( $context );
1000
+    }
1001
+
1002
+    /**
1003
+     * Alias of self::get_email().
1004
+     *
1005
+     * @since 1.0.19
1006
+     * @param  string $context View or edit context.
1007
+     * @return string
1008
+     */
1009
+    public function get_customer_email( $context = 'view' ) {
1010
+        return $this->get_email( $context );
1011
+    }
1012
+
1013
+    /**
1014
+     * Get the customer's country.
1015
+     *
1016
+     * @since 1.0.19
1017
+     * @param  string $context View or edit context.
1018
+     * @return string
1019
+     */
1020
+    public function get_country( $context = 'view' ) {
1021
+        $country = $this->get_prop( 'country', $context );
1022
+        return empty( $country ) ? wpinv_get_default_country() : $country;
1023
+    }
1024
+
1025
+    /**
1026
+     * Alias of self::get_country().
1027
+     *
1028
+     * @since 1.0.19
1029
+     * @param  string $context View or edit context.
1030
+     * @return string
1031
+     */
1032
+    public function get_user_country( $context = 'view' ) {
1033
+        return $this->get_country( $context );
1034
+    }
1035
+
1036
+    /**
1037
+     * Alias of self::get_country().
1038
+     *
1039
+     * @since 1.0.19
1040
+     * @param  string $context View or edit context.
1041
+     * @return string
1042
+     */
1043
+    public function get_customer_country( $context = 'view' ) {
1044
+        return $this->get_country( $context );
1045
+    }
1046
+
958 1047
     /**
959
-	 * Alias of self::get_phone().
960
-	 *
961
-	 * @since 1.0.19
962
-	 * @param  string $context View or edit context.
963
-	 * @return string
964
-	 */
965
-	public function get_customer_phone( $context = 'view' ) {
966
-		return $this->get_phone( $context );
1048
+     * Get the customer's state.
1049
+     *
1050
+     * @since 1.0.19
1051
+     * @param  string $context View or edit context.
1052
+     * @return string
1053
+     */
1054
+    public function get_state( $context = 'view' ) {
1055
+        $state = $this->get_prop( 'state', $context );
1056
+        return empty( $state ) ? wpinv_get_default_state() : $state;
1057
+    }
1058
+
1059
+    /**
1060
+     * Alias of self::get_state().
1061
+     *
1062
+     * @since 1.0.19
1063
+     * @param  string $context View or edit context.
1064
+     * @return string
1065
+     */
1066
+    public function get_user_state( $context = 'view' ) {
1067
+        return $this->get_state( $context );
1068
+    }
1069
+
1070
+    /**
1071
+     * Alias of self::get_state().
1072
+     *
1073
+     * @since 1.0.19
1074
+     * @param  string $context View or edit context.
1075
+     * @return string
1076
+     */
1077
+    public function get_customer_state( $context = 'view' ) {
1078
+        return $this->get_state( $context );
1079
+    }
1080
+
1081
+    /**
1082
+     * Get the customer's city.
1083
+     *
1084
+     * @since 1.0.19
1085
+     * @param  string $context View or edit context.
1086
+     * @return string
1087
+     */
1088
+    public function get_city( $context = 'view' ) {
1089
+        return $this->get_prop( 'city', $context );
1090
+    }
1091
+
1092
+    /**
1093
+     * Alias of self::get_city().
1094
+     *
1095
+     * @since 1.0.19
1096
+     * @param  string $context View or edit context.
1097
+     * @return string
1098
+     */
1099
+    public function get_user_city( $context = 'view' ) {
1100
+        return $this->get_city( $context );
967 1101
     }
968 1102
 
969 1103
     /**
970
-	 * Get the customer's email address.
971
-	 *
972
-	 * @since 1.0.19
973
-	 * @param  string $context View or edit context.
974
-	 * @return string
975
-	 */
976
-	public function get_email( $context = 'view' ) {
977
-		return $this->get_prop( 'email', $context );
1104
+     * Alias of self::get_city().
1105
+     *
1106
+     * @since 1.0.19
1107
+     * @param  string $context View or edit context.
1108
+     * @return string
1109
+     */
1110
+    public function get_customer_city( $context = 'view' ) {
1111
+        return $this->get_city( $context );
978 1112
     }
979 1113
 
980 1114
     /**
981
-	 * Alias of self::get_email().
982
-	 *
983
-	 * @since 1.0.19
984
-	 * @param  string $context View or edit context.
985
-	 * @return string
986
-	 */
987
-	public function get_email_address( $context = 'view' ) {
988
-		return $this->get_email( $context );
1115
+     * Get the customer's zip.
1116
+     *
1117
+     * @since 1.0.19
1118
+     * @param  string $context View or edit context.
1119
+     * @return string
1120
+     */
1121
+    public function get_zip( $context = 'view' ) {
1122
+        return $this->get_prop( 'zip', $context );
989 1123
     }
990 1124
 
991 1125
     /**
992
-	 * Alias of self::get_email().
993
-	 *
994
-	 * @since 1.0.19
995
-	 * @param  string $context View or edit context.
996
-	 * @return string
997
-	 */
998
-	public function get_user_email( $context = 'view' ) {
999
-		return $this->get_email( $context );
1126
+     * Alias of self::get_zip().
1127
+     *
1128
+     * @since 1.0.19
1129
+     * @param  string $context View or edit context.
1130
+     * @return string
1131
+     */
1132
+    public function get_user_zip( $context = 'view' ) {
1133
+        return $this->get_zip( $context );
1000 1134
     }
1001 1135
 
1002 1136
     /**
1003
-	 * Alias of self::get_email().
1004
-	 *
1005
-	 * @since 1.0.19
1006
-	 * @param  string $context View or edit context.
1007
-	 * @return string
1008
-	 */
1009
-	public function get_customer_email( $context = 'view' ) {
1010
-		return $this->get_email( $context );
1137
+     * Alias of self::get_zip().
1138
+     *
1139
+     * @since 1.0.19
1140
+     * @param  string $context View or edit context.
1141
+     * @return string
1142
+     */
1143
+    public function get_customer_zip( $context = 'view' ) {
1144
+        return $this->get_zip( $context );
1011 1145
     }
1012 1146
 
1013 1147
     /**
1014
-	 * Get the customer's country.
1015
-	 *
1016
-	 * @since 1.0.19
1017
-	 * @param  string $context View or edit context.
1018
-	 * @return string
1019
-	 */
1020
-	public function get_country( $context = 'view' ) {
1021
-		$country = $this->get_prop( 'country', $context );
1022
-		return empty( $country ) ? wpinv_get_default_country() : $country;
1148
+     * Get the customer's company.
1149
+     *
1150
+     * @since 1.0.19
1151
+     * @param  string $context View or edit context.
1152
+     * @return string
1153
+     */
1154
+    public function get_company( $context = 'view' ) {
1155
+        return $this->get_prop( 'company', $context );
1023 1156
     }
1024 1157
 
1025 1158
     /**
1026
-	 * Alias of self::get_country().
1027
-	 *
1028
-	 * @since 1.0.19
1029
-	 * @param  string $context View or edit context.
1030
-	 * @return string
1031
-	 */
1032
-	public function get_user_country( $context = 'view' ) {
1033
-		return $this->get_country( $context );
1159
+     * Alias of self::get_company().
1160
+     *
1161
+     * @since 1.0.19
1162
+     * @param  string $context View or edit context.
1163
+     * @return string
1164
+     */
1165
+    public function get_user_company( $context = 'view' ) {
1166
+        return $this->get_company( $context );
1167
+    }
1168
+
1169
+    /**
1170
+     * Alias of self::get_company().
1171
+     *
1172
+     * @since 1.0.19
1173
+     * @param  string $context View or edit context.
1174
+     * @return string
1175
+     */
1176
+    public function get_customer_company( $context = 'view' ) {
1177
+        return $this->get_company( $context );
1034 1178
     }
1035 1179
 
1036 1180
     /**
1037
-	 * Alias of self::get_country().
1038
-	 *
1039
-	 * @since 1.0.19
1040
-	 * @param  string $context View or edit context.
1041
-	 * @return string
1042
-	 */
1043
-	public function get_customer_country( $context = 'view' ) {
1044
-		return $this->get_country( $context );
1181
+     * Get the customer's vat number.
1182
+     *
1183
+     * @since 1.0.19
1184
+     * @param  string $context View or edit context.
1185
+     * @return string
1186
+     */
1187
+    public function get_vat_number( $context = 'view' ) {
1188
+        return $this->get_prop( 'vat_number', $context );
1045 1189
     }
1046 1190
 
1047 1191
     /**
1048
-	 * Get the customer's state.
1049
-	 *
1050
-	 * @since 1.0.19
1051
-	 * @param  string $context View or edit context.
1052
-	 * @return string
1053
-	 */
1054
-	public function get_state( $context = 'view' ) {
1055
-		$state = $this->get_prop( 'state', $context );
1056
-		return empty( $state ) ? wpinv_get_default_state() : $state;
1192
+     * Alias of self::get_vat_number().
1193
+     *
1194
+     * @since 1.0.19
1195
+     * @param  string $context View or edit context.
1196
+     * @return string
1197
+     */
1198
+    public function get_user_vat_number( $context = 'view' ) {
1199
+        return $this->get_vat_number( $context );
1057 1200
     }
1058 1201
 
1059 1202
     /**
1060
-	 * Alias of self::get_state().
1061
-	 *
1062
-	 * @since 1.0.19
1063
-	 * @param  string $context View or edit context.
1064
-	 * @return string
1065
-	 */
1066
-	public function get_user_state( $context = 'view' ) {
1067
-		return $this->get_state( $context );
1203
+     * Alias of self::get_vat_number().
1204
+     *
1205
+     * @since 1.0.19
1206
+     * @param  string $context View or edit context.
1207
+     * @return string
1208
+     */
1209
+    public function get_customer_vat_number( $context = 'view' ) {
1210
+        return $this->get_vat_number( $context );
1068 1211
     }
1069 1212
 
1070 1213
     /**
1071
-	 * Alias of self::get_state().
1072
-	 *
1073
-	 * @since 1.0.19
1074
-	 * @param  string $context View or edit context.
1075
-	 * @return string
1076
-	 */
1077
-	public function get_customer_state( $context = 'view' ) {
1078
-		return $this->get_state( $context );
1214
+     * Get the customer's vat rate.
1215
+     *
1216
+     * @since 1.0.19
1217
+     * @param  string $context View or edit context.
1218
+     * @return string
1219
+     */
1220
+    public function get_vat_rate( $context = 'view' ) {
1221
+        return $this->get_prop( 'vat_rate', $context );
1079 1222
     }
1080 1223
 
1081 1224
     /**
1082
-	 * Get the customer's city.
1083
-	 *
1084
-	 * @since 1.0.19
1085
-	 * @param  string $context View or edit context.
1086
-	 * @return string
1087
-	 */
1088
-	public function get_city( $context = 'view' ) {
1089
-		return $this->get_prop( 'city', $context );
1225
+     * Alias of self::get_vat_rate().
1226
+     *
1227
+     * @since 1.0.19
1228
+     * @param  string $context View or edit context.
1229
+     * @return string
1230
+     */
1231
+    public function get_user_vat_rate( $context = 'view' ) {
1232
+        return $this->get_vat_rate( $context );
1090 1233
     }
1091 1234
 
1092 1235
     /**
1093
-	 * Alias of self::get_city().
1094
-	 *
1095
-	 * @since 1.0.19
1096
-	 * @param  string $context View or edit context.
1097
-	 * @return string
1098
-	 */
1099
-	public function get_user_city( $context = 'view' ) {
1100
-		return $this->get_city( $context );
1236
+     * Alias of self::get_vat_rate().
1237
+     *
1238
+     * @since 1.0.19
1239
+     * @param  string $context View or edit context.
1240
+     * @return string
1241
+     */
1242
+    public function get_customer_vat_rate( $context = 'view' ) {
1243
+        return $this->get_vat_rate( $context );
1101 1244
     }
1102 1245
 
1103 1246
     /**
1104
-	 * Alias of self::get_city().
1105
-	 *
1106
-	 * @since 1.0.19
1107
-	 * @param  string $context View or edit context.
1108
-	 * @return string
1109
-	 */
1110
-	public function get_customer_city( $context = 'view' ) {
1111
-		return $this->get_city( $context );
1247
+     * Get the customer's address.
1248
+     *
1249
+     * @since 1.0.19
1250
+     * @param  string $context View or edit context.
1251
+     * @return string
1252
+     */
1253
+    public function get_address( $context = 'view' ) {
1254
+        return $this->get_prop( 'address', $context );
1112 1255
     }
1113 1256
 
1114 1257
     /**
1115
-	 * Get the customer's zip.
1116
-	 *
1117
-	 * @since 1.0.19
1118
-	 * @param  string $context View or edit context.
1119
-	 * @return string
1120
-	 */
1121
-	public function get_zip( $context = 'view' ) {
1122
-		return $this->get_prop( 'zip', $context );
1258
+     * Alias of self::get_address().
1259
+     *
1260
+     * @since 1.0.19
1261
+     * @param  string $context View or edit context.
1262
+     * @return string
1263
+     */
1264
+    public function get_user_address( $context = 'view' ) {
1265
+        return $this->get_address( $context );
1123 1266
     }
1124 1267
 
1125 1268
     /**
1126
-	 * Alias of self::get_zip().
1127
-	 *
1128
-	 * @since 1.0.19
1129
-	 * @param  string $context View or edit context.
1130
-	 * @return string
1131
-	 */
1132
-	public function get_user_zip( $context = 'view' ) {
1133
-		return $this->get_zip( $context );
1269
+     * Alias of self::get_address().
1270
+     *
1271
+     * @since 1.0.19
1272
+     * @param  string $context View or edit context.
1273
+     * @return string
1274
+     */
1275
+    public function get_customer_address( $context = 'view' ) {
1276
+        return $this->get_address( $context );
1134 1277
     }
1135 1278
 
1136 1279
     /**
1137
-	 * Alias of self::get_zip().
1138
-	 *
1139
-	 * @since 1.0.19
1140
-	 * @param  string $context View or edit context.
1141
-	 * @return string
1142
-	 */
1143
-	public function get_customer_zip( $context = 'view' ) {
1144
-		return $this->get_zip( $context );
1280
+     * Get whether the customer has viewed the invoice or not.
1281
+     *
1282
+     * @since 1.0.19
1283
+     * @param  string $context View or edit context.
1284
+     * @return bool
1285
+     */
1286
+    public function get_is_viewed( $context = 'view' ) {
1287
+        return (bool) $this->get_prop( 'is_viewed', $context );
1145 1288
     }
1146 1289
 
1147 1290
     /**
1148
-	 * Get the customer's company.
1149
-	 *
1150
-	 * @since 1.0.19
1151
-	 * @param  string $context View or edit context.
1152
-	 * @return string
1153
-	 */
1154
-	public function get_company( $context = 'view' ) {
1155
-		return $this->get_prop( 'company', $context );
1291
+     * Get other recipients for invoice communications.
1292
+     *
1293
+     * @since 1.0.19
1294
+     * @param  string $context View or edit context.
1295
+     * @return bool
1296
+     */
1297
+    public function get_email_cc( $context = 'view' ) {
1298
+        return $this->get_prop( 'email_cc', $context );
1156 1299
     }
1157 1300
 
1158 1301
     /**
1159
-	 * Alias of self::get_company().
1160
-	 *
1161
-	 * @since 1.0.19
1162
-	 * @param  string $context View or edit context.
1163
-	 * @return string
1164
-	 */
1165
-	public function get_user_company( $context = 'view' ) {
1166
-		return $this->get_company( $context );
1302
+     * Get invoice template.
1303
+     *
1304
+     * @since 1.0.19
1305
+     * @param  string $context View or edit context.
1306
+     * @return bool
1307
+     */
1308
+    public function get_template( $context = 'view' ) {
1309
+        return $this->get_prop( 'template', $context );
1167 1310
     }
1168 1311
 
1169 1312
     /**
1170
-	 * Alias of self::get_company().
1171
-	 *
1172
-	 * @since 1.0.19
1173
-	 * @param  string $context View or edit context.
1174
-	 * @return string
1175
-	 */
1176
-	public function get_customer_company( $context = 'view' ) {
1177
-		return $this->get_company( $context );
1313
+     * Get invoice source.
1314
+     *
1315
+     * @since 1.0.19
1316
+     * @param  string $context View or edit context.
1317
+     * @return bool
1318
+     */
1319
+    public function get_created_via( $context = 'view' ) {
1320
+        return $this->get_prop( 'created_via', $context );
1178 1321
     }
1179 1322
 
1180 1323
     /**
1181
-	 * Get the customer's vat number.
1182
-	 *
1183
-	 * @since 1.0.19
1184
-	 * @param  string $context View or edit context.
1185
-	 * @return string
1186
-	 */
1187
-	public function get_vat_number( $context = 'view' ) {
1188
-		return $this->get_prop( 'vat_number', $context );
1324
+     * Get whether the customer has confirmed their address.
1325
+     *
1326
+     * @since 1.0.19
1327
+     * @param  string $context View or edit context.
1328
+     * @return bool
1329
+     */
1330
+    public function get_address_confirmed( $context = 'view' ) {
1331
+        return (bool) $this->get_prop( 'address_confirmed', $context );
1189 1332
     }
1190 1333
 
1191 1334
     /**
1192
-	 * Alias of self::get_vat_number().
1193
-	 *
1194
-	 * @since 1.0.19
1195
-	 * @param  string $context View or edit context.
1196
-	 * @return string
1197
-	 */
1198
-	public function get_user_vat_number( $context = 'view' ) {
1199
-		return $this->get_vat_number( $context );
1335
+     * Alias of self::get_address_confirmed().
1336
+     *
1337
+     * @since 1.0.19
1338
+     * @param  string $context View or edit context.
1339
+     * @return bool
1340
+     */
1341
+    public function get_user_address_confirmed( $context = 'view' ) {
1342
+        return $this->get_address_confirmed( $context );
1200 1343
     }
1201 1344
 
1202 1345
     /**
1203
-	 * Alias of self::get_vat_number().
1204
-	 *
1205
-	 * @since 1.0.19
1206
-	 * @param  string $context View or edit context.
1207
-	 * @return string
1208
-	 */
1209
-	public function get_customer_vat_number( $context = 'view' ) {
1210
-		return $this->get_vat_number( $context );
1346
+     * Alias of self::get_address().
1347
+     *
1348
+     * @since 1.0.19
1349
+     * @param  string $context View or edit context.
1350
+     * @return bool
1351
+     */
1352
+    public function get_customer_address_confirmed( $context = 'view' ) {
1353
+        return $this->get_address_confirmed( $context );
1211 1354
     }
1212 1355
 
1213 1356
     /**
1214
-	 * Get the customer's vat rate.
1215
-	 *
1216
-	 * @since 1.0.19
1217
-	 * @param  string $context View or edit context.
1218
-	 * @return string
1219
-	 */
1220
-	public function get_vat_rate( $context = 'view' ) {
1221
-		return $this->get_prop( 'vat_rate', $context );
1222
-    }
1223
-
1224
-    /**
1225
-	 * Alias of self::get_vat_rate().
1226
-	 *
1227
-	 * @since 1.0.19
1228
-	 * @param  string $context View or edit context.
1229
-	 * @return string
1230
-	 */
1231
-	public function get_user_vat_rate( $context = 'view' ) {
1232
-		return $this->get_vat_rate( $context );
1233
-    }
1234
-
1235
-    /**
1236
-	 * Alias of self::get_vat_rate().
1237
-	 *
1238
-	 * @since 1.0.19
1239
-	 * @param  string $context View or edit context.
1240
-	 * @return string
1241
-	 */
1242
-	public function get_customer_vat_rate( $context = 'view' ) {
1243
-		return $this->get_vat_rate( $context );
1244
-    }
1245
-
1246
-    /**
1247
-	 * Get the customer's address.
1248
-	 *
1249
-	 * @since 1.0.19
1250
-	 * @param  string $context View or edit context.
1251
-	 * @return string
1252
-	 */
1253
-	public function get_address( $context = 'view' ) {
1254
-		return $this->get_prop( 'address', $context );
1255
-    }
1256
-
1257
-    /**
1258
-	 * Alias of self::get_address().
1259
-	 *
1260
-	 * @since 1.0.19
1261
-	 * @param  string $context View or edit context.
1262
-	 * @return string
1263
-	 */
1264
-	public function get_user_address( $context = 'view' ) {
1265
-		return $this->get_address( $context );
1266
-    }
1267
-
1268
-    /**
1269
-	 * Alias of self::get_address().
1270
-	 *
1271
-	 * @since 1.0.19
1272
-	 * @param  string $context View or edit context.
1273
-	 * @return string
1274
-	 */
1275
-	public function get_customer_address( $context = 'view' ) {
1276
-		return $this->get_address( $context );
1277
-    }
1278
-
1279
-    /**
1280
-	 * Get whether the customer has viewed the invoice or not.
1281
-	 *
1282
-	 * @since 1.0.19
1283
-	 * @param  string $context View or edit context.
1284
-	 * @return bool
1285
-	 */
1286
-	public function get_is_viewed( $context = 'view' ) {
1287
-		return (bool) $this->get_prop( 'is_viewed', $context );
1288
-	}
1289
-
1290
-	/**
1291
-	 * Get other recipients for invoice communications.
1292
-	 *
1293
-	 * @since 1.0.19
1294
-	 * @param  string $context View or edit context.
1295
-	 * @return bool
1296
-	 */
1297
-	public function get_email_cc( $context = 'view' ) {
1298
-		return $this->get_prop( 'email_cc', $context );
1299
-	}
1300
-
1301
-	/**
1302
-	 * Get invoice template.
1303
-	 *
1304
-	 * @since 1.0.19
1305
-	 * @param  string $context View or edit context.
1306
-	 * @return bool
1307
-	 */
1308
-	public function get_template( $context = 'view' ) {
1309
-		return $this->get_prop( 'template', $context );
1310
-	}
1311
-
1312
-	/**
1313
-	 * Get invoice source.
1314
-	 *
1315
-	 * @since 1.0.19
1316
-	 * @param  string $context View or edit context.
1317
-	 * @return bool
1318
-	 */
1319
-	public function get_created_via( $context = 'view' ) {
1320
-		return $this->get_prop( 'created_via', $context );
1321
-	}
1322
-
1323
-	/**
1324
-	 * Get whether the customer has confirmed their address.
1325
-	 *
1326
-	 * @since 1.0.19
1327
-	 * @param  string $context View or edit context.
1328
-	 * @return bool
1329
-	 */
1330
-	public function get_address_confirmed( $context = 'view' ) {
1331
-		return (bool) $this->get_prop( 'address_confirmed', $context );
1332
-    }
1333
-
1334
-    /**
1335
-	 * Alias of self::get_address_confirmed().
1336
-	 *
1337
-	 * @since 1.0.19
1338
-	 * @param  string $context View or edit context.
1339
-	 * @return bool
1340
-	 */
1341
-	public function get_user_address_confirmed( $context = 'view' ) {
1342
-		return $this->get_address_confirmed( $context );
1343
-    }
1344
-
1345
-    /**
1346
-	 * Alias of self::get_address().
1347
-	 *
1348
-	 * @since 1.0.19
1349
-	 * @param  string $context View or edit context.
1350
-	 * @return bool
1351
-	 */
1352
-	public function get_customer_address_confirmed( $context = 'view' ) {
1353
-		return $this->get_address_confirmed( $context );
1354
-    }
1355
-
1356
-    /**
1357
-	 * Get the invoice subtotal.
1358
-	 *
1359
-	 * @since 1.0.19
1360
-	 * @param  string $context View or edit context.
1361
-	 * @return float
1362
-	 */
1363
-	public function get_subtotal( $context = 'view' ) {
1357
+     * Get the invoice subtotal.
1358
+     *
1359
+     * @since 1.0.19
1360
+     * @param  string $context View or edit context.
1361
+     * @return float
1362
+     */
1363
+    public function get_subtotal( $context = 'view' ) {
1364 1364
         $subtotal = (float) $this->get_prop( 'subtotal', $context );
1365 1365
 
1366 1366
         // Backwards compatibility.
@@ -1372,166 +1372,166 @@  discard block
 block discarded – undo
1372 1372
     }
1373 1373
 
1374 1374
     /**
1375
-	 * Get the invoice discount total.
1376
-	 *
1377
-	 * @since 1.0.19
1378
-	 * @param  string $context View or edit context.
1379
-	 * @return float
1380
-	 */
1381
-	public function get_total_discount( $context = 'view' ) {
1382
-		return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) );
1375
+     * Get the invoice discount total.
1376
+     *
1377
+     * @since 1.0.19
1378
+     * @param  string $context View or edit context.
1379
+     * @return float
1380
+     */
1381
+    public function get_total_discount( $context = 'view' ) {
1382
+        return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) );
1383 1383
     }
1384 1384
 
1385 1385
     /**
1386
-	 * Get the invoice tax total.
1387
-	 *
1388
-	 * @since 1.0.19
1389
-	 * @param  string $context View or edit context.
1390
-	 * @return float
1391
-	 */
1392
-	public function get_total_tax( $context = 'view' ) {
1393
-		return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) );
1394
-	}
1386
+     * Get the invoice tax total.
1387
+     *
1388
+     * @since 1.0.19
1389
+     * @param  string $context View or edit context.
1390
+     * @return float
1391
+     */
1392
+    public function get_total_tax( $context = 'view' ) {
1393
+        return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) );
1394
+    }
1395 1395
 
1396
-	/**
1397
-	 * @deprecated
1398
-	 */
1399
-	public function get_final_tax( $currency = false ) {
1400
-		$tax = $this->get_total_tax();
1396
+    /**
1397
+     * @deprecated
1398
+     */
1399
+    public function get_final_tax( $currency = false ) {
1400
+        $tax = $this->get_total_tax();
1401 1401
 
1402 1402
         if ( $currency ) {
1403
-			return wpinv_price( $tax, $this->get_currency() );
1403
+            return wpinv_price( $tax, $this->get_currency() );
1404 1404
         }
1405 1405
 
1406 1406
         return $tax;
1407 1407
     }
1408 1408
 
1409 1409
     /**
1410
-	 * Get the invoice fees total.
1411
-	 *
1412
-	 * @since 1.0.19
1413
-	 * @param  string $context View or edit context.
1414
-	 * @return float
1415
-	 */
1416
-	public function get_total_fees( $context = 'view' ) {
1417
-		return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) );
1410
+     * Get the invoice fees total.
1411
+     *
1412
+     * @since 1.0.19
1413
+     * @param  string $context View or edit context.
1414
+     * @return float
1415
+     */
1416
+    public function get_total_fees( $context = 'view' ) {
1417
+        return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) );
1418 1418
     }
1419 1419
 
1420 1420
     /**
1421
-	 * Alias for self::get_total_fees().
1422
-	 *
1423
-	 * @since 1.0.19
1424
-	 * @param  string $context View or edit context.
1425
-	 * @return float
1426
-	 */
1427
-	public function get_fees_total( $context = 'view' ) {
1428
-		return $this->get_total_fees( $context );
1421
+     * Alias for self::get_total_fees().
1422
+     *
1423
+     * @since 1.0.19
1424
+     * @param  string $context View or edit context.
1425
+     * @return float
1426
+     */
1427
+    public function get_fees_total( $context = 'view' ) {
1428
+        return $this->get_total_fees( $context );
1429 1429
     }
1430 1430
 
1431 1431
     /**
1432
-	 * Get the invoice total.
1433
-	 *
1434
-	 * @since 1.0.19
1432
+     * Get the invoice total.
1433
+     *
1434
+     * @since 1.0.19
1435 1435
      * @return float
1436
-	 */
1437
-	public function get_total( $context = 'view' ) {
1438
-		return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total', $context ) ) );
1439
-	}
1440
-
1441
-	/**
1442
-	 * Get the invoice totals.
1443
-	 *
1444
-	 * @since 1.0.19
1436
+     */
1437
+    public function get_total( $context = 'view' ) {
1438
+        return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total', $context ) ) );
1439
+    }
1440
+
1441
+    /**
1442
+     * Get the invoice totals.
1443
+     *
1444
+     * @since 1.0.19
1445 1445
      * @return array
1446
-	 */
1447
-	public function get_totals() {
1448
-		return $this->totals;
1446
+     */
1447
+    public function get_totals() {
1448
+        return $this->totals;
1449 1449
     }
1450 1450
 
1451 1451
     /**
1452
-	 * Get the initial invoice total.
1453
-	 *
1454
-	 * @since 1.0.19
1452
+     * Get the initial invoice total.
1453
+     *
1454
+     * @since 1.0.19
1455 1455
      * @param  string $context View or edit context.
1456 1456
      * @return float
1457
-	 */
1457
+     */
1458 1458
     public function get_initial_total() {
1459 1459
 
1460
-		if ( empty( $this->totals ) ) {
1461
-			$this->recalculate_total();
1462
-		}
1460
+        if ( empty( $this->totals ) ) {
1461
+            $this->recalculate_total();
1462
+        }
1463 1463
 
1464
-		$tax      = $this->totals['tax']['initial'];
1465
-		$fee      = $this->totals['fee']['initial'];
1466
-		$discount = $this->totals['discount']['initial'];
1467
-		$subtotal = $this->totals['subtotal']['initial'];
1468
-		$total    = $tax + $fee - $discount + $subtotal;
1464
+        $tax      = $this->totals['tax']['initial'];
1465
+        $fee      = $this->totals['fee']['initial'];
1466
+        $discount = $this->totals['discount']['initial'];
1467
+        $subtotal = $this->totals['subtotal']['initial'];
1468
+        $total    = $tax + $fee - $discount + $subtotal;
1469 1469
 
1470
-		if ( 0 > $total ) {
1471
-			$total = 0;
1472
-		}
1470
+        if ( 0 > $total ) {
1471
+            $total = 0;
1472
+        }
1473 1473
 
1474
-		$total = wpinv_round_amount( wpinv_sanitize_amount( $total ) );
1474
+        $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) );
1475 1475
         return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this );
1476
-	}
1476
+    }
1477 1477
 
1478
-	/**
1479
-	 * Get the recurring invoice total.
1480
-	 *
1481
-	 * @since 1.0.19
1478
+    /**
1479
+     * Get the recurring invoice total.
1480
+     *
1481
+     * @since 1.0.19
1482 1482
      * @param  string $context View or edit context.
1483 1483
      * @return float
1484
-	 */
1484
+     */
1485 1485
     public function get_recurring_total() {
1486 1486
 
1487
-		if ( empty( $this->totals ) ) {
1488
-			$this->recalculate_total();
1489
-		}
1487
+        if ( empty( $this->totals ) ) {
1488
+            $this->recalculate_total();
1489
+        }
1490 1490
 
1491
-		$tax      = $this->totals['tax']['recurring'];
1492
-		$fee      = $this->totals['fee']['recurring'];
1493
-		$discount = $this->totals['discount']['recurring'];
1494
-		$subtotal = $this->totals['subtotal']['recurring'];
1495
-		$total    = $tax + $fee - $discount + $subtotal;
1491
+        $tax      = $this->totals['tax']['recurring'];
1492
+        $fee      = $this->totals['fee']['recurring'];
1493
+        $discount = $this->totals['discount']['recurring'];
1494
+        $subtotal = $this->totals['subtotal']['recurring'];
1495
+        $total    = $tax + $fee - $discount + $subtotal;
1496 1496
 
1497
-		if ( 0 > $total ) {
1498
-			$total = 0;
1499
-		}
1497
+        if ( 0 > $total ) {
1498
+            $total = 0;
1499
+        }
1500 1500
 
1501
-		$total = wpinv_round_amount( wpinv_sanitize_amount( $total ) );
1501
+        $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) );
1502 1502
         return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this );
1503
-	}
1503
+    }
1504 1504
 
1505
-	/**
1506
-	 * Returns recurring payment details.
1507
-	 *
1508
-	 * @since 1.0.19
1505
+    /**
1506
+     * Returns recurring payment details.
1507
+     *
1508
+     * @since 1.0.19
1509 1509
      * @param  string $field Optionally provide a field to return.
1510
-	 * @param string $currency Whether to include the currency.
1510
+     * @param string $currency Whether to include the currency.
1511 1511
      * @return float|string
1512
-	 */
1512
+     */
1513 1513
     public function get_recurring_details( $field = '', $currency = false ) {
1514 1514
 
1515
-		// Maybe recalculate totals.
1516
-		if ( empty( $this->totals ) ) {
1517
-			$this->recalculate_total();
1518
-		}
1515
+        // Maybe recalculate totals.
1516
+        if ( empty( $this->totals ) ) {
1517
+            $this->recalculate_total();
1518
+        }
1519 1519
 
1520
-		// Prepare recurring totals.
1520
+        // Prepare recurring totals.
1521 1521
         $data = apply_filters(
1522
-			'wpinv_get_invoice_recurring_details',
1523
-			array(
1524
-				'cart_details' => $this->get_cart_details(),
1525
-				'subtotal'     => $this->totals['subtotal']['recurring'],
1526
-				'discount'     => $this->totals['discount']['recurring'],
1527
-				'tax'          => $this->totals['tax']['recurring'],
1528
-				'fee'          => $this->totals['fee']['recurring'],
1529
-				'total'        => $this->get_recurring_total(),
1530
-			),
1531
-			$this,
1532
-			$field,
1533
-			$currency
1534
-		);
1522
+            'wpinv_get_invoice_recurring_details',
1523
+            array(
1524
+                'cart_details' => $this->get_cart_details(),
1525
+                'subtotal'     => $this->totals['subtotal']['recurring'],
1526
+                'discount'     => $this->totals['discount']['recurring'],
1527
+                'tax'          => $this->totals['tax']['recurring'],
1528
+                'fee'          => $this->totals['fee']['recurring'],
1529
+                'total'        => $this->get_recurring_total(),
1530
+            ),
1531
+            $this,
1532
+            $field,
1533
+            $currency
1534
+        );
1535 1535
 
1536 1536
         if ( isset( $data[$field] ) ) {
1537 1537
             return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
@@ -1541,166 +1541,166 @@  discard block
 block discarded – undo
1541 1541
     }
1542 1542
 
1543 1543
     /**
1544
-	 * Get the invoice fees.
1545
-	 *
1546
-	 * @since 1.0.19
1547
-	 * @param  string $context View or edit context.
1548
-	 * @return array
1549
-	 */
1550
-	public function get_fees( $context = 'view' ) {
1551
-		return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1544
+     * Get the invoice fees.
1545
+     *
1546
+     * @since 1.0.19
1547
+     * @param  string $context View or edit context.
1548
+     * @return array
1549
+     */
1550
+    public function get_fees( $context = 'view' ) {
1551
+        return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1552 1552
     }
1553 1553
 
1554 1554
     /**
1555
-	 * Get the invoice discounts.
1556
-	 *
1557
-	 * @since 1.0.19
1558
-	 * @param  string $context View or edit context.
1559
-	 * @return array
1560
-	 */
1561
-	public function get_discounts( $context = 'view' ) {
1562
-		return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1555
+     * Get the invoice discounts.
1556
+     *
1557
+     * @since 1.0.19
1558
+     * @param  string $context View or edit context.
1559
+     * @return array
1560
+     */
1561
+    public function get_discounts( $context = 'view' ) {
1562
+        return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1563 1563
     }
1564 1564
 
1565 1565
     /**
1566
-	 * Get the invoice taxes.
1567
-	 *
1568
-	 * @since 1.0.19
1569
-	 * @param  string $context View or edit context.
1570
-	 * @return array
1571
-	 */
1572
-	public function get_taxes( $context = 'view' ) {
1573
-		return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1566
+     * Get the invoice taxes.
1567
+     *
1568
+     * @since 1.0.19
1569
+     * @param  string $context View or edit context.
1570
+     * @return array
1571
+     */
1572
+    public function get_taxes( $context = 'view' ) {
1573
+        return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1574 1574
     }
1575 1575
 
1576 1576
     /**
1577
-	 * Get the invoice items.
1578
-	 *
1579
-	 * @since 1.0.19
1580
-	 * @param  string $context View or edit context.
1581
-	 * @return GetPaid_Form_Item[]
1582
-	 */
1583
-	public function get_items( $context = 'view' ) {
1577
+     * Get the invoice items.
1578
+     *
1579
+     * @since 1.0.19
1580
+     * @param  string $context View or edit context.
1581
+     * @return GetPaid_Form_Item[]
1582
+     */
1583
+    public function get_items( $context = 'view' ) {
1584 1584
         return $this->get_prop( 'items', $context );
1585
-	}
1585
+    }
1586 1586
 
1587
-	/**
1588
-	 * Get the invoice item ids.
1589
-	 *
1590
-	 * @since 1.0.19
1591
-	 * @return string
1592
-	 */
1593
-	public function get_item_ids() {
1594
-		return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) );
1587
+    /**
1588
+     * Get the invoice item ids.
1589
+     *
1590
+     * @since 1.0.19
1591
+     * @return string
1592
+     */
1593
+    public function get_item_ids() {
1594
+        return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) );
1595 1595
     }
1596 1596
 
1597 1597
     /**
1598
-	 * Get the invoice's payment form.
1599
-	 *
1600
-	 * @since 1.0.19
1601
-	 * @param  string $context View or edit context.
1602
-	 * @return int
1603
-	 */
1604
-	public function get_payment_form( $context = 'view' ) {
1605
-		return intval( $this->get_prop( 'payment_form', $context ) );
1598
+     * Get the invoice's payment form.
1599
+     *
1600
+     * @since 1.0.19
1601
+     * @param  string $context View or edit context.
1602
+     * @return int
1603
+     */
1604
+    public function get_payment_form( $context = 'view' ) {
1605
+        return intval( $this->get_prop( 'payment_form', $context ) );
1606 1606
     }
1607 1607
 
1608 1608
     /**
1609
-	 * Get the invoice's submission id.
1610
-	 *
1611
-	 * @since 1.0.19
1612
-	 * @param  string $context View or edit context.
1613
-	 * @return string
1614
-	 */
1615
-	public function get_submission_id( $context = 'view' ) {
1616
-		return $this->get_prop( 'submission_id', $context );
1609
+     * Get the invoice's submission id.
1610
+     *
1611
+     * @since 1.0.19
1612
+     * @param  string $context View or edit context.
1613
+     * @return string
1614
+     */
1615
+    public function get_submission_id( $context = 'view' ) {
1616
+        return $this->get_prop( 'submission_id', $context );
1617 1617
     }
1618 1618
 
1619 1619
     /**
1620
-	 * Get the invoice's discount code.
1621
-	 *
1622
-	 * @since 1.0.19
1623
-	 * @param  string $context View or edit context.
1624
-	 * @return string
1625
-	 */
1626
-	public function get_discount_code( $context = 'view' ) {
1627
-		return $this->get_prop( 'discount_code', $context );
1620
+     * Get the invoice's discount code.
1621
+     *
1622
+     * @since 1.0.19
1623
+     * @param  string $context View or edit context.
1624
+     * @return string
1625
+     */
1626
+    public function get_discount_code( $context = 'view' ) {
1627
+        return $this->get_prop( 'discount_code', $context );
1628 1628
     }
1629 1629
 
1630 1630
     /**
1631
-	 * Get the invoice's gateway.
1632
-	 *
1633
-	 * @since 1.0.19
1634
-	 * @param  string $context View or edit context.
1635
-	 * @return string
1636
-	 */
1637
-	public function get_gateway( $context = 'view' ) {
1638
-		return $this->get_prop( 'gateway', $context );
1631
+     * Get the invoice's gateway.
1632
+     *
1633
+     * @since 1.0.19
1634
+     * @param  string $context View or edit context.
1635
+     * @return string
1636
+     */
1637
+    public function get_gateway( $context = 'view' ) {
1638
+        return $this->get_prop( 'gateway', $context );
1639 1639
     }
1640 1640
 
1641 1641
     /**
1642
-	 * Get the invoice's gateway display title.
1643
-	 *
1644
-	 * @since 1.0.19
1645
-	 * @return string
1646
-	 */
1642
+     * Get the invoice's gateway display title.
1643
+     *
1644
+     * @since 1.0.19
1645
+     * @return string
1646
+     */
1647 1647
     public function get_gateway_title() {
1648 1648
         $title =  wpinv_get_gateway_checkout_label( $this->get_gateway() );
1649 1649
         return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this );
1650 1650
     }
1651 1651
 
1652 1652
     /**
1653
-	 * Get the invoice's transaction id.
1654
-	 *
1655
-	 * @since 1.0.19
1656
-	 * @param  string $context View or edit context.
1657
-	 * @return string
1658
-	 */
1659
-	public function get_transaction_id( $context = 'view' ) {
1660
-		return $this->get_prop( 'transaction_id', $context );
1653
+     * Get the invoice's transaction id.
1654
+     *
1655
+     * @since 1.0.19
1656
+     * @param  string $context View or edit context.
1657
+     * @return string
1658
+     */
1659
+    public function get_transaction_id( $context = 'view' ) {
1660
+        return $this->get_prop( 'transaction_id', $context );
1661 1661
     }
1662 1662
 
1663 1663
     /**
1664
-	 * Get the invoice's currency.
1665
-	 *
1666
-	 * @since 1.0.19
1667
-	 * @param  string $context View or edit context.
1668
-	 * @return string
1669
-	 */
1670
-	public function get_currency( $context = 'view' ) {
1664
+     * Get the invoice's currency.
1665
+     *
1666
+     * @since 1.0.19
1667
+     * @param  string $context View or edit context.
1668
+     * @return string
1669
+     */
1670
+    public function get_currency( $context = 'view' ) {
1671 1671
         $currency = $this->get_prop( 'currency', $context );
1672 1672
         return empty( $currency ) ? wpinv_get_currency() : $currency;
1673 1673
     }
1674 1674
 
1675 1675
     /**
1676
-	 * Checks if we are charging taxes for this invoice.
1677
-	 *
1678
-	 * @since 1.0.19
1679
-	 * @param  string $context View or edit context.
1680
-	 * @return bool
1681
-	 */
1682
-	public function get_disable_taxes( $context = 'view' ) {
1676
+     * Checks if we are charging taxes for this invoice.
1677
+     *
1678
+     * @since 1.0.19
1679
+     * @param  string $context View or edit context.
1680
+     * @return bool
1681
+     */
1682
+    public function get_disable_taxes( $context = 'view' ) {
1683 1683
         return (bool) $this->get_prop( 'disable_taxes', $context );
1684 1684
     }
1685 1685
 
1686 1686
     /**
1687
-	 * Retrieves the subscription id for an invoice.
1688
-	 *
1689
-	 * @since 1.0.19
1690
-	 * @param  string $context View or edit context.
1691
-	 * @return int
1692
-	 */
1687
+     * Retrieves the subscription id for an invoice.
1688
+     *
1689
+     * @since 1.0.19
1690
+     * @param  string $context View or edit context.
1691
+     * @return int
1692
+     */
1693 1693
     public function get_subscription_id( $context = 'view' ) {
1694
-		return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context );
1695
-	}
1696
-
1697
-	/**
1698
-	 * Retrieves the remote subscription id for an invoice.
1699
-	 *
1700
-	 * @since 1.0.19
1701
-	 * @param  string $context View or edit context.
1702
-	 * @return int
1703
-	 */
1694
+        return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context );
1695
+    }
1696
+
1697
+    /**
1698
+     * Retrieves the remote subscription id for an invoice.
1699
+     *
1700
+     * @since 1.0.19
1701
+     * @param  string $context View or edit context.
1702
+     * @return int
1703
+     */
1704 1704
     public function get_remote_subscription_id( $context = 'view' ) {
1705 1705
         $subscription_id = $this->get_prop( 'remote_subscription_id', $context );
1706 1706
 
@@ -1713,12 +1713,12 @@  discard block
 block discarded – undo
1713 1713
     }
1714 1714
 
1715 1715
     /**
1716
-	 * Retrieves the payment meta for an invoice.
1717
-	 *
1718
-	 * @since 1.0.19
1719
-	 * @param  string $context View or edit context.
1720
-	 * @return array
1721
-	 */
1716
+     * Retrieves the payment meta for an invoice.
1717
+     *
1718
+     * @since 1.0.19
1719
+     * @param  string $context View or edit context.
1720
+     * @return array
1721
+     */
1722 1722
     public function get_payment_meta( $context = 'view' ) {
1723 1723
 
1724 1724
         return array(
@@ -1738,31 +1738,31 @@  discard block
 block discarded – undo
1738 1738
     }
1739 1739
 
1740 1740
     /**
1741
-	 * Retrieves the cart details for an invoice.
1742
-	 *
1743
-	 * @since 1.0.19
1744
-	 * @return array
1745
-	 */
1741
+     * Retrieves the cart details for an invoice.
1742
+     *
1743
+     * @since 1.0.19
1744
+     * @return array
1745
+     */
1746 1746
     public function get_cart_details() {
1747 1747
         $items        = $this->get_items();
1748 1748
         $cart_details = array();
1749 1749
 
1750 1750
         foreach ( $items as $item ) {
1751
-			$item->invoice_id = $this->get_id();
1751
+            $item->invoice_id = $this->get_id();
1752 1752
             $cart_details[]   = $item->prepare_data_for_saving();
1753 1753
         }
1754 1754
 
1755 1755
         return $cart_details;
1756
-	}
1756
+    }
1757 1757
 
1758
-	/**
1759
-	 * Retrieves the recurring item.
1760
-	 *
1761
-	 * @return null|GetPaid_Form_Item|int
1762
-	 */
1763
-	public function get_recurring( $object = false ) {
1758
+    /**
1759
+     * Retrieves the recurring item.
1760
+     *
1761
+     * @return null|GetPaid_Form_Item|int
1762
+     */
1763
+    public function get_recurring( $object = false ) {
1764 1764
 
1765
-		// Are we returning an object?
1765
+        // Are we returning an object?
1766 1766
         if ( $object ) {
1767 1767
             return $this->get_item( $this->recurring_item );
1768 1768
         }
@@ -1770,114 +1770,114 @@  discard block
 block discarded – undo
1770 1770
         return $this->recurring_item;
1771 1771
     }
1772 1772
 
1773
-	/**
1774
-	 * Retrieves the subscription name.
1775
-	 *
1776
-	 * @since 1.0.19
1777
-	 * @return string
1778
-	 */
1779
-	public function get_subscription_name() {
1773
+    /**
1774
+     * Retrieves the subscription name.
1775
+     *
1776
+     * @since 1.0.19
1777
+     * @return string
1778
+     */
1779
+    public function get_subscription_name() {
1780 1780
 
1781
-		// Retrieve the recurring name
1781
+        // Retrieve the recurring name
1782 1782
         $item = $this->get_recurring( true );
1783 1783
 
1784
-		// Abort if it does not exist.
1784
+        // Abort if it does not exist.
1785 1785
         if ( empty( $item ) ) {
1786 1786
             return '';
1787 1787
         }
1788 1788
 
1789
-		// Return the item name.
1789
+        // Return the item name.
1790 1790
         return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this );
1791
-	}
1792
-
1793
-	/**
1794
-	 * Retrieves the view url.
1795
-	 *
1796
-	 * @since 1.0.19
1797
-	 * @return string
1798
-	 */
1799
-	public function get_view_url() {
1791
+    }
1792
+
1793
+    /**
1794
+     * Retrieves the view url.
1795
+     *
1796
+     * @since 1.0.19
1797
+     * @return string
1798
+     */
1799
+    public function get_view_url() {
1800 1800
         $invoice_url = get_permalink( $this->get_id() );
1801
-		$invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1801
+        $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1802 1802
         return apply_filters( 'wpinv_get_view_url', $invoice_url, $this );
1803
-	}
1803
+    }
1804 1804
 
1805
-	/**
1806
-	 * Retrieves the payment url.
1807
-	 *
1808
-	 * @since 1.0.19
1809
-	 * @return string
1810
-	 */
1811
-	public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1805
+    /**
1806
+     * Retrieves the payment url.
1807
+     *
1808
+     * @since 1.0.19
1809
+     * @return string
1810
+     */
1811
+    public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1812 1812
 
1813
-		// Retrieve the checkout url.
1813
+        // Retrieve the checkout url.
1814 1814
         $pay_url = wpinv_get_checkout_uri();
1815 1815
 
1816
-		// Maybe force ssl.
1816
+        // Maybe force ssl.
1817 1817
         if ( is_ssl() ) {
1818 1818
             $pay_url = str_replace( 'http:', 'https:', $pay_url );
1819 1819
         }
1820 1820
 
1821
-		// Add the invoice key.
1822
-		$pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1821
+        // Add the invoice key.
1822
+        $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1823 1823
 
1824
-		// (Maybe?) add a secret
1824
+        // (Maybe?) add a secret
1825 1825
         if ( $secret ) {
1826 1826
             $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url );
1827 1827
         }
1828 1828
 
1829 1829
         return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret );
1830
-	}
1830
+    }
1831 1831
 	
1832
-	/**
1833
-	 * Retrieves the receipt url.
1834
-	 *
1835
-	 * @since 1.0.19
1836
-	 * @return string
1837
-	 */
1838
-	public function get_receipt_url() {
1839
-
1840
-		// Retrieve the checkout url.
1832
+    /**
1833
+     * Retrieves the receipt url.
1834
+     *
1835
+     * @since 1.0.19
1836
+     * @return string
1837
+     */
1838
+    public function get_receipt_url() {
1839
+
1840
+        // Retrieve the checkout url.
1841 1841
         $receipt_url = wpinv_get_success_page_uri();
1842 1842
 
1843
-		// Maybe force ssl.
1843
+        // Maybe force ssl.
1844 1844
         if ( is_ssl() ) {
1845 1845
             $receipt_url = str_replace( 'http:', 'https:', $receipt_url );
1846 1846
         }
1847 1847
 
1848
-		// Add the invoice key.
1849
-		$receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url );
1848
+        // Add the invoice key.
1849
+        $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url );
1850 1850
 
1851 1851
         return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this );
1852
-	}
1852
+    }
1853 1853
 	
1854
-	/**
1855
-	 * Retrieves the default status.
1856
-	 *
1857
-	 * @since 1.0.19
1858
-	 * @return string
1859
-	 */
1860
-	public function get_default_status() {
1861
-
1862
-		$type   = $this->get_type();
1863
-		$status = "wpi-$type-pending";
1864
-		return str_replace( '-invoice', '', $status );
1865
-
1866
-	}
1867
-
1868
-    /**
1869
-	 * Magic method for accessing invoice properties.
1870
-	 *
1871
-	 * @since 1.0.15
1872
-	 * @access public
1873
-	 *
1874
-	 * @param string $key Discount data to retrieve
1875
-	 * @param  string $context View or edit context.
1876
-	 * @return mixed Value of the given invoice property (if set).
1877
-	 */
1878
-	public function get( $key, $context = 'view' ) {
1854
+    /**
1855
+     * Retrieves the default status.
1856
+     *
1857
+     * @since 1.0.19
1858
+     * @return string
1859
+     */
1860
+    public function get_default_status() {
1861
+
1862
+        $type   = $this->get_type();
1863
+        $status = "wpi-$type-pending";
1864
+        return str_replace( '-invoice', '', $status );
1865
+
1866
+    }
1867
+
1868
+    /**
1869
+     * Magic method for accessing invoice properties.
1870
+     *
1871
+     * @since 1.0.15
1872
+     * @access public
1873
+     *
1874
+     * @param string $key Discount data to retrieve
1875
+     * @param  string $context View or edit context.
1876
+     * @return mixed Value of the given invoice property (if set).
1877
+     */
1878
+    public function get( $key, $context = 'view' ) {
1879 1879
         return $this->get_prop( $key, $context );
1880
-	}
1880
+    }
1881 1881
 
1882 1882
     /*
1883 1883
 	|--------------------------------------------------------------------------
@@ -1890,130 +1890,130 @@  discard block
 block discarded – undo
1890 1890
     */
1891 1891
 
1892 1892
     /**
1893
-	 * Magic method for setting invoice properties.
1894
-	 *
1895
-	 * @since 1.0.19
1896
-	 * @access public
1897
-	 *
1898
-	 * @param string $key Discount data to retrieve
1899
-	 * @param  mixed $value new value.
1900
-	 * @return mixed Value of the given invoice property (if set).
1901
-	 */
1902
-	public function set( $key, $value ) {
1893
+     * Magic method for setting invoice properties.
1894
+     *
1895
+     * @since 1.0.19
1896
+     * @access public
1897
+     *
1898
+     * @param string $key Discount data to retrieve
1899
+     * @param  mixed $value new value.
1900
+     * @return mixed Value of the given invoice property (if set).
1901
+     */
1902
+    public function set( $key, $value ) {
1903 1903
 
1904 1904
         $setter = "set_$key";
1905 1905
         if ( is_callable( array( $this, $setter ) ) ) {
1906 1906
             $this->{$setter}( $value );
1907 1907
         }
1908 1908
 
1909
-	}
1909
+    }
1910 1910
 
1911
-	/**
1912
-	 * Sets item status.
1913
-	 *
1914
-	 * @since 1.0.19
1915
-	 * @param string $new_status    New status.
1916
-	 * @param string $note          Optional note to add.
1917
-	 * @param bool   $manual_update Is this a manual status change?.
1918
-	 * @return array details of change.
1919
-	 */
1920
-	public function set_status( $new_status, $note = '', $manual_update = false ) {
1921
-		$old_status = $this->get_status();
1911
+    /**
1912
+     * Sets item status.
1913
+     *
1914
+     * @since 1.0.19
1915
+     * @param string $new_status    New status.
1916
+     * @param string $note          Optional note to add.
1917
+     * @param bool   $manual_update Is this a manual status change?.
1918
+     * @return array details of change.
1919
+     */
1920
+    public function set_status( $new_status, $note = '', $manual_update = false ) {
1921
+        $old_status = $this->get_status();
1922 1922
 
1923
-		$statuses = $this->get_all_statuses();
1923
+        $statuses = $this->get_all_statuses();
1924 1924
 
1925
-		if ( isset( $statuses[ 'draft' ] ) ) {
1926
-			unset( $statuses[ 'draft' ] );
1927
-		}
1925
+        if ( isset( $statuses[ 'draft' ] ) ) {
1926
+            unset( $statuses[ 'draft' ] );
1927
+        }
1928 1928
 
1929
-		$this->set_prop( 'status', $new_status );
1929
+        $this->set_prop( 'status', $new_status );
1930 1930
 
1931
-		// If setting the status, ensure it's set to a valid status.
1932
-		if ( true === $this->object_read ) {
1931
+        // If setting the status, ensure it's set to a valid status.
1932
+        if ( true === $this->object_read ) {
1933 1933
 
1934
-			// Only allow valid new status.
1935
-			if ( ! array_key_exists( $new_status, $statuses ) ) {
1936
-				$new_status = $this->get_default_status();
1937
-			}
1934
+            // Only allow valid new status.
1935
+            if ( ! array_key_exists( $new_status, $statuses ) ) {
1936
+                $new_status = $this->get_default_status();
1937
+            }
1938 1938
 
1939
-			// If the old status is set but unknown (e.g. draft) assume its pending for action usage.
1940
-			if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) {
1941
-				$old_status = $this->get_default_status();
1942
-			}
1939
+            // If the old status is set but unknown (e.g. draft) assume its pending for action usage.
1940
+            if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) {
1941
+                $old_status = $this->get_default_status();
1942
+            }
1943 1943
 
1944
-			// Paid - Renewal (i.e when duplicating a parent invoice )
1945
-			if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) {
1946
-				$old_status = 'wpi-pending';
1947
-			}
1944
+            // Paid - Renewal (i.e when duplicating a parent invoice )
1945
+            if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) {
1946
+                $old_status = 'wpi-pending';
1947
+            }
1948 1948
 
1949
-			if ( $old_status !== $new_status ) {
1950
-				$this->status_transition = array(
1951
-					'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
1952
-					'to'     => $new_status,
1953
-					'note'   => $note,
1954
-					'manual' => (bool) $manual_update,
1955
-				);
1949
+            if ( $old_status !== $new_status ) {
1950
+                $this->status_transition = array(
1951
+                    'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
1952
+                    'to'     => $new_status,
1953
+                    'note'   => $note,
1954
+                    'manual' => (bool) $manual_update,
1955
+                );
1956 1956
 
1957
-				if ( $manual_update ) {
1958
-					do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
1959
-				}
1957
+                if ( $manual_update ) {
1958
+                    do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
1959
+                }
1960 1960
 
1961
-				$this->maybe_set_date_paid();
1961
+                $this->maybe_set_date_paid();
1962 1962
 
1963
-			}
1963
+            }
1964 1964
 
1965
-		}
1965
+        }
1966 1966
 
1967
-		return array(
1968
-			'from' => $old_status,
1969
-			'to'   => $new_status,
1970
-		);
1971
-	}
1967
+        return array(
1968
+            'from' => $old_status,
1969
+            'to'   => $new_status,
1970
+        );
1971
+    }
1972 1972
 
1973
-	/**
1974
-	 * Maybe set date paid.
1975
-	 *
1976
-	 * Sets the date paid variable when transitioning to the payment complete
1977
-	 * order status.
1978
-	 *
1979
-	 * @since 1.0.19
1980
-	 */
1981
-	public function maybe_set_date_paid() {
1973
+    /**
1974
+     * Maybe set date paid.
1975
+     *
1976
+     * Sets the date paid variable when transitioning to the payment complete
1977
+     * order status.
1978
+     *
1979
+     * @since 1.0.19
1980
+     */
1981
+    public function maybe_set_date_paid() {
1982 1982
 
1983
-		if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
1984
-			$this->set_date_completed( current_time( 'mysql' ) );
1985
-		}
1986
-	}
1983
+        if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
1984
+            $this->set_date_completed( current_time( 'mysql' ) );
1985
+        }
1986
+    }
1987 1987
 
1988 1988
     /**
1989
-	 * Set parent invoice ID.
1990
-	 *
1991
-	 * @since 1.0.19
1992
-	 */
1993
-	public function set_parent_id( $value ) {
1994
-		if ( $value && ( $value === $this->get_id() ) ) {
1995
-			return;
1996
-		}
1997
-		$this->set_prop( 'parent_id', absint( $value ) );
1989
+     * Set parent invoice ID.
1990
+     *
1991
+     * @since 1.0.19
1992
+     */
1993
+    public function set_parent_id( $value ) {
1994
+        if ( $value && ( $value === $this->get_id() ) ) {
1995
+            return;
1996
+        }
1997
+        $this->set_prop( 'parent_id', absint( $value ) );
1998 1998
     }
1999 1999
 
2000 2000
     /**
2001
-	 * Set plugin version when the invoice was created.
2002
-	 *
2003
-	 * @since 1.0.19
2004
-	 */
2005
-	public function set_version( $value ) {
2006
-		$this->set_prop( 'version', $value );
2001
+     * Set plugin version when the invoice was created.
2002
+     *
2003
+     * @since 1.0.19
2004
+     */
2005
+    public function set_version( $value ) {
2006
+        $this->set_prop( 'version', $value );
2007 2007
     }
2008
-
2009
-    /**
2010
-	 * Set date when the invoice was created.
2011
-	 *
2012
-	 * @since 1.0.19
2013
-	 * @param string $value Value to set.
2008
+
2009
+    /**
2010
+     * Set date when the invoice was created.
2011
+     *
2012
+     * @since 1.0.19
2013
+     * @param string $value Value to set.
2014 2014
      * @return bool Whether or not the date was set.
2015
-	 */
2016
-	public function set_date_created( $value ) {
2015
+     */
2016
+    public function set_date_created( $value ) {
2017 2017
         $date = strtotime( $value );
2018 2018
 
2019 2019
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -2021,19 +2021,19 @@  discard block
 block discarded – undo
2021 2021
             return true;
2022 2022
         }
2023 2023
 
2024
-		$this->set_prop( 'date_created', '' );
2025
-		return false;
2024
+        $this->set_prop( 'date_created', '' );
2025
+        return false;
2026 2026
 
2027 2027
     }
2028 2028
 
2029 2029
     /**
2030
-	 * Set date invoice due date.
2031
-	 *
2032
-	 * @since 1.0.19
2033
-	 * @param string $value Value to set.
2030
+     * Set date invoice due date.
2031
+     *
2032
+     * @since 1.0.19
2033
+     * @param string $value Value to set.
2034 2034
      * @return bool Whether or not the date was set.
2035
-	 */
2036
-	public function set_due_date( $value ) {
2035
+     */
2036
+    public function set_due_date( $value ) {
2037 2037
         $date = strtotime( $value );
2038 2038
 
2039 2039
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -2041,29 +2041,29 @@  discard block
 block discarded – undo
2041 2041
             return true;
2042 2042
         }
2043 2043
 
2044
-		$this->set_prop( 'due_date', '' );
2044
+        $this->set_prop( 'due_date', '' );
2045 2045
         return false;
2046 2046
 
2047 2047
     }
2048 2048
 
2049 2049
     /**
2050
-	 * Alias of self::set_due_date().
2051
-	 *
2052
-	 * @since 1.0.19
2053
-	 * @param  string $value New name.
2054
-	 */
2055
-	public function set_date_due( $value ) {
2056
-		$this->set_due_date( $value );
2050
+     * Alias of self::set_due_date().
2051
+     *
2052
+     * @since 1.0.19
2053
+     * @param  string $value New name.
2054
+     */
2055
+    public function set_date_due( $value ) {
2056
+        $this->set_due_date( $value );
2057 2057
     }
2058 2058
 
2059 2059
     /**
2060
-	 * Set date invoice was completed.
2061
-	 *
2062
-	 * @since 1.0.19
2063
-	 * @param string $value Value to set.
2060
+     * Set date invoice was completed.
2061
+     *
2062
+     * @since 1.0.19
2063
+     * @param string $value Value to set.
2064 2064
      * @return bool Whether or not the date was set.
2065
-	 */
2066
-	public function set_completed_date( $value ) {
2065
+     */
2066
+    public function set_completed_date( $value ) {
2067 2067
         $date = strtotime( $value );
2068 2068
 
2069 2069
         if ( $date && $value !== '0000-00-00 00:00:00'  ) {
@@ -2071,29 +2071,29 @@  discard block
 block discarded – undo
2071 2071
             return true;
2072 2072
         }
2073 2073
 
2074
-		$this->set_prop( 'completed_date', '' );
2074
+        $this->set_prop( 'completed_date', '' );
2075 2075
         return false;
2076 2076
 
2077 2077
     }
2078 2078
 
2079 2079
     /**
2080
-	 * Alias of self::set_completed_date().
2081
-	 *
2082
-	 * @since 1.0.19
2083
-	 * @param  string $value New name.
2084
-	 */
2085
-	public function set_date_completed( $value ) {
2086
-		$this->set_completed_date( $value );
2080
+     * Alias of self::set_completed_date().
2081
+     *
2082
+     * @since 1.0.19
2083
+     * @param  string $value New name.
2084
+     */
2085
+    public function set_date_completed( $value ) {
2086
+        $this->set_completed_date( $value );
2087 2087
     }
2088 2088
 
2089 2089
     /**
2090
-	 * Set date when the invoice was last modified.
2091
-	 *
2092
-	 * @since 1.0.19
2093
-	 * @param string $value Value to set.
2090
+     * Set date when the invoice was last modified.
2091
+     *
2092
+     * @since 1.0.19
2093
+     * @param string $value Value to set.
2094 2094
      * @return bool Whether or not the date was set.
2095
-	 */
2096
-	public function set_date_modified( $value ) {
2095
+     */
2096
+    public function set_date_modified( $value ) {
2097 2097
         $date = strtotime( $value );
2098 2098
 
2099 2099
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -2101,788 +2101,788 @@  discard block
 block discarded – undo
2101 2101
             return true;
2102 2102
         }
2103 2103
 
2104
-		$this->set_prop( 'date_modified', '' );
2104
+        $this->set_prop( 'date_modified', '' );
2105 2105
         return false;
2106 2106
 
2107 2107
     }
2108 2108
 
2109 2109
     /**
2110
-	 * Set the invoice number.
2111
-	 *
2112
-	 * @since 1.0.19
2113
-	 * @param  string $value New number.
2114
-	 */
2115
-	public function set_number( $value ) {
2110
+     * Set the invoice number.
2111
+     *
2112
+     * @since 1.0.19
2113
+     * @param  string $value New number.
2114
+     */
2115
+    public function set_number( $value ) {
2116 2116
         $number = sanitize_text_field( $value );
2117
-		$this->set_prop( 'number', $number );
2117
+        $this->set_prop( 'number', $number );
2118 2118
     }
2119 2119
 
2120 2120
     /**
2121
-	 * Set the invoice type.
2122
-	 *
2123
-	 * @since 1.0.19
2124
-	 * @param  string $value Type.
2125
-	 */
2126
-	public function set_type( $value ) {
2121
+     * Set the invoice type.
2122
+     *
2123
+     * @since 1.0.19
2124
+     * @param  string $value Type.
2125
+     */
2126
+    public function set_type( $value ) {
2127 2127
         $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) );
2128
-		$this->set_prop( 'type', $type );
2129
-	}
2128
+        $this->set_prop( 'type', $type );
2129
+    }
2130 2130
 
2131 2131
     /**
2132
-	 * Set the invoice post type.
2133
-	 *
2134
-	 * @since 1.0.19
2135
-	 * @param  string $value Post type.
2136
-	 */
2137
-	public function set_post_type( $value ) {
2132
+     * Set the invoice post type.
2133
+     *
2134
+     * @since 1.0.19
2135
+     * @param  string $value Post type.
2136
+     */
2137
+    public function set_post_type( $value ) {
2138 2138
         if ( getpaid_is_invoice_post_type( $value ) ) {
2139
-			$this->set_type( $value );
2139
+            $this->set_type( $value );
2140 2140
             $this->set_prop( 'post_type', $value );
2141 2141
         }
2142 2142
     }
2143 2143
 
2144 2144
     /**
2145
-	 * Set the invoice key.
2146
-	 *
2147
-	 * @since 1.0.19
2148
-	 * @param  string $value New key.
2149
-	 */
2150
-	public function set_key( $value ) {
2145
+     * Set the invoice key.
2146
+     *
2147
+     * @since 1.0.19
2148
+     * @param  string $value New key.
2149
+     */
2150
+    public function set_key( $value ) {
2151 2151
         $key = sanitize_text_field( $value );
2152
-		$this->set_prop( 'key', $key );
2152
+        $this->set_prop( 'key', $key );
2153 2153
     }
2154 2154
 
2155 2155
     /**
2156
-	 * Set the invoice mode.
2157
-	 *
2158
-	 * @since 1.0.19
2159
-	 * @param  string $value mode.
2160
-	 */
2161
-	public function set_mode( $value ) {
2156
+     * Set the invoice mode.
2157
+     *
2158
+     * @since 1.0.19
2159
+     * @param  string $value mode.
2160
+     */
2161
+    public function set_mode( $value ) {
2162 2162
         if ( in_array( $value, array( 'live', 'test' ) ) ) {
2163 2163
             $this->set_prop( 'mode', $value );
2164 2164
         }
2165 2165
     }
2166 2166
 
2167 2167
     /**
2168
-	 * Set the invoice path.
2169
-	 *
2170
-	 * @since 1.0.19
2171
-	 * @param  string $value path.
2172
-	 */
2173
-	public function set_path( $value ) {
2168
+     * Set the invoice path.
2169
+     *
2170
+     * @since 1.0.19
2171
+     * @param  string $value path.
2172
+     */
2173
+    public function set_path( $value ) {
2174 2174
         $this->set_prop( 'path', $value );
2175 2175
     }
2176 2176
 
2177 2177
     /**
2178
-	 * Set the invoice name.
2179
-	 *
2180
-	 * @since 1.0.19
2181
-	 * @param  string $value New name.
2182
-	 */
2183
-	public function set_name( $value ) {
2178
+     * Set the invoice name.
2179
+     *
2180
+     * @since 1.0.19
2181
+     * @param  string $value New name.
2182
+     */
2183
+    public function set_name( $value ) {
2184 2184
         $name = sanitize_text_field( $value );
2185
-		$this->set_prop( 'name', $name );
2185
+        $this->set_prop( 'name', $name );
2186 2186
     }
2187 2187
 
2188 2188
     /**
2189
-	 * Alias of self::set_name().
2190
-	 *
2191
-	 * @since 1.0.19
2192
-	 * @param  string $value New name.
2193
-	 */
2194
-	public function set_title( $value ) {
2195
-		$this->set_name( $value );
2189
+     * Alias of self::set_name().
2190
+     *
2191
+     * @since 1.0.19
2192
+     * @param  string $value New name.
2193
+     */
2194
+    public function set_title( $value ) {
2195
+        $this->set_name( $value );
2196 2196
     }
2197 2197
 
2198 2198
     /**
2199
-	 * Set the invoice description.
2200
-	 *
2201
-	 * @since 1.0.19
2202
-	 * @param  string $value New description.
2203
-	 */
2204
-	public function set_description( $value ) {
2199
+     * Set the invoice description.
2200
+     *
2201
+     * @since 1.0.19
2202
+     * @param  string $value New description.
2203
+     */
2204
+    public function set_description( $value ) {
2205 2205
         $description = wp_kses_post( $value );
2206
-		$this->set_prop( 'description', $description );
2206
+        $this->set_prop( 'description', $description );
2207 2207
     }
2208 2208
 
2209 2209
     /**
2210
-	 * Alias of self::set_description().
2211
-	 *
2212
-	 * @since 1.0.19
2213
-	 * @param  string $value New description.
2214
-	 */
2215
-	public function set_excerpt( $value ) {
2216
-		$this->set_description( $value );
2210
+     * Alias of self::set_description().
2211
+     *
2212
+     * @since 1.0.19
2213
+     * @param  string $value New description.
2214
+     */
2215
+    public function set_excerpt( $value ) {
2216
+        $this->set_description( $value );
2217 2217
     }
2218 2218
 
2219 2219
     /**
2220
-	 * Alias of self::set_description().
2221
-	 *
2222
-	 * @since 1.0.19
2223
-	 * @param  string $value New description.
2224
-	 */
2225
-	public function set_summary( $value ) {
2226
-		$this->set_description( $value );
2220
+     * Alias of self::set_description().
2221
+     *
2222
+     * @since 1.0.19
2223
+     * @param  string $value New description.
2224
+     */
2225
+    public function set_summary( $value ) {
2226
+        $this->set_description( $value );
2227
+    }
2228
+
2229
+    /**
2230
+     * Set the receiver of the invoice.
2231
+     *
2232
+     * @since 1.0.19
2233
+     * @param  int $value New author.
2234
+     */
2235
+    public function set_author( $value ) {
2236
+        $user = get_user_by( 'id', (int) $value );
2237
+
2238
+        if ( $user && $user->ID ) {
2239
+            $this->set_prop( 'author', $user->ID );
2240
+            $this->set_prop( 'email', $user->user_email );
2241
+        }
2242
+
2227 2243
     }
2228 2244
 
2229 2245
     /**
2230
-	 * Set the receiver of the invoice.
2231
-	 *
2232
-	 * @since 1.0.19
2233
-	 * @param  int $value New author.
2234
-	 */
2235
-	public function set_author( $value ) {
2236
-		$user = get_user_by( 'id', (int) $value );
2246
+     * Alias of self::set_author().
2247
+     *
2248
+     * @since 1.0.19
2249
+     * @param  int $value New user id.
2250
+     */
2251
+    public function set_user_id( $value ) {
2252
+        $this->set_author( $value );
2253
+    }
2237 2254
 
2238
-		if ( $user && $user->ID ) {
2239
-			$this->set_prop( 'author', $user->ID );
2240
-			$this->set_prop( 'email', $user->user_email );
2241
-		}
2255
+    /**
2256
+     * Alias of self::set_author().
2257
+     *
2258
+     * @since 1.0.19
2259
+     * @param  int $value New user id.
2260
+     */
2261
+    public function set_customer_id( $value ) {
2262
+        $this->set_author( $value );
2263
+    }
2242 2264
 
2265
+    /**
2266
+     * Set the customer's ip.
2267
+     *
2268
+     * @since 1.0.19
2269
+     * @param  string $value ip address.
2270
+     */
2271
+    public function set_ip( $value ) {
2272
+        $this->set_prop( 'ip', $value );
2243 2273
     }
2244 2274
 
2245 2275
     /**
2246
-	 * Alias of self::set_author().
2247
-	 *
2248
-	 * @since 1.0.19
2249
-	 * @param  int $value New user id.
2250
-	 */
2251
-	public function set_user_id( $value ) {
2252
-		$this->set_author( $value );
2276
+     * Alias of self::set_ip().
2277
+     *
2278
+     * @since 1.0.19
2279
+     * @param  string $value ip address.
2280
+     */
2281
+    public function set_user_ip( $value ) {
2282
+        $this->set_ip( $value );
2253 2283
     }
2254 2284
 
2255 2285
     /**
2256
-	 * Alias of self::set_author().
2257
-	 *
2258
-	 * @since 1.0.19
2259
-	 * @param  int $value New user id.
2260
-	 */
2261
-	public function set_customer_id( $value ) {
2262
-		$this->set_author( $value );
2286
+     * Set the customer's first name.
2287
+     *
2288
+     * @since 1.0.19
2289
+     * @param  string $value first name.
2290
+     */
2291
+    public function set_first_name( $value ) {
2292
+        $this->set_prop( 'first_name', $value );
2263 2293
     }
2264 2294
 
2265 2295
     /**
2266
-	 * Set the customer's ip.
2267
-	 *
2268
-	 * @since 1.0.19
2269
-	 * @param  string $value ip address.
2270
-	 */
2271
-	public function set_ip( $value ) {
2272
-		$this->set_prop( 'ip', $value );
2296
+     * Alias of self::set_first_name().
2297
+     *
2298
+     * @since 1.0.19
2299
+     * @param  string $value first name.
2300
+     */
2301
+    public function set_user_first_name( $value ) {
2302
+        $this->set_first_name( $value );
2273 2303
     }
2274 2304
 
2275 2305
     /**
2276
-	 * Alias of self::set_ip().
2277
-	 *
2278
-	 * @since 1.0.19
2279
-	 * @param  string $value ip address.
2280
-	 */
2281
-	public function set_user_ip( $value ) {
2282
-		$this->set_ip( $value );
2306
+     * Alias of self::set_first_name().
2307
+     *
2308
+     * @since 1.0.19
2309
+     * @param  string $value first name.
2310
+     */
2311
+    public function set_customer_first_name( $value ) {
2312
+        $this->set_first_name( $value );
2283 2313
     }
2284 2314
 
2285 2315
     /**
2286
-	 * Set the customer's first name.
2287
-	 *
2288
-	 * @since 1.0.19
2289
-	 * @param  string $value first name.
2290
-	 */
2291
-	public function set_first_name( $value ) {
2292
-		$this->set_prop( 'first_name', $value );
2316
+     * Set the customer's last name.
2317
+     *
2318
+     * @since 1.0.19
2319
+     * @param  string $value last name.
2320
+     */
2321
+    public function set_last_name( $value ) {
2322
+        $this->set_prop( 'last_name', $value );
2293 2323
     }
2294 2324
 
2295 2325
     /**
2296
-	 * Alias of self::set_first_name().
2297
-	 *
2298
-	 * @since 1.0.19
2299
-	 * @param  string $value first name.
2300
-	 */
2301
-	public function set_user_first_name( $value ) {
2302
-		$this->set_first_name( $value );
2326
+     * Alias of self::set_last_name().
2327
+     *
2328
+     * @since 1.0.19
2329
+     * @param  string $value last name.
2330
+     */
2331
+    public function set_user_last_name( $value ) {
2332
+        $this->set_last_name( $value );
2303 2333
     }
2304 2334
 
2305 2335
     /**
2306
-	 * Alias of self::set_first_name().
2307
-	 *
2308
-	 * @since 1.0.19
2309
-	 * @param  string $value first name.
2310
-	 */
2311
-	public function set_customer_first_name( $value ) {
2312
-		$this->set_first_name( $value );
2336
+     * Alias of self::set_last_name().
2337
+     *
2338
+     * @since 1.0.19
2339
+     * @param  string $value last name.
2340
+     */
2341
+    public function set_customer_last_name( $value ) {
2342
+        $this->set_last_name( $value );
2313 2343
     }
2314 2344
 
2315 2345
     /**
2316
-	 * Set the customer's last name.
2317
-	 *
2318
-	 * @since 1.0.19
2319
-	 * @param  string $value last name.
2320
-	 */
2321
-	public function set_last_name( $value ) {
2322
-		$this->set_prop( 'last_name', $value );
2346
+     * Set the customer's phone number.
2347
+     *
2348
+     * @since 1.0.19
2349
+     * @param  string $value phone.
2350
+     */
2351
+    public function set_phone( $value ) {
2352
+        $this->set_prop( 'phone', $value );
2323 2353
     }
2324 2354
 
2325 2355
     /**
2326
-	 * Alias of self::set_last_name().
2327
-	 *
2328
-	 * @since 1.0.19
2329
-	 * @param  string $value last name.
2330
-	 */
2331
-	public function set_user_last_name( $value ) {
2332
-		$this->set_last_name( $value );
2356
+     * Alias of self::set_phone().
2357
+     *
2358
+     * @since 1.0.19
2359
+     * @param  string $value phone.
2360
+     */
2361
+    public function set_user_phone( $value ) {
2362
+        $this->set_phone( $value );
2333 2363
     }
2334 2364
 
2335 2365
     /**
2336
-	 * Alias of self::set_last_name().
2337
-	 *
2338
-	 * @since 1.0.19
2339
-	 * @param  string $value last name.
2340
-	 */
2341
-	public function set_customer_last_name( $value ) {
2342
-		$this->set_last_name( $value );
2366
+     * Alias of self::set_phone().
2367
+     *
2368
+     * @since 1.0.19
2369
+     * @param  string $value phone.
2370
+     */
2371
+    public function set_customer_phone( $value ) {
2372
+        $this->set_phone( $value );
2373
+    }
2374
+
2375
+    /**
2376
+     * Alias of self::set_phone().
2377
+     *
2378
+     * @since 1.0.19
2379
+     * @param  string $value phone.
2380
+     */
2381
+    public function set_phone_number( $value ) {
2382
+        $this->set_phone( $value );
2383
+    }
2384
+
2385
+    /**
2386
+     * Set the customer's email address.
2387
+     *
2388
+     * @since 1.0.19
2389
+     * @param  string $value email address.
2390
+     */
2391
+    public function set_email( $value ) {
2392
+        $this->set_prop( 'email', $value );
2393
+    }
2394
+
2395
+    /**
2396
+     * Alias of self::set_email().
2397
+     *
2398
+     * @since 1.0.19
2399
+     * @param  string $value email address.
2400
+     */
2401
+    public function set_user_email( $value ) {
2402
+        $this->set_email( $value );
2403
+    }
2404
+
2405
+    /**
2406
+     * Alias of self::set_email().
2407
+     *
2408
+     * @since 1.0.19
2409
+     * @param  string $value email address.
2410
+     */
2411
+    public function set_email_address( $value ) {
2412
+        $this->set_email( $value );
2413
+    }
2414
+
2415
+    /**
2416
+     * Alias of self::set_email().
2417
+     *
2418
+     * @since 1.0.19
2419
+     * @param  string $value email address.
2420
+     */
2421
+    public function set_customer_email( $value ) {
2422
+        $this->set_email( $value );
2423
+    }
2424
+
2425
+    /**
2426
+     * Set the customer's country.
2427
+     *
2428
+     * @since 1.0.19
2429
+     * @param  string $value country.
2430
+     */
2431
+    public function set_country( $value ) {
2432
+        $this->set_prop( 'country', $value );
2433
+    }
2434
+
2435
+    /**
2436
+     * Alias of self::set_country().
2437
+     *
2438
+     * @since 1.0.19
2439
+     * @param  string $value country.
2440
+     */
2441
+    public function set_user_country( $value ) {
2442
+        $this->set_country( $value );
2443
+    }
2444
+
2445
+    /**
2446
+     * Alias of self::set_country().
2447
+     *
2448
+     * @since 1.0.19
2449
+     * @param  string $value country.
2450
+     */
2451
+    public function set_customer_country( $value ) {
2452
+        $this->set_country( $value );
2453
+    }
2454
+
2455
+    /**
2456
+     * Set the customer's state.
2457
+     *
2458
+     * @since 1.0.19
2459
+     * @param  string $value state.
2460
+     */
2461
+    public function set_state( $value ) {
2462
+        $this->set_prop( 'state', $value );
2463
+    }
2464
+
2465
+    /**
2466
+     * Alias of self::set_state().
2467
+     *
2468
+     * @since 1.0.19
2469
+     * @param  string $value state.
2470
+     */
2471
+    public function set_user_state( $value ) {
2472
+        $this->set_state( $value );
2473
+    }
2474
+
2475
+    /**
2476
+     * Alias of self::set_state().
2477
+     *
2478
+     * @since 1.0.19
2479
+     * @param  string $value state.
2480
+     */
2481
+    public function set_customer_state( $value ) {
2482
+        $this->set_state( $value );
2483
+    }
2484
+
2485
+    /**
2486
+     * Set the customer's city.
2487
+     *
2488
+     * @since 1.0.19
2489
+     * @param  string $value city.
2490
+     */
2491
+    public function set_city( $value ) {
2492
+        $this->set_prop( 'city', $value );
2343 2493
     }
2344 2494
 
2345 2495
     /**
2346
-	 * Set the customer's phone number.
2347
-	 *
2348
-	 * @since 1.0.19
2349
-	 * @param  string $value phone.
2350
-	 */
2351
-	public function set_phone( $value ) {
2352
-		$this->set_prop( 'phone', $value );
2496
+     * Alias of self::set_city().
2497
+     *
2498
+     * @since 1.0.19
2499
+     * @param  string $value city.
2500
+     */
2501
+    public function set_user_city( $value ) {
2502
+        $this->set_city( $value );
2353 2503
     }
2354 2504
 
2355 2505
     /**
2356
-	 * Alias of self::set_phone().
2357
-	 *
2358
-	 * @since 1.0.19
2359
-	 * @param  string $value phone.
2360
-	 */
2361
-	public function set_user_phone( $value ) {
2362
-		$this->set_phone( $value );
2506
+     * Alias of self::set_city().
2507
+     *
2508
+     * @since 1.0.19
2509
+     * @param  string $value city.
2510
+     */
2511
+    public function set_customer_city( $value ) {
2512
+        $this->set_city( $value );
2363 2513
     }
2364 2514
 
2365 2515
     /**
2366
-	 * Alias of self::set_phone().
2367
-	 *
2368
-	 * @since 1.0.19
2369
-	 * @param  string $value phone.
2370
-	 */
2371
-	public function set_customer_phone( $value ) {
2372
-		$this->set_phone( $value );
2516
+     * Set the customer's zip code.
2517
+     *
2518
+     * @since 1.0.19
2519
+     * @param  string $value zip.
2520
+     */
2521
+    public function set_zip( $value ) {
2522
+        $this->set_prop( 'zip', $value );
2373 2523
     }
2374 2524
 
2375 2525
     /**
2376
-	 * Alias of self::set_phone().
2377
-	 *
2378
-	 * @since 1.0.19
2379
-	 * @param  string $value phone.
2380
-	 */
2381
-	public function set_phone_number( $value ) {
2382
-		$this->set_phone( $value );
2526
+     * Alias of self::set_zip().
2527
+     *
2528
+     * @since 1.0.19
2529
+     * @param  string $value zip.
2530
+     */
2531
+    public function set_user_zip( $value ) {
2532
+        $this->set_zip( $value );
2383 2533
     }
2384 2534
 
2385 2535
     /**
2386
-	 * Set the customer's email address.
2387
-	 *
2388
-	 * @since 1.0.19
2389
-	 * @param  string $value email address.
2390
-	 */
2391
-	public function set_email( $value ) {
2392
-		$this->set_prop( 'email', $value );
2536
+     * Alias of self::set_zip().
2537
+     *
2538
+     * @since 1.0.19
2539
+     * @param  string $value zip.
2540
+     */
2541
+    public function set_customer_zip( $value ) {
2542
+        $this->set_zip( $value );
2393 2543
     }
2394 2544
 
2395 2545
     /**
2396
-	 * Alias of self::set_email().
2397
-	 *
2398
-	 * @since 1.0.19
2399
-	 * @param  string $value email address.
2400
-	 */
2401
-	public function set_user_email( $value ) {
2402
-		$this->set_email( $value );
2546
+     * Set the customer's company.
2547
+     *
2548
+     * @since 1.0.19
2549
+     * @param  string $value company.
2550
+     */
2551
+    public function set_company( $value ) {
2552
+        $this->set_prop( 'company', $value );
2403 2553
     }
2404 2554
 
2405 2555
     /**
2406
-	 * Alias of self::set_email().
2407
-	 *
2408
-	 * @since 1.0.19
2409
-	 * @param  string $value email address.
2410
-	 */
2411
-	public function set_email_address( $value ) {
2412
-		$this->set_email( $value );
2556
+     * Alias of self::set_company().
2557
+     *
2558
+     * @since 1.0.19
2559
+     * @param  string $value company.
2560
+     */
2561
+    public function set_user_company( $value ) {
2562
+        $this->set_company( $value );
2413 2563
     }
2414 2564
 
2415 2565
     /**
2416
-	 * Alias of self::set_email().
2417
-	 *
2418
-	 * @since 1.0.19
2419
-	 * @param  string $value email address.
2420
-	 */
2421
-	public function set_customer_email( $value ) {
2422
-		$this->set_email( $value );
2566
+     * Alias of self::set_company().
2567
+     *
2568
+     * @since 1.0.19
2569
+     * @param  string $value company.
2570
+     */
2571
+    public function set_customer_company( $value ) {
2572
+        $this->set_company( $value );
2423 2573
     }
2424 2574
 
2425 2575
     /**
2426
-	 * Set the customer's country.
2427
-	 *
2428
-	 * @since 1.0.19
2429
-	 * @param  string $value country.
2430
-	 */
2431
-	public function set_country( $value ) {
2432
-		$this->set_prop( 'country', $value );
2576
+     * Set the customer's var number.
2577
+     *
2578
+     * @since 1.0.19
2579
+     * @param  string $value var number.
2580
+     */
2581
+    public function set_vat_number( $value ) {
2582
+        $this->set_prop( 'vat_number', $value );
2433 2583
     }
2434 2584
 
2435 2585
     /**
2436
-	 * Alias of self::set_country().
2437
-	 *
2438
-	 * @since 1.0.19
2439
-	 * @param  string $value country.
2440
-	 */
2441
-	public function set_user_country( $value ) {
2442
-		$this->set_country( $value );
2586
+     * Alias of self::set_vat_number().
2587
+     *
2588
+     * @since 1.0.19
2589
+     * @param  string $value var number.
2590
+     */
2591
+    public function set_user_vat_number( $value ) {
2592
+        $this->set_vat_number( $value );
2443 2593
     }
2444 2594
 
2445 2595
     /**
2446
-	 * Alias of self::set_country().
2447
-	 *
2448
-	 * @since 1.0.19
2449
-	 * @param  string $value country.
2450
-	 */
2451
-	public function set_customer_country( $value ) {
2452
-		$this->set_country( $value );
2596
+     * Alias of self::set_vat_number().
2597
+     *
2598
+     * @since 1.0.19
2599
+     * @param  string $value var number.
2600
+     */
2601
+    public function set_customer_vat_number( $value ) {
2602
+        $this->set_vat_number( $value );
2453 2603
     }
2454 2604
 
2455 2605
     /**
2456
-	 * Set the customer's state.
2457
-	 *
2458
-	 * @since 1.0.19
2459
-	 * @param  string $value state.
2460
-	 */
2461
-	public function set_state( $value ) {
2462
-		$this->set_prop( 'state', $value );
2606
+     * Set the customer's vat rate.
2607
+     *
2608
+     * @since 1.0.19
2609
+     * @param  string $value var rate.
2610
+     */
2611
+    public function set_vat_rate( $value ) {
2612
+        $this->set_prop( 'vat_rate', $value );
2463 2613
     }
2464 2614
 
2465 2615
     /**
2466
-	 * Alias of self::set_state().
2467
-	 *
2468
-	 * @since 1.0.19
2469
-	 * @param  string $value state.
2470
-	 */
2471
-	public function set_user_state( $value ) {
2472
-		$this->set_state( $value );
2616
+     * Alias of self::set_vat_rate().
2617
+     *
2618
+     * @since 1.0.19
2619
+     * @param  string $value var number.
2620
+     */
2621
+    public function set_user_vat_rate( $value ) {
2622
+        $this->set_vat_rate( $value );
2473 2623
     }
2474 2624
 
2475 2625
     /**
2476
-	 * Alias of self::set_state().
2477
-	 *
2478
-	 * @since 1.0.19
2479
-	 * @param  string $value state.
2480
-	 */
2481
-	public function set_customer_state( $value ) {
2482
-		$this->set_state( $value );
2626
+     * Alias of self::set_vat_rate().
2627
+     *
2628
+     * @since 1.0.19
2629
+     * @param  string $value var number.
2630
+     */
2631
+    public function set_customer_vat_rate( $value ) {
2632
+        $this->set_vat_rate( $value );
2483 2633
     }
2484 2634
 
2485 2635
     /**
2486
-	 * Set the customer's city.
2487
-	 *
2488
-	 * @since 1.0.19
2489
-	 * @param  string $value city.
2490
-	 */
2491
-	public function set_city( $value ) {
2492
-		$this->set_prop( 'city', $value );
2636
+     * Set the customer's address.
2637
+     *
2638
+     * @since 1.0.19
2639
+     * @param  string $value address.
2640
+     */
2641
+    public function set_address( $value ) {
2642
+        $this->set_prop( 'address', $value );
2493 2643
     }
2494 2644
 
2495 2645
     /**
2496
-	 * Alias of self::set_city().
2497
-	 *
2498
-	 * @since 1.0.19
2499
-	 * @param  string $value city.
2500
-	 */
2501
-	public function set_user_city( $value ) {
2502
-		$this->set_city( $value );
2646
+     * Alias of self::set_address().
2647
+     *
2648
+     * @since 1.0.19
2649
+     * @param  string $value address.
2650
+     */
2651
+    public function set_user_address( $value ) {
2652
+        $this->set_address( $value );
2503 2653
     }
2504 2654
 
2505 2655
     /**
2506
-	 * Alias of self::set_city().
2507
-	 *
2508
-	 * @since 1.0.19
2509
-	 * @param  string $value city.
2510
-	 */
2511
-	public function set_customer_city( $value ) {
2512
-		$this->set_city( $value );
2656
+     * Alias of self::set_address().
2657
+     *
2658
+     * @since 1.0.19
2659
+     * @param  string $value address.
2660
+     */
2661
+    public function set_customer_address( $value ) {
2662
+        $this->set_address( $value );
2513 2663
     }
2514 2664
 
2515 2665
     /**
2516
-	 * Set the customer's zip code.
2517
-	 *
2518
-	 * @since 1.0.19
2519
-	 * @param  string $value zip.
2520
-	 */
2521
-	public function set_zip( $value ) {
2522
-		$this->set_prop( 'zip', $value );
2666
+     * Set whether the customer has viewed the invoice or not.
2667
+     *
2668
+     * @since 1.0.19
2669
+     * @param  int|bool $value confirmed.
2670
+     */
2671
+    public function set_is_viewed( $value ) {
2672
+        $this->set_prop( 'is_viewed', $value );
2523 2673
     }
2524 2674
 
2525 2675
     /**
2526
-	 * Alias of self::set_zip().
2527
-	 *
2528
-	 * @since 1.0.19
2529
-	 * @param  string $value zip.
2530
-	 */
2531
-	public function set_user_zip( $value ) {
2532
-		$this->set_zip( $value );
2676
+     * Set extra email recipients.
2677
+     *
2678
+     * @since 1.0.19
2679
+     * @param  string $value email recipients.
2680
+     */
2681
+    public function set_email_cc( $value ) {
2682
+        $this->set_prop( 'email_cc', $value );
2533 2683
     }
2534 2684
 
2535 2685
     /**
2536
-	 * Alias of self::set_zip().
2537
-	 *
2538
-	 * @since 1.0.19
2539
-	 * @param  string $value zip.
2540
-	 */
2541
-	public function set_customer_zip( $value ) {
2542
-		$this->set_zip( $value );
2686
+     * Set the invoice template.
2687
+     *
2688
+     * @since 1.0.19
2689
+     * @param  string $value template.
2690
+     */
2691
+    public function set_template( $value ) {
2692
+        if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2693
+            $this->set_prop( 'template', $value );
2694
+        }
2543 2695
     }
2544 2696
 
2545 2697
     /**
2546
-	 * Set the customer's company.
2547
-	 *
2548
-	 * @since 1.0.19
2549
-	 * @param  string $value company.
2550
-	 */
2551
-	public function set_company( $value ) {
2552
-		$this->set_prop( 'company', $value );
2698
+     * Set the invoice source.
2699
+     *
2700
+     * @since 1.0.19
2701
+     * @param  string $value source.
2702
+     * @deprecated
2703
+     */
2704
+    public function created_via( $value ) {
2705
+        $this->set_created_via( sanitize_text_field( $value ) );
2553 2706
     }
2554 2707
 
2555 2708
     /**
2556
-	 * Alias of self::set_company().
2557
-	 *
2558
-	 * @since 1.0.19
2559
-	 * @param  string $value company.
2560
-	 */
2561
-	public function set_user_company( $value ) {
2562
-		$this->set_company( $value );
2709
+     * Set the invoice source.
2710
+     *
2711
+     * @since 1.0.19
2712
+     * @param  string $value source.
2713
+     */
2714
+    public function set_created_via( $value ) {
2715
+        $this->set_prop( 'created_via', sanitize_text_field( $value ) );
2563 2716
     }
2564 2717
 
2565 2718
     /**
2566
-	 * Alias of self::set_company().
2567
-	 *
2568
-	 * @since 1.0.19
2569
-	 * @param  string $value company.
2570
-	 */
2571
-	public function set_customer_company( $value ) {
2572
-		$this->set_company( $value );
2719
+     * Set the customer's address confirmed status.
2720
+     *
2721
+     * @since 1.0.19
2722
+     * @param  int|bool $value confirmed.
2723
+     */
2724
+    public function set_address_confirmed( $value ) {
2725
+        $this->set_prop( 'address_confirmed', $value );
2573 2726
     }
2574 2727
 
2575 2728
     /**
2576
-	 * Set the customer's var number.
2577
-	 *
2578
-	 * @since 1.0.19
2579
-	 * @param  string $value var number.
2580
-	 */
2581
-	public function set_vat_number( $value ) {
2582
-		$this->set_prop( 'vat_number', $value );
2729
+     * Alias of self::set_address_confirmed().
2730
+     *
2731
+     * @since 1.0.19
2732
+     * @param  int|bool $value confirmed.
2733
+     */
2734
+    public function set_user_address_confirmed( $value ) {
2735
+        $this->set_address_confirmed( $value );
2583 2736
     }
2584 2737
 
2585 2738
     /**
2586
-	 * Alias of self::set_vat_number().
2587
-	 *
2588
-	 * @since 1.0.19
2589
-	 * @param  string $value var number.
2590
-	 */
2591
-	public function set_user_vat_number( $value ) {
2592
-		$this->set_vat_number( $value );
2739
+     * Alias of self::set_address_confirmed().
2740
+     *
2741
+     * @since 1.0.19
2742
+     * @param  int|bool $value confirmed.
2743
+     */
2744
+    public function set_customer_address_confirmed( $value ) {
2745
+        $this->set_address_confirmed( $value );
2593 2746
     }
2594 2747
 
2595 2748
     /**
2596
-	 * Alias of self::set_vat_number().
2597
-	 *
2598
-	 * @since 1.0.19
2599
-	 * @param  string $value var number.
2600
-	 */
2601
-	public function set_customer_vat_number( $value ) {
2602
-		$this->set_vat_number( $value );
2749
+     * Set the invoice sub total.
2750
+     *
2751
+     * @since 1.0.19
2752
+     * @param  float $value sub total.
2753
+     */
2754
+    public function set_subtotal( $value ) {
2755
+        $this->set_prop( 'subtotal', max( 0, $value ) );
2603 2756
     }
2604 2757
 
2605 2758
     /**
2606
-	 * Set the customer's vat rate.
2607
-	 *
2608
-	 * @since 1.0.19
2609
-	 * @param  string $value var rate.
2610
-	 */
2611
-	public function set_vat_rate( $value ) {
2612
-		$this->set_prop( 'vat_rate', $value );
2759
+     * Set the invoice total.
2760
+     *
2761
+     * @since 1.0.19
2762
+     * @param  float $value sub total.
2763
+     */
2764
+    public function set_total( $value ) {
2765
+        $this->set_prop( 'total', max( 0, $value ) );
2613 2766
     }
2614 2767
 
2615 2768
     /**
2616
-	 * Alias of self::set_vat_rate().
2617
-	 *
2618
-	 * @since 1.0.19
2619
-	 * @param  string $value var number.
2620
-	 */
2621
-	public function set_user_vat_rate( $value ) {
2622
-		$this->set_vat_rate( $value );
2623
-    }
2624
-
2625
-    /**
2626
-	 * Alias of self::set_vat_rate().
2627
-	 *
2628
-	 * @since 1.0.19
2629
-	 * @param  string $value var number.
2630
-	 */
2631
-	public function set_customer_vat_rate( $value ) {
2632
-		$this->set_vat_rate( $value );
2633
-    }
2634
-
2635
-    /**
2636
-	 * Set the customer's address.
2637
-	 *
2638
-	 * @since 1.0.19
2639
-	 * @param  string $value address.
2640
-	 */
2641
-	public function set_address( $value ) {
2642
-		$this->set_prop( 'address', $value );
2643
-    }
2644
-
2645
-    /**
2646
-	 * Alias of self::set_address().
2647
-	 *
2648
-	 * @since 1.0.19
2649
-	 * @param  string $value address.
2650
-	 */
2651
-	public function set_user_address( $value ) {
2652
-		$this->set_address( $value );
2653
-    }
2654
-
2655
-    /**
2656
-	 * Alias of self::set_address().
2657
-	 *
2658
-	 * @since 1.0.19
2659
-	 * @param  string $value address.
2660
-	 */
2661
-	public function set_customer_address( $value ) {
2662
-		$this->set_address( $value );
2663
-    }
2664
-
2665
-    /**
2666
-	 * Set whether the customer has viewed the invoice or not.
2667
-	 *
2668
-	 * @since 1.0.19
2669
-	 * @param  int|bool $value confirmed.
2670
-	 */
2671
-	public function set_is_viewed( $value ) {
2672
-		$this->set_prop( 'is_viewed', $value );
2673
-	}
2674
-
2675
-	/**
2676
-	 * Set extra email recipients.
2677
-	 *
2678
-	 * @since 1.0.19
2679
-	 * @param  string $value email recipients.
2680
-	 */
2681
-	public function set_email_cc( $value ) {
2682
-		$this->set_prop( 'email_cc', $value );
2683
-	}
2684
-
2685
-	/**
2686
-	 * Set the invoice template.
2687
-	 *
2688
-	 * @since 1.0.19
2689
-	 * @param  string $value template.
2690
-	 */
2691
-	public function set_template( $value ) {
2692
-		if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2693
-			$this->set_prop( 'template', $value );
2694
-		}
2695
-	}
2696
-
2697
-	/**
2698
-	 * Set the invoice source.
2699
-	 *
2700
-	 * @since 1.0.19
2701
-	 * @param  string $value source.
2702
-	 * @deprecated
2703
-	 */
2704
-	public function created_via( $value ) {
2705
-		$this->set_created_via( sanitize_text_field( $value ) );
2706
-	}
2707
-
2708
-	/**
2709
-	 * Set the invoice source.
2710
-	 *
2711
-	 * @since 1.0.19
2712
-	 * @param  string $value source.
2713
-	 */
2714
-	public function set_created_via( $value ) {
2715
-		$this->set_prop( 'created_via', sanitize_text_field( $value ) );
2716
-	}
2717
-
2718
-	/**
2719
-	 * Set the customer's address confirmed status.
2720
-	 *
2721
-	 * @since 1.0.19
2722
-	 * @param  int|bool $value confirmed.
2723
-	 */
2724
-	public function set_address_confirmed( $value ) {
2725
-		$this->set_prop( 'address_confirmed', $value );
2726
-    }
2727
-
2728
-    /**
2729
-	 * Alias of self::set_address_confirmed().
2730
-	 *
2731
-	 * @since 1.0.19
2732
-	 * @param  int|bool $value confirmed.
2733
-	 */
2734
-	public function set_user_address_confirmed( $value ) {
2735
-		$this->set_address_confirmed( $value );
2736
-    }
2737
-
2738
-    /**
2739
-	 * Alias of self::set_address_confirmed().
2740
-	 *
2741
-	 * @since 1.0.19
2742
-	 * @param  int|bool $value confirmed.
2743
-	 */
2744
-	public function set_customer_address_confirmed( $value ) {
2745
-		$this->set_address_confirmed( $value );
2746
-    }
2747
-
2748
-    /**
2749
-	 * Set the invoice sub total.
2750
-	 *
2751
-	 * @since 1.0.19
2752
-	 * @param  float $value sub total.
2753
-	 */
2754
-	public function set_subtotal( $value ) {
2755
-		$this->set_prop( 'subtotal', max( 0, $value ) );
2756
-	}
2757
-
2758
-	/**
2759
-	 * Set the invoice total.
2760
-	 *
2761
-	 * @since 1.0.19
2762
-	 * @param  float $value sub total.
2763
-	 */
2764
-	public function set_total( $value ) {
2765
-		$this->set_prop( 'total', max( 0, $value ) );
2766
-    }
2767
-
2768
-    /**
2769
-	 * Set the invoice discount amount.
2770
-	 *
2771
-	 * @since 1.0.19
2772
-	 * @param  float $value discount total.
2773
-	 */
2774
-	public function set_total_discount( $value ) {
2775
-		$this->set_prop( 'total_discount', max( 0, $value ) );
2769
+     * Set the invoice discount amount.
2770
+     *
2771
+     * @since 1.0.19
2772
+     * @param  float $value discount total.
2773
+     */
2774
+    public function set_total_discount( $value ) {
2775
+        $this->set_prop( 'total_discount', max( 0, $value ) );
2776 2776
     }
2777 2777
 
2778 2778
     /**
2779
-	 * Alias of self::set_total_discount().
2780
-	 *
2781
-	 * @since 1.0.19
2782
-	 * @param  float $value discount total.
2783
-	 */
2784
-	public function set_discount( $value ) {
2785
-		$this->set_total_discount( $value );
2779
+     * Alias of self::set_total_discount().
2780
+     *
2781
+     * @since 1.0.19
2782
+     * @param  float $value discount total.
2783
+     */
2784
+    public function set_discount( $value ) {
2785
+        $this->set_total_discount( $value );
2786 2786
     }
2787 2787
 
2788 2788
     /**
2789
-	 * Set the invoice tax amount.
2790
-	 *
2791
-	 * @since 1.0.19
2792
-	 * @param  float $value tax total.
2793
-	 */
2794
-	public function set_total_tax( $value ) {
2795
-		$this->set_prop( 'total_tax', max( 0, $value ) );
2789
+     * Set the invoice tax amount.
2790
+     *
2791
+     * @since 1.0.19
2792
+     * @param  float $value tax total.
2793
+     */
2794
+    public function set_total_tax( $value ) {
2795
+        $this->set_prop( 'total_tax', max( 0, $value ) );
2796 2796
     }
2797 2797
 
2798 2798
     /**
2799
-	 * Alias of self::set_total_tax().
2800
-	 *
2801
-	 * @since 1.0.19
2802
-	 * @param  float $value tax total.
2803
-	 */
2804
-	public function set_tax_total( $value ) {
2805
-		$this->set_total_tax( $value );
2799
+     * Alias of self::set_total_tax().
2800
+     *
2801
+     * @since 1.0.19
2802
+     * @param  float $value tax total.
2803
+     */
2804
+    public function set_tax_total( $value ) {
2805
+        $this->set_total_tax( $value );
2806 2806
     }
2807 2807
 
2808 2808
     /**
2809
-	 * Set the invoice fees amount.
2810
-	 *
2811
-	 * @since 1.0.19
2812
-	 * @param  float $value fees total.
2813
-	 */
2814
-	public function set_total_fees( $value ) {
2815
-		$this->set_prop( 'total_fees', max( 0, $value ) );
2809
+     * Set the invoice fees amount.
2810
+     *
2811
+     * @since 1.0.19
2812
+     * @param  float $value fees total.
2813
+     */
2814
+    public function set_total_fees( $value ) {
2815
+        $this->set_prop( 'total_fees', max( 0, $value ) );
2816 2816
     }
2817 2817
 
2818 2818
     /**
2819
-	 * Alias of self::set_total_fees().
2820
-	 *
2821
-	 * @since 1.0.19
2822
-	 * @param  float $value fees total.
2823
-	 */
2824
-	public function set_fees_total( $value ) {
2825
-		$this->set_total_fees( $value );
2819
+     * Alias of self::set_total_fees().
2820
+     *
2821
+     * @since 1.0.19
2822
+     * @param  float $value fees total.
2823
+     */
2824
+    public function set_fees_total( $value ) {
2825
+        $this->set_total_fees( $value );
2826 2826
     }
2827 2827
 
2828 2828
     /**
2829
-	 * Set the invoice fees.
2830
-	 *
2831
-	 * @since 1.0.19
2832
-	 * @param  array $value fees.
2833
-	 */
2834
-	public function set_fees( $value ) {
2829
+     * Set the invoice fees.
2830
+     *
2831
+     * @since 1.0.19
2832
+     * @param  array $value fees.
2833
+     */
2834
+    public function set_fees( $value ) {
2835 2835
 
2836
-		if ( ! is_array( $value ) ) {
2837
-			$value = array();
2838
-		}
2836
+        if ( ! is_array( $value ) ) {
2837
+            $value = array();
2838
+        }
2839 2839
 
2840
-		$this->set_prop( 'fees', $value );
2840
+        $this->set_prop( 'fees', $value );
2841 2841
 
2842 2842
     }
2843 2843
 
2844 2844
     /**
2845
-	 * Set the invoice taxes.
2846
-	 *
2847
-	 * @since 1.0.19
2848
-	 * @param  array $value taxes.
2849
-	 */
2850
-	public function set_taxes( $value ) {
2845
+     * Set the invoice taxes.
2846
+     *
2847
+     * @since 1.0.19
2848
+     * @param  array $value taxes.
2849
+     */
2850
+    public function set_taxes( $value ) {
2851 2851
 
2852
-		if ( ! is_array( $value ) ) {
2853
-			$value = array();
2854
-		}
2852
+        if ( ! is_array( $value ) ) {
2853
+            $value = array();
2854
+        }
2855 2855
 
2856
-		$this->set_prop( 'taxes', $value );
2856
+        $this->set_prop( 'taxes', $value );
2857 2857
 
2858 2858
     }
2859 2859
 
2860 2860
     /**
2861
-	 * Set the invoice discounts.
2862
-	 *
2863
-	 * @since 1.0.19
2864
-	 * @param  array $value discounts.
2865
-	 */
2866
-	public function set_discounts( $value ) {
2861
+     * Set the invoice discounts.
2862
+     *
2863
+     * @since 1.0.19
2864
+     * @param  array $value discounts.
2865
+     */
2866
+    public function set_discounts( $value ) {
2867 2867
 
2868
-		if ( ! is_array( $value ) ) {
2869
-			$value = array();
2870
-		}
2868
+        if ( ! is_array( $value ) ) {
2869
+            $value = array();
2870
+        }
2871 2871
 
2872
-		$this->set_prop( 'discounts', $value );
2872
+        $this->set_prop( 'discounts', $value );
2873 2873
     }
2874 2874
 
2875 2875
     /**
2876
-	 * Set the invoice items.
2877
-	 *
2878
-	 * @since 1.0.19
2879
-	 * @param  GetPaid_Form_Item[] $value items.
2880
-	 */
2881
-	public function set_items( $value ) {
2876
+     * Set the invoice items.
2877
+     *
2878
+     * @since 1.0.19
2879
+     * @param  GetPaid_Form_Item[] $value items.
2880
+     */
2881
+    public function set_items( $value ) {
2882 2882
 
2883 2883
         // Remove existing items.
2884 2884
         $this->set_prop( 'items', array() );
2885
-		$this->recurring_item = null;
2885
+        $this->recurring_item = null;
2886 2886
 
2887 2887
         // Ensure that we have an array.
2888 2888
         if ( ! is_array( $value ) ) {
@@ -2896,95 +2896,95 @@  discard block
 block discarded – undo
2896 2896
     }
2897 2897
 
2898 2898
     /**
2899
-	 * Set the payment form.
2900
-	 *
2901
-	 * @since 1.0.19
2902
-	 * @param  int $value payment form.
2903
-	 */
2904
-	public function set_payment_form( $value ) {
2905
-		$this->set_prop( 'payment_form', $value );
2899
+     * Set the payment form.
2900
+     *
2901
+     * @since 1.0.19
2902
+     * @param  int $value payment form.
2903
+     */
2904
+    public function set_payment_form( $value ) {
2905
+        $this->set_prop( 'payment_form', $value );
2906 2906
     }
2907 2907
 
2908 2908
     /**
2909
-	 * Set the submission id.
2910
-	 *
2911
-	 * @since 1.0.19
2912
-	 * @param  string $value submission id.
2913
-	 */
2914
-	public function set_submission_id( $value ) {
2915
-		$this->set_prop( 'submission_id', $value );
2909
+     * Set the submission id.
2910
+     *
2911
+     * @since 1.0.19
2912
+     * @param  string $value submission id.
2913
+     */
2914
+    public function set_submission_id( $value ) {
2915
+        $this->set_prop( 'submission_id', $value );
2916 2916
     }
2917 2917
 
2918 2918
     /**
2919
-	 * Set the discount code.
2920
-	 *
2921
-	 * @since 1.0.19
2922
-	 * @param  string $value discount code.
2923
-	 */
2924
-	public function set_discount_code( $value ) {
2925
-		$this->set_prop( 'discount_code', sanitize_text_field( $value ) );
2919
+     * Set the discount code.
2920
+     *
2921
+     * @since 1.0.19
2922
+     * @param  string $value discount code.
2923
+     */
2924
+    public function set_discount_code( $value ) {
2925
+        $this->set_prop( 'discount_code', sanitize_text_field( $value ) );
2926 2926
     }
2927 2927
 
2928 2928
     /**
2929
-	 * Set the gateway.
2930
-	 *
2931
-	 * @since 1.0.19
2932
-	 * @param  string $value gateway.
2933
-	 */
2934
-	public function set_gateway( $value ) {
2935
-		$this->set_prop( 'gateway', $value );
2929
+     * Set the gateway.
2930
+     *
2931
+     * @since 1.0.19
2932
+     * @param  string $value gateway.
2933
+     */
2934
+    public function set_gateway( $value ) {
2935
+        $this->set_prop( 'gateway', $value );
2936 2936
     }
2937 2937
 
2938 2938
     /**
2939
-	 * Set the transaction id.
2940
-	 *
2941
-	 * @since 1.0.19
2942
-	 * @param  string $value transaction id.
2943
-	 */
2944
-	public function set_transaction_id( $value ) {
2945
-		if ( ! empty( $value ) ) {
2946
-			$this->set_prop( 'transaction_id', $value );
2947
-		}
2939
+     * Set the transaction id.
2940
+     *
2941
+     * @since 1.0.19
2942
+     * @param  string $value transaction id.
2943
+     */
2944
+    public function set_transaction_id( $value ) {
2945
+        if ( ! empty( $value ) ) {
2946
+            $this->set_prop( 'transaction_id', $value );
2947
+        }
2948 2948
     }
2949 2949
 
2950 2950
     /**
2951
-	 * Set the currency id.
2952
-	 *
2953
-	 * @since 1.0.19
2954
-	 * @param  string $value currency id.
2955
-	 */
2956
-	public function set_currency( $value ) {
2957
-		$this->set_prop( 'currency', $value );
2951
+     * Set the currency id.
2952
+     *
2953
+     * @since 1.0.19
2954
+     * @param  string $value currency id.
2955
+     */
2956
+    public function set_currency( $value ) {
2957
+        $this->set_prop( 'currency', $value );
2958 2958
     }
2959 2959
 
2960
-	/**
2961
-	 * Set whether to disable taxes.
2962
-	 *
2963
-	 * @since 1.0.19
2964
-	 * @param  bool $value value.
2965
-	 */
2966
-	public function set_disable_taxes( $value ) {
2967
-		$this->set_prop( 'disable_taxes', (bool) $value );
2968
-	}
2960
+    /**
2961
+     * Set whether to disable taxes.
2962
+     *
2963
+     * @since 1.0.19
2964
+     * @param  bool $value value.
2965
+     */
2966
+    public function set_disable_taxes( $value ) {
2967
+        $this->set_prop( 'disable_taxes', (bool) $value );
2968
+    }
2969 2969
 
2970 2970
     /**
2971
-	 * Set the subscription id.
2972
-	 *
2973
-	 * @since 1.0.19
2974
-	 * @param  string $value subscription id.
2975
-	 */
2976
-	public function set_subscription_id( $value ) {
2977
-		$this->set_prop( 'subscription_id', $value );
2978
-	}
2971
+     * Set the subscription id.
2972
+     *
2973
+     * @since 1.0.19
2974
+     * @param  string $value subscription id.
2975
+     */
2976
+    public function set_subscription_id( $value ) {
2977
+        $this->set_prop( 'subscription_id', $value );
2978
+    }
2979 2979
 	
2980
-	/**
2981
-	 * Set the remote subscription id.
2982
-	 *
2983
-	 * @since 1.0.19
2984
-	 * @param  string $value subscription id.
2985
-	 */
2986
-	public function set_remote_subscription_id( $value ) {
2987
-		$this->set_prop( 'remote_subscription_id', $value );
2980
+    /**
2981
+     * Set the remote subscription id.
2982
+     *
2983
+     * @since 1.0.19
2984
+     * @param  string $value subscription id.
2985
+     */
2986
+    public function set_remote_subscription_id( $value ) {
2987
+        $this->set_prop( 'remote_subscription_id', $value );
2988 2988
     }
2989 2989
 
2990 2990
     /*
@@ -3023,24 +3023,24 @@  discard block
 block discarded – undo
3023 3023
      */
3024 3024
     public function is_taxable() {
3025 3025
         return ! $this->get_disable_taxes();
3026
-	}
3026
+    }
3027 3027
 
3028
-	/**
3029
-	 * @deprecated
3030
-	 */
3031
-	public function has_vat() {
3028
+    /**
3029
+     * @deprecated
3030
+     */
3031
+    public function has_vat() {
3032 3032
         return $this->is_taxable();
3033
-	}
3033
+    }
3034 3034
 
3035
-	/**
3036
-	 * Checks to see if the invoice requires payment.
3037
-	 */
3038
-	public function is_free() {
3035
+    /**
3036
+     * Checks to see if the invoice requires payment.
3037
+     */
3038
+    public function is_free() {
3039 3039
         $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 );
3040 3040
 
3041
-		if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) {
3042
-			$is_free = false;
3043
-		}
3041
+        if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) {
3042
+            $is_free = false;
3043
+        }
3044 3044
 
3045 3045
         return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
3046 3046
     }
@@ -3051,46 +3051,46 @@  discard block
 block discarded – undo
3051 3051
     public function is_paid() {
3052 3052
         $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
3053 3053
         return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
3054
-	}
3054
+    }
3055 3055
 
3056
-	/**
3056
+    /**
3057 3057
      * Checks if the invoice needs payment.
3058 3058
      */
3059
-	public function needs_payment() {
3060
-		$needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free();
3059
+    public function needs_payment() {
3060
+        $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free();
3061 3061
         return apply_filters( 'wpinv_needs_payment', $needs_payment, $this );
3062 3062
     }
3063 3063
   
3064
-	/**
3064
+    /**
3065 3065
      * Checks if the invoice is refunded.
3066 3066
      */
3067
-	public function is_refunded() {
3067
+    public function is_refunded() {
3068 3068
         $is_refunded = $this->has_status( 'wpi-refunded' );
3069 3069
         return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
3070
-	}
3070
+    }
3071 3071
 
3072
-	/**
3072
+    /**
3073 3073
      * Checks if the invoice is held.
3074 3074
      */
3075
-	public function is_held() {
3075
+    public function is_held() {
3076 3076
         $is_held = $this->has_status( 'wpi-onhold' );
3077 3077
         return apply_filters( 'wpinv_invoice_is_held', $is_held, $this );
3078
-	}
3078
+    }
3079 3079
 
3080
-	/**
3080
+    /**
3081 3081
      * Checks if the invoice is due.
3082 3082
      */
3083
-	public function is_due() {
3084
-		$due_date = $this->get_due_date();
3085
-		return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date );
3086
-	}
3083
+    public function is_due() {
3084
+        $due_date = $this->get_due_date();
3085
+        return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date );
3086
+    }
3087 3087
 
3088
-	/**
3088
+    /**
3089 3089
      * Checks if the invoice is draft.
3090 3090
      */
3091
-	public function is_draft() {
3091
+    public function is_draft() {
3092 3092
         return $this->has_status( 'draft, auto-draft' );
3093
-	}
3093
+    }
3094 3094
 
3095 3095
     /**
3096 3096
      * Checks if the invoice has a given status.
@@ -3098,9 +3098,9 @@  discard block
 block discarded – undo
3098 3098
     public function has_status( $status ) {
3099 3099
         $status = wpinv_parse_list( $status );
3100 3100
         return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status );
3101
-	}
3101
+    }
3102 3102
 
3103
-	/**
3103
+    /**
3104 3104
      * Checks if the invoice is of a given type.
3105 3105
      */
3106 3106
     public function is_type( $type ) {
@@ -3123,25 +3123,25 @@  discard block
 block discarded – undo
3123 3123
      */
3124 3124
     public function has_free_trial() {
3125 3125
         return $this->is_recurring() && 0 == $this->get_initial_total();
3126
-	}
3126
+    }
3127 3127
 
3128
-	/**
3128
+    /**
3129 3129
      * @deprecated
3130 3130
      */
3131 3131
     public function is_free_trial() {
3132 3132
         $this->has_free_trial();
3133 3133
     }
3134 3134
 
3135
-	/**
3135
+    /**
3136 3136
      * Check if the initial payment if 0.
3137 3137
      *
3138 3138
      */
3139
-	public function is_initial_free() {
3139
+    public function is_initial_free() {
3140 3140
         $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 );
3141 3141
         return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this );
3142 3142
     }
3143 3143
 	
3144
-	/**
3144
+    /**
3145 3145
      * Check if the recurring item has a free trial.
3146 3146
      *
3147 3147
      */
@@ -3154,21 +3154,21 @@  discard block
 block discarded – undo
3154 3154
 
3155 3155
         $item = $this->get_recurring( true );
3156 3156
         return $item->has_free_trial();
3157
-	}
3157
+    }
3158 3158
 
3159
-	/**
3159
+    /**
3160 3160
      * Check if the free trial is a result of a discount.
3161 3161
      */
3162 3162
     public function is_free_trial_from_discount() {
3163
-		return $this->has_free_trial() && ! $this->item_has_free_trial();
3164
-	}
3163
+        return $this->has_free_trial() && ! $this->item_has_free_trial();
3164
+    }
3165 3165
 	
3166
-	/**
3166
+    /**
3167 3167
      * @deprecated
3168 3168
      */
3169 3169
     public function discount_first_payment_only() {
3170 3170
 
3171
-		$discount = wpinv_get_discount_obj( $this->get_discount_code() );
3171
+        $discount = wpinv_get_discount_obj( $this->get_discount_code() );
3172 3172
         if ( ! $discount->exists() || ! $this->is_recurring() ) {
3173 3173
             return true;
3174 3174
         }
@@ -3193,143 +3193,143 @@  discard block
 block discarded – undo
3193 3193
      */
3194 3194
     public function add_item( $item ) {
3195 3195
 
3196
-		if ( is_array( $item ) ) {
3197
-			$item = $this->process_array_item( $item );
3198
-		}
3196
+        if ( is_array( $item ) ) {
3197
+            $item = $this->process_array_item( $item );
3198
+        }
3199 3199
 
3200
-		if ( is_numeric( $item ) ) {
3201
-			$item = new GetPaid_Form_Item( $item );
3202
-		}
3200
+        if ( is_numeric( $item ) ) {
3201
+            $item = new GetPaid_Form_Item( $item );
3202
+        }
3203 3203
 
3204 3204
         // Make sure that it is available for purchase.
3205
-		if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
3206
-			return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
3205
+        if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
3206
+            return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
3207 3207
         }
3208 3208
 
3209 3209
         // Do we have a recurring item?
3210
-		if ( $item->is_recurring() ) {
3211
-			$this->recurring_item = $item->get_id();
3210
+        if ( $item->is_recurring() ) {
3211
+            $this->recurring_item = $item->get_id();
3212 3212
         }
3213 3213
 
3214 3214
         // Invoice id.
3215 3215
         $item->invoice_id = (int) $this->get_id();
3216 3216
 
3217
-		// Remove duplicates.
3218
-		$this->remove_item( $item->get_id() );
3217
+        // Remove duplicates.
3218
+        $this->remove_item( $item->get_id() );
3219 3219
 
3220
-		// Retrieve all items.
3220
+        // Retrieve all items.
3221 3221
         $items   = $this->get_items();
3222 3222
 
3223
-		// Add new item.
3223
+        // Add new item.
3224 3224
         $items[] = $item;
3225 3225
 
3226 3226
         $this->set_prop( 'items', $items );
3227 3227
 
3228
-		return true;
3229
-	}
3228
+        return true;
3229
+    }
3230 3230
 
3231
-	/**
3232
-	 * Converts an array to an item.
3233
-	 *
3234
-	 * @since 1.0.19
3235
-	 * @return GetPaid_Form_Item
3236
-	 */
3237
-	protected function process_array_item( $array ) {
3231
+    /**
3232
+     * Converts an array to an item.
3233
+     *
3234
+     * @since 1.0.19
3235
+     * @return GetPaid_Form_Item
3236
+     */
3237
+    protected function process_array_item( $array ) {
3238 3238
 
3239
-		$item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0;
3240
-		$item    = new GetPaid_Form_Item( $item_id );
3239
+        $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0;
3240
+        $item    = new GetPaid_Form_Item( $item_id );
3241 3241
 
3242
-		// Set item data.
3243
-		foreach ( array( 'name', 'price', 'description' ) as $key ) {
3244
-			if ( isset( $array[ "item_$key" ] ) ) {
3245
-				$method = "set_$key";
3246
-				$item->$method( $array[ "item_$key" ] );
3247
-			}
3248
-		}
3242
+        // Set item data.
3243
+        foreach ( array( 'name', 'price', 'description' ) as $key ) {
3244
+            if ( isset( $array[ "item_$key" ] ) ) {
3245
+                $method = "set_$key";
3246
+                $item->$method( $array[ "item_$key" ] );
3247
+            }
3248
+        }
3249 3249
 
3250
-		if ( isset( $array['quantity'] ) ) {
3251
-			$item->set_quantity( $array['quantity'] );
3252
-		}
3250
+        if ( isset( $array['quantity'] ) ) {
3251
+            $item->set_quantity( $array['quantity'] );
3252
+        }
3253 3253
 
3254
-		// Set item meta.
3255
-		if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) {
3256
-			$item->set_item_meta( $array['meta'] );
3257
-		}
3254
+        // Set item meta.
3255
+        if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) {
3256
+            $item->set_item_meta( $array['meta'] );
3257
+        }
3258 3258
 
3259
-		return $item;
3259
+        return $item;
3260 3260
 
3261
-	}
3261
+    }
3262 3262
 
3263 3263
     /**
3264
-	 * Retrieves a specific item.
3265
-	 *
3266
-	 * @since 1.0.19
3267
-	 * @return GetPaid_Form_Item|null
3268
-	 */
3269
-	public function get_item( $item_id ) {
3264
+     * Retrieves a specific item.
3265
+     *
3266
+     * @since 1.0.19
3267
+     * @return GetPaid_Form_Item|null
3268
+     */
3269
+    public function get_item( $item_id ) {
3270 3270
 
3271
-		foreach ( $this->get_items() as $item ) {
3272
-			if ( (int) $item_id == $item->get_id() ) {
3273
-				return $item;
3274
-			}
3275
-		}
3271
+        foreach ( $this->get_items() as $item ) {
3272
+            if ( (int) $item_id == $item->get_id() ) {
3273
+                return $item;
3274
+            }
3275
+        }
3276 3276
 
3277
-		return null;
3277
+        return null;
3278 3278
     }
3279 3279
 
3280 3280
     /**
3281
-	 * Removes a specific item.
3282
-	 *
3283
-	 * @since 1.0.19
3284
-	 */
3285
-	public function remove_item( $item_id ) {
3286
-		$items   = $this->get_items();
3287
-		$item_id = (int) $item_id;
3281
+     * Removes a specific item.
3282
+     *
3283
+     * @since 1.0.19
3284
+     */
3285
+    public function remove_item( $item_id ) {
3286
+        $items   = $this->get_items();
3287
+        $item_id = (int) $item_id;
3288 3288
 
3289
-		foreach ( $items as $index => $item ) {
3290
-			if ( (int) $item_id == $item->get_id() ) {
3291
-				unset( $items[ $index ] );
3292
-				$this->set_prop( 'items', $items );
3289
+        foreach ( $items as $index => $item ) {
3290
+            if ( (int) $item_id == $item->get_id() ) {
3291
+                unset( $items[ $index ] );
3292
+                $this->set_prop( 'items', $items );
3293 3293
 
3294
-				if ( $item_id == $this->recurring_item ) {
3295
-					$this->recurring_item = null;
3296
-				}
3294
+                if ( $item_id == $this->recurring_item ) {
3295
+                    $this->recurring_item = null;
3296
+                }
3297 3297
 
3298
-			}
3299
-		}
3298
+            }
3299
+        }
3300 3300
 
3301 3301
     }
3302 3302
 
3303 3303
     /**
3304
-	 * Adds a fee to the invoice.
3305
-	 *
3306
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
3307
-	 * @since 1.0.19
3308
-	 */
3304
+     * Adds a fee to the invoice.
3305
+     *
3306
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
3307
+     * @since 1.0.19
3308
+     */
3309 3309
     public function add_fee( $fee ) {
3310 3310
 
3311
-		$fees                 = $this->get_fees();
3312
-		$fees[ $fee['name'] ] = $fee;
3313
-		$this->set_prop( 'fees', $fees );
3311
+        $fees                 = $this->get_fees();
3312
+        $fees[ $fee['name'] ] = $fee;
3313
+        $this->set_prop( 'fees', $fees );
3314 3314
 
3315 3315
     }
3316 3316
 
3317 3317
     /**
3318
-	 * Retrieves a specific fee.
3319
-	 *
3320
-	 * @since 1.0.19
3321
-	 */
3322
-	public function get_fee( $fee ) {
3318
+     * Retrieves a specific fee.
3319
+     *
3320
+     * @since 1.0.19
3321
+     */
3322
+    public function get_fee( $fee ) {
3323 3323
         $fees = $this->get_fees();
3324
-		return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3324
+        return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3325 3325
     }
3326 3326
 
3327 3327
     /**
3328
-	 * Removes a specific fee.
3329
-	 *
3330
-	 * @since 1.0.19
3331
-	 */
3332
-	public function remove_fee( $fee ) {
3328
+     * Removes a specific fee.
3329
+     *
3330
+     * @since 1.0.19
3331
+     */
3332
+    public function remove_fee( $fee ) {
3333 3333
         $fees = $this->get_fees();
3334 3334
         if ( isset( $fees[ $fee ] ) ) {
3335 3335
             unset( $fees[ $fee ] );
@@ -3337,55 +3337,55 @@  discard block
 block discarded – undo
3337 3337
         }
3338 3338
     }
3339 3339
 
3340
-	/**
3341
-	 * Adds a discount to the invoice.
3342
-	 *
3343
-	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
3344
-	 * @since 1.0.19
3345
-	 */
3346
-	public function add_discount( $discount ) {
3340
+    /**
3341
+     * Adds a discount to the invoice.
3342
+     *
3343
+     * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
3344
+     * @since 1.0.19
3345
+     */
3346
+    public function add_discount( $discount ) {
3347 3347
 
3348
-		$discounts = $this->get_discounts();
3349
-		$discounts[ $discount['name'] ] = $discount;
3350
-		$this->set_prop( 'discounts', $discounts );
3348
+        $discounts = $this->get_discounts();
3349
+        $discounts[ $discount['name'] ] = $discount;
3350
+        $this->set_prop( 'discounts', $discounts );
3351 3351
 
3352
-	}
3352
+    }
3353 3353
 
3354 3354
     /**
3355
-	 * Retrieves a specific discount.
3356
-	 *
3357
-	 * @since 1.0.19
3358
-	 * @return float
3359
-	 */
3360
-	public function get_discount( $discount = false ) {
3355
+     * Retrieves a specific discount.
3356
+     *
3357
+     * @since 1.0.19
3358
+     * @return float
3359
+     */
3360
+    public function get_discount( $discount = false ) {
3361 3361
 
3362
-		// Backwards compatibilty.
3363
-		if ( empty( $discount ) ) {
3364
-			return $this->get_total_discount();
3365
-		}
3362
+        // Backwards compatibilty.
3363
+        if ( empty( $discount ) ) {
3364
+            return $this->get_total_discount();
3365
+        }
3366 3366
 
3367 3367
         $discounts = $this->get_discounts();
3368
-		return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3368
+        return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3369 3369
     }
3370 3370
 
3371 3371
     /**
3372
-	 * Removes a specific discount.
3373
-	 *
3374
-	 * @since 1.0.19
3375
-	 */
3376
-	public function remove_discount( $discount ) {
3372
+     * Removes a specific discount.
3373
+     *
3374
+     * @since 1.0.19
3375
+     */
3376
+    public function remove_discount( $discount ) {
3377 3377
         $discounts = $this->get_discounts();
3378 3378
         if ( isset( $discounts[ $discount ] ) ) {
3379 3379
             unset( $discounts[ $discount ] );
3380 3380
             $this->set_prop( 'discounts', $discounts );
3381 3381
         }
3382 3382
 
3383
-		if ( 'discount_code' == $discount ) {
3384
-			foreach ( $this->get_items() as $item ) {
3385
-				$item->item_discount           = 0;
3386
-				$item->recurring_item_discount = 0;
3387
-			}
3388
-		}
3383
+        if ( 'discount_code' == $discount ) {
3384
+            foreach ( $this->get_items() as $item ) {
3385
+                $item->item_discount           = 0;
3386
+                $item->recurring_item_discount = 0;
3387
+            }
3388
+        }
3389 3389
 
3390 3390
     }
3391 3391
 
@@ -3398,34 +3398,34 @@  discard block
 block discarded – undo
3398 3398
         if ( $this->is_taxable() ) {
3399 3399
 
3400 3400
             $taxes                 = $this->get_taxes();
3401
-			$taxes[ $tax['name'] ] = $tax;
3402
-			$this->set_prop( 'taxes', $tax );
3401
+            $taxes[ $tax['name'] ] = $tax;
3402
+            $this->set_prop( 'taxes', $tax );
3403 3403
 
3404 3404
         }
3405 3405
     }
3406 3406
 
3407 3407
     /**
3408
-	 * Retrieves a specific tax.
3409
-	 *
3410
-	 * @since 1.0.19
3411
-	 */
3412
-	public function get_tax( $tax = null ) {
3408
+     * Retrieves a specific tax.
3409
+     *
3410
+     * @since 1.0.19
3411
+     */
3412
+    public function get_tax( $tax = null ) {
3413 3413
 
3414
-		// Backwards compatility.
3415
-		if ( empty( $tax ) ) {
3416
-			return $this->get_total_tax();
3417
-		}
3414
+        // Backwards compatility.
3415
+        if ( empty( $tax ) ) {
3416
+            return $this->get_total_tax();
3417
+        }
3418 3418
 
3419 3419
         $taxes = $this->get_taxes();
3420
-		return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3420
+        return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3421 3421
     }
3422 3422
 
3423 3423
     /**
3424
-	 * Removes a specific tax.
3425
-	 *
3426
-	 * @since 1.0.19
3427
-	 */
3428
-	public function remove_tax( $tax ) {
3424
+     * Removes a specific tax.
3425
+     *
3426
+     * @since 1.0.19
3427
+     */
3428
+    public function remove_tax( $tax ) {
3429 3429
         $taxes = $this->get_taxes();
3430 3430
         if ( isset( $taxes[ $tax ] ) ) {
3431 3431
             unset( $taxes[ $tax ] );
@@ -3434,185 +3434,185 @@  discard block
 block discarded – undo
3434 3434
     }
3435 3435
 
3436 3436
     /**
3437
-	 * Recalculates the invoice subtotal.
3438
-	 *
3439
-	 * @since 1.0.19
3440
-	 * @return float The recalculated subtotal
3441
-	 */
3442
-	public function recalculate_subtotal() {
3437
+     * Recalculates the invoice subtotal.
3438
+     *
3439
+     * @since 1.0.19
3440
+     * @return float The recalculated subtotal
3441
+     */
3442
+    public function recalculate_subtotal() {
3443 3443
         $items     = $this->get_items();
3444
-		$subtotal  = 0;
3445
-		$recurring = 0;
3444
+        $subtotal  = 0;
3445
+        $recurring = 0;
3446 3446
 
3447 3447
         foreach ( $items as $item ) {
3448
-			$subtotal  += $item->get_sub_total();
3449
-			$recurring += $item->get_recurring_sub_total();
3448
+            $subtotal  += $item->get_sub_total();
3449
+            $recurring += $item->get_recurring_sub_total();
3450 3450
         }
3451 3451
 
3452
-		if ( wpinv_prices_include_tax() ) {
3453
-			$subtotal  = max( 0, $subtotal - $this->totals['tax']['initial'] );
3454
-			$recurring = max( 0, $recurring - $this->totals['tax']['recurring'] );
3455
-		}
3452
+        if ( wpinv_prices_include_tax() ) {
3453
+            $subtotal  = max( 0, $subtotal - $this->totals['tax']['initial'] );
3454
+            $recurring = max( 0, $recurring - $this->totals['tax']['recurring'] );
3455
+        }
3456 3456
 
3457
-		$current = $this->is_renewal() ? $recurring : $subtotal;
3458
-		$this->set_subtotal( $current );
3457
+        $current = $this->is_renewal() ? $recurring : $subtotal;
3458
+        $this->set_subtotal( $current );
3459 3459
 
3460
-		$this->totals['subtotal'] = array(
3461
-			'initial'   => $subtotal,
3462
-			'recurring' => $recurring,
3463
-		);
3460
+        $this->totals['subtotal'] = array(
3461
+            'initial'   => $subtotal,
3462
+            'recurring' => $recurring,
3463
+        );
3464 3464
 
3465 3465
         return $current;
3466 3466
     }
3467 3467
 
3468 3468
     /**
3469
-	 * Recalculates the invoice discount total.
3470
-	 *
3471
-	 * @since 1.0.19
3472
-	 * @return float The recalculated discount
3473
-	 */
3474
-	public function recalculate_total_discount() {
3469
+     * Recalculates the invoice discount total.
3470
+     *
3471
+     * @since 1.0.19
3472
+     * @return float The recalculated discount
3473
+     */
3474
+    public function recalculate_total_discount() {
3475 3475
         $discounts = $this->get_discounts();
3476
-		$discount  = 0;
3477
-		$recurring = 0;
3476
+        $discount  = 0;
3477
+        $recurring = 0;
3478 3478
 
3479 3479
         foreach ( $discounts as $data ) {
3480
-			$discount  += wpinv_sanitize_amount( $data['initial_discount'] );
3481
-			$recurring += wpinv_sanitize_amount( $data['recurring_discount'] );
3482
-		}
3480
+            $discount  += wpinv_sanitize_amount( $data['initial_discount'] );
3481
+            $recurring += wpinv_sanitize_amount( $data['recurring_discount'] );
3482
+        }
3483 3483
 
3484
-		$current = $this->is_renewal() ? $recurring : $discount;
3484
+        $current = $this->is_renewal() ? $recurring : $discount;
3485 3485
 
3486
-		$this->set_total_discount( $current );
3486
+        $this->set_total_discount( $current );
3487 3487
 
3488
-		$this->totals['discount'] = array(
3489
-			'initial'   => $discount,
3490
-			'recurring' => $recurring,
3491
-		);
3488
+        $this->totals['discount'] = array(
3489
+            'initial'   => $discount,
3490
+            'recurring' => $recurring,
3491
+        );
3492 3492
 
3493
-		return $current;
3493
+        return $current;
3494 3494
 
3495 3495
     }
3496 3496
 
3497 3497
     /**
3498
-	 * Recalculates the invoice tax total.
3499
-	 *
3500
-	 * @since 1.0.19
3501
-	 * @return float The recalculated tax
3502
-	 */
3503
-	public function recalculate_total_tax() {
3498
+     * Recalculates the invoice tax total.
3499
+     *
3500
+     * @since 1.0.19
3501
+     * @return float The recalculated tax
3502
+     */
3503
+    public function recalculate_total_tax() {
3504 3504
 
3505
-		// Maybe disable taxes.
3506
-		$vat_number = $this->get_vat_number();
3507
-		$skip_tax   = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number );
3505
+        // Maybe disable taxes.
3506
+        $vat_number = $this->get_vat_number();
3507
+        $skip_tax   = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number );
3508 3508
 
3509
-		if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
3510
-			$skip_tax = false;
3511
-		}
3509
+        if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
3510
+            $skip_tax = false;
3511
+        }
3512 3512
 
3513
-		if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax   ) {
3513
+        if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax   ) {
3514 3514
 
3515
-			$this->totals['tax'] = array(
3516
-				'initial'   => 0,
3517
-				'recurring' => 0,
3518
-			);
3515
+            $this->totals['tax'] = array(
3516
+                'initial'   => 0,
3517
+                'recurring' => 0,
3518
+            );
3519 3519
 
3520
-			$this->tax_rate = 0;
3520
+            $this->tax_rate = 0;
3521 3521
 
3522
-			$this->set_taxes( array() );
3523
-			$current = 0;
3524
-		} else {
3522
+            $this->set_taxes( array() );
3523
+            $current = 0;
3524
+        } else {
3525 3525
 
3526
-			$item_taxes = array();
3526
+            $item_taxes = array();
3527 3527
 
3528
-			foreach ( $this->get_items() as $item ) {
3529
-				$rates    = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() );
3530
-				$rates    = getpaid_filter_item_tax_rates( $item, $rates );
3531
-				$taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
3532
-				$r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
3533
-				foreach ( $taxes as $name => $amount ) {
3534
-					$recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
3535
-					$tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
3528
+            foreach ( $this->get_items() as $item ) {
3529
+                $rates    = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() );
3530
+                $rates    = getpaid_filter_item_tax_rates( $item, $rates );
3531
+                $taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
3532
+                $r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
3533
+                foreach ( $taxes as $name => $amount ) {
3534
+                    $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
3535
+                    $tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
3536 3536
 
3537
-					if ( ! isset( $item_taxes[ $name ] ) ) {
3538
-						$item_taxes[ $name ] = $tax;
3539
-						continue;
3540
-					}
3537
+                    if ( ! isset( $item_taxes[ $name ] ) ) {
3538
+                        $item_taxes[ $name ] = $tax;
3539
+                        continue;
3540
+                    }
3541 3541
 
3542
-					$item_taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
3543
-					$item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
3542
+                    $item_taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
3543
+                    $item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
3544 3544
 
3545
-				}
3545
+                }
3546 3546
 
3547
-			}
3547
+            }
3548 3548
 
3549
-			$item_taxes = array_replace( $this->get_taxes(), $item_taxes );
3550
-			$this->set_taxes( $item_taxes );
3549
+            $item_taxes = array_replace( $this->get_taxes(), $item_taxes );
3550
+            $this->set_taxes( $item_taxes );
3551 3551
 
3552
-			$initial_tax   = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) );
3553
-			$recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) );
3552
+            $initial_tax   = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) );
3553
+            $recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) );
3554 3554
 
3555
-			$current = $this->is_renewal() ? $recurring_tax : $initial_tax;
3555
+            $current = $this->is_renewal() ? $recurring_tax : $initial_tax;
3556 3556
 
3557
-			$this->totals['tax'] = array(
3558
-				'initial'   => $initial_tax,
3559
-				'recurring' => $recurring_tax,
3560
-			);
3557
+            $this->totals['tax'] = array(
3558
+                'initial'   => $initial_tax,
3559
+                'recurring' => $recurring_tax,
3560
+            );
3561 3561
 
3562
-		}
3562
+        }
3563 3563
 
3564
-		$this->set_total_tax( $current );
3564
+        $this->set_total_tax( $current );
3565 3565
 
3566
-		return $current;
3566
+        return $current;
3567 3567
 
3568 3568
     }
3569 3569
 
3570 3570
     /**
3571
-	 * Recalculates the invoice fees total.
3572
-	 *
3573
-	 * @since 1.0.19
3574
-	 * @return float The recalculated fee
3575
-	 */
3576
-	public function recalculate_total_fees() {
3577
-		$fees      = $this->get_fees();
3578
-		$fee       = 0;
3579
-		$recurring = 0;
3571
+     * Recalculates the invoice fees total.
3572
+     *
3573
+     * @since 1.0.19
3574
+     * @return float The recalculated fee
3575
+     */
3576
+    public function recalculate_total_fees() {
3577
+        $fees      = $this->get_fees();
3578
+        $fee       = 0;
3579
+        $recurring = 0;
3580 3580
 
3581 3581
         foreach ( $fees as $data ) {
3582
-			$fee       += wpinv_sanitize_amount( $data['initial_fee'] );
3583
-			$recurring += wpinv_sanitize_amount( $data['recurring_fee'] );
3584
-		}
3582
+            $fee       += wpinv_sanitize_amount( $data['initial_fee'] );
3583
+            $recurring += wpinv_sanitize_amount( $data['recurring_fee'] );
3584
+        }
3585 3585
 
3586
-		$current = $this->is_renewal() ? $recurring : $fee;
3587
-		$this->set_total_fees( $current );
3586
+        $current = $this->is_renewal() ? $recurring : $fee;
3587
+        $this->set_total_fees( $current );
3588 3588
 
3589
-		$this->totals['fee'] = array(
3590
-			'initial'   => $fee,
3591
-			'recurring' => $recurring,
3592
-		);
3589
+        $this->totals['fee'] = array(
3590
+            'initial'   => $fee,
3591
+            'recurring' => $recurring,
3592
+        );
3593 3593
 
3594 3594
         $this->set_total_fees( $fee );
3595 3595
         return $current;
3596 3596
     }
3597 3597
 
3598 3598
     /**
3599
-	 * Recalculates the invoice total.
3600
-	 *
3601
-	 * @since 1.0.19
3599
+     * Recalculates the invoice total.
3600
+     *
3601
+     * @since 1.0.19
3602 3602
      * @return float The invoice total
3603
-	 */
3604
-	public function recalculate_total() {
3603
+     */
3604
+    public function recalculate_total() {
3605 3605
         $this->recalculate_total_fees();
3606 3606
         $this->recalculate_total_discount();
3607
-		$this->recalculate_total_tax();
3608
-		$this->recalculate_subtotal();
3609
-		$this->set_total( $this->get_total_tax() + $this->get_total_fees() + $this->get_subtotal() - $this->get_total_discount() );
3610
-		return $this->get_total();
3611
-	}
3612
-
3613
-	/**
3614
-	 * @deprecated
3615
-	 */
3607
+        $this->recalculate_total_tax();
3608
+        $this->recalculate_subtotal();
3609
+        $this->set_total( $this->get_total_tax() + $this->get_total_fees() + $this->get_subtotal() - $this->get_total_discount() );
3610
+        return $this->get_total();
3611
+    }
3612
+
3613
+    /**
3614
+     * @deprecated
3615
+     */
3616 3616
     public function recalculate_totals() {
3617 3617
         $this->recalculate_total();
3618 3618
         $this->save( true );
@@ -3630,7 +3630,7 @@  discard block
 block discarded – undo
3630 3630
      * Adds a note to an invoice.
3631 3631
      *
3632 3632
      * @param string $note The note being added.
3633
-	 * @return int|false The new note's ID on success, false on failure.
3633
+     * @return int|false The new note's ID on success, false on failure.
3634 3634
      *
3635 3635
      */
3636 3636
     public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
@@ -3640,21 +3640,21 @@  discard block
 block discarded – undo
3640 3640
             return false;
3641 3641
         }
3642 3642
 
3643
-		$author       = 'System';
3644
-		$author_email = '[email protected]';
3643
+        $author       = 'System';
3644
+        $author_email = '[email protected]';
3645 3645
 
3646
-		// If this is an admin comment or it has been added by the user.
3647
-		if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) {
3648
-			$user         = get_user_by( 'id', get_current_user_id() );
3646
+        // If this is an admin comment or it has been added by the user.
3647
+        if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) {
3648
+            $user         = get_user_by( 'id', get_current_user_id() );
3649 3649
             $author       = $user->display_name;
3650 3650
             $author_email = $user->user_email;
3651
-		}
3651
+        }
3652 3652
 
3653
-		return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type );
3653
+        return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type );
3654 3654
 
3655
-	}
3655
+    }
3656 3656
 
3657
-	/**
3657
+    /**
3658 3658
      * Generates a unique key for the invoice.
3659 3659
      */
3660 3660
     public function generate_key( $string = '' ) {
@@ -3674,113 +3674,113 @@  discard block
 block discarded – undo
3674 3674
             $number = wpinv_get_next_invoice_number( $this->get_post_type() );
3675 3675
         }
3676 3676
 
3677
-		return wpinv_format_invoice_number( $number, $this->get_post_type() );
3678
-
3679
-	}
3680
-
3681
-	/**
3682
-	 * Handle the status transition.
3683
-	 */
3684
-	protected function status_transition() {
3685
-		$status_transition = $this->status_transition;
3686
-
3687
-		// Reset status transition variable.
3688
-		$this->status_transition = false;
3677
+        return wpinv_format_invoice_number( $number, $this->get_post_type() );
3689 3678
 
3690
-		if ( $status_transition ) {
3691
-			try {
3692
-
3693
-				// Fire a hook for the status change.
3694
-				do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition );
3695
-
3696
-				// @deprecated this is deprecated and will be removed in the future.
3697
-				do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3698
-
3699
-				if ( ! empty( $status_transition['from'] ) ) {
3700
-
3701
-					/* translators: 1: old invoice status 2: new invoice status */
3702
-					$transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this  ) );
3703
-
3704
-					// Fire another hook.
3705
-					do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this );
3706
-					do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] );
3707
-
3708
-					// @deprecated this is deprecated and will be removed in the future.
3709
-					do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3710
-
3711
-					// Note the transition occurred.
3712
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] );
3713
-
3714
-					// Work out if this was for a payment, and trigger a payment_status hook instead.
3715
-					if (
3716
-						in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true )
3717
-						&& in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3718
-					) {
3719
-						do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition );
3720
-					}
3721
-
3722
-					// Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead.
3723
-					if (
3724
-						in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3725
-						&& in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true )
3726
-					) {
3727
-						do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition );
3728
-					}
3729
-				} else {
3730
-					/* translators: %s: new invoice status */
3731
-					$transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this  ) );
3732
-
3733
-					// Note the transition occurred.
3734
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3679
+    }
3735 3680
 
3736
-				}
3737
-			} catch ( Exception $e ) {
3738
-				$this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3739
-			}
3740
-		}
3741
-	}
3681
+    /**
3682
+     * Handle the status transition.
3683
+     */
3684
+    protected function status_transition() {
3685
+        $status_transition = $this->status_transition;
3686
+
3687
+        // Reset status transition variable.
3688
+        $this->status_transition = false;
3689
+
3690
+        if ( $status_transition ) {
3691
+            try {
3692
+
3693
+                // Fire a hook for the status change.
3694
+                do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition );
3695
+
3696
+                // @deprecated this is deprecated and will be removed in the future.
3697
+                do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3698
+
3699
+                if ( ! empty( $status_transition['from'] ) ) {
3700
+
3701
+                    /* translators: 1: old invoice status 2: new invoice status */
3702
+                    $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this  ) );
3703
+
3704
+                    // Fire another hook.
3705
+                    do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this );
3706
+                    do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] );
3707
+
3708
+                    // @deprecated this is deprecated and will be removed in the future.
3709
+                    do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3710
+
3711
+                    // Note the transition occurred.
3712
+                    $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] );
3713
+
3714
+                    // Work out if this was for a payment, and trigger a payment_status hook instead.
3715
+                    if (
3716
+                        in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true )
3717
+                        && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3718
+                    ) {
3719
+                        do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition );
3720
+                    }
3721
+
3722
+                    // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead.
3723
+                    if (
3724
+                        in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3725
+                        && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true )
3726
+                    ) {
3727
+                        do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition );
3728
+                    }
3729
+                } else {
3730
+                    /* translators: %s: new invoice status */
3731
+                    $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this  ) );
3732
+
3733
+                    // Note the transition occurred.
3734
+                    $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3735
+
3736
+                }
3737
+            } catch ( Exception $e ) {
3738
+                $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3739
+            }
3740
+        }
3741
+    }
3742 3742
 
3743
-	/**
3744
-	 * Updates an invoice status.
3745
-	 */
3746
-	public function update_status( $new_status = false, $note = '', $manual = false ) {
3743
+    /**
3744
+     * Updates an invoice status.
3745
+     */
3746
+    public function update_status( $new_status = false, $note = '', $manual = false ) {
3747 3747
 
3748
-		// Fires before updating a status.
3749
-		do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) );
3748
+        // Fires before updating a status.
3749
+        do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) );
3750 3750
 
3751
-		// Update the status.
3752
-		$this->set_status( $new_status, $note, $manual );
3751
+        // Update the status.
3752
+        $this->set_status( $new_status, $note, $manual );
3753 3753
 
3754
-		// Save the order.
3755
-		return $this->save();
3754
+        // Save the order.
3755
+        return $this->save();
3756 3756
 
3757
-	}
3757
+    }
3758 3758
 
3759
-	/**
3760
-	 * @deprecated
3761
-	 */
3762
-	public function refresh_item_ids() {
3759
+    /**
3760
+     * @deprecated
3761
+     */
3762
+    public function refresh_item_ids() {
3763 3763
         $item_ids = implode( ',', array_unique( wp_list_pluck( $this->get_cart_details(), 'item_id' ) ) );
3764 3764
         update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids );
3765
-	}
3765
+    }
3766 3766
 
3767
-	/**
3768
-	 * @deprecated
3769
-	 */
3770
-	public function update_items( $temp = false ) {
3767
+    /**
3768
+     * @deprecated
3769
+     */
3770
+    public function update_items( $temp = false ) {
3771 3771
 
3772
-		$this->set_items( $this->get_items() );
3772
+        $this->set_items( $this->get_items() );
3773 3773
 
3774
-		if ( ! $temp ) {
3775
-			$this->save();
3776
-		}
3774
+        if ( ! $temp ) {
3775
+            $this->save();
3776
+        }
3777 3777
 
3778 3778
         return $this;
3779
-	}
3779
+    }
3780 3780
 
3781
-	/**
3782
-	 * @deprecated
3783
-	 */
3781
+    /**
3782
+     * @deprecated
3783
+     */
3784 3784
     public function validate_discount() {
3785 3785
 
3786 3786
         $discount_code = $this->get_discount_code();
@@ -3796,93 +3796,93 @@  discard block
 block discarded – undo
3796 3796
 
3797 3797
     }
3798 3798
 
3799
-	/**
3800
-	 * Refunds an invoice.
3801
-	 */
3799
+    /**
3800
+     * Refunds an invoice.
3801
+     */
3802 3802
     public function refund() {
3803
-		$this->set_status( 'wpi-refunded' );
3803
+        $this->set_status( 'wpi-refunded' );
3804 3804
         $this->save();
3805
-	}
3805
+    }
3806 3806
 
3807
-	/**
3808
-	 * Marks an invoice as paid.
3809
-	 * 
3810
-	 * @param string $transaction_id
3811
-	 */
3807
+    /**
3808
+     * Marks an invoice as paid.
3809
+     * 
3810
+     * @param string $transaction_id
3811
+     */
3812 3812
     public function mark_paid( $transaction_id = null, $note = '' ) {
3813 3813
 
3814
-		// Set the transaction id.
3815
-		if ( empty( $transaction_id ) ) {
3816
-			$transaction_id = $this->generate_key('trans_');
3817
-		}
3814
+        // Set the transaction id.
3815
+        if ( empty( $transaction_id ) ) {
3816
+            $transaction_id = $this->generate_key('trans_');
3817
+        }
3818 3818
 
3819
-		if ( ! $this->get_transaction_id() ) {
3820
-			$this->set_transaction_id( $transaction_id );
3821
-		}
3819
+        if ( ! $this->get_transaction_id() ) {
3820
+            $this->set_transaction_id( $transaction_id );
3821
+        }
3822 3822
 
3823
-		if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) {
3824
-			return $this->save();
3825
-		}
3823
+        if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) {
3824
+            return $this->save();
3825
+        }
3826 3826
 
3827
-		// Set the completed date.
3828
-		$this->set_date_completed( current_time( 'mysql' ) );
3827
+        // Set the completed date.
3828
+        $this->set_date_completed( current_time( 'mysql' ) );
3829 3829
 
3830
-		// Set the new status.
3831
-		$gateway = sanitize_text_field( $this->get_gateway_title() );
3832
-		if ( $this->is_renewal() ) {
3830
+        // Set the new status.
3831
+        $gateway = sanitize_text_field( $this->get_gateway_title() );
3832
+        if ( $this->is_renewal() ) {
3833 3833
 
3834
-			$_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway );
3835
-			$_note = $_note . empty( $note ) ? '' : " ($note)";
3834
+            $_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway );
3835
+            $_note = $_note . empty( $note ) ? '' : " ($note)";
3836 3836
 
3837
-			if ( 'none' == $this->get_gateway() ) {
3838
-				$_note = $note;
3839
-			}
3837
+            if ( 'none' == $this->get_gateway() ) {
3838
+                $_note = $note;
3839
+            }
3840 3840
 
3841
-			$this->set_status( 'wpi-renewal', $_note );
3841
+            $this->set_status( 'wpi-renewal', $_note );
3842 3842
 
3843
-		} else {
3843
+        } else {
3844 3844
 
3845
-			$_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway );
3846
-			$_note = $_note . empty( $note ) ? '' : " ($note)";
3845
+            $_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway );
3846
+            $_note = $_note . empty( $note ) ? '' : " ($note)";
3847 3847
 
3848
-			if ( 'none' == $this->get_gateway() ) {
3849
-				$_note = $note;
3850
-			}
3848
+            if ( 'none' == $this->get_gateway() ) {
3849
+                $_note = $note;
3850
+            }
3851 3851
 
3852
-			$this->set_status( 'publish', $_note );
3852
+            $this->set_status( 'publish', $_note );
3853 3853
 
3854
-		}
3854
+        }
3855 3855
 
3856
-		// Set checkout mode.
3857
-		$mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live';
3858
-		$this->set_mode( $mode );
3856
+        // Set checkout mode.
3857
+        $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live';
3858
+        $this->set_mode( $mode );
3859 3859
 
3860
-		// Save the invoice.
3860
+        // Save the invoice.
3861 3861
         $this->save();
3862
-	}
3863
-
3864
-	/**
3865
-	 * Save data to the database.
3866
-	 *
3867
-	 * @since 1.0.19
3868
-	 * @return int invoice ID
3869
-	 */
3870
-	public function save() {
3871
-		$this->maybe_set_date_paid();
3872
-		$this->maybe_set_key();
3873
-		parent::save();
3874
-		$this->clear_cache();
3875
-		$this->status_transition();
3876
-		return $this->get_id();
3877
-	}
3878
-
3879
-	/**
3862
+    }
3863
+
3864
+    /**
3865
+     * Save data to the database.
3866
+     *
3867
+     * @since 1.0.19
3868
+     * @return int invoice ID
3869
+     */
3870
+    public function save() {
3871
+        $this->maybe_set_date_paid();
3872
+        $this->maybe_set_key();
3873
+        parent::save();
3874
+        $this->clear_cache();
3875
+        $this->status_transition();
3876
+        return $this->get_id();
3877
+    }
3878
+
3879
+    /**
3880 3880
      * Clears the subscription's cache.
3881 3881
      */
3882 3882
     public function clear_cache() {
3883
-		wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' );
3884
-		wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' );
3885
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' );
3886
-	}
3883
+        wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' );
3884
+        wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' );
3885
+        wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' );
3886
+    }
3887 3887
 
3888 3888
 }
Please login to merge, or discard this patch.
includes/wpinv-discount-functions.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -160,51 +160,51 @@
 block discarded – undo
160 160
  */
161 161
 function getpaid_calculate_invoice_discount( $invoice, $discount ) {
162 162
 
163
-	$initial_discount   = 0;
164
-	$recurring_discount = 0;
163
+    $initial_discount   = 0;
164
+    $recurring_discount = 0;
165 165
 
166
-	foreach ( $invoice->get_items() as $item ) {
166
+    foreach ( $invoice->get_items() as $item ) {
167 167
 
168
-		// Abort if it is not valid for this item.
169
-		if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) {
170
-			continue;
171
-		}
168
+        // Abort if it is not valid for this item.
169
+        if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) {
170
+            continue;
171
+        }
172 172
 
173
-		// Calculate the initial amount...
174
-		$item_discount           = $discount->get_discounted_amount( $item->get_sub_total() );
175
-		$recurring_item_discount = 0;
173
+        // Calculate the initial amount...
174
+        $item_discount           = $discount->get_discounted_amount( $item->get_sub_total() );
175
+        $recurring_item_discount = 0;
176 176
 
177
-		// ... and maybe the recurring amount.
178
-		if ( $item->is_recurring() && $discount->is_recurring() ) {
179
-			$recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() );
180
-		}
177
+        // ... and maybe the recurring amount.
178
+        if ( $item->is_recurring() && $discount->is_recurring() ) {
179
+            $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() );
180
+        }
181 181
 
182
-		// Discount should not exceed discounted amount.
183
-		if ( ! $discount->is_type( 'percent' ) ) {
182
+        // Discount should not exceed discounted amount.
183
+        if ( ! $discount->is_type( 'percent' ) ) {
184 184
 
185
-			if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) {
186
-				$item_discount = $discount->get_amount() - $initial_discount;
187
-			}
185
+            if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) {
186
+                $item_discount = $discount->get_amount() - $initial_discount;
187
+            }
188 188
 
189
-			if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) {
190
-				$recurring_item_discount = $discount->get_amount() - $recurring_discount;
191
-			}
189
+            if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) {
190
+                $recurring_item_discount = $discount->get_amount() - $recurring_discount;
191
+            }
192 192
 
193
-		}
193
+        }
194 194
 
195
-		$initial_discount             += $item_discount;
196
-		$recurring_discount           += $recurring_item_discount;
197
-		$item->item_discount           = $item_discount;
198
-		$item->recurring_item_discount = $recurring_item_discount;
195
+        $initial_discount             += $item_discount;
196
+        $recurring_discount           += $recurring_item_discount;
197
+        $item->item_discount           = $item_discount;
198
+        $item->recurring_item_discount = $recurring_item_discount;
199 199
 
200
-	}
200
+    }
201 201
 
202
-	return array(
203
-		'name'               => 'discount_code',
204
-		'discount_code'      => $discount->get_code(),
205
-		'initial_discount'   => $initial_discount,
206
-		'recurring_discount' => $recurring_discount,
207
-	);
202
+    return array(
203
+        'name'               => 'discount_code',
204
+        'discount_code'      => $discount->get_code(),
205
+        'initial_discount'   => $initial_discount,
206
+        'recurring_discount' => $recurring_discount,
207
+    );
208 208
 
209 209
 }
210 210
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 1 patch
Indentation   +813 added lines, -813 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,206 +10,206 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form_Submission {
11 11
 
12 12
     /**
13
-	 * Submission ID
14
-	 *
15
-	 * @var string
16
-	 */
17
-	public $id = null;
18
-
19
-	/**
20
-	 * The raw submission data.
21
-	 *
22
-	 * @var array
23
-	 */
24
-	protected $data = null;
25
-
26
-	/**
27
-	 * Submission totals
28
-	 *
29
-	 * @var array
30
-	 */
31
-	protected $totals = array(
32
-
33
-		'subtotal'      => array(
34
-			'initial'   => 0,
35
-			'recurring' => 0,
36
-		),
37
-
38
-		'discount'      => array(
39
-			'initial'   => 0,
40
-			'recurring' => 0,
41
-		),
42
-
43
-		'fees'          => array(
44
-			'initial'   => 0,
45
-			'recurring' => 0,
46
-		),
47
-
48
-		'taxes'         => array(
49
-			'initial'   => 0,
50
-			'recurring' => 0,
51
-		),
52
-
53
-	);
54
-
55
-	/**
56
-	 * Sets the associated payment form.
57
-	 *
58
-	 * @var GetPaid_Payment_Form
59
-	 */
13
+     * Submission ID
14
+     *
15
+     * @var string
16
+     */
17
+    public $id = null;
18
+
19
+    /**
20
+     * The raw submission data.
21
+     *
22
+     * @var array
23
+     */
24
+    protected $data = null;
25
+
26
+    /**
27
+     * Submission totals
28
+     *
29
+     * @var array
30
+     */
31
+    protected $totals = array(
32
+
33
+        'subtotal'      => array(
34
+            'initial'   => 0,
35
+            'recurring' => 0,
36
+        ),
37
+
38
+        'discount'      => array(
39
+            'initial'   => 0,
40
+            'recurring' => 0,
41
+        ),
42
+
43
+        'fees'          => array(
44
+            'initial'   => 0,
45
+            'recurring' => 0,
46
+        ),
47
+
48
+        'taxes'         => array(
49
+            'initial'   => 0,
50
+            'recurring' => 0,
51
+        ),
52
+
53
+    );
54
+
55
+    /**
56
+     * Sets the associated payment form.
57
+     *
58
+     * @var GetPaid_Payment_Form
59
+     */
60 60
     protected $payment_form = null;
61 61
 
62 62
     /**
63
-	 * The country for the submission.
64
-	 *
65
-	 * @var string
66
-	 */
67
-	public $country = null;
68
-
69
-    /**
70
-	 * The state for the submission.
71
-	 *
72
-	 * @since 1.0.19
73
-	 * @var string
74
-	 */
75
-	public $state = null;
76
-
77
-	/**
78
-	 * The invoice associated with the submission.
79
-	 *
80
-	 * @var WPInv_Invoice
81
-	 */
82
-	protected $invoice = null;
83
-
84
-	/**
85
-	 * The recurring item for the submission.
86
-	 *
87
-	 * @var int
88
-	 */
89
-	public $has_recurring = 0;
90
-
91
-	/**
92
-	 * The subscription groups. If more than 2, ensure the gateway
93
-	 * supports multiple subscriptions.
94
-	 *
95
-	 * @var array
96
-	 */
97
-	public $subscription_groups = array();
98
-
99
-	/**
100
-	 * An array of fees for the submission.
101
-	 *
102
-	 * @var array
103
-	 */
104
-	protected $fees = array();
105
-
106
-	/**
107
-	 * An array of discounts for the submission.
108
-	 *
109
-	 * @var array
110
-	 */
111
-	protected $discounts = array();
112
-
113
-	/**
114
-	 * An array of taxes for the submission.
115
-	 *
116
-	 * @var array
117
-	 */
118
-	protected $taxes = array();
119
-
120
-	/**
121
-	 * An array of items for the submission.
122
-	 *
123
-	 * @var GetPaid_Form_Item[]
124
-	 */
125
-	protected $items = array();
126
-
127
-	/**
128
-	 * The last error.
129
-	 *
130
-	 * @var string
131
-	 */
132
-	public $last_error = null;
133
-
134
-	/**
135
-	 * The last error code.
136
-	 *
137
-	 * @var string
138
-	 */
139
-	public $last_error_code = null;
140
-
141
-    /**
142
-	 * Class constructor.
143
-	 *
144
-	 */
145
-	public function __construct() {
146
-
147
-		// Set the state and country to the default state and country.
148
-		$this->country = wpinv_default_billing_country();
149
-		$this->state   = wpinv_get_default_state();
150
-
151
-		// Do we have an actual submission?
152
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
153
-			$this->load_data( $_POST );
154
-		}
155
-
156
-	}
157
-
158
-	/**
159
-	 * Loads submission data.
160
-	 *
161
-	 * @param array $data
162
-	 */
163
-	public function load_data( $data ) {
164
-
165
-		// Remove slashes from the submitted data...
166
-		$data       = wp_unslash( $data );
167
-
168
-		// Allow plugins to filter the data.
169
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
170
-
171
-		// Cache it...
172
-		$this->data = $data;
173
-
174
-		// Then generate a unique id from the data.
175
-		$this->id   = md5( wp_json_encode( $data ) );
176
-
177
-		// Finally, process the submission.
178
-		try {
179
-
180
-			// Each process is passed an instance of the class (with reference)
181
-			// and should throw an Exception whenever it encounters one.
182
-			$processors = apply_filters(
183
-				'getpaid_payment_form_submission_processors',
184
-				array(
185
-					array( $this, 'process_payment_form' ),
186
-					array( $this, 'process_invoice' ),
187
-					array( $this, 'process_fees' ),
188
-					array( $this, 'process_items' ),
189
-					array( $this, 'process_discount' ),
190
-					array( $this, 'process_taxes' ),
191
-				),
192
-				$this		
193
-			);
194
-
195
-			foreach ( $processors as $processor ) {
196
-				call_user_func_array( $processor, array( &$this ) );
197
-			}
198
-
199
-		} catch( GetPaid_Payment_Exception $e ) {
200
-			$this->last_error      = $e->getMessage();
201
-			$this->last_error_code = $e->getErrorCode();
202
-		} catch ( Exception $e ) {
203
-			$this->last_error      = $e->getMessage();
204
-			$this->last_error_code = $e->getCode();
205
-		}
206
-
207
-		// Fired when we are done processing a submission.
208
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
209
-
210
-	}
211
-
212
-	/*
63
+     * The country for the submission.
64
+     *
65
+     * @var string
66
+     */
67
+    public $country = null;
68
+
69
+    /**
70
+     * The state for the submission.
71
+     *
72
+     * @since 1.0.19
73
+     * @var string
74
+     */
75
+    public $state = null;
76
+
77
+    /**
78
+     * The invoice associated with the submission.
79
+     *
80
+     * @var WPInv_Invoice
81
+     */
82
+    protected $invoice = null;
83
+
84
+    /**
85
+     * The recurring item for the submission.
86
+     *
87
+     * @var int
88
+     */
89
+    public $has_recurring = 0;
90
+
91
+    /**
92
+     * The subscription groups. If more than 2, ensure the gateway
93
+     * supports multiple subscriptions.
94
+     *
95
+     * @var array
96
+     */
97
+    public $subscription_groups = array();
98
+
99
+    /**
100
+     * An array of fees for the submission.
101
+     *
102
+     * @var array
103
+     */
104
+    protected $fees = array();
105
+
106
+    /**
107
+     * An array of discounts for the submission.
108
+     *
109
+     * @var array
110
+     */
111
+    protected $discounts = array();
112
+
113
+    /**
114
+     * An array of taxes for the submission.
115
+     *
116
+     * @var array
117
+     */
118
+    protected $taxes = array();
119
+
120
+    /**
121
+     * An array of items for the submission.
122
+     *
123
+     * @var GetPaid_Form_Item[]
124
+     */
125
+    protected $items = array();
126
+
127
+    /**
128
+     * The last error.
129
+     *
130
+     * @var string
131
+     */
132
+    public $last_error = null;
133
+
134
+    /**
135
+     * The last error code.
136
+     *
137
+     * @var string
138
+     */
139
+    public $last_error_code = null;
140
+
141
+    /**
142
+     * Class constructor.
143
+     *
144
+     */
145
+    public function __construct() {
146
+
147
+        // Set the state and country to the default state and country.
148
+        $this->country = wpinv_default_billing_country();
149
+        $this->state   = wpinv_get_default_state();
150
+
151
+        // Do we have an actual submission?
152
+        if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
153
+            $this->load_data( $_POST );
154
+        }
155
+
156
+    }
157
+
158
+    /**
159
+     * Loads submission data.
160
+     *
161
+     * @param array $data
162
+     */
163
+    public function load_data( $data ) {
164
+
165
+        // Remove slashes from the submitted data...
166
+        $data       = wp_unslash( $data );
167
+
168
+        // Allow plugins to filter the data.
169
+        $data       = apply_filters( 'getpaid_submission_data', $data, $this );
170
+
171
+        // Cache it...
172
+        $this->data = $data;
173
+
174
+        // Then generate a unique id from the data.
175
+        $this->id   = md5( wp_json_encode( $data ) );
176
+
177
+        // Finally, process the submission.
178
+        try {
179
+
180
+            // Each process is passed an instance of the class (with reference)
181
+            // and should throw an Exception whenever it encounters one.
182
+            $processors = apply_filters(
183
+                'getpaid_payment_form_submission_processors',
184
+                array(
185
+                    array( $this, 'process_payment_form' ),
186
+                    array( $this, 'process_invoice' ),
187
+                    array( $this, 'process_fees' ),
188
+                    array( $this, 'process_items' ),
189
+                    array( $this, 'process_discount' ),
190
+                    array( $this, 'process_taxes' ),
191
+                ),
192
+                $this		
193
+            );
194
+
195
+            foreach ( $processors as $processor ) {
196
+                call_user_func_array( $processor, array( &$this ) );
197
+            }
198
+
199
+        } catch( GetPaid_Payment_Exception $e ) {
200
+            $this->last_error      = $e->getMessage();
201
+            $this->last_error_code = $e->getErrorCode();
202
+        } catch ( Exception $e ) {
203
+            $this->last_error      = $e->getMessage();
204
+            $this->last_error_code = $e->getCode();
205
+        }
206
+
207
+        // Fired when we are done processing a submission.
208
+        do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
209
+
210
+    }
211
+
212
+    /*
213 213
 	|--------------------------------------------------------------------------
214 214
 	| Payment Forms.
215 215
 	|--------------------------------------------------------------------------
@@ -218,39 +218,39 @@  discard block
 block discarded – undo
218 218
 	| submission has an active payment form etc.
219 219
     */
220 220
 
221
-	/**
222
-	 * Prepares the submission's payment form.
223
-	 *
224
-	 * @since 1.0.19
225
-	 */
226
-	public function process_payment_form() {
221
+    /**
222
+     * Prepares the submission's payment form.
223
+     *
224
+     * @since 1.0.19
225
+     */
226
+    public function process_payment_form() {
227 227
 
228
-		// Every submission needs an active payment form.
229
-		if ( empty( $this->data['form_id'] ) ) {
230
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
231
-		}
228
+        // Every submission needs an active payment form.
229
+        if ( empty( $this->data['form_id'] ) ) {
230
+            throw new Exception( __( 'Missing payment form', 'invoicing' ) );
231
+        }
232 232
 
233
-		// Fetch the payment form.
234
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
233
+        // Fetch the payment form.
234
+        $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
235 235
 
236
-		if ( ! $this->payment_form->is_active() ) {
237
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
238
-		}
236
+        if ( ! $this->payment_form->is_active() ) {
237
+            throw new Exception( __( 'Payment form not active', 'invoicing' ) );
238
+        }
239 239
 
240
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
241
-	}
240
+        do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
241
+    }
242 242
 
243 243
     /**
244
-	 * Returns the payment form.
245
-	 *
246
-	 * @since 1.0.19
247
-	 * @return GetPaid_Payment_Form
248
-	 */
249
-	public function get_payment_form() {
250
-		return $this->payment_form;
251
-	}
244
+     * Returns the payment form.
245
+     *
246
+     * @since 1.0.19
247
+     * @return GetPaid_Payment_Form
248
+     */
249
+    public function get_payment_form() {
250
+        return $this->payment_form;
251
+    }
252 252
 
253
-	/*
253
+    /*
254 254
 	|--------------------------------------------------------------------------
255 255
 	| Invoices.
256 256
 	|--------------------------------------------------------------------------
@@ -259,84 +259,84 @@  discard block
 block discarded – undo
259 259
 	| might be for an existing invoice.
260 260
 	*/
261 261
 
262
-	/**
263
-	 * Prepares the submission's invoice.
264
-	 *
265
-	 * @since 1.0.19
266
-	 */
267
-	public function process_invoice() {
262
+    /**
263
+     * Prepares the submission's invoice.
264
+     *
265
+     * @since 1.0.19
266
+     */
267
+    public function process_invoice() {
268 268
 
269
-		// Abort if there is no invoice.
270
-		if ( empty( $this->data['invoice_id'] ) ) {
271
-			return;
272
-		}
269
+        // Abort if there is no invoice.
270
+        if ( empty( $this->data['invoice_id'] ) ) {
271
+            return;
272
+        }
273 273
 
274
-		// If the submission is for an existing invoice, ensure that it exists
275
-		// and that it is not paid for.
276
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
274
+        // If the submission is for an existing invoice, ensure that it exists
275
+        // and that it is not paid for.
276
+        $invoice = wpinv_get_invoice( $this->data['invoice_id'] );
277 277
 
278 278
         if ( empty( $invoice ) ) {
279
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
280
-		}
279
+            throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
280
+        }
281 281
 
282
-		if ( $invoice->is_paid() ) {
283
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
284
-		}
282
+        if ( $invoice->is_paid() ) {
283
+            throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
284
+        }
285 285
 
286
-		$this->payment_form->invoice = $invoice;
287
-		if ( ! $this->payment_form->is_default() ) {
286
+        $this->payment_form->invoice = $invoice;
287
+        if ( ! $this->payment_form->is_default() ) {
288 288
 
289
-			$items    = array();
290
-			$item_ids = array();
289
+            $items    = array();
290
+            $item_ids = array();
291 291
 	
292
-			foreach ( $invoice->get_items() as $item ) {
293
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
294
-					$item_ids[] = $item->get_id();
295
-					$items[]    = $item;
296
-				}
297
-			}
292
+            foreach ( $invoice->get_items() as $item ) {
293
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
294
+                    $item_ids[] = $item->get_id();
295
+                    $items[]    = $item;
296
+                }
297
+            }
298 298
 	
299
-			foreach ( $this->payment_form->get_items() as $item ) {
300
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
301
-					$item_ids[] = $item->get_id();
302
-					$items[]    = $item;
303
-				}
304
-			}
299
+            foreach ( $this->payment_form->get_items() as $item ) {
300
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
301
+                    $item_ids[] = $item->get_id();
302
+                    $items[]    = $item;
303
+                }
304
+            }
305 305
 	
306
-			$this->payment_form->set_items( $items );
306
+            $this->payment_form->set_items( $items );
307 307
 	
308
-		} else {
309
-			$this->payment_form->set_items( $invoice->get_items() );
310
-		}
311
-
312
-		$this->country = $invoice->get_country();
313
-		$this->state   = $invoice->get_state();
314
-		$this->invoice = $invoice;
315
-
316
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
317
-	}
318
-
319
-	/**
320
-	 * Returns the associated invoice.
321
-	 *
322
-	 * @since 1.0.19
323
-	 * @return WPInv_Invoice
324
-	 */
325
-	public function get_invoice() {
326
-		return $this->invoice;
327
-	}
328
-
329
-	/**
330
-	 * Checks whether there is an invoice associated with this submission.
331
-	 *
332
-	 * @since 1.0.19
333
-	 * @return bool
334
-	 */
335
-	public function has_invoice() {
336
-		return ! empty( $this->invoice );
337
-	}
338
-
339
-	/*
308
+        } else {
309
+            $this->payment_form->set_items( $invoice->get_items() );
310
+        }
311
+
312
+        $this->country = $invoice->get_country();
313
+        $this->state   = $invoice->get_state();
314
+        $this->invoice = $invoice;
315
+
316
+        do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
317
+    }
318
+
319
+    /**
320
+     * Returns the associated invoice.
321
+     *
322
+     * @since 1.0.19
323
+     * @return WPInv_Invoice
324
+     */
325
+    public function get_invoice() {
326
+        return $this->invoice;
327
+    }
328
+
329
+    /**
330
+     * Checks whether there is an invoice associated with this submission.
331
+     *
332
+     * @since 1.0.19
333
+     * @return bool
334
+     */
335
+    public function has_invoice() {
336
+        return ! empty( $this->invoice );
337
+    }
338
+
339
+    /*
340 340
 	|--------------------------------------------------------------------------
341 341
 	| Items.
342 342
 	|--------------------------------------------------------------------------
@@ -345,116 +345,116 @@  discard block
 block discarded – undo
345 345
 	| recurring item. But can have an unlimited number of non-recurring items.
346 346
 	*/
347 347
 
348
-	/**
349
-	 * Prepares the submission's items.
350
-	 *
351
-	 * @since 1.0.19
352
-	 */
353
-	public function process_items() {
354
-
355
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
356
-
357
-		foreach ( $processor->items as $item ) {
358
-			$this->add_item( $item );
359
-		}
360
-
361
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
362
-	}
363
-
364
-	/**
365
-	 * Adds an item to the submission.
366
-	 *
367
-	 * @since 1.0.19
368
-	 * @param GetPaid_Form_Item $item
369
-	 */
370
-	public function add_item( $item ) {
371
-
372
-		// Make sure that it is available for purchase.
373
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
374
-			return;
375
-		}
376
-
377
-		// Each submission can only contain one recurring item.
378
-		if ( $item->is_recurring() ) {
379
-
380
-			if ( $this->has_recurring != 0 ) {
381
-				throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
382
-			}
383
-
384
-			$this->has_recurring = $item->get_id();
385
-
386
-		}
387
-
388
-		// Update the items and totals.
389
-		$this->items[ $item->get_id() ]         = $item;
390
-		$this->totals['subtotal']['initial']   += $item->get_sub_total();
391
-		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
392
-
393
-		$this->subscription_groups = getpaid_calculate_subscription_totals( $this );
394
-	}
395
-
396
-	/**
397
-	 * Removes a specific item.
398
-	 * 
399
-	 * You should not call this method after the discounts and taxes
400
-	 * have been calculated.
401
-	 *
402
-	 * @since 1.0.19
403
-	 */
404
-	public function remove_item( $item_id ) {
405
-
406
-		if ( isset( $this->items[ $item_id ] ) ) {
407
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
408
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
409
-
410
-			if ( $this->items[ $item_id ]->is_recurring() ) {
411
-				$this->has_recurring = 0;
412
-			}
413
-
414
-			unset( $this->items[ $item_id ] );
415
-		}
416
-
417
-	}
418
-
419
-	/**
420
-	 * Returns the subtotal.
421
-	 *
422
-	 * @since 1.0.19
423
-	 */
424
-	public function get_subtotal() {
425
-
426
-		if ( wpinv_prices_include_tax() ) {
427
-			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
428
-		}
429
-
430
-		return $this->totals['subtotal']['initial'];
431
-	}
432
-
433
-	/**
434
-	 * Returns the recurring subtotal.
435
-	 *
436
-	 * @since 1.0.19
437
-	 */
438
-	public function get_recurring_subtotal() {
439
-
440
-		if ( wpinv_prices_include_tax() ) {
441
-			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
442
-		}
443
-
444
-		return $this->totals['subtotal']['recurring'];
445
-	}
446
-
447
-	/**
448
-	 * Returns all items.
449
-	 *
450
-	 * @since 1.0.19
451
-	 * @return GetPaid_Form_Item[]
452
-	 */
453
-	public function get_items() {
454
-		return $this->items;
455
-	}
456
-
457
-	/*
348
+    /**
349
+     * Prepares the submission's items.
350
+     *
351
+     * @since 1.0.19
352
+     */
353
+    public function process_items() {
354
+
355
+        $processor = new GetPaid_Payment_Form_Submission_Items( $this );
356
+
357
+        foreach ( $processor->items as $item ) {
358
+            $this->add_item( $item );
359
+        }
360
+
361
+        do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
362
+    }
363
+
364
+    /**
365
+     * Adds an item to the submission.
366
+     *
367
+     * @since 1.0.19
368
+     * @param GetPaid_Form_Item $item
369
+     */
370
+    public function add_item( $item ) {
371
+
372
+        // Make sure that it is available for purchase.
373
+        if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
374
+            return;
375
+        }
376
+
377
+        // Each submission can only contain one recurring item.
378
+        if ( $item->is_recurring() ) {
379
+
380
+            if ( $this->has_recurring != 0 ) {
381
+                throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
382
+            }
383
+
384
+            $this->has_recurring = $item->get_id();
385
+
386
+        }
387
+
388
+        // Update the items and totals.
389
+        $this->items[ $item->get_id() ]         = $item;
390
+        $this->totals['subtotal']['initial']   += $item->get_sub_total();
391
+        $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
392
+
393
+        $this->subscription_groups = getpaid_calculate_subscription_totals( $this );
394
+    }
395
+
396
+    /**
397
+     * Removes a specific item.
398
+     * 
399
+     * You should not call this method after the discounts and taxes
400
+     * have been calculated.
401
+     *
402
+     * @since 1.0.19
403
+     */
404
+    public function remove_item( $item_id ) {
405
+
406
+        if ( isset( $this->items[ $item_id ] ) ) {
407
+            $this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
408
+            $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
409
+
410
+            if ( $this->items[ $item_id ]->is_recurring() ) {
411
+                $this->has_recurring = 0;
412
+            }
413
+
414
+            unset( $this->items[ $item_id ] );
415
+        }
416
+
417
+    }
418
+
419
+    /**
420
+     * Returns the subtotal.
421
+     *
422
+     * @since 1.0.19
423
+     */
424
+    public function get_subtotal() {
425
+
426
+        if ( wpinv_prices_include_tax() ) {
427
+            return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
428
+        }
429
+
430
+        return $this->totals['subtotal']['initial'];
431
+    }
432
+
433
+    /**
434
+     * Returns the recurring subtotal.
435
+     *
436
+     * @since 1.0.19
437
+     */
438
+    public function get_recurring_subtotal() {
439
+
440
+        if ( wpinv_prices_include_tax() ) {
441
+            return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
442
+        }
443
+
444
+        return $this->totals['subtotal']['recurring'];
445
+    }
446
+
447
+    /**
448
+     * Returns all items.
449
+     *
450
+     * @since 1.0.19
451
+     * @return GetPaid_Form_Item[]
452
+     */
453
+    public function get_items() {
454
+        return $this->items;
455
+    }
456
+
457
+    /*
458 458
 	|--------------------------------------------------------------------------
459 459
 	| Taxes
460 460
 	|--------------------------------------------------------------------------
@@ -463,128 +463,128 @@  discard block
 block discarded – undo
463 463
 	| or only one-time.
464 464
     */
465 465
 
466
-	/**
467
-	 * Prepares the submission's taxes.
468
-	 *
469
-	 * @since 1.0.19
470
-	 */
471
-	public function process_taxes() {
472
-
473
-		// Abort if we're not using taxes.
474
-		if ( ! $this->use_taxes() ) {
475
-			return;
476
-		}
477
-
478
-		// If a custom country && state has been passed in, use it to calculate taxes.
479
-		$country = $this->get_field( 'wpinv_country', 'billing' );
480
-		if ( ! empty( $country ) ) {
481
-			$this->country = $country;
482
-		}
483
-
484
-		$state = $this->get_field( 'wpinv_state', 'billing' );
485
-		if ( ! empty( $state ) ) {
486
-			$this->state = $state;
487
-		}
488
-
489
-		// Confirm if the provided country and the ip country are similar.
490
-		$address_confirmed = $this->get_field( 'confirm-address' );
491
-		if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
492
-			throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
493
-		}
494
-
495
-		// Abort if the country is not taxable.
496
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
497
-			return;
498
-		}
499
-
500
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
501
-
502
-		foreach ( $processor->taxes as $tax ) {
503
-			$this->add_tax( $tax );
504
-		}
505
-
506
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
507
-	}
508
-
509
-	/**
510
-	 * Adds a tax to the submission.
511
-	 *
512
-	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
513
-	 * @since 1.0.19
514
-	 */
515
-	public function add_tax( $tax ) {
516
-
517
-		if ( wpinv_round_tax_per_tax_rate() ) {
518
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
519
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
520
-		}
521
-
522
-		$this->taxes[ $tax['name'] ]         = $tax;
523
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
524
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
525
-
526
-	}
527
-
528
-	/**
529
-	 * Removes a specific tax.
530
-	 *
531
-	 * @since 1.0.19
532
-	 */
533
-	public function remove_tax( $tax_name ) {
534
-
535
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
536
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
537
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
538
-			unset( $this->taxes[ $tax_name ] );
539
-		}
540
-
541
-	}
542
-
543
-	/**
544
-	 * Whether or not we'll use taxes for the submission.
545
-	 *
546
-	 * @since 1.0.19
547
-	 */
548
-	public function use_taxes() {
549
-
550
-		$use_taxes = wpinv_use_taxes();
551
-
552
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
553
-			$use_taxes = false;
554
-		}
555
-
556
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
557
-
558
-	}
559
-
560
-	/**
561
-	 * Returns the tax.
562
-	 *
563
-	 * @since 1.0.19
564
-	 */
565
-	public function get_tax() {
566
-		return $this->totals['taxes']['initial'];
567
-	}
568
-
569
-	/**
570
-	 * Returns the recurring tax.
571
-	 *
572
-	 * @since 1.0.19
573
-	 */
574
-	public function get_recurring_tax() {
575
-		return $this->totals['taxes']['recurring'];
576
-	}
577
-
578
-	/**
579
-	 * Returns all taxes.
580
-	 *
581
-	 * @since 1.0.19
582
-	 */
583
-	public function get_taxes() {
584
-		return $this->taxes;
585
-	}
586
-
587
-	/*
466
+    /**
467
+     * Prepares the submission's taxes.
468
+     *
469
+     * @since 1.0.19
470
+     */
471
+    public function process_taxes() {
472
+
473
+        // Abort if we're not using taxes.
474
+        if ( ! $this->use_taxes() ) {
475
+            return;
476
+        }
477
+
478
+        // If a custom country && state has been passed in, use it to calculate taxes.
479
+        $country = $this->get_field( 'wpinv_country', 'billing' );
480
+        if ( ! empty( $country ) ) {
481
+            $this->country = $country;
482
+        }
483
+
484
+        $state = $this->get_field( 'wpinv_state', 'billing' );
485
+        if ( ! empty( $state ) ) {
486
+            $this->state = $state;
487
+        }
488
+
489
+        // Confirm if the provided country and the ip country are similar.
490
+        $address_confirmed = $this->get_field( 'confirm-address' );
491
+        if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
492
+            throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
493
+        }
494
+
495
+        // Abort if the country is not taxable.
496
+        if ( ! wpinv_is_country_taxable( $this->country ) ) {
497
+            return;
498
+        }
499
+
500
+        $processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
501
+
502
+        foreach ( $processor->taxes as $tax ) {
503
+            $this->add_tax( $tax );
504
+        }
505
+
506
+        do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
507
+    }
508
+
509
+    /**
510
+     * Adds a tax to the submission.
511
+     *
512
+     * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
513
+     * @since 1.0.19
514
+     */
515
+    public function add_tax( $tax ) {
516
+
517
+        if ( wpinv_round_tax_per_tax_rate() ) {
518
+            $tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
519
+            $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
520
+        }
521
+
522
+        $this->taxes[ $tax['name'] ]         = $tax;
523
+        $this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
524
+        $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
525
+
526
+    }
527
+
528
+    /**
529
+     * Removes a specific tax.
530
+     *
531
+     * @since 1.0.19
532
+     */
533
+    public function remove_tax( $tax_name ) {
534
+
535
+        if ( isset( $this->taxes[ $tax_name ] ) ) {
536
+            $this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
537
+            $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
538
+            unset( $this->taxes[ $tax_name ] );
539
+        }
540
+
541
+    }
542
+
543
+    /**
544
+     * Whether or not we'll use taxes for the submission.
545
+     *
546
+     * @since 1.0.19
547
+     */
548
+    public function use_taxes() {
549
+
550
+        $use_taxes = wpinv_use_taxes();
551
+
552
+        if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
553
+            $use_taxes = false;
554
+        }
555
+
556
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
557
+
558
+    }
559
+
560
+    /**
561
+     * Returns the tax.
562
+     *
563
+     * @since 1.0.19
564
+     */
565
+    public function get_tax() {
566
+        return $this->totals['taxes']['initial'];
567
+    }
568
+
569
+    /**
570
+     * Returns the recurring tax.
571
+     *
572
+     * @since 1.0.19
573
+     */
574
+    public function get_recurring_tax() {
575
+        return $this->totals['taxes']['recurring'];
576
+    }
577
+
578
+    /**
579
+     * Returns all taxes.
580
+     *
581
+     * @since 1.0.19
582
+     */
583
+    public function get_taxes() {
584
+        return $this->taxes;
585
+    }
586
+
587
+    /*
588 588
 	|--------------------------------------------------------------------------
589 589
 	| Discounts
590 590
 	|--------------------------------------------------------------------------
@@ -593,99 +593,99 @@  discard block
 block discarded – undo
593 593
 	| or only one-time. They also do not have to come from a discount code.
594 594
     */
595 595
 
596
-	/**
597
-	 * Prepares the submission's discount.
598
-	 *
599
-	 * @since 1.0.19
600
-	 */
601
-	public function process_discount() {
602
-
603
-		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
604
-		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
605
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
606
-
607
-		foreach ( $processor->discounts as $discount ) {
608
-			$this->add_discount( $discount );
609
-		}
610
-
611
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
612
-	}
613
-
614
-	/**
615
-	 * Adds a discount to the submission.
616
-	 *
617
-	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
618
-	 * @since 1.0.19
619
-	 */
620
-	public function add_discount( $discount ) {
621
-		$this->discounts[ $discount['name'] ]   = $discount;
622
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
623
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
624
-	}
625
-
626
-	/**
627
-	 * Removes a discount from the submission.
628
-	 *
629
-	 * @since 1.0.19
630
-	 */
631
-	public function remove_discount( $name ) {
632
-
633
-		if ( isset( $this->discounts[ $name ] ) ) {
634
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
635
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
636
-			unset( $this->discounts[ $name ] );
637
-		}
638
-
639
-	}
640
-
641
-	/**
642
-	 * Checks whether there is a discount code associated with this submission.
643
-	 *
644
-	 * @since 1.0.19
645
-	 * @return bool
646
-	 */
647
-	public function has_discount_code() {
648
-		return ! empty( $this->discounts['discount_code'] );
649
-	}
650
-
651
-	/**
652
-	 * Returns the discount code.
653
-	 *
654
-	 * @since 1.0.19
655
-	 * @return string
656
-	 */
657
-	public function get_discount_code() {
658
-		return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
659
-	}
660
-
661
-	/**
662
-	 * Returns the discount.
663
-	 *
664
-	 * @since 1.0.19
665
-	 */
666
-	public function get_discount() {
667
-		return $this->totals['discount']['initial'];
668
-	}
669
-
670
-	/**
671
-	 * Returns the recurring discount.
672
-	 *
673
-	 * @since 1.0.19
674
-	 */
675
-	public function get_recurring_discount() {
676
-		return $this->totals['discount']['recurring'];
677
-	}
678
-
679
-	/**
680
-	 * Returns all discounts.
681
-	 *
682
-	 * @since 1.0.19
683
-	 */
684
-	public function get_discounts() {
685
-		return $this->discounts;
686
-	}
687
-
688
-	/*
596
+    /**
597
+     * Prepares the submission's discount.
598
+     *
599
+     * @since 1.0.19
600
+     */
601
+    public function process_discount() {
602
+
603
+        $initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
604
+        $recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
605
+        $processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
606
+
607
+        foreach ( $processor->discounts as $discount ) {
608
+            $this->add_discount( $discount );
609
+        }
610
+
611
+        do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
612
+    }
613
+
614
+    /**
615
+     * Adds a discount to the submission.
616
+     *
617
+     * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
618
+     * @since 1.0.19
619
+     */
620
+    public function add_discount( $discount ) {
621
+        $this->discounts[ $discount['name'] ]   = $discount;
622
+        $this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
623
+        $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
624
+    }
625
+
626
+    /**
627
+     * Removes a discount from the submission.
628
+     *
629
+     * @since 1.0.19
630
+     */
631
+    public function remove_discount( $name ) {
632
+
633
+        if ( isset( $this->discounts[ $name ] ) ) {
634
+            $this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
635
+            $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
636
+            unset( $this->discounts[ $name ] );
637
+        }
638
+
639
+    }
640
+
641
+    /**
642
+     * Checks whether there is a discount code associated with this submission.
643
+     *
644
+     * @since 1.0.19
645
+     * @return bool
646
+     */
647
+    public function has_discount_code() {
648
+        return ! empty( $this->discounts['discount_code'] );
649
+    }
650
+
651
+    /**
652
+     * Returns the discount code.
653
+     *
654
+     * @since 1.0.19
655
+     * @return string
656
+     */
657
+    public function get_discount_code() {
658
+        return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
659
+    }
660
+
661
+    /**
662
+     * Returns the discount.
663
+     *
664
+     * @since 1.0.19
665
+     */
666
+    public function get_discount() {
667
+        return $this->totals['discount']['initial'];
668
+    }
669
+
670
+    /**
671
+     * Returns the recurring discount.
672
+     *
673
+     * @since 1.0.19
674
+     */
675
+    public function get_recurring_discount() {
676
+        return $this->totals['discount']['recurring'];
677
+    }
678
+
679
+    /**
680
+     * Returns all discounts.
681
+     *
682
+     * @since 1.0.19
683
+     */
684
+    public function get_discounts() {
685
+        return $this->discounts;
686
+    }
687
+
688
+    /*
689 689
 	|--------------------------------------------------------------------------
690 690
 	| Fees
691 691
 	|--------------------------------------------------------------------------
@@ -695,89 +695,89 @@  discard block
 block discarded – undo
695 695
 	| fees.
696 696
     */
697 697
 
698
-	/**
699
-	 * Prepares the submission's fees.
700
-	 *
701
-	 * @since 1.0.19
702
-	 */
703
-	public function process_fees() {
704
-
705
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
706
-
707
-		foreach ( $fees_processor->fees as $fee ) {
708
-			$this->add_fee( $fee );
709
-		}
710
-
711
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
712
-	}
713
-
714
-	/**
715
-	 * Adds a fee to the submission.
716
-	 *
717
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
718
-	 * @since 1.0.19
719
-	 */
720
-	public function add_fee( $fee ) {
721
-
722
-		$this->fees[ $fee['name'] ]         = $fee;
723
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
724
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
725
-
726
-	}
727
-
728
-	/**
729
-	 * Removes a fee from the submission.
730
-	 *
731
-	 * @since 1.0.19
732
-	 */
733
-	public function remove_fee( $name ) {
734
-
735
-		if ( isset( $this->fees[ $name ] ) ) {
736
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
737
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
738
-			unset( $this->fees[ $name ] );
739
-		}
740
-
741
-	}
742
-
743
-	/**
744
-	 * Returns the fees.
745
-	 *
746
-	 * @since 1.0.19
747
-	 */
748
-	public function get_fee() {
749
-		return $this->totals['fees']['initial'];
750
-	}
751
-
752
-	/**
753
-	 * Returns the recurring fees.
754
-	 *
755
-	 * @since 1.0.19
756
-	 */
757
-	public function get_recurring_fee() {
758
-		return $this->totals['fees']['recurring'];
759
-	}
760
-
761
-	/**
762
-	 * Returns all fees.
763
-	 *
764
-	 * @since 1.0.19
765
-	 */
766
-	public function get_fees() {
767
-		return $this->fees;
768
-	}
769
-
770
-	/**
771
-	 * Checks if there are any fees for the form.
772
-	 *
773
-	 * @return bool
774
-	 * @since 1.0.19
775
-	 */
776
-	public function has_fees() {
777
-		return count( $this->fees ) !== 0;
778
-	}
779
-
780
-	/*
698
+    /**
699
+     * Prepares the submission's fees.
700
+     *
701
+     * @since 1.0.19
702
+     */
703
+    public function process_fees() {
704
+
705
+        $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
706
+
707
+        foreach ( $fees_processor->fees as $fee ) {
708
+            $this->add_fee( $fee );
709
+        }
710
+
711
+        do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
712
+    }
713
+
714
+    /**
715
+     * Adds a fee to the submission.
716
+     *
717
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
718
+     * @since 1.0.19
719
+     */
720
+    public function add_fee( $fee ) {
721
+
722
+        $this->fees[ $fee['name'] ]         = $fee;
723
+        $this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
724
+        $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
725
+
726
+    }
727
+
728
+    /**
729
+     * Removes a fee from the submission.
730
+     *
731
+     * @since 1.0.19
732
+     */
733
+    public function remove_fee( $name ) {
734
+
735
+        if ( isset( $this->fees[ $name ] ) ) {
736
+            $this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
737
+            $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
738
+            unset( $this->fees[ $name ] );
739
+        }
740
+
741
+    }
742
+
743
+    /**
744
+     * Returns the fees.
745
+     *
746
+     * @since 1.0.19
747
+     */
748
+    public function get_fee() {
749
+        return $this->totals['fees']['initial'];
750
+    }
751
+
752
+    /**
753
+     * Returns the recurring fees.
754
+     *
755
+     * @since 1.0.19
756
+     */
757
+    public function get_recurring_fee() {
758
+        return $this->totals['fees']['recurring'];
759
+    }
760
+
761
+    /**
762
+     * Returns all fees.
763
+     *
764
+     * @since 1.0.19
765
+     */
766
+    public function get_fees() {
767
+        return $this->fees;
768
+    }
769
+
770
+    /**
771
+     * Checks if there are any fees for the form.
772
+     *
773
+     * @return bool
774
+     * @since 1.0.19
775
+     */
776
+    public function has_fees() {
777
+        return count( $this->fees ) !== 0;
778
+    }
779
+
780
+    /*
781 781
 	|--------------------------------------------------------------------------
782 782
 	| MISC
783 783
 	|--------------------------------------------------------------------------
@@ -785,119 +785,119 @@  discard block
 block discarded – undo
785 785
 	| Extra submission functions.
786 786
     */
787 787
 
788
-	/**
789
-	 * Checks if this is the initial fetch.
790
-	 *
791
-	 * @return bool
792
-	 * @since 1.0.19
793
-	 */
794
-	public function is_initial_fetch() {
795
-		return empty( $this->data['initial_state'] );
796
-	}
797
-
798
-	/**
799
-	 * Returns the total amount to collect for this submission.
800
-	 *
801
-	 * @since 1.0.19
802
-	 */
803
-	public function get_total() {
804
-		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
805
-		return max( $total, 0 );
806
-	}
807
-
808
-	/**
809
-	 * Returns the recurring total amount to collect for this submission.
810
-	 *
811
-	 * @since 1.0.19
812
-	 */
813
-	public function get_recurring_total() {
814
-		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
815
-		return max( $total, 0 );
816
-	}
817
-
818
-	/**
819
-	 * Whether payment details should be collected for this submission.
820
-	 *
821
-	 * @since 1.0.19
822
-	 */
823
-	public function should_collect_payment_details() {
824
-		$initial   = $this->get_total();
825
-		$recurring = $this->get_recurring_total();
826
-
827
-		if ( $this->has_recurring == 0 ) {
828
-			$recurring = 0;
829
-		}
830
-
831
-		$collect = $initial > 0 || $recurring > 0;
832
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
833
-	}
834
-
835
-	/**
836
-	 * Returns the billing email of the user.
837
-	 *
838
-	 * @since 1.0.19
839
-	 */
840
-	public function get_billing_email() {
841
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
842
-	}
843
-
844
-	/**
845
-	 * Checks if the submitter has a billing email.
846
-	 *
847
-	 * @since 1.0.19
848
-	 */
849
-	public function has_billing_email() {
850
-		$billing_email = $this->get_billing_email();
851
-		return ! empty( $billing_email ) && is_email( $billing_email );
852
-	}
853
-
854
-	/**
855
-	 * Returns the appropriate currency for the submission.
856
-	 *
857
-	 * @since 1.0.19
858
-	 * @return string
859
-	 */
860
-	public function get_currency() {
861
-		return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
862
-    }
863
-
864
-    /**
865
-	 * Returns the raw submission data.
866
-	 *
867
-	 * @since 1.0.19
868
-	 * @return array
869
-	 */
870
-	public function get_data() {
871
-		return $this->data;
872
-	}
873
-
874
-	/**
875
-	 * Returns a field from the submission data
876
-	 *
877
-	 * @param string $field
878
-	 * @since 1.0.19
879
-	 * @return mixed|null
880
-	 */
881
-	public function get_field( $field, $sub_array_key = null ) {
882
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
883
-	}
884
-
885
-	/**
886
-	 * Checks if a required field is set.
887
-	 *
888
-	 * @since 1.0.19
889
-	 */
890
-	public function is_required_field_set( $field ) {
891
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
892
-	}
893
-
894
-	/**
895
-	 * Formats an amount
896
-	 *
897
-	 * @since 1.0.19
898
-	 */
899
-	public function format_amount( $amount ) {
900
-		return wpinv_price( $amount, $this->get_currency() );
901
-	}
788
+    /**
789
+     * Checks if this is the initial fetch.
790
+     *
791
+     * @return bool
792
+     * @since 1.0.19
793
+     */
794
+    public function is_initial_fetch() {
795
+        return empty( $this->data['initial_state'] );
796
+    }
797
+
798
+    /**
799
+     * Returns the total amount to collect for this submission.
800
+     *
801
+     * @since 1.0.19
802
+     */
803
+    public function get_total() {
804
+        $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
805
+        return max( $total, 0 );
806
+    }
807
+
808
+    /**
809
+     * Returns the recurring total amount to collect for this submission.
810
+     *
811
+     * @since 1.0.19
812
+     */
813
+    public function get_recurring_total() {
814
+        $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
815
+        return max( $total, 0 );
816
+    }
817
+
818
+    /**
819
+     * Whether payment details should be collected for this submission.
820
+     *
821
+     * @since 1.0.19
822
+     */
823
+    public function should_collect_payment_details() {
824
+        $initial   = $this->get_total();
825
+        $recurring = $this->get_recurring_total();
826
+
827
+        if ( $this->has_recurring == 0 ) {
828
+            $recurring = 0;
829
+        }
830
+
831
+        $collect = $initial > 0 || $recurring > 0;
832
+        return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
833
+    }
834
+
835
+    /**
836
+     * Returns the billing email of the user.
837
+     *
838
+     * @since 1.0.19
839
+     */
840
+    public function get_billing_email() {
841
+        return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
842
+    }
843
+
844
+    /**
845
+     * Checks if the submitter has a billing email.
846
+     *
847
+     * @since 1.0.19
848
+     */
849
+    public function has_billing_email() {
850
+        $billing_email = $this->get_billing_email();
851
+        return ! empty( $billing_email ) && is_email( $billing_email );
852
+    }
853
+
854
+    /**
855
+     * Returns the appropriate currency for the submission.
856
+     *
857
+     * @since 1.0.19
858
+     * @return string
859
+     */
860
+    public function get_currency() {
861
+        return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
862
+    }
863
+
864
+    /**
865
+     * Returns the raw submission data.
866
+     *
867
+     * @since 1.0.19
868
+     * @return array
869
+     */
870
+    public function get_data() {
871
+        return $this->data;
872
+    }
873
+
874
+    /**
875
+     * Returns a field from the submission data
876
+     *
877
+     * @param string $field
878
+     * @since 1.0.19
879
+     * @return mixed|null
880
+     */
881
+    public function get_field( $field, $sub_array_key = null ) {
882
+        return getpaid_get_array_field( $this->data, $field, $sub_array_key );
883
+    }
884
+
885
+    /**
886
+     * Checks if a required field is set.
887
+     *
888
+     * @since 1.0.19
889
+     */
890
+    public function is_required_field_set( $field ) {
891
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
892
+    }
893
+
894
+    /**
895
+     * Formats an amount
896
+     *
897
+     * @since 1.0.19
898
+     */
899
+    public function format_amount( $amount ) {
900
+        return wpinv_price( $amount, $this->get_currency() );
901
+    }
902 902
 
903 903
 }
Please login to merge, or discard this patch.
includes/class-getpaid-tax.php 1 patch
Indentation   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -13,168 +13,168 @@
 block discarded – undo
13 13
  */
14 14
 class GetPaid_Tax {
15 15
 
16
-	/**
17
-	 * Calculates tax for a line item.
18
-	 *
19
-	 * @param  float   $price              The price to calc tax on.
20
-	 * @param  array   $rates              The rates to apply.
21
-	 * @param  boolean $price_includes_tax Whether the passed price has taxes included.
22
-	 * @return array                       Array of tax name => tax amount.
23
-	 */
24
-	public static function calc_tax( $price, $rates, $price_includes_tax = false ) {
25
-
26
-		if ( $price_includes_tax ) {
27
-			$taxes = self::calc_inclusive_tax( $price, $rates );
28
-		} else {
29
-			$taxes = self::calc_exclusive_tax( $price, $rates );
30
-		}
31
-
32
-		return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax );
33
-
34
-	}
35
-
36
-	/**
37
-	 * Calc tax from inclusive price.
38
-	 *
39
-	 * @param  float $price Price to calculate tax for.
40
-	 * @param  array $rates Array of tax rates.
41
-	 * @return array
42
-	 */
43
-	public static function calc_inclusive_tax( $price, $rates ) {
44
-		$taxes     = array();
45
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
46
-
47
-		// Add tax rates.
48
-		$tax_rate  = 1 + ( array_sum( $tax_rates ) / 100 );
49
-
50
-		foreach ( $tax_rates as $name => $rate ) {
51
-			$the_rate       = ( $rate / 100 ) / $tax_rate;
52
-			$net_price      = $price - ( $the_rate * $price );
53
-			$tax_amount     = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price );
54
-			$taxes[ $name ] = $tax_amount;
55
-		}
56
-
57
-		// Round all taxes to precision (4DP) before passing them back.
58
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
59
-
60
-		return $taxes;
61
-	}
62
-
63
-	/**
64
-	 * Calc tax from exclusive price.
65
-	 *
66
-	 * @param  float $price Price to calculate tax for.
67
-	 * @param  array $rates Array of tax rates.
68
-	 * @return array
69
-	 */
70
-	public static function calc_exclusive_tax( $price, $rates ) {
71
-		$taxes     = array();
72
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
73
-
74
-		foreach ( $tax_rates as $name => $rate ) {
75
-
76
-			$tax_amount     = $price * ( $rate / 100 );
77
-			$taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price );
78
-
79
-		}
80
-
81
-		// Round all taxes to precision (4DP) before passing them back.
82
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
83
-
84
-		return $taxes;
85
-	}
86
-
87
-	/**
88
-	 * Get's an array of all tax rates.
89
-	 *
90
-	 * @return array
91
-	 */
92
-	public static function get_all_tax_rates() {
93
-
94
-		$rates = get_option( 'wpinv_tax_rates', array() );
95
-
96
-		return apply_filters(
97
-			'getpaid_get_all_tax_rates',
98
-			array_filter( wpinv_parse_list( $rates ) )
99
-		);
100
-
101
-	}
102
-
103
-	/**
104
-	 * Get's an array of default tax rates.
105
-	 *
106
-	 * @return array
107
-	 */
108
-	public static function get_default_tax_rates() {
109
-
110
-		return apply_filters(
111
-			'getpaid_get_default_tax_rates',
112
-			array(
113
-				array(
114
-					'country'   => wpinv_get_default_country(),
115
-					'state'     => wpinv_get_default_state(),
116
-					'global'    => true,
117
-					'rate'      => wpinv_get_default_tax_rate(),
118
-					'name'      => __( 'Base Tax', 'invoicing' ),
119
-				)
120
-			)
121
-		);
122
-
123
-	}
124
-
125
-	/**
126
-	 * Get's an array of tax rates for a given address.
127
-	 *
128
-	 * @param string $country
129
-	 * @param string $state
130
-	 * @return array
131
-	 */
132
-	public static function get_address_tax_rates( $country, $state ) {
133
-
134
-		$all_tax_rates  = self::get_all_tax_rates();
135
-		$matching_rates = array_merge(
136
-			wp_list_filter( $all_tax_rates, array( 'country' => $country ) ),
137
-			wp_list_filter( $all_tax_rates, array( 'country' => '' ) )
138
-		);
139
-
140
-		foreach ( $matching_rates as $i => $rate ) {
141
-
142
-			$states = array_filter( wpinv_clean( explode( ',', strtolower( $rate['state'] ) ) ) );
143
-			if ( empty( $rate['global'] ) && ! in_array( strtolower( $state ), $states ) ) {
144
-				unset( $matching_rates[ $i ] );
145
-			}
146
-
147
-		}
148
-
149
-		return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state );
150
-
151
-	}
152
-
153
-	/**
154
-	 * Sums a set of taxes to form a single total. Result is rounded to precision.
155
-	 *
156
-	 * @param  array $taxes Array of taxes.
157
-	 * @return float
158
-	 */
159
-	public static function get_tax_total( $taxes ) {
160
-		return self::round( array_sum( $taxes ) );
161
-	}
162
-
163
-	/**
164
-	 * Round to precision.
165
-	 *
166
-	 * Filter example: to return rounding to .5 cents you'd use:
167
-	 *
168
-	 * function euro_5cent_rounding( $in ) {
169
-	 *      return round( $in / 5, 2 ) * 5;
170
-	 * }
171
-	 * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' );
172
-	 *
173
-	 * @param float|int $in Value to round.
174
-	 * @return float
175
-	 */
176
-	public static function round( $in ) {
177
-		return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in );
178
-	}
16
+    /**
17
+     * Calculates tax for a line item.
18
+     *
19
+     * @param  float   $price              The price to calc tax on.
20
+     * @param  array   $rates              The rates to apply.
21
+     * @param  boolean $price_includes_tax Whether the passed price has taxes included.
22
+     * @return array                       Array of tax name => tax amount.
23
+     */
24
+    public static function calc_tax( $price, $rates, $price_includes_tax = false ) {
25
+
26
+        if ( $price_includes_tax ) {
27
+            $taxes = self::calc_inclusive_tax( $price, $rates );
28
+        } else {
29
+            $taxes = self::calc_exclusive_tax( $price, $rates );
30
+        }
31
+
32
+        return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax );
33
+
34
+    }
35
+
36
+    /**
37
+     * Calc tax from inclusive price.
38
+     *
39
+     * @param  float $price Price to calculate tax for.
40
+     * @param  array $rates Array of tax rates.
41
+     * @return array
42
+     */
43
+    public static function calc_inclusive_tax( $price, $rates ) {
44
+        $taxes     = array();
45
+        $tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
46
+
47
+        // Add tax rates.
48
+        $tax_rate  = 1 + ( array_sum( $tax_rates ) / 100 );
49
+
50
+        foreach ( $tax_rates as $name => $rate ) {
51
+            $the_rate       = ( $rate / 100 ) / $tax_rate;
52
+            $net_price      = $price - ( $the_rate * $price );
53
+            $tax_amount     = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price );
54
+            $taxes[ $name ] = $tax_amount;
55
+        }
56
+
57
+        // Round all taxes to precision (4DP) before passing them back.
58
+        $taxes = array_map( array( __CLASS__, 'round' ), $taxes );
59
+
60
+        return $taxes;
61
+    }
62
+
63
+    /**
64
+     * Calc tax from exclusive price.
65
+     *
66
+     * @param  float $price Price to calculate tax for.
67
+     * @param  array $rates Array of tax rates.
68
+     * @return array
69
+     */
70
+    public static function calc_exclusive_tax( $price, $rates ) {
71
+        $taxes     = array();
72
+        $tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
73
+
74
+        foreach ( $tax_rates as $name => $rate ) {
75
+
76
+            $tax_amount     = $price * ( $rate / 100 );
77
+            $taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price );
78
+
79
+        }
80
+
81
+        // Round all taxes to precision (4DP) before passing them back.
82
+        $taxes = array_map( array( __CLASS__, 'round' ), $taxes );
83
+
84
+        return $taxes;
85
+    }
86
+
87
+    /**
88
+     * Get's an array of all tax rates.
89
+     *
90
+     * @return array
91
+     */
92
+    public static function get_all_tax_rates() {
93
+
94
+        $rates = get_option( 'wpinv_tax_rates', array() );
95
+
96
+        return apply_filters(
97
+            'getpaid_get_all_tax_rates',
98
+            array_filter( wpinv_parse_list( $rates ) )
99
+        );
100
+
101
+    }
102
+
103
+    /**
104
+     * Get's an array of default tax rates.
105
+     *
106
+     * @return array
107
+     */
108
+    public static function get_default_tax_rates() {
109
+
110
+        return apply_filters(
111
+            'getpaid_get_default_tax_rates',
112
+            array(
113
+                array(
114
+                    'country'   => wpinv_get_default_country(),
115
+                    'state'     => wpinv_get_default_state(),
116
+                    'global'    => true,
117
+                    'rate'      => wpinv_get_default_tax_rate(),
118
+                    'name'      => __( 'Base Tax', 'invoicing' ),
119
+                )
120
+            )
121
+        );
122
+
123
+    }
124
+
125
+    /**
126
+     * Get's an array of tax rates for a given address.
127
+     *
128
+     * @param string $country
129
+     * @param string $state
130
+     * @return array
131
+     */
132
+    public static function get_address_tax_rates( $country, $state ) {
133
+
134
+        $all_tax_rates  = self::get_all_tax_rates();
135
+        $matching_rates = array_merge(
136
+            wp_list_filter( $all_tax_rates, array( 'country' => $country ) ),
137
+            wp_list_filter( $all_tax_rates, array( 'country' => '' ) )
138
+        );
139
+
140
+        foreach ( $matching_rates as $i => $rate ) {
141
+
142
+            $states = array_filter( wpinv_clean( explode( ',', strtolower( $rate['state'] ) ) ) );
143
+            if ( empty( $rate['global'] ) && ! in_array( strtolower( $state ), $states ) ) {
144
+                unset( $matching_rates[ $i ] );
145
+            }
146
+
147
+        }
148
+
149
+        return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state );
150
+
151
+    }
152
+
153
+    /**
154
+     * Sums a set of taxes to form a single total. Result is rounded to precision.
155
+     *
156
+     * @param  array $taxes Array of taxes.
157
+     * @return float
158
+     */
159
+    public static function get_tax_total( $taxes ) {
160
+        return self::round( array_sum( $taxes ) );
161
+    }
162
+
163
+    /**
164
+     * Round to precision.
165
+     *
166
+     * Filter example: to return rounding to .5 cents you'd use:
167
+     *
168
+     * function euro_5cent_rounding( $in ) {
169
+     *      return round( $in / 5, 2 ) * 5;
170
+     * }
171
+     * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' );
172
+     *
173
+     * @param float|int $in Value to round.
174
+     * @return float
175
+     */
176
+    public static function round( $in ) {
177
+        return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in );
178
+    }
179 179
 
180 180
 }
Please login to merge, or discard this patch.
invoicing.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,16 +19,16 @@  discard block
 block discarded – undo
19 19
 
20 20
 // Define constants.
21 21
 if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) {
22
-	define( 'WPINV_PLUGIN_FILE', __FILE__ );
22
+    define( 'WPINV_PLUGIN_FILE', __FILE__ );
23 23
 }
24 24
 
25 25
 if ( ! defined( 'WPINV_VERSION' ) ) {
26
-	define( 'WPINV_VERSION', '2.2.6' );
26
+    define( 'WPINV_VERSION', '2.2.6' );
27 27
 }
28 28
 
29 29
 // Include the main Invoicing class.
30 30
 if ( ! class_exists( 'WPInv_Plugin', false ) ) {
31
-	require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
31
+    require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
32 32
 }
33 33
 
34 34
 /**
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
         $GLOBALS['invoicing'] = new WPInv_Plugin();
44 44
     }
45 45
 
46
-	return $GLOBALS['invoicing'];
46
+    return $GLOBALS['invoicing'];
47 47
 }
48 48
 
49 49
 /**
Please login to merge, or discard this patch.
includes/wpinv-subscription.php 1 patch
Indentation   +1023 added lines, -1023 removed lines patch added patch discarded remove patch
@@ -15,125 +15,125 @@  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'      => '',
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
-	/**
66
-	 * Get the subscription if ID is passed, otherwise the subscription is new and empty.
67
-	 *
68
-	 * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69
-	 * @param  bool $deprecated
70
-	 */
71
-	function __construct( $subscription = 0, $deprecated = false ) {
72
-
73
-		parent::__construct( $subscription );
74
-
75
-		if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
-			$this->set_id( $subscription );
77
-		} elseif ( $subscription instanceof self ) {
78
-			$this->set_id( $subscription->get_id() );
79
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
80
-			$this->set_id( $subscription_id );
81
-		} elseif ( ! empty( $subscription->id ) ) {
82
-			$this->set_id( $subscription->id );
83
-		} else {
84
-			$this->set_object_read( true );
85
-		}
86
-
87
-		// Load the datastore.
88
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
89
-
90
-		if ( $this->get_id() > 0 ) {
91
-			$this->data_store->read( $this );
92
-		}
93
-
94
-	}
95
-
96
-	/**
97
-	 * Given an invoice id, profile id, transaction id, it returns the subscription's id.
98
-	 *
99
-	 *
100
-	 * @static
101
-	 * @param string $value
102
-	 * @param string $field Either invoice_id, transaction_id or profile_id.
103
-	 * @since 1.0.19
104
-	 * @return int
105
-	 */
106
-	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'      => '',
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
+    /**
66
+     * Get the subscription if ID is passed, otherwise the subscription is new and empty.
67
+     *
68
+     * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69
+     * @param  bool $deprecated
70
+     */
71
+    function __construct( $subscription = 0, $deprecated = false ) {
72
+
73
+        parent::__construct( $subscription );
74
+
75
+        if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
+            $this->set_id( $subscription );
77
+        } elseif ( $subscription instanceof self ) {
78
+            $this->set_id( $subscription->get_id() );
79
+        } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
80
+            $this->set_id( $subscription_id );
81
+        } elseif ( ! empty( $subscription->id ) ) {
82
+            $this->set_id( $subscription->id );
83
+        } else {
84
+            $this->set_object_read( true );
85
+        }
86
+
87
+        // Load the datastore.
88
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
89
+
90
+        if ( $this->get_id() > 0 ) {
91
+            $this->data_store->read( $this );
92
+        }
93
+
94
+    }
95
+
96
+    /**
97
+     * Given an invoice id, profile id, transaction id, it returns the subscription's id.
98
+     *
99
+     *
100
+     * @static
101
+     * @param string $value
102
+     * @param string $field Either invoice_id, transaction_id or profile_id.
103
+     * @since 1.0.19
104
+     * @return int
105
+     */
106
+    public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
107 107
         global $wpdb;
108 108
 
109
-		// Trim the value.
110
-		$value = trim( $value );
109
+        // Trim the value.
110
+        $value = trim( $value );
111 111
 
112
-		if ( empty( $value ) ) {
113
-			return 0;
114
-		}
112
+        if ( empty( $value ) ) {
113
+            return 0;
114
+        }
115 115
 
116
-		if ( 'invoice_id' == $field ) {
117
-			$field = 'parent_payment_id';
118
-		}
116
+        if ( 'invoice_id' == $field ) {
117
+            $field = 'parent_payment_id';
118
+        }
119 119
 
120 120
         // Valid fields.
121 121
         $fields = array(
122
-			'parent_payment_id',
123
-			'transaction_id',
124
-			'profile_id'
125
-		);
126
-
127
-		// Ensure a field has been passed.
128
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
129
-			return 0;
130
-		}
131
-
132
-		// Maybe retrieve from the cache.
133
-		$subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
-		if ( ! empty( $subscription_id ) ) {
135
-			return $subscription_id;
136
-		}
122
+            'parent_payment_id',
123
+            'transaction_id',
124
+            'profile_id'
125
+        );
126
+
127
+        // Ensure a field has been passed.
128
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
129
+            return 0;
130
+        }
131
+
132
+        // Maybe retrieve from the cache.
133
+        $subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
+        if ( ! empty( $subscription_id ) ) {
135
+            return $subscription_id;
136
+        }
137 137
 
138 138
         // Fetch from the db.
139 139
         $table            = $wpdb->prefix . 'wpinv_subscriptions';
@@ -141,34 +141,34 @@  discard block
 block discarded – undo
141 141
             $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
142 142
         );
143 143
 
144
-		if ( empty( $subscription_id ) ) {
145
-			return 0;
146
-		}
144
+        if ( empty( $subscription_id ) ) {
145
+            return 0;
146
+        }
147 147
 
148
-		// Update the cache with our data.
149
-		wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
148
+        // Update the cache with our data.
149
+        wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
150 150
 
151
-		return $subscription_id;
152
-	}
151
+        return $subscription_id;
152
+    }
153 153
 
154
-	/**
154
+    /**
155 155
      * Clears the subscription's cache.
156 156
      */
157 157
     public function clear_cache() {
158
-		wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
159
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
160
-		wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
161
-		wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
162
-	}
158
+        wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
159
+        wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
160
+        wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
161
+        wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
162
+    }
163 163
 
164
-	/**
164
+    /**
165 165
      * Checks if a subscription key is set.
166 166
      */
167 167
     public function _isset( $key ) {
168 168
         return isset( $this->data[$key] ) || method_exists( $this, "get_$key" );
169
-	}
169
+    }
170 170
 
171
-	/*
171
+    /*
172 172
 	|--------------------------------------------------------------------------
173 173
 	| CRUD methods
174 174
 	|--------------------------------------------------------------------------
@@ -177,545 +177,545 @@  discard block
 block discarded – undo
177 177
 	|
178 178
     */
179 179
 
180
-	/*
181
-	|--------------------------------------------------------------------------
182
-	| Getters
183
-	|--------------------------------------------------------------------------
184
-	*/
180
+    /*
181
+	|--------------------------------------------------------------------------
182
+	| Getters
183
+	|--------------------------------------------------------------------------
184
+	*/
185
+
186
+    /**
187
+     * Get customer id.
188
+     *
189
+     * @since 1.0.19
190
+     * @param  string $context View or edit context.
191
+     * @return int
192
+     */
193
+    public function get_customer_id( $context = 'view' ) {
194
+        return (int) $this->get_prop( 'customer_id', $context );
195
+    }
196
+
197
+    /**
198
+     * Get customer information.
199
+     *
200
+     * @since 1.0.19
201
+     * @param  string $context View or edit context.
202
+     * @return WP_User|false WP_User object on success, false on failure.
203
+     */
204
+    public function get_customer( $context = 'view' ) {
205
+        return get_userdata( $this->get_customer_id( $context ) );
206
+    }
207
+
208
+    /**
209
+     * Get parent invoice id.
210
+     *
211
+     * @since 1.0.19
212
+     * @param  string $context View or edit context.
213
+     * @return int
214
+     */
215
+    public function get_parent_invoice_id( $context = 'view' ) {
216
+        return (int) $this->get_prop( 'parent_payment_id', $context );
217
+    }
218
+
219
+    /**
220
+     * Alias for self::get_parent_invoice_id().
221
+     *
222
+     * @since 1.0.19
223
+     * @param  string $context View or edit context.
224
+     * @return int
225
+     */
226
+    public function get_parent_payment_id( $context = 'view' ) {
227
+        return $this->get_parent_invoice_id( $context );
228
+    }
229
+
230
+    /**
231
+     * Alias for self::get_parent_invoice_id().
232
+     *
233
+     * @since  1.0.0
234
+     * @return int
235
+     */
236
+    public function get_original_payment_id( $context = 'view' ) {
237
+        return $this->get_parent_invoice_id( $context );
238
+    }
239
+
240
+    /**
241
+     * Get parent invoice.
242
+     *
243
+     * @since 1.0.19
244
+     * @param  string $context View or edit context.
245
+     * @return WPInv_Invoice
246
+     */
247
+    public function get_parent_invoice( $context = 'view' ) {
248
+        return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
249
+    }
250
+
251
+    /**
252
+     * Alias for self::get_parent_invoice().
253
+     *
254
+     * @since 1.0.19
255
+     * @param  string $context View or edit context.
256
+     * @return WPInv_Invoice
257
+     */
258
+    public function get_parent_payment( $context = 'view' ) {
259
+        return $this->get_parent_invoice( $context );
260
+    }
261
+
262
+    /**
263
+     * Get subscription's product id.
264
+     *
265
+     * @since 1.0.19
266
+     * @param  string $context View or edit context.
267
+     * @return int
268
+     */
269
+    public function get_product_id( $context = 'view' ) {
270
+        return (int) $this->get_prop( 'product_id', $context );
271
+    }
272
+
273
+    /**
274
+     * Get the subscription product.
275
+     *
276
+     * @since 1.0.19
277
+     * @param  string $context View or edit context.
278
+     * @return WPInv_Item
279
+     */
280
+    public function get_product( $context = 'view' ) {
281
+        return new WPInv_Item( $this->get_product_id( $context ) );
282
+    }
283
+
284
+    /**
285
+     * Get parent invoice's gateway.
286
+     *
287
+     * Here for backwards compatibility.
288
+     *
289
+     * @since 1.0.19
290
+     * @param  string $context View or edit context.
291
+     * @return string
292
+     */
293
+    public function get_gateway( $context = 'view' ) {
294
+        return $this->get_parent_invoice( $context )->get_gateway();
295
+    }
296
+
297
+    /**
298
+     * Get the period of a renewal.
299
+     *
300
+     * @since 1.0.19
301
+     * @param  string $context View or edit context.
302
+     * @return string
303
+     */
304
+    public function get_period( $context = 'view' ) {
305
+        return $this->get_prop( 'period', $context );
306
+    }
307
+
308
+    /**
309
+     * Get number of periods each renewal is valid for.
310
+     *
311
+     * @since 1.0.19
312
+     * @param  string $context View or edit context.
313
+     * @return int
314
+     */
315
+    public function get_frequency( $context = 'view' ) {
316
+        return (int) $this->get_prop( 'frequency', $context );
317
+    }
318
+
319
+    /**
320
+     * Get the initial amount for the subscription.
321
+     *
322
+     * @since 1.0.19
323
+     * @param  string $context View or edit context.
324
+     * @return float
325
+     */
326
+    public function get_initial_amount( $context = 'view' ) {
327
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
328
+    }
329
+
330
+    /**
331
+     * Get the recurring amount for the subscription.
332
+     *
333
+     * @since 1.0.19
334
+     * @param  string $context View or edit context.
335
+     * @return float
336
+     */
337
+    public function get_recurring_amount( $context = 'view' ) {
338
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
339
+    }
340
+
341
+    /**
342
+     * Get number of times that this subscription can be renewed.
343
+     *
344
+     * @since 1.0.19
345
+     * @param  string $context View or edit context.
346
+     * @return int
347
+     */
348
+    public function get_bill_times( $context = 'view' ) {
349
+        return (int) $this->get_prop( 'bill_times', $context );
350
+    }
351
+
352
+    /**
353
+     * Get transaction id of this subscription's parent invoice.
354
+     *
355
+     * @since 1.0.19
356
+     * @param  string $context View or edit context.
357
+     * @return string
358
+     */
359
+    public function get_transaction_id( $context = 'view' ) {
360
+        return $this->get_prop( 'transaction_id', $context );
361
+    }
362
+
363
+    /**
364
+     * Get the date that the subscription was created.
365
+     *
366
+     * @since 1.0.19
367
+     * @param  string $context View or edit context.
368
+     * @return string
369
+     */
370
+    public function get_created( $context = 'view' ) {
371
+        return $this->get_prop( 'created', $context );
372
+    }
373
+
374
+    /**
375
+     * Alias for self::get_created().
376
+     *
377
+     * @since 1.0.19
378
+     * @param  string $context View or edit context.
379
+     * @return string
380
+     */
381
+    public function get_date_created( $context = 'view' ) {
382
+        return $this->get_created( $context );
383
+    }
384
+
385
+    /**
386
+     * Retrieves the creation date in a timestamp
387
+     *
388
+     * @since  1.0.0
389
+     * @return int
390
+     */
391
+    public function get_time_created() {
392
+        $created = $this->get_date_created();
393
+        return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
394
+    }
395
+
396
+    /**
397
+     * Get GMT date when the subscription was created.
398
+     *
399
+     * @since 1.0.19
400
+     * @param  string $context View or edit context.
401
+     * @return string
402
+     */
403
+    public function get_date_created_gmt( $context = 'view' ) {
404
+        $date = $this->get_date_created( $context );
405
+
406
+        if ( $date ) {
407
+            $date = get_gmt_from_date( $date );
408
+        }
409
+        return $date;
410
+    }
411
+
412
+    /**
413
+     * Get the date that the subscription will renew.
414
+     *
415
+     * @since 1.0.19
416
+     * @param  string $context View or edit context.
417
+     * @return string
418
+     */
419
+    public function get_next_renewal_date( $context = 'view' ) {
420
+        return $this->get_prop( 'expiration', $context );
421
+    }
422
+
423
+    /**
424
+     * Alias for self::get_next_renewal_date().
425
+     *
426
+     * @since 1.0.19
427
+     * @param  string $context View or edit context.
428
+     * @return string
429
+     */
430
+    public function get_expiration( $context = 'view' ) {
431
+        return $this->get_next_renewal_date( $context );
432
+    }
433
+
434
+    /**
435
+     * Retrieves the expiration date in a timestamp
436
+     *
437
+     * @since  1.0.0
438
+     * @return int
439
+     */
440
+    public function get_expiration_time() {
441
+        $expiration = $this->get_expiration();
442
+
443
+        if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
444
+            return current_time( 'timestamp' );
445
+        }
446
+
447
+        $expiration = strtotime( $expiration, current_time( 'timestamp' ) );
448
+        return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
449
+    }
450
+
451
+    /**
452
+     * Get GMT date when the subscription will renew.
453
+     *
454
+     * @since 1.0.19
455
+     * @param  string $context View or edit context.
456
+     * @return string
457
+     */
458
+    public function get_next_renewal_date_gmt( $context = 'view' ) {
459
+        $date = $this->get_next_renewal_date( $context );
460
+
461
+        if ( $date ) {
462
+            $date = get_gmt_from_date( $date );
463
+        }
464
+        return $date;
465
+    }
466
+
467
+    /**
468
+     * Get the subscription's trial period.
469
+     *
470
+     * @since 1.0.19
471
+     * @param  string $context View or edit context.
472
+     * @return string
473
+     */
474
+    public function get_trial_period( $context = 'view' ) {
475
+        return $this->get_prop( 'trial_period', $context );
476
+    }
477
+
478
+    /**
479
+     * Get the subscription's status.
480
+     *
481
+     * @since 1.0.19
482
+     * @param  string $context View or edit context.
483
+     * @return string
484
+     */
485
+    public function get_status( $context = 'view' ) {
486
+        return $this->get_prop( 'status', $context );
487
+    }
488
+
489
+    /**
490
+     * Get the subscription's profile id.
491
+     *
492
+     * @since 1.0.19
493
+     * @param  string $context View or edit context.
494
+     * @return string
495
+     */
496
+    public function get_profile_id( $context = 'view' ) {
497
+        return $this->get_prop( 'profile_id', $context );
498
+    }
499
+
500
+    /*
501
+	|--------------------------------------------------------------------------
502
+	| Setters
503
+	|--------------------------------------------------------------------------
504
+	*/
505
+
506
+    /**
507
+     * Set customer id.
508
+     *
509
+     * @since 1.0.19
510
+     * @param  int $value The customer's id.
511
+     */
512
+    public function set_customer_id( $value ) {
513
+        $this->set_prop( 'customer_id', (int) $value );
514
+    }
515
+
516
+    /**
517
+     * Set parent invoice id.
518
+     *
519
+     * @since 1.0.19
520
+     * @param  int $value The parent invoice id.
521
+     */
522
+    public function set_parent_invoice_id( $value ) {
523
+        $this->set_prop( 'parent_payment_id', (int) $value );
524
+    }
525
+
526
+    /**
527
+     * Alias for self::set_parent_invoice_id().
528
+     *
529
+     * @since 1.0.19
530
+     * @param  int $value The parent invoice id.
531
+     */
532
+    public function set_parent_payment_id( $value ) {
533
+        $this->set_parent_invoice_id( $value );
534
+    }
535
+
536
+    /**
537
+     * Alias for self::set_parent_invoice_id().
538
+     *
539
+     * @since 1.0.19
540
+     * @param  int $value The parent invoice id.
541
+     */
542
+    public function set_original_payment_id( $value ) {
543
+        $this->set_parent_invoice_id( $value );
544
+    }
545
+
546
+    /**
547
+     * Set subscription's product id.
548
+     *
549
+     * @since 1.0.19
550
+     * @param  int $value The subscription product id.
551
+     */
552
+    public function set_product_id( $value ) {
553
+        $this->set_prop( 'product_id', (int) $value );
554
+    }
555
+
556
+    /**
557
+     * Set the period of a renewal.
558
+     *
559
+     * @since 1.0.19
560
+     * @param  string $value The renewal period.
561
+     */
562
+    public function set_period( $value ) {
563
+        $this->set_prop( 'period', $value );
564
+    }
565
+
566
+    /**
567
+     * Set number of periods each renewal is valid for.
568
+     *
569
+     * @since 1.0.19
570
+     * @param  int $value The subscription frequency.
571
+     */
572
+    public function set_frequency( $value ) {
573
+        $value = empty( $value ) ? 1 : (int) $value;
574
+        $this->set_prop( 'frequency', absint( $value ) );
575
+    }
576
+
577
+    /**
578
+     * Set the initial amount for the subscription.
579
+     *
580
+     * @since 1.0.19
581
+     * @param  float $value The initial subcription amount.
582
+     */
583
+    public function set_initial_amount( $value ) {
584
+        $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
585
+    }
586
+
587
+    /**
588
+     * Set the recurring amount for the subscription.
589
+     *
590
+     * @since 1.0.19
591
+     * @param  float $value The recurring subcription amount.
592
+     */
593
+    public function set_recurring_amount( $value ) {
594
+        $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
595
+    }
596
+
597
+    /**
598
+     * Set number of times that this subscription can be renewed.
599
+     *
600
+     * @since 1.0.19
601
+     * @param  int $value Bill times.
602
+     */
603
+    public function set_bill_times( $value ) {
604
+        $this->set_prop( 'bill_times', (int) $value );
605
+    }
606
+
607
+    /**
608
+     * Get transaction id of this subscription's parent invoice.
609
+     *
610
+     * @since 1.0.19
611
+     * @param string $value Bill times.
612
+     */
613
+    public function set_transaction_id( $value ) {
614
+        $this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
615
+    }
616
+
617
+    /**
618
+     * Set date when this subscription started.
619
+     *
620
+     * @since 1.0.19
621
+     * @param string $value strtotime compliant date.
622
+     */
623
+    public function set_created( $value ) {
624
+        $date = strtotime( $value );
625
+
626
+        if ( $date && $value !== '0000-00-00 00:00:00' ) {
627
+            $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) );
628
+            return;
629
+        }
630
+
631
+        $this->set_prop( 'created', '' );
185 632
 
186
-	/**
187
-	 * Get customer id.
188
-	 *
189
-	 * @since 1.0.19
190
-	 * @param  string $context View or edit context.
191
-	 * @return int
192
-	 */
193
-	public function get_customer_id( $context = 'view' ) {
194
-		return (int) $this->get_prop( 'customer_id', $context );
195
-	}
196
-
197
-	/**
198
-	 * Get customer information.
199
-	 *
200
-	 * @since 1.0.19
201
-	 * @param  string $context View or edit context.
202
-	 * @return WP_User|false WP_User object on success, false on failure.
203
-	 */
204
-	public function get_customer( $context = 'view' ) {
205
-		return get_userdata( $this->get_customer_id( $context ) );
206
-	}
207
-
208
-	/**
209
-	 * Get parent invoice id.
210
-	 *
211
-	 * @since 1.0.19
212
-	 * @param  string $context View or edit context.
213
-	 * @return int
214
-	 */
215
-	public function get_parent_invoice_id( $context = 'view' ) {
216
-		return (int) $this->get_prop( 'parent_payment_id', $context );
217
-	}
218
-
219
-	/**
220
-	 * Alias for self::get_parent_invoice_id().
221
-	 *
222
-	 * @since 1.0.19
223
-	 * @param  string $context View or edit context.
224
-	 * @return int
225
-	 */
226
-    public function get_parent_payment_id( $context = 'view' ) {
227
-        return $this->get_parent_invoice_id( $context );
228
-	}
633
+    }
229 634
 
230
-	/**
231
-     * Alias for self::get_parent_invoice_id().
635
+    /**
636
+     * Alias for self::set_created().
232 637
      *
233
-     * @since  1.0.0
234
-     * @return int
638
+     * @since 1.0.19
639
+     * @param string $value strtotime compliant date.
235 640
      */
236
-    public function get_original_payment_id( $context = 'view' ) {
237
-        return $this->get_parent_invoice_id( $context );
641
+    public function set_date_created( $value ) {
642
+        $this->set_created( $value );
238 643
     }
239 644
 
240
-	/**
241
-	 * Get parent invoice.
242
-	 *
243
-	 * @since 1.0.19
244
-	 * @param  string $context View or edit context.
245
-	 * @return WPInv_Invoice
246
-	 */
247
-	public function get_parent_invoice( $context = 'view' ) {
248
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
249
-	}
250
-
251
-	/**
252
-	 * Alias for self::get_parent_invoice().
253
-	 *
254
-	 * @since 1.0.19
255
-	 * @param  string $context View or edit context.
256
-	 * @return WPInv_Invoice
257
-	 */
258
-    public function get_parent_payment( $context = 'view' ) {
259
-        return $this->get_parent_invoice( $context );
260
-	}
261
-
262
-	/**
263
-	 * Get subscription's product id.
264
-	 *
265
-	 * @since 1.0.19
266
-	 * @param  string $context View or edit context.
267
-	 * @return int
268
-	 */
269
-	public function get_product_id( $context = 'view' ) {
270
-		return (int) $this->get_prop( 'product_id', $context );
271
-	}
272
-
273
-	/**
274
-	 * Get the subscription product.
275
-	 *
276
-	 * @since 1.0.19
277
-	 * @param  string $context View or edit context.
278
-	 * @return WPInv_Item
279
-	 */
280
-	public function get_product( $context = 'view' ) {
281
-		return new WPInv_Item( $this->get_product_id( $context ) );
282
-	}
283
-
284
-	/**
285
-	 * Get parent invoice's gateway.
286
-	 *
287
-	 * Here for backwards compatibility.
288
-	 *
289
-	 * @since 1.0.19
290
-	 * @param  string $context View or edit context.
291
-	 * @return string
292
-	 */
293
-	public function get_gateway( $context = 'view' ) {
294
-		return $this->get_parent_invoice( $context )->get_gateway();
295
-	}
296
-
297
-	/**
298
-	 * Get the period of a renewal.
299
-	 *
300
-	 * @since 1.0.19
301
-	 * @param  string $context View or edit context.
302
-	 * @return string
303
-	 */
304
-	public function get_period( $context = 'view' ) {
305
-		return $this->get_prop( 'period', $context );
306
-	}
307
-
308
-	/**
309
-	 * Get number of periods each renewal is valid for.
310
-	 *
311
-	 * @since 1.0.19
312
-	 * @param  string $context View or edit context.
313
-	 * @return int
314
-	 */
315
-	public function get_frequency( $context = 'view' ) {
316
-		return (int) $this->get_prop( 'frequency', $context );
317
-	}
318
-
319
-	/**
320
-	 * Get the initial amount for the subscription.
321
-	 *
322
-	 * @since 1.0.19
323
-	 * @param  string $context View or edit context.
324
-	 * @return float
325
-	 */
326
-	public function get_initial_amount( $context = 'view' ) {
327
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
328
-	}
329
-
330
-	/**
331
-	 * Get the recurring amount for the subscription.
332
-	 *
333
-	 * @since 1.0.19
334
-	 * @param  string $context View or edit context.
335
-	 * @return float
336
-	 */
337
-	public function get_recurring_amount( $context = 'view' ) {
338
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
339
-	}
340
-
341
-	/**
342
-	 * Get number of times that this subscription can be renewed.
343
-	 *
344
-	 * @since 1.0.19
345
-	 * @param  string $context View or edit context.
346
-	 * @return int
347
-	 */
348
-	public function get_bill_times( $context = 'view' ) {
349
-		return (int) $this->get_prop( 'bill_times', $context );
350
-	}
351
-
352
-	/**
353
-	 * Get transaction id of this subscription's parent invoice.
354
-	 *
355
-	 * @since 1.0.19
356
-	 * @param  string $context View or edit context.
357
-	 * @return string
358
-	 */
359
-	public function get_transaction_id( $context = 'view' ) {
360
-		return $this->get_prop( 'transaction_id', $context );
361
-	}
362
-
363
-	/**
364
-	 * Get the date that the subscription was created.
365
-	 *
366
-	 * @since 1.0.19
367
-	 * @param  string $context View or edit context.
368
-	 * @return string
369
-	 */
370
-	public function get_created( $context = 'view' ) {
371
-		return $this->get_prop( 'created', $context );
372
-	}
373
-
374
-	/**
375
-	 * Alias for self::get_created().
376
-	 *
377
-	 * @since 1.0.19
378
-	 * @param  string $context View or edit context.
379
-	 * @return string
380
-	 */
381
-	public function get_date_created( $context = 'view' ) {
382
-		return $this->get_created( $context );
383
-	}
384
-
385
-	/**
386
-	 * Retrieves the creation date in a timestamp
387
-	 *
388
-	 * @since  1.0.0
389
-	 * @return int
390
-	 */
391
-	public function get_time_created() {
392
-		$created = $this->get_date_created();
393
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
394
-	}
395
-
396
-	/**
397
-	 * Get GMT date when the subscription was created.
398
-	 *
399
-	 * @since 1.0.19
400
-	 * @param  string $context View or edit context.
401
-	 * @return string
402
-	 */
403
-	public function get_date_created_gmt( $context = 'view' ) {
404
-        $date = $this->get_date_created( $context );
645
+    /**
646
+     * Set the date that the subscription will renew.
647
+     *
648
+     * @since 1.0.19
649
+     * @param string $value strtotime compliant date.
650
+     */
651
+    public function set_next_renewal_date( $value ) {
652
+        $date = strtotime( $value );
405 653
 
406
-        if ( $date ) {
407
-            $date = get_gmt_from_date( $date );
654
+        if ( $date && $value !== '0000-00-00 00:00:00' ) {
655
+            $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
656
+            return;
408 657
         }
409
-		return $date;
410
-	}
411
-
412
-	/**
413
-	 * Get the date that the subscription will renew.
414
-	 *
415
-	 * @since 1.0.19
416
-	 * @param  string $context View or edit context.
417
-	 * @return string
418
-	 */
419
-	public function get_next_renewal_date( $context = 'view' ) {
420
-		return $this->get_prop( 'expiration', $context );
421
-	}
422
-
423
-	/**
424
-	 * Alias for self::get_next_renewal_date().
425
-	 *
426
-	 * @since 1.0.19
427
-	 * @param  string $context View or edit context.
428
-	 * @return string
429
-	 */
430
-	public function get_expiration( $context = 'view' ) {
431
-		return $this->get_next_renewal_date( $context );
432
-	}
433
-
434
-	/**
435
-	 * Retrieves the expiration date in a timestamp
436
-	 *
437
-	 * @since  1.0.0
438
-	 * @return int
439
-	 */
440
-	public function get_expiration_time() {
441
-		$expiration = $this->get_expiration();
442
-
443
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
444
-			return current_time( 'timestamp' );
445
-		}
446
-
447
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
448
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
449
-	}
450
-
451
-	/**
452
-	 * Get GMT date when the subscription will renew.
453
-	 *
454
-	 * @since 1.0.19
455
-	 * @param  string $context View or edit context.
456
-	 * @return string
457
-	 */
458
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
459
-        $date = $this->get_next_renewal_date( $context );
460 658
 
461
-        if ( $date ) {
462
-            $date = get_gmt_from_date( $date );
463
-        }
464
-		return $date;
465
-	}
466
-
467
-	/**
468
-	 * Get the subscription's trial period.
469
-	 *
470
-	 * @since 1.0.19
471
-	 * @param  string $context View or edit context.
472
-	 * @return string
473
-	 */
474
-	public function get_trial_period( $context = 'view' ) {
475
-		return $this->get_prop( 'trial_period', $context );
476
-	}
477
-
478
-	/**
479
-	 * Get the subscription's status.
480
-	 *
481
-	 * @since 1.0.19
482
-	 * @param  string $context View or edit context.
483
-	 * @return string
484
-	 */
485
-	public function get_status( $context = 'view' ) {
486
-		return $this->get_prop( 'status', $context );
487
-	}
488
-
489
-	/**
490
-	 * Get the subscription's profile id.
491
-	 *
492
-	 * @since 1.0.19
493
-	 * @param  string $context View or edit context.
494
-	 * @return string
495
-	 */
496
-	public function get_profile_id( $context = 'view' ) {
497
-		return $this->get_prop( 'profile_id', $context );
498
-	}
499
-
500
-	/*
501
-	|--------------------------------------------------------------------------
502
-	| Setters
503
-	|--------------------------------------------------------------------------
504
-	*/
659
+        $this->set_prop( 'expiration', '' );
505 660
 
506
-	/**
507
-	 * Set customer id.
508
-	 *
509
-	 * @since 1.0.19
510
-	 * @param  int $value The customer's id.
511
-	 */
512
-	public function set_customer_id( $value ) {
513
-		$this->set_prop( 'customer_id', (int) $value );
514
-	}
515
-
516
-	/**
517
-	 * Set parent invoice id.
518
-	 *
519
-	 * @since 1.0.19
520
-	 * @param  int $value The parent invoice id.
521
-	 */
522
-	public function set_parent_invoice_id( $value ) {
523
-		$this->set_prop( 'parent_payment_id', (int) $value );
524
-	}
525
-
526
-	/**
527
-	 * Alias for self::set_parent_invoice_id().
528
-	 *
529
-	 * @since 1.0.19
530
-	 * @param  int $value The parent invoice id.
531
-	 */
532
-    public function set_parent_payment_id( $value ) {
533
-        $this->set_parent_invoice_id( $value );
534
-	}
661
+    }
535 662
 
536
-	/**
537
-     * Alias for self::set_parent_invoice_id().
663
+    /**
664
+     * Alias for self::set_next_renewal_date().
538 665
      *
539 666
      * @since 1.0.19
540
-	 * @param  int $value The parent invoice id.
667
+     * @param string $value strtotime compliant date.
541 668
      */
542
-    public function set_original_payment_id( $value ) {
543
-        $this->set_parent_invoice_id( $value );
544
-	}
545
-
546
-	/**
547
-	 * Set subscription's product id.
548
-	 *
549
-	 * @since 1.0.19
550
-	 * @param  int $value The subscription product id.
551
-	 */
552
-	public function set_product_id( $value ) {
553
-		$this->set_prop( 'product_id', (int) $value );
554
-	}
555
-
556
-	/**
557
-	 * Set the period of a renewal.
558
-	 *
559
-	 * @since 1.0.19
560
-	 * @param  string $value The renewal period.
561
-	 */
562
-	public function set_period( $value ) {
563
-		$this->set_prop( 'period', $value );
564
-	}
565
-
566
-	/**
567
-	 * Set number of periods each renewal is valid for.
568
-	 *
569
-	 * @since 1.0.19
570
-	 * @param  int $value The subscription frequency.
571
-	 */
572
-	public function set_frequency( $value ) {
573
-		$value = empty( $value ) ? 1 : (int) $value;
574
-		$this->set_prop( 'frequency', absint( $value ) );
575
-	}
576
-
577
-	/**
578
-	 * Set the initial amount for the subscription.
579
-	 *
580
-	 * @since 1.0.19
581
-	 * @param  float $value The initial subcription amount.
582
-	 */
583
-	public function set_initial_amount( $value ) {
584
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
585
-	}
586
-
587
-	/**
588
-	 * Set the recurring amount for the subscription.
589
-	 *
590
-	 * @since 1.0.19
591
-	 * @param  float $value The recurring subcription amount.
592
-	 */
593
-	public function set_recurring_amount( $value ) {
594
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
595
-	}
596
-
597
-	/**
598
-	 * Set number of times that this subscription can be renewed.
599
-	 *
600
-	 * @since 1.0.19
601
-	 * @param  int $value Bill times.
602
-	 */
603
-	public function set_bill_times( $value ) {
604
-		$this->set_prop( 'bill_times', (int) $value );
605
-	}
606
-
607
-	/**
608
-	 * Get transaction id of this subscription's parent invoice.
609
-	 *
610
-	 * @since 1.0.19
611
-	 * @param string $value Bill times.
612
-	 */
613
-	public function set_transaction_id( $value ) {
614
-		$this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
615
-	}
616
-
617
-	/**
618
-	 * Set date when this subscription started.
619
-	 *
620
-	 * @since 1.0.19
621
-	 * @param string $value strtotime compliant date.
622
-	 */
623
-	public function set_created( $value ) {
624
-        $date = strtotime( $value );
669
+    public function set_expiration( $value ) {
670
+        $this->set_next_renewal_date( $value );
671
+    }
625 672
 
626
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
627
-            $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) );
673
+    /**
674
+     * Set the subscription's trial period.
675
+     *
676
+     * @since 1.0.19
677
+     * @param string $value trial period e.g 1 year.
678
+     */
679
+    public function set_trial_period( $value ) {
680
+        $this->set_prop( 'trial_period', $value );
681
+    }
682
+
683
+    /**
684
+     * Set the subscription's status.
685
+     *
686
+     * @since 1.0.19
687
+     * @param string $new_status    New subscription status.
688
+     */
689
+    public function set_status( $new_status ) {
690
+
691
+        // Abort if this is not a valid status;
692
+        if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
628 693
             return;
629 694
         }
630 695
 
631
-		$this->set_prop( 'created', '' );
696
+        $old_status = $this->get_status();
697
+        $this->set_prop( 'status', $new_status );
632 698
 
633
-	}
699
+        if ( true === $this->object_read && $old_status !== $new_status ) {
700
+            $this->status_transition = array(
701
+                'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
702
+                'to'     => $new_status,
703
+            );
704
+        }
634 705
 
635
-	/**
636
-	 * Alias for self::set_created().
637
-	 *
638
-	 * @since 1.0.19
639
-	 * @param string $value strtotime compliant date.
640
-	 */
641
-	public function set_date_created( $value ) {
642
-		$this->set_created( $value );
643 706
     }
644 707
 
645
-	/**
646
-	 * Set the date that the subscription will renew.
647
-	 *
648
-	 * @since 1.0.19
649
-	 * @param string $value strtotime compliant date.
650
-	 */
651
-	public function set_next_renewal_date( $value ) {
652
-		$date = strtotime( $value );
708
+    /**
709
+     * Set the subscription's (remote) profile id.
710
+     *
711
+     * @since 1.0.19
712
+     * @param  string $value the remote profile id.
713
+     */
714
+    public function set_profile_id( $value ) {
715
+        $this->set_prop( 'profile_id', sanitize_text_field( $value ) );
716
+    }
653 717
 
654
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
655
-            $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
656
-            return;
657
-		}
658
-
659
-		$this->set_prop( 'expiration', '' );
660
-
661
-	}
662
-
663
-	/**
664
-	 * Alias for self::set_next_renewal_date().
665
-	 *
666
-	 * @since 1.0.19
667
-	 * @param string $value strtotime compliant date.
668
-	 */
669
-	public function set_expiration( $value ) {
670
-		$this->set_next_renewal_date( $value );
671
-    }
672
-
673
-	/**
674
-	 * Set the subscription's trial period.
675
-	 *
676
-	 * @since 1.0.19
677
-	 * @param string $value trial period e.g 1 year.
678
-	 */
679
-	public function set_trial_period( $value ) {
680
-		$this->set_prop( 'trial_period', $value );
681
-	}
682
-
683
-	/**
684
-	 * Set the subscription's status.
685
-	 *
686
-	 * @since 1.0.19
687
-	 * @param string $new_status    New subscription status.
688
-	 */
689
-	public function set_status( $new_status ) {
690
-
691
-		// Abort if this is not a valid status;
692
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
693
-			return;
694
-		}
695
-
696
-		$old_status = $this->get_status();
697
-		$this->set_prop( 'status', $new_status );
698
-
699
-		if ( true === $this->object_read && $old_status !== $new_status ) {
700
-			$this->status_transition = array(
701
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
702
-				'to'     => $new_status,
703
-			);
704
-		}
705
-
706
-	}
707
-
708
-	/**
709
-	 * Set the subscription's (remote) profile id.
710
-	 *
711
-	 * @since 1.0.19
712
-	 * @param  string $value the remote profile id.
713
-	 */
714
-	public function set_profile_id( $value ) {
715
-		$this->set_prop( 'profile_id', sanitize_text_field( $value ) );
716
-	}
717
-
718
-	/*
718
+    /*
719 719
 	|--------------------------------------------------------------------------
720 720
 	| Boolean methods
721 721
 	|--------------------------------------------------------------------------
@@ -724,55 +724,55 @@  discard block
 block discarded – undo
724 724
 	|
725 725
 	*/
726 726
 
727
-	/**
727
+    /**
728 728
      * Checks if the subscription has a given status.
729
-	 *
730
-	 * @param string|array String or array of strings to check for.
731
-	 * @return bool
729
+     *
730
+     * @param string|array String or array of strings to check for.
731
+     * @return bool
732 732
      */
733 733
     public function has_status( $status ) {
734 734
         return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) );
735
-	}
735
+    }
736 736
 
737
-	/**
737
+    /**
738 738
      * Checks if the subscription has a trial period.
739
-	 *
740
-	 * @return bool
739
+     *
740
+     * @return bool
741 741
      */
742 742
     public function has_trial_period() {
743
-		$period = $this->get_trial_period();
743
+        $period = $this->get_trial_period();
744 744
         return ! empty( $period );
745
-	}
746
-
747
-	/**
748
-	 * Is the subscription active?
749
-	 *
750
-	 * @return bool
751
-	 */
752
-	public function is_active() {
753
-		return $this->has_status( 'active trialling' ) && ! $this->is_expired();
754
-	}
755
-
756
-	/**
757
-	 * Is the subscription expired?
758
-	 *
759
-	 * @return bool
760
-	 */
761
-	public function is_expired() {
762
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
763
-	}
764
-
765
-	/**
766
-	 * Is this the last renewals?
767
-	 *
768
-	 * @return bool
769
-	 */
770
-	public function is_last_renewal() {
771
-		$max_bills = $this->get_bill_times();
772
-		return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
773
-	}
774
-
775
-	/*
745
+    }
746
+
747
+    /**
748
+     * Is the subscription active?
749
+     *
750
+     * @return bool
751
+     */
752
+    public function is_active() {
753
+        return $this->has_status( 'active trialling' ) && ! $this->is_expired();
754
+    }
755
+
756
+    /**
757
+     * Is the subscription expired?
758
+     *
759
+     * @return bool
760
+     */
761
+    public function is_expired() {
762
+        return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
763
+    }
764
+
765
+    /**
766
+     * Is this the last renewals?
767
+     *
768
+     * @return bool
769
+     */
770
+    public function is_last_renewal() {
771
+        $max_bills = $this->get_bill_times();
772
+        return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
773
+    }
774
+
775
+    /*
776 776
 	|--------------------------------------------------------------------------
777 777
 	| Additional methods
778 778
 	|--------------------------------------------------------------------------
@@ -781,27 +781,27 @@  discard block
 block discarded – undo
781 781
 	|
782 782
 	*/
783 783
 
784
-	/**
785
-	 * Backwards compatibilty.
786
-	 */
787
-	public function create( $data = array() ) {
784
+    /**
785
+     * Backwards compatibilty.
786
+     */
787
+    public function create( $data = array() ) {
788 788
 
789
-		// Set the properties.
790
-		if ( is_array( $data ) ) {
791
-			$this->set_props( $data );
792
-		}
789
+        // Set the properties.
790
+        if ( is_array( $data ) ) {
791
+            $this->set_props( $data );
792
+        }
793 793
 
794
-		// Save the item.
795
-		return $this->save();
794
+        // Save the item.
795
+        return $this->save();
796 796
 
797
-	}
797
+    }
798 798
 
799
-	/**
800
-	 * Backwards compatibilty.
801
-	 */
802
-	public function update( $args = array() ) {
803
-		return $this->create( $args );
804
-	}
799
+    /**
800
+     * Backwards compatibilty.
801
+     */
802
+    public function update( $args = array() ) {
803
+        return $this->create( $args );
804
+    }
805 805
 
806 806
     /**
807 807
      * Retrieve renewal payments for a subscription
@@ -811,22 +811,22 @@  discard block
 block discarded – undo
811 811
      */
812 812
     public function get_child_payments( $hide_pending = true ) {
813 813
 
814
-		$statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
814
+        $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
815 815
 
816
-		if ( ! $hide_pending ) {
817
-			$statuses = array_keys( wpinv_get_invoice_statuses() );
818
-		}
816
+        if ( ! $hide_pending ) {
817
+            $statuses = array_keys( wpinv_get_invoice_statuses() );
818
+        }
819 819
 
820 820
         return get_posts(
821
-			array(
822
-            	'post_parent'    => $this->get_parent_payment_id(),
823
-            	'numberposts'    => -1,
824
-            	'post_status'    => $statuses,
825
-            	'orderby'        => 'ID',
826
-            	'order'          => 'ASC',
827
-            	'post_type'      => 'wpi_invoice'
828
-			)
829
-		);
821
+            array(
822
+                'post_parent'    => $this->get_parent_payment_id(),
823
+                'numberposts'    => -1,
824
+                'post_status'    => $statuses,
825
+                'orderby'        => 'ID',
826
+                'order'          => 'ASC',
827
+                'post_type'      => 'wpi_invoice'
828
+            )
829
+        );
830 830
     }
831 831
 
832 832
     /**
@@ -836,16 +836,16 @@  discard block
 block discarded – undo
836 836
      * @return int
837 837
      */
838 838
     public function get_total_payments() {
839
-		global $wpdb;
839
+        global $wpdb;
840 840
 
841
-		$count = (int) $wpdb->get_var(
842
-			$wpdb->prepare(
843
-				"SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
844
-				$this->get_parent_invoice_id()
845
-			)
846
-		);
841
+        $count = (int) $wpdb->get_var(
842
+            $wpdb->prepare(
843
+                "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
844
+                $this->get_parent_invoice_id()
845
+            )
846
+        );
847 847
 
848
-		// Maybe include parent invoice.
848
+        // Maybe include parent invoice.
849 849
         if ( $this->get_parent_payment()->is_paid() ) {
850 850
             $count++;
851 851
         }
@@ -874,57 +874,57 @@  discard block
 block discarded – undo
874 874
      *
875 875
      * @since  2.4
876 876
      * @param  array $args Array of values for the payment, including amount and transaction ID
877
-	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
877
+     * @param  WPInv_Invoice $invoice If adding an existing invoice.
878 878
      * @return bool
879 879
      */
880 880
     public function add_payment( $args = array(), $invoice = false ) {
881 881
 
882
-		// Process each payment once.
882
+        // Process each payment once.
883 883
         if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
884 884
             return false;
885 885
         }
886 886
 
887
-		// Are we creating a new invoice?
888
-		if ( empty( $invoice ) ) {
889
-			$invoice = $this->create_payment();
887
+        // Are we creating a new invoice?
888
+        if ( empty( $invoice ) ) {
889
+            $invoice = $this->create_payment();
890 890
 
891
-			if ( empty( $invoice ) ) {
892
-				return false;
893
-			}
891
+            if ( empty( $invoice ) ) {
892
+                return false;
893
+            }
894 894
 
895
-		}
895
+        }
896 896
 
897
-		$invoice->set_status( 'wpi-renewal' );
897
+        $invoice->set_status( 'wpi-renewal' );
898 898
 
899
-		// Maybe set a transaction id.
900
-		if ( ! empty( $args['transaction_id'] ) ) {
901
-			$invoice->set_transaction_id( $args['transaction_id'] );
902
-		}
899
+        // Maybe set a transaction id.
900
+        if ( ! empty( $args['transaction_id'] ) ) {
901
+            $invoice->set_transaction_id( $args['transaction_id'] );
902
+        }
903 903
 
904
-		// Set the completed date.
905
-		$invoice->set_completed_date( current_time( 'mysql' ) );
904
+        // Set the completed date.
905
+        $invoice->set_completed_date( current_time( 'mysql' ) );
906 906
 
907
-		// And the gateway.
908
-		if ( ! empty( $args['gateway'] ) ) {
909
-			$invoice->set_gateway( $args['gateway'] );
910
-		}
907
+        // And the gateway.
908
+        if ( ! empty( $args['gateway'] ) ) {
909
+            $invoice->set_gateway( $args['gateway'] );
910
+        }
911 911
 
912
-		$invoice->save();
912
+        $invoice->save();
913 913
 
914
-		if ( ! $invoice->exists() ) {
915
-			return false;
916
-		}
914
+        if ( ! $invoice->exists() ) {
915
+            return false;
916
+        }
917 917
 
918
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
919
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
918
+        do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
919
+        do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
920 920
         do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
921 921
 
922 922
         update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
923 923
 
924 924
         return $invoice->get_id();
925
-	}
925
+    }
926 926
 
927
-	/**
927
+    /**
928 928
      * Creates a new invoice and returns it.
929 929
      *
930 930
      * @since  1.0.19
@@ -932,105 +932,105 @@  discard block
 block discarded – undo
932 932
      */
933 933
     public function create_payment() {
934 934
 
935
-		$parent_invoice = $this->get_parent_payment();
936
-
937
-		if ( ! $parent_invoice->exists() ) {
938
-			return false;
939
-		}
940
-
941
-		// Duplicate the parent invoice.
942
-		$invoice = getpaid_duplicate_invoice( $parent_invoice );
943
-		$invoice->set_parent_id( $parent_invoice->get_id() );
944
-
945
-		// Maybe recalculate discount (Pre-GetPaid Fix).
946
-		$discount = new WPInv_Discount( $invoice->get_discount_code() );
947
-		if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
948
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
949
-		}
950
-
951
-		$invoice->recalculate_total();
952
-		$invoice->set_status( 'wpi-pending' );
953
-		$invoice->save();
954
-
955
-		return $invoice->exists() ? $invoice : false;
956
-    }
957
-
958
-	/**
959
-	 * Renews or completes a subscription
960
-	 *
961
-	 * @since  1.0.0
962
-	 * @return int The subscription's id
963
-	 */
964
-	public function renew() {
965
-
966
-		// Complete subscription if applicable
967
-		if ( $this->is_last_renewal() ) {
968
-			return $this->complete();
969
-		}
970
-
971
-		// Calculate new expiration
972
-		$frequency      = $this->get_frequency();
973
-		$period         = $this->get_period();
974
-		$new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
975
-
976
-		$this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
977
-		$this->set_status( 'active' );
978
-		$this->save();
979
-
980
-		do_action( 'getpaid_subscription_renewed', $this );
981
-
982
-		return $this->get_id();
983
-	}
984
-
985
-	/**
986
-	 * Marks a subscription as completed
987
-	 *
988
-	 * Subscription is completed when the number of payments matches the billing_times field
989
-	 *
990
-	 * @since  1.0.0
991
-	 * @return int|bool Subscription id or false if the subscription is cancelled.
992
-	 */
993
-	public function complete() {
994
-
995
-		// Only mark a subscription as complete if it's not already cancelled.
996
-		if ( $this->has_status( 'cancelled' ) ) {
997
-			return false;
998
-		}
999
-
1000
-		$this->set_status( 'completed' );
1001
-		return $this->save();
1002
-
1003
-	}
1004
-
1005
-	/**
1006
-	 * Marks a subscription as expired
1007
-	 *
1008
-	 * @since  1.0.0
1009
-	 * @param  bool $check_expiration
1010
-	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1011
-	 */
1012
-	public function expire( $check_expiration = false ) {
1013
-
1014
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1015
-			// Do not mark as expired since real expiration date is in the future
1016
-			return false;
1017
-		}
1018
-
1019
-		$this->set_status( 'expired' );
1020
-		return $this->save();
1021
-
1022
-	}
1023
-
1024
-	/**
1025
-	 * Marks a subscription as failing
1026
-	 *
1027
-	 * @since  2.4.2
1028
-	 * @return int Subscription id.
1029
-	 */
1030
-	public function failing() {
1031
-		$this->set_status( 'failing' );
1032
-		return $this->save();
1033
-	}
935
+        $parent_invoice = $this->get_parent_payment();
936
+
937
+        if ( ! $parent_invoice->exists() ) {
938
+            return false;
939
+        }
940
+
941
+        // Duplicate the parent invoice.
942
+        $invoice = getpaid_duplicate_invoice( $parent_invoice );
943
+        $invoice->set_parent_id( $parent_invoice->get_id() );
944
+
945
+        // Maybe recalculate discount (Pre-GetPaid Fix).
946
+        $discount = new WPInv_Discount( $invoice->get_discount_code() );
947
+        if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
948
+            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
949
+        }
950
+
951
+        $invoice->recalculate_total();
952
+        $invoice->set_status( 'wpi-pending' );
953
+        $invoice->save();
954
+
955
+        return $invoice->exists() ? $invoice : false;
956
+    }
957
+
958
+    /**
959
+     * Renews or completes a subscription
960
+     *
961
+     * @since  1.0.0
962
+     * @return int The subscription's id
963
+     */
964
+    public function renew() {
965
+
966
+        // Complete subscription if applicable
967
+        if ( $this->is_last_renewal() ) {
968
+            return $this->complete();
969
+        }
970
+
971
+        // Calculate new expiration
972
+        $frequency      = $this->get_frequency();
973
+        $period         = $this->get_period();
974
+        $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
975
+
976
+        $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
977
+        $this->set_status( 'active' );
978
+        $this->save();
979
+
980
+        do_action( 'getpaid_subscription_renewed', $this );
981
+
982
+        return $this->get_id();
983
+    }
984
+
985
+    /**
986
+     * Marks a subscription as completed
987
+     *
988
+     * Subscription is completed when the number of payments matches the billing_times field
989
+     *
990
+     * @since  1.0.0
991
+     * @return int|bool Subscription id or false if the subscription is cancelled.
992
+     */
993
+    public function complete() {
994
+
995
+        // Only mark a subscription as complete if it's not already cancelled.
996
+        if ( $this->has_status( 'cancelled' ) ) {
997
+            return false;
998
+        }
999
+
1000
+        $this->set_status( 'completed' );
1001
+        return $this->save();
1002
+
1003
+    }
1004
+
1005
+    /**
1006
+     * Marks a subscription as expired
1007
+     *
1008
+     * @since  1.0.0
1009
+     * @param  bool $check_expiration
1010
+     * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1011
+     */
1012
+    public function expire( $check_expiration = false ) {
1013
+
1014
+        if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1015
+            // Do not mark as expired since real expiration date is in the future
1016
+            return false;
1017
+        }
1018
+
1019
+        $this->set_status( 'expired' );
1020
+        return $this->save();
1021
+
1022
+    }
1023
+
1024
+    /**
1025
+     * Marks a subscription as failing
1026
+     *
1027
+     * @since  2.4.2
1028
+     * @return int Subscription id.
1029
+     */
1030
+    public function failing() {
1031
+        $this->set_status( 'failing' );
1032
+        return $this->save();
1033
+    }
1034 1034
 
1035 1035
     /**
1036 1036
      * Marks a subscription as cancelled
@@ -1039,19 +1039,19 @@  discard block
 block discarded – undo
1039 1039
      * @return int Subscription id.
1040 1040
      */
1041 1041
     public function cancel() {
1042
-		$this->set_status( 'cancelled' );
1043
-		return $this->save();
1042
+        $this->set_status( 'cancelled' );
1043
+        return $this->save();
1044 1044
     }
1045 1045
 
1046
-	/**
1047
-	 * Determines if a subscription can be cancelled both locally and with a payment processor.
1048
-	 *
1049
-	 * @since  1.0.0
1050
-	 * @return bool
1051
-	 */
1052
-	public function can_cancel() {
1053
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1054
-	}
1046
+    /**
1047
+     * Determines if a subscription can be cancelled both locally and with a payment processor.
1048
+     *
1049
+     * @since  1.0.0
1050
+     * @return bool
1051
+     */
1052
+    public function can_cancel() {
1053
+        return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1054
+    }
1055 1055
 
1056 1056
     /**
1057 1057
      * Returns an array of subscription statuses that can be cancelled
@@ -1064,96 +1064,96 @@  discard block
 block discarded – undo
1064 1064
         return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1065 1065
     }
1066 1066
 
1067
-	/**
1068
-	 * Retrieves the URL to cancel subscription
1069
-	 *
1070
-	 * @since  1.0.0
1071
-	 * @return string
1072
-	 */
1073
-	public function get_cancel_url() {
1074
-		$url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1075
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1076
-	}
1077
-
1078
-	/**
1079
-	 * Retrieves the URL to view a subscription
1080
-	 *
1081
-	 * @since  1.0.19
1082
-	 * @return string
1083
-	 */
1084
-	public function get_view_url() {
1085
-
1086
-		$url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1087
-		$url = add_query_arg( 'subscription', $this->get_id(), $url );
1088
-
1089
-		return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1090
-	}
1091
-
1092
-	/**
1093
-	 * Determines if subscription can be manually renewed
1094
-	 *
1095
-	 * This method is filtered by payment gateways in order to return true on subscriptions
1096
-	 * that can be renewed manually
1097
-	 *
1098
-	 * @since  2.5
1099
-	 * @return bool
1100
-	 */
1101
-	public function can_renew() {
1102
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1103
-	}
1104
-
1105
-	/**
1106
-	 * Retrieves the URL to renew a subscription
1107
-	 *
1108
-	 * @since  2.5
1109
-	 * @return string
1110
-	 */
1111
-	public function get_renew_url() {
1112
-		$url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' );
1113
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1114
-	}
1115
-
1116
-	/**
1117
-	 * Determines if subscription can have their payment method updated
1118
-	 *
1119
-	 * @since  1.0.0
1120
-	 * @return bool
1121
-	 */
1122
-	public function can_update() {
1123
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1124
-	}
1125
-
1126
-	/**
1127
-	 * Retrieves the URL to update subscription
1128
-	 *
1129
-	 * @since  1.0.0
1130
-	 * @return string
1131
-	 */
1132
-	public function get_update_url() {
1133
-		$url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1134
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1135
-	}
1136
-
1137
-	/**
1138
-	 * Retrieves the subscription status label
1139
-	 *
1140
-	 * @since  1.0.0
1141
-	 * @return string
1142
-	 */
1143
-	public function get_status_label() {
1144
-		return getpaid_get_subscription_status_label( $this->get_status() );
1145
-	}
1146
-
1147
-	/**
1148
-	 * Retrieves the subscription status class
1149
-	 *
1150
-	 * @since  1.0.19
1151
-	 * @return string
1152
-	 */
1153
-	public function get_status_class() {
1154
-		$statuses = getpaid_get_subscription_status_classes();
1155
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
1156
-	}
1067
+    /**
1068
+     * Retrieves the URL to cancel subscription
1069
+     *
1070
+     * @since  1.0.0
1071
+     * @return string
1072
+     */
1073
+    public function get_cancel_url() {
1074
+        $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1075
+        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1076
+    }
1077
+
1078
+    /**
1079
+     * Retrieves the URL to view a subscription
1080
+     *
1081
+     * @since  1.0.19
1082
+     * @return string
1083
+     */
1084
+    public function get_view_url() {
1085
+
1086
+        $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1087
+        $url = add_query_arg( 'subscription', $this->get_id(), $url );
1088
+
1089
+        return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1090
+    }
1091
+
1092
+    /**
1093
+     * Determines if subscription can be manually renewed
1094
+     *
1095
+     * This method is filtered by payment gateways in order to return true on subscriptions
1096
+     * that can be renewed manually
1097
+     *
1098
+     * @since  2.5
1099
+     * @return bool
1100
+     */
1101
+    public function can_renew() {
1102
+        return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1103
+    }
1104
+
1105
+    /**
1106
+     * Retrieves the URL to renew a subscription
1107
+     *
1108
+     * @since  2.5
1109
+     * @return string
1110
+     */
1111
+    public function get_renew_url() {
1112
+        $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' );
1113
+        return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1114
+    }
1115
+
1116
+    /**
1117
+     * Determines if subscription can have their payment method updated
1118
+     *
1119
+     * @since  1.0.0
1120
+     * @return bool
1121
+     */
1122
+    public function can_update() {
1123
+        return apply_filters( 'wpinv_subscription_can_update', false, $this );
1124
+    }
1125
+
1126
+    /**
1127
+     * Retrieves the URL to update subscription
1128
+     *
1129
+     * @since  1.0.0
1130
+     * @return string
1131
+     */
1132
+    public function get_update_url() {
1133
+        $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1134
+        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1135
+    }
1136
+
1137
+    /**
1138
+     * Retrieves the subscription status label
1139
+     *
1140
+     * @since  1.0.0
1141
+     * @return string
1142
+     */
1143
+    public function get_status_label() {
1144
+        return getpaid_get_subscription_status_label( $this->get_status() );
1145
+    }
1146
+
1147
+    /**
1148
+     * Retrieves the subscription status class
1149
+     *
1150
+     * @since  1.0.19
1151
+     * @return string
1152
+     */
1153
+    public function get_status_class() {
1154
+        $statuses = getpaid_get_subscription_status_classes();
1155
+        return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
1156
+    }
1157 1157
 
1158 1158
     /**
1159 1159
      * Retrieves the subscription status label
@@ -1163,11 +1163,11 @@  discard block
 block discarded – undo
1163 1163
      */
1164 1164
     public function get_status_label_html() {
1165 1165
 
1166
-		$status_label = sanitize_text_field( $this->get_status_label() );
1167
-		$class        = esc_attr( $this->get_status_class() );
1168
-		$status       = sanitize_html_class( $this->get_status() );
1166
+        $status_label = sanitize_text_field( $this->get_status_label() );
1167
+        $class        = esc_attr( $this->get_status_class() );
1168
+        $status       = sanitize_html_class( $this->get_status() );
1169 1169
 
1170
-		return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1170
+        return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1171 1171
     }
1172 1172
 
1173 1173
     /**
@@ -1178,75 +1178,75 @@  discard block
 block discarded – undo
1178 1178
      * @return bool
1179 1179
      */
1180 1180
     public function payment_exists( $txn_id = '' ) {
1181
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1181
+        $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1182 1182
         return ! empty( $invoice_id );
1183
-	}
1184
-
1185
-	/**
1186
-	 * Handle the status transition.
1187
-	 */
1188
-	protected function status_transition() {
1189
-		$status_transition = $this->status_transition;
1190
-
1191
-		// Reset status transition variable.
1192
-		$this->status_transition = false;
1193
-
1194
-		if ( $status_transition ) {
1195
-			try {
1196
-
1197
-				// Fire a hook for the status change.
1198
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1199
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1200
-
1201
-				if ( ! empty( $status_transition['from'] ) ) {
1202
-
1203
-					/* translators: 1: old subscription status 2: new subscription status */
1204
-					$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'] ) );
1205
-
1206
-					// Note the transition occurred.
1207
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1208
-
1209
-					// Fire another hook.
1210
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1211
-					do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1212
-
1213
-				} else {
1214
-					/* translators: %s: new invoice status */
1215
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1216
-
1217
-					// Note the transition occurred.
1218
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1219
-
1220
-				}
1221
-			} catch ( Exception $e ) {
1222
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1223
-			}
1224
-		}
1225
-
1226
-	}
1227
-
1228
-	/**
1229
-	 * Save data to the database.
1230
-	 *
1231
-	 * @since 1.0.19
1232
-	 * @return int subscription ID
1233
-	 */
1234
-	public function save() {
1235
-		parent::save();
1236
-		$this->status_transition();
1237
-		return $this->get_id();
1238
-	}
1239
-
1240
-	/**
1241
-	 * Activates a subscription.
1242
-	 *
1243
-	 * @since 1.0.19
1244
-	 * @return int subscription ID
1245
-	 */
1246
-	public function activate() {
1247
-		$status = 'trialling' == $this->get_status() ? 'trialling' : 'active';
1248
-		$this->set_status( $status );
1249
-		return $this->save();
1250
-	}
1183
+    }
1184
+
1185
+    /**
1186
+     * Handle the status transition.
1187
+     */
1188
+    protected function status_transition() {
1189
+        $status_transition = $this->status_transition;
1190
+
1191
+        // Reset status transition variable.
1192
+        $this->status_transition = false;
1193
+
1194
+        if ( $status_transition ) {
1195
+            try {
1196
+
1197
+                // Fire a hook for the status change.
1198
+                do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1199
+                do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1200
+
1201
+                if ( ! empty( $status_transition['from'] ) ) {
1202
+
1203
+                    /* translators: 1: old subscription status 2: new subscription status */
1204
+                    $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'] ) );
1205
+
1206
+                    // Note the transition occurred.
1207
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1208
+
1209
+                    // Fire another hook.
1210
+                    do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1211
+                    do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1212
+
1213
+                } else {
1214
+                    /* translators: %s: new invoice status */
1215
+                    $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1216
+
1217
+                    // Note the transition occurred.
1218
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1219
+
1220
+                }
1221
+            } catch ( Exception $e ) {
1222
+                $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1223
+            }
1224
+        }
1225
+
1226
+    }
1227
+
1228
+    /**
1229
+     * Save data to the database.
1230
+     *
1231
+     * @since 1.0.19
1232
+     * @return int subscription ID
1233
+     */
1234
+    public function save() {
1235
+        parent::save();
1236
+        $this->status_transition();
1237
+        return $this->get_id();
1238
+    }
1239
+
1240
+    /**
1241
+     * Activates a subscription.
1242
+     *
1243
+     * @since 1.0.19
1244
+     * @return int subscription ID
1245
+     */
1246
+    public function activate() {
1247
+        $status = 'trialling' == $this->get_status() ? 'trialling' : 'active';
1248
+        $this->set_status( $status );
1249
+        return $this->save();
1250
+    }
1251 1251
 
1252 1252
 }
Please login to merge, or discard this patch.