@@ -7,105 +7,105 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | -if ( !is_admin() ) { |
|
15 | - add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
16 | - add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' ); |
|
17 | - add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' ); |
|
18 | - add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' ); |
|
14 | +if (!is_admin()) { |
|
15 | + add_filter('template_include', 'wpinv_template', 10, 1); |
|
16 | + add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar'); |
|
17 | + add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions'); |
|
18 | + add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions'); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | function wpinv_template_path() { |
22 | - return apply_filters( 'wpinv_template_path', 'invoicing/' ); |
|
22 | + return apply_filters('wpinv_template_path', 'invoicing/'); |
|
23 | 23 | } |
24 | 24 | |
25 | -function wpinv_post_class( $classes, $class, $post_id ) { |
|
25 | +function wpinv_post_class($classes, $class, $post_id) { |
|
26 | 26 | global $pagenow, $typenow; |
27 | 27 | |
28 | - if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' ) { |
|
28 | + if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow && get_post_meta($post_id, '_wpinv_type', true) == 'package') { |
|
29 | 29 | $classes[] = 'wpi-gd-package'; |
30 | 30 | } |
31 | 31 | return $classes; |
32 | 32 | } |
33 | -add_filter( 'post_class', 'wpinv_post_class', 10, 3 ); |
|
33 | +add_filter('post_class', 'wpinv_post_class', 10, 3); |
|
34 | 34 | |
35 | -function wpinv_display_invoice_top_bar( $invoice ) { |
|
36 | - if ( empty( $invoice ) ) { |
|
35 | +function wpinv_display_invoice_top_bar($invoice) { |
|
36 | + if (empty($invoice)) { |
|
37 | 37 | return; |
38 | 38 | } |
39 | 39 | ?> |
40 | 40 | <div class="row wpinv-top-bar no-print"> |
41 | 41 | <div class="container"> |
42 | 42 | <div class="col-xs-6"> |
43 | - <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?> |
|
43 | + <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?> |
|
44 | 44 | </div> |
45 | 45 | <div class="col-xs-6 text-right"> |
46 | - <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?> |
|
46 | + <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?> |
|
47 | 47 | </div> |
48 | 48 | </div> |
49 | 49 | </div> |
50 | 50 | <?php |
51 | 51 | } |
52 | 52 | |
53 | -function wpinv_invoice_display_left_actions( $invoice ) { |
|
54 | - if ( empty( $invoice ) ) { |
|
53 | +function wpinv_invoice_display_left_actions($invoice) { |
|
54 | + if (empty($invoice)) { |
|
55 | 55 | return; |
56 | 56 | } |
57 | 57 | |
58 | 58 | $user_id = (int)$invoice->get_user_id(); |
59 | 59 | $current_user_id = (int)get_current_user_id(); |
60 | 60 | |
61 | - if ( $user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment() ) { |
|
61 | + if ($user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment()) { |
|
62 | 62 | ?> |
63 | - <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a> |
|
63 | + <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a> |
|
64 | 64 | <?php |
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | -function wpinv_invoice_display_right_actions( $invoice ) { |
|
69 | - if ( empty( $invoice ) ) { |
|
68 | +function wpinv_invoice_display_right_actions($invoice) { |
|
69 | + if (empty($invoice)) { |
|
70 | 70 | return; |
71 | 71 | } |
72 | 72 | |
73 | 73 | $user_id = (int)$invoice->get_user_id(); |
74 | 74 | $current_user_id = (int)get_current_user_id(); |
75 | 75 | |
76 | - if ( $user_id > 0 && $user_id == $current_user_id ) { |
|
76 | + if ($user_id > 0 && $user_id == $current_user_id) { |
|
77 | 77 | ?> |
78 | - <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a> |
|
79 | - <a class="btn btn-warning btn-sm" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a> |
|
78 | + <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a> |
|
79 | + <a class="btn btn-warning btn-sm" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a> |
|
80 | 80 | <?php } ?> |
81 | 81 | <?php |
82 | 82 | } |
83 | 83 | |
84 | -function wpinv_before_invoice_content( $content ) { |
|
84 | +function wpinv_before_invoice_content($content) { |
|
85 | 85 | global $post; |
86 | 86 | |
87 | - if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
87 | + if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
88 | 88 | ob_start(); |
89 | - do_action( 'wpinv_before_invoice_content', $post->ID ); |
|
89 | + do_action('wpinv_before_invoice_content', $post->ID); |
|
90 | 90 | $content = ob_get_clean() . $content; |
91 | 91 | } |
92 | 92 | |
93 | 93 | return $content; |
94 | 94 | } |
95 | -add_filter( 'the_content', 'wpinv_before_invoice_content' ); |
|
95 | +add_filter('the_content', 'wpinv_before_invoice_content'); |
|
96 | 96 | |
97 | -function wpinv_after_invoice_content( $content ) { |
|
97 | +function wpinv_after_invoice_content($content) { |
|
98 | 98 | global $post; |
99 | 99 | |
100 | - if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
100 | + if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
101 | 101 | ob_start(); |
102 | - do_action( 'wpinv_after_invoice_content', $post->ID ); |
|
102 | + do_action('wpinv_after_invoice_content', $post->ID); |
|
103 | 103 | $content .= ob_get_clean(); |
104 | 104 | } |
105 | 105 | |
106 | 106 | return $content; |
107 | 107 | } |
108 | -add_filter( 'the_content', 'wpinv_after_invoice_content' ); |
|
108 | +add_filter('the_content', 'wpinv_after_invoice_content'); |
|
109 | 109 | |
110 | 110 | function wpinv_get_templates_dir() { |
111 | 111 | return WPINV_PLUGIN_DIR . 'templates'; |
@@ -115,105 +115,105 @@ discard block |
||
115 | 115 | return WPINV_PLUGIN_URL . 'templates'; |
116 | 116 | } |
117 | 117 | |
118 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
119 | - if ( ! empty( $args ) && is_array( $args ) ) { |
|
120 | - extract( $args ); |
|
118 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
119 | + if (!empty($args) && is_array($args)) { |
|
120 | + extract($args); |
|
121 | 121 | } |
122 | 122 | |
123 | - $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
124 | - if ( ! file_exists( $located ) ) { |
|
125 | - _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' ); |
|
123 | + $located = wpinv_locate_template($template_name, $template_path, $default_path); |
|
124 | + if (!file_exists($located)) { |
|
125 | + _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1'); |
|
126 | 126 | return; |
127 | 127 | } |
128 | 128 | |
129 | 129 | // Allow 3rd party plugin filter template file from their plugin. |
130 | - $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path ); |
|
130 | + $located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path); |
|
131 | 131 | |
132 | - do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args ); |
|
132 | + do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args); |
|
133 | 133 | |
134 | - include( $located ); |
|
134 | + include($located); |
|
135 | 135 | |
136 | - do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
|
136 | + do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args); |
|
137 | 137 | } |
138 | 138 | |
139 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
139 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
140 | 140 | ob_start(); |
141 | - wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
|
141 | + wpinv_get_template($template_name, $args, $template_path, $default_path); |
|
142 | 142 | return ob_get_clean(); |
143 | 143 | } |
144 | 144 | |
145 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
146 | - if ( ! $template_path ) { |
|
145 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
146 | + if (!$template_path) { |
|
147 | 147 | $template_path = wpinv_template_path(); |
148 | 148 | } |
149 | 149 | |
150 | - if ( ! $default_path ) { |
|
150 | + if (!$default_path) { |
|
151 | 151 | $default_path = WPINV_PLUGIN_DIR . 'templates/'; |
152 | 152 | } |
153 | 153 | |
154 | 154 | // Look within passed path within the theme - this is priority. |
155 | 155 | $template = locate_template( |
156 | 156 | array( |
157 | - trailingslashit( $template_path ) . $template_name, |
|
157 | + trailingslashit($template_path) . $template_name, |
|
158 | 158 | $template_name |
159 | 159 | ) |
160 | 160 | ); |
161 | 161 | |
162 | 162 | // Get default templates/ |
163 | - if ( !$template && $default_path ) { |
|
164 | - $template = trailingslashit( $default_path ) . $template_name; |
|
163 | + if (!$template && $default_path) { |
|
164 | + $template = trailingslashit($default_path) . $template_name; |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | // Return what we found. |
168 | - return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path ); |
|
168 | + return apply_filters('wpinv_locate_template', $template, $template_name, $template_path); |
|
169 | 169 | } |
170 | 170 | |
171 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
172 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
171 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
172 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
173 | 173 | |
174 | 174 | // Setup possible parts |
175 | 175 | $templates = array(); |
176 | - if ( isset( $name ) ) |
|
176 | + if (isset($name)) |
|
177 | 177 | $templates[] = $slug . '-' . $name . '.php'; |
178 | 178 | $templates[] = $slug . '.php'; |
179 | 179 | |
180 | 180 | // Allow template parts to be filtered |
181 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
181 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
182 | 182 | |
183 | 183 | // Return the part that is found |
184 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
184 | + return wpinv_locate_tmpl($templates, $load, false); |
|
185 | 185 | } |
186 | 186 | |
187 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
187 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
188 | 188 | // No file found yet |
189 | 189 | $located = false; |
190 | 190 | |
191 | 191 | // Try to find a template file |
192 | - foreach ( (array)$template_names as $template_name ) { |
|
192 | + foreach ((array)$template_names as $template_name) { |
|
193 | 193 | |
194 | 194 | // Continue if template is empty |
195 | - if ( empty( $template_name ) ) |
|
195 | + if (empty($template_name)) |
|
196 | 196 | continue; |
197 | 197 | |
198 | 198 | // Trim off any slashes from the template name |
199 | - $template_name = ltrim( $template_name, '/' ); |
|
199 | + $template_name = ltrim($template_name, '/'); |
|
200 | 200 | |
201 | 201 | // try locating this template file by looping through the template paths |
202 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
202 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
203 | 203 | |
204 | - if( file_exists( $template_path . $template_name ) ) { |
|
204 | + if (file_exists($template_path . $template_name)) { |
|
205 | 205 | $located = $template_path . $template_name; |
206 | 206 | break; |
207 | 207 | } |
208 | 208 | } |
209 | 209 | |
210 | - if( !empty( $located ) ) { |
|
210 | + if (!empty($located)) { |
|
211 | 211 | break; |
212 | 212 | } |
213 | 213 | } |
214 | 214 | |
215 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
216 | - load_template( $located, $require_once ); |
|
215 | + if ((true == $load) && !empty($located)) |
|
216 | + load_template($located, $require_once); |
|
217 | 217 | |
218 | 218 | return $located; |
219 | 219 | } |
@@ -222,143 +222,143 @@ discard block |
||
222 | 222 | $template_dir = wpinv_get_theme_template_dir_name(); |
223 | 223 | |
224 | 224 | $file_paths = array( |
225 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
226 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
225 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
226 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
227 | 227 | 100 => wpinv_get_templates_dir() |
228 | 228 | ); |
229 | 229 | |
230 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
230 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
231 | 231 | |
232 | 232 | // sort the file paths based on priority |
233 | - ksort( $file_paths, SORT_NUMERIC ); |
|
233 | + ksort($file_paths, SORT_NUMERIC); |
|
234 | 234 | |
235 | - return array_map( 'trailingslashit', $file_paths ); |
|
235 | + return array_map('trailingslashit', $file_paths); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | function wpinv_get_theme_template_dir_name() { |
239 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'wpinv_templates' ) ); |
|
239 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'wpinv_templates')); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | function wpinv_checkout_meta_tags() { |
243 | 243 | |
244 | 244 | $pages = array(); |
245 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
246 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
247 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
245 | + $pages[] = wpinv_get_option('success_page'); |
|
246 | + $pages[] = wpinv_get_option('failure_page'); |
|
247 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
248 | 248 | |
249 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
249 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
250 | 250 | return; |
251 | 251 | } |
252 | 252 | |
253 | 253 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
254 | 254 | } |
255 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
255 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
256 | 256 | |
257 | -function wpinv_add_body_classes( $class ) { |
|
257 | +function wpinv_add_body_classes($class) { |
|
258 | 258 | $classes = (array)$class; |
259 | 259 | |
260 | - if( wpinv_is_checkout() ) { |
|
260 | + if (wpinv_is_checkout()) { |
|
261 | 261 | $classes[] = 'wpinv-checkout'; |
262 | 262 | $classes[] = 'wpinv-page'; |
263 | 263 | } |
264 | 264 | |
265 | - if( wpinv_is_success_page() ) { |
|
265 | + if (wpinv_is_success_page()) { |
|
266 | 266 | $classes[] = 'wpinv-success'; |
267 | 267 | $classes[] = 'wpinv-page'; |
268 | 268 | } |
269 | 269 | |
270 | - if( wpinv_is_failed_transaction_page() ) { |
|
270 | + if (wpinv_is_failed_transaction_page()) { |
|
271 | 271 | $classes[] = 'wpinv-failed-transaction'; |
272 | 272 | $classes[] = 'wpinv-page'; |
273 | 273 | } |
274 | 274 | |
275 | - if( wpinv_is_invoice_history_page() ) { |
|
275 | + if (wpinv_is_invoice_history_page()) { |
|
276 | 276 | $classes[] = 'wpinv-history'; |
277 | 277 | $classes[] = 'wpinv-page'; |
278 | 278 | } |
279 | 279 | |
280 | - if( wpinv_is_test_mode() ) { |
|
280 | + if (wpinv_is_test_mode()) { |
|
281 | 281 | $classes[] = 'wpinv-test-mode'; |
282 | 282 | $classes[] = 'wpinv-page'; |
283 | 283 | } |
284 | 284 | |
285 | - return array_unique( $classes ); |
|
285 | + return array_unique($classes); |
|
286 | 286 | } |
287 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
287 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
288 | 288 | |
289 | -function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) { |
|
290 | - $args = array( 'nopaging' => true ); |
|
289 | +function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') { |
|
290 | + $args = array('nopaging' => true); |
|
291 | 291 | |
292 | - if ( ! empty( $status ) ) |
|
292 | + if (!empty($status)) |
|
293 | 293 | $args['post_status'] = $status; |
294 | 294 | |
295 | - $discounts = wpinv_get_discounts( $args ); |
|
295 | + $discounts = wpinv_get_discounts($args); |
|
296 | 296 | $options = array(); |
297 | 297 | |
298 | - if ( $discounts ) { |
|
299 | - foreach ( $discounts as $discount ) { |
|
300 | - $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) ); |
|
298 | + if ($discounts) { |
|
299 | + foreach ($discounts as $discount) { |
|
300 | + $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID)); |
|
301 | 301 | } |
302 | 302 | } else { |
303 | - $options[0] = __( 'No discounts found', 'invoicing' ); |
|
303 | + $options[0] = __('No discounts found', 'invoicing'); |
|
304 | 304 | } |
305 | 305 | |
306 | - $output = wpinv_html_select( array( |
|
306 | + $output = wpinv_html_select(array( |
|
307 | 307 | 'name' => $name, |
308 | 308 | 'selected' => $selected, |
309 | 309 | 'options' => $options, |
310 | 310 | 'show_option_all' => false, |
311 | 311 | 'show_option_none' => false, |
312 | - ) ); |
|
312 | + )); |
|
313 | 313 | |
314 | 314 | return $output; |
315 | 315 | } |
316 | 316 | |
317 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
318 | - $current = date( 'Y' ); |
|
319 | - $start_year = $current - absint( $years_before ); |
|
320 | - $end_year = $current + absint( $years_after ); |
|
321 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
317 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
318 | + $current = date('Y'); |
|
319 | + $start_year = $current - absint($years_before); |
|
320 | + $end_year = $current + absint($years_after); |
|
321 | + $selected = empty($selected) ? date('Y') : $selected; |
|
322 | 322 | $options = array(); |
323 | 323 | |
324 | - while ( $start_year <= $end_year ) { |
|
325 | - $options[ absint( $start_year ) ] = $start_year; |
|
324 | + while ($start_year <= $end_year) { |
|
325 | + $options[absint($start_year)] = $start_year; |
|
326 | 326 | $start_year++; |
327 | 327 | } |
328 | 328 | |
329 | - $output = wpinv_html_select( array( |
|
329 | + $output = wpinv_html_select(array( |
|
330 | 330 | 'name' => $name, |
331 | 331 | 'selected' => $selected, |
332 | 332 | 'options' => $options, |
333 | 333 | 'show_option_all' => false, |
334 | 334 | 'show_option_none' => false |
335 | - ) ); |
|
335 | + )); |
|
336 | 336 | |
337 | 337 | return $output; |
338 | 338 | } |
339 | 339 | |
340 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
340 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
341 | 341 | $month = 1; |
342 | 342 | $options = array(); |
343 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
343 | + $selected = empty($selected) ? date('n') : $selected; |
|
344 | 344 | |
345 | - while ( $month <= 12 ) { |
|
346 | - $options[ absint( $month ) ] = wpinv_month_num_to_name( $month ); |
|
345 | + while ($month <= 12) { |
|
346 | + $options[absint($month)] = wpinv_month_num_to_name($month); |
|
347 | 347 | $month++; |
348 | 348 | } |
349 | 349 | |
350 | - $output = wpinv_html_select( array( |
|
350 | + $output = wpinv_html_select(array( |
|
351 | 351 | 'name' => $name, |
352 | 352 | 'selected' => $selected, |
353 | 353 | 'options' => $options, |
354 | 354 | 'show_option_all' => false, |
355 | 355 | 'show_option_none' => false |
356 | - ) ); |
|
356 | + )); |
|
357 | 357 | |
358 | 358 | return $output; |
359 | 359 | } |
360 | 360 | |
361 | -function wpinv_html_select( $args = array() ) { |
|
361 | +function wpinv_html_select($args = array()) { |
|
362 | 362 | $defaults = array( |
363 | 363 | 'options' => array(), |
364 | 364 | 'name' => null, |
@@ -368,8 +368,8 @@ discard block |
||
368 | 368 | 'chosen' => false, |
369 | 369 | 'placeholder' => null, |
370 | 370 | 'multiple' => false, |
371 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
372 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
371 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
372 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
373 | 373 | 'data' => array(), |
374 | 374 | 'onchange' => null, |
375 | 375 | 'required' => false, |
@@ -377,78 +377,78 @@ discard block |
||
377 | 377 | 'readonly' => false, |
378 | 378 | ); |
379 | 379 | |
380 | - $args = wp_parse_args( $args, $defaults ); |
|
380 | + $args = wp_parse_args($args, $defaults); |
|
381 | 381 | |
382 | 382 | $data_elements = ''; |
383 | - foreach ( $args['data'] as $key => $value ) { |
|
384 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
383 | + foreach ($args['data'] as $key => $value) { |
|
384 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
385 | 385 | } |
386 | 386 | |
387 | - if( $args['multiple'] ) { |
|
387 | + if ($args['multiple']) { |
|
388 | 388 | $multiple = ' MULTIPLE'; |
389 | 389 | } else { |
390 | 390 | $multiple = ''; |
391 | 391 | } |
392 | 392 | |
393 | - if( $args['chosen'] ) { |
|
393 | + if ($args['chosen']) { |
|
394 | 394 | $args['class'] .= ' wpinv-select-chosen'; |
395 | 395 | } |
396 | 396 | |
397 | - if( $args['placeholder'] ) { |
|
397 | + if ($args['placeholder']) { |
|
398 | 398 | $placeholder = $args['placeholder']; |
399 | 399 | } else { |
400 | 400 | $placeholder = ''; |
401 | 401 | } |
402 | 402 | |
403 | 403 | $options = ''; |
404 | - if( !empty( $args['onchange'] ) ) { |
|
405 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
404 | + if (!empty($args['onchange'])) { |
|
405 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
406 | 406 | } |
407 | 407 | |
408 | - if( !empty( $args['required'] ) ) { |
|
408 | + if (!empty($args['required'])) { |
|
409 | 409 | $options .= ' required="required"'; |
410 | 410 | } |
411 | 411 | |
412 | - if( !empty( $args['disabled'] ) ) { |
|
412 | + if (!empty($args['disabled'])) { |
|
413 | 413 | $options .= ' disabled'; |
414 | 414 | } |
415 | 415 | |
416 | - if( !empty( $args['readonly'] ) ) { |
|
416 | + if (!empty($args['readonly'])) { |
|
417 | 417 | $options .= ' readonly'; |
418 | 418 | } |
419 | 419 | |
420 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
421 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
420 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
421 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
422 | 422 | |
423 | - if ( $args['show_option_all'] ) { |
|
424 | - if( $args['multiple'] ) { |
|
425 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
423 | + if ($args['show_option_all']) { |
|
424 | + if ($args['multiple']) { |
|
425 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
426 | 426 | } else { |
427 | - $selected = selected( $args['selected'], 0, false ); |
|
427 | + $selected = selected($args['selected'], 0, false); |
|
428 | 428 | } |
429 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
429 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
430 | 430 | } |
431 | 431 | |
432 | - if ( !empty( $args['options'] ) ) { |
|
432 | + if (!empty($args['options'])) { |
|
433 | 433 | |
434 | - if ( $args['show_option_none'] ) { |
|
435 | - if( $args['multiple'] ) { |
|
436 | - $selected = selected( true, in_array( "", $args['selected'] ), false ); |
|
434 | + if ($args['show_option_none']) { |
|
435 | + if ($args['multiple']) { |
|
436 | + $selected = selected(true, in_array("", $args['selected']), false); |
|
437 | 437 | } else { |
438 | - $selected = selected( $args['selected'] === "", true, false ); |
|
438 | + $selected = selected($args['selected'] === "", true, false); |
|
439 | 439 | } |
440 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
440 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
441 | 441 | } |
442 | 442 | |
443 | - foreach( $args['options'] as $key => $option ) { |
|
443 | + foreach ($args['options'] as $key => $option) { |
|
444 | 444 | |
445 | - if( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
446 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
445 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
446 | + $selected = selected(true, (bool)in_array($key, $args['selected']), false); |
|
447 | 447 | } else { |
448 | - $selected = selected( $args['selected'], $key, false ); |
|
448 | + $selected = selected($args['selected'], $key, false); |
|
449 | 449 | } |
450 | 450 | |
451 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
451 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
452 | 452 | } |
453 | 453 | } |
454 | 454 | |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | return $output; |
458 | 458 | } |
459 | 459 | |
460 | -function wpinv_item_dropdown( $args = array() ) { |
|
460 | +function wpinv_item_dropdown($args = array()) { |
|
461 | 461 | $defaults = array( |
462 | 462 | 'name' => 'wpi_item', |
463 | 463 | 'id' => 'wpi_item', |
@@ -466,15 +466,15 @@ discard block |
||
466 | 466 | 'selected' => 0, |
467 | 467 | 'chosen' => false, |
468 | 468 | 'number' => 100, |
469 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
470 | - 'data' => array( 'search-type' => 'item' ), |
|
469 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
470 | + 'data' => array('search-type' => 'item'), |
|
471 | 471 | 'show_option_all' => false, |
472 | 472 | 'show_option_none' => false, |
473 | 473 | 'with_packages' => true, |
474 | 474 | 'show_recurring' => false, |
475 | 475 | ); |
476 | 476 | |
477 | - $args = wp_parse_args( $args, $defaults ); |
|
477 | + $args = wp_parse_args($args, $defaults); |
|
478 | 478 | |
479 | 479 | $item_args = array( |
480 | 480 | 'post_type' => 'wpi_item', |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | 'posts_per_page' => $args['number'] |
484 | 484 | ); |
485 | 485 | |
486 | - if ( !$args['with_packages'] ) { |
|
486 | + if (!$args['with_packages']) { |
|
487 | 487 | $item_args['meta_query'] = array( |
488 | 488 | array( |
489 | 489 | 'key' => '_wpinv_type', |
@@ -493,42 +493,42 @@ discard block |
||
493 | 493 | ); |
494 | 494 | } |
495 | 495 | |
496 | - $items = get_posts( $item_args ); |
|
496 | + $items = get_posts($item_args); |
|
497 | 497 | $options = array(); |
498 | - if ( $items ) { |
|
499 | - foreach ( $items as $item ) { |
|
500 | - $title = esc_html( $item->post_title ); |
|
498 | + if ($items) { |
|
499 | + foreach ($items as $item) { |
|
500 | + $title = esc_html($item->post_title); |
|
501 | 501 | |
502 | - if ( !empty( $args['show_recurring'] ) ) { |
|
503 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
502 | + if (!empty($args['show_recurring'])) { |
|
503 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
504 | 504 | } |
505 | 505 | |
506 | - $options[ absint( $item->ID ) ] = $title; |
|
506 | + $options[absint($item->ID)] = $title; |
|
507 | 507 | } |
508 | 508 | } |
509 | 509 | |
510 | 510 | // This ensures that any selected items are included in the drop down |
511 | - if( is_array( $args['selected'] ) ) { |
|
512 | - foreach( $args['selected'] as $item ) { |
|
513 | - if( ! in_array( $item, $options ) ) { |
|
514 | - $title = get_the_title( $item ); |
|
515 | - if ( !empty( $args['show_recurring'] ) ) { |
|
516 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
511 | + if (is_array($args['selected'])) { |
|
512 | + foreach ($args['selected'] as $item) { |
|
513 | + if (!in_array($item, $options)) { |
|
514 | + $title = get_the_title($item); |
|
515 | + if (!empty($args['show_recurring'])) { |
|
516 | + $title .= wpinv_get_item_suffix($item, false); |
|
517 | 517 | } |
518 | 518 | $options[$item] = $title; |
519 | 519 | } |
520 | 520 | } |
521 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
522 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
523 | - $title = get_the_title( $args['selected'] ); |
|
524 | - if ( !empty( $args['show_recurring'] ) ) { |
|
525 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
521 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
522 | + if (!in_array($args['selected'], $options)) { |
|
523 | + $title = get_the_title($args['selected']); |
|
524 | + if (!empty($args['show_recurring'])) { |
|
525 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
526 | 526 | } |
527 | - $options[$args['selected']] = get_the_title( $args['selected'] ); |
|
527 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
528 | 528 | } |
529 | 529 | } |
530 | 530 | |
531 | - $output = wpinv_html_select( array( |
|
531 | + $output = wpinv_html_select(array( |
|
532 | 532 | 'name' => $args['name'], |
533 | 533 | 'selected' => $args['selected'], |
534 | 534 | 'id' => $args['id'], |
@@ -540,12 +540,12 @@ discard block |
||
540 | 540 | 'show_option_all' => $args['show_option_all'], |
541 | 541 | 'show_option_none' => $args['show_option_none'], |
542 | 542 | 'data' => $args['data'], |
543 | - ) ); |
|
543 | + )); |
|
544 | 544 | |
545 | 545 | return $output; |
546 | 546 | } |
547 | 547 | |
548 | -function wpinv_html_checkbox( $args = array() ) { |
|
548 | +function wpinv_html_checkbox($args = array()) { |
|
549 | 549 | $defaults = array( |
550 | 550 | 'name' => null, |
551 | 551 | 'current' => null, |
@@ -556,38 +556,38 @@ discard block |
||
556 | 556 | ) |
557 | 557 | ); |
558 | 558 | |
559 | - $args = wp_parse_args( $args, $defaults ); |
|
559 | + $args = wp_parse_args($args, $defaults); |
|
560 | 560 | |
561 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
561 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
562 | 562 | $options = ''; |
563 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
563 | + if (!empty($args['options']['disabled'])) { |
|
564 | 564 | $options .= ' disabled="disabled"'; |
565 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
565 | + } elseif (!empty($args['options']['readonly'])) { |
|
566 | 566 | $options .= ' readonly'; |
567 | 567 | } |
568 | 568 | |
569 | - $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
569 | + $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
570 | 570 | |
571 | 571 | return $output; |
572 | 572 | } |
573 | 573 | |
574 | -function wpinv_html_text( $args = array() ) { |
|
574 | +function wpinv_html_text($args = array()) { |
|
575 | 575 | // Backwards compatibility |
576 | - if ( func_num_args() > 1 ) { |
|
576 | + if (func_num_args() > 1) { |
|
577 | 577 | $args = func_get_args(); |
578 | 578 | |
579 | 579 | $name = $args[0]; |
580 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
581 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
582 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
580 | + $value = isset($args[1]) ? $args[1] : ''; |
|
581 | + $label = isset($args[2]) ? $args[2] : ''; |
|
582 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
583 | 583 | } |
584 | 584 | |
585 | 585 | $defaults = array( |
586 | 586 | 'id' => '', |
587 | - 'name' => isset( $name ) ? $name : 'text', |
|
588 | - 'value' => isset( $value ) ? $value : null, |
|
589 | - 'label' => isset( $label ) ? $label : null, |
|
590 | - 'desc' => isset( $desc ) ? $desc : null, |
|
587 | + 'name' => isset($name) ? $name : 'text', |
|
588 | + 'value' => isset($value) ? $value : null, |
|
589 | + 'label' => isset($label) ? $label : null, |
|
590 | + 'desc' => isset($desc) ? $desc : null, |
|
591 | 591 | 'placeholder' => '', |
592 | 592 | 'class' => 'regular-text', |
593 | 593 | 'disabled' => false, |
@@ -597,51 +597,51 @@ discard block |
||
597 | 597 | 'data' => false |
598 | 598 | ); |
599 | 599 | |
600 | - $args = wp_parse_args( $args, $defaults ); |
|
600 | + $args = wp_parse_args($args, $defaults); |
|
601 | 601 | |
602 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
602 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
603 | 603 | $options = ''; |
604 | - if( $args['required'] ) { |
|
604 | + if ($args['required']) { |
|
605 | 605 | $options .= ' required="required"'; |
606 | 606 | } |
607 | - if( $args['readonly'] ) { |
|
607 | + if ($args['readonly']) { |
|
608 | 608 | $options .= ' readonly'; |
609 | 609 | } |
610 | - if( $args['readonly'] ) { |
|
610 | + if ($args['readonly']) { |
|
611 | 611 | $options .= ' readonly'; |
612 | 612 | } |
613 | 613 | |
614 | 614 | $data = ''; |
615 | - if ( !empty( $args['data'] ) ) { |
|
616 | - foreach ( $args['data'] as $key => $value ) { |
|
617 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
615 | + if (!empty($args['data'])) { |
|
616 | + foreach ($args['data'] as $key => $value) { |
|
617 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
618 | 618 | } |
619 | 619 | } |
620 | 620 | |
621 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
622 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
623 | - if ( ! empty( $args['desc'] ) ) { |
|
624 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
621 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
622 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
623 | + if (!empty($args['desc'])) { |
|
624 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
625 | 625 | } |
626 | 626 | |
627 | - $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 ) . '/>'; |
|
627 | + $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) . '/>'; |
|
628 | 628 | |
629 | 629 | $output .= '</span>'; |
630 | 630 | |
631 | 631 | return $output; |
632 | 632 | } |
633 | 633 | |
634 | -function wpinv_html_date_field( $args = array() ) { |
|
635 | - if( empty( $args['class'] ) ) { |
|
634 | +function wpinv_html_date_field($args = array()) { |
|
635 | + if (empty($args['class'])) { |
|
636 | 636 | $args['class'] = 'wpiDatepicker'; |
637 | - } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) { |
|
637 | + } elseif (!strpos($args['class'], 'wpiDatepicker')) { |
|
638 | 638 | $args['class'] .= ' wpiDatepicker'; |
639 | 639 | } |
640 | 640 | |
641 | - return wpinv_html_text( $args ); |
|
641 | + return wpinv_html_text($args); |
|
642 | 642 | } |
643 | 643 | |
644 | -function wpinv_html_textarea( $args = array() ) { |
|
644 | +function wpinv_html_textarea($args = array()) { |
|
645 | 645 | $defaults = array( |
646 | 646 | 'name' => 'textarea', |
647 | 647 | 'value' => null, |
@@ -651,31 +651,31 @@ discard block |
||
651 | 651 | 'disabled' => false |
652 | 652 | ); |
653 | 653 | |
654 | - $args = wp_parse_args( $args, $defaults ); |
|
654 | + $args = wp_parse_args($args, $defaults); |
|
655 | 655 | |
656 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
656 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
657 | 657 | $disabled = ''; |
658 | - if( $args['disabled'] ) { |
|
658 | + if ($args['disabled']) { |
|
659 | 659 | $disabled = ' disabled="disabled"'; |
660 | 660 | } |
661 | 661 | |
662 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
663 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
664 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
662 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
663 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
664 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
665 | 665 | |
666 | - if ( ! empty( $args['desc'] ) ) { |
|
667 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
666 | + if (!empty($args['desc'])) { |
|
667 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
668 | 668 | } |
669 | 669 | $output .= '</span>'; |
670 | 670 | |
671 | 671 | return $output; |
672 | 672 | } |
673 | 673 | |
674 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
674 | +function wpinv_html_ajax_user_search($args = array()) { |
|
675 | 675 | $defaults = array( |
676 | 676 | 'name' => 'user_id', |
677 | 677 | 'value' => null, |
678 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
678 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
679 | 679 | 'label' => null, |
680 | 680 | 'desc' => null, |
681 | 681 | 'class' => '', |
@@ -684,13 +684,13 @@ discard block |
||
684 | 684 | 'data' => false |
685 | 685 | ); |
686 | 686 | |
687 | - $args = wp_parse_args( $args, $defaults ); |
|
687 | + $args = wp_parse_args($args, $defaults); |
|
688 | 688 | |
689 | 689 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
690 | 690 | |
691 | 691 | $output = '<span class="wpinv_user_search_wrap">'; |
692 | - $output .= wpinv_html_text( $args ); |
|
693 | - $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>'; |
|
692 | + $output .= wpinv_html_text($args); |
|
693 | + $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>'; |
|
694 | 694 | $output .= '</span>'; |
695 | 695 | |
696 | 696 | return $output; |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | function wpinv_ip_geolocation() { |
700 | 700 | global $wpinv_euvat; |
701 | 701 | |
702 | - $ip = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : ''; |
|
702 | + $ip = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : ''; |
|
703 | 703 | $content = ''; |
704 | 704 | $iso = ''; |
705 | 705 | $country = ''; |
@@ -710,69 +710,69 @@ discard block |
||
710 | 710 | $credit = ''; |
711 | 711 | $address = ''; |
712 | 712 | |
713 | - if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) { |
|
713 | + if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) { |
|
714 | 714 | try { |
715 | 715 | $iso = $geoip2_city->country->isoCode; |
716 | 716 | $country = $geoip2_city->country->name; |
717 | - $region = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : ''; |
|
717 | + $region = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : ''; |
|
718 | 718 | $city = $geoip2_city->city->name; |
719 | 719 | $longitude = $geoip2_city->location->longitude; |
720 | 720 | $latitude = $geoip2_city->location->latitude; |
721 | - $credit = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' ); |
|
722 | - } catch( Exception $e ) { } |
|
721 | + $credit = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing'); |
|
722 | + } catch (Exception $e) { } |
|
723 | 723 | } |
724 | 724 | |
725 | - if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) { |
|
725 | + if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) { |
|
726 | 726 | try { |
727 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
727 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
728 | 728 | |
729 | - if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) { |
|
729 | + if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) { |
|
730 | 730 | $iso = $load_xml->geoplugin_countryCode; |
731 | 731 | $country = $load_xml->geoplugin_countryName; |
732 | - $region = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : ''; |
|
733 | - $city = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : ''; |
|
732 | + $region = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : ''; |
|
733 | + $city = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : ''; |
|
734 | 734 | $longitude = $load_xml->geoplugin_longitude; |
735 | 735 | $latitude = $load_xml->geoplugin_latitude; |
736 | 736 | $credit = $load_xml->geoplugin_credit; |
737 | - $credit = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit; |
|
737 | + $credit = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit; |
|
738 | 738 | } |
739 | - } catch( Exception $e ) { } |
|
739 | + } catch (Exception $e) { } |
|
740 | 740 | } |
741 | 741 | |
742 | - if ( $iso && $longitude && $latitude ) { |
|
743 | - if ( $city ) { |
|
742 | + if ($iso && $longitude && $latitude) { |
|
743 | + if ($city) { |
|
744 | 744 | $address .= $city . ', '; |
745 | 745 | } |
746 | 746 | |
747 | - if ( $region ) { |
|
747 | + if ($region) { |
|
748 | 748 | $address .= $region . ', '; |
749 | 749 | } |
750 | 750 | |
751 | 751 | $address .= $country . ' (' . $iso . ')'; |
752 | - $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>'; |
|
753 | - $content .= '<p>'. $credit . '</p>'; |
|
752 | + $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>'; |
|
753 | + $content .= '<p>' . $credit . '</p>'; |
|
754 | 754 | } else { |
755 | - $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>'; |
|
755 | + $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>'; |
|
756 | 756 | } |
757 | 757 | ?> |
758 | 758 | <!DOCTYPE html> |
759 | -<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head> |
|
759 | +<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head> |
|
760 | 760 | <body> |
761 | - <?php if ( $latitude && $latitude ) { ?> |
|
761 | + <?php if ($latitude && $latitude) { ?> |
|
762 | 762 | <div id="map"></div> |
763 | 763 | <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script> |
764 | 764 | <script type="text/javascript"> |
765 | 765 | var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', |
766 | 766 | osmAttrib = '© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors', |
767 | 767 | osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}), |
768 | - latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>); |
|
768 | + latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>); |
|
769 | 769 | |
770 | 770 | var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]}); |
771 | 771 | |
772 | 772 | var marker = new L.Marker(latlng); |
773 | 773 | map.addLayer(marker); |
774 | 774 | |
775 | - marker.bindPopup("<p><?php esc_attr_e( $address );?></p>"); |
|
775 | + marker.bindPopup("<p><?php esc_attr_e($address); ?></p>"); |
|
776 | 776 | </script> |
777 | 777 | <?php } ?> |
778 | 778 | <div style="height:100px"><?php echo $content; ?></div> |
@@ -780,31 +780,31 @@ discard block |
||
780 | 780 | <?php |
781 | 781 | exit; |
782 | 782 | } |
783 | -add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
784 | -add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
783 | +add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
784 | +add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
785 | 785 | |
786 | 786 | // Set up the template for the invoice. |
787 | -function wpinv_template( $template ) { |
|
787 | +function wpinv_template($template) { |
|
788 | 788 | global $post, $wp_query; |
789 | 789 | |
790 | - if ( ( is_single() || is_404() ) && !empty( $post->ID ) && get_post_type( $post->ID ) == 'wpi_invoice' ) { |
|
791 | - if ( wpinv_user_can_print_invoice( $post->ID ) ) { |
|
792 | - $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
790 | + if ((is_single() || is_404()) && !empty($post->ID) && get_post_type($post->ID) == 'wpi_invoice') { |
|
791 | + if (wpinv_user_can_print_invoice($post->ID)) { |
|
792 | + $template = wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
793 | 793 | } else { |
794 | - if ( !is_user_logged_in() && !empty( $_REQUEST['_wpipay'] ) && $invoice = wpinv_get_invoice( $post->ID ) ) { |
|
794 | + if (!is_user_logged_in() && !empty($_REQUEST['_wpipay']) && $invoice = wpinv_get_invoice($post->ID)) { |
|
795 | 795 | $user_id = $invoice->get_user_id(); |
796 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
796 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
797 | 797 | |
798 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key() ) ) { // valid invoice link |
|
799 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
798 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key())) { // valid invoice link |
|
799 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
800 | 800 | |
801 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
801 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
802 | 802 | wpinv_die(); |
803 | 803 | } |
804 | 804 | } |
805 | - $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
805 | + $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
806 | 806 | |
807 | - wp_redirect( $redirect_to ); |
|
807 | + wp_redirect($redirect_to); |
|
808 | 808 | wpinv_die(); |
809 | 809 | } |
810 | 810 | } |
@@ -814,7 +814,7 @@ discard block |
||
814 | 814 | |
815 | 815 | function wpinv_get_business_address() { |
816 | 816 | $business_address = wpinv_store_address(); |
817 | - $business_address = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
817 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
818 | 818 | |
819 | 819 | /* |
820 | 820 | $default_country = wpinv_get_default_country(); |
@@ -838,7 +838,7 @@ discard block |
||
838 | 838 | |
839 | 839 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
840 | 840 | |
841 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
841 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
842 | 842 | } |
843 | 843 | |
844 | 844 | function wpinv_display_from_address() { |
@@ -848,182 +848,182 @@ discard block |
||
848 | 848 | if (empty($from_name)) { |
849 | 849 | $from_name = wpinv_get_business_name(); |
850 | 850 | } |
851 | - ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div> |
|
851 | + ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div> |
|
852 | 852 | <div class="wrapper col-xs-10"> |
853 | - <div class="name"><?php echo esc_html( $from_name ); ?></div> |
|
854 | - <?php if ( $address = wpinv_get_business_address() ) { ?> |
|
855 | - <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div> |
|
853 | + <div class="name"><?php echo esc_html($from_name); ?></div> |
|
854 | + <?php if ($address = wpinv_get_business_address()) { ?> |
|
855 | + <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div> |
|
856 | 856 | <?php } ?> |
857 | - <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?> |
|
858 | - <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s' ), $email_from );?></div> |
|
857 | + <?php if ($email_from = wpinv_mail_get_from_address()) { ?> |
|
858 | + <div class="email_from"><?php echo wp_sprintf(__('Email: %s'), $email_from); ?></div> |
|
859 | 859 | <?php } ?> |
860 | 860 | </div> |
861 | 861 | <?php |
862 | 862 | } |
863 | 863 | |
864 | -function wpinv_watermark( $id = 0 ) { |
|
865 | - $output = wpinv_get_watermark( $id ); |
|
864 | +function wpinv_watermark($id = 0) { |
|
865 | + $output = wpinv_get_watermark($id); |
|
866 | 866 | |
867 | - return apply_filters( 'wpinv_get_watermark', $output, $id ); |
|
867 | + return apply_filters('wpinv_get_watermark', $output, $id); |
|
868 | 868 | } |
869 | 869 | |
870 | -function wpinv_get_watermark( $id ) { |
|
871 | - if ( !$id > 0 ) { |
|
870 | +function wpinv_get_watermark($id) { |
|
871 | + if (!$id > 0) { |
|
872 | 872 | return NULL; |
873 | 873 | } |
874 | - $invoice = wpinv_get_invoice( $id ); |
|
874 | + $invoice = wpinv_get_invoice($id); |
|
875 | 875 | |
876 | - if ( !empty( $invoice ) ) { |
|
877 | - if ( $invoice->is_paid() ) { |
|
878 | - return __( 'Paid', 'invoicing' ); |
|
876 | + if (!empty($invoice)) { |
|
877 | + if ($invoice->is_paid()) { |
|
878 | + return __('Paid', 'invoicing'); |
|
879 | 879 | } |
880 | - if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) { |
|
881 | - return __( 'Cancelled', 'invoicing' ); |
|
880 | + if ($invoice->has_status(array('wpi-cancelled'))) { |
|
881 | + return __('Cancelled', 'invoicing'); |
|
882 | 882 | } |
883 | 883 | } |
884 | 884 | |
885 | 885 | return NULL; |
886 | 886 | } |
887 | 887 | |
888 | -function wpinv_display_invoice_details( $invoice ) { |
|
888 | +function wpinv_display_invoice_details($invoice) { |
|
889 | 889 | global $wpinv_euvat; |
890 | 890 | |
891 | 891 | $invoice_id = $invoice->ID; |
892 | 892 | $vat_name = $wpinv_euvat->get_vat_name(); |
893 | 893 | $use_taxes = wpinv_use_taxes(); |
894 | 894 | |
895 | - $invoice_status = wpinv_get_invoice_status( $invoice_id ); |
|
895 | + $invoice_status = wpinv_get_invoice_status($invoice_id); |
|
896 | 896 | ?> |
897 | 897 | <table class="table table-bordered table-sm"> |
898 | - <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?> |
|
898 | + <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?> |
|
899 | 899 | <tr class="wpi-row-number"> |
900 | - <th><?php _e( 'Invoice Number', 'invoicing' ); ?></th> |
|
901 | - <td><?php echo esc_html( $invoice_number ); ?></td> |
|
900 | + <th><?php _e('Invoice Number', 'invoicing'); ?></th> |
|
901 | + <td><?php echo esc_html($invoice_number); ?></td> |
|
902 | 902 | </tr> |
903 | 903 | <?php } ?> |
904 | 904 | <tr class="wpi-row-status"> |
905 | - <th><?php _e( 'Invoice Status', 'invoicing' ); ?></th> |
|
906 | - <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td> |
|
905 | + <th><?php _e('Invoice Status', 'invoicing'); ?></th> |
|
906 | + <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td> |
|
907 | 907 | </tr> |
908 | - <?php if ( $invoice->is_renewal() ) { ?> |
|
908 | + <?php if ($invoice->is_renewal()) { ?> |
|
909 | 909 | <tr class="wpi-row-parent"> |
910 | - <th><?php _e( 'Parent Invoice', 'invoicing' ); ?></th> |
|
911 | - <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td> |
|
910 | + <th><?php _e('Parent Invoice', 'invoicing'); ?></th> |
|
911 | + <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td> |
|
912 | 912 | </tr> |
913 | 913 | <?php } ?> |
914 | 914 | <tr class="wpi-row-gateway"> |
915 | - <th><?php _e( 'Payment Method', 'invoicing' ); ?></th> |
|
916 | - <td><?php echo wpinv_get_payment_gateway_name( $invoice_id ); ?></td> |
|
915 | + <th><?php _e('Payment Method', 'invoicing'); ?></th> |
|
916 | + <td><?php echo wpinv_get_payment_gateway_name($invoice_id); ?></td> |
|
917 | 917 | </tr> |
918 | - <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?> |
|
918 | + <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?> |
|
919 | 919 | <tr class="wpi-row-date"> |
920 | - <th><?php _e( 'Invoice Date', 'invoicing' ); ?></th> |
|
920 | + <th><?php _e('Invoice Date', 'invoicing'); ?></th> |
|
921 | 921 | <td><?php echo $invoice_date; ?></td> |
922 | 922 | </tr> |
923 | 923 | <?php } ?> |
924 | - <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?> |
|
924 | + <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?> |
|
925 | 925 | <tr class="wpi-row-date"> |
926 | - <th><?php _e( 'Due Date', 'invoicing' ); ?></th> |
|
926 | + <th><?php _e('Due Date', 'invoicing'); ?></th> |
|
927 | 927 | <td><?php echo $due_date; ?></td> |
928 | 928 | </tr> |
929 | 929 | <?php } ?> |
930 | - <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?> |
|
930 | + <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?> |
|
931 | 931 | <tr class="wpi-row-ovatno"> |
932 | - <th><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></th> |
|
932 | + <th><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></th> |
|
933 | 933 | <td><?php echo $owner_vat_number; ?></td> |
934 | 934 | </tr> |
935 | 935 | <?php } ?> |
936 | - <?php if ( $use_taxes && $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) { ?> |
|
936 | + <?php if ($use_taxes && $user_vat_number = wpinv_get_invoice_vat_number($invoice_id)) { ?> |
|
937 | 937 | <tr class="wpi-row-uvatno"> |
938 | - <th><?php echo wp_sprintf( __( 'Your %s Number', 'invoicing' ), $vat_name ); ?></th> |
|
938 | + <th><?php echo wp_sprintf(__('Your %s Number', 'invoicing'), $vat_name); ?></th> |
|
939 | 939 | <td><?php echo $user_vat_number; ?></td> |
940 | 940 | </tr> |
941 | 941 | <?php } ?> |
942 | 942 | <tr class="table-active tr-total wpi-row-total"> |
943 | - <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th> |
|
944 | - <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td> |
|
943 | + <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th> |
|
944 | + <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td> |
|
945 | 945 | </tr> |
946 | 946 | </table> |
947 | 947 | <?php |
948 | 948 | } |
949 | 949 | |
950 | -function wpinv_display_to_address( $invoice_id = 0 ) { |
|
951 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
950 | +function wpinv_display_to_address($invoice_id = 0) { |
|
951 | + $invoice = wpinv_get_invoice($invoice_id); |
|
952 | 952 | |
953 | - if ( empty( $invoice ) ) { |
|
953 | + if (empty($invoice)) { |
|
954 | 954 | return NULL; |
955 | 955 | } |
956 | 956 | |
957 | 957 | $billing_details = $invoice->get_user_info(); |
958 | - $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>'; |
|
958 | + $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>'; |
|
959 | 959 | $output .= '<div class="wrapper col-xs-10">'; |
960 | 960 | |
961 | 961 | ob_start(); |
962 | - do_action( 'wpinv_display_to_address_top', $invoice ); |
|
962 | + do_action('wpinv_display_to_address_top', $invoice); |
|
963 | 963 | $output .= ob_get_clean(); |
964 | 964 | |
965 | - $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>'; |
|
966 | - if ( $company = $billing_details['company'] ) { |
|
967 | - $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>'; |
|
965 | + $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>'; |
|
966 | + if ($company = $billing_details['company']) { |
|
967 | + $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>'; |
|
968 | 968 | } |
969 | 969 | $address_row = ''; |
970 | - if ( $address = $billing_details['address'] ) { |
|
971 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
970 | + if ($address = $billing_details['address']) { |
|
971 | + $address_row .= wpautop(wp_kses_post($address)); |
|
972 | 972 | } |
973 | 973 | |
974 | 974 | $address_fields = array(); |
975 | - if ( !empty( $billing_details['city'] ) ) { |
|
975 | + if (!empty($billing_details['city'])) { |
|
976 | 976 | $address_fields[] = $billing_details['city']; |
977 | 977 | } |
978 | 978 | |
979 | - $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
980 | - if ( !empty( $billing_details['state'] ) ) { |
|
981 | - $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
979 | + $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : ''; |
|
980 | + if (!empty($billing_details['state'])) { |
|
981 | + $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country); |
|
982 | 982 | } |
983 | 983 | |
984 | - if ( !empty( $billing_country ) ) { |
|
985 | - $address_fields[] = wpinv_country_name( $billing_country ); |
|
984 | + if (!empty($billing_country)) { |
|
985 | + $address_fields[] = wpinv_country_name($billing_country); |
|
986 | 986 | } |
987 | 987 | |
988 | - if ( !empty( $address_fields ) ) { |
|
989 | - $address_fields = implode( ", ", $address_fields ); |
|
988 | + if (!empty($address_fields)) { |
|
989 | + $address_fields = implode(", ", $address_fields); |
|
990 | 990 | |
991 | - if ( !empty( $billing_details['zip'] ) ) { |
|
991 | + if (!empty($billing_details['zip'])) { |
|
992 | 992 | $address_fields .= ' ' . $billing_details['zip']; |
993 | 993 | } |
994 | 994 | |
995 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
995 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
996 | 996 | } |
997 | 997 | |
998 | - if ( $address_row ) { |
|
998 | + if ($address_row) { |
|
999 | 999 | $output .= '<div class="address">' . $address_row . '</div>'; |
1000 | 1000 | } |
1001 | 1001 | |
1002 | - if ( $phone = $invoice->get_phone() ) { |
|
1003 | - $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s' ), esc_html( $phone ) ) . '</div>'; |
|
1002 | + if ($phone = $invoice->get_phone()) { |
|
1003 | + $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s'), esc_html($phone)) . '</div>'; |
|
1004 | 1004 | } |
1005 | - if ( $email = $invoice->get_email() ) { |
|
1006 | - $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' ), esc_html( $email ) ) . '</div>'; |
|
1005 | + if ($email = $invoice->get_email()) { |
|
1006 | + $output .= '<div class="email">' . wp_sprintf(__('Email: %s'), esc_html($email)) . '</div>'; |
|
1007 | 1007 | } |
1008 | 1008 | |
1009 | 1009 | ob_start(); |
1010 | - do_action( 'wpinv_display_to_address_bottom', $invoice ); |
|
1010 | + do_action('wpinv_display_to_address_bottom', $invoice); |
|
1011 | 1011 | $output .= ob_get_clean(); |
1012 | 1012 | |
1013 | 1013 | $output .= '</div>'; |
1014 | - $output = apply_filters( 'wpinv_display_to_address', $output, $invoice ); |
|
1014 | + $output = apply_filters('wpinv_display_to_address', $output, $invoice); |
|
1015 | 1015 | |
1016 | 1016 | echo $output; |
1017 | 1017 | } |
1018 | 1018 | |
1019 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
1019 | +function wpinv_display_line_items($invoice_id = 0) { |
|
1020 | 1020 | global $wpinv_euvat, $ajax_cart_details; |
1021 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1021 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1022 | 1022 | $quantities_enabled = wpinv_item_quantities_enabled(); |
1023 | 1023 | $use_taxes = wpinv_use_taxes(); |
1024 | 1024 | $zero_tax = !(float)$invoice->get_tax() > 0 ? true : false; |
1025 | - $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' ); |
|
1026 | - $tax_title = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : ''; |
|
1025 | + $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing'); |
|
1026 | + $tax_title = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : ''; |
|
1027 | 1027 | |
1028 | 1028 | $cart_details = $invoice->get_cart_details(); |
1029 | 1029 | $ajax_cart_details = $cart_details; |
@@ -1032,68 +1032,68 @@ discard block |
||
1032 | 1032 | <table class="table table-sm table-bordered table-responsive"> |
1033 | 1033 | <thead> |
1034 | 1034 | <tr> |
1035 | - <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th> |
|
1036 | - <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th> |
|
1035 | + <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th> |
|
1036 | + <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th> |
|
1037 | 1037 | <?php if ($quantities_enabled) { ?> |
1038 | - <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th> |
|
1038 | + <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th> |
|
1039 | 1039 | <?php } ?> |
1040 | 1040 | <?php if ($use_taxes && !$zero_tax) { ?> |
1041 | 1041 | <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th> |
1042 | 1042 | <?php } ?> |
1043 | - <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th> |
|
1043 | + <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th> |
|
1044 | 1044 | </tr> |
1045 | 1045 | </thead> |
1046 | 1046 | <tbody> |
1047 | 1047 | <?php |
1048 | - if ( !empty( $cart_details ) ) { |
|
1049 | - do_action( 'wpinv_display_line_items_start', $invoice ); |
|
1048 | + if (!empty($cart_details)) { |
|
1049 | + do_action('wpinv_display_line_items_start', $invoice); |
|
1050 | 1050 | |
1051 | 1051 | $count = 0; |
1052 | 1052 | $cols = 3; |
1053 | - foreach ( $cart_details as $key => $cart_item ) { |
|
1054 | - $item_id = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : ''; |
|
1055 | - $item_price = isset($cart_item["item_price"]) ? wpinv_format_amount( $cart_item["item_price"] ) : 0; |
|
1056 | - $line_total = isset($cart_item["subtotal"]) ? wpinv_format_amount( $cart_item["subtotal"] ) : 0; |
|
1057 | - $quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1; |
|
1053 | + foreach ($cart_details as $key => $cart_item) { |
|
1054 | + $item_id = !empty($cart_item['id']) ? absint($cart_item['id']) : ''; |
|
1055 | + $item_price = isset($cart_item["item_price"]) ? wpinv_format_amount($cart_item["item_price"]) : 0; |
|
1056 | + $line_total = isset($cart_item["subtotal"]) ? wpinv_format_amount($cart_item["subtotal"]) : 0; |
|
1057 | + $quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1; |
|
1058 | 1058 | |
1059 | - $item = $item_id ? new WPInv_Item( $item_id ) : NULL; |
|
1059 | + $item = $item_id ? new WPInv_Item($item_id) : NULL; |
|
1060 | 1060 | $summary = ''; |
1061 | 1061 | $cols = 3; |
1062 | - if ( !empty($item) ) { |
|
1062 | + if (!empty($item)) { |
|
1063 | 1063 | $item_name = $item->get_name(); |
1064 | 1064 | $summary = $item->get_summary(); |
1065 | 1065 | } |
1066 | - $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
1066 | + $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
1067 | 1067 | |
1068 | 1068 | if (!empty($item) && $item->is_package() && !empty($cart_item['meta']['post_id'])) { |
1069 | - $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>'; |
|
1070 | - $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $item->get_cpt_singular_name(), $post_link ); |
|
1069 | + $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>'; |
|
1070 | + $summary = wp_sprintf(__('%s: %s', 'invoicing'), $item->get_cpt_singular_name(), $post_link); |
|
1071 | 1071 | } |
1072 | - $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice ); |
|
1072 | + $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice); |
|
1073 | 1073 | |
1074 | 1074 | $item_tax = ''; |
1075 | 1075 | $tax_rate = ''; |
1076 | - if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
1077 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) ); |
|
1078 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
1079 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount( $tax_rate, 2 ) : ''; |
|
1076 | + if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
1077 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax'])); |
|
1078 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
1079 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount($tax_rate, 2) : ''; |
|
1080 | 1080 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : ''; |
1081 | 1081 | } |
1082 | 1082 | |
1083 | 1083 | $line_item_tax = $item_tax . $tax_rate; |
1084 | 1084 | |
1085 | - if ( $line_item_tax === '' ) { |
|
1085 | + if ($line_item_tax === '') { |
|
1086 | 1086 | $line_item_tax = 0; // Zero tax |
1087 | 1087 | } |
1088 | 1088 | |
1089 | - $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">'; |
|
1090 | - $line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item ); |
|
1091 | - if ( $summary !== '' ) { |
|
1092 | - $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>'; |
|
1089 | + $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">'; |
|
1090 | + $line_item .= '<td class="name">' . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item); |
|
1091 | + if ($summary !== '') { |
|
1092 | + $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>'; |
|
1093 | 1093 | } |
1094 | 1094 | $line_item .= '</td>'; |
1095 | 1095 | |
1096 | - $line_item .= '<td class="rate">' . esc_html__( wpinv_price( $item_price, $invoice->get_currency() ) ) . '</td>'; |
|
1096 | + $line_item .= '<td class="rate">' . esc_html__(wpinv_price($item_price, $invoice->get_currency())) . '</td>'; |
|
1097 | 1097 | if ($quantities_enabled) { |
1098 | 1098 | $cols++; |
1099 | 1099 | $line_item .= '<td class="qty">' . $quantity . '</td>'; |
@@ -1102,55 +1102,55 @@ discard block |
||
1102 | 1102 | $cols++; |
1103 | 1103 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
1104 | 1104 | } |
1105 | - $line_item .= '<td class="total">' . esc_html__( wpinv_price( $line_total, $invoice->get_currency() ) ) . '</td>'; |
|
1105 | + $line_item .= '<td class="total">' . esc_html__(wpinv_price($line_total, $invoice->get_currency())) . '</td>'; |
|
1106 | 1106 | $line_item .= '</tr>'; |
1107 | 1107 | |
1108 | - echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols ); |
|
1108 | + echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols); |
|
1109 | 1109 | |
1110 | 1110 | $count++; |
1111 | 1111 | } |
1112 | 1112 | |
1113 | - do_action( 'wpinv_display_before_subtotal', $invoice, $cols ); |
|
1113 | + do_action('wpinv_display_before_subtotal', $invoice, $cols); |
|
1114 | 1114 | ?> |
1115 | 1115 | <tr class="row-sub-total row_odd"> |
1116 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
1117 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
1116 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
1117 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
1118 | 1118 | </tr> |
1119 | 1119 | <?php |
1120 | - do_action( 'wpinv_display_after_subtotal', $invoice, $cols ); |
|
1120 | + do_action('wpinv_display_after_subtotal', $invoice, $cols); |
|
1121 | 1121 | |
1122 | - if ( wpinv_discount( $invoice_id, false ) > 0 ) { |
|
1123 | - do_action( 'wpinv_display_before_discount', $invoice, $cols ); |
|
1122 | + if (wpinv_discount($invoice_id, false) > 0) { |
|
1123 | + do_action('wpinv_display_before_discount', $invoice, $cols); |
|
1124 | 1124 | ?> |
1125 | 1125 | <tr class="row-discount"> |
1126 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td> |
|
1127 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
1126 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td> |
|
1127 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
1128 | 1128 | </tr> |
1129 | 1129 | <?php |
1130 | - do_action( 'wpinv_display_after_discount', $invoice, $cols ); |
|
1130 | + do_action('wpinv_display_after_discount', $invoice, $cols); |
|
1131 | 1131 | } |
1132 | 1132 | |
1133 | - if ( $use_taxes ) { |
|
1134 | - do_action( 'wpinv_display_before_tax', $invoice, $cols ); |
|
1133 | + if ($use_taxes) { |
|
1134 | + do_action('wpinv_display_before_tax', $invoice, $cols); |
|
1135 | 1135 | ?> |
1136 | 1136 | <tr class="row-tax"> |
1137 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td> |
|
1138 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
1137 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td> |
|
1138 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
1139 | 1139 | </tr> |
1140 | 1140 | <?php |
1141 | - do_action( 'wpinv_display_after_tax', $invoice, $cols ); |
|
1141 | + do_action('wpinv_display_after_tax', $invoice, $cols); |
|
1142 | 1142 | } |
1143 | 1143 | |
1144 | - do_action( 'wpinv_display_before_total', $invoice, $cols ); |
|
1144 | + do_action('wpinv_display_before_total', $invoice, $cols); |
|
1145 | 1145 | ?> |
1146 | 1146 | <tr class="table-active row-total"> |
1147 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
1148 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
1147 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
1148 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
1149 | 1149 | </tr> |
1150 | 1150 | <?php |
1151 | - do_action( 'wpinv_display_after_total', $invoice, $cols ); |
|
1151 | + do_action('wpinv_display_after_total', $invoice, $cols); |
|
1152 | 1152 | |
1153 | - do_action( 'wpinv_display_line_end', $invoice, $cols ); |
|
1153 | + do_action('wpinv_display_line_end', $invoice, $cols); |
|
1154 | 1154 | } |
1155 | 1155 | ?> |
1156 | 1156 | </tbody> |
@@ -1159,35 +1159,35 @@ discard block |
||
1159 | 1159 | echo ob_get_clean(); |
1160 | 1160 | } |
1161 | 1161 | |
1162 | -function wpinv_display_invoice_totals( $invoice_id = 0 ) { |
|
1162 | +function wpinv_display_invoice_totals($invoice_id = 0) { |
|
1163 | 1163 | $use_taxes = wpinv_use_taxes(); |
1164 | 1164 | |
1165 | - do_action( 'wpinv_before_display_totals_table', $invoice_id ); |
|
1165 | + do_action('wpinv_before_display_totals_table', $invoice_id); |
|
1166 | 1166 | ?> |
1167 | 1167 | <table class="table table-sm table-bordered table-responsive"> |
1168 | 1168 | <tbody> |
1169 | - <?php do_action( 'wpinv_before_display_totals' ); ?> |
|
1169 | + <?php do_action('wpinv_before_display_totals'); ?> |
|
1170 | 1170 | <tr class="row-sub-total"> |
1171 | - <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td> |
|
1172 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
1171 | + <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td> |
|
1172 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
1173 | 1173 | </tr> |
1174 | - <?php do_action( 'wpinv_after_display_totals' ); ?> |
|
1175 | - <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?> |
|
1174 | + <?php do_action('wpinv_after_display_totals'); ?> |
|
1175 | + <?php if (wpinv_discount($invoice_id, false) > 0) { ?> |
|
1176 | 1176 | <tr class="row-discount"> |
1177 | - <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td> |
|
1178 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
1177 | + <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td> |
|
1178 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
1179 | 1179 | </tr> |
1180 | - <?php do_action( 'wpinv_after_display_discount' ); ?> |
|
1180 | + <?php do_action('wpinv_after_display_discount'); ?> |
|
1181 | 1181 | <?php } ?> |
1182 | - <?php if ( $use_taxes ) { ?> |
|
1182 | + <?php if ($use_taxes) { ?> |
|
1183 | 1183 | <tr class="row-tax"> |
1184 | - <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td> |
|
1185 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
1184 | + <td class="rate"><?php _e('Tax', 'invoicing'); ?></td> |
|
1185 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
1186 | 1186 | </tr> |
1187 | - <?php do_action( 'wpinv_after_display_tax' ); ?> |
|
1187 | + <?php do_action('wpinv_after_display_tax'); ?> |
|
1188 | 1188 | <?php } ?> |
1189 | - <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?> |
|
1190 | - <?php foreach ( $fees as $fee ) { ?> |
|
1189 | + <?php if ($fees = wpinv_get_fees($invoice_id)) { ?> |
|
1190 | + <?php foreach ($fees as $fee) { ?> |
|
1191 | 1191 | <tr class="row-fee"> |
1192 | 1192 | <td class="rate"><?php echo $fee['label']; ?></td> |
1193 | 1193 | <td class="total"><?php echo $fee['amount_display']; ?></td> |
@@ -1195,72 +1195,72 @@ discard block |
||
1195 | 1195 | <?php } ?> |
1196 | 1196 | <?php } ?> |
1197 | 1197 | <tr class="table-active row-total"> |
1198 | - <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td> |
|
1199 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
1198 | + <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td> |
|
1199 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
1200 | 1200 | </tr> |
1201 | - <?php do_action( 'wpinv_after_totals' ); ?> |
|
1201 | + <?php do_action('wpinv_after_totals'); ?> |
|
1202 | 1202 | </tbody> |
1203 | 1203 | |
1204 | 1204 | </table> |
1205 | 1205 | |
1206 | - <?php do_action( 'wpinv_after_totals_table' ); |
|
1206 | + <?php do_action('wpinv_after_totals_table'); |
|
1207 | 1207 | } |
1208 | 1208 | |
1209 | -function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) { |
|
1210 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1209 | +function wpinv_display_payments_info($invoice_id = 0, $echo = true) { |
|
1210 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1211 | 1211 | |
1212 | 1212 | ob_start(); |
1213 | - do_action( 'wpinv_before_display_payments_info', $invoice_id ); |
|
1214 | - if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() ) { |
|
1213 | + do_action('wpinv_before_display_payments_info', $invoice_id); |
|
1214 | + if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid()) { |
|
1215 | 1215 | ?> |
1216 | 1216 | <div class="wpi-payment-info"> |
1217 | - <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p> |
|
1218 | - <?php if ( $gateway_title ) { ?> |
|
1219 | - <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p> |
|
1217 | + <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p> |
|
1218 | + <?php if ($gateway_title) { ?> |
|
1219 | + <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p> |
|
1220 | 1220 | <?php } ?> |
1221 | 1221 | </div> |
1222 | 1222 | <?php |
1223 | 1223 | } |
1224 | - do_action( 'wpinv_after_display_payments_info', $invoice_id ); |
|
1224 | + do_action('wpinv_after_display_payments_info', $invoice_id); |
|
1225 | 1225 | $outout = ob_get_clean(); |
1226 | 1226 | |
1227 | - if ( $echo ) { |
|
1227 | + if ($echo) { |
|
1228 | 1228 | echo $outout; |
1229 | 1229 | } else { |
1230 | 1230 | return $outout; |
1231 | 1231 | } |
1232 | 1232 | } |
1233 | 1233 | |
1234 | -function wpinv_display_style( $invoice ) { |
|
1235 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION ); |
|
1234 | +function wpinv_display_style($invoice) { |
|
1235 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION); |
|
1236 | 1236 | |
1237 | - wp_print_styles( 'open-sans' ); |
|
1238 | - wp_print_styles( 'wpinv-single-style' ); |
|
1237 | + wp_print_styles('open-sans'); |
|
1238 | + wp_print_styles('wpinv-single-style'); |
|
1239 | 1239 | } |
1240 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
1240 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
1241 | 1241 | |
1242 | 1242 | function wpinv_checkout_billing_details() { |
1243 | 1243 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
1244 | 1244 | if (empty($invoice_id)) { |
1245 | - wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ ); |
|
1245 | + wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__); |
|
1246 | 1246 | return null; |
1247 | 1247 | } |
1248 | 1248 | |
1249 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
1249 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
1250 | 1250 | if (empty($invoice)) { |
1251 | - wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ ); |
|
1251 | + wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__); |
|
1252 | 1252 | return null; |
1253 | 1253 | } |
1254 | 1254 | $user_id = $invoice->get_user_id(); |
1255 | 1255 | $user_info = $invoice->get_user_info(); |
1256 | - $address_info = wpinv_get_user_address( $user_id ); |
|
1256 | + $address_info = wpinv_get_user_address($user_id); |
|
1257 | 1257 | |
1258 | - if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) { |
|
1258 | + if (empty($user_info['first_name']) && !empty($user_info['first_name'])) { |
|
1259 | 1259 | $user_info['first_name'] = $user_info['first_name']; |
1260 | 1260 | $user_info['last_name'] = $user_info['last_name']; |
1261 | 1261 | } |
1262 | 1262 | |
1263 | - if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) { |
|
1263 | + if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) { |
|
1264 | 1264 | $user_info['country'] = $address_info['country']; |
1265 | 1265 | $user_info['state'] = $address_info['state']; |
1266 | 1266 | $user_info['city'] = $address_info['city']; |
@@ -1276,103 +1276,103 @@ discard block |
||
1276 | 1276 | 'address' |
1277 | 1277 | ); |
1278 | 1278 | |
1279 | - foreach ( $address_fields as $field ) { |
|
1280 | - if ( empty( $user_info[$field] ) ) { |
|
1279 | + foreach ($address_fields as $field) { |
|
1280 | + if (empty($user_info[$field])) { |
|
1281 | 1281 | $user_info[$field] = $address_info[$field]; |
1282 | 1282 | } |
1283 | 1283 | } |
1284 | 1284 | |
1285 | - return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice ); |
|
1285 | + return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice); |
|
1286 | 1286 | } |
1287 | 1287 | |
1288 | 1288 | function wpinv_admin_get_line_items($invoice = array()) { |
1289 | 1289 | $item_quantities = wpinv_item_quantities_enabled(); |
1290 | 1290 | $use_taxes = wpinv_use_taxes(); |
1291 | 1291 | |
1292 | - if ( empty( $invoice ) ) { |
|
1292 | + if (empty($invoice)) { |
|
1293 | 1293 | return NULL; |
1294 | 1294 | } |
1295 | 1295 | |
1296 | 1296 | $cart_items = $invoice->get_cart_details(); |
1297 | - if ( empty( $cart_items ) ) { |
|
1297 | + if (empty($cart_items)) { |
|
1298 | 1298 | return NULL; |
1299 | 1299 | } |
1300 | 1300 | ob_start(); |
1301 | 1301 | |
1302 | - do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice ); |
|
1302 | + do_action('wpinv_admin_before_line_items', $cart_items, $invoice); |
|
1303 | 1303 | |
1304 | 1304 | $count = 0; |
1305 | - foreach ( $cart_items as $key => $cart_item ) { |
|
1305 | + foreach ($cart_items as $key => $cart_item) { |
|
1306 | 1306 | $item_id = $cart_item['id']; |
1307 | - $wpi_item = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL; |
|
1307 | + $wpi_item = $item_id > 0 ? new WPInv_Item($item_id) : NULL; |
|
1308 | 1308 | |
1309 | 1309 | if (empty($wpi_item)) { |
1310 | 1310 | continue; |
1311 | 1311 | } |
1312 | 1312 | |
1313 | - $item_price = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ) ); |
|
1314 | - $quantity = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
1315 | - $item_subtotal = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ) ); |
|
1313 | + $item_price = wpinv_price(wpinv_format_amount($cart_item['item_price'])); |
|
1314 | + $quantity = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
1315 | + $item_subtotal = wpinv_price(wpinv_format_amount($cart_item['subtotal'])); |
|
1316 | 1316 | $can_remove = true; |
1317 | 1317 | |
1318 | 1318 | $summary = ''; |
1319 | 1319 | if ($wpi_item->is_package() && !empty($cart_item['meta']['post_id'])) { |
1320 | - $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>'; |
|
1321 | - $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_cpt_singular_name(), $post_link ); |
|
1320 | + $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>'; |
|
1321 | + $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_cpt_singular_name(), $post_link); |
|
1322 | 1322 | } |
1323 | - $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice ); |
|
1323 | + $summary = apply_filters('wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice); |
|
1324 | 1324 | |
1325 | 1325 | $item_tax = ''; |
1326 | 1326 | $tax_rate = ''; |
1327 | - if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
1328 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) ); |
|
1329 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
1330 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount( $tax_rate, 2 ) : ''; |
|
1327 | + if ($cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
1328 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax'])); |
|
1329 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
1330 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount($tax_rate, 2) : ''; |
|
1331 | 1331 | $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : ''; |
1332 | 1332 | } |
1333 | 1333 | $line_item_tax = $item_tax . $tax_rate; |
1334 | 1334 | |
1335 | - if ( $line_item_tax === '' ) { |
|
1335 | + if ($line_item_tax === '') { |
|
1336 | 1336 | $line_item_tax = 0; // Zero tax |
1337 | 1337 | } |
1338 | 1338 | |
1339 | - $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">'; |
|
1339 | + $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">'; |
|
1340 | 1340 | $line_item .= '<td class="id">' . $item_id . '</td>'; |
1341 | - $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item ); |
|
1342 | - if ( $summary !== '' ) { |
|
1343 | - $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>'; |
|
1341 | + $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item); |
|
1342 | + if ($summary !== '') { |
|
1343 | + $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>'; |
|
1344 | 1344 | } |
1345 | 1345 | $line_item .= '</td>'; |
1346 | 1346 | $line_item .= '<td class="price">' . $item_price . '</td>'; |
1347 | 1347 | |
1348 | - if ( $item_quantities ) { |
|
1349 | - if ( count( $cart_items ) == 1 && $quantity <= 1 ) { |
|
1348 | + if ($item_quantities) { |
|
1349 | + if (count($cart_items) == 1 && $quantity <= 1) { |
|
1350 | 1350 | $can_remove = false; |
1351 | 1351 | } |
1352 | 1352 | $line_item .= '<td class="qty" data-quantity="' . $quantity . '"> × ' . $quantity . '</td>'; |
1353 | 1353 | } else { |
1354 | - if ( count( $cart_items ) == 1 ) { |
|
1354 | + if (count($cart_items) == 1) { |
|
1355 | 1355 | $can_remove = false; |
1356 | 1356 | } |
1357 | 1357 | } |
1358 | 1358 | $line_item .= '<td class="total">' . $item_subtotal . '</td>'; |
1359 | 1359 | |
1360 | - if ( $use_taxes ) { |
|
1360 | + if ($use_taxes) { |
|
1361 | 1361 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
1362 | 1362 | } |
1363 | 1363 | $line_item .= '<td class="action">'; |
1364 | - if ( !$invoice->is_paid() && $can_remove ) { |
|
1364 | + if (!$invoice->is_paid() && $can_remove) { |
|
1365 | 1365 | $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>'; |
1366 | 1366 | } |
1367 | 1367 | $line_item .= '</td>'; |
1368 | 1368 | $line_item .= '</tr>'; |
1369 | 1369 | |
1370 | - echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice ); |
|
1370 | + echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice); |
|
1371 | 1371 | |
1372 | 1372 | $count++; |
1373 | 1373 | } |
1374 | 1374 | |
1375 | - do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice ); |
|
1375 | + do_action('wpinv_admin_after_line_items', $cart_items, $invoice); |
|
1376 | 1376 | |
1377 | 1377 | return ob_get_clean(); |
1378 | 1378 | } |
@@ -1383,35 +1383,35 @@ discard block |
||
1383 | 1383 | // Set current invoice id. |
1384 | 1384 | $wpi_checkout_id = wpinv_get_invoice_cart_id(); |
1385 | 1385 | |
1386 | - $form_action = esc_url( wpinv_get_checkout_uri() ); |
|
1386 | + $form_action = esc_url(wpinv_get_checkout_uri()); |
|
1387 | 1387 | |
1388 | 1388 | ob_start(); |
1389 | 1389 | echo '<div id="wpinv_checkout_wrap">'; |
1390 | 1390 | |
1391 | - if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) { |
|
1391 | + if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) { |
|
1392 | 1392 | ?> |
1393 | 1393 | <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive"> |
1394 | - <?php do_action( 'wpinv_before_checkout_form' ); ?> |
|
1394 | + <?php do_action('wpinv_before_checkout_form'); ?> |
|
1395 | 1395 | <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST"> |
1396 | 1396 | <?php |
1397 | - do_action( 'wpinv_checkout_form_top' ); |
|
1398 | - do_action( 'wpinv_checkout_billing_info' ); |
|
1399 | - do_action( 'wpinv_checkout_cart' ); |
|
1400 | - do_action( 'wpinv_payment_mode_select' ); |
|
1401 | - do_action( 'wpinv_checkout_form_bottom' ) |
|
1397 | + do_action('wpinv_checkout_form_top'); |
|
1398 | + do_action('wpinv_checkout_billing_info'); |
|
1399 | + do_action('wpinv_checkout_cart'); |
|
1400 | + do_action('wpinv_payment_mode_select'); |
|
1401 | + do_action('wpinv_checkout_form_bottom') |
|
1402 | 1402 | ?> |
1403 | 1403 | </form> |
1404 | - <?php do_action( 'wpinv_after_purchase_form' ); ?> |
|
1404 | + <?php do_action('wpinv_after_purchase_form'); ?> |
|
1405 | 1405 | </div><!--end #wpinv_checkout_form_wrap--> |
1406 | 1406 | <?php |
1407 | 1407 | } else { |
1408 | - do_action( 'wpinv_cart_empty' ); |
|
1408 | + do_action('wpinv_cart_empty'); |
|
1409 | 1409 | } |
1410 | 1410 | echo '</div><!--end #wpinv_checkout_wrap-->'; |
1411 | 1411 | return ob_get_clean(); |
1412 | 1412 | } |
1413 | 1413 | |
1414 | -function wpinv_checkout_cart( $cart_details = array(), $echo = true ) { |
|
1414 | +function wpinv_checkout_cart($cart_details = array(), $echo = true) { |
|
1415 | 1415 | global $ajax_cart_details; |
1416 | 1416 | $ajax_cart_details = $cart_details; |
1417 | 1417 | /* |
@@ -1426,25 +1426,25 @@ discard block |
||
1426 | 1426 | } |
1427 | 1427 | */ |
1428 | 1428 | ob_start(); |
1429 | - do_action( 'wpinv_before_checkout_cart' ); |
|
1429 | + do_action('wpinv_before_checkout_cart'); |
|
1430 | 1430 | echo '<div id="wpinv_checkout_cart_form" method="post">'; |
1431 | 1431 | echo '<div id="wpinv_checkout_cart_wrap">'; |
1432 | - wpinv_get_template_part( 'wpinv-checkout-cart' ); |
|
1432 | + wpinv_get_template_part('wpinv-checkout-cart'); |
|
1433 | 1433 | echo '</div>'; |
1434 | 1434 | echo '</div>'; |
1435 | - do_action( 'wpinv_after_checkout_cart' ); |
|
1435 | + do_action('wpinv_after_checkout_cart'); |
|
1436 | 1436 | $content = ob_get_clean(); |
1437 | 1437 | |
1438 | - if ( $echo ) { |
|
1438 | + if ($echo) { |
|
1439 | 1439 | echo $content; |
1440 | 1440 | } else { |
1441 | 1441 | return $content; |
1442 | 1442 | } |
1443 | 1443 | } |
1444 | -add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 ); |
|
1444 | +add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10); |
|
1445 | 1445 | |
1446 | 1446 | function wpinv_empty_cart_message() { |
1447 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1447 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1448 | 1448 | } |
1449 | 1449 | |
1450 | 1450 | /** |
@@ -1456,91 +1456,91 @@ discard block |
||
1456 | 1456 | function wpinv_empty_checkout_cart() { |
1457 | 1457 | echo wpinv_empty_cart_message(); |
1458 | 1458 | } |
1459 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1459 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1460 | 1460 | |
1461 | 1461 | function wpinv_save_cart_button() { |
1462 | - if ( wpinv_is_cart_saving_disabled() ) |
|
1462 | + if (wpinv_is_cart_saving_disabled()) |
|
1463 | 1463 | return; |
1464 | 1464 | ?> |
1465 | - <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a> |
|
1465 | + <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url(add_query_arg('wpi_action', 'save_cart')); ?>"><?php _e('Save Cart', 'invoicing'); ?></a> |
|
1466 | 1466 | <?php |
1467 | 1467 | } |
1468 | 1468 | |
1469 | 1469 | function wpinv_update_cart_button() { |
1470 | - if ( !wpinv_item_quantities_enabled() ) |
|
1470 | + if (!wpinv_item_quantities_enabled()) |
|
1471 | 1471 | return; |
1472 | 1472 | ?> |
1473 | - <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/> |
|
1473 | + <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/> |
|
1474 | 1474 | <input type="hidden" name="wpi_action" value="update_cart"/> |
1475 | 1475 | <?php |
1476 | 1476 | } |
1477 | 1477 | |
1478 | 1478 | function wpinv_checkout_cart_columns() { |
1479 | 1479 | $default = 3; |
1480 | - if ( wpinv_item_quantities_enabled() ) { |
|
1480 | + if (wpinv_item_quantities_enabled()) { |
|
1481 | 1481 | $default++; |
1482 | 1482 | } |
1483 | 1483 | |
1484 | - if ( wpinv_use_taxes() ) { |
|
1484 | + if (wpinv_use_taxes()) { |
|
1485 | 1485 | $default++; |
1486 | 1486 | } |
1487 | 1487 | |
1488 | - return apply_filters( 'wpinv_checkout_cart_columns', $default ); |
|
1488 | + return apply_filters('wpinv_checkout_cart_columns', $default); |
|
1489 | 1489 | } |
1490 | 1490 | |
1491 | 1491 | function wpinv_display_cart_messages() { |
1492 | 1492 | global $wpi_session; |
1493 | 1493 | |
1494 | - $messages = $wpi_session->get( 'wpinv_cart_messages' ); |
|
1494 | + $messages = $wpi_session->get('wpinv_cart_messages'); |
|
1495 | 1495 | |
1496 | - if ( $messages ) { |
|
1497 | - foreach ( $messages as $message_id => $message ) { |
|
1496 | + if ($messages) { |
|
1497 | + foreach ($messages as $message_id => $message) { |
|
1498 | 1498 | // Try and detect what type of message this is |
1499 | - if ( strpos( strtolower( $message ), 'error' ) ) { |
|
1499 | + if (strpos(strtolower($message), 'error')) { |
|
1500 | 1500 | $type = 'error'; |
1501 | - } elseif ( strpos( strtolower( $message ), 'success' ) ) { |
|
1501 | + } elseif (strpos(strtolower($message), 'success')) { |
|
1502 | 1502 | $type = 'success'; |
1503 | 1503 | } else { |
1504 | 1504 | $type = 'info'; |
1505 | 1505 | } |
1506 | 1506 | |
1507 | - $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) ); |
|
1507 | + $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type)); |
|
1508 | 1508 | |
1509 | - echo '<div class="' . implode( ' ', $classes ) . '">'; |
|
1509 | + echo '<div class="' . implode(' ', $classes) . '">'; |
|
1510 | 1510 | // Loop message codes and display messages |
1511 | 1511 | echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>'; |
1512 | 1512 | echo '</div>'; |
1513 | 1513 | } |
1514 | 1514 | |
1515 | 1515 | // Remove all of the cart saving messages |
1516 | - $wpi_session->set( 'wpinv_cart_messages', null ); |
|
1516 | + $wpi_session->set('wpinv_cart_messages', null); |
|
1517 | 1517 | } |
1518 | 1518 | } |
1519 | -add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' ); |
|
1519 | +add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages'); |
|
1520 | 1520 | |
1521 | 1521 | function wpinv_discount_field() { |
1522 | - if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) { |
|
1522 | + if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) { |
|
1523 | 1523 | return; // Only show before a payment method has been selected if ajax is disabled |
1524 | 1524 | } |
1525 | 1525 | |
1526 | - if ( !wpinv_is_checkout() ) { |
|
1526 | + if (!wpinv_is_checkout()) { |
|
1527 | 1527 | return; |
1528 | 1528 | } |
1529 | 1529 | |
1530 | - if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) { |
|
1530 | + if (wpinv_has_active_discounts() && wpinv_get_cart_total()) { |
|
1531 | 1531 | ?> |
1532 | 1532 | <div id="wpinv-discount-field" class="panel panel-default"> |
1533 | 1533 | <div class="panel-body"> |
1534 | 1534 | <p> |
1535 | - <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label> |
|
1536 | - <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span> |
|
1535 | + <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label> |
|
1536 | + <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span> |
|
1537 | 1537 | </p> |
1538 | 1538 | <div class="form-group row"> |
1539 | 1539 | <div class="col-sm-4"> |
1540 | - <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/> |
|
1540 | + <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/> |
|
1541 | 1541 | </div> |
1542 | 1542 | <div class="col-sm-3"> |
1543 | - <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button> |
|
1543 | + <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button> |
|
1544 | 1544 | </div> |
1545 | 1545 | <div class="col-sm-12 wpinv-discount-msg"> |
1546 | 1546 | <div class="alert alert-success"><i class="fa fa-check-circle"></i><span class="wpi-msg"></span></div> |
@@ -1552,10 +1552,10 @@ discard block |
||
1552 | 1552 | <?php |
1553 | 1553 | } |
1554 | 1554 | } |
1555 | -add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 ); |
|
1555 | +add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10); |
|
1556 | 1556 | |
1557 | 1557 | function wpinv_agree_to_terms_js() { |
1558 | - if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
1558 | + if (wpinv_get_option('show_agree_to_terms', false)) { |
|
1559 | 1559 | ?> |
1560 | 1560 | <script type="text/javascript"> |
1561 | 1561 | jQuery(document).ready(function($){ |
@@ -1570,124 +1570,124 @@ discard block |
||
1570 | 1570 | <?php |
1571 | 1571 | } |
1572 | 1572 | } |
1573 | -add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' ); |
|
1573 | +add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js'); |
|
1574 | 1574 | |
1575 | 1575 | function wpinv_payment_mode_select() { |
1576 | - $gateways = wpinv_get_enabled_payment_gateways( true ); |
|
1577 | - $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways ); |
|
1576 | + $gateways = wpinv_get_enabled_payment_gateways(true); |
|
1577 | + $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways); |
|
1578 | 1578 | $page_URL = wpinv_get_current_page_url(); |
1579 | 1579 | |
1580 | 1580 | do_action('wpinv_payment_mode_top'); |
1581 | 1581 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
1582 | 1582 | ?> |
1583 | 1583 | <div id="wpinv_payment_mode_select"> |
1584 | - <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?> |
|
1584 | + <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?> |
|
1585 | 1585 | <div id="wpinv-payment-mode-wrap" class="panel panel-default"> |
1586 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div> |
|
1586 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div> |
|
1587 | 1587 | <div class="panel-body list-group wpi-payment_methods"> |
1588 | 1588 | <?php |
1589 | - do_action( 'wpinv_payment_mode_before_gateways' ); |
|
1590 | - $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id ); |
|
1589 | + do_action('wpinv_payment_mode_before_gateways'); |
|
1590 | + $chosen_gateway = wpinv_get_chosen_gateway($invoice_id); |
|
1591 | 1591 | |
1592 | - if(!empty($gateways)){ |
|
1593 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
1594 | - $checked = checked( $gateway_id, $chosen_gateway, false ); |
|
1595 | - $button_label = wpinv_get_gateway_button_label( $gateway_id ); |
|
1596 | - $description = wpinv_get_gateway_description( $gateway_id ); |
|
1592 | + if (!empty($gateways)) { |
|
1593 | + foreach ($gateways as $gateway_id => $gateway) { |
|
1594 | + $checked = checked($gateway_id, $chosen_gateway, false); |
|
1595 | + $button_label = wpinv_get_gateway_button_label($gateway_id); |
|
1596 | + $description = wpinv_get_gateway_description($gateway_id); |
|
1597 | 1597 | ?> |
1598 | 1598 | <div class="list-group-item"> |
1599 | 1599 | <div class="radio"> |
1600 | - <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway['checkout_label'] ); ?></label> |
|
1600 | + <label><input type="radio" data-button-text="<?php echo esc_attr($button_label); ?>" value="<?php echo esc_attr($gateway_id); ?>" <?php echo $checked; ?> id="wpi_gateway_<?php echo esc_attr($gateway_id); ?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html($gateway['checkout_label']); ?></label> |
|
1601 | 1601 | </div> |
1602 | - <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert"> |
|
1603 | - <?php if ( !empty( $description ) ) { ?> |
|
1604 | - <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div> |
|
1602 | + <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert"> |
|
1603 | + <?php if (!empty($description)) { ?> |
|
1604 | + <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div> |
|
1605 | 1605 | <?php } ?> |
1606 | - <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?> |
|
1606 | + <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?> |
|
1607 | 1607 | </div> |
1608 | 1608 | </div> |
1609 | 1609 | <?php |
1610 | 1610 | } |
1611 | - }else{ |
|
1612 | - echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>'; |
|
1611 | + } else { |
|
1612 | + echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>'; |
|
1613 | 1613 | } |
1614 | 1614 | |
1615 | - do_action( 'wpinv_payment_mode_after_gateways' ); |
|
1615 | + do_action('wpinv_payment_mode_after_gateways'); |
|
1616 | 1616 | ?> |
1617 | 1617 | </div> |
1618 | 1618 | </div> |
1619 | - <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?> |
|
1619 | + <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?> |
|
1620 | 1620 | </div> |
1621 | 1621 | <?php |
1622 | 1622 | do_action('wpinv_payment_mode_bottom'); |
1623 | 1623 | } |
1624 | -add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' ); |
|
1624 | +add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select'); |
|
1625 | 1625 | |
1626 | 1626 | function wpinv_checkout_billing_info() { |
1627 | - if ( wpinv_is_checkout() ) { |
|
1627 | + if (wpinv_is_checkout()) { |
|
1628 | 1628 | $logged_in = is_user_logged_in(); |
1629 | 1629 | $billing_details = wpinv_checkout_billing_details(); |
1630 | - $selected_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
1630 | + $selected_country = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
1631 | 1631 | ?> |
1632 | 1632 | <div id="wpinv-fields" class="clearfix"> |
1633 | 1633 | <div id="wpi-billing" class="wpi-billing clearfix panel panel-default"> |
1634 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div> |
|
1634 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div> |
|
1635 | 1635 | <div id="wpinv-fields-box" class="panel-body"> |
1636 | - <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?> |
|
1636 | + <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?> |
|
1637 | 1637 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1638 | - <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1638 | + <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1639 | 1639 | <?php |
1640 | - echo wpinv_html_text( array( |
|
1640 | + echo wpinv_html_text(array( |
|
1641 | 1641 | 'id' => 'wpinv_first_name', |
1642 | 1642 | 'name' => 'wpinv_first_name', |
1643 | 1643 | 'value' => $billing_details['first_name'], |
1644 | 1644 | 'class' => 'wpi-input form-control required', |
1645 | - 'placeholder' => __( 'First name', 'invoicing' ), |
|
1645 | + 'placeholder' => __('First name', 'invoicing'), |
|
1646 | 1646 | 'required' => true, |
1647 | - ) ); |
|
1647 | + )); |
|
1648 | 1648 | ?> |
1649 | 1649 | </p> |
1650 | 1650 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1651 | - <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?></label> |
|
1651 | + <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?></label> |
|
1652 | 1652 | <?php |
1653 | - echo wpinv_html_text( array( |
|
1653 | + echo wpinv_html_text(array( |
|
1654 | 1654 | 'id' => 'wpinv_last_name', |
1655 | 1655 | 'name' => 'wpinv_last_name', |
1656 | 1656 | 'value' => $billing_details['last_name'], |
1657 | 1657 | 'class' => 'wpi-input form-control', |
1658 | - 'placeholder' => __( 'Last name', 'invoicing' ), |
|
1659 | - ) ); |
|
1658 | + 'placeholder' => __('Last name', 'invoicing'), |
|
1659 | + )); |
|
1660 | 1660 | ?> |
1661 | 1661 | </p> |
1662 | 1662 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1663 | - <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1663 | + <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1664 | 1664 | <?php |
1665 | - echo wpinv_html_text( array( |
|
1665 | + echo wpinv_html_text(array( |
|
1666 | 1666 | 'id' => 'wpinv_address', |
1667 | 1667 | 'name' => 'wpinv_address', |
1668 | 1668 | 'value' => $billing_details['address'], |
1669 | 1669 | 'class' => 'wpi-input form-control required', |
1670 | - 'placeholder' => __( 'Address', 'invoicing' ), |
|
1670 | + 'placeholder' => __('Address', 'invoicing'), |
|
1671 | 1671 | 'required' => true, |
1672 | - ) ); |
|
1672 | + )); |
|
1673 | 1673 | ?> |
1674 | 1674 | </p> |
1675 | 1675 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1676 | - <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1676 | + <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1677 | 1677 | <?php |
1678 | - echo wpinv_html_text( array( |
|
1678 | + echo wpinv_html_text(array( |
|
1679 | 1679 | 'id' => 'wpinv_city', |
1680 | 1680 | 'name' => 'wpinv_city', |
1681 | 1681 | 'value' => $billing_details['city'], |
1682 | 1682 | 'class' => 'wpi-input form-control required', |
1683 | - 'placeholder' => __( 'City', 'invoicing' ), |
|
1683 | + 'placeholder' => __('City', 'invoicing'), |
|
1684 | 1684 | 'required' => true, |
1685 | - ) ); |
|
1685 | + )); |
|
1686 | 1686 | ?> |
1687 | 1687 | </p> |
1688 | 1688 | <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf"> |
1689 | - <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1690 | - <?php echo wpinv_html_select( array( |
|
1689 | + <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1690 | + <?php echo wpinv_html_select(array( |
|
1691 | 1691 | 'options' => wpinv_get_country_list(), |
1692 | 1692 | 'name' => 'wpinv_country', |
1693 | 1693 | 'id' => 'wpinv_country', |
@@ -1695,16 +1695,16 @@ discard block |
||
1695 | 1695 | 'show_option_all' => false, |
1696 | 1696 | 'show_option_none' => false, |
1697 | 1697 | 'class' => 'wpi-input form-control required', |
1698 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
1698 | + 'placeholder' => __('Choose a country', 'invoicing'), |
|
1699 | 1699 | 'required' => true, |
1700 | - ) ); ?> |
|
1700 | + )); ?> |
|
1701 | 1701 | </p> |
1702 | 1702 | <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll"> |
1703 | - <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1703 | + <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1704 | 1704 | <?php |
1705 | - $states = wpinv_get_country_states( $selected_country ); |
|
1706 | - if( !empty( $states ) ) { |
|
1707 | - echo wpinv_html_select( array( |
|
1705 | + $states = wpinv_get_country_states($selected_country); |
|
1706 | + if (!empty($states)) { |
|
1707 | + echo wpinv_html_select(array( |
|
1708 | 1708 | 'options' => $states, |
1709 | 1709 | 'name' => 'wpinv_state', |
1710 | 1710 | 'id' => 'wpinv_state', |
@@ -1712,60 +1712,60 @@ discard block |
||
1712 | 1712 | 'show_option_all' => false, |
1713 | 1713 | 'show_option_none' => false, |
1714 | 1714 | 'class' => 'wpi-input form-control required', |
1715 | - 'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
1715 | + 'placeholder' => __('Choose a state', 'invoicing'), |
|
1716 | 1716 | 'required' => true, |
1717 | - ) ); |
|
1717 | + )); |
|
1718 | 1718 | } else { |
1719 | - echo wpinv_html_text( array( |
|
1719 | + echo wpinv_html_text(array( |
|
1720 | 1720 | 'name' => 'wpinv_state', |
1721 | 1721 | 'value' => $billing_details['state'], |
1722 | 1722 | 'id' => 'wpinv_state', |
1723 | 1723 | 'class' => 'wpi-input form-control required', |
1724 | - 'placeholder' => __( 'State / Province', 'invoicing' ), |
|
1724 | + 'placeholder' => __('State / Province', 'invoicing'), |
|
1725 | 1725 | 'required' => true, |
1726 | - ) ); |
|
1726 | + )); |
|
1727 | 1727 | } |
1728 | 1728 | ?> |
1729 | 1729 | </p> |
1730 | 1730 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1731 | - <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?></label> |
|
1731 | + <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?></label> |
|
1732 | 1732 | <?php |
1733 | - echo wpinv_html_text( array( |
|
1733 | + echo wpinv_html_text(array( |
|
1734 | 1734 | 'name' => 'wpinv_zip', |
1735 | 1735 | 'value' => $billing_details['zip'], |
1736 | 1736 | 'id' => 'wpinv_zip', |
1737 | 1737 | 'class' => 'wpi-input form-control', |
1738 | - 'placeholder' => __( 'ZIP / Postcode', 'invoicing' ), |
|
1739 | - ) ); |
|
1738 | + 'placeholder' => __('ZIP / Postcode', 'invoicing'), |
|
1739 | + )); |
|
1740 | 1740 | ?> |
1741 | 1741 | </p> |
1742 | 1742 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1743 | - <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1743 | + <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1744 | 1744 | <?php |
1745 | - echo wpinv_html_text( array( |
|
1745 | + echo wpinv_html_text(array( |
|
1746 | 1746 | 'id' => 'wpinv_phone', |
1747 | 1747 | 'name' => 'wpinv_phone', |
1748 | 1748 | 'value' => $billing_details['phone'], |
1749 | 1749 | 'class' => 'wpi-input form-control', |
1750 | - 'placeholder' => __( 'Phone', 'invoicing' ), |
|
1751 | - 'required' => (bool)wpinv_get_option( 'phone_mandatory' ), |
|
1752 | - ) ); |
|
1750 | + 'placeholder' => __('Phone', 'invoicing'), |
|
1751 | + 'required' => (bool)wpinv_get_option('phone_mandatory'), |
|
1752 | + )); |
|
1753 | 1753 | ?> |
1754 | 1754 | </p> |
1755 | - <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?> |
|
1755 | + <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?> |
|
1756 | 1756 | <div class="clearfix"></div> |
1757 | 1757 | </div> |
1758 | 1758 | </div> |
1759 | - <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?> |
|
1759 | + <?php do_action('wpinv_after_billing_fields', $billing_details); ?> |
|
1760 | 1760 | </div> |
1761 | 1761 | <?php |
1762 | 1762 | } |
1763 | 1763 | } |
1764 | -add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' ); |
|
1764 | +add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info'); |
|
1765 | 1765 | |
1766 | 1766 | function wpinv_checkout_hidden_fields() { |
1767 | 1767 | ?> |
1768 | - <?php if ( is_user_logged_in() ) { ?> |
|
1768 | + <?php if (is_user_logged_in()) { ?> |
|
1769 | 1769 | <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/> |
1770 | 1770 | <?php } ?> |
1771 | 1771 | <input type="hidden" name="wpi_action" value="payment" /> |
@@ -1775,9 +1775,9 @@ discard block |
||
1775 | 1775 | function wpinv_checkout_button_purchase() { |
1776 | 1776 | ob_start(); |
1777 | 1777 | ?> |
1778 | - <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/> |
|
1778 | + <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/> |
|
1779 | 1779 | <?php |
1780 | - return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() ); |
|
1780 | + return apply_filters('wpinv_checkout_button_purchase', ob_get_clean()); |
|
1781 | 1781 | } |
1782 | 1782 | |
1783 | 1783 | function wpinv_checkout_total() { |
@@ -1786,96 +1786,96 @@ discard block |
||
1786 | 1786 | <div id="wpinv_checkout_total" class="panel panel-info"> |
1787 | 1787 | <div class="panel-body"> |
1788 | 1788 | <?php |
1789 | - do_action( 'wpinv_purchase_form_before_checkout_total' ); |
|
1789 | + do_action('wpinv_purchase_form_before_checkout_total'); |
|
1790 | 1790 | ?> |
1791 | - <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span> |
|
1791 | + <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span> |
|
1792 | 1792 | <?php |
1793 | - do_action( 'wpinv_purchase_form_after_checkout_total' ); |
|
1793 | + do_action('wpinv_purchase_form_after_checkout_total'); |
|
1794 | 1794 | ?> |
1795 | 1795 | </div> |
1796 | 1796 | </div> |
1797 | 1797 | <?php |
1798 | 1798 | } |
1799 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 ); |
|
1799 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998); |
|
1800 | 1800 | |
1801 | 1801 | function wpinv_checkout_submit() { |
1802 | 1802 | ?> |
1803 | 1803 | <div id="wpinv_purchase_submit" class="panel panel-success"> |
1804 | 1804 | <div class="panel-body text-center"> |
1805 | 1805 | <?php |
1806 | - do_action( 'wpinv_purchase_form_before_submit' ); |
|
1806 | + do_action('wpinv_purchase_form_before_submit'); |
|
1807 | 1807 | wpinv_checkout_hidden_fields(); |
1808 | 1808 | echo wpinv_checkout_button_purchase(); |
1809 | - do_action( 'wpinv_purchase_form_after_submit' ); |
|
1809 | + do_action('wpinv_purchase_form_after_submit'); |
|
1810 | 1810 | ?> |
1811 | 1811 | </div> |
1812 | 1812 | </div> |
1813 | 1813 | <?php |
1814 | 1814 | } |
1815 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 ); |
|
1815 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999); |
|
1816 | 1816 | |
1817 | -function wpinv_receipt_billing_address( $invoice_id = 0 ) { |
|
1818 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1817 | +function wpinv_receipt_billing_address($invoice_id = 0) { |
|
1818 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1819 | 1819 | |
1820 | - if ( empty( $invoice ) ) { |
|
1820 | + if (empty($invoice)) { |
|
1821 | 1821 | return NULL; |
1822 | 1822 | } |
1823 | 1823 | |
1824 | 1824 | $billing_details = $invoice->get_user_info(); |
1825 | 1825 | $address_row = ''; |
1826 | - if ( $address = $billing_details['address'] ) { |
|
1827 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
1826 | + if ($address = $billing_details['address']) { |
|
1827 | + $address_row .= wpautop(wp_kses_post($address)); |
|
1828 | 1828 | } |
1829 | 1829 | |
1830 | 1830 | $address_fields = array(); |
1831 | - if ( !empty( $billing_details['city'] ) ) { |
|
1831 | + if (!empty($billing_details['city'])) { |
|
1832 | 1832 | $address_fields[] = $billing_details['city']; |
1833 | 1833 | } |
1834 | 1834 | |
1835 | - $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
1836 | - if ( !empty( $billing_details['state'] ) ) { |
|
1837 | - $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
1835 | + $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : ''; |
|
1836 | + if (!empty($billing_details['state'])) { |
|
1837 | + $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country); |
|
1838 | 1838 | } |
1839 | 1839 | |
1840 | - if ( !empty( $billing_country ) ) { |
|
1841 | - $address_fields[] = wpinv_country_name( $billing_country ); |
|
1840 | + if (!empty($billing_country)) { |
|
1841 | + $address_fields[] = wpinv_country_name($billing_country); |
|
1842 | 1842 | } |
1843 | 1843 | |
1844 | - if ( !empty( $address_fields ) ) { |
|
1845 | - $address_fields = implode( ", ", $address_fields ); |
|
1844 | + if (!empty($address_fields)) { |
|
1845 | + $address_fields = implode(", ", $address_fields); |
|
1846 | 1846 | |
1847 | - if ( !empty( $billing_details['zip'] ) ) { |
|
1847 | + if (!empty($billing_details['zip'])) { |
|
1848 | 1848 | $address_fields .= ' ' . $billing_details['zip']; |
1849 | 1849 | } |
1850 | 1850 | |
1851 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
1851 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
1852 | 1852 | } |
1853 | 1853 | ob_start(); |
1854 | 1854 | ?> |
1855 | 1855 | <table class="table table-bordered table-sm wpi-billing-details"> |
1856 | 1856 | <tbody> |
1857 | 1857 | <tr class="wpi-receipt-name"> |
1858 | - <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th> |
|
1859 | - <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td> |
|
1858 | + <th class="text-left"><?php _e('Name', 'invoicing'); ?></th> |
|
1859 | + <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td> |
|
1860 | 1860 | </tr> |
1861 | 1861 | <tr class="wpi-receipt-email"> |
1862 | - <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th> |
|
1863 | - <td><?php echo $billing_details['email'] ;?></td> |
|
1862 | + <th class="text-left"><?php _e('Email', 'invoicing'); ?></th> |
|
1863 | + <td><?php echo $billing_details['email']; ?></td> |
|
1864 | 1864 | </tr> |
1865 | - <?php if ( $billing_details['company'] ) { ?> |
|
1865 | + <?php if ($billing_details['company']) { ?> |
|
1866 | 1866 | <tr class="wpi-receipt-company"> |
1867 | - <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th> |
|
1868 | - <td><?php echo esc_html( $billing_details['company'] ) ;?></td> |
|
1867 | + <th class="text-left"><?php _e('Company', 'invoicing'); ?></th> |
|
1868 | + <td><?php echo esc_html($billing_details['company']); ?></td> |
|
1869 | 1869 | </tr> |
1870 | 1870 | <?php } ?> |
1871 | 1871 | <tr class="wpi-receipt-address"> |
1872 | - <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th> |
|
1873 | - <td><?php echo $address_row ;?></td> |
|
1872 | + <th class="text-left"><?php _e('Address', 'invoicing'); ?></th> |
|
1873 | + <td><?php echo $address_row; ?></td> |
|
1874 | 1874 | </tr> |
1875 | - <?php if ( $billing_details['phone'] ) { ?> |
|
1875 | + <?php if ($billing_details['phone']) { ?> |
|
1876 | 1876 | <tr class="wpi-receipt-phone"> |
1877 | - <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th> |
|
1878 | - <td><?php echo esc_html( $billing_details['phone'] ) ;?></td> |
|
1877 | + <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th> |
|
1878 | + <td><?php echo esc_html($billing_details['phone']); ?></td> |
|
1879 | 1879 | </tr> |
1880 | 1880 | <?php } ?> |
1881 | 1881 | </tbody> |
@@ -1883,98 +1883,98 @@ discard block |
||
1883 | 1883 | <?php |
1884 | 1884 | $output = ob_get_clean(); |
1885 | 1885 | |
1886 | - $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id ); |
|
1886 | + $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id); |
|
1887 | 1887 | |
1888 | 1888 | echo $output; |
1889 | 1889 | } |
1890 | 1890 | |
1891 | -function wpinv_filter_success_page_content( $content ) { |
|
1892 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1893 | - if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) { |
|
1894 | - $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content ); |
|
1891 | +function wpinv_filter_success_page_content($content) { |
|
1892 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1893 | + if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) { |
|
1894 | + $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content); |
|
1895 | 1895 | } |
1896 | 1896 | } |
1897 | 1897 | |
1898 | 1898 | return $content; |
1899 | 1899 | } |
1900 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1900 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1901 | 1901 | |
1902 | -function wpinv_receipt_actions( $invoice ) { |
|
1903 | - if ( !empty( $invoice ) ) { |
|
1902 | +function wpinv_receipt_actions($invoice) { |
|
1903 | + if (!empty($invoice)) { |
|
1904 | 1904 | $actions = array( |
1905 | 1905 | 'print' => array( |
1906 | 1906 | 'url' => $invoice->get_view_url(), |
1907 | - 'name' => __( 'Print Invoice', 'invoicing' ), |
|
1907 | + 'name' => __('Print Invoice', 'invoicing'), |
|
1908 | 1908 | 'class' => 'btn-primary', |
1909 | 1909 | ), |
1910 | 1910 | 'history' => array( |
1911 | 1911 | 'url' => wpinv_get_history_page_uri(), |
1912 | - 'name' => __( 'Invoice History', 'invoicing' ), |
|
1912 | + 'name' => __('Invoice History', 'invoicing'), |
|
1913 | 1913 | 'class' => 'btn-warning', |
1914 | 1914 | ) |
1915 | 1915 | ); |
1916 | 1916 | |
1917 | - $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice ); |
|
1917 | + $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice); |
|
1918 | 1918 | |
1919 | - if ( !empty( $actions ) ) { |
|
1919 | + if (!empty($actions)) { |
|
1920 | 1920 | ?> |
1921 | 1921 | <div class="wpinv-receipt-actions text-right"> |
1922 | - <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?> |
|
1923 | - <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a> |
|
1922 | + <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?> |
|
1923 | + <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a> |
|
1924 | 1924 | <?php } ?> |
1925 | 1925 | </div> |
1926 | 1926 | <?php |
1927 | 1927 | } |
1928 | 1928 | } |
1929 | 1929 | } |
1930 | -add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 ); |
|
1930 | +add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1); |
|
1931 | 1931 | |
1932 | -function wpinv_invoice_link( $invoice_id ) { |
|
1933 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1932 | +function wpinv_invoice_link($invoice_id) { |
|
1933 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1934 | 1934 | |
1935 | - if ( empty( $invoice ) ) { |
|
1935 | + if (empty($invoice)) { |
|
1936 | 1936 | return NULL; |
1937 | 1937 | } |
1938 | 1938 | |
1939 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1939 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1940 | 1940 | |
1941 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1941 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1942 | 1942 | } |
1943 | 1943 | |
1944 | -function wpinv_invoice_subscription_details( $invoice ) { |
|
1945 | - if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) { |
|
1944 | +function wpinv_invoice_subscription_details($invoice) { |
|
1945 | + if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) { |
|
1946 | 1946 | $total_payments = (int)$invoice->get_total_payments(); |
1947 | 1947 | $payments = $invoice->get_child_payments(); |
1948 | 1948 | |
1949 | 1949 | $subscription = $invoice->get_subscription_data(); |
1950 | 1950 | |
1951 | - if ( !( !empty( $subscription ) && !empty( $subscription['item_id'] ) ) ) { |
|
1951 | + if (!(!empty($subscription) && !empty($subscription['item_id']))) { |
|
1952 | 1952 | return; |
1953 | 1953 | } |
1954 | 1954 | |
1955 | - $billing_cycle = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() ); |
|
1956 | - $times_billed = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] ); |
|
1955 | + $billing_cycle = wpinv_get_billing_cycle($subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency()); |
|
1956 | + $times_billed = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']); |
|
1957 | 1957 | |
1958 | 1958 | $subscription_status = $invoice->get_subscription_status(); |
1959 | 1959 | |
1960 | 1960 | $status_desc = ''; |
1961 | - if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) { |
|
1962 | - $status_desc = wp_sprintf( __( 'Until: %s', 'invoicing' ), $trial_end_date ); |
|
1963 | - } else if ( $subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date() ) { |
|
1964 | - $status_desc = wp_sprintf( __( 'On: %s', 'invoicing' ), $cancelled_date ); |
|
1961 | + if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) { |
|
1962 | + $status_desc = wp_sprintf(__('Until: %s', 'invoicing'), $trial_end_date); |
|
1963 | + } else if ($subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date()) { |
|
1964 | + $status_desc = wp_sprintf(__('On: %s', 'invoicing'), $cancelled_date); |
|
1965 | 1965 | } |
1966 | 1966 | $status_desc = $status_desc != '' ? '<span class="meta">' . $status_desc . '</span>' : ''; |
1967 | 1967 | ?> |
1968 | 1968 | <div class="wpinv-subscriptions-details"> |
1969 | - <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3> |
|
1969 | + <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3> |
|
1970 | 1970 | <table class="table"> |
1971 | 1971 | <thead> |
1972 | 1972 | <tr> |
1973 | - <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th> |
|
1974 | - <th><?php _e( 'Start Date', 'invoicing' ) ;?></th> |
|
1975 | - <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th> |
|
1976 | - <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th> |
|
1977 | - <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th> |
|
1973 | + <th><?php _e('Billing Cycle', 'invoicing'); ?></th> |
|
1974 | + <th><?php _e('Start Date', 'invoicing'); ?></th> |
|
1975 | + <th><?php _e('Expiration Date', 'invoicing'); ?></th> |
|
1976 | + <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th> |
|
1977 | + <th class="text-center"><?php _e('Status', 'invoicing'); ?></th> |
|
1978 | 1978 | </tr> |
1979 | 1979 | </thead> |
1980 | 1980 | <tbody> |
@@ -1983,32 +1983,32 @@ discard block |
||
1983 | 1983 | <td><?php echo $invoice->get_subscription_start(); ?></td> |
1984 | 1984 | <td><?php echo $invoice->get_subscription_end(); ?></td> |
1985 | 1985 | <td class="text-center"><?php echo $times_billed; ?></td> |
1986 | - <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label() ;?> |
|
1986 | + <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label(); ?> |
|
1987 | 1987 | <?php echo $status_desc; ?> |
1988 | 1988 | </td> |
1989 | 1989 | </tr> |
1990 | 1990 | </tbody> |
1991 | 1991 | </table> |
1992 | 1992 | </div> |
1993 | - <?php if ( !empty( $payments ) ) { ?> |
|
1993 | + <?php if (!empty($payments)) { ?> |
|
1994 | 1994 | <div class="wpinv-renewal-payments"> |
1995 | - <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3> |
|
1995 | + <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3> |
|
1996 | 1996 | <table class="table"> |
1997 | 1997 | <thead> |
1998 | 1998 | <tr> |
1999 | 1999 | <th>#</th> |
2000 | - <th><?php _e( 'Invoice', 'invoicing' ) ;?></th> |
|
2001 | - <th><?php _e( 'Date', 'invoicing' ) ;?></th> |
|
2002 | - <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th> |
|
2000 | + <th><?php _e('Invoice', 'invoicing'); ?></th> |
|
2001 | + <th><?php _e('Date', 'invoicing'); ?></th> |
|
2002 | + <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th> |
|
2003 | 2003 | </tr> |
2004 | 2004 | </thead> |
2005 | 2005 | <tbody> |
2006 | - <?php foreach ( $payments as $key => $invoice_id ) { ?> |
|
2006 | + <?php foreach ($payments as $key => $invoice_id) { ?> |
|
2007 | 2007 | <tr> |
2008 | - <th scope="row"><?php echo ( $key + 1 );?></th> |
|
2009 | - <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td> |
|
2010 | - <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td> |
|
2011 | - <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td> |
|
2008 | + <th scope="row"><?php echo ($key + 1); ?></th> |
|
2009 | + <td><?php echo wpinv_invoice_link($invoice_id); ?></td> |
|
2010 | + <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td> |
|
2011 | + <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td> |
|
2012 | 2012 | </tr> |
2013 | 2013 | <?php } ?> |
2014 | 2014 | <tr><td colspan="4" style="padding:0"></td></tr> |
@@ -2020,52 +2020,52 @@ discard block |
||
2020 | 2020 | } |
2021 | 2021 | } |
2022 | 2022 | |
2023 | -function wpinv_cart_total_label( $label, $invoice ) { |
|
2024 | - if ( empty( $invoice ) ) { |
|
2023 | +function wpinv_cart_total_label($label, $invoice) { |
|
2024 | + if (empty($invoice)) { |
|
2025 | 2025 | return $label; |
2026 | 2026 | } |
2027 | 2027 | |
2028 | 2028 | $prefix_label = ''; |
2029 | - if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) { |
|
2030 | - $prefix_label = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice ); |
|
2031 | - } else if ( $invoice->is_renewal() ) { |
|
2032 | - $prefix_label = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> '; |
|
2029 | + if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) { |
|
2030 | + $prefix_label = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice); |
|
2031 | + } else if ($invoice->is_renewal()) { |
|
2032 | + $prefix_label = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> '; |
|
2033 | 2033 | } |
2034 | 2034 | |
2035 | - if ( $prefix_label != '' ) { |
|
2036 | - $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
2035 | + if ($prefix_label != '') { |
|
2036 | + $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
2037 | 2037 | } |
2038 | 2038 | |
2039 | 2039 | return $label; |
2040 | 2040 | } |
2041 | -add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2042 | -add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2043 | -add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2041 | +add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2042 | +add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2043 | +add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2044 | 2044 | |
2045 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 ); |
|
2045 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1); |
|
2046 | 2046 | |
2047 | -function wpinv_invoice_print_description( $invoice ) { |
|
2048 | - if ( empty( $invoice ) ) { |
|
2047 | +function wpinv_invoice_print_description($invoice) { |
|
2048 | + if (empty($invoice)) { |
|
2049 | 2049 | return NULL; |
2050 | 2050 | } |
2051 | - if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) { |
|
2051 | + if ($description = wpinv_get_invoice_description($invoice->ID)) { |
|
2052 | 2052 | ?> |
2053 | 2053 | <div class="row wpinv-lower"> |
2054 | 2054 | <div class="col-sm-12 wpinv-description"> |
2055 | - <?php echo wpautop( $description ); ?> |
|
2055 | + <?php echo wpautop($description); ?> |
|
2056 | 2056 | </div> |
2057 | 2057 | </div> |
2058 | 2058 | <?php |
2059 | 2059 | } |
2060 | 2060 | } |
2061 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 ); |
|
2061 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1); |
|
2062 | 2062 | |
2063 | -function wpinv_invoice_print_payment_info( $invoice ) { |
|
2064 | - if ( empty( $invoice ) ) { |
|
2063 | +function wpinv_invoice_print_payment_info($invoice) { |
|
2064 | + if (empty($invoice)) { |
|
2065 | 2065 | return NULL; |
2066 | 2066 | } |
2067 | 2067 | |
2068 | - if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) { |
|
2068 | + if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) { |
|
2069 | 2069 | ?> |
2070 | 2070 | <div class="row wpinv-payments"> |
2071 | 2071 | <div class="col-sm-12"> |
@@ -2077,40 +2077,40 @@ discard block |
||
2077 | 2077 | } |
2078 | 2078 | // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 ); |
2079 | 2079 | |
2080 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
2081 | - if ( empty( $note ) ) { |
|
2080 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
2081 | + if (empty($note)) { |
|
2082 | 2082 | return NULL; |
2083 | 2083 | } |
2084 | 2084 | |
2085 | - if ( is_int( $note ) ) { |
|
2086 | - $note = get_comment( $note ); |
|
2085 | + if (is_int($note)) { |
|
2086 | + $note = get_comment($note); |
|
2087 | 2087 | } |
2088 | 2088 | |
2089 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
2089 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
2090 | 2090 | return NULL; |
2091 | 2091 | } |
2092 | 2092 | |
2093 | - $note_classes = array( 'note' ); |
|
2094 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
2095 | - $note_classes[] = $note->comment_author === __( 'GeoDirectory', 'invoicing' ) ? 'system-note' : ''; |
|
2096 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
2097 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
2093 | + $note_classes = array('note'); |
|
2094 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
2095 | + $note_classes[] = $note->comment_author === __('GeoDirectory', 'invoicing') ? 'system-note' : ''; |
|
2096 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
2097 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
2098 | 2098 | |
2099 | 2099 | ob_start(); |
2100 | 2100 | ?> |
2101 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>"> |
|
2101 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>"> |
|
2102 | 2102 | <div class="note_content"> |
2103 | - <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?> |
|
2103 | + <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?> |
|
2104 | 2104 | </div> |
2105 | 2105 | <p class="meta"> |
2106 | - <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr> <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
2106 | + <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr> <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
2107 | 2107 | </p> |
2108 | 2108 | </li> |
2109 | 2109 | <?php |
2110 | 2110 | $note_content = ob_get_clean(); |
2111 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
2111 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
2112 | 2112 | |
2113 | - if ( $echo ) { |
|
2113 | + if ($echo) { |
|
2114 | 2114 | echo $note_content; |
2115 | 2115 | } else { |
2116 | 2116 | return $note_content; |
@@ -7,112 +7,112 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_item_quantities_enabled() { |
15 | - $ret = wpinv_get_option( 'item_quantities', true ); |
|
15 | + $ret = wpinv_get_option('item_quantities', true); |
|
16 | 16 | |
17 | - return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret ); |
|
17 | + return (bool)apply_filters('wpinv_item_quantities_enabled', $ret); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | function wpinv_get_ip() { |
21 | 21 | $ip = '127.0.0.1'; |
22 | 22 | |
23 | - if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { |
|
24 | - $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] ); |
|
25 | - } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
|
26 | - $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] ); |
|
27 | - } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) { |
|
28 | - $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] ); |
|
23 | + if (!empty($_SERVER['HTTP_CLIENT_IP'])) { |
|
24 | + $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']); |
|
25 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
26 | + $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']); |
|
27 | + } elseif (!empty($_SERVER['REMOTE_ADDR'])) { |
|
28 | + $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']); |
|
29 | 29 | } |
30 | 30 | |
31 | - return apply_filters( 'wpinv_get_ip', $ip ); |
|
31 | + return apply_filters('wpinv_get_ip', $ip); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | function wpinv_get_user_agent() { |
35 | - if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
|
36 | - $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ); |
|
35 | + if (!empty($_SERVER['HTTP_USER_AGENT'])) { |
|
36 | + $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']); |
|
37 | 37 | } else { |
38 | 38 | $user_agent = ''; |
39 | 39 | } |
40 | 40 | |
41 | - return apply_filters( 'wpinv_get_user_agent', $user_agent ); |
|
41 | + return apply_filters('wpinv_get_user_agent', $user_agent); |
|
42 | 42 | } |
43 | 43 | |
44 | -function wpinv_sanitize_amount( $amount ) { |
|
44 | +function wpinv_sanitize_amount($amount) { |
|
45 | 45 | $is_negative = false; |
46 | 46 | $thousands_sep = wpinv_thousands_seperator(); |
47 | 47 | $decimal_sep = wpinv_decimal_seperator(); |
48 | 48 | |
49 | 49 | // Sanitize the amount |
50 | - if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) { |
|
51 | - if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
52 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
53 | - } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) { |
|
54 | - $amount = str_replace( '.', '', $amount ); |
|
50 | + if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) { |
|
51 | + if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) { |
|
52 | + $amount = str_replace($thousands_sep, '', $amount); |
|
53 | + } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) { |
|
54 | + $amount = str_replace('.', '', $amount); |
|
55 | 55 | } |
56 | 56 | |
57 | - $amount = str_replace( $decimal_sep, '.', $amount ); |
|
58 | - } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
59 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
57 | + $amount = str_replace($decimal_sep, '.', $amount); |
|
58 | + } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
59 | + $amount = str_replace($thousands_sep, '', $amount); |
|
60 | 60 | } |
61 | 61 | |
62 | - if( $amount < 0 ) { |
|
62 | + if ($amount < 0) { |
|
63 | 63 | $is_negative = true; |
64 | 64 | } |
65 | 65 | |
66 | - $amount = preg_replace( '/[^0-9\.]/', '', $amount ); |
|
66 | + $amount = preg_replace('/[^0-9\.]/', '', $amount); |
|
67 | 67 | |
68 | - $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', 2, $amount ); |
|
69 | - $amount = number_format( (double) $amount, $decimals, '.', '' ); |
|
68 | + $decimals = apply_filters('wpinv_sanitize_amount_decimals', 2, $amount); |
|
69 | + $amount = number_format((double)$amount, $decimals, '.', ''); |
|
70 | 70 | |
71 | - if( $is_negative ) { |
|
71 | + if ($is_negative) { |
|
72 | 72 | $amount *= -1; |
73 | 73 | } |
74 | 74 | |
75 | - return apply_filters( 'wpinv_sanitize_amount', $amount ); |
|
75 | + return apply_filters('wpinv_sanitize_amount', $amount); |
|
76 | 76 | } |
77 | 77 | |
78 | -function wpinv_get_invoice_statuses( $trashed = false ) { |
|
78 | +function wpinv_get_invoice_statuses($trashed = false) { |
|
79 | 79 | $invoice_statuses = array( |
80 | - 'pending' => __( 'Pending Payment', 'invoicing' ), |
|
81 | - 'publish' => __( 'Paid', 'invoicing' ), |
|
82 | - 'wpi-processing' => __( 'Processing', 'invoicing' ), |
|
83 | - 'wpi-onhold' => __( 'On Hold', 'invoicing' ), |
|
84 | - 'wpi-refunded' => __( 'Refunded', 'invoicing' ), |
|
85 | - 'wpi-cancelled' => __( 'Cancelled', 'invoicing' ), |
|
86 | - 'wpi-failed' => __( 'Failed', 'invoicing' ), |
|
87 | - 'wpi-renewal' => __( 'Renewal Payment', 'invoicing' ) |
|
80 | + 'pending' => __('Pending Payment', 'invoicing'), |
|
81 | + 'publish' => __('Paid', 'invoicing'), |
|
82 | + 'wpi-processing' => __('Processing', 'invoicing'), |
|
83 | + 'wpi-onhold' => __('On Hold', 'invoicing'), |
|
84 | + 'wpi-refunded' => __('Refunded', 'invoicing'), |
|
85 | + 'wpi-cancelled' => __('Cancelled', 'invoicing'), |
|
86 | + 'wpi-failed' => __('Failed', 'invoicing'), |
|
87 | + 'wpi-renewal' => __('Renewal Payment', 'invoicing') |
|
88 | 88 | ); |
89 | 89 | |
90 | - if ( $trashed ) { |
|
91 | - $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
|
90 | + if ($trashed) { |
|
91 | + $invoice_statuses['trash'] = __('Trash', 'invoicing'); |
|
92 | 92 | } |
93 | 93 | |
94 | - return apply_filters( 'wpinv_statuses', $invoice_statuses ); |
|
94 | + return apply_filters('wpinv_statuses', $invoice_statuses); |
|
95 | 95 | } |
96 | 96 | |
97 | -function wpinv_status_nicename( $status ) { |
|
97 | +function wpinv_status_nicename($status) { |
|
98 | 98 | $statuses = wpinv_get_invoice_statuses(); |
99 | - $status = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' ); |
|
99 | + $status = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing'); |
|
100 | 100 | |
101 | 101 | return $status; |
102 | 102 | } |
103 | 103 | |
104 | 104 | function wpinv_get_currency() { |
105 | - $currency = wpinv_get_option( 'currency', 'USD' ); |
|
105 | + $currency = wpinv_get_option('currency', 'USD'); |
|
106 | 106 | |
107 | - return apply_filters( 'wpinv_currency', $currency ); |
|
107 | + return apply_filters('wpinv_currency', $currency); |
|
108 | 108 | } |
109 | 109 | |
110 | -function wpinv_currency_symbol( $currency = '' ) { |
|
111 | - if ( empty( $currency ) ) { |
|
110 | +function wpinv_currency_symbol($currency = '') { |
|
111 | + if (empty($currency)) { |
|
112 | 112 | $currency = wpinv_get_currency(); |
113 | 113 | } |
114 | 114 | |
115 | - $symbols = apply_filters( 'wpinv_currency_symbols', array( |
|
115 | + $symbols = apply_filters('wpinv_currency_symbols', array( |
|
116 | 116 | 'AED' => 'د.إ', |
117 | 117 | 'ARS' => '$', |
118 | 118 | 'AUD' => '$', |
@@ -164,78 +164,78 @@ discard block |
||
164 | 164 | 'USD' => '$', |
165 | 165 | 'VND' => '₫', |
166 | 166 | 'ZAR' => 'R', |
167 | - ) ); |
|
167 | + )); |
|
168 | 168 | |
169 | - $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : '$'; |
|
169 | + $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : '$'; |
|
170 | 170 | |
171 | - return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
|
171 | + return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | function wpinv_currency_position() { |
175 | - $position = wpinv_get_option( 'currency_position', 'left' ); |
|
175 | + $position = wpinv_get_option('currency_position', 'left'); |
|
176 | 176 | |
177 | - return apply_filters( 'wpinv_currency_position', $position ); |
|
177 | + return apply_filters('wpinv_currency_position', $position); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | function wpinv_thousands_seperator() { |
181 | - $thousand_sep = wpinv_get_option( 'thousands_seperator', ',' ); |
|
181 | + $thousand_sep = wpinv_get_option('thousands_seperator', ','); |
|
182 | 182 | |
183 | - return apply_filters( 'wpinv_thousands_seperator', $thousand_sep ); |
|
183 | + return apply_filters('wpinv_thousands_seperator', $thousand_sep); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | function wpinv_decimal_seperator() { |
187 | - $decimal_sep = wpinv_get_option( 'decimal_seperator', '.' ); |
|
187 | + $decimal_sep = wpinv_get_option('decimal_seperator', '.'); |
|
188 | 188 | |
189 | - return apply_filters( 'wpinv_decimal_seperator', $decimal_sep ); |
|
189 | + return apply_filters('wpinv_decimal_seperator', $decimal_sep); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | function wpinv_decimals() { |
193 | - $decimals = wpinv_get_option( 'decimals', 2 ); |
|
193 | + $decimals = wpinv_get_option('decimals', 2); |
|
194 | 194 | |
195 | - return apply_filters( 'wpinv_decimals', $decimals ); |
|
195 | + return apply_filters('wpinv_decimals', $decimals); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | function wpinv_get_currencies() { |
199 | 199 | $currencies = array( |
200 | - 'USD' => __( 'US Dollars ($)', 'invoicing' ), |
|
201 | - 'EUR' => __( 'Euros (€)', 'invoicing' ), |
|
202 | - 'GBP' => __( 'Pounds Sterling (£)', 'invoicing' ), |
|
203 | - 'AUD' => __( 'Australian Dollars ($)', 'invoicing' ), |
|
204 | - 'BRL' => __( 'Brazilian Real (R$)', 'invoicing' ), |
|
205 | - 'CAD' => __( 'Canadian Dollars ($)', 'invoicing' ), |
|
206 | - 'CLP' => __( 'Chilean Peso ($)', 'invoicing' ), |
|
207 | - 'CNY' => __( 'Chinese Yuan (¥)', 'invoicing' ), |
|
208 | - 'CZK' => __( 'Czech Koruna (Kč)', 'invoicing' ), |
|
209 | - 'DKK' => __( 'Danish Krone (DKK)', 'invoicing' ), |
|
210 | - 'HKD' => __( 'Hong Kong Dollar ($)', 'invoicing' ), |
|
211 | - 'HUF' => __( 'Hungarian Forint (Ft)', 'invoicing' ), |
|
212 | - 'INR' => __( 'Indian Rupee (₹)', 'invoicing' ), |
|
213 | - 'ILS' => __( 'Israeli Shekel (₪)', 'invoicing' ), |
|
214 | - 'JPY' => __( 'Japanese Yen (¥)', 'invoicing' ), |
|
215 | - 'MYR' => __( 'Malaysian Ringgit (RM)', 'invoicing' ), |
|
216 | - 'MXN' => __( 'Mexican Peso ($)', 'invoicing' ), |
|
217 | - 'NZD' => __( 'New Zealand Dollar ($)', 'invoicing' ), |
|
218 | - 'NOK' => __( 'Norwegian Krone (kr)', 'invoicing' ), |
|
219 | - 'PHP' => __( 'Philippine Peso (₱)', 'invoicing' ), |
|
220 | - 'PLN' => __( 'Polish Zloty (zł)', 'invoicing' ), |
|
221 | - 'SGD' => __( 'Singapore Dollar ($)', 'invoicing' ), |
|
222 | - 'SEK' => __( 'Swedish Krona (kr)', 'invoicing' ), |
|
223 | - 'CHF' => __( 'Swiss Franc (CHF)', 'invoicing' ), |
|
224 | - 'TWD' => __( 'Taiwan New Dollar (NT$)', 'invoicing' ), |
|
225 | - 'THB' => __( 'Thai Baht (฿)', 'invoicing' ), |
|
226 | - 'TRY' => __( 'Turkish Lira (₺)', 'invoicing' ), |
|
227 | - 'RIAL' => __( 'Iranian Rial (﷼)', 'invoicing' ), |
|
228 | - 'RUB' => __( 'Russian Ruble (₽)', 'invoicing' ), |
|
229 | - 'ZAR' => __( 'South African Rand (R)', 'invoicing' ) |
|
200 | + 'USD' => __('US Dollars ($)', 'invoicing'), |
|
201 | + 'EUR' => __('Euros (€)', 'invoicing'), |
|
202 | + 'GBP' => __('Pounds Sterling (£)', 'invoicing'), |
|
203 | + 'AUD' => __('Australian Dollars ($)', 'invoicing'), |
|
204 | + 'BRL' => __('Brazilian Real (R$)', 'invoicing'), |
|
205 | + 'CAD' => __('Canadian Dollars ($)', 'invoicing'), |
|
206 | + 'CLP' => __('Chilean Peso ($)', 'invoicing'), |
|
207 | + 'CNY' => __('Chinese Yuan (¥)', 'invoicing'), |
|
208 | + 'CZK' => __('Czech Koruna (Kč)', 'invoicing'), |
|
209 | + 'DKK' => __('Danish Krone (DKK)', 'invoicing'), |
|
210 | + 'HKD' => __('Hong Kong Dollar ($)', 'invoicing'), |
|
211 | + 'HUF' => __('Hungarian Forint (Ft)', 'invoicing'), |
|
212 | + 'INR' => __('Indian Rupee (₹)', 'invoicing'), |
|
213 | + 'ILS' => __('Israeli Shekel (₪)', 'invoicing'), |
|
214 | + 'JPY' => __('Japanese Yen (¥)', 'invoicing'), |
|
215 | + 'MYR' => __('Malaysian Ringgit (RM)', 'invoicing'), |
|
216 | + 'MXN' => __('Mexican Peso ($)', 'invoicing'), |
|
217 | + 'NZD' => __('New Zealand Dollar ($)', 'invoicing'), |
|
218 | + 'NOK' => __('Norwegian Krone (kr)', 'invoicing'), |
|
219 | + 'PHP' => __('Philippine Peso (₱)', 'invoicing'), |
|
220 | + 'PLN' => __('Polish Zloty (zł)', 'invoicing'), |
|
221 | + 'SGD' => __('Singapore Dollar ($)', 'invoicing'), |
|
222 | + 'SEK' => __('Swedish Krona (kr)', 'invoicing'), |
|
223 | + 'CHF' => __('Swiss Franc (CHF)', 'invoicing'), |
|
224 | + 'TWD' => __('Taiwan New Dollar (NT$)', 'invoicing'), |
|
225 | + 'THB' => __('Thai Baht (฿)', 'invoicing'), |
|
226 | + 'TRY' => __('Turkish Lira (₺)', 'invoicing'), |
|
227 | + 'RIAL' => __('Iranian Rial (﷼)', 'invoicing'), |
|
228 | + 'RUB' => __('Russian Ruble (₽)', 'invoicing'), |
|
229 | + 'ZAR' => __('South African Rand (R)', 'invoicing') |
|
230 | 230 | ); |
231 | 231 | |
232 | - asort( $currencies ); |
|
232 | + asort($currencies); |
|
233 | 233 | |
234 | - return apply_filters( 'wpinv_currencies', $currencies ); |
|
234 | + return apply_filters('wpinv_currencies', $currencies); |
|
235 | 235 | } |
236 | 236 | |
237 | -function wpinv_price( $amount = '', $currency = '' ) { |
|
238 | - if( empty( $currency ) ) { |
|
237 | +function wpinv_price($amount = '', $currency = '') { |
|
238 | + if (empty($currency)) { |
|
239 | 239 | $currency = wpinv_get_currency(); |
240 | 240 | } |
241 | 241 | |
@@ -243,14 +243,14 @@ discard block |
||
243 | 243 | |
244 | 244 | $negative = $amount < 0; |
245 | 245 | |
246 | - if ( $negative ) { |
|
247 | - $amount = substr( $amount, 1 ); |
|
246 | + if ($negative) { |
|
247 | + $amount = substr($amount, 1); |
|
248 | 248 | } |
249 | 249 | |
250 | - $symbol = wpinv_currency_symbol( $currency ); |
|
250 | + $symbol = wpinv_currency_symbol($currency); |
|
251 | 251 | |
252 | - if ( $position == 'left' || $position == 'left_space' ) { |
|
253 | - switch ( $currency ) { |
|
252 | + if ($position == 'left' || $position == 'left_space') { |
|
253 | + switch ($currency) { |
|
254 | 254 | case "GBP" : |
255 | 255 | case "BRL" : |
256 | 256 | case "EUR" : |
@@ -262,15 +262,15 @@ discard block |
||
262 | 262 | case "NZD" : |
263 | 263 | case "SGD" : |
264 | 264 | case "JPY" : |
265 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
265 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
266 | 266 | break; |
267 | 267 | default : |
268 | 268 | //$price = $currency . ' ' . $amount; |
269 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
269 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
270 | 270 | break; |
271 | 271 | } |
272 | 272 | } else { |
273 | - switch ( $currency ) { |
|
273 | + switch ($currency) { |
|
274 | 274 | case "GBP" : |
275 | 275 | case "BRL" : |
276 | 276 | case "EUR" : |
@@ -281,82 +281,82 @@ discard block |
||
281 | 281 | case "MXN" : |
282 | 282 | case "SGD" : |
283 | 283 | case "JPY" : |
284 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
284 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
285 | 285 | break; |
286 | 286 | default : |
287 | 287 | //$price = $amount . ' ' . $currency; |
288 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
288 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
289 | 289 | break; |
290 | 290 | } |
291 | 291 | } |
292 | 292 | |
293 | - if ( $negative ) { |
|
293 | + if ($negative) { |
|
294 | 294 | $price = '-' . $price; |
295 | 295 | } |
296 | 296 | |
297 | - $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount ); |
|
297 | + $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount); |
|
298 | 298 | |
299 | 299 | return $price; |
300 | 300 | } |
301 | 301 | |
302 | -function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) { |
|
302 | +function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) { |
|
303 | 303 | $thousands_sep = wpinv_thousands_seperator(); |
304 | 304 | $decimal_sep = wpinv_decimal_seperator(); |
305 | 305 | |
306 | - if ( $decimals === NULL ) { |
|
306 | + if ($decimals === NULL) { |
|
307 | 307 | $decimals = wpinv_decimals(); |
308 | 308 | } |
309 | 309 | |
310 | - if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) { |
|
311 | - $whole = substr( $amount, 0, $sep_found ); |
|
312 | - $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) ); |
|
310 | + if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) { |
|
311 | + $whole = substr($amount, 0, $sep_found); |
|
312 | + $part = substr($amount, $sep_found + 1, (strlen($amount) - 1)); |
|
313 | 313 | $amount = $whole . '.' . $part; |
314 | 314 | } |
315 | 315 | |
316 | - if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
317 | - $amount = str_replace( ',', '', $amount ); |
|
316 | + if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
317 | + $amount = str_replace(',', '', $amount); |
|
318 | 318 | } |
319 | 319 | |
320 | - if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
321 | - $amount = str_replace( ' ', '', $amount ); |
|
320 | + if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
321 | + $amount = str_replace(' ', '', $amount); |
|
322 | 322 | } |
323 | 323 | |
324 | - if ( empty( $amount ) ) { |
|
324 | + if (empty($amount)) { |
|
325 | 325 | $amount = 0; |
326 | 326 | } |
327 | 327 | |
328 | - $decimals = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate ); |
|
329 | - $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep ); |
|
328 | + $decimals = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate); |
|
329 | + $formatted = number_format((float)$amount, $decimals, $decimal_sep, $thousands_sep); |
|
330 | 330 | |
331 | - if ( $calculate ) { |
|
332 | - if ( $thousands_sep === "," ) { |
|
333 | - $formatted = str_replace( ",", "", $formatted ); |
|
331 | + if ($calculate) { |
|
332 | + if ($thousands_sep === ",") { |
|
333 | + $formatted = str_replace(",", "", $formatted); |
|
334 | 334 | } |
335 | 335 | |
336 | - if ( $decimal_sep === "," ) { |
|
337 | - $formatted = str_replace( ",", ".", $formatted ); |
|
336 | + if ($decimal_sep === ",") { |
|
337 | + $formatted = str_replace(",", ".", $formatted); |
|
338 | 338 | } |
339 | 339 | } |
340 | 340 | |
341 | - return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate ); |
|
341 | + return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate); |
|
342 | 342 | } |
343 | 343 | |
344 | -function wpinv_sanitize_key( $key ) { |
|
344 | +function wpinv_sanitize_key($key) { |
|
345 | 345 | $raw_key = $key; |
346 | - $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key ); |
|
346 | + $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key); |
|
347 | 347 | |
348 | - return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
|
348 | + return apply_filters('wpinv_sanitize_key', $key, $raw_key); |
|
349 | 349 | } |
350 | 350 | |
351 | -function wpinv_get_file_extension( $str ) { |
|
352 | - $parts = explode( '.', $str ); |
|
353 | - return end( $parts ); |
|
351 | +function wpinv_get_file_extension($str) { |
|
352 | + $parts = explode('.', $str); |
|
353 | + return end($parts); |
|
354 | 354 | } |
355 | 355 | |
356 | -function wpinv_string_is_image_url( $str ) { |
|
357 | - $ext = wpinv_get_file_extension( $str ); |
|
356 | +function wpinv_string_is_image_url($str) { |
|
357 | + $ext = wpinv_get_file_extension($str); |
|
358 | 358 | |
359 | - switch ( strtolower( $ext ) ) { |
|
359 | + switch (strtolower($ext)) { |
|
360 | 360 | case 'jpeg'; |
361 | 361 | case 'jpg'; |
362 | 362 | $return = true; |
@@ -372,32 +372,32 @@ discard block |
||
372 | 372 | break; |
373 | 373 | } |
374 | 374 | |
375 | - return (bool)apply_filters( 'wpinv_string_is_image', $return, $str ); |
|
375 | + return (bool)apply_filters('wpinv_string_is_image', $return, $str); |
|
376 | 376 | } |
377 | 377 | |
378 | -function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) { |
|
379 | - $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG ); |
|
378 | +function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) { |
|
379 | + $should_log = apply_filters('wpinv_log_errors', WP_DEBUG); |
|
380 | 380 | |
381 | - if ( true === $should_log ) { |
|
381 | + if (true === $should_log) { |
|
382 | 382 | $label = ''; |
383 | - if ( $file && $file !== '' ) { |
|
384 | - $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' ); |
|
383 | + if ($file && $file !== '') { |
|
384 | + $label .= basename($file) . ($line ? '(' . $line . ')' : ''); |
|
385 | 385 | } |
386 | 386 | |
387 | - if ( $title && $title !== '' ) { |
|
387 | + if ($title && $title !== '') { |
|
388 | 388 | $label = $label !== '' ? $label . ' ' : ''; |
389 | 389 | $label .= $title . ' '; |
390 | 390 | } |
391 | 391 | |
392 | - $label = $label !== '' ? trim( $label ) . ' : ' : ''; |
|
392 | + $label = $label !== '' ? trim($label) . ' : ' : ''; |
|
393 | 393 | |
394 | - if ( is_array( $log ) || is_object( $log ) ) { |
|
395 | - error_log( $label . print_r( $log, true ) ); |
|
394 | + if (is_array($log) || is_object($log)) { |
|
395 | + error_log($label . print_r($log, true)); |
|
396 | 396 | } else { |
397 | - error_log( $label . $log ); |
|
397 | + error_log($label . $log); |
|
398 | 398 | } |
399 | 399 | |
400 | - if ( $exit ) { |
|
400 | + if ($exit) { |
|
401 | 401 | exit; |
402 | 402 | } |
403 | 403 | } |
@@ -405,65 +405,65 @@ discard block |
||
405 | 405 | |
406 | 406 | function wpinv_is_ajax_disabled() { |
407 | 407 | $retval = false; |
408 | - return apply_filters( 'wpinv_is_ajax_disabled', $retval ); |
|
408 | + return apply_filters('wpinv_is_ajax_disabled', $retval); |
|
409 | 409 | } |
410 | 410 | |
411 | -function wpinv_get_current_page_url( $nocache = false ) { |
|
411 | +function wpinv_get_current_page_url($nocache = false) { |
|
412 | 412 | global $wp; |
413 | 413 | |
414 | - if ( get_option( 'permalink_structure' ) ) { |
|
415 | - $base = trailingslashit( home_url( $wp->request ) ); |
|
414 | + if (get_option('permalink_structure')) { |
|
415 | + $base = trailingslashit(home_url($wp->request)); |
|
416 | 416 | } else { |
417 | - $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) ); |
|
418 | - $base = remove_query_arg( array( 'post_type', 'name' ), $base ); |
|
417 | + $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request))); |
|
418 | + $base = remove_query_arg(array('post_type', 'name'), $base); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | $scheme = is_ssl() ? 'https' : 'http'; |
422 | - $uri = set_url_scheme( $base, $scheme ); |
|
422 | + $uri = set_url_scheme($base, $scheme); |
|
423 | 423 | |
424 | - if ( is_front_page() ) { |
|
425 | - $uri = home_url( '/' ); |
|
426 | - } elseif ( wpinv_is_checkout( array(), false ) ) { |
|
424 | + if (is_front_page()) { |
|
425 | + $uri = home_url('/'); |
|
426 | + } elseif (wpinv_is_checkout(array(), false)) { |
|
427 | 427 | $uri = wpinv_get_checkout_uri(); |
428 | 428 | } |
429 | 429 | |
430 | - $uri = apply_filters( 'wpinv_get_current_page_url', $uri ); |
|
430 | + $uri = apply_filters('wpinv_get_current_page_url', $uri); |
|
431 | 431 | |
432 | - if ( $nocache ) { |
|
433 | - $uri = wpinv_add_cache_busting( $uri ); |
|
432 | + if ($nocache) { |
|
433 | + $uri = wpinv_add_cache_busting($uri); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | return $uri; |
437 | 437 | } |
438 | 438 | |
439 | 439 | function wpinv_get_php_arg_separator_output() { |
440 | - return ini_get( 'arg_separator.output' ); |
|
440 | + return ini_get('arg_separator.output'); |
|
441 | 441 | } |
442 | 442 | |
443 | -function wpinv_rgb_from_hex( $color ) { |
|
444 | - $color = str_replace( '#', '', $color ); |
|
443 | +function wpinv_rgb_from_hex($color) { |
|
444 | + $color = str_replace('#', '', $color); |
|
445 | 445 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
446 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
|
446 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); |
|
447 | 447 | |
448 | 448 | $rgb = array(); |
449 | - $rgb['R'] = hexdec( $color{0}.$color{1} ); |
|
450 | - $rgb['G'] = hexdec( $color{2}.$color{3} ); |
|
451 | - $rgb['B'] = hexdec( $color{4}.$color{5} ); |
|
449 | + $rgb['R'] = hexdec($color{0} . $color{1} ); |
|
450 | + $rgb['G'] = hexdec($color{2} . $color{3} ); |
|
451 | + $rgb['B'] = hexdec($color{4} . $color{5} ); |
|
452 | 452 | |
453 | 453 | return $rgb; |
454 | 454 | } |
455 | 455 | |
456 | -function wpinv_hex_darker( $color, $factor = 30 ) { |
|
457 | - $base = wpinv_rgb_from_hex( $color ); |
|
456 | +function wpinv_hex_darker($color, $factor = 30) { |
|
457 | + $base = wpinv_rgb_from_hex($color); |
|
458 | 458 | $color = '#'; |
459 | 459 | |
460 | - foreach ( $base as $k => $v ) { |
|
460 | + foreach ($base as $k => $v) { |
|
461 | 461 | $amount = $v / 100; |
462 | - $amount = round( $amount * $factor ); |
|
462 | + $amount = round($amount * $factor); |
|
463 | 463 | $new_decimal = $v - $amount; |
464 | 464 | |
465 | - $new_hex_component = dechex( $new_decimal ); |
|
466 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
465 | + $new_hex_component = dechex($new_decimal); |
|
466 | + if (strlen($new_hex_component) < 2) { |
|
467 | 467 | $new_hex_component = "0" . $new_hex_component; |
468 | 468 | } |
469 | 469 | $color .= $new_hex_component; |
@@ -472,18 +472,18 @@ discard block |
||
472 | 472 | return $color; |
473 | 473 | } |
474 | 474 | |
475 | -function wpinv_hex_lighter( $color, $factor = 30 ) { |
|
476 | - $base = wpinv_rgb_from_hex( $color ); |
|
475 | +function wpinv_hex_lighter($color, $factor = 30) { |
|
476 | + $base = wpinv_rgb_from_hex($color); |
|
477 | 477 | $color = '#'; |
478 | 478 | |
479 | - foreach ( $base as $k => $v ) { |
|
479 | + foreach ($base as $k => $v) { |
|
480 | 480 | $amount = 255 - $v; |
481 | 481 | $amount = $amount / 100; |
482 | - $amount = round( $amount * $factor ); |
|
482 | + $amount = round($amount * $factor); |
|
483 | 483 | $new_decimal = $v + $amount; |
484 | 484 | |
485 | - $new_hex_component = dechex( $new_decimal ); |
|
486 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
485 | + $new_hex_component = dechex($new_decimal); |
|
486 | + if (strlen($new_hex_component) < 2) { |
|
487 | 487 | $new_hex_component = "0" . $new_hex_component; |
488 | 488 | } |
489 | 489 | $color .= $new_hex_component; |
@@ -492,22 +492,22 @@ discard block |
||
492 | 492 | return $color; |
493 | 493 | } |
494 | 494 | |
495 | -function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
|
496 | - $hex = str_replace( '#', '', $color ); |
|
495 | +function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { |
|
496 | + $hex = str_replace('#', '', $color); |
|
497 | 497 | |
498 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); |
|
499 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); |
|
500 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); |
|
498 | + $c_r = hexdec(substr($hex, 0, 2)); |
|
499 | + $c_g = hexdec(substr($hex, 2, 2)); |
|
500 | + $c_b = hexdec(substr($hex, 4, 2)); |
|
501 | 501 | |
502 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
|
502 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; |
|
503 | 503 | |
504 | 504 | return $brightness > 155 ? $dark : $light; |
505 | 505 | } |
506 | 506 | |
507 | -function wpinv_format_hex( $hex ) { |
|
508 | - $hex = trim( str_replace( '#', '', $hex ) ); |
|
507 | +function wpinv_format_hex($hex) { |
|
508 | + $hex = trim(str_replace('#', '', $hex)); |
|
509 | 509 | |
510 | - if ( strlen( $hex ) == 3 ) { |
|
510 | + if (strlen($hex) == 3) { |
|
511 | 511 | $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
512 | 512 | } |
513 | 513 | |
@@ -527,12 +527,12 @@ discard block |
||
527 | 527 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
528 | 528 | * @return string |
529 | 529 | */ |
530 | -function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) { |
|
531 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
532 | - return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding ); |
|
530 | +function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') { |
|
531 | + if (function_exists('mb_strimwidth')) { |
|
532 | + return mb_strimwidth($str, $start, $width, $trimmaker, $encoding); |
|
533 | 533 | } |
534 | 534 | |
535 | - return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker; |
|
535 | + return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker; |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | /** |
@@ -544,28 +544,28 @@ discard block |
||
544 | 544 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
545 | 545 | * @return int Returns the number of characters in string. |
546 | 546 | */ |
547 | -function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) { |
|
548 | - if ( function_exists( 'mb_strlen' ) ) { |
|
549 | - return mb_strlen( $str, $encoding ); |
|
547 | +function wpinv_utf8_strlen($str, $encoding = 'UTF-8') { |
|
548 | + if (function_exists('mb_strlen')) { |
|
549 | + return mb_strlen($str, $encoding); |
|
550 | 550 | } |
551 | 551 | |
552 | - return strlen( $str ); |
|
552 | + return strlen($str); |
|
553 | 553 | } |
554 | 554 | |
555 | -function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
|
556 | - if ( function_exists( 'mb_strtolower' ) ) { |
|
557 | - return mb_strtolower( $str, $encoding ); |
|
555 | +function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') { |
|
556 | + if (function_exists('mb_strtolower')) { |
|
557 | + return mb_strtolower($str, $encoding); |
|
558 | 558 | } |
559 | 559 | |
560 | - return strtolower( $str ); |
|
560 | + return strtolower($str); |
|
561 | 561 | } |
562 | 562 | |
563 | -function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
|
564 | - if ( function_exists( 'mb_strtoupper' ) ) { |
|
565 | - return mb_strtoupper( $str, $encoding ); |
|
563 | +function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') { |
|
564 | + if (function_exists('mb_strtoupper')) { |
|
565 | + return mb_strtoupper($str, $encoding); |
|
566 | 566 | } |
567 | 567 | |
568 | - return strtoupper( $str ); |
|
568 | + return strtoupper($str); |
|
569 | 569 | } |
570 | 570 | |
571 | 571 | /** |
@@ -579,12 +579,12 @@ discard block |
||
579 | 579 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
580 | 580 | * @return int Returns the position of the first occurrence of search in the string. |
581 | 581 | */ |
582 | -function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
583 | - if ( function_exists( 'mb_strpos' ) ) { |
|
584 | - return mb_strpos( $str, $find, $offset, $encoding ); |
|
582 | +function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
583 | + if (function_exists('mb_strpos')) { |
|
584 | + return mb_strpos($str, $find, $offset, $encoding); |
|
585 | 585 | } |
586 | 586 | |
587 | - return strpos( $str, $find, $offset ); |
|
587 | + return strpos($str, $find, $offset); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | /** |
@@ -598,12 +598,12 @@ discard block |
||
598 | 598 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
599 | 599 | * @return int Returns the position of the last occurrence of search. |
600 | 600 | */ |
601 | -function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
602 | - if ( function_exists( 'mb_strrpos' ) ) { |
|
603 | - return mb_strrpos( $str, $find, $offset, $encoding ); |
|
601 | +function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
602 | + if (function_exists('mb_strrpos')) { |
|
603 | + return mb_strrpos($str, $find, $offset, $encoding); |
|
604 | 604 | } |
605 | 605 | |
606 | - return strrpos( $str, $find, $offset ); |
|
606 | + return strrpos($str, $find, $offset); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -618,16 +618,16 @@ discard block |
||
618 | 618 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
619 | 619 | * @return string |
620 | 620 | */ |
621 | -function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) { |
|
622 | - if ( function_exists( 'mb_substr' ) ) { |
|
623 | - if ( $length === null ) { |
|
624 | - return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
621 | +function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') { |
|
622 | + if (function_exists('mb_substr')) { |
|
623 | + if ($length === null) { |
|
624 | + return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
625 | 625 | } else { |
626 | - return mb_substr( $str, $start, $length, $encoding ); |
|
626 | + return mb_substr($str, $start, $length, $encoding); |
|
627 | 627 | } |
628 | 628 | } |
629 | 629 | |
630 | - return substr( $str, $start, $length ); |
|
630 | + return substr($str, $start, $length); |
|
631 | 631 | } |
632 | 632 | |
633 | 633 | /** |
@@ -639,48 +639,48 @@ discard block |
||
639 | 639 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
640 | 640 | * @return string The width of string. |
641 | 641 | */ |
642 | -function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
|
643 | - if ( function_exists( 'mb_strwidth' ) ) { |
|
644 | - return mb_strwidth( $str, $encoding ); |
|
642 | +function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') { |
|
643 | + if (function_exists('mb_strwidth')) { |
|
644 | + return mb_strwidth($str, $encoding); |
|
645 | 645 | } |
646 | 646 | |
647 | - return wpinv_utf8_strlen( $str, $encoding ); |
|
647 | + return wpinv_utf8_strlen($str, $encoding); |
|
648 | 648 | } |
649 | 649 | |
650 | -function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) { |
|
651 | - if ( function_exists( 'mb_strlen' ) ) { |
|
652 | - $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding ); |
|
650 | +function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') { |
|
651 | + if (function_exists('mb_strlen')) { |
|
652 | + $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding); |
|
653 | 653 | $str_end = ""; |
654 | 654 | |
655 | - if ( $lower_str_end ) { |
|
656 | - $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding ); |
|
655 | + if ($lower_str_end) { |
|
656 | + $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding); |
|
657 | 657 | } else { |
658 | - $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
658 | + $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | return $first_letter . $str_end; |
662 | 662 | } |
663 | 663 | |
664 | - return ucfirst( $str ); |
|
664 | + return ucfirst($str); |
|
665 | 665 | } |
666 | 666 | |
667 | -function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) { |
|
668 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
669 | - return mb_convert_case( $str, MB_CASE_TITLE, $encoding ); |
|
667 | +function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') { |
|
668 | + if (function_exists('mb_convert_case')) { |
|
669 | + return mb_convert_case($str, MB_CASE_TITLE, $encoding); |
|
670 | 670 | } |
671 | 671 | |
672 | - return ucwords( $str ); |
|
672 | + return ucwords($str); |
|
673 | 673 | } |
674 | 674 | |
675 | -function wpinv_period_in_days( $period, $unit ) { |
|
676 | - $period = absint( $period ); |
|
675 | +function wpinv_period_in_days($period, $unit) { |
|
676 | + $period = absint($period); |
|
677 | 677 | |
678 | - if ( $period > 0 ) { |
|
679 | - if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) { |
|
678 | + if ($period > 0) { |
|
679 | + if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) { |
|
680 | 680 | $period = $period * 7; |
681 | - } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) { |
|
681 | + } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) { |
|
682 | 682 | $period = $period * 30; |
683 | - } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) { |
|
683 | + } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) { |
|
684 | 684 | $period = $period * 365; |
685 | 685 | } |
686 | 686 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | 'notify_url' => $listener_url, |
66 | 66 | 'cbt' => get_bloginfo( 'name' ), |
67 | 67 | 'bn' => 'WPInvoicing_SP', |
68 | - 'lc' => 'US' // this will force paypal site to english |
|
68 | + 'lc' => 'US' // this will force paypal site to english |
|
69 | 69 | ); |
70 | 70 | |
71 | 71 | $paypal_args['address1'] = $invoice->get_address(); |
@@ -217,261 +217,261 @@ discard block |
||
217 | 217 | add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 ); |
218 | 218 | |
219 | 219 | function wpinv_process_paypal_ipn() { |
220 | - // Check the request method is POST |
|
221 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
222 | - return; |
|
223 | - } |
|
224 | - |
|
225 | - // Set initial post data to empty string |
|
226 | - $post_data = ''; |
|
227 | - |
|
228 | - // Fallback just in case post_max_size is lower than needed |
|
229 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
230 | - $post_data = file_get_contents( 'php://input' ); |
|
231 | - } else { |
|
232 | - // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
|
233 | - ini_set( 'post_max_size', '12M' ); |
|
234 | - } |
|
235 | - // Start the encoded data collection with notification command |
|
236 | - $encoded_data = 'cmd=_notify-validate'; |
|
237 | - |
|
238 | - // Get current arg separator |
|
239 | - $arg_separator = wpinv_get_php_arg_separator_output(); |
|
240 | - |
|
241 | - // Verify there is a post_data |
|
242 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
243 | - // Append the data |
|
244 | - $encoded_data .= $arg_separator.$post_data; |
|
245 | - } else { |
|
246 | - // Check if POST is empty |
|
247 | - if ( empty( $_POST ) ) { |
|
248 | - // Nothing to do |
|
249 | - return; |
|
250 | - } else { |
|
251 | - // Loop through each POST |
|
252 | - foreach ( $_POST as $key => $value ) { |
|
253 | - // Encode the value and append the data |
|
254 | - $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
255 | - } |
|
256 | - } |
|
257 | - } |
|
258 | - |
|
259 | - // Convert collected post data to an array |
|
260 | - parse_str( $encoded_data, $encoded_data_array ); |
|
261 | - |
|
262 | - foreach ( $encoded_data_array as $key => $value ) { |
|
263 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
264 | - $new_key = str_replace( '&', '&', $key ); |
|
265 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
266 | - |
|
267 | - unset( $encoded_data_array[ $key ] ); |
|
268 | - $encoded_data_array[ $new_key ] = $value; |
|
269 | - } |
|
270 | - } |
|
271 | - |
|
272 | - // Get the PayPal redirect uri |
|
273 | - $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
274 | - |
|
275 | - if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
276 | - // Validate the IPN |
|
277 | - |
|
278 | - $remote_post_vars = array( |
|
279 | - 'method' => 'POST', |
|
280 | - 'timeout' => 45, |
|
281 | - 'redirection' => 5, |
|
282 | - 'httpversion' => '1.1', |
|
283 | - 'blocking' => true, |
|
284 | - 'headers' => array( |
|
285 | - 'host' => 'www.paypal.com', |
|
286 | - 'connection' => 'close', |
|
287 | - 'content-type' => 'application/x-www-form-urlencoded', |
|
288 | - 'post' => '/cgi-bin/webscr HTTP/1.1', |
|
289 | - |
|
290 | - ), |
|
291 | - 'sslverify' => false, |
|
292 | - 'body' => $encoded_data_array |
|
293 | - ); |
|
294 | - |
|
295 | - // Get response |
|
296 | - $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
297 | - |
|
298 | - if ( is_wp_error( $api_response ) ) { |
|
299 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
300 | - return; // Something went wrong |
|
301 | - } |
|
302 | - |
|
303 | - if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
304 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
305 | - return; // Response not okay |
|
306 | - } |
|
307 | - } |
|
308 | - |
|
309 | - // Check if $post_data_array has been populated |
|
310 | - if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
311 | - return; |
|
312 | - |
|
313 | - $defaults = array( |
|
314 | - 'txn_type' => '', |
|
315 | - 'payment_status' => '' |
|
316 | - ); |
|
317 | - |
|
318 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
319 | - |
|
320 | - $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
220 | + // Check the request method is POST |
|
221 | + if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
222 | + return; |
|
223 | + } |
|
224 | + |
|
225 | + // Set initial post data to empty string |
|
226 | + $post_data = ''; |
|
227 | + |
|
228 | + // Fallback just in case post_max_size is lower than needed |
|
229 | + if ( ini_get( 'allow_url_fopen' ) ) { |
|
230 | + $post_data = file_get_contents( 'php://input' ); |
|
231 | + } else { |
|
232 | + // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
|
233 | + ini_set( 'post_max_size', '12M' ); |
|
234 | + } |
|
235 | + // Start the encoded data collection with notification command |
|
236 | + $encoded_data = 'cmd=_notify-validate'; |
|
237 | + |
|
238 | + // Get current arg separator |
|
239 | + $arg_separator = wpinv_get_php_arg_separator_output(); |
|
240 | + |
|
241 | + // Verify there is a post_data |
|
242 | + if ( $post_data || strlen( $post_data ) > 0 ) { |
|
243 | + // Append the data |
|
244 | + $encoded_data .= $arg_separator.$post_data; |
|
245 | + } else { |
|
246 | + // Check if POST is empty |
|
247 | + if ( empty( $_POST ) ) { |
|
248 | + // Nothing to do |
|
249 | + return; |
|
250 | + } else { |
|
251 | + // Loop through each POST |
|
252 | + foreach ( $_POST as $key => $value ) { |
|
253 | + // Encode the value and append the data |
|
254 | + $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
255 | + } |
|
256 | + } |
|
257 | + } |
|
258 | + |
|
259 | + // Convert collected post data to an array |
|
260 | + parse_str( $encoded_data, $encoded_data_array ); |
|
261 | + |
|
262 | + foreach ( $encoded_data_array as $key => $value ) { |
|
263 | + if ( false !== strpos( $key, 'amp;' ) ) { |
|
264 | + $new_key = str_replace( '&', '&', $key ); |
|
265 | + $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
266 | + |
|
267 | + unset( $encoded_data_array[ $key ] ); |
|
268 | + $encoded_data_array[ $new_key ] = $value; |
|
269 | + } |
|
270 | + } |
|
271 | + |
|
272 | + // Get the PayPal redirect uri |
|
273 | + $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
274 | + |
|
275 | + if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
276 | + // Validate the IPN |
|
277 | + |
|
278 | + $remote_post_vars = array( |
|
279 | + 'method' => 'POST', |
|
280 | + 'timeout' => 45, |
|
281 | + 'redirection' => 5, |
|
282 | + 'httpversion' => '1.1', |
|
283 | + 'blocking' => true, |
|
284 | + 'headers' => array( |
|
285 | + 'host' => 'www.paypal.com', |
|
286 | + 'connection' => 'close', |
|
287 | + 'content-type' => 'application/x-www-form-urlencoded', |
|
288 | + 'post' => '/cgi-bin/webscr HTTP/1.1', |
|
289 | + |
|
290 | + ), |
|
291 | + 'sslverify' => false, |
|
292 | + 'body' => $encoded_data_array |
|
293 | + ); |
|
294 | + |
|
295 | + // Get response |
|
296 | + $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
297 | + |
|
298 | + if ( is_wp_error( $api_response ) ) { |
|
299 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
300 | + return; // Something went wrong |
|
301 | + } |
|
302 | + |
|
303 | + if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
304 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
305 | + return; // Response not okay |
|
306 | + } |
|
307 | + } |
|
308 | + |
|
309 | + // Check if $post_data_array has been populated |
|
310 | + if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
311 | + return; |
|
312 | + |
|
313 | + $defaults = array( |
|
314 | + 'txn_type' => '', |
|
315 | + 'payment_status' => '' |
|
316 | + ); |
|
317 | + |
|
318 | + $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
319 | + |
|
320 | + $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
321 | 321 | |
322 | - wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
323 | - |
|
324 | - if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
325 | - // Allow PayPal IPN types to be processed separately |
|
326 | - do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
327 | - } else { |
|
328 | - // Fallback to web accept just in case the txn_type isn't present |
|
329 | - do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
330 | - } |
|
331 | - exit; |
|
322 | + wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
323 | + |
|
324 | + if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
325 | + // Allow PayPal IPN types to be processed separately |
|
326 | + do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
327 | + } else { |
|
328 | + // Fallback to web accept just in case the txn_type isn't present |
|
329 | + do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
330 | + } |
|
331 | + exit; |
|
332 | 332 | } |
333 | 333 | add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' ); |
334 | 334 | |
335 | 335 | function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) { |
336 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
337 | - return; |
|
338 | - } |
|
339 | - |
|
340 | - if( empty( $invoice_id ) ) { |
|
341 | - return; |
|
342 | - } |
|
343 | - |
|
344 | - // Collect payment details |
|
345 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
346 | - $paypal_amount = $data['mc_gross']; |
|
347 | - $payment_status = strtolower( $data['payment_status'] ); |
|
348 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
349 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
350 | - $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
351 | - |
|
352 | - if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
353 | - return; // this isn't a PayPal standard IPN |
|
354 | - } |
|
355 | - |
|
356 | - // Verify payment recipient |
|
357 | - if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
358 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
359 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
360 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ) ); |
|
361 | - return; |
|
362 | - } |
|
363 | - |
|
364 | - // Verify payment currency |
|
365 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
366 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
367 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
368 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ) ); |
|
369 | - return; |
|
370 | - } |
|
371 | - |
|
372 | - if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
373 | - // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
|
374 | - // No email associated with purchase, so store from PayPal |
|
375 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
376 | - |
|
377 | - // Setup and store the customer's details |
|
378 | - $user_info = array( |
|
379 | - 'user_id' => '-1', |
|
380 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
381 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
382 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
383 | - 'discount' => '', |
|
384 | - ); |
|
385 | - $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
386 | - $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
387 | - $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
388 | - $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
389 | - $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
390 | - |
|
391 | - $payment_meta['user_info'] = $user_info; |
|
392 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
393 | - } |
|
394 | - |
|
395 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
396 | - // Process a refund |
|
397 | - wpinv_process_paypal_refund( $data, $invoice_id ); |
|
398 | - } else { |
|
399 | - if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
400 | - return; // Only paid payments once |
|
401 | - } |
|
402 | - |
|
403 | - // Retrieve the total purchase amount (before PayPal) |
|
404 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
405 | - |
|
406 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
407 | - // The prices don't match |
|
408 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
409 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
410 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ) ); |
|
411 | - return; |
|
412 | - } |
|
413 | - if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
414 | - // Purchase keys don't match |
|
415 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
416 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
417 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ) ); |
|
418 | - return; |
|
419 | - } |
|
420 | - |
|
421 | - if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
422 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ) ); |
|
423 | - wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
424 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
425 | - } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
426 | - // Look for possible pending reasons, such as an echeck |
|
427 | - $note = ''; |
|
428 | - |
|
429 | - switch( strtolower( $data['pending_reason'] ) ) { |
|
430 | - case 'echeck' : |
|
431 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
432 | - break; |
|
336 | + if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
337 | + return; |
|
338 | + } |
|
339 | + |
|
340 | + if( empty( $invoice_id ) ) { |
|
341 | + return; |
|
342 | + } |
|
343 | + |
|
344 | + // Collect payment details |
|
345 | + $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
346 | + $paypal_amount = $data['mc_gross']; |
|
347 | + $payment_status = strtolower( $data['payment_status'] ); |
|
348 | + $currency_code = strtolower( $data['mc_currency'] ); |
|
349 | + $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
350 | + $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
351 | + |
|
352 | + if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
353 | + return; // this isn't a PayPal standard IPN |
|
354 | + } |
|
355 | + |
|
356 | + // Verify payment recipient |
|
357 | + if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
358 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
359 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
360 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ) ); |
|
361 | + return; |
|
362 | + } |
|
363 | + |
|
364 | + // Verify payment currency |
|
365 | + if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
366 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
367 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
368 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ) ); |
|
369 | + return; |
|
370 | + } |
|
371 | + |
|
372 | + if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
373 | + // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
|
374 | + // No email associated with purchase, so store from PayPal |
|
375 | + wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
376 | + |
|
377 | + // Setup and store the customer's details |
|
378 | + $user_info = array( |
|
379 | + 'user_id' => '-1', |
|
380 | + 'email' => sanitize_text_field( $data['payer_email'] ), |
|
381 | + 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
382 | + 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
383 | + 'discount' => '', |
|
384 | + ); |
|
385 | + $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
386 | + $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
387 | + $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
388 | + $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
389 | + $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
390 | + |
|
391 | + $payment_meta['user_info'] = $user_info; |
|
392 | + wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
393 | + } |
|
394 | + |
|
395 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
396 | + // Process a refund |
|
397 | + wpinv_process_paypal_refund( $data, $invoice_id ); |
|
398 | + } else { |
|
399 | + if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
400 | + return; // Only paid payments once |
|
401 | + } |
|
402 | + |
|
403 | + // Retrieve the total purchase amount (before PayPal) |
|
404 | + $payment_amount = wpinv_payment_total( $invoice_id ); |
|
405 | + |
|
406 | + if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
407 | + // The prices don't match |
|
408 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
409 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
410 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ) ); |
|
411 | + return; |
|
412 | + } |
|
413 | + if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
414 | + // Purchase keys don't match |
|
415 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
416 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
417 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ) ); |
|
418 | + return; |
|
419 | + } |
|
420 | + |
|
421 | + if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
422 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ) ); |
|
423 | + wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
424 | + wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
425 | + } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
426 | + // Look for possible pending reasons, such as an echeck |
|
427 | + $note = ''; |
|
428 | + |
|
429 | + switch( strtolower( $data['pending_reason'] ) ) { |
|
430 | + case 'echeck' : |
|
431 | + $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
432 | + break; |
|
433 | 433 | |
434 | 434 | case 'address' : |
435 | - $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
436 | - break; |
|
435 | + $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
436 | + break; |
|
437 | 437 | |
438 | 438 | case 'intl' : |
439 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
440 | - break; |
|
439 | + $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
440 | + break; |
|
441 | 441 | |
442 | 442 | case 'multi-currency' : |
443 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
444 | - break; |
|
443 | + $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
444 | + break; |
|
445 | 445 | |
446 | 446 | case 'paymentreview' : |
447 | 447 | case 'regulatory_review' : |
448 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
449 | - break; |
|
448 | + $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
449 | + break; |
|
450 | 450 | |
451 | 451 | case 'unilateral' : |
452 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
453 | - break; |
|
452 | + $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
453 | + break; |
|
454 | 454 | |
455 | 455 | case 'upgrade' : |
456 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
457 | - break; |
|
456 | + $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
457 | + break; |
|
458 | 458 | |
459 | 459 | case 'verify' : |
460 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
461 | - break; |
|
462 | - |
|
463 | - case 'other' : |
|
464 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
465 | - break; |
|
466 | - } |
|
467 | - |
|
468 | - if ( ! empty( $note ) ) { |
|
469 | - wpinv_insert_payment_note( $invoice_id, $note ); |
|
470 | - } |
|
471 | - } else { |
|
472 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ) ); |
|
473 | - } |
|
474 | - } |
|
460 | + $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
461 | + break; |
|
462 | + |
|
463 | + case 'other' : |
|
464 | + $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
465 | + break; |
|
466 | + } |
|
467 | + |
|
468 | + if ( ! empty( $note ) ) { |
|
469 | + wpinv_insert_payment_note( $invoice_id, $note ); |
|
470 | + } |
|
471 | + } else { |
|
472 | + wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ) ); |
|
473 | + } |
|
474 | + } |
|
475 | 475 | } |
476 | 476 | add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 ); |
477 | 477 | |
@@ -686,27 +686,27 @@ discard block |
||
686 | 686 | } |
687 | 687 | |
688 | 688 | function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) { |
689 | - // Collect payment details |
|
689 | + // Collect payment details |
|
690 | 690 | |
691 | - if( empty( $invoice_id ) ) { |
|
692 | - return; |
|
693 | - } |
|
691 | + if( empty( $invoice_id ) ) { |
|
692 | + return; |
|
693 | + } |
|
694 | 694 | |
695 | - if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
696 | - return; // Only refund payments once |
|
697 | - } |
|
695 | + if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
696 | + return; // Only refund payments once |
|
697 | + } |
|
698 | 698 | |
699 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
700 | - $refund_amount = $data['mc_gross'] * -1; |
|
699 | + $payment_amount = wpinv_payment_total( $invoice_id ); |
|
700 | + $refund_amount = $data['mc_gross'] * -1; |
|
701 | 701 | |
702 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
703 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Partial PayPal refund processed: %s', 'invoicing' ), $data['parent_txn_id'] ) ); |
|
704 | - return; // This is a partial refund |
|
705 | - } |
|
702 | + if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
703 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Partial PayPal refund processed: %s', 'invoicing' ), $data['parent_txn_id'] ) ); |
|
704 | + return; // This is a partial refund |
|
705 | + } |
|
706 | 706 | |
707 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ) ); |
|
708 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ) ); |
|
709 | - wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
707 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ) ); |
|
708 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ) ); |
|
709 | + wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
710 | 710 | } |
711 | 711 | |
712 | 712 | function wpinv_get_paypal_redirect( $ssl_check = false ) { |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_action( 'wpinv_paypal_cc_form', '__return_false' ); |
|
6 | -add_filter( 'wpinv_paypal_support_subscription', '__return_true' ); |
|
5 | +add_action('wpinv_paypal_cc_form', '__return_false'); |
|
6 | +add_filter('wpinv_paypal_support_subscription', '__return_true'); |
|
7 | 7 | |
8 | -function wpinv_process_paypal_payment( $purchase_data ) { |
|
9 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
10 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
8 | +function wpinv_process_paypal_payment($purchase_data) { |
|
9 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
10 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | // Collect payment data |
@@ -21,34 +21,34 @@ discard block |
||
21 | 21 | 'user_info' => $purchase_data['user_info'], |
22 | 22 | 'cart_details' => $purchase_data['cart_details'], |
23 | 23 | 'gateway' => 'paypal', |
24 | - 'status' => !empty( $purchase_data['buy_now'] ) ? 'private' : 'pending' |
|
24 | + 'status' => !empty($purchase_data['buy_now']) ? 'private' : 'pending' |
|
25 | 25 | ); |
26 | 26 | |
27 | 27 | // Record the pending payment |
28 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
28 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
29 | 29 | |
30 | 30 | // Check payment |
31 | - if ( ! $invoice ) { |
|
31 | + if (!$invoice) { |
|
32 | 32 | // Record the error |
33 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $payment ); |
|
33 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing'), json_encode($payment_data)), $payment); |
|
34 | 34 | // Problems? send back |
35 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
35 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
36 | 36 | } else { |
37 | 37 | // Only send to PayPal if the pending payment is created successfully |
38 | - $listener_url = wpinv_get_ipn_url( 'paypal' ); |
|
38 | + $listener_url = wpinv_get_ipn_url('paypal'); |
|
39 | 39 | |
40 | 40 | // Get the success url |
41 | - $return_url = add_query_arg( array( |
|
41 | + $return_url = add_query_arg(array( |
|
42 | 42 | 'payment-confirm' => 'paypal', |
43 | 43 | 'invoice-id' => $invoice->ID |
44 | - ), get_permalink( wpinv_get_option( 'success_page', false ) ) ); |
|
44 | + ), get_permalink(wpinv_get_option('success_page', false))); |
|
45 | 45 | |
46 | 46 | // Get the PayPal redirect uri |
47 | - $paypal_redirect = trailingslashit( wpinv_get_paypal_redirect() ) . '?'; |
|
47 | + $paypal_redirect = trailingslashit(wpinv_get_paypal_redirect()) . '?'; |
|
48 | 48 | |
49 | 49 | // Setup PayPal arguments |
50 | 50 | $paypal_args = array( |
51 | - 'business' => wpinv_get_option( 'paypal_email', false ), |
|
51 | + 'business' => wpinv_get_option('paypal_email', false), |
|
52 | 52 | 'email' => $invoice->get_email(), |
53 | 53 | 'first_name' => $invoice->get_first_name(), |
54 | 54 | 'last_name' => $invoice->get_last_name(), |
@@ -57,13 +57,13 @@ discard block |
||
57 | 57 | 'shipping' => '0', |
58 | 58 | 'no_note' => '1', |
59 | 59 | 'currency_code' => wpinv_get_currency(), |
60 | - 'charset' => get_bloginfo( 'charset' ), |
|
60 | + 'charset' => get_bloginfo('charset'), |
|
61 | 61 | 'custom' => $invoice->ID, |
62 | 62 | 'rm' => '2', |
63 | 63 | 'return' => $return_url, |
64 | - 'cancel_return' => wpinv_get_failed_transaction_uri( '?invoice-id=' . $invoice->ID ), |
|
64 | + 'cancel_return' => wpinv_get_failed_transaction_uri('?invoice-id=' . $invoice->ID), |
|
65 | 65 | 'notify_url' => $listener_url, |
66 | - 'cbt' => get_bloginfo( 'name' ), |
|
66 | + 'cbt' => get_bloginfo('name'), |
|
67 | 67 | 'bn' => 'WPInvoicing_SP', |
68 | 68 | 'lc' => 'US' // this will force paypal site to english |
69 | 69 | ); |
@@ -79,57 +79,57 @@ discard block |
||
79 | 79 | 'upload' => '1' |
80 | 80 | ); |
81 | 81 | |
82 | - $paypal_args = array_merge( $paypal_extra_args, $paypal_args ); |
|
82 | + $paypal_args = array_merge($paypal_extra_args, $paypal_args); |
|
83 | 83 | |
84 | 84 | // Add cart items |
85 | 85 | $i = 1; |
86 | - if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) { |
|
87 | - foreach ( $purchase_data['cart_details'] as $item ) { |
|
86 | + if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) { |
|
87 | + foreach ($purchase_data['cart_details'] as $item) { |
|
88 | 88 | $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1; |
89 | - $item_amount = round( $item['subtotal'] / $item['quantity'], 2 ); |
|
89 | + $item_amount = round($item['subtotal'] / $item['quantity'], 2); |
|
90 | 90 | |
91 | - if ( $item_amount <= 0 ) { |
|
91 | + if ($item_amount <= 0) { |
|
92 | 92 | $item_amount = 0; |
93 | 93 | } |
94 | 94 | |
95 | - $paypal_args['item_number_' . $i ] = $item['id']; |
|
96 | - $paypal_args['item_name_' . $i ] = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) ); |
|
97 | - $paypal_args['quantity_' . $i ] = $item['quantity']; |
|
98 | - $paypal_args['amount_' . $i ] = $item_amount; |
|
99 | - $paypal_args['discount_amount_' . $i ] = $item['discount']; |
|
95 | + $paypal_args['item_number_' . $i] = $item['id']; |
|
96 | + $paypal_args['item_name_' . $i] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8')); |
|
97 | + $paypal_args['quantity_' . $i] = $item['quantity']; |
|
98 | + $paypal_args['amount_' . $i] = $item_amount; |
|
99 | + $paypal_args['discount_amount_' . $i] = $item['discount']; |
|
100 | 100 | |
101 | 101 | $i++; |
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
105 | 105 | // Add taxes to the cart |
106 | - if ( wpinv_use_taxes() ) { |
|
107 | - $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float)$invoice->get_tax() ); |
|
106 | + if (wpinv_use_taxes()) { |
|
107 | + $paypal_args['tax_cart'] = wpinv_sanitize_amount((float)$invoice->get_tax()); |
|
108 | 108 | } |
109 | 109 | |
110 | - $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice ); |
|
110 | + $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice); |
|
111 | 111 | |
112 | 112 | // Build query |
113 | - $paypal_redirect .= http_build_query( $paypal_args ); |
|
113 | + $paypal_redirect .= http_build_query($paypal_args); |
|
114 | 114 | |
115 | 115 | // Fix for some sites that encode the entities |
116 | - $paypal_redirect = str_replace( '&', '&', $paypal_redirect ); |
|
116 | + $paypal_redirect = str_replace('&', '&', $paypal_redirect); |
|
117 | 117 | |
118 | 118 | // Get rid of cart contents |
119 | 119 | wpinv_empty_cart(); |
120 | 120 | |
121 | 121 | // Redirect to PayPal |
122 | - wp_redirect( $paypal_redirect ); |
|
122 | + wp_redirect($paypal_redirect); |
|
123 | 123 | exit; |
124 | 124 | } |
125 | 125 | } |
126 | -add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' ); |
|
126 | +add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment'); |
|
127 | 127 | |
128 | -function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) { |
|
129 | - if ( $invoice->is_recurring() && $item_id = $invoice->get_recurring() ) { |
|
130 | - $item = new WPInv_Item( $item_id ); |
|
128 | +function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) { |
|
129 | + if ($invoice->is_recurring() && $item_id = $invoice->get_recurring()) { |
|
130 | + $item = new WPInv_Item($item_id); |
|
131 | 131 | |
132 | - if ( empty( $item ) ) { |
|
132 | + if (empty($item)) { |
|
133 | 133 | return $paypal_args; |
134 | 134 | } |
135 | 135 | |
@@ -137,24 +137,24 @@ discard block |
||
137 | 137 | $interval = $item->get_recurring_interval(); |
138 | 138 | $bill_times = (int)$item->get_recurring_limit(); |
139 | 139 | |
140 | - $initial_amount = wpinv_format_amount( $invoice->get_total() ); |
|
141 | - $recurring_amount = wpinv_format_amount( $invoice->get_recurring_details( 'total' ) ); |
|
140 | + $initial_amount = wpinv_format_amount($invoice->get_total()); |
|
141 | + $recurring_amount = wpinv_format_amount($invoice->get_recurring_details('total')); |
|
142 | 142 | |
143 | 143 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
144 | 144 | $paypal_args['sra'] = '1'; |
145 | 145 | $paypal_args['src'] = '1'; |
146 | 146 | |
147 | 147 | // Set item description |
148 | - $paypal_args['item_name'] = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( array( 'id' => $item->ID ) ), ENT_COMPAT, 'UTF-8' ) ); |
|
148 | + $paypal_args['item_name'] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name(array('id' => $item->ID)), ENT_COMPAT, 'UTF-8')); |
|
149 | 149 | |
150 | - if ( $invoice->is_free_trial() && $item->has_free_trial() ) { |
|
150 | + if ($invoice->is_free_trial() && $item->has_free_trial()) { |
|
151 | 151 | $paypal_args['a1'] = $initial_amount; |
152 | 152 | $paypal_args['p1'] = $item->get_trial_interval(); |
153 | 153 | $paypal_args['t1'] = $item->get_trial_period(); |
154 | 154 | |
155 | 155 | // Set the recurring amount |
156 | 156 | $paypal_args['a3'] = $recurring_amount; |
157 | - } else if ( $initial_amount != $recurring_amount && $bill_times != 1 ) { |
|
157 | + } else if ($initial_amount != $recurring_amount && $bill_times != 1) { |
|
158 | 158 | $paypal_args['a1'] = $initial_amount; |
159 | 159 | $paypal_args['p1'] = $interval; |
160 | 160 | $paypal_args['t1'] = $period; |
@@ -162,63 +162,63 @@ discard block |
||
162 | 162 | // Set the recurring amount |
163 | 163 | $paypal_args['a3'] = $recurring_amount; |
164 | 164 | |
165 | - if ( $bill_times > 1 ) { |
|
165 | + if ($bill_times > 1) { |
|
166 | 166 | $bill_times--; |
167 | 167 | } |
168 | 168 | } else { |
169 | - $paypal_args['a3'] = $initial_amount; |
|
169 | + $paypal_args['a3'] = $initial_amount; |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | $paypal_args['p3'] = $interval; |
173 | 173 | $paypal_args['t3'] = $period; |
174 | 174 | |
175 | - if ( $bill_times > 1 ) { |
|
175 | + if ($bill_times > 1) { |
|
176 | 176 | // Make sure it's not over the max of 52 |
177 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
177 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | // Remove cart items |
181 | 181 | $i = 1; |
182 | - if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) { |
|
183 | - foreach ( $purchase_data['cart_details'] as $item ) { |
|
184 | - if ( isset( $paypal_args['item_number_' . $i] ) ) { |
|
185 | - unset( $paypal_args['item_number_' . $i] ); |
|
182 | + if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) { |
|
183 | + foreach ($purchase_data['cart_details'] as $item) { |
|
184 | + if (isset($paypal_args['item_number_' . $i])) { |
|
185 | + unset($paypal_args['item_number_' . $i]); |
|
186 | 186 | } |
187 | - if ( isset( $paypal_args['item_name_' . $i] ) ) { |
|
188 | - unset( $paypal_args['item_name_' . $i] ); |
|
187 | + if (isset($paypal_args['item_name_' . $i])) { |
|
188 | + unset($paypal_args['item_name_' . $i]); |
|
189 | 189 | } |
190 | - if ( isset( $paypal_args['quantity_' . $i] ) ) { |
|
191 | - unset( $paypal_args['quantity_' . $i] ); |
|
190 | + if (isset($paypal_args['quantity_' . $i])) { |
|
191 | + unset($paypal_args['quantity_' . $i]); |
|
192 | 192 | } |
193 | - if ( isset( $paypal_args['amount_' . $i] ) ) { |
|
194 | - unset( $paypal_args['amount_' . $i] ); |
|
193 | + if (isset($paypal_args['amount_' . $i])) { |
|
194 | + unset($paypal_args['amount_' . $i]); |
|
195 | 195 | } |
196 | - if ( isset( $paypal_args['discount_amount_' . $i] ) ) { |
|
197 | - unset( $paypal_args['discount_amount_' . $i] ); |
|
196 | + if (isset($paypal_args['discount_amount_' . $i])) { |
|
197 | + unset($paypal_args['discount_amount_' . $i]); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | $i++; |
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | - if ( isset( $paypal_args['tax_cart'] ) ) { |
|
205 | - unset( $paypal_args['tax_cart'] ); |
|
204 | + if (isset($paypal_args['tax_cart'])) { |
|
205 | + unset($paypal_args['tax_cart']); |
|
206 | 206 | } |
207 | 207 | |
208 | - if ( isset( $paypal_args['upload'] ) ) { |
|
209 | - unset( $paypal_args['upload'] ); |
|
208 | + if (isset($paypal_args['upload'])) { |
|
209 | + unset($paypal_args['upload']); |
|
210 | 210 | } |
211 | 211 | |
212 | - $paypal_args = apply_filters( 'wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice ); |
|
212 | + $paypal_args = apply_filters('wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | return $paypal_args; |
216 | 216 | } |
217 | -add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 ); |
|
217 | +add_filter('wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3); |
|
218 | 218 | |
219 | 219 | function wpinv_process_paypal_ipn() { |
220 | 220 | // Check the request method is POST |
221 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
221 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
222 | 222 | return; |
223 | 223 | } |
224 | 224 | |
@@ -226,11 +226,11 @@ discard block |
||
226 | 226 | $post_data = ''; |
227 | 227 | |
228 | 228 | // Fallback just in case post_max_size is lower than needed |
229 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
230 | - $post_data = file_get_contents( 'php://input' ); |
|
229 | + if (ini_get('allow_url_fopen')) { |
|
230 | + $post_data = file_get_contents('php://input'); |
|
231 | 231 | } else { |
232 | 232 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
233 | - ini_set( 'post_max_size', '12M' ); |
|
233 | + ini_set('post_max_size', '12M'); |
|
234 | 234 | } |
235 | 235 | // Start the encoded data collection with notification command |
236 | 236 | $encoded_data = 'cmd=_notify-validate'; |
@@ -239,43 +239,43 @@ discard block |
||
239 | 239 | $arg_separator = wpinv_get_php_arg_separator_output(); |
240 | 240 | |
241 | 241 | // Verify there is a post_data |
242 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
242 | + if ($post_data || strlen($post_data) > 0) { |
|
243 | 243 | // Append the data |
244 | - $encoded_data .= $arg_separator.$post_data; |
|
244 | + $encoded_data .= $arg_separator . $post_data; |
|
245 | 245 | } else { |
246 | 246 | // Check if POST is empty |
247 | - if ( empty( $_POST ) ) { |
|
247 | + if (empty($_POST)) { |
|
248 | 248 | // Nothing to do |
249 | 249 | return; |
250 | 250 | } else { |
251 | 251 | // Loop through each POST |
252 | - foreach ( $_POST as $key => $value ) { |
|
252 | + foreach ($_POST as $key => $value) { |
|
253 | 253 | // Encode the value and append the data |
254 | - $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
254 | + $encoded_data .= $arg_separator . "$key=" . urlencode($value); |
|
255 | 255 | } |
256 | 256 | } |
257 | 257 | } |
258 | 258 | |
259 | 259 | // Convert collected post data to an array |
260 | - parse_str( $encoded_data, $encoded_data_array ); |
|
260 | + parse_str($encoded_data, $encoded_data_array); |
|
261 | 261 | |
262 | - foreach ( $encoded_data_array as $key => $value ) { |
|
263 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
264 | - $new_key = str_replace( '&', '&', $key ); |
|
265 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
262 | + foreach ($encoded_data_array as $key => $value) { |
|
263 | + if (false !== strpos($key, 'amp;')) { |
|
264 | + $new_key = str_replace('&', '&', $key); |
|
265 | + $new_key = str_replace('amp;', '&', $new_key); |
|
266 | 266 | |
267 | - unset( $encoded_data_array[ $key ] ); |
|
268 | - $encoded_data_array[ $new_key ] = $value; |
|
267 | + unset($encoded_data_array[$key]); |
|
268 | + $encoded_data_array[$new_key] = $value; |
|
269 | 269 | } |
270 | 270 | } |
271 | 271 | |
272 | 272 | // Get the PayPal redirect uri |
273 | - $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
273 | + $paypal_redirect = wpinv_get_paypal_redirect(true); |
|
274 | 274 | |
275 | - if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
275 | + if (!wpinv_get_option('disable_paypal_verification', false)) { |
|
276 | 276 | // Validate the IPN |
277 | 277 | |
278 | - $remote_post_vars = array( |
|
278 | + $remote_post_vars = array( |
|
279 | 279 | 'method' => 'POST', |
280 | 280 | 'timeout' => 45, |
281 | 281 | 'redirection' => 5, |
@@ -293,21 +293,21 @@ discard block |
||
293 | 293 | ); |
294 | 294 | |
295 | 295 | // Get response |
296 | - $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
296 | + $api_response = wp_remote_post(wpinv_get_paypal_redirect(), $remote_post_vars); |
|
297 | 297 | |
298 | - if ( is_wp_error( $api_response ) ) { |
|
299 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
298 | + if (is_wp_error($api_response)) { |
|
299 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response))); |
|
300 | 300 | return; // Something went wrong |
301 | 301 | } |
302 | 302 | |
303 | - if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
304 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
303 | + if ($api_response['body'] !== 'VERIFIED' && wpinv_get_option('disable_paypal_verification', false)) { |
|
304 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response))); |
|
305 | 305 | return; // Response not okay |
306 | 306 | } |
307 | 307 | } |
308 | 308 | |
309 | 309 | // Check if $post_data_array has been populated |
310 | - if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
310 | + if (!is_array($encoded_data_array) && !empty($encoded_data_array)) |
|
311 | 311 | return; |
312 | 312 | |
313 | 313 | $defaults = array( |
@@ -315,215 +315,215 @@ discard block |
||
315 | 315 | 'payment_status' => '' |
316 | 316 | ); |
317 | 317 | |
318 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
318 | + $encoded_data_array = wp_parse_args($encoded_data_array, $defaults); |
|
319 | 319 | |
320 | - $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
320 | + $invoice_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0; |
|
321 | 321 | |
322 | - wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
322 | + wpinv_error_log($encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__); |
|
323 | 323 | |
324 | - if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
324 | + if (has_action('wpinv_paypal_' . $encoded_data_array['txn_type'])) { |
|
325 | 325 | // Allow PayPal IPN types to be processed separately |
326 | - do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
326 | + do_action('wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id); |
|
327 | 327 | } else { |
328 | 328 | // Fallback to web accept just in case the txn_type isn't present |
329 | - do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
329 | + do_action('wpinv_paypal_web_accept', $encoded_data_array, $invoice_id); |
|
330 | 330 | } |
331 | 331 | exit; |
332 | 332 | } |
333 | -add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' ); |
|
333 | +add_action('wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn'); |
|
334 | 334 | |
335 | -function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) { |
|
336 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
335 | +function wpinv_process_paypal_web_accept_and_cart($data, $invoice_id) { |
|
336 | + if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') { |
|
337 | 337 | return; |
338 | 338 | } |
339 | 339 | |
340 | - if( empty( $invoice_id ) ) { |
|
340 | + if (empty($invoice_id)) { |
|
341 | 341 | return; |
342 | 342 | } |
343 | 343 | |
344 | 344 | // Collect payment details |
345 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
345 | + $purchase_key = isset($data['invoice']) ? $data['invoice'] : $data['item_number']; |
|
346 | 346 | $paypal_amount = $data['mc_gross']; |
347 | - $payment_status = strtolower( $data['payment_status'] ); |
|
348 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
349 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
350 | - $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
347 | + $payment_status = strtolower($data['payment_status']); |
|
348 | + $currency_code = strtolower($data['mc_currency']); |
|
349 | + $business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']); |
|
350 | + $payment_meta = wpinv_get_invoice_meta($invoice_id); |
|
351 | 351 | |
352 | - if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
352 | + if (wpinv_get_payment_gateway($invoice_id) != 'paypal') { |
|
353 | 353 | return; // this isn't a PayPal standard IPN |
354 | 354 | } |
355 | 355 | |
356 | 356 | // Verify payment recipient |
357 | - if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
358 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
359 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
360 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ) ); |
|
357 | + if (strcasecmp($business_email, trim(wpinv_get_option('paypal_email', false))) != 0) { |
|
358 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
359 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
360 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid PayPal business email.', 'invoicing')); |
|
361 | 361 | return; |
362 | 362 | } |
363 | 363 | |
364 | 364 | // Verify payment currency |
365 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
366 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
367 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
368 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ) ); |
|
365 | + if ($currency_code != strtolower($payment_meta['currency'])) { |
|
366 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
367 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
368 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid currency in PayPal IPN.', 'invoicing')); |
|
369 | 369 | return; |
370 | 370 | } |
371 | 371 | |
372 | - if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
372 | + if (!wpinv_get_payment_user_email($invoice_id)) { |
|
373 | 373 | // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
374 | 374 | // No email associated with purchase, so store from PayPal |
375 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
375 | + wpinv_update_invoice_meta($invoice_id, '_wpinv_email', $data['payer_email']); |
|
376 | 376 | |
377 | 377 | // Setup and store the customer's details |
378 | 378 | $user_info = array( |
379 | 379 | 'user_id' => '-1', |
380 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
381 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
382 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
380 | + 'email' => sanitize_text_field($data['payer_email']), |
|
381 | + 'first_name' => sanitize_text_field($data['first_name']), |
|
382 | + 'last_name' => sanitize_text_field($data['last_name']), |
|
383 | 383 | 'discount' => '', |
384 | 384 | ); |
385 | - $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
386 | - $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
387 | - $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
388 | - $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
389 | - $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
385 | + $user_info['address'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false; |
|
386 | + $user_info['city'] = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false; |
|
387 | + $user_info['state'] = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false; |
|
388 | + $user_info['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false; |
|
389 | + $user_info['zip'] = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false; |
|
390 | 390 | |
391 | 391 | $payment_meta['user_info'] = $user_info; |
392 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
392 | + wpinv_update_invoice_meta($invoice_id, '_wpinv_payment_meta', $payment_meta); |
|
393 | 393 | } |
394 | 394 | |
395 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
395 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
396 | 396 | // Process a refund |
397 | - wpinv_process_paypal_refund( $data, $invoice_id ); |
|
397 | + wpinv_process_paypal_refund($data, $invoice_id); |
|
398 | 398 | } else { |
399 | - if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
399 | + if (get_post_status($invoice_id) == 'publish') { |
|
400 | 400 | return; // Only paid payments once |
401 | 401 | } |
402 | 402 | |
403 | 403 | // Retrieve the total purchase amount (before PayPal) |
404 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
404 | + $payment_amount = wpinv_payment_total($invoice_id); |
|
405 | 405 | |
406 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
406 | + if (number_format((float)$paypal_amount, 2) < number_format((float)$payment_amount, 2)) { |
|
407 | 407 | // The prices don't match |
408 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
409 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
410 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ) ); |
|
408 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
409 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
410 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid amount in PayPal IPN.', 'invoicing')); |
|
411 | 411 | return; |
412 | 412 | } |
413 | - if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
413 | + if ($purchase_key != wpinv_get_payment_key($invoice_id)) { |
|
414 | 414 | // Purchase keys don't match |
415 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
416 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
417 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ) ); |
|
415 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
416 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
417 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing')); |
|
418 | 418 | return; |
419 | 419 | } |
420 | 420 | |
421 | - if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
422 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ) ); |
|
423 | - wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
424 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
425 | - } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
421 | + if ('complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode('paypal')) { |
|
422 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $data['txn_id'])); |
|
423 | + wpinv_set_payment_transaction_id($invoice_id, $data['txn_id']); |
|
424 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
425 | + } else if ('pending' == $payment_status && isset($data['pending_reason'])) { |
|
426 | 426 | // Look for possible pending reasons, such as an echeck |
427 | 427 | $note = ''; |
428 | 428 | |
429 | - switch( strtolower( $data['pending_reason'] ) ) { |
|
429 | + switch (strtolower($data['pending_reason'])) { |
|
430 | 430 | case 'echeck' : |
431 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
431 | + $note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing'); |
|
432 | 432 | break; |
433 | 433 | |
434 | 434 | case 'address' : |
435 | - $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
435 | + $note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing'); |
|
436 | 436 | break; |
437 | 437 | |
438 | 438 | case 'intl' : |
439 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
439 | + $note = __('Payment must be accepted manually through PayPal due to international account regulations', 'invoicing'); |
|
440 | 440 | break; |
441 | 441 | |
442 | 442 | case 'multi-currency' : |
443 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
443 | + $note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing'); |
|
444 | 444 | break; |
445 | 445 | |
446 | 446 | case 'paymentreview' : |
447 | 447 | case 'regulatory_review' : |
448 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
448 | + $note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing'); |
|
449 | 449 | break; |
450 | 450 | |
451 | 451 | case 'unilateral' : |
452 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
452 | + $note = __('Payment was sent to non-confirmed or non-registered email address.', 'invoicing'); |
|
453 | 453 | break; |
454 | 454 | |
455 | 455 | case 'upgrade' : |
456 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
456 | + $note = __('PayPal account must be upgraded before this payment can be accepted', 'invoicing'); |
|
457 | 457 | break; |
458 | 458 | |
459 | 459 | case 'verify' : |
460 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
460 | + $note = __('PayPal account is not verified. Verify account in order to accept this payment', 'invoicing'); |
|
461 | 461 | break; |
462 | 462 | |
463 | 463 | case 'other' : |
464 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
464 | + $note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing'); |
|
465 | 465 | break; |
466 | 466 | } |
467 | 467 | |
468 | - if ( ! empty( $note ) ) { |
|
469 | - wpinv_insert_payment_note( $invoice_id, $note ); |
|
468 | + if (!empty($note)) { |
|
469 | + wpinv_insert_payment_note($invoice_id, $note); |
|
470 | 470 | } |
471 | 471 | } else { |
472 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ) ); |
|
472 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal IPN has been received with invalid payment status: %s', 'invoicing'), $payment_status)); |
|
473 | 473 | } |
474 | 474 | } |
475 | 475 | } |
476 | -add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 ); |
|
476 | +add_action('wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2); |
|
477 | 477 | |
478 | 478 | // Process PayPal subscription sign ups |
479 | -add_action( 'wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup' ); |
|
479 | +add_action('wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup'); |
|
480 | 480 | |
481 | 481 | // Process PayPal subscription payments |
482 | -add_action( 'wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment' ); |
|
482 | +add_action('wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment'); |
|
483 | 483 | |
484 | 484 | // Process PayPal subscription cancellations |
485 | -add_action( 'wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel' ); |
|
485 | +add_action('wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel'); |
|
486 | 486 | |
487 | 487 | // Process PayPal subscription end of term notices |
488 | -add_action( 'wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot' ); |
|
488 | +add_action('wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot'); |
|
489 | 489 | |
490 | 490 | // Process PayPal payment failed |
491 | -add_action( 'wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed' ); |
|
491 | +add_action('wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed'); |
|
492 | 492 | |
493 | 493 | |
494 | 494 | /** |
495 | 495 | * Process the subscription started IPN. |
496 | 496 | */ |
497 | -function wpinv_process_paypal_subscr_signup( $ipn_data ) { |
|
498 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
499 | - if( empty( $parent_invoice_id ) ) { |
|
497 | +function wpinv_process_paypal_subscr_signup($ipn_data) { |
|
498 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
499 | + if (empty($parent_invoice_id)) { |
|
500 | 500 | return; |
501 | 501 | } |
502 | 502 | |
503 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
504 | - if ( empty( $invoice ) ) { |
|
503 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
504 | + if (empty($invoice)) { |
|
505 | 505 | return; |
506 | 506 | } |
507 | 507 | |
508 | - if ( $invoice->is_free_trial() && !empty( $ipn_data['invoice'] ) ) { |
|
509 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Invoice ID: %s', 'invoicing' ) , $ipn_data['invoice'] ) ); |
|
510 | - wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['invoice'] ); |
|
508 | + if ($invoice->is_free_trial() && !empty($ipn_data['invoice'])) { |
|
509 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Invoice ID: %s', 'invoicing'), $ipn_data['invoice'])); |
|
510 | + wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['invoice']); |
|
511 | 511 | } |
512 | 512 | |
513 | - wpinv_update_payment_status( $parent_invoice_id, 'publish' ); |
|
513 | + wpinv_update_payment_status($parent_invoice_id, 'publish'); |
|
514 | 514 | sleep(1); |
515 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ) ); |
|
515 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id'])); |
|
516 | 516 | |
517 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
518 | - if ( false === $subscription ) { |
|
517 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
518 | + if (false === $subscription) { |
|
519 | 519 | return; |
520 | 520 | } |
521 | 521 | |
522 | - $cart_details = $invoice->cart_details; |
|
522 | + $cart_details = $invoice->cart_details; |
|
523 | 523 | |
524 | - if ( !empty( $cart_details ) ) { |
|
525 | - foreach ( $cart_details as $cart_item ) { |
|
526 | - $item = new WPInv_Item( $cart_item['id'] ); |
|
524 | + if (!empty($cart_details)) { |
|
525 | + foreach ($cart_details as $cart_item) { |
|
526 | + $item = new WPInv_Item($cart_item['id']); |
|
527 | 527 | |
528 | 528 | $status = $invoice->is_free_trial() && $item->has_free_trial() ? 'trialing' : 'active'; |
529 | 529 | |
@@ -532,15 +532,15 @@ discard block |
||
532 | 532 | 'status' => $status, |
533 | 533 | 'period' => $item->get_recurring_period(), |
534 | 534 | 'initial_amount' => $invoice->get_total(), |
535 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
535 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
536 | 536 | 'interval' => $item->get_recurring_interval(), |
537 | 537 | 'bill_times' => $item->get_recurring_limit(), |
538 | - 'expiration' => $invoice->get_new_expiration( $cart_item['id'] ), |
|
538 | + 'expiration' => $invoice->get_new_expiration($cart_item['id']), |
|
539 | 539 | 'profile_id' => $ipn_data['subscr_id'], |
540 | - 'created' => date_i18n( 'Y-m-d H:i:s', strtotime( $ipn_data['subscr_date'] ) ) |
|
540 | + 'created' => date_i18n('Y-m-d H:i:s', strtotime($ipn_data['subscr_date'])) |
|
541 | 541 | ); |
542 | 542 | |
543 | - if ( $item->has_free_trial() ) { |
|
543 | + if ($item->has_free_trial()) { |
|
544 | 544 | $args['trial_period'] = $item->get_trial_period(); |
545 | 545 | $args['trial_interval'] = $item->get_trial_interval(); |
546 | 546 | } else { |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | } |
550 | 550 | |
551 | 551 | |
552 | - $subscription->update_subscription( $args ); |
|
552 | + $subscription->update_subscription($args); |
|
553 | 553 | } |
554 | 554 | } |
555 | 555 | } |
@@ -557,39 +557,39 @@ discard block |
||
557 | 557 | /** |
558 | 558 | * Process the subscription payment received IPN. |
559 | 559 | */ |
560 | -function wpinv_process_paypal_subscr_payment( $ipn_data ) { |
|
561 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
560 | +function wpinv_process_paypal_subscr_payment($ipn_data) { |
|
561 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
562 | 562 | |
563 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
564 | - if ( false === $subscription ) { |
|
563 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
564 | + if (false === $subscription) { |
|
565 | 565 | return; |
566 | 566 | } |
567 | 567 | |
568 | - $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id ); |
|
569 | - $signup_date = strtotime( $subscription->get_subscription_created() ); |
|
570 | - $today = date_i18n( 'Y-m-d', $signup_date ) == date_i18n( 'Y-m-d', strtotime( $ipn_data['payment_date'] ) ); |
|
568 | + $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id); |
|
569 | + $signup_date = strtotime($subscription->get_subscription_created()); |
|
570 | + $today = date_i18n('Y-m-d', $signup_date) == date_i18n('Y-m-d', strtotime($ipn_data['payment_date'])); |
|
571 | 571 | |
572 | 572 | // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet. |
573 | - if ( $today && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) { |
|
574 | - wpinv_update_payment_status( $parent_invoice_id, 'publish' ); |
|
573 | + if ($today && (!$transaction_id || $transaction_id == $parent_invoice_id)) { |
|
574 | + wpinv_update_payment_status($parent_invoice_id, 'publish'); |
|
575 | 575 | sleep(1); |
576 | 576 | |
577 | 577 | // This is the very first payment |
578 | - wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] ); |
|
579 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) ); |
|
578 | + wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']); |
|
579 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id'])); |
|
580 | 580 | return; |
581 | 581 | } |
582 | 582 | |
583 | - if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) { |
|
583 | + if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) { |
|
584 | 584 | return; // Payment already recorded |
585 | 585 | } |
586 | 586 | |
587 | - $currency_code = strtolower( $ipn_data['mc_currency'] ); |
|
587 | + $currency_code = strtolower($ipn_data['mc_currency']); |
|
588 | 588 | |
589 | 589 | // verify details |
590 | - if ( $currency_code != strtolower( wpinv_get_currency() ) ) { |
|
590 | + if ($currency_code != strtolower(wpinv_get_currency())) { |
|
591 | 591 | // the currency code is invalid |
592 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) ); |
|
592 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data))); |
|
593 | 593 | return; |
594 | 594 | } |
595 | 595 | |
@@ -598,11 +598,11 @@ discard block |
||
598 | 598 | 'transaction_id' => $ipn_data['txn_id'] |
599 | 599 | ); |
600 | 600 | |
601 | - $invoice = wpinv_recurring_add_subscription_payment( $parent_invoice_id, $args ); |
|
601 | + $invoice = wpinv_recurring_add_subscription_payment($parent_invoice_id, $args); |
|
602 | 602 | |
603 | - if ( !empty( $invoice ) ) { |
|
603 | + if (!empty($invoice)) { |
|
604 | 604 | sleep(1); |
605 | - wpinv_insert_payment_note( $invoice->ID, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) ); |
|
605 | + wpinv_insert_payment_note($invoice->ID, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id'])); |
|
606 | 606 | |
607 | 607 | $invoice->renew_subscription(); |
608 | 608 | } |
@@ -611,10 +611,10 @@ discard block |
||
611 | 611 | /** |
612 | 612 | * Process the subscription canceled IPN. |
613 | 613 | */ |
614 | -function wpinv_process_paypal_subscr_cancel( $ipn_data ) { |
|
615 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
614 | +function wpinv_process_paypal_subscr_cancel($ipn_data) { |
|
615 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
616 | 616 | |
617 | - if( false === $subscription ) { |
|
617 | + if (false === $subscription) { |
|
618 | 618 | return; |
619 | 619 | } |
620 | 620 | |
@@ -624,10 +624,10 @@ discard block |
||
624 | 624 | /** |
625 | 625 | * Process the subscription expired IPN. |
626 | 626 | */ |
627 | -function wpinv_process_paypal_subscr_eot( $ipn_data ) { |
|
628 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
627 | +function wpinv_process_paypal_subscr_eot($ipn_data) { |
|
628 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
629 | 629 | |
630 | - if( false === $subscription ) { |
|
630 | + if (false === $subscription) { |
|
631 | 631 | return; |
632 | 632 | } |
633 | 633 | |
@@ -637,45 +637,45 @@ discard block |
||
637 | 637 | /** |
638 | 638 | * Process the subscription payment failed IPN. |
639 | 639 | */ |
640 | -function wpinv_process_paypal_subscr_failed( $ipn_data ) { |
|
641 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
640 | +function wpinv_process_paypal_subscr_failed($ipn_data) { |
|
641 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
642 | 642 | |
643 | - if( false === $subscription ) { |
|
643 | + if (false === $subscription) { |
|
644 | 644 | return; |
645 | 645 | } |
646 | 646 | |
647 | 647 | $subscription->failing_subscription(); |
648 | 648 | |
649 | - do_action( 'wpinv_recurring_payment_failed', $subscription ); |
|
649 | + do_action('wpinv_recurring_payment_failed', $subscription); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | /** |
653 | 653 | * Retrieve the subscription this IPN notice is for. |
654 | 654 | */ |
655 | -function wpinv_get_paypal_subscription( $ipn_data = array() ) { |
|
656 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
655 | +function wpinv_get_paypal_subscription($ipn_data = array()) { |
|
656 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
657 | 657 | |
658 | - if( empty( $parent_invoice_id ) ) { |
|
658 | + if (empty($parent_invoice_id)) { |
|
659 | 659 | return false; |
660 | 660 | } |
661 | 661 | |
662 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
663 | - if ( empty( $invoice ) ) { |
|
662 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
663 | + if (empty($invoice)) { |
|
664 | 664 | return false; |
665 | 665 | } |
666 | 666 | |
667 | - $subscription = wpinv_get_subscription( $ipn_data['subscr_id'], true ); |
|
667 | + $subscription = wpinv_get_subscription($ipn_data['subscr_id'], true); |
|
668 | 668 | |
669 | - if ( empty( $subscription ) ) { |
|
670 | - $subs = wpinv_get_subscriptions( array( 'parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1 ) ); |
|
671 | - $subscription = reset( $subs ); |
|
669 | + if (empty($subscription)) { |
|
670 | + $subs = wpinv_get_subscriptions(array('parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1)); |
|
671 | + $subscription = reset($subs); |
|
672 | 672 | |
673 | - if ( $subscription && $subscription->ID > 0 ) { |
|
673 | + if ($subscription && $subscription->ID > 0) { |
|
674 | 674 | // Update the profile ID so it is set for future renewals |
675 | - $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) ); |
|
675 | + $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id']))); |
|
676 | 676 | } else { |
677 | 677 | $subscription = $invoice; |
678 | - $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) ); |
|
678 | + $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id']))); |
|
679 | 679 | // No subscription found with a matching payment ID, bail |
680 | 680 | //return false; |
681 | 681 | } |
@@ -685,39 +685,39 @@ discard block |
||
685 | 685 | |
686 | 686 | } |
687 | 687 | |
688 | -function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) { |
|
688 | +function wpinv_process_paypal_refund($data, $invoice_id = 0) { |
|
689 | 689 | // Collect payment details |
690 | 690 | |
691 | - if( empty( $invoice_id ) ) { |
|
691 | + if (empty($invoice_id)) { |
|
692 | 692 | return; |
693 | 693 | } |
694 | 694 | |
695 | - if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
695 | + if (get_post_status($invoice_id) == 'wpi-refunded') { |
|
696 | 696 | return; // Only refund payments once |
697 | 697 | } |
698 | 698 | |
699 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
699 | + $payment_amount = wpinv_payment_total($invoice_id); |
|
700 | 700 | $refund_amount = $data['mc_gross'] * -1; |
701 | 701 | |
702 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
703 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Partial PayPal refund processed: %s', 'invoicing' ), $data['parent_txn_id'] ) ); |
|
702 | + if (number_format((float)$refund_amount, 2) < number_format((float)$payment_amount, 2)) { |
|
703 | + wpinv_insert_payment_note($invoice_id, sprintf(__('Partial PayPal refund processed: %s', 'invoicing'), $data['parent_txn_id'])); |
|
704 | 704 | return; // This is a partial refund |
705 | 705 | } |
706 | 706 | |
707 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ) ); |
|
708 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ) ); |
|
709 | - wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
707 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code'])); |
|
708 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id'])); |
|
709 | + wpinv_update_payment_status($invoice_id, 'wpi-refunded'); |
|
710 | 710 | } |
711 | 711 | |
712 | -function wpinv_get_paypal_redirect( $ssl_check = false ) { |
|
713 | - if ( is_ssl() || ! $ssl_check ) { |
|
712 | +function wpinv_get_paypal_redirect($ssl_check = false) { |
|
713 | + if (is_ssl() || !$ssl_check) { |
|
714 | 714 | $protocol = 'https://'; |
715 | 715 | } else { |
716 | 716 | $protocol = 'http://'; |
717 | 717 | } |
718 | 718 | |
719 | 719 | // Check the current payment mode |
720 | - if ( wpinv_is_test_mode( 'paypal' ) ) { |
|
720 | + if (wpinv_is_test_mode('paypal')) { |
|
721 | 721 | // Test mode |
722 | 722 | $paypal_uri = $protocol . 'www.sandbox.paypal.com/cgi-bin/webscr'; |
723 | 723 | } else { |
@@ -725,67 +725,67 @@ discard block |
||
725 | 725 | $paypal_uri = $protocol . 'www.paypal.com/cgi-bin/webscr'; |
726 | 726 | } |
727 | 727 | |
728 | - return apply_filters( 'wpinv_paypal_uri', $paypal_uri ); |
|
728 | + return apply_filters('wpinv_paypal_uri', $paypal_uri); |
|
729 | 729 | } |
730 | 730 | |
731 | -function wpinv_paypal_success_page_content( $content ) { |
|
731 | +function wpinv_paypal_success_page_content($content) { |
|
732 | 732 | global $wpi_invoice; |
733 | 733 | |
734 | 734 | $session = wpinv_get_checkout_session(); |
735 | 735 | |
736 | - if ( empty( $_GET['invoice-id'] ) && empty( $session['invoice_key'] ) ) { |
|
736 | + if (empty($_GET['invoice-id']) && empty($session['invoice_key'])) { |
|
737 | 737 | return $content; |
738 | 738 | } |
739 | 739 | |
740 | - $invoice_id = !empty( $_GET['invoice-id'] ) ? absint( $_GET['invoice-id'] ) : wpinv_get_invoice_id_by_key( $session['invoice_key'] ); |
|
740 | + $invoice_id = !empty($_GET['invoice-id']) ? absint($_GET['invoice-id']) : wpinv_get_invoice_id_by_key($session['invoice_key']); |
|
741 | 741 | |
742 | - if ( empty( $invoice_id ) ) { |
|
742 | + if (empty($invoice_id)) { |
|
743 | 743 | return $content; |
744 | 744 | } |
745 | 745 | |
746 | - $wpi_invoice = wpinv_get_invoice( $invoice_id ); |
|
746 | + $wpi_invoice = wpinv_get_invoice($invoice_id); |
|
747 | 747 | |
748 | - if ( !empty( $wpi_invoice ) && 'pending' == $wpi_invoice->status ) { |
|
748 | + if (!empty($wpi_invoice) && 'pending' == $wpi_invoice->status) { |
|
749 | 749 | // Payment is still pending so show processing indicator to fix the Race Condition, issue # |
750 | 750 | ob_start(); |
751 | - wpinv_get_template_part( 'wpinv-payment-processing' ); |
|
751 | + wpinv_get_template_part('wpinv-payment-processing'); |
|
752 | 752 | $content = ob_get_clean(); |
753 | 753 | } |
754 | 754 | |
755 | 755 | return $content; |
756 | 756 | } |
757 | -add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' ); |
|
757 | +add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content'); |
|
758 | 758 | |
759 | -function wpinv_paypal_get_transaction_id( $invoice_id ) { |
|
759 | +function wpinv_paypal_get_transaction_id($invoice_id) { |
|
760 | 760 | $transaction_id = ''; |
761 | - $notes = wpinv_get_invoice_notes( $invoice_id ); |
|
761 | + $notes = wpinv_get_invoice_notes($invoice_id); |
|
762 | 762 | |
763 | - foreach ( $notes as $note ) { |
|
764 | - if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) { |
|
763 | + foreach ($notes as $note) { |
|
764 | + if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) { |
|
765 | 765 | $transaction_id = $match[1]; |
766 | 766 | continue; |
767 | 767 | } |
768 | 768 | } |
769 | 769 | |
770 | - return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id ); |
|
770 | + return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id); |
|
771 | 771 | } |
772 | -add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 ); |
|
772 | +add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1); |
|
773 | 773 | |
774 | -function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) { |
|
775 | - if ( $invoice->is_free_trial() || $transaction_id == $invoice_id ) { // Free trial does not have transaction at PayPal. |
|
774 | +function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) { |
|
775 | + if ($invoice->is_free_trial() || $transaction_id == $invoice_id) { // Free trial does not have transaction at PayPal. |
|
776 | 776 | $transaction_url = $invoice->get_view_url(); |
777 | 777 | } else { |
778 | - $sandbox = wpinv_is_test_mode( 'paypal' ) ? '.sandbox' : ''; |
|
778 | + $sandbox = wpinv_is_test_mode('paypal') ? '.sandbox' : ''; |
|
779 | 779 | $transaction_url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=' . $transaction_id; |
780 | 780 | } |
781 | 781 | |
782 | - $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>'; |
|
782 | + $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>'; |
|
783 | 783 | |
784 | - return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice ); |
|
784 | + return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice); |
|
785 | 785 | } |
786 | -add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 ); |
|
786 | +add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3); |
|
787 | 787 | |
788 | 788 | function wpinv_gateway_paypal_button_label($label) { |
789 | - return __( 'Proceed to PayPal', 'invoicing' ); |
|
789 | + return __('Proceed to PayPal', 'invoicing'); |
|
790 | 790 | } |
791 | -add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 ); |
|
792 | 791 | \ No newline at end of file |
792 | +add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1); |
|
793 | 793 | \ No newline at end of file |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_action( 'wpinv_worldpay_cc_form', '__return_false' ); |
|
5 | +add_action('wpinv_worldpay_cc_form', '__return_false'); |
|
6 | 6 | |
7 | -function wpinv_process_worldpay_payment( $purchase_data ) { |
|
8 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
9 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
7 | +function wpinv_process_worldpay_payment($purchase_data) { |
|
8 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
9 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | // Collect payment data |
@@ -24,120 +24,120 @@ discard block |
||
24 | 24 | ); |
25 | 25 | |
26 | 26 | // Record the pending payment |
27 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
27 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
28 | 28 | |
29 | - if ( !empty( $invoice ) ) { |
|
29 | + if (!empty($invoice)) { |
|
30 | 30 | $quantities_enabled = wpinv_item_quantities_enabled(); |
31 | 31 | |
32 | - $instId = wpinv_get_option( 'worldpay_instId', false ); |
|
32 | + $instId = wpinv_get_option('worldpay_instId', false); |
|
33 | 33 | $cartId = $invoice->get_number(); |
34 | - $testMode = wpinv_is_test_mode( 'worldpay' ) ? 100 : 0; |
|
34 | + $testMode = wpinv_is_test_mode('worldpay') ? 100 : 0; |
|
35 | 35 | $name = $invoice->get_user_full_name(); |
36 | - $address = wp_strip_all_tags( $invoice->get_address(), true ); |
|
36 | + $address = wp_strip_all_tags($invoice->get_address(), true); |
|
37 | 37 | $postcode = $invoice->zip; |
38 | 38 | $tel = $invoice->phone; |
39 | 39 | $email = $invoice->get_email(); |
40 | 40 | $country = $invoice->country; |
41 | - $amount = wpinv_sanitize_amount( $invoice->get_total() ); |
|
41 | + $amount = wpinv_sanitize_amount($invoice->get_total()); |
|
42 | 42 | $currency = wpinv_get_currency(); |
43 | 43 | |
44 | 44 | $items = array(); |
45 | - foreach ( $invoice->get_cart_details() as $item ) { |
|
45 | + foreach ($invoice->get_cart_details() as $item) { |
|
46 | 46 | $item_desc = $item['name']; |
47 | - $quantity = !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
48 | - $item_desc .= ' (' . ( $quantities_enabled ? $quantity . 'x ' : '' ) . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')'; |
|
47 | + $quantity = !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
48 | + $item_desc .= ' (' . ($quantities_enabled ? $quantity . 'x ' : '') . wpinv_price(wpinv_format_amount($item['item_price'])) . ')'; |
|
49 | 49 | |
50 | 50 | $items[] = $item_desc; |
51 | 51 | } |
52 | 52 | |
53 | - $desc = implode( ', ', $items ); |
|
54 | - if ( wpinv_use_taxes() && $invoice->get_tax() > 0 ) { |
|
55 | - $desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) ); |
|
53 | + $desc = implode(', ', $items); |
|
54 | + if (wpinv_use_taxes() && $invoice->get_tax() > 0) { |
|
55 | + $desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true)); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | $extra_params = array(); |
59 | 59 | $extra_params['MC_description'] = $desc; |
60 | - $extra_params['MC_callback'] = wpinv_get_ipn_url( 'worldpay' ); |
|
60 | + $extra_params['MC_callback'] = wpinv_get_ipn_url('worldpay'); |
|
61 | 61 | $extra_params['MC_key'] = $invoice->get_key(); |
62 | 62 | $extra_params['MC_invoice_id'] = $invoice->ID; |
63 | 63 | $extra_params['address1'] = $address; |
64 | 64 | $extra_params['town'] = $invoice->city; |
65 | 65 | $extra_params['region'] = $invoice->state; |
66 | - $extra_params['amountString'] = $invoice->get_total( true ); |
|
67 | - $extra_params['countryString'] = wpinv_country_name( $invoice->country ); |
|
66 | + $extra_params['amountString'] = $invoice->get_total(true); |
|
67 | + $extra_params['countryString'] = wpinv_country_name($invoice->country); |
|
68 | 68 | $extra_params['compName'] = $invoice->company; |
69 | 69 | |
70 | - $extra_params = apply_filters( 'wpinv_worldpay_form_extra_parameters', $extra_params, $invoice ); |
|
70 | + $extra_params = apply_filters('wpinv_worldpay_form_extra_parameters', $extra_params, $invoice); |
|
71 | 71 | |
72 | - $redirect_text = __( 'Redirecting to Worldpay site, click on button if not redirected.', 'invoicing' ); |
|
73 | - $redirect_text = apply_filters( 'wpinv_worldpay_redirect_text', $redirect_text, $invoice ); |
|
72 | + $redirect_text = __('Redirecting to Worldpay site, click on button if not redirected.', 'invoicing'); |
|
73 | + $redirect_text = apply_filters('wpinv_worldpay_redirect_text', $redirect_text, $invoice); |
|
74 | 74 | |
75 | 75 | // Empty the shopping cart |
76 | 76 | wpinv_empty_cart(); |
77 | 77 | ?> |
78 | 78 | <div class="wpi-worldpay-form" style="padding:20px;font-family:arial,sans-serif;text-align:center;color:#555"> |
79 | -<?php do_action( 'wpinv_worldpay_form_before', $invoice ); ?> |
|
80 | -<h3><?php echo $redirect_text ;?></h3> |
|
79 | +<?php do_action('wpinv_worldpay_form_before', $invoice); ?> |
|
80 | +<h3><?php echo $redirect_text; ?></h3> |
|
81 | 81 | <form action="<?php echo wpinv_get_worldpay_redirect(); ?>" name="wpi_worldpay_form" method="POST"> |
82 | - <input type="hidden" value="<?php echo $amount;?>" name="amount"> |
|
83 | - <input type="hidden" value="<?php echo esc_attr( $cartId );?>" name="cartId"> |
|
84 | - <input type="hidden" value="<?php echo $currency;?>" name="currency"> |
|
85 | - <input type="hidden" value="<?php echo $instId;?>" name="instId"> |
|
86 | - <input type="hidden" value="<?php echo $testMode;?>" name="testMode"> |
|
87 | - <input type="hidden" value="<?php echo esc_attr( $name );?>" name="name"> |
|
88 | - <input type="hidden" value="<?php echo esc_attr( $address );?>" name="address"> |
|
89 | - <input type="hidden" value="<?php echo esc_attr( $postcode );?>" name="postcode"> |
|
90 | - <input type="hidden" value="<?php echo esc_attr( $tel );?>" name="tel"> |
|
91 | - <input type="hidden" value="<?php echo esc_attr( $email );?>" name="email"> |
|
92 | - <input type="hidden" value="<?php echo esc_attr( $country );?>" name="country"> |
|
93 | - <input type="hidden" value="<?php echo esc_attr( $desc );?>" name="desc"> |
|
94 | - <?php foreach ( $extra_params as $param => $value ) { ?> |
|
95 | - <?php if ( !empty( $value !== false ) ) { ?> |
|
96 | - <input type="hidden" value="<?php echo esc_attr( $value );?>" name="<?php echo esc_attr( $param );?>"> |
|
82 | + <input type="hidden" value="<?php echo $amount; ?>" name="amount"> |
|
83 | + <input type="hidden" value="<?php echo esc_attr($cartId); ?>" name="cartId"> |
|
84 | + <input type="hidden" value="<?php echo $currency; ?>" name="currency"> |
|
85 | + <input type="hidden" value="<?php echo $instId; ?>" name="instId"> |
|
86 | + <input type="hidden" value="<?php echo $testMode; ?>" name="testMode"> |
|
87 | + <input type="hidden" value="<?php echo esc_attr($name); ?>" name="name"> |
|
88 | + <input type="hidden" value="<?php echo esc_attr($address); ?>" name="address"> |
|
89 | + <input type="hidden" value="<?php echo esc_attr($postcode); ?>" name="postcode"> |
|
90 | + <input type="hidden" value="<?php echo esc_attr($tel); ?>" name="tel"> |
|
91 | + <input type="hidden" value="<?php echo esc_attr($email); ?>" name="email"> |
|
92 | + <input type="hidden" value="<?php echo esc_attr($country); ?>" name="country"> |
|
93 | + <input type="hidden" value="<?php echo esc_attr($desc); ?>" name="desc"> |
|
94 | + <?php foreach ($extra_params as $param => $value) { ?> |
|
95 | + <?php if (!empty($value !== false)) { ?> |
|
96 | + <input type="hidden" value="<?php echo esc_attr($value); ?>" name="<?php echo esc_attr($param); ?>"> |
|
97 | 97 | <?php } ?> |
98 | 98 | <?php } ?> |
99 | - <?php do_action( 'wpinv_worldpay_form_parameters', $invoice ); ?> |
|
100 | - <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e( 'Pay by Debit/Credit Card (WorldPay)', 'invoicing' ) ;?>"> |
|
99 | + <?php do_action('wpinv_worldpay_form_parameters', $invoice); ?> |
|
100 | + <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e('Pay by Debit/Credit Card (WorldPay)', 'invoicing'); ?>"> |
|
101 | 101 | </form> |
102 | 102 | <script type="text/javascript">document.wpi_worldpay_form.submit();</script> |
103 | -<?php do_action( 'wpinv_worldpay_form_after', $invoice ); ?> |
|
103 | +<?php do_action('wpinv_worldpay_form_after', $invoice); ?> |
|
104 | 104 | </div> |
105 | 105 | <?php |
106 | 106 | } else { |
107 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
107 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice); |
|
108 | 108 | // If errors are present, send the user back to the purchase page so they can be corrected |
109 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
109 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
110 | 110 | } |
111 | 111 | } |
112 | -add_action( 'wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment' ); |
|
112 | +add_action('wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment'); |
|
113 | 113 | |
114 | 114 | function wpinv_get_worldpay_redirect() { |
115 | - $redirect = wpinv_is_test_mode( 'worldpay' ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
115 | + $redirect = wpinv_is_test_mode('worldpay') ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
116 | 116 | |
117 | - return apply_filters( 'wpinv_worldpay_redirect', $redirect ); |
|
117 | + return apply_filters('wpinv_worldpay_redirect', $redirect); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | function wpinv_process_worldpay_ipn() { |
121 | - $request = wpinv_get_post_data( 'post' ); |
|
121 | + $request = wpinv_get_post_data('post'); |
|
122 | 122 | |
123 | - if ( !empty( $request['cartId'] ) && !empty( $request['transStatus'] ) && !empty( $request['installation'] ) && isset( $request['testMode'] ) && isset( $request['MC_invoice_id'] ) && isset( $request['MC_key'] ) ) { |
|
123 | + if (!empty($request['cartId']) && !empty($request['transStatus']) && !empty($request['installation']) && isset($request['testMode']) && isset($request['MC_invoice_id']) && isset($request['MC_key'])) { |
|
124 | 124 | $invoice_id = $request['MC_invoice_id']; |
125 | 125 | |
126 | - if ( $invoice_id == wpinv_get_invoice_id_by_key( $request['MC_key'] ) && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
127 | - if ( $request['transStatus'] == 'Y' ) { |
|
128 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
129 | - wpinv_set_payment_transaction_id( $invoice_id, $request['transId'] ); |
|
130 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Worldpay Transaction ID: %s', 'invoicing' ), $request['transId'] ) ); |
|
126 | + if ($invoice_id == wpinv_get_invoice_id_by_key($request['MC_key']) && $invoice = wpinv_get_invoice($invoice_id)) { |
|
127 | + if ($request['transStatus'] == 'Y') { |
|
128 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
129 | + wpinv_set_payment_transaction_id($invoice_id, $request['transId']); |
|
130 | + wpinv_insert_payment_note($invoice_id, sprintf(__('Worldpay Transaction ID: %s', 'invoicing'), $request['transId'])); |
|
131 | 131 | return; |
132 | - } else if ( $request['transStatus'] == 'C' ) { |
|
133 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
134 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing' ) ); |
|
132 | + } else if ($request['transStatus'] == 'C') { |
|
133 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
134 | + wpinv_insert_payment_note($invoice_id, __('Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing')); |
|
135 | 135 | |
136 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing' ), json_encode( $request ) ), $invoice_id ); |
|
136 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing'), json_encode($request)), $invoice_id); |
|
137 | 137 | return; |
138 | 138 | } |
139 | 139 | } |
140 | 140 | } |
141 | 141 | return; |
142 | 142 | } |
143 | -add_action( 'wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn' ); |
|
144 | 143 | \ No newline at end of file |
144 | +add_action('wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn'); |
|
145 | 145 | \ No newline at end of file |