@@ -7,172 +7,172 @@ 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_is_checkout() { |
15 | 15 | global $wp_query; |
16 | 16 | |
17 | - $is_object_set = isset( $wp_query->queried_object ); |
|
18 | - $is_object_id_set = isset( $wp_query->queried_object_id ); |
|
19 | - $checkout_page = wpinv_get_option( 'checkout_page' ); |
|
20 | - $is_checkout = ! empty( $checkout_page ) && is_page( $checkout_page ); |
|
17 | + $is_object_set = isset($wp_query->queried_object); |
|
18 | + $is_object_id_set = isset($wp_query->queried_object_id); |
|
19 | + $checkout_page = wpinv_get_option('checkout_page'); |
|
20 | + $is_checkout = !empty($checkout_page) && is_page($checkout_page); |
|
21 | 21 | |
22 | - if ( !$is_object_set ) { |
|
23 | - unset( $wp_query->queried_object ); |
|
22 | + if (!$is_object_set) { |
|
23 | + unset($wp_query->queried_object); |
|
24 | 24 | } |
25 | 25 | |
26 | - if ( !$is_object_id_set ) { |
|
27 | - unset( $wp_query->queried_object_id ); |
|
26 | + if (!$is_object_id_set) { |
|
27 | + unset($wp_query->queried_object_id); |
|
28 | 28 | } |
29 | 29 | |
30 | - return apply_filters( 'wpinv_is_checkout', $is_checkout ); |
|
30 | + return apply_filters('wpinv_is_checkout', $is_checkout); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | function wpinv_can_checkout() { |
34 | 34 | $can_checkout = true; // Always true for now |
35 | 35 | |
36 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
36 | + return (bool) apply_filters('wpinv_can_checkout', $can_checkout); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | function wpinv_get_success_page_uri() { |
40 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
41 | - $page_id = absint( $page_id ); |
|
40 | + $page_id = wpinv_get_option('success_page', 0); |
|
41 | + $page_id = absint($page_id); |
|
42 | 42 | |
43 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
43 | + return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id)); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | function wpinv_get_history_page_uri() { |
47 | - $page_id = wpinv_get_option( 'invoice_history_page', 0 ); |
|
48 | - $page_id = absint( $page_id ); |
|
47 | + $page_id = wpinv_get_option('invoice_history_page', 0); |
|
48 | + $page_id = absint($page_id); |
|
49 | 49 | |
50 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) ); |
|
50 | + return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id)); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | function wpinv_is_success_page() { |
54 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
55 | - $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
54 | + $is_success_page = wpinv_get_option('success_page', false); |
|
55 | + $is_success_page = !empty($is_success_page) ? is_page($is_success_page) : false; |
|
56 | 56 | |
57 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
57 | + return apply_filters('wpinv_is_success_page', $is_success_page); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | function wpinv_is_invoice_history_page() { |
61 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
62 | - $ret = $ret ? is_page( $ret ) : false; |
|
63 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
61 | + $ret = wpinv_get_option('invoice_history_page', false); |
|
62 | + $ret = $ret ? is_page($ret) : false; |
|
63 | + return apply_filters('wpinv_is_invoice_history_page', $ret); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | function wpinv_is_subscriptions_history_page() { |
67 | - $ret = wpinv_get_option( 'invoice_subscription_page', false ); |
|
68 | - $ret = $ret ? is_page( $ret ) : false; |
|
69 | - return apply_filters( 'wpinv_is_subscriptions_history_page', $ret ); |
|
67 | + $ret = wpinv_get_option('invoice_subscription_page', false); |
|
68 | + $ret = $ret ? is_page($ret) : false; |
|
69 | + return apply_filters('wpinv_is_subscriptions_history_page', $ret); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Redirects a user the success page. |
74 | 74 | */ |
75 | -function wpinv_send_to_success_page( $args = array() ) { |
|
75 | +function wpinv_send_to_success_page($args = array()) { |
|
76 | 76 | $redirect = add_query_arg( |
77 | - wp_parse_args( $args ), |
|
77 | + wp_parse_args($args), |
|
78 | 78 | wpinv_get_success_page_uri() |
79 | 79 | ); |
80 | 80 | |
81 | - wp_redirect( $redirect ); |
|
81 | + wp_redirect($redirect); |
|
82 | 82 | exit; |
83 | 83 | } |
84 | 84 | |
85 | -function wpinv_send_to_failed_page( $args = null ) { |
|
85 | +function wpinv_send_to_failed_page($args = null) { |
|
86 | 86 | $redirect = wpinv_get_failed_transaction_uri(); |
87 | 87 | |
88 | - if ( !empty( $args ) ) { |
|
88 | + if (!empty($args)) { |
|
89 | 89 | // Check for backward compatibility |
90 | - if ( is_string( $args ) ) |
|
91 | - $args = str_replace( '?', '', $args ); |
|
90 | + if (is_string($args)) |
|
91 | + $args = str_replace('?', '', $args); |
|
92 | 92 | |
93 | - $args = wp_parse_args( $args ); |
|
93 | + $args = wp_parse_args($args); |
|
94 | 94 | |
95 | - $redirect = add_query_arg( $args, $redirect ); |
|
95 | + $redirect = add_query_arg($args, $redirect); |
|
96 | 96 | } |
97 | 97 | |
98 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : ''; |
|
98 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : ''; |
|
99 | 99 | |
100 | - $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args ); |
|
101 | - wp_redirect( $redirect ); |
|
100 | + $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args); |
|
101 | + wp_redirect($redirect); |
|
102 | 102 | exit; |
103 | 103 | } |
104 | 104 | |
105 | -function wpinv_get_checkout_uri( $args = array() ) { |
|
106 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
107 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
105 | +function wpinv_get_checkout_uri($args = array()) { |
|
106 | + $uri = wpinv_get_option('checkout_page', false); |
|
107 | + $uri = isset($uri) ? get_permalink($uri) : NULL; |
|
108 | 108 | |
109 | - if ( !empty( $args ) ) { |
|
109 | + if (!empty($args)) { |
|
110 | 110 | // Check for backward compatibility |
111 | - if ( is_string( $args ) ) |
|
112 | - $args = str_replace( '?', '', $args ); |
|
111 | + if (is_string($args)) |
|
112 | + $args = str_replace('?', '', $args); |
|
113 | 113 | |
114 | - $args = wp_parse_args( $args ); |
|
114 | + $args = wp_parse_args($args); |
|
115 | 115 | |
116 | - $uri = add_query_arg( $args, $uri ); |
|
116 | + $uri = add_query_arg($args, $uri); |
|
117 | 117 | } |
118 | 118 | |
119 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
119 | + $scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
120 | 120 | |
121 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
121 | + $ajax_url = admin_url('admin-ajax.php', $scheme); |
|
122 | 122 | |
123 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
124 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
123 | + if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) { |
|
124 | + $uri = preg_replace('/^http:/', 'https:', $uri); |
|
125 | 125 | } |
126 | 126 | |
127 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
127 | + return apply_filters('wpinv_get_checkout_uri', $uri); |
|
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_get_success_page_url( $query_string = null ) { |
|
131 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
132 | - $success_page = get_permalink( $success_page ); |
|
130 | +function wpinv_get_success_page_url($query_string = null) { |
|
131 | + $success_page = wpinv_get_option('success_page', 0); |
|
132 | + $success_page = get_permalink($success_page); |
|
133 | 133 | |
134 | - if ( $query_string ) |
|
134 | + if ($query_string) |
|
135 | 135 | $success_page .= $query_string; |
136 | 136 | |
137 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
137 | + return apply_filters('wpinv_success_page_url', $success_page); |
|
138 | 138 | } |
139 | 139 | |
140 | -function wpinv_get_failed_transaction_uri( $extras = false ) { |
|
141 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
142 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
140 | +function wpinv_get_failed_transaction_uri($extras = false) { |
|
141 | + $uri = wpinv_get_option('failure_page', ''); |
|
142 | + $uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url(); |
|
143 | 143 | |
144 | - if ( $extras ) |
|
144 | + if ($extras) |
|
145 | 145 | $uri .= $extras; |
146 | 146 | |
147 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
147 | + return apply_filters('wpinv_get_failed_transaction_uri', $uri); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | function wpinv_is_failed_transaction_page() { |
151 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
152 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
151 | + $ret = wpinv_get_option('failure_page', false); |
|
152 | + $ret = isset($ret) ? is_page($ret) : false; |
|
153 | 153 | |
154 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
154 | + return apply_filters('wpinv_is_failure_page', $ret); |
|
155 | 155 | } |
156 | 156 | |
157 | -function wpinv_transaction_query( $type = 'start' ) { |
|
157 | +function wpinv_transaction_query($type = 'start') { |
|
158 | 158 | global $wpdb; |
159 | 159 | |
160 | 160 | $wpdb->hide_errors(); |
161 | 161 | |
162 | - if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) { |
|
163 | - define( 'WPINV_USE_TRANSACTIONS', true ); |
|
162 | + if (!defined('WPINV_USE_TRANSACTIONS')) { |
|
163 | + define('WPINV_USE_TRANSACTIONS', true); |
|
164 | 164 | } |
165 | 165 | |
166 | - if ( WPINV_USE_TRANSACTIONS ) { |
|
167 | - switch ( $type ) { |
|
166 | + if (WPINV_USE_TRANSACTIONS) { |
|
167 | + switch ($type) { |
|
168 | 168 | case 'commit' : |
169 | - $wpdb->query( 'COMMIT' ); |
|
169 | + $wpdb->query('COMMIT'); |
|
170 | 170 | break; |
171 | 171 | case 'rollback' : |
172 | - $wpdb->query( 'ROLLBACK' ); |
|
172 | + $wpdb->query('ROLLBACK'); |
|
173 | 173 | break; |
174 | 174 | default : |
175 | - $wpdb->query( 'START TRANSACTION' ); |
|
175 | + $wpdb->query('START TRANSACTION'); |
|
176 | 176 | break; |
177 | 177 | } |
178 | 178 | } |
@@ -181,141 +181,141 @@ discard block |
||
181 | 181 | function wpinv_get_prefix() { |
182 | 182 | $invoice_prefix = 'INV-'; |
183 | 183 | |
184 | - return apply_filters( 'wpinv_get_prefix', $invoice_prefix ); |
|
184 | + return apply_filters('wpinv_get_prefix', $invoice_prefix); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | function wpinv_get_business_logo() { |
188 | - $business_logo = wpinv_get_option( 'logo' ); |
|
189 | - return apply_filters( 'wpinv_get_business_logo', $business_logo ); |
|
188 | + $business_logo = wpinv_get_option('logo'); |
|
189 | + return apply_filters('wpinv_get_business_logo', $business_logo); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | function wpinv_get_business_name() { |
193 | 193 | $business_name = wpinv_get_option('store_name'); |
194 | - return apply_filters( 'wpinv_get_business_name', $business_name ); |
|
194 | + return apply_filters('wpinv_get_business_name', $business_name); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | function wpinv_get_blogname() { |
198 | - return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
198 | + return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | function wpinv_get_admin_email() { |
202 | - $admin_email = wpinv_get_option( 'admin_email', get_option( 'admin_email' ) ); |
|
203 | - return apply_filters( 'wpinv_admin_email', $admin_email ); |
|
202 | + $admin_email = wpinv_get_option('admin_email', get_option('admin_email')); |
|
203 | + return apply_filters('wpinv_admin_email', $admin_email); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | function wpinv_get_business_website() { |
207 | - $business_website = home_url( '/' ); |
|
208 | - return apply_filters( 'wpinv_get_business_website', $business_website ); |
|
207 | + $business_website = home_url('/'); |
|
208 | + return apply_filters('wpinv_get_business_website', $business_website); |
|
209 | 209 | } |
210 | 210 | |
211 | -function wpinv_get_terms_text( $invoice_id = 0 ) { |
|
211 | +function wpinv_get_terms_text($invoice_id = 0) { |
|
212 | 212 | $terms_text = ''; |
213 | - return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id ); |
|
213 | + return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | function wpinv_get_business_footer() { |
217 | - $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>'; |
|
218 | - $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link ); |
|
219 | - return apply_filters( 'wpinv_get_business_footer', $business_footer ); |
|
217 | + $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>'; |
|
218 | + $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link); |
|
219 | + return apply_filters('wpinv_get_business_footer', $business_footer); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | function wpinv_checkout_required_fields() { |
223 | 223 | $required_fields = array(); |
224 | 224 | |
225 | 225 | // Let payment gateways and other extensions determine if address fields should be required |
226 | - $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
|
226 | + $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes()); |
|
227 | 227 | |
228 | - if ( $require_billing_details ) { |
|
229 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
228 | + if ($require_billing_details) { |
|
229 | + if ((bool) wpinv_get_option('fname_mandatory')) { |
|
230 | 230 | $required_fields['first_name'] = array( |
231 | 231 | 'error_id' => 'invalid_first_name', |
232 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
232 | + 'error_message' => __('Please enter your first name', 'invoicing') |
|
233 | 233 | ); |
234 | 234 | } |
235 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
235 | + if ((bool) wpinv_get_option('address_mandatory')) { |
|
236 | 236 | $required_fields['address'] = array( |
237 | 237 | 'error_id' => 'invalid_address', |
238 | - 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
238 | + 'error_message' => __('Please enter your address', 'invoicing') |
|
239 | 239 | ); |
240 | 240 | } |
241 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
241 | + if ((bool) wpinv_get_option('city_mandatory')) { |
|
242 | 242 | $required_fields['city'] = array( |
243 | 243 | 'error_id' => 'invalid_city', |
244 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
244 | + 'error_message' => __('Please enter your billing city', 'invoicing') |
|
245 | 245 | ); |
246 | 246 | } |
247 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
247 | + if ((bool) wpinv_get_option('state_mandatory')) { |
|
248 | 248 | $required_fields['state'] = array( |
249 | 249 | 'error_id' => 'invalid_state', |
250 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
250 | + 'error_message' => __('Please enter billing state / province', 'invoicing') |
|
251 | 251 | ); |
252 | 252 | } |
253 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
253 | + if ((bool) wpinv_get_option('country_mandatory')) { |
|
254 | 254 | $required_fields['country'] = array( |
255 | 255 | 'error_id' => 'invalid_country', |
256 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
256 | + 'error_message' => __('Please select your billing country', 'invoicing') |
|
257 | 257 | ); |
258 | 258 | } |
259 | 259 | } |
260 | 260 | |
261 | - return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
|
261 | + return apply_filters('wpinv_checkout_required_fields', $required_fields); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | function wpinv_is_ssl_enforced() { |
265 | - $ssl_enforced = wpinv_get_option( 'enforce_ssl', false ); |
|
266 | - return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced ); |
|
265 | + $ssl_enforced = wpinv_get_option('enforce_ssl', false); |
|
266 | + return (bool) apply_filters('wpinv_is_ssl_enforced', $ssl_enforced); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | function wpinv_schedule_event_twicedaily() { |
270 | 270 | wpinv_email_payment_reminders(); |
271 | 271 | } |
272 | -add_action( 'wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily' ); |
|
272 | +add_action('wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily'); |
|
273 | 273 | |
274 | 274 | function wpinv_require_login_to_checkout() { |
275 | - $return = wpinv_get_option( 'login_to_checkout', false ); |
|
276 | - return (bool) apply_filters( 'wpinv_require_login_to_checkout', $return ); |
|
275 | + $return = wpinv_get_option('login_to_checkout', false); |
|
276 | + return (bool) apply_filters('wpinv_require_login_to_checkout', $return); |
|
277 | 277 | } |
278 | 278 | |
279 | -function wpinv_sequential_number_active( $type = '' ) { |
|
280 | - $check = apply_filters( 'wpinv_pre_check_sequential_number_active', null, $type ); |
|
281 | - if ( null !== $check ) { |
|
279 | +function wpinv_sequential_number_active($type = '') { |
|
280 | + $check = apply_filters('wpinv_pre_check_sequential_number_active', null, $type); |
|
281 | + if (null !== $check) { |
|
282 | 282 | return $check; |
283 | 283 | } |
284 | 284 | |
285 | - return wpinv_get_option( 'sequential_invoice_number' ); |
|
285 | + return wpinv_get_option('sequential_invoice_number'); |
|
286 | 286 | } |
287 | 287 | |
288 | -function wpinv_switch_to_locale( $locale = NULL ) { |
|
288 | +function wpinv_switch_to_locale($locale = NULL) { |
|
289 | 289 | global $invoicing, $wpi_switch_locale; |
290 | 290 | |
291 | - if ( ! empty( $invoicing ) && function_exists( 'switch_to_locale' ) ) { |
|
292 | - $locale = empty( $locale ) ? get_locale() : $locale; |
|
291 | + if (!empty($invoicing) && function_exists('switch_to_locale')) { |
|
292 | + $locale = empty($locale) ? get_locale() : $locale; |
|
293 | 293 | |
294 | - switch_to_locale( $locale ); |
|
294 | + switch_to_locale($locale); |
|
295 | 295 | |
296 | 296 | $wpi_switch_locale = $locale; |
297 | 297 | |
298 | - add_filter( 'plugin_locale', 'get_locale' ); |
|
298 | + add_filter('plugin_locale', 'get_locale'); |
|
299 | 299 | |
300 | 300 | $invoicing->load_textdomain(); |
301 | 301 | |
302 | - do_action( 'wpinv_switch_to_locale', $locale ); |
|
302 | + do_action('wpinv_switch_to_locale', $locale); |
|
303 | 303 | } |
304 | 304 | } |
305 | 305 | |
306 | 306 | function wpinv_restore_locale() { |
307 | 307 | global $invoicing, $wpi_switch_locale; |
308 | 308 | |
309 | - if ( ! empty( $invoicing ) && function_exists( 'restore_previous_locale' ) && $wpi_switch_locale ) { |
|
309 | + if (!empty($invoicing) && function_exists('restore_previous_locale') && $wpi_switch_locale) { |
|
310 | 310 | restore_previous_locale(); |
311 | 311 | |
312 | 312 | $wpi_switch_locale = NULL; |
313 | 313 | |
314 | - remove_filter( 'plugin_locale', 'get_locale' ); |
|
314 | + remove_filter('plugin_locale', 'get_locale'); |
|
315 | 315 | |
316 | 316 | $invoicing->load_textdomain(); |
317 | 317 | |
318 | - do_action( 'wpinv_restore_locale' ); |
|
318 | + do_action('wpinv_restore_locale'); |
|
319 | 319 | } |
320 | 320 | } |
321 | 321 | |
@@ -323,22 +323,22 @@ discard block |
||
323 | 323 | * Returns the default form's id. |
324 | 324 | */ |
325 | 325 | function wpinv_get_default_payment_form() { |
326 | - $form = get_option( 'wpinv_default_payment_form' ); |
|
326 | + $form = get_option('wpinv_default_payment_form'); |
|
327 | 327 | |
328 | - if ( empty( $form ) || 'publish' != get_post_status( $form ) ) { |
|
328 | + if (empty($form) || 'publish' != get_post_status($form)) { |
|
329 | 329 | $form = wp_insert_post( |
330 | 330 | array( |
331 | 331 | 'post_type' => 'wpi_payment_form', |
332 | - 'post_title' => __( 'Checkout (default)', 'invoicing' ), |
|
332 | + 'post_title' => __('Checkout (default)', 'invoicing'), |
|
333 | 333 | 'post_status' => 'publish', |
334 | 334 | 'meta_input' => array( |
335 | - 'wpinv_form_elements' => wpinv_get_data( 'default-payment-form' ), |
|
335 | + 'wpinv_form_elements' => wpinv_get_data('default-payment-form'), |
|
336 | 336 | 'wpinv_form_items' => array(), |
337 | 337 | ) |
338 | 338 | ) |
339 | 339 | ); |
340 | 340 | |
341 | - update_option( 'wpinv_default_payment_form', $form ); |
|
341 | + update_option('wpinv_default_payment_form', $form); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | return $form; |
@@ -349,19 +349,19 @@ discard block |
||
349 | 349 | * |
350 | 350 | * @param int $payment_form |
351 | 351 | */ |
352 | -function getpaid_get_payment_form_elements( $payment_form ) { |
|
352 | +function getpaid_get_payment_form_elements($payment_form) { |
|
353 | 353 | |
354 | - if ( empty( $payment_form ) ) { |
|
355 | - return wpinv_get_data( 'sample-payment-form' ); |
|
354 | + if (empty($payment_form)) { |
|
355 | + return wpinv_get_data('sample-payment-form'); |
|
356 | 356 | } |
357 | 357 | |
358 | - $form_elements = get_post_meta( $payment_form, 'wpinv_form_elements', true ); |
|
358 | + $form_elements = get_post_meta($payment_form, 'wpinv_form_elements', true); |
|
359 | 359 | |
360 | - if ( is_array( $form_elements ) ) { |
|
360 | + if (is_array($form_elements)) { |
|
361 | 361 | return $form_elements; |
362 | 362 | } |
363 | 363 | |
364 | - return wpinv_get_data( 'sample-payment-form' ); |
|
364 | + return wpinv_get_data('sample-payment-form'); |
|
365 | 365 | |
366 | 366 | } |
367 | 367 | |
@@ -370,13 +370,13 @@ discard block |
||
370 | 370 | * |
371 | 371 | * @param int $payment_form |
372 | 372 | */ |
373 | -function gepaid_get_form_items( $id ) { |
|
374 | - $form = new GetPaid_Payment_Form( $id ); |
|
373 | +function gepaid_get_form_items($id) { |
|
374 | + $form = new GetPaid_Payment_Form($id); |
|
375 | 375 | |
376 | 376 | // Is this a default form? |
377 | - if ( $form->is_default() ) { |
|
377 | + if ($form->is_default()) { |
|
378 | 378 | return array(); |
379 | 379 | } |
380 | -wpinv_error_log( $form->get_items( 'view', 'arrays' ) ); |
|
381 | - return $form->get_items( 'view', 'arrays' ); |
|
380 | +wpinv_error_log($form->get_items('view', 'arrays')); |
|
381 | + return $form->get_items('view', 'arrays'); |
|
382 | 382 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * WPInv_Ajax class. |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | * Hook in ajax handlers. |
18 | 18 | */ |
19 | 19 | public static function init() { |
20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
20 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
21 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
22 | 22 | self::add_ajax_events(); |
23 | 23 | } |
24 | 24 | |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public static function define_ajax() { |
29 | 29 | |
30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
30 | + if (!empty($_GET['wpinv-ajax'])) { |
|
31 | + getpaid_maybe_define_constant('DOING_AJAX', true); |
|
32 | + getpaid_maybe_define_constant('WPInv_DOING_AJAX', true); |
|
33 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
34 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
35 | 35 | } |
36 | 36 | $GLOBALS['wpdb']->hide_errors(); |
37 | 37 | } |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | * @since 1.0.18 |
45 | 45 | */ |
46 | 46 | private static function wpinv_ajax_headers() { |
47 | - if ( ! headers_sent() ) { |
|
47 | + if (!headers_sent()) { |
|
48 | 48 | send_origin_headers(); |
49 | 49 | send_nosniff_header(); |
50 | 50 | nocache_headers(); |
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
51 | + header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
52 | + header('X-Robots-Tag: noindex'); |
|
53 | + status_header(200); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
@@ -60,16 +60,16 @@ discard block |
||
60 | 60 | public static function do_wpinv_ajax() { |
61 | 61 | global $wp_query; |
62 | 62 | |
63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
63 | + if (!empty($_GET['wpinv-ajax'])) { |
|
64 | + $wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax']))); |
|
65 | 65 | } |
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get('wpinv-ajax'); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
69 | + if ($action) { |
|
70 | 70 | self::wpinv_ajax_headers(); |
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
71 | + $action = sanitize_text_field($action); |
|
72 | + do_action('wpinv_ajax_' . $action); |
|
73 | 73 | wp_die(); |
74 | 74 | } |
75 | 75 | |
@@ -102,36 +102,36 @@ discard block |
||
102 | 102 | 'ip_geolocation' => true, |
103 | 103 | ); |
104 | 104 | |
105 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
106 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
107 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
105 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
106 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
107 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
108 | 108 | |
109 | - if ( $nopriv ) { |
|
110 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
111 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
112 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
109 | + if ($nopriv) { |
|
110 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
111 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
112 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
117 | 117 | public static function add_note() { |
118 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
118 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
119 | 119 | |
120 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
120 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
121 | 121 | die(-1); |
122 | 122 | } |
123 | 123 | |
124 | - $post_id = absint( $_POST['post_id'] ); |
|
125 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
126 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
124 | + $post_id = absint($_POST['post_id']); |
|
125 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
126 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
127 | 127 | |
128 | 128 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
129 | 129 | |
130 | - if ( $post_id > 0 ) { |
|
131 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
130 | + if ($post_id > 0) { |
|
131 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
132 | 132 | |
133 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
134 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
133 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
134 | + wpinv_get_invoice_note_line_item($note_id); |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
@@ -139,16 +139,16 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | public static function delete_note() { |
142 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
142 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
143 | 143 | |
144 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
144 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
145 | 145 | die(-1); |
146 | 146 | } |
147 | 147 | |
148 | - $note_id = (int)$_POST['note_id']; |
|
148 | + $note_id = (int) $_POST['note_id']; |
|
149 | 149 | |
150 | - if ( $note_id > 0 ) { |
|
151 | - wp_delete_comment( $note_id, true ); |
|
150 | + if ($note_id > 0) { |
|
151 | + wp_delete_comment($note_id, true); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | die(); |
@@ -166,34 +166,34 @@ discard block |
||
166 | 166 | public static function get_billing_details() { |
167 | 167 | |
168 | 168 | // Verify nonce. |
169 | - check_ajax_referer( 'wpinv-nonce' ); |
|
169 | + check_ajax_referer('wpinv-nonce'); |
|
170 | 170 | |
171 | 171 | // Can the user manage the plugin? |
172 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
172 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
173 | 173 | die(-1); |
174 | 174 | } |
175 | 175 | |
176 | 176 | // Do we have a user id? |
177 | 177 | $user_id = $_GET['user_id']; |
178 | 178 | |
179 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
179 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
180 | 180 | die(-1); |
181 | 181 | } |
182 | 182 | |
183 | 183 | // Fetch the billing details. |
184 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
185 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
184 | + $billing_details = wpinv_get_user_address($user_id); |
|
185 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
186 | 186 | |
187 | 187 | // unset the user id and email. |
188 | - $to_ignore = array( 'user_id', 'email' ); |
|
188 | + $to_ignore = array('user_id', 'email'); |
|
189 | 189 | |
190 | - foreach ( $to_ignore as $key ) { |
|
191 | - if ( isset( $billing_details[ $key ] ) ) { |
|
192 | - unset( $billing_details[ $key ] ); |
|
190 | + foreach ($to_ignore as $key) { |
|
191 | + if (isset($billing_details[$key])) { |
|
192 | + unset($billing_details[$key]); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
196 | - wp_send_json_success( $billing_details ); |
|
196 | + wp_send_json_success($billing_details); |
|
197 | 197 | |
198 | 198 | } |
199 | 199 | |
@@ -203,47 +203,47 @@ discard block |
||
203 | 203 | public static function check_new_user_email() { |
204 | 204 | |
205 | 205 | // Verify nonce. |
206 | - check_ajax_referer( 'wpinv-nonce' ); |
|
206 | + check_ajax_referer('wpinv-nonce'); |
|
207 | 207 | |
208 | 208 | // Can the user manage the plugin? |
209 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
209 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
210 | 210 | die(-1); |
211 | 211 | } |
212 | 212 | |
213 | 213 | // We need an email address. |
214 | - if ( empty( $_GET['email'] ) ) { |
|
215 | - _e( "Provide the new user's email address", 'invoicing' ); |
|
214 | + if (empty($_GET['email'])) { |
|
215 | + _e("Provide the new user's email address", 'invoicing'); |
|
216 | 216 | exit; |
217 | 217 | } |
218 | 218 | |
219 | 219 | // Ensure the email is valid. |
220 | - $email = sanitize_text_field( $_GET['email'] ); |
|
221 | - if ( ! is_email( $email ) ) { |
|
222 | - _e( 'Invalid email address', 'invoicing' ); |
|
220 | + $email = sanitize_text_field($_GET['email']); |
|
221 | + if (!is_email($email)) { |
|
222 | + _e('Invalid email address', 'invoicing'); |
|
223 | 223 | exit; |
224 | 224 | } |
225 | 225 | |
226 | 226 | // And it does not exist. |
227 | - if ( email_exists( $email ) ) { |
|
228 | - _e( 'A user with this email address already exists', 'invoicing' ); |
|
227 | + if (email_exists($email)) { |
|
228 | + _e('A user with this email address already exists', 'invoicing'); |
|
229 | 229 | exit; |
230 | 230 | } |
231 | 231 | |
232 | - wp_send_json_success( true ); |
|
232 | + wp_send_json_success(true); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | public static function run_tool() { |
236 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
237 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
236 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
237 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
238 | 238 | die(-1); |
239 | 239 | } |
240 | 240 | |
241 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
241 | + $tool = sanitize_text_field($_POST['tool']); |
|
242 | 242 | |
243 | - do_action( 'wpinv_run_tool' ); |
|
243 | + do_action('wpinv_run_tool'); |
|
244 | 244 | |
245 | - if ( !empty( $tool ) ) { |
|
246 | - do_action( 'wpinv_tool_' . $tool ); |
|
245 | + if (!empty($tool)) { |
|
246 | + do_action('wpinv_tool_' . $tool); |
|
247 | 247 | } |
248 | 248 | } |
249 | 249 | |
@@ -253,30 +253,30 @@ discard block |
||
253 | 253 | public static function get_payment_form() { |
254 | 254 | |
255 | 255 | // Check nonce. |
256 | - if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'getpaid_ajax_form' ) ) { |
|
257 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
256 | + if (!isset($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], 'getpaid_ajax_form')) { |
|
257 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
258 | 258 | exit; |
259 | 259 | } |
260 | 260 | |
261 | 261 | // Is the request set up correctly? |
262 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
262 | + if (empty($_GET['form']) && empty($_GET['item'])) { |
|
263 | 263 | echo aui()->alert( |
264 | 264 | array( |
265 | 265 | 'type' => 'warning', |
266 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
266 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
267 | 267 | ) |
268 | 268 | ); |
269 | 269 | exit; |
270 | 270 | } |
271 | 271 | |
272 | 272 | // Payment form or button? |
273 | - if ( ! empty( $_GET['form'] ) ) { |
|
274 | - getpaid_display_payment_form( $_GET['form'] ); |
|
275 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
276 | - getpaid_display_invoice_payment_form( $_GET['invoice'] ); |
|
273 | + if (!empty($_GET['form'])) { |
|
274 | + getpaid_display_payment_form($_GET['form']); |
|
275 | + } else if (!empty($_GET['invoice'])) { |
|
276 | + getpaid_display_invoice_payment_form($_GET['invoice']); |
|
277 | 277 | } else { |
278 | - $items = getpaid_convert_items_to_array( $_GET['item'] ); |
|
279 | - getpaid_display_item_payment_form( $items ); |
|
278 | + $items = getpaid_convert_items_to_array($_GET['item']); |
|
279 | + getpaid_display_item_payment_form($items); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | exit; |
@@ -291,17 +291,17 @@ discard block |
||
291 | 291 | public static function payment_form() { |
292 | 292 | |
293 | 293 | // Check nonce. |
294 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
294 | + check_ajax_referer('getpaid_form_nonce'); |
|
295 | 295 | |
296 | 296 | // ... form fields... |
297 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
298 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
297 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
298 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
299 | 299 | exit; |
300 | 300 | } |
301 | 301 | |
302 | 302 | // Process the payment form. |
303 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
304 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
303 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
304 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
305 | 305 | $checkout->process_checkout(); |
306 | 306 | |
307 | 307 | exit; |
@@ -314,51 +314,51 @@ discard block |
||
314 | 314 | */ |
315 | 315 | public static function get_payment_form_states_field() { |
316 | 316 | |
317 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
317 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
318 | 318 | exit; |
319 | 319 | } |
320 | 320 | |
321 | - $elements = getpaid_get_payment_form_elements( $_GET['form'] ); |
|
321 | + $elements = getpaid_get_payment_form_elements($_GET['form']); |
|
322 | 322 | |
323 | - if ( empty( $elements ) ) { |
|
323 | + if (empty($elements)) { |
|
324 | 324 | exit; |
325 | 325 | } |
326 | 326 | |
327 | 327 | $address_fields = array(); |
328 | - foreach ( $elements as $element ) { |
|
329 | - if ( 'address' === $element['type'] ) { |
|
328 | + foreach ($elements as $element) { |
|
329 | + if ('address' === $element['type']) { |
|
330 | 330 | $address_fields = $element; |
331 | 331 | break; |
332 | 332 | } |
333 | 333 | } |
334 | 334 | |
335 | - if ( empty( $address_fields ) ) { |
|
335 | + if (empty($address_fields)) { |
|
336 | 336 | exit; |
337 | 337 | } |
338 | 338 | |
339 | - foreach( $address_fields['fields'] as $address_field ) { |
|
339 | + foreach ($address_fields['fields'] as $address_field) { |
|
340 | 340 | |
341 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
341 | + if ('wpinv_state' == $address_field['name']) { |
|
342 | 342 | |
343 | 343 | $label = $address_field['label']; |
344 | 344 | |
345 | - if ( ! empty( $address_field['required'] ) ) { |
|
345 | + if (!empty($address_field['required'])) { |
|
346 | 346 | $label .= "<span class='text-danger'> *</span>"; |
347 | 347 | } |
348 | 348 | |
349 | - $states = wpinv_get_country_states( $_GET['country'] ); |
|
349 | + $states = wpinv_get_country_states($_GET['country']); |
|
350 | 350 | |
351 | - if ( ! empty( $states ) ) { |
|
351 | + if (!empty($states)) { |
|
352 | 352 | |
353 | 353 | $html = aui()->select( |
354 | 354 | array( |
355 | 355 | 'options' => $states, |
356 | - 'name' => esc_attr( $address_field['name'] ), |
|
357 | - 'id' => esc_attr( $address_field['name'] ), |
|
358 | - 'placeholder' => esc_attr( $address_field['placeholder'] ), |
|
356 | + 'name' => esc_attr($address_field['name']), |
|
357 | + 'id' => esc_attr($address_field['name']), |
|
358 | + 'placeholder' => esc_attr($address_field['placeholder']), |
|
359 | 359 | 'required' => (bool) $address_field['required'], |
360 | 360 | 'no_wrap' => true, |
361 | - 'label' => wp_kses_post( $label ), |
|
361 | + 'label' => wp_kses_post($label), |
|
362 | 362 | 'select2' => false, |
363 | 363 | ) |
364 | 364 | ); |
@@ -367,10 +367,10 @@ discard block |
||
367 | 367 | |
368 | 368 | $html = aui()->input( |
369 | 369 | array( |
370 | - 'name' => esc_attr( $address_field['name'] ), |
|
371 | - 'id' => esc_attr( $address_field['name'] ), |
|
370 | + 'name' => esc_attr($address_field['name']), |
|
371 | + 'id' => esc_attr($address_field['name']), |
|
372 | 372 | 'required' => (bool) $address_field['required'], |
373 | - 'label' => wp_kses_post( $label ), |
|
373 | + 'label' => wp_kses_post($label), |
|
374 | 374 | 'no_wrap' => true, |
375 | 375 | 'type' => 'text', |
376 | 376 | ) |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | |
379 | 379 | } |
380 | 380 | |
381 | - wp_send_json_success( str_replace( 'sr-only', '', $html ) ); |
|
381 | + wp_send_json_success(str_replace('sr-only', '', $html)); |
|
382 | 382 | exit; |
383 | 383 | |
384 | 384 | } |
@@ -394,56 +394,56 @@ discard block |
||
394 | 394 | public static function recalculate_invoice_totals() { |
395 | 395 | |
396 | 396 | // Verify nonce. |
397 | - check_ajax_referer( 'wpinv-nonce' ); |
|
397 | + check_ajax_referer('wpinv-nonce'); |
|
398 | 398 | |
399 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
399 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
400 | 400 | exit; |
401 | 401 | } |
402 | 402 | |
403 | 403 | // We need an invoice. |
404 | - if ( empty( $_POST['post_id'] ) ) { |
|
404 | + if (empty($_POST['post_id'])) { |
|
405 | 405 | exit; |
406 | 406 | } |
407 | 407 | |
408 | 408 | // Fetch the invoice. |
409 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
409 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
410 | 410 | |
411 | 411 | // Ensure it exists. |
412 | - if ( ! $invoice->get_id() ) { |
|
412 | + if (!$invoice->get_id()) { |
|
413 | 413 | exit; |
414 | 414 | } |
415 | 415 | |
416 | 416 | // Maybe set the country, state, currency. |
417 | - foreach ( array( 'country', 'state', 'currency' ) as $key ) { |
|
418 | - if ( isset( $_POST[ $key ] ) ) { |
|
417 | + foreach (array('country', 'state', 'currency') as $key) { |
|
418 | + if (isset($_POST[$key])) { |
|
419 | 419 | $method = "set_$key"; |
420 | - $invoice->$method( $_POST[ $key ] ); |
|
420 | + $invoice->$method($_POST[$key]); |
|
421 | 421 | } |
422 | 422 | } |
423 | 423 | |
424 | 424 | // Maybe disable taxes. |
425 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
425 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
426 | 426 | |
427 | 427 | // Recalculate totals. |
428 | 428 | $invoice->recalculate_total(); |
429 | 429 | |
430 | - $total = wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ); |
|
430 | + $total = wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()); |
|
431 | 431 | |
432 | - if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
433 | - $recurring_total = wpinv_price( wpinv_format_amount( $invoice->get_recurring_total() ), $invoice->get_currency() ); |
|
434 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
432 | + if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
433 | + $recurring_total = wpinv_price(wpinv_format_amount($invoice->get_recurring_total()), $invoice->get_currency()); |
|
434 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | $totals = array( |
438 | - 'subtotal' => wpinv_price( wpinv_format_amount( $invoice->get_subtotal() ), $invoice->get_currency() ), |
|
439 | - 'discount' => wpinv_price( wpinv_format_amount( $invoice->get_total_discount() ), $invoice->get_currency() ), |
|
440 | - 'tax' => wpinv_price( wpinv_format_amount( $invoice->get_total_tax() ), $invoice->get_currency() ), |
|
438 | + 'subtotal' => wpinv_price(wpinv_format_amount($invoice->get_subtotal()), $invoice->get_currency()), |
|
439 | + 'discount' => wpinv_price(wpinv_format_amount($invoice->get_total_discount()), $invoice->get_currency()), |
|
440 | + 'tax' => wpinv_price(wpinv_format_amount($invoice->get_total_tax()), $invoice->get_currency()), |
|
441 | 441 | 'total' => $total, |
442 | 442 | ); |
443 | 443 | |
444 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
444 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
445 | 445 | |
446 | - wp_send_json_success( compact( 'totals' ) ); |
|
446 | + wp_send_json_success(compact('totals')); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -452,33 +452,33 @@ discard block |
||
452 | 452 | public static function get_invoice_items() { |
453 | 453 | |
454 | 454 | // Verify nonce. |
455 | - check_ajax_referer( 'wpinv-nonce' ); |
|
455 | + check_ajax_referer('wpinv-nonce'); |
|
456 | 456 | |
457 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
457 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
458 | 458 | exit; |
459 | 459 | } |
460 | 460 | |
461 | 461 | // We need an invoice and items. |
462 | - if ( empty( $_POST['post_id'] ) ) { |
|
462 | + if (empty($_POST['post_id'])) { |
|
463 | 463 | exit; |
464 | 464 | } |
465 | 465 | |
466 | 466 | // Fetch the invoice. |
467 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
467 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
468 | 468 | |
469 | 469 | // Ensure it exists. |
470 | - if ( ! $invoice->get_id() ) { |
|
470 | + if (!$invoice->get_id()) { |
|
471 | 471 | exit; |
472 | 472 | } |
473 | 473 | |
474 | 474 | // Return an array of invoice items. |
475 | 475 | $items = array(); |
476 | 476 | |
477 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
478 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
477 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
478 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
479 | 479 | } |
480 | 480 | |
481 | - wp_send_json_success( compact( 'items' ) ); |
|
481 | + wp_send_json_success(compact('items')); |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | /** |
@@ -487,50 +487,50 @@ discard block |
||
487 | 487 | public static function edit_invoice_item() { |
488 | 488 | |
489 | 489 | // Verify nonce. |
490 | - check_ajax_referer( 'wpinv-nonce' ); |
|
490 | + check_ajax_referer('wpinv-nonce'); |
|
491 | 491 | |
492 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
492 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
493 | 493 | exit; |
494 | 494 | } |
495 | 495 | |
496 | 496 | // We need an invoice and item details. |
497 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
497 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
498 | 498 | exit; |
499 | 499 | } |
500 | 500 | |
501 | 501 | // Fetch the invoice. |
502 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
502 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
503 | 503 | |
504 | 504 | // Ensure it exists and its not been paid for. |
505 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
505 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
506 | 506 | exit; |
507 | 507 | } |
508 | 508 | |
509 | 509 | // Format the data. |
510 | - $data = wp_list_pluck( $_POST['data'], 'value', 'field' ); |
|
510 | + $data = wp_list_pluck($_POST['data'], 'value', 'field'); |
|
511 | 511 | |
512 | 512 | // Ensure that we have an item id. |
513 | - if ( empty( $data['id'] ) ) { |
|
513 | + if (empty($data['id'])) { |
|
514 | 514 | exit; |
515 | 515 | } |
516 | 516 | |
517 | 517 | // Abort if the invoice does not have the specified item. |
518 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
518 | + $item = $invoice->get_item((int) $data['id']); |
|
519 | 519 | |
520 | - if ( empty( $item ) ) { |
|
520 | + if (empty($item)) { |
|
521 | 521 | exit; |
522 | 522 | } |
523 | 523 | |
524 | 524 | // Update the item. |
525 | - $item->set_price( $data['price'] ); |
|
526 | - $item->set_name( $data['name'] ); |
|
527 | - $item->set_description( $data['description'] ); |
|
528 | - $item->set_quantity( $data['quantity'] ); |
|
525 | + $item->set_price($data['price']); |
|
526 | + $item->set_name($data['name']); |
|
527 | + $item->set_description($data['description']); |
|
528 | + $item->set_quantity($data['quantity']); |
|
529 | 529 | |
530 | 530 | // Add it to the invoice. |
531 | - $error = $invoice->add_item( $item ); |
|
531 | + $error = $invoice->add_item($item); |
|
532 | 532 | $alert = false; |
533 | - if ( is_wp_error( $error ) ) { |
|
533 | + if (is_wp_error($error)) { |
|
534 | 534 | $alert = $error->get_error_message(); |
535 | 535 | } |
536 | 536 | |
@@ -543,11 +543,11 @@ discard block |
||
543 | 543 | // Return an array of invoice items. |
544 | 544 | $items = array(); |
545 | 545 | |
546 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
547 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
546 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
547 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
548 | 548 | } |
549 | 549 | |
550 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
550 | + wp_send_json_success(compact('items', 'alert')); |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | /** |
@@ -556,33 +556,33 @@ discard block |
||
556 | 556 | public static function remove_invoice_item() { |
557 | 557 | |
558 | 558 | // Verify nonce. |
559 | - check_ajax_referer( 'wpinv-nonce' ); |
|
559 | + check_ajax_referer('wpinv-nonce'); |
|
560 | 560 | |
561 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
561 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
562 | 562 | exit; |
563 | 563 | } |
564 | 564 | |
565 | 565 | // We need an invoice and an item. |
566 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
566 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
567 | 567 | exit; |
568 | 568 | } |
569 | 569 | |
570 | 570 | // Fetch the invoice. |
571 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
571 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
572 | 572 | |
573 | 573 | // Ensure it exists and its not been paid for. |
574 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
574 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
575 | 575 | exit; |
576 | 576 | } |
577 | 577 | |
578 | 578 | // Abort if the invoice does not have the specified item. |
579 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
579 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
580 | 580 | |
581 | - if ( empty( $item ) ) { |
|
581 | + if (empty($item)) { |
|
582 | 582 | exit; |
583 | 583 | } |
584 | 584 | |
585 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
585 | + $invoice->remove_item((int) $_POST['item_id']); |
|
586 | 586 | |
587 | 587 | // Update totals. |
588 | 588 | $invoice->recalculate_total(); |
@@ -593,11 +593,11 @@ discard block |
||
593 | 593 | // Return an array of invoice items. |
594 | 594 | $items = array(); |
595 | 595 | |
596 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
597 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
596 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
597 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
598 | 598 | } |
599 | 599 | |
600 | - wp_send_json_success( compact( 'items' ) ); |
|
600 | + wp_send_json_success(compact('items')); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | /** |
@@ -606,39 +606,39 @@ discard block |
||
606 | 606 | public static function add_invoice_items() { |
607 | 607 | |
608 | 608 | // Verify nonce. |
609 | - check_ajax_referer( 'wpinv-nonce' ); |
|
609 | + check_ajax_referer('wpinv-nonce'); |
|
610 | 610 | |
611 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
611 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
612 | 612 | exit; |
613 | 613 | } |
614 | 614 | |
615 | 615 | // We need an invoice and items. |
616 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
616 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
617 | 617 | exit; |
618 | 618 | } |
619 | 619 | |
620 | 620 | // Fetch the invoice. |
621 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
621 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
622 | 622 | $alert = false; |
623 | 623 | |
624 | 624 | // Ensure it exists and its not been paid for. |
625 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
625 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
626 | 626 | exit; |
627 | 627 | } |
628 | 628 | |
629 | 629 | // Add the items. |
630 | - foreach ( $_POST['items'] as $data ) { |
|
630 | + foreach ($_POST['items'] as $data) { |
|
631 | 631 | |
632 | - $item = new GetPaid_Form_Item( $data[ 'id' ] ); |
|
632 | + $item = new GetPaid_Form_Item($data['id']); |
|
633 | 633 | |
634 | - if ( is_numeric( $data[ 'qty' ] ) && (int) $data[ 'qty' ] > 0 ) { |
|
635 | - $item->set_quantity( $data[ 'qty' ] ); |
|
634 | + if (is_numeric($data['qty']) && (int) $data['qty'] > 0) { |
|
635 | + $item->set_quantity($data['qty']); |
|
636 | 636 | } |
637 | 637 | |
638 | - if ( $item->get_id() > 0 ) { |
|
639 | - $error = $invoice->add_item( $item ); |
|
638 | + if ($item->get_id() > 0) { |
|
639 | + $error = $invoice->add_item($item); |
|
640 | 640 | |
641 | - if ( is_wp_error( $error ) ) { |
|
641 | + if (is_wp_error($error)) { |
|
642 | 642 | $alert = $error->get_error_message(); |
643 | 643 | } |
644 | 644 | |
@@ -653,11 +653,11 @@ discard block |
||
653 | 653 | // Return an array of invoice items. |
654 | 654 | $items = array(); |
655 | 655 | |
656 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
657 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
656 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
657 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
658 | 658 | } |
659 | 659 | |
660 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
660 | + wp_send_json_success(compact('items', 'alert')); |
|
661 | 661 | } |
662 | 662 | |
663 | 663 | /** |
@@ -666,15 +666,15 @@ discard block |
||
666 | 666 | public static function get_invoicing_items() { |
667 | 667 | |
668 | 668 | // Verify nonce. |
669 | - check_ajax_referer( 'wpinv-nonce' ); |
|
669 | + check_ajax_referer('wpinv-nonce'); |
|
670 | 670 | |
671 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
671 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
672 | 672 | exit; |
673 | 673 | } |
674 | 674 | |
675 | 675 | // We need a search term. |
676 | - if ( empty( $_GET['search'] ) ) { |
|
677 | - wp_send_json_success( array() ); |
|
676 | + if (empty($_GET['search'])) { |
|
677 | + wp_send_json_success(array()); |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | // Retrieve items. |
@@ -683,8 +683,8 @@ discard block |
||
683 | 683 | 'orderby' => 'title', |
684 | 684 | 'order' => 'ASC', |
685 | 685 | 'posts_per_page' => -1, |
686 | - 'post_status' => array( 'publish' ), |
|
687 | - 's' => trim( $_GET['search'] ), |
|
686 | + 'post_status' => array('publish'), |
|
687 | + 's' => trim($_GET['search']), |
|
688 | 688 | 'meta_query' => array( |
689 | 689 | array( |
690 | 690 | 'key' => '_wpinv_type', |
@@ -694,14 +694,14 @@ discard block |
||
694 | 694 | ) |
695 | 695 | ); |
696 | 696 | |
697 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
697 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
698 | 698 | $data = array(); |
699 | 699 | |
700 | 700 | |
701 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) ); |
|
701 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id'])); |
|
702 | 702 | |
703 | - foreach ( $items as $item ) { |
|
704 | - $item = new GetPaid_Form_Item( $item ); |
|
703 | + foreach ($items as $item) { |
|
704 | + $item = new GetPaid_Form_Item($item); |
|
705 | 705 | $data[] = array( |
706 | 706 | 'id' => $item->get_id(), |
707 | 707 | 'text' => $item->get_name(), |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | ); |
710 | 710 | } |
711 | 711 | |
712 | - wp_send_json_success( $data ); |
|
712 | + wp_send_json_success($data); |
|
713 | 713 | |
714 | 714 | } |
715 | 715 | |
@@ -719,24 +719,24 @@ discard block |
||
719 | 719 | public static function get_aui_states_field() { |
720 | 720 | |
721 | 721 | // Verify nonce. |
722 | - check_ajax_referer( 'wpinv-nonce' ); |
|
722 | + check_ajax_referer('wpinv-nonce'); |
|
723 | 723 | |
724 | 724 | // We need a country. |
725 | - if ( empty( $_GET['country'] ) ) { |
|
725 | + if (empty($_GET['country'])) { |
|
726 | 726 | exit; |
727 | 727 | } |
728 | 728 | |
729 | - $states = wpinv_get_country_states( trim( $_GET['country'] ) ); |
|
730 | - $state = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state(); |
|
729 | + $states = wpinv_get_country_states(trim($_GET['country'])); |
|
730 | + $state = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state(); |
|
731 | 731 | |
732 | - if ( empty( $states ) ) { |
|
732 | + if (empty($states)) { |
|
733 | 733 | |
734 | 734 | $html = aui()->input( |
735 | 735 | array( |
736 | 736 | 'type' => 'text', |
737 | 737 | 'id' => 'wpinv_state', |
738 | 738 | 'name' => 'wpinv_state', |
739 | - 'label' => __( 'State', 'invoicing' ), |
|
739 | + 'label' => __('State', 'invoicing'), |
|
740 | 740 | 'label_type' => 'vertical', |
741 | 741 | 'placeholder' => 'Liège', |
742 | 742 | 'class' => 'form-control-sm', |
@@ -750,9 +750,9 @@ discard block |
||
750 | 750 | array( |
751 | 751 | 'id' => 'wpinv_state', |
752 | 752 | 'name' => 'wpinv_state', |
753 | - 'label' => __( 'State', 'invoicing' ), |
|
753 | + 'label' => __('State', 'invoicing'), |
|
754 | 754 | 'label_type' => 'vertical', |
755 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
755 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
756 | 756 | 'class' => 'form-control-sm', |
757 | 757 | 'value' => $state, |
758 | 758 | 'options' => $states, |
@@ -766,7 +766,7 @@ discard block |
||
766 | 766 | wp_send_json_success( |
767 | 767 | array( |
768 | 768 | 'html' => $html, |
769 | - 'select' => ! empty ( $states ) |
|
769 | + 'select' => !empty ($states) |
|
770 | 770 | ) |
771 | 771 | ); |
772 | 772 | |
@@ -780,46 +780,46 @@ discard block |
||
780 | 780 | public static function ip_geolocation() { |
781 | 781 | |
782 | 782 | // Check nonce. |
783 | - check_ajax_referer( 'getpaid-ip-location' ); |
|
783 | + check_ajax_referer('getpaid-ip-location'); |
|
784 | 784 | |
785 | 785 | // IP address. |
786 | - if ( empty( $_GET['ip'] ) || ! rest_is_ip_address( $_GET['ip'] ) ) { |
|
787 | - _e( 'Invalid IP Address.', 'invoicing' ); |
|
786 | + if (empty($_GET['ip']) || !rest_is_ip_address($_GET['ip'])) { |
|
787 | + _e('Invalid IP Address.', 'invoicing'); |
|
788 | 788 | exit; |
789 | 789 | } |
790 | 790 | |
791 | 791 | // Retrieve location info. |
792 | - $location = getpaid_geolocate_ip_address( $_GET['ip'] ); |
|
792 | + $location = getpaid_geolocate_ip_address($_GET['ip']); |
|
793 | 793 | |
794 | - if ( empty( $location ) ) { |
|
795 | - _e( 'Unable to find geolocation for the IP Address.', 'invoicing' ); |
|
794 | + if (empty($location)) { |
|
795 | + _e('Unable to find geolocation for the IP Address.', 'invoicing'); |
|
796 | 796 | exit; |
797 | 797 | } |
798 | 798 | |
799 | 799 | // Sorry. |
800 | - extract( $location ); |
|
800 | + extract($location); |
|
801 | 801 | |
802 | 802 | // Prepare the address. |
803 | 803 | $content = ''; |
804 | 804 | |
805 | - if ( ! empty( $location['city'] ) ) { |
|
806 | - $content .= $location['city'] . ', '; |
|
805 | + if (!empty($location['city'])) { |
|
806 | + $content .= $location['city'] . ', '; |
|
807 | 807 | } |
808 | 808 | |
809 | - if ( ! empty( $location['region'] ) ) { |
|
810 | - $content .= $location['region'] . ', '; |
|
809 | + if (!empty($location['region'])) { |
|
810 | + $content .= $location['region'] . ', '; |
|
811 | 811 | } |
812 | 812 | |
813 | - $content .= $location['country'] . ' (' . $location['iso'] . ')'; |
|
813 | + $content .= $location['country'] . ' (' . $location['iso'] . ')'; |
|
814 | 814 | |
815 | 815 | $location['address'] = $content; |
816 | 816 | |
817 | - $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $content ) . '</p>'; |
|
818 | - $content .= '<p>'. $location['credit'] . '</p>'; |
|
817 | + $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $content) . '</p>'; |
|
818 | + $content .= '<p>' . $location['credit'] . '</p>'; |
|
819 | 819 | |
820 | 820 | $location['content'] = $content; |
821 | 821 | |
822 | - wpinv_get_template( 'geolocation.php', $location ); |
|
822 | + wpinv_get_template('geolocation.php', $location); |
|
823 | 823 | |
824 | 824 | exit; |
825 | 825 | } |
@@ -832,11 +832,11 @@ discard block |
||
832 | 832 | public static function payment_form_refresh_prices() { |
833 | 833 | |
834 | 834 | // Check nonce. |
835 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
835 | + check_ajax_referer('getpaid_form_nonce'); |
|
836 | 836 | |
837 | 837 | // ... form fields... |
838 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
839 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
838 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
839 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
840 | 840 | exit; |
841 | 841 | } |
842 | 842 | |
@@ -844,18 +844,18 @@ discard block |
||
844 | 844 | $submission = new GetPaid_Payment_Form_Submission(); |
845 | 845 | |
846 | 846 | // Do we have an error? |
847 | - if ( ! empty( $submission->last_error ) ) { |
|
847 | + if (!empty($submission->last_error)) { |
|
848 | 848 | echo $submission->last_error; |
849 | 849 | exit; |
850 | 850 | } |
851 | 851 | |
852 | 852 | // Prepare the response. |
853 | - $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission ); |
|
853 | + $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission); |
|
854 | 854 | |
855 | 855 | // Filter the response. |
856 | - $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission ); |
|
856 | + $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission); |
|
857 | 857 | |
858 | - wp_send_json_success( $response ); |
|
858 | + wp_send_json_success($response); |
|
859 | 859 | } |
860 | 860 | |
861 | 861 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
10 | - exit; // Exit if accessed directly |
|
10 | + exit; // Exit if accessed directly |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -16,10 +16,10 @@ discard block |
||
16 | 16 | class GetPaid_Meta_Box_Payment_Form { |
17 | 17 | |
18 | 18 | /** |
19 | - * Output the metabox. |
|
20 | - * |
|
21 | - * @param WP_Post $post |
|
22 | - */ |
|
19 | + * Output the metabox. |
|
20 | + * |
|
21 | + * @param WP_Post $post |
|
22 | + */ |
|
23 | 23 | public static function output( $post ) { |
24 | 24 | ?> |
25 | 25 | <div id="wpinv-form-builder" class="bsui"> |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | - * Save meta box data. |
|
90 | - * |
|
91 | - * @param int $post_id |
|
92 | - */ |
|
93 | - public static function save( $post_id ) { |
|
89 | + * Save meta box data. |
|
90 | + * |
|
91 | + * @param int $post_id |
|
92 | + */ |
|
93 | + public static function save( $post_id ) { |
|
94 | 94 | |
95 | 95 | // Prepare the form. |
96 | 96 | $form = new GetPaid_Payment_Form( $post_id ); |
@@ -121,11 +121,11 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | - * Converts an array fo form items to objects. |
|
125 | - * |
|
126 | - * @param array $items |
|
127 | - */ |
|
128 | - public static function item_to_objects( $items ) { |
|
124 | + * Converts an array fo form items to objects. |
|
125 | + * |
|
126 | + * @param array $items |
|
127 | + */ |
|
128 | + public static function item_to_objects( $items ) { |
|
129 | 129 | |
130 | 130 | $objects = array(); |
131 | 131 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if (!defined('ABSPATH')) { |
|
10 | 10 | exit; // Exit if accessed directly |
11 | 11 | } |
12 | 12 | |
@@ -20,14 +20,14 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @param WP_Post $post |
22 | 22 | */ |
23 | - public static function output( $post ) { |
|
23 | + public static function output($post) { |
|
24 | 24 | ?> |
25 | 25 | <div id="wpinv-form-builder" class="bsui"> |
26 | 26 | <div class="row"> |
27 | 27 | <div class="col-sm-4"> |
28 | 28 | |
29 | 29 | <!-- Builder tabs --> |
30 | - <button class="button button-primary" v-if="active_tab!='new_item'" @click.prevent="active_tab='new_item'"><?php _e( 'Go Back', 'invoicing' ); ?></button> |
|
30 | + <button class="button button-primary" v-if="active_tab!='new_item'" @click.prevent="active_tab='new_item'"><?php _e('Go Back', 'invoicing'); ?></button> |
|
31 | 31 | |
32 | 32 | <!-- Builder tab content --> |
33 | 33 | <div class="mt-4"> |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | <!-- Available builder elements --> |
36 | 36 | <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='new_item'"> |
37 | 37 | <div class="wpinv-form-builder-add-field-types"> |
38 | - <small class='form-text text-muted'><?php _e( 'Add an element by dragging it to the payment form.', 'invoicing' ); ?></small> |
|
38 | + <small class='form-text text-muted'><?php _e('Add an element by dragging it to the payment form.', 'invoicing'); ?></small> |
|
39 | 39 | <draggable class="section mt-2" style="display: flex; flex-flow: wrap; justify-content: space-between;" v-model="elements" :group="{ name: 'fields', pull: 'clone', put: false }" :sort="false" :clone="addDraggedField" tag="ul" filter=".wpinv-undraggable"> |
40 | 40 | <li v-for="element in elements" class= "wpinv-payment-form-left-fields-field" @click.prevent="addField(element)" :class="{ 'd-none': element.defaults.premade }"> |
41 | 41 | <button class="button btn"> |
@@ -50,10 +50,10 @@ discard block |
||
50 | 50 | <!-- Edit an element --> |
51 | 51 | <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='edit_item'" style="font-size: 14px;"> |
52 | 52 | <div class="wpinv-form-builder-edit-field-wrapper"> |
53 | - <?php do_action( 'wpinv_payment_form_edit_element_template', 'active_form_element', $post ); ?> |
|
54 | - <?php do_action( 'getpaid_payment_form_edit_element_template', $post ); ?> |
|
53 | + <?php do_action('wpinv_payment_form_edit_element_template', 'active_form_element', $post); ?> |
|
54 | + <?php do_action('getpaid_payment_form_edit_element_template', $post); ?> |
|
55 | 55 | <div> |
56 | - <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e( 'Delete Element', 'invoicing' ); ?></button> |
|
56 | + <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e('Delete Element', 'invoicing'); ?></button> |
|
57 | 57 | </div> |
58 | 58 | </div> |
59 | 59 | </div> |
@@ -62,14 +62,14 @@ discard block |
||
62 | 62 | |
63 | 63 | </div> |
64 | 64 | <div class="col-sm-8 border-left"> |
65 | - <small class='form-text text-muted' v-if='form_elements.length'><?php _e( 'Click on any element to edit or delete it.', 'invoicing' ); ?></small> |
|
66 | - <p class='form-text text-muted' v-if='! form_elements.length'><?php _e( 'This form is empty. Add new elements by dragging them from the right.', 'invoicing' ); ?></p> |
|
65 | + <small class='form-text text-muted' v-if='form_elements.length'><?php _e('Click on any element to edit or delete it.', 'invoicing'); ?></small> |
|
66 | + <p class='form-text text-muted' v-if='! form_elements.length'><?php _e('This form is empty. Add new elements by dragging them from the right.', 'invoicing'); ?></p> |
|
67 | 67 | |
68 | 68 | <draggable class="section bsui" v-model="form_elements" @add="highlightLastDroppedField" group="fields" tag="div" style="min-height: 100%; font-size: 14px;"> |
69 | 69 | <div v-for="form_element in form_elements" class="wpinv-form-builder-element-preview" :class="[{ active: active_form_element==form_element && active_tab=='edit_item' }, form_element.type]" @click="active_tab = 'edit_item'; active_form_element = form_element"> |
70 | 70 | <div class="wpinv-form-builder-element-preview-inner"> |
71 | 71 | <div class="wpinv-payment-form-field-preview-overlay"></div> |
72 | - <?php do_action( 'wpinv_payment_form_render_element_template', 'form_element', $post ); ?> |
|
72 | + <?php do_action('wpinv_payment_form_render_element_template', 'form_element', $post); ?> |
|
73 | 73 | </div> |
74 | 74 | </div> |
75 | 75 | </draggable> |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | </div> |
83 | 83 | <?php |
84 | 84 | |
85 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
85 | + wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce'); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -90,33 +90,33 @@ discard block |
||
90 | 90 | * |
91 | 91 | * @param int $post_id |
92 | 92 | */ |
93 | - public static function save( $post_id ) { |
|
93 | + public static function save($post_id) { |
|
94 | 94 | |
95 | 95 | // Prepare the form. |
96 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
96 | + $form = new GetPaid_Payment_Form($post_id); |
|
97 | 97 | |
98 | 98 | // Fetch form items. |
99 | - $form_items = json_decode( wp_unslash( $_POST['wpinv_form_items'] ), true ); |
|
99 | + $form_items = json_decode(wp_unslash($_POST['wpinv_form_items']), true); |
|
100 | 100 | |
101 | 101 | // Ensure that we have an array... |
102 | - if ( empty( $form_items ) ) { |
|
102 | + if (empty($form_items)) { |
|
103 | 103 | $form_items = array(); |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Add it to the form. |
107 | - $form->set_items( self::item_to_objects( $form_items ) ); |
|
107 | + $form->set_items(self::item_to_objects($form_items)); |
|
108 | 108 | |
109 | 109 | // Save form elements. |
110 | - $form_elements = json_decode( wp_unslash( $_POST['wpinv_form_elements'] ), true ); |
|
111 | - if ( empty( $form_elements ) ) { |
|
110 | + $form_elements = json_decode(wp_unslash($_POST['wpinv_form_elements']), true); |
|
111 | + if (empty($form_elements)) { |
|
112 | 112 | $form_elements = array(); |
113 | 113 | } |
114 | 114 | |
115 | - $form->set_elements( $form_elements ); |
|
115 | + $form->set_elements($form_elements); |
|
116 | 116 | |
117 | 117 | // Persist data to the datastore. |
118 | 118 | $form->save(); |
119 | - do_action( 'getpaid_payment_form_metabox_save', $post_id, $form ); |
|
119 | + do_action('getpaid_payment_form_metabox_save', $post_id, $form); |
|
120 | 120 | |
121 | 121 | } |
122 | 122 | |
@@ -125,14 +125,14 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @param array $items |
127 | 127 | */ |
128 | - public static function item_to_objects( $items ) { |
|
128 | + public static function item_to_objects($items) { |
|
129 | 129 | |
130 | 130 | $objects = array(); |
131 | 131 | |
132 | - foreach ( $items as $item ) { |
|
133 | - $_item = new GetPaid_Form_Item( $item['id'] ); |
|
134 | - $_item->set_allow_quantities( (bool) $item['allow_quantities'] ); |
|
135 | - $_item->set_allow_quantities( (bool) $item['required'] ); |
|
132 | + foreach ($items as $item) { |
|
133 | + $_item = new GetPaid_Form_Item($item['id']); |
|
134 | + $_item->set_allow_quantities((bool) $item['allow_quantities']); |
|
135 | + $_item->set_allow_quantities((bool) $item['required']); |
|
136 | 136 | $objects[] = $_item; |
137 | 137 | } |
138 | 138 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | class GetPaid_Meta_Box_Discount_Details { |
18 | 18 | |
19 | 19 | /** |
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | 24 | public static function output( $post ) { |
25 | 25 | |
26 | 26 | // Prepare the discount. |
@@ -368,34 +368,34 @@ discard block |
||
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
371 | - * Save meta box data. |
|
372 | - * |
|
373 | - * @param int $post_id |
|
374 | - */ |
|
375 | - public static function save( $post_id ) { |
|
371 | + * Save meta box data. |
|
372 | + * |
|
373 | + * @param int $post_id |
|
374 | + */ |
|
375 | + public static function save( $post_id ) { |
|
376 | 376 | |
377 | 377 | // Prepare the discount. |
378 | 378 | $discount = new WPInv_Discount( $post_id ); |
379 | 379 | |
380 | 380 | // Load new data. |
381 | 381 | $discount->set_props( |
382 | - array( |
|
383 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
384 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
385 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
386 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
387 | - 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
382 | + array( |
|
383 | + 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
384 | + 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
385 | + 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
386 | + 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
387 | + 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
388 | 388 | 'type' => isset( $_POST['wpinv_discount_type'] ) ? $_POST['wpinv_discount_type'] : null, |
389 | - 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
390 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(), |
|
391 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
392 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
393 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
394 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
395 | - ) |
|
389 | + 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
390 | + 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(), |
|
391 | + 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
392 | + 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
393 | + 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
394 | + 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
395 | + ) |
|
396 | 396 | ); |
397 | 397 | |
398 | - $discount->save(); |
|
399 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
400 | - } |
|
398 | + $discount->save(); |
|
399 | + do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
400 | + } |
|
401 | 401 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -21,24 +21,24 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param WP_Post $post |
23 | 23 | */ |
24 | - public static function output( $post ) { |
|
24 | + public static function output($post) { |
|
25 | 25 | |
26 | 26 | // Prepare the discount. |
27 | - $discount = new WPInv_Discount( $post ); |
|
27 | + $discount = new WPInv_Discount($post); |
|
28 | 28 | |
29 | 29 | // Nonce field. |
30 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
30 | + wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce'); |
|
31 | 31 | |
32 | - do_action( 'wpinv_discount_form_top', $discount ); |
|
32 | + do_action('wpinv_discount_form_top', $discount); |
|
33 | 33 | |
34 | 34 | // Set the currency position. |
35 | 35 | $position = wpinv_currency_position(); |
36 | 36 | |
37 | - if ( $position == 'left_space' ) { |
|
37 | + if ($position == 'left_space') { |
|
38 | 38 | $position = 'left'; |
39 | 39 | } |
40 | 40 | |
41 | - if ( $position == 'right_space' ) { |
|
41 | + if ($position == 'right_space') { |
|
42 | 42 | $position = 'right'; |
43 | 43 | } |
44 | 44 | |
@@ -52,66 +52,66 @@ discard block |
||
52 | 52 | </style> |
53 | 53 | <div class='bsui' style='max-width: 600px;padding-top: 10px;'> |
54 | 54 | |
55 | - <?php do_action( 'wpinv_discount_form_first', $discount ); ?> |
|
55 | + <?php do_action('wpinv_discount_form_first', $discount); ?> |
|
56 | 56 | |
57 | - <?php do_action( 'wpinv_discount_form_before_code', $discount ); ?> |
|
57 | + <?php do_action('wpinv_discount_form_before_code', $discount); ?> |
|
58 | 58 | <div class="form-group row"> |
59 | 59 | <label for="wpinv_discount_code" class="col-sm-3 col-form-label"> |
60 | - <?php _e( 'Discount Code', 'invoicing' );?> |
|
60 | + <?php _e('Discount Code', 'invoicing'); ?> |
|
61 | 61 | </label> |
62 | 62 | <div class="col-sm-8"> |
63 | 63 | <div class="row"> |
64 | 64 | <div class="col-sm-12 form-group"> |
65 | - <input type="text" value="<?php echo esc_attr( $discount->get_code( 'edit' ) ); ?>" placeholder="SUMMER_SALE" name="wpinv_discount_code" id="wpinv_discount_code" style="width: 100%;" /> |
|
65 | + <input type="text" value="<?php echo esc_attr($discount->get_code('edit')); ?>" placeholder="SUMMER_SALE" name="wpinv_discount_code" id="wpinv_discount_code" style="width: 100%;" /> |
|
66 | 66 | </div> |
67 | 67 | <div class="col-sm-12"> |
68 | 68 | <?php |
69 | - do_action( 'wpinv_discount_form_before_single_use', $discount ); |
|
69 | + do_action('wpinv_discount_form_before_single_use', $discount); |
|
70 | 70 | |
71 | 71 | echo aui()->input( |
72 | 72 | array( |
73 | 73 | 'id' => 'wpinv_discount_single_use', |
74 | 74 | 'name' => 'wpinv_discount_single_use', |
75 | 75 | 'type' => 'checkbox', |
76 | - 'label' => __( 'Each customer can only use this discount once', 'invoicing' ), |
|
76 | + 'label' => __('Each customer can only use this discount once', 'invoicing'), |
|
77 | 77 | 'value' => '1', |
78 | 78 | 'checked' => $discount->is_single_use(), |
79 | 79 | ) |
80 | 80 | ); |
81 | 81 | |
82 | - do_action( 'wpinv_discount_form_single_use', $discount ); |
|
82 | + do_action('wpinv_discount_form_single_use', $discount); |
|
83 | 83 | ?> |
84 | 84 | </div> |
85 | 85 | <div class="col-sm-12"> |
86 | 86 | <?php |
87 | - do_action( 'wpinv_discount_form_before_recurring', $discount ); |
|
87 | + do_action('wpinv_discount_form_before_recurring', $discount); |
|
88 | 88 | |
89 | 89 | echo aui()->input( |
90 | 90 | array( |
91 | 91 | 'id' => 'wpinv_discount_recurring', |
92 | 92 | 'name' => 'wpinv_discount_recurring', |
93 | 93 | 'type' => 'checkbox', |
94 | - 'label' => __( 'Apply this discount to all recurring payments for subscriptions', 'invoicing' ), |
|
94 | + 'label' => __('Apply this discount to all recurring payments for subscriptions', 'invoicing'), |
|
95 | 95 | 'value' => '1', |
96 | 96 | 'checked' => $discount->is_recurring(), |
97 | 97 | ) |
98 | 98 | ); |
99 | 99 | |
100 | - do_action( 'wpinv_discount_form_recurring', $discount ); |
|
100 | + do_action('wpinv_discount_form_recurring', $discount); |
|
101 | 101 | ?> |
102 | 102 | </div> |
103 | 103 | </div> |
104 | 104 | </div> |
105 | 105 | <div class="col-sm-1 pt-2 pl-0"> |
106 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter a discount code such as 10OFF.', 'invoicing' ); ?>"></span> |
|
106 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter a discount code such as 10OFF.', 'invoicing'); ?>"></span> |
|
107 | 107 | </div> |
108 | 108 | </div> |
109 | - <?php do_action( 'wpinv_discount_form_code', $discount ); ?> |
|
109 | + <?php do_action('wpinv_discount_form_code', $discount); ?> |
|
110 | 110 | |
111 | - <?php do_action( 'wpinv_discount_form_before_type', $discount ); ?> |
|
111 | + <?php do_action('wpinv_discount_form_before_type', $discount); ?> |
|
112 | 112 | <div class="form-group row"> |
113 | 113 | <label for="wpinv_discount_type" class="col-sm-3 col-form-label"> |
114 | - <?php _e( 'Discount Type', 'invoicing' );?> |
|
114 | + <?php _e('Discount Type', 'invoicing'); ?> |
|
115 | 115 | </label> |
116 | 116 | <div class="col-sm-8"> |
117 | 117 | <?php |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | array( |
120 | 120 | 'id' => 'wpinv_discount_type', |
121 | 121 | 'name' => 'wpinv_discount_type', |
122 | - 'label' => __( 'Discount Type', 'invoicing' ), |
|
123 | - 'placeholder' => __( 'Select Discount Type', 'invoicing' ), |
|
124 | - 'value' => $discount->get_type( 'edit' ), |
|
122 | + 'label' => __('Discount Type', 'invoicing'), |
|
123 | + 'placeholder' => __('Select Discount Type', 'invoicing'), |
|
124 | + 'value' => $discount->get_type('edit'), |
|
125 | 125 | 'select2' => true, |
126 | 126 | 'data-allow-clear' => 'false', |
127 | 127 | 'options' => wpinv_get_discount_types() |
@@ -130,19 +130,19 @@ discard block |
||
130 | 130 | ?> |
131 | 131 | </div> |
132 | 132 | <div class="col-sm-1 pt-2 pl-0"> |
133 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Discount type.', 'invoicing' ); ?>"></span> |
|
133 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Discount type.', 'invoicing'); ?>"></span> |
|
134 | 134 | </div> |
135 | 135 | </div> |
136 | - <?php do_action( 'wpinv_discount_form_type', $discount ); ?> |
|
136 | + <?php do_action('wpinv_discount_form_type', $discount); ?> |
|
137 | 137 | |
138 | - <?php do_action( 'wpinv_discount_form_before_amount', $discount ); ?> |
|
139 | - <div class="form-group row <?php echo esc_attr( $discount->get_type( 'edit' ) ); ?>" id="wpinv_discount_amount_wrap"> |
|
138 | + <?php do_action('wpinv_discount_form_before_amount', $discount); ?> |
|
139 | + <div class="form-group row <?php echo esc_attr($discount->get_type('edit')); ?>" id="wpinv_discount_amount_wrap"> |
|
140 | 140 | <label for="wpinv_discount_amount" class="col-sm-3 col-form-label"> |
141 | - <?php _e( 'Discount Amount', 'invoicing' );?> |
|
141 | + <?php _e('Discount Amount', 'invoicing'); ?> |
|
142 | 142 | </label> |
143 | 143 | <div class="col-sm-8"> |
144 | 144 | <div class="input-group input-group-sm"> |
145 | - <?php if( 'left' == $position ) : ?> |
|
145 | + <?php if ('left' == $position) : ?> |
|
146 | 146 | <div class="input-group-prepend left wpinv-if-flat"> |
147 | 147 | <span class="input-group-text"> |
148 | 148 | <?php echo wpinv_currency_symbol(); ?> |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | </div> |
151 | 151 | <?php endif; ?> |
152 | 152 | |
153 | - <input type="text" name="wpinv_discount_amount" id="wpinv_discount_amount" value="<?php echo esc_attr( $discount->get_amount( 'edit' ) ); ?>" placeholder="0" class="form-control"> |
|
153 | + <input type="text" name="wpinv_discount_amount" id="wpinv_discount_amount" value="<?php echo esc_attr($discount->get_amount('edit')); ?>" placeholder="0" class="form-control"> |
|
154 | 154 | |
155 | - <?php if( 'right' == $position ) : ?> |
|
155 | + <?php if ('right' == $position) : ?> |
|
156 | 156 | <div class="input-group-prepend left wpinv-if-flat"> |
157 | 157 | <span class="input-group-text"> |
158 | 158 | <?php echo wpinv_currency_symbol(); ?> |
@@ -165,15 +165,15 @@ discard block |
||
165 | 165 | </div> |
166 | 166 | </div> |
167 | 167 | <div class="col-sm-1 pt-2 pl-0"> |
168 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?>"></span> |
|
168 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter the discount value. Ex: 10', 'invoicing'); ?>"></span> |
|
169 | 169 | </div> |
170 | 170 | </div> |
171 | - <?php do_action( 'wpinv_discount_form_amount', $discount ); ?> |
|
171 | + <?php do_action('wpinv_discount_form_amount', $discount); ?> |
|
172 | 172 | |
173 | - <?php do_action( 'wpinv_discount_form_before_items', $discount ); ?> |
|
173 | + <?php do_action('wpinv_discount_form_before_items', $discount); ?> |
|
174 | 174 | <div class="form-group row"> |
175 | 175 | <label for="wpinv_discount_items" class="col-sm-3 col-form-label"> |
176 | - <?php _e( 'Items', 'invoicing' );?> |
|
176 | + <?php _e('Items', 'invoicing'); ?> |
|
177 | 177 | </label> |
178 | 178 | <div class="col-sm-8"> |
179 | 179 | <?php |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | array( |
182 | 182 | 'id' => 'wpinv_discount_items', |
183 | 183 | 'name' => 'wpinv_discount_items[]', |
184 | - 'label' => __( 'Items', 'invoicing' ), |
|
185 | - 'placeholder' => __( 'Select Items', 'invoicing' ), |
|
186 | - 'value' => $discount->get_items( 'edit' ), |
|
184 | + 'label' => __('Items', 'invoicing'), |
|
185 | + 'placeholder' => __('Select Items', 'invoicing'), |
|
186 | + 'value' => $discount->get_items('edit'), |
|
187 | 187 | 'select2' => true, |
188 | 188 | 'multiple' => true, |
189 | 189 | 'data-allow-clear' => 'false', |
@@ -193,15 +193,15 @@ discard block |
||
193 | 193 | ?> |
194 | 194 | </div> |
195 | 195 | <div class="col-sm-1 pt-2 pl-0"> |
196 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select the items that are allowed to use this discount or leave blank to use this discount all items.', 'invoicing' ); ?>"></span> |
|
196 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Select the items that are allowed to use this discount or leave blank to use this discount all items.', 'invoicing'); ?>"></span> |
|
197 | 197 | </div> |
198 | 198 | </div> |
199 | - <?php do_action( 'wpinv_discount_form_items', $discount ); ?> |
|
199 | + <?php do_action('wpinv_discount_form_items', $discount); ?> |
|
200 | 200 | |
201 | - <?php do_action( 'wpinv_discount_form_before_excluded_items', $discount ); ?> |
|
201 | + <?php do_action('wpinv_discount_form_before_excluded_items', $discount); ?> |
|
202 | 202 | <div class="form-group row"> |
203 | 203 | <label for="wpinv_discount_excluded_items" class="col-sm-3 col-form-label"> |
204 | - <?php _e( 'Excluded Items', 'invoicing' );?> |
|
204 | + <?php _e('Excluded Items', 'invoicing'); ?> |
|
205 | 205 | </label> |
206 | 206 | <div class="col-sm-8"> |
207 | 207 | <?php |
@@ -209,9 +209,9 @@ discard block |
||
209 | 209 | array( |
210 | 210 | 'id' => 'wpinv_discount_excluded_items', |
211 | 211 | 'name' => 'wpinv_discount_excluded_items[]', |
212 | - 'label' => __( 'Excluded Items', 'invoicing' ), |
|
213 | - 'placeholder' => __( 'Select Items', 'invoicing' ), |
|
214 | - 'value' => $discount->get_excluded_items( 'edit' ), |
|
212 | + 'label' => __('Excluded Items', 'invoicing'), |
|
213 | + 'placeholder' => __('Select Items', 'invoicing'), |
|
214 | + 'value' => $discount->get_excluded_items('edit'), |
|
215 | 215 | 'select2' => true, |
216 | 216 | 'multiple' => true, |
217 | 217 | 'data-allow-clear' => 'false', |
@@ -221,15 +221,15 @@ discard block |
||
221 | 221 | ?> |
222 | 222 | </div> |
223 | 223 | <div class="col-sm-1 pt-2 pl-0"> |
224 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select all the items that are not allowed to use this discount.', 'invoicing' ); ?>"></span> |
|
224 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Select all the items that are not allowed to use this discount.', 'invoicing'); ?>"></span> |
|
225 | 225 | </div> |
226 | 226 | </div> |
227 | - <?php do_action( 'wpinv_discount_form_excluded_items', $discount ); ?> |
|
227 | + <?php do_action('wpinv_discount_form_excluded_items', $discount); ?> |
|
228 | 228 | |
229 | - <?php do_action( 'wpinv_discount_form_before_start', $discount ); ?> |
|
229 | + <?php do_action('wpinv_discount_form_before_start', $discount); ?> |
|
230 | 230 | <div class="form-group row"> |
231 | 231 | <label for="wpinv_discount_start" class="col-sm-3 col-form-label"> |
232 | - <?php _e( 'Start Date', 'invoicing' );?> |
|
232 | + <?php _e('Start Date', 'invoicing'); ?> |
|
233 | 233 | </label> |
234 | 234 | <div class="col-sm-8"> |
235 | 235 | <?php |
@@ -238,10 +238,10 @@ discard block |
||
238 | 238 | 'type' => 'datepicker', |
239 | 239 | 'id' => 'wpinv_discount_start', |
240 | 240 | 'name' => 'wpinv_discount_start', |
241 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
241 | + 'label' => __('Start Date', 'invoicing'), |
|
242 | 242 | 'placeholder' => 'YYYY-MM-DD 00:00', |
243 | 243 | 'class' => 'form-control-sm', |
244 | - 'value' => $discount->get_start_date( 'edit' ), |
|
244 | + 'value' => $discount->get_start_date('edit'), |
|
245 | 245 | 'extra_attributes' => array( |
246 | 246 | 'data-enable-time' => 'true', |
247 | 247 | 'data-time_24hr' => 'true', |
@@ -252,15 +252,15 @@ discard block |
||
252 | 252 | ?> |
253 | 253 | </div> |
254 | 254 | <div class="col-sm-1 pt-2 pl-0"> |
255 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?>"></span> |
|
255 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?>"></span> |
|
256 | 256 | </div> |
257 | 257 | </div> |
258 | - <?php do_action( 'wpinv_discount_form_start', $discount ); ?> |
|
258 | + <?php do_action('wpinv_discount_form_start', $discount); ?> |
|
259 | 259 | |
260 | - <?php do_action( 'wpinv_discount_form_before_expiration', $discount ); ?> |
|
260 | + <?php do_action('wpinv_discount_form_before_expiration', $discount); ?> |
|
261 | 261 | <div class="form-group row"> |
262 | 262 | <label for="wpinv_discount_expiration" class="col-sm-3 col-form-label"> |
263 | - <?php _e( 'Expiration Date', 'invoicing' );?> |
|
263 | + <?php _e('Expiration Date', 'invoicing'); ?> |
|
264 | 264 | </label> |
265 | 265 | <div class="col-sm-8"> |
266 | 266 | <?php |
@@ -269,10 +269,10 @@ discard block |
||
269 | 269 | 'type' => 'datepicker', |
270 | 270 | 'id' => 'wpinv_discount_expiration', |
271 | 271 | 'name' => 'wpinv_discount_expiration', |
272 | - 'label' => __( 'Expiration Date', 'invoicing' ), |
|
272 | + 'label' => __('Expiration Date', 'invoicing'), |
|
273 | 273 | 'placeholder' => 'YYYY-MM-DD 00:00', |
274 | 274 | 'class' => 'form-control-sm', |
275 | - 'value' => $discount->get_end_date( 'edit' ), |
|
275 | + 'value' => $discount->get_end_date('edit'), |
|
276 | 276 | 'extra_attributes' => array( |
277 | 277 | 'data-enable-time' => 'true', |
278 | 278 | 'data-time_24hr' => 'true', |
@@ -285,27 +285,27 @@ discard block |
||
285 | 285 | ?> |
286 | 286 | </div> |
287 | 287 | <div class="col-sm-1 pt-2 pl-0"> |
288 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the date after which the discount will expire.', 'invoicing' ); ?>"></span> |
|
288 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the date after which the discount will expire.', 'invoicing'); ?>"></span> |
|
289 | 289 | </div> |
290 | 290 | </div> |
291 | - <?php do_action( 'wpinv_discount_form_expiration', $discount ); ?> |
|
291 | + <?php do_action('wpinv_discount_form_expiration', $discount); ?> |
|
292 | 292 | |
293 | - <?php do_action( 'wpinv_discount_form_before_min_total', $discount ); ?> |
|
293 | + <?php do_action('wpinv_discount_form_before_min_total', $discount); ?> |
|
294 | 294 | <div class="form-group row"> |
295 | 295 | <label for="wpinv_discount_min_total" class="col-sm-3 col-form-label"> |
296 | - <?php _e( 'Minimum Amount', 'invoicing' );?> |
|
296 | + <?php _e('Minimum Amount', 'invoicing'); ?> |
|
297 | 297 | </label> |
298 | 298 | <div class="col-sm-8"> |
299 | 299 | <div class="input-group input-group-sm"> |
300 | - <?php if( 'left' == $position ) : ?> |
|
300 | + <?php if ('left' == $position) : ?> |
|
301 | 301 | <div class="input-group-prepend"> |
302 | 302 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
303 | 303 | </div> |
304 | 304 | <?php endif; ?> |
305 | 305 | |
306 | - <input type="text" name="wpinv_discount_min_total" id="wpinv_discount_min_total" value="<?php echo esc_attr( $discount->get_minimum_total( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'No minimum', 'invoicing' ); ?>" class="form-control"> |
|
306 | + <input type="text" name="wpinv_discount_min_total" id="wpinv_discount_min_total" value="<?php echo esc_attr($discount->get_minimum_total('edit')); ?>" placeholder="<?php esc_attr_e('No minimum', 'invoicing'); ?>" class="form-control"> |
|
307 | 307 | |
308 | - <?php if( 'left' != $position ) : ?> |
|
308 | + <?php if ('left' != $position) : ?> |
|
309 | 309 | <div class="input-group-append"> |
310 | 310 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
311 | 311 | </div> |
@@ -313,27 +313,27 @@ discard block |
||
313 | 313 | </div> |
314 | 314 | </div> |
315 | 315 | <div class="col-sm-1 pt-2 pl-0"> |
316 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the minimum amount (including taxes) required to use this discount.', 'invoicing' ); ?>"></span> |
|
316 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the minimum amount (including taxes) required to use this discount.', 'invoicing'); ?>"></span> |
|
317 | 317 | </div> |
318 | 318 | </div> |
319 | - <?php do_action( 'wpinv_discount_form_min_total', $discount ); ?> |
|
319 | + <?php do_action('wpinv_discount_form_min_total', $discount); ?> |
|
320 | 320 | |
321 | - <?php do_action( 'wpinv_discount_form_before_max_total', $discount ); ?> |
|
321 | + <?php do_action('wpinv_discount_form_before_max_total', $discount); ?> |
|
322 | 322 | <div class="form-group row"> |
323 | 323 | <label for="wpinv_discount_max_total" class="col-sm-3 col-form-label"> |
324 | - <?php _e( 'Maximum Amount', 'invoicing' );?> |
|
324 | + <?php _e('Maximum Amount', 'invoicing'); ?> |
|
325 | 325 | </label> |
326 | 326 | <div class="col-sm-8"> |
327 | 327 | <div class="input-group input-group-sm"> |
328 | - <?php if( 'left' == $position ) : ?> |
|
328 | + <?php if ('left' == $position) : ?> |
|
329 | 329 | <div class="input-group-prepend"> |
330 | 330 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
331 | 331 | </div> |
332 | 332 | <?php endif; ?> |
333 | 333 | |
334 | - <input type="text" name="wpinv_discount_max_total" id="wpinv_discount_max_total" value="<?php echo esc_attr( $discount->get_maximum_total( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'No maximum', 'invoicing' ); ?>" class="form-control"> |
|
334 | + <input type="text" name="wpinv_discount_max_total" id="wpinv_discount_max_total" value="<?php echo esc_attr($discount->get_maximum_total('edit')); ?>" placeholder="<?php esc_attr_e('No maximum', 'invoicing'); ?>" class="form-control"> |
|
335 | 335 | |
336 | - <?php if( 'left' != $position ) : ?> |
|
336 | + <?php if ('left' != $position) : ?> |
|
337 | 337 | <div class="input-group-append"> |
338 | 338 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
339 | 339 | </div> |
@@ -341,30 +341,30 @@ discard block |
||
341 | 341 | </div> |
342 | 342 | </div> |
343 | 343 | <div class="col-sm-1 pt-2 pl-0"> |
344 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the maximum amount (including taxes) allowed when using this discount.', 'invoicing' ); ?>"></span> |
|
344 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the maximum amount (including taxes) allowed when using this discount.', 'invoicing'); ?>"></span> |
|
345 | 345 | </div> |
346 | 346 | </div> |
347 | - <?php do_action( 'wpinv_discount_form_before_max_total', $discount ); ?> |
|
347 | + <?php do_action('wpinv_discount_form_before_max_total', $discount); ?> |
|
348 | 348 | |
349 | - <?php do_action( 'wpinv_discount_form_before_max_uses', $discount ); ?> |
|
349 | + <?php do_action('wpinv_discount_form_before_max_uses', $discount); ?> |
|
350 | 350 | <div class="form-group row"> |
351 | 351 | <label for="wpinv_discount_max_uses" class="col-sm-3 col-form-label"> |
352 | - <?php _e( 'Maximum Uses', 'invoicing' );?> |
|
352 | + <?php _e('Maximum Uses', 'invoicing'); ?> |
|
353 | 353 | </label> |
354 | 354 | <div class="col-sm-8"> |
355 | - <input type="text" value="<?php echo esc_attr( $discount->get_max_uses( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'Unlimited', 'invoicing' ); ?>" name="wpinv_discount_max_uses" id="wpinv_discount_max_uses" style="width: 100%;" /> |
|
355 | + <input type="text" value="<?php echo esc_attr($discount->get_max_uses('edit')); ?>" placeholder="<?php esc_attr_e('Unlimited', 'invoicing'); ?>" name="wpinv_discount_max_uses" id="wpinv_discount_max_uses" style="width: 100%;" /> |
|
356 | 356 | </div> |
357 | 357 | <div class="col-sm-1 pt-2 pl-0"> |
358 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the maximum number of times that this discount code can be used.', 'invoicing' ); ?>"></span> |
|
358 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the maximum number of times that this discount code can be used.', 'invoicing'); ?>"></span> |
|
359 | 359 | </div> |
360 | 360 | </div> |
361 | - <?php do_action( 'wpinv_discount_form_max_uses', $discount ); ?> |
|
361 | + <?php do_action('wpinv_discount_form_max_uses', $discount); ?> |
|
362 | 362 | |
363 | - <?php do_action( 'wpinv_discount_form_last', $discount ); ?> |
|
363 | + <?php do_action('wpinv_discount_form_last', $discount); ?> |
|
364 | 364 | |
365 | 365 | </div> |
366 | 366 | <?php |
367 | - do_action( 'wpinv_discount_form_bottom', $post ); |
|
367 | + do_action('wpinv_discount_form_bottom', $post); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -372,30 +372,30 @@ discard block |
||
372 | 372 | * |
373 | 373 | * @param int $post_id |
374 | 374 | */ |
375 | - public static function save( $post_id ) { |
|
375 | + public static function save($post_id) { |
|
376 | 376 | |
377 | 377 | // Prepare the discount. |
378 | - $discount = new WPInv_Discount( $post_id ); |
|
378 | + $discount = new WPInv_Discount($post_id); |
|
379 | 379 | |
380 | 380 | // Load new data. |
381 | 381 | $discount->set_props( |
382 | 382 | array( |
383 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
384 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
385 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
386 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
387 | - 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
388 | - 'type' => isset( $_POST['wpinv_discount_type'] ) ? $_POST['wpinv_discount_type'] : null, |
|
389 | - 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
390 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(), |
|
391 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
392 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
393 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
394 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
383 | + 'code' => isset($_POST['wpinv_discount_code']) ? $_POST['wpinv_discount_code'] : null, |
|
384 | + 'amount' => isset($_POST['wpinv_discount_amount']) ? $_POST['wpinv_discount_amount'] : null, |
|
385 | + 'start' => isset($_POST['wpinv_discount_start']) ? wpinv_clean($_POST['wpinv_discount_start']) : null, |
|
386 | + 'expiration' => isset($_POST['wpinv_discount_expiration']) ? wpinv_clean($_POST['wpinv_discount_expiration']) : null, |
|
387 | + 'is_single_use' => isset($_POST['wpinv_discount_single_use']), |
|
388 | + 'type' => isset($_POST['wpinv_discount_type']) ? $_POST['wpinv_discount_type'] : null, |
|
389 | + 'is_recurring' => isset($_POST['wpinv_discount_recurring']), |
|
390 | + 'items' => isset($_POST['wpinv_discount_items']) ? $_POST['wpinv_discount_items'] : array(), |
|
391 | + 'excluded_items' => isset($_POST['wpinv_discount_excluded_items']) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
392 | + 'max_uses' => isset($_POST['wpinv_discount_max_uses']) ? $_POST['wpinv_discount_max_uses'] : null, |
|
393 | + 'min_total' => isset($_POST['wpinv_discount_min_total']) ? $_POST['wpinv_discount_min_total'] : null, |
|
394 | + 'max_total' => isset($_POST['wpinv_discount_max_total']) ? $_POST['wpinv_discount_max_total'] : null, |
|
395 | 395 | ) |
396 | 396 | ); |
397 | 397 | |
398 | 398 | $discount->save(); |
399 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
399 | + do_action('getpaid_discount_metabox_save', $post_id, $discount); |
|
400 | 400 | } |
401 | 401 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Retrieves an item by it's ID. |
@@ -14,9 +14,9 @@ discard block |
||
14 | 14 | * @param int the item ID to retrieve. |
15 | 15 | * @return WPInv_Item|false |
16 | 16 | */ |
17 | -function wpinv_get_item_by_id( $id ) { |
|
18 | - $item = wpinv_get_item( $id ); |
|
19 | - return empty( $item ) || $id != $item->get_id() ? false : $item; |
|
17 | +function wpinv_get_item_by_id($id) { |
|
18 | + $item = wpinv_get_item($id); |
|
19 | + return empty($item) || $id != $item->get_id() ? false : $item; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @return WPInv_Item|false |
26 | 26 | */ |
27 | -function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
|
27 | +function wpinv_get_item_by($field = '', $value = '', $type = '') { |
|
28 | 28 | |
29 | - if ( 'id' == strtolower( $field ) ) { |
|
30 | - return wpinv_get_item_by_id( $field ); |
|
29 | + if ('id' == strtolower($field)) { |
|
30 | + return wpinv_get_item_by_id($field); |
|
31 | 31 | } |
32 | 32 | |
33 | - $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type ); |
|
34 | - return $id ? wpinv_get_item( $id ) : false; |
|
33 | + $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type); |
|
34 | + return $id ? wpinv_get_item($id) : false; |
|
35 | 35 | |
36 | 36 | } |
37 | 37 | |
@@ -41,22 +41,22 @@ discard block |
||
41 | 41 | * @param int|WPInv_Item the item to retrieve. |
42 | 42 | * @return WPInv_Item|false |
43 | 43 | */ |
44 | -function wpinv_get_item( $item = 0 ) { |
|
44 | +function wpinv_get_item($item = 0) { |
|
45 | 45 | |
46 | - if ( empty( $item ) ) { |
|
46 | + if (empty($item)) { |
|
47 | 47 | return false; |
48 | 48 | } |
49 | 49 | |
50 | - $item = new WPInv_Item( $item ); |
|
50 | + $item = new WPInv_Item($item); |
|
51 | 51 | return $item->get_id() ? $item : false; |
52 | 52 | |
53 | 53 | } |
54 | 54 | |
55 | -function wpinv_get_all_items( $args = array() ) { |
|
55 | +function wpinv_get_all_items($args = array()) { |
|
56 | 56 | |
57 | - $args = wp_parse_args( $args, array( |
|
58 | - 'status' => array( 'publish' ), |
|
59 | - 'limit' => get_option( 'posts_per_page' ), |
|
57 | + $args = wp_parse_args($args, array( |
|
58 | + 'status' => array('publish'), |
|
59 | + 'limit' => get_option('posts_per_page'), |
|
60 | 60 | 'page' => 1, |
61 | 61 | 'exclude' => array(), |
62 | 62 | 'orderby' => 'date', |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | 'meta_query' => array(), |
66 | 66 | 'return' => 'objects', |
67 | 67 | 'paginate' => false, |
68 | - ) ); |
|
68 | + )); |
|
69 | 69 | |
70 | 70 | $wp_query_args = array( |
71 | 71 | 'post_type' => 'wpi_item', |
@@ -75,26 +75,26 @@ discard block |
||
75 | 75 | 'fields' => 'ids', |
76 | 76 | 'orderby' => $args['orderby'], |
77 | 77 | 'order' => $args['order'], |
78 | - 'paged' => absint( $args['page'] ), |
|
78 | + 'paged' => absint($args['page']), |
|
79 | 79 | ); |
80 | 80 | |
81 | - if ( ! empty( $args['exclude'] ) ) { |
|
82 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
81 | + if (!empty($args['exclude'])) { |
|
82 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
83 | 83 | } |
84 | 84 | |
85 | - if ( ! $args['paginate' ] ) { |
|
85 | + if (!$args['paginate']) { |
|
86 | 86 | $wp_query_args['no_found_rows'] = true; |
87 | 87 | } |
88 | 88 | |
89 | - if ( ! empty( $args['search'] ) ) { |
|
89 | + if (!empty($args['search'])) { |
|
90 | 90 | $wp_query_args['s'] = $args['search']; |
91 | 91 | } |
92 | 92 | |
93 | - if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) { |
|
94 | - $types = wpinv_parse_list( $args['type'] ); |
|
93 | + if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) { |
|
94 | + $types = wpinv_parse_list($args['type']); |
|
95 | 95 | $wp_query_args['meta_query'][] = array( |
96 | 96 | 'key' => '_wpinv_type', |
97 | - 'value' => implode( ',', $types ), |
|
97 | + 'value' => implode(',', $types), |
|
98 | 98 | 'compare' => 'IN', |
99 | 99 | ); |
100 | 100 | } |
@@ -102,17 +102,17 @@ discard block |
||
102 | 102 | $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args); |
103 | 103 | |
104 | 104 | // Get results. |
105 | - $items = new WP_Query( $wp_query_args ); |
|
105 | + $items = new WP_Query($wp_query_args); |
|
106 | 106 | |
107 | - if ( 'objects' === $args['return'] ) { |
|
108 | - $return = array_map( 'wpinv_get_item_by_id', $items->posts ); |
|
109 | - } elseif ( 'self' === $args['return'] ) { |
|
107 | + if ('objects' === $args['return']) { |
|
108 | + $return = array_map('wpinv_get_item_by_id', $items->posts); |
|
109 | + } elseif ('self' === $args['return']) { |
|
110 | 110 | return $items; |
111 | 111 | } else { |
112 | 112 | $return = $items->posts; |
113 | 113 | } |
114 | 114 | |
115 | - if ( $args['paginate' ] ) { |
|
115 | + if ($args['paginate']) { |
|
116 | 116 | return (object) array( |
117 | 117 | 'items' => $return, |
118 | 118 | 'total' => $items->found_posts, |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | |
125 | 125 | } |
126 | 126 | |
127 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
128 | - if( empty( $item_id ) ) { |
|
127 | +function wpinv_is_free_item($item_id = 0) { |
|
128 | + if (empty($item_id)) { |
|
129 | 129 | return false; |
130 | 130 | } |
131 | 131 | |
132 | - $item = new WPInv_Item( $item_id ); |
|
132 | + $item = new WPInv_Item($item_id); |
|
133 | 133 | |
134 | 134 | return $item->is_free(); |
135 | 135 | } |
@@ -139,128 +139,128 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @param WP_Post|WPInv_Item|Int $item The item to check for. |
141 | 141 | */ |
142 | -function wpinv_item_is_editable( $item = 0 ) { |
|
142 | +function wpinv_item_is_editable($item = 0) { |
|
143 | 143 | |
144 | 144 | // Fetch the item. |
145 | - $item = new WPInv_Item( $item ); |
|
145 | + $item = new WPInv_Item($item); |
|
146 | 146 | |
147 | 147 | // Check if it is editable. |
148 | 148 | return $item->is_editable(); |
149 | 149 | } |
150 | 150 | |
151 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
152 | - if( empty( $item_id ) ) { |
|
151 | +function wpinv_get_item_price($item_id = 0) { |
|
152 | + if (empty($item_id)) { |
|
153 | 153 | return false; |
154 | 154 | } |
155 | 155 | |
156 | - $item = new WPInv_Item( $item_id ); |
|
156 | + $item = new WPInv_Item($item_id); |
|
157 | 157 | |
158 | 158 | return $item->get_price(); |
159 | 159 | } |
160 | 160 | |
161 | -function wpinv_is_recurring_item( $item_id = 0 ) { |
|
162 | - if( empty( $item_id ) ) { |
|
161 | +function wpinv_is_recurring_item($item_id = 0) { |
|
162 | + if (empty($item_id)) { |
|
163 | 163 | return false; |
164 | 164 | } |
165 | 165 | |
166 | - $item = new WPInv_Item( $item_id ); |
|
166 | + $item = new WPInv_Item($item_id); |
|
167 | 167 | |
168 | 168 | return $item->is_recurring(); |
169 | 169 | } |
170 | 170 | |
171 | -function wpinv_item_price( $item_id = 0 ) { |
|
172 | - if( empty( $item_id ) ) { |
|
171 | +function wpinv_item_price($item_id = 0) { |
|
172 | + if (empty($item_id)) { |
|
173 | 173 | return false; |
174 | 174 | } |
175 | 175 | |
176 | - $price = wpinv_get_item_price( $item_id ); |
|
177 | - $price = wpinv_price( wpinv_format_amount( $price ) ); |
|
176 | + $price = wpinv_get_item_price($item_id); |
|
177 | + $price = wpinv_price(wpinv_format_amount($price)); |
|
178 | 178 | |
179 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
179 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
180 | 180 | } |
181 | 181 | |
182 | -function wpinv_item_show_price( $item_id = 0, $echo = true ) { |
|
183 | - if ( empty( $item_id ) ) { |
|
182 | +function wpinv_item_show_price($item_id = 0, $echo = true) { |
|
183 | + if (empty($item_id)) { |
|
184 | 184 | $item_id = get_the_ID(); |
185 | 185 | } |
186 | 186 | |
187 | - $price = wpinv_item_price( $item_id ); |
|
187 | + $price = wpinv_item_price($item_id); |
|
188 | 188 | |
189 | - $price = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id ); |
|
189 | + $price = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id); |
|
190 | 190 | $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>'; |
191 | - $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price ); |
|
191 | + $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price); |
|
192 | 192 | |
193 | - if ( $echo ) { |
|
193 | + if ($echo) { |
|
194 | 194 | echo $formatted_price; |
195 | 195 | } else { |
196 | 196 | return $formatted_price; |
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
200 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
201 | - if ( is_null( $amount_override ) ) { |
|
202 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
200 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
201 | + if (is_null($amount_override)) { |
|
202 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
203 | 203 | } else { |
204 | 204 | $original_price = $amount_override; |
205 | 205 | } |
206 | 206 | |
207 | 207 | $price = $original_price; |
208 | 208 | |
209 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
209 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
210 | 210 | } |
211 | 211 | |
212 | -function wpinv_item_custom_singular_name( $item_id ) { |
|
213 | - if( empty( $item_id ) ) { |
|
212 | +function wpinv_item_custom_singular_name($item_id) { |
|
213 | + if (empty($item_id)) { |
|
214 | 214 | return false; |
215 | 215 | } |
216 | 216 | |
217 | - $item = new WPInv_Item( $item_id ); |
|
217 | + $item = new WPInv_Item($item_id); |
|
218 | 218 | |
219 | 219 | return $item->get_custom_singular_name(); |
220 | 220 | } |
221 | 221 | |
222 | 222 | function wpinv_get_item_types() { |
223 | 223 | $item_types = array( |
224 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
225 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
224 | + 'custom' => __('Standard', 'invoicing'), |
|
225 | + 'fee' => __('Fee', 'invoicing'), |
|
226 | 226 | ); |
227 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
227 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | function wpinv_item_types() { |
231 | 231 | $item_types = wpinv_get_item_types(); |
232 | 232 | |
233 | - return ( !empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
233 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
234 | 234 | } |
235 | 235 | |
236 | -function wpinv_get_item_type( $item_id ) { |
|
237 | - if( empty( $item_id ) ) { |
|
236 | +function wpinv_get_item_type($item_id) { |
|
237 | + if (empty($item_id)) { |
|
238 | 238 | return false; |
239 | 239 | } |
240 | 240 | |
241 | - $item = new WPInv_Item( $item_id ); |
|
241 | + $item = new WPInv_Item($item_id); |
|
242 | 242 | |
243 | 243 | return $item->get_type(); |
244 | 244 | } |
245 | 245 | |
246 | -function wpinv_item_type( $item_id ) { |
|
246 | +function wpinv_item_type($item_id) { |
|
247 | 247 | $item_types = wpinv_get_item_types(); |
248 | 248 | |
249 | - $item_type = wpinv_get_item_type( $item_id ); |
|
249 | + $item_type = wpinv_get_item_type($item_id); |
|
250 | 250 | |
251 | - if ( empty( $item_type ) ) { |
|
251 | + if (empty($item_type)) { |
|
252 | 252 | $item_type = '-'; |
253 | 253 | } |
254 | 254 | |
255 | - $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' ); |
|
255 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
256 | 256 | |
257 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
257 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
258 | 258 | } |
259 | 259 | |
260 | -function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) { |
|
260 | +function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) { |
|
261 | 261 | global $wpinv_logs; |
262 | 262 | |
263 | - if ( empty( $wpinv_logs ) ) { |
|
263 | + if (empty($wpinv_logs)) { |
|
264 | 264 | return false; |
265 | 265 | } |
266 | 266 | |
@@ -269,278 +269,278 @@ discard block |
||
269 | 269 | 'log_type' => 'wpi_item' |
270 | 270 | ); |
271 | 271 | |
272 | - $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1; |
|
272 | + $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1; |
|
273 | 273 | |
274 | 274 | $log_meta = array( |
275 | 275 | 'user_info' => $user_info, |
276 | 276 | 'user_id' => $user_id, |
277 | - 'file_id' => (int)$file_id, |
|
277 | + 'file_id' => (int) $file_id, |
|
278 | 278 | 'ip' => $ip, |
279 | 279 | 'invoice_id'=> $invoice_id, |
280 | 280 | ); |
281 | 281 | |
282 | - $wpinv_logs->insert_log( $log_data, $log_meta ); |
|
282 | + $wpinv_logs->insert_log($log_data, $log_meta); |
|
283 | 283 | } |
284 | 284 | |
285 | -function wpinv_remove_item_logs_on_delete( $item_id = 0 ) { |
|
286 | - if ( 'wpi_item' !== get_post_type( $item_id ) ) |
|
285 | +function wpinv_remove_item_logs_on_delete($item_id = 0) { |
|
286 | + if ('wpi_item' !== get_post_type($item_id)) |
|
287 | 287 | return; |
288 | 288 | |
289 | 289 | global $wpinv_logs; |
290 | 290 | |
291 | - if ( empty( $wpinv_logs ) ) { |
|
291 | + if (empty($wpinv_logs)) { |
|
292 | 292 | return false; |
293 | 293 | } |
294 | 294 | |
295 | 295 | // Remove all log entries related to this item |
296 | - $wpinv_logs->delete_logs( $item_id ); |
|
296 | + $wpinv_logs->delete_logs($item_id); |
|
297 | 297 | } |
298 | -add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' ); |
|
298 | +add_action('delete_post', 'wpinv_remove_item_logs_on_delete'); |
|
299 | 299 | |
300 | -function wpinv_get_random_item( $post_ids = true ) { |
|
301 | - wpinv_get_random_items( 1, $post_ids ); |
|
300 | +function wpinv_get_random_item($post_ids = true) { |
|
301 | + wpinv_get_random_items(1, $post_ids); |
|
302 | 302 | } |
303 | 303 | |
304 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
305 | - if ( $post_ids ) { |
|
306 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' ); |
|
304 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
305 | + if ($post_ids) { |
|
306 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids'); |
|
307 | 307 | } else { |
308 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num ); |
|
308 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num); |
|
309 | 309 | } |
310 | 310 | |
311 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
311 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
312 | 312 | |
313 | - return get_posts( $args ); |
|
313 | + return get_posts($args); |
|
314 | 314 | } |
315 | 315 | |
316 | -function wpinv_get_item_token( $url = '' ) { |
|
316 | +function wpinv_get_item_token($url = '') { |
|
317 | 317 | $args = array(); |
318 | - $hash = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' ); |
|
319 | - $secret = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) ); |
|
318 | + $hash = apply_filters('wpinv_get_url_token_algorithm', 'sha256'); |
|
319 | + $secret = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt())); |
|
320 | 320 | |
321 | - $parts = parse_url( $url ); |
|
321 | + $parts = parse_url($url); |
|
322 | 322 | $options = array(); |
323 | 323 | |
324 | - if ( isset( $parts['query'] ) ) { |
|
325 | - wp_parse_str( $parts['query'], $query_args ); |
|
324 | + if (isset($parts['query'])) { |
|
325 | + wp_parse_str($parts['query'], $query_args); |
|
326 | 326 | |
327 | - if ( ! empty( $query_args['o'] ) ) { |
|
328 | - $options = explode( ':', rawurldecode( $query_args['o'] ) ); |
|
327 | + if (!empty($query_args['o'])) { |
|
328 | + $options = explode(':', rawurldecode($query_args['o'])); |
|
329 | 329 | |
330 | - if ( in_array( 'ip', $options ) ) { |
|
330 | + if (in_array('ip', $options)) { |
|
331 | 331 | $args['ip'] = wpinv_get_ip(); |
332 | 332 | } |
333 | 333 | |
334 | - if ( in_array( 'ua', $options ) ) { |
|
334 | + if (in_array('ua', $options)) { |
|
335 | 335 | $ua = wpinv_get_user_agent(); |
336 | - $args['user_agent'] = rawurlencode( $ua ); |
|
336 | + $args['user_agent'] = rawurlencode($ua); |
|
337 | 337 | } |
338 | 338 | } |
339 | 339 | } |
340 | 340 | |
341 | - $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options ); |
|
341 | + $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options); |
|
342 | 342 | |
343 | 343 | $args['secret'] = $secret; |
344 | 344 | $args['token'] = false; |
345 | 345 | |
346 | - $url = add_query_arg( $args, $url ); |
|
347 | - $parts = parse_url( $url ); |
|
346 | + $url = add_query_arg($args, $url); |
|
347 | + $parts = parse_url($url); |
|
348 | 348 | |
349 | - if ( ! isset( $parts['path'] ) ) { |
|
349 | + if (!isset($parts['path'])) { |
|
350 | 350 | $parts['path'] = ''; |
351 | 351 | } |
352 | 352 | |
353 | - $token = md5( $parts['path'] . '?' . $parts['query'] ); |
|
353 | + $token = md5($parts['path'] . '?' . $parts['query']); |
|
354 | 354 | |
355 | 355 | return $token; |
356 | 356 | } |
357 | 357 | |
358 | -function wpinv_validate_url_token( $url = '' ) { |
|
358 | +function wpinv_validate_url_token($url = '') { |
|
359 | 359 | $ret = false; |
360 | - $parts = parse_url( $url ); |
|
360 | + $parts = parse_url($url); |
|
361 | 361 | |
362 | - if ( isset( $parts['query'] ) ) { |
|
363 | - wp_parse_str( $parts['query'], $query_args ); |
|
362 | + if (isset($parts['query'])) { |
|
363 | + wp_parse_str($parts['query'], $query_args); |
|
364 | 364 | |
365 | - $allowed = apply_filters( 'wpinv_url_token_allowed_params', array( |
|
365 | + $allowed = apply_filters('wpinv_url_token_allowed_params', array( |
|
366 | 366 | 'item', |
367 | 367 | 'ttl', |
368 | 368 | 'token' |
369 | - ) ); |
|
369 | + )); |
|
370 | 370 | |
371 | 371 | $remove = array(); |
372 | 372 | |
373 | - foreach( $query_args as $key => $value ) { |
|
374 | - if( false === in_array( $key, $allowed ) ) { |
|
373 | + foreach ($query_args as $key => $value) { |
|
374 | + if (false === in_array($key, $allowed)) { |
|
375 | 375 | $remove[] = $key; |
376 | 376 | } |
377 | 377 | } |
378 | 378 | |
379 | - if( ! empty( $remove ) ) { |
|
380 | - $url = remove_query_arg( $remove, $url ); |
|
379 | + if (!empty($remove)) { |
|
380 | + $url = remove_query_arg($remove, $url); |
|
381 | 381 | } |
382 | 382 | |
383 | - if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) { |
|
384 | - wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
383 | + if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) { |
|
384 | + wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403)); |
|
385 | 385 | } |
386 | 386 | |
387 | - if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) { |
|
387 | + if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) { |
|
388 | 388 | $ret = true; |
389 | 389 | } |
390 | 390 | |
391 | 391 | } |
392 | 392 | |
393 | - return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args ); |
|
393 | + return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args); |
|
394 | 394 | } |
395 | 395 | |
396 | -function wpinv_item_in_cart( $item_id = 0, $options = array() ) { |
|
396 | +function wpinv_item_in_cart($item_id = 0, $options = array()) { |
|
397 | 397 | $cart_items = wpinv_get_cart_contents(); |
398 | 398 | |
399 | 399 | $ret = false; |
400 | 400 | |
401 | - if ( is_array( $cart_items ) ) { |
|
402 | - foreach ( $cart_items as $item ) { |
|
403 | - if ( $item['id'] == $item_id ) { |
|
401 | + if (is_array($cart_items)) { |
|
402 | + foreach ($cart_items as $item) { |
|
403 | + if ($item['id'] == $item_id) { |
|
404 | 404 | $ret = true; |
405 | 405 | break; |
406 | 406 | } |
407 | 407 | } |
408 | 408 | } |
409 | 409 | |
410 | - return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options ); |
|
410 | + return (bool) apply_filters('wpinv_item_in_cart', $ret, $item_id, $options); |
|
411 | 411 | } |
412 | 412 | |
413 | -function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) { |
|
413 | +function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) { |
|
414 | 414 | $tax = 0; |
415 | - if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
416 | - $country = !empty( $_POST['country'] ) ? $_POST['country'] : false; |
|
417 | - $state = isset( $_POST['state'] ) ? $_POST['state'] : ''; |
|
415 | + if (!wpinv_item_is_tax_exclusive($item_id)) { |
|
416 | + $country = !empty($_POST['country']) ? $_POST['country'] : false; |
|
417 | + $state = isset($_POST['state']) ? $_POST['state'] : ''; |
|
418 | 418 | |
419 | - $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id ); |
|
419 | + $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id); |
|
420 | 420 | } |
421 | 421 | |
422 | - return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options ); |
|
422 | + return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options); |
|
423 | 423 | } |
424 | 424 | |
425 | -function wpinv_cart_item_price( $item, $currency = '' ) { |
|
425 | +function wpinv_cart_item_price($item, $currency = '') { |
|
426 | 426 | |
427 | - if( empty( $currency ) ) { |
|
427 | + if (empty($currency)) { |
|
428 | 428 | $currency = wpinv_get_currency(); |
429 | 429 | } |
430 | 430 | |
431 | - $item_id = isset( $item['id'] ) ? $item['id'] : 0; |
|
432 | - $price = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0; |
|
433 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ) ); |
|
431 | + $item_id = isset($item['id']) ? $item['id'] : 0; |
|
432 | + $price = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0; |
|
433 | + $tax = wpinv_price(wpinv_format_amount($item['tax'])); |
|
434 | 434 | |
435 | - if ( !wpinv_is_free_item( $item_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
436 | - if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) { |
|
435 | + if (!wpinv_is_free_item($item_id) && !wpinv_item_is_tax_exclusive($item_id)) { |
|
436 | + if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) { |
|
437 | 437 | $price += $tax; |
438 | 438 | } |
439 | 439 | |
440 | - if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) { |
|
440 | + if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) { |
|
441 | 441 | $price -= $tax; |
442 | 442 | } |
443 | 443 | } |
444 | 444 | |
445 | - $price = wpinv_price( wpinv_format_amount( $price ), $currency ); |
|
445 | + $price = wpinv_price(wpinv_format_amount($price), $currency); |
|
446 | 446 | |
447 | - return apply_filters( 'wpinv_cart_item_price_label', $price, $item ); |
|
447 | + return apply_filters('wpinv_cart_item_price_label', $price, $item); |
|
448 | 448 | } |
449 | 449 | |
450 | -function wpinv_cart_item_subtotal( $item, $currency = '' ) { |
|
450 | +function wpinv_cart_item_subtotal($item, $currency = '') { |
|
451 | 451 | |
452 | - if( empty( $currency ) ) { |
|
452 | + if (empty($currency)) { |
|
453 | 453 | $currency = wpinv_get_currency(); |
454 | 454 | } |
455 | 455 | |
456 | - $subtotal = isset( $item['subtotal'] ) ? $item['subtotal'] : 0; |
|
457 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal ), $currency ); |
|
456 | + $subtotal = isset($item['subtotal']) ? $item['subtotal'] : 0; |
|
457 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal), $currency); |
|
458 | 458 | |
459 | - return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item ); |
|
459 | + return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item); |
|
460 | 460 | } |
461 | 461 | |
462 | -function wpinv_cart_item_tax( $item, $currency = '' ) { |
|
462 | +function wpinv_cart_item_tax($item, $currency = '') { |
|
463 | 463 | $tax = ''; |
464 | 464 | $tax_rate = ''; |
465 | 465 | |
466 | - if( empty( $currency ) ) { |
|
466 | + if (empty($currency)) { |
|
467 | 467 | $currency = wpinv_get_currency(); |
468 | 468 | } |
469 | 469 | |
470 | - if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) { |
|
471 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ), $currency ); |
|
472 | - $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100; |
|
473 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
470 | + if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) { |
|
471 | + $tax = wpinv_price(wpinv_format_amount($item['tax']), $currency); |
|
472 | + $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100; |
|
473 | + $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : ''; |
|
474 | 474 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : ''; |
475 | 475 | } |
476 | 476 | |
477 | - $tax = $tax . $tax_rate; |
|
477 | + $tax = $tax . $tax_rate; |
|
478 | 478 | |
479 | - if ( $tax === '' ) { |
|
479 | + if ($tax === '') { |
|
480 | 480 | $tax = 0; // Zero tax |
481 | 481 | } |
482 | 482 | |
483 | - return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item ); |
|
483 | + return apply_filters('wpinv_cart_item_tax_label', $tax, $item); |
|
484 | 484 | } |
485 | 485 | |
486 | -function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) { |
|
486 | +function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) { |
|
487 | 487 | $price = 0; |
488 | 488 | |
489 | 489 | // Set custom price |
490 | - if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) { |
|
490 | + if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') { |
|
491 | 491 | $price = $cart_item['custom_price']; |
492 | 492 | } else { |
493 | - $variable_prices = wpinv_has_variable_prices( $item_id ); |
|
493 | + $variable_prices = wpinv_has_variable_prices($item_id); |
|
494 | 494 | |
495 | - if ( $variable_prices ) { |
|
496 | - $prices = wpinv_get_variable_prices( $item_id ); |
|
495 | + if ($variable_prices) { |
|
496 | + $prices = wpinv_get_variable_prices($item_id); |
|
497 | 497 | |
498 | - if ( $prices ) { |
|
499 | - if( ! empty( $options ) ) { |
|
500 | - $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false; |
|
498 | + if ($prices) { |
|
499 | + if (!empty($options)) { |
|
500 | + $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false; |
|
501 | 501 | } else { |
502 | 502 | $price = false; |
503 | 503 | } |
504 | 504 | } |
505 | 505 | } |
506 | 506 | |
507 | - if( ! $variable_prices || false === $price ) { |
|
508 | - if($cart_item['item_price'] > 0){ |
|
507 | + if (!$variable_prices || false === $price) { |
|
508 | + if ($cart_item['item_price'] > 0) { |
|
509 | 509 | $price = $cart_item['item_price']; |
510 | 510 | } else { |
511 | 511 | // Get the standard Item price if not using variable prices |
512 | - $price = wpinv_get_item_price( $item_id ); |
|
512 | + $price = wpinv_get_item_price($item_id); |
|
513 | 513 | } |
514 | 514 | } |
515 | 515 | } |
516 | 516 | |
517 | - if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) { |
|
518 | - $price -= wpinv_get_cart_item_tax( $item_id, $price, $options ); |
|
517 | + if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) { |
|
518 | + $price -= wpinv_get_cart_item_tax($item_id, $price, $options); |
|
519 | 519 | } |
520 | 520 | |
521 | - return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive ); |
|
521 | + return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive); |
|
522 | 522 | } |
523 | 523 | |
524 | -function wpinv_get_cart_item_price_id( $item = array() ) { |
|
525 | - if( isset( $item['item_number'] ) ) { |
|
526 | - $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null; |
|
524 | +function wpinv_get_cart_item_price_id($item = array()) { |
|
525 | + if (isset($item['item_number'])) { |
|
526 | + $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null; |
|
527 | 527 | } else { |
528 | - $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null; |
|
528 | + $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null; |
|
529 | 529 | } |
530 | 530 | return $price_id; |
531 | 531 | } |
532 | 532 | |
533 | -function wpinv_get_cart_item_price_name( $item = array() ) { |
|
534 | - $price_id = (int)wpinv_get_cart_item_price_id( $item ); |
|
535 | - $prices = wpinv_get_variable_prices( $item['id'] ); |
|
536 | - $name = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : ''; |
|
537 | - return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item ); |
|
533 | +function wpinv_get_cart_item_price_name($item = array()) { |
|
534 | + $price_id = (int) wpinv_get_cart_item_price_id($item); |
|
535 | + $prices = wpinv_get_variable_prices($item['id']); |
|
536 | + $name = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : ''; |
|
537 | + return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item); |
|
538 | 538 | } |
539 | 539 | |
540 | -function wpinv_get_cart_item_name( $item = array() ) { |
|
541 | - $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] ); |
|
540 | +function wpinv_get_cart_item_name($item = array()) { |
|
541 | + $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']); |
|
542 | 542 | |
543 | - if ( empty( $item_title ) ) { |
|
543 | + if (empty($item_title)) { |
|
544 | 544 | $item_title = $item['id']; |
545 | 545 | } |
546 | 546 | |
@@ -550,23 +550,23 @@ discard block |
||
550 | 550 | } |
551 | 551 | */ |
552 | 552 | |
553 | - return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item ); |
|
553 | + return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item); |
|
554 | 554 | } |
555 | 555 | |
556 | -function wpinv_has_variable_prices( $item_id = 0 ) { |
|
556 | +function wpinv_has_variable_prices($item_id = 0) { |
|
557 | 557 | return false; |
558 | 558 | } |
559 | 559 | |
560 | -function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) { |
|
560 | +function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) { |
|
561 | 561 | $cart_items = wpinv_get_cart_contents(); |
562 | 562 | |
563 | - if ( !is_array( $cart_items ) ) { |
|
563 | + if (!is_array($cart_items)) { |
|
564 | 564 | return false; // Empty cart |
565 | 565 | } else { |
566 | - foreach ( $cart_items as $position => $item ) { |
|
567 | - if ( $item['id'] == $item_id ) { |
|
568 | - if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) { |
|
569 | - if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) { |
|
566 | + foreach ($cart_items as $position => $item) { |
|
567 | + if ($item['id'] == $item_id) { |
|
568 | + if (isset($options['price_id']) && isset($item['options']['price_id'])) { |
|
569 | + if ((int) $options['price_id'] == (int) $item['options']['price_id']) { |
|
570 | 570 | return $position; |
571 | 571 | } |
572 | 572 | } else { |
@@ -579,80 +579,80 @@ discard block |
||
579 | 579 | return false; // Not found |
580 | 580 | } |
581 | 581 | |
582 | -function wpinv_get_cart_item_quantity( $item ) { |
|
583 | - if ( wpinv_item_quantities_enabled() ) { |
|
584 | - $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
582 | +function wpinv_get_cart_item_quantity($item) { |
|
583 | + if (wpinv_item_quantities_enabled()) { |
|
584 | + $quantity = !empty($item['quantity']) && (int) $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
585 | 585 | } else { |
586 | 586 | $quantity = 1; |
587 | 587 | } |
588 | 588 | |
589 | - if ( $quantity < 1 ) { |
|
589 | + if ($quantity < 1) { |
|
590 | 590 | $quantity = 1; |
591 | 591 | } |
592 | 592 | |
593 | - return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item ); |
|
593 | + return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item); |
|
594 | 594 | } |
595 | 595 | |
596 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
597 | - if ( empty( $item ) ) { |
|
596 | +function wpinv_get_item_suffix($item, $html = true) { |
|
597 | + if (empty($item)) { |
|
598 | 598 | return NULL; |
599 | 599 | } |
600 | 600 | |
601 | - if ( is_int( $item ) ) { |
|
602 | - $item = new WPInv_Item( $item ); |
|
601 | + if (is_int($item)) { |
|
602 | + $item = new WPInv_Item($item); |
|
603 | 603 | } |
604 | 604 | |
605 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
605 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
606 | 606 | return NULL; |
607 | 607 | } |
608 | 608 | |
609 | - $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : ''; |
|
609 | + $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''; |
|
610 | 610 | |
611 | - if ( !$html && $suffix ) { |
|
612 | - $suffix = strip_tags( $suffix ); |
|
611 | + if (!$html && $suffix) { |
|
612 | + $suffix = strip_tags($suffix); |
|
613 | 613 | } |
614 | 614 | |
615 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
615 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
616 | 616 | } |
617 | 617 | |
618 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
619 | - if ( empty( $item ) ) { |
|
618 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
619 | + if (empty($item)) { |
|
620 | 620 | return NULL; |
621 | 621 | } |
622 | 622 | |
623 | - if ( is_int( $item ) ) { |
|
624 | - $item = new WPInv_Item( $item ); |
|
623 | + if (is_int($item)) { |
|
624 | + $item = new WPInv_Item($item); |
|
625 | 625 | } |
626 | 626 | |
627 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
627 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
628 | 628 | return NULL; |
629 | 629 | } |
630 | 630 | |
631 | - do_action( 'wpinv_pre_delete_item', $item ); |
|
631 | + do_action('wpinv_pre_delete_item', $item); |
|
632 | 632 | |
633 | - wp_delete_post( $item->ID, $force_delete ); |
|
633 | + wp_delete_post($item->ID, $force_delete); |
|
634 | 634 | |
635 | - do_action( 'wpinv_post_delete_item', $item ); |
|
635 | + do_action('wpinv_post_delete_item', $item); |
|
636 | 636 | } |
637 | 637 | |
638 | -function wpinv_can_delete_item( $post_id ) { |
|
638 | +function wpinv_can_delete_item($post_id) { |
|
639 | 639 | $return = wpinv_current_user_can_manage_invoicing() ? true : false; |
640 | 640 | |
641 | - if ( $return && wpinv_item_in_use( $post_id ) ) { |
|
641 | + if ($return && wpinv_item_in_use($post_id)) { |
|
642 | 642 | $return = false; // Don't delete item already use in invoices. |
643 | 643 | } |
644 | 644 | |
645 | - return apply_filters( 'wpinv_can_delete_item', $return, $post_id ); |
|
645 | + return apply_filters('wpinv_can_delete_item', $return, $post_id); |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | function wpinv_admin_action_delete() { |
649 | 649 | $screen = get_current_screen(); |
650 | 650 | |
651 | - if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) { |
|
651 | + if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) { |
|
652 | 652 | $post_ids = array(); |
653 | 653 | |
654 | - foreach ( $_REQUEST['post'] as $post_id ) { |
|
655 | - if ( !wpinv_can_delete_item( $post_id ) ) { |
|
654 | + foreach ($_REQUEST['post'] as $post_id) { |
|
655 | + if (!wpinv_can_delete_item($post_id)) { |
|
656 | 656 | continue; |
657 | 657 | } |
658 | 658 | |
@@ -662,39 +662,39 @@ discard block |
||
662 | 662 | $_REQUEST['post'] = $post_ids; |
663 | 663 | } |
664 | 664 | } |
665 | -add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 ); |
|
666 | -add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 ); |
|
665 | +add_action('admin_action_trash', 'wpinv_admin_action_delete', -10); |
|
666 | +add_action('admin_action_delete', 'wpinv_admin_action_delete', -10); |
|
667 | 667 | |
668 | -function wpinv_check_delete_item( $check, $post, $force_delete ) { |
|
669 | - if ( $post->post_type == 'wpi_item' ) { |
|
670 | - if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) { |
|
668 | +function wpinv_check_delete_item($check, $post, $force_delete) { |
|
669 | + if ($post->post_type == 'wpi_item') { |
|
670 | + if ($force_delete && !wpinv_can_delete_item($post->ID)) { |
|
671 | 671 | return true; |
672 | 672 | } |
673 | 673 | } |
674 | 674 | |
675 | 675 | return $check; |
676 | 676 | } |
677 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 ); |
|
677 | +add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3); |
|
678 | 678 | |
679 | -function wpinv_item_in_use( $item_id ) { |
|
679 | +function wpinv_item_in_use($item_id) { |
|
680 | 680 | global $wpdb, $wpi_items_in_use; |
681 | 681 | |
682 | - if ( !$item_id > 0 ) { |
|
682 | + if (!$item_id > 0) { |
|
683 | 683 | return false; |
684 | 684 | } |
685 | 685 | |
686 | - if ( !empty( $wpi_items_in_use ) ) { |
|
687 | - if ( isset( $wpi_items_in_use[$item_id] ) ) { |
|
686 | + if (!empty($wpi_items_in_use)) { |
|
687 | + if (isset($wpi_items_in_use[$item_id])) { |
|
688 | 688 | return $wpi_items_in_use[$item_id]; |
689 | 689 | } |
690 | 690 | } else { |
691 | 691 | $wpi_items_in_use = array(); |
692 | 692 | } |
693 | 693 | |
694 | - $statuses = array_keys( wpinv_get_invoice_statuses( true, true ) ); |
|
694 | + $statuses = array_keys(wpinv_get_invoice_statuses(true, true)); |
|
695 | 695 | |
696 | - $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )"; |
|
697 | - $in_use = $wpdb->get_var( $query ) > 0 ? true : false; |
|
696 | + $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int) $item_id . "', pm.meta_value )"; |
|
697 | + $in_use = $wpdb->get_var($query) > 0 ? true : false; |
|
698 | 698 | |
699 | 699 | $wpi_items_in_use[$item_id] = $in_use; |
700 | 700 | |
@@ -737,45 +737,45 @@ discard block |
||
737 | 737 | * @param bool $wp_error whether or not to return a WP_Error on failure. |
738 | 738 | * @return bool|WP_Error|WPInv_Item |
739 | 739 | */ |
740 | -function wpinv_create_item( $args = array(), $wp_error = false ) { |
|
740 | +function wpinv_create_item($args = array(), $wp_error = false) { |
|
741 | 741 | |
742 | 742 | // Prepare the item. |
743 | - if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) { |
|
744 | - $type = empty( $args['type'] ) ? 'custom' : $args['type']; |
|
745 | - $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type ); |
|
743 | + if (!empty($args['custom_id']) && empty($args['ID'])) { |
|
744 | + $type = empty($args['type']) ? 'custom' : $args['type']; |
|
745 | + $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type); |
|
746 | 746 | |
747 | - if ( ! empty( $item ) ) { |
|
747 | + if (!empty($item)) { |
|
748 | 748 | $args['ID'] = $item->get_id(); |
749 | 749 | } |
750 | 750 | |
751 | 751 | } |
752 | 752 | |
753 | 753 | // Do we have an item? |
754 | - if ( ! empty( $args['ID'] ) ) { |
|
755 | - $item = new WPInv_Item( $args['ID'] ); |
|
754 | + if (!empty($args['ID'])) { |
|
755 | + $item = new WPInv_Item($args['ID']); |
|
756 | 756 | } else { |
757 | 757 | $item = new WPInv_Item(); |
758 | 758 | } |
759 | 759 | |
760 | 760 | // Do we have an error? |
761 | - if ( ! empty( $item->last_error ) ) { |
|
762 | - return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false; |
|
761 | + if (!empty($item->last_error)) { |
|
762 | + return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false; |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | // Update item props. |
766 | - $item->set_props( $args ); |
|
766 | + $item->set_props($args); |
|
767 | 767 | |
768 | 768 | // Save the item. |
769 | 769 | $item->save(); |
770 | 770 | |
771 | 771 | // Do we have an error? |
772 | - if ( ! empty( $item->last_error ) ) { |
|
773 | - return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false; |
|
772 | + if (!empty($item->last_error)) { |
|
773 | + return $wp_error ? new WP_Error('not_saved', $item->last_error) : false; |
|
774 | 774 | } |
775 | 775 | |
776 | 776 | // Was the item saved? |
777 | - if ( ! $item->get_id() ) { |
|
778 | - return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false; |
|
777 | + if (!$item->get_id()) { |
|
778 | + return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false; |
|
779 | 779 | } |
780 | 780 | |
781 | 781 | return $item; |
@@ -787,14 +787,14 @@ discard block |
||
787 | 787 | * |
788 | 788 | * @see wpinv_create_item() |
789 | 789 | */ |
790 | -function wpinv_update_item( $args = array(), $wp_error = false ) { |
|
791 | - return wpinv_create_item( $args, $wp_error ); |
|
790 | +function wpinv_update_item($args = array(), $wp_error = false) { |
|
791 | + return wpinv_create_item($args, $wp_error); |
|
792 | 792 | } |
793 | 793 | |
794 | 794 | /** |
795 | 795 | * Sanitizes a recurring period |
796 | 796 | */ |
797 | -function getpaid_sanitize_recurring_period( $period, $full = false ) { |
|
797 | +function getpaid_sanitize_recurring_period($period, $full = false) { |
|
798 | 798 | |
799 | 799 | $periods = array( |
800 | 800 | 'D' => 'day', |
@@ -803,11 +803,11 @@ discard block |
||
803 | 803 | 'Y' => 'year', |
804 | 804 | ); |
805 | 805 | |
806 | - if ( ! isset( $periods[ $period ] ) ) { |
|
806 | + if (!isset($periods[$period])) { |
|
807 | 807 | $period = 'D'; |
808 | 808 | } |
809 | 809 | |
810 | - return $full ? $periods[ $period ] : $period; |
|
810 | + return $full ? $periods[$period] : $period; |
|
811 | 811 | |
812 | 812 | } |
813 | 813 | |
@@ -816,29 +816,29 @@ discard block |
||
816 | 816 | * |
817 | 817 | * @param WPInv_Item $item |
818 | 818 | */ |
819 | -function getpaid_item_recurring_price_help_text( $item, $currency = '' ) { |
|
819 | +function getpaid_item_recurring_price_help_text($item, $currency = '') { |
|
820 | 820 | |
821 | 821 | // Abort if it is not recurring. |
822 | - if ( ! $item->is_recurring() ) { |
|
822 | + if (!$item->is_recurring()) { |
|
823 | 823 | return ''; |
824 | 824 | } |
825 | 825 | |
826 | - $initial_price = wpinv_price( wpinv_sanitize_amount( $item->get_initial_price() ), $currency ); |
|
827 | - $recurring_price = wpinv_price( wpinv_sanitize_amount( $item->get_recurring_price() ), $currency ); |
|
828 | - $period = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ); |
|
826 | + $initial_price = wpinv_price(wpinv_sanitize_amount($item->get_initial_price()), $currency); |
|
827 | + $recurring_price = wpinv_price(wpinv_sanitize_amount($item->get_recurring_price()), $currency); |
|
828 | + $period = getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), ''); |
|
829 | 829 | $initial_class = 'getpaid-item-initial-price'; |
830 | 830 | $recurring_class = 'getpaid-item-recurring-price'; |
831 | 831 | |
832 | 832 | // For free trial items. |
833 | - if ( $item->has_free_trial() ) { |
|
834 | - $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() ); |
|
833 | + if ($item->has_free_trial()) { |
|
834 | + $trial_period = getpaid_get_subscription_period_label($item->get_trial_period(), $item->get_trial_interval()); |
|
835 | 835 | |
836 | - if ( 0 == $item->get_initial_price() ) { |
|
836 | + if (0 == $item->get_initial_price()) { |
|
837 | 837 | |
838 | 838 | return sprintf( |
839 | 839 | |
840 | 840 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period |
841 | - _x( 'Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ), |
|
841 | + _x('Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing'), |
|
842 | 842 | $trial_period, |
843 | 843 | "<span class='$recurring_class'>$recurring_price</span>", |
844 | 844 | $period |
@@ -850,7 +850,7 @@ discard block |
||
850 | 850 | return sprintf( |
851 | 851 | |
852 | 852 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period |
853 | - _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ), |
|
853 | + _x('%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing'), |
|
854 | 854 | "<span class='$initial_class'>$initial_price</span>", |
855 | 855 | $trial_period, |
856 | 856 | "<span class='$recurring_class'>$recurring_price</span>", |
@@ -860,12 +860,12 @@ discard block |
||
860 | 860 | |
861 | 861 | } |
862 | 862 | |
863 | - if ( $initial_price == $recurring_price ) { |
|
863 | + if ($initial_price == $recurring_price) { |
|
864 | 864 | |
865 | 865 | return sprintf( |
866 | 866 | |
867 | 867 | // translators: $1: is the recurring price, $2: is the susbcription period |
868 | - _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
868 | + _x('%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing'), |
|
869 | 869 | "<span class='$recurring_class'>$recurring_price</span>", |
870 | 870 | $period |
871 | 871 | |
@@ -876,7 +876,7 @@ discard block |
||
876 | 876 | return sprintf( |
877 | 877 | |
878 | 878 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period |
879 | - _x( 'Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ), |
|
879 | + _x('Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing'), |
|
880 | 880 | "<span class='$initial_class'>$initial_price</span>", |
881 | 881 | "<span class='$recurring_class'>$recurring_price</span>", |
882 | 882 | $period |
@@ -12,108 +12,108 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Fees { |
14 | 14 | |
15 | - /** |
|
16 | - * The fee validation error. |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - public $fee_error; |
|
20 | - |
|
21 | - /** |
|
22 | - * Submission fees. |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - public $fees = array(); |
|
15 | + /** |
|
16 | + * The fee validation error. |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + public $fee_error; |
|
20 | + |
|
21 | + /** |
|
22 | + * Submission fees. |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + public $fees = array(); |
|
26 | + |
|
27 | + /** |
|
28 | + * Class constructor |
|
29 | + * |
|
30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
31 | + */ |
|
32 | + public function __construct( $submission ) { |
|
33 | + |
|
34 | + // Process any existing invoice fees. |
|
35 | + if ( $submission->has_invoice() ) { |
|
36 | + $this->fees = $submission->get_invoice()->get_fees(); |
|
37 | + } |
|
38 | + |
|
39 | + // Process price fields. |
|
40 | + $data = $submission->get_data(); |
|
41 | + $payment_form = $submission->get_payment_form(); |
|
42 | + |
|
43 | + foreach ( $payment_form->get_elements() as $element ) { |
|
44 | + |
|
45 | + if ( 'price_input' == $element['type'] ) { |
|
46 | + $this->process_price_input( $element, $data ); |
|
47 | + } |
|
48 | + |
|
49 | + if ( 'price_select' == $element['type'] ) { |
|
50 | + $this->process_price_select( $element, $data ); |
|
51 | + } |
|
52 | + |
|
53 | + } |
|
54 | + |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Process a price input field. |
|
59 | + * |
|
60 | + * @param array $element |
|
61 | + * @param array $data |
|
62 | + */ |
|
63 | + public function process_price_input( $element, $data ) { |
|
64 | + |
|
65 | + // Abort if not passed. |
|
66 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
67 | + return; |
|
68 | + } |
|
69 | + |
|
70 | + $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
71 | + $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
72 | + |
|
73 | + if ( $amount < $minimum ) { |
|
74 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) ); |
|
75 | + } |
|
76 | + |
|
77 | + $this->fees[ $element['label'] ] = array( |
|
78 | + 'name' => $element['label'], |
|
79 | + 'initial_fee' => $amount, |
|
80 | + 'recurring_fee' => 0, |
|
81 | + ); |
|
82 | + |
|
83 | + } |
|
26 | 84 | |
27 | 85 | /** |
28 | - * Class constructor |
|
29 | - * |
|
30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
31 | - */ |
|
32 | - public function __construct( $submission ) { |
|
33 | - |
|
34 | - // Process any existing invoice fees. |
|
35 | - if ( $submission->has_invoice() ) { |
|
36 | - $this->fees = $submission->get_invoice()->get_fees(); |
|
37 | - } |
|
38 | - |
|
39 | - // Process price fields. |
|
40 | - $data = $submission->get_data(); |
|
41 | - $payment_form = $submission->get_payment_form(); |
|
42 | - |
|
43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
44 | - |
|
45 | - if ( 'price_input' == $element['type'] ) { |
|
46 | - $this->process_price_input( $element, $data ); |
|
47 | - } |
|
48 | - |
|
49 | - if ( 'price_select' == $element['type'] ) { |
|
50 | - $this->process_price_select( $element, $data ); |
|
51 | - } |
|
52 | - |
|
53 | - } |
|
54 | - |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Process a price input field. |
|
59 | - * |
|
60 | - * @param array $element |
|
61 | - * @param array $data |
|
62 | - */ |
|
63 | - public function process_price_input( $element, $data ) { |
|
64 | - |
|
65 | - // Abort if not passed. |
|
66 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
67 | - return; |
|
68 | - } |
|
69 | - |
|
70 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
71 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
72 | - |
|
73 | - if ( $amount < $minimum ) { |
|
74 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) ); |
|
75 | - } |
|
76 | - |
|
77 | - $this->fees[ $element['label'] ] = array( |
|
78 | - 'name' => $element['label'], |
|
79 | - 'initial_fee' => $amount, |
|
80 | - 'recurring_fee' => 0, |
|
81 | - ); |
|
82 | - |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Process a price select field. |
|
87 | - * |
|
88 | - * @param array $element |
|
89 | - * @param array $data |
|
90 | - */ |
|
91 | - public function process_price_select( $element, $data ) { |
|
92 | - |
|
93 | - // Abort if not passed. |
|
94 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
95 | - return; |
|
96 | - } |
|
97 | - |
|
98 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
99 | - $selected = wpinv_parse_list( $data[ $element['id'] ] ); |
|
100 | - $total = 0; |
|
101 | - |
|
102 | - foreach ( $selected as $price ) { |
|
103 | - |
|
104 | - if ( ! isset( $options[ $price ] ) ) { |
|
105 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
106 | - } |
|
107 | - |
|
108 | - $total += (float) wpinv_sanitize_amount( $price ); |
|
109 | - } |
|
110 | - |
|
111 | - $this->fees[ $element['label'] ] = array( |
|
112 | - 'name' => $element['label'], |
|
113 | - 'initial_fee' => $total, |
|
114 | - 'recurring_fee' => 0, |
|
115 | - ); |
|
116 | - |
|
117 | - } |
|
86 | + * Process a price select field. |
|
87 | + * |
|
88 | + * @param array $element |
|
89 | + * @param array $data |
|
90 | + */ |
|
91 | + public function process_price_select( $element, $data ) { |
|
92 | + |
|
93 | + // Abort if not passed. |
|
94 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
95 | + return; |
|
96 | + } |
|
97 | + |
|
98 | + $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
99 | + $selected = wpinv_parse_list( $data[ $element['id'] ] ); |
|
100 | + $total = 0; |
|
101 | + |
|
102 | + foreach ( $selected as $price ) { |
|
103 | + |
|
104 | + if ( ! isset( $options[ $price ] ) ) { |
|
105 | + throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
106 | + } |
|
107 | + |
|
108 | + $total += (float) wpinv_sanitize_amount( $price ); |
|
109 | + } |
|
110 | + |
|
111 | + $this->fees[ $element['label'] ] = array( |
|
112 | + 'name' => $element['label'], |
|
113 | + 'initial_fee' => $total, |
|
114 | + 'recurring_fee' => 0, |
|
115 | + ); |
|
116 | + |
|
117 | + } |
|
118 | 118 | |
119 | 119 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment form submission fees class |
@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @param GetPaid_Payment_Form_Submission $submission |
31 | 31 | */ |
32 | - public function __construct( $submission ) { |
|
32 | + public function __construct($submission) { |
|
33 | 33 | |
34 | 34 | // Process any existing invoice fees. |
35 | - if ( $submission->has_invoice() ) { |
|
35 | + if ($submission->has_invoice()) { |
|
36 | 36 | $this->fees = $submission->get_invoice()->get_fees(); |
37 | 37 | } |
38 | 38 | |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | $data = $submission->get_data(); |
41 | 41 | $payment_form = $submission->get_payment_form(); |
42 | 42 | |
43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
43 | + foreach ($payment_form->get_elements() as $element) { |
|
44 | 44 | |
45 | - if ( 'price_input' == $element['type'] ) { |
|
46 | - $this->process_price_input( $element, $data ); |
|
45 | + if ('price_input' == $element['type']) { |
|
46 | + $this->process_price_input($element, $data); |
|
47 | 47 | } |
48 | 48 | |
49 | - if ( 'price_select' == $element['type'] ) { |
|
50 | - $this->process_price_select( $element, $data ); |
|
49 | + if ('price_select' == $element['type']) { |
|
50 | + $this->process_price_select($element, $data); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | } |
@@ -60,21 +60,21 @@ discard block |
||
60 | 60 | * @param array $element |
61 | 61 | * @param array $data |
62 | 62 | */ |
63 | - public function process_price_input( $element, $data ) { |
|
63 | + public function process_price_input($element, $data) { |
|
64 | 64 | |
65 | 65 | // Abort if not passed. |
66 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
66 | + if (empty($data[$element['id']])) { |
|
67 | 67 | return; |
68 | 68 | } |
69 | 69 | |
70 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
71 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
70 | + $amount = (float) wpinv_sanitize_amount($data[$element['id']]); |
|
71 | + $minimum = empty($element['minimum']) ? 0 : (float) wpinv_sanitize_amount($element['minimum']); |
|
72 | 72 | |
73 | - if ( $amount < $minimum ) { |
|
74 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) ); |
|
73 | + if ($amount < $minimum) { |
|
74 | + throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), $minimum)); |
|
75 | 75 | } |
76 | 76 | |
77 | - $this->fees[ $element['label'] ] = array( |
|
77 | + $this->fees[$element['label']] = array( |
|
78 | 78 | 'name' => $element['label'], |
79 | 79 | 'initial_fee' => $amount, |
80 | 80 | 'recurring_fee' => 0, |
@@ -88,27 +88,27 @@ discard block |
||
88 | 88 | * @param array $element |
89 | 89 | * @param array $data |
90 | 90 | */ |
91 | - public function process_price_select( $element, $data ) { |
|
91 | + public function process_price_select($element, $data) { |
|
92 | 92 | |
93 | 93 | // Abort if not passed. |
94 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
94 | + if (empty($data[$element['id']])) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
99 | - $selected = wpinv_parse_list( $data[ $element['id'] ] ); |
|
98 | + $options = getpaid_convert_price_string_to_options($element['options']); |
|
99 | + $selected = wpinv_parse_list($data[$element['id']]); |
|
100 | 100 | $total = 0; |
101 | 101 | |
102 | - foreach ( $selected as $price ) { |
|
102 | + foreach ($selected as $price) { |
|
103 | 103 | |
104 | - if ( ! isset( $options[ $price ] ) ) { |
|
105 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
104 | + if (!isset($options[$price])) { |
|
105 | + throw new Exception(__('You have selected an invalid amount', 'invoicing')); |
|
106 | 106 | } |
107 | 107 | |
108 | - $total += (float) wpinv_sanitize_amount( $price ); |
|
108 | + $total += (float) wpinv_sanitize_amount($price); |
|
109 | 109 | } |
110 | 110 | |
111 | - $this->fees[ $element['label'] ] = array( |
|
111 | + $this->fees[$element['label']] = array( |
|
112 | 112 | 'name' => $element['label'], |
113 | 113 | 'initial_fee' => $total, |
114 | 114 | 'recurring_fee' => 0, |
@@ -12,231 +12,231 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Taxes { |
14 | 14 | |
15 | - /** |
|
16 | - * Submission taxes. |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $taxes = array(); |
|
20 | - |
|
21 | - /** |
|
22 | - * Initial tax. |
|
23 | - * @var float |
|
24 | - */ |
|
25 | - protected $initial_tax = 0; |
|
26 | - |
|
27 | - /** |
|
28 | - * Recurring tax. |
|
29 | - * @var float |
|
30 | - */ |
|
31 | - protected $recurring_tax = 0; |
|
15 | + /** |
|
16 | + * Submission taxes. |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $taxes = array(); |
|
20 | + |
|
21 | + /** |
|
22 | + * Initial tax. |
|
23 | + * @var float |
|
24 | + */ |
|
25 | + protected $initial_tax = 0; |
|
26 | + |
|
27 | + /** |
|
28 | + * Recurring tax. |
|
29 | + * @var float |
|
30 | + */ |
|
31 | + protected $recurring_tax = 0; |
|
32 | + |
|
33 | + /** |
|
34 | + * Class constructor |
|
35 | + * |
|
36 | + * @param GetPaid_Payment_Form_Submission $submission |
|
37 | + */ |
|
38 | + public function __construct( $submission ) { |
|
39 | + |
|
40 | + // Validate VAT number. |
|
41 | + $this->validate_vat( $submission ); |
|
42 | + |
|
43 | + foreach ( $submission->get_items() as $item ) { |
|
44 | + $this->process_item_tax( $item, $submission ); |
|
45 | + } |
|
46 | + |
|
47 | + // Process any existing invoice taxes. |
|
48 | + if ( $submission->has_invoice() ) { |
|
49 | + $this->taxes = $submission->get_invoice()->get_taxes(); |
|
50 | + } |
|
51 | + |
|
52 | + // Add VAT. |
|
53 | + $this->taxes['vat'] = array( |
|
54 | + 'name' => 'vat', |
|
55 | + 'initial_tax' => $this->initial_tax, |
|
56 | + 'recurring_tax' => $this->recurring_tax, |
|
57 | + ); |
|
58 | + |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Maybe process tax. |
|
63 | + * |
|
64 | + * @since 1.0.19 |
|
65 | + * @param GetPaid_Form_Item $item |
|
66 | + * @param GetPaid_Payment_Form_Submission $submission |
|
67 | + */ |
|
68 | + public function process_item_tax( $item, $submission ) { |
|
69 | + |
|
70 | + $rate = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() ); |
|
71 | + $price = $item->get_sub_total(); |
|
72 | + $item_tax = $price * $rate * 0.01; |
|
73 | + |
|
74 | + if ( wpinv_prices_include_tax() ) { |
|
75 | + $item_tax = $price - ( $price - $price * $rate * 0.01 ); |
|
76 | + } |
|
77 | + |
|
78 | + $this->initial_tax += $item_tax; |
|
79 | + |
|
80 | + if ( $item->is_recurring() ) { |
|
81 | + $this->recurring_tax += $item_tax; |
|
82 | + } |
|
83 | + |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Checks if the submission has a digital item. |
|
88 | + * |
|
89 | + * @param GetPaid_Payment_Form_Submission $submission |
|
90 | + * @since 1.0.19 |
|
91 | + * @return bool |
|
92 | + */ |
|
93 | + public function has_digital_item( $submission ) { |
|
94 | + |
|
95 | + foreach ( $submission->get_items() as $item ) { |
|
96 | + |
|
97 | + if ( 'digital' == $item->get_vat_rule() ) { |
|
98 | + return true; |
|
99 | + } |
|
100 | + |
|
101 | + } |
|
102 | + |
|
103 | + return false; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Checks if this is an eu store. |
|
108 | + * |
|
109 | + * @since 1.0.19 |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public function is_eu_store() { |
|
113 | + return $this->is_eu_country( wpinv_get_default_country() ); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Checks if this is an eu country. |
|
118 | + * |
|
119 | + * @param string $country |
|
120 | + * @since 1.0.19 |
|
121 | + * @return bool |
|
122 | + */ |
|
123 | + public function is_eu_country( $country ) { |
|
124 | + return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Checks if this is an eu purchase. |
|
129 | + * |
|
130 | + * @param string $customer_country |
|
131 | + * @since 1.0.19 |
|
132 | + * @return bool |
|
133 | + */ |
|
134 | + public function is_eu_transaction( $customer_country ) { |
|
135 | + return $this->is_eu_country( $customer_country ) && $this->is_eu_store(); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Retrieves the vat number. |
|
140 | + * |
|
141 | + * @param GetPaid_Payment_Form_Submission $submission |
|
142 | + * @since 1.0.19 |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public function get_vat_number( $submission ) { |
|
146 | + |
|
147 | + // Retrieve from the posted number. |
|
148 | + $vat_number = $submission->get_field( 'wpinv_vat_number' ); |
|
149 | + if ( ! empty( $vat_number ) ) { |
|
150 | + return wpinv_clean( $vat_number ); |
|
151 | + } |
|
152 | + |
|
153 | + // Retrieve from the invoice. |
|
154 | + return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Retrieves the company. |
|
159 | + * |
|
160 | + * @param GetPaid_Payment_Form_Submission $submission |
|
161 | + * @since 1.0.19 |
|
162 | + * @return string |
|
163 | + */ |
|
164 | + public function get_company( $submission ) { |
|
165 | + |
|
166 | + // Retrieve from the posted data. |
|
167 | + $company = $submission->get_field( 'wpinv_company' ); |
|
168 | + if ( ! empty( $company ) ) { |
|
169 | + return wpinv_clean( $company ); |
|
170 | + } |
|
171 | + |
|
172 | + // Retrieve from the invoice. |
|
173 | + return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Checks if we requires a VAT number. |
|
178 | + * |
|
179 | + * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
180 | + * @param bool $country_in_eu Whether the customer country is from the EU |
|
181 | + * @since 1.0.19 |
|
182 | + * @return string |
|
183 | + */ |
|
184 | + public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
185 | + |
|
186 | + $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
187 | + $prevent_b2c = ! empty( $prevent_b2c ); |
|
188 | + $is_eu = $ip_in_eu || $country_in_eu; |
|
189 | + |
|
190 | + return $prevent_b2c && $is_eu; |
|
191 | + } |
|
32 | 192 | |
33 | 193 | /** |
34 | - * Class constructor |
|
35 | - * |
|
36 | - * @param GetPaid_Payment_Form_Submission $submission |
|
37 | - */ |
|
38 | - public function __construct( $submission ) { |
|
39 | - |
|
40 | - // Validate VAT number. |
|
41 | - $this->validate_vat( $submission ); |
|
42 | - |
|
43 | - foreach ( $submission->get_items() as $item ) { |
|
44 | - $this->process_item_tax( $item, $submission ); |
|
45 | - } |
|
46 | - |
|
47 | - // Process any existing invoice taxes. |
|
48 | - if ( $submission->has_invoice() ) { |
|
49 | - $this->taxes = $submission->get_invoice()->get_taxes(); |
|
50 | - } |
|
51 | - |
|
52 | - // Add VAT. |
|
53 | - $this->taxes['vat'] = array( |
|
54 | - 'name' => 'vat', |
|
55 | - 'initial_tax' => $this->initial_tax, |
|
56 | - 'recurring_tax' => $this->recurring_tax, |
|
57 | - ); |
|
58 | - |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Maybe process tax. |
|
63 | - * |
|
64 | - * @since 1.0.19 |
|
65 | - * @param GetPaid_Form_Item $item |
|
66 | - * @param GetPaid_Payment_Form_Submission $submission |
|
67 | - */ |
|
68 | - public function process_item_tax( $item, $submission ) { |
|
69 | - |
|
70 | - $rate = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() ); |
|
71 | - $price = $item->get_sub_total(); |
|
72 | - $item_tax = $price * $rate * 0.01; |
|
73 | - |
|
74 | - if ( wpinv_prices_include_tax() ) { |
|
75 | - $item_tax = $price - ( $price - $price * $rate * 0.01 ); |
|
76 | - } |
|
77 | - |
|
78 | - $this->initial_tax += $item_tax; |
|
79 | - |
|
80 | - if ( $item->is_recurring() ) { |
|
81 | - $this->recurring_tax += $item_tax; |
|
82 | - } |
|
83 | - |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Checks if the submission has a digital item. |
|
88 | - * |
|
89 | - * @param GetPaid_Payment_Form_Submission $submission |
|
90 | - * @since 1.0.19 |
|
91 | - * @return bool |
|
92 | - */ |
|
93 | - public function has_digital_item( $submission ) { |
|
94 | - |
|
95 | - foreach ( $submission->get_items() as $item ) { |
|
96 | - |
|
97 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
98 | - return true; |
|
99 | - } |
|
100 | - |
|
101 | - } |
|
102 | - |
|
103 | - return false; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Checks if this is an eu store. |
|
108 | - * |
|
109 | - * @since 1.0.19 |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public function is_eu_store() { |
|
113 | - return $this->is_eu_country( wpinv_get_default_country() ); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Checks if this is an eu country. |
|
118 | - * |
|
119 | - * @param string $country |
|
120 | - * @since 1.0.19 |
|
121 | - * @return bool |
|
122 | - */ |
|
123 | - public function is_eu_country( $country ) { |
|
124 | - return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Checks if this is an eu purchase. |
|
129 | - * |
|
130 | - * @param string $customer_country |
|
131 | - * @since 1.0.19 |
|
132 | - * @return bool |
|
133 | - */ |
|
134 | - public function is_eu_transaction( $customer_country ) { |
|
135 | - return $this->is_eu_country( $customer_country ) && $this->is_eu_store(); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Retrieves the vat number. |
|
140 | - * |
|
141 | - * @param GetPaid_Payment_Form_Submission $submission |
|
142 | - * @since 1.0.19 |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public function get_vat_number( $submission ) { |
|
146 | - |
|
147 | - // Retrieve from the posted number. |
|
148 | - $vat_number = $submission->get_field( 'wpinv_vat_number' ); |
|
149 | - if ( ! empty( $vat_number ) ) { |
|
150 | - return wpinv_clean( $vat_number ); |
|
151 | - } |
|
152 | - |
|
153 | - // Retrieve from the invoice. |
|
154 | - return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Retrieves the company. |
|
159 | - * |
|
160 | - * @param GetPaid_Payment_Form_Submission $submission |
|
161 | - * @since 1.0.19 |
|
162 | - * @return string |
|
163 | - */ |
|
164 | - public function get_company( $submission ) { |
|
165 | - |
|
166 | - // Retrieve from the posted data. |
|
167 | - $company = $submission->get_field( 'wpinv_company' ); |
|
168 | - if ( ! empty( $company ) ) { |
|
169 | - return wpinv_clean( $company ); |
|
170 | - } |
|
171 | - |
|
172 | - // Retrieve from the invoice. |
|
173 | - return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Checks if we requires a VAT number. |
|
178 | - * |
|
179 | - * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
180 | - * @param bool $country_in_eu Whether the customer country is from the EU |
|
181 | - * @since 1.0.19 |
|
182 | - * @return string |
|
183 | - */ |
|
184 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
185 | - |
|
186 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
187 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
188 | - $is_eu = $ip_in_eu || $country_in_eu; |
|
189 | - |
|
190 | - return $prevent_b2c && $is_eu; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Validate VAT data. |
|
195 | - * |
|
196 | - * @param GetPaid_Payment_Form_Submission $submission |
|
197 | - * @since 1.0.19 |
|
198 | - */ |
|
199 | - public function validate_vat( $submission ) { |
|
200 | - |
|
201 | - $has_digital = $this->has_digital_item( $submission ); |
|
202 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
203 | - |
|
204 | - // Abort if we are not validating vat numbers. |
|
205 | - if ( ! $has_digital && ! $in_eu ) { |
|
194 | + * Validate VAT data. |
|
195 | + * |
|
196 | + * @param GetPaid_Payment_Form_Submission $submission |
|
197 | + * @since 1.0.19 |
|
198 | + */ |
|
199 | + public function validate_vat( $submission ) { |
|
200 | + |
|
201 | + $has_digital = $this->has_digital_item( $submission ); |
|
202 | + $in_eu = $this->is_eu_transaction( $submission->country ); |
|
203 | + |
|
204 | + // Abort if we are not validating vat numbers. |
|
205 | + if ( ! $has_digital && ! $in_eu ) { |
|
206 | 206 | return; |
207 | - } |
|
207 | + } |
|
208 | 208 | |
209 | - // Prepare variables. |
|
210 | - $vat_number = $this->get_vat_number( $submission ); |
|
211 | - $company = $this->get_company( $submission ); |
|
212 | - $ip_country = WPInv_EUVat::get_country_by_ip(); |
|
209 | + // Prepare variables. |
|
210 | + $vat_number = $this->get_vat_number( $submission ); |
|
211 | + $company = $this->get_company( $submission ); |
|
212 | + $ip_country = WPInv_EUVat::get_country_by_ip(); |
|
213 | 213 | $is_eu = $this->is_eu_country( $submission->country ); |
214 | 214 | $is_ip_eu = $this->is_eu_country( $ip_country ); |
215 | 215 | |
216 | - // If we're preventing business to consumer purchases, ensure |
|
217 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
216 | + // If we're preventing business to consumer purchases, ensure |
|
217 | + if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
218 | 218 | |
219 | - // Ensure that a vat number has been specified. |
|
220 | - throw new Exception( |
|
221 | - wp_sprintf( |
|
222 | - __( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ), |
|
223 | - getpaid_vat_name() |
|
224 | - ) |
|
225 | - ); |
|
219 | + // Ensure that a vat number has been specified. |
|
220 | + throw new Exception( |
|
221 | + wp_sprintf( |
|
222 | + __( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ), |
|
223 | + getpaid_vat_name() |
|
224 | + ) |
|
225 | + ); |
|
226 | 226 | |
227 | - } |
|
227 | + } |
|
228 | 228 | |
229 | - // Abort if we are not validating vat (vat number should exist, user should be in eu and business too). |
|
230 | - if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) { |
|
229 | + // Abort if we are not validating vat (vat number should exist, user should be in eu and business too). |
|
230 | + if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) { |
|
231 | 231 | return; |
232 | - } |
|
232 | + } |
|
233 | 233 | |
234 | - $is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country ); |
|
234 | + $is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country ); |
|
235 | 235 | |
236 | - if ( is_string( $is_valid ) ) { |
|
237 | - throw new Exception( $is_valid ); |
|
238 | - } |
|
236 | + if ( is_string( $is_valid ) ) { |
|
237 | + throw new Exception( $is_valid ); |
|
238 | + } |
|
239 | 239 | |
240 | - } |
|
240 | + } |
|
241 | 241 | |
242 | 242 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment form submission taxes class |
@@ -35,17 +35,17 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @param GetPaid_Payment_Form_Submission $submission |
37 | 37 | */ |
38 | - public function __construct( $submission ) { |
|
38 | + public function __construct($submission) { |
|
39 | 39 | |
40 | 40 | // Validate VAT number. |
41 | - $this->validate_vat( $submission ); |
|
41 | + $this->validate_vat($submission); |
|
42 | 42 | |
43 | - foreach ( $submission->get_items() as $item ) { |
|
44 | - $this->process_item_tax( $item, $submission ); |
|
43 | + foreach ($submission->get_items() as $item) { |
|
44 | + $this->process_item_tax($item, $submission); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | // Process any existing invoice taxes. |
48 | - if ( $submission->has_invoice() ) { |
|
48 | + if ($submission->has_invoice()) { |
|
49 | 49 | $this->taxes = $submission->get_invoice()->get_taxes(); |
50 | 50 | } |
51 | 51 | |
@@ -65,19 +65,19 @@ discard block |
||
65 | 65 | * @param GetPaid_Form_Item $item |
66 | 66 | * @param GetPaid_Payment_Form_Submission $submission |
67 | 67 | */ |
68 | - public function process_item_tax( $item, $submission ) { |
|
68 | + public function process_item_tax($item, $submission) { |
|
69 | 69 | |
70 | - $rate = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() ); |
|
70 | + $rate = wpinv_get_tax_rate($submission->country, $submission->state, $item->get_id()); |
|
71 | 71 | $price = $item->get_sub_total(); |
72 | 72 | $item_tax = $price * $rate * 0.01; |
73 | 73 | |
74 | - if ( wpinv_prices_include_tax() ) { |
|
75 | - $item_tax = $price - ( $price - $price * $rate * 0.01 ); |
|
74 | + if (wpinv_prices_include_tax()) { |
|
75 | + $item_tax = $price - ($price - $price * $rate * 0.01); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | $this->initial_tax += $item_tax; |
79 | 79 | |
80 | - if ( $item->is_recurring() ) { |
|
80 | + if ($item->is_recurring()) { |
|
81 | 81 | $this->recurring_tax += $item_tax; |
82 | 82 | } |
83 | 83 | |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | * @since 1.0.19 |
91 | 91 | * @return bool |
92 | 92 | */ |
93 | - public function has_digital_item( $submission ) { |
|
93 | + public function has_digital_item($submission) { |
|
94 | 94 | |
95 | - foreach ( $submission->get_items() as $item ) { |
|
95 | + foreach ($submission->get_items() as $item) { |
|
96 | 96 | |
97 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
97 | + if ('digital' == $item->get_vat_rule()) { |
|
98 | 98 | return true; |
99 | 99 | } |
100 | 100 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @return bool |
111 | 111 | */ |
112 | 112 | public function is_eu_store() { |
113 | - return $this->is_eu_country( wpinv_get_default_country() ); |
|
113 | + return $this->is_eu_country(wpinv_get_default_country()); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @since 1.0.19 |
121 | 121 | * @return bool |
122 | 122 | */ |
123 | - public function is_eu_country( $country ) { |
|
124 | - return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
123 | + public function is_eu_country($country) { |
|
124 | + return getpaid_is_eu_state($country) || getpaid_is_gst_country($country); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | * @since 1.0.19 |
132 | 132 | * @return bool |
133 | 133 | */ |
134 | - public function is_eu_transaction( $customer_country ) { |
|
135 | - return $this->is_eu_country( $customer_country ) && $this->is_eu_store(); |
|
134 | + public function is_eu_transaction($customer_country) { |
|
135 | + return $this->is_eu_country($customer_country) && $this->is_eu_store(); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -142,12 +142,12 @@ discard block |
||
142 | 142 | * @since 1.0.19 |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public function get_vat_number( $submission ) { |
|
145 | + public function get_vat_number($submission) { |
|
146 | 146 | |
147 | 147 | // Retrieve from the posted number. |
148 | - $vat_number = $submission->get_field( 'wpinv_vat_number' ); |
|
149 | - if ( ! empty( $vat_number ) ) { |
|
150 | - return wpinv_clean( $vat_number ); |
|
148 | + $vat_number = $submission->get_field('wpinv_vat_number'); |
|
149 | + if (!empty($vat_number)) { |
|
150 | + return wpinv_clean($vat_number); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // Retrieve from the invoice. |
@@ -161,12 +161,12 @@ discard block |
||
161 | 161 | * @since 1.0.19 |
162 | 162 | * @return string |
163 | 163 | */ |
164 | - public function get_company( $submission ) { |
|
164 | + public function get_company($submission) { |
|
165 | 165 | |
166 | 166 | // Retrieve from the posted data. |
167 | - $company = $submission->get_field( 'wpinv_company' ); |
|
168 | - if ( ! empty( $company ) ) { |
|
169 | - return wpinv_clean( $company ); |
|
167 | + $company = $submission->get_field('wpinv_company'); |
|
168 | + if (!empty($company)) { |
|
169 | + return wpinv_clean($company); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | // Retrieve from the invoice. |
@@ -181,10 +181,10 @@ discard block |
||
181 | 181 | * @since 1.0.19 |
182 | 182 | * @return string |
183 | 183 | */ |
184 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
184 | + public function requires_vat($ip_in_eu, $country_in_eu) { |
|
185 | 185 | |
186 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
187 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
186 | + $prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase'); |
|
187 | + $prevent_b2c = !empty($prevent_b2c); |
|
188 | 188 | $is_eu = $ip_in_eu || $country_in_eu; |
189 | 189 | |
190 | 190 | return $prevent_b2c && $is_eu; |
@@ -196,30 +196,30 @@ discard block |
||
196 | 196 | * @param GetPaid_Payment_Form_Submission $submission |
197 | 197 | * @since 1.0.19 |
198 | 198 | */ |
199 | - public function validate_vat( $submission ) { |
|
199 | + public function validate_vat($submission) { |
|
200 | 200 | |
201 | - $has_digital = $this->has_digital_item( $submission ); |
|
202 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
201 | + $has_digital = $this->has_digital_item($submission); |
|
202 | + $in_eu = $this->is_eu_transaction($submission->country); |
|
203 | 203 | |
204 | 204 | // Abort if we are not validating vat numbers. |
205 | - if ( ! $has_digital && ! $in_eu ) { |
|
205 | + if (!$has_digital && !$in_eu) { |
|
206 | 206 | return; |
207 | 207 | } |
208 | 208 | |
209 | 209 | // Prepare variables. |
210 | - $vat_number = $this->get_vat_number( $submission ); |
|
211 | - $company = $this->get_company( $submission ); |
|
210 | + $vat_number = $this->get_vat_number($submission); |
|
211 | + $company = $this->get_company($submission); |
|
212 | 212 | $ip_country = WPInv_EUVat::get_country_by_ip(); |
213 | - $is_eu = $this->is_eu_country( $submission->country ); |
|
214 | - $is_ip_eu = $this->is_eu_country( $ip_country ); |
|
213 | + $is_eu = $this->is_eu_country($submission->country); |
|
214 | + $is_ip_eu = $this->is_eu_country($ip_country); |
|
215 | 215 | |
216 | 216 | // If we're preventing business to consumer purchases, ensure |
217 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
217 | + if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) { |
|
218 | 218 | |
219 | 219 | // Ensure that a vat number has been specified. |
220 | 220 | throw new Exception( |
221 | 221 | wp_sprintf( |
222 | - __( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ), |
|
222 | + __('Please enter your %s number to verify your purchase is by an EU business.', 'invoicing'), |
|
223 | 223 | getpaid_vat_name() |
224 | 224 | ) |
225 | 225 | ); |
@@ -227,14 +227,14 @@ discard block |
||
227 | 227 | } |
228 | 228 | |
229 | 229 | // Abort if we are not validating vat (vat number should exist, user should be in eu and business too). |
230 | - if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) { |
|
230 | + if (!$is_eu || !$in_eu || empty($vat_number)) { |
|
231 | 231 | return; |
232 | 232 | } |
233 | 233 | |
234 | - $is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country ); |
|
234 | + $is_valid = WPInv_EUVat::validate_vat_number($vat_number, $company, $submission->country); |
|
235 | 235 | |
236 | - if ( is_string( $is_valid ) ) { |
|
237 | - throw new Exception( $is_valid ); |
|
236 | + if (is_string($is_valid)) { |
|
237 | + throw new Exception($is_valid); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,187 +10,187 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form_Submission { |
11 | 11 | |
12 | 12 | /** |
13 | - * Submission ID |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - public $id = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * The raw submission data. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $data = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * Submission totals |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $totals = array( |
|
32 | - |
|
33 | - 'subtotal' => array( |
|
34 | - 'initial' => 0, |
|
35 | - 'recurring' => 0, |
|
36 | - ), |
|
37 | - |
|
38 | - 'discount' => array( |
|
39 | - 'initial' => 0, |
|
40 | - 'recurring' => 0, |
|
41 | - ), |
|
42 | - |
|
43 | - 'fees' => array( |
|
44 | - 'initial' => 0, |
|
45 | - 'recurring' => 0, |
|
46 | - ), |
|
47 | - |
|
48 | - 'taxes' => array( |
|
49 | - 'initial' => 0, |
|
50 | - 'recurring' => 0, |
|
51 | - ), |
|
52 | - |
|
53 | - ); |
|
54 | - |
|
55 | - /** |
|
56 | - * Sets the associated payment form. |
|
57 | - * |
|
58 | - * @var GetPaid_Payment_Form |
|
59 | - */ |
|
13 | + * Submission ID |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + public $id = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * The raw submission data. |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $data = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * Submission totals |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $totals = array( |
|
32 | + |
|
33 | + 'subtotal' => array( |
|
34 | + 'initial' => 0, |
|
35 | + 'recurring' => 0, |
|
36 | + ), |
|
37 | + |
|
38 | + 'discount' => array( |
|
39 | + 'initial' => 0, |
|
40 | + 'recurring' => 0, |
|
41 | + ), |
|
42 | + |
|
43 | + 'fees' => array( |
|
44 | + 'initial' => 0, |
|
45 | + 'recurring' => 0, |
|
46 | + ), |
|
47 | + |
|
48 | + 'taxes' => array( |
|
49 | + 'initial' => 0, |
|
50 | + 'recurring' => 0, |
|
51 | + ), |
|
52 | + |
|
53 | + ); |
|
54 | + |
|
55 | + /** |
|
56 | + * Sets the associated payment form. |
|
57 | + * |
|
58 | + * @var GetPaid_Payment_Form |
|
59 | + */ |
|
60 | 60 | protected $payment_form = null; |
61 | 61 | |
62 | 62 | /** |
63 | - * The country for the submission. |
|
64 | - * |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - public $country = null; |
|
68 | - |
|
69 | - /** |
|
70 | - * The state for the submission. |
|
71 | - * |
|
72 | - * @since 1.0.19 |
|
73 | - * @var string |
|
74 | - */ |
|
75 | - public $state = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * The invoice associated with the submission. |
|
79 | - * |
|
80 | - * @var WPInv_Invoice |
|
81 | - */ |
|
82 | - protected $invoice = null; |
|
83 | - |
|
84 | - /** |
|
85 | - * The recurring item for the submission. |
|
86 | - * |
|
87 | - * @var int |
|
88 | - */ |
|
89 | - public $has_recurring = 0; |
|
90 | - |
|
91 | - /** |
|
92 | - * An array of fees for the submission. |
|
93 | - * |
|
94 | - * @var array |
|
95 | - */ |
|
96 | - protected $fees = array(); |
|
97 | - |
|
98 | - /** |
|
99 | - * An array of discounts for the submission. |
|
100 | - * |
|
101 | - * @var array |
|
102 | - */ |
|
103 | - protected $discounts = array(); |
|
104 | - |
|
105 | - /** |
|
106 | - * An array of taxes for the submission. |
|
107 | - * |
|
108 | - * @var array |
|
109 | - */ |
|
110 | - protected $taxes = array(); |
|
111 | - |
|
112 | - /** |
|
113 | - * An array of items for the submission. |
|
114 | - * |
|
115 | - * @var GetPaid_Form_Item[] |
|
116 | - */ |
|
117 | - protected $items = array(); |
|
118 | - |
|
119 | - /** |
|
120 | - * The last error. |
|
121 | - * |
|
122 | - * @var string |
|
123 | - */ |
|
124 | - public $last_error = null; |
|
125 | - |
|
126 | - /** |
|
127 | - * Class constructor. |
|
128 | - * |
|
129 | - */ |
|
130 | - public function __construct() { |
|
131 | - |
|
132 | - // Set the state and country to the default state and country. |
|
133 | - $this->country = wpinv_default_billing_country(); |
|
134 | - $this->state = wpinv_get_default_state(); |
|
135 | - |
|
136 | - // Do we have an actual submission? |
|
137 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
138 | - $this->load_data( $_POST ); |
|
139 | - } |
|
140 | - |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Loads submission data. |
|
145 | - * |
|
146 | - * @param array $data |
|
147 | - */ |
|
148 | - public function load_data( $data ) { |
|
149 | - |
|
150 | - // Remove slashes from the submitted data... |
|
151 | - $data = wp_unslash( $data ); |
|
152 | - |
|
153 | - // Allow plugins to filter the data. |
|
154 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
155 | - |
|
156 | - // Cache it... |
|
157 | - $this->data = $data; |
|
158 | - |
|
159 | - // Then generate a unique id from the data. |
|
160 | - $this->id = md5( wp_json_encode( $data ) ); |
|
161 | - |
|
162 | - // Finally, process the submission. |
|
163 | - try { |
|
164 | - |
|
165 | - // Each process is passed an instance of the class (with reference) |
|
166 | - // and should throw an Exception whenever it encounters one. |
|
167 | - $processors = apply_filters( |
|
168 | - 'getpaid_payment_form_submission_processors', |
|
169 | - array( |
|
170 | - array( $this, 'process_payment_form' ), |
|
171 | - array( $this, 'process_invoice' ), |
|
172 | - array( $this, 'process_fees' ), |
|
173 | - array( $this, 'process_items' ), |
|
174 | - array( $this, 'process_taxes' ), |
|
175 | - array( $this, 'process_discount' ), |
|
176 | - ), |
|
177 | - $this |
|
178 | - ); |
|
179 | - |
|
180 | - foreach ( $processors as $processor ) { |
|
181 | - call_user_func_array( $processor, array( &$this ) ); |
|
182 | - } |
|
183 | - |
|
184 | - } catch ( Exception $e ) { |
|
185 | - $this->last_error = $e->getMessage(); |
|
186 | - } |
|
187 | - |
|
188 | - // Fired when we are done processing a submission. |
|
189 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
190 | - |
|
191 | - } |
|
192 | - |
|
193 | - /* |
|
63 | + * The country for the submission. |
|
64 | + * |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + public $country = null; |
|
68 | + |
|
69 | + /** |
|
70 | + * The state for the submission. |
|
71 | + * |
|
72 | + * @since 1.0.19 |
|
73 | + * @var string |
|
74 | + */ |
|
75 | + public $state = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * The invoice associated with the submission. |
|
79 | + * |
|
80 | + * @var WPInv_Invoice |
|
81 | + */ |
|
82 | + protected $invoice = null; |
|
83 | + |
|
84 | + /** |
|
85 | + * The recurring item for the submission. |
|
86 | + * |
|
87 | + * @var int |
|
88 | + */ |
|
89 | + public $has_recurring = 0; |
|
90 | + |
|
91 | + /** |
|
92 | + * An array of fees for the submission. |
|
93 | + * |
|
94 | + * @var array |
|
95 | + */ |
|
96 | + protected $fees = array(); |
|
97 | + |
|
98 | + /** |
|
99 | + * An array of discounts for the submission. |
|
100 | + * |
|
101 | + * @var array |
|
102 | + */ |
|
103 | + protected $discounts = array(); |
|
104 | + |
|
105 | + /** |
|
106 | + * An array of taxes for the submission. |
|
107 | + * |
|
108 | + * @var array |
|
109 | + */ |
|
110 | + protected $taxes = array(); |
|
111 | + |
|
112 | + /** |
|
113 | + * An array of items for the submission. |
|
114 | + * |
|
115 | + * @var GetPaid_Form_Item[] |
|
116 | + */ |
|
117 | + protected $items = array(); |
|
118 | + |
|
119 | + /** |
|
120 | + * The last error. |
|
121 | + * |
|
122 | + * @var string |
|
123 | + */ |
|
124 | + public $last_error = null; |
|
125 | + |
|
126 | + /** |
|
127 | + * Class constructor. |
|
128 | + * |
|
129 | + */ |
|
130 | + public function __construct() { |
|
131 | + |
|
132 | + // Set the state and country to the default state and country. |
|
133 | + $this->country = wpinv_default_billing_country(); |
|
134 | + $this->state = wpinv_get_default_state(); |
|
135 | + |
|
136 | + // Do we have an actual submission? |
|
137 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
138 | + $this->load_data( $_POST ); |
|
139 | + } |
|
140 | + |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Loads submission data. |
|
145 | + * |
|
146 | + * @param array $data |
|
147 | + */ |
|
148 | + public function load_data( $data ) { |
|
149 | + |
|
150 | + // Remove slashes from the submitted data... |
|
151 | + $data = wp_unslash( $data ); |
|
152 | + |
|
153 | + // Allow plugins to filter the data. |
|
154 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
155 | + |
|
156 | + // Cache it... |
|
157 | + $this->data = $data; |
|
158 | + |
|
159 | + // Then generate a unique id from the data. |
|
160 | + $this->id = md5( wp_json_encode( $data ) ); |
|
161 | + |
|
162 | + // Finally, process the submission. |
|
163 | + try { |
|
164 | + |
|
165 | + // Each process is passed an instance of the class (with reference) |
|
166 | + // and should throw an Exception whenever it encounters one. |
|
167 | + $processors = apply_filters( |
|
168 | + 'getpaid_payment_form_submission_processors', |
|
169 | + array( |
|
170 | + array( $this, 'process_payment_form' ), |
|
171 | + array( $this, 'process_invoice' ), |
|
172 | + array( $this, 'process_fees' ), |
|
173 | + array( $this, 'process_items' ), |
|
174 | + array( $this, 'process_taxes' ), |
|
175 | + array( $this, 'process_discount' ), |
|
176 | + ), |
|
177 | + $this |
|
178 | + ); |
|
179 | + |
|
180 | + foreach ( $processors as $processor ) { |
|
181 | + call_user_func_array( $processor, array( &$this ) ); |
|
182 | + } |
|
183 | + |
|
184 | + } catch ( Exception $e ) { |
|
185 | + $this->last_error = $e->getMessage(); |
|
186 | + } |
|
187 | + |
|
188 | + // Fired when we are done processing a submission. |
|
189 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
190 | + |
|
191 | + } |
|
192 | + |
|
193 | + /* |
|
194 | 194 | |-------------------------------------------------------------------------- |
195 | 195 | | Payment Forms. |
196 | 196 | |-------------------------------------------------------------------------- |
@@ -199,39 +199,39 @@ discard block |
||
199 | 199 | | submission has an active payment form etc. |
200 | 200 | */ |
201 | 201 | |
202 | - /** |
|
203 | - * Prepares the submission's payment form. |
|
204 | - * |
|
205 | - * @since 1.0.19 |
|
206 | - */ |
|
207 | - public function process_payment_form() { |
|
202 | + /** |
|
203 | + * Prepares the submission's payment form. |
|
204 | + * |
|
205 | + * @since 1.0.19 |
|
206 | + */ |
|
207 | + public function process_payment_form() { |
|
208 | 208 | |
209 | - // Every submission needs an active payment form. |
|
210 | - if ( empty( $this->data['form_id'] ) ) { |
|
211 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
212 | - } |
|
209 | + // Every submission needs an active payment form. |
|
210 | + if ( empty( $this->data['form_id'] ) ) { |
|
211 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
212 | + } |
|
213 | 213 | |
214 | - // Fetch the payment form. |
|
215 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
214 | + // Fetch the payment form. |
|
215 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
216 | 216 | |
217 | - if ( ! $this->payment_form->is_active() ) { |
|
218 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
219 | - } |
|
217 | + if ( ! $this->payment_form->is_active() ) { |
|
218 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
219 | + } |
|
220 | 220 | |
221 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
222 | - } |
|
221 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
222 | + } |
|
223 | 223 | |
224 | 224 | /** |
225 | - * Returns the payment form. |
|
226 | - * |
|
227 | - * @since 1.0.19 |
|
228 | - * @return GetPaid_Payment_Form |
|
229 | - */ |
|
230 | - public function get_payment_form() { |
|
231 | - return $this->payment_form; |
|
232 | - } |
|
225 | + * Returns the payment form. |
|
226 | + * |
|
227 | + * @since 1.0.19 |
|
228 | + * @return GetPaid_Payment_Form |
|
229 | + */ |
|
230 | + public function get_payment_form() { |
|
231 | + return $this->payment_form; |
|
232 | + } |
|
233 | 233 | |
234 | - /* |
|
234 | + /* |
|
235 | 235 | |-------------------------------------------------------------------------- |
236 | 236 | | Invoices. |
237 | 237 | |-------------------------------------------------------------------------- |
@@ -240,61 +240,61 @@ discard block |
||
240 | 240 | | might be for an existing invoice. |
241 | 241 | */ |
242 | 242 | |
243 | - /** |
|
244 | - * Prepares the submission's invoice. |
|
245 | - * |
|
246 | - * @since 1.0.19 |
|
247 | - */ |
|
248 | - public function process_invoice() { |
|
243 | + /** |
|
244 | + * Prepares the submission's invoice. |
|
245 | + * |
|
246 | + * @since 1.0.19 |
|
247 | + */ |
|
248 | + public function process_invoice() { |
|
249 | 249 | |
250 | - // Abort if there is no invoice. |
|
251 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
252 | - return; |
|
253 | - } |
|
250 | + // Abort if there is no invoice. |
|
251 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
252 | + return; |
|
253 | + } |
|
254 | 254 | |
255 | - // If the submission is for an existing invoice, ensure that it exists |
|
256 | - // and that it is not paid for. |
|
257 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
255 | + // If the submission is for an existing invoice, ensure that it exists |
|
256 | + // and that it is not paid for. |
|
257 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
258 | 258 | |
259 | 259 | if ( empty( $invoice ) ) { |
260 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
261 | - } |
|
262 | - |
|
263 | - if ( $invoice->is_paid() ) { |
|
264 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
265 | - } |
|
266 | - |
|
267 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
268 | - $this->payment_form->invoice = $invoice; |
|
269 | - |
|
270 | - $this->country = $invoice->get_country(); |
|
271 | - $this->state = $invoice->get_state(); |
|
272 | - $this->invoice = $invoice; |
|
273 | - |
|
274 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Returns the associated invoice. |
|
279 | - * |
|
280 | - * @since 1.0.19 |
|
281 | - * @return WPInv_Invoice |
|
282 | - */ |
|
283 | - public function get_invoice() { |
|
284 | - return $this->invoice; |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * Checks whether there is an invoice associated with this submission. |
|
289 | - * |
|
290 | - * @since 1.0.19 |
|
291 | - * @return bool |
|
292 | - */ |
|
293 | - public function has_invoice() { |
|
294 | - return ! empty( $this->invoice ); |
|
295 | - } |
|
296 | - |
|
297 | - /* |
|
260 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
261 | + } |
|
262 | + |
|
263 | + if ( $invoice->is_paid() ) { |
|
264 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
265 | + } |
|
266 | + |
|
267 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
268 | + $this->payment_form->invoice = $invoice; |
|
269 | + |
|
270 | + $this->country = $invoice->get_country(); |
|
271 | + $this->state = $invoice->get_state(); |
|
272 | + $this->invoice = $invoice; |
|
273 | + |
|
274 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Returns the associated invoice. |
|
279 | + * |
|
280 | + * @since 1.0.19 |
|
281 | + * @return WPInv_Invoice |
|
282 | + */ |
|
283 | + public function get_invoice() { |
|
284 | + return $this->invoice; |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * Checks whether there is an invoice associated with this submission. |
|
289 | + * |
|
290 | + * @since 1.0.19 |
|
291 | + * @return bool |
|
292 | + */ |
|
293 | + public function has_invoice() { |
|
294 | + return ! empty( $this->invoice ); |
|
295 | + } |
|
296 | + |
|
297 | + /* |
|
298 | 298 | |-------------------------------------------------------------------------- |
299 | 299 | | Items. |
300 | 300 | |-------------------------------------------------------------------------- |
@@ -303,105 +303,105 @@ discard block |
||
303 | 303 | | recurring item. But can have an unlimited number of non-recurring items. |
304 | 304 | */ |
305 | 305 | |
306 | - /** |
|
307 | - * Prepares the submission's items. |
|
308 | - * |
|
309 | - * @since 1.0.19 |
|
310 | - */ |
|
311 | - public function process_items() { |
|
312 | - |
|
313 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
314 | - |
|
315 | - foreach ( $processor->items as $item ) { |
|
316 | - $this->add_item( $item ); |
|
317 | - } |
|
318 | - |
|
319 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Adds an item to the submission. |
|
324 | - * |
|
325 | - * @since 1.0.19 |
|
326 | - * @param GetPaid_Form_Item $item |
|
327 | - */ |
|
328 | - public function add_item( $item ) { |
|
329 | - |
|
330 | - // Make sure that it is available for purchase. |
|
331 | - if ( ! $item->can_purchase() ) { |
|
332 | - return; |
|
333 | - } |
|
334 | - |
|
335 | - // Each submission can only contain one recurring item. |
|
336 | - if ( $item->is_recurring() ) { |
|
337 | - |
|
338 | - if ( $this->has_recurring != 0 ) { |
|
339 | - throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
340 | - } |
|
341 | - |
|
342 | - $this->has_recurring = $item->get_id(); |
|
343 | - |
|
344 | - } |
|
345 | - |
|
346 | - // Update the items and totals. |
|
347 | - $this->items[ $item->get_id() ] = $item; |
|
348 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
349 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
350 | - |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * Removes a specific item. |
|
355 | - * |
|
356 | - * You should not call this method after the discounts and taxes |
|
357 | - * have been calculated. |
|
358 | - * |
|
359 | - * @since 1.0.19 |
|
360 | - */ |
|
361 | - public function remove_item( $item_id ) { |
|
362 | - |
|
363 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
364 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
365 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
366 | - |
|
367 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
368 | - $this->has_recurring = 0; |
|
369 | - } |
|
370 | - |
|
371 | - unset( $this->items[ $item_id ] ); |
|
372 | - } |
|
306 | + /** |
|
307 | + * Prepares the submission's items. |
|
308 | + * |
|
309 | + * @since 1.0.19 |
|
310 | + */ |
|
311 | + public function process_items() { |
|
312 | + |
|
313 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
314 | + |
|
315 | + foreach ( $processor->items as $item ) { |
|
316 | + $this->add_item( $item ); |
|
317 | + } |
|
318 | + |
|
319 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Adds an item to the submission. |
|
324 | + * |
|
325 | + * @since 1.0.19 |
|
326 | + * @param GetPaid_Form_Item $item |
|
327 | + */ |
|
328 | + public function add_item( $item ) { |
|
329 | + |
|
330 | + // Make sure that it is available for purchase. |
|
331 | + if ( ! $item->can_purchase() ) { |
|
332 | + return; |
|
333 | + } |
|
334 | + |
|
335 | + // Each submission can only contain one recurring item. |
|
336 | + if ( $item->is_recurring() ) { |
|
337 | + |
|
338 | + if ( $this->has_recurring != 0 ) { |
|
339 | + throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
340 | + } |
|
341 | + |
|
342 | + $this->has_recurring = $item->get_id(); |
|
343 | + |
|
344 | + } |
|
345 | + |
|
346 | + // Update the items and totals. |
|
347 | + $this->items[ $item->get_id() ] = $item; |
|
348 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
349 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
350 | + |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * Removes a specific item. |
|
355 | + * |
|
356 | + * You should not call this method after the discounts and taxes |
|
357 | + * have been calculated. |
|
358 | + * |
|
359 | + * @since 1.0.19 |
|
360 | + */ |
|
361 | + public function remove_item( $item_id ) { |
|
362 | + |
|
363 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
364 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
365 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
366 | + |
|
367 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
368 | + $this->has_recurring = 0; |
|
369 | + } |
|
370 | + |
|
371 | + unset( $this->items[ $item_id ] ); |
|
372 | + } |
|
373 | 373 | |
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * Returns the subtotal. |
|
378 | - * |
|
379 | - * @since 1.0.19 |
|
380 | - */ |
|
381 | - public function get_subtotal() { |
|
382 | - return $this->totals['subtotal']['initial']; |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * Returns the recurring subtotal. |
|
387 | - * |
|
388 | - * @since 1.0.19 |
|
389 | - */ |
|
390 | - public function get_recurring_subtotal() { |
|
391 | - return $this->totals['subtotal']['recurring']; |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * Returns all items. |
|
396 | - * |
|
397 | - * @since 1.0.19 |
|
398 | - * @return GetPaid_Form_Item[] |
|
399 | - */ |
|
400 | - public function get_items() { |
|
401 | - return $this->items; |
|
402 | - } |
|
403 | - |
|
404 | - /* |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * Returns the subtotal. |
|
378 | + * |
|
379 | + * @since 1.0.19 |
|
380 | + */ |
|
381 | + public function get_subtotal() { |
|
382 | + return $this->totals['subtotal']['initial']; |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * Returns the recurring subtotal. |
|
387 | + * |
|
388 | + * @since 1.0.19 |
|
389 | + */ |
|
390 | + public function get_recurring_subtotal() { |
|
391 | + return $this->totals['subtotal']['recurring']; |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * Returns all items. |
|
396 | + * |
|
397 | + * @since 1.0.19 |
|
398 | + * @return GetPaid_Form_Item[] |
|
399 | + */ |
|
400 | + public function get_items() { |
|
401 | + return $this->items; |
|
402 | + } |
|
403 | + |
|
404 | + /* |
|
405 | 405 | |-------------------------------------------------------------------------- |
406 | 406 | | Taxes |
407 | 407 | |-------------------------------------------------------------------------- |
@@ -410,108 +410,108 @@ discard block |
||
410 | 410 | | or only one-time. |
411 | 411 | */ |
412 | 412 | |
413 | - /** |
|
414 | - * Prepares the submission's taxes. |
|
415 | - * |
|
416 | - * @since 1.0.19 |
|
417 | - */ |
|
418 | - public function process_taxes() { |
|
419 | - |
|
420 | - // Abort if we're not using taxes. |
|
421 | - if ( ! $this->use_taxes() ) { |
|
422 | - return; |
|
423 | - } |
|
424 | - |
|
425 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
426 | - if ( ! empty( $this->data['wpinv_country'] ) ) { |
|
427 | - $this->country = $this->data['wpinv_country']; |
|
428 | - } |
|
429 | - |
|
430 | - if ( ! empty( $this->data['wpinv_state'] ) ) { |
|
431 | - $this->country = $this->data['wpinv_state']; |
|
432 | - } |
|
433 | - |
|
434 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
435 | - |
|
436 | - foreach ( $processor->taxes as $tax ) { |
|
437 | - $this->add_tax( $tax ); |
|
438 | - } |
|
439 | - |
|
440 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * Adds a tax to the submission. |
|
445 | - * |
|
446 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
447 | - * @since 1.0.19 |
|
448 | - */ |
|
449 | - public function add_tax( $tax ) { |
|
450 | - $this->taxes[ $tax['name'] ] = $tax; |
|
451 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
452 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Removes a specific tax. |
|
457 | - * |
|
458 | - * @since 1.0.19 |
|
459 | - */ |
|
460 | - public function remove_tax( $tax_name ) { |
|
461 | - |
|
462 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
463 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
464 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
465 | - unset( $this->taxes[ $tax_name ] ); |
|
466 | - } |
|
467 | - |
|
468 | - } |
|
469 | - |
|
470 | - /** |
|
471 | - * Whether or not we'll use taxes for the submission. |
|
472 | - * |
|
473 | - * @since 1.0.19 |
|
474 | - */ |
|
475 | - public function use_taxes() { |
|
476 | - |
|
477 | - $use_taxes = wpinv_use_taxes(); |
|
478 | - |
|
479 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
480 | - $use_taxes = false; |
|
481 | - } |
|
482 | - |
|
483 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
484 | - |
|
485 | - } |
|
486 | - |
|
487 | - /** |
|
488 | - * Returns the tax. |
|
489 | - * |
|
490 | - * @since 1.0.19 |
|
491 | - */ |
|
492 | - public function get_tax() { |
|
493 | - return $this->totals['taxes']['initial']; |
|
494 | - } |
|
495 | - |
|
496 | - /** |
|
497 | - * Returns the recurring tax. |
|
498 | - * |
|
499 | - * @since 1.0.19 |
|
500 | - */ |
|
501 | - public function get_recurring_tax() { |
|
502 | - return $this->totals['taxes']['recurring']; |
|
503 | - } |
|
504 | - |
|
505 | - /** |
|
506 | - * Returns all taxes. |
|
507 | - * |
|
508 | - * @since 1.0.19 |
|
509 | - */ |
|
510 | - public function get_taxes() { |
|
511 | - return $this->taxes; |
|
512 | - } |
|
513 | - |
|
514 | - /* |
|
413 | + /** |
|
414 | + * Prepares the submission's taxes. |
|
415 | + * |
|
416 | + * @since 1.0.19 |
|
417 | + */ |
|
418 | + public function process_taxes() { |
|
419 | + |
|
420 | + // Abort if we're not using taxes. |
|
421 | + if ( ! $this->use_taxes() ) { |
|
422 | + return; |
|
423 | + } |
|
424 | + |
|
425 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
426 | + if ( ! empty( $this->data['wpinv_country'] ) ) { |
|
427 | + $this->country = $this->data['wpinv_country']; |
|
428 | + } |
|
429 | + |
|
430 | + if ( ! empty( $this->data['wpinv_state'] ) ) { |
|
431 | + $this->country = $this->data['wpinv_state']; |
|
432 | + } |
|
433 | + |
|
434 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
435 | + |
|
436 | + foreach ( $processor->taxes as $tax ) { |
|
437 | + $this->add_tax( $tax ); |
|
438 | + } |
|
439 | + |
|
440 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * Adds a tax to the submission. |
|
445 | + * |
|
446 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
447 | + * @since 1.0.19 |
|
448 | + */ |
|
449 | + public function add_tax( $tax ) { |
|
450 | + $this->taxes[ $tax['name'] ] = $tax; |
|
451 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
452 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Removes a specific tax. |
|
457 | + * |
|
458 | + * @since 1.0.19 |
|
459 | + */ |
|
460 | + public function remove_tax( $tax_name ) { |
|
461 | + |
|
462 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
463 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
464 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
465 | + unset( $this->taxes[ $tax_name ] ); |
|
466 | + } |
|
467 | + |
|
468 | + } |
|
469 | + |
|
470 | + /** |
|
471 | + * Whether or not we'll use taxes for the submission. |
|
472 | + * |
|
473 | + * @since 1.0.19 |
|
474 | + */ |
|
475 | + public function use_taxes() { |
|
476 | + |
|
477 | + $use_taxes = wpinv_use_taxes(); |
|
478 | + |
|
479 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
480 | + $use_taxes = false; |
|
481 | + } |
|
482 | + |
|
483 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
484 | + |
|
485 | + } |
|
486 | + |
|
487 | + /** |
|
488 | + * Returns the tax. |
|
489 | + * |
|
490 | + * @since 1.0.19 |
|
491 | + */ |
|
492 | + public function get_tax() { |
|
493 | + return $this->totals['taxes']['initial']; |
|
494 | + } |
|
495 | + |
|
496 | + /** |
|
497 | + * Returns the recurring tax. |
|
498 | + * |
|
499 | + * @since 1.0.19 |
|
500 | + */ |
|
501 | + public function get_recurring_tax() { |
|
502 | + return $this->totals['taxes']['recurring']; |
|
503 | + } |
|
504 | + |
|
505 | + /** |
|
506 | + * Returns all taxes. |
|
507 | + * |
|
508 | + * @since 1.0.19 |
|
509 | + */ |
|
510 | + public function get_taxes() { |
|
511 | + return $this->taxes; |
|
512 | + } |
|
513 | + |
|
514 | + /* |
|
515 | 515 | |-------------------------------------------------------------------------- |
516 | 516 | | Discounts |
517 | 517 | |-------------------------------------------------------------------------- |
@@ -520,99 +520,99 @@ discard block |
||
520 | 520 | | or only one-time. They also do not have to come from a discount code. |
521 | 521 | */ |
522 | 522 | |
523 | - /** |
|
524 | - * Prepares the submission's discount. |
|
525 | - * |
|
526 | - * @since 1.0.19 |
|
527 | - */ |
|
528 | - public function process_discount() { |
|
529 | - |
|
530 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
531 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
532 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
533 | - |
|
534 | - foreach ( $processor->discounts as $discount ) { |
|
535 | - $this->add_discount( $discount ); |
|
536 | - } |
|
537 | - |
|
538 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
539 | - } |
|
540 | - |
|
541 | - /** |
|
542 | - * Adds a discount to the submission. |
|
543 | - * |
|
544 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
545 | - * @since 1.0.19 |
|
546 | - */ |
|
547 | - public function add_discount( $discount ) { |
|
548 | - $this->discounts[ $discount['name'] ] = $discount; |
|
549 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
550 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * Removes a discount from the submission. |
|
555 | - * |
|
556 | - * @since 1.0.19 |
|
557 | - */ |
|
558 | - public function remove_discount( $name ) { |
|
559 | - |
|
560 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
561 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
562 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
563 | - unset( $this->discounts[ $name ] ); |
|
564 | - } |
|
565 | - |
|
566 | - } |
|
567 | - |
|
568 | - /** |
|
569 | - * Checks whether there is a discount code associated with this submission. |
|
570 | - * |
|
571 | - * @since 1.0.19 |
|
572 | - * @return bool |
|
573 | - */ |
|
574 | - public function has_discount_code() { |
|
575 | - return ! empty( $this->discounts['discount_code'] ); |
|
576 | - } |
|
577 | - |
|
578 | - /** |
|
579 | - * Returns the discount code. |
|
580 | - * |
|
581 | - * @since 1.0.19 |
|
582 | - * @return string |
|
583 | - */ |
|
584 | - public function get_discount_code() { |
|
585 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
586 | - } |
|
587 | - |
|
588 | - /** |
|
589 | - * Returns the discount. |
|
590 | - * |
|
591 | - * @since 1.0.19 |
|
592 | - */ |
|
593 | - public function get_discount() { |
|
594 | - return $this->totals['discount']['initial']; |
|
595 | - } |
|
596 | - |
|
597 | - /** |
|
598 | - * Returns the recurring discount. |
|
599 | - * |
|
600 | - * @since 1.0.19 |
|
601 | - */ |
|
602 | - public function get_recurring_discount() { |
|
603 | - return $this->totals['discount']['recurring']; |
|
604 | - } |
|
605 | - |
|
606 | - /** |
|
607 | - * Returns all discounts. |
|
608 | - * |
|
609 | - * @since 1.0.19 |
|
610 | - */ |
|
611 | - public function get_discounts() { |
|
612 | - return $this->discounts; |
|
613 | - } |
|
614 | - |
|
615 | - /* |
|
523 | + /** |
|
524 | + * Prepares the submission's discount. |
|
525 | + * |
|
526 | + * @since 1.0.19 |
|
527 | + */ |
|
528 | + public function process_discount() { |
|
529 | + |
|
530 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
531 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
532 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
533 | + |
|
534 | + foreach ( $processor->discounts as $discount ) { |
|
535 | + $this->add_discount( $discount ); |
|
536 | + } |
|
537 | + |
|
538 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
539 | + } |
|
540 | + |
|
541 | + /** |
|
542 | + * Adds a discount to the submission. |
|
543 | + * |
|
544 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
545 | + * @since 1.0.19 |
|
546 | + */ |
|
547 | + public function add_discount( $discount ) { |
|
548 | + $this->discounts[ $discount['name'] ] = $discount; |
|
549 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
550 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * Removes a discount from the submission. |
|
555 | + * |
|
556 | + * @since 1.0.19 |
|
557 | + */ |
|
558 | + public function remove_discount( $name ) { |
|
559 | + |
|
560 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
561 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
562 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
563 | + unset( $this->discounts[ $name ] ); |
|
564 | + } |
|
565 | + |
|
566 | + } |
|
567 | + |
|
568 | + /** |
|
569 | + * Checks whether there is a discount code associated with this submission. |
|
570 | + * |
|
571 | + * @since 1.0.19 |
|
572 | + * @return bool |
|
573 | + */ |
|
574 | + public function has_discount_code() { |
|
575 | + return ! empty( $this->discounts['discount_code'] ); |
|
576 | + } |
|
577 | + |
|
578 | + /** |
|
579 | + * Returns the discount code. |
|
580 | + * |
|
581 | + * @since 1.0.19 |
|
582 | + * @return string |
|
583 | + */ |
|
584 | + public function get_discount_code() { |
|
585 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
586 | + } |
|
587 | + |
|
588 | + /** |
|
589 | + * Returns the discount. |
|
590 | + * |
|
591 | + * @since 1.0.19 |
|
592 | + */ |
|
593 | + public function get_discount() { |
|
594 | + return $this->totals['discount']['initial']; |
|
595 | + } |
|
596 | + |
|
597 | + /** |
|
598 | + * Returns the recurring discount. |
|
599 | + * |
|
600 | + * @since 1.0.19 |
|
601 | + */ |
|
602 | + public function get_recurring_discount() { |
|
603 | + return $this->totals['discount']['recurring']; |
|
604 | + } |
|
605 | + |
|
606 | + /** |
|
607 | + * Returns all discounts. |
|
608 | + * |
|
609 | + * @since 1.0.19 |
|
610 | + */ |
|
611 | + public function get_discounts() { |
|
612 | + return $this->discounts; |
|
613 | + } |
|
614 | + |
|
615 | + /* |
|
616 | 616 | |-------------------------------------------------------------------------- |
617 | 617 | | Fees |
618 | 618 | |-------------------------------------------------------------------------- |
@@ -622,89 +622,89 @@ discard block |
||
622 | 622 | | fees. |
623 | 623 | */ |
624 | 624 | |
625 | - /** |
|
626 | - * Prepares the submission's fees. |
|
627 | - * |
|
628 | - * @since 1.0.19 |
|
629 | - */ |
|
630 | - public function process_fees() { |
|
631 | - |
|
632 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
633 | - |
|
634 | - foreach ( $fees_processor->fees as $fee ) { |
|
635 | - $this->add_fee( $fee ); |
|
636 | - } |
|
637 | - |
|
638 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
639 | - } |
|
640 | - |
|
641 | - /** |
|
642 | - * Adds a fee to the submission. |
|
643 | - * |
|
644 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
645 | - * @since 1.0.19 |
|
646 | - */ |
|
647 | - public function add_fee( $fee ) { |
|
648 | - |
|
649 | - $this->fees[ $fee['name'] ] = $fee; |
|
650 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
651 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
652 | - |
|
653 | - } |
|
654 | - |
|
655 | - /** |
|
656 | - * Removes a fee from the submission. |
|
657 | - * |
|
658 | - * @since 1.0.19 |
|
659 | - */ |
|
660 | - public function remove_fee( $name ) { |
|
661 | - |
|
662 | - if ( isset( $this->fees[ $name ] ) ) { |
|
663 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
664 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
665 | - unset( $this->fees[ $name ] ); |
|
666 | - } |
|
667 | - |
|
668 | - } |
|
669 | - |
|
670 | - /** |
|
671 | - * Returns the fees. |
|
672 | - * |
|
673 | - * @since 1.0.19 |
|
674 | - */ |
|
675 | - public function get_fee() { |
|
676 | - return $this->totals['fees']['initial']; |
|
677 | - } |
|
678 | - |
|
679 | - /** |
|
680 | - * Returns the recurring fees. |
|
681 | - * |
|
682 | - * @since 1.0.19 |
|
683 | - */ |
|
684 | - public function get_recurring_fee() { |
|
685 | - return $this->totals['fees']['recurring']; |
|
686 | - } |
|
687 | - |
|
688 | - /** |
|
689 | - * Returns all fees. |
|
690 | - * |
|
691 | - * @since 1.0.19 |
|
692 | - */ |
|
693 | - public function get_fees() { |
|
694 | - return $this->fees; |
|
695 | - } |
|
696 | - |
|
697 | - /** |
|
698 | - * Checks if there are any fees for the form. |
|
699 | - * |
|
700 | - * @return bool |
|
701 | - * @since 1.0.19 |
|
702 | - */ |
|
703 | - public function has_fees() { |
|
704 | - return count( $this->fees ) !== 0; |
|
705 | - } |
|
706 | - |
|
707 | - /* |
|
625 | + /** |
|
626 | + * Prepares the submission's fees. |
|
627 | + * |
|
628 | + * @since 1.0.19 |
|
629 | + */ |
|
630 | + public function process_fees() { |
|
631 | + |
|
632 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
633 | + |
|
634 | + foreach ( $fees_processor->fees as $fee ) { |
|
635 | + $this->add_fee( $fee ); |
|
636 | + } |
|
637 | + |
|
638 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
639 | + } |
|
640 | + |
|
641 | + /** |
|
642 | + * Adds a fee to the submission. |
|
643 | + * |
|
644 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
645 | + * @since 1.0.19 |
|
646 | + */ |
|
647 | + public function add_fee( $fee ) { |
|
648 | + |
|
649 | + $this->fees[ $fee['name'] ] = $fee; |
|
650 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
651 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
652 | + |
|
653 | + } |
|
654 | + |
|
655 | + /** |
|
656 | + * Removes a fee from the submission. |
|
657 | + * |
|
658 | + * @since 1.0.19 |
|
659 | + */ |
|
660 | + public function remove_fee( $name ) { |
|
661 | + |
|
662 | + if ( isset( $this->fees[ $name ] ) ) { |
|
663 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
664 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
665 | + unset( $this->fees[ $name ] ); |
|
666 | + } |
|
667 | + |
|
668 | + } |
|
669 | + |
|
670 | + /** |
|
671 | + * Returns the fees. |
|
672 | + * |
|
673 | + * @since 1.0.19 |
|
674 | + */ |
|
675 | + public function get_fee() { |
|
676 | + return $this->totals['fees']['initial']; |
|
677 | + } |
|
678 | + |
|
679 | + /** |
|
680 | + * Returns the recurring fees. |
|
681 | + * |
|
682 | + * @since 1.0.19 |
|
683 | + */ |
|
684 | + public function get_recurring_fee() { |
|
685 | + return $this->totals['fees']['recurring']; |
|
686 | + } |
|
687 | + |
|
688 | + /** |
|
689 | + * Returns all fees. |
|
690 | + * |
|
691 | + * @since 1.0.19 |
|
692 | + */ |
|
693 | + public function get_fees() { |
|
694 | + return $this->fees; |
|
695 | + } |
|
696 | + |
|
697 | + /** |
|
698 | + * Checks if there are any fees for the form. |
|
699 | + * |
|
700 | + * @return bool |
|
701 | + * @since 1.0.19 |
|
702 | + */ |
|
703 | + public function has_fees() { |
|
704 | + return count( $this->fees ) !== 0; |
|
705 | + } |
|
706 | + |
|
707 | + /* |
|
708 | 708 | |-------------------------------------------------------------------------- |
709 | 709 | | MISC |
710 | 710 | |-------------------------------------------------------------------------- |
@@ -712,109 +712,109 @@ discard block |
||
712 | 712 | | Extra submission functions. |
713 | 713 | */ |
714 | 714 | |
715 | - /** |
|
716 | - * Returns the total amount to collect for this submission. |
|
717 | - * |
|
718 | - * @since 1.0.19 |
|
719 | - */ |
|
720 | - public function get_total() { |
|
721 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
722 | - return max( $total, 0 ); |
|
723 | - } |
|
724 | - |
|
725 | - /** |
|
726 | - * Returns the recurring total amount to collect for this submission. |
|
727 | - * |
|
728 | - * @since 1.0.19 |
|
729 | - */ |
|
730 | - public function get_recurring_total() { |
|
731 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
732 | - return max( $total, 0 ); |
|
733 | - } |
|
734 | - |
|
735 | - /** |
|
736 | - * Whether payment details should be collected for this submission. |
|
737 | - * |
|
738 | - * @since 1.0.19 |
|
739 | - */ |
|
740 | - public function should_collect_payment_details() { |
|
741 | - $initial = $this->get_total(); |
|
742 | - $recurring = $this->get_recurring_total(); |
|
743 | - |
|
744 | - if ( $this->has_recurring == 0 ) { |
|
745 | - $recurring = 0; |
|
746 | - } |
|
747 | - |
|
748 | - $collect = $initial > 0 || $recurring > 0; |
|
749 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
750 | - } |
|
751 | - |
|
752 | - /** |
|
753 | - * Returns the billing email of the user. |
|
754 | - * |
|
755 | - * @since 1.0.19 |
|
756 | - */ |
|
757 | - public function get_billing_email() { |
|
758 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
759 | - } |
|
760 | - |
|
761 | - /** |
|
762 | - * Checks if the submitter has a billing email. |
|
763 | - * |
|
764 | - * @since 1.0.19 |
|
765 | - */ |
|
766 | - public function has_billing_email() { |
|
767 | - $billing_email = $this->get_billing_email(); |
|
768 | - return ! empty( $billing_email ); |
|
769 | - } |
|
770 | - |
|
771 | - /** |
|
772 | - * Returns the appropriate currency for the submission. |
|
773 | - * |
|
774 | - * @since 1.0.19 |
|
775 | - * @return string |
|
776 | - */ |
|
777 | - public function get_currency() { |
|
778 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
779 | - } |
|
780 | - |
|
781 | - /** |
|
782 | - * Returns the raw submission data. |
|
783 | - * |
|
784 | - * @since 1.0.19 |
|
785 | - * @return array |
|
786 | - */ |
|
787 | - public function get_data() { |
|
788 | - return $this->data; |
|
789 | - } |
|
790 | - |
|
791 | - /** |
|
792 | - * Returns a field from the submission data |
|
793 | - * |
|
794 | - * @param string $field |
|
795 | - * @since 1.0.19 |
|
796 | - * @return mixed |
|
797 | - */ |
|
798 | - public function get_field( $field ) { |
|
799 | - return isset( $this->data[ $field ] ) ? $this->data[ $field ] : ''; |
|
800 | - } |
|
801 | - |
|
802 | - /** |
|
803 | - * Checks if a required field is set. |
|
804 | - * |
|
805 | - * @since 1.0.19 |
|
806 | - */ |
|
807 | - public function is_required_field_set( $field ) { |
|
808 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
809 | - } |
|
810 | - |
|
811 | - /** |
|
812 | - * Formats an amount |
|
813 | - * |
|
814 | - * @since 1.0.19 |
|
815 | - */ |
|
816 | - public function format_amount( $amount ) { |
|
817 | - return wpinv_price( $amount, $this->get_currency() ); |
|
818 | - } |
|
715 | + /** |
|
716 | + * Returns the total amount to collect for this submission. |
|
717 | + * |
|
718 | + * @since 1.0.19 |
|
719 | + */ |
|
720 | + public function get_total() { |
|
721 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
722 | + return max( $total, 0 ); |
|
723 | + } |
|
724 | + |
|
725 | + /** |
|
726 | + * Returns the recurring total amount to collect for this submission. |
|
727 | + * |
|
728 | + * @since 1.0.19 |
|
729 | + */ |
|
730 | + public function get_recurring_total() { |
|
731 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
732 | + return max( $total, 0 ); |
|
733 | + } |
|
734 | + |
|
735 | + /** |
|
736 | + * Whether payment details should be collected for this submission. |
|
737 | + * |
|
738 | + * @since 1.0.19 |
|
739 | + */ |
|
740 | + public function should_collect_payment_details() { |
|
741 | + $initial = $this->get_total(); |
|
742 | + $recurring = $this->get_recurring_total(); |
|
743 | + |
|
744 | + if ( $this->has_recurring == 0 ) { |
|
745 | + $recurring = 0; |
|
746 | + } |
|
747 | + |
|
748 | + $collect = $initial > 0 || $recurring > 0; |
|
749 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
750 | + } |
|
751 | + |
|
752 | + /** |
|
753 | + * Returns the billing email of the user. |
|
754 | + * |
|
755 | + * @since 1.0.19 |
|
756 | + */ |
|
757 | + public function get_billing_email() { |
|
758 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
759 | + } |
|
760 | + |
|
761 | + /** |
|
762 | + * Checks if the submitter has a billing email. |
|
763 | + * |
|
764 | + * @since 1.0.19 |
|
765 | + */ |
|
766 | + public function has_billing_email() { |
|
767 | + $billing_email = $this->get_billing_email(); |
|
768 | + return ! empty( $billing_email ); |
|
769 | + } |
|
770 | + |
|
771 | + /** |
|
772 | + * Returns the appropriate currency for the submission. |
|
773 | + * |
|
774 | + * @since 1.0.19 |
|
775 | + * @return string |
|
776 | + */ |
|
777 | + public function get_currency() { |
|
778 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
779 | + } |
|
780 | + |
|
781 | + /** |
|
782 | + * Returns the raw submission data. |
|
783 | + * |
|
784 | + * @since 1.0.19 |
|
785 | + * @return array |
|
786 | + */ |
|
787 | + public function get_data() { |
|
788 | + return $this->data; |
|
789 | + } |
|
790 | + |
|
791 | + /** |
|
792 | + * Returns a field from the submission data |
|
793 | + * |
|
794 | + * @param string $field |
|
795 | + * @since 1.0.19 |
|
796 | + * @return mixed |
|
797 | + */ |
|
798 | + public function get_field( $field ) { |
|
799 | + return isset( $this->data[ $field ] ) ? $this->data[ $field ] : ''; |
|
800 | + } |
|
801 | + |
|
802 | + /** |
|
803 | + * Checks if a required field is set. |
|
804 | + * |
|
805 | + * @since 1.0.19 |
|
806 | + */ |
|
807 | + public function is_required_field_set( $field ) { |
|
808 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
809 | + } |
|
810 | + |
|
811 | + /** |
|
812 | + * Formats an amount |
|
813 | + * |
|
814 | + * @since 1.0.19 |
|
815 | + */ |
|
816 | + public function format_amount( $amount ) { |
|
817 | + return wpinv_price( $amount, $this->get_currency() ); |
|
818 | + } |
|
819 | 819 | |
820 | 820 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | $this->state = wpinv_get_default_state(); |
135 | 135 | |
136 | 136 | // Do we have an actual submission? |
137 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
138 | - $this->load_data( $_POST ); |
|
137 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
138 | + $this->load_data($_POST); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | } |
@@ -145,19 +145,19 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @param array $data |
147 | 147 | */ |
148 | - public function load_data( $data ) { |
|
148 | + public function load_data($data) { |
|
149 | 149 | |
150 | 150 | // Remove slashes from the submitted data... |
151 | - $data = wp_unslash( $data ); |
|
151 | + $data = wp_unslash($data); |
|
152 | 152 | |
153 | 153 | // Allow plugins to filter the data. |
154 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
154 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
155 | 155 | |
156 | 156 | // Cache it... |
157 | 157 | $this->data = $data; |
158 | 158 | |
159 | 159 | // Then generate a unique id from the data. |
160 | - $this->id = md5( wp_json_encode( $data ) ); |
|
160 | + $this->id = md5(wp_json_encode($data)); |
|
161 | 161 | |
162 | 162 | // Finally, process the submission. |
163 | 163 | try { |
@@ -167,26 +167,26 @@ discard block |
||
167 | 167 | $processors = apply_filters( |
168 | 168 | 'getpaid_payment_form_submission_processors', |
169 | 169 | array( |
170 | - array( $this, 'process_payment_form' ), |
|
171 | - array( $this, 'process_invoice' ), |
|
172 | - array( $this, 'process_fees' ), |
|
173 | - array( $this, 'process_items' ), |
|
174 | - array( $this, 'process_taxes' ), |
|
175 | - array( $this, 'process_discount' ), |
|
170 | + array($this, 'process_payment_form'), |
|
171 | + array($this, 'process_invoice'), |
|
172 | + array($this, 'process_fees'), |
|
173 | + array($this, 'process_items'), |
|
174 | + array($this, 'process_taxes'), |
|
175 | + array($this, 'process_discount'), |
|
176 | 176 | ), |
177 | 177 | $this |
178 | 178 | ); |
179 | 179 | |
180 | - foreach ( $processors as $processor ) { |
|
181 | - call_user_func_array( $processor, array( &$this ) ); |
|
180 | + foreach ($processors as $processor) { |
|
181 | + call_user_func_array($processor, array(&$this)); |
|
182 | 182 | } |
183 | 183 | |
184 | - } catch ( Exception $e ) { |
|
184 | + } catch (Exception $e) { |
|
185 | 185 | $this->last_error = $e->getMessage(); |
186 | 186 | } |
187 | 187 | |
188 | 188 | // Fired when we are done processing a submission. |
189 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
189 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
190 | 190 | |
191 | 191 | } |
192 | 192 | |
@@ -207,18 +207,18 @@ discard block |
||
207 | 207 | public function process_payment_form() { |
208 | 208 | |
209 | 209 | // Every submission needs an active payment form. |
210 | - if ( empty( $this->data['form_id'] ) ) { |
|
211 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
210 | + if (empty($this->data['form_id'])) { |
|
211 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | // Fetch the payment form. |
215 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
215 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
216 | 216 | |
217 | - if ( ! $this->payment_form->is_active() ) { |
|
218 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
217 | + if (!$this->payment_form->is_active()) { |
|
218 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
219 | 219 | } |
220 | 220 | |
221 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
221 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -248,30 +248,30 @@ discard block |
||
248 | 248 | public function process_invoice() { |
249 | 249 | |
250 | 250 | // Abort if there is no invoice. |
251 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
251 | + if (empty($this->data['invoice_id'])) { |
|
252 | 252 | return; |
253 | 253 | } |
254 | 254 | |
255 | 255 | // If the submission is for an existing invoice, ensure that it exists |
256 | 256 | // and that it is not paid for. |
257 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
257 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
258 | 258 | |
259 | - if ( empty( $invoice ) ) { |
|
260 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
259 | + if (empty($invoice)) { |
|
260 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
261 | 261 | } |
262 | 262 | |
263 | - if ( $invoice->is_paid() ) { |
|
264 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
263 | + if ($invoice->is_paid()) { |
|
264 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
265 | 265 | } |
266 | 266 | |
267 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
267 | + $this->payment_form->set_items($invoice->get_items()); |
|
268 | 268 | $this->payment_form->invoice = $invoice; |
269 | 269 | |
270 | 270 | $this->country = $invoice->get_country(); |
271 | 271 | $this->state = $invoice->get_state(); |
272 | 272 | $this->invoice = $invoice; |
273 | 273 | |
274 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
274 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * @return bool |
292 | 292 | */ |
293 | 293 | public function has_invoice() { |
294 | - return ! empty( $this->invoice ); |
|
294 | + return !empty($this->invoice); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /* |
@@ -310,13 +310,13 @@ discard block |
||
310 | 310 | */ |
311 | 311 | public function process_items() { |
312 | 312 | |
313 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
313 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
314 | 314 | |
315 | - foreach ( $processor->items as $item ) { |
|
316 | - $this->add_item( $item ); |
|
315 | + foreach ($processor->items as $item) { |
|
316 | + $this->add_item($item); |
|
317 | 317 | } |
318 | 318 | |
319 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
319 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
@@ -325,18 +325,18 @@ discard block |
||
325 | 325 | * @since 1.0.19 |
326 | 326 | * @param GetPaid_Form_Item $item |
327 | 327 | */ |
328 | - public function add_item( $item ) { |
|
328 | + public function add_item($item) { |
|
329 | 329 | |
330 | 330 | // Make sure that it is available for purchase. |
331 | - if ( ! $item->can_purchase() ) { |
|
331 | + if (!$item->can_purchase()) { |
|
332 | 332 | return; |
333 | 333 | } |
334 | 334 | |
335 | 335 | // Each submission can only contain one recurring item. |
336 | - if ( $item->is_recurring() ) { |
|
336 | + if ($item->is_recurring()) { |
|
337 | 337 | |
338 | - if ( $this->has_recurring != 0 ) { |
|
339 | - throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
338 | + if ($this->has_recurring != 0) { |
|
339 | + throw new Exception(__('You can only buy one recurring item at a time.', 'invoicing')); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | $this->has_recurring = $item->get_id(); |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | } |
345 | 345 | |
346 | 346 | // Update the items and totals. |
347 | - $this->items[ $item->get_id() ] = $item; |
|
347 | + $this->items[$item->get_id()] = $item; |
|
348 | 348 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
349 | 349 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
350 | 350 | |
@@ -358,17 +358,17 @@ discard block |
||
358 | 358 | * |
359 | 359 | * @since 1.0.19 |
360 | 360 | */ |
361 | - public function remove_item( $item_id ) { |
|
361 | + public function remove_item($item_id) { |
|
362 | 362 | |
363 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
364 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
365 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
363 | + if (isset($this->items[$item_id])) { |
|
364 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
365 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
366 | 366 | |
367 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
367 | + if ($this->items[$item_id]->is_recurring()) { |
|
368 | 368 | $this->has_recurring = 0; |
369 | 369 | } |
370 | 370 | |
371 | - unset( $this->items[ $item_id ] ); |
|
371 | + unset($this->items[$item_id]); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | } |
@@ -418,26 +418,26 @@ discard block |
||
418 | 418 | public function process_taxes() { |
419 | 419 | |
420 | 420 | // Abort if we're not using taxes. |
421 | - if ( ! $this->use_taxes() ) { |
|
421 | + if (!$this->use_taxes()) { |
|
422 | 422 | return; |
423 | 423 | } |
424 | 424 | |
425 | 425 | // If a custom country && state has been passed in, use it to calculate taxes. |
426 | - if ( ! empty( $this->data['wpinv_country'] ) ) { |
|
426 | + if (!empty($this->data['wpinv_country'])) { |
|
427 | 427 | $this->country = $this->data['wpinv_country']; |
428 | 428 | } |
429 | 429 | |
430 | - if ( ! empty( $this->data['wpinv_state'] ) ) { |
|
430 | + if (!empty($this->data['wpinv_state'])) { |
|
431 | 431 | $this->country = $this->data['wpinv_state']; |
432 | 432 | } |
433 | 433 | |
434 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
434 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
435 | 435 | |
436 | - foreach ( $processor->taxes as $tax ) { |
|
437 | - $this->add_tax( $tax ); |
|
436 | + foreach ($processor->taxes as $tax) { |
|
437 | + $this->add_tax($tax); |
|
438 | 438 | } |
439 | 439 | |
440 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
440 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | /** |
@@ -446,10 +446,10 @@ discard block |
||
446 | 446 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
447 | 447 | * @since 1.0.19 |
448 | 448 | */ |
449 | - public function add_tax( $tax ) { |
|
450 | - $this->taxes[ $tax['name'] ] = $tax; |
|
451 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
452 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
449 | + public function add_tax($tax) { |
|
450 | + $this->taxes[$tax['name']] = $tax; |
|
451 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
452 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | /** |
@@ -457,12 +457,12 @@ discard block |
||
457 | 457 | * |
458 | 458 | * @since 1.0.19 |
459 | 459 | */ |
460 | - public function remove_tax( $tax_name ) { |
|
460 | + public function remove_tax($tax_name) { |
|
461 | 461 | |
462 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
463 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
464 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
465 | - unset( $this->taxes[ $tax_name ] ); |
|
462 | + if (isset($this->taxes[$tax_name])) { |
|
463 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
464 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
465 | + unset($this->taxes[$tax_name]); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | } |
@@ -476,11 +476,11 @@ discard block |
||
476 | 476 | |
477 | 477 | $use_taxes = wpinv_use_taxes(); |
478 | 478 | |
479 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
479 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
480 | 480 | $use_taxes = false; |
481 | 481 | } |
482 | 482 | |
483 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
483 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
484 | 484 | |
485 | 485 | } |
486 | 486 | |
@@ -529,13 +529,13 @@ discard block |
||
529 | 529 | |
530 | 530 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
531 | 531 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
532 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
532 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
533 | 533 | |
534 | - foreach ( $processor->discounts as $discount ) { |
|
535 | - $this->add_discount( $discount ); |
|
534 | + foreach ($processor->discounts as $discount) { |
|
535 | + $this->add_discount($discount); |
|
536 | 536 | } |
537 | 537 | |
538 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
538 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | /** |
@@ -544,10 +544,10 @@ discard block |
||
544 | 544 | * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
545 | 545 | * @since 1.0.19 |
546 | 546 | */ |
547 | - public function add_discount( $discount ) { |
|
548 | - $this->discounts[ $discount['name'] ] = $discount; |
|
549 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
550 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
547 | + public function add_discount($discount) { |
|
548 | + $this->discounts[$discount['name']] = $discount; |
|
549 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
550 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | /** |
@@ -555,12 +555,12 @@ discard block |
||
555 | 555 | * |
556 | 556 | * @since 1.0.19 |
557 | 557 | */ |
558 | - public function remove_discount( $name ) { |
|
558 | + public function remove_discount($name) { |
|
559 | 559 | |
560 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
561 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
562 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
563 | - unset( $this->discounts[ $name ] ); |
|
560 | + if (isset($this->discounts[$name])) { |
|
561 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
562 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
563 | + unset($this->discounts[$name]); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | } |
@@ -572,7 +572,7 @@ discard block |
||
572 | 572 | * @return bool |
573 | 573 | */ |
574 | 574 | public function has_discount_code() { |
575 | - return ! empty( $this->discounts['discount_code'] ); |
|
575 | + return !empty($this->discounts['discount_code']); |
|
576 | 576 | } |
577 | 577 | |
578 | 578 | /** |
@@ -629,13 +629,13 @@ discard block |
||
629 | 629 | */ |
630 | 630 | public function process_fees() { |
631 | 631 | |
632 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
632 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
633 | 633 | |
634 | - foreach ( $fees_processor->fees as $fee ) { |
|
635 | - $this->add_fee( $fee ); |
|
634 | + foreach ($fees_processor->fees as $fee) { |
|
635 | + $this->add_fee($fee); |
|
636 | 636 | } |
637 | 637 | |
638 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
638 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
639 | 639 | } |
640 | 640 | |
641 | 641 | /** |
@@ -644,11 +644,11 @@ discard block |
||
644 | 644 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
645 | 645 | * @since 1.0.19 |
646 | 646 | */ |
647 | - public function add_fee( $fee ) { |
|
647 | + public function add_fee($fee) { |
|
648 | 648 | |
649 | - $this->fees[ $fee['name'] ] = $fee; |
|
650 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
651 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
649 | + $this->fees[$fee['name']] = $fee; |
|
650 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
651 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
652 | 652 | |
653 | 653 | } |
654 | 654 | |
@@ -657,12 +657,12 @@ discard block |
||
657 | 657 | * |
658 | 658 | * @since 1.0.19 |
659 | 659 | */ |
660 | - public function remove_fee( $name ) { |
|
660 | + public function remove_fee($name) { |
|
661 | 661 | |
662 | - if ( isset( $this->fees[ $name ] ) ) { |
|
663 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
664 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
665 | - unset( $this->fees[ $name ] ); |
|
662 | + if (isset($this->fees[$name])) { |
|
663 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
664 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
665 | + unset($this->fees[$name]); |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | } |
@@ -701,7 +701,7 @@ discard block |
||
701 | 701 | * @since 1.0.19 |
702 | 702 | */ |
703 | 703 | public function has_fees() { |
704 | - return count( $this->fees ) !== 0; |
|
704 | + return count($this->fees) !== 0; |
|
705 | 705 | } |
706 | 706 | |
707 | 707 | /* |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | */ |
720 | 720 | public function get_total() { |
721 | 721 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
722 | - return max( $total, 0 ); |
|
722 | + return max($total, 0); |
|
723 | 723 | } |
724 | 724 | |
725 | 725 | /** |
@@ -729,7 +729,7 @@ discard block |
||
729 | 729 | */ |
730 | 730 | public function get_recurring_total() { |
731 | 731 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
732 | - return max( $total, 0 ); |
|
732 | + return max($total, 0); |
|
733 | 733 | } |
734 | 734 | |
735 | 735 | /** |
@@ -741,12 +741,12 @@ discard block |
||
741 | 741 | $initial = $this->get_total(); |
742 | 742 | $recurring = $this->get_recurring_total(); |
743 | 743 | |
744 | - if ( $this->has_recurring == 0 ) { |
|
744 | + if ($this->has_recurring == 0) { |
|
745 | 745 | $recurring = 0; |
746 | 746 | } |
747 | 747 | |
748 | 748 | $collect = $initial > 0 || $recurring > 0; |
749 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
749 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
750 | 750 | } |
751 | 751 | |
752 | 752 | /** |
@@ -755,7 +755,7 @@ discard block |
||
755 | 755 | * @since 1.0.19 |
756 | 756 | */ |
757 | 757 | public function get_billing_email() { |
758 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
758 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
759 | 759 | } |
760 | 760 | |
761 | 761 | /** |
@@ -765,7 +765,7 @@ discard block |
||
765 | 765 | */ |
766 | 766 | public function has_billing_email() { |
767 | 767 | $billing_email = $this->get_billing_email(); |
768 | - return ! empty( $billing_email ); |
|
768 | + return !empty($billing_email); |
|
769 | 769 | } |
770 | 770 | |
771 | 771 | /** |
@@ -795,8 +795,8 @@ discard block |
||
795 | 795 | * @since 1.0.19 |
796 | 796 | * @return mixed |
797 | 797 | */ |
798 | - public function get_field( $field ) { |
|
799 | - return isset( $this->data[ $field ] ) ? $this->data[ $field ] : ''; |
|
798 | + public function get_field($field) { |
|
799 | + return isset($this->data[$field]) ? $this->data[$field] : ''; |
|
800 | 800 | } |
801 | 801 | |
802 | 802 | /** |
@@ -804,8 +804,8 @@ discard block |
||
804 | 804 | * |
805 | 805 | * @since 1.0.19 |
806 | 806 | */ |
807 | - public function is_required_field_set( $field ) { |
|
808 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
807 | + public function is_required_field_set($field) { |
|
808 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
809 | 809 | } |
810 | 810 | |
811 | 811 | /** |
@@ -813,8 +813,8 @@ discard block |
||
813 | 813 | * |
814 | 814 | * @since 1.0.19 |
815 | 815 | */ |
816 | - public function format_amount( $amount ) { |
|
817 | - return wpinv_price( $amount, $this->get_currency() ); |
|
816 | + public function format_amount($amount) { |
|
817 | + return wpinv_price($amount, $this->get_currency()); |
|
818 | 818 | } |
819 | 819 | |
820 | 820 | } |
@@ -12,185 +12,185 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Refresh_Prices { |
14 | 14 | |
15 | - /** |
|
16 | - * Contains the response for refreshing prices. |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $response = array(); |
|
15 | + /** |
|
16 | + * Contains the response for refreshing prices. |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $response = array(); |
|
20 | 20 | |
21 | 21 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - */ |
|
26 | - public function __construct( $submission ) { |
|
27 | - |
|
28 | - $this->response = array( |
|
29 | - 'submission_id' => $submission->id, |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + */ |
|
26 | + public function __construct( $submission ) { |
|
27 | + |
|
28 | + $this->response = array( |
|
29 | + 'submission_id' => $submission->id, |
|
30 | 30 | 'has_recurring' => $submission->has_recurring, |
31 | 31 | 'is_free' => $submission->should_collect_payment_details(), |
32 | - ); |
|
32 | + ); |
|
33 | 33 | |
34 | - $this->add_totals( $submission ); |
|
35 | - $this->add_texts( $submission ); |
|
36 | - $this->add_items( $submission ); |
|
37 | - $this->add_fees( $submission ); |
|
38 | - $this->add_discounts( $submission ); |
|
39 | - $this->add_taxes( $submission ); |
|
40 | - |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Adds totals to a response for submission refresh prices. |
|
45 | - * |
|
46 | - * @param GetPaid_Payment_Form_Submission $submission |
|
47 | - */ |
|
48 | - public function add_totals( $submission ) { |
|
49 | - |
|
50 | - $this->response = array_merge( |
|
51 | - $this->response, |
|
52 | - array( |
|
53 | - |
|
54 | - 'totals' => array( |
|
55 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
56 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
57 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
58 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
59 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
60 | - ), |
|
34 | + $this->add_totals( $submission ); |
|
35 | + $this->add_texts( $submission ); |
|
36 | + $this->add_items( $submission ); |
|
37 | + $this->add_fees( $submission ); |
|
38 | + $this->add_discounts( $submission ); |
|
39 | + $this->add_taxes( $submission ); |
|
40 | + |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Adds totals to a response for submission refresh prices. |
|
45 | + * |
|
46 | + * @param GetPaid_Payment_Form_Submission $submission |
|
47 | + */ |
|
48 | + public function add_totals( $submission ) { |
|
49 | + |
|
50 | + $this->response = array_merge( |
|
51 | + $this->response, |
|
52 | + array( |
|
53 | + |
|
54 | + 'totals' => array( |
|
55 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
56 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
57 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
58 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
59 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
60 | + ), |
|
61 | 61 | |
62 | - 'recurring' => array( |
|
63 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
64 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
65 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
66 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
67 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
68 | - ), |
|
62 | + 'recurring' => array( |
|
63 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
64 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
65 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
66 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
67 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
68 | + ), |
|
69 | 69 | |
70 | - ) |
|
71 | - ); |
|
70 | + ) |
|
71 | + ); |
|
72 | 72 | |
73 | - } |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Adds texts to a response for submission refresh prices. |
|
77 | - * |
|
78 | - * @param GetPaid_Payment_Form_Submission $submission |
|
79 | - */ |
|
80 | - public function add_texts( $submission ) { |
|
75 | + /** |
|
76 | + * Adds texts to a response for submission refresh prices. |
|
77 | + * |
|
78 | + * @param GetPaid_Payment_Form_Submission $submission |
|
79 | + */ |
|
80 | + public function add_texts( $submission ) { |
|
81 | 81 | |
82 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
82 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
83 | 83 | |
84 | - if ( $submission->has_recurring != 0 ) { |
|
84 | + if ( $submission->has_recurring != 0 ) { |
|
85 | 85 | |
86 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
87 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
86 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
87 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
88 | 88 | |
89 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
90 | - $payable = "$payable / $period"; |
|
91 | - } else { |
|
92 | - $payable = sprintf( |
|
93 | - __( '%1$s (renews at %2$s / %3$s)'), |
|
94 | - $submission->format_amount( $submission->get_total() ), |
|
95 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
96 | - $period |
|
97 | - ); |
|
98 | - } |
|
89 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
90 | + $payable = "$payable / $period"; |
|
91 | + } else { |
|
92 | + $payable = sprintf( |
|
93 | + __( '%1$s (renews at %2$s / %3$s)'), |
|
94 | + $submission->format_amount( $submission->get_total() ), |
|
95 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
96 | + $period |
|
97 | + ); |
|
98 | + } |
|
99 | 99 | |
100 | - } |
|
100 | + } |
|
101 | 101 | |
102 | - $texts = array( |
|
103 | - '.getpaid-checkout-total-payable' => $payable, |
|
104 | - ); |
|
102 | + $texts = array( |
|
103 | + '.getpaid-checkout-total-payable' => $payable, |
|
104 | + ); |
|
105 | 105 | |
106 | - foreach ( $submission->get_items() as $item_id => $item ) { |
|
107 | - $texts[".item-$item_id .getpaid-item-initial-price"] = $submission->format_amount( $item->get_sub_total() ); |
|
108 | - $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() ); |
|
109 | - } |
|
106 | + foreach ( $submission->get_items() as $item_id => $item ) { |
|
107 | + $texts[".item-$item_id .getpaid-item-initial-price"] = $submission->format_amount( $item->get_sub_total() ); |
|
108 | + $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() ); |
|
109 | + } |
|
110 | 110 | |
111 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
111 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
112 | 112 | |
113 | - } |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Adds items to a response for submission refresh prices. |
|
117 | - * |
|
118 | - * @param GetPaid_Payment_Form_Submission $submission |
|
119 | - */ |
|
120 | - public function add_items( $submission ) { |
|
115 | + /** |
|
116 | + * Adds items to a response for submission refresh prices. |
|
117 | + * |
|
118 | + * @param GetPaid_Payment_Form_Submission $submission |
|
119 | + */ |
|
120 | + public function add_items( $submission ) { |
|
121 | 121 | |
122 | - // Add items. |
|
123 | - $items = array(); |
|
122 | + // Add items. |
|
123 | + $items = array(); |
|
124 | 124 | |
125 | 125 | foreach ( $submission->get_items() as $item_id => $item ) { |
126 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
127 | - } |
|
126 | + $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
127 | + } |
|
128 | 128 | |
129 | - $this->response = array_merge( |
|
130 | - $this->response, |
|
131 | - array( 'items' => $items ) |
|
132 | - ); |
|
129 | + $this->response = array_merge( |
|
130 | + $this->response, |
|
131 | + array( 'items' => $items ) |
|
132 | + ); |
|
133 | 133 | |
134 | - } |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * Adds fees to a response for submission refresh prices. |
|
138 | - * |
|
139 | - * @param GetPaid_Payment_Form_Submission $submission |
|
140 | - */ |
|
141 | - public function add_fees( $submission ) { |
|
136 | + /** |
|
137 | + * Adds fees to a response for submission refresh prices. |
|
138 | + * |
|
139 | + * @param GetPaid_Payment_Form_Submission $submission |
|
140 | + */ |
|
141 | + public function add_fees( $submission ) { |
|
142 | 142 | |
143 | - $fees = array(); |
|
143 | + $fees = array(); |
|
144 | 144 | |
145 | 145 | foreach ( $submission->get_fees() as $name => $data ) { |
146 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
147 | - } |
|
146 | + $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
147 | + } |
|
148 | 148 | |
149 | - $this->response = array_merge( |
|
150 | - $this->response, |
|
151 | - array( 'fees' => $fees ) |
|
152 | - ); |
|
149 | + $this->response = array_merge( |
|
150 | + $this->response, |
|
151 | + array( 'fees' => $fees ) |
|
152 | + ); |
|
153 | 153 | |
154 | - } |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * Adds discounts to a response for submission refresh prices. |
|
158 | - * |
|
159 | - * @param GetPaid_Payment_Form_Submission $submission |
|
160 | - */ |
|
161 | - public function add_discounts( $submission ) { |
|
156 | + /** |
|
157 | + * Adds discounts to a response for submission refresh prices. |
|
158 | + * |
|
159 | + * @param GetPaid_Payment_Form_Submission $submission |
|
160 | + */ |
|
161 | + public function add_discounts( $submission ) { |
|
162 | 162 | |
163 | - $discounts = array(); |
|
163 | + $discounts = array(); |
|
164 | 164 | |
165 | 165 | foreach ( $submission->get_discounts() as $name => $data ) { |
166 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
167 | - } |
|
166 | + $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
167 | + } |
|
168 | 168 | |
169 | - $this->response = array_merge( |
|
170 | - $this->response, |
|
171 | - array( 'discounts' => $discounts ) |
|
172 | - ); |
|
169 | + $this->response = array_merge( |
|
170 | + $this->response, |
|
171 | + array( 'discounts' => $discounts ) |
|
172 | + ); |
|
173 | 173 | |
174 | - } |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * Adds taxes to a response for submission refresh prices. |
|
178 | - * |
|
179 | - * @param GetPaid_Payment_Form_Submission $submission |
|
180 | - */ |
|
181 | - public function add_taxes( $submission ) { |
|
176 | + /** |
|
177 | + * Adds taxes to a response for submission refresh prices. |
|
178 | + * |
|
179 | + * @param GetPaid_Payment_Form_Submission $submission |
|
180 | + */ |
|
181 | + public function add_taxes( $submission ) { |
|
182 | 182 | |
183 | - $taxes = array(); |
|
183 | + $taxes = array(); |
|
184 | 184 | |
185 | 185 | foreach ( $submission->get_taxes() as $name => $data ) { |
186 | - $taxes[$name] = $submission->format_amount( $data['initial_tax'] ); |
|
187 | - } |
|
186 | + $taxes[$name] = $submission->format_amount( $data['initial_tax'] ); |
|
187 | + } |
|
188 | 188 | |
189 | - $this->response = array_merge( |
|
190 | - $this->response, |
|
191 | - array( 'taxes' => $taxes ) |
|
192 | - ); |
|
189 | + $this->response = array_merge( |
|
190 | + $this->response, |
|
191 | + array( 'taxes' => $taxes ) |
|
192 | + ); |
|
193 | 193 | |
194 | - } |
|
194 | + } |
|
195 | 195 | |
196 | 196 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment form submission refresh prices class |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param GetPaid_Payment_Form_Submission $submission |
25 | 25 | */ |
26 | - public function __construct( $submission ) { |
|
26 | + public function __construct($submission) { |
|
27 | 27 | |
28 | 28 | $this->response = array( |
29 | 29 | 'submission_id' => $submission->id, |
@@ -31,12 +31,12 @@ discard block |
||
31 | 31 | 'is_free' => $submission->should_collect_payment_details(), |
32 | 32 | ); |
33 | 33 | |
34 | - $this->add_totals( $submission ); |
|
35 | - $this->add_texts( $submission ); |
|
36 | - $this->add_items( $submission ); |
|
37 | - $this->add_fees( $submission ); |
|
38 | - $this->add_discounts( $submission ); |
|
39 | - $this->add_taxes( $submission ); |
|
34 | + $this->add_totals($submission); |
|
35 | + $this->add_texts($submission); |
|
36 | + $this->add_items($submission); |
|
37 | + $this->add_fees($submission); |
|
38 | + $this->add_discounts($submission); |
|
39 | + $this->add_taxes($submission); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | |
@@ -45,26 +45,26 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @param GetPaid_Payment_Form_Submission $submission |
47 | 47 | */ |
48 | - public function add_totals( $submission ) { |
|
48 | + public function add_totals($submission) { |
|
49 | 49 | |
50 | 50 | $this->response = array_merge( |
51 | 51 | $this->response, |
52 | 52 | array( |
53 | 53 | |
54 | 54 | 'totals' => array( |
55 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
56 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
57 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
58 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
59 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
55 | + 'subtotal' => $submission->format_amount($submission->get_subtotal()), |
|
56 | + 'discount' => $submission->format_amount($submission->get_discount()), |
|
57 | + 'fees' => $submission->format_amount($submission->get_fee()), |
|
58 | + 'tax' => $submission->format_amount($submission->get_tax()), |
|
59 | + 'total' => $submission->format_amount($submission->get_total()), |
|
60 | 60 | ), |
61 | 61 | |
62 | 62 | 'recurring' => array( |
63 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
64 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
65 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
66 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
67 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
63 | + 'subtotal' => $submission->format_amount($submission->get_recurring_subtotal()), |
|
64 | + 'discount' => $submission->format_amount($submission->get_recurring_discount()), |
|
65 | + 'fees' => $submission->format_amount($submission->get_recurring_fee()), |
|
66 | + 'tax' => $submission->format_amount($submission->get_recurring_tax()), |
|
67 | + 'total' => $submission->format_amount($submission->get_recurring_total()), |
|
68 | 68 | ), |
69 | 69 | |
70 | 70 | ) |
@@ -77,22 +77,22 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @param GetPaid_Payment_Form_Submission $submission |
79 | 79 | */ |
80 | - public function add_texts( $submission ) { |
|
80 | + public function add_texts($submission) { |
|
81 | 81 | |
82 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
82 | + $payable = $submission->format_amount($submission->get_total()); |
|
83 | 83 | |
84 | - if ( $submission->has_recurring != 0 ) { |
|
84 | + if ($submission->has_recurring != 0) { |
|
85 | 85 | |
86 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
87 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
86 | + $recurring = new WPInv_Item($submission->has_recurring); |
|
87 | + $period = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), ''); |
|
88 | 88 | |
89 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
89 | + if ($submission->get_total() == $submission->get_recurring_total()) { |
|
90 | 90 | $payable = "$payable / $period"; |
91 | 91 | } else { |
92 | 92 | $payable = sprintf( |
93 | - __( '%1$s (renews at %2$s / %3$s)'), |
|
94 | - $submission->format_amount( $submission->get_total() ), |
|
95 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
93 | + __('%1$s (renews at %2$s / %3$s)'), |
|
94 | + $submission->format_amount($submission->get_total()), |
|
95 | + $submission->format_amount($submission->get_recurring_total()), |
|
96 | 96 | $period |
97 | 97 | ); |
98 | 98 | } |
@@ -103,12 +103,12 @@ discard block |
||
103 | 103 | '.getpaid-checkout-total-payable' => $payable, |
104 | 104 | ); |
105 | 105 | |
106 | - foreach ( $submission->get_items() as $item_id => $item ) { |
|
107 | - $texts[".item-$item_id .getpaid-item-initial-price"] = $submission->format_amount( $item->get_sub_total() ); |
|
108 | - $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() ); |
|
106 | + foreach ($submission->get_items() as $item_id => $item) { |
|
107 | + $texts[".item-$item_id .getpaid-item-initial-price"] = $submission->format_amount($item->get_sub_total()); |
|
108 | + $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount($item->get_recurring_sub_total()); |
|
109 | 109 | } |
110 | 110 | |
111 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
111 | + $this->response = array_merge($this->response, array('texts' => $texts)); |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | |
@@ -117,18 +117,18 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @param GetPaid_Payment_Form_Submission $submission |
119 | 119 | */ |
120 | - public function add_items( $submission ) { |
|
120 | + public function add_items($submission) { |
|
121 | 121 | |
122 | 122 | // Add items. |
123 | 123 | $items = array(); |
124 | 124 | |
125 | - foreach ( $submission->get_items() as $item_id => $item ) { |
|
126 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
125 | + foreach ($submission->get_items() as $item_id => $item) { |
|
126 | + $items["$item_id"] = $submission->format_amount($item->get_sub_total()); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | $this->response = array_merge( |
130 | 130 | $this->response, |
131 | - array( 'items' => $items ) |
|
131 | + array('items' => $items) |
|
132 | 132 | ); |
133 | 133 | |
134 | 134 | } |
@@ -138,17 +138,17 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @param GetPaid_Payment_Form_Submission $submission |
140 | 140 | */ |
141 | - public function add_fees( $submission ) { |
|
141 | + public function add_fees($submission) { |
|
142 | 142 | |
143 | 143 | $fees = array(); |
144 | 144 | |
145 | - foreach ( $submission->get_fees() as $name => $data ) { |
|
146 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
145 | + foreach ($submission->get_fees() as $name => $data) { |
|
146 | + $fees[$name] = $submission->format_amount($data['initial_fee']); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | $this->response = array_merge( |
150 | 150 | $this->response, |
151 | - array( 'fees' => $fees ) |
|
151 | + array('fees' => $fees) |
|
152 | 152 | ); |
153 | 153 | |
154 | 154 | } |
@@ -158,17 +158,17 @@ discard block |
||
158 | 158 | * |
159 | 159 | * @param GetPaid_Payment_Form_Submission $submission |
160 | 160 | */ |
161 | - public function add_discounts( $submission ) { |
|
161 | + public function add_discounts($submission) { |
|
162 | 162 | |
163 | 163 | $discounts = array(); |
164 | 164 | |
165 | - foreach ( $submission->get_discounts() as $name => $data ) { |
|
166 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
165 | + foreach ($submission->get_discounts() as $name => $data) { |
|
166 | + $discounts[$name] = $submission->format_amount($data['initial_discount']); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | $this->response = array_merge( |
170 | 170 | $this->response, |
171 | - array( 'discounts' => $discounts ) |
|
171 | + array('discounts' => $discounts) |
|
172 | 172 | ); |
173 | 173 | |
174 | 174 | } |
@@ -178,17 +178,17 @@ discard block |
||
178 | 178 | * |
179 | 179 | * @param GetPaid_Payment_Form_Submission $submission |
180 | 180 | */ |
181 | - public function add_taxes( $submission ) { |
|
181 | + public function add_taxes($submission) { |
|
182 | 182 | |
183 | 183 | $taxes = array(); |
184 | 184 | |
185 | - foreach ( $submission->get_taxes() as $name => $data ) { |
|
186 | - $taxes[$name] = $submission->format_amount( $data['initial_tax'] ); |
|
185 | + foreach ($submission->get_taxes() as $name => $data) { |
|
186 | + $taxes[$name] = $submission->format_amount($data['initial_tax']); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | $this->response = array_merge( |
190 | 190 | $this->response, |
191 | - array( 'taxes' => $taxes ) |
|
191 | + array('taxes' => $taxes) |
|
192 | 192 | ); |
193 | 193 | |
194 | 194 | } |