@@ -281,9 +281,9 @@ |
||
281 | 281 | return $value; |
282 | 282 | } |
283 | 283 | |
284 | - /** |
|
285 | - * Sets an invoice key. |
|
286 | - */ |
|
284 | + /** |
|
285 | + * Sets an invoice key. |
|
286 | + */ |
|
287 | 287 | public function set( $key, $value ) { |
288 | 288 | $ignore = array( 'items', 'cart_details', 'fees', '_ID' ); |
289 | 289 |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // MUST have WordPress. |
4 | -if ( !defined( 'WPINC' ) ) { |
|
5 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
4 | +if (!defined('WPINC')) { |
|
5 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | /** |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | /** |
14 | 14 | * @var int the invoice ID. |
15 | 15 | */ |
16 | - public $ID = 0; |
|
16 | + public $ID = 0; |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * @var string the invoice title. |
@@ -258,22 +258,22 @@ discard block |
||
258 | 258 | /** |
259 | 259 | * @param int|WPInv_Invoice|WP_Post $invoice The invoice. |
260 | 260 | */ |
261 | - public function __construct( $invoice = false ) { |
|
261 | + public function __construct($invoice = false) { |
|
262 | 262 | |
263 | 263 | // Do we have an invoice? |
264 | - if ( empty( $invoice ) ) { |
|
264 | + if (empty($invoice)) { |
|
265 | 265 | return false; |
266 | 266 | } |
267 | 267 | |
268 | - $this->setup_invoice( $invoice ); |
|
268 | + $this->setup_invoice($invoice); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
272 | 272 | * Retrieves an invoice key. |
273 | 273 | */ |
274 | - public function get( $key ) { |
|
275 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
276 | - $value = call_user_func( array( $this, 'get_' . $key ) ); |
|
274 | + public function get($key) { |
|
275 | + if (method_exists($this, 'get_' . $key)) { |
|
276 | + $value = call_user_func(array($this, 'get_' . $key)); |
|
277 | 277 | } else { |
278 | 278 | $value = $this->$key; |
279 | 279 | } |
@@ -284,18 +284,18 @@ discard block |
||
284 | 284 | /** |
285 | 285 | * Sets an invoice key. |
286 | 286 | */ |
287 | - public function set( $key, $value ) { |
|
288 | - $ignore = array( 'items', 'cart_details', 'fees', '_ID' ); |
|
287 | + public function set($key, $value) { |
|
288 | + $ignore = array('items', 'cart_details', 'fees', '_ID'); |
|
289 | 289 | |
290 | - if ( $key === 'status' ) { |
|
290 | + if ($key === 'status') { |
|
291 | 291 | $this->old_status = $this->status; |
292 | 292 | } |
293 | 293 | |
294 | - if ( ! in_array( $key, $ignore ) ) { |
|
295 | - $this->pending[ $key ] = $value; |
|
294 | + if (!in_array($key, $ignore)) { |
|
295 | + $this->pending[$key] = $value; |
|
296 | 296 | } |
297 | 297 | |
298 | - if( '_ID' !== $key ) { |
|
298 | + if ('_ID' !== $key) { |
|
299 | 299 | $this->$key = $value; |
300 | 300 | } |
301 | 301 | } |
@@ -303,9 +303,9 @@ discard block |
||
303 | 303 | /** |
304 | 304 | * Checks if an invoice key is set. |
305 | 305 | */ |
306 | - public function _isset( $name ) { |
|
307 | - if ( property_exists( $this, $name) ) { |
|
308 | - return false === empty( $this->$name ); |
|
306 | + public function _isset($name) { |
|
307 | + if (property_exists($this, $name)) { |
|
308 | + return false === empty($this->$name); |
|
309 | 309 | } else { |
310 | 310 | return null; |
311 | 311 | } |
@@ -314,66 +314,66 @@ discard block |
||
314 | 314 | /** |
315 | 315 | * @param int|WPInv_Invoice|WP_Post $invoice The invoice. |
316 | 316 | */ |
317 | - private function setup_invoice( $invoice ) { |
|
317 | + private function setup_invoice($invoice) { |
|
318 | 318 | global $wpdb; |
319 | 319 | $this->pending = array(); |
320 | 320 | |
321 | - if ( empty( $invoice ) ) { |
|
321 | + if (empty($invoice)) { |
|
322 | 322 | return false; |
323 | 323 | } |
324 | 324 | |
325 | - if ( is_a( $invoice, 'WPInv_Invoice' ) ) { |
|
326 | - foreach ( get_object_vars( $invoice ) as $prop => $value ) { |
|
325 | + if (is_a($invoice, 'WPInv_Invoice')) { |
|
326 | + foreach (get_object_vars($invoice) as $prop => $value) { |
|
327 | 327 | $this->$prop = $value; |
328 | 328 | } |
329 | 329 | return true; |
330 | 330 | } |
331 | 331 | |
332 | 332 | // Retrieve post object. |
333 | - $invoice = get_post( $invoice ); |
|
333 | + $invoice = get_post($invoice); |
|
334 | 334 | |
335 | - if( ! $invoice || is_wp_error( $invoice ) ) { |
|
335 | + if (!$invoice || is_wp_error($invoice)) { |
|
336 | 336 | return false; |
337 | 337 | } |
338 | 338 | |
339 | - if( ! ( 'wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type ) ) { |
|
339 | + if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) { |
|
340 | 340 | return false; |
341 | 341 | } |
342 | 342 | |
343 | 343 | // Retrieve post data. |
344 | 344 | $table = $wpdb->prefix . 'getpaid_invoices'; |
345 | 345 | $data = $wpdb->get_row( |
346 | - $wpdb->prepare( "SELECT * FROM $table WHERE post_id=%d", $invoice->ID ) |
|
346 | + $wpdb->prepare("SELECT * FROM $table WHERE post_id=%d", $invoice->ID) |
|
347 | 347 | ); |
348 | 348 | |
349 | - do_action( 'wpinv_pre_setup_invoice', $this, $invoice->ID, $data ); |
|
349 | + do_action('wpinv_pre_setup_invoice', $this, $invoice->ID, $data); |
|
350 | 350 | |
351 | 351 | // Primary Identifier |
352 | - $this->ID = absint( $invoice->ID ); |
|
352 | + $this->ID = absint($invoice->ID); |
|
353 | 353 | $this->post_type = $invoice->post_type; |
354 | 354 | |
355 | 355 | $this->date = $invoice->post_date; |
356 | 356 | $this->status = $invoice->post_status; |
357 | 357 | |
358 | - if ( 'future' == $this->status ) { |
|
358 | + if ('future' == $this->status) { |
|
359 | 359 | $this->status = 'publish'; |
360 | 360 | } |
361 | 361 | |
362 | 362 | $this->post_status = $this->status; |
363 | 363 | $this->parent_invoice = $invoice->post_parent; |
364 | - $this->post_name = $this->setup_post_name( $invoice ); |
|
365 | - $this->status_nicename = $this->setup_status_nicename( $invoice->post_status ); |
|
364 | + $this->post_name = $this->setup_post_name($invoice); |
|
365 | + $this->status_nicename = $this->setup_status_nicename($invoice->post_status); |
|
366 | 366 | |
367 | - $this->user_id = ! empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id(); |
|
368 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
367 | + $this->user_id = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); |
|
368 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
369 | 369 | $this->currency = wpinv_get_currency(); |
370 | - $this->setup_invoice_data( $data ); |
|
370 | + $this->setup_invoice_data($data); |
|
371 | 371 | |
372 | 372 | // Other Identifiers |
373 | - $this->title = ! empty( $invoice->post_title ) ? $invoice->post_title : $this->number; |
|
373 | + $this->title = !empty($invoice->post_title) ? $invoice->post_title : $this->number; |
|
374 | 374 | |
375 | 375 | // Allow extensions to add items to this object via hook |
376 | - do_action( 'wpinv_setup_invoice', $this, $invoice->ID, $data ); |
|
376 | + do_action('wpinv_setup_invoice', $this, $invoice->ID, $data); |
|
377 | 377 | |
378 | 378 | return true; |
379 | 379 | } |
@@ -381,16 +381,16 @@ discard block |
||
381 | 381 | /** |
382 | 382 | * @param stdClass $data The invoice data. |
383 | 383 | */ |
384 | - private function setup_invoice_data( $data ) { |
|
384 | + private function setup_invoice_data($data) { |
|
385 | 385 | |
386 | - if ( empty( $data ) ) { |
|
387 | - $this->number = $this->setup_invoice_number( $data ); |
|
386 | + if (empty($data)) { |
|
387 | + $this->number = $this->setup_invoice_number($data); |
|
388 | 388 | return; |
389 | 389 | } |
390 | 390 | |
391 | - $data = map_deep( $data, 'maybe_unserialize' ); |
|
391 | + $data = map_deep($data, 'maybe_unserialize'); |
|
392 | 392 | |
393 | - $this->payment_meta = is_array( $data->custom_meta ) ? $data->custom_meta : array(); |
|
393 | + $this->payment_meta = is_array($data->custom_meta) ? $data->custom_meta : array(); |
|
394 | 394 | $this->due_date = $data->due_date; |
395 | 395 | $this->completed_date = $data->completed_date; |
396 | 396 | $this->mode = $data->mode; |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | // Items |
399 | 399 | $this->fees = $this->setup_fees(); |
400 | 400 | $this->cart_details = $this->setup_cart_details(); |
401 | - $this->items = ! empty( $this->payment_meta['items'] ) ? $this->payment_meta['items'] : array(); |
|
401 | + $this->items = !empty($this->payment_meta['items']) ? $this->payment_meta['items'] : array(); |
|
402 | 402 | |
403 | 403 | // Currency Based |
404 | 404 | $this->total = $data->total; |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | $this->tax = $data->tax; |
407 | 407 | $this->fees_total = $data->fees_total; |
408 | 408 | $this->subtotal = $data->subtotal; |
409 | - $this->currency = empty( $data->currency ) ? wpinv_get_currency() : $data->currency ; |
|
409 | + $this->currency = empty($data->currency) ? wpinv_get_currency() : $data->currency; |
|
410 | 410 | |
411 | 411 | // Gateway based |
412 | 412 | $this->gateway = $data->gateway; |
@@ -415,30 +415,30 @@ discard block |
||
415 | 415 | |
416 | 416 | // User based |
417 | 417 | $this->ip = $data->user_ip; |
418 | - $this->user_info = ! empty( $this->payment_meta['user_info'] ) ? $this->payment_meta['user_info'] : array(); |
|
418 | + $this->user_info = !empty($this->payment_meta['user_info']) ? $this->payment_meta['user_info'] : array(); |
|
419 | 419 | |
420 | 420 | $this->first_name = $data->first_name; |
421 | 421 | $this->last_name = $data->last_name; |
422 | 422 | $this->company = $data->company; |
423 | 423 | $this->vat_number = $data->vat_number; |
424 | 424 | $this->vat_rate = $data->vat_rate; |
425 | - $this->adddress_confirmed = (int) $data->adddress_confirmed; |
|
425 | + $this->adddress_confirmed = (int) $data->adddress_confirmed; |
|
426 | 426 | $this->address = $data->address; |
427 | 427 | $this->city = $data->city; |
428 | 428 | $this->country = $data->country; |
429 | 429 | $this->state = $data->state; |
430 | 430 | $this->zip = $data->zip; |
431 | - $this->phone = ! empty( $this->user_info['phone'] ) ? $this->user_info['phone'] : ''; |
|
431 | + $this->phone = !empty($this->user_info['phone']) ? $this->user_info['phone'] : ''; |
|
432 | 432 | |
433 | - $this->discounts = ! empty( $this->user_info['discount'] ) ? $this->user_info['discount'] : ''; |
|
433 | + $this->discounts = !empty($this->user_info['discount']) ? $this->user_info['discount'] : ''; |
|
434 | 434 | $this->discount = $data->discount; |
435 | 435 | $this->discount_code = $data->discount_code; |
436 | 436 | |
437 | 437 | // Other Identifiers |
438 | 438 | $this->key = $data->key; |
439 | - $this->number = $this->setup_invoice_number( $data ); |
|
439 | + $this->number = $this->setup_invoice_number($data); |
|
440 | 440 | |
441 | - $this->full_name = trim( $this->first_name . ' '. $this->last_name ); |
|
441 | + $this->full_name = trim($this->first_name . ' ' . $this->last_name); |
|
442 | 442 | |
443 | 443 | |
444 | 444 | return true; |
@@ -448,52 +448,52 @@ discard block |
||
448 | 448 | /** |
449 | 449 | * Sets up the status nice name. |
450 | 450 | */ |
451 | - private function setup_status_nicename( $status ) { |
|
452 | - $all_invoice_statuses = wpinv_get_invoice_statuses( true, true, $this ); |
|
451 | + private function setup_status_nicename($status) { |
|
452 | + $all_invoice_statuses = wpinv_get_invoice_statuses(true, true, $this); |
|
453 | 453 | |
454 | - if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) { |
|
455 | - $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
|
454 | + if ($this->is_quote() && class_exists('Wpinv_Quotes_Shared')) { |
|
455 | + $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
|
456 | 456 | } |
457 | - $status = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' ); |
|
457 | + $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing'); |
|
458 | 458 | |
459 | - return apply_filters( 'setup_status_nicename', $status ); |
|
459 | + return apply_filters('setup_status_nicename', $status); |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | /** |
463 | 463 | * Set's up the invoice number. |
464 | 464 | */ |
465 | - private function setup_invoice_number( $data ) { |
|
465 | + private function setup_invoice_number($data) { |
|
466 | 466 | |
467 | - if ( ! empty( $data ) && ! empty( $data->number ) ) { |
|
467 | + if (!empty($data) && !empty($data->number)) { |
|
468 | 468 | return $data->number; |
469 | 469 | } |
470 | 470 | |
471 | 471 | $number = $this->ID; |
472 | 472 | |
473 | - if ( $this->status == 'auto-draft' && wpinv_sequential_number_active( $this->post_type ) ) { |
|
474 | - $next_number = wpinv_get_next_invoice_number( $this->post_type ); |
|
473 | + if ($this->status == 'auto-draft' && wpinv_sequential_number_active($this->post_type)) { |
|
474 | + $next_number = wpinv_get_next_invoice_number($this->post_type); |
|
475 | 475 | $number = $next_number; |
476 | 476 | } |
477 | 477 | |
478 | - return wpinv_format_invoice_number( $number, $this->post_type ); |
|
478 | + return wpinv_format_invoice_number($number, $this->post_type); |
|
479 | 479 | |
480 | 480 | } |
481 | 481 | |
482 | 482 | /** |
483 | 483 | * Invoice's post name. |
484 | 484 | */ |
485 | - private function setup_post_name( $post = NULL ) { |
|
485 | + private function setup_post_name($post = NULL) { |
|
486 | 486 | global $wpdb; |
487 | 487 | |
488 | 488 | $post_name = ''; |
489 | 489 | |
490 | - if ( !empty( $post ) ) { |
|
491 | - if( !empty( $post->post_name ) ) { |
|
490 | + if (!empty($post)) { |
|
491 | + if (!empty($post->post_name)) { |
|
492 | 492 | $post_name = $post->post_name; |
493 | - } else if ( !empty( $post->ID ) ) { |
|
494 | - $post_name = wpinv_generate_post_name( $post->ID ); |
|
493 | + } else if (!empty($post->ID)) { |
|
494 | + $post_name = wpinv_generate_post_name($post->ID); |
|
495 | 495 | |
496 | - $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) ); |
|
496 | + $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID)); |
|
497 | 497 | } |
498 | 498 | } |
499 | 499 | |
@@ -506,18 +506,18 @@ discard block |
||
506 | 506 | public function setup_cart_details() { |
507 | 507 | global $wpdb; |
508 | 508 | |
509 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
509 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
510 | 510 | $items = $wpdb->get_results( |
511 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $this->ID ) |
|
511 | + $wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d", $this->ID) |
|
512 | 512 | ); |
513 | 513 | |
514 | - if ( empty( $items ) ) { |
|
514 | + if (empty($items)) { |
|
515 | 515 | return array(); |
516 | 516 | } |
517 | 517 | |
518 | 518 | $details = array(); |
519 | 519 | |
520 | - foreach ( $items as $item ) { |
|
520 | + foreach ($items as $item) { |
|
521 | 521 | $item = (array) $item; |
522 | 522 | $details[] = array( |
523 | 523 | 'name' => $item['item_name'], |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | ); |
537 | 537 | } |
538 | 538 | |
539 | - return map_deep( $details, 'maybe_unserialize' ); |
|
539 | + return map_deep($details, 'maybe_unserialize'); |
|
540 | 540 | |
541 | 541 | } |
542 | 542 | |
@@ -544,16 +544,16 @@ discard block |
||
544 | 544 | * Convert this to an array. |
545 | 545 | */ |
546 | 546 | public function array_convert() { |
547 | - return get_object_vars( $this ); |
|
547 | + return get_object_vars($this); |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | private function setup_fees() { |
551 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
551 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
552 | 552 | return $payment_fees; |
553 | 553 | } |
554 | 554 | |
555 | 555 | private function setup_gateway_title() { |
556 | - $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway ); |
|
556 | + $gateway_title = wpinv_get_gateway_checkout_label($this->gateway); |
|
557 | 557 | return $gateway_title; |
558 | 558 | } |
559 | 559 | |
@@ -589,16 +589,16 @@ discard block |
||
589 | 589 | 'fees' => $this->fees, |
590 | 590 | ); |
591 | 591 | |
592 | - $this->payment_meta = array_merge( $this->payment_meta, $payment_data ); |
|
592 | + $this->payment_meta = array_merge($this->payment_meta, $payment_data); |
|
593 | 593 | |
594 | 594 | } |
595 | 595 | |
596 | 596 | private function insert_invoice() { |
597 | 597 | |
598 | - if ( empty( $this->post_type ) ) { |
|
599 | - if ( !empty( $this->ID ) && $post_type = get_post_type( $this->ID ) ) { |
|
598 | + if (empty($this->post_type)) { |
|
599 | + if (!empty($this->ID) && $post_type = get_post_type($this->ID)) { |
|
600 | 600 | $this->post_type = $post_type; |
601 | - } else if ( !empty( $this->parent_invoice ) && $post_type = get_post_type( $this->parent_invoice ) ) { |
|
601 | + } else if (!empty($this->parent_invoice) && $post_type = get_post_type($this->parent_invoice)) { |
|
602 | 602 | $this->post_type = $post_type; |
603 | 603 | } else { |
604 | 604 | $this->post_type = 'wpi_invoice'; |
@@ -606,16 +606,16 @@ discard block |
||
606 | 606 | } |
607 | 607 | |
608 | 608 | $invoice_number = $this->ID; |
609 | - if ( $number = $this->number ) { |
|
609 | + if ($number = $this->number) { |
|
610 | 610 | $invoice_number = $number; |
611 | 611 | } |
612 | 612 | |
613 | - if ( empty( $this->key ) ) { |
|
613 | + if (empty($this->key)) { |
|
614 | 614 | $this->key = $this->generate_key(); |
615 | 615 | $this->pending['key'] = $this->key; |
616 | 616 | } |
617 | 617 | |
618 | - if ( empty( $this->ip ) ) { |
|
618 | + if (empty($this->ip)) { |
|
619 | 619 | $this->ip = wpinv_get_ip(); |
620 | 620 | $this->pending['ip'] = $this->ip; |
621 | 621 | } |
@@ -652,34 +652,34 @@ discard block |
||
652 | 652 | 'post_status' => $this->status, |
653 | 653 | 'post_author' => $this->user_id, |
654 | 654 | 'post_type' => $this->post_type, |
655 | - 'post_date' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ), |
|
656 | - 'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ), |
|
655 | + 'post_date' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'), |
|
656 | + 'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1), |
|
657 | 657 | 'post_parent' => $this->parent_invoice, |
658 | 658 | ); |
659 | - $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this ); |
|
659 | + $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this); |
|
660 | 660 | |
661 | 661 | // Create a blank invoice |
662 | - if ( !empty( $this->ID ) ) { |
|
663 | - $args['ID'] = $this->ID; |
|
664 | - $invoice_id = wp_update_post( $args, true ); |
|
662 | + if (!empty($this->ID)) { |
|
663 | + $args['ID'] = $this->ID; |
|
664 | + $invoice_id = wp_update_post($args, true); |
|
665 | 665 | } else { |
666 | - $invoice_id = wp_insert_post( $args, true ); |
|
666 | + $invoice_id = wp_insert_post($args, true); |
|
667 | 667 | } |
668 | 668 | |
669 | - if ( is_wp_error( $invoice_id ) ) { |
|
669 | + if (is_wp_error($invoice_id)) { |
|
670 | 670 | return false; |
671 | 671 | } |
672 | 672 | |
673 | - if ( ! empty( $invoice_id ) ) { |
|
673 | + if (!empty($invoice_id)) { |
|
674 | 674 | $this->ID = $invoice_id; |
675 | 675 | $this->_ID = $invoice_id; |
676 | 676 | |
677 | - $this->payment_meta = array_merge( $this->payment_meta, $payment_data ); |
|
677 | + $this->payment_meta = array_merge($this->payment_meta, $payment_data); |
|
678 | 678 | |
679 | - if ( ! empty( $this->payment_meta['fees'] ) ) { |
|
680 | - $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] ); |
|
681 | - foreach( $this->fees as $fee ) { |
|
682 | - $this->increase_fees( $fee['amount'] ); |
|
679 | + if (!empty($this->payment_meta['fees'])) { |
|
680 | + $this->fees = array_merge($this->fees, $this->payment_meta['fees']); |
|
681 | + foreach ($this->fees as $fee) { |
|
682 | + $this->increase_fees($fee['amount']); |
|
683 | 683 | } |
684 | 684 | } |
685 | 685 | |
@@ -695,11 +695,11 @@ discard block |
||
695 | 695 | */ |
696 | 696 | public function get_special_fields() { |
697 | 697 | |
698 | - return array ( |
|
698 | + return array( |
|
699 | 699 | 'post_id' => $this->ID, |
700 | 700 | 'number' => $this->get_number(), |
701 | 701 | 'key' => $this->get_key(), |
702 | - 'type' => str_replace( 'wpi_', '', $this->post_type ), |
|
702 | + 'type' => str_replace('wpi_', '', $this->post_type), |
|
703 | 703 | 'mode' => $this->mode, |
704 | 704 | 'user_ip' => $this->get_ip(), |
705 | 705 | 'first_name' => $this->get_first_name(), |
@@ -739,37 +739,37 @@ discard block |
||
739 | 739 | $this->refresh_payment_data(); |
740 | 740 | |
741 | 741 | $fields = $this->get_special_fields(); |
742 | - $fields = array_map( 'maybe_serialize', $fields ); |
|
742 | + $fields = array_map('maybe_serialize', $fields); |
|
743 | 743 | |
744 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
744 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
745 | 745 | |
746 | 746 | $id = (int) $this->ID; |
747 | 747 | |
748 | - if ( empty( $id ) ) { |
|
748 | + if (empty($id)) { |
|
749 | 749 | return; |
750 | 750 | } |
751 | 751 | |
752 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`=$id" ) ) { |
|
752 | + if ($wpdb->get_var("SELECT `post_id` FROM $table WHERE `post_id`=$id")) { |
|
753 | 753 | |
754 | - $wpdb->update( $table, $fields, array( 'post_id' => $id ) ); |
|
754 | + $wpdb->update($table, $fields, array('post_id' => $id)); |
|
755 | 755 | |
756 | 756 | } else { |
757 | 757 | |
758 | - $wpdb->insert( $table, $fields ); |
|
758 | + $wpdb->insert($table, $fields); |
|
759 | 759 | |
760 | 760 | } |
761 | 761 | |
762 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
763 | - $wpdb->delete( $table, array( 'post_id' => $this->ID ) ); |
|
762 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
763 | + $wpdb->delete($table, array('post_id' => $this->ID)); |
|
764 | 764 | |
765 | - foreach ( $this->get_cart_details() as $details ) { |
|
765 | + foreach ($this->get_cart_details() as $details) { |
|
766 | 766 | $fields = array( |
767 | 767 | 'post_id' => $this->ID, |
768 | 768 | 'item_id' => $details['id'], |
769 | 769 | 'item_name' => $details['name'], |
770 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
770 | + 'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'], |
|
771 | 771 | 'vat_rate' => $details['vat_rate'], |
772 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
772 | + 'vat_class' => empty($details['vat_class']) ? '_standard' : $details['vat_class'], |
|
773 | 773 | 'tax' => $details['tax'], |
774 | 774 | 'item_price' => $details['item_price'], |
775 | 775 | 'custom_price' => $details['custom_price'], |
@@ -781,41 +781,41 @@ discard block |
||
781 | 781 | 'fees' => $details['fees'], |
782 | 782 | ); |
783 | 783 | |
784 | - $item_columns = array_keys ( $fields ); |
|
784 | + $item_columns = array_keys($fields); |
|
785 | 785 | |
786 | - foreach ( $fields as $key => $val ) { |
|
787 | - if ( is_null( $val ) ) { |
|
786 | + foreach ($fields as $key => $val) { |
|
787 | + if (is_null($val)) { |
|
788 | 788 | $val = ''; |
789 | 789 | } |
790 | - $val = maybe_serialize( $val ); |
|
791 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
790 | + $val = maybe_serialize($val); |
|
791 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
792 | 792 | } |
793 | 793 | |
794 | - $fields = implode( ', ', $fields ); |
|
794 | + $fields = implode(', ', $fields); |
|
795 | 795 | $item_rows[] = "($fields)"; |
796 | 796 | } |
797 | 797 | |
798 | - $item_rows = implode( ', ', $item_rows ); |
|
799 | - $item_columns = implode( ', ', $item_columns ); |
|
800 | - $wpdb->query( "INSERT INTO $table ($item_columns) VALUES $item_rows" ); |
|
798 | + $item_rows = implode(', ', $item_rows); |
|
799 | + $item_columns = implode(', ', $item_columns); |
|
800 | + $wpdb->query("INSERT INTO $table ($item_columns) VALUES $item_rows"); |
|
801 | 801 | } |
802 | 802 | |
803 | - public function save( $setup = false ) { |
|
803 | + public function save($setup = false) { |
|
804 | 804 | global $wpi_session; |
805 | 805 | |
806 | 806 | $saved = false; |
807 | - if ( empty( $this->items ) ) { |
|
807 | + if (empty($this->items)) { |
|
808 | 808 | return $saved; |
809 | 809 | } |
810 | 810 | |
811 | - if ( empty( $this->key ) ) { |
|
811 | + if (empty($this->key)) { |
|
812 | 812 | $this->key = $this->generate_key(); |
813 | 813 | } |
814 | 814 | |
815 | - if ( empty( $this->ID ) ) { |
|
815 | + if (empty($this->ID)) { |
|
816 | 816 | $invoice_id = $this->insert_invoice(); |
817 | 817 | |
818 | - if ( false === $invoice_id ) { |
|
818 | + if (false === $invoice_id) { |
|
819 | 819 | $saved = false; |
820 | 820 | } else { |
821 | 821 | $this->ID = $invoice_id; |
@@ -823,28 +823,28 @@ discard block |
||
823 | 823 | } |
824 | 824 | |
825 | 825 | // If we have something pending, let's save it |
826 | - if ( ! empty( $this->pending ) ) { |
|
826 | + if (!empty($this->pending)) { |
|
827 | 827 | $total_increase = 0; |
828 | 828 | $total_decrease = 0; |
829 | 829 | |
830 | - foreach ( $this->pending as $key => $value ) { |
|
830 | + foreach ($this->pending as $key => $value) { |
|
831 | 831 | |
832 | - switch( $key ) { |
|
832 | + switch ($key) { |
|
833 | 833 | case 'items': |
834 | 834 | // Update totals for pending items |
835 | - foreach ( $this->pending[ $key ] as $item ) { |
|
836 | - switch( $item['action'] ) { |
|
835 | + foreach ($this->pending[$key] as $item) { |
|
836 | + switch ($item['action']) { |
|
837 | 837 | case 'add': |
838 | 838 | $price = $item['price']; |
839 | 839 | $taxes = $item['tax']; |
840 | 840 | |
841 | - if ( 'publish' === $this->status ) { |
|
841 | + if ('publish' === $this->status) { |
|
842 | 842 | $total_increase += $price; |
843 | 843 | } |
844 | 844 | break; |
845 | 845 | |
846 | 846 | case 'remove': |
847 | - if ( 'publish' === $this->status ) { |
|
847 | + if ('publish' === $this->status) { |
|
848 | 848 | $total_decrease += $item['price']; |
849 | 849 | } |
850 | 850 | break; |
@@ -852,16 +852,16 @@ discard block |
||
852 | 852 | } |
853 | 853 | break; |
854 | 854 | case 'fees': |
855 | - if ( 'publish' !== $this->status ) { |
|
855 | + if ('publish' !== $this->status) { |
|
856 | 856 | break; |
857 | 857 | } |
858 | 858 | |
859 | - if ( empty( $this->pending[ $key ] ) ) { |
|
859 | + if (empty($this->pending[$key])) { |
|
860 | 860 | break; |
861 | 861 | } |
862 | 862 | |
863 | - foreach ( $this->pending[ $key ] as $fee ) { |
|
864 | - switch( $fee['action'] ) { |
|
863 | + foreach ($this->pending[$key] as $fee) { |
|
864 | + switch ($fee['action']) { |
|
865 | 865 | case 'add': |
866 | 866 | $total_increase += $fee['amount']; |
867 | 867 | break; |
@@ -873,7 +873,7 @@ discard block |
||
873 | 873 | } |
874 | 874 | break; |
875 | 875 | case 'status': |
876 | - $this->update_status( $this->status ); |
|
876 | + $this->update_status($this->status); |
|
877 | 877 | break; |
878 | 878 | case 'first_name': |
879 | 879 | $this->user_info['first_name'] = $this->first_name; |
@@ -905,12 +905,12 @@ discard block |
||
905 | 905 | case 'vat_number': |
906 | 906 | $this->user_info['vat_number'] = $this->vat_number; |
907 | 907 | |
908 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
909 | - if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) { |
|
910 | - $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false; |
|
911 | - $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed ); |
|
912 | - $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed; |
|
913 | - $this->adddress_confirmed = (bool)$adddress_confirmed; |
|
908 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
909 | + if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) { |
|
910 | + $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
911 | + $this->update_meta('_wpinv_adddress_confirmed', (bool) $adddress_confirmed); |
|
912 | + $this->user_info['adddress_confirmed'] = (bool) $adddress_confirmed; |
|
913 | + $this->adddress_confirmed = (bool) $adddress_confirmed; |
|
914 | 914 | } |
915 | 915 | |
916 | 916 | break; |
@@ -927,34 +927,34 @@ discard block |
||
927 | 927 | 'edit_date' => true, |
928 | 928 | ); |
929 | 929 | |
930 | - wp_update_post( $args ); |
|
930 | + wp_update_post($args); |
|
931 | 931 | break; |
932 | 932 | case 'due_date': |
933 | - if ( empty( $this->due_date ) ) { |
|
933 | + if (empty($this->due_date)) { |
|
934 | 934 | $this->due_date = 'none'; |
935 | 935 | } |
936 | 936 | break; |
937 | 937 | case 'discounts': |
938 | - if ( ! is_array( $this->discounts ) ) { |
|
939 | - $this->discounts = explode( ',', $this->discounts ); |
|
938 | + if (!is_array($this->discounts)) { |
|
939 | + $this->discounts = explode(',', $this->discounts); |
|
940 | 940 | } |
941 | 941 | |
942 | - $this->user_info['discount'] = implode( ',', $this->discounts ); |
|
942 | + $this->user_info['discount'] = implode(',', $this->discounts); |
|
943 | 943 | break; |
944 | 944 | case 'parent_invoice': |
945 | 945 | $args = array( |
946 | 946 | 'ID' => $this->ID, |
947 | 947 | 'post_parent' => $this->parent_invoice, |
948 | 948 | ); |
949 | - wp_update_post( $args ); |
|
949 | + wp_update_post($args); |
|
950 | 950 | break; |
951 | 951 | default: |
952 | - do_action( 'wpinv_save', $this, $key ); |
|
952 | + do_action('wpinv_save', $this, $key); |
|
953 | 953 | break; |
954 | 954 | } |
955 | 955 | } |
956 | 956 | |
957 | - $this->items = array_values( $this->items ); |
|
957 | + $this->items = array_values($this->items); |
|
958 | 958 | |
959 | 959 | $this->pending = array(); |
960 | 960 | $saved = true; |
@@ -967,14 +967,14 @@ discard block |
||
967 | 967 | 'currency' => $this->currency, |
968 | 968 | 'user_info' => $this->user_info, |
969 | 969 | ); |
970 | - $this->payment_meta = array_merge( $this->payment_meta, $new_meta ); |
|
970 | + $this->payment_meta = array_merge($this->payment_meta, $new_meta); |
|
971 | 971 | $this->update_items(); |
972 | 972 | |
973 | 973 | $this->save_special(); |
974 | - do_action( 'wpinv_invoice_save', $this, $saved ); |
|
974 | + do_action('wpinv_invoice_save', $this, $saved); |
|
975 | 975 | |
976 | - if ( true === $saved || $setup ) { |
|
977 | - $this->setup_invoice( $this->ID ); |
|
976 | + if (true === $saved || $setup) { |
|
977 | + $this->setup_invoice($this->ID); |
|
978 | 978 | } |
979 | 979 | |
980 | 980 | $this->refresh_item_ids(); |
@@ -982,7 +982,7 @@ discard block |
||
982 | 982 | return $saved; |
983 | 983 | } |
984 | 984 | |
985 | - public function add_fee( $args, $global = true ) { |
|
985 | + public function add_fee($args, $global = true) { |
|
986 | 986 | $default_args = array( |
987 | 987 | 'label' => '', |
988 | 988 | 'amount' => 0, |
@@ -992,75 +992,75 @@ discard block |
||
992 | 992 | 'item_id' => 0, |
993 | 993 | ); |
994 | 994 | |
995 | - $fee = wp_parse_args( $args, $default_args ); |
|
995 | + $fee = wp_parse_args($args, $default_args); |
|
996 | 996 | |
997 | - if ( empty( $fee['label'] ) ) { |
|
997 | + if (empty($fee['label'])) { |
|
998 | 998 | return false; |
999 | 999 | } |
1000 | 1000 | |
1001 | - $fee['id'] = sanitize_title( $fee['label'] ); |
|
1001 | + $fee['id'] = sanitize_title($fee['label']); |
|
1002 | 1002 | |
1003 | - $this->fees[] = $fee; |
|
1003 | + $this->fees[] = $fee; |
|
1004 | 1004 | |
1005 | 1005 | $added_fee = $fee; |
1006 | 1006 | $added_fee['action'] = 'add'; |
1007 | 1007 | $this->pending['fees'][] = $added_fee; |
1008 | - reset( $this->fees ); |
|
1008 | + reset($this->fees); |
|
1009 | 1009 | |
1010 | - $this->increase_fees( $fee['amount'] ); |
|
1010 | + $this->increase_fees($fee['amount']); |
|
1011 | 1011 | return true; |
1012 | 1012 | } |
1013 | 1013 | |
1014 | - public function remove_fee( $key ) { |
|
1014 | + public function remove_fee($key) { |
|
1015 | 1015 | $removed = false; |
1016 | 1016 | |
1017 | - if ( is_numeric( $key ) ) { |
|
1018 | - $removed = $this->remove_fee_by( 'index', $key ); |
|
1017 | + if (is_numeric($key)) { |
|
1018 | + $removed = $this->remove_fee_by('index', $key); |
|
1019 | 1019 | } |
1020 | 1020 | |
1021 | 1021 | return $removed; |
1022 | 1022 | } |
1023 | 1023 | |
1024 | - public function remove_fee_by( $key, $value, $global = false ) { |
|
1025 | - $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array( |
|
1024 | + public function remove_fee_by($key, $value, $global = false) { |
|
1025 | + $allowed_fee_keys = apply_filters('wpinv_fee_keys', array( |
|
1026 | 1026 | 'index', 'label', 'amount', 'type', |
1027 | - ) ); |
|
1027 | + )); |
|
1028 | 1028 | |
1029 | - if ( ! in_array( $key, $allowed_fee_keys ) ) { |
|
1029 | + if (!in_array($key, $allowed_fee_keys)) { |
|
1030 | 1030 | return false; |
1031 | 1031 | } |
1032 | 1032 | |
1033 | 1033 | $removed = false; |
1034 | - if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) { |
|
1035 | - $removed_fee = $this->fees[ $value ]; |
|
1034 | + if ('index' === $key && array_key_exists($value, $this->fees)) { |
|
1035 | + $removed_fee = $this->fees[$value]; |
|
1036 | 1036 | $removed_fee['action'] = 'remove'; |
1037 | 1037 | $this->pending['fees'][] = $removed_fee; |
1038 | 1038 | |
1039 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
1039 | + $this->decrease_fees($removed_fee['amount']); |
|
1040 | 1040 | |
1041 | - unset( $this->fees[ $value ] ); |
|
1041 | + unset($this->fees[$value]); |
|
1042 | 1042 | $removed = true; |
1043 | - } else if ( 'index' !== $key ) { |
|
1044 | - foreach ( $this->fees as $index => $fee ) { |
|
1045 | - if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) { |
|
1043 | + } else if ('index' !== $key) { |
|
1044 | + foreach ($this->fees as $index => $fee) { |
|
1045 | + if (isset($fee[$key]) && $fee[$key] == $value) { |
|
1046 | 1046 | $removed_fee = $fee; |
1047 | 1047 | $removed_fee['action'] = 'remove'; |
1048 | 1048 | $this->pending['fees'][] = $removed_fee; |
1049 | 1049 | |
1050 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
1050 | + $this->decrease_fees($removed_fee['amount']); |
|
1051 | 1051 | |
1052 | - unset( $this->fees[ $index ] ); |
|
1052 | + unset($this->fees[$index]); |
|
1053 | 1053 | $removed = true; |
1054 | 1054 | |
1055 | - if ( false === $global ) { |
|
1055 | + if (false === $global) { |
|
1056 | 1056 | break; |
1057 | 1057 | } |
1058 | 1058 | } |
1059 | 1059 | } |
1060 | 1060 | } |
1061 | 1061 | |
1062 | - if ( true === $removed ) { |
|
1063 | - $this->fees = array_values( $this->fees ); |
|
1062 | + if (true === $removed) { |
|
1063 | + $this->fees = array_values($this->fees); |
|
1064 | 1064 | } |
1065 | 1065 | |
1066 | 1066 | return $removed; |
@@ -1068,35 +1068,35 @@ discard block |
||
1068 | 1068 | |
1069 | 1069 | |
1070 | 1070 | |
1071 | - public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
|
1071 | + public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) { |
|
1072 | 1072 | // Bail if no note specified |
1073 | - if( !$note ) { |
|
1073 | + if (!$note) { |
|
1074 | 1074 | return false; |
1075 | 1075 | } |
1076 | 1076 | |
1077 | - if ( empty( $this->ID ) ) |
|
1077 | + if (empty($this->ID)) |
|
1078 | 1078 | return false; |
1079 | 1079 | |
1080 | - if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && !$system ) { |
|
1081 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
1080 | + if (((is_user_logged_in() && wpinv_current_user_can_manage_invoicing()) || $added_by_user) && !$system) { |
|
1081 | + $user = get_user_by('id', get_current_user_id()); |
|
1082 | 1082 | $comment_author = $user->display_name; |
1083 | 1083 | $comment_author_email = $user->user_email; |
1084 | 1084 | } else { |
1085 | 1085 | $comment_author = 'System'; |
1086 | 1086 | $comment_author_email = 'system@'; |
1087 | - $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com'; |
|
1088 | - $comment_author_email = sanitize_email( $comment_author_email ); |
|
1087 | + $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com'; |
|
1088 | + $comment_author_email = sanitize_email($comment_author_email); |
|
1089 | 1089 | } |
1090 | 1090 | |
1091 | - do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type ); |
|
1091 | + do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type); |
|
1092 | 1092 | |
1093 | - $note_id = wp_insert_comment( wp_filter_comment( array( |
|
1093 | + $note_id = wp_insert_comment(wp_filter_comment(array( |
|
1094 | 1094 | 'comment_post_ID' => $this->ID, |
1095 | 1095 | 'comment_content' => $note, |
1096 | 1096 | 'comment_agent' => 'WPInvoicing', |
1097 | 1097 | 'user_id' => is_admin() ? get_current_user_id() : 0, |
1098 | - 'comment_date' => current_time( 'mysql' ), |
|
1099 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
1098 | + 'comment_date' => current_time('mysql'), |
|
1099 | + 'comment_date_gmt' => current_time('mysql', 1), |
|
1100 | 1100 | 'comment_approved' => 1, |
1101 | 1101 | 'comment_parent' => 0, |
1102 | 1102 | 'comment_author' => $comment_author, |
@@ -1104,53 +1104,53 @@ discard block |
||
1104 | 1104 | 'comment_author_url' => '', |
1105 | 1105 | 'comment_author_email' => $comment_author_email, |
1106 | 1106 | 'comment_type' => 'wpinv_note' |
1107 | - ) ) ); |
|
1107 | + ))); |
|
1108 | 1108 | |
1109 | - do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note ); |
|
1109 | + do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note); |
|
1110 | 1110 | |
1111 | - if ( $customer_type ) { |
|
1112 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
1111 | + if ($customer_type) { |
|
1112 | + add_comment_meta($note_id, '_wpi_customer_note', 1); |
|
1113 | 1113 | |
1114 | - do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) ); |
|
1114 | + do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note)); |
|
1115 | 1115 | } |
1116 | 1116 | |
1117 | 1117 | return $note_id; |
1118 | 1118 | } |
1119 | 1119 | |
1120 | - private function increase_subtotal( $amount = 0.00 ) { |
|
1120 | + private function increase_subtotal($amount = 0.00) { |
|
1121 | 1121 | $amount = (float) $amount; |
1122 | 1122 | $this->subtotal += $amount; |
1123 | - $this->subtotal = wpinv_round_amount( $this->subtotal ); |
|
1123 | + $this->subtotal = wpinv_round_amount($this->subtotal); |
|
1124 | 1124 | |
1125 | 1125 | $this->recalculate_total(); |
1126 | 1126 | } |
1127 | 1127 | |
1128 | - private function decrease_subtotal( $amount = 0.00 ) { |
|
1128 | + private function decrease_subtotal($amount = 0.00) { |
|
1129 | 1129 | $amount = (float) $amount; |
1130 | 1130 | $this->subtotal -= $amount; |
1131 | - $this->subtotal = wpinv_round_amount( $this->subtotal ); |
|
1131 | + $this->subtotal = wpinv_round_amount($this->subtotal); |
|
1132 | 1132 | |
1133 | - if ( $this->subtotal < 0 ) { |
|
1133 | + if ($this->subtotal < 0) { |
|
1134 | 1134 | $this->subtotal = 0; |
1135 | 1135 | } |
1136 | 1136 | |
1137 | 1137 | $this->recalculate_total(); |
1138 | 1138 | } |
1139 | 1139 | |
1140 | - private function increase_fees( $amount = 0.00 ) { |
|
1141 | - $amount = (float)$amount; |
|
1140 | + private function increase_fees($amount = 0.00) { |
|
1141 | + $amount = (float) $amount; |
|
1142 | 1142 | $this->fees_total += $amount; |
1143 | - $this->fees_total = wpinv_round_amount( $this->fees_total ); |
|
1143 | + $this->fees_total = wpinv_round_amount($this->fees_total); |
|
1144 | 1144 | |
1145 | 1145 | $this->recalculate_total(); |
1146 | 1146 | } |
1147 | 1147 | |
1148 | - private function decrease_fees( $amount = 0.00 ) { |
|
1148 | + private function decrease_fees($amount = 0.00) { |
|
1149 | 1149 | $amount = (float) $amount; |
1150 | 1150 | $this->fees_total -= $amount; |
1151 | - $this->fees_total = wpinv_round_amount( $this->fees_total ); |
|
1151 | + $this->fees_total = wpinv_round_amount($this->fees_total); |
|
1152 | 1152 | |
1153 | - if ( $this->fees_total < 0 ) { |
|
1153 | + if ($this->fees_total < 0) { |
|
1154 | 1154 | $this->fees_total = 0; |
1155 | 1155 | } |
1156 | 1156 | |
@@ -1161,54 +1161,54 @@ discard block |
||
1161 | 1161 | global $wpi_nosave; |
1162 | 1162 | |
1163 | 1163 | $this->total = $this->subtotal + $this->tax + $this->fees_total; |
1164 | - $this->total = wpinv_round_amount( $this->total ); |
|
1164 | + $this->total = wpinv_round_amount($this->total); |
|
1165 | 1165 | |
1166 | - do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave ); |
|
1166 | + do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave); |
|
1167 | 1167 | } |
1168 | 1168 | |
1169 | - public function increase_tax( $amount = 0.00 ) { |
|
1169 | + public function increase_tax($amount = 0.00) { |
|
1170 | 1170 | $amount = (float) $amount; |
1171 | 1171 | $this->tax += $amount; |
1172 | 1172 | |
1173 | 1173 | $this->recalculate_total(); |
1174 | 1174 | } |
1175 | 1175 | |
1176 | - public function decrease_tax( $amount = 0.00 ) { |
|
1176 | + public function decrease_tax($amount = 0.00) { |
|
1177 | 1177 | $amount = (float) $amount; |
1178 | 1178 | $this->tax -= $amount; |
1179 | 1179 | |
1180 | - if ( $this->tax < 0 ) { |
|
1180 | + if ($this->tax < 0) { |
|
1181 | 1181 | $this->tax = 0; |
1182 | 1182 | } |
1183 | 1183 | |
1184 | 1184 | $this->recalculate_total(); |
1185 | 1185 | } |
1186 | 1186 | |
1187 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
1188 | - $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID ); |
|
1187 | + public function update_status($new_status = false, $note = '', $manual = false) { |
|
1188 | + $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID); |
|
1189 | 1189 | |
1190 | - if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses( true ) ) ) ) { |
|
1190 | + if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses(true)))) { |
|
1191 | 1191 | return false; // Don't permit status changes that aren't changes |
1192 | 1192 | } |
1193 | 1193 | |
1194 | - $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status ); |
|
1194 | + $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status); |
|
1195 | 1195 | $updated = false; |
1196 | 1196 | |
1197 | - if ( $do_change ) { |
|
1198 | - do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status ); |
|
1197 | + if ($do_change) { |
|
1198 | + do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status); |
|
1199 | 1199 | |
1200 | 1200 | $update_post_data = array(); |
1201 | 1201 | $update_post_data['ID'] = $this->ID; |
1202 | 1202 | $update_post_data['post_status'] = $new_status; |
1203 | - $update_post_data['edit_date'] = current_time( 'mysql', 0 ); |
|
1204 | - $update_post_data['edit_date_gmt'] = current_time( 'mysql', 1 ); |
|
1203 | + $update_post_data['edit_date'] = current_time('mysql', 0); |
|
1204 | + $update_post_data['edit_date_gmt'] = current_time('mysql', 1); |
|
1205 | 1205 | |
1206 | - $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID ); |
|
1206 | + $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID); |
|
1207 | 1207 | |
1208 | - $updated = wp_update_post( $update_post_data ); |
|
1208 | + $updated = wp_update_post($update_post_data); |
|
1209 | 1209 | |
1210 | 1210 | // Process any specific status functions |
1211 | - switch( $new_status ) { |
|
1211 | + switch ($new_status) { |
|
1212 | 1212 | case 'wpi-refunded': |
1213 | 1213 | $this->process_refund(); |
1214 | 1214 | break; |
@@ -1221,9 +1221,9 @@ discard block |
||
1221 | 1221 | } |
1222 | 1222 | |
1223 | 1223 | // Status was changed. |
1224 | - do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status ); |
|
1225 | - do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status ); |
|
1226 | - do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status ); |
|
1224 | + do_action('wpinv_status_' . $new_status, $this->ID, $old_status); |
|
1225 | + do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status); |
|
1226 | + do_action('wpinv_update_status', $this->ID, $new_status, $old_status); |
|
1227 | 1227 | } |
1228 | 1228 | |
1229 | 1229 | return $updated; |
@@ -1237,68 +1237,68 @@ discard block |
||
1237 | 1237 | $this->save(); |
1238 | 1238 | } |
1239 | 1239 | |
1240 | - public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
1241 | - if ( empty( $meta_key ) ) { |
|
1240 | + public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { |
|
1241 | + if (empty($meta_key)) { |
|
1242 | 1242 | return false; |
1243 | 1243 | } |
1244 | 1244 | |
1245 | - if ( $meta_key == 'key' || $meta_key == 'date' ) { |
|
1245 | + if ($meta_key == 'key' || $meta_key == 'date') { |
|
1246 | 1246 | $current_meta = $this->get_meta(); |
1247 | - $current_meta[ $meta_key ] = $meta_value; |
|
1247 | + $current_meta[$meta_key] = $meta_value; |
|
1248 | 1248 | |
1249 | 1249 | $meta_key = '_wpinv_payment_meta'; |
1250 | 1250 | $meta_value = $current_meta; |
1251 | 1251 | } |
1252 | 1252 | |
1253 | - $key = str_ireplace( '_wpinv_', '', $meta_key ); |
|
1253 | + $key = str_ireplace('_wpinv_', '', $meta_key); |
|
1254 | 1254 | $this->$key = $meta_value; |
1255 | 1255 | |
1256 | - $special = array_keys( $this->get_special_fields() ); |
|
1257 | - if ( in_array( $key, $special ) ) { |
|
1256 | + $special = array_keys($this->get_special_fields()); |
|
1257 | + if (in_array($key, $special)) { |
|
1258 | 1258 | $this->save_special(); |
1259 | 1259 | } else { |
1260 | - $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID ); |
|
1260 | + $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID); |
|
1261 | 1261 | } |
1262 | 1262 | |
1263 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value ); |
|
1263 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value); |
|
1264 | 1264 | } |
1265 | 1265 | |
1266 | 1266 | private function process_refund() { |
1267 | 1267 | $process_refund = true; |
1268 | 1268 | |
1269 | 1269 | // If the payment was not in publish, don't decrement stats as they were never incremented |
1270 | - if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) { |
|
1270 | + if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) { |
|
1271 | 1271 | $process_refund = false; |
1272 | 1272 | } |
1273 | 1273 | |
1274 | 1274 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
1275 | - $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this ); |
|
1275 | + $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this); |
|
1276 | 1276 | |
1277 | - if ( false === $process_refund ) { |
|
1277 | + if (false === $process_refund) { |
|
1278 | 1278 | return; |
1279 | 1279 | } |
1280 | 1280 | |
1281 | - do_action( 'wpinv_pre_refund_invoice', $this ); |
|
1281 | + do_action('wpinv_pre_refund_invoice', $this); |
|
1282 | 1282 | |
1283 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this ); |
|
1284 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this ); |
|
1285 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this ); |
|
1283 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this); |
|
1284 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this); |
|
1285 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this); |
|
1286 | 1286 | |
1287 | - do_action( 'wpinv_post_refund_invoice', $this ); |
|
1287 | + do_action('wpinv_post_refund_invoice', $this); |
|
1288 | 1288 | } |
1289 | 1289 | |
1290 | 1290 | private function process_failure() { |
1291 | 1291 | $discounts = $this->discounts; |
1292 | - if ( empty( $discounts ) ) { |
|
1292 | + if (empty($discounts)) { |
|
1293 | 1293 | return; |
1294 | 1294 | } |
1295 | 1295 | |
1296 | - if ( ! is_array( $discounts ) ) { |
|
1297 | - $discounts = array_map( 'trim', explode( ',', $discounts ) ); |
|
1296 | + if (!is_array($discounts)) { |
|
1297 | + $discounts = array_map('trim', explode(',', $discounts)); |
|
1298 | 1298 | } |
1299 | 1299 | |
1300 | - foreach ( $discounts as $discount ) { |
|
1301 | - wpinv_decrease_discount_usage( $discount ); |
|
1300 | + foreach ($discounts as $discount) { |
|
1301 | + wpinv_decrease_discount_usage($discount); |
|
1302 | 1302 | } |
1303 | 1303 | } |
1304 | 1304 | |
@@ -1306,95 +1306,95 @@ discard block |
||
1306 | 1306 | $process_pending = true; |
1307 | 1307 | |
1308 | 1308 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented |
1309 | - if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'wpi-pending' != $this->status ) { |
|
1309 | + if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'wpi-pending' != $this->status) { |
|
1310 | 1310 | $process_pending = false; |
1311 | 1311 | } |
1312 | 1312 | |
1313 | 1313 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
1314 | - $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this ); |
|
1314 | + $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this); |
|
1315 | 1315 | |
1316 | - if ( false === $process_pending ) { |
|
1316 | + if (false === $process_pending) { |
|
1317 | 1317 | return; |
1318 | 1318 | } |
1319 | 1319 | |
1320 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this ); |
|
1321 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this ); |
|
1322 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this ); |
|
1320 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this); |
|
1321 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this); |
|
1322 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this); |
|
1323 | 1323 | |
1324 | 1324 | $this->completed_date = ''; |
1325 | - $this->update_meta( '_wpinv_completed_date', '' ); |
|
1325 | + $this->update_meta('_wpinv_completed_date', ''); |
|
1326 | 1326 | } |
1327 | 1327 | |
1328 | 1328 | // get data |
1329 | - public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
1330 | - $meta = get_post_meta( $this->ID, $meta_key, $single ); |
|
1329 | + public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) { |
|
1330 | + $meta = get_post_meta($this->ID, $meta_key, $single); |
|
1331 | 1331 | |
1332 | - if ( $meta_key === '_wpinv_payment_meta' ) { |
|
1332 | + if ($meta_key === '_wpinv_payment_meta') { |
|
1333 | 1333 | |
1334 | - if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is. |
|
1334 | + if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is. |
|
1335 | 1335 | |
1336 | - if ( empty( $meta['key'] ) ) { |
|
1336 | + if (empty($meta['key'])) { |
|
1337 | 1337 | $meta['key'] = $this->key; |
1338 | 1338 | } |
1339 | 1339 | |
1340 | - if ( empty( $meta['date'] ) ) { |
|
1341 | - $meta['date'] = get_post_field( 'post_date', $this->ID ); |
|
1340 | + if (empty($meta['date'])) { |
|
1341 | + $meta['date'] = get_post_field('post_date', $this->ID); |
|
1342 | 1342 | } |
1343 | 1343 | } |
1344 | 1344 | |
1345 | - $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID ); |
|
1345 | + $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID); |
|
1346 | 1346 | |
1347 | - return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key ); |
|
1347 | + return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key); |
|
1348 | 1348 | } |
1349 | 1349 | |
1350 | 1350 | public function get_description() { |
1351 | - $post = get_post( $this->ID ); |
|
1351 | + $post = get_post($this->ID); |
|
1352 | 1352 | |
1353 | - $description = !empty( $post ) ? $post->post_content : ''; |
|
1354 | - return apply_filters( 'wpinv_get_description', $description, $this->ID, $this ); |
|
1353 | + $description = !empty($post) ? $post->post_content : ''; |
|
1354 | + return apply_filters('wpinv_get_description', $description, $this->ID, $this); |
|
1355 | 1355 | } |
1356 | 1356 | |
1357 | - public function get_status( $nicename = false ) { |
|
1358 | - if ( !$nicename ) { |
|
1357 | + public function get_status($nicename = false) { |
|
1358 | + if (!$nicename) { |
|
1359 | 1359 | $status = $this->status; |
1360 | 1360 | } else { |
1361 | 1361 | $status = $this->status_nicename; |
1362 | 1362 | } |
1363 | 1363 | |
1364 | - return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this ); |
|
1364 | + return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this); |
|
1365 | 1365 | } |
1366 | 1366 | |
1367 | 1367 | public function get_cart_details() { |
1368 | - return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this ); |
|
1368 | + return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this); |
|
1369 | 1369 | } |
1370 | 1370 | |
1371 | - public function get_subtotal( $currency = false ) { |
|
1372 | - $subtotal = wpinv_round_amount( $this->subtotal ); |
|
1371 | + public function get_subtotal($currency = false) { |
|
1372 | + $subtotal = wpinv_round_amount($this->subtotal); |
|
1373 | 1373 | |
1374 | - if ( $currency ) { |
|
1375 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() ); |
|
1374 | + if ($currency) { |
|
1375 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency()); |
|
1376 | 1376 | } |
1377 | 1377 | |
1378 | - return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency ); |
|
1378 | + return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency); |
|
1379 | 1379 | } |
1380 | 1380 | |
1381 | - public function get_total( $currency = false ) { |
|
1382 | - if ( $this->is_free_trial() ) { |
|
1383 | - $total = wpinv_round_amount( 0 ); |
|
1381 | + public function get_total($currency = false) { |
|
1382 | + if ($this->is_free_trial()) { |
|
1383 | + $total = wpinv_round_amount(0); |
|
1384 | 1384 | } else { |
1385 | - $total = wpinv_round_amount( $this->total ); |
|
1385 | + $total = wpinv_round_amount($this->total); |
|
1386 | 1386 | } |
1387 | - if ( $currency ) { |
|
1388 | - $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() ); |
|
1387 | + if ($currency) { |
|
1388 | + $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency()); |
|
1389 | 1389 | } |
1390 | 1390 | |
1391 | - return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency ); |
|
1391 | + return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency); |
|
1392 | 1392 | } |
1393 | 1393 | |
1394 | 1394 | /** |
1395 | 1395 | * Returns recurring payment details. |
1396 | 1396 | */ |
1397 | - public function get_recurring_details( $field = '', $currency = false ) { |
|
1397 | + public function get_recurring_details($field = '', $currency = false) { |
|
1398 | 1398 | $data = array(); |
1399 | 1399 | $data['cart_details'] = $this->cart_details; |
1400 | 1400 | $data['subtotal'] = $this->get_subtotal(); |
@@ -1402,75 +1402,75 @@ discard block |
||
1402 | 1402 | $data['tax'] = $this->get_tax(); |
1403 | 1403 | $data['total'] = $this->get_total(); |
1404 | 1404 | |
1405 | - if ( $this->is_parent() || $this->is_renewal() ) { |
|
1405 | + if ($this->is_parent() || $this->is_renewal()) { |
|
1406 | 1406 | |
1407 | - if ( $this->is_free_trial() || ( $this->total == 0 && $this->discount_first_payment_only() ) ) { |
|
1407 | + if ($this->is_free_trial() || ($this->total == 0 && $this->discount_first_payment_only())) { |
|
1408 | 1408 | |
1409 | - $data['subtotal'] = wpinv_round_amount( $this->subtotal ); |
|
1410 | - $data['discount'] = wpinv_round_amount( 0 ); |
|
1411 | - $data['tax'] = wpinv_round_amount( $this->tax ); |
|
1412 | - $data['total'] = wpinv_round_amount( $this->total + $this->discount ); |
|
1409 | + $data['subtotal'] = wpinv_round_amount($this->subtotal); |
|
1410 | + $data['discount'] = wpinv_round_amount(0); |
|
1411 | + $data['tax'] = wpinv_round_amount($this->tax); |
|
1412 | + $data['total'] = wpinv_round_amount($this->total + $this->discount); |
|
1413 | 1413 | |
1414 | 1414 | } else { |
1415 | 1415 | |
1416 | - $data['subtotal'] = wpinv_round_amount( $this->subtotal ); |
|
1417 | - $data['discount'] = wpinv_round_amount( $this->discount ); |
|
1418 | - $data['tax'] = wpinv_round_amount( $this->tax ); |
|
1419 | - $data['total'] = wpinv_round_amount( $this->total ); |
|
1416 | + $data['subtotal'] = wpinv_round_amount($this->subtotal); |
|
1417 | + $data['discount'] = wpinv_round_amount($this->discount); |
|
1418 | + $data['tax'] = wpinv_round_amount($this->tax); |
|
1419 | + $data['total'] = wpinv_round_amount($this->total); |
|
1420 | 1420 | |
1421 | 1421 | } |
1422 | 1422 | |
1423 | 1423 | } |
1424 | 1424 | |
1425 | - $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency ); |
|
1425 | + $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency); |
|
1426 | 1426 | |
1427 | - if ( isset( $data[$field] ) ) { |
|
1428 | - return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
|
1427 | + if (isset($data[$field])) { |
|
1428 | + return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]); |
|
1429 | 1429 | } |
1430 | 1430 | |
1431 | 1431 | return $data; |
1432 | 1432 | } |
1433 | 1433 | |
1434 | - public function get_final_tax( $currency = false ) { |
|
1435 | - $final_total = wpinv_round_amount( $this->tax ); |
|
1436 | - if ( $currency ) { |
|
1437 | - $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() ); |
|
1434 | + public function get_final_tax($currency = false) { |
|
1435 | + $final_total = wpinv_round_amount($this->tax); |
|
1436 | + if ($currency) { |
|
1437 | + $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency()); |
|
1438 | 1438 | } |
1439 | 1439 | |
1440 | - return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency ); |
|
1440 | + return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency); |
|
1441 | 1441 | } |
1442 | 1442 | |
1443 | - public function get_discounts( $array = false ) { |
|
1443 | + public function get_discounts($array = false) { |
|
1444 | 1444 | $discounts = $this->discounts; |
1445 | - if ( $array && $discounts ) { |
|
1446 | - $discounts = explode( ',', $discounts ); |
|
1445 | + if ($array && $discounts) { |
|
1446 | + $discounts = explode(',', $discounts); |
|
1447 | 1447 | } |
1448 | - return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array ); |
|
1448 | + return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array); |
|
1449 | 1449 | } |
1450 | 1450 | |
1451 | - public function get_discount( $currency = false, $dash = false ) { |
|
1452 | - if ( !empty( $this->discounts ) ) { |
|
1451 | + public function get_discount($currency = false, $dash = false) { |
|
1452 | + if (!empty($this->discounts)) { |
|
1453 | 1453 | global $ajax_cart_details; |
1454 | 1454 | $ajax_cart_details = $this->get_cart_details(); |
1455 | 1455 | |
1456 | - if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) { |
|
1456 | + if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) { |
|
1457 | 1457 | $cart_items = $ajax_cart_details; |
1458 | 1458 | } else { |
1459 | 1459 | $cart_items = $this->items; |
1460 | 1460 | } |
1461 | 1461 | |
1462 | - $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts ); |
|
1462 | + $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts); |
|
1463 | 1463 | } |
1464 | - $discount = wpinv_round_amount( $this->discount ); |
|
1464 | + $discount = wpinv_round_amount($this->discount); |
|
1465 | 1465 | $dash = $dash && $discount > 0 ? '–' : ''; |
1466 | 1466 | |
1467 | - if ( $currency ) { |
|
1468 | - $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() ); |
|
1467 | + if ($currency) { |
|
1468 | + $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency()); |
|
1469 | 1469 | } |
1470 | 1470 | |
1471 | - $discount = $dash . $discount; |
|
1471 | + $discount = $dash . $discount; |
|
1472 | 1472 | |
1473 | - return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash ); |
|
1473 | + return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash); |
|
1474 | 1474 | } |
1475 | 1475 | |
1476 | 1476 | public function get_discount_code() { |
@@ -1482,163 +1482,163 @@ discard block |
||
1482 | 1482 | return (int) $this->disable_taxes === 0; |
1483 | 1483 | } |
1484 | 1484 | |
1485 | - public function get_tax( $currency = false ) { |
|
1486 | - $tax = wpinv_round_amount( $this->tax ); |
|
1485 | + public function get_tax($currency = false) { |
|
1486 | + $tax = wpinv_round_amount($this->tax); |
|
1487 | 1487 | |
1488 | - if ( $currency ) { |
|
1489 | - $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() ); |
|
1488 | + if ($currency) { |
|
1489 | + $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency()); |
|
1490 | 1490 | } |
1491 | 1491 | |
1492 | - if ( ! $this->is_taxable() ) { |
|
1493 | - $tax = wpinv_round_amount( 0.00 ); |
|
1492 | + if (!$this->is_taxable()) { |
|
1493 | + $tax = wpinv_round_amount(0.00); |
|
1494 | 1494 | } |
1495 | 1495 | |
1496 | - return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency ); |
|
1496 | + return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency); |
|
1497 | 1497 | } |
1498 | 1498 | |
1499 | - public function get_fees( $type = 'all' ) { |
|
1500 | - $fees = array(); |
|
1499 | + public function get_fees($type = 'all') { |
|
1500 | + $fees = array(); |
|
1501 | 1501 | |
1502 | - if ( ! empty( $this->fees ) && is_array( $this->fees ) ) { |
|
1503 | - foreach ( $this->fees as $fee ) { |
|
1504 | - if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
1502 | + if (!empty($this->fees) && is_array($this->fees)) { |
|
1503 | + foreach ($this->fees as $fee) { |
|
1504 | + if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) { |
|
1505 | 1505 | continue; |
1506 | 1506 | } |
1507 | 1507 | |
1508 | - $fee['label'] = stripslashes( $fee['label'] ); |
|
1509 | - $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() ); |
|
1510 | - $fees[] = $fee; |
|
1508 | + $fee['label'] = stripslashes($fee['label']); |
|
1509 | + $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency()); |
|
1510 | + $fees[] = $fee; |
|
1511 | 1511 | } |
1512 | 1512 | } |
1513 | 1513 | |
1514 | - return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this ); |
|
1514 | + return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this); |
|
1515 | 1515 | } |
1516 | 1516 | |
1517 | - public function get_fees_total( $type = 'all' ) { |
|
1517 | + public function get_fees_total($type = 'all') { |
|
1518 | 1518 | $fees_total = (float) 0.00; |
1519 | 1519 | |
1520 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
1521 | - if ( ! empty( $payment_fees ) ) { |
|
1522 | - foreach ( $payment_fees as $fee ) { |
|
1520 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
1521 | + if (!empty($payment_fees)) { |
|
1522 | + foreach ($payment_fees as $fee) { |
|
1523 | 1523 | $fees_total += (float) $fee['amount']; |
1524 | 1524 | } |
1525 | 1525 | } |
1526 | 1526 | |
1527 | - return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this ); |
|
1527 | + return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this); |
|
1528 | 1528 | |
1529 | 1529 | } |
1530 | 1530 | |
1531 | 1531 | public function get_user_id() { |
1532 | - return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this ); |
|
1532 | + return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this); |
|
1533 | 1533 | } |
1534 | 1534 | |
1535 | 1535 | public function get_first_name() { |
1536 | - return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this ); |
|
1536 | + return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this); |
|
1537 | 1537 | } |
1538 | 1538 | |
1539 | 1539 | public function get_last_name() { |
1540 | - return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this ); |
|
1540 | + return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this); |
|
1541 | 1541 | } |
1542 | 1542 | |
1543 | 1543 | public function get_user_full_name() { |
1544 | - return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this ); |
|
1544 | + return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this); |
|
1545 | 1545 | } |
1546 | 1546 | |
1547 | 1547 | public function get_user_info() { |
1548 | - return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this ); |
|
1548 | + return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this); |
|
1549 | 1549 | } |
1550 | 1550 | |
1551 | 1551 | public function get_email() { |
1552 | - return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this ); |
|
1552 | + return apply_filters('wpinv_user_email', $this->email, $this->ID, $this); |
|
1553 | 1553 | } |
1554 | 1554 | |
1555 | 1555 | public function get_address() { |
1556 | - return apply_filters( 'wpinv_address', $this->address, $this->ID, $this ); |
|
1556 | + return apply_filters('wpinv_address', $this->address, $this->ID, $this); |
|
1557 | 1557 | } |
1558 | 1558 | |
1559 | 1559 | public function get_phone() { |
1560 | - return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this ); |
|
1560 | + return apply_filters('wpinv_phone', $this->phone, $this->ID, $this); |
|
1561 | 1561 | } |
1562 | 1562 | |
1563 | 1563 | public function get_number() { |
1564 | - return apply_filters( 'wpinv_number', $this->number, $this->ID, $this ); |
|
1564 | + return apply_filters('wpinv_number', $this->number, $this->ID, $this); |
|
1565 | 1565 | } |
1566 | 1566 | |
1567 | 1567 | public function get_items() { |
1568 | - return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this ); |
|
1568 | + return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this); |
|
1569 | 1569 | } |
1570 | 1570 | |
1571 | 1571 | public function get_key() { |
1572 | - return apply_filters( 'wpinv_key', $this->key, $this->ID, $this ); |
|
1572 | + return apply_filters('wpinv_key', $this->key, $this->ID, $this); |
|
1573 | 1573 | } |
1574 | 1574 | |
1575 | 1575 | public function get_transaction_id() { |
1576 | - return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this ); |
|
1576 | + return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this); |
|
1577 | 1577 | } |
1578 | 1578 | |
1579 | 1579 | public function get_gateway() { |
1580 | - return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this ); |
|
1580 | + return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this); |
|
1581 | 1581 | } |
1582 | 1582 | |
1583 | 1583 | public function get_gateway_title() { |
1584 | - $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway ); |
|
1584 | + $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway); |
|
1585 | 1585 | |
1586 | - return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this ); |
|
1586 | + return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this); |
|
1587 | 1587 | } |
1588 | 1588 | |
1589 | 1589 | public function get_currency() { |
1590 | - return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this ); |
|
1590 | + return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this); |
|
1591 | 1591 | } |
1592 | 1592 | |
1593 | 1593 | public function get_created_date() { |
1594 | - return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this ); |
|
1594 | + return apply_filters('wpinv_created_date', $this->date, $this->ID, $this); |
|
1595 | 1595 | } |
1596 | 1596 | |
1597 | - public function get_due_date( $display = false ) { |
|
1598 | - $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this ); |
|
1597 | + public function get_due_date($display = false) { |
|
1598 | + $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this); |
|
1599 | 1599 | |
1600 | - if ( !$display || empty( $due_date ) ) { |
|
1600 | + if (!$display || empty($due_date)) { |
|
1601 | 1601 | return $due_date; |
1602 | 1602 | } |
1603 | 1603 | |
1604 | - return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) ); |
|
1604 | + return date_i18n(get_option('date_format'), strtotime($due_date)); |
|
1605 | 1605 | } |
1606 | 1606 | |
1607 | 1607 | public function get_completed_date() { |
1608 | - return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this ); |
|
1608 | + return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this); |
|
1609 | 1609 | } |
1610 | 1610 | |
1611 | - public function get_invoice_date( $formatted = true ) { |
|
1611 | + public function get_invoice_date($formatted = true) { |
|
1612 | 1612 | $date_completed = $this->completed_date; |
1613 | 1613 | $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : ''; |
1614 | 1614 | |
1615 | - if ( $invoice_date == '' ) { |
|
1615 | + if ($invoice_date == '') { |
|
1616 | 1616 | $date_created = $this->date; |
1617 | 1617 | $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : ''; |
1618 | 1618 | } |
1619 | 1619 | |
1620 | - if ( $formatted && $invoice_date ) { |
|
1621 | - $invoice_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) ); |
|
1620 | + if ($formatted && $invoice_date) { |
|
1621 | + $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date)); |
|
1622 | 1622 | } |
1623 | 1623 | |
1624 | - return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this ); |
|
1624 | + return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this); |
|
1625 | 1625 | } |
1626 | 1626 | |
1627 | 1627 | public function get_ip() { |
1628 | - return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this ); |
|
1628 | + return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this); |
|
1629 | 1629 | } |
1630 | 1630 | |
1631 | - public function has_status( $status ) { |
|
1632 | - return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status ); |
|
1631 | + public function has_status($status) { |
|
1632 | + return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status); |
|
1633 | 1633 | } |
1634 | 1634 | |
1635 | - public function add_item( $item_id = 0, $args = array() ) { |
|
1635 | + public function add_item($item_id = 0, $args = array()) { |
|
1636 | 1636 | global $wpi_current_id, $wpi_item_id; |
1637 | 1637 | |
1638 | - $item = new WPInv_Item( $item_id ); |
|
1638 | + $item = new WPInv_Item($item_id); |
|
1639 | 1639 | |
1640 | 1640 | // Bail if this post isn't a item |
1641 | - if( !$item || $item->post_type !== 'wpi_item' ) { |
|
1641 | + if (!$item || $item->post_type !== 'wpi_item') { |
|
1642 | 1642 | return false; |
1643 | 1643 | } |
1644 | 1644 | |
@@ -1657,8 +1657,8 @@ discard block |
||
1657 | 1657 | 'fees' => array() |
1658 | 1658 | ); |
1659 | 1659 | |
1660 | - $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults ); |
|
1661 | - $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1; |
|
1660 | + $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults); |
|
1661 | + $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1; |
|
1662 | 1662 | |
1663 | 1663 | $wpi_current_id = $this->ID; |
1664 | 1664 | $wpi_item_id = $item->ID; |
@@ -1670,19 +1670,19 @@ discard block |
||
1670 | 1670 | $found_cart_key = false; |
1671 | 1671 | |
1672 | 1672 | if ($has_quantities) { |
1673 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
1673 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
1674 | 1674 | |
1675 | - foreach ( $this->items as $key => $cart_item ) { |
|
1676 | - if ( (int)$item_id !== (int)$cart_item['id'] ) { |
|
1675 | + foreach ($this->items as $key => $cart_item) { |
|
1676 | + if ((int) $item_id !== (int) $cart_item['id']) { |
|
1677 | 1677 | continue; |
1678 | 1678 | } |
1679 | 1679 | |
1680 | - $this->items[ $key ]['quantity'] += $args['quantity']; |
|
1680 | + $this->items[$key]['quantity'] += $args['quantity']; |
|
1681 | 1681 | break; |
1682 | 1682 | } |
1683 | 1683 | |
1684 | - foreach ( $this->cart_details as $cart_key => $cart_item ) { |
|
1685 | - if ( $item_id != $cart_item['id'] ) { |
|
1684 | + foreach ($this->cart_details as $cart_key => $cart_item) { |
|
1685 | + if ($item_id != $cart_item['id']) { |
|
1686 | 1686 | continue; |
1687 | 1687 | } |
1688 | 1688 | |
@@ -1694,29 +1694,29 @@ discard block |
||
1694 | 1694 | if ($has_quantities && $found_cart_key !== false) { |
1695 | 1695 | $cart_item = $this->cart_details[$found_cart_key]; |
1696 | 1696 | $item_price = $cart_item['item_price']; |
1697 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
1698 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
1697 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
1698 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
1699 | 1699 | |
1700 | 1700 | $new_quantity = $quantity + $args['quantity']; |
1701 | 1701 | $subtotal = $item_price * $new_quantity; |
1702 | 1702 | |
1703 | 1703 | $args['quantity'] = $new_quantity; |
1704 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
1705 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1704 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
1705 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
1706 | 1706 | |
1707 | - $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0; |
|
1708 | - $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0; |
|
1707 | + $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float) $cart_item['discount'] ? $discount - (float) $cart_item['discount'] : 0; |
|
1708 | + $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float) $cart_item['tax'] ? $tax - (float) $cart_item['tax'] : 0; |
|
1709 | 1709 | // The total increase equals the number removed * the item_price |
1710 | - $total_increased = wpinv_round_amount( $item_price ); |
|
1710 | + $total_increased = wpinv_round_amount($item_price); |
|
1711 | 1711 | |
1712 | - if ( wpinv_prices_include_tax() ) { |
|
1713 | - $subtotal -= wpinv_round_amount( $tax ); |
|
1712 | + if (wpinv_prices_include_tax()) { |
|
1713 | + $subtotal -= wpinv_round_amount($tax); |
|
1714 | 1714 | } |
1715 | 1715 | |
1716 | - $total = $subtotal - $discount + $tax; |
|
1716 | + $total = $subtotal - $discount + $tax; |
|
1717 | 1717 | |
1718 | 1718 | // Do not allow totals to go negative |
1719 | - if( $total < 0 ) { |
|
1719 | + if ($total < 0) { |
|
1720 | 1720 | $total = 0; |
1721 | 1721 | } |
1722 | 1722 | |
@@ -1732,25 +1732,25 @@ discard block |
||
1732 | 1732 | $this->cart_details[$found_cart_key] = $cart_item; |
1733 | 1733 | } else { |
1734 | 1734 | // Set custom price. |
1735 | - if ( $args['custom_price'] !== '' ) { |
|
1735 | + if ($args['custom_price'] !== '') { |
|
1736 | 1736 | $item_price = $args['custom_price']; |
1737 | 1737 | } else { |
1738 | 1738 | // Allow overriding the price |
1739 | - if ( false !== $args['item_price'] ) { |
|
1739 | + if (false !== $args['item_price']) { |
|
1740 | 1740 | $item_price = $args['item_price']; |
1741 | 1741 | } else { |
1742 | - $item_price = wpinv_get_item_price( $item->ID ); |
|
1742 | + $item_price = wpinv_get_item_price($item->ID); |
|
1743 | 1743 | } |
1744 | 1744 | } |
1745 | 1745 | |
1746 | 1746 | // Sanitizing the price here so we don't have a dozen calls later |
1747 | - $item_price = wpinv_sanitize_amount( $item_price ); |
|
1748 | - $subtotal = wpinv_round_amount( $item_price * $args['quantity'] ); |
|
1747 | + $item_price = wpinv_sanitize_amount($item_price); |
|
1748 | + $subtotal = wpinv_round_amount($item_price * $args['quantity']); |
|
1749 | 1749 | |
1750 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
1751 | - $tax_class = !empty( $args['vat_class'] ) ? $args['vat_class'] : ''; |
|
1752 | - $tax_rate = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0; |
|
1753 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1750 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
1751 | + $tax_class = !empty($args['vat_class']) ? $args['vat_class'] : ''; |
|
1752 | + $tax_rate = !empty($args['vat_rate']) ? $args['vat_rate'] : 0; |
|
1753 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
1754 | 1754 | |
1755 | 1755 | // Setup the items meta item |
1756 | 1756 | $new_item = array( |
@@ -1758,29 +1758,29 @@ discard block |
||
1758 | 1758 | 'quantity' => $args['quantity'], |
1759 | 1759 | ); |
1760 | 1760 | |
1761 | - $this->items[] = $new_item; |
|
1761 | + $this->items[] = $new_item; |
|
1762 | 1762 | |
1763 | - if ( wpinv_prices_include_tax() ) { |
|
1764 | - $subtotal -= wpinv_round_amount( $tax ); |
|
1763 | + if (wpinv_prices_include_tax()) { |
|
1764 | + $subtotal -= wpinv_round_amount($tax); |
|
1765 | 1765 | } |
1766 | 1766 | |
1767 | - $total = $subtotal - $discount + $tax; |
|
1767 | + $total = $subtotal - $discount + $tax; |
|
1768 | 1768 | |
1769 | 1769 | // Do not allow totals to go negative |
1770 | - if( $total < 0 ) { |
|
1770 | + if ($total < 0) { |
|
1771 | 1771 | $total = 0; |
1772 | 1772 | } |
1773 | 1773 | |
1774 | 1774 | $this->cart_details[] = array( |
1775 | 1775 | 'name' => !empty($args['name']) ? $args['name'] : $item->get_name(), |
1776 | 1776 | 'id' => $item->ID, |
1777 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
1778 | - 'custom_price' => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ), |
|
1777 | + 'item_price' => wpinv_round_amount($item_price), |
|
1778 | + 'custom_price' => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''), |
|
1779 | 1779 | 'quantity' => $args['quantity'], |
1780 | 1780 | 'discount' => $discount, |
1781 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
1782 | - 'tax' => wpinv_round_amount( $tax ), |
|
1783 | - 'price' => wpinv_round_amount( $total ), |
|
1781 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
1782 | + 'tax' => wpinv_round_amount($tax), |
|
1783 | + 'price' => wpinv_round_amount($total), |
|
1784 | 1784 | 'vat_rate' => $tax_rate, |
1785 | 1785 | 'vat_class' => $tax_class, |
1786 | 1786 | 'meta' => $args['meta'], |
@@ -1790,18 +1790,18 @@ discard block |
||
1790 | 1790 | $subtotal = $subtotal - $discount; |
1791 | 1791 | } |
1792 | 1792 | |
1793 | - $added_item = end( $this->cart_details ); |
|
1794 | - $added_item['action'] = 'add'; |
|
1793 | + $added_item = end($this->cart_details); |
|
1794 | + $added_item['action'] = 'add'; |
|
1795 | 1795 | |
1796 | 1796 | $this->pending['items'][] = $added_item; |
1797 | 1797 | |
1798 | - $this->increase_subtotal( $subtotal ); |
|
1799 | - $this->increase_tax( $tax ); |
|
1798 | + $this->increase_subtotal($subtotal); |
|
1799 | + $this->increase_tax($tax); |
|
1800 | 1800 | |
1801 | 1801 | return true; |
1802 | 1802 | } |
1803 | 1803 | |
1804 | - public function remove_item( $item_id, $args = array() ) { |
|
1804 | + public function remove_item($item_id, $args = array()) { |
|
1805 | 1805 | |
1806 | 1806 | // Set some defaults |
1807 | 1807 | $defaults = array( |
@@ -1810,51 +1810,51 @@ discard block |
||
1810 | 1810 | 'custom_price' => '', |
1811 | 1811 | 'cart_index' => false, |
1812 | 1812 | ); |
1813 | - $args = wp_parse_args( $args, $defaults ); |
|
1813 | + $args = wp_parse_args($args, $defaults); |
|
1814 | 1814 | |
1815 | 1815 | // Bail if this post isn't a item |
1816 | - if ( get_post_type( $item_id ) !== 'wpi_item' ) { |
|
1816 | + if (get_post_type($item_id) !== 'wpi_item') { |
|
1817 | 1817 | return false; |
1818 | 1818 | } |
1819 | 1819 | |
1820 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
1820 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
1821 | 1821 | |
1822 | - foreach ( $this->items as $key => $item ) { |
|
1823 | - if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) { |
|
1822 | + foreach ($this->items as $key => $item) { |
|
1823 | + if (!empty($item['id']) && (int) $item_id !== (int) $item['id']) { |
|
1824 | 1824 | continue; |
1825 | 1825 | } |
1826 | 1826 | |
1827 | - if ( false !== $args['cart_index'] ) { |
|
1828 | - $cart_index = absint( $args['cart_index'] ); |
|
1829 | - $cart_item = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false; |
|
1827 | + if (false !== $args['cart_index']) { |
|
1828 | + $cart_index = absint($args['cart_index']); |
|
1829 | + $cart_item = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false; |
|
1830 | 1830 | |
1831 | - if ( ! empty( $cart_item ) ) { |
|
1831 | + if (!empty($cart_item)) { |
|
1832 | 1832 | // If the cart index item isn't the same item ID, don't remove it |
1833 | - if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) { |
|
1833 | + if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) { |
|
1834 | 1834 | continue; |
1835 | 1835 | } |
1836 | 1836 | } |
1837 | 1837 | } |
1838 | 1838 | |
1839 | - $item_quantity = $this->items[ $key ]['quantity']; |
|
1840 | - if ( $item_quantity > $args['quantity'] ) { |
|
1841 | - $this->items[ $key ]['quantity'] -= $args['quantity']; |
|
1839 | + $item_quantity = $this->items[$key]['quantity']; |
|
1840 | + if ($item_quantity > $args['quantity']) { |
|
1841 | + $this->items[$key]['quantity'] -= $args['quantity']; |
|
1842 | 1842 | break; |
1843 | 1843 | } else { |
1844 | - unset( $this->items[ $key ] ); |
|
1844 | + unset($this->items[$key]); |
|
1845 | 1845 | break; |
1846 | 1846 | } |
1847 | 1847 | } |
1848 | 1848 | |
1849 | 1849 | $found_cart_key = false; |
1850 | - if ( false === $args['cart_index'] ) { |
|
1851 | - foreach ( $this->cart_details as $cart_key => $item ) { |
|
1852 | - if ( $item_id != $item['id'] ) { |
|
1850 | + if (false === $args['cart_index']) { |
|
1851 | + foreach ($this->cart_details as $cart_key => $item) { |
|
1852 | + if ($item_id != $item['id']) { |
|
1853 | 1853 | continue; |
1854 | 1854 | } |
1855 | 1855 | |
1856 | - if ( false !== $args['item_price'] ) { |
|
1857 | - if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) { |
|
1856 | + if (false !== $args['item_price']) { |
|
1857 | + if (isset($item['item_price']) && (float) $args['item_price'] != (float) $item['item_price']) { |
|
1858 | 1858 | continue; |
1859 | 1859 | } |
1860 | 1860 | } |
@@ -1863,13 +1863,13 @@ discard block |
||
1863 | 1863 | break; |
1864 | 1864 | } |
1865 | 1865 | } else { |
1866 | - $cart_index = absint( $args['cart_index'] ); |
|
1866 | + $cart_index = absint($args['cart_index']); |
|
1867 | 1867 | |
1868 | - if ( ! array_key_exists( $cart_index, $this->cart_details ) ) { |
|
1868 | + if (!array_key_exists($cart_index, $this->cart_details)) { |
|
1869 | 1869 | return false; // Invalid cart index passed. |
1870 | 1870 | } |
1871 | 1871 | |
1872 | - if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) { |
|
1872 | + if ((int) $this->cart_details[$cart_index]['id'] > 0 && (int) $this->cart_details[$cart_index]['id'] !== (int) $item_id) { |
|
1873 | 1873 | return false; // We still need the proper Item ID to be sure. |
1874 | 1874 | } |
1875 | 1875 | |
@@ -1877,41 +1877,41 @@ discard block |
||
1877 | 1877 | } |
1878 | 1878 | |
1879 | 1879 | $cart_item = $this->cart_details[$found_cart_key]; |
1880 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
1880 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
1881 | 1881 | |
1882 | - if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) { |
|
1882 | + if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) { |
|
1883 | 1883 | //return false; // Invoice must contain at least one item. |
1884 | 1884 | } |
1885 | 1885 | |
1886 | - $discounts = $this->get_discounts(); |
|
1886 | + $discounts = $this->get_discounts(); |
|
1887 | 1887 | |
1888 | - if ( $quantity > $args['quantity'] ) { |
|
1888 | + if ($quantity > $args['quantity']) { |
|
1889 | 1889 | $item_price = $cart_item['item_price']; |
1890 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
1890 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
1891 | 1891 | |
1892 | - $new_quantity = max( $quantity - $args['quantity'], 1); |
|
1892 | + $new_quantity = max($quantity - $args['quantity'], 1); |
|
1893 | 1893 | $subtotal = $item_price * $new_quantity; |
1894 | 1894 | |
1895 | 1895 | $args['quantity'] = $new_quantity; |
1896 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
1897 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1896 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
1897 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
1898 | 1898 | |
1899 | - $discount_decrease = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0; |
|
1900 | - $discount_decrease = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; |
|
1901 | - $tax_decrease = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0; |
|
1902 | - $tax_decrease = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease; |
|
1899 | + $discount_decrease = (float) $cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['discount'] / $quantity)) : 0; |
|
1900 | + $discount_decrease = $discount > 0 && $subtotal > 0 && (float) $cart_item['discount'] > $discount ? (float) $cart_item['discount'] - $discount : $discount_decrease; |
|
1901 | + $tax_decrease = (float) $cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['tax'] / $quantity)) : 0; |
|
1902 | + $tax_decrease = $tax > 0 && $subtotal > 0 && (float) $cart_item['tax'] > $tax ? (float) $cart_item['tax'] - $tax : $tax_decrease; |
|
1903 | 1903 | |
1904 | 1904 | // The total increase equals the number removed * the item_price |
1905 | - $total_decrease = wpinv_round_amount( $item_price ); |
|
1905 | + $total_decrease = wpinv_round_amount($item_price); |
|
1906 | 1906 | |
1907 | - if ( wpinv_prices_include_tax() ) { |
|
1908 | - $subtotal -= wpinv_round_amount( $tax ); |
|
1907 | + if (wpinv_prices_include_tax()) { |
|
1908 | + $subtotal -= wpinv_round_amount($tax); |
|
1909 | 1909 | } |
1910 | 1910 | |
1911 | - $total = $subtotal - $discount + $tax; |
|
1911 | + $total = $subtotal - $discount + $tax; |
|
1912 | 1912 | |
1913 | 1913 | // Do not allow totals to go negative |
1914 | - if( $total < 0 ) { |
|
1914 | + if ($total < 0) { |
|
1915 | 1915 | $total = 0; |
1916 | 1916 | } |
1917 | 1917 | |
@@ -1930,16 +1930,16 @@ discard block |
||
1930 | 1930 | |
1931 | 1931 | $this->cart_details[$found_cart_key] = $cart_item; |
1932 | 1932 | |
1933 | - $remove_item = end( $this->cart_details ); |
|
1933 | + $remove_item = end($this->cart_details); |
|
1934 | 1934 | } else { |
1935 | 1935 | $item_price = $cart_item['item_price']; |
1936 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
1937 | - $tax = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0; |
|
1936 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
1937 | + $tax = !empty($cart_item['tax']) ? $cart_item['tax'] : 0; |
|
1938 | 1938 | |
1939 | - $subtotal_decrease = ( $item_price * $quantity ) - $discount; |
|
1939 | + $subtotal_decrease = ($item_price * $quantity) - $discount; |
|
1940 | 1940 | $tax_decrease = $tax; |
1941 | 1941 | |
1942 | - unset( $this->cart_details[$found_cart_key] ); |
|
1942 | + unset($this->cart_details[$found_cart_key]); |
|
1943 | 1943 | |
1944 | 1944 | $remove_item = $args; |
1945 | 1945 | $remove_item['id'] = $item_id; |
@@ -1950,8 +1950,8 @@ discard block |
||
1950 | 1950 | $remove_item['action'] = 'remove'; |
1951 | 1951 | $this->pending['items'][] = $remove_item; |
1952 | 1952 | |
1953 | - $this->decrease_subtotal( $subtotal_decrease ); |
|
1954 | - $this->decrease_tax( $tax_decrease ); |
|
1953 | + $this->decrease_subtotal($subtotal_decrease); |
|
1954 | + $this->decrease_tax($tax_decrease); |
|
1955 | 1955 | |
1956 | 1956 | return true; |
1957 | 1957 | } |
@@ -1959,7 +1959,7 @@ discard block |
||
1959 | 1959 | public function update_items($temp = false) { |
1960 | 1960 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave; |
1961 | 1961 | |
1962 | - if ( ! empty( $this->cart_details ) ) { |
|
1962 | + if (!empty($this->cart_details)) { |
|
1963 | 1963 | $wpi_nosave = $temp; |
1964 | 1964 | $cart_subtotal = 0; |
1965 | 1965 | $cart_discount = 0; |
@@ -1969,65 +1969,65 @@ discard block |
||
1969 | 1969 | $_POST['wpinv_country'] = $this->country; |
1970 | 1970 | $_POST['wpinv_state'] = $this->state; |
1971 | 1971 | |
1972 | - foreach ( $this->cart_details as $key => $item ) { |
|
1972 | + foreach ($this->cart_details as $key => $item) { |
|
1973 | 1973 | $item_price = $item['item_price']; |
1974 | - $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
1975 | - $amount = wpinv_round_amount( $item_price * $quantity ); |
|
1974 | + $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
1975 | + $amount = wpinv_round_amount($item_price * $quantity); |
|
1976 | 1976 | $subtotal = $item_price * $quantity; |
1977 | 1977 | |
1978 | 1978 | $wpi_current_id = $this->ID; |
1979 | 1979 | $wpi_item_id = $item['id']; |
1980 | 1980 | |
1981 | - $discount = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() ); |
|
1981 | + $discount = wpinv_get_cart_item_discount_amount($item, $this->get_discounts()); |
|
1982 | 1982 | |
1983 | - $tax_rate = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id ); |
|
1984 | - $tax_class = $wpinv_euvat->get_item_class( $wpi_item_id ); |
|
1985 | - $tax = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1983 | + $tax_rate = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id); |
|
1984 | + $tax_class = $wpinv_euvat->get_item_class($wpi_item_id); |
|
1985 | + $tax = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
1986 | 1986 | |
1987 | - if ( ! $this->is_taxable() ) { |
|
1987 | + if (!$this->is_taxable()) { |
|
1988 | 1988 | $tax = 0; |
1989 | 1989 | } |
1990 | 1990 | |
1991 | - if ( wpinv_prices_include_tax() ) { |
|
1992 | - $subtotal -= wpinv_round_amount( $tax ); |
|
1991 | + if (wpinv_prices_include_tax()) { |
|
1992 | + $subtotal -= wpinv_round_amount($tax); |
|
1993 | 1993 | } |
1994 | 1994 | |
1995 | - $total = $subtotal - $discount + $tax; |
|
1995 | + $total = $subtotal - $discount + $tax; |
|
1996 | 1996 | |
1997 | 1997 | // Do not allow totals to go negative |
1998 | - if( $total < 0 ) { |
|
1998 | + if ($total < 0) { |
|
1999 | 1999 | $total = 0; |
2000 | 2000 | } |
2001 | 2001 | |
2002 | 2002 | $cart_details[] = array( |
2003 | 2003 | 'id' => $item['id'], |
2004 | 2004 | 'name' => $item['name'], |
2005 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
2006 | - 'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ), |
|
2005 | + 'item_price' => wpinv_round_amount($item_price), |
|
2006 | + 'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''), |
|
2007 | 2007 | 'quantity' => $quantity, |
2008 | 2008 | 'discount' => $discount, |
2009 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
2010 | - 'tax' => wpinv_round_amount( $tax ), |
|
2011 | - 'price' => wpinv_round_amount( $total ), |
|
2009 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
2010 | + 'tax' => wpinv_round_amount($tax), |
|
2011 | + 'price' => wpinv_round_amount($total), |
|
2012 | 2012 | 'vat_rate' => $tax_rate, |
2013 | 2013 | 'vat_class' => $tax_class, |
2014 | 2014 | 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
2015 | 2015 | 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
2016 | 2016 | ); |
2017 | 2017 | |
2018 | - $cart_subtotal += (float)($subtotal - $discount); // TODO |
|
2019 | - $cart_discount += (float)($discount); |
|
2020 | - $cart_tax += (float)($tax); |
|
2018 | + $cart_subtotal += (float) ($subtotal - $discount); // TODO |
|
2019 | + $cart_discount += (float) ($discount); |
|
2020 | + $cart_tax += (float) ($tax); |
|
2021 | 2021 | } |
2022 | - if ( $cart_subtotal < 0 ) { |
|
2022 | + if ($cart_subtotal < 0) { |
|
2023 | 2023 | $cart_subtotal = 0; |
2024 | 2024 | } |
2025 | - if ( $cart_tax < 0 ) { |
|
2025 | + if ($cart_tax < 0) { |
|
2026 | 2026 | $cart_tax = 0; |
2027 | 2027 | } |
2028 | - $this->subtotal = wpinv_round_amount( $cart_subtotal ); |
|
2029 | - $this->tax = wpinv_round_amount( $cart_tax ); |
|
2030 | - $this->discount = wpinv_round_amount( $cart_discount ); |
|
2028 | + $this->subtotal = wpinv_round_amount($cart_subtotal); |
|
2029 | + $this->tax = wpinv_round_amount($cart_tax); |
|
2030 | + $this->discount = wpinv_round_amount($cart_discount); |
|
2031 | 2031 | |
2032 | 2032 | $this->recalculate_total(); |
2033 | 2033 | |
@@ -2039,78 +2039,78 @@ discard block |
||
2039 | 2039 | |
2040 | 2040 | public function recalculate_totals($temp = false) { |
2041 | 2041 | $this->update_items($temp); |
2042 | - $this->save( true ); |
|
2042 | + $this->save(true); |
|
2043 | 2043 | |
2044 | 2044 | return $this; |
2045 | 2045 | } |
2046 | 2046 | |
2047 | 2047 | public function needs_payment() { |
2048 | - $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'wpi-pending' ), $this ); |
|
2048 | + $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('wpi-pending'), $this); |
|
2049 | 2049 | |
2050 | - if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free() ) ) { |
|
2050 | + if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free())) { |
|
2051 | 2051 | $needs_payment = true; |
2052 | 2052 | } else { |
2053 | 2053 | $needs_payment = false; |
2054 | 2054 | } |
2055 | 2055 | |
2056 | - return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses ); |
|
2056 | + return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses); |
|
2057 | 2057 | } |
2058 | 2058 | |
2059 | - public function get_checkout_payment_url( $with_key = false, $secret = false ) { |
|
2059 | + public function get_checkout_payment_url($with_key = false, $secret = false) { |
|
2060 | 2060 | $pay_url = wpinv_get_checkout_uri(); |
2061 | 2061 | |
2062 | - if ( is_ssl() ) { |
|
2063 | - $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
|
2062 | + if (is_ssl()) { |
|
2063 | + $pay_url = str_replace('http:', 'https:', $pay_url); |
|
2064 | 2064 | } |
2065 | 2065 | |
2066 | 2066 | $key = $this->get_key(); |
2067 | 2067 | |
2068 | - if ( $with_key ) { |
|
2069 | - $pay_url = add_query_arg( 'invoice_key', $key, $pay_url ); |
|
2068 | + if ($with_key) { |
|
2069 | + $pay_url = add_query_arg('invoice_key', $key, $pay_url); |
|
2070 | 2070 | } else { |
2071 | - $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url ); |
|
2071 | + $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url); |
|
2072 | 2072 | } |
2073 | 2073 | |
2074 | - if ( $secret ) { |
|
2075 | - $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url ); |
|
2074 | + if ($secret) { |
|
2075 | + $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url); |
|
2076 | 2076 | } |
2077 | 2077 | |
2078 | - return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret ); |
|
2078 | + return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret); |
|
2079 | 2079 | } |
2080 | 2080 | |
2081 | - public function get_view_url( $with_key = false ) { |
|
2082 | - $invoice_url = get_permalink( $this->ID ); |
|
2081 | + public function get_view_url($with_key = false) { |
|
2082 | + $invoice_url = get_permalink($this->ID); |
|
2083 | 2083 | |
2084 | - if ( $with_key ) { |
|
2085 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
2084 | + if ($with_key) { |
|
2085 | + $invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url); |
|
2086 | 2086 | } |
2087 | 2087 | |
2088 | - return apply_filters( 'wpinv_get_view_url', $invoice_url, $this, $with_key ); |
|
2088 | + return apply_filters('wpinv_get_view_url', $invoice_url, $this, $with_key); |
|
2089 | 2089 | } |
2090 | 2090 | |
2091 | - public function generate_key( $string = '' ) { |
|
2092 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
2093 | - return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) ); // Unique key |
|
2091 | + public function generate_key($string = '') { |
|
2092 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
2093 | + return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key |
|
2094 | 2094 | } |
2095 | 2095 | |
2096 | 2096 | public function is_recurring() { |
2097 | - if ( empty( $this->cart_details ) ) { |
|
2097 | + if (empty($this->cart_details)) { |
|
2098 | 2098 | return false; |
2099 | 2099 | } |
2100 | 2100 | |
2101 | 2101 | $has_subscription = false; |
2102 | - foreach( $this->cart_details as $cart_item ) { |
|
2103 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
2102 | + foreach ($this->cart_details as $cart_item) { |
|
2103 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
2104 | 2104 | $has_subscription = true; |
2105 | 2105 | break; |
2106 | 2106 | } |
2107 | 2107 | } |
2108 | 2108 | |
2109 | - if ( count( $this->cart_details ) > 1 ) { |
|
2109 | + if (count($this->cart_details) > 1) { |
|
2110 | 2110 | $has_subscription = false; |
2111 | 2111 | } |
2112 | 2112 | |
2113 | - return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details ); |
|
2113 | + return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details); |
|
2114 | 2114 | } |
2115 | 2115 | |
2116 | 2116 | /** |
@@ -2121,13 +2121,13 @@ discard block |
||
2121 | 2121 | public function is_free_trial() { |
2122 | 2122 | $is_free_trial = false; |
2123 | 2123 | |
2124 | - if ( $this->is_parent() && $item = $this->get_recurring( true ) ) { |
|
2125 | - if ( ! empty( $item ) && ( $item->has_free_trial() || ( $this->total == 0 && $this->discount_first_payment_only() ) ) ) { |
|
2124 | + if ($this->is_parent() && $item = $this->get_recurring(true)) { |
|
2125 | + if (!empty($item) && ($item->has_free_trial() || ($this->total == 0 && $this->discount_first_payment_only()))) { |
|
2126 | 2126 | $is_free_trial = true; |
2127 | 2127 | } |
2128 | 2128 | } |
2129 | 2129 | |
2130 | - return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this ); |
|
2130 | + return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this); |
|
2131 | 2131 | } |
2132 | 2132 | |
2133 | 2133 | /** |
@@ -2135,99 +2135,99 @@ discard block |
||
2135 | 2135 | */ |
2136 | 2136 | public function discount_first_payment_only() { |
2137 | 2137 | |
2138 | - if ( empty( $this->discounts ) || ! $this->is_recurring() ) { |
|
2138 | + if (empty($this->discounts) || !$this->is_recurring()) { |
|
2139 | 2139 | return false; |
2140 | 2140 | } |
2141 | 2141 | |
2142 | - $discount = wpinv_get_discount_obj( $this->discounts[0] ); |
|
2142 | + $discount = wpinv_get_discount_obj($this->discounts[0]); |
|
2143 | 2143 | return $discount && $discount->exists() && $discount->get_is_recurring(); |
2144 | 2144 | } |
2145 | 2145 | |
2146 | 2146 | public function is_initial_free() { |
2147 | 2147 | $is_initial_free = false; |
2148 | 2148 | |
2149 | - if ( ! ( (float)wpinv_round_amount( $this->get_total() ) > 0 ) && $this->is_parent() && $this->is_recurring() && ! $this->is_free_trial() && ! $this->is_free() ) { |
|
2149 | + if (!((float) wpinv_round_amount($this->get_total()) > 0) && $this->is_parent() && $this->is_recurring() && !$this->is_free_trial() && !$this->is_free()) { |
|
2150 | 2150 | $is_initial_free = true; |
2151 | 2151 | } |
2152 | 2152 | |
2153 | - return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details ); |
|
2153 | + return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details); |
|
2154 | 2154 | } |
2155 | 2155 | |
2156 | - public function get_recurring( $object = false ) { |
|
2156 | + public function get_recurring($object = false) { |
|
2157 | 2157 | $item = NULL; |
2158 | 2158 | |
2159 | - if ( empty( $this->cart_details ) ) { |
|
2159 | + if (empty($this->cart_details)) { |
|
2160 | 2160 | return $item; |
2161 | 2161 | } |
2162 | 2162 | |
2163 | - foreach( $this->cart_details as $cart_item ) { |
|
2164 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
2163 | + foreach ($this->cart_details as $cart_item) { |
|
2164 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
2165 | 2165 | $item = $cart_item['id']; |
2166 | 2166 | break; |
2167 | 2167 | } |
2168 | 2168 | } |
2169 | 2169 | |
2170 | - if ( $object ) { |
|
2171 | - $item = $item ? new WPInv_Item( $item ) : NULL; |
|
2170 | + if ($object) { |
|
2171 | + $item = $item ? new WPInv_Item($item) : NULL; |
|
2172 | 2172 | |
2173 | - apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this ); |
|
2173 | + apply_filters('wpinv_invoice_get_recurring_item', $item, $this); |
|
2174 | 2174 | } |
2175 | 2175 | |
2176 | - return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this ); |
|
2176 | + return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this); |
|
2177 | 2177 | } |
2178 | 2178 | |
2179 | 2179 | public function get_subscription_name() { |
2180 | - $item = $this->get_recurring( true ); |
|
2180 | + $item = $this->get_recurring(true); |
|
2181 | 2181 | |
2182 | - if ( empty( $item ) ) { |
|
2182 | + if (empty($item)) { |
|
2183 | 2183 | return NULL; |
2184 | 2184 | } |
2185 | 2185 | |
2186 | - if ( !($name = $item->get_name()) ) { |
|
2186 | + if (!($name = $item->get_name())) { |
|
2187 | 2187 | $name = $item->post_name; |
2188 | 2188 | } |
2189 | 2189 | |
2190 | - return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this ); |
|
2190 | + return apply_filters('wpinv_invoice_get_subscription_name', $name, $this); |
|
2191 | 2191 | } |
2192 | 2192 | |
2193 | 2193 | public function get_subscription_id() { |
2194 | - $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true ); |
|
2194 | + $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true); |
|
2195 | 2195 | |
2196 | - if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) { |
|
2197 | - $parent_invoice = wpinv_get_invoice( $this->parent_invoice ); |
|
2196 | + if (empty($subscription_id) && !empty($this->parent_invoice)) { |
|
2197 | + $parent_invoice = wpinv_get_invoice($this->parent_invoice); |
|
2198 | 2198 | |
2199 | - $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true ); |
|
2199 | + $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true); |
|
2200 | 2200 | } |
2201 | 2201 | |
2202 | 2202 | return $subscription_id; |
2203 | 2203 | } |
2204 | 2204 | |
2205 | 2205 | public function is_parent() { |
2206 | - $is_parent = empty( $this->parent_invoice ) ? true : false; |
|
2206 | + $is_parent = empty($this->parent_invoice) ? true : false; |
|
2207 | 2207 | |
2208 | - return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this ); |
|
2208 | + return apply_filters('wpinv_invoice_is_parent', $is_parent, $this); |
|
2209 | 2209 | } |
2210 | 2210 | |
2211 | 2211 | public function is_renewal() { |
2212 | 2212 | $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false; |
2213 | 2213 | |
2214 | - return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this ); |
|
2214 | + return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this); |
|
2215 | 2215 | } |
2216 | 2216 | |
2217 | 2217 | public function get_parent_payment() { |
2218 | 2218 | $parent_payment = NULL; |
2219 | 2219 | |
2220 | - if ( $this->is_renewal() ) { |
|
2221 | - $parent_payment = wpinv_get_invoice( $this->parent_invoice ); |
|
2220 | + if ($this->is_renewal()) { |
|
2221 | + $parent_payment = wpinv_get_invoice($this->parent_invoice); |
|
2222 | 2222 | } |
2223 | 2223 | |
2224 | 2224 | return $parent_payment; |
2225 | 2225 | } |
2226 | 2226 | |
2227 | 2227 | public function is_paid() { |
2228 | - $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
|
2228 | + $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal')); |
|
2229 | 2229 | |
2230 | - return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
|
2230 | + return apply_filters('wpinv_invoice_is_paid', $is_paid, $this); |
|
2231 | 2231 | } |
2232 | 2232 | |
2233 | 2233 | /** |
@@ -2240,23 +2240,23 @@ discard block |
||
2240 | 2240 | } |
2241 | 2241 | |
2242 | 2242 | public function is_refunded() { |
2243 | - $is_refunded = $this->has_status( array( 'wpi-refunded' ) ); |
|
2243 | + $is_refunded = $this->has_status(array('wpi-refunded')); |
|
2244 | 2244 | |
2245 | - return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
|
2245 | + return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this); |
|
2246 | 2246 | } |
2247 | 2247 | |
2248 | 2248 | public function is_free() { |
2249 | 2249 | $is_free = false; |
2250 | 2250 | |
2251 | - if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) { |
|
2252 | - if ( $this->is_parent() && $this->is_recurring() ) { |
|
2253 | - $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true; |
|
2251 | + if (!((float) wpinv_round_amount($this->get_total()) > 0)) { |
|
2252 | + if ($this->is_parent() && $this->is_recurring()) { |
|
2253 | + $is_free = (float) wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true; |
|
2254 | 2254 | } else { |
2255 | 2255 | $is_free = true; |
2256 | 2256 | } |
2257 | 2257 | } |
2258 | 2258 | |
2259 | - return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
|
2259 | + return apply_filters('wpinv_invoice_is_free', $is_free, $this); |
|
2260 | 2260 | } |
2261 | 2261 | |
2262 | 2262 | public function has_vat() { |
@@ -2264,41 +2264,41 @@ discard block |
||
2264 | 2264 | |
2265 | 2265 | $requires_vat = false; |
2266 | 2266 | |
2267 | - if ( $this->country ) { |
|
2267 | + if ($this->country) { |
|
2268 | 2268 | $wpi_country = $this->country; |
2269 | 2269 | |
2270 | - $requires_vat = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) ); |
|
2270 | + $requires_vat = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this)); |
|
2271 | 2271 | } |
2272 | 2272 | |
2273 | - return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this ); |
|
2273 | + return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this); |
|
2274 | 2274 | } |
2275 | 2275 | |
2276 | 2276 | public function refresh_item_ids() { |
2277 | 2277 | $item_ids = array(); |
2278 | 2278 | |
2279 | - if ( ! empty( $this->cart_details ) ) { |
|
2280 | - foreach ( array_keys( $this->cart_details ) as $item ) { |
|
2281 | - if ( ! empty( $item['id'] ) ) { |
|
2279 | + if (!empty($this->cart_details)) { |
|
2280 | + foreach (array_keys($this->cart_details) as $item) { |
|
2281 | + if (!empty($item['id'])) { |
|
2282 | 2282 | $item_ids[] = $item['id']; |
2283 | 2283 | } |
2284 | 2284 | } |
2285 | 2285 | } |
2286 | 2286 | |
2287 | - $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : ''; |
|
2287 | + $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : ''; |
|
2288 | 2288 | |
2289 | - update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids ); |
|
2289 | + update_post_meta($this->ID, '_wpinv_item_ids', $item_ids); |
|
2290 | 2290 | } |
2291 | 2291 | |
2292 | - public function get_invoice_quote_type( $post_id ) { |
|
2293 | - if ( empty( $post_id ) ) { |
|
2292 | + public function get_invoice_quote_type($post_id) { |
|
2293 | + if (empty($post_id)) { |
|
2294 | 2294 | return ''; |
2295 | 2295 | } |
2296 | 2296 | |
2297 | - $type = get_post_type( $post_id ); |
|
2297 | + $type = get_post_type($post_id); |
|
2298 | 2298 | |
2299 | - if ( 'wpi_invoice' === $type ) { |
|
2299 | + if ('wpi_invoice' === $type) { |
|
2300 | 2300 | $post_type = __('Invoice', 'invoicing'); |
2301 | - } else{ |
|
2301 | + } else { |
|
2302 | 2302 | $post_type = __('Quote', 'invoicing'); |
2303 | 2303 | } |
2304 | 2304 |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | } |
701 | 701 | |
702 | 702 | function wpinv_get_payment_key( $invoice_id = 0 ) { |
703 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
703 | + $invoice = new WPInv_Invoice( $invoice_id ); |
|
704 | 704 | return $invoice->get_key(); |
705 | 705 | } |
706 | 706 | |
@@ -966,7 +966,7 @@ discard block |
||
966 | 966 | return false; |
967 | 967 | } |
968 | 968 | $invoice = wpinv_get_invoice_cart(); |
969 | - if ( empty( $invoice ) ) { |
|
969 | + if ( empty( $invoice ) ) { |
|
970 | 970 | return false; |
971 | 971 | } |
972 | 972 | |
@@ -1259,20 +1259,20 @@ discard block |
||
1259 | 1259 | } |
1260 | 1260 | |
1261 | 1261 | function wpinv_checkout_get_cc_info() { |
1262 | - $cc_info = array(); |
|
1263 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
1264 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
1265 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
1266 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
1267 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
1268 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
1269 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
1270 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
1271 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
1272 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
1273 | - |
|
1274 | - // Return cc info |
|
1275 | - return $cc_info; |
|
1262 | + $cc_info = array(); |
|
1263 | + $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
1264 | + $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
1265 | + $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
1266 | + $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
1267 | + $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
1268 | + $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
1269 | + $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
1270 | + $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
1271 | + $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
1272 | + $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
1273 | + |
|
1274 | + // Return cc info |
|
1275 | + return $cc_info; |
|
1276 | 1276 | } |
1277 | 1277 | |
1278 | 1278 | function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
@@ -1479,7 +1479,7 @@ discard block |
||
1479 | 1479 | $required_fields = wpinv_checkout_required_fields(); |
1480 | 1480 | |
1481 | 1481 | // Loop through required fields and show error messages |
1482 | - if ( !empty( $required_fields ) ) { |
|
1482 | + if ( !empty( $required_fields ) ) { |
|
1483 | 1483 | foreach ( $required_fields as $field_name => $value ) { |
1484 | 1484 | if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
1485 | 1485 | wpinv_set_error( $value['error_id'], $value['error_message'] ); |
@@ -1582,7 +1582,7 @@ discard block |
||
1582 | 1582 | } |
1583 | 1583 | |
1584 | 1584 | function wpinv_get_checkout_session() { |
1585 | - global $wpi_session; |
|
1585 | + global $wpi_session; |
|
1586 | 1586 | |
1587 | 1587 | return $wpi_session->get( 'wpinv_checkout' ); |
1588 | 1588 | } |
@@ -1663,7 +1663,7 @@ discard block |
||
1663 | 1663 | $response['data']['taxf'] = $invoice->get_tax( true ); |
1664 | 1664 | $response['data']['total'] = $invoice->get_total(); |
1665 | 1665 | $response['data']['totalf'] = $invoice->get_total( true ); |
1666 | - $response['data']['free'] = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false; |
|
1666 | + $response['data']['free'] = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false; |
|
1667 | 1667 | |
1668 | 1668 | wp_send_json( $response ); |
1669 | 1669 | } |
@@ -1734,8 +1734,8 @@ discard block |
||
1734 | 1734 | // Allow themes and plugins to hook before the gateway |
1735 | 1735 | do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
1736 | 1736 | |
1737 | - // If it is free, abort. |
|
1738 | - if ( $invoice->is_free() && ! ( $invoice->is_recurring() || ! $invoice->has_free_lifetime_discount() ) ) { |
|
1737 | + // If it is free, abort. |
|
1738 | + if ( $invoice->is_free() && ! ( $invoice->is_recurring() || ! $invoice->has_free_lifetime_discount() ) ) { |
|
1739 | 1739 | $invoice_data['gateway'] = 'manual'; |
1740 | 1740 | $_POST['wpi-gateway'] = 'manual'; |
1741 | 1741 | } |
@@ -1950,52 +1950,52 @@ discard block |
||
1950 | 1950 | * Given an invoice key, this function returns the id. |
1951 | 1951 | */ |
1952 | 1952 | function wpinv_get_invoice_id_by_key( $key ) { |
1953 | - global $wpdb; |
|
1953 | + global $wpdb; |
|
1954 | 1954 | $table = $wpdb->prefix . 'getpaid_invoices'; |
1955 | - return (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key ) ); |
|
1955 | + return (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key ) ); |
|
1956 | 1956 | } |
1957 | 1957 | |
1958 | 1958 | function wpinv_can_view_receipt( $invoice_key = '' ) { |
1959 | - $return = false; |
|
1959 | + $return = false; |
|
1960 | 1960 | |
1961 | - if ( empty( $invoice_key ) ) { |
|
1962 | - return $return; |
|
1963 | - } |
|
1961 | + if ( empty( $invoice_key ) ) { |
|
1962 | + return $return; |
|
1963 | + } |
|
1964 | 1964 | |
1965 | - global $wpinv_receipt_args; |
|
1965 | + global $wpinv_receipt_args; |
|
1966 | 1966 | |
1967 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1968 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
1969 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
1970 | - } |
|
1967 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1968 | + if ( isset( $_GET['invoice-id'] ) ) { |
|
1969 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
1970 | + } |
|
1971 | 1971 | |
1972 | - if ( empty( $wpinv_receipt_args['id'] ) ) { |
|
1973 | - return $return; |
|
1974 | - } |
|
1972 | + if ( empty( $wpinv_receipt_args['id'] ) ) { |
|
1973 | + return $return; |
|
1974 | + } |
|
1975 | 1975 | |
1976 | - $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] ); |
|
1977 | - if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) { |
|
1978 | - return $return; |
|
1979 | - } |
|
1976 | + $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] ); |
|
1977 | + if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) { |
|
1978 | + return $return; |
|
1979 | + } |
|
1980 | 1980 | |
1981 | - if ( is_user_logged_in() ) { |
|
1982 | - if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) { |
|
1983 | - $return = true; |
|
1984 | - } |
|
1985 | - } |
|
1981 | + if ( is_user_logged_in() ) { |
|
1982 | + if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) { |
|
1983 | + $return = true; |
|
1984 | + } |
|
1985 | + } |
|
1986 | 1986 | |
1987 | - $session = wpinv_get_checkout_session(); |
|
1988 | - if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) { |
|
1989 | - $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
1987 | + $session = wpinv_get_checkout_session(); |
|
1988 | + if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) { |
|
1989 | + $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
1990 | 1990 | |
1991 | - if ( wpinv_require_login_to_checkout() ) { |
|
1992 | - $return = $return && $check_key === $invoice_key; |
|
1993 | - } else { |
|
1994 | - $return = $check_key === $invoice_key; |
|
1995 | - } |
|
1996 | - } |
|
1991 | + if ( wpinv_require_login_to_checkout() ) { |
|
1992 | + $return = $return && $check_key === $invoice_key; |
|
1993 | + } else { |
|
1994 | + $return = $check_key === $invoice_key; |
|
1995 | + } |
|
1996 | + } |
|
1997 | 1997 | |
1998 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
1998 | + return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
1999 | 1999 | } |
2000 | 2000 | |
2001 | 2001 | function wpinv_pay_for_invoice() { |
@@ -2305,14 +2305,14 @@ discard block |
||
2305 | 2305 | |
2306 | 2306 | if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) { |
2307 | 2307 | $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : ''; |
2308 | - global $post; |
|
2308 | + global $post; |
|
2309 | 2309 | |
2310 | 2310 | if(!empty($invoice_key)){ |
2311 | - $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
2311 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
2312 | 2312 | } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) { |
2313 | - $invoice_id = $post->ID; |
|
2313 | + $invoice_id = $post->ID; |
|
2314 | 2314 | } else { |
2315 | - return; |
|
2315 | + return; |
|
2316 | 2316 | } |
2317 | 2317 | |
2318 | 2318 | $invoice = new WPInv_Invoice($invoice_id); |
@@ -2321,17 +2321,17 @@ discard block |
||
2321 | 2321 | return; |
2322 | 2322 | } |
2323 | 2323 | |
2324 | - if ( is_user_logged_in() ) { |
|
2325 | - if ( (int)$invoice->get_user_id() === get_current_user_id() ) { |
|
2326 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2327 | - } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2328 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2329 | - } |
|
2330 | - } else { |
|
2331 | - if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2332 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2333 | - } |
|
2334 | - } |
|
2324 | + if ( is_user_logged_in() ) { |
|
2325 | + if ( (int)$invoice->get_user_id() === get_current_user_id() ) { |
|
2326 | + update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2327 | + } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2328 | + update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2329 | + } |
|
2330 | + } else { |
|
2331 | + if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2332 | + update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2333 | + } |
|
2334 | + } |
|
2335 | 2335 | } |
2336 | 2336 | |
2337 | 2337 | } |
@@ -7,14 +7,14 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_get_invoice_cart_id() { |
15 | 15 | $wpinv_checkout = wpinv_get_checkout_session(); |
16 | 16 | |
17 | - if ( !empty( $wpinv_checkout['invoice_id'] ) ) { |
|
17 | + if (!empty($wpinv_checkout['invoice_id'])) { |
|
18 | 18 | return $wpinv_checkout['invoice_id']; |
19 | 19 | } |
20 | 20 | |
@@ -28,48 +28,48 @@ discard block |
||
28 | 28 | * @param bool $wp_error Whether to return false or WP_Error on failure. |
29 | 29 | * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success. |
30 | 30 | */ |
31 | -function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) { |
|
32 | - if ( empty( $invoice_data ) ) { |
|
31 | +function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) { |
|
32 | + if (empty($invoice_data)) { |
|
33 | 33 | return false; |
34 | 34 | } |
35 | 35 | |
36 | - if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) { |
|
37 | - return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast one item.', 'invoicing' ) ) : 0; |
|
36 | + if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) { |
|
37 | + return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast one item.', 'invoicing')) : 0; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | // If no user id is provided, default to the current user id |
41 | - if ( empty( $invoice_data['user_id'] ) ) { |
|
41 | + if (empty($invoice_data['user_id'])) { |
|
42 | 42 | $invoice_data['user_id'] = get_current_user_id(); |
43 | 43 | } |
44 | 44 | |
45 | - $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0; |
|
45 | + $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int) $invoice_data['invoice_id'] : 0; |
|
46 | 46 | |
47 | - if ( empty( $invoice_data['status'] ) ) { |
|
47 | + if (empty($invoice_data['status'])) { |
|
48 | 48 | $invoice_data['status'] = 'wpi-pending'; |
49 | 49 | } |
50 | 50 | |
51 | - if ( empty( $invoice_data['post_type'] ) ) { |
|
51 | + if (empty($invoice_data['post_type'])) { |
|
52 | 52 | $invoice_data['post_type'] = 'wpi_invoice'; |
53 | 53 | } |
54 | 54 | |
55 | - if ( empty( $invoice_data['ip'] ) ) { |
|
55 | + if (empty($invoice_data['ip'])) { |
|
56 | 56 | $invoice_data['ip'] = wpinv_get_ip(); |
57 | 57 | } |
58 | 58 | |
59 | 59 | // default invoice args, note that status is checked for validity in wpinv_create_invoice() |
60 | 60 | $default_args = array( |
61 | - 'invoice_id' => (int)$invoice_data['invoice_id'], |
|
62 | - 'user_id' => (int)$invoice_data['user_id'], |
|
61 | + 'invoice_id' => (int) $invoice_data['invoice_id'], |
|
62 | + 'user_id' => (int) $invoice_data['user_id'], |
|
63 | 63 | 'status' => $invoice_data['status'], |
64 | 64 | 'post_type' => $invoice_data['post_type'], |
65 | 65 | ); |
66 | 66 | |
67 | - $invoice = wpinv_create_invoice( $default_args, $invoice_data, true ); |
|
68 | - if ( is_wp_error( $invoice ) ) { |
|
67 | + $invoice = wpinv_create_invoice($default_args, $invoice_data, true); |
|
68 | + if (is_wp_error($invoice)) { |
|
69 | 69 | return $wp_error ? $invoice : 0; |
70 | 70 | } |
71 | 71 | |
72 | - if ( empty( $invoice_data['invoice_id'] ) ) { |
|
72 | + if (empty($invoice_data['invoice_id'])) { |
|
73 | 73 | //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) ); |
74 | 74 | } |
75 | 75 | |
@@ -92,24 +92,24 @@ discard block |
||
92 | 92 | 'discount' => array(), |
93 | 93 | ); |
94 | 94 | |
95 | - if ( $user_id = (int)$invoice->get_user_id() ) { |
|
96 | - if ( $user_address = wpinv_get_user_address( $user_id ) ) { |
|
97 | - $default_user_info = wp_parse_args( $user_address, $default_user_info ); |
|
95 | + if ($user_id = (int) $invoice->get_user_id()) { |
|
96 | + if ($user_address = wpinv_get_user_address($user_id)) { |
|
97 | + $default_user_info = wp_parse_args($user_address, $default_user_info); |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
101 | - if ( empty( $invoice_data['user_info'] ) ) { |
|
101 | + if (empty($invoice_data['user_info'])) { |
|
102 | 102 | $invoice_data['user_info'] = array(); |
103 | 103 | } |
104 | 104 | |
105 | - $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info ); |
|
105 | + $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info); |
|
106 | 106 | |
107 | - if ( empty( $user_info['first_name'] ) ) { |
|
107 | + if (empty($user_info['first_name'])) { |
|
108 | 108 | $user_info['first_name'] = $default_user_info['first_name']; |
109 | 109 | $user_info['last_name'] = $default_user_info['last_name']; |
110 | 110 | } |
111 | 111 | |
112 | - if ( empty( $user_info['country'] ) ) { |
|
112 | + if (empty($user_info['country'])) { |
|
113 | 113 | $user_info['country'] = $default_user_info['country']; |
114 | 114 | $user_info['state'] = $default_user_info['state']; |
115 | 115 | $user_info['city'] = $default_user_info['city']; |
@@ -118,13 +118,13 @@ discard block |
||
118 | 118 | $user_info['phone'] = $default_user_info['phone']; |
119 | 119 | } |
120 | 120 | |
121 | - if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) { |
|
122 | - $user_info['discount'] = (array)$user_info['discount']; |
|
121 | + if (!empty($user_info['discount']) && !is_array($user_info['discount'])) { |
|
122 | + $user_info['discount'] = (array) $user_info['discount']; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | // Payment details |
126 | 126 | $payment_details = array(); |
127 | - if ( !empty( $invoice_data['payment_details'] ) ) { |
|
127 | + if (!empty($invoice_data['payment_details'])) { |
|
128 | 128 | $default_payment_details = array( |
129 | 129 | 'gateway' => 'manual', |
130 | 130 | 'gateway_title' => '', |
@@ -132,56 +132,56 @@ discard block |
||
132 | 132 | 'transaction_id' => '', |
133 | 133 | ); |
134 | 134 | |
135 | - $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details ); |
|
135 | + $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details); |
|
136 | 136 | |
137 | - if ( empty( $payment_details['gateway'] ) ) { |
|
137 | + if (empty($payment_details['gateway'])) { |
|
138 | 138 | $payment_details['gateway'] = 'manual'; |
139 | 139 | } |
140 | 140 | |
141 | - if ( empty( $payment_details['currency'] ) ) { |
|
141 | + if (empty($payment_details['currency'])) { |
|
142 | 142 | $payment_details['currency'] = wpinv_get_default_country(); |
143 | 143 | } |
144 | 144 | |
145 | - if ( empty( $payment_details['gateway_title'] ) ) { |
|
146 | - $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] ); |
|
145 | + if (empty($payment_details['gateway_title'])) { |
|
146 | + $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']); |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
150 | - $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) ); |
|
151 | - |
|
152 | - if ( !empty( $payment_details ) ) { |
|
153 | - $invoice->set( 'currency', $payment_details['currency'] ); |
|
154 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
155 | - $invoice->set( 'gateway_title', $payment_details['gateway_title'] ); |
|
156 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
157 | - } |
|
158 | - |
|
159 | - $invoice->set( 'user_info', $user_info ); |
|
160 | - $invoice->set( 'first_name', $user_info['first_name'] ); |
|
161 | - $invoice->set( 'last_name', $user_info['last_name'] ); |
|
162 | - $invoice->set( 'address', $user_info['address'] ); |
|
163 | - $invoice->set( 'company', $user_info['company'] ); |
|
164 | - $invoice->set( 'vat_number', $user_info['vat_number'] ); |
|
165 | - $invoice->set( 'phone', $user_info['phone'] ); |
|
166 | - $invoice->set( 'city', $user_info['city'] ); |
|
167 | - $invoice->set( 'country', $user_info['country'] ); |
|
168 | - $invoice->set( 'state', $user_info['state'] ); |
|
169 | - $invoice->set( 'zip', $user_info['zip'] ); |
|
170 | - $invoice->set( 'discounts', $user_info['discount'] ); |
|
171 | - $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) ); |
|
172 | - $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) ); |
|
173 | - $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) ); |
|
174 | - |
|
175 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) { |
|
176 | - foreach ( $invoice_data['cart_details'] as $key => $item ) { |
|
177 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
178 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
179 | - $name = !empty( $item['name'] ) ? $item['name'] : ''; |
|
180 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : ''; |
|
150 | + $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending')); |
|
151 | + |
|
152 | + if (!empty($payment_details)) { |
|
153 | + $invoice->set('currency', $payment_details['currency']); |
|
154 | + $invoice->set('gateway', $payment_details['gateway']); |
|
155 | + $invoice->set('gateway_title', $payment_details['gateway_title']); |
|
156 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
157 | + } |
|
158 | + |
|
159 | + $invoice->set('user_info', $user_info); |
|
160 | + $invoice->set('first_name', $user_info['first_name']); |
|
161 | + $invoice->set('last_name', $user_info['last_name']); |
|
162 | + $invoice->set('address', $user_info['address']); |
|
163 | + $invoice->set('company', $user_info['company']); |
|
164 | + $invoice->set('vat_number', $user_info['vat_number']); |
|
165 | + $invoice->set('phone', $user_info['phone']); |
|
166 | + $invoice->set('city', $user_info['city']); |
|
167 | + $invoice->set('country', $user_info['country']); |
|
168 | + $invoice->set('state', $user_info['state']); |
|
169 | + $invoice->set('zip', $user_info['zip']); |
|
170 | + $invoice->set('discounts', $user_info['discount']); |
|
171 | + $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip())); |
|
172 | + $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live')); |
|
173 | + $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : '')); |
|
174 | + |
|
175 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) { |
|
176 | + foreach ($invoice_data['cart_details'] as $key => $item) { |
|
177 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
178 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
179 | + $name = !empty($item['name']) ? $item['name'] : ''; |
|
180 | + $item_price = isset($item['item_price']) ? $item['item_price'] : ''; |
|
181 | 181 | |
182 | - $post_item = new WPInv_Item( $item_id ); |
|
183 | - if ( !empty( $post_item ) ) { |
|
184 | - $name = !empty( $name ) ? $name : $post_item->get_name(); |
|
182 | + $post_item = new WPInv_Item($item_id); |
|
183 | + if (!empty($post_item)) { |
|
184 | + $name = !empty($name) ? $name : $post_item->get_name(); |
|
185 | 185 | $item_price = $item_price !== '' ? $item_price : $post_item->get_price(); |
186 | 186 | } else { |
187 | 187 | continue; |
@@ -191,262 +191,262 @@ discard block |
||
191 | 191 | 'name' => $name, |
192 | 192 | 'quantity' => $quantity, |
193 | 193 | 'item_price' => $item_price, |
194 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
195 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0.00, |
|
196 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
197 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
198 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
194 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
195 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0.00, |
|
196 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
197 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
198 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
199 | 199 | ); |
200 | 200 | |
201 | - $invoice->add_item( $item_id, $args ); |
|
201 | + $invoice->add_item($item_id, $args); |
|
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
205 | - $invoice->increase_tax( wpinv_get_cart_fee_tax() ); |
|
205 | + $invoice->increase_tax(wpinv_get_cart_fee_tax()); |
|
206 | 206 | |
207 | - if ( isset( $invoice_data['post_date'] ) ) { |
|
208 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
207 | + if (isset($invoice_data['post_date'])) { |
|
208 | + $invoice->set('date', $invoice_data['post_date']); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | // Invoice due date |
212 | - if ( isset( $invoice_data['due_date'] ) ) { |
|
213 | - $invoice->set( 'due_date', $invoice_data['due_date'] ); |
|
212 | + if (isset($invoice_data['due_date'])) { |
|
213 | + $invoice->set('due_date', $invoice_data['due_date']); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | $invoice->save(); |
217 | 217 | |
218 | 218 | // Add notes |
219 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
220 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
219 | + if (!empty($invoice_data['private_note'])) { |
|
220 | + $invoice->add_note($invoice_data['private_note']); |
|
221 | 221 | } |
222 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
223 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
222 | + if (!empty($invoice_data['user_note'])) { |
|
223 | + $invoice->add_note($invoice_data['user_note'], true); |
|
224 | 224 | } |
225 | 225 | |
226 | - if ( $invoice->is_quote() ) { |
|
226 | + if ($invoice->is_quote()) { |
|
227 | 227 | |
228 | - if ( isset( $invoice_data['valid_until'] ) ) { |
|
229 | - update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] ); |
|
228 | + if (isset($invoice_data['valid_until'])) { |
|
229 | + update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']); |
|
230 | 230 | } |
231 | 231 | return $invoice; |
232 | 232 | |
233 | 233 | } |
234 | 234 | |
235 | - do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data ); |
|
235 | + do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data); |
|
236 | 236 | |
237 | - if ( ! empty( $invoice->ID ) ) { |
|
237 | + if (!empty($invoice->ID)) { |
|
238 | 238 | global $wpi_userID, $wpinv_ip_address_country; |
239 | 239 | |
240 | 240 | $checkout_session = wpinv_get_checkout_session(); |
241 | 241 | |
242 | 242 | $data_session = array(); |
243 | 243 | $data_session['invoice_id'] = $invoice->ID; |
244 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
244 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
245 | 245 | |
246 | - wpinv_set_checkout_session( $data_session ); |
|
246 | + wpinv_set_checkout_session($data_session); |
|
247 | 247 | |
248 | - $wpi_userID = (int)$invoice->get_user_id(); |
|
248 | + $wpi_userID = (int) $invoice->get_user_id(); |
|
249 | 249 | |
250 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
250 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
251 | 251 | $_POST['state'] = $invoice->state; |
252 | 252 | |
253 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
254 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
253 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
254 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
255 | 255 | |
256 | 256 | $wpinv_ip_address_country = $invoice->country; |
257 | 257 | |
258 | - $invoice = $invoice->recalculate_totals( true ); |
|
258 | + $invoice = $invoice->recalculate_totals(true); |
|
259 | 259 | |
260 | - wpinv_set_checkout_session( $checkout_session ); |
|
260 | + wpinv_set_checkout_session($checkout_session); |
|
261 | 261 | |
262 | 262 | return $invoice; |
263 | 263 | } |
264 | 264 | |
265 | - if ( $wp_error ) { |
|
266 | - if ( is_wp_error( $invoice ) ) { |
|
265 | + if ($wp_error) { |
|
266 | + if (is_wp_error($invoice)) { |
|
267 | 267 | return $invoice; |
268 | 268 | } else { |
269 | - return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) ); |
|
269 | + return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing')); |
|
270 | 270 | } |
271 | 271 | } else { |
272 | 272 | return 0; |
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
276 | -function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) { |
|
277 | - $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL; |
|
276 | +function wpinv_update_invoice($invoice_data = array(), $wp_error = false) { |
|
277 | + $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL; |
|
278 | 278 | |
279 | - if ( !$invoice_ID ) { |
|
280 | - if ( $wp_error ) { |
|
281 | - return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ); |
|
279 | + if (!$invoice_ID) { |
|
280 | + if ($wp_error) { |
|
281 | + return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')); |
|
282 | 282 | } |
283 | 283 | return 0; |
284 | 284 | } |
285 | 285 | |
286 | - $invoice = wpinv_get_invoice( $invoice_ID ); |
|
286 | + $invoice = wpinv_get_invoice($invoice_ID); |
|
287 | 287 | |
288 | - $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL; |
|
288 | + $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL; |
|
289 | 289 | |
290 | - if ( empty( $invoice->ID ) ) { |
|
291 | - if ( $wp_error ) { |
|
292 | - return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) ); |
|
290 | + if (empty($invoice->ID)) { |
|
291 | + if ($wp_error) { |
|
292 | + return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing')); |
|
293 | 293 | } |
294 | 294 | return 0; |
295 | 295 | } |
296 | 296 | |
297 | - if ( ! $invoice->has_status( array( 'wpi-pending' ) ) && ! $invoice->is_quote() ) { |
|
298 | - if ( $wp_error ) { |
|
299 | - return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) ); |
|
297 | + if (!$invoice->has_status(array('wpi-pending')) && !$invoice->is_quote()) { |
|
298 | + if ($wp_error) { |
|
299 | + return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing')); |
|
300 | 300 | } |
301 | 301 | return 0; |
302 | 302 | } |
303 | 303 | |
304 | 304 | // Invoice status |
305 | - if ( !empty( $invoice_data['status'] ) ) { |
|
306 | - $invoice->set( 'status', $invoice_data['status'] ); |
|
305 | + if (!empty($invoice_data['status'])) { |
|
306 | + $invoice->set('status', $invoice_data['status']); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | // Invoice date |
310 | - if ( !empty( $invoice_data['post_date'] ) ) { |
|
311 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
310 | + if (!empty($invoice_data['post_date'])) { |
|
311 | + $invoice->set('date', $invoice_data['post_date']); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | // Invoice due date |
315 | - if ( isset( $invoice_data['due_date'] ) ) { |
|
316 | - $invoice->set( 'due_date', $invoice_data['due_date'] ); |
|
315 | + if (isset($invoice_data['due_date'])) { |
|
316 | + $invoice->set('due_date', $invoice_data['due_date']); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | // Invoice IP address |
320 | - if ( !empty( $invoice_data['ip'] ) ) { |
|
321 | - $invoice->set( 'ip', $invoice_data['ip'] ); |
|
320 | + if (!empty($invoice_data['ip'])) { |
|
321 | + $invoice->set('ip', $invoice_data['ip']); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | // User info |
325 | - if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) { |
|
326 | - $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info ); |
|
325 | + if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) { |
|
326 | + $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info); |
|
327 | 327 | |
328 | - if ( $discounts = $invoice->get_discounts() ) { |
|
328 | + if ($discounts = $invoice->get_discounts()) { |
|
329 | 329 | $set_discount = $discounts; |
330 | 330 | } else { |
331 | 331 | $set_discount = ''; |
332 | 332 | } |
333 | 333 | |
334 | 334 | // Manage discount |
335 | - if ( !empty( $invoice_data['user_info']['discount'] ) ) { |
|
335 | + if (!empty($invoice_data['user_info']['discount'])) { |
|
336 | 336 | // Remove discount |
337 | - if ( $invoice_data['user_info']['discount'] == 'none' ) { |
|
337 | + if ($invoice_data['user_info']['discount'] == 'none') { |
|
338 | 338 | $set_discount = ''; |
339 | 339 | } else { |
340 | 340 | $set_discount = $invoice_data['user_info']['discount']; |
341 | 341 | } |
342 | 342 | |
343 | - $invoice->set( 'discounts', $set_discount ); |
|
343 | + $invoice->set('discounts', $set_discount); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | $user_info['discount'] = $set_discount; |
347 | 347 | |
348 | - $invoice->set( 'user_info', $user_info ); |
|
348 | + $invoice->set('user_info', $user_info); |
|
349 | 349 | } |
350 | 350 | |
351 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) { |
|
352 | - $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array(); |
|
351 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) { |
|
352 | + $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array(); |
|
353 | 353 | |
354 | - if ( !empty( $remove_items[0]['id'] ) ) { |
|
355 | - foreach ( $remove_items as $item ) { |
|
356 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
357 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
358 | - if ( empty( $item_id ) ) { |
|
354 | + if (!empty($remove_items[0]['id'])) { |
|
355 | + foreach ($remove_items as $item) { |
|
356 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
357 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
358 | + if (empty($item_id)) { |
|
359 | 359 | continue; |
360 | 360 | } |
361 | 361 | |
362 | - foreach ( $invoice->cart_details as $cart_index => $cart_item ) { |
|
363 | - if ( $item_id == $cart_item['id'] ) { |
|
362 | + foreach ($invoice->cart_details as $cart_index => $cart_item) { |
|
363 | + if ($item_id == $cart_item['id']) { |
|
364 | 364 | $args = array( |
365 | 365 | 'id' => $item_id, |
366 | 366 | 'quantity' => $quantity, |
367 | 367 | 'cart_index' => $cart_index |
368 | 368 | ); |
369 | 369 | |
370 | - $invoice->remove_item( $item_id, $args ); |
|
370 | + $invoice->remove_item($item_id, $args); |
|
371 | 371 | break; |
372 | 372 | } |
373 | 373 | } |
374 | 374 | } |
375 | 375 | } |
376 | 376 | |
377 | - $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array(); |
|
377 | + $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array(); |
|
378 | 378 | |
379 | - if ( !empty( $add_items[0]['id'] ) ) { |
|
380 | - foreach ( $add_items as $item ) { |
|
381 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
382 | - $post_item = new WPInv_Item( $item_id ); |
|
383 | - if ( empty( $post_item ) ) { |
|
379 | + if (!empty($add_items[0]['id'])) { |
|
380 | + foreach ($add_items as $item) { |
|
381 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
382 | + $post_item = new WPInv_Item($item_id); |
|
383 | + if (empty($post_item)) { |
|
384 | 384 | continue; |
385 | 385 | } |
386 | 386 | |
387 | 387 | $valid_item = true; |
388 | - if ( !empty( $recurring_item ) ) { |
|
389 | - if ( $recurring_item->ID != $item_id ) { |
|
388 | + if (!empty($recurring_item)) { |
|
389 | + if ($recurring_item->ID != $item_id) { |
|
390 | 390 | $valid_item = false; |
391 | 391 | } |
392 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
392 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
393 | 393 | $valid_item = false; |
394 | 394 | } |
395 | 395 | |
396 | - if ( !$valid_item ) { |
|
397 | - if ( $wp_error ) { |
|
398 | - return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) ); |
|
396 | + if (!$valid_item) { |
|
397 | + if ($wp_error) { |
|
398 | + return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing')); |
|
399 | 399 | } |
400 | 400 | return 0; |
401 | 401 | } |
402 | 402 | |
403 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
404 | - $name = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name(); |
|
405 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price(); |
|
403 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
404 | + $name = !empty($item['name']) ? $item['name'] : $post_item->get_name(); |
|
405 | + $item_price = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price(); |
|
406 | 406 | |
407 | 407 | $args = array( |
408 | 408 | 'name' => $name, |
409 | 409 | 'quantity' => $quantity, |
410 | 410 | 'item_price' => $item_price, |
411 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
412 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0, |
|
413 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
414 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
415 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
411 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
412 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0, |
|
413 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
414 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
415 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
416 | 416 | ); |
417 | 417 | |
418 | - $invoice->add_item( $item_id, $args ); |
|
418 | + $invoice->add_item($item_id, $args); |
|
419 | 419 | } |
420 | 420 | } |
421 | 421 | } |
422 | 422 | |
423 | 423 | // Payment details |
424 | - if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) { |
|
425 | - if ( !empty( $payment_details['gateway'] ) ) { |
|
426 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
424 | + if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) { |
|
425 | + if (!empty($payment_details['gateway'])) { |
|
426 | + $invoice->set('gateway', $payment_details['gateway']); |
|
427 | 427 | } |
428 | 428 | |
429 | - if ( !empty( $payment_details['transaction_id'] ) ) { |
|
430 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
429 | + if (!empty($payment_details['transaction_id'])) { |
|
430 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
431 | 431 | } |
432 | 432 | } |
433 | 433 | |
434 | - do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data ); |
|
434 | + do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data); |
|
435 | 435 | |
436 | 436 | // Parent invoice |
437 | - if ( !empty( $invoice_data['parent'] ) ) { |
|
438 | - $invoice->set( 'parent_invoice', $invoice_data['parent'] ); |
|
437 | + if (!empty($invoice_data['parent'])) { |
|
438 | + $invoice->set('parent_invoice', $invoice_data['parent']); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | // Save invoice data. |
442 | 442 | $invoice->save(); |
443 | 443 | |
444 | - if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) { |
|
445 | - if ( $wp_error ) { |
|
446 | - if ( is_wp_error( $invoice ) ) { |
|
444 | + if (empty($invoice->ID) || is_wp_error($invoice)) { |
|
445 | + if ($wp_error) { |
|
446 | + if (is_wp_error($invoice)) { |
|
447 | 447 | return $invoice; |
448 | 448 | } else { |
449 | - return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) ); |
|
449 | + return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing')); |
|
450 | 450 | } |
451 | 451 | } else { |
452 | 452 | return 0; |
@@ -454,19 +454,19 @@ discard block |
||
454 | 454 | } |
455 | 455 | |
456 | 456 | // Add private note |
457 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
458 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
457 | + if (!empty($invoice_data['private_note'])) { |
|
458 | + $invoice->add_note($invoice_data['private_note']); |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | // Add user note |
462 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
463 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
462 | + if (!empty($invoice_data['user_note'])) { |
|
463 | + $invoice->add_note($invoice_data['user_note'], true); |
|
464 | 464 | } |
465 | 465 | |
466 | - if ( $invoice->is_quote() ) { |
|
466 | + if ($invoice->is_quote()) { |
|
467 | 467 | |
468 | - if ( isset( $invoice_data['valid_until'] ) ) { |
|
469 | - update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] ); |
|
468 | + if (isset($invoice_data['valid_until'])) { |
|
469 | + update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']); |
|
470 | 470 | } |
471 | 471 | return $invoice; |
472 | 472 | |
@@ -478,466 +478,466 @@ discard block |
||
478 | 478 | |
479 | 479 | $data_session = array(); |
480 | 480 | $data_session['invoice_id'] = $invoice->ID; |
481 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
481 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
482 | 482 | |
483 | - wpinv_set_checkout_session( $data_session ); |
|
483 | + wpinv_set_checkout_session($data_session); |
|
484 | 484 | |
485 | - $wpi_userID = (int)$invoice->get_user_id(); |
|
485 | + $wpi_userID = (int) $invoice->get_user_id(); |
|
486 | 486 | |
487 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
487 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
488 | 488 | $_POST['state'] = $invoice->state; |
489 | 489 | |
490 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
491 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
490 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
491 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
492 | 492 | |
493 | 493 | $wpinv_ip_address_country = $invoice->country; |
494 | 494 | |
495 | - $invoice = $invoice->recalculate_totals( true ); |
|
495 | + $invoice = $invoice->recalculate_totals(true); |
|
496 | 496 | |
497 | - do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data ); |
|
497 | + do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data); |
|
498 | 498 | |
499 | - wpinv_set_checkout_session( $checkout_session ); |
|
499 | + wpinv_set_checkout_session($checkout_session); |
|
500 | 500 | |
501 | 501 | return $invoice; |
502 | 502 | } |
503 | 503 | |
504 | -function wpinv_get_invoice( $invoice_id = 0, $cart = false ) { |
|
505 | - if ( $cart && empty( $invoice_id ) ) { |
|
506 | - $invoice_id = (int)wpinv_get_invoice_cart_id(); |
|
504 | +function wpinv_get_invoice($invoice_id = 0, $cart = false) { |
|
505 | + if ($cart && empty($invoice_id)) { |
|
506 | + $invoice_id = (int) wpinv_get_invoice_cart_id(); |
|
507 | 507 | } |
508 | 508 | |
509 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
509 | + $invoice = new WPInv_Invoice($invoice_id); |
|
510 | 510 | |
511 | - if ( ! empty( $invoice ) && ! empty( $invoice->ID ) ) { |
|
511 | + if (!empty($invoice) && !empty($invoice->ID)) { |
|
512 | 512 | return $invoice; |
513 | 513 | } |
514 | 514 | |
515 | 515 | return NULL; |
516 | 516 | } |
517 | 517 | |
518 | -function wpinv_get_invoice_cart( $invoice_id = 0 ) { |
|
519 | - return wpinv_get_invoice( $invoice_id, true ); |
|
518 | +function wpinv_get_invoice_cart($invoice_id = 0) { |
|
519 | + return wpinv_get_invoice($invoice_id, true); |
|
520 | 520 | } |
521 | 521 | |
522 | -function wpinv_get_invoice_description( $invoice_id = 0 ) { |
|
523 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
522 | +function wpinv_get_invoice_description($invoice_id = 0) { |
|
523 | + $invoice = new WPInv_Invoice($invoice_id); |
|
524 | 524 | return $invoice->get_description(); |
525 | 525 | } |
526 | 526 | |
527 | -function wpinv_get_invoice_currency_code( $invoice_id = 0 ) { |
|
528 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
527 | +function wpinv_get_invoice_currency_code($invoice_id = 0) { |
|
528 | + $invoice = new WPInv_Invoice($invoice_id); |
|
529 | 529 | return $invoice->get_currency(); |
530 | 530 | } |
531 | 531 | |
532 | -function wpinv_get_payment_user_email( $invoice_id ) { |
|
533 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
532 | +function wpinv_get_payment_user_email($invoice_id) { |
|
533 | + $invoice = new WPInv_Invoice($invoice_id); |
|
534 | 534 | return $invoice->get_email(); |
535 | 535 | } |
536 | 536 | |
537 | -function wpinv_get_user_id( $invoice_id ) { |
|
538 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
537 | +function wpinv_get_user_id($invoice_id) { |
|
538 | + $invoice = new WPInv_Invoice($invoice_id); |
|
539 | 539 | return $invoice->get_user_id(); |
540 | 540 | } |
541 | 541 | |
542 | -function wpinv_get_invoice_status( $invoice_id, $return_label = false ) { |
|
543 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
542 | +function wpinv_get_invoice_status($invoice_id, $return_label = false) { |
|
543 | + $invoice = new WPInv_Invoice($invoice_id); |
|
544 | 544 | |
545 | - return $invoice->get_status( $return_label ); |
|
545 | + return $invoice->get_status($return_label); |
|
546 | 546 | } |
547 | 547 | |
548 | -function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) { |
|
549 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
548 | +function wpinv_get_payment_gateway($invoice_id, $return_label = false) { |
|
549 | + $invoice = new WPInv_Invoice($invoice_id); |
|
550 | 550 | |
551 | - return $invoice->get_gateway( $return_label ); |
|
551 | + return $invoice->get_gateway($return_label); |
|
552 | 552 | } |
553 | 553 | |
554 | -function wpinv_get_payment_gateway_name( $invoice_id ) { |
|
555 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
554 | +function wpinv_get_payment_gateway_name($invoice_id) { |
|
555 | + $invoice = new WPInv_Invoice($invoice_id); |
|
556 | 556 | |
557 | 557 | return $invoice->get_gateway_title(); |
558 | 558 | } |
559 | 559 | |
560 | -function wpinv_get_payment_transaction_id( $invoice_id ) { |
|
561 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
560 | +function wpinv_get_payment_transaction_id($invoice_id) { |
|
561 | + $invoice = new WPInv_Invoice($invoice_id); |
|
562 | 562 | |
563 | 563 | return $invoice->get_transaction_id(); |
564 | 564 | } |
565 | 565 | |
566 | -function wpinv_get_id_by_transaction_id( $key ) { |
|
566 | +function wpinv_get_id_by_transaction_id($key) { |
|
567 | 567 | global $wpdb; |
568 | 568 | |
569 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) ); |
|
569 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key)); |
|
570 | 570 | |
571 | - if ( $invoice_id != NULL ) |
|
571 | + if ($invoice_id != NULL) |
|
572 | 572 | return $invoice_id; |
573 | 573 | |
574 | 574 | return 0; |
575 | 575 | } |
576 | 576 | |
577 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
578 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
577 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
578 | + $invoice = new WPInv_Invoice($invoice_id); |
|
579 | 579 | |
580 | - return $invoice->get_meta( $meta_key, $single ); |
|
580 | + return $invoice->get_meta($meta_key, $single); |
|
581 | 581 | } |
582 | 582 | |
583 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
584 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
583 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') { |
|
584 | + $invoice = new WPInv_Invoice($invoice_id); |
|
585 | 585 | |
586 | - return $invoice->update_meta( $meta_key, $meta_value, $prev_value ); |
|
586 | + return $invoice->update_meta($meta_key, $meta_value, $prev_value); |
|
587 | 587 | } |
588 | 588 | |
589 | -function wpinv_get_items( $invoice_id = 0 ) { |
|
590 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
589 | +function wpinv_get_items($invoice_id = 0) { |
|
590 | + $invoice = wpinv_get_invoice($invoice_id); |
|
591 | 591 | |
592 | 592 | $items = $invoice->get_items(); |
593 | 593 | $invoice_currency = $invoice->get_currency(); |
594 | 594 | |
595 | - if ( !empty( $items ) && is_array( $items ) ) { |
|
596 | - foreach ( $items as $key => $item ) { |
|
595 | + if (!empty($items) && is_array($items)) { |
|
596 | + foreach ($items as $key => $item) { |
|
597 | 597 | $items[$key]['currency'] = $invoice_currency; |
598 | 598 | |
599 | - if ( !isset( $item['subtotal'] ) ) { |
|
599 | + if (!isset($item['subtotal'])) { |
|
600 | 600 | $items[$key]['subtotal'] = $items[$key]['amount'] * 1; |
601 | 601 | } |
602 | 602 | } |
603 | 603 | } |
604 | 604 | |
605 | - return apply_filters( 'wpinv_get_items', $items, $invoice_id ); |
|
605 | + return apply_filters('wpinv_get_items', $items, $invoice_id); |
|
606 | 606 | } |
607 | 607 | |
608 | -function wpinv_get_fees( $invoice_id = 0 ) { |
|
609 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
608 | +function wpinv_get_fees($invoice_id = 0) { |
|
609 | + $invoice = wpinv_get_invoice($invoice_id); |
|
610 | 610 | $fees = $invoice->get_fees(); |
611 | 611 | |
612 | - return apply_filters( 'wpinv_get_fees', $fees, $invoice_id ); |
|
612 | + return apply_filters('wpinv_get_fees', $fees, $invoice_id); |
|
613 | 613 | } |
614 | 614 | |
615 | -function wpinv_get_invoice_ip( $invoice_id ) { |
|
616 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
615 | +function wpinv_get_invoice_ip($invoice_id) { |
|
616 | + $invoice = new WPInv_Invoice($invoice_id); |
|
617 | 617 | return $invoice->get_ip(); |
618 | 618 | } |
619 | 619 | |
620 | -function wpinv_get_invoice_user_info( $invoice_id ) { |
|
621 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
620 | +function wpinv_get_invoice_user_info($invoice_id) { |
|
621 | + $invoice = new WPInv_Invoice($invoice_id); |
|
622 | 622 | return $invoice->get_user_info(); |
623 | 623 | } |
624 | 624 | |
625 | -function wpinv_subtotal( $invoice_id = 0, $currency = false ) { |
|
626 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
625 | +function wpinv_subtotal($invoice_id = 0, $currency = false) { |
|
626 | + $invoice = new WPInv_Invoice($invoice_id); |
|
627 | 627 | |
628 | - return $invoice->get_subtotal( $currency ); |
|
628 | + return $invoice->get_subtotal($currency); |
|
629 | 629 | } |
630 | 630 | |
631 | -function wpinv_tax( $invoice_id = 0, $currency = false ) { |
|
632 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
631 | +function wpinv_tax($invoice_id = 0, $currency = false) { |
|
632 | + $invoice = new WPInv_Invoice($invoice_id); |
|
633 | 633 | |
634 | - return $invoice->get_tax( $currency ); |
|
634 | + return $invoice->get_tax($currency); |
|
635 | 635 | } |
636 | 636 | |
637 | -function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) { |
|
638 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
637 | +function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) { |
|
638 | + $invoice = wpinv_get_invoice($invoice_id); |
|
639 | 639 | |
640 | - return $invoice->get_discount( $currency, $dash ); |
|
640 | + return $invoice->get_discount($currency, $dash); |
|
641 | 641 | } |
642 | 642 | |
643 | -function wpinv_discount_code( $invoice_id = 0 ) { |
|
644 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
643 | +function wpinv_discount_code($invoice_id = 0) { |
|
644 | + $invoice = new WPInv_Invoice($invoice_id); |
|
645 | 645 | |
646 | 646 | return $invoice->get_discount_code(); |
647 | 647 | } |
648 | 648 | |
649 | -function wpinv_payment_total( $invoice_id = 0, $currency = false ) { |
|
650 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
649 | +function wpinv_payment_total($invoice_id = 0, $currency = false) { |
|
650 | + $invoice = new WPInv_Invoice($invoice_id); |
|
651 | 651 | |
652 | - return $invoice->get_total( $currency ); |
|
652 | + return $invoice->get_total($currency); |
|
653 | 653 | } |
654 | 654 | |
655 | -function wpinv_get_date_created( $invoice_id = 0, $format = '' ) { |
|
656 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
655 | +function wpinv_get_date_created($invoice_id = 0, $format = '') { |
|
656 | + $invoice = new WPInv_Invoice($invoice_id); |
|
657 | 657 | |
658 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
658 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
659 | 659 | $date_created = $invoice->get_created_date(); |
660 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
660 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : ''; |
|
661 | 661 | |
662 | 662 | return $date_created; |
663 | 663 | } |
664 | 664 | |
665 | -function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) { |
|
666 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
665 | +function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) { |
|
666 | + $invoice = new WPInv_Invoice($invoice_id); |
|
667 | 667 | |
668 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
668 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
669 | 669 | $date_completed = $invoice->get_completed_date(); |
670 | - $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : ''; |
|
671 | - if ( $invoice_date == '' && $default ) { |
|
672 | - $invoice_date = wpinv_get_date_created( $invoice_id, $format ); |
|
670 | + $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : ''; |
|
671 | + if ($invoice_date == '' && $default) { |
|
672 | + $invoice_date = wpinv_get_date_created($invoice_id, $format); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | return $invoice_date; |
676 | 676 | } |
677 | 677 | |
678 | -function wpinv_get_invoice_vat_number( $invoice_id = 0 ) { |
|
679 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
678 | +function wpinv_get_invoice_vat_number($invoice_id = 0) { |
|
679 | + $invoice = new WPInv_Invoice($invoice_id); |
|
680 | 680 | |
681 | 681 | return $invoice->vat_number; |
682 | 682 | } |
683 | 683 | |
684 | -function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) { |
|
685 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
684 | +function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) { |
|
685 | + $invoice = new WPInv_Invoice($invoice_id); |
|
686 | 686 | |
687 | - return $invoice->add_note( $note, $user_type, $added_by_user, $system ); |
|
687 | + return $invoice->add_note($note, $user_type, $added_by_user, $system); |
|
688 | 688 | } |
689 | 689 | |
690 | -function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
690 | +function wpinv_get_invoice_notes($invoice_id = 0, $type = '') { |
|
691 | 691 | global $invoicing; |
692 | 692 | |
693 | - if ( empty( $invoice_id ) ) { |
|
693 | + if (empty($invoice_id)) { |
|
694 | 694 | return NULL; |
695 | 695 | } |
696 | 696 | |
697 | - $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type ); |
|
697 | + $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type); |
|
698 | 698 | |
699 | - return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type ); |
|
699 | + return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type); |
|
700 | 700 | } |
701 | 701 | |
702 | -function wpinv_get_payment_key( $invoice_id = 0 ) { |
|
703 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
702 | +function wpinv_get_payment_key($invoice_id = 0) { |
|
703 | + $invoice = new WPInv_Invoice($invoice_id); |
|
704 | 704 | return $invoice->get_key(); |
705 | 705 | } |
706 | 706 | |
707 | -function wpinv_get_invoice_number( $invoice_id = 0 ) { |
|
708 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
707 | +function wpinv_get_invoice_number($invoice_id = 0) { |
|
708 | + $invoice = new WPInv_Invoice($invoice_id); |
|
709 | 709 | return $invoice->get_number(); |
710 | 710 | } |
711 | 711 | |
712 | -function wpinv_get_cart_discountable_subtotal( $code_id ) { |
|
712 | +function wpinv_get_cart_discountable_subtotal($code_id) { |
|
713 | 713 | $cart_items = wpinv_get_cart_content_details(); |
714 | 714 | $items = array(); |
715 | 715 | |
716 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
716 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
717 | 717 | |
718 | - if( $cart_items ) { |
|
718 | + if ($cart_items) { |
|
719 | 719 | |
720 | - foreach( $cart_items as $item ) { |
|
720 | + foreach ($cart_items as $item) { |
|
721 | 721 | |
722 | - if( ! in_array( $item['id'], $excluded_items ) ) { |
|
723 | - $items[] = $item; |
|
722 | + if (!in_array($item['id'], $excluded_items)) { |
|
723 | + $items[] = $item; |
|
724 | 724 | } |
725 | 725 | } |
726 | 726 | } |
727 | 727 | |
728 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
728 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
729 | 729 | |
730 | - return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal ); |
|
730 | + return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal); |
|
731 | 731 | } |
732 | 732 | |
733 | -function wpinv_get_cart_items_subtotal( $items ) { |
|
733 | +function wpinv_get_cart_items_subtotal($items) { |
|
734 | 734 | $subtotal = 0.00; |
735 | 735 | |
736 | - if ( is_array( $items ) && ! empty( $items ) ) { |
|
737 | - $prices = wp_list_pluck( $items, 'subtotal' ); |
|
736 | + if (is_array($items) && !empty($items)) { |
|
737 | + $prices = wp_list_pluck($items, 'subtotal'); |
|
738 | 738 | |
739 | - if( is_array( $prices ) ) { |
|
740 | - $subtotal = array_sum( $prices ); |
|
739 | + if (is_array($prices)) { |
|
740 | + $subtotal = array_sum($prices); |
|
741 | 741 | } else { |
742 | 742 | $subtotal = 0.00; |
743 | 743 | } |
744 | 744 | |
745 | - if( $subtotal < 0 ) { |
|
745 | + if ($subtotal < 0) { |
|
746 | 746 | $subtotal = 0.00; |
747 | 747 | } |
748 | 748 | } |
749 | 749 | |
750 | - return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal ); |
|
750 | + return apply_filters('wpinv_get_cart_items_subtotal', $subtotal); |
|
751 | 751 | } |
752 | 752 | |
753 | -function wpinv_get_cart_subtotal( $items = array() ) { |
|
754 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
755 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
753 | +function wpinv_get_cart_subtotal($items = array()) { |
|
754 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
755 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
756 | 756 | |
757 | - return apply_filters( 'wpinv_get_cart_subtotal', $subtotal ); |
|
757 | + return apply_filters('wpinv_get_cart_subtotal', $subtotal); |
|
758 | 758 | } |
759 | 759 | |
760 | -function wpinv_cart_subtotal( $items = array(), $currency = '' ) { |
|
760 | +function wpinv_cart_subtotal($items = array(), $currency = '') { |
|
761 | 761 | |
762 | - if( empty( $currency ) ) { |
|
762 | + if (empty($currency)) { |
|
763 | 763 | $currency = wpinv_get_currency(); |
764 | 764 | } |
765 | 765 | |
766 | - $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ), $currency ); |
|
766 | + $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)), $currency); |
|
767 | 767 | |
768 | 768 | return $price; |
769 | 769 | } |
770 | 770 | |
771 | -function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) { |
|
772 | - $subtotal = (float)wpinv_get_cart_subtotal( $items ); |
|
773 | - $discounts = (float)wpinv_get_cart_discounted_amount( $items ); |
|
774 | - $cart_tax = (float)wpinv_get_cart_tax( $items, $invoice ); |
|
775 | - $fees = (float)wpinv_get_cart_fee_total(); |
|
776 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
771 | +function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) { |
|
772 | + $subtotal = (float) wpinv_get_cart_subtotal($items); |
|
773 | + $discounts = (float) wpinv_get_cart_discounted_amount($items); |
|
774 | + $cart_tax = (float) wpinv_get_cart_tax($items, $invoice); |
|
775 | + $fees = (float) wpinv_get_cart_fee_total(); |
|
776 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
777 | 777 | $total = 0; |
778 | 778 | } else { |
779 | - $total = $subtotal - $discounts + $cart_tax + $fees; |
|
779 | + $total = $subtotal - $discounts + $cart_tax + $fees; |
|
780 | 780 | } |
781 | 781 | |
782 | - if ( $total < 0 ) { |
|
782 | + if ($total < 0) { |
|
783 | 783 | $total = 0.00; |
784 | 784 | } |
785 | 785 | |
786 | - $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items ); |
|
786 | + $total = (float) apply_filters('wpinv_get_cart_total', $total, $items); |
|
787 | 787 | |
788 | - return wpinv_sanitize_amount( $total ); |
|
788 | + return wpinv_sanitize_amount($total); |
|
789 | 789 | } |
790 | 790 | |
791 | -function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) { |
|
791 | +function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) { |
|
792 | 792 | global $cart_total; |
793 | - $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ), $invoice->get_currency() ); |
|
794 | - $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice ); |
|
793 | + $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)), $invoice->get_currency()); |
|
794 | + $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice); |
|
795 | 795 | |
796 | 796 | $cart_total = $total; |
797 | 797 | |
798 | - if ( !$echo ) { |
|
798 | + if (!$echo) { |
|
799 | 799 | return $total; |
800 | 800 | } |
801 | 801 | |
802 | 802 | echo $total; |
803 | 803 | } |
804 | 804 | |
805 | -function wpinv_get_cart_tax( $items = array(), $invoice = 0 ) { |
|
805 | +function wpinv_get_cart_tax($items = array(), $invoice = 0) { |
|
806 | 806 | |
807 | - if ( ! empty( $invoice ) && ! $invoice->is_taxable() ) { |
|
807 | + if (!empty($invoice) && !$invoice->is_taxable()) { |
|
808 | 808 | return 0; |
809 | 809 | } |
810 | 810 | |
811 | 811 | $cart_tax = 0; |
812 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
812 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
813 | 813 | |
814 | - if ( $items ) { |
|
815 | - $taxes = wp_list_pluck( $items, 'tax' ); |
|
814 | + if ($items) { |
|
815 | + $taxes = wp_list_pluck($items, 'tax'); |
|
816 | 816 | |
817 | - if( is_array( $taxes ) ) { |
|
818 | - $cart_tax = array_sum( $taxes ); |
|
817 | + if (is_array($taxes)) { |
|
818 | + $cart_tax = array_sum($taxes); |
|
819 | 819 | } |
820 | 820 | } |
821 | 821 | |
822 | 822 | $cart_tax += wpinv_get_cart_fee_tax(); |
823 | 823 | |
824 | - return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) ); |
|
824 | + return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax)); |
|
825 | 825 | } |
826 | 826 | |
827 | -function wpinv_cart_tax( $items = array(), $echo = false, $currency = '', $invoice = 0 ) { |
|
827 | +function wpinv_cart_tax($items = array(), $echo = false, $currency = '', $invoice = 0) { |
|
828 | 828 | |
829 | - if ( ! empty( $invoice && ! $invoice->is_taxable() ) ) { |
|
830 | - echo wpinv_price( wpinv_format_amount( 0 ), $currency ); |
|
829 | + if (!empty($invoice && !$invoice->is_taxable())) { |
|
830 | + echo wpinv_price(wpinv_format_amount(0), $currency); |
|
831 | 831 | return; |
832 | 832 | } |
833 | 833 | |
834 | - $cart_tax = wpinv_get_cart_tax( $items, $invoice ); |
|
835 | - $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ), $currency ); |
|
834 | + $cart_tax = wpinv_get_cart_tax($items, $invoice); |
|
835 | + $cart_tax = wpinv_price(wpinv_format_amount($cart_tax), $currency); |
|
836 | 836 | |
837 | - $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items ); |
|
837 | + $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items); |
|
838 | 838 | |
839 | - if ( !$echo ) { |
|
839 | + if (!$echo) { |
|
840 | 840 | return $tax; |
841 | 841 | } |
842 | 842 | |
843 | 843 | echo $tax; |
844 | 844 | } |
845 | 845 | |
846 | -function wpinv_get_cart_discount_code( $items = array() ) { |
|
846 | +function wpinv_get_cart_discount_code($items = array()) { |
|
847 | 847 | $invoice = wpinv_get_invoice_cart(); |
848 | - $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : ''; |
|
848 | + $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : ''; |
|
849 | 849 | |
850 | - return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code ); |
|
850 | + return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code); |
|
851 | 851 | } |
852 | 852 | |
853 | -function wpinv_cart_discount_code( $items = array(), $echo = false ) { |
|
854 | - $cart_discount_code = wpinv_get_cart_discount_code( $items ); |
|
853 | +function wpinv_cart_discount_code($items = array(), $echo = false) { |
|
854 | + $cart_discount_code = wpinv_get_cart_discount_code($items); |
|
855 | 855 | |
856 | - if ( $cart_discount_code != '' ) { |
|
856 | + if ($cart_discount_code != '') { |
|
857 | 857 | $cart_discount_code = ' (' . $cart_discount_code . ')'; |
858 | 858 | } |
859 | 859 | |
860 | - $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items ); |
|
860 | + $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items); |
|
861 | 861 | |
862 | - if ( !$echo ) { |
|
862 | + if (!$echo) { |
|
863 | 863 | return $discount_code; |
864 | 864 | } |
865 | 865 | |
866 | 866 | echo $discount_code; |
867 | 867 | } |
868 | 868 | |
869 | -function wpinv_get_cart_discount( $items = array() ) { |
|
869 | +function wpinv_get_cart_discount($items = array()) { |
|
870 | 870 | $invoice = wpinv_get_invoice_cart(); |
871 | - $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0; |
|
871 | + $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0; |
|
872 | 872 | |
873 | - return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items ); |
|
873 | + return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items); |
|
874 | 874 | } |
875 | 875 | |
876 | -function wpinv_cart_discount( $items = array(), $echo = false ) { |
|
877 | - $cart_discount = wpinv_get_cart_discount( $items ); |
|
878 | - $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) ); |
|
876 | +function wpinv_cart_discount($items = array(), $echo = false) { |
|
877 | + $cart_discount = wpinv_get_cart_discount($items); |
|
878 | + $cart_discount = wpinv_price(wpinv_format_amount($cart_discount)); |
|
879 | 879 | |
880 | - $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items ); |
|
880 | + $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items); |
|
881 | 881 | |
882 | - if ( !$echo ) { |
|
882 | + if (!$echo) { |
|
883 | 883 | return $discount; |
884 | 884 | } |
885 | 885 | |
886 | 886 | echo $discount; |
887 | 887 | } |
888 | 888 | |
889 | -function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) { |
|
890 | - $item = new WPInv_Item( $item_id ); |
|
889 | +function wpinv_get_cart_fees($type = 'all', $item_id = 0) { |
|
890 | + $item = new WPInv_Item($item_id); |
|
891 | 891 | |
892 | - return $item->get_fees( $type, $item_id ); |
|
892 | + return $item->get_fees($type, $item_id); |
|
893 | 893 | } |
894 | 894 | |
895 | 895 | function wpinv_get_cart_fee_total() { |
896 | - $total = 0; |
|
896 | + $total = 0; |
|
897 | 897 | $fees = wpinv_get_cart_fees(); |
898 | 898 | |
899 | - if ( $fees ) { |
|
900 | - foreach ( $fees as $fee_id => $fee ) { |
|
899 | + if ($fees) { |
|
900 | + foreach ($fees as $fee_id => $fee) { |
|
901 | 901 | $total += $fee['amount']; |
902 | 902 | } |
903 | 903 | } |
904 | 904 | |
905 | - return apply_filters( 'wpinv_get_cart_fee_total', $total ); |
|
905 | + return apply_filters('wpinv_get_cart_fee_total', $total); |
|
906 | 906 | } |
907 | 907 | |
908 | 908 | function wpinv_get_cart_fee_tax() { |
909 | 909 | $tax = 0; |
910 | 910 | $fees = wpinv_get_cart_fees(); |
911 | 911 | |
912 | - if ( $fees ) { |
|
913 | - foreach ( $fees as $fee_id => $fee ) { |
|
914 | - if( ! empty( $fee['no_tax'] ) ) { |
|
912 | + if ($fees) { |
|
913 | + foreach ($fees as $fee_id => $fee) { |
|
914 | + if (!empty($fee['no_tax'])) { |
|
915 | 915 | continue; |
916 | 916 | } |
917 | 917 | |
918 | - $tax += wpinv_calculate_tax( $fee['amount'] ); |
|
918 | + $tax += wpinv_calculate_tax($fee['amount']); |
|
919 | 919 | } |
920 | 920 | } |
921 | 921 | |
922 | - return apply_filters( 'wpinv_get_cart_fee_tax', $tax ); |
|
922 | + return apply_filters('wpinv_get_cart_fee_tax', $tax); |
|
923 | 923 | } |
924 | 924 | |
925 | 925 | function wpinv_cart_has_recurring_item() { |
926 | 926 | $cart_items = wpinv_get_cart_contents(); |
927 | 927 | |
928 | - if ( empty( $cart_items ) ) { |
|
928 | + if (empty($cart_items)) { |
|
929 | 929 | return false; |
930 | 930 | } |
931 | 931 | |
932 | 932 | $has_subscription = false; |
933 | - foreach( $cart_items as $cart_item ) { |
|
934 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
933 | + foreach ($cart_items as $cart_item) { |
|
934 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
935 | 935 | $has_subscription = true; |
936 | 936 | break; |
937 | 937 | } |
938 | 938 | } |
939 | 939 | |
940 | - return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items ); |
|
940 | + return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items); |
|
941 | 941 | } |
942 | 942 | |
943 | 943 | function wpinv_cart_has_free_trial() { |
@@ -945,100 +945,100 @@ discard block |
||
945 | 945 | |
946 | 946 | $free_trial = false; |
947 | 947 | |
948 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
948 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
949 | 949 | $free_trial = true; |
950 | 950 | } |
951 | 951 | |
952 | - return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice ); |
|
952 | + return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice); |
|
953 | 953 | } |
954 | 954 | |
955 | 955 | function wpinv_get_cart_contents() { |
956 | 956 | $cart_details = wpinv_get_cart_details(); |
957 | 957 | |
958 | - return apply_filters( 'wpinv_get_cart_contents', $cart_details ); |
|
958 | + return apply_filters('wpinv_get_cart_contents', $cart_details); |
|
959 | 959 | } |
960 | 960 | |
961 | 961 | function wpinv_get_cart_content_details() { |
962 | 962 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
963 | 963 | $cart_items = wpinv_get_cart_contents(); |
964 | 964 | |
965 | - if ( empty( $cart_items ) ) { |
|
965 | + if (empty($cart_items)) { |
|
966 | 966 | return false; |
967 | 967 | } |
968 | 968 | $invoice = wpinv_get_invoice_cart(); |
969 | - if ( empty( $invoice ) ) { |
|
969 | + if (empty($invoice)) { |
|
970 | 970 | return false; |
971 | 971 | } |
972 | 972 | |
973 | 973 | $details = array(); |
974 | - $length = count( $cart_items ) - 1; |
|
974 | + $length = count($cart_items) - 1; |
|
975 | 975 | |
976 | - if ( empty( $_POST['country'] ) ) { |
|
976 | + if (empty($_POST['country'])) { |
|
977 | 977 | $_POST['country'] = $invoice->country; |
978 | 978 | } |
979 | - if ( !isset( $_POST['state'] ) ) { |
|
979 | + if (!isset($_POST['state'])) { |
|
980 | 980 | $_POST['state'] = $invoice->state; |
981 | 981 | } |
982 | 982 | |
983 | - foreach( $cart_items as $key => $item ) { |
|
984 | - $item_id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
985 | - if ( empty( $item_id ) ) { |
|
983 | + foreach ($cart_items as $key => $item) { |
|
984 | + $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
985 | + if (empty($item_id)) { |
|
986 | 986 | continue; |
987 | 987 | } |
988 | 988 | |
989 | 989 | $wpi_current_id = $invoice->ID; |
990 | 990 | $wpi_item_id = $item_id; |
991 | 991 | |
992 | - if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) { |
|
992 | + if (isset($item['custom_price']) && $item['custom_price'] !== '') { |
|
993 | 993 | $item_price = $item['custom_price']; |
994 | 994 | } else { |
995 | - if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) { |
|
995 | + if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) { |
|
996 | 996 | $item_price = $item['item_price']; |
997 | 997 | } else { |
998 | - $item_price = wpinv_get_item_price( $item_id ); |
|
998 | + $item_price = wpinv_get_item_price($item_id); |
|
999 | 999 | } |
1000 | 1000 | } |
1001 | - $discount = wpinv_get_cart_item_discount_amount( $item ); |
|
1002 | - $discount = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item ); |
|
1003 | - $quantity = wpinv_get_cart_item_quantity( $item ); |
|
1004 | - $fees = wpinv_get_cart_fees( 'fee', $item_id ); |
|
1001 | + $discount = wpinv_get_cart_item_discount_amount($item); |
|
1002 | + $discount = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item); |
|
1003 | + $quantity = wpinv_get_cart_item_quantity($item); |
|
1004 | + $fees = wpinv_get_cart_fees('fee', $item_id); |
|
1005 | 1005 | |
1006 | 1006 | $subtotal = $item_price * $quantity; |
1007 | - $tax_rate = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id ); |
|
1008 | - $tax_class = $wpinv_euvat->get_item_class( $item_id ); |
|
1009 | - $tax = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount ); |
|
1007 | + $tax_rate = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id); |
|
1008 | + $tax_class = $wpinv_euvat->get_item_class($item_id); |
|
1009 | + $tax = wpinv_get_cart_item_tax($item_id, $subtotal - $discount); |
|
1010 | 1010 | |
1011 | - if ( ! $invoice->is_taxable() ) { |
|
1011 | + if (!$invoice->is_taxable()) { |
|
1012 | 1012 | $tax = 0; |
1013 | 1013 | } |
1014 | - if ( wpinv_prices_include_tax() ) { |
|
1015 | - $subtotal -= wpinv_round_amount( $tax ); |
|
1014 | + if (wpinv_prices_include_tax()) { |
|
1015 | + $subtotal -= wpinv_round_amount($tax); |
|
1016 | 1016 | } |
1017 | 1017 | |
1018 | - $total = $subtotal - $discount + $tax; |
|
1018 | + $total = $subtotal - $discount + $tax; |
|
1019 | 1019 | |
1020 | 1020 | // Do not allow totals to go negatve |
1021 | - if( $total < 0 ) { |
|
1021 | + if ($total < 0) { |
|
1022 | 1022 | $total = 0; |
1023 | 1023 | } |
1024 | 1024 | |
1025 | - $details[ $key ] = array( |
|
1025 | + $details[$key] = array( |
|
1026 | 1026 | 'id' => $item_id, |
1027 | - 'name' => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ), |
|
1028 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
1029 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
1027 | + 'name' => !empty($item['name']) ? $item['name'] : get_the_title($item_id), |
|
1028 | + 'item_price' => wpinv_round_amount($item_price), |
|
1029 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
1030 | 1030 | 'quantity' => $quantity, |
1031 | - 'discount' => wpinv_round_amount( $discount ), |
|
1032 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
1033 | - 'tax' => wpinv_round_amount( $tax ), |
|
1034 | - 'price' => wpinv_round_amount( $total ), |
|
1031 | + 'discount' => wpinv_round_amount($discount), |
|
1032 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
1033 | + 'tax' => wpinv_round_amount($tax), |
|
1034 | + 'price' => wpinv_round_amount($total), |
|
1035 | 1035 | 'vat_rates_class' => $tax_class, |
1036 | 1036 | 'vat_rate' => $tax_rate, |
1037 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
1037 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
1038 | 1038 | 'fees' => $fees, |
1039 | 1039 | ); |
1040 | 1040 | |
1041 | - if ( $wpinv_is_last_cart_item ) { |
|
1041 | + if ($wpinv_is_last_cart_item) { |
|
1042 | 1042 | $wpinv_is_last_cart_item = false; |
1043 | 1043 | $wpinv_flat_discount_total = 0.00; |
1044 | 1044 | } |
@@ -1047,67 +1047,67 @@ discard block |
||
1047 | 1047 | return $details; |
1048 | 1048 | } |
1049 | 1049 | |
1050 | -function wpinv_get_cart_details( $invoice_id = 0 ) { |
|
1050 | +function wpinv_get_cart_details($invoice_id = 0) { |
|
1051 | 1051 | global $ajax_cart_details; |
1052 | 1052 | |
1053 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
1053 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
1054 | 1054 | $cart_details = $ajax_cart_details; |
1055 | - if ( empty( $cart_details ) && ! empty( $invoice->cart_details ) ) { |
|
1055 | + if (empty($cart_details) && !empty($invoice->cart_details)) { |
|
1056 | 1056 | $cart_details = $invoice->cart_details; |
1057 | 1057 | } |
1058 | 1058 | |
1059 | - if ( ! empty( $cart_details ) && is_array( $cart_details ) ) { |
|
1060 | - $invoice_currency = ! empty( $invoice->currency ) ? $invoice->currency : wpinv_get_default_country(); |
|
1059 | + if (!empty($cart_details) && is_array($cart_details)) { |
|
1060 | + $invoice_currency = !empty($invoice->currency) ? $invoice->currency : wpinv_get_default_country(); |
|
1061 | 1061 | |
1062 | - foreach ( $cart_details as $key => $cart_item ) { |
|
1063 | - $cart_details[ $key ]['currency'] = $invoice_currency; |
|
1062 | + foreach ($cart_details as $key => $cart_item) { |
|
1063 | + $cart_details[$key]['currency'] = $invoice_currency; |
|
1064 | 1064 | |
1065 | - if ( ! isset( $cart_item['subtotal'] ) ) { |
|
1066 | - $cart_details[ $key ]['subtotal'] = $cart_item['price']; |
|
1065 | + if (!isset($cart_item['subtotal'])) { |
|
1066 | + $cart_details[$key]['subtotal'] = $cart_item['price']; |
|
1067 | 1067 | } |
1068 | 1068 | } |
1069 | 1069 | } |
1070 | 1070 | |
1071 | - return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id ); |
|
1071 | + return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id); |
|
1072 | 1072 | } |
1073 | 1073 | |
1074 | -function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) { |
|
1075 | - if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) { |
|
1074 | +function wpinv_record_status_change($invoice_id, $new_status, $old_status) { |
|
1075 | + if ('wpi_invoice' != get_post_type($invoice_id)) { |
|
1076 | 1076 | return; |
1077 | 1077 | } |
1078 | 1078 | |
1079 | - if ( ( $old_status == 'wpi-pending' && $new_status == 'draft' ) || ( $old_status == 'draft' && $new_status == 'wpi-pending' ) ) { |
|
1079 | + if (($old_status == 'wpi-pending' && $new_status == 'draft') || ($old_status == 'draft' && $new_status == 'wpi-pending')) { |
|
1080 | 1080 | return; |
1081 | 1081 | } |
1082 | 1082 | |
1083 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1083 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1084 | 1084 | |
1085 | - $old_status = wpinv_status_nicename( $old_status ); |
|
1086 | - $new_status = wpinv_status_nicename( $new_status ); |
|
1085 | + $old_status = wpinv_status_nicename($old_status); |
|
1086 | + $new_status = wpinv_status_nicename($new_status); |
|
1087 | 1087 | |
1088 | - $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status ); |
|
1088 | + $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status); |
|
1089 | 1089 | |
1090 | 1090 | // Add note |
1091 | - return $invoice->add_note( $status_change, false, false, true ); |
|
1091 | + return $invoice->add_note($status_change, false, false, true); |
|
1092 | 1092 | } |
1093 | -add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 ); |
|
1093 | +add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3); |
|
1094 | 1094 | |
1095 | -function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) { |
|
1095 | +function wpinv_complete_payment($invoice_id, $new_status, $old_status) { |
|
1096 | 1096 | global $wpi_has_free_trial; |
1097 | 1097 | |
1098 | 1098 | $wpi_has_free_trial = false; |
1099 | 1099 | |
1100 | - if ( $old_status == 'publish' ) { |
|
1100 | + if ($old_status == 'publish') { |
|
1101 | 1101 | return; // Make sure that payments are only paid once |
1102 | 1102 | } |
1103 | 1103 | |
1104 | 1104 | // Make sure the payment completion is only processed when new status is paid |
1105 | - if ( $new_status != 'publish' ) { |
|
1105 | + if ($new_status != 'publish') { |
|
1106 | 1106 | return; |
1107 | 1107 | } |
1108 | 1108 | |
1109 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
1110 | - if ( empty( $invoice ) ) { |
|
1109 | + $invoice = new WPInv_Invoice($invoice_id); |
|
1110 | + if (empty($invoice)) { |
|
1111 | 1111 | return; |
1112 | 1112 | } |
1113 | 1113 | |
@@ -1115,58 +1115,58 @@ discard block |
||
1115 | 1115 | $completed_date = $invoice->completed_date; |
1116 | 1116 | $cart_details = $invoice->cart_details; |
1117 | 1117 | |
1118 | - do_action( 'wpinv_pre_complete_payment', $invoice_id ); |
|
1118 | + do_action('wpinv_pre_complete_payment', $invoice_id); |
|
1119 | 1119 | |
1120 | - if ( is_array( $cart_details ) ) { |
|
1120 | + if (is_array($cart_details)) { |
|
1121 | 1121 | // Increase purchase count and earnings |
1122 | - foreach ( $cart_details as $cart_index => $item ) { |
|
1122 | + foreach ($cart_details as $cart_index => $item) { |
|
1123 | 1123 | // Ensure these actions only run once, ever |
1124 | - if ( empty( $completed_date ) ) { |
|
1125 | - do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index ); |
|
1124 | + if (empty($completed_date)) { |
|
1125 | + do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index); |
|
1126 | 1126 | } |
1127 | 1127 | } |
1128 | 1128 | } |
1129 | 1129 | |
1130 | 1130 | // Check for discount codes and increment their use counts |
1131 | - if ( $discounts = $invoice->get_discounts( true ) ) { |
|
1132 | - if( ! empty( $discounts ) ) { |
|
1133 | - foreach( $discounts as $code ) { |
|
1134 | - wpinv_increase_discount_usage( $code ); |
|
1131 | + if ($discounts = $invoice->get_discounts(true)) { |
|
1132 | + if (!empty($discounts)) { |
|
1133 | + foreach ($discounts as $code) { |
|
1134 | + wpinv_increase_discount_usage($code); |
|
1135 | 1135 | } |
1136 | 1136 | } |
1137 | 1137 | } |
1138 | 1138 | |
1139 | 1139 | // Ensure this action only runs once ever |
1140 | - if( empty( $completed_date ) ) { |
|
1140 | + if (empty($completed_date)) { |
|
1141 | 1141 | // Save the completed date |
1142 | - $invoice->set( 'completed_date', current_time( 'mysql', 0 ) ); |
|
1142 | + $invoice->set('completed_date', current_time('mysql', 0)); |
|
1143 | 1143 | $invoice->save(); |
1144 | 1144 | |
1145 | - do_action( 'wpinv_complete_payment', $invoice_id ); |
|
1145 | + do_action('wpinv_complete_payment', $invoice_id); |
|
1146 | 1146 | } |
1147 | 1147 | |
1148 | 1148 | // Empty the shopping cart |
1149 | 1149 | wpinv_empty_cart(); |
1150 | 1150 | } |
1151 | -add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 ); |
|
1151 | +add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3); |
|
1152 | 1152 | |
1153 | -function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) { |
|
1154 | - $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id ); |
|
1153 | +function wpinv_update_payment_status($invoice_id, $new_status = 'publish') { |
|
1154 | + $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int) $invoice_id); |
|
1155 | 1155 | |
1156 | - if ( empty( $invoice ) ) { |
|
1156 | + if (empty($invoice)) { |
|
1157 | 1157 | return false; |
1158 | 1158 | } |
1159 | 1159 | |
1160 | - return $invoice->update_status( $new_status ); |
|
1160 | + return $invoice->update_status($new_status); |
|
1161 | 1161 | } |
1162 | 1162 | |
1163 | -function wpinv_cart_has_fees( $type = 'all' ) { |
|
1163 | +function wpinv_cart_has_fees($type = 'all') { |
|
1164 | 1164 | return false; |
1165 | 1165 | } |
1166 | 1166 | |
1167 | 1167 | function wpinv_validate_checkout_fields() { |
1168 | 1168 | // Check if there is $_POST |
1169 | - if ( empty( $_POST ) ) { |
|
1169 | + if (empty($_POST)) { |
|
1170 | 1170 | return false; |
1171 | 1171 | } |
1172 | 1172 | |
@@ -1189,28 +1189,28 @@ discard block |
||
1189 | 1189 | |
1190 | 1190 | $invoice = wpinv_get_invoice_cart(); |
1191 | 1191 | $has_subscription = $invoice->is_recurring(); |
1192 | - if ( empty( $invoice ) ) { |
|
1193 | - wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) ); |
|
1192 | + if (empty($invoice)) { |
|
1193 | + wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing')); |
|
1194 | 1194 | return $gateway; |
1195 | 1195 | } |
1196 | 1196 | |
1197 | 1197 | // Check if a gateway value is present |
1198 | - if ( !empty( $_REQUEST['wpi-gateway'] ) ) { |
|
1199 | - $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] ); |
|
1198 | + if (!empty($_REQUEST['wpi-gateway'])) { |
|
1199 | + $gateway = sanitize_text_field($_REQUEST['wpi-gateway']); |
|
1200 | 1200 | |
1201 | - if ( $invoice->is_free() ) { |
|
1201 | + if ($invoice->is_free()) { |
|
1202 | 1202 | $gateway = 'manual'; |
1203 | - } elseif ( !wpinv_is_gateway_active( $gateway ) ) { |
|
1204 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) ); |
|
1205 | - } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) { |
|
1206 | - if ( apply_filters( 'wpinv_reject_non_recurring_gateway', true ) ) { |
|
1207 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway does not support subscription payment', 'invoicing' ) ); |
|
1203 | + } elseif (!wpinv_is_gateway_active($gateway)) { |
|
1204 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing')); |
|
1205 | + } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) { |
|
1206 | + if (apply_filters('wpinv_reject_non_recurring_gateway', true)) { |
|
1207 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway does not support subscription payment', 'invoicing')); |
|
1208 | 1208 | } |
1209 | 1209 | } |
1210 | 1210 | } |
1211 | 1211 | |
1212 | - if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) { |
|
1213 | - wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) ); |
|
1212 | + if ($has_subscription && count(wpinv_get_cart_contents()) > 1) { |
|
1213 | + wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing')); |
|
1214 | 1214 | } |
1215 | 1215 | |
1216 | 1216 | return $gateway; |
@@ -1224,10 +1224,10 @@ discard block |
||
1224 | 1224 | |
1225 | 1225 | $error = false; |
1226 | 1226 | // If we have discounts, loop through them |
1227 | - if ( ! empty( $discounts ) ) { |
|
1228 | - foreach ( $discounts as $discount ) { |
|
1227 | + if (!empty($discounts)) { |
|
1228 | + foreach ($discounts as $discount) { |
|
1229 | 1229 | // Check if valid |
1230 | - if ( !wpinv_is_discount_valid( $discount, (int)$wpi_cart->get_user_id() ) ) { |
|
1230 | + if (!wpinv_is_discount_valid($discount, (int) $wpi_cart->get_user_id())) { |
|
1231 | 1231 | // Discount is not valid |
1232 | 1232 | $error = true; |
1233 | 1233 | } |
@@ -1237,20 +1237,20 @@ discard block |
||
1237 | 1237 | return NULL; |
1238 | 1238 | } |
1239 | 1239 | |
1240 | - if ( $error && !wpinv_get_errors() ) { |
|
1241 | - wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) ); |
|
1240 | + if ($error && !wpinv_get_errors()) { |
|
1241 | + wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing')); |
|
1242 | 1242 | } |
1243 | 1243 | |
1244 | - return implode( ',', $discounts ); |
|
1244 | + return implode(',', $discounts); |
|
1245 | 1245 | } |
1246 | 1246 | |
1247 | 1247 | function wpinv_checkout_validate_cc() { |
1248 | 1248 | $card_data = wpinv_checkout_get_cc_info(); |
1249 | 1249 | |
1250 | 1250 | // Validate the card zip |
1251 | - if ( !empty( $card_data['wpinv_zip'] ) ) { |
|
1252 | - if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) { |
|
1253 | - wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) ); |
|
1251 | + if (!empty($card_data['wpinv_zip'])) { |
|
1252 | + if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) { |
|
1253 | + wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing')); |
|
1254 | 1254 | } |
1255 | 1255 | } |
1256 | 1256 | |
@@ -1260,28 +1260,28 @@ discard block |
||
1260 | 1260 | |
1261 | 1261 | function wpinv_checkout_get_cc_info() { |
1262 | 1262 | $cc_info = array(); |
1263 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
1264 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
1265 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
1266 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
1267 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
1268 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
1269 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
1270 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
1271 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
1272 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
1263 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
1264 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
1265 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
1266 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
1267 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
1268 | + $cc_info['card_address'] = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : ''; |
|
1269 | + $cc_info['card_city'] = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : ''; |
|
1270 | + $cc_info['card_state'] = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : ''; |
|
1271 | + $cc_info['card_country'] = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : ''; |
|
1272 | + $cc_info['card_zip'] = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : ''; |
|
1273 | 1273 | |
1274 | 1274 | // Return cc info |
1275 | 1275 | return $cc_info; |
1276 | 1276 | } |
1277 | 1277 | |
1278 | -function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
1278 | +function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') { |
|
1279 | 1279 | $ret = false; |
1280 | 1280 | |
1281 | - if ( empty( $zip ) || empty( $country_code ) ) |
|
1281 | + if (empty($zip) || empty($country_code)) |
|
1282 | 1282 | return $ret; |
1283 | 1283 | |
1284 | - $country_code = strtoupper( $country_code ); |
|
1284 | + $country_code = strtoupper($country_code); |
|
1285 | 1285 | |
1286 | 1286 | $zip_regex = array( |
1287 | 1287 | "AD" => "AD\d{3}", |
@@ -1441,72 +1441,72 @@ discard block |
||
1441 | 1441 | "ZM" => "\d{5}" |
1442 | 1442 | ); |
1443 | 1443 | |
1444 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) |
|
1444 | + if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip)) |
|
1445 | 1445 | $ret = true; |
1446 | 1446 | |
1447 | - return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code ); |
|
1447 | + return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code); |
|
1448 | 1448 | } |
1449 | 1449 | |
1450 | 1450 | function wpinv_checkout_validate_agree_to_terms() { |
1451 | 1451 | // Validate agree to terms |
1452 | - if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) { |
|
1452 | + if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) { |
|
1453 | 1453 | // User did not agree |
1454 | - wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) ); |
|
1454 | + wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing'))); |
|
1455 | 1455 | } |
1456 | 1456 | } |
1457 | 1457 | |
1458 | 1458 | function wpinv_checkout_validate_invoice_user() { |
1459 | 1459 | global $wpi_cart, $user_ID; |
1460 | 1460 | |
1461 | - if(empty($wpi_cart)){ |
|
1461 | + if (empty($wpi_cart)) { |
|
1462 | 1462 | $wpi_cart = wpinv_get_invoice_cart(); |
1463 | 1463 | } |
1464 | 1464 | |
1465 | - $invoice_user = (int)$wpi_cart->get_user_id(); |
|
1465 | + $invoice_user = (int) $wpi_cart->get_user_id(); |
|
1466 | 1466 | $valid_user_data = array( |
1467 | 1467 | 'user_id' => $invoice_user |
1468 | 1468 | ); |
1469 | 1469 | |
1470 | 1470 | // If guest checkout allowed |
1471 | - if ( !wpinv_require_login_to_checkout() ) { |
|
1471 | + if (!wpinv_require_login_to_checkout()) { |
|
1472 | 1472 | return $valid_user_data; |
1473 | 1473 | } |
1474 | 1474 | |
1475 | 1475 | // Verify there is a user_ID |
1476 | - if ( $user_ID == $invoice_user ) { |
|
1476 | + if ($user_ID == $invoice_user) { |
|
1477 | 1477 | // Get the logged in user data |
1478 | - $user_data = get_userdata( $user_ID ); |
|
1479 | - $required_fields = wpinv_checkout_required_fields(); |
|
1478 | + $user_data = get_userdata($user_ID); |
|
1479 | + $required_fields = wpinv_checkout_required_fields(); |
|
1480 | 1480 | |
1481 | 1481 | // Loop through required fields and show error messages |
1482 | - if ( !empty( $required_fields ) ) { |
|
1483 | - foreach ( $required_fields as $field_name => $value ) { |
|
1484 | - if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
|
1485 | - wpinv_set_error( $value['error_id'], $value['error_message'] ); |
|
1482 | + if (!empty($required_fields)) { |
|
1483 | + foreach ($required_fields as $field_name => $value) { |
|
1484 | + if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) { |
|
1485 | + wpinv_set_error($value['error_id'], $value['error_message']); |
|
1486 | 1486 | } |
1487 | 1487 | } |
1488 | 1488 | } |
1489 | 1489 | |
1490 | 1490 | // Verify data |
1491 | - if ( $user_data ) { |
|
1491 | + if ($user_data) { |
|
1492 | 1492 | // Collected logged in user data |
1493 | 1493 | $valid_user_data = array( |
1494 | 1494 | 'user_id' => $user_ID, |
1495 | - 'email' => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email, |
|
1496 | - 'first_name' => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name, |
|
1497 | - 'last_name' => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name'] ) ? sanitize_text_field( $_POST['wpinv_last_name'] ) : $user_data->last_name, |
|
1495 | + 'email' => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email, |
|
1496 | + 'first_name' => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name, |
|
1497 | + 'last_name' => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name, |
|
1498 | 1498 | ); |
1499 | 1499 | |
1500 | - if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) { |
|
1501 | - wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) ); |
|
1500 | + if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) { |
|
1501 | + wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing')); |
|
1502 | 1502 | } |
1503 | 1503 | } else { |
1504 | 1504 | // Set invalid user error |
1505 | - wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) ); |
|
1505 | + wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing')); |
|
1506 | 1506 | } |
1507 | 1507 | } else { |
1508 | 1508 | // Set invalid user error |
1509 | - wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) ); |
|
1509 | + wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing')); |
|
1510 | 1510 | } |
1511 | 1511 | |
1512 | 1512 | // Return user data |
@@ -1518,27 +1518,27 @@ discard block |
||
1518 | 1518 | |
1519 | 1519 | $data = array(); |
1520 | 1520 | |
1521 | - if ( is_user_logged_in() ) { |
|
1522 | - if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) { |
|
1523 | - $data['user_id'] = (int)get_current_user_id(); |
|
1521 | + if (is_user_logged_in()) { |
|
1522 | + if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int) $wpi_cart->get_user_id() === (int) get_current_user_id())) { |
|
1523 | + $data['user_id'] = (int) get_current_user_id(); |
|
1524 | 1524 | } else { |
1525 | - wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) ); |
|
1525 | + wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing')); |
|
1526 | 1526 | } |
1527 | 1527 | } else { |
1528 | 1528 | // If guest checkout allowed |
1529 | - if ( !wpinv_require_login_to_checkout() ) { |
|
1529 | + if (!wpinv_require_login_to_checkout()) { |
|
1530 | 1530 | $data['user_id'] = 0; |
1531 | 1531 | } else { |
1532 | - wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) ); |
|
1532 | + wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing')); |
|
1533 | 1533 | } |
1534 | 1534 | } |
1535 | 1535 | |
1536 | 1536 | return $data; |
1537 | 1537 | } |
1538 | 1538 | |
1539 | -function wpinv_checkout_form_get_user( $valid_data = array() ) { |
|
1539 | +function wpinv_checkout_form_get_user($valid_data = array()) { |
|
1540 | 1540 | |
1541 | - if ( !empty( $valid_data['current_user']['user_id'] ) ) { |
|
1541 | + if (!empty($valid_data['current_user']['user_id'])) { |
|
1542 | 1542 | $user = $valid_data['current_user']; |
1543 | 1543 | } else { |
1544 | 1544 | // Set the valid invoice user |
@@ -1546,7 +1546,7 @@ discard block |
||
1546 | 1546 | } |
1547 | 1547 | |
1548 | 1548 | // Verify invoice have an user |
1549 | - if ( false === $user || empty( $user ) ) { |
|
1549 | + if (false === $user || empty($user)) { |
|
1550 | 1550 | return false; |
1551 | 1551 | } |
1552 | 1552 | |
@@ -1563,11 +1563,11 @@ discard block |
||
1563 | 1563 | 'zip', |
1564 | 1564 | ); |
1565 | 1565 | |
1566 | - foreach ( $address_fields as $field ) { |
|
1567 | - $user[$field] = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false; |
|
1566 | + foreach ($address_fields as $field) { |
|
1567 | + $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false; |
|
1568 | 1568 | |
1569 | - if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id'] ) { |
|
1570 | - update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] ); |
|
1569 | + if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id']) { |
|
1570 | + update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]); |
|
1571 | 1571 | } |
1572 | 1572 | } |
1573 | 1573 | |
@@ -1575,28 +1575,28 @@ discard block |
||
1575 | 1575 | return $user; |
1576 | 1576 | } |
1577 | 1577 | |
1578 | -function wpinv_set_checkout_session( $invoice_data = array() ) { |
|
1578 | +function wpinv_set_checkout_session($invoice_data = array()) { |
|
1579 | 1579 | global $wpi_session; |
1580 | 1580 | |
1581 | - return $wpi_session->set( 'wpinv_checkout', $invoice_data ); |
|
1581 | + return $wpi_session->set('wpinv_checkout', $invoice_data); |
|
1582 | 1582 | } |
1583 | 1583 | |
1584 | 1584 | function wpinv_get_checkout_session() { |
1585 | 1585 | global $wpi_session; |
1586 | 1586 | |
1587 | - return $wpi_session->get( 'wpinv_checkout' ); |
|
1587 | + return $wpi_session->get('wpinv_checkout'); |
|
1588 | 1588 | } |
1589 | 1589 | |
1590 | 1590 | function wpinv_empty_cart() { |
1591 | 1591 | global $wpi_session; |
1592 | 1592 | |
1593 | 1593 | // Remove cart contents |
1594 | - $wpi_session->set( 'wpinv_checkout', NULL ); |
|
1594 | + $wpi_session->set('wpinv_checkout', NULL); |
|
1595 | 1595 | |
1596 | 1596 | // Remove all cart fees |
1597 | - $wpi_session->set( 'wpi_cart_fees', NULL ); |
|
1597 | + $wpi_session->set('wpi_cart_fees', NULL); |
|
1598 | 1598 | |
1599 | - do_action( 'wpinv_empty_cart' ); |
|
1599 | + do_action('wpinv_empty_cart'); |
|
1600 | 1600 | } |
1601 | 1601 | |
1602 | 1602 | function wpinv_process_checkout() { |
@@ -1605,7 +1605,7 @@ discard block |
||
1605 | 1605 | wpinv_clear_errors(); |
1606 | 1606 | |
1607 | 1607 | $invoice = wpinv_get_invoice_cart(); |
1608 | - if ( empty( $invoice ) ) { |
|
1608 | + if (empty($invoice)) { |
|
1609 | 1609 | return false; |
1610 | 1610 | } |
1611 | 1611 | |
@@ -1613,42 +1613,42 @@ discard block |
||
1613 | 1613 | |
1614 | 1614 | $wpi_checkout_id = $invoice->ID; |
1615 | 1615 | |
1616 | - do_action( 'wpinv_pre_process_checkout' ); |
|
1616 | + do_action('wpinv_pre_process_checkout'); |
|
1617 | 1617 | |
1618 | - if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty |
|
1618 | + if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty |
|
1619 | 1619 | $valid_data = false; |
1620 | - wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) ); |
|
1620 | + wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing')); |
|
1621 | 1621 | } else { |
1622 | 1622 | // Validate the form $_POST data |
1623 | 1623 | $valid_data = wpinv_validate_checkout_fields(); |
1624 | 1624 | |
1625 | 1625 | // Allow themes and plugins to hook to errors |
1626 | - do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST ); |
|
1626 | + do_action('wpinv_checkout_error_checks', $valid_data, $_POST); |
|
1627 | 1627 | } |
1628 | 1628 | |
1629 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
1629 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
1630 | 1630 | |
1631 | 1631 | // Validate the user |
1632 | - $user = wpinv_checkout_form_get_user( $valid_data ); |
|
1632 | + $user = wpinv_checkout_form_get_user($valid_data); |
|
1633 | 1633 | |
1634 | 1634 | // Let extensions validate fields after user is logged in if user has used login/registration form |
1635 | - do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST ); |
|
1635 | + do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST); |
|
1636 | 1636 | |
1637 | - if ( false === $valid_data || wpinv_get_errors() || ! $user ) { |
|
1638 | - if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) { |
|
1639 | - do_action( 'wpinv_ajax_checkout_errors' ); |
|
1637 | + if (false === $valid_data || wpinv_get_errors() || !$user) { |
|
1638 | + if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) { |
|
1639 | + do_action('wpinv_ajax_checkout_errors'); |
|
1640 | 1640 | die(); |
1641 | 1641 | } else { |
1642 | 1642 | return false; |
1643 | 1643 | } |
1644 | 1644 | } |
1645 | 1645 | |
1646 | - if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) { |
|
1646 | + if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) { |
|
1647 | 1647 | // Save address fields. |
1648 | - $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' ); |
|
1649 | - foreach ( $address_fields as $field ) { |
|
1650 | - if ( isset( $user[$field] ) ) { |
|
1651 | - $invoice->set( $field, $user[$field] ); |
|
1648 | + $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company'); |
|
1649 | + foreach ($address_fields as $field) { |
|
1650 | + if (isset($user[$field])) { |
|
1651 | + $invoice->set($field, $user[$field]); |
|
1652 | 1652 | } |
1653 | 1653 | |
1654 | 1654 | $invoice->save(); |
@@ -1656,16 +1656,16 @@ discard block |
||
1656 | 1656 | |
1657 | 1657 | $response['success'] = true; |
1658 | 1658 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
1659 | - $response['data']['subtotalf'] = $invoice->get_subtotal( true ); |
|
1659 | + $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
|
1660 | 1660 | $response['data']['discount'] = $invoice->get_discount(); |
1661 | - $response['data']['discountf'] = $invoice->get_discount( true ); |
|
1661 | + $response['data']['discountf'] = $invoice->get_discount(true); |
|
1662 | 1662 | $response['data']['tax'] = $invoice->get_tax(); |
1663 | - $response['data']['taxf'] = $invoice->get_tax( true ); |
|
1663 | + $response['data']['taxf'] = $invoice->get_tax(true); |
|
1664 | 1664 | $response['data']['total'] = $invoice->get_total(); |
1665 | - $response['data']['totalf'] = $invoice->get_total( true ); |
|
1666 | - $response['data']['free'] = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false; |
|
1665 | + $response['data']['totalf'] = $invoice->get_total(true); |
|
1666 | + $response['data']['free'] = $invoice->is_free() && (!((float) $response['data']['total'] > 0) || $invoice->is_free_trial()) ? true : false; |
|
1667 | 1667 | |
1668 | - wp_send_json( $response ); |
|
1668 | + wp_send_json($response); |
|
1669 | 1669 | } |
1670 | 1670 | |
1671 | 1671 | $user_info = array( |
@@ -1687,42 +1687,42 @@ discard block |
||
1687 | 1687 | |
1688 | 1688 | // Setup invoice information |
1689 | 1689 | $invoice_data = array( |
1690 | - 'invoice_id' => !empty( $invoice ) ? $invoice->ID : 0, |
|
1690 | + 'invoice_id' => !empty($invoice) ? $invoice->ID : 0, |
|
1691 | 1691 | 'items' => $cart_items, |
1692 | 1692 | 'cart_discounts' => $discounts, |
1693 | - 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1694 | - 'subtotal' => wpinv_get_cart_subtotal( $cart_items ), // Amount before taxes and discounts |
|
1695 | - 'discount' => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount |
|
1696 | - 'tax' => wpinv_get_cart_tax( $cart_items, $invoice ), // Taxed amount |
|
1697 | - 'price' => wpinv_get_cart_total( $cart_items, $discounts ), // Amount after taxes |
|
1693 | + 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1694 | + 'subtotal' => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts |
|
1695 | + 'discount' => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount |
|
1696 | + 'tax' => wpinv_get_cart_tax($cart_items, $invoice), // Taxed amount |
|
1697 | + 'price' => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes |
|
1698 | 1698 | 'invoice_key' => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(), |
1699 | 1699 | 'user_email' => $invoice->get_email(), |
1700 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
1701 | - 'user_info' => stripslashes_deep( $user_info ), |
|
1700 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
1701 | + 'user_info' => stripslashes_deep($user_info), |
|
1702 | 1702 | 'post_data' => $_POST, |
1703 | 1703 | 'cart_details' => $cart_items, |
1704 | 1704 | 'gateway' => $valid_data['gateway'], |
1705 | 1705 | 'card_info' => $valid_data['cc_info'] |
1706 | 1706 | ); |
1707 | 1707 | |
1708 | - $vat_info = $wpinv_euvat->current_vat_data(); |
|
1709 | - if ( is_array( $vat_info ) ) { |
|
1708 | + $vat_info = $wpinv_euvat->current_vat_data(); |
|
1709 | + if (is_array($vat_info)) { |
|
1710 | 1710 | $invoice_data['user_info']['vat_number'] = $vat_info['number']; |
1711 | 1711 | $invoice_data['user_info']['vat_rate'] = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']); |
1712 | - $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1712 | + $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1713 | 1713 | |
1714 | 1714 | // Add the VAT rate to each item in the cart |
1715 | - foreach( $invoice_data['cart_details'] as $key => $item_data) { |
|
1715 | + foreach ($invoice_data['cart_details'] as $key => $item_data) { |
|
1716 | 1716 | $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']); |
1717 | - $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 ); |
|
1717 | + $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4); |
|
1718 | 1718 | } |
1719 | 1719 | } |
1720 | 1720 | |
1721 | 1721 | // Save vat fields. |
1722 | - $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' ); |
|
1723 | - foreach ( $address_fields as $field ) { |
|
1724 | - if ( isset( $invoice_data['user_info'][$field] ) ) { |
|
1725 | - $invoice->set( $field, $invoice_data['user_info'][$field] ); |
|
1722 | + $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed'); |
|
1723 | + foreach ($address_fields as $field) { |
|
1724 | + if (isset($invoice_data['user_info'][$field])) { |
|
1725 | + $invoice->set($field, $invoice_data['user_info'][$field]); |
|
1726 | 1726 | } |
1727 | 1727 | |
1728 | 1728 | $invoice->save(); |
@@ -1732,54 +1732,54 @@ discard block |
||
1732 | 1732 | $valid_data['user'] = $user; |
1733 | 1733 | |
1734 | 1734 | // Allow themes and plugins to hook before the gateway |
1735 | - do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
1735 | + do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
1736 | 1736 | |
1737 | 1737 | // If it is free, abort. |
1738 | - if ( $invoice->is_free() && ! ( $invoice->is_recurring() || ! $invoice->has_free_lifetime_discount() ) ) { |
|
1738 | + if ($invoice->is_free() && !($invoice->is_recurring() || !$invoice->has_free_lifetime_discount())) { |
|
1739 | 1739 | $invoice_data['gateway'] = 'manual'; |
1740 | 1740 | $_POST['wpi-gateway'] = 'manual'; |
1741 | 1741 | } |
1742 | 1742 | |
1743 | 1743 | // Allow the invoice data to be modified before it is sent to the gateway |
1744 | - $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data ); |
|
1744 | + $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data); |
|
1745 | 1745 | |
1746 | - if ( $invoice_data['price'] && $invoice_data['gateway'] == 'manual' ) { |
|
1746 | + if ($invoice_data['price'] && $invoice_data['gateway'] == 'manual') { |
|
1747 | 1747 | $mode = 'test'; |
1748 | 1748 | } else { |
1749 | - $mode = wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live'; |
|
1749 | + $mode = wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live'; |
|
1750 | 1750 | } |
1751 | 1751 | |
1752 | 1752 | // Setup the data we're storing in the purchase session |
1753 | 1753 | $session_data = $invoice_data; |
1754 | 1754 | // Make sure credit card numbers are never stored in sessions |
1755 | - if ( !empty( $session_data['card_info']['card_number'] ) ) { |
|
1756 | - unset( $session_data['card_info']['card_number'] ); |
|
1755 | + if (!empty($session_data['card_info']['card_number'])) { |
|
1756 | + unset($session_data['card_info']['card_number']); |
|
1757 | 1757 | } |
1758 | 1758 | |
1759 | 1759 | // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data. |
1760 | - wpinv_set_checkout_session( $invoice_data ); |
|
1760 | + wpinv_set_checkout_session($invoice_data); |
|
1761 | 1761 | |
1762 | 1762 | // Set gateway |
1763 | - $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] ); |
|
1764 | - $invoice->update_meta( '_wpinv_mode', $mode ); |
|
1765 | - $invoice->update_meta( '_wpinv_checkout', date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) ); |
|
1763 | + $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']); |
|
1764 | + $invoice->update_meta('_wpinv_mode', $mode); |
|
1765 | + $invoice->update_meta('_wpinv_checkout', date_i18n('Y-m-d H:i:s', current_time('timestamp'))); |
|
1766 | 1766 | |
1767 | - do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data ); |
|
1767 | + do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data); |
|
1768 | 1768 | |
1769 | 1769 | // Send info to the gateway for payment processing |
1770 | - wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data ); |
|
1770 | + wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data); |
|
1771 | 1771 | die(); |
1772 | 1772 | } |
1773 | -add_action( 'wpinv_payment', 'wpinv_process_checkout' ); |
|
1773 | +add_action('wpinv_payment', 'wpinv_process_checkout'); |
|
1774 | 1774 | |
1775 | -function wpinv_get_invoices( $args ) { |
|
1776 | - $args = wp_parse_args( $args, array( |
|
1777 | - 'status' => array_keys( wpinv_get_invoice_statuses() ), |
|
1775 | +function wpinv_get_invoices($args) { |
|
1776 | + $args = wp_parse_args($args, array( |
|
1777 | + 'status' => array_keys(wpinv_get_invoice_statuses()), |
|
1778 | 1778 | 'type' => 'wpi_invoice', |
1779 | 1779 | 'parent' => null, |
1780 | 1780 | 'user' => null, |
1781 | 1781 | 'email' => '', |
1782 | - 'limit' => get_option( 'posts_per_page' ), |
|
1782 | + 'limit' => get_option('posts_per_page'), |
|
1783 | 1783 | 'offset' => null, |
1784 | 1784 | 'page' => 1, |
1785 | 1785 | 'exclude' => array(), |
@@ -1787,7 +1787,7 @@ discard block |
||
1787 | 1787 | 'order' => 'DESC', |
1788 | 1788 | 'return' => 'objects', |
1789 | 1789 | 'paginate' => false, |
1790 | - ) ); |
|
1790 | + )); |
|
1791 | 1791 | |
1792 | 1792 | // Handle some BW compatibility arg names where wp_query args differ in naming. |
1793 | 1793 | $map_legacy = array( |
@@ -1800,18 +1800,18 @@ discard block |
||
1800 | 1800 | 'paged' => 'page', |
1801 | 1801 | ); |
1802 | 1802 | |
1803 | - foreach ( $map_legacy as $from => $to ) { |
|
1804 | - if ( isset( $args[ $from ] ) ) { |
|
1805 | - $args[ $to ] = $args[ $from ]; |
|
1803 | + foreach ($map_legacy as $from => $to) { |
|
1804 | + if (isset($args[$from])) { |
|
1805 | + $args[$to] = $args[$from]; |
|
1806 | 1806 | } |
1807 | 1807 | } |
1808 | 1808 | |
1809 | - if ( get_query_var( 'paged' ) ) |
|
1809 | + if (get_query_var('paged')) |
|
1810 | 1810 | $args['page'] = get_query_var('paged'); |
1811 | - else if ( get_query_var( 'page' ) ) |
|
1812 | - $args['page'] = get_query_var( 'page' ); |
|
1813 | - else if ( !empty( $args[ 'page' ] ) ) |
|
1814 | - $args['page'] = $args[ 'page' ]; |
|
1811 | + else if (get_query_var('page')) |
|
1812 | + $args['page'] = get_query_var('page'); |
|
1813 | + else if (!empty($args['page'])) |
|
1814 | + $args['page'] = $args['page']; |
|
1815 | 1815 | else |
1816 | 1816 | $args['page'] = 1; |
1817 | 1817 | |
@@ -1824,48 +1824,48 @@ discard block |
||
1824 | 1824 | 'post_status' => $args['status'], |
1825 | 1825 | 'posts_per_page' => $args['limit'], |
1826 | 1826 | 'meta_query' => array(), |
1827 | - 'date_query' => !empty( $args['date_query'] ) ? $args['date_query'] : array(), |
|
1827 | + 'date_query' => !empty($args['date_query']) ? $args['date_query'] : array(), |
|
1828 | 1828 | 'fields' => 'ids', |
1829 | 1829 | 'orderby' => $args['orderby'], |
1830 | 1830 | 'order' => $args['order'], |
1831 | 1831 | ); |
1832 | 1832 | |
1833 | - if ( !empty( $args['user'] ) ) { |
|
1834 | - $wp_query_args['author'] = absint( $args['user'] ); |
|
1833 | + if (!empty($args['user'])) { |
|
1834 | + $wp_query_args['author'] = absint($args['user']); |
|
1835 | 1835 | } |
1836 | 1836 | |
1837 | - if ( ! is_null( $args['parent'] ) ) { |
|
1838 | - $wp_query_args['post_parent'] = absint( $args['parent'] ); |
|
1837 | + if (!is_null($args['parent'])) { |
|
1838 | + $wp_query_args['post_parent'] = absint($args['parent']); |
|
1839 | 1839 | } |
1840 | 1840 | |
1841 | - if ( ! is_null( $args['offset'] ) ) { |
|
1842 | - $wp_query_args['offset'] = absint( $args['offset'] ); |
|
1841 | + if (!is_null($args['offset'])) { |
|
1842 | + $wp_query_args['offset'] = absint($args['offset']); |
|
1843 | 1843 | } else { |
1844 | - $wp_query_args['paged'] = absint( $args['page'] ); |
|
1844 | + $wp_query_args['paged'] = absint($args['page']); |
|
1845 | 1845 | } |
1846 | 1846 | |
1847 | - if ( ! empty( $args['exclude'] ) ) { |
|
1848 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
1847 | + if (!empty($args['exclude'])) { |
|
1848 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
1849 | 1849 | } |
1850 | 1850 | |
1851 | - if ( ! $args['paginate' ] ) { |
|
1851 | + if (!$args['paginate']) { |
|
1852 | 1852 | $wp_query_args['no_found_rows'] = true; |
1853 | 1853 | } |
1854 | 1854 | |
1855 | 1855 | $wp_query_args = apply_filters('wpinv_get_invoices_args', $wp_query_args, $args); |
1856 | 1856 | |
1857 | 1857 | // Get results. |
1858 | - $invoices = new WP_Query( $wp_query_args ); |
|
1858 | + $invoices = new WP_Query($wp_query_args); |
|
1859 | 1859 | |
1860 | - if ( 'objects' === $args['return'] ) { |
|
1861 | - $return = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
1862 | - } elseif ( 'self' === $args['return'] ) { |
|
1860 | + if ('objects' === $args['return']) { |
|
1861 | + $return = array_map('wpinv_get_invoice', $invoices->posts); |
|
1862 | + } elseif ('self' === $args['return']) { |
|
1863 | 1863 | return $invoices; |
1864 | 1864 | } else { |
1865 | 1865 | $return = $invoices->posts; |
1866 | 1866 | } |
1867 | 1867 | |
1868 | - if ( $args['paginate' ] ) { |
|
1868 | + if ($args['paginate']) { |
|
1869 | 1869 | return (object) array( |
1870 | 1870 | 'invoices' => $return, |
1871 | 1871 | 'total' => $invoices->found_posts, |
@@ -1878,22 +1878,22 @@ discard block |
||
1878 | 1878 | |
1879 | 1879 | function wpinv_get_user_invoices_columns() { |
1880 | 1880 | $columns = array( |
1881 | - 'invoice-number' => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ), |
|
1882 | - 'created-date' => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ), |
|
1883 | - 'payment-date' => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ), |
|
1884 | - 'invoice-status' => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ), |
|
1885 | - 'invoice-total' => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ), |
|
1886 | - 'invoice-actions' => array( 'title' => ' ', 'class' => 'text-center' ), |
|
1881 | + 'invoice-number' => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'), |
|
1882 | + 'created-date' => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'), |
|
1883 | + 'payment-date' => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'), |
|
1884 | + 'invoice-status' => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'), |
|
1885 | + 'invoice-total' => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'), |
|
1886 | + 'invoice-actions' => array('title' => ' ', 'class' => 'text-center'), |
|
1887 | 1887 | ); |
1888 | 1888 | |
1889 | - return apply_filters( 'wpinv_user_invoices_columns', $columns ); |
|
1889 | + return apply_filters('wpinv_user_invoices_columns', $columns); |
|
1890 | 1890 | } |
1891 | 1891 | |
1892 | -function wpinv_payment_receipt( $atts, $content = null ) { |
|
1892 | +function wpinv_payment_receipt($atts, $content = null) { |
|
1893 | 1893 | global $wpinv_receipt_args; |
1894 | 1894 | |
1895 | - $wpinv_receipt_args = shortcode_atts( array( |
|
1896 | - 'error' => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ), |
|
1895 | + $wpinv_receipt_args = shortcode_atts(array( |
|
1896 | + 'error' => __('Sorry, trouble retrieving payment receipt.', 'invoicing'), |
|
1897 | 1897 | 'price' => true, |
1898 | 1898 | 'discount' => true, |
1899 | 1899 | 'items' => true, |
@@ -1902,44 +1902,44 @@ discard block |
||
1902 | 1902 | 'invoice_key' => false, |
1903 | 1903 | 'payment_method' => true, |
1904 | 1904 | 'invoice_id' => true |
1905 | - ), $atts, 'wpinv_receipt' ); |
|
1905 | + ), $atts, 'wpinv_receipt'); |
|
1906 | 1906 | |
1907 | 1907 | $session = wpinv_get_checkout_session(); |
1908 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
1909 | - $invoice_key = urldecode( $_GET['invoice_key'] ); |
|
1910 | - } else if ( $session && isset( $session['invoice_key'] ) ) { |
|
1908 | + if (isset($_GET['invoice_key'])) { |
|
1909 | + $invoice_key = urldecode($_GET['invoice_key']); |
|
1910 | + } else if ($session && isset($session['invoice_key'])) { |
|
1911 | 1911 | $invoice_key = $session['invoice_key']; |
1912 | - } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) { |
|
1912 | + } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) { |
|
1913 | 1913 | $invoice_key = $wpinv_receipt_args['invoice_key']; |
1914 | - } else if ( isset( $_GET['invoice-id'] ) ) { |
|
1915 | - $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] ); |
|
1914 | + } else if (isset($_GET['invoice-id'])) { |
|
1915 | + $invoice_key = wpinv_get_payment_key((int) $_GET['invoice-id']); |
|
1916 | 1916 | } |
1917 | 1917 | |
1918 | 1918 | // No key found |
1919 | - if ( ! isset( $invoice_key ) ) { |
|
1919 | + if (!isset($invoice_key)) { |
|
1920 | 1920 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
1921 | 1921 | } |
1922 | 1922 | |
1923 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1924 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
1925 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
1926 | - $invoice_id = (int)$_GET['invoice-id']; |
|
1927 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
1923 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
1924 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
1925 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
1926 | + $invoice_id = (int) $_GET['invoice-id']; |
|
1927 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false; |
|
1928 | 1928 | } |
1929 | 1929 | |
1930 | 1930 | // Key was provided, but user is logged out. Offer them the ability to login and view the receipt |
1931 | - if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) { |
|
1931 | + if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) { |
|
1932 | 1932 | // login redirect |
1933 | - return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>'; |
|
1933 | + return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>'; |
|
1934 | 1934 | } |
1935 | 1935 | |
1936 | - if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) { |
|
1936 | + if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) { |
|
1937 | 1937 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
1938 | 1938 | } |
1939 | 1939 | |
1940 | 1940 | ob_start(); |
1941 | 1941 | |
1942 | - wpinv_get_template_part( 'wpinv-invoice-receipt' ); |
|
1942 | + wpinv_get_template_part('wpinv-invoice-receipt'); |
|
1943 | 1943 | |
1944 | 1944 | $display = ob_get_clean(); |
1945 | 1945 | |
@@ -1949,148 +1949,148 @@ discard block |
||
1949 | 1949 | /** |
1950 | 1950 | * Given an invoice key, this function returns the id. |
1951 | 1951 | */ |
1952 | -function wpinv_get_invoice_id_by_key( $key ) { |
|
1952 | +function wpinv_get_invoice_id_by_key($key) { |
|
1953 | 1953 | global $wpdb; |
1954 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
1955 | - return (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key ) ); |
|
1954 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
1955 | + return (int) $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key)); |
|
1956 | 1956 | } |
1957 | 1957 | |
1958 | -function wpinv_can_view_receipt( $invoice_key = '' ) { |
|
1958 | +function wpinv_can_view_receipt($invoice_key = '') { |
|
1959 | 1959 | $return = false; |
1960 | 1960 | |
1961 | - if ( empty( $invoice_key ) ) { |
|
1961 | + if (empty($invoice_key)) { |
|
1962 | 1962 | return $return; |
1963 | 1963 | } |
1964 | 1964 | |
1965 | 1965 | global $wpinv_receipt_args; |
1966 | 1966 | |
1967 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1968 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
1969 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
1967 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key); |
|
1968 | + if (isset($_GET['invoice-id'])) { |
|
1969 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? (int) $_GET['invoice-id'] : 0; |
|
1970 | 1970 | } |
1971 | 1971 | |
1972 | - if ( empty( $wpinv_receipt_args['id'] ) ) { |
|
1972 | + if (empty($wpinv_receipt_args['id'])) { |
|
1973 | 1973 | return $return; |
1974 | 1974 | } |
1975 | 1975 | |
1976 | - $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] ); |
|
1977 | - if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) { |
|
1976 | + $invoice = wpinv_get_invoice($wpinv_receipt_args['id']); |
|
1977 | + if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) { |
|
1978 | 1978 | return $return; |
1979 | 1979 | } |
1980 | 1980 | |
1981 | - if ( is_user_logged_in() ) { |
|
1982 | - if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) { |
|
1981 | + if (is_user_logged_in()) { |
|
1982 | + if ((int) $invoice->get_user_id() === (int) get_current_user_id()) { |
|
1983 | 1983 | $return = true; |
1984 | 1984 | } |
1985 | 1985 | } |
1986 | 1986 | |
1987 | 1987 | $session = wpinv_get_checkout_session(); |
1988 | - if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) { |
|
1989 | - $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
1988 | + if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) { |
|
1989 | + $check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
1990 | 1990 | |
1991 | - if ( wpinv_require_login_to_checkout() ) { |
|
1991 | + if (wpinv_require_login_to_checkout()) { |
|
1992 | 1992 | $return = $return && $check_key === $invoice_key; |
1993 | 1993 | } else { |
1994 | 1994 | $return = $check_key === $invoice_key; |
1995 | 1995 | } |
1996 | 1996 | } |
1997 | 1997 | |
1998 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
1998 | + return (bool) apply_filters('wpinv_can_view_receipt', $return, $invoice_key); |
|
1999 | 1999 | } |
2000 | 2000 | |
2001 | 2001 | function wpinv_pay_for_invoice() { |
2002 | 2002 | global $wpinv_euvat; |
2003 | 2003 | |
2004 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
2004 | + if (isset($_GET['invoice_key'])) { |
|
2005 | 2005 | $checkout_uri = wpinv_get_checkout_uri(); |
2006 | - $invoice_key = sanitize_text_field( $_GET['invoice_key'] ); |
|
2006 | + $invoice_key = sanitize_text_field($_GET['invoice_key']); |
|
2007 | 2007 | |
2008 | - if ( empty( $invoice_key ) ) { |
|
2009 | - wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) ); |
|
2010 | - wp_redirect( $checkout_uri ); |
|
2008 | + if (empty($invoice_key)) { |
|
2009 | + wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing')); |
|
2010 | + wp_redirect($checkout_uri); |
|
2011 | 2011 | exit(); |
2012 | 2012 | } |
2013 | 2013 | |
2014 | - do_action( 'wpinv_check_pay_for_invoice', $invoice_key ); |
|
2014 | + do_action('wpinv_check_pay_for_invoice', $invoice_key); |
|
2015 | 2015 | |
2016 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
2017 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
2018 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
2019 | - $invoice_id = (int)$_GET['invoice-id']; |
|
2020 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
2016 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
2017 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
2018 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
2019 | + $invoice_id = (int) $_GET['invoice-id']; |
|
2020 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false; |
|
2021 | 2021 | } |
2022 | 2022 | |
2023 | - if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) { |
|
2024 | - if ( $invoice->needs_payment() ) { |
|
2023 | + if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) { |
|
2024 | + if ($invoice->needs_payment()) { |
|
2025 | 2025 | $data = array(); |
2026 | 2026 | $data['invoice_id'] = $invoice_id; |
2027 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
2027 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
2028 | 2028 | |
2029 | - wpinv_set_checkout_session( $data ); |
|
2029 | + wpinv_set_checkout_session($data); |
|
2030 | 2030 | |
2031 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
2031 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
2032 | 2032 | $_POST['country'] = $wpinv_euvat->get_country_by_ip(); |
2033 | 2033 | $_POST['state'] = $_POST['country'] == $invoice->country ? $invoice->state : ''; |
2034 | 2034 | |
2035 | - wpinv_recalculate_tax( true ); |
|
2035 | + wpinv_recalculate_tax(true); |
|
2036 | 2036 | } |
2037 | 2037 | |
2038 | 2038 | } else { |
2039 | 2039 | $checkout_uri = $invoice->get_view_url(); |
2040 | 2040 | } |
2041 | 2041 | } else { |
2042 | - wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) ); |
|
2042 | + wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing')); |
|
2043 | 2043 | |
2044 | - $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
2044 | + $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
2045 | 2045 | } |
2046 | 2046 | |
2047 | - if(wp_redirect( $checkout_uri )){ |
|
2047 | + if (wp_redirect($checkout_uri)) { |
|
2048 | 2048 | exit; |
2049 | 2049 | }; |
2050 | 2050 | wpinv_die(); |
2051 | 2051 | } |
2052 | 2052 | } |
2053 | -add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' ); |
|
2053 | +add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice'); |
|
2054 | 2054 | |
2055 | -function wpinv_handle_pay_via_invoice_link( $invoice_key ) { |
|
2056 | - if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) { |
|
2057 | - if ( $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
2055 | +function wpinv_handle_pay_via_invoice_link($invoice_key) { |
|
2056 | + if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) { |
|
2057 | + if ($invoice = wpinv_get_invoice($invoice_id)) { |
|
2058 | 2058 | $user_id = $invoice->get_user_id(); |
2059 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
2059 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
2060 | 2060 | |
2061 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link |
|
2062 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
2061 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link |
|
2062 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
2063 | 2063 | |
2064 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
2064 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
2065 | 2065 | exit(); |
2066 | 2066 | } |
2067 | 2067 | } |
2068 | 2068 | } |
2069 | 2069 | } |
2070 | -add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' ); |
|
2070 | +add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link'); |
|
2071 | 2071 | |
2072 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
2073 | - $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id; |
|
2072 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
2073 | + $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id; |
|
2074 | 2074 | |
2075 | - if ( empty( $invoice_id ) && $invoice_id > 0 ) { |
|
2075 | + if (empty($invoice_id) && $invoice_id > 0) { |
|
2076 | 2076 | return false; |
2077 | 2077 | } |
2078 | 2078 | |
2079 | - if ( empty( $transaction_id ) ) { |
|
2079 | + if (empty($transaction_id)) { |
|
2080 | 2080 | $transaction_id = $invoice_id; |
2081 | 2081 | } |
2082 | 2082 | |
2083 | - $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id ); |
|
2083 | + $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id); |
|
2084 | 2084 | |
2085 | - return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id ); |
|
2085 | + return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id); |
|
2086 | 2086 | } |
2087 | 2087 | |
2088 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
2089 | - if ( empty( $status_display ) ) { |
|
2090 | - $status_display = wpinv_status_nicename( $status ); |
|
2088 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
2089 | + if (empty($status_display)) { |
|
2090 | + $status_display = wpinv_status_nicename($status); |
|
2091 | 2091 | } |
2092 | 2092 | |
2093 | - switch ( $status ) { |
|
2093 | + switch ($status) { |
|
2094 | 2094 | case 'publish' : |
2095 | 2095 | case 'wpi-renewal' : |
2096 | 2096 | $class = 'label-success'; |
@@ -2115,201 +2115,201 @@ discard block |
||
2115 | 2115 | |
2116 | 2116 | $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>'; |
2117 | 2117 | |
2118 | - return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display ); |
|
2118 | + return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display); |
|
2119 | 2119 | } |
2120 | 2120 | |
2121 | -function wpinv_format_invoice_number( $number, $type = '' ) { |
|
2122 | - $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type ); |
|
2123 | - if ( null !== $check ) { |
|
2121 | +function wpinv_format_invoice_number($number, $type = '') { |
|
2122 | + $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type); |
|
2123 | + if (null !== $check) { |
|
2124 | 2124 | return $check; |
2125 | 2125 | } |
2126 | 2126 | |
2127 | - if ( !empty( $number ) && !is_numeric( $number ) ) { |
|
2127 | + if (!empty($number) && !is_numeric($number)) { |
|
2128 | 2128 | return $number; |
2129 | 2129 | } |
2130 | 2130 | |
2131 | - $padd = wpinv_get_option( 'invoice_number_padd' ); |
|
2132 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
2133 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
2131 | + $padd = wpinv_get_option('invoice_number_padd'); |
|
2132 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
2133 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
2134 | 2134 | |
2135 | - $padd = absint( $padd ); |
|
2136 | - $formatted_number = absint( $number ); |
|
2135 | + $padd = absint($padd); |
|
2136 | + $formatted_number = absint($number); |
|
2137 | 2137 | |
2138 | - if ( $padd > 0 ) { |
|
2139 | - $formatted_number = zeroise( $formatted_number, $padd ); |
|
2138 | + if ($padd > 0) { |
|
2139 | + $formatted_number = zeroise($formatted_number, $padd); |
|
2140 | 2140 | } |
2141 | 2141 | |
2142 | 2142 | $formatted_number = $prefix . $formatted_number . $postfix; |
2143 | 2143 | |
2144 | - return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd ); |
|
2144 | + return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd); |
|
2145 | 2145 | } |
2146 | 2146 | |
2147 | -function wpinv_get_next_invoice_number( $type = '' ) { |
|
2148 | - $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type ); |
|
2149 | - if ( null !== $check ) { |
|
2147 | +function wpinv_get_next_invoice_number($type = '') { |
|
2148 | + $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type); |
|
2149 | + if (null !== $check) { |
|
2150 | 2150 | return $check; |
2151 | 2151 | } |
2152 | 2152 | |
2153 | - if ( !wpinv_sequential_number_active() ) { |
|
2153 | + if (!wpinv_sequential_number_active()) { |
|
2154 | 2154 | return false; |
2155 | 2155 | } |
2156 | 2156 | |
2157 | - $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 ); |
|
2158 | - $start = wpinv_get_option( 'invoice_sequence_start', 1 ); |
|
2159 | - if ( !absint( $start ) > 0 ) { |
|
2157 | + $number = $last_number = get_option('wpinv_last_invoice_number', 0); |
|
2158 | + $start = wpinv_get_option('invoice_sequence_start', 1); |
|
2159 | + if (!absint($start) > 0) { |
|
2160 | 2160 | $start = 1; |
2161 | 2161 | } |
2162 | 2162 | $increment_number = true; |
2163 | 2163 | $save_number = false; |
2164 | 2164 | |
2165 | - if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) { |
|
2166 | - $number = wpinv_clean_invoice_number( $number ); |
|
2165 | + if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) { |
|
2166 | + $number = wpinv_clean_invoice_number($number); |
|
2167 | 2167 | } |
2168 | 2168 | |
2169 | - if ( empty( $number ) ) { |
|
2170 | - if ( !( $last_number === 0 || $last_number === '0' ) ) { |
|
2171 | - $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true, true ) ) ) ); |
|
2169 | + if (empty($number)) { |
|
2170 | + if (!($last_number === 0 || $last_number === '0')) { |
|
2171 | + $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true, true)))); |
|
2172 | 2172 | |
2173 | - if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) { |
|
2174 | - if ( is_numeric( $invoice_number ) ) { |
|
2173 | + if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) { |
|
2174 | + if (is_numeric($invoice_number)) { |
|
2175 | 2175 | $number = $invoice_number; |
2176 | 2176 | } else { |
2177 | - $number = wpinv_clean_invoice_number( $invoice_number ); |
|
2177 | + $number = wpinv_clean_invoice_number($invoice_number); |
|
2178 | 2178 | } |
2179 | 2179 | } |
2180 | 2180 | |
2181 | - if ( empty( $number ) ) { |
|
2181 | + if (empty($number)) { |
|
2182 | 2182 | $increment_number = false; |
2183 | 2183 | $number = $start; |
2184 | - $save_number = ( $number - 1 ); |
|
2184 | + $save_number = ($number - 1); |
|
2185 | 2185 | } else { |
2186 | 2186 | $save_number = $number; |
2187 | 2187 | } |
2188 | 2188 | } |
2189 | 2189 | } |
2190 | 2190 | |
2191 | - if ( $start > $number ) { |
|
2191 | + if ($start > $number) { |
|
2192 | 2192 | $increment_number = false; |
2193 | 2193 | $number = $start; |
2194 | - $save_number = ( $number - 1 ); |
|
2194 | + $save_number = ($number - 1); |
|
2195 | 2195 | } |
2196 | 2196 | |
2197 | - if ( $save_number !== false ) { |
|
2198 | - update_option( 'wpinv_last_invoice_number', $save_number ); |
|
2197 | + if ($save_number !== false) { |
|
2198 | + update_option('wpinv_last_invoice_number', $save_number); |
|
2199 | 2199 | } |
2200 | 2200 | |
2201 | - $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number ); |
|
2201 | + $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number); |
|
2202 | 2202 | |
2203 | - if ( $increment_number ) { |
|
2203 | + if ($increment_number) { |
|
2204 | 2204 | $number++; |
2205 | 2205 | } |
2206 | 2206 | |
2207 | - return apply_filters( 'wpinv_get_next_invoice_number', $number ); |
|
2207 | + return apply_filters('wpinv_get_next_invoice_number', $number); |
|
2208 | 2208 | } |
2209 | 2209 | |
2210 | -function wpinv_clean_invoice_number( $number, $type = '' ) { |
|
2211 | - $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type ); |
|
2212 | - if ( null !== $check ) { |
|
2210 | +function wpinv_clean_invoice_number($number, $type = '') { |
|
2211 | + $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type); |
|
2212 | + if (null !== $check) { |
|
2213 | 2213 | return $check; |
2214 | 2214 | } |
2215 | 2215 | |
2216 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
2217 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
2216 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
2217 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
2218 | 2218 | |
2219 | - $number = preg_replace( '/' . $prefix . '/', '', $number, 1 ); |
|
2219 | + $number = preg_replace('/' . $prefix . '/', '', $number, 1); |
|
2220 | 2220 | |
2221 | - $length = strlen( $number ); |
|
2222 | - $postfix_pos = strrpos( $number, $postfix ); |
|
2221 | + $length = strlen($number); |
|
2222 | + $postfix_pos = strrpos($number, $postfix); |
|
2223 | 2223 | |
2224 | - if ( false !== $postfix_pos ) { |
|
2225 | - $number = substr_replace( $number, '', $postfix_pos, $length ); |
|
2224 | + if (false !== $postfix_pos) { |
|
2225 | + $number = substr_replace($number, '', $postfix_pos, $length); |
|
2226 | 2226 | } |
2227 | 2227 | |
2228 | - $number = intval( $number ); |
|
2228 | + $number = intval($number); |
|
2229 | 2229 | |
2230 | - return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix ); |
|
2230 | + return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix); |
|
2231 | 2231 | } |
2232 | 2232 | |
2233 | -function wpinv_save_number_post_saved( $post_ID, $post, $update ) { |
|
2233 | +function wpinv_save_number_post_saved($post_ID, $post, $update) { |
|
2234 | 2234 | global $wpdb; |
2235 | 2235 | |
2236 | - if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) { |
|
2237 | - wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type ); |
|
2236 | + if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) { |
|
2237 | + wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type); |
|
2238 | 2238 | } |
2239 | 2239 | |
2240 | - if ( !$update ) { |
|
2241 | - $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) ); |
|
2242 | - clean_post_cache( $post_ID ); |
|
2240 | + if (!$update) { |
|
2241 | + $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID)); |
|
2242 | + clean_post_cache($post_ID); |
|
2243 | 2243 | } |
2244 | 2244 | } |
2245 | -add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 ); |
|
2245 | +add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3); |
|
2246 | 2246 | |
2247 | -function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) { |
|
2248 | - if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) { |
|
2249 | - wpinv_update_invoice_number( $post_ID, true, $post_after->post_type ); |
|
2247 | +function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) { |
|
2248 | + if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) { |
|
2249 | + wpinv_update_invoice_number($post_ID, true, $post_after->post_type); |
|
2250 | 2250 | } |
2251 | 2251 | } |
2252 | -add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 ); |
|
2252 | +add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3); |
|
2253 | 2253 | |
2254 | -function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) { |
|
2254 | +function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') { |
|
2255 | 2255 | global $wpdb; |
2256 | 2256 | |
2257 | - $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type ); |
|
2258 | - if ( null !== $check ) { |
|
2257 | + $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type); |
|
2258 | + if (null !== $check) { |
|
2259 | 2259 | return $check; |
2260 | 2260 | } |
2261 | 2261 | |
2262 | - if ( wpinv_sequential_number_active() ) { |
|
2262 | + if (wpinv_sequential_number_active()) { |
|
2263 | 2263 | $number = wpinv_get_next_invoice_number(); |
2264 | 2264 | |
2265 | - if ( $save_sequential ) { |
|
2266 | - update_option( 'wpinv_last_invoice_number', $number ); |
|
2265 | + if ($save_sequential) { |
|
2266 | + update_option('wpinv_last_invoice_number', $number); |
|
2267 | 2267 | } |
2268 | 2268 | } else { |
2269 | 2269 | $number = $post_ID; |
2270 | 2270 | } |
2271 | 2271 | |
2272 | - $number = wpinv_format_invoice_number( $number ); |
|
2272 | + $number = wpinv_format_invoice_number($number); |
|
2273 | 2273 | |
2274 | - update_post_meta( $post_ID, '_wpinv_number', $number ); |
|
2274 | + update_post_meta($post_ID, '_wpinv_number', $number); |
|
2275 | 2275 | |
2276 | - $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) ); |
|
2276 | + $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID)); |
|
2277 | 2277 | |
2278 | - clean_post_cache( $post_ID ); |
|
2278 | + clean_post_cache($post_ID); |
|
2279 | 2279 | |
2280 | 2280 | return $number; |
2281 | 2281 | } |
2282 | 2282 | |
2283 | -function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) { |
|
2284 | - return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type ); |
|
2283 | +function wpinv_post_name_prefix($post_type = 'wpi_invoice') { |
|
2284 | + return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type); |
|
2285 | 2285 | } |
2286 | 2286 | |
2287 | -function wpinv_generate_post_name( $post_ID ) { |
|
2288 | - $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) ); |
|
2289 | - $post_name = sanitize_title( $prefix . $post_ID ); |
|
2287 | +function wpinv_generate_post_name($post_ID) { |
|
2288 | + $prefix = wpinv_post_name_prefix(get_post_type($post_ID)); |
|
2289 | + $post_name = sanitize_title($prefix . $post_ID); |
|
2290 | 2290 | |
2291 | - return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix ); |
|
2291 | + return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix); |
|
2292 | 2292 | } |
2293 | 2293 | |
2294 | -function wpinv_is_invoice_viewed( $invoice_id ) { |
|
2295 | - if ( empty( $invoice_id ) ) { |
|
2294 | +function wpinv_is_invoice_viewed($invoice_id) { |
|
2295 | + if (empty($invoice_id)) { |
|
2296 | 2296 | return false; |
2297 | 2297 | } |
2298 | 2298 | |
2299 | - $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true ); |
|
2299 | + $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true); |
|
2300 | 2300 | |
2301 | - return apply_filters( 'wpinv_is_invoice_viewed', 1 === (int)$viewed_meta, $invoice_id ); |
|
2301 | + return apply_filters('wpinv_is_invoice_viewed', 1 === (int) $viewed_meta, $invoice_id); |
|
2302 | 2302 | } |
2303 | 2303 | |
2304 | 2304 | function wpinv_mark_invoice_viewed() { |
2305 | 2305 | |
2306 | - if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) { |
|
2307 | - $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : ''; |
|
2306 | + if (isset($_GET['invoice_key']) || is_singular('wpi_invoice') || is_singular('wpi_quote')) { |
|
2307 | + $invoice_key = isset($_GET['invoice_key']) ? urldecode($_GET['invoice_key']) : ''; |
|
2308 | 2308 | global $post; |
2309 | 2309 | |
2310 | - if(!empty($invoice_key)){ |
|
2310 | + if (!empty($invoice_key)) { |
|
2311 | 2311 | $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
2312 | - } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) { |
|
2312 | + } else if (!empty($post) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) { |
|
2313 | 2313 | $invoice_id = $post->ID; |
2314 | 2314 | } else { |
2315 | 2315 | return; |
@@ -2317,60 +2317,60 @@ discard block |
||
2317 | 2317 | |
2318 | 2318 | $invoice = new WPInv_Invoice($invoice_id); |
2319 | 2319 | |
2320 | - if(!$invoice_id){ |
|
2320 | + if (!$invoice_id) { |
|
2321 | 2321 | return; |
2322 | 2322 | } |
2323 | 2323 | |
2324 | - if ( is_user_logged_in() ) { |
|
2325 | - if ( (int)$invoice->get_user_id() === get_current_user_id() ) { |
|
2326 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2327 | - } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2328 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2324 | + if (is_user_logged_in()) { |
|
2325 | + if ((int) $invoice->get_user_id() === get_current_user_id()) { |
|
2326 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
2327 | + } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
2328 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
2329 | 2329 | } |
2330 | 2330 | } else { |
2331 | - if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2332 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2331 | + if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
2332 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
2333 | 2333 | } |
2334 | 2334 | } |
2335 | 2335 | } |
2336 | 2336 | |
2337 | 2337 | } |
2338 | -add_action( 'template_redirect', 'wpinv_mark_invoice_viewed' ); |
|
2338 | +add_action('template_redirect', 'wpinv_mark_invoice_viewed'); |
|
2339 | 2339 | |
2340 | -function wpinv_get_subscription( $invoice, $by_parent = false ) { |
|
2341 | - if ( empty( $invoice ) ) { |
|
2340 | +function wpinv_get_subscription($invoice, $by_parent = false) { |
|
2341 | + if (empty($invoice)) { |
|
2342 | 2342 | return false; |
2343 | 2343 | } |
2344 | 2344 | |
2345 | - if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
2346 | - $invoice = wpinv_get_invoice( $invoice ); |
|
2345 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
2346 | + $invoice = wpinv_get_invoice($invoice); |
|
2347 | 2347 | } |
2348 | 2348 | |
2349 | - if ( !( is_object( $invoice ) && ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) { |
|
2349 | + if (!(is_object($invoice) && !empty($invoice->ID) && $invoice->is_recurring())) { |
|
2350 | 2350 | return false; |
2351 | 2351 | } |
2352 | 2352 | |
2353 | - $invoice_id = ! $by_parent && ! empty( $invoice->parent_invoice ) ? $invoice->parent_invoice : $invoice->ID; |
|
2353 | + $invoice_id = !$by_parent && !empty($invoice->parent_invoice) ? $invoice->parent_invoice : $invoice->ID; |
|
2354 | 2354 | |
2355 | 2355 | $subs_db = new WPInv_Subscriptions_DB; |
2356 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_id, 'number' => 1 ) ); |
|
2356 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_id, 'number' => 1)); |
|
2357 | 2357 | |
2358 | - if ( ! empty( $subs ) ) { |
|
2359 | - return reset( $subs ); |
|
2358 | + if (!empty($subs)) { |
|
2359 | + return reset($subs); |
|
2360 | 2360 | } |
2361 | 2361 | |
2362 | 2362 | return false; |
2363 | 2363 | } |
2364 | 2364 | |
2365 | -function wpinv_filter_posts_clauses( $clauses, $wp_query ) { |
|
2365 | +function wpinv_filter_posts_clauses($clauses, $wp_query) { |
|
2366 | 2366 | global $wpdb; |
2367 | 2367 | |
2368 | - if ( ! empty( $wp_query->query_vars['orderby'] ) && $wp_query->query_vars['orderby'] == 'invoice_date' ) { |
|
2369 | - if ( !empty( $clauses['join'] ) ) { |
|
2368 | + if (!empty($wp_query->query_vars['orderby']) && $wp_query->query_vars['orderby'] == 'invoice_date') { |
|
2369 | + if (!empty($clauses['join'])) { |
|
2370 | 2370 | $clauses['join'] .= " "; |
2371 | 2371 | } |
2372 | 2372 | |
2373 | - if ( !empty( $clauses['fields'] ) ) { |
|
2373 | + if (!empty($clauses['fields'])) { |
|
2374 | 2374 | $clauses['fields'] .= ", "; |
2375 | 2375 | } |
2376 | 2376 | |
@@ -2381,4 +2381,4 @@ discard block |
||
2381 | 2381 | |
2382 | 2382 | return $clauses; |
2383 | 2383 | } |
2384 | -add_filter( 'posts_clauses', 'wpinv_filter_posts_clauses', 10, 2 ); |
|
2385 | 2384 | \ No newline at end of file |
2385 | +add_filter('posts_clauses', 'wpinv_filter_posts_clauses', 10, 2); |
|
2386 | 2386 | \ No newline at end of file |
@@ -7,28 +7,28 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | class WPInv_Ajax { |
15 | 15 | public static function init() { |
16 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
17 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
16 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
17 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
18 | 18 | self::add_ajax_events(); |
19 | 19 | } |
20 | 20 | |
21 | 21 | public static function define_ajax() { |
22 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
23 | - if ( ! defined( 'DOING_AJAX' ) ) { |
|
24 | - define( 'DOING_AJAX', true ); |
|
22 | + if (!empty($_GET['wpinv-ajax'])) { |
|
23 | + if (!defined('DOING_AJAX')) { |
|
24 | + define('DOING_AJAX', true); |
|
25 | 25 | } |
26 | - if ( ! defined( 'WC_DOING_AJAX' ) ) { |
|
27 | - define( 'WC_DOING_AJAX', true ); |
|
26 | + if (!defined('WC_DOING_AJAX')) { |
|
27 | + define('WC_DOING_AJAX', true); |
|
28 | 28 | } |
29 | 29 | // Turn off display_errors during AJAX events to prevent malformed JSON |
30 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
31 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
30 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
31 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
32 | 32 | } |
33 | 33 | $GLOBALS['wpdb']->hide_errors(); |
34 | 34 | } |
@@ -37,24 +37,24 @@ discard block |
||
37 | 37 | public static function do_wpinv_ajax() { |
38 | 38 | global $wp_query; |
39 | 39 | |
40 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
41 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) ); |
|
40 | + if (!empty($_GET['wpinv-ajax'])) { |
|
41 | + $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax'])); |
|
42 | 42 | } |
43 | 43 | |
44 | - if ( $action = $wp_query->get( 'wpinv-ajax' ) ) { |
|
44 | + if ($action = $wp_query->get('wpinv-ajax')) { |
|
45 | 45 | self::wpinv_ajax_headers(); |
46 | - do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) ); |
|
46 | + do_action('wpinv_ajax_' . sanitize_text_field($action)); |
|
47 | 47 | die(); |
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | 51 | private static function wpinv_ajax_headers() { |
52 | 52 | send_origin_headers(); |
53 | - /** @scrutinizer ignore-unhandled */ @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
54 | - /** @scrutinizer ignore-unhandled */ @header( 'X-Robots-Tag: noindex' ); |
|
53 | + /** @scrutinizer ignore-unhandled */ @header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
54 | + /** @scrutinizer ignore-unhandled */ @header('X-Robots-Tag: noindex'); |
|
55 | 55 | send_nosniff_header(); |
56 | 56 | nocache_headers(); |
57 | - status_header( 200 ); |
|
57 | + status_header(200); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | public static function add_ajax_events() { |
@@ -82,41 +82,41 @@ discard block |
||
82 | 82 | 'buy_items' => true, |
83 | 83 | ); |
84 | 84 | |
85 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
86 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
87 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
85 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
86 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
87 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
88 | 88 | |
89 | - if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) { |
|
90 | - define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 ); |
|
89 | + if (!defined('WPI_AJAX_' . strtoupper($nopriv))) { |
|
90 | + define('WPI_AJAX_' . strtoupper($nopriv), 1); |
|
91 | 91 | } |
92 | 92 | |
93 | - if ( $nopriv ) { |
|
94 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
95 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
93 | + if ($nopriv) { |
|
94 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
95 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
96 | 96 | |
97 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
97 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | 102 | public static function add_note() { |
103 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
103 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
104 | 104 | |
105 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
105 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
106 | 106 | die(-1); |
107 | 107 | } |
108 | 108 | |
109 | - $post_id = absint( $_POST['post_id'] ); |
|
110 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
111 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
109 | + $post_id = absint($_POST['post_id']); |
|
110 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
111 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
112 | 112 | |
113 | 113 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
114 | 114 | |
115 | - if ( $post_id > 0 ) { |
|
116 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
115 | + if ($post_id > 0) { |
|
116 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
117 | 117 | |
118 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
119 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
118 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
119 | + wpinv_get_invoice_note_line_item($note_id); |
|
120 | 120 | } |
121 | 121 | } |
122 | 122 | |
@@ -124,16 +124,16 @@ discard block |
||
124 | 124 | } |
125 | 125 | |
126 | 126 | public static function delete_note() { |
127 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
127 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
128 | 128 | |
129 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
129 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
130 | 130 | die(-1); |
131 | 131 | } |
132 | 132 | |
133 | - $note_id = (int)$_POST['note_id']; |
|
133 | + $note_id = (int) $_POST['note_id']; |
|
134 | 134 | |
135 | - if ( $note_id > 0 ) { |
|
136 | - wp_delete_comment( $note_id, true ); |
|
135 | + if ($note_id > 0) { |
|
136 | + wp_delete_comment($note_id, true); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | die(); |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | } |
147 | 147 | |
148 | 148 | public static function checkout() { |
149 | - if ( ! defined( 'WPINV_CHECKOUT' ) ) { |
|
150 | - define( 'WPINV_CHECKOUT', true ); |
|
149 | + if (!defined('WPINV_CHECKOUT')) { |
|
150 | + define('WPINV_CHECKOUT', true); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | wpinv_process_checkout(); |
@@ -156,53 +156,53 @@ discard block |
||
156 | 156 | |
157 | 157 | public static function add_invoice_item() { |
158 | 158 | global $wpi_userID, $wpinv_ip_address_country; |
159 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
160 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
159 | + check_ajax_referer('invoice-item', '_nonce'); |
|
160 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
161 | 161 | die(-1); |
162 | 162 | } |
163 | 163 | |
164 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
165 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
164 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
165 | + $invoice_id = absint($_POST['invoice_id']); |
|
166 | 166 | |
167 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
167 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
168 | 168 | die(); |
169 | 169 | } |
170 | 170 | |
171 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
172 | - if ( empty( $invoice ) ) { |
|
171 | + $invoice = wpinv_get_invoice($invoice_id); |
|
172 | + if (empty($invoice)) { |
|
173 | 173 | die(); |
174 | 174 | } |
175 | 175 | |
176 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
176 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
177 | 177 | die(); // Don't allow modify items for paid invoice. |
178 | 178 | } |
179 | 179 | |
180 | - if ( !empty( $_POST['user_id'] ) ) { |
|
181 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
180 | + if (!empty($_POST['user_id'])) { |
|
181 | + $wpi_userID = absint($_POST['user_id']); |
|
182 | 182 | } |
183 | 183 | |
184 | - $item = new WPInv_Item( $item_id ); |
|
185 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
184 | + $item = new WPInv_Item($item_id); |
|
185 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
186 | 186 | die(); |
187 | 187 | } |
188 | 188 | |
189 | 189 | // Validate item before adding to invoice because recurring item must be paid individually. |
190 | - if ( !empty( $invoice->cart_details ) ) { |
|
190 | + if (!empty($invoice->cart_details)) { |
|
191 | 191 | $valid = true; |
192 | 192 | |
193 | - if ( $recurring_item = $invoice->get_recurring() ) { |
|
194 | - if ( $recurring_item != $item_id ) { |
|
193 | + if ($recurring_item = $invoice->get_recurring()) { |
|
194 | + if ($recurring_item != $item_id) { |
|
195 | 195 | $valid = false; |
196 | 196 | } |
197 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
197 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
198 | 198 | $valid = false; |
199 | 199 | } |
200 | 200 | |
201 | - if ( !$valid ) { |
|
201 | + if (!$valid) { |
|
202 | 202 | $response = array(); |
203 | 203 | $response['success'] = false; |
204 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
205 | - wp_send_json( $response ); |
|
204 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
205 | + wp_send_json($response); |
|
206 | 206 | } |
207 | 207 | } |
208 | 208 | |
@@ -210,11 +210,11 @@ discard block |
||
210 | 210 | |
211 | 211 | $data = array(); |
212 | 212 | $data['invoice_id'] = $invoice_id; |
213 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
213 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
214 | 214 | |
215 | - wpinv_set_checkout_session( $data ); |
|
215 | + wpinv_set_checkout_session($data); |
|
216 | 216 | |
217 | - $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1; |
|
217 | + $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int) $_POST['qty'] > 0 ? (int) $_POST['qty'] : 1; |
|
218 | 218 | |
219 | 219 | $args = array( |
220 | 220 | 'id' => $item_id, |
@@ -227,21 +227,21 @@ discard block |
||
227 | 227 | 'fees' => array() |
228 | 228 | ); |
229 | 229 | |
230 | - $invoice->add_item( $item_id, $args ); |
|
230 | + $invoice->add_item($item_id, $args); |
|
231 | 231 | $invoice->save(); |
232 | 232 | |
233 | - if ( empty( $_POST['country'] ) ) { |
|
233 | + if (empty($_POST['country'])) { |
|
234 | 234 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
235 | 235 | } |
236 | - if ( empty( $_POST['state'] ) ) { |
|
236 | + if (empty($_POST['state'])) { |
|
237 | 237 | $_POST['state'] = $invoice->state; |
238 | 238 | } |
239 | 239 | |
240 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
241 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
240 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
241 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
242 | 242 | |
243 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
244 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
243 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
244 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
245 | 245 | |
246 | 246 | $wpinv_ip_address_country = $invoice->country; |
247 | 247 | |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | |
250 | 250 | $response = array(); |
251 | 251 | $response['success'] = true; |
252 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
252 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
253 | 253 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
254 | 254 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
255 | 255 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -261,41 +261,41 @@ discard block |
||
261 | 261 | |
262 | 262 | wpinv_set_checkout_session($checkout_session); |
263 | 263 | |
264 | - wp_send_json( $response ); |
|
264 | + wp_send_json($response); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | |
268 | 268 | public static function remove_invoice_item() { |
269 | 269 | global $wpi_userID, $wpinv_ip_address_country; |
270 | 270 | |
271 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
272 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
271 | + check_ajax_referer('invoice-item', '_nonce'); |
|
272 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
273 | 273 | die(-1); |
274 | 274 | } |
275 | 275 | |
276 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
277 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
278 | - $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
276 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
277 | + $invoice_id = absint($_POST['invoice_id']); |
|
278 | + $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
279 | 279 | |
280 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
280 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
281 | 281 | die(); |
282 | 282 | } |
283 | 283 | |
284 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
285 | - if ( empty( $invoice ) ) { |
|
284 | + $invoice = wpinv_get_invoice($invoice_id); |
|
285 | + if (empty($invoice)) { |
|
286 | 286 | die(); |
287 | 287 | } |
288 | 288 | |
289 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
289 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
290 | 290 | die(); // Don't allow modify items for paid invoice. |
291 | 291 | } |
292 | 292 | |
293 | - if ( !empty( $_POST['user_id'] ) ) { |
|
294 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
293 | + if (!empty($_POST['user_id'])) { |
|
294 | + $wpi_userID = absint($_POST['user_id']); |
|
295 | 295 | } |
296 | 296 | |
297 | - $item = new WPInv_Item( $item_id ); |
|
298 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
297 | + $item = new WPInv_Item($item_id); |
|
298 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
299 | 299 | die(); |
300 | 300 | } |
301 | 301 | |
@@ -303,9 +303,9 @@ discard block |
||
303 | 303 | |
304 | 304 | $data = array(); |
305 | 305 | $data['invoice_id'] = $invoice_id; |
306 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
306 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
307 | 307 | |
308 | - wpinv_set_checkout_session( $data ); |
|
308 | + wpinv_set_checkout_session($data); |
|
309 | 309 | |
310 | 310 | $args = array( |
311 | 311 | 'id' => $item_id, |
@@ -313,21 +313,21 @@ discard block |
||
313 | 313 | 'cart_index' => $cart_index |
314 | 314 | ); |
315 | 315 | |
316 | - $invoice->remove_item( $item_id, $args ); |
|
316 | + $invoice->remove_item($item_id, $args); |
|
317 | 317 | $invoice->save(); |
318 | 318 | |
319 | - if ( empty( $_POST['country'] ) ) { |
|
319 | + if (empty($_POST['country'])) { |
|
320 | 320 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
321 | 321 | } |
322 | - if ( empty( $_POST['state'] ) ) { |
|
322 | + if (empty($_POST['state'])) { |
|
323 | 323 | $_POST['state'] = $invoice->state; |
324 | 324 | } |
325 | 325 | |
326 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
327 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
326 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
327 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
328 | 328 | |
329 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
330 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
329 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
330 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
331 | 331 | |
332 | 332 | $wpinv_ip_address_country = $invoice->country; |
333 | 333 | |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | |
336 | 336 | $response = array(); |
337 | 337 | $response['success'] = true; |
338 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
338 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
339 | 339 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
340 | 340 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
341 | 341 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -347,55 +347,55 @@ discard block |
||
347 | 347 | |
348 | 348 | wpinv_set_checkout_session($checkout_session); |
349 | 349 | |
350 | - wp_send_json( $response ); |
|
350 | + wp_send_json($response); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | public static function create_invoice_item() { |
354 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
355 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
354 | + check_ajax_referer('invoice-item', '_nonce'); |
|
355 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
356 | 356 | die(-1); |
357 | 357 | } |
358 | 358 | |
359 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
359 | + $invoice_id = absint($_POST['invoice_id']); |
|
360 | 360 | |
361 | 361 | // Find the item |
362 | - if ( !is_numeric( $invoice_id ) ) { |
|
362 | + if (!is_numeric($invoice_id)) { |
|
363 | 363 | die(); |
364 | 364 | } |
365 | 365 | |
366 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
367 | - if ( empty( $invoice ) ) { |
|
366 | + $invoice = wpinv_get_invoice($invoice_id); |
|
367 | + if (empty($invoice)) { |
|
368 | 368 | die(); |
369 | 369 | } |
370 | 370 | |
371 | 371 | // Validate item before adding to invoice because recurring item must be paid individually. |
372 | - if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) { |
|
372 | + if (!empty($invoice->cart_details) && $invoice->get_recurring()) { |
|
373 | 373 | $response = array(); |
374 | 374 | $response['success'] = false; |
375 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
376 | - wp_send_json( $response ); |
|
375 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
376 | + wp_send_json($response); |
|
377 | 377 | } |
378 | 378 | |
379 | - $save_item = wp_unslash( $_POST['_wpinv_quick'] ); |
|
379 | + $save_item = wp_unslash($_POST['_wpinv_quick']); |
|
380 | 380 | |
381 | 381 | $meta = array(); |
382 | 382 | $meta['type'] = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom'; |
383 | - $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0; |
|
383 | + $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0; |
|
384 | 384 | $meta['vat_rule'] = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital'; |
385 | 385 | $meta['vat_class'] = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard'; |
386 | 386 | |
387 | 387 | $data = array(); |
388 | 388 | $data['post_title'] = sanitize_text_field($save_item['name']); |
389 | 389 | $data['post_status'] = 'publish'; |
390 | - $data['post_excerpt'] = ! empty( $save_item['excerpt'] ) ? wp_kses_post( $save_item['excerpt'] ) : ''; |
|
390 | + $data['post_excerpt'] = !empty($save_item['excerpt']) ? wp_kses_post($save_item['excerpt']) : ''; |
|
391 | 391 | $data['meta'] = $meta; |
392 | 392 | |
393 | 393 | $item = new WPInv_Item(); |
394 | - $item->create( $data ); |
|
394 | + $item->create($data); |
|
395 | 395 | |
396 | - if ( !empty( $item ) ) { |
|
396 | + if (!empty($item)) { |
|
397 | 397 | $_POST['item_id'] = $item->ID; |
398 | - $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1; |
|
398 | + $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int) $save_item['qty'] : 1; |
|
399 | 399 | |
400 | 400 | self::add_invoice_item(); |
401 | 401 | } |
@@ -403,15 +403,15 @@ discard block |
||
403 | 403 | } |
404 | 404 | |
405 | 405 | public static function get_billing_details() { |
406 | - check_ajax_referer( 'get-billing-details', '_nonce' ); |
|
406 | + check_ajax_referer('get-billing-details', '_nonce'); |
|
407 | 407 | |
408 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
408 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
409 | 409 | die(-1); |
410 | 410 | } |
411 | 411 | |
412 | - $user_id = (int)$_POST['user_id']; |
|
412 | + $user_id = (int) $_POST['user_id']; |
|
413 | 413 | $billing_details = wpinv_get_user_address($user_id); |
414 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
414 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
415 | 415 | |
416 | 416 | if (isset($billing_details['user_id'])) { |
417 | 417 | unset($billing_details['user_id']); |
@@ -425,20 +425,20 @@ discard block |
||
425 | 425 | $response['success'] = true; |
426 | 426 | $response['data']['billing_details'] = $billing_details; |
427 | 427 | |
428 | - wp_send_json( $response ); |
|
428 | + wp_send_json($response); |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | public static function admin_recalculate_totals() { |
432 | 432 | global $wpi_userID, $wpinv_ip_address_country; |
433 | 433 | |
434 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
435 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
434 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
435 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
436 | 436 | die(-1); |
437 | 437 | } |
438 | 438 | |
439 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
440 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
441 | - if ( empty( $invoice ) ) { |
|
439 | + $invoice_id = absint($_POST['invoice_id']); |
|
440 | + $invoice = wpinv_get_invoice($invoice_id); |
|
441 | + if (empty($invoice)) { |
|
442 | 442 | die(); |
443 | 443 | } |
444 | 444 | |
@@ -446,29 +446,29 @@ discard block |
||
446 | 446 | |
447 | 447 | $data = array(); |
448 | 448 | $data['invoice_id'] = $invoice_id; |
449 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
449 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
450 | 450 | |
451 | - wpinv_set_checkout_session( $data ); |
|
451 | + wpinv_set_checkout_session($data); |
|
452 | 452 | |
453 | - if ( !empty( $_POST['user_id'] ) ) { |
|
454 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
453 | + if (!empty($_POST['user_id'])) { |
|
454 | + $wpi_userID = absint($_POST['user_id']); |
|
455 | 455 | } |
456 | 456 | |
457 | - if ( empty( $_POST['country'] ) ) { |
|
457 | + if (empty($_POST['country'])) { |
|
458 | 458 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
459 | 459 | } |
460 | 460 | |
461 | 461 | $disable_taxes = 0; |
462 | - if ( ! empty( $_POST['disable_taxes'] ) ) { |
|
462 | + if (!empty($_POST['disable_taxes'])) { |
|
463 | 463 | $disable_taxes = 1; |
464 | 464 | } |
465 | - $invoice->set( 'disable_taxes', $disable_taxes ); |
|
465 | + $invoice->set('disable_taxes', $disable_taxes); |
|
466 | 466 | |
467 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
468 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
469 | - if ( isset( $_POST['state'] ) ) { |
|
470 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
471 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
467 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
468 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
469 | + if (isset($_POST['state'])) { |
|
470 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
471 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | $wpinv_ip_address_country = $invoice->country; |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | |
478 | 478 | $response = array(); |
479 | 479 | $response['success'] = true; |
480 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
480 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
481 | 481 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
482 | 482 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
483 | 483 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -489,25 +489,25 @@ discard block |
||
489 | 489 | |
490 | 490 | wpinv_set_checkout_session($checkout_session); |
491 | 491 | |
492 | - wp_send_json( $response ); |
|
492 | + wp_send_json($response); |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | public static function admin_apply_discount() { |
496 | 496 | global $wpi_userID; |
497 | 497 | |
498 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
499 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
498 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
499 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
500 | 500 | die(-1); |
501 | 501 | } |
502 | 502 | |
503 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
504 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
505 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
503 | + $invoice_id = absint($_POST['invoice_id']); |
|
504 | + $discount_code = sanitize_text_field($_POST['code']); |
|
505 | + if (empty($invoice_id) || empty($discount_code)) { |
|
506 | 506 | die(); |
507 | 507 | } |
508 | 508 | |
509 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
510 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
509 | + $invoice = wpinv_get_invoice($invoice_id); |
|
510 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
511 | 511 | die(); |
512 | 512 | } |
513 | 513 | |
@@ -515,49 +515,49 @@ discard block |
||
515 | 515 | |
516 | 516 | $data = array(); |
517 | 517 | $data['invoice_id'] = $invoice_id; |
518 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
518 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
519 | 519 | |
520 | - wpinv_set_checkout_session( $data ); |
|
520 | + wpinv_set_checkout_session($data); |
|
521 | 521 | |
522 | 522 | $response = array(); |
523 | 523 | $response['success'] = false; |
524 | - $response['msg'] = __( 'This discount is invalid.', 'invoicing' ); |
|
524 | + $response['msg'] = __('This discount is invalid.', 'invoicing'); |
|
525 | 525 | $response['data']['code'] = $discount_code; |
526 | 526 | |
527 | - if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) { |
|
528 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
527 | + if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) { |
|
528 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
529 | 529 | |
530 | 530 | $response['success'] = true; |
531 | - $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' ); |
|
532 | - } else { |
|
531 | + $response['msg'] = __('Discount has been applied successfully.', 'invoicing'); |
|
532 | + } else { |
|
533 | 533 | $errors = wpinv_get_errors(); |
534 | - if ( !empty( $errors['wpinv-discount-error'] ) ) { |
|
534 | + if (!empty($errors['wpinv-discount-error'])) { |
|
535 | 535 | $response['msg'] = $errors['wpinv-discount-error']; |
536 | 536 | } |
537 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
537 | + wpinv_unset_error('wpinv-discount-error'); |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | wpinv_set_checkout_session($checkout_session); |
541 | 541 | |
542 | - wp_send_json( $response ); |
|
542 | + wp_send_json($response); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | public static function admin_remove_discount() { |
546 | 546 | global $wpi_userID; |
547 | 547 | |
548 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
549 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
548 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
549 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
550 | 550 | die(-1); |
551 | 551 | } |
552 | 552 | |
553 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
554 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
555 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
553 | + $invoice_id = absint($_POST['invoice_id']); |
|
554 | + $discount_code = sanitize_text_field($_POST['code']); |
|
555 | + if (empty($invoice_id) || empty($discount_code)) { |
|
556 | 556 | die(); |
557 | 557 | } |
558 | 558 | |
559 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
560 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
559 | + $invoice = wpinv_get_invoice($invoice_id); |
|
560 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
561 | 561 | die(); |
562 | 562 | } |
563 | 563 | |
@@ -565,38 +565,38 @@ discard block |
||
565 | 565 | |
566 | 566 | $data = array(); |
567 | 567 | $data['invoice_id'] = $invoice_id; |
568 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
568 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
569 | 569 | |
570 | - wpinv_set_checkout_session( $data ); |
|
570 | + wpinv_set_checkout_session($data); |
|
571 | 571 | |
572 | 572 | $response = array(); |
573 | 573 | $response['success'] = false; |
574 | 574 | $response['msg'] = NULL; |
575 | 575 | |
576 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
576 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
577 | 577 | $response['success'] = true; |
578 | - $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' ); |
|
578 | + $response['msg'] = __('Discount has been removed successfully.', 'invoicing'); |
|
579 | 579 | |
580 | 580 | wpinv_set_checkout_session($checkout_session); |
581 | 581 | |
582 | - wp_send_json( $response ); |
|
582 | + wp_send_json($response); |
|
583 | 583 | } |
584 | 584 | |
585 | 585 | public static function check_email() { |
586 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
587 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
586 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
587 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
588 | 588 | die(-1); |
589 | 589 | } |
590 | 590 | |
591 | - $email = sanitize_text_field( $_POST['email'] ); |
|
591 | + $email = sanitize_text_field($_POST['email']); |
|
592 | 592 | |
593 | 593 | $response = array(); |
594 | - if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) { |
|
594 | + if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) { |
|
595 | 595 | $user_id = $user_data->ID; |
596 | 596 | $user_login = $user_data->user_login; |
597 | 597 | $display_name = $user_data->display_name ? $user_data->display_name : $user_login; |
598 | 598 | $billing_details = wpinv_get_user_address($user_id); |
599 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
599 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
600 | 600 | |
601 | 601 | if (isset($billing_details['user_id'])) { |
602 | 602 | unset($billing_details['user_id']); |
@@ -612,54 +612,54 @@ discard block |
||
612 | 612 | $response['data']['billing_details'] = $billing_details; |
613 | 613 | } |
614 | 614 | |
615 | - wp_send_json( $response ); |
|
615 | + wp_send_json($response); |
|
616 | 616 | } |
617 | 617 | |
618 | 618 | public static function run_tool() { |
619 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
620 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
619 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
620 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
621 | 621 | die(-1); |
622 | 622 | } |
623 | 623 | |
624 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
624 | + $tool = sanitize_text_field($_POST['tool']); |
|
625 | 625 | |
626 | - do_action( 'wpinv_run_tool' ); |
|
626 | + do_action('wpinv_run_tool'); |
|
627 | 627 | |
628 | - if ( !empty( $tool ) ) { |
|
629 | - do_action( 'wpinv_tool_' . $tool ); |
|
628 | + if (!empty($tool)) { |
|
629 | + do_action('wpinv_tool_' . $tool); |
|
630 | 630 | } |
631 | 631 | } |
632 | 632 | |
633 | 633 | public static function apply_discount() { |
634 | 634 | global $wpi_userID; |
635 | 635 | |
636 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
636 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
637 | 637 | |
638 | 638 | $response = array(); |
639 | 639 | |
640 | - if ( isset( $_POST['code'] ) ) { |
|
641 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
640 | + if (isset($_POST['code'])) { |
|
641 | + $discount_code = sanitize_text_field($_POST['code']); |
|
642 | 642 | |
643 | 643 | $response['success'] = false; |
644 | 644 | $response['msg'] = ''; |
645 | 645 | $response['data']['code'] = $discount_code; |
646 | 646 | |
647 | 647 | $invoice = wpinv_get_invoice_cart(); |
648 | - if ( empty( $invoice->ID ) ) { |
|
649 | - $response['msg'] = __( 'Invalid checkout request.', 'invoicing' ); |
|
650 | - wp_send_json( $response ); |
|
648 | + if (empty($invoice->ID)) { |
|
649 | + $response['msg'] = __('Invalid checkout request.', 'invoicing'); |
|
650 | + wp_send_json($response); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | $wpi_userID = $invoice->get_user_id(); |
654 | 654 | |
655 | - if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) { |
|
656 | - $discount = wpinv_get_discount_by_code( $discount_code ); |
|
657 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
658 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
659 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
660 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
655 | + if (wpinv_is_discount_valid($discount_code, $wpi_userID)) { |
|
656 | + $discount = wpinv_get_discount_by_code($discount_code); |
|
657 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
658 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
659 | + $total = wpinv_get_cart_total(null, $discounts); |
|
660 | + $cart_totals = wpinv_recalculate_tax(true); |
|
661 | 661 | |
662 | - if ( !empty( $cart_totals ) ) { |
|
662 | + if (!empty($cart_totals)) { |
|
663 | 663 | $response['success'] = true; |
664 | 664 | $response['data'] = $cart_totals; |
665 | 665 | $response['data']['code'] = $discount_code; |
@@ -668,29 +668,29 @@ discard block |
||
668 | 668 | } |
669 | 669 | } else { |
670 | 670 | $errors = wpinv_get_errors(); |
671 | - $response['msg'] = $errors['wpinv-discount-error']; |
|
672 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
671 | + $response['msg'] = $errors['wpinv-discount-error']; |
|
672 | + wpinv_unset_error('wpinv-discount-error'); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | // Allow for custom discount code handling |
676 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
676 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
677 | 677 | } |
678 | 678 | |
679 | - wp_send_json( $response ); |
|
679 | + wp_send_json($response); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | public static function remove_discount() { |
683 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
683 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
684 | 684 | |
685 | 685 | $response = array(); |
686 | 686 | |
687 | - if ( isset( $_POST['code'] ) ) { |
|
688 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
689 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
690 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
691 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
687 | + if (isset($_POST['code'])) { |
|
688 | + $discount_code = sanitize_text_field($_POST['code']); |
|
689 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
690 | + $total = wpinv_get_cart_total(null, $discounts); |
|
691 | + $cart_totals = wpinv_recalculate_tax(true); |
|
692 | 692 | |
693 | - if ( !empty( $cart_totals ) ) { |
|
693 | + if (!empty($cart_totals)) { |
|
694 | 694 | $response['success'] = true; |
695 | 695 | $response['data'] = $cart_totals; |
696 | 696 | $response['data']['code'] = $discount_code; |
@@ -699,10 +699,10 @@ discard block |
||
699 | 699 | } |
700 | 700 | |
701 | 701 | // Allow for custom discount code handling |
702 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
702 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
703 | 703 | } |
704 | 704 | |
705 | - wp_send_json( $response ); |
|
705 | + wp_send_json($response); |
|
706 | 706 | } |
707 | 707 | |
708 | 708 | /** |
@@ -711,30 +711,30 @@ discard block |
||
711 | 711 | public static function get_payment_form() { |
712 | 712 | |
713 | 713 | // Check nonce. |
714 | - if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'getpaid_ajax_form' ) ) { |
|
715 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
714 | + if (!isset($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], 'getpaid_ajax_form')) { |
|
715 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
716 | 716 | exit; |
717 | 717 | } |
718 | 718 | |
719 | 719 | // Is the request set up correctly? |
720 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
720 | + if (empty($_GET['form']) && empty($_GET['item'])) { |
|
721 | 721 | echo aui()->alert( |
722 | 722 | array( |
723 | 723 | 'type' => 'warning', |
724 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
724 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
725 | 725 | ) |
726 | 726 | ); |
727 | 727 | exit; |
728 | 728 | } |
729 | 729 | |
730 | 730 | // Payment form or button? |
731 | - if ( ! empty( $_GET['form'] ) ) { |
|
732 | - echo getpaid_display_payment_form( $_GET['form'] ); |
|
733 | - } else if( $_GET['invoice'] ) { |
|
734 | - echo getpaid_display_invoice_payment_form( $_GET['invoice'] ); |
|
731 | + if (!empty($_GET['form'])) { |
|
732 | + echo getpaid_display_payment_form($_GET['form']); |
|
733 | + } else if ($_GET['invoice']) { |
|
734 | + echo getpaid_display_invoice_payment_form($_GET['invoice']); |
|
735 | 735 | } else { |
736 | - $items = getpaid_convert_items_to_array( $_GET['item'] ); |
|
737 | - echo getpaid_display_item_payment_form( $items ); |
|
736 | + $items = getpaid_convert_items_to_array($_GET['item']); |
|
737 | + echo getpaid_display_item_payment_form($items); |
|
738 | 738 | } |
739 | 739 | |
740 | 740 | exit; |
@@ -750,72 +750,72 @@ discard block |
||
750 | 750 | global $invoicing, $wpi_checkout_id, $cart_total; |
751 | 751 | |
752 | 752 | // Check nonce. |
753 | - if ( ! isset( $_POST['wpinv_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_payment_form'], 'wpinv_payment_form' ) ) { |
|
754 | - wp_send_json_error( __( 'Security checks failed.', 'invoicing' ) ); |
|
753 | + if (!isset($_POST['wpinv_payment_form']) || !wp_verify_nonce($_POST['wpinv_payment_form'], 'wpinv_payment_form')) { |
|
754 | + wp_send_json_error(__('Security checks failed.', 'invoicing')); |
|
755 | 755 | } |
756 | 756 | |
757 | 757 | // Prepare submitted data... |
758 | - $data = wp_unslash( $_POST ); |
|
758 | + $data = wp_unslash($_POST); |
|
759 | 759 | |
760 | 760 | // ... form fields... |
761 | - if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) { |
|
762 | - wp_send_json_error( __( 'This payment form is no longer active.', 'invoicing' ) ); |
|
761 | + if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) { |
|
762 | + wp_send_json_error(__('This payment form is no longer active.', 'invoicing')); |
|
763 | 763 | } |
764 | 764 | |
765 | - if ( empty( $data['billing_email'] ) || ! is_email( $data['billing_email'] ) ) { |
|
766 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
765 | + if (empty($data['billing_email']) || !is_email($data['billing_email'])) { |
|
766 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
767 | 767 | } |
768 | 768 | |
769 | 769 | $prepared = array( |
770 | - 'billing_email' => sanitize_email( $data['billing_email'] ), |
|
771 | - __( 'Billing Email', 'invoicing' ) => sanitize_email( $data['billing_email'] ), |
|
772 | - __( 'Form Id', 'invoicing' ) => absint( $data['form_id'] ), |
|
770 | + 'billing_email' => sanitize_email($data['billing_email']), |
|
771 | + __('Billing Email', 'invoicing') => sanitize_email($data['billing_email']), |
|
772 | + __('Form Id', 'invoicing') => absint($data['form_id']), |
|
773 | 773 | ); |
774 | 774 | |
775 | 775 | // Do we have a discount? |
776 | 776 | $discount = 0; |
777 | - if ( ! empty( $data['discount'] ) ) { |
|
777 | + if (!empty($data['discount'])) { |
|
778 | 778 | |
779 | 779 | // Validate discount. |
780 | - $discount = self::payment_form_validate_discount( $data ); |
|
780 | + $discount = self::payment_form_validate_discount($data); |
|
781 | 781 | |
782 | - if ( is_string( $discount ) ){ |
|
783 | - wp_send_json_error( $discount ); |
|
782 | + if (is_string($discount)) { |
|
783 | + wp_send_json_error($discount); |
|
784 | 784 | } |
785 | 785 | |
786 | - if ( is_array( $discount ) ){ |
|
787 | - $discount = $discount[ 'discount' ]; |
|
786 | + if (is_array($discount)) { |
|
787 | + $discount = $discount['discount']; |
|
788 | 788 | } |
789 | 789 | |
790 | - if ( ! $discount ) { |
|
790 | + if (!$discount) { |
|
791 | 791 | $discount = 0; |
792 | 792 | } |
793 | 793 | |
794 | 794 | } |
795 | 795 | |
796 | - $fields = $invoicing->form_elements->get_form_elements( $data['form_id'] ); |
|
796 | + $fields = $invoicing->form_elements->get_form_elements($data['form_id']); |
|
797 | 797 | |
798 | 798 | // ... and form items. |
799 | - if ( ! empty( $data['invoice_id'] ) ) { |
|
800 | - $invoice = wpinv_get_invoice( $data['invoice_id'] ); |
|
799 | + if (!empty($data['invoice_id'])) { |
|
800 | + $invoice = wpinv_get_invoice($data['invoice_id']); |
|
801 | 801 | |
802 | - if ( empty( $invoice ) ) { |
|
803 | - wp_send_json_error( __( 'Invalid invoice.', 'invoicing' ) ); |
|
802 | + if (empty($invoice)) { |
|
803 | + wp_send_json_error(__('Invalid invoice.', 'invoicing')); |
|
804 | 804 | } |
805 | 805 | |
806 | - if ( $invoice->is_paid() ) { |
|
807 | - wp_send_json_error( __( 'This invoice has already been paid.', 'invoicing' ) ); |
|
806 | + if ($invoice->is_paid()) { |
|
807 | + wp_send_json_error(__('This invoice has already been paid.', 'invoicing')); |
|
808 | 808 | } |
809 | 809 | |
810 | - $items = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice ); |
|
810 | + $items = $invoicing->form_elements->convert_checkout_items($invoice->cart_details, $invoice); |
|
811 | 811 | |
812 | 812 | } else { |
813 | 813 | |
814 | - if ( isset( $data['form_items'] ) ) { |
|
815 | - $items = getpaid_convert_items_to_array( $data['form_items'] ); |
|
816 | - $items = $invoicing->form_elements->convert_normal_items( $items ); |
|
814 | + if (isset($data['form_items'])) { |
|
815 | + $items = getpaid_convert_items_to_array($data['form_items']); |
|
816 | + $items = $invoicing->form_elements->convert_normal_items($items); |
|
817 | 817 | } else { |
818 | - $items = $invoicing->form_elements->get_form_items( $data['form_id'] ); |
|
818 | + $items = $invoicing->form_elements->get_form_items($data['form_id']); |
|
819 | 819 | } |
820 | 820 | |
821 | 821 | $invoice = 0; |
@@ -825,48 +825,48 @@ discard block |
||
825 | 825 | $address_fields = array(); |
826 | 826 | $has_recurring = false; |
827 | 827 | |
828 | - if ( ! empty( $data['wpinv-items'] ) ) { |
|
828 | + if (!empty($data['wpinv-items'])) { |
|
829 | 829 | |
830 | - $selected_items = wpinv_clean( $data['wpinv-items'] ); |
|
830 | + $selected_items = wpinv_clean($data['wpinv-items']); |
|
831 | 831 | |
832 | - foreach ( $items as $item ) { |
|
832 | + foreach ($items as $item) { |
|
833 | 833 | |
834 | - if ( ! empty( $item['required'] ) && ! isset( $selected_items[ $item['id'] ] ) ) { |
|
835 | - wp_send_json_error( __( 'A required item is missing.', 'invoicing' ) ); |
|
834 | + if (!empty($item['required']) && !isset($selected_items[$item['id']])) { |
|
835 | + wp_send_json_error(__('A required item is missing.', 'invoicing')); |
|
836 | 836 | } |
837 | 837 | |
838 | - if ( ! isset( $selected_items[ $item['id'] ] ) ) { |
|
838 | + if (!isset($selected_items[$item['id']])) { |
|
839 | 839 | continue; |
840 | 840 | } |
841 | 841 | |
842 | - if ( ! empty( $item['recurring'] ) ) { |
|
843 | - $has_recurring = true; |
|
842 | + if (!empty($item['recurring'])) { |
|
843 | + $has_recurring = true; |
|
844 | 844 | } |
845 | 845 | |
846 | - $quantity = empty( $item['quantity'] ) ? 1 : absint( $item['quantity'] ); |
|
846 | + $quantity = empty($item['quantity']) ? 1 : absint($item['quantity']); |
|
847 | 847 | |
848 | - if ( ! empty( $item['allow_quantities'] ) && ! empty( $data["wpinv-item-{$item['id']}-quantity"] ) ) { |
|
848 | + if (!empty($item['allow_quantities']) && !empty($data["wpinv-item-{$item['id']}-quantity"])) { |
|
849 | 849 | |
850 | - $_quantity = intval( $data["wpinv-item-{$item['id']}-quantity"] ); |
|
850 | + $_quantity = intval($data["wpinv-item-{$item['id']}-quantity"]); |
|
851 | 851 | |
852 | - if ( ! empty( $_quantity ) ) { |
|
852 | + if (!empty($_quantity)) { |
|
853 | 853 | $quantity = $_quantity; |
854 | 854 | } |
855 | 855 | } |
856 | 856 | |
857 | 857 | // Custom pricing. |
858 | - if ( ! empty( $item['custom_price'] ) ) { |
|
858 | + if (!empty($item['custom_price'])) { |
|
859 | 859 | |
860 | - $minimum_price = wpinv_sanitize_amount( $item['minimum_price'] ); |
|
861 | - $set_price = wpinv_sanitize_amount( $selected_items[ $item['id'] ] ); |
|
860 | + $minimum_price = wpinv_sanitize_amount($item['minimum_price']); |
|
861 | + $set_price = wpinv_sanitize_amount($selected_items[$item['id']]); |
|
862 | 862 | |
863 | - if ( $set_price < $minimum_price ) { |
|
864 | - wp_send_json_error( __( 'The provided amount is less than the minimum allowed value.', 'invoicing' ) ); |
|
863 | + if ($set_price < $minimum_price) { |
|
864 | + wp_send_json_error(__('The provided amount is less than the minimum allowed value.', 'invoicing')); |
|
865 | 865 | } |
866 | 866 | |
867 | 867 | $prepared_items[] = array( |
868 | 868 | 'id' =>$item['id'], |
869 | - 'item_price' => wpinv_sanitize_amount( $item['price'] ), |
|
869 | + 'item_price' => wpinv_sanitize_amount($item['price']), |
|
870 | 870 | 'custom_price' => $set_price, |
871 | 871 | 'name' => $item['title'], |
872 | 872 | 'quantity' => $quantity, |
@@ -876,8 +876,8 @@ discard block |
||
876 | 876 | |
877 | 877 | $prepared_items[] = array( |
878 | 878 | 'id' => $item['id'], |
879 | - 'item_price' => wpinv_sanitize_amount( $item['price'] ), |
|
880 | - 'custom_price' => wpinv_sanitize_amount( $item['price'] ), |
|
879 | + 'item_price' => wpinv_sanitize_amount($item['price']), |
|
880 | + 'custom_price' => wpinv_sanitize_amount($item['price']), |
|
881 | 881 | 'name' => $item['title'], |
882 | 882 | 'quantity' => $quantity, |
883 | 883 | ); |
@@ -888,76 +888,76 @@ discard block |
||
888 | 888 | |
889 | 889 | } else { |
890 | 890 | |
891 | - wp_send_json_error( __( 'You have not selected any items.', 'invoicing' ) ); |
|
891 | + wp_send_json_error(__('You have not selected any items.', 'invoicing')); |
|
892 | 892 | |
893 | 893 | } |
894 | 894 | |
895 | - if ( $has_recurring && 1 != count( $prepared_items ) ) { |
|
896 | - wp_send_json_error( __( 'Recurring items should be bought individually.', 'invoicing' ) ); |
|
895 | + if ($has_recurring && 1 != count($prepared_items)) { |
|
896 | + wp_send_json_error(__('Recurring items should be bought individually.', 'invoicing')); |
|
897 | 897 | } |
898 | 898 | |
899 | 899 | // Are all required fields provided? |
900 | - foreach ( $fields as $field ) { |
|
900 | + foreach ($fields as $field) { |
|
901 | 901 | |
902 | - if ( ! empty( $field['premade'] ) ) { |
|
902 | + if (!empty($field['premade'])) { |
|
903 | 903 | continue; |
904 | 904 | } |
905 | 905 | |
906 | - if ( ! empty( $field['required'] ) && empty( $data[ $field['id'] ] ) ) { |
|
907 | - wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) ); |
|
906 | + if (!empty($field['required']) && empty($data[$field['id']])) { |
|
907 | + wp_send_json_error(__('Some required fields have not been filled.', 'invoicing')); |
|
908 | 908 | } |
909 | 909 | |
910 | - if ( $field['type'] == 'address' ) { |
|
910 | + if ($field['type'] == 'address') { |
|
911 | 911 | |
912 | - foreach ( $field['fields'] as $address_field ) { |
|
912 | + foreach ($field['fields'] as $address_field) { |
|
913 | 913 | |
914 | - if ( empty( $address_field['visible'] ) ) { |
|
914 | + if (empty($address_field['visible'])) { |
|
915 | 915 | continue; |
916 | 916 | } |
917 | 917 | |
918 | - if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) { |
|
919 | - wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) ); |
|
918 | + if (!empty($address_field['required']) && empty($data[$address_field['name']])) { |
|
919 | + wp_send_json_error(__('Some required fields have not been filled.', 'invoicing')); |
|
920 | 920 | } |
921 | 921 | |
922 | - if ( isset( $data[ $address_field['name'] ] ) ) { |
|
923 | - $label = str_replace( 'wpinv_', '', $address_field['name'] ); |
|
924 | - $address_fields[ $label ] = wpinv_clean( $data[ $address_field['name'] ] ); |
|
922 | + if (isset($data[$address_field['name']])) { |
|
923 | + $label = str_replace('wpinv_', '', $address_field['name']); |
|
924 | + $address_fields[$label] = wpinv_clean($data[$address_field['name']]); |
|
925 | 925 | } |
926 | 926 | |
927 | 927 | } |
928 | 928 | |
929 | - } else if ( isset( $data[ $field['id'] ] ) ) { |
|
929 | + } else if (isset($data[$field['id']])) { |
|
930 | 930 | $label = $field['id']; |
931 | 931 | |
932 | - if ( isset( $field['label'] ) ) { |
|
932 | + if (isset($field['label'])) { |
|
933 | 933 | $label = $field['label']; |
934 | 934 | } |
935 | 935 | |
936 | - $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] ); |
|
936 | + $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]); |
|
937 | 937 | } |
938 | 938 | |
939 | 939 | } |
940 | 940 | |
941 | - $user = get_user_by( 'email', $prepared['billing_email'] ); |
|
941 | + $user = get_user_by('email', $prepared['billing_email']); |
|
942 | 942 | |
943 | - if ( empty( $user ) ) { |
|
944 | - $user = wpinv_create_user( $prepared['billing_email'] ); |
|
943 | + if (empty($user)) { |
|
944 | + $user = wpinv_create_user($prepared['billing_email']); |
|
945 | 945 | } |
946 | 946 | |
947 | - if ( is_wp_error( $user ) ) { |
|
948 | - wp_send_json_error( $user->get_error_message() ); |
|
947 | + if (is_wp_error($user)) { |
|
948 | + wp_send_json_error($user->get_error_message()); |
|
949 | 949 | } |
950 | 950 | |
951 | - if ( is_numeric( $user ) ) { |
|
952 | - $user = get_user_by( 'id', $user ); |
|
951 | + if (is_numeric($user)) { |
|
952 | + $user = get_user_by('id', $user); |
|
953 | 953 | } |
954 | 954 | |
955 | - if ( $discount ) { |
|
956 | - $address_fields['discount'] = array( $data['discount'] ); |
|
955 | + if ($discount) { |
|
956 | + $address_fields['discount'] = array($data['discount']); |
|
957 | 957 | } |
958 | 958 | |
959 | 959 | // Create the invoice. |
960 | - if ( empty( $invoice ) ) { |
|
960 | + if (empty($invoice)) { |
|
961 | 961 | |
962 | 962 | $invoice = wpinv_insert_invoice( |
963 | 963 | array( |
@@ -984,34 +984,34 @@ discard block |
||
984 | 984 | |
985 | 985 | } |
986 | 986 | |
987 | - if ( is_wp_error( $invoice ) ) { |
|
988 | - wp_send_json_error( $invoice->get_error_message() ); |
|
987 | + if (is_wp_error($invoice)) { |
|
988 | + wp_send_json_error($invoice->get_error_message()); |
|
989 | 989 | } |
990 | 990 | |
991 | - if ( empty( $invoice ) ) { |
|
992 | - wp_send_json_error( __( 'Could not create your invoice.', 'invoicing' ) ); |
|
991 | + if (empty($invoice)) { |
|
992 | + wp_send_json_error(__('Could not create your invoice.', 'invoicing')); |
|
993 | 993 | } |
994 | 994 | |
995 | - unset( $prepared['billing_email'] ); |
|
996 | - update_post_meta( $invoice->ID, 'payment_form_data', $prepared ); |
|
995 | + unset($prepared['billing_email']); |
|
996 | + update_post_meta($invoice->ID, 'payment_form_data', $prepared); |
|
997 | 997 | |
998 | 998 | $wpi_checkout_id = $invoice->ID; |
999 | 999 | $cart_total = wpinv_price( |
1000 | 1000 | wpinv_format_amount( |
1001 | - wpinv_get_cart_total( $invoice->get_cart_details(), NULL, $invoice ) ), |
|
1001 | + wpinv_get_cart_total($invoice->get_cart_details(), NULL, $invoice) ), |
|
1002 | 1002 | $invoice->get_currency() |
1003 | 1003 | ); |
1004 | 1004 | |
1005 | 1005 | $data = array(); |
1006 | 1006 | $data['invoice_id'] = $invoice->ID; |
1007 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
1007 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
1008 | 1008 | |
1009 | - wpinv_set_checkout_session( $data ); |
|
1010 | - add_filter( 'wp_redirect', array( $invoicing->form_elements, 'send_redirect_response' ) ); |
|
1011 | - add_action( 'wpinv_pre_send_back_to_checkout', array( $invoicing->form_elements, 'checkout_error' ) ); |
|
1009 | + wpinv_set_checkout_session($data); |
|
1010 | + add_filter('wp_redirect', array($invoicing->form_elements, 'send_redirect_response')); |
|
1011 | + add_action('wpinv_pre_send_back_to_checkout', array($invoicing->form_elements, 'checkout_error')); |
|
1012 | 1012 | |
1013 | - if ( ! defined( 'WPINV_CHECKOUT' ) ) { |
|
1014 | - define( 'WPINV_CHECKOUT', true ); |
|
1013 | + if (!defined('WPINV_CHECKOUT')) { |
|
1014 | + define('WPINV_CHECKOUT', true); |
|
1015 | 1015 | } |
1016 | 1016 | |
1017 | 1017 | wpinv_process_checkout(); |
@@ -1029,51 +1029,51 @@ discard block |
||
1029 | 1029 | public static function get_payment_form_states_field() { |
1030 | 1030 | global $invoicing; |
1031 | 1031 | |
1032 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
1032 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
1033 | 1033 | exit; |
1034 | 1034 | } |
1035 | 1035 | |
1036 | - $elements = $invoicing->form_elements->get_form_elements( $_GET['form'] ); |
|
1036 | + $elements = $invoicing->form_elements->get_form_elements($_GET['form']); |
|
1037 | 1037 | |
1038 | - if ( empty( $elements ) ) { |
|
1038 | + if (empty($elements)) { |
|
1039 | 1039 | exit; |
1040 | 1040 | } |
1041 | 1041 | |
1042 | 1042 | $address_fields = array(); |
1043 | - foreach ( $elements as $element ) { |
|
1044 | - if ( 'address' === $element['type'] ) { |
|
1043 | + foreach ($elements as $element) { |
|
1044 | + if ('address' === $element['type']) { |
|
1045 | 1045 | $address_fields = $element; |
1046 | 1046 | break; |
1047 | 1047 | } |
1048 | 1048 | } |
1049 | 1049 | |
1050 | - if ( empty( $address_fields ) ) { |
|
1050 | + if (empty($address_fields)) { |
|
1051 | 1051 | exit; |
1052 | 1052 | } |
1053 | 1053 | |
1054 | - foreach( $address_fields['fields'] as $address_field ) { |
|
1054 | + foreach ($address_fields['fields'] as $address_field) { |
|
1055 | 1055 | |
1056 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
1056 | + if ('wpinv_state' == $address_field['name']) { |
|
1057 | 1057 | |
1058 | 1058 | $label = $address_field['label']; |
1059 | 1059 | |
1060 | - if ( ! empty( $address_field['required'] ) ) { |
|
1060 | + if (!empty($address_field['required'])) { |
|
1061 | 1061 | $label .= "<span class='text-danger'> *</span>"; |
1062 | 1062 | } |
1063 | 1063 | |
1064 | - $states = wpinv_get_country_states( $_GET['country'] ); |
|
1064 | + $states = wpinv_get_country_states($_GET['country']); |
|
1065 | 1065 | |
1066 | - if ( ! empty( $states ) ) { |
|
1066 | + if (!empty($states)) { |
|
1067 | 1067 | |
1068 | 1068 | $html = aui()->select( |
1069 | 1069 | array( |
1070 | 1070 | 'options' => $states, |
1071 | - 'name' => esc_attr( $address_field['name'] ), |
|
1072 | - 'id' => esc_attr( $address_field['name'] ), |
|
1073 | - 'placeholder' => esc_attr( $address_field['placeholder'] ), |
|
1071 | + 'name' => esc_attr($address_field['name']), |
|
1072 | + 'id' => esc_attr($address_field['name']), |
|
1073 | + 'placeholder' => esc_attr($address_field['placeholder']), |
|
1074 | 1074 | 'required' => (bool) $address_field['required'], |
1075 | 1075 | 'no_wrap' => true, |
1076 | - 'label' => wp_kses_post( $label ), |
|
1076 | + 'label' => wp_kses_post($label), |
|
1077 | 1077 | 'select2' => false, |
1078 | 1078 | ) |
1079 | 1079 | ); |
@@ -1082,10 +1082,10 @@ discard block |
||
1082 | 1082 | |
1083 | 1083 | $html = aui()->input( |
1084 | 1084 | array( |
1085 | - 'name' => esc_attr( $address_field['name'] ), |
|
1086 | - 'id' => esc_attr( $address_field['name'] ), |
|
1085 | + 'name' => esc_attr($address_field['name']), |
|
1086 | + 'id' => esc_attr($address_field['name']), |
|
1087 | 1087 | 'required' => (bool) $address_field['required'], |
1088 | - 'label' => wp_kses_post( $label ), |
|
1088 | + 'label' => wp_kses_post($label), |
|
1089 | 1089 | 'no_wrap' => true, |
1090 | 1090 | 'type' => 'text', |
1091 | 1091 | ) |
@@ -1093,7 +1093,7 @@ discard block |
||
1093 | 1093 | |
1094 | 1094 | } |
1095 | 1095 | |
1096 | - wp_send_json_success( str_replace( 'sr-only', '', $html ) ); |
|
1096 | + wp_send_json_success(str_replace('sr-only', '', $html)); |
|
1097 | 1097 | exit; |
1098 | 1098 | |
1099 | 1099 | } |
@@ -1112,51 +1112,51 @@ discard block |
||
1112 | 1112 | global $invoicing; |
1113 | 1113 | |
1114 | 1114 | // Check nonce. |
1115 | - check_ajax_referer( 'wpinv_payment_form', 'wpinv_payment_form' ); |
|
1115 | + check_ajax_referer('wpinv_payment_form', 'wpinv_payment_form'); |
|
1116 | 1116 | |
1117 | 1117 | // Prepare submitted data... |
1118 | - $data = wp_unslash( $_POST ); |
|
1118 | + $data = wp_unslash($_POST); |
|
1119 | 1119 | |
1120 | 1120 | // ... form fields... |
1121 | - if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) { |
|
1121 | + if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) { |
|
1122 | 1122 | exit; |
1123 | 1123 | } |
1124 | 1124 | |
1125 | 1125 | // Do we have a discount? |
1126 | - if ( ! empty( $data['discount'] ) ) { |
|
1126 | + if (!empty($data['discount'])) { |
|
1127 | 1127 | |
1128 | 1128 | // Validate discount. |
1129 | - $discount = self::payment_form_validate_discount( $data ); |
|
1130 | - |
|
1131 | - if ( is_array( $discount ) ){ |
|
1132 | - $data['total'] = wpinv_price( wpinv_format_amount( $discount['total'] ) ); |
|
1133 | - $data['sub_total'] = wpinv_price( wpinv_format_amount( $discount['sub_total'] ) ); |
|
1134 | - $data['discount'] = wpinv_price( wpinv_format_amount( $discount['discount'] ) ); |
|
1135 | - $data['tax'] = wpinv_price( wpinv_format_amount( $discount['tax'] ) ); |
|
1136 | - wp_send_json_success( $discount ); |
|
1129 | + $discount = self::payment_form_validate_discount($data); |
|
1130 | + |
|
1131 | + if (is_array($discount)) { |
|
1132 | + $data['total'] = wpinv_price(wpinv_format_amount($discount['total'])); |
|
1133 | + $data['sub_total'] = wpinv_price(wpinv_format_amount($discount['sub_total'])); |
|
1134 | + $data['discount'] = wpinv_price(wpinv_format_amount($discount['discount'])); |
|
1135 | + $data['tax'] = wpinv_price(wpinv_format_amount($discount['tax'])); |
|
1136 | + wp_send_json_success($discount); |
|
1137 | 1137 | } |
1138 | 1138 | |
1139 | 1139 | } |
1140 | 1140 | |
1141 | 1141 | // For existing invoices. |
1142 | - if ( ! empty( $data['invoice_id'] ) ) { |
|
1143 | - $invoice = wpinv_get_invoice( $data['invoice_id'] ); |
|
1142 | + if (!empty($data['invoice_id'])) { |
|
1143 | + $invoice = wpinv_get_invoice($data['invoice_id']); |
|
1144 | 1144 | |
1145 | - if ( empty( $invoice ) ) { |
|
1145 | + if (empty($invoice)) { |
|
1146 | 1146 | exit; |
1147 | 1147 | } |
1148 | 1148 | |
1149 | - $items = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice ); |
|
1149 | + $items = $invoicing->form_elements->convert_checkout_items($invoice->cart_details, $invoice); |
|
1150 | 1150 | $country = $invoice->country; |
1151 | 1151 | $state = $invoice->state; |
1152 | 1152 | |
1153 | 1153 | } else { |
1154 | 1154 | |
1155 | - if ( isset( $data['form_items'] ) ) { |
|
1156 | - $items = getpaid_convert_items_to_array( $data['form_items'] ); |
|
1157 | - $items = $invoicing->form_elements->convert_normal_items( $items ); |
|
1155 | + if (isset($data['form_items'])) { |
|
1156 | + $items = getpaid_convert_items_to_array($data['form_items']); |
|
1157 | + $items = $invoicing->form_elements->convert_normal_items($items); |
|
1158 | 1158 | } else { |
1159 | - $items = $invoicing->form_elements->get_form_items( $data['form_id'] ); |
|
1159 | + $items = $invoicing->form_elements->get_form_items($data['form_id']); |
|
1160 | 1160 | } |
1161 | 1161 | |
1162 | 1162 | $country = wpinv_default_billing_country(); |
@@ -1168,64 +1168,64 @@ discard block |
||
1168 | 1168 | $tax = 0; |
1169 | 1169 | $sub_total = 0; |
1170 | 1170 | |
1171 | - if ( ! empty( $data['wpinv_country'] ) ) { |
|
1171 | + if (!empty($data['wpinv_country'])) { |
|
1172 | 1172 | $country = $data['wpinv_country']; |
1173 | 1173 | } |
1174 | 1174 | |
1175 | - if ( ! empty( $data['wpinv_state'] ) ) { |
|
1175 | + if (!empty($data['wpinv_state'])) { |
|
1176 | 1176 | $state = $data['wpinv_state']; |
1177 | 1177 | } |
1178 | 1178 | |
1179 | - $has_recurring = false; |
|
1180 | - if ( ! empty( $data['wpinv-items'] ) ) { |
|
1179 | + $has_recurring = false; |
|
1180 | + if (!empty($data['wpinv-items'])) { |
|
1181 | 1181 | |
1182 | - $selected_items = wpinv_clean( $data['wpinv-items'] ); |
|
1182 | + $selected_items = wpinv_clean($data['wpinv-items']); |
|
1183 | 1183 | |
1184 | - foreach ( $items as $item ) { |
|
1184 | + foreach ($items as $item) { |
|
1185 | 1185 | |
1186 | - if ( ! isset( $selected_items[ $item['id'] ] ) ) { |
|
1186 | + if (!isset($selected_items[$item['id']])) { |
|
1187 | 1187 | continue; |
1188 | 1188 | } |
1189 | 1189 | |
1190 | - if ( ! empty( $item['recurring'] ) ) { |
|
1191 | - $has_recurring = true; |
|
1190 | + if (!empty($item['recurring'])) { |
|
1191 | + $has_recurring = true; |
|
1192 | 1192 | } |
1193 | 1193 | |
1194 | - $quantity = empty( $item['quantity'] ) ? 1 : absint( $item['quantity'] ); |
|
1194 | + $quantity = empty($item['quantity']) ? 1 : absint($item['quantity']); |
|
1195 | 1195 | |
1196 | - if ( ! empty( $item['allow_quantities'] ) && ! empty( $data["wpinv-item-{$item['id']}-quantity"] ) ) { |
|
1196 | + if (!empty($item['allow_quantities']) && !empty($data["wpinv-item-{$item['id']}-quantity"])) { |
|
1197 | 1197 | |
1198 | - $quantity = intval( $data["wpinv-item-{$item['id']}-quantity"] ); |
|
1198 | + $quantity = intval($data["wpinv-item-{$item['id']}-quantity"]); |
|
1199 | 1199 | |
1200 | - if ( 1 > $quantity ) { |
|
1200 | + if (1 > $quantity) { |
|
1201 | 1201 | $quantity = 1; |
1202 | 1202 | } |
1203 | 1203 | |
1204 | 1204 | } |
1205 | 1205 | |
1206 | 1206 | // Custom pricing. |
1207 | - $price = wpinv_sanitize_amount( $item['price'] ); |
|
1208 | - if ( ! empty( $item['custom_price'] ) ) { |
|
1207 | + $price = wpinv_sanitize_amount($item['price']); |
|
1208 | + if (!empty($item['custom_price'])) { |
|
1209 | 1209 | |
1210 | - $minimum_price = wpinv_sanitize_amount( $item['minimum_price'] ); |
|
1211 | - $set_price = wpinv_sanitize_amount( $selected_items[ $item['id'] ] ); |
|
1210 | + $minimum_price = wpinv_sanitize_amount($item['minimum_price']); |
|
1211 | + $set_price = wpinv_sanitize_amount($selected_items[$item['id']]); |
|
1212 | 1212 | |
1213 | - if ( $set_price < $minimum_price ) { |
|
1213 | + if ($set_price < $minimum_price) { |
|
1214 | 1214 | $set_price = $minimum_price; |
1215 | 1215 | } |
1216 | 1216 | |
1217 | - $price = wpinv_sanitize_amount( $set_price ); |
|
1217 | + $price = wpinv_sanitize_amount($set_price); |
|
1218 | 1218 | |
1219 | 1219 | } |
1220 | 1220 | |
1221 | - $price = $quantity * floatval( $price ); |
|
1221 | + $price = $quantity * floatval($price); |
|
1222 | 1222 | |
1223 | - if ( wpinv_use_taxes() ) { |
|
1223 | + if (wpinv_use_taxes()) { |
|
1224 | 1224 | |
1225 | - $rate = wpinv_get_tax_rate( $country, $state, (int) $item['id'] ); |
|
1225 | + $rate = wpinv_get_tax_rate($country, $state, (int) $item['id']); |
|
1226 | 1226 | |
1227 | - if ( wpinv_prices_include_tax() ) { |
|
1228 | - $pre_tax = ( $price - $price * $rate * 0.01 ); |
|
1227 | + if (wpinv_prices_include_tax()) { |
|
1228 | + $pre_tax = ($price - $price * $rate * 0.01); |
|
1229 | 1229 | $item_tax = $price - $pre_tax; |
1230 | 1230 | } else { |
1231 | 1231 | $pre_tax = $price; |
@@ -1237,18 +1237,18 @@ discard block |
||
1237 | 1237 | $total = $sub_total + $tax; |
1238 | 1238 | |
1239 | 1239 | } else { |
1240 | - $total = $total + $price; |
|
1240 | + $total = $total + $price; |
|
1241 | 1241 | } |
1242 | 1242 | |
1243 | 1243 | } |
1244 | 1244 | |
1245 | 1245 | } |
1246 | 1246 | |
1247 | - wp_send_json_success( array( |
|
1247 | + wp_send_json_success(array( |
|
1248 | 1248 | 'free' => $total == 0, |
1249 | - 'total' => wpinv_price( wpinv_format_amount( $total ) ), |
|
1250 | - 'tax' => wpinv_price( wpinv_format_amount( $tax ) ), |
|
1251 | - 'sub_total' => wpinv_price( wpinv_format_amount( $sub_total ) ), |
|
1249 | + 'total' => wpinv_price(wpinv_format_amount($total)), |
|
1250 | + 'tax' => wpinv_price(wpinv_format_amount($tax)), |
|
1251 | + 'sub_total' => wpinv_price(wpinv_format_amount($sub_total)), |
|
1252 | 1252 | 'has_recurring' => false, |
1253 | 1253 | 'discount' => false, |
1254 | 1254 | )); |
@@ -1263,41 +1263,41 @@ discard block |
||
1263 | 1263 | public static function payment_form_discount() { |
1264 | 1264 | |
1265 | 1265 | // Check nonce. |
1266 | - check_ajax_referer( 'wpinv_payment_form', 'wpinv_payment_form' ); |
|
1266 | + check_ajax_referer('wpinv_payment_form', 'wpinv_payment_form'); |
|
1267 | 1267 | |
1268 | 1268 | // Prepare submitted data... |
1269 | - $data = wp_unslash( $_POST ); |
|
1269 | + $data = wp_unslash($_POST); |
|
1270 | 1270 | |
1271 | 1271 | // ... form fields... |
1272 | - if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) { |
|
1272 | + if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) { |
|
1273 | 1273 | exit; |
1274 | 1274 | } |
1275 | 1275 | |
1276 | 1276 | // Do we have a discount? |
1277 | - if ( empty( $data['discount'] ) ) { |
|
1278 | - _e( 'Please enter your discount code', 'invoicing' ); |
|
1277 | + if (empty($data['discount'])) { |
|
1278 | + _e('Please enter your discount code', 'invoicing'); |
|
1279 | 1279 | exit; |
1280 | 1280 | } |
1281 | 1281 | |
1282 | 1282 | // Validate discount. |
1283 | - $data = self::payment_form_validate_discount( $data ); |
|
1283 | + $data = self::payment_form_validate_discount($data); |
|
1284 | 1284 | |
1285 | - if ( false === $data ) { |
|
1286 | - _e( 'There was an error applying your discount code', 'invoicing' ); |
|
1285 | + if (false === $data) { |
|
1286 | + _e('There was an error applying your discount code', 'invoicing'); |
|
1287 | 1287 | exit; |
1288 | 1288 | } |
1289 | 1289 | |
1290 | - if ( is_string( $data ) ) { |
|
1290 | + if (is_string($data)) { |
|
1291 | 1291 | echo $data; |
1292 | 1292 | exit; |
1293 | 1293 | } |
1294 | 1294 | |
1295 | - $data['total'] = wpinv_price( wpinv_format_amount( $data['total'] ) ); |
|
1296 | - $data['sub_total'] = wpinv_price( wpinv_format_amount( $data['sub_total'] ) ); |
|
1297 | - $data['discount'] = wpinv_price( wpinv_format_amount( $data['discount'] ) ); |
|
1298 | - $data['tax'] = wpinv_price( wpinv_format_amount( $data['tax'] ) ); |
|
1295 | + $data['total'] = wpinv_price(wpinv_format_amount($data['total'])); |
|
1296 | + $data['sub_total'] = wpinv_price(wpinv_format_amount($data['sub_total'])); |
|
1297 | + $data['discount'] = wpinv_price(wpinv_format_amount($data['discount'])); |
|
1298 | + $data['tax'] = wpinv_price(wpinv_format_amount($data['tax'])); |
|
1299 | 1299 | |
1300 | - wp_send_json_success( $data ); |
|
1300 | + wp_send_json_success($data); |
|
1301 | 1301 | exit; |
1302 | 1302 | |
1303 | 1303 | } |
@@ -1307,54 +1307,54 @@ discard block |
||
1307 | 1307 | * |
1308 | 1308 | * @since 1.0.19 |
1309 | 1309 | */ |
1310 | - public static function payment_form_validate_discount( $data ) { |
|
1310 | + public static function payment_form_validate_discount($data) { |
|
1311 | 1311 | global $invoicing; |
1312 | 1312 | |
1313 | 1313 | // Do we have a discount? |
1314 | - if ( empty( $data['discount'] ) ) { |
|
1314 | + if (empty($data['discount'])) { |
|
1315 | 1315 | return false; |
1316 | 1316 | } |
1317 | 1317 | |
1318 | 1318 | // If yes, ensure that it exists. |
1319 | - $discount = wpinv_get_discount_obj( $data['discount'] ); |
|
1319 | + $discount = wpinv_get_discount_obj($data['discount']); |
|
1320 | 1320 | |
1321 | 1321 | // Ensure it is active. |
1322 | - if ( ! $discount->exists() || ! $discount->is_active() || ! $discount->has_started() || $discount->is_expired() ) { |
|
1323 | - return __( 'This discount code is not valid', 'invoicing' ); |
|
1322 | + if (!$discount->exists() || !$discount->is_active() || !$discount->has_started() || $discount->is_expired()) { |
|
1323 | + return __('This discount code is not valid', 'invoicing'); |
|
1324 | 1324 | } |
1325 | 1325 | |
1326 | 1326 | // If it can only be used once per user... |
1327 | - if ( $discount->is_single_use ) { |
|
1327 | + if ($discount->is_single_use) { |
|
1328 | 1328 | |
1329 | - if ( empty( $data['billing_email'] ) ) { |
|
1330 | - return __( 'Please enter your billing email before applying this discount', 'invoicing' ); |
|
1329 | + if (empty($data['billing_email'])) { |
|
1330 | + return __('Please enter your billing email before applying this discount', 'invoicing'); |
|
1331 | 1331 | } |
1332 | 1332 | |
1333 | - if ( ! $discount->is_valid_for_user( $data['billing_email'] ) ) { |
|
1334 | - return __( 'You have already used this discount', 'invoicing' ); |
|
1333 | + if (!$discount->is_valid_for_user($data['billing_email'])) { |
|
1334 | + return __('You have already used this discount', 'invoicing'); |
|
1335 | 1335 | } |
1336 | 1336 | |
1337 | 1337 | } |
1338 | 1338 | |
1339 | 1339 | // Prepare items. |
1340 | - if ( ! empty( $data['invoice_id'] ) ) { |
|
1341 | - $invoice = wpinv_get_invoice( $data['invoice_id'] ); |
|
1340 | + if (!empty($data['invoice_id'])) { |
|
1341 | + $invoice = wpinv_get_invoice($data['invoice_id']); |
|
1342 | 1342 | |
1343 | - if ( empty( $invoice ) ) { |
|
1343 | + if (empty($invoice)) { |
|
1344 | 1344 | return false; |
1345 | 1345 | } |
1346 | 1346 | |
1347 | 1347 | $country = $invoice->country; |
1348 | 1348 | $state = $invoice->state; |
1349 | - $items = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice ); |
|
1349 | + $items = $invoicing->form_elements->convert_checkout_items($invoice->cart_details, $invoice); |
|
1350 | 1350 | |
1351 | 1351 | } else { |
1352 | 1352 | |
1353 | - if ( isset( $data['form_items'] ) ) { |
|
1354 | - $items = getpaid_convert_items_to_array( $data['form_items'] ); |
|
1355 | - $items = $invoicing->form_elements->convert_normal_items( $items ); |
|
1353 | + if (isset($data['form_items'])) { |
|
1354 | + $items = getpaid_convert_items_to_array($data['form_items']); |
|
1355 | + $items = $invoicing->form_elements->convert_normal_items($items); |
|
1356 | 1356 | } else { |
1357 | - $items = $invoicing->form_elements->get_form_items( $data['form_id'] ); |
|
1357 | + $items = $invoicing->form_elements->get_form_items($data['form_id']); |
|
1358 | 1358 | } |
1359 | 1359 | |
1360 | 1360 | $country = wpinv_default_billing_country(); |
@@ -1367,69 +1367,69 @@ discard block |
||
1367 | 1367 | $tax = 0; |
1368 | 1368 | $sub_total = 0; |
1369 | 1369 | |
1370 | - if ( ! empty( $data['wpinv_country'] ) ) { |
|
1370 | + if (!empty($data['wpinv_country'])) { |
|
1371 | 1371 | $country = $data['wpinv_country']; |
1372 | 1372 | } |
1373 | 1373 | |
1374 | - if ( ! empty( $data['wpinv_state'] ) ) { |
|
1374 | + if (!empty($data['wpinv_state'])) { |
|
1375 | 1375 | $state = $data['wpinv_state']; |
1376 | 1376 | } |
1377 | 1377 | |
1378 | - if ( ! empty( $data['wpinv-items'] ) ) { |
|
1378 | + if (!empty($data['wpinv-items'])) { |
|
1379 | 1379 | |
1380 | - $selected_items = wpinv_clean( $data['wpinv-items'] ); |
|
1380 | + $selected_items = wpinv_clean($data['wpinv-items']); |
|
1381 | 1381 | |
1382 | 1382 | // Check if it is valid for the selected items. |
1383 | - if ( ! $discount->is_valid_for_items( array_keys( $selected_items ) ) ) { |
|
1384 | - return __( 'This discount is not valid for the items in your cart', 'invoicing' ); |
|
1383 | + if (!$discount->is_valid_for_items(array_keys($selected_items))) { |
|
1384 | + return __('This discount is not valid for the items in your cart', 'invoicing'); |
|
1385 | 1385 | } |
1386 | 1386 | |
1387 | - $has_recurring = false; |
|
1388 | - foreach ( $items as $item ) { |
|
1387 | + $has_recurring = false; |
|
1388 | + foreach ($items as $item) { |
|
1389 | 1389 | |
1390 | - if ( ! isset( $selected_items[ $item['id'] ] ) ) { |
|
1390 | + if (!isset($selected_items[$item['id']])) { |
|
1391 | 1391 | continue; |
1392 | 1392 | } |
1393 | 1393 | |
1394 | - $quantity = empty( $item['quantity'] ) ? 1 : absint( $item['quantity'] ); |
|
1394 | + $quantity = empty($item['quantity']) ? 1 : absint($item['quantity']); |
|
1395 | 1395 | |
1396 | - if ( ! empty( $item['recurring'] ) ) { |
|
1397 | - $has_recurring = true; |
|
1396 | + if (!empty($item['recurring'])) { |
|
1397 | + $has_recurring = true; |
|
1398 | 1398 | } |
1399 | 1399 | |
1400 | - if ( ! empty( $item['allow_quantities'] ) && ! empty( $data["wpinv-item-{$item['id']}-quantity"] ) ) { |
|
1400 | + if (!empty($item['allow_quantities']) && !empty($data["wpinv-item-{$item['id']}-quantity"])) { |
|
1401 | 1401 | |
1402 | - $quantity = intval( $data["wpinv-item-{$item['id']}-quantity"] ); |
|
1402 | + $quantity = intval($data["wpinv-item-{$item['id']}-quantity"]); |
|
1403 | 1403 | |
1404 | - if ( 1 > $quantity ) { |
|
1404 | + if (1 > $quantity) { |
|
1405 | 1405 | $quantity = 1; |
1406 | 1406 | } |
1407 | 1407 | |
1408 | 1408 | } |
1409 | 1409 | |
1410 | 1410 | // Custom pricing. |
1411 | - $price = wpinv_sanitize_amount( $item['price'] ); |
|
1412 | - if ( ! empty( $item['custom_price'] ) ) { |
|
1411 | + $price = wpinv_sanitize_amount($item['price']); |
|
1412 | + if (!empty($item['custom_price'])) { |
|
1413 | 1413 | |
1414 | - $minimum_price = wpinv_sanitize_amount( $item['minimum_price'] ); |
|
1415 | - $set_price = wpinv_sanitize_amount( $selected_items[ $item['id'] ] ); |
|
1414 | + $minimum_price = wpinv_sanitize_amount($item['minimum_price']); |
|
1415 | + $set_price = wpinv_sanitize_amount($selected_items[$item['id']]); |
|
1416 | 1416 | |
1417 | - if ( $set_price < $minimum_price ) { |
|
1417 | + if ($set_price < $minimum_price) { |
|
1418 | 1418 | $set_price = $minimum_price; |
1419 | 1419 | } |
1420 | 1420 | |
1421 | - $price = wpinv_sanitize_amount( $set_price ); |
|
1421 | + $price = wpinv_sanitize_amount($set_price); |
|
1422 | 1422 | |
1423 | 1423 | } |
1424 | 1424 | |
1425 | - $price = $quantity * floatval( $price ); |
|
1425 | + $price = $quantity * floatval($price); |
|
1426 | 1426 | |
1427 | - if ( wpinv_use_taxes() ) { |
|
1427 | + if (wpinv_use_taxes()) { |
|
1428 | 1428 | |
1429 | - $rate = wpinv_get_tax_rate( $country, $state, (int) $item['id'] ); |
|
1429 | + $rate = wpinv_get_tax_rate($country, $state, (int) $item['id']); |
|
1430 | 1430 | |
1431 | - if ( wpinv_prices_include_tax() ) { |
|
1432 | - $pre_tax = ( $price - $price * $rate * 0.01 ); |
|
1431 | + if (wpinv_prices_include_tax()) { |
|
1432 | + $pre_tax = ($price - $price * $rate * 0.01); |
|
1433 | 1433 | $item_tax = $price - $pre_tax; |
1434 | 1434 | } else { |
1435 | 1435 | $pre_tax = $price; |
@@ -1441,33 +1441,33 @@ discard block |
||
1441 | 1441 | $total = $sub_total + $tax; |
1442 | 1442 | |
1443 | 1443 | } else { |
1444 | - $total = $total + $price; |
|
1444 | + $total = $total + $price; |
|
1445 | 1445 | } |
1446 | 1446 | |
1447 | 1447 | } |
1448 | 1448 | |
1449 | 1449 | } |
1450 | 1450 | |
1451 | - if ( ! $discount->is_minimum_amount_met( $total ) ) { |
|
1452 | - $min = wpinv_price( wpinv_format_amount( $discount->min_total ) ); |
|
1453 | - return sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ); |
|
1451 | + if (!$discount->is_minimum_amount_met($total)) { |
|
1452 | + $min = wpinv_price(wpinv_format_amount($discount->min_total)); |
|
1453 | + return sprintf(__('The minimum total for using this discount is %s', 'invoicing'), $min); |
|
1454 | 1454 | } |
1455 | 1455 | |
1456 | - if ( ! $discount->is_maximum_amount_met( $total ) ) { |
|
1457 | - $max = wpinv_price( wpinv_format_amount( $discount->max_total ) ); |
|
1458 | - return sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ); |
|
1456 | + if (!$discount->is_maximum_amount_met($total)) { |
|
1457 | + $max = wpinv_price(wpinv_format_amount($discount->max_total)); |
|
1458 | + return sprintf(__('The maximum total for using this discount is %s', 'invoicing'), $max); |
|
1459 | 1459 | } |
1460 | 1460 | |
1461 | 1461 | $recurring_discount = $discount->get_is_recurring() && $has_recurring; |
1462 | - $discount = $discount->get_discounted_amount( $total ); |
|
1462 | + $discount = $discount->get_discounted_amount($total); |
|
1463 | 1463 | $total = $total - $discount; |
1464 | 1464 | $free = false; |
1465 | 1465 | |
1466 | - if ( $total == 0 ) { |
|
1466 | + if ($total == 0) { |
|
1467 | 1467 | $free = true; |
1468 | 1468 | } |
1469 | 1469 | |
1470 | - return compact( 'total', 'tax', 'sub_total', 'discount', 'recurring_discount', 'free', 'has_recurring' ); |
|
1470 | + return compact('total', 'tax', 'sub_total', 'discount', 'recurring_discount', 'free', 'has_recurring'); |
|
1471 | 1471 | |
1472 | 1472 | } |
1473 | 1473 | |
@@ -1479,53 +1479,53 @@ discard block |
||
1479 | 1479 | public static function buy_items() { |
1480 | 1480 | $user_id = get_current_user_id(); |
1481 | 1481 | |
1482 | - if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page |
|
1483 | - wp_send_json( array( |
|
1484 | - 'success' => wp_login_url( wp_get_referer() ) |
|
1485 | - ) ); |
|
1482 | + if (empty($user_id)) { // If not logged in then lets redirect to the login page |
|
1483 | + wp_send_json(array( |
|
1484 | + 'success' => wp_login_url(wp_get_referer()) |
|
1485 | + )); |
|
1486 | 1486 | } else { |
1487 | 1487 | // Only check nonce if logged in as it could be cached when logged out. |
1488 | - if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) { |
|
1489 | - wp_send_json( array( |
|
1490 | - 'error' => __( 'Security checks failed.', 'invoicing' ) |
|
1491 | - ) ); |
|
1488 | + if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) { |
|
1489 | + wp_send_json(array( |
|
1490 | + 'error' => __('Security checks failed.', 'invoicing') |
|
1491 | + )); |
|
1492 | 1492 | wp_die(); |
1493 | 1493 | } |
1494 | 1494 | |
1495 | 1495 | // allow to set a custom price through post_id |
1496 | 1496 | $items = $_POST['items']; |
1497 | - $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0; |
|
1498 | - $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0; |
|
1497 | + $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0; |
|
1498 | + $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0; |
|
1499 | 1499 | |
1500 | 1500 | $cart_items = array(); |
1501 | - if ( $items ) { |
|
1502 | - $items = explode( ',', $items ); |
|
1501 | + if ($items) { |
|
1502 | + $items = explode(',', $items); |
|
1503 | 1503 | |
1504 | - foreach( $items as $item ) { |
|
1504 | + foreach ($items as $item) { |
|
1505 | 1505 | $item_id = $item; |
1506 | 1506 | $quantity = 1; |
1507 | 1507 | |
1508 | - if ( strpos( $item, '|' ) !== false ) { |
|
1509 | - $item_parts = explode( '|', $item ); |
|
1508 | + if (strpos($item, '|') !== false) { |
|
1509 | + $item_parts = explode('|', $item); |
|
1510 | 1510 | $item_id = $item_parts[0]; |
1511 | 1511 | $quantity = $item_parts[1]; |
1512 | 1512 | } |
1513 | 1513 | |
1514 | - if ( $item_id && $quantity ) { |
|
1514 | + if ($item_id && $quantity) { |
|
1515 | 1515 | $cart_items_arr = array( |
1516 | - 'id' => (int)$item_id, |
|
1517 | - 'quantity' => (int)$quantity |
|
1516 | + 'id' => (int) $item_id, |
|
1517 | + 'quantity' => (int) $quantity |
|
1518 | 1518 | ); |
1519 | 1519 | |
1520 | 1520 | // If there is a related post id then add it to meta |
1521 | - if ( $related_post_id ) { |
|
1521 | + if ($related_post_id) { |
|
1522 | 1522 | $cart_items_arr['meta'] = array( |
1523 | 1523 | 'post_id' => $related_post_id |
1524 | 1524 | ); |
1525 | 1525 | } |
1526 | 1526 | |
1527 | 1527 | // If there is a custom price then set it. |
1528 | - if ( $custom_item_price ) { |
|
1528 | + if ($custom_item_price) { |
|
1529 | 1529 | $cart_items_arr['custom_price'] = $custom_item_price; |
1530 | 1530 | } |
1531 | 1531 | |
@@ -1541,37 +1541,37 @@ discard block |
||
1541 | 1541 | * @param int $related_post_id The related post id if any. |
1542 | 1542 | * @since 1.0.0 |
1543 | 1543 | */ |
1544 | - $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id ); |
|
1544 | + $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id); |
|
1545 | 1545 | |
1546 | 1546 | // Make sure its not in the cart already, if it is then redirect to checkout. |
1547 | 1547 | $cart_invoice = wpinv_get_invoice_cart(); |
1548 | 1548 | |
1549 | - if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) { |
|
1550 | - wp_send_json( array( |
|
1549 | + if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) { |
|
1550 | + wp_send_json(array( |
|
1551 | 1551 | 'success' => $cart_invoice->get_checkout_payment_url() |
1552 | - ) ); |
|
1552 | + )); |
|
1553 | 1553 | wp_die(); |
1554 | 1554 | } |
1555 | 1555 | |
1556 | 1556 | // Check if user has invoice with same items waiting to be paid. |
1557 | - $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' ); |
|
1558 | - if ( !empty( $user_invoices ) ) { |
|
1559 | - foreach( $user_invoices as $user_invoice ) { |
|
1557 | + $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending'); |
|
1558 | + if (!empty($user_invoices)) { |
|
1559 | + foreach ($user_invoices as $user_invoice) { |
|
1560 | 1560 | $user_cart_details = array(); |
1561 | - $invoice = wpinv_get_invoice( $user_invoice->ID ); |
|
1561 | + $invoice = wpinv_get_invoice($user_invoice->ID); |
|
1562 | 1562 | $cart_details = $invoice->get_cart_details(); |
1563 | 1563 | |
1564 | - if ( !empty( $cart_details ) ) { |
|
1565 | - foreach ( $cart_details as $invoice_item ) { |
|
1564 | + if (!empty($cart_details)) { |
|
1565 | + foreach ($cart_details as $invoice_item) { |
|
1566 | 1566 | $ii_arr = array(); |
1567 | - $ii_arr['id'] = (int)$invoice_item['id']; |
|
1568 | - $ii_arr['quantity'] = (int)$invoice_item['quantity']; |
|
1567 | + $ii_arr['id'] = (int) $invoice_item['id']; |
|
1568 | + $ii_arr['quantity'] = (int) $invoice_item['quantity']; |
|
1569 | 1569 | |
1570 | - if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) { |
|
1570 | + if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) { |
|
1571 | 1571 | $ii_arr['meta'] = $invoice_item['meta']; |
1572 | 1572 | } |
1573 | 1573 | |
1574 | - if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) { |
|
1574 | + if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) { |
|
1575 | 1575 | $ii_arr['custom_price'] = $invoice_item['custom_price']; |
1576 | 1576 | } |
1577 | 1577 | |
@@ -1579,17 +1579,17 @@ discard block |
||
1579 | 1579 | } |
1580 | 1580 | } |
1581 | 1581 | |
1582 | - if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) { |
|
1583 | - wp_send_json( array( |
|
1582 | + if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) { |
|
1583 | + wp_send_json(array( |
|
1584 | 1584 | 'success' => $invoice->get_checkout_payment_url() |
1585 | - ) ); |
|
1585 | + )); |
|
1586 | 1586 | wp_die(); |
1587 | 1587 | } |
1588 | 1588 | } |
1589 | 1589 | } |
1590 | 1590 | |
1591 | 1591 | // Create invoice and send user to checkout |
1592 | - if ( !empty( $cart_items ) ) { |
|
1592 | + if (!empty($cart_items)) { |
|
1593 | 1593 | $invoice_data = array( |
1594 | 1594 | 'status' => 'wpi-pending', |
1595 | 1595 | 'created_via' => 'wpi', |
@@ -1597,21 +1597,21 @@ discard block |
||
1597 | 1597 | 'cart_details' => $cart_items, |
1598 | 1598 | ); |
1599 | 1599 | |
1600 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
1600 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
1601 | 1601 | |
1602 | - if ( !empty( $invoice ) && isset( $invoice->ID ) ) { |
|
1603 | - wp_send_json( array( |
|
1602 | + if (!empty($invoice) && isset($invoice->ID)) { |
|
1603 | + wp_send_json(array( |
|
1604 | 1604 | 'success' => $invoice->get_checkout_payment_url() |
1605 | - ) ); |
|
1605 | + )); |
|
1606 | 1606 | } else { |
1607 | - wp_send_json( array( |
|
1608 | - 'error' => __( 'Invoice failed to create', 'invoicing' ) |
|
1609 | - ) ); |
|
1607 | + wp_send_json(array( |
|
1608 | + 'error' => __('Invoice failed to create', 'invoicing') |
|
1609 | + )); |
|
1610 | 1610 | } |
1611 | 1611 | } else { |
1612 | - wp_send_json( array( |
|
1613 | - 'error' => __( 'Items not valid.', 'invoicing' ) |
|
1614 | - ) ); |
|
1612 | + wp_send_json(array( |
|
1613 | + 'error' => __('Items not valid.', 'invoicing') |
|
1614 | + )); |
|
1615 | 1615 | } |
1616 | 1616 | } |
1617 | 1617 |