@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly. |
3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | 5 | class WPInv_EUVat { |
6 | 6 | private static $is_ajax = false; |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | private static $instance = false; |
9 | 9 | |
10 | 10 | public static function get_instance() { |
11 | - if ( !self::$instance ) { |
|
11 | + if (!self::$instance) { |
|
12 | 12 | self::$instance = new self(); |
13 | 13 | self::$instance->actions(); |
14 | 14 | } |
@@ -17,132 +17,132 @@ discard block |
||
17 | 17 | } |
18 | 18 | |
19 | 19 | public function __construct() { |
20 | - self::$is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
20 | + self::$is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
21 | 21 | self::$default_country = wpinv_get_default_country(); |
22 | 22 | } |
23 | 23 | |
24 | 24 | public static function actions() { |
25 | - if ( is_admin() ) { |
|
26 | - add_action( 'admin_enqueue_scripts', array( self::$instance, 'enqueue_admin_scripts' ) ); |
|
27 | - add_action( 'wpinv_settings_sections_taxes', array( self::$instance, 'section_vat_settings' ) ); |
|
28 | - add_action( 'wpinv_settings_taxes', array( self::$instance, 'vat_settings' ) ); |
|
29 | - add_filter( 'wpinv_settings_taxes-vat_sanitize', array( self::$instance, 'sanitize_vat_settings' ) ); |
|
30 | - add_filter( 'wpinv_settings_taxes-vat_rates_sanitize', array( self::$instance, 'sanitize_vat_rates' ) ); |
|
31 | - add_action( 'wp_ajax_wpinv_add_vat_class', array( self::$instance, 'add_class' ) ); |
|
32 | - add_action( 'wp_ajax_nopriv_wpinv_add_vat_class', array( self::$instance, 'add_class' ) ); |
|
33 | - add_action( 'wp_ajax_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) ); |
|
34 | - add_action( 'wp_ajax_nopriv_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) ); |
|
35 | - add_action( 'wp_ajax_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) ); |
|
36 | - add_action( 'wp_ajax_nopriv_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) ); |
|
37 | - add_action( 'wp_ajax_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) ); |
|
38 | - add_action( 'wp_ajax_nopriv_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) ); |
|
39 | - } |
|
40 | - |
|
41 | - add_action( 'wp_enqueue_scripts', array( self::$instance, 'enqueue_vat_scripts' ) ); |
|
42 | - add_filter( 'wpinv_default_billing_country', array( self::$instance, 'get_user_country' ), 10 ); |
|
43 | - add_filter( 'wpinv_get_user_country', array( self::$instance, 'set_user_country' ), 10 ); |
|
44 | - add_action( 'wp_ajax_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) ); |
|
45 | - add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) ); |
|
46 | - add_action( 'wp_ajax_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) ); |
|
47 | - add_action( 'wp_ajax_nopriv_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) ); |
|
48 | - add_action( 'wpinv_invoice_print_after_line_items', array( self::$instance, 'show_vat_notice' ), 999, 1 ); |
|
49 | - if ( wpinv_use_taxes() ) { |
|
50 | - add_action( 'wpinv_after_billing_fields', array( self::$instance, 'checkout_vat_fields' ) ); |
|
51 | - if ( self::allow_vat_rules() ) { |
|
52 | - add_action( 'wpinv_checkout_error_checks', array( self::$instance, 'checkout_vat_validate' ), 10, 2 ); |
|
53 | - add_filter( 'wpinv_tax_rate', array( self::$instance, 'get_rate' ), 10, 4 ); |
|
25 | + if (is_admin()) { |
|
26 | + add_action('admin_enqueue_scripts', array(self::$instance, 'enqueue_admin_scripts')); |
|
27 | + add_action('wpinv_settings_sections_taxes', array(self::$instance, 'section_vat_settings')); |
|
28 | + add_action('wpinv_settings_taxes', array(self::$instance, 'vat_settings')); |
|
29 | + add_filter('wpinv_settings_taxes-vat_sanitize', array(self::$instance, 'sanitize_vat_settings')); |
|
30 | + add_filter('wpinv_settings_taxes-vat_rates_sanitize', array(self::$instance, 'sanitize_vat_rates')); |
|
31 | + add_action('wp_ajax_wpinv_add_vat_class', array(self::$instance, 'add_class')); |
|
32 | + add_action('wp_ajax_nopriv_wpinv_add_vat_class', array(self::$instance, 'add_class')); |
|
33 | + add_action('wp_ajax_wpinv_delete_vat_class', array(self::$instance, 'delete_class')); |
|
34 | + add_action('wp_ajax_nopriv_wpinv_delete_vat_class', array(self::$instance, 'delete_class')); |
|
35 | + add_action('wp_ajax_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates')); |
|
36 | + add_action('wp_ajax_nopriv_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates')); |
|
37 | + add_action('wp_ajax_wpinv_geoip2', array(self::$instance, 'geoip2_download_database')); |
|
38 | + add_action('wp_ajax_nopriv_wpinv_geoip2', array(self::$instance, 'geoip2_download_database')); |
|
39 | + } |
|
40 | + |
|
41 | + add_action('wp_enqueue_scripts', array(self::$instance, 'enqueue_vat_scripts')); |
|
42 | + add_filter('wpinv_default_billing_country', array(self::$instance, 'get_user_country'), 10); |
|
43 | + add_filter('wpinv_get_user_country', array(self::$instance, 'set_user_country'), 10); |
|
44 | + add_action('wp_ajax_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate')); |
|
45 | + add_action('wp_ajax_nopriv_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate')); |
|
46 | + add_action('wp_ajax_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset')); |
|
47 | + add_action('wp_ajax_nopriv_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset')); |
|
48 | + add_action('wpinv_invoice_print_after_line_items', array(self::$instance, 'show_vat_notice'), 999, 1); |
|
49 | + if (wpinv_use_taxes()) { |
|
50 | + add_action('wpinv_after_billing_fields', array(self::$instance, 'checkout_vat_fields')); |
|
51 | + if (self::allow_vat_rules()) { |
|
52 | + add_action('wpinv_checkout_error_checks', array(self::$instance, 'checkout_vat_validate'), 10, 2); |
|
53 | + add_filter('wpinv_tax_rate', array(self::$instance, 'get_rate'), 10, 4); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
58 | - public static function get_eu_states( $sort = true ) { |
|
59 | - $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' ); |
|
60 | - if ( $sort ) { |
|
61 | - $sort = sort( $eu_states ); |
|
58 | + public static function get_eu_states($sort = true) { |
|
59 | + $eu_states = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE'); |
|
60 | + if ($sort) { |
|
61 | + $sort = sort($eu_states); |
|
62 | 62 | } |
63 | 63 | |
64 | - return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort ); |
|
64 | + return apply_filters('wpinv_get_eu_states', $eu_states, $sort); |
|
65 | 65 | } |
66 | 66 | |
67 | - public static function get_gst_countries( $sort = true ) { |
|
68 | - $gst_countries = array( 'AU', 'NZ', 'CA', 'CN' ); |
|
67 | + public static function get_gst_countries($sort = true) { |
|
68 | + $gst_countries = array('AU', 'NZ', 'CA', 'CN'); |
|
69 | 69 | |
70 | - if ( $sort ) { |
|
71 | - $sort = sort( $gst_countries ); |
|
70 | + if ($sort) { |
|
71 | + $sort = sort($gst_countries); |
|
72 | 72 | } |
73 | 73 | |
74 | - return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort ); |
|
74 | + return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort); |
|
75 | 75 | } |
76 | 76 | |
77 | - public static function is_eu_state( $country_code ) { |
|
78 | - $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false; |
|
77 | + public static function is_eu_state($country_code) { |
|
78 | + $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false; |
|
79 | 79 | |
80 | - return apply_filters( 'wpinv_is_eu_state', $return, $country_code ); |
|
80 | + return apply_filters('wpinv_is_eu_state', $return, $country_code); |
|
81 | 81 | } |
82 | 82 | |
83 | - public static function is_gst_country( $country_code ) { |
|
84 | - $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false; |
|
83 | + public static function is_gst_country($country_code) { |
|
84 | + $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false; |
|
85 | 85 | |
86 | - return apply_filters( 'wpinv_is_gst_country', $return, $country_code ); |
|
86 | + return apply_filters('wpinv_is_gst_country', $return, $country_code); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | public static function enqueue_vat_scripts() { |
90 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
90 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
91 | 91 | |
92 | - wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
93 | - wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
92 | + wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
93 | + wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
94 | 94 | |
95 | - $vat_name = self::get_vat_name(); |
|
95 | + $vat_name = self::get_vat_name(); |
|
96 | 96 | |
97 | 97 | $vars = array(); |
98 | 98 | $vars['UseTaxes'] = wpinv_use_taxes(); |
99 | 99 | $vars['EUStates'] = self::get_eu_states(); |
100 | - $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' ); |
|
101 | - $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
102 | - $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
103 | - $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name ); |
|
104 | - $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name ); |
|
105 | - $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name ); |
|
106 | - $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name ); |
|
107 | - $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' ); |
|
100 | + $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing'); |
|
101 | + $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing'); |
|
102 | + $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
103 | + $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name); |
|
104 | + $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name); |
|
105 | + $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name); |
|
106 | + $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name); |
|
107 | + $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing'); |
|
108 | 108 | $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false; |
109 | 109 | $vars['HideVatFields'] = $vars['ApplyVATRules'] ? self::hide_vat_fields() : true; |
110 | - $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' ); |
|
111 | - $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' ); |
|
112 | - $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' ); |
|
113 | - $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' ); |
|
114 | - $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' ); |
|
115 | - $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' ); |
|
116 | - $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' ); |
|
117 | - $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' ); |
|
118 | - $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name ); |
|
119 | - $vars['VatReseting'] = __( 'Reseting...', 'invoicing' ); |
|
120 | - $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
121 | - $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
122 | - $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' ); |
|
110 | + $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing'); |
|
111 | + $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing'); |
|
112 | + $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing'); |
|
113 | + $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing'); |
|
114 | + $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing'); |
|
115 | + $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing'); |
|
116 | + $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing'); |
|
117 | + $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing'); |
|
118 | + $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name); |
|
119 | + $vars['VatReseting'] = __('Reseting...', 'invoicing'); |
|
120 | + $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
121 | + $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
122 | + $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing'); |
|
123 | 123 | $vars['isFront'] = is_admin() ? false : true; |
124 | - $vars['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
124 | + $vars['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
125 | 125 | $vars['baseCountry'] = wpinv_get_default_country(); |
126 | - $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false ); |
|
127 | - $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false; |
|
126 | + $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false); |
|
127 | + $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false; |
|
128 | 128 | |
129 | - wp_enqueue_script( 'wpinv-vat-validation-script' ); |
|
130 | - wp_enqueue_script( 'wpinv-vat-script' ); |
|
131 | - wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars ); |
|
129 | + wp_enqueue_script('wpinv-vat-validation-script'); |
|
130 | + wp_enqueue_script('wpinv-vat-script'); |
|
131 | + wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | public static function enqueue_admin_scripts() { |
135 | - if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) { |
|
135 | + if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) { |
|
136 | 136 | self::enqueue_vat_scripts(); |
137 | 137 | } |
138 | 138 | } |
139 | 139 | |
140 | - public static function section_vat_settings( $sections ) { |
|
141 | - if ( !empty( $sections ) ) { |
|
142 | - $sections['vat'] = __( 'EU VAT Settings', 'invoicing' ); |
|
140 | + public static function section_vat_settings($sections) { |
|
141 | + if (!empty($sections)) { |
|
142 | + $sections['vat'] = __('EU VAT Settings', 'invoicing'); |
|
143 | 143 | |
144 | - if ( self::allow_vat_classes() ) { |
|
145 | - $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' ); |
|
144 | + if (self::allow_vat_classes()) { |
|
145 | + $sections['vat_rates'] = __('EU VAT Rates', 'invoicing'); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | return $sections; |
@@ -151,52 +151,52 @@ discard block |
||
151 | 151 | public static function vat_rates_settings() { |
152 | 152 | $vat_classes = self::get_rate_classes(); |
153 | 153 | $vat_rates = array(); |
154 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new'; |
|
155 | - $current_url = remove_query_arg( 'wpi_sub' ); |
|
154 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new'; |
|
155 | + $current_url = remove_query_arg('wpi_sub'); |
|
156 | 156 | |
157 | 157 | $vat_rates['vat_rates_header'] = array( |
158 | 158 | 'id' => 'vat_rates_header', |
159 | - 'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>', |
|
159 | + 'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>', |
|
160 | 160 | 'desc' => '', |
161 | 161 | 'type' => 'header', |
162 | 162 | 'size' => 'regular' |
163 | 163 | ); |
164 | 164 | $vat_rates['vat_rates_class'] = array( |
165 | 165 | 'id' => 'vat_rates_class', |
166 | - 'name' => __( 'Edit VAT Rates', 'invoicing' ), |
|
167 | - 'desc' => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ), |
|
166 | + 'name' => __('Edit VAT Rates', 'invoicing'), |
|
167 | + 'desc' => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'), |
|
168 | 168 | 'type' => 'select', |
169 | - 'options' => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ), |
|
169 | + 'options' => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))), |
|
170 | 170 | 'chosen' => true, |
171 | - 'placeholder' => __( 'Select a VAT Rate', 'invoicing' ), |
|
171 | + 'placeholder' => __('Select a VAT Rate', 'invoicing'), |
|
172 | 172 | 'selected' => $vat_class, |
173 | 173 | 'onchange' => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;', |
174 | 174 | ); |
175 | 175 | |
176 | - if ( $vat_class != '_standard' && $vat_class != '_new' ) { |
|
176 | + if ($vat_class != '_standard' && $vat_class != '_new') { |
|
177 | 177 | $vat_rates['vat_rate_delete'] = array( |
178 | 178 | 'id' => 'vat_rate_delete', |
179 | 179 | 'type' => 'vat_rate_delete', |
180 | 180 | ); |
181 | 181 | } |
182 | 182 | |
183 | - if ( $vat_class == '_new' ) { |
|
183 | + if ($vat_class == '_new') { |
|
184 | 184 | $vat_rates['vat_rates_settings'] = array( |
185 | 185 | 'id' => 'vat_rates_settings', |
186 | - 'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>', |
|
186 | + 'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>', |
|
187 | 187 | 'type' => 'header', |
188 | 188 | ); |
189 | 189 | $vat_rates['vat_rate_name'] = array( |
190 | 190 | 'id' => 'vat_rate_name', |
191 | - 'name' => __( 'Name', 'invoicing' ), |
|
192 | - 'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ), |
|
191 | + 'name' => __('Name', 'invoicing'), |
|
192 | + 'desc' => __('A short name for the new VAT Rate class', 'invoicing'), |
|
193 | 193 | 'type' => 'text', |
194 | 194 | 'size' => 'regular', |
195 | 195 | ); |
196 | 196 | $vat_rates['vat_rate_desc'] = array( |
197 | 197 | 'id' => 'vat_rate_desc', |
198 | - 'name' => __( 'Description', 'invoicing' ), |
|
199 | - 'desc' => __( 'Manage VAT Rate class', 'invoicing' ), |
|
198 | + 'name' => __('Description', 'invoicing'), |
|
199 | + 'desc' => __('Manage VAT Rate class', 'invoicing'), |
|
200 | 200 | 'type' => 'text', |
201 | 201 | 'size' => 'regular', |
202 | 202 | ); |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | $vat_rates['vat_rates'] = array( |
209 | 209 | 'id' => 'vat_rates', |
210 | 210 | 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>', |
211 | - 'desc' => self::get_class_desc( $vat_class ), |
|
211 | + 'desc' => self::get_class_desc($vat_class), |
|
212 | 212 | 'type' => 'vat_rates', |
213 | 213 | ); |
214 | 214 | } |
@@ -216,12 +216,12 @@ discard block |
||
216 | 216 | return $vat_rates; |
217 | 217 | } |
218 | 218 | |
219 | - public static function vat_settings( $settings ) { |
|
220 | - if ( !empty( $settings ) ) { |
|
219 | + public static function vat_settings($settings) { |
|
220 | + if (!empty($settings)) { |
|
221 | 221 | $vat_settings = array(); |
222 | 222 | $vat_settings['vat_company_title'] = array( |
223 | 223 | 'id' => 'vat_company_title', |
224 | - 'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>', |
|
224 | + 'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>', |
|
225 | 225 | 'desc' => '', |
226 | 226 | 'type' => 'header', |
227 | 227 | 'size' => 'regular' |
@@ -229,22 +229,22 @@ discard block |
||
229 | 229 | |
230 | 230 | $vat_settings['vat_company_name'] = array( |
231 | 231 | 'id' => 'vat_company_name', |
232 | - 'name' => __( 'Your Company Name', 'invoicing' ), |
|
233 | - 'desc' => wp_sprintf(__( 'Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
232 | + 'name' => __('Your Company Name', 'invoicing'), |
|
233 | + 'desc' => wp_sprintf(__('Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
234 | 234 | 'type' => 'text', |
235 | 235 | 'size' => 'regular', |
236 | 236 | ); |
237 | 237 | |
238 | 238 | $vat_settings['vat_number'] = array( |
239 | 239 | 'id' => 'vat_number', |
240 | - 'name' => __( 'Your VAT Number', 'invoicing' ), |
|
240 | + 'name' => __('Your VAT Number', 'invoicing'), |
|
241 | 241 | 'type' => 'vat_number', |
242 | 242 | 'size' => 'regular', |
243 | 243 | ); |
244 | 244 | |
245 | 245 | $vat_settings['vat_settings_title'] = array( |
246 | 246 | 'id' => 'vat_settings_title', |
247 | - 'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>', |
|
247 | + 'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>', |
|
248 | 248 | 'desc' => '', |
249 | 249 | 'type' => 'header', |
250 | 250 | 'size' => 'regular' |
@@ -252,8 +252,8 @@ discard block |
||
252 | 252 | |
253 | 253 | $vat_settings['apply_vat_rules'] = array( |
254 | 254 | 'id' => 'apply_vat_rules', |
255 | - 'name' => __( 'Enable VAT Rules', 'invoicing' ), |
|
256 | - 'desc' => __( 'Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable unless you know what you are doing.', 'invoicing' ) . '</font>', |
|
255 | + 'name' => __('Enable VAT Rules', 'invoicing'), |
|
256 | + 'desc' => __('Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable unless you know what you are doing.', 'invoicing') . '</font>', |
|
257 | 257 | 'type' => 'checkbox', |
258 | 258 | 'std' => '1' |
259 | 259 | ); |
@@ -269,8 +269,8 @@ discard block |
||
269 | 269 | |
270 | 270 | $vat_settings['vat_prevent_b2c_purchase'] = array( |
271 | 271 | 'id' => 'vat_prevent_b2c_purchase', |
272 | - 'name' => __( 'Prevent EU B2C Sales', 'invoicing' ), |
|
273 | - 'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ), |
|
272 | + 'name' => __('Prevent EU B2C Sales', 'invoicing'), |
|
273 | + 'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'), |
|
274 | 274 | 'type' => 'checkbox' |
275 | 275 | ); |
276 | 276 | |
@@ -278,21 +278,21 @@ discard block |
||
278 | 278 | |
279 | 279 | $vat_settings['vat_same_country_rule'] = array( |
280 | 280 | 'id' => 'vat_same_country_rule', |
281 | - 'name' => __( 'Same Country Rule', 'invoicing' ), |
|
282 | - 'desc' => __( 'Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing' ), |
|
281 | + 'name' => __('Same Country Rule', 'invoicing'), |
|
282 | + 'desc' => __('Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing'), |
|
283 | 283 | 'type' => 'select', |
284 | 284 | 'options' => array( |
285 | - '' => __( 'Normal', 'invoicing' ), |
|
286 | - 'no' => __( 'No VAT', 'invoicing' ), |
|
287 | - 'always' => __( 'Always apply VAT', 'invoicing' ), |
|
285 | + '' => __('Normal', 'invoicing'), |
|
286 | + 'no' => __('No VAT', 'invoicing'), |
|
287 | + 'always' => __('Always apply VAT', 'invoicing'), |
|
288 | 288 | ), |
289 | - 'placeholder' => __( 'Select an option', 'invoicing' ), |
|
289 | + 'placeholder' => __('Select an option', 'invoicing'), |
|
290 | 290 | 'std' => '' |
291 | 291 | ); |
292 | 292 | |
293 | 293 | $vat_settings['vat_checkout_title'] = array( |
294 | 294 | 'id' => 'vat_checkout_title', |
295 | - 'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>', |
|
295 | + 'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>', |
|
296 | 296 | 'desc' => '', |
297 | 297 | 'type' => 'header', |
298 | 298 | 'size' => 'regular' |
@@ -300,14 +300,14 @@ discard block |
||
300 | 300 | |
301 | 301 | $vat_settings['vat_disable_fields'] = array( |
302 | 302 | 'id' => 'vat_disable_fields', |
303 | - 'name' => __( 'Disable VAT Fields', 'invoicing' ), |
|
304 | - 'desc' => __( 'Disable VAT fields if Invoicing is being used for GST.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing' ) . '</font>', |
|
303 | + 'name' => __('Disable VAT Fields', 'invoicing'), |
|
304 | + 'desc' => __('Disable VAT fields if Invoicing is being used for GST.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing') . '</font>', |
|
305 | 305 | 'type' => 'checkbox' |
306 | 306 | ); |
307 | 307 | |
308 | 308 | $vat_settings['vat_ip_lookup'] = array( |
309 | 309 | 'id' => 'vat_ip_lookup', |
310 | - 'name' => __( 'IP Country Look-up', 'invoicing' ), |
|
310 | + 'name' => __('IP Country Look-up', 'invoicing'), |
|
311 | 311 | 'type' => 'vat_ip_lookup', |
312 | 312 | 'size' => 'regular', |
313 | 313 | 'std' => 'default' |
@@ -315,21 +315,21 @@ discard block |
||
315 | 315 | |
316 | 316 | $vat_settings['hide_ip_address'] = array( |
317 | 317 | 'id' => 'hide_ip_address', |
318 | - 'name' => __( 'Hide IP Info at Checkout', 'invoicing' ), |
|
319 | - 'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ), |
|
318 | + 'name' => __('Hide IP Info at Checkout', 'invoicing'), |
|
319 | + 'desc' => __('Hide the user IP info at checkout.', 'invoicing'), |
|
320 | 320 | 'type' => 'checkbox' |
321 | 321 | ); |
322 | 322 | |
323 | 323 | $vat_settings['vat_ip_country_default'] = array( |
324 | 324 | 'id' => 'vat_ip_country_default', |
325 | - 'name' => __( 'Enable IP Country as Default', 'invoicing' ), |
|
326 | - 'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ), |
|
325 | + 'name' => __('Enable IP Country as Default', 'invoicing'), |
|
326 | + 'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'), |
|
327 | 327 | 'type' => 'checkbox' |
328 | 328 | ); |
329 | 329 | |
330 | 330 | $vat_settings['vies_validation_title'] = array( |
331 | 331 | 'id' => 'vies_validation_title', |
332 | - 'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>', |
|
332 | + 'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>', |
|
333 | 333 | 'desc' => '', |
334 | 334 | 'type' => 'header', |
335 | 335 | 'size' => 'regular' |
@@ -337,37 +337,37 @@ discard block |
||
337 | 337 | |
338 | 338 | $vat_settings['vat_vies_check'] = array( |
339 | 339 | 'id' => 'vat_vies_check', |
340 | - 'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ), |
|
341 | - 'desc' => wp_sprintf( __( 'Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
340 | + 'name' => __('Disable VIES VAT ID Check', 'invoicing'), |
|
341 | + 'desc' => wp_sprintf(__('Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
342 | 342 | 'type' => 'checkbox' |
343 | 343 | ); |
344 | 344 | |
345 | 345 | $vat_settings['vat_disable_company_name_check'] = array( |
346 | 346 | 'id' => 'vat_disable_company_name_check', |
347 | - 'name' => __( 'Disable VIES Name Check', 'invoicing' ), |
|
348 | - 'desc' => wp_sprintf( __( 'Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
347 | + 'name' => __('Disable VIES Name Check', 'invoicing'), |
|
348 | + 'desc' => wp_sprintf(__('Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
349 | 349 | 'type' => 'checkbox' |
350 | 350 | ); |
351 | 351 | |
352 | 352 | $vat_settings['vat_offline_check'] = array( |
353 | 353 | 'id' => 'vat_offline_check', |
354 | - 'name' => __( 'Disable Basic Checks', 'invoicing' ), |
|
355 | - 'desc' => __( 'This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing' ), |
|
354 | + 'name' => __('Disable Basic Checks', 'invoicing'), |
|
355 | + 'desc' => __('This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing'), |
|
356 | 356 | 'type' => 'checkbox' |
357 | 357 | ); |
358 | 358 | |
359 | 359 | |
360 | 360 | $settings['vat'] = $vat_settings; |
361 | 361 | |
362 | - if ( self::allow_vat_classes() ) { |
|
362 | + if (self::allow_vat_classes()) { |
|
363 | 363 | $settings['vat_rates'] = self::vat_rates_settings(); |
364 | 364 | } |
365 | 365 | |
366 | 366 | $eu_fallback_rate = array( |
367 | 367 | 'id' => 'eu_fallback_rate', |
368 | - 'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>', |
|
368 | + 'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>', |
|
369 | 369 | 'type' => 'eu_fallback_rate', |
370 | - 'desc' => __( 'Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing' ), |
|
370 | + 'desc' => __('Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing'), |
|
371 | 371 | 'std' => '20', |
372 | 372 | 'size' => 'small' |
373 | 373 | ); |
@@ -383,11 +383,11 @@ discard block |
||
383 | 383 | $database_url = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/'; |
384 | 384 | $destination_dir = $upload_dir['basedir'] . '/invoicing'; |
385 | 385 | |
386 | - if ( !is_dir( $destination_dir ) ) { |
|
387 | - mkdir( $destination_dir ); |
|
386 | + if (!is_dir($destination_dir)) { |
|
387 | + mkdir($destination_dir); |
|
388 | 388 | } |
389 | 389 | |
390 | - $database_files = array( |
|
390 | + $database_files = array( |
|
391 | 391 | 'country' => array( |
392 | 392 | 'source' => $database_url . 'GeoLite2-Country.mmdb.gz', |
393 | 393 | 'destination' => $destination_dir . '/GeoLite2-Country.mmdb', |
@@ -398,57 +398,57 @@ discard block |
||
398 | 398 | ) |
399 | 399 | ); |
400 | 400 | |
401 | - foreach( $database_files as $database => $files ) { |
|
402 | - $result = self::geoip2_download_file( $files['source'], $files['destination'] ); |
|
401 | + foreach ($database_files as $database => $files) { |
|
402 | + $result = self::geoip2_download_file($files['source'], $files['destination']); |
|
403 | 403 | |
404 | - if ( empty( $result['success'] ) ) { |
|
404 | + if (empty($result['success'])) { |
|
405 | 405 | echo $result['message']; |
406 | 406 | exit; |
407 | 407 | } |
408 | 408 | |
409 | - wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) ); |
|
410 | - echo sprintf(__( 'GeoIp2 %s database updated successfully.', 'invoicing' ), $database ) . ' '; |
|
409 | + wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp')); |
|
410 | + echo sprintf(__('GeoIp2 %s database updated successfully.', 'invoicing'), $database) . ' '; |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | exit; |
414 | 414 | } |
415 | 415 | |
416 | - public static function geoip2_download_file( $source_url, $destination_file ) { |
|
416 | + public static function geoip2_download_file($source_url, $destination_file) { |
|
417 | 417 | $success = false; |
418 | 418 | $message = ''; |
419 | 419 | |
420 | - if ( !function_exists( 'download_url' ) ) { |
|
421 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
420 | + if (!function_exists('download_url')) { |
|
421 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
422 | 422 | } |
423 | 423 | |
424 | - $temp_file = download_url( $source_url ); |
|
424 | + $temp_file = download_url($source_url); |
|
425 | 425 | |
426 | - if ( is_wp_error( $temp_file ) ) { |
|
427 | - $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() ); |
|
426 | + if (is_wp_error($temp_file)) { |
|
427 | + $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message()); |
|
428 | 428 | } else { |
429 | - $handle = gzopen( $temp_file, 'rb' ); |
|
429 | + $handle = gzopen($temp_file, 'rb'); |
|
430 | 430 | |
431 | - if ( $handle ) { |
|
432 | - $fopen = fopen( $destination_file, 'wb' ); |
|
433 | - if ( $fopen ) { |
|
434 | - while ( ( $data = gzread( $handle, 4096 ) ) != false ) { |
|
435 | - fwrite( $fopen, $data ); |
|
431 | + if ($handle) { |
|
432 | + $fopen = fopen($destination_file, 'wb'); |
|
433 | + if ($fopen) { |
|
434 | + while (($data = gzread($handle, 4096)) != false) { |
|
435 | + fwrite($fopen, $data); |
|
436 | 436 | } |
437 | 437 | |
438 | - gzclose( $handle ); |
|
439 | - fclose( $fopen ); |
|
438 | + gzclose($handle); |
|
439 | + fclose($fopen); |
|
440 | 440 | |
441 | 441 | $success = true; |
442 | 442 | } else { |
443 | - gzclose( $handle ); |
|
444 | - $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file ); |
|
443 | + gzclose($handle); |
|
444 | + $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file); |
|
445 | 445 | } |
446 | 446 | } else { |
447 | - $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file ); |
|
447 | + $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file); |
|
448 | 448 | } |
449 | 449 | |
450 | - if ( file_exists( $temp_file ) ) { |
|
451 | - unlink( $temp_file ); |
|
450 | + if (file_exists($temp_file)) { |
|
451 | + unlink($temp_file); |
|
452 | 452 | } |
453 | 453 | } |
454 | 454 | |
@@ -460,11 +460,11 @@ discard block |
||
460 | 460 | } |
461 | 461 | |
462 | 462 | public static function load_geoip2() { |
463 | - if ( defined( 'WPINV_GEOIP2_LODDED' ) ) { |
|
463 | + if (defined('WPINV_GEOIP2_LODDED')) { |
|
464 | 464 | return; |
465 | 465 | } |
466 | 466 | |
467 | - if ( !class_exists( '\MaxMind\Db\Reader' ) ) { |
|
467 | + if (!class_exists('\MaxMind\Db\Reader')) { |
|
468 | 468 | $maxmind_db_files = array( |
469 | 469 | 'Reader/Decoder.php', |
470 | 470 | 'Reader/InvalidDatabaseException.php', |
@@ -473,12 +473,12 @@ discard block |
||
473 | 473 | 'Reader.php', |
474 | 474 | ); |
475 | 475 | |
476 | - foreach ( $maxmind_db_files as $key => $file ) { |
|
477 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file ); |
|
476 | + foreach ($maxmind_db_files as $key => $file) { |
|
477 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file); |
|
478 | 478 | } |
479 | 479 | } |
480 | 480 | |
481 | - if ( !class_exists( '\GeoIp2\Database\Reader' ) ) { |
|
481 | + if (!class_exists('\GeoIp2\Database\Reader')) { |
|
482 | 482 | $geoip2_files = array( |
483 | 483 | 'ProviderInterface.php', |
484 | 484 | 'Compat/JsonSerializable.php', |
@@ -512,23 +512,23 @@ discard block |
||
512 | 512 | 'WebService/Client.php', |
513 | 513 | ); |
514 | 514 | |
515 | - foreach ( $geoip2_files as $key => $file ) { |
|
516 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file ); |
|
515 | + foreach ($geoip2_files as $key => $file) { |
|
516 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file); |
|
517 | 517 | } |
518 | 518 | } |
519 | 519 | |
520 | - define( 'WPINV_GEOIP2_LODDED', true ); |
|
520 | + define('WPINV_GEOIP2_LODDED', true); |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | public static function geoip2_country_dbfile() { |
524 | 524 | $upload_dir = wp_upload_dir(); |
525 | 525 | |
526 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
526 | + if (!isset($upload_dir['basedir'])) { |
|
527 | 527 | return false; |
528 | 528 | } |
529 | 529 | |
530 | 530 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb'; |
531 | - if ( !file_exists( $filename ) ) { |
|
531 | + if (!file_exists($filename)) { |
|
532 | 532 | return false; |
533 | 533 | } |
534 | 534 | |
@@ -538,12 +538,12 @@ discard block |
||
538 | 538 | public static function geoip2_city_dbfile() { |
539 | 539 | $upload_dir = wp_upload_dir(); |
540 | 540 | |
541 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
541 | + if (!isset($upload_dir['basedir'])) { |
|
542 | 542 | return false; |
543 | 543 | } |
544 | 544 | |
545 | 545 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb'; |
546 | - if ( !file_exists( $filename ) ) { |
|
546 | + if (!file_exists($filename)) { |
|
547 | 547 | return false; |
548 | 548 | } |
549 | 549 | |
@@ -554,10 +554,10 @@ discard block |
||
554 | 554 | try { |
555 | 555 | self::load_geoip2(); |
556 | 556 | |
557 | - if ( $filename = self::geoip2_country_dbfile() ) { |
|
558 | - return new \GeoIp2\Database\Reader( $filename ); |
|
557 | + if ($filename = self::geoip2_country_dbfile()) { |
|
558 | + return new \GeoIp2\Database\Reader($filename); |
|
559 | 559 | } |
560 | - } catch( Exception $e ) { |
|
560 | + } catch (Exception $e) { |
|
561 | 561 | return false; |
562 | 562 | } |
563 | 563 | |
@@ -568,173 +568,173 @@ discard block |
||
568 | 568 | try { |
569 | 569 | self::load_geoip2(); |
570 | 570 | |
571 | - if ( $filename = self::geoip2_city_dbfile() ) { |
|
572 | - return new \GeoIp2\Database\Reader( $filename ); |
|
571 | + if ($filename = self::geoip2_city_dbfile()) { |
|
572 | + return new \GeoIp2\Database\Reader($filename); |
|
573 | 573 | } |
574 | - } catch( Exception $e ) { |
|
574 | + } catch (Exception $e) { |
|
575 | 575 | return false; |
576 | 576 | } |
577 | 577 | |
578 | 578 | return false; |
579 | 579 | } |
580 | 580 | |
581 | - public static function geoip2_country_record( $ip_address ) { |
|
581 | + public static function geoip2_country_record($ip_address) { |
|
582 | 582 | try { |
583 | 583 | $reader = self::geoip2_country_reader(); |
584 | 584 | |
585 | - if ( $reader ) { |
|
586 | - $record = $reader->country( $ip_address ); |
|
585 | + if ($reader) { |
|
586 | + $record = $reader->country($ip_address); |
|
587 | 587 | |
588 | - if ( !empty( $record->country->isoCode ) ) { |
|
588 | + if (!empty($record->country->isoCode)) { |
|
589 | 589 | return $record; |
590 | 590 | } |
591 | 591 | } |
592 | - } catch(\InvalidArgumentException $e) { |
|
593 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
592 | + } catch (\InvalidArgumentException $e) { |
|
593 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
594 | 594 | |
595 | 595 | return false; |
596 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
597 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
596 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
597 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
598 | 598 | |
599 | 599 | return false; |
600 | - } catch( Exception $e ) { |
|
600 | + } catch (Exception $e) { |
|
601 | 601 | return false; |
602 | 602 | } |
603 | 603 | |
604 | 604 | return false; |
605 | 605 | } |
606 | 606 | |
607 | - public static function geoip2_city_record( $ip_address ) { |
|
607 | + public static function geoip2_city_record($ip_address) { |
|
608 | 608 | try { |
609 | 609 | $reader = self::geoip2_city_reader(); |
610 | 610 | |
611 | - if ( $reader ) { |
|
612 | - $record = $reader->city( $ip_address ); |
|
611 | + if ($reader) { |
|
612 | + $record = $reader->city($ip_address); |
|
613 | 613 | |
614 | - if ( !empty( $record->country->isoCode ) ) { |
|
614 | + if (!empty($record->country->isoCode)) { |
|
615 | 615 | return $record; |
616 | 616 | } |
617 | 617 | } |
618 | - } catch(\InvalidArgumentException $e) { |
|
619 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
618 | + } catch (\InvalidArgumentException $e) { |
|
619 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
620 | 620 | |
621 | 621 | return false; |
622 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
623 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
622 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
623 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
624 | 624 | |
625 | 625 | return false; |
626 | - } catch( Exception $e ) { |
|
626 | + } catch (Exception $e) { |
|
627 | 627 | return false; |
628 | 628 | } |
629 | 629 | |
630 | 630 | return false; |
631 | 631 | } |
632 | 632 | |
633 | - public static function geoip2_country_code( $ip_address ) { |
|
634 | - $record = self::geoip2_country_record( $ip_address ); |
|
635 | - return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country(); |
|
633 | + public static function geoip2_country_code($ip_address) { |
|
634 | + $record = self::geoip2_country_record($ip_address); |
|
635 | + return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country(); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | // Find country by IP address. |
639 | - public static function get_country_by_ip( $ip = '' ) { |
|
639 | + public static function get_country_by_ip($ip = '') { |
|
640 | 640 | global $wpinv_ip_address_country; |
641 | 641 | |
642 | - if ( !empty( $wpinv_ip_address_country ) ) { |
|
642 | + if (!empty($wpinv_ip_address_country)) { |
|
643 | 643 | return $wpinv_ip_address_country; |
644 | 644 | } |
645 | 645 | |
646 | - if ( empty( $ip ) ) { |
|
646 | + if (empty($ip)) { |
|
647 | 647 | $ip = wpinv_get_ip(); |
648 | 648 | } |
649 | 649 | |
650 | - $ip_country_service = wpinv_get_option( 'vat_ip_lookup' ); |
|
651 | - $is_default = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false; |
|
650 | + $ip_country_service = wpinv_get_option('vat_ip_lookup'); |
|
651 | + $is_default = empty($ip_country_service) || $ip_country_service === 'default' ? true : false; |
|
652 | 652 | |
653 | - if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country. |
|
654 | - if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) { |
|
653 | + if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country. |
|
654 | + if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) { |
|
655 | 655 | try { |
656 | - $wpinv_ip_address_country = geoip_country_code_by_name( $ip ); |
|
657 | - } catch( Exception $e ) { |
|
658 | - wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' ); |
|
656 | + $wpinv_ip_address_country = geoip_country_code_by_name($ip); |
|
657 | + } catch (Exception $e) { |
|
658 | + wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )'); |
|
659 | 659 | } |
660 | - } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) { |
|
661 | - $wpinv_ip_address_country = self::geoip2_country_code( $ip ); |
|
662 | - } else if ( function_exists( 'simplexml_load_file' ) && ( $ip_country_service === 'geoplugin' || $is_default ) ) { |
|
663 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
660 | + } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) { |
|
661 | + $wpinv_ip_address_country = self::geoip2_country_code($ip); |
|
662 | + } else if (function_exists('simplexml_load_file') && ($ip_country_service === 'geoplugin' || $is_default)) { |
|
663 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
664 | 664 | |
665 | - if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) { |
|
665 | + if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) { |
|
666 | 666 | $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode; |
667 | 667 | } |
668 | 668 | } |
669 | 669 | } |
670 | 670 | |
671 | - if ( empty( $wpinv_ip_address_country ) ) { |
|
671 | + if (empty($wpinv_ip_address_country)) { |
|
672 | 672 | $wpinv_ip_address_country = wpinv_get_default_country(); |
673 | 673 | } |
674 | 674 | |
675 | 675 | return $wpinv_ip_address_country; |
676 | 676 | } |
677 | 677 | |
678 | - public static function sanitize_vat_settings( $input ) { |
|
678 | + public static function sanitize_vat_settings($input) { |
|
679 | 679 | global $wpinv_options; |
680 | 680 | |
681 | 681 | $valid = false; |
682 | 682 | $message = ''; |
683 | 683 | |
684 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
685 | - if ( empty( $wpinv_options['vat_offline_check'] ) ) { |
|
686 | - $valid = self::offline_check( $input['vat_number'] ); |
|
684 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
685 | + if (empty($wpinv_options['vat_offline_check'])) { |
|
686 | + $valid = self::offline_check($input['vat_number']); |
|
687 | 687 | } else { |
688 | 688 | $valid = true; |
689 | 689 | } |
690 | 690 | |
691 | - $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' ); |
|
691 | + $message = $valid ? '' : __('VAT number not validated', 'invoicing'); |
|
692 | 692 | } else { |
693 | - $result = self::check_vat( $input['vat_number'] ); |
|
693 | + $result = self::check_vat($input['vat_number']); |
|
694 | 694 | |
695 | - if ( empty( $result['valid'] ) ) { |
|
695 | + if (empty($result['valid'])) { |
|
696 | 696 | $valid = false; |
697 | 697 | $message = $result['message']; |
698 | 698 | } else { |
699 | - $valid = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] ); |
|
700 | - $message = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' ); |
|
699 | + $valid = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']); |
|
700 | + $message = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing'); |
|
701 | 701 | } |
702 | 702 | } |
703 | 703 | |
704 | - if ( $message && self::is_vat_validated() != $valid ) { |
|
705 | - add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) ); |
|
704 | + if ($message && self::is_vat_validated() != $valid) { |
|
705 | + add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error')); |
|
706 | 706 | } |
707 | 707 | |
708 | 708 | $input['vat_valid'] = $valid; |
709 | 709 | return $input; |
710 | 710 | } |
711 | 711 | |
712 | - public static function sanitize_vat_rates( $input ) { |
|
713 | - if( !current_user_can( 'manage_options' ) ) { |
|
714 | - add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' ); |
|
712 | + public static function sanitize_vat_rates($input) { |
|
713 | + if (!current_user_can('manage_options')) { |
|
714 | + add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error'); |
|
715 | 715 | return $input; |
716 | 716 | } |
717 | 717 | |
718 | 718 | $vat_classes = self::get_rate_classes(); |
719 | - $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : ''; |
|
719 | + $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : ''; |
|
720 | 720 | |
721 | - if ( empty( $vat_class ) ) { |
|
722 | - add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' ); |
|
721 | + if (empty($vat_class)) { |
|
722 | + add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error'); |
|
723 | 723 | |
724 | 724 | return $input; |
725 | 725 | } |
726 | 726 | |
727 | - $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array(); |
|
727 | + $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array(); |
|
728 | 728 | |
729 | - if ( $vat_class === '_standard' ) { |
|
729 | + if ($vat_class === '_standard') { |
|
730 | 730 | // Save the active rates in the invoice settings |
731 | - update_option( 'wpinv_tax_rates', $new_rates ); |
|
731 | + update_option('wpinv_tax_rates', $new_rates); |
|
732 | 732 | } else { |
733 | 733 | // Get the existing set of rates |
734 | 734 | $rates = self::get_non_standard_rates(); |
735 | 735 | $rates[$vat_class] = $new_rates; |
736 | 736 | |
737 | - update_option( 'wpinv_vat_rates', $rates ); |
|
737 | + update_option('wpinv_vat_rates', $rates); |
|
738 | 738 | } |
739 | 739 | |
740 | 740 | return $input; |
@@ -744,71 +744,71 @@ discard block |
||
744 | 744 | $response = array(); |
745 | 745 | $response['success'] = false; |
746 | 746 | |
747 | - if ( !current_user_can( 'manage_options' ) ) { |
|
748 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
749 | - wp_send_json( $response ); |
|
747 | + if (!current_user_can('manage_options')) { |
|
748 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
749 | + wp_send_json($response); |
|
750 | 750 | } |
751 | 751 | |
752 | - $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false; |
|
753 | - $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false; |
|
752 | + $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false; |
|
753 | + $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false; |
|
754 | 754 | |
755 | - if ( empty( $vat_class_name ) ) { |
|
756 | - $response['error'] = __( 'Select the VAT rate name', 'invoicing' ); |
|
757 | - wp_send_json( $response ); |
|
755 | + if (empty($vat_class_name)) { |
|
756 | + $response['error'] = __('Select the VAT rate name', 'invoicing'); |
|
757 | + wp_send_json($response); |
|
758 | 758 | } |
759 | 759 | |
760 | 760 | $vat_classes = (array)self::get_rate_classes(); |
761 | 761 | |
762 | - if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) { |
|
763 | - $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name ); |
|
764 | - wp_send_json( $response ); |
|
762 | + if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) { |
|
763 | + $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name); |
|
764 | + wp_send_json($response); |
|
765 | 765 | } |
766 | 766 | |
767 | - $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name ); |
|
768 | - $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) ); |
|
767 | + $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name); |
|
768 | + $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key)); |
|
769 | 769 | |
770 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
771 | - $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc ); |
|
770 | + $vat_classes = (array)self::get_rate_classes(true); |
|
771 | + $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc); |
|
772 | 772 | |
773 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
773 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
774 | 774 | |
775 | 775 | $response['success'] = true; |
776 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key ); |
|
776 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key); |
|
777 | 777 | |
778 | - wp_send_json( $response ); |
|
778 | + wp_send_json($response); |
|
779 | 779 | } |
780 | 780 | |
781 | 781 | public static function delete_class() { |
782 | 782 | $response = array(); |
783 | 783 | $response['success'] = false; |
784 | 784 | |
785 | - if ( !current_user_can( 'manage_options' ) || !isset( $_POST['class'] ) ) { |
|
786 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
787 | - wp_send_json( $response ); |
|
785 | + if (!current_user_can('manage_options') || !isset($_POST['class'])) { |
|
786 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
787 | + wp_send_json($response); |
|
788 | 788 | } |
789 | 789 | |
790 | - $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false; |
|
790 | + $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false; |
|
791 | 791 | $vat_classes = (array)self::get_rate_classes(); |
792 | 792 | |
793 | - if ( !isset( $vat_classes[$vat_class] ) ) { |
|
794 | - $response['error'] = __( 'Requested class does not exists', 'invoicing' ); |
|
795 | - wp_send_json( $response ); |
|
793 | + if (!isset($vat_classes[$vat_class])) { |
|
794 | + $response['error'] = __('Requested class does not exists', 'invoicing'); |
|
795 | + wp_send_json($response); |
|
796 | 796 | } |
797 | 797 | |
798 | - if ( $vat_class == '_new' || $vat_class == '_standard' ) { |
|
799 | - $response['error'] = __( 'You can not delete standard rates class', 'invoicing' ); |
|
800 | - wp_send_json( $response ); |
|
798 | + if ($vat_class == '_new' || $vat_class == '_standard') { |
|
799 | + $response['error'] = __('You can not delete standard rates class', 'invoicing'); |
|
800 | + wp_send_json($response); |
|
801 | 801 | } |
802 | 802 | |
803 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
804 | - unset( $vat_classes[$vat_class] ); |
|
803 | + $vat_classes = (array)self::get_rate_classes(true); |
|
804 | + unset($vat_classes[$vat_class]); |
|
805 | 805 | |
806 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
806 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
807 | 807 | |
808 | 808 | $response['success'] = true; |
809 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new' ); |
|
809 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new'); |
|
810 | 810 | |
811 | - wp_send_json( $response ); |
|
811 | + wp_send_json($response); |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | public static function update_eu_rates() { |
@@ -817,72 +817,72 @@ discard block |
||
817 | 817 | $response['error'] = null; |
818 | 818 | $response['data'] = null; |
819 | 819 | |
820 | - if ( !current_user_can( 'manage_options' ) ) { |
|
821 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
822 | - wp_send_json( $response ); |
|
820 | + if (!current_user_can('manage_options')) { |
|
821 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
822 | + wp_send_json($response); |
|
823 | 823 | } |
824 | 824 | |
825 | - $group = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : ''; |
|
826 | - $euvatrates = self::request_euvatrates( $group ); |
|
825 | + $group = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : ''; |
|
826 | + $euvatrates = self::request_euvatrates($group); |
|
827 | 827 | |
828 | - if ( !empty( $euvatrates ) ) { |
|
829 | - if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) { |
|
828 | + if (!empty($euvatrates)) { |
|
829 | + if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) { |
|
830 | 830 | $response['success'] = true; |
831 | 831 | $response['data']['rates'] = $euvatrates['rates']; |
832 | - } else if ( !empty( $euvatrates['error'] ) ) { |
|
832 | + } else if (!empty($euvatrates['error'])) { |
|
833 | 833 | $response['error'] = $euvatrates['error']; |
834 | 834 | } |
835 | 835 | } |
836 | 836 | |
837 | - wp_send_json( $response ); |
|
837 | + wp_send_json($response); |
|
838 | 838 | } |
839 | 839 | |
840 | 840 | public static function hide_vat_fields() { |
841 | - $hide = wpinv_get_option( 'vat_disable_fields' ); |
|
841 | + $hide = wpinv_get_option('vat_disable_fields'); |
|
842 | 842 | |
843 | - return apply_filters( 'wpinv_hide_vat_fields', $hide ); |
|
843 | + return apply_filters('wpinv_hide_vat_fields', $hide); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | public static function same_country_rule() { |
847 | - $same_country_rule = wpinv_get_option( 'vat_same_country_rule' ); |
|
847 | + $same_country_rule = wpinv_get_option('vat_same_country_rule'); |
|
848 | 848 | |
849 | - return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule ); |
|
849 | + return apply_filters('wpinv_vat_same_country_rule', $same_country_rule); |
|
850 | 850 | } |
851 | 851 | |
852 | 852 | public static function get_vat_name() { |
853 | - $vat_name = wpinv_get_option( 'vat_name' ); |
|
854 | - $vat_name = !empty( $vat_name ) ? $vat_name : 'VAT'; |
|
853 | + $vat_name = wpinv_get_option('vat_name'); |
|
854 | + $vat_name = !empty($vat_name) ? $vat_name : 'VAT'; |
|
855 | 855 | |
856 | - return apply_filters( 'wpinv_get_owner_vat_name', $vat_name ); |
|
856 | + return apply_filters('wpinv_get_owner_vat_name', $vat_name); |
|
857 | 857 | } |
858 | 858 | |
859 | 859 | public static function get_company_name() { |
860 | - $company_name = wpinv_get_option( 'vat_company_name' ); |
|
860 | + $company_name = wpinv_get_option('vat_company_name'); |
|
861 | 861 | |
862 | - return apply_filters( 'wpinv_get_owner_company_name', $company_name ); |
|
862 | + return apply_filters('wpinv_get_owner_company_name', $company_name); |
|
863 | 863 | } |
864 | 864 | |
865 | 865 | public static function get_vat_number() { |
866 | - $vat_number = wpinv_get_option( 'vat_number' ); |
|
866 | + $vat_number = wpinv_get_option('vat_number'); |
|
867 | 867 | |
868 | - return apply_filters( 'wpinv_get_owner_vat_number', $vat_number ); |
|
868 | + return apply_filters('wpinv_get_owner_vat_number', $vat_number); |
|
869 | 869 | } |
870 | 870 | |
871 | 871 | public static function is_vat_validated() { |
872 | - $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' ); |
|
872 | + $validated = self::get_vat_number() && wpinv_get_option('vat_valid'); |
|
873 | 873 | |
874 | - return apply_filters( 'wpinv_is_owner_vat_validated', $validated ); |
|
874 | + return apply_filters('wpinv_is_owner_vat_validated', $validated); |
|
875 | 875 | } |
876 | 876 | |
877 | - public static function sanitize_vat( $vat_number, $country_code = '' ) { |
|
878 | - $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) ); |
|
877 | + public static function sanitize_vat($vat_number, $country_code = '') { |
|
878 | + $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number))); |
|
879 | 879 | |
880 | - if ( empty( $country_code ) ) { |
|
881 | - $country_code = substr( $vat_number, 0, 2 ); |
|
880 | + if (empty($country_code)) { |
|
881 | + $country_code = substr($vat_number, 0, 2); |
|
882 | 882 | } |
883 | 883 | |
884 | - if ( strpos( $vat_number , $country_code ) === 0 ) { |
|
885 | - $vat = str_replace( $country_code, '', $vat_number ); |
|
884 | + if (strpos($vat_number, $country_code) === 0) { |
|
885 | + $vat = str_replace($country_code, '', $vat_number); |
|
886 | 886 | } else { |
887 | 887 | $vat = $country_code . $vat_number; |
888 | 888 | } |
@@ -895,140 +895,140 @@ discard block |
||
895 | 895 | return $return; |
896 | 896 | } |
897 | 897 | |
898 | - public static function offline_check( $vat_number, $country_code = '', $formatted = false ) { |
|
899 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
898 | + public static function offline_check($vat_number, $country_code = '', $formatted = false) { |
|
899 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
900 | 900 | $vat_number = $vat['vat_number']; |
901 | 901 | $country_code = $vat['iso']; |
902 | 902 | $regex = array(); |
903 | 903 | |
904 | - switch ( $country_code ) { |
|
904 | + switch ($country_code) { |
|
905 | 905 | case 'AT': |
906 | - $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
906 | + $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
907 | 907 | break; |
908 | 908 | case 'BE': |
909 | - $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
909 | + $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
910 | 910 | break; |
911 | 911 | case 'BG': |
912 | - $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
912 | + $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
913 | 913 | break; |
914 | 914 | case 'CH': |
915 | 915 | case 'CHE': |
916 | - $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
916 | + $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
917 | 917 | break; |
918 | 918 | case 'CY': |
919 | - $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
919 | + $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
920 | 920 | break; |
921 | 921 | case 'CZ': |
922 | - $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
922 | + $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
923 | 923 | break; |
924 | 924 | case 'DE': |
925 | - $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
925 | + $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
926 | 926 | break; |
927 | 927 | case 'DK': |
928 | - $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
928 | + $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
929 | 929 | break; |
930 | 930 | case 'EE': |
931 | - $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
931 | + $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
932 | 932 | break; |
933 | 933 | case 'EL': |
934 | - $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
934 | + $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
935 | 935 | break; |
936 | 936 | case 'ES': |
937 | - $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
938 | - $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
939 | - $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
940 | - $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
937 | + $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
938 | + $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
939 | + $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
940 | + $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
941 | 941 | break; |
942 | 942 | case 'EU': |
943 | - $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
943 | + $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
944 | 944 | break; |
945 | 945 | case 'FI': |
946 | - $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
946 | + $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
947 | 947 | break; |
948 | 948 | case 'FR': |
949 | - $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
950 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
951 | - $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
952 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
949 | + $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
950 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
951 | + $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
952 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
953 | 953 | break; |
954 | 954 | case 'GB': |
955 | - $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
956 | - $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
957 | - $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
958 | - $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
955 | + $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
956 | + $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
957 | + $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
958 | + $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
959 | 959 | break; |
960 | 960 | case 'GR': |
961 | - $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
961 | + $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
962 | 962 | break; |
963 | 963 | case 'HR': |
964 | - $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
964 | + $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
965 | 965 | break; |
966 | 966 | case 'HU': |
967 | - $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
967 | + $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
968 | 968 | break; |
969 | 969 | case 'IE': |
970 | - $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
971 | - $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
972 | - $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
970 | + $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
971 | + $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
972 | + $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
973 | 973 | break; |
974 | 974 | case 'IT': |
975 | - $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
975 | + $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
976 | 976 | break; |
977 | 977 | case 'LV': |
978 | - $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
978 | + $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
979 | 979 | break; |
980 | 980 | case 'LT': |
981 | - $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
981 | + $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
982 | 982 | break; |
983 | 983 | case 'LU': |
984 | - $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
984 | + $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
985 | 985 | break; |
986 | 986 | case 'MT': |
987 | - $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
987 | + $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
988 | 988 | break; |
989 | 989 | case 'NL': |
990 | - $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
990 | + $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
991 | 991 | break; |
992 | 992 | case 'NO': |
993 | - $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
993 | + $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
994 | 994 | break; |
995 | 995 | case 'PL': |
996 | - $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
996 | + $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
997 | 997 | break; |
998 | 998 | case 'PT': |
999 | - $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
999 | + $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
1000 | 1000 | break; |
1001 | 1001 | case 'RO': |
1002 | - $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
1002 | + $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
1003 | 1003 | break; |
1004 | 1004 | case 'RS': |
1005 | - $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
1005 | + $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
1006 | 1006 | break; |
1007 | 1007 | case 'SI': |
1008 | - $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
1008 | + $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
1009 | 1009 | break; |
1010 | 1010 | case 'SK': |
1011 | - $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
1011 | + $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
1012 | 1012 | break; |
1013 | 1013 | case 'SE': |
1014 | - $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
1014 | + $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
1015 | 1015 | break; |
1016 | 1016 | default: |
1017 | 1017 | $regex = array(); |
1018 | 1018 | break; |
1019 | 1019 | } |
1020 | 1020 | |
1021 | - if ( empty( $regex ) ) { |
|
1021 | + if (empty($regex)) { |
|
1022 | 1022 | return false; |
1023 | 1023 | } |
1024 | 1024 | |
1025 | - foreach ( $regex as $pattern ) { |
|
1025 | + foreach ($regex as $pattern) { |
|
1026 | 1026 | $matches = null; |
1027 | - preg_match_all( $pattern, $vat_number, $matches ); |
|
1027 | + preg_match_all($pattern, $vat_number, $matches); |
|
1028 | 1028 | |
1029 | - if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) { |
|
1030 | - if ( $formatted ) { |
|
1031 | - return array( 'code' => $matches[1][0], 'number' => $matches[2][0] ); |
|
1029 | + if (!empty($matches[1][0]) && !empty($matches[2][0])) { |
|
1030 | + if ($formatted) { |
|
1031 | + return array('code' => $matches[1][0], 'number' => $matches[2][0]); |
|
1032 | 1032 | } else { |
1033 | 1033 | return true; |
1034 | 1034 | } |
@@ -1038,75 +1038,75 @@ discard block |
||
1038 | 1038 | return false; |
1039 | 1039 | } |
1040 | 1040 | |
1041 | - public static function vies_check( $vat_number, $country_code = '', $result = false ) { |
|
1042 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
1041 | + public static function vies_check($vat_number, $country_code = '', $result = false) { |
|
1042 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
1043 | 1043 | $vat_number = $vat['vat']; |
1044 | 1044 | $iso = $vat['iso']; |
1045 | 1045 | |
1046 | - $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number ); |
|
1046 | + $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number); |
|
1047 | 1047 | |
1048 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
1049 | - $response = file_get_contents( $url ); |
|
1050 | - } else if ( function_exists( 'curl_init' ) ) { |
|
1048 | + if (ini_get('allow_url_fopen')) { |
|
1049 | + $response = file_get_contents($url); |
|
1050 | + } else if (function_exists('curl_init')) { |
|
1051 | 1051 | $ch = curl_init(); |
1052 | 1052 | |
1053 | - curl_setopt( $ch, CURLOPT_URL, $url ); |
|
1054 | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 ); |
|
1055 | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); |
|
1056 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); |
|
1057 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); |
|
1053 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
1054 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); |
|
1055 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
1056 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
1057 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
1058 | 1058 | |
1059 | - $response = curl_exec( $ch ); |
|
1059 | + $response = curl_exec($ch); |
|
1060 | 1060 | |
1061 | - if ( curl_errno( $ch ) ) { |
|
1062 | - wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' ); |
|
1061 | + if (curl_errno($ch)) { |
|
1062 | + wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR'); |
|
1063 | 1063 | $response = ''; |
1064 | 1064 | } |
1065 | 1065 | |
1066 | - curl_close( $ch ); |
|
1066 | + curl_close($ch); |
|
1067 | 1067 | } else { |
1068 | - wpinv_error_log( 'To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR' ); |
|
1068 | + wpinv_error_log('To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR'); |
|
1069 | 1069 | } |
1070 | 1070 | |
1071 | - if ( empty( $response ) ) { |
|
1071 | + if (empty($response)) { |
|
1072 | 1072 | return $result; |
1073 | 1073 | } |
1074 | 1074 | |
1075 | - if ( preg_match( '/invalid VAT number/i', $response ) ) { |
|
1075 | + if (preg_match('/invalid VAT number/i', $response)) { |
|
1076 | 1076 | return false; |
1077 | - } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) { |
|
1078 | - $content = explode( "valid VAT number", htmlentities( $response ) ); |
|
1077 | + } else if (preg_match('/valid VAT number/i', $response, $matches)) { |
|
1078 | + $content = explode("valid VAT number", htmlentities($response)); |
|
1079 | 1079 | |
1080 | - if ( !empty( $content[1] ) ) { |
|
1081 | - preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches ); |
|
1080 | + if (!empty($content[1])) { |
|
1081 | + preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches); |
|
1082 | 1082 | |
1083 | - if ( !empty( $matches[2] ) && $matches[3] ) { |
|
1083 | + if (!empty($matches[2]) && $matches[3]) { |
|
1084 | 1084 | $return = array(); |
1085 | 1085 | |
1086 | - foreach ( $matches[2] as $key => $label ) { |
|
1087 | - $label = trim( $label ); |
|
1086 | + foreach ($matches[2] as $key => $label) { |
|
1087 | + $label = trim($label); |
|
1088 | 1088 | |
1089 | - switch ( strtolower( $label ) ) { |
|
1089 | + switch (strtolower($label)) { |
|
1090 | 1090 | case 'member state': |
1091 | - $return['state'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1091 | + $return['state'] = trim(strip_tags($matches[3][$key])); |
|
1092 | 1092 | break; |
1093 | 1093 | case 'vat number': |
1094 | - $return['number'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1094 | + $return['number'] = trim(strip_tags($matches[3][$key])); |
|
1095 | 1095 | break; |
1096 | 1096 | case 'name': |
1097 | - $return['company'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1097 | + $return['company'] = trim(strip_tags($matches[3][$key])); |
|
1098 | 1098 | break; |
1099 | 1099 | case 'address': |
1100 | - $address = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) ); |
|
1101 | - $return['address'] = trim( strip_tags( $address, '<br>' ) ); |
|
1100 | + $address = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key]))); |
|
1101 | + $return['address'] = trim(strip_tags($address, '<br>')); |
|
1102 | 1102 | break; |
1103 | 1103 | case 'consultation number': |
1104 | - $return['consultation'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1104 | + $return['consultation'] = trim(strip_tags($matches[3][$key])); |
|
1105 | 1105 | break; |
1106 | 1106 | } |
1107 | 1107 | } |
1108 | 1108 | |
1109 | - if ( !empty( $return ) ) { |
|
1109 | + if (!empty($return)) { |
|
1110 | 1110 | return $return; |
1111 | 1111 | } |
1112 | 1112 | } |
@@ -1118,55 +1118,55 @@ discard block |
||
1118 | 1118 | } |
1119 | 1119 | } |
1120 | 1120 | |
1121 | - public static function check_vat( $vat_number, $country_code = '' ) { |
|
1121 | + public static function check_vat($vat_number, $country_code = '') { |
|
1122 | 1122 | $vat_name = self::get_vat_name(); |
1123 | 1123 | |
1124 | 1124 | $return = array(); |
1125 | 1125 | $return['valid'] = false; |
1126 | - $return['message'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
1126 | + $return['message'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
1127 | 1127 | |
1128 | - if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) { |
|
1128 | + if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) { |
|
1129 | 1129 | return $return; |
1130 | 1130 | } |
1131 | 1131 | |
1132 | - $response = self::vies_check( $vat_number, $country_code ); |
|
1132 | + $response = self::vies_check($vat_number, $country_code); |
|
1133 | 1133 | |
1134 | - if ( $response ) { |
|
1135 | - $return['valid'] = true; |
|
1134 | + if ($response) { |
|
1135 | + $return['valid'] = true; |
|
1136 | 1136 | |
1137 | - if ( is_array( $response ) ) { |
|
1138 | - $return['company'] = isset( $response['company'] ) ? $response['company'] : ''; |
|
1139 | - $return['address'] = isset( $response['address'] ) ? $response['address'] : ''; |
|
1137 | + if (is_array($response)) { |
|
1138 | + $return['company'] = isset($response['company']) ? $response['company'] : ''; |
|
1139 | + $return['address'] = isset($response['address']) ? $response['address'] : ''; |
|
1140 | 1140 | $return['message'] = $return['company'] . '<br/>' . $return['address']; |
1141 | 1141 | } |
1142 | 1142 | } else { |
1143 | 1143 | $return['valid'] = false; |
1144 | - $return['message'] = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
1144 | + $return['message'] = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
1145 | 1145 | } |
1146 | 1146 | |
1147 | 1147 | return $return; |
1148 | 1148 | } |
1149 | 1149 | |
1150 | - public static function request_euvatrates( $group ) { |
|
1150 | + public static function request_euvatrates($group) { |
|
1151 | 1151 | $response = array(); |
1152 | 1152 | $response['success'] = false; |
1153 | 1153 | $response['error'] = null; |
1154 | 1154 | $response['eurates'] = null; |
1155 | 1155 | |
1156 | 1156 | $euvatrates_url = 'https://euvatrates.com/rates.json'; |
1157 | - $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url ); |
|
1158 | - $api_response = wp_remote_get( $euvatrates_url ); |
|
1157 | + $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url); |
|
1158 | + $api_response = wp_remote_get($euvatrates_url); |
|
1159 | 1159 | |
1160 | 1160 | try { |
1161 | - if ( is_wp_error( $api_response ) ) { |
|
1162 | - $response['error'] = __( $api_response->get_error_message(), 'invoicing' ); |
|
1161 | + if (is_wp_error($api_response)) { |
|
1162 | + $response['error'] = __($api_response->get_error_message(), 'invoicing'); |
|
1163 | 1163 | } else { |
1164 | - $body = json_decode( $api_response['body'] ); |
|
1164 | + $body = json_decode($api_response['body']); |
|
1165 | 1165 | |
1166 | - if ( isset( $body->rates ) ) { |
|
1166 | + if (isset($body->rates)) { |
|
1167 | 1167 | $rates = array(); |
1168 | 1168 | |
1169 | - foreach ( $body->rates as $country_code => $rate ) { |
|
1169 | + foreach ($body->rates as $country_code => $rate) { |
|
1170 | 1170 | $vat_rate = array(); |
1171 | 1171 | $vat_rate['country'] = $rate->country; |
1172 | 1172 | $vat_rate['standard'] = (float)$rate->standard_rate; |
@@ -1174,7 +1174,7 @@ discard block |
||
1174 | 1174 | $vat_rate['superreduced'] = (float)$rate->super_reduced_rate; |
1175 | 1175 | $vat_rate['parking'] = (float)$rate->parking_rate; |
1176 | 1176 | |
1177 | - if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) { |
|
1177 | + if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) { |
|
1178 | 1178 | $vat_rate_group = array(); |
1179 | 1179 | $vat_rate_group['country'] = $rate->country; |
1180 | 1180 | $vat_rate_group[$group] = $vat_rate[$group]; |
@@ -1186,79 +1186,79 @@ discard block |
||
1186 | 1186 | } |
1187 | 1187 | |
1188 | 1188 | $response['success'] = true; |
1189 | - $response['rates'] = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group ); |
|
1189 | + $response['rates'] = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group); |
|
1190 | 1190 | } else { |
1191 | - $response['error'] = __( 'No EU rates found!', 'invoicing' ); |
|
1191 | + $response['error'] = __('No EU rates found!', 'invoicing'); |
|
1192 | 1192 | } |
1193 | 1193 | } |
1194 | - } catch ( Exception $e ) { |
|
1195 | - $response['error'] = __( $e->getMessage(), 'invoicing' ); |
|
1194 | + } catch (Exception $e) { |
|
1195 | + $response['error'] = __($e->getMessage(), 'invoicing'); |
|
1196 | 1196 | } |
1197 | 1197 | |
1198 | - return apply_filters( 'wpinv_response_euvatrates', $response, $group ); |
|
1198 | + return apply_filters('wpinv_response_euvatrates', $response, $group); |
|
1199 | 1199 | } |
1200 | 1200 | |
1201 | - public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) { |
|
1201 | + public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) { |
|
1202 | 1202 | global $wpi_item_id, $wpi_country; |
1203 | 1203 | |
1204 | - if ( !empty( $_POST['wpinv_country'] ) ) { |
|
1205 | - $country_code = trim( $_POST['wpinv_country'] ); |
|
1206 | - } else if ( !empty( $_POST['country'] ) ) { |
|
1207 | - $country_code = trim( $_POST['country'] ); |
|
1208 | - } else if ( !empty( $wpi_country ) ) { |
|
1204 | + if (!empty($_POST['wpinv_country'])) { |
|
1205 | + $country_code = trim($_POST['wpinv_country']); |
|
1206 | + } else if (!empty($_POST['country'])) { |
|
1207 | + $country_code = trim($_POST['country']); |
|
1208 | + } else if (!empty($wpi_country)) { |
|
1209 | 1209 | $country_code = $wpi_country; |
1210 | 1210 | } else { |
1211 | - $country_code = self::get_user_country( '', $user_id ); |
|
1211 | + $country_code = self::get_user_country('', $user_id); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | - if ( $is_digital === null && $wpi_item_id ) { |
|
1215 | - $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules(); |
|
1214 | + if ($is_digital === null && $wpi_item_id) { |
|
1215 | + $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules(); |
|
1216 | 1216 | } |
1217 | 1217 | |
1218 | - if ( !empty( $country_code ) ) { |
|
1219 | - $requires_vat = ( self::is_eu_state( $country_code ) && ( self::is_eu_state( self::$default_country ) || $is_digital ) ) || ( self::is_gst_country( $country_code ) && self::is_gst_country( self::$default_country ) ); |
|
1218 | + if (!empty($country_code)) { |
|
1219 | + $requires_vat = (self::is_eu_state($country_code) && (self::is_eu_state(self::$default_country) || $is_digital)) || (self::is_gst_country($country_code) && self::is_gst_country(self::$default_country)); |
|
1220 | 1220 | } |
1221 | 1221 | |
1222 | - return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id ); |
|
1222 | + return apply_filters('wpinv_requires_vat', $requires_vat, $user_id); |
|
1223 | 1223 | } |
1224 | 1224 | |
1225 | - public static function tax_label( $label = '' ) { |
|
1225 | + public static function tax_label($label = '') { |
|
1226 | 1226 | global $wpi_requires_vat; |
1227 | 1227 | |
1228 | - if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) { |
|
1229 | - $wpi_requires_vat = self::requires_vat( 0, false ); |
|
1228 | + if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) { |
|
1229 | + $wpi_requires_vat = self::requires_vat(0, false); |
|
1230 | 1230 | } |
1231 | 1231 | |
1232 | - return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) ); |
|
1232 | + return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing')); |
|
1233 | 1233 | } |
1234 | 1234 | |
1235 | 1235 | public static function standard_rates_label() { |
1236 | - return __( 'Standard Rates', 'invoicing' ); |
|
1236 | + return __('Standard Rates', 'invoicing'); |
|
1237 | 1237 | } |
1238 | 1238 | |
1239 | - public static function get_rate_classes( $with_desc = false ) { |
|
1240 | - $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true ); |
|
1241 | - $classes = maybe_unserialize( $rate_classes_option ); |
|
1239 | + public static function get_rate_classes($with_desc = false) { |
|
1240 | + $rate_classes_option = get_option('_wpinv_vat_rate_classes', true); |
|
1241 | + $classes = maybe_unserialize($rate_classes_option); |
|
1242 | 1242 | |
1243 | - if ( empty( $classes ) || !is_array( $classes ) ) { |
|
1243 | + if (empty($classes) || !is_array($classes)) { |
|
1244 | 1244 | $classes = array(); |
1245 | 1245 | } |
1246 | 1246 | |
1247 | 1247 | $rate_classes = array(); |
1248 | - if ( !array_key_exists( '_standard', $classes ) ) { |
|
1249 | - if ( $with_desc ) { |
|
1250 | - $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) ); |
|
1248 | + if (!array_key_exists('_standard', $classes)) { |
|
1249 | + if ($with_desc) { |
|
1250 | + $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing')); |
|
1251 | 1251 | } else { |
1252 | 1252 | $rate_classes['_standard'] = self::standard_rates_label(); |
1253 | 1253 | } |
1254 | 1254 | } |
1255 | 1255 | |
1256 | - foreach ( $classes as $key => $class ) { |
|
1257 | - $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key; |
|
1258 | - $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : ''; |
|
1256 | + foreach ($classes as $key => $class) { |
|
1257 | + $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key; |
|
1258 | + $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : ''; |
|
1259 | 1259 | |
1260 | - if ( $with_desc ) { |
|
1261 | - $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc ); |
|
1260 | + if ($with_desc) { |
|
1261 | + $rate_classes[$key] = array('name' => $name, 'desc' => $desc); |
|
1262 | 1262 | } else { |
1263 | 1263 | $rate_classes[$key] = $name; |
1264 | 1264 | } |
@@ -1269,15 +1269,15 @@ discard block |
||
1269 | 1269 | |
1270 | 1270 | public static function get_all_classes() { |
1271 | 1271 | $classes = self::get_rate_classes(); |
1272 | - $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' ); |
|
1272 | + $classes['_exempt'] = __('Exempt (0%)', 'invoicing'); |
|
1273 | 1273 | |
1274 | - return apply_filters( 'wpinv_vat_get_all_classes', $classes ); |
|
1274 | + return apply_filters('wpinv_vat_get_all_classes', $classes); |
|
1275 | 1275 | } |
1276 | 1276 | |
1277 | - public static function get_class_desc( $rate_class ) { |
|
1278 | - $rate_classes = self::get_rate_classes( true ); |
|
1277 | + public static function get_class_desc($rate_class) { |
|
1278 | + $rate_classes = self::get_rate_classes(true); |
|
1279 | 1279 | |
1280 | - if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) { |
|
1280 | + if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) { |
|
1281 | 1281 | return $rate_classes[$rate_class]['desc']; |
1282 | 1282 | } |
1283 | 1283 | |
@@ -1293,106 +1293,106 @@ discard block |
||
1293 | 1293 | 'increased' => 'Increased' |
1294 | 1294 | ); |
1295 | 1295 | |
1296 | - return apply_filters( 'wpinv_get_vat_groups', $vat_groups ); |
|
1296 | + return apply_filters('wpinv_get_vat_groups', $vat_groups); |
|
1297 | 1297 | } |
1298 | 1298 | |
1299 | 1299 | public static function get_rules() { |
1300 | 1300 | $vat_rules = array( |
1301 | - 'digital' => __( 'Digital Product', 'invoicing' ), |
|
1302 | - 'physical' => __( 'Physical Product', 'invoicing' ) |
|
1301 | + 'digital' => __('Digital Product', 'invoicing'), |
|
1302 | + 'physical' => __('Physical Product', 'invoicing') |
|
1303 | 1303 | ); |
1304 | - return apply_filters( 'wpinv_get_vat_rules', $vat_rules ); |
|
1304 | + return apply_filters('wpinv_get_vat_rules', $vat_rules); |
|
1305 | 1305 | } |
1306 | 1306 | |
1307 | - public static function get_vat_rates( $class ) { |
|
1308 | - if ( $class === '_standard' ) { |
|
1307 | + public static function get_vat_rates($class) { |
|
1308 | + if ($class === '_standard') { |
|
1309 | 1309 | return wpinv_get_tax_rates(); |
1310 | 1310 | } |
1311 | 1311 | |
1312 | 1312 | $rates = self::get_non_standard_rates(); |
1313 | 1313 | |
1314 | - return array_key_exists( $class, $rates ) ? $rates[$class] : array(); |
|
1314 | + return array_key_exists($class, $rates) ? $rates[$class] : array(); |
|
1315 | 1315 | } |
1316 | 1316 | |
1317 | 1317 | public static function get_non_standard_rates() { |
1318 | - $option = get_option( 'wpinv_vat_rates', array()); |
|
1319 | - return is_array( $option ) ? $option : array(); |
|
1318 | + $option = get_option('wpinv_vat_rates', array()); |
|
1319 | + return is_array($option) ? $option : array(); |
|
1320 | 1320 | } |
1321 | 1321 | |
1322 | 1322 | public static function allow_vat_rules() { |
1323 | - return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false ); |
|
1323 | + return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false); |
|
1324 | 1324 | } |
1325 | 1325 | |
1326 | 1326 | public static function allow_vat_classes() { |
1327 | 1327 | return false; // TODO |
1328 | - return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false ); |
|
1328 | + return (wpinv_get_option('vat_allow_classes') ? true : false); |
|
1329 | 1329 | } |
1330 | 1330 | |
1331 | - public static function get_item_class( $postID ) { |
|
1332 | - $class = get_post_meta( $postID, '_wpinv_vat_class', true ); |
|
1331 | + public static function get_item_class($postID) { |
|
1332 | + $class = get_post_meta($postID, '_wpinv_vat_class', true); |
|
1333 | 1333 | |
1334 | - if ( empty( $class ) ) { |
|
1334 | + if (empty($class)) { |
|
1335 | 1335 | $class = '_standard'; |
1336 | 1336 | } |
1337 | 1337 | |
1338 | - return apply_filters( 'wpinv_get_item_vat_class', $class, $postID ); |
|
1338 | + return apply_filters('wpinv_get_item_vat_class', $class, $postID); |
|
1339 | 1339 | } |
1340 | 1340 | |
1341 | - public static function item_class_label( $postID ) { |
|
1341 | + public static function item_class_label($postID) { |
|
1342 | 1342 | $vat_classes = self::get_all_classes(); |
1343 | 1343 | |
1344 | - $class = self::get_item_class( $postID ); |
|
1345 | - $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' ); |
|
1344 | + $class = self::get_item_class($postID); |
|
1345 | + $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing'); |
|
1346 | 1346 | |
1347 | - return apply_filters( 'wpinv_item_class_label', $class, $postID ); |
|
1347 | + return apply_filters('wpinv_item_class_label', $class, $postID); |
|
1348 | 1348 | } |
1349 | 1349 | |
1350 | - public static function get_item_rule( $postID ) { |
|
1351 | - $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true ); |
|
1350 | + public static function get_item_rule($postID) { |
|
1351 | + $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true); |
|
1352 | 1352 | |
1353 | - if ( empty( $rule_type ) ) { |
|
1353 | + if (empty($rule_type)) { |
|
1354 | 1354 | $rule_type = self::allow_vat_rules() ? 'digital' : 'physical'; |
1355 | 1355 | } |
1356 | 1356 | |
1357 | - return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID ); |
|
1357 | + return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID); |
|
1358 | 1358 | } |
1359 | 1359 | |
1360 | - public static function item_rule_label( $postID ) { |
|
1360 | + public static function item_rule_label($postID) { |
|
1361 | 1361 | $vat_rules = self::get_rules(); |
1362 | - $vat_rule = self::get_item_rule( $postID ); |
|
1363 | - $vat_rule = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule; |
|
1362 | + $vat_rule = self::get_item_rule($postID); |
|
1363 | + $vat_rule = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule; |
|
1364 | 1364 | |
1365 | - return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID ); |
|
1365 | + return apply_filters('wpinv_item_rule_label', $vat_rule, $postID); |
|
1366 | 1366 | } |
1367 | 1367 | |
1368 | - public static function item_has_digital_rule( $item_id = 0 ) { |
|
1369 | - return self::get_item_rule( $item_id ) == 'digital' ? true : false; |
|
1368 | + public static function item_has_digital_rule($item_id = 0) { |
|
1369 | + return self::get_item_rule($item_id) == 'digital' ? true : false; |
|
1370 | 1370 | } |
1371 | 1371 | |
1372 | - public static function invoice_has_digital_rule( $invoice = 0 ) { |
|
1373 | - if ( !self::allow_vat_rules() ) { |
|
1372 | + public static function invoice_has_digital_rule($invoice = 0) { |
|
1373 | + if (!self::allow_vat_rules()) { |
|
1374 | 1374 | return false; |
1375 | 1375 | } |
1376 | 1376 | |
1377 | - if ( empty( $invoice ) ) { |
|
1377 | + if (empty($invoice)) { |
|
1378 | 1378 | return true; |
1379 | 1379 | } |
1380 | 1380 | |
1381 | - if ( is_int( $invoice ) ) { |
|
1382 | - $invoice = new WPInv_Invoice( $invoice ); |
|
1381 | + if (is_int($invoice)) { |
|
1382 | + $invoice = new WPInv_Invoice($invoice); |
|
1383 | 1383 | } |
1384 | 1384 | |
1385 | - if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) { |
|
1385 | + if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) { |
|
1386 | 1386 | return true; |
1387 | 1387 | } |
1388 | 1388 | |
1389 | - $cart_items = $invoice->get_cart_details(); |
|
1389 | + $cart_items = $invoice->get_cart_details(); |
|
1390 | 1390 | |
1391 | - if ( !empty( $cart_items ) ) { |
|
1391 | + if (!empty($cart_items)) { |
|
1392 | 1392 | $has_digital_rule = false; |
1393 | 1393 | |
1394 | - foreach ( $cart_items as $key => $item ) { |
|
1395 | - if ( self::item_has_digital_rule( $item['id'] ) ) { |
|
1394 | + foreach ($cart_items as $key => $item) { |
|
1395 | + if (self::item_has_digital_rule($item['id'])) { |
|
1396 | 1396 | $has_digital_rule = true; |
1397 | 1397 | break; |
1398 | 1398 | } |
@@ -1404,67 +1404,67 @@ discard block |
||
1404 | 1404 | return $has_digital_rule; |
1405 | 1405 | } |
1406 | 1406 | |
1407 | - public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) { |
|
1408 | - if ( !wpinv_use_taxes() ) { |
|
1407 | + public static function item_is_taxable($item_id = 0, $country = false, $state = false) { |
|
1408 | + if (!wpinv_use_taxes()) { |
|
1409 | 1409 | return false; |
1410 | 1410 | } |
1411 | 1411 | |
1412 | 1412 | $is_taxable = true; |
1413 | 1413 | |
1414 | - if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) { |
|
1414 | + if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') { |
|
1415 | 1415 | $is_taxable = false; |
1416 | 1416 | } |
1417 | 1417 | |
1418 | - return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state ); |
|
1418 | + return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state); |
|
1419 | 1419 | } |
1420 | 1420 | |
1421 | - public static function find_rate( $country, $state, $rate, $class ) { |
|
1421 | + public static function find_rate($country, $state, $rate, $class) { |
|
1422 | 1422 | global $wpi_zero_tax; |
1423 | 1423 | |
1424 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
1424 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
1425 | 1425 | return 0; |
1426 | 1426 | } |
1427 | 1427 | |
1428 | - $tax_rates = wpinv_get_tax_rates(); |
|
1428 | + $tax_rates = wpinv_get_tax_rates(); |
|
1429 | 1429 | |
1430 | - if ( $class !== '_standard' ) { |
|
1431 | - $class_rates = self::get_vat_rates( $class ); |
|
1430 | + if ($class !== '_standard') { |
|
1431 | + $class_rates = self::get_vat_rates($class); |
|
1432 | 1432 | |
1433 | - if ( is_array( $class_rates ) ) { |
|
1433 | + if (is_array($class_rates)) { |
|
1434 | 1434 | $indexed_class_rates = array(); |
1435 | 1435 | |
1436 | - foreach ( $class_rates as $key => $cr ) { |
|
1436 | + foreach ($class_rates as $key => $cr) { |
|
1437 | 1437 | $indexed_class_rates[$cr['country']] = $cr; |
1438 | 1438 | } |
1439 | 1439 | |
1440 | - $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) { |
|
1440 | + $tax_rates = array_map(function($tr) use($indexed_class_rates) { |
|
1441 | 1441 | $tr_country = $tr['country']; |
1442 | - if ( !isset( $indexed_class_rates[$tr_country] ) ) { |
|
1442 | + if (!isset($indexed_class_rates[$tr_country])) { |
|
1443 | 1443 | return $tr; |
1444 | 1444 | } |
1445 | 1445 | $icr = $indexed_class_rates[$tr_country]; |
1446 | - return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr; |
|
1446 | + return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr; |
|
1447 | 1447 | |
1448 | - }, $tax_rates, $class_rates ); |
|
1448 | + }, $tax_rates, $class_rates); |
|
1449 | 1449 | } |
1450 | 1450 | } |
1451 | 1451 | |
1452 | - if ( !empty( $tax_rates ) ) { |
|
1453 | - foreach ( $tax_rates as $key => $tax_rate ) { |
|
1454 | - if ( $country != $tax_rate['country'] ) |
|
1452 | + if (!empty($tax_rates)) { |
|
1453 | + foreach ($tax_rates as $key => $tax_rate) { |
|
1454 | + if ($country != $tax_rate['country']) |
|
1455 | 1455 | continue; |
1456 | 1456 | |
1457 | - if ( !empty( $tax_rate['global'] ) ) { |
|
1458 | - if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) { |
|
1459 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
1457 | + if (!empty($tax_rate['global'])) { |
|
1458 | + if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) { |
|
1459 | + $rate = number_format($tax_rate['rate'], 4); |
|
1460 | 1460 | } |
1461 | 1461 | } else { |
1462 | - if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
1462 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
1463 | 1463 | continue; |
1464 | 1464 | |
1465 | 1465 | $state_rate = $tax_rate['rate']; |
1466 | - if ( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
1467 | - $rate = number_format( $state_rate, 4 ); |
|
1466 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
1467 | + $rate = number_format($state_rate, 4); |
|
1468 | 1468 | } |
1469 | 1469 | } |
1470 | 1470 | } |
@@ -1473,84 +1473,84 @@ discard block |
||
1473 | 1473 | return $rate; |
1474 | 1474 | } |
1475 | 1475 | |
1476 | - public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) { |
|
1476 | + public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) { |
|
1477 | 1477 | global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax; |
1478 | 1478 | |
1479 | 1479 | $item_id = $item_id > 0 ? $item_id : $wpi_item_id; |
1480 | 1480 | $allow_vat_classes = self::allow_vat_classes(); |
1481 | - $class = $item_id ? self::get_item_class( $item_id ) : '_standard'; |
|
1481 | + $class = $item_id ? self::get_item_class($item_id) : '_standard'; |
|
1482 | 1482 | |
1483 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
1483 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
1484 | 1484 | return 0; |
1485 | - } else if ( !$allow_vat_classes ) { |
|
1485 | + } else if (!$allow_vat_classes) { |
|
1486 | 1486 | $class = '_standard'; |
1487 | 1487 | } |
1488 | 1488 | |
1489 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
1489 | + if (!empty($_POST['wpinv_country'])) { |
|
1490 | 1490 | $post_country = $_POST['wpinv_country']; |
1491 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
1491 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
1492 | 1492 | $post_country = $_POST['wpinv_country']; |
1493 | - } elseif( !empty( $_POST['country'] ) ) { |
|
1493 | + } elseif (!empty($_POST['country'])) { |
|
1494 | 1494 | $post_country = $_POST['country']; |
1495 | 1495 | } else { |
1496 | 1496 | $post_country = ''; |
1497 | 1497 | } |
1498 | 1498 | |
1499 | - $country = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country ); |
|
1500 | - $base_country = wpinv_is_base_country( $country ); |
|
1499 | + $country = !empty($post_country) ? $post_country : wpinv_default_billing_country($country); |
|
1500 | + $base_country = wpinv_is_base_country($country); |
|
1501 | 1501 | |
1502 | - $requires_vat = self::requires_vat( 0, false ); |
|
1503 | - $is_digital = self::get_item_rule( $item_id ) == 'digital' ; |
|
1504 | - $rate = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
1502 | + $requires_vat = self::requires_vat(0, false); |
|
1503 | + $is_digital = self::get_item_rule($item_id) == 'digital'; |
|
1504 | + $rate = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
1505 | 1505 | |
1506 | - if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country |
|
1506 | + if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country |
|
1507 | 1507 | $rate = 0; |
1508 | - } else if ( $requires_vat ) { |
|
1509 | - $vat_number = self::get_user_vat_number( '', 0, true ); |
|
1508 | + } else if ($requires_vat) { |
|
1509 | + $vat_number = self::get_user_vat_number('', 0, true); |
|
1510 | 1510 | $vat_info = self::current_vat_data(); |
1511 | 1511 | |
1512 | - if ( is_array( $vat_info ) ) { |
|
1513 | - $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : ""; |
|
1512 | + if (is_array($vat_info)) { |
|
1513 | + $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : ""; |
|
1514 | 1514 | } |
1515 | 1515 | |
1516 | - if ( $country == 'UK' ) { |
|
1516 | + if ($country == 'UK') { |
|
1517 | 1517 | $country = 'GB'; |
1518 | 1518 | } |
1519 | 1519 | |
1520 | - if ( !empty( $vat_number ) ) { |
|
1520 | + if (!empty($vat_number)) { |
|
1521 | 1521 | $rate = 0; |
1522 | 1522 | } else { |
1523 | - $rate = self::find_rate( $country, $state, $rate, $class ); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate |
|
1523 | + $rate = self::find_rate($country, $state, $rate, $class); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate |
|
1524 | 1524 | } |
1525 | 1525 | |
1526 | - if ( empty( $vat_number ) && !$is_digital ) { |
|
1527 | - if ( $base_country ) { |
|
1528 | - $rate = self::find_rate( $country, null, $rate, $class ); |
|
1526 | + if (empty($vat_number) && !$is_digital) { |
|
1527 | + if ($base_country) { |
|
1528 | + $rate = self::find_rate($country, null, $rate, $class); |
|
1529 | 1529 | } else { |
1530 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
1530 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
1531 | 1531 | $rate = $wpinv_options['eu_fallback_rate']; |
1532 | - } else if( !empty( $country ) ) { |
|
1533 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1532 | + } else if (!empty($country)) { |
|
1533 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1534 | 1534 | } |
1535 | 1535 | } |
1536 | - } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) { |
|
1537 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
1536 | + } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) { |
|
1537 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
1538 | 1538 | $rate = $wpinv_options['eu_fallback_rate']; |
1539 | - } else if( !empty( $country ) ) { |
|
1540 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1539 | + } else if (!empty($country)) { |
|
1540 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1541 | 1541 | } |
1542 | 1542 | } |
1543 | 1543 | } else { |
1544 | - if ( $is_digital ) { |
|
1544 | + if ($is_digital) { |
|
1545 | 1545 | $ip_country_code = self::get_country_by_ip(); |
1546 | 1546 | |
1547 | - if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) { |
|
1548 | - $rate = self::find_rate( $ip_country_code, '', 0, $class ); |
|
1547 | + if ($ip_country_code && self::is_eu_state($ip_country_code)) { |
|
1548 | + $rate = self::find_rate($ip_country_code, '', 0, $class); |
|
1549 | 1549 | } else { |
1550 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1550 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1551 | 1551 | } |
1552 | 1552 | } else { |
1553 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1553 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1554 | 1554 | } |
1555 | 1555 | } |
1556 | 1556 | |
@@ -1560,48 +1560,48 @@ discard block |
||
1560 | 1560 | public static function current_vat_data() { |
1561 | 1561 | global $wpi_session; |
1562 | 1562 | |
1563 | - return $wpi_session->get( 'user_vat_data' ); |
|
1563 | + return $wpi_session->get('user_vat_data'); |
|
1564 | 1564 | } |
1565 | 1565 | |
1566 | - public static function get_user_country( $country = '', $user_id = 0 ) { |
|
1567 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
1566 | + public static function get_user_country($country = '', $user_id = 0) { |
|
1567 | + $user_address = wpinv_get_user_address($user_id, false); |
|
1568 | 1568 | |
1569 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
1569 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
1570 | 1570 | $country = ''; |
1571 | 1571 | } |
1572 | 1572 | |
1573 | - $country = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country']; |
|
1574 | - $result = apply_filters( 'wpinv_get_user_country', $country, $user_id ); |
|
1573 | + $country = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country']; |
|
1574 | + $result = apply_filters('wpinv_get_user_country', $country, $user_id); |
|
1575 | 1575 | |
1576 | - if ( empty( $result ) ) { |
|
1576 | + if (empty($result)) { |
|
1577 | 1577 | $result = self::get_country_by_ip(); |
1578 | 1578 | } |
1579 | 1579 | |
1580 | 1580 | return $result; |
1581 | 1581 | } |
1582 | 1582 | |
1583 | - public static function set_user_country( $country = '', $user_id = 0 ) { |
|
1583 | + public static function set_user_country($country = '', $user_id = 0) { |
|
1584 | 1584 | global $wpi_userID; |
1585 | 1585 | |
1586 | - if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) { |
|
1586 | + if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) { |
|
1587 | 1587 | $country = wpinv_get_default_country(); |
1588 | 1588 | } |
1589 | 1589 | |
1590 | 1590 | return $country; |
1591 | 1591 | } |
1592 | 1592 | |
1593 | - public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) { |
|
1593 | + public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) { |
|
1594 | 1594 | global $wpi_current_id, $wpi_userID; |
1595 | 1595 | |
1596 | - if ( !empty( $_POST['new_user'] ) ) { |
|
1596 | + if (!empty($_POST['new_user'])) { |
|
1597 | 1597 | return ''; |
1598 | 1598 | } |
1599 | 1599 | |
1600 | - if ( empty( $user_id ) ) { |
|
1601 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
1600 | + if (empty($user_id)) { |
|
1601 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
1602 | 1602 | } |
1603 | 1603 | |
1604 | - $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true ); |
|
1604 | + $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true); |
|
1605 | 1605 | |
1606 | 1606 | /* TODO |
1607 | 1607 | if ( $is_valid && $vat_number ) { |
@@ -1612,38 +1612,38 @@ discard block |
||
1612 | 1612 | } |
1613 | 1613 | */ |
1614 | 1614 | |
1615 | - return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid ); |
|
1615 | + return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid); |
|
1616 | 1616 | } |
1617 | 1617 | |
1618 | - public static function get_user_company( $company = '', $user_id = 0 ) { |
|
1618 | + public static function get_user_company($company = '', $user_id = 0) { |
|
1619 | 1619 | global $wpi_current_id, $wpi_userID; |
1620 | 1620 | |
1621 | - if ( empty( $user_id ) ) { |
|
1622 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
1621 | + if (empty($user_id)) { |
|
1622 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
1623 | 1623 | } |
1624 | 1624 | |
1625 | - $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true ); |
|
1625 | + $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true); |
|
1626 | 1626 | |
1627 | - return apply_filters( 'wpinv_user_company', $company, $user_id ); |
|
1627 | + return apply_filters('wpinv_user_company', $company, $user_id); |
|
1628 | 1628 | } |
1629 | 1629 | |
1630 | - public static function save_user_vat_details( $company = '', $vat_number = '' ) { |
|
1631 | - $save = apply_filters( 'wpinv_allow_save_user_vat_details', true ); |
|
1630 | + public static function save_user_vat_details($company = '', $vat_number = '') { |
|
1631 | + $save = apply_filters('wpinv_allow_save_user_vat_details', true); |
|
1632 | 1632 | |
1633 | - if ( is_user_logged_in() && $save ) { |
|
1633 | + if (is_user_logged_in() && $save) { |
|
1634 | 1634 | $user_id = get_current_user_id(); |
1635 | 1635 | |
1636 | - if ( !empty( $vat_number ) ) { |
|
1637 | - update_user_meta( $user_id, '_wpinv_vat_number', $vat_number ); |
|
1636 | + if (!empty($vat_number)) { |
|
1637 | + update_user_meta($user_id, '_wpinv_vat_number', $vat_number); |
|
1638 | 1638 | } else { |
1639 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
1639 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
1640 | 1640 | } |
1641 | 1641 | |
1642 | - if ( !empty( $company ) ) { |
|
1643 | - update_user_meta( $user_id, '_wpinv_company', $company ); |
|
1642 | + if (!empty($company)) { |
|
1643 | + update_user_meta($user_id, '_wpinv_company', $company); |
|
1644 | 1644 | } else { |
1645 | - delete_user_meta( $user_id, '_wpinv_company'); |
|
1646 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
1645 | + delete_user_meta($user_id, '_wpinv_company'); |
|
1646 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
1647 | 1647 | } |
1648 | 1648 | } |
1649 | 1649 | |
@@ -1653,113 +1653,113 @@ discard block |
||
1653 | 1653 | public static function ajax_vat_validate() { |
1654 | 1654 | global $wpinv_options, $wpi_session; |
1655 | 1655 | |
1656 | - $is_checkout = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false; |
|
1656 | + $is_checkout = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false; |
|
1657 | 1657 | $response = array(); |
1658 | 1658 | $response['success'] = false; |
1659 | 1659 | |
1660 | - if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) { |
|
1661 | - $response['error'] = __( 'Invalid security nonce', 'invoicing' ); |
|
1662 | - wp_send_json( $response ); |
|
1660 | + if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) { |
|
1661 | + $response['error'] = __('Invalid security nonce', 'invoicing'); |
|
1662 | + wp_send_json($response); |
|
1663 | 1663 | } |
1664 | 1664 | |
1665 | - $vat_name = self::get_vat_name(); |
|
1665 | + $vat_name = self::get_vat_name(); |
|
1666 | 1666 | |
1667 | - if ( $is_checkout ) { |
|
1667 | + if ($is_checkout) { |
|
1668 | 1668 | $invoice = wpinv_get_invoice_cart(); |
1669 | 1669 | |
1670 | - if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) { |
|
1670 | + if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) { |
|
1671 | 1671 | $vat_info = array(); |
1672 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1672 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1673 | 1673 | |
1674 | 1674 | self::save_user_vat_details(); |
1675 | 1675 | |
1676 | 1676 | $response['success'] = true; |
1677 | - $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name ); |
|
1678 | - wp_send_json( $response ); |
|
1677 | + $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name); |
|
1678 | + wp_send_json($response); |
|
1679 | 1679 | } |
1680 | 1680 | } |
1681 | 1681 | |
1682 | - $company = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : ''; |
|
1683 | - $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : ''; |
|
1682 | + $company = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : ''; |
|
1683 | + $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : ''; |
|
1684 | 1684 | |
1685 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1686 | - if ( !is_array( $vat_info ) || empty( $vat_info ) ) { |
|
1687 | - $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true ); |
|
1685 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1686 | + if (!is_array($vat_info) || empty($vat_info)) { |
|
1687 | + $vat_info = array('company'=> $company, 'number' => '', 'valid' => true); |
|
1688 | 1688 | } |
1689 | 1689 | |
1690 | - if ( empty( $vat_number ) ) { |
|
1691 | - if ( $is_checkout ) { |
|
1690 | + if (empty($vat_number)) { |
|
1691 | + if ($is_checkout) { |
|
1692 | 1692 | $response['success'] = true; |
1693 | - $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name ); |
|
1693 | + $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name); |
|
1694 | 1694 | |
1695 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1695 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1696 | 1696 | $vat_info['number'] = ""; |
1697 | 1697 | $vat_info['valid'] = true; |
1698 | 1698 | |
1699 | - self::save_user_vat_details( $company ); |
|
1699 | + self::save_user_vat_details($company); |
|
1700 | 1700 | } else { |
1701 | - $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
1701 | + $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
1702 | 1702 | |
1703 | 1703 | $vat_info['valid'] = false; |
1704 | 1704 | } |
1705 | 1705 | |
1706 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1707 | - wp_send_json( $response ); |
|
1706 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1707 | + wp_send_json($response); |
|
1708 | 1708 | } |
1709 | 1709 | |
1710 | - if ( empty( $company ) ) { |
|
1710 | + if (empty($company)) { |
|
1711 | 1711 | $vat_info['valid'] = false; |
1712 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1712 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1713 | 1713 | |
1714 | - $response['error'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
1715 | - wp_send_json( $response ); |
|
1714 | + $response['error'] = __('Please enter your registered company name!', 'invoicing'); |
|
1715 | + wp_send_json($response); |
|
1716 | 1716 | } |
1717 | 1717 | |
1718 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
1719 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
1718 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
1719 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
1720 | 1720 | $vat_info['valid'] = false; |
1721 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1721 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1722 | 1722 | |
1723 | - $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
1724 | - wp_send_json( $response ); |
|
1723 | + $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
1724 | + wp_send_json($response); |
|
1725 | 1725 | } |
1726 | 1726 | |
1727 | 1727 | $response['success'] = true; |
1728 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
1728 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
1729 | 1729 | } else { |
1730 | - $result = self::check_vat( $vat_number ); |
|
1730 | + $result = self::check_vat($vat_number); |
|
1731 | 1731 | |
1732 | - if ( empty( $result['valid'] ) ) { |
|
1732 | + if (empty($result['valid'])) { |
|
1733 | 1733 | $response['error'] = $result['message']; |
1734 | - wp_send_json( $response ); |
|
1734 | + wp_send_json($response); |
|
1735 | 1735 | } |
1736 | 1736 | |
1737 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
1738 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
1737 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
1738 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
1739 | 1739 | |
1740 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
1740 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
1741 | 1741 | |
1742 | - if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) { |
|
1742 | + if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) { |
|
1743 | 1743 | $response['success'] = true; |
1744 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
1744 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
1745 | 1745 | } else { |
1746 | 1746 | $vat_info['valid'] = false; |
1747 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1747 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1748 | 1748 | |
1749 | 1749 | $response['success'] = false; |
1750 | - $response['message'] = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name ); |
|
1751 | - wp_send_json( $response ); |
|
1750 | + $response['message'] = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name); |
|
1751 | + wp_send_json($response); |
|
1752 | 1752 | } |
1753 | 1753 | } |
1754 | 1754 | |
1755 | - if ( $is_checkout ) { |
|
1756 | - self::save_user_vat_details( $company, $vat_number ); |
|
1755 | + if ($is_checkout) { |
|
1756 | + self::save_user_vat_details($company, $vat_number); |
|
1757 | 1757 | |
1758 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true ); |
|
1759 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1758 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true); |
|
1759 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1760 | 1760 | } |
1761 | 1761 | |
1762 | - wp_send_json( $response ); |
|
1762 | + wp_send_json($response); |
|
1763 | 1763 | } |
1764 | 1764 | |
1765 | 1765 | public static function ajax_vat_reset() { |
@@ -1768,161 +1768,161 @@ discard block |
||
1768 | 1768 | $company = is_user_logged_in() ? self::get_user_company() : ''; |
1769 | 1769 | $vat_number = self::get_user_vat_number(); |
1770 | 1770 | |
1771 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false ); |
|
1772 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1771 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false); |
|
1772 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1773 | 1773 | |
1774 | 1774 | $response = array(); |
1775 | 1775 | $response['success'] = true; |
1776 | 1776 | $response['data']['company'] = $company; |
1777 | 1777 | $response['data']['number'] = $vat_number; |
1778 | 1778 | |
1779 | - wp_send_json( $response ); |
|
1779 | + wp_send_json($response); |
|
1780 | 1780 | } |
1781 | 1781 | |
1782 | - public static function checkout_vat_validate( $valid_data, $post ) { |
|
1782 | + public static function checkout_vat_validate($valid_data, $post) { |
|
1783 | 1783 | global $wpinv_options, $wpi_session; |
1784 | 1784 | |
1785 | - $vat_name = __( self::get_vat_name(), 'invoicing' ); |
|
1785 | + $vat_name = __(self::get_vat_name(), 'invoicing'); |
|
1786 | 1786 | |
1787 | - if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) { |
|
1788 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) ); |
|
1787 | + if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) { |
|
1788 | + wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name)); |
|
1789 | 1789 | return; |
1790 | 1790 | } |
1791 | 1791 | |
1792 | - $vat_saved = $wpi_session->get( 'user_vat_data' ); |
|
1793 | - $wpi_session->set( 'user_vat_data', null ); |
|
1792 | + $vat_saved = $wpi_session->get('user_vat_data'); |
|
1793 | + $wpi_session->set('user_vat_data', null); |
|
1794 | 1794 | |
1795 | 1795 | $invoice = wpinv_get_invoice_cart(); |
1796 | 1796 | $amount = $invoice->get_total(); |
1797 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
1798 | - $no_vat = !self::requires_vat( 0, false, $is_digital ); |
|
1797 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
1798 | + $no_vat = !self::requires_vat(0, false, $is_digital); |
|
1799 | 1799 | |
1800 | - $company = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null; |
|
1801 | - $vat_number = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null; |
|
1802 | - $country = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country; |
|
1803 | - if ( empty( $country ) ) { |
|
1800 | + $company = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null; |
|
1801 | + $vat_number = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null; |
|
1802 | + $country = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country; |
|
1803 | + if (empty($country)) { |
|
1804 | 1804 | $country = wpinv_default_billing_country(); |
1805 | 1805 | } |
1806 | 1806 | |
1807 | - if ( !$is_digital && $no_vat ) { |
|
1807 | + if (!$is_digital && $no_vat) { |
|
1808 | 1808 | return; |
1809 | 1809 | } |
1810 | 1810 | |
1811 | - $vat_data = array( 'company' => '', 'number' => '', 'valid' => false ); |
|
1811 | + $vat_data = array('company' => '', 'number' => '', 'valid' => false); |
|
1812 | 1812 | |
1813 | 1813 | $ip_country_code = self::get_country_by_ip(); |
1814 | - $is_eu_state = self::is_eu_state( $country ); |
|
1815 | - $is_eu_state_ip = self::is_eu_state( $ip_country_code ); |
|
1814 | + $is_eu_state = self::is_eu_state($country); |
|
1815 | + $is_eu_state_ip = self::is_eu_state($ip_country_code); |
|
1816 | 1816 | $is_non_eu_user = !$is_eu_state && !$is_eu_state_ip; |
1817 | 1817 | |
1818 | - if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) { |
|
1818 | + if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) { |
|
1819 | 1819 | $vat_data['adddress_confirmed'] = false; |
1820 | 1820 | |
1821 | - if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) { |
|
1822 | - if ( $ip_country_code != $country ) { |
|
1823 | - wpinv_set_error( 'vat_validation', sprintf( __( 'The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing' ), '<a href="#wpinv_adddress_confirm">', '</a>' ) ); |
|
1821 | + if (!isset($_POST['wpinv_adddress_confirmed'])) { |
|
1822 | + if ($ip_country_code != $country) { |
|
1823 | + wpinv_set_error('vat_validation', sprintf(__('The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing'), '<a href="#wpinv_adddress_confirm">', '</a>')); |
|
1824 | 1824 | } |
1825 | 1825 | } else { |
1826 | 1826 | $vat_data['adddress_confirmed'] = true; |
1827 | 1827 | } |
1828 | 1828 | } |
1829 | 1829 | |
1830 | - if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) { |
|
1831 | - if ( $is_eu_state ) { |
|
1832 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing' ), $vat_name ) ); |
|
1833 | - } else if ( $is_digital && $is_eu_state_ip ) { |
|
1834 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) ); |
|
1830 | + if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) { |
|
1831 | + if ($is_eu_state) { |
|
1832 | + wpinv_set_error('vat_validation', wp_sprintf(__('Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing'), $vat_name)); |
|
1833 | + } else if ($is_digital && $is_eu_state_ip) { |
|
1834 | + wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name)); |
|
1835 | 1835 | } |
1836 | 1836 | } |
1837 | 1837 | |
1838 | - if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) { |
|
1838 | + if (!$is_eu_state || $no_vat || empty($vat_number)) { |
|
1839 | 1839 | return; |
1840 | 1840 | } |
1841 | 1841 | |
1842 | - if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) { |
|
1843 | - $vat_data['valid'] = $vat_saved['valid']; |
|
1842 | + if (!empty($vat_saved) && isset($vat_saved['valid'])) { |
|
1843 | + $vat_data['valid'] = $vat_saved['valid']; |
|
1844 | 1844 | } |
1845 | 1845 | |
1846 | - if ( $company !== null ) { |
|
1846 | + if ($company !== null) { |
|
1847 | 1847 | $vat_data['company'] = $company; |
1848 | 1848 | } |
1849 | 1849 | |
1850 | 1850 | $message = ''; |
1851 | - if ( $vat_number !== null ) { |
|
1851 | + if ($vat_number !== null) { |
|
1852 | 1852 | $vat_data['number'] = $vat_number; |
1853 | 1853 | |
1854 | - if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) { |
|
1855 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
1856 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
1854 | + if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) { |
|
1855 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
1856 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
1857 | 1857 | $vat_data['valid'] = false; |
1858 | 1858 | } |
1859 | 1859 | } else { |
1860 | - $result = self::check_vat( $vat_number ); |
|
1860 | + $result = self::check_vat($vat_number); |
|
1861 | 1861 | |
1862 | - if ( !empty( $result['valid'] ) ) { |
|
1862 | + if (!empty($result['valid'])) { |
|
1863 | 1863 | $vat_data['valid'] = true; |
1864 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
1865 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
1864 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
1865 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
1866 | 1866 | |
1867 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
1867 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
1868 | 1868 | |
1869 | - if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) { |
|
1869 | + if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) { |
|
1870 | 1870 | $vat_data['valid'] = false; |
1871 | 1871 | |
1872 | - $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name ); |
|
1872 | + $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name); |
|
1873 | 1873 | } |
1874 | 1874 | } else { |
1875 | - $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
1875 | + $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
1876 | 1876 | } |
1877 | 1877 | } |
1878 | 1878 | |
1879 | - if ( !$vat_data['valid'] ) { |
|
1880 | - $error = wp_sprintf( __( 'The %s %s number %s you have entered has not been validated', 'invoicing' ), '<a href="#wpi-vat-details">', $vat_name, '</a>' ) . ( $message ? ' ( ' . $message . ' )' : '' ); |
|
1881 | - wpinv_set_error( 'vat_validation', $error ); |
|
1879 | + if (!$vat_data['valid']) { |
|
1880 | + $error = wp_sprintf(__('The %s %s number %s you have entered has not been validated', 'invoicing'), '<a href="#wpi-vat-details">', $vat_name, '</a>') . ($message ? ' ( ' . $message . ' )' : ''); |
|
1881 | + wpinv_set_error('vat_validation', $error); |
|
1882 | 1882 | } |
1883 | 1883 | } |
1884 | 1884 | } |
1885 | 1885 | |
1886 | - $wpi_session->set( 'user_vat_data', $vat_data ); |
|
1886 | + $wpi_session->set('user_vat_data', $vat_data); |
|
1887 | 1887 | } |
1888 | 1888 | |
1889 | - public static function checkout_vat_fields( $billing_details ) { |
|
1889 | + public static function checkout_vat_fields($billing_details) { |
|
1890 | 1890 | global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat; |
1891 | 1891 | |
1892 | 1892 | $ip_address = wpinv_get_ip(); |
1893 | 1893 | $ip_country_code = self::get_country_by_ip(); |
1894 | 1894 | |
1895 | - $tax_label = __( self::get_vat_name(), 'invoicing' ); |
|
1895 | + $tax_label = __(self::get_vat_name(), 'invoicing'); |
|
1896 | 1896 | $invoice = wpinv_get_invoice_cart(); |
1897 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
1897 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
1898 | 1898 | $wpi_country = $invoice->country; |
1899 | 1899 | |
1900 | - $requires_vat = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat( 0, false, $is_digital ); |
|
1900 | + $requires_vat = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat(0, false, $is_digital); |
|
1901 | 1901 | $wpi_requires_vat = $requires_vat; |
1902 | 1902 | |
1903 | 1903 | $company = self::get_user_company(); |
1904 | 1904 | $vat_number = self::get_user_vat_number(); |
1905 | 1905 | |
1906 | - $validated = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1; |
|
1907 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1906 | + $validated = $vat_number ? self::get_user_vat_number('', 0, true) : 1; |
|
1907 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1908 | 1908 | |
1909 | - if ( is_array( $vat_info ) ) { |
|
1910 | - $company = isset( $vat_info['company'] ) ? $vat_info['company'] : ''; |
|
1911 | - $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : ''; |
|
1912 | - $validated = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false; |
|
1909 | + if (is_array($vat_info)) { |
|
1910 | + $company = isset($vat_info['company']) ? $vat_info['company'] : ''; |
|
1911 | + $vat_number = isset($vat_info['number']) ? $vat_info['number'] : ''; |
|
1912 | + $validated = isset($vat_info['valid']) ? $vat_info['valid'] : false; |
|
1913 | 1913 | } |
1914 | 1914 | |
1915 | 1915 | $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country(); |
1916 | 1916 | |
1917 | - if ( $ip_country_code == 'UK' ) { |
|
1917 | + if ($ip_country_code == 'UK') { |
|
1918 | 1918 | $ip_country_code = 'GB'; |
1919 | 1919 | } |
1920 | 1920 | |
1921 | - if ( $selected_country == 'UK' ) { |
|
1921 | + if ($selected_country == 'UK') { |
|
1922 | 1922 | $selected_country = 'GB'; |
1923 | 1923 | } |
1924 | 1924 | |
1925 | - if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) { |
|
1925 | + if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) { |
|
1926 | 1926 | $requires_vat = false; |
1927 | 1927 | } |
1928 | 1928 | |
@@ -1930,52 +1930,52 @@ discard block |
||
1930 | 1930 | $display_validate_btn = 'none'; |
1931 | 1931 | $display_reset_btn = 'none'; |
1932 | 1932 | |
1933 | - if ( !empty( $vat_number ) && $validated ) { |
|
1934 | - $vat_vailidated_text = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label ); |
|
1933 | + if (!empty($vat_number) && $validated) { |
|
1934 | + $vat_vailidated_text = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label); |
|
1935 | 1935 | $vat_vailidated_class = 'wpinv-vat-stat-1'; |
1936 | 1936 | $display_reset_btn = 'block'; |
1937 | 1937 | } else { |
1938 | - $vat_vailidated_text = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label ); |
|
1939 | - $vat_vailidated_class = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0'; |
|
1938 | + $vat_vailidated_text = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label); |
|
1939 | + $vat_vailidated_class = empty($vat_number) ? '' : 'wpinv-vat-stat-0'; |
|
1940 | 1940 | $display_validate_btn = 'block'; |
1941 | 1941 | } |
1942 | 1942 | |
1943 | - $show_ip_country = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
1943 | + $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
1944 | 1944 | ?> |
1945 | 1945 | <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>"> |
1946 | 1946 | <div id="wpi_vat_info" class="clearfix panel panel-default"> |
1947 | - <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div> |
|
1947 | + <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div> |
|
1948 | 1948 | <div id="wpinv-fields-box" class="panel-body"> |
1949 | 1949 | <p id="wpi_show_vat_note"> |
1950 | - <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?> |
|
1950 | + <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?> |
|
1951 | 1951 | </p> |
1952 | 1952 | <div id="wpi_vat_fields" class="wpi_vat_info"> |
1953 | 1953 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1954 | - <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label> |
|
1954 | + <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label> |
|
1955 | 1955 | <?php |
1956 | - echo wpinv_html_text( array( |
|
1956 | + echo wpinv_html_text(array( |
|
1957 | 1957 | 'id' => 'wpinv_company', |
1958 | 1958 | 'name' => 'wpinv_company', |
1959 | 1959 | 'value' => $company, |
1960 | 1960 | 'class' => 'wpi-input form-control', |
1961 | - 'placeholder' => __( 'Company name', 'invoicing' ), |
|
1962 | - ) ); |
|
1961 | + 'placeholder' => __('Company name', 'invoicing'), |
|
1962 | + )); |
|
1963 | 1963 | ?> |
1964 | 1964 | </p> |
1965 | 1965 | <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat"> |
1966 | - <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label> |
|
1966 | + <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label> |
|
1967 | 1967 | <span id="wpinv_vat_number-wrap"> |
1968 | 1968 | <label for="wpinv_vat_number" class="wpinv-label"></label> |
1969 | - <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr( wp_sprintf( __( '%s number', 'invoicing' ), $tax_label ) );?>" value="<?php esc_attr_e( $vat_number );?>" id="wpinv_vat_number" name="wpinv_vat_number"> |
|
1970 | - <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text;?></font></span> |
|
1969 | + <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr(wp_sprintf(__('%s number', 'invoicing'), $tax_label)); ?>" value="<?php esc_attr_e($vat_number); ?>" id="wpinv_vat_number" name="wpinv_vat_number"> |
|
1970 | + <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text; ?></font></span> |
|
1971 | 1971 | </span> |
1972 | 1972 | </p> |
1973 | 1973 | <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions"> |
1974 | - <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf( __("Validate %s Number", 'invoicing'), $tax_label ); ?></button> |
|
1975 | - <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf( __("Reset %s", 'invoicing'), $tax_label ); ?></button> |
|
1974 | + <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf(__("Validate %s Number", 'invoicing'), $tax_label); ?></button> |
|
1975 | + <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf(__("Reset %s", 'invoicing'), $tax_label); ?></button> |
|
1976 | 1976 | <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span> |
1977 | 1977 | <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span> |
1978 | - <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" /> |
|
1978 | + <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" /> |
|
1979 | 1979 | </p> |
1980 | 1980 | </div> |
1981 | 1981 | </div> |
@@ -1989,32 +1989,32 @@ discard block |
||
1989 | 1989 | </span> |
1990 | 1990 | </div> |
1991 | 1991 | </div> |
1992 | - <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { |
|
1993 | - $ip_link = '<a title="' . esc_attr( __( 'View more details on map', 'invoicing' ) ) . '" target="_blank" href="' . esc_url( admin_url( 'admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address ) ) . '" class="wpi-ip-address-link">' . $ip_address . ' <i class="fa fa-external-link-square" aria-hidden="true"></i></a>'; |
|
1992 | + <?php if (empty($wpinv_options['hide_ip_address'])) { |
|
1993 | + $ip_link = '<a title="' . esc_attr(__('View more details on map', 'invoicing')) . '" target="_blank" href="' . esc_url(admin_url('admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address)) . '" class="wpi-ip-address-link">' . $ip_address . ' <i class="fa fa-external-link-square" aria-hidden="true"></i></a>'; |
|
1994 | 1994 | ?> |
1995 | 1995 | <div class="wpi-ip-info clearfix panel panel-info"> |
1996 | 1996 | <div id="wpinv-fields-box" class="panel-body"> |
1997 | - <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span> |
|
1997 | + <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span> |
|
1998 | 1998 | </div> |
1999 | 1999 | </div> |
2000 | 2000 | <?php } |
2001 | 2001 | } |
2002 | 2002 | |
2003 | - public static function show_vat_notice( $invoice ) { |
|
2004 | - if ( empty( $invoice ) ) { |
|
2003 | + public static function show_vat_notice($invoice) { |
|
2004 | + if (empty($invoice)) { |
|
2005 | 2005 | return NULL; |
2006 | 2006 | } |
2007 | 2007 | |
2008 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
2009 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
2010 | - if ( $label || $notice ) { |
|
2008 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
2009 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
2010 | + if ($label || $notice) { |
|
2011 | 2011 | ?> |
2012 | 2012 | <div class="row wpinv-vat-notice"> |
2013 | 2013 | <div class="col-sm-12"> |
2014 | - <?php if ( $label ) { ?> |
|
2015 | - <strong><?php _e( $label, 'invoicing' ); ?></strong> |
|
2016 | - <?php } if ( $notice ) { ?> |
|
2017 | - <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?> |
|
2014 | + <?php if ($label) { ?> |
|
2015 | + <strong><?php _e($label, 'invoicing'); ?></strong> |
|
2016 | + <?php } if ($notice) { ?> |
|
2017 | + <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?> |
|
2018 | 2018 | <?php } ?> |
2019 | 2019 | </div> |
2020 | 2020 | </div> |
@@ -7,28 +7,28 @@ 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 | class WPInv_Ajax { |
15 | 15 | public static function init() { |
16 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
17 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
16 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
17 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
18 | 18 | self::add_ajax_events(); |
19 | 19 | } |
20 | 20 | |
21 | 21 | public static function define_ajax() { |
22 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
23 | - if ( ! defined( 'DOING_AJAX' ) ) { |
|
24 | - define( 'DOING_AJAX', true ); |
|
22 | + if (!empty($_GET['wpinv-ajax'])) { |
|
23 | + if (!defined('DOING_AJAX')) { |
|
24 | + define('DOING_AJAX', true); |
|
25 | 25 | } |
26 | - if ( ! defined( 'WC_DOING_AJAX' ) ) { |
|
27 | - define( 'WC_DOING_AJAX', true ); |
|
26 | + if (!defined('WC_DOING_AJAX')) { |
|
27 | + define('WC_DOING_AJAX', true); |
|
28 | 28 | } |
29 | 29 | // Turn off display_errors during AJAX events to prevent malformed JSON |
30 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
31 | - @ini_set( 'display_errors', 0 ); |
|
30 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
31 | + @ini_set('display_errors', 0); |
|
32 | 32 | } |
33 | 33 | $GLOBALS['wpdb']->hide_errors(); |
34 | 34 | } |
@@ -37,24 +37,24 @@ discard block |
||
37 | 37 | public static function do_wpinv_ajax() { |
38 | 38 | global $wp_query; |
39 | 39 | |
40 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
41 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) ); |
|
40 | + if (!empty($_GET['wpinv-ajax'])) { |
|
41 | + $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax'])); |
|
42 | 42 | } |
43 | 43 | |
44 | - if ( $action = $wp_query->get( 'wpinv-ajax' ) ) { |
|
44 | + if ($action = $wp_query->get('wpinv-ajax')) { |
|
45 | 45 | self::wpinv_ajax_headers(); |
46 | - do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) ); |
|
46 | + do_action('wpinv_ajax_' . sanitize_text_field($action)); |
|
47 | 47 | die(); |
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | 51 | private static function wpinv_ajax_headers() { |
52 | 52 | send_origin_headers(); |
53 | - @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
54 | - @header( 'X-Robots-Tag: noindex' ); |
|
53 | + @header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
54 | + @header('X-Robots-Tag: noindex'); |
|
55 | 55 | send_nosniff_header(); |
56 | 56 | nocache_headers(); |
57 | - status_header( 200 ); |
|
57 | + status_header(200); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | public static function add_ajax_events() { |
@@ -77,39 +77,39 @@ discard block |
||
77 | 77 | 'buy_items' => true, |
78 | 78 | ); |
79 | 79 | |
80 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
81 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
80 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
81 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
82 | 82 | |
83 | - if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) { |
|
84 | - define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 ); |
|
83 | + if (!defined('WPI_AJAX_' . strtoupper($nopriv))) { |
|
84 | + define('WPI_AJAX_' . strtoupper($nopriv), 1); |
|
85 | 85 | } |
86 | 86 | |
87 | - if ( $nopriv ) { |
|
88 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
87 | + if ($nopriv) { |
|
88 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
89 | 89 | |
90 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
90 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | 95 | public static function add_note() { |
96 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
96 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
97 | 97 | |
98 | - if ( !current_user_can( 'manage_options' ) ) { |
|
98 | + if (!current_user_can('manage_options')) { |
|
99 | 99 | die(-1); |
100 | 100 | } |
101 | 101 | |
102 | - $post_id = absint( $_POST['post_id'] ); |
|
103 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
104 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
102 | + $post_id = absint($_POST['post_id']); |
|
103 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
104 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
105 | 105 | |
106 | 106 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
107 | 107 | |
108 | - if ( $post_id > 0 ) { |
|
109 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
108 | + if ($post_id > 0) { |
|
109 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
110 | 110 | |
111 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
112 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
111 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
112 | + wpinv_get_invoice_note_line_item($note_id); |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
@@ -117,16 +117,16 @@ discard block |
||
117 | 117 | } |
118 | 118 | |
119 | 119 | public static function delete_note() { |
120 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
120 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
121 | 121 | |
122 | - if ( !current_user_can( 'manage_options' ) ) { |
|
122 | + if (!current_user_can('manage_options')) { |
|
123 | 123 | die(-1); |
124 | 124 | } |
125 | 125 | |
126 | 126 | $note_id = (int)$_POST['note_id']; |
127 | 127 | |
128 | - if ( $note_id > 0 ) { |
|
129 | - wp_delete_comment( $note_id, true ); |
|
128 | + if ($note_id > 0) { |
|
129 | + wp_delete_comment($note_id, true); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | die(); |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | public static function checkout() { |
142 | - if ( ! defined( 'WPINV_CHECKOUT' ) ) { |
|
143 | - define( 'WPINV_CHECKOUT', true ); |
|
142 | + if (!defined('WPINV_CHECKOUT')) { |
|
143 | + define('WPINV_CHECKOUT', true); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | wpinv_process_checkout(); |
@@ -149,53 +149,53 @@ discard block |
||
149 | 149 | |
150 | 150 | public static function add_invoice_item() { |
151 | 151 | global $wpi_userID, $wpinv_ip_address_country; |
152 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
153 | - if ( !current_user_can( 'manage_options' ) ) { |
|
152 | + check_ajax_referer('invoice-item', '_nonce'); |
|
153 | + if (!current_user_can('manage_options')) { |
|
154 | 154 | die(-1); |
155 | 155 | } |
156 | 156 | |
157 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
158 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
157 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
158 | + $invoice_id = absint($_POST['invoice_id']); |
|
159 | 159 | |
160 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
160 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
161 | 161 | die(); |
162 | 162 | } |
163 | 163 | |
164 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
165 | - if ( empty( $invoice ) ) { |
|
164 | + $invoice = wpinv_get_invoice($invoice_id); |
|
165 | + if (empty($invoice)) { |
|
166 | 166 | die(); |
167 | 167 | } |
168 | 168 | |
169 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
169 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
170 | 170 | die(); // Don't allow modify items for paid invoice. |
171 | 171 | } |
172 | 172 | |
173 | - if ( !empty( $_POST['user_id'] ) ) { |
|
174 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
173 | + if (!empty($_POST['user_id'])) { |
|
174 | + $wpi_userID = absint($_POST['user_id']); |
|
175 | 175 | } |
176 | 176 | |
177 | - $item = new WPInv_Item( $item_id ); |
|
178 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
177 | + $item = new WPInv_Item($item_id); |
|
178 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
179 | 179 | die(); |
180 | 180 | } |
181 | 181 | |
182 | 182 | // Validate item before adding to invoice because recurring item must be paid individually. |
183 | - if ( !empty( $invoice->cart_details ) ) { |
|
183 | + if (!empty($invoice->cart_details)) { |
|
184 | 184 | $valid = true; |
185 | 185 | |
186 | - if ( $recurring_item = $invoice->get_recurring() ) { |
|
187 | - if ( $recurring_item != $item_id ) { |
|
186 | + if ($recurring_item = $invoice->get_recurring()) { |
|
187 | + if ($recurring_item != $item_id) { |
|
188 | 188 | $valid = false; |
189 | 189 | } |
190 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
190 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
191 | 191 | $valid = false; |
192 | 192 | } |
193 | 193 | |
194 | - if ( !$valid ) { |
|
194 | + if (!$valid) { |
|
195 | 195 | $response = array(); |
196 | 196 | $response['success'] = false; |
197 | - $response['msg'] = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' ); |
|
198 | - wp_send_json( $response ); |
|
197 | + $response['msg'] = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing'); |
|
198 | + wp_send_json($response); |
|
199 | 199 | } |
200 | 200 | } |
201 | 201 | |
@@ -203,9 +203,9 @@ discard block |
||
203 | 203 | |
204 | 204 | $data = array(); |
205 | 205 | $data['invoice_id'] = $invoice_id; |
206 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
206 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
207 | 207 | |
208 | - wpinv_set_checkout_session( $data ); |
|
208 | + wpinv_set_checkout_session($data); |
|
209 | 209 | |
210 | 210 | $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1; |
211 | 211 | |
@@ -220,21 +220,21 @@ discard block |
||
220 | 220 | 'fees' => array() |
221 | 221 | ); |
222 | 222 | |
223 | - $invoice->add_item( $item_id, $args ); |
|
223 | + $invoice->add_item($item_id, $args); |
|
224 | 224 | $invoice->save(); |
225 | 225 | |
226 | - if ( empty( $_POST['country'] ) ) { |
|
226 | + if (empty($_POST['country'])) { |
|
227 | 227 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
228 | 228 | } |
229 | - if ( empty( $_POST['state'] ) ) { |
|
229 | + if (empty($_POST['state'])) { |
|
230 | 230 | $_POST['state'] = $invoice->state; |
231 | 231 | } |
232 | 232 | |
233 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
234 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
233 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
234 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
235 | 235 | |
236 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
237 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
236 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
237 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
238 | 238 | |
239 | 239 | $wpinv_ip_address_country = $invoice->country; |
240 | 240 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | |
243 | 243 | $response = array(); |
244 | 244 | $response['success'] = true; |
245 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
245 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
246 | 246 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
247 | 247 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
248 | 248 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -254,40 +254,40 @@ discard block |
||
254 | 254 | |
255 | 255 | wpinv_set_checkout_session($checkout_session); |
256 | 256 | |
257 | - wp_send_json( $response ); |
|
257 | + wp_send_json($response); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | public static function remove_invoice_item() { |
261 | 261 | global $wpi_userID, $wpinv_ip_address_country; |
262 | 262 | |
263 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
264 | - if ( !current_user_can( 'manage_options' ) ) { |
|
263 | + check_ajax_referer('invoice-item', '_nonce'); |
|
264 | + if (!current_user_can('manage_options')) { |
|
265 | 265 | die(-1); |
266 | 266 | } |
267 | 267 | |
268 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
269 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
270 | - $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
268 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
269 | + $invoice_id = absint($_POST['invoice_id']); |
|
270 | + $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
271 | 271 | |
272 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
272 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
273 | 273 | die(); |
274 | 274 | } |
275 | 275 | |
276 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
277 | - if ( empty( $invoice ) ) { |
|
276 | + $invoice = wpinv_get_invoice($invoice_id); |
|
277 | + if (empty($invoice)) { |
|
278 | 278 | die(); |
279 | 279 | } |
280 | 280 | |
281 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
281 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
282 | 282 | die(); // Don't allow modify items for paid invoice. |
283 | 283 | } |
284 | 284 | |
285 | - if ( !empty( $_POST['user_id'] ) ) { |
|
286 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
285 | + if (!empty($_POST['user_id'])) { |
|
286 | + $wpi_userID = absint($_POST['user_id']); |
|
287 | 287 | } |
288 | 288 | |
289 | - $item = new WPInv_Item( $item_id ); |
|
290 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
289 | + $item = new WPInv_Item($item_id); |
|
290 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
291 | 291 | die(); |
292 | 292 | } |
293 | 293 | |
@@ -295,9 +295,9 @@ discard block |
||
295 | 295 | |
296 | 296 | $data = array(); |
297 | 297 | $data['invoice_id'] = $invoice_id; |
298 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
298 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
299 | 299 | |
300 | - wpinv_set_checkout_session( $data ); |
|
300 | + wpinv_set_checkout_session($data); |
|
301 | 301 | |
302 | 302 | $args = array( |
303 | 303 | 'id' => $item_id, |
@@ -305,21 +305,21 @@ discard block |
||
305 | 305 | 'cart_index' => $cart_index |
306 | 306 | ); |
307 | 307 | |
308 | - $invoice->remove_item( $item_id, $args ); |
|
308 | + $invoice->remove_item($item_id, $args); |
|
309 | 309 | $invoice->save(); |
310 | 310 | |
311 | - if ( empty( $_POST['country'] ) ) { |
|
311 | + if (empty($_POST['country'])) { |
|
312 | 312 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
313 | 313 | } |
314 | - if ( empty( $_POST['state'] ) ) { |
|
314 | + if (empty($_POST['state'])) { |
|
315 | 315 | $_POST['state'] = $invoice->state; |
316 | 316 | } |
317 | 317 | |
318 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
319 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
318 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
319 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
320 | 320 | |
321 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
322 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
321 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
322 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
323 | 323 | |
324 | 324 | $wpinv_ip_address_country = $invoice->country; |
325 | 325 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | |
328 | 328 | $response = array(); |
329 | 329 | $response['success'] = true; |
330 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
330 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
331 | 331 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
332 | 332 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
333 | 333 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -339,40 +339,40 @@ discard block |
||
339 | 339 | |
340 | 340 | wpinv_set_checkout_session($checkout_session); |
341 | 341 | |
342 | - wp_send_json( $response ); |
|
342 | + wp_send_json($response); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | public static function create_invoice_item() { |
346 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
347 | - if ( !current_user_can( 'manage_options' ) ) { |
|
346 | + check_ajax_referer('invoice-item', '_nonce'); |
|
347 | + if (!current_user_can('manage_options')) { |
|
348 | 348 | die(-1); |
349 | 349 | } |
350 | 350 | |
351 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
351 | + $invoice_id = absint($_POST['invoice_id']); |
|
352 | 352 | |
353 | 353 | // Find the item |
354 | - if ( !is_numeric( $invoice_id ) ) { |
|
354 | + if (!is_numeric($invoice_id)) { |
|
355 | 355 | die(); |
356 | 356 | } |
357 | 357 | |
358 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
359 | - if ( empty( $invoice ) ) { |
|
358 | + $invoice = wpinv_get_invoice($invoice_id); |
|
359 | + if (empty($invoice)) { |
|
360 | 360 | die(); |
361 | 361 | } |
362 | 362 | |
363 | 363 | // Validate item before adding to invoice because recurring item must be paid individually. |
364 | - if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) { |
|
364 | + if (!empty($invoice->cart_details) && $invoice->get_recurring()) { |
|
365 | 365 | $response = array(); |
366 | 366 | $response['success'] = false; |
367 | - $response['msg'] = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' ); |
|
368 | - wp_send_json( $response ); |
|
367 | + $response['msg'] = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing'); |
|
368 | + wp_send_json($response); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | $save_item = $_POST['_wpinv_quick']; |
372 | 372 | |
373 | 373 | $meta = array(); |
374 | 374 | $meta['type'] = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom'; |
375 | - $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0; |
|
375 | + $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0; |
|
376 | 376 | $meta['vat_rule'] = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital'; |
377 | 377 | $meta['vat_class'] = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard'; |
378 | 378 | |
@@ -382,9 +382,9 @@ discard block |
||
382 | 382 | $data['meta'] = $meta; |
383 | 383 | |
384 | 384 | $item = new WPInv_Item(); |
385 | - $item->create( $data ); |
|
385 | + $item->create($data); |
|
386 | 386 | |
387 | - if ( !empty( $item ) ) { |
|
387 | + if (!empty($item)) { |
|
388 | 388 | $_POST['item_id'] = $item->ID; |
389 | 389 | $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1; |
390 | 390 | |
@@ -394,15 +394,15 @@ discard block |
||
394 | 394 | } |
395 | 395 | |
396 | 396 | public static function get_billing_details() { |
397 | - check_ajax_referer( 'get-billing-details', '_nonce' ); |
|
397 | + check_ajax_referer('get-billing-details', '_nonce'); |
|
398 | 398 | |
399 | - if ( !current_user_can( 'manage_options' ) ) { |
|
399 | + if (!current_user_can('manage_options')) { |
|
400 | 400 | die(-1); |
401 | 401 | } |
402 | 402 | |
403 | 403 | $user_id = (int)$_POST['user_id']; |
404 | 404 | $billing_details = wpinv_get_user_address($user_id); |
405 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
405 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
406 | 406 | |
407 | 407 | if (isset($billing_details['user_id'])) { |
408 | 408 | unset($billing_details['user_id']); |
@@ -416,20 +416,20 @@ discard block |
||
416 | 416 | $response['success'] = true; |
417 | 417 | $response['data']['billing_details'] = $billing_details; |
418 | 418 | |
419 | - wp_send_json( $response ); |
|
419 | + wp_send_json($response); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | public static function admin_recalculate_totals() { |
423 | 423 | global $wpi_userID, $wpinv_ip_address_country; |
424 | 424 | |
425 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
426 | - if ( !current_user_can( 'manage_options' ) ) { |
|
425 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
426 | + if (!current_user_can('manage_options')) { |
|
427 | 427 | die(-1); |
428 | 428 | } |
429 | 429 | |
430 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
431 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
432 | - if ( empty( $invoice ) ) { |
|
430 | + $invoice_id = absint($_POST['invoice_id']); |
|
431 | + $invoice = wpinv_get_invoice($invoice_id); |
|
432 | + if (empty($invoice)) { |
|
433 | 433 | die(); |
434 | 434 | } |
435 | 435 | |
@@ -437,23 +437,23 @@ discard block |
||
437 | 437 | |
438 | 438 | $data = array(); |
439 | 439 | $data['invoice_id'] = $invoice_id; |
440 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
440 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
441 | 441 | |
442 | - wpinv_set_checkout_session( $data ); |
|
442 | + wpinv_set_checkout_session($data); |
|
443 | 443 | |
444 | - if ( !empty( $_POST['user_id'] ) ) { |
|
445 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
444 | + if (!empty($_POST['user_id'])) { |
|
445 | + $wpi_userID = absint($_POST['user_id']); |
|
446 | 446 | } |
447 | 447 | |
448 | - if ( empty( $_POST['country'] ) ) { |
|
448 | + if (empty($_POST['country'])) { |
|
449 | 449 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
450 | 450 | } |
451 | 451 | |
452 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
453 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
454 | - if ( isset( $_POST['state'] ) ) { |
|
455 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
456 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
452 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
453 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
454 | + if (isset($_POST['state'])) { |
|
455 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
456 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | $wpinv_ip_address_country = $invoice->country; |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | |
463 | 463 | $response = array(); |
464 | 464 | $response['success'] = true; |
465 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
465 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
466 | 466 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
467 | 467 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
468 | 468 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -474,25 +474,25 @@ discard block |
||
474 | 474 | |
475 | 475 | wpinv_set_checkout_session($checkout_session); |
476 | 476 | |
477 | - wp_send_json( $response ); |
|
477 | + wp_send_json($response); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | public static function admin_apply_discount() { |
481 | 481 | global $wpi_userID; |
482 | 482 | |
483 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
484 | - if ( !current_user_can( 'manage_options' ) ) { |
|
483 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
484 | + if (!current_user_can('manage_options')) { |
|
485 | 485 | die(-1); |
486 | 486 | } |
487 | 487 | |
488 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
489 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
490 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
488 | + $invoice_id = absint($_POST['invoice_id']); |
|
489 | + $discount_code = sanitize_text_field($_POST['code']); |
|
490 | + if (empty($invoice_id) || empty($discount_code)) { |
|
491 | 491 | die(); |
492 | 492 | } |
493 | 493 | |
494 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
495 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
494 | + $invoice = wpinv_get_invoice($invoice_id); |
|
495 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
496 | 496 | die(); |
497 | 497 | } |
498 | 498 | |
@@ -500,49 +500,49 @@ discard block |
||
500 | 500 | |
501 | 501 | $data = array(); |
502 | 502 | $data['invoice_id'] = $invoice_id; |
503 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
503 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
504 | 504 | |
505 | - wpinv_set_checkout_session( $data ); |
|
505 | + wpinv_set_checkout_session($data); |
|
506 | 506 | |
507 | 507 | $response = array(); |
508 | 508 | $response['success'] = false; |
509 | - $response['msg'] = __( 'This discount is invalid.', 'invoicing' ); |
|
509 | + $response['msg'] = __('This discount is invalid.', 'invoicing'); |
|
510 | 510 | $response['data']['code'] = $discount_code; |
511 | 511 | |
512 | - if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) { |
|
513 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
512 | + if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) { |
|
513 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
514 | 514 | |
515 | 515 | $response['success'] = true; |
516 | - $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' ); |
|
517 | - } else { |
|
516 | + $response['msg'] = __('Discount has been applied successfully.', 'invoicing'); |
|
517 | + } else { |
|
518 | 518 | $errors = wpinv_get_errors(); |
519 | - if ( !empty( $errors['wpinv-discount-error'] ) ) { |
|
519 | + if (!empty($errors['wpinv-discount-error'])) { |
|
520 | 520 | $response['msg'] = $errors['wpinv-discount-error']; |
521 | 521 | } |
522 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
522 | + wpinv_unset_error('wpinv-discount-error'); |
|
523 | 523 | } |
524 | 524 | |
525 | 525 | wpinv_set_checkout_session($checkout_session); |
526 | 526 | |
527 | - wp_send_json( $response ); |
|
527 | + wp_send_json($response); |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | public static function admin_remove_discount() { |
531 | 531 | global $wpi_userID; |
532 | 532 | |
533 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
534 | - if ( !current_user_can( 'manage_options' ) ) { |
|
533 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
534 | + if (!current_user_can('manage_options')) { |
|
535 | 535 | die(-1); |
536 | 536 | } |
537 | 537 | |
538 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
539 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
540 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
538 | + $invoice_id = absint($_POST['invoice_id']); |
|
539 | + $discount_code = sanitize_text_field($_POST['code']); |
|
540 | + if (empty($invoice_id) || empty($discount_code)) { |
|
541 | 541 | die(); |
542 | 542 | } |
543 | 543 | |
544 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
545 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
544 | + $invoice = wpinv_get_invoice($invoice_id); |
|
545 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
546 | 546 | die(); |
547 | 547 | } |
548 | 548 | |
@@ -550,38 +550,38 @@ discard block |
||
550 | 550 | |
551 | 551 | $data = array(); |
552 | 552 | $data['invoice_id'] = $invoice_id; |
553 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
553 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
554 | 554 | |
555 | - wpinv_set_checkout_session( $data ); |
|
555 | + wpinv_set_checkout_session($data); |
|
556 | 556 | |
557 | 557 | $response = array(); |
558 | 558 | $response['success'] = false; |
559 | 559 | $response['msg'] = NULL; |
560 | 560 | |
561 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
561 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
562 | 562 | $response['success'] = true; |
563 | - $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' ); |
|
563 | + $response['msg'] = __('Discount has been removed successfully.', 'invoicing'); |
|
564 | 564 | |
565 | 565 | wpinv_set_checkout_session($checkout_session); |
566 | 566 | |
567 | - wp_send_json( $response ); |
|
567 | + wp_send_json($response); |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | public static function check_email() { |
571 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
572 | - if ( !current_user_can( 'manage_options' ) ) { |
|
571 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
572 | + if (!current_user_can('manage_options')) { |
|
573 | 573 | die(-1); |
574 | 574 | } |
575 | 575 | |
576 | - $email = sanitize_text_field( $_POST['email'] ); |
|
576 | + $email = sanitize_text_field($_POST['email']); |
|
577 | 577 | |
578 | 578 | $response = array(); |
579 | - if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) { |
|
579 | + if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) { |
|
580 | 580 | $user_id = $user_data->ID; |
581 | 581 | $user_login = $user_data->user_login; |
582 | 582 | $display_name = $user_data->display_name ? $user_data->display_name : $user_login; |
583 | 583 | $billing_details = wpinv_get_user_address($user_id); |
584 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
584 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
585 | 585 | |
586 | 586 | if (isset($billing_details['user_id'])) { |
587 | 587 | unset($billing_details['user_id']); |
@@ -597,54 +597,54 @@ discard block |
||
597 | 597 | $response['data']['billing_details'] = $billing_details; |
598 | 598 | } |
599 | 599 | |
600 | - wp_send_json( $response ); |
|
600 | + wp_send_json($response); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | public static function run_tool() { |
604 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
605 | - if ( !current_user_can( 'manage_options' ) ) { |
|
604 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
605 | + if (!current_user_can('manage_options')) { |
|
606 | 606 | die(-1); |
607 | 607 | } |
608 | 608 | |
609 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
609 | + $tool = sanitize_text_field($_POST['tool']); |
|
610 | 610 | |
611 | - do_action( 'wpinv_run_tool' ); |
|
611 | + do_action('wpinv_run_tool'); |
|
612 | 612 | |
613 | - if ( !empty( $tool ) ) { |
|
614 | - do_action( 'wpinv_tool_' . $tool ); |
|
613 | + if (!empty($tool)) { |
|
614 | + do_action('wpinv_tool_' . $tool); |
|
615 | 615 | } |
616 | 616 | } |
617 | 617 | |
618 | 618 | public static function apply_discount() { |
619 | 619 | global $wpi_userID; |
620 | 620 | |
621 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
621 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
622 | 622 | |
623 | 623 | $response = array(); |
624 | 624 | |
625 | - if ( isset( $_POST['code'] ) ) { |
|
626 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
625 | + if (isset($_POST['code'])) { |
|
626 | + $discount_code = sanitize_text_field($_POST['code']); |
|
627 | 627 | |
628 | 628 | $response['success'] = false; |
629 | 629 | $response['msg'] = ''; |
630 | 630 | $response['data']['code'] = $discount_code; |
631 | 631 | |
632 | 632 | $invoice = wpinv_get_invoice_cart(); |
633 | - if ( empty( $invoice->ID ) ) { |
|
634 | - $response['msg'] = __( 'Invalid checkout request.', 'invoicing' ); |
|
635 | - wp_send_json( $response ); |
|
633 | + if (empty($invoice->ID)) { |
|
634 | + $response['msg'] = __('Invalid checkout request.', 'invoicing'); |
|
635 | + wp_send_json($response); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | $wpi_userID = $invoice->get_user_id(); |
639 | 639 | |
640 | - if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) { |
|
641 | - $discount = wpinv_get_discount_by_code( $discount_code ); |
|
642 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
643 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
644 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
645 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
640 | + if (wpinv_is_discount_valid($discount_code, $wpi_userID)) { |
|
641 | + $discount = wpinv_get_discount_by_code($discount_code); |
|
642 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
643 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
644 | + $total = wpinv_get_cart_total(null, $discounts); |
|
645 | + $cart_totals = wpinv_recalculate_tax(true); |
|
646 | 646 | |
647 | - if ( !empty( $cart_totals ) ) { |
|
647 | + if (!empty($cart_totals)) { |
|
648 | 648 | $response['success'] = true; |
649 | 649 | $response['data'] = $cart_totals; |
650 | 650 | $response['data']['code'] = $discount_code; |
@@ -653,29 +653,29 @@ discard block |
||
653 | 653 | } |
654 | 654 | } else { |
655 | 655 | $errors = wpinv_get_errors(); |
656 | - $response['msg'] = $errors['wpinv-discount-error']; |
|
657 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
656 | + $response['msg'] = $errors['wpinv-discount-error']; |
|
657 | + wpinv_unset_error('wpinv-discount-error'); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | // Allow for custom discount code handling |
661 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
661 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
662 | 662 | } |
663 | 663 | |
664 | - wp_send_json( $response ); |
|
664 | + wp_send_json($response); |
|
665 | 665 | } |
666 | 666 | |
667 | 667 | public static function remove_discount() { |
668 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
668 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
669 | 669 | |
670 | 670 | $response = array(); |
671 | 671 | |
672 | - if ( isset( $_POST['code'] ) ) { |
|
673 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
674 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
675 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
676 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
672 | + if (isset($_POST['code'])) { |
|
673 | + $discount_code = sanitize_text_field($_POST['code']); |
|
674 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
675 | + $total = wpinv_get_cart_total(null, $discounts); |
|
676 | + $cart_totals = wpinv_recalculate_tax(true); |
|
677 | 677 | |
678 | - if ( !empty( $cart_totals ) ) { |
|
678 | + if (!empty($cart_totals)) { |
|
679 | 679 | $response['success'] = true; |
680 | 680 | $response['data'] = $cart_totals; |
681 | 681 | $response['data']['code'] = $discount_code; |
@@ -684,10 +684,10 @@ discard block |
||
684 | 684 | } |
685 | 685 | |
686 | 686 | // Allow for custom discount code handling |
687 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
687 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
688 | 688 | } |
689 | 689 | |
690 | - wp_send_json( $response ); |
|
690 | + wp_send_json($response); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | |
@@ -696,20 +696,20 @@ discard block |
||
696 | 696 | * |
697 | 697 | * @since 1.0.0 |
698 | 698 | */ |
699 | - public function buy_items(){ |
|
699 | + public function buy_items() { |
|
700 | 700 | |
701 | 701 | $user_id = get_current_user_id(); |
702 | - if(!$user_id ){ // if not logged in then lets redirect to the login page |
|
702 | + if (!$user_id) { // if not logged in then lets redirect to the login page |
|
703 | 703 | |
704 | 704 | wp_send_json(array( |
705 | - 'success' => wp_login_url( wp_get_referer() ) |
|
705 | + 'success' => wp_login_url(wp_get_referer()) |
|
706 | 706 | )); |
707 | - }else{ |
|
707 | + } else { |
|
708 | 708 | |
709 | 709 | // only check nonce if logged in as it could be cached when logged out. |
710 | - if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) { |
|
710 | + if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) { |
|
711 | 711 | wp_send_json(array( |
712 | - 'error' => __('Security checks failed.','invoicing') |
|
712 | + 'error' => __('Security checks failed.', 'invoicing') |
|
713 | 713 | )); |
714 | 714 | wp_die(); |
715 | 715 | } |
@@ -717,36 +717,36 @@ discard block |
||
717 | 717 | // allow to set a custom price through post_id |
718 | 718 | $items = $_POST['items']; |
719 | 719 | $related_post_id = isset($_POST['post_id']) ? (int)$_POST['post_id'] : 0; |
720 | - $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id,'_wpi_custom_price',true)) : 0; |
|
720 | + $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0; |
|
721 | 721 | |
722 | 722 | |
723 | 723 | $cart_items = array(); |
724 | - if($items){ |
|
725 | - $items = explode(',',$items); |
|
726 | - foreach($items as $item){ |
|
724 | + if ($items) { |
|
725 | + $items = explode(',', $items); |
|
726 | + foreach ($items as $item) { |
|
727 | 727 | $item_id = $item; |
728 | 728 | $quantity = 1; |
729 | 729 | if (strpos($item, '|') !== false) { |
730 | - $item_parts = explode('|',$item); |
|
730 | + $item_parts = explode('|', $item); |
|
731 | 731 | $item_id = $item_parts[0]; |
732 | 732 | $quantity = $item_parts[1]; |
733 | 733 | } |
734 | 734 | |
735 | - if($item_id && $quantity){ |
|
735 | + if ($item_id && $quantity) { |
|
736 | 736 | $cart_items_arr = array( |
737 | 737 | 'id' => (int)$item_id, |
738 | 738 | 'quantity' => (int)$quantity |
739 | 739 | ); |
740 | 740 | |
741 | 741 | // if there is a related post id then add it to meta |
742 | - if($related_post_id){ |
|
742 | + if ($related_post_id) { |
|
743 | 743 | $cart_items_arr['meta'] = array( |
744 | 744 | 'post_id' => $related_post_id |
745 | 745 | ); |
746 | 746 | } |
747 | 747 | |
748 | 748 | // if there is a custom price then set it. |
749 | - if($custom_item_price){ |
|
749 | + if ($custom_item_price) { |
|
750 | 750 | $cart_items_arr['custom_price'] = $custom_item_price; |
751 | 751 | |
752 | 752 | } |
@@ -765,12 +765,12 @@ discard block |
||
765 | 765 | * @param int $related_post_id The related post id if any. |
766 | 766 | * @since 1.0.0 |
767 | 767 | */ |
768 | - $cart_items = apply_filters('wpinv_buy_cart_items',$cart_items,$related_post_id); |
|
768 | + $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id); |
|
769 | 769 | |
770 | 770 | |
771 | 771 | //make sure its not in the cart already, if it is then redirect to checkout. |
772 | 772 | $cart_invoice = wpinv_get_invoice_cart(); |
773 | - if(isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items)==serialize($cart_items) ){ |
|
773 | + if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) { |
|
774 | 774 | wp_send_json(array( |
775 | 775 | 'success' => $cart_invoice->get_checkout_payment_url() |
776 | 776 | )); |
@@ -779,25 +779,25 @@ discard block |
||
779 | 779 | |
780 | 780 | |
781 | 781 | // check if user has invoice with same items waiting to be paid. |
782 | - $user_invoices = wpinv_get_users_invoices( $user_id , 1 , false , 'pending' ); |
|
783 | - if(!empty($user_invoices)){ |
|
782 | + $user_invoices = wpinv_get_users_invoices($user_id, 1, false, 'pending'); |
|
783 | + if (!empty($user_invoices)) { |
|
784 | 784 | |
785 | - foreach($user_invoices as $user_invoice){ |
|
785 | + foreach ($user_invoices as $user_invoice) { |
|
786 | 786 | $user_cart_details = array(); |
787 | - $invoice = wpinv_get_invoice( $user_invoice->ID ); |
|
787 | + $invoice = wpinv_get_invoice($user_invoice->ID); |
|
788 | 788 | $cart_details = $invoice->get_cart_details(); |
789 | - if(!empty($cart_details)){ |
|
790 | - foreach($cart_details as $invoice_item){ |
|
789 | + if (!empty($cart_details)) { |
|
790 | + foreach ($cart_details as $invoice_item) { |
|
791 | 791 | |
792 | 792 | $ii_arr = array(); |
793 | 793 | $ii_arr['id'] = (int)$invoice_item['id']; |
794 | 794 | $ii_arr['quantity'] = (int)$invoice_item['quantity']; |
795 | 795 | |
796 | - if(isset($invoice_item['meta']) && !empty($invoice_item['meta'])){ |
|
796 | + if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) { |
|
797 | 797 | $ii_arr['meta'] = $invoice_item['meta']; |
798 | 798 | } |
799 | 799 | |
800 | - if(isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])){ |
|
800 | + if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) { |
|
801 | 801 | $ii_arr['custom_price'] = $invoice_item['custom_price']; |
802 | 802 | } |
803 | 803 | |
@@ -806,7 +806,7 @@ discard block |
||
806 | 806 | } |
807 | 807 | } |
808 | 808 | |
809 | - if(!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)){ |
|
809 | + if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) { |
|
810 | 810 | wp_send_json(array( |
811 | 811 | 'success' => $invoice->get_checkout_payment_url() |
812 | 812 | )); |
@@ -819,7 +819,7 @@ discard block |
||
819 | 819 | |
820 | 820 | |
821 | 821 | // Create invoice and send user to checkout |
822 | - if(!empty($cart_items)){ |
|
822 | + if (!empty($cart_items)) { |
|
823 | 823 | |
824 | 824 | $invoice_data = array( |
825 | 825 | 'status' => 'wpi-pending', |
@@ -829,26 +829,26 @@ discard block |
||
829 | 829 | ); |
830 | 830 | |
831 | 831 | // default invoice args |
832 | - $invoice_data['status'] = !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending'; |
|
833 | - $invoice_data['user_id'] = !empty( $invoice_data['user_id'] ) ? (int)$invoice_data['user_id'] : get_current_user_id(); |
|
832 | + $invoice_data['status'] = !empty($invoice_data['status']) ? $invoice_data['status'] : 'pending'; |
|
833 | + $invoice_data['user_id'] = !empty($invoice_data['user_id']) ? (int)$invoice_data['user_id'] : get_current_user_id(); |
|
834 | 834 | |
835 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
835 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
836 | 836 | |
837 | - if(isset($invoice->ID)){ |
|
837 | + if (isset($invoice->ID)) { |
|
838 | 838 | |
839 | 839 | wp_send_json(array( |
840 | 840 | 'success' => $invoice->get_checkout_payment_url() |
841 | 841 | )); |
842 | 842 | |
843 | - }else{ |
|
843 | + } else { |
|
844 | 844 | wp_send_json(array( |
845 | - 'error' => __('Invoice failed to create','invoicing') |
|
845 | + 'error' => __('Invoice failed to create', 'invoicing') |
|
846 | 846 | )); |
847 | 847 | } |
848 | 848 | |
849 | - }else{ |
|
849 | + } else { |
|
850 | 850 | wp_send_json(array( |
851 | - 'error' => __('Items not valid.','invoicing') |
|
851 | + 'error' => __('Items not valid.', 'invoicing') |
|
852 | 852 | )); |
853 | 853 | } |
854 | 854 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | 'wpinv_buy' => __CLASS__ . '::buy', |
16 | 16 | ); |
17 | 17 | |
18 | - foreach ( $shortcodes as $shortcode => $function ) { |
|
19 | - add_shortcode( apply_filters( "{$shortcode}_shortcode_tag", $shortcode ), $function ); |
|
18 | + foreach ($shortcodes as $shortcode => $function) { |
|
19 | + add_shortcode(apply_filters("{$shortcode}_shortcode_tag", $shortcode), $function); |
|
20 | 20 | } |
21 | 21 | |
22 | - add_shortcode( 'wpinv_messages', __CLASS__ . '::messages' ); |
|
22 | + add_shortcode('wpinv_messages', __CLASS__ . '::messages'); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | public static function shortcode_wrapper( |
@@ -33,25 +33,25 @@ discard block |
||
33 | 33 | ) { |
34 | 34 | ob_start(); |
35 | 35 | |
36 | - echo empty( $wrapper['before'] ) ? '<div class="' . esc_attr( $wrapper['class'] ) . '">' : $wrapper['before']; |
|
37 | - call_user_func( $function, $atts ); |
|
38 | - echo empty( $wrapper['after'] ) ? '</div>' : $wrapper['after']; |
|
36 | + echo empty($wrapper['before']) ? '<div class="' . esc_attr($wrapper['class']) . '">' : $wrapper['before']; |
|
37 | + call_user_func($function, $atts); |
|
38 | + echo empty($wrapper['after']) ? '</div>' : $wrapper['after']; |
|
39 | 39 | |
40 | 40 | return ob_get_clean(); |
41 | 41 | } |
42 | 42 | |
43 | - public static function checkout( $atts = array(), $content = null ) { |
|
44 | - return wpinv_checkout_form( $atts, $content ); |
|
43 | + public static function checkout($atts = array(), $content = null) { |
|
44 | + return wpinv_checkout_form($atts, $content); |
|
45 | 45 | } |
46 | 46 | |
47 | - public static function messages( $atts, $content = null ) { |
|
47 | + public static function messages($atts, $content = null) { |
|
48 | 48 | ob_start(); |
49 | 49 | wpinv_print_errors(); |
50 | 50 | return '<div class="wpinv">' . ob_get_clean() . '</div>'; |
51 | 51 | } |
52 | 52 | |
53 | - public static function history( $atts, $content = null ) { |
|
54 | - return self::shortcode_wrapper( array( __CLASS__, 'history_output' ), $atts ); |
|
53 | + public static function history($atts, $content = null) { |
|
54 | + return self::shortcode_wrapper(array(__CLASS__, 'history_output'), $atts); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -59,28 +59,28 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @param array $atts |
61 | 61 | */ |
62 | - public static function history_output( $atts ) { |
|
63 | - do_action( 'wpinv_before_user_invoice_history' ); |
|
64 | - wpinv_get_template_part( 'wpinv-invoice-history', $atts ); |
|
65 | - do_action( 'wpinv_after_user_invoice_history' ); |
|
62 | + public static function history_output($atts) { |
|
63 | + do_action('wpinv_before_user_invoice_history'); |
|
64 | + wpinv_get_template_part('wpinv-invoice-history', $atts); |
|
65 | + do_action('wpinv_after_user_invoice_history'); |
|
66 | 66 | } |
67 | 67 | |
68 | - public static function receipt( $atts, $content = null ) { |
|
69 | - return wpinv_payment_receipt( $atts, $content ); |
|
68 | + public static function receipt($atts, $content = null) { |
|
69 | + return wpinv_payment_receipt($atts, $content); |
|
70 | 70 | } |
71 | 71 | |
72 | - public static function buy( $atts, $content = null ) { |
|
73 | - $a = shortcode_atts( array( |
|
72 | + public static function buy($atts, $content = null) { |
|
73 | + $a = shortcode_atts(array( |
|
74 | 74 | 'items' => '', // should be used like: item_id|quantity,item_id|quantity,item_id|quantity |
75 | - 'title' => __('Buy Now', 'invoicing' ), // the button title |
|
75 | + 'title' => __('Buy Now', 'invoicing'), // the button title |
|
76 | 76 | 'post_id' => '', // any related post_id |
77 | - ), $atts ); |
|
77 | + ), $atts); |
|
78 | 78 | |
79 | 79 | $post_id = isset($a['post_id']) ? (int)$a['post_id'] : ''; |
80 | 80 | |
81 | 81 | $html = '<div class="wpi-buy-button-wrapper">'; |
82 | - $html .= '<input type="submit" name="submit" class="button button-primary wpi-buy-button" value="'.$a['title'].'" onclick="wpi_buy(\''.$a['items'].'\','.$post_id.');" />'; |
|
83 | - $html .= wp_nonce_field( 'wpinv_buy_items', 'wpinv_buy_nonce', true, false ); |
|
82 | + $html .= '<input type="submit" name="submit" class="button button-primary wpi-buy-button" value="' . $a['title'] . '" onclick="wpi_buy(\'' . $a['items'] . '\',' . $post_id . ');" />'; |
|
83 | + $html .= wp_nonce_field('wpinv_buy_items', 'wpinv_buy_nonce', true, false); |
|
84 | 84 | $html .= '</div>'; |
85 | 85 | |
86 | 86 |
@@ -7,15 +7,15 @@ 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 | class WPInv_Plugin { |
15 | 15 | private static $instance; |
16 | 16 | |
17 | 17 | public static function run() { |
18 | - if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) { |
|
18 | + if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) { |
|
19 | 19 | self::$instance = new WPInv_Plugin; |
20 | 20 | self::$instance->includes(); |
21 | 21 | self::$instance->actions(); |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | self::$instance->reports = new WPInv_Reports(); |
24 | 24 | } |
25 | 25 | |
26 | - do_action( 'wpinv_loaded' ); |
|
26 | + do_action('wpinv_loaded'); |
|
27 | 27 | |
28 | 28 | return self::$instance; |
29 | 29 | } |
@@ -33,33 +33,33 @@ discard block |
||
33 | 33 | } |
34 | 34 | |
35 | 35 | public function define_constants() { |
36 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
37 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
36 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
37 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | private function actions() { |
41 | 41 | /* Internationalize the text strings used. */ |
42 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
42 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
43 | 43 | |
44 | 44 | /* Perform actions on admin initialization. */ |
45 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
46 | - add_action( 'init', array( &$this, 'init' ), 3 ); |
|
47 | - add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) ); |
|
48 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
45 | + add_action('admin_init', array(&$this, 'admin_init')); |
|
46 | + add_action('init', array(&$this, 'init'), 3); |
|
47 | + add_action('init', array('WPInv_Shortcodes', 'init')); |
|
48 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
49 | 49 | |
50 | - if ( class_exists( 'BuddyPress' ) ) { |
|
51 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
50 | + if (class_exists('BuddyPress')) { |
|
51 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
52 | 52 | } |
53 | 53 | |
54 | - add_filter( 'geodir_googlemap_script_extra', array( &$this,'add_google_maps_places_lib'), 101, 1 ); |
|
54 | + add_filter('geodir_googlemap_script_extra', array(&$this, 'add_google_maps_places_lib'), 101, 1); |
|
55 | 55 | |
56 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
56 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
57 | 57 | |
58 | - if ( is_admin() ) { |
|
59 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
60 | - add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
58 | + if (is_admin()) { |
|
59 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
60 | + add_action('admin_body_class', array(&$this, 'admin_body_class')); |
|
61 | 61 | } else { |
62 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
62 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
71 | 71 | */ |
72 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
72 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
73 | 73 | |
74 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
74 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | public function plugins_loaded() { |
@@ -85,157 +85,157 @@ discard block |
||
85 | 85 | * @since 1.0 |
86 | 86 | */ |
87 | 87 | public function load_textdomain() { |
88 | - $locale = apply_filters( 'plugin_locale', get_locale(), 'invoicing' ); |
|
88 | + $locale = apply_filters('plugin_locale', get_locale(), 'invoicing'); |
|
89 | 89 | |
90 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
91 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
90 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
91 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
92 | 92 | |
93 | 93 | /** |
94 | 94 | * Define language constants. |
95 | 95 | */ |
96 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
96 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | public function includes() { |
100 | 100 | global $wpinv_options; |
101 | 101 | |
102 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
102 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
103 | 103 | $wpinv_options = wpinv_get_settings(); |
104 | 104 | |
105 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
106 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
107 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
108 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
109 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
110 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
111 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
112 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
113 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
114 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
115 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
116 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
117 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
118 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php' ); |
|
119 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
105 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
106 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
107 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
108 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
109 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
110 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
111 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
112 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
113 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
114 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
115 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
116 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
117 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
118 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php'); |
|
119 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
120 | 120 | //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
121 | 121 | //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
122 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
122 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
123 | 123 | //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscription.php' ); |
124 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
125 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
126 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' ); |
|
127 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
128 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
129 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
130 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' ); |
|
131 | - if ( !class_exists( 'Geodir_EUVat' ) ) { |
|
132 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
124 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
125 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
126 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php'); |
|
127 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
128 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
129 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
130 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php'); |
|
131 | + if (!class_exists('Geodir_EUVat')) { |
|
132 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
133 | 133 | } |
134 | 134 | |
135 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
136 | - if ( !empty( $gateways ) ) { |
|
137 | - foreach ( $gateways as $gateway ) { |
|
138 | - if ( $gateway == 'manual' ) { |
|
135 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
136 | + if (!empty($gateways)) { |
|
137 | + foreach ($gateways as $gateway) { |
|
138 | + if ($gateway == 'manual') { |
|
139 | 139 | continue; |
140 | 140 | } |
141 | 141 | |
142 | 142 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
143 | 143 | |
144 | - if ( file_exists( $gateway_file ) ) { |
|
145 | - require_once( $gateway_file ); |
|
144 | + if (file_exists($gateway_file)) { |
|
145 | + require_once($gateway_file); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | } |
149 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
149 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
150 | 150 | |
151 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
152 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
153 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
154 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
151 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
152 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
153 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
154 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
155 | 155 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
156 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
157 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
158 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
159 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
160 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
156 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
157 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
158 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
159 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
160 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
161 | 161 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
162 | 162 | } |
163 | 163 | |
164 | 164 | // include css inliner |
165 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
166 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
165 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
166 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
167 | 167 | } |
168 | 168 | |
169 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
169 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | public function init() { |
173 | 173 | } |
174 | 174 | |
175 | 175 | public function admin_init() { |
176 | - if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) { |
|
176 | + if (!(defined('DOING_AJAX') && DOING_AJAX)) { |
|
177 | 177 | } |
178 | 178 | |
179 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
179 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | public function activation_redirect() { |
183 | 183 | // Bail if no activation redirect |
184 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
184 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
185 | 185 | return; |
186 | 186 | } |
187 | 187 | |
188 | 188 | // Delete the redirect transient |
189 | - delete_transient( '_wpinv_activation_redirect' ); |
|
189 | + delete_transient('_wpinv_activation_redirect'); |
|
190 | 190 | |
191 | 191 | // Bail if activating from network, or bulk |
192 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
192 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
193 | 193 | return; |
194 | 194 | } |
195 | 195 | |
196 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
196 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
197 | 197 | exit; |
198 | 198 | } |
199 | 199 | |
200 | 200 | public function enqueue_scripts() { |
201 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
201 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
202 | 202 | |
203 | - wp_deregister_style( 'font-awesome' ); |
|
204 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
205 | - wp_enqueue_style( 'font-awesome' ); |
|
203 | + wp_deregister_style('font-awesome'); |
|
204 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
205 | + wp_enqueue_style('font-awesome'); |
|
206 | 206 | |
207 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION ); |
|
208 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
207 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION); |
|
208 | + wp_enqueue_style('wpinv_front_style'); |
|
209 | 209 | |
210 | 210 | // Register scripts |
211 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
212 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ), WPINV_VERSION ); |
|
211 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
212 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION); |
|
213 | 213 | |
214 | 214 | $localize = array(); |
215 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
216 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
215 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
216 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
217 | 217 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
218 | 218 | $localize['currency_pos'] = wpinv_currency_position(); |
219 | 219 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
220 | 220 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
221 | 221 | $localize['decimals'] = wpinv_decimals(); |
222 | 222 | |
223 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
223 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
224 | 224 | |
225 | - wp_enqueue_script( 'jquery-blockui' ); |
|
225 | + wp_enqueue_script('jquery-blockui'); |
|
226 | 226 | $autofill_api = wpinv_get_option('address_autofill_api'); |
227 | 227 | $autofill_active = wpinv_get_option('address_autofill_active'); |
228 | 228 | if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
229 | 229 | |
230 | 230 | // we don't need this if GD is installed. |
231 | - if(!function_exists('geodir_templates_scripts')){ |
|
231 | + if (!function_exists('geodir_templates_scripts')) { |
|
232 | 232 | wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
233 | 233 | } |
234 | - wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery','google-maps-api'), '', true); |
|
234 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
235 | 235 | |
236 | 236 | } |
237 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
238 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
237 | + wp_enqueue_script('wpinv-front-script'); |
|
238 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
@@ -245,9 +245,9 @@ discard block |
||
245 | 245 | * @since 1.0.0 |
246 | 246 | * @return string |
247 | 247 | */ |
248 | - public function add_google_maps_places_lib( $extra ) { |
|
248 | + public function add_google_maps_places_lib($extra) { |
|
249 | 249 | |
250 | - if ( wpinv_is_checkout() && ! str_replace( 'libraries=places', '', $extra ) ) { |
|
250 | + if (wpinv_is_checkout() && !str_replace('libraries=places', '', $extra)) { |
|
251 | 251 | $extra .= "&libraries=places"; |
252 | 252 | } |
253 | 253 | |
@@ -258,35 +258,35 @@ discard block |
||
258 | 258 | global $post, $pagenow; |
259 | 259 | |
260 | 260 | $post_type = wpinv_admin_post_type(); |
261 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
261 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
262 | 262 | |
263 | - wp_deregister_style( 'font-awesome' ); |
|
264 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
265 | - wp_enqueue_style( 'font-awesome' ); |
|
263 | + wp_deregister_style('font-awesome'); |
|
264 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
265 | + wp_enqueue_style('font-awesome'); |
|
266 | 266 | |
267 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
268 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
267 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
268 | + wp_enqueue_style('jquery-ui-css'); |
|
269 | 269 | |
270 | - wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' ); |
|
271 | - wp_enqueue_style( 'jquery-chosen' ); |
|
270 | + wp_register_style('jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2'); |
|
271 | + wp_enqueue_style('jquery-chosen'); |
|
272 | 272 | |
273 | - wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' ); |
|
274 | - wp_enqueue_script( 'jquery-chosen' ); |
|
273 | + wp_register_script('jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array('jquery'), '1.6.2'); |
|
274 | + wp_enqueue_script('jquery-chosen'); |
|
275 | 275 | |
276 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
277 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
276 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
277 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
278 | 278 | |
279 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION ); |
|
280 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
279 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION); |
|
280 | + wp_enqueue_style('wpinv_admin_style'); |
|
281 | 281 | |
282 | - if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
283 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
282 | + if ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
283 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
284 | 284 | } |
285 | 285 | |
286 | - wp_enqueue_style( 'wp-color-picker' ); |
|
287 | - wp_enqueue_script( 'wp-color-picker' ); |
|
286 | + wp_enqueue_style('wp-color-picker'); |
|
287 | + wp_enqueue_script('wp-color-picker'); |
|
288 | 288 | |
289 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
289 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
290 | 290 | |
291 | 291 | if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
292 | 292 | $autofill_api = wpinv_get_option('address_autofill_api'); |
@@ -297,17 +297,17 @@ discard block |
||
297 | 297 | } |
298 | 298 | } |
299 | 299 | |
300 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), WPINV_VERSION ); |
|
301 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
300 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), WPINV_VERSION); |
|
301 | + wp_enqueue_script('wpinv-admin-script'); |
|
302 | 302 | |
303 | 303 | $localize = array(); |
304 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
305 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
306 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
307 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
308 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
309 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
310 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
304 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
305 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
306 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
307 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
308 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
309 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
310 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
311 | 311 | $localize['tax'] = wpinv_tax_amount(); |
312 | 312 | $localize['discount'] = wpinv_discount_amount(); |
313 | 313 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -315,65 +315,65 @@ discard block |
||
315 | 315 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
316 | 316 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
317 | 317 | $localize['decimals'] = wpinv_decimals(); |
318 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
319 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
320 | - $localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
321 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
322 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
323 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
324 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
325 | - $localize['confirmCalcTotals'] = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ); |
|
326 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
318 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
319 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
320 | + $localize['status_pending'] = wpinv_status_nicename('wpi-pending'); |
|
321 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
322 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
323 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
324 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
325 | + $localize['confirmCalcTotals'] = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'); |
|
326 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
327 | 327 | $localize['hasGD'] = wpinv_gd_active(); |
328 | 328 | $localize['hasPM'] = wpinv_pm_active(); |
329 | - $localize['emptyInvoice'] = __( 'Add atleast one item to save invoice!', 'invoicing' ); |
|
330 | - $localize['deletePackage'] = __( 'GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing' ); |
|
331 | - $localize['deletePackages'] = __( 'GD package items should be deleted from GD payment manager only', 'invoicing' ); |
|
332 | - $localize['deleteInvoiceFirst'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
329 | + $localize['emptyInvoice'] = __('Add atleast one item to save invoice!', 'invoicing'); |
|
330 | + $localize['deletePackage'] = __('GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing'); |
|
331 | + $localize['deletePackages'] = __('GD package items should be deleted from GD payment manager only', 'invoicing'); |
|
332 | + $localize['deleteInvoiceFirst'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
333 | 333 | |
334 | - $localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
334 | + $localize = apply_filters('wpinv_admin_js_localize', $localize); |
|
335 | 335 | |
336 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
336 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
337 | 337 | } |
338 | 338 | |
339 | - public function admin_body_class( $classes ) { |
|
339 | + public function admin_body_class($classes) { |
|
340 | 340 | global $pagenow, $post, $current_screen; |
341 | 341 | |
342 | - if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote' ) ) { |
|
342 | + if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote')) { |
|
343 | 343 | $classes .= ' wpinv-cpt'; |
344 | 344 | } |
345 | 345 | |
346 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
346 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
347 | 347 | |
348 | 348 | $add_class = false; |
349 | - if ( $pagenow == 'admin.php' && $page ) { |
|
350 | - $add_class = strpos( $page, 'wpinv-' ); |
|
349 | + if ($pagenow == 'admin.php' && $page) { |
|
350 | + $add_class = strpos($page, 'wpinv-'); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | $settings_class = array(); |
354 | - if ( $page == 'wpinv-settings' ) { |
|
355 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
356 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
354 | + if ($page == 'wpinv-settings') { |
|
355 | + if (!empty($_REQUEST['tab'])) { |
|
356 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
357 | 357 | } |
358 | 358 | |
359 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
360 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
359 | + if (!empty($_REQUEST['section'])) { |
|
360 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
361 | 361 | } |
362 | 362 | |
363 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
363 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
364 | 364 | } |
365 | 365 | |
366 | - if ( !empty( $settings_class ) ) { |
|
367 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
366 | + if (!empty($settings_class)) { |
|
367 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | $post_type = wpinv_admin_post_type(); |
371 | 371 | |
372 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
372 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
373 | 373 | return $classes .= ' wpinv'; |
374 | 374 | } |
375 | 375 | |
376 | - if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
376 | + if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
377 | 377 | $classes .= ' wpi-editable-n'; |
378 | 378 | } |
379 | 379 | |
@@ -385,20 +385,20 @@ discard block |
||
385 | 385 | } |
386 | 386 | |
387 | 387 | public function wpinv_actions() { |
388 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
389 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
388 | + if (isset($_REQUEST['wpi_action'])) { |
|
389 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
390 | 390 | } |
391 | 391 | } |
392 | 392 | |
393 | - public function pre_get_posts( $wp_query ) { |
|
394 | - if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
395 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
393 | + public function pre_get_posts($wp_query) { |
|
394 | + if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
395 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | return $wp_query; |
399 | 399 | } |
400 | 400 | |
401 | 401 | public function bp_invoicing_init() { |
402 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
402 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
403 | 403 | } |
404 | 404 | } |
405 | 405 | \ No newline at end of file |
@@ -7,8 +7,8 @@ |
||
7 | 7 | set_transient('_wpinv_activation_redirect', true, 30); |
8 | 8 | wpinv_install($network_wide); |
9 | 9 | |
10 | - if(!wpinv_get_option('address_autofill_api') && $api_key = get_option('geodir_google_api_key')){ |
|
11 | - wpinv_update_option( 'address_autofill_api', $api_key); |
|
10 | + if (!wpinv_get_option('address_autofill_api') && $api_key = get_option('geodir_google_api_key')) { |
|
11 | + wpinv_update_option('address_autofill_api', $api_key); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | } |
@@ -1,34 +1,34 @@ 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 | class WPInv_Meta_Box_Billing_Details { |
8 | - public static function output( $post ) { |
|
8 | + public static function output($post) { |
|
9 | 9 | global $user_ID; |
10 | - $post_id = !empty( $post->ID ) ? $post->ID : 0; |
|
11 | - $invoice = new WPInv_Invoice( $post_id ); |
|
10 | + $post_id = !empty($post->ID) ? $post->ID : 0; |
|
11 | + $invoice = new WPInv_Invoice($post_id); |
|
12 | 12 | ?> |
13 | 13 | <div class="gdmbx2-wrap form-table"> |
14 | 14 | <div id="gdmbx2-metabox-wpinv_address" class="gdmbx2-metabox gdmbx-field-list wpinv-address gdmbx-row"> |
15 | 15 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-user-id table-layout"> |
16 | 16 | <div class="gdmbx-th"> |
17 | - <label for="post_author_override"><?php _e( 'Customer', 'invoicing' );?></label> |
|
17 | + <label for="post_author_override"><?php _e('Customer', 'invoicing'); ?></label> |
|
18 | 18 | </div> |
19 | 19 | <div class="gdmbx-td gdmbx-customer-div"> |
20 | - <?php wpinv_dropdown_users( array( |
|
20 | + <?php wpinv_dropdown_users(array( |
|
21 | 21 | 'name' => 'post_author_override', |
22 | 22 | 'selected' => empty($post->ID) ? $user_ID : $post->post_author, |
23 | 23 | 'include_selected' => true, |
24 | 24 | 'show' => 'user_email', |
25 | 25 | 'orderby' => 'user_email', |
26 | 26 | 'class' => 'gdmbx2-text-large' |
27 | - ) ); ?> |
|
27 | + )); ?> |
|
28 | 28 | </div> |
29 | 29 | </div> |
30 | 30 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-email table-layout" style="display:none"> |
31 | - <div class="gdmbx-th"><label for="wpinv_email"><?php _e( 'Email', 'invoicing' );?> <span class="required">*</span></label> |
|
31 | + <div class="gdmbx-th"><label for="wpinv_email"><?php _e('Email', 'invoicing'); ?> <span class="required">*</span></label> |
|
32 | 32 | </div> |
33 | 33 | <div class="gdmbx-td"> |
34 | 34 | <input type="hidden" id="wpinv_new_user" name="wpinv_new_user" value="" /> |
@@ -36,58 +36,58 @@ discard block |
||
36 | 36 | </div> |
37 | 37 | </div> |
38 | 38 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-btns table-layout"> |
39 | - <div class="gdmbx-th"><label><?php _e( 'Actions', 'invoicing' );?></label> |
|
39 | + <div class="gdmbx-th"><label><?php _e('Actions', 'invoicing'); ?></label> |
|
40 | 40 | </div> |
41 | - <?php if($invoice->has_status(array('auto-draft', 'wpi-pending', 'wpi-quote-pending'))){ ?> |
|
41 | + <?php if ($invoice->has_status(array('auto-draft', 'wpi-pending', 'wpi-quote-pending'))) { ?> |
|
42 | 42 | <div class="gdmbx-td"> |
43 | - <a id="wpinv-fill-user-details" class="button button-small button-secondary" title="<?php esc_attr_e( 'Fill User Details', 'invoicing' );?>" href="javascript:void(0)"><i aria-hidden="true" class="fa fa-refresh"></i><?php _e( 'Fill User Details', 'invoicing' );?></a> |
|
44 | - <a class="wpinv-new-user button button-small button-secondary" href="javascript:void(0)"><i aria-hidden="true" class="fa fa-plus"></i><?php _e( 'Add New User', 'invoicing' );?></a> |
|
45 | - <a style="display:none" class="wpinv-new-cancel button button-small button-secondary" href="javascript:void(0)"><i aria-hidden="true" class="fa fa-close"></i><?php _e( 'Cancel', 'invoicing' );?> </a> |
|
43 | + <a id="wpinv-fill-user-details" class="button button-small button-secondary" title="<?php esc_attr_e('Fill User Details', 'invoicing'); ?>" href="javascript:void(0)"><i aria-hidden="true" class="fa fa-refresh"></i><?php _e('Fill User Details', 'invoicing'); ?></a> |
|
44 | + <a class="wpinv-new-user button button-small button-secondary" href="javascript:void(0)"><i aria-hidden="true" class="fa fa-plus"></i><?php _e('Add New User', 'invoicing'); ?></a> |
|
45 | + <a style="display:none" class="wpinv-new-cancel button button-small button-secondary" href="javascript:void(0)"><i aria-hidden="true" class="fa fa-close"></i><?php _e('Cancel', 'invoicing'); ?> </a> |
|
46 | 46 | </div> |
47 | 47 | <?php } ?> |
48 | 48 | </div> |
49 | 49 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-first-name table-layout"> |
50 | - <div class="gdmbx-th"><label for="wpinv_first_name"><?php _e( 'First Name', 'invoicing' );?></label></div> |
|
50 | + <div class="gdmbx-th"><label for="wpinv_first_name"><?php _e('First Name', 'invoicing'); ?></label></div> |
|
51 | 51 | <div class="gdmbx-td"> |
52 | - <input type="text" class="gdmbx2-text-large" name="wpinv_first_name" id="wpinv_first_name" value="<?php echo esc_attr( $invoice->first_name );?>" /> |
|
52 | + <input type="text" class="gdmbx2-text-large" name="wpinv_first_name" id="wpinv_first_name" value="<?php echo esc_attr($invoice->first_name); ?>" /> |
|
53 | 53 | </div> |
54 | 54 | </div> |
55 | 55 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-last-name table-layout"> |
56 | - <div class="gdmbx-th"><label for="wpinv_last_name"><?php _e( 'Last Name', 'invoicing' );?></label></div> |
|
56 | + <div class="gdmbx-th"><label for="wpinv_last_name"><?php _e('Last Name', 'invoicing'); ?></label></div> |
|
57 | 57 | <div class="gdmbx-td"> |
58 | - <input type="text" class="gdmbx2-text-large" name="wpinv_last_name" id="wpinv_last_name" value="<?php echo esc_attr( $invoice->last_name );?>" /> |
|
58 | + <input type="text" class="gdmbx2-text-large" name="wpinv_last_name" id="wpinv_last_name" value="<?php echo esc_attr($invoice->last_name); ?>" /> |
|
59 | 59 | </div> |
60 | 60 | </div> |
61 | 61 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-company table-layout"> |
62 | - <div class="gdmbx-th"><label for="wpinv_company"><?php _e( 'Company', 'invoicing' );?></label></div> |
|
62 | + <div class="gdmbx-th"><label for="wpinv_company"><?php _e('Company', 'invoicing'); ?></label></div> |
|
63 | 63 | <div class="gdmbx-td"> |
64 | - <input type="text" class="gdmbx2-text-large" name="wpinv_company" id="wpinv_company" value="<?php echo esc_attr( $invoice->company );?>" /> |
|
64 | + <input type="text" class="gdmbx2-text-large" name="wpinv_company" id="wpinv_company" value="<?php echo esc_attr($invoice->company); ?>" /> |
|
65 | 65 | </div> |
66 | 66 | </div> |
67 | 67 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-vat-number table-layout"> |
68 | - <div class="gdmbx-th"><label for="wpinv_vat_number"><?php _e( 'Vat Number', 'invoicing' );?></label></div> |
|
68 | + <div class="gdmbx-th"><label for="wpinv_vat_number"><?php _e('Vat Number', 'invoicing'); ?></label></div> |
|
69 | 69 | <div class="gdmbx-td"> |
70 | - <input type="text" class="gdmbx2-text-large" name="wpinv_vat_number" id="wpinv_vat_number" value="<?php echo esc_attr( $invoice->vat_number );?>" /> |
|
70 | + <input type="text" class="gdmbx2-text-large" name="wpinv_vat_number" id="wpinv_vat_number" value="<?php echo esc_attr($invoice->vat_number); ?>" /> |
|
71 | 71 | </div> |
72 | 72 | </div> |
73 | 73 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-address table-layout"> |
74 | - <div class="gdmbx-th"><label for="wpinv_address"><?php _e( 'Address', 'invoicing' );?></label></div> |
|
74 | + <div class="gdmbx-th"><label for="wpinv_address"><?php _e('Address', 'invoicing'); ?></label></div> |
|
75 | 75 | <div class="gdmbx-td"> |
76 | - <input type="text" class="gdmbx2-text-large" name="wpinv_address" id="wpinv_address" value="<?php echo esc_attr( $invoice->address );?>" /> |
|
76 | + <input type="text" class="gdmbx2-text-large" name="wpinv_address" id="wpinv_address" value="<?php echo esc_attr($invoice->address); ?>" /> |
|
77 | 77 | </div> |
78 | 78 | </div> |
79 | 79 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-city table-layout"> |
80 | - <div class="gdmbx-th"><label for="wpinv_city"><?php _e( 'City', 'invoicing' );?></label></div> |
|
80 | + <div class="gdmbx-th"><label for="wpinv_city"><?php _e('City', 'invoicing'); ?></label></div> |
|
81 | 81 | <div class="gdmbx-td"> |
82 | - <input type="text" class="gdmbx2-text-large" name="wpinv_city" id="wpinv_city" value="<?php echo esc_attr( $invoice->city );?>" /> |
|
82 | + <input type="text" class="gdmbx2-text-large" name="wpinv_city" id="wpinv_city" value="<?php echo esc_attr($invoice->city); ?>" /> |
|
83 | 83 | </div> |
84 | 84 | </div> |
85 | 85 | <div class="gdmbx-row gdmbx-type-select gdmbx-wpinv-country table-layout"> |
86 | - <div class="gdmbx-th"><label for="wpinv_country"><?php _e( 'Country', 'invoicing' );?> <span class="wpi-loader"><i class="fa fa-refresh fa-spin"></i></span></label></div> |
|
86 | + <div class="gdmbx-th"><label for="wpinv_country"><?php _e('Country', 'invoicing'); ?> <span class="wpi-loader"><i class="fa fa-refresh fa-spin"></i></span></label></div> |
|
87 | 87 | <div class="gdmbx-td"> |
88 | 88 | <?php |
89 | - echo wpinv_html_select( array( |
|
90 | - 'options' => array_merge( array( '' => __( 'Choose a country', 'invoicing' ) ), wpinv_get_country_list() ), |
|
89 | + echo wpinv_html_select(array( |
|
90 | + 'options' => array_merge(array('' => __('Choose a country', 'invoicing')), wpinv_get_country_list()), |
|
91 | 91 | 'name' => 'wpinv_country', |
92 | 92 | 'id' => 'wpinv_country', |
93 | 93 | 'selected' => $invoice->country, |
@@ -95,20 +95,20 @@ discard block |
||
95 | 95 | 'show_option_none' => false, |
96 | 96 | 'class' => 'gdmbx2-text-large', |
97 | 97 | 'chosen' => false, |
98 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
98 | + 'placeholder' => __('Choose a country', 'invoicing'), |
|
99 | 99 | 'required' => false, |
100 | - ) ); |
|
100 | + )); |
|
101 | 101 | ?> |
102 | 102 | </div> |
103 | 103 | </div> |
104 | 104 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-state table-layout"> |
105 | - <div class="gdmbx-th"><label for="wpinv_state"><?php _e( 'State', 'invoicing' );?></label></div> |
|
105 | + <div class="gdmbx-th"><label for="wpinv_state"><?php _e('State', 'invoicing'); ?></label></div> |
|
106 | 106 | <div class="gdmbx-td"> |
107 | 107 | <?php |
108 | - $states = wpinv_get_country_states( $invoice->country ); |
|
109 | - if( !empty( $states ) ) { |
|
110 | - echo wpinv_html_select( array( |
|
111 | - 'options' => array_merge( array( '' => __( 'Choose a state', 'invoicing' ) ), $states ), |
|
108 | + $states = wpinv_get_country_states($invoice->country); |
|
109 | + if (!empty($states)) { |
|
110 | + echo wpinv_html_select(array( |
|
111 | + 'options' => array_merge(array('' => __('Choose a state', 'invoicing')), $states), |
|
112 | 112 | 'name' => 'wpinv_state', |
113 | 113 | 'id' => 'wpinv_state', |
114 | 114 | 'selected' => $invoice->state, |
@@ -116,44 +116,44 @@ discard block |
||
116 | 116 | 'show_option_none' => false, |
117 | 117 | 'class' => 'gdmbx2-text-large', |
118 | 118 | 'chosen' => false, |
119 | - 'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
119 | + 'placeholder' => __('Choose a state', 'invoicing'), |
|
120 | 120 | 'required' => false, |
121 | - ) ); |
|
121 | + )); |
|
122 | 122 | } else { |
123 | - echo wpinv_html_text( array( |
|
123 | + echo wpinv_html_text(array( |
|
124 | 124 | 'name' => 'wpinv_state', |
125 | - 'value' => ! empty( $invoice->state ) ? $invoice->state : '', |
|
125 | + 'value' => !empty($invoice->state) ? $invoice->state : '', |
|
126 | 126 | 'id' => 'wpinv_state', |
127 | 127 | 'class' => 'gdmbx2-text-large', |
128 | 128 | 'required' => false, |
129 | - ) ); |
|
129 | + )); |
|
130 | 130 | } |
131 | 131 | ?> |
132 | 132 | </div> |
133 | 133 | </div> |
134 | 134 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-zip table-layout"> |
135 | - <div class="gdmbx-th"><label for="wpinv_zip"><?php _e( 'Zipcode', 'invoicing' );?></label></div> |
|
135 | + <div class="gdmbx-th"><label for="wpinv_zip"><?php _e('Zipcode', 'invoicing'); ?></label></div> |
|
136 | 136 | <div class="gdmbx-td"> |
137 | - <input type="text" class="gdmbx2-text-large" name="wpinv_zip" id="wpinv_zip" value="<?php echo esc_attr( $invoice->zip );?>" /> |
|
137 | + <input type="text" class="gdmbx2-text-large" name="wpinv_zip" id="wpinv_zip" value="<?php echo esc_attr($invoice->zip); ?>" /> |
|
138 | 138 | </div> |
139 | 139 | </div> |
140 | 140 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-phone table-layout"> |
141 | - <div class="gdmbx-th"><label for="wpinv_phone"><?php _e( 'Phone', 'invoicing' );?></label></div> |
|
141 | + <div class="gdmbx-th"><label for="wpinv_phone"><?php _e('Phone', 'invoicing'); ?></label></div> |
|
142 | 142 | <div class="gdmbx-td"> |
143 | - <input type="text" class="gdmbx2-text-large" name="wpinv_phone" id="wpinv_phone" value="<?php echo esc_attr( $invoice->phone );?>" /> |
|
143 | + <input type="text" class="gdmbx2-text-large" name="wpinv_phone" id="wpinv_phone" value="<?php echo esc_attr($invoice->phone); ?>" /> |
|
144 | 144 | </div> |
145 | 145 | </div> |
146 | 146 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-ip table-layout"> |
147 | - <div class="gdmbx-th"><label for="wpinv_ip"><?php _e( 'IP Address', 'invoicing' );?><?php if ($invoice->ip) { ?> |
|
148 | - <a href="<?php echo admin_url( 'admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $invoice->ip ); ?>" title="<?php esc_attr_e( 'View IP information', 'invoicing' );?>" target="_blank"><i class="fa fa-external-link" aria-hidden="true"></i></a> |
|
147 | + <div class="gdmbx-th"><label for="wpinv_ip"><?php _e('IP Address', 'invoicing'); ?><?php if ($invoice->ip) { ?> |
|
148 | + <a href="<?php echo admin_url('admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $invoice->ip); ?>" title="<?php esc_attr_e('View IP information', 'invoicing'); ?>" target="_blank"><i class="fa fa-external-link" aria-hidden="true"></i></a> |
|
149 | 149 | <?php } ?></label></div> |
150 | 150 | <div class="gdmbx-td"> |
151 | - <input type="text" class="gdmbx2-text-large" value="<?php echo esc_attr( $invoice->ip );?>" readonly /> |
|
151 | + <input type="text" class="gdmbx2-text-large" value="<?php echo esc_attr($invoice->ip); ?>" readonly /> |
|
152 | 152 | </div> |
153 | 153 | </div> |
154 | 154 | </div> |
155 | 155 | </div> |
156 | -<?php wp_nonce_field( 'wpinv_save_invoice', 'wpinv_save_invoice' ) ;?> |
|
156 | +<?php wp_nonce_field('wpinv_save_invoice', 'wpinv_save_invoice'); ?> |
|
157 | 157 | <?php |
158 | 158 | } |
159 | 159 | } |
@@ -1,56 +1,56 @@ |
||
1 | 1 | <?php |
2 | -if ( !defined('ABSPATH') ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | -do_action( 'wpinv_invalid_invoice_before_display' ); ?><!DOCTYPE html> |
|
5 | +do_action('wpinv_invalid_invoice_before_display'); ?><!DOCTYPE html> |
|
6 | 6 | <html <?php language_attributes(); ?>> |
7 | 7 | <head> |
8 | 8 | <meta charset="UTF-8"> |
9 | 9 | <title><?php wp_title() ?></title> |
10 | - <meta charset="<?php bloginfo( 'charset' ); ?>" /> |
|
10 | + <meta charset="<?php bloginfo('charset'); ?>" /> |
|
11 | 11 | <meta name="viewport" content="width=device-width,initial-scale=1"> |
12 | 12 | <meta name="robots" content="noindex,nofollow"> |
13 | - <?php do_action( 'wpinv_invalid_invoice_head' ); ?> |
|
13 | + <?php do_action('wpinv_invalid_invoice_head'); ?> |
|
14 | 14 | </head> |
15 | 15 | <body class="body wpinv wpinv-print wpinv-invalid-invoice"> |
16 | - <?php do_action( 'wpinv_invalid_invoice_body_start' ); ?> |
|
16 | + <?php do_action('wpinv_invalid_invoice_body_start'); ?> |
|
17 | 17 | <div class="container wpinv-wrap"> |
18 | 18 | <!-- ///// Start Header --> |
19 | 19 | <htmlpageheader name="wpinv-pdf-header"> |
20 | - <?php do_action( 'wpinv_invalid_invoice_before_header' ); ?> |
|
20 | + <?php do_action('wpinv_invalid_invoice_before_header'); ?> |
|
21 | 21 | <div class="row wpinv-header"> |
22 | 22 | <div class="col-xs-12 wpinv-business"> |
23 | - <a target="_blank" href="<?php echo esc_url( wpinv_get_business_website() ); ?>"> |
|
24 | - <?php if ( $logo = wpinv_get_business_logo() ) { ?> |
|
25 | - <img class="logo" src="<?php echo esc_url( $logo ); ?>"> |
|
23 | + <a target="_blank" href="<?php echo esc_url(wpinv_get_business_website()); ?>"> |
|
24 | + <?php if ($logo = wpinv_get_business_logo()) { ?> |
|
25 | + <img class="logo" src="<?php echo esc_url($logo); ?>"> |
|
26 | 26 | <?php } else { ?> |
27 | - <h1><?php echo esc_html( wpinv_get_business_name() ); ?></h1> |
|
27 | + <h1><?php echo esc_html(wpinv_get_business_name()); ?></h1> |
|
28 | 28 | <?php } ?> |
29 | 29 | </a> |
30 | 30 | </div> |
31 | 31 | </div> |
32 | - <?php do_action( 'wpinv_invalid_invoice_after_header' ); ?> |
|
32 | + <?php do_action('wpinv_invalid_invoice_after_header'); ?> |
|
33 | 33 | </htmlpageheader> |
34 | 34 | <!-- End Header ///// --> |
35 | 35 | |
36 | - <?php do_action( 'wpinv_invalid_invoice_before_content' ); ?> |
|
36 | + <?php do_action('wpinv_invalid_invoice_before_content'); ?> |
|
37 | 37 | |
38 | - <?php do_action( 'wpinv_invalid_invoice_content' ); ?> |
|
38 | + <?php do_action('wpinv_invalid_invoice_content'); ?> |
|
39 | 39 | |
40 | - <?php do_action( 'wpinv_invalid_invoice_after_content' ); ?> |
|
40 | + <?php do_action('wpinv_invalid_invoice_after_content'); ?> |
|
41 | 41 | |
42 | 42 | <!-- ///// Start Footer --> |
43 | 43 | <htmlpagefooter name="wpinv-pdf-footer"> |
44 | - <?php do_action( 'wpinv_invalid_invoice_before_footer' ); ?> |
|
44 | + <?php do_action('wpinv_invalid_invoice_before_footer'); ?> |
|
45 | 45 | <div class="row wpinv-footer"> |
46 | 46 | <div class="col-sm-12"> |
47 | 47 | <div class="footer-text"><?php echo wpinv_get_business_footer(); ?></div> |
48 | 48 | </div> |
49 | 49 | </div> |
50 | - <?php do_action( 'wpinv_invalid_invoice_after_footer' ); ?> |
|
50 | + <?php do_action('wpinv_invalid_invoice_after_footer'); ?> |
|
51 | 51 | </htmlpagefooter> |
52 | 52 | <!-- End Footer ///// --> |
53 | 53 | </div> |
54 | - <?php do_action( 'wpinv_invalid_invoice_body_end' ); ?> |
|
54 | + <?php do_action('wpinv_invalid_invoice_body_end'); ?> |
|
55 | 55 | </body> |
56 | 56 | </html> |
57 | 57 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -function wpinv_get_subscriptions( $args = array() ) { |
|
3 | - if ( empty( $args['parent_invoice_id'] ) ) { |
|
2 | +function wpinv_get_subscriptions($args = array()) { |
|
3 | + if (empty($args['parent_invoice_id'])) { |
|
4 | 4 | return false; |
5 | 5 | } |
6 | 6 | |
@@ -14,18 +14,18 @@ discard block |
||
14 | 14 | ); |
15 | 15 | |
16 | 16 | $args['post_parent'] = $args['parent_invoice_id']; |
17 | - $args = wp_parse_args( $args, $defaults ); |
|
17 | + $args = wp_parse_args($args, $defaults); |
|
18 | 18 | |
19 | - if( $args['numberposts'] < 1 ) { |
|
19 | + if ($args['numberposts'] < 1) { |
|
20 | 20 | $args['numberposts'] = 999999999999; |
21 | 21 | } |
22 | 22 | |
23 | - $posts = get_posts( $args ); |
|
23 | + $posts = get_posts($args); |
|
24 | 24 | $subscriptions = array(); |
25 | - if ( !empty( $posts ) ) { |
|
26 | - foreach ( $posts as $post ) { |
|
27 | - if ( !empty( $post->ID ) ) { |
|
28 | - $subscriptions[] = wpinv_get_invoice( $post->ID ); |
|
25 | + if (!empty($posts)) { |
|
26 | + foreach ($posts as $post) { |
|
27 | + if (!empty($post->ID)) { |
|
28 | + $subscriptions[] = wpinv_get_invoice($post->ID); |
|
29 | 29 | } |
30 | 30 | } |
31 | 31 | } |
@@ -33,19 +33,19 @@ discard block |
||
33 | 33 | |
34 | 34 | return $subscriptions; |
35 | 35 | } |
36 | -function wpinv_get_subscription( $id = 0, $by_profile_id = false ) { |
|
36 | +function wpinv_get_subscription($id = 0, $by_profile_id = false) { |
|
37 | 37 | global $wpdb; |
38 | 38 | |
39 | - if ( empty( $id ) ) { |
|
39 | + if (empty($id)) { |
|
40 | 40 | return false; |
41 | 41 | } |
42 | 42 | |
43 | - $id = esc_sql( $id ); |
|
43 | + $id = esc_sql($id); |
|
44 | 44 | |
45 | - $invoice_id = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1" ); |
|
45 | + $invoice_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1"); |
|
46 | 46 | |
47 | - if ( $invoice_id != null ) { |
|
48 | - return wpinv_get_invoice( $invoice_id ); |
|
47 | + if ($invoice_id != null) { |
|
48 | + return wpinv_get_invoice($invoice_id); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | return false; |
@@ -55,46 +55,46 @@ discard block |
||
55 | 55 | * Records a new payment on the subscription |
56 | 56 | * |
57 | 57 | */ |
58 | -function wpinv_recurring_add_subscription_payment( $parent_invoice_id, $subscription_args = array() ) { |
|
59 | - $args = wp_parse_args( $subscription_args, array( |
|
58 | +function wpinv_recurring_add_subscription_payment($parent_invoice_id, $subscription_args = array()) { |
|
59 | + $args = wp_parse_args($subscription_args, array( |
|
60 | 60 | 'amount' => '', |
61 | 61 | 'transaction_id' => '', |
62 | 62 | 'gateway' => '' |
63 | - ) ); |
|
63 | + )); |
|
64 | 64 | |
65 | - if ( wpinv_payment_exists( $args['transaction_id'] ) ) { |
|
65 | + if (wpinv_payment_exists($args['transaction_id'])) { |
|
66 | 66 | return false; |
67 | 67 | } |
68 | 68 | |
69 | - $parent_invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
70 | - if ( empty( $parent_invoice ) ) { |
|
69 | + $parent_invoice = wpinv_get_invoice($parent_invoice_id); |
|
70 | + if (empty($parent_invoice)) { |
|
71 | 71 | return; |
72 | 72 | } |
73 | 73 | |
74 | 74 | $invoice = new WPInv_Invoice(); |
75 | - $invoice->set( 'parent_invoice', $parent_invoice_id ); |
|
76 | - $invoice->set( 'currency', $parent_invoice->get_currency() ); |
|
77 | - $invoice->set( 'transaction_id', $args['transaction_id'] ); |
|
78 | - $invoice->set( 'key', $parent_invoice->generate_key() ); |
|
79 | - $invoice->set( 'ip', $parent_invoice->ip ); |
|
80 | - $invoice->set( 'user_id', $parent_invoice->get_user_id() ); |
|
81 | - $invoice->set( 'first_name', $parent_invoice->get_first_name() ); |
|
82 | - $invoice->set( 'last_name', $parent_invoice->get_last_name() ); |
|
83 | - $invoice->set( 'phone', $parent_invoice->phone ); |
|
84 | - $invoice->set( 'address', $parent_invoice->address ); |
|
85 | - $invoice->set( 'city', $parent_invoice->city ); |
|
86 | - $invoice->set( 'country', $parent_invoice->country ); |
|
87 | - $invoice->set( 'state', $parent_invoice->state ); |
|
88 | - $invoice->set( 'zip', $parent_invoice->zip ); |
|
89 | - $invoice->set( 'company', $parent_invoice->company ); |
|
90 | - $invoice->set( 'vat_number', $parent_invoice->vat_number ); |
|
91 | - $invoice->set( 'vat_rate', $parent_invoice->vat_rate ); |
|
92 | - $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed ); |
|
93 | - |
|
94 | - if ( empty( $args['gateway'] ) ) { |
|
95 | - $invoice->set( 'gateway', $parent_invoice->get_gateway() ); |
|
75 | + $invoice->set('parent_invoice', $parent_invoice_id); |
|
76 | + $invoice->set('currency', $parent_invoice->get_currency()); |
|
77 | + $invoice->set('transaction_id', $args['transaction_id']); |
|
78 | + $invoice->set('key', $parent_invoice->generate_key()); |
|
79 | + $invoice->set('ip', $parent_invoice->ip); |
|
80 | + $invoice->set('user_id', $parent_invoice->get_user_id()); |
|
81 | + $invoice->set('first_name', $parent_invoice->get_first_name()); |
|
82 | + $invoice->set('last_name', $parent_invoice->get_last_name()); |
|
83 | + $invoice->set('phone', $parent_invoice->phone); |
|
84 | + $invoice->set('address', $parent_invoice->address); |
|
85 | + $invoice->set('city', $parent_invoice->city); |
|
86 | + $invoice->set('country', $parent_invoice->country); |
|
87 | + $invoice->set('state', $parent_invoice->state); |
|
88 | + $invoice->set('zip', $parent_invoice->zip); |
|
89 | + $invoice->set('company', $parent_invoice->company); |
|
90 | + $invoice->set('vat_number', $parent_invoice->vat_number); |
|
91 | + $invoice->set('vat_rate', $parent_invoice->vat_rate); |
|
92 | + $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed); |
|
93 | + |
|
94 | + if (empty($args['gateway'])) { |
|
95 | + $invoice->set('gateway', $parent_invoice->get_gateway()); |
|
96 | 96 | } else { |
97 | - $invoice->set( 'gateway', $args['gateway'] ); |
|
97 | + $invoice->set('gateway', $args['gateway']); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | $recurring_details = $parent_invoice->get_recurring_details(); |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | // increase the earnings for each item in the subscription |
103 | 103 | $items = $recurring_details['cart_details']; |
104 | 104 | |
105 | - if ( $items ) { |
|
105 | + if ($items) { |
|
106 | 106 | $add_items = array(); |
107 | 107 | $cart_details = array(); |
108 | 108 | |
109 | - foreach ( $items as $item ) { |
|
109 | + foreach ($items as $item) { |
|
110 | 110 | $add_item = array(); |
111 | 111 | $add_item['id'] = $item['id']; |
112 | 112 | $add_item['quantity'] = $item['quantity']; |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | break; |
117 | 117 | } |
118 | 118 | |
119 | - $invoice->set( 'items', $add_items ); |
|
119 | + $invoice->set('items', $add_items); |
|
120 | 120 | $invoice->cart_details = $cart_details; |
121 | 121 | } |
122 | 122 | |
@@ -126,277 +126,277 @@ discard block |
||
126 | 126 | $tax = $recurring_details['tax']; |
127 | 127 | $discount = $recurring_details['discount']; |
128 | 128 | |
129 | - if ( $discount > 0 ) { |
|
130 | - $invoice->set( 'discount_code', $parent_invoice->discount_code ); |
|
129 | + if ($discount > 0) { |
|
130 | + $invoice->set('discount_code', $parent_invoice->discount_code); |
|
131 | 131 | } |
132 | 132 | |
133 | - $invoice->subtotal = wpinv_round_amount( $subtotal ); |
|
134 | - $invoice->tax = wpinv_round_amount( $tax ); |
|
135 | - $invoice->discount = wpinv_round_amount( $discount ); |
|
136 | - $invoice->total = wpinv_round_amount( $total ); |
|
133 | + $invoice->subtotal = wpinv_round_amount($subtotal); |
|
134 | + $invoice->tax = wpinv_round_amount($tax); |
|
135 | + $invoice->discount = wpinv_round_amount($discount); |
|
136 | + $invoice->total = wpinv_round_amount($total); |
|
137 | 137 | $invoice->save(); |
138 | 138 | |
139 | - wpinv_update_payment_status( $invoice->ID, 'publish' ); |
|
139 | + wpinv_update_payment_status($invoice->ID, 'publish'); |
|
140 | 140 | sleep(1); |
141 | - wpinv_update_payment_status( $invoice->ID, 'wpi-renewal' ); |
|
141 | + wpinv_update_payment_status($invoice->ID, 'wpi-renewal'); |
|
142 | 142 | |
143 | - $invoice = wpinv_get_invoice( $invoice->ID ); |
|
143 | + $invoice = wpinv_get_invoice($invoice->ID); |
|
144 | 144 | |
145 | - $subscription_data = wpinv_payment_subscription_data( $parent_invoice ); |
|
145 | + $subscription_data = wpinv_payment_subscription_data($parent_invoice); |
|
146 | 146 | $subscription_data['recurring_amount'] = $invoice->get_total(); |
147 | - $subscription_data['created'] = current_time( 'mysql', 0 ); |
|
148 | - $subscription_data['expiration'] = $invoice->get_new_expiration( $subscription_data['item_id'] ); |
|
147 | + $subscription_data['created'] = current_time('mysql', 0); |
|
148 | + $subscription_data['expiration'] = $invoice->get_new_expiration($subscription_data['item_id']); |
|
149 | 149 | |
150 | 150 | // Retrieve pending subscription from database and update it's status to active and set proper profile ID |
151 | - $invoice->update_subscription( $subscription_data ); |
|
151 | + $invoice->update_subscription($subscription_data); |
|
152 | 152 | |
153 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args ); |
|
154 | - do_action( 'wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args ); |
|
153 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args); |
|
154 | + do_action('wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args); |
|
155 | 155 | |
156 | 156 | return $invoice; |
157 | 157 | } |
158 | 158 | |
159 | -function wpinv_payment_exists( $txn_id = '' ) { |
|
159 | +function wpinv_payment_exists($txn_id = '') { |
|
160 | 160 | global $wpdb; |
161 | 161 | |
162 | - if ( empty( $txn_id ) ) { |
|
162 | + if (empty($txn_id)) { |
|
163 | 163 | return false; |
164 | 164 | } |
165 | 165 | |
166 | - $txn_id = esc_sql( $txn_id ); |
|
166 | + $txn_id = esc_sql($txn_id); |
|
167 | 167 | |
168 | - $invoice = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" ); |
|
168 | + $invoice = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1"); |
|
169 | 169 | |
170 | - if ( $invoice != null ) { |
|
170 | + if ($invoice != null) { |
|
171 | 171 | return true; |
172 | 172 | } |
173 | 173 | |
174 | 174 | return false; |
175 | 175 | } |
176 | 176 | |
177 | -function wpinv_is_subscription_payment( $invoice = '' ) { |
|
178 | - if ( empty( $invoice ) ) { |
|
177 | +function wpinv_is_subscription_payment($invoice = '') { |
|
178 | + if (empty($invoice)) { |
|
179 | 179 | return false; |
180 | 180 | } |
181 | 181 | |
182 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
183 | - $invoice = wpinv_get_invoice( $invoice ); |
|
182 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
183 | + $invoice = wpinv_get_invoice($invoice); |
|
184 | 184 | } |
185 | 185 | |
186 | - if ( empty( $invoice ) ) { |
|
186 | + if (empty($invoice)) { |
|
187 | 187 | return false; |
188 | 188 | } |
189 | 189 | |
190 | - if ( $invoice->is_renewal() ) { |
|
190 | + if ($invoice->is_renewal()) { |
|
191 | 191 | return true; |
192 | 192 | } |
193 | 193 | |
194 | 194 | return false; |
195 | 195 | } |
196 | 196 | |
197 | -function wpinv_payment_subscription_data( $invoice = '' ) { |
|
198 | - if ( empty( $invoice ) ) { |
|
197 | +function wpinv_payment_subscription_data($invoice = '') { |
|
198 | + if (empty($invoice)) { |
|
199 | 199 | return false; |
200 | 200 | } |
201 | 201 | |
202 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
203 | - $invoice = wpinv_get_invoice( $invoice ); |
|
202 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
203 | + $invoice = wpinv_get_invoice($invoice); |
|
204 | 204 | } |
205 | 205 | |
206 | - if ( empty( $invoice ) ) { |
|
206 | + if (empty($invoice)) { |
|
207 | 207 | return false; |
208 | 208 | } |
209 | 209 | |
210 | 210 | return $invoice->get_subscription_data(); |
211 | 211 | } |
212 | 212 | |
213 | -function wpinv_payment_link_transaction_id( $invoice = '' ) { |
|
214 | - if ( empty( $invoice ) ) { |
|
213 | +function wpinv_payment_link_transaction_id($invoice = '') { |
|
214 | + if (empty($invoice)) { |
|
215 | 215 | return false; |
216 | 216 | } |
217 | 217 | |
218 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
219 | - $invoice = wpinv_get_invoice( $invoice ); |
|
218 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
219 | + $invoice = wpinv_get_invoice($invoice); |
|
220 | 220 | } |
221 | 221 | |
222 | - if ( empty( $invoice ) ) { |
|
222 | + if (empty($invoice)) { |
|
223 | 223 | return false; |
224 | 224 | } |
225 | 225 | |
226 | - return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice ); |
|
226 | + return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice); |
|
227 | 227 | } |
228 | 228 | |
229 | -function wpinv_get_pretty_subscription_period( $period ) { |
|
229 | +function wpinv_get_pretty_subscription_period($period) { |
|
230 | 230 | $frequency = ''; |
231 | 231 | //Format period details |
232 | - switch ( $period ) { |
|
232 | + switch ($period) { |
|
233 | 233 | case 'D' : |
234 | 234 | case 'day' : |
235 | - $frequency = __( 'Daily', 'invoicing' ); |
|
235 | + $frequency = __('Daily', 'invoicing'); |
|
236 | 236 | break; |
237 | 237 | case 'W' : |
238 | 238 | case 'week' : |
239 | - $frequency = __( 'Weekly', 'invoicing' ); |
|
239 | + $frequency = __('Weekly', 'invoicing'); |
|
240 | 240 | break; |
241 | 241 | case 'M' : |
242 | 242 | case 'month' : |
243 | - $frequency = __( 'Monthly', 'invoicing' ); |
|
243 | + $frequency = __('Monthly', 'invoicing'); |
|
244 | 244 | break; |
245 | 245 | case 'Y' : |
246 | 246 | case 'year' : |
247 | - $frequency = __( 'Yearly', 'invoicing' ); |
|
247 | + $frequency = __('Yearly', 'invoicing'); |
|
248 | 248 | break; |
249 | 249 | default : |
250 | - $frequency = apply_filters( 'wpinv_pretty_subscription_period', $frequency, $period ); |
|
250 | + $frequency = apply_filters('wpinv_pretty_subscription_period', $frequency, $period); |
|
251 | 251 | break; |
252 | 252 | } |
253 | 253 | |
254 | 254 | return $frequency; |
255 | 255 | } |
256 | 256 | |
257 | -function wpinv_get_pretty_subscription_period_name( $period ) { |
|
257 | +function wpinv_get_pretty_subscription_period_name($period) { |
|
258 | 258 | $frequency = ''; |
259 | 259 | //Format period details |
260 | - switch ( $period ) { |
|
260 | + switch ($period) { |
|
261 | 261 | case 'D' : |
262 | 262 | case 'day' : |
263 | - $frequency = __( 'Day', 'invoicing' ); |
|
263 | + $frequency = __('Day', 'invoicing'); |
|
264 | 264 | break; |
265 | 265 | case 'W' : |
266 | 266 | case 'week' : |
267 | - $frequency = __( 'Week', 'invoicing' ); |
|
267 | + $frequency = __('Week', 'invoicing'); |
|
268 | 268 | break; |
269 | 269 | case 'M' : |
270 | 270 | case 'month' : |
271 | - $frequency = __( 'Month', 'invoicing' ); |
|
271 | + $frequency = __('Month', 'invoicing'); |
|
272 | 272 | break; |
273 | 273 | case 'Y' : |
274 | 274 | case 'year' : |
275 | - $frequency = __( 'Year', 'invoicing' ); |
|
275 | + $frequency = __('Year', 'invoicing'); |
|
276 | 276 | break; |
277 | 277 | default : |
278 | - $frequency = apply_filters( 'wpinv_pretty_subscription_period_name', $frequency, $period ); |
|
278 | + $frequency = apply_filters('wpinv_pretty_subscription_period_name', $frequency, $period); |
|
279 | 279 | break; |
280 | 280 | } |
281 | 281 | |
282 | 282 | return $frequency; |
283 | 283 | } |
284 | 284 | |
285 | -function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) { |
|
285 | +function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) { |
|
286 | 286 | $interval = (int)$interval > 0 ? (int)$interval : 1; |
287 | 287 | |
288 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
289 | - $amount = __( 'Free', 'invoicing' ); |
|
288 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
289 | + $amount = __('Free', 'invoicing'); |
|
290 | 290 | $interval = $trial_interval; |
291 | 291 | $period = $trial_period; |
292 | 292 | } |
293 | 293 | |
294 | 294 | $description = ''; |
295 | - switch ( $period ) { |
|
295 | + switch ($period) { |
|
296 | 296 | case 'D' : |
297 | 297 | case 'day' : |
298 | - $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
298 | + $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval); |
|
299 | 299 | break; |
300 | 300 | case 'W' : |
301 | 301 | case 'week' : |
302 | - $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
302 | + $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
303 | 303 | break; |
304 | 304 | case 'M' : |
305 | 305 | case 'month' : |
306 | - $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
306 | + $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval); |
|
307 | 307 | break; |
308 | 308 | case 'Y' : |
309 | 309 | case 'year' : |
310 | - $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
310 | + $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval); |
|
311 | 311 | break; |
312 | 312 | } |
313 | 313 | |
314 | - return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval ); |
|
314 | + return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval); |
|
315 | 315 | } |
316 | 316 | |
317 | -function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) { |
|
317 | +function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) { |
|
318 | 318 | $interval = (int)$interval > 0 ? (int)$interval : 1; |
319 | 319 | $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0; |
320 | 320 | |
321 | 321 | $description = ''; |
322 | - switch ( $period ) { |
|
322 | + switch ($period) { |
|
323 | 323 | case 'D' : |
324 | 324 | case 'day' : |
325 | - if ( (int)$bill_times > 0 ) { |
|
326 | - if ( $interval > 1 ) { |
|
327 | - if ( $bill_times > 1 ) { |
|
328 | - $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
325 | + if ((int)$bill_times > 0) { |
|
326 | + if ($interval > 1) { |
|
327 | + if ($bill_times > 1) { |
|
328 | + $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
329 | 329 | } else { |
330 | - $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval ); |
|
330 | + $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval); |
|
331 | 331 | } |
332 | 332 | } else { |
333 | - $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
333 | + $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
334 | 334 | } |
335 | 335 | } else { |
336 | - $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval ); |
|
336 | + $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval); |
|
337 | 337 | } |
338 | 338 | break; |
339 | 339 | case 'W' : |
340 | 340 | case 'week' : |
341 | - if ( (int)$bill_times > 0 ) { |
|
342 | - if ( $interval > 1 ) { |
|
343 | - if ( $bill_times > 1 ) { |
|
344 | - $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
341 | + if ((int)$bill_times > 0) { |
|
342 | + if ($interval > 1) { |
|
343 | + if ($bill_times > 1) { |
|
344 | + $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
345 | 345 | } else { |
346 | - $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval ); |
|
346 | + $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval); |
|
347 | 347 | } |
348 | 348 | } else { |
349 | - $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
349 | + $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
350 | 350 | } |
351 | 351 | } else { |
352 | - $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
352 | + $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
353 | 353 | } |
354 | 354 | break; |
355 | 355 | case 'M' : |
356 | 356 | case 'month' : |
357 | - if ( (int)$bill_times > 0 ) { |
|
358 | - if ( $interval > 1 ) { |
|
359 | - if ( $bill_times > 1 ) { |
|
360 | - $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
357 | + if ((int)$bill_times > 0) { |
|
358 | + if ($interval > 1) { |
|
359 | + if ($bill_times > 1) { |
|
360 | + $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
361 | 361 | } else { |
362 | - $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval ); |
|
362 | + $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval); |
|
363 | 363 | } |
364 | 364 | } else { |
365 | - $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
365 | + $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
366 | 366 | } |
367 | 367 | } else { |
368 | - $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
368 | + $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval); |
|
369 | 369 | } |
370 | 370 | break; |
371 | 371 | case 'Y' : |
372 | 372 | case 'year' : |
373 | - if ( (int)$bill_times > 0 ) { |
|
374 | - if ( $interval > 1 ) { |
|
375 | - if ( $bill_times > 1 ) { |
|
376 | - $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
373 | + if ((int)$bill_times > 0) { |
|
374 | + if ($interval > 1) { |
|
375 | + if ($bill_times > 1) { |
|
376 | + $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
377 | 377 | } else { |
378 | - $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval ); |
|
378 | + $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval); |
|
379 | 379 | } |
380 | 380 | } else { |
381 | - $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
381 | + $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
382 | 382 | } |
383 | 383 | } else { |
384 | - $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
384 | + $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval); |
|
385 | 385 | } |
386 | 386 | break; |
387 | 387 | } |
388 | 388 | |
389 | - return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
389 | + return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
390 | 390 | } |
391 | 391 | |
392 | -function wpinv_subscription_payment_desc( $invoice ) { |
|
393 | - if ( empty( $invoice ) ) { |
|
392 | +function wpinv_subscription_payment_desc($invoice) { |
|
393 | + if (empty($invoice)) { |
|
394 | 394 | return NULL; |
395 | 395 | } |
396 | 396 | |
397 | 397 | $description = ''; |
398 | - if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { |
|
399 | - if ( $item->has_free_trial() ) { |
|
398 | + if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) { |
|
399 | + if ($item->has_free_trial()) { |
|
400 | 400 | $trial_period = $item->get_trial_period(); |
401 | 401 | $trial_interval = $item->get_trial_interval(); |
402 | 402 | } else { |
@@ -404,45 +404,45 @@ discard block |
||
404 | 404 | $trial_interval = 0; |
405 | 405 | } |
406 | 406 | |
407 | - $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() ); |
|
407 | + $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency()); |
|
408 | 408 | } |
409 | 409 | |
410 | - return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice ); |
|
410 | + return apply_filters('wpinv_subscription_payment_desc', $description, $invoice); |
|
411 | 411 | } |
412 | 412 | |
413 | -function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) { |
|
414 | - $initial_total = wpinv_round_amount( $initial ); |
|
415 | - $recurring_total = wpinv_round_amount( $recurring ); |
|
413 | +function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') { |
|
414 | + $initial_total = wpinv_round_amount($initial); |
|
415 | + $recurring_total = wpinv_round_amount($recurring); |
|
416 | 416 | |
417 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
417 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
418 | 418 | // Free trial |
419 | 419 | } else { |
420 | - if ( $bill_times == 1 ) { |
|
420 | + if ($bill_times == 1) { |
|
421 | 421 | $recurring_total = $initial_total; |
422 | - } else if ( $bill_times > 1 && $initial_total != $recurring_total ) { |
|
422 | + } else if ($bill_times > 1 && $initial_total != $recurring_total) { |
|
423 | 423 | $bill_times--; |
424 | 424 | } |
425 | 425 | } |
426 | 426 | |
427 | - $initial_amount = wpinv_price( wpinv_format_amount( $initial_total ), $currency ); |
|
428 | - $recurring_amount = wpinv_price( wpinv_format_amount( $recurring_total ), $currency ); |
|
427 | + $initial_amount = wpinv_price(wpinv_format_amount($initial_total), $currency); |
|
428 | + $recurring_amount = wpinv_price(wpinv_format_amount($recurring_total), $currency); |
|
429 | 429 | |
430 | - $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
430 | + $recurring = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
431 | 431 | |
432 | - if ( $initial_total != $recurring_total ) { |
|
433 | - $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval ); |
|
432 | + if ($initial_total != $recurring_total) { |
|
433 | + $initial = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval); |
|
434 | 434 | |
435 | - $description = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring ); |
|
435 | + $description = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring); |
|
436 | 436 | } else { |
437 | 437 | $description = $recurring; |
438 | 438 | } |
439 | 439 | |
440 | - return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency ); |
|
440 | + return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency); |
|
441 | 441 | } |
442 | 442 | |
443 | -function wpinv_recurring_send_payment_failed( $invoice ) { |
|
444 | - if ( !empty( $invoice->ID ) ) { |
|
445 | - wpinv_failed_invoice_notification( $invoice->ID ); |
|
443 | +function wpinv_recurring_send_payment_failed($invoice) { |
|
444 | + if (!empty($invoice->ID)) { |
|
445 | + wpinv_failed_invoice_notification($invoice->ID); |
|
446 | 446 | } |
447 | 447 | } |
448 | -add_action( 'wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1 ); |
|
449 | 448 | \ No newline at end of file |
449 | +add_action('wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1); |
|
450 | 450 | \ No newline at end of file |
@@ -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( !( (float)wpinv_payment_total( $payment ) > 0 ) ) { |
|
129 | - $label = __( 'Free Purchase', 'invoicing' ); |
|
127 | + if ($gateway == 'manual' && $payment) { |
|
128 | + if (!((float)wpinv_payment_total($payment) > 0)) { |
|
129 | + $label = __('Free Purchase', '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,123 +416,123 @@ 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_sort_code'] = array( |
473 | 473 | 'type' => 'text', |
474 | 474 | 'id' => 'bank_transfer_sort_code', |
475 | - 'name' => __( 'Sort Code', 'invoicing' ), |
|
476 | - 'std' => __( '12-34-56', 'invoicing' ), |
|
475 | + 'name' => __('Sort Code', 'invoicing'), |
|
476 | + 'std' => __('12-34-56', 'invoicing'), |
|
477 | 477 | ); |
478 | 478 | |
479 | 479 | $setting['bank_transfer_info'] = array( |
480 | 480 | 'id' => 'bank_transfer_info', |
481 | - 'name' => __( 'Instructions', 'invoicing' ), |
|
482 | - 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
|
481 | + 'name' => __('Instructions', 'invoicing'), |
|
482 | + 'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'), |
|
483 | 483 | 'type' => 'textarea', |
484 | - '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' ), |
|
484 | + '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'), |
|
485 | 485 | 'cols' => 37, |
486 | 486 | 'rows' => 5 |
487 | 487 | ); |
488 | 488 | |
489 | 489 | return $setting; |
490 | 490 | } |
491 | -add_filter( 'wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1 ); |
|
491 | +add_filter('wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1); |
|
492 | 492 | |
493 | 493 | // Authorize.Net settings |
494 | -function wpinv_gateway_settings_authorizenet( $setting ) { |
|
495 | - $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __( '( currencies supported: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing' ); |
|
496 | - $setting['authorizenet_desc']['std'] = __( 'Pay using a Authorize.Net to process credit card / debit card transactions.', 'invoicing' ); |
|
494 | +function wpinv_gateway_settings_authorizenet($setting) { |
|
495 | + $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __('( currencies supported: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing'); |
|
496 | + $setting['authorizenet_desc']['std'] = __('Pay using a Authorize.Net to process credit card / debit card transactions.', 'invoicing'); |
|
497 | 497 | |
498 | 498 | $setting['authorizenet_sandbox'] = array( |
499 | 499 | 'type' => 'checkbox', |
500 | 500 | 'id' => 'authorizenet_sandbox', |
501 | - 'name' => __( 'Authorize.Net Test Mode', 'invoicing' ), |
|
502 | - 'desc' => __( 'Enable Authorize.Net test mode to test payments.', 'invoicing' ), |
|
501 | + 'name' => __('Authorize.Net Test Mode', 'invoicing'), |
|
502 | + 'desc' => __('Enable Authorize.Net test mode to test payments.', 'invoicing'), |
|
503 | 503 | 'std' => 1 |
504 | 504 | ); |
505 | 505 | |
506 | 506 | $setting['authorizenet_login_id'] = array( |
507 | 507 | 'type' => 'text', |
508 | 508 | 'id' => 'authorizenet_login_id', |
509 | - 'name' => __( 'API Login ID', 'invoicing' ), |
|
510 | - 'desc' => __( 'API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing' ), |
|
509 | + 'name' => __('API Login ID', 'invoicing'), |
|
510 | + 'desc' => __('API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing'), |
|
511 | 511 | 'std' => '2j4rBekUnD', |
512 | 512 | ); |
513 | 513 | |
514 | 514 | $setting['authorizenet_transaction_key'] = array( |
515 | 515 | 'type' => 'text', |
516 | 516 | 'id' => 'authorizenet_transaction_key', |
517 | - 'name' => __( 'Transaction Key', 'invoicing' ), |
|
518 | - 'desc' => __( 'Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing' ), |
|
517 | + 'name' => __('Transaction Key', 'invoicing'), |
|
518 | + 'desc' => __('Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing'), |
|
519 | 519 | 'std' => '4vyBUOJgR74679xa', |
520 | 520 | ); |
521 | 521 | |
522 | 522 | $setting['authorizenet_md5_hash'] = array( |
523 | 523 | 'type' => 'text', |
524 | 524 | 'id' => 'authorizenet_md5_hash', |
525 | - 'name' => __( 'MD5-Hash', 'invoicing' ), |
|
526 | - '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' ), |
|
525 | + 'name' => __('MD5-Hash', 'invoicing'), |
|
526 | + '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'), |
|
527 | 527 | 'std' => '', |
528 | 528 | ); |
529 | 529 | |
530 | 530 | $setting['authorizenet_ipn_url'] = array( |
531 | 531 | 'type' => 'ipn_url', |
532 | 532 | 'id' => 'authorizenet_ipn_url', |
533 | - 'name' => __( 'Silent Post URL', 'invoicing' ), |
|
534 | - 'std' => wpinv_get_ipn_url( 'authorizenet' ), |
|
535 | - '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' ), |
|
533 | + 'name' => __('Silent Post URL', 'invoicing'), |
|
534 | + 'std' => wpinv_get_ipn_url('authorizenet'), |
|
535 | + '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'), |
|
536 | 536 | 'size' => 'large', |
537 | 537 | 'custom' => 'authorizenet', |
538 | 538 | 'readonly' => true |
@@ -540,25 +540,25 @@ discard block |
||
540 | 540 | |
541 | 541 | return $setting; |
542 | 542 | } |
543 | -add_filter( 'wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1 ); |
|
543 | +add_filter('wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1); |
|
544 | 544 | |
545 | 545 | // Worldpay settings |
546 | -function wpinv_gateway_settings_worldpay( $setting ) { |
|
547 | - $setting['worldpay_desc']['std'] = __( 'Pay using a Worldpay account to process credit card / debit card transactions.', 'invoicing' ); |
|
546 | +function wpinv_gateway_settings_worldpay($setting) { |
|
547 | + $setting['worldpay_desc']['std'] = __('Pay using a Worldpay account to process credit card / debit card transactions.', 'invoicing'); |
|
548 | 548 | |
549 | 549 | $setting['worldpay_sandbox'] = array( |
550 | 550 | 'type' => 'checkbox', |
551 | 551 | 'id' => 'worldpay_sandbox', |
552 | - 'name' => __( 'Worldpay Test Mode', 'invoicing' ), |
|
553 | - 'desc' => __( 'This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing' ), |
|
552 | + 'name' => __('Worldpay Test Mode', 'invoicing'), |
|
553 | + 'desc' => __('This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing'), |
|
554 | 554 | 'std' => 1 |
555 | 555 | ); |
556 | 556 | |
557 | 557 | $setting['worldpay_instId'] = array( |
558 | 558 | 'type' => 'text', |
559 | 559 | 'id' => 'worldpay_instId', |
560 | - 'name' => __( 'Installation Id', 'invoicing' ), |
|
561 | - 'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ), |
|
560 | + 'name' => __('Installation Id', 'invoicing'), |
|
561 | + 'desc' => __('Your installation id. Ex: 211616', 'invoicing'), |
|
562 | 562 | 'std' => '211616', |
563 | 563 | ); |
564 | 564 | /* |
@@ -574,9 +574,9 @@ discard block |
||
574 | 574 | $setting['worldpay_ipn_url'] = array( |
575 | 575 | 'type' => 'ipn_url', |
576 | 576 | 'id' => 'worldpay_ipn_url', |
577 | - 'name' => __( 'Worldpay Callback Url', 'invoicing' ), |
|
578 | - 'std' => wpinv_get_ipn_url( 'worldpay' ), |
|
579 | - '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>' ), |
|
577 | + 'name' => __('Worldpay Callback Url', 'invoicing'), |
|
578 | + 'std' => wpinv_get_ipn_url('worldpay'), |
|
579 | + '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>'), |
|
580 | 580 | 'size' => 'large', |
581 | 581 | 'custom' => 'worldpay', |
582 | 582 | 'readonly' => true |
@@ -584,95 +584,95 @@ discard block |
||
584 | 584 | |
585 | 585 | return $setting; |
586 | 586 | } |
587 | -add_filter( 'wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1 ); |
|
587 | +add_filter('wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1); |
|
588 | 588 | |
589 | -function wpinv_ipn_url_callback( $args ) { |
|
590 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
589 | +function wpinv_ipn_url_callback($args) { |
|
590 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
591 | 591 | |
592 | 592 | $attrs = $args['readonly'] ? ' readonly' : ''; |
593 | 593 | |
594 | - $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">'; |
|
595 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
594 | + $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">'; |
|
595 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
596 | 596 | |
597 | 597 | echo $html; |
598 | 598 | } |
599 | 599 | |
600 | -function wpinv_is_test_mode( $gateway = '' ) { |
|
601 | - if ( empty( $gateway ) ) { |
|
600 | +function wpinv_is_test_mode($gateway = '') { |
|
601 | + if (empty($gateway)) { |
|
602 | 602 | return false; |
603 | 603 | } |
604 | 604 | |
605 | - $is_test_mode = wpinv_get_option( $gateway . '_sandbox', false ); |
|
605 | + $is_test_mode = wpinv_get_option($gateway . '_sandbox', false); |
|
606 | 606 | |
607 | - return apply_filters( 'wpinv_is_test_mode', $is_test_mode, $gateway ); |
|
607 | + return apply_filters('wpinv_is_test_mode', $is_test_mode, $gateway); |
|
608 | 608 | } |
609 | 609 | |
610 | -function wpinv_get_ipn_url( $gateway = '', $args = array() ) { |
|
611 | - $data = array( 'wpi-listener' => 'IPN' ); |
|
610 | +function wpinv_get_ipn_url($gateway = '', $args = array()) { |
|
611 | + $data = array('wpi-listener' => 'IPN'); |
|
612 | 612 | |
613 | - if ( !empty( $gateway ) ) { |
|
614 | - $data['wpi-gateway'] = wpinv_sanitize_key( $gateway ); |
|
613 | + if (!empty($gateway)) { |
|
614 | + $data['wpi-gateway'] = wpinv_sanitize_key($gateway); |
|
615 | 615 | } |
616 | 616 | |
617 | - $args = !empty( $args ) && is_array( $args ) ? array_merge( $data, $args ) : $data; |
|
617 | + $args = !empty($args) && is_array($args) ? array_merge($data, $args) : $data; |
|
618 | 618 | |
619 | - $ipn_url = add_query_arg( $args, home_url( 'index.php' ) ); |
|
619 | + $ipn_url = add_query_arg($args, home_url('index.php')); |
|
620 | 620 | |
621 | - return apply_filters( 'wpinv_ipn_url', $ipn_url ); |
|
621 | + return apply_filters('wpinv_ipn_url', $ipn_url); |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | function wpinv_listen_for_payment_ipn() { |
625 | 625 | // Regular PayPal IPN |
626 | - if ( isset( $_GET['wpi-listener'] ) && $_GET['wpi-listener'] == 'IPN' ) { |
|
627 | - do_action( 'wpinv_verify_payment_ipn' ); |
|
626 | + if (isset($_GET['wpi-listener']) && $_GET['wpi-listener'] == 'IPN') { |
|
627 | + do_action('wpinv_verify_payment_ipn'); |
|
628 | 628 | |
629 | - if ( !empty( $_GET['wpi-gateway'] ) ) { |
|
630 | - wpinv_error_log( sanitize_text_field( $_GET['wpi-gateway'] ), 'wpinv_listen_for_payment_ipn()', __FILE__, __LINE__ ); |
|
631 | - do_action( 'wpinv_verify_' . sanitize_text_field( $_GET['wpi-gateway'] ) . '_ipn' ); |
|
629 | + if (!empty($_GET['wpi-gateway'])) { |
|
630 | + wpinv_error_log(sanitize_text_field($_GET['wpi-gateway']), 'wpinv_listen_for_payment_ipn()', __FILE__, __LINE__); |
|
631 | + do_action('wpinv_verify_' . sanitize_text_field($_GET['wpi-gateway']) . '_ipn'); |
|
632 | 632 | } |
633 | 633 | } |
634 | 634 | } |
635 | -add_action( 'init', 'wpinv_listen_for_payment_ipn' ); |
|
635 | +add_action('init', 'wpinv_listen_for_payment_ipn'); |
|
636 | 636 | |
637 | 637 | function wpinv_get_bank_instructions() { |
638 | - $bank_instructions = wpinv_get_option( 'bank_transfer_info' ); |
|
638 | + $bank_instructions = wpinv_get_option('bank_transfer_info'); |
|
639 | 639 | |
640 | - return apply_filters( 'wpinv_bank_instructions', $bank_instructions ); |
|
640 | + return apply_filters('wpinv_bank_instructions', $bank_instructions); |
|
641 | 641 | } |
642 | 642 | |
643 | -function wpinv_get_bank_info( $filtered = false ) { |
|
643 | +function wpinv_get_bank_info($filtered = false) { |
|
644 | 644 | $bank_fields = array( |
645 | - 'bank_transfer_ac_name' => __( 'Account Name', 'invoicing' ), |
|
646 | - 'bank_transfer_ac_no' => __( 'Account Number', 'invoicing' ), |
|
647 | - 'bank_transfer_bank_name' => __( 'Bank Name', 'invoicing' ), |
|
648 | - 'bank_transfer_ifsc' => __( 'IFSC code', 'invoicing' ), |
|
649 | - 'bank_transfer_iban' => __( 'IBAN', 'invoicing' ), |
|
650 | - 'bank_transfer_bic' => __( 'BIC/Swift code', 'invoicing' ), |
|
651 | - 'bank_transfer_sort_code' => __( 'Sort Code', 'invoicing' ) |
|
645 | + 'bank_transfer_ac_name' => __('Account Name', 'invoicing'), |
|
646 | + 'bank_transfer_ac_no' => __('Account Number', 'invoicing'), |
|
647 | + 'bank_transfer_bank_name' => __('Bank Name', 'invoicing'), |
|
648 | + 'bank_transfer_ifsc' => __('IFSC code', 'invoicing'), |
|
649 | + 'bank_transfer_iban' => __('IBAN', 'invoicing'), |
|
650 | + 'bank_transfer_bic' => __('BIC/Swift code', 'invoicing'), |
|
651 | + 'bank_transfer_sort_code' => __('Sort Code', 'invoicing') |
|
652 | 652 | ); |
653 | 653 | |
654 | 654 | $bank_info = array(); |
655 | - foreach ( $bank_fields as $field => $label ) { |
|
656 | - if ( $filtered && !( $value = wpinv_get_option( $field ) ) ) { |
|
655 | + foreach ($bank_fields as $field => $label) { |
|
656 | + if ($filtered && !($value = wpinv_get_option($field))) { |
|
657 | 657 | continue; |
658 | 658 | } |
659 | 659 | |
660 | - $bank_info[$field] = array( 'label' => $label, 'value' => $value ); |
|
660 | + $bank_info[$field] = array('label' => $label, 'value' => $value); |
|
661 | 661 | } |
662 | 662 | |
663 | - return apply_filters( 'wpinv_bank_info', $bank_info, $filtered ); |
|
663 | + return apply_filters('wpinv_bank_info', $bank_info, $filtered); |
|
664 | 664 | } |
665 | 665 | |
666 | -function wpinv_process_before_send_to_gateway( $invoice, $invoice_data = array() ) { |
|
667 | - if ( !empty( $invoice ) && $invoice->is_recurring() && $subscription_item = $invoice->get_recurring( true ) ) { |
|
666 | +function wpinv_process_before_send_to_gateway($invoice, $invoice_data = array()) { |
|
667 | + if (!empty($invoice) && $invoice->is_recurring() && $subscription_item = $invoice->get_recurring(true)) { |
|
668 | 668 | $args = array(); |
669 | 669 | $args['item_id'] = $subscription_item->ID; |
670 | - $args['initial_amount'] = wpinv_round_amount( $invoice->get_total() ); |
|
671 | - $args['recurring_amount'] = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) ); |
|
670 | + $args['initial_amount'] = wpinv_round_amount($invoice->get_total()); |
|
671 | + $args['recurring_amount'] = wpinv_round_amount($invoice->get_recurring_details('total')); |
|
672 | 672 | $args['currency'] = $invoice->get_currency(); |
673 | 673 | $args['period'] = $subscription_item->get_recurring_period(); |
674 | 674 | $args['interval'] = $subscription_item->get_recurring_interval(); |
675 | - if ( $subscription_item->has_free_trial() ) { |
|
675 | + if ($subscription_item->has_free_trial()) { |
|
676 | 676 | $args['trial_period'] = $subscription_item->get_trial_period(); |
677 | 677 | $args['trial_interval'] = $subscription_item->get_trial_interval(); |
678 | 678 | } else { |
@@ -681,25 +681,25 @@ discard block |
||
681 | 681 | } |
682 | 682 | $args['bill_times'] = (int)$subscription_item->get_recurring_limit(); |
683 | 683 | |
684 | - $invoice->update_subscription( $args ); |
|
684 | + $invoice->update_subscription($args); |
|
685 | 685 | } |
686 | 686 | } |
687 | -add_action( 'wpinv_checkout_before_send_to_gateway', 'wpinv_process_before_send_to_gateway', 10, 2 ); |
|
687 | +add_action('wpinv_checkout_before_send_to_gateway', 'wpinv_process_before_send_to_gateway', 10, 2); |
|
688 | 688 | |
689 | -function wpinv_get_post_data( $method = 'request' ) { |
|
689 | +function wpinv_get_post_data($method = 'request') { |
|
690 | 690 | $data = array(); |
691 | 691 | $request = $_REQUEST; |
692 | 692 | |
693 | - if ( $method == 'post' ) { |
|
694 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
693 | + if ($method == 'post') { |
|
694 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
695 | 695 | return $data; |
696 | 696 | } |
697 | 697 | |
698 | 698 | $request = $_POST; |
699 | 699 | } |
700 | 700 | |
701 | - if ( $method == 'get' ) { |
|
702 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET' ) { |
|
701 | + if ($method == 'get') { |
|
702 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET') { |
|
703 | 703 | return $data; |
704 | 704 | } |
705 | 705 | |
@@ -710,11 +710,11 @@ discard block |
||
710 | 710 | $post_data = ''; |
711 | 711 | |
712 | 712 | // Fallback just in case post_max_size is lower than needed |
713 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
714 | - $post_data = file_get_contents( 'php://input' ); |
|
713 | + if (ini_get('allow_url_fopen')) { |
|
714 | + $post_data = file_get_contents('php://input'); |
|
715 | 715 | } else { |
716 | 716 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
717 | - ini_set( 'post_max_size', '12M' ); |
|
717 | + ini_set('post_max_size', '12M'); |
|
718 | 718 | } |
719 | 719 | // Start the encoded data collection with notification command |
720 | 720 | $encoded_data = 'cmd=_notify-validate'; |
@@ -723,58 +723,58 @@ discard block |
||
723 | 723 | $arg_separator = wpinv_get_php_arg_separator_output(); |
724 | 724 | |
725 | 725 | // Verify there is a post_data |
726 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
726 | + if ($post_data || strlen($post_data) > 0) { |
|
727 | 727 | // Append the data |
728 | 728 | $encoded_data .= $arg_separator . $post_data; |
729 | 729 | } else { |
730 | 730 | // Check if POST is empty |
731 | - if ( empty( $request ) ) { |
|
731 | + if (empty($request)) { |
|
732 | 732 | // Nothing to do |
733 | 733 | return; |
734 | 734 | } else { |
735 | 735 | // Loop through each POST |
736 | - foreach ( $request as $key => $value ) { |
|
736 | + foreach ($request as $key => $value) { |
|
737 | 737 | // Encode the value and append the data |
738 | - $encoded_data .= $arg_separator . "$key=" . urlencode( $value ); |
|
738 | + $encoded_data .= $arg_separator . "$key=" . urlencode($value); |
|
739 | 739 | } |
740 | 740 | } |
741 | 741 | } |
742 | 742 | |
743 | 743 | // Convert collected post data to an array |
744 | - parse_str( $encoded_data, $data ); |
|
744 | + parse_str($encoded_data, $data); |
|
745 | 745 | |
746 | - foreach ( $data as $key => $value ) { |
|
747 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
748 | - $new_key = str_replace( '&', '&', $key ); |
|
749 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
746 | + foreach ($data as $key => $value) { |
|
747 | + if (false !== strpos($key, 'amp;')) { |
|
748 | + $new_key = str_replace('&', '&', $key); |
|
749 | + $new_key = str_replace('amp;', '&', $new_key); |
|
750 | 750 | |
751 | - unset( $data[ $key ] ); |
|
752 | - $data[ $new_key ] = sanitize_text_field( $value ); |
|
751 | + unset($data[$key]); |
|
752 | + $data[$new_key] = sanitize_text_field($value); |
|
753 | 753 | } |
754 | 754 | } |
755 | 755 | |
756 | 756 | return $data; |
757 | 757 | } |
758 | 758 | |
759 | -function wpinv_gateway_support_subscription( $gateway ) { |
|
759 | +function wpinv_gateway_support_subscription($gateway) { |
|
760 | 760 | $return = false; |
761 | 761 | |
762 | - if ( wpinv_is_gateway_active( $gateway ) ) { |
|
763 | - $return = apply_filters( 'wpinv_' . $gateway . '_support_subscription', false ); |
|
762 | + if (wpinv_is_gateway_active($gateway)) { |
|
763 | + $return = apply_filters('wpinv_' . $gateway . '_support_subscription', false); |
|
764 | 764 | } |
765 | 765 | |
766 | 766 | return $return; |
767 | 767 | } |
768 | 768 | |
769 | -function wpinv_payment_gateways_on_cart( $gateways = array() ) { |
|
770 | - if ( !empty( $gateways ) && wpinv_cart_has_recurring_item() ) { |
|
771 | - foreach ( $gateways as $gateway => $info ) { |
|
772 | - if ( !wpinv_gateway_support_subscription( $gateway ) ) { |
|
773 | - unset( $gateways[$gateway] ); |
|
769 | +function wpinv_payment_gateways_on_cart($gateways = array()) { |
|
770 | + if (!empty($gateways) && wpinv_cart_has_recurring_item()) { |
|
771 | + foreach ($gateways as $gateway => $info) { |
|
772 | + if (!wpinv_gateway_support_subscription($gateway)) { |
|
773 | + unset($gateways[$gateway]); |
|
774 | 774 | } |
775 | 775 | } |
776 | 776 | } |
777 | 777 | |
778 | 778 | return $gateways; |
779 | 779 | } |
780 | -add_filter( 'wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1 ); |
|
781 | 780 | \ No newline at end of file |
781 | +add_filter('wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1); |
|
782 | 782 | \ No newline at end of file |