@@ -7,440 +7,440 @@ 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_invoice_cart_id() { |
15 | 15 | $wpinv_checkout = wpinv_get_checkout_session(); |
16 | 16 | |
17 | - if ( !empty( $wpinv_checkout['invoice_id'] ) ) { |
|
17 | + if (!empty($wpinv_checkout['invoice_id'])) { |
|
18 | 18 | return $wpinv_checkout['invoice_id']; |
19 | 19 | } |
20 | 20 | |
21 | 21 | return NULL; |
22 | 22 | } |
23 | 23 | |
24 | -function wpinv_get_invoice( $invoice_id = 0, $cart = false ) { |
|
25 | - if ( $cart && empty( $invoice_id ) ) { |
|
24 | +function wpinv_get_invoice($invoice_id = 0, $cart = false) { |
|
25 | + if ($cart && empty($invoice_id)) { |
|
26 | 26 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
27 | 27 | } |
28 | 28 | |
29 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
29 | + $invoice = new WPInv_Invoice($invoice_id); |
|
30 | 30 | return $invoice; |
31 | 31 | } |
32 | 32 | |
33 | -function wpinv_get_invoice_cart( $invoice_id = 0 ) { |
|
34 | - return wpinv_get_invoice( $invoice_id, true ); |
|
33 | +function wpinv_get_invoice_cart($invoice_id = 0) { |
|
34 | + return wpinv_get_invoice($invoice_id, true); |
|
35 | 35 | } |
36 | 36 | |
37 | -function wpinv_get_invoice_description( $invoice_id = 0 ) { |
|
38 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
37 | +function wpinv_get_invoice_description($invoice_id = 0) { |
|
38 | + $invoice = new WPInv_Invoice($invoice_id); |
|
39 | 39 | return $invoice->get_description(); |
40 | 40 | } |
41 | 41 | |
42 | -function wpinv_get_invoice_currency_code( $invoice_id = 0 ) { |
|
43 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
42 | +function wpinv_get_invoice_currency_code($invoice_id = 0) { |
|
43 | + $invoice = new WPInv_Invoice($invoice_id); |
|
44 | 44 | return $invoice->get_currency(); |
45 | 45 | } |
46 | 46 | |
47 | -function wpinv_get_payment_user_email( $invoice_id ) { |
|
48 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
47 | +function wpinv_get_payment_user_email($invoice_id) { |
|
48 | + $invoice = new WPInv_Invoice($invoice_id); |
|
49 | 49 | return $invoice->get_email(); |
50 | 50 | } |
51 | 51 | |
52 | -function wpinv_get_user_id( $invoice_id ) { |
|
53 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
52 | +function wpinv_get_user_id($invoice_id) { |
|
53 | + $invoice = new WPInv_Invoice($invoice_id); |
|
54 | 54 | return $invoice->get_user_id(); |
55 | 55 | } |
56 | 56 | |
57 | -function wpinv_get_invoice_status( $invoice_id, $return_label = false ) { |
|
58 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
57 | +function wpinv_get_invoice_status($invoice_id, $return_label = false) { |
|
58 | + $invoice = new WPInv_Invoice($invoice_id); |
|
59 | 59 | |
60 | - return $invoice->get_status( $return_label ); |
|
60 | + return $invoice->get_status($return_label); |
|
61 | 61 | } |
62 | 62 | |
63 | -function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) { |
|
64 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
63 | +function wpinv_get_payment_gateway($invoice_id, $return_label = false) { |
|
64 | + $invoice = new WPInv_Invoice($invoice_id); |
|
65 | 65 | |
66 | - return $invoice->get_gateway( $return_label ); |
|
66 | + return $invoice->get_gateway($return_label); |
|
67 | 67 | } |
68 | 68 | |
69 | -function wpinv_get_payment_gateway_name( $invoice_id ) { |
|
70 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
69 | +function wpinv_get_payment_gateway_name($invoice_id) { |
|
70 | + $invoice = new WPInv_Invoice($invoice_id); |
|
71 | 71 | |
72 | 72 | return $invoice->get_gateway_title(); |
73 | 73 | } |
74 | 74 | |
75 | -function wpinv_get_payment_transaction_id( $invoice_id ) { |
|
76 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
75 | +function wpinv_get_payment_transaction_id($invoice_id) { |
|
76 | + $invoice = new WPInv_Invoice($invoice_id); |
|
77 | 77 | |
78 | 78 | return $invoice->get_transaction_id(); |
79 | 79 | } |
80 | 80 | |
81 | -function wpinv_get_id_by_transaction_id( $key ) { |
|
81 | +function wpinv_get_id_by_transaction_id($key) { |
|
82 | 82 | global $wpdb; |
83 | 83 | |
84 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) ); |
|
84 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key)); |
|
85 | 85 | |
86 | - if ( $invoice_id != NULL ) |
|
86 | + if ($invoice_id != NULL) |
|
87 | 87 | return $invoice_id; |
88 | 88 | |
89 | 89 | return 0; |
90 | 90 | } |
91 | 91 | |
92 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
93 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
92 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
93 | + $invoice = new WPInv_Invoice($invoice_id); |
|
94 | 94 | |
95 | - return $invoice->get_meta( $meta_key, $single ); |
|
95 | + return $invoice->get_meta($meta_key, $single); |
|
96 | 96 | } |
97 | 97 | |
98 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
99 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
98 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') { |
|
99 | + $invoice = new WPInv_Invoice($invoice_id); |
|
100 | 100 | |
101 | - return $invoice->update_meta( $meta_key, $meta_value, $prev_value ); |
|
101 | + return $invoice->update_meta($meta_key, $meta_value, $prev_value); |
|
102 | 102 | } |
103 | 103 | |
104 | -function wpinv_get_items( $invoice_id = 0 ) { |
|
105 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
104 | +function wpinv_get_items($invoice_id = 0) { |
|
105 | + $invoice = wpinv_get_invoice($invoice_id); |
|
106 | 106 | |
107 | 107 | $items = $invoice->get_items(); |
108 | 108 | $invoice_currency = $invoice->get_currency(); |
109 | 109 | |
110 | - if ( !empty( $items ) && is_array( $items ) ) { |
|
111 | - foreach ( $items as $key => $item ) { |
|
110 | + if (!empty($items) && is_array($items)) { |
|
111 | + foreach ($items as $key => $item) { |
|
112 | 112 | $items[$key]['currency'] = $invoice_currency; |
113 | 113 | |
114 | - if ( !isset( $cart_item['subtotal'] ) ) { |
|
114 | + if (!isset($cart_item['subtotal'])) { |
|
115 | 115 | $items[$key]['subtotal'] = $items[$key]['amount'] * 1; |
116 | 116 | } |
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | - return apply_filters( 'wpinv_get_items', $items, $invoice_id ); |
|
120 | + return apply_filters('wpinv_get_items', $items, $invoice_id); |
|
121 | 121 | } |
122 | 122 | |
123 | -function wpinv_get_fees( $invoice_id = 0 ) { |
|
124 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
123 | +function wpinv_get_fees($invoice_id = 0) { |
|
124 | + $invoice = wpinv_get_invoice($invoice_id); |
|
125 | 125 | $fees = $invoice->get_fees(); |
126 | 126 | |
127 | - return apply_filters( 'wpinv_get_fees', $fees, $invoice_id ); |
|
127 | + return apply_filters('wpinv_get_fees', $fees, $invoice_id); |
|
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_get_invoice_ip( $invoice_id ) { |
|
131 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
130 | +function wpinv_get_invoice_ip($invoice_id) { |
|
131 | + $invoice = new WPInv_Invoice($invoice_id); |
|
132 | 132 | return $invoice->get_ip(); |
133 | 133 | } |
134 | 134 | |
135 | -function wpinv_get_invoice_user_info( $invoice_id ) { |
|
136 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
135 | +function wpinv_get_invoice_user_info($invoice_id) { |
|
136 | + $invoice = new WPInv_Invoice($invoice_id); |
|
137 | 137 | return $invoice->get_user_info(); |
138 | 138 | } |
139 | 139 | |
140 | -function wpinv_subtotal( $invoice_id = 0, $currency = false ) { |
|
141 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
140 | +function wpinv_subtotal($invoice_id = 0, $currency = false) { |
|
141 | + $invoice = new WPInv_Invoice($invoice_id); |
|
142 | 142 | |
143 | - return $invoice->get_subtotal( $currency ); |
|
143 | + return $invoice->get_subtotal($currency); |
|
144 | 144 | } |
145 | 145 | |
146 | -function wpinv_tax( $invoice_id = 0, $currency = false ) { |
|
147 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
146 | +function wpinv_tax($invoice_id = 0, $currency = false) { |
|
147 | + $invoice = new WPInv_Invoice($invoice_id); |
|
148 | 148 | |
149 | - return $invoice->get_tax( $currency ); |
|
149 | + return $invoice->get_tax($currency); |
|
150 | 150 | } |
151 | 151 | |
152 | -function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) { |
|
153 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
152 | +function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) { |
|
153 | + $invoice = wpinv_get_invoice($invoice_id); |
|
154 | 154 | |
155 | - return $invoice->get_discount( $currency, $dash ); |
|
155 | + return $invoice->get_discount($currency, $dash); |
|
156 | 156 | } |
157 | 157 | |
158 | -function wpinv_discount_code( $invoice_id = 0 ) { |
|
159 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
158 | +function wpinv_discount_code($invoice_id = 0) { |
|
159 | + $invoice = new WPInv_Invoice($invoice_id); |
|
160 | 160 | |
161 | 161 | return $invoice->get_discount_code(); |
162 | 162 | } |
163 | 163 | |
164 | -function wpinv_payment_total( $invoice_id = 0, $currency = false ) { |
|
165 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
164 | +function wpinv_payment_total($invoice_id = 0, $currency = false) { |
|
165 | + $invoice = new WPInv_Invoice($invoice_id); |
|
166 | 166 | |
167 | - return $invoice->get_total( $currency ); |
|
167 | + return $invoice->get_total($currency); |
|
168 | 168 | } |
169 | 169 | |
170 | -function wpinv_get_date_created( $invoice_id = 0 ) { |
|
171 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
170 | +function wpinv_get_date_created($invoice_id = 0) { |
|
171 | + $invoice = new WPInv_Invoice($invoice_id); |
|
172 | 172 | |
173 | 173 | $date_created = $invoice->get_created_date(); |
174 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ), strtotime( $date_created ) ) : ''; |
|
174 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format'), strtotime($date_created)) : ''; |
|
175 | 175 | |
176 | 176 | return $date_created; |
177 | 177 | } |
178 | 178 | |
179 | -function wpinv_get_invoice_date( $invoice_id = 0, $format = '' ) { |
|
180 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
179 | +function wpinv_get_invoice_date($invoice_id = 0, $format = '') { |
|
180 | + $invoice = new WPInv_Invoice($invoice_id); |
|
181 | 181 | |
182 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
182 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
183 | 183 | $date_completed = $invoice->get_completed_date(); |
184 | - $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : ''; |
|
185 | - if ( $invoice_date == '' ) { |
|
184 | + $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : ''; |
|
185 | + if ($invoice_date == '') { |
|
186 | 186 | $date_created = $invoice->get_created_date(); |
187 | - $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
187 | + $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : ''; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | return $invoice_date; |
191 | 191 | } |
192 | 192 | |
193 | -function wpinv_get_invoice_vat_number( $invoice_id = 0 ) { |
|
194 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
193 | +function wpinv_get_invoice_vat_number($invoice_id = 0) { |
|
194 | + $invoice = new WPInv_Invoice($invoice_id); |
|
195 | 195 | |
196 | 196 | return $invoice->vat_number; |
197 | 197 | } |
198 | 198 | |
199 | -function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false ) { |
|
200 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
199 | +function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false) { |
|
200 | + $invoice = new WPInv_Invoice($invoice_id); |
|
201 | 201 | |
202 | - return $invoice->add_note( $note, $user_type, $added_by_user ); |
|
202 | + return $invoice->add_note($note, $user_type, $added_by_user); |
|
203 | 203 | } |
204 | 204 | |
205 | -function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
205 | +function wpinv_get_invoice_notes($invoice_id = 0, $type = '') { |
|
206 | 206 | global $invoicing; |
207 | 207 | |
208 | - if ( empty( $invoice_id ) ) { |
|
208 | + if (empty($invoice_id)) { |
|
209 | 209 | return NULL; |
210 | 210 | } |
211 | 211 | |
212 | - $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type ); |
|
212 | + $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type); |
|
213 | 213 | |
214 | - return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type ); |
|
214 | + return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type); |
|
215 | 215 | } |
216 | 216 | |
217 | -function wpinv_get_payment_key( $invoice_id = 0 ) { |
|
218 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
217 | +function wpinv_get_payment_key($invoice_id = 0) { |
|
218 | + $invoice = new WPInv_Invoice($invoice_id); |
|
219 | 219 | return $invoice->get_key(); |
220 | 220 | } |
221 | 221 | |
222 | -function wpinv_get_invoice_number( $invoice_id = 0 ) { |
|
223 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
222 | +function wpinv_get_invoice_number($invoice_id = 0) { |
|
223 | + $invoice = new WPInv_Invoice($invoice_id); |
|
224 | 224 | return $invoice->get_number(); |
225 | 225 | } |
226 | 226 | |
227 | -function wpinv_get_cart_discountable_subtotal( $code_id ) { |
|
227 | +function wpinv_get_cart_discountable_subtotal($code_id) { |
|
228 | 228 | $cart_items = wpinv_get_cart_content_details(); |
229 | 229 | $items = array(); |
230 | 230 | |
231 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
231 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
232 | 232 | |
233 | - if( $cart_items ) { |
|
233 | + if ($cart_items) { |
|
234 | 234 | |
235 | - foreach( $cart_items as $item ) { |
|
235 | + foreach ($cart_items as $item) { |
|
236 | 236 | |
237 | - if( ! in_array( $item['id'], $excluded_items ) ) { |
|
238 | - $items[] = $item; |
|
237 | + if (!in_array($item['id'], $excluded_items)) { |
|
238 | + $items[] = $item; |
|
239 | 239 | } |
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
243 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
243 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
244 | 244 | |
245 | - return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal ); |
|
245 | + return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal); |
|
246 | 246 | } |
247 | 247 | |
248 | -function wpinv_get_cart_items_subtotal( $items ) { |
|
248 | +function wpinv_get_cart_items_subtotal($items) { |
|
249 | 249 | $subtotal = 0.00; |
250 | 250 | |
251 | - if ( is_array( $items ) && ! empty( $items ) ) { |
|
252 | - $prices = wp_list_pluck( $items, 'subtotal' ); |
|
251 | + if (is_array($items) && !empty($items)) { |
|
252 | + $prices = wp_list_pluck($items, 'subtotal'); |
|
253 | 253 | |
254 | - if( is_array( $prices ) ) { |
|
255 | - $subtotal = array_sum( $prices ); |
|
254 | + if (is_array($prices)) { |
|
255 | + $subtotal = array_sum($prices); |
|
256 | 256 | } else { |
257 | 257 | $subtotal = 0.00; |
258 | 258 | } |
259 | 259 | |
260 | - if( $subtotal < 0 ) { |
|
260 | + if ($subtotal < 0) { |
|
261 | 261 | $subtotal = 0.00; |
262 | 262 | } |
263 | 263 | } |
264 | 264 | |
265 | - return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal ); |
|
265 | + return apply_filters('wpinv_get_cart_items_subtotal', $subtotal); |
|
266 | 266 | } |
267 | 267 | |
268 | -function wpinv_get_cart_subtotal( $items = array() ) { |
|
269 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
270 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
268 | +function wpinv_get_cart_subtotal($items = array()) { |
|
269 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
270 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
271 | 271 | |
272 | - return apply_filters( 'wpinv_get_cart_subtotal', $subtotal ); |
|
272 | + return apply_filters('wpinv_get_cart_subtotal', $subtotal); |
|
273 | 273 | } |
274 | 274 | |
275 | -function wpinv_cart_subtotal( $items = array() ) { |
|
276 | - $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) ); |
|
275 | +function wpinv_cart_subtotal($items = array()) { |
|
276 | + $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items))); |
|
277 | 277 | |
278 | 278 | // Todo - Show tax labels here (if needed) |
279 | 279 | |
280 | 280 | return $price; |
281 | 281 | } |
282 | 282 | |
283 | -function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) { |
|
284 | - $subtotal = (float)wpinv_get_cart_subtotal( $items ); |
|
285 | - $discounts = (float)wpinv_get_cart_discounted_amount( $items ); |
|
286 | - $cart_tax = (float)wpinv_get_cart_tax( $items ); |
|
283 | +function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) { |
|
284 | + $subtotal = (float)wpinv_get_cart_subtotal($items); |
|
285 | + $discounts = (float)wpinv_get_cart_discounted_amount($items); |
|
286 | + $cart_tax = (float)wpinv_get_cart_tax($items); |
|
287 | 287 | $fees = (float)wpinv_get_cart_fee_total(); |
288 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
288 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
289 | 289 | $total = 0; |
290 | 290 | } else { |
291 | - $total = $subtotal - $discounts + $cart_tax + $fees; |
|
291 | + $total = $subtotal - $discounts + $cart_tax + $fees; |
|
292 | 292 | } |
293 | 293 | |
294 | - if ( $total < 0 ) { |
|
294 | + if ($total < 0) { |
|
295 | 295 | $total = 0.00; |
296 | 296 | } |
297 | 297 | |
298 | - $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items ); |
|
298 | + $total = (float)apply_filters('wpinv_get_cart_total', $total, $items); |
|
299 | 299 | |
300 | - return wpinv_sanitize_amount( $total ); |
|
300 | + return wpinv_sanitize_amount($total); |
|
301 | 301 | } |
302 | 302 | |
303 | -function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) { |
|
303 | +function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) { |
|
304 | 304 | global $cart_total; |
305 | - $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) ); |
|
306 | - $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice ); |
|
305 | + $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice))); |
|
306 | + $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice); |
|
307 | 307 | |
308 | 308 | // Todo - Show tax labels here (if needed) |
309 | 309 | |
310 | 310 | $cart_total = $total; |
311 | 311 | |
312 | - if ( !$echo ) { |
|
312 | + if (!$echo) { |
|
313 | 313 | return $total; |
314 | 314 | } |
315 | 315 | |
316 | 316 | echo $total; |
317 | 317 | } |
318 | 318 | |
319 | -function wpinv_get_cart_tax( $items = array() ) { |
|
319 | +function wpinv_get_cart_tax($items = array()) { |
|
320 | 320 | $cart_tax = 0; |
321 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
321 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
322 | 322 | |
323 | - if ( $items ) { |
|
324 | - $taxes = wp_list_pluck( $items, 'tax' ); |
|
323 | + if ($items) { |
|
324 | + $taxes = wp_list_pluck($items, 'tax'); |
|
325 | 325 | |
326 | - if( is_array( $taxes ) ) { |
|
327 | - $cart_tax = array_sum( $taxes ); |
|
326 | + if (is_array($taxes)) { |
|
327 | + $cart_tax = array_sum($taxes); |
|
328 | 328 | } |
329 | 329 | } |
330 | 330 | |
331 | 331 | $cart_tax += wpinv_get_cart_fee_tax(); |
332 | 332 | |
333 | - return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) ); |
|
333 | + return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax)); |
|
334 | 334 | } |
335 | 335 | |
336 | -function wpinv_cart_tax( $items = array(), $echo = false ) { |
|
337 | - $cart_tax = wpinv_get_cart_tax( $items ); |
|
338 | - $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) ); |
|
336 | +function wpinv_cart_tax($items = array(), $echo = false) { |
|
337 | + $cart_tax = wpinv_get_cart_tax($items); |
|
338 | + $cart_tax = wpinv_price(wpinv_format_amount($cart_tax)); |
|
339 | 339 | |
340 | - $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items ); |
|
340 | + $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items); |
|
341 | 341 | |
342 | - if ( !$echo ) { |
|
342 | + if (!$echo) { |
|
343 | 343 | return $tax; |
344 | 344 | } |
345 | 345 | |
346 | 346 | echo $tax; |
347 | 347 | } |
348 | 348 | |
349 | -function wpinv_get_cart_discount_code( $items = array() ) { |
|
349 | +function wpinv_get_cart_discount_code($items = array()) { |
|
350 | 350 | $invoice = wpinv_get_invoice_cart(); |
351 | - $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : ''; |
|
351 | + $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : ''; |
|
352 | 352 | |
353 | - return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code ); |
|
353 | + return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code); |
|
354 | 354 | } |
355 | 355 | |
356 | -function wpinv_cart_discount_code( $items = array(), $echo = false ) { |
|
357 | - $cart_discount_code = wpinv_get_cart_discount_code( $items ); |
|
356 | +function wpinv_cart_discount_code($items = array(), $echo = false) { |
|
357 | + $cart_discount_code = wpinv_get_cart_discount_code($items); |
|
358 | 358 | |
359 | - if ( $cart_discount_code != '' ) { |
|
359 | + if ($cart_discount_code != '') { |
|
360 | 360 | $cart_discount_code = ' (' . $cart_discount_code . ')'; |
361 | 361 | } |
362 | 362 | |
363 | - $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items ); |
|
363 | + $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items); |
|
364 | 364 | |
365 | - if ( !$echo ) { |
|
365 | + if (!$echo) { |
|
366 | 366 | return $discount_code; |
367 | 367 | } |
368 | 368 | |
369 | 369 | echo $discount_code; |
370 | 370 | } |
371 | 371 | |
372 | -function wpinv_get_cart_discount( $items = array() ) { |
|
372 | +function wpinv_get_cart_discount($items = array()) { |
|
373 | 373 | $invoice = wpinv_get_invoice_cart(); |
374 | - $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0; |
|
374 | + $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0; |
|
375 | 375 | |
376 | - return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items ); |
|
376 | + return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items); |
|
377 | 377 | } |
378 | 378 | |
379 | -function wpinv_cart_discount( $items = array(), $echo = false ) { |
|
380 | - $cart_discount = wpinv_get_cart_discount( $items ); |
|
381 | - $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) ); |
|
379 | +function wpinv_cart_discount($items = array(), $echo = false) { |
|
380 | + $cart_discount = wpinv_get_cart_discount($items); |
|
381 | + $cart_discount = wpinv_price(wpinv_format_amount($cart_discount)); |
|
382 | 382 | |
383 | - $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items ); |
|
383 | + $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items); |
|
384 | 384 | |
385 | - if ( !$echo ) { |
|
385 | + if (!$echo) { |
|
386 | 386 | return $discount; |
387 | 387 | } |
388 | 388 | |
389 | 389 | echo $discount; |
390 | 390 | } |
391 | 391 | |
392 | -function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) { |
|
393 | - $item = new WPInv_Item( $item_id ); |
|
392 | +function wpinv_get_cart_fees($type = 'all', $item_id = 0) { |
|
393 | + $item = new WPInv_Item($item_id); |
|
394 | 394 | |
395 | - return $item->get_fees( $type, $item_id ); |
|
395 | + return $item->get_fees($type, $item_id); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | function wpinv_get_cart_fee_total() { |
399 | - $total = 0; |
|
399 | + $total = 0; |
|
400 | 400 | $fees = wpinv_get_cart_fees(); |
401 | 401 | |
402 | - if ( $fees ) { |
|
403 | - foreach ( $fees as $fee_id => $fee ) { |
|
402 | + if ($fees) { |
|
403 | + foreach ($fees as $fee_id => $fee) { |
|
404 | 404 | $total += $fee['amount']; |
405 | 405 | } |
406 | 406 | } |
407 | 407 | |
408 | - return apply_filters( 'wpinv_get_cart_fee_total', $total ); |
|
408 | + return apply_filters('wpinv_get_cart_fee_total', $total); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | function wpinv_get_cart_fee_tax() { |
412 | 412 | $tax = 0; |
413 | 413 | $fees = wpinv_get_cart_fees(); |
414 | 414 | |
415 | - if ( $fees ) { |
|
416 | - foreach ( $fees as $fee_id => $fee ) { |
|
417 | - if( ! empty( $fee['no_tax'] ) ) { |
|
415 | + if ($fees) { |
|
416 | + foreach ($fees as $fee_id => $fee) { |
|
417 | + if (!empty($fee['no_tax'])) { |
|
418 | 418 | continue; |
419 | 419 | } |
420 | 420 | |
421 | - $tax += wpinv_calculate_tax( $fee['amount'] ); |
|
421 | + $tax += wpinv_calculate_tax($fee['amount']); |
|
422 | 422 | } |
423 | 423 | } |
424 | 424 | |
425 | - return apply_filters( 'wpinv_get_cart_fee_tax', $tax ); |
|
425 | + return apply_filters('wpinv_get_cart_fee_tax', $tax); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | function wpinv_cart_has_recurring_item() { |
429 | 429 | $cart_items = wpinv_get_cart_contents(); |
430 | 430 | |
431 | - if ( empty( $cart_items ) ) { |
|
431 | + if (empty($cart_items)) { |
|
432 | 432 | return false; |
433 | 433 | } |
434 | 434 | |
435 | 435 | $has_subscription = false; |
436 | - foreach( $cart_items as $cart_item ) { |
|
437 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
436 | + foreach ($cart_items as $cart_item) { |
|
437 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
438 | 438 | $has_subscription = true; |
439 | 439 | break; |
440 | 440 | } |
441 | 441 | } |
442 | 442 | |
443 | - return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items ); |
|
443 | + return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | function wpinv_cart_has_free_trial() { |
@@ -448,85 +448,85 @@ discard block |
||
448 | 448 | |
449 | 449 | $free_trial = false; |
450 | 450 | |
451 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
451 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
452 | 452 | $free_trial = true; |
453 | 453 | } |
454 | 454 | |
455 | - return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice ); |
|
455 | + return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | function wpinv_get_cart_contents() { |
459 | 459 | $cart_details = wpinv_get_cart_details(); |
460 | 460 | |
461 | - return apply_filters( 'wpinv_get_cart_contents', $cart_details ); |
|
461 | + return apply_filters('wpinv_get_cart_contents', $cart_details); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | function wpinv_get_cart_content_details() { |
465 | 465 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
466 | 466 | $cart_items = wpinv_get_cart_contents(); |
467 | 467 | |
468 | - if ( empty( $cart_items ) ) { |
|
468 | + if (empty($cart_items)) { |
|
469 | 469 | return false; |
470 | 470 | } |
471 | 471 | $invoice = wpinv_get_invoice_cart(); |
472 | 472 | |
473 | 473 | $details = array(); |
474 | - $length = count( $cart_items ) - 1; |
|
474 | + $length = count($cart_items) - 1; |
|
475 | 475 | |
476 | - if ( empty( $_POST['country'] ) ) { |
|
476 | + if (empty($_POST['country'])) { |
|
477 | 477 | $_POST['country'] = $invoice->country; |
478 | 478 | } |
479 | - if ( !isset( $_POST['state'] ) ) { |
|
479 | + if (!isset($_POST['state'])) { |
|
480 | 480 | $_POST['state'] = $invoice->state; |
481 | 481 | } |
482 | 482 | |
483 | - foreach( $cart_items as $key => $item ) { |
|
484 | - $item_id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
485 | - if ( empty( $item_id ) ) { |
|
483 | + foreach ($cart_items as $key => $item) { |
|
484 | + $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
485 | + if (empty($item_id)) { |
|
486 | 486 | continue; |
487 | 487 | } |
488 | 488 | |
489 | 489 | $wpi_current_id = $invoice->ID; |
490 | 490 | $wpi_item_id = $item_id; |
491 | 491 | |
492 | - $item_price = wpinv_get_item_price( $item_id ); |
|
493 | - $discount = wpinv_get_cart_item_discount_amount( $item ); |
|
494 | - $discount = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item ); |
|
495 | - $quantity = wpinv_get_cart_item_quantity( $item ); |
|
496 | - $fees = wpinv_get_cart_fees( 'fee', $item_id ); |
|
492 | + $item_price = wpinv_get_item_price($item_id); |
|
493 | + $discount = wpinv_get_cart_item_discount_amount($item); |
|
494 | + $discount = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item); |
|
495 | + $quantity = wpinv_get_cart_item_quantity($item); |
|
496 | + $fees = wpinv_get_cart_fees('fee', $item_id); |
|
497 | 497 | |
498 | 498 | $subtotal = $item_price * $quantity; |
499 | - $tax_rate = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id ); |
|
500 | - $tax_class = $wpinv_euvat->get_item_class( $item_id ); |
|
501 | - $tax = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount ); |
|
499 | + $tax_rate = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id); |
|
500 | + $tax_class = $wpinv_euvat->get_item_class($item_id); |
|
501 | + $tax = wpinv_get_cart_item_tax($item_id, $subtotal - $discount); |
|
502 | 502 | |
503 | - if ( wpinv_prices_include_tax() ) { |
|
504 | - $subtotal -= wpinv_format_amount( $tax, NULL, true ); |
|
503 | + if (wpinv_prices_include_tax()) { |
|
504 | + $subtotal -= wpinv_format_amount($tax, NULL, true); |
|
505 | 505 | } |
506 | 506 | |
507 | - $total = $subtotal - $discount + $tax; |
|
507 | + $total = $subtotal - $discount + $tax; |
|
508 | 508 | |
509 | 509 | // Do not allow totals to go negatve |
510 | - if( $total < 0 ) { |
|
510 | + if ($total < 0) { |
|
511 | 511 | $total = 0; |
512 | 512 | } |
513 | 513 | |
514 | - $details[ $key ] = array( |
|
514 | + $details[$key] = array( |
|
515 | 515 | 'id' => $item_id, |
516 | - 'name' => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ), |
|
517 | - 'item_price' => wpinv_format_amount( $item_price, NULL, true ), |
|
516 | + 'name' => !empty($item['name']) ? $item['name'] : get_the_title($item_id), |
|
517 | + 'item_price' => wpinv_format_amount($item_price, NULL, true), |
|
518 | 518 | 'quantity' => $quantity, |
519 | - 'discount' => wpinv_format_amount( $discount, NULL, true ), |
|
520 | - 'subtotal' => wpinv_format_amount( $subtotal, NULL, true ), |
|
521 | - 'tax' => wpinv_format_amount( $tax, NULL, true ), |
|
522 | - 'price' => wpinv_format_amount( $total, NULL, true ), |
|
519 | + 'discount' => wpinv_format_amount($discount, NULL, true), |
|
520 | + 'subtotal' => wpinv_format_amount($subtotal, NULL, true), |
|
521 | + 'tax' => wpinv_format_amount($tax, NULL, true), |
|
522 | + 'price' => wpinv_format_amount($total, NULL, true), |
|
523 | 523 | 'vat_rates_class' => $tax_class, |
524 | - 'vat_rate' => wpinv_format_amount( $tax_rate, NULL, true ), |
|
525 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
524 | + 'vat_rate' => wpinv_format_amount($tax_rate, NULL, true), |
|
525 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
526 | 526 | 'fees' => $fees, |
527 | 527 | ); |
528 | 528 | |
529 | - if ( $wpinv_is_last_cart_item ) { |
|
529 | + if ($wpinv_is_last_cart_item) { |
|
530 | 530 | $wpinv_is_last_cart_item = false; |
531 | 531 | $wpinv_flat_discount_total = 0.00; |
532 | 532 | } |
@@ -535,56 +535,56 @@ discard block |
||
535 | 535 | return $details; |
536 | 536 | } |
537 | 537 | |
538 | -function wpinv_get_cart_details( $invoice_id = 0 ) { |
|
538 | +function wpinv_get_cart_details($invoice_id = 0) { |
|
539 | 539 | global $ajax_cart_details; |
540 | 540 | |
541 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
542 | - $cart_details = !empty( $ajax_cart_details ) ? $ajax_cart_details : $invoice->cart_details; |
|
541 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
542 | + $cart_details = !empty($ajax_cart_details) ? $ajax_cart_details : $invoice->cart_details; |
|
543 | 543 | |
544 | 544 | $invoice_currency = $invoice->currency; |
545 | 545 | |
546 | - if ( ! empty( $cart_details ) && is_array( $cart_details ) ) { |
|
547 | - foreach ( $cart_details as $key => $cart_item ) { |
|
548 | - $cart_details[ $key ]['currency'] = $invoice_currency; |
|
546 | + if (!empty($cart_details) && is_array($cart_details)) { |
|
547 | + foreach ($cart_details as $key => $cart_item) { |
|
548 | + $cart_details[$key]['currency'] = $invoice_currency; |
|
549 | 549 | |
550 | - if ( ! isset( $cart_item['subtotal'] ) ) { |
|
551 | - $cart_details[ $key ]['subtotal'] = $cart_item['price']; |
|
550 | + if (!isset($cart_item['subtotal'])) { |
|
551 | + $cart_details[$key]['subtotal'] = $cart_item['price']; |
|
552 | 552 | } |
553 | 553 | } |
554 | 554 | } |
555 | 555 | |
556 | - return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id ); |
|
556 | + return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id); |
|
557 | 557 | } |
558 | 558 | |
559 | -function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) { |
|
560 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
559 | +function wpinv_record_status_change($invoice_id, $new_status, $old_status) { |
|
560 | + $invoice = wpinv_get_invoice($invoice_id); |
|
561 | 561 | |
562 | - $old_status = wpinv_status_nicename( $old_status ); |
|
563 | - $new_status = wpinv_status_nicename( $new_status ); |
|
562 | + $old_status = wpinv_status_nicename($old_status); |
|
563 | + $new_status = wpinv_status_nicename($new_status); |
|
564 | 564 | |
565 | - $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status ); |
|
565 | + $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status); |
|
566 | 566 | |
567 | 567 | // Add note |
568 | - return $invoice->add_note( $status_change, 0 ); |
|
568 | + return $invoice->add_note($status_change, 0); |
|
569 | 569 | } |
570 | -add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 ); |
|
570 | +add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3); |
|
571 | 571 | |
572 | -function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) { |
|
572 | +function wpinv_complete_payment($invoice_id, $new_status, $old_status) { |
|
573 | 573 | global $wpi_has_free_trial; |
574 | 574 | |
575 | 575 | $wpi_has_free_trial = false; |
576 | 576 | |
577 | - if ( $old_status == 'publish' || $old_status == 'complete' ) { |
|
577 | + if ($old_status == 'publish' || $old_status == 'complete') { |
|
578 | 578 | return; // Make sure that payments are only paid once |
579 | 579 | } |
580 | 580 | |
581 | 581 | // Make sure the payment completion is only processed when new status is paid |
582 | - if ( $new_status != 'publish' && $new_status != 'complete' ) { |
|
582 | + if ($new_status != 'publish' && $new_status != 'complete') { |
|
583 | 583 | return; |
584 | 584 | } |
585 | 585 | |
586 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
587 | - if ( empty( $invoice ) ) { |
|
586 | + $invoice = new WPInv_Invoice($invoice_id); |
|
587 | + if (empty($invoice)) { |
|
588 | 588 | return; |
589 | 589 | } |
590 | 590 | |
@@ -592,58 +592,58 @@ discard block |
||
592 | 592 | $completed_date = $invoice->completed_date; |
593 | 593 | $cart_details = $invoice->cart_details; |
594 | 594 | |
595 | - do_action( 'wpinv_pre_complete_payment', $invoice_id ); |
|
595 | + do_action('wpinv_pre_complete_payment', $invoice_id); |
|
596 | 596 | |
597 | - if ( is_array( $cart_details ) ) { |
|
597 | + if (is_array($cart_details)) { |
|
598 | 598 | // Increase purchase count and earnings |
599 | - foreach ( $cart_details as $cart_index => $item ) { |
|
599 | + foreach ($cart_details as $cart_index => $item) { |
|
600 | 600 | // Ensure these actions only run once, ever |
601 | - if ( empty( $completed_date ) ) { |
|
602 | - do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index ); |
|
601 | + if (empty($completed_date)) { |
|
602 | + do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index); |
|
603 | 603 | } |
604 | 604 | } |
605 | 605 | } |
606 | 606 | |
607 | 607 | // Check for discount codes and increment their use counts |
608 | - if ( $discounts = $invoice->get_discounts( true ) ) { |
|
609 | - if( ! empty( $discounts ) ) { |
|
610 | - foreach( $discounts as $code ) { |
|
611 | - wpinv_increase_discount_usage( $code ); |
|
608 | + if ($discounts = $invoice->get_discounts(true)) { |
|
609 | + if (!empty($discounts)) { |
|
610 | + foreach ($discounts as $code) { |
|
611 | + wpinv_increase_discount_usage($code); |
|
612 | 612 | } |
613 | 613 | } |
614 | 614 | } |
615 | 615 | |
616 | 616 | // Ensure this action only runs once ever |
617 | - if( empty( $completed_date ) ) { |
|
617 | + if (empty($completed_date)) { |
|
618 | 618 | // Save the completed date |
619 | - $invoice->set( 'completed_date', current_time( 'mysql', 0 ) ); |
|
619 | + $invoice->set('completed_date', current_time('mysql', 0)); |
|
620 | 620 | $invoice->save(); |
621 | 621 | |
622 | - do_action( 'wpinv_complete_payment', $invoice_id ); |
|
622 | + do_action('wpinv_complete_payment', $invoice_id); |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | // Empty the shopping cart |
626 | 626 | wpinv_empty_cart(); |
627 | 627 | } |
628 | -add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 ); |
|
628 | +add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3); |
|
629 | 629 | |
630 | -function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) { |
|
631 | - $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id ); |
|
630 | +function wpinv_update_payment_status($invoice_id, $new_status = 'publish') { |
|
631 | + $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id); |
|
632 | 632 | |
633 | - if ( empty( $invoice ) ) { |
|
633 | + if (empty($invoice)) { |
|
634 | 634 | return false; |
635 | 635 | } |
636 | 636 | |
637 | - return $invoice->update_status( $new_status ); |
|
637 | + return $invoice->update_status($new_status); |
|
638 | 638 | } |
639 | 639 | |
640 | -function wpinv_cart_has_fees( $type = 'all' ) { |
|
640 | +function wpinv_cart_has_fees($type = 'all') { |
|
641 | 641 | return false; |
642 | 642 | } |
643 | 643 | |
644 | 644 | function wpinv_validate_checkout_fields() { |
645 | 645 | // Check if there is $_POST |
646 | - if ( empty( $_POST ) ) { |
|
646 | + if (empty($_POST)) { |
|
647 | 647 | return false; |
648 | 648 | } |
649 | 649 | |
@@ -655,11 +655,11 @@ discard block |
||
655 | 655 | ); |
656 | 656 | |
657 | 657 | // Validate agree to terms |
658 | - if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
658 | + if (wpinv_get_option('show_agree_to_terms', false)) { |
|
659 | 659 | wpinv_checkout_validate_agree_to_terms(); |
660 | 660 | } |
661 | 661 | |
662 | - $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user(); |
|
662 | + $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user(); |
|
663 | 663 | |
664 | 664 | // Return collected data |
665 | 665 | return $valid_data; |
@@ -671,20 +671,20 @@ discard block |
||
671 | 671 | $has_subscription = wpinv_cart_has_recurring_item(); |
672 | 672 | |
673 | 673 | // Check if a gateway value is present |
674 | - if ( !empty( $_REQUEST['wpi-gateway'] ) ) { |
|
675 | - $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] ); |
|
674 | + if (!empty($_REQUEST['wpi-gateway'])) { |
|
675 | + $gateway = sanitize_text_field($_REQUEST['wpi-gateway']); |
|
676 | 676 | |
677 | - if ( '0.00' == wpinv_get_cart_total() ) { |
|
677 | + if ('0.00' == wpinv_get_cart_total()) { |
|
678 | 678 | $gateway = 'manual'; |
679 | - } elseif ( !wpinv_is_gateway_active( $gateway ) ) { |
|
680 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) ); |
|
681 | - } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) { |
|
682 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) ); |
|
679 | + } elseif (!wpinv_is_gateway_active($gateway)) { |
|
680 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing')); |
|
681 | + } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) { |
|
682 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing')); |
|
683 | 683 | } |
684 | 684 | } |
685 | 685 | |
686 | - if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) { |
|
687 | - wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) ); |
|
686 | + if ($has_subscription && count(wpinv_get_cart_contents()) > 1) { |
|
687 | + wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing')); |
|
688 | 688 | } |
689 | 689 | |
690 | 690 | return $gateway; |
@@ -696,10 +696,10 @@ discard block |
||
696 | 696 | |
697 | 697 | $error = false; |
698 | 698 | // If we have discounts, loop through them |
699 | - if ( ! empty( $discounts ) ) { |
|
700 | - foreach ( $discounts as $discount ) { |
|
699 | + if (!empty($discounts)) { |
|
700 | + foreach ($discounts as $discount) { |
|
701 | 701 | // Check if valid |
702 | - if ( !wpinv_is_discount_valid( $discount, get_current_user_id() ) ) { |
|
702 | + if (!wpinv_is_discount_valid($discount, get_current_user_id())) { |
|
703 | 703 | // Discount is not valid |
704 | 704 | $error = true; |
705 | 705 | } |
@@ -709,20 +709,20 @@ discard block |
||
709 | 709 | return NULL; |
710 | 710 | } |
711 | 711 | |
712 | - if ( $error && !wpinv_get_errors() ) { |
|
713 | - wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) ); |
|
712 | + if ($error && !wpinv_get_errors()) { |
|
713 | + wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing')); |
|
714 | 714 | } |
715 | 715 | |
716 | - return implode( ',', $discounts ); |
|
716 | + return implode(',', $discounts); |
|
717 | 717 | } |
718 | 718 | |
719 | 719 | function wpinv_checkout_validate_cc() { |
720 | 720 | $card_data = wpinv_checkout_get_cc_info(); |
721 | 721 | |
722 | 722 | // Validate the card zip |
723 | - if ( !empty( $card_data['wpinv_zip'] ) ) { |
|
724 | - if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) { |
|
725 | - wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) ); |
|
723 | + if (!empty($card_data['wpinv_zip'])) { |
|
724 | + if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) { |
|
725 | + wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing')); |
|
726 | 726 | } |
727 | 727 | } |
728 | 728 | |
@@ -732,28 +732,28 @@ discard block |
||
732 | 732 | |
733 | 733 | function wpinv_checkout_get_cc_info() { |
734 | 734 | $cc_info = array(); |
735 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
736 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
737 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
738 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
739 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
740 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
741 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
742 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
743 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
744 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
735 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
736 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
737 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
738 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
739 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
740 | + $cc_info['card_address'] = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : ''; |
|
741 | + $cc_info['card_city'] = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : ''; |
|
742 | + $cc_info['card_state'] = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : ''; |
|
743 | + $cc_info['card_country'] = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : ''; |
|
744 | + $cc_info['card_zip'] = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : ''; |
|
745 | 745 | |
746 | 746 | // Return cc info |
747 | 747 | return $cc_info; |
748 | 748 | } |
749 | 749 | |
750 | -function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
750 | +function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') { |
|
751 | 751 | $ret = false; |
752 | 752 | |
753 | - if ( empty( $zip ) || empty( $country_code ) ) |
|
753 | + if (empty($zip) || empty($country_code)) |
|
754 | 754 | return $ret; |
755 | 755 | |
756 | - $country_code = strtoupper( $country_code ); |
|
756 | + $country_code = strtoupper($country_code); |
|
757 | 757 | |
758 | 758 | $zip_regex = array( |
759 | 759 | "AD" => "AD\d{3}", |
@@ -913,17 +913,17 @@ discard block |
||
913 | 913 | "ZM" => "\d{5}" |
914 | 914 | ); |
915 | 915 | |
916 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) |
|
916 | + if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip)) |
|
917 | 917 | $ret = true; |
918 | 918 | |
919 | - return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code ); |
|
919 | + return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code); |
|
920 | 920 | } |
921 | 921 | |
922 | 922 | function wpinv_checkout_validate_agree_to_terms() { |
923 | 923 | // Validate agree to terms |
924 | - if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) { |
|
924 | + if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) { |
|
925 | 925 | // User did not agree |
926 | - wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) ); |
|
926 | + wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing'))); |
|
927 | 927 | } |
928 | 928 | } |
929 | 929 | |
@@ -936,36 +936,36 @@ discard block |
||
936 | 936 | ); |
937 | 937 | |
938 | 938 | // Verify there is a user_ID |
939 | - if ( $user_ID > 0 ) { |
|
939 | + if ($user_ID > 0) { |
|
940 | 940 | // Get the logged in user data |
941 | - $user_data = get_userdata( $user_ID ); |
|
942 | - $required_fields = wpinv_checkout_required_fields(); |
|
941 | + $user_data = get_userdata($user_ID); |
|
942 | + $required_fields = wpinv_checkout_required_fields(); |
|
943 | 943 | |
944 | 944 | // Loop through required fields and show error messages |
945 | - if ( !empty( $required_fields ) ) { |
|
946 | - foreach ( $required_fields as $field_name => $value ) { |
|
947 | - if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
|
948 | - wpinv_set_error( $value['error_id'], $value['error_message'] ); |
|
945 | + if (!empty($required_fields)) { |
|
946 | + foreach ($required_fields as $field_name => $value) { |
|
947 | + if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) { |
|
948 | + wpinv_set_error($value['error_id'], $value['error_message']); |
|
949 | 949 | } |
950 | 950 | } |
951 | 951 | } |
952 | 952 | |
953 | 953 | // Verify data |
954 | - if ( $user_data ) { |
|
954 | + if ($user_data) { |
|
955 | 955 | // Collected logged in user data |
956 | 956 | $valid_user_data = array( |
957 | 957 | 'user_id' => $user_ID, |
958 | - 'email' => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email, |
|
959 | - 'first_name' => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name, |
|
960 | - 'last_name' => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name'] ) ? sanitize_text_field( $_POST['wpinv_last_name'] ) : $user_data->last_name, |
|
958 | + 'email' => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email, |
|
959 | + 'first_name' => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name, |
|
960 | + 'last_name' => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name, |
|
961 | 961 | ); |
962 | 962 | |
963 | - if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) { |
|
964 | - wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) ); |
|
963 | + if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) { |
|
964 | + wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing')); |
|
965 | 965 | } |
966 | 966 | } else { |
967 | 967 | // Set invalid user error |
968 | - wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) ); |
|
968 | + wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing')); |
|
969 | 969 | } |
970 | 970 | } |
971 | 971 | |
@@ -973,21 +973,21 @@ discard block |
||
973 | 973 | return $valid_user_data; |
974 | 974 | } |
975 | 975 | |
976 | -function wpinv_checkout_form_get_user( $valid_data = array() ) { |
|
976 | +function wpinv_checkout_form_get_user($valid_data = array()) { |
|
977 | 977 | // Initialize user |
978 | 978 | $user = false; |
979 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
979 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
980 | 980 | |
981 | 981 | /*if ( $is_ajax ) { |
982 | 982 | // Do not create or login the user during the ajax submission (check for errors only) |
983 | 983 | return true; |
984 | - } else */if ( is_user_logged_in() ) { |
|
984 | + } else */if (is_user_logged_in()) { |
|
985 | 985 | // Set the valid user as the logged in collected data |
986 | 986 | $user = $valid_data['logged_in_user']; |
987 | 987 | } |
988 | 988 | |
989 | 989 | // Verify we have an user |
990 | - if ( false === $user || empty( $user ) ) { |
|
990 | + if (false === $user || empty($user)) { |
|
991 | 991 | // Return false |
992 | 992 | return false; |
993 | 993 | } |
@@ -1006,11 +1006,11 @@ discard block |
||
1006 | 1006 | 'zip', |
1007 | 1007 | ); |
1008 | 1008 | |
1009 | - foreach ( $address_fields as $field ) { |
|
1010 | - $user[$field] = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false; |
|
1009 | + foreach ($address_fields as $field) { |
|
1010 | + $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false; |
|
1011 | 1011 | |
1012 | - if ( !empty( $user['user_id'] ) ) { |
|
1013 | - update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] ); |
|
1012 | + if (!empty($user['user_id'])) { |
|
1013 | + update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]); |
|
1014 | 1014 | } |
1015 | 1015 | } |
1016 | 1016 | |
@@ -1018,28 +1018,28 @@ discard block |
||
1018 | 1018 | return $user; |
1019 | 1019 | } |
1020 | 1020 | |
1021 | -function wpinv_set_checkout_session( $invoice_data = array() ) { |
|
1021 | +function wpinv_set_checkout_session($invoice_data = array()) { |
|
1022 | 1022 | global $wpi_session; |
1023 | 1023 | |
1024 | - return $wpi_session->set( 'wpinv_checkout', $invoice_data ); |
|
1024 | + return $wpi_session->set('wpinv_checkout', $invoice_data); |
|
1025 | 1025 | } |
1026 | 1026 | |
1027 | 1027 | function wpinv_get_checkout_session() { |
1028 | 1028 | global $wpi_session; |
1029 | 1029 | |
1030 | - return $wpi_session->get( 'wpinv_checkout' ); |
|
1030 | + return $wpi_session->get('wpinv_checkout'); |
|
1031 | 1031 | } |
1032 | 1032 | |
1033 | 1033 | function wpinv_empty_cart() { |
1034 | 1034 | global $wpi_session; |
1035 | 1035 | |
1036 | 1036 | // Remove cart contents |
1037 | - $wpi_session->set( 'wpinv_checkout', NULL ); |
|
1037 | + $wpi_session->set('wpinv_checkout', NULL); |
|
1038 | 1038 | |
1039 | 1039 | // Remove all cart fees |
1040 | - $wpi_session->set( 'wpi_cart_fees', NULL ); |
|
1040 | + $wpi_session->set('wpi_cart_fees', NULL); |
|
1041 | 1041 | |
1042 | - do_action( 'wpinv_empty_cart' ); |
|
1042 | + do_action('wpinv_empty_cart'); |
|
1043 | 1043 | } |
1044 | 1044 | |
1045 | 1045 | function wpinv_process_checkout() { |
@@ -1051,42 +1051,42 @@ discard block |
||
1051 | 1051 | |
1052 | 1052 | $wpi_checkout_id = $invoice->ID; |
1053 | 1053 | |
1054 | - do_action( 'wpinv_pre_process_checkout' ); |
|
1054 | + do_action('wpinv_pre_process_checkout'); |
|
1055 | 1055 | |
1056 | - if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty |
|
1056 | + if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty |
|
1057 | 1057 | $valid_data = false; |
1058 | - wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) ); |
|
1058 | + wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing')); |
|
1059 | 1059 | } else { |
1060 | 1060 | // Validate the form $_POST data |
1061 | 1061 | $valid_data = wpinv_validate_checkout_fields(); |
1062 | 1062 | |
1063 | 1063 | // Allow themes and plugins to hook to errors |
1064 | - do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST ); |
|
1064 | + do_action('wpinv_checkout_error_checks', $valid_data, $_POST); |
|
1065 | 1065 | } |
1066 | 1066 | |
1067 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
1067 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
1068 | 1068 | |
1069 | 1069 | // Validate the user |
1070 | - $user = wpinv_checkout_form_get_user( $valid_data ); |
|
1070 | + $user = wpinv_checkout_form_get_user($valid_data); |
|
1071 | 1071 | |
1072 | 1072 | // Let extensions validate fields after user is logged in if user has used login/registration form |
1073 | - do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST ); |
|
1073 | + do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST); |
|
1074 | 1074 | |
1075 | - if ( false === $valid_data || wpinv_get_errors() || ! $user ) { |
|
1076 | - if ( $is_ajax ) { |
|
1077 | - do_action( 'wpinv_ajax_checkout_errors' ); |
|
1075 | + if (false === $valid_data || wpinv_get_errors() || !$user) { |
|
1076 | + if ($is_ajax) { |
|
1077 | + do_action('wpinv_ajax_checkout_errors'); |
|
1078 | 1078 | die(); |
1079 | 1079 | } else { |
1080 | 1080 | return false; |
1081 | 1081 | } |
1082 | 1082 | } |
1083 | 1083 | |
1084 | - if ( $is_ajax ) { |
|
1084 | + if ($is_ajax) { |
|
1085 | 1085 | // Save address fields. |
1086 | - $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' ); |
|
1087 | - foreach ( $address_fields as $field ) { |
|
1088 | - if ( isset( $user[$field] ) ) { |
|
1089 | - $invoice->set( $field, $user[$field] ); |
|
1086 | + $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company'); |
|
1087 | + foreach ($address_fields as $field) { |
|
1088 | + if (isset($user[$field])) { |
|
1089 | + $invoice->set($field, $user[$field]); |
|
1090 | 1090 | } |
1091 | 1091 | |
1092 | 1092 | $invoice->save(); |
@@ -1094,15 +1094,15 @@ discard block |
||
1094 | 1094 | |
1095 | 1095 | $response['success'] = true; |
1096 | 1096 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
1097 | - $response['data']['subtotalf'] = $invoice->get_subtotal( true ); |
|
1097 | + $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
|
1098 | 1098 | $response['data']['discount'] = $invoice->get_discount(); |
1099 | - $response['data']['discountf'] = $invoice->get_discount( true ); |
|
1099 | + $response['data']['discountf'] = $invoice->get_discount(true); |
|
1100 | 1100 | $response['data']['tax'] = $invoice->get_tax(); |
1101 | - $response['data']['taxf'] = $invoice->get_tax( true ); |
|
1101 | + $response['data']['taxf'] = $invoice->get_tax(true); |
|
1102 | 1102 | $response['data']['total'] = $invoice->get_total(); |
1103 | - $response['data']['totalf'] = $invoice->get_total( true ); |
|
1103 | + $response['data']['totalf'] = $invoice->get_total(true); |
|
1104 | 1104 | |
1105 | - wp_send_json( $response ); |
|
1105 | + wp_send_json($response); |
|
1106 | 1106 | } |
1107 | 1107 | |
1108 | 1108 | $user_info = array( |
@@ -1124,42 +1124,42 @@ discard block |
||
1124 | 1124 | |
1125 | 1125 | // Setup invoice information |
1126 | 1126 | $invoice_data = array( |
1127 | - 'invoice_id' => !empty( $invoice ) ? $invoice->ID : 0, |
|
1127 | + 'invoice_id' => !empty($invoice) ? $invoice->ID : 0, |
|
1128 | 1128 | 'items' => $cart_items, |
1129 | 1129 | 'cart_discounts' => $discounts, |
1130 | - 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1131 | - 'subtotal' => wpinv_get_cart_subtotal( $cart_items ), // Amount before taxes and discounts |
|
1132 | - 'discount' => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount |
|
1133 | - 'tax' => wpinv_get_cart_tax( $cart_items ), // Taxed amount |
|
1134 | - 'price' => wpinv_get_cart_total( $cart_items, $discounts ), // Amount after taxes |
|
1130 | + 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1131 | + 'subtotal' => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts |
|
1132 | + 'discount' => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount |
|
1133 | + 'tax' => wpinv_get_cart_tax($cart_items), // Taxed amount |
|
1134 | + 'price' => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes |
|
1135 | 1135 | 'invoice_key' => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(), |
1136 | 1136 | 'user_email' => $user['email'], |
1137 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
1138 | - 'user_info' => stripslashes_deep( $user_info ), |
|
1137 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
1138 | + 'user_info' => stripslashes_deep($user_info), |
|
1139 | 1139 | 'post_data' => $_POST, |
1140 | 1140 | 'cart_details' => $cart_items, |
1141 | 1141 | 'gateway' => $valid_data['gateway'], |
1142 | 1142 | 'card_info' => $valid_data['cc_info'] |
1143 | 1143 | ); |
1144 | 1144 | |
1145 | - $vat_info = $wpinv_euvat->current_vat_data(); |
|
1146 | - if ( is_array( $vat_info ) ) { |
|
1145 | + $vat_info = $wpinv_euvat->current_vat_data(); |
|
1146 | + if (is_array($vat_info)) { |
|
1147 | 1147 | $invoice_data['user_info']['vat_number'] = $vat_info['number']; |
1148 | 1148 | $invoice_data['user_info']['vat_rate'] = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']); |
1149 | - $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1149 | + $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1150 | 1150 | |
1151 | 1151 | // Add the VAT rate to each item in the cart |
1152 | - foreach( $invoice_data['cart_details'] as $key => $item_data) { |
|
1152 | + foreach ($invoice_data['cart_details'] as $key => $item_data) { |
|
1153 | 1153 | $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']); |
1154 | - $invoice_data['cart_details'][$key]['vat_rate'] = round( $rate, 3 ); |
|
1154 | + $invoice_data['cart_details'][$key]['vat_rate'] = round($rate, 3); |
|
1155 | 1155 | } |
1156 | 1156 | } |
1157 | 1157 | |
1158 | 1158 | // Save vat fields. |
1159 | - $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' ); |
|
1160 | - foreach ( $address_fields as $field ) { |
|
1161 | - if ( isset( $invoice_data['user_info'][$field] ) ) { |
|
1162 | - $invoice->set( $field, $invoice_data['user_info'][$field] ); |
|
1159 | + $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed'); |
|
1160 | + foreach ($address_fields as $field) { |
|
1161 | + if (isset($invoice_data['user_info'][$field])) { |
|
1162 | + $invoice->set($field, $invoice_data['user_info'][$field]); |
|
1163 | 1163 | } |
1164 | 1164 | |
1165 | 1165 | $invoice->save(); |
@@ -1169,49 +1169,49 @@ discard block |
||
1169 | 1169 | $valid_data['user'] = $user; |
1170 | 1170 | |
1171 | 1171 | // Allow themes and plugins to hook before the gateway |
1172 | - do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
1172 | + do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
1173 | 1173 | |
1174 | 1174 | // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice |
1175 | - if ( !$invoice_data['price'] ) { |
|
1175 | + if (!$invoice_data['price']) { |
|
1176 | 1176 | // Revert to manual |
1177 | 1177 | $invoice_data['gateway'] = 'manual'; |
1178 | 1178 | $_POST['wpi-gateway'] = 'manual'; |
1179 | 1179 | } |
1180 | 1180 | |
1181 | 1181 | // Allow the invoice data to be modified before it is sent to the gateway |
1182 | - $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data ); |
|
1182 | + $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data); |
|
1183 | 1183 | |
1184 | 1184 | // Setup the data we're storing in the purchase session |
1185 | 1185 | $session_data = $invoice_data; |
1186 | 1186 | // Make sure credit card numbers are never stored in sessions |
1187 | - if ( !empty( $session_data['card_info']['card_number'] ) ) { |
|
1188 | - unset( $session_data['card_info']['card_number'] ); |
|
1187 | + if (!empty($session_data['card_info']['card_number'])) { |
|
1188 | + unset($session_data['card_info']['card_number']); |
|
1189 | 1189 | } |
1190 | 1190 | |
1191 | 1191 | // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data. |
1192 | - wpinv_set_checkout_session( $invoice_data ); |
|
1192 | + wpinv_set_checkout_session($invoice_data); |
|
1193 | 1193 | |
1194 | 1194 | // Set gateway |
1195 | - $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] ); |
|
1196 | - $invoice->update_meta( '_wpinv_mode', ( wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live' ) ); |
|
1197 | - $invoice->update_meta( '_wpinv_checkout', true ); |
|
1195 | + $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']); |
|
1196 | + $invoice->update_meta('_wpinv_mode', (wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live')); |
|
1197 | + $invoice->update_meta('_wpinv_checkout', true); |
|
1198 | 1198 | |
1199 | - do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data ); |
|
1199 | + do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data); |
|
1200 | 1200 | |
1201 | 1201 | // Send info to the gateway for payment processing |
1202 | - wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data ); |
|
1202 | + wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data); |
|
1203 | 1203 | die(); |
1204 | 1204 | } |
1205 | -add_action( 'wpinv_payment', 'wpinv_process_checkout' ); |
|
1205 | +add_action('wpinv_payment', 'wpinv_process_checkout'); |
|
1206 | 1206 | |
1207 | -function wpinv_get_invoices( $args ) { |
|
1208 | - $args = wp_parse_args( $args, array( |
|
1209 | - 'status' => array_keys( wpinv_get_invoice_statuses() ), |
|
1207 | +function wpinv_get_invoices($args) { |
|
1208 | + $args = wp_parse_args($args, array( |
|
1209 | + 'status' => array_keys(wpinv_get_invoice_statuses()), |
|
1210 | 1210 | 'type' => 'wpi_invoice', |
1211 | 1211 | 'parent' => null, |
1212 | 1212 | 'user' => null, |
1213 | 1213 | 'email' => '', |
1214 | - 'limit' => get_option( 'posts_per_page' ), |
|
1214 | + 'limit' => get_option('posts_per_page'), |
|
1215 | 1215 | 'offset' => null, |
1216 | 1216 | 'page' => 1, |
1217 | 1217 | 'exclude' => array(), |
@@ -1219,7 +1219,7 @@ discard block |
||
1219 | 1219 | 'order' => 'DESC', |
1220 | 1220 | 'return' => 'objects', |
1221 | 1221 | 'paginate' => false, |
1222 | - ) ); |
|
1222 | + )); |
|
1223 | 1223 | |
1224 | 1224 | // Handle some BW compatibility arg names where wp_query args differ in naming. |
1225 | 1225 | $map_legacy = array( |
@@ -1232,18 +1232,18 @@ discard block |
||
1232 | 1232 | 'paged' => 'page', |
1233 | 1233 | ); |
1234 | 1234 | |
1235 | - foreach ( $map_legacy as $from => $to ) { |
|
1236 | - if ( isset( $args[ $from ] ) ) { |
|
1237 | - $args[ $to ] = $args[ $from ]; |
|
1235 | + foreach ($map_legacy as $from => $to) { |
|
1236 | + if (isset($args[$from])) { |
|
1237 | + $args[$to] = $args[$from]; |
|
1238 | 1238 | } |
1239 | 1239 | } |
1240 | 1240 | |
1241 | - if ( get_query_var( 'paged' ) ) |
|
1241 | + if (get_query_var('paged')) |
|
1242 | 1242 | $args['page'] = get_query_var('paged'); |
1243 | - else if ( get_query_var( 'page' ) ) |
|
1244 | - $args['page'] = get_query_var( 'page' ); |
|
1245 | - else if ( !empty( $args[ 'page' ] ) ) |
|
1246 | - $args['page'] = $args[ 'page' ]; |
|
1243 | + else if (get_query_var('page')) |
|
1244 | + $args['page'] = get_query_var('page'); |
|
1245 | + else if (!empty($args['page'])) |
|
1246 | + $args['page'] = $args['page']; |
|
1247 | 1247 | else |
1248 | 1248 | $args['page'] = 1; |
1249 | 1249 | |
@@ -1256,47 +1256,47 @@ discard block |
||
1256 | 1256 | 'post_status' => $args['status'], |
1257 | 1257 | 'posts_per_page' => $args['limit'], |
1258 | 1258 | 'meta_query' => array(), |
1259 | - 'date_query' => !empty( $args['date_query'] ) ? $args['date_query'] : array(), |
|
1259 | + 'date_query' => !empty($args['date_query']) ? $args['date_query'] : array(), |
|
1260 | 1260 | 'fields' => 'ids', |
1261 | 1261 | 'orderby' => $args['orderby'], |
1262 | 1262 | 'order' => $args['order'], |
1263 | 1263 | ); |
1264 | 1264 | |
1265 | - if ( !empty( $args['user'] ) ) { |
|
1266 | - $wp_query_args['author'] = absint( $args['user'] ); |
|
1265 | + if (!empty($args['user'])) { |
|
1266 | + $wp_query_args['author'] = absint($args['user']); |
|
1267 | 1267 | } |
1268 | 1268 | |
1269 | - if ( ! is_null( $args['parent'] ) ) { |
|
1270 | - $wp_query_args['post_parent'] = absint( $args['parent'] ); |
|
1269 | + if (!is_null($args['parent'])) { |
|
1270 | + $wp_query_args['post_parent'] = absint($args['parent']); |
|
1271 | 1271 | } |
1272 | 1272 | |
1273 | - if ( ! is_null( $args['offset'] ) ) { |
|
1274 | - $wp_query_args['offset'] = absint( $args['offset'] ); |
|
1273 | + if (!is_null($args['offset'])) { |
|
1274 | + $wp_query_args['offset'] = absint($args['offset']); |
|
1275 | 1275 | } else { |
1276 | - $wp_query_args['paged'] = absint( $args['page'] ); |
|
1276 | + $wp_query_args['paged'] = absint($args['page']); |
|
1277 | 1277 | } |
1278 | 1278 | |
1279 | - if ( ! empty( $args['exclude'] ) ) { |
|
1280 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
1279 | + if (!empty($args['exclude'])) { |
|
1280 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
1281 | 1281 | } |
1282 | 1282 | |
1283 | - if ( ! $args['paginate' ] ) { |
|
1283 | + if (!$args['paginate']) { |
|
1284 | 1284 | $wp_query_args['no_found_rows'] = true; |
1285 | 1285 | } |
1286 | 1286 | |
1287 | 1287 | // Get results. |
1288 | - $invoices = new WP_Query( $wp_query_args ); |
|
1288 | + $invoices = new WP_Query($wp_query_args); |
|
1289 | 1289 | |
1290 | - if ( 'objects' === $args['return'] ) { |
|
1291 | - $return = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
1292 | - } elseif ( 'self' === $args['return'] ) { |
|
1290 | + if ('objects' === $args['return']) { |
|
1291 | + $return = array_map('wpinv_get_invoice', $invoices->posts); |
|
1292 | + } elseif ('self' === $args['return']) { |
|
1293 | 1293 | return $invoices; |
1294 | 1294 | } else { |
1295 | 1295 | $return = $invoices->posts; |
1296 | 1296 | } |
1297 | 1297 | |
1298 | - if ( $args['paginate' ] ) { |
|
1299 | - return (object) array( |
|
1298 | + if ($args['paginate']) { |
|
1299 | + return (object)array( |
|
1300 | 1300 | 'invoices' => $return, |
1301 | 1301 | 'total' => $invoices->found_posts, |
1302 | 1302 | 'max_num_pages' => $invoices->max_num_pages, |
@@ -1308,21 +1308,21 @@ discard block |
||
1308 | 1308 | |
1309 | 1309 | function wpinv_get_user_invoices_columns() { |
1310 | 1310 | $columns = array( |
1311 | - 'invoice-number' => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ), |
|
1312 | - 'invoice-date' => array( 'title' => __( 'Date', 'invoicing' ), 'class' => 'text-left' ), |
|
1313 | - 'invoice-status' => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ), |
|
1314 | - 'invoice-total' => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ), |
|
1315 | - 'invoice-actions' => array( 'title' => ' ', 'class' => 'text-center' ), |
|
1311 | + 'invoice-number' => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'), |
|
1312 | + 'invoice-date' => array('title' => __('Date', 'invoicing'), 'class' => 'text-left'), |
|
1313 | + 'invoice-status' => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'), |
|
1314 | + 'invoice-total' => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'), |
|
1315 | + 'invoice-actions' => array('title' => ' ', 'class' => 'text-center'), |
|
1316 | 1316 | ); |
1317 | 1317 | |
1318 | - return apply_filters( 'wpinv_user_invoices_columns', $columns ); |
|
1318 | + return apply_filters('wpinv_user_invoices_columns', $columns); |
|
1319 | 1319 | } |
1320 | 1320 | |
1321 | -function wpinv_payment_receipt( $atts, $content = null ) { |
|
1321 | +function wpinv_payment_receipt($atts, $content = null) { |
|
1322 | 1322 | global $wpinv_receipt_args; |
1323 | 1323 | |
1324 | - $wpinv_receipt_args = shortcode_atts( array( |
|
1325 | - 'error' => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ), |
|
1324 | + $wpinv_receipt_args = shortcode_atts(array( |
|
1325 | + 'error' => __('Sorry, trouble retrieving payment receipt.', 'invoicing'), |
|
1326 | 1326 | 'price' => true, |
1327 | 1327 | 'discount' => true, |
1328 | 1328 | 'items' => true, |
@@ -1331,185 +1331,185 @@ discard block |
||
1331 | 1331 | 'invoice_key' => false, |
1332 | 1332 | 'payment_method' => true, |
1333 | 1333 | 'invoice_id' => true |
1334 | - ), $atts, 'wpinv_receipt' ); |
|
1334 | + ), $atts, 'wpinv_receipt'); |
|
1335 | 1335 | |
1336 | 1336 | $session = wpinv_get_checkout_session(); |
1337 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
1338 | - $invoice_key = urldecode( $_GET['invoice_key'] ); |
|
1339 | - } else if ( $session && isset( $session['invoice_key'] ) ) { |
|
1337 | + if (isset($_GET['invoice_key'])) { |
|
1338 | + $invoice_key = urldecode($_GET['invoice_key']); |
|
1339 | + } else if ($session && isset($session['invoice_key'])) { |
|
1340 | 1340 | $invoice_key = $session['invoice_key']; |
1341 | - } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) { |
|
1341 | + } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) { |
|
1342 | 1342 | $invoice_key = $wpinv_receipt_args['invoice_key']; |
1343 | - } else if ( isset( $_GET['invoice-id'] ) ) { |
|
1344 | - $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] ); |
|
1343 | + } else if (isset($_GET['invoice-id'])) { |
|
1344 | + $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']); |
|
1345 | 1345 | } |
1346 | 1346 | |
1347 | 1347 | // No key found |
1348 | - if ( ! isset( $invoice_key ) ) { |
|
1348 | + if (!isset($invoice_key)) { |
|
1349 | 1349 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
1350 | 1350 | } |
1351 | 1351 | |
1352 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1353 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
1354 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
1352 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
1353 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
1354 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
1355 | 1355 | $invoice_id = (int)$_GET['invoice-id']; |
1356 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
1356 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
1357 | 1357 | } |
1358 | 1358 | |
1359 | 1359 | // Key was provided, but user is logged out. Offer them the ability to login and view the receipt |
1360 | - if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) { |
|
1360 | + if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) { |
|
1361 | 1361 | // login redirect |
1362 | - return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>'; |
|
1362 | + return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>'; |
|
1363 | 1363 | } |
1364 | 1364 | |
1365 | - if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) { |
|
1365 | + if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) { |
|
1366 | 1366 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
1367 | 1367 | } |
1368 | 1368 | |
1369 | 1369 | ob_start(); |
1370 | 1370 | |
1371 | - wpinv_get_template_part( 'wpinv-invoice-receipt' ); |
|
1371 | + wpinv_get_template_part('wpinv-invoice-receipt'); |
|
1372 | 1372 | |
1373 | 1373 | $display = ob_get_clean(); |
1374 | 1374 | |
1375 | 1375 | return $display; |
1376 | 1376 | } |
1377 | 1377 | |
1378 | -function wpinv_get_invoice_id_by_key( $key ) { |
|
1378 | +function wpinv_get_invoice_id_by_key($key) { |
|
1379 | 1379 | global $wpdb; |
1380 | 1380 | |
1381 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
1381 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key)); |
|
1382 | 1382 | |
1383 | - if ( $invoice_id != NULL ) |
|
1383 | + if ($invoice_id != NULL) |
|
1384 | 1384 | return $invoice_id; |
1385 | 1385 | |
1386 | 1386 | return 0; |
1387 | 1387 | } |
1388 | 1388 | |
1389 | -function wpinv_can_view_receipt( $invoice_key = '' ) { |
|
1389 | +function wpinv_can_view_receipt($invoice_key = '') { |
|
1390 | 1390 | $return = false; |
1391 | 1391 | |
1392 | - if ( empty( $invoice_key ) ) { |
|
1392 | + if (empty($invoice_key)) { |
|
1393 | 1393 | return $return; |
1394 | 1394 | } |
1395 | 1395 | |
1396 | 1396 | global $wpinv_receipt_args; |
1397 | 1397 | |
1398 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1399 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
1400 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
1398 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key); |
|
1399 | + if (isset($_GET['invoice-id'])) { |
|
1400 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0; |
|
1401 | 1401 | } |
1402 | 1402 | |
1403 | - $user_id = (int) wpinv_get_user_id( $wpinv_receipt_args['id'] ); |
|
1404 | - $invoice_meta = wpinv_get_invoice_meta( $wpinv_receipt_args['id'] ); |
|
1403 | + $user_id = (int)wpinv_get_user_id($wpinv_receipt_args['id']); |
|
1404 | + $invoice_meta = wpinv_get_invoice_meta($wpinv_receipt_args['id']); |
|
1405 | 1405 | |
1406 | - if ( is_user_logged_in() ) { |
|
1407 | - if ( $user_id === (int) get_current_user_id() ) { |
|
1406 | + if (is_user_logged_in()) { |
|
1407 | + if ($user_id === (int)get_current_user_id()) { |
|
1408 | 1408 | $return = true; |
1409 | 1409 | } |
1410 | 1410 | } |
1411 | 1411 | |
1412 | 1412 | $session = wpinv_get_checkout_session(); |
1413 | - if ( ! empty( $session ) && ! is_user_logged_in() ) { |
|
1414 | - if ( $session['invoice_key'] === $invoice_meta['key'] ) { |
|
1413 | + if (!empty($session) && !is_user_logged_in()) { |
|
1414 | + if ($session['invoice_key'] === $invoice_meta['key']) { |
|
1415 | 1415 | $return = true; |
1416 | 1416 | } |
1417 | 1417 | } |
1418 | 1418 | |
1419 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
1419 | + return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key); |
|
1420 | 1420 | } |
1421 | 1421 | |
1422 | 1422 | function wpinv_pay_for_invoice() { |
1423 | 1423 | global $wpinv_euvat; |
1424 | 1424 | |
1425 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
1425 | + if (isset($_GET['invoice_key'])) { |
|
1426 | 1426 | $checkout_uri = wpinv_get_checkout_uri(); |
1427 | - $invoice_key = sanitize_text_field( $_GET['invoice_key'] ); |
|
1427 | + $invoice_key = sanitize_text_field($_GET['invoice_key']); |
|
1428 | 1428 | |
1429 | - if ( empty( $invoice_key ) ) { |
|
1430 | - wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) ); |
|
1431 | - wp_redirect( $checkout_uri ); |
|
1429 | + if (empty($invoice_key)) { |
|
1430 | + wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing')); |
|
1431 | + wp_redirect($checkout_uri); |
|
1432 | 1432 | wpinv_die(); |
1433 | 1433 | } |
1434 | 1434 | |
1435 | - do_action( 'wpinv_check_pay_for_invoice', $invoice_key ); |
|
1435 | + do_action('wpinv_check_pay_for_invoice', $invoice_key); |
|
1436 | 1436 | |
1437 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1438 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
1439 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
1437 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
1438 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
1439 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
1440 | 1440 | $invoice_id = (int)$_GET['invoice-id']; |
1441 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
1441 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
1442 | 1442 | } |
1443 | 1443 | |
1444 | - if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) { |
|
1445 | - if ( $invoice->needs_payment() ) { |
|
1444 | + if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) { |
|
1445 | + if ($invoice->needs_payment()) { |
|
1446 | 1446 | $data = array(); |
1447 | 1447 | $data['invoice_id'] = $invoice_id; |
1448 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
1448 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
1449 | 1449 | |
1450 | - wpinv_set_checkout_session( $data ); |
|
1450 | + wpinv_set_checkout_session($data); |
|
1451 | 1451 | |
1452 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
1452 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
1453 | 1453 | $_POST['country'] = $wpinv_euvat->get_country_by_ip(); |
1454 | 1454 | $_POST['state'] = $_POST['country'] == $invoice->country ? $invoice->state : ''; |
1455 | 1455 | |
1456 | - wpinv_recalculate_tax( true ); |
|
1456 | + wpinv_recalculate_tax(true); |
|
1457 | 1457 | } |
1458 | 1458 | |
1459 | 1459 | } else { |
1460 | 1460 | $checkout_uri = $invoice->get_view_url(); |
1461 | 1461 | } |
1462 | 1462 | } else { |
1463 | - wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) ); |
|
1463 | + wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing')); |
|
1464 | 1464 | |
1465 | - $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
1465 | + $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
1466 | 1466 | } |
1467 | 1467 | |
1468 | - wp_redirect( $checkout_uri ); |
|
1468 | + wp_redirect($checkout_uri); |
|
1469 | 1469 | wpinv_die(); |
1470 | 1470 | } |
1471 | 1471 | } |
1472 | -add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' ); |
|
1472 | +add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice'); |
|
1473 | 1473 | |
1474 | -function wpinv_handle_pay_via_invoice_link( $invoice_key ) { |
|
1475 | - if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) { |
|
1476 | - if ( $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
1474 | +function wpinv_handle_pay_via_invoice_link($invoice_key) { |
|
1475 | + if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) { |
|
1476 | + if ($invoice = wpinv_get_invoice($invoice_id)) { |
|
1477 | 1477 | $user_id = $invoice->get_user_id(); |
1478 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
1478 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
1479 | 1479 | |
1480 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link |
|
1481 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
1480 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link |
|
1481 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
1482 | 1482 | |
1483 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
1483 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
1484 | 1484 | wpinv_die(); |
1485 | 1485 | } |
1486 | 1486 | } |
1487 | 1487 | } |
1488 | 1488 | } |
1489 | -add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' ); |
|
1489 | +add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link'); |
|
1490 | 1490 | |
1491 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
1492 | - $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id; |
|
1491 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
1492 | + $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id; |
|
1493 | 1493 | |
1494 | - if ( empty( $invoice_id ) && $invoice_id > 0 ) { |
|
1494 | + if (empty($invoice_id) && $invoice_id > 0) { |
|
1495 | 1495 | return false; |
1496 | 1496 | } |
1497 | 1497 | |
1498 | - if ( empty( $transaction_id ) ) { |
|
1498 | + if (empty($transaction_id)) { |
|
1499 | 1499 | $transaction_id = $invoice_id; |
1500 | 1500 | } |
1501 | 1501 | |
1502 | - $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id ); |
|
1502 | + $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id); |
|
1503 | 1503 | |
1504 | - return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id ); |
|
1504 | + return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id); |
|
1505 | 1505 | } |
1506 | 1506 | |
1507 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
1508 | - if ( empty( $status_display ) ) { |
|
1509 | - $status_display = wpinv_status_nicename( $status ); |
|
1507 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
1508 | + if (empty($status_display)) { |
|
1509 | + $status_display = wpinv_status_nicename($status); |
|
1510 | 1510 | } |
1511 | 1511 | |
1512 | - switch ( $status ) { |
|
1512 | + switch ($status) { |
|
1513 | 1513 | case 'publish' : |
1514 | 1514 | case 'complete' : |
1515 | 1515 | case 'renewal' : |
@@ -1535,28 +1535,28 @@ discard block |
||
1535 | 1535 | |
1536 | 1536 | $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>'; |
1537 | 1537 | |
1538 | - return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display ); |
|
1538 | + return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display); |
|
1539 | 1539 | } |
1540 | 1540 | |
1541 | -function wpinv_format_invoice_number( $number ) { |
|
1542 | - $padd = wpinv_get_option( 'invoice_number_padd' ); |
|
1541 | +function wpinv_format_invoice_number($number) { |
|
1542 | + $padd = wpinv_get_option('invoice_number_padd'); |
|
1543 | 1543 | |
1544 | 1544 | // TODO maintain old invoice numbers if invoice number settings not saved. Should be removed before stable release. |
1545 | - if ( $padd === '' || $padd === false || $padd === NULL ) { |
|
1546 | - return wp_sprintf( __( 'WPINV-%d', 'invoicing' ), $number ); |
|
1545 | + if ($padd === '' || $padd === false || $padd === NULL) { |
|
1546 | + return wp_sprintf(__('WPINV-%d', 'invoicing'), $number); |
|
1547 | 1547 | } |
1548 | 1548 | |
1549 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
1550 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
1549 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
1550 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
1551 | 1551 | |
1552 | - $padd = absint( $padd ); |
|
1553 | - $formatted_number = absint( $number ); |
|
1552 | + $padd = absint($padd); |
|
1553 | + $formatted_number = absint($number); |
|
1554 | 1554 | |
1555 | - if ( $padd > 0 ) { |
|
1556 | - $formatted_number = zeroise( $formatted_number, $padd ); |
|
1555 | + if ($padd > 0) { |
|
1556 | + $formatted_number = zeroise($formatted_number, $padd); |
|
1557 | 1557 | } |
1558 | 1558 | |
1559 | 1559 | $formatted_number = $prefix . $formatted_number . $postfix; |
1560 | 1560 | |
1561 | - return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd ); |
|
1561 | + return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd); |
|
1562 | 1562 | } |
1563 | 1563 | \ No newline at end of file |
@@ -11,19 +11,19 @@ discard block |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | // MUST have WordPress. |
14 | -if ( !defined( 'WPINC' ) ) { |
|
15 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
14 | +if (!defined('WPINC')) { |
|
15 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
16 | 16 | } |
17 | 17 | |
18 | -if ( !defined( 'WPINV_VERSION' ) ) { |
|
19 | - define( 'WPINV_VERSION', '0.0.4' ); |
|
18 | +if (!defined('WPINV_VERSION')) { |
|
19 | + define('WPINV_VERSION', '0.0.4'); |
|
20 | 20 | } |
21 | 21 | |
22 | -if ( !defined( 'WPINV_PLUGIN_FILE' ) ) { |
|
23 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
22 | +if (!defined('WPINV_PLUGIN_FILE')) { |
|
23 | + define('WPINV_PLUGIN_FILE', __FILE__); |
|
24 | 24 | } |
25 | 25 | |
26 | -require plugin_dir_path( __FILE__ ) . 'includes/class-wpinv.php'; |
|
26 | +require plugin_dir_path(__FILE__) . 'includes/class-wpinv.php'; |
|
27 | 27 | |
28 | 28 | function wpinv_run() { |
29 | 29 | global $invoicing; |
@@ -40,16 +40,16 @@ discard block |
||
40 | 40 | /** |
41 | 41 | * Show update plugin admin notification. |
42 | 42 | */ |
43 | -if(is_admin()){ |
|
43 | +if (is_admin()) { |
|
44 | 44 | if (!function_exists('ayecode_show_update_plugin_requirement')) {//only load the update file if needed |
45 | 45 | function ayecode_show_update_plugin_requirement() { |
46 | - if ( !defined( 'WP_EASY_UPDATES_ACTIVE' ) ) { |
|
46 | + if (!defined('WP_EASY_UPDATES_ACTIVE')) { |
|
47 | 47 | ?> |
48 | 48 | <div class="notice notice-warning is-dismissible"> |
49 | 49 | <p> |
50 | 50 | <strong> |
51 | 51 | <?php |
52 | - echo sprintf( __( 'The plugin %sWP Easy Updates%s is required to check for and update some installed plugins, please install it now.', 'geodirectory' ), '<a href="https://wpeasyupdates.com/" target="_blank" title="WP Easy Updates">', '</a>' ); |
|
52 | + echo sprintf(__('The plugin %sWP Easy Updates%s is required to check for and update some installed plugins, please install it now.', 'geodirectory'), '<a href="https://wpeasyupdates.com/" target="_blank" title="WP Easy Updates">', '</a>'); |
|
53 | 53 | ?> |
54 | 54 | </strong> |
55 | 55 | </p> |
@@ -58,6 +58,6 @@ discard block |
||
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
61 | - add_action( 'admin_notices', 'ayecode_show_update_plugin_requirement' ); |
|
61 | + add_action('admin_notices', 'ayecode_show_update_plugin_requirement'); |
|
62 | 62 | } |
63 | 63 | } |