@@ -7,206 +7,206 @@ 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_get_payment_gateways() { |
15 | 15 | // Default, built-in gateways |
16 | 16 | $gateways = array( |
17 | 17 | 'paypal' => array( |
18 | - 'admin_label' => __( 'PayPal Standard', 'invoicing' ), |
|
19 | - 'checkout_label' => __( 'PayPal Standard', 'invoicing' ), |
|
18 | + 'admin_label' => __('PayPal Standard', 'invoicing'), |
|
19 | + 'checkout_label' => __('PayPal Standard', 'invoicing'), |
|
20 | 20 | 'ordering' => 1, |
21 | 21 | ), |
22 | 22 | 'authorizenet' => array( |
23 | - 'admin_label' => __( 'Authorize.Net (AIM)', 'invoicing' ), |
|
24 | - 'checkout_label' => __( 'Authorize.Net - Credit Card / Debit Card', 'invoicing' ), |
|
23 | + 'admin_label' => __('Authorize.Net (AIM)', 'invoicing'), |
|
24 | + 'checkout_label' => __('Authorize.Net - Credit Card / Debit Card', 'invoicing'), |
|
25 | 25 | 'ordering' => 4, |
26 | 26 | ), |
27 | 27 | 'worldpay' => array( |
28 | - 'admin_label' => __( 'Worldpay', 'invoicing' ), |
|
29 | - 'checkout_label' => __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ), |
|
28 | + 'admin_label' => __('Worldpay', 'invoicing'), |
|
29 | + 'checkout_label' => __('Worldpay - Credit Card / Debit Card', 'invoicing'), |
|
30 | 30 | 'ordering' => 5, |
31 | 31 | ), |
32 | 32 | 'bank_transfer' => array( |
33 | - 'admin_label' => __( 'Pre Bank Transfer', 'invoicing' ), |
|
34 | - 'checkout_label' => __( 'Pre Bank Transfer', 'invoicing' ), |
|
33 | + 'admin_label' => __('Pre Bank Transfer', 'invoicing'), |
|
34 | + 'checkout_label' => __('Pre Bank Transfer', 'invoicing'), |
|
35 | 35 | 'ordering' => 11, |
36 | 36 | ), |
37 | 37 | 'manual' => array( |
38 | - 'admin_label' => __( 'Test Payment', 'invoicing' ), |
|
39 | - 'checkout_label' => __( 'Test Payment', 'invoicing' ), |
|
38 | + 'admin_label' => __('Test Payment', 'invoicing'), |
|
39 | + 'checkout_label' => __('Test Payment', 'invoicing'), |
|
40 | 40 | 'ordering' => 12, |
41 | 41 | ), |
42 | 42 | ); |
43 | 43 | |
44 | - return apply_filters( 'wpinv_payment_gateways', $gateways ); |
|
44 | + return apply_filters('wpinv_payment_gateways', $gateways); |
|
45 | 45 | } |
46 | 46 | |
47 | -function wpinv_payment_gateway_titles( $all_gateways ) { |
|
47 | +function wpinv_payment_gateway_titles($all_gateways) { |
|
48 | 48 | global $wpinv_options; |
49 | 49 | |
50 | 50 | $gateways = array(); |
51 | - foreach ( $all_gateways as $key => $gateway ) { |
|
52 | - if ( !empty( $wpinv_options[$key . '_title'] ) ) { |
|
53 | - $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' ); |
|
51 | + foreach ($all_gateways as $key => $gateway) { |
|
52 | + if (!empty($wpinv_options[$key . '_title'])) { |
|
53 | + $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing'); |
|
54 | 54 | } |
55 | 55 | |
56 | - $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' ); |
|
56 | + $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : ''); |
|
57 | 57 | } |
58 | 58 | |
59 | - asort( $gateways ); |
|
59 | + asort($gateways); |
|
60 | 60 | |
61 | - foreach ( $gateways as $gateway => $key ) { |
|
61 | + foreach ($gateways as $gateway => $key) { |
|
62 | 62 | $gateways[$gateway] = $all_gateways[$gateway]; |
63 | 63 | } |
64 | 64 | |
65 | 65 | return $gateways; |
66 | 66 | } |
67 | -add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 ); |
|
67 | +add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1); |
|
68 | 68 | |
69 | -function wpinv_get_enabled_payment_gateways( $sort = false ) { |
|
69 | +function wpinv_get_enabled_payment_gateways($sort = false) { |
|
70 | 70 | $gateways = wpinv_get_payment_gateways(); |
71 | - $enabled = wpinv_get_option( 'gateways', false ); |
|
71 | + $enabled = wpinv_get_option('gateways', false); |
|
72 | 72 | |
73 | 73 | $gateway_list = array(); |
74 | 74 | |
75 | - foreach ( $gateways as $key => $gateway ) { |
|
76 | - if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) { |
|
77 | - $gateway_list[ $key ] = $gateway; |
|
75 | + foreach ($gateways as $key => $gateway) { |
|
76 | + if (isset($enabled[$key]) && $enabled[$key] == 1) { |
|
77 | + $gateway_list[$key] = $gateway; |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | - if ( true === $sort ) { |
|
82 | - uasort( $gateway_list, 'wpinv_sort_gateway_order' ); |
|
81 | + if (true === $sort) { |
|
82 | + uasort($gateway_list, 'wpinv_sort_gateway_order'); |
|
83 | 83 | |
84 | 84 | // Reorder our gateways so the default is first |
85 | 85 | $default_gateway_id = wpinv_get_default_gateway(); |
86 | 86 | |
87 | - if ( wpinv_is_gateway_active( $default_gateway_id ) ) { |
|
88 | - $default_gateway = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] ); |
|
89 | - unset( $gateway_list[ $default_gateway_id ] ); |
|
87 | + if (wpinv_is_gateway_active($default_gateway_id)) { |
|
88 | + $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]); |
|
89 | + unset($gateway_list[$default_gateway_id]); |
|
90 | 90 | |
91 | - $gateway_list = array_merge( $default_gateway, $gateway_list ); |
|
91 | + $gateway_list = array_merge($default_gateway, $gateway_list); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | - return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list ); |
|
95 | + return apply_filters('wpinv_enabled_payment_gateways', $gateway_list); |
|
96 | 96 | } |
97 | 97 | |
98 | -function wpinv_sort_gateway_order( $a, $b ) { |
|
98 | +function wpinv_sort_gateway_order($a, $b) { |
|
99 | 99 | return $a['ordering'] - $b['ordering']; |
100 | 100 | } |
101 | 101 | |
102 | -function wpinv_is_gateway_active( $gateway ) { |
|
102 | +function wpinv_is_gateway_active($gateway) { |
|
103 | 103 | $gateways = wpinv_get_enabled_payment_gateways(); |
104 | 104 | |
105 | - $ret = is_array($gateways) && $gateway ? array_key_exists( $gateway, $gateways ) : false; |
|
105 | + $ret = is_array($gateways) && $gateway ? array_key_exists($gateway, $gateways) : false; |
|
106 | 106 | |
107 | - return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways ); |
|
107 | + return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | function wpinv_get_default_gateway() { |
111 | - $default = wpinv_get_option( 'default_gateway', 'paypal' ); |
|
111 | + $default = wpinv_get_option('default_gateway', 'paypal'); |
|
112 | 112 | |
113 | - if ( !wpinv_is_gateway_active( $default ) ) { |
|
113 | + if (!wpinv_is_gateway_active($default)) { |
|
114 | 114 | $gateways = wpinv_get_enabled_payment_gateways(); |
115 | - $gateways = array_keys( $gateways ); |
|
116 | - $default = reset( $gateways ); |
|
115 | + $gateways = array_keys($gateways); |
|
116 | + $default = reset($gateways); |
|
117 | 117 | } |
118 | 118 | |
119 | - return apply_filters( 'wpinv_default_gateway', $default ); |
|
119 | + return apply_filters('wpinv_default_gateway', $default); |
|
120 | 120 | } |
121 | 121 | |
122 | -function wpinv_get_gateway_admin_label( $gateway ) { |
|
122 | +function wpinv_get_gateway_admin_label($gateway) { |
|
123 | 123 | $gateways = wpinv_get_payment_gateways(); |
124 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway; |
|
125 | - $payment = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false; |
|
124 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway; |
|
125 | + $payment = isset($_GET['id']) ? absint($_GET['id']) : false; |
|
126 | 126 | |
127 | - if( $gateway == 'manual' && $payment ) { |
|
128 | - if( wpinv_get_payment_amount( $payment ) == 0 ) { |
|
129 | - $label = __( 'Manual Payment', 'invoicing' ); |
|
127 | + if ($gateway == 'manual' && $payment) { |
|
128 | + if (wpinv_get_payment_amount($payment) == 0) { |
|
129 | + $label = __('Manual Payment', 'invoicing'); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | - return apply_filters( 'wpinv_gateway_admin_label', $label, $gateway ); |
|
133 | + return apply_filters('wpinv_gateway_admin_label', $label, $gateway); |
|
134 | 134 | } |
135 | 135 | |
136 | -function wpinv_get_gateway_description( $gateway ) { |
|
136 | +function wpinv_get_gateway_description($gateway) { |
|
137 | 137 | global $wpinv_options; |
138 | 138 | |
139 | - $description = isset( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : ''; |
|
139 | + $description = isset($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : ''; |
|
140 | 140 | |
141 | - return apply_filters( 'wpinv_gateway_description', $description, $gateway ); |
|
141 | + return apply_filters('wpinv_gateway_description', $description, $gateway); |
|
142 | 142 | } |
143 | 143 | |
144 | -function wpinv_get_gateway_button_label( $gateway ) { |
|
145 | - return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' ); |
|
144 | +function wpinv_get_gateway_button_label($gateway) { |
|
145 | + return apply_filters('wpinv_gateway_' . $gateway . '_button_label', ''); |
|
146 | 146 | } |
147 | 147 | |
148 | -function wpinv_get_gateway_checkout_label( $gateway ) { |
|
148 | +function wpinv_get_gateway_checkout_label($gateway) { |
|
149 | 149 | $gateways = wpinv_get_payment_gateways(); |
150 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway; |
|
150 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway; |
|
151 | 151 | |
152 | - if( $gateway == 'manual' ) { |
|
153 | - $label = __( 'Manual Payment', 'invoicing' ); |
|
152 | + if ($gateway == 'manual') { |
|
153 | + $label = __('Manual Payment', 'invoicing'); |
|
154 | 154 | } |
155 | 155 | |
156 | - return apply_filters( 'wpinv_gateway_checkout_label', $label, $gateway ); |
|
156 | + return apply_filters('wpinv_gateway_checkout_label', $label, $gateway); |
|
157 | 157 | } |
158 | 158 | |
159 | -function wpinv_settings_sections_gateways( $settings ) { |
|
159 | +function wpinv_settings_sections_gateways($settings) { |
|
160 | 160 | $gateways = wpinv_get_payment_gateways(); |
161 | 161 | |
162 | 162 | if (!empty($gateways)) { |
163 | - foreach ($gateways as $key => $gateway) { |
|
163 | + foreach ($gateways as $key => $gateway) { |
|
164 | 164 | $settings[$key] = $gateway['admin_label']; |
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | 168 | return $settings; |
169 | 169 | } |
170 | -add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 ); |
|
170 | +add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1); |
|
171 | 171 | |
172 | -function wpinv_settings_gateways( $settings ) { |
|
172 | +function wpinv_settings_gateways($settings) { |
|
173 | 173 | $gateways = wpinv_get_payment_gateways(); |
174 | 174 | |
175 | 175 | if (!empty($gateways)) { |
176 | - foreach ($gateways as $key => $gateway) { |
|
176 | + foreach ($gateways as $key => $gateway) { |
|
177 | 177 | $setting = array(); |
178 | 178 | $setting[$key . '_header'] = array( |
179 | 179 | 'id' => 'gateway_header', |
180 | - 'name' => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>', |
|
180 | + 'name' => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>', |
|
181 | 181 | 'custom' => $key, |
182 | 182 | 'type' => 'gateway_header', |
183 | 183 | ); |
184 | 184 | $setting[$key . '_active'] = array( |
185 | 185 | 'id' => $key . '_active', |
186 | - 'name' => __( 'Active', 'invoicing' ), |
|
187 | - 'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ), |
|
186 | + 'name' => __('Active', 'invoicing'), |
|
187 | + 'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']), |
|
188 | 188 | 'type' => 'checkbox', |
189 | 189 | ); |
190 | 190 | |
191 | 191 | $setting[$key . '_title'] = array( |
192 | 192 | 'id' => $key . '_title', |
193 | - 'name' => __( 'Title', 'invoicing' ), |
|
194 | - 'desc' => __( 'This controls the title which the user sees during checkout.', 'invoicing' ), |
|
193 | + 'name' => __('Title', 'invoicing'), |
|
194 | + 'desc' => __('This controls the title which the user sees during checkout.', 'invoicing'), |
|
195 | 195 | 'type' => 'text', |
196 | 196 | 'std' => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : '' |
197 | 197 | ); |
198 | 198 | |
199 | 199 | $setting[$key . '_desc'] = array( |
200 | 200 | 'id' => $key . '_desc', |
201 | - 'name' => __( 'Description', 'invoicing' ), |
|
202 | - 'desc' => __( 'This controls the description which the user sees during checkout.', 'invoicing' ), |
|
201 | + 'name' => __('Description', 'invoicing'), |
|
202 | + 'desc' => __('This controls the description which the user sees during checkout.', 'invoicing'), |
|
203 | 203 | 'type' => 'text', |
204 | 204 | 'size' => 'large' |
205 | 205 | ); |
206 | 206 | |
207 | 207 | $setting[$key . '_ordering'] = array( |
208 | 208 | 'id' => $key . '_ordering', |
209 | - 'name' => __( 'Display Order', 'invoicing' ), |
|
209 | + 'name' => __('Display Order', 'invoicing'), |
|
210 | 210 | 'type' => 'number', |
211 | 211 | 'size' => 'small', |
212 | 212 | 'std' => isset($gateway['ordering']) ? $gateway['ordering'] : '10', |
@@ -215,8 +215,8 @@ discard block |
||
215 | 215 | 'step' => '1' |
216 | 216 | ); |
217 | 217 | |
218 | - $setting = apply_filters( 'wpinv_gateway_settings', $setting, $key ); |
|
219 | - $setting = apply_filters( 'wpinv_gateway_settings_' . $key, $setting ); |
|
218 | + $setting = apply_filters('wpinv_gateway_settings', $setting, $key); |
|
219 | + $setting = apply_filters('wpinv_gateway_settings_' . $key, $setting); |
|
220 | 220 | |
221 | 221 | $settings[$key] = $setting; |
222 | 222 | } |
@@ -224,106 +224,106 @@ discard block |
||
224 | 224 | |
225 | 225 | return $settings; |
226 | 226 | } |
227 | -add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 ); |
|
227 | +add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1); |
|
228 | 228 | |
229 | -function wpinv_gateway_header_callback( $args ) { |
|
230 | - echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />'; |
|
229 | +function wpinv_gateway_header_callback($args) { |
|
230 | + echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />'; |
|
231 | 231 | } |
232 | 232 | |
233 | -function wpinv_get_gateway_supports( $gateway ) { |
|
233 | +function wpinv_get_gateway_supports($gateway) { |
|
234 | 234 | $gateways = wpinv_get_enabled_payment_gateways(); |
235 | - $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array(); |
|
236 | - return apply_filters( 'wpinv_gateway_supports', $supports, $gateway ); |
|
235 | + $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array(); |
|
236 | + return apply_filters('wpinv_gateway_supports', $supports, $gateway); |
|
237 | 237 | } |
238 | 238 | |
239 | -function wpinv_gateway_supports_buy_now( $gateway ) { |
|
240 | - $supports = wpinv_get_gateway_supports( $gateway ); |
|
241 | - $ret = in_array( 'buy_now', $supports ); |
|
242 | - return apply_filters( 'wpinv_gateway_supports_buy_now', $ret, $gateway ); |
|
239 | +function wpinv_gateway_supports_buy_now($gateway) { |
|
240 | + $supports = wpinv_get_gateway_supports($gateway); |
|
241 | + $ret = in_array('buy_now', $supports); |
|
242 | + return apply_filters('wpinv_gateway_supports_buy_now', $ret, $gateway); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | function wpinv_shop_supports_buy_now() { |
246 | 246 | $gateways = wpinv_get_enabled_payment_gateways(); |
247 | 247 | $ret = false; |
248 | 248 | |
249 | - if ( !wpinv_use_taxes() && $gateways ) { |
|
250 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
251 | - if ( wpinv_gateway_supports_buy_now( $gateway_id ) ) { |
|
249 | + if (!wpinv_use_taxes() && $gateways) { |
|
250 | + foreach ($gateways as $gateway_id => $gateway) { |
|
251 | + if (wpinv_gateway_supports_buy_now($gateway_id)) { |
|
252 | 252 | $ret = true; |
253 | 253 | break; |
254 | 254 | } |
255 | 255 | } |
256 | 256 | } |
257 | 257 | |
258 | - return apply_filters( 'wpinv_shop_supports_buy_now', $ret ); |
|
258 | + return apply_filters('wpinv_shop_supports_buy_now', $ret); |
|
259 | 259 | } |
260 | 260 | |
261 | -function wpinv_send_to_gateway( $gateway, $payment_data ) { |
|
262 | - $payment_data['gateway_nonce'] = wp_create_nonce( 'wpi-gateway' ); |
|
261 | +function wpinv_send_to_gateway($gateway, $payment_data) { |
|
262 | + $payment_data['gateway_nonce'] = wp_create_nonce('wpi-gateway'); |
|
263 | 263 | |
264 | 264 | // $gateway must match the ID used when registering the gateway |
265 | - do_action( 'wpinv_gateway_' . $gateway, $payment_data ); |
|
265 | + do_action('wpinv_gateway_' . $gateway, $payment_data); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | function wpinv_show_gateways() { |
269 | 269 | $gateways = wpinv_get_enabled_payment_gateways(); |
270 | 270 | $show_gateways = false; |
271 | 271 | |
272 | - $chosen_gateway = isset( $_GET['payment-mode'] ) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode'] ) : false; |
|
272 | + $chosen_gateway = isset($_GET['payment-mode']) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode']) : false; |
|
273 | 273 | |
274 | - if ( count( $gateways ) > 1 && empty( $chosen_gateway ) ) { |
|
274 | + if (count($gateways) > 1 && empty($chosen_gateway)) { |
|
275 | 275 | $show_gateways = true; |
276 | - if ( wpinv_get_cart_total() <= 0 ) { |
|
276 | + if (wpinv_get_cart_total() <= 0) { |
|
277 | 277 | $show_gateways = false; |
278 | 278 | } |
279 | 279 | } |
280 | 280 | |
281 | - if ( !$show_gateways && wpinv_cart_has_recurring_item() ) { |
|
281 | + if (!$show_gateways && wpinv_cart_has_recurring_item()) { |
|
282 | 282 | $show_gateways = true; |
283 | 283 | } |
284 | 284 | |
285 | - return apply_filters( 'wpinv_show_gateways', $show_gateways ); |
|
285 | + return apply_filters('wpinv_show_gateways', $show_gateways); |
|
286 | 286 | } |
287 | 287 | |
288 | -function wpinv_get_chosen_gateway( $invoice_id = 0 ) { |
|
289 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
288 | +function wpinv_get_chosen_gateway($invoice_id = 0) { |
|
289 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
290 | 290 | |
291 | 291 | $chosen = false; |
292 | - if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
292 | + if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) { |
|
293 | 293 | $chosen = $invoice->get_gateway(); |
294 | 294 | } |
295 | 295 | |
296 | - $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
296 | + $chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen; |
|
297 | 297 | |
298 | - if ( false !== $chosen ) { |
|
299 | - $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
298 | + if (false !== $chosen) { |
|
299 | + $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen); |
|
300 | 300 | } |
301 | 301 | |
302 | - if ( ! empty ( $chosen ) ) { |
|
303 | - $enabled_gateway = urldecode( $chosen ); |
|
304 | - } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
302 | + if (!empty ($chosen)) { |
|
303 | + $enabled_gateway = urldecode($chosen); |
|
304 | + } else if (!empty($invoice) && (float)$invoice->get_subtotal() <= 0) { |
|
305 | 305 | $enabled_gateway = 'manual'; |
306 | 306 | } else { |
307 | 307 | $enabled_gateway = wpinv_get_default_gateway(); |
308 | 308 | } |
309 | 309 | |
310 | - if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) { |
|
311 | - if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){ |
|
310 | + if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) { |
|
311 | + if (wpinv_is_gateway_active(wpinv_get_default_gateway())) { |
|
312 | 312 | $enabled_gateway = wpinv_get_default_gateway(); |
313 | - }else{ |
|
313 | + } else { |
|
314 | 314 | $enabled_gateway = $gateways[0]; |
315 | 315 | } |
316 | 316 | |
317 | 317 | } |
318 | 318 | |
319 | - return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
319 | + return apply_filters('wpinv_chosen_gateway', $enabled_gateway); |
|
320 | 320 | } |
321 | 321 | |
322 | -function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) { |
|
323 | - return wpinv_error_log( $message, $title ); |
|
322 | +function wpinv_record_gateway_error($title = '', $message = '', $parent = 0) { |
|
323 | + return wpinv_error_log($message, $title); |
|
324 | 324 | } |
325 | 325 | |
326 | -function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) { |
|
326 | +function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') { |
|
327 | 327 | $ret = 0; |
328 | 328 | $args = array( |
329 | 329 | 'meta_key' => '_wpinv_gateway', |
@@ -334,48 +334,48 @@ discard block |
||
334 | 334 | 'fields' => 'ids' |
335 | 335 | ); |
336 | 336 | |
337 | - $payments = new WP_Query( $args ); |
|
337 | + $payments = new WP_Query($args); |
|
338 | 338 | |
339 | - if( $payments ) |
|
339 | + if ($payments) |
|
340 | 340 | $ret = $payments->post_count; |
341 | 341 | return $ret; |
342 | 342 | } |
343 | 343 | |
344 | -function wpinv_settings_update_gateways( $input ) { |
|
344 | +function wpinv_settings_update_gateways($input) { |
|
345 | 345 | global $wpinv_options; |
346 | 346 | |
347 | - if ( !empty( $input['save_gateway'] ) ) { |
|
348 | - $gateways = wpinv_get_option( 'gateways', false ); |
|
347 | + if (!empty($input['save_gateway'])) { |
|
348 | + $gateways = wpinv_get_option('gateways', false); |
|
349 | 349 | $gateways = !empty($gateways) ? $gateways : array(); |
350 | 350 | $gateway = $input['save_gateway']; |
351 | 351 | |
352 | - if ( !empty( $input[$gateway . '_active'] ) ) { |
|
352 | + if (!empty($input[$gateway . '_active'])) { |
|
353 | 353 | $gateways[$gateway] = 1; |
354 | 354 | } else { |
355 | - if ( isset( $gateways[$gateway] ) ) { |
|
356 | - unset( $gateways[$gateway] ); |
|
355 | + if (isset($gateways[$gateway])) { |
|
356 | + unset($gateways[$gateway]); |
|
357 | 357 | } |
358 | 358 | } |
359 | 359 | |
360 | 360 | $input['gateways'] = $gateways; |
361 | 361 | } |
362 | 362 | |
363 | - if ( !empty( $input['default_gateway'] ) ) { |
|
363 | + if (!empty($input['default_gateway'])) { |
|
364 | 364 | $gateways = wpinv_get_payment_gateways(); |
365 | 365 | |
366 | - foreach ( $gateways as $key => $gateway ) { |
|
367 | - $active = 0; |
|
368 | - if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) { |
|
366 | + foreach ($gateways as $key => $gateway) { |
|
367 | + $active = 0; |
|
368 | + if (!empty($input['gateways']) && !empty($input['gateways'][$key])) { |
|
369 | 369 | $active = 1; |
370 | 370 | } |
371 | 371 | |
372 | 372 | $input[$key . '_active'] = $active; |
373 | 373 | |
374 | - if ( empty( $wpinv_options[$key . '_title'] ) ) { |
|
374 | + if (empty($wpinv_options[$key . '_title'])) { |
|
375 | 375 | $input[$key . '_title'] = $gateway['checkout_label']; |
376 | 376 | } |
377 | 377 | |
378 | - if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) { |
|
378 | + if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) { |
|
379 | 379 | $input[$key . '_ordering'] = $gateway['ordering']; |
380 | 380 | } |
381 | 381 | } |
@@ -383,26 +383,26 @@ discard block |
||
383 | 383 | |
384 | 384 | return $input; |
385 | 385 | } |
386 | -add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 ); |
|
386 | +add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1); |
|
387 | 387 | |
388 | 388 | // PayPal Standard settings |
389 | -function wpinv_gateway_settings_paypal( $setting ) { |
|
390 | - $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
|
389 | +function wpinv_gateway_settings_paypal($setting) { |
|
390 | + $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing'); |
|
391 | 391 | |
392 | 392 | $setting['paypal_sandbox'] = array( |
393 | 393 | 'type' => 'checkbox', |
394 | 394 | 'id' => 'paypal_sandbox', |
395 | - 'name' => __( 'PayPal Sandbox', 'invoicing' ), |
|
396 | - 'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ), |
|
395 | + 'name' => __('PayPal Sandbox', 'invoicing'), |
|
396 | + 'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'), |
|
397 | 397 | 'std' => 1 |
398 | 398 | ); |
399 | 399 | |
400 | 400 | $setting['paypal_email'] = array( |
401 | 401 | 'type' => 'text', |
402 | 402 | 'id' => 'paypal_email', |
403 | - 'name' => __( 'PayPal Email', 'invoicing' ), |
|
404 | - 'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ), |
|
405 | - 'std' => __( '[email protected]', 'invoicing' ), |
|
403 | + 'name' => __('PayPal Email', 'invoicing'), |
|
404 | + 'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'), |
|
405 | + 'std' => __('[email protected]', 'invoicing'), |
|
406 | 406 | ); |
407 | 407 | /* |
408 | 408 | $setting['paypal_ipn_url'] = array( |
@@ -416,116 +416,116 @@ discard block |
||
416 | 416 | |
417 | 417 | return $setting; |
418 | 418 | } |
419 | -add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 ); |
|
419 | +add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1); |
|
420 | 420 | |
421 | 421 | // Pre Bank Transfer settings |
422 | -function wpinv_gateway_settings_bank_transfer( $setting ) { |
|
423 | - $setting['bank_transfer_desc']['std'] = __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ); |
|
422 | +function wpinv_gateway_settings_bank_transfer($setting) { |
|
423 | + $setting['bank_transfer_desc']['std'] = __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'); |
|
424 | 424 | |
425 | 425 | $setting['bank_transfer_ac_name'] = array( |
426 | 426 | 'type' => 'text', |
427 | 427 | 'id' => 'bank_transfer_ac_name', |
428 | - 'name' => __( 'Account Name', 'invoicing' ), |
|
429 | - 'desc' => __( 'Enter the bank account name to which you want to transfer payment.', 'invoicing' ), |
|
430 | - 'std' => __( 'Mr. John Martin', 'invoicing' ), |
|
428 | + 'name' => __('Account Name', 'invoicing'), |
|
429 | + 'desc' => __('Enter the bank account name to which you want to transfer payment.', 'invoicing'), |
|
430 | + 'std' => __('Mr. John Martin', 'invoicing'), |
|
431 | 431 | ); |
432 | 432 | |
433 | 433 | $setting['bank_transfer_ac_no'] = array( |
434 | 434 | 'type' => 'text', |
435 | 435 | 'id' => 'bank_transfer_ac_no', |
436 | - 'name' => __( 'Account Number', 'invoicing' ), |
|
437 | - 'desc' => __( 'Enter your bank account number.', 'invoicing' ), |
|
438 | - 'std' => __( 'TEST1234567890', 'invoicing' ), |
|
436 | + 'name' => __('Account Number', 'invoicing'), |
|
437 | + 'desc' => __('Enter your bank account number.', 'invoicing'), |
|
438 | + 'std' => __('TEST1234567890', 'invoicing'), |
|
439 | 439 | ); |
440 | 440 | |
441 | 441 | $setting['bank_transfer_bank_name'] = array( |
442 | 442 | 'type' => 'text', |
443 | 443 | 'id' => 'bank_transfer_bank_name', |
444 | - 'name' => __( 'Bank Name', 'invoicing' ), |
|
445 | - 'desc' => __( 'Enter the bank name to which you want to transfer payment.', 'invoicing' ), |
|
446 | - 'std' => __( 'ICICI Bank', 'invoicing' ), |
|
444 | + 'name' => __('Bank Name', 'invoicing'), |
|
445 | + 'desc' => __('Enter the bank name to which you want to transfer payment.', 'invoicing'), |
|
446 | + 'std' => __('ICICI Bank', 'invoicing'), |
|
447 | 447 | ); |
448 | 448 | |
449 | 449 | $setting['bank_transfer_ifsc'] = array( |
450 | 450 | 'type' => 'text', |
451 | 451 | 'id' => 'bank_transfer_ifsc', |
452 | - 'name' => __( 'IFSC code', 'invoicing' ), |
|
453 | - 'desc' => __( 'Enter your bank IFSC code.', 'invoicing' ), |
|
454 | - 'std' => __( 'ICIC0001234', 'invoicing' ), |
|
452 | + 'name' => __('IFSC code', 'invoicing'), |
|
453 | + 'desc' => __('Enter your bank IFSC code.', 'invoicing'), |
|
454 | + 'std' => __('ICIC0001234', 'invoicing'), |
|
455 | 455 | ); |
456 | 456 | |
457 | 457 | $setting['bank_transfer_iban'] = array( |
458 | 458 | 'type' => 'text', |
459 | 459 | 'id' => 'bank_transfer_iban', |
460 | - 'name' => __( 'IBAN', 'invoicing' ), |
|
461 | - 'desc' => __( 'Enter your International Bank Account Number(IBAN).', 'invoicing' ), |
|
462 | - 'std' => __( 'GB29NWBK60161331926819', 'invoicing' ), |
|
460 | + 'name' => __('IBAN', 'invoicing'), |
|
461 | + 'desc' => __('Enter your International Bank Account Number(IBAN).', 'invoicing'), |
|
462 | + 'std' => __('GB29NWBK60161331926819', 'invoicing'), |
|
463 | 463 | ); |
464 | 464 | |
465 | 465 | $setting['bank_transfer_bic'] = array( |
466 | 466 | 'type' => 'text', |
467 | 467 | 'id' => 'bank_transfer_bic', |
468 | - 'name' => __( 'BIC/Swift code', 'invoicing' ), |
|
469 | - 'std' => __( 'ICICGB2L129', 'invoicing' ), |
|
468 | + 'name' => __('BIC/Swift code', 'invoicing'), |
|
469 | + 'std' => __('ICICGB2L129', 'invoicing'), |
|
470 | 470 | ); |
471 | 471 | |
472 | 472 | $setting['bank_transfer_info'] = array( |
473 | 473 | 'id' => 'bank_transfer_info', |
474 | - 'name' => __( 'Instructions', 'invoicing' ), |
|
475 | - 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
|
474 | + 'name' => __('Instructions', 'invoicing'), |
|
475 | + 'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'), |
|
476 | 476 | 'type' => 'textarea', |
477 | - 'std' => __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ), |
|
477 | + 'std' => __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'), |
|
478 | 478 | 'cols' => 37, |
479 | 479 | 'rows' => 5 |
480 | 480 | ); |
481 | 481 | |
482 | 482 | return $setting; |
483 | 483 | } |
484 | -add_filter( 'wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1 ); |
|
484 | +add_filter('wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1); |
|
485 | 485 | |
486 | 486 | // Authorize.Net settings |
487 | -function wpinv_gateway_settings_authorizenet( $setting ) { |
|
488 | - $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __( '( currencies supported: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing' ); |
|
489 | - $setting['authorizenet_desc']['std'] = __( 'Pay using a Authorize.Net to process credit card / debit card transactions.', 'invoicing' ); |
|
487 | +function wpinv_gateway_settings_authorizenet($setting) { |
|
488 | + $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __('( currencies supported: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing'); |
|
489 | + $setting['authorizenet_desc']['std'] = __('Pay using a Authorize.Net to process credit card / debit card transactions.', 'invoicing'); |
|
490 | 490 | |
491 | 491 | $setting['authorizenet_sandbox'] = array( |
492 | 492 | 'type' => 'checkbox', |
493 | 493 | 'id' => 'authorizenet_sandbox', |
494 | - 'name' => __( 'Authorize.Net Test Mode', 'invoicing' ), |
|
495 | - 'desc' => __( 'Enable Authorize.Net test mode to test payments.', 'invoicing' ), |
|
494 | + 'name' => __('Authorize.Net Test Mode', 'invoicing'), |
|
495 | + 'desc' => __('Enable Authorize.Net test mode to test payments.', 'invoicing'), |
|
496 | 496 | 'std' => 1 |
497 | 497 | ); |
498 | 498 | |
499 | 499 | $setting['authorizenet_login_id'] = array( |
500 | 500 | 'type' => 'text', |
501 | 501 | 'id' => 'authorizenet_login_id', |
502 | - 'name' => __( 'API Login ID', 'invoicing' ), |
|
503 | - 'desc' => __( 'API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing' ), |
|
502 | + 'name' => __('API Login ID', 'invoicing'), |
|
503 | + 'desc' => __('API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing'), |
|
504 | 504 | 'std' => '2j4rBekUnD', |
505 | 505 | ); |
506 | 506 | |
507 | 507 | $setting['authorizenet_transaction_key'] = array( |
508 | 508 | 'type' => 'text', |
509 | 509 | 'id' => 'authorizenet_transaction_key', |
510 | - 'name' => __( 'Transaction Key', 'invoicing' ), |
|
511 | - 'desc' => __( 'Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing' ), |
|
510 | + 'name' => __('Transaction Key', 'invoicing'), |
|
511 | + 'desc' => __('Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing'), |
|
512 | 512 | 'std' => '4vyBUOJgR74679xa', |
513 | 513 | ); |
514 | 514 | |
515 | 515 | $setting['authorizenet_md5_hash'] = array( |
516 | 516 | 'type' => 'text', |
517 | 517 | 'id' => 'authorizenet_md5_hash', |
518 | - 'name' => __( 'MD5-Hash', 'invoicing' ), |
|
519 | - 'desc' => __( 'The MD5 Hash security feature allows you to authenticate transaction responses from the Authorize.Net. If you are accepting recurring payments then md5 hash will helps to validate response from Authorize.net. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing' ), |
|
518 | + 'name' => __('MD5-Hash', 'invoicing'), |
|
519 | + 'desc' => __('The MD5 Hash security feature allows you to authenticate transaction responses from the Authorize.Net. If you are accepting recurring payments then md5 hash will helps to validate response from Authorize.net. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing'), |
|
520 | 520 | 'std' => '', |
521 | 521 | ); |
522 | 522 | |
523 | 523 | $setting['authorizenet_ipn_url'] = array( |
524 | 524 | 'type' => 'ipn_url', |
525 | 525 | 'id' => 'authorizenet_ipn_url', |
526 | - 'name' => __( 'Silent Post URL', 'invoicing' ), |
|
527 | - 'std' => wpinv_get_ipn_url( 'authorizenet' ), |
|
528 | - 'desc' => __( 'If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing' ), |
|
526 | + 'name' => __('Silent Post URL', 'invoicing'), |
|
527 | + 'std' => wpinv_get_ipn_url('authorizenet'), |
|
528 | + 'desc' => __('If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing'), |
|
529 | 529 | 'size' => 'large', |
530 | 530 | 'custom' => 'authorizenet', |
531 | 531 | 'readonly' => true |
@@ -533,25 +533,25 @@ discard block |
||
533 | 533 | |
534 | 534 | return $setting; |
535 | 535 | } |
536 | -add_filter( 'wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1 ); |
|
536 | +add_filter('wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1); |
|
537 | 537 | |
538 | 538 | // Worldpay settings |
539 | -function wpinv_gateway_settings_worldpay( $setting ) { |
|
540 | - $setting['worldpay_desc']['std'] = __( 'Pay using a Worldpay account to process credit card / debit card transactions.', 'invoicing' ); |
|
539 | +function wpinv_gateway_settings_worldpay($setting) { |
|
540 | + $setting['worldpay_desc']['std'] = __('Pay using a Worldpay account to process credit card / debit card transactions.', 'invoicing'); |
|
541 | 541 | |
542 | 542 | $setting['worldpay_sandbox'] = array( |
543 | 543 | 'type' => 'checkbox', |
544 | 544 | 'id' => 'worldpay_sandbox', |
545 | - 'name' => __( 'Worldpay Test Mode', 'invoicing' ), |
|
546 | - 'desc' => __( 'This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing' ), |
|
545 | + 'name' => __('Worldpay Test Mode', 'invoicing'), |
|
546 | + 'desc' => __('This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing'), |
|
547 | 547 | 'std' => 1 |
548 | 548 | ); |
549 | 549 | |
550 | 550 | $setting['worldpay_instId'] = array( |
551 | 551 | 'type' => 'text', |
552 | 552 | 'id' => 'worldpay_instId', |
553 | - 'name' => __( 'Installation Id', 'invoicing' ), |
|
554 | - 'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ), |
|
553 | + 'name' => __('Installation Id', 'invoicing'), |
|
554 | + 'desc' => __('Your installation id. Ex: 211616', 'invoicing'), |
|
555 | 555 | 'std' => '211616', |
556 | 556 | ); |
557 | 557 | /* |
@@ -567,9 +567,9 @@ discard block |
||
567 | 567 | $setting['worldpay_ipn_url'] = array( |
568 | 568 | 'type' => 'ipn_url', |
569 | 569 | 'id' => 'worldpay_ipn_url', |
570 | - 'name' => __( 'Worldpay Callback Url', 'invoicing' ), |
|
571 | - 'std' => wpinv_get_ipn_url( 'worldpay' ), |
|
572 | - 'desc' => wp_sprintf( __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing' ), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url( 'worldpay' ) . '</font>', '<font style="color:#000;font-style:normal"><wpdisplay item=MC_callback></font>' ), |
|
570 | + 'name' => __('Worldpay Callback Url', 'invoicing'), |
|
571 | + 'std' => wpinv_get_ipn_url('worldpay'), |
|
572 | + 'desc' => wp_sprintf(__('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing'), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url('worldpay') . '</font>', '<font style="color:#000;font-style:normal"><wpdisplay item=MC_callback></font>'), |
|
573 | 573 | 'size' => 'large', |
574 | 574 | 'custom' => 'worldpay', |
575 | 575 | 'readonly' => true |
@@ -577,94 +577,94 @@ discard block |
||
577 | 577 | |
578 | 578 | return $setting; |
579 | 579 | } |
580 | -add_filter( 'wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1 ); |
|
580 | +add_filter('wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1); |
|
581 | 581 | |
582 | -function wpinv_ipn_url_callback( $args ) { |
|
583 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
582 | +function wpinv_ipn_url_callback($args) { |
|
583 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
584 | 584 | |
585 | 585 | $attrs = $args['readonly'] ? ' readonly' : ''; |
586 | 586 | |
587 | - $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">'; |
|
588 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
587 | + $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">'; |
|
588 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
589 | 589 | |
590 | 590 | echo $html; |
591 | 591 | } |
592 | 592 | |
593 | -function wpinv_is_test_mode( $gateway = '' ) { |
|
594 | - if ( empty( $gateway ) ) { |
|
593 | +function wpinv_is_test_mode($gateway = '') { |
|
594 | + if (empty($gateway)) { |
|
595 | 595 | return false; |
596 | 596 | } |
597 | 597 | |
598 | - $is_test_mode = wpinv_get_option( $gateway . '_sandbox', false ); |
|
598 | + $is_test_mode = wpinv_get_option($gateway . '_sandbox', false); |
|
599 | 599 | |
600 | - return apply_filters( 'wpinv_is_test_mode', $is_test_mode, $gateway ); |
|
600 | + return apply_filters('wpinv_is_test_mode', $is_test_mode, $gateway); |
|
601 | 601 | } |
602 | 602 | |
603 | -function wpinv_get_ipn_url( $gateway = '', $args = array() ) { |
|
604 | - $data = array( 'wpi-listener' => 'IPN' ); |
|
603 | +function wpinv_get_ipn_url($gateway = '', $args = array()) { |
|
604 | + $data = array('wpi-listener' => 'IPN'); |
|
605 | 605 | |
606 | - if ( !empty( $gateway ) ) { |
|
607 | - $data['wpi-gateway'] = wpinv_sanitize_key( $gateway ); |
|
606 | + if (!empty($gateway)) { |
|
607 | + $data['wpi-gateway'] = wpinv_sanitize_key($gateway); |
|
608 | 608 | } |
609 | 609 | |
610 | - $args = !empty( $args ) && is_array( $args ) ? array_merge( $data, $args ) : $data; |
|
610 | + $args = !empty($args) && is_array($args) ? array_merge($data, $args) : $data; |
|
611 | 611 | |
612 | - $ipn_url = add_query_arg( $args, home_url( 'index.php' ) ); |
|
612 | + $ipn_url = add_query_arg($args, home_url('index.php')); |
|
613 | 613 | |
614 | - return apply_filters( 'wpinv_ipn_url', $ipn_url ); |
|
614 | + return apply_filters('wpinv_ipn_url', $ipn_url); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | function wpinv_listen_for_payment_ipn() { |
618 | 618 | // Regular PayPal IPN |
619 | - if ( isset( $_GET['wpi-listener'] ) && $_GET['wpi-listener'] == 'IPN' ) { |
|
620 | - do_action( 'wpinv_verify_payment_ipn' ); |
|
619 | + if (isset($_GET['wpi-listener']) && $_GET['wpi-listener'] == 'IPN') { |
|
620 | + do_action('wpinv_verify_payment_ipn'); |
|
621 | 621 | |
622 | - if ( !empty( $_GET['wpi-gateway'] ) ) { |
|
623 | - wpinv_error_log( sanitize_text_field( $_GET['wpi-gateway'] ), 'wpinv_listen_for_payment_ipn()', __FILE__, __LINE__ ); |
|
624 | - do_action( 'wpinv_verify_' . sanitize_text_field( $_GET['wpi-gateway'] ) . '_ipn' ); |
|
622 | + if (!empty($_GET['wpi-gateway'])) { |
|
623 | + wpinv_error_log(sanitize_text_field($_GET['wpi-gateway']), 'wpinv_listen_for_payment_ipn()', __FILE__, __LINE__); |
|
624 | + do_action('wpinv_verify_' . sanitize_text_field($_GET['wpi-gateway']) . '_ipn'); |
|
625 | 625 | } |
626 | 626 | } |
627 | 627 | } |
628 | -add_action( 'init', 'wpinv_listen_for_payment_ipn' ); |
|
628 | +add_action('init', 'wpinv_listen_for_payment_ipn'); |
|
629 | 629 | |
630 | 630 | function wpinv_get_bank_instructions() { |
631 | - $bank_instructions = wpinv_get_option( 'bank_transfer_info' ); |
|
631 | + $bank_instructions = wpinv_get_option('bank_transfer_info'); |
|
632 | 632 | |
633 | - return apply_filters( 'wpinv_bank_instructions', $bank_instructions ); |
|
633 | + return apply_filters('wpinv_bank_instructions', $bank_instructions); |
|
634 | 634 | } |
635 | 635 | |
636 | -function wpinv_get_bank_info( $filtered = false ) { |
|
636 | +function wpinv_get_bank_info($filtered = false) { |
|
637 | 637 | $bank_fields = array( |
638 | - 'bank_transfer_ac_name' => __( 'Account Name', 'invoicing' ), |
|
639 | - 'bank_transfer_ac_no' => __( 'Account Number', 'invoicing' ), |
|
640 | - 'bank_transfer_bank_name' => __( 'Bank Name', 'invoicing' ), |
|
641 | - 'bank_transfer_ifsc' => __( 'IFSC code', 'invoicing' ), |
|
642 | - 'bank_transfer_iban' => __( 'IBAN', 'invoicing' ), |
|
643 | - 'bank_transfer_bic' => __( 'BIC/Swift code', 'invoicing' ) |
|
638 | + 'bank_transfer_ac_name' => __('Account Name', 'invoicing'), |
|
639 | + 'bank_transfer_ac_no' => __('Account Number', 'invoicing'), |
|
640 | + 'bank_transfer_bank_name' => __('Bank Name', 'invoicing'), |
|
641 | + 'bank_transfer_ifsc' => __('IFSC code', 'invoicing'), |
|
642 | + 'bank_transfer_iban' => __('IBAN', 'invoicing'), |
|
643 | + 'bank_transfer_bic' => __('BIC/Swift code', 'invoicing') |
|
644 | 644 | ); |
645 | 645 | |
646 | 646 | $bank_info = array(); |
647 | - foreach ( $bank_fields as $field => $label ) { |
|
648 | - if ( $filtered && !( $value = wpinv_get_option( $field ) ) ) { |
|
647 | + foreach ($bank_fields as $field => $label) { |
|
648 | + if ($filtered && !($value = wpinv_get_option($field))) { |
|
649 | 649 | continue; |
650 | 650 | } |
651 | 651 | |
652 | - $bank_info[$field] = array( 'label' => $label, 'value' => $value ); |
|
652 | + $bank_info[$field] = array('label' => $label, 'value' => $value); |
|
653 | 653 | } |
654 | 654 | |
655 | - return apply_filters( 'wpinv_bank_info', $bank_info, $filtered ); |
|
655 | + return apply_filters('wpinv_bank_info', $bank_info, $filtered); |
|
656 | 656 | } |
657 | 657 | |
658 | -function wpinv_process_before_send_to_gateway( $invoice, $invoice_data = array() ) { |
|
659 | - if ( !empty( $invoice ) && $invoice->is_recurring() && $subscription_item = $invoice->get_recurring( true ) ) { |
|
658 | +function wpinv_process_before_send_to_gateway($invoice, $invoice_data = array()) { |
|
659 | + if (!empty($invoice) && $invoice->is_recurring() && $subscription_item = $invoice->get_recurring(true)) { |
|
660 | 660 | $args = array(); |
661 | 661 | $args['item_id'] = $subscription_item->ID; |
662 | - $args['initial_amount'] = wpinv_format_amount( $invoice->get_total() ); |
|
663 | - $args['recurring_amount'] = wpinv_format_amount( $invoice->get_recurring_details( 'total' ) ); |
|
662 | + $args['initial_amount'] = wpinv_format_amount($invoice->get_total()); |
|
663 | + $args['recurring_amount'] = wpinv_format_amount($invoice->get_recurring_details('total')); |
|
664 | 664 | $args['currency'] = $invoice->get_currency(); |
665 | 665 | $args['period'] = $subscription_item->get_recurring_period(); |
666 | 666 | $args['interval'] = $subscription_item->get_recurring_interval(); |
667 | - if ( $subscription_item->has_free_trial() ) { |
|
667 | + if ($subscription_item->has_free_trial()) { |
|
668 | 668 | $args['trial_period'] = $subscription_item->get_trial_period(); |
669 | 669 | $args['trial_interval'] = $subscription_item->get_trial_interval(); |
670 | 670 | } else { |
@@ -673,25 +673,25 @@ discard block |
||
673 | 673 | } |
674 | 674 | $args['bill_times'] = (int)$subscription_item->get_recurring_limit(); |
675 | 675 | |
676 | - $invoice->update_subscription( $args ); |
|
676 | + $invoice->update_subscription($args); |
|
677 | 677 | } |
678 | 678 | } |
679 | -add_action( 'wpinv_checkout_before_send_to_gateway', 'wpinv_process_before_send_to_gateway', 10, 2 ); |
|
679 | +add_action('wpinv_checkout_before_send_to_gateway', 'wpinv_process_before_send_to_gateway', 10, 2); |
|
680 | 680 | |
681 | -function wpinv_get_post_data( $method = 'request' ) { |
|
681 | +function wpinv_get_post_data($method = 'request') { |
|
682 | 682 | $data = array(); |
683 | 683 | $request = $_REQUEST; |
684 | 684 | |
685 | - if ( $method == 'post' ) { |
|
686 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
685 | + if ($method == 'post') { |
|
686 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
687 | 687 | return $data; |
688 | 688 | } |
689 | 689 | |
690 | 690 | $request = $_POST; |
691 | 691 | } |
692 | 692 | |
693 | - if ( $method == 'get' ) { |
|
694 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET' ) { |
|
693 | + if ($method == 'get') { |
|
694 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET') { |
|
695 | 695 | return $data; |
696 | 696 | } |
697 | 697 | |
@@ -702,11 +702,11 @@ discard block |
||
702 | 702 | $post_data = ''; |
703 | 703 | |
704 | 704 | // Fallback just in case post_max_size is lower than needed |
705 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
706 | - $post_data = file_get_contents( 'php://input' ); |
|
705 | + if (ini_get('allow_url_fopen')) { |
|
706 | + $post_data = file_get_contents('php://input'); |
|
707 | 707 | } else { |
708 | 708 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
709 | - ini_set( 'post_max_size', '12M' ); |
|
709 | + ini_set('post_max_size', '12M'); |
|
710 | 710 | } |
711 | 711 | // Start the encoded data collection with notification command |
712 | 712 | $encoded_data = 'cmd=_notify-validate'; |
@@ -715,58 +715,58 @@ discard block |
||
715 | 715 | $arg_separator = wpinv_get_php_arg_separator_output(); |
716 | 716 | |
717 | 717 | // Verify there is a post_data |
718 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
718 | + if ($post_data || strlen($post_data) > 0) { |
|
719 | 719 | // Append the data |
720 | 720 | $encoded_data .= $arg_separator . $post_data; |
721 | 721 | } else { |
722 | 722 | // Check if POST is empty |
723 | - if ( empty( $request ) ) { |
|
723 | + if (empty($request)) { |
|
724 | 724 | // Nothing to do |
725 | 725 | return; |
726 | 726 | } else { |
727 | 727 | // Loop through each POST |
728 | - foreach ( $request as $key => $value ) { |
|
728 | + foreach ($request as $key => $value) { |
|
729 | 729 | // Encode the value and append the data |
730 | - $encoded_data .= $arg_separator . "$key=" . urlencode( $value ); |
|
730 | + $encoded_data .= $arg_separator . "$key=" . urlencode($value); |
|
731 | 731 | } |
732 | 732 | } |
733 | 733 | } |
734 | 734 | |
735 | 735 | // Convert collected post data to an array |
736 | - parse_str( $encoded_data, $data ); |
|
736 | + parse_str($encoded_data, $data); |
|
737 | 737 | |
738 | - foreach ( $data as $key => $value ) { |
|
739 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
740 | - $new_key = str_replace( '&', '&', $key ); |
|
741 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
738 | + foreach ($data as $key => $value) { |
|
739 | + if (false !== strpos($key, 'amp;')) { |
|
740 | + $new_key = str_replace('&', '&', $key); |
|
741 | + $new_key = str_replace('amp;', '&', $new_key); |
|
742 | 742 | |
743 | - unset( $data[ $key ] ); |
|
744 | - $data[ $new_key ] = sanitize_text_field( $value ); |
|
743 | + unset($data[$key]); |
|
744 | + $data[$new_key] = sanitize_text_field($value); |
|
745 | 745 | } |
746 | 746 | } |
747 | 747 | |
748 | 748 | return $data; |
749 | 749 | } |
750 | 750 | |
751 | -function wpinv_gateway_support_subscription( $gateway ) { |
|
751 | +function wpinv_gateway_support_subscription($gateway) { |
|
752 | 752 | $return = false; |
753 | 753 | |
754 | - if ( wpinv_is_gateway_active( $gateway ) ) { |
|
755 | - $return = apply_filters( 'wpinv_' . $gateway . '_support_subscription', false ); |
|
754 | + if (wpinv_is_gateway_active($gateway)) { |
|
755 | + $return = apply_filters('wpinv_' . $gateway . '_support_subscription', false); |
|
756 | 756 | } |
757 | 757 | |
758 | 758 | return $return; |
759 | 759 | } |
760 | 760 | |
761 | -function wpinv_payment_gateways_on_cart( $gateways = array() ) { |
|
762 | - if ( !empty( $gateways ) && wpinv_cart_has_recurring_item() ) { |
|
763 | - foreach ( $gateways as $gateway => $info ) { |
|
764 | - if ( !wpinv_gateway_support_subscription( $gateway ) ) { |
|
765 | - unset( $gateways[$gateway] ); |
|
761 | +function wpinv_payment_gateways_on_cart($gateways = array()) { |
|
762 | + if (!empty($gateways) && wpinv_cart_has_recurring_item()) { |
|
763 | + foreach ($gateways as $gateway => $info) { |
|
764 | + if (!wpinv_gateway_support_subscription($gateway)) { |
|
765 | + unset($gateways[$gateway]); |
|
766 | 766 | } |
767 | 767 | } |
768 | 768 | } |
769 | 769 | |
770 | 770 | return $gateways; |
771 | 771 | } |
772 | -add_filter( 'wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1 ); |
|
773 | 772 | \ No newline at end of file |
773 | +add_filter('wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1); |
|
774 | 774 | \ No newline at end of file |
@@ -7,12 +7,12 @@ 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 | final class WPInv_Invoice { |
15 | - public $ID = 0; |
|
15 | + public $ID = 0; |
|
16 | 16 | public $title; |
17 | 17 | public $post_type; |
18 | 18 | |
@@ -65,17 +65,17 @@ discard block |
||
65 | 65 | public $full_name = ''; |
66 | 66 | public $parent_invoice = 0; |
67 | 67 | |
68 | - public function __construct( $invoice_id = false ) { |
|
69 | - if( empty( $invoice_id ) ) { |
|
68 | + public function __construct($invoice_id = false) { |
|
69 | + if (empty($invoice_id)) { |
|
70 | 70 | return false; |
71 | 71 | } |
72 | 72 | |
73 | - $this->setup_invoice( $invoice_id ); |
|
73 | + $this->setup_invoice($invoice_id); |
|
74 | 74 | } |
75 | 75 | |
76 | - public function get( $key ) { |
|
77 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
78 | - $value = call_user_func( array( $this, 'get_' . $key ) ); |
|
76 | + public function get($key) { |
|
77 | + if (method_exists($this, 'get_' . $key)) { |
|
78 | + $value = call_user_func(array($this, 'get_' . $key)); |
|
79 | 79 | } else { |
80 | 80 | $value = $this->$key; |
81 | 81 | } |
@@ -83,52 +83,52 @@ discard block |
||
83 | 83 | return $value; |
84 | 84 | } |
85 | 85 | |
86 | - public function set( $key, $value ) { |
|
87 | - $ignore = array( 'items', 'cart_details', 'fees', '_ID' ); |
|
86 | + public function set($key, $value) { |
|
87 | + $ignore = array('items', 'cart_details', 'fees', '_ID'); |
|
88 | 88 | |
89 | - if ( $key === 'status' ) { |
|
89 | + if ($key === 'status') { |
|
90 | 90 | $this->old_status = $this->status; |
91 | 91 | } |
92 | 92 | |
93 | - if ( ! in_array( $key, $ignore ) ) { |
|
94 | - $this->pending[ $key ] = $value; |
|
93 | + if (!in_array($key, $ignore)) { |
|
94 | + $this->pending[$key] = $value; |
|
95 | 95 | } |
96 | 96 | |
97 | - if( '_ID' !== $key ) { |
|
97 | + if ('_ID' !== $key) { |
|
98 | 98 | $this->$key = $value; |
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | - public function _isset( $name ) { |
|
103 | - if ( property_exists( $this, $name) ) { |
|
104 | - return false === empty( $this->$name ); |
|
102 | + public function _isset($name) { |
|
103 | + if (property_exists($this, $name)) { |
|
104 | + return false === empty($this->$name); |
|
105 | 105 | } else { |
106 | 106 | return null; |
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
110 | - private function setup_invoice( $invoice_id ) { |
|
110 | + private function setup_invoice($invoice_id) { |
|
111 | 111 | $this->pending = array(); |
112 | 112 | |
113 | - if ( empty( $invoice_id ) ) { |
|
113 | + if (empty($invoice_id)) { |
|
114 | 114 | return false; |
115 | 115 | } |
116 | 116 | |
117 | - $invoice = get_post( $invoice_id ); |
|
117 | + $invoice = get_post($invoice_id); |
|
118 | 118 | |
119 | - if( !$invoice || is_wp_error( $invoice ) ) { |
|
119 | + if (!$invoice || is_wp_error($invoice)) { |
|
120 | 120 | return false; |
121 | 121 | } |
122 | 122 | |
123 | - if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) { |
|
123 | + if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) { |
|
124 | 124 | return false; |
125 | 125 | } |
126 | 126 | |
127 | - do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id ); |
|
127 | + do_action('wpinv_pre_setup_invoice', $this, $invoice_id); |
|
128 | 128 | |
129 | 129 | // Primary Identifier |
130 | - $this->ID = absint( $invoice_id ); |
|
131 | - $this->post_type = $invoice->post_type; |
|
130 | + $this->ID = absint($invoice_id); |
|
131 | + $this->post_type = $invoice->post_type; |
|
132 | 132 | |
133 | 133 | // We have a payment, get the generic payment_meta item to reduce calls to it |
134 | 134 | $this->payment_meta = $this->get_meta(); |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $this->post_status = $this->status; |
140 | 140 | $this->mode = $this->setup_mode(); |
141 | 141 | $this->parent_invoice = $invoice->post_parent; |
142 | - $this->post_name = $this->setup_post_name( $invoice ); |
|
142 | + $this->post_name = $this->setup_post_name($invoice); |
|
143 | 143 | $this->status_nicename = $this->setup_status_nicename(); |
144 | 144 | |
145 | 145 | // Items |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | |
162 | 162 | // User based |
163 | 163 | $this->ip = $this->setup_ip(); |
164 | - $this->user_id = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id(); |
|
165 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
164 | + $this->user_id = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id(); |
|
165 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
166 | 166 | |
167 | 167 | $this->user_info = $this->setup_user_info(); |
168 | 168 | |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | $this->company = $this->user_info['company']; |
172 | 172 | $this->vat_number = $this->user_info['vat_number']; |
173 | 173 | $this->vat_rate = $this->user_info['vat_rate']; |
174 | - $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
174 | + $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
175 | 175 | $this->address = $this->user_info['address']; |
176 | 176 | $this->city = $this->user_info['city']; |
177 | 177 | $this->country = $this->user_info['country']; |
@@ -186,48 +186,48 @@ discard block |
||
186 | 186 | // Other Identifiers |
187 | 187 | $this->key = $this->setup_invoice_key(); |
188 | 188 | $this->number = $this->setup_invoice_number(); |
189 | - $this->title = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number; |
|
189 | + $this->title = !empty($invoice->post_title) ? $invoice->post_title : $this->number; |
|
190 | 190 | |
191 | - $this->full_name = trim( $this->first_name . ' '. $this->last_name ); |
|
191 | + $this->full_name = trim($this->first_name . ' ' . $this->last_name); |
|
192 | 192 | |
193 | 193 | // Allow extensions to add items to this object via hook |
194 | - do_action( 'wpinv_setup_invoice', $this, $invoice_id ); |
|
194 | + do_action('wpinv_setup_invoice', $this, $invoice_id); |
|
195 | 195 | |
196 | 196 | return true; |
197 | 197 | } |
198 | 198 | |
199 | 199 | private function setup_status_nicename() { |
200 | - $all_invoice_statuses = wpinv_get_invoice_statuses(); |
|
200 | + $all_invoice_statuses = wpinv_get_invoice_statuses(); |
|
201 | 201 | |
202 | - $status = array_key_exists( $this->status, $all_invoice_statuses ) ? $all_invoice_statuses[$this->status] : ucfirst( $this->status ); |
|
202 | + $status = array_key_exists($this->status, $all_invoice_statuses) ? $all_invoice_statuses[$this->status] : ucfirst($this->status); |
|
203 | 203 | |
204 | 204 | return $status; |
205 | 205 | } |
206 | 206 | |
207 | - private function setup_post_name( $post = NULL ) { |
|
207 | + private function setup_post_name($post = NULL) { |
|
208 | 208 | $post_name = ''; |
209 | 209 | |
210 | - if ( !empty( $post ) ) { |
|
211 | - if( !empty( $post->post_name ) ) { |
|
210 | + if (!empty($post)) { |
|
211 | + if (!empty($post->post_name)) { |
|
212 | 212 | $post_name = $post->post_name; |
213 | - } else if ( !empty( $post->ID ) && !empty( $post->post_title ) ) { |
|
214 | - $post_name = sanitize_title( $post->post_title ); |
|
213 | + } else if (!empty($post->ID) && !empty($post->post_title)) { |
|
214 | + $post_name = sanitize_title($post->post_title); |
|
215 | 215 | |
216 | 216 | global $wpdb; |
217 | - $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) ); |
|
217 | + $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID)); |
|
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
221 | - $this->post_name = $post_name; |
|
221 | + $this->post_name = $post_name; |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | private function setup_due_date() { |
225 | - $due_date = $this->get_meta( '_wpinv_due_date' ); |
|
225 | + $due_date = $this->get_meta('_wpinv_due_date'); |
|
226 | 226 | |
227 | - if ( empty( $due_date ) ) { |
|
228 | - $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) ); |
|
229 | - $due_date = date_i18n( 'Y-m-d', $overdue_time ); |
|
230 | - } else if ( $due_date == 'none' ) { |
|
227 | + if (empty($due_date)) { |
|
228 | + $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days'))); |
|
229 | + $due_date = date_i18n('Y-m-d', $overdue_time); |
|
230 | + } else if ($due_date == 'none') { |
|
231 | 231 | $due_date = ''; |
232 | 232 | } |
233 | 233 | |
@@ -235,63 +235,63 @@ discard block |
||
235 | 235 | } |
236 | 236 | |
237 | 237 | private function setup_completed_date() { |
238 | - $invoice = get_post( $this->ID ); |
|
238 | + $invoice = get_post($this->ID); |
|
239 | 239 | |
240 | - if ( 'pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) { |
|
240 | + if ('pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) { |
|
241 | 241 | return false; // This invoice was never paid |
242 | 242 | } |
243 | 243 | |
244 | - $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date; |
|
244 | + $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date; |
|
245 | 245 | |
246 | 246 | return $date; |
247 | 247 | } |
248 | 248 | |
249 | 249 | private function setup_cart_details() { |
250 | - $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array(); |
|
250 | + $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array(); |
|
251 | 251 | return $cart_details; |
252 | 252 | } |
253 | 253 | |
254 | 254 | public function array_convert() { |
255 | - return get_object_vars( $this ); |
|
255 | + return get_object_vars($this); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | private function setup_items() { |
259 | - $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array(); |
|
259 | + $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array(); |
|
260 | 260 | return $items; |
261 | 261 | } |
262 | 262 | |
263 | 263 | private function setup_fees() { |
264 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
264 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
265 | 265 | return $payment_fees; |
266 | 266 | } |
267 | 267 | |
268 | 268 | private function setup_currency() { |
269 | - $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this ); |
|
269 | + $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this); |
|
270 | 270 | return $currency; |
271 | 271 | } |
272 | 272 | |
273 | 273 | private function setup_discount() { |
274 | 274 | //$discount = $this->get_meta( '_wpinv_discount', true ); |
275 | - $discount = $this->subtotal - ( $this->total - $this->tax - $this->fees_total ); |
|
276 | - if ( $discount < 0 ) { |
|
275 | + $discount = $this->subtotal - ($this->total - $this->tax - $this->fees_total); |
|
276 | + if ($discount < 0) { |
|
277 | 277 | $discount = 0; |
278 | 278 | } |
279 | - $discount = wpinv_format_amount( $discount, NULL, true ); |
|
279 | + $discount = wpinv_format_amount($discount, NULL, true); |
|
280 | 280 | |
281 | 281 | return $discount; |
282 | 282 | } |
283 | 283 | |
284 | 284 | private function setup_discount_code() { |
285 | - $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true ); |
|
285 | + $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true); |
|
286 | 286 | return $discount_code; |
287 | 287 | } |
288 | 288 | |
289 | 289 | private function setup_tax() { |
290 | - $tax = $this->get_meta( '_wpinv_tax', true ); |
|
290 | + $tax = $this->get_meta('_wpinv_tax', true); |
|
291 | 291 | |
292 | 292 | // We don't have tax as it's own meta and no meta was passed |
293 | - if ( '' === $tax ) { |
|
294 | - $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0; |
|
293 | + if ('' === $tax) { |
|
294 | + $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0; |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | return $tax; |
@@ -305,9 +305,9 @@ discard block |
||
305 | 305 | $subtotal = 0; |
306 | 306 | $cart_details = $this->cart_details; |
307 | 307 | |
308 | - if ( is_array( $cart_details ) ) { |
|
309 | - foreach ( $cart_details as $item ) { |
|
310 | - if ( isset( $item['subtotal'] ) ) { |
|
308 | + if (is_array($cart_details)) { |
|
309 | + foreach ($cart_details as $item) { |
|
310 | + if (isset($item['subtotal'])) { |
|
311 | 311 | $subtotal += $item['subtotal']; |
312 | 312 | } |
313 | 313 | } |
@@ -321,18 +321,18 @@ discard block |
||
321 | 321 | } |
322 | 322 | |
323 | 323 | private function setup_discounts() { |
324 | - $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array(); |
|
324 | + $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array(); |
|
325 | 325 | return $discounts; |
326 | 326 | } |
327 | 327 | |
328 | 328 | private function setup_total() { |
329 | - $amount = $this->get_meta( '_wpinv_total', true ); |
|
329 | + $amount = $this->get_meta('_wpinv_total', true); |
|
330 | 330 | |
331 | - if ( empty( $amount ) && '0.00' != $amount ) { |
|
332 | - $meta = $this->get_meta( '_wpinv_payment_meta', true ); |
|
333 | - $meta = maybe_unserialize( $meta ); |
|
331 | + if (empty($amount) && '0.00' != $amount) { |
|
332 | + $meta = $this->get_meta('_wpinv_payment_meta', true); |
|
333 | + $meta = maybe_unserialize($meta); |
|
334 | 334 | |
335 | - if ( isset( $meta['amount'] ) ) { |
|
335 | + if (isset($meta['amount'])) { |
|
336 | 336 | $amount = $meta['amount']; |
337 | 337 | } |
338 | 338 | } |
@@ -341,13 +341,13 @@ discard block |
||
341 | 341 | } |
342 | 342 | |
343 | 343 | private function setup_mode() { |
344 | - return $this->get_meta( '_wpinv_mode' ); |
|
344 | + return $this->get_meta('_wpinv_mode'); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | private function setup_gateway() { |
348 | - $gateway = $this->get_meta( '_wpinv_gateway' ); |
|
348 | + $gateway = $this->get_meta('_wpinv_gateway'); |
|
349 | 349 | |
350 | - if ( empty( $gateway ) && 'publish' === $this->status ) { |
|
350 | + if (empty($gateway) && 'publish' === $this->status) { |
|
351 | 351 | $gateway = 'manual'; |
352 | 352 | } |
353 | 353 | |
@@ -355,23 +355,23 @@ discard block |
||
355 | 355 | } |
356 | 356 | |
357 | 357 | private function setup_gateway_title() { |
358 | - $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway ); |
|
358 | + $gateway_title = wpinv_get_gateway_checkout_label($this->gateway); |
|
359 | 359 | return $gateway_title; |
360 | 360 | } |
361 | 361 | |
362 | 362 | private function setup_transaction_id() { |
363 | - $transaction_id = $this->get_meta( '_wpinv_transaction_id' ); |
|
363 | + $transaction_id = $this->get_meta('_wpinv_transaction_id'); |
|
364 | 364 | |
365 | - if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) { |
|
365 | + if (empty($transaction_id) || (int)$transaction_id === (int)$this->ID) { |
|
366 | 366 | $gateway = $this->gateway; |
367 | - $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID ); |
|
367 | + $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | return $transaction_id; |
371 | 371 | } |
372 | 372 | |
373 | 373 | private function setup_ip() { |
374 | - $ip = $this->get_meta( '_wpinv_user_ip' ); |
|
374 | + $ip = $this->get_meta('_wpinv_user_ip'); |
|
375 | 375 | return $ip; |
376 | 376 | } |
377 | 377 | |
@@ -381,62 +381,62 @@ discard block |
||
381 | 381 | ///} |
382 | 382 | |
383 | 383 | private function setup_first_name() { |
384 | - $first_name = $this->get_meta( '_wpinv_first_name' ); |
|
384 | + $first_name = $this->get_meta('_wpinv_first_name'); |
|
385 | 385 | return $first_name; |
386 | 386 | } |
387 | 387 | |
388 | 388 | private function setup_last_name() { |
389 | - $last_name = $this->get_meta( '_wpinv_last_name' ); |
|
389 | + $last_name = $this->get_meta('_wpinv_last_name'); |
|
390 | 390 | return $last_name; |
391 | 391 | } |
392 | 392 | |
393 | 393 | private function setup_company() { |
394 | - $company = $this->get_meta( '_wpinv_company' ); |
|
394 | + $company = $this->get_meta('_wpinv_company'); |
|
395 | 395 | return $company; |
396 | 396 | } |
397 | 397 | |
398 | 398 | private function setup_vat_number() { |
399 | - $vat_number = $this->get_meta( '_wpinv_vat_number' ); |
|
399 | + $vat_number = $this->get_meta('_wpinv_vat_number'); |
|
400 | 400 | return $vat_number; |
401 | 401 | } |
402 | 402 | |
403 | 403 | private function setup_vat_rate() { |
404 | - $vat_rate = $this->get_meta( '_wpinv_vat_rate' ); |
|
404 | + $vat_rate = $this->get_meta('_wpinv_vat_rate'); |
|
405 | 405 | return $vat_rate; |
406 | 406 | } |
407 | 407 | |
408 | 408 | private function setup_adddress_confirmed() { |
409 | - $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' ); |
|
409 | + $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed'); |
|
410 | 410 | return $adddress_confirmed; |
411 | 411 | } |
412 | 412 | |
413 | 413 | private function setup_phone() { |
414 | - $phone = $this->get_meta( '_wpinv_phone' ); |
|
414 | + $phone = $this->get_meta('_wpinv_phone'); |
|
415 | 415 | return $phone; |
416 | 416 | } |
417 | 417 | |
418 | 418 | private function setup_address() { |
419 | - $address = $this->get_meta( '_wpinv_address', true ); |
|
419 | + $address = $this->get_meta('_wpinv_address', true); |
|
420 | 420 | return $address; |
421 | 421 | } |
422 | 422 | |
423 | 423 | private function setup_city() { |
424 | - $city = $this->get_meta( '_wpinv_city', true ); |
|
424 | + $city = $this->get_meta('_wpinv_city', true); |
|
425 | 425 | return $city; |
426 | 426 | } |
427 | 427 | |
428 | 428 | private function setup_country() { |
429 | - $country = $this->get_meta( '_wpinv_country', true ); |
|
429 | + $country = $this->get_meta('_wpinv_country', true); |
|
430 | 430 | return $country; |
431 | 431 | } |
432 | 432 | |
433 | 433 | private function setup_state() { |
434 | - $state = $this->get_meta( '_wpinv_state', true ); |
|
434 | + $state = $this->get_meta('_wpinv_state', true); |
|
435 | 435 | return $state; |
436 | 436 | } |
437 | 437 | |
438 | 438 | private function setup_zip() { |
439 | - $zip = $this->get_meta( '_wpinv_zip', true ); |
|
439 | + $zip = $this->get_meta('_wpinv_zip', true); |
|
440 | 440 | return $zip; |
441 | 441 | } |
442 | 442 | |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | 'user_id' => $this->user_id, |
446 | 446 | 'first_name' => $this->first_name, |
447 | 447 | 'last_name' => $this->last_name, |
448 | - 'email' => get_the_author_meta( 'email', $this->user_id ), |
|
448 | + 'email' => get_the_author_meta('email', $this->user_id), |
|
449 | 449 | 'phone' => $this->phone, |
450 | 450 | 'address' => $this->address, |
451 | 451 | 'city' => $this->city, |
@@ -460,12 +460,12 @@ discard block |
||
460 | 460 | ); |
461 | 461 | |
462 | 462 | $user_info = array(); |
463 | - if ( isset( $this->payment_meta['user_info'] ) ) { |
|
464 | - $user_info = maybe_unserialize( $this->payment_meta['user_info'] ); |
|
463 | + if (isset($this->payment_meta['user_info'])) { |
|
464 | + $user_info = maybe_unserialize($this->payment_meta['user_info']); |
|
465 | 465 | |
466 | - if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) { |
|
466 | + if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) { |
|
467 | 467 | $this->user_id = $post->post_author; |
468 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
468 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
469 | 469 | |
470 | 470 | $user_info['user_id'] = $this->user_id; |
471 | 471 | $user_info['email'] = $this->email; |
@@ -474,13 +474,13 @@ discard block |
||
474 | 474 | } |
475 | 475 | } |
476 | 476 | |
477 | - $user_info = wp_parse_args( $user_info, $defaults ); |
|
477 | + $user_info = wp_parse_args($user_info, $defaults); |
|
478 | 478 | |
479 | 479 | // Get the user, but only if it's been created |
480 | - $user = get_userdata( $this->user_id ); |
|
480 | + $user = get_userdata($this->user_id); |
|
481 | 481 | |
482 | - if ( !empty( $user ) && $user->ID > 0 ) { |
|
483 | - if ( empty( $user_info ) ) { |
|
482 | + if (!empty($user) && $user->ID > 0) { |
|
483 | + if (empty($user_info)) { |
|
484 | 484 | $user_info = array( |
485 | 485 | 'user_id' => $user->ID, |
486 | 486 | 'first_name' => $user->first_name, |
@@ -489,23 +489,23 @@ discard block |
||
489 | 489 | 'discount' => '', |
490 | 490 | ); |
491 | 491 | } else { |
492 | - foreach ( $user_info as $key => $value ) { |
|
493 | - if ( ! empty( $value ) ) { |
|
492 | + foreach ($user_info as $key => $value) { |
|
493 | + if (!empty($value)) { |
|
494 | 494 | continue; |
495 | 495 | } |
496 | 496 | |
497 | - switch( $key ) { |
|
497 | + switch ($key) { |
|
498 | 498 | case 'user_id': |
499 | - $user_info[ $key ] = $user->ID; |
|
499 | + $user_info[$key] = $user->ID; |
|
500 | 500 | break; |
501 | 501 | case 'first_name': |
502 | - $user_info[ $key ] = $user->first_name; |
|
502 | + $user_info[$key] = $user->first_name; |
|
503 | 503 | break; |
504 | 504 | case 'last_name': |
505 | - $user_info[ $key ] = $user->last_name; |
|
505 | + $user_info[$key] = $user->last_name; |
|
506 | 506 | break; |
507 | 507 | case 'email': |
508 | - $user_info[ $key ] = $user->user_email; |
|
508 | + $user_info[$key] = $user->user_email; |
|
509 | 509 | break; |
510 | 510 | } |
511 | 511 | } |
@@ -516,16 +516,16 @@ discard block |
||
516 | 516 | } |
517 | 517 | |
518 | 518 | private function setup_invoice_key() { |
519 | - $key = $this->get_meta( '_wpinv_key', true ); |
|
519 | + $key = $this->get_meta('_wpinv_key', true); |
|
520 | 520 | |
521 | 521 | return $key; |
522 | 522 | } |
523 | 523 | |
524 | 524 | private function setup_invoice_number() { |
525 | - $number = $this->get_meta( '_wpinv_number', true ); |
|
525 | + $number = $this->get_meta('_wpinv_number', true); |
|
526 | 526 | |
527 | - if ( !$number ) { |
|
528 | - $number = wpinv_format_invoice_number( $this->ID ); |
|
527 | + if (!$number) { |
|
528 | + $number = wpinv_format_invoice_number($this->ID); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | return $number; |
@@ -536,18 +536,18 @@ discard block |
||
536 | 536 | |
537 | 537 | if ($number = $this->get_number()) { |
538 | 538 | $invoice_title = $number; |
539 | - } else if ( ! empty( $this->ID ) ) { |
|
540 | - $invoice_title = wpinv_format_invoice_number( $this->ID ); |
|
539 | + } else if (!empty($this->ID)) { |
|
540 | + $invoice_title = wpinv_format_invoice_number($this->ID); |
|
541 | 541 | } else { |
542 | - $invoice_title = wpinv_format_invoice_number( 0 ); |
|
542 | + $invoice_title = wpinv_format_invoice_number(0); |
|
543 | 543 | } |
544 | 544 | |
545 | - if ( empty( $this->key ) ) { |
|
545 | + if (empty($this->key)) { |
|
546 | 546 | $this->key = self::generate_key(); |
547 | 547 | $this->pending['key'] = $this->key; |
548 | 548 | } |
549 | 549 | |
550 | - if ( empty( $this->ip ) ) { |
|
550 | + if (empty($this->ip)) { |
|
551 | 551 | $this->ip = wpinv_get_ip(); |
552 | 552 | $this->pending['ip'] = $this->ip; |
553 | 553 | } |
@@ -579,75 +579,75 @@ discard block |
||
579 | 579 | 'fees' => $this->fees, |
580 | 580 | ); |
581 | 581 | |
582 | - $post_name = sanitize_title( $invoice_title ); |
|
582 | + $post_name = sanitize_title($invoice_title); |
|
583 | 583 | |
584 | 584 | $post_data = array( |
585 | 585 | 'post_title' => $invoice_title, |
586 | 586 | 'post_status' => $this->status, |
587 | 587 | 'post_author' => $this->user_id, |
588 | 588 | 'post_type' => $this->post_type, |
589 | - 'post_date' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ), |
|
590 | - 'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ), |
|
589 | + 'post_date' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'), |
|
590 | + 'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1), |
|
591 | 591 | 'post_parent' => $this->parent_invoice, |
592 | 592 | ); |
593 | - $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this ); |
|
593 | + $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this); |
|
594 | 594 | |
595 | 595 | // Create a blank invoice |
596 | - if ( !empty( $this->ID ) ) { |
|
596 | + if (!empty($this->ID)) { |
|
597 | 597 | $args['ID'] = $this->ID; |
598 | 598 | $args['post_name'] = $post_name; |
599 | 599 | |
600 | - $invoice_id = wp_update_post( $args ); |
|
600 | + $invoice_id = wp_update_post($args); |
|
601 | 601 | } else { |
602 | - $invoice_id = wp_insert_post( $args ); |
|
602 | + $invoice_id = wp_insert_post($args); |
|
603 | 603 | |
604 | - $post_title = wpinv_format_invoice_number( $invoice_id ); |
|
604 | + $post_title = wpinv_format_invoice_number($invoice_id); |
|
605 | 605 | global $wpdb; |
606 | - $wpdb->update( $wpdb->posts, array( 'post_title' => $post_title, 'post_name' => sanitize_title( $post_title ) ), array( 'ID' => $invoice_id ) ); |
|
607 | - clean_post_cache( $invoice_id ); |
|
606 | + $wpdb->update($wpdb->posts, array('post_title' => $post_title, 'post_name' => sanitize_title($post_title)), array('ID' => $invoice_id)); |
|
607 | + clean_post_cache($invoice_id); |
|
608 | 608 | } |
609 | 609 | |
610 | - if ( !empty( $invoice_id ) ) { |
|
610 | + if (!empty($invoice_id)) { |
|
611 | 611 | $this->ID = $invoice_id; |
612 | 612 | $this->_ID = $invoice_id; |
613 | 613 | |
614 | 614 | ///$this->pending['user_id'] = $this->user_id; |
615 | - if ( isset( $this->pending['number'] ) ) { |
|
615 | + if (isset($this->pending['number'])) { |
|
616 | 616 | $this->pending['number'] = $post_name; |
617 | 617 | } |
618 | 618 | |
619 | - $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data ); |
|
620 | - if ( ! empty( $this->payment_meta['fees'] ) ) { |
|
621 | - $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] ); |
|
622 | - foreach( $this->fees as $fee ) { |
|
623 | - $this->increase_fees( $fee['amount'] ); |
|
619 | + $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data); |
|
620 | + if (!empty($this->payment_meta['fees'])) { |
|
621 | + $this->fees = array_merge($this->fees, $this->payment_meta['fees']); |
|
622 | + foreach ($this->fees as $fee) { |
|
623 | + $this->increase_fees($fee['amount']); |
|
624 | 624 | } |
625 | 625 | } |
626 | 626 | |
627 | - $this->update_meta( '_wpinv_payment_meta', $this->payment_meta ); |
|
627 | + $this->update_meta('_wpinv_payment_meta', $this->payment_meta); |
|
628 | 628 | $this->new = true; |
629 | 629 | } |
630 | 630 | |
631 | 631 | return $this->ID; |
632 | 632 | } |
633 | 633 | |
634 | - public function save( $setup = false ) { |
|
634 | + public function save($setup = false) { |
|
635 | 635 | global $wpi_session; |
636 | 636 | |
637 | 637 | $saved = false; |
638 | - if ( empty( $this->items ) ) { |
|
638 | + if (empty($this->items)) { |
|
639 | 639 | return $saved; // Don't save empty invoice. |
640 | 640 | } |
641 | 641 | |
642 | - if ( empty( $this->key ) ) { |
|
642 | + if (empty($this->key)) { |
|
643 | 643 | $this->key = self::generate_key(); |
644 | 644 | $this->pending['key'] = $this->key; |
645 | 645 | } |
646 | 646 | |
647 | - if ( empty( $this->ID ) ) { |
|
647 | + if (empty($this->ID)) { |
|
648 | 648 | $invoice_id = $this->insert_invoice(); |
649 | 649 | |
650 | - if ( false === $invoice_id ) { |
|
650 | + if (false === $invoice_id) { |
|
651 | 651 | $saved = false; |
652 | 652 | } else { |
653 | 653 | $this->ID = $invoice_id; |
@@ -655,27 +655,27 @@ discard block |
||
655 | 655 | } |
656 | 656 | |
657 | 657 | // If we have something pending, let's save it |
658 | - if ( !empty( $this->pending ) ) { |
|
658 | + if (!empty($this->pending)) { |
|
659 | 659 | $total_increase = 0; |
660 | 660 | $total_decrease = 0; |
661 | 661 | |
662 | - foreach ( $this->pending as $key => $value ) { |
|
663 | - switch( $key ) { |
|
662 | + foreach ($this->pending as $key => $value) { |
|
663 | + switch ($key) { |
|
664 | 664 | case 'items': |
665 | 665 | // Update totals for pending items |
666 | - foreach ( $this->pending[ $key ] as $item ) { |
|
667 | - switch( $item['action'] ) { |
|
666 | + foreach ($this->pending[$key] as $item) { |
|
667 | + switch ($item['action']) { |
|
668 | 668 | case 'add': |
669 | 669 | $price = $item['price']; |
670 | 670 | $taxes = $item['tax']; |
671 | 671 | |
672 | - if ( 'publish' === $this->status ) { |
|
672 | + if ('publish' === $this->status) { |
|
673 | 673 | $total_increase += $price; |
674 | 674 | } |
675 | 675 | break; |
676 | 676 | |
677 | 677 | case 'remove': |
678 | - if ( 'publish' === $this->status ) { |
|
678 | + if ('publish' === $this->status) { |
|
679 | 679 | $total_decrease += $item['price']; |
680 | 680 | } |
681 | 681 | break; |
@@ -683,16 +683,16 @@ discard block |
||
683 | 683 | } |
684 | 684 | break; |
685 | 685 | case 'fees': |
686 | - if ( 'publish' !== $this->status ) { |
|
686 | + if ('publish' !== $this->status) { |
|
687 | 687 | break; |
688 | 688 | } |
689 | 689 | |
690 | - if ( empty( $this->pending[ $key ] ) ) { |
|
690 | + if (empty($this->pending[$key])) { |
|
691 | 691 | break; |
692 | 692 | } |
693 | 693 | |
694 | - foreach ( $this->pending[ $key ] as $fee ) { |
|
695 | - switch( $fee['action'] ) { |
|
694 | + foreach ($this->pending[$key] as $fee) { |
|
695 | + switch ($fee['action']) { |
|
696 | 696 | case 'add': |
697 | 697 | $total_increase += $fee['amount']; |
698 | 698 | break; |
@@ -704,86 +704,86 @@ discard block |
||
704 | 704 | } |
705 | 705 | break; |
706 | 706 | case 'status': |
707 | - $this->update_status( $this->status ); |
|
707 | + $this->update_status($this->status); |
|
708 | 708 | break; |
709 | 709 | case 'gateway': |
710 | - $this->update_meta( '_wpinv_gateway', $this->gateway ); |
|
710 | + $this->update_meta('_wpinv_gateway', $this->gateway); |
|
711 | 711 | break; |
712 | 712 | case 'mode': |
713 | - $this->update_meta( '_wpinv_mode', $this->mode ); |
|
713 | + $this->update_meta('_wpinv_mode', $this->mode); |
|
714 | 714 | break; |
715 | 715 | case 'transaction_id': |
716 | - $this->update_meta( '_wpinv_transaction_id', $this->transaction_id ); |
|
716 | + $this->update_meta('_wpinv_transaction_id', $this->transaction_id); |
|
717 | 717 | break; |
718 | 718 | case 'ip': |
719 | - $this->update_meta( '_wpinv_user_ip', $this->ip ); |
|
719 | + $this->update_meta('_wpinv_user_ip', $this->ip); |
|
720 | 720 | break; |
721 | 721 | ///case 'user_id': |
722 | 722 | ///$this->update_meta( '_wpinv_user_id', $this->user_id ); |
723 | 723 | ///$this->user_info['user_id'] = $this->user_id; |
724 | 724 | ///break; |
725 | 725 | case 'first_name': |
726 | - $this->update_meta( '_wpinv_first_name', $this->first_name ); |
|
726 | + $this->update_meta('_wpinv_first_name', $this->first_name); |
|
727 | 727 | $this->user_info['first_name'] = $this->first_name; |
728 | 728 | break; |
729 | 729 | case 'last_name': |
730 | - $this->update_meta( '_wpinv_last_name', $this->last_name ); |
|
730 | + $this->update_meta('_wpinv_last_name', $this->last_name); |
|
731 | 731 | $this->user_info['last_name'] = $this->last_name; |
732 | 732 | break; |
733 | 733 | case 'phone': |
734 | - $this->update_meta( '_wpinv_phone', $this->phone ); |
|
734 | + $this->update_meta('_wpinv_phone', $this->phone); |
|
735 | 735 | $this->user_info['phone'] = $this->phone; |
736 | 736 | break; |
737 | 737 | case 'address': |
738 | - $this->update_meta( '_wpinv_address', $this->address ); |
|
738 | + $this->update_meta('_wpinv_address', $this->address); |
|
739 | 739 | $this->user_info['address'] = $this->address; |
740 | 740 | break; |
741 | 741 | case 'city': |
742 | - $this->update_meta( '_wpinv_city', $this->city ); |
|
742 | + $this->update_meta('_wpinv_city', $this->city); |
|
743 | 743 | $this->user_info['city'] = $this->city; |
744 | 744 | break; |
745 | 745 | case 'country': |
746 | - $this->update_meta( '_wpinv_country', $this->country ); |
|
746 | + $this->update_meta('_wpinv_country', $this->country); |
|
747 | 747 | $this->user_info['country'] = $this->country; |
748 | 748 | break; |
749 | 749 | case 'state': |
750 | - $this->update_meta( '_wpinv_state', $this->state ); |
|
750 | + $this->update_meta('_wpinv_state', $this->state); |
|
751 | 751 | $this->user_info['state'] = $this->state; |
752 | 752 | break; |
753 | 753 | case 'zip': |
754 | - $this->update_meta( '_wpinv_zip', $this->zip ); |
|
754 | + $this->update_meta('_wpinv_zip', $this->zip); |
|
755 | 755 | $this->user_info['zip'] = $this->zip; |
756 | 756 | break; |
757 | 757 | case 'company': |
758 | - $this->update_meta( '_wpinv_company', $this->company ); |
|
758 | + $this->update_meta('_wpinv_company', $this->company); |
|
759 | 759 | $this->user_info['company'] = $this->company; |
760 | 760 | break; |
761 | 761 | case 'vat_number': |
762 | - $this->update_meta( '_wpinv_vat_number', $this->vat_number ); |
|
762 | + $this->update_meta('_wpinv_vat_number', $this->vat_number); |
|
763 | 763 | $this->user_info['vat_number'] = $this->vat_number; |
764 | 764 | |
765 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
766 | - if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) { |
|
767 | - $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false; |
|
768 | - $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed ); |
|
765 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
766 | + if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) { |
|
767 | + $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
768 | + $this->update_meta('_wpinv_adddress_confirmed', (bool)$adddress_confirmed); |
|
769 | 769 | $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed; |
770 | 770 | } |
771 | 771 | |
772 | 772 | break; |
773 | 773 | case 'vat_rate': |
774 | - $this->update_meta( '_wpinv_vat_rate', $this->vat_rate ); |
|
774 | + $this->update_meta('_wpinv_vat_rate', $this->vat_rate); |
|
775 | 775 | $this->user_info['vat_rate'] = $this->vat_rate; |
776 | 776 | break; |
777 | 777 | case 'adddress_confirmed': |
778 | - $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed ); |
|
778 | + $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed); |
|
779 | 779 | $this->user_info['adddress_confirmed'] = $this->adddress_confirmed; |
780 | 780 | break; |
781 | 781 | |
782 | 782 | case 'key': |
783 | - $this->update_meta( '_wpinv_key', $this->key ); |
|
783 | + $this->update_meta('_wpinv_key', $this->key); |
|
784 | 784 | break; |
785 | 785 | case 'number': |
786 | - $this->update_meta( '_wpinv_number', $this->number ); |
|
786 | + $this->update_meta('_wpinv_number', $this->number); |
|
787 | 787 | break; |
788 | 788 | case 'date': |
789 | 789 | $args = array( |
@@ -792,34 +792,34 @@ discard block |
||
792 | 792 | 'edit_date' => true, |
793 | 793 | ); |
794 | 794 | |
795 | - wp_update_post( $args ); |
|
795 | + wp_update_post($args); |
|
796 | 796 | break; |
797 | 797 | case 'due_date': |
798 | - if ( empty( $this->due_date ) ) { |
|
798 | + if (empty($this->due_date)) { |
|
799 | 799 | $this->due_date = 'none'; |
800 | 800 | } |
801 | 801 | |
802 | - $this->update_meta( '_wpinv_due_date', $this->due_date ); |
|
802 | + $this->update_meta('_wpinv_due_date', $this->due_date); |
|
803 | 803 | break; |
804 | 804 | case 'completed_date': |
805 | - $this->update_meta( '_wpinv_completed_date', $this->completed_date ); |
|
805 | + $this->update_meta('_wpinv_completed_date', $this->completed_date); |
|
806 | 806 | break; |
807 | 807 | case 'discounts': |
808 | - if ( ! is_array( $this->discounts ) ) { |
|
809 | - $this->discounts = explode( ',', $this->discounts ); |
|
808 | + if (!is_array($this->discounts)) { |
|
809 | + $this->discounts = explode(',', $this->discounts); |
|
810 | 810 | } |
811 | 811 | |
812 | - $this->user_info['discount'] = implode( ',', $this->discounts ); |
|
812 | + $this->user_info['discount'] = implode(',', $this->discounts); |
|
813 | 813 | break; |
814 | 814 | |
815 | 815 | //case 'tax': |
816 | 816 | //$this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) ); |
817 | 817 | //break; |
818 | 818 | case 'discount': |
819 | - $this->update_meta( '_wpinv_discount', wpinv_format_amount( $this->discount, NULL, true ) ); |
|
819 | + $this->update_meta('_wpinv_discount', wpinv_format_amount($this->discount, NULL, true)); |
|
820 | 820 | break; |
821 | 821 | case 'discount_code': |
822 | - $this->update_meta( '_wpinv_discount_code', $this->discount_code ); |
|
822 | + $this->update_meta('_wpinv_discount_code', $this->discount_code); |
|
823 | 823 | break; |
824 | 824 | //case 'fees': |
825 | 825 | //$this->update_meta( '_wpinv_fees', $this->fees ); |
@@ -829,19 +829,19 @@ discard block |
||
829 | 829 | 'ID' => $this->ID, |
830 | 830 | 'post_parent' => $this->parent_invoice, |
831 | 831 | ); |
832 | - wp_update_post( $args ); |
|
832 | + wp_update_post($args); |
|
833 | 833 | break; |
834 | 834 | default: |
835 | - do_action( 'wpinv_save', $this, $key ); |
|
835 | + do_action('wpinv_save', $this, $key); |
|
836 | 836 | break; |
837 | 837 | } |
838 | 838 | } |
839 | 839 | |
840 | - $this->update_meta( '_wpinv_subtotal', wpinv_format_amount( $this->subtotal, NULL, true ) ); |
|
841 | - $this->update_meta( '_wpinv_total', wpinv_format_amount( $this->total, NULL, true ) ); |
|
842 | - $this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) ); |
|
840 | + $this->update_meta('_wpinv_subtotal', wpinv_format_amount($this->subtotal, NULL, true)); |
|
841 | + $this->update_meta('_wpinv_total', wpinv_format_amount($this->total, NULL, true)); |
|
842 | + $this->update_meta('_wpinv_tax', wpinv_format_amount($this->tax, NULL, true)); |
|
843 | 843 | |
844 | - $this->items = array_values( $this->items ); |
|
844 | + $this->items = array_values($this->items); |
|
845 | 845 | |
846 | 846 | $new_meta = array( |
847 | 847 | 'items' => $this->items, |
@@ -852,12 +852,12 @@ discard block |
||
852 | 852 | ); |
853 | 853 | |
854 | 854 | $meta = $this->get_meta(); |
855 | - $merged_meta = array_merge( $meta, $new_meta ); |
|
855 | + $merged_meta = array_merge($meta, $new_meta); |
|
856 | 856 | |
857 | 857 | // Only save the payment meta if it's changed |
858 | - if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) { |
|
859 | - $updated = $this->update_meta( '_wpinv_payment_meta', $merged_meta ); |
|
860 | - if ( false !== $updated ) { |
|
858 | + if (md5(serialize($meta)) !== md5(serialize($merged_meta))) { |
|
859 | + $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta); |
|
860 | + if (false !== $updated) { |
|
861 | 861 | $saved = true; |
862 | 862 | } |
863 | 863 | } |
@@ -865,15 +865,15 @@ discard block |
||
865 | 865 | $this->pending = array(); |
866 | 866 | $saved = true; |
867 | 867 | } else { |
868 | - $this->update_meta( '_wpinv_subtotal', wpinv_format_amount( $this->subtotal, NULL, true ) ); |
|
869 | - $this->update_meta( '_wpinv_total', wpinv_format_amount( $this->total, NULL, true ) ); |
|
870 | - $this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) ); |
|
868 | + $this->update_meta('_wpinv_subtotal', wpinv_format_amount($this->subtotal, NULL, true)); |
|
869 | + $this->update_meta('_wpinv_total', wpinv_format_amount($this->total, NULL, true)); |
|
870 | + $this->update_meta('_wpinv_tax', wpinv_format_amount($this->tax, NULL, true)); |
|
871 | 871 | } |
872 | 872 | |
873 | - do_action( 'wpinv_invoice_save', $this, $saved ); |
|
873 | + do_action('wpinv_invoice_save', $this, $saved); |
|
874 | 874 | |
875 | - if ( true === $saved || $setup ) { |
|
876 | - $this->setup_invoice( $this->ID ); |
|
875 | + if (true === $saved || $setup) { |
|
876 | + $this->setup_invoice($this->ID); |
|
877 | 877 | } |
878 | 878 | |
879 | 879 | $this->refresh_item_ids(); |
@@ -881,7 +881,7 @@ discard block |
||
881 | 881 | return $saved; |
882 | 882 | } |
883 | 883 | |
884 | - public function add_fee( $args, $global = true ) { |
|
884 | + public function add_fee($args, $global = true) { |
|
885 | 885 | $default_args = array( |
886 | 886 | 'label' => '', |
887 | 887 | 'amount' => 0, |
@@ -891,75 +891,75 @@ discard block |
||
891 | 891 | 'item_id' => 0, |
892 | 892 | ); |
893 | 893 | |
894 | - $fee = wp_parse_args( $args, $default_args ); |
|
894 | + $fee = wp_parse_args($args, $default_args); |
|
895 | 895 | |
896 | - if ( !empty( $fee['label'] ) ) { |
|
896 | + if (!empty($fee['label'])) { |
|
897 | 897 | return false; |
898 | 898 | } |
899 | 899 | |
900 | - $fee['id'] = sanitize_title( $fee['label'] ); |
|
900 | + $fee['id'] = sanitize_title($fee['label']); |
|
901 | 901 | |
902 | - $this->fees[] = $fee; |
|
902 | + $this->fees[] = $fee; |
|
903 | 903 | |
904 | 904 | $added_fee = $fee; |
905 | 905 | $added_fee['action'] = 'add'; |
906 | 906 | $this->pending['fees'][] = $added_fee; |
907 | - reset( $this->fees ); |
|
907 | + reset($this->fees); |
|
908 | 908 | |
909 | - $this->increase_fees( $fee['amount'] ); |
|
909 | + $this->increase_fees($fee['amount']); |
|
910 | 910 | return true; |
911 | 911 | } |
912 | 912 | |
913 | - public function remove_fee( $key ) { |
|
913 | + public function remove_fee($key) { |
|
914 | 914 | $removed = false; |
915 | 915 | |
916 | - if ( is_numeric( $key ) ) { |
|
917 | - $removed = $this->remove_fee_by( 'index', $key ); |
|
916 | + if (is_numeric($key)) { |
|
917 | + $removed = $this->remove_fee_by('index', $key); |
|
918 | 918 | } |
919 | 919 | |
920 | 920 | return $removed; |
921 | 921 | } |
922 | 922 | |
923 | - public function remove_fee_by( $key, $value, $global = false ) { |
|
924 | - $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array( |
|
923 | + public function remove_fee_by($key, $value, $global = false) { |
|
924 | + $allowed_fee_keys = apply_filters('wpinv_fee_keys', array( |
|
925 | 925 | 'index', 'label', 'amount', 'type', |
926 | - ) ); |
|
926 | + )); |
|
927 | 927 | |
928 | - if ( ! in_array( $key, $allowed_fee_keys ) ) { |
|
928 | + if (!in_array($key, $allowed_fee_keys)) { |
|
929 | 929 | return false; |
930 | 930 | } |
931 | 931 | |
932 | 932 | $removed = false; |
933 | - if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) { |
|
934 | - $removed_fee = $this->fees[ $value ]; |
|
933 | + if ('index' === $key && array_key_exists($value, $this->fees)) { |
|
934 | + $removed_fee = $this->fees[$value]; |
|
935 | 935 | $removed_fee['action'] = 'remove'; |
936 | 936 | $this->pending['fees'][] = $removed_fee; |
937 | 937 | |
938 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
938 | + $this->decrease_fees($removed_fee['amount']); |
|
939 | 939 | |
940 | - unset( $this->fees[ $value ] ); |
|
940 | + unset($this->fees[$value]); |
|
941 | 941 | $removed = true; |
942 | - } else if ( 'index' !== $key ) { |
|
943 | - foreach ( $this->fees as $index => $fee ) { |
|
944 | - if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) { |
|
942 | + } else if ('index' !== $key) { |
|
943 | + foreach ($this->fees as $index => $fee) { |
|
944 | + if (isset($fee[$key]) && $fee[$key] == $value) { |
|
945 | 945 | $removed_fee = $fee; |
946 | 946 | $removed_fee['action'] = 'remove'; |
947 | 947 | $this->pending['fees'][] = $removed_fee; |
948 | 948 | |
949 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
949 | + $this->decrease_fees($removed_fee['amount']); |
|
950 | 950 | |
951 | - unset( $this->fees[ $index ] ); |
|
951 | + unset($this->fees[$index]); |
|
952 | 952 | $removed = true; |
953 | 953 | |
954 | - if ( false === $global ) { |
|
954 | + if (false === $global) { |
|
955 | 955 | break; |
956 | 956 | } |
957 | 957 | } |
958 | 958 | } |
959 | 959 | } |
960 | 960 | |
961 | - if ( true === $removed ) { |
|
962 | - $this->fees = array_values( $this->fees ); |
|
961 | + if (true === $removed) { |
|
962 | + $this->fees = array_values($this->fees); |
|
963 | 963 | } |
964 | 964 | |
965 | 965 | return $removed; |
@@ -967,35 +967,35 @@ discard block |
||
967 | 967 | |
968 | 968 | |
969 | 969 | |
970 | - public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
|
970 | + public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) { |
|
971 | 971 | // Bail if no note specified |
972 | - if( !$note ) { |
|
972 | + if (!$note) { |
|
973 | 973 | return false; |
974 | 974 | } |
975 | 975 | |
976 | - if ( empty( $this->ID ) ) |
|
976 | + if (empty($this->ID)) |
|
977 | 977 | return false; |
978 | 978 | |
979 | - if ( ( ( is_user_logged_in() && current_user_can( 'manage_options' ) ) || $added_by_user ) && !$system ) { |
|
980 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
979 | + if (((is_user_logged_in() && current_user_can('manage_options')) || $added_by_user) && !$system) { |
|
980 | + $user = get_user_by('id', get_current_user_id()); |
|
981 | 981 | $comment_author = $user->display_name; |
982 | 982 | $comment_author_email = $user->user_email; |
983 | 983 | } else { |
984 | - $comment_author = __( 'System', 'invoicing' ); |
|
985 | - $comment_author_email = strtolower( __( 'System', 'invoicing' ) ) . '@'; |
|
986 | - $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com'; |
|
987 | - $comment_author_email = sanitize_email( $comment_author_email ); |
|
984 | + $comment_author = __('System', 'invoicing'); |
|
985 | + $comment_author_email = strtolower(__('System', 'invoicing')) . '@'; |
|
986 | + $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com'; |
|
987 | + $comment_author_email = sanitize_email($comment_author_email); |
|
988 | 988 | } |
989 | 989 | |
990 | - do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type ); |
|
990 | + do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type); |
|
991 | 991 | |
992 | - $note_id = wp_insert_comment( wp_filter_comment( array( |
|
992 | + $note_id = wp_insert_comment(wp_filter_comment(array( |
|
993 | 993 | 'comment_post_ID' => $this->ID, |
994 | 994 | 'comment_content' => $note, |
995 | 995 | 'comment_agent' => 'GeoDirectory', |
996 | 996 | 'user_id' => is_admin() ? get_current_user_id() : 0, |
997 | - 'comment_date' => current_time( 'mysql' ), |
|
998 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
997 | + 'comment_date' => current_time('mysql'), |
|
998 | + 'comment_date_gmt' => current_time('mysql', 1), |
|
999 | 999 | 'comment_approved' => 1, |
1000 | 1000 | 'comment_parent' => 0, |
1001 | 1001 | 'comment_author' => $comment_author, |
@@ -1003,53 +1003,53 @@ discard block |
||
1003 | 1003 | 'comment_author_url' => '', |
1004 | 1004 | 'comment_author_email' => $comment_author_email, |
1005 | 1005 | 'comment_type' => 'wpinv_note' |
1006 | - ) ) ); |
|
1006 | + ))); |
|
1007 | 1007 | |
1008 | - do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note ); |
|
1008 | + do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note); |
|
1009 | 1009 | |
1010 | - if ( $customer_type ) { |
|
1011 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
1010 | + if ($customer_type) { |
|
1011 | + add_comment_meta($note_id, '_wpi_customer_note', 1); |
|
1012 | 1012 | |
1013 | - do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) ); |
|
1013 | + do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note)); |
|
1014 | 1014 | } |
1015 | 1015 | |
1016 | 1016 | return $note_id; |
1017 | 1017 | } |
1018 | 1018 | |
1019 | - private function increase_subtotal( $amount = 0.00 ) { |
|
1020 | - $amount = (float) $amount; |
|
1019 | + private function increase_subtotal($amount = 0.00) { |
|
1020 | + $amount = (float)$amount; |
|
1021 | 1021 | $this->subtotal += $amount; |
1022 | - $this->subtotal = wpinv_format_amount( $this->subtotal, NULL, true ); |
|
1022 | + $this->subtotal = wpinv_format_amount($this->subtotal, NULL, true); |
|
1023 | 1023 | |
1024 | 1024 | $this->recalculate_total(); |
1025 | 1025 | } |
1026 | 1026 | |
1027 | - private function decrease_subtotal( $amount = 0.00 ) { |
|
1028 | - $amount = (float) $amount; |
|
1027 | + private function decrease_subtotal($amount = 0.00) { |
|
1028 | + $amount = (float)$amount; |
|
1029 | 1029 | $this->subtotal -= $amount; |
1030 | - $this->subtotal = wpinv_format_amount( $this->subtotal, NULL, true ); |
|
1030 | + $this->subtotal = wpinv_format_amount($this->subtotal, NULL, true); |
|
1031 | 1031 | |
1032 | - if ( $this->subtotal < 0 ) { |
|
1032 | + if ($this->subtotal < 0) { |
|
1033 | 1033 | $this->subtotal = 0; |
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | $this->recalculate_total(); |
1037 | 1037 | } |
1038 | 1038 | |
1039 | - private function increase_fees( $amount = 0.00 ) { |
|
1039 | + private function increase_fees($amount = 0.00) { |
|
1040 | 1040 | $amount = (float)$amount; |
1041 | 1041 | $this->fees_total += $amount; |
1042 | - $this->fees_total = wpinv_format_amount( $this->fees_total, NULL, true ); |
|
1042 | + $this->fees_total = wpinv_format_amount($this->fees_total, NULL, true); |
|
1043 | 1043 | |
1044 | 1044 | $this->recalculate_total(); |
1045 | 1045 | } |
1046 | 1046 | |
1047 | - private function decrease_fees( $amount = 0.00 ) { |
|
1048 | - $amount = (float) $amount; |
|
1047 | + private function decrease_fees($amount = 0.00) { |
|
1048 | + $amount = (float)$amount; |
|
1049 | 1049 | $this->fees_total -= $amount; |
1050 | - $this->fees_total = wpinv_format_amount( $this->fees_total, NULL, true ); |
|
1050 | + $this->fees_total = wpinv_format_amount($this->fees_total, NULL, true); |
|
1051 | 1051 | |
1052 | - if ( $this->fees_total < 0 ) { |
|
1052 | + if ($this->fees_total < 0) { |
|
1053 | 1053 | $this->fees_total = 0; |
1054 | 1054 | } |
1055 | 1055 | |
@@ -1060,54 +1060,54 @@ discard block |
||
1060 | 1060 | global $wpi_nosave; |
1061 | 1061 | |
1062 | 1062 | $this->total = $this->subtotal + $this->tax + $this->fees_total; |
1063 | - $this->total = wpinv_format_amount( $this->total, NULL, true ); |
|
1063 | + $this->total = wpinv_format_amount($this->total, NULL, true); |
|
1064 | 1064 | |
1065 | - do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave ); |
|
1065 | + do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave); |
|
1066 | 1066 | } |
1067 | 1067 | |
1068 | - public function increase_tax( $amount = 0.00 ) { |
|
1069 | - $amount = (float) $amount; |
|
1068 | + public function increase_tax($amount = 0.00) { |
|
1069 | + $amount = (float)$amount; |
|
1070 | 1070 | $this->tax += $amount; |
1071 | 1071 | |
1072 | 1072 | $this->recalculate_total(); |
1073 | 1073 | } |
1074 | 1074 | |
1075 | - public function decrease_tax( $amount = 0.00 ) { |
|
1076 | - $amount = (float) $amount; |
|
1075 | + public function decrease_tax($amount = 0.00) { |
|
1076 | + $amount = (float)$amount; |
|
1077 | 1077 | $this->tax -= $amount; |
1078 | 1078 | |
1079 | - if ( $this->tax < 0 ) { |
|
1079 | + if ($this->tax < 0) { |
|
1080 | 1080 | $this->tax = 0; |
1081 | 1081 | } |
1082 | 1082 | |
1083 | 1083 | $this->recalculate_total(); |
1084 | 1084 | } |
1085 | 1085 | |
1086 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
1087 | - $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID ); |
|
1086 | + public function update_status($new_status = false, $note = '', $manual = false) { |
|
1087 | + $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID); |
|
1088 | 1088 | |
1089 | - if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses() ) ) ) { |
|
1089 | + if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses()))) { |
|
1090 | 1090 | return false; // Don't permit status changes that aren't changes |
1091 | 1091 | } |
1092 | 1092 | |
1093 | - $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status ); |
|
1093 | + $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status); |
|
1094 | 1094 | $updated = false; |
1095 | 1095 | |
1096 | - if ( $do_change ) { |
|
1097 | - do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status ); |
|
1096 | + if ($do_change) { |
|
1097 | + do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status); |
|
1098 | 1098 | |
1099 | 1099 | $update_post_data = array(); |
1100 | 1100 | $update_post_data['ID'] = $this->ID; |
1101 | 1101 | $update_post_data['post_status'] = $new_status; |
1102 | - $update_post_data['edit_date'] = current_time( 'mysql', 0 ); |
|
1103 | - $update_post_data['edit_date_gmt'] = current_time( 'mysql', 1 ); |
|
1102 | + $update_post_data['edit_date'] = current_time('mysql', 0); |
|
1103 | + $update_post_data['edit_date_gmt'] = current_time('mysql', 1); |
|
1104 | 1104 | |
1105 | - $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID ); |
|
1105 | + $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID); |
|
1106 | 1106 | |
1107 | - $updated = wp_update_post( $update_post_data ); |
|
1107 | + $updated = wp_update_post($update_post_data); |
|
1108 | 1108 | |
1109 | 1109 | // Process any specific status functions |
1110 | - switch( $new_status ) { |
|
1110 | + switch ($new_status) { |
|
1111 | 1111 | case 'wpi-refunded': |
1112 | 1112 | $this->process_refund(); |
1113 | 1113 | break; |
@@ -1120,9 +1120,9 @@ discard block |
||
1120 | 1120 | } |
1121 | 1121 | |
1122 | 1122 | // Status was changed. |
1123 | - do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status ); |
|
1124 | - do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status ); |
|
1125 | - do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status ); |
|
1123 | + do_action('wpinv_status_' . $new_status, $this->ID, $old_status); |
|
1124 | + do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status); |
|
1125 | + do_action('wpinv_update_status', $this->ID, $new_status, $old_status); |
|
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | return $updated; |
@@ -1136,72 +1136,72 @@ discard block |
||
1136 | 1136 | $this->save(); |
1137 | 1137 | } |
1138 | 1138 | |
1139 | - public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
1140 | - if ( empty( $meta_key ) ) { |
|
1139 | + public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { |
|
1140 | + if (empty($meta_key)) { |
|
1141 | 1141 | return false; |
1142 | 1142 | } |
1143 | 1143 | |
1144 | - if ( $meta_key == 'key' || $meta_key == 'date' ) { |
|
1144 | + if ($meta_key == 'key' || $meta_key == 'date') { |
|
1145 | 1145 | $current_meta = $this->get_meta(); |
1146 | - $current_meta[ $meta_key ] = $meta_value; |
|
1146 | + $current_meta[$meta_key] = $meta_value; |
|
1147 | 1147 | |
1148 | 1148 | $meta_key = '_wpinv_payment_meta'; |
1149 | 1149 | $meta_value = $current_meta; |
1150 | 1150 | } |
1151 | 1151 | |
1152 | - $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID ); |
|
1152 | + $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID); |
|
1153 | 1153 | |
1154 | - if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) { |
|
1154 | + if ($meta_key == '_wpinv_completed_date' && !empty($meta_value)) { |
|
1155 | 1155 | $args = array( |
1156 | 1156 | 'ID' => $this->ID, |
1157 | 1157 | 'post_date' => $meta_value, |
1158 | 1158 | 'edit_date' => true, |
1159 | - 'post_date_gmt' => get_gmt_from_date( $meta_value ), |
|
1159 | + 'post_date_gmt' => get_gmt_from_date($meta_value), |
|
1160 | 1160 | 'post_modified' => $meta_value, |
1161 | - 'post_modified_gmt' => get_gmt_from_date( $meta_value ) |
|
1161 | + 'post_modified_gmt' => get_gmt_from_date($meta_value) |
|
1162 | 1162 | ); |
1163 | - wp_update_post( $args ); |
|
1163 | + wp_update_post($args); |
|
1164 | 1164 | } |
1165 | 1165 | |
1166 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value ); |
|
1166 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value); |
|
1167 | 1167 | } |
1168 | 1168 | |
1169 | 1169 | private function process_refund() { |
1170 | 1170 | $process_refund = true; |
1171 | 1171 | |
1172 | 1172 | // If the payment was not in publish, don't decrement stats as they were never incremented |
1173 | - if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) { |
|
1173 | + if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) { |
|
1174 | 1174 | $process_refund = false; |
1175 | 1175 | } |
1176 | 1176 | |
1177 | 1177 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
1178 | - $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this ); |
|
1178 | + $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this); |
|
1179 | 1179 | |
1180 | - if ( false === $process_refund ) { |
|
1180 | + if (false === $process_refund) { |
|
1181 | 1181 | return; |
1182 | 1182 | } |
1183 | 1183 | |
1184 | - do_action( 'wpinv_pre_refund_invoice', $this ); |
|
1184 | + do_action('wpinv_pre_refund_invoice', $this); |
|
1185 | 1185 | |
1186 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this ); |
|
1187 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this ); |
|
1188 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this ); |
|
1186 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this); |
|
1187 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this); |
|
1188 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this); |
|
1189 | 1189 | |
1190 | - do_action( 'wpinv_post_refund_invoice', $this ); |
|
1190 | + do_action('wpinv_post_refund_invoice', $this); |
|
1191 | 1191 | } |
1192 | 1192 | |
1193 | 1193 | private function process_failure() { |
1194 | 1194 | $discounts = $this->discounts; |
1195 | - if ( empty( $discounts ) ) { |
|
1195 | + if (empty($discounts)) { |
|
1196 | 1196 | return; |
1197 | 1197 | } |
1198 | 1198 | |
1199 | - if ( ! is_array( $discounts ) ) { |
|
1200 | - $discounts = array_map( 'trim', explode( ',', $discounts ) ); |
|
1199 | + if (!is_array($discounts)) { |
|
1200 | + $discounts = array_map('trim', explode(',', $discounts)); |
|
1201 | 1201 | } |
1202 | 1202 | |
1203 | - foreach ( $discounts as $discount ) { |
|
1204 | - wpinv_decrease_discount_usage( $discount ); |
|
1203 | + foreach ($discounts as $discount) { |
|
1204 | + wpinv_decrease_discount_usage($discount); |
|
1205 | 1205 | } |
1206 | 1206 | } |
1207 | 1207 | |
@@ -1209,92 +1209,92 @@ discard block |
||
1209 | 1209 | $process_pending = true; |
1210 | 1210 | |
1211 | 1211 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented |
1212 | - if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'pending' != $this->status ) { |
|
1212 | + if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'pending' != $this->status) { |
|
1213 | 1213 | $process_pending = false; |
1214 | 1214 | } |
1215 | 1215 | |
1216 | 1216 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
1217 | - $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this ); |
|
1217 | + $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this); |
|
1218 | 1218 | |
1219 | - if ( false === $process_pending ) { |
|
1219 | + if (false === $process_pending) { |
|
1220 | 1220 | return; |
1221 | 1221 | } |
1222 | 1222 | |
1223 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this ); |
|
1224 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this ); |
|
1225 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this ); |
|
1223 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this); |
|
1224 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this); |
|
1225 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this); |
|
1226 | 1226 | |
1227 | 1227 | $this->completed_date = ''; |
1228 | - $this->update_meta( '_wpinv_completed_date', '' ); |
|
1228 | + $this->update_meta('_wpinv_completed_date', ''); |
|
1229 | 1229 | } |
1230 | 1230 | |
1231 | 1231 | // get data |
1232 | - public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
1233 | - $meta = get_post_meta( $this->ID, $meta_key, $single ); |
|
1232 | + public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) { |
|
1233 | + $meta = get_post_meta($this->ID, $meta_key, $single); |
|
1234 | 1234 | |
1235 | - if ( $meta_key === '_wpinv_payment_meta' ) { |
|
1235 | + if ($meta_key === '_wpinv_payment_meta') { |
|
1236 | 1236 | |
1237 | - if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is. |
|
1237 | + if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is. |
|
1238 | 1238 | |
1239 | - if ( empty( $meta['key'] ) ) { |
|
1239 | + if (empty($meta['key'])) { |
|
1240 | 1240 | $meta['key'] = $this->setup_invoice_key(); |
1241 | 1241 | } |
1242 | 1242 | |
1243 | - if ( empty( $meta['date'] ) ) { |
|
1244 | - $meta['date'] = get_post_field( 'post_date', $this->ID ); |
|
1243 | + if (empty($meta['date'])) { |
|
1244 | + $meta['date'] = get_post_field('post_date', $this->ID); |
|
1245 | 1245 | } |
1246 | 1246 | } |
1247 | 1247 | |
1248 | - $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID ); |
|
1248 | + $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID); |
|
1249 | 1249 | |
1250 | - return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key ); |
|
1250 | + return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key); |
|
1251 | 1251 | } |
1252 | 1252 | |
1253 | 1253 | public function get_description() { |
1254 | - $post = get_post( $this->ID ); |
|
1254 | + $post = get_post($this->ID); |
|
1255 | 1255 | |
1256 | - $description = !empty( $post ) ? $post->post_content : ''; |
|
1257 | - return apply_filters( 'wpinv_get_description', $description, $this->ID, $this ); |
|
1256 | + $description = !empty($post) ? $post->post_content : ''; |
|
1257 | + return apply_filters('wpinv_get_description', $description, $this->ID, $this); |
|
1258 | 1258 | } |
1259 | 1259 | |
1260 | - public function get_status( $nicename = false ) { |
|
1261 | - if ( !$nicename ) { |
|
1260 | + public function get_status($nicename = false) { |
|
1261 | + if (!$nicename) { |
|
1262 | 1262 | $status = $this->status; |
1263 | 1263 | } else { |
1264 | 1264 | $status = $this->status_nicename; |
1265 | 1265 | } |
1266 | 1266 | |
1267 | - return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this ); |
|
1267 | + return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this); |
|
1268 | 1268 | } |
1269 | 1269 | |
1270 | 1270 | public function get_cart_details() { |
1271 | - return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this ); |
|
1271 | + return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this); |
|
1272 | 1272 | } |
1273 | 1273 | |
1274 | - public function get_subtotal( $currency = false ) { |
|
1275 | - $subtotal = wpinv_format_amount( $this->subtotal, NULL, !$currency ); |
|
1274 | + public function get_subtotal($currency = false) { |
|
1275 | + $subtotal = wpinv_format_amount($this->subtotal, NULL, !$currency); |
|
1276 | 1276 | |
1277 | - if ( $currency ) { |
|
1278 | - $subtotal = wpinv_price( $subtotal, $this->get_currency() ); |
|
1277 | + if ($currency) { |
|
1278 | + $subtotal = wpinv_price($subtotal, $this->get_currency()); |
|
1279 | 1279 | } |
1280 | 1280 | |
1281 | - return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency ); |
|
1281 | + return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency); |
|
1282 | 1282 | } |
1283 | 1283 | |
1284 | - public function get_total( $currency = false ) { |
|
1285 | - if ( $this->is_free_trial() ) { |
|
1286 | - $total = wpinv_format_amount( 0, NULL, !$currency ); |
|
1284 | + public function get_total($currency = false) { |
|
1285 | + if ($this->is_free_trial()) { |
|
1286 | + $total = wpinv_format_amount(0, NULL, !$currency); |
|
1287 | 1287 | } else { |
1288 | - $total = wpinv_format_amount( $this->total, NULL, !$currency ); |
|
1288 | + $total = wpinv_format_amount($this->total, NULL, !$currency); |
|
1289 | 1289 | } |
1290 | - if ( $currency ) { |
|
1291 | - $total = wpinv_price( $total, $this->get_currency() ); |
|
1290 | + if ($currency) { |
|
1291 | + $total = wpinv_price($total, $this->get_currency()); |
|
1292 | 1292 | } |
1293 | 1293 | |
1294 | - return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency ); |
|
1294 | + return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency); |
|
1295 | 1295 | } |
1296 | 1296 | |
1297 | - public function get_recurring_details( $field = '', $currency = false ) { |
|
1297 | + public function get_recurring_details($field = '', $currency = false) { |
|
1298 | 1298 | $data = array(); |
1299 | 1299 | $data['cart_details'] = $this->cart_details; |
1300 | 1300 | $data['subtotal'] = $this->get_subtotal(); |
@@ -1302,45 +1302,45 @@ discard block |
||
1302 | 1302 | $data['tax'] = $this->get_tax(); |
1303 | 1303 | $data['total'] = $this->get_total(); |
1304 | 1304 | |
1305 | - if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) { |
|
1305 | + if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) { |
|
1306 | 1306 | $is_free_trial = $this->is_free_trial(); |
1307 | - $discounts = $this->get_discounts( true ); |
|
1307 | + $discounts = $this->get_discounts(true); |
|
1308 | 1308 | |
1309 | - if ( $is_free_trial || !empty( $discounts ) ) { |
|
1309 | + if ($is_free_trial || !empty($discounts)) { |
|
1310 | 1310 | $first_use_only = false; |
1311 | 1311 | |
1312 | - if ( !empty( $discounts ) ) { |
|
1313 | - foreach ( $discounts as $key => $code ) { |
|
1314 | - if ( wpinv_discount_is_recurring( $code, true ) ) { |
|
1312 | + if (!empty($discounts)) { |
|
1313 | + foreach ($discounts as $key => $code) { |
|
1314 | + if (wpinv_discount_is_recurring($code, true)) { |
|
1315 | 1315 | $first_use_only = true; |
1316 | 1316 | break; |
1317 | 1317 | } |
1318 | 1318 | } |
1319 | 1319 | } |
1320 | 1320 | |
1321 | - if ( !$first_use_only ) { |
|
1322 | - $data['subtotal'] = wpinv_format_amount( $this->subtotal, NULL, true ); |
|
1323 | - $data['discount'] = wpinv_format_amount( $this->discount, NULL, true ); |
|
1324 | - $data['tax'] = wpinv_format_amount( $this->tax, NULL, true ); |
|
1325 | - $data['total'] = wpinv_format_amount( $this->total, NULL, true ); |
|
1321 | + if (!$first_use_only) { |
|
1322 | + $data['subtotal'] = wpinv_format_amount($this->subtotal, NULL, true); |
|
1323 | + $data['discount'] = wpinv_format_amount($this->discount, NULL, true); |
|
1324 | + $data['tax'] = wpinv_format_amount($this->tax, NULL, true); |
|
1325 | + $data['total'] = wpinv_format_amount($this->total, NULL, true); |
|
1326 | 1326 | } else { |
1327 | 1327 | $cart_subtotal = 0; |
1328 | 1328 | $cart_discount = 0; |
1329 | 1329 | $cart_tax = 0; |
1330 | 1330 | |
1331 | - foreach ( $this->cart_details as $key => $item ) { |
|
1332 | - $item_quantity = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
1333 | - $item_subtotal = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity; |
|
1331 | + foreach ($this->cart_details as $key => $item) { |
|
1332 | + $item_quantity = $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
1333 | + $item_subtotal = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity; |
|
1334 | 1334 | $item_discount = 0; |
1335 | - $item_tax = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0; |
|
1335 | + $item_tax = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float)$item['vat_rate']) : 0; |
|
1336 | 1336 | |
1337 | - if ( wpinv_prices_include_tax() ) { |
|
1338 | - $item_subtotal -= wpinv_format_amount( $item_tax, NULL, true ); |
|
1337 | + if (wpinv_prices_include_tax()) { |
|
1338 | + $item_subtotal -= wpinv_format_amount($item_tax, NULL, true); |
|
1339 | 1339 | } |
1340 | 1340 | |
1341 | 1341 | $item_total = $item_subtotal - $item_discount + $item_tax; |
1342 | 1342 | // Do not allow totals to go negative |
1343 | - if ( $item_total < 0 ) { |
|
1343 | + if ($item_total < 0) { |
|
1344 | 1344 | $item_total = 0; |
1345 | 1345 | } |
1346 | 1346 | |
@@ -1348,107 +1348,107 @@ discard block |
||
1348 | 1348 | $cart_discount += (float)($item_discount); |
1349 | 1349 | $cart_tax += (float)($item_tax); |
1350 | 1350 | |
1351 | - $data['cart_details'][$key]['discount'] = wpinv_format_amount( $item_discount, NULL, true ); |
|
1352 | - $data['cart_details'][$key]['tax'] = wpinv_format_amount( $item_tax, NULL, true ); |
|
1353 | - $data['cart_details'][$key]['price'] = wpinv_format_amount( $item_total, NULL, true ); |
|
1351 | + $data['cart_details'][$key]['discount'] = wpinv_format_amount($item_discount, NULL, true); |
|
1352 | + $data['cart_details'][$key]['tax'] = wpinv_format_amount($item_tax, NULL, true); |
|
1353 | + $data['cart_details'][$key]['price'] = wpinv_format_amount($item_total, NULL, true); |
|
1354 | 1354 | } |
1355 | 1355 | |
1356 | - $data['subtotal'] = wpinv_format_amount( $cart_subtotal, NULL, true ); |
|
1357 | - $data['discount'] = wpinv_format_amount( $cart_discount, NULL, true ); |
|
1358 | - $data['tax'] = wpinv_format_amount( $cart_tax, NULL, true ); |
|
1359 | - $data['total'] = wpinv_format_amount( ( $data['subtotal'] + $data['tax'] ), NULL, true ); |
|
1356 | + $data['subtotal'] = wpinv_format_amount($cart_subtotal, NULL, true); |
|
1357 | + $data['discount'] = wpinv_format_amount($cart_discount, NULL, true); |
|
1358 | + $data['tax'] = wpinv_format_amount($cart_tax, NULL, true); |
|
1359 | + $data['total'] = wpinv_format_amount(($data['subtotal'] + $data['tax']), NULL, true); |
|
1360 | 1360 | } |
1361 | 1361 | } |
1362 | 1362 | } |
1363 | 1363 | |
1364 | - $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency ); |
|
1364 | + $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency); |
|
1365 | 1365 | |
1366 | - if ( isset( $data[$field] ) ) { |
|
1367 | - return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
|
1366 | + if (isset($data[$field])) { |
|
1367 | + return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]); |
|
1368 | 1368 | } |
1369 | 1369 | |
1370 | 1370 | return $data; |
1371 | 1371 | } |
1372 | 1372 | |
1373 | - public function get_final_tax( $currency = false ) { |
|
1374 | - $final_total = wpinv_format_amount( $this->tax, NULL, !$currency ); |
|
1375 | - if ( $currency ) { |
|
1376 | - $final_total = wpinv_price( $final_total, $this->get_currency() ); |
|
1373 | + public function get_final_tax($currency = false) { |
|
1374 | + $final_total = wpinv_format_amount($this->tax, NULL, !$currency); |
|
1375 | + if ($currency) { |
|
1376 | + $final_total = wpinv_price($final_total, $this->get_currency()); |
|
1377 | 1377 | } |
1378 | 1378 | |
1379 | - return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency ); |
|
1379 | + return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency); |
|
1380 | 1380 | } |
1381 | 1381 | |
1382 | - public function get_discounts( $array = false ) { |
|
1382 | + public function get_discounts($array = false) { |
|
1383 | 1383 | $discounts = $this->discounts; |
1384 | - if ( $array && $discounts ) { |
|
1385 | - $discounts = explode( ',', $discounts ); |
|
1384 | + if ($array && $discounts) { |
|
1385 | + $discounts = explode(',', $discounts); |
|
1386 | 1386 | } |
1387 | - return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array ); |
|
1387 | + return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array); |
|
1388 | 1388 | } |
1389 | 1389 | |
1390 | - public function get_discount( $currency = false, $dash = false ) { |
|
1391 | - if ( !empty( $this->discounts ) ) { |
|
1390 | + public function get_discount($currency = false, $dash = false) { |
|
1391 | + if (!empty($this->discounts)) { |
|
1392 | 1392 | global $ajax_cart_details; |
1393 | 1393 | $ajax_cart_details = $this->get_cart_details(); |
1394 | 1394 | |
1395 | - $this->discount = wpinv_get_cart_items_discount_amount( $this->items , $this->discounts ); |
|
1395 | + $this->discount = wpinv_get_cart_items_discount_amount($this->items, $this->discounts); |
|
1396 | 1396 | } |
1397 | - $discount = wpinv_format_amount( $this->discount, NULL, !$currency ); |
|
1397 | + $discount = wpinv_format_amount($this->discount, NULL, !$currency); |
|
1398 | 1398 | $dash = $dash && $discount > 0 ? '–' : ''; |
1399 | 1399 | |
1400 | - if ( $currency ) { |
|
1401 | - $discount = wpinv_price( $discount, $this->get_currency() ); |
|
1400 | + if ($currency) { |
|
1401 | + $discount = wpinv_price($discount, $this->get_currency()); |
|
1402 | 1402 | } |
1403 | 1403 | |
1404 | - $discount = $dash . $discount; |
|
1404 | + $discount = $dash . $discount; |
|
1405 | 1405 | |
1406 | - return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash ); |
|
1406 | + return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash); |
|
1407 | 1407 | } |
1408 | 1408 | |
1409 | 1409 | public function get_discount_code() { |
1410 | 1410 | return $this->discount_code; |
1411 | 1411 | } |
1412 | 1412 | |
1413 | - public function get_tax( $currency = false ) { |
|
1414 | - $tax = wpinv_format_amount( $this->tax, NULL, !$currency ); |
|
1413 | + public function get_tax($currency = false) { |
|
1414 | + $tax = wpinv_format_amount($this->tax, NULL, !$currency); |
|
1415 | 1415 | |
1416 | - if ( $currency ) { |
|
1417 | - $tax = wpinv_price( $tax, $this->get_currency() ); |
|
1416 | + if ($currency) { |
|
1417 | + $tax = wpinv_price($tax, $this->get_currency()); |
|
1418 | 1418 | } |
1419 | 1419 | |
1420 | - return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency ); |
|
1420 | + return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency); |
|
1421 | 1421 | } |
1422 | 1422 | |
1423 | - public function get_fees( $type = 'all' ) { |
|
1424 | - $fees = array(); |
|
1423 | + public function get_fees($type = 'all') { |
|
1424 | + $fees = array(); |
|
1425 | 1425 | |
1426 | - if ( ! empty( $this->fees ) && is_array( $this->fees ) ) { |
|
1427 | - foreach ( $this->fees as $fee ) { |
|
1428 | - if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
1426 | + if (!empty($this->fees) && is_array($this->fees)) { |
|
1427 | + foreach ($this->fees as $fee) { |
|
1428 | + if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) { |
|
1429 | 1429 | continue; |
1430 | 1430 | } |
1431 | 1431 | |
1432 | - $fee['label'] = stripslashes( $fee['label'] ); |
|
1433 | - $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() ); |
|
1434 | - $fees[] = $fee; |
|
1432 | + $fee['label'] = stripslashes($fee['label']); |
|
1433 | + $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency()); |
|
1434 | + $fees[] = $fee; |
|
1435 | 1435 | } |
1436 | 1436 | } |
1437 | 1437 | |
1438 | - return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this ); |
|
1438 | + return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this); |
|
1439 | 1439 | } |
1440 | 1440 | |
1441 | - public function get_fees_total( $type = 'all' ) { |
|
1442 | - $fees_total = (float) 0.00; |
|
1441 | + public function get_fees_total($type = 'all') { |
|
1442 | + $fees_total = (float)0.00; |
|
1443 | 1443 | |
1444 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
1445 | - if ( ! empty( $payment_fees ) ) { |
|
1446 | - foreach ( $payment_fees as $fee ) { |
|
1447 | - $fees_total += (float) $fee['amount']; |
|
1444 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
1445 | + if (!empty($payment_fees)) { |
|
1446 | + foreach ($payment_fees as $fee) { |
|
1447 | + $fees_total += (float)$fee['amount']; |
|
1448 | 1448 | } |
1449 | 1449 | } |
1450 | 1450 | |
1451 | - return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this ); |
|
1451 | + return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this); |
|
1452 | 1452 | /* |
1453 | 1453 | $fees = $this->get_fees( $type ); |
1454 | 1454 | |
@@ -1468,116 +1468,116 @@ discard block |
||
1468 | 1468 | } |
1469 | 1469 | |
1470 | 1470 | public function get_user_id() { |
1471 | - return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this ); |
|
1471 | + return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this); |
|
1472 | 1472 | } |
1473 | 1473 | |
1474 | 1474 | public function get_first_name() { |
1475 | - return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this ); |
|
1475 | + return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this); |
|
1476 | 1476 | } |
1477 | 1477 | |
1478 | 1478 | public function get_last_name() { |
1479 | - return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this ); |
|
1479 | + return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this); |
|
1480 | 1480 | } |
1481 | 1481 | |
1482 | 1482 | public function get_user_full_name() { |
1483 | - return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this ); |
|
1483 | + return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this); |
|
1484 | 1484 | } |
1485 | 1485 | |
1486 | 1486 | public function get_user_info() { |
1487 | - return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this ); |
|
1487 | + return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this); |
|
1488 | 1488 | } |
1489 | 1489 | |
1490 | 1490 | public function get_email() { |
1491 | - return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this ); |
|
1491 | + return apply_filters('wpinv_user_email', $this->email, $this->ID, $this); |
|
1492 | 1492 | } |
1493 | 1493 | |
1494 | 1494 | public function get_address() { |
1495 | - return apply_filters( 'wpinv_address', $this->address, $this->ID, $this ); |
|
1495 | + return apply_filters('wpinv_address', $this->address, $this->ID, $this); |
|
1496 | 1496 | } |
1497 | 1497 | |
1498 | 1498 | public function get_phone() { |
1499 | - return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this ); |
|
1499 | + return apply_filters('wpinv_phone', $this->phone, $this->ID, $this); |
|
1500 | 1500 | } |
1501 | 1501 | |
1502 | 1502 | public function get_number() { |
1503 | - return apply_filters( 'wpinv_number', $this->number, $this->ID, $this ); |
|
1503 | + return apply_filters('wpinv_number', $this->number, $this->ID, $this); |
|
1504 | 1504 | } |
1505 | 1505 | |
1506 | 1506 | public function get_items() { |
1507 | - return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this ); |
|
1507 | + return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this); |
|
1508 | 1508 | } |
1509 | 1509 | |
1510 | 1510 | public function get_key() { |
1511 | - return apply_filters( 'wpinv_key', $this->key, $this->ID, $this ); |
|
1511 | + return apply_filters('wpinv_key', $this->key, $this->ID, $this); |
|
1512 | 1512 | } |
1513 | 1513 | |
1514 | 1514 | public function get_transaction_id() { |
1515 | - return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this ); |
|
1515 | + return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this); |
|
1516 | 1516 | } |
1517 | 1517 | |
1518 | 1518 | public function get_gateway() { |
1519 | - return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this ); |
|
1519 | + return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this); |
|
1520 | 1520 | } |
1521 | 1521 | |
1522 | 1522 | public function get_gateway_title() { |
1523 | - $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway ); |
|
1523 | + $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway); |
|
1524 | 1524 | |
1525 | - return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this ); |
|
1525 | + return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this); |
|
1526 | 1526 | } |
1527 | 1527 | |
1528 | 1528 | public function get_currency() { |
1529 | - return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this ); |
|
1529 | + return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this); |
|
1530 | 1530 | } |
1531 | 1531 | |
1532 | 1532 | public function get_created_date() { |
1533 | - return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this ); |
|
1533 | + return apply_filters('wpinv_created_date', $this->date, $this->ID, $this); |
|
1534 | 1534 | } |
1535 | 1535 | |
1536 | - public function get_due_date( $display = false ) { |
|
1537 | - $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this ); |
|
1536 | + public function get_due_date($display = false) { |
|
1537 | + $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this); |
|
1538 | 1538 | |
1539 | - if ( !$display || empty( $due_date ) ) { |
|
1539 | + if (!$display || empty($due_date)) { |
|
1540 | 1540 | return $due_date; |
1541 | 1541 | } |
1542 | 1542 | |
1543 | - return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) ); |
|
1543 | + return date_i18n(get_option('date_format'), strtotime($due_date)); |
|
1544 | 1544 | } |
1545 | 1545 | |
1546 | 1546 | public function get_completed_date() { |
1547 | - return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this ); |
|
1547 | + return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this); |
|
1548 | 1548 | } |
1549 | 1549 | |
1550 | - public function get_invoice_date( $formatted = true ) { |
|
1550 | + public function get_invoice_date($formatted = true) { |
|
1551 | 1551 | $date_completed = $this->completed_date; |
1552 | 1552 | $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : ''; |
1553 | 1553 | |
1554 | - if ( $invoice_date == '' ) { |
|
1554 | + if ($invoice_date == '') { |
|
1555 | 1555 | $date_created = $this->date; |
1556 | 1556 | $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : ''; |
1557 | 1557 | } |
1558 | 1558 | |
1559 | - if ( $formatted && $invoice_date ) { |
|
1560 | - $invoice_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) ); |
|
1559 | + if ($formatted && $invoice_date) { |
|
1560 | + $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date)); |
|
1561 | 1561 | } |
1562 | 1562 | |
1563 | - return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this ); |
|
1563 | + return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this); |
|
1564 | 1564 | } |
1565 | 1565 | |
1566 | 1566 | public function get_ip() { |
1567 | - return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this ); |
|
1567 | + return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this); |
|
1568 | 1568 | } |
1569 | 1569 | |
1570 | - public function has_status( $status ) { |
|
1571 | - return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status ); |
|
1570 | + public function has_status($status) { |
|
1571 | + return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status); |
|
1572 | 1572 | } |
1573 | 1573 | |
1574 | - public function add_item( $item_id = 0, $args = array() ) { |
|
1574 | + public function add_item($item_id = 0, $args = array()) { |
|
1575 | 1575 | global $wpi_current_id, $wpi_item_id; |
1576 | 1576 | |
1577 | - $item = new WPInv_Item( $item_id ); |
|
1577 | + $item = new WPInv_Item($item_id); |
|
1578 | 1578 | |
1579 | 1579 | // Bail if this post isn't a item |
1580 | - if( !$item || $item->post_type !== 'wpi_item' ) { |
|
1580 | + if (!$item || $item->post_type !== 'wpi_item') { |
|
1581 | 1581 | return false; |
1582 | 1582 | } |
1583 | 1583 | |
@@ -1595,8 +1595,8 @@ discard block |
||
1595 | 1595 | 'fees' => array() |
1596 | 1596 | ); |
1597 | 1597 | |
1598 | - $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults ); |
|
1599 | - $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1; |
|
1598 | + $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults); |
|
1599 | + $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1; |
|
1600 | 1600 | |
1601 | 1601 | $wpi_current_id = $this->ID; |
1602 | 1602 | $wpi_item_id = $item->ID; |
@@ -1608,19 +1608,19 @@ discard block |
||
1608 | 1608 | $found_cart_key = false; |
1609 | 1609 | |
1610 | 1610 | if ($has_quantities) { |
1611 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
1611 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
1612 | 1612 | |
1613 | - foreach ( $this->items as $key => $cart_item ) { |
|
1614 | - if ( (int)$item_id !== (int)$cart_item['id'] ) { |
|
1613 | + foreach ($this->items as $key => $cart_item) { |
|
1614 | + if ((int)$item_id !== (int)$cart_item['id']) { |
|
1615 | 1615 | continue; |
1616 | 1616 | } |
1617 | 1617 | |
1618 | - $this->items[ $key ]['quantity'] += $args['quantity']; |
|
1618 | + $this->items[$key]['quantity'] += $args['quantity']; |
|
1619 | 1619 | break; |
1620 | 1620 | } |
1621 | 1621 | |
1622 | - foreach ( $this->cart_details as $cart_key => $cart_item ) { |
|
1623 | - if ( $item_id != $cart_item['id'] ) { |
|
1622 | + foreach ($this->cart_details as $cart_key => $cart_item) { |
|
1623 | + if ($item_id != $cart_item['id']) { |
|
1624 | 1624 | continue; |
1625 | 1625 | } |
1626 | 1626 | |
@@ -1632,29 +1632,29 @@ discard block |
||
1632 | 1632 | if ($has_quantities && $found_cart_key !== false) { |
1633 | 1633 | $cart_item = $this->cart_details[$found_cart_key]; |
1634 | 1634 | $item_price = $cart_item['item_price']; |
1635 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
1636 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
1635 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
1636 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
1637 | 1637 | |
1638 | 1638 | $new_quantity = $quantity + $args['quantity']; |
1639 | 1639 | $subtotal = $item_price * $new_quantity; |
1640 | 1640 | |
1641 | 1641 | $args['quantity'] = $new_quantity; |
1642 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
1643 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1642 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
1643 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0; |
|
1644 | 1644 | |
1645 | 1645 | $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0; |
1646 | 1646 | $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0; |
1647 | 1647 | // The total increase equals the number removed * the item_price |
1648 | - $total_increased = wpinv_format_amount( $item_price, NULL, true ); |
|
1648 | + $total_increased = wpinv_format_amount($item_price, NULL, true); |
|
1649 | 1649 | |
1650 | - if ( wpinv_prices_include_tax() ) { |
|
1651 | - $subtotal -= wpinv_format_amount( $tax, NULL, true ); |
|
1650 | + if (wpinv_prices_include_tax()) { |
|
1651 | + $subtotal -= wpinv_format_amount($tax, NULL, true); |
|
1652 | 1652 | } |
1653 | 1653 | |
1654 | - $total = $subtotal - $discount + $tax; |
|
1654 | + $total = $subtotal - $discount + $tax; |
|
1655 | 1655 | |
1656 | 1656 | // Do not allow totals to go negative |
1657 | - if( $total < 0 ) { |
|
1657 | + if ($total < 0) { |
|
1658 | 1658 | $total = 0; |
1659 | 1659 | } |
1660 | 1660 | |
@@ -1670,20 +1670,20 @@ discard block |
||
1670 | 1670 | $this->cart_details[$found_cart_key] = $cart_item; |
1671 | 1671 | } else { |
1672 | 1672 | // Allow overriding the price |
1673 | - if( false !== $args['item_price'] ) { |
|
1673 | + if (false !== $args['item_price']) { |
|
1674 | 1674 | $item_price = $args['item_price']; |
1675 | 1675 | } else { |
1676 | - $item_price = wpinv_get_item_price( $item->ID ); |
|
1676 | + $item_price = wpinv_get_item_price($item->ID); |
|
1677 | 1677 | } |
1678 | 1678 | |
1679 | 1679 | // Sanitizing the price here so we don't have a dozen calls later |
1680 | - $item_price = wpinv_sanitize_amount( $item_price ); |
|
1681 | - $subtotal = wpinv_format_amount( $item_price * $args['quantity'], NULL, true ); |
|
1680 | + $item_price = wpinv_sanitize_amount($item_price); |
|
1681 | + $subtotal = wpinv_format_amount($item_price * $args['quantity'], NULL, true); |
|
1682 | 1682 | |
1683 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
1684 | - $tax_class = !empty( $args['vat_class'] ) ? $args['vat_class'] : ''; |
|
1685 | - $tax_rate = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0; |
|
1686 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1683 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
1684 | + $tax_class = !empty($args['vat_class']) ? $args['vat_class'] : ''; |
|
1685 | + $tax_rate = !empty($args['vat_rate']) ? $args['vat_rate'] : 0; |
|
1686 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0; |
|
1687 | 1687 | |
1688 | 1688 | // Setup the items meta item |
1689 | 1689 | $new_item = array( |
@@ -1691,28 +1691,28 @@ discard block |
||
1691 | 1691 | 'quantity' => $args['quantity'], |
1692 | 1692 | ); |
1693 | 1693 | |
1694 | - $this->items[] = $new_item; |
|
1694 | + $this->items[] = $new_item; |
|
1695 | 1695 | |
1696 | - if ( wpinv_prices_include_tax() ) { |
|
1697 | - $subtotal -= wpinv_format_amount( $tax, NULL, true ); |
|
1696 | + if (wpinv_prices_include_tax()) { |
|
1697 | + $subtotal -= wpinv_format_amount($tax, NULL, true); |
|
1698 | 1698 | } |
1699 | 1699 | |
1700 | - $total = $subtotal - $discount + $tax; |
|
1700 | + $total = $subtotal - $discount + $tax; |
|
1701 | 1701 | |
1702 | 1702 | // Do not allow totals to go negative |
1703 | - if( $total < 0 ) { |
|
1703 | + if ($total < 0) { |
|
1704 | 1704 | $total = 0; |
1705 | 1705 | } |
1706 | 1706 | |
1707 | 1707 | $this->cart_details[] = array( |
1708 | 1708 | 'name' => !empty($args['name']) ? $args['name'] : $item->get_name(), |
1709 | 1709 | 'id' => $item->ID, |
1710 | - 'item_price' => wpinv_format_amount( $item_price, NULL, true ), |
|
1710 | + 'item_price' => wpinv_format_amount($item_price, NULL, true), |
|
1711 | 1711 | 'quantity' => $args['quantity'], |
1712 | 1712 | 'discount' => $discount, |
1713 | - 'subtotal' => wpinv_format_amount( $subtotal, NULL, true ), |
|
1714 | - 'tax' => wpinv_format_amount( $tax, NULL, true ), |
|
1715 | - 'price' => wpinv_format_amount( $total, NULL, true ), |
|
1713 | + 'subtotal' => wpinv_format_amount($subtotal, NULL, true), |
|
1714 | + 'tax' => wpinv_format_amount($tax, NULL, true), |
|
1715 | + 'price' => wpinv_format_amount($total, NULL, true), |
|
1716 | 1716 | 'vat_rate' => $tax_rate, |
1717 | 1717 | 'vat_class' => $tax_class, |
1718 | 1718 | 'meta' => $args['meta'], |
@@ -1722,69 +1722,69 @@ discard block |
||
1722 | 1722 | $subtotal = $subtotal - $discount; |
1723 | 1723 | } |
1724 | 1724 | |
1725 | - $added_item = end( $this->cart_details ); |
|
1726 | - $added_item['action'] = 'add'; |
|
1725 | + $added_item = end($this->cart_details); |
|
1726 | + $added_item['action'] = 'add'; |
|
1727 | 1727 | |
1728 | 1728 | $this->pending['items'][] = $added_item; |
1729 | 1729 | |
1730 | - $this->increase_subtotal( $subtotal ); |
|
1731 | - $this->increase_tax( $tax ); |
|
1730 | + $this->increase_subtotal($subtotal); |
|
1731 | + $this->increase_tax($tax); |
|
1732 | 1732 | |
1733 | 1733 | return true; |
1734 | 1734 | } |
1735 | 1735 | |
1736 | - public function remove_item( $item_id, $args = array() ) { |
|
1736 | + public function remove_item($item_id, $args = array()) { |
|
1737 | 1737 | // Set some defaults |
1738 | 1738 | $defaults = array( |
1739 | 1739 | 'quantity' => 1, |
1740 | 1740 | 'item_price' => false, |
1741 | 1741 | 'cart_index' => false, |
1742 | 1742 | ); |
1743 | - $args = wp_parse_args( $args, $defaults ); |
|
1743 | + $args = wp_parse_args($args, $defaults); |
|
1744 | 1744 | |
1745 | 1745 | // Bail if this post isn't a item |
1746 | - if ( get_post_type( $item_id ) !== 'wpi_item' ) { |
|
1746 | + if (get_post_type($item_id) !== 'wpi_item') { |
|
1747 | 1747 | return false; |
1748 | 1748 | } |
1749 | 1749 | |
1750 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
1750 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
1751 | 1751 | |
1752 | - foreach ( $this->items as $key => $item ) { |
|
1753 | - if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) { |
|
1752 | + foreach ($this->items as $key => $item) { |
|
1753 | + if (!empty($item['id']) && (int)$item_id !== (int)$item['id']) { |
|
1754 | 1754 | continue; |
1755 | 1755 | } |
1756 | 1756 | |
1757 | - if ( false !== $args['cart_index'] ) { |
|
1758 | - $cart_index = absint( $args['cart_index'] ); |
|
1759 | - $cart_item = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false; |
|
1757 | + if (false !== $args['cart_index']) { |
|
1758 | + $cart_index = absint($args['cart_index']); |
|
1759 | + $cart_item = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false; |
|
1760 | 1760 | |
1761 | - if ( ! empty( $cart_item ) ) { |
|
1761 | + if (!empty($cart_item)) { |
|
1762 | 1762 | // If the cart index item isn't the same item ID, don't remove it |
1763 | - if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) { |
|
1763 | + if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) { |
|
1764 | 1764 | continue; |
1765 | 1765 | } |
1766 | 1766 | } |
1767 | 1767 | } |
1768 | 1768 | |
1769 | - $item_quantity = $this->items[ $key ]['quantity']; |
|
1770 | - if ( $item_quantity > $args['quantity'] ) { |
|
1771 | - $this->items[ $key ]['quantity'] -= $args['quantity']; |
|
1769 | + $item_quantity = $this->items[$key]['quantity']; |
|
1770 | + if ($item_quantity > $args['quantity']) { |
|
1771 | + $this->items[$key]['quantity'] -= $args['quantity']; |
|
1772 | 1772 | break; |
1773 | 1773 | } else { |
1774 | - unset( $this->items[ $key ] ); |
|
1774 | + unset($this->items[$key]); |
|
1775 | 1775 | break; |
1776 | 1776 | } |
1777 | 1777 | } |
1778 | 1778 | |
1779 | 1779 | $found_cart_key = false; |
1780 | - if ( false === $args['cart_index'] ) { |
|
1781 | - foreach ( $this->cart_details as $cart_key => $item ) { |
|
1782 | - if ( $item_id != $item['id'] ) { |
|
1780 | + if (false === $args['cart_index']) { |
|
1781 | + foreach ($this->cart_details as $cart_key => $item) { |
|
1782 | + if ($item_id != $item['id']) { |
|
1783 | 1783 | continue; |
1784 | 1784 | } |
1785 | 1785 | |
1786 | - if ( false !== $args['item_price'] ) { |
|
1787 | - if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) { |
|
1786 | + if (false !== $args['item_price']) { |
|
1787 | + if (isset($item['item_price']) && (float)$args['item_price'] != (float)$item['item_price']) { |
|
1788 | 1788 | continue; |
1789 | 1789 | } |
1790 | 1790 | } |
@@ -1793,13 +1793,13 @@ discard block |
||
1793 | 1793 | break; |
1794 | 1794 | } |
1795 | 1795 | } else { |
1796 | - $cart_index = absint( $args['cart_index'] ); |
|
1796 | + $cart_index = absint($args['cart_index']); |
|
1797 | 1797 | |
1798 | - if ( ! array_key_exists( $cart_index, $this->cart_details ) ) { |
|
1798 | + if (!array_key_exists($cart_index, $this->cart_details)) { |
|
1799 | 1799 | return false; // Invalid cart index passed. |
1800 | 1800 | } |
1801 | 1801 | |
1802 | - if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) { |
|
1802 | + if ((int)$this->cart_details[$cart_index]['id'] > 0 && (int)$this->cart_details[$cart_index]['id'] !== (int)$item_id) { |
|
1803 | 1803 | return false; // We still need the proper Item ID to be sure. |
1804 | 1804 | } |
1805 | 1805 | |
@@ -1807,41 +1807,41 @@ discard block |
||
1807 | 1807 | } |
1808 | 1808 | |
1809 | 1809 | $cart_item = $this->cart_details[$found_cart_key]; |
1810 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
1810 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
1811 | 1811 | |
1812 | - if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) { |
|
1812 | + if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) { |
|
1813 | 1813 | return false; // Invoice must contain at least one item. |
1814 | 1814 | } |
1815 | 1815 | |
1816 | - $discounts = $this->get_discounts(); |
|
1816 | + $discounts = $this->get_discounts(); |
|
1817 | 1817 | |
1818 | - if ( $quantity > $args['quantity'] ) { |
|
1818 | + if ($quantity > $args['quantity']) { |
|
1819 | 1819 | $item_price = $cart_item['item_price']; |
1820 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
1820 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
1821 | 1821 | |
1822 | - $new_quantity = max( $quantity - $args['quantity'], 1); |
|
1822 | + $new_quantity = max($quantity - $args['quantity'], 1); |
|
1823 | 1823 | $subtotal = $item_price * $new_quantity; |
1824 | 1824 | |
1825 | 1825 | $args['quantity'] = $new_quantity; |
1826 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
1827 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1826 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
1827 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0; |
|
1828 | 1828 | |
1829 | - $discount_decrease = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_format_amount( ( (float)$cart_item['discount'] / $quantity ), NULL, true ) : 0; |
|
1829 | + $discount_decrease = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_format_amount(((float)$cart_item['discount'] / $quantity), NULL, true) : 0; |
|
1830 | 1830 | $discount_decrease = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; |
1831 | - $tax_decrease = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_format_amount( ( (float)$cart_item['tax'] / $quantity ), NULL, true ) : 0; |
|
1831 | + $tax_decrease = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_format_amount(((float)$cart_item['tax'] / $quantity), NULL, true) : 0; |
|
1832 | 1832 | $tax_decrease = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease; |
1833 | 1833 | |
1834 | 1834 | // The total increase equals the number removed * the item_price |
1835 | - $total_decrease = wpinv_format_amount( $item_price, NULL, true ); |
|
1835 | + $total_decrease = wpinv_format_amount($item_price, NULL, true); |
|
1836 | 1836 | |
1837 | - if ( wpinv_prices_include_tax() ) { |
|
1838 | - $subtotal -= wpinv_format_amount( $tax, NULL, true ); |
|
1837 | + if (wpinv_prices_include_tax()) { |
|
1838 | + $subtotal -= wpinv_format_amount($tax, NULL, true); |
|
1839 | 1839 | } |
1840 | 1840 | |
1841 | - $total = $subtotal - $discount + $tax; |
|
1841 | + $total = $subtotal - $discount + $tax; |
|
1842 | 1842 | |
1843 | 1843 | // Do not allow totals to go negative |
1844 | - if( $total < 0 ) { |
|
1844 | + if ($total < 0) { |
|
1845 | 1845 | $total = 0; |
1846 | 1846 | } |
1847 | 1847 | |
@@ -1860,16 +1860,16 @@ discard block |
||
1860 | 1860 | |
1861 | 1861 | $this->cart_details[$found_cart_key] = $cart_item; |
1862 | 1862 | |
1863 | - $remove_item = end( $this->cart_details ); |
|
1863 | + $remove_item = end($this->cart_details); |
|
1864 | 1864 | } else { |
1865 | 1865 | $item_price = $cart_item['item_price']; |
1866 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
1867 | - $tax = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0; |
|
1866 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
1867 | + $tax = !empty($cart_item['tax']) ? $cart_item['tax'] : 0; |
|
1868 | 1868 | |
1869 | - $subtotal_decrease = ( $item_price * $quantity ) - $discount; |
|
1869 | + $subtotal_decrease = ($item_price * $quantity) - $discount; |
|
1870 | 1870 | $tax_decrease = $tax; |
1871 | 1871 | |
1872 | - unset( $this->cart_details[$found_cart_key] ); |
|
1872 | + unset($this->cart_details[$found_cart_key]); |
|
1873 | 1873 | |
1874 | 1874 | $remove_item = $args; |
1875 | 1875 | $remove_item['id'] = $item_id; |
@@ -1880,8 +1880,8 @@ discard block |
||
1880 | 1880 | $remove_item['action'] = 'remove'; |
1881 | 1881 | $this->pending['items'][] = $remove_item; |
1882 | 1882 | |
1883 | - $this->decrease_subtotal( $subtotal_decrease ); |
|
1884 | - $this->decrease_tax( $tax_decrease ); |
|
1883 | + $this->decrease_subtotal($subtotal_decrease); |
|
1884 | + $this->decrease_tax($tax_decrease); |
|
1885 | 1885 | |
1886 | 1886 | return true; |
1887 | 1887 | } |
@@ -1889,7 +1889,7 @@ discard block |
||
1889 | 1889 | public function update_items($temp = false) { |
1890 | 1890 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave; |
1891 | 1891 | |
1892 | - if ( !empty( $this->cart_details ) ) { |
|
1892 | + if (!empty($this->cart_details)) { |
|
1893 | 1893 | $wpi_nosave = $temp; |
1894 | 1894 | $cart_subtotal = 0; |
1895 | 1895 | $cart_discount = 0; |
@@ -1899,41 +1899,41 @@ discard block |
||
1899 | 1899 | $_POST['wpinv_country'] = $this->country; |
1900 | 1900 | $_POST['wpinv_state'] = $this->state; |
1901 | 1901 | |
1902 | - foreach ( $this->cart_details as $key => $item ) { |
|
1902 | + foreach ($this->cart_details as $key => $item) { |
|
1903 | 1903 | $item_price = $item['item_price']; |
1904 | - $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
1905 | - $amount = wpinv_format_amount( $item_price * $quantity, NULL, true ); |
|
1904 | + $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
1905 | + $amount = wpinv_format_amount($item_price * $quantity, NULL, true); |
|
1906 | 1906 | $subtotal = $item_price * $quantity; |
1907 | 1907 | |
1908 | 1908 | $wpi_current_id = $this->ID; |
1909 | 1909 | $wpi_item_id = $item['id']; |
1910 | 1910 | |
1911 | - $discount = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() ); |
|
1911 | + $discount = wpinv_get_cart_item_discount_amount($item, $this->get_discounts()); |
|
1912 | 1912 | |
1913 | - $tax_rate = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id ); |
|
1914 | - $tax_class = $wpinv_euvat->get_item_class( $wpi_item_id ); |
|
1915 | - $tax = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1913 | + $tax_rate = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id); |
|
1914 | + $tax_class = $wpinv_euvat->get_item_class($wpi_item_id); |
|
1915 | + $tax = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0; |
|
1916 | 1916 | |
1917 | - if ( wpinv_prices_include_tax() ) { |
|
1918 | - $subtotal -= wpinv_format_amount( $tax, NULL, true ); |
|
1917 | + if (wpinv_prices_include_tax()) { |
|
1918 | + $subtotal -= wpinv_format_amount($tax, NULL, true); |
|
1919 | 1919 | } |
1920 | 1920 | |
1921 | - $total = $subtotal - $discount + $tax; |
|
1921 | + $total = $subtotal - $discount + $tax; |
|
1922 | 1922 | |
1923 | 1923 | // Do not allow totals to go negative |
1924 | - if( $total < 0 ) { |
|
1924 | + if ($total < 0) { |
|
1925 | 1925 | $total = 0; |
1926 | 1926 | } |
1927 | 1927 | |
1928 | 1928 | $cart_details[] = array( |
1929 | 1929 | 'id' => $item['id'], |
1930 | 1930 | 'name' => $item['name'], |
1931 | - 'item_price' => wpinv_format_amount( $item_price, NULL, true ), |
|
1931 | + 'item_price' => wpinv_format_amount($item_price, NULL, true), |
|
1932 | 1932 | 'quantity' => $quantity, |
1933 | 1933 | 'discount' => $discount, |
1934 | - 'subtotal' => wpinv_format_amount( $subtotal, NULL, true ), |
|
1935 | - 'tax' => wpinv_format_amount( $tax, NULL, true ), |
|
1936 | - 'price' => wpinv_format_amount( $total, NULL, true ), |
|
1934 | + 'subtotal' => wpinv_format_amount($subtotal, NULL, true), |
|
1935 | + 'tax' => wpinv_format_amount($tax, NULL, true), |
|
1936 | + 'price' => wpinv_format_amount($total, NULL, true), |
|
1937 | 1937 | 'vat_rate' => $tax_rate, |
1938 | 1938 | 'vat_class' => $tax_class, |
1939 | 1939 | 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
@@ -1944,9 +1944,9 @@ discard block |
||
1944 | 1944 | $cart_discount += (float)($discount); |
1945 | 1945 | $cart_tax += (float)($tax); |
1946 | 1946 | } |
1947 | - $this->subtotal = wpinv_format_amount( $cart_subtotal, NULL, true ); |
|
1948 | - $this->tax = wpinv_format_amount( $cart_tax, NULL, true ); |
|
1949 | - $this->discount = wpinv_format_amount( $cart_discount, NULL, true ); |
|
1947 | + $this->subtotal = wpinv_format_amount($cart_subtotal, NULL, true); |
|
1948 | + $this->tax = wpinv_format_amount($cart_tax, NULL, true); |
|
1949 | + $this->discount = wpinv_format_amount($cart_discount, NULL, true); |
|
1950 | 1950 | |
1951 | 1951 | $this->recalculate_total(); |
1952 | 1952 | |
@@ -1958,221 +1958,221 @@ discard block |
||
1958 | 1958 | |
1959 | 1959 | public function recalculate_totals($temp = false) { |
1960 | 1960 | $this->update_items($temp); |
1961 | - $this->save( true ); |
|
1961 | + $this->save(true); |
|
1962 | 1962 | |
1963 | 1963 | return $this; |
1964 | 1964 | } |
1965 | 1965 | |
1966 | 1966 | public function needs_payment() { |
1967 | - $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'pending' ), $this ); |
|
1967 | + $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('pending'), $this); |
|
1968 | 1968 | |
1969 | - if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() ) ) { |
|
1969 | + if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial())) { |
|
1970 | 1970 | $needs_payment = true; |
1971 | 1971 | } else { |
1972 | 1972 | $needs_payment = false; |
1973 | 1973 | } |
1974 | 1974 | |
1975 | - return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses ); |
|
1975 | + return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses); |
|
1976 | 1976 | } |
1977 | 1977 | |
1978 | - public function get_checkout_payment_url( $on_checkout = false, $secret = false ) { |
|
1978 | + public function get_checkout_payment_url($on_checkout = false, $secret = false) { |
|
1979 | 1979 | $pay_url = wpinv_get_checkout_uri(); |
1980 | 1980 | |
1981 | - if ( is_ssl() ) { |
|
1982 | - $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
|
1981 | + if (is_ssl()) { |
|
1982 | + $pay_url = str_replace('http:', 'https:', $pay_url); |
|
1983 | 1983 | } |
1984 | 1984 | |
1985 | 1985 | $key = $this->get_key(); |
1986 | 1986 | |
1987 | - if ( $on_checkout ) { |
|
1988 | - $pay_url = add_query_arg( 'invoice_key', $key, $pay_url ); |
|
1987 | + if ($on_checkout) { |
|
1988 | + $pay_url = add_query_arg('invoice_key', $key, $pay_url); |
|
1989 | 1989 | } else { |
1990 | - $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url ); |
|
1990 | + $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url); |
|
1991 | 1991 | } |
1992 | 1992 | |
1993 | - if ( $secret ) { |
|
1994 | - $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url ); |
|
1993 | + if ($secret) { |
|
1994 | + $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url); |
|
1995 | 1995 | } |
1996 | 1996 | |
1997 | - return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this ); |
|
1997 | + return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this); |
|
1998 | 1998 | } |
1999 | 1999 | |
2000 | - public function get_view_url( $secret = false ) { |
|
2001 | - $print_url = get_permalink( $this->ID ); |
|
2000 | + public function get_view_url($secret = false) { |
|
2001 | + $print_url = get_permalink($this->ID); |
|
2002 | 2002 | |
2003 | - if ( $secret ) { |
|
2004 | - $print_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $print_url ); |
|
2003 | + if ($secret) { |
|
2004 | + $print_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $print_url); |
|
2005 | 2005 | } |
2006 | 2006 | |
2007 | - return apply_filters( 'wpinv_get_view_url', $print_url, $this ); |
|
2007 | + return apply_filters('wpinv_get_view_url', $print_url, $this); |
|
2008 | 2008 | } |
2009 | 2009 | |
2010 | - public function generate_key( $string = '' ) { |
|
2011 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
2012 | - return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) ); // Unique key |
|
2010 | + public function generate_key($string = '') { |
|
2011 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
2012 | + return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key |
|
2013 | 2013 | } |
2014 | 2014 | |
2015 | 2015 | public function is_recurring() { |
2016 | - if ( empty( $this->cart_details ) ) { |
|
2016 | + if (empty($this->cart_details)) { |
|
2017 | 2017 | return false; |
2018 | 2018 | } |
2019 | 2019 | |
2020 | 2020 | $has_subscription = false; |
2021 | - foreach( $this->cart_details as $cart_item ) { |
|
2022 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
2021 | + foreach ($this->cart_details as $cart_item) { |
|
2022 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
2023 | 2023 | $has_subscription = true; |
2024 | 2024 | break; |
2025 | 2025 | } |
2026 | 2026 | } |
2027 | 2027 | |
2028 | - if ( count( $this->cart_details ) > 1 ) { |
|
2028 | + if (count($this->cart_details) > 1) { |
|
2029 | 2029 | $has_subscription = false; |
2030 | 2030 | } |
2031 | 2031 | |
2032 | - return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details ); |
|
2032 | + return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details); |
|
2033 | 2033 | } |
2034 | 2034 | |
2035 | 2035 | public function is_free_trial() { |
2036 | 2036 | $is_free_trial = false; |
2037 | 2037 | |
2038 | - if ( $this->is_parent() && $item = $this->get_recurring( true ) ) { |
|
2039 | - if ( !empty( $item ) && $item->has_free_trial() ) { |
|
2038 | + if ($this->is_parent() && $item = $this->get_recurring(true)) { |
|
2039 | + if (!empty($item) && $item->has_free_trial()) { |
|
2040 | 2040 | $is_free_trial = true; |
2041 | 2041 | } |
2042 | 2042 | } |
2043 | 2043 | |
2044 | - return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details ); |
|
2044 | + return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details); |
|
2045 | 2045 | } |
2046 | 2046 | |
2047 | - public function get_recurring( $object = false ) { |
|
2047 | + public function get_recurring($object = false) { |
|
2048 | 2048 | $item = NULL; |
2049 | 2049 | |
2050 | - if ( empty( $this->cart_details ) ) { |
|
2050 | + if (empty($this->cart_details)) { |
|
2051 | 2051 | return $item; |
2052 | 2052 | } |
2053 | 2053 | |
2054 | - foreach( $this->cart_details as $cart_item ) { |
|
2055 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
2054 | + foreach ($this->cart_details as $cart_item) { |
|
2055 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
2056 | 2056 | $item = $cart_item['id']; |
2057 | 2057 | break; |
2058 | 2058 | } |
2059 | 2059 | } |
2060 | 2060 | |
2061 | - if ( $object ) { |
|
2062 | - $item = $item ? new WPInv_Item( $item ) : NULL; |
|
2061 | + if ($object) { |
|
2062 | + $item = $item ? new WPInv_Item($item) : NULL; |
|
2063 | 2063 | |
2064 | - apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this ); |
|
2064 | + apply_filters('wpinv_invoice_get_recurring_item', $item, $this); |
|
2065 | 2065 | } |
2066 | 2066 | |
2067 | - return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this ); |
|
2067 | + return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this); |
|
2068 | 2068 | } |
2069 | 2069 | |
2070 | 2070 | public function get_subscription_name() { |
2071 | - $item = $this->get_recurring( true ); |
|
2071 | + $item = $this->get_recurring(true); |
|
2072 | 2072 | |
2073 | - if ( empty( $item ) ) { |
|
2073 | + if (empty($item)) { |
|
2074 | 2074 | return NULL; |
2075 | 2075 | } |
2076 | 2076 | |
2077 | - if ( !($name = $item->get_name()) ) { |
|
2077 | + if (!($name = $item->get_name())) { |
|
2078 | 2078 | $name = $item->post_name; |
2079 | 2079 | } |
2080 | 2080 | |
2081 | - return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this ); |
|
2081 | + return apply_filters('wpinv_invoice_get_subscription_name', $name, $this); |
|
2082 | 2082 | } |
2083 | 2083 | |
2084 | 2084 | public function get_expiration() { |
2085 | - $expiration = $this->get_meta( '_wpinv_subscr_expiration', true ); |
|
2085 | + $expiration = $this->get_meta('_wpinv_subscr_expiration', true); |
|
2086 | 2086 | return $expiration; |
2087 | 2087 | } |
2088 | 2088 | |
2089 | - public function get_cancelled_date( $formatted = true ) { |
|
2090 | - $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta( '_wpinv_subscr_cancelled_on', true ) : ''; |
|
2089 | + public function get_cancelled_date($formatted = true) { |
|
2090 | + $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta('_wpinv_subscr_cancelled_on', true) : ''; |
|
2091 | 2091 | |
2092 | - if ( $formatted && $cancelled_date ) { |
|
2093 | - $cancelled_date = date_i18n( get_option( 'date_format' ), strtotime( $cancelled_date ) ); |
|
2092 | + if ($formatted && $cancelled_date) { |
|
2093 | + $cancelled_date = date_i18n(get_option('date_format'), strtotime($cancelled_date)); |
|
2094 | 2094 | } |
2095 | 2095 | |
2096 | 2096 | return $cancelled_date; |
2097 | 2097 | } |
2098 | 2098 | |
2099 | - public function get_trial_end_date( $formatted = true ) { |
|
2100 | - if ( !$this->is_free_trial() || !$this->is_paid() ) { |
|
2099 | + public function get_trial_end_date($formatted = true) { |
|
2100 | + if (!$this->is_free_trial() || !$this->is_paid()) { |
|
2101 | 2101 | return NULL; |
2102 | 2102 | } |
2103 | 2103 | |
2104 | - $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta( '_wpinv_subscr_trial_end', true ) : ''; |
|
2104 | + $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta('_wpinv_subscr_trial_end', true) : ''; |
|
2105 | 2105 | |
2106 | - if ( empty( $trial_end_date ) ) { |
|
2107 | - $trial_start_time = strtotime( $this->get_subscription_start() ); |
|
2108 | - $trial_start_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ; |
|
2106 | + if (empty($trial_end_date)) { |
|
2107 | + $trial_start_time = strtotime($this->get_subscription_start()); |
|
2108 | + $trial_start_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS); |
|
2109 | 2109 | |
2110 | - $trial_end_date = date_i18n( 'Y-m-d H:i:s', $trial_start_time ); |
|
2110 | + $trial_end_date = date_i18n('Y-m-d H:i:s', $trial_start_time); |
|
2111 | 2111 | } |
2112 | 2112 | |
2113 | - if ( $formatted && $trial_end_date ) { |
|
2114 | - $trial_end_date = date_i18n( get_option( 'date_format' ), strtotime( $trial_end_date ) ); |
|
2113 | + if ($formatted && $trial_end_date) { |
|
2114 | + $trial_end_date = date_i18n(get_option('date_format'), strtotime($trial_end_date)); |
|
2115 | 2115 | } |
2116 | 2116 | |
2117 | 2117 | return $trial_end_date; |
2118 | 2118 | } |
2119 | 2119 | |
2120 | - public function get_subscription_created( $default = true ) { |
|
2121 | - $created = $this->get_meta( '_wpinv_subscr_created', true ); |
|
2120 | + public function get_subscription_created($default = true) { |
|
2121 | + $created = $this->get_meta('_wpinv_subscr_created', true); |
|
2122 | 2122 | |
2123 | - if ( empty( $created ) && $default ) { |
|
2123 | + if (empty($created) && $default) { |
|
2124 | 2124 | $created = $this->date; |
2125 | 2125 | } |
2126 | 2126 | return $created; |
2127 | 2127 | } |
2128 | 2128 | |
2129 | - public function get_subscription_start( $formatted = true ) { |
|
2130 | - if ( !$this->is_paid() ) { |
|
2129 | + public function get_subscription_start($formatted = true) { |
|
2130 | + if (!$this->is_paid()) { |
|
2131 | 2131 | return '-'; |
2132 | 2132 | } |
2133 | - $start = $this->get_subscription_created(); |
|
2133 | + $start = $this->get_subscription_created(); |
|
2134 | 2134 | |
2135 | - if ( $formatted ) { |
|
2136 | - $date = date_i18n( get_option( 'date_format' ), strtotime( $start ) ); |
|
2135 | + if ($formatted) { |
|
2136 | + $date = date_i18n(get_option('date_format'), strtotime($start)); |
|
2137 | 2137 | } else { |
2138 | - $date = date_i18n( 'Y-m-d H:i:s', strtotime( $start ) ); |
|
2138 | + $date = date_i18n('Y-m-d H:i:s', strtotime($start)); |
|
2139 | 2139 | } |
2140 | 2140 | |
2141 | 2141 | return $date; |
2142 | 2142 | } |
2143 | 2143 | |
2144 | - public function get_subscription_end( $formatted = true ) { |
|
2145 | - if ( !$this->is_paid() ) { |
|
2144 | + public function get_subscription_end($formatted = true) { |
|
2145 | + if (!$this->is_paid()) { |
|
2146 | 2146 | return '-'; |
2147 | 2147 | } |
2148 | 2148 | $start = $this->get_subscription_created(); |
2149 | 2149 | $interval = $this->get_subscription_interval(); |
2150 | - $period = $this->get_subscription_period( true ); |
|
2150 | + $period = $this->get_subscription_period(true); |
|
2151 | 2151 | $bill_times = (int)$this->get_bill_times(); |
2152 | 2152 | |
2153 | - if ( $bill_times == 0 ) { |
|
2154 | - return $formatted ? __( 'Until cancelled', 'invoicing' ) : $bill_times; |
|
2153 | + if ($bill_times == 0) { |
|
2154 | + return $formatted ? __('Until cancelled', 'invoicing') : $bill_times; |
|
2155 | 2155 | } |
2156 | 2156 | |
2157 | - $total_period = $start . '+' . ( $interval * $bill_times ) . ' ' . $period; |
|
2157 | + $total_period = $start . '+' . ($interval * $bill_times) . ' ' . $period; |
|
2158 | 2158 | |
2159 | - $end_time = strtotime( $start . '+' . ( $interval * $bill_times ) . ' ' . $period ); |
|
2159 | + $end_time = strtotime($start . '+' . ($interval * $bill_times) . ' ' . $period); |
|
2160 | 2160 | |
2161 | - if ( $this->is_free_trial() ) { |
|
2162 | - $end_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ; |
|
2161 | + if ($this->is_free_trial()) { |
|
2162 | + $end_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS); |
|
2163 | 2163 | } |
2164 | 2164 | |
2165 | - if ( $formatted ) { |
|
2166 | - $date = date_i18n( get_option( 'date_format' ), $end_time ); |
|
2165 | + if ($formatted) { |
|
2166 | + $date = date_i18n(get_option('date_format'), $end_time); |
|
2167 | 2167 | } else { |
2168 | - $date = date_i18n( 'Y-m-d H:i:s', $end_time ); |
|
2168 | + $date = date_i18n('Y-m-d H:i:s', $end_time); |
|
2169 | 2169 | } |
2170 | 2170 | |
2171 | 2171 | return $date; |
2172 | 2172 | } |
2173 | 2173 | |
2174 | 2174 | public function get_expiration_time() { |
2175 | - return strtotime( $this->get_expiration(), current_time( 'timestamp' ) ); |
|
2175 | + return strtotime($this->get_expiration(), current_time('timestamp')); |
|
2176 | 2176 | } |
2177 | 2177 | |
2178 | 2178 | public function get_original_invoice_id() { |
@@ -2184,125 +2184,125 @@ discard block |
||
2184 | 2184 | return $subscription_data['bill_times']; |
2185 | 2185 | } |
2186 | 2186 | |
2187 | - public function get_child_payments( $self = false ) { |
|
2188 | - $invoices = get_posts( array( |
|
2187 | + public function get_child_payments($self = false) { |
|
2188 | + $invoices = get_posts(array( |
|
2189 | 2189 | 'post_type' => $this->post_type, |
2190 | 2190 | 'post_parent' => (int)$this->ID, |
2191 | 2191 | 'posts_per_page' => '999', |
2192 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
2192 | + 'post_status' => array('publish', 'wpi-processing', 'wpi-renewal'), |
|
2193 | 2193 | 'orderby' => 'ID', |
2194 | 2194 | 'order' => 'DESC', |
2195 | 2195 | 'fields' => 'ids' |
2196 | - ) ); |
|
2196 | + )); |
|
2197 | 2197 | |
2198 | - if ( $this->is_free_trial() ) { |
|
2198 | + if ($this->is_free_trial()) { |
|
2199 | 2199 | $self = false; |
2200 | 2200 | } |
2201 | 2201 | |
2202 | - if ( $self && $this->is_paid() ) { |
|
2203 | - if ( !empty( $invoices ) ) { |
|
2202 | + if ($self && $this->is_paid()) { |
|
2203 | + if (!empty($invoices)) { |
|
2204 | 2204 | $invoices[] = (int)$this->ID; |
2205 | 2205 | } else { |
2206 | - $invoices = array( $this->ID ); |
|
2206 | + $invoices = array($this->ID); |
|
2207 | 2207 | } |
2208 | 2208 | |
2209 | - $invoices = array_unique( $invoices ); |
|
2209 | + $invoices = array_unique($invoices); |
|
2210 | 2210 | } |
2211 | 2211 | |
2212 | 2212 | return $invoices; |
2213 | 2213 | } |
2214 | 2214 | |
2215 | - public function get_total_payments( $self = true ) { |
|
2216 | - return count( $this->get_child_payments( $self ) ); |
|
2215 | + public function get_total_payments($self = true) { |
|
2216 | + return count($this->get_child_payments($self)); |
|
2217 | 2217 | } |
2218 | 2218 | |
2219 | - public function get_subscriptions( $limit = -1 ) { |
|
2220 | - $subscriptions = wpinv_get_subscriptions( array( 'parent_invoice_id' => $this->ID, 'numberposts' => $limit ) ); |
|
2219 | + public function get_subscriptions($limit = -1) { |
|
2220 | + $subscriptions = wpinv_get_subscriptions(array('parent_invoice_id' => $this->ID, 'numberposts' => $limit)); |
|
2221 | 2221 | |
2222 | 2222 | return $subscriptions; |
2223 | 2223 | } |
2224 | 2224 | |
2225 | 2225 | public function get_subscription_id() { |
2226 | - $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true ); |
|
2226 | + $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true); |
|
2227 | 2227 | |
2228 | - if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) { |
|
2229 | - $parent_invoice = wpinv_get_invoice( $this->parent_invoice ); |
|
2228 | + if (empty($subscription_id) && !empty($this->parent_invoice)) { |
|
2229 | + $parent_invoice = wpinv_get_invoice($this->parent_invoice); |
|
2230 | 2230 | |
2231 | - $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true ); |
|
2231 | + $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true); |
|
2232 | 2232 | } |
2233 | 2233 | |
2234 | 2234 | return $subscription_id; |
2235 | 2235 | } |
2236 | 2236 | |
2237 | 2237 | public function get_subscription_status() { |
2238 | - $subscription_status = $this->get_meta( '_wpinv_subscr_status', true ); |
|
2238 | + $subscription_status = $this->get_meta('_wpinv_subscr_status', true); |
|
2239 | 2239 | |
2240 | - if ( empty( $subscription_status ) ) { |
|
2240 | + if (empty($subscription_status)) { |
|
2241 | 2241 | $status = 'pending'; |
2242 | 2242 | |
2243 | - if ( $this->is_paid() ) { |
|
2243 | + if ($this->is_paid()) { |
|
2244 | 2244 | $bill_times = (int)$this->get_bill_times(); |
2245 | 2245 | $times_billed = (int)$this->get_total_payments(); |
2246 | - $expiration = $this->get_subscription_end( false ); |
|
2247 | - $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime( date_i18n( 'Y-m-d', strtotime( $expiration ) ) ) < strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) ) ? true : false; |
|
2246 | + $expiration = $this->get_subscription_end(false); |
|
2247 | + $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime(date_i18n('Y-m-d', strtotime($expiration))) < strtotime(date_i18n('Y-m-d', current_time('timestamp'))) ? true : false; |
|
2248 | 2248 | |
2249 | - if ( (int)$bill_times == 0 ) { |
|
2249 | + if ((int)$bill_times == 0) { |
|
2250 | 2250 | $status = $expired ? 'expired' : 'active'; |
2251 | - } else if ( $bill_times > 0 && $times_billed >= $bill_times ) { |
|
2251 | + } else if ($bill_times > 0 && $times_billed >= $bill_times) { |
|
2252 | 2252 | $status = 'completed'; |
2253 | - } else if ( $expired ) { |
|
2253 | + } else if ($expired) { |
|
2254 | 2254 | $status = 'expired'; |
2255 | - } else if ( $bill_times > 0 ) { |
|
2255 | + } else if ($bill_times > 0) { |
|
2256 | 2256 | $status = 'active'; |
2257 | 2257 | } else { |
2258 | 2258 | $status = 'pending'; |
2259 | 2259 | } |
2260 | 2260 | } |
2261 | 2261 | |
2262 | - if ( $status && $status != $subscription_status ) { |
|
2262 | + if ($status && $status != $subscription_status) { |
|
2263 | 2263 | $subscription_status = $status; |
2264 | 2264 | |
2265 | - $this->update_meta( '_wpinv_subscr_status', $status ); |
|
2265 | + $this->update_meta('_wpinv_subscr_status', $status); |
|
2266 | 2266 | } |
2267 | 2267 | } |
2268 | 2268 | |
2269 | 2269 | return $subscription_status; |
2270 | 2270 | } |
2271 | 2271 | |
2272 | - public function get_subscription_status_label( $status = '' ) { |
|
2273 | - $status = !empty( $status ) ? $status : $this->get_subscription_status(); |
|
2272 | + public function get_subscription_status_label($status = '') { |
|
2273 | + $status = !empty($status) ? $status : $this->get_subscription_status(); |
|
2274 | 2274 | |
2275 | - switch( $status ) { |
|
2275 | + switch ($status) { |
|
2276 | 2276 | case 'active' : |
2277 | - $status_label = __( 'Active', 'invoicing' ); |
|
2277 | + $status_label = __('Active', 'invoicing'); |
|
2278 | 2278 | break; |
2279 | 2279 | |
2280 | 2280 | case 'cancelled' : |
2281 | - $status_label = __( 'Cancelled', 'invoicing' ); |
|
2281 | + $status_label = __('Cancelled', 'invoicing'); |
|
2282 | 2282 | break; |
2283 | 2283 | |
2284 | 2284 | case 'completed' : |
2285 | - $status_label = __( 'Completed', 'invoicing' ); |
|
2285 | + $status_label = __('Completed', 'invoicing'); |
|
2286 | 2286 | break; |
2287 | 2287 | |
2288 | 2288 | case 'expired' : |
2289 | - $status_label = __( 'Expired', 'invoicing' ); |
|
2289 | + $status_label = __('Expired', 'invoicing'); |
|
2290 | 2290 | break; |
2291 | 2291 | |
2292 | 2292 | case 'pending' : |
2293 | - $status_label = __( 'Pending', 'invoicing' ); |
|
2293 | + $status_label = __('Pending', 'invoicing'); |
|
2294 | 2294 | break; |
2295 | 2295 | |
2296 | 2296 | case 'failing' : |
2297 | - $status_label = __( 'Failing', 'invoicing' ); |
|
2297 | + $status_label = __('Failing', 'invoicing'); |
|
2298 | 2298 | break; |
2299 | 2299 | |
2300 | 2300 | case 'stopped' : |
2301 | - $status_label = __( 'Stopped', 'invoicing' ); |
|
2301 | + $status_label = __('Stopped', 'invoicing'); |
|
2302 | 2302 | break; |
2303 | 2303 | |
2304 | 2304 | case 'trialing' : |
2305 | - $status_label = __( 'Trialing', 'invoicing' ); |
|
2305 | + $status_label = __('Trialing', 'invoicing'); |
|
2306 | 2306 | break; |
2307 | 2307 | |
2308 | 2308 | default: |
@@ -2313,26 +2313,26 @@ discard block |
||
2313 | 2313 | return $status_label; |
2314 | 2314 | } |
2315 | 2315 | |
2316 | - public function get_subscription_period( $full = false ) { |
|
2317 | - $period = $this->get_meta( '_wpinv_subscr_period', true ); |
|
2316 | + public function get_subscription_period($full = false) { |
|
2317 | + $period = $this->get_meta('_wpinv_subscr_period', true); |
|
2318 | 2318 | |
2319 | 2319 | // Fix period for old invoices |
2320 | - if ( $period == 'day' ) { |
|
2320 | + if ($period == 'day') { |
|
2321 | 2321 | $period = 'D'; |
2322 | - } else if ( $period == 'week' ) { |
|
2322 | + } else if ($period == 'week') { |
|
2323 | 2323 | $period = 'W'; |
2324 | - } else if ( $period == 'month' ) { |
|
2324 | + } else if ($period == 'month') { |
|
2325 | 2325 | $period = 'M'; |
2326 | - } else if ( $period == 'year' ) { |
|
2326 | + } else if ($period == 'year') { |
|
2327 | 2327 | $period = 'Y'; |
2328 | 2328 | } |
2329 | 2329 | |
2330 | - if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { |
|
2330 | + if (!in_array($period, array('D', 'W', 'M', 'Y'))) { |
|
2331 | 2331 | $period = 'D'; |
2332 | 2332 | } |
2333 | 2333 | |
2334 | - if ( $full ) { |
|
2335 | - switch( $period ) { |
|
2334 | + if ($full) { |
|
2335 | + switch ($period) { |
|
2336 | 2336 | case 'D': |
2337 | 2337 | $period = 'day'; |
2338 | 2338 | break; |
@@ -2352,39 +2352,39 @@ discard block |
||
2352 | 2352 | } |
2353 | 2353 | |
2354 | 2354 | public function get_subscription_interval() { |
2355 | - $interval = (int)$this->get_meta( '_wpinv_subscr_interval', true ); |
|
2355 | + $interval = (int)$this->get_meta('_wpinv_subscr_interval', true); |
|
2356 | 2356 | |
2357 | - if ( !$interval > 0 ) { |
|
2357 | + if (!$interval > 0) { |
|
2358 | 2358 | $interval = 1; |
2359 | 2359 | } |
2360 | 2360 | |
2361 | 2361 | return $interval; |
2362 | 2362 | } |
2363 | 2363 | |
2364 | - public function get_subscription_trial_period( $full = false ) { |
|
2365 | - if ( !$this->is_free_trial() ) { |
|
2364 | + public function get_subscription_trial_period($full = false) { |
|
2365 | + if (!$this->is_free_trial()) { |
|
2366 | 2366 | return ''; |
2367 | 2367 | } |
2368 | 2368 | |
2369 | - $period = $this->get_meta( '_wpinv_subscr_trial_period', true ); |
|
2369 | + $period = $this->get_meta('_wpinv_subscr_trial_period', true); |
|
2370 | 2370 | |
2371 | 2371 | // Fix period for old invoices |
2372 | - if ( $period == 'day' ) { |
|
2372 | + if ($period == 'day') { |
|
2373 | 2373 | $period = 'D'; |
2374 | - } else if ( $period == 'week' ) { |
|
2374 | + } else if ($period == 'week') { |
|
2375 | 2375 | $period = 'W'; |
2376 | - } else if ( $period == 'month' ) { |
|
2376 | + } else if ($period == 'month') { |
|
2377 | 2377 | $period = 'M'; |
2378 | - } else if ( $period == 'year' ) { |
|
2378 | + } else if ($period == 'year') { |
|
2379 | 2379 | $period = 'Y'; |
2380 | 2380 | } |
2381 | 2381 | |
2382 | - if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { |
|
2382 | + if (!in_array($period, array('D', 'W', 'M', 'Y'))) { |
|
2383 | 2383 | $period = 'D'; |
2384 | 2384 | } |
2385 | 2385 | |
2386 | - if ( $full ) { |
|
2387 | - switch( $period ) { |
|
2386 | + if ($full) { |
|
2387 | + switch ($period) { |
|
2388 | 2388 | case 'D': |
2389 | 2389 | $period = 'day'; |
2390 | 2390 | break; |
@@ -2404,13 +2404,13 @@ discard block |
||
2404 | 2404 | } |
2405 | 2405 | |
2406 | 2406 | public function get_subscription_trial_interval() { |
2407 | - if ( !$this->is_free_trial() ) { |
|
2407 | + if (!$this->is_free_trial()) { |
|
2408 | 2408 | return 0; |
2409 | 2409 | } |
2410 | 2410 | |
2411 | - $interval = (int)$this->get_meta( '_wpinv_subscr_trial_interval', true ); |
|
2411 | + $interval = (int)$this->get_meta('_wpinv_subscr_trial_interval', true); |
|
2412 | 2412 | |
2413 | - if ( !$interval > 0 ) { |
|
2413 | + if (!$interval > 0) { |
|
2414 | 2414 | $interval = 1; |
2415 | 2415 | } |
2416 | 2416 | |
@@ -2422,8 +2422,8 @@ discard block |
||
2422 | 2422 | 'status' => 'failing' |
2423 | 2423 | ); |
2424 | 2424 | |
2425 | - if ( $this->update_subscription( $args ) ) { |
|
2426 | - do_action( 'wpinv_subscription_failing', $this->ID, $this ); |
|
2425 | + if ($this->update_subscription($args)) { |
|
2426 | + do_action('wpinv_subscription_failing', $this->ID, $this); |
|
2427 | 2427 | return true; |
2428 | 2428 | } |
2429 | 2429 | |
@@ -2435,8 +2435,8 @@ discard block |
||
2435 | 2435 | 'status' => 'stopped' |
2436 | 2436 | ); |
2437 | 2437 | |
2438 | - if ( $this->update_subscription( $args ) ) { |
|
2439 | - do_action( 'wpinv_subscription_stopped', $this->ID, $this ); |
|
2438 | + if ($this->update_subscription($args)) { |
|
2439 | + do_action('wpinv_subscription_stopped', $this->ID, $this); |
|
2440 | 2440 | return true; |
2441 | 2441 | } |
2442 | 2442 | |
@@ -2448,8 +2448,8 @@ discard block |
||
2448 | 2448 | 'status' => 'active' |
2449 | 2449 | ); |
2450 | 2450 | |
2451 | - if ( $this->update_subscription( $args ) ) { |
|
2452 | - do_action( 'wpinv_subscription_restarted', $this->ID, $this ); |
|
2451 | + if ($this->update_subscription($args)) { |
|
2452 | + do_action('wpinv_subscription_restarted', $this->ID, $this); |
|
2453 | 2453 | return true; |
2454 | 2454 | } |
2455 | 2455 | |
@@ -2461,23 +2461,23 @@ discard block |
||
2461 | 2461 | 'status' => 'cancelled' |
2462 | 2462 | ); |
2463 | 2463 | |
2464 | - if ( $this->update_subscription( $args ) ) { |
|
2465 | - if ( is_user_logged_in() ) { |
|
2466 | - $userdata = get_userdata( get_current_user_id() ); |
|
2464 | + if ($this->update_subscription($args)) { |
|
2465 | + if (is_user_logged_in()) { |
|
2466 | + $userdata = get_userdata(get_current_user_id()); |
|
2467 | 2467 | $user = $userdata->user_login; |
2468 | 2468 | } else { |
2469 | - $user = __( 'gateway', 'invoicing' ); |
|
2469 | + $user = __('gateway', 'invoicing'); |
|
2470 | 2470 | } |
2471 | 2471 | |
2472 | 2472 | $subscription_id = $this->get_subscription_id(); |
2473 | - if ( !$subscription_id ) { |
|
2473 | + if (!$subscription_id) { |
|
2474 | 2474 | $subscription_id = $this->ID; |
2475 | 2475 | } |
2476 | 2476 | |
2477 | - $note = sprintf( __( 'Subscription %s has been cancelled by %s', 'invoicing' ), $subscription_id, $user ); |
|
2478 | - $this->add_note( $note ); |
|
2477 | + $note = sprintf(__('Subscription %s has been cancelled by %s', 'invoicing'), $subscription_id, $user); |
|
2478 | + $this->add_note($note); |
|
2479 | 2479 | |
2480 | - do_action( 'wpinv_subscription_cancelled', $this->ID, $this ); |
|
2480 | + do_action('wpinv_subscription_cancelled', $this->ID, $this); |
|
2481 | 2481 | return true; |
2482 | 2482 | } |
2483 | 2483 | |
@@ -2485,11 +2485,11 @@ discard block |
||
2485 | 2485 | } |
2486 | 2486 | |
2487 | 2487 | public function can_cancel() { |
2488 | - return apply_filters( 'wpinv_subscription_can_cancel', false, $this ); |
|
2488 | + return apply_filters('wpinv_subscription_can_cancel', false, $this); |
|
2489 | 2489 | } |
2490 | 2490 | |
2491 | - public function add_subscription( $data = array() ) { |
|
2492 | - if ( empty( $this->ID ) ) { |
|
2491 | + public function add_subscription($data = array()) { |
|
2492 | + if (empty($this->ID)) { |
|
2493 | 2493 | return false; |
2494 | 2494 | } |
2495 | 2495 | |
@@ -2508,85 +2508,85 @@ discard block |
||
2508 | 2508 | 'profile_id' => '', |
2509 | 2509 | ); |
2510 | 2510 | |
2511 | - $args = wp_parse_args( $data, $defaults ); |
|
2511 | + $args = wp_parse_args($data, $defaults); |
|
2512 | 2512 | |
2513 | - if ( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
2514 | - if ( 'active' == $args['status'] || $args['status'] == 'trialing' ) { |
|
2513 | + if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) { |
|
2514 | + if ('active' == $args['status'] || $args['status'] == 'trialing') { |
|
2515 | 2515 | $args['status'] = 'expired'; |
2516 | 2516 | } |
2517 | 2517 | } |
2518 | 2518 | |
2519 | - do_action( 'wpinv_subscription_pre_create', $args, $data, $this ); |
|
2519 | + do_action('wpinv_subscription_pre_create', $args, $data, $this); |
|
2520 | 2520 | |
2521 | - if ( !empty( $args ) ) { |
|
2522 | - foreach ( $args as $key => $value ) { |
|
2523 | - $this->update_meta( '_wpinv_subscr_' . $key, $value ); |
|
2521 | + if (!empty($args)) { |
|
2522 | + foreach ($args as $key => $value) { |
|
2523 | + $this->update_meta('_wpinv_subscr_' . $key, $value); |
|
2524 | 2524 | } |
2525 | 2525 | } |
2526 | 2526 | |
2527 | - do_action( 'wpinv_subscription_post_create', $args, $data, $this ); |
|
2527 | + do_action('wpinv_subscription_post_create', $args, $data, $this); |
|
2528 | 2528 | |
2529 | 2529 | return true; |
2530 | 2530 | } |
2531 | 2531 | |
2532 | - public function update_subscription( $args = array() ) { |
|
2533 | - if ( empty( $this->ID ) ) { |
|
2532 | + public function update_subscription($args = array()) { |
|
2533 | + if (empty($this->ID)) { |
|
2534 | 2534 | return false; |
2535 | 2535 | } |
2536 | 2536 | |
2537 | - if ( !empty( $args['expiration'] ) && $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
2538 | - if ( !isset( $args['status'] ) || ( isset( $args['status'] ) && ( 'active' == $args['status'] || $args['status'] == 'trialing' ) ) ) { |
|
2537 | + if (!empty($args['expiration']) && $args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) { |
|
2538 | + if (!isset($args['status']) || (isset($args['status']) && ('active' == $args['status'] || $args['status'] == 'trialing'))) { |
|
2539 | 2539 | $args['status'] = 'expired'; |
2540 | 2540 | } |
2541 | 2541 | } |
2542 | 2542 | |
2543 | - if ( isset( $args['status'] ) && $args['status'] == 'cancelled' && empty( $args['cancelled_on'] ) ) { |
|
2544 | - $args['cancelled_on'] = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ); |
|
2543 | + if (isset($args['status']) && $args['status'] == 'cancelled' && empty($args['cancelled_on'])) { |
|
2544 | + $args['cancelled_on'] = date_i18n('Y-m-d H:i:s', current_time('timestamp')); |
|
2545 | 2545 | } |
2546 | 2546 | |
2547 | - do_action( 'wpinv_subscription_pre_update', $args, $this ); |
|
2547 | + do_action('wpinv_subscription_pre_update', $args, $this); |
|
2548 | 2548 | |
2549 | - if ( !empty( $args ) ) { |
|
2550 | - foreach ( $args as $key => $value ) { |
|
2551 | - $this->update_meta( '_wpinv_subscr_' . $key, $value ); |
|
2549 | + if (!empty($args)) { |
|
2550 | + foreach ($args as $key => $value) { |
|
2551 | + $this->update_meta('_wpinv_subscr_' . $key, $value); |
|
2552 | 2552 | } |
2553 | 2553 | } |
2554 | 2554 | |
2555 | - do_action( 'wpinv_subscription_post_update', $args, $this ); |
|
2555 | + do_action('wpinv_subscription_post_update', $args, $this); |
|
2556 | 2556 | |
2557 | 2557 | return true; |
2558 | 2558 | } |
2559 | 2559 | |
2560 | 2560 | public function renew_subscription() { |
2561 | 2561 | $parent_invoice = $this->get_parent_payment(); |
2562 | - $parent_invoice = empty( $parent_invoice ) ? $this : $parent_invoice; |
|
2562 | + $parent_invoice = empty($parent_invoice) ? $this : $parent_invoice; |
|
2563 | 2563 | |
2564 | - $current_time = current_time( 'timestamp' ); |
|
2564 | + $current_time = current_time('timestamp'); |
|
2565 | 2565 | $start = $this->get_subscription_created(); |
2566 | - $start = $start ? strtotime( $start ) : $current_time; |
|
2566 | + $start = $start ? strtotime($start) : $current_time; |
|
2567 | 2567 | $expires = $this->get_expiration_time(); |
2568 | 2568 | |
2569 | - if ( !$expires ) { |
|
2570 | - $expires = strtotime( '+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period( true ), $start ); |
|
2569 | + if (!$expires) { |
|
2570 | + $expires = strtotime('+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period(true), $start); |
|
2571 | 2571 | } |
2572 | 2572 | |
2573 | - $expiration = date_i18n( 'Y-m-d 23:59:59', $expires ); |
|
2574 | - $expiration = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this ); |
|
2573 | + $expiration = date_i18n('Y-m-d 23:59:59', $expires); |
|
2574 | + $expiration = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this); |
|
2575 | 2575 | $bill_times = $parent_invoice->get_bill_times(); |
2576 | 2576 | $times_billed = $parent_invoice->get_total_payments(); |
2577 | 2577 | |
2578 | - if ( $parent_invoice->get_subscription_status() == 'trialing' && ( $times_billed > 0 || strtotime( date_i18n( 'Y-m-d' ) ) < strtotime( $parent_invoice->get_trial_end_date( false ) ) ) ) { |
|
2578 | + if ($parent_invoice->get_subscription_status() == 'trialing' && ($times_billed > 0 || strtotime(date_i18n('Y-m-d')) < strtotime($parent_invoice->get_trial_end_date(false)))) { |
|
2579 | 2579 | $args = array( |
2580 | 2580 | 'status' => 'active', |
2581 | 2581 | ); |
2582 | 2582 | |
2583 | - $parent_invoice->update_subscription( $args ); |
|
2583 | + $parent_invoice->update_subscription($args); |
|
2584 | 2584 | } |
2585 | 2585 | |
2586 | - do_action( 'wpinv_subscription_pre_renew', $this->ID, $expiration, $this ); |
|
2586 | + do_action('wpinv_subscription_pre_renew', $this->ID, $expiration, $this); |
|
2587 | 2587 | |
2588 | - $status = 'active'; |
|
2589 | - if ( $bill_times > 0 && $times_billed >= $bill_times ) { |
|
2588 | + $status = 'active'; |
|
2589 | + if ($bill_times > 0 && $times_billed >= $bill_times) { |
|
2590 | 2590 | $this->complete_subscription(); |
2591 | 2591 | $status = 'completed'; |
2592 | 2592 | } |
@@ -2596,10 +2596,10 @@ discard block |
||
2596 | 2596 | 'status' => $status, |
2597 | 2597 | ); |
2598 | 2598 | |
2599 | - $this->update_subscription( $args ); |
|
2599 | + $this->update_subscription($args); |
|
2600 | 2600 | |
2601 | - do_action( 'wpinv_subscription_post_renew', $this->ID, $expiration, $this ); |
|
2602 | - do_action( 'wpinv_recurring_set_subscription_status', $this->ID, $status, $this ); |
|
2601 | + do_action('wpinv_subscription_post_renew', $this->ID, $expiration, $this); |
|
2602 | + do_action('wpinv_recurring_set_subscription_status', $this->ID, $status, $this); |
|
2603 | 2603 | } |
2604 | 2604 | |
2605 | 2605 | public function complete_subscription() { |
@@ -2607,8 +2607,8 @@ discard block |
||
2607 | 2607 | 'status' => 'completed' |
2608 | 2608 | ); |
2609 | 2609 | |
2610 | - if ( $this->update_subscription( $args ) ) { |
|
2611 | - do_action( 'wpinv_subscription_completed', $this->ID, $this ); |
|
2610 | + if ($this->update_subscription($args)) { |
|
2611 | + do_action('wpinv_subscription_completed', $this->ID, $this); |
|
2612 | 2612 | } |
2613 | 2613 | } |
2614 | 2614 | |
@@ -2617,44 +2617,44 @@ discard block |
||
2617 | 2617 | 'status' => 'expired' |
2618 | 2618 | ); |
2619 | 2619 | |
2620 | - if ( $this->update_subscription( $args ) ) { |
|
2621 | - do_action( 'wpinv_subscription_expired', $this->ID, $this ); |
|
2620 | + if ($this->update_subscription($args)) { |
|
2621 | + do_action('wpinv_subscription_expired', $this->ID, $this); |
|
2622 | 2622 | } |
2623 | 2623 | } |
2624 | 2624 | |
2625 | 2625 | public function get_cancel_url() { |
2626 | - $url = wp_nonce_url( add_query_arg( array( 'wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID ) ), 'wpinv-recurring-cancel' ); |
|
2626 | + $url = wp_nonce_url(add_query_arg(array('wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID)), 'wpinv-recurring-cancel'); |
|
2627 | 2627 | |
2628 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
2628 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
2629 | 2629 | } |
2630 | 2630 | |
2631 | 2631 | public function can_update() { |
2632 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
2632 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
2633 | 2633 | } |
2634 | 2634 | |
2635 | 2635 | public function get_update_url() { |
2636 | - $url = add_query_arg( array( 'action' => 'update', 'sub_id' => $this->ID ) ); |
|
2636 | + $url = add_query_arg(array('action' => 'update', 'sub_id' => $this->ID)); |
|
2637 | 2637 | |
2638 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
2638 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
2639 | 2639 | } |
2640 | 2640 | |
2641 | 2641 | public function is_parent() { |
2642 | - $is_parent = empty( $this->parent_invoice ) ? true : false; |
|
2642 | + $is_parent = empty($this->parent_invoice) ? true : false; |
|
2643 | 2643 | |
2644 | - return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this ); |
|
2644 | + return apply_filters('wpinv_invoice_is_parent', $is_parent, $this); |
|
2645 | 2645 | } |
2646 | 2646 | |
2647 | 2647 | public function is_renewal() { |
2648 | 2648 | $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false; |
2649 | 2649 | |
2650 | - return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this ); |
|
2650 | + return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this); |
|
2651 | 2651 | } |
2652 | 2652 | |
2653 | 2653 | public function get_parent_payment() { |
2654 | 2654 | $parent_payment = NULL; |
2655 | 2655 | |
2656 | - if ( $this->is_renewal() ) { |
|
2657 | - $parent_payment = wpinv_get_invoice( $this->parent_invoice ); |
|
2656 | + if ($this->is_renewal()) { |
|
2657 | + $parent_payment = wpinv_get_invoice($this->parent_invoice); |
|
2658 | 2658 | } |
2659 | 2659 | |
2660 | 2660 | return $parent_payment; |
@@ -2665,100 +2665,100 @@ discard block |
||
2665 | 2665 | |
2666 | 2666 | $subscription_status = $this->get_subscription_status(); |
2667 | 2667 | |
2668 | - if( ! $this->is_subscription_expired() && ( $subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing' ) ) { |
|
2668 | + if (!$this->is_subscription_expired() && ($subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing')) { |
|
2669 | 2669 | $ret = true; |
2670 | 2670 | } |
2671 | 2671 | |
2672 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->ID, $this ); |
|
2672 | + return apply_filters('wpinv_subscription_is_active', $ret, $this->ID, $this); |
|
2673 | 2673 | } |
2674 | 2674 | |
2675 | 2675 | public function is_subscription_expired() { |
2676 | 2676 | $ret = false; |
2677 | 2677 | $subscription_status = $this->get_subscription_status(); |
2678 | 2678 | |
2679 | - if ( $subscription_status == 'expired' ) { |
|
2679 | + if ($subscription_status == 'expired') { |
|
2680 | 2680 | $ret = true; |
2681 | - } else if ( 'active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status ) { |
|
2681 | + } else if ('active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status) { |
|
2682 | 2682 | $ret = false; |
2683 | 2683 | $expiration = $this->get_expiration_time(); |
2684 | 2684 | |
2685 | - if ( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
2685 | + if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) { |
|
2686 | 2686 | $ret = true; |
2687 | 2687 | |
2688 | - if ( 'active' === $subscription_status || 'trialing' === $subscription_status ) { |
|
2688 | + if ('active' === $subscription_status || 'trialing' === $subscription_status) { |
|
2689 | 2689 | $this->expire_subscription(); |
2690 | 2690 | } |
2691 | 2691 | } |
2692 | 2692 | } |
2693 | 2693 | |
2694 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->ID, $this ); |
|
2694 | + return apply_filters('wpinv_subscription_is_expired', $ret, $this->ID, $this); |
|
2695 | 2695 | } |
2696 | 2696 | |
2697 | - public function get_new_expiration( $item_id = 0, $trial = true ) { |
|
2698 | - $item = new WPInv_Item( $item_id ); |
|
2697 | + public function get_new_expiration($item_id = 0, $trial = true) { |
|
2698 | + $item = new WPInv_Item($item_id); |
|
2699 | 2699 | $interval = $item->get_recurring_interval(); |
2700 | - $period = $item->get_recurring_period( true ); |
|
2700 | + $period = $item->get_recurring_period(true); |
|
2701 | 2701 | |
2702 | - $expiration_time = strtotime( '+' . $interval . ' ' . $period ); |
|
2702 | + $expiration_time = strtotime('+' . $interval . ' ' . $period); |
|
2703 | 2703 | |
2704 | - if ( $trial && $this->is_free_trial() && $item->has_free_trial() ) { |
|
2705 | - $expiration_time += ( wpinv_period_in_days( $item->get_trial_interval(), $item->get_trial_period() ) * DAY_IN_SECONDS ) ; |
|
2704 | + if ($trial && $this->is_free_trial() && $item->has_free_trial()) { |
|
2705 | + $expiration_time += (wpinv_period_in_days($item->get_trial_interval(), $item->get_trial_period()) * DAY_IN_SECONDS); |
|
2706 | 2706 | } |
2707 | 2707 | |
2708 | - return date_i18n( 'Y-m-d 23:59:59', $expiration_time ); |
|
2708 | + return date_i18n('Y-m-d 23:59:59', $expiration_time); |
|
2709 | 2709 | } |
2710 | 2710 | |
2711 | - public function get_subscription_data( $filed = '' ) { |
|
2712 | - $fields = array( 'item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on' ); |
|
2711 | + public function get_subscription_data($filed = '') { |
|
2712 | + $fields = array('item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on'); |
|
2713 | 2713 | |
2714 | 2714 | $subscription_meta = array(); |
2715 | - foreach ( $fields as $field ) { |
|
2716 | - $subscription_meta[ $field ] = $this->get_meta( '_wpinv_subscr_' . $field ); |
|
2715 | + foreach ($fields as $field) { |
|
2716 | + $subscription_meta[$field] = $this->get_meta('_wpinv_subscr_' . $field); |
|
2717 | 2717 | } |
2718 | 2718 | |
2719 | - $item = $this->get_recurring( true ); |
|
2719 | + $item = $this->get_recurring(true); |
|
2720 | 2720 | |
2721 | - if ( !empty( $item ) ) { |
|
2722 | - if ( empty( $subscription_meta['item_id'] ) ) { |
|
2721 | + if (!empty($item)) { |
|
2722 | + if (empty($subscription_meta['item_id'])) { |
|
2723 | 2723 | $subscription_meta['item_id'] = $item->ID; |
2724 | 2724 | } |
2725 | - if ( empty( $subscription_meta['period'] ) ) { |
|
2725 | + if (empty($subscription_meta['period'])) { |
|
2726 | 2726 | $subscription_meta['period'] = $item->get_recurring_period(); |
2727 | 2727 | } |
2728 | - if ( empty( $subscription_meta['interval'] ) ) { |
|
2728 | + if (empty($subscription_meta['interval'])) { |
|
2729 | 2729 | $subscription_meta['interval'] = $item->get_recurring_interval(); |
2730 | 2730 | } |
2731 | - if ( $item->has_free_trial() ) { |
|
2732 | - if ( empty( $subscription_meta['trial_period'] ) ) { |
|
2731 | + if ($item->has_free_trial()) { |
|
2732 | + if (empty($subscription_meta['trial_period'])) { |
|
2733 | 2733 | $subscription_meta['trial_period'] = $item->get_trial_period(); |
2734 | 2734 | } |
2735 | - if ( empty( $subscription_meta['trial_interval'] ) ) { |
|
2735 | + if (empty($subscription_meta['trial_interval'])) { |
|
2736 | 2736 | $subscription_meta['trial_interval'] = $item->get_trial_interval(); |
2737 | 2737 | } |
2738 | 2738 | } else { |
2739 | 2739 | $subscription_meta['trial_period'] = ''; |
2740 | 2740 | $subscription_meta['trial_interval'] = 0; |
2741 | 2741 | } |
2742 | - if ( !$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0 ) { |
|
2742 | + if (!$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0) { |
|
2743 | 2743 | $subscription_meta['bill_times'] = $item->get_recurring_limit(); |
2744 | 2744 | } |
2745 | - if ( $subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '' ) { |
|
2746 | - $subscription_meta['initial_amount'] = wpinv_format_amount( $this->get_total() ); |
|
2747 | - $subscription_meta['recurring_amount'] = wpinv_format_amount( $this->get_recurring_details( 'total' ) ); |
|
2745 | + if ($subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '') { |
|
2746 | + $subscription_meta['initial_amount'] = wpinv_format_amount($this->get_total()); |
|
2747 | + $subscription_meta['recurring_amount'] = wpinv_format_amount($this->get_recurring_details('total')); |
|
2748 | 2748 | } |
2749 | 2749 | } |
2750 | 2750 | |
2751 | - if ( $filed === '' ) { |
|
2752 | - return apply_filters( 'wpinv_get_invoice_subscription_data', $subscription_meta, $this ); |
|
2751 | + if ($filed === '') { |
|
2752 | + return apply_filters('wpinv_get_invoice_subscription_data', $subscription_meta, $this); |
|
2753 | 2753 | } |
2754 | 2754 | |
2755 | - $value = isset( $subscription_meta[$filed] ) ? $subscription_meta[$filed] : ''; |
|
2755 | + $value = isset($subscription_meta[$filed]) ? $subscription_meta[$filed] : ''; |
|
2756 | 2756 | |
2757 | - return apply_filters( 'wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this ); |
|
2757 | + return apply_filters('wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this); |
|
2758 | 2758 | } |
2759 | 2759 | |
2760 | 2760 | public function is_paid() { |
2761 | - if ( $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) { |
|
2761 | + if ($this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'))) { |
|
2762 | 2762 | return true; |
2763 | 2763 | } |
2764 | 2764 | |
@@ -2770,28 +2770,28 @@ discard block |
||
2770 | 2770 | |
2771 | 2771 | $requires_vat = false; |
2772 | 2772 | |
2773 | - if ( $this->country ) { |
|
2773 | + if ($this->country) { |
|
2774 | 2774 | $wpi_country = $this->country; |
2775 | 2775 | |
2776 | - $requires_vat = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) ); |
|
2776 | + $requires_vat = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this)); |
|
2777 | 2777 | } |
2778 | 2778 | |
2779 | - return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this ); |
|
2779 | + return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this); |
|
2780 | 2780 | } |
2781 | 2781 | |
2782 | 2782 | public function refresh_item_ids() { |
2783 | 2783 | $item_ids = array(); |
2784 | 2784 | |
2785 | - if ( !empty( $this->cart_details ) ) { |
|
2786 | - foreach ( $this->cart_details as $key => $item ) { |
|
2787 | - if ( !empty( $item['id'] ) ) { |
|
2785 | + if (!empty($this->cart_details)) { |
|
2786 | + foreach ($this->cart_details as $key => $item) { |
|
2787 | + if (!empty($item['id'])) { |
|
2788 | 2788 | $item_ids[] = $item['id']; |
2789 | 2789 | } |
2790 | 2790 | } |
2791 | 2791 | } |
2792 | 2792 | |
2793 | - $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : ''; |
|
2793 | + $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : ''; |
|
2794 | 2794 | |
2795 | - update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids ); |
|
2795 | + update_post_meta($this->ID, '_wpinv_item_ids', $item_ids); |
|
2796 | 2796 | } |
2797 | 2797 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
@@ -14,73 +14,73 @@ discard block |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | public function init() { |
17 | - do_action( 'wpinv_class_notes_init', $this ); |
|
17 | + do_action('wpinv_class_notes_init', $this); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | public function includes() { |
21 | - do_action( 'wpinv_class_notes_includes', $this ); |
|
21 | + do_action('wpinv_class_notes_includes', $this); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function actions() { |
25 | 25 | // Secure inovice notes |
26 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
26 | + add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1); |
|
27 | 27 | |
28 | 28 | // Count comments |
29 | - add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 11, 2 ); |
|
29 | + add_filter('wp_count_comments', array($this, 'wp_count_comments'), 11, 2); |
|
30 | 30 | |
31 | 31 | // Delete comments count cache whenever there is a new comment or a comment status changes |
32 | - add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
33 | - add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
32 | + add_action('wp_insert_comment', array($this, 'delete_comments_count_cache')); |
|
33 | + add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache')); |
|
34 | 34 | |
35 | - do_action( 'wpinv_class_notes_actions', $this ); |
|
35 | + do_action('wpinv_class_notes_actions', $this); |
|
36 | 36 | } |
37 | 37 | |
38 | - public function set_invoice_note_type( $query ) { |
|
39 | - $post_ID = !empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
38 | + public function set_invoice_note_type($query) { |
|
39 | + $post_ID = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
40 | 40 | |
41 | - if ( $post_ID && get_post_type( $post_ID ) == $this->invoice_post_type ) { |
|
41 | + if ($post_ID && get_post_type($post_ID) == $this->invoice_post_type) { |
|
42 | 42 | $query->query_vars['type__in'] = $this->comment_type; |
43 | 43 | $query->query_vars['type__not_in'] = ''; |
44 | 44 | } else { |
45 | - if ( isset( $query->query_vars['type__in'] ) && $type_in = $query->query_vars['type__in'] ) { |
|
46 | - if ( is_array( $type_in ) && in_array( $this->comment_type, $type_in ) ) { |
|
47 | - $key = array_search( $this->comment_type, $type_in ); |
|
48 | - unset( $query->query_vars['type__in'][$key] ); |
|
49 | - } else if ( !is_array( $type_in ) && $type_in == $this->comment_type ) { |
|
45 | + if (isset($query->query_vars['type__in']) && $type_in = $query->query_vars['type__in']) { |
|
46 | + if (is_array($type_in) && in_array($this->comment_type, $type_in)) { |
|
47 | + $key = array_search($this->comment_type, $type_in); |
|
48 | + unset($query->query_vars['type__in'][$key]); |
|
49 | + } else if (!is_array($type_in) && $type_in == $this->comment_type) { |
|
50 | 50 | $query->query_vars['type__in'] = ''; |
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
54 | - if ( isset( $query->query_vars['type__not_in'] ) && $type_not_in = $query->query_vars['type__not_in'] ) { |
|
55 | - if ( is_array( $type_not_in ) && !in_array( $this->comment_type, $type_not_in ) ) { |
|
54 | + if (isset($query->query_vars['type__not_in']) && $type_not_in = $query->query_vars['type__not_in']) { |
|
55 | + if (is_array($type_not_in) && !in_array($this->comment_type, $type_not_in)) { |
|
56 | 56 | $query->query_vars['type__not_in'][] = $this->comment_type; |
57 | - } else if ( !is_array( $type_not_in ) && $type_not_in != $this->comment_type ) { |
|
57 | + } else if (!is_array($type_not_in) && $type_not_in != $this->comment_type) { |
|
58 | 58 | $query->query_vars['type__not_in'] = (array)$query->query_vars['type__not_in']; |
59 | 59 | $query->query_vars['type__not_in'][] = $this->comment_type; |
60 | 60 | } |
61 | 61 | } else { |
62 | - $query->query_vars['type__not_in'] = $this->comment_type; |
|
62 | + $query->query_vars['type__not_in'] = $this->comment_type; |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
66 | 66 | return $query; |
67 | 67 | } |
68 | 68 | |
69 | - public function get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
69 | + public function get_invoice_notes($invoice_id = 0, $type = '') { |
|
70 | 70 | $args = array( |
71 | 71 | 'post_id' => $invoice_id, |
72 | 72 | 'order' => 'comment_date_gmt', |
73 | 73 | 'order' => 'DESC', |
74 | 74 | ); |
75 | 75 | |
76 | - if ( $type == 'customer' ) { |
|
76 | + if ($type == 'customer') { |
|
77 | 77 | $args['meta_key'] = '_wpi_customer_note'; |
78 | 78 | $args['meta_value'] = 1; |
79 | 79 | } |
80 | 80 | |
81 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
81 | + $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type); |
|
82 | 82 | |
83 | - return get_comments( $args ); |
|
83 | + return get_comments($args); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @return void |
92 | 92 | */ |
93 | 93 | public function delete_comments_count_cache() { |
94 | - delete_transient( 'wpinv_count_comments' ); |
|
94 | + delete_transient('wpinv_count_comments'); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -102,16 +102,16 @@ discard block |
||
102 | 102 | * @param int $post_id Post ID. |
103 | 103 | * @return object |
104 | 104 | */ |
105 | - public function wp_count_comments( $stats, $post_id ) { |
|
105 | + public function wp_count_comments($stats, $post_id) { |
|
106 | 106 | global $wpdb; |
107 | 107 | |
108 | - if ( 0 === $post_id ) { |
|
109 | - $stats = get_transient( 'wpinv_count_comments' ); |
|
108 | + if (0 === $post_id) { |
|
109 | + $stats = get_transient('wpinv_count_comments'); |
|
110 | 110 | |
111 | - if ( ! $stats ) { |
|
111 | + if (!$stats) { |
|
112 | 112 | $stats = array(); |
113 | 113 | |
114 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A ); |
|
114 | + $count = $wpdb->get_results("SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A); |
|
115 | 115 | |
116 | 116 | $total = 0; |
117 | 117 | $approved = array( |
@@ -122,26 +122,26 @@ discard block |
||
122 | 122 | 'post-trashed' => 'post-trashed', |
123 | 123 | ); |
124 | 124 | |
125 | - foreach ( (array) $count as $row ) { |
|
125 | + foreach ((array)$count as $row) { |
|
126 | 126 | // Do not count post-trashed toward totals. |
127 | - if ( 'post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved'] ) { |
|
127 | + if ('post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved']) { |
|
128 | 128 | $total += $row['num_comments']; |
129 | 129 | } |
130 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
131 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
130 | + if (isset($approved[$row['comment_approved']])) { |
|
131 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
135 | 135 | $stats['total_comments'] = $total; |
136 | 136 | $stats['all'] = $total; |
137 | - foreach ( $approved as $key ) { |
|
138 | - if ( empty( $stats[ $key ] ) ) { |
|
139 | - $stats[ $key ] = 0; |
|
137 | + foreach ($approved as $key) { |
|
138 | + if (empty($stats[$key])) { |
|
139 | + $stats[$key] = 0; |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
143 | - $stats = (object) $stats; |
|
144 | - set_transient( 'wpinv_count_comments', $stats ); |
|
143 | + $stats = (object)$stats; |
|
144 | + set_transient('wpinv_count_comments', $stats); |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 |