@@ -12,236 +12,236 @@ |
||
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 | - } elseif ( '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 | - $meta_fields = $this->get_payment_form_meta( $invoice ); |
|
106 | - |
|
107 | - foreach ( $fields as $field ) { |
|
108 | - $value = ''; |
|
109 | - $method = "get_$field"; |
|
110 | - |
|
111 | - if ( method_exists( $invoice, $method ) ) { |
|
112 | - $value = $invoice->$method(); |
|
113 | - } else if( strpos( $field, '_' ) === 0 && isset( $meta_fields[ $field ] ) ) { |
|
114 | - $value = $meta_fields[ $field ]; |
|
115 | - } |
|
116 | - |
|
117 | - if ( in_array( $field, $amount_fields ) ) { |
|
118 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
119 | - } |
|
120 | - |
|
121 | - $prepared[ $field ] = wpinv_clean( $value ); |
|
122 | - |
|
123 | - } |
|
124 | - |
|
125 | - return $prepared; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Retrieves export fields. |
|
130 | - * |
|
131 | - * @param string $post_type |
|
132 | - * @since 1.0.19 |
|
133 | - * @return array |
|
134 | - */ |
|
135 | - public function get_export_fields( $post_type ) { |
|
136 | - |
|
137 | - $fields = array( |
|
138 | - 'id', |
|
139 | - 'parent_id', |
|
140 | - 'status', |
|
141 | - 'date_created', |
|
142 | - 'date_modified', |
|
143 | - 'date_due', |
|
144 | - 'date_completed', |
|
145 | - 'number', |
|
146 | - 'key', |
|
147 | - 'description', |
|
148 | - 'post_type', |
|
149 | - 'mode', |
|
150 | - 'customer_id', |
|
151 | - 'customer_first_name', |
|
152 | - 'customer_last_name', |
|
153 | - 'customer_phone', |
|
154 | - 'customer_email', |
|
155 | - 'customer_country', |
|
156 | - 'customer_city', |
|
157 | - 'customer_state', |
|
158 | - 'customer_zip', |
|
159 | - 'customer_company', |
|
160 | - 'customer_vat_number', |
|
161 | - 'customer_address', |
|
162 | - 'subtotal', |
|
163 | - 'total_discount', |
|
164 | - 'total_tax', |
|
165 | - 'total_fees', |
|
166 | - 'fees', |
|
167 | - 'discounts', |
|
168 | - 'taxes', |
|
169 | - 'cart_details', |
|
170 | - 'item_ids', |
|
171 | - 'payment_form', |
|
172 | - 'discount_code', |
|
173 | - 'gateway', |
|
174 | - 'transaction_id', |
|
175 | - 'currency', |
|
176 | - 'disable_taxes', |
|
177 | - 'subscription_id', |
|
178 | - 'remote_subscription_id', |
|
179 | - 'is_viewed', |
|
180 | - 'email_cc', |
|
181 | - 'template', |
|
182 | - 'created_via', |
|
183 | - ); |
|
184 | - |
|
185 | - // Payment form meta fields. |
|
186 | - $meta_fields = getpaid_get_payment_form_custom_fields(); |
|
187 | - |
|
188 | - if ( ! empty( $meta_fields ) ) { |
|
189 | - foreach ( $meta_fields as $field_key => $field_label ) { |
|
190 | - $fields[] = $field_key; |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type ); |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Retrieves amount fields. |
|
199 | - * |
|
200 | - * @param string $post_type |
|
201 | - * @since 1.0.19 |
|
202 | - * @return array |
|
203 | - */ |
|
204 | - public function get_amount_fields( $post_type ) { |
|
205 | - |
|
206 | - $fields = array( |
|
207 | - 'subtotal', |
|
208 | - 'total_discount', |
|
209 | - 'total_tax', |
|
210 | - 'total_fees', |
|
211 | - ); |
|
212 | - |
|
213 | - return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type ); |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Retrieves payment form meta fields. |
|
218 | - * |
|
219 | - * @since 2.8.23 |
|
220 | - * |
|
221 | - * @return array |
|
222 | - */ |
|
223 | - public function get_payment_form_meta( $invoice ) { |
|
224 | - // Payment form meta fields. |
|
225 | - $field_keys = getpaid_get_payment_form_custom_fields(); |
|
226 | - $meta = get_post_meta( $invoice->get_id(), 'additional_meta_data', true ); |
|
227 | - |
|
228 | - $field_values = array(); |
|
229 | - if ( ! empty( $field_keys ) ) { |
|
230 | - foreach ( $field_keys as $field_key => $field_label ) { |
|
231 | - $value = ''; |
|
232 | - |
|
233 | - if ( ! empty( $meta ) ) { |
|
234 | - foreach ( $meta as $meta_label => $meta_value ) { |
|
235 | - if ( getpaid_strtolower( wpinv_clean( wp_unslash( $meta_label ) ) ) == getpaid_strtolower( $field_label ) ) { |
|
236 | - $value = $meta_value; |
|
237 | - } |
|
238 | - } |
|
239 | - } |
|
240 | - |
|
241 | - $field_values[ $field_key ] = $value; |
|
242 | - } |
|
243 | - } |
|
244 | - |
|
245 | - return $field_values; |
|
246 | - } |
|
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 | + } elseif ( '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 | + $meta_fields = $this->get_payment_form_meta( $invoice ); |
|
106 | + |
|
107 | + foreach ( $fields as $field ) { |
|
108 | + $value = ''; |
|
109 | + $method = "get_$field"; |
|
110 | + |
|
111 | + if ( method_exists( $invoice, $method ) ) { |
|
112 | + $value = $invoice->$method(); |
|
113 | + } else if( strpos( $field, '_' ) === 0 && isset( $meta_fields[ $field ] ) ) { |
|
114 | + $value = $meta_fields[ $field ]; |
|
115 | + } |
|
116 | + |
|
117 | + if ( in_array( $field, $amount_fields ) ) { |
|
118 | + $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
119 | + } |
|
120 | + |
|
121 | + $prepared[ $field ] = wpinv_clean( $value ); |
|
122 | + |
|
123 | + } |
|
124 | + |
|
125 | + return $prepared; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Retrieves export fields. |
|
130 | + * |
|
131 | + * @param string $post_type |
|
132 | + * @since 1.0.19 |
|
133 | + * @return array |
|
134 | + */ |
|
135 | + public function get_export_fields( $post_type ) { |
|
136 | + |
|
137 | + $fields = array( |
|
138 | + 'id', |
|
139 | + 'parent_id', |
|
140 | + 'status', |
|
141 | + 'date_created', |
|
142 | + 'date_modified', |
|
143 | + 'date_due', |
|
144 | + 'date_completed', |
|
145 | + 'number', |
|
146 | + 'key', |
|
147 | + 'description', |
|
148 | + 'post_type', |
|
149 | + 'mode', |
|
150 | + 'customer_id', |
|
151 | + 'customer_first_name', |
|
152 | + 'customer_last_name', |
|
153 | + 'customer_phone', |
|
154 | + 'customer_email', |
|
155 | + 'customer_country', |
|
156 | + 'customer_city', |
|
157 | + 'customer_state', |
|
158 | + 'customer_zip', |
|
159 | + 'customer_company', |
|
160 | + 'customer_vat_number', |
|
161 | + 'customer_address', |
|
162 | + 'subtotal', |
|
163 | + 'total_discount', |
|
164 | + 'total_tax', |
|
165 | + 'total_fees', |
|
166 | + 'fees', |
|
167 | + 'discounts', |
|
168 | + 'taxes', |
|
169 | + 'cart_details', |
|
170 | + 'item_ids', |
|
171 | + 'payment_form', |
|
172 | + 'discount_code', |
|
173 | + 'gateway', |
|
174 | + 'transaction_id', |
|
175 | + 'currency', |
|
176 | + 'disable_taxes', |
|
177 | + 'subscription_id', |
|
178 | + 'remote_subscription_id', |
|
179 | + 'is_viewed', |
|
180 | + 'email_cc', |
|
181 | + 'template', |
|
182 | + 'created_via', |
|
183 | + ); |
|
184 | + |
|
185 | + // Payment form meta fields. |
|
186 | + $meta_fields = getpaid_get_payment_form_custom_fields(); |
|
187 | + |
|
188 | + if ( ! empty( $meta_fields ) ) { |
|
189 | + foreach ( $meta_fields as $field_key => $field_label ) { |
|
190 | + $fields[] = $field_key; |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type ); |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Retrieves amount fields. |
|
199 | + * |
|
200 | + * @param string $post_type |
|
201 | + * @since 1.0.19 |
|
202 | + * @return array |
|
203 | + */ |
|
204 | + public function get_amount_fields( $post_type ) { |
|
205 | + |
|
206 | + $fields = array( |
|
207 | + 'subtotal', |
|
208 | + 'total_discount', |
|
209 | + 'total_tax', |
|
210 | + 'total_fees', |
|
211 | + ); |
|
212 | + |
|
213 | + return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type ); |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Retrieves payment form meta fields. |
|
218 | + * |
|
219 | + * @since 2.8.23 |
|
220 | + * |
|
221 | + * @return array |
|
222 | + */ |
|
223 | + public function get_payment_form_meta( $invoice ) { |
|
224 | + // Payment form meta fields. |
|
225 | + $field_keys = getpaid_get_payment_form_custom_fields(); |
|
226 | + $meta = get_post_meta( $invoice->get_id(), 'additional_meta_data', true ); |
|
227 | + |
|
228 | + $field_values = array(); |
|
229 | + if ( ! empty( $field_keys ) ) { |
|
230 | + foreach ( $field_keys as $field_key => $field_label ) { |
|
231 | + $value = ''; |
|
232 | + |
|
233 | + if ( ! empty( $meta ) ) { |
|
234 | + foreach ( $meta as $meta_label => $meta_value ) { |
|
235 | + if ( getpaid_strtolower( wpinv_clean( wp_unslash( $meta_label ) ) ) == getpaid_strtolower( $field_label ) ) { |
|
236 | + $value = $meta_value; |
|
237 | + } |
|
238 | + } |
|
239 | + } |
|
240 | + |
|
241 | + $field_values[ $field_key ] = $value; |
|
242 | + } |
|
243 | + } |
|
244 | + |
|
245 | + return $field_values; |
|
246 | + } |
|
247 | 247 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
142 | 142 | function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
143 | + return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | function wpinv_get_theme_template_dir_name() { |
161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
161 | + return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -175,125 +175,125 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
178 | + do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
179 | 179 | |
180 | - // Setup possible parts |
|
181 | - $templates = array(); |
|
182 | - if ( isset( $name ) ) { |
|
183 | - $templates[] = $slug . '-' . $name . '.php'; |
|
180 | + // Setup possible parts |
|
181 | + $templates = array(); |
|
182 | + if ( isset( $name ) ) { |
|
183 | + $templates[] = $slug . '-' . $name . '.php'; |
|
184 | 184 | } |
185 | - $templates[] = $slug . '.php'; |
|
185 | + $templates[] = $slug . '.php'; |
|
186 | 186 | |
187 | - // Allow template parts to be filtered |
|
188 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
187 | + // Allow template parts to be filtered |
|
188 | + $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
189 | 189 | |
190 | - // Return the part that is found |
|
191 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
190 | + // Return the part that is found |
|
191 | + return wpinv_locate_tmpl( $templates, $load, false ); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
195 | - // No file found yet |
|
196 | - $located = false; |
|
195 | + // No file found yet |
|
196 | + $located = false; |
|
197 | 197 | |
198 | - // Try to find a template file |
|
199 | - foreach ( (array)$template_names as $template_name ) { |
|
198 | + // Try to find a template file |
|
199 | + foreach ( (array)$template_names as $template_name ) { |
|
200 | 200 | |
201 | - // Continue if template is empty |
|
202 | - if ( empty( $template_name ) ) { |
|
203 | - continue; |
|
201 | + // Continue if template is empty |
|
202 | + if ( empty( $template_name ) ) { |
|
203 | + continue; |
|
204 | 204 | } |
205 | 205 | |
206 | - // Trim off any slashes from the template name |
|
207 | - $template_name = ltrim( $template_name, '/' ); |
|
206 | + // Trim off any slashes from the template name |
|
207 | + $template_name = ltrim( $template_name, '/' ); |
|
208 | 208 | |
209 | - // try locating this template file by looping through the template paths |
|
210 | - foreach ( wpinv_get_theme_template_paths() as $template_path ) { |
|
209 | + // try locating this template file by looping through the template paths |
|
210 | + foreach ( wpinv_get_theme_template_paths() as $template_path ) { |
|
211 | 211 | |
212 | - if ( file_exists( $template_path . $template_name ) ) { |
|
213 | - $located = $template_path . $template_name; |
|
214 | - break; |
|
215 | - } |
|
216 | - } |
|
212 | + if ( file_exists( $template_path . $template_name ) ) { |
|
213 | + $located = $template_path . $template_name; |
|
214 | + break; |
|
215 | + } |
|
216 | + } |
|
217 | 217 | |
218 | - if ( ! empty( $located ) ) { |
|
219 | - break; |
|
220 | - } |
|
221 | - } |
|
218 | + if ( ! empty( $located ) ) { |
|
219 | + break; |
|
220 | + } |
|
221 | + } |
|
222 | 222 | |
223 | - if ( ( true == $load ) && ! empty( $located ) ) { |
|
224 | - load_template( $located, $require_once ); |
|
223 | + if ( ( true == $load ) && ! empty( $located ) ) { |
|
224 | + load_template( $located, $require_once ); |
|
225 | 225 | } |
226 | 226 | |
227 | - return $located; |
|
227 | + return $located; |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | function wpinv_get_theme_template_paths() { |
231 | - $template_dir = wpinv_get_theme_template_dir_name(); |
|
231 | + $template_dir = wpinv_get_theme_template_dir_name(); |
|
232 | 232 | |
233 | - $file_paths = array( |
|
234 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
235 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
236 | - 100 => wpinv_get_templates_dir(), |
|
237 | - ); |
|
233 | + $file_paths = array( |
|
234 | + 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
235 | + 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
236 | + 100 => wpinv_get_templates_dir(), |
|
237 | + ); |
|
238 | 238 | |
239 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
239 | + $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
240 | 240 | |
241 | - // sort the file paths based on priority |
|
242 | - ksort( $file_paths, SORT_NUMERIC ); |
|
241 | + // sort the file paths based on priority |
|
242 | + ksort( $file_paths, SORT_NUMERIC ); |
|
243 | 243 | |
244 | - return array_map( 'trailingslashit', $file_paths ); |
|
244 | + return array_map( 'trailingslashit', $file_paths ); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | function wpinv_checkout_meta_tags() { |
248 | 248 | |
249 | - $pages = array(); |
|
250 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
251 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
252 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
253 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
249 | + $pages = array(); |
|
250 | + $pages[] = wpinv_get_option( 'success_page' ); |
|
251 | + $pages[] = wpinv_get_option( 'failure_page' ); |
|
252 | + $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
253 | + $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
254 | 254 | |
255 | - if ( ! wpinv_is_checkout() && ! is_page( $pages ) ) { |
|
256 | - return; |
|
257 | - } |
|
255 | + if ( ! wpinv_is_checkout() && ! is_page( $pages ) ) { |
|
256 | + return; |
|
257 | + } |
|
258 | 258 | |
259 | - echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
259 | + echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
260 | 260 | } |
261 | 261 | add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
262 | 262 | |
263 | 263 | function wpinv_add_body_classes( $class ) { |
264 | - $classes = (array)$class; |
|
264 | + $classes = (array)$class; |
|
265 | 265 | |
266 | - if ( wpinv_is_checkout() ) { |
|
267 | - $classes[] = 'wpinv-checkout'; |
|
268 | - $classes[] = 'wpinv-page'; |
|
269 | - } |
|
266 | + if ( wpinv_is_checkout() ) { |
|
267 | + $classes[] = 'wpinv-checkout'; |
|
268 | + $classes[] = 'wpinv-page'; |
|
269 | + } |
|
270 | 270 | |
271 | - if ( wpinv_is_success_page() ) { |
|
272 | - $classes[] = 'wpinv-success'; |
|
273 | - $classes[] = 'wpinv-page'; |
|
274 | - } |
|
271 | + if ( wpinv_is_success_page() ) { |
|
272 | + $classes[] = 'wpinv-success'; |
|
273 | + $classes[] = 'wpinv-page'; |
|
274 | + } |
|
275 | 275 | |
276 | - if ( wpinv_is_failed_transaction_page() ) { |
|
277 | - $classes[] = 'wpinv-failed-transaction'; |
|
278 | - $classes[] = 'wpinv-page'; |
|
279 | - } |
|
276 | + if ( wpinv_is_failed_transaction_page() ) { |
|
277 | + $classes[] = 'wpinv-failed-transaction'; |
|
278 | + $classes[] = 'wpinv-page'; |
|
279 | + } |
|
280 | 280 | |
281 | - if ( wpinv_is_invoice_history_page() ) { |
|
282 | - $classes[] = 'wpinv-history'; |
|
283 | - $classes[] = 'wpinv-page'; |
|
284 | - } |
|
281 | + if ( wpinv_is_invoice_history_page() ) { |
|
282 | + $classes[] = 'wpinv-history'; |
|
283 | + $classes[] = 'wpinv-page'; |
|
284 | + } |
|
285 | 285 | |
286 | - if ( wpinv_is_subscriptions_history_page() ) { |
|
287 | - $classes[] = 'wpinv-subscription'; |
|
288 | - $classes[] = 'wpinv-page'; |
|
289 | - } |
|
286 | + if ( wpinv_is_subscriptions_history_page() ) { |
|
287 | + $classes[] = 'wpinv-subscription'; |
|
288 | + $classes[] = 'wpinv-page'; |
|
289 | + } |
|
290 | 290 | |
291 | - if ( wpinv_is_test_mode() ) { |
|
292 | - $classes[] = 'wpinv-test-mode'; |
|
293 | - $classes[] = 'wpinv-page'; |
|
294 | - } |
|
291 | + if ( wpinv_is_test_mode() ) { |
|
292 | + $classes[] = 'wpinv-test-mode'; |
|
293 | + $classes[] = 'wpinv-page'; |
|
294 | + } |
|
295 | 295 | |
296 | - return array_unique( $classes ); |
|
296 | + return array_unique( $classes ); |
|
297 | 297 | } |
298 | 298 | add_filter( 'body_class', 'wpinv_add_body_classes' ); |
299 | 299 | |
@@ -467,16 +467,16 @@ discard block |
||
467 | 467 | |
468 | 468 | wpinv_html_select( |
469 | 469 | array( |
470 | - 'name' => $args['name'], |
|
471 | - 'selected' => $args['selected'], |
|
472 | - 'id' => $args['id'], |
|
473 | - 'class' => $args['class'], |
|
474 | - 'options' => $options, |
|
475 | - 'multiple' => $args['multiple'], |
|
476 | - 'placeholder' => $args['placeholder'], |
|
477 | - 'show_option_all' => $args['show_option_all'], |
|
478 | - 'show_option_none' => $args['show_option_none'], |
|
479 | - 'data' => $args['data'], |
|
470 | + 'name' => $args['name'], |
|
471 | + 'selected' => $args['selected'], |
|
472 | + 'id' => $args['id'], |
|
473 | + 'class' => $args['class'], |
|
474 | + 'options' => $options, |
|
475 | + 'multiple' => $args['multiple'], |
|
476 | + 'placeholder' => $args['placeholder'], |
|
477 | + 'show_option_all' => $args['show_option_all'], |
|
478 | + 'show_option_none' => $args['show_option_none'], |
|
479 | + 'data' => $args['data'], |
|
480 | 480 | ) |
481 | 481 | ); |
482 | 482 | |
@@ -776,21 +776,21 @@ discard block |
||
776 | 776 | |
777 | 777 | $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
778 | 778 | |
779 | - // Remove unavailable tags. |
|
779 | + // Remove unavailable tags. |
|
780 | 780 | $formatted_address = preg_replace( '/\{\{\w+\}\}/', '', $formatted_address ); |
781 | 781 | |
782 | 782 | // Clean up white space. |
783 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
783 | + $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
784 | 784 | $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
785 | 785 | |
786 | 786 | // Break newlines apart and remove empty lines/trim commas and white space. |
787 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
787 | + $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
788 | 788 | |
789 | 789 | // Add html breaks. |
790 | - $formatted_address = implode( $separator, $formatted_address ); |
|
790 | + $formatted_address = implode( $separator, $formatted_address ); |
|
791 | 791 | |
792 | - // We're done! |
|
793 | - return $formatted_address; |
|
792 | + // We're done! |
|
793 | + return $formatted_address; |
|
794 | 794 | |
795 | 795 | } |
796 | 796 | |
@@ -836,7 +836,7 @@ discard block |
||
836 | 836 | function getpaid_display_invoice_subscriptions( $invoice ) { |
837 | 837 | |
838 | 838 | // Subscriptions. |
839 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
839 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
840 | 840 | |
841 | 841 | if ( empty( $subscriptions ) || ! $invoice->is_recurring() ) { |
842 | 842 | return; |
@@ -1052,7 +1052,7 @@ discard block |
||
1052 | 1052 | } |
1053 | 1053 | |
1054 | 1054 | function wpinv_empty_cart_message() { |
1055 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1055 | + return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1056 | 1056 | } |
1057 | 1057 | |
1058 | 1058 | /** |
@@ -1250,9 +1250,9 @@ discard block |
||
1250 | 1250 | |
1251 | 1251 | if ( 0 == count( $form->get_items() ) ) { |
1252 | 1252 | aui()->alert( |
1253 | - array( |
|
1254 | - 'type' => 'warning', |
|
1255 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1253 | + array( |
|
1254 | + 'type' => 'warning', |
|
1255 | + 'content' => __( 'No published items found', 'invoicing' ), |
|
1256 | 1256 | ), |
1257 | 1257 | true |
1258 | 1258 | ); |
@@ -1275,10 +1275,10 @@ discard block |
||
1275 | 1275 | $invoice = wpinv_get_invoice( $invoice_id ); |
1276 | 1276 | |
1277 | 1277 | if ( empty( $invoice ) ) { |
1278 | - aui()->alert( |
|
1279 | - array( |
|
1280 | - 'type' => 'warning', |
|
1281 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1278 | + aui()->alert( |
|
1279 | + array( |
|
1280 | + 'type' => 'warning', |
|
1281 | + 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1282 | 1282 | ), |
1283 | 1283 | true |
1284 | 1284 | ); |
@@ -1286,10 +1286,10 @@ discard block |
||
1286 | 1286 | } |
1287 | 1287 | |
1288 | 1288 | if ( $invoice->is_paid() ) { |
1289 | - aui()->alert( |
|
1290 | - array( |
|
1291 | - 'type' => 'warning', |
|
1292 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1289 | + aui()->alert( |
|
1290 | + array( |
|
1291 | + 'type' => 'warning', |
|
1292 | + 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1293 | 1293 | ), |
1294 | 1294 | true |
1295 | 1295 | ); |
@@ -1354,7 +1354,7 @@ discard block |
||
1354 | 1354 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; |
1355 | 1355 | } |
1356 | 1356 | |
1357 | - if ( ! empty( $items ) ) { |
|
1357 | + if ( ! empty( $items ) ) { |
|
1358 | 1358 | $items = esc_attr( $items ); |
1359 | 1359 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; |
1360 | 1360 | } |
@@ -1554,21 +1554,21 @@ discard block |
||
1554 | 1554 | |
1555 | 1555 | return aui()->select( |
1556 | 1556 | array( |
1557 | - 'options' => $states, |
|
1558 | - 'name' => esc_attr( $field_name ), |
|
1559 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1560 | - 'value' => sanitize_text_field( $state ), |
|
1561 | - 'placeholder' => $placeholder, |
|
1562 | - 'required' => $required, |
|
1563 | - 'label' => wp_kses_post( $label ), |
|
1564 | - 'label_type' => 'vertical', |
|
1565 | - 'help_text' => $help_text, |
|
1566 | - 'class' => 'getpaid-address-field wpinv_state', |
|
1567 | - 'wrap_class' => "$wrapper_class getpaid-address-field-wrapper__state", |
|
1568 | - 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state', |
|
1569 | - 'extra_attributes' => array( |
|
1570 | - 'autocomplete' => 'address-level1', |
|
1571 | - ), |
|
1557 | + 'options' => $states, |
|
1558 | + 'name' => esc_attr( $field_name ), |
|
1559 | + 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1560 | + 'value' => sanitize_text_field( $state ), |
|
1561 | + 'placeholder' => $placeholder, |
|
1562 | + 'required' => $required, |
|
1563 | + 'label' => wp_kses_post( $label ), |
|
1564 | + 'label_type' => 'vertical', |
|
1565 | + 'help_text' => $help_text, |
|
1566 | + 'class' => 'getpaid-address-field wpinv_state', |
|
1567 | + 'wrap_class' => "$wrapper_class getpaid-address-field-wrapper__state", |
|
1568 | + 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state', |
|
1569 | + 'extra_attributes' => array( |
|
1570 | + 'autocomplete' => 'address-level1', |
|
1571 | + ), |
|
1572 | 1572 | ), |
1573 | 1573 | $echo |
1574 | 1574 | ); |
@@ -1664,34 +1664,34 @@ discard block |
||
1664 | 1664 | * @return array Array of custom fields. |
1665 | 1665 | */ |
1666 | 1666 | function getpaid_get_payment_form_custom_fields() { |
1667 | - global $wpdb, $payment_form_meta_fields; |
|
1667 | + global $wpdb, $payment_form_meta_fields; |
|
1668 | 1668 | |
1669 | - if ( ! empty( $payment_form_meta_fields ) ) { |
|
1670 | - return $payment_form_meta_fields; |
|
1671 | - } |
|
1669 | + if ( ! empty( $payment_form_meta_fields ) ) { |
|
1670 | + return $payment_form_meta_fields; |
|
1671 | + } |
|
1672 | 1672 | |
1673 | - $results = $wpdb->get_results( "SELECT `pm`.`meta_value` FROM `{$wpdb->postmeta}` AS pm LEFT JOIN `{$wpdb->posts}` AS p ON p.ID = pm.post_id WHERE `pm`.`meta_key` = 'wpinv_form_elements' AND `p`.`post_type` = 'wpi_payment_form'" ); |
|
1673 | + $results = $wpdb->get_results( "SELECT `pm`.`meta_value` FROM `{$wpdb->postmeta}` AS pm LEFT JOIN `{$wpdb->posts}` AS p ON p.ID = pm.post_id WHERE `pm`.`meta_key` = 'wpinv_form_elements' AND `p`.`post_type` = 'wpi_payment_form'" ); |
|
1674 | 1674 | |
1675 | - $meta_fields = array(); |
|
1675 | + $meta_fields = array(); |
|
1676 | 1676 | |
1677 | - if ( ! empty( $results ) ) { |
|
1678 | - foreach ( $results as $row ) { |
|
1679 | - $fields = maybe_unserialize( $row->meta_value ); |
|
1677 | + if ( ! empty( $results ) ) { |
|
1678 | + foreach ( $results as $row ) { |
|
1679 | + $fields = maybe_unserialize( $row->meta_value ); |
|
1680 | 1680 | |
1681 | - if ( ! empty( $fields ) && is_array( $fields ) ) { |
|
1682 | - foreach ( $fields as $field ) { |
|
1683 | - $label = ! empty( $field['add_meta'] ) && ! empty( $field['label'] ) ? wpinv_clean( wp_unslash( $field['label'] ) ) : ''; |
|
1681 | + if ( ! empty( $fields ) && is_array( $fields ) ) { |
|
1682 | + foreach ( $fields as $field ) { |
|
1683 | + $label = ! empty( $field['add_meta'] ) && ! empty( $field['label'] ) ? wpinv_clean( wp_unslash( $field['label'] ) ) : ''; |
|
1684 | 1684 | |
1685 | - if ( $label ) { |
|
1686 | - $field_key = '_' . str_replace( array( ' ', "'", '"', ',' ), array( '_', '', '', '_' ), getpaid_strtolower( $label ) ); |
|
1687 | - $meta_fields[ $field_key ] = $label; |
|
1688 | - } |
|
1689 | - } |
|
1690 | - } |
|
1691 | - } |
|
1692 | - } |
|
1685 | + if ( $label ) { |
|
1686 | + $field_key = '_' . str_replace( array( ' ', "'", '"', ',' ), array( '_', '', '', '_' ), getpaid_strtolower( $label ) ); |
|
1687 | + $meta_fields[ $field_key ] = $label; |
|
1688 | + } |
|
1689 | + } |
|
1690 | + } |
|
1691 | + } |
|
1692 | + } |
|
1693 | 1693 | |
1694 | - $payment_form_meta_fields = $meta_fields; |
|
1694 | + $payment_form_meta_fields = $meta_fields; |
|
1695 | 1695 | |
1696 | - return $meta_fields; |
|
1696 | + return $meta_fields; |
|
1697 | 1697 | } |
@@ -137,13 +137,13 @@ discard block |
||
137 | 137 | */ |
138 | 138 | function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
139 | 139 | |
140 | - $invoice_statuses = array( |
|
141 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
140 | + $invoice_statuses = array( |
|
141 | + 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
142 | 142 | 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
143 | 143 | 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
144 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
145 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
146 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
144 | + 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
145 | + 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
146 | + 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
147 | 147 | 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
148 | 148 | 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
149 | 149 | ); |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $invoice = $invoice->get_post_type(); |
161 | 161 | } |
162 | 162 | |
163 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
163 | + return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -278,25 +278,25 @@ discard block |
||
278 | 278 | * @return string |
279 | 279 | */ |
280 | 280 | function getpaid_get_price_format() { |
281 | - $currency_pos = wpinv_currency_position(); |
|
282 | - $format = '%1$s%2$s'; |
|
283 | - |
|
284 | - switch ( $currency_pos ) { |
|
285 | - case 'left': |
|
286 | - $format = '%1$s%2$s'; |
|
287 | - break; |
|
288 | - case 'right': |
|
289 | - $format = '%2$s%1$s'; |
|
290 | - break; |
|
291 | - case 'left_space': |
|
292 | - $format = '%1$s %2$s'; |
|
293 | - break; |
|
294 | - case 'right_space': |
|
295 | - $format = '%2$s %1$s'; |
|
296 | - break; |
|
297 | - } |
|
298 | - |
|
299 | - return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
281 | + $currency_pos = wpinv_currency_position(); |
|
282 | + $format = '%1$s%2$s'; |
|
283 | + |
|
284 | + switch ( $currency_pos ) { |
|
285 | + case 'left': |
|
286 | + $format = '%1$s%2$s'; |
|
287 | + break; |
|
288 | + case 'right': |
|
289 | + $format = '%2$s%1$s'; |
|
290 | + break; |
|
291 | + case 'left_space': |
|
292 | + $format = '%1$s %2$s'; |
|
293 | + break; |
|
294 | + case 'right_space': |
|
295 | + $format = '%2$s %1$s'; |
|
296 | + break; |
|
297 | + } |
|
298 | + |
|
299 | + return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -402,13 +402,13 @@ discard block |
||
402 | 402 | * @param mixed $value Value. |
403 | 403 | */ |
404 | 404 | function getpaid_maybe_define_constant( $name, $value ) { |
405 | - if ( ! defined( $name ) ) { |
|
406 | - define( $name, $value ); |
|
407 | - } |
|
405 | + if ( ! defined( $name ) ) { |
|
406 | + define( $name, $value ); |
|
407 | + } |
|
408 | 408 | } |
409 | 409 | |
410 | 410 | function wpinv_get_php_arg_separator_output() { |
411 | - return ini_get( 'arg_separator.output' ); |
|
411 | + return ini_get( 'arg_separator.output' ); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | function wpinv_rgb_from_hex( $color ) { |
@@ -719,16 +719,16 @@ discard block |
||
719 | 719 | return wp_kses( |
720 | 720 | html_entity_decode( $var ), |
721 | 721 | array( |
722 | - 'br' => array(), |
|
723 | - 'em' => array(), |
|
724 | - 'strong' => array(), |
|
725 | - 'b' => array(), |
|
726 | - 'small' => array(), |
|
727 | - 'span' => array(), |
|
728 | - 'ul' => array(), |
|
729 | - 'li' => array(), |
|
730 | - 'ol' => array(), |
|
731 | - 'p' => array(), |
|
722 | + 'br' => array(), |
|
723 | + 'em' => array(), |
|
724 | + 'strong' => array(), |
|
725 | + 'b' => array(), |
|
726 | + 'small' => array(), |
|
727 | + 'span' => array(), |
|
728 | + 'ul' => array(), |
|
729 | + 'li' => array(), |
|
730 | + 'ol' => array(), |
|
731 | + 'p' => array(), |
|
732 | 732 | ) |
733 | 733 | ); |
734 | 734 | } |
@@ -779,11 +779,11 @@ discard block |
||
779 | 779 | $list = array(); |
780 | 780 | } |
781 | 781 | |
782 | - if ( ! is_array( $list ) ) { |
|
783 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
784 | - } |
|
782 | + if ( ! is_array( $list ) ) { |
|
783 | + return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
784 | + } |
|
785 | 785 | |
786 | - return $list; |
|
786 | + return $list; |
|
787 | 787 | } |
788 | 788 | |
789 | 789 | /** |
@@ -824,17 +824,17 @@ discard block |
||
824 | 824 | */ |
825 | 825 | function wpinv_clean( $var ) { |
826 | 826 | |
827 | - if ( is_array( $var ) ) { |
|
828 | - return array_map( 'wpinv_clean', $var ); |
|
827 | + if ( is_array( $var ) ) { |
|
828 | + return array_map( 'wpinv_clean', $var ); |
|
829 | 829 | } |
830 | 830 | |
831 | 831 | if ( is_object( $var ) ) { |
832 | - $object_vars = get_object_vars( $var ); |
|
833 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
834 | - $var->$property_name = wpinv_clean( $property_value ); |
|
832 | + $object_vars = get_object_vars( $var ); |
|
833 | + foreach ( $object_vars as $property_name => $property_value ) { |
|
834 | + $var->$property_name = wpinv_clean( $property_value ); |
|
835 | 835 | } |
836 | 836 | return $var; |
837 | - } |
|
837 | + } |
|
838 | 838 | |
839 | 839 | return is_string( $var ) ? sanitize_text_field( stripslashes( $var ) ) : $var; |
840 | 840 | } |
@@ -847,7 +847,7 @@ discard block |
||
847 | 847 | */ |
848 | 848 | function getpaid_convert_price_string_to_options( $str ) { |
849 | 849 | |
850 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
850 | + $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
851 | 851 | $options = array(); |
852 | 852 | |
853 | 853 | foreach ( $raw_options as $option ) { |
@@ -936,7 +936,7 @@ discard block |
||
936 | 936 | * @return string |
937 | 937 | */ |
938 | 938 | function getpaid_date_format() { |
939 | - return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
939 | + return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
940 | 940 | } |
941 | 941 | |
942 | 942 | /** |
@@ -945,7 +945,7 @@ discard block |
||
945 | 945 | * @return string |
946 | 946 | */ |
947 | 947 | function getpaid_time_format() { |
948 | - return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
948 | + return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
949 | 949 | } |
950 | 950 | |
951 | 951 | /** |
@@ -958,15 +958,15 @@ discard block |
||
958 | 958 | function getpaid_limit_length( $string, $limit ) { |
959 | 959 | $str_limit = $limit - 3; |
960 | 960 | |
961 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
962 | - if ( mb_strlen( $string ) > $limit ) { |
|
963 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
964 | - } |
|
965 | - } else { |
|
966 | - if ( strlen( $string ) > $limit ) { |
|
967 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
968 | - } |
|
969 | - } |
|
961 | + if ( function_exists( 'mb_strimwidth' ) ) { |
|
962 | + if ( mb_strlen( $string ) > $limit ) { |
|
963 | + $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
964 | + } |
|
965 | + } else { |
|
966 | + if ( strlen( $string ) > $limit ) { |
|
967 | + $string = substr( $string, 0, $str_limit ) . '...'; |
|
968 | + } |
|
969 | + } |
|
970 | 970 | return $string; |
971 | 971 | |
972 | 972 | } |
@@ -1096,12 +1096,12 @@ discard block |
||
1096 | 1096 | $types = get_allowed_mime_types(); |
1097 | 1097 | |
1098 | 1098 | if ( isset( $types['htm|html'] ) ) { |
1099 | - unset( $types['htm|html'] ); |
|
1100 | - } |
|
1099 | + unset( $types['htm|html'] ); |
|
1100 | + } |
|
1101 | 1101 | |
1102 | 1102 | if ( isset( $types['js'] ) ) { |
1103 | - unset( $types['js'] ); |
|
1104 | - } |
|
1103 | + unset( $types['js'] ); |
|
1104 | + } |
|
1105 | 1105 | |
1106 | 1106 | return $types; |
1107 | 1107 | |
@@ -1157,11 +1157,11 @@ discard block |
||
1157 | 1157 | * @return string Returns converted string. |
1158 | 1158 | */ |
1159 | 1159 | function getpaid_strtolower( $string, $charset = 'UTF-8' ) { |
1160 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
1161 | - return mb_convert_case( $string, MB_CASE_LOWER, $charset ); |
|
1162 | - } else { |
|
1163 | - return strtolower( $string ); |
|
1164 | - } |
|
1160 | + if ( function_exists( 'mb_convert_case' ) ) { |
|
1161 | + return mb_convert_case( $string, MB_CASE_LOWER, $charset ); |
|
1162 | + } else { |
|
1163 | + return strtolower( $string ); |
|
1164 | + } |
|
1165 | 1165 | } |
1166 | 1166 | |
1167 | 1167 | /** |
@@ -1174,9 +1174,9 @@ discard block |
||
1174 | 1174 | * @return string Returns converted string. |
1175 | 1175 | */ |
1176 | 1176 | function getpaid_strtoupper( $string, $charset = 'UTF-8' ) { |
1177 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
1178 | - return mb_convert_case( $string, MB_CASE_UPPER, $charset ); |
|
1179 | - } else { |
|
1180 | - return strtoupper( $string ); |
|
1181 | - } |
|
1177 | + if ( function_exists( 'mb_convert_case' ) ) { |
|
1178 | + return mb_convert_case( $string, MB_CASE_UPPER, $charset ); |
|
1179 | + } else { |
|
1180 | + return strtoupper( $string ); |
|
1181 | + } |
|
1182 | 1182 | } |
1183 | 1183 | \ No newline at end of file |
@@ -10,227 +10,227 @@ |
||
10 | 10 | */ |
11 | 11 | class GetPaid_PayPal_API { |
12 | 12 | |
13 | - /** |
|
14 | - * Retrieves the bearer token. |
|
15 | - * |
|
13 | + /** |
|
14 | + * Retrieves the bearer token. |
|
15 | + * |
|
16 | 16 | * @return string|\WP_Error |
17 | - */ |
|
18 | - public static function get_token( $mode = 'live' ) { |
|
17 | + */ |
|
18 | + public static function get_token( $mode = 'live' ) { |
|
19 | 19 | |
20 | - $token = get_transient( 'getpaid_paypal_' . $mode . '_token' ); |
|
20 | + $token = get_transient( 'getpaid_paypal_' . $mode . '_token' ); |
|
21 | 21 | |
22 | - if ( $token ) { |
|
23 | - return $token; |
|
24 | - } |
|
22 | + if ( $token ) { |
|
23 | + return $token; |
|
24 | + } |
|
25 | 25 | |
26 | - $client_id = 'live' === $mode ? wpinv_get_option( 'paypal_client_id' ) : wpinv_get_option( 'paypal_sandbox_client_id' ); |
|
27 | - $secret_key = 'live' === $mode ? wpinv_get_option( 'paypal_secret' ) : wpinv_get_option( 'paypal_sandbox_secret' ); |
|
28 | - $url = self::get_api_url( 'v1/oauth2/token?grant_type=client_credentials', $mode ); |
|
26 | + $client_id = 'live' === $mode ? wpinv_get_option( 'paypal_client_id' ) : wpinv_get_option( 'paypal_sandbox_client_id' ); |
|
27 | + $secret_key = 'live' === $mode ? wpinv_get_option( 'paypal_secret' ) : wpinv_get_option( 'paypal_sandbox_secret' ); |
|
28 | + $url = self::get_api_url( 'v1/oauth2/token?grant_type=client_credentials', $mode ); |
|
29 | 29 | |
30 | 30 | if ( empty( $client_id ) || empty( $secret_key ) ) { |
31 | 31 | return new \WP_Error( 'invalid_request', 'Missing client id or secret key.', array( 'status' => 400 ) ); |
32 | 32 | } |
33 | 33 | |
34 | - $args = array( |
|
35 | - 'method' => 'POST', |
|
36 | - 'timeout' => 30, |
|
37 | - 'headers' => array( |
|
38 | - 'Authorization' => 'Basic ' . base64_encode( $client_id . ':' . $secret_key ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
|
39 | - 'Accept' => 'application/json', |
|
40 | - 'Content-Type' => 'application/x-www-form-urlencoded', |
|
41 | - ), |
|
42 | - ); |
|
43 | - |
|
44 | - $response = self::response_or_error( wp_remote_post( $url, $args ) ); |
|
45 | - |
|
46 | - if ( is_wp_error( $response ) ) { |
|
47 | - return $response; |
|
48 | - } |
|
49 | - |
|
50 | - if ( ! isset( $response->access_token ) ) { |
|
51 | - return new \WP_Error( 'invalid_request', 'Could not create token.', array( 'status' => 400 ) ); |
|
52 | - } |
|
53 | - |
|
54 | - set_transient( 'getpaid_paypal_' . $mode . '_token', $response->access_token, $response->expires_in - 600 ); |
|
55 | - return $response->access_token; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Retrieves the PayPal API URL. |
|
60 | - * |
|
61 | - * @param string $endpoint |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public static function get_api_url( $endpoint = '', $mode = 'live' ) { |
|
65 | - $endpoint = ltrim( $endpoint, '/' ); |
|
66 | - return 'live' === $mode ? 'https://api-m.paypal.com/' . $endpoint : 'https://api-m.sandbox.paypal.com/' . $endpoint; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Handles a post request. |
|
71 | - * |
|
72 | - * @param string $path The path to the endpoint. |
|
73 | - * @param mixed $data The data to send. |
|
74 | - * @param string $method The method to use. |
|
75 | - * |
|
76 | - * @return true|\WP_Error |
|
77 | - */ |
|
78 | - public static function post( $path, $data, $mode = 'live', $method = 'POST' ) { |
|
79 | - |
|
80 | - $access_token = self::get_token( $mode ); |
|
81 | - |
|
82 | - if ( is_wp_error( $access_token ) ) { |
|
83 | - return $access_token; |
|
84 | - } |
|
85 | - |
|
86 | - $url = self::get_api_url( $path, $mode ); |
|
87 | - $args = array( |
|
88 | - 'method' => $method, |
|
89 | - 'headers' => array( |
|
90 | - 'Authorization' => 'Bearer ' . $access_token, |
|
91 | - 'Content-Type' => 'application/json', |
|
92 | - ), |
|
93 | - ); |
|
94 | - |
|
95 | - if( ! empty( $data )) { |
|
96 | - $args['body'] = wp_json_encode( $data ); |
|
97 | - } |
|
98 | - |
|
99 | - return self::response_or_error( wp_remote_post( $url, $args ) ); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Handles a get request. |
|
104 | - * |
|
105 | - * @param string $path The path to the endpoint. |
|
106 | - * @param string $method |
|
107 | - * @return object|\WP_Error |
|
108 | - */ |
|
109 | - public static function get( $path, $mode = 'live', $method = 'GET' ) { |
|
110 | - |
|
111 | - $access_token = self::get_token( $mode ); |
|
112 | - |
|
113 | - if ( is_wp_error( $access_token ) ) { |
|
114 | - return $access_token; |
|
115 | - } |
|
116 | - |
|
117 | - $url = self::get_api_url( $path, $mode ); |
|
118 | - $args = array( |
|
119 | - 'method' => $method, |
|
120 | - 'headers' => array( |
|
121 | - 'Authorization' => 'Bearer ' . $access_token, |
|
122 | - ), |
|
123 | - ); |
|
124 | - |
|
125 | - return self::response_or_error( wp_remote_get( $url, $args ) ); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Returns the response body |
|
130 | - * |
|
131 | - * @since 1.0.0 |
|
132 | - * @version 1.0.0 |
|
133 | - * @param \WP_Error|array $response |
|
134 | - * @return \WP_Error|object |
|
135 | - */ |
|
136 | - public static function response_or_error( $response ) { |
|
137 | - |
|
138 | - if ( is_wp_error( $response ) ) { |
|
139 | - return new \WP_Error( 'paypal_error', __( 'There was a problem connecting to the PayPal API endpoint.', 'invoicing' ) ); |
|
140 | - } |
|
141 | - |
|
142 | - if ( empty( $response['body'] ) ) { |
|
143 | - return true; |
|
144 | - } |
|
145 | - |
|
146 | - $response_body = json_decode( wp_remote_retrieve_body( $response ) ); |
|
147 | - |
|
148 | - if ( wp_remote_retrieve_response_code( $response ) > 299 ) { |
|
149 | - |
|
150 | - // Normal errors. |
|
151 | - if ( $response_body && isset( $response_body->message ) ) { |
|
152 | - $error_message = $response_body->message; |
|
153 | - |
|
154 | - // Identity errors. |
|
155 | - } elseif ( $response_body && isset( $response_body->error_description ) ) { |
|
156 | - $error_message = $response_body->error_description; |
|
157 | - return new \WP_Error( 'paypal_error', wp_kses_post( $response_body->error_description ) ); |
|
158 | - } else { |
|
159 | - $error_message = __( 'There was an error connecting to the PayPal API endpoint.', 'invoicing' ); |
|
160 | - } |
|
161 | - |
|
162 | - return new \WP_Error( 'paypal_error', $error_message ); |
|
163 | - } |
|
164 | - |
|
165 | - return $response_body; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Fetches an order. |
|
170 | - * |
|
171 | - * @since 1.0.0 |
|
172 | - * @version 1.0.0 |
|
173 | - * @param string $order_id |
|
174 | - * @link https://developer.paypal.com/docs/api/orders/v2/#orders_get |
|
175 | - * @return \WP_Error|object |
|
176 | - */ |
|
177 | - public static function get_order( $order_id, $mode = 'live' ) { |
|
178 | - return self::get( '/v2/checkout/orders/' . $order_id, $mode ); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Fetches a subscription. |
|
183 | - * |
|
184 | - * @since 1.0.0 |
|
185 | - * @version 1.0.0 |
|
186 | - * @param string $subscription_id |
|
187 | - * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get |
|
188 | - * @return \WP_Error|object |
|
189 | - */ |
|
190 | - public static function get_subscription( $subscription_id, $mode = 'live' ) { |
|
191 | - return self::get( '/v1/billing/subscriptions/' . $subscription_id, $mode ); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Fetches a subscription's latest transactions (limits search to last one day). |
|
196 | - * |
|
197 | - * @since 1.0.0 |
|
198 | - * @version 1.0.0 |
|
199 | - * @param string $subscription_id |
|
200 | - * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions |
|
201 | - * @return \WP_Error|object |
|
202 | - */ |
|
203 | - public static function get_subscription_transaction( $subscription_id, $mode = 'live' ) { |
|
204 | - $start_time = gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '-1 day' ) ); |
|
205 | - $end_time = gmdate( 'Y-m-d\TH:i:s\Z' ); |
|
206 | - return self::get( "/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode ); |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Refunds a capture. |
|
211 | - * |
|
212 | - * @since 1.0.0 |
|
213 | - * @version 1.0.0 |
|
214 | - * @param string $capture_id |
|
215 | - * @param array $args |
|
216 | - * @link https://developer.paypal.com/docs/api/payments/v2/#captures_refund |
|
217 | - * @return \WP_Error|object |
|
218 | - */ |
|
219 | - public static function refund_capture( $capture_id, $args = array(), $mode = 'live' ) { |
|
220 | - return self::post( '/v2/payments/captures/' . $capture_id . '/refund', $args, $mode ); |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Cancels a subscription. |
|
225 | - * |
|
226 | - * @since 2.8.24 |
|
227 | - * @version 2.8.24 |
|
228 | - * @param string $subscription_id |
|
229 | - * @param array $args |
|
230 | - * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel |
|
231 | - * @return \WP_Error|object |
|
232 | - */ |
|
233 | - public static function cancel_subscription( $subscription_id, $args = array(), $mode = 'live' ) { |
|
234 | - return self::post( '/v1/billing/subscriptions/' . $subscription_id . '/cancel', $args, $mode ); |
|
235 | - } |
|
34 | + $args = array( |
|
35 | + 'method' => 'POST', |
|
36 | + 'timeout' => 30, |
|
37 | + 'headers' => array( |
|
38 | + 'Authorization' => 'Basic ' . base64_encode( $client_id . ':' . $secret_key ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
|
39 | + 'Accept' => 'application/json', |
|
40 | + 'Content-Type' => 'application/x-www-form-urlencoded', |
|
41 | + ), |
|
42 | + ); |
|
43 | + |
|
44 | + $response = self::response_or_error( wp_remote_post( $url, $args ) ); |
|
45 | + |
|
46 | + if ( is_wp_error( $response ) ) { |
|
47 | + return $response; |
|
48 | + } |
|
49 | + |
|
50 | + if ( ! isset( $response->access_token ) ) { |
|
51 | + return new \WP_Error( 'invalid_request', 'Could not create token.', array( 'status' => 400 ) ); |
|
52 | + } |
|
53 | + |
|
54 | + set_transient( 'getpaid_paypal_' . $mode . '_token', $response->access_token, $response->expires_in - 600 ); |
|
55 | + return $response->access_token; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Retrieves the PayPal API URL. |
|
60 | + * |
|
61 | + * @param string $endpoint |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public static function get_api_url( $endpoint = '', $mode = 'live' ) { |
|
65 | + $endpoint = ltrim( $endpoint, '/' ); |
|
66 | + return 'live' === $mode ? 'https://api-m.paypal.com/' . $endpoint : 'https://api-m.sandbox.paypal.com/' . $endpoint; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Handles a post request. |
|
71 | + * |
|
72 | + * @param string $path The path to the endpoint. |
|
73 | + * @param mixed $data The data to send. |
|
74 | + * @param string $method The method to use. |
|
75 | + * |
|
76 | + * @return true|\WP_Error |
|
77 | + */ |
|
78 | + public static function post( $path, $data, $mode = 'live', $method = 'POST' ) { |
|
79 | + |
|
80 | + $access_token = self::get_token( $mode ); |
|
81 | + |
|
82 | + if ( is_wp_error( $access_token ) ) { |
|
83 | + return $access_token; |
|
84 | + } |
|
85 | + |
|
86 | + $url = self::get_api_url( $path, $mode ); |
|
87 | + $args = array( |
|
88 | + 'method' => $method, |
|
89 | + 'headers' => array( |
|
90 | + 'Authorization' => 'Bearer ' . $access_token, |
|
91 | + 'Content-Type' => 'application/json', |
|
92 | + ), |
|
93 | + ); |
|
94 | + |
|
95 | + if( ! empty( $data )) { |
|
96 | + $args['body'] = wp_json_encode( $data ); |
|
97 | + } |
|
98 | + |
|
99 | + return self::response_or_error( wp_remote_post( $url, $args ) ); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Handles a get request. |
|
104 | + * |
|
105 | + * @param string $path The path to the endpoint. |
|
106 | + * @param string $method |
|
107 | + * @return object|\WP_Error |
|
108 | + */ |
|
109 | + public static function get( $path, $mode = 'live', $method = 'GET' ) { |
|
110 | + |
|
111 | + $access_token = self::get_token( $mode ); |
|
112 | + |
|
113 | + if ( is_wp_error( $access_token ) ) { |
|
114 | + return $access_token; |
|
115 | + } |
|
116 | + |
|
117 | + $url = self::get_api_url( $path, $mode ); |
|
118 | + $args = array( |
|
119 | + 'method' => $method, |
|
120 | + 'headers' => array( |
|
121 | + 'Authorization' => 'Bearer ' . $access_token, |
|
122 | + ), |
|
123 | + ); |
|
124 | + |
|
125 | + return self::response_or_error( wp_remote_get( $url, $args ) ); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Returns the response body |
|
130 | + * |
|
131 | + * @since 1.0.0 |
|
132 | + * @version 1.0.0 |
|
133 | + * @param \WP_Error|array $response |
|
134 | + * @return \WP_Error|object |
|
135 | + */ |
|
136 | + public static function response_or_error( $response ) { |
|
137 | + |
|
138 | + if ( is_wp_error( $response ) ) { |
|
139 | + return new \WP_Error( 'paypal_error', __( 'There was a problem connecting to the PayPal API endpoint.', 'invoicing' ) ); |
|
140 | + } |
|
141 | + |
|
142 | + if ( empty( $response['body'] ) ) { |
|
143 | + return true; |
|
144 | + } |
|
145 | + |
|
146 | + $response_body = json_decode( wp_remote_retrieve_body( $response ) ); |
|
147 | + |
|
148 | + if ( wp_remote_retrieve_response_code( $response ) > 299 ) { |
|
149 | + |
|
150 | + // Normal errors. |
|
151 | + if ( $response_body && isset( $response_body->message ) ) { |
|
152 | + $error_message = $response_body->message; |
|
153 | + |
|
154 | + // Identity errors. |
|
155 | + } elseif ( $response_body && isset( $response_body->error_description ) ) { |
|
156 | + $error_message = $response_body->error_description; |
|
157 | + return new \WP_Error( 'paypal_error', wp_kses_post( $response_body->error_description ) ); |
|
158 | + } else { |
|
159 | + $error_message = __( 'There was an error connecting to the PayPal API endpoint.', 'invoicing' ); |
|
160 | + } |
|
161 | + |
|
162 | + return new \WP_Error( 'paypal_error', $error_message ); |
|
163 | + } |
|
164 | + |
|
165 | + return $response_body; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Fetches an order. |
|
170 | + * |
|
171 | + * @since 1.0.0 |
|
172 | + * @version 1.0.0 |
|
173 | + * @param string $order_id |
|
174 | + * @link https://developer.paypal.com/docs/api/orders/v2/#orders_get |
|
175 | + * @return \WP_Error|object |
|
176 | + */ |
|
177 | + public static function get_order( $order_id, $mode = 'live' ) { |
|
178 | + return self::get( '/v2/checkout/orders/' . $order_id, $mode ); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Fetches a subscription. |
|
183 | + * |
|
184 | + * @since 1.0.0 |
|
185 | + * @version 1.0.0 |
|
186 | + * @param string $subscription_id |
|
187 | + * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get |
|
188 | + * @return \WP_Error|object |
|
189 | + */ |
|
190 | + public static function get_subscription( $subscription_id, $mode = 'live' ) { |
|
191 | + return self::get( '/v1/billing/subscriptions/' . $subscription_id, $mode ); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Fetches a subscription's latest transactions (limits search to last one day). |
|
196 | + * |
|
197 | + * @since 1.0.0 |
|
198 | + * @version 1.0.0 |
|
199 | + * @param string $subscription_id |
|
200 | + * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions |
|
201 | + * @return \WP_Error|object |
|
202 | + */ |
|
203 | + public static function get_subscription_transaction( $subscription_id, $mode = 'live' ) { |
|
204 | + $start_time = gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '-1 day' ) ); |
|
205 | + $end_time = gmdate( 'Y-m-d\TH:i:s\Z' ); |
|
206 | + return self::get( "/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode ); |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Refunds a capture. |
|
211 | + * |
|
212 | + * @since 1.0.0 |
|
213 | + * @version 1.0.0 |
|
214 | + * @param string $capture_id |
|
215 | + * @param array $args |
|
216 | + * @link https://developer.paypal.com/docs/api/payments/v2/#captures_refund |
|
217 | + * @return \WP_Error|object |
|
218 | + */ |
|
219 | + public static function refund_capture( $capture_id, $args = array(), $mode = 'live' ) { |
|
220 | + return self::post( '/v2/payments/captures/' . $capture_id . '/refund', $args, $mode ); |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Cancels a subscription. |
|
225 | + * |
|
226 | + * @since 2.8.24 |
|
227 | + * @version 2.8.24 |
|
228 | + * @param string $subscription_id |
|
229 | + * @param array $args |
|
230 | + * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel |
|
231 | + * @return \WP_Error|object |
|
232 | + */ |
|
233 | + public static function cancel_subscription( $subscription_id, $args = array(), $mode = 'live' ) { |
|
234 | + return self::post( '/v1/billing/subscriptions/' . $subscription_id . '/cancel', $args, $mode ); |
|
235 | + } |
|
236 | 236 | } |
@@ -13,103 +13,103 @@ discard block |
||
13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'paypal'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group', 'refunds' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 1; |
35 | 35 | |
36 | 36 | /** |
37 | - * Stores line items to send to PayPal. |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
37 | + * Stores line items to send to PayPal. |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | 41 | protected $line_items = array(); |
42 | 42 | |
43 | 43 | /** |
44 | - * Endpoint for requests from PayPal. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - protected $notify_url; |
|
44 | + * Endpoint for requests from PayPal. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + protected $notify_url; |
|
49 | 49 | |
50 | - /** |
|
51 | - * Endpoint for requests to PayPal. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
50 | + /** |
|
51 | + * Endpoint for requests to PayPal. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | 55 | protected $endpoint; |
56 | 56 | |
57 | 57 | /** |
58 | - * Currencies this gateway is allowed for. |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
58 | + * Currencies this gateway is allowed for. |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
63 | 63 | |
64 | 64 | /** |
65 | - * URL to view a transaction. |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
65 | + * URL to view a transaction. |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
70 | 70 | |
71 | 71 | /** |
72 | - * URL to view a subscription. |
|
73 | - * |
|
74 | - * @var string |
|
75 | - */ |
|
76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
72 | + * URL to view a subscription. |
|
73 | + * |
|
74 | + * @var string |
|
75 | + */ |
|
76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
77 | 77 | |
78 | 78 | /** |
79 | - * Class constructor. |
|
80 | - */ |
|
81 | - public function __construct() { |
|
82 | - parent::__construct(); |
|
79 | + * Class constructor. |
|
80 | + */ |
|
81 | + public function __construct() { |
|
82 | + parent::__construct(); |
|
83 | 83 | |
84 | 84 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
85 | 85 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
86 | 86 | $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
87 | 87 | $this->notify_url = wpinv_get_ipn_url( $this->id ); |
88 | 88 | |
89 | - add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 ); |
|
90 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
91 | - add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
92 | - add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
93 | - add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) ); |
|
94 | - |
|
95 | - if ( $this->enabled ) { |
|
96 | - add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
97 | - add_action( 'getpaid_paypal_subscription_cancelled', array( $this, 'subscription_cancelled' ) ); |
|
98 | - add_action( 'getpaid_delete_subscription', array( $this, 'subscription_cancelled' ) ); |
|
99 | - add_action( 'getpaid_refund_invoice_remotely', array( $this, 'refund_invoice' ) ); |
|
100 | - } |
|
89 | + add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 ); |
|
90 | + add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
91 | + add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
92 | + add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
93 | + add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) ); |
|
94 | + |
|
95 | + if ( $this->enabled ) { |
|
96 | + add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
97 | + add_action( 'getpaid_paypal_subscription_cancelled', array( $this, 'subscription_cancelled' ) ); |
|
98 | + add_action( 'getpaid_delete_subscription', array( $this, 'subscription_cancelled' ) ); |
|
99 | + add_action( 'getpaid_refund_invoice_remotely', array( $this, 'refund_invoice' ) ); |
|
100 | + } |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
104 | - * Process Payment. |
|
105 | - * |
|
106 | - * |
|
107 | - * @param WPInv_Invoice $invoice Invoice. |
|
108 | - * @param array $submission_data Posted checkout fields. |
|
109 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
110 | - * @return array |
|
111 | - */ |
|
112 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
104 | + * Process Payment. |
|
105 | + * |
|
106 | + * |
|
107 | + * @param WPInv_Invoice $invoice Invoice. |
|
108 | + * @param array $submission_data Posted checkout fields. |
|
109 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
110 | + * @return array |
|
111 | + */ |
|
112 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
113 | 113 | |
114 | 114 | // Get redirect url. |
115 | 115 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -132,15 +132,15 @@ discard block |
||
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
135 | - * Get the PayPal request URL for an invoice. |
|
136 | - * |
|
137 | - * @param WPInv_Invoice $invoice Invoice object. |
|
138 | - * @return string |
|
139 | - */ |
|
140 | - public function get_request_url( $invoice ) { |
|
135 | + * Get the PayPal request URL for an invoice. |
|
136 | + * |
|
137 | + * @param WPInv_Invoice $invoice Invoice object. |
|
138 | + * @return string |
|
139 | + */ |
|
140 | + public function get_request_url( $invoice ) { |
|
141 | 141 | |
142 | 142 | // Endpoint for this request |
143 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
143 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
144 | 144 | |
145 | 145 | // Retrieve paypal args. |
146 | 146 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -153,45 +153,45 @@ discard block |
||
153 | 153 | |
154 | 154 | return add_query_arg( $paypal_args, $this->endpoint ); |
155 | 155 | |
156 | - } |
|
156 | + } |
|
157 | 157 | |
158 | 158 | /** |
159 | - * Get PayPal Args for passing to PP. |
|
160 | - * |
|
161 | - * @param WPInv_Invoice $invoice Invoice object. |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - protected function get_paypal_args( $invoice ) { |
|
159 | + * Get PayPal Args for passing to PP. |
|
160 | + * |
|
161 | + * @param WPInv_Invoice $invoice Invoice object. |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + protected function get_paypal_args( $invoice ) { |
|
165 | 165 | |
166 | 166 | // Whether or not to send the line items as one item. |
167 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
168 | - |
|
169 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
170 | - $force_one_line_item = true; |
|
171 | - } |
|
172 | - |
|
173 | - $paypal_args = apply_filters( |
|
174 | - 'getpaid_paypal_args', |
|
175 | - array_merge( |
|
176 | - $this->get_transaction_args( $invoice ), |
|
177 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
178 | - ), |
|
179 | - $invoice |
|
180 | - ); |
|
181 | - |
|
182 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
167 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
168 | + |
|
169 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
170 | + $force_one_line_item = true; |
|
171 | + } |
|
172 | + |
|
173 | + $paypal_args = apply_filters( |
|
174 | + 'getpaid_paypal_args', |
|
175 | + array_merge( |
|
176 | + $this->get_transaction_args( $invoice ), |
|
177 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
178 | + ), |
|
179 | + $invoice |
|
180 | + ); |
|
181 | + |
|
182 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
186 | - * Get transaction args for paypal request. |
|
187 | - * |
|
188 | - * @param WPInv_Invoice $invoice Invoice object. |
|
189 | - * @return array |
|
190 | - */ |
|
191 | - protected function get_transaction_args( $invoice ) { |
|
186 | + * Get transaction args for paypal request. |
|
187 | + * |
|
188 | + * @param WPInv_Invoice $invoice Invoice object. |
|
189 | + * @return array |
|
190 | + */ |
|
191 | + protected function get_transaction_args( $invoice ) { |
|
192 | 192 | |
193 | - $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
194 | - return array( |
|
193 | + $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
194 | + return array( |
|
195 | 195 | 'cmd' => '_cart', |
196 | 196 | 'business' => $email, |
197 | 197 | 'no_shipping' => '1', |
@@ -216,16 +216,16 @@ discard block |
||
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
219 | - * Get line item args for paypal request. |
|
220 | - * |
|
221 | - * @param WPInv_Invoice $invoice Invoice object. |
|
222 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
223 | - * @return array |
|
224 | - */ |
|
225 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
219 | + * Get line item args for paypal request. |
|
220 | + * |
|
221 | + * @param WPInv_Invoice $invoice Invoice object. |
|
222 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
223 | + * @return array |
|
224 | + */ |
|
225 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
226 | 226 | |
227 | 227 | // Maybe send invoice as a single item. |
228 | - if ( $force_one_line_item ) { |
|
228 | + if ( $force_one_line_item ) { |
|
229 | 229 | return $this->get_line_item_args_single_item( $invoice ); |
230 | 230 | } |
231 | 231 | |
@@ -245,134 +245,134 @@ discard block |
||
245 | 245 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
246 | 246 | } |
247 | 247 | |
248 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
248 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
249 | 249 | |
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
253 | - * Get line item args for paypal request as a single line item. |
|
254 | - * |
|
255 | - * @param WPInv_Invoice $invoice Invoice object. |
|
256 | - * @return array |
|
257 | - */ |
|
258 | - protected function get_line_item_args_single_item( $invoice ) { |
|
259 | - $this->delete_line_items(); |
|
253 | + * Get line item args for paypal request as a single line item. |
|
254 | + * |
|
255 | + * @param WPInv_Invoice $invoice Invoice object. |
|
256 | + * @return array |
|
257 | + */ |
|
258 | + protected function get_line_item_args_single_item( $invoice ) { |
|
259 | + $this->delete_line_items(); |
|
260 | 260 | |
261 | 261 | $item_name = wp_sprintf( __( 'Invoice %s', 'invoicing' ), $invoice->get_number() ); |
262 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
262 | + $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
263 | 263 | |
264 | - return $this->get_line_items(); |
|
264 | + return $this->get_line_items(); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
268 | - * Return all line items. |
|
269 | - */ |
|
270 | - protected function get_line_items() { |
|
271 | - return $this->line_items; |
|
272 | - } |
|
268 | + * Return all line items. |
|
269 | + */ |
|
270 | + protected function get_line_items() { |
|
271 | + return $this->line_items; |
|
272 | + } |
|
273 | 273 | |
274 | 274 | /** |
275 | - * Remove all line items. |
|
276 | - */ |
|
277 | - protected function delete_line_items() { |
|
278 | - $this->line_items = array(); |
|
275 | + * Remove all line items. |
|
276 | + */ |
|
277 | + protected function delete_line_items() { |
|
278 | + $this->line_items = array(); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
282 | - * Prepare line items to send to paypal. |
|
283 | - * |
|
284 | - * @param WPInv_Invoice $invoice Invoice object. |
|
285 | - */ |
|
286 | - protected function prepare_line_items( $invoice ) { |
|
287 | - $this->delete_line_items(); |
|
288 | - |
|
289 | - // Items. |
|
290 | - foreach ( $invoice->get_items() as $item ) { |
|
291 | - $amount = $item->get_price(); |
|
292 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
293 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
282 | + * Prepare line items to send to paypal. |
|
283 | + * |
|
284 | + * @param WPInv_Invoice $invoice Invoice object. |
|
285 | + */ |
|
286 | + protected function prepare_line_items( $invoice ) { |
|
287 | + $this->delete_line_items(); |
|
288 | + |
|
289 | + // Items. |
|
290 | + foreach ( $invoice->get_items() as $item ) { |
|
291 | + $amount = $item->get_price(); |
|
292 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
293 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | // Fees. |
297 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
297 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
298 | 298 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
299 | 299 | } |
300 | 300 | |
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
304 | - * Add PayPal Line Item. |
|
305 | - * |
|
306 | - * @param string $item_name Item name. |
|
307 | - * @param float $quantity Item quantity. |
|
308 | - * @param float $amount Amount. |
|
309 | - * @param string $item_number Item number. |
|
310 | - */ |
|
311 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
312 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
313 | - |
|
314 | - /** |
|
315 | - * Prevent error "Things don't appear to be working at the moment. (https://www.sandbox.paypal.com/webapps/hermes/error)" |
|
316 | - */ |
|
317 | - $item_name = str_replace( "#", "", $item_name ); |
|
318 | - |
|
319 | - $item = apply_filters( |
|
320 | - 'getpaid_paypal_line_item', |
|
321 | - array( |
|
322 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
323 | - 'quantity' => (float) $quantity, |
|
324 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
325 | - 'item_number' => $item_number, |
|
326 | - ), |
|
327 | - $item_name, |
|
328 | - $quantity, |
|
329 | - $amount, |
|
330 | - $item_number |
|
331 | - ); |
|
332 | - |
|
333 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
304 | + * Add PayPal Line Item. |
|
305 | + * |
|
306 | + * @param string $item_name Item name. |
|
307 | + * @param float $quantity Item quantity. |
|
308 | + * @param float $amount Amount. |
|
309 | + * @param string $item_number Item number. |
|
310 | + */ |
|
311 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
312 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
313 | + |
|
314 | + /** |
|
315 | + * Prevent error "Things don't appear to be working at the moment. (https://www.sandbox.paypal.com/webapps/hermes/error)" |
|
316 | + */ |
|
317 | + $item_name = str_replace( "#", "", $item_name ); |
|
318 | + |
|
319 | + $item = apply_filters( |
|
320 | + 'getpaid_paypal_line_item', |
|
321 | + array( |
|
322 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
323 | + 'quantity' => (float) $quantity, |
|
324 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
325 | + 'item_number' => $item_number, |
|
326 | + ), |
|
327 | + $item_name, |
|
328 | + $quantity, |
|
329 | + $amount, |
|
330 | + $item_number |
|
331 | + ); |
|
332 | + |
|
333 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
334 | 334 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
335 | 335 | |
336 | 336 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
337 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
338 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
337 | + $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
338 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
342 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
343 | - * |
|
344 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
345 | - * |
|
346 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
347 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
348 | - * @return array |
|
349 | - */ |
|
350 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
351 | - $max_paypal_length = 2083; |
|
352 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
353 | - |
|
354 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
355 | - return $paypal_args; |
|
356 | - } |
|
357 | - |
|
358 | - return apply_filters( |
|
359 | - 'getpaid_paypal_args', |
|
360 | - array_merge( |
|
361 | - $this->get_transaction_args( $invoice ), |
|
362 | - $this->get_line_item_args( $invoice, true ) |
|
363 | - ), |
|
364 | - $invoice |
|
365 | - ); |
|
342 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
343 | + * |
|
344 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
345 | + * |
|
346 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
347 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
348 | + * @return array |
|
349 | + */ |
|
350 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
351 | + $max_paypal_length = 2083; |
|
352 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
353 | + |
|
354 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
355 | + return $paypal_args; |
|
356 | + } |
|
357 | + |
|
358 | + return apply_filters( |
|
359 | + 'getpaid_paypal_args', |
|
360 | + array_merge( |
|
361 | + $this->get_transaction_args( $invoice ), |
|
362 | + $this->get_line_item_args( $invoice, true ) |
|
363 | + ), |
|
364 | + $invoice |
|
365 | + ); |
|
366 | 366 | |
367 | 367 | } |
368 | 368 | |
369 | 369 | /** |
370 | - * Processes recurring invoices. |
|
371 | - * |
|
372 | - * @param array $paypal_args PayPal args. |
|
373 | - * @param WPInv_Invoice $invoice Invoice object. |
|
374 | - */ |
|
375 | - public function process_subscription( $paypal_args, $invoice ) { |
|
370 | + * Processes recurring invoices. |
|
371 | + * |
|
372 | + * @param array $paypal_args PayPal args. |
|
373 | + * @param WPInv_Invoice $invoice Invoice object. |
|
374 | + */ |
|
375 | + public function process_subscription( $paypal_args, $invoice ) { |
|
376 | 376 | |
377 | 377 | // Make sure this is a subscription. |
378 | 378 | if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
@@ -393,21 +393,21 @@ discard block |
||
393 | 393 | $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
394 | 394 | $subscription_item = $invoice->get_recurring( true ); |
395 | 395 | |
396 | - // Convert 365 days to 1 year. |
|
397 | - if ( 'D' == $period && 365 == $interval ) { |
|
398 | - $period = 'Y'; |
|
399 | - $interval = 1; |
|
400 | - } |
|
396 | + // Convert 365 days to 1 year. |
|
397 | + if ( 'D' == $period && 365 == $interval ) { |
|
398 | + $period = 'Y'; |
|
399 | + $interval = 1; |
|
400 | + } |
|
401 | 401 | |
402 | 402 | if ( $subscription_item->has_free_trial() ) { |
403 | 403 | |
404 | 404 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
405 | 405 | |
406 | - // Trial period length. |
|
407 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
406 | + // Trial period length. |
|
407 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
408 | 408 | |
409 | - // Trial period. |
|
410 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
409 | + // Trial period. |
|
410 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
411 | 411 | |
412 | 412 | } elseif ( $initial_amount != $recurring_amount ) { |
413 | 413 | |
@@ -430,40 +430,40 @@ discard block |
||
430 | 430 | } |
431 | 431 | |
432 | 432 | // We have a recurring payment |
433 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
433 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
434 | 434 | |
435 | - // Subscription price |
|
436 | - $paypal_args['a3'] = $recurring_amount; |
|
435 | + // Subscription price |
|
436 | + $paypal_args['a3'] = $recurring_amount; |
|
437 | 437 | |
438 | - // Subscription duration |
|
439 | - $paypal_args['p3'] = $interval; |
|
438 | + // Subscription duration |
|
439 | + $paypal_args['p3'] = $interval; |
|
440 | 440 | |
441 | - // Subscription period |
|
442 | - $paypal_args['t3'] = $period; |
|
441 | + // Subscription period |
|
442 | + $paypal_args['t3'] = $period; |
|
443 | 443 | |
444 | 444 | } |
445 | 445 | |
446 | 446 | // Recurring payments |
447 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
447 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
448 | 448 | |
449 | - // Non-recurring payments |
|
450 | - $paypal_args['src'] = 0; |
|
449 | + // Non-recurring payments |
|
450 | + $paypal_args['src'] = 0; |
|
451 | 451 | |
452 | - } else { |
|
452 | + } else { |
|
453 | 453 | |
454 | - $paypal_args['src'] = 1; |
|
454 | + $paypal_args['src'] = 1; |
|
455 | 455 | |
456 | - if ( $bill_times > 0 ) { |
|
456 | + if ( $bill_times > 0 ) { |
|
457 | 457 | |
458 | - // An initial period is being used to charge a sign-up fee |
|
459 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
460 | - $bill_times--; |
|
461 | - } |
|
458 | + // An initial period is being used to charge a sign-up fee |
|
459 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
460 | + $bill_times--; |
|
461 | + } |
|
462 | 462 | |
463 | 463 | // Make sure it's not over the max of 52 |
464 | 464 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
465 | 465 | |
466 | - } |
|
466 | + } |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | // Force return URL so that order description & instructions display |
@@ -475,115 +475,115 @@ discard block |
||
475 | 475 | if ( isset( $paypal_args[ $arg ] ) ) { |
476 | 476 | unset( $paypal_args[ $arg ] ); |
477 | 477 | } |
478 | - } |
|
478 | + } |
|
479 | 479 | |
480 | 480 | return apply_filters( |
481 | - 'getpaid_paypal_subscription_args', |
|
482 | - $paypal_args, |
|
483 | - $invoice |
|
481 | + 'getpaid_paypal_subscription_args', |
|
482 | + $paypal_args, |
|
483 | + $invoice |
|
484 | + ); |
|
485 | + |
|
486 | + } |
|
487 | + |
|
488 | + /** |
|
489 | + * Refunds an invoice remotely. |
|
490 | + * |
|
491 | + * @since 2.8.24 |
|
492 | + * @param WPInv_Invoice $invoice Invoice object. |
|
493 | + */ |
|
494 | + public function refund_invoice( $invoice ) { |
|
495 | + |
|
496 | + if ( $invoice->get_gateway() !== $this->id ) { |
|
497 | + return; |
|
498 | + } |
|
499 | + |
|
500 | + $mode = $this->is_sandbox( $invoice ) ? 'sandbox' : 'live'; |
|
501 | + $result = GetPaid_PayPal_API::refund_capture( $invoice->get_transaction_id(), array(), $mode ); |
|
502 | + |
|
503 | + if ( is_wp_error( $result ) ) { |
|
504 | + $invoice->add_system_note( |
|
505 | + sprintf( |
|
506 | + // translators: %s is the error message. |
|
507 | + __( 'An error occured while trying to refund invoice #%1$s in PayPal: %2$s', 'invoicing' ), |
|
508 | + $invoice->get_id(), |
|
509 | + $result->get_error_message() |
|
510 | + ) |
|
511 | + ); |
|
512 | + } else { |
|
513 | + $invoice->add_system_note( |
|
514 | + sprintf( |
|
515 | + // translators: %s is the refund ID. |
|
516 | + __( 'Successfully refunded invoice #%1$s in PayPal. Refund ID: %2$s', 'invoicing' ), |
|
517 | + $invoice->get_id(), |
|
518 | + $result->id |
|
519 | + ) |
|
520 | + ); |
|
521 | + } |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * Cancels a subscription remotely. |
|
526 | + * |
|
527 | + * @since 2.8.24 |
|
528 | + * @param WPInv_Subscription $subscription Subscription object. |
|
529 | + */ |
|
530 | + public function subscription_cancelled( $subscription ) { |
|
531 | + |
|
532 | + if ( $subscription->get_gateway() != $this->id ) { |
|
533 | + return; |
|
534 | + } |
|
535 | + |
|
536 | + $invoice = $subscription->get_parent_invoice(); |
|
537 | + |
|
538 | + // Abort if the parent invoice does not exist. |
|
539 | + if ( ! $invoice->exists() ) { |
|
540 | + return; |
|
541 | + } |
|
542 | + |
|
543 | + $mode = $this->is_sandbox( $invoice ) ? 'sandbox' : 'live'; |
|
544 | + $result = GetPaid_PayPal_API::cancel_subscription( |
|
545 | + $invoice->get_remote_subscription_id(), |
|
546 | + array( |
|
547 | + 'reason' => __(' Customer requested cancellation', 'invoicing' ), |
|
548 | + ), |
|
549 | + $mode |
|
484 | 550 | ); |
485 | 551 | |
552 | + if ( is_wp_error( $result ) ) { |
|
553 | + |
|
554 | + $error = sprintf( |
|
555 | + // translators: %s is the subscription ID. |
|
556 | + __( 'An error occured while trying to cancel subscription #%s in PayPal.', 'invoicing' ), |
|
557 | + $subscription->get_id() |
|
558 | + ); |
|
559 | + |
|
560 | + getpaid_admin()->show_error( $error . ' ' . $result->get_error_message() ); |
|
561 | + |
|
562 | + if ( ! is_admin() ) { |
|
563 | + wpinv_set_error( $result->get_error_code(), $error ); |
|
564 | + } |
|
565 | + |
|
566 | + return; |
|
567 | + } |
|
568 | + |
|
569 | + if ( is_admin() ) { |
|
570 | + getpaid_admin()->show_success( |
|
571 | + sprintf( |
|
572 | + // translators: %s is the subscription ID. |
|
573 | + __( 'Successfully cancelled subscription #%s in PayPal.', 'invoicing' ), |
|
574 | + $subscription->get_id() |
|
575 | + ) |
|
576 | + ); |
|
577 | + } |
|
578 | + |
|
486 | 579 | } |
487 | 580 | |
488 | - /** |
|
489 | - * Refunds an invoice remotely. |
|
490 | - * |
|
491 | - * @since 2.8.24 |
|
492 | - * @param WPInv_Invoice $invoice Invoice object. |
|
493 | - */ |
|
494 | - public function refund_invoice( $invoice ) { |
|
495 | - |
|
496 | - if ( $invoice->get_gateway() !== $this->id ) { |
|
497 | - return; |
|
498 | - } |
|
499 | - |
|
500 | - $mode = $this->is_sandbox( $invoice ) ? 'sandbox' : 'live'; |
|
501 | - $result = GetPaid_PayPal_API::refund_capture( $invoice->get_transaction_id(), array(), $mode ); |
|
502 | - |
|
503 | - if ( is_wp_error( $result ) ) { |
|
504 | - $invoice->add_system_note( |
|
505 | - sprintf( |
|
506 | - // translators: %s is the error message. |
|
507 | - __( 'An error occured while trying to refund invoice #%1$s in PayPal: %2$s', 'invoicing' ), |
|
508 | - $invoice->get_id(), |
|
509 | - $result->get_error_message() |
|
510 | - ) |
|
511 | - ); |
|
512 | - } else { |
|
513 | - $invoice->add_system_note( |
|
514 | - sprintf( |
|
515 | - // translators: %s is the refund ID. |
|
516 | - __( 'Successfully refunded invoice #%1$s in PayPal. Refund ID: %2$s', 'invoicing' ), |
|
517 | - $invoice->get_id(), |
|
518 | - $result->id |
|
519 | - ) |
|
520 | - ); |
|
521 | - } |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * Cancels a subscription remotely. |
|
526 | - * |
|
527 | - * @since 2.8.24 |
|
528 | - * @param WPInv_Subscription $subscription Subscription object. |
|
529 | - */ |
|
530 | - public function subscription_cancelled( $subscription ) { |
|
531 | - |
|
532 | - if ( $subscription->get_gateway() != $this->id ) { |
|
533 | - return; |
|
534 | - } |
|
535 | - |
|
536 | - $invoice = $subscription->get_parent_invoice(); |
|
537 | - |
|
538 | - // Abort if the parent invoice does not exist. |
|
539 | - if ( ! $invoice->exists() ) { |
|
540 | - return; |
|
541 | - } |
|
542 | - |
|
543 | - $mode = $this->is_sandbox( $invoice ) ? 'sandbox' : 'live'; |
|
544 | - $result = GetPaid_PayPal_API::cancel_subscription( |
|
545 | - $invoice->get_remote_subscription_id(), |
|
546 | - array( |
|
547 | - 'reason' => __(' Customer requested cancellation', 'invoicing' ), |
|
548 | - ), |
|
549 | - $mode |
|
550 | - ); |
|
551 | - |
|
552 | - if ( is_wp_error( $result ) ) { |
|
553 | - |
|
554 | - $error = sprintf( |
|
555 | - // translators: %s is the subscription ID. |
|
556 | - __( 'An error occured while trying to cancel subscription #%s in PayPal.', 'invoicing' ), |
|
557 | - $subscription->get_id() |
|
558 | - ); |
|
559 | - |
|
560 | - getpaid_admin()->show_error( $error . ' ' . $result->get_error_message() ); |
|
561 | - |
|
562 | - if ( ! is_admin() ) { |
|
563 | - wpinv_set_error( $result->get_error_code(), $error ); |
|
564 | - } |
|
565 | - |
|
566 | - return; |
|
567 | - } |
|
568 | - |
|
569 | - if ( is_admin() ) { |
|
570 | - getpaid_admin()->show_success( |
|
571 | - sprintf( |
|
572 | - // translators: %s is the subscription ID. |
|
573 | - __( 'Successfully cancelled subscription #%s in PayPal.', 'invoicing' ), |
|
574 | - $subscription->get_id() |
|
575 | - ) |
|
576 | - ); |
|
577 | - } |
|
578 | - |
|
579 | - } |
|
580 | - |
|
581 | - /** |
|
582 | - * Processes ipns and marks payments as complete. |
|
583 | - * |
|
584 | - * @return void |
|
585 | - */ |
|
586 | - public function verify_ipn() { |
|
581 | + /** |
|
582 | + * Processes ipns and marks payments as complete. |
|
583 | + * |
|
584 | + * @return void |
|
585 | + */ |
|
586 | + public function verify_ipn() { |
|
587 | 587 | new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
588 | 588 | } |
589 | 589 | |
@@ -593,19 +593,19 @@ discard block |
||
593 | 593 | public function sandbox_notice() { |
594 | 594 | |
595 | 595 | return sprintf( |
596 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
597 | - '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
598 | - '</a>' |
|
599 | - ); |
|
596 | + __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
597 | + '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
598 | + '</a>' |
|
599 | + ); |
|
600 | 600 | |
601 | 601 | } |
602 | 602 | |
603 | - /** |
|
604 | - * Filters the gateway settings. |
|
605 | - * |
|
606 | - * @param array $admin_settings |
|
607 | - */ |
|
608 | - public function admin_settings( $admin_settings ) { |
|
603 | + /** |
|
604 | + * Filters the gateway settings. |
|
605 | + * |
|
606 | + * @param array $admin_settings |
|
607 | + */ |
|
608 | + public function admin_settings( $admin_settings ) { |
|
609 | 609 | |
610 | 610 | $currencies = sprintf( |
611 | 611 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -615,66 +615,66 @@ discard block |
||
615 | 615 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
616 | 616 | $admin_settings['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
617 | 617 | |
618 | - // Access tokens. |
|
619 | - $live_email = wpinv_get_option( 'paypal_email' ); |
|
620 | - $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
618 | + // Access tokens. |
|
619 | + $live_email = wpinv_get_option( 'paypal_email' ); |
|
620 | + $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
621 | 621 | |
622 | - $admin_settings['paypal_connect'] = array( |
|
623 | - 'type' => 'hook', |
|
624 | - 'id' => 'paypal_connect', |
|
625 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
626 | - ); |
|
622 | + $admin_settings['paypal_connect'] = array( |
|
623 | + 'type' => 'hook', |
|
624 | + 'id' => 'paypal_connect', |
|
625 | + 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
626 | + ); |
|
627 | 627 | |
628 | 628 | $admin_settings['paypal_email'] = array( |
629 | 629 | 'type' => 'text', |
630 | - 'class' => 'live-auth-data', |
|
630 | + 'class' => 'live-auth-data', |
|
631 | 631 | 'id' => 'paypal_email', |
632 | 632 | 'name' => __( 'Live Email Address', 'invoicing' ), |
633 | 633 | 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
634 | 634 | ); |
635 | 635 | |
636 | - $admin_settings['paypal_sandbox_email'] = array( |
|
636 | + $admin_settings['paypal_sandbox_email'] = array( |
|
637 | 637 | 'type' => 'text', |
638 | - 'class' => 'sandbox-auth-data', |
|
638 | + 'class' => 'sandbox-auth-data', |
|
639 | 639 | 'id' => 'paypal_sandbox_email', |
640 | 640 | 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
641 | 641 | 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
642 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
642 | + 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
643 | + ); |
|
644 | + |
|
645 | + // Client ID and secret. |
|
646 | + $admin_settings['paypal_client_id'] = array( |
|
647 | + 'type' => 'text', |
|
648 | + 'class' => 'live-auth-data', |
|
649 | + 'id' => 'paypal_client_id', |
|
650 | + 'name' => __( 'Live Client ID', 'invoicing' ), |
|
651 | + 'desc' => __( 'The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
652 | + ); |
|
653 | + |
|
654 | + $admin_settings['paypal_sandbox_client_id'] = array( |
|
655 | + 'type' => 'text', |
|
656 | + 'class' => 'sandbox-auth-data', |
|
657 | + 'id' => 'paypal_sandbox_client_id', |
|
658 | + 'name' => __( 'Sandbox Client ID', 'invoicing' ), |
|
659 | + 'desc' => __( 'The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
660 | + 'std' => wpinv_get_option( 'paypal_client_id', '' ), |
|
643 | 661 | ); |
644 | 662 | |
645 | - // Client ID and secret. |
|
646 | - $admin_settings['paypal_client_id'] = array( |
|
647 | - 'type' => 'text', |
|
648 | - 'class' => 'live-auth-data', |
|
649 | - 'id' => 'paypal_client_id', |
|
650 | - 'name' => __( 'Live Client ID', 'invoicing' ), |
|
651 | - 'desc' => __( 'The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
652 | - ); |
|
653 | - |
|
654 | - $admin_settings['paypal_sandbox_client_id'] = array( |
|
655 | - 'type' => 'text', |
|
656 | - 'class' => 'sandbox-auth-data', |
|
657 | - 'id' => 'paypal_sandbox_client_id', |
|
658 | - 'name' => __( 'Sandbox Client ID', 'invoicing' ), |
|
659 | - 'desc' => __( 'The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
660 | - 'std' => wpinv_get_option( 'paypal_client_id', '' ), |
|
661 | - ); |
|
662 | - |
|
663 | - $admin_settings['paypal_secret'] = array( |
|
664 | - 'type' => 'text', |
|
665 | - 'class' => 'live-auth-data', |
|
666 | - 'id' => 'paypal_secret', |
|
667 | - 'name' => __( 'Live Secret', 'invoicing' ), |
|
668 | - 'desc' => __( 'The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
669 | - ); |
|
670 | - |
|
671 | - $admin_settings['paypal_sandbox_secret'] = array( |
|
672 | - 'type' => 'text', |
|
673 | - 'class' => 'sandbox-auth-data', |
|
674 | - 'id' => 'paypal_sandbox_secret', |
|
675 | - 'name' => __( 'Sandbox Secret', 'invoicing' ), |
|
676 | - 'desc' => __( 'The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
677 | - ); |
|
663 | + $admin_settings['paypal_secret'] = array( |
|
664 | + 'type' => 'text', |
|
665 | + 'class' => 'live-auth-data', |
|
666 | + 'id' => 'paypal_secret', |
|
667 | + 'name' => __( 'Live Secret', 'invoicing' ), |
|
668 | + 'desc' => __( 'The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
669 | + ); |
|
670 | + |
|
671 | + $admin_settings['paypal_sandbox_secret'] = array( |
|
672 | + 'type' => 'text', |
|
673 | + 'class' => 'sandbox-auth-data', |
|
674 | + 'id' => 'paypal_sandbox_secret', |
|
675 | + 'name' => __( 'Sandbox Secret', 'invoicing' ), |
|
676 | + 'desc' => __( 'The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
677 | + ); |
|
678 | 678 | |
679 | 679 | $admin_settings['paypal_ipn_url'] = array( |
680 | 680 | 'type' => 'ipn_url', |
@@ -685,57 +685,57 @@ discard block |
||
685 | 685 | 'readonly' => true, |
686 | 686 | ); |
687 | 687 | |
688 | - return $admin_settings; |
|
689 | - } |
|
690 | - |
|
691 | - /** |
|
692 | - * Retrieves the URL to cancel a subscription. |
|
693 | - * |
|
694 | - * @param string $url |
|
695 | - * @param WPInv_Subscription $subscription |
|
696 | - */ |
|
697 | - public function filter_cancel_subscription_url( $url, $subscription ) { |
|
698 | - |
|
699 | - if ( $this->id !== $subscription->get_gateway() ) { |
|
700 | - return $url; |
|
701 | - } |
|
702 | - |
|
703 | - // Get the PayPal profile ID. |
|
704 | - $profile_id = $subscription->get_profile_id(); |
|
705 | - |
|
706 | - // Bail if no profile ID. |
|
707 | - if ( empty( $profile_id ) ) { |
|
708 | - return $url; |
|
709 | - } |
|
710 | - |
|
711 | - $cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel'; |
|
712 | - if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) { |
|
713 | - $cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel'; |
|
714 | - } |
|
715 | - |
|
716 | - return sprintf( $cancel_url, $profile_id ); |
|
717 | - } |
|
718 | - |
|
719 | - /** |
|
720 | - * Retrieves the PayPal connect URL when using the setup wizzard. |
|
721 | - * |
|
722 | - * |
|
688 | + return $admin_settings; |
|
689 | + } |
|
690 | + |
|
691 | + /** |
|
692 | + * Retrieves the URL to cancel a subscription. |
|
693 | + * |
|
694 | + * @param string $url |
|
695 | + * @param WPInv_Subscription $subscription |
|
696 | + */ |
|
697 | + public function filter_cancel_subscription_url( $url, $subscription ) { |
|
698 | + |
|
699 | + if ( $this->id !== $subscription->get_gateway() ) { |
|
700 | + return $url; |
|
701 | + } |
|
702 | + |
|
703 | + // Get the PayPal profile ID. |
|
704 | + $profile_id = $subscription->get_profile_id(); |
|
705 | + |
|
706 | + // Bail if no profile ID. |
|
707 | + if ( empty( $profile_id ) ) { |
|
708 | + return $url; |
|
709 | + } |
|
710 | + |
|
711 | + $cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel'; |
|
712 | + if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) { |
|
713 | + $cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel'; |
|
714 | + } |
|
715 | + |
|
716 | + return sprintf( $cancel_url, $profile_id ); |
|
717 | + } |
|
718 | + |
|
719 | + /** |
|
720 | + * Retrieves the PayPal connect URL when using the setup wizzard. |
|
721 | + * |
|
722 | + * |
|
723 | 723 | * @param array $data |
724 | 724 | * @return string |
725 | - */ |
|
726 | - public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
727 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
728 | - } |
|
729 | - |
|
730 | - /** |
|
731 | - * Retrieves the PayPal connect URL. |
|
732 | - * |
|
733 | - * |
|
725 | + */ |
|
726 | + public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
727 | + return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
728 | + } |
|
729 | + |
|
730 | + /** |
|
731 | + * Retrieves the PayPal connect URL. |
|
732 | + * |
|
733 | + * |
|
734 | 734 | * @param bool $is_sandbox |
735 | - * @param string $redirect |
|
735 | + * @param string $redirect |
|
736 | 736 | * @return string |
737 | - */ |
|
738 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
737 | + */ |
|
738 | + public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
739 | 739 | |
740 | 740 | $redirect_url = add_query_arg( |
741 | 741 | array( |
@@ -745,7 +745,7 @@ discard block |
||
745 | 745 | 'tab' => 'gateways', |
746 | 746 | 'section' => 'paypal', |
747 | 747 | 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
748 | - 'redirect' => urlencode( $redirect ), |
|
748 | + 'redirect' => urlencode( $redirect ), |
|
749 | 749 | ), |
750 | 750 | admin_url( 'admin.php' ) |
751 | 751 | ); |
@@ -760,12 +760,12 @@ discard block |
||
760 | 760 | |
761 | 761 | } |
762 | 762 | |
763 | - /** |
|
764 | - * Generates settings page js. |
|
765 | - * |
|
763 | + /** |
|
764 | + * Generates settings page js. |
|
765 | + * |
|
766 | 766 | * @return void |
767 | - */ |
|
768 | - public static function display_connect_buttons() { |
|
767 | + */ |
|
768 | + public static function display_connect_buttons() { |
|
769 | 769 | |
770 | 770 | ?> |
771 | 771 | <div class="wpinv-paypal-connect-live"> |
@@ -807,70 +807,70 @@ discard block |
||
807 | 807 | <?php |
808 | 808 | } |
809 | 809 | |
810 | - /** |
|
811 | - * Connects to PayPal. |
|
812 | - * |
|
813 | - * @param array $data Connection data. |
|
814 | - * @return void |
|
815 | - */ |
|
816 | - public function connect_paypal( $data ) { |
|
817 | - |
|
818 | - $sandbox = $this->is_sandbox(); |
|
819 | - $data = wp_unslash( $data ); |
|
820 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
821 | - |
|
822 | - if ( isset( $data['live_mode'] ) ) { |
|
823 | - $sandbox = empty( $data['live_mode'] ); |
|
824 | - } |
|
825 | - |
|
826 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
827 | - wpinv_update_option( 'paypal_active', 1 ); |
|
828 | - |
|
829 | - if ( ! empty( $data['error_description'] ) ) { |
|
830 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
831 | - } else { |
|
832 | - |
|
833 | - // Retrieve the user info. |
|
834 | - $user_info = wp_remote_get( |
|
835 | - ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
836 | - array( |
|
837 | - |
|
838 | - 'headers' => array( |
|
839 | - 'Authorization' => 'Bearer ' . $access_token, |
|
840 | - 'Content-type' => 'application/json', |
|
841 | - ), |
|
842 | - |
|
843 | - ) |
|
844 | - ); |
|
845 | - |
|
846 | - if ( is_wp_error( $user_info ) ) { |
|
847 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
848 | - } else { |
|
849 | - |
|
850 | - // Create application. |
|
851 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
852 | - |
|
853 | - if ( $sandbox ) { |
|
854 | - wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
855 | - wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
856 | - set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
857 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
858 | - } else { |
|
859 | - wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
860 | - wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
861 | - set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
862 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
863 | - } |
|
864 | - } |
|
865 | - } |
|
866 | - |
|
867 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
868 | - |
|
869 | - if ( isset( $data['step'] ) ) { |
|
870 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
871 | - } |
|
872 | - wp_redirect( $redirect ); |
|
873 | - exit; |
|
874 | - } |
|
810 | + /** |
|
811 | + * Connects to PayPal. |
|
812 | + * |
|
813 | + * @param array $data Connection data. |
|
814 | + * @return void |
|
815 | + */ |
|
816 | + public function connect_paypal( $data ) { |
|
817 | + |
|
818 | + $sandbox = $this->is_sandbox(); |
|
819 | + $data = wp_unslash( $data ); |
|
820 | + $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
821 | + |
|
822 | + if ( isset( $data['live_mode'] ) ) { |
|
823 | + $sandbox = empty( $data['live_mode'] ); |
|
824 | + } |
|
825 | + |
|
826 | + wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
827 | + wpinv_update_option( 'paypal_active', 1 ); |
|
828 | + |
|
829 | + if ( ! empty( $data['error_description'] ) ) { |
|
830 | + getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
831 | + } else { |
|
832 | + |
|
833 | + // Retrieve the user info. |
|
834 | + $user_info = wp_remote_get( |
|
835 | + ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
836 | + array( |
|
837 | + |
|
838 | + 'headers' => array( |
|
839 | + 'Authorization' => 'Bearer ' . $access_token, |
|
840 | + 'Content-type' => 'application/json', |
|
841 | + ), |
|
842 | + |
|
843 | + ) |
|
844 | + ); |
|
845 | + |
|
846 | + if ( is_wp_error( $user_info ) ) { |
|
847 | + getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
848 | + } else { |
|
849 | + |
|
850 | + // Create application. |
|
851 | + $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
852 | + |
|
853 | + if ( $sandbox ) { |
|
854 | + wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
855 | + wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
856 | + set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
857 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
858 | + } else { |
|
859 | + wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
860 | + wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
861 | + set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
862 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
863 | + } |
|
864 | + } |
|
865 | + } |
|
866 | + |
|
867 | + $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
868 | + |
|
869 | + if ( isset( $data['step'] ) ) { |
|
870 | + $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
871 | + } |
|
872 | + wp_redirect( $redirect ); |
|
873 | + exit; |
|
874 | + } |
|
875 | 875 | |
876 | 876 | } |
@@ -13,19 +13,19 @@ |
||
13 | 13 | $label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
14 | 14 | |
15 | 15 | if ( ! empty( $required ) ) { |
16 | - $label .= "<span class='text-danger'> *</span>"; |
|
16 | + $label .= "<span class='text-danger'> *</span>"; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | aui()->input( |
20 | - array( |
|
21 | - 'type' => 'checkbox', |
|
22 | - 'name' => esc_attr( $id ), |
|
23 | - 'id' => esc_attr( $element_id ), |
|
24 | - 'required' => ! empty( $required ), |
|
25 | - 'label' => $label, |
|
26 | - 'value' => esc_attr__( 'Yes', 'invoicing' ), |
|
27 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
28 | - 'class' => $label_class |
|
29 | - ), |
|
30 | - true |
|
20 | + array( |
|
21 | + 'type' => 'checkbox', |
|
22 | + 'name' => esc_attr( $id ), |
|
23 | + 'id' => esc_attr( $element_id ), |
|
24 | + 'required' => ! empty( $required ), |
|
25 | + 'label' => $label, |
|
26 | + 'value' => esc_attr__( 'Yes', 'invoicing' ), |
|
27 | + 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
28 | + 'class' => $label_class |
|
29 | + ), |
|
30 | + true |
|
31 | 31 | ); |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | defined( 'ABSPATH' ) || exit; |
11 | 11 | |
12 | 12 | if ( empty( $fields ) ) { |
13 | - return; |
|
13 | + return; |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | // A prefix for all ids (so that a form can be included in the same page multiple times). |
@@ -18,12 +18,12 @@ discard block |
||
18 | 18 | |
19 | 19 | // Prepare the user's country. |
20 | 20 | if ( ! empty( $form->invoice ) ) { |
21 | - $country = $form->invoice->get_country(); |
|
21 | + $country = $form->invoice->get_country(); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | if ( empty( $country ) ) { |
25 | - $country = empty( $country ) ? getpaid_get_ip_country() : $country; |
|
26 | - $country = empty( $country ) ? wpinv_get_default_country() : $country; |
|
25 | + $country = empty( $country ) ? getpaid_get_ip_country() : $country; |
|
26 | + $country = empty( $country ) ? wpinv_get_default_country() : $country; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // A prefix for all ids (so that a form can be included in the same page multiple times). |
@@ -50,32 +50,32 @@ discard block |
||
50 | 50 | <!-- Start Billing Address --> |
51 | 51 | <div class="getpaid-billing-address-wrapper"> |
52 | 52 | <?php |
53 | - $field_type = 'billing'; |
|
53 | + $field_type = 'billing'; |
|
54 | 54 | |
55 | - wpinv_get_template( 'payment-forms/elements/address-fields.php', array( 'form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country ) ); |
|
55 | + wpinv_get_template( 'payment-forms/elements/address-fields.php', array( 'form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country ) ); |
|
56 | 56 | |
57 | - do_action( 'getpaid_after_payment_form_billing_fields', $form ); |
|
58 | - ?> |
|
57 | + do_action( 'getpaid_after_payment_form_billing_fields', $form ); |
|
58 | + ?> |
|
59 | 59 | </div> |
60 | 60 | <!-- End Billing Address --> |
61 | 61 | <?php endif; ?> |
62 | 62 | |
63 | 63 | <?php if ( 'both' === $address_type ) : ?> |
64 | 64 | <?php |
65 | - aui()->input( |
|
66 | - array( |
|
67 | - 'type' => 'checkbox', |
|
68 | - 'name' => 'same-shipping-address', |
|
69 | - 'id' => "shipping-toggle$uniqid", |
|
70 | - 'required' => false, |
|
71 | - 'label' => empty( $shipping_address_toggle ) ? esc_html__( 'Same billing & shipping address.', 'invoicing' ) : wp_kses_post( $shipping_address_toggle ), |
|
72 | - 'value' => 1, |
|
73 | - 'checked' => true, |
|
74 | - 'class' => 'chkbox-same-shipping-address' |
|
75 | - ), |
|
76 | - true |
|
77 | - ); |
|
78 | - ?> |
|
65 | + aui()->input( |
|
66 | + array( |
|
67 | + 'type' => 'checkbox', |
|
68 | + 'name' => 'same-shipping-address', |
|
69 | + 'id' => "shipping-toggle$uniqid", |
|
70 | + 'required' => false, |
|
71 | + 'label' => empty( $shipping_address_toggle ) ? esc_html__( 'Same billing & shipping address.', 'invoicing' ) : wp_kses_post( $shipping_address_toggle ), |
|
72 | + 'value' => 1, |
|
73 | + 'checked' => true, |
|
74 | + 'class' => 'chkbox-same-shipping-address' |
|
75 | + ), |
|
76 | + true |
|
77 | + ); |
|
78 | + ?> |
|
79 | 79 | <!-- Start Shipping Address Title --> |
80 | 80 | <h4 class="mb-3 getpaid-shipping-address-title"> |
81 | 81 | <?php esc_html_e( 'Shipping Address', 'invoicing' ); ?> |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | <!-- Start Shipping Address --> |
88 | 88 | <div class="getpaid-shipping-address-wrapper"> |
89 | 89 | <?php |
90 | - $field_type = 'shipping'; |
|
90 | + $field_type = 'shipping'; |
|
91 | 91 | |
92 | - wpinv_get_template( 'payment-forms/elements/address-fields.php', array( 'form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country ) ); |
|
92 | + wpinv_get_template( 'payment-forms/elements/address-fields.php', array( 'form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country ) ); |
|
93 | 93 | |
94 | - do_action( 'getpaid_after_payment_form_shipping_fields', $form ); |
|
95 | - ?> |
|
94 | + do_action( 'getpaid_after_payment_form_shipping_fields', $form ); |
|
95 | + ?> |
|
96 | 96 | </div> |
97 | 97 | <!-- End Shipping Address --> |
98 | 98 | <?php endif; ?> |
@@ -13,755 +13,755 @@ discard block |
||
13 | 13 | class GetPaid_Post_Types_Admin { |
14 | 14 | |
15 | 15 | /** |
16 | - * Hook in methods. |
|
17 | - */ |
|
18 | - public static function init() { |
|
19 | - |
|
20 | - // Init metaboxes. |
|
21 | - GetPaid_Metaboxes::init(); |
|
22 | - |
|
23 | - // Filter the post updated messages. |
|
24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
25 | - |
|
26 | - // Filter post actions. |
|
27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
28 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
29 | - |
|
30 | - // Invoice table columns. |
|
31 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
32 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
33 | - add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
34 | - add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
35 | - |
|
36 | - // Items table columns. |
|
37 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
38 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
39 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
40 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
41 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
42 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
43 | - |
|
44 | - // Payment forms columns. |
|
45 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
46 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
47 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
48 | - |
|
49 | - // Discount table columns. |
|
50 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
51 | - add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
52 | - |
|
53 | - // Deleting posts. |
|
54 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
55 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
56 | - |
|
57 | - add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Post updated messages. |
|
62 | - */ |
|
63 | - public static function post_updated_messages( $messages ) { |
|
64 | - global $post; |
|
65 | - |
|
66 | - $messages['wpi_discount'] = array( |
|
67 | - 0 => '', |
|
68 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
69 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
70 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
71 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
72 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
73 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
74 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
75 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
76 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
77 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
78 | - ); |
|
79 | - |
|
80 | - $messages['wpi_payment_form'] = array( |
|
81 | - 0 => '', |
|
82 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
83 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
84 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
85 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
86 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
87 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
88 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
89 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
90 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
91 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
92 | - ); |
|
93 | - |
|
94 | - return $messages; |
|
95 | - |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Post row actions. |
|
100 | - */ |
|
101 | - public static function post_row_actions( $actions, $post ) { |
|
102 | - |
|
103 | - $post = get_post( $post ); |
|
104 | - |
|
105 | - // We do not want to edit the default payment form. |
|
106 | - if ( 'wpi_payment_form' == $post->post_type ) { |
|
107 | - |
|
108 | - if ( wpinv_get_default_payment_form() === $post->ID ) { |
|
109 | - unset( $actions['trash'] ); |
|
110 | - unset( $actions['inline hide-if-no-js'] ); |
|
111 | - } |
|
112 | - |
|
113 | - $actions['duplicate'] = sprintf( |
|
114 | - '<a href="%1$s">%2$s</a>', |
|
115 | - esc_url( |
|
116 | - wp_nonce_url( |
|
117 | - add_query_arg( |
|
118 | - array( |
|
119 | - 'getpaid-admin-action' => 'duplicate_form', |
|
120 | - 'form_id' => $post->ID, |
|
121 | - ) |
|
122 | - ), |
|
123 | - 'getpaid-nonce', |
|
124 | - 'getpaid-nonce' |
|
125 | - ) |
|
126 | - ), |
|
127 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
128 | - ); |
|
129 | - |
|
130 | - $actions['reset'] = sprintf( |
|
131 | - '<a href="%1$s" style="color: #800">%2$s</a>', |
|
132 | - esc_url( |
|
133 | - wp_nonce_url( |
|
134 | - add_query_arg( |
|
135 | - array( |
|
136 | - 'getpaid-admin-action' => 'reset_form_stats', |
|
137 | - 'form_id' => $post->ID, |
|
138 | - ) |
|
139 | - ), |
|
140 | - 'getpaid-nonce', |
|
141 | - 'getpaid-nonce' |
|
142 | - ) |
|
143 | - ), |
|
144 | - esc_html( __( 'Reset Stats', 'invoicing' ) ) |
|
145 | - ); |
|
146 | - } |
|
147 | - |
|
148 | - // Link to item payment form. |
|
149 | - if ( 'wpi_item' == $post->post_type ) { |
|
150 | - if ( getpaid_item_type_supports( get_post_meta( $post->ID, '_wpinv_type', true ), 'buy_now' ) ) { |
|
151 | - $actions['buy'] = sprintf( |
|
152 | - '<a href="%1$s">%2$s</a>', |
|
153 | - esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ), |
|
154 | - esc_html( __( 'Buy', 'invoicing' ) ) |
|
155 | - ); |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - return $actions; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
16 | + * Hook in methods. |
|
17 | + */ |
|
18 | + public static function init() { |
|
19 | + |
|
20 | + // Init metaboxes. |
|
21 | + GetPaid_Metaboxes::init(); |
|
22 | + |
|
23 | + // Filter the post updated messages. |
|
24 | + add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
25 | + |
|
26 | + // Filter post actions. |
|
27 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
28 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
29 | + |
|
30 | + // Invoice table columns. |
|
31 | + add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
32 | + add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
33 | + add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
34 | + add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
35 | + |
|
36 | + // Items table columns. |
|
37 | + add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
38 | + add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
39 | + add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
40 | + add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
41 | + add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
42 | + add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
43 | + |
|
44 | + // Payment forms columns. |
|
45 | + add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
46 | + add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
47 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
48 | + |
|
49 | + // Discount table columns. |
|
50 | + add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
51 | + add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
52 | + |
|
53 | + // Deleting posts. |
|
54 | + add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
55 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
56 | + |
|
57 | + add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Post updated messages. |
|
62 | + */ |
|
63 | + public static function post_updated_messages( $messages ) { |
|
64 | + global $post; |
|
65 | + |
|
66 | + $messages['wpi_discount'] = array( |
|
67 | + 0 => '', |
|
68 | + 1 => __( 'Discount updated.', 'invoicing' ), |
|
69 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
70 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
71 | + 4 => __( 'Discount updated.', 'invoicing' ), |
|
72 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
73 | + 6 => __( 'Discount updated.', 'invoicing' ), |
|
74 | + 7 => __( 'Discount saved.', 'invoicing' ), |
|
75 | + 8 => __( 'Discount submitted.', 'invoicing' ), |
|
76 | + 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
77 | + 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
78 | + ); |
|
79 | + |
|
80 | + $messages['wpi_payment_form'] = array( |
|
81 | + 0 => '', |
|
82 | + 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
83 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
84 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
85 | + 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
86 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
87 | + 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
88 | + 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
89 | + 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
90 | + 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
91 | + 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
92 | + ); |
|
93 | + |
|
94 | + return $messages; |
|
95 | + |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Post row actions. |
|
100 | + */ |
|
101 | + public static function post_row_actions( $actions, $post ) { |
|
102 | + |
|
103 | + $post = get_post( $post ); |
|
104 | + |
|
105 | + // We do not want to edit the default payment form. |
|
106 | + if ( 'wpi_payment_form' == $post->post_type ) { |
|
107 | + |
|
108 | + if ( wpinv_get_default_payment_form() === $post->ID ) { |
|
109 | + unset( $actions['trash'] ); |
|
110 | + unset( $actions['inline hide-if-no-js'] ); |
|
111 | + } |
|
112 | + |
|
113 | + $actions['duplicate'] = sprintf( |
|
114 | + '<a href="%1$s">%2$s</a>', |
|
115 | + esc_url( |
|
116 | + wp_nonce_url( |
|
117 | + add_query_arg( |
|
118 | + array( |
|
119 | + 'getpaid-admin-action' => 'duplicate_form', |
|
120 | + 'form_id' => $post->ID, |
|
121 | + ) |
|
122 | + ), |
|
123 | + 'getpaid-nonce', |
|
124 | + 'getpaid-nonce' |
|
125 | + ) |
|
126 | + ), |
|
127 | + esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
128 | + ); |
|
129 | + |
|
130 | + $actions['reset'] = sprintf( |
|
131 | + '<a href="%1$s" style="color: #800">%2$s</a>', |
|
132 | + esc_url( |
|
133 | + wp_nonce_url( |
|
134 | + add_query_arg( |
|
135 | + array( |
|
136 | + 'getpaid-admin-action' => 'reset_form_stats', |
|
137 | + 'form_id' => $post->ID, |
|
138 | + ) |
|
139 | + ), |
|
140 | + 'getpaid-nonce', |
|
141 | + 'getpaid-nonce' |
|
142 | + ) |
|
143 | + ), |
|
144 | + esc_html( __( 'Reset Stats', 'invoicing' ) ) |
|
145 | + ); |
|
146 | + } |
|
147 | + |
|
148 | + // Link to item payment form. |
|
149 | + if ( 'wpi_item' == $post->post_type ) { |
|
150 | + if ( getpaid_item_type_supports( get_post_meta( $post->ID, '_wpinv_type', true ), 'buy_now' ) ) { |
|
151 | + $actions['buy'] = sprintf( |
|
152 | + '<a href="%1$s">%2$s</a>', |
|
153 | + esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ), |
|
154 | + esc_html( __( 'Buy', 'invoicing' ) ) |
|
155 | + ); |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + return $actions; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | 163 | * Remove bulk edit option from admin side quote listing |
164 | 164 | * |
165 | 165 | * @since 1.0.0 |
166 | 166 | * @param array $actions post actions |
167 | - * @param WP_Post $post |
|
167 | + * @param WP_Post $post |
|
168 | 168 | * @return array $actions actions without edit option |
169 | 169 | */ |
170 | 170 | public static function filter_invoice_row_actions( $actions, $post ) { |
171 | 171 | |
172 | 172 | if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
173 | 173 | |
174 | - $actions = array(); |
|
175 | - $invoice = new WPInv_Invoice( $post ); |
|
176 | - |
|
177 | - $actions['edit'] = sprintf( |
|
178 | - '<a href="%1$s">%2$s</a>', |
|
179 | - esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
180 | - esc_html( __( 'Edit', 'invoicing' ) ) |
|
181 | - ); |
|
182 | - |
|
183 | - if ( ! $invoice->is_draft() ) { |
|
184 | - |
|
185 | - $actions['view'] = sprintf( |
|
186 | - '<a href="%1$s">%2$s</a>', |
|
187 | - esc_url( $invoice->get_view_url() ), |
|
188 | - sprintf( |
|
189 | - // translators: %s is the invoice type |
|
190 | - esc_html__( 'View %s', 'invoicing' ), |
|
191 | - getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
192 | - ) |
|
193 | - ); |
|
194 | - |
|
195 | - $actions['send'] = sprintf( |
|
196 | - '<a href="%1$s">%2$s</a>', |
|
197 | - esc_url( |
|
198 | - wp_nonce_url( |
|
199 | - add_query_arg( |
|
200 | - array( |
|
201 | - 'getpaid-admin-action' => 'send_invoice', |
|
202 | - 'invoice_id' => $invoice->get_id(), |
|
203 | - ) |
|
204 | - ), |
|
205 | - 'getpaid-nonce', |
|
206 | - 'getpaid-nonce' |
|
207 | - ) |
|
208 | - ), |
|
209 | - esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
210 | - ); |
|
211 | - |
|
212 | - } |
|
213 | - |
|
214 | - $actions['duplicate'] = sprintf( |
|
215 | - '<a href="%1$s">%2$s</a>', |
|
216 | - esc_url( |
|
217 | - wp_nonce_url( |
|
218 | - add_query_arg( |
|
219 | - array( |
|
220 | - 'getpaid-admin-action' => 'duplicate_invoice', |
|
221 | - 'invoice_id' => $post->ID, |
|
222 | - ) |
|
223 | - ), |
|
224 | - 'getpaid-nonce', |
|
225 | - 'getpaid-nonce' |
|
226 | - ) |
|
227 | - ), |
|
228 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
229 | - ); |
|
174 | + $actions = array(); |
|
175 | + $invoice = new WPInv_Invoice( $post ); |
|
176 | + |
|
177 | + $actions['edit'] = sprintf( |
|
178 | + '<a href="%1$s">%2$s</a>', |
|
179 | + esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
180 | + esc_html( __( 'Edit', 'invoicing' ) ) |
|
181 | + ); |
|
182 | + |
|
183 | + if ( ! $invoice->is_draft() ) { |
|
184 | + |
|
185 | + $actions['view'] = sprintf( |
|
186 | + '<a href="%1$s">%2$s</a>', |
|
187 | + esc_url( $invoice->get_view_url() ), |
|
188 | + sprintf( |
|
189 | + // translators: %s is the invoice type |
|
190 | + esc_html__( 'View %s', 'invoicing' ), |
|
191 | + getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
192 | + ) |
|
193 | + ); |
|
194 | + |
|
195 | + $actions['send'] = sprintf( |
|
196 | + '<a href="%1$s">%2$s</a>', |
|
197 | + esc_url( |
|
198 | + wp_nonce_url( |
|
199 | + add_query_arg( |
|
200 | + array( |
|
201 | + 'getpaid-admin-action' => 'send_invoice', |
|
202 | + 'invoice_id' => $invoice->get_id(), |
|
203 | + ) |
|
204 | + ), |
|
205 | + 'getpaid-nonce', |
|
206 | + 'getpaid-nonce' |
|
207 | + ) |
|
208 | + ), |
|
209 | + esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
210 | + ); |
|
211 | + |
|
212 | + } |
|
213 | + |
|
214 | + $actions['duplicate'] = sprintf( |
|
215 | + '<a href="%1$s">%2$s</a>', |
|
216 | + esc_url( |
|
217 | + wp_nonce_url( |
|
218 | + add_query_arg( |
|
219 | + array( |
|
220 | + 'getpaid-admin-action' => 'duplicate_invoice', |
|
221 | + 'invoice_id' => $post->ID, |
|
222 | + ) |
|
223 | + ), |
|
224 | + 'getpaid-nonce', |
|
225 | + 'getpaid-nonce' |
|
226 | + ) |
|
227 | + ), |
|
228 | + esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
229 | + ); |
|
230 | 230 | |
231 | 231 | } |
232 | 232 | |
233 | 233 | return $actions; |
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Returns an array of invoice table columns. |
|
238 | - */ |
|
239 | - public static function invoice_columns( $columns ) { |
|
240 | - |
|
241 | - $columns = array( |
|
242 | - 'cb' => $columns['cb'], |
|
243 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
244 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
245 | - 'invoice_date' => __( 'Created', 'invoicing' ), |
|
246 | - 'payment_date' => __( 'Completed', 'invoicing' ), |
|
247 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
248 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
249 | - 'status' => __( 'Status', 'invoicing' ), |
|
250 | - ); |
|
251 | - |
|
252 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Displays invoice table columns. |
|
257 | - */ |
|
258 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
259 | - |
|
260 | - $invoice = new WPInv_Invoice( $post_id ); |
|
261 | - |
|
262 | - switch ( $column_name ) { |
|
263 | - |
|
264 | - case 'invoice_date': |
|
265 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
266 | - $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
267 | - echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
268 | - break; |
|
269 | - |
|
270 | - case 'payment_date': |
|
271 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
272 | - $date_time = esc_attr( $invoice->get_completed_date() ); |
|
273 | - $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
274 | - echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
275 | - |
|
276 | - if ( $_gateway = $invoice->get_gateway() ) { |
|
277 | - $gateway_label = wpinv_get_gateway_admin_label( $_gateway ); |
|
278 | - |
|
279 | - if ( $transaction_url = $invoice->get_transaction_url() ) { |
|
280 | - $gateway_label = '<a href="' . esc_url( $transaction_url ) . '" target="_blank" title="' . esc_attr__( 'Open transaction link', 'invoicing' ) . '">' . $gateway_label . '</a>'; |
|
281 | - } |
|
282 | - |
|
283 | - $gateway = '<small class="meta bsui"><span class="fs-xs text-muted fst-normal">' . wp_sprintf( _x( 'Via %s', 'Paid via gateway', 'invoicing' ), $gateway_label ) . '</span></small>'; |
|
284 | - } else { |
|
285 | - $gateway = ''; |
|
286 | - } |
|
287 | - |
|
288 | - $gateway = apply_filters( 'getpaid_admin_invoices_list_table_gateway', $gateway, $invoice ); |
|
289 | - |
|
290 | - if ( $gateway ) { |
|
291 | - echo wp_kses_post( $gateway ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
292 | - } |
|
293 | - } else { |
|
294 | - echo '—'; |
|
295 | - } |
|
296 | - |
|
297 | - break; |
|
298 | - |
|
299 | - case 'amount': |
|
300 | - $amount = $invoice->get_total(); |
|
301 | - $formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) ); |
|
302 | - |
|
303 | - if ( $invoice->is_refunded() ) { |
|
304 | - $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
305 | - echo wp_kses_post( "<del>$formated_amount</del> <ins>$refunded_amount</ins>" ); |
|
306 | - } else { |
|
307 | - |
|
308 | - $discount = $invoice->get_total_discount(); |
|
309 | - |
|
310 | - if ( ! empty( $discount ) ) { |
|
311 | - $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
312 | - echo wp_kses_post( "<del>$new_amount</del> <ins>$formated_amount</ins>" ); |
|
313 | - } else { |
|
314 | - echo wp_kses_post( $formated_amount ); |
|
315 | - } |
|
316 | - } |
|
317 | - |
|
318 | - break; |
|
319 | - |
|
320 | - case 'status': |
|
321 | - $status = esc_html( $invoice->get_status() ); |
|
322 | - |
|
323 | - // If it is paid, show the gateway title. |
|
324 | - if ( $invoice->is_paid() ) { |
|
325 | - $gateway = esc_html( $invoice->get_gateway_title() ); |
|
326 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) ); |
|
327 | - |
|
328 | - echo wp_kses_post( "<span class='bsui wpi-help-tip getpaid-invoice-statuss $status' title='$gateway'><span class='fs-base'>" . $invoice->get_status_label_html() . "</span></span>" ); |
|
329 | - } else { |
|
330 | - echo wp_kses_post( "<span class='bsui getpaid-invoice-statuss $status'><span class='fs-base'>" . $invoice->get_status_label_html() . "</span></span>" ); |
|
331 | - } |
|
332 | - |
|
333 | - // If it is not paid, display the overdue and view status. |
|
334 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
335 | - |
|
336 | - // Invoice view status. |
|
337 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
338 | - echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
339 | - } else { |
|
340 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
341 | - } |
|
342 | - |
|
343 | - // Display the overview status. |
|
344 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
345 | - $due_date = $invoice->get_due_date(); |
|
346 | - $fomatted = getpaid_format_date( $due_date ); |
|
347 | - |
|
348 | - if ( ! empty( $fomatted ) ) { |
|
349 | - $date = wp_sprintf( |
|
350 | - // translators: %s is the due date. |
|
351 | - __( 'Due %s', 'invoicing' ), |
|
352 | - $fomatted |
|
353 | - ); |
|
354 | - echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" ); |
|
355 | - } |
|
356 | - } |
|
357 | - } |
|
358 | - |
|
359 | - break; |
|
360 | - |
|
361 | - case 'recurring': |
|
362 | - if ( $invoice->is_recurring() ) { |
|
363 | - echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
364 | - } else { |
|
365 | - echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
366 | - } |
|
367 | - break; |
|
368 | - |
|
369 | - case 'number': |
|
370 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
371 | - $invoice_number = esc_html( $invoice->get_number() ); |
|
372 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
373 | - |
|
374 | - echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" ); |
|
375 | - |
|
376 | - do_action( 'getpaid_admin_table_invoice_number_column', $invoice ); |
|
377 | - break; |
|
378 | - |
|
379 | - case 'customer': |
|
380 | - $customer_name = $invoice->get_user_full_name(); |
|
381 | - |
|
382 | - if ( empty( $customer_name ) ) { |
|
383 | - $customer_name = $invoice->get_email(); |
|
384 | - } |
|
385 | - |
|
386 | - if ( ! empty( $customer_name ) ) { |
|
387 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
388 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
389 | - echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" ); |
|
390 | - } else { |
|
391 | - echo '<div>—</div>'; |
|
392 | - } |
|
393 | - |
|
394 | - break; |
|
395 | - |
|
396 | - } |
|
397 | - |
|
398 | - } |
|
399 | - |
|
400 | - /** |
|
401 | - * Displays invoice bulk actions. |
|
402 | - */ |
|
403 | - public static function invoice_bulk_actions( $actions ) { |
|
404 | - $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
405 | - return $actions; |
|
406 | - } |
|
407 | - |
|
408 | - /** |
|
409 | - * Processes invoice bulk actions. |
|
410 | - */ |
|
411 | - public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
412 | - |
|
413 | - if ( 'resend-invoice' === $action ) { |
|
414 | - foreach ( $post_ids as $post_id ) { |
|
415 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
416 | - } |
|
417 | - } |
|
418 | - |
|
419 | - return $redirect_url; |
|
420 | - |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Returns an array of payment forms table columns. |
|
425 | - */ |
|
426 | - public static function payment_form_columns( $columns ) { |
|
427 | - |
|
428 | - $columns = array( |
|
429 | - 'cb' => $columns['cb'], |
|
430 | - 'title' => __( 'Name', 'invoicing' ), |
|
431 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
432 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
433 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
434 | - 'items' => __( 'Items', 'invoicing' ), |
|
435 | - 'date' => __( 'Date', 'invoicing' ), |
|
436 | - ); |
|
437 | - |
|
438 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
439 | - |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * Displays payment form table columns. |
|
444 | - */ |
|
445 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
446 | - |
|
447 | - // Retrieve the payment form. |
|
448 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
449 | - |
|
450 | - switch ( $column_name ) { |
|
451 | - |
|
452 | - case 'earnings': |
|
453 | - echo wp_kses_post( wpinv_price( $form->get_earned() ) ); |
|
454 | - break; |
|
455 | - |
|
456 | - case 'refunds': |
|
457 | - echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
458 | - break; |
|
459 | - |
|
460 | - case 'refunds': |
|
461 | - echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
462 | - break; |
|
463 | - |
|
464 | - case 'shortcode': |
|
465 | - if ( $form->is_default() ) { |
|
466 | - echo '—'; |
|
467 | - } else { |
|
468 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
469 | - } |
|
470 | - |
|
471 | - break; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Returns an array of invoice table columns. |
|
238 | + */ |
|
239 | + public static function invoice_columns( $columns ) { |
|
240 | + |
|
241 | + $columns = array( |
|
242 | + 'cb' => $columns['cb'], |
|
243 | + 'number' => __( 'Invoice', 'invoicing' ), |
|
244 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
245 | + 'invoice_date' => __( 'Created', 'invoicing' ), |
|
246 | + 'payment_date' => __( 'Completed', 'invoicing' ), |
|
247 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
248 | + 'recurring' => __( 'Recurring', 'invoicing' ), |
|
249 | + 'status' => __( 'Status', 'invoicing' ), |
|
250 | + ); |
|
251 | + |
|
252 | + return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Displays invoice table columns. |
|
257 | + */ |
|
258 | + public static function display_invoice_columns( $column_name, $post_id ) { |
|
259 | + |
|
260 | + $invoice = new WPInv_Invoice( $post_id ); |
|
261 | + |
|
262 | + switch ( $column_name ) { |
|
263 | + |
|
264 | + case 'invoice_date': |
|
265 | + $date_time = esc_attr( $invoice->get_created_date() ); |
|
266 | + $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
267 | + echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
268 | + break; |
|
269 | + |
|
270 | + case 'payment_date': |
|
271 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
272 | + $date_time = esc_attr( $invoice->get_completed_date() ); |
|
273 | + $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
274 | + echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
275 | + |
|
276 | + if ( $_gateway = $invoice->get_gateway() ) { |
|
277 | + $gateway_label = wpinv_get_gateway_admin_label( $_gateway ); |
|
278 | + |
|
279 | + if ( $transaction_url = $invoice->get_transaction_url() ) { |
|
280 | + $gateway_label = '<a href="' . esc_url( $transaction_url ) . '" target="_blank" title="' . esc_attr__( 'Open transaction link', 'invoicing' ) . '">' . $gateway_label . '</a>'; |
|
281 | + } |
|
282 | + |
|
283 | + $gateway = '<small class="meta bsui"><span class="fs-xs text-muted fst-normal">' . wp_sprintf( _x( 'Via %s', 'Paid via gateway', 'invoicing' ), $gateway_label ) . '</span></small>'; |
|
284 | + } else { |
|
285 | + $gateway = ''; |
|
286 | + } |
|
287 | + |
|
288 | + $gateway = apply_filters( 'getpaid_admin_invoices_list_table_gateway', $gateway, $invoice ); |
|
289 | + |
|
290 | + if ( $gateway ) { |
|
291 | + echo wp_kses_post( $gateway ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
292 | + } |
|
293 | + } else { |
|
294 | + echo '—'; |
|
295 | + } |
|
296 | + |
|
297 | + break; |
|
298 | + |
|
299 | + case 'amount': |
|
300 | + $amount = $invoice->get_total(); |
|
301 | + $formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) ); |
|
302 | + |
|
303 | + if ( $invoice->is_refunded() ) { |
|
304 | + $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
305 | + echo wp_kses_post( "<del>$formated_amount</del> <ins>$refunded_amount</ins>" ); |
|
306 | + } else { |
|
307 | + |
|
308 | + $discount = $invoice->get_total_discount(); |
|
309 | + |
|
310 | + if ( ! empty( $discount ) ) { |
|
311 | + $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
312 | + echo wp_kses_post( "<del>$new_amount</del> <ins>$formated_amount</ins>" ); |
|
313 | + } else { |
|
314 | + echo wp_kses_post( $formated_amount ); |
|
315 | + } |
|
316 | + } |
|
317 | + |
|
318 | + break; |
|
319 | + |
|
320 | + case 'status': |
|
321 | + $status = esc_html( $invoice->get_status() ); |
|
322 | + |
|
323 | + // If it is paid, show the gateway title. |
|
324 | + if ( $invoice->is_paid() ) { |
|
325 | + $gateway = esc_html( $invoice->get_gateway_title() ); |
|
326 | + $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) ); |
|
327 | + |
|
328 | + echo wp_kses_post( "<span class='bsui wpi-help-tip getpaid-invoice-statuss $status' title='$gateway'><span class='fs-base'>" . $invoice->get_status_label_html() . "</span></span>" ); |
|
329 | + } else { |
|
330 | + echo wp_kses_post( "<span class='bsui getpaid-invoice-statuss $status'><span class='fs-base'>" . $invoice->get_status_label_html() . "</span></span>" ); |
|
331 | + } |
|
332 | + |
|
333 | + // If it is not paid, display the overdue and view status. |
|
334 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
335 | + |
|
336 | + // Invoice view status. |
|
337 | + if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
338 | + echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
339 | + } else { |
|
340 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
341 | + } |
|
342 | + |
|
343 | + // Display the overview status. |
|
344 | + if ( wpinv_get_option( 'overdue_active' ) ) { |
|
345 | + $due_date = $invoice->get_due_date(); |
|
346 | + $fomatted = getpaid_format_date( $due_date ); |
|
347 | + |
|
348 | + if ( ! empty( $fomatted ) ) { |
|
349 | + $date = wp_sprintf( |
|
350 | + // translators: %s is the due date. |
|
351 | + __( 'Due %s', 'invoicing' ), |
|
352 | + $fomatted |
|
353 | + ); |
|
354 | + echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" ); |
|
355 | + } |
|
356 | + } |
|
357 | + } |
|
358 | + |
|
359 | + break; |
|
360 | + |
|
361 | + case 'recurring': |
|
362 | + if ( $invoice->is_recurring() ) { |
|
363 | + echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
364 | + } else { |
|
365 | + echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
366 | + } |
|
367 | + break; |
|
368 | + |
|
369 | + case 'number': |
|
370 | + $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
371 | + $invoice_number = esc_html( $invoice->get_number() ); |
|
372 | + $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
373 | + |
|
374 | + echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" ); |
|
375 | + |
|
376 | + do_action( 'getpaid_admin_table_invoice_number_column', $invoice ); |
|
377 | + break; |
|
378 | + |
|
379 | + case 'customer': |
|
380 | + $customer_name = $invoice->get_user_full_name(); |
|
381 | + |
|
382 | + if ( empty( $customer_name ) ) { |
|
383 | + $customer_name = $invoice->get_email(); |
|
384 | + } |
|
385 | + |
|
386 | + if ( ! empty( $customer_name ) ) { |
|
387 | + $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
388 | + $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
389 | + echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" ); |
|
390 | + } else { |
|
391 | + echo '<div>—</div>'; |
|
392 | + } |
|
393 | + |
|
394 | + break; |
|
472 | 395 | |
473 | - case 'items': |
|
474 | - $items = $form->get_items(); |
|
475 | - |
|
476 | - if ( $form->is_default() || empty( $items ) ) { |
|
477 | - echo '—'; |
|
478 | - return; |
|
479 | - } |
|
480 | - |
|
481 | - $_items = array(); |
|
482 | - |
|
483 | - foreach ( $items as $item ) { |
|
484 | - $url = $item->get_edit_url(); |
|
485 | - |
|
486 | - if ( empty( $url ) ) { |
|
487 | - $_items[] = esc_html( $item->get_name() ); |
|
488 | - } else { |
|
489 | - $_items[] = sprintf( |
|
490 | - '<a href="%s">%s</a>', |
|
491 | - esc_url( $url ), |
|
492 | - esc_html( $item->get_name() ) |
|
493 | - ); |
|
494 | - } |
|
396 | + } |
|
397 | + |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * Displays invoice bulk actions. |
|
402 | + */ |
|
403 | + public static function invoice_bulk_actions( $actions ) { |
|
404 | + $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
405 | + return $actions; |
|
406 | + } |
|
407 | + |
|
408 | + /** |
|
409 | + * Processes invoice bulk actions. |
|
410 | + */ |
|
411 | + public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
412 | + |
|
413 | + if ( 'resend-invoice' === $action ) { |
|
414 | + foreach ( $post_ids as $post_id ) { |
|
415 | + getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
416 | + } |
|
417 | + } |
|
418 | + |
|
419 | + return $redirect_url; |
|
420 | + |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Returns an array of payment forms table columns. |
|
425 | + */ |
|
426 | + public static function payment_form_columns( $columns ) { |
|
427 | + |
|
428 | + $columns = array( |
|
429 | + 'cb' => $columns['cb'], |
|
430 | + 'title' => __( 'Name', 'invoicing' ), |
|
431 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
432 | + 'earnings' => __( 'Revenue', 'invoicing' ), |
|
433 | + 'refunds' => __( 'Refunded', 'invoicing' ), |
|
434 | + 'items' => __( 'Items', 'invoicing' ), |
|
435 | + 'date' => __( 'Date', 'invoicing' ), |
|
436 | + ); |
|
437 | + |
|
438 | + return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
439 | + |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * Displays payment form table columns. |
|
444 | + */ |
|
445 | + public static function display_payment_form_columns( $column_name, $post_id ) { |
|
446 | + |
|
447 | + // Retrieve the payment form. |
|
448 | + $form = new GetPaid_Payment_Form( $post_id ); |
|
449 | + |
|
450 | + switch ( $column_name ) { |
|
451 | + |
|
452 | + case 'earnings': |
|
453 | + echo wp_kses_post( wpinv_price( $form->get_earned() ) ); |
|
454 | + break; |
|
455 | + |
|
456 | + case 'refunds': |
|
457 | + echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
458 | + break; |
|
459 | + |
|
460 | + case 'refunds': |
|
461 | + echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
462 | + break; |
|
463 | + |
|
464 | + case 'shortcode': |
|
465 | + if ( $form->is_default() ) { |
|
466 | + echo '—'; |
|
467 | + } else { |
|
468 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
469 | + } |
|
470 | + |
|
471 | + break; |
|
472 | + |
|
473 | + case 'items': |
|
474 | + $items = $form->get_items(); |
|
475 | + |
|
476 | + if ( $form->is_default() || empty( $items ) ) { |
|
477 | + echo '—'; |
|
478 | + return; |
|
479 | + } |
|
480 | + |
|
481 | + $_items = array(); |
|
482 | + |
|
483 | + foreach ( $items as $item ) { |
|
484 | + $url = $item->get_edit_url(); |
|
485 | + |
|
486 | + if ( empty( $url ) ) { |
|
487 | + $_items[] = esc_html( $item->get_name() ); |
|
488 | + } else { |
|
489 | + $_items[] = sprintf( |
|
490 | + '<a href="%s">%s</a>', |
|
491 | + esc_url( $url ), |
|
492 | + esc_html( $item->get_name() ) |
|
493 | + ); |
|
494 | + } |
|
495 | 495 | } |
496 | 496 | |
497 | - echo wp_kses_post( implode( '<br>', $_items ) ); |
|
497 | + echo wp_kses_post( implode( '<br>', $_items ) ); |
|
498 | + |
|
499 | + break; |
|
500 | + |
|
501 | + } |
|
502 | + |
|
503 | + } |
|
504 | + |
|
505 | + /** |
|
506 | + * Filters post states. |
|
507 | + */ |
|
508 | + public static function filter_payment_form_state( $post_states, $post ) { |
|
509 | + |
|
510 | + if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) { |
|
511 | + $post_states['default_form'] = __( 'Default Payment Form', 'invoicing' ); |
|
512 | + } |
|
513 | + |
|
514 | + return $post_states; |
|
515 | + |
|
516 | + } |
|
517 | + |
|
518 | + /** |
|
519 | + * Returns an array of coupon table columns. |
|
520 | + */ |
|
521 | + public static function discount_columns( $columns ) { |
|
522 | + |
|
523 | + $columns = array( |
|
524 | + 'cb' => $columns['cb'], |
|
525 | + 'title' => __( 'Name', 'invoicing' ), |
|
526 | + 'code' => __( 'Code', 'invoicing' ), |
|
527 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
528 | + 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
529 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
530 | + 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
531 | + ); |
|
532 | + |
|
533 | + return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
534 | + } |
|
498 | 535 | |
499 | - break; |
|
536 | + /** |
|
537 | + * Filters post states. |
|
538 | + */ |
|
539 | + public static function filter_discount_state( $post_states, $post ) { |
|
500 | 540 | |
501 | - } |
|
541 | + if ( 'wpi_discount' === $post->post_type ) { |
|
502 | 542 | |
503 | - } |
|
543 | + $discount = new WPInv_Discount( $post ); |
|
504 | 544 | |
505 | - /** |
|
506 | - * Filters post states. |
|
507 | - */ |
|
508 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
545 | + $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
509 | 546 | |
510 | - if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) { |
|
511 | - $post_states['default_form'] = __( 'Default Payment Form', 'invoicing' ); |
|
512 | - } |
|
547 | + if ( 'publish' !== $status ) { |
|
548 | + return array( |
|
549 | + 'discount_status' => wpinv_discount_status( $status ), |
|
550 | + ); |
|
551 | + } |
|
552 | + |
|
553 | + return array(); |
|
554 | + |
|
555 | + } |
|
556 | + |
|
557 | + return $post_states; |
|
513 | 558 | |
514 | - return $post_states; |
|
559 | + } |
|
515 | 560 | |
516 | - } |
|
561 | + /** |
|
562 | + * Returns an array of items table columns. |
|
563 | + */ |
|
564 | + public static function item_columns( $columns ) { |
|
565 | + |
|
566 | + $columns = array( |
|
567 | + 'cb' => $columns['cb'], |
|
568 | + 'title' => __( 'Name', 'invoicing' ), |
|
569 | + 'price' => __( 'Price', 'invoicing' ), |
|
570 | + 'vat_rule' => __( 'Tax Rule', 'invoicing' ), |
|
571 | + 'vat_class' => __( 'Tax Class', 'invoicing' ), |
|
572 | + 'type' => __( 'Type', 'invoicing' ), |
|
573 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
574 | + ); |
|
575 | + |
|
576 | + if ( ! wpinv_use_taxes() ) { |
|
577 | + unset( $columns['vat_rule'] ); |
|
578 | + unset( $columns['vat_class'] ); |
|
579 | + } |
|
517 | 580 | |
518 | - /** |
|
519 | - * Returns an array of coupon table columns. |
|
520 | - */ |
|
521 | - public static function discount_columns( $columns ) { |
|
581 | + return apply_filters( 'wpi_item_table_columns', $columns ); |
|
582 | + } |
|
522 | 583 | |
523 | - $columns = array( |
|
524 | - 'cb' => $columns['cb'], |
|
525 | - 'title' => __( 'Name', 'invoicing' ), |
|
526 | - 'code' => __( 'Code', 'invoicing' ), |
|
527 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
528 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
529 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
530 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
531 | - ); |
|
584 | + /** |
|
585 | + * Returns an array of sortable items table columns. |
|
586 | + */ |
|
587 | + public static function sortable_item_columns( $columns ) { |
|
588 | + |
|
589 | + return array_merge( |
|
590 | + $columns, |
|
591 | + array( |
|
592 | + 'price' => 'price', |
|
593 | + 'vat_rule' => 'vat_rule', |
|
594 | + 'vat_class' => 'vat_class', |
|
595 | + 'type' => 'type', |
|
596 | + ) |
|
597 | + ); |
|
532 | 598 | |
533 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
534 | - } |
|
599 | + } |
|
535 | 600 | |
536 | - /** |
|
537 | - * Filters post states. |
|
538 | - */ |
|
539 | - public static function filter_discount_state( $post_states, $post ) { |
|
601 | + /** |
|
602 | + * Displays items table columns. |
|
603 | + */ |
|
604 | + public static function display_item_columns( $column_name, $post_id ) { |
|
540 | 605 | |
541 | - if ( 'wpi_discount' === $post->post_type ) { |
|
606 | + $item = new WPInv_Item( $post_id ); |
|
542 | 607 | |
543 | - $discount = new WPInv_Discount( $post ); |
|
608 | + switch ( $column_name ) { |
|
544 | 609 | |
545 | - $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
610 | + case 'price': |
|
611 | + if ( ! $item->is_recurring() ) { |
|
612 | + echo wp_kses_post( $item->get_the_price() ); |
|
613 | + break; |
|
614 | + } |
|
546 | 615 | |
547 | - if ( 'publish' !== $status ) { |
|
548 | - return array( |
|
549 | - 'discount_status' => wpinv_discount_status( $status ), |
|
550 | - ); |
|
551 | - } |
|
616 | + $price = wp_sprintf( |
|
617 | + __( '%1$s / %2$s', 'invoicing' ), |
|
618 | + $item->get_the_price(), |
|
619 | + getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
620 | + ); |
|
552 | 621 | |
553 | - return array(); |
|
622 | + if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
623 | + echo wp_kses_post( $price ); |
|
624 | + break; |
|
625 | + } |
|
554 | 626 | |
555 | - } |
|
627 | + echo wp_kses_post( $item->get_the_initial_price() ); |
|
556 | 628 | |
557 | - return $post_states; |
|
629 | + echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>'; |
|
630 | + break; |
|
558 | 631 | |
559 | - } |
|
632 | + case 'vat_rule': |
|
633 | + echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) ); |
|
634 | + break; |
|
560 | 635 | |
561 | - /** |
|
562 | - * Returns an array of items table columns. |
|
563 | - */ |
|
564 | - public static function item_columns( $columns ) { |
|
636 | + case 'vat_class': |
|
637 | + echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) ); |
|
638 | + break; |
|
565 | 639 | |
566 | - $columns = array( |
|
567 | - 'cb' => $columns['cb'], |
|
568 | - 'title' => __( 'Name', 'invoicing' ), |
|
569 | - 'price' => __( 'Price', 'invoicing' ), |
|
570 | - 'vat_rule' => __( 'Tax Rule', 'invoicing' ), |
|
571 | - 'vat_class' => __( 'Tax Class', 'invoicing' ), |
|
572 | - 'type' => __( 'Type', 'invoicing' ), |
|
573 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
574 | - ); |
|
640 | + case 'shortcode': |
|
641 | + if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) { |
|
642 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
643 | + } else { |
|
644 | + echo '—'; |
|
645 | + } |
|
575 | 646 | |
576 | - if ( ! wpinv_use_taxes() ) { |
|
577 | - unset( $columns['vat_rule'] ); |
|
578 | - unset( $columns['vat_class'] ); |
|
579 | - } |
|
647 | + break; |
|
580 | 648 | |
581 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
582 | - } |
|
649 | + case 'type': |
|
650 | + echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' ); |
|
651 | + break; |
|
583 | 652 | |
584 | - /** |
|
585 | - * Returns an array of sortable items table columns. |
|
586 | - */ |
|
587 | - public static function sortable_item_columns( $columns ) { |
|
588 | - |
|
589 | - return array_merge( |
|
590 | - $columns, |
|
591 | - array( |
|
592 | - 'price' => 'price', |
|
593 | - 'vat_rule' => 'vat_rule', |
|
594 | - 'vat_class' => 'vat_class', |
|
595 | - 'type' => 'type', |
|
596 | - ) |
|
597 | - ); |
|
598 | - |
|
599 | - } |
|
600 | - |
|
601 | - /** |
|
602 | - * Displays items table columns. |
|
603 | - */ |
|
604 | - public static function display_item_columns( $column_name, $post_id ) { |
|
605 | - |
|
606 | - $item = new WPInv_Item( $post_id ); |
|
607 | - |
|
608 | - switch ( $column_name ) { |
|
609 | - |
|
610 | - case 'price': |
|
611 | - if ( ! $item->is_recurring() ) { |
|
612 | - echo wp_kses_post( $item->get_the_price() ); |
|
613 | - break; |
|
614 | - } |
|
615 | - |
|
616 | - $price = wp_sprintf( |
|
617 | - __( '%1$s / %2$s', 'invoicing' ), |
|
618 | - $item->get_the_price(), |
|
619 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
620 | - ); |
|
621 | - |
|
622 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
623 | - echo wp_kses_post( $price ); |
|
624 | - break; |
|
625 | - } |
|
626 | - |
|
627 | - echo wp_kses_post( $item->get_the_initial_price() ); |
|
628 | - |
|
629 | - echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>'; |
|
630 | - break; |
|
631 | - |
|
632 | - case 'vat_rule': |
|
633 | - echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) ); |
|
634 | - break; |
|
635 | - |
|
636 | - case 'vat_class': |
|
637 | - echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) ); |
|
638 | - break; |
|
639 | - |
|
640 | - case 'shortcode': |
|
641 | - if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) { |
|
642 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
643 | - } else { |
|
644 | - echo '—'; |
|
645 | - } |
|
646 | - |
|
647 | - break; |
|
648 | - |
|
649 | - case 'type': |
|
650 | - echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' ); |
|
651 | - break; |
|
652 | - |
|
653 | - } |
|
654 | - |
|
655 | - } |
|
656 | - |
|
657 | - /** |
|
658 | - * Lets users filter items using taxes. |
|
659 | - */ |
|
660 | - public static function add_item_filters( $post_type ) { |
|
661 | - |
|
662 | - // Abort if we're not dealing with items. |
|
663 | - if ( 'wpi_item' !== $post_type ) { |
|
664 | - return; |
|
665 | - } |
|
666 | - |
|
667 | - // Filter by vat rules. |
|
668 | - if ( wpinv_use_taxes() ) { |
|
669 | - |
|
670 | - // Sanitize selected vat rule. |
|
671 | - $vat_rule = ''; |
|
672 | - $vat_rules = getpaid_get_tax_rules(); |
|
673 | - if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
674 | - $vat_rule = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
675 | - } |
|
676 | - |
|
677 | - // Filter by VAT rule. |
|
678 | - wpinv_html_select( |
|
679 | - array( |
|
680 | - 'options' => array_merge( |
|
681 | - array( |
|
682 | - '' => __( 'All Tax Rules', 'invoicing' ), |
|
683 | - ), |
|
684 | - $vat_rules |
|
685 | - ), |
|
686 | - 'name' => 'vat_rule', |
|
687 | - 'id' => 'vat_rule', |
|
688 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '', |
|
689 | - 'show_option_all' => false, |
|
690 | - 'show_option_none' => false, |
|
691 | - ) |
|
692 | - ); |
|
693 | - |
|
694 | - // Filter by VAT class. |
|
695 | - |
|
696 | - // Sanitize selected vat rule. |
|
697 | - $vat_class = ''; |
|
698 | - $vat_classes = getpaid_get_tax_classes(); |
|
699 | - if ( isset( $_GET['vat_class'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
700 | - $vat_class = sanitize_text_field( $_GET['vat_class'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
701 | - } |
|
702 | - |
|
703 | - wpinv_html_select( |
|
704 | - array( |
|
705 | - 'options' => array_merge( |
|
706 | - array( |
|
707 | - '' => __( 'All Tax Classes', 'invoicing' ), |
|
708 | - ), |
|
709 | - $vat_classes |
|
710 | - ), |
|
711 | - 'name' => 'vat_class', |
|
712 | - 'id' => 'vat_class', |
|
713 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '', |
|
714 | - 'show_option_all' => false, |
|
715 | - 'show_option_none' => false, |
|
716 | - ) |
|
717 | - ); |
|
718 | - |
|
719 | - } |
|
720 | - |
|
721 | - // Filter by item type. |
|
722 | - $type = ''; |
|
723 | - if ( isset( $_GET['type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
724 | - $type = sanitize_text_field( $_GET['type'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
725 | - } |
|
726 | - |
|
727 | - wpinv_html_select( |
|
728 | - array( |
|
729 | - 'options' => array_merge( |
|
730 | - array( |
|
731 | - '' => __( 'All item types', 'invoicing' ), |
|
732 | - ), |
|
733 | - wpinv_get_item_types() |
|
734 | - ), |
|
735 | - 'name' => 'type', |
|
736 | - 'id' => 'type', |
|
737 | - 'selected' => in_array( $type, wpinv_item_types(), true ) ? $type : '', |
|
738 | - 'show_option_all' => false, |
|
739 | - 'show_option_none' => false, |
|
740 | - ) |
|
741 | - ); |
|
742 | - |
|
743 | - } |
|
744 | - |
|
745 | - /** |
|
746 | - * Filters the item query. |
|
747 | - */ |
|
748 | - public static function filter_item_query( $query ) { |
|
749 | - |
|
750 | - // modify the query only if it admin and main query. |
|
751 | - if ( ! ( is_admin() && $query->is_main_query() ) ) { |
|
752 | - return $query; |
|
753 | - } |
|
754 | - |
|
755 | - // we want to modify the query for our items. |
|
756 | - if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) { |
|
757 | - return $query; |
|
758 | - } |
|
759 | - |
|
760 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
761 | - $query->query_vars['meta_query'] = array(); |
|
762 | - } |
|
763 | - |
|
764 | - // Filter vat rule type |
|
653 | + } |
|
654 | + |
|
655 | + } |
|
656 | + |
|
657 | + /** |
|
658 | + * Lets users filter items using taxes. |
|
659 | + */ |
|
660 | + public static function add_item_filters( $post_type ) { |
|
661 | + |
|
662 | + // Abort if we're not dealing with items. |
|
663 | + if ( 'wpi_item' !== $post_type ) { |
|
664 | + return; |
|
665 | + } |
|
666 | + |
|
667 | + // Filter by vat rules. |
|
668 | + if ( wpinv_use_taxes() ) { |
|
669 | + |
|
670 | + // Sanitize selected vat rule. |
|
671 | + $vat_rule = ''; |
|
672 | + $vat_rules = getpaid_get_tax_rules(); |
|
673 | + if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
674 | + $vat_rule = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
675 | + } |
|
676 | + |
|
677 | + // Filter by VAT rule. |
|
678 | + wpinv_html_select( |
|
679 | + array( |
|
680 | + 'options' => array_merge( |
|
681 | + array( |
|
682 | + '' => __( 'All Tax Rules', 'invoicing' ), |
|
683 | + ), |
|
684 | + $vat_rules |
|
685 | + ), |
|
686 | + 'name' => 'vat_rule', |
|
687 | + 'id' => 'vat_rule', |
|
688 | + 'selected' => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '', |
|
689 | + 'show_option_all' => false, |
|
690 | + 'show_option_none' => false, |
|
691 | + ) |
|
692 | + ); |
|
693 | + |
|
694 | + // Filter by VAT class. |
|
695 | + |
|
696 | + // Sanitize selected vat rule. |
|
697 | + $vat_class = ''; |
|
698 | + $vat_classes = getpaid_get_tax_classes(); |
|
699 | + if ( isset( $_GET['vat_class'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
700 | + $vat_class = sanitize_text_field( $_GET['vat_class'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
701 | + } |
|
702 | + |
|
703 | + wpinv_html_select( |
|
704 | + array( |
|
705 | + 'options' => array_merge( |
|
706 | + array( |
|
707 | + '' => __( 'All Tax Classes', 'invoicing' ), |
|
708 | + ), |
|
709 | + $vat_classes |
|
710 | + ), |
|
711 | + 'name' => 'vat_class', |
|
712 | + 'id' => 'vat_class', |
|
713 | + 'selected' => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '', |
|
714 | + 'show_option_all' => false, |
|
715 | + 'show_option_none' => false, |
|
716 | + ) |
|
717 | + ); |
|
718 | + |
|
719 | + } |
|
720 | + |
|
721 | + // Filter by item type. |
|
722 | + $type = ''; |
|
723 | + if ( isset( $_GET['type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
724 | + $type = sanitize_text_field( $_GET['type'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
725 | + } |
|
726 | + |
|
727 | + wpinv_html_select( |
|
728 | + array( |
|
729 | + 'options' => array_merge( |
|
730 | + array( |
|
731 | + '' => __( 'All item types', 'invoicing' ), |
|
732 | + ), |
|
733 | + wpinv_get_item_types() |
|
734 | + ), |
|
735 | + 'name' => 'type', |
|
736 | + 'id' => 'type', |
|
737 | + 'selected' => in_array( $type, wpinv_item_types(), true ) ? $type : '', |
|
738 | + 'show_option_all' => false, |
|
739 | + 'show_option_none' => false, |
|
740 | + ) |
|
741 | + ); |
|
742 | + |
|
743 | + } |
|
744 | + |
|
745 | + /** |
|
746 | + * Filters the item query. |
|
747 | + */ |
|
748 | + public static function filter_item_query( $query ) { |
|
749 | + |
|
750 | + // modify the query only if it admin and main query. |
|
751 | + if ( ! ( is_admin() && $query->is_main_query() ) ) { |
|
752 | + return $query; |
|
753 | + } |
|
754 | + |
|
755 | + // we want to modify the query for our items. |
|
756 | + if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) { |
|
757 | + return $query; |
|
758 | + } |
|
759 | + |
|
760 | + if ( empty( $query->query_vars['meta_query'] ) ) { |
|
761 | + $query->query_vars['meta_query'] = array(); |
|
762 | + } |
|
763 | + |
|
764 | + // Filter vat rule type |
|
765 | 765 | if ( ! empty( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
766 | 766 | $query->query_vars['meta_query'][] = array( |
767 | 767 | 'key' => '_wpinv_vat_rule', |
@@ -786,101 +786,101 @@ discard block |
||
786 | 786 | 'value' => sanitize_text_field( $_GET['type'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
787 | 787 | 'compare' => '=', |
788 | 788 | ); |
789 | - } |
|
790 | - |
|
791 | - $query->query_vars['meta_query'][] = array( |
|
792 | - 'key' => '_wpinv_one_time', |
|
793 | - 'compare' => 'NOT EXISTS', |
|
794 | - ); |
|
795 | - } |
|
796 | - |
|
797 | - /** |
|
798 | - * Reorders items. |
|
799 | - */ |
|
800 | - public static function reorder_items( $vars ) { |
|
801 | - global $typenow; |
|
802 | - |
|
803 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
804 | - return $vars; |
|
805 | - } |
|
806 | - |
|
807 | - // By item type. |
|
808 | - if ( 'type' === $vars['orderby'] ) { |
|
809 | - return array_merge( |
|
810 | - $vars, |
|
811 | - array( |
|
812 | - 'meta_key' => '_wpinv_type', |
|
813 | - 'orderby' => 'meta_value', |
|
814 | - ) |
|
815 | - ); |
|
816 | - } |
|
817 | - |
|
818 | - // By vat class. |
|
819 | - if ( 'vat_class' === $vars['orderby'] ) { |
|
820 | - return array_merge( |
|
821 | - $vars, |
|
822 | - array( |
|
823 | - 'meta_key' => '_wpinv_vat_class', |
|
824 | - 'orderby' => 'meta_value', |
|
825 | - ) |
|
826 | - ); |
|
827 | - } |
|
828 | - |
|
829 | - // By vat rule. |
|
830 | - if ( 'vat_rule' === $vars['orderby'] ) { |
|
831 | - return array_merge( |
|
832 | - $vars, |
|
833 | - array( |
|
834 | - 'meta_key' => '_wpinv_vat_rule', |
|
835 | - 'orderby' => 'meta_value', |
|
836 | - ) |
|
837 | - ); |
|
838 | - } |
|
839 | - |
|
840 | - // By price. |
|
841 | - if ( 'price' === $vars['orderby'] ) { |
|
842 | - return array_merge( |
|
843 | - $vars, |
|
844 | - array( |
|
845 | - 'meta_key' => '_wpinv_price', |
|
846 | - 'orderby' => 'meta_value_num', |
|
847 | - ) |
|
848 | - ); |
|
849 | - } |
|
850 | - |
|
851 | - return $vars; |
|
852 | - |
|
853 | - } |
|
854 | - |
|
855 | - /** |
|
856 | - * Fired when deleting a post. |
|
857 | - */ |
|
858 | - public static function delete_post( $post_id ) { |
|
859 | - |
|
860 | - switch ( get_post_type( $post_id ) ) { |
|
861 | - |
|
862 | - case 'wpi_item': |
|
863 | - do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) ); |
|
864 | - break; |
|
865 | - |
|
866 | - case 'wpi_payment_form': |
|
867 | - do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) ); |
|
868 | - break; |
|
869 | - |
|
870 | - case 'wpi_discount': |
|
871 | - do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) ); |
|
872 | - break; |
|
873 | - |
|
874 | - case 'wpi_invoice': |
|
875 | - $invoice = new WPInv_Invoice( $post_id ); |
|
876 | - do_action( 'getpaid_before_delete_invoice', $invoice ); |
|
877 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
878 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
879 | - break; |
|
880 | - } |
|
881 | - } |
|
882 | - |
|
883 | - /** |
|
789 | + } |
|
790 | + |
|
791 | + $query->query_vars['meta_query'][] = array( |
|
792 | + 'key' => '_wpinv_one_time', |
|
793 | + 'compare' => 'NOT EXISTS', |
|
794 | + ); |
|
795 | + } |
|
796 | + |
|
797 | + /** |
|
798 | + * Reorders items. |
|
799 | + */ |
|
800 | + public static function reorder_items( $vars ) { |
|
801 | + global $typenow; |
|
802 | + |
|
803 | + if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
804 | + return $vars; |
|
805 | + } |
|
806 | + |
|
807 | + // By item type. |
|
808 | + if ( 'type' === $vars['orderby'] ) { |
|
809 | + return array_merge( |
|
810 | + $vars, |
|
811 | + array( |
|
812 | + 'meta_key' => '_wpinv_type', |
|
813 | + 'orderby' => 'meta_value', |
|
814 | + ) |
|
815 | + ); |
|
816 | + } |
|
817 | + |
|
818 | + // By vat class. |
|
819 | + if ( 'vat_class' === $vars['orderby'] ) { |
|
820 | + return array_merge( |
|
821 | + $vars, |
|
822 | + array( |
|
823 | + 'meta_key' => '_wpinv_vat_class', |
|
824 | + 'orderby' => 'meta_value', |
|
825 | + ) |
|
826 | + ); |
|
827 | + } |
|
828 | + |
|
829 | + // By vat rule. |
|
830 | + if ( 'vat_rule' === $vars['orderby'] ) { |
|
831 | + return array_merge( |
|
832 | + $vars, |
|
833 | + array( |
|
834 | + 'meta_key' => '_wpinv_vat_rule', |
|
835 | + 'orderby' => 'meta_value', |
|
836 | + ) |
|
837 | + ); |
|
838 | + } |
|
839 | + |
|
840 | + // By price. |
|
841 | + if ( 'price' === $vars['orderby'] ) { |
|
842 | + return array_merge( |
|
843 | + $vars, |
|
844 | + array( |
|
845 | + 'meta_key' => '_wpinv_price', |
|
846 | + 'orderby' => 'meta_value_num', |
|
847 | + ) |
|
848 | + ); |
|
849 | + } |
|
850 | + |
|
851 | + return $vars; |
|
852 | + |
|
853 | + } |
|
854 | + |
|
855 | + /** |
|
856 | + * Fired when deleting a post. |
|
857 | + */ |
|
858 | + public static function delete_post( $post_id ) { |
|
859 | + |
|
860 | + switch ( get_post_type( $post_id ) ) { |
|
861 | + |
|
862 | + case 'wpi_item': |
|
863 | + do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) ); |
|
864 | + break; |
|
865 | + |
|
866 | + case 'wpi_payment_form': |
|
867 | + do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) ); |
|
868 | + break; |
|
869 | + |
|
870 | + case 'wpi_discount': |
|
871 | + do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) ); |
|
872 | + break; |
|
873 | + |
|
874 | + case 'wpi_invoice': |
|
875 | + $invoice = new WPInv_Invoice( $post_id ); |
|
876 | + do_action( 'getpaid_before_delete_invoice', $invoice ); |
|
877 | + $invoice->get_data_store()->delete_items( $invoice ); |
|
878 | + $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
879 | + break; |
|
880 | + } |
|
881 | + } |
|
882 | + |
|
883 | + /** |
|
884 | 884 | * Add a post display state for special GetPaid pages in the page list table. |
885 | 885 | * |
886 | 886 | * @param array $post_states An array of post display states. |
@@ -894,21 +894,21 @@ discard block |
||
894 | 894 | $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' ); |
895 | 895 | } |
896 | 896 | |
897 | - foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
897 | + foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
898 | 898 | |
899 | - if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
900 | - $post_states[ "getpaid_{$post_type}_history_page" ] = sprintf( |
|
901 | - __( 'GetPaid %s History Page', 'invoicing' ), |
|
902 | - $label |
|
903 | - ); |
|
904 | - } |
|
899 | + if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
900 | + $post_states[ "getpaid_{$post_type}_history_page" ] = sprintf( |
|
901 | + __( 'GetPaid %s History Page', 'invoicing' ), |
|
902 | + $label |
|
903 | + ); |
|
904 | + } |
|
905 | 905 | } |
906 | 906 | |
907 | - if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
907 | + if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
908 | 908 | $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' ); |
909 | 909 | } |
910 | 910 | |
911 | - if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
911 | + if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
912 | 912 | $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' ); |
913 | 913 | } |
914 | 914 |
@@ -14,620 +14,620 @@ |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var array An array of payment gateways. |
|
40 | - */ |
|
41 | - public $gateways; |
|
42 | - |
|
43 | - /** |
|
44 | - * Class constructor. |
|
45 | - */ |
|
46 | - public function __construct() { |
|
47 | - $this->define_constants(); |
|
48 | - $this->includes(); |
|
49 | - $this->init_hooks(); |
|
50 | - $this->set_properties(); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Sets a custom data property. |
|
55 | - * |
|
56 | - * @param string $prop The prop to set. |
|
57 | - * @param mixed $value The value to retrieve. |
|
58 | - */ |
|
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Gets a custom data property. |
|
65 | - * |
|
66 | - * @param string $prop The prop to set. |
|
67 | - * @return mixed The value. |
|
68 | - */ |
|
69 | - public function get( $prop ) { |
|
70 | - if ( isset( $this->data[ $prop ] ) ) { |
|
71 | - return $this->data[ $prop ]; |
|
72 | - } |
|
73 | - |
|
74 | - return null; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Define class properties. |
|
79 | - */ |
|
80 | - public function set_properties() { |
|
81 | - // Sessions. |
|
82 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
83 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
84 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
85 | - |
|
86 | - // Init other objects. |
|
87 | - $this->set( 'notes', new WPInv_Notes() ); |
|
88 | - $this->set( 'api', new WPInv_API() ); |
|
89 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
90 | - $this->set( 'template', new GetPaid_Template() ); |
|
91 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
92 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
93 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
94 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
95 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
96 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
97 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
98 | - $this->set( 'data_retention', new WPInv_Data_Retention() ); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Define plugin constants. |
|
103 | - */ |
|
104 | - public function define_constants() { |
|
105 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
106 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
107 | - $this->version = WPINV_VERSION; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Hook into actions and filters. |
|
112 | - * |
|
113 | - * @since 1.0.19 |
|
114 | - */ |
|
115 | - protected function init_hooks() { |
|
116 | - /* Internationalize the text strings used. */ |
|
117 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
118 | - |
|
119 | - // Init the plugin after WordPress inits. |
|
120 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
121 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 100 ); |
|
122 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
123 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
124 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
125 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
126 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
127 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
128 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
129 | - add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
130 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
131 | - |
|
132 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
133 | - add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
134 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
135 | - |
|
136 | - // Fires after registering actions. |
|
137 | - do_action( 'wpinv_actions', $this ); |
|
138 | - do_action( 'getpaid_actions', $this ); |
|
139 | - } |
|
140 | - |
|
141 | - public function plugins_loaded() { |
|
142 | - /* Internationalize the text strings used. */ |
|
143 | - $this->load_textdomain(); |
|
144 | - |
|
145 | - do_action( 'wpinv_loaded' ); |
|
146 | - |
|
147 | - // Fix oxygen page builder conflict |
|
148 | - if ( function_exists( 'ct_css_output' ) ) { |
|
149 | - wpinv_oxygen_fix_conflict(); |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Load Localisation files. |
|
155 | - * |
|
156 | - * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
157 | - * |
|
158 | - * Locales found in: |
|
159 | - * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
160 | - * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
161 | - * |
|
162 | - * @since 1.0.0 |
|
163 | - */ |
|
164 | - public function load_textdomain() { |
|
165 | - // Determines the current locale. |
|
166 | - if ( function_exists( 'determine_locale' ) ) { |
|
167 | - $locale = determine_locale(); |
|
168 | - } else if ( function_exists( 'get_user_locale' ) ) { |
|
169 | - $locale = get_user_locale(); |
|
170 | - } else { |
|
171 | - $locale = get_locale(); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Filter the locale to use for translations. |
|
176 | - */ |
|
177 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
178 | - |
|
179 | - unload_textdomain( 'invoicing', true ); |
|
180 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
181 | - load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Include required core files used in admin and on the frontend. |
|
186 | - */ |
|
187 | - public function includes() { |
|
188 | - // Start with the settings. |
|
189 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
190 | - |
|
191 | - // Packages/libraries. |
|
192 | - require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
193 | - require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
194 | - |
|
195 | - // Load functions. |
|
196 | - require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
197 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
198 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
199 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
200 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
201 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
202 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
203 | - require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
204 | - require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
205 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
206 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
207 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
208 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
209 | - require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
210 | - require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
211 | - |
|
212 | - // Register autoloader. |
|
213 | - try { |
|
214 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
215 | - } catch ( Exception $e ) { |
|
216 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
217 | - } |
|
218 | - |
|
219 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
220 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
221 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
222 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
223 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
224 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
225 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
226 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
227 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
228 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
229 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
230 | - require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
231 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
232 | - require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
233 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
234 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
235 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
236 | - require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
237 | - require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
238 | - require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
239 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
240 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
241 | - |
|
242 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
243 | - GetPaid_Post_Types_Admin::init(); |
|
244 | - |
|
245 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
246 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
247 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
248 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
249 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
250 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
251 | - // load the user class only on the users.php page |
|
252 | - global $pagenow; |
|
253 | - if ( $pagenow == 'users.php' ) { |
|
254 | - new WPInv_Admin_Users(); |
|
255 | - } |
|
256 | - } |
|
257 | - |
|
258 | - // Register cli commands |
|
259 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
260 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
261 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
262 | - } |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Class autoloader |
|
267 | - * |
|
268 | - * @param string $class_name The name of the class to load. |
|
269 | - * @access public |
|
270 | - * @since 1.0.19 |
|
271 | - * @return void |
|
272 | - */ |
|
273 | - public function autoload( $class_name ) { |
|
274 | - // Normalize the class name... |
|
275 | - $class_name = strtolower( $class_name ); |
|
276 | - |
|
277 | - // ... and make sure it is our class. |
|
278 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
279 | - return; |
|
280 | - } |
|
281 | - |
|
282 | - // Next, prepare the file name from the class. |
|
283 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
284 | - |
|
285 | - // Base path of the classes. |
|
286 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
287 | - |
|
288 | - // And an array of possible locations in order of importance. |
|
289 | - $locations = array( |
|
290 | - "$plugin_path/includes", |
|
291 | - "$plugin_path/includes/data-stores", |
|
292 | - "$plugin_path/includes/gateways", |
|
293 | - "$plugin_path/includes/payments", |
|
294 | - "$plugin_path/includes/geolocation", |
|
295 | - "$plugin_path/includes/reports", |
|
296 | - "$plugin_path/includes/api", |
|
297 | - "$plugin_path/includes/admin", |
|
298 | - "$plugin_path/includes/admin/meta-boxes", |
|
299 | - ); |
|
300 | - |
|
301 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
302 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
303 | - include trailingslashit( $location ) . $file_name; |
|
304 | - break; |
|
305 | - } |
|
306 | - } |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * Inits hooks etc. |
|
311 | - */ |
|
312 | - public function init() { |
|
313 | - // Fires before getpaid inits. |
|
314 | - do_action( 'before_getpaid_init', $this ); |
|
315 | - |
|
316 | - // Maybe upgrade. |
|
317 | - $this->maybe_upgrade_database(); |
|
318 | - |
|
319 | - // Load default gateways. |
|
320 | - $gateways = apply_filters( |
|
321 | - 'getpaid_default_gateways', |
|
322 | - array( |
|
323 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
324 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
325 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
326 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
327 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
328 | - ) |
|
329 | - ); |
|
330 | - |
|
331 | - foreach ( $gateways as $id => $class ) { |
|
332 | - $this->gateways[ $id ] = new $class(); |
|
333 | - } |
|
334 | - |
|
335 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
336 | - GetPaid_Installer::rename_gateways_label(); |
|
337 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
338 | - } |
|
339 | - |
|
340 | - // Fires after getpaid inits. |
|
341 | - do_action( 'getpaid_init', $this ); |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Checks if this is an IPN request and processes it. |
|
346 | - */ |
|
347 | - public function maybe_process_ipn() { |
|
348 | - // Ensure that this is an IPN request. |
|
349 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
350 | - return; |
|
351 | - } |
|
352 | - |
|
353 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
354 | - |
|
355 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
356 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
357 | - exit; |
|
358 | - } |
|
359 | - |
|
360 | - public function enqueue_scripts() { |
|
361 | - // Fires before adding scripts. |
|
362 | - do_action( 'getpaid_enqueue_scripts' ); |
|
363 | - |
|
364 | - $localize = array(); |
|
365 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
366 | - $localize['thousands'] = wpinv_thousands_separator(); |
|
367 | - $localize['decimals'] = wpinv_decimal_separator(); |
|
368 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
369 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
370 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
371 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
372 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
373 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
374 | - $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
375 | - |
|
376 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
377 | - |
|
378 | - // reCaptcha. |
|
379 | - if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
380 | - wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
381 | - } |
|
382 | - |
|
383 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array( 'jquery' ), WPINV_VERSION, true ); |
|
384 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
385 | - } |
|
386 | - |
|
387 | - public function wpinv_actions() { |
|
388 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
389 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
390 | - } |
|
391 | - |
|
392 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
393 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
394 | - } |
|
395 | - } |
|
396 | - |
|
397 | - /** |
|
398 | - * Fires an action after verifying that a user can fire them. |
|
399 | - * |
|
400 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
401 | - * current user owns the invoice/subscription. |
|
402 | - */ |
|
403 | - public function maybe_do_authenticated_action() { |
|
404 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
405 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
406 | - $data = wp_unslash( $_REQUEST ); |
|
407 | - |
|
408 | - if ( is_user_logged_in() ) { |
|
409 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
410 | - } |
|
411 | - |
|
412 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
413 | - } |
|
414 | - } |
|
415 | - |
|
416 | - public function pre_get_posts( $wp_query ) { |
|
417 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
418 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
419 | - } |
|
420 | - |
|
421 | - return $wp_query; |
|
422 | - } |
|
423 | - |
|
424 | - /** |
|
425 | - * Register widgets |
|
426 | - * |
|
427 | - */ |
|
428 | - public function register_widgets() { |
|
429 | - global $pagenow; |
|
430 | - |
|
431 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
432 | - // So we disable our widgets when editing a page with UX Builder. |
|
433 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
434 | - return; |
|
435 | - } |
|
436 | - |
|
437 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
438 | - |
|
439 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
440 | - // don't initiate in these conditions. |
|
441 | - } else { |
|
442 | - // Only load allowed widgets. |
|
443 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
444 | - $widgets = apply_filters( |
|
445 | - 'getpaid_widget_classes', |
|
446 | - array( |
|
447 | - 'WPInv_Checkout_Widget', |
|
448 | - 'WPInv_History_Widget', |
|
449 | - 'WPInv_Receipt_Widget', |
|
450 | - 'WPInv_Subscriptions_Widget', |
|
451 | - 'WPInv_Buy_Item_Widget', |
|
452 | - 'WPInv_Messages_Widget', |
|
453 | - 'WPInv_GetPaid_Widget', |
|
454 | - 'WPInv_Invoice_Widget', |
|
455 | - ) |
|
456 | - ); |
|
457 | - |
|
458 | - // For each widget... |
|
459 | - foreach ( $widgets as $widget ) { |
|
460 | - // Abort early if it is excluded for this page. |
|
461 | - if ( in_array( $widget, $exclude ) ) { |
|
462 | - continue; |
|
463 | - } |
|
464 | - |
|
465 | - // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
466 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
467 | - register_widget( $widget ); |
|
468 | - } else { |
|
469 | - new $widget(); |
|
470 | - } |
|
471 | - } |
|
472 | - } |
|
473 | - } |
|
474 | - |
|
475 | - /** |
|
476 | - * Upgrades the database. |
|
477 | - * |
|
478 | - * @since 2.0.2 |
|
479 | - */ |
|
480 | - public function maybe_upgrade_database() { |
|
481 | - // Ensure the database tables are up to date. |
|
482 | - GetPaid_Installer::maybe_create_db_tables(); |
|
483 | - |
|
484 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
485 | - |
|
486 | - if ( $wpi_version == WPINV_VERSION ) { |
|
487 | - return; |
|
488 | - } |
|
489 | - |
|
490 | - $installer = new GetPaid_Installer(); |
|
491 | - |
|
492 | - if ( empty( $wpi_version ) ) { |
|
493 | - return $installer->upgrade_db( 0 ); |
|
494 | - } |
|
495 | - |
|
496 | - $upgrades = array( |
|
497 | - '0.0.5' => '004', |
|
498 | - '1.0.3' => '102', |
|
499 | - '2.0.0' => '118', |
|
500 | - '2.8.0' => '279', |
|
501 | - ); |
|
502 | - |
|
503 | - foreach ( $upgrades as $key => $method ) { |
|
504 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
505 | - return $installer->upgrade_db( $method ); |
|
506 | - } |
|
507 | - } |
|
508 | - } |
|
509 | - |
|
510 | - /** |
|
511 | - * Flushes the permalinks if needed. |
|
512 | - * |
|
513 | - * @since 2.0.8 |
|
514 | - */ |
|
515 | - public function maybe_flush_permalinks() { |
|
516 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
517 | - |
|
518 | - if ( ! empty( $flush ) ) { |
|
519 | - flush_rewrite_rules(); |
|
520 | - delete_option( 'wpinv_flush_permalinks' ); |
|
521 | - } |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * Remove our pages from yoast sitemaps. |
|
526 | - * |
|
527 | - * @since 1.0.19 |
|
528 | - * @param int[] $excluded_posts_ids |
|
529 | - */ |
|
530 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
531 | - // Ensure that we have an array. |
|
532 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
533 | - $excluded_posts_ids = array(); |
|
534 | - } |
|
535 | - |
|
536 | - // Prepare our pages. |
|
537 | - $our_pages = array(); |
|
538 | - |
|
539 | - // Checkout page. |
|
540 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
541 | - |
|
542 | - // Success page. |
|
543 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
544 | - |
|
545 | - // Failure page. |
|
546 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
547 | - |
|
548 | - // History page. |
|
549 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
550 | - |
|
551 | - // Subscriptions page. |
|
552 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
553 | - |
|
554 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
555 | - |
|
556 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
557 | - |
|
558 | - return array_unique( $excluded_posts_ids ); |
|
559 | - } |
|
560 | - |
|
561 | - /** |
|
562 | - * Remove our pages from yoast sitemaps. |
|
563 | - * |
|
564 | - * @since 1.0.19 |
|
565 | - * @param string[] $post_types |
|
566 | - */ |
|
567 | - public function exclude_invoicing_post_types( $post_types ) { |
|
568 | - // Ensure that we have an array. |
|
569 | - if ( ! is_array( $post_types ) ) { |
|
570 | - $post_types = array(); |
|
571 | - } |
|
572 | - |
|
573 | - // Remove our post types. |
|
574 | - return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * Displays additional footer code. |
|
579 | - * |
|
580 | - * @since 2.0.0 |
|
581 | - */ |
|
582 | - public function wp_footer() { |
|
583 | - wpinv_get_template( 'frontend-footer.php' ); |
|
584 | - } |
|
585 | - |
|
586 | - /** |
|
587 | - * Displays additional header code. |
|
588 | - * |
|
589 | - * @since 2.0.0 |
|
590 | - */ |
|
591 | - public function wp_head() { |
|
592 | - wpinv_get_template( 'frontend-head.php' ); |
|
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * Custom query vars. |
|
597 | - * |
|
598 | - */ |
|
599 | - public function custom_query_vars( $vars ) { |
|
600 | - $vars[] = 'getpaid-ipn'; |
|
601 | - return $vars; |
|
602 | - } |
|
603 | - |
|
604 | - /** |
|
605 | - * Add rewrite tags and rules. |
|
606 | - * |
|
607 | - */ |
|
608 | - public function add_rewrite_rule() { |
|
609 | - $tag = 'getpaid-ipn'; |
|
610 | - add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
611 | - add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
612 | - } |
|
613 | - |
|
614 | - /** |
|
615 | - * Processes non-query string ipns. |
|
616 | - * |
|
617 | - */ |
|
618 | - public function maybe_process_new_ipn( $query ) { |
|
619 | - if ( is_admin() || ! $query->is_main_query() ) { |
|
620 | - return; |
|
621 | - } |
|
622 | - |
|
623 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
624 | - |
|
625 | - if ( ! empty( $gateway ) ) { |
|
626 | - $gateway = sanitize_text_field( $gateway ); |
|
627 | - nocache_headers(); |
|
628 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
629 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
630 | - exit; |
|
631 | - } |
|
632 | - } |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var array An array of payment gateways. |
|
40 | + */ |
|
41 | + public $gateways; |
|
42 | + |
|
43 | + /** |
|
44 | + * Class constructor. |
|
45 | + */ |
|
46 | + public function __construct() { |
|
47 | + $this->define_constants(); |
|
48 | + $this->includes(); |
|
49 | + $this->init_hooks(); |
|
50 | + $this->set_properties(); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Sets a custom data property. |
|
55 | + * |
|
56 | + * @param string $prop The prop to set. |
|
57 | + * @param mixed $value The value to retrieve. |
|
58 | + */ |
|
59 | + public function set( $prop, $value ) { |
|
60 | + $this->data[ $prop ] = $value; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Gets a custom data property. |
|
65 | + * |
|
66 | + * @param string $prop The prop to set. |
|
67 | + * @return mixed The value. |
|
68 | + */ |
|
69 | + public function get( $prop ) { |
|
70 | + if ( isset( $this->data[ $prop ] ) ) { |
|
71 | + return $this->data[ $prop ]; |
|
72 | + } |
|
73 | + |
|
74 | + return null; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Define class properties. |
|
79 | + */ |
|
80 | + public function set_properties() { |
|
81 | + // Sessions. |
|
82 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
83 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
84 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
85 | + |
|
86 | + // Init other objects. |
|
87 | + $this->set( 'notes', new WPInv_Notes() ); |
|
88 | + $this->set( 'api', new WPInv_API() ); |
|
89 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
90 | + $this->set( 'template', new GetPaid_Template() ); |
|
91 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
92 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
93 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
94 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
95 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
96 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
97 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
98 | + $this->set( 'data_retention', new WPInv_Data_Retention() ); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Define plugin constants. |
|
103 | + */ |
|
104 | + public function define_constants() { |
|
105 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
106 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
107 | + $this->version = WPINV_VERSION; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Hook into actions and filters. |
|
112 | + * |
|
113 | + * @since 1.0.19 |
|
114 | + */ |
|
115 | + protected function init_hooks() { |
|
116 | + /* Internationalize the text strings used. */ |
|
117 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
118 | + |
|
119 | + // Init the plugin after WordPress inits. |
|
120 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
121 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 100 ); |
|
122 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
123 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
124 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
125 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
126 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
127 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
128 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
129 | + add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
130 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
131 | + |
|
132 | + add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
133 | + add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
134 | + add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
135 | + |
|
136 | + // Fires after registering actions. |
|
137 | + do_action( 'wpinv_actions', $this ); |
|
138 | + do_action( 'getpaid_actions', $this ); |
|
139 | + } |
|
140 | + |
|
141 | + public function plugins_loaded() { |
|
142 | + /* Internationalize the text strings used. */ |
|
143 | + $this->load_textdomain(); |
|
144 | + |
|
145 | + do_action( 'wpinv_loaded' ); |
|
146 | + |
|
147 | + // Fix oxygen page builder conflict |
|
148 | + if ( function_exists( 'ct_css_output' ) ) { |
|
149 | + wpinv_oxygen_fix_conflict(); |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Load Localisation files. |
|
155 | + * |
|
156 | + * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
157 | + * |
|
158 | + * Locales found in: |
|
159 | + * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
160 | + * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
161 | + * |
|
162 | + * @since 1.0.0 |
|
163 | + */ |
|
164 | + public function load_textdomain() { |
|
165 | + // Determines the current locale. |
|
166 | + if ( function_exists( 'determine_locale' ) ) { |
|
167 | + $locale = determine_locale(); |
|
168 | + } else if ( function_exists( 'get_user_locale' ) ) { |
|
169 | + $locale = get_user_locale(); |
|
170 | + } else { |
|
171 | + $locale = get_locale(); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Filter the locale to use for translations. |
|
176 | + */ |
|
177 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
178 | + |
|
179 | + unload_textdomain( 'invoicing', true ); |
|
180 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
181 | + load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Include required core files used in admin and on the frontend. |
|
186 | + */ |
|
187 | + public function includes() { |
|
188 | + // Start with the settings. |
|
189 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
190 | + |
|
191 | + // Packages/libraries. |
|
192 | + require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
193 | + require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
194 | + |
|
195 | + // Load functions. |
|
196 | + require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
197 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
198 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
199 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
200 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
201 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
202 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
203 | + require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
204 | + require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
205 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
206 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
207 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
208 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
209 | + require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
210 | + require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
211 | + |
|
212 | + // Register autoloader. |
|
213 | + try { |
|
214 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
215 | + } catch ( Exception $e ) { |
|
216 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
217 | + } |
|
218 | + |
|
219 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
220 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
221 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
222 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
223 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
224 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
225 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
226 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
227 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
228 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
229 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
230 | + require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
231 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
232 | + require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
233 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
234 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
235 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
236 | + require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
237 | + require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
238 | + require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
239 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
240 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
241 | + |
|
242 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
243 | + GetPaid_Post_Types_Admin::init(); |
|
244 | + |
|
245 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
246 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
247 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
248 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
249 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
250 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
251 | + // load the user class only on the users.php page |
|
252 | + global $pagenow; |
|
253 | + if ( $pagenow == 'users.php' ) { |
|
254 | + new WPInv_Admin_Users(); |
|
255 | + } |
|
256 | + } |
|
257 | + |
|
258 | + // Register cli commands |
|
259 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
260 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
261 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
262 | + } |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Class autoloader |
|
267 | + * |
|
268 | + * @param string $class_name The name of the class to load. |
|
269 | + * @access public |
|
270 | + * @since 1.0.19 |
|
271 | + * @return void |
|
272 | + */ |
|
273 | + public function autoload( $class_name ) { |
|
274 | + // Normalize the class name... |
|
275 | + $class_name = strtolower( $class_name ); |
|
276 | + |
|
277 | + // ... and make sure it is our class. |
|
278 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
279 | + return; |
|
280 | + } |
|
281 | + |
|
282 | + // Next, prepare the file name from the class. |
|
283 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
284 | + |
|
285 | + // Base path of the classes. |
|
286 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
287 | + |
|
288 | + // And an array of possible locations in order of importance. |
|
289 | + $locations = array( |
|
290 | + "$plugin_path/includes", |
|
291 | + "$plugin_path/includes/data-stores", |
|
292 | + "$plugin_path/includes/gateways", |
|
293 | + "$plugin_path/includes/payments", |
|
294 | + "$plugin_path/includes/geolocation", |
|
295 | + "$plugin_path/includes/reports", |
|
296 | + "$plugin_path/includes/api", |
|
297 | + "$plugin_path/includes/admin", |
|
298 | + "$plugin_path/includes/admin/meta-boxes", |
|
299 | + ); |
|
300 | + |
|
301 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
302 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
303 | + include trailingslashit( $location ) . $file_name; |
|
304 | + break; |
|
305 | + } |
|
306 | + } |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * Inits hooks etc. |
|
311 | + */ |
|
312 | + public function init() { |
|
313 | + // Fires before getpaid inits. |
|
314 | + do_action( 'before_getpaid_init', $this ); |
|
315 | + |
|
316 | + // Maybe upgrade. |
|
317 | + $this->maybe_upgrade_database(); |
|
318 | + |
|
319 | + // Load default gateways. |
|
320 | + $gateways = apply_filters( |
|
321 | + 'getpaid_default_gateways', |
|
322 | + array( |
|
323 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
324 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
325 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
326 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
327 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
328 | + ) |
|
329 | + ); |
|
330 | + |
|
331 | + foreach ( $gateways as $id => $class ) { |
|
332 | + $this->gateways[ $id ] = new $class(); |
|
333 | + } |
|
334 | + |
|
335 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
336 | + GetPaid_Installer::rename_gateways_label(); |
|
337 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
338 | + } |
|
339 | + |
|
340 | + // Fires after getpaid inits. |
|
341 | + do_action( 'getpaid_init', $this ); |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Checks if this is an IPN request and processes it. |
|
346 | + */ |
|
347 | + public function maybe_process_ipn() { |
|
348 | + // Ensure that this is an IPN request. |
|
349 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
350 | + return; |
|
351 | + } |
|
352 | + |
|
353 | + $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
354 | + |
|
355 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
356 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
357 | + exit; |
|
358 | + } |
|
359 | + |
|
360 | + public function enqueue_scripts() { |
|
361 | + // Fires before adding scripts. |
|
362 | + do_action( 'getpaid_enqueue_scripts' ); |
|
363 | + |
|
364 | + $localize = array(); |
|
365 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
366 | + $localize['thousands'] = wpinv_thousands_separator(); |
|
367 | + $localize['decimals'] = wpinv_decimal_separator(); |
|
368 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
369 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
370 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
371 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
372 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
373 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
374 | + $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
375 | + |
|
376 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
377 | + |
|
378 | + // reCaptcha. |
|
379 | + if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
380 | + wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
381 | + } |
|
382 | + |
|
383 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array( 'jquery' ), WPINV_VERSION, true ); |
|
384 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
385 | + } |
|
386 | + |
|
387 | + public function wpinv_actions() { |
|
388 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
389 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
390 | + } |
|
391 | + |
|
392 | + if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
393 | + include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
394 | + } |
|
395 | + } |
|
396 | + |
|
397 | + /** |
|
398 | + * Fires an action after verifying that a user can fire them. |
|
399 | + * |
|
400 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
401 | + * current user owns the invoice/subscription. |
|
402 | + */ |
|
403 | + public function maybe_do_authenticated_action() { |
|
404 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
405 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
406 | + $data = wp_unslash( $_REQUEST ); |
|
407 | + |
|
408 | + if ( is_user_logged_in() ) { |
|
409 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
410 | + } |
|
411 | + |
|
412 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
413 | + } |
|
414 | + } |
|
415 | + |
|
416 | + public function pre_get_posts( $wp_query ) { |
|
417 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
418 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
419 | + } |
|
420 | + |
|
421 | + return $wp_query; |
|
422 | + } |
|
423 | + |
|
424 | + /** |
|
425 | + * Register widgets |
|
426 | + * |
|
427 | + */ |
|
428 | + public function register_widgets() { |
|
429 | + global $pagenow; |
|
430 | + |
|
431 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
432 | + // So we disable our widgets when editing a page with UX Builder. |
|
433 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
434 | + return; |
|
435 | + } |
|
436 | + |
|
437 | + $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
438 | + |
|
439 | + if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
440 | + // don't initiate in these conditions. |
|
441 | + } else { |
|
442 | + // Only load allowed widgets. |
|
443 | + $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
444 | + $widgets = apply_filters( |
|
445 | + 'getpaid_widget_classes', |
|
446 | + array( |
|
447 | + 'WPInv_Checkout_Widget', |
|
448 | + 'WPInv_History_Widget', |
|
449 | + 'WPInv_Receipt_Widget', |
|
450 | + 'WPInv_Subscriptions_Widget', |
|
451 | + 'WPInv_Buy_Item_Widget', |
|
452 | + 'WPInv_Messages_Widget', |
|
453 | + 'WPInv_GetPaid_Widget', |
|
454 | + 'WPInv_Invoice_Widget', |
|
455 | + ) |
|
456 | + ); |
|
457 | + |
|
458 | + // For each widget... |
|
459 | + foreach ( $widgets as $widget ) { |
|
460 | + // Abort early if it is excluded for this page. |
|
461 | + if ( in_array( $widget, $exclude ) ) { |
|
462 | + continue; |
|
463 | + } |
|
464 | + |
|
465 | + // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
466 | + if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
467 | + register_widget( $widget ); |
|
468 | + } else { |
|
469 | + new $widget(); |
|
470 | + } |
|
471 | + } |
|
472 | + } |
|
473 | + } |
|
474 | + |
|
475 | + /** |
|
476 | + * Upgrades the database. |
|
477 | + * |
|
478 | + * @since 2.0.2 |
|
479 | + */ |
|
480 | + public function maybe_upgrade_database() { |
|
481 | + // Ensure the database tables are up to date. |
|
482 | + GetPaid_Installer::maybe_create_db_tables(); |
|
483 | + |
|
484 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
485 | + |
|
486 | + if ( $wpi_version == WPINV_VERSION ) { |
|
487 | + return; |
|
488 | + } |
|
489 | + |
|
490 | + $installer = new GetPaid_Installer(); |
|
491 | + |
|
492 | + if ( empty( $wpi_version ) ) { |
|
493 | + return $installer->upgrade_db( 0 ); |
|
494 | + } |
|
495 | + |
|
496 | + $upgrades = array( |
|
497 | + '0.0.5' => '004', |
|
498 | + '1.0.3' => '102', |
|
499 | + '2.0.0' => '118', |
|
500 | + '2.8.0' => '279', |
|
501 | + ); |
|
502 | + |
|
503 | + foreach ( $upgrades as $key => $method ) { |
|
504 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
505 | + return $installer->upgrade_db( $method ); |
|
506 | + } |
|
507 | + } |
|
508 | + } |
|
509 | + |
|
510 | + /** |
|
511 | + * Flushes the permalinks if needed. |
|
512 | + * |
|
513 | + * @since 2.0.8 |
|
514 | + */ |
|
515 | + public function maybe_flush_permalinks() { |
|
516 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
517 | + |
|
518 | + if ( ! empty( $flush ) ) { |
|
519 | + flush_rewrite_rules(); |
|
520 | + delete_option( 'wpinv_flush_permalinks' ); |
|
521 | + } |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * Remove our pages from yoast sitemaps. |
|
526 | + * |
|
527 | + * @since 1.0.19 |
|
528 | + * @param int[] $excluded_posts_ids |
|
529 | + */ |
|
530 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
531 | + // Ensure that we have an array. |
|
532 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
533 | + $excluded_posts_ids = array(); |
|
534 | + } |
|
535 | + |
|
536 | + // Prepare our pages. |
|
537 | + $our_pages = array(); |
|
538 | + |
|
539 | + // Checkout page. |
|
540 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
541 | + |
|
542 | + // Success page. |
|
543 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
544 | + |
|
545 | + // Failure page. |
|
546 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
547 | + |
|
548 | + // History page. |
|
549 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
550 | + |
|
551 | + // Subscriptions page. |
|
552 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
553 | + |
|
554 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
555 | + |
|
556 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
557 | + |
|
558 | + return array_unique( $excluded_posts_ids ); |
|
559 | + } |
|
560 | + |
|
561 | + /** |
|
562 | + * Remove our pages from yoast sitemaps. |
|
563 | + * |
|
564 | + * @since 1.0.19 |
|
565 | + * @param string[] $post_types |
|
566 | + */ |
|
567 | + public function exclude_invoicing_post_types( $post_types ) { |
|
568 | + // Ensure that we have an array. |
|
569 | + if ( ! is_array( $post_types ) ) { |
|
570 | + $post_types = array(); |
|
571 | + } |
|
572 | + |
|
573 | + // Remove our post types. |
|
574 | + return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * Displays additional footer code. |
|
579 | + * |
|
580 | + * @since 2.0.0 |
|
581 | + */ |
|
582 | + public function wp_footer() { |
|
583 | + wpinv_get_template( 'frontend-footer.php' ); |
|
584 | + } |
|
585 | + |
|
586 | + /** |
|
587 | + * Displays additional header code. |
|
588 | + * |
|
589 | + * @since 2.0.0 |
|
590 | + */ |
|
591 | + public function wp_head() { |
|
592 | + wpinv_get_template( 'frontend-head.php' ); |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * Custom query vars. |
|
597 | + * |
|
598 | + */ |
|
599 | + public function custom_query_vars( $vars ) { |
|
600 | + $vars[] = 'getpaid-ipn'; |
|
601 | + return $vars; |
|
602 | + } |
|
603 | + |
|
604 | + /** |
|
605 | + * Add rewrite tags and rules. |
|
606 | + * |
|
607 | + */ |
|
608 | + public function add_rewrite_rule() { |
|
609 | + $tag = 'getpaid-ipn'; |
|
610 | + add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
611 | + add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
612 | + } |
|
613 | + |
|
614 | + /** |
|
615 | + * Processes non-query string ipns. |
|
616 | + * |
|
617 | + */ |
|
618 | + public function maybe_process_new_ipn( $query ) { |
|
619 | + if ( is_admin() || ! $query->is_main_query() ) { |
|
620 | + return; |
|
621 | + } |
|
622 | + |
|
623 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
624 | + |
|
625 | + if ( ! empty( $gateway ) ) { |
|
626 | + $gateway = sanitize_text_field( $gateway ); |
|
627 | + nocache_headers(); |
|
628 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
629 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
630 | + exit; |
|
631 | + } |
|
632 | + } |
|
633 | 633 | } |