@@ -12,46 +12,46 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Report { |
14 | 14 | |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - public $views; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + public $views; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - */ |
|
24 | - public function __construct() { |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + */ |
|
24 | + public function __construct() { |
|
25 | 25 | |
26 | - $this->views = array( |
|
26 | + $this->views = array( |
|
27 | 27 | |
28 | 28 | 'items' => array( |
29 | - 'label' => __( 'Items', 'invoicing' ), |
|
30 | - 'class' => 'GetPaid_Reports_Report_Items', |
|
31 | - ), |
|
29 | + 'label' => __( 'Items', 'invoicing' ), |
|
30 | + 'class' => 'GetPaid_Reports_Report_Items', |
|
31 | + ), |
|
32 | 32 | |
33 | - 'gateways' => array( |
|
34 | - 'label' => __( 'Payment Methods', 'invoicing' ), |
|
35 | - 'class' => 'GetPaid_Reports_Report_Gateways', |
|
36 | - ), |
|
33 | + 'gateways' => array( |
|
34 | + 'label' => __( 'Payment Methods', 'invoicing' ), |
|
35 | + 'class' => 'GetPaid_Reports_Report_Gateways', |
|
36 | + ), |
|
37 | 37 | |
38 | - 'discounts' => array( |
|
39 | - 'label' => __( 'Discount Codes', 'invoicing' ), |
|
40 | - 'class' => 'GetPaid_Reports_Report_Discounts', |
|
41 | - ), |
|
38 | + 'discounts' => array( |
|
39 | + 'label' => __( 'Discount Codes', 'invoicing' ), |
|
40 | + 'class' => 'GetPaid_Reports_Report_Discounts', |
|
41 | + ), |
|
42 | 42 | |
43 | 43 | ); |
44 | 44 | |
45 | - $this->views = apply_filters( 'wpinv_report_views', $this->views ); |
|
45 | + $this->views = apply_filters( 'wpinv_report_views', $this->views ); |
|
46 | 46 | |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Displays the reports tab. |
|
51 | - * |
|
52 | - */ |
|
53 | - public function display() { |
|
54 | - ?> |
|
49 | + /** |
|
50 | + * Displays the reports tab. |
|
51 | + * |
|
52 | + */ |
|
53 | + public function display() { |
|
54 | + ?> |
|
55 | 55 | |
56 | 56 | <div class="mt-4" style="max-width: 1200px;"> |
57 | 57 | |
@@ -69,44 +69,44 @@ discard block |
||
69 | 69 | |
70 | 70 | <?php |
71 | 71 | |
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Displays the left side. |
|
76 | - * |
|
77 | - */ |
|
78 | - public function display_left() { |
|
79 | - $earnings = new GetPaid_Reports_Report_Earnings(); |
|
80 | - $earnings->display(); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Retrieves the download url. |
|
85 | - * |
|
86 | - */ |
|
87 | - public function get_download_url( $graph, $file_type ) { |
|
88 | - |
|
89 | - return wp_nonce_url( |
|
90 | - add_query_arg( |
|
91 | - array( |
|
92 | - 'getpaid-admin-action' => 'download_graph', |
|
93 | - 'file_type' => urlencode( $file_type ), |
|
94 | - 'graph' => urlencode( $graph ), |
|
95 | - ) |
|
96 | - ), |
|
97 | - 'getpaid-nonce', |
|
98 | - 'getpaid-nonce' |
|
99 | - ); |
|
100 | - |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Displays the right side. |
|
105 | - * |
|
106 | - */ |
|
107 | - public function display_right() { |
|
108 | - |
|
109 | - ?> |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Displays the left side. |
|
76 | + * |
|
77 | + */ |
|
78 | + public function display_left() { |
|
79 | + $earnings = new GetPaid_Reports_Report_Earnings(); |
|
80 | + $earnings->display(); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Retrieves the download url. |
|
85 | + * |
|
86 | + */ |
|
87 | + public function get_download_url( $graph, $file_type ) { |
|
88 | + |
|
89 | + return wp_nonce_url( |
|
90 | + add_query_arg( |
|
91 | + array( |
|
92 | + 'getpaid-admin-action' => 'download_graph', |
|
93 | + 'file_type' => urlencode( $file_type ), |
|
94 | + 'graph' => urlencode( $graph ), |
|
95 | + ) |
|
96 | + ), |
|
97 | + 'getpaid-nonce', |
|
98 | + 'getpaid-nonce' |
|
99 | + ); |
|
100 | + |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Displays the right side. |
|
105 | + * |
|
106 | + */ |
|
107 | + public function display_right() { |
|
108 | + |
|
109 | + ?> |
|
110 | 110 | |
111 | 111 | <?php foreach ( $this->views as $key => $view ) : ?> |
112 | 112 | <div class="row mb-4"> |
@@ -135,10 +135,10 @@ discard block |
||
135 | 135 | </div> |
136 | 136 | <div class="card-body"> |
137 | 137 | <?php |
138 | - $class = $view['class']; |
|
139 | - $class = new $class(); |
|
140 | - $class->display_stats(); |
|
141 | - ?> |
|
138 | + $class = $view['class']; |
|
139 | + $class = new $class(); |
|
140 | + $class->display_stats(); |
|
141 | + ?> |
|
142 | 142 | </div> |
143 | 143 | </div> |
144 | 144 | </div> |
@@ -147,6 +147,6 @@ discard block |
||
147 | 147 | |
148 | 148 | <?php |
149 | 149 | |
150 | - } |
|
150 | + } |
|
151 | 151 | |
152 | 152 | } |
@@ -97,13 +97,13 @@ discard block |
||
97 | 97 | */ |
98 | 98 | function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
99 | 99 | |
100 | - $invoice_statuses = array( |
|
101 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
100 | + $invoice_statuses = array( |
|
101 | + 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
102 | 102 | 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
103 | 103 | 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
104 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
105 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
106 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
104 | + 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
105 | + 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
106 | + 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
107 | 107 | 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
108 | 108 | 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
109 | 109 | ); |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $invoice = $invoice->get_post_type(); |
121 | 121 | } |
122 | 122 | |
123 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
123 | + return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -238,25 +238,25 @@ discard block |
||
238 | 238 | * @return string |
239 | 239 | */ |
240 | 240 | function getpaid_get_price_format() { |
241 | - $currency_pos = wpinv_currency_position(); |
|
242 | - $format = '%1$s%2$s'; |
|
243 | - |
|
244 | - switch ( $currency_pos ) { |
|
245 | - case 'left': |
|
246 | - $format = '%1$s%2$s'; |
|
247 | - break; |
|
248 | - case 'right': |
|
249 | - $format = '%2$s%1$s'; |
|
250 | - break; |
|
251 | - case 'left_space': |
|
252 | - $format = '%1$s %2$s'; |
|
253 | - break; |
|
254 | - case 'right_space': |
|
255 | - $format = '%2$s %1$s'; |
|
256 | - break; |
|
257 | - } |
|
258 | - |
|
259 | - return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
241 | + $currency_pos = wpinv_currency_position(); |
|
242 | + $format = '%1$s%2$s'; |
|
243 | + |
|
244 | + switch ( $currency_pos ) { |
|
245 | + case 'left': |
|
246 | + $format = '%1$s%2$s'; |
|
247 | + break; |
|
248 | + case 'right': |
|
249 | + $format = '%2$s%1$s'; |
|
250 | + break; |
|
251 | + case 'left_space': |
|
252 | + $format = '%1$s %2$s'; |
|
253 | + break; |
|
254 | + case 'right_space': |
|
255 | + $format = '%2$s %1$s'; |
|
256 | + break; |
|
257 | + } |
|
258 | + |
|
259 | + return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -359,13 +359,13 @@ discard block |
||
359 | 359 | * @param mixed $value Value. |
360 | 360 | */ |
361 | 361 | function getpaid_maybe_define_constant( $name, $value ) { |
362 | - if ( ! defined( $name ) ) { |
|
363 | - define( $name, $value ); |
|
364 | - } |
|
362 | + if ( ! defined( $name ) ) { |
|
363 | + define( $name, $value ); |
|
364 | + } |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | function wpinv_get_php_arg_separator_output() { |
368 | - return ini_get( 'arg_separator.output' ); |
|
368 | + return ini_get( 'arg_separator.output' ); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | function wpinv_rgb_from_hex( $color ) { |
@@ -716,11 +716,11 @@ discard block |
||
716 | 716 | $list = array(); |
717 | 717 | } |
718 | 718 | |
719 | - if ( ! is_array( $list ) ) { |
|
720 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
721 | - } |
|
719 | + if ( ! is_array( $list ) ) { |
|
720 | + return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
721 | + } |
|
722 | 722 | |
723 | - return $list; |
|
723 | + return $list; |
|
724 | 724 | } |
725 | 725 | |
726 | 726 | /** |
@@ -740,9 +740,9 @@ discard block |
||
740 | 740 | } |
741 | 741 | |
742 | 742 | $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" ); |
743 | - wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
743 | + wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
744 | 744 | |
745 | - return $data; |
|
745 | + return $data; |
|
746 | 746 | } |
747 | 747 | |
748 | 748 | /** |
@@ -771,17 +771,17 @@ discard block |
||
771 | 771 | */ |
772 | 772 | function wpinv_clean( $var ) { |
773 | 773 | |
774 | - if ( is_array( $var ) ) { |
|
775 | - return array_map( 'wpinv_clean', $var ); |
|
774 | + if ( is_array( $var ) ) { |
|
775 | + return array_map( 'wpinv_clean', $var ); |
|
776 | 776 | } |
777 | 777 | |
778 | 778 | if ( is_object( $var ) ) { |
779 | - $object_vars = get_object_vars( $var ); |
|
780 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
781 | - $var->$property_name = wpinv_clean( $property_value ); |
|
779 | + $object_vars = get_object_vars( $var ); |
|
780 | + foreach ( $object_vars as $property_name => $property_value ) { |
|
781 | + $var->$property_name = wpinv_clean( $property_value ); |
|
782 | 782 | } |
783 | 783 | return $var; |
784 | - } |
|
784 | + } |
|
785 | 785 | |
786 | 786 | return is_string( $var ) ? sanitize_text_field( $var ) : $var; |
787 | 787 | } |
@@ -794,7 +794,7 @@ discard block |
||
794 | 794 | */ |
795 | 795 | function getpaid_convert_price_string_to_options( $str ) { |
796 | 796 | |
797 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
797 | + $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
798 | 798 | $options = array(); |
799 | 799 | |
800 | 800 | foreach ( $raw_options as $option ) { |
@@ -872,7 +872,7 @@ discard block |
||
872 | 872 | * @return string |
873 | 873 | */ |
874 | 874 | function getpaid_date_format() { |
875 | - return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
875 | + return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
876 | 876 | } |
877 | 877 | |
878 | 878 | /** |
@@ -881,7 +881,7 @@ discard block |
||
881 | 881 | * @return string |
882 | 882 | */ |
883 | 883 | function getpaid_time_format() { |
884 | - return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
884 | + return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | /** |
@@ -894,15 +894,15 @@ discard block |
||
894 | 894 | function getpaid_limit_length( $string, $limit ) { |
895 | 895 | $str_limit = $limit - 3; |
896 | 896 | |
897 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
898 | - if ( mb_strlen( $string ) > $limit ) { |
|
899 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
900 | - } |
|
901 | - } else { |
|
902 | - if ( strlen( $string ) > $limit ) { |
|
903 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
904 | - } |
|
905 | - } |
|
897 | + if ( function_exists( 'mb_strimwidth' ) ) { |
|
898 | + if ( mb_strlen( $string ) > $limit ) { |
|
899 | + $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
900 | + } |
|
901 | + } else { |
|
902 | + if ( strlen( $string ) > $limit ) { |
|
903 | + $string = substr( $string, 0, $str_limit ) . '...'; |
|
904 | + } |
|
905 | + } |
|
906 | 906 | return $string; |
907 | 907 | |
908 | 908 | } |
@@ -12,224 +12,224 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Refresh_Prices { |
14 | 14 | |
15 | - /** |
|
16 | - * Contains the response for refreshing prices. |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $response = array(); |
|
15 | + /** |
|
16 | + * Contains the response for refreshing prices. |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $response = array(); |
|
20 | 20 | |
21 | 21 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - */ |
|
26 | - public function __construct( $submission ) { |
|
27 | - |
|
28 | - $this->response = array( |
|
29 | - 'submission_id' => $submission->id, |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + */ |
|
26 | + public function __construct( $submission ) { |
|
27 | + |
|
28 | + $this->response = array( |
|
29 | + 'submission_id' => $submission->id, |
|
30 | 30 | 'has_recurring' => $submission->has_recurring, |
31 | 31 | 'is_free' => ! $submission->should_collect_payment_details(), |
32 | - ); |
|
33 | - |
|
34 | - $this->add_totals( $submission ); |
|
35 | - $this->add_texts( $submission ); |
|
36 | - $this->add_items( $submission ); |
|
37 | - $this->add_fees( $submission ); |
|
38 | - $this->add_discounts( $submission ); |
|
39 | - $this->add_taxes( $submission ); |
|
40 | - $this->add_gateways( $submission ); |
|
41 | - |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Adds totals to a response for submission refresh prices. |
|
46 | - * |
|
47 | - * @param GetPaid_Payment_Form_Submission $submission |
|
48 | - */ |
|
49 | - public function add_totals( $submission ) { |
|
50 | - |
|
51 | - $this->response = array_merge( |
|
52 | - $this->response, |
|
53 | - array( |
|
54 | - |
|
55 | - 'totals' => array( |
|
56 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
57 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
58 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
59 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
60 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
61 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
62 | - ), |
|
63 | - |
|
64 | - 'recurring' => array( |
|
65 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
66 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
67 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
68 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
69 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
70 | - ), |
|
71 | - |
|
72 | - ) |
|
73 | - ); |
|
74 | - |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Adds texts to a response for submission refresh prices. |
|
79 | - * |
|
80 | - * @param GetPaid_Payment_Form_Submission $submission |
|
81 | - */ |
|
82 | - public function add_texts( $submission ) { |
|
83 | - |
|
84 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
85 | - |
|
86 | - if ( $submission->has_recurring != 0 ) { |
|
87 | - |
|
88 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
89 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
90 | - |
|
91 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
92 | - $payable = "$payable / $period"; |
|
93 | - } else { |
|
94 | - $payable = sprintf( |
|
95 | - __( '%1$s (renews at %2$s / %3$s)'), |
|
96 | - $submission->format_amount( $submission->get_total() ), |
|
97 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
98 | - $period |
|
99 | - ); |
|
100 | - } |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - $texts = array( |
|
105 | - '.getpaid-checkout-total-payable' => $payable, |
|
106 | - ); |
|
107 | - |
|
108 | - foreach ( $submission->get_items() as $item_id => $item ) { |
|
109 | - $texts[".item-$item_id .getpaid-item-initial-price"] = $submission->format_amount( $item->get_sub_total() ); |
|
110 | - $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() ); |
|
111 | - } |
|
112 | - |
|
113 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
114 | - |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Adds items to a response for submission refresh prices. |
|
119 | - * |
|
120 | - * @param GetPaid_Payment_Form_Submission $submission |
|
121 | - */ |
|
122 | - public function add_items( $submission ) { |
|
123 | - |
|
124 | - // Add items. |
|
125 | - $items = array(); |
|
32 | + ); |
|
33 | + |
|
34 | + $this->add_totals( $submission ); |
|
35 | + $this->add_texts( $submission ); |
|
36 | + $this->add_items( $submission ); |
|
37 | + $this->add_fees( $submission ); |
|
38 | + $this->add_discounts( $submission ); |
|
39 | + $this->add_taxes( $submission ); |
|
40 | + $this->add_gateways( $submission ); |
|
41 | + |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Adds totals to a response for submission refresh prices. |
|
46 | + * |
|
47 | + * @param GetPaid_Payment_Form_Submission $submission |
|
48 | + */ |
|
49 | + public function add_totals( $submission ) { |
|
50 | + |
|
51 | + $this->response = array_merge( |
|
52 | + $this->response, |
|
53 | + array( |
|
54 | + |
|
55 | + 'totals' => array( |
|
56 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
57 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
58 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
59 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
60 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
61 | + 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
62 | + ), |
|
63 | + |
|
64 | + 'recurring' => array( |
|
65 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
66 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
67 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
68 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
69 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
70 | + ), |
|
71 | + |
|
72 | + ) |
|
73 | + ); |
|
74 | + |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Adds texts to a response for submission refresh prices. |
|
79 | + * |
|
80 | + * @param GetPaid_Payment_Form_Submission $submission |
|
81 | + */ |
|
82 | + public function add_texts( $submission ) { |
|
83 | + |
|
84 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
85 | + |
|
86 | + if ( $submission->has_recurring != 0 ) { |
|
87 | + |
|
88 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
89 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
90 | + |
|
91 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
92 | + $payable = "$payable / $period"; |
|
93 | + } else { |
|
94 | + $payable = sprintf( |
|
95 | + __( '%1$s (renews at %2$s / %3$s)'), |
|
96 | + $submission->format_amount( $submission->get_total() ), |
|
97 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
98 | + $period |
|
99 | + ); |
|
100 | + } |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + $texts = array( |
|
105 | + '.getpaid-checkout-total-payable' => $payable, |
|
106 | + ); |
|
126 | 107 | |
127 | 108 | foreach ( $submission->get_items() as $item_id => $item ) { |
128 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
129 | - } |
|
109 | + $texts[".item-$item_id .getpaid-item-initial-price"] = $submission->format_amount( $item->get_sub_total() ); |
|
110 | + $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() ); |
|
111 | + } |
|
130 | 112 | |
131 | - $this->response = array_merge( |
|
132 | - $this->response, |
|
133 | - array( 'items' => $items ) |
|
134 | - ); |
|
113 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
135 | 114 | |
136 | - } |
|
115 | + } |
|
137 | 116 | |
138 | - /** |
|
139 | - * Adds fees to a response for submission refresh prices. |
|
140 | - * |
|
141 | - * @param GetPaid_Payment_Form_Submission $submission |
|
142 | - */ |
|
143 | - public function add_fees( $submission ) { |
|
117 | + /** |
|
118 | + * Adds items to a response for submission refresh prices. |
|
119 | + * |
|
120 | + * @param GetPaid_Payment_Form_Submission $submission |
|
121 | + */ |
|
122 | + public function add_items( $submission ) { |
|
123 | + |
|
124 | + // Add items. |
|
125 | + $items = array(); |
|
126 | + |
|
127 | + foreach ( $submission->get_items() as $item_id => $item ) { |
|
128 | + $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
129 | + } |
|
130 | + |
|
131 | + $this->response = array_merge( |
|
132 | + $this->response, |
|
133 | + array( 'items' => $items ) |
|
134 | + ); |
|
135 | + |
|
136 | + } |
|
144 | 137 | |
145 | - $fees = array(); |
|
138 | + /** |
|
139 | + * Adds fees to a response for submission refresh prices. |
|
140 | + * |
|
141 | + * @param GetPaid_Payment_Form_Submission $submission |
|
142 | + */ |
|
143 | + public function add_fees( $submission ) { |
|
144 | + |
|
145 | + $fees = array(); |
|
146 | 146 | |
147 | 147 | foreach ( $submission->get_fees() as $name => $data ) { |
148 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
149 | - } |
|
148 | + $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
149 | + } |
|
150 | 150 | |
151 | - $this->response = array_merge( |
|
152 | - $this->response, |
|
153 | - array( 'fees' => $fees ) |
|
154 | - ); |
|
151 | + $this->response = array_merge( |
|
152 | + $this->response, |
|
153 | + array( 'fees' => $fees ) |
|
154 | + ); |
|
155 | 155 | |
156 | - } |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * Adds discounts to a response for submission refresh prices. |
|
160 | - * |
|
161 | - * @param GetPaid_Payment_Form_Submission $submission |
|
162 | - */ |
|
163 | - public function add_discounts( $submission ) { |
|
158 | + /** |
|
159 | + * Adds discounts to a response for submission refresh prices. |
|
160 | + * |
|
161 | + * @param GetPaid_Payment_Form_Submission $submission |
|
162 | + */ |
|
163 | + public function add_discounts( $submission ) { |
|
164 | 164 | |
165 | - $discounts = array(); |
|
165 | + $discounts = array(); |
|
166 | 166 | |
167 | 167 | foreach ( $submission->get_discounts() as $name => $data ) { |
168 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
169 | - } |
|
168 | + $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
169 | + } |
|
170 | 170 | |
171 | - $this->response = array_merge( |
|
172 | - $this->response, |
|
173 | - array( 'discounts' => $discounts ) |
|
174 | - ); |
|
171 | + $this->response = array_merge( |
|
172 | + $this->response, |
|
173 | + array( 'discounts' => $discounts ) |
|
174 | + ); |
|
175 | 175 | |
176 | - } |
|
176 | + } |
|
177 | 177 | |
178 | - /** |
|
179 | - * Adds taxes to a response for submission refresh prices. |
|
180 | - * |
|
181 | - * @param GetPaid_Payment_Form_Submission $submission |
|
182 | - */ |
|
183 | - public function add_taxes( $submission ) { |
|
184 | - |
|
185 | - $taxes = array(); |
|
186 | - $markup = ''; |
|
178 | + /** |
|
179 | + * Adds taxes to a response for submission refresh prices. |
|
180 | + * |
|
181 | + * @param GetPaid_Payment_Form_Submission $submission |
|
182 | + */ |
|
183 | + public function add_taxes( $submission ) { |
|
184 | + |
|
185 | + $taxes = array(); |
|
186 | + $markup = ''; |
|
187 | 187 | foreach ( $submission->get_taxes() as $name => $data ) { |
188 | - $name = sanitize_text_field( $name ); |
|
189 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
190 | - $taxes[$name] = $amount; |
|
191 | - $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
192 | - } |
|
188 | + $name = sanitize_text_field( $name ); |
|
189 | + $amount = $submission->format_amount( $data['initial_tax'] ); |
|
190 | + $taxes[$name] = $amount; |
|
191 | + $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
192 | + } |
|
193 | 193 | |
194 | - if ( wpinv_display_individual_tax_rates() ) { |
|
195 | - $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
196 | - } |
|
194 | + if ( wpinv_display_individual_tax_rates() ) { |
|
195 | + $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
196 | + } |
|
197 | 197 | |
198 | - $this->response = array_merge( |
|
199 | - $this->response, |
|
200 | - array( 'taxes' => $taxes ) |
|
201 | - ); |
|
198 | + $this->response = array_merge( |
|
199 | + $this->response, |
|
200 | + array( 'taxes' => $taxes ) |
|
201 | + ); |
|
202 | 202 | |
203 | - } |
|
203 | + } |
|
204 | 204 | |
205 | - /** |
|
206 | - * Adds gateways to a response for submission refresh prices. |
|
207 | - * |
|
208 | - * @param GetPaid_Payment_Form_Submission $submission |
|
209 | - */ |
|
210 | - public function add_gateways( $submission ) { |
|
205 | + /** |
|
206 | + * Adds gateways to a response for submission refresh prices. |
|
207 | + * |
|
208 | + * @param GetPaid_Payment_Form_Submission $submission |
|
209 | + */ |
|
210 | + public function add_gateways( $submission ) { |
|
211 | 211 | |
212 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
212 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
213 | 213 | |
214 | - if ( $this->response['has_recurring'] ) { |
|
214 | + if ( $this->response['has_recurring'] ) { |
|
215 | 215 | |
216 | - foreach ( $gateways as $i => $gateway ) { |
|
216 | + foreach ( $gateways as $i => $gateway ) { |
|
217 | 217 | |
218 | - if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
219 | - unset( $gateways[ $i ] ); |
|
220 | - } |
|
218 | + if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
219 | + unset( $gateways[ $i ] ); |
|
220 | + } |
|
221 | 221 | |
222 | - } |
|
222 | + } |
|
223 | 223 | |
224 | - } |
|
224 | + } |
|
225 | 225 | |
226 | 226 | |
227 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
228 | - $this->response = array_merge( |
|
229 | - $this->response, |
|
230 | - array( 'gateways' => $gateways ) |
|
231 | - ); |
|
227 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
228 | + $this->response = array_merge( |
|
229 | + $this->response, |
|
230 | + array( 'gateways' => $gateways ) |
|
231 | + ); |
|
232 | 232 | |
233 | - } |
|
233 | + } |
|
234 | 234 | |
235 | 235 | } |
@@ -12,194 +12,194 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Invoice_Exporter extends GetPaid_Graph_Downloader { |
14 | 14 | |
15 | - /** |
|
16 | - * Retrieves invoices query args. |
|
17 | - * |
|
18 | - * @param string $post_type post type to retrieve. |
|
19 | - * @param array $args Args to search for. |
|
20 | - * @return array |
|
21 | - */ |
|
22 | - public function get_invoice_query_args( $post_type, $args ) { |
|
23 | - |
|
24 | - $query_args = array( |
|
25 | - 'post_type' => $post_type, |
|
26 | - 'post_status' => array_keys( wpinv_get_invoice_statuses( true, false, $post_type ) ), |
|
27 | - 'posts_per_page' => -1, |
|
28 | - 'no_found_rows' => true, |
|
29 | - 'update_post_term_cache' => false, |
|
30 | - 'fields' => 'ids', |
|
31 | - ); |
|
32 | - |
|
33 | - if ( ! empty( $args['status'] ) && in_array( $args['status'], $query_args['post_status'], true ) ) { |
|
34 | - $query_args['post_status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
35 | - } |
|
36 | - |
|
37 | - $date_query = array(); |
|
38 | - if ( ! empty( $args['to_date'] ) ) { |
|
39 | - $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
40 | - } |
|
41 | - |
|
42 | - if ( ! empty( $args['from_date'] ) ) { |
|
43 | - $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
44 | - } |
|
45 | - |
|
46 | - if ( ! empty( $date_query ) ) { |
|
47 | - $date_query['inclusive'] = true; |
|
48 | - $query_args['date_query'] = array( $date_query ); |
|
49 | - } |
|
50 | - |
|
51 | - return $query_args; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Retrieves invoices. |
|
56 | - * |
|
57 | - * @param array $query_args WP_Query args. |
|
58 | - * @return WPInv_Invoice[] |
|
59 | - */ |
|
60 | - public function get_invoices( $query_args ) { |
|
61 | - |
|
62 | - // Get invoices. |
|
63 | - $invoices = new WP_Query( $query_args ); |
|
64 | - |
|
65 | - // Prepare the results. |
|
66 | - return array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
67 | - |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Handles the actual download. |
|
72 | - * |
|
73 | - */ |
|
74 | - public function export( $post_type, $args ) { |
|
75 | - |
|
76 | - $invoices = $this->get_invoices( $this->get_invoice_query_args( $post_type, $args ) ); |
|
77 | - $stream = $this->prepare_output(); |
|
78 | - $headers = $this->get_export_fields( $post_type ); |
|
79 | - $file_type = $this->prepare_file_type( strtolower( getpaid_get_post_type_label( $post_type ) ) ); |
|
80 | - |
|
81 | - if ( 'csv' == $file_type ) { |
|
82 | - $this->download_csv( $invoices, $stream, $headers ); |
|
83 | - } else if( 'xml' == $file_type ) { |
|
84 | - $this->download_xml( $invoices, $stream, $headers ); |
|
85 | - } else { |
|
86 | - $this->download_json( $invoices, $stream, $headers ); |
|
87 | - } |
|
88 | - |
|
89 | - fclose( $stream ); |
|
90 | - exit; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Prepares a single invoice for download. |
|
95 | - * |
|
96 | - * @param WPInv_Invoice $invoice The invoice to prepare.. |
|
97 | - * @param array $fields The fields to stream. |
|
98 | - * @since 1.0.19 |
|
99 | - * @return array |
|
100 | - */ |
|
101 | - public function prepare_row( $invoice, $fields ) { |
|
102 | - |
|
103 | - $prepared = array(); |
|
104 | - $amount_fields = $this->get_amount_fields( $invoice->get_post_type() ); |
|
105 | - |
|
106 | - foreach ( $fields as $field ) { |
|
107 | - |
|
108 | - $value = ''; |
|
109 | - $method = "get_$field"; |
|
110 | - |
|
111 | - if ( method_exists( $invoice, $method ) ) { |
|
112 | - $value = $invoice->$method(); |
|
113 | - } |
|
114 | - |
|
115 | - if ( in_array( $field, $amount_fields ) ) { |
|
116 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
117 | - } |
|
118 | - |
|
119 | - $prepared[ $field ] = wpinv_clean( $value ); |
|
120 | - |
|
121 | - } |
|
122 | - |
|
123 | - return $prepared; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Retrieves export fields. |
|
128 | - * |
|
129 | - * @param string $post_type |
|
130 | - * @since 1.0.19 |
|
131 | - * @return array |
|
132 | - */ |
|
133 | - public function get_export_fields( $post_type ) { |
|
134 | - |
|
135 | - $fields = array( |
|
136 | - 'id', |
|
137 | - 'parent_id', |
|
138 | - 'status', |
|
139 | - 'date_created', |
|
140 | - 'date_modified', |
|
141 | - 'date_due', |
|
142 | - 'date_completed', |
|
143 | - 'number', |
|
144 | - 'key', |
|
145 | - 'description', |
|
146 | - 'post_type', |
|
147 | - 'mode', |
|
148 | - 'customer_id', |
|
149 | - 'customer_first_name', |
|
150 | - 'customer_last_name', |
|
151 | - 'customer_phone', |
|
152 | - 'customer_email', |
|
153 | - 'customer_country', |
|
154 | - 'customer_city', |
|
155 | - 'customer_state', |
|
156 | - 'customer_zip', |
|
157 | - 'customer_company', |
|
158 | - 'customer_vat_number', |
|
159 | - 'customer_address', |
|
160 | - 'subtotal', |
|
161 | - 'total_discount', |
|
162 | - 'total_tax', |
|
163 | - 'total_fees', |
|
164 | - 'fees', |
|
165 | - 'discounts', |
|
166 | - 'taxes', |
|
167 | - 'cart_details', |
|
168 | - 'item_ids', |
|
169 | - 'payment_form', |
|
170 | - 'discount_code', |
|
171 | - 'gateway', |
|
172 | - 'transaction_id', |
|
173 | - 'currency', |
|
174 | - 'disable_taxes', |
|
175 | - 'subscription_id', |
|
176 | - 'remote_subscription_id', |
|
177 | - 'is_viewed', |
|
178 | - 'email_cc', |
|
179 | - 'template', |
|
180 | - 'created_via' |
|
181 | - ); |
|
182 | - |
|
183 | - return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type ); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Retrieves amount fields. |
|
188 | - * |
|
189 | - * @param string $post_type |
|
190 | - * @since 1.0.19 |
|
191 | - * @return array |
|
192 | - */ |
|
193 | - public function get_amount_fields( $post_type ) { |
|
194 | - |
|
195 | - $fields = array( |
|
196 | - 'subtotal', |
|
197 | - 'total_discount', |
|
198 | - 'total_tax', |
|
199 | - 'total_fees' |
|
200 | - ); |
|
201 | - |
|
202 | - return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type ); |
|
203 | - } |
|
15 | + /** |
|
16 | + * Retrieves invoices query args. |
|
17 | + * |
|
18 | + * @param string $post_type post type to retrieve. |
|
19 | + * @param array $args Args to search for. |
|
20 | + * @return array |
|
21 | + */ |
|
22 | + public function get_invoice_query_args( $post_type, $args ) { |
|
23 | + |
|
24 | + $query_args = array( |
|
25 | + 'post_type' => $post_type, |
|
26 | + 'post_status' => array_keys( wpinv_get_invoice_statuses( true, false, $post_type ) ), |
|
27 | + 'posts_per_page' => -1, |
|
28 | + 'no_found_rows' => true, |
|
29 | + 'update_post_term_cache' => false, |
|
30 | + 'fields' => 'ids', |
|
31 | + ); |
|
32 | + |
|
33 | + if ( ! empty( $args['status'] ) && in_array( $args['status'], $query_args['post_status'], true ) ) { |
|
34 | + $query_args['post_status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
35 | + } |
|
36 | + |
|
37 | + $date_query = array(); |
|
38 | + if ( ! empty( $args['to_date'] ) ) { |
|
39 | + $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
40 | + } |
|
41 | + |
|
42 | + if ( ! empty( $args['from_date'] ) ) { |
|
43 | + $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
44 | + } |
|
45 | + |
|
46 | + if ( ! empty( $date_query ) ) { |
|
47 | + $date_query['inclusive'] = true; |
|
48 | + $query_args['date_query'] = array( $date_query ); |
|
49 | + } |
|
50 | + |
|
51 | + return $query_args; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Retrieves invoices. |
|
56 | + * |
|
57 | + * @param array $query_args WP_Query args. |
|
58 | + * @return WPInv_Invoice[] |
|
59 | + */ |
|
60 | + public function get_invoices( $query_args ) { |
|
61 | + |
|
62 | + // Get invoices. |
|
63 | + $invoices = new WP_Query( $query_args ); |
|
64 | + |
|
65 | + // Prepare the results. |
|
66 | + return array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
67 | + |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Handles the actual download. |
|
72 | + * |
|
73 | + */ |
|
74 | + public function export( $post_type, $args ) { |
|
75 | + |
|
76 | + $invoices = $this->get_invoices( $this->get_invoice_query_args( $post_type, $args ) ); |
|
77 | + $stream = $this->prepare_output(); |
|
78 | + $headers = $this->get_export_fields( $post_type ); |
|
79 | + $file_type = $this->prepare_file_type( strtolower( getpaid_get_post_type_label( $post_type ) ) ); |
|
80 | + |
|
81 | + if ( 'csv' == $file_type ) { |
|
82 | + $this->download_csv( $invoices, $stream, $headers ); |
|
83 | + } else if( 'xml' == $file_type ) { |
|
84 | + $this->download_xml( $invoices, $stream, $headers ); |
|
85 | + } else { |
|
86 | + $this->download_json( $invoices, $stream, $headers ); |
|
87 | + } |
|
88 | + |
|
89 | + fclose( $stream ); |
|
90 | + exit; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Prepares a single invoice for download. |
|
95 | + * |
|
96 | + * @param WPInv_Invoice $invoice The invoice to prepare.. |
|
97 | + * @param array $fields The fields to stream. |
|
98 | + * @since 1.0.19 |
|
99 | + * @return array |
|
100 | + */ |
|
101 | + public function prepare_row( $invoice, $fields ) { |
|
102 | + |
|
103 | + $prepared = array(); |
|
104 | + $amount_fields = $this->get_amount_fields( $invoice->get_post_type() ); |
|
105 | + |
|
106 | + foreach ( $fields as $field ) { |
|
107 | + |
|
108 | + $value = ''; |
|
109 | + $method = "get_$field"; |
|
110 | + |
|
111 | + if ( method_exists( $invoice, $method ) ) { |
|
112 | + $value = $invoice->$method(); |
|
113 | + } |
|
114 | + |
|
115 | + if ( in_array( $field, $amount_fields ) ) { |
|
116 | + $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
117 | + } |
|
118 | + |
|
119 | + $prepared[ $field ] = wpinv_clean( $value ); |
|
120 | + |
|
121 | + } |
|
122 | + |
|
123 | + return $prepared; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Retrieves export fields. |
|
128 | + * |
|
129 | + * @param string $post_type |
|
130 | + * @since 1.0.19 |
|
131 | + * @return array |
|
132 | + */ |
|
133 | + public function get_export_fields( $post_type ) { |
|
134 | + |
|
135 | + $fields = array( |
|
136 | + 'id', |
|
137 | + 'parent_id', |
|
138 | + 'status', |
|
139 | + 'date_created', |
|
140 | + 'date_modified', |
|
141 | + 'date_due', |
|
142 | + 'date_completed', |
|
143 | + 'number', |
|
144 | + 'key', |
|
145 | + 'description', |
|
146 | + 'post_type', |
|
147 | + 'mode', |
|
148 | + 'customer_id', |
|
149 | + 'customer_first_name', |
|
150 | + 'customer_last_name', |
|
151 | + 'customer_phone', |
|
152 | + 'customer_email', |
|
153 | + 'customer_country', |
|
154 | + 'customer_city', |
|
155 | + 'customer_state', |
|
156 | + 'customer_zip', |
|
157 | + 'customer_company', |
|
158 | + 'customer_vat_number', |
|
159 | + 'customer_address', |
|
160 | + 'subtotal', |
|
161 | + 'total_discount', |
|
162 | + 'total_tax', |
|
163 | + 'total_fees', |
|
164 | + 'fees', |
|
165 | + 'discounts', |
|
166 | + 'taxes', |
|
167 | + 'cart_details', |
|
168 | + 'item_ids', |
|
169 | + 'payment_form', |
|
170 | + 'discount_code', |
|
171 | + 'gateway', |
|
172 | + 'transaction_id', |
|
173 | + 'currency', |
|
174 | + 'disable_taxes', |
|
175 | + 'subscription_id', |
|
176 | + 'remote_subscription_id', |
|
177 | + 'is_viewed', |
|
178 | + 'email_cc', |
|
179 | + 'template', |
|
180 | + 'created_via' |
|
181 | + ); |
|
182 | + |
|
183 | + return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type ); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Retrieves amount fields. |
|
188 | + * |
|
189 | + * @param string $post_type |
|
190 | + * @since 1.0.19 |
|
191 | + * @return array |
|
192 | + */ |
|
193 | + public function get_amount_fields( $post_type ) { |
|
194 | + |
|
195 | + $fields = array( |
|
196 | + 'subtotal', |
|
197 | + 'total_discount', |
|
198 | + 'total_tax', |
|
199 | + 'total_fees' |
|
200 | + ); |
|
201 | + |
|
202 | + return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type ); |
|
203 | + } |
|
204 | 204 | |
205 | 205 | } |
@@ -13,168 +13,168 @@ |
||
13 | 13 | */ |
14 | 14 | class GetPaid_Tax { |
15 | 15 | |
16 | - /** |
|
17 | - * Calculates tax for a line item. |
|
18 | - * |
|
19 | - * @param float $price The price to calc tax on. |
|
20 | - * @param array $rates The rates to apply. |
|
21 | - * @param boolean $price_includes_tax Whether the passed price has taxes included. |
|
22 | - * @return array Array of tax name => tax amount. |
|
23 | - */ |
|
24 | - public static function calc_tax( $price, $rates, $price_includes_tax = false ) { |
|
25 | - |
|
26 | - if ( $price_includes_tax ) { |
|
27 | - $taxes = self::calc_inclusive_tax( $price, $rates ); |
|
28 | - } else { |
|
29 | - $taxes = self::calc_exclusive_tax( $price, $rates ); |
|
30 | - } |
|
31 | - |
|
32 | - return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax ); |
|
33 | - |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * Calc tax from inclusive price. |
|
38 | - * |
|
39 | - * @param float $price Price to calculate tax for. |
|
40 | - * @param array $rates Array of tax rates. |
|
41 | - * @return array |
|
42 | - */ |
|
43 | - public static function calc_inclusive_tax( $price, $rates ) { |
|
44 | - $taxes = array(); |
|
45 | - $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
46 | - |
|
47 | - // Add tax rates. |
|
48 | - $tax_rate = 1 + ( array_sum( $tax_rates ) / 100 ); |
|
49 | - |
|
50 | - foreach ( $tax_rates as $name => $rate ) { |
|
51 | - $the_rate = ( $rate / 100 ) / $tax_rate; |
|
52 | - $net_price = $price - ( $the_rate * $price ); |
|
53 | - $tax_amount = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price ); |
|
54 | - $taxes[ $name ] = $tax_amount; |
|
55 | - } |
|
56 | - |
|
57 | - // Round all taxes to precision (4DP) before passing them back. |
|
58 | - $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
59 | - |
|
60 | - return $taxes; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Calc tax from exclusive price. |
|
65 | - * |
|
66 | - * @param float $price Price to calculate tax for. |
|
67 | - * @param array $rates Array of tax rates. |
|
68 | - * @return array |
|
69 | - */ |
|
70 | - public static function calc_exclusive_tax( $price, $rates ) { |
|
71 | - $taxes = array(); |
|
72 | - $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
73 | - |
|
74 | - foreach ( $tax_rates as $name => $rate ) { |
|
75 | - |
|
76 | - $tax_amount = $price * ( $rate / 100 ); |
|
77 | - $taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price ); |
|
78 | - |
|
79 | - } |
|
80 | - |
|
81 | - // Round all taxes to precision (4DP) before passing them back. |
|
82 | - $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
83 | - |
|
84 | - return $taxes; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Get's an array of all tax rates. |
|
89 | - * |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public static function get_all_tax_rates() { |
|
93 | - |
|
94 | - $rates = get_option( 'wpinv_tax_rates', array() ); |
|
95 | - |
|
96 | - return apply_filters( |
|
97 | - 'getpaid_get_all_tax_rates', |
|
98 | - array_filter( wpinv_parse_list( $rates ) ) |
|
99 | - ); |
|
100 | - |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Get's an array of default tax rates. |
|
105 | - * |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - public static function get_default_tax_rates() { |
|
109 | - |
|
110 | - return apply_filters( |
|
111 | - 'getpaid_get_default_tax_rates', |
|
112 | - array( |
|
113 | - array( |
|
114 | - 'country' => wpinv_get_default_country(), |
|
115 | - 'state' => wpinv_get_default_state(), |
|
116 | - 'global' => true, |
|
117 | - 'rate' => wpinv_get_default_tax_rate(), |
|
118 | - 'name' => __( 'Base Tax', 'invoicing' ), |
|
119 | - ) |
|
120 | - ) |
|
121 | - ); |
|
122 | - |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Get's an array of tax rates for a given address. |
|
127 | - * |
|
128 | - * @param string $country |
|
129 | - * @param string $state |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - public static function get_address_tax_rates( $country, $state ) { |
|
133 | - |
|
134 | - $all_tax_rates = self::get_all_tax_rates(); |
|
135 | - $matching_rates = array_merge( |
|
136 | - wp_list_filter( $all_tax_rates, array( 'country' => $country ) ), |
|
137 | - wp_list_filter( $all_tax_rates, array( 'country' => '' ) ) |
|
138 | - ); |
|
139 | - |
|
140 | - foreach ( $matching_rates as $i => $rate ) { |
|
141 | - |
|
142 | - $states = array_filter( wpinv_clean( explode( ',', $rate['state'] ) ) ); |
|
143 | - if ( empty( $rate['global'] ) && ! in_array( $state, $states ) ) { |
|
144 | - unset( $matching_rates[ $i ] ); |
|
145 | - } |
|
146 | - |
|
147 | - } |
|
148 | - |
|
149 | - return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state ); |
|
150 | - |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Sums a set of taxes to form a single total. Result is rounded to precision. |
|
155 | - * |
|
156 | - * @param array $taxes Array of taxes. |
|
157 | - * @return float |
|
158 | - */ |
|
159 | - public static function get_tax_total( $taxes ) { |
|
160 | - return self::round( array_sum( $taxes ) ); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Round to precision. |
|
165 | - * |
|
166 | - * Filter example: to return rounding to .5 cents you'd use: |
|
167 | - * |
|
168 | - * function euro_5cent_rounding( $in ) { |
|
169 | - * return round( $in / 5, 2 ) * 5; |
|
170 | - * } |
|
171 | - * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' ); |
|
172 | - * |
|
173 | - * @param float|int $in Value to round. |
|
174 | - * @return float |
|
175 | - */ |
|
176 | - public static function round( $in ) { |
|
177 | - return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in ); |
|
178 | - } |
|
16 | + /** |
|
17 | + * Calculates tax for a line item. |
|
18 | + * |
|
19 | + * @param float $price The price to calc tax on. |
|
20 | + * @param array $rates The rates to apply. |
|
21 | + * @param boolean $price_includes_tax Whether the passed price has taxes included. |
|
22 | + * @return array Array of tax name => tax amount. |
|
23 | + */ |
|
24 | + public static function calc_tax( $price, $rates, $price_includes_tax = false ) { |
|
25 | + |
|
26 | + if ( $price_includes_tax ) { |
|
27 | + $taxes = self::calc_inclusive_tax( $price, $rates ); |
|
28 | + } else { |
|
29 | + $taxes = self::calc_exclusive_tax( $price, $rates ); |
|
30 | + } |
|
31 | + |
|
32 | + return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax ); |
|
33 | + |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * Calc tax from inclusive price. |
|
38 | + * |
|
39 | + * @param float $price Price to calculate tax for. |
|
40 | + * @param array $rates Array of tax rates. |
|
41 | + * @return array |
|
42 | + */ |
|
43 | + public static function calc_inclusive_tax( $price, $rates ) { |
|
44 | + $taxes = array(); |
|
45 | + $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
46 | + |
|
47 | + // Add tax rates. |
|
48 | + $tax_rate = 1 + ( array_sum( $tax_rates ) / 100 ); |
|
49 | + |
|
50 | + foreach ( $tax_rates as $name => $rate ) { |
|
51 | + $the_rate = ( $rate / 100 ) / $tax_rate; |
|
52 | + $net_price = $price - ( $the_rate * $price ); |
|
53 | + $tax_amount = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price ); |
|
54 | + $taxes[ $name ] = $tax_amount; |
|
55 | + } |
|
56 | + |
|
57 | + // Round all taxes to precision (4DP) before passing them back. |
|
58 | + $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
59 | + |
|
60 | + return $taxes; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Calc tax from exclusive price. |
|
65 | + * |
|
66 | + * @param float $price Price to calculate tax for. |
|
67 | + * @param array $rates Array of tax rates. |
|
68 | + * @return array |
|
69 | + */ |
|
70 | + public static function calc_exclusive_tax( $price, $rates ) { |
|
71 | + $taxes = array(); |
|
72 | + $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
73 | + |
|
74 | + foreach ( $tax_rates as $name => $rate ) { |
|
75 | + |
|
76 | + $tax_amount = $price * ( $rate / 100 ); |
|
77 | + $taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price ); |
|
78 | + |
|
79 | + } |
|
80 | + |
|
81 | + // Round all taxes to precision (4DP) before passing them back. |
|
82 | + $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
83 | + |
|
84 | + return $taxes; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Get's an array of all tax rates. |
|
89 | + * |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public static function get_all_tax_rates() { |
|
93 | + |
|
94 | + $rates = get_option( 'wpinv_tax_rates', array() ); |
|
95 | + |
|
96 | + return apply_filters( |
|
97 | + 'getpaid_get_all_tax_rates', |
|
98 | + array_filter( wpinv_parse_list( $rates ) ) |
|
99 | + ); |
|
100 | + |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Get's an array of default tax rates. |
|
105 | + * |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + public static function get_default_tax_rates() { |
|
109 | + |
|
110 | + return apply_filters( |
|
111 | + 'getpaid_get_default_tax_rates', |
|
112 | + array( |
|
113 | + array( |
|
114 | + 'country' => wpinv_get_default_country(), |
|
115 | + 'state' => wpinv_get_default_state(), |
|
116 | + 'global' => true, |
|
117 | + 'rate' => wpinv_get_default_tax_rate(), |
|
118 | + 'name' => __( 'Base Tax', 'invoicing' ), |
|
119 | + ) |
|
120 | + ) |
|
121 | + ); |
|
122 | + |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Get's an array of tax rates for a given address. |
|
127 | + * |
|
128 | + * @param string $country |
|
129 | + * @param string $state |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + public static function get_address_tax_rates( $country, $state ) { |
|
133 | + |
|
134 | + $all_tax_rates = self::get_all_tax_rates(); |
|
135 | + $matching_rates = array_merge( |
|
136 | + wp_list_filter( $all_tax_rates, array( 'country' => $country ) ), |
|
137 | + wp_list_filter( $all_tax_rates, array( 'country' => '' ) ) |
|
138 | + ); |
|
139 | + |
|
140 | + foreach ( $matching_rates as $i => $rate ) { |
|
141 | + |
|
142 | + $states = array_filter( wpinv_clean( explode( ',', $rate['state'] ) ) ); |
|
143 | + if ( empty( $rate['global'] ) && ! in_array( $state, $states ) ) { |
|
144 | + unset( $matching_rates[ $i ] ); |
|
145 | + } |
|
146 | + |
|
147 | + } |
|
148 | + |
|
149 | + return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state ); |
|
150 | + |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Sums a set of taxes to form a single total. Result is rounded to precision. |
|
155 | + * |
|
156 | + * @param array $taxes Array of taxes. |
|
157 | + * @return float |
|
158 | + */ |
|
159 | + public static function get_tax_total( $taxes ) { |
|
160 | + return self::round( array_sum( $taxes ) ); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Round to precision. |
|
165 | + * |
|
166 | + * Filter example: to return rounding to .5 cents you'd use: |
|
167 | + * |
|
168 | + * function euro_5cent_rounding( $in ) { |
|
169 | + * return round( $in / 5, 2 ) * 5; |
|
170 | + * } |
|
171 | + * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' ); |
|
172 | + * |
|
173 | + * @param float|int $in Value to round. |
|
174 | + * @return float |
|
175 | + */ |
|
176 | + public static function round( $in ) { |
|
177 | + return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in ); |
|
178 | + } |
|
179 | 179 | |
180 | 180 | } |
@@ -215,16 +215,16 @@ discard block |
||
215 | 215 | function getpaid_prepare_item_tax( $item, $tax_name, $tax_amount, $recurring_tax_amount ) { |
216 | 216 | |
217 | 217 | $initial_tax = $tax_amount; |
218 | - $recurring_tax = 0; |
|
218 | + $recurring_tax = 0; |
|
219 | 219 | |
220 | 220 | if ( $item->is_recurring() ) { |
221 | - $recurring_tax = $recurring_tax_amount; |
|
222 | - } |
|
221 | + $recurring_tax = $recurring_tax_amount; |
|
222 | + } |
|
223 | 223 | |
224 | - return array( |
|
225 | - 'name' => sanitize_text_field( $tax_name ), |
|
226 | - 'initial_tax' => $initial_tax, |
|
227 | - 'recurring_tax' => $recurring_tax, |
|
224 | + return array( |
|
225 | + 'name' => sanitize_text_field( $tax_name ), |
|
226 | + 'initial_tax' => $initial_tax, |
|
227 | + 'recurring_tax' => $recurring_tax, |
|
228 | 228 | ); |
229 | 229 | |
230 | 230 | } |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | */ |
329 | 329 | function wpinv_should_validate_vat_number() { |
330 | 330 | $validate = wpinv_get_option( 'validate_vat_number' ); |
331 | - return ! empty( $validate ); |
|
331 | + return ! empty( $validate ); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | function wpinv_sales_tax_for_year( $year = null ) { |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | class GetPaid_Meta_Box_Item_VAT { |
18 | 18 | |
19 | 19 | /** |
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | 24 | public static function output( $post ) { |
25 | 25 | |
26 | 26 | // Prepare the item. |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | - * Output the VAT rules settings. |
|
50 | - * |
|
51 | - * @param WPInv_Item $item |
|
52 | - */ |
|
49 | + * Output the VAT rules settings. |
|
50 | + * |
|
51 | + * @param WPInv_Item $item |
|
52 | + */ |
|
53 | 53 | public static function output_vat_rules( $item ) { |
54 | 54 | ?> |
55 | 55 | |
@@ -87,10 +87,10 @@ discard block |
||
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
90 | - * Output the VAT class settings. |
|
91 | - * |
|
92 | - * @param WPInv_Item $item |
|
93 | - */ |
|
90 | + * Output the VAT class settings. |
|
91 | + * |
|
92 | + * @param WPInv_Item $item |
|
93 | + */ |
|
94 | 94 | public static function output_vat_classes( $item ) { |
95 | 95 | ?> |
96 | 96 |
@@ -12,267 +12,267 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Metaboxes { |
14 | 14 | |
15 | - /** |
|
16 | - * Only save metaboxes once. |
|
17 | - * |
|
18 | - * @var boolean |
|
19 | - */ |
|
20 | - private static $saved_meta_boxes = false; |
|
21 | - |
|
22 | 15 | /** |
23 | - * Hook in methods. |
|
24 | - */ |
|
25 | - public static function init() { |
|
26 | - |
|
27 | - // Register metaboxes. |
|
28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
29 | - |
|
30 | - // Remove metaboxes. |
|
31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
32 | - |
|
33 | - // Rename metaboxes. |
|
34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
35 | - |
|
36 | - // Save metaboxes. |
|
37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | - } |
|
16 | + * Only save metaboxes once. |
|
17 | + * |
|
18 | + * @var boolean |
|
19 | + */ |
|
20 | + private static $saved_meta_boxes = false; |
|
39 | 21 | |
40 | - /** |
|
41 | - * Register core metaboxes. |
|
42 | - */ |
|
43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
44 | - |
|
45 | - // For invoices... |
|
46 | - self::add_invoice_meta_boxes( $post_type, $post ); |
|
22 | + /** |
|
23 | + * Hook in methods. |
|
24 | + */ |
|
25 | + public static function init() { |
|
47 | 26 | |
48 | - // For payment forms. |
|
49 | - self::add_payment_form_meta_boxes( $post_type ); |
|
27 | + // Register metaboxes. |
|
28 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
50 | 29 | |
51 | - // For invoice items. |
|
52 | - self::add_item_meta_boxes( $post_type ); |
|
30 | + // Remove metaboxes. |
|
31 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
53 | 32 | |
54 | - // For invoice discounts. |
|
55 | - if ( $post_type == 'wpi_discount' ) { |
|
56 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
57 | - } |
|
33 | + // Rename metaboxes. |
|
34 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
58 | 35 | |
59 | - } |
|
36 | + // Save metaboxes. |
|
37 | + add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | + } |
|
60 | 39 | |
61 | - /** |
|
62 | - * Register core metaboxes. |
|
63 | - */ |
|
64 | - protected static function add_payment_form_meta_boxes( $post_type ) { |
|
40 | + /** |
|
41 | + * Register core metaboxes. |
|
42 | + */ |
|
43 | + public static function add_meta_boxes( $post_type, $post ) { |
|
65 | 44 | |
66 | - // For payment forms. |
|
67 | - if ( $post_type == 'wpi_payment_form' ) { |
|
45 | + // For invoices... |
|
46 | + self::add_invoice_meta_boxes( $post_type, $post ); |
|
68 | 47 | |
69 | - // Design payment form. |
|
70 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
48 | + // For payment forms. |
|
49 | + self::add_payment_form_meta_boxes( $post_type ); |
|
71 | 50 | |
72 | - // Payment form information. |
|
73 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
51 | + // For invoice items. |
|
52 | + self::add_item_meta_boxes( $post_type ); |
|
74 | 53 | |
75 | - } |
|
54 | + // For invoice discounts. |
|
55 | + if ( $post_type == 'wpi_discount' ) { |
|
56 | + add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
57 | + } |
|
76 | 58 | |
77 | - } |
|
59 | + } |
|
78 | 60 | |
79 | - /** |
|
80 | - * Register core metaboxes. |
|
81 | - */ |
|
82 | - protected static function add_item_meta_boxes( $post_type ) { |
|
61 | + /** |
|
62 | + * Register core metaboxes. |
|
63 | + */ |
|
64 | + protected static function add_payment_form_meta_boxes( $post_type ) { |
|
83 | 65 | |
84 | - if ( $post_type == 'wpi_item' ) { |
|
66 | + // For payment forms. |
|
67 | + if ( $post_type == 'wpi_payment_form' ) { |
|
85 | 68 | |
86 | - // Item details. |
|
87 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
69 | + // Design payment form. |
|
70 | + add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
88 | 71 | |
89 | - // If taxes are enabled, register the tax metabox. |
|
90 | - if ( wpinv_use_taxes() ) { |
|
91 | - add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
92 | - } |
|
72 | + // Payment form information. |
|
73 | + add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
93 | 74 | |
94 | - // Item info. |
|
95 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
75 | + } |
|
96 | 76 | |
97 | - } |
|
77 | + } |
|
98 | 78 | |
99 | - } |
|
79 | + /** |
|
80 | + * Register core metaboxes. |
|
81 | + */ |
|
82 | + protected static function add_item_meta_boxes( $post_type ) { |
|
100 | 83 | |
101 | - /** |
|
102 | - * Register invoice metaboxes. |
|
103 | - */ |
|
104 | - protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
84 | + if ( $post_type == 'wpi_item' ) { |
|
105 | 85 | |
106 | - // For invoices... |
|
107 | - if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
108 | - $invoice = new WPInv_Invoice( $post ); |
|
86 | + // Item details. |
|
87 | + add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
109 | 88 | |
110 | - // Resend invoice. |
|
111 | - if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) { |
|
89 | + // If taxes are enabled, register the tax metabox. |
|
90 | + if ( wpinv_use_taxes() ) { |
|
91 | + add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
92 | + } |
|
112 | 93 | |
113 | - add_meta_box( |
|
114 | - 'wpinv-mb-resend-invoice', |
|
115 | - sprintf( |
|
116 | - __( 'Resend %s', 'invoicing' ), |
|
117 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
118 | - ), |
|
119 | - 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
120 | - $post_type, |
|
121 | - 'side', |
|
122 | - 'low' |
|
123 | - ); |
|
94 | + // Item info. |
|
95 | + add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
124 | 96 | |
125 | - } |
|
97 | + } |
|
126 | 98 | |
127 | - // Subscriptions. |
|
128 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
129 | - if ( ! empty( $subscription ) ) { |
|
130 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
131 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
132 | - } |
|
133 | - |
|
134 | - // Invoice details. |
|
135 | - add_meta_box( |
|
136 | - 'wpinv-details', |
|
137 | - sprintf( |
|
138 | - __( '%s Details', 'invoicing' ), |
|
139 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
140 | - ), |
|
141 | - 'GetPaid_Meta_Box_Invoice_Details::output', |
|
142 | - $post_type, |
|
143 | - 'side' |
|
144 | - ); |
|
145 | - |
|
146 | - // Payment details. |
|
147 | - if ( ! $invoice->is_draft() ) { |
|
148 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
149 | - } |
|
99 | + } |
|
150 | 100 | |
151 | - // Billing details. |
|
152 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
101 | + /** |
|
102 | + * Register invoice metaboxes. |
|
103 | + */ |
|
104 | + protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
105 | + |
|
106 | + // For invoices... |
|
107 | + if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
108 | + $invoice = new WPInv_Invoice( $post ); |
|
109 | + |
|
110 | + // Resend invoice. |
|
111 | + if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) { |
|
112 | + |
|
113 | + add_meta_box( |
|
114 | + 'wpinv-mb-resend-invoice', |
|
115 | + sprintf( |
|
116 | + __( 'Resend %s', 'invoicing' ), |
|
117 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
118 | + ), |
|
119 | + 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
120 | + $post_type, |
|
121 | + 'side', |
|
122 | + 'low' |
|
123 | + ); |
|
124 | + |
|
125 | + } |
|
126 | + |
|
127 | + // Subscriptions. |
|
128 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
129 | + if ( ! empty( $subscription ) ) { |
|
130 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
131 | + add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
132 | + } |
|
133 | + |
|
134 | + // Invoice details. |
|
135 | + add_meta_box( |
|
136 | + 'wpinv-details', |
|
137 | + sprintf( |
|
138 | + __( '%s Details', 'invoicing' ), |
|
139 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
140 | + ), |
|
141 | + 'GetPaid_Meta_Box_Invoice_Details::output', |
|
142 | + $post_type, |
|
143 | + 'side' |
|
144 | + ); |
|
145 | + |
|
146 | + // Payment details. |
|
147 | + if ( ! $invoice->is_draft() ) { |
|
148 | + add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
149 | + } |
|
150 | + |
|
151 | + // Billing details. |
|
152 | + add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
153 | 153 | |
154 | - // Invoice items. |
|
155 | - add_meta_box( |
|
156 | - 'wpinv-items', |
|
157 | - sprintf( |
|
158 | - __( '%s Items', 'invoicing' ), |
|
159 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
160 | - ), |
|
161 | - 'GetPaid_Meta_Box_Invoice_Items::output', |
|
162 | - $post_type, |
|
163 | - 'normal', |
|
164 | - 'high' |
|
165 | - ); |
|
154 | + // Invoice items. |
|
155 | + add_meta_box( |
|
156 | + 'wpinv-items', |
|
157 | + sprintf( |
|
158 | + __( '%s Items', 'invoicing' ), |
|
159 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
160 | + ), |
|
161 | + 'GetPaid_Meta_Box_Invoice_Items::output', |
|
162 | + $post_type, |
|
163 | + 'normal', |
|
164 | + 'high' |
|
165 | + ); |
|
166 | 166 | |
167 | - // Invoice notes. |
|
168 | - add_meta_box( |
|
169 | - 'wpinv-notes', |
|
170 | - sprintf( |
|
171 | - __( '%s Notes', 'invoicing' ), |
|
172 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
173 | - ), |
|
174 | - 'WPInv_Meta_Box_Notes::output', |
|
175 | - $post_type, |
|
176 | - 'side', |
|
177 | - 'low' |
|
178 | - ); |
|
179 | - |
|
180 | - // Shipping Address. |
|
181 | - if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
182 | - add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
183 | - } |
|
184 | - |
|
185 | - // Payment form information. |
|
186 | - if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
187 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
188 | - } |
|
189 | - |
|
190 | - } |
|
191 | - |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Remove some metaboxes. |
|
196 | - */ |
|
197 | - public static function remove_meta_boxes() { |
|
198 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Rename other metaboxes. |
|
203 | - */ |
|
204 | - public static function rename_meta_boxes() { |
|
167 | + // Invoice notes. |
|
168 | + add_meta_box( |
|
169 | + 'wpinv-notes', |
|
170 | + sprintf( |
|
171 | + __( '%s Notes', 'invoicing' ), |
|
172 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
173 | + ), |
|
174 | + 'WPInv_Meta_Box_Notes::output', |
|
175 | + $post_type, |
|
176 | + 'side', |
|
177 | + 'low' |
|
178 | + ); |
|
179 | + |
|
180 | + // Shipping Address. |
|
181 | + if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
182 | + add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
183 | + } |
|
184 | + |
|
185 | + // Payment form information. |
|
186 | + if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
187 | + add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
188 | + } |
|
189 | + |
|
190 | + } |
|
191 | + |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Remove some metaboxes. |
|
196 | + */ |
|
197 | + public static function remove_meta_boxes() { |
|
198 | + remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Rename other metaboxes. |
|
203 | + */ |
|
204 | + public static function rename_meta_boxes() { |
|
205 | 205 | |
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Check if we're saving, then trigger an action based on the post type. |
|
210 | - * |
|
211 | - * @param int $post_id Post ID. |
|
212 | - * @param object $post Post object. |
|
213 | - */ |
|
214 | - public static function save_meta_boxes( $post_id, $post ) { |
|
215 | - $post_id = absint( $post_id ); |
|
216 | - $data = wp_unslash( $_POST ); |
|
217 | - |
|
218 | - // Do not save for ajax requests. |
|
219 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
220 | - return; |
|
221 | - } |
|
222 | - |
|
223 | - // $post_id and $post are required |
|
224 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
225 | - return; |
|
226 | - } |
|
227 | - |
|
228 | - // Dont' save meta boxes for revisions or autosaves. |
|
229 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
230 | - return; |
|
231 | - } |
|
232 | - |
|
233 | - // Check the nonce. |
|
234 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
235 | - return; |
|
236 | - } |
|
237 | - |
|
238 | - // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
239 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
240 | - return; |
|
241 | - } |
|
242 | - |
|
243 | - // Check user has permission to edit. |
|
244 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
245 | - return; |
|
246 | - } |
|
247 | - |
|
248 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
249 | - |
|
250 | - // We need this save event to run once to avoid potential endless loops. |
|
251 | - self::$saved_meta_boxes = true; |
|
252 | - |
|
253 | - return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
254 | - |
|
255 | - } |
|
256 | - |
|
257 | - // Ensure this is our post type. |
|
258 | - $post_types_map = array( |
|
259 | - 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
260 | - 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
261 | - 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
262 | - ); |
|
263 | - |
|
264 | - // Is this our post type? |
|
265 | - if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
266 | - return; |
|
267 | - } |
|
268 | - |
|
269 | - // We need this save event to run once to avoid potential endless loops. |
|
270 | - self::$saved_meta_boxes = true; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Check if we're saving, then trigger an action based on the post type. |
|
210 | + * |
|
211 | + * @param int $post_id Post ID. |
|
212 | + * @param object $post Post object. |
|
213 | + */ |
|
214 | + public static function save_meta_boxes( $post_id, $post ) { |
|
215 | + $post_id = absint( $post_id ); |
|
216 | + $data = wp_unslash( $_POST ); |
|
217 | + |
|
218 | + // Do not save for ajax requests. |
|
219 | + if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
220 | + return; |
|
221 | + } |
|
222 | + |
|
223 | + // $post_id and $post are required |
|
224 | + if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
225 | + return; |
|
226 | + } |
|
227 | + |
|
228 | + // Dont' save meta boxes for revisions or autosaves. |
|
229 | + if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
230 | + return; |
|
231 | + } |
|
232 | + |
|
233 | + // Check the nonce. |
|
234 | + if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
235 | + return; |
|
236 | + } |
|
237 | + |
|
238 | + // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
239 | + if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
240 | + return; |
|
241 | + } |
|
242 | + |
|
243 | + // Check user has permission to edit. |
|
244 | + if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
245 | + return; |
|
246 | + } |
|
247 | + |
|
248 | + if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
249 | + |
|
250 | + // We need this save event to run once to avoid potential endless loops. |
|
251 | + self::$saved_meta_boxes = true; |
|
252 | + |
|
253 | + return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
254 | + |
|
255 | + } |
|
256 | + |
|
257 | + // Ensure this is our post type. |
|
258 | + $post_types_map = array( |
|
259 | + 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
260 | + 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
261 | + 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
262 | + ); |
|
263 | + |
|
264 | + // Is this our post type? |
|
265 | + if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
266 | + return; |
|
267 | + } |
|
268 | + |
|
269 | + // We need this save event to run once to avoid potential endless loops. |
|
270 | + self::$saved_meta_boxes = true; |
|
271 | 271 | |
272 | - // Save the post. |
|
273 | - $class = $post_types_map[ $post->post_type ]; |
|
274 | - $class::save( $post_id, $_POST, $post ); |
|
272 | + // Save the post. |
|
273 | + $class = $post_types_map[ $post->post_type ]; |
|
274 | + $class::save( $post_id, $_POST, $post ); |
|
275 | 275 | |
276 | - } |
|
276 | + } |
|
277 | 277 | |
278 | 278 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,187 +10,187 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form_Submission { |
11 | 11 | |
12 | 12 | /** |
13 | - * Submission ID |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - public $id = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * The raw submission data. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $data = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * Submission totals |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $totals = array( |
|
32 | - |
|
33 | - 'subtotal' => array( |
|
34 | - 'initial' => 0, |
|
35 | - 'recurring' => 0, |
|
36 | - ), |
|
37 | - |
|
38 | - 'discount' => array( |
|
39 | - 'initial' => 0, |
|
40 | - 'recurring' => 0, |
|
41 | - ), |
|
42 | - |
|
43 | - 'fees' => array( |
|
44 | - 'initial' => 0, |
|
45 | - 'recurring' => 0, |
|
46 | - ), |
|
47 | - |
|
48 | - 'taxes' => array( |
|
49 | - 'initial' => 0, |
|
50 | - 'recurring' => 0, |
|
51 | - ), |
|
52 | - |
|
53 | - ); |
|
54 | - |
|
55 | - /** |
|
56 | - * Sets the associated payment form. |
|
57 | - * |
|
58 | - * @var GetPaid_Payment_Form |
|
59 | - */ |
|
13 | + * Submission ID |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + public $id = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * The raw submission data. |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $data = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * Submission totals |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $totals = array( |
|
32 | + |
|
33 | + 'subtotal' => array( |
|
34 | + 'initial' => 0, |
|
35 | + 'recurring' => 0, |
|
36 | + ), |
|
37 | + |
|
38 | + 'discount' => array( |
|
39 | + 'initial' => 0, |
|
40 | + 'recurring' => 0, |
|
41 | + ), |
|
42 | + |
|
43 | + 'fees' => array( |
|
44 | + 'initial' => 0, |
|
45 | + 'recurring' => 0, |
|
46 | + ), |
|
47 | + |
|
48 | + 'taxes' => array( |
|
49 | + 'initial' => 0, |
|
50 | + 'recurring' => 0, |
|
51 | + ), |
|
52 | + |
|
53 | + ); |
|
54 | + |
|
55 | + /** |
|
56 | + * Sets the associated payment form. |
|
57 | + * |
|
58 | + * @var GetPaid_Payment_Form |
|
59 | + */ |
|
60 | 60 | protected $payment_form = null; |
61 | 61 | |
62 | 62 | /** |
63 | - * The country for the submission. |
|
64 | - * |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - public $country = null; |
|
68 | - |
|
69 | - /** |
|
70 | - * The state for the submission. |
|
71 | - * |
|
72 | - * @since 1.0.19 |
|
73 | - * @var string |
|
74 | - */ |
|
75 | - public $state = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * The invoice associated with the submission. |
|
79 | - * |
|
80 | - * @var WPInv_Invoice |
|
81 | - */ |
|
82 | - protected $invoice = null; |
|
83 | - |
|
84 | - /** |
|
85 | - * The recurring item for the submission. |
|
86 | - * |
|
87 | - * @var int |
|
88 | - */ |
|
89 | - public $has_recurring = 0; |
|
90 | - |
|
91 | - /** |
|
92 | - * An array of fees for the submission. |
|
93 | - * |
|
94 | - * @var array |
|
95 | - */ |
|
96 | - protected $fees = array(); |
|
97 | - |
|
98 | - /** |
|
99 | - * An array of discounts for the submission. |
|
100 | - * |
|
101 | - * @var array |
|
102 | - */ |
|
103 | - protected $discounts = array(); |
|
104 | - |
|
105 | - /** |
|
106 | - * An array of taxes for the submission. |
|
107 | - * |
|
108 | - * @var array |
|
109 | - */ |
|
110 | - protected $taxes = array(); |
|
111 | - |
|
112 | - /** |
|
113 | - * An array of items for the submission. |
|
114 | - * |
|
115 | - * @var GetPaid_Form_Item[] |
|
116 | - */ |
|
117 | - protected $items = array(); |
|
118 | - |
|
119 | - /** |
|
120 | - * The last error. |
|
121 | - * |
|
122 | - * @var string |
|
123 | - */ |
|
124 | - public $last_error = null; |
|
125 | - |
|
126 | - /** |
|
127 | - * Class constructor. |
|
128 | - * |
|
129 | - */ |
|
130 | - public function __construct() { |
|
131 | - |
|
132 | - // Set the state and country to the default state and country. |
|
133 | - $this->country = wpinv_default_billing_country(); |
|
134 | - $this->state = wpinv_get_default_state(); |
|
135 | - |
|
136 | - // Do we have an actual submission? |
|
137 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
138 | - $this->load_data( $_POST ); |
|
139 | - } |
|
140 | - |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Loads submission data. |
|
145 | - * |
|
146 | - * @param array $data |
|
147 | - */ |
|
148 | - public function load_data( $data ) { |
|
149 | - |
|
150 | - // Remove slashes from the submitted data... |
|
151 | - $data = wp_unslash( $data ); |
|
152 | - |
|
153 | - // Allow plugins to filter the data. |
|
154 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
155 | - |
|
156 | - // Cache it... |
|
157 | - $this->data = $data; |
|
158 | - |
|
159 | - // Then generate a unique id from the data. |
|
160 | - $this->id = md5( wp_json_encode( $data ) ); |
|
161 | - |
|
162 | - // Finally, process the submission. |
|
163 | - try { |
|
164 | - |
|
165 | - // Each process is passed an instance of the class (with reference) |
|
166 | - // and should throw an Exception whenever it encounters one. |
|
167 | - $processors = apply_filters( |
|
168 | - 'getpaid_payment_form_submission_processors', |
|
169 | - array( |
|
170 | - array( $this, 'process_payment_form' ), |
|
171 | - array( $this, 'process_invoice' ), |
|
172 | - array( $this, 'process_fees' ), |
|
173 | - array( $this, 'process_items' ), |
|
174 | - array( $this, 'process_taxes' ), |
|
175 | - array( $this, 'process_discount' ), |
|
176 | - ), |
|
177 | - $this |
|
178 | - ); |
|
179 | - |
|
180 | - foreach ( $processors as $processor ) { |
|
181 | - call_user_func_array( $processor, array( &$this ) ); |
|
182 | - } |
|
183 | - |
|
184 | - } catch ( Exception $e ) { |
|
185 | - $this->last_error = $e->getMessage(); |
|
186 | - } |
|
187 | - |
|
188 | - // Fired when we are done processing a submission. |
|
189 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
190 | - |
|
191 | - } |
|
192 | - |
|
193 | - /* |
|
63 | + * The country for the submission. |
|
64 | + * |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + public $country = null; |
|
68 | + |
|
69 | + /** |
|
70 | + * The state for the submission. |
|
71 | + * |
|
72 | + * @since 1.0.19 |
|
73 | + * @var string |
|
74 | + */ |
|
75 | + public $state = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * The invoice associated with the submission. |
|
79 | + * |
|
80 | + * @var WPInv_Invoice |
|
81 | + */ |
|
82 | + protected $invoice = null; |
|
83 | + |
|
84 | + /** |
|
85 | + * The recurring item for the submission. |
|
86 | + * |
|
87 | + * @var int |
|
88 | + */ |
|
89 | + public $has_recurring = 0; |
|
90 | + |
|
91 | + /** |
|
92 | + * An array of fees for the submission. |
|
93 | + * |
|
94 | + * @var array |
|
95 | + */ |
|
96 | + protected $fees = array(); |
|
97 | + |
|
98 | + /** |
|
99 | + * An array of discounts for the submission. |
|
100 | + * |
|
101 | + * @var array |
|
102 | + */ |
|
103 | + protected $discounts = array(); |
|
104 | + |
|
105 | + /** |
|
106 | + * An array of taxes for the submission. |
|
107 | + * |
|
108 | + * @var array |
|
109 | + */ |
|
110 | + protected $taxes = array(); |
|
111 | + |
|
112 | + /** |
|
113 | + * An array of items for the submission. |
|
114 | + * |
|
115 | + * @var GetPaid_Form_Item[] |
|
116 | + */ |
|
117 | + protected $items = array(); |
|
118 | + |
|
119 | + /** |
|
120 | + * The last error. |
|
121 | + * |
|
122 | + * @var string |
|
123 | + */ |
|
124 | + public $last_error = null; |
|
125 | + |
|
126 | + /** |
|
127 | + * Class constructor. |
|
128 | + * |
|
129 | + */ |
|
130 | + public function __construct() { |
|
131 | + |
|
132 | + // Set the state and country to the default state and country. |
|
133 | + $this->country = wpinv_default_billing_country(); |
|
134 | + $this->state = wpinv_get_default_state(); |
|
135 | + |
|
136 | + // Do we have an actual submission? |
|
137 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
138 | + $this->load_data( $_POST ); |
|
139 | + } |
|
140 | + |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Loads submission data. |
|
145 | + * |
|
146 | + * @param array $data |
|
147 | + */ |
|
148 | + public function load_data( $data ) { |
|
149 | + |
|
150 | + // Remove slashes from the submitted data... |
|
151 | + $data = wp_unslash( $data ); |
|
152 | + |
|
153 | + // Allow plugins to filter the data. |
|
154 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
155 | + |
|
156 | + // Cache it... |
|
157 | + $this->data = $data; |
|
158 | + |
|
159 | + // Then generate a unique id from the data. |
|
160 | + $this->id = md5( wp_json_encode( $data ) ); |
|
161 | + |
|
162 | + // Finally, process the submission. |
|
163 | + try { |
|
164 | + |
|
165 | + // Each process is passed an instance of the class (with reference) |
|
166 | + // and should throw an Exception whenever it encounters one. |
|
167 | + $processors = apply_filters( |
|
168 | + 'getpaid_payment_form_submission_processors', |
|
169 | + array( |
|
170 | + array( $this, 'process_payment_form' ), |
|
171 | + array( $this, 'process_invoice' ), |
|
172 | + array( $this, 'process_fees' ), |
|
173 | + array( $this, 'process_items' ), |
|
174 | + array( $this, 'process_taxes' ), |
|
175 | + array( $this, 'process_discount' ), |
|
176 | + ), |
|
177 | + $this |
|
178 | + ); |
|
179 | + |
|
180 | + foreach ( $processors as $processor ) { |
|
181 | + call_user_func_array( $processor, array( &$this ) ); |
|
182 | + } |
|
183 | + |
|
184 | + } catch ( Exception $e ) { |
|
185 | + $this->last_error = $e->getMessage(); |
|
186 | + } |
|
187 | + |
|
188 | + // Fired when we are done processing a submission. |
|
189 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
190 | + |
|
191 | + } |
|
192 | + |
|
193 | + /* |
|
194 | 194 | |-------------------------------------------------------------------------- |
195 | 195 | | Payment Forms. |
196 | 196 | |-------------------------------------------------------------------------- |
@@ -199,39 +199,39 @@ discard block |
||
199 | 199 | | submission has an active payment form etc. |
200 | 200 | */ |
201 | 201 | |
202 | - /** |
|
203 | - * Prepares the submission's payment form. |
|
204 | - * |
|
205 | - * @since 1.0.19 |
|
206 | - */ |
|
207 | - public function process_payment_form() { |
|
202 | + /** |
|
203 | + * Prepares the submission's payment form. |
|
204 | + * |
|
205 | + * @since 1.0.19 |
|
206 | + */ |
|
207 | + public function process_payment_form() { |
|
208 | 208 | |
209 | - // Every submission needs an active payment form. |
|
210 | - if ( empty( $this->data['form_id'] ) ) { |
|
211 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
212 | - } |
|
209 | + // Every submission needs an active payment form. |
|
210 | + if ( empty( $this->data['form_id'] ) ) { |
|
211 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
212 | + } |
|
213 | 213 | |
214 | - // Fetch the payment form. |
|
215 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
214 | + // Fetch the payment form. |
|
215 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
216 | 216 | |
217 | - if ( ! $this->payment_form->is_active() ) { |
|
218 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
219 | - } |
|
217 | + if ( ! $this->payment_form->is_active() ) { |
|
218 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
219 | + } |
|
220 | 220 | |
221 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
222 | - } |
|
221 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
222 | + } |
|
223 | 223 | |
224 | 224 | /** |
225 | - * Returns the payment form. |
|
226 | - * |
|
227 | - * @since 1.0.19 |
|
228 | - * @return GetPaid_Payment_Form |
|
229 | - */ |
|
230 | - public function get_payment_form() { |
|
231 | - return $this->payment_form; |
|
232 | - } |
|
225 | + * Returns the payment form. |
|
226 | + * |
|
227 | + * @since 1.0.19 |
|
228 | + * @return GetPaid_Payment_Form |
|
229 | + */ |
|
230 | + public function get_payment_form() { |
|
231 | + return $this->payment_form; |
|
232 | + } |
|
233 | 233 | |
234 | - /* |
|
234 | + /* |
|
235 | 235 | |-------------------------------------------------------------------------- |
236 | 236 | | Invoices. |
237 | 237 | |-------------------------------------------------------------------------- |
@@ -240,61 +240,61 @@ discard block |
||
240 | 240 | | might be for an existing invoice. |
241 | 241 | */ |
242 | 242 | |
243 | - /** |
|
244 | - * Prepares the submission's invoice. |
|
245 | - * |
|
246 | - * @since 1.0.19 |
|
247 | - */ |
|
248 | - public function process_invoice() { |
|
243 | + /** |
|
244 | + * Prepares the submission's invoice. |
|
245 | + * |
|
246 | + * @since 1.0.19 |
|
247 | + */ |
|
248 | + public function process_invoice() { |
|
249 | 249 | |
250 | - // Abort if there is no invoice. |
|
251 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
252 | - return; |
|
253 | - } |
|
250 | + // Abort if there is no invoice. |
|
251 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
252 | + return; |
|
253 | + } |
|
254 | 254 | |
255 | - // If the submission is for an existing invoice, ensure that it exists |
|
256 | - // and that it is not paid for. |
|
257 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
255 | + // If the submission is for an existing invoice, ensure that it exists |
|
256 | + // and that it is not paid for. |
|
257 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
258 | 258 | |
259 | 259 | if ( empty( $invoice ) ) { |
260 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
261 | - } |
|
262 | - |
|
263 | - if ( $invoice->is_paid() ) { |
|
264 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
265 | - } |
|
266 | - |
|
267 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
268 | - $this->payment_form->invoice = $invoice; |
|
269 | - |
|
270 | - $this->country = $invoice->get_country(); |
|
271 | - $this->state = $invoice->get_state(); |
|
272 | - $this->invoice = $invoice; |
|
273 | - |
|
274 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Returns the associated invoice. |
|
279 | - * |
|
280 | - * @since 1.0.19 |
|
281 | - * @return WPInv_Invoice |
|
282 | - */ |
|
283 | - public function get_invoice() { |
|
284 | - return $this->invoice; |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * Checks whether there is an invoice associated with this submission. |
|
289 | - * |
|
290 | - * @since 1.0.19 |
|
291 | - * @return bool |
|
292 | - */ |
|
293 | - public function has_invoice() { |
|
294 | - return ! empty( $this->invoice ); |
|
295 | - } |
|
296 | - |
|
297 | - /* |
|
260 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
261 | + } |
|
262 | + |
|
263 | + if ( $invoice->is_paid() ) { |
|
264 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
265 | + } |
|
266 | + |
|
267 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
268 | + $this->payment_form->invoice = $invoice; |
|
269 | + |
|
270 | + $this->country = $invoice->get_country(); |
|
271 | + $this->state = $invoice->get_state(); |
|
272 | + $this->invoice = $invoice; |
|
273 | + |
|
274 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Returns the associated invoice. |
|
279 | + * |
|
280 | + * @since 1.0.19 |
|
281 | + * @return WPInv_Invoice |
|
282 | + */ |
|
283 | + public function get_invoice() { |
|
284 | + return $this->invoice; |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * Checks whether there is an invoice associated with this submission. |
|
289 | + * |
|
290 | + * @since 1.0.19 |
|
291 | + * @return bool |
|
292 | + */ |
|
293 | + public function has_invoice() { |
|
294 | + return ! empty( $this->invoice ); |
|
295 | + } |
|
296 | + |
|
297 | + /* |
|
298 | 298 | |-------------------------------------------------------------------------- |
299 | 299 | | Items. |
300 | 300 | |-------------------------------------------------------------------------- |
@@ -303,115 +303,115 @@ discard block |
||
303 | 303 | | recurring item. But can have an unlimited number of non-recurring items. |
304 | 304 | */ |
305 | 305 | |
306 | - /** |
|
307 | - * Prepares the submission's items. |
|
308 | - * |
|
309 | - * @since 1.0.19 |
|
310 | - */ |
|
311 | - public function process_items() { |
|
312 | - |
|
313 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
314 | - |
|
315 | - foreach ( $processor->items as $item ) { |
|
316 | - $this->add_item( $item ); |
|
317 | - } |
|
318 | - |
|
319 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Adds an item to the submission. |
|
324 | - * |
|
325 | - * @since 1.0.19 |
|
326 | - * @param GetPaid_Form_Item $item |
|
327 | - */ |
|
328 | - public function add_item( $item ) { |
|
329 | - |
|
330 | - // Make sure that it is available for purchase. |
|
331 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
332 | - return; |
|
333 | - } |
|
334 | - |
|
335 | - // Each submission can only contain one recurring item. |
|
336 | - if ( $item->is_recurring() ) { |
|
337 | - |
|
338 | - if ( $this->has_recurring != 0 ) { |
|
339 | - throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
340 | - } |
|
341 | - |
|
342 | - $this->has_recurring = $item->get_id(); |
|
343 | - |
|
344 | - } |
|
345 | - |
|
346 | - // Update the items and totals. |
|
347 | - $this->items[ $item->get_id() ] = $item; |
|
348 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
349 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
350 | - |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * Removes a specific item. |
|
355 | - * |
|
356 | - * You should not call this method after the discounts and taxes |
|
357 | - * have been calculated. |
|
358 | - * |
|
359 | - * @since 1.0.19 |
|
360 | - */ |
|
361 | - public function remove_item( $item_id ) { |
|
362 | - |
|
363 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
364 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
365 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
366 | - |
|
367 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
368 | - $this->has_recurring = 0; |
|
369 | - } |
|
370 | - |
|
371 | - unset( $this->items[ $item_id ] ); |
|
372 | - } |
|
373 | - |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * Returns the subtotal. |
|
378 | - * |
|
379 | - * @since 1.0.19 |
|
380 | - */ |
|
381 | - public function get_subtotal() { |
|
382 | - |
|
383 | - if ( wpinv_prices_include_tax() ) { |
|
384 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
385 | - } |
|
386 | - |
|
387 | - return $this->totals['subtotal']['initial']; |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * Returns the recurring subtotal. |
|
392 | - * |
|
393 | - * @since 1.0.19 |
|
394 | - */ |
|
395 | - public function get_recurring_subtotal() { |
|
396 | - |
|
397 | - if ( wpinv_prices_include_tax() ) { |
|
398 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
399 | - } |
|
400 | - |
|
401 | - return $this->totals['subtotal']['recurring']; |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Returns all items. |
|
406 | - * |
|
407 | - * @since 1.0.19 |
|
408 | - * @return GetPaid_Form_Item[] |
|
409 | - */ |
|
410 | - public function get_items() { |
|
411 | - return $this->items; |
|
412 | - } |
|
413 | - |
|
414 | - /* |
|
306 | + /** |
|
307 | + * Prepares the submission's items. |
|
308 | + * |
|
309 | + * @since 1.0.19 |
|
310 | + */ |
|
311 | + public function process_items() { |
|
312 | + |
|
313 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
314 | + |
|
315 | + foreach ( $processor->items as $item ) { |
|
316 | + $this->add_item( $item ); |
|
317 | + } |
|
318 | + |
|
319 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Adds an item to the submission. |
|
324 | + * |
|
325 | + * @since 1.0.19 |
|
326 | + * @param GetPaid_Form_Item $item |
|
327 | + */ |
|
328 | + public function add_item( $item ) { |
|
329 | + |
|
330 | + // Make sure that it is available for purchase. |
|
331 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
332 | + return; |
|
333 | + } |
|
334 | + |
|
335 | + // Each submission can only contain one recurring item. |
|
336 | + if ( $item->is_recurring() ) { |
|
337 | + |
|
338 | + if ( $this->has_recurring != 0 ) { |
|
339 | + throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
340 | + } |
|
341 | + |
|
342 | + $this->has_recurring = $item->get_id(); |
|
343 | + |
|
344 | + } |
|
345 | + |
|
346 | + // Update the items and totals. |
|
347 | + $this->items[ $item->get_id() ] = $item; |
|
348 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
349 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
350 | + |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * Removes a specific item. |
|
355 | + * |
|
356 | + * You should not call this method after the discounts and taxes |
|
357 | + * have been calculated. |
|
358 | + * |
|
359 | + * @since 1.0.19 |
|
360 | + */ |
|
361 | + public function remove_item( $item_id ) { |
|
362 | + |
|
363 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
364 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
365 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
366 | + |
|
367 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
368 | + $this->has_recurring = 0; |
|
369 | + } |
|
370 | + |
|
371 | + unset( $this->items[ $item_id ] ); |
|
372 | + } |
|
373 | + |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * Returns the subtotal. |
|
378 | + * |
|
379 | + * @since 1.0.19 |
|
380 | + */ |
|
381 | + public function get_subtotal() { |
|
382 | + |
|
383 | + if ( wpinv_prices_include_tax() ) { |
|
384 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
385 | + } |
|
386 | + |
|
387 | + return $this->totals['subtotal']['initial']; |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * Returns the recurring subtotal. |
|
392 | + * |
|
393 | + * @since 1.0.19 |
|
394 | + */ |
|
395 | + public function get_recurring_subtotal() { |
|
396 | + |
|
397 | + if ( wpinv_prices_include_tax() ) { |
|
398 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
399 | + } |
|
400 | + |
|
401 | + return $this->totals['subtotal']['recurring']; |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Returns all items. |
|
406 | + * |
|
407 | + * @since 1.0.19 |
|
408 | + * @return GetPaid_Form_Item[] |
|
409 | + */ |
|
410 | + public function get_items() { |
|
411 | + return $this->items; |
|
412 | + } |
|
413 | + |
|
414 | + /* |
|
415 | 415 | |-------------------------------------------------------------------------- |
416 | 416 | | Taxes |
417 | 417 | |-------------------------------------------------------------------------- |
@@ -420,122 +420,122 @@ discard block |
||
420 | 420 | | or only one-time. |
421 | 421 | */ |
422 | 422 | |
423 | - /** |
|
424 | - * Prepares the submission's taxes. |
|
425 | - * |
|
426 | - * @since 1.0.19 |
|
427 | - */ |
|
428 | - public function process_taxes() { |
|
429 | - |
|
430 | - // Abort if we're not using taxes. |
|
431 | - if ( ! $this->use_taxes() ) { |
|
432 | - return; |
|
433 | - } |
|
434 | - |
|
435 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
436 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
437 | - if ( ! empty( $country ) ) { |
|
438 | - $this->country = $country; |
|
439 | - } |
|
440 | - |
|
441 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
442 | - if ( ! empty( $state ) ) { |
|
443 | - $this->state = $state; |
|
444 | - } |
|
445 | - |
|
446 | - // Abort if the country is not taxable. |
|
447 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
448 | - return; |
|
449 | - } |
|
450 | - |
|
451 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
452 | - |
|
453 | - foreach ( $processor->taxes as $tax ) { |
|
454 | - $this->add_tax( $tax ); |
|
455 | - } |
|
456 | - |
|
457 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
458 | - } |
|
459 | - |
|
460 | - /** |
|
461 | - * Adds a tax to the submission. |
|
462 | - * |
|
463 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
464 | - * @since 1.0.19 |
|
465 | - */ |
|
466 | - public function add_tax( $tax ) { |
|
467 | - |
|
468 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
469 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
470 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
471 | - } |
|
472 | - |
|
473 | - $this->taxes[ $tax['name'] ] = $tax; |
|
474 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
475 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
476 | - |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * Removes a specific tax. |
|
481 | - * |
|
482 | - * @since 1.0.19 |
|
483 | - */ |
|
484 | - public function remove_tax( $tax_name ) { |
|
485 | - |
|
486 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
487 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
488 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
489 | - unset( $this->taxes[ $tax_name ] ); |
|
490 | - } |
|
491 | - |
|
492 | - } |
|
493 | - |
|
494 | - /** |
|
495 | - * Whether or not we'll use taxes for the submission. |
|
496 | - * |
|
497 | - * @since 1.0.19 |
|
498 | - */ |
|
499 | - public function use_taxes() { |
|
500 | - |
|
501 | - $use_taxes = wpinv_use_taxes(); |
|
502 | - |
|
503 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
504 | - $use_taxes = false; |
|
505 | - } |
|
506 | - |
|
507 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
508 | - |
|
509 | - } |
|
510 | - |
|
511 | - /** |
|
512 | - * Returns the tax. |
|
513 | - * |
|
514 | - * @since 1.0.19 |
|
515 | - */ |
|
516 | - public function get_tax() { |
|
517 | - return $this->totals['taxes']['initial']; |
|
518 | - } |
|
519 | - |
|
520 | - /** |
|
521 | - * Returns the recurring tax. |
|
522 | - * |
|
523 | - * @since 1.0.19 |
|
524 | - */ |
|
525 | - public function get_recurring_tax() { |
|
526 | - return $this->totals['taxes']['recurring']; |
|
527 | - } |
|
528 | - |
|
529 | - /** |
|
530 | - * Returns all taxes. |
|
531 | - * |
|
532 | - * @since 1.0.19 |
|
533 | - */ |
|
534 | - public function get_taxes() { |
|
535 | - return $this->taxes; |
|
536 | - } |
|
537 | - |
|
538 | - /* |
|
423 | + /** |
|
424 | + * Prepares the submission's taxes. |
|
425 | + * |
|
426 | + * @since 1.0.19 |
|
427 | + */ |
|
428 | + public function process_taxes() { |
|
429 | + |
|
430 | + // Abort if we're not using taxes. |
|
431 | + if ( ! $this->use_taxes() ) { |
|
432 | + return; |
|
433 | + } |
|
434 | + |
|
435 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
436 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
437 | + if ( ! empty( $country ) ) { |
|
438 | + $this->country = $country; |
|
439 | + } |
|
440 | + |
|
441 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
442 | + if ( ! empty( $state ) ) { |
|
443 | + $this->state = $state; |
|
444 | + } |
|
445 | + |
|
446 | + // Abort if the country is not taxable. |
|
447 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
448 | + return; |
|
449 | + } |
|
450 | + |
|
451 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
452 | + |
|
453 | + foreach ( $processor->taxes as $tax ) { |
|
454 | + $this->add_tax( $tax ); |
|
455 | + } |
|
456 | + |
|
457 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
458 | + } |
|
459 | + |
|
460 | + /** |
|
461 | + * Adds a tax to the submission. |
|
462 | + * |
|
463 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
464 | + * @since 1.0.19 |
|
465 | + */ |
|
466 | + public function add_tax( $tax ) { |
|
467 | + |
|
468 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
469 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
470 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
471 | + } |
|
472 | + |
|
473 | + $this->taxes[ $tax['name'] ] = $tax; |
|
474 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
475 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
476 | + |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * Removes a specific tax. |
|
481 | + * |
|
482 | + * @since 1.0.19 |
|
483 | + */ |
|
484 | + public function remove_tax( $tax_name ) { |
|
485 | + |
|
486 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
487 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
488 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
489 | + unset( $this->taxes[ $tax_name ] ); |
|
490 | + } |
|
491 | + |
|
492 | + } |
|
493 | + |
|
494 | + /** |
|
495 | + * Whether or not we'll use taxes for the submission. |
|
496 | + * |
|
497 | + * @since 1.0.19 |
|
498 | + */ |
|
499 | + public function use_taxes() { |
|
500 | + |
|
501 | + $use_taxes = wpinv_use_taxes(); |
|
502 | + |
|
503 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
504 | + $use_taxes = false; |
|
505 | + } |
|
506 | + |
|
507 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
508 | + |
|
509 | + } |
|
510 | + |
|
511 | + /** |
|
512 | + * Returns the tax. |
|
513 | + * |
|
514 | + * @since 1.0.19 |
|
515 | + */ |
|
516 | + public function get_tax() { |
|
517 | + return $this->totals['taxes']['initial']; |
|
518 | + } |
|
519 | + |
|
520 | + /** |
|
521 | + * Returns the recurring tax. |
|
522 | + * |
|
523 | + * @since 1.0.19 |
|
524 | + */ |
|
525 | + public function get_recurring_tax() { |
|
526 | + return $this->totals['taxes']['recurring']; |
|
527 | + } |
|
528 | + |
|
529 | + /** |
|
530 | + * Returns all taxes. |
|
531 | + * |
|
532 | + * @since 1.0.19 |
|
533 | + */ |
|
534 | + public function get_taxes() { |
|
535 | + return $this->taxes; |
|
536 | + } |
|
537 | + |
|
538 | + /* |
|
539 | 539 | |-------------------------------------------------------------------------- |
540 | 540 | | Discounts |
541 | 541 | |-------------------------------------------------------------------------- |
@@ -544,99 +544,99 @@ discard block |
||
544 | 544 | | or only one-time. They also do not have to come from a discount code. |
545 | 545 | */ |
546 | 546 | |
547 | - /** |
|
548 | - * Prepares the submission's discount. |
|
549 | - * |
|
550 | - * @since 1.0.19 |
|
551 | - */ |
|
552 | - public function process_discount() { |
|
553 | - |
|
554 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
555 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
556 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
557 | - |
|
558 | - foreach ( $processor->discounts as $discount ) { |
|
559 | - $this->add_discount( $discount ); |
|
560 | - } |
|
561 | - |
|
562 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
563 | - } |
|
564 | - |
|
565 | - /** |
|
566 | - * Adds a discount to the submission. |
|
567 | - * |
|
568 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
569 | - * @since 1.0.19 |
|
570 | - */ |
|
571 | - public function add_discount( $discount ) { |
|
572 | - $this->discounts[ $discount['name'] ] = $discount; |
|
573 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
574 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * Removes a discount from the submission. |
|
579 | - * |
|
580 | - * @since 1.0.19 |
|
581 | - */ |
|
582 | - public function remove_discount( $name ) { |
|
583 | - |
|
584 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
585 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
586 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
587 | - unset( $this->discounts[ $name ] ); |
|
588 | - } |
|
589 | - |
|
590 | - } |
|
591 | - |
|
592 | - /** |
|
593 | - * Checks whether there is a discount code associated with this submission. |
|
594 | - * |
|
595 | - * @since 1.0.19 |
|
596 | - * @return bool |
|
597 | - */ |
|
598 | - public function has_discount_code() { |
|
599 | - return ! empty( $this->discounts['discount_code'] ); |
|
600 | - } |
|
601 | - |
|
602 | - /** |
|
603 | - * Returns the discount code. |
|
604 | - * |
|
605 | - * @since 1.0.19 |
|
606 | - * @return string |
|
607 | - */ |
|
608 | - public function get_discount_code() { |
|
609 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
610 | - } |
|
611 | - |
|
612 | - /** |
|
613 | - * Returns the discount. |
|
614 | - * |
|
615 | - * @since 1.0.19 |
|
616 | - */ |
|
617 | - public function get_discount() { |
|
618 | - return $this->totals['discount']['initial']; |
|
619 | - } |
|
620 | - |
|
621 | - /** |
|
622 | - * Returns the recurring discount. |
|
623 | - * |
|
624 | - * @since 1.0.19 |
|
625 | - */ |
|
626 | - public function get_recurring_discount() { |
|
627 | - return $this->totals['discount']['recurring']; |
|
628 | - } |
|
629 | - |
|
630 | - /** |
|
631 | - * Returns all discounts. |
|
632 | - * |
|
633 | - * @since 1.0.19 |
|
634 | - */ |
|
635 | - public function get_discounts() { |
|
636 | - return $this->discounts; |
|
637 | - } |
|
638 | - |
|
639 | - /* |
|
547 | + /** |
|
548 | + * Prepares the submission's discount. |
|
549 | + * |
|
550 | + * @since 1.0.19 |
|
551 | + */ |
|
552 | + public function process_discount() { |
|
553 | + |
|
554 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
555 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
556 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
557 | + |
|
558 | + foreach ( $processor->discounts as $discount ) { |
|
559 | + $this->add_discount( $discount ); |
|
560 | + } |
|
561 | + |
|
562 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
563 | + } |
|
564 | + |
|
565 | + /** |
|
566 | + * Adds a discount to the submission. |
|
567 | + * |
|
568 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
569 | + * @since 1.0.19 |
|
570 | + */ |
|
571 | + public function add_discount( $discount ) { |
|
572 | + $this->discounts[ $discount['name'] ] = $discount; |
|
573 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
574 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * Removes a discount from the submission. |
|
579 | + * |
|
580 | + * @since 1.0.19 |
|
581 | + */ |
|
582 | + public function remove_discount( $name ) { |
|
583 | + |
|
584 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
585 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
586 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
587 | + unset( $this->discounts[ $name ] ); |
|
588 | + } |
|
589 | + |
|
590 | + } |
|
591 | + |
|
592 | + /** |
|
593 | + * Checks whether there is a discount code associated with this submission. |
|
594 | + * |
|
595 | + * @since 1.0.19 |
|
596 | + * @return bool |
|
597 | + */ |
|
598 | + public function has_discount_code() { |
|
599 | + return ! empty( $this->discounts['discount_code'] ); |
|
600 | + } |
|
601 | + |
|
602 | + /** |
|
603 | + * Returns the discount code. |
|
604 | + * |
|
605 | + * @since 1.0.19 |
|
606 | + * @return string |
|
607 | + */ |
|
608 | + public function get_discount_code() { |
|
609 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
610 | + } |
|
611 | + |
|
612 | + /** |
|
613 | + * Returns the discount. |
|
614 | + * |
|
615 | + * @since 1.0.19 |
|
616 | + */ |
|
617 | + public function get_discount() { |
|
618 | + return $this->totals['discount']['initial']; |
|
619 | + } |
|
620 | + |
|
621 | + /** |
|
622 | + * Returns the recurring discount. |
|
623 | + * |
|
624 | + * @since 1.0.19 |
|
625 | + */ |
|
626 | + public function get_recurring_discount() { |
|
627 | + return $this->totals['discount']['recurring']; |
|
628 | + } |
|
629 | + |
|
630 | + /** |
|
631 | + * Returns all discounts. |
|
632 | + * |
|
633 | + * @since 1.0.19 |
|
634 | + */ |
|
635 | + public function get_discounts() { |
|
636 | + return $this->discounts; |
|
637 | + } |
|
638 | + |
|
639 | + /* |
|
640 | 640 | |-------------------------------------------------------------------------- |
641 | 641 | | Fees |
642 | 642 | |-------------------------------------------------------------------------- |
@@ -646,89 +646,89 @@ discard block |
||
646 | 646 | | fees. |
647 | 647 | */ |
648 | 648 | |
649 | - /** |
|
650 | - * Prepares the submission's fees. |
|
651 | - * |
|
652 | - * @since 1.0.19 |
|
653 | - */ |
|
654 | - public function process_fees() { |
|
655 | - |
|
656 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
657 | - |
|
658 | - foreach ( $fees_processor->fees as $fee ) { |
|
659 | - $this->add_fee( $fee ); |
|
660 | - } |
|
661 | - |
|
662 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
663 | - } |
|
664 | - |
|
665 | - /** |
|
666 | - * Adds a fee to the submission. |
|
667 | - * |
|
668 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
669 | - * @since 1.0.19 |
|
670 | - */ |
|
671 | - public function add_fee( $fee ) { |
|
672 | - |
|
673 | - $this->fees[ $fee['name'] ] = $fee; |
|
674 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
675 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
676 | - |
|
677 | - } |
|
678 | - |
|
679 | - /** |
|
680 | - * Removes a fee from the submission. |
|
681 | - * |
|
682 | - * @since 1.0.19 |
|
683 | - */ |
|
684 | - public function remove_fee( $name ) { |
|
685 | - |
|
686 | - if ( isset( $this->fees[ $name ] ) ) { |
|
687 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
688 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
689 | - unset( $this->fees[ $name ] ); |
|
690 | - } |
|
691 | - |
|
692 | - } |
|
693 | - |
|
694 | - /** |
|
695 | - * Returns the fees. |
|
696 | - * |
|
697 | - * @since 1.0.19 |
|
698 | - */ |
|
699 | - public function get_fee() { |
|
700 | - return $this->totals['fees']['initial']; |
|
701 | - } |
|
702 | - |
|
703 | - /** |
|
704 | - * Returns the recurring fees. |
|
705 | - * |
|
706 | - * @since 1.0.19 |
|
707 | - */ |
|
708 | - public function get_recurring_fee() { |
|
709 | - return $this->totals['fees']['recurring']; |
|
710 | - } |
|
711 | - |
|
712 | - /** |
|
713 | - * Returns all fees. |
|
714 | - * |
|
715 | - * @since 1.0.19 |
|
716 | - */ |
|
717 | - public function get_fees() { |
|
718 | - return $this->fees; |
|
719 | - } |
|
720 | - |
|
721 | - /** |
|
722 | - * Checks if there are any fees for the form. |
|
723 | - * |
|
724 | - * @return bool |
|
725 | - * @since 1.0.19 |
|
726 | - */ |
|
727 | - public function has_fees() { |
|
728 | - return count( $this->fees ) !== 0; |
|
729 | - } |
|
730 | - |
|
731 | - /* |
|
649 | + /** |
|
650 | + * Prepares the submission's fees. |
|
651 | + * |
|
652 | + * @since 1.0.19 |
|
653 | + */ |
|
654 | + public function process_fees() { |
|
655 | + |
|
656 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
657 | + |
|
658 | + foreach ( $fees_processor->fees as $fee ) { |
|
659 | + $this->add_fee( $fee ); |
|
660 | + } |
|
661 | + |
|
662 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
663 | + } |
|
664 | + |
|
665 | + /** |
|
666 | + * Adds a fee to the submission. |
|
667 | + * |
|
668 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
669 | + * @since 1.0.19 |
|
670 | + */ |
|
671 | + public function add_fee( $fee ) { |
|
672 | + |
|
673 | + $this->fees[ $fee['name'] ] = $fee; |
|
674 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
675 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
676 | + |
|
677 | + } |
|
678 | + |
|
679 | + /** |
|
680 | + * Removes a fee from the submission. |
|
681 | + * |
|
682 | + * @since 1.0.19 |
|
683 | + */ |
|
684 | + public function remove_fee( $name ) { |
|
685 | + |
|
686 | + if ( isset( $this->fees[ $name ] ) ) { |
|
687 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
688 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
689 | + unset( $this->fees[ $name ] ); |
|
690 | + } |
|
691 | + |
|
692 | + } |
|
693 | + |
|
694 | + /** |
|
695 | + * Returns the fees. |
|
696 | + * |
|
697 | + * @since 1.0.19 |
|
698 | + */ |
|
699 | + public function get_fee() { |
|
700 | + return $this->totals['fees']['initial']; |
|
701 | + } |
|
702 | + |
|
703 | + /** |
|
704 | + * Returns the recurring fees. |
|
705 | + * |
|
706 | + * @since 1.0.19 |
|
707 | + */ |
|
708 | + public function get_recurring_fee() { |
|
709 | + return $this->totals['fees']['recurring']; |
|
710 | + } |
|
711 | + |
|
712 | + /** |
|
713 | + * Returns all fees. |
|
714 | + * |
|
715 | + * @since 1.0.19 |
|
716 | + */ |
|
717 | + public function get_fees() { |
|
718 | + return $this->fees; |
|
719 | + } |
|
720 | + |
|
721 | + /** |
|
722 | + * Checks if there are any fees for the form. |
|
723 | + * |
|
724 | + * @return bool |
|
725 | + * @since 1.0.19 |
|
726 | + */ |
|
727 | + public function has_fees() { |
|
728 | + return count( $this->fees ) !== 0; |
|
729 | + } |
|
730 | + |
|
731 | + /* |
|
732 | 732 | |-------------------------------------------------------------------------- |
733 | 733 | | MISC |
734 | 734 | |-------------------------------------------------------------------------- |
@@ -736,109 +736,109 @@ discard block |
||
736 | 736 | | Extra submission functions. |
737 | 737 | */ |
738 | 738 | |
739 | - /** |
|
740 | - * Returns the total amount to collect for this submission. |
|
741 | - * |
|
742 | - * @since 1.0.19 |
|
743 | - */ |
|
744 | - public function get_total() { |
|
745 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
746 | - return max( $total, 0 ); |
|
747 | - } |
|
748 | - |
|
749 | - /** |
|
750 | - * Returns the recurring total amount to collect for this submission. |
|
751 | - * |
|
752 | - * @since 1.0.19 |
|
753 | - */ |
|
754 | - public function get_recurring_total() { |
|
755 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
756 | - return max( $total, 0 ); |
|
757 | - } |
|
758 | - |
|
759 | - /** |
|
760 | - * Whether payment details should be collected for this submission. |
|
761 | - * |
|
762 | - * @since 1.0.19 |
|
763 | - */ |
|
764 | - public function should_collect_payment_details() { |
|
765 | - $initial = $this->get_total(); |
|
766 | - $recurring = $this->get_recurring_total(); |
|
767 | - |
|
768 | - if ( $this->has_recurring == 0 ) { |
|
769 | - $recurring = 0; |
|
770 | - } |
|
771 | - |
|
772 | - $collect = $initial > 0 || $recurring > 0; |
|
773 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
774 | - } |
|
775 | - |
|
776 | - /** |
|
777 | - * Returns the billing email of the user. |
|
778 | - * |
|
779 | - * @since 1.0.19 |
|
780 | - */ |
|
781 | - public function get_billing_email() { |
|
782 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
783 | - } |
|
784 | - |
|
785 | - /** |
|
786 | - * Checks if the submitter has a billing email. |
|
787 | - * |
|
788 | - * @since 1.0.19 |
|
789 | - */ |
|
790 | - public function has_billing_email() { |
|
791 | - $billing_email = $this->get_billing_email(); |
|
792 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
793 | - } |
|
794 | - |
|
795 | - /** |
|
796 | - * Returns the appropriate currency for the submission. |
|
797 | - * |
|
798 | - * @since 1.0.19 |
|
799 | - * @return string |
|
800 | - */ |
|
801 | - public function get_currency() { |
|
802 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
803 | - } |
|
804 | - |
|
805 | - /** |
|
806 | - * Returns the raw submission data. |
|
807 | - * |
|
808 | - * @since 1.0.19 |
|
809 | - * @return array |
|
810 | - */ |
|
811 | - public function get_data() { |
|
812 | - return $this->data; |
|
813 | - } |
|
814 | - |
|
815 | - /** |
|
816 | - * Returns a field from the submission data |
|
817 | - * |
|
818 | - * @param string $field |
|
819 | - * @since 1.0.19 |
|
820 | - * @return mixed|null |
|
821 | - */ |
|
822 | - public function get_field( $field, $sub_array_key = null ) { |
|
823 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
824 | - } |
|
825 | - |
|
826 | - /** |
|
827 | - * Checks if a required field is set. |
|
828 | - * |
|
829 | - * @since 1.0.19 |
|
830 | - */ |
|
831 | - public function is_required_field_set( $field ) { |
|
832 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
833 | - } |
|
834 | - |
|
835 | - /** |
|
836 | - * Formats an amount |
|
837 | - * |
|
838 | - * @since 1.0.19 |
|
839 | - */ |
|
840 | - public function format_amount( $amount ) { |
|
841 | - return wpinv_price( $amount, $this->get_currency() ); |
|
842 | - } |
|
739 | + /** |
|
740 | + * Returns the total amount to collect for this submission. |
|
741 | + * |
|
742 | + * @since 1.0.19 |
|
743 | + */ |
|
744 | + public function get_total() { |
|
745 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
746 | + return max( $total, 0 ); |
|
747 | + } |
|
748 | + |
|
749 | + /** |
|
750 | + * Returns the recurring total amount to collect for this submission. |
|
751 | + * |
|
752 | + * @since 1.0.19 |
|
753 | + */ |
|
754 | + public function get_recurring_total() { |
|
755 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
756 | + return max( $total, 0 ); |
|
757 | + } |
|
758 | + |
|
759 | + /** |
|
760 | + * Whether payment details should be collected for this submission. |
|
761 | + * |
|
762 | + * @since 1.0.19 |
|
763 | + */ |
|
764 | + public function should_collect_payment_details() { |
|
765 | + $initial = $this->get_total(); |
|
766 | + $recurring = $this->get_recurring_total(); |
|
767 | + |
|
768 | + if ( $this->has_recurring == 0 ) { |
|
769 | + $recurring = 0; |
|
770 | + } |
|
771 | + |
|
772 | + $collect = $initial > 0 || $recurring > 0; |
|
773 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
774 | + } |
|
775 | + |
|
776 | + /** |
|
777 | + * Returns the billing email of the user. |
|
778 | + * |
|
779 | + * @since 1.0.19 |
|
780 | + */ |
|
781 | + public function get_billing_email() { |
|
782 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
783 | + } |
|
784 | + |
|
785 | + /** |
|
786 | + * Checks if the submitter has a billing email. |
|
787 | + * |
|
788 | + * @since 1.0.19 |
|
789 | + */ |
|
790 | + public function has_billing_email() { |
|
791 | + $billing_email = $this->get_billing_email(); |
|
792 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
793 | + } |
|
794 | + |
|
795 | + /** |
|
796 | + * Returns the appropriate currency for the submission. |
|
797 | + * |
|
798 | + * @since 1.0.19 |
|
799 | + * @return string |
|
800 | + */ |
|
801 | + public function get_currency() { |
|
802 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
803 | + } |
|
804 | + |
|
805 | + /** |
|
806 | + * Returns the raw submission data. |
|
807 | + * |
|
808 | + * @since 1.0.19 |
|
809 | + * @return array |
|
810 | + */ |
|
811 | + public function get_data() { |
|
812 | + return $this->data; |
|
813 | + } |
|
814 | + |
|
815 | + /** |
|
816 | + * Returns a field from the submission data |
|
817 | + * |
|
818 | + * @param string $field |
|
819 | + * @since 1.0.19 |
|
820 | + * @return mixed|null |
|
821 | + */ |
|
822 | + public function get_field( $field, $sub_array_key = null ) { |
|
823 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
824 | + } |
|
825 | + |
|
826 | + /** |
|
827 | + * Checks if a required field is set. |
|
828 | + * |
|
829 | + * @since 1.0.19 |
|
830 | + */ |
|
831 | + public function is_required_field_set( $field ) { |
|
832 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
833 | + } |
|
834 | + |
|
835 | + /** |
|
836 | + * Formats an amount |
|
837 | + * |
|
838 | + * @since 1.0.19 |
|
839 | + */ |
|
840 | + public function format_amount( $amount ) { |
|
841 | + return wpinv_price( $amount, $this->get_currency() ); |
|
842 | + } |
|
843 | 843 | |
844 | 844 | } |