@@ -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,31 +33,31 @@ 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_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
54 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
55 | 55 | |
56 | - if ( is_admin() ) { |
|
57 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
58 | - add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
56 | + if (is_admin()) { |
|
57 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
58 | + add_action('admin_body_class', array(&$this, 'admin_body_class')); |
|
59 | 59 | } else { |
60 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
60 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
69 | 69 | */ |
70 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
70 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
71 | 71 | |
72 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
72 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | public function plugins_loaded() { |
@@ -83,187 +83,187 @@ discard block |
||
83 | 83 | * @since 1.0 |
84 | 84 | */ |
85 | 85 | public function load_textdomain() { |
86 | - $locale = apply_filters( 'plugin_locale', get_locale(), 'invoicing' ); |
|
86 | + $locale = apply_filters('plugin_locale', get_locale(), 'invoicing'); |
|
87 | 87 | |
88 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
89 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
88 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
89 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Define language constants. |
93 | 93 | */ |
94 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
94 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | public function includes() { |
98 | 98 | global $wpinv_options; |
99 | 99 | |
100 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
100 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
101 | 101 | $wpinv_options = wpinv_get_settings(); |
102 | 102 | |
103 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
104 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
105 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
106 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
107 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
108 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
109 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
110 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
111 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
112 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
113 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
114 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
115 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
116 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php' ); |
|
117 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
118 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
119 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
120 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
121 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' ); |
|
122 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
123 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
124 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
125 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' ); |
|
126 | - if ( !class_exists( 'Geodir_EUVat' ) ) { |
|
127 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
103 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
104 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
105 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
106 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
107 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
108 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
109 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
110 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
111 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
112 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
113 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
114 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
115 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
116 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php'); |
|
117 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
118 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
119 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
120 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
121 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php'); |
|
122 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
123 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
124 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
125 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php'); |
|
126 | + if (!class_exists('Geodir_EUVat')) { |
|
127 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
128 | 128 | } |
129 | 129 | |
130 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
131 | - if ( !empty( $gateways ) ) { |
|
132 | - foreach ( $gateways as $gateway ) { |
|
133 | - if ( $gateway == 'manual' ) { |
|
130 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
131 | + if (!empty($gateways)) { |
|
132 | + foreach ($gateways as $gateway) { |
|
133 | + if ($gateway == 'manual') { |
|
134 | 134 | continue; |
135 | 135 | } |
136 | 136 | |
137 | 137 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
138 | 138 | |
139 | - if ( file_exists( $gateway_file ) ) { |
|
140 | - require_once( $gateway_file ); |
|
139 | + if (file_exists($gateway_file)) { |
|
140 | + require_once($gateway_file); |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | } |
144 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
145 | - |
|
146 | - if ( is_admin() ) { |
|
147 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
148 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
149 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
150 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
151 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
152 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
153 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
144 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
145 | + |
|
146 | + if (is_admin()) { |
|
147 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
148 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
149 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
150 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
151 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
152 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
153 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | // include css inliner |
157 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
158 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
157 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
158 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
159 | 159 | } |
160 | 160 | |
161 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
161 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | public function init() { |
165 | 165 | } |
166 | 166 | |
167 | 167 | public function admin_init() { |
168 | - if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) { |
|
168 | + if (!(defined('DOING_AJAX') && DOING_AJAX)) { |
|
169 | 169 | } |
170 | 170 | |
171 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
171 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | public function activation_redirect() { |
175 | 175 | // Bail if no activation redirect |
176 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
176 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
177 | 177 | return; |
178 | 178 | } |
179 | 179 | |
180 | 180 | // Delete the redirect transient |
181 | - delete_transient( '_wpinv_activation_redirect' ); |
|
181 | + delete_transient('_wpinv_activation_redirect'); |
|
182 | 182 | |
183 | 183 | // Bail if activating from network, or bulk |
184 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
184 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
185 | 185 | return; |
186 | 186 | } |
187 | 187 | |
188 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
188 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
189 | 189 | exit; |
190 | 190 | } |
191 | 191 | |
192 | 192 | public function enqueue_scripts() { |
193 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
193 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
194 | 194 | |
195 | - wp_deregister_style( 'font-awesome' ); |
|
196 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
197 | - wp_enqueue_style( 'font-awesome' ); |
|
195 | + wp_deregister_style('font-awesome'); |
|
196 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
197 | + wp_enqueue_style('font-awesome'); |
|
198 | 198 | |
199 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION ); |
|
200 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
199 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION); |
|
200 | + wp_enqueue_style('wpinv_front_style'); |
|
201 | 201 | |
202 | 202 | // Register scripts |
203 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
204 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ), WPINV_VERSION ); |
|
203 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
204 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION); |
|
205 | 205 | |
206 | 206 | $localize = array(); |
207 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
208 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
207 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
208 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
209 | 209 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
210 | 210 | $localize['currency_pos'] = wpinv_currency_position(); |
211 | 211 | $localize['thousand_sep'] = wpinv_thousands_seperator(); |
212 | 212 | $localize['decimal_sep'] = wpinv_decimal_seperator(); |
213 | 213 | $localize['decimals'] = wpinv_decimals(); |
214 | 214 | |
215 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
215 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
216 | 216 | |
217 | - wp_enqueue_script( 'jquery-blockui' ); |
|
218 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
219 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
217 | + wp_enqueue_script('jquery-blockui'); |
|
218 | + wp_enqueue_script('wpinv-front-script'); |
|
219 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | public function admin_enqueue_scripts() { |
223 | 223 | global $post, $pagenow; |
224 | 224 | |
225 | 225 | $post_type = wpinv_admin_post_type(); |
226 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
226 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
227 | 227 | |
228 | - wp_deregister_style( 'font-awesome' ); |
|
229 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
230 | - wp_enqueue_style( 'font-awesome' ); |
|
228 | + wp_deregister_style('font-awesome'); |
|
229 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
230 | + wp_enqueue_style('font-awesome'); |
|
231 | 231 | |
232 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
233 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
232 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
233 | + wp_enqueue_style('jquery-ui-css'); |
|
234 | 234 | |
235 | - wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' ); |
|
236 | - wp_enqueue_style( 'jquery-chosen' ); |
|
235 | + wp_register_style('jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2'); |
|
236 | + wp_enqueue_style('jquery-chosen'); |
|
237 | 237 | |
238 | - wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' ); |
|
239 | - wp_enqueue_script( 'jquery-chosen' ); |
|
238 | + wp_register_script('jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array('jquery'), '1.6.2'); |
|
239 | + wp_enqueue_script('jquery-chosen'); |
|
240 | 240 | |
241 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
242 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
241 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
242 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
243 | 243 | |
244 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION ); |
|
245 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
244 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION); |
|
245 | + wp_enqueue_style('wpinv_admin_style'); |
|
246 | 246 | |
247 | - if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
248 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
247 | + if ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
248 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
249 | 249 | } |
250 | 250 | |
251 | - wp_enqueue_style( 'wp-color-picker' ); |
|
252 | - wp_enqueue_script( 'wp-color-picker' ); |
|
251 | + wp_enqueue_style('wp-color-picker'); |
|
252 | + wp_enqueue_script('wp-color-picker'); |
|
253 | 253 | |
254 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
254 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
255 | 255 | |
256 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui' ), WPINV_VERSION ); |
|
257 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
256 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui'), WPINV_VERSION); |
|
257 | + wp_enqueue_script('wpinv-admin-script'); |
|
258 | 258 | |
259 | 259 | $localize = array(); |
260 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
261 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
262 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
263 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
264 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
265 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
266 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
260 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
261 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
262 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
263 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
264 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
265 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
266 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
267 | 267 | $localize['tax'] = wpinv_tax_amount(); |
268 | 268 | $localize['discount'] = wpinv_discount_amount(); |
269 | 269 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -271,55 +271,55 @@ discard block |
||
271 | 271 | $localize['thousand_sep'] = wpinv_thousands_seperator(); |
272 | 272 | $localize['decimal_sep'] = wpinv_decimal_seperator(); |
273 | 273 | $localize['decimals'] = wpinv_decimals(); |
274 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
275 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
276 | - $localize['status_pending'] = wpinv_status_nicename( 'pending' ); |
|
277 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
278 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
279 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
280 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
281 | - $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' ); |
|
282 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
283 | - $localize['hasGD'] = wpinv_gd_active();; |
|
274 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
275 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
276 | + $localize['status_pending'] = wpinv_status_nicename('pending'); |
|
277 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
278 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
279 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
280 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
281 | + $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'); |
|
282 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
283 | + $localize['hasGD'] = wpinv_gd_active(); ; |
|
284 | 284 | $localize['hasPM'] = wpinv_pm_active(); |
285 | - $localize['emptyInvoice'] = __( 'Add atleast one item to save invoice!', 'invoicing' ); |
|
286 | - $localize['deletePackage'] = __( 'GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing' ); |
|
287 | - $localize['deletePackages'] = __( 'GD package items should be deleted from GD payment manager only', 'invoicing' ); |
|
288 | - $localize['deleteInvoiceFirst'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
285 | + $localize['emptyInvoice'] = __('Add atleast one item to save invoice!', 'invoicing'); |
|
286 | + $localize['deletePackage'] = __('GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing'); |
|
287 | + $localize['deletePackages'] = __('GD package items should be deleted from GD payment manager only', 'invoicing'); |
|
288 | + $localize['deleteInvoiceFirst'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
289 | 289 | |
290 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
290 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
291 | 291 | } |
292 | 292 | |
293 | - public function admin_body_class( $classes ) { |
|
293 | + public function admin_body_class($classes) { |
|
294 | 294 | global $pagenow; |
295 | 295 | |
296 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
296 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
297 | 297 | |
298 | 298 | $add_class = false; |
299 | - if ( $pagenow == 'admin.php' && $page ) { |
|
300 | - $add_class = strpos( $page, 'wpinv-' ); |
|
299 | + if ($pagenow == 'admin.php' && $page) { |
|
300 | + $add_class = strpos($page, 'wpinv-'); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | $settings_class = array(); |
304 | - if ( $page == 'wpinv-settings' ) { |
|
305 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
306 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
304 | + if ($page == 'wpinv-settings') { |
|
305 | + if (!empty($_REQUEST['tab'])) { |
|
306 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
307 | 307 | } |
308 | 308 | |
309 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
310 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
309 | + if (!empty($_REQUEST['section'])) { |
|
310 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
311 | 311 | } |
312 | 312 | |
313 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
313 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
314 | 314 | } |
315 | 315 | |
316 | - if ( !empty( $settings_class ) ) { |
|
317 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
316 | + if (!empty($settings_class)) { |
|
317 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | $post_type = wpinv_admin_post_type(); |
321 | 321 | |
322 | - if ( $post_type == 'wpi_invoice' || $add_class !== false ) { |
|
322 | + if ($post_type == 'wpi_invoice' || $add_class !== false) { |
|
323 | 323 | return $classes .= ' wpinv'; |
324 | 324 | } else { |
325 | 325 | return $classes; |
@@ -331,26 +331,26 @@ discard block |
||
331 | 331 | public function admin_print_scripts_edit_php() { |
332 | 332 | $post_type = wpinv_admin_post_type(); |
333 | 333 | |
334 | - if ( $post_type == 'wpi_item' ) { |
|
335 | - wp_enqueue_script( 'wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array( 'jquery', 'inline-edit-post' ), '', true ); |
|
334 | + if ($post_type == 'wpi_item') { |
|
335 | + wp_enqueue_script('wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array('jquery', 'inline-edit-post'), '', true); |
|
336 | 336 | } |
337 | 337 | } |
338 | 338 | |
339 | 339 | public function wpinv_actions() { |
340 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
341 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
340 | + if (isset($_REQUEST['wpi_action'])) { |
|
341 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
342 | 342 | } |
343 | 343 | } |
344 | 344 | |
345 | - public function pre_get_posts( $wp_query ) { |
|
346 | - 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() ) { |
|
347 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
345 | + public function pre_get_posts($wp_query) { |
|
346 | + 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()) { |
|
347 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | return $wp_query; |
351 | 351 | } |
352 | 352 | |
353 | 353 | public function bp_invoicing_init() { |
354 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
354 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
355 | 355 | } |
356 | 356 | } |
357 | 357 | \ No newline at end of file |
@@ -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_Item { |
6 | 6 | public $ID = 0; |
@@ -34,26 +34,26 @@ discard block |
||
34 | 34 | public $filter; |
35 | 35 | |
36 | 36 | |
37 | - public function __construct( $_id = false, $_args = array() ) { |
|
38 | - $item = WP_Post::get_instance( $_id ); |
|
39 | - return $this->setup_item( $item ); |
|
37 | + public function __construct($_id = false, $_args = array()) { |
|
38 | + $item = WP_Post::get_instance($_id); |
|
39 | + return $this->setup_item($item); |
|
40 | 40 | } |
41 | 41 | |
42 | - private function setup_item( $item ) { |
|
43 | - if( ! is_object( $item ) ) { |
|
42 | + private function setup_item($item) { |
|
43 | + if (!is_object($item)) { |
|
44 | 44 | return false; |
45 | 45 | } |
46 | 46 | |
47 | - if( ! is_a( $item, 'WP_Post' ) ) { |
|
47 | + if (!is_a($item, 'WP_Post')) { |
|
48 | 48 | return false; |
49 | 49 | } |
50 | 50 | |
51 | - if( 'wpi_item' !== $item->post_type ) { |
|
51 | + if ('wpi_item' !== $item->post_type) { |
|
52 | 52 | return false; |
53 | 53 | } |
54 | 54 | |
55 | - foreach ( $item as $key => $value ) { |
|
56 | - switch ( $key ) { |
|
55 | + foreach ($item as $key => $value) { |
|
56 | + switch ($key) { |
|
57 | 57 | default: |
58 | 58 | $this->$key = $value; |
59 | 59 | break; |
@@ -63,76 +63,76 @@ discard block |
||
63 | 63 | return true; |
64 | 64 | } |
65 | 65 | |
66 | - public function __get( $key ) { |
|
67 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
68 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
66 | + public function __get($key) { |
|
67 | + if (method_exists($this, 'get_' . $key)) { |
|
68 | + return call_user_func(array($this, 'get_' . $key)); |
|
69 | 69 | } else { |
70 | - return new WP_Error( 'wpinv-item-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
70 | + return new WP_Error('wpinv-item-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key)); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
74 | - public function create( $data = array(), $wp_error = false ) { |
|
75 | - if ( $this->ID != 0 ) { |
|
74 | + public function create($data = array(), $wp_error = false) { |
|
75 | + if ($this->ID != 0) { |
|
76 | 76 | return false; |
77 | 77 | } |
78 | 78 | |
79 | 79 | $defaults = array( |
80 | 80 | 'post_type' => 'wpi_item', |
81 | 81 | 'post_status' => 'draft', |
82 | - 'post_title' => __( 'New Invoice Item', 'invoicing' ) |
|
82 | + 'post_title' => __('New Invoice Item', 'invoicing') |
|
83 | 83 | ); |
84 | 84 | |
85 | - $args = wp_parse_args( $data, $defaults ); |
|
85 | + $args = wp_parse_args($data, $defaults); |
|
86 | 86 | |
87 | - do_action( 'wpinv_item_pre_create', $args ); |
|
87 | + do_action('wpinv_item_pre_create', $args); |
|
88 | 88 | |
89 | - $id = wp_insert_post( $args, $wp_error ); |
|
89 | + $id = wp_insert_post($args, $wp_error); |
|
90 | 90 | if ($wp_error && is_wp_error($id)) { |
91 | 91 | return $id; |
92 | 92 | } |
93 | - if ( !$id ) { |
|
93 | + if (!$id) { |
|
94 | 94 | return false; |
95 | 95 | } |
96 | 96 | |
97 | - $item = WP_Post::get_instance( $id ); |
|
97 | + $item = WP_Post::get_instance($id); |
|
98 | 98 | |
99 | 99 | if (!empty($item) && !empty($data['meta'])) { |
100 | 100 | $this->ID = $item->ID; |
101 | 101 | $this->save_metas($data['meta']); |
102 | 102 | } |
103 | 103 | |
104 | - do_action( 'wpinv_item_create', $id, $args ); |
|
104 | + do_action('wpinv_item_create', $id, $args); |
|
105 | 105 | |
106 | - return $this->setup_item( $item ); |
|
106 | + return $this->setup_item($item); |
|
107 | 107 | } |
108 | 108 | |
109 | - public function update( $data = array(), $wp_error = false ) { |
|
110 | - if ( !$this->ID > 0 ) { |
|
109 | + public function update($data = array(), $wp_error = false) { |
|
110 | + if (!$this->ID > 0) { |
|
111 | 111 | return false; |
112 | 112 | } |
113 | 113 | |
114 | 114 | $data['ID'] = $this->ID; |
115 | 115 | |
116 | - do_action( 'wpinv_item_pre_update', $data ); |
|
116 | + do_action('wpinv_item_pre_update', $data); |
|
117 | 117 | |
118 | - $id = wp_update_post( $data, $wp_error ); |
|
118 | + $id = wp_update_post($data, $wp_error); |
|
119 | 119 | if ($wp_error && is_wp_error($id)) { |
120 | 120 | return $id; |
121 | 121 | } |
122 | 122 | |
123 | - if ( !$id ) { |
|
123 | + if (!$id) { |
|
124 | 124 | return false; |
125 | 125 | } |
126 | 126 | |
127 | - $item = WP_Post::get_instance( $id ); |
|
127 | + $item = WP_Post::get_instance($id); |
|
128 | 128 | if (!empty($item) && !empty($data['meta'])) { |
129 | 129 | $this->ID = $item->ID; |
130 | 130 | $this->save_metas($data['meta']); |
131 | 131 | } |
132 | 132 | |
133 | - do_action( 'wpinv_item_update', $id, $data ); |
|
133 | + do_action('wpinv_item_update', $id, $data); |
|
134 | 134 | |
135 | - return $this->setup_item( $item ); |
|
135 | + return $this->setup_item($item); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | public function get_ID() { |
@@ -140,95 +140,95 @@ discard block |
||
140 | 140 | } |
141 | 141 | |
142 | 142 | public function get_name() { |
143 | - return get_the_title( $this->ID ); |
|
143 | + return get_the_title($this->ID); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | public function get_summary() { |
147 | - return get_the_excerpt( $this->ID ); |
|
147 | + return get_the_excerpt($this->ID); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | public function get_price() { |
151 | - if ( ! isset( $this->price ) ) { |
|
152 | - $this->price = get_post_meta( $this->ID, '_wpinv_price', true ); |
|
151 | + if (!isset($this->price)) { |
|
152 | + $this->price = get_post_meta($this->ID, '_wpinv_price', true); |
|
153 | 153 | |
154 | - if ( $this->price ) { |
|
155 | - $this->price = wpinv_sanitize_amount( $this->price ); |
|
154 | + if ($this->price) { |
|
155 | + $this->price = wpinv_sanitize_amount($this->price); |
|
156 | 156 | } else { |
157 | 157 | $this->price = 0; |
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
161 | - return apply_filters( 'wpinv_get_item_price', $this->price, $this->ID ); |
|
161 | + return apply_filters('wpinv_get_item_price', $this->price, $this->ID); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | public function get_the_price() { |
165 | - $item_price = wpinv_price( wpinv_format_amount( $this->price ) ); |
|
165 | + $item_price = wpinv_price(wpinv_format_amount($this->price)); |
|
166 | 166 | |
167 | - return apply_filters( 'wpinv_get_the_item_price', $item_price, $this->ID ); |
|
167 | + return apply_filters('wpinv_get_the_item_price', $item_price, $this->ID); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | public function get_vat_rule() { |
171 | 171 | global $wpinv_euvat; |
172 | 172 | |
173 | - if( !isset( $this->vat_rule ) ) { |
|
174 | - $this->vat_rule = get_post_meta( $this->ID, '_wpinv_vat_rule', true ); |
|
173 | + if (!isset($this->vat_rule)) { |
|
174 | + $this->vat_rule = get_post_meta($this->ID, '_wpinv_vat_rule', true); |
|
175 | 175 | |
176 | - if ( empty( $this->vat_rule ) ) { |
|
176 | + if (empty($this->vat_rule)) { |
|
177 | 177 | $this->vat_rule = $wpinv_euvat->allow_vat_rules() ? 'digital' : 'physical'; |
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
181 | - return apply_filters( 'wpinv_get_item_vat_rule', $this->vat_rule, $this->ID ); |
|
181 | + return apply_filters('wpinv_get_item_vat_rule', $this->vat_rule, $this->ID); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | public function get_vat_class() { |
185 | - if( !isset( $this->vat_class ) ) { |
|
186 | - $this->vat_class = get_post_meta( $this->ID, '_wpinv_vat_class', true ); |
|
185 | + if (!isset($this->vat_class)) { |
|
186 | + $this->vat_class = get_post_meta($this->ID, '_wpinv_vat_class', true); |
|
187 | 187 | |
188 | - if ( empty( $this->vat_class ) ) { |
|
188 | + if (empty($this->vat_class)) { |
|
189 | 189 | $this->vat_class = '_standard'; |
190 | 190 | } |
191 | 191 | } |
192 | 192 | |
193 | - return apply_filters( 'wpinv_get_item_vat_class', $this->vat_class, $this->ID ); |
|
193 | + return apply_filters('wpinv_get_item_vat_class', $this->vat_class, $this->ID); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | public function get_cpt_singular_name() { |
197 | - if( ! isset( $this->cpt_singular_name ) ) { |
|
198 | - $this->cpt_singular_name = get_post_meta( $this->ID, '_wpinv_cpt_singular_name', true ); |
|
197 | + if (!isset($this->cpt_singular_name)) { |
|
198 | + $this->cpt_singular_name = get_post_meta($this->ID, '_wpinv_cpt_singular_name', true); |
|
199 | 199 | } |
200 | 200 | |
201 | - return apply_filters( 'wpinv_item_get_cpt_singular_name', $this->cpt_singular_name, $this->ID ); |
|
201 | + return apply_filters('wpinv_item_get_cpt_singular_name', $this->cpt_singular_name, $this->ID); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | public function get_type() { |
205 | - if( ! isset( $this->type ) ) { |
|
206 | - $this->type = get_post_meta( $this->ID, '_wpinv_type', true ); |
|
205 | + if (!isset($this->type)) { |
|
206 | + $this->type = get_post_meta($this->ID, '_wpinv_type', true); |
|
207 | 207 | |
208 | - if ( empty( $this->type ) ) { |
|
208 | + if (empty($this->type)) { |
|
209 | 209 | $this->type = 'custom'; |
210 | 210 | } |
211 | 211 | } |
212 | 212 | |
213 | - return apply_filters( 'wpinv_get_item_type', $this->type, $this->ID ); |
|
213 | + return apply_filters('wpinv_get_item_type', $this->type, $this->ID); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | public function is_recurring() { |
217 | - $is_recurring = get_post_meta( $this->ID, '_wpinv_is_recurring', true ); |
|
217 | + $is_recurring = get_post_meta($this->ID, '_wpinv_is_recurring', true); |
|
218 | 218 | |
219 | - return (bool)apply_filters( 'wpinv_is_recurring_item', $is_recurring, $this->ID ); |
|
219 | + return (bool)apply_filters('wpinv_is_recurring_item', $is_recurring, $this->ID); |
|
220 | 220 | |
221 | 221 | } |
222 | 222 | |
223 | - public function get_recurring_period( $full = false ) { |
|
224 | - $period = get_post_meta( $this->ID, '_wpinv_recurring_period', true ); |
|
223 | + public function get_recurring_period($full = false) { |
|
224 | + $period = get_post_meta($this->ID, '_wpinv_recurring_period', true); |
|
225 | 225 | |
226 | - if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { |
|
226 | + if (!in_array($period, array('D', 'W', 'M', 'Y'))) { |
|
227 | 227 | $period = 'D'; |
228 | 228 | } |
229 | 229 | |
230 | - if ( $full ) { |
|
231 | - switch( $period ) { |
|
230 | + if ($full) { |
|
231 | + switch ($period) { |
|
232 | 232 | case 'D': |
233 | 233 | $period = 'day'; |
234 | 234 | break; |
@@ -244,45 +244,45 @@ discard block |
||
244 | 244 | } |
245 | 245 | } |
246 | 246 | |
247 | - return apply_filters( 'wpinv_item_recurring_period', $period, $full, $this->ID ); |
|
247 | + return apply_filters('wpinv_item_recurring_period', $period, $full, $this->ID); |
|
248 | 248 | |
249 | 249 | } |
250 | 250 | |
251 | 251 | public function get_recurring_interval() { |
252 | - $interval = (int)get_post_meta( $this->ID, '_wpinv_recurring_interval', true ); |
|
252 | + $interval = (int)get_post_meta($this->ID, '_wpinv_recurring_interval', true); |
|
253 | 253 | |
254 | - if ( !$interval > 0 ) { |
|
254 | + if (!$interval > 0) { |
|
255 | 255 | $interval = 1; |
256 | 256 | } |
257 | 257 | |
258 | - return apply_filters( 'wpinv_item_recurring_interval', $interval, $this->ID ); |
|
258 | + return apply_filters('wpinv_item_recurring_interval', $interval, $this->ID); |
|
259 | 259 | |
260 | 260 | } |
261 | 261 | |
262 | 262 | public function get_recurring_limit() { |
263 | - $limit = get_post_meta( $this->ID, '_wpinv_recurring_limit', true ); |
|
263 | + $limit = get_post_meta($this->ID, '_wpinv_recurring_limit', true); |
|
264 | 264 | |
265 | - return (int)apply_filters( 'wpinv_item_recurring_limit', $limit, $this->ID ); |
|
265 | + return (int)apply_filters('wpinv_item_recurring_limit', $limit, $this->ID); |
|
266 | 266 | |
267 | 267 | } |
268 | 268 | |
269 | 269 | public function has_free_trial() { |
270 | - $free_trial = get_post_meta( $this->ID, '_wpinv_free_trial', true ); |
|
271 | - $free_trial = $this->is_recurring() && !empty( $free_trial ) ? true : false; |
|
270 | + $free_trial = get_post_meta($this->ID, '_wpinv_free_trial', true); |
|
271 | + $free_trial = $this->is_recurring() && !empty($free_trial) ? true : false; |
|
272 | 272 | |
273 | - return (bool)apply_filters( 'wpinv_item_has_free_trial', $free_trial, $this->ID ); |
|
273 | + return (bool)apply_filters('wpinv_item_has_free_trial', $free_trial, $this->ID); |
|
274 | 274 | |
275 | 275 | } |
276 | 276 | |
277 | - public function get_trial_period( $full = false ) { |
|
278 | - $period = get_post_meta( $this->ID, '_wpinv_trial_period', true ); |
|
277 | + public function get_trial_period($full = false) { |
|
278 | + $period = get_post_meta($this->ID, '_wpinv_trial_period', true); |
|
279 | 279 | |
280 | - if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { |
|
280 | + if (!in_array($period, array('D', 'W', 'M', 'Y'))) { |
|
281 | 281 | $period = 'D'; |
282 | 282 | } |
283 | 283 | |
284 | - if ( $full ) { |
|
285 | - switch( $period ) { |
|
284 | + if ($full) { |
|
285 | + switch ($period) { |
|
286 | 286 | case 'D': |
287 | 287 | $period = 'day'; |
288 | 288 | break; |
@@ -298,47 +298,47 @@ discard block |
||
298 | 298 | } |
299 | 299 | } |
300 | 300 | |
301 | - return apply_filters( 'wpinv_item_trial_period', $period, $full, $this->ID ); |
|
301 | + return apply_filters('wpinv_item_trial_period', $period, $full, $this->ID); |
|
302 | 302 | |
303 | 303 | } |
304 | 304 | |
305 | 305 | public function get_trial_interval() { |
306 | - $interval = absint( get_post_meta( $this->ID, '_wpinv_trial_interval', true ) ); |
|
306 | + $interval = absint(get_post_meta($this->ID, '_wpinv_trial_interval', true)); |
|
307 | 307 | |
308 | - if ( !$interval > 0 ) { |
|
308 | + if (!$interval > 0) { |
|
309 | 309 | $interval = 1; |
310 | 310 | } |
311 | 311 | |
312 | - return apply_filters( 'wpinv_item_trial_interval', $interval, $this->ID ); |
|
312 | + return apply_filters('wpinv_item_trial_interval', $interval, $this->ID); |
|
313 | 313 | |
314 | 314 | } |
315 | 315 | |
316 | 316 | public function is_free() { |
317 | 317 | $is_free = false; |
318 | 318 | |
319 | - $price = get_post_meta( $this->ID, '_wpinv_price', true ); |
|
319 | + $price = get_post_meta($this->ID, '_wpinv_price', true); |
|
320 | 320 | |
321 | - if ( (float)$price == 0 ) { |
|
321 | + if ((float)$price == 0) { |
|
322 | 322 | $is_free = true; |
323 | 323 | } |
324 | 324 | |
325 | - return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID ); |
|
325 | + return (bool)apply_filters('wpinv_is_free_item', $is_free, $this->ID); |
|
326 | 326 | |
327 | 327 | } |
328 | 328 | |
329 | 329 | public function is_package() { |
330 | 330 | $is_package = $this->get_type() == 'package' ? true : false; |
331 | 331 | |
332 | - return (bool) apply_filters( 'wpinv_is_package_item', $is_package, $this->ID ); |
|
332 | + return (bool)apply_filters('wpinv_is_package_item', $is_package, $this->ID); |
|
333 | 333 | |
334 | 334 | } |
335 | 335 | |
336 | - public function save_metas( $metas = array() ) { |
|
337 | - if ( empty( $metas ) ) { |
|
336 | + public function save_metas($metas = array()) { |
|
337 | + if (empty($metas)) { |
|
338 | 338 | return false; |
339 | 339 | } |
340 | 340 | |
341 | - foreach ( $metas as $meta_key => $meta_value ) { |
|
341 | + foreach ($metas as $meta_key => $meta_value) { |
|
342 | 342 | $meta_key = strpos($meta_key, '_wpinv_') !== 0 ? '_wpinv_' . $meta_key : $meta_key; |
343 | 343 | |
344 | 344 | $this->update_meta($meta_key, $meta_value); |
@@ -347,66 +347,66 @@ discard block |
||
347 | 347 | return true; |
348 | 348 | } |
349 | 349 | |
350 | - public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
351 | - if ( empty( $meta_key ) ) { |
|
350 | + public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { |
|
351 | + if (empty($meta_key)) { |
|
352 | 352 | return false; |
353 | 353 | } |
354 | 354 | |
355 | - $meta_value = apply_filters( 'wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID ); |
|
355 | + $meta_value = apply_filters('wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID); |
|
356 | 356 | |
357 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value ); |
|
357 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value); |
|
358 | 358 | } |
359 | 359 | |
360 | - public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
360 | + public function get_fees($type = 'fee', $item_id = 0) { |
|
361 | 361 | global $wpi_session; |
362 | 362 | |
363 | - $fees = $wpi_session->get( 'wpi_cart_fees' ); |
|
363 | + $fees = $wpi_session->get('wpi_cart_fees'); |
|
364 | 364 | |
365 | - if ( ! wpinv_get_cart_contents() ) { |
|
365 | + if (!wpinv_get_cart_contents()) { |
|
366 | 366 | // We can only get item type fees when the cart is empty |
367 | 367 | $type = 'custom'; |
368 | 368 | } |
369 | 369 | |
370 | - if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) { |
|
371 | - foreach( $fees as $key => $fee ) { |
|
372 | - if( ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
373 | - unset( $fees[ $key ] ); |
|
370 | + if (!empty($fees) && !empty($type) && 'all' !== $type) { |
|
371 | + foreach ($fees as $key => $fee) { |
|
372 | + if (!empty($fee['type']) && $type != $fee['type']) { |
|
373 | + unset($fees[$key]); |
|
374 | 374 | } |
375 | 375 | } |
376 | 376 | } |
377 | 377 | |
378 | - if ( ! empty( $fees ) && ! empty( $item_id ) ) { |
|
378 | + if (!empty($fees) && !empty($item_id)) { |
|
379 | 379 | // Remove fees that don't belong to the specified Item |
380 | - foreach ( $fees as $key => $fee ) { |
|
381 | - if ( (int) $item_id !== (int)$fee['item_id'] ) { |
|
382 | - unset( $fees[ $key ] ); |
|
380 | + foreach ($fees as $key => $fee) { |
|
381 | + if ((int)$item_id !== (int)$fee['item_id']) { |
|
382 | + unset($fees[$key]); |
|
383 | 383 | } |
384 | 384 | } |
385 | 385 | } |
386 | 386 | |
387 | - if ( ! empty( $fees ) ) { |
|
387 | + if (!empty($fees)) { |
|
388 | 388 | // Remove fees that belong to a specific item but are not in the cart |
389 | - foreach( $fees as $key => $fee ) { |
|
390 | - if( empty( $fee['item_id'] ) ) { |
|
389 | + foreach ($fees as $key => $fee) { |
|
390 | + if (empty($fee['item_id'])) { |
|
391 | 391 | continue; |
392 | 392 | } |
393 | 393 | |
394 | - if ( !wpinv_item_in_cart( $fee['item_id'] ) ) { |
|
395 | - unset( $fees[ $key ] ); |
|
394 | + if (!wpinv_item_in_cart($fee['item_id'])) { |
|
395 | + unset($fees[$key]); |
|
396 | 396 | } |
397 | 397 | } |
398 | 398 | } |
399 | 399 | |
400 | - return ! empty( $fees ) ? $fees : array(); |
|
400 | + return !empty($fees) ? $fees : array(); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | public function can_purchase() { |
404 | 404 | $can_purchase = true; |
405 | 405 | |
406 | - if ( !current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) { |
|
406 | + if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') { |
|
407 | 407 | $can_purchase = false; |
408 | 408 | } |
409 | 409 | |
410 | - return (bool)apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this ); |
|
410 | + return (bool)apply_filters('wpinv_can_purchase_item', $can_purchase, $this); |
|
411 | 411 | } |
412 | 412 | } |
@@ -1,6 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; |
|
5 | +} |
|
4 | 6 | |
5 | 7 | class WPInv_Item { |
6 | 8 | public $ID = 0; |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_action( 'wpinv_worldpay_cc_form', '__return_false' ); |
|
5 | +add_action('wpinv_worldpay_cc_form', '__return_false'); |
|
6 | 6 | |
7 | -function wpinv_process_worldpay_payment( $purchase_data ) { |
|
8 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
9 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
7 | +function wpinv_process_worldpay_payment($purchase_data) { |
|
8 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
9 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | // Collect payment data |
@@ -24,120 +24,120 @@ discard block |
||
24 | 24 | ); |
25 | 25 | |
26 | 26 | // Record the pending payment |
27 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
27 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
28 | 28 | |
29 | - if ( !empty( $invoice ) ) { |
|
29 | + if (!empty($invoice)) { |
|
30 | 30 | $quantities_enabled = wpinv_item_quantities_enabled(); |
31 | 31 | |
32 | - $instId = wpinv_get_option( 'worldpay_instId', false ); |
|
32 | + $instId = wpinv_get_option('worldpay_instId', false); |
|
33 | 33 | $cartId = $invoice->get_number(); |
34 | - $testMode = wpinv_is_test_mode( 'worldpay' ) ? 100 : 0; |
|
34 | + $testMode = wpinv_is_test_mode('worldpay') ? 100 : 0; |
|
35 | 35 | $name = $invoice->get_user_full_name(); |
36 | - $address = wp_strip_all_tags( $invoice->get_address(), true ); |
|
36 | + $address = wp_strip_all_tags($invoice->get_address(), true); |
|
37 | 37 | $postcode = $invoice->zip; |
38 | 38 | $tel = $invoice->phone; |
39 | 39 | $email = $invoice->get_email(); |
40 | 40 | $country = $invoice->country; |
41 | - $amount = wpinv_sanitize_amount( $invoice->get_total() ); |
|
41 | + $amount = wpinv_sanitize_amount($invoice->get_total()); |
|
42 | 42 | $currency = wpinv_get_currency(); |
43 | 43 | |
44 | 44 | $items = array(); |
45 | - foreach ( $invoice->get_cart_details() as $item ) { |
|
45 | + foreach ($invoice->get_cart_details() as $item) { |
|
46 | 46 | $item_desc = $item['name']; |
47 | - $quantity = !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
48 | - $item_desc .= ' (' . ( $quantities_enabled ? $quantity . 'x ' : '' ) . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')'; |
|
47 | + $quantity = !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
48 | + $item_desc .= ' (' . ($quantities_enabled ? $quantity . 'x ' : '') . wpinv_price(wpinv_format_amount($item['item_price'])) . ')'; |
|
49 | 49 | |
50 | 50 | $items[] = $item_desc; |
51 | 51 | } |
52 | 52 | |
53 | - $desc = implode( ', ', $items ); |
|
54 | - if ( wpinv_use_taxes() && $invoice->get_tax() > 0 ) { |
|
55 | - $desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) ); |
|
53 | + $desc = implode(', ', $items); |
|
54 | + if (wpinv_use_taxes() && $invoice->get_tax() > 0) { |
|
55 | + $desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true)); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | $extra_params = array(); |
59 | 59 | $extra_params['MC_description'] = $desc; |
60 | - $extra_params['MC_callback'] = wpinv_get_ipn_url( 'worldpay' ); |
|
60 | + $extra_params['MC_callback'] = wpinv_get_ipn_url('worldpay'); |
|
61 | 61 | $extra_params['MC_key'] = $invoice->get_key(); |
62 | 62 | $extra_params['MC_invoice_id'] = $invoice->ID; |
63 | 63 | $extra_params['address1'] = $address; |
64 | 64 | $extra_params['town'] = $invoice->city; |
65 | 65 | $extra_params['region'] = $invoice->state; |
66 | - $extra_params['amountString'] = $invoice->get_total( true ); |
|
67 | - $extra_params['countryString'] = wpinv_country_name( $invoice->country ); |
|
66 | + $extra_params['amountString'] = $invoice->get_total(true); |
|
67 | + $extra_params['countryString'] = wpinv_country_name($invoice->country); |
|
68 | 68 | $extra_params['compName'] = $invoice->company; |
69 | 69 | |
70 | - $extra_params = apply_filters( 'wpinv_worldpay_form_extra_parameters', $extra_params, $invoice ); |
|
70 | + $extra_params = apply_filters('wpinv_worldpay_form_extra_parameters', $extra_params, $invoice); |
|
71 | 71 | |
72 | - $redirect_text = __( 'Redirecting to Worldpay site, click on button if not redirected.', 'invoicing' ); |
|
73 | - $redirect_text = apply_filters( 'wpinv_worldpay_redirect_text', $redirect_text, $invoice ); |
|
72 | + $redirect_text = __('Redirecting to Worldpay site, click on button if not redirected.', 'invoicing'); |
|
73 | + $redirect_text = apply_filters('wpinv_worldpay_redirect_text', $redirect_text, $invoice); |
|
74 | 74 | |
75 | 75 | // Empty the shopping cart |
76 | 76 | wpinv_empty_cart(); |
77 | 77 | ?> |
78 | 78 | <div class="wpi-worldpay-form" style="padding:20px;font-family:arial,sans-serif;text-align:center;color:#555"> |
79 | -<?php do_action( 'wpinv_worldpay_form_before', $invoice ); ?> |
|
80 | -<h3><?php echo $redirect_text ;?></h3> |
|
79 | +<?php do_action('wpinv_worldpay_form_before', $invoice); ?> |
|
80 | +<h3><?php echo $redirect_text; ?></h3> |
|
81 | 81 | <form action="<?php echo wpinv_get_worldpay_redirect(); ?>" name="wpi_worldpay_form" method="POST"> |
82 | - <input type="hidden" value="<?php echo $amount;?>" name="amount"> |
|
83 | - <input type="hidden" value="<?php echo esc_attr( $cartId );?>" name="cartId"> |
|
84 | - <input type="hidden" value="<?php echo $currency;?>" name="currency"> |
|
85 | - <input type="hidden" value="<?php echo $instId;?>" name="instId"> |
|
86 | - <input type="hidden" value="<?php echo $testMode;?>" name="testMode"> |
|
87 | - <input type="hidden" value="<?php echo esc_attr( $name );?>" name="name"> |
|
88 | - <input type="hidden" value="<?php echo esc_attr( $address );?>" name="address"> |
|
89 | - <input type="hidden" value="<?php echo esc_attr( $postcode );?>" name="postcode"> |
|
90 | - <input type="hidden" value="<?php echo esc_attr( $tel );?>" name="tel"> |
|
91 | - <input type="hidden" value="<?php echo esc_attr( $email );?>" name="email"> |
|
92 | - <input type="hidden" value="<?php echo esc_attr( $country );?>" name="country"> |
|
93 | - <input type="hidden" value="<?php echo esc_attr( $desc );?>" name="desc"> |
|
94 | - <?php foreach ( $extra_params as $param => $value ) { ?> |
|
95 | - <?php if ( !empty( $value !== false ) ) { ?> |
|
96 | - <input type="hidden" value="<?php echo esc_attr( $value );?>" name="<?php echo esc_attr( $param );?>"> |
|
82 | + <input type="hidden" value="<?php echo $amount; ?>" name="amount"> |
|
83 | + <input type="hidden" value="<?php echo esc_attr($cartId); ?>" name="cartId"> |
|
84 | + <input type="hidden" value="<?php echo $currency; ?>" name="currency"> |
|
85 | + <input type="hidden" value="<?php echo $instId; ?>" name="instId"> |
|
86 | + <input type="hidden" value="<?php echo $testMode; ?>" name="testMode"> |
|
87 | + <input type="hidden" value="<?php echo esc_attr($name); ?>" name="name"> |
|
88 | + <input type="hidden" value="<?php echo esc_attr($address); ?>" name="address"> |
|
89 | + <input type="hidden" value="<?php echo esc_attr($postcode); ?>" name="postcode"> |
|
90 | + <input type="hidden" value="<?php echo esc_attr($tel); ?>" name="tel"> |
|
91 | + <input type="hidden" value="<?php echo esc_attr($email); ?>" name="email"> |
|
92 | + <input type="hidden" value="<?php echo esc_attr($country); ?>" name="country"> |
|
93 | + <input type="hidden" value="<?php echo esc_attr($desc); ?>" name="desc"> |
|
94 | + <?php foreach ($extra_params as $param => $value) { ?> |
|
95 | + <?php if (!empty($value !== false)) { ?> |
|
96 | + <input type="hidden" value="<?php echo esc_attr($value); ?>" name="<?php echo esc_attr($param); ?>"> |
|
97 | 97 | <?php } ?> |
98 | 98 | <?php } ?> |
99 | - <?php do_action( 'wpinv_worldpay_form_parameters', $invoice ); ?> |
|
100 | - <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e( 'Pay by Debit/Credit Card (WorldPay)', 'invoicing' ) ;?>"> |
|
99 | + <?php do_action('wpinv_worldpay_form_parameters', $invoice); ?> |
|
100 | + <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e('Pay by Debit/Credit Card (WorldPay)', 'invoicing'); ?>"> |
|
101 | 101 | </form> |
102 | 102 | <script type="text/javascript">document.wpi_worldpay_form.submit();</script> |
103 | -<?php do_action( 'wpinv_worldpay_form_after', $invoice ); ?> |
|
103 | +<?php do_action('wpinv_worldpay_form_after', $invoice); ?> |
|
104 | 104 | </div> |
105 | 105 | <?php |
106 | 106 | } else { |
107 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
107 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice); |
|
108 | 108 | // If errors are present, send the user back to the purchase page so they can be corrected |
109 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
109 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
110 | 110 | } |
111 | 111 | } |
112 | -add_action( 'wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment' ); |
|
112 | +add_action('wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment'); |
|
113 | 113 | |
114 | 114 | function wpinv_get_worldpay_redirect() { |
115 | - $redirect = wpinv_is_test_mode( 'worldpay' ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
115 | + $redirect = wpinv_is_test_mode('worldpay') ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
116 | 116 | |
117 | - return apply_filters( 'wpinv_worldpay_redirect', $redirect ); |
|
117 | + return apply_filters('wpinv_worldpay_redirect', $redirect); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | function wpinv_process_worldpay_ipn() { |
121 | - $request = wpinv_get_post_data( 'post' ); |
|
121 | + $request = wpinv_get_post_data('post'); |
|
122 | 122 | |
123 | - if ( !empty( $request['cartId'] ) && !empty( $request['transStatus'] ) && !empty( $request['installation'] ) && isset( $request['testMode'] ) && isset( $request['MC_invoice_id'] ) && isset( $request['MC_key'] ) ) { |
|
123 | + if (!empty($request['cartId']) && !empty($request['transStatus']) && !empty($request['installation']) && isset($request['testMode']) && isset($request['MC_invoice_id']) && isset($request['MC_key'])) { |
|
124 | 124 | $invoice_id = $request['MC_invoice_id']; |
125 | 125 | |
126 | - if ( $invoice_id == wpinv_get_invoice_id_by_key( $request['MC_key'] ) && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
127 | - if ( $request['transStatus'] == 'Y' ) { |
|
128 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
129 | - wpinv_set_payment_transaction_id( $invoice_id, $request['transId'] ); |
|
130 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Worldpay Transaction ID: %s', 'invoicing' ), $request['transId'] ) ); |
|
126 | + if ($invoice_id == wpinv_get_invoice_id_by_key($request['MC_key']) && $invoice = wpinv_get_invoice($invoice_id)) { |
|
127 | + if ($request['transStatus'] == 'Y') { |
|
128 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
129 | + wpinv_set_payment_transaction_id($invoice_id, $request['transId']); |
|
130 | + wpinv_insert_payment_note($invoice_id, sprintf(__('Worldpay Transaction ID: %s', 'invoicing'), $request['transId'])); |
|
131 | 131 | return; |
132 | - } else if ( $request['transStatus'] == 'C' ) { |
|
133 | - wpinv_update_payment_status( $invoice_id, 'failed' ); |
|
134 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing' ) ); |
|
132 | + } else if ($request['transStatus'] == 'C') { |
|
133 | + wpinv_update_payment_status($invoice_id, 'failed'); |
|
134 | + wpinv_insert_payment_note($invoice_id, __('Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing')); |
|
135 | 135 | |
136 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing' ), json_encode( $request ) ), $invoice_id ); |
|
136 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing'), json_encode($request)), $invoice_id); |
|
137 | 137 | return; |
138 | 138 | } |
139 | 139 | } |
140 | 140 | } |
141 | 141 | return; |
142 | 142 | } |
143 | -add_action( 'wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn' ); |
|
144 | 143 | \ No newline at end of file |
144 | +add_action('wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn'); |
|
145 | 145 | \ No newline at end of file |
@@ -1,6 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; |
|
5 | +} |
|
4 | 6 | |
5 | 7 | add_action( 'wpinv_worldpay_cc_form', '__return_false' ); |
6 | 8 |
@@ -182,7 +182,7 @@ |
||
182 | 182 | $string = ""; |
183 | 183 | foreach ($array as $key => $value) { |
184 | 184 | if ($value) { |
185 | - $string .= '<input type="hidden" name="'.$key.'" value="'.$value.'">'; |
|
185 | + $string .= '<input type="hidden" name="' . $key . '" value="' . $value . '">'; |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 | return $string; |
@@ -91,13 +91,13 @@ |
||
91 | 91 | return $this->_sendRequest(); |
92 | 92 | } |
93 | 93 | |
94 | - /** |
|
95 | - * |
|
96 | - * |
|
97 | - * @param string $response |
|
98 | - * |
|
99 | - * @return AuthorizeNetARB_Response |
|
100 | - */ |
|
94 | + /** |
|
95 | + * |
|
96 | + * |
|
97 | + * @param string $response |
|
98 | + * |
|
99 | + * @return AuthorizeNetARB_Response |
|
100 | + */ |
|
101 | 101 | protected function _handleResponse($response) |
102 | 102 | { |
103 | 103 | return new AuthorizeNetARB_Response($response); |
@@ -116,7 +116,7 @@ |
||
116 | 116 | */ |
117 | 117 | protected function _setPostString() |
118 | 118 | { |
119 | - $this->_post_string =<<<XML |
|
119 | + $this->_post_string = <<<XML |
|
120 | 120 | <?xml version="1.0" encoding="utf-8"?> |
121 | 121 | <ARB{$this->_request_type} xmlns= "AnetApi/xml/v1/schema/AnetApiSchema.xsd"> |
122 | 122 | <merchantAuthentication> |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | { |
65 | 65 | $month = ($month ? $month : date('m')); |
66 | 66 | $year = ($year ? $year : date('Y')); |
67 | - $firstSettlementDate = substr(date('c',mktime(0, 0, 0, $month, 1, $year)),0,-6); |
|
68 | - $lastSettlementDate = substr(date('c',mktime(0, 0, 0, $month+1, 0, $year)),0,-6); |
|
67 | + $firstSettlementDate = substr(date('c', mktime(0, 0, 0, $month, 1, $year)), 0, -6); |
|
68 | + $lastSettlementDate = substr(date('c', mktime(0, 0, 0, $month + 1, 0, $year)), 0, -6); |
|
69 | 69 | return $this->getSettledBatchList(true, $firstSettlementDate, $lastSettlementDate); |
70 | 70 | } |
71 | 71 | |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | $month = ($month ? $month : date('m')); |
99 | 99 | $day = ($day ? $day : date('d')); |
100 | 100 | $year = ($year ? $year : date('Y')); |
101 | - $firstSettlementDate = substr(date('c',mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)),0,-6); |
|
102 | - $lastSettlementDate = substr(date('c',mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)),0,-6); |
|
101 | + $firstSettlementDate = substr(date('c', mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)), 0, -6); |
|
102 | + $lastSettlementDate = substr(date('c', mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)), 0, -6); |
|
103 | 103 | $response = $this->getSettledBatchList(true, $firstSettlementDate, $lastSettlementDate); |
104 | 104 | $batches = $response->xpath("batchList/batch"); |
105 | 105 | foreach ($batches as $batch) { |
@@ -187,11 +187,11 @@ discard block |
||
187 | 187 | */ |
188 | 188 | private function _constructXml($request_type) |
189 | 189 | { |
190 | - $string = '<?xml version="1.0" encoding="utf-8"?><'.$request_type.' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></'.$request_type.'>'; |
|
190 | + $string = '<?xml version="1.0" encoding="utf-8"?><' . $request_type . ' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></' . $request_type . '>'; |
|
191 | 191 | $this->_xml = @new SimpleXMLElement($string); |
192 | 192 | $merchant = $this->_xml->addChild('merchantAuthentication'); |
193 | - $merchant->addChild('name',$this->_api_login); |
|
194 | - $merchant->addChild('transactionKey',$this->_transaction_key); |
|
193 | + $merchant->addChild('name', $this->_api_login); |
|
194 | + $merchant->addChild('transactionKey', $this->_transaction_key); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | } |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | $string = ""; |
52 | 52 | $types = $this->__getTypes(); |
53 | 53 | foreach ($types as $type) { |
54 | - if (preg_match("/struct /",$type)) { |
|
55 | - $type = preg_replace("/struct /","class ",$type); |
|
56 | - $type = preg_replace("/ (\w+) (\w+);/"," // $1\n public \$$2;",$type); |
|
57 | - $string .= $type ."\n"; |
|
54 | + if (preg_match("/struct /", $type)) { |
|
55 | + $type = preg_replace("/struct /", "class ", $type); |
|
56 | + $type = preg_replace("/ (\w+) (\w+);/", " // $1\n public \$$2;", $type); |
|
57 | + $string .= $type . "\n"; |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | return $string; |
@@ -84,13 +84,13 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function saveSoapDocumentation($path) |
86 | 86 | { |
87 | - $string = "<?php\n"; |
|
87 | + $string = "<?php\n"; |
|
88 | 88 | $string .= "/**\n"; |
89 | 89 | $string .= " * Auto generated documentation for the AuthorizeNetSOAP API.\n"; |
90 | 90 | $string .= " * Generated " . date("m/d/Y") . "\n"; |
91 | 91 | $string .= " */\n"; |
92 | 92 | $string .= "class AuthorizeNetSOAP\n"; |
93 | - $string .= "{\n" . $this->getSoapMethods() . "\n}\n\n" . $this->getSoapTypes() ."\n\n ?>"; |
|
93 | + $string .= "{\n" . $this->getSoapMethods() . "\n}\n\n" . $this->getSoapTypes() . "\n\n ?>"; |
|
94 | 94 | return file_put_contents($path, $string); |
95 | 95 | } |
96 | 96 |
@@ -76,7 +76,7 @@ |
||
76 | 76 | } |
77 | 77 | else |
78 | 78 | { |
79 | - echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']); |
|
79 | + echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | else |
58 | 58 | { |
59 | 59 | // Redirect to error page. |
60 | - $redirect_url = $url . '?response_code='.$response->response_code . '&response_reason_text=' . $response->response_reason_text; |
|
60 | + $redirect_url = $url . '?response_code=' . $response->response_code . '&response_reason_text=' . $response->response_reason_text; |
|
61 | 61 | } |
62 | 62 | // Send the Javascript back to AuthorizeNet, which will redirect user back to your site. |
63 | 63 | echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url); |
@@ -179,54 +179,54 @@ discard block |
||
179 | 179 | -moz-box-shadow: inset 3px -3px 3px rgba(0,0,0,.5), inset 0 3px 3px rgba(255,255,255,.5), inset -3px 0 3px rgba(255,255,255,.75); |
180 | 180 | box-shadow: inset 3px -3px 3px rgba(0,0,0,.5), inset 0 3px 3px rgba(255,255,255,.5), inset -3px 0 3px rgba(255,255,255,.75); } |
181 | 181 | </style> |
182 | - <form method="post" action="'.$post_url.'"> |
|
183 | - '.$hidden_fields.' |
|
182 | + <form method="post" action="'.$post_url . '"> |
|
183 | + '.$hidden_fields . ' |
|
184 | 184 | <fieldset> |
185 | 185 | <div> |
186 | 186 | <label>Credit Card Number</label> |
187 | - <input type="text" class="text" size="15" name="x_card_num" value="'.($prefill ? '6011000000000012' : '').'"></input> |
|
187 | + <input type="text" class="text" size="15" name="x_card_num" value="'.($prefill ? '6011000000000012' : '') . '"></input> |
|
188 | 188 | </div> |
189 | 189 | <div> |
190 | 190 | <label>Exp.</label> |
191 | - <input type="text" class="text" size="4" name="x_exp_date" value="'.($prefill ? '04/17' : '').'"></input> |
|
191 | + <input type="text" class="text" size="4" name="x_exp_date" value="'.($prefill ? '04/17' : '') . '"></input> |
|
192 | 192 | </div> |
193 | 193 | <div> |
194 | 194 | <label>CCV</label> |
195 | - <input type="text" class="text" size="4" name="x_card_code" value="'.($prefill ? '782' : '').'"></input> |
|
195 | + <input type="text" class="text" size="4" name="x_card_code" value="'.($prefill ? '782' : '') . '"></input> |
|
196 | 196 | </div> |
197 | 197 | </fieldset> |
198 | 198 | <fieldset> |
199 | 199 | <div> |
200 | 200 | <label>First Name</label> |
201 | - <input type="text" class="text" size="15" name="x_first_name" value="'.($prefill ? 'John' : '').'"></input> |
|
201 | + <input type="text" class="text" size="15" name="x_first_name" value="'.($prefill ? 'John' : '') . '"></input> |
|
202 | 202 | </div> |
203 | 203 | <div> |
204 | 204 | <label>Last Name</label> |
205 | - <input type="text" class="text" size="14" name="x_last_name" value="'.($prefill ? 'Doe' : '').'"></input> |
|
205 | + <input type="text" class="text" size="14" name="x_last_name" value="'.($prefill ? 'Doe' : '') . '"></input> |
|
206 | 206 | </div> |
207 | 207 | </fieldset> |
208 | 208 | <fieldset> |
209 | 209 | <div> |
210 | 210 | <label>Address</label> |
211 | - <input type="text" class="text" size="26" name="x_address" value="'.($prefill ? '123 Main Street' : '').'"></input> |
|
211 | + <input type="text" class="text" size="26" name="x_address" value="'.($prefill ? '123 Main Street' : '') . '"></input> |
|
212 | 212 | </div> |
213 | 213 | <div> |
214 | 214 | <label>City</label> |
215 | - <input type="text" class="text" size="15" name="x_city" value="'.($prefill ? 'Boston' : '').'"></input> |
|
215 | + <input type="text" class="text" size="15" name="x_city" value="'.($prefill ? 'Boston' : '') . '"></input> |
|
216 | 216 | </div> |
217 | 217 | </fieldset> |
218 | 218 | <fieldset> |
219 | 219 | <div> |
220 | 220 | <label>State</label> |
221 | - <input type="text" class="text" size="4" name="x_state" value="'.($prefill ? 'MA' : '').'"></input> |
|
221 | + <input type="text" class="text" size="4" name="x_state" value="'.($prefill ? 'MA' : '') . '"></input> |
|
222 | 222 | </div> |
223 | 223 | <div> |
224 | 224 | <label>Zip Code</label> |
225 | - <input type="text" class="text" size="9" name="x_zip" value="'.($prefill ? '02142' : '').'"></input> |
|
225 | + <input type="text" class="text" size="9" name="x_zip" value="'.($prefill ? '02142' : '') . '"></input> |
|
226 | 226 | </div> |
227 | 227 | <div> |
228 | 228 | <label>Country</label> |
229 | - <input type="text" class="text" size="22" name="x_country" value="'.($prefill ? 'US' : '').'"></input> |
|
229 | + <input type="text" class="text" size="22" name="x_country" value="'.($prefill ? 'US' : '') . '"></input> |
|
230 | 230 | </div> |
231 | 231 | </fieldset> |
232 | 232 | <input type="submit" value="BUY" class="submit buy"> |
@@ -53,16 +53,14 @@ discard block |
||
53 | 53 | { |
54 | 54 | // Do your processing here. |
55 | 55 | $redirect_url = $url . '?response_code=1&transaction_id=' . $response->transaction_id; |
56 | - } |
|
57 | - else |
|
56 | + } else |
|
58 | 57 | { |
59 | 58 | // Redirect to error page. |
60 | 59 | $redirect_url = $url . '?response_code='.$response->response_code . '&response_reason_text=' . $response->response_reason_text; |
61 | 60 | } |
62 | 61 | // Send the Javascript back to AuthorizeNet, which will redirect user back to your site. |
63 | 62 | echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url); |
64 | - } |
|
65 | - else |
|
63 | + } else |
|
66 | 64 | { |
67 | 65 | echo "Error -- not AuthorizeNet. Check your MD5 Setting."; |
68 | 66 | } |
@@ -73,8 +71,7 @@ discard block |
||
73 | 71 | if ($_GET['response_code'] == 1) |
74 | 72 | { |
75 | 73 | echo "Thank you for your purchase! Transaction id: " . htmlentities($_GET['transaction_id']); |
76 | - } |
|
77 | - else |
|
74 | + } else |
|
78 | 75 | { |
79 | 76 | echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']); |
80 | 77 | } |
@@ -1,60 +1,60 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_filter( 'wpinv_authorizenet_support_subscription', '__return_true' ); |
|
5 | +add_filter('wpinv_authorizenet_support_subscription', '__return_true'); |
|
6 | 6 | |
7 | -function wpinv_authorizenet_cc_form( $invoice_id ) { |
|
8 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
9 | - $cc_owner = !empty( $invoice ) ? esc_attr( $invoice->get_user_full_name() ) : ''; |
|
7 | +function wpinv_authorizenet_cc_form($invoice_id) { |
|
8 | + $invoice = wpinv_get_invoice($invoice_id); |
|
9 | + $cc_owner = !empty($invoice) ? esc_attr($invoice->get_user_full_name()) : ''; |
|
10 | 10 | ?> |
11 | 11 | <div id="authorizenet_cc_form" class="form-horizontal wpi-cc-form panel panel-default"> |
12 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Card Details', 'invoicing' ) ;?></h3></div> |
|
12 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Card Details', 'invoicing'); ?></h3></div> |
|
13 | 13 | <div class="panel-body"> |
14 | 14 | <div class="form-group required"> |
15 | - <label for="auth-input-cc-owner" class="col-sm-4 control-label"><?php _e( 'Card Owner', 'invoicing' ) ;?></label> |
|
15 | + <label for="auth-input-cc-owner" class="col-sm-4 control-label"><?php _e('Card Owner', 'invoicing'); ?></label> |
|
16 | 16 | <div class="col-sm-8"> |
17 | - <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e( 'Card Owner', 'invoicing' ) ;?>" value="<?php echo $cc_owner;?>" name="authorizenet[cc_owner]"> |
|
17 | + <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e('Card Owner', 'invoicing'); ?>" value="<?php echo $cc_owner; ?>" name="authorizenet[cc_owner]"> |
|
18 | 18 | </div> |
19 | 19 | </div> |
20 | 20 | <div class="form-group required"> |
21 | - <label for="auth-input-cc-number" class="col-sm-4 control-label"><?php _e( 'Card Number', 'invoicing' ) ;?></label> |
|
21 | + <label for="auth-input-cc-number" class="col-sm-4 control-label"><?php _e('Card Number', 'invoicing'); ?></label> |
|
22 | 22 | <div class="col-sm-8"> |
23 | - <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e( 'Card Number', 'invoicing' ) ;?>" value="" name="authorizenet[cc_number]"> |
|
23 | + <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e('Card Number', 'invoicing'); ?>" value="" name="authorizenet[cc_number]"> |
|
24 | 24 | </div> |
25 | 25 | </div> |
26 | 26 | <div class="form-group required"> |
27 | - <label for="auth-input-cc-expire-date" class="col-sm-4 control-label"><?php _e( 'Card Expiry Date', 'invoicing' ) ;?></label> |
|
27 | + <label for="auth-input-cc-expire-date" class="col-sm-4 control-label"><?php _e('Card Expiry Date', 'invoicing'); ?></label> |
|
28 | 28 | <div class="col-sm-2"> |
29 | 29 | <select class="form-control" id="auth-input-cc-expire-date" name="authorizenet[cc_expire_month]"> |
30 | - <?php for ( $i = 1; $i <= 12; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
31 | - <option value="<?php echo $value;?>"><?php echo $value;?></option> |
|
30 | + <?php for ($i = 1; $i <= 12; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
31 | + <option value="<?php echo $value; ?>"><?php echo $value; ?></option> |
|
32 | 32 | <?php } ?> |
33 | 33 | </select> |
34 | 34 | </div> |
35 | 35 | <div class="col-sm-2"> |
36 | 36 | <select class="form-control" name="authorizenet[cc_expire_year]"> |
37 | - <?php $year = date( 'Y' ); for ( $i = $year; $i <= ( $year + 10 ); $i++ ) { ?> |
|
38 | - <option value="<?php echo $i;?>"><?php echo $i;?></option> |
|
37 | + <?php $year = date('Y'); for ($i = $year; $i <= ($year + 10); $i++) { ?> |
|
38 | + <option value="<?php echo $i; ?>"><?php echo $i; ?></option> |
|
39 | 39 | <?php } ?> |
40 | 40 | </select> |
41 | 41 | </div> |
42 | 42 | </div> |
43 | 43 | <div class="form-group required"> |
44 | - <label for="auth-input-cc-cvv2" class="col-sm-4 control-label"><?php _e( 'Card Security Code (CVV2)', 'invoicing' ) ;?></label> |
|
44 | + <label for="auth-input-cc-cvv2" class="col-sm-4 control-label"><?php _e('Card Security Code (CVV2)', 'invoicing'); ?></label> |
|
45 | 45 | <div class="col-sm-8"> |
46 | - <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e( 'Card Security Code (CVV2)', 'invoicing' ) ;?>" value="" name="authorizenet[cc_cvv2]""> |
|
46 | + <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e('Card Security Code (CVV2)', 'invoicing'); ?>" value="" name="authorizenet[cc_cvv2]""> |
|
47 | 47 | </div> |
48 | 48 | </div> |
49 | 49 | </div> |
50 | 50 | </div> |
51 | 51 | <?php |
52 | 52 | } |
53 | -add_action( 'wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1 ); |
|
53 | +add_action('wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1); |
|
54 | 54 | |
55 | -function wpinv_process_authorizenet_payment( $purchase_data ) { |
|
56 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
57 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
55 | +function wpinv_process_authorizenet_payment($purchase_data) { |
|
56 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
57 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // Collect payment data |
@@ -72,10 +72,10 @@ discard block |
||
72 | 72 | ); |
73 | 73 | |
74 | 74 | // Record the pending payment |
75 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
75 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
76 | 76 | |
77 | - if ( !empty( $invoice ) ) { |
|
78 | - $authorizenet_card = !empty( $_POST['authorizenet'] ) ? $_POST['authorizenet'] : array(); |
|
77 | + if (!empty($invoice)) { |
|
78 | + $authorizenet_card = !empty($_POST['authorizenet']) ? $_POST['authorizenet'] : array(); |
|
79 | 79 | $card_defaults = array( |
80 | 80 | 'cc_owner' => $invoice->get_user_full_name(), |
81 | 81 | 'cc_number' => false, |
@@ -83,27 +83,27 @@ discard block |
||
83 | 83 | 'cc_expire_year' => false, |
84 | 84 | 'cc_cvv2' => false, |
85 | 85 | ); |
86 | - $authorizenet_card = wp_parse_args( $authorizenet_card, $card_defaults ); |
|
86 | + $authorizenet_card = wp_parse_args($authorizenet_card, $card_defaults); |
|
87 | 87 | |
88 | - if ( empty( $authorizenet_card['cc_owner'] ) ) { |
|
89 | - wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing')); |
|
88 | + if (empty($authorizenet_card['cc_owner'])) { |
|
89 | + wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing')); |
|
90 | 90 | } |
91 | - if ( empty( $authorizenet_card['cc_number'] ) ) { |
|
92 | - wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing')); |
|
91 | + if (empty($authorizenet_card['cc_number'])) { |
|
92 | + wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing')); |
|
93 | 93 | } |
94 | - if ( empty( $authorizenet_card['cc_expire_month'] ) ) { |
|
95 | - wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing')); |
|
94 | + if (empty($authorizenet_card['cc_expire_month'])) { |
|
95 | + wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing')); |
|
96 | 96 | } |
97 | - if ( empty( $authorizenet_card['cc_expire_year'] ) ) { |
|
98 | - wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing')); |
|
97 | + if (empty($authorizenet_card['cc_expire_year'])) { |
|
98 | + wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing')); |
|
99 | 99 | } |
100 | - if ( empty( $authorizenet_card['cc_cvv2'] ) ) { |
|
101 | - wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) ); |
|
100 | + if (empty($authorizenet_card['cc_cvv2'])) { |
|
101 | + wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing')); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | $errors = wpinv_get_errors(); |
105 | 105 | |
106 | - if ( empty( $errors ) ) { |
|
106 | + if (empty($errors)) { |
|
107 | 107 | $invoice_id = $invoice->ID; |
108 | 108 | $quantities_enabled = wpinv_item_quantities_enabled(); |
109 | 109 | $use_taxes = wpinv_use_taxes(); |
@@ -112,141 +112,141 @@ discard block |
||
112 | 112 | $authorizeAIM->first_name = $invoice->get_first_name(); |
113 | 113 | $authorizeAIM->last_name = $invoice->get_last_name(); |
114 | 114 | $authorizeAIM->company = $invoice->company; |
115 | - $authorizeAIM->address = wp_strip_all_tags( $invoice->get_address(), true ); |
|
115 | + $authorizeAIM->address = wp_strip_all_tags($invoice->get_address(), true); |
|
116 | 116 | $authorizeAIM->city = $invoice->city; |
117 | 117 | $authorizeAIM->state = $invoice->state; |
118 | 118 | $authorizeAIM->zip = $invoice->zip; |
119 | 119 | $authorizeAIM->country = $invoice->country; |
120 | 120 | $authorizeAIM->phone = $invoice->phone; |
121 | 121 | $authorizeAIM->email = $invoice->get_email(); |
122 | - $authorizeAIM->amount = wpinv_sanitize_amount( $invoice->get_total() ); |
|
123 | - $authorizeAIM->card_num = str_replace( ' ', '', sanitize_text_field( $authorizenet_card['cc_number'] ) ); |
|
124 | - $authorizeAIM->exp_date = sanitize_text_field( $authorizenet_card['cc_expire_month'] ) . sanitize_text_field( $authorizenet_card['cc_expire_year'] ); |
|
125 | - $authorizeAIM->card_code = sanitize_text_field( $authorizenet_card['cc_cvv2'] ); |
|
122 | + $authorizeAIM->amount = wpinv_sanitize_amount($invoice->get_total()); |
|
123 | + $authorizeAIM->card_num = str_replace(' ', '', sanitize_text_field($authorizenet_card['cc_number'])); |
|
124 | + $authorizeAIM->exp_date = sanitize_text_field($authorizenet_card['cc_expire_month']) . sanitize_text_field($authorizenet_card['cc_expire_year']); |
|
125 | + $authorizeAIM->card_code = sanitize_text_field($authorizenet_card['cc_cvv2']); |
|
126 | 126 | $authorizeAIM->invoice_num = $invoice->ID; |
127 | 127 | |
128 | 128 | $item_desc = array(); |
129 | - foreach ( $invoice->get_cart_details() as $item ) { |
|
130 | - $quantity = $quantities_enabled && !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
131 | - $item_desc[] = $item['name'] . ' (' . $quantity . 'x ' . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')'; |
|
129 | + foreach ($invoice->get_cart_details() as $item) { |
|
130 | + $quantity = $quantities_enabled && !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
131 | + $item_desc[] = $item['name'] . ' (' . $quantity . 'x ' . wpinv_price(wpinv_format_amount($item['item_price'])) . ')'; |
|
132 | 132 | |
133 | - $authorizeAIM->addLineItem( $item['id'], $item['name'], '', $quantity, $item['item_price'], ( $use_taxes && !empty( $item['tax'] ) && $item['tax'] > 0 ? 'Y' : 'N' ) ); |
|
133 | + $authorizeAIM->addLineItem($item['id'], $item['name'], '', $quantity, $item['item_price'], ($use_taxes && !empty($item['tax']) && $item['tax'] > 0 ? 'Y' : 'N')); |
|
134 | 134 | } |
135 | 135 | |
136 | - $item_desc = '#' . $invoice->get_number() . ': ' . implode( ', ', $item_desc ); |
|
136 | + $item_desc = '#' . $invoice->get_number() . ': ' . implode(', ', $item_desc); |
|
137 | 137 | |
138 | - if ( $use_taxes && $invoice->get_tax() > 0 ) { |
|
139 | - $authorizeAIM->tax = $invoice->get_tax(); |
|
138 | + if ($use_taxes && $invoice->get_tax() > 0) { |
|
139 | + $authorizeAIM->tax = $invoice->get_tax(); |
|
140 | 140 | |
141 | - $item_desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) ); |
|
141 | + $item_desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true)); |
|
142 | 142 | } |
143 | 143 | |
144 | - if ( $invoice->get_discount() > 0 ) { |
|
145 | - $item_desc .= ', ' . wp_sprintf( __( 'Discount: %s', 'invoicing' ), $invoice->get_discount( true ) ); |
|
144 | + if ($invoice->get_discount() > 0) { |
|
145 | + $item_desc .= ', ' . wp_sprintf(__('Discount: %s', 'invoicing'), $invoice->get_discount(true)); |
|
146 | 146 | } |
147 | 147 | |
148 | - $authorizeAIM->description = html_entity_decode( $item_desc , ENT_QUOTES, 'UTF-8' ); |
|
148 | + $authorizeAIM->description = html_entity_decode($item_desc, ENT_QUOTES, 'UTF-8'); |
|
149 | 149 | |
150 | 150 | $is_recurring = $invoice->is_recurring(); // Recurring payment. |
151 | 151 | |
152 | - if ( $is_recurring ) { |
|
152 | + if ($is_recurring) { |
|
153 | 153 | $authorizeAIM->recurring_billing = true; |
154 | 154 | } |
155 | 155 | |
156 | 156 | try { |
157 | - if ( $is_recurring ) { |
|
157 | + if ($is_recurring) { |
|
158 | 158 | $response = $authorizeAIM->authorizeOnly(); |
159 | 159 | } else { |
160 | 160 | $response = $authorizeAIM->authorizeAndCapture(); |
161 | 161 | } |
162 | 162 | |
163 | - if ( $response->approved || $response->held ) { |
|
164 | - if ( $response->approved ) { |
|
165 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
163 | + if ($response->approved || $response->held) { |
|
164 | + if ($response->approved) { |
|
165 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
166 | 166 | } |
167 | - wpinv_set_payment_transaction_id( $invoice_id, $response->transaction_id ); |
|
167 | + wpinv_set_payment_transaction_id($invoice_id, $response->transaction_id); |
|
168 | 168 | |
169 | - $message = wp_sprintf( __( 'Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing' ), $response->response_reason_text, $response->transaction_id, strtoupper( $response->transaction_type ), $response->authorization_code ); |
|
169 | + $message = wp_sprintf(__('Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing'), $response->response_reason_text, $response->transaction_id, strtoupper($response->transaction_type), $response->authorization_code); |
|
170 | 170 | |
171 | - wpinv_insert_payment_note( $invoice_id, $message ); |
|
171 | + wpinv_insert_payment_note($invoice_id, $message); |
|
172 | 172 | |
173 | - do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card ); |
|
173 | + do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card); |
|
174 | 174 | |
175 | 175 | wpinv_clear_errors(); |
176 | 176 | wpinv_empty_cart(); |
177 | 177 | |
178 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
178 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
179 | 179 | } else { |
180 | - if ( !empty( $response->response_reason_text ) ) { |
|
181 | - $error = __( $response->response_reason_text, 'invoicing' ); |
|
182 | - } else if ( !empty( $response->error_message ) ) { |
|
183 | - $error = __( $response->error_message, 'invoicing' ); |
|
180 | + if (!empty($response->response_reason_text)) { |
|
181 | + $error = __($response->response_reason_text, 'invoicing'); |
|
182 | + } else if (!empty($response->error_message)) { |
|
183 | + $error = __($response->error_message, 'invoicing'); |
|
184 | 184 | } else { |
185 | - $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) ); |
|
185 | + $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true)); |
|
186 | 186 | } |
187 | 187 | |
188 | - $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error ); |
|
188 | + $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error); |
|
189 | 189 | |
190 | - wpinv_set_error( 'payment_error', $error ); |
|
191 | - wpinv_record_gateway_error( $error, $response ); |
|
192 | - wpinv_insert_payment_note( $invoice_id, $error ); |
|
190 | + wpinv_set_error('payment_error', $error); |
|
191 | + wpinv_record_gateway_error($error, $response); |
|
192 | + wpinv_insert_payment_note($invoice_id, $error); |
|
193 | 193 | |
194 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
194 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
195 | 195 | } |
196 | - } catch ( AuthorizeNetException $e ) { |
|
197 | - wpinv_set_error( 'request_error', $e->getMessage() ); |
|
198 | - wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) ); |
|
199 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
196 | + } catch (AuthorizeNetException $e) { |
|
197 | + wpinv_set_error('request_error', $e->getMessage()); |
|
198 | + wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage())); |
|
199 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
200 | 200 | } |
201 | 201 | } else { |
202 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
202 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
203 | 203 | } |
204 | 204 | } else { |
205 | - wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing' ), print_r( $payment_data, true ) ), $invoice ); |
|
206 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
205 | + wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing'), print_r($payment_data, true)), $invoice); |
|
206 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
207 | 207 | } |
208 | 208 | } |
209 | -add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' ); |
|
209 | +add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment'); |
|
210 | 210 | |
211 | -function wpinv_authorizenet_cancel_subscription( $subscription_id = '' ) { |
|
212 | - if ( empty( $subscription_id ) ) { |
|
211 | +function wpinv_authorizenet_cancel_subscription($subscription_id = '') { |
|
212 | + if (empty($subscription_id)) { |
|
213 | 213 | return false; |
214 | 214 | } |
215 | 215 | |
216 | 216 | try { |
217 | 217 | $authnetXML = wpinv_authorizenet_XML(); |
218 | - $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription_id ) ); |
|
218 | + $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription_id)); |
|
219 | 219 | |
220 | 220 | return $authnetXML->isSuccessful(); |
221 | - } catch( Exception $e ) { |
|
222 | - wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) ); |
|
221 | + } catch (Exception $e) { |
|
222 | + wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing')); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | return false; |
226 | 226 | } |
227 | 227 | |
228 | -function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) { |
|
229 | - $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' ); |
|
230 | - if ( empty( $authorizenet_md5_hash ) ) { |
|
228 | +function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) { |
|
229 | + $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash'); |
|
230 | + if (empty($authorizenet_md5_hash)) { |
|
231 | 231 | return true; |
232 | 232 | } |
233 | 233 | |
234 | - $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) ); |
|
234 | + $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount)); |
|
235 | 235 | |
236 | - return hash_equals( $compare_md5, $md5_hash ); |
|
236 | + return hash_equals($compare_md5, $md5_hash); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | function wpinv_authorizenet_AIM() { |
240 | - if ( !class_exists( 'AuthorizeNetException' ) ) { |
|
241 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php'; |
|
240 | + if (!class_exists('AuthorizeNetException')) { |
|
241 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php'; |
|
242 | 242 | } |
243 | 243 | |
244 | - $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) ); |
|
244 | + $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key')); |
|
245 | 245 | |
246 | - if ( wpinv_is_test_mode( 'authorizenet' ) ) { |
|
247 | - $authorizeAIM->setSandbox( true ); |
|
246 | + if (wpinv_is_test_mode('authorizenet')) { |
|
247 | + $authorizeAIM->setSandbox(true); |
|
248 | 248 | } else { |
249 | - $authorizeAIM->setSandbox( false ); |
|
249 | + $authorizeAIM->setSandbox(false); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | $authorizeAIM->customer_ip = wpinv_get_ip(); |
@@ -255,164 +255,164 @@ discard block |
||
255 | 255 | } |
256 | 256 | |
257 | 257 | function wpinv_authorizenet_XML() { |
258 | - if ( !class_exists( 'AuthnetXML' ) ) { |
|
259 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php'; |
|
258 | + if (!class_exists('AuthnetXML')) { |
|
259 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php'; |
|
260 | 260 | } |
261 | 261 | |
262 | - $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) ); |
|
262 | + $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool)wpinv_is_test_mode('authorizenet')); |
|
263 | 263 | |
264 | 264 | return $authnetXML; |
265 | 265 | } |
266 | 266 | |
267 | -function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) { |
|
268 | - if ( empty( $response ) || empty( $invoice ) ) { |
|
267 | +function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) { |
|
268 | + if (empty($response) || empty($invoice)) { |
|
269 | 269 | return false; |
270 | 270 | } |
271 | 271 | |
272 | - if ( !empty( $response->approved ) ) { |
|
273 | - $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info ); |
|
272 | + if (!empty($response->approved)) { |
|
273 | + $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info); |
|
274 | 274 | |
275 | - if ( !empty( $subscription ) && $subscription->isSuccessful() ) { |
|
276 | - do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' ); |
|
275 | + if (!empty($subscription) && $subscription->isSuccessful()) { |
|
276 | + do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet'); |
|
277 | 277 | |
278 | - wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ); |
|
278 | + wpinv_authorizenet_subscription_record_signup($subscription, $invoice); |
|
279 | 279 | |
280 | - do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' ); |
|
280 | + do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet'); |
|
281 | 281 | } else { |
282 | - if ( isset( $subscription->messages->message ) ) { |
|
282 | + if (isset($subscription->messages->message)) { |
|
283 | 283 | $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text; |
284 | - wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' ); |
|
284 | + wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing'); |
|
285 | 285 | } else { |
286 | - $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' ); |
|
287 | - wpinv_set_error( 'wpinv_authorize_recurring_error', $error ); |
|
286 | + $error = __('Your subscription cannot be created due to an error.', 'invoicing'); |
|
287 | + wpinv_set_error('wpinv_authorize_recurring_error', $error); |
|
288 | 288 | } |
289 | 289 | |
290 | - wpinv_record_gateway_error( $error, $subscription ); |
|
290 | + wpinv_record_gateway_error($error, $subscription); |
|
291 | 291 | |
292 | - wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ) ); |
|
292 | + wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error)); |
|
293 | 293 | } |
294 | 294 | } |
295 | 295 | } |
296 | -add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 ); |
|
296 | +add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3); |
|
297 | 297 | |
298 | -function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) { |
|
299 | - if ( empty( $invoice ) ) { |
|
298 | +function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) { |
|
299 | + if (empty($invoice)) { |
|
300 | 300 | return false; |
301 | 301 | } |
302 | 302 | |
303 | - $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response ); |
|
303 | + $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response); |
|
304 | 304 | |
305 | 305 | try { |
306 | 306 | $authnetXML = wpinv_authorizenet_XML(); |
307 | - $authnetXML->ARBCreateSubscriptionRequest( $params ); |
|
308 | - } catch( Exception $e ) { |
|
307 | + $authnetXML->ARBCreateSubscriptionRequest($params); |
|
308 | + } catch (Exception $e) { |
|
309 | 309 | $authnetXML = array(); |
310 | - wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) ); |
|
310 | + wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing')); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | return $authnetXML; |
314 | 314 | } |
315 | 315 | |
316 | -function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) { |
|
317 | - if ( empty( $invoice ) ) { |
|
316 | +function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) { |
|
317 | + if (empty($invoice)) { |
|
318 | 318 | return false; |
319 | 319 | } |
320 | 320 | |
321 | - $subscription_item = $invoice->get_recurring( true ); |
|
322 | - if ( empty( $subscription_item ) ) { |
|
321 | + $subscription_item = $invoice->get_recurring(true); |
|
322 | + if (empty($subscription_item)) { |
|
323 | 323 | return false; |
324 | 324 | } |
325 | 325 | |
326 | - $card_details = wpinv_authorizenet_generate_card_info( $card_info ); |
|
326 | + $card_details = wpinv_authorizenet_generate_card_info($card_info); |
|
327 | 327 | $subscription_name = $invoice->get_subscription_name(); |
328 | - $initial_amount = wpinv_format_amount( $invoice->get_total() ); |
|
329 | - $recurring_amount = wpinv_format_amount( $invoice->get_recurring_details( 'total' ) ); |
|
328 | + $initial_amount = wpinv_format_amount($invoice->get_total()); |
|
329 | + $recurring_amount = wpinv_format_amount($invoice->get_recurring_details('total')); |
|
330 | 330 | $interval = $subscription_item->get_recurring_interval(); |
331 | 331 | $period = $subscription_item->get_recurring_period(); |
332 | 332 | $bill_times = (int)$subscription_item->get_recurring_limit(); |
333 | 333 | $bill_times = $bill_times > 0 ? $bill_times : 9999; |
334 | 334 | |
335 | - $time_period = wpinv_authorizenet_get_time_period( $interval, $period ); |
|
335 | + $time_period = wpinv_authorizenet_get_time_period($interval, $period); |
|
336 | 336 | $interval = $time_period['interval']; |
337 | 337 | $period = $time_period['period']; |
338 | 338 | |
339 | 339 | $current_tz = date_default_timezone_get(); |
340 | - date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts. |
|
341 | - $today = date( 'Y-m-d' ); |
|
342 | - date_default_timezone_set( $current_tz ); |
|
340 | + date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts. |
|
341 | + $today = date('Y-m-d'); |
|
342 | + date_default_timezone_set($current_tz); |
|
343 | 343 | |
344 | 344 | $free_trial = $invoice->is_free_trial(); |
345 | - if ( $free_trial && $subscription_item->has_free_trial() ) { |
|
345 | + if ($free_trial && $subscription_item->has_free_trial()) { |
|
346 | 346 | $trial_interval = $subscription_item->get_trial_interval(); |
347 | - $trial_period = $subscription_item->get_trial_period( true ); |
|
347 | + $trial_period = $subscription_item->get_trial_period(true); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | $subscription = array(); |
351 | 351 | $subscription['name'] = $subscription_name; |
352 | 352 | |
353 | 353 | $subscription['paymentSchedule'] = array( |
354 | - 'interval' => array( 'length' => $interval, 'unit' => $period ), |
|
354 | + 'interval' => array('length' => $interval, 'unit' => $period), |
|
355 | 355 | 'startDate' => $today, |
356 | 356 | 'totalOccurrences' => $bill_times, |
357 | - 'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0, |
|
357 | + 'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0, |
|
358 | 358 | ); |
359 | 359 | |
360 | 360 | $subscription['amount'] = $recurring_amount; |
361 | 361 | $subscription['trialAmount'] = $initial_amount; |
362 | - $subscription['payment'] = array( 'creditCard' => $card_details ); |
|
363 | - $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() ); |
|
364 | - $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone ); |
|
362 | + $subscription['payment'] = array('creditCard' => $card_details); |
|
363 | + $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number()); |
|
364 | + $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone); |
|
365 | 365 | |
366 | 366 | $subscription['billTo'] = array( |
367 | 367 | 'firstName' => $invoice->get_first_name(), |
368 | 368 | 'lastName' => $invoice->get_last_name(), |
369 | 369 | 'company' => $invoice->company, |
370 | - 'address' => wp_strip_all_tags( $invoice->get_address(), true ), |
|
370 | + 'address' => wp_strip_all_tags($invoice->get_address(), true), |
|
371 | 371 | 'city' => $invoice->city, |
372 | 372 | 'state' => $invoice->state, |
373 | 373 | 'zip' => $invoice->zip, |
374 | 374 | 'country' => $invoice->country, |
375 | 375 | ); |
376 | 376 | |
377 | - $params = array( 'subscription' => $subscription ); |
|
377 | + $params = array('subscription' => $subscription); |
|
378 | 378 | |
379 | - return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response ); |
|
379 | + return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response); |
|
380 | 380 | } |
381 | 381 | |
382 | -function wpinv_authorizenet_generate_card_info( $card_info = array() ) { |
|
383 | - $card_defaults = array( |
|
382 | +function wpinv_authorizenet_generate_card_info($card_info = array()) { |
|
383 | + $card_defaults = array( |
|
384 | 384 | 'cc_owner' => null, |
385 | 385 | 'cc_number' => null, |
386 | 386 | 'cc_expire_month' => null, |
387 | 387 | 'cc_expire_year' => null, |
388 | 388 | 'cc_cvv2' => null, |
389 | 389 | ); |
390 | - $card_info = wp_parse_args( $card_info, $card_defaults ); |
|
390 | + $card_info = wp_parse_args($card_info, $card_defaults); |
|
391 | 391 | |
392 | 392 | $card_details = array( |
393 | - 'cardNumber' => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ), |
|
394 | - 'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ), |
|
395 | - 'cardCode' => sanitize_text_field( $card_info['cc_cvv2'] ), |
|
393 | + 'cardNumber' => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])), |
|
394 | + 'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']), |
|
395 | + 'cardCode' => sanitize_text_field($card_info['cc_cvv2']), |
|
396 | 396 | ); |
397 | 397 | |
398 | 398 | return $card_details; |
399 | 399 | } |
400 | 400 | |
401 | -function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) { |
|
402 | - if ( empty( $invoice ) || empty( $subscription ) ) { |
|
401 | +function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) { |
|
402 | + if (empty($invoice) || empty($subscription)) { |
|
403 | 403 | return false; |
404 | 404 | } |
405 | 405 | |
406 | - $subscription_item = $invoice->get_recurring( true ); |
|
407 | - if ( empty( $subscription_item ) ) { |
|
406 | + $subscription_item = $invoice->get_recurring(true); |
|
407 | + if (empty($subscription_item)) { |
|
408 | 408 | return false; |
409 | 409 | } |
410 | 410 | |
411 | 411 | $invoice_id = $invoice->ID; |
412 | 412 | $subscriptionId = (array)$subscription->subscriptionId; |
413 | - $subscription_id = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $invoice_id; |
|
413 | + $subscription_id = !empty($subscriptionId[0]) ? $subscriptionId[0] : $invoice_id; |
|
414 | 414 | |
415 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ) ); |
|
415 | + wpinv_insert_payment_note($invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id)); |
|
416 | 416 | |
417 | 417 | $status = $invoice->is_free_trial() && $subscription_item->has_free_trial() ? 'trialing' : 'active'; |
418 | 418 | |
@@ -420,16 +420,16 @@ discard block |
||
420 | 420 | 'profile_id' => $subscription_id, |
421 | 421 | 'item_id' => $subscription_item->ID, |
422 | 422 | 'initial_amount' => $invoice->get_total(), |
423 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
423 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
424 | 424 | 'period' => $subscription_item->get_recurring_period(), |
425 | 425 | 'interval' => $subscription_item->get_recurring_interval(), |
426 | 426 | 'bill_times' => $subscription_item->get_recurring_limit(), |
427 | - 'expiration' => $invoice->get_new_expiration( $subscription_item->ID ), |
|
427 | + 'expiration' => $invoice->get_new_expiration($subscription_item->ID), |
|
428 | 428 | 'status' => $status, |
429 | - 'created' => current_time( 'mysql', 0 ) |
|
429 | + 'created' => current_time('mysql', 0) |
|
430 | 430 | ); |
431 | 431 | |
432 | - if ( $invoice->is_free_trial() && $subscription_item->has_free_trial() ) { |
|
432 | + if ($invoice->is_free_trial() && $subscription_item->has_free_trial()) { |
|
433 | 433 | $args['trial_period'] = $subscription_item->get_trial_period(); |
434 | 434 | $args['trial_interval'] = $subscription_item->get_trial_interval(); |
435 | 435 | } else { |
@@ -437,58 +437,58 @@ discard block |
||
437 | 437 | $args['trial_interval'] = 0; |
438 | 438 | } |
439 | 439 | |
440 | - return $invoice->update_subscription( $args ); |
|
440 | + return $invoice->update_subscription($args); |
|
441 | 441 | } |
442 | 442 | |
443 | -function wpinv_authorizenet_validate_checkout( $valid_data, $post ) { |
|
444 | - if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) { |
|
443 | +function wpinv_authorizenet_validate_checkout($valid_data, $post) { |
|
444 | + if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') { |
|
445 | 445 | $error = false; |
446 | 446 | |
447 | - if ( empty( $post['authorizenet']['cc_owner'] ) ) { |
|
447 | + if (empty($post['authorizenet']['cc_owner'])) { |
|
448 | 448 | $error = true; |
449 | - wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing')); |
|
449 | + wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing')); |
|
450 | 450 | } |
451 | - if ( empty( $post['authorizenet']['cc_number'] ) ) { |
|
451 | + if (empty($post['authorizenet']['cc_number'])) { |
|
452 | 452 | $error = true; |
453 | - wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing')); |
|
453 | + wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing')); |
|
454 | 454 | } |
455 | - if ( empty( $post['authorizenet']['cc_expire_month'] ) ) { |
|
455 | + if (empty($post['authorizenet']['cc_expire_month'])) { |
|
456 | 456 | $error = true; |
457 | - wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing')); |
|
457 | + wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing')); |
|
458 | 458 | } |
459 | - if ( empty( $post['authorizenet']['cc_expire_year'] ) ) { |
|
459 | + if (empty($post['authorizenet']['cc_expire_year'])) { |
|
460 | 460 | $error = true; |
461 | - wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing')); |
|
461 | + wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing')); |
|
462 | 462 | } |
463 | - if ( empty( $post['authorizenet']['cc_cvv2'] ) ) { |
|
463 | + if (empty($post['authorizenet']['cc_cvv2'])) { |
|
464 | 464 | $error = true; |
465 | - wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) ); |
|
465 | + wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing')); |
|
466 | 466 | } |
467 | 467 | |
468 | - if ( $error ) { |
|
468 | + if ($error) { |
|
469 | 469 | return; |
470 | 470 | } |
471 | 471 | |
472 | 472 | $invoice = wpinv_get_invoice_cart(); |
473 | 473 | |
474 | - if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) { |
|
475 | - $subscription_item = $invoice->get_recurring( true ); |
|
474 | + if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) { |
|
475 | + $subscription_item = $invoice->get_recurring(true); |
|
476 | 476 | |
477 | 477 | $interval = $subscription_item->get_recurring_interval(); |
478 | 478 | $period = $subscription_item->get_recurring_period(); |
479 | 479 | |
480 | - if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) { |
|
481 | - wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) ); |
|
480 | + if ($period == 'D' && ($interval < 7 || $interval > 365)) { |
|
481 | + wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing')); |
|
482 | 482 | } |
483 | 483 | } |
484 | 484 | } |
485 | 485 | } |
486 | -add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 ); |
|
486 | +add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2); |
|
487 | 487 | |
488 | -function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) { |
|
489 | - $subscription_interval = absint( $subscription_interval ); |
|
488 | +function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) { |
|
489 | + $subscription_interval = absint($subscription_interval); |
|
490 | 490 | |
491 | - switch( $subscription_period ) { |
|
491 | + switch ($subscription_period) { |
|
492 | 492 | case 'W': |
493 | 493 | case 'week': |
494 | 494 | case 'weeks': |
@@ -498,14 +498,14 @@ discard block |
||
498 | 498 | case 'M': |
499 | 499 | case 'month': |
500 | 500 | case 'months': |
501 | - if ( $subscription_interval > 12 ) { |
|
501 | + if ($subscription_interval > 12) { |
|
502 | 502 | $subscription_interval = 12; |
503 | 503 | } |
504 | 504 | |
505 | 505 | $interval = $subscription_interval; |
506 | 506 | $period = 'months'; |
507 | 507 | |
508 | - if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) { |
|
508 | + if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) { |
|
509 | 509 | $interval = $subscription_interval * 30; |
510 | 510 | $period = 'days'; |
511 | 511 | } |
@@ -522,40 +522,40 @@ discard block |
||
522 | 522 | break; |
523 | 523 | } |
524 | 524 | |
525 | - return compact( 'interval', 'period' ); |
|
525 | + return compact('interval', 'period'); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | function wpinv_authorizenet_process_ipn() { |
529 | - if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) { |
|
529 | + if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) { |
|
530 | 530 | return; |
531 | 531 | } |
532 | 532 | |
533 | - $subscription_id = intval( $_POST['x_subscription_id'] ); |
|
533 | + $subscription_id = intval($_POST['x_subscription_id']); |
|
534 | 534 | |
535 | - if ( $subscription_id ) { |
|
536 | - $transaction_id = sanitize_text_field( $_POST['x_trans_id'] ); |
|
537 | - $renewal_amount = sanitize_text_field( $_POST['x_amount'] ); |
|
538 | - $response_code = intval( $_POST['x_response_code'] ); |
|
539 | - $reason_code = intval( $_POST['x_response_reason_code'] ); |
|
535 | + if ($subscription_id) { |
|
536 | + $transaction_id = sanitize_text_field($_POST['x_trans_id']); |
|
537 | + $renewal_amount = sanitize_text_field($_POST['x_amount']); |
|
538 | + $response_code = intval($_POST['x_response_code']); |
|
539 | + $reason_code = intval($_POST['x_response_reason_code']); |
|
540 | 540 | |
541 | - if ( 1 == $response_code ) { |
|
541 | + if (1 == $response_code) { |
|
542 | 542 | // Approved |
543 | - do_action( 'wpinv_authorizenet_renewal_payment', $transaction_id ); |
|
544 | - } else if ( 2 == $response_code ) { |
|
543 | + do_action('wpinv_authorizenet_renewal_payment', $transaction_id); |
|
544 | + } else if (2 == $response_code) { |
|
545 | 545 | // Declined |
546 | - do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id ); |
|
547 | - do_action( 'wpinv_authorizenet_renewal_error', $transaction_id ); |
|
548 | - } else if ( 3 == $response_code || 8 == $reason_code ) { |
|
546 | + do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id); |
|
547 | + do_action('wpinv_authorizenet_renewal_error', $transaction_id); |
|
548 | + } else if (3 == $response_code || 8 == $reason_code) { |
|
549 | 549 | // An expired card |
550 | - do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id ); |
|
551 | - do_action( 'wpinv_authorizenet_renewal_payment_error', $transaction_id ); |
|
550 | + do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id); |
|
551 | + do_action('wpinv_authorizenet_renewal_payment_error', $transaction_id); |
|
552 | 552 | |
553 | 553 | } else { |
554 | 554 | // Other Error |
555 | - do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription ); |
|
555 | + do_action('wpinv_authorizenet_renewal_payment_error', $subscription); |
|
556 | 556 | } |
557 | 557 | |
558 | 558 | exit; |
559 | 559 | } |
560 | 560 | } |
561 | -add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' ); |
|
562 | 561 | \ No newline at end of file |
562 | +add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn'); |
|
563 | 563 | \ No newline at end of file |
@@ -1,6 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; |
|
5 | +} |
|
4 | 6 | |
5 | 7 | add_filter( 'wpinv_authorizenet_support_subscription', '__return_true' ); |
6 | 8 |