@@ -4,99 +4,99 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Displays an invoice. |
11 | 11 | * |
12 | 12 | * @param WPInv_Invoice $invoice. |
13 | 13 | */ |
14 | -function getpaid_invoice( $invoice ) { |
|
15 | - if ( ! empty( $invoice ) ) { |
|
16 | - wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) ); |
|
14 | +function getpaid_invoice($invoice) { |
|
15 | + if (!empty($invoice)) { |
|
16 | + wpinv_get_template('invoice/invoice.php', compact('invoice')); |
|
17 | 17 | } |
18 | 18 | } |
19 | -add_action( 'getpaid_invoice', 'getpaid_invoice', 10 ); |
|
19 | +add_action('getpaid_invoice', 'getpaid_invoice', 10); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Displays the invoice footer. |
23 | 23 | */ |
24 | -function getpaid_invoice_footer( $invoice ) { |
|
25 | - if ( ! empty( $invoice ) ) { |
|
26 | - wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) ); |
|
24 | +function getpaid_invoice_footer($invoice) { |
|
25 | + if (!empty($invoice)) { |
|
26 | + wpinv_get_template('invoice/footer.php', compact('invoice')); |
|
27 | 27 | } |
28 | 28 | } |
29 | -add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 ); |
|
29 | +add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Displays the invoice top bar. |
33 | 33 | */ |
34 | -function getpaid_invoice_header( $invoice ) { |
|
35 | - if ( ! empty( $invoice ) ) { |
|
36 | - wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) ); |
|
34 | +function getpaid_invoice_header($invoice) { |
|
35 | + if (!empty($invoice)) { |
|
36 | + wpinv_get_template('invoice/header.php', compact('invoice')); |
|
37 | 37 | } |
38 | 38 | } |
39 | -add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 ); |
|
39 | +add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10); |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Displays actions on the left side of the header. |
43 | 43 | */ |
44 | -function getpaid_invoice_header_left_actions( $invoice ) { |
|
45 | - if ( ! empty( $invoice ) ) { |
|
46 | - wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) ); |
|
44 | +function getpaid_invoice_header_left_actions($invoice) { |
|
45 | + if (!empty($invoice)) { |
|
46 | + wpinv_get_template('invoice/header-left-actions.php', compact('invoice')); |
|
47 | 47 | } |
48 | 48 | } |
49 | -add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 ); |
|
49 | +add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10); |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Displays actions on the right side of the invoice top bar. |
53 | 53 | */ |
54 | -function getpaid_invoice_header_right_actions( $invoice ) { |
|
55 | - if ( ! empty( $invoice ) ) { |
|
56 | - wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) ); |
|
54 | +function getpaid_invoice_header_right_actions($invoice) { |
|
55 | + if (!empty($invoice)) { |
|
56 | + wpinv_get_template('invoice/header-right-actions.php', compact('invoice')); |
|
57 | 57 | } |
58 | 58 | } |
59 | -add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 ); |
|
59 | +add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10); |
|
60 | 60 | |
61 | 61 | /** |
62 | 62 | * Displays the invoice title, logo etc. |
63 | 63 | */ |
64 | -function getpaid_invoice_details_top( $invoice ) { |
|
65 | - if ( ! empty( $invoice ) ) { |
|
66 | - wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) ); |
|
64 | +function getpaid_invoice_details_top($invoice) { |
|
65 | + if (!empty($invoice)) { |
|
66 | + wpinv_get_template('invoice/details-top.php', compact('invoice')); |
|
67 | 67 | } |
68 | 68 | } |
69 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 ); |
|
69 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10); |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * Displays the company logo. |
73 | 73 | */ |
74 | -function getpaid_invoice_logo( $invoice ) { |
|
75 | - if ( ! empty( $invoice ) ) { |
|
76 | - wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) ); |
|
74 | +function getpaid_invoice_logo($invoice) { |
|
75 | + if (!empty($invoice)) { |
|
76 | + wpinv_get_template('invoice/invoice-logo.php', compact('invoice')); |
|
77 | 77 | } |
78 | 78 | } |
79 | -add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' ); |
|
79 | +add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo'); |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Displays the type of invoice. |
83 | 83 | */ |
84 | -function getpaid_invoice_type( $invoice ) { |
|
85 | - if ( ! empty( $invoice ) ) { |
|
86 | - wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) ); |
|
84 | +function getpaid_invoice_type($invoice) { |
|
85 | + if (!empty($invoice)) { |
|
86 | + wpinv_get_template('invoice/invoice-type.php', compact('invoice')); |
|
87 | 87 | } |
88 | 88 | } |
89 | -add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' ); |
|
89 | +add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type'); |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Displays the invoice details. |
93 | 93 | */ |
94 | -function getpaid_invoice_details_main( $invoice ) { |
|
95 | - if ( ! empty( $invoice ) ) { |
|
96 | - wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) ); |
|
94 | +function getpaid_invoice_details_main($invoice) { |
|
95 | + if (!empty($invoice)) { |
|
96 | + wpinv_get_template('invoice/details.php', compact('invoice')); |
|
97 | 97 | } |
98 | 98 | } |
99 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 ); |
|
99 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50); |
|
100 | 100 | |
101 | 101 | /** |
102 | 102 | * Returns a path to the templates directory. |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
126 | 126 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
127 | 127 | */ |
128 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
129 | - getpaid_template()->display_template( $template_name, $args, $template_path, $default_path ); |
|
128 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
129 | + getpaid_template()->display_template($template_name, $args, $template_path, $default_path); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
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 ); |
|
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); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @return string |
150 | 150 | */ |
151 | 151 | function wpinv_template_path() { |
152 | - return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() ); |
|
152 | + return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name()); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -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 | /** |
@@ -170,58 +170,58 @@ discard block |
||
170 | 170 | * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'. |
171 | 171 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
172 | 172 | */ |
173 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
174 | - return getpaid_template()->locate_template( $template_name, $template_path, $default_path ); |
|
173 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
174 | + return getpaid_template()->locate_template($template_name, $template_path, $default_path); |
|
175 | 175 | } |
176 | 176 | |
177 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
177 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
178 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
179 | 179 | |
180 | 180 | // Setup possible parts |
181 | 181 | $templates = array(); |
182 | - if ( isset( $name ) ) { |
|
182 | + if (isset($name)) { |
|
183 | 183 | $templates[] = $slug . '-' . $name . '.php'; |
184 | 184 | } |
185 | 185 | $templates[] = $slug . '.php'; |
186 | 186 | |
187 | 187 | // Allow template parts to be filtered |
188 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
188 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
189 | 189 | |
190 | 190 | // Return the part that is found |
191 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
191 | + return wpinv_locate_tmpl($templates, $load, false); |
|
192 | 192 | } |
193 | 193 | |
194 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
194 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
195 | 195 | // No file found yet |
196 | 196 | $located = false; |
197 | 197 | |
198 | 198 | // Try to find a template file |
199 | - foreach ( (array)$template_names as $template_name ) { |
|
199 | + foreach ((array) $template_names as $template_name) { |
|
200 | 200 | |
201 | 201 | // Continue if template is empty |
202 | - if ( empty( $template_name ) ) { |
|
202 | + if (empty($template_name)) { |
|
203 | 203 | continue; |
204 | 204 | } |
205 | 205 | |
206 | 206 | // Trim off any slashes from the template name |
207 | - $template_name = ltrim( $template_name, '/' ); |
|
207 | + $template_name = ltrim($template_name, '/'); |
|
208 | 208 | |
209 | 209 | // try locating this template file by looping through the template paths |
210 | - foreach ( wpinv_get_theme_template_paths() as $template_path ) { |
|
210 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
211 | 211 | |
212 | - if ( file_exists( $template_path . $template_name ) ) { |
|
212 | + if (file_exists($template_path . $template_name)) { |
|
213 | 213 | $located = $template_path . $template_name; |
214 | 214 | break; |
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
218 | - if ( ! empty( $located ) ) { |
|
218 | + if (!empty($located)) { |
|
219 | 219 | break; |
220 | 220 | } |
221 | 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 | 227 | return $located; |
@@ -231,73 +231,73 @@ discard block |
||
231 | 231 | $template_dir = wpinv_get_theme_template_dir_name(); |
232 | 232 | |
233 | 233 | $file_paths = array( |
234 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
235 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
234 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
235 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
236 | 236 | 100 => wpinv_get_templates_dir(), |
237 | 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 | 241 | // sort the file paths based on priority |
242 | - ksort( $file_paths, SORT_NUMERIC ); |
|
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 | 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' ); |
|
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 ) ) { |
|
255 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
256 | 256 | return; |
257 | 257 | } |
258 | 258 | |
259 | 259 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
260 | 260 | } |
261 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
261 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
262 | 262 | |
263 | -function wpinv_add_body_classes( $class ) { |
|
264 | - $classes = (array)$class; |
|
263 | +function wpinv_add_body_classes($class) { |
|
264 | + $classes = (array) $class; |
|
265 | 265 | |
266 | - if ( wpinv_is_checkout() ) { |
|
266 | + if (wpinv_is_checkout()) { |
|
267 | 267 | $classes[] = 'wpinv-checkout'; |
268 | 268 | $classes[] = 'wpinv-page'; |
269 | 269 | } |
270 | 270 | |
271 | - if ( wpinv_is_success_page() ) { |
|
271 | + if (wpinv_is_success_page()) { |
|
272 | 272 | $classes[] = 'wpinv-success'; |
273 | 273 | $classes[] = 'wpinv-page'; |
274 | 274 | } |
275 | 275 | |
276 | - if ( wpinv_is_failed_transaction_page() ) { |
|
276 | + if (wpinv_is_failed_transaction_page()) { |
|
277 | 277 | $classes[] = 'wpinv-failed-transaction'; |
278 | 278 | $classes[] = 'wpinv-page'; |
279 | 279 | } |
280 | 280 | |
281 | - if ( wpinv_is_invoice_history_page() ) { |
|
281 | + if (wpinv_is_invoice_history_page()) { |
|
282 | 282 | $classes[] = 'wpinv-history'; |
283 | 283 | $classes[] = 'wpinv-page'; |
284 | 284 | } |
285 | 285 | |
286 | - if ( wpinv_is_subscriptions_history_page() ) { |
|
286 | + if (wpinv_is_subscriptions_history_page()) { |
|
287 | 287 | $classes[] = 'wpinv-subscription'; |
288 | 288 | $classes[] = 'wpinv-page'; |
289 | 289 | } |
290 | 290 | |
291 | - if ( wpinv_is_test_mode() ) { |
|
291 | + if (wpinv_is_test_mode()) { |
|
292 | 292 | $classes[] = 'wpinv-test-mode'; |
293 | 293 | $classes[] = 'wpinv-page'; |
294 | 294 | } |
295 | 295 | |
296 | - return array_unique( $classes ); |
|
296 | + return array_unique($classes); |
|
297 | 297 | } |
298 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
298 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
299 | 299 | |
300 | -function wpinv_html_select( $args = array() ) { |
|
300 | +function wpinv_html_select($args = array()) { |
|
301 | 301 | $defaults = array( |
302 | 302 | 'options' => array(), |
303 | 303 | 'name' => null, |
@@ -306,8 +306,8 @@ discard block |
||
306 | 306 | 'selected' => 0, |
307 | 307 | 'placeholder' => null, |
308 | 308 | 'multiple' => false, |
309 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
310 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
309 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
310 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
311 | 311 | 'data' => array(), |
312 | 312 | 'onchange' => null, |
313 | 313 | 'required' => false, |
@@ -315,79 +315,79 @@ discard block |
||
315 | 315 | 'readonly' => false, |
316 | 316 | ); |
317 | 317 | |
318 | - $args = wp_parse_args( $args, $defaults ); |
|
318 | + $args = wp_parse_args($args, $defaults); |
|
319 | 319 | |
320 | 320 | $attrs = array( |
321 | 321 | 'name' => $args['name'], |
322 | 322 | 'id' => $args['id'], |
323 | - 'class' => 'wpinv-select ' . implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ), |
|
324 | - 'multiple' => ! empty( $args['multiple'] ), |
|
325 | - 'readonly' => ! empty( $args['readonly'] ), |
|
326 | - 'disabled' => ! empty( $args['disabled'] ), |
|
327 | - 'required' => ! empty( $args['required'] ), |
|
328 | - 'onchange' => ! empty( $args['onchange'] ), |
|
323 | + 'class' => 'wpinv-select ' . implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))), |
|
324 | + 'multiple' => !empty($args['multiple']), |
|
325 | + 'readonly' => !empty($args['readonly']), |
|
326 | + 'disabled' => !empty($args['disabled']), |
|
327 | + 'required' => !empty($args['required']), |
|
328 | + 'onchange' => !empty($args['onchange']), |
|
329 | 329 | ); |
330 | 330 | |
331 | - if ( $args['placeholder'] ) { |
|
331 | + if ($args['placeholder']) { |
|
332 | 332 | $attrs['data-placeholder'] = $args['placeholder']; |
333 | 333 | } |
334 | 334 | |
335 | - if ( $args['onchange'] ) { |
|
335 | + if ($args['onchange']) { |
|
336 | 336 | $attrs['onchange'] = $args['onchange']; |
337 | 337 | } |
338 | 338 | |
339 | - foreach ( $args['data'] as $key => $value ) { |
|
339 | + foreach ($args['data'] as $key => $value) { |
|
340 | 340 | $attrs["data-$key"] = $value; |
341 | 341 | } |
342 | 342 | |
343 | 343 | echo '<select '; |
344 | 344 | |
345 | - foreach ( $attrs as $attr => $value ) { |
|
345 | + foreach ($attrs as $attr => $value) { |
|
346 | 346 | |
347 | - if ( false === $value ) { |
|
347 | + if (false === $value) { |
|
348 | 348 | continue; |
349 | 349 | } |
350 | 350 | |
351 | - if ( true === $value ) { |
|
352 | - echo ' ' . esc_attr( $attr ); |
|
351 | + if (true === $value) { |
|
352 | + echo ' ' . esc_attr($attr); |
|
353 | 353 | } else { |
354 | - echo ' ' . esc_attr( $attr ) . '="' . esc_attr( $value ) . '"'; |
|
354 | + echo ' ' . esc_attr($attr) . '="' . esc_attr($value) . '"'; |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | } |
358 | 358 | |
359 | 359 | echo '>'; |
360 | 360 | |
361 | - if ( $args['show_option_all'] ) { |
|
362 | - if ( $args['multiple'] ) { |
|
363 | - $selected = in_array( 0, $args['selected'] ); |
|
361 | + if ($args['show_option_all']) { |
|
362 | + if ($args['multiple']) { |
|
363 | + $selected = in_array(0, $args['selected']); |
|
364 | 364 | } else { |
365 | - $selected = empty( $args['selected'] ); |
|
365 | + $selected = empty($args['selected']); |
|
366 | 366 | } |
367 | - echo '<option value="all"' . selected( $selected, true, false ) . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
367 | + echo '<option value="all"' . selected($selected, true, false) . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
368 | 368 | } |
369 | 369 | |
370 | - if ( ! empty( $args['options'] ) ) { |
|
370 | + if (!empty($args['options'])) { |
|
371 | 371 | |
372 | - if ( $args['show_option_none'] ) { |
|
373 | - if ( $args['multiple'] ) { |
|
374 | - $selected = in_array( '', $args['selected'] ); |
|
372 | + if ($args['show_option_none']) { |
|
373 | + if ($args['multiple']) { |
|
374 | + $selected = in_array('', $args['selected']); |
|
375 | 375 | } else { |
376 | 376 | $selected = $args['selected'] === ''; |
377 | 377 | } |
378 | 378 | |
379 | - echo '<option value=""' . selected( $selected, true, false ) . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
379 | + echo '<option value=""' . selected($selected, true, false) . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
380 | 380 | } |
381 | 381 | |
382 | - foreach ( $args['options'] as $key => $option ) { |
|
382 | + foreach ($args['options'] as $key => $option) { |
|
383 | 383 | |
384 | - if ( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
385 | - $selected = in_array( $key, $args['selected'] ); |
|
384 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
385 | + $selected = in_array($key, $args['selected']); |
|
386 | 386 | } else { |
387 | 387 | $selected = $args['selected'] == $key; |
388 | 388 | } |
389 | 389 | |
390 | - echo '<option value="' . esc_attr( $key ) . '"' . selected( $selected, true, false ) . '>' . esc_html( $option ) . '</option>'; |
|
390 | + echo '<option value="' . esc_attr($key) . '"' . selected($selected, true, false) . '>' . esc_html($option) . '</option>'; |
|
391 | 391 | } |
392 | 392 | } |
393 | 393 | |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | |
396 | 396 | } |
397 | 397 | |
398 | -function wpinv_item_dropdown( $args = array() ) { |
|
398 | +function wpinv_item_dropdown($args = array()) { |
|
399 | 399 | $defaults = array( |
400 | 400 | 'name' => 'wpi_item', |
401 | 401 | 'id' => 'wpi_item', |
@@ -403,14 +403,14 @@ discard block |
||
403 | 403 | 'multiple' => false, |
404 | 404 | 'selected' => 0, |
405 | 405 | 'number' => -1, |
406 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
407 | - 'data' => array( 'search-type' => 'item' ), |
|
406 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
407 | + 'data' => array('search-type' => 'item'), |
|
408 | 408 | 'show_option_all' => false, |
409 | 409 | 'show_option_none' => false, |
410 | 410 | 'show_recurring' => false, |
411 | 411 | ); |
412 | 412 | |
413 | - $args = wp_parse_args( $args, $defaults ); |
|
413 | + $args = wp_parse_args($args, $defaults); |
|
414 | 414 | |
415 | 415 | $item_args = array( |
416 | 416 | 'post_type' => 'wpi_item', |
@@ -419,40 +419,40 @@ discard block |
||
419 | 419 | 'posts_per_page' => $args['number'], |
420 | 420 | ); |
421 | 421 | |
422 | - $item_args = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults ); |
|
422 | + $item_args = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults); |
|
423 | 423 | |
424 | - $items = get_posts( $item_args ); |
|
424 | + $items = get_posts($item_args); |
|
425 | 425 | $options = array(); |
426 | - if ( $items ) { |
|
427 | - foreach ( $items as $item ) { |
|
428 | - $title = esc_html( $item->post_title ); |
|
426 | + if ($items) { |
|
427 | + foreach ($items as $item) { |
|
428 | + $title = esc_html($item->post_title); |
|
429 | 429 | |
430 | - if ( ! empty( $args['show_recurring'] ) ) { |
|
431 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
430 | + if (!empty($args['show_recurring'])) { |
|
431 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
432 | 432 | } |
433 | 433 | |
434 | - $options[ absint( $item->ID ) ] = $title; |
|
434 | + $options[absint($item->ID)] = $title; |
|
435 | 435 | } |
436 | 436 | } |
437 | 437 | |
438 | 438 | // This ensures that any selected items are included in the drop down |
439 | - if ( is_array( $args['selected'] ) ) { |
|
440 | - foreach ( $args['selected'] as $item ) { |
|
441 | - if ( ! in_array( $item, $options ) ) { |
|
442 | - $title = get_the_title( $item ); |
|
443 | - if ( ! empty( $args['show_recurring'] ) ) { |
|
444 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
439 | + if (is_array($args['selected'])) { |
|
440 | + foreach ($args['selected'] as $item) { |
|
441 | + if (!in_array($item, $options)) { |
|
442 | + $title = get_the_title($item); |
|
443 | + if (!empty($args['show_recurring'])) { |
|
444 | + $title .= wpinv_get_item_suffix($item, false); |
|
445 | 445 | } |
446 | - $options[ $item ] = $title; |
|
446 | + $options[$item] = $title; |
|
447 | 447 | } |
448 | 448 | } |
449 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
450 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
451 | - $title = get_the_title( $args['selected'] ); |
|
452 | - if ( ! empty( $args['show_recurring'] ) ) { |
|
453 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
449 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
450 | + if (!in_array($args['selected'], $options)) { |
|
451 | + $title = get_the_title($args['selected']); |
|
452 | + if (!empty($args['show_recurring'])) { |
|
453 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
454 | 454 | } |
455 | - $options[ $args['selected'] ] = get_the_title( $args['selected'] ); |
|
455 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
456 | 456 | } |
457 | 457 | } |
458 | 458 | |
@@ -488,16 +488,16 @@ discard block |
||
488 | 488 | ); |
489 | 489 | |
490 | 490 | $options = array(); |
491 | - if ( $items ) { |
|
492 | - foreach ( $items as $item ) { |
|
493 | - $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false ); |
|
491 | + if ($items) { |
|
492 | + foreach ($items as $item) { |
|
493 | + $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false); |
|
494 | 494 | } |
495 | 495 | } |
496 | 496 | |
497 | 497 | return $options; |
498 | 498 | } |
499 | 499 | |
500 | -function wpinv_html_checkbox( $args = array() ) { |
|
500 | +function wpinv_html_checkbox($args = array()) { |
|
501 | 501 | $defaults = array( |
502 | 502 | 'name' => null, |
503 | 503 | 'current' => null, |
@@ -508,17 +508,17 @@ discard block |
||
508 | 508 | ), |
509 | 509 | ); |
510 | 510 | |
511 | - $args = wp_parse_args( $args, $defaults ); |
|
511 | + $args = wp_parse_args($args, $defaults); |
|
512 | 512 | |
513 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
513 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
514 | 514 | $attr = ''; |
515 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
515 | + if (!empty($args['options']['disabled'])) { |
|
516 | 516 | $attr .= ' disabled="disabled"'; |
517 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
517 | + } elseif (!empty($args['options']['readonly'])) { |
|
518 | 518 | $attr .= ' readonly'; |
519 | 519 | } |
520 | 520 | |
521 | - $output = '<input type="checkbox"' . $attr . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . esc_attr( $class ) . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
521 | + $output = '<input type="checkbox"' . $attr . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . esc_attr($class) . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
522 | 522 | |
523 | 523 | return $output; |
524 | 524 | } |
@@ -526,34 +526,34 @@ discard block |
||
526 | 526 | /** |
527 | 527 | * Displays a hidden field. |
528 | 528 | */ |
529 | -function getpaid_hidden_field( $name, $value ) { |
|
530 | - echo "<input type='hidden' name='" . esc_attr( $name ) . "' value=' " . esc_attr( $value ) . "' />"; |
|
529 | +function getpaid_hidden_field($name, $value) { |
|
530 | + echo "<input type='hidden' name='" . esc_attr($name) . "' value=' " . esc_attr($value) . "' />"; |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | /** |
534 | 534 | * Displays a submit field. |
535 | 535 | */ |
536 | -function getpaid_submit_field( $value, $name = 'submit', $class = 'btn-primary' ) { |
|
537 | - echo "<input type='submit' name='" . esc_attr( $name ) . "' value='" . esc_attr( $value ) . "' class='btn " . esc_attr( $class ) . "' />"; |
|
536 | +function getpaid_submit_field($value, $name = 'submit', $class = 'btn-primary') { |
|
537 | + echo "<input type='submit' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' class='btn " . esc_attr($class) . "' />"; |
|
538 | 538 | } |
539 | 539 | |
540 | -function wpinv_html_text( $args = array() ) { |
|
540 | +function wpinv_html_text($args = array()) { |
|
541 | 541 | // Backwards compatibility |
542 | - if ( func_num_args() > 1 ) { |
|
542 | + if (func_num_args() > 1) { |
|
543 | 543 | $args = func_get_args(); |
544 | 544 | |
545 | 545 | $name = $args[0]; |
546 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
547 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
548 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
546 | + $value = isset($args[1]) ? $args[1] : ''; |
|
547 | + $label = isset($args[2]) ? $args[2] : ''; |
|
548 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | $defaults = array( |
552 | 552 | 'id' => '', |
553 | - 'name' => isset( $name ) ? $name : 'text', |
|
554 | - 'value' => isset( $value ) ? $value : null, |
|
555 | - 'label' => isset( $label ) ? $label : null, |
|
556 | - 'desc' => isset( $desc ) ? $desc : null, |
|
553 | + 'name' => isset($name) ? $name : 'text', |
|
554 | + 'value' => isset($value) ? $value : null, |
|
555 | + 'label' => isset($label) ? $label : null, |
|
556 | + 'desc' => isset($desc) ? $desc : null, |
|
557 | 557 | 'placeholder' => '', |
558 | 558 | 'class' => 'regular-text', |
559 | 559 | 'disabled' => false, |
@@ -563,41 +563,41 @@ discard block |
||
563 | 563 | 'data' => false, |
564 | 564 | ); |
565 | 565 | |
566 | - $args = wp_parse_args( $args, $defaults ); |
|
566 | + $args = wp_parse_args($args, $defaults); |
|
567 | 567 | |
568 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
568 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
569 | 569 | $options = ''; |
570 | - if ( $args['required'] ) { |
|
570 | + if ($args['required']) { |
|
571 | 571 | $options .= ' required="required"'; |
572 | 572 | } |
573 | - if ( $args['readonly'] ) { |
|
573 | + if ($args['readonly']) { |
|
574 | 574 | $options .= ' readonly'; |
575 | 575 | } |
576 | - if ( $args['readonly'] ) { |
|
576 | + if ($args['readonly']) { |
|
577 | 577 | $options .= ' readonly'; |
578 | 578 | } |
579 | 579 | |
580 | 580 | $data = ''; |
581 | - if ( ! empty( $args['data'] ) ) { |
|
582 | - foreach ( $args['data'] as $key => $value ) { |
|
583 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
581 | + if (!empty($args['data'])) { |
|
582 | + foreach ($args['data'] as $key => $value) { |
|
583 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
584 | 584 | } |
585 | 585 | } |
586 | 586 | |
587 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
588 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
589 | - if ( ! empty( $args['desc'] ) ) { |
|
590 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
587 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
588 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
589 | + if (!empty($args['desc'])) { |
|
590 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
591 | 591 | } |
592 | 592 | |
593 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
593 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
594 | 594 | |
595 | 595 | $output .= '</span>'; |
596 | 596 | |
597 | 597 | return $output; |
598 | 598 | } |
599 | 599 | |
600 | -function wpinv_html_textarea( $args = array() ) { |
|
600 | +function wpinv_html_textarea($args = array()) { |
|
601 | 601 | $defaults = array( |
602 | 602 | 'name' => 'textarea', |
603 | 603 | 'value' => null, |
@@ -608,31 +608,31 @@ discard block |
||
608 | 608 | 'placeholder' => '', |
609 | 609 | ); |
610 | 610 | |
611 | - $args = wp_parse_args( $args, $defaults ); |
|
611 | + $args = wp_parse_args($args, $defaults); |
|
612 | 612 | |
613 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
613 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
614 | 614 | $disabled = ''; |
615 | - if ( $args['disabled'] ) { |
|
615 | + if ($args['disabled']) { |
|
616 | 616 | $disabled = ' disabled="disabled"'; |
617 | 617 | } |
618 | 618 | |
619 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
620 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
621 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
619 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
620 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
621 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
622 | 622 | |
623 | - if ( ! empty( $args['desc'] ) ) { |
|
624 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
623 | + if (!empty($args['desc'])) { |
|
624 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
625 | 625 | } |
626 | 626 | $output .= '</span>'; |
627 | 627 | |
628 | 628 | return $output; |
629 | 629 | } |
630 | 630 | |
631 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
631 | +function wpinv_html_ajax_user_search($args = array()) { |
|
632 | 632 | $defaults = array( |
633 | 633 | 'name' => 'user_id', |
634 | 634 | 'value' => null, |
635 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
635 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
636 | 636 | 'label' => null, |
637 | 637 | 'desc' => null, |
638 | 638 | 'class' => '', |
@@ -641,13 +641,13 @@ discard block |
||
641 | 641 | 'data' => false, |
642 | 642 | ); |
643 | 643 | |
644 | - $args = wp_parse_args( $args, $defaults ); |
|
644 | + $args = wp_parse_args($args, $defaults); |
|
645 | 645 | |
646 | 646 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
647 | 647 | |
648 | 648 | $output = '<span class="wpinv_user_search_wrap">'; |
649 | - $output .= wpinv_html_text( $args ); |
|
650 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
649 | + $output .= wpinv_html_text($args); |
|
650 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
651 | 651 | $output .= '</span>'; |
652 | 652 | |
653 | 653 | return $output; |
@@ -658,44 +658,44 @@ discard block |
||
658 | 658 | * |
659 | 659 | * @param string $template the template that is currently being used. |
660 | 660 | */ |
661 | -function wpinv_template( $template ) { |
|
661 | +function wpinv_template($template) { |
|
662 | 662 | global $post; |
663 | 663 | |
664 | - if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) { |
|
664 | + if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) { |
|
665 | 665 | |
666 | 666 | // If the user can view this invoice, display it. |
667 | - if ( wpinv_user_can_view_invoice( $post->ID ) ) { |
|
667 | + if (wpinv_user_can_view_invoice($post->ID)) { |
|
668 | 668 | |
669 | - return wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
669 | + return wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
670 | 670 | |
671 | 671 | // Else display an error message. |
672 | 672 | } else { |
673 | 673 | |
674 | - return wpinv_get_template_part( 'wpinv-invalid-access', false, false ); |
|
674 | + return wpinv_get_template_part('wpinv-invalid-access', false, false); |
|
675 | 675 | |
676 | 676 | } |
677 | 677 | } |
678 | 678 | |
679 | 679 | return $template; |
680 | 680 | } |
681 | -add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
681 | +add_filter('template_include', 'wpinv_template', 10, 1); |
|
682 | 682 | |
683 | 683 | function wpinv_get_business_address() { |
684 | 684 | $business_address = wpinv_store_address(); |
685 | - $business_address = ! empty( $business_address ) ? wp_kses_post( wpautop( $business_address ) ) : ''; |
|
685 | + $business_address = !empty($business_address) ? wp_kses_post(wpautop($business_address)) : ''; |
|
686 | 686 | |
687 | 687 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
688 | 688 | |
689 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
689 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
690 | 690 | } |
691 | 691 | |
692 | 692 | /** |
693 | 693 | * Displays the company address. |
694 | 694 | */ |
695 | 695 | function wpinv_display_from_address() { |
696 | - wpinv_get_template( 'invoice/company-address.php' ); |
|
696 | + wpinv_get_template('invoice/company-address.php'); |
|
697 | 697 | } |
698 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 ); |
|
698 | +add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10); |
|
699 | 699 | |
700 | 700 | /** |
701 | 701 | * Generates a watermark text for an invoice. |
@@ -703,9 +703,9 @@ discard block |
||
703 | 703 | * @param WPInv_Invoice $invoice |
704 | 704 | * @return string |
705 | 705 | */ |
706 | -function wpinv_watermark( $invoice ) { |
|
707 | - $watermark = wpinv_get_watermark( $invoice ); |
|
708 | - return apply_filters( 'wpinv_get_watermark', $watermark, $invoice ); |
|
706 | +function wpinv_watermark($invoice) { |
|
707 | + $watermark = wpinv_get_watermark($invoice); |
|
708 | + return apply_filters('wpinv_get_watermark', $watermark, $invoice); |
|
709 | 709 | } |
710 | 710 | |
711 | 711 | /** |
@@ -714,37 +714,37 @@ discard block |
||
714 | 714 | * @param WPInv_Invoice $invoice |
715 | 715 | * @return string |
716 | 716 | */ |
717 | -function wpinv_get_watermark( $invoice ) { |
|
717 | +function wpinv_get_watermark($invoice) { |
|
718 | 718 | return $invoice->get_status_nicename(); |
719 | 719 | } |
720 | 720 | |
721 | 721 | /** |
722 | 722 | * @deprecated |
723 | 723 | */ |
724 | -function wpinv_display_invoice_details( $invoice ) { |
|
725 | - return getpaid_invoice_meta( $invoice ); |
|
724 | +function wpinv_display_invoice_details($invoice) { |
|
725 | + return getpaid_invoice_meta($invoice); |
|
726 | 726 | } |
727 | 727 | |
728 | 728 | /** |
729 | 729 | * Displays invoice meta. |
730 | 730 | */ |
731 | -function getpaid_invoice_meta( $invoice ) { |
|
731 | +function getpaid_invoice_meta($invoice) { |
|
732 | 732 | |
733 | - $invoice = new WPInv_Invoice( $invoice ); |
|
733 | + $invoice = new WPInv_Invoice($invoice); |
|
734 | 734 | |
735 | 735 | // Ensure that we have an invoice. |
736 | - if ( 0 == $invoice->get_id() ) { |
|
736 | + if (0 == $invoice->get_id()) { |
|
737 | 737 | return; |
738 | 738 | } |
739 | 739 | |
740 | 740 | // Get the invoice meta. |
741 | - $meta = getpaid_get_invoice_meta( $invoice ); |
|
741 | + $meta = getpaid_get_invoice_meta($invoice); |
|
742 | 742 | |
743 | 743 | // Display the meta. |
744 | - wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) ); |
|
744 | + wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta')); |
|
745 | 745 | |
746 | 746 | } |
747 | -add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 ); |
|
747 | +add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10); |
|
748 | 748 | |
749 | 749 | /** |
750 | 750 | * Retrieves the address markup to use on Invoices. |
@@ -756,29 +756,29 @@ discard block |
||
756 | 756 | * @param string $separator How to separate address lines. |
757 | 757 | * @return string |
758 | 758 | */ |
759 | -function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) { |
|
759 | +function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') { |
|
760 | 760 | |
761 | 761 | // Retrieve the address markup... |
762 | - $country = empty( $billing_details['country'] ) ? '' : $billing_details['country']; |
|
763 | - $format = wpinv_get_full_address_format( $country ); |
|
762 | + $country = empty($billing_details['country']) ? '' : $billing_details['country']; |
|
763 | + $format = wpinv_get_full_address_format($country); |
|
764 | 764 | |
765 | 765 | // ... and the replacements. |
766 | - $replacements = wpinv_get_invoice_address_replacements( $billing_details ); |
|
766 | + $replacements = wpinv_get_invoice_address_replacements($billing_details); |
|
767 | 767 | |
768 | - $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
|
768 | + $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format); |
|
769 | 769 | |
770 | 770 | // Remove unavailable tags. |
771 | - $formatted_address = preg_replace( '/\{\{\w+\}\}/', '', $formatted_address ); |
|
771 | + $formatted_address = preg_replace('/\{\{\w+\}\}/', '', $formatted_address); |
|
772 | 772 | |
773 | 773 | // Clean up white space. |
774 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
775 | - $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
|
774 | + $formatted_address = preg_replace('/ +/', ' ', trim($formatted_address)); |
|
775 | + $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address); |
|
776 | 776 | |
777 | 777 | // Break newlines apart and remove empty lines/trim commas and white space. |
778 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
778 | + $formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address))); |
|
779 | 779 | |
780 | 780 | // Add html breaks. |
781 | - $formatted_address = implode( $separator, $formatted_address ); |
|
781 | + $formatted_address = implode($separator, $formatted_address); |
|
782 | 782 | |
783 | 783 | // We're done! |
784 | 784 | return $formatted_address; |
@@ -790,118 +790,118 @@ discard block |
||
790 | 790 | * |
791 | 791 | * @param WPInv_Invoice $invoice |
792 | 792 | */ |
793 | -function wpinv_display_to_address( $invoice = 0 ) { |
|
794 | - if ( ! empty( $invoice ) ) { |
|
795 | - wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) ); |
|
793 | +function wpinv_display_to_address($invoice = 0) { |
|
794 | + if (!empty($invoice)) { |
|
795 | + wpinv_get_template('invoice/billing-address.php', compact('invoice')); |
|
796 | 796 | } |
797 | 797 | } |
798 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 ); |
|
798 | +add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40); |
|
799 | 799 | |
800 | 800 | |
801 | 801 | /** |
802 | 802 | * Displays invoice line items. |
803 | 803 | */ |
804 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
804 | +function wpinv_display_line_items($invoice_id = 0) { |
|
805 | 805 | |
806 | 806 | // Prepare the invoice. |
807 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
807 | + $invoice = new WPInv_Invoice($invoice_id); |
|
808 | 808 | |
809 | 809 | // Abort if there is no invoice. |
810 | - if ( 0 == $invoice->get_id() ) { |
|
810 | + if (0 == $invoice->get_id()) { |
|
811 | 811 | return; |
812 | 812 | } |
813 | 813 | |
814 | 814 | // Line item columns. |
815 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
816 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
815 | + $columns = getpaid_invoice_item_columns($invoice); |
|
816 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
817 | 817 | |
818 | - wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) ); |
|
818 | + wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns')); |
|
819 | 819 | } |
820 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 ); |
|
820 | +add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10); |
|
821 | 821 | |
822 | 822 | /** |
823 | 823 | * Displays invoice subscriptions. |
824 | 824 | * |
825 | 825 | * @param WPInv_Invoice $invoice |
826 | 826 | */ |
827 | -function getpaid_display_invoice_subscriptions( $invoice ) { |
|
827 | +function getpaid_display_invoice_subscriptions($invoice) { |
|
828 | 828 | |
829 | 829 | // Subscriptions. |
830 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
830 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
831 | 831 | |
832 | - if ( empty( $subscriptions ) || ! $invoice->is_recurring() ) { |
|
832 | + if (empty($subscriptions) || !$invoice->is_recurring()) { |
|
833 | 833 | return; |
834 | 834 | } |
835 | 835 | |
836 | - $main_subscription = getpaid_get_invoice_subscription( $invoice ); |
|
836 | + $main_subscription = getpaid_get_invoice_subscription($invoice); |
|
837 | 837 | |
838 | 838 | // Display related subscriptions. |
839 | - if ( is_array( $subscriptions ) ) { |
|
840 | - printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Subscriptions', 'invoicing' ) ); |
|
841 | - getpaid_admin_subscription_related_subscriptions_metabox( $main_subscription, false ); |
|
839 | + if (is_array($subscriptions)) { |
|
840 | + printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Subscriptions', 'invoicing')); |
|
841 | + getpaid_admin_subscription_related_subscriptions_metabox($main_subscription, false); |
|
842 | 842 | } |
843 | 843 | |
844 | - if ( $main_subscription->get_total_payments() > 1 ) { |
|
845 | - printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Invoices', 'invoicing' ) ); |
|
846 | - getpaid_admin_subscription_invoice_details_metabox( $main_subscription, false ); |
|
844 | + if ($main_subscription->get_total_payments() > 1) { |
|
845 | + printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Invoices', 'invoicing')); |
|
846 | + getpaid_admin_subscription_invoice_details_metabox($main_subscription, false); |
|
847 | 847 | } |
848 | 848 | |
849 | 849 | } |
850 | -add_action( 'getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 55 ); |
|
851 | -add_action( 'wpinv_receipt_end', 'getpaid_display_invoice_subscriptions', 11 ); |
|
850 | +add_action('getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 55); |
|
851 | +add_action('wpinv_receipt_end', 'getpaid_display_invoice_subscriptions', 11); |
|
852 | 852 | |
853 | 853 | /** |
854 | 854 | * Displays invoice notices on invoices. |
855 | 855 | */ |
856 | 856 | function wpinv_display_invoice_notice() { |
857 | 857 | |
858 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
859 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
858 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
859 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
860 | 860 | |
861 | - if ( empty( $label ) && empty( $notice ) ) { |
|
861 | + if (empty($label) && empty($notice)) { |
|
862 | 862 | return; |
863 | 863 | } |
864 | 864 | |
865 | 865 | echo '<div class="mt-4 mb-4 wpinv-vat-notice">'; |
866 | 866 | |
867 | - if ( ! empty( $label ) ) { |
|
868 | - echo "<h5>" . esc_html( $label ) . "</h5>"; |
|
867 | + if (!empty($label)) { |
|
868 | + echo "<h5>" . esc_html($label) . "</h5>"; |
|
869 | 869 | } |
870 | 870 | |
871 | - if ( ! empty( $notice ) ) { |
|
872 | - echo '<small class="form-text text-muted">' . wp_kses_post( wpautop( wptexturize( $notice ) ) ) . '</small>'; |
|
871 | + if (!empty($notice)) { |
|
872 | + echo '<small class="form-text text-muted">' . wp_kses_post(wpautop(wptexturize($notice))) . '</small>'; |
|
873 | 873 | } |
874 | 874 | |
875 | 875 | echo '</div>'; |
876 | 876 | } |
877 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 ); |
|
877 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100); |
|
878 | 878 | |
879 | 879 | /** |
880 | 880 | * @param WPInv_Invoice $invoice |
881 | 881 | */ |
882 | -function wpinv_display_invoice_notes( $invoice ) { |
|
882 | +function wpinv_display_invoice_notes($invoice) { |
|
883 | 883 | |
884 | 884 | // Retrieve the notes. |
885 | - $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' ); |
|
885 | + $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer'); |
|
886 | 886 | |
887 | 887 | // Abort if we have non. |
888 | - if ( empty( $notes ) ) { |
|
888 | + if (empty($notes)) { |
|
889 | 889 | return; |
890 | 890 | } |
891 | 891 | |
892 | 892 | // Echo the note. |
893 | 893 | echo '<div class="getpaid-invoice-notes-wrapper position-relative my-4">'; |
894 | - echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . esc_html__( 'Notes', 'invoicing' ) . '</h2>'; |
|
894 | + echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . esc_html__('Notes', 'invoicing') . '</h2>'; |
|
895 | 895 | echo '<ul class="getpaid-invoice-notes text-break overflow-auto list-unstyled p-0 m-0">'; |
896 | 896 | |
897 | - foreach ( $notes as $note ) { |
|
898 | - wpinv_get_invoice_note_line_item( $note ); |
|
897 | + foreach ($notes as $note) { |
|
898 | + wpinv_get_invoice_note_line_item($note); |
|
899 | 899 | } |
900 | 900 | |
901 | 901 | echo '</ul>'; |
902 | 902 | echo '</div>'; |
903 | 903 | } |
904 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 ); |
|
904 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60); |
|
905 | 905 | |
906 | 906 | /** |
907 | 907 | * Loads scripts on our invoice templates. |
@@ -909,32 +909,32 @@ discard block |
||
909 | 909 | function wpinv_display_style() { |
910 | 910 | |
911 | 911 | // Make sure that all scripts have been loaded. |
912 | - if ( ! did_action( 'wp_enqueue_scripts' ) ) { |
|
913 | - do_action( 'wp_enqueue_scripts' ); |
|
912 | + if (!did_action('wp_enqueue_scripts')) { |
|
913 | + do_action('wp_enqueue_scripts'); |
|
914 | 914 | } |
915 | 915 | |
916 | 916 | // Register the invoices style. |
917 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) ); |
|
917 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css')); |
|
918 | 918 | |
919 | 919 | // Load required styles |
920 | - wp_print_styles( 'wpinv-single-style' ); |
|
921 | - wp_print_styles( 'ayecode-ui' ); |
|
920 | + wp_print_styles('wpinv-single-style'); |
|
921 | + wp_print_styles('ayecode-ui'); |
|
922 | 922 | |
923 | 923 | // Maybe load custom css. |
924 | - $custom_css = wpinv_get_option( 'template_custom_css' ); |
|
924 | + $custom_css = wpinv_get_option('template_custom_css'); |
|
925 | 925 | |
926 | - if ( isset( $custom_css ) && ! empty( $custom_css ) ) { |
|
927 | - $custom_css = wp_kses( $custom_css, array( '\'', '\"' ) ); |
|
928 | - $custom_css = str_replace( '>', '>', $custom_css ); |
|
926 | + if (isset($custom_css) && !empty($custom_css)) { |
|
927 | + $custom_css = wp_kses($custom_css, array('\'', '\"')); |
|
928 | + $custom_css = str_replace('>', '>', $custom_css); |
|
929 | 929 | echo '<style type="text/css">'; |
930 | - echo wp_kses_post( $custom_css ); |
|
930 | + echo wp_kses_post($custom_css); |
|
931 | 931 | echo '</style>'; |
932 | 932 | } |
933 | 933 | |
934 | 934 | wp_site_icon(); |
935 | 935 | } |
936 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
937 | -add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' ); |
|
936 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
937 | +add_action('wpinv_invalid_invoice_head', 'wpinv_display_style'); |
|
938 | 938 | |
939 | 939 | |
940 | 940 | /** |
@@ -946,41 +946,41 @@ discard block |
||
946 | 946 | // Retrieve the current invoice. |
947 | 947 | $invoice_id = getpaid_get_current_invoice_id(); |
948 | 948 | |
949 | - if ( empty( $invoice_id ) ) { |
|
949 | + if (empty($invoice_id)) { |
|
950 | 950 | |
951 | 951 | return aui()->alert( |
952 | 952 | array( |
953 | 953 | 'type' => 'warning', |
954 | - 'content' => __( 'Invalid invoice', 'invoicing' ), |
|
954 | + 'content' => __('Invalid invoice', 'invoicing'), |
|
955 | 955 | ) |
956 | 956 | ); |
957 | 957 | |
958 | 958 | } |
959 | 959 | |
960 | 960 | // Can the user view this invoice? |
961 | - if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) { |
|
961 | + if (!wpinv_user_can_view_invoice($invoice_id)) { |
|
962 | 962 | |
963 | 963 | return aui()->alert( |
964 | 964 | array( |
965 | 965 | 'type' => 'warning', |
966 | - 'content' => __( 'You are not allowed to view this invoice', 'invoicing' ), |
|
966 | + 'content' => __('You are not allowed to view this invoice', 'invoicing'), |
|
967 | 967 | ) |
968 | 968 | ); |
969 | 969 | |
970 | 970 | } |
971 | 971 | |
972 | 972 | // Ensure that it is not yet paid for. |
973 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
973 | + $invoice = new WPInv_Invoice($invoice_id); |
|
974 | 974 | |
975 | 975 | // Maybe mark it as viewed. |
976 | - getpaid_maybe_mark_invoice_as_viewed( $invoice ); |
|
976 | + getpaid_maybe_mark_invoice_as_viewed($invoice); |
|
977 | 977 | |
978 | - if ( $invoice->is_paid() ) { |
|
978 | + if ($invoice->is_paid()) { |
|
979 | 979 | |
980 | 980 | return aui()->alert( |
981 | 981 | array( |
982 | 982 | 'type' => 'success', |
983 | - 'content' => __( 'This invoice has already been paid.', 'invoicing' ), |
|
983 | + 'content' => __('This invoice has already been paid.', 'invoicing'), |
|
984 | 984 | ) |
985 | 985 | ); |
986 | 986 | |
@@ -990,15 +990,15 @@ discard block |
||
990 | 990 | $wpi_checkout_id = $invoice_id; |
991 | 991 | |
992 | 992 | // Retrieve appropriate payment form. |
993 | - $payment_form = new GetPaid_Payment_Form( $invoice->get_meta( 'force_payment_form' ) ); |
|
994 | - $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
993 | + $payment_form = new GetPaid_Payment_Form($invoice->get_meta('force_payment_form')); |
|
994 | + $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
995 | 995 | |
996 | - if ( ! $payment_form->exists() ) { |
|
996 | + if (!$payment_form->exists()) { |
|
997 | 997 | |
998 | 998 | return aui()->alert( |
999 | 999 | array( |
1000 | 1000 | 'type' => 'warning', |
1001 | - 'content' => __( 'Error loading the payment form', 'invoicing' ), |
|
1001 | + 'content' => __('Error loading the payment form', 'invoicing'), |
|
1002 | 1002 | ) |
1003 | 1003 | ); |
1004 | 1004 | |
@@ -1007,29 +1007,29 @@ discard block |
||
1007 | 1007 | // Set the invoice. |
1008 | 1008 | $payment_form->invoice = $invoice; |
1009 | 1009 | |
1010 | - if ( ! $payment_form->is_default() ) { |
|
1010 | + if (!$payment_form->is_default()) { |
|
1011 | 1011 | |
1012 | 1012 | $items = array(); |
1013 | 1013 | $item_ids = array(); |
1014 | 1014 | |
1015 | - foreach ( $invoice->get_items() as $item ) { |
|
1016 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
1015 | + foreach ($invoice->get_items() as $item) { |
|
1016 | + if (!in_array($item->get_id(), $item_ids)) { |
|
1017 | 1017 | $item_ids[] = $item->get_id(); |
1018 | 1018 | $items[] = $item; |
1019 | 1019 | } |
1020 | 1020 | } |
1021 | 1021 | |
1022 | - foreach ( $payment_form->get_items() as $item ) { |
|
1023 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
1022 | + foreach ($payment_form->get_items() as $item) { |
|
1023 | + if (!in_array($item->get_id(), $item_ids)) { |
|
1024 | 1024 | $item_ids[] = $item->get_id(); |
1025 | 1025 | $items[] = $item; |
1026 | 1026 | } |
1027 | 1027 | } |
1028 | 1028 | |
1029 | - $payment_form->set_items( $items ); |
|
1029 | + $payment_form->set_items($items); |
|
1030 | 1030 | |
1031 | 1031 | } else { |
1032 | - $payment_form->set_items( $invoice->get_items() ); |
|
1032 | + $payment_form->set_items($invoice->get_items()); |
|
1033 | 1033 | } |
1034 | 1034 | |
1035 | 1035 | // Generate the html. |
@@ -1038,7 +1038,7 @@ discard block |
||
1038 | 1038 | } |
1039 | 1039 | |
1040 | 1040 | function wpinv_empty_cart_message() { |
1041 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1041 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1042 | 1042 | } |
1043 | 1043 | |
1044 | 1044 | /** |
@@ -1056,76 +1056,76 @@ discard block |
||
1056 | 1056 | true |
1057 | 1057 | ); |
1058 | 1058 | } |
1059 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1059 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1060 | 1060 | |
1061 | 1061 | /** |
1062 | 1062 | * Filters the receipt page. |
1063 | 1063 | */ |
1064 | -function wpinv_filter_success_page_content( $content ) { |
|
1064 | +function wpinv_filter_success_page_content($content) { |
|
1065 | 1065 | |
1066 | 1066 | // Maybe abort early. |
1067 | - if ( is_admin() || ! is_singular() || ! in_the_loop() || ! is_main_query() || is_preview() ) { |
|
1067 | + if (is_admin() || !is_singular() || !in_the_loop() || !is_main_query() || is_preview()) { |
|
1068 | 1068 | return $content; |
1069 | 1069 | } |
1070 | 1070 | |
1071 | 1071 | // Ensure this is our page. |
1072 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1072 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1073 | 1073 | |
1074 | - $gateway = sanitize_text_field( $_GET['payment-confirm'] ); |
|
1075 | - return apply_filters( "wpinv_payment_confirm_$gateway", $content ); |
|
1074 | + $gateway = sanitize_text_field($_GET['payment-confirm']); |
|
1075 | + return apply_filters("wpinv_payment_confirm_$gateway", $content); |
|
1076 | 1076 | |
1077 | 1077 | } |
1078 | 1078 | |
1079 | 1079 | return $content; |
1080 | 1080 | } |
1081 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1081 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1082 | 1082 | |
1083 | -function wpinv_invoice_link( $invoice_id ) { |
|
1084 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1083 | +function wpinv_invoice_link($invoice_id) { |
|
1084 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1085 | 1085 | |
1086 | - if ( empty( $invoice ) ) { |
|
1086 | + if (empty($invoice)) { |
|
1087 | 1087 | return null; |
1088 | 1088 | } |
1089 | 1089 | |
1090 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1090 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1091 | 1091 | |
1092 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1092 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1093 | 1093 | } |
1094 | 1094 | |
1095 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
1096 | - if ( empty( $note ) ) { |
|
1095 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
1096 | + if (empty($note)) { |
|
1097 | 1097 | return null; |
1098 | 1098 | } |
1099 | 1099 | |
1100 | - if ( is_int( $note ) ) { |
|
1101 | - $note = get_comment( $note ); |
|
1100 | + if (is_int($note)) { |
|
1101 | + $note = get_comment($note); |
|
1102 | 1102 | } |
1103 | 1103 | |
1104 | - if ( ! ( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
1104 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
1105 | 1105 | return null; |
1106 | 1106 | } |
1107 | 1107 | |
1108 | - $note_classes = array( 'note' ); |
|
1109 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
1108 | + $note_classes = array('note'); |
|
1109 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
1110 | 1110 | $note_classes[] = $note->comment_author === 'System' ? 'system-note' : ''; |
1111 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
1112 | - $note_classes = ! empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
1111 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
1112 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
1113 | 1113 | |
1114 | 1114 | ob_start(); |
1115 | 1115 | ?> |
1116 | - <li rel="<?php echo absint( $note->comment_ID ); ?>" class="<?php echo esc_attr( $note_classes ); ?> mb-2"> |
|
1116 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mb-2"> |
|
1117 | 1117 | <div class="note_content"> |
1118 | 1118 | |
1119 | - <?php echo wp_kses_post( wptexturize( $note->comment_content ) ); ?> |
|
1119 | + <?php echo wp_kses_post(wptexturize($note->comment_content)); ?> |
|
1120 | 1120 | |
1121 | - <?php if ( ! is_admin() ) : ?> |
|
1121 | + <?php if (!is_admin()) : ?> |
|
1122 | 1122 | <em class="small form-text text-muted mt-0"> |
1123 | 1123 | <?php |
1124 | 1124 | printf( |
1125 | - esc_html__( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1126 | - esc_html( $note->comment_author ), |
|
1127 | - esc_html( getpaid_format_date_value( $note->comment_date ) ), |
|
1128 | - esc_html( date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ) |
|
1125 | + esc_html__('%1$s - %2$s at %3$s', 'invoicing'), |
|
1126 | + esc_html($note->comment_author), |
|
1127 | + esc_html(getpaid_format_date_value($note->comment_date)), |
|
1128 | + esc_html(date_i18n(get_option('time_format'), strtotime($note->comment_date))) |
|
1129 | 1129 | ); |
1130 | 1130 | ?> |
1131 | 1131 | </em> |
@@ -1133,21 +1133,21 @@ discard block |
||
1133 | 1133 | |
1134 | 1134 | </div> |
1135 | 1135 | |
1136 | - <?php if ( is_admin() ) : ?> |
|
1136 | + <?php if (is_admin()) : ?> |
|
1137 | 1137 | |
1138 | 1138 | <p class="meta px-4 py-2"> |
1139 | - <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>"> |
|
1139 | + <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>"> |
|
1140 | 1140 | <?php |
1141 | 1141 | printf( |
1142 | - esc_html__( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1143 | - esc_html( $note->comment_author ), |
|
1144 | - esc_html( getpaid_format_date_value( $note->comment_date ) ), |
|
1145 | - esc_html( date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ) |
|
1142 | + esc_html__('%1$s - %2$s at %3$s', 'invoicing'), |
|
1143 | + esc_html($note->comment_author), |
|
1144 | + esc_html(getpaid_format_date_value($note->comment_date)), |
|
1145 | + esc_html(date_i18n(get_option('time_format'), strtotime($note->comment_date))) |
|
1146 | 1146 | ); |
1147 | 1147 | ?> |
1148 | 1148 | </abbr> |
1149 | - <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?> |
|
1150 | - <a href="#" class="delete_note"><?php esc_html_e( 'Delete note', 'invoicing' ); ?></a> |
|
1149 | + <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?> |
|
1150 | + <a href="#" class="delete_note"><?php esc_html_e('Delete note', 'invoicing'); ?></a> |
|
1151 | 1151 | <?php } ?> |
1152 | 1152 | </p> |
1153 | 1153 | |
@@ -1156,10 +1156,10 @@ discard block |
||
1156 | 1156 | </li> |
1157 | 1157 | <?php |
1158 | 1158 | $note_content = ob_get_clean(); |
1159 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
1159 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
1160 | 1160 | |
1161 | - if ( $echo ) { |
|
1162 | - echo wp_kses_post( $note_content ); |
|
1161 | + if ($echo) { |
|
1162 | + echo wp_kses_post($note_content); |
|
1163 | 1163 | } else { |
1164 | 1164 | return $note_content; |
1165 | 1165 | } |
@@ -1172,43 +1172,43 @@ discard block |
||
1172 | 1172 | * @return string |
1173 | 1173 | */ |
1174 | 1174 | function wpinv_get_policy_text() { |
1175 | - $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 ); |
|
1175 | + $privacy_page_id = get_option('wp_page_for_privacy_policy', 0); |
|
1176 | 1176 | |
1177 | - $text = wpinv_get_option( 'invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ) ); |
|
1177 | + $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]')); |
|
1178 | 1178 | |
1179 | - if ( ! $privacy_page_id ) { |
|
1180 | - $privacy_page_id = wpinv_get_option( 'privacy_page', 0 ); |
|
1179 | + if (!$privacy_page_id) { |
|
1180 | + $privacy_page_id = wpinv_get_option('privacy_page', 0); |
|
1181 | 1181 | } |
1182 | 1182 | |
1183 | - $privacy_link = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' ); |
|
1183 | + $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing'); |
|
1184 | 1184 | |
1185 | 1185 | $find_replace = array( |
1186 | 1186 | '[wpinv_privacy_policy]' => $privacy_link, |
1187 | 1187 | ); |
1188 | 1188 | |
1189 | - $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text ); |
|
1189 | + $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text); |
|
1190 | 1190 | |
1191 | - return wp_kses_post( wpautop( $privacy_text ) ); |
|
1191 | + return wp_kses_post(wpautop($privacy_text)); |
|
1192 | 1192 | } |
1193 | 1193 | |
1194 | 1194 | function wpinv_oxygen_fix_conflict() { |
1195 | 1195 | global $ct_ignore_post_types; |
1196 | 1196 | |
1197 | - if ( ! is_array( $ct_ignore_post_types ) ) { |
|
1197 | + if (!is_array($ct_ignore_post_types)) { |
|
1198 | 1198 | $ct_ignore_post_types = array(); |
1199 | 1199 | } |
1200 | 1200 | |
1201 | - $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form' ); |
|
1201 | + $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form'); |
|
1202 | 1202 | |
1203 | - foreach ( $post_types as $post_type ) { |
|
1203 | + foreach ($post_types as $post_type) { |
|
1204 | 1204 | $ct_ignore_post_types[] = $post_type; |
1205 | 1205 | |
1206 | 1206 | // Ignore post type |
1207 | - add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 ); |
|
1207 | + add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999); |
|
1208 | 1208 | } |
1209 | 1209 | |
1210 | - remove_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
1211 | - add_filter( 'template_include', 'wpinv_template', 999, 1 ); |
|
1210 | + remove_filter('template_include', 'wpinv_template', 10, 1); |
|
1211 | + add_filter('template_include', 'wpinv_template', 999, 1); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | /** |
@@ -1216,10 +1216,10 @@ discard block |
||
1216 | 1216 | * |
1217 | 1217 | * @param GetPaid_Payment_Form $form |
1218 | 1218 | */ |
1219 | -function getpaid_display_payment_form( $form ) { |
|
1219 | +function getpaid_display_payment_form($form) { |
|
1220 | 1220 | |
1221 | - if ( is_numeric( $form ) ) { |
|
1222 | - $form = new GetPaid_Payment_Form( $form ); |
|
1221 | + if (is_numeric($form)) { |
|
1222 | + $form = new GetPaid_Payment_Form($form); |
|
1223 | 1223 | } |
1224 | 1224 | |
1225 | 1225 | $form->display(); |
@@ -1229,61 +1229,61 @@ discard block |
||
1229 | 1229 | /** |
1230 | 1230 | * Helper function to display a item payment form on the frontend. |
1231 | 1231 | */ |
1232 | -function getpaid_display_item_payment_form( $items ) { |
|
1232 | +function getpaid_display_item_payment_form($items) { |
|
1233 | 1233 | |
1234 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1235 | - $form->set_items( $items ); |
|
1234 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1235 | + $form->set_items($items); |
|
1236 | 1236 | |
1237 | - if ( 0 == count( $form->get_items() ) ) { |
|
1237 | + if (0 == count($form->get_items())) { |
|
1238 | 1238 | aui()->alert( |
1239 | 1239 | array( |
1240 | 1240 | 'type' => 'warning', |
1241 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1241 | + 'content' => __('No published items found', 'invoicing'), |
|
1242 | 1242 | ), |
1243 | 1243 | true |
1244 | 1244 | ); |
1245 | 1245 | return; |
1246 | 1246 | } |
1247 | 1247 | |
1248 | - $extra_items = esc_attr( getpaid_convert_items_to_string( $items ) ); |
|
1249 | - $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items ); |
|
1248 | + $extra_items = esc_attr(getpaid_convert_items_to_string($items)); |
|
1249 | + $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items); |
|
1250 | 1250 | $extra_items = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />"; |
1251 | 1251 | $extra_items .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />"; |
1252 | 1252 | |
1253 | - $form->display( $extra_items ); |
|
1253 | + $form->display($extra_items); |
|
1254 | 1254 | } |
1255 | 1255 | |
1256 | 1256 | /** |
1257 | 1257 | * Helper function to display an invoice payment form on the frontend. |
1258 | 1258 | */ |
1259 | -function getpaid_display_invoice_payment_form( $invoice_id ) { |
|
1259 | +function getpaid_display_invoice_payment_form($invoice_id) { |
|
1260 | 1260 | |
1261 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1261 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1262 | 1262 | |
1263 | - if ( empty( $invoice ) ) { |
|
1263 | + if (empty($invoice)) { |
|
1264 | 1264 | aui()->alert( |
1265 | 1265 | array( |
1266 | 1266 | 'type' => 'warning', |
1267 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1267 | + 'content' => __('Invoice not found', 'invoicing'), |
|
1268 | 1268 | ), |
1269 | 1269 | true |
1270 | 1270 | ); |
1271 | 1271 | return; |
1272 | 1272 | } |
1273 | 1273 | |
1274 | - if ( $invoice->is_paid() ) { |
|
1274 | + if ($invoice->is_paid()) { |
|
1275 | 1275 | aui()->alert( |
1276 | 1276 | array( |
1277 | 1277 | 'type' => 'warning', |
1278 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1278 | + 'content' => __('Invoice has already been paid', 'invoicing'), |
|
1279 | 1279 | ), |
1280 | 1280 | true |
1281 | 1281 | ); |
1282 | 1282 | return; |
1283 | 1283 | } |
1284 | 1284 | |
1285 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1286 | - $form->set_items( $invoice->get_items() ); |
|
1285 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1286 | + $form->set_items($invoice->get_items()); |
|
1287 | 1287 | |
1288 | 1288 | $form->display(); |
1289 | 1289 | } |
@@ -1291,23 +1291,23 @@ discard block |
||
1291 | 1291 | /** |
1292 | 1292 | * Helper function to convert item string to array. |
1293 | 1293 | */ |
1294 | -function getpaid_convert_items_to_array( $items ) { |
|
1295 | - $items = array_filter( array_map( 'trim', explode( ',', $items ) ) ); |
|
1294 | +function getpaid_convert_items_to_array($items) { |
|
1295 | + $items = array_filter(array_map('trim', explode(',', $items))); |
|
1296 | 1296 | $prepared = array(); |
1297 | 1297 | |
1298 | - foreach ( $items as $item ) { |
|
1299 | - $data = array_map( 'trim', explode( '|', $item ) ); |
|
1298 | + foreach ($items as $item) { |
|
1299 | + $data = array_map('trim', explode('|', $item)); |
|
1300 | 1300 | |
1301 | - if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) { |
|
1301 | + if (empty($data[0]) || !is_numeric($data[0])) { |
|
1302 | 1302 | continue; |
1303 | 1303 | } |
1304 | 1304 | |
1305 | 1305 | $quantity = 1; |
1306 | - if ( isset( $data[1] ) && is_numeric( $data[1] ) ) { |
|
1306 | + if (isset($data[1]) && is_numeric($data[1])) { |
|
1307 | 1307 | $quantity = (float) $data[1]; |
1308 | 1308 | } |
1309 | 1309 | |
1310 | - $prepared[ $data[0] ] = $quantity; |
|
1310 | + $prepared[$data[0]] = $quantity; |
|
1311 | 1311 | |
1312 | 1312 | } |
1313 | 1313 | |
@@ -1317,13 +1317,13 @@ discard block |
||
1317 | 1317 | /** |
1318 | 1318 | * Helper function to convert item array to string. |
1319 | 1319 | */ |
1320 | -function getpaid_convert_items_to_string( $items ) { |
|
1320 | +function getpaid_convert_items_to_string($items) { |
|
1321 | 1321 | $prepared = array(); |
1322 | 1322 | |
1323 | - foreach ( $items as $item => $quantity ) { |
|
1323 | + foreach ($items as $item => $quantity) { |
|
1324 | 1324 | $prepared[] = "$item|$quantity"; |
1325 | 1325 | } |
1326 | - return implode( ',', $prepared ); |
|
1326 | + return implode(',', $prepared); |
|
1327 | 1327 | } |
1328 | 1328 | |
1329 | 1329 | /** |
@@ -1331,21 +1331,21 @@ discard block |
||
1331 | 1331 | * |
1332 | 1332 | * Provide a label and one of $form, $items or $invoice. |
1333 | 1333 | */ |
1334 | -function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) { |
|
1335 | - $label = sanitize_text_field( $label ); |
|
1334 | +function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) { |
|
1335 | + $label = sanitize_text_field($label); |
|
1336 | 1336 | |
1337 | - if ( ! empty( $form ) ) { |
|
1338 | - $form = esc_attr( $form ); |
|
1337 | + if (!empty($form)) { |
|
1338 | + $form = esc_attr($form); |
|
1339 | 1339 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; |
1340 | 1340 | } |
1341 | 1341 | |
1342 | - if ( ! empty( $items ) ) { |
|
1343 | - $items = esc_attr( $items ); |
|
1342 | + if (!empty($items)) { |
|
1343 | + $items = esc_attr($items); |
|
1344 | 1344 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; |
1345 | 1345 | } |
1346 | 1346 | |
1347 | - if ( ! empty( $invoice ) ) { |
|
1348 | - $invoice = esc_attr( $invoice ); |
|
1347 | + if (!empty($invoice)) { |
|
1348 | + $invoice = esc_attr($invoice); |
|
1349 | 1349 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-invoice='$invoice'>$label</button>"; |
1350 | 1350 | } |
1351 | 1351 | |
@@ -1356,17 +1356,17 @@ discard block |
||
1356 | 1356 | * |
1357 | 1357 | * @param WPInv_Invoice $invoice |
1358 | 1358 | */ |
1359 | -function getpaid_the_invoice_description( $invoice ) { |
|
1359 | +function getpaid_the_invoice_description($invoice) { |
|
1360 | 1360 | $description = $invoice->get_description(); |
1361 | 1361 | |
1362 | - if ( empty( $description ) ) { |
|
1362 | + if (empty($description)) { |
|
1363 | 1363 | return; |
1364 | 1364 | } |
1365 | 1365 | |
1366 | - echo "<small class='getpaid-invoice-description text-dark p-2 form-text' style='margin-bottom: 20px; border-left: 2px solid #2196F3;'><em>" . wp_kses_post( wpautop( $description ) ) . "</em></small>"; |
|
1366 | + echo "<small class='getpaid-invoice-description text-dark p-2 form-text' style='margin-bottom: 20px; border-left: 2px solid #2196F3;'><em>" . wp_kses_post(wpautop($description)) . "</em></small>"; |
|
1367 | 1367 | } |
1368 | -add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 ); |
|
1369 | -add_action( 'wpinv_email_billing_details', 'getpaid_the_invoice_description', 100 ); |
|
1368 | +add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100); |
|
1369 | +add_action('wpinv_email_billing_details', 'getpaid_the_invoice_description', 100); |
|
1370 | 1370 | |
1371 | 1371 | /** |
1372 | 1372 | * Render element on a form. |
@@ -1374,71 +1374,71 @@ discard block |
||
1374 | 1374 | * @param array $element |
1375 | 1375 | * @param GetPaid_Payment_Form $form |
1376 | 1376 | */ |
1377 | -function getpaid_payment_form_element( $element, $form ) { |
|
1377 | +function getpaid_payment_form_element($element, $form) { |
|
1378 | 1378 | |
1379 | 1379 | // Set up the args. |
1380 | - $element_type = trim( $element['type'] ); |
|
1380 | + $element_type = trim($element['type']); |
|
1381 | 1381 | $element['form'] = $form; |
1382 | - extract( $element ); |
|
1382 | + extract($element); |
|
1383 | 1383 | |
1384 | 1384 | // Try to locate the appropriate template. |
1385 | - $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" ); |
|
1385 | + $located = wpinv_locate_template("payment-forms/elements/$element_type.php"); |
|
1386 | 1386 | |
1387 | 1387 | // Abort if this is not our element. |
1388 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1388 | + if (empty($located) || !file_exists($located)) { |
|
1389 | 1389 | return; |
1390 | 1390 | } |
1391 | 1391 | |
1392 | 1392 | // Generate the class and id of the element. |
1393 | - $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) ); |
|
1394 | - $id = isset( $id ) ? $id : uniqid( 'gp' ); |
|
1393 | + $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type)); |
|
1394 | + $id = isset($id) ? $id : uniqid('gp'); |
|
1395 | 1395 | |
1396 | 1396 | // Echo the opening wrapper. |
1397 | - echo "<div class='getpaid-payment-form-element " . esc_attr( $wrapper_class ) . "'>"; |
|
1397 | + echo "<div class='getpaid-payment-form-element " . esc_attr($wrapper_class) . "'>"; |
|
1398 | 1398 | |
1399 | 1399 | // Fires before displaying a given element type's content. |
1400 | - do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form ); |
|
1400 | + do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form); |
|
1401 | 1401 | |
1402 | 1402 | // Include the template for the element. |
1403 | 1403 | include $located; |
1404 | 1404 | |
1405 | 1405 | // Fires after displaying a given element type's content. |
1406 | - do_action( "getpaid_payment_form_{$element_type}_element", $element, $form ); |
|
1406 | + do_action("getpaid_payment_form_{$element_type}_element", $element, $form); |
|
1407 | 1407 | |
1408 | 1408 | // Echo the closing wrapper. |
1409 | 1409 | echo '</div>'; |
1410 | 1410 | } |
1411 | -add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 ); |
|
1411 | +add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2); |
|
1412 | 1412 | |
1413 | 1413 | /** |
1414 | 1414 | * Render an element's edit page. |
1415 | 1415 | * |
1416 | 1416 | * @param WP_Post $post |
1417 | 1417 | */ |
1418 | -function getpaid_payment_form_edit_element_template( $post ) { |
|
1418 | +function getpaid_payment_form_edit_element_template($post) { |
|
1419 | 1419 | |
1420 | 1420 | // Retrieve all elements. |
1421 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1421 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1422 | 1422 | |
1423 | - foreach ( $all_elements as $element ) { |
|
1423 | + foreach ($all_elements as $element) { |
|
1424 | 1424 | |
1425 | 1425 | // Try to locate the appropriate template. |
1426 | - $element = esc_attr( sanitize_key( $element ) ); |
|
1427 | - $located = wpinv_locate_template( "payment-forms-admin/edit/$element.php" ); |
|
1426 | + $element = esc_attr(sanitize_key($element)); |
|
1427 | + $located = wpinv_locate_template("payment-forms-admin/edit/$element.php"); |
|
1428 | 1428 | |
1429 | 1429 | // Continue if this is not our element. |
1430 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1430 | + if (empty($located) || !file_exists($located)) { |
|
1431 | 1431 | continue; |
1432 | 1432 | } |
1433 | 1433 | |
1434 | 1434 | // Include the template for the element. |
1435 | - echo "<div v-if=\"active_form_element.type=='" . esc_attr( $element ) . "'\">"; |
|
1435 | + echo "<div v-if=\"active_form_element.type=='" . esc_attr($element) . "'\">"; |
|
1436 | 1436 | include $located; |
1437 | 1437 | echo '</div>'; |
1438 | 1438 | } |
1439 | 1439 | |
1440 | 1440 | } |
1441 | -add_action( 'getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template' ); |
|
1441 | +add_action('getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template'); |
|
1442 | 1442 | |
1443 | 1443 | /** |
1444 | 1444 | * Render an element's preview. |
@@ -1447,27 +1447,27 @@ discard block |
||
1447 | 1447 | function getpaid_payment_form_render_element_preview_template() { |
1448 | 1448 | |
1449 | 1449 | // Retrieve all elements. |
1450 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1450 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1451 | 1451 | |
1452 | - foreach ( $all_elements as $element ) { |
|
1452 | + foreach ($all_elements as $element) { |
|
1453 | 1453 | |
1454 | 1454 | // Try to locate the appropriate template. |
1455 | - $element = sanitize_key( $element ); |
|
1456 | - $located = wpinv_locate_template( "payment-forms-admin/previews/$element.php" ); |
|
1455 | + $element = sanitize_key($element); |
|
1456 | + $located = wpinv_locate_template("payment-forms-admin/previews/$element.php"); |
|
1457 | 1457 | |
1458 | 1458 | // Continue if this is not our element. |
1459 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1459 | + if (empty($located) || !file_exists($located)) { |
|
1460 | 1460 | continue; |
1461 | 1461 | } |
1462 | 1462 | |
1463 | 1463 | // Include the template for the element. |
1464 | - echo "<div v-if=\"form_element.type=='" . esc_html( $element ) . "'\">"; |
|
1464 | + echo "<div v-if=\"form_element.type=='" . esc_html($element) . "'\">"; |
|
1465 | 1465 | include $located; |
1466 | 1466 | echo '</div>'; |
1467 | 1467 | } |
1468 | 1468 | |
1469 | 1469 | } |
1470 | -add_action( 'wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template' ); |
|
1470 | +add_action('wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template'); |
|
1471 | 1471 | |
1472 | 1472 | /** |
1473 | 1473 | * Shows a list of gateways that support recurring payments. |
@@ -1475,17 +1475,17 @@ discard block |
||
1475 | 1475 | function wpinv_get_recurring_gateways_text() { |
1476 | 1476 | $gateways = array(); |
1477 | 1477 | |
1478 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
1479 | - if ( wpinv_gateway_support_subscription( $key ) ) { |
|
1480 | - $gateways[] = sanitize_text_field( $gateway['admin_label'] ); |
|
1478 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
1479 | + if (wpinv_gateway_support_subscription($key)) { |
|
1480 | + $gateways[] = sanitize_text_field($gateway['admin_label']); |
|
1481 | 1481 | } |
1482 | 1482 | } |
1483 | 1483 | |
1484 | - if ( empty( $gateways ) ) { |
|
1485 | - return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) . '</span>'; |
|
1484 | + if (empty($gateways)) { |
|
1485 | + return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . '</span>'; |
|
1486 | 1486 | } |
1487 | 1487 | |
1488 | - return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) . '</span>'; |
|
1488 | + return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . '</span>'; |
|
1489 | 1489 | |
1490 | 1490 | } |
1491 | 1491 | |
@@ -1495,7 +1495,7 @@ discard block |
||
1495 | 1495 | * @return GetPaid_Template |
1496 | 1496 | */ |
1497 | 1497 | function getpaid_template() { |
1498 | - return getpaid()->get( 'template' ); |
|
1498 | + return getpaid()->get('template'); |
|
1499 | 1499 | } |
1500 | 1500 | |
1501 | 1501 | /** |
@@ -1504,8 +1504,8 @@ discard block |
||
1504 | 1504 | * @param array args |
1505 | 1505 | * @return string |
1506 | 1506 | */ |
1507 | -function getpaid_paginate_links( $args ) { |
|
1508 | - return str_replace( 'page-link dots', 'page-link text-dark', aui()->pagination( $args ) ); |
|
1507 | +function getpaid_paginate_links($args) { |
|
1508 | + return str_replace('page-link dots', 'page-link text-dark', aui()->pagination($args)); |
|
1509 | 1509 | } |
1510 | 1510 | |
1511 | 1511 | /** |
@@ -1515,22 +1515,22 @@ discard block |
||
1515 | 1515 | * @param string state |
1516 | 1516 | * @return string |
1517 | 1517 | */ |
1518 | -function getpaid_get_states_select_markup( $country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state', $echo = false ) { |
|
1518 | +function getpaid_get_states_select_markup($country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state', $echo = false) { |
|
1519 | 1519 | |
1520 | - $states = wpinv_get_country_states( $country ); |
|
1521 | - $uniqid = uniqid( '_' ); |
|
1520 | + $states = wpinv_get_country_states($country); |
|
1521 | + $uniqid = uniqid('_'); |
|
1522 | 1522 | |
1523 | - if ( ! empty( $states ) ) { |
|
1523 | + if (!empty($states)) { |
|
1524 | 1524 | |
1525 | 1525 | return aui()->select( |
1526 | 1526 | array( |
1527 | 1527 | 'options' => $states, |
1528 | - 'name' => esc_attr( $field_name ), |
|
1529 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1530 | - 'value' => sanitize_text_field( $state ), |
|
1528 | + 'name' => esc_attr($field_name), |
|
1529 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
1530 | + 'value' => sanitize_text_field($state), |
|
1531 | 1531 | 'placeholder' => $placeholder, |
1532 | 1532 | 'required' => $required, |
1533 | - 'label' => wp_kses_post( $label ), |
|
1533 | + 'label' => wp_kses_post($label), |
|
1534 | 1534 | 'label_type' => 'vertical', |
1535 | 1535 | 'help_text' => $help_text, |
1536 | 1536 | 'class' => 'getpaid-address-field wpinv_state', |
@@ -1547,14 +1547,14 @@ discard block |
||
1547 | 1547 | |
1548 | 1548 | return aui()->input( |
1549 | 1549 | array( |
1550 | - 'name' => esc_attr( $field_name ), |
|
1551 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1550 | + 'name' => esc_attr($field_name), |
|
1551 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
1552 | 1552 | 'placeholder' => $placeholder, |
1553 | 1553 | 'required' => $required, |
1554 | - 'label' => wp_kses_post( $label ), |
|
1554 | + 'label' => wp_kses_post($label), |
|
1555 | 1555 | 'label_type' => 'vertical', |
1556 | 1556 | 'help_text' => $help_text, |
1557 | - 'value' => sanitize_text_field( $state ), |
|
1557 | + 'value' => sanitize_text_field($state), |
|
1558 | 1558 | 'class' => 'getpaid-address-field wpinv_state', |
1559 | 1559 | 'wrap_class' => "$wrapper_class getpaid-address-field-wrapper__state", |
1560 | 1560 | 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state', |
@@ -1573,16 +1573,16 @@ discard block |
||
1573 | 1573 | * @param array $element |
1574 | 1574 | * @return string |
1575 | 1575 | */ |
1576 | -function getpaid_get_form_element_grid_class( $element ) { |
|
1576 | +function getpaid_get_form_element_grid_class($element) { |
|
1577 | 1577 | |
1578 | 1578 | $class = 'col-12'; |
1579 | - $width = empty( $element['grid_width'] ) ? 'full' : $element['grid_width']; |
|
1579 | + $width = empty($element['grid_width']) ? 'full' : $element['grid_width']; |
|
1580 | 1580 | |
1581 | - if ( $width == 'half' ) { |
|
1581 | + if ($width == 'half') { |
|
1582 | 1582 | $class .= ' col-md-6'; |
1583 | 1583 | } |
1584 | 1584 | |
1585 | - if ( $width == 'third' ) { |
|
1585 | + if ($width == 'third') { |
|
1586 | 1586 | $class .= ' col-md-4'; |
1587 | 1587 | } |
1588 | 1588 | |
@@ -1597,15 +1597,15 @@ discard block |
||
1597 | 1597 | * |
1598 | 1598 | * @return string |
1599 | 1599 | */ |
1600 | -function getpaid_embed_url( $payment_form = false, $items = false ) { |
|
1600 | +function getpaid_embed_url($payment_form = false, $items = false) { |
|
1601 | 1601 | |
1602 | 1602 | return add_query_arg( |
1603 | 1603 | array( |
1604 | 1604 | 'getpaid_embed' => 1, |
1605 | - 'form' => $payment_form ? absint( $payment_form ) : false, |
|
1606 | - 'item' => $items ? urlencode( $items ) : false, |
|
1605 | + 'form' => $payment_form ? absint($payment_form) : false, |
|
1606 | + 'item' => $items ? urlencode($items) : false, |
|
1607 | 1607 | ), |
1608 | - home_url( 'index.php' ) |
|
1608 | + home_url('index.php') |
|
1609 | 1609 | ); |
1610 | 1610 | |
1611 | 1611 | } |
@@ -1615,13 +1615,13 @@ discard block |
||
1615 | 1615 | * |
1616 | 1616 | * @return string |
1617 | 1617 | */ |
1618 | -function getpaid_filter_embed_template( $template ) { |
|
1618 | +function getpaid_filter_embed_template($template) { |
|
1619 | 1619 | |
1620 | - if ( isset( $_GET['getpaid_embed'] ) ) { |
|
1621 | - wpinv_get_template( 'payment-forms/embed.php' ); |
|
1620 | + if (isset($_GET['getpaid_embed'])) { |
|
1621 | + wpinv_get_template('payment-forms/embed.php'); |
|
1622 | 1622 | exit; |
1623 | 1623 | } |
1624 | 1624 | |
1625 | 1625 | return $template; |
1626 | 1626 | } |
1627 | -add_filter( 'template_include', 'getpaid_filter_embed_template' ); |
|
1627 | +add_filter('template_include', 'getpaid_filter_embed_template'); |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * @deprecated |
@@ -19,48 +19,48 @@ discard block |
||
19 | 19 | * @deprecated |
20 | 20 | */ |
21 | 21 | function wpinv_get_invoice_cart() { |
22 | - return wpinv_get_invoice( getpaid_get_current_invoice_id() ); |
|
22 | + return wpinv_get_invoice(getpaid_get_current_invoice_id()); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * @deprecated |
27 | 27 | */ |
28 | -function wpinv_get_invoice_description( $invoice ) { |
|
29 | - $invoice = new WPInv_Invoice( $invoice ); |
|
28 | +function wpinv_get_invoice_description($invoice) { |
|
29 | + $invoice = new WPInv_Invoice($invoice); |
|
30 | 30 | return $invoice->get_description(); |
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @deprecated |
35 | 35 | */ |
36 | -function wpinv_get_invoice_currency_code( $invoice ) { |
|
37 | - $invoice = new WPInv_Invoice( $invoice ); |
|
36 | +function wpinv_get_invoice_currency_code($invoice) { |
|
37 | + $invoice = new WPInv_Invoice($invoice); |
|
38 | 38 | return $invoice->get_currency(); |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @deprecated |
43 | 43 | */ |
44 | -function wpinv_get_payment_user_email( $invoice ) { |
|
45 | - $invoice = new WPInv_Invoice( $invoice ); |
|
44 | +function wpinv_get_payment_user_email($invoice) { |
|
45 | + $invoice = new WPInv_Invoice($invoice); |
|
46 | 46 | return $invoice->get_email(); |
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * @deprecated |
51 | 51 | */ |
52 | -function wpinv_get_user_id( $invoice ) { |
|
53 | - $invoice = new WPInv_Invoice( $invoice ); |
|
52 | +function wpinv_get_user_id($invoice) { |
|
53 | + $invoice = new WPInv_Invoice($invoice); |
|
54 | 54 | return $invoice->get_user_id(); |
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @deprecated |
59 | 59 | */ |
60 | -function wpinv_get_invoice_status( $invoice, $return_label = false ) { |
|
61 | - $invoice = new WPInv_Invoice( $invoice ); |
|
60 | +function wpinv_get_invoice_status($invoice, $return_label = false) { |
|
61 | + $invoice = new WPInv_Invoice($invoice); |
|
62 | 62 | |
63 | - if ( $return_label ) { |
|
63 | + if ($return_label) { |
|
64 | 64 | return $invoice->get_status_nicename(); |
65 | 65 | } |
66 | 66 | |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | /** |
71 | 71 | * @deprecated |
72 | 72 | */ |
73 | -function wpinv_get_payment_gateway( $invoice, $return_label = false ) { |
|
74 | - $invoice = new WPInv_Invoice( $invoice ); |
|
73 | +function wpinv_get_payment_gateway($invoice, $return_label = false) { |
|
74 | + $invoice = new WPInv_Invoice($invoice); |
|
75 | 75 | |
76 | - if ( $return_label ) { |
|
76 | + if ($return_label) { |
|
77 | 77 | return $invoice->get_gateway_title(); |
78 | 78 | } |
79 | 79 | |
@@ -83,75 +83,75 @@ discard block |
||
83 | 83 | /** |
84 | 84 | * @deprecated |
85 | 85 | */ |
86 | -function wpinv_get_payment_gateway_name( $invoice ) { |
|
87 | - return wpinv_get_payment_gateway( $invoice, true ); |
|
86 | +function wpinv_get_payment_gateway_name($invoice) { |
|
87 | + return wpinv_get_payment_gateway($invoice, true); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
91 | 91 | * @deprecated |
92 | 92 | */ |
93 | -function wpinv_get_payment_transaction_id( $invoice ) { |
|
94 | - $invoice = new WPInv_Invoice( $invoice ); |
|
93 | +function wpinv_get_payment_transaction_id($invoice) { |
|
94 | + $invoice = new WPInv_Invoice($invoice); |
|
95 | 95 | return $invoice->get_transaction_id(); |
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
99 | 99 | * @deprecated |
100 | 100 | */ |
101 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
102 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
103 | - return $invoice->get_meta( $meta_key, $single ); |
|
101 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
102 | + $invoice = new WPInv_Invoice($invoice_id); |
|
103 | + return $invoice->get_meta($meta_key, $single); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | 107 | * @deprecated |
108 | 108 | */ |
109 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '' ) { |
|
110 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
111 | - return $invoice->update_meta_data( $meta_key, $meta_value ); |
|
109 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '') { |
|
110 | + $invoice = new WPInv_Invoice($invoice_id); |
|
111 | + return $invoice->update_meta_data($meta_key, $meta_value); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
115 | 115 | * @deprecated |
116 | 116 | */ |
117 | -function wpinv_get_items( $invoice = 0 ) { |
|
118 | - $invoice = new WPInv_Invoice( $invoice ); |
|
117 | +function wpinv_get_items($invoice = 0) { |
|
118 | + $invoice = new WPInv_Invoice($invoice); |
|
119 | 119 | return $invoice->get_items(); |
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @deprecated |
124 | 124 | */ |
125 | -function wpinv_get_fees( $invoice = 0 ) { |
|
126 | - $invoice = new WPInv_Invoice( $invoice ); |
|
125 | +function wpinv_get_fees($invoice = 0) { |
|
126 | + $invoice = new WPInv_Invoice($invoice); |
|
127 | 127 | return $invoice->get_fees(); |
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
131 | 131 | * @deprecated |
132 | 132 | */ |
133 | -function wpinv_get_invoice_ip( $invoice ) { |
|
134 | - $invoice = new WPInv_Invoice( $invoice ); |
|
133 | +function wpinv_get_invoice_ip($invoice) { |
|
134 | + $invoice = new WPInv_Invoice($invoice); |
|
135 | 135 | return $invoice->get_ip(); |
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | 139 | * @deprecated |
140 | 140 | */ |
141 | -function wpinv_get_invoice_user_info( $invoice ) { |
|
142 | - $invoice = new WPInv_Invoice( $invoice ); |
|
141 | +function wpinv_get_invoice_user_info($invoice) { |
|
142 | + $invoice = new WPInv_Invoice($invoice); |
|
143 | 143 | return $invoice->get_user_info(); |
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | 147 | * @deprecated |
148 | 148 | */ |
149 | -function wpinv_subtotal( $invoice = 0, $currency = false ) { |
|
150 | - $invoice = new WPInv_Invoice( $invoice ); |
|
149 | +function wpinv_subtotal($invoice = 0, $currency = false) { |
|
150 | + $invoice = new WPInv_Invoice($invoice); |
|
151 | 151 | $subtotal = $invoice->get_subtotal(); |
152 | 152 | |
153 | - if ( $currency ) { |
|
154 | - return wpinv_price( $subtotal, $invoice->get_currency() ); |
|
153 | + if ($currency) { |
|
154 | + return wpinv_price($subtotal, $invoice->get_currency()); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | return $subtotal; |
@@ -160,12 +160,12 @@ discard block |
||
160 | 160 | /** |
161 | 161 | * @deprecated |
162 | 162 | */ |
163 | -function wpinv_tax( $invoice = 0, $currency = false ) { |
|
164 | - $invoice = new WPInv_Invoice( $invoice ); |
|
163 | +function wpinv_tax($invoice = 0, $currency = false) { |
|
164 | + $invoice = new WPInv_Invoice($invoice); |
|
165 | 165 | $tax = $invoice->get_total_tax(); |
166 | 166 | |
167 | - if ( $currency ) { |
|
168 | - return wpinv_price( $tax, $invoice->get_currency() ); |
|
167 | + if ($currency) { |
|
168 | + return wpinv_price($tax, $invoice->get_currency()); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | return $tax; |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | /** |
175 | 175 | * @deprecated |
176 | 176 | */ |
177 | -function wpinv_discount( $invoice = 0, $currency = false ) { |
|
178 | - $invoice = new WPInv_Invoice( $invoice ); |
|
177 | +function wpinv_discount($invoice = 0, $currency = false) { |
|
178 | + $invoice = new WPInv_Invoice($invoice); |
|
179 | 179 | $discount = $invoice->get_total_discount(); |
180 | 180 | |
181 | - if ( $currency ) { |
|
182 | - return wpinv_price( $discount, $invoice->get_currency() ); |
|
181 | + if ($currency) { |
|
182 | + return wpinv_price($discount, $invoice->get_currency()); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | return $discount; |
@@ -188,20 +188,20 @@ discard block |
||
188 | 188 | /** |
189 | 189 | * @deprecated |
190 | 190 | */ |
191 | -function wpinv_discount_code( $invoice = 0 ) { |
|
192 | - $invoice = new WPInv_Invoice( $invoice ); |
|
191 | +function wpinv_discount_code($invoice = 0) { |
|
192 | + $invoice = new WPInv_Invoice($invoice); |
|
193 | 193 | return $invoice->get_discount_code(); |
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
197 | 197 | * @deprecated |
198 | 198 | */ |
199 | -function wpinv_payment_total( $invoice = 0, $currency = false ) { |
|
200 | - $invoice = new WPInv_Invoice( $invoice ); |
|
199 | +function wpinv_payment_total($invoice = 0, $currency = false) { |
|
200 | + $invoice = new WPInv_Invoice($invoice); |
|
201 | 201 | $total = $invoice->get_total(); |
202 | 202 | |
203 | - if ( $currency ) { |
|
204 | - return wpinv_price( $total, $invoice->get_currency() ); |
|
203 | + if ($currency) { |
|
204 | + return wpinv_price($total, $invoice->get_currency()); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | return $total; |
@@ -210,51 +210,51 @@ discard block |
||
210 | 210 | /** |
211 | 211 | * @deprecated |
212 | 212 | */ |
213 | -function wpinv_get_date_created( $invoice = 0, $format = '' ) { |
|
214 | - $invoice = new WPInv_Invoice( $invoice ); |
|
213 | +function wpinv_get_date_created($invoice = 0, $format = '') { |
|
214 | + $invoice = new WPInv_Invoice($invoice); |
|
215 | 215 | |
216 | - $format = ! empty( $format ) ? $format : get_option( 'date_format' ); |
|
216 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
217 | 217 | $date_created = $invoice->get_created_date(); |
218 | 218 | |
219 | - return empty( $date_created ) ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
219 | + return empty($date_created) ? date_i18n($format, strtotime($date_created)) : ''; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
223 | 223 | * @deprecated |
224 | 224 | */ |
225 | -function wpinv_get_invoice_date( $invoice = 0, $format = '' ) { |
|
226 | - wpinv_get_date_created( $invoice, $format ); |
|
225 | +function wpinv_get_invoice_date($invoice = 0, $format = '') { |
|
226 | + wpinv_get_date_created($invoice, $format); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
230 | 230 | * @deprecated |
231 | 231 | */ |
232 | -function wpinv_get_invoice_vat_number( $invoice = 0 ) { |
|
233 | - $invoice = new WPInv_Invoice( $invoice ); |
|
232 | +function wpinv_get_invoice_vat_number($invoice = 0) { |
|
233 | + $invoice = new WPInv_Invoice($invoice); |
|
234 | 234 | return $invoice->get_vat_number(); |
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
238 | 238 | * @deprecated |
239 | 239 | */ |
240 | -function wpinv_insert_payment_note( $invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) { |
|
241 | - $invoice = new WPInv_Invoice( $invoice ); |
|
242 | - return $invoice->add_note( $note, $user_type, $added_by_user, $system ); |
|
240 | +function wpinv_insert_payment_note($invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) { |
|
241 | + $invoice = new WPInv_Invoice($invoice); |
|
242 | + return $invoice->add_note($note, $user_type, $added_by_user, $system); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
246 | 246 | * @deprecated |
247 | 247 | */ |
248 | -function wpinv_get_payment_key( $invoice = 0 ) { |
|
249 | - $invoice = new WPInv_Invoice( $invoice ); |
|
248 | +function wpinv_get_payment_key($invoice = 0) { |
|
249 | + $invoice = new WPInv_Invoice($invoice); |
|
250 | 250 | return $invoice->get_key(); |
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
254 | 254 | * @deprecated |
255 | 255 | */ |
256 | -function wpinv_get_invoice_number( $invoice = 0 ) { |
|
257 | - $invoice = new WPInv_Invoice( $invoice ); |
|
256 | +function wpinv_get_invoice_number($invoice = 0) { |
|
257 | + $invoice = new WPInv_Invoice($invoice); |
|
258 | 258 | return $invoice->get_number(); |
259 | 259 | } |
260 | 260 | |
@@ -401,9 +401,9 @@ discard block |
||
401 | 401 | /** |
402 | 402 | * @deprecated |
403 | 403 | */ |
404 | -function wpinv_update_payment_status( $invoice, $new_status = 'publish' ) { |
|
405 | - $invoice = new WPInv_Invoice( $invoice ); |
|
406 | - return $invoice->update_status( $new_status ); |
|
404 | +function wpinv_update_payment_status($invoice, $new_status = 'publish') { |
|
405 | + $invoice = new WPInv_Invoice($invoice); |
|
406 | + return $invoice->update_status($new_status); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -456,22 +456,22 @@ discard block |
||
456 | 456 | /** |
457 | 457 | * @deprecated |
458 | 458 | */ |
459 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
459 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
460 | 460 | |
461 | 461 | // Fetch the invoice. |
462 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
462 | + $invoice = new WPInv_Invoice($invoice_id); |
|
463 | 463 | |
464 | - if ( 0 == $invoice->get_id() ) { |
|
464 | + if (0 == $invoice->get_id()) { |
|
465 | 465 | return false; |
466 | 466 | } |
467 | 467 | |
468 | 468 | // Prepare the transaction id. |
469 | - if ( empty( $transaction_id ) ) { |
|
469 | + if (empty($transaction_id)) { |
|
470 | 470 | $transaction_id = $invoice_id; |
471 | 471 | } |
472 | 472 | |
473 | 473 | // Set the transaction id; |
474 | - $invoice->set_transaction_id( apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice ) ); |
|
474 | + $invoice->set_transaction_id(apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice)); |
|
475 | 475 | |
476 | 476 | // Save the invoice. |
477 | 477 | return $invoice->save(); |
@@ -484,12 +484,12 @@ discard block |
||
484 | 484 | * @param WPInv_Invoice $invoice |
485 | 485 | * @param string $gateway |
486 | 486 | */ |
487 | -function wpinv_send_to_gateway( $gateway, $invoice ) { |
|
487 | +function wpinv_send_to_gateway($gateway, $invoice) { |
|
488 | 488 | |
489 | 489 | $payment_data = array( |
490 | 490 | 'invoice_id' => $invoice->get_id(), |
491 | 491 | 'items' => $invoice->get_cart_details(), |
492 | - 'cart_discounts' => array( $invoice->get_discount_code() ), |
|
492 | + 'cart_discounts' => array($invoice->get_discount_code()), |
|
493 | 493 | 'fees' => $invoice->get_total_fees(), |
494 | 494 | 'subtotal' => $invoice->get_subtotal(), |
495 | 495 | 'discount' => $invoice->get_total_discount(), |
@@ -497,16 +497,16 @@ discard block |
||
497 | 497 | 'price' => $invoice->get_total(), |
498 | 498 | 'invoice_key' => $invoice->get_key(), |
499 | 499 | 'user_email' => $invoice->get_email(), |
500 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
500 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
501 | 501 | 'user_info' => $invoice->get_user_info(), |
502 | - 'post_data' => wp_kses_post( wp_unslash( $_POST ) ), |
|
502 | + 'post_data' => wp_kses_post(wp_unslash($_POST)), |
|
503 | 503 | 'cart_details' => $invoice->get_cart_details(), |
504 | 504 | 'gateway' => $gateway, |
505 | 505 | 'card_info' => array(), |
506 | - 'gateway_nonce' => wp_create_nonce( 'wpi-gateway' ), |
|
506 | + 'gateway_nonce' => wp_create_nonce('wpi-gateway'), |
|
507 | 507 | ); |
508 | 508 | |
509 | - do_action( 'wpinv_gateway_' . $gateway, $payment_data ); |
|
509 | + do_action('wpinv_gateway_' . $gateway, $payment_data); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
@@ -519,10 +519,10 @@ discard block |
||
519 | 519 | /** |
520 | 520 | * @deprecated |
521 | 521 | */ |
522 | -function wpinv_die( $message = '', $title = '', $status = 400 ) { |
|
523 | - add_filter( 'wp_die_ajax_handler', 'wpinv_die_handler', 10, 3 ); |
|
524 | - add_filter( 'wp_die_handler', 'wpinv_die_handler', 10, 3 ); |
|
525 | - wp_die( esc_html( $message ), esc_html( $title ), array( 'response' => (int) $status ) ); |
|
522 | +function wpinv_die($message = '', $title = '', $status = 400) { |
|
523 | + add_filter('wp_die_ajax_handler', 'wpinv_die_handler', 10, 3); |
|
524 | + add_filter('wp_die_handler', 'wpinv_die_handler', 10, 3); |
|
525 | + wp_die(esc_html($message), esc_html($title), array('response' => (int) $status)); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | /** |
@@ -640,14 +640,14 @@ discard block |
||
640 | 640 | /** |
641 | 641 | * @deprecated |
642 | 642 | */ |
643 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
644 | - return empty( $status_display ) ? sanitize_text_field( $status ) : sanitize_text_field( $status_display ); |
|
643 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
644 | + return empty($status_display) ? sanitize_text_field($status) : sanitize_text_field($status_display); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
648 | 648 | * @deprecated |
649 | 649 | */ |
650 | -function wpinv_clean_invoice_number( $number ) { |
|
650 | +function wpinv_clean_invoice_number($number) { |
|
651 | 651 | return $number; |
652 | 652 | } |
653 | 653 | |
@@ -852,12 +852,12 @@ discard block |
||
852 | 852 | /** |
853 | 853 | * @deprecated |
854 | 854 | */ |
855 | -function wpinv_item_show_price( $item_id = 0, $echo = true ) { |
|
855 | +function wpinv_item_show_price($item_id = 0, $echo = true) { |
|
856 | 856 | |
857 | - if ( $echo ) { |
|
858 | - echo wp_kses_post( wpinv_item_price( $item_id ) ); |
|
857 | + if ($echo) { |
|
858 | + echo wp_kses_post(wpinv_item_price($item_id)); |
|
859 | 859 | } else { |
860 | - return wpinv_item_price( $item_id ); |
|
860 | + return wpinv_item_price($item_id); |
|
861 | 861 | } |
862 | 862 | |
863 | 863 | } |
@@ -1272,6 +1272,6 @@ discard block |
||
1272 | 1272 | * @return WPInv_Subscription|bool |
1273 | 1273 | * @deprecated |
1274 | 1274 | */ |
1275 | -function wpinv_get_subscription( $invoice ) { |
|
1276 | - return wpinv_get_invoice_subscription( $invoice ); |
|
1275 | +function wpinv_get_subscription($invoice) { |
|
1276 | + return wpinv_get_invoice_subscription($invoice); |
|
1277 | 1277 | } |
@@ -13,30 +13,30 @@ discard block |
||
13 | 13 | class GetPaid_Bank_Transfer_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 = 'bank_transfer'; |
21 | 21 | |
22 | - /** |
|
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
22 | + /** |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
34 | - public $order = 8; |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | + public $order = 8; |
|
35 | 35 | |
36 | 36 | /** |
37 | - * Class constructor. |
|
38 | - */ |
|
39 | - public function __construct() { |
|
37 | + * Class constructor. |
|
38 | + */ |
|
39 | + public function __construct() { |
|
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | 42 | $this->title = __( 'Direct bank transfer', 'invoicing' ); |
@@ -44,24 +44,24 @@ discard block |
||
44 | 44 | $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
45 | 45 | $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
46 | 46 | |
47 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
48 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
49 | - add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
50 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
51 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
52 | - add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
47 | + add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
48 | + add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
49 | + add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
50 | + add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
51 | + add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
52 | + add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
53 | 53 | |
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | - * Process Payment. |
|
58 | - * |
|
59 | - * @param WPInv_Invoice $invoice Invoice. |
|
60 | - * @param array $submission_data Posted checkout fields. |
|
61 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
62 | - * @return array |
|
63 | - */ |
|
64 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
57 | + * Process Payment. |
|
58 | + * |
|
59 | + * @param WPInv_Invoice $invoice Invoice. |
|
60 | + * @param array $submission_data Posted checkout fields. |
|
61 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
62 | + * @return array |
|
63 | + */ |
|
64 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
65 | 65 | |
66 | 66 | // Add a transaction id. |
67 | 67 | $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) ); |
@@ -82,66 +82,66 @@ discard block |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | - * Output for the order received page. |
|
86 | - * |
|
87 | - * @param WPInv_Invoice $invoice Invoice. |
|
88 | - */ |
|
89 | - public function thankyou_page( $invoice ) { |
|
85 | + * Output for the order received page. |
|
86 | + * |
|
87 | + * @param WPInv_Invoice $invoice Invoice. |
|
88 | + */ |
|
89 | + public function thankyou_page( $invoice ) { |
|
90 | 90 | |
91 | 91 | if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
92 | 92 | |
93 | - echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
93 | + echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
94 | 94 | |
95 | 95 | if ( ! empty( $this->instructions ) ) { |
96 | 96 | echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
97 | - } |
|
97 | + } |
|
98 | 98 | |
99 | - $this->bank_details( $invoice ); |
|
99 | + $this->bank_details( $invoice ); |
|
100 | 100 | |
101 | - echo '</div>'; |
|
101 | + echo '</div>'; |
|
102 | 102 | |
103 | 103 | } |
104 | 104 | |
105 | - } |
|
105 | + } |
|
106 | 106 | |
107 | 107 | /** |
108 | - * Add content to the WPI emails. |
|
109 | - * |
|
110 | - * @param WPInv_Invoice $invoice Invoice. |
|
111 | - * @param string $email_type Email format: plain text or HTML. |
|
112 | - * @param bool $sent_to_admin Sent to admin. |
|
113 | - */ |
|
114 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
108 | + * Add content to the WPI emails. |
|
109 | + * |
|
110 | + * @param WPInv_Invoice $invoice Invoice. |
|
111 | + * @param string $email_type Email format: plain text or HTML. |
|
112 | + * @param bool $sent_to_admin Sent to admin. |
|
113 | + */ |
|
114 | + public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
115 | 115 | |
116 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
116 | + if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
117 | 117 | |
118 | - echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
118 | + echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
119 | 119 | |
120 | - if ( $this->instructions ) { |
|
121 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
120 | + if ( $this->instructions ) { |
|
121 | + echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
122 | 122 | } |
123 | 123 | |
124 | - $this->bank_details( $invoice ); |
|
124 | + $this->bank_details( $invoice ); |
|
125 | 125 | |
126 | - echo '</div>'; |
|
126 | + echo '</div>'; |
|
127 | 127 | |
128 | - } |
|
128 | + } |
|
129 | 129 | |
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
133 | - * Get bank details and place into a list format. |
|
134 | - * |
|
135 | - * @param WPInv_Invoice $invoice Invoice. |
|
136 | - */ |
|
137 | - protected function bank_details( $invoice ) { |
|
133 | + * Get bank details and place into a list format. |
|
134 | + * |
|
135 | + * @param WPInv_Invoice $invoice Invoice. |
|
136 | + */ |
|
137 | + protected function bank_details( $invoice ) { |
|
138 | 138 | |
139 | - // Get the invoice country and country $locale. |
|
140 | - $country = $invoice->get_country(); |
|
141 | - $locale = $this->get_country_locale(); |
|
139 | + // Get the invoice country and country $locale. |
|
140 | + $country = $invoice->get_country(); |
|
141 | + $locale = $this->get_country_locale(); |
|
142 | 142 | |
143 | - // Get sortcode label in the $locale array and use appropriate one. |
|
144 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
143 | + // Get sortcode label in the $locale array and use appropriate one. |
|
144 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
145 | 145 | |
146 | 146 | $bank_fields = array( |
147 | 147 | 'ac_name' => __( 'Account Name', 'invoicing' ), |
@@ -160,9 +160,9 @@ discard block |
||
160 | 160 | |
161 | 161 | if ( ! empty( $value ) ) { |
162 | 162 | $bank_info[ $field ] = array( |
163 | - 'label' => $label, |
|
164 | - 'value' => $value, |
|
165 | - ); |
|
163 | + 'label' => $label, |
|
164 | + 'value' => $value, |
|
165 | + ); |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
@@ -172,139 +172,139 @@ discard block |
||
172 | 172 | return; |
173 | 173 | } |
174 | 174 | |
175 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) ) . '</h3>' . PHP_EOL; |
|
175 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) ) . '</h3>' . PHP_EOL; |
|
176 | 176 | |
177 | - echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
177 | + echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
178 | 178 | |
179 | - foreach ( $bank_info as $key => $data ) { |
|
180 | - echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . "</td></tr>" . PHP_EOL; |
|
181 | - } |
|
179 | + foreach ( $bank_info as $key => $data ) { |
|
180 | + echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . "</td></tr>" . PHP_EOL; |
|
181 | + } |
|
182 | 182 | |
183 | - echo '</table>'; |
|
183 | + echo '</table>'; |
|
184 | 184 | |
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
188 | - * Get country locale if localized. |
|
189 | - * |
|
190 | - * @return array |
|
191 | - */ |
|
192 | - public function get_country_locale() { |
|
193 | - |
|
194 | - if ( empty( $this->locale ) ) { |
|
195 | - |
|
196 | - // Locale information to be used - only those that are not 'Sort Code'. |
|
197 | - $this->locale = apply_filters( |
|
198 | - 'getpaid_get_bank_transfer_locale', |
|
199 | - array( |
|
200 | - 'AU' => array( |
|
201 | - 'sortcode' => array( |
|
202 | - 'label' => __( 'BSB', 'invoicing' ), |
|
203 | - ), |
|
204 | - ), |
|
205 | - 'CA' => array( |
|
206 | - 'sortcode' => array( |
|
207 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
208 | - ), |
|
209 | - ), |
|
210 | - 'IN' => array( |
|
211 | - 'sortcode' => array( |
|
212 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
213 | - ), |
|
214 | - ), |
|
215 | - 'IT' => array( |
|
216 | - 'sortcode' => array( |
|
217 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
218 | - ), |
|
219 | - ), |
|
220 | - 'NZ' => array( |
|
221 | - 'sortcode' => array( |
|
222 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
223 | - ), |
|
224 | - ), |
|
225 | - 'SE' => array( |
|
226 | - 'sortcode' => array( |
|
227 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
228 | - ), |
|
229 | - ), |
|
230 | - 'US' => array( |
|
231 | - 'sortcode' => array( |
|
232 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
233 | - ), |
|
234 | - ), |
|
235 | - 'ZA' => array( |
|
236 | - 'sortcode' => array( |
|
237 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
238 | - ), |
|
239 | - ), |
|
240 | - ) |
|
241 | - ); |
|
242 | - |
|
243 | - } |
|
244 | - |
|
245 | - return $this->locale; |
|
246 | - |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * Filters the gateway settings. |
|
251 | - * |
|
252 | - * @param array $admin_settings |
|
253 | - */ |
|
254 | - public function admin_settings( $admin_settings ) { |
|
188 | + * Get country locale if localized. |
|
189 | + * |
|
190 | + * @return array |
|
191 | + */ |
|
192 | + public function get_country_locale() { |
|
193 | + |
|
194 | + if ( empty( $this->locale ) ) { |
|
195 | + |
|
196 | + // Locale information to be used - only those that are not 'Sort Code'. |
|
197 | + $this->locale = apply_filters( |
|
198 | + 'getpaid_get_bank_transfer_locale', |
|
199 | + array( |
|
200 | + 'AU' => array( |
|
201 | + 'sortcode' => array( |
|
202 | + 'label' => __( 'BSB', 'invoicing' ), |
|
203 | + ), |
|
204 | + ), |
|
205 | + 'CA' => array( |
|
206 | + 'sortcode' => array( |
|
207 | + 'label' => __( 'Bank transit number', 'invoicing' ), |
|
208 | + ), |
|
209 | + ), |
|
210 | + 'IN' => array( |
|
211 | + 'sortcode' => array( |
|
212 | + 'label' => __( 'IFSC', 'invoicing' ), |
|
213 | + ), |
|
214 | + ), |
|
215 | + 'IT' => array( |
|
216 | + 'sortcode' => array( |
|
217 | + 'label' => __( 'Branch sort', 'invoicing' ), |
|
218 | + ), |
|
219 | + ), |
|
220 | + 'NZ' => array( |
|
221 | + 'sortcode' => array( |
|
222 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
223 | + ), |
|
224 | + ), |
|
225 | + 'SE' => array( |
|
226 | + 'sortcode' => array( |
|
227 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
228 | + ), |
|
229 | + ), |
|
230 | + 'US' => array( |
|
231 | + 'sortcode' => array( |
|
232 | + 'label' => __( 'Routing number', 'invoicing' ), |
|
233 | + ), |
|
234 | + ), |
|
235 | + 'ZA' => array( |
|
236 | + 'sortcode' => array( |
|
237 | + 'label' => __( 'Branch code', 'invoicing' ), |
|
238 | + ), |
|
239 | + ), |
|
240 | + ) |
|
241 | + ); |
|
242 | + |
|
243 | + } |
|
244 | + |
|
245 | + return $this->locale; |
|
246 | + |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Filters the gateway settings. |
|
251 | + * |
|
252 | + * @param array $admin_settings |
|
253 | + */ |
|
254 | + public function admin_settings( $admin_settings ) { |
|
255 | 255 | |
256 | 256 | $admin_settings['bank_transfer_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
257 | - $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
257 | + $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
258 | 258 | |
259 | - $locale = $this->get_country_locale(); |
|
259 | + $locale = $this->get_country_locale(); |
|
260 | 260 | |
261 | - // Get sortcode label in the $locale array and use appropriate one. |
|
262 | - $country = wpinv_default_billing_country(); |
|
263 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
261 | + // Get sortcode label in the $locale array and use appropriate one. |
|
262 | + $country = wpinv_default_billing_country(); |
|
263 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
264 | 264 | |
265 | - $admin_settings['bank_transfer_ac_name'] = array( |
|
265 | + $admin_settings['bank_transfer_ac_name'] = array( |
|
266 | 266 | 'type' => 'text', |
267 | 267 | 'id' => 'bank_transfer_ac_name', |
268 | 268 | 'name' => __( 'Account Name', 'invoicing' ), |
269 | - ); |
|
269 | + ); |
|
270 | 270 | |
271 | - $admin_settings['bank_transfer_ac_no'] = array( |
|
271 | + $admin_settings['bank_transfer_ac_no'] = array( |
|
272 | 272 | 'type' => 'text', |
273 | 273 | 'id' => 'bank_transfer_ac_no', |
274 | 274 | 'name' => __( 'Account Number', 'invoicing' ), |
275 | - ); |
|
275 | + ); |
|
276 | 276 | |
277 | - $admin_settings['bank_transfer_bank_name'] = array( |
|
277 | + $admin_settings['bank_transfer_bank_name'] = array( |
|
278 | 278 | 'type' => 'text', |
279 | 279 | 'id' => 'bank_transfer_bank_name', |
280 | 280 | 'name' => __( 'Bank Name', 'invoicing' ), |
281 | - ); |
|
281 | + ); |
|
282 | 282 | |
283 | - $admin_settings['bank_transfer_ifsc'] = array( |
|
283 | + $admin_settings['bank_transfer_ifsc'] = array( |
|
284 | 284 | 'type' => 'text', |
285 | 285 | 'id' => 'bank_transfer_ifsc', |
286 | 286 | 'name' => __( 'IFSC Code', 'invoicing' ), |
287 | - ); |
|
287 | + ); |
|
288 | 288 | |
289 | - $admin_settings['bank_transfer_iban'] = array( |
|
289 | + $admin_settings['bank_transfer_iban'] = array( |
|
290 | 290 | 'type' => 'text', |
291 | 291 | 'id' => 'bank_transfer_iban', |
292 | 292 | 'name' => __( 'IBAN', 'invoicing' ), |
293 | - ); |
|
293 | + ); |
|
294 | 294 | |
295 | - $admin_settings['bank_transfer_bic'] = array( |
|
295 | + $admin_settings['bank_transfer_bic'] = array( |
|
296 | 296 | 'type' => 'text', |
297 | 297 | 'id' => 'bank_transfer_bic', |
298 | 298 | 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
299 | - ); |
|
299 | + ); |
|
300 | 300 | |
301 | - $admin_settings['bank_transfer_sort_code'] = array( |
|
302 | - 'type' => 'text', |
|
303 | - 'id' => 'bank_transfer_sort_code', |
|
304 | - 'name' => $sortcode, |
|
305 | - ); |
|
301 | + $admin_settings['bank_transfer_sort_code'] = array( |
|
302 | + 'type' => 'text', |
|
303 | + 'id' => 'bank_transfer_sort_code', |
|
304 | + 'name' => $sortcode, |
|
305 | + ); |
|
306 | 306 | |
307 | - $admin_settings['bank_transfer_info'] = array( |
|
307 | + $admin_settings['bank_transfer_info'] = array( |
|
308 | 308 | 'id' => 'bank_transfer_info', |
309 | 309 | 'name' => __( 'Instructions', 'invoicing' ), |
310 | 310 | 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
@@ -314,17 +314,17 @@ discard block |
||
314 | 314 | 'rows' => 5, |
315 | 315 | ); |
316 | 316 | |
317 | - return $admin_settings; |
|
318 | - } |
|
317 | + return $admin_settings; |
|
318 | + } |
|
319 | 319 | |
320 | - /** |
|
321 | - * Processes invoice addons. |
|
322 | - * |
|
323 | - * @param WPInv_Invoice $invoice |
|
324 | - * @param GetPaid_Form_Item[] $items |
|
325 | - * @return WPInv_Invoice |
|
326 | - */ |
|
327 | - public function process_addons( $invoice, $items ) { |
|
320 | + /** |
|
321 | + * Processes invoice addons. |
|
322 | + * |
|
323 | + * @param WPInv_Invoice $invoice |
|
324 | + * @param GetPaid_Form_Item[] $items |
|
325 | + * @return WPInv_Invoice |
|
326 | + */ |
|
327 | + public function process_addons( $invoice, $items ) { |
|
328 | 328 | |
329 | 329 | foreach ( $items as $item ) { |
330 | 330 | $invoice->add_item( $item ); |
@@ -332,66 +332,66 @@ discard block |
||
332 | 332 | |
333 | 333 | $invoice->recalculate_total(); |
334 | 334 | $invoice->save(); |
335 | - } |
|
335 | + } |
|
336 | 336 | |
337 | - /** |
|
338 | - * (Maybe) renews a bank transfer subscription profile. |
|
339 | - * |
|
340 | - * |
|
337 | + /** |
|
338 | + * (Maybe) renews a bank transfer subscription profile. |
|
339 | + * |
|
340 | + * |
|
341 | 341 | * @param WPInv_Subscription $subscription |
342 | - */ |
|
343 | - public function maybe_renew_subscription( $subscription ) { |
|
342 | + */ |
|
343 | + public function maybe_renew_subscription( $subscription ) { |
|
344 | 344 | |
345 | 345 | // Ensure its our subscription && it's active. |
346 | 346 | if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
347 | - $subscription->create_payment(); |
|
347 | + $subscription->create_payment(); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | } |
351 | 351 | |
352 | - /** |
|
353 | - * Process a bank transfer payment. |
|
354 | - * |
|
355 | - * |
|
352 | + /** |
|
353 | + * Process a bank transfer payment. |
|
354 | + * |
|
355 | + * |
|
356 | 356 | * @param WPInv_Invoice $invoice |
357 | - */ |
|
358 | - public function invoice_paid( $invoice ) { |
|
359 | - |
|
360 | - // Abort if not paid by bank transfer. |
|
361 | - if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
362 | - return; |
|
363 | - } |
|
364 | - |
|
365 | - // Is it a parent payment? |
|
366 | - if ( 0 == $invoice->get_parent_id() ) { |
|
367 | - |
|
368 | - // (Maybe) activate subscriptions. |
|
369 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
370 | - |
|
371 | - if ( ! empty( $subscriptions ) ) { |
|
372 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
373 | - |
|
374 | - foreach ( $subscriptions as $subscription ) { |
|
375 | - if ( $subscription->exists() ) { |
|
376 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
377 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
378 | - |
|
379 | - $subscription->set_next_renewal_date( $expiry ); |
|
380 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
381 | - $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
382 | - $subscription->activate(); |
|
383 | - } |
|
384 | - } |
|
357 | + */ |
|
358 | + public function invoice_paid( $invoice ) { |
|
359 | + |
|
360 | + // Abort if not paid by bank transfer. |
|
361 | + if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
362 | + return; |
|
363 | + } |
|
364 | + |
|
365 | + // Is it a parent payment? |
|
366 | + if ( 0 == $invoice->get_parent_id() ) { |
|
367 | + |
|
368 | + // (Maybe) activate subscriptions. |
|
369 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
370 | + |
|
371 | + if ( ! empty( $subscriptions ) ) { |
|
372 | + $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
373 | + |
|
374 | + foreach ( $subscriptions as $subscription ) { |
|
375 | + if ( $subscription->exists() ) { |
|
376 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
377 | + $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
378 | + |
|
379 | + $subscription->set_next_renewal_date( $expiry ); |
|
380 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
381 | + $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
382 | + $subscription->activate(); |
|
383 | + } |
|
384 | + } |
|
385 | 385 | } |
386 | 386 | } else { |
387 | 387 | |
388 | - $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
388 | + $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
389 | 389 | |
390 | - // Renew the subscription. |
|
391 | - if ( $subscription && $subscription->exists() ) { |
|
392 | - $subscription->add_payment( array(), $invoice ); |
|
393 | - $subscription->renew(); |
|
394 | - } |
|
390 | + // Renew the subscription. |
|
391 | + if ( $subscription && $subscription->exists() ) { |
|
392 | + $subscription->add_payment( array(), $invoice ); |
|
393 | + $subscription->renew(); |
|
394 | + } |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Bank transfer Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
27 | + protected $supports = array('subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -39,17 +39,17 @@ discard block |
||
39 | 39 | public function __construct() { |
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | - $this->title = __( 'Direct bank transfer', 'invoicing' ); |
|
43 | - $this->method_title = __( 'Bank transfer', 'invoicing' ); |
|
44 | - $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
|
45 | - $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
|
42 | + $this->title = __('Direct bank transfer', 'invoicing'); |
|
43 | + $this->method_title = __('Bank transfer', 'invoicing'); |
|
44 | + $this->checkout_button_text = __('Proceed', 'invoicing'); |
|
45 | + $this->instructions = apply_filters('wpinv_bank_instructions', $this->get_option('info')); |
|
46 | 46 | |
47 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
48 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
49 | - add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
50 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
51 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
52 | - add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
47 | + add_action('wpinv_receipt_end', array($this, 'thankyou_page')); |
|
48 | + add_action('getpaid_invoice_line_items', array($this, 'thankyou_page'), 40); |
|
49 | + add_action('wpinv_pdf_content_billing', array($this, 'thankyou_page'), 11); |
|
50 | + add_action('wpinv_email_invoice_details', array($this, 'email_instructions'), 10, 3); |
|
51 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
52 | + add_action('getpaid_invoice_status_publish', array($this, 'invoice_paid'), 20); |
|
53 | 53 | |
54 | 54 | } |
55 | 55 | |
@@ -61,23 +61,23 @@ discard block |
||
61 | 61 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
62 | 62 | * @return array |
63 | 63 | */ |
64 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
64 | + public function process_payment($invoice, $submission_data, $submission) { |
|
65 | 65 | |
66 | 66 | // Add a transaction id. |
67 | - $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) ); |
|
67 | + $invoice->set_transaction_id($invoice->generate_key('bt_')); |
|
68 | 68 | |
69 | 69 | // Set it as pending payment. |
70 | - if ( ! $invoice->needs_payment() ) { |
|
70 | + if (!$invoice->needs_payment()) { |
|
71 | 71 | $invoice->mark_paid(); |
72 | - } elseif ( ! $invoice->is_paid() ) { |
|
73 | - $invoice->set_status( 'wpi-onhold' ); |
|
72 | + } elseif (!$invoice->is_paid()) { |
|
73 | + $invoice->set_status('wpi-onhold'); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | // Save it. |
77 | 77 | $invoice->save(); |
78 | 78 | |
79 | 79 | // Send to the success page. |
80 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
80 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
81 | 81 | |
82 | 82 | } |
83 | 83 | |
@@ -86,17 +86,17 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @param WPInv_Invoice $invoice Invoice. |
88 | 88 | */ |
89 | - public function thankyou_page( $invoice ) { |
|
89 | + public function thankyou_page($invoice) { |
|
90 | 90 | |
91 | - if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
91 | + if ('bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) { |
|
92 | 92 | |
93 | 93 | echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
94 | 94 | |
95 | - if ( ! empty( $this->instructions ) ) { |
|
96 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
|
95 | + if (!empty($this->instructions)) { |
|
96 | + echo wp_kses_post(wpautop(wptexturize($this->instructions))); |
|
97 | 97 | } |
98 | 98 | |
99 | - $this->bank_details( $invoice ); |
|
99 | + $this->bank_details($invoice); |
|
100 | 100 | |
101 | 101 | echo '</div>'; |
102 | 102 | |
@@ -111,17 +111,17 @@ discard block |
||
111 | 111 | * @param string $email_type Email format: plain text or HTML. |
112 | 112 | * @param bool $sent_to_admin Sent to admin. |
113 | 113 | */ |
114 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
114 | + public function email_instructions($invoice, $email_type, $sent_to_admin) { |
|
115 | 115 | |
116 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
116 | + if (!$sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) { |
|
117 | 117 | |
118 | 118 | echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
119 | 119 | |
120 | - if ( $this->instructions ) { |
|
121 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
120 | + if ($this->instructions) { |
|
121 | + echo wp_kses_post(wpautop(wptexturize($this->instructions)) . PHP_EOL); |
|
122 | 122 | } |
123 | 123 | |
124 | - $this->bank_details( $invoice ); |
|
124 | + $this->bank_details($invoice); |
|
125 | 125 | |
126 | 126 | echo '</div>'; |
127 | 127 | |
@@ -134,50 +134,50 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @param WPInv_Invoice $invoice Invoice. |
136 | 136 | */ |
137 | - protected function bank_details( $invoice ) { |
|
137 | + protected function bank_details($invoice) { |
|
138 | 138 | |
139 | 139 | // Get the invoice country and country $locale. |
140 | 140 | $country = $invoice->get_country(); |
141 | 141 | $locale = $this->get_country_locale(); |
142 | 142 | |
143 | 143 | // Get sortcode label in the $locale array and use appropriate one. |
144 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
144 | + $sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing'); |
|
145 | 145 | |
146 | 146 | $bank_fields = array( |
147 | - 'ac_name' => __( 'Account Name', 'invoicing' ), |
|
148 | - 'ac_no' => __( 'Account Number', 'invoicing' ), |
|
149 | - 'bank_name' => __( 'Bank Name', 'invoicing' ), |
|
150 | - 'ifsc' => __( 'IFSC code', 'invoicing' ), |
|
151 | - 'iban' => __( 'IBAN', 'invoicing' ), |
|
152 | - 'bic' => __( 'BIC/Swift code', 'invoicing' ), |
|
147 | + 'ac_name' => __('Account Name', 'invoicing'), |
|
148 | + 'ac_no' => __('Account Number', 'invoicing'), |
|
149 | + 'bank_name' => __('Bank Name', 'invoicing'), |
|
150 | + 'ifsc' => __('IFSC code', 'invoicing'), |
|
151 | + 'iban' => __('IBAN', 'invoicing'), |
|
152 | + 'bic' => __('BIC/Swift code', 'invoicing'), |
|
153 | 153 | 'sort_code' => $sortcode, |
154 | 154 | ); |
155 | 155 | |
156 | 156 | $bank_info = array(); |
157 | 157 | |
158 | - foreach ( $bank_fields as $field => $label ) { |
|
159 | - $value = $this->get_option( $field ); |
|
158 | + foreach ($bank_fields as $field => $label) { |
|
159 | + $value = $this->get_option($field); |
|
160 | 160 | |
161 | - if ( ! empty( $value ) ) { |
|
162 | - $bank_info[ $field ] = array( |
|
161 | + if (!empty($value)) { |
|
162 | + $bank_info[$field] = array( |
|
163 | 163 | 'label' => $label, |
164 | 164 | 'value' => $value, |
165 | 165 | ); |
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | - $bank_info = apply_filters( 'wpinv_bank_info', $bank_info ); |
|
169 | + $bank_info = apply_filters('wpinv_bank_info', $bank_info); |
|
170 | 170 | |
171 | - if ( empty( $bank_info ) ) { |
|
171 | + if (empty($bank_info)) { |
|
172 | 172 | return; |
173 | 173 | } |
174 | 174 | |
175 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) ) . '</h3>' . PHP_EOL; |
|
175 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html(apply_filters('wpinv_receipt_bank_details_title', __('Bank Details', 'invoicing'))) . '</h3>' . PHP_EOL; |
|
176 | 176 | |
177 | 177 | echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
178 | 178 | |
179 | - foreach ( $bank_info as $key => $data ) { |
|
180 | - echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . "</td></tr>" . PHP_EOL; |
|
179 | + foreach ($bank_info as $key => $data) { |
|
180 | + echo "<tr class='getpaid-bank-transfer-" . esc_attr($key) . "'><th class='font-weight-bold'>" . wp_kses_post($data['label']) . "</th><td class='w-75'>" . wp_kses_post(wptexturize($data['value'])) . "</td></tr>" . PHP_EOL; |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | echo '</table>'; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public function get_country_locale() { |
193 | 193 | |
194 | - if ( empty( $this->locale ) ) { |
|
194 | + if (empty($this->locale)) { |
|
195 | 195 | |
196 | 196 | // Locale information to be used - only those that are not 'Sort Code'. |
197 | 197 | $this->locale = apply_filters( |
@@ -199,42 +199,42 @@ discard block |
||
199 | 199 | array( |
200 | 200 | 'AU' => array( |
201 | 201 | 'sortcode' => array( |
202 | - 'label' => __( 'BSB', 'invoicing' ), |
|
202 | + 'label' => __('BSB', 'invoicing'), |
|
203 | 203 | ), |
204 | 204 | ), |
205 | 205 | 'CA' => array( |
206 | 206 | 'sortcode' => array( |
207 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
207 | + 'label' => __('Bank transit number', 'invoicing'), |
|
208 | 208 | ), |
209 | 209 | ), |
210 | 210 | 'IN' => array( |
211 | 211 | 'sortcode' => array( |
212 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
212 | + 'label' => __('IFSC', 'invoicing'), |
|
213 | 213 | ), |
214 | 214 | ), |
215 | 215 | 'IT' => array( |
216 | 216 | 'sortcode' => array( |
217 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
217 | + 'label' => __('Branch sort', 'invoicing'), |
|
218 | 218 | ), |
219 | 219 | ), |
220 | 220 | 'NZ' => array( |
221 | 221 | 'sortcode' => array( |
222 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
222 | + 'label' => __('Bank code', 'invoicing'), |
|
223 | 223 | ), |
224 | 224 | ), |
225 | 225 | 'SE' => array( |
226 | 226 | 'sortcode' => array( |
227 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
227 | + 'label' => __('Bank code', 'invoicing'), |
|
228 | 228 | ), |
229 | 229 | ), |
230 | 230 | 'US' => array( |
231 | 231 | 'sortcode' => array( |
232 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
232 | + 'label' => __('Routing number', 'invoicing'), |
|
233 | 233 | ), |
234 | 234 | ), |
235 | 235 | 'ZA' => array( |
236 | 236 | 'sortcode' => array( |
237 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
237 | + 'label' => __('Branch code', 'invoicing'), |
|
238 | 238 | ), |
239 | 239 | ), |
240 | 240 | ) |
@@ -251,51 +251,51 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @param array $admin_settings |
253 | 253 | */ |
254 | - public function admin_settings( $admin_settings ) { |
|
254 | + public function admin_settings($admin_settings) { |
|
255 | 255 | |
256 | - $admin_settings['bank_transfer_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
|
257 | - $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
256 | + $admin_settings['bank_transfer_desc']['std'] = __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing'); |
|
257 | + $admin_settings['bank_transfer_active']['desc'] = __('Enable bank transfer', 'invoicing'); |
|
258 | 258 | |
259 | - $locale = $this->get_country_locale(); |
|
259 | + $locale = $this->get_country_locale(); |
|
260 | 260 | |
261 | 261 | // Get sortcode label in the $locale array and use appropriate one. |
262 | 262 | $country = wpinv_default_billing_country(); |
263 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
263 | + $sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing'); |
|
264 | 264 | |
265 | 265 | $admin_settings['bank_transfer_ac_name'] = array( |
266 | 266 | 'type' => 'text', |
267 | 267 | 'id' => 'bank_transfer_ac_name', |
268 | - 'name' => __( 'Account Name', 'invoicing' ), |
|
268 | + 'name' => __('Account Name', 'invoicing'), |
|
269 | 269 | ); |
270 | 270 | |
271 | 271 | $admin_settings['bank_transfer_ac_no'] = array( |
272 | 272 | 'type' => 'text', |
273 | 273 | 'id' => 'bank_transfer_ac_no', |
274 | - 'name' => __( 'Account Number', 'invoicing' ), |
|
274 | + 'name' => __('Account Number', 'invoicing'), |
|
275 | 275 | ); |
276 | 276 | |
277 | 277 | $admin_settings['bank_transfer_bank_name'] = array( |
278 | 278 | 'type' => 'text', |
279 | 279 | 'id' => 'bank_transfer_bank_name', |
280 | - 'name' => __( 'Bank Name', 'invoicing' ), |
|
280 | + 'name' => __('Bank Name', 'invoicing'), |
|
281 | 281 | ); |
282 | 282 | |
283 | 283 | $admin_settings['bank_transfer_ifsc'] = array( |
284 | 284 | 'type' => 'text', |
285 | 285 | 'id' => 'bank_transfer_ifsc', |
286 | - 'name' => __( 'IFSC Code', 'invoicing' ), |
|
286 | + 'name' => __('IFSC Code', 'invoicing'), |
|
287 | 287 | ); |
288 | 288 | |
289 | 289 | $admin_settings['bank_transfer_iban'] = array( |
290 | 290 | 'type' => 'text', |
291 | 291 | 'id' => 'bank_transfer_iban', |
292 | - 'name' => __( 'IBAN', 'invoicing' ), |
|
292 | + 'name' => __('IBAN', 'invoicing'), |
|
293 | 293 | ); |
294 | 294 | |
295 | 295 | $admin_settings['bank_transfer_bic'] = array( |
296 | 296 | 'type' => 'text', |
297 | 297 | 'id' => 'bank_transfer_bic', |
298 | - 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
|
298 | + 'name' => __('BIC/Swift Code', 'invoicing'), |
|
299 | 299 | ); |
300 | 300 | |
301 | 301 | $admin_settings['bank_transfer_sort_code'] = array( |
@@ -306,10 +306,10 @@ discard block |
||
306 | 306 | |
307 | 307 | $admin_settings['bank_transfer_info'] = array( |
308 | 308 | 'id' => 'bank_transfer_info', |
309 | - 'name' => __( 'Instructions', 'invoicing' ), |
|
310 | - 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
|
309 | + 'name' => __('Instructions', 'invoicing'), |
|
310 | + 'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'), |
|
311 | 311 | 'type' => 'textarea', |
312 | - 'std' => __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ), |
|
312 | + 'std' => __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing'), |
|
313 | 313 | 'cols' => 50, |
314 | 314 | 'rows' => 5, |
315 | 315 | ); |
@@ -324,10 +324,10 @@ discard block |
||
324 | 324 | * @param GetPaid_Form_Item[] $items |
325 | 325 | * @return WPInv_Invoice |
326 | 326 | */ |
327 | - public function process_addons( $invoice, $items ) { |
|
327 | + public function process_addons($invoice, $items) { |
|
328 | 328 | |
329 | - foreach ( $items as $item ) { |
|
330 | - $invoice->add_item( $item ); |
|
329 | + foreach ($items as $item) { |
|
330 | + $invoice->add_item($item); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | $invoice->recalculate_total(); |
@@ -340,10 +340,10 @@ discard block |
||
340 | 340 | * |
341 | 341 | * @param WPInv_Subscription $subscription |
342 | 342 | */ |
343 | - public function maybe_renew_subscription( $subscription ) { |
|
343 | + public function maybe_renew_subscription($subscription) { |
|
344 | 344 | |
345 | 345 | // Ensure its our subscription && it's active. |
346 | - if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
346 | + if ($this->id == $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
347 | 347 | $subscription->create_payment(); |
348 | 348 | } |
349 | 349 | |
@@ -355,41 +355,41 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @param WPInv_Invoice $invoice |
357 | 357 | */ |
358 | - public function invoice_paid( $invoice ) { |
|
358 | + public function invoice_paid($invoice) { |
|
359 | 359 | |
360 | 360 | // Abort if not paid by bank transfer. |
361 | - if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
361 | + if ($this->id !== $invoice->get_gateway() || !$invoice->is_recurring()) { |
|
362 | 362 | return; |
363 | 363 | } |
364 | 364 | |
365 | 365 | // Is it a parent payment? |
366 | - if ( 0 == $invoice->get_parent_id() ) { |
|
366 | + if (0 == $invoice->get_parent_id()) { |
|
367 | 367 | |
368 | 368 | // (Maybe) activate subscriptions. |
369 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
369 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
370 | 370 | |
371 | - if ( ! empty( $subscriptions ) ) { |
|
372 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
371 | + if (!empty($subscriptions)) { |
|
372 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
373 | 373 | |
374 | - foreach ( $subscriptions as $subscription ) { |
|
375 | - if ( $subscription->exists() ) { |
|
376 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
377 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
374 | + foreach ($subscriptions as $subscription) { |
|
375 | + if ($subscription->exists()) { |
|
376 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
377 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
378 | 378 | |
379 | - $subscription->set_next_renewal_date( $expiry ); |
|
380 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
381 | - $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
379 | + $subscription->set_next_renewal_date($expiry); |
|
380 | + $subscription->set_date_created(current_time('mysql')); |
|
381 | + $subscription->set_profile_id('bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id()); |
|
382 | 382 | $subscription->activate(); |
383 | 383 | } |
384 | 384 | } |
385 | 385 | } |
386 | 386 | } else { |
387 | 387 | |
388 | - $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
388 | + $subscription = getpaid_get_subscription($invoice->get_subscription_id()); |
|
389 | 389 | |
390 | 390 | // Renew the subscription. |
391 | - if ( $subscription && $subscription->exists() ) { |
|
392 | - $subscription->add_payment( array(), $invoice ); |
|
391 | + if ($subscription && $subscription->exists()) { |
|
392 | + $subscription->add_payment(array(), $invoice); |
|
393 | 393 | $subscription->renew(); |
394 | 394 | } |
395 | 395 | } |
@@ -13,462 +13,462 @@ discard block |
||
13 | 13 | */ |
14 | 14 | abstract class GetPaid_Payment_Gateway { |
15 | 15 | |
16 | - /** |
|
17 | - * Set if the place checkout button should be renamed on selection. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $checkout_button_text; |
|
22 | - |
|
23 | - /** |
|
24 | - * Boolean whether the method is enabled. |
|
25 | - * |
|
26 | - * @var bool |
|
27 | - */ |
|
28 | - public $enabled = true; |
|
29 | - |
|
30 | - /** |
|
31 | - * Payment method id. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public $id; |
|
36 | - |
|
37 | - /** |
|
38 | - * Payment method order. |
|
39 | - * |
|
40 | - * @var int |
|
41 | - */ |
|
42 | - public $order = 10; |
|
43 | - |
|
44 | - /** |
|
45 | - * Payment method title for the frontend. |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $title; |
|
50 | - |
|
51 | - /** |
|
52 | - * Payment method description for the frontend. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - public $description; |
|
57 | - |
|
58 | - /** |
|
59 | - * Gateway title. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - public $method_title = ''; |
|
64 | - |
|
65 | - /** |
|
66 | - * Gateway description. |
|
67 | - * |
|
68 | - * @var string |
|
69 | - */ |
|
70 | - public $method_description = ''; |
|
71 | - |
|
72 | - /** |
|
73 | - * Countries this gateway is allowed for. |
|
74 | - * |
|
75 | - * @var array |
|
76 | - */ |
|
77 | - public $countries; |
|
78 | - |
|
79 | - /** |
|
80 | - * Currencies this gateway is allowed for. |
|
81 | - * |
|
82 | - * @var array |
|
83 | - */ |
|
84 | - public $currencies; |
|
85 | - |
|
86 | - /** |
|
87 | - * Currencies this gateway is not allowed for. |
|
88 | - * |
|
89 | - * @var array |
|
90 | - */ |
|
91 | - public $exclude_currencies; |
|
92 | - |
|
93 | - /** |
|
94 | - * Maximum transaction amount, zero does not define a maximum. |
|
95 | - * |
|
96 | - * @var int |
|
97 | - */ |
|
98 | - public $max_amount = 0; |
|
99 | - |
|
100 | - /** |
|
101 | - * Optional URL to view a transaction. |
|
102 | - * |
|
103 | - * @var string |
|
104 | - */ |
|
105 | - public $view_transaction_url = ''; |
|
106 | - |
|
107 | - /** |
|
108 | - * Optional URL to view a subscription. |
|
109 | - * |
|
110 | - * @var string |
|
111 | - */ |
|
112 | - public $view_subscription_url = ''; |
|
113 | - |
|
114 | - /** |
|
115 | - * Optional label to show for "new payment method" in the payment |
|
116 | - * method/token selection radio selection. |
|
117 | - * |
|
118 | - * @var string |
|
119 | - */ |
|
120 | - public $new_method_label = ''; |
|
121 | - |
|
122 | - /** |
|
123 | - * Contains a user's saved tokens for this gateway. |
|
124 | - * |
|
125 | - * @var array |
|
126 | - */ |
|
127 | - protected $tokens = array(); |
|
128 | - |
|
129 | - /** |
|
130 | - * An array of features that this gateway supports. |
|
131 | - * |
|
132 | - * @var array |
|
133 | - */ |
|
134 | - protected $supports = array(); |
|
135 | - |
|
136 | - /** |
|
137 | - * Class constructor. |
|
138 | - */ |
|
139 | - public function __construct() { |
|
140 | - |
|
141 | - // Register gateway. |
|
142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
143 | - |
|
144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
145 | - |
|
146 | - // Add support for various features. |
|
147 | - foreach ( $this->supports as $feature ) { |
|
148 | - add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
149 | - add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
150 | - add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
151 | - } |
|
152 | - |
|
153 | - // Invoice addons. |
|
154 | - if ( $this->supports( 'addons' ) ) { |
|
155 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
156 | - } |
|
157 | - |
|
158 | - // Gateway settings. |
|
159 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
160 | - |
|
161 | - // Gateway checkout fiellds. |
|
162 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
163 | - |
|
164 | - // Process payment. |
|
165 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
166 | - |
|
167 | - // Change the checkout button text. |
|
168 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
169 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
170 | - } |
|
171 | - |
|
172 | - // Check if a gateway is valid for a given currency. |
|
173 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
174 | - |
|
175 | - // Generate the transaction url. |
|
176 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
177 | - |
|
178 | - // Generate the subscription url. |
|
179 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
180 | - |
|
181 | - // Confirm payments. |
|
182 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
183 | - |
|
184 | - // Verify IPNs. |
|
185 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
186 | - |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Checks if this gateway is a given gateway. |
|
191 | - * |
|
192 | - * @since 1.0.19 |
|
193 | - * @return bool |
|
194 | - */ |
|
195 | - public function is( $gateway ) { |
|
196 | - return $gateway == $this->id; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Returns a users saved tokens for this gateway. |
|
201 | - * |
|
202 | - * @since 1.0.19 |
|
203 | - * @return array |
|
204 | - */ |
|
205 | - public function get_tokens( $sandbox = null ) { |
|
206 | - |
|
207 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
208 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
209 | - |
|
210 | - if ( is_array( $tokens ) ) { |
|
211 | - $this->tokens = $tokens; |
|
212 | - } |
|
16 | + /** |
|
17 | + * Set if the place checkout button should be renamed on selection. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $checkout_button_text; |
|
22 | + |
|
23 | + /** |
|
24 | + * Boolean whether the method is enabled. |
|
25 | + * |
|
26 | + * @var bool |
|
27 | + */ |
|
28 | + public $enabled = true; |
|
29 | + |
|
30 | + /** |
|
31 | + * Payment method id. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public $id; |
|
36 | + |
|
37 | + /** |
|
38 | + * Payment method order. |
|
39 | + * |
|
40 | + * @var int |
|
41 | + */ |
|
42 | + public $order = 10; |
|
43 | + |
|
44 | + /** |
|
45 | + * Payment method title for the frontend. |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $title; |
|
50 | + |
|
51 | + /** |
|
52 | + * Payment method description for the frontend. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + public $description; |
|
57 | + |
|
58 | + /** |
|
59 | + * Gateway title. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + public $method_title = ''; |
|
64 | + |
|
65 | + /** |
|
66 | + * Gateway description. |
|
67 | + * |
|
68 | + * @var string |
|
69 | + */ |
|
70 | + public $method_description = ''; |
|
71 | + |
|
72 | + /** |
|
73 | + * Countries this gateway is allowed for. |
|
74 | + * |
|
75 | + * @var array |
|
76 | + */ |
|
77 | + public $countries; |
|
78 | + |
|
79 | + /** |
|
80 | + * Currencies this gateway is allowed for. |
|
81 | + * |
|
82 | + * @var array |
|
83 | + */ |
|
84 | + public $currencies; |
|
85 | + |
|
86 | + /** |
|
87 | + * Currencies this gateway is not allowed for. |
|
88 | + * |
|
89 | + * @var array |
|
90 | + */ |
|
91 | + public $exclude_currencies; |
|
92 | + |
|
93 | + /** |
|
94 | + * Maximum transaction amount, zero does not define a maximum. |
|
95 | + * |
|
96 | + * @var int |
|
97 | + */ |
|
98 | + public $max_amount = 0; |
|
99 | + |
|
100 | + /** |
|
101 | + * Optional URL to view a transaction. |
|
102 | + * |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + public $view_transaction_url = ''; |
|
106 | + |
|
107 | + /** |
|
108 | + * Optional URL to view a subscription. |
|
109 | + * |
|
110 | + * @var string |
|
111 | + */ |
|
112 | + public $view_subscription_url = ''; |
|
113 | + |
|
114 | + /** |
|
115 | + * Optional label to show for "new payment method" in the payment |
|
116 | + * method/token selection radio selection. |
|
117 | + * |
|
118 | + * @var string |
|
119 | + */ |
|
120 | + public $new_method_label = ''; |
|
121 | + |
|
122 | + /** |
|
123 | + * Contains a user's saved tokens for this gateway. |
|
124 | + * |
|
125 | + * @var array |
|
126 | + */ |
|
127 | + protected $tokens = array(); |
|
128 | + |
|
129 | + /** |
|
130 | + * An array of features that this gateway supports. |
|
131 | + * |
|
132 | + * @var array |
|
133 | + */ |
|
134 | + protected $supports = array(); |
|
135 | + |
|
136 | + /** |
|
137 | + * Class constructor. |
|
138 | + */ |
|
139 | + public function __construct() { |
|
140 | + |
|
141 | + // Register gateway. |
|
142 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
143 | + |
|
144 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
145 | + |
|
146 | + // Add support for various features. |
|
147 | + foreach ( $this->supports as $feature ) { |
|
148 | + add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
149 | + add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
150 | + add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
151 | + } |
|
152 | + |
|
153 | + // Invoice addons. |
|
154 | + if ( $this->supports( 'addons' ) ) { |
|
155 | + add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
156 | + } |
|
157 | + |
|
158 | + // Gateway settings. |
|
159 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
160 | + |
|
161 | + // Gateway checkout fiellds. |
|
162 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
163 | + |
|
164 | + // Process payment. |
|
165 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
166 | + |
|
167 | + // Change the checkout button text. |
|
168 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
169 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
170 | + } |
|
171 | + |
|
172 | + // Check if a gateway is valid for a given currency. |
|
173 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
174 | + |
|
175 | + // Generate the transaction url. |
|
176 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
177 | + |
|
178 | + // Generate the subscription url. |
|
179 | + add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
180 | + |
|
181 | + // Confirm payments. |
|
182 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
183 | + |
|
184 | + // Verify IPNs. |
|
185 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
186 | + |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Checks if this gateway is a given gateway. |
|
191 | + * |
|
192 | + * @since 1.0.19 |
|
193 | + * @return bool |
|
194 | + */ |
|
195 | + public function is( $gateway ) { |
|
196 | + return $gateway == $this->id; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Returns a users saved tokens for this gateway. |
|
201 | + * |
|
202 | + * @since 1.0.19 |
|
203 | + * @return array |
|
204 | + */ |
|
205 | + public function get_tokens( $sandbox = null ) { |
|
206 | + |
|
207 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
208 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
209 | + |
|
210 | + if ( is_array( $tokens ) ) { |
|
211 | + $this->tokens = $tokens; |
|
212 | + } |
|
213 | 213 | } |
214 | 214 | |
215 | - if ( ! is_bool( $sandbox ) ) { |
|
216 | - return $this->tokens; |
|
217 | - } |
|
218 | - |
|
219 | - // Filter tokens. |
|
220 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
221 | - return wp_list_filter( $this->tokens, $args ); |
|
222 | - |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Saves a token for this gateway. |
|
227 | - * |
|
228 | - * @since 1.0.19 |
|
229 | - */ |
|
230 | - public function save_token( $token ) { |
|
231 | - |
|
232 | - $tokens = $this->get_tokens(); |
|
233 | - $tokens[] = $token; |
|
234 | - |
|
235 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
236 | - |
|
237 | - $this->tokens = $tokens; |
|
238 | - |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Return the title for admin screens. |
|
243 | - * |
|
244 | - * @return string |
|
245 | - */ |
|
246 | - public function get_method_title() { |
|
247 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Return the description for admin screens. |
|
252 | - * |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - public function get_method_description() { |
|
256 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Get the success url. |
|
261 | - * |
|
262 | - * @param WPInv_Invoice $invoice Invoice object. |
|
263 | - * @return string |
|
264 | - */ |
|
265 | - public function get_return_url( $invoice ) { |
|
266 | - |
|
267 | - // Payment success url |
|
268 | - $return_url = add_query_arg( |
|
269 | - array( |
|
270 | - 'payment-confirm' => $this->id, |
|
271 | - 'invoice_key' => $invoice->get_key(), |
|
272 | - 'utm_nooverride' => 1, |
|
273 | - ), |
|
274 | - wpinv_get_success_page_uri() |
|
275 | - ); |
|
276 | - |
|
277 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Confirms payments when rendering the success page. |
|
282 | - * |
|
283 | - * @param string $content Success page content. |
|
284 | - * @return string |
|
285 | - */ |
|
286 | - public function confirm_payment( $content ) { |
|
287 | - |
|
288 | - // Retrieve the invoice. |
|
289 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
290 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
291 | - |
|
292 | - // Ensure that it exists and that it is pending payment. |
|
293 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
294 | - return $content; |
|
295 | - } |
|
296 | - |
|
297 | - // Can the user view this invoice?? |
|
298 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
299 | - return $content; |
|
300 | - } |
|
301 | - |
|
302 | - // Show payment processing indicator. |
|
303 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Processes ipns and marks payments as complete. |
|
308 | - * |
|
309 | - * @return void |
|
310 | - */ |
|
311 | - public function verify_ipn() {} |
|
312 | - |
|
313 | - /** |
|
314 | - * Processes invoice addons. |
|
315 | - * |
|
316 | - * @param WPInv_Invoice $invoice |
|
317 | - * @param GetPaid_Form_Item[] $items |
|
318 | - * @return WPInv_Invoice |
|
319 | - */ |
|
320 | - public function process_addons( $invoice, $items ) { |
|
321 | - |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
326 | - * |
|
327 | - * @param string $transaction_url transaction url. |
|
328 | - * @param WPInv_Invoice $invoice Invoice object. |
|
329 | - * @return string transaction URL, or empty string. |
|
330 | - */ |
|
331 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
332 | - |
|
333 | - $transaction_id = $invoice->get_transaction_id(); |
|
334 | - |
|
335 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
336 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
337 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
338 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
339 | - } |
|
340 | - |
|
341 | - return $transaction_url; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
346 | - * |
|
347 | - * @param string $subscription_url transaction url. |
|
348 | - * @param WPInv_Subscription $subscription Subscription objectt. |
|
349 | - * @return string subscription URL, or empty string. |
|
350 | - */ |
|
351 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
352 | - |
|
353 | - $profile_id = $subscription->get_profile_id(); |
|
354 | - |
|
355 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
356 | - |
|
357 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
358 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
359 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
360 | - |
|
361 | - } |
|
362 | - |
|
363 | - return $subscription_url; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Check if the gateway is available for use. |
|
368 | - * |
|
369 | - * @return bool |
|
370 | - */ |
|
371 | - public function is_available() { |
|
372 | - return ! empty( $this->enabled ); |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Return the gateway's title. |
|
377 | - * |
|
378 | - * @return string |
|
379 | - */ |
|
380 | - public function get_title() { |
|
381 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * Return the gateway's description. |
|
386 | - * |
|
387 | - * @return string |
|
388 | - */ |
|
389 | - public function get_description() { |
|
390 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Process Payment. |
|
395 | - * |
|
396 | - * |
|
397 | - * @param WPInv_Invoice $invoice Invoice. |
|
398 | - * @param array $submission_data Posted checkout fields. |
|
399 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
400 | - * @return void |
|
401 | - */ |
|
402 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
403 | - // Process the payment then either redirect to the success page or the gateway. |
|
404 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * Process refund. |
|
409 | - * |
|
410 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
411 | - * a passed in amount. |
|
412 | - * |
|
413 | - * @param WPInv_Invoice $invoice Invoice. |
|
414 | - * @param float $amount Refund amount. |
|
415 | - * @param string $reason Refund reason. |
|
416 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
417 | - */ |
|
418 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
419 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Displays the payment fields, credit cards etc. |
|
424 | - * |
|
425 | - * @param int $invoice_id 0 or invoice id. |
|
426 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
427 | - */ |
|
428 | - public function payment_fields( $invoice_id, $form ) { |
|
429 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Filters the gateway settings. |
|
434 | - * |
|
435 | - * @param array $admin_settings |
|
436 | - */ |
|
437 | - public function admin_settings( $admin_settings ) { |
|
438 | - return $admin_settings; |
|
439 | - } |
|
440 | - |
|
441 | - /** |
|
442 | - * Retrieves the value of a gateway setting. |
|
443 | - * |
|
444 | - * @param string $option |
|
445 | - */ |
|
446 | - public function get_option( $option, $default = false ) { |
|
447 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * Check if a gateway supports a given feature. |
|
452 | - * |
|
453 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
454 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
455 | - * |
|
456 | - * @param string $feature string The name of a feature to test support for. |
|
457 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
458 | - * @since 1.0.19 |
|
459 | - */ |
|
460 | - public function supports( $feature ) { |
|
461 | - return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Returns the credit card form html. |
|
466 | - * |
|
467 | - * @param bool $save whether or not to display the save button. |
|
468 | - */ |
|
215 | + if ( ! is_bool( $sandbox ) ) { |
|
216 | + return $this->tokens; |
|
217 | + } |
|
218 | + |
|
219 | + // Filter tokens. |
|
220 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
221 | + return wp_list_filter( $this->tokens, $args ); |
|
222 | + |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Saves a token for this gateway. |
|
227 | + * |
|
228 | + * @since 1.0.19 |
|
229 | + */ |
|
230 | + public function save_token( $token ) { |
|
231 | + |
|
232 | + $tokens = $this->get_tokens(); |
|
233 | + $tokens[] = $token; |
|
234 | + |
|
235 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
236 | + |
|
237 | + $this->tokens = $tokens; |
|
238 | + |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Return the title for admin screens. |
|
243 | + * |
|
244 | + * @return string |
|
245 | + */ |
|
246 | + public function get_method_title() { |
|
247 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Return the description for admin screens. |
|
252 | + * |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + public function get_method_description() { |
|
256 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Get the success url. |
|
261 | + * |
|
262 | + * @param WPInv_Invoice $invoice Invoice object. |
|
263 | + * @return string |
|
264 | + */ |
|
265 | + public function get_return_url( $invoice ) { |
|
266 | + |
|
267 | + // Payment success url |
|
268 | + $return_url = add_query_arg( |
|
269 | + array( |
|
270 | + 'payment-confirm' => $this->id, |
|
271 | + 'invoice_key' => $invoice->get_key(), |
|
272 | + 'utm_nooverride' => 1, |
|
273 | + ), |
|
274 | + wpinv_get_success_page_uri() |
|
275 | + ); |
|
276 | + |
|
277 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Confirms payments when rendering the success page. |
|
282 | + * |
|
283 | + * @param string $content Success page content. |
|
284 | + * @return string |
|
285 | + */ |
|
286 | + public function confirm_payment( $content ) { |
|
287 | + |
|
288 | + // Retrieve the invoice. |
|
289 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
290 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
291 | + |
|
292 | + // Ensure that it exists and that it is pending payment. |
|
293 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
294 | + return $content; |
|
295 | + } |
|
296 | + |
|
297 | + // Can the user view this invoice?? |
|
298 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
299 | + return $content; |
|
300 | + } |
|
301 | + |
|
302 | + // Show payment processing indicator. |
|
303 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Processes ipns and marks payments as complete. |
|
308 | + * |
|
309 | + * @return void |
|
310 | + */ |
|
311 | + public function verify_ipn() {} |
|
312 | + |
|
313 | + /** |
|
314 | + * Processes invoice addons. |
|
315 | + * |
|
316 | + * @param WPInv_Invoice $invoice |
|
317 | + * @param GetPaid_Form_Item[] $items |
|
318 | + * @return WPInv_Invoice |
|
319 | + */ |
|
320 | + public function process_addons( $invoice, $items ) { |
|
321 | + |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
326 | + * |
|
327 | + * @param string $transaction_url transaction url. |
|
328 | + * @param WPInv_Invoice $invoice Invoice object. |
|
329 | + * @return string transaction URL, or empty string. |
|
330 | + */ |
|
331 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
332 | + |
|
333 | + $transaction_id = $invoice->get_transaction_id(); |
|
334 | + |
|
335 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
336 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
337 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
338 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
339 | + } |
|
340 | + |
|
341 | + return $transaction_url; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
346 | + * |
|
347 | + * @param string $subscription_url transaction url. |
|
348 | + * @param WPInv_Subscription $subscription Subscription objectt. |
|
349 | + * @return string subscription URL, or empty string. |
|
350 | + */ |
|
351 | + public function generate_subscription_url( $subscription_url, $subscription ) { |
|
352 | + |
|
353 | + $profile_id = $subscription->get_profile_id(); |
|
354 | + |
|
355 | + if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
356 | + |
|
357 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
358 | + $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
359 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
360 | + |
|
361 | + } |
|
362 | + |
|
363 | + return $subscription_url; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Check if the gateway is available for use. |
|
368 | + * |
|
369 | + * @return bool |
|
370 | + */ |
|
371 | + public function is_available() { |
|
372 | + return ! empty( $this->enabled ); |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Return the gateway's title. |
|
377 | + * |
|
378 | + * @return string |
|
379 | + */ |
|
380 | + public function get_title() { |
|
381 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * Return the gateway's description. |
|
386 | + * |
|
387 | + * @return string |
|
388 | + */ |
|
389 | + public function get_description() { |
|
390 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Process Payment. |
|
395 | + * |
|
396 | + * |
|
397 | + * @param WPInv_Invoice $invoice Invoice. |
|
398 | + * @param array $submission_data Posted checkout fields. |
|
399 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
400 | + * @return void |
|
401 | + */ |
|
402 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
403 | + // Process the payment then either redirect to the success page or the gateway. |
|
404 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * Process refund. |
|
409 | + * |
|
410 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
411 | + * a passed in amount. |
|
412 | + * |
|
413 | + * @param WPInv_Invoice $invoice Invoice. |
|
414 | + * @param float $amount Refund amount. |
|
415 | + * @param string $reason Refund reason. |
|
416 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
417 | + */ |
|
418 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
419 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Displays the payment fields, credit cards etc. |
|
424 | + * |
|
425 | + * @param int $invoice_id 0 or invoice id. |
|
426 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
427 | + */ |
|
428 | + public function payment_fields( $invoice_id, $form ) { |
|
429 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Filters the gateway settings. |
|
434 | + * |
|
435 | + * @param array $admin_settings |
|
436 | + */ |
|
437 | + public function admin_settings( $admin_settings ) { |
|
438 | + return $admin_settings; |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * Retrieves the value of a gateway setting. |
|
443 | + * |
|
444 | + * @param string $option |
|
445 | + */ |
|
446 | + public function get_option( $option, $default = false ) { |
|
447 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
448 | + } |
|
449 | + |
|
450 | + /** |
|
451 | + * Check if a gateway supports a given feature. |
|
452 | + * |
|
453 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
454 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
455 | + * |
|
456 | + * @param string $feature string The name of a feature to test support for. |
|
457 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
458 | + * @since 1.0.19 |
|
459 | + */ |
|
460 | + public function supports( $feature ) { |
|
461 | + return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Returns the credit card form html. |
|
466 | + * |
|
467 | + * @param bool $save whether or not to display the save button. |
|
468 | + */ |
|
469 | 469 | public function get_cc_form( $save = false ) { |
470 | 470 | |
471 | - ob_start(); |
|
471 | + ob_start(); |
|
472 | 472 | |
473 | 473 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
474 | 474 | |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | |
529 | 529 | <?php |
530 | 530 | foreach ( $months as $key => $month ) { |
531 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . "</option>" . PHP_EOL; |
|
531 | + echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . "</option>" . PHP_EOL; |
|
532 | 532 | } |
533 | 533 | ?> |
534 | 534 | |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | |
542 | 542 | <?php |
543 | 543 | foreach ( $years as $key => $year ) { |
544 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . "</option>" . PHP_EOL; |
|
544 | + echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . "</option>" . PHP_EOL; |
|
545 | 545 | } |
546 | 546 | ?> |
547 | 547 | |
@@ -559,13 +559,13 @@ discard block |
||
559 | 559 | 'name' => $this->id . '[cc_cvv2]', |
560 | 560 | 'id' => "$id_prefix-cc-cvv2", |
561 | 561 | 'label' => __( 'CCV', 'invoicing' ), |
562 | - 'label_type' => 'vertical', |
|
563 | - 'class' => 'form-control-sm', |
|
564 | - 'extra_attributes' => array( |
|
565 | - 'autocomplete' => 'cc-csc', |
|
566 | - ), |
|
562 | + 'label_type' => 'vertical', |
|
563 | + 'class' => 'form-control-sm', |
|
564 | + 'extra_attributes' => array( |
|
565 | + 'autocomplete' => 'cc-csc', |
|
566 | + ), |
|
567 | 567 | ), |
568 | - true |
|
568 | + true |
|
569 | 569 | ); |
570 | 570 | ?> |
571 | 571 | </div> |
@@ -574,192 +574,192 @@ discard block |
||
574 | 574 | |
575 | 575 | <?php |
576 | 576 | |
577 | - if ( $save ) { |
|
578 | - $this->save_payment_method_checkbox(); |
|
579 | - } |
|
577 | + if ( $save ) { |
|
578 | + $this->save_payment_method_checkbox(); |
|
579 | + } |
|
580 | 580 | |
581 | - ?> |
|
581 | + ?> |
|
582 | 582 | </div> |
583 | 583 | |
584 | 584 | </div> |
585 | 585 | <?php |
586 | 586 | |
587 | - return ob_get_clean(); |
|
587 | + return ob_get_clean(); |
|
588 | + |
|
589 | + } |
|
590 | + |
|
591 | + /** |
|
592 | + * Displays a new payment method entry form. |
|
593 | + * |
|
594 | + * @since 1.0.19 |
|
595 | + */ |
|
596 | + public function new_payment_method_entry( $form ) { |
|
597 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . " . </div>"; |
|
598 | + } |
|
599 | + |
|
600 | + /** |
|
601 | + * Grab and display our saved payment methods. |
|
602 | + * |
|
603 | + * @since 1.0.19 |
|
604 | + */ |
|
605 | + public function saved_payment_methods() { |
|
606 | + echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
607 | + |
|
608 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
609 | + $this->get_saved_payment_method_option_html( $token ); |
|
610 | + } |
|
611 | + |
|
612 | + $this->get_new_payment_method_option_html(); |
|
613 | + echo '</ul>'; |
|
588 | 614 | |
589 | 615 | } |
590 | 616 | |
591 | - /** |
|
592 | - * Displays a new payment method entry form. |
|
593 | - * |
|
594 | - * @since 1.0.19 |
|
595 | - */ |
|
596 | - public function new_payment_method_entry( $form ) { |
|
597 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . " . </div>"; |
|
598 | - } |
|
599 | - |
|
600 | - /** |
|
601 | - * Grab and display our saved payment methods. |
|
602 | - * |
|
603 | - * @since 1.0.19 |
|
604 | - */ |
|
605 | - public function saved_payment_methods() { |
|
606 | - echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
607 | - |
|
608 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
609 | - $this->get_saved_payment_method_option_html( $token ); |
|
610 | - } |
|
611 | - |
|
612 | - $this->get_new_payment_method_option_html(); |
|
613 | - echo '</ul>'; |
|
614 | - |
|
615 | - } |
|
616 | - |
|
617 | - /** |
|
618 | - * Gets saved payment method HTML from a token. |
|
619 | - * |
|
620 | - * @since 1.0.19 |
|
621 | - * @param array $token Payment Token. |
|
622 | - * @return string Generated payment method HTML |
|
623 | - */ |
|
624 | - public function get_saved_payment_method_option_html( $token ) { |
|
625 | - |
|
626 | - printf( |
|
627 | - '<li class="getpaid-payment-method form-group"> |
|
617 | + /** |
|
618 | + * Gets saved payment method HTML from a token. |
|
619 | + * |
|
620 | + * @since 1.0.19 |
|
621 | + * @param array $token Payment Token. |
|
622 | + * @return string Generated payment method HTML |
|
623 | + */ |
|
624 | + public function get_saved_payment_method_option_html( $token ) { |
|
625 | + |
|
626 | + printf( |
|
627 | + '<li class="getpaid-payment-method form-group"> |
|
628 | 628 | <label> |
629 | 629 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" data-currency="%5$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
630 | 630 | <span>%3$s</span> |
631 | 631 | </label> |
632 | 632 | </li>', |
633 | - esc_attr( $this->id ), |
|
634 | - esc_attr( $token['id'] ), |
|
635 | - esc_html( $token['name'] ), |
|
636 | - checked( empty( $token['default'] ), false, false ), |
|
637 | - empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
638 | - ); |
|
639 | - |
|
640 | - } |
|
641 | - |
|
642 | - /** |
|
643 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
644 | - * |
|
645 | - * @since 1.0.19 |
|
646 | - */ |
|
647 | - public function get_new_payment_method_option_html() { |
|
648 | - |
|
649 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
650 | - |
|
651 | - printf( |
|
652 | - '<li class="getpaid-new-payment-method"> |
|
633 | + esc_attr( $this->id ), |
|
634 | + esc_attr( $token['id'] ), |
|
635 | + esc_html( $token['name'] ), |
|
636 | + checked( empty( $token['default'] ), false, false ), |
|
637 | + empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
638 | + ); |
|
639 | + |
|
640 | + } |
|
641 | + |
|
642 | + /** |
|
643 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
644 | + * |
|
645 | + * @since 1.0.19 |
|
646 | + */ |
|
647 | + public function get_new_payment_method_option_html() { |
|
648 | + |
|
649 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
650 | + |
|
651 | + printf( |
|
652 | + '<li class="getpaid-new-payment-method"> |
|
653 | 653 | <label> |
654 | 654 | <input name="getpaid-%1$s-payment-method" type="radio" data-currency="none" value="new" style="width:auto;" /> |
655 | 655 | <span>%2$s</span> |
656 | 656 | </label> |
657 | 657 | </li>', |
658 | - esc_attr( $this->id ), |
|
659 | - esc_html( $label ) |
|
660 | - ); |
|
661 | - |
|
662 | - } |
|
663 | - |
|
664 | - /** |
|
665 | - * Outputs a checkbox for saving a new payment method to the database. |
|
666 | - * |
|
667 | - * @since 1.0.19 |
|
668 | - */ |
|
669 | - public function save_payment_method_checkbox() { |
|
670 | - |
|
671 | - aui()->input( |
|
672 | - array( |
|
673 | - 'type' => 'checkbox', |
|
674 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
675 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
676 | - 'required' => false, |
|
677 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
678 | - 'value' => 'true', |
|
679 | - 'checked' => true, |
|
680 | - 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
681 | - ), |
|
682 | - true |
|
683 | - ); |
|
684 | - |
|
685 | - } |
|
686 | - |
|
687 | - /** |
|
688 | - * Registers the gateway. |
|
689 | - * |
|
690 | - * @return array |
|
691 | - */ |
|
692 | - public function register_gateway( $gateways ) { |
|
693 | - |
|
694 | - $gateways[ $this->id ] = array( |
|
695 | - |
|
696 | - 'admin_label' => $this->method_title, |
|
658 | + esc_attr( $this->id ), |
|
659 | + esc_html( $label ) |
|
660 | + ); |
|
661 | + |
|
662 | + } |
|
663 | + |
|
664 | + /** |
|
665 | + * Outputs a checkbox for saving a new payment method to the database. |
|
666 | + * |
|
667 | + * @since 1.0.19 |
|
668 | + */ |
|
669 | + public function save_payment_method_checkbox() { |
|
670 | + |
|
671 | + aui()->input( |
|
672 | + array( |
|
673 | + 'type' => 'checkbox', |
|
674 | + 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
675 | + 'id' => esc_attr( uniqid( $this->id ) ), |
|
676 | + 'required' => false, |
|
677 | + 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
678 | + 'value' => 'true', |
|
679 | + 'checked' => true, |
|
680 | + 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
681 | + ), |
|
682 | + true |
|
683 | + ); |
|
684 | + |
|
685 | + } |
|
686 | + |
|
687 | + /** |
|
688 | + * Registers the gateway. |
|
689 | + * |
|
690 | + * @return array |
|
691 | + */ |
|
692 | + public function register_gateway( $gateways ) { |
|
693 | + |
|
694 | + $gateways[ $this->id ] = array( |
|
695 | + |
|
696 | + 'admin_label' => $this->method_title, |
|
697 | 697 | 'checkout_label' => $this->title, |
698 | - 'ordering' => $this->order, |
|
698 | + 'ordering' => $this->order, |
|
699 | 699 | |
700 | - ); |
|
700 | + ); |
|
701 | 701 | |
702 | - return $gateways; |
|
702 | + return $gateways; |
|
703 | 703 | |
704 | - } |
|
704 | + } |
|
705 | 705 | |
706 | - /** |
|
707 | - * Checks whether or not this is a sandbox request. |
|
708 | - * |
|
709 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
710 | - * @return bool |
|
711 | - */ |
|
712 | - public function is_sandbox( $invoice = null ) { |
|
706 | + /** |
|
707 | + * Checks whether or not this is a sandbox request. |
|
708 | + * |
|
709 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
710 | + * @return bool |
|
711 | + */ |
|
712 | + public function is_sandbox( $invoice = null ) { |
|
713 | 713 | |
714 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
715 | - return $invoice->get_mode() == 'test'; |
|
716 | - } |
|
714 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
715 | + return $invoice->get_mode() == 'test'; |
|
716 | + } |
|
717 | 717 | |
718 | - return wpinv_is_test_mode( $this->id ); |
|
718 | + return wpinv_is_test_mode( $this->id ); |
|
719 | 719 | |
720 | - } |
|
720 | + } |
|
721 | 721 | |
722 | - /** |
|
723 | - * Renames the checkout button |
|
724 | - * |
|
725 | - * @return string |
|
726 | - */ |
|
727 | - public function rename_checkout_button() { |
|
728 | - return $this->checkout_button_text; |
|
729 | - } |
|
722 | + /** |
|
723 | + * Renames the checkout button |
|
724 | + * |
|
725 | + * @return string |
|
726 | + */ |
|
727 | + public function rename_checkout_button() { |
|
728 | + return $this->checkout_button_text; |
|
729 | + } |
|
730 | 730 | |
731 | - /** |
|
732 | - * Validate gateway currency |
|
733 | - * |
|
734 | - * @return bool |
|
735 | - */ |
|
736 | - public function validate_currency( $validation, $currency ) { |
|
731 | + /** |
|
732 | + * Validate gateway currency |
|
733 | + * |
|
734 | + * @return bool |
|
735 | + */ |
|
736 | + public function validate_currency( $validation, $currency ) { |
|
737 | 737 | |
738 | - // Required currencies. |
|
739 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
740 | - return false; |
|
741 | - } |
|
738 | + // Required currencies. |
|
739 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
740 | + return false; |
|
741 | + } |
|
742 | 742 | |
743 | - // Excluded currencies. |
|
744 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
745 | - return false; |
|
746 | - } |
|
743 | + // Excluded currencies. |
|
744 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
745 | + return false; |
|
746 | + } |
|
747 | 747 | |
748 | - return $validation; |
|
749 | - } |
|
748 | + return $validation; |
|
749 | + } |
|
750 | 750 | |
751 | - /** |
|
752 | - * Displays an error |
|
753 | - * |
|
754 | - */ |
|
755 | - public function show_error( $code, $message, $type ) { |
|
751 | + /** |
|
752 | + * Displays an error |
|
753 | + * |
|
754 | + */ |
|
755 | + public function show_error( $code, $message, $type ) { |
|
756 | 756 | |
757 | - if ( is_admin() ) { |
|
758 | - getpaid_admin()->{"show_$type"}( $message ); |
|
759 | - } |
|
757 | + if ( is_admin() ) { |
|
758 | + getpaid_admin()->{"show_$type"}( $message ); |
|
759 | + } |
|
760 | 760 | |
761 | - wpinv_set_error( $code, $message, $type ); |
|
761 | + wpinv_set_error( $code, $message, $type ); |
|
762 | 762 | |
763 | - } |
|
763 | + } |
|
764 | 764 | |
765 | 765 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Abstaract Payment Gateway class. |
@@ -139,50 +139,50 @@ discard block |
||
139 | 139 | public function __construct() { |
140 | 140 | |
141 | 141 | // Register gateway. |
142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
142 | + add_filter('wpinv_payment_gateways', array($this, 'register_gateway')); |
|
143 | 143 | |
144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
144 | + $this->enabled = wpinv_is_gateway_active($this->id); |
|
145 | 145 | |
146 | 146 | // Add support for various features. |
147 | - foreach ( $this->supports as $feature ) { |
|
148 | - add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
149 | - add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
150 | - add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
147 | + foreach ($this->supports as $feature) { |
|
148 | + add_filter("wpinv_{$this->id}_support_{$feature}", '__return_true'); |
|
149 | + add_filter("getpaid_{$this->id}_support_{$feature}", '__return_true'); |
|
150 | + add_filter("getpaid_{$this->id}_supports_{$feature}", '__return_true'); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // Invoice addons. |
154 | - if ( $this->supports( 'addons' ) ) { |
|
155 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
154 | + if ($this->supports('addons')) { |
|
155 | + add_action("getpaid_process_{$this->id}_invoice_addons", array($this, 'process_addons'), 10, 2); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | // Gateway settings. |
159 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
159 | + add_filter("wpinv_gateway_settings_{$this->id}", array($this, 'admin_settings')); |
|
160 | 160 | |
161 | 161 | // Gateway checkout fiellds. |
162 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
162 | + add_action("wpinv_{$this->id}_cc_form", array($this, 'payment_fields'), 10, 2); |
|
163 | 163 | |
164 | 164 | // Process payment. |
165 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
165 | + add_action("getpaid_gateway_{$this->id}", array($this, 'process_payment'), 10, 3); |
|
166 | 166 | |
167 | 167 | // Change the checkout button text. |
168 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
169 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
168 | + if (!empty($this->checkout_button_text)) { |
|
169 | + add_filter("getpaid_gateway_{$this->id}_checkout_button_label", array($this, 'rename_checkout_button')); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | // Check if a gateway is valid for a given currency. |
173 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
173 | + add_filter("getpaid_gateway_{$this->id}_is_valid_for_currency", array($this, 'validate_currency'), 10, 2); |
|
174 | 174 | |
175 | 175 | // Generate the transaction url. |
176 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
176 | + add_filter("getpaid_gateway_{$this->id}_transaction_url", array($this, 'filter_transaction_url'), 10, 2); |
|
177 | 177 | |
178 | 178 | // Generate the subscription url. |
179 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
179 | + add_filter('getpaid_remote_subscription_profile_url', array($this, 'generate_subscription_url'), 10, 2); |
|
180 | 180 | |
181 | 181 | // Confirm payments. |
182 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
182 | + add_filter("wpinv_payment_confirm_{$this->id}", array($this, 'confirm_payment'), 10, 2); |
|
183 | 183 | |
184 | 184 | // Verify IPNs. |
185 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
185 | + add_action("wpinv_verify_{$this->id}_ipn", array($this, 'verify_ipn')); |
|
186 | 186 | |
187 | 187 | } |
188 | 188 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @since 1.0.19 |
193 | 193 | * @return bool |
194 | 194 | */ |
195 | - public function is( $gateway ) { |
|
195 | + public function is($gateway) { |
|
196 | 196 | return $gateway == $this->id; |
197 | 197 | } |
198 | 198 | |
@@ -202,23 +202,23 @@ discard block |
||
202 | 202 | * @since 1.0.19 |
203 | 203 | * @return array |
204 | 204 | */ |
205 | - public function get_tokens( $sandbox = null ) { |
|
205 | + public function get_tokens($sandbox = null) { |
|
206 | 206 | |
207 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
208 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
207 | + if (is_user_logged_in() && $this->supports('tokens') && 0 == count($this->tokens)) { |
|
208 | + $tokens = get_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", true); |
|
209 | 209 | |
210 | - if ( is_array( $tokens ) ) { |
|
210 | + if (is_array($tokens)) { |
|
211 | 211 | $this->tokens = $tokens; |
212 | 212 | } |
213 | 213 | } |
214 | 214 | |
215 | - if ( ! is_bool( $sandbox ) ) { |
|
215 | + if (!is_bool($sandbox)) { |
|
216 | 216 | return $this->tokens; |
217 | 217 | } |
218 | 218 | |
219 | 219 | // Filter tokens. |
220 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
221 | - return wp_list_filter( $this->tokens, $args ); |
|
220 | + $args = array('type' => $sandbox ? 'sandbox' : 'live'); |
|
221 | + return wp_list_filter($this->tokens, $args); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 | |
@@ -227,12 +227,12 @@ discard block |
||
227 | 227 | * |
228 | 228 | * @since 1.0.19 |
229 | 229 | */ |
230 | - public function save_token( $token ) { |
|
230 | + public function save_token($token) { |
|
231 | 231 | |
232 | 232 | $tokens = $this->get_tokens(); |
233 | 233 | $tokens[] = $token; |
234 | 234 | |
235 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
235 | + update_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens); |
|
236 | 236 | |
237 | 237 | $this->tokens = $tokens; |
238 | 238 | |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | * @return string |
245 | 245 | */ |
246 | 246 | public function get_method_title() { |
247 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
247 | + return apply_filters('getpaid_gateway_method_title', $this->method_title, $this); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @return string |
254 | 254 | */ |
255 | 255 | public function get_method_description() { |
256 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
256 | + return apply_filters('getpaid_gateway_method_description', $this->method_description, $this); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @param WPInv_Invoice $invoice Invoice object. |
263 | 263 | * @return string |
264 | 264 | */ |
265 | - public function get_return_url( $invoice ) { |
|
265 | + public function get_return_url($invoice) { |
|
266 | 266 | |
267 | 267 | // Payment success url |
268 | 268 | $return_url = add_query_arg( |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | wpinv_get_success_page_uri() |
275 | 275 | ); |
276 | 276 | |
277 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
277 | + return apply_filters('getpaid_gateway_success_url', $return_url, $invoice, $this); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -283,24 +283,24 @@ discard block |
||
283 | 283 | * @param string $content Success page content. |
284 | 284 | * @return string |
285 | 285 | */ |
286 | - public function confirm_payment( $content ) { |
|
286 | + public function confirm_payment($content) { |
|
287 | 287 | |
288 | 288 | // Retrieve the invoice. |
289 | 289 | $invoice_id = getpaid_get_current_invoice_id(); |
290 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
290 | + $invoice = wpinv_get_invoice($invoice_id); |
|
291 | 291 | |
292 | 292 | // Ensure that it exists and that it is pending payment. |
293 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
293 | + if (empty($invoice_id) || !$invoice->needs_payment()) { |
|
294 | 294 | return $content; |
295 | 295 | } |
296 | 296 | |
297 | 297 | // Can the user view this invoice?? |
298 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
298 | + if (!wpinv_user_can_view_invoice($invoice)) { |
|
299 | 299 | return $content; |
300 | 300 | } |
301 | 301 | |
302 | 302 | // Show payment processing indicator. |
303 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
303 | + return wpinv_get_template_html('wpinv-payment-processing.php', compact('invoice')); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | * @param GetPaid_Form_Item[] $items |
318 | 318 | * @return WPInv_Invoice |
319 | 319 | */ |
320 | - public function process_addons( $invoice, $items ) { |
|
320 | + public function process_addons($invoice, $items) { |
|
321 | 321 | |
322 | 322 | } |
323 | 323 | |
@@ -328,14 +328,14 @@ discard block |
||
328 | 328 | * @param WPInv_Invoice $invoice Invoice object. |
329 | 329 | * @return string transaction URL, or empty string. |
330 | 330 | */ |
331 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
331 | + public function filter_transaction_url($transaction_url, $invoice) { |
|
332 | 332 | |
333 | - $transaction_id = $invoice->get_transaction_id(); |
|
333 | + $transaction_id = $invoice->get_transaction_id(); |
|
334 | 334 | |
335 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
336 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
337 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
338 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
335 | + if (!empty($this->view_transaction_url) && !empty($transaction_id)) { |
|
336 | + $transaction_url = sprintf($this->view_transaction_url, $transaction_id); |
|
337 | + $replace = $this->is_sandbox($invoice) ? 'sandbox' : ''; |
|
338 | + $transaction_url = str_replace('{sandbox}', $replace, $transaction_url); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | return $transaction_url; |
@@ -348,15 +348,15 @@ discard block |
||
348 | 348 | * @param WPInv_Subscription $subscription Subscription objectt. |
349 | 349 | * @return string subscription URL, or empty string. |
350 | 350 | */ |
351 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
351 | + public function generate_subscription_url($subscription_url, $subscription) { |
|
352 | 352 | |
353 | - $profile_id = $subscription->get_profile_id(); |
|
353 | + $profile_id = $subscription->get_profile_id(); |
|
354 | 354 | |
355 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
355 | + if ($this->id == $subscription->get_gateway() && !empty($this->view_subscription_url) && !empty($profile_id)) { |
|
356 | 356 | |
357 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
358 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
359 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
357 | + $subscription_url = sprintf($this->view_subscription_url, $profile_id); |
|
358 | + $replace = $this->is_sandbox($subscription->get_parent_invoice()) ? 'sandbox' : ''; |
|
359 | + $subscription_url = str_replace('{sandbox}', $replace, $subscription_url); |
|
360 | 360 | |
361 | 361 | } |
362 | 362 | |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * @return bool |
370 | 370 | */ |
371 | 371 | public function is_available() { |
372 | - return ! empty( $this->enabled ); |
|
372 | + return !empty($this->enabled); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | /** |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | * @return string |
379 | 379 | */ |
380 | 380 | public function get_title() { |
381 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
381 | + return apply_filters('getpaid_gateway_title', $this->title, $this); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | /** |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | * @return string |
388 | 388 | */ |
389 | 389 | public function get_description() { |
390 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
390 | + return apply_filters('getpaid_gateway_description', $this->description, $this); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | /** |
@@ -399,9 +399,9 @@ discard block |
||
399 | 399 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
400 | 400 | * @return void |
401 | 401 | */ |
402 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
402 | + public function process_payment($invoice, $submission_data, $submission) { |
|
403 | 403 | // Process the payment then either redirect to the success page or the gateway. |
404 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
404 | + do_action('getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission); |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | /** |
@@ -415,8 +415,8 @@ discard block |
||
415 | 415 | * @param string $reason Refund reason. |
416 | 416 | * @return WP_Error|bool True or false based on success, or a WP_Error object. |
417 | 417 | */ |
418 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
419 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
418 | + public function process_refund($invoice, $amount = null, $reason = '') { |
|
419 | + return apply_filters('getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | /** |
@@ -425,8 +425,8 @@ discard block |
||
425 | 425 | * @param int $invoice_id 0 or invoice id. |
426 | 426 | * @param GetPaid_Payment_Form $form Current payment form. |
427 | 427 | */ |
428 | - public function payment_fields( $invoice_id, $form ) { |
|
429 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
428 | + public function payment_fields($invoice_id, $form) { |
|
429 | + do_action('getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | /** |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | * |
435 | 435 | * @param array $admin_settings |
436 | 436 | */ |
437 | - public function admin_settings( $admin_settings ) { |
|
437 | + public function admin_settings($admin_settings) { |
|
438 | 438 | return $admin_settings; |
439 | 439 | } |
440 | 440 | |
@@ -443,8 +443,8 @@ discard block |
||
443 | 443 | * |
444 | 444 | * @param string $option |
445 | 445 | */ |
446 | - public function get_option( $option, $default = false ) { |
|
447 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
446 | + public function get_option($option, $default = false) { |
|
447 | + return wpinv_get_option($this->id . '_' . $option, $default); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
@@ -457,8 +457,8 @@ discard block |
||
457 | 457 | * @return bool True if the gateway supports the feature, false otherwise. |
458 | 458 | * @since 1.0.19 |
459 | 459 | */ |
460 | - public function supports( $feature ) { |
|
461 | - return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
460 | + public function supports($feature) { |
|
461 | + return getpaid_payment_gateway_supports($this->id, $feature); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | /** |
@@ -466,36 +466,36 @@ discard block |
||
466 | 466 | * |
467 | 467 | * @param bool $save whether or not to display the save button. |
468 | 468 | */ |
469 | - public function get_cc_form( $save = false ) { |
|
469 | + public function get_cc_form($save = false) { |
|
470 | 470 | |
471 | 471 | ob_start(); |
472 | 472 | |
473 | - $id_prefix = esc_attr( uniqid( $this->id ) ); |
|
473 | + $id_prefix = esc_attr(uniqid($this->id)); |
|
474 | 474 | |
475 | 475 | $months = array( |
476 | - '01' => __( 'January', 'invoicing' ), |
|
477 | - '02' => __( 'February', 'invoicing' ), |
|
478 | - '03' => __( 'March', 'invoicing' ), |
|
479 | - '04' => __( 'April', 'invoicing' ), |
|
480 | - '05' => __( 'May', 'invoicing' ), |
|
481 | - '06' => __( 'June', 'invoicing' ), |
|
482 | - '07' => __( 'July', 'invoicing' ), |
|
483 | - '08' => __( 'August', 'invoicing' ), |
|
484 | - '09' => __( 'September', 'invoicing' ), |
|
485 | - '10' => __( 'October', 'invoicing' ), |
|
486 | - '11' => __( 'November', 'invoicing' ), |
|
487 | - '12' => __( 'December', 'invoicing' ), |
|
476 | + '01' => __('January', 'invoicing'), |
|
477 | + '02' => __('February', 'invoicing'), |
|
478 | + '03' => __('March', 'invoicing'), |
|
479 | + '04' => __('April', 'invoicing'), |
|
480 | + '05' => __('May', 'invoicing'), |
|
481 | + '06' => __('June', 'invoicing'), |
|
482 | + '07' => __('July', 'invoicing'), |
|
483 | + '08' => __('August', 'invoicing'), |
|
484 | + '09' => __('September', 'invoicing'), |
|
485 | + '10' => __('October', 'invoicing'), |
|
486 | + '11' => __('November', 'invoicing'), |
|
487 | + '12' => __('December', 'invoicing'), |
|
488 | 488 | ); |
489 | 489 | |
490 | - $year = (int) date( 'Y', current_time( 'timestamp' ) ); |
|
490 | + $year = (int) date('Y', current_time('timestamp')); |
|
491 | 491 | $years = array(); |
492 | 492 | |
493 | - for ( $i = 0; $i <= 10; $i++ ) { |
|
494 | - $years[ $year + $i ] = $year + $i; |
|
493 | + for ($i = 0; $i <= 10; $i++) { |
|
494 | + $years[$year + $i] = $year + $i; |
|
495 | 495 | } |
496 | 496 | |
497 | 497 | ?> |
498 | - <div class="<?php echo esc_attr( $this->id ); ?>-cc-form getpaid-cc-form mt-1"> |
|
498 | + <div class="<?php echo esc_attr($this->id); ?>-cc-form getpaid-cc-form mt-1"> |
|
499 | 499 | |
500 | 500 | |
501 | 501 | <div class="getpaid-cc-card-inner"> |
@@ -504,14 +504,14 @@ discard block |
||
504 | 504 | <div class="col-12"> |
505 | 505 | |
506 | 506 | <div class="form-group"> |
507 | - <label for="<?php echo esc_attr( "$id_prefix-cc-number" ); ?>"><?php esc_html_e( 'Card number', 'invoicing' ); ?></label> |
|
507 | + <label for="<?php echo esc_attr("$id_prefix-cc-number"); ?>"><?php esc_html_e('Card number', 'invoicing'); ?></label> |
|
508 | 508 | <div class="input-group input-group-sm"> |
509 | 509 | <div class="input-group-prepend "> |
510 | 510 | <span class="input-group-text"> |
511 | 511 | <i class="fa fa-credit-card"></i> |
512 | 512 | </span> |
513 | 513 | </div> |
514 | - <input type="text" name="<?php echo esc_attr( $this->id . '[cc_number]' ); ?>" id="<?php echo esc_attr( "$id_prefix-cc-number" ); ?>" class="form-control form-control-sm" autocomplete="cc-number"> |
|
514 | + <input type="text" name="<?php echo esc_attr($this->id . '[cc_number]'); ?>" id="<?php echo esc_attr("$id_prefix-cc-number"); ?>" class="form-control form-control-sm" autocomplete="cc-number"> |
|
515 | 515 | </div> |
516 | 516 | </div> |
517 | 517 | |
@@ -519,16 +519,16 @@ discard block |
||
519 | 519 | |
520 | 520 | <div class="col-12"> |
521 | 521 | <div class="form-group"> |
522 | - <label><?php esc_html_e( 'Expiration', 'invoicing' ); ?></label> |
|
522 | + <label><?php esc_html_e('Expiration', 'invoicing'); ?></label> |
|
523 | 523 | <div class="form-row"> |
524 | 524 | |
525 | 525 | <div class="col"> |
526 | - <select class="form-control form-control-sm" autocomplete="cc-exp-month" name="<?php echo esc_attr( $this->id ); ?>[cc_expire_month]"> |
|
527 | - <option disabled selected="selected"><?php esc_html_e( 'MM', 'invoicing' ); ?></option> |
|
526 | + <select class="form-control form-control-sm" autocomplete="cc-exp-month" name="<?php echo esc_attr($this->id); ?>[cc_expire_month]"> |
|
527 | + <option disabled selected="selected"><?php esc_html_e('MM', 'invoicing'); ?></option> |
|
528 | 528 | |
529 | 529 | <?php |
530 | - foreach ( $months as $key => $month ) { |
|
531 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . "</option>" . PHP_EOL; |
|
530 | + foreach ($months as $key => $month) { |
|
531 | + echo "<option value='" . esc_attr($key) . "'>" . esc_html($month) . "</option>" . PHP_EOL; |
|
532 | 532 | } |
533 | 533 | ?> |
534 | 534 | |
@@ -536,12 +536,12 @@ discard block |
||
536 | 536 | </div> |
537 | 537 | |
538 | 538 | <div class="col"> |
539 | - <select class="form-control form-control-sm" autocomplete="cc-exp-year" name="<?php echo esc_attr( $this->id ); ?>[cc_expire_year]"> |
|
540 | - <option disabled selected="selected"><?php esc_html_e( 'YY', 'invoicing' ); ?></option> |
|
539 | + <select class="form-control form-control-sm" autocomplete="cc-exp-year" name="<?php echo esc_attr($this->id); ?>[cc_expire_year]"> |
|
540 | + <option disabled selected="selected"><?php esc_html_e('YY', 'invoicing'); ?></option> |
|
541 | 541 | |
542 | 542 | <?php |
543 | - foreach ( $years as $key => $year ) { |
|
544 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . "</option>" . PHP_EOL; |
|
543 | + foreach ($years as $key => $year) { |
|
544 | + echo "<option value='" . esc_attr($key) . "'>" . esc_html($year) . "</option>" . PHP_EOL; |
|
545 | 545 | } |
546 | 546 | ?> |
547 | 547 | |
@@ -558,7 +558,7 @@ discard block |
||
558 | 558 | array( |
559 | 559 | 'name' => $this->id . '[cc_cvv2]', |
560 | 560 | 'id' => "$id_prefix-cc-cvv2", |
561 | - 'label' => __( 'CCV', 'invoicing' ), |
|
561 | + 'label' => __('CCV', 'invoicing'), |
|
562 | 562 | 'label_type' => 'vertical', |
563 | 563 | 'class' => 'form-control-sm', |
564 | 564 | 'extra_attributes' => array( |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | |
575 | 575 | <?php |
576 | 576 | |
577 | - if ( $save ) { |
|
577 | + if ($save) { |
|
578 | 578 | $this->save_payment_method_checkbox(); |
579 | 579 | } |
580 | 580 | |
@@ -593,8 +593,8 @@ discard block |
||
593 | 593 | * |
594 | 594 | * @since 1.0.19 |
595 | 595 | */ |
596 | - public function new_payment_method_entry( $form ) { |
|
597 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . " . </div>"; |
|
596 | + public function new_payment_method_entry($form) { |
|
597 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses($form, getpaid_allowed_html()) . " . </div>"; |
|
598 | 598 | } |
599 | 599 | |
600 | 600 | /** |
@@ -603,10 +603,10 @@ discard block |
||
603 | 603 | * @since 1.0.19 |
604 | 604 | */ |
605 | 605 | public function saved_payment_methods() { |
606 | - echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
606 | + echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr(count($this->get_tokens($this->is_sandbox()))) . '">'; |
|
607 | 607 | |
608 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
609 | - $this->get_saved_payment_method_option_html( $token ); |
|
608 | + foreach ($this->get_tokens($this->is_sandbox()) as $token) { |
|
609 | + $this->get_saved_payment_method_option_html($token); |
|
610 | 610 | } |
611 | 611 | |
612 | 612 | $this->get_new_payment_method_option_html(); |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | * @param array $token Payment Token. |
622 | 622 | * @return string Generated payment method HTML |
623 | 623 | */ |
624 | - public function get_saved_payment_method_option_html( $token ) { |
|
624 | + public function get_saved_payment_method_option_html($token) { |
|
625 | 625 | |
626 | 626 | printf( |
627 | 627 | '<li class="getpaid-payment-method form-group"> |
@@ -630,11 +630,11 @@ discard block |
||
630 | 630 | <span>%3$s</span> |
631 | 631 | </label> |
632 | 632 | </li>', |
633 | - esc_attr( $this->id ), |
|
634 | - esc_attr( $token['id'] ), |
|
635 | - esc_html( $token['name'] ), |
|
636 | - checked( empty( $token['default'] ), false, false ), |
|
637 | - empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
633 | + esc_attr($this->id), |
|
634 | + esc_attr($token['id']), |
|
635 | + esc_html($token['name']), |
|
636 | + checked(empty($token['default']), false, false), |
|
637 | + empty($token['currency']) ? 'none' : esc_attr($token['currency']) |
|
638 | 638 | ); |
639 | 639 | |
640 | 640 | } |
@@ -646,7 +646,7 @@ discard block |
||
646 | 646 | */ |
647 | 647 | public function get_new_payment_method_option_html() { |
648 | 648 | |
649 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
649 | + $label = apply_filters('getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __('Use a new payment method', 'invoicing'), $this); |
|
650 | 650 | |
651 | 651 | printf( |
652 | 652 | '<li class="getpaid-new-payment-method"> |
@@ -655,8 +655,8 @@ discard block |
||
655 | 655 | <span>%2$s</span> |
656 | 656 | </label> |
657 | 657 | </li>', |
658 | - esc_attr( $this->id ), |
|
659 | - esc_html( $label ) |
|
658 | + esc_attr($this->id), |
|
659 | + esc_html($label) |
|
660 | 660 | ); |
661 | 661 | |
662 | 662 | } |
@@ -671,10 +671,10 @@ discard block |
||
671 | 671 | aui()->input( |
672 | 672 | array( |
673 | 673 | 'type' => 'checkbox', |
674 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
675 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
674 | + 'name' => esc_attr("getpaid-$this->id-new-payment-method"), |
|
675 | + 'id' => esc_attr(uniqid($this->id)), |
|
676 | 676 | 'required' => false, |
677 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
677 | + 'label' => esc_html__('Save payment method', 'invoicing'), |
|
678 | 678 | 'value' => 'true', |
679 | 679 | 'checked' => true, |
680 | 680 | 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
@@ -689,9 +689,9 @@ discard block |
||
689 | 689 | * |
690 | 690 | * @return array |
691 | 691 | */ |
692 | - public function register_gateway( $gateways ) { |
|
692 | + public function register_gateway($gateways) { |
|
693 | 693 | |
694 | - $gateways[ $this->id ] = array( |
|
694 | + $gateways[$this->id] = array( |
|
695 | 695 | |
696 | 696 | 'admin_label' => $this->method_title, |
697 | 697 | 'checkout_label' => $this->title, |
@@ -709,13 +709,13 @@ discard block |
||
709 | 709 | * @param WPInv_Invoice|null $invoice Invoice object or null. |
710 | 710 | * @return bool |
711 | 711 | */ |
712 | - public function is_sandbox( $invoice = null ) { |
|
712 | + public function is_sandbox($invoice = null) { |
|
713 | 713 | |
714 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
714 | + if (!empty($invoice) && !$invoice->needs_payment()) { |
|
715 | 715 | return $invoice->get_mode() == 'test'; |
716 | 716 | } |
717 | 717 | |
718 | - return wpinv_is_test_mode( $this->id ); |
|
718 | + return wpinv_is_test_mode($this->id); |
|
719 | 719 | |
720 | 720 | } |
721 | 721 | |
@@ -733,15 +733,15 @@ discard block |
||
733 | 733 | * |
734 | 734 | * @return bool |
735 | 735 | */ |
736 | - public function validate_currency( $validation, $currency ) { |
|
736 | + public function validate_currency($validation, $currency) { |
|
737 | 737 | |
738 | 738 | // Required currencies. |
739 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
739 | + if (!empty($this->currencies) && !in_array($currency, $this->currencies)) { |
|
740 | 740 | return false; |
741 | 741 | } |
742 | 742 | |
743 | 743 | // Excluded currencies. |
744 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
744 | + if (!empty($this->exclude_currencies) && in_array($currency, $this->exclude_currencies)) { |
|
745 | 745 | return false; |
746 | 746 | } |
747 | 747 | |
@@ -752,13 +752,13 @@ discard block |
||
752 | 752 | * Displays an error |
753 | 753 | * |
754 | 754 | */ |
755 | - public function show_error( $code, $message, $type ) { |
|
755 | + public function show_error($code, $message, $type) { |
|
756 | 756 | |
757 | - if ( is_admin() ) { |
|
758 | - getpaid_admin()->{"show_$type"}( $message ); |
|
757 | + if (is_admin()) { |
|
758 | + getpaid_admin()->{"show_$type"}($message); |
|
759 | 759 | } |
760 | 760 | |
761 | - wpinv_set_error( $code, $message, $type ); |
|
761 | + wpinv_set_error($code, $message, $type); |
|
762 | 762 | |
763 | 763 | } |
764 | 764 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Authorize.net Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
27 | + protected $supports = array('subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @var array |
54 | 54 | */ |
55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
55 | + public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD'); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * URL to view a transaction. |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function __construct() { |
68 | 68 | |
69 | - $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
|
70 | - $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
|
71 | - $this->notify_url = getpaid_get_non_query_string_ipn_url( $this->id ); |
|
69 | + $this->title = __('Credit Card / Debit Card', 'invoicing'); |
|
70 | + $this->method_title = __('Authorize.Net', 'invoicing'); |
|
71 | + $this->notify_url = getpaid_get_non_query_string_ipn_url($this->id); |
|
72 | 72 | |
73 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
74 | - add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
73 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
74 | + add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice')); |
|
75 | 75 | parent::__construct(); |
76 | 76 | } |
77 | 77 | |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | * @param int $invoice_id 0 or invoice id. |
82 | 82 | * @param GetPaid_Payment_Form $form Current payment form. |
83 | 83 | */ |
84 | - public function payment_fields( $invoice_id, $form ) { |
|
84 | + public function payment_fields($invoice_id, $form) { |
|
85 | 85 | |
86 | 86 | // Let the user select a payment method. |
87 | 87 | $this->saved_payment_methods(); |
88 | 88 | |
89 | 89 | // Show the credit card entry form. |
90 | - $this->new_payment_method_entry( $this->get_cc_form( true ) ); |
|
90 | + $this->new_payment_method_entry($this->get_cc_form(true)); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -100,79 +100,79 @@ discard block |
||
100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
101 | 101 | * @return string|WP_Error Payment profile id. |
102 | 102 | */ |
103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
103 | + public function create_customer_profile($invoice, $submission_data, $save = true) { |
|
104 | 104 | |
105 | 105 | // Remove non-digits from the number |
106 | - $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
106 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
107 | 107 | |
108 | 108 | // Generate args. |
109 | 109 | $args = array( |
110 | 110 | 'createCustomerProfileRequest' => array( |
111 | 111 | 'merchantAuthentication' => $this->get_auth_params(), |
112 | 112 | 'profile' => array( |
113 | - 'merchantCustomerId' => getpaid_limit_length( $invoice->get_user_id(), 20 ), |
|
114 | - 'description' => getpaid_limit_length( $invoice->get_full_name(), 255 ), |
|
115 | - 'email' => getpaid_limit_length( $invoice->get_email(), 255 ), |
|
113 | + 'merchantCustomerId' => getpaid_limit_length($invoice->get_user_id(), 20), |
|
114 | + 'description' => getpaid_limit_length($invoice->get_full_name(), 255), |
|
115 | + 'email' => getpaid_limit_length($invoice->get_email(), 255), |
|
116 | 116 | 'paymentProfiles' => array( |
117 | 117 | 'customerType' => 'individual', |
118 | 118 | |
119 | 119 | // Billing information. |
120 | 120 | 'billTo' => array( |
121 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
122 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
123 | - 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
124 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
125 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
126 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
127 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
121 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
122 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
123 | + 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
124 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
125 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
126 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
127 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
128 | 128 | ), |
129 | 129 | |
130 | 130 | // Payment information. |
131 | - 'payment' => $this->get_payment_information( $submission_data['authorizenet'] ), |
|
131 | + 'payment' => $this->get_payment_information($submission_data['authorizenet']), |
|
132 | 132 | ), |
133 | 133 | ), |
134 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
134 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
135 | 135 | ), |
136 | 136 | ); |
137 | 137 | |
138 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice ); |
|
138 | + $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice); |
|
139 | 139 | |
140 | - if ( is_wp_error( $response ) ) { |
|
140 | + if (is_wp_error($response)) { |
|
141 | 141 | |
142 | 142 | // In case the payment profile already exists remotely. |
143 | - if ( 'dup_payment_profile' == $response->get_error_code() ) { |
|
144 | - $customer_profile_id = strtok( $response->get_error_message(), '.' ); |
|
145 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id ); |
|
146 | - return strtok( '.' ); |
|
143 | + if ('dup_payment_profile' == $response->get_error_code()) { |
|
144 | + $customer_profile_id = strtok($response->get_error_message(), '.'); |
|
145 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id); |
|
146 | + return strtok('.'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | // In case the customer profile already exists remotely. |
150 | - if ( 'E00039' == $response->get_error_code() ) { |
|
151 | - $customer_profile_id = str_replace( 'A duplicate record with ID ', '', $response->get_error_message() ); |
|
152 | - $customer_profile_id = str_replace( ' already exists.', '', $customer_profile_id ); |
|
153 | - return $this->create_customer_payment_profile( trim( $customer_profile_id ), $invoice, $submission_data, $save ); |
|
150 | + if ('E00039' == $response->get_error_code()) { |
|
151 | + $customer_profile_id = str_replace('A duplicate record with ID ', '', $response->get_error_message()); |
|
152 | + $customer_profile_id = str_replace(' already exists.', '', $customer_profile_id); |
|
153 | + return $this->create_customer_payment_profile(trim($customer_profile_id), $invoice, $submission_data, $save); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | return $response; |
157 | 157 | } |
158 | 158 | |
159 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId ); |
|
159 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId); |
|
160 | 160 | |
161 | 161 | // Save the payment token. |
162 | - if ( $save ) { |
|
162 | + if ($save) { |
|
163 | 163 | $this->save_token( |
164 | 164 | array( |
165 | 165 | 'id' => $response->customerPaymentProfileIdList[0], |
166 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
166 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
167 | 167 | 'default' => true, |
168 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
168 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
169 | 169 | ) |
170 | 170 | ); |
171 | 171 | } |
172 | 172 | |
173 | 173 | // Add a note about the validation response. |
174 | 174 | $invoice->add_note( |
175 | - sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ), |
|
175 | + sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]), |
|
176 | 176 | false, |
177 | 177 | false, |
178 | 178 | true |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * @return string|WP_Error Profile id. |
190 | 190 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
191 | 191 | */ |
192 | - public function get_customer_profile( $profile_id ) { |
|
192 | + public function get_customer_profile($profile_id) { |
|
193 | 193 | |
194 | 194 | // Generate args. |
195 | 195 | $args = array( |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | ), |
200 | 200 | ); |
201 | 201 | |
202 | - return $this->post( $args, false ); |
|
202 | + return $this->post($args, false); |
|
203 | 203 | |
204 | 204 | } |
205 | 205 | |
@@ -214,18 +214,18 @@ discard block |
||
214 | 214 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
215 | 215 | * @return string|WP_Error Profile id. |
216 | 216 | */ |
217 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
217 | + public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) { |
|
218 | 218 | |
219 | 219 | // Remove non-digits from the number |
220 | - $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
220 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
221 | 221 | |
222 | 222 | // Prepare card details. |
223 | - $payment_information = $this->get_payment_information( $submission_data['authorizenet'] ); |
|
223 | + $payment_information = $this->get_payment_information($submission_data['authorizenet']); |
|
224 | 224 | |
225 | 225 | // Authorize.NET does not support saving the same card twice. |
226 | - $cached_information = $this->retrieve_payment_profile_from_cache( $payment_information, $customer_profile, $invoice ); |
|
226 | + $cached_information = $this->retrieve_payment_profile_from_cache($payment_information, $customer_profile, $invoice); |
|
227 | 227 | |
228 | - if ( $cached_information ) { |
|
228 | + if ($cached_information) { |
|
229 | 229 | return $cached_information; |
230 | 230 | } |
231 | 231 | |
@@ -238,34 +238,34 @@ discard block |
||
238 | 238 | |
239 | 239 | // Billing information. |
240 | 240 | 'billTo' => array( |
241 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
242 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
243 | - 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
244 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
245 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
246 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
247 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
241 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
242 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
243 | + 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
244 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
245 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
246 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
247 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
248 | 248 | ), |
249 | 249 | |
250 | 250 | // Payment information. |
251 | 251 | 'payment' => $payment_information, |
252 | 252 | ), |
253 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
253 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
254 | 254 | ), |
255 | 255 | ); |
256 | 256 | |
257 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
257 | + $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice); |
|
258 | 258 | |
259 | - if ( is_wp_error( $response ) ) { |
|
259 | + if (is_wp_error($response)) { |
|
260 | 260 | |
261 | 261 | // In case the payment profile already exists remotely. |
262 | - if ( 'dup_payment_profile' == $response->get_error_code() ) { |
|
263 | - $customer_profile_id = strtok( $response->get_error_message(), '.' ); |
|
264 | - $payment_profile_id = strtok( '.' ); |
|
265 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id ); |
|
262 | + if ('dup_payment_profile' == $response->get_error_code()) { |
|
263 | + $customer_profile_id = strtok($response->get_error_message(), '.'); |
|
264 | + $payment_profile_id = strtok('.'); |
|
265 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id); |
|
266 | 266 | |
267 | 267 | // Cache payment profile id. |
268 | - $this->add_payment_profile_to_cache( $payment_information, $payment_profile_id ); |
|
268 | + $this->add_payment_profile_to_cache($payment_information, $payment_profile_id); |
|
269 | 269 | |
270 | 270 | return $payment_profile_id; |
271 | 271 | } |
@@ -274,29 +274,29 @@ discard block |
||
274 | 274 | } |
275 | 275 | |
276 | 276 | // Save the payment token. |
277 | - if ( $save ) { |
|
277 | + if ($save) { |
|
278 | 278 | $this->save_token( |
279 | 279 | array( |
280 | 280 | 'id' => $response->customerPaymentProfileId, |
281 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
281 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' ···· ' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
282 | 282 | 'default' => true, |
283 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
283 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
284 | 284 | ) |
285 | 285 | ); |
286 | 286 | } |
287 | 287 | |
288 | 288 | // Cache payment profile id. |
289 | - $this->add_payment_profile_to_cache( $payment_information, $response->customerPaymentProfileId ); |
|
289 | + $this->add_payment_profile_to_cache($payment_information, $response->customerPaymentProfileId); |
|
290 | 290 | |
291 | 291 | // Add a note about the validation response. |
292 | 292 | $invoice->add_note( |
293 | - sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ), |
|
293 | + sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse), |
|
294 | 294 | false, |
295 | 295 | false, |
296 | 296 | true |
297 | 297 | ); |
298 | 298 | |
299 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile ); |
|
299 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile); |
|
300 | 300 | |
301 | 301 | return $response->customerPaymentProfileId; |
302 | 302 | } |
@@ -308,12 +308,12 @@ discard block |
||
308 | 308 | * @param array $payment_details. |
309 | 309 | * @return array|false Profile id. |
310 | 310 | */ |
311 | - public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
311 | + public function retrieve_payment_profile_from_cache($payment_details, $customer_profile, $invoice) { |
|
312 | 312 | |
313 | - $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
314 | - $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
313 | + $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
314 | + $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
315 | 315 | |
316 | - if ( ! is_array( $cached_information ) || ! array_key_exists( $payment_details, $cached_information ) ) { |
|
316 | + if (!is_array($cached_information) || !array_key_exists($payment_details, $cached_information)) { |
|
317 | 317 | return false; |
318 | 318 | } |
319 | 319 | |
@@ -322,13 +322,13 @@ discard block |
||
322 | 322 | 'getCustomerPaymentProfileRequest' => array( |
323 | 323 | 'merchantAuthentication' => $this->get_auth_params(), |
324 | 324 | 'customerProfileId' => $customer_profile, |
325 | - 'customerPaymentProfileId' => $cached_information[ $payment_details ], |
|
325 | + 'customerPaymentProfileId' => $cached_information[$payment_details], |
|
326 | 326 | ), |
327 | 327 | ); |
328 | 328 | |
329 | - $response = $this->post( $args, $invoice ); |
|
329 | + $response = $this->post($args, $invoice); |
|
330 | 330 | |
331 | - return is_wp_error( $response ) ? false : $cached_information[ $payment_details ]; |
|
331 | + return is_wp_error($response) ? false : $cached_information[$payment_details]; |
|
332 | 332 | |
333 | 333 | } |
334 | 334 | |
@@ -339,14 +339,14 @@ discard block |
||
339 | 339 | * @param array $payment_details. |
340 | 340 | * @param string $payment_profile_id. |
341 | 341 | */ |
342 | - public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
342 | + public function add_payment_profile_to_cache($payment_details, $payment_profile_id) { |
|
343 | 343 | |
344 | - $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
345 | - $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
|
346 | - $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
344 | + $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
345 | + $cached_information = is_array($cached_information) ? $cached_information : array(); |
|
346 | + $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
347 | 347 | |
348 | - $cached_information[ $payment_details ] = $payment_profile_id; |
|
349 | - update_option( 'getpaid_authorize_net_cached_profiles', $cached_information ); |
|
348 | + $cached_information[$payment_details] = $payment_profile_id; |
|
349 | + update_option('getpaid_authorize_net_cached_profiles', $cached_information); |
|
350 | 350 | |
351 | 351 | } |
352 | 352 | |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | * @return string|WP_Error Profile id. |
360 | 360 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
361 | 361 | */ |
362 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
362 | + public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) { |
|
363 | 363 | |
364 | 364 | // Generate args. |
365 | 365 | $args = array( |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | ), |
371 | 371 | ); |
372 | 372 | |
373 | - return $this->post( $args, false ); |
|
373 | + return $this->post($args, false); |
|
374 | 374 | |
375 | 375 | } |
376 | 376 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
384 | 384 | * @return WP_Error|object |
385 | 385 | */ |
386 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
386 | + public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) { |
|
387 | 387 | |
388 | 388 | // Generate args. |
389 | 389 | $args = array( |
@@ -403,28 +403,28 @@ discard block |
||
403 | 403 | ), |
404 | 404 | ), |
405 | 405 | 'order' => array( |
406 | - 'invoiceNumber' => getpaid_limit_length( $invoice->get_number(), 20 ), |
|
406 | + 'invoiceNumber' => getpaid_limit_length($invoice->get_number(), 20), |
|
407 | 407 | ), |
408 | - 'lineItems' => array( 'lineItem' => $this->get_line_items( $invoice ) ), |
|
408 | + 'lineItems' => array('lineItem' => $this->get_line_items($invoice)), |
|
409 | 409 | 'tax' => array( |
410 | 410 | 'amount' => $invoice->get_total_tax(), |
411 | - 'name' => __( 'TAX', 'invoicing' ), |
|
411 | + 'name' => __('TAX', 'invoicing'), |
|
412 | 412 | ), |
413 | - 'poNumber' => getpaid_limit_length( $invoice->get_number(), 25 ), |
|
413 | + 'poNumber' => getpaid_limit_length($invoice->get_number(), 25), |
|
414 | 414 | 'customer' => array( |
415 | - 'id' => getpaid_limit_length( $invoice->get_user_id(), 25 ), |
|
416 | - 'email' => getpaid_limit_length( $invoice->get_email(), 25 ), |
|
415 | + 'id' => getpaid_limit_length($invoice->get_user_id(), 25), |
|
416 | + 'email' => getpaid_limit_length($invoice->get_email(), 25), |
|
417 | 417 | ), |
418 | 418 | 'customerIP' => $invoice->get_ip(), |
419 | 419 | ), |
420 | 420 | ), |
421 | 421 | ); |
422 | 422 | |
423 | - if ( 0 == $invoice->get_total_tax() ) { |
|
424 | - unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
423 | + if (0 == $invoice->get_total_tax()) { |
|
424 | + unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
425 | 425 | } |
426 | 426 | |
427 | - return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
427 | + return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice); |
|
428 | 428 | |
429 | 429 | } |
430 | 430 | |
@@ -434,29 +434,29 @@ discard block |
||
434 | 434 | * @param stdClass $result Api response. |
435 | 435 | * @param WPInv_Invoice $invoice Invoice. |
436 | 436 | */ |
437 | - public function process_charge_response( $result, $invoice ) { |
|
437 | + public function process_charge_response($result, $invoice) { |
|
438 | 438 | |
439 | 439 | wpinv_clear_errors(); |
440 | 440 | $response_code = (int) $result->transactionResponse->responseCode; |
441 | 441 | |
442 | 442 | // Succeeded. |
443 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
443 | + if (1 == $response_code || 4 == $response_code) { |
|
444 | 444 | |
445 | 445 | // Maybe set a transaction id. |
446 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
447 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
446 | + if (!empty($result->transactionResponse->transId)) { |
|
447 | + $invoice->set_transaction_id($result->transactionResponse->transId); |
|
448 | 448 | } |
449 | 449 | |
450 | - $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
450 | + $invoice->add_note(sprintf(__('Authentication code: %1$s (%2$s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true); |
|
451 | 451 | |
452 | - if ( 1 == $response_code ) { |
|
452 | + if (1 == $response_code) { |
|
453 | 453 | return $invoice->mark_paid(); |
454 | 454 | } |
455 | 455 | |
456 | - $invoice->set_status( 'wpi-onhold' ); |
|
456 | + $invoice->set_status('wpi-onhold'); |
|
457 | 457 | $invoice->add_note( |
458 | 458 | sprintf( |
459 | - __( 'Held for review: %s', 'invoicing' ), |
|
459 | + __('Held for review: %s', 'invoicing'), |
|
460 | 460 | $result->transactionResponse->messages->message[0]->description |
461 | 461 | ) |
462 | 462 | ); |
@@ -465,11 +465,11 @@ discard block |
||
465 | 465 | |
466 | 466 | } |
467 | 467 | |
468 | - wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
|
468 | + wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing')); |
|
469 | 469 | |
470 | - if ( ! empty( $result->transactionResponse->errors ) ) { |
|
470 | + if (!empty($result->transactionResponse->errors)) { |
|
471 | 471 | $errors = (object) $result->transactionResponse->errors; |
472 | - wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) ); |
|
472 | + wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText)); |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | } |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | * @param array $card Card details. |
482 | 482 | * @return array |
483 | 483 | */ |
484 | - public function get_payment_information( $card ) { |
|
484 | + public function get_payment_information($card) { |
|
485 | 485 | return array( |
486 | 486 | |
487 | 487 | 'creditCard' => array( |
@@ -500,8 +500,8 @@ discard block |
||
500 | 500 | * @param WPInv_Invoice $invoice Invoice. |
501 | 501 | * @return string |
502 | 502 | */ |
503 | - public function get_customer_profile_meta_name( $invoice ) { |
|
504 | - return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
503 | + public function get_customer_profile_meta_name($invoice) { |
|
504 | + return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | /** |
@@ -512,34 +512,34 @@ discard block |
||
512 | 512 | * @param WPInv_Invoice $invoice |
513 | 513 | * @return WP_Error|string The payment profile id |
514 | 514 | */ |
515 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
515 | + public function validate_submission_data($submission_data, $invoice) { |
|
516 | 516 | |
517 | 517 | // Validate authentication details. |
518 | 518 | $auth = $this->get_auth_params(); |
519 | 519 | |
520 | - if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) { |
|
521 | - return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing' ) ); |
|
520 | + if (empty($auth['name']) || empty($auth['transactionKey'])) { |
|
521 | + return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing')); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | // Validate the payment method. |
525 | - if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) { |
|
526 | - return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing' ) ); |
|
525 | + if (empty($submission_data['getpaid-authorizenet-payment-method'])) { |
|
526 | + return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing')); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | // Are we adding a new payment method? |
530 | - if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) { |
|
530 | + if ('new' != $submission_data['getpaid-authorizenet-payment-method']) { |
|
531 | 531 | return $submission_data['getpaid-authorizenet-payment-method']; |
532 | 532 | } |
533 | 533 | |
534 | 534 | // Retrieve the customer profile id. |
535 | - $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
535 | + $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
536 | 536 | |
537 | 537 | // Create payment method. |
538 | - if ( empty( $profile_id ) ) { |
|
539 | - return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
538 | + if (empty($profile_id)) { |
|
539 | + return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
540 | 540 | } |
541 | 541 | |
542 | - return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
542 | + return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
543 | 543 | |
544 | 544 | } |
545 | 545 | |
@@ -550,32 +550,32 @@ discard block |
||
550 | 550 | * @param WPInv_Invoice $invoice Invoice. |
551 | 551 | * @return array |
552 | 552 | */ |
553 | - public function get_line_items( $invoice ) { |
|
553 | + public function get_line_items($invoice) { |
|
554 | 554 | $items = array(); |
555 | 555 | |
556 | - foreach ( $invoice->get_items() as $item ) { |
|
556 | + foreach ($invoice->get_items() as $item) { |
|
557 | 557 | |
558 | 558 | $amount = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
559 | 559 | $items[] = array( |
560 | - 'itemId' => getpaid_limit_length( $item->get_id(), 31 ), |
|
561 | - 'name' => getpaid_limit_length( $item->get_raw_name(), 31 ), |
|
562 | - 'description' => getpaid_limit_length( $item->get_description(), 255 ), |
|
563 | - 'quantity' => (string) ( $invoice->get_template() == 'amount' ? 1 : $item->get_quantity() ), |
|
560 | + 'itemId' => getpaid_limit_length($item->get_id(), 31), |
|
561 | + 'name' => getpaid_limit_length($item->get_raw_name(), 31), |
|
562 | + 'description' => getpaid_limit_length($item->get_description(), 255), |
|
563 | + 'quantity' => (string) ($invoice->get_template() == 'amount' ? 1 : $item->get_quantity()), |
|
564 | 564 | 'unitPrice' => (float) $amount, |
565 | 565 | 'taxable' => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(), |
566 | 566 | ); |
567 | 567 | |
568 | 568 | } |
569 | 569 | |
570 | - foreach ( $invoice->get_fees() as $fee_name => $fee ) { |
|
570 | + foreach ($invoice->get_fees() as $fee_name => $fee) { |
|
571 | 571 | |
572 | - $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
572 | + $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
573 | 573 | |
574 | - if ( $amount > 0 ) { |
|
574 | + if ($amount > 0) { |
|
575 | 575 | $items[] = array( |
576 | - 'itemId' => getpaid_limit_length( $fee_name, 31 ), |
|
577 | - 'name' => getpaid_limit_length( $fee_name, 31 ), |
|
578 | - 'description' => getpaid_limit_length( $fee_name, 255 ), |
|
576 | + 'itemId' => getpaid_limit_length($fee_name, 31), |
|
577 | + 'name' => getpaid_limit_length($fee_name, 31), |
|
578 | + 'description' => getpaid_limit_length($fee_name, 255), |
|
579 | 579 | 'quantity' => '1', |
580 | 580 | 'unitPrice' => (float) $amount, |
581 | 581 | 'taxable' => false, |
@@ -595,36 +595,36 @@ discard block |
||
595 | 595 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
596 | 596 | * @return array |
597 | 597 | */ |
598 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
598 | + public function process_payment($invoice, $submission_data, $submission) { |
|
599 | 599 | |
600 | 600 | // Validate the submitted data. |
601 | - $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
|
601 | + $payment_profile_id = $this->validate_submission_data($submission_data, $invoice); |
|
602 | 602 | |
603 | 603 | // Do we have an error? |
604 | - if ( is_wp_error( $payment_profile_id ) ) { |
|
605 | - wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() ); |
|
606 | - wpinv_send_back_to_checkout( $invoice ); |
|
604 | + if (is_wp_error($payment_profile_id)) { |
|
605 | + wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message()); |
|
606 | + wpinv_send_back_to_checkout($invoice); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | // Save the payment method to the order. |
610 | - update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id ); |
|
610 | + update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id); |
|
611 | 611 | |
612 | 612 | // Check if this is a subscription or not. |
613 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
614 | - if ( ! empty( $subscriptions ) ) { |
|
615 | - $this->process_subscription( $invoice, $subscriptions ); |
|
613 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
614 | + if (!empty($subscriptions)) { |
|
615 | + $this->process_subscription($invoice, $subscriptions); |
|
616 | 616 | } |
617 | 617 | |
618 | 618 | // If it is free, send to the success page. |
619 | - if ( ! $invoice->needs_payment() ) { |
|
619 | + if (!$invoice->needs_payment()) { |
|
620 | 620 | $invoice->mark_paid(); |
621 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
621 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | // Charge the payment profile. |
625 | - $this->process_initial_payment( $invoice ); |
|
625 | + $this->process_initial_payment($invoice); |
|
626 | 626 | |
627 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
627 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
628 | 628 | |
629 | 629 | exit; |
630 | 630 | |
@@ -635,23 +635,23 @@ discard block |
||
635 | 635 | * |
636 | 636 | * @param WPInv_Invoice $invoice Invoice. |
637 | 637 | */ |
638 | - protected function process_initial_payment( $invoice ) { |
|
638 | + protected function process_initial_payment($invoice) { |
|
639 | 639 | |
640 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
641 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
642 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
640 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
641 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
642 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
643 | 643 | |
644 | 644 | // Do we have an error? |
645 | - if ( is_wp_error( $result ) ) { |
|
646 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
647 | - wpinv_send_back_to_checkout( $invoice ); |
|
645 | + if (is_wp_error($result)) { |
|
646 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
647 | + wpinv_send_back_to_checkout($invoice); |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | // Process the response. |
651 | - $this->process_charge_response( $result, $invoice ); |
|
651 | + $this->process_charge_response($result, $invoice); |
|
652 | 652 | |
653 | - if ( wpinv_get_errors() ) { |
|
654 | - wpinv_send_back_to_checkout( $invoice ); |
|
653 | + if (wpinv_get_errors()) { |
|
654 | + wpinv_send_back_to_checkout($invoice); |
|
655 | 655 | } |
656 | 656 | |
657 | 657 | } |
@@ -662,30 +662,30 @@ discard block |
||
662 | 662 | * @param WPInv_Invoice $invoice Invoice. |
663 | 663 | * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
664 | 664 | */ |
665 | - public function process_subscription( $invoice, $subscriptions ) { |
|
665 | + public function process_subscription($invoice, $subscriptions) { |
|
666 | 666 | |
667 | 667 | // Check if there is an initial amount to charge. |
668 | - if ( (float) $invoice->get_total() > 0 ) { |
|
669 | - $this->process_initial_payment( $invoice ); |
|
668 | + if ((float) $invoice->get_total() > 0) { |
|
669 | + $this->process_initial_payment($invoice); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | // Activate the subscriptions. |
673 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
673 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
674 | 674 | |
675 | - foreach ( $subscriptions as $subscription ) { |
|
676 | - if ( $subscription->exists() ) { |
|
677 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
678 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
675 | + foreach ($subscriptions as $subscription) { |
|
676 | + if ($subscription->exists()) { |
|
677 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
678 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
679 | 679 | |
680 | - $subscription->set_next_renewal_date( $expiry ); |
|
681 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
682 | - $subscription->set_profile_id( $invoice->generate_key( 'authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) ); |
|
680 | + $subscription->set_next_renewal_date($expiry); |
|
681 | + $subscription->set_date_created(current_time('mysql')); |
|
682 | + $subscription->set_profile_id($invoice->generate_key('authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id())); |
|
683 | 683 | $subscription->activate(); |
684 | 684 | } |
685 | 685 | } |
686 | 686 | |
687 | 687 | // Redirect to the success page. |
688 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
688 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
689 | 689 | |
690 | 690 | } |
691 | 691 | |
@@ -695,11 +695,11 @@ discard block |
||
695 | 695 | * |
696 | 696 | * @param WPInv_Subscription $subscription |
697 | 697 | */ |
698 | - public function maybe_renew_subscription( $subscription ) { |
|
698 | + public function maybe_renew_subscription($subscription) { |
|
699 | 699 | |
700 | 700 | // Ensure its our subscription && it's active. |
701 | - if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
702 | - $this->renew_subscription( $subscription ); |
|
701 | + if ($this->id == $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
702 | + $this->renew_subscription($subscription); |
|
703 | 703 | } |
704 | 704 | |
705 | 705 | } |
@@ -709,28 +709,28 @@ discard block |
||
709 | 709 | * |
710 | 710 | * @param WPInv_Subscription $subscription |
711 | 711 | */ |
712 | - public function renew_subscription( $subscription ) { |
|
712 | + public function renew_subscription($subscription) { |
|
713 | 713 | |
714 | 714 | // Generate the renewal invoice. |
715 | 715 | $new_invoice = $subscription->create_payment(); |
716 | 716 | $old_invoice = $subscription->get_parent_payment(); |
717 | 717 | |
718 | - if ( empty( $new_invoice ) ) { |
|
719 | - $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
|
718 | + if (empty($new_invoice)) { |
|
719 | + $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false); |
|
720 | 720 | $subscription->failing(); |
721 | 721 | return; |
722 | 722 | } |
723 | 723 | |
724 | 724 | // Charge the payment method. |
725 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
726 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
727 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
725 | + $payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
726 | + $customer_profile = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true); |
|
727 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice); |
|
728 | 728 | |
729 | 729 | // Do we have an error? |
730 | - if ( is_wp_error( $result ) ) { |
|
730 | + if (is_wp_error($result)) { |
|
731 | 731 | |
732 | 732 | $old_invoice->add_note( |
733 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
733 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()), |
|
734 | 734 | true, |
735 | 735 | false, |
736 | 736 | true |
@@ -741,12 +741,12 @@ discard block |
||
741 | 741 | } |
742 | 742 | |
743 | 743 | // Process the response. |
744 | - $this->process_charge_response( $result, $new_invoice ); |
|
744 | + $this->process_charge_response($result, $new_invoice); |
|
745 | 745 | |
746 | - if ( wpinv_get_errors() ) { |
|
746 | + if (wpinv_get_errors()) { |
|
747 | 747 | |
748 | 748 | $old_invoice->add_note( |
749 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
749 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()), |
|
750 | 750 | true, |
751 | 751 | false, |
752 | 752 | true |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | |
757 | 757 | } |
758 | 758 | |
759 | - $subscription->add_payment( array(), $new_invoice ); |
|
759 | + $subscription->add_payment(array(), $new_invoice); |
|
760 | 760 | $subscription->renew(); |
761 | 761 | } |
762 | 762 | |
@@ -767,33 +767,33 @@ discard block |
||
767 | 767 | * @param GetPaid_Form_Item[] $items |
768 | 768 | * @return WPInv_Invoice |
769 | 769 | */ |
770 | - public function process_addons( $invoice, $items ) { |
|
770 | + public function process_addons($invoice, $items) { |
|
771 | 771 | |
772 | 772 | global $getpaid_authorize_addons; |
773 | 773 | |
774 | 774 | $getpaid_authorize_addons = array(); |
775 | - foreach ( $items as $item ) { |
|
775 | + foreach ($items as $item) { |
|
776 | 776 | |
777 | - if ( is_null( $invoice->get_item( $item->get_id() ) ) && ! is_wp_error( $invoice->add_item( $item ) ) ) { |
|
777 | + if (is_null($invoice->get_item($item->get_id())) && !is_wp_error($invoice->add_item($item))) { |
|
778 | 778 | $getpaid_authorize_addons[] = $item; |
779 | 779 | } |
780 | 780 | } |
781 | 781 | |
782 | - if ( empty( $getpaid_authorize_addons ) ) { |
|
782 | + if (empty($getpaid_authorize_addons)) { |
|
783 | 783 | return; |
784 | 784 | } |
785 | 785 | |
786 | 786 | $invoice->recalculate_total(); |
787 | 787 | |
788 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
789 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
788 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
789 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
790 | 790 | |
791 | - add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
|
792 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
793 | - remove_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ) ); |
|
791 | + add_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'), 10, 2); |
|
792 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
793 | + remove_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request')); |
|
794 | 794 | |
795 | - if ( is_wp_error( $result ) ) { |
|
796 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
795 | + if (is_wp_error($result)) { |
|
796 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
797 | 797 | return; |
798 | 798 | } |
799 | 799 | |
@@ -806,19 +806,19 @@ discard block |
||
806 | 806 | * @param array $args |
807 | 807 | * @return array |
808 | 808 | */ |
809 | - public function filter_addons_request( $args ) { |
|
809 | + public function filter_addons_request($args) { |
|
810 | 810 | |
811 | 811 | global $getpaid_authorize_addons; |
812 | 812 | $total = 0; |
813 | 813 | |
814 | - foreach ( $getpaid_authorize_addons as $addon ) { |
|
814 | + foreach ($getpaid_authorize_addons as $addon) { |
|
815 | 815 | $total += $addon->get_sub_total(); |
816 | 816 | } |
817 | 817 | |
818 | 818 | $args['createTransactionRequest']['transactionRequest']['amount'] = $total; |
819 | 819 | |
820 | - if ( isset( $args['createTransactionRequest']['transactionRequest']['tax'] ) ) { |
|
821 | - unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
820 | + if (isset($args['createTransactionRequest']['transactionRequest']['tax'])) { |
|
821 | + unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | return $args; |
@@ -831,7 +831,7 @@ discard block |
||
831 | 831 | public function sandbox_notice() { |
832 | 832 | |
833 | 833 | return sprintf( |
834 | - __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
834 | + __('SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing'), |
|
835 | 835 | '<a href="https://developer.authorize.net/hello_world/testing_guide.html">', |
836 | 836 | '</a>' |
837 | 837 | ); |
@@ -843,42 +843,42 @@ discard block |
||
843 | 843 | * |
844 | 844 | * @param array $admin_settings |
845 | 845 | */ |
846 | - public function admin_settings( $admin_settings ) { |
|
846 | + public function admin_settings($admin_settings) { |
|
847 | 847 | |
848 | 848 | $currencies = sprintf( |
849 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
850 | - implode( ', ', $this->currencies ) |
|
849 | + __('Supported Currencies: %s', 'invoicing'), |
|
850 | + implode(', ', $this->currencies) |
|
851 | 851 | ); |
852 | 852 | |
853 | 853 | $admin_settings['authorizenet_active']['desc'] .= " ($currencies)"; |
854 | - $admin_settings['authorizenet_desc']['std'] = __( 'Pay securely using your credit or debit card.', 'invoicing' ); |
|
854 | + $admin_settings['authorizenet_desc']['std'] = __('Pay securely using your credit or debit card.', 'invoicing'); |
|
855 | 855 | |
856 | 856 | $admin_settings['authorizenet_login_id'] = array( |
857 | 857 | 'type' => 'text', |
858 | 858 | 'id' => 'authorizenet_login_id', |
859 | - 'name' => __( 'API Login ID', 'invoicing' ), |
|
860 | - 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>', |
|
859 | + 'name' => __('API Login ID', 'invoicing'), |
|
860 | + 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>', |
|
861 | 861 | ); |
862 | 862 | |
863 | 863 | $admin_settings['authorizenet_transaction_key'] = array( |
864 | 864 | 'type' => 'text', |
865 | 865 | 'id' => 'authorizenet_transaction_key', |
866 | - 'name' => __( 'Transaction Key', 'invoicing' ), |
|
866 | + 'name' => __('Transaction Key', 'invoicing'), |
|
867 | 867 | ); |
868 | 868 | |
869 | 869 | $admin_settings['authorizenet_signature_key'] = array( |
870 | 870 | 'type' => 'text', |
871 | 871 | 'id' => 'authorizenet_signature_key', |
872 | - 'name' => __( 'Signature Key', 'invoicing' ), |
|
873 | - 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
872 | + 'name' => __('Signature Key', 'invoicing'), |
|
873 | + 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
874 | 874 | ); |
875 | 875 | |
876 | 876 | $admin_settings['authorizenet_ipn_url'] = array( |
877 | 877 | 'type' => 'ipn_url', |
878 | 878 | 'id' => 'authorizenet_ipn_url', |
879 | - 'name' => __( 'Webhook URL', 'invoicing' ), |
|
879 | + 'name' => __('Webhook URL', 'invoicing'), |
|
880 | 880 | 'std' => $this->notify_url, |
881 | - 'desc' => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
881 | + 'desc' => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
882 | 882 | 'custom' => 'authorizenet', |
883 | 883 | 'readonly' => true, |
884 | 884 | ); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,55 +10,55 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form extends GetPaid_Data { |
11 | 11 | |
12 | 12 | /** |
13 | - * Which data store to load. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
13 | + * Which data store to load. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | 17 | protected $data_store_name = 'payment_form'; |
18 | 18 | |
19 | 19 | /** |
20 | - * This is the name of this object type. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $object_type = 'payment_form'; |
|
20 | + * This is the name of this object type. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $object_type = 'payment_form'; |
|
25 | 25 | |
26 | 26 | /** |
27 | - * Form Data array. This is the core form data exposed in APIs. |
|
28 | - * |
|
29 | - * @since 1.0.19 |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $data = array( |
|
33 | - 'status' => 'draft', |
|
34 | - 'version' => '', |
|
35 | - 'date_created' => null, |
|
27 | + * Form Data array. This is the core form data exposed in APIs. |
|
28 | + * |
|
29 | + * @since 1.0.19 |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $data = array( |
|
33 | + 'status' => 'draft', |
|
34 | + 'version' => '', |
|
35 | + 'date_created' => null, |
|
36 | 36 | 'date_modified' => null, |
37 | 37 | 'name' => '', |
38 | 38 | 'author' => 1, |
39 | 39 | 'elements' => null, |
40 | - 'items' => null, |
|
41 | - 'earned' => 0, |
|
42 | - 'refunded' => 0, |
|
43 | - 'cancelled' => 0, |
|
44 | - 'failed' => 0, |
|
45 | - ); |
|
46 | - |
|
47 | - /** |
|
48 | - * Stores meta in cache for future reads. |
|
49 | - * |
|
50 | - * A group must be set to to enable caching. |
|
51 | - * |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $cache_group = 'getpaid_forms'; |
|
55 | - |
|
56 | - /** |
|
57 | - * Stores a reference to the invoice if the form is for an invoice.. |
|
58 | - * |
|
59 | - * @var WPInv_Invoice |
|
60 | - */ |
|
61 | - public $invoice = 0; |
|
40 | + 'items' => null, |
|
41 | + 'earned' => 0, |
|
42 | + 'refunded' => 0, |
|
43 | + 'cancelled' => 0, |
|
44 | + 'failed' => 0, |
|
45 | + ); |
|
46 | + |
|
47 | + /** |
|
48 | + * Stores meta in cache for future reads. |
|
49 | + * |
|
50 | + * A group must be set to to enable caching. |
|
51 | + * |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $cache_group = 'getpaid_forms'; |
|
55 | + |
|
56 | + /** |
|
57 | + * Stores a reference to the invoice if the form is for an invoice.. |
|
58 | + * |
|
59 | + * @var WPInv_Invoice |
|
60 | + */ |
|
61 | + public $invoice = 0; |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Stores a reference to the original WP_Post object |
@@ -68,35 +68,35 @@ discard block |
||
68 | 68 | protected $post = null; |
69 | 69 | |
70 | 70 | /** |
71 | - * Get the form if ID is passed, otherwise the form is new and empty. |
|
72 | - * |
|
73 | - * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
74 | - */ |
|
75 | - public function __construct( $form = 0 ) { |
|
76 | - parent::__construct( $form ); |
|
71 | + * Get the form if ID is passed, otherwise the form is new and empty. |
|
72 | + * |
|
73 | + * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
74 | + */ |
|
75 | + public function __construct( $form = 0 ) { |
|
76 | + parent::__construct( $form ); |
|
77 | 77 | |
78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | - $this->set_id( $form ); |
|
80 | - } elseif ( $form instanceof self ) { |
|
78 | + if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | + $this->set_id( $form ); |
|
80 | + } elseif ( $form instanceof self ) { |
|
81 | 81 | |
82 | - $this->set_id( $form->get_id() ); |
|
83 | - $this->invoice = $form->invoice; |
|
82 | + $this->set_id( $form->get_id() ); |
|
83 | + $this->invoice = $form->invoice; |
|
84 | 84 | |
85 | - } elseif ( ! empty( $form->ID ) ) { |
|
86 | - $this->set_id( $form->ID ); |
|
87 | - } else { |
|
88 | - $this->set_object_read( true ); |
|
89 | - } |
|
85 | + } elseif ( ! empty( $form->ID ) ) { |
|
86 | + $this->set_id( $form->ID ); |
|
87 | + } else { |
|
88 | + $this->set_object_read( true ); |
|
89 | + } |
|
90 | 90 | |
91 | 91 | // Load the datastore. |
92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
92 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
93 | 93 | |
94 | - if ( $this->get_id() > 0 ) { |
|
94 | + if ( $this->get_id() > 0 ) { |
|
95 | 95 | $this->post = get_post( $this->get_id() ); |
96 | - $this->data_store->read( $this ); |
|
96 | + $this->data_store->read( $this ); |
|
97 | 97 | } |
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | 101 | /* |
102 | 102 | |-------------------------------------------------------------------------- |
@@ -114,356 +114,356 @@ discard block |
||
114 | 114 | */ |
115 | 115 | |
116 | 116 | /** |
117 | - * Get plugin version when the form was created. |
|
118 | - * |
|
119 | - * @since 1.0.19 |
|
120 | - * @param string $context View or edit context. |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function get_version( $context = 'view' ) { |
|
124 | - return $this->get_prop( 'version', $context ); |
|
117 | + * Get plugin version when the form was created. |
|
118 | + * |
|
119 | + * @since 1.0.19 |
|
120 | + * @param string $context View or edit context. |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function get_version( $context = 'view' ) { |
|
124 | + return $this->get_prop( 'version', $context ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | - * Get date when the form was created. |
|
129 | - * |
|
130 | - * @since 1.0.19 |
|
131 | - * @param string $context View or edit context. |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function get_date_created( $context = 'view' ) { |
|
135 | - return $this->get_prop( 'date_created', $context ); |
|
128 | + * Get date when the form was created. |
|
129 | + * |
|
130 | + * @since 1.0.19 |
|
131 | + * @param string $context View or edit context. |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function get_date_created( $context = 'view' ) { |
|
135 | + return $this->get_prop( 'date_created', $context ); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | - * Get GMT date when the form was created. |
|
140 | - * |
|
141 | - * @since 1.0.19 |
|
142 | - * @param string $context View or edit context. |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
139 | + * Get GMT date when the form was created. |
|
140 | + * |
|
141 | + * @since 1.0.19 |
|
142 | + * @param string $context View or edit context. |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public function get_date_created_gmt( $context = 'view' ) { |
|
146 | 146 | $date = $this->get_date_created( $context ); |
147 | 147 | |
148 | 148 | if ( $date ) { |
149 | 149 | $date = get_gmt_from_date( $date ); |
150 | 150 | } |
151 | - return $date; |
|
151 | + return $date; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | - * Get date when the form was last modified. |
|
156 | - * |
|
157 | - * @since 1.0.19 |
|
158 | - * @param string $context View or edit context. |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function get_date_modified( $context = 'view' ) { |
|
162 | - return $this->get_prop( 'date_modified', $context ); |
|
155 | + * Get date when the form was last modified. |
|
156 | + * |
|
157 | + * @since 1.0.19 |
|
158 | + * @param string $context View or edit context. |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function get_date_modified( $context = 'view' ) { |
|
162 | + return $this->get_prop( 'date_modified', $context ); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | - * Get GMT date when the form was last modified. |
|
167 | - * |
|
168 | - * @since 1.0.19 |
|
169 | - * @param string $context View or edit context. |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
166 | + * Get GMT date when the form was last modified. |
|
167 | + * |
|
168 | + * @since 1.0.19 |
|
169 | + * @param string $context View or edit context. |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
173 | 173 | $date = $this->get_date_modified( $context ); |
174 | 174 | |
175 | 175 | if ( $date ) { |
176 | 176 | $date = get_gmt_from_date( $date ); |
177 | 177 | } |
178 | - return $date; |
|
178 | + return $date; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
182 | - * Get the form name. |
|
183 | - * |
|
184 | - * @since 1.0.19 |
|
185 | - * @param string $context View or edit context. |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - public function get_name( $context = 'view' ) { |
|
189 | - return $this->get_prop( 'name', $context ); |
|
182 | + * Get the form name. |
|
183 | + * |
|
184 | + * @since 1.0.19 |
|
185 | + * @param string $context View or edit context. |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + public function get_name( $context = 'view' ) { |
|
189 | + return $this->get_prop( 'name', $context ); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
193 | - * Alias of self::get_name(). |
|
194 | - * |
|
195 | - * @since 1.0.19 |
|
196 | - * @param string $context View or edit context. |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public function get_title( $context = 'view' ) { |
|
200 | - return $this->get_name( $context ); |
|
201 | - } |
|
193 | + * Alias of self::get_name(). |
|
194 | + * |
|
195 | + * @since 1.0.19 |
|
196 | + * @param string $context View or edit context. |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public function get_title( $context = 'view' ) { |
|
200 | + return $this->get_name( $context ); |
|
201 | + } |
|
202 | 202 | |
203 | 203 | /** |
204 | - * Get the owner of the form. |
|
205 | - * |
|
206 | - * @since 1.0.19 |
|
207 | - * @param string $context View or edit context. |
|
208 | - * @return int |
|
209 | - */ |
|
210 | - public function get_author( $context = 'view' ) { |
|
211 | - return (int) $this->get_prop( 'author', $context ); |
|
204 | + * Get the owner of the form. |
|
205 | + * |
|
206 | + * @since 1.0.19 |
|
207 | + * @param string $context View or edit context. |
|
208 | + * @return int |
|
209 | + */ |
|
210 | + public function get_author( $context = 'view' ) { |
|
211 | + return (int) $this->get_prop( 'author', $context ); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
215 | - * Get the elements that make up the form. |
|
216 | - * |
|
217 | - * @since 1.0.19 |
|
218 | - * @param string $context View or edit context. |
|
219 | - * @return array |
|
220 | - */ |
|
221 | - public function get_elements( $context = 'view' ) { |
|
222 | - $elements = $this->get_prop( 'elements', $context ); |
|
215 | + * Get the elements that make up the form. |
|
216 | + * |
|
217 | + * @since 1.0.19 |
|
218 | + * @param string $context View or edit context. |
|
219 | + * @return array |
|
220 | + */ |
|
221 | + public function get_elements( $context = 'view' ) { |
|
222 | + $elements = $this->get_prop( 'elements', $context ); |
|
223 | 223 | |
224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
224 | + if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
225 | 225 | return wpinv_get_data( 'sample-payment-form' ); |
226 | - } |
|
226 | + } |
|
227 | 227 | |
228 | - // Ensure that all required elements exist. |
|
229 | - $_elements = array(); |
|
230 | - foreach ( $elements as $element ) { |
|
228 | + // Ensure that all required elements exist. |
|
229 | + $_elements = array(); |
|
230 | + foreach ( $elements as $element ) { |
|
231 | 231 | |
232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
232 | + if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
233 | 233 | |
234 | - $_elements[] = array( |
|
235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
236 | - 'id' => 'gtscicd', |
|
237 | - 'name' => 'gtscicd', |
|
238 | - 'type' => 'gateway_select', |
|
239 | - 'premade' => true, |
|
234 | + $_elements[] = array( |
|
235 | + 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
236 | + 'id' => 'gtscicd', |
|
237 | + 'name' => 'gtscicd', |
|
238 | + 'type' => 'gateway_select', |
|
239 | + 'premade' => true, |
|
240 | 240 | |
241 | - ); |
|
241 | + ); |
|
242 | 242 | |
243 | - } |
|
243 | + } |
|
244 | 244 | |
245 | - $_elements[] = $element; |
|
245 | + $_elements[] = $element; |
|
246 | 246 | |
247 | - } |
|
247 | + } |
|
248 | 248 | |
249 | 249 | return $_elements; |
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Get the items sold via the form. |
|
254 | - * |
|
255 | - * @since 1.0.19 |
|
256 | - * @param string $context View or edit context. |
|
257 | - * @param string $return objects or arrays. |
|
258 | - * @return GetPaid_Form_Item[] |
|
259 | - */ |
|
260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | - $items = $this->get_prop( 'items', $context ); |
|
262 | - |
|
263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Get the items sold via the form. |
|
254 | + * |
|
255 | + * @since 1.0.19 |
|
256 | + * @param string $context View or edit context. |
|
257 | + * @param string $return objects or arrays. |
|
258 | + * @return GetPaid_Form_Item[] |
|
259 | + */ |
|
260 | + public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | + $items = $this->get_prop( 'items', $context ); |
|
262 | + |
|
263 | + if ( empty( $items ) || ! is_array( $items ) ) { |
|
264 | 264 | $items = wpinv_get_data( 'sample-payment-form-items' ); |
265 | - } |
|
265 | + } |
|
266 | 266 | |
267 | - // Convert the items. |
|
268 | - $prepared = array(); |
|
267 | + // Convert the items. |
|
268 | + $prepared = array(); |
|
269 | 269 | |
270 | - foreach ( $items as $key => $value ) { |
|
270 | + foreach ( $items as $key => $value ) { |
|
271 | 271 | |
272 | - // Form items. |
|
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
272 | + // Form items. |
|
273 | + if ( $value instanceof GetPaid_Form_Item ) { |
|
274 | 274 | |
275 | - if ( $value->can_purchase() ) { |
|
276 | - $prepared[] = $value; |
|
277 | - } |
|
275 | + if ( $value->can_purchase() ) { |
|
276 | + $prepared[] = $value; |
|
277 | + } |
|
278 | 278 | |
279 | - continue; |
|
279 | + continue; |
|
280 | 280 | |
281 | - } |
|
281 | + } |
|
282 | 282 | |
283 | - // $item_id => $quantity (buy buttons) |
|
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
283 | + // $item_id => $quantity (buy buttons) |
|
284 | + if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | + $item = new GetPaid_Form_Item( $key ); |
|
286 | 286 | |
287 | - if ( $item->can_purchase() ) { |
|
287 | + if ( $item->can_purchase() ) { |
|
288 | 288 | |
289 | - $value = (float) $value; |
|
290 | - $item->set_quantity( $value ); |
|
291 | - if ( 0 == $value ) { |
|
292 | - $item->set_quantity( 1 ); |
|
293 | - $item->set_allow_quantities( true ); |
|
294 | - } |
|
289 | + $value = (float) $value; |
|
290 | + $item->set_quantity( $value ); |
|
291 | + if ( 0 == $value ) { |
|
292 | + $item->set_quantity( 1 ); |
|
293 | + $item->set_allow_quantities( true ); |
|
294 | + } |
|
295 | 295 | |
296 | - $prepared[] = $item; |
|
297 | - } |
|
296 | + $prepared[] = $item; |
|
297 | + } |
|
298 | 298 | |
299 | - continue; |
|
300 | - } |
|
299 | + continue; |
|
300 | + } |
|
301 | 301 | |
302 | - // Items saved via payment forms editor. |
|
303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
302 | + // Items saved via payment forms editor. |
|
303 | + if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
304 | 304 | |
305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
305 | + $item = new GetPaid_Form_Item( $value['id'] ); |
|
306 | 306 | |
307 | - if ( ! $item->can_purchase() ) { |
|
308 | - continue; |
|
309 | - } |
|
307 | + if ( ! $item->can_purchase() ) { |
|
308 | + continue; |
|
309 | + } |
|
310 | 310 | |
311 | - // Sub-total (Cart items). |
|
312 | - if ( isset( $value['subtotal'] ) ) { |
|
313 | - $item->set_price( $value['subtotal'] ); |
|
314 | - } |
|
311 | + // Sub-total (Cart items). |
|
312 | + if ( isset( $value['subtotal'] ) ) { |
|
313 | + $item->set_price( $value['subtotal'] ); |
|
314 | + } |
|
315 | 315 | |
316 | - if ( isset( $value['quantity'] ) ) { |
|
317 | - $item->set_quantity( $value['quantity'] ); |
|
318 | - } |
|
316 | + if ( isset( $value['quantity'] ) ) { |
|
317 | + $item->set_quantity( $value['quantity'] ); |
|
318 | + } |
|
319 | 319 | |
320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
322 | - } |
|
320 | + if ( isset( $value['allow_quantities'] ) ) { |
|
321 | + $item->set_allow_quantities( $value['allow_quantities'] ); |
|
322 | + } |
|
323 | 323 | |
324 | - if ( isset( $value['required'] ) ) { |
|
325 | - $item->set_is_required( $value['required'] ); |
|
326 | - } |
|
324 | + if ( isset( $value['required'] ) ) { |
|
325 | + $item->set_is_required( $value['required'] ); |
|
326 | + } |
|
327 | 327 | |
328 | - if ( isset( $value['description'] ) ) { |
|
329 | - $item->set_custom_description( $value['description'] ); |
|
330 | - } |
|
328 | + if ( isset( $value['description'] ) ) { |
|
329 | + $item->set_custom_description( $value['description'] ); |
|
330 | + } |
|
331 | 331 | |
332 | - $prepared[] = $item; |
|
333 | - continue; |
|
332 | + $prepared[] = $item; |
|
333 | + continue; |
|
334 | 334 | |
335 | - } |
|
335 | + } |
|
336 | 336 | |
337 | - // $item_id => array( 'price' => 10 ) (item variations) |
|
338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | - $item = new GetPaid_Form_Item( $key ); |
|
337 | + // $item_id => array( 'price' => 10 ) (item variations) |
|
338 | + if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | + $item = new GetPaid_Form_Item( $key ); |
|
340 | 340 | |
341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | - $item->set_price( $value['price'] ); |
|
343 | - } |
|
341 | + if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | + $item->set_price( $value['price'] ); |
|
343 | + } |
|
344 | 344 | |
345 | - if ( $item->can_purchase() ) { |
|
346 | - $prepared[] = $item; |
|
347 | - } |
|
345 | + if ( $item->can_purchase() ) { |
|
346 | + $prepared[] = $item; |
|
347 | + } |
|
348 | 348 | |
349 | - continue; |
|
350 | - } |
|
349 | + continue; |
|
350 | + } |
|
351 | 351 | } |
352 | 352 | |
353 | - if ( 'objects' == $return && 'view' == $context ) { |
|
354 | - return $prepared; |
|
355 | - } |
|
356 | - |
|
357 | - $items = array(); |
|
358 | - foreach ( $prepared as $item ) { |
|
359 | - $items[] = $item->prepare_data_for_use(); |
|
360 | - } |
|
361 | - |
|
362 | - return $items; |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Get a single item belonging to the form. |
|
367 | - * |
|
368 | - * @since 1.0.19 |
|
369 | - * @param int $item_id The item id to return. |
|
370 | - * @return GetPaid_Form_Item|bool |
|
371 | - */ |
|
372 | - public function get_item( $item_id ) { |
|
373 | - |
|
374 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
375 | - return false; |
|
376 | - } |
|
377 | - |
|
378 | - foreach ( $this->get_items() as $item ) { |
|
379 | - if ( $item->get_id() == (int) $item_id ) { |
|
380 | - return $item; |
|
381 | - } |
|
382 | - } |
|
383 | - |
|
384 | - return false; |
|
385 | - |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * Gets a single element. |
|
390 | - * |
|
391 | - * @since 1.0.19 |
|
392 | - * @param string $element_type The element type to return. |
|
393 | - * @return array|bool |
|
394 | - */ |
|
395 | - public function get_element_type( $element_type ) { |
|
396 | - |
|
397 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
398 | - return false; |
|
399 | - } |
|
400 | - |
|
401 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
402 | - |
|
403 | - if ( $element['type'] == $element_type ) { |
|
404 | - return $element; |
|
405 | - } |
|
353 | + if ( 'objects' == $return && 'view' == $context ) { |
|
354 | + return $prepared; |
|
355 | + } |
|
356 | + |
|
357 | + $items = array(); |
|
358 | + foreach ( $prepared as $item ) { |
|
359 | + $items[] = $item->prepare_data_for_use(); |
|
360 | + } |
|
361 | + |
|
362 | + return $items; |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Get a single item belonging to the form. |
|
367 | + * |
|
368 | + * @since 1.0.19 |
|
369 | + * @param int $item_id The item id to return. |
|
370 | + * @return GetPaid_Form_Item|bool |
|
371 | + */ |
|
372 | + public function get_item( $item_id ) { |
|
373 | + |
|
374 | + if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
375 | + return false; |
|
376 | + } |
|
377 | + |
|
378 | + foreach ( $this->get_items() as $item ) { |
|
379 | + if ( $item->get_id() == (int) $item_id ) { |
|
380 | + return $item; |
|
381 | + } |
|
382 | + } |
|
383 | + |
|
384 | + return false; |
|
385 | + |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * Gets a single element. |
|
390 | + * |
|
391 | + * @since 1.0.19 |
|
392 | + * @param string $element_type The element type to return. |
|
393 | + * @return array|bool |
|
394 | + */ |
|
395 | + public function get_element_type( $element_type ) { |
|
396 | + |
|
397 | + if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
398 | + return false; |
|
399 | + } |
|
400 | + |
|
401 | + foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
402 | + |
|
403 | + if ( $element['type'] == $element_type ) { |
|
404 | + return $element; |
|
405 | + } |
|
406 | 406 | } |
407 | 407 | |
408 | - return false; |
|
409 | - |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Get the total amount earned via this form. |
|
414 | - * |
|
415 | - * @since 1.0.19 |
|
416 | - * @param string $context View or edit context. |
|
417 | - * @return float |
|
418 | - */ |
|
419 | - public function get_earned( $context = 'view' ) { |
|
420 | - return $this->get_prop( 'earned', $context ); |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Get the total amount refunded via this form. |
|
425 | - * |
|
426 | - * @since 1.0.19 |
|
427 | - * @param string $context View or edit context. |
|
428 | - * @return float |
|
429 | - */ |
|
430 | - public function get_refunded( $context = 'view' ) { |
|
431 | - return $this->get_prop( 'refunded', $context ); |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Get the total amount cancelled via this form. |
|
436 | - * |
|
437 | - * @since 1.0.19 |
|
438 | - * @param string $context View or edit context. |
|
439 | - * @return float |
|
440 | - */ |
|
441 | - public function get_cancelled( $context = 'view' ) { |
|
442 | - return $this->get_prop( 'cancelled', $context ); |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * Get the total amount failed via this form. |
|
447 | - * |
|
448 | - * @since 1.0.19 |
|
449 | - * @param string $context View or edit context. |
|
450 | - * @return float |
|
451 | - */ |
|
452 | - public function get_failed( $context = 'view' ) { |
|
453 | - return $this->get_prop( 'failed', $context ); |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * Get the currency. |
|
458 | - * |
|
459 | - * @since 1.0.19 |
|
460 | - * @param string $context View or edit context. |
|
461 | - * @return string |
|
462 | - */ |
|
463 | - public function get_currency() { |
|
464 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
466 | - } |
|
408 | + return false; |
|
409 | + |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Get the total amount earned via this form. |
|
414 | + * |
|
415 | + * @since 1.0.19 |
|
416 | + * @param string $context View or edit context. |
|
417 | + * @return float |
|
418 | + */ |
|
419 | + public function get_earned( $context = 'view' ) { |
|
420 | + return $this->get_prop( 'earned', $context ); |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Get the total amount refunded via this form. |
|
425 | + * |
|
426 | + * @since 1.0.19 |
|
427 | + * @param string $context View or edit context. |
|
428 | + * @return float |
|
429 | + */ |
|
430 | + public function get_refunded( $context = 'view' ) { |
|
431 | + return $this->get_prop( 'refunded', $context ); |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Get the total amount cancelled via this form. |
|
436 | + * |
|
437 | + * @since 1.0.19 |
|
438 | + * @param string $context View or edit context. |
|
439 | + * @return float |
|
440 | + */ |
|
441 | + public function get_cancelled( $context = 'view' ) { |
|
442 | + return $this->get_prop( 'cancelled', $context ); |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * Get the total amount failed via this form. |
|
447 | + * |
|
448 | + * @since 1.0.19 |
|
449 | + * @param string $context View or edit context. |
|
450 | + * @return float |
|
451 | + */ |
|
452 | + public function get_failed( $context = 'view' ) { |
|
453 | + return $this->get_prop( 'failed', $context ); |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * Get the currency. |
|
458 | + * |
|
459 | + * @since 1.0.19 |
|
460 | + * @param string $context View or edit context. |
|
461 | + * @return string |
|
462 | + */ |
|
463 | + public function get_currency() { |
|
464 | + $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | + return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
466 | + } |
|
467 | 467 | |
468 | 468 | /* |
469 | 469 | |-------------------------------------------------------------------------- |
@@ -476,22 +476,22 @@ discard block |
||
476 | 476 | */ |
477 | 477 | |
478 | 478 | /** |
479 | - * Set plugin version when the item was created. |
|
480 | - * |
|
481 | - * @since 1.0.19 |
|
482 | - */ |
|
483 | - public function set_version( $value ) { |
|
484 | - $this->set_prop( 'version', $value ); |
|
479 | + * Set plugin version when the item was created. |
|
480 | + * |
|
481 | + * @since 1.0.19 |
|
482 | + */ |
|
483 | + public function set_version( $value ) { |
|
484 | + $this->set_prop( 'version', $value ); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
488 | - * Set date when the item was created. |
|
489 | - * |
|
490 | - * @since 1.0.19 |
|
491 | - * @param string $value Value to set. |
|
488 | + * Set date when the item was created. |
|
489 | + * |
|
490 | + * @since 1.0.19 |
|
491 | + * @param string $value Value to set. |
|
492 | 492 | * @return bool Whether or not the date was set. |
493 | - */ |
|
494 | - public function set_date_created( $value ) { |
|
493 | + */ |
|
494 | + public function set_date_created( $value ) { |
|
495 | 495 | $date = strtotime( $value ); |
496 | 496 | |
497 | 497 | if ( $date ) { |
@@ -504,13 +504,13 @@ discard block |
||
504 | 504 | } |
505 | 505 | |
506 | 506 | /** |
507 | - * Set date when the item was last modified. |
|
508 | - * |
|
509 | - * @since 1.0.19 |
|
510 | - * @param string $value Value to set. |
|
507 | + * Set date when the item was last modified. |
|
508 | + * |
|
509 | + * @since 1.0.19 |
|
510 | + * @param string $value Value to set. |
|
511 | 511 | * @return bool Whether or not the date was set. |
512 | - */ |
|
513 | - public function set_date_modified( $value ) { |
|
512 | + */ |
|
513 | + public function set_date_modified( $value ) { |
|
514 | 514 | $date = strtotime( $value ); |
515 | 515 | |
516 | 516 | if ( $date ) { |
@@ -523,164 +523,164 @@ discard block |
||
523 | 523 | } |
524 | 524 | |
525 | 525 | /** |
526 | - * Set the item name. |
|
527 | - * |
|
528 | - * @since 1.0.19 |
|
529 | - * @param string $value New name. |
|
530 | - */ |
|
531 | - public function set_name( $value ) { |
|
532 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
533 | - } |
|
534 | - |
|
535 | - /** |
|
536 | - * Alias of self::set_name(). |
|
537 | - * |
|
538 | - * @since 1.0.19 |
|
539 | - * @param string $value New name. |
|
540 | - */ |
|
541 | - public function set_title( $value ) { |
|
542 | - $this->set_name( $value ); |
|
543 | - } |
|
544 | - |
|
545 | - /** |
|
546 | - * Set the owner of the item. |
|
547 | - * |
|
548 | - * @since 1.0.19 |
|
549 | - * @param int $value New author. |
|
550 | - */ |
|
551 | - public function set_author( $value ) { |
|
552 | - $this->set_prop( 'author', (int) $value ); |
|
553 | - } |
|
554 | - |
|
555 | - /** |
|
556 | - * Set the form elements. |
|
557 | - * |
|
558 | - * @since 1.0.19 |
|
559 | - * @sinve 2.3.4 Array values sanitized. |
|
560 | - * @param array $value Form elements. |
|
561 | - */ |
|
562 | - public function set_elements( $value ) { |
|
563 | - if ( is_array( $value ) ) { |
|
564 | - $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
565 | - } |
|
566 | - } |
|
567 | - |
|
568 | - /** |
|
569 | - * Sanitize array values. |
|
570 | - * |
|
571 | - * @param $value |
|
572 | - * |
|
573 | - * @return mixed |
|
574 | - */ |
|
575 | - public function sanitize_array_values( $value ) { |
|
576 | - |
|
577 | - // sanitize |
|
578 | - if ( ! empty( $value ) ) { |
|
579 | - |
|
580 | - foreach ( $value as $key => $val_arr ) { |
|
581 | - |
|
582 | - if ( is_array( $val_arr ) ) { |
|
583 | - // check if we have sub array items. |
|
584 | - $sub_arr = array(); |
|
585 | - foreach ( $val_arr as $key2 => $val2 ) { |
|
586 | - if ( is_array( $val2 ) ) { |
|
587 | - $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 ); |
|
588 | - unset( $val_arr[ $key ][ $key2 ] ); |
|
589 | - } |
|
590 | - } |
|
591 | - |
|
592 | - // we allow some html in description so we sanitize it separately. |
|
593 | - $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : ''; |
|
594 | - |
|
595 | - // sanitize array elements |
|
596 | - $value[ $key ] = array_map( 'sanitize_text_field', $val_arr ); |
|
597 | - |
|
598 | - // add back the description if set |
|
599 | - if ( isset( $val_arr['description'] ) ) { |
|
526 | + * Set the item name. |
|
527 | + * |
|
528 | + * @since 1.0.19 |
|
529 | + * @param string $value New name. |
|
530 | + */ |
|
531 | + public function set_name( $value ) { |
|
532 | + $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
533 | + } |
|
534 | + |
|
535 | + /** |
|
536 | + * Alias of self::set_name(). |
|
537 | + * |
|
538 | + * @since 1.0.19 |
|
539 | + * @param string $value New name. |
|
540 | + */ |
|
541 | + public function set_title( $value ) { |
|
542 | + $this->set_name( $value ); |
|
543 | + } |
|
544 | + |
|
545 | + /** |
|
546 | + * Set the owner of the item. |
|
547 | + * |
|
548 | + * @since 1.0.19 |
|
549 | + * @param int $value New author. |
|
550 | + */ |
|
551 | + public function set_author( $value ) { |
|
552 | + $this->set_prop( 'author', (int) $value ); |
|
553 | + } |
|
554 | + |
|
555 | + /** |
|
556 | + * Set the form elements. |
|
557 | + * |
|
558 | + * @since 1.0.19 |
|
559 | + * @sinve 2.3.4 Array values sanitized. |
|
560 | + * @param array $value Form elements. |
|
561 | + */ |
|
562 | + public function set_elements( $value ) { |
|
563 | + if ( is_array( $value ) ) { |
|
564 | + $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
565 | + } |
|
566 | + } |
|
567 | + |
|
568 | + /** |
|
569 | + * Sanitize array values. |
|
570 | + * |
|
571 | + * @param $value |
|
572 | + * |
|
573 | + * @return mixed |
|
574 | + */ |
|
575 | + public function sanitize_array_values( $value ) { |
|
576 | + |
|
577 | + // sanitize |
|
578 | + if ( ! empty( $value ) ) { |
|
579 | + |
|
580 | + foreach ( $value as $key => $val_arr ) { |
|
581 | + |
|
582 | + if ( is_array( $val_arr ) ) { |
|
583 | + // check if we have sub array items. |
|
584 | + $sub_arr = array(); |
|
585 | + foreach ( $val_arr as $key2 => $val2 ) { |
|
586 | + if ( is_array( $val2 ) ) { |
|
587 | + $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 ); |
|
588 | + unset( $val_arr[ $key ][ $key2 ] ); |
|
589 | + } |
|
590 | + } |
|
591 | + |
|
592 | + // we allow some html in description so we sanitize it separately. |
|
593 | + $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : ''; |
|
594 | + |
|
595 | + // sanitize array elements |
|
596 | + $value[ $key ] = array_map( 'sanitize_text_field', $val_arr ); |
|
597 | + |
|
598 | + // add back the description if set |
|
599 | + if ( isset( $val_arr['description'] ) ) { |
|
600 | 600 | $value[ $key ]['description'] = $help_text;} |
601 | 601 | |
602 | - // add back sub array items after its been sanitized. |
|
603 | - if ( ! empty( $sub_arr ) ) { |
|
604 | - $value[ $key ] = array_merge( $value[ $key ], $sub_arr ); |
|
605 | - } |
|
606 | - } |
|
602 | + // add back sub array items after its been sanitized. |
|
603 | + if ( ! empty( $sub_arr ) ) { |
|
604 | + $value[ $key ] = array_merge( $value[ $key ], $sub_arr ); |
|
605 | + } |
|
606 | + } |
|
607 | 607 | } |
608 | 608 | } |
609 | 609 | |
610 | - return $value; |
|
611 | - } |
|
612 | - |
|
613 | - /** |
|
614 | - * Set the form items. |
|
615 | - * |
|
616 | - * @since 1.0.19 |
|
617 | - * @param array $value Form elements. |
|
618 | - */ |
|
619 | - public function set_items( $value ) { |
|
620 | - if ( is_array( $value ) ) { |
|
621 | - $this->set_prop( 'items', $value ); |
|
622 | - } |
|
623 | - } |
|
624 | - |
|
625 | - /** |
|
626 | - * Set the total amount earned via this form. |
|
627 | - * |
|
628 | - * @since 1.0.19 |
|
629 | - * @param float $value Amount earned. |
|
630 | - */ |
|
631 | - public function set_earned( $value ) { |
|
632 | - $value = max( (float) $value, 0 ); |
|
633 | - $this->set_prop( 'earned', $value ); |
|
634 | - } |
|
635 | - |
|
636 | - /** |
|
637 | - * Set the total amount refunded via this form. |
|
638 | - * |
|
639 | - * @since 1.0.19 |
|
640 | - * @param float $value Amount refunded. |
|
641 | - */ |
|
642 | - public function set_refunded( $value ) { |
|
643 | - $value = max( (float) $value, 0 ); |
|
644 | - $this->set_prop( 'refunded', $value ); |
|
645 | - } |
|
646 | - |
|
647 | - /** |
|
648 | - * Set the total amount cancelled via this form. |
|
649 | - * |
|
650 | - * @since 1.0.19 |
|
651 | - * @param float $value Amount cancelled. |
|
652 | - */ |
|
653 | - public function set_cancelled( $value ) { |
|
654 | - $value = max( (float) $value, 0 ); |
|
655 | - $this->set_prop( 'cancelled', $value ); |
|
656 | - } |
|
657 | - |
|
658 | - /** |
|
659 | - * Set the total amount failed via this form. |
|
660 | - * |
|
661 | - * @since 1.0.19 |
|
662 | - * @param float $value Amount cancelled. |
|
663 | - */ |
|
664 | - public function set_failed( $value ) { |
|
665 | - $value = max( (float) $value, 0 ); |
|
666 | - $this->set_prop( 'failed', $value ); |
|
667 | - } |
|
610 | + return $value; |
|
611 | + } |
|
612 | + |
|
613 | + /** |
|
614 | + * Set the form items. |
|
615 | + * |
|
616 | + * @since 1.0.19 |
|
617 | + * @param array $value Form elements. |
|
618 | + */ |
|
619 | + public function set_items( $value ) { |
|
620 | + if ( is_array( $value ) ) { |
|
621 | + $this->set_prop( 'items', $value ); |
|
622 | + } |
|
623 | + } |
|
624 | + |
|
625 | + /** |
|
626 | + * Set the total amount earned via this form. |
|
627 | + * |
|
628 | + * @since 1.0.19 |
|
629 | + * @param float $value Amount earned. |
|
630 | + */ |
|
631 | + public function set_earned( $value ) { |
|
632 | + $value = max( (float) $value, 0 ); |
|
633 | + $this->set_prop( 'earned', $value ); |
|
634 | + } |
|
635 | + |
|
636 | + /** |
|
637 | + * Set the total amount refunded via this form. |
|
638 | + * |
|
639 | + * @since 1.0.19 |
|
640 | + * @param float $value Amount refunded. |
|
641 | + */ |
|
642 | + public function set_refunded( $value ) { |
|
643 | + $value = max( (float) $value, 0 ); |
|
644 | + $this->set_prop( 'refunded', $value ); |
|
645 | + } |
|
646 | + |
|
647 | + /** |
|
648 | + * Set the total amount cancelled via this form. |
|
649 | + * |
|
650 | + * @since 1.0.19 |
|
651 | + * @param float $value Amount cancelled. |
|
652 | + */ |
|
653 | + public function set_cancelled( $value ) { |
|
654 | + $value = max( (float) $value, 0 ); |
|
655 | + $this->set_prop( 'cancelled', $value ); |
|
656 | + } |
|
657 | + |
|
658 | + /** |
|
659 | + * Set the total amount failed via this form. |
|
660 | + * |
|
661 | + * @since 1.0.19 |
|
662 | + * @param float $value Amount cancelled. |
|
663 | + */ |
|
664 | + public function set_failed( $value ) { |
|
665 | + $value = max( (float) $value, 0 ); |
|
666 | + $this->set_prop( 'failed', $value ); |
|
667 | + } |
|
668 | 668 | |
669 | 669 | /** |
670 | 670 | * Create an item. For backwards compatibilty. |
671 | 671 | * |
672 | 672 | * @deprecated |
673 | - * @return int item id |
|
673 | + * @return int item id |
|
674 | 674 | */ |
675 | 675 | public function create( $data = array() ) { |
676 | 676 | |
677 | - // Set the properties. |
|
678 | - if ( is_array( $data ) ) { |
|
679 | - $this->set_props( $data ); |
|
680 | - } |
|
677 | + // Set the properties. |
|
678 | + if ( is_array( $data ) ) { |
|
679 | + $this->set_props( $data ); |
|
680 | + } |
|
681 | 681 | |
682 | - // Save the item. |
|
683 | - return $this->save(); |
|
682 | + // Save the item. |
|
683 | + return $this->save(); |
|
684 | 684 | |
685 | 685 | } |
686 | 686 | |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | * Updates an item. For backwards compatibilty. |
689 | 689 | * |
690 | 690 | * @deprecated |
691 | - * @return int item id |
|
691 | + * @return int item id |
|
692 | 692 | */ |
693 | 693 | public function update( $data = array() ) { |
694 | 694 | return $this->create( $data ); |
@@ -704,22 +704,22 @@ discard block |
||
704 | 704 | */ |
705 | 705 | |
706 | 706 | /** |
707 | - * Checks whether this is the default payment form. |
|
708 | - * |
|
709 | - * @since 1.0.19 |
|
710 | - * @return bool |
|
711 | - */ |
|
707 | + * Checks whether this is the default payment form. |
|
708 | + * |
|
709 | + * @since 1.0.19 |
|
710 | + * @return bool |
|
711 | + */ |
|
712 | 712 | public function is_default() { |
713 | 713 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
714 | 714 | return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
715 | - } |
|
715 | + } |
|
716 | 716 | |
717 | 717 | /** |
718 | - * Checks whether the form is active. |
|
719 | - * |
|
720 | - * @since 1.0.19 |
|
721 | - * @return bool |
|
722 | - */ |
|
718 | + * Checks whether the form is active. |
|
719 | + * |
|
720 | + * @since 1.0.19 |
|
721 | + * @return bool |
|
722 | + */ |
|
723 | 723 | public function is_active() { |
724 | 724 | $is_active = 0 !== (int) $this->get_id(); |
725 | 725 | |
@@ -728,81 +728,81 @@ discard block |
||
728 | 728 | } |
729 | 729 | |
730 | 730 | return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
731 | - } |
|
732 | - |
|
733 | - /** |
|
734 | - * Checks whether the form has a given item. |
|
735 | - * |
|
736 | - * @since 1.0.19 |
|
737 | - * @return bool |
|
738 | - */ |
|
731 | + } |
|
732 | + |
|
733 | + /** |
|
734 | + * Checks whether the form has a given item. |
|
735 | + * |
|
736 | + * @since 1.0.19 |
|
737 | + * @return bool |
|
738 | + */ |
|
739 | 739 | public function has_item( $item_id ) { |
740 | 740 | return false !== $this->get_item( $item_id ); |
741 | - } |
|
742 | - |
|
743 | - /** |
|
744 | - * Checks whether the form has a given element. |
|
745 | - * |
|
746 | - * @since 1.0.19 |
|
747 | - * @return bool |
|
748 | - */ |
|
741 | + } |
|
742 | + |
|
743 | + /** |
|
744 | + * Checks whether the form has a given element. |
|
745 | + * |
|
746 | + * @since 1.0.19 |
|
747 | + * @return bool |
|
748 | + */ |
|
749 | 749 | public function has_element_type( $element_type ) { |
750 | 750 | return false !== $this->get_element_type( $element_type ); |
751 | - } |
|
752 | - |
|
753 | - /** |
|
754 | - * Checks whether this form is recurring or not. |
|
755 | - * |
|
756 | - * @since 1.0.19 |
|
757 | - * @return bool |
|
758 | - */ |
|
751 | + } |
|
752 | + |
|
753 | + /** |
|
754 | + * Checks whether this form is recurring or not. |
|
755 | + * |
|
756 | + * @since 1.0.19 |
|
757 | + * @return bool |
|
758 | + */ |
|
759 | 759 | public function is_recurring() { |
760 | 760 | |
761 | - if ( ! empty( $this->invoice ) ) { |
|
762 | - return $this->invoice->is_recurring(); |
|
763 | - } |
|
761 | + if ( ! empty( $this->invoice ) ) { |
|
762 | + return $this->invoice->is_recurring(); |
|
763 | + } |
|
764 | 764 | |
765 | - foreach ( $this->get_items() as $item ) { |
|
765 | + foreach ( $this->get_items() as $item ) { |
|
766 | 766 | |
767 | - if ( $item->is_recurring() ) { |
|
768 | - return true; |
|
769 | - } |
|
767 | + if ( $item->is_recurring() ) { |
|
768 | + return true; |
|
769 | + } |
|
770 | 770 | } |
771 | 771 | |
772 | 772 | return false; |
773 | - } |
|
773 | + } |
|
774 | 774 | |
775 | - /** |
|
776 | - * Retrieves the form's html. |
|
777 | - * |
|
778 | - * @since 1.0.19 |
|
779 | - */ |
|
775 | + /** |
|
776 | + * Retrieves the form's html. |
|
777 | + * |
|
778 | + * @since 1.0.19 |
|
779 | + */ |
|
780 | 780 | public function get_html( $extra_markup = '' ) { |
781 | 781 | |
782 | - // Return the HTML. |
|
783 | - return wpinv_get_template_html( |
|
784 | - 'payment-forms/form.php', |
|
785 | - array( |
|
786 | - 'form' => $this, |
|
787 | - 'extra_markup' => $extra_markup, |
|
788 | - ) |
|
789 | - ); |
|
790 | - |
|
791 | - } |
|
792 | - |
|
793 | - /** |
|
794 | - * Displays the payment form. |
|
795 | - * |
|
796 | - * @since 1.0.19 |
|
797 | - */ |
|
782 | + // Return the HTML. |
|
783 | + return wpinv_get_template_html( |
|
784 | + 'payment-forms/form.php', |
|
785 | + array( |
|
786 | + 'form' => $this, |
|
787 | + 'extra_markup' => $extra_markup, |
|
788 | + ) |
|
789 | + ); |
|
790 | + |
|
791 | + } |
|
792 | + |
|
793 | + /** |
|
794 | + * Displays the payment form. |
|
795 | + * |
|
796 | + * @since 1.0.19 |
|
797 | + */ |
|
798 | 798 | public function display( $extra_markup = '' ) { |
799 | - return wpinv_get_template( |
|
800 | - 'payment-forms/form.php', |
|
801 | - array( |
|
802 | - 'form' => $this, |
|
803 | - 'extra_markup' => $extra_markup, |
|
804 | - ) |
|
805 | - ); |
|
799 | + return wpinv_get_template( |
|
800 | + 'payment-forms/form.php', |
|
801 | + array( |
|
802 | + 'form' => $this, |
|
803 | + 'extra_markup' => $extra_markup, |
|
804 | + ) |
|
805 | + ); |
|
806 | 806 | } |
807 | 807 | |
808 | 808 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -72,28 +72,28 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
74 | 74 | */ |
75 | - public function __construct( $form = 0 ) { |
|
76 | - parent::__construct( $form ); |
|
75 | + public function __construct($form = 0) { |
|
76 | + parent::__construct($form); |
|
77 | 77 | |
78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | - $this->set_id( $form ); |
|
80 | - } elseif ( $form instanceof self ) { |
|
78 | + if (is_numeric($form) && $form > 0) { |
|
79 | + $this->set_id($form); |
|
80 | + } elseif ($form instanceof self) { |
|
81 | 81 | |
82 | - $this->set_id( $form->get_id() ); |
|
82 | + $this->set_id($form->get_id()); |
|
83 | 83 | $this->invoice = $form->invoice; |
84 | 84 | |
85 | - } elseif ( ! empty( $form->ID ) ) { |
|
86 | - $this->set_id( $form->ID ); |
|
85 | + } elseif (!empty($form->ID)) { |
|
86 | + $this->set_id($form->ID); |
|
87 | 87 | } else { |
88 | - $this->set_object_read( true ); |
|
88 | + $this->set_object_read(true); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | // Load the datastore. |
92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
92 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
93 | 93 | |
94 | - if ( $this->get_id() > 0 ) { |
|
95 | - $this->post = get_post( $this->get_id() ); |
|
96 | - $this->data_store->read( $this ); |
|
94 | + if ($this->get_id() > 0) { |
|
95 | + $this->post = get_post($this->get_id()); |
|
96 | + $this->data_store->read($this); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @param string $context View or edit context. |
121 | 121 | * @return string |
122 | 122 | */ |
123 | - public function get_version( $context = 'view' ) { |
|
124 | - return $this->get_prop( 'version', $context ); |
|
123 | + public function get_version($context = 'view') { |
|
124 | + return $this->get_prop('version', $context); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | * @param string $context View or edit context. |
132 | 132 | * @return string |
133 | 133 | */ |
134 | - public function get_date_created( $context = 'view' ) { |
|
135 | - return $this->get_prop( 'date_created', $context ); |
|
134 | + public function get_date_created($context = 'view') { |
|
135 | + return $this->get_prop('date_created', $context); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | * @param string $context View or edit context. |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
146 | - $date = $this->get_date_created( $context ); |
|
145 | + public function get_date_created_gmt($context = 'view') { |
|
146 | + $date = $this->get_date_created($context); |
|
147 | 147 | |
148 | - if ( $date ) { |
|
149 | - $date = get_gmt_from_date( $date ); |
|
148 | + if ($date) { |
|
149 | + $date = get_gmt_from_date($date); |
|
150 | 150 | } |
151 | 151 | return $date; |
152 | 152 | } |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @param string $context View or edit context. |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - public function get_date_modified( $context = 'view' ) { |
|
162 | - return $this->get_prop( 'date_modified', $context ); |
|
161 | + public function get_date_modified($context = 'view') { |
|
162 | + return $this->get_prop('date_modified', $context); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -169,11 +169,11 @@ discard block |
||
169 | 169 | * @param string $context View or edit context. |
170 | 170 | * @return string |
171 | 171 | */ |
172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
173 | - $date = $this->get_date_modified( $context ); |
|
172 | + public function get_date_modified_gmt($context = 'view') { |
|
173 | + $date = $this->get_date_modified($context); |
|
174 | 174 | |
175 | - if ( $date ) { |
|
176 | - $date = get_gmt_from_date( $date ); |
|
175 | + if ($date) { |
|
176 | + $date = get_gmt_from_date($date); |
|
177 | 177 | } |
178 | 178 | return $date; |
179 | 179 | } |
@@ -185,8 +185,8 @@ discard block |
||
185 | 185 | * @param string $context View or edit context. |
186 | 186 | * @return string |
187 | 187 | */ |
188 | - public function get_name( $context = 'view' ) { |
|
189 | - return $this->get_prop( 'name', $context ); |
|
188 | + public function get_name($context = 'view') { |
|
189 | + return $this->get_prop('name', $context); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | * @param string $context View or edit context. |
197 | 197 | * @return string |
198 | 198 | */ |
199 | - public function get_title( $context = 'view' ) { |
|
200 | - return $this->get_name( $context ); |
|
199 | + public function get_title($context = 'view') { |
|
200 | + return $this->get_name($context); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | * @param string $context View or edit context. |
208 | 208 | * @return int |
209 | 209 | */ |
210 | - public function get_author( $context = 'view' ) { |
|
211 | - return (int) $this->get_prop( 'author', $context ); |
|
210 | + public function get_author($context = 'view') { |
|
211 | + return (int) $this->get_prop('author', $context); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -218,21 +218,21 @@ discard block |
||
218 | 218 | * @param string $context View or edit context. |
219 | 219 | * @return array |
220 | 220 | */ |
221 | - public function get_elements( $context = 'view' ) { |
|
222 | - $elements = $this->get_prop( 'elements', $context ); |
|
221 | + public function get_elements($context = 'view') { |
|
222 | + $elements = $this->get_prop('elements', $context); |
|
223 | 223 | |
224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
225 | - return wpinv_get_data( 'sample-payment-form' ); |
|
224 | + if (empty($elements) || !is_array($elements)) { |
|
225 | + return wpinv_get_data('sample-payment-form'); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | // Ensure that all required elements exist. |
229 | 229 | $_elements = array(); |
230 | - foreach ( $elements as $element ) { |
|
230 | + foreach ($elements as $element) { |
|
231 | 231 | |
232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
232 | + if ($element['type'] == 'pay_button' && !$this->has_element_type('gateway_select')) { |
|
233 | 233 | |
234 | 234 | $_elements[] = array( |
235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
235 | + 'text' => __('Select Payment Method', 'invoicing'), |
|
236 | 236 | 'id' => 'gtscicd', |
237 | 237 | 'name' => 'gtscicd', |
238 | 238 | 'type' => 'gateway_select', |
@@ -257,22 +257,22 @@ discard block |
||
257 | 257 | * @param string $return objects or arrays. |
258 | 258 | * @return GetPaid_Form_Item[] |
259 | 259 | */ |
260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | - $items = $this->get_prop( 'items', $context ); |
|
260 | + public function get_items($context = 'view', $return = 'objects') { |
|
261 | + $items = $this->get_prop('items', $context); |
|
262 | 262 | |
263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
264 | - $items = wpinv_get_data( 'sample-payment-form-items' ); |
|
263 | + if (empty($items) || !is_array($items)) { |
|
264 | + $items = wpinv_get_data('sample-payment-form-items'); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | // Convert the items. |
268 | 268 | $prepared = array(); |
269 | 269 | |
270 | - foreach ( $items as $key => $value ) { |
|
270 | + foreach ($items as $key => $value) { |
|
271 | 271 | |
272 | 272 | // Form items. |
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
273 | + if ($value instanceof GetPaid_Form_Item) { |
|
274 | 274 | |
275 | - if ( $value->can_purchase() ) { |
|
275 | + if ($value->can_purchase()) { |
|
276 | 276 | $prepared[] = $value; |
277 | 277 | } |
278 | 278 | |
@@ -281,16 +281,16 @@ discard block |
||
281 | 281 | } |
282 | 282 | |
283 | 283 | // $item_id => $quantity (buy buttons) |
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
284 | + if (is_numeric($key) && is_numeric($value)) { |
|
285 | + $item = new GetPaid_Form_Item($key); |
|
286 | 286 | |
287 | - if ( $item->can_purchase() ) { |
|
287 | + if ($item->can_purchase()) { |
|
288 | 288 | |
289 | 289 | $value = (float) $value; |
290 | - $item->set_quantity( $value ); |
|
291 | - if ( 0 == $value ) { |
|
292 | - $item->set_quantity( 1 ); |
|
293 | - $item->set_allow_quantities( true ); |
|
290 | + $item->set_quantity($value); |
|
291 | + if (0 == $value) { |
|
292 | + $item->set_quantity(1); |
|
293 | + $item->set_allow_quantities(true); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | $prepared[] = $item; |
@@ -300,33 +300,33 @@ discard block |
||
300 | 300 | } |
301 | 301 | |
302 | 302 | // Items saved via payment forms editor. |
303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
303 | + if (is_array($value) && isset($value['id'])) { |
|
304 | 304 | |
305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
305 | + $item = new GetPaid_Form_Item($value['id']); |
|
306 | 306 | |
307 | - if ( ! $item->can_purchase() ) { |
|
307 | + if (!$item->can_purchase()) { |
|
308 | 308 | continue; |
309 | 309 | } |
310 | 310 | |
311 | 311 | // Sub-total (Cart items). |
312 | - if ( isset( $value['subtotal'] ) ) { |
|
313 | - $item->set_price( $value['subtotal'] ); |
|
312 | + if (isset($value['subtotal'])) { |
|
313 | + $item->set_price($value['subtotal']); |
|
314 | 314 | } |
315 | 315 | |
316 | - if ( isset( $value['quantity'] ) ) { |
|
317 | - $item->set_quantity( $value['quantity'] ); |
|
316 | + if (isset($value['quantity'])) { |
|
317 | + $item->set_quantity($value['quantity']); |
|
318 | 318 | } |
319 | 319 | |
320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
320 | + if (isset($value['allow_quantities'])) { |
|
321 | + $item->set_allow_quantities($value['allow_quantities']); |
|
322 | 322 | } |
323 | 323 | |
324 | - if ( isset( $value['required'] ) ) { |
|
325 | - $item->set_is_required( $value['required'] ); |
|
324 | + if (isset($value['required'])) { |
|
325 | + $item->set_is_required($value['required']); |
|
326 | 326 | } |
327 | 327 | |
328 | - if ( isset( $value['description'] ) ) { |
|
329 | - $item->set_custom_description( $value['description'] ); |
|
328 | + if (isset($value['description'])) { |
|
329 | + $item->set_custom_description($value['description']); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | $prepared[] = $item; |
@@ -335,14 +335,14 @@ discard block |
||
335 | 335 | } |
336 | 336 | |
337 | 337 | // $item_id => array( 'price' => 10 ) (item variations) |
338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | - $item = new GetPaid_Form_Item( $key ); |
|
338 | + if (is_numeric($key) && is_array($value)) { |
|
339 | + $item = new GetPaid_Form_Item($key); |
|
340 | 340 | |
341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | - $item->set_price( $value['price'] ); |
|
341 | + if (isset($value['price']) && $item->user_can_set_their_price()) { |
|
342 | + $item->set_price($value['price']); |
|
343 | 343 | } |
344 | 344 | |
345 | - if ( $item->can_purchase() ) { |
|
345 | + if ($item->can_purchase()) { |
|
346 | 346 | $prepared[] = $item; |
347 | 347 | } |
348 | 348 | |
@@ -350,12 +350,12 @@ discard block |
||
350 | 350 | } |
351 | 351 | } |
352 | 352 | |
353 | - if ( 'objects' == $return && 'view' == $context ) { |
|
353 | + if ('objects' == $return && 'view' == $context) { |
|
354 | 354 | return $prepared; |
355 | 355 | } |
356 | 356 | |
357 | 357 | $items = array(); |
358 | - foreach ( $prepared as $item ) { |
|
358 | + foreach ($prepared as $item) { |
|
359 | 359 | $items[] = $item->prepare_data_for_use(); |
360 | 360 | } |
361 | 361 | |
@@ -369,14 +369,14 @@ discard block |
||
369 | 369 | * @param int $item_id The item id to return. |
370 | 370 | * @return GetPaid_Form_Item|bool |
371 | 371 | */ |
372 | - public function get_item( $item_id ) { |
|
372 | + public function get_item($item_id) { |
|
373 | 373 | |
374 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
374 | + if (empty($item_id) || !is_numeric($item_id)) { |
|
375 | 375 | return false; |
376 | 376 | } |
377 | 377 | |
378 | - foreach ( $this->get_items() as $item ) { |
|
379 | - if ( $item->get_id() == (int) $item_id ) { |
|
378 | + foreach ($this->get_items() as $item) { |
|
379 | + if ($item->get_id() == (int) $item_id) { |
|
380 | 380 | return $item; |
381 | 381 | } |
382 | 382 | } |
@@ -392,15 +392,15 @@ discard block |
||
392 | 392 | * @param string $element_type The element type to return. |
393 | 393 | * @return array|bool |
394 | 394 | */ |
395 | - public function get_element_type( $element_type ) { |
|
395 | + public function get_element_type($element_type) { |
|
396 | 396 | |
397 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
397 | + if (empty($element_type) || !is_scalar($element_type)) { |
|
398 | 398 | return false; |
399 | 399 | } |
400 | 400 | |
401 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
401 | + foreach ($this->get_prop('elements') as $element) { |
|
402 | 402 | |
403 | - if ( $element['type'] == $element_type ) { |
|
403 | + if ($element['type'] == $element_type) { |
|
404 | 404 | return $element; |
405 | 405 | } |
406 | 406 | } |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | * @param string $context View or edit context. |
417 | 417 | * @return float |
418 | 418 | */ |
419 | - public function get_earned( $context = 'view' ) { |
|
420 | - return $this->get_prop( 'earned', $context ); |
|
419 | + public function get_earned($context = 'view') { |
|
420 | + return $this->get_prop('earned', $context); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -427,8 +427,8 @@ discard block |
||
427 | 427 | * @param string $context View or edit context. |
428 | 428 | * @return float |
429 | 429 | */ |
430 | - public function get_refunded( $context = 'view' ) { |
|
431 | - return $this->get_prop( 'refunded', $context ); |
|
430 | + public function get_refunded($context = 'view') { |
|
431 | + return $this->get_prop('refunded', $context); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
@@ -438,8 +438,8 @@ discard block |
||
438 | 438 | * @param string $context View or edit context. |
439 | 439 | * @return float |
440 | 440 | */ |
441 | - public function get_cancelled( $context = 'view' ) { |
|
442 | - return $this->get_prop( 'cancelled', $context ); |
|
441 | + public function get_cancelled($context = 'view') { |
|
442 | + return $this->get_prop('cancelled', $context); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | /** |
@@ -449,8 +449,8 @@ discard block |
||
449 | 449 | * @param string $context View or edit context. |
450 | 450 | * @return float |
451 | 451 | */ |
452 | - public function get_failed( $context = 'view' ) { |
|
453 | - return $this->get_prop( 'failed', $context ); |
|
452 | + public function get_failed($context = 'view') { |
|
453 | + return $this->get_prop('failed', $context); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | /** |
@@ -461,8 +461,8 @@ discard block |
||
461 | 461 | * @return string |
462 | 462 | */ |
463 | 463 | public function get_currency() { |
464 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
464 | + $currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | + return apply_filters('getpaid-payment-form-currency', $currency, $this); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | /* |
@@ -480,8 +480,8 @@ discard block |
||
480 | 480 | * |
481 | 481 | * @since 1.0.19 |
482 | 482 | */ |
483 | - public function set_version( $value ) { |
|
484 | - $this->set_prop( 'version', $value ); |
|
483 | + public function set_version($value) { |
|
484 | + $this->set_prop('version', $value); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
@@ -491,11 +491,11 @@ discard block |
||
491 | 491 | * @param string $value Value to set. |
492 | 492 | * @return bool Whether or not the date was set. |
493 | 493 | */ |
494 | - public function set_date_created( $value ) { |
|
495 | - $date = strtotime( $value ); |
|
494 | + public function set_date_created($value) { |
|
495 | + $date = strtotime($value); |
|
496 | 496 | |
497 | - if ( $date ) { |
|
498 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
497 | + if ($date) { |
|
498 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
499 | 499 | return true; |
500 | 500 | } |
501 | 501 | |
@@ -510,11 +510,11 @@ discard block |
||
510 | 510 | * @param string $value Value to set. |
511 | 511 | * @return bool Whether or not the date was set. |
512 | 512 | */ |
513 | - public function set_date_modified( $value ) { |
|
514 | - $date = strtotime( $value ); |
|
513 | + public function set_date_modified($value) { |
|
514 | + $date = strtotime($value); |
|
515 | 515 | |
516 | - if ( $date ) { |
|
517 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
516 | + if ($date) { |
|
517 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
518 | 518 | return true; |
519 | 519 | } |
520 | 520 | |
@@ -528,8 +528,8 @@ discard block |
||
528 | 528 | * @since 1.0.19 |
529 | 529 | * @param string $value New name. |
530 | 530 | */ |
531 | - public function set_name( $value ) { |
|
532 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
531 | + public function set_name($value) { |
|
532 | + $this->set_prop('name', sanitize_text_field($value)); |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | /** |
@@ -538,8 +538,8 @@ discard block |
||
538 | 538 | * @since 1.0.19 |
539 | 539 | * @param string $value New name. |
540 | 540 | */ |
541 | - public function set_title( $value ) { |
|
542 | - $this->set_name( $value ); |
|
541 | + public function set_title($value) { |
|
542 | + $this->set_name($value); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | /** |
@@ -548,8 +548,8 @@ discard block |
||
548 | 548 | * @since 1.0.19 |
549 | 549 | * @param int $value New author. |
550 | 550 | */ |
551 | - public function set_author( $value ) { |
|
552 | - $this->set_prop( 'author', (int) $value ); |
|
551 | + public function set_author($value) { |
|
552 | + $this->set_prop('author', (int) $value); |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | /** |
@@ -559,9 +559,9 @@ discard block |
||
559 | 559 | * @sinve 2.3.4 Array values sanitized. |
560 | 560 | * @param array $value Form elements. |
561 | 561 | */ |
562 | - public function set_elements( $value ) { |
|
563 | - if ( is_array( $value ) ) { |
|
564 | - $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
562 | + public function set_elements($value) { |
|
563 | + if (is_array($value)) { |
|
564 | + $this->set_prop('elements', wp_kses_post_deep($value)); |
|
565 | 565 | } |
566 | 566 | } |
567 | 567 | |
@@ -572,36 +572,36 @@ discard block |
||
572 | 572 | * |
573 | 573 | * @return mixed |
574 | 574 | */ |
575 | - public function sanitize_array_values( $value ) { |
|
575 | + public function sanitize_array_values($value) { |
|
576 | 576 | |
577 | 577 | // sanitize |
578 | - if ( ! empty( $value ) ) { |
|
578 | + if (!empty($value)) { |
|
579 | 579 | |
580 | - foreach ( $value as $key => $val_arr ) { |
|
580 | + foreach ($value as $key => $val_arr) { |
|
581 | 581 | |
582 | - if ( is_array( $val_arr ) ) { |
|
582 | + if (is_array($val_arr)) { |
|
583 | 583 | // check if we have sub array items. |
584 | 584 | $sub_arr = array(); |
585 | - foreach ( $val_arr as $key2 => $val2 ) { |
|
586 | - if ( is_array( $val2 ) ) { |
|
587 | - $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 ); |
|
588 | - unset( $val_arr[ $key ][ $key2 ] ); |
|
585 | + foreach ($val_arr as $key2 => $val2) { |
|
586 | + if (is_array($val2)) { |
|
587 | + $sub_arr[$key2] = $this->sanitize_array_values($val2); |
|
588 | + unset($val_arr[$key][$key2]); |
|
589 | 589 | } |
590 | 590 | } |
591 | 591 | |
592 | 592 | // we allow some html in description so we sanitize it separately. |
593 | - $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : ''; |
|
593 | + $help_text = !empty($val_arr['description']) ? wp_kses_post($val_arr['description']) : ''; |
|
594 | 594 | |
595 | 595 | // sanitize array elements |
596 | - $value[ $key ] = array_map( 'sanitize_text_field', $val_arr ); |
|
596 | + $value[$key] = array_map('sanitize_text_field', $val_arr); |
|
597 | 597 | |
598 | 598 | // add back the description if set |
599 | - if ( isset( $val_arr['description'] ) ) { |
|
600 | -$value[ $key ]['description'] = $help_text;} |
|
599 | + if (isset($val_arr['description'])) { |
|
600 | +$value[$key]['description'] = $help_text; } |
|
601 | 601 | |
602 | 602 | // add back sub array items after its been sanitized. |
603 | - if ( ! empty( $sub_arr ) ) { |
|
604 | - $value[ $key ] = array_merge( $value[ $key ], $sub_arr ); |
|
603 | + if (!empty($sub_arr)) { |
|
604 | + $value[$key] = array_merge($value[$key], $sub_arr); |
|
605 | 605 | } |
606 | 606 | } |
607 | 607 | } |
@@ -616,9 +616,9 @@ discard block |
||
616 | 616 | * @since 1.0.19 |
617 | 617 | * @param array $value Form elements. |
618 | 618 | */ |
619 | - public function set_items( $value ) { |
|
620 | - if ( is_array( $value ) ) { |
|
621 | - $this->set_prop( 'items', $value ); |
|
619 | + public function set_items($value) { |
|
620 | + if (is_array($value)) { |
|
621 | + $this->set_prop('items', $value); |
|
622 | 622 | } |
623 | 623 | } |
624 | 624 | |
@@ -628,9 +628,9 @@ discard block |
||
628 | 628 | * @since 1.0.19 |
629 | 629 | * @param float $value Amount earned. |
630 | 630 | */ |
631 | - public function set_earned( $value ) { |
|
632 | - $value = max( (float) $value, 0 ); |
|
633 | - $this->set_prop( 'earned', $value ); |
|
631 | + public function set_earned($value) { |
|
632 | + $value = max((float) $value, 0); |
|
633 | + $this->set_prop('earned', $value); |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -639,9 +639,9 @@ discard block |
||
639 | 639 | * @since 1.0.19 |
640 | 640 | * @param float $value Amount refunded. |
641 | 641 | */ |
642 | - public function set_refunded( $value ) { |
|
643 | - $value = max( (float) $value, 0 ); |
|
644 | - $this->set_prop( 'refunded', $value ); |
|
642 | + public function set_refunded($value) { |
|
643 | + $value = max((float) $value, 0); |
|
644 | + $this->set_prop('refunded', $value); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
@@ -650,9 +650,9 @@ discard block |
||
650 | 650 | * @since 1.0.19 |
651 | 651 | * @param float $value Amount cancelled. |
652 | 652 | */ |
653 | - public function set_cancelled( $value ) { |
|
654 | - $value = max( (float) $value, 0 ); |
|
655 | - $this->set_prop( 'cancelled', $value ); |
|
653 | + public function set_cancelled($value) { |
|
654 | + $value = max((float) $value, 0); |
|
655 | + $this->set_prop('cancelled', $value); |
|
656 | 656 | } |
657 | 657 | |
658 | 658 | /** |
@@ -661,9 +661,9 @@ discard block |
||
661 | 661 | * @since 1.0.19 |
662 | 662 | * @param float $value Amount cancelled. |
663 | 663 | */ |
664 | - public function set_failed( $value ) { |
|
665 | - $value = max( (float) $value, 0 ); |
|
666 | - $this->set_prop( 'failed', $value ); |
|
664 | + public function set_failed($value) { |
|
665 | + $value = max((float) $value, 0); |
|
666 | + $this->set_prop('failed', $value); |
|
667 | 667 | } |
668 | 668 | |
669 | 669 | /** |
@@ -672,11 +672,11 @@ discard block |
||
672 | 672 | * @deprecated |
673 | 673 | * @return int item id |
674 | 674 | */ |
675 | - public function create( $data = array() ) { |
|
675 | + public function create($data = array()) { |
|
676 | 676 | |
677 | 677 | // Set the properties. |
678 | - if ( is_array( $data ) ) { |
|
679 | - $this->set_props( $data ); |
|
678 | + if (is_array($data)) { |
|
679 | + $this->set_props($data); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | // Save the item. |
@@ -690,8 +690,8 @@ discard block |
||
690 | 690 | * @deprecated |
691 | 691 | * @return int item id |
692 | 692 | */ |
693 | - public function update( $data = array() ) { |
|
694 | - return $this->create( $data ); |
|
693 | + public function update($data = array()) { |
|
694 | + return $this->create($data); |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /* |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | */ |
712 | 712 | public function is_default() { |
713 | 713 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
714 | - return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
|
714 | + return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this); |
|
715 | 715 | } |
716 | 716 | |
717 | 717 | /** |
@@ -723,11 +723,11 @@ discard block |
||
723 | 723 | public function is_active() { |
724 | 724 | $is_active = 0 !== (int) $this->get_id(); |
725 | 725 | |
726 | - if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) { |
|
726 | + if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') { |
|
727 | 727 | $is_active = false; |
728 | 728 | } |
729 | 729 | |
730 | - return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
|
730 | + return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this); |
|
731 | 731 | } |
732 | 732 | |
733 | 733 | /** |
@@ -736,8 +736,8 @@ discard block |
||
736 | 736 | * @since 1.0.19 |
737 | 737 | * @return bool |
738 | 738 | */ |
739 | - public function has_item( $item_id ) { |
|
740 | - return false !== $this->get_item( $item_id ); |
|
739 | + public function has_item($item_id) { |
|
740 | + return false !== $this->get_item($item_id); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | /** |
@@ -746,8 +746,8 @@ discard block |
||
746 | 746 | * @since 1.0.19 |
747 | 747 | * @return bool |
748 | 748 | */ |
749 | - public function has_element_type( $element_type ) { |
|
750 | - return false !== $this->get_element_type( $element_type ); |
|
749 | + public function has_element_type($element_type) { |
|
750 | + return false !== $this->get_element_type($element_type); |
|
751 | 751 | } |
752 | 752 | |
753 | 753 | /** |
@@ -758,13 +758,13 @@ discard block |
||
758 | 758 | */ |
759 | 759 | public function is_recurring() { |
760 | 760 | |
761 | - if ( ! empty( $this->invoice ) ) { |
|
761 | + if (!empty($this->invoice)) { |
|
762 | 762 | return $this->invoice->is_recurring(); |
763 | 763 | } |
764 | 764 | |
765 | - foreach ( $this->get_items() as $item ) { |
|
765 | + foreach ($this->get_items() as $item) { |
|
766 | 766 | |
767 | - if ( $item->is_recurring() ) { |
|
767 | + if ($item->is_recurring()) { |
|
768 | 768 | return true; |
769 | 769 | } |
770 | 770 | } |
@@ -777,7 +777,7 @@ discard block |
||
777 | 777 | * |
778 | 778 | * @since 1.0.19 |
779 | 779 | */ |
780 | - public function get_html( $extra_markup = '' ) { |
|
780 | + public function get_html($extra_markup = '') { |
|
781 | 781 | |
782 | 782 | // Return the HTML. |
783 | 783 | return wpinv_get_template_html( |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | * |
796 | 796 | * @since 1.0.19 |
797 | 797 | */ |
798 | - public function display( $extra_markup = '' ) { |
|
798 | + public function display($extra_markup = '') { |
|
799 | 799 | return wpinv_get_template( |
800 | 800 | 'payment-forms/form.php', |
801 | 801 | array( |
@@ -12,49 +12,49 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - * |
|
18 | - */ |
|
19 | - public function __construct() { |
|
20 | - add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
21 | - add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
22 | - add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
23 | - add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
24 | - add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) ); |
|
25 | - |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Registers the reports page. |
|
30 | - * |
|
31 | - */ |
|
32 | - public function register_reports_page() { |
|
33 | - |
|
34 | - add_submenu_page( |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + * |
|
18 | + */ |
|
19 | + public function __construct() { |
|
20 | + add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
21 | + add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
22 | + add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
23 | + add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
24 | + add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) ); |
|
25 | + |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Registers the reports page. |
|
30 | + * |
|
31 | + */ |
|
32 | + public function register_reports_page() { |
|
33 | + |
|
34 | + add_submenu_page( |
|
35 | 35 | 'wpinv', |
36 | 36 | __( 'Reports', 'invoicing' ), |
37 | 37 | __( 'Reports', 'invoicing' ), |
38 | 38 | wpinv_get_capability(), |
39 | 39 | 'wpinv-reports', |
40 | 40 | array( $this, 'display_reports_page' ) |
41 | - ); |
|
41 | + ); |
|
42 | 42 | |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Displays the reports page. |
|
47 | - * |
|
48 | - */ |
|
49 | - public function display_reports_page() { |
|
45 | + /** |
|
46 | + * Displays the reports page. |
|
47 | + * |
|
48 | + */ |
|
49 | + public function display_reports_page() { |
|
50 | 50 | |
51 | - // Prepare variables. |
|
52 | - $tabs = $this->get_tabs(); |
|
53 | - $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
54 | - $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
51 | + // Prepare variables. |
|
52 | + $tabs = $this->get_tabs(); |
|
53 | + $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
54 | + $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
55 | 55 | |
56 | - // Display the current tab. |
|
57 | - ?> |
|
56 | + // Display the current tab. |
|
57 | + ?> |
|
58 | 58 | |
59 | 59 | <div class="wrap"> |
60 | 60 | |
@@ -63,19 +63,19 @@ discard block |
||
63 | 63 | <nav class="nav-tab-wrapper"> |
64 | 64 | |
65 | 65 | <?php |
66 | - foreach ( $tabs as $key => $label ) { |
|
66 | + foreach ( $tabs as $key => $label ) { |
|
67 | 67 | |
68 | - $key = sanitize_key( $key ); |
|
69 | - $label = esc_html( $label ); |
|
70 | - $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
|
71 | - $url = esc_url( |
|
68 | + $key = sanitize_key( $key ); |
|
69 | + $label = esc_html( $label ); |
|
70 | + $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
|
71 | + $url = esc_url( |
|
72 | 72 | add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) ) |
73 | 73 | ); |
74 | 74 | |
75 | - echo wp_kses_post( "\n\t\t\t<a href='$url' class='" . $class . "'>$label</a>" ); |
|
75 | + echo wp_kses_post( "\n\t\t\t<a href='$url' class='" . $class . "'>$label</a>" ); |
|
76 | 76 | |
77 | - } |
|
78 | - ?> |
|
77 | + } |
|
78 | + ?> |
|
79 | 79 | |
80 | 80 | </nav> |
81 | 81 | |
@@ -86,82 +86,82 @@ discard block |
||
86 | 86 | </div> |
87 | 87 | <?php |
88 | 88 | |
89 | - // Wordfence loads an unsupported version of chart js on our page. |
|
90 | - wp_deregister_style( 'chart-js' ); |
|
91 | - wp_deregister_script( 'chart-js' ); |
|
92 | - wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.min.js', array( 'jquery' ), '3.7.1', true ); |
|
89 | + // Wordfence loads an unsupported version of chart js on our page. |
|
90 | + wp_deregister_style( 'chart-js' ); |
|
91 | + wp_deregister_script( 'chart-js' ); |
|
92 | + wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.min.js', array( 'jquery' ), '3.7.1', true ); |
|
93 | 93 | |
94 | - } |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Retrieves reports page tabs. |
|
98 | - * |
|
99 | - * @return array |
|
100 | - */ |
|
101 | - public function get_tabs() { |
|
96 | + /** |
|
97 | + * Retrieves reports page tabs. |
|
98 | + * |
|
99 | + * @return array |
|
100 | + */ |
|
101 | + public function get_tabs() { |
|
102 | 102 | |
103 | - $tabs = array( |
|
104 | - 'reports' => __( 'Reports', 'invoicing' ), |
|
105 | - 'export' => __( 'Export', 'invoicing' ), |
|
106 | - ); |
|
103 | + $tabs = array( |
|
104 | + 'reports' => __( 'Reports', 'invoicing' ), |
|
105 | + 'export' => __( 'Export', 'invoicing' ), |
|
106 | + ); |
|
107 | 107 | |
108 | - return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
109 | - } |
|
108 | + return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * Displays the reports tab. |
|
113 | - * |
|
114 | - */ |
|
115 | - public function display_reports_tab() { |
|
111 | + /** |
|
112 | + * Displays the reports tab. |
|
113 | + * |
|
114 | + */ |
|
115 | + public function display_reports_tab() { |
|
116 | 116 | |
117 | - $reports = new GetPaid_Reports_Report(); |
|
118 | - $reports->display(); |
|
117 | + $reports = new GetPaid_Reports_Report(); |
|
118 | + $reports->display(); |
|
119 | 119 | |
120 | - } |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Displays the exports tab. |
|
124 | - * |
|
125 | - */ |
|
126 | - public function display_exports_tab() { |
|
122 | + /** |
|
123 | + * Displays the exports tab. |
|
124 | + * |
|
125 | + */ |
|
126 | + public function display_exports_tab() { |
|
127 | 127 | |
128 | - $exports = new GetPaid_Reports_Export(); |
|
129 | - $exports->display(); |
|
128 | + $exports = new GetPaid_Reports_Export(); |
|
129 | + $exports->display(); |
|
130 | 130 | |
131 | - } |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * Donwnloads a graph. |
|
135 | - * |
|
136 | - * @param array $args |
|
137 | - */ |
|
138 | - public function download_graph( $args ) { |
|
133 | + /** |
|
134 | + * Donwnloads a graph. |
|
135 | + * |
|
136 | + * @param array $args |
|
137 | + */ |
|
138 | + public function download_graph( $args ) { |
|
139 | 139 | |
140 | - if ( ! empty( $args['graph'] ) ) { |
|
141 | - $downloader = new GetPaid_Graph_Downloader(); |
|
142 | - $downloader->download( $args['graph'] ); |
|
143 | - } |
|
140 | + if ( ! empty( $args['graph'] ) ) { |
|
141 | + $downloader = new GetPaid_Graph_Downloader(); |
|
142 | + $downloader->download( $args['graph'] ); |
|
143 | + } |
|
144 | 144 | |
145 | - } |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * Exports invoices. |
|
149 | - * |
|
150 | - * @param array $args |
|
151 | - */ |
|
152 | - public function export_invoices( $args ) { |
|
147 | + /** |
|
148 | + * Exports invoices. |
|
149 | + * |
|
150 | + * @param array $args |
|
151 | + */ |
|
152 | + public function export_invoices( $args ) { |
|
153 | 153 | |
154 | - if ( ! empty( $args['post_type'] ) ) { |
|
154 | + if ( ! empty( $args['post_type'] ) ) { |
|
155 | 155 | |
156 | - if ( 'subscriptions' === $args['post_type'] ) { |
|
157 | - $downloader = new GetPaid_Subscription_Exporter(); |
|
158 | - } else { |
|
159 | - $downloader = new GetPaid_Invoice_Exporter(); |
|
160 | - } |
|
156 | + if ( 'subscriptions' === $args['post_type'] ) { |
|
157 | + $downloader = new GetPaid_Subscription_Exporter(); |
|
158 | + } else { |
|
159 | + $downloader = new GetPaid_Invoice_Exporter(); |
|
160 | + } |
|
161 | 161 | |
162 | - $downloader->export( $args['post_type'], $args ); |
|
163 | - } |
|
162 | + $downloader->export( $args['post_type'], $args ); |
|
163 | + } |
|
164 | 164 | |
165 | - } |
|
165 | + } |
|
166 | 166 | |
167 | 167 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports Class. |
@@ -17,11 +17,11 @@ discard block |
||
17 | 17 | * |
18 | 18 | */ |
19 | 19 | public function __construct() { |
20 | - add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
21 | - add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
22 | - add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
23 | - add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
24 | - add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) ); |
|
20 | + add_action('admin_menu', array($this, 'register_reports_page'), 20); |
|
21 | + add_action('wpinv_reports_tab_reports', array($this, 'display_reports_tab')); |
|
22 | + add_action('wpinv_reports_tab_export', array($this, 'display_exports_tab')); |
|
23 | + add_action('getpaid_authenticated_admin_action_download_graph', array($this, 'download_graph')); |
|
24 | + add_action('getpaid_authenticated_admin_action_export_invoices', array($this, 'export_invoices')); |
|
25 | 25 | |
26 | 26 | } |
27 | 27 | |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | |
34 | 34 | add_submenu_page( |
35 | 35 | 'wpinv', |
36 | - __( 'Reports', 'invoicing' ), |
|
37 | - __( 'Reports', 'invoicing' ), |
|
36 | + __('Reports', 'invoicing'), |
|
37 | + __('Reports', 'invoicing'), |
|
38 | 38 | wpinv_get_capability(), |
39 | 39 | 'wpinv-reports', |
40 | - array( $this, 'display_reports_page' ) |
|
40 | + array($this, 'display_reports_page') |
|
41 | 41 | ); |
42 | 42 | |
43 | 43 | } |
@@ -50,46 +50,46 @@ discard block |
||
50 | 50 | |
51 | 51 | // Prepare variables. |
52 | 52 | $tabs = $this->get_tabs(); |
53 | - $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
54 | - $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
53 | + $current_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'reports'; |
|
54 | + $current_tab = array_key_exists($current_tab, $tabs) ? $current_tab : 'reports'; |
|
55 | 55 | |
56 | 56 | // Display the current tab. |
57 | 57 | ?> |
58 | 58 | |
59 | 59 | <div class="wrap"> |
60 | 60 | |
61 | - <h1><?php echo esc_html( $tabs[ $current_tab ] ); ?></h1> |
|
61 | + <h1><?php echo esc_html($tabs[$current_tab]); ?></h1> |
|
62 | 62 | |
63 | 63 | <nav class="nav-tab-wrapper"> |
64 | 64 | |
65 | 65 | <?php |
66 | - foreach ( $tabs as $key => $label ) { |
|
66 | + foreach ($tabs as $key => $label) { |
|
67 | 67 | |
68 | - $key = sanitize_key( $key ); |
|
69 | - $label = esc_html( $label ); |
|
68 | + $key = sanitize_key($key); |
|
69 | + $label = esc_html($label); |
|
70 | 70 | $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
71 | 71 | $url = esc_url( |
72 | - add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) ) |
|
72 | + add_query_arg('tab', $key, admin_url('admin.php?page=wpinv-reports')) |
|
73 | 73 | ); |
74 | 74 | |
75 | - echo wp_kses_post( "\n\t\t\t<a href='$url' class='" . $class . "'>$label</a>" ); |
|
75 | + echo wp_kses_post("\n\t\t\t<a href='$url' class='" . $class . "'>$label</a>"); |
|
76 | 76 | |
77 | 77 | } |
78 | 78 | ?> |
79 | 79 | |
80 | 80 | </nav> |
81 | 81 | |
82 | - <div class="bsui <?php echo esc_attr( $current_tab ); ?>"> |
|
83 | - <?php do_action( "wpinv_reports_tab_{$current_tab}" ); ?> |
|
82 | + <div class="bsui <?php echo esc_attr($current_tab); ?>"> |
|
83 | + <?php do_action("wpinv_reports_tab_{$current_tab}"); ?> |
|
84 | 84 | </div> |
85 | 85 | |
86 | 86 | </div> |
87 | 87 | <?php |
88 | 88 | |
89 | 89 | // Wordfence loads an unsupported version of chart js on our page. |
90 | - wp_deregister_style( 'chart-js' ); |
|
91 | - wp_deregister_script( 'chart-js' ); |
|
92 | - wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.min.js', array( 'jquery' ), '3.7.1', true ); |
|
90 | + wp_deregister_style('chart-js'); |
|
91 | + wp_deregister_script('chart-js'); |
|
92 | + wp_enqueue_script('chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.min.js', array('jquery'), '3.7.1', true); |
|
93 | 93 | |
94 | 94 | } |
95 | 95 | |
@@ -101,11 +101,11 @@ discard block |
||
101 | 101 | public function get_tabs() { |
102 | 102 | |
103 | 103 | $tabs = array( |
104 | - 'reports' => __( 'Reports', 'invoicing' ), |
|
105 | - 'export' => __( 'Export', 'invoicing' ), |
|
104 | + 'reports' => __('Reports', 'invoicing'), |
|
105 | + 'export' => __('Export', 'invoicing'), |
|
106 | 106 | ); |
107 | 107 | |
108 | - return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
108 | + return apply_filters('getpaid_report_tabs', $tabs); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -135,11 +135,11 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @param array $args |
137 | 137 | */ |
138 | - public function download_graph( $args ) { |
|
138 | + public function download_graph($args) { |
|
139 | 139 | |
140 | - if ( ! empty( $args['graph'] ) ) { |
|
140 | + if (!empty($args['graph'])) { |
|
141 | 141 | $downloader = new GetPaid_Graph_Downloader(); |
142 | - $downloader->download( $args['graph'] ); |
|
142 | + $downloader->download($args['graph']); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | } |
@@ -149,17 +149,17 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @param array $args |
151 | 151 | */ |
152 | - public function export_invoices( $args ) { |
|
152 | + public function export_invoices($args) { |
|
153 | 153 | |
154 | - if ( ! empty( $args['post_type'] ) ) { |
|
154 | + if (!empty($args['post_type'])) { |
|
155 | 155 | |
156 | - if ( 'subscriptions' === $args['post_type'] ) { |
|
156 | + if ('subscriptions' === $args['post_type']) { |
|
157 | 157 | $downloader = new GetPaid_Subscription_Exporter(); |
158 | 158 | } else { |
159 | 159 | $downloader = new GetPaid_Invoice_Exporter(); |
160 | 160 | } |
161 | 161 | |
162 | - $downloader->export( $args['post_type'], $args ); |
|
162 | + $downloader->export($args['post_type'], $args); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | } |
@@ -12,47 +12,47 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Export { |
14 | 14 | |
15 | - /** |
|
16 | - * Displays the reports tab. |
|
17 | - * |
|
18 | - */ |
|
19 | - public function display() { |
|
20 | - |
|
21 | - echo "<div class='row mt-4' style='max-width: 920px;' >"; |
|
22 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
23 | - $this->display_post_type_export( $post_type ); |
|
24 | - } |
|
25 | - $this->display_subscription_export(); |
|
26 | - echo '</div>'; |
|
27 | - |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * Retrieves the download url. |
|
32 | - * |
|
33 | - */ |
|
34 | - public function get_download_url( $post_type ) { |
|
35 | - |
|
36 | - return wp_nonce_url( |
|
37 | - add_query_arg( |
|
38 | - array( |
|
39 | - 'getpaid-admin-action' => 'export_invoices', |
|
40 | - 'post_type' => urlencode( $post_type ), |
|
41 | - ) |
|
42 | - ), |
|
43 | - 'getpaid-nonce', |
|
44 | - 'getpaid-nonce' |
|
45 | - ); |
|
46 | - |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Displays a single post type export card. |
|
51 | - * |
|
52 | - */ |
|
53 | - public function display_post_type_export( $post_type ) { |
|
54 | - |
|
55 | - ?> |
|
15 | + /** |
|
16 | + * Displays the reports tab. |
|
17 | + * |
|
18 | + */ |
|
19 | + public function display() { |
|
20 | + |
|
21 | + echo "<div class='row mt-4' style='max-width: 920px;' >"; |
|
22 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
23 | + $this->display_post_type_export( $post_type ); |
|
24 | + } |
|
25 | + $this->display_subscription_export(); |
|
26 | + echo '</div>'; |
|
27 | + |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * Retrieves the download url. |
|
32 | + * |
|
33 | + */ |
|
34 | + public function get_download_url( $post_type ) { |
|
35 | + |
|
36 | + return wp_nonce_url( |
|
37 | + add_query_arg( |
|
38 | + array( |
|
39 | + 'getpaid-admin-action' => 'export_invoices', |
|
40 | + 'post_type' => urlencode( $post_type ), |
|
41 | + ) |
|
42 | + ), |
|
43 | + 'getpaid-nonce', |
|
44 | + 'getpaid-nonce' |
|
45 | + ); |
|
46 | + |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Displays a single post type export card. |
|
51 | + * |
|
52 | + */ |
|
53 | + public function display_post_type_export( $post_type ) { |
|
54 | + |
|
55 | + ?> |
|
56 | 56 | |
57 | 57 | <div class="col-12 col-md-6"> |
58 | 58 | <div class="card m-0 p-0" style="max-width:100%"> |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | <div class="card-header"> |
61 | 61 | <strong> |
62 | 62 | <?php |
63 | - printf( |
|
64 | - esc_html__( 'Export %s', 'invoicing' ), |
|
65 | - esc_html( getpaid_get_post_type_label( $post_type ) ) |
|
66 | - ); |
|
67 | - ?> |
|
63 | + printf( |
|
64 | + esc_html__( 'Export %s', 'invoicing' ), |
|
65 | + esc_html( getpaid_get_post_type_label( $post_type ) ) |
|
66 | + ); |
|
67 | + ?> |
|
68 | 68 | </strong> |
69 | 69 | </div> |
70 | 70 | |
@@ -73,12 +73,12 @@ discard block |
||
73 | 73 | <form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>"> |
74 | 74 | |
75 | 75 | <?php |
76 | - $this->display_markup( $this->generate_from_date( $post_type ) ); |
|
77 | - $this->display_markup( $this->generate_to_date( $post_type ) ); |
|
78 | - $this->display_markup( $this->generate_post_status_select( $post_type ) ); |
|
79 | - $this->display_markup( $this->generate_file_type_select( $post_type ) ); |
|
80 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
81 | - ?> |
|
76 | + $this->display_markup( $this->generate_from_date( $post_type ) ); |
|
77 | + $this->display_markup( $this->generate_to_date( $post_type ) ); |
|
78 | + $this->display_markup( $this->generate_post_status_select( $post_type ) ); |
|
79 | + $this->display_markup( $this->generate_file_type_select( $post_type ) ); |
|
80 | + submit_button( __( 'Download', 'invoicing' ) ); |
|
81 | + ?> |
|
82 | 82 | |
83 | 83 | </form> |
84 | 84 | |
@@ -89,125 +89,125 @@ discard block |
||
89 | 89 | |
90 | 90 | <?php |
91 | 91 | |
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Generates the from date input field. |
|
96 | - * |
|
97 | - */ |
|
98 | - public function generate_from_date( $post_type ) { |
|
99 | - |
|
100 | - return aui()->input( |
|
101 | - array( |
|
102 | - 'name' => 'from_date', |
|
103 | - 'id' => esc_attr( "$post_type-from_date" ), |
|
104 | - 'placeholder' => 'yy-mm-dd', |
|
105 | - 'label' => __( 'From Date', 'invoicing' ), |
|
106 | - 'label_type' => 'vertical', |
|
107 | - 'label_class' => 'd-block', |
|
108 | - 'type' => 'datepicker', |
|
109 | - ) |
|
110 | - ); |
|
111 | - |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Generates the to date input field. |
|
116 | - * |
|
117 | - */ |
|
118 | - public function generate_to_date( $post_type ) { |
|
119 | - |
|
120 | - return aui()->input( |
|
121 | - array( |
|
122 | - 'name' => 'to_date', |
|
123 | - 'id' => esc_attr( "$post_type-to_date" ), |
|
124 | - 'placeholder' => 'yy-mm-dd', |
|
125 | - 'label' => __( 'To Date', 'invoicing' ), |
|
126 | - 'label_type' => 'vertical', |
|
127 | - 'label_class' => 'd-block', |
|
128 | - 'type' => 'datepicker', |
|
129 | - ) |
|
130 | - ); |
|
131 | - |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Generates the to post status select field. |
|
136 | - * |
|
137 | - */ |
|
138 | - public function generate_post_status_select( $post_type ) { |
|
139 | - |
|
140 | - if ( 'subscriptions' === $post_type ) { |
|
141 | - $options = getpaid_get_subscription_statuses(); |
|
142 | - } else { |
|
143 | - $options = wpinv_get_invoice_statuses( true, false, $post_type ); |
|
144 | - } |
|
145 | - |
|
146 | - return aui()->select( |
|
147 | - array( |
|
148 | - 'name' => 'status', |
|
149 | - 'id' => esc_attr( "$post_type-status" ), |
|
150 | - 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
151 | - 'label' => __( 'Status', 'invoicing' ), |
|
152 | - 'label_type' => 'vertical', |
|
153 | - 'label_class' => 'd-block', |
|
154 | - 'options' => $options, |
|
155 | - ) |
|
156 | - ); |
|
157 | - |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Generates the to file type select field. |
|
162 | - * |
|
163 | - */ |
|
164 | - public function generate_file_type_select( $post_type ) { |
|
165 | - |
|
166 | - return aui()->select( |
|
167 | - array( |
|
168 | - 'name' => 'file_type', |
|
169 | - 'id' => esc_attr( "$post_type-file_type" ), |
|
170 | - 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
171 | - 'label' => __( 'Export File', 'invoicing' ), |
|
172 | - 'label_type' => 'vertical', |
|
173 | - 'label_class' => 'd-block', |
|
174 | - 'options' => array( |
|
175 | - 'csv' => __( 'CSV', 'invoicing' ), |
|
176 | - 'xml' => __( 'XML', 'invoicing' ), |
|
177 | - 'json' => __( 'JSON', 'invoicing' ), |
|
178 | - ), |
|
179 | - ) |
|
180 | - ); |
|
181 | - |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Displays a field's markup. |
|
186 | - * |
|
187 | - */ |
|
188 | - public function display_markup( $markup ) { |
|
189 | - |
|
190 | - echo wp_kses( |
|
191 | - str_replace( |
|
192 | - array( |
|
193 | - 'form-control', |
|
194 | - 'custom-select', |
|
195 | - ), |
|
196 | - 'regular-text', |
|
197 | - $markup |
|
198 | - ), |
|
199 | - getpaid_allowed_html() |
|
200 | - ); |
|
201 | - |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Displays a subscription export card. |
|
206 | - * |
|
207 | - */ |
|
208 | - public function display_subscription_export() { |
|
209 | - |
|
210 | - ?> |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Generates the from date input field. |
|
96 | + * |
|
97 | + */ |
|
98 | + public function generate_from_date( $post_type ) { |
|
99 | + |
|
100 | + return aui()->input( |
|
101 | + array( |
|
102 | + 'name' => 'from_date', |
|
103 | + 'id' => esc_attr( "$post_type-from_date" ), |
|
104 | + 'placeholder' => 'yy-mm-dd', |
|
105 | + 'label' => __( 'From Date', 'invoicing' ), |
|
106 | + 'label_type' => 'vertical', |
|
107 | + 'label_class' => 'd-block', |
|
108 | + 'type' => 'datepicker', |
|
109 | + ) |
|
110 | + ); |
|
111 | + |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Generates the to date input field. |
|
116 | + * |
|
117 | + */ |
|
118 | + public function generate_to_date( $post_type ) { |
|
119 | + |
|
120 | + return aui()->input( |
|
121 | + array( |
|
122 | + 'name' => 'to_date', |
|
123 | + 'id' => esc_attr( "$post_type-to_date" ), |
|
124 | + 'placeholder' => 'yy-mm-dd', |
|
125 | + 'label' => __( 'To Date', 'invoicing' ), |
|
126 | + 'label_type' => 'vertical', |
|
127 | + 'label_class' => 'd-block', |
|
128 | + 'type' => 'datepicker', |
|
129 | + ) |
|
130 | + ); |
|
131 | + |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Generates the to post status select field. |
|
136 | + * |
|
137 | + */ |
|
138 | + public function generate_post_status_select( $post_type ) { |
|
139 | + |
|
140 | + if ( 'subscriptions' === $post_type ) { |
|
141 | + $options = getpaid_get_subscription_statuses(); |
|
142 | + } else { |
|
143 | + $options = wpinv_get_invoice_statuses( true, false, $post_type ); |
|
144 | + } |
|
145 | + |
|
146 | + return aui()->select( |
|
147 | + array( |
|
148 | + 'name' => 'status', |
|
149 | + 'id' => esc_attr( "$post_type-status" ), |
|
150 | + 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
151 | + 'label' => __( 'Status', 'invoicing' ), |
|
152 | + 'label_type' => 'vertical', |
|
153 | + 'label_class' => 'd-block', |
|
154 | + 'options' => $options, |
|
155 | + ) |
|
156 | + ); |
|
157 | + |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Generates the to file type select field. |
|
162 | + * |
|
163 | + */ |
|
164 | + public function generate_file_type_select( $post_type ) { |
|
165 | + |
|
166 | + return aui()->select( |
|
167 | + array( |
|
168 | + 'name' => 'file_type', |
|
169 | + 'id' => esc_attr( "$post_type-file_type" ), |
|
170 | + 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
171 | + 'label' => __( 'Export File', 'invoicing' ), |
|
172 | + 'label_type' => 'vertical', |
|
173 | + 'label_class' => 'd-block', |
|
174 | + 'options' => array( |
|
175 | + 'csv' => __( 'CSV', 'invoicing' ), |
|
176 | + 'xml' => __( 'XML', 'invoicing' ), |
|
177 | + 'json' => __( 'JSON', 'invoicing' ), |
|
178 | + ), |
|
179 | + ) |
|
180 | + ); |
|
181 | + |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Displays a field's markup. |
|
186 | + * |
|
187 | + */ |
|
188 | + public function display_markup( $markup ) { |
|
189 | + |
|
190 | + echo wp_kses( |
|
191 | + str_replace( |
|
192 | + array( |
|
193 | + 'form-control', |
|
194 | + 'custom-select', |
|
195 | + ), |
|
196 | + 'regular-text', |
|
197 | + $markup |
|
198 | + ), |
|
199 | + getpaid_allowed_html() |
|
200 | + ); |
|
201 | + |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Displays a subscription export card. |
|
206 | + * |
|
207 | + */ |
|
208 | + public function display_subscription_export() { |
|
209 | + |
|
210 | + ?> |
|
211 | 211 | |
212 | 212 | <div class="col-12 col-md-6"> |
213 | 213 | <div class="card m-0 p-0" style="max-width:100%"> |
@@ -223,12 +223,12 @@ discard block |
||
223 | 223 | <form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>"> |
224 | 224 | |
225 | 225 | <?php |
226 | - $this->display_markup( $this->generate_from_date( 'subscriptions' ) ); |
|
227 | - $this->display_markup( $this->generate_to_date( 'subscriptions' ) ); |
|
228 | - $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) ); |
|
229 | - $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) ); |
|
230 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
231 | - ?> |
|
226 | + $this->display_markup( $this->generate_from_date( 'subscriptions' ) ); |
|
227 | + $this->display_markup( $this->generate_to_date( 'subscriptions' ) ); |
|
228 | + $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) ); |
|
229 | + $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) ); |
|
230 | + submit_button( __( 'Download', 'invoicing' ) ); |
|
231 | + ?> |
|
232 | 232 | |
233 | 233 | </form> |
234 | 234 | |
@@ -239,6 +239,6 @@ discard block |
||
239 | 239 | |
240 | 240 | <?php |
241 | 241 | |
242 | - } |
|
242 | + } |
|
243 | 243 | |
244 | 244 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports_Export Class. |
@@ -19,8 +19,8 @@ discard block |
||
19 | 19 | public function display() { |
20 | 20 | |
21 | 21 | echo "<div class='row mt-4' style='max-width: 920px;' >"; |
22 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
23 | - $this->display_post_type_export( $post_type ); |
|
22 | + foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) { |
|
23 | + $this->display_post_type_export($post_type); |
|
24 | 24 | } |
25 | 25 | $this->display_subscription_export(); |
26 | 26 | echo '</div>'; |
@@ -31,13 +31,13 @@ discard block |
||
31 | 31 | * Retrieves the download url. |
32 | 32 | * |
33 | 33 | */ |
34 | - public function get_download_url( $post_type ) { |
|
34 | + public function get_download_url($post_type) { |
|
35 | 35 | |
36 | 36 | return wp_nonce_url( |
37 | 37 | add_query_arg( |
38 | 38 | array( |
39 | 39 | 'getpaid-admin-action' => 'export_invoices', |
40 | - 'post_type' => urlencode( $post_type ), |
|
40 | + 'post_type' => urlencode($post_type), |
|
41 | 41 | ) |
42 | 42 | ), |
43 | 43 | 'getpaid-nonce', |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * Displays a single post type export card. |
51 | 51 | * |
52 | 52 | */ |
53 | - public function display_post_type_export( $post_type ) { |
|
53 | + public function display_post_type_export($post_type) { |
|
54 | 54 | |
55 | 55 | ?> |
56 | 56 | |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | <strong> |
62 | 62 | <?php |
63 | 63 | printf( |
64 | - esc_html__( 'Export %s', 'invoicing' ), |
|
65 | - esc_html( getpaid_get_post_type_label( $post_type ) ) |
|
64 | + esc_html__('Export %s', 'invoicing'), |
|
65 | + esc_html(getpaid_get_post_type_label($post_type)) |
|
66 | 66 | ); |
67 | 67 | ?> |
68 | 68 | </strong> |
@@ -70,14 +70,14 @@ discard block |
||
70 | 70 | |
71 | 71 | <div class="card-body"> |
72 | 72 | |
73 | - <form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>"> |
|
73 | + <form method="post" action="<?php echo esc_url($this->get_download_url($post_type)); ?>"> |
|
74 | 74 | |
75 | 75 | <?php |
76 | - $this->display_markup( $this->generate_from_date( $post_type ) ); |
|
77 | - $this->display_markup( $this->generate_to_date( $post_type ) ); |
|
78 | - $this->display_markup( $this->generate_post_status_select( $post_type ) ); |
|
79 | - $this->display_markup( $this->generate_file_type_select( $post_type ) ); |
|
80 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
76 | + $this->display_markup($this->generate_from_date($post_type)); |
|
77 | + $this->display_markup($this->generate_to_date($post_type)); |
|
78 | + $this->display_markup($this->generate_post_status_select($post_type)); |
|
79 | + $this->display_markup($this->generate_file_type_select($post_type)); |
|
80 | + submit_button(__('Download', 'invoicing')); |
|
81 | 81 | ?> |
82 | 82 | |
83 | 83 | </form> |
@@ -95,14 +95,14 @@ discard block |
||
95 | 95 | * Generates the from date input field. |
96 | 96 | * |
97 | 97 | */ |
98 | - public function generate_from_date( $post_type ) { |
|
98 | + public function generate_from_date($post_type) { |
|
99 | 99 | |
100 | 100 | return aui()->input( |
101 | 101 | array( |
102 | 102 | 'name' => 'from_date', |
103 | - 'id' => esc_attr( "$post_type-from_date" ), |
|
103 | + 'id' => esc_attr("$post_type-from_date"), |
|
104 | 104 | 'placeholder' => 'yy-mm-dd', |
105 | - 'label' => __( 'From Date', 'invoicing' ), |
|
105 | + 'label' => __('From Date', 'invoicing'), |
|
106 | 106 | 'label_type' => 'vertical', |
107 | 107 | 'label_class' => 'd-block', |
108 | 108 | 'type' => 'datepicker', |
@@ -115,14 +115,14 @@ discard block |
||
115 | 115 | * Generates the to date input field. |
116 | 116 | * |
117 | 117 | */ |
118 | - public function generate_to_date( $post_type ) { |
|
118 | + public function generate_to_date($post_type) { |
|
119 | 119 | |
120 | 120 | return aui()->input( |
121 | 121 | array( |
122 | 122 | 'name' => 'to_date', |
123 | - 'id' => esc_attr( "$post_type-to_date" ), |
|
123 | + 'id' => esc_attr("$post_type-to_date"), |
|
124 | 124 | 'placeholder' => 'yy-mm-dd', |
125 | - 'label' => __( 'To Date', 'invoicing' ), |
|
125 | + 'label' => __('To Date', 'invoicing'), |
|
126 | 126 | 'label_type' => 'vertical', |
127 | 127 | 'label_class' => 'd-block', |
128 | 128 | 'type' => 'datepicker', |
@@ -135,20 +135,20 @@ discard block |
||
135 | 135 | * Generates the to post status select field. |
136 | 136 | * |
137 | 137 | */ |
138 | - public function generate_post_status_select( $post_type ) { |
|
138 | + public function generate_post_status_select($post_type) { |
|
139 | 139 | |
140 | - if ( 'subscriptions' === $post_type ) { |
|
140 | + if ('subscriptions' === $post_type) { |
|
141 | 141 | $options = getpaid_get_subscription_statuses(); |
142 | 142 | } else { |
143 | - $options = wpinv_get_invoice_statuses( true, false, $post_type ); |
|
143 | + $options = wpinv_get_invoice_statuses(true, false, $post_type); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | return aui()->select( |
147 | 147 | array( |
148 | 148 | 'name' => 'status', |
149 | - 'id' => esc_attr( "$post_type-status" ), |
|
150 | - 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
151 | - 'label' => __( 'Status', 'invoicing' ), |
|
149 | + 'id' => esc_attr("$post_type-status"), |
|
150 | + 'placeholder' => __('All Statuses', 'invoicing'), |
|
151 | + 'label' => __('Status', 'invoicing'), |
|
152 | 152 | 'label_type' => 'vertical', |
153 | 153 | 'label_class' => 'd-block', |
154 | 154 | 'options' => $options, |
@@ -161,20 +161,20 @@ discard block |
||
161 | 161 | * Generates the to file type select field. |
162 | 162 | * |
163 | 163 | */ |
164 | - public function generate_file_type_select( $post_type ) { |
|
164 | + public function generate_file_type_select($post_type) { |
|
165 | 165 | |
166 | 166 | return aui()->select( |
167 | 167 | array( |
168 | 168 | 'name' => 'file_type', |
169 | - 'id' => esc_attr( "$post_type-file_type" ), |
|
170 | - 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
171 | - 'label' => __( 'Export File', 'invoicing' ), |
|
169 | + 'id' => esc_attr("$post_type-file_type"), |
|
170 | + 'placeholder' => __('Select File Type', 'invoicing'), |
|
171 | + 'label' => __('Export File', 'invoicing'), |
|
172 | 172 | 'label_type' => 'vertical', |
173 | 173 | 'label_class' => 'd-block', |
174 | 174 | 'options' => array( |
175 | - 'csv' => __( 'CSV', 'invoicing' ), |
|
176 | - 'xml' => __( 'XML', 'invoicing' ), |
|
177 | - 'json' => __( 'JSON', 'invoicing' ), |
|
175 | + 'csv' => __('CSV', 'invoicing'), |
|
176 | + 'xml' => __('XML', 'invoicing'), |
|
177 | + 'json' => __('JSON', 'invoicing'), |
|
178 | 178 | ), |
179 | 179 | ) |
180 | 180 | ); |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * Displays a field's markup. |
186 | 186 | * |
187 | 187 | */ |
188 | - public function display_markup( $markup ) { |
|
188 | + public function display_markup($markup) { |
|
189 | 189 | |
190 | 190 | echo wp_kses( |
191 | 191 | str_replace( |
@@ -214,20 +214,20 @@ discard block |
||
214 | 214 | |
215 | 215 | <div class="card-header"> |
216 | 216 | <strong> |
217 | - <?php esc_html_e( 'Export Subscriptions', 'invoicing' ); ?> |
|
217 | + <?php esc_html_e('Export Subscriptions', 'invoicing'); ?> |
|
218 | 218 | </strong> |
219 | 219 | </div> |
220 | 220 | |
221 | 221 | <div class="card-body"> |
222 | 222 | |
223 | - <form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>"> |
|
223 | + <form method="post" action="<?php echo esc_url($this->get_download_url('subscriptions')); ?>"> |
|
224 | 224 | |
225 | 225 | <?php |
226 | - $this->display_markup( $this->generate_from_date( 'subscriptions' ) ); |
|
227 | - $this->display_markup( $this->generate_to_date( 'subscriptions' ) ); |
|
228 | - $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) ); |
|
229 | - $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) ); |
|
230 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
226 | + $this->display_markup($this->generate_from_date('subscriptions')); |
|
227 | + $this->display_markup($this->generate_to_date('subscriptions')); |
|
228 | + $this->display_markup($this->generate_post_status_select('subscriptions')); |
|
229 | + $this->display_markup($this->generate_file_type_select('subscriptions')); |
|
230 | + submit_button(__('Download', 'invoicing')); |
|
231 | 231 | ?> |
232 | 232 | |
233 | 233 | </form> |
@@ -12,218 +12,218 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Graph_Downloader { |
14 | 14 | |
15 | - /** |
|
16 | - * @var GetPaid_Reports_Report |
|
17 | - */ |
|
18 | - public $handler; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - */ |
|
24 | - public function __construct() { |
|
25 | - $this->handler = new GetPaid_Reports_Report(); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Prepares the datastore handler. |
|
30 | - * |
|
31 | - * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
|
32 | - */ |
|
33 | - public function prepare_handler( $graph ) { |
|
34 | - |
|
35 | - if ( empty( $this->handler->views[ $graph ] ) ) { |
|
36 | - wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 ); |
|
37 | - } |
|
38 | - |
|
39 | - return new $this->handler->views[ $graph ]['class'](); |
|
40 | - |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Prepares the output stream. |
|
45 | - * |
|
46 | - * @return resource |
|
47 | - */ |
|
48 | - public function prepare_output() { |
|
49 | - |
|
50 | - $output = fopen( 'php://output', 'w' ); |
|
51 | - |
|
52 | - if ( false === $output ) { |
|
53 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
54 | - } |
|
55 | - |
|
56 | - return $output; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Prepares the file type. |
|
61 | - * |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public function prepare_file_type( $graph ) { |
|
65 | - |
|
66 | - $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
67 | - $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
68 | - |
|
69 | - header( "Content-Type:application/$file_type" ); |
|
70 | - header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
71 | - |
|
72 | - return $file_type; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Handles the actual download. |
|
77 | - * |
|
78 | - */ |
|
79 | - public function download( $graph ) { |
|
80 | - global $wpdb; |
|
81 | - |
|
82 | - $handler = $this->prepare_handler( $graph ); |
|
83 | - $stream = $this->prepare_output(); |
|
84 | - $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
85 | - $headers = array( $handler->field, 'total', 'total_raw' ); |
|
86 | - $file_type = $this->prepare_file_type( $graph ); |
|
87 | - |
|
88 | - if ( 'csv' == $file_type ) { |
|
89 | - $this->download_csv( $stats, $stream, $headers ); |
|
90 | - } elseif ( 'xml' == $file_type ) { |
|
91 | - $this->download_xml( $stats, $stream, $headers ); |
|
92 | - } else { |
|
93 | - $this->download_json( $stats, $stream, $headers ); |
|
94 | - } |
|
95 | - |
|
96 | - fclose( $stream ); |
|
97 | - exit; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Downloads graph as csv |
|
102 | - * |
|
103 | - * @param array $stats The stats being downloaded. |
|
104 | - * @param resource $stream The stream to output to. |
|
105 | - * @param array $headers The fields to stream. |
|
106 | - * @since 1.0.19 |
|
107 | - */ |
|
108 | - public function download_csv( $stats, $stream, $headers ) { |
|
109 | - |
|
110 | - // Output the csv column headers. |
|
111 | - fputcsv( $stream, $headers ); |
|
112 | - |
|
113 | - // Loop through |
|
114 | - foreach ( $stats as $stat ) { |
|
115 | - $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
116 | - $row = array_map( 'maybe_serialize', $row ); |
|
117 | - fputcsv( $stream, $row ); |
|
118 | - } |
|
119 | - |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Downloads graph as json |
|
124 | - * |
|
125 | - * @param array $stats The stats being downloaded. |
|
126 | - * @param resource $stream The stream to output to. |
|
127 | - * @param array $headers The fields to stream. |
|
128 | - * @since 1.0.19 |
|
129 | - */ |
|
130 | - public function download_json( $stats, $stream, $headers ) { |
|
131 | - |
|
132 | - $prepared = array(); |
|
133 | - |
|
134 | - // Loop through |
|
135 | - foreach ( $stats as $stat ) { |
|
136 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
137 | - } |
|
138 | - |
|
139 | - fwrite( $stream, wp_json_encode( $prepared ) ); |
|
140 | - |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Downloads graph as xml |
|
145 | - * |
|
146 | - * @param array $stats The stats being downloaded. |
|
147 | - * @param resource $stream The stream to output to. |
|
148 | - * @param array $headers The fields to stream. |
|
149 | - * @since 1.0.19 |
|
150 | - */ |
|
151 | - public function download_xml( $stats, $stream, $headers ) { |
|
152 | - |
|
153 | - $prepared = array(); |
|
154 | - |
|
155 | - // Loop through |
|
156 | - foreach ( $stats as $stat ) { |
|
157 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
158 | - } |
|
159 | - |
|
160 | - $xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' ); |
|
161 | - $this->convert_array_xml( $prepared, $xml ); |
|
162 | - |
|
163 | - fwrite( $stream, $xml->asXML() ); |
|
164 | - |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Converts stats array to xml |
|
169 | - * |
|
170 | - * @access public |
|
171 | - * @since 1.0.19 |
|
172 | - */ |
|
173 | - public function convert_array_xml( $data, $xml ) { |
|
174 | - |
|
175 | - // Loop through |
|
176 | - foreach ( $data as $key => $value ) { |
|
177 | - |
|
178 | - $key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key ); |
|
179 | - |
|
180 | - if ( is_array( $value ) ) { |
|
181 | - |
|
182 | - if ( is_numeric( $key ) ) { |
|
183 | - $key = 'item' . $key; //dealing with <0/>..<n/> issues |
|
184 | - } |
|
185 | - |
|
186 | - $subnode = $xml->addChild( $key ); |
|
187 | - $this->convert_array_xml( $value, $subnode ); |
|
188 | - |
|
189 | - } else { |
|
190 | - $xml->addChild( $key, htmlspecialchars( $value ) ); |
|
191 | - } |
|
15 | + /** |
|
16 | + * @var GetPaid_Reports_Report |
|
17 | + */ |
|
18 | + public $handler; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + */ |
|
24 | + public function __construct() { |
|
25 | + $this->handler = new GetPaid_Reports_Report(); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Prepares the datastore handler. |
|
30 | + * |
|
31 | + * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
|
32 | + */ |
|
33 | + public function prepare_handler( $graph ) { |
|
34 | + |
|
35 | + if ( empty( $this->handler->views[ $graph ] ) ) { |
|
36 | + wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 ); |
|
37 | + } |
|
38 | + |
|
39 | + return new $this->handler->views[ $graph ]['class'](); |
|
40 | + |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Prepares the output stream. |
|
45 | + * |
|
46 | + * @return resource |
|
47 | + */ |
|
48 | + public function prepare_output() { |
|
49 | + |
|
50 | + $output = fopen( 'php://output', 'w' ); |
|
51 | + |
|
52 | + if ( false === $output ) { |
|
53 | + wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
54 | + } |
|
55 | + |
|
56 | + return $output; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Prepares the file type. |
|
61 | + * |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public function prepare_file_type( $graph ) { |
|
65 | + |
|
66 | + $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
67 | + $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
68 | + |
|
69 | + header( "Content-Type:application/$file_type" ); |
|
70 | + header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
71 | + |
|
72 | + return $file_type; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Handles the actual download. |
|
77 | + * |
|
78 | + */ |
|
79 | + public function download( $graph ) { |
|
80 | + global $wpdb; |
|
81 | + |
|
82 | + $handler = $this->prepare_handler( $graph ); |
|
83 | + $stream = $this->prepare_output(); |
|
84 | + $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
85 | + $headers = array( $handler->field, 'total', 'total_raw' ); |
|
86 | + $file_type = $this->prepare_file_type( $graph ); |
|
87 | + |
|
88 | + if ( 'csv' == $file_type ) { |
|
89 | + $this->download_csv( $stats, $stream, $headers ); |
|
90 | + } elseif ( 'xml' == $file_type ) { |
|
91 | + $this->download_xml( $stats, $stream, $headers ); |
|
92 | + } else { |
|
93 | + $this->download_json( $stats, $stream, $headers ); |
|
94 | + } |
|
95 | + |
|
96 | + fclose( $stream ); |
|
97 | + exit; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Downloads graph as csv |
|
102 | + * |
|
103 | + * @param array $stats The stats being downloaded. |
|
104 | + * @param resource $stream The stream to output to. |
|
105 | + * @param array $headers The fields to stream. |
|
106 | + * @since 1.0.19 |
|
107 | + */ |
|
108 | + public function download_csv( $stats, $stream, $headers ) { |
|
109 | + |
|
110 | + // Output the csv column headers. |
|
111 | + fputcsv( $stream, $headers ); |
|
112 | + |
|
113 | + // Loop through |
|
114 | + foreach ( $stats as $stat ) { |
|
115 | + $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
116 | + $row = array_map( 'maybe_serialize', $row ); |
|
117 | + fputcsv( $stream, $row ); |
|
118 | + } |
|
119 | + |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Downloads graph as json |
|
124 | + * |
|
125 | + * @param array $stats The stats being downloaded. |
|
126 | + * @param resource $stream The stream to output to. |
|
127 | + * @param array $headers The fields to stream. |
|
128 | + * @since 1.0.19 |
|
129 | + */ |
|
130 | + public function download_json( $stats, $stream, $headers ) { |
|
131 | + |
|
132 | + $prepared = array(); |
|
133 | + |
|
134 | + // Loop through |
|
135 | + foreach ( $stats as $stat ) { |
|
136 | + $prepared[] = $this->prepare_row( $stat, $headers ); |
|
137 | + } |
|
138 | + |
|
139 | + fwrite( $stream, wp_json_encode( $prepared ) ); |
|
140 | + |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Downloads graph as xml |
|
145 | + * |
|
146 | + * @param array $stats The stats being downloaded. |
|
147 | + * @param resource $stream The stream to output to. |
|
148 | + * @param array $headers The fields to stream. |
|
149 | + * @since 1.0.19 |
|
150 | + */ |
|
151 | + public function download_xml( $stats, $stream, $headers ) { |
|
152 | + |
|
153 | + $prepared = array(); |
|
154 | + |
|
155 | + // Loop through |
|
156 | + foreach ( $stats as $stat ) { |
|
157 | + $prepared[] = $this->prepare_row( $stat, $headers ); |
|
158 | + } |
|
159 | + |
|
160 | + $xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' ); |
|
161 | + $this->convert_array_xml( $prepared, $xml ); |
|
162 | + |
|
163 | + fwrite( $stream, $xml->asXML() ); |
|
164 | + |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Converts stats array to xml |
|
169 | + * |
|
170 | + * @access public |
|
171 | + * @since 1.0.19 |
|
172 | + */ |
|
173 | + public function convert_array_xml( $data, $xml ) { |
|
174 | + |
|
175 | + // Loop through |
|
176 | + foreach ( $data as $key => $value ) { |
|
177 | + |
|
178 | + $key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key ); |
|
179 | + |
|
180 | + if ( is_array( $value ) ) { |
|
181 | + |
|
182 | + if ( is_numeric( $key ) ) { |
|
183 | + $key = 'item' . $key; //dealing with <0/>..<n/> issues |
|
184 | + } |
|
185 | + |
|
186 | + $subnode = $xml->addChild( $key ); |
|
187 | + $this->convert_array_xml( $value, $subnode ); |
|
188 | + |
|
189 | + } else { |
|
190 | + $xml->addChild( $key, htmlspecialchars( $value ) ); |
|
191 | + } |
|
192 | 192 | } |
193 | 193 | |
194 | - } |
|
194 | + } |
|
195 | 195 | |
196 | - /** |
|
197 | - * Prepares a single row for download. |
|
198 | - * |
|
199 | - * @param stdClass|array $row The row to prepare.. |
|
200 | - * @param array $fields The fields to stream. |
|
201 | - * @since 1.0.19 |
|
202 | - * @return array |
|
203 | - */ |
|
204 | - public function prepare_row( $row, $fields ) { |
|
196 | + /** |
|
197 | + * Prepares a single row for download. |
|
198 | + * |
|
199 | + * @param stdClass|array $row The row to prepare.. |
|
200 | + * @param array $fields The fields to stream. |
|
201 | + * @since 1.0.19 |
|
202 | + * @return array |
|
203 | + */ |
|
204 | + public function prepare_row( $row, $fields ) { |
|
205 | 205 | |
206 | - $prepared = array(); |
|
207 | - $row = (array) $row; |
|
206 | + $prepared = array(); |
|
207 | + $row = (array) $row; |
|
208 | 208 | |
209 | - foreach ( $fields as $field ) { |
|
209 | + foreach ( $fields as $field ) { |
|
210 | 210 | |
211 | - if ( $field === 'total' ) { |
|
212 | - $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
213 | - continue; |
|
214 | - } |
|
211 | + if ( $field === 'total' ) { |
|
212 | + $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
213 | + continue; |
|
214 | + } |
|
215 | 215 | |
216 | - if ( $field === 'total_raw' ) { |
|
217 | - $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
218 | - continue; |
|
219 | - } |
|
216 | + if ( $field === 'total_raw' ) { |
|
217 | + $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
218 | + continue; |
|
219 | + } |
|
220 | 220 | |
221 | - $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
221 | + $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
222 | 222 | |
223 | - } |
|
223 | + } |
|
224 | 224 | |
225 | - return $prepared; |
|
226 | - } |
|
225 | + return $prepared; |
|
226 | + } |
|
227 | 227 | |
228 | 228 | |
229 | 229 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Graph_Downloader Class. |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
32 | 32 | */ |
33 | - public function prepare_handler( $graph ) { |
|
33 | + public function prepare_handler($graph) { |
|
34 | 34 | |
35 | - if ( empty( $this->handler->views[ $graph ] ) ) { |
|
36 | - wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 ); |
|
35 | + if (empty($this->handler->views[$graph])) { |
|
36 | + wp_die(esc_html__('Invalid Graph', 'invoicing'), 400); |
|
37 | 37 | } |
38 | 38 | |
39 | - return new $this->handler->views[ $graph ]['class'](); |
|
39 | + return new $this->handler->views[$graph]['class'](); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | |
@@ -47,10 +47,10 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function prepare_output() { |
49 | 49 | |
50 | - $output = fopen( 'php://output', 'w' ); |
|
50 | + $output = fopen('php://output', 'w'); |
|
51 | 51 | |
52 | - if ( false === $output ) { |
|
53 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
52 | + if (false === $output) { |
|
53 | + wp_die(esc_html__('Unsupported server', 'invoicing'), 500); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | return $output; |
@@ -61,13 +61,13 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return string |
63 | 63 | */ |
64 | - public function prepare_file_type( $graph ) { |
|
64 | + public function prepare_file_type($graph) { |
|
65 | 65 | |
66 | - $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
67 | - $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
66 | + $file_type = empty($_REQUEST['file_type']) ? 'csv' : sanitize_text_field($_REQUEST['file_type']); |
|
67 | + $file_name = wpinv_sanitize_key("getpaid-$graph-" . current_time('Y-m-d')); |
|
68 | 68 | |
69 | - header( "Content-Type:application/$file_type" ); |
|
70 | - header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
69 | + header("Content-Type:application/$file_type"); |
|
70 | + header("Content-Disposition:attachment;filename=$file_name.$file_type"); |
|
71 | 71 | |
72 | 72 | return $file_type; |
73 | 73 | } |
@@ -76,24 +76,24 @@ discard block |
||
76 | 76 | * Handles the actual download. |
77 | 77 | * |
78 | 78 | */ |
79 | - public function download( $graph ) { |
|
79 | + public function download($graph) { |
|
80 | 80 | global $wpdb; |
81 | 81 | |
82 | - $handler = $this->prepare_handler( $graph ); |
|
82 | + $handler = $this->prepare_handler($graph); |
|
83 | 83 | $stream = $this->prepare_output(); |
84 | - $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
85 | - $headers = array( $handler->field, 'total', 'total_raw' ); |
|
86 | - $file_type = $this->prepare_file_type( $graph ); |
|
87 | - |
|
88 | - if ( 'csv' == $file_type ) { |
|
89 | - $this->download_csv( $stats, $stream, $headers ); |
|
90 | - } elseif ( 'xml' == $file_type ) { |
|
91 | - $this->download_xml( $stats, $stream, $headers ); |
|
84 | + $stats = $wpdb->get_results($handler->get_sql($handler->get_range())); |
|
85 | + $headers = array($handler->field, 'total', 'total_raw'); |
|
86 | + $file_type = $this->prepare_file_type($graph); |
|
87 | + |
|
88 | + if ('csv' == $file_type) { |
|
89 | + $this->download_csv($stats, $stream, $headers); |
|
90 | + } elseif ('xml' == $file_type) { |
|
91 | + $this->download_xml($stats, $stream, $headers); |
|
92 | 92 | } else { |
93 | - $this->download_json( $stats, $stream, $headers ); |
|
93 | + $this->download_json($stats, $stream, $headers); |
|
94 | 94 | } |
95 | 95 | |
96 | - fclose( $stream ); |
|
96 | + fclose($stream); |
|
97 | 97 | exit; |
98 | 98 | } |
99 | 99 | |
@@ -105,16 +105,16 @@ discard block |
||
105 | 105 | * @param array $headers The fields to stream. |
106 | 106 | * @since 1.0.19 |
107 | 107 | */ |
108 | - public function download_csv( $stats, $stream, $headers ) { |
|
108 | + public function download_csv($stats, $stream, $headers) { |
|
109 | 109 | |
110 | 110 | // Output the csv column headers. |
111 | - fputcsv( $stream, $headers ); |
|
111 | + fputcsv($stream, $headers); |
|
112 | 112 | |
113 | 113 | // Loop through |
114 | - foreach ( $stats as $stat ) { |
|
115 | - $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
116 | - $row = array_map( 'maybe_serialize', $row ); |
|
117 | - fputcsv( $stream, $row ); |
|
114 | + foreach ($stats as $stat) { |
|
115 | + $row = array_values($this->prepare_row($stat, $headers)); |
|
116 | + $row = array_map('maybe_serialize', $row); |
|
117 | + fputcsv($stream, $row); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | } |
@@ -127,16 +127,16 @@ discard block |
||
127 | 127 | * @param array $headers The fields to stream. |
128 | 128 | * @since 1.0.19 |
129 | 129 | */ |
130 | - public function download_json( $stats, $stream, $headers ) { |
|
130 | + public function download_json($stats, $stream, $headers) { |
|
131 | 131 | |
132 | 132 | $prepared = array(); |
133 | 133 | |
134 | 134 | // Loop through |
135 | - foreach ( $stats as $stat ) { |
|
136 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
135 | + foreach ($stats as $stat) { |
|
136 | + $prepared[] = $this->prepare_row($stat, $headers); |
|
137 | 137 | } |
138 | 138 | |
139 | - fwrite( $stream, wp_json_encode( $prepared ) ); |
|
139 | + fwrite($stream, wp_json_encode($prepared)); |
|
140 | 140 | |
141 | 141 | } |
142 | 142 | |
@@ -148,19 +148,19 @@ discard block |
||
148 | 148 | * @param array $headers The fields to stream. |
149 | 149 | * @since 1.0.19 |
150 | 150 | */ |
151 | - public function download_xml( $stats, $stream, $headers ) { |
|
151 | + public function download_xml($stats, $stream, $headers) { |
|
152 | 152 | |
153 | 153 | $prepared = array(); |
154 | 154 | |
155 | 155 | // Loop through |
156 | - foreach ( $stats as $stat ) { |
|
157 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
156 | + foreach ($stats as $stat) { |
|
157 | + $prepared[] = $this->prepare_row($stat, $headers); |
|
158 | 158 | } |
159 | 159 | |
160 | - $xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' ); |
|
161 | - $this->convert_array_xml( $prepared, $xml ); |
|
160 | + $xml = new SimpleXMLElement('<?xml version="1.0"?><data></data>'); |
|
161 | + $this->convert_array_xml($prepared, $xml); |
|
162 | 162 | |
163 | - fwrite( $stream, $xml->asXML() ); |
|
163 | + fwrite($stream, $xml->asXML()); |
|
164 | 164 | |
165 | 165 | } |
166 | 166 | |
@@ -170,24 +170,24 @@ discard block |
||
170 | 170 | * @access public |
171 | 171 | * @since 1.0.19 |
172 | 172 | */ |
173 | - public function convert_array_xml( $data, $xml ) { |
|
173 | + public function convert_array_xml($data, $xml) { |
|
174 | 174 | |
175 | 175 | // Loop through |
176 | - foreach ( $data as $key => $value ) { |
|
176 | + foreach ($data as $key => $value) { |
|
177 | 177 | |
178 | - $key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key ); |
|
178 | + $key = preg_replace('/[^A-Za-z0-9_\-]/', '', $key); |
|
179 | 179 | |
180 | - if ( is_array( $value ) ) { |
|
180 | + if (is_array($value)) { |
|
181 | 181 | |
182 | - if ( is_numeric( $key ) ) { |
|
182 | + if (is_numeric($key)) { |
|
183 | 183 | $key = 'item' . $key; //dealing with <0/>..<n/> issues |
184 | 184 | } |
185 | 185 | |
186 | - $subnode = $xml->addChild( $key ); |
|
187 | - $this->convert_array_xml( $value, $subnode ); |
|
186 | + $subnode = $xml->addChild($key); |
|
187 | + $this->convert_array_xml($value, $subnode); |
|
188 | 188 | |
189 | 189 | } else { |
190 | - $xml->addChild( $key, htmlspecialchars( $value ) ); |
|
190 | + $xml->addChild($key, htmlspecialchars($value)); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -201,24 +201,24 @@ discard block |
||
201 | 201 | * @since 1.0.19 |
202 | 202 | * @return array |
203 | 203 | */ |
204 | - public function prepare_row( $row, $fields ) { |
|
204 | + public function prepare_row($row, $fields) { |
|
205 | 205 | |
206 | 206 | $prepared = array(); |
207 | 207 | $row = (array) $row; |
208 | 208 | |
209 | - foreach ( $fields as $field ) { |
|
209 | + foreach ($fields as $field) { |
|
210 | 210 | |
211 | - if ( $field === 'total' ) { |
|
212 | - $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
211 | + if ($field === 'total') { |
|
212 | + $prepared[$field] = html_entity_decode(strip_tags(wpinv_price($row['total'])), ENT_QUOTES); |
|
213 | 213 | continue; |
214 | 214 | } |
215 | 215 | |
216 | - if ( $field === 'total_raw' ) { |
|
217 | - $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
216 | + if ($field === 'total_raw') { |
|
217 | + $prepared[$field] = wpinv_round_amount(wpinv_sanitize_amount($row['total'])); |
|
218 | 218 | continue; |
219 | 219 | } |
220 | 220 | |
221 | - $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
221 | + $prepared[$field] = strip_tags($row[$field]); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 |