@@ -1,121 +1,121 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | function wpinv_use_taxes() { |
8 | - $ret = wpinv_get_option( 'enable_taxes', false ); |
|
8 | + $ret = wpinv_get_option('enable_taxes', false); |
|
9 | 9 | |
10 | - return (bool) apply_filters( 'wpinv_use_taxes', $ret ); |
|
10 | + return (bool)apply_filters('wpinv_use_taxes', $ret); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | function wpinv_get_tax_rates() { |
14 | - $rates = get_option( 'wpinv_tax_rates', array() ); |
|
14 | + $rates = get_option('wpinv_tax_rates', array()); |
|
15 | 15 | |
16 | - return apply_filters( 'wpinv_get_tax_rates', $rates ); |
|
16 | + return apply_filters('wpinv_get_tax_rates', $rates); |
|
17 | 17 | } |
18 | 18 | |
19 | -function wpinv_get_tax_rate( $country = false, $state = false, $item_id = 0 ) { |
|
19 | +function wpinv_get_tax_rate($country = false, $state = false, $item_id = 0) { |
|
20 | 20 | global $wpinv_euvat, $wpi_tax_rates, $wpi_userID; |
21 | - $wpi_tax_rates = !empty( $wpi_tax_rates ) ? $wpi_tax_rates : array(); |
|
21 | + $wpi_tax_rates = !empty($wpi_tax_rates) ? $wpi_tax_rates : array(); |
|
22 | 22 | |
23 | - if ( !empty( $wpi_tax_rates ) && !empty( $item_id ) && isset( $wpi_tax_rates[$item_id] ) ) { |
|
23 | + if (!empty($wpi_tax_rates) && !empty($item_id) && isset($wpi_tax_rates[$item_id])) { |
|
24 | 24 | return $wpi_tax_rates[$item_id]; |
25 | 25 | } |
26 | 26 | |
27 | - if ( !$wpinv_euvat->item_is_taxable( $item_id, $country, $state ) ) { |
|
27 | + if (!$wpinv_euvat->item_is_taxable($item_id, $country, $state)) { |
|
28 | 28 | $wpi_tax_rates[$item_id] = 0; |
29 | 29 | return 0; |
30 | 30 | } |
31 | 31 | |
32 | 32 | $is_global = false; |
33 | - if ( $item_id == 'global' ) { |
|
33 | + if ($item_id == 'global') { |
|
34 | 34 | $is_global = true; |
35 | 35 | $item_id = 0; |
36 | 36 | } |
37 | 37 | |
38 | - $rate = (float)wpinv_get_option( 'tax_rate', 0 ); |
|
39 | - $user_address = wpinv_get_user_address( $wpi_userID ); |
|
38 | + $rate = (float)wpinv_get_option('tax_rate', 0); |
|
39 | + $user_address = wpinv_get_user_address($wpi_userID); |
|
40 | 40 | |
41 | - if( empty( $country ) ) { |
|
42 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
41 | + if (empty($country)) { |
|
42 | + if (!empty($_POST['wpinv_country'])) { |
|
43 | 43 | $country = $_POST['wpinv_country']; |
44 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
44 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
45 | 45 | $country = $_POST['wpinv_country']; |
46 | - } elseif( !empty( $_POST['country'] ) ) { |
|
46 | + } elseif (!empty($_POST['country'])) { |
|
47 | 47 | $country = $_POST['country']; |
48 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
48 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
49 | 49 | $country = $user_address['country']; |
50 | 50 | } |
51 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
51 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
52 | 52 | } |
53 | 53 | |
54 | - if( empty( $state ) ) { |
|
55 | - if( !empty( $_POST['wpinv_state'] ) ) { |
|
54 | + if (empty($state)) { |
|
55 | + if (!empty($_POST['wpinv_state'])) { |
|
56 | 56 | $state = $_POST['wpinv_state']; |
57 | - } elseif( !empty( $_POST['wpinv_state'] ) ) { |
|
57 | + } elseif (!empty($_POST['wpinv_state'])) { |
|
58 | 58 | $state = $_POST['wpinv_state']; |
59 | - } elseif( !empty( $_POST['state'] ) ) { |
|
59 | + } elseif (!empty($_POST['state'])) { |
|
60 | 60 | $state = $_POST['state']; |
61 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
61 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
62 | 62 | $state = $user_address['state']; |
63 | 63 | } |
64 | - $state = !empty( $state ) ? $state : wpinv_get_default_state(); |
|
64 | + $state = !empty($state) ? $state : wpinv_get_default_state(); |
|
65 | 65 | } |
66 | 66 | |
67 | - if( !empty( $country ) ) { |
|
68 | - $tax_rates = wpinv_get_tax_rates(); |
|
67 | + if (!empty($country)) { |
|
68 | + $tax_rates = wpinv_get_tax_rates(); |
|
69 | 69 | |
70 | - if( !empty( $tax_rates ) ) { |
|
70 | + if (!empty($tax_rates)) { |
|
71 | 71 | // Locate the tax rate for this country / state, if it exists |
72 | - foreach( $tax_rates as $key => $tax_rate ) { |
|
73 | - if( $country != $tax_rate['country'] ) |
|
72 | + foreach ($tax_rates as $key => $tax_rate) { |
|
73 | + if ($country != $tax_rate['country']) |
|
74 | 74 | continue; |
75 | 75 | |
76 | - if( !empty( $tax_rate['global'] ) ) { |
|
77 | - if( !empty( $tax_rate['rate'] ) ) { |
|
78 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
76 | + if (!empty($tax_rate['global'])) { |
|
77 | + if (!empty($tax_rate['rate'])) { |
|
78 | + $rate = number_format($tax_rate['rate'], 4); |
|
79 | 79 | } |
80 | 80 | } else { |
81 | 81 | |
82 | - if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
82 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
83 | 83 | continue; |
84 | 84 | |
85 | 85 | $state_rate = $tax_rate['rate']; |
86 | - if( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
87 | - $rate = number_format( $state_rate, 4 ); |
|
86 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
87 | + $rate = number_format($state_rate, 4); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | - $rate = apply_filters( 'wpinv_tax_rate', $rate, $country, $state, $item_id ); |
|
94 | + $rate = apply_filters('wpinv_tax_rate', $rate, $country, $state, $item_id); |
|
95 | 95 | |
96 | - if ( !empty( $item_id ) ) { |
|
96 | + if (!empty($item_id)) { |
|
97 | 97 | $wpi_tax_rates[$item_id] = $rate; |
98 | - } else if ( $is_global ) { |
|
98 | + } else if ($is_global) { |
|
99 | 99 | $wpi_tax_rates['global'] = $rate; |
100 | 100 | } |
101 | 101 | |
102 | 102 | return $rate; |
103 | 103 | } |
104 | 104 | |
105 | -function wpinv_get_formatted_tax_rate( $country = false, $state = false, $item_id ) { |
|
106 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
107 | - $rate = round( $rate, 4 ); |
|
105 | +function wpinv_get_formatted_tax_rate($country = false, $state = false, $item_id) { |
|
106 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
107 | + $rate = round($rate, 4); |
|
108 | 108 | $formatted = $rate .= '%'; |
109 | - return apply_filters( 'wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id ); |
|
109 | + return apply_filters('wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id); |
|
110 | 110 | } |
111 | 111 | |
112 | -function wpinv_calculate_tax( $amount = 0, $country = false, $state = false, $item_id = 0 ) { |
|
113 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
112 | +function wpinv_calculate_tax($amount = 0, $country = false, $state = false, $item_id = 0) { |
|
113 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
114 | 114 | $tax = 0.00; |
115 | 115 | |
116 | - if ( wpinv_use_taxes() ) { |
|
117 | - if ( wpinv_prices_include_tax() ) { |
|
118 | - $pre_tax = ( $amount / ( ( 1 + $rate ) * 0.01 ) ); |
|
116 | + if (wpinv_use_taxes()) { |
|
117 | + if (wpinv_prices_include_tax()) { |
|
118 | + $pre_tax = ($amount / ((1 + $rate) * 0.01)); |
|
119 | 119 | $tax = $amount - $pre_tax; |
120 | 120 | } else { |
121 | 121 | $tax = $amount * $rate * 0.01; |
@@ -123,46 +123,46 @@ discard block |
||
123 | 123 | |
124 | 124 | } |
125 | 125 | |
126 | - return apply_filters( 'wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id ); |
|
126 | + return apply_filters('wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | function wpinv_prices_include_tax() { |
130 | 130 | return false; // TODO |
131 | - $ret = ( wpinv_get_option( 'prices_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
131 | + $ret = (wpinv_get_option('prices_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
132 | 132 | |
133 | - return apply_filters( 'wpinv_prices_include_tax', $ret ); |
|
133 | + return apply_filters('wpinv_prices_include_tax', $ret); |
|
134 | 134 | } |
135 | 135 | |
136 | -function wpinv_sales_tax_for_year( $year = null ) { |
|
137 | - return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) ); |
|
136 | +function wpinv_sales_tax_for_year($year = null) { |
|
137 | + return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year))); |
|
138 | 138 | } |
139 | 139 | |
140 | -function wpinv_get_sales_tax_for_year( $year = null ) { |
|
140 | +function wpinv_get_sales_tax_for_year($year = null) { |
|
141 | 141 | global $wpdb; |
142 | 142 | |
143 | 143 | // Start at zero |
144 | 144 | $tax = 0; |
145 | 145 | |
146 | - if ( ! empty( $year ) ) { |
|
146 | + if (!empty($year)) { |
|
147 | 147 | $args = array( |
148 | 148 | 'post_type' => 'wpi_invoice', |
149 | - 'post_status' => array( 'publish' ), |
|
149 | + 'post_status' => array('publish'), |
|
150 | 150 | 'posts_per_page' => -1, |
151 | 151 | 'year' => $year, |
152 | 152 | 'fields' => 'ids' |
153 | 153 | ); |
154 | 154 | |
155 | - $payments = get_posts( $args ); |
|
156 | - $payment_ids = implode( ',', $payments ); |
|
155 | + $payments = get_posts($args); |
|
156 | + $payment_ids = implode(',', $payments); |
|
157 | 157 | |
158 | - if ( count( $payments ) > 0 ) { |
|
158 | + if (count($payments) > 0) { |
|
159 | 159 | $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )"; |
160 | - $tax = $wpdb->get_var( $sql ); |
|
160 | + $tax = $wpdb->get_var($sql); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | } |
164 | 164 | |
165 | - return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year ); |
|
165 | + return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | function wpinv_is_cart_taxed() { |
@@ -171,33 +171,33 @@ discard block |
||
171 | 171 | |
172 | 172 | function wpinv_prices_show_tax_on_checkout() { |
173 | 173 | return false; // TODO |
174 | - $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
174 | + $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
175 | 175 | |
176 | - return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret ); |
|
176 | + return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | function wpinv_display_tax_rate() { |
180 | - $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false ); |
|
180 | + $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false); |
|
181 | 181 | |
182 | - return apply_filters( 'wpinv_display_tax_rate', $ret ); |
|
182 | + return apply_filters('wpinv_display_tax_rate', $ret); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | function wpinv_cart_needs_tax_address_fields() { |
186 | - if( !wpinv_is_cart_taxed() ) |
|
186 | + if (!wpinv_is_cart_taxed()) |
|
187 | 187 | return false; |
188 | 188 | |
189 | - return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
|
189 | + return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields'); |
|
190 | 190 | } |
191 | 191 | |
192 | -function wpinv_item_is_tax_exclusive( $item_id = 0 ) { |
|
193 | - $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false ); |
|
194 | - return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id ); |
|
192 | +function wpinv_item_is_tax_exclusive($item_id = 0) { |
|
193 | + $ret = (bool)get_post_meta($item_id, '_wpinv_tax_exclusive', false); |
|
194 | + return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id); |
|
195 | 195 | } |
196 | 196 | |
197 | -function wpinv_currency_decimal_filter( $decimals = 2 ) { |
|
197 | +function wpinv_currency_decimal_filter($decimals = 2) { |
|
198 | 198 | $currency = wpinv_get_currency(); |
199 | 199 | |
200 | - switch ( $currency ) { |
|
200 | + switch ($currency) { |
|
201 | 201 | case 'RIAL' : |
202 | 202 | case 'JPY' : |
203 | 203 | case 'TWD' : |
@@ -206,48 +206,48 @@ discard block |
||
206 | 206 | break; |
207 | 207 | } |
208 | 208 | |
209 | - return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency ); |
|
209 | + return apply_filters('wpinv_currency_decimal_count', $decimals, $currency); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | function wpinv_tax_amount() { |
213 | 213 | $output = 0.00; |
214 | 214 | |
215 | - return apply_filters( 'wpinv_tax_amount', $output ); |
|
215 | + return apply_filters('wpinv_tax_amount', $output); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | function wpinv_recalculated_tax() { |
219 | - define( 'WPINV_RECALCTAX', true ); |
|
219 | + define('WPINV_RECALCTAX', true); |
|
220 | 220 | } |
221 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1 ); |
|
221 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1); |
|
222 | 222 | |
223 | -function wpinv_recalculate_tax( $return = false ) { |
|
223 | +function wpinv_recalculate_tax($return = false) { |
|
224 | 224 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
225 | - if ( empty( $invoice_id ) ) { |
|
225 | + if (empty($invoice_id)) { |
|
226 | 226 | return false; |
227 | 227 | } |
228 | 228 | |
229 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
229 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
230 | 230 | |
231 | - if ( empty( $invoice ) ) { |
|
231 | + if (empty($invoice)) { |
|
232 | 232 | return false; |
233 | 233 | } |
234 | 234 | |
235 | - if ( empty( $_POST['country'] ) ) { |
|
235 | + if (empty($_POST['country'])) { |
|
236 | 236 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
237 | 237 | } |
238 | 238 | |
239 | 239 | $invoice->country = sanitize_text_field($_POST['country']); |
240 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
240 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
241 | 241 | if (isset($_POST['state'])) { |
242 | 242 | $invoice->state = sanitize_text_field($_POST['state']); |
243 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
243 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | $invoice->cart_details = wpinv_get_cart_content_details(); |
247 | 247 | |
248 | - $subtotal = wpinv_get_cart_subtotal( $invoice->cart_details ); |
|
249 | - $tax = wpinv_get_cart_tax( $invoice->cart_details ); |
|
250 | - $total = wpinv_get_cart_total( $invoice->cart_details ); |
|
248 | + $subtotal = wpinv_get_cart_subtotal($invoice->cart_details); |
|
249 | + $tax = wpinv_get_cart_tax($invoice->cart_details); |
|
250 | + $total = wpinv_get_cart_total($invoice->cart_details); |
|
251 | 251 | |
252 | 252 | $invoice->tax = $tax; |
253 | 253 | $invoice->subtotal = $subtotal; |
@@ -255,61 +255,61 @@ discard block |
||
255 | 255 | |
256 | 256 | $invoice->save(); |
257 | 257 | |
258 | - if ( $invoice->is_free_trial() ) { |
|
258 | + if ($invoice->is_free_trial()) { |
|
259 | 259 | $total = 0; |
260 | 260 | } |
261 | 261 | |
262 | 262 | $response = array( |
263 | - 'total' => html_entity_decode( wpinv_price( wpinv_format_amount( $total ) ), ENT_COMPAT, 'UTF-8' ), |
|
263 | + 'total' => html_entity_decode(wpinv_price(wpinv_format_amount($total)), ENT_COMPAT, 'UTF-8'), |
|
264 | 264 | 'total_raw' => $total, |
265 | - 'free' => !( (float)$total > 0 ) && $invoice->is_free() ? true : false, |
|
266 | - 'html' => wpinv_checkout_cart( $invoice->cart_details, false ), |
|
265 | + 'free' => !((float)$total > 0) && $invoice->is_free() ? true : false, |
|
266 | + 'html' => wpinv_checkout_cart($invoice->cart_details, false), |
|
267 | 267 | ); |
268 | 268 | |
269 | - if ( $return ) { |
|
269 | + if ($return) { |
|
270 | 270 | return $response; |
271 | 271 | } |
272 | 272 | |
273 | - wp_send_json( $response ); |
|
273 | + wp_send_json($response); |
|
274 | 274 | } |
275 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
276 | -add_action( 'wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
275 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
276 | +add_action('wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
277 | 277 | |
278 | 278 | // VAT Settings |
279 | -function wpinv_vat_rate_add_callback( $args ) { |
|
279 | +function wpinv_vat_rate_add_callback($args) { |
|
280 | 280 | ?> |
281 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e( 'Add', 'invoicing' );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
281 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
282 | 282 | <?php |
283 | 283 | } |
284 | 284 | |
285 | -function wpinv_vat_rate_delete_callback( $args ) { |
|
285 | +function wpinv_vat_rate_delete_callback($args) { |
|
286 | 286 | global $wpinv_euvat; |
287 | 287 | |
288 | 288 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
289 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : ''; |
|
290 | - if ( isset( $vat_classes[$vat_class] ) ) { |
|
289 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : ''; |
|
290 | + if (isset($vat_classes[$vat_class])) { |
|
291 | 291 | ?> |
292 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf( esc_attr__( 'Delete class "%s"', 'invoicing' ), $vat_classes[$vat_class] );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
292 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf(esc_attr__('Delete class "%s"', 'invoicing'), $vat_classes[$vat_class]); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
293 | 293 | <?php |
294 | 294 | } |
295 | 295 | } |
296 | 296 | |
297 | -function wpinv_vat_rates_callback( $args ) { |
|
297 | +function wpinv_vat_rates_callback($args) { |
|
298 | 298 | global $wpinv_euvat; |
299 | 299 | |
300 | 300 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
301 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard'; |
|
301 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard'; |
|
302 | 302 | |
303 | 303 | $eu_states = $wpinv_euvat->get_eu_states(); |
304 | 304 | $countries = wpinv_get_country_list(); |
305 | 305 | $vat_groups = $wpinv_euvat->get_vat_groups(); |
306 | - $rates = $wpinv_euvat->get_vat_rates( $vat_class ); |
|
306 | + $rates = $wpinv_euvat->get_vat_rates($vat_class); |
|
307 | 307 | ob_start(); |
308 | 308 | ?> |
309 | 309 | </td><tr> |
310 | 310 | <td colspan="2" class="wpinv_vat_tdbox"> |
311 | - <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" /> |
|
312 | - <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p> |
|
311 | + <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" /> |
|
312 | + <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p> |
|
313 | 313 | <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts"> |
314 | 314 | <colgroup> |
315 | 315 | <col width="50px" /> |
@@ -321,43 +321,43 @@ discard block |
||
321 | 321 | </colgroup> |
322 | 322 | <thead> |
323 | 323 | <tr> |
324 | - <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th> |
|
325 | - <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th> |
|
326 | - <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> |
|
327 | - <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th> |
|
328 | - <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th> |
|
324 | + <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th> |
|
325 | + <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th> |
|
326 | + <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> |
|
327 | + <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th> |
|
328 | + <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th> |
|
329 | 329 | </tr> |
330 | 330 | </thead> |
331 | 331 | <tbody> |
332 | - <?php if( !empty( $eu_states ) ) { ?> |
|
332 | + <?php if (!empty($eu_states)) { ?> |
|
333 | 333 | <?php |
334 | - foreach ( $eu_states as $state ) { |
|
335 | - $country_name = isset( $countries[$state] ) ? $countries[$state] : ''; |
|
334 | + foreach ($eu_states as $state) { |
|
335 | + $country_name = isset($countries[$state]) ? $countries[$state] : ''; |
|
336 | 336 | |
337 | 337 | // Filter the rate for each country |
338 | - $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } ); |
|
338 | + $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } ); |
|
339 | 339 | |
340 | 340 | // If one does not exist create a default |
341 | - $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array(); |
|
341 | + $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array(); |
|
342 | 342 | |
343 | - $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true; |
|
344 | - $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : ''; |
|
345 | - $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : ''; |
|
346 | - $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' ); |
|
343 | + $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true; |
|
344 | + $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : ''; |
|
345 | + $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : ''; |
|
346 | + $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced'); |
|
347 | 347 | ?> |
348 | 348 | <tr> |
349 | 349 | <td class="wpinv_vat_country"><?php echo $state; ?><input type="hidden" name="vat_rates[<?php echo $state; ?>][country]" value="<?php echo $state; ?>" /><input type="hidden" name="vat_rates[<?php echo $state; ?>][state]" value="" /></td> |
350 | 350 | <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td> |
351 | 351 | <td class="wpinv_vat_global"> |
352 | - <input type="checkbox" name="vat_rates[<?php echo $state;?>][global]" id="vat_rates[<?php echo $state;?>][global]" value="1" <?php checked( true, $vat_global );?> disabled="disabled" /> |
|
353 | - <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
354 | - <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" /> |
|
352 | + <input type="checkbox" name="vat_rates[<?php echo $state; ?>][global]" id="vat_rates[<?php echo $state; ?>][global]" value="1" <?php checked(true, $vat_global); ?> disabled="disabled" /> |
|
353 | + <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
354 | + <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" /> |
|
355 | 355 | </td> |
356 | - <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state;?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
357 | - <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
356 | + <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state; ?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
357 | + <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
358 | 358 | <td class="wpinv_vat_group"> |
359 | 359 | <?php |
360 | - echo wpinv_html_select( array( |
|
360 | + echo wpinv_html_select(array( |
|
361 | 361 | 'name' => 'vat_rates[' . $state . '][group]', |
362 | 362 | 'selected' => $vat_group, |
363 | 363 | 'id' => 'vat_rates[' . $state . '][group]', |
@@ -367,14 +367,14 @@ discard block |
||
367 | 367 | 'chosen' => false, |
368 | 368 | 'show_option_all' => false, |
369 | 369 | 'show_option_none' => false |
370 | - ) ); |
|
370 | + )); |
|
371 | 371 | ?> |
372 | 372 | </td> |
373 | 373 | </tr> |
374 | 374 | <?php } ?> |
375 | 375 | <tr> |
376 | 376 | <td colspan="6" style="background-color:#fafafa;"> |
377 | - <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e( 'Update EU VAT Rates', 'invoicing' ); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
377 | + <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e('Update EU VAT Rates', 'invoicing'); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
378 | 378 | </td> |
379 | 379 | </tr> |
380 | 380 | <?php } ?> |
@@ -386,35 +386,35 @@ discard block |
||
386 | 386 | echo $content; |
387 | 387 | } |
388 | 388 | |
389 | -function wpinv_vat_number_callback( $args ) { |
|
389 | +function wpinv_vat_number_callback($args) { |
|
390 | 390 | global $wpinv_euvat; |
391 | 391 | |
392 | 392 | $vat_number = $wpinv_euvat->get_vat_number(); |
393 | 393 | $vat_valid = $wpinv_euvat->is_vat_validated(); |
394 | 394 | |
395 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
396 | - $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' ); |
|
395 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
396 | + $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing'); |
|
397 | 397 | $disabled = $vat_valid ? 'disabled="disabled"' : " "; |
398 | 398 | |
399 | - $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr( stripslashes( $vat_number ) ) . '"/>'; |
|
400 | - $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__( 'Validate VAT Number', 'invoicing' ) . '" /></span>'; |
|
399 | + $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr(stripslashes($vat_number)) . '"/>'; |
|
400 | + $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__('Validate VAT Number', 'invoicing') . '" /></span>'; |
|
401 | 401 | $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>'; |
402 | - $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __( 'Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing' ).'</p>' . '</label>'; |
|
403 | - $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">'; |
|
402 | + $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __('Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing') . '</p>' . '</label>'; |
|
403 | + $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">'; |
|
404 | 404 | |
405 | 405 | echo $html; |
406 | 406 | } |
407 | 407 | |
408 | -function wpinv_eu_fallback_rate_callback( $args ) { |
|
408 | +function wpinv_eu_fallback_rate_callback($args) { |
|
409 | 409 | global $wpinv_options; |
410 | 410 | |
411 | - $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' ); |
|
412 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small'; |
|
411 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : ''); |
|
412 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small'; |
|
413 | 413 | |
414 | - $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
415 | - $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>'; |
|
416 | - $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>'; |
|
417 | - $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__( 'Update EU VAT Rates', 'invoicing' ) . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
414 | + $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '" />'; |
|
415 | + $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>'; |
|
416 | + $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>'; |
|
417 | + $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__('Update EU VAT Rates', 'invoicing') . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
418 | 418 | $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>'; |
419 | 419 | echo $html; |
420 | 420 | ?> |
@@ -422,36 +422,36 @@ discard block |
||
422 | 422 | <?php |
423 | 423 | } |
424 | 424 | |
425 | -function wpinv_vat_ip_lookup_callback( $args ) { |
|
425 | +function wpinv_vat_ip_lookup_callback($args) { |
|
426 | 426 | global $wpinv_options, $wpinv_euvat; |
427 | 427 | |
428 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : 'default' ); |
|
428 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : 'default'); |
|
429 | 429 | |
430 | 430 | $options = array(); |
431 | - if ( function_exists( 'geoip_country_code_by_name' ) ) { |
|
432 | - $options['geoip'] = __( 'PHP GeoIP extension', 'invoicing' ); |
|
431 | + if (function_exists('geoip_country_code_by_name')) { |
|
432 | + $options['geoip'] = __('PHP GeoIP extension', 'invoicing'); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | $geoip2_database = $wpinv_euvat->geoip2_country_dbfile(); |
436 | 436 | |
437 | - if ( !function_exists( 'bcadd' ) ) { |
|
438 | - $geoip2_message = __( 'GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing' ); |
|
437 | + if (!function_exists('bcadd')) { |
|
438 | + $geoip2_message = __('GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing'); |
|
439 | 439 | } else { |
440 | - $geoip2_message = ini_get('safe_mode') ? __( 'GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing' ) : ''; |
|
440 | + $geoip2_message = ini_get('safe_mode') ? __('GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing') : ''; |
|
441 | 441 | } |
442 | 442 | |
443 | - if ( $geoip2_database !== false && empty( $geoip2_message ) ) { |
|
444 | - $options['geoip2'] = __( 'GeoIP2 Database', 'invoicing' ); |
|
443 | + if ($geoip2_database !== false && empty($geoip2_message)) { |
|
444 | + $options['geoip2'] = __('GeoIP2 Database', 'invoicing'); |
|
445 | 445 | } |
446 | 446 | |
447 | - if ( function_exists( 'simplexml_load_file' ) ) { |
|
448 | - $options['geoplugin'] = __( 'geoPlugin Web Service', 'invoicing' ); |
|
447 | + if (function_exists('simplexml_load_file')) { |
|
448 | + $options['geoplugin'] = __('geoPlugin Web Service', 'invoicing'); |
|
449 | 449 | } |
450 | 450 | |
451 | - $options['site'] = __( 'Use default country', 'invoicing' ); |
|
452 | - $options['default'] = __( 'Auto', 'invoicing' ); |
|
451 | + $options['site'] = __('Use default country', 'invoicing'); |
|
452 | + $options['default'] = __('Auto', 'invoicing'); |
|
453 | 453 | |
454 | - $html = wpinv_html_select( array( |
|
454 | + $html = wpinv_html_select(array( |
|
455 | 455 | 'name' => "wpinv_settings[{$args['id']}]", |
456 | 456 | 'selected' => $value, |
457 | 457 | 'id' => "wpinv_settings[{$args['id']}]", |
@@ -464,23 +464,23 @@ discard block |
||
464 | 464 | )); |
465 | 465 | |
466 | 466 | $desc = '<label for="wpinv_settings[' . $args['id'] . ']">'; |
467 | - $desc .= __( 'Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing' ); |
|
467 | + $desc .= __('Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing'); |
|
468 | 468 | $desc .= '<p>'; |
469 | - if ( empty( $geoip2_message ) ) { |
|
470 | - if ( $geoip2_database ) { |
|
469 | + if (empty($geoip2_message)) { |
|
470 | + if ($geoip2_database) { |
|
471 | 471 | $last_updated = ''; |
472 | - if ( $time_updated = wpinv_get_option( 'wpinv_geoip2_date_updated' ) ) { |
|
473 | - $date_updated = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time_updated ); |
|
474 | - $last_updated = '<br>' . sprintf( __( 'The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing' ), $date_updated ); |
|
472 | + if ($time_updated = wpinv_get_option('wpinv_geoip2_date_updated')) { |
|
473 | + $date_updated = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time_updated); |
|
474 | + $last_updated = '<br>' . sprintf(__('The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing'), $date_updated); |
|
475 | 475 | } |
476 | - $desc .= __( 'GeoIP2 database exists:', 'invoicing' ) . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __( 'Update GeoIP2 database now (~55MB)', 'invoicing' ) . '"></input>'; |
|
476 | + $desc .= __('GeoIP2 database exists:', 'invoicing') . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __('Update GeoIP2 database now (~55MB)', 'invoicing') . '"></input>'; |
|
477 | 477 | } else { |
478 | - $desc .= __( 'GeoIP2 database does not exist:', 'invoicing' ) . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __( 'Download GeoIP2 database now', 'invoicing' ) . ' (~53MB)"></input><br>' . __( 'After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing' ); |
|
478 | + $desc .= __('GeoIP2 database does not exist:', 'invoicing') . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __('Download GeoIP2 database now', 'invoicing') . ' (~53MB)"></input><br>' . __('After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing'); |
|
479 | 479 | } |
480 | 480 | } else { |
481 | 481 | $desc .= $geoip2_message; |
482 | 482 | } |
483 | - $desc .= '</p><p>'. __( 'GeoPlugin is a great free service please consider supporting them: ', 'invoicing' ) . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
483 | + $desc .= '</p><p>' . __('GeoPlugin is a great free service please consider supporting them: ', 'invoicing') . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
484 | 484 | $desc .= '</label>'; |
485 | 485 | |
486 | 486 | $html .= $desc; |
@@ -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_round_amount( $invoice->get_total() ); |
|
663 | - $args['recurring_amount'] = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) ); |
|
662 | + $args['initial_amount'] = wpinv_round_amount($invoice->get_total()); |
|
663 | + $args['recurring_amount'] = wpinv_round_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 |
@@ -1,23 +1,23 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | function wpinv_gd_active() { |
8 | - return (bool)defined( 'GEODIRECTORY_VERSION' ); |
|
8 | + return (bool)defined('GEODIRECTORY_VERSION'); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | function wpinv_pm_active() { |
12 | - return (bool)wpinv_gd_active() && (bool)defined( 'GEODIRPAYMENT_VERSION' ); |
|
12 | + return (bool)wpinv_gd_active() && (bool)defined('GEODIRPAYMENT_VERSION'); |
|
13 | 13 | } |
14 | 14 | |
15 | -function wpinv_is_gd_post_type( $post_type ) { |
|
15 | +function wpinv_is_gd_post_type($post_type) { |
|
16 | 16 | global $gd_posttypes; |
17 | 17 | |
18 | - $gd_posttypes = !empty( $gd_posttypes ) && is_array( $gd_posttypes ) ? $gd_posttypes : geodir_get_posttypes(); |
|
18 | + $gd_posttypes = !empty($gd_posttypes) && is_array($gd_posttypes) ? $gd_posttypes : geodir_get_posttypes(); |
|
19 | 19 | |
20 | - if ( !empty( $post_type ) && !empty( $gd_posttypes ) && in_array( $post_type, $gd_posttypes ) ) { |
|
20 | + if (!empty($post_type) && !empty($gd_posttypes) && in_array($post_type, $gd_posttypes)) { |
|
21 | 21 | return true; |
22 | 22 | } |
23 | 23 | |
@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | return; |
30 | 30 | } |
31 | 31 | |
32 | - if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) { |
|
32 | + if (!(defined('DOING_AJAX') && DOING_AJAX)) { |
|
33 | 33 | // Add fields for force upgrade |
34 | - if ( defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column') ) { |
|
35 | - geodir_add_column_if_not_exist( INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0' ); |
|
34 | + if (defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column')) { |
|
35 | + geodir_add_column_if_not_exist(INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0'); |
|
36 | 36 | |
37 | 37 | update_option('wpinv_gdp_column', '1'); |
38 | 38 | } |
@@ -40,39 +40,39 @@ discard block |
||
40 | 40 | wpinv_merge_gd_packages_to_items(); |
41 | 41 | } |
42 | 42 | } |
43 | -add_action( 'admin_init', 'wpinv_geodir_integration' ); |
|
43 | +add_action('admin_init', 'wpinv_geodir_integration'); |
|
44 | 44 | |
45 | -function wpinv_get_gdp_package_type( $item_types ) { |
|
46 | - if ( wpinv_pm_active() ) { |
|
47 | - $item_types['package'] = __( 'Package', 'invoicing' ); |
|
45 | +function wpinv_get_gdp_package_type($item_types) { |
|
46 | + if (wpinv_pm_active()) { |
|
47 | + $item_types['package'] = __('Package', 'invoicing'); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | return $item_types; |
51 | 51 | } |
52 | -add_filter( 'wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1 ); |
|
52 | +add_filter('wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1); |
|
53 | 53 | |
54 | 54 | function wpinv_update_package_item($package_id) { |
55 | 55 | return wpinv_merge_gd_package_to_item($package_id, true); |
56 | 56 | } |
57 | 57 | add_action('geodir_after_save_package', 'wpinv_update_package_item', 10, 1); |
58 | 58 | |
59 | -function wpinv_merge_gd_packages_to_items( $force = false ) { |
|
60 | - if ( $merged = get_option( 'wpinv_merge_gd_packages' ) && !$force ) { |
|
59 | +function wpinv_merge_gd_packages_to_items($force = false) { |
|
60 | + if ($merged = get_option('wpinv_merge_gd_packages') && !$force) { |
|
61 | 61 | return true; |
62 | 62 | } |
63 | 63 | |
64 | - if(!function_exists('geodir_package_list_info')){ |
|
64 | + if (!function_exists('geodir_package_list_info')) { |
|
65 | 65 | return false; |
66 | 66 | } |
67 | 67 | |
68 | 68 | $packages = geodir_package_list_info(); |
69 | 69 | |
70 | - foreach ( $packages as $key => $package ) { |
|
71 | - wpinv_merge_gd_package_to_item( $package->pid, $force, $package ); |
|
70 | + foreach ($packages as $key => $package) { |
|
71 | + wpinv_merge_gd_package_to_item($package->pid, $force, $package); |
|
72 | 72 | } |
73 | 73 | |
74 | - if ( !$merged ) { |
|
75 | - update_option( 'wpinv_merge_gd_packages', 1 ); |
|
74 | + if (!$merged) { |
|
75 | + update_option('wpinv_merge_gd_packages', 1); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | return true; |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | |
102 | 102 | $package = empty($package) ? geodir_get_package_info_by_id($package_id, '') : $package; |
103 | 103 | |
104 | - if ( empty($package) || !wpinv_is_gd_post_type( $package->post_type ) ) { |
|
104 | + if (empty($package) || !wpinv_is_gd_post_type($package->post_type)) { |
|
105 | 105 | return false; |
106 | 106 | } |
107 | 107 | |
@@ -111,17 +111,17 @@ discard block |
||
111 | 111 | $meta['post_type'] = $package->post_type; |
112 | 112 | $meta['cpt_singular_name'] = get_post_type_singular_label($package->post_type); |
113 | 113 | $meta['cpt_name'] = get_post_type_plural_label($package->post_type); |
114 | - $meta['price'] = wpinv_round_amount( $package->amount ); |
|
114 | + $meta['price'] = wpinv_round_amount($package->amount); |
|
115 | 115 | $meta['vat_rule'] = 'digital'; |
116 | 116 | $meta['vat_class'] = '_standard'; |
117 | 117 | |
118 | - if ( !empty( $package->sub_active ) ) { |
|
119 | - $sub_num_trial_days = absint( $package->sub_num_trial_days ); |
|
118 | + if (!empty($package->sub_active)) { |
|
119 | + $sub_num_trial_days = absint($package->sub_num_trial_days); |
|
120 | 120 | |
121 | 121 | $meta['is_recurring'] = 1; |
122 | 122 | $meta['recurring_period'] = $package->sub_units; |
123 | - $meta['recurring_interval'] = absint( $package->sub_units_num ); |
|
124 | - $meta['recurring_limit'] = absint( $package->sub_units_num_times ); |
|
123 | + $meta['recurring_interval'] = absint($package->sub_units_num); |
|
124 | + $meta['recurring_limit'] = absint($package->sub_units_num_times); |
|
125 | 125 | $meta['free_trial'] = $sub_num_trial_days > 0 ? 1 : 0; |
126 | 126 | $meta['trial_period'] = $package->sub_num_trial_units; |
127 | 127 | $meta['trial_interval'] = $sub_num_trial_days; |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | $meta['trial_interval'] = ''; |
136 | 136 | } |
137 | 137 | |
138 | - $data = array( |
|
138 | + $data = array( |
|
139 | 139 | 'post_title' => $package->title, |
140 | 140 | 'post_excerpt' => $package->title_desc, |
141 | 141 | 'post_status' => $package->status == 1 ? 'publish' : 'pending', |
@@ -152,48 +152,48 @@ discard block |
||
152 | 152 | return $item; |
153 | 153 | } |
154 | 154 | |
155 | -function wpinv_gdp_to_wpi_gateway( $payment_method ) { |
|
156 | - switch( $payment_method ) { |
|
155 | +function wpinv_gdp_to_wpi_gateway($payment_method) { |
|
156 | + switch ($payment_method) { |
|
157 | 157 | case 'prebanktransfer': |
158 | 158 | $gateway = 'bank_transfer'; |
159 | 159 | break; |
160 | 160 | default: |
161 | - $gateway = empty( $payment_method ) ? 'manual' : $payment_method; |
|
161 | + $gateway = empty($payment_method) ? 'manual' : $payment_method; |
|
162 | 162 | break; |
163 | 163 | } |
164 | 164 | |
165 | - return apply_filters( 'wpinv_gdp_to_wpi_gateway', $gateway, $payment_method ); |
|
165 | + return apply_filters('wpinv_gdp_to_wpi_gateway', $gateway, $payment_method); |
|
166 | 166 | } |
167 | 167 | |
168 | -function wpinv_gdp_to_wpi_gateway_title( $payment_method ) { |
|
169 | - $gateway = wpinv_gdp_to_wpi_gateway( $payment_method ); |
|
168 | +function wpinv_gdp_to_wpi_gateway_title($payment_method) { |
|
169 | + $gateway = wpinv_gdp_to_wpi_gateway($payment_method); |
|
170 | 170 | |
171 | - $gateway_title = wpinv_get_gateway_checkout_label( $gateway ); |
|
171 | + $gateway_title = wpinv_get_gateway_checkout_label($gateway); |
|
172 | 172 | |
173 | - if ( $gateway == $gateway_title ) { |
|
174 | - $gateway_title = geodir_payment_method_title( $gateway ); |
|
173 | + if ($gateway == $gateway_title) { |
|
174 | + $gateway_title = geodir_payment_method_title($gateway); |
|
175 | 175 | } |
176 | 176 | |
177 | - return apply_filters( 'wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method ); |
|
177 | + return apply_filters('wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | function wpinv_print_checkout_errors() { |
181 | 181 | global $wpi_session; |
182 | 182 | wpinv_print_errors(); |
183 | 183 | } |
184 | -add_action( 'geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10 ); |
|
184 | +add_action('geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10); |
|
185 | 185 | |
186 | -function wpinv_cpt_save( $invoice_id, $update = false, $pre_status = NULL ) { |
|
186 | +function wpinv_cpt_save($invoice_id, $update = false, $pre_status = NULL) { |
|
187 | 187 | global $wpi_nosave, $wpi_zero_tax, $wpi_gdp_inv_merge; |
188 | 188 | |
189 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
189 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
190 | 190 | |
191 | - $wpi_invoice_id = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : 0; |
|
191 | + $wpi_invoice_id = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : 0; |
|
192 | 192 | |
193 | 193 | if (!empty($invoice_info)) { |
194 | - $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice( $wpi_invoice_id ) : NULL; |
|
194 | + $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice($wpi_invoice_id) : NULL; |
|
195 | 195 | |
196 | - if ( !empty( $wpi_invoice ) ) { // update invoice |
|
196 | + if (!empty($wpi_invoice)) { // update invoice |
|
197 | 197 | $save = false; |
198 | 198 | if ($invoice_info->coupon_code !== $wpi_invoice->discount_code || (float)$invoice_info->discount < (float)$wpi_invoice->discount || (float)$invoice_info->discount > (float)$wpi_invoice->discount) { |
199 | 199 | $save = true; |
@@ -203,16 +203,16 @@ discard block |
||
203 | 203 | |
204 | 204 | if ($invoice_info->paymentmethod !== $wpi_invoice->gateway) { |
205 | 205 | $save = true; |
206 | - $gateway = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : ''; |
|
207 | - $gateway = wpinv_gdp_to_wpi_gateway( $gateway ); |
|
208 | - $gateway_title = wpinv_gdp_to_wpi_gateway_title( $gateway ); |
|
209 | - $wpi_invoice->set('gateway', $gateway ); |
|
210 | - $wpi_invoice->set('gateway_title', $gateway_title ); |
|
206 | + $gateway = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : ''; |
|
207 | + $gateway = wpinv_gdp_to_wpi_gateway($gateway); |
|
208 | + $gateway_title = wpinv_gdp_to_wpi_gateway_title($gateway); |
|
209 | + $wpi_invoice->set('gateway', $gateway); |
|
210 | + $wpi_invoice->set('gateway_title', $gateway_title); |
|
211 | 211 | } |
212 | 212 | |
213 | - if ( ( $status = wpinv_gdp_to_wpi_status( $invoice_info->status ) ) !== $wpi_invoice->status ) { |
|
213 | + if (($status = wpinv_gdp_to_wpi_status($invoice_info->status)) !== $wpi_invoice->status) { |
|
214 | 214 | $save = true; |
215 | - $wpi_invoice->set( 'status', $status ); |
|
215 | + $wpi_invoice->set('status', $status); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | if ($save) { |
@@ -223,37 +223,37 @@ discard block |
||
223 | 223 | |
224 | 224 | return $wpi_invoice; |
225 | 225 | } else { // create invoice |
226 | - $user_info = get_userdata( $invoice_info->user_id ); |
|
226 | + $user_info = get_userdata($invoice_info->user_id); |
|
227 | 227 | |
228 | - if ( !empty( $pre_status ) ) { |
|
228 | + if (!empty($pre_status)) { |
|
229 | 229 | $invoice_info->status = $pre_status; |
230 | 230 | } |
231 | - $status = wpinv_gdp_to_wpi_status( $invoice_info->status ); |
|
231 | + $status = wpinv_gdp_to_wpi_status($invoice_info->status); |
|
232 | 232 | |
233 | 233 | $wpi_zero_tax = false; |
234 | 234 | |
235 | - if ( $wpi_gdp_inv_merge && in_array( $status, array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) { |
|
235 | + if ($wpi_gdp_inv_merge && in_array($status, array('publish', 'wpi-processing', 'wpi-renewal'))) { |
|
236 | 236 | $wpi_zero_tax = true; |
237 | 237 | } |
238 | 238 | |
239 | 239 | $invoice_data = array(); |
240 | 240 | $invoice_data['invoice_id'] = $wpi_invoice_id; |
241 | 241 | $invoice_data['status'] = $status; |
242 | - if ( $update ) { |
|
242 | + if ($update) { |
|
243 | 243 | //$invoice_data['private_note'] = __( 'Invoice was updated.', 'invoicing' ); |
244 | 244 | } else { |
245 | - $invoice_data['private_note'] = wp_sprintf( __( 'Invoice was created with status %s.', 'invoicing' ), wpinv_status_nicename( $status ) ); |
|
245 | + $invoice_data['private_note'] = wp_sprintf(__('Invoice was created with status %s.', 'invoicing'), wpinv_status_nicename($status)); |
|
246 | 246 | } |
247 | 247 | $invoice_data['user_id'] = $invoice_info->user_id; |
248 | 248 | $invoice_data['created_via'] = 'API'; |
249 | 249 | |
250 | - if ( !empty( $invoice_info->date ) ) { |
|
251 | - $invoice_data['created_date'] = $invoice_info->date; |
|
250 | + if (!empty($invoice_info->date)) { |
|
251 | + $invoice_data['created_date'] = $invoice_info->date; |
|
252 | 252 | } |
253 | 253 | |
254 | - $paymentmethod = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : ''; |
|
255 | - $paymentmethod = wpinv_gdp_to_wpi_gateway( $paymentmethod ); |
|
256 | - $payment_method_title = wpinv_gdp_to_wpi_gateway_title( $paymentmethod ); |
|
254 | + $paymentmethod = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : ''; |
|
255 | + $paymentmethod = wpinv_gdp_to_wpi_gateway($paymentmethod); |
|
256 | + $payment_method_title = wpinv_gdp_to_wpi_gateway_title($paymentmethod); |
|
257 | 257 | |
258 | 258 | $invoice_data['payment_details'] = array( |
259 | 259 | 'gateway' => $paymentmethod, |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | 'paid' => $status === 'publish' ? true : false |
263 | 263 | ); |
264 | 264 | |
265 | - $user_address = wpinv_get_user_address( $invoice_info->user_id, false ); |
|
265 | + $user_address = wpinv_get_user_address($invoice_info->user_id, false); |
|
266 | 266 | |
267 | 267 | $invoice_data['user_info'] = array( |
268 | 268 | 'user_id' => $invoice_info->user_id, |
@@ -285,8 +285,8 @@ discard block |
||
285 | 285 | |
286 | 286 | $post_item = wpinv_get_gd_package_item($invoice_info->package_id); |
287 | 287 | |
288 | - if ( !empty( $post_item ) ) { |
|
289 | - $cart_details = array(); |
|
288 | + if (!empty($post_item)) { |
|
289 | + $cart_details = array(); |
|
290 | 290 | $cart_details[] = array( |
291 | 291 | 'id' => $post_item->ID, |
292 | 292 | 'name' => $post_item->get_name(), |
@@ -299,19 +299,19 @@ discard block |
||
299 | 299 | ), |
300 | 300 | ); |
301 | 301 | |
302 | - $invoice_data['cart_details'] = $cart_details; |
|
302 | + $invoice_data['cart_details'] = $cart_details; |
|
303 | 303 | } |
304 | 304 | |
305 | - $data = array( 'invoice' => $invoice_data ); |
|
305 | + $data = array('invoice' => $invoice_data); |
|
306 | 306 | |
307 | 307 | $wpinv_api = new WPInv_API(); |
308 | - $data = $wpinv_api->insert_invoice( $data ); |
|
308 | + $data = $wpinv_api->insert_invoice($data); |
|
309 | 309 | |
310 | - if ( is_wp_error( $data ) ) { |
|
311 | - wpinv_error_log( 'WPInv_Invoice: ' . $data->get_error_message() ); |
|
310 | + if (is_wp_error($data)) { |
|
311 | + wpinv_error_log('WPInv_Invoice: ' . $data->get_error_message()); |
|
312 | 312 | } else { |
313 | - if ( !empty( $data ) ) { |
|
314 | - update_post_meta( $data->ID, '_wpinv_gdp_id', $invoice_id ); |
|
313 | + if (!empty($data)) { |
|
314 | + update_post_meta($data->ID, '_wpinv_gdp_id', $invoice_id); |
|
315 | 315 | |
316 | 316 | global $wpi_userID, $wpinv_ip_address_country; |
317 | 317 | |
@@ -319,21 +319,21 @@ discard block |
||
319 | 319 | |
320 | 320 | $data_session = array(); |
321 | 321 | $data_session['invoice_id'] = $data->ID; |
322 | - $data_session['cart_discounts'] = $data->get_discounts( true ); |
|
322 | + $data_session['cart_discounts'] = $data->get_discounts(true); |
|
323 | 323 | |
324 | - wpinv_set_checkout_session( $data_session ); |
|
324 | + wpinv_set_checkout_session($data_session); |
|
325 | 325 | |
326 | 326 | $wpi_userID = (int)$data->get_user_id(); |
327 | 327 | $_POST['country'] = !empty($data->country) ? $data->country : wpinv_get_default_country(); |
328 | 328 | |
329 | - $data->country = sanitize_text_field( $_POST['country'] ); |
|
330 | - $data->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
329 | + $data->country = sanitize_text_field($_POST['country']); |
|
330 | + $data->set('country', sanitize_text_field($_POST['country'])); |
|
331 | 331 | |
332 | 332 | $wpinv_ip_address_country = $data->country; |
333 | 333 | |
334 | 334 | $data = $data->recalculate_totals(true); |
335 | 335 | |
336 | - wpinv_set_checkout_session( $checkout_session ); |
|
336 | + wpinv_set_checkout_session($checkout_session); |
|
337 | 337 | |
338 | 338 | $update_data = array(); |
339 | 339 | $update_data['tax_amount'] = $data->get_tax(); |
@@ -341,14 +341,14 @@ discard block |
||
341 | 341 | $update_data['invoice_id'] = $data->ID; |
342 | 342 | |
343 | 343 | global $wpdb; |
344 | - $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $invoice_id ) ); |
|
344 | + $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $invoice_id)); |
|
345 | 345 | |
346 | 346 | return $data; |
347 | 347 | } else { |
348 | - if ( $update ) { |
|
349 | - wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to update invoice.', 'invoicing' ) ); |
|
348 | + if ($update) { |
|
349 | + wpinv_error_log('WPInv_Invoice: ' . __('Fail to update invoice.', 'invoicing')); |
|
350 | 350 | } else { |
351 | - wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to create invoice.', 'invoicing' ) ); |
|
351 | + wpinv_error_log('WPInv_Invoice: ' . __('Fail to create invoice.', 'invoicing')); |
|
352 | 352 | } |
353 | 353 | } |
354 | 354 | } |
@@ -359,59 +359,59 @@ discard block |
||
359 | 359 | } |
360 | 360 | add_action('geodir_payment_invoice_created', 'wpinv_cpt_save', 11, 3); |
361 | 361 | |
362 | -function wpinv_cpt_update( $invoice_id ) { |
|
363 | - return wpinv_cpt_save( $invoice_id, true ); |
|
362 | +function wpinv_cpt_update($invoice_id) { |
|
363 | + return wpinv_cpt_save($invoice_id, true); |
|
364 | 364 | } |
365 | 365 | add_action('geodir_payment_invoice_updated', 'wpinv_cpt_update', 11, 1); |
366 | 366 | |
367 | -function wpinv_payment_status_changed( $invoice_id, $new_status, $old_status = 'pending', $subscription = false ) { |
|
368 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
369 | - if ( empty( $invoice_info ) ) { |
|
367 | +function wpinv_payment_status_changed($invoice_id, $new_status, $old_status = 'pending', $subscription = false) { |
|
368 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
369 | + if (empty($invoice_info)) { |
|
370 | 370 | return false; |
371 | 371 | } |
372 | 372 | |
373 | - $invoice = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL; |
|
374 | - if ( !empty( $invoice ) ) { |
|
373 | + $invoice = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL; |
|
374 | + if (!empty($invoice)) { |
|
375 | 375 | $new_status = wpinv_gdp_to_wpi_status($new_status); |
376 | - $invoice = wpinv_update_payment_status( $invoice->ID, $new_status ); |
|
376 | + $invoice = wpinv_update_payment_status($invoice->ID, $new_status); |
|
377 | 377 | } else { |
378 | - $invoice = wpinv_cpt_save( $invoice_id ); |
|
378 | + $invoice = wpinv_cpt_save($invoice_id); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | return $invoice; |
382 | 382 | } |
383 | -add_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 ); |
|
383 | +add_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4); |
|
384 | 384 | |
385 | -function wpinv_transaction_details_note( $invoice_id, $html ) { |
|
386 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
387 | - if ( empty( $invoice_info ) ) { |
|
385 | +function wpinv_transaction_details_note($invoice_id, $html) { |
|
386 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
387 | + if (empty($invoice_info)) { |
|
388 | 388 | return false; |
389 | 389 | } |
390 | 390 | |
391 | - $wpi_invoice_id = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : NULL; |
|
391 | + $wpi_invoice_id = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : NULL; |
|
392 | 392 | |
393 | - if ( !$wpi_invoice_id ) { |
|
394 | - $invoice = wpinv_cpt_save( $invoice_id, false, $old_status ); |
|
393 | + if (!$wpi_invoice_id) { |
|
394 | + $invoice = wpinv_cpt_save($invoice_id, false, $old_status); |
|
395 | 395 | |
396 | - if ( !empty( $invoice ) ) { |
|
396 | + if (!empty($invoice)) { |
|
397 | 397 | $wpi_invoice_id = $invoice->ID; |
398 | 398 | } |
399 | 399 | } |
400 | 400 | |
401 | - $invoice = wpinv_get_invoice( $wpi_invoice_id ); |
|
401 | + $invoice = wpinv_get_invoice($wpi_invoice_id); |
|
402 | 402 | |
403 | - if ( empty( $invoice ) ) { |
|
403 | + if (empty($invoice)) { |
|
404 | 404 | return false; |
405 | 405 | } |
406 | 406 | |
407 | - return $invoice->add_note( $html, true ); |
|
407 | + return $invoice->add_note($html, true); |
|
408 | 408 | } |
409 | -add_action( 'geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2 ); |
|
409 | +add_action('geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2); |
|
410 | 410 | |
411 | -function wpinv_gdp_to_wpi_status( $status ) { |
|
411 | +function wpinv_gdp_to_wpi_status($status) { |
|
412 | 412 | $inv_status = $status ? $status : 'pending'; |
413 | 413 | |
414 | - switch ( $status ) { |
|
414 | + switch ($status) { |
|
415 | 415 | case 'confirmed': |
416 | 416 | $inv_status = 'publish'; |
417 | 417 | break; |
@@ -420,10 +420,10 @@ discard block |
||
420 | 420 | return $inv_status; |
421 | 421 | } |
422 | 422 | |
423 | -function wpinv_wpi_to_gdp_status( $status ) { |
|
423 | +function wpinv_wpi_to_gdp_status($status) { |
|
424 | 424 | $inv_status = $status ? $status : 'pending'; |
425 | 425 | |
426 | - switch ( $status ) { |
|
426 | + switch ($status) { |
|
427 | 427 | case 'publish': |
428 | 428 | case 'wpi-processing': |
429 | 429 | case 'wpi-renewal': |
@@ -434,102 +434,102 @@ discard block |
||
434 | 434 | return $inv_status; |
435 | 435 | } |
436 | 436 | |
437 | -function wpinv_wpi_to_gdp_id( $invoice_id ) { |
|
437 | +function wpinv_wpi_to_gdp_id($invoice_id) { |
|
438 | 438 | global $wpdb; |
439 | 439 | |
440 | - return $wpdb->get_var( $wpdb->prepare( "SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array( (int)$invoice_id ) ) ); |
|
440 | + return $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array((int)$invoice_id))); |
|
441 | 441 | } |
442 | 442 | |
443 | -function wpinv_gdp_to_wpi_id( $invoice_id ) { |
|
444 | - $invoice = geodir_get_invoice( $invoice_id ); |
|
445 | - return ( empty( $invoice->invoice_id ) ? $invoice->invoice_id : false); |
|
443 | +function wpinv_gdp_to_wpi_id($invoice_id) { |
|
444 | + $invoice = geodir_get_invoice($invoice_id); |
|
445 | + return (empty($invoice->invoice_id) ? $invoice->invoice_id : false); |
|
446 | 446 | } |
447 | 447 | |
448 | -function wpinv_to_gdp_recalculate_total( $invoice, $wpi_nosave ) { |
|
448 | +function wpinv_to_gdp_recalculate_total($invoice, $wpi_nosave) { |
|
449 | 449 | global $wpdb; |
450 | 450 | |
451 | - if ( !empty( $wpi_nosave ) ) { |
|
451 | + if (!empty($wpi_nosave)) { |
|
452 | 452 | return; |
453 | 453 | } |
454 | 454 | |
455 | - $gdp_invoice_id = wpinv_wpi_to_gdp_id( $invoice->ID ); |
|
455 | + $gdp_invoice_id = wpinv_wpi_to_gdp_id($invoice->ID); |
|
456 | 456 | |
457 | - if ( $gdp_invoice_id > 0 ) { |
|
457 | + if ($gdp_invoice_id > 0) { |
|
458 | 458 | $update_data = array(); |
459 | 459 | $update_data['tax_amount'] = $invoice->tax; |
460 | 460 | $update_data['paied_amount'] = $invoice->total; |
461 | 461 | $update_data['discount'] = $invoice->discount; |
462 | 462 | $update_data['coupon_code'] = $invoice->discount_code; |
463 | 463 | |
464 | - $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $gdp_invoice_id ) ); |
|
464 | + $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $gdp_invoice_id)); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | return; |
468 | 468 | } |
469 | 469 | //add_action( 'wpinv_invoice_recalculate_total', 'wpinv_to_gdp_recalculate_total', 10, 2 ); |
470 | 470 | |
471 | -function wpinv_gdp_to_wpi_invoice( $invoice_id ) { |
|
472 | - $invoice = geodir_get_invoice( $invoice_id ); |
|
473 | - if ( empty( $invoice->invoice_id ) ) { |
|
471 | +function wpinv_gdp_to_wpi_invoice($invoice_id) { |
|
472 | + $invoice = geodir_get_invoice($invoice_id); |
|
473 | + if (empty($invoice->invoice_id)) { |
|
474 | 474 | return false; |
475 | 475 | } |
476 | 476 | |
477 | - return wpinv_get_invoice( $invoice->invoice_id ); |
|
477 | + return wpinv_get_invoice($invoice->invoice_id); |
|
478 | 478 | } |
479 | 479 | |
480 | -function wpinv_payment_set_coupon_code( $status, $invoice_id, $coupon_code ) { |
|
481 | - $invoice = wpinv_gdp_to_wpi_invoice( $invoice_id ); |
|
482 | - if ( empty( $invoice ) ) { |
|
480 | +function wpinv_payment_set_coupon_code($status, $invoice_id, $coupon_code) { |
|
481 | + $invoice = wpinv_gdp_to_wpi_invoice($invoice_id); |
|
482 | + if (empty($invoice)) { |
|
483 | 483 | return $status; |
484 | 484 | } |
485 | 485 | |
486 | - if ( $status === 1 || $status === 0 ) { |
|
487 | - if ( $status === 1 ) { |
|
488 | - $discount = geodir_get_discount_amount( $coupon_code, $invoice->get_subtotal() ); |
|
486 | + if ($status === 1 || $status === 0) { |
|
487 | + if ($status === 1) { |
|
488 | + $discount = geodir_get_discount_amount($coupon_code, $invoice->get_subtotal()); |
|
489 | 489 | } else { |
490 | 490 | $discount = ''; |
491 | 491 | $coupon_code = ''; |
492 | 492 | } |
493 | 493 | |
494 | - $invoice->set( 'discount', $discount ); |
|
495 | - $invoice->set( 'discount_code', $coupon_code ); |
|
494 | + $invoice->set('discount', $discount); |
|
495 | + $invoice->set('discount_code', $coupon_code); |
|
496 | 496 | $invoice->save(); |
497 | 497 | $invoice->recalculate_total(); |
498 | 498 | } |
499 | 499 | |
500 | 500 | return $status; |
501 | 501 | } |
502 | -add_filter( 'geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3 ); |
|
502 | +add_filter('geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3); |
|
503 | 503 | |
504 | -function wpinv_insert_invoice( $invoice_data = array() ) { |
|
505 | - if ( empty( $invoice_data ) ) { |
|
504 | +function wpinv_insert_invoice($invoice_data = array()) { |
|
505 | + if (empty($invoice_data)) { |
|
506 | 506 | return false; |
507 | 507 | } |
508 | 508 | |
509 | - if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) { |
|
510 | - return new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast on item.', 'invoicing' ) ); |
|
509 | + if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) { |
|
510 | + return new WP_Error('wpinv_invalid_items', __('Invoice must have atleast on item.', 'invoicing')); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | // default invoice args, note that status is checked for validity in wpinv_create_invoice() |
514 | 514 | $default_args = array( |
515 | - 'status' => !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending', |
|
516 | - 'user_note' => !empty( $invoice_data['note'] ) ? $invoice_data['note'] : null, |
|
517 | - 'invoice_id' => !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0, |
|
518 | - 'user_id' => !empty( $invoice_data['user_id'] ) ? (int)$invoice_data['user_id'] : get_current_user_id(), |
|
515 | + 'status' => !empty($invoice_data['status']) ? $invoice_data['status'] : 'pending', |
|
516 | + 'user_note' => !empty($invoice_data['note']) ? $invoice_data['note'] : null, |
|
517 | + 'invoice_id' => !empty($invoice_data['invoice_id']) ? (int)$invoice_data['invoice_id'] : 0, |
|
518 | + 'user_id' => !empty($invoice_data['user_id']) ? (int)$invoice_data['user_id'] : get_current_user_id(), |
|
519 | 519 | ); |
520 | 520 | |
521 | - $invoice = wpinv_create_invoice( $default_args, $invoice_data ); |
|
522 | - if ( is_wp_error( $invoice ) ) { |
|
521 | + $invoice = wpinv_create_invoice($default_args, $invoice_data); |
|
522 | + if (is_wp_error($invoice)) { |
|
523 | 523 | return $invoice; |
524 | 524 | } |
525 | 525 | |
526 | - $gateway = !empty( $invoice_data['gateway'] ) ? $invoice_data['gateway'] : ''; |
|
527 | - $gateway = empty( $gateway ) && isset( $_POST['gateway'] ) ? $_POST['gateway'] : $gateway; |
|
526 | + $gateway = !empty($invoice_data['gateway']) ? $invoice_data['gateway'] : ''; |
|
527 | + $gateway = empty($gateway) && isset($_POST['gateway']) ? $_POST['gateway'] : $gateway; |
|
528 | 528 | |
529 | - if ( !empty( $gateway ) ) { |
|
530 | - $gateway = wpinv_gdp_to_wpi_gateway( $gateway ); |
|
529 | + if (!empty($gateway)) { |
|
530 | + $gateway = wpinv_gdp_to_wpi_gateway($gateway); |
|
531 | 531 | $invoice_data['payment_details']['gateway'] = $gateway; |
532 | - $invoice_data['payment_details']['gateway_title'] = wpinv_gdp_to_wpi_gateway_title( $gateway ); |
|
532 | + $invoice_data['payment_details']['gateway_title'] = wpinv_gdp_to_wpi_gateway_title($gateway); |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | $user_info = array( |
@@ -550,67 +550,67 @@ discard block |
||
550 | 550 | 'discount' => array(), |
551 | 551 | ); |
552 | 552 | |
553 | - $user_info = wp_parse_args( $invoice_data['user_info'], $user_info ); |
|
553 | + $user_info = wp_parse_args($invoice_data['user_info'], $user_info); |
|
554 | 554 | |
555 | 555 | $payment_details = array(); |
556 | - if ( !empty( $invoice_data['payment_details'] ) ) { |
|
556 | + if (!empty($invoice_data['payment_details'])) { |
|
557 | 557 | $payment_details = array( |
558 | 558 | 'gateway' => 'manual', |
559 | - 'gateway_title' => __( 'Manual Payment', 'invoicing' ), |
|
559 | + 'gateway_title' => __('Manual Payment', 'invoicing'), |
|
560 | 560 | 'currency' => geodir_get_currency_type(), |
561 | 561 | 'paid' => false, |
562 | 562 | 'transaction_id' => '', |
563 | 563 | ); |
564 | - $payment_details = wp_parse_args( $invoice_data['payment_details'], $payment_details ); |
|
564 | + $payment_details = wp_parse_args($invoice_data['payment_details'], $payment_details); |
|
565 | 565 | } |
566 | - $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending' ) ); |
|
567 | - if ( !empty( $payment_details ) ) { |
|
568 | - $invoice->set( 'currency', $payment_details['currency'] ); |
|
569 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
570 | - $invoice->set( 'gateway_title', $payment_details['gateway_title'] ); |
|
571 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
566 | + $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'pending')); |
|
567 | + if (!empty($payment_details)) { |
|
568 | + $invoice->set('currency', $payment_details['currency']); |
|
569 | + $invoice->set('gateway', $payment_details['gateway']); |
|
570 | + $invoice->set('gateway_title', $payment_details['gateway_title']); |
|
571 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
572 | 572 | } |
573 | 573 | |
574 | - $invoice->set( 'user_info', $user_info ); |
|
574 | + $invoice->set('user_info', $user_info); |
|
575 | 575 | ///$invoice->set( 'user_id', $user_info['user_id'] ); |
576 | 576 | ///$invoice->set( 'email', $user_info['email'] ); |
577 | - $invoice->set( 'first_name', $user_info['first_name'] ); |
|
578 | - $invoice->set( 'last_name', $user_info['last_name'] ); |
|
579 | - $invoice->set( 'address', $user_info['address'] ); |
|
580 | - $invoice->set( 'company', $user_info['company'] ); |
|
581 | - $invoice->set( 'vat_number', $user_info['vat_number'] ); |
|
582 | - $invoice->set( 'phone', $user_info['phone'] ); |
|
583 | - $invoice->set( 'city', $user_info['city'] ); |
|
584 | - $invoice->set( 'country', $user_info['country'] ); |
|
585 | - $invoice->set( 'state', $user_info['state'] ); |
|
586 | - $invoice->set( 'zip', $user_info['zip'] ); |
|
587 | - $invoice->set( 'discounts', ( !empty( $user_info['discount'] ) ? $user_info['discount'] : array() ) ); |
|
588 | - $invoice->set( 'ip', wpinv_get_ip() ); |
|
589 | - if ( !empty( $invoice_data['invoice_key'] ) ) { |
|
590 | - $invoice->set( 'key', $invoice_data['invoice_key'] ); |
|
577 | + $invoice->set('first_name', $user_info['first_name']); |
|
578 | + $invoice->set('last_name', $user_info['last_name']); |
|
579 | + $invoice->set('address', $user_info['address']); |
|
580 | + $invoice->set('company', $user_info['company']); |
|
581 | + $invoice->set('vat_number', $user_info['vat_number']); |
|
582 | + $invoice->set('phone', $user_info['phone']); |
|
583 | + $invoice->set('city', $user_info['city']); |
|
584 | + $invoice->set('country', $user_info['country']); |
|
585 | + $invoice->set('state', $user_info['state']); |
|
586 | + $invoice->set('zip', $user_info['zip']); |
|
587 | + $invoice->set('discounts', (!empty($user_info['discount']) ? $user_info['discount'] : array())); |
|
588 | + $invoice->set('ip', wpinv_get_ip()); |
|
589 | + if (!empty($invoice_data['invoice_key'])) { |
|
590 | + $invoice->set('key', $invoice_data['invoice_key']); |
|
591 | 591 | } |
592 | - $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) ); |
|
593 | - $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) ); |
|
592 | + $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live')); |
|
593 | + $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : '')); |
|
594 | 594 | |
595 | 595 | // Add note |
596 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
597 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
596 | + if (!empty($invoice_data['user_note'])) { |
|
597 | + $invoice->add_note($invoice_data['user_note'], true); |
|
598 | 598 | } |
599 | 599 | |
600 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
601 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
600 | + if (!empty($invoice_data['private_note'])) { |
|
601 | + $invoice->add_note($invoice_data['private_note']); |
|
602 | 602 | } |
603 | 603 | |
604 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) { |
|
605 | - foreach ( $invoice_data['cart_details'] as $key => $item ) { |
|
606 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
607 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
608 | - $name = !empty( $item['name'] ) ? $item['name'] : ''; |
|
609 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : ''; |
|
604 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) { |
|
605 | + foreach ($invoice_data['cart_details'] as $key => $item) { |
|
606 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
607 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
608 | + $name = !empty($item['name']) ? $item['name'] : ''; |
|
609 | + $item_price = isset($item['item_price']) ? $item['item_price'] : ''; |
|
610 | 610 | |
611 | - $post_item = new WPInv_Item( $item_id ); |
|
612 | - if ( !empty( $post_item ) ) { |
|
613 | - $name = !empty( $name ) ? $name : $post_item->get_name(); |
|
611 | + $post_item = new WPInv_Item($item_id); |
|
612 | + if (!empty($post_item)) { |
|
613 | + $name = !empty($name) ? $name : $post_item->get_name(); |
|
614 | 614 | $item_price = $item_price !== '' ? $item_price : $post_item->get_price(); |
615 | 615 | } else { |
616 | 616 | continue; |
@@ -620,33 +620,33 @@ discard block |
||
620 | 620 | 'name' => $name, |
621 | 621 | 'quantity' => $quantity, |
622 | 622 | 'item_price' => $item_price, |
623 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0.00, |
|
624 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
625 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
626 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
623 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0.00, |
|
624 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
625 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
626 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
627 | 627 | ); |
628 | 628 | |
629 | - $invoice->add_item( $item_id, $args ); |
|
629 | + $invoice->add_item($item_id, $args); |
|
630 | 630 | } |
631 | 631 | } |
632 | 632 | |
633 | - $invoice->increase_tax( wpinv_get_cart_fee_tax() ); |
|
633 | + $invoice->increase_tax(wpinv_get_cart_fee_tax()); |
|
634 | 634 | |
635 | - if ( isset( $invoice_data['post_date'] ) ) { |
|
636 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
635 | + if (isset($invoice_data['post_date'])) { |
|
636 | + $invoice->set('date', $invoice_data['post_date']); |
|
637 | 637 | } |
638 | 638 | |
639 | - $number = wpinv_format_invoice_number( $invoice->ID ); |
|
640 | - $invoice->set( 'number', $number ); |
|
641 | - update_option( 'wpinv_last_invoice_number', $number ); |
|
639 | + $number = wpinv_format_invoice_number($invoice->ID); |
|
640 | + $invoice->set('number', $number); |
|
641 | + update_option('wpinv_last_invoice_number', $number); |
|
642 | 642 | |
643 | 643 | $invoice->save(); |
644 | 644 | |
645 | - do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data ); |
|
645 | + do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data); |
|
646 | 646 | |
647 | - if ( ! empty( $invoice->ID ) ) { |
|
647 | + if (!empty($invoice->ID)) { |
|
648 | 648 | // payment method (and payment_complete() if `paid` == true) |
649 | - if ( !empty( $payment_details['paid'] ) ) { |
|
649 | + if (!empty($payment_details['paid'])) { |
|
650 | 650 | //$invoice->payment_complete( !empty( $payment_details['transaction_id'] ) ? $payment_details['transaction_id'] : $invoice->ID ); |
651 | 651 | } |
652 | 652 | |
@@ -663,158 +663,158 @@ discard block |
||
663 | 663 | } |
664 | 664 | ?> |
665 | 665 | <tr> |
666 | - <td><?php _e( 'Merge Price Packages', 'invoicing' ); ?></td> |
|
667 | - <td><p><?php _e( 'Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing' ); ?></p></td> |
|
668 | - <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
666 | + <td><?php _e('Merge Price Packages', 'invoicing'); ?></td> |
|
667 | + <td><p><?php _e('Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing'); ?></p></td> |
|
668 | + <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
669 | 669 | </tr> |
670 | 670 | <tr> |
671 | - <td><?php _e( 'Merge Invoices', 'invoicing' ); ?></td> |
|
672 | - <td><p><?php _e( 'Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing' ); ?></p></td> |
|
673 | - <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
671 | + <td><?php _e('Merge Invoices', 'invoicing'); ?></td> |
|
672 | + <td><p><?php _e('Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing'); ?></p></td> |
|
673 | + <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
674 | 674 | </tr> |
675 | 675 | <tr> |
676 | - <td><?php _e( 'Fix Taxes for Merged Invoices', 'invoicing' ); ?></td> |
|
677 | - <td><p><?php _e( 'Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing' ); ?></p></td> |
|
678 | - <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
676 | + <td><?php _e('Fix Taxes for Merged Invoices', 'invoicing'); ?></td> |
|
677 | + <td><p><?php _e('Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing'); ?></p></td> |
|
678 | + <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
679 | 679 | </tr> |
680 | 680 | <tr> |
681 | - <td><?php _e( 'Merge Coupons', 'invoicing' ); ?></td> |
|
682 | - <td><p><?php _e( 'Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing' ); ?></p></td> |
|
683 | - <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
681 | + <td><?php _e('Merge Coupons', 'invoicing'); ?></td> |
|
682 | + <td><p><?php _e('Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing'); ?></p></td> |
|
683 | + <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
684 | 684 | </tr> |
685 | 685 | <?php |
686 | 686 | } |
687 | -add_action( 'wpinv_tools_row', 'wpinv_merge_gd_invoices', 10 ); |
|
687 | +add_action('wpinv_tools_row', 'wpinv_merge_gd_invoices', 10); |
|
688 | 688 | |
689 | 689 | function wpinv_tool_merge_packages() { |
690 | 690 | $packages = geodir_package_list_info(); |
691 | 691 | |
692 | 692 | $count = 0; |
693 | 693 | |
694 | - if ( !empty( $packages ) ) { |
|
694 | + if (!empty($packages)) { |
|
695 | 695 | $success = true; |
696 | 696 | |
697 | - foreach ( $packages as $key => $package ) { |
|
697 | + foreach ($packages as $key => $package) { |
|
698 | 698 | $item = wpinv_get_item_by('package_id', $package->pid); |
699 | - if ( !empty( $item ) ) { |
|
699 | + if (!empty($item)) { |
|
700 | 700 | continue; |
701 | 701 | } |
702 | 702 | |
703 | - $merged = wpinv_merge_gd_package_to_item( $package->pid, false, $package ); |
|
703 | + $merged = wpinv_merge_gd_package_to_item($package->pid, false, $package); |
|
704 | 704 | |
705 | - if ( !empty( $merged ) ) { |
|
706 | - wpinv_error_log( 'Package merge S : ' . $package->pid ); |
|
705 | + if (!empty($merged)) { |
|
706 | + wpinv_error_log('Package merge S : ' . $package->pid); |
|
707 | 707 | $count++; |
708 | 708 | } else { |
709 | - wpinv_error_log( 'Package merge F : ' . $package->pid ); |
|
709 | + wpinv_error_log('Package merge F : ' . $package->pid); |
|
710 | 710 | } |
711 | 711 | } |
712 | 712 | |
713 | - if ( $count > 0 ) { |
|
714 | - $message = sprintf( _n( 'Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing' ), $count ); |
|
713 | + if ($count > 0) { |
|
714 | + $message = sprintf(_n('Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing'), $count); |
|
715 | 715 | } else { |
716 | - $message = __( 'No price packages merged.', 'invoicing' ); |
|
716 | + $message = __('No price packages merged.', 'invoicing'); |
|
717 | 717 | } |
718 | 718 | } else { |
719 | 719 | $success = false; |
720 | - $message = __( 'No price packages found to merge!', 'invoicing' ); |
|
720 | + $message = __('No price packages found to merge!', 'invoicing'); |
|
721 | 721 | } |
722 | 722 | |
723 | 723 | $response = array(); |
724 | 724 | $response['success'] = $success; |
725 | 725 | $response['data']['message'] = $message; |
726 | - wp_send_json( $response ); |
|
726 | + wp_send_json($response); |
|
727 | 727 | } |
728 | -add_action( 'wpinv_tool_merge_packages', 'wpinv_tool_merge_packages' ); |
|
728 | +add_action('wpinv_tool_merge_packages', 'wpinv_tool_merge_packages'); |
|
729 | 729 | |
730 | 730 | function wpinv_tool_merge_invoices() { |
731 | 731 | global $wpdb, $wpi_gdp_inv_merge, $wpi_tax_rates; |
732 | 732 | |
733 | 733 | $sql = "SELECT `gdi`.`id`, `gdi`.`date`, `gdi`.`date_updated` FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NULL ORDER BY `gdi`.`id` ASC"; |
734 | - $items = $wpdb->get_results( $sql ); |
|
734 | + $items = $wpdb->get_results($sql); |
|
735 | 735 | |
736 | 736 | $count = 0; |
737 | 737 | |
738 | - if ( !empty( $items ) ) { |
|
738 | + if (!empty($items)) { |
|
739 | 739 | $success = true; |
740 | 740 | $wpi_gdp_inv_merge = true; |
741 | 741 | |
742 | - foreach ( $items as $item ) { |
|
742 | + foreach ($items as $item) { |
|
743 | 743 | $wpi_tax_rates = NULL; |
744 | 744 | |
745 | - $wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'" ); |
|
745 | + $wpdb->query("UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'"); |
|
746 | 746 | |
747 | - $merged = wpinv_cpt_save( $item->id ); |
|
747 | + $merged = wpinv_cpt_save($item->id); |
|
748 | 748 | |
749 | - if ( !empty( $merged ) && !empty( $merged->ID ) ) { |
|
749 | + if (!empty($merged) && !empty($merged->ID)) { |
|
750 | 750 | $count++; |
751 | 751 | |
752 | 752 | //$wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = '" . $merged->ID . "' WHERE id = '" . $item->id . "'" ); |
753 | 753 | |
754 | - $post_date = !empty( $item->date ) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time( 'mysql' ); |
|
755 | - $post_date_gmt = get_gmt_from_date( $post_date ); |
|
756 | - $post_modified = !empty( $item->date_updated ) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date; |
|
757 | - $post_modified_gmt = get_gmt_from_date( $post_modified ); |
|
754 | + $post_date = !empty($item->date) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time('mysql'); |
|
755 | + $post_date_gmt = get_gmt_from_date($post_date); |
|
756 | + $post_modified = !empty($item->date_updated) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date; |
|
757 | + $post_modified_gmt = get_gmt_from_date($post_modified); |
|
758 | 758 | |
759 | - $wpdb->update( $wpdb->posts, array( 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt ), array( 'ID' => $merged->ID ) ); |
|
759 | + $wpdb->update($wpdb->posts, array('post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt), array('ID' => $merged->ID)); |
|
760 | 760 | |
761 | - if ( $merged->is_paid() ) { |
|
762 | - update_post_meta( $merged->ID, '_wpinv_completed_date', $post_modified ); |
|
761 | + if ($merged->is_paid()) { |
|
762 | + update_post_meta($merged->ID, '_wpinv_completed_date', $post_modified); |
|
763 | 763 | } |
764 | 764 | |
765 | - clean_post_cache( $merged->ID ); |
|
765 | + clean_post_cache($merged->ID); |
|
766 | 766 | |
767 | - wpinv_error_log( 'Invoice merge S : ' . $item->id . ' => ' . $merged->ID ); |
|
767 | + wpinv_error_log('Invoice merge S : ' . $item->id . ' => ' . $merged->ID); |
|
768 | 768 | } else { |
769 | - wpinv_error_log( 'Invoice merge F : ' . $item->id ); |
|
769 | + wpinv_error_log('Invoice merge F : ' . $item->id); |
|
770 | 770 | } |
771 | 771 | } |
772 | 772 | |
773 | 773 | $wpi_gdp_inv_merge = false; |
774 | 774 | |
775 | - if ( $count > 0 ) { |
|
776 | - $message = sprintf( _n( 'Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing' ), $count ); |
|
775 | + if ($count > 0) { |
|
776 | + $message = sprintf(_n('Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing'), $count); |
|
777 | 777 | } else { |
778 | - $message = __( 'No invoices merged.', 'invoicing' ); |
|
778 | + $message = __('No invoices merged.', 'invoicing'); |
|
779 | 779 | } |
780 | 780 | } else { |
781 | 781 | $success = false; |
782 | - $message = __( 'No invoices found to merge!', 'invoicing' ); |
|
782 | + $message = __('No invoices found to merge!', 'invoicing'); |
|
783 | 783 | } |
784 | 784 | |
785 | 785 | $response = array(); |
786 | 786 | $response['success'] = $success; |
787 | 787 | $response['data']['message'] = $message; |
788 | - wp_send_json( $response ); |
|
788 | + wp_send_json($response); |
|
789 | 789 | } |
790 | -add_action( 'wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices' ); |
|
790 | +add_action('wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices'); |
|
791 | 791 | |
792 | 792 | function wpinv_tool_merge_coupons() { |
793 | 793 | global $wpdb; |
794 | 794 | |
795 | 795 | $sql = "SELECT * FROM `" . COUPON_TABLE . "` WHERE `coupon_code` IS NOT NULL AND `coupon_code` != '' ORDER BY `cid` ASC"; |
796 | - $items = $wpdb->get_results( $sql ); |
|
796 | + $items = $wpdb->get_results($sql); |
|
797 | 797 | $count = 0; |
798 | 798 | |
799 | - if ( !empty( $items ) ) { |
|
799 | + if (!empty($items)) { |
|
800 | 800 | $success = true; |
801 | 801 | |
802 | - foreach ( $items as $item ) { |
|
803 | - if ( wpinv_get_discount_by_code( $item->coupon_code ) ) { |
|
802 | + foreach ($items as $item) { |
|
803 | + if (wpinv_get_discount_by_code($item->coupon_code)) { |
|
804 | 804 | continue; |
805 | 805 | } |
806 | 806 | |
807 | 807 | $args = array( |
808 | 808 | 'post_type' => 'wpi_discount', |
809 | 809 | 'post_title' => $item->coupon_code, |
810 | - 'post_status' => !empty( $item->status ) ? 'publish' : 'pending' |
|
810 | + 'post_status' => !empty($item->status) ? 'publish' : 'pending' |
|
811 | 811 | ); |
812 | 812 | |
813 | - $merged = wp_insert_post( $args ); |
|
813 | + $merged = wp_insert_post($args); |
|
814 | 814 | |
815 | 815 | $item_id = $item->cid; |
816 | 816 | |
817 | - if ( $merged ) { |
|
817 | + if ($merged) { |
|
818 | 818 | $meta = array( |
819 | 819 | 'code' => $item->coupon_code, |
820 | 820 | 'type' => $item->discount_type != 'per' ? 'flat' : 'percent', |
@@ -822,65 +822,65 @@ discard block |
||
822 | 822 | 'max_uses' => (int)$item->usage_limit, |
823 | 823 | 'uses' => (int)$item->usage_count, |
824 | 824 | ); |
825 | - wpinv_store_discount( $merged, $meta, get_post( $merged ) ); |
|
825 | + wpinv_store_discount($merged, $meta, get_post($merged)); |
|
826 | 826 | |
827 | 827 | $count++; |
828 | 828 | |
829 | - wpinv_error_log( 'Coupon merge S : ' . $item_id . ' => ' . $merged ); |
|
829 | + wpinv_error_log('Coupon merge S : ' . $item_id . ' => ' . $merged); |
|
830 | 830 | } else { |
831 | - wpinv_error_log( 'Coupon merge F : ' . $item_id ); |
|
831 | + wpinv_error_log('Coupon merge F : ' . $item_id); |
|
832 | 832 | } |
833 | 833 | } |
834 | 834 | |
835 | - if ( $count > 0 ) { |
|
836 | - $message = sprintf( _n( 'Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing' ), $count ); |
|
835 | + if ($count > 0) { |
|
836 | + $message = sprintf(_n('Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing'), $count); |
|
837 | 837 | } else { |
838 | - $message = __( 'No coupons merged.', 'invoicing' ); |
|
838 | + $message = __('No coupons merged.', 'invoicing'); |
|
839 | 839 | } |
840 | 840 | } else { |
841 | 841 | $success = false; |
842 | - $message = __( 'No coupons found to merge!', 'invoicing' ); |
|
842 | + $message = __('No coupons found to merge!', 'invoicing'); |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | $response = array(); |
846 | 846 | $response['success'] = $success; |
847 | 847 | $response['data']['message'] = $message; |
848 | - wp_send_json( $response ); |
|
848 | + wp_send_json($response); |
|
849 | 849 | } |
850 | -add_action( 'wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons' ); |
|
850 | +add_action('wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons'); |
|
851 | 851 | |
852 | -function wpinv_gdp_to_wpi_currency( $value, $option = '' ) { |
|
852 | +function wpinv_gdp_to_wpi_currency($value, $option = '') { |
|
853 | 853 | return wpinv_get_currency(); |
854 | 854 | } |
855 | -add_filter( 'pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2 ); |
|
855 | +add_filter('pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2); |
|
856 | 856 | |
857 | -function wpinv_gdp_to_wpi_currency_sign( $value, $option = '' ) { |
|
857 | +function wpinv_gdp_to_wpi_currency_sign($value, $option = '') { |
|
858 | 858 | return wpinv_currency_symbol(); |
859 | 859 | } |
860 | -add_filter( 'pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2 ); |
|
860 | +add_filter('pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2); |
|
861 | 861 | |
862 | -function wpinv_gdp_to_wpi_display_price( $price, $amount, $display = true , $decimal_sep, $thousand_sep ) { |
|
863 | - if ( !$display ) { |
|
864 | - $price = wpinv_round_amount( $amount ); |
|
862 | +function wpinv_gdp_to_wpi_display_price($price, $amount, $display = true, $decimal_sep, $thousand_sep) { |
|
863 | + if (!$display) { |
|
864 | + $price = wpinv_round_amount($amount); |
|
865 | 865 | } else { |
866 | - $price = wpinv_price( wpinv_format_amount( $amount ) ); |
|
866 | + $price = wpinv_price(wpinv_format_amount($amount)); |
|
867 | 867 | } |
868 | 868 | |
869 | 869 | return $price; |
870 | 870 | } |
871 | -add_filter( 'geodir_payment_price' , 'wpinv_gdp_to_wpi_display_price', 10000, 5 ); |
|
871 | +add_filter('geodir_payment_price', 'wpinv_gdp_to_wpi_display_price', 10000, 5); |
|
872 | 872 | |
873 | -function wpinv_gdp_to_inv_checkout_redirect( $redirect_url ) { |
|
873 | +function wpinv_gdp_to_inv_checkout_redirect($redirect_url) { |
|
874 | 874 | $invoice_id = geodir_payment_cart_id(); |
875 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
876 | - $wpi_invoice = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL; |
|
875 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
876 | + $wpi_invoice = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL; |
|
877 | 877 | |
878 | - if ( !( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) ) { |
|
879 | - $wpi_invoice_id = wpinv_cpt_save( $invoice_id ); |
|
880 | - $wpi_invoice = wpinv_get_invoice( $wpi_invoice_id ); |
|
878 | + if (!(!empty($wpi_invoice) && !empty($wpi_invoice->ID))) { |
|
879 | + $wpi_invoice_id = wpinv_cpt_save($invoice_id); |
|
880 | + $wpi_invoice = wpinv_get_invoice($wpi_invoice_id); |
|
881 | 881 | } |
882 | 882 | |
883 | - if ( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) { |
|
883 | + if (!empty($wpi_invoice) && !empty($wpi_invoice->ID)) { |
|
884 | 884 | |
885 | 885 | // Clear cart |
886 | 886 | geodir_payment_clear_cart(); |
@@ -890,121 +890,121 @@ discard block |
||
890 | 890 | |
891 | 891 | return $redirect_url; |
892 | 892 | } |
893 | -add_filter( 'geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1 ); |
|
893 | +add_filter('geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1); |
|
894 | 894 | |
895 | -function wpinv_gdp_dashboard_invoice_history_link( $dashboard_links ) { |
|
896 | - if ( get_current_user_id() ) { |
|
897 | - $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url( wpinv_get_history_page_uri() ) . '">' . __( 'My Invoice History', 'invoicing' ) . '</a></li>'; |
|
895 | +function wpinv_gdp_dashboard_invoice_history_link($dashboard_links) { |
|
896 | + if (get_current_user_id()) { |
|
897 | + $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url(wpinv_get_history_page_uri()) . '">' . __('My Invoice History', 'invoicing') . '</a></li>'; |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | return $dashboard_links; |
901 | 901 | } |
902 | -add_action( 'geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link' ); |
|
903 | -remove_action( 'geodir_dashboard_links', 'geodir_payment_invoices_list_page_link' ); |
|
902 | +add_action('geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link'); |
|
903 | +remove_action('geodir_dashboard_links', 'geodir_payment_invoices_list_page_link'); |
|
904 | 904 | |
905 | -function wpinv_wpi_to_gdp_update_status( $invoice_id, $new_status, $old_status ) { |
|
905 | +function wpinv_wpi_to_gdp_update_status($invoice_id, $new_status, $old_status) { |
|
906 | 906 | if (!defined('GEODIRPAYMENT_VERSION')) { |
907 | 907 | return false; |
908 | 908 | } |
909 | 909 | |
910 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
911 | - if ( empty( $invoice ) ) { |
|
910 | + $invoice = wpinv_get_invoice($invoice_id); |
|
911 | + if (empty($invoice)) { |
|
912 | 912 | return false; |
913 | 913 | } |
914 | 914 | |
915 | - remove_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 ); |
|
915 | + remove_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4); |
|
916 | 916 | |
917 | - $invoice_id = wpinv_wpi_to_gdp_id( $invoice_id ); |
|
918 | - $new_status = wpinv_wpi_to_gdp_status( $new_status ); |
|
917 | + $invoice_id = wpinv_wpi_to_gdp_id($invoice_id); |
|
918 | + $new_status = wpinv_wpi_to_gdp_status($new_status); |
|
919 | 919 | |
920 | - geodir_update_invoice_status( $invoice_id, $new_status, $invoice->is_recurring() ); |
|
920 | + geodir_update_invoice_status($invoice_id, $new_status, $invoice->is_recurring()); |
|
921 | 921 | } |
922 | -add_action( 'wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3 ); |
|
922 | +add_action('wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3); |
|
923 | 923 | |
924 | -function wpinv_gdp_to_wpi_delete_package( $gd_package_id ) { |
|
925 | - $item = wpinv_get_item_by( 'package_id', $gd_package_id ); |
|
924 | +function wpinv_gdp_to_wpi_delete_package($gd_package_id) { |
|
925 | + $item = wpinv_get_item_by('package_id', $gd_package_id); |
|
926 | 926 | |
927 | - if ( !empty( $item ) ) { |
|
928 | - wpinv_remove_item( $item, true ); |
|
927 | + if (!empty($item)) { |
|
928 | + wpinv_remove_item($item, true); |
|
929 | 929 | } |
930 | 930 | } |
931 | -add_action( 'geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1 ) ; |
|
931 | +add_action('geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1); |
|
932 | 932 | |
933 | -function wpinv_can_delete_package_item( $return, $post_id ) { |
|
934 | - if ( $return && function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && $package_id = get_post_meta( $post_id, '_wpinv_package_id', true ) ) { |
|
935 | - $gd_package = geodir_get_package_info_by_id( $package_id, '' ); |
|
933 | +function wpinv_can_delete_package_item($return, $post_id) { |
|
934 | + if ($return && function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && $package_id = get_post_meta($post_id, '_wpinv_package_id', true)) { |
|
935 | + $gd_package = geodir_get_package_info_by_id($package_id, ''); |
|
936 | 936 | |
937 | - if ( !empty( $gd_package ) ) { |
|
937 | + if (!empty($gd_package)) { |
|
938 | 938 | $return = false; |
939 | 939 | } |
940 | 940 | } |
941 | 941 | |
942 | 942 | return $return; |
943 | 943 | } |
944 | -add_filter( 'wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2 ); |
|
944 | +add_filter('wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2); |
|
945 | 945 | |
946 | -function wpinv_package_item_classes( $classes, $class, $post_id ) { |
|
946 | +function wpinv_package_item_classes($classes, $class, $post_id) { |
|
947 | 947 | global $typenow; |
948 | 948 | |
949 | - if ( $typenow == 'wpi_item' && in_array( 'wpi-gd-package', $classes ) ) { |
|
950 | - if ( wpinv_item_in_use( $post_id ) ) { |
|
949 | + if ($typenow == 'wpi_item' && in_array('wpi-gd-package', $classes)) { |
|
950 | + if (wpinv_item_in_use($post_id)) { |
|
951 | 951 | $classes[] = 'wpi-inuse-pkg'; |
952 | - } else if ( !( function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && geodir_get_package_info_by_id( (int)get_post_meta( $post_id, '_wpinv_package_id', true ), '' ) ) ) { |
|
952 | + } else if (!(function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && geodir_get_package_info_by_id((int)get_post_meta($post_id, '_wpinv_package_id', true), ''))) { |
|
953 | 953 | $classes[] = 'wpi-delete-pkg'; |
954 | 954 | } |
955 | 955 | } |
956 | 956 | |
957 | 957 | return $classes; |
958 | 958 | } |
959 | -add_filter( 'post_class', 'wpinv_package_item_classes', 10, 3 ); |
|
959 | +add_filter('post_class', 'wpinv_package_item_classes', 10, 3); |
|
960 | 960 | |
961 | -function wpinv_gdp_package_type_info( $post ) { |
|
962 | - if ( wpinv_pm_active() ) { |
|
963 | - ?><p class="wpi-m0"><?php _e( 'Package: GeoDirectory price packages items.', 'invoicing' );?></p> |
|
961 | +function wpinv_gdp_package_type_info($post) { |
|
962 | + if (wpinv_pm_active()) { |
|
963 | + ?><p class="wpi-m0"><?php _e('Package: GeoDirectory price packages items.', 'invoicing'); ?></p> |
|
964 | 964 | <?php |
965 | 965 | } |
966 | 966 | } |
967 | -add_action( 'wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1 ) ; |
|
967 | +add_action('wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1); |
|
968 | 968 | |
969 | -function wpinv_gdp_to_gdi_set_zero_tax( $is_taxable, $item_id, $country , $state ) { |
|
969 | +function wpinv_gdp_to_gdi_set_zero_tax($is_taxable, $item_id, $country, $state) { |
|
970 | 970 | global $wpi_zero_tax; |
971 | 971 | |
972 | - if ( $wpi_zero_tax ) { |
|
972 | + if ($wpi_zero_tax) { |
|
973 | 973 | $is_taxable = false; |
974 | 974 | } |
975 | 975 | |
976 | 976 | return $is_taxable; |
977 | 977 | } |
978 | -add_action( 'wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4 ) ; |
|
978 | +add_action('wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4); |
|
979 | 979 | |
980 | 980 | function wpinv_tool_merge_fix_taxes() { |
981 | 981 | global $wpdb; |
982 | 982 | |
983 | 983 | $sql = "SELECT DISTINCT p.ID FROM `" . $wpdb->posts . "` AS p LEFT JOIN " . $wpdb->postmeta . " AS pm ON pm.post_id = p.ID WHERE p.post_type = 'wpi_item' AND pm.meta_key = '_wpinv_type' AND pm.meta_value = 'package'"; |
984 | - $items = $wpdb->get_results( $sql ); |
|
984 | + $items = $wpdb->get_results($sql); |
|
985 | 985 | |
986 | - if ( !empty( $items ) ) { |
|
987 | - foreach ( $items as $item ) { |
|
988 | - if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) { |
|
989 | - update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' ); |
|
986 | + if (!empty($items)) { |
|
987 | + foreach ($items as $item) { |
|
988 | + if (get_post_meta($item->ID, '_wpinv_vat_class', true) == '_exempt') { |
|
989 | + update_post_meta($item->ID, '_wpinv_vat_class', '_standard'); |
|
990 | 990 | } |
991 | 991 | } |
992 | 992 | } |
993 | 993 | |
994 | 994 | $sql = "SELECT `p`.`ID`, gdi.id AS gdp_id FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NOT NULL AND p.post_status NOT IN( 'publish', 'wpi-processing', 'wpi-renewal' ) ORDER BY `gdi`.`id` ASC"; |
995 | - $items = $wpdb->get_results( $sql ); |
|
995 | + $items = $wpdb->get_results($sql); |
|
996 | 996 | |
997 | - if ( !empty( $items ) ) { |
|
997 | + if (!empty($items)) { |
|
998 | 998 | $success = false; |
999 | - $message = __( 'Taxes fixed for non-paid merged GD invoices.', 'invoicing' ); |
|
999 | + $message = __('Taxes fixed for non-paid merged GD invoices.', 'invoicing'); |
|
1000 | 1000 | |
1001 | 1001 | global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates; |
1002 | 1002 | |
1003 | - foreach ( $items as $item ) { |
|
1003 | + foreach ($items as $item) { |
|
1004 | 1004 | $wpi_tax_rates = NULL; |
1005 | 1005 | $data = wpinv_get_invoice($item->ID); |
1006 | 1006 | |
1007 | - if ( empty( $data ) ) { |
|
1007 | + if (empty($data)) { |
|
1008 | 1008 | continue; |
1009 | 1009 | } |
1010 | 1010 | |
@@ -1012,51 +1012,51 @@ discard block |
||
1012 | 1012 | |
1013 | 1013 | $data_session = array(); |
1014 | 1014 | $data_session['invoice_id'] = $data->ID; |
1015 | - $data_session['cart_discounts'] = $data->get_discounts( true ); |
|
1015 | + $data_session['cart_discounts'] = $data->get_discounts(true); |
|
1016 | 1016 | |
1017 | - wpinv_set_checkout_session( $data_session ); |
|
1017 | + wpinv_set_checkout_session($data_session); |
|
1018 | 1018 | |
1019 | 1019 | $wpi_userID = (int)$data->get_user_id(); |
1020 | 1020 | $_POST['country'] = !empty($data->country) ? $data->country : wpinv_get_default_country(); |
1021 | 1021 | |
1022 | - $data->country = sanitize_text_field( $_POST['country'] ); |
|
1023 | - $data->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
1022 | + $data->country = sanitize_text_field($_POST['country']); |
|
1023 | + $data->set('country', sanitize_text_field($_POST['country'])); |
|
1024 | 1024 | |
1025 | 1025 | $wpinv_ip_address_country = $data->country; |
1026 | 1026 | |
1027 | 1027 | $data->recalculate_totals(true); |
1028 | 1028 | |
1029 | - wpinv_set_checkout_session( $checkout_session ); |
|
1029 | + wpinv_set_checkout_session($checkout_session); |
|
1030 | 1030 | |
1031 | 1031 | $update_data = array(); |
1032 | 1032 | $update_data['tax_amount'] = $data->get_tax(); |
1033 | 1033 | $update_data['paied_amount'] = $data->get_total(); |
1034 | 1034 | $update_data['invoice_id'] = $data->ID; |
1035 | 1035 | |
1036 | - $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) ); |
|
1036 | + $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $item->gdp_id)); |
|
1037 | 1037 | } |
1038 | 1038 | } else { |
1039 | 1039 | $success = false; |
1040 | - $message = __( 'No invoices found to fix taxes!', 'invoicing' ); |
|
1040 | + $message = __('No invoices found to fix taxes!', 'invoicing'); |
|
1041 | 1041 | } |
1042 | 1042 | |
1043 | 1043 | $response = array(); |
1044 | 1044 | $response['success'] = $success; |
1045 | 1045 | $response['data']['message'] = $message; |
1046 | - wp_send_json( $response ); |
|
1046 | + wp_send_json($response); |
|
1047 | 1047 | } |
1048 | -add_action( 'wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes' ); |
|
1049 | -remove_action( 'geodir_before_detail_fields' , 'geodir_build_coupon', 2 ); |
|
1048 | +add_action('wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes'); |
|
1049 | +remove_action('geodir_before_detail_fields', 'geodir_build_coupon', 2); |
|
1050 | 1050 | |
1051 | -function wpinv_wpi_to_gdp_handle_subscription_cancel( $invoice_id, $invoice ) { |
|
1052 | - if ( wpinv_pm_active() && !empty( $invoice ) && $invoice->is_recurring() ) { |
|
1053 | - if ( $invoice->is_renewal() ) { |
|
1051 | +function wpinv_wpi_to_gdp_handle_subscription_cancel($invoice_id, $invoice) { |
|
1052 | + if (wpinv_pm_active() && !empty($invoice) && $invoice->is_recurring()) { |
|
1053 | + if ($invoice->is_renewal()) { |
|
1054 | 1054 | $invoice = $invoice->get_parent_payment(); |
1055 | 1055 | } |
1056 | 1056 | |
1057 | - if ( !empty( $invoice ) ) { |
|
1058 | - wpinv_wpi_to_gdp_update_status( $invoice->ID, 'wpi-cancelled', $invoice->get_status() ); |
|
1057 | + if (!empty($invoice)) { |
|
1058 | + wpinv_wpi_to_gdp_update_status($invoice->ID, 'wpi-cancelled', $invoice->get_status()); |
|
1059 | 1059 | } |
1060 | 1060 | } |
1061 | 1061 | } |
1062 | -add_action( 'wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2 ); |
|
1063 | 1062 | \ No newline at end of file |
1063 | +add_action('wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2); |
|
1064 | 1064 | \ No newline at end of file |