@@ -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(); |
@@ -32,31 +32,31 @@ discard block |
||
32 | 32 | } |
33 | 33 | |
34 | 34 | public function define_constants() { |
35 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
36 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
35 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
36 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | private function actions() { |
40 | 40 | /* Internationalize the text strings used. */ |
41 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
41 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
42 | 42 | |
43 | 43 | /* Perform actions on admin initialization. */ |
44 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
45 | - add_action( 'init', array( &$this, 'init' ), 3 ); |
|
46 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
44 | + add_action('admin_init', array(&$this, 'admin_init')); |
|
45 | + add_action('init', array(&$this, 'init'), 3); |
|
46 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
47 | 47 | |
48 | - if ( class_exists( 'BuddyPress' ) ) { |
|
49 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
48 | + if (class_exists('BuddyPress')) { |
|
49 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
50 | 50 | } |
51 | 51 | |
52 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
53 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
52 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
53 | + add_action('widgets_init', array(&$this, 'register_widgets')); |
|
54 | 54 | |
55 | - if ( is_admin() ) { |
|
56 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
57 | - add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
55 | + if (is_admin()) { |
|
56 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
57 | + add_action('admin_body_class', array(&$this, 'admin_body_class')); |
|
58 | 58 | } else { |
59 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
59 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -66,19 +66,19 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
68 | 68 | */ |
69 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
69 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
70 | 70 | |
71 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
71 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | public function plugins_loaded() { |
75 | 75 | /* Internationalize the text strings used. */ |
76 | 76 | $this->load_textdomain(); |
77 | 77 | |
78 | - do_action( 'wpinv_loaded' ); |
|
78 | + do_action('wpinv_loaded'); |
|
79 | 79 | |
80 | 80 | // Fix oxygen page builder conflict |
81 | - if ( function_exists( 'ct_css_output' ) ) { |
|
81 | + if (function_exists('ct_css_output')) { |
|
82 | 82 | wpinv_oxygen_fix_conflict(); |
83 | 83 | } |
84 | 84 | } |
@@ -88,228 +88,228 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @since 1.0 |
90 | 90 | */ |
91 | - public function load_textdomain( $locale = NULL ) { |
|
92 | - if ( empty( $locale ) ) { |
|
93 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
91 | + public function load_textdomain($locale = NULL) { |
|
92 | + if (empty($locale)) { |
|
93 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
94 | 94 | } |
95 | 95 | |
96 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
96 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
97 | 97 | |
98 | - unload_textdomain( 'invoicing' ); |
|
99 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
100 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
98 | + unload_textdomain('invoicing'); |
|
99 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
100 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
101 | 101 | |
102 | 102 | /** |
103 | 103 | * Define language constants. |
104 | 104 | */ |
105 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
105 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | public function includes() { |
109 | 109 | global $wpinv_options; |
110 | 110 | |
111 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
111 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
112 | 112 | $wpinv_options = wpinv_get_settings(); |
113 | 113 | |
114 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
115 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
116 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
117 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
118 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
119 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
120 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
121 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
122 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
123 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
124 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
125 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
126 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
127 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
128 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
129 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
130 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
131 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
132 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
133 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
134 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
135 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
136 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
137 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
138 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
139 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
140 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
141 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
142 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
143 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' ); |
|
144 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
145 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
146 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
147 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
148 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
149 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
150 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
151 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
152 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
153 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
154 | - |
|
155 | - if ( !class_exists( 'WPInv_EUVat' ) ) { |
|
156 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
114 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
115 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
116 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
117 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
118 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
119 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
120 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
121 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
122 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
123 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
124 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
125 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
126 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
127 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
128 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
129 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
130 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
131 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
132 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'); |
|
133 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'); |
|
134 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
135 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
136 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
137 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
138 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
139 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
140 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
141 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php'); |
|
142 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
143 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php'); |
|
144 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'); |
|
145 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
146 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'); |
|
147 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'); |
|
148 | + require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php'); |
|
149 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'); |
|
150 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'); |
|
151 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'); |
|
152 | + require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'); |
|
153 | + require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php'); |
|
154 | + |
|
155 | + if (!class_exists('WPInv_EUVat')) { |
|
156 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
157 | 157 | } |
158 | 158 | |
159 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
160 | - if ( !empty( $gateways ) ) { |
|
161 | - foreach ( $gateways as $gateway ) { |
|
162 | - if ( $gateway == 'manual' ) { |
|
159 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
160 | + if (!empty($gateways)) { |
|
161 | + foreach ($gateways as $gateway) { |
|
162 | + if ($gateway == 'manual') { |
|
163 | 163 | continue; |
164 | 164 | } |
165 | 165 | |
166 | 166 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
167 | 167 | |
168 | - if ( file_exists( $gateway_file ) ) { |
|
169 | - require_once( $gateway_file ); |
|
168 | + if (file_exists($gateway_file)) { |
|
169 | + require_once($gateway_file); |
|
170 | 170 | } |
171 | 171 | } |
172 | 172 | } |
173 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
173 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
174 | 174 | |
175 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
176 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
177 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
178 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
175 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
176 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
177 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
178 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
179 | 179 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
180 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
181 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
182 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
183 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
184 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
185 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
186 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
180 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
181 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
182 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
183 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
184 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
185 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'); |
|
186 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
187 | 187 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
188 | 188 | // load the user class only on the users.php page |
189 | 189 | global $pagenow; |
190 | - if($pagenow=='users.php'){ |
|
190 | + if ($pagenow == 'users.php') { |
|
191 | 191 | new WPInv_Admin_Users(); |
192 | 192 | } |
193 | 193 | } |
194 | 194 | |
195 | 195 | // Register cli commands |
196 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
198 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
196 | + if (defined('WP_CLI') && WP_CLI) { |
|
197 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'); |
|
198 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | // include css inliner |
202 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
203 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
202 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
203 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
204 | 204 | } |
205 | 205 | |
206 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
206 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | public function init() { |
210 | 210 | } |
211 | 211 | |
212 | 212 | public function admin_init() { |
213 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
213 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | public function activation_redirect() { |
217 | 217 | // Bail if no activation redirect |
218 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
218 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
219 | 219 | return; |
220 | 220 | } |
221 | 221 | |
222 | 222 | // Delete the redirect transient |
223 | - delete_transient( '_wpinv_activation_redirect' ); |
|
223 | + delete_transient('_wpinv_activation_redirect'); |
|
224 | 224 | |
225 | 225 | // Bail if activating from network, or bulk |
226 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
226 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
227 | 227 | return; |
228 | 228 | } |
229 | 229 | |
230 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
230 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
231 | 231 | exit; |
232 | 232 | } |
233 | 233 | |
234 | 234 | public function enqueue_scripts() { |
235 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
235 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
236 | 236 | |
237 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION ); |
|
238 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
237 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION); |
|
238 | + wp_enqueue_style('wpinv_front_style'); |
|
239 | 239 | |
240 | 240 | // Register scripts |
241 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
242 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), WPINV_VERSION ); |
|
241 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
242 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), WPINV_VERSION); |
|
243 | 243 | |
244 | 244 | $localize = array(); |
245 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
246 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
245 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
246 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
247 | 247 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
248 | 248 | $localize['currency_pos'] = wpinv_currency_position(); |
249 | 249 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
250 | 250 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
251 | 251 | $localize['decimals'] = wpinv_decimals(); |
252 | - $localize['txtComplete'] = __( 'Complete', 'invoicing' ); |
|
252 | + $localize['txtComplete'] = __('Complete', 'invoicing'); |
|
253 | 253 | $localize['UseTaxes'] = wpinv_use_taxes(); |
254 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
254 | + $localize['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
255 | 255 | |
256 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
256 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
257 | 257 | |
258 | - wp_enqueue_script( 'jquery-blockui' ); |
|
258 | + wp_enqueue_script('jquery-blockui'); |
|
259 | 259 | $autofill_api = wpinv_get_option('address_autofill_api'); |
260 | 260 | $autofill_active = wpinv_get_option('address_autofill_active'); |
261 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
262 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
263 | - wp_dequeue_script( 'google-maps-api' ); |
|
261 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
|
262 | + if (wp_script_is('google-maps-api', 'enqueued')) { |
|
263 | + wp_dequeue_script('google-maps-api'); |
|
264 | 264 | } |
265 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
266 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
265 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
266 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
267 | 267 | } |
268 | 268 | |
269 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
270 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
269 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
270 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
271 | 271 | |
272 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
273 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
272 | + wp_enqueue_script('wpinv-front-script'); |
|
273 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | public function admin_enqueue_scripts() { |
277 | 277 | global $post, $pagenow; |
278 | 278 | |
279 | 279 | $post_type = wpinv_admin_post_type(); |
280 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
281 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : ''; |
|
280 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
281 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : ''; |
|
282 | 282 | |
283 | 283 | $jquery_ui_css = false; |
284 | - if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
284 | + if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
285 | 285 | $jquery_ui_css = true; |
286 | - } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) { |
|
286 | + } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') { |
|
287 | 287 | $jquery_ui_css = true; |
288 | 288 | } |
289 | - if ( $jquery_ui_css ) { |
|
290 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
291 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
289 | + if ($jquery_ui_css) { |
|
290 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
291 | + wp_enqueue_style('jquery-ui-css'); |
|
292 | 292 | } |
293 | 293 | |
294 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
295 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
294 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
295 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
296 | 296 | |
297 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION ); |
|
298 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
297 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION); |
|
298 | + wp_enqueue_style('wpinv_admin_style'); |
|
299 | 299 | |
300 | - $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ); |
|
301 | - if ( $page == 'wpinv-subscriptions' ) { |
|
302 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
300 | + $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')); |
|
301 | + if ($page == 'wpinv-subscriptions') { |
|
302 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
303 | 303 | } |
304 | 304 | |
305 | - if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
|
306 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
305 | + if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) { |
|
306 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
307 | 307 | } |
308 | 308 | |
309 | - wp_enqueue_style( 'wp-color-picker' ); |
|
310 | - wp_enqueue_script( 'wp-color-picker' ); |
|
309 | + wp_enqueue_style('wp-color-picker'); |
|
310 | + wp_enqueue_script('wp-color-picker'); |
|
311 | 311 | |
312 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
312 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
313 | 313 | |
314 | 314 | if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
315 | 315 | $autofill_api = wpinv_get_option('address_autofill_api'); |
@@ -320,20 +320,20 @@ discard block |
||
320 | 320 | } |
321 | 321 | } |
322 | 322 | |
323 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
324 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
323 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
324 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
325 | 325 | |
326 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), WPINV_VERSION ); |
|
327 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
326 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), WPINV_VERSION); |
|
327 | + wp_enqueue_script('wpinv-admin-script'); |
|
328 | 328 | |
329 | 329 | $localize = array(); |
330 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
331 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
332 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
333 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
334 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
335 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
336 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
330 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
331 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
332 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
333 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
334 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
335 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
336 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
337 | 337 | $localize['tax'] = wpinv_tax_amount(); |
338 | 338 | $localize['discount'] = wpinv_discount_amount(); |
339 | 339 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -341,69 +341,69 @@ discard block |
||
341 | 341 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
342 | 342 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
343 | 343 | $localize['decimals'] = wpinv_decimals(); |
344 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
345 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
346 | - $localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
347 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
348 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
349 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
350 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
351 | - $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' ); |
|
352 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
353 | - $localize['emptyInvoice'] = __( 'Add at least one item to save invoice!', 'invoicing' ); |
|
354 | - $localize['errDeleteItem'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
355 | - $localize['delete_subscription'] = __( 'Are you sure you want to delete this subscription?', 'invoicing' ); |
|
356 | - $localize['action_edit'] = __( 'Edit', 'invoicing' ); |
|
357 | - $localize['action_cancel'] = __( 'Cancel', 'invoicing' ); |
|
358 | - |
|
359 | - $localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
360 | - |
|
361 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
362 | - |
|
363 | - if ( $page == 'wpinv-subscriptions' ) { |
|
364 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
365 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
344 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
345 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
346 | + $localize['status_pending'] = wpinv_status_nicename('wpi-pending'); |
|
347 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
348 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
349 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
350 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
351 | + $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'); |
|
352 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
353 | + $localize['emptyInvoice'] = __('Add at least one item to save invoice!', 'invoicing'); |
|
354 | + $localize['errDeleteItem'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
355 | + $localize['delete_subscription'] = __('Are you sure you want to delete this subscription?', 'invoicing'); |
|
356 | + $localize['action_edit'] = __('Edit', 'invoicing'); |
|
357 | + $localize['action_cancel'] = __('Cancel', 'invoicing'); |
|
358 | + |
|
359 | + $localize = apply_filters('wpinv_admin_js_localize', $localize); |
|
360 | + |
|
361 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
362 | + |
|
363 | + if ($page == 'wpinv-subscriptions') { |
|
364 | + wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION); |
|
365 | + wp_enqueue_script('wpinv-sub-admin-script'); |
|
366 | 366 | } |
367 | 367 | } |
368 | 368 | |
369 | - public function admin_body_class( $classes ) { |
|
369 | + public function admin_body_class($classes) { |
|
370 | 370 | global $pagenow, $post, $current_screen; |
371 | 371 | |
372 | - if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote' ) ) { |
|
372 | + if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote')) { |
|
373 | 373 | $classes .= ' wpinv-cpt'; |
374 | 374 | } |
375 | 375 | |
376 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
376 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
377 | 377 | |
378 | - $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false; |
|
379 | - if ( $add_class ) { |
|
380 | - $classes .= ' wpi-' . wpinv_sanitize_key( $page ); |
|
378 | + $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false; |
|
379 | + if ($add_class) { |
|
380 | + $classes .= ' wpi-' . wpinv_sanitize_key($page); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | $settings_class = array(); |
384 | - if ( $page == 'wpinv-settings' ) { |
|
385 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
386 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
384 | + if ($page == 'wpinv-settings') { |
|
385 | + if (!empty($_REQUEST['tab'])) { |
|
386 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
387 | 387 | } |
388 | 388 | |
389 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
390 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
389 | + if (!empty($_REQUEST['section'])) { |
|
390 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
391 | 391 | } |
392 | 392 | |
393 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
393 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
394 | 394 | } |
395 | 395 | |
396 | - if ( !empty( $settings_class ) ) { |
|
397 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
396 | + if (!empty($settings_class)) { |
|
397 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | $post_type = wpinv_admin_post_type(); |
401 | 401 | |
402 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
402 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
403 | 403 | return $classes .= ' wpinv'; |
404 | 404 | } |
405 | 405 | |
406 | - if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
406 | + if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
407 | 407 | $classes .= ' wpi-editable-n'; |
408 | 408 | } |
409 | 409 | |
@@ -415,21 +415,21 @@ discard block |
||
415 | 415 | } |
416 | 416 | |
417 | 417 | public function wpinv_actions() { |
418 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
419 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
418 | + if (isset($_REQUEST['wpi_action'])) { |
|
419 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
420 | 420 | } |
421 | 421 | } |
422 | 422 | |
423 | - public function pre_get_posts( $wp_query ) { |
|
424 | - 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() ) { |
|
425 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
423 | + public function pre_get_posts($wp_query) { |
|
424 | + 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()) { |
|
425 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | return $wp_query; |
429 | 429 | } |
430 | 430 | |
431 | 431 | public function bp_invoicing_init() { |
432 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
432 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | /** |
@@ -437,11 +437,11 @@ discard block |
||
437 | 437 | * |
438 | 438 | */ |
439 | 439 | public function register_widgets() { |
440 | - register_widget( "WPInv_Checkout_Widget" ); |
|
441 | - register_widget( "WPInv_History_Widget" ); |
|
442 | - register_widget( "WPInv_Receipt_Widget" ); |
|
443 | - register_widget( "WPInv_Subscriptions_Widget" ); |
|
444 | - register_widget( "WPInv_Buy_Item_Widget" ); |
|
445 | - register_widget( "WPInv_Messages_Widget" ); |
|
440 | + register_widget("WPInv_Checkout_Widget"); |
|
441 | + register_widget("WPInv_History_Widget"); |
|
442 | + register_widget("WPInv_Receipt_Widget"); |
|
443 | + register_widget("WPInv_Subscriptions_Widget"); |
|
444 | + register_widget("WPInv_Buy_Item_Widget"); |
|
445 | + register_widget("WPInv_Messages_Widget"); |
|
446 | 446 | } |
447 | 447 | } |
448 | 448 | \ No newline at end of file |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | return false; |
343 | 343 | } |
344 | 344 | if (null !== $this->apcuPrefix) { |
345 | - $file = apcu_fetch($this->apcuPrefix.$class, $hit); |
|
345 | + $file = apcu_fetch($this->apcuPrefix . $class, $hit); |
|
346 | 346 | if ($hit) { |
347 | 347 | return $file; |
348 | 348 | } |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | } |
357 | 357 | |
358 | 358 | if (null !== $this->apcuPrefix) { |
359 | - apcu_add($this->apcuPrefix.$class, $file); |
|
359 | + apcu_add($this->apcuPrefix . $class, $file); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | if (false === $file) { |
@@ -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-3 control-label"><?php _e( 'Card Owner', 'invoicing' ) ;?></label> |
|
15 | + <label for="auth-input-cc-owner" class="col-sm-3 control-label"><?php _e('Card Owner', 'invoicing'); ?></label> |
|
16 | 16 | <div class="col-sm-5"> |
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-3 control-label"><?php _e( 'Card Number', 'invoicing' ) ;?></label> |
|
21 | + <label for="auth-input-cc-number" class="col-sm-3 control-label"><?php _e('Card Number', 'invoicing'); ?></label> |
|
22 | 22 | <div class="col-sm-5"> |
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-3 control-label"><?php _e( 'Card Expiry Date', 'invoicing' ) ;?></label> |
|
27 | + <label for="auth-input-cc-expire-date" class="col-sm-3 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-3"> |
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-3 control-label"><?php _e( 'Card Security Code (CVV2)', 'invoicing' ) ;?></label> |
|
44 | + <label for="auth-input-cc-cvv2" class="col-sm-3 control-label"><?php _e('Card Security Code (CVV2)', 'invoicing'); ?></label> |
|
45 | 45 | <div class="col-sm-5"> |
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,192 +83,192 @@ 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(); |
110 | 110 | |
111 | 111 | $authorizeAIM = wpinv_authorizenet_AIM(); |
112 | - $authorizeAIM->first_name = wpinv_utf8_substr( $invoice->get_first_name(), 0, 50 ); |
|
113 | - $authorizeAIM->last_name = wpinv_utf8_substr( $invoice->get_last_name(), 0, 50 ); |
|
114 | - $authorizeAIM->company = wpinv_utf8_substr( $invoice->company, 0, 50 ); |
|
115 | - $authorizeAIM->address = wpinv_utf8_substr( wp_strip_all_tags( $invoice->get_address(), true ), 0, 60 ); |
|
116 | - $authorizeAIM->city = wpinv_utf8_substr( $invoice->city, 0, 40 ); |
|
117 | - $authorizeAIM->state = wpinv_utf8_substr( $invoice->state, 0, 40 ); |
|
118 | - $authorizeAIM->zip = wpinv_utf8_substr( $invoice->zip, 0, 40 ); |
|
119 | - $authorizeAIM->country = wpinv_utf8_substr( $invoice->country, 0, 60 ); |
|
120 | - $authorizeAIM->phone = wpinv_utf8_substr( $invoice->phone, 0, 25 ); |
|
121 | - $authorizeAIM->email = wpinv_utf8_substr( $invoice->get_email(), 0, 255 ); |
|
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'] ); |
|
112 | + $authorizeAIM->first_name = wpinv_utf8_substr($invoice->get_first_name(), 0, 50); |
|
113 | + $authorizeAIM->last_name = wpinv_utf8_substr($invoice->get_last_name(), 0, 50); |
|
114 | + $authorizeAIM->company = wpinv_utf8_substr($invoice->company, 0, 50); |
|
115 | + $authorizeAIM->address = wpinv_utf8_substr(wp_strip_all_tags($invoice->get_address(), true), 0, 60); |
|
116 | + $authorizeAIM->city = wpinv_utf8_substr($invoice->city, 0, 40); |
|
117 | + $authorizeAIM->state = wpinv_utf8_substr($invoice->state, 0, 40); |
|
118 | + $authorizeAIM->zip = wpinv_utf8_substr($invoice->zip, 0, 40); |
|
119 | + $authorizeAIM->country = wpinv_utf8_substr($invoice->country, 0, 60); |
|
120 | + $authorizeAIM->phone = wpinv_utf8_substr($invoice->phone, 0, 25); |
|
121 | + $authorizeAIM->email = wpinv_utf8_substr($invoice->get_email(), 0, 255); |
|
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_name = wpinv_utf8_substr( $item['name'], 0, 31 ); |
|
132 | - $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_name = wpinv_utf8_substr($item['name'], 0, 31); |
|
132 | + $item_desc[] = $item_name . ' (' . $quantity . 'x ' . wpinv_price(wpinv_format_amount($item['item_price'])) . ')'; |
|
133 | 133 | |
134 | - $authorizeAIM->addLineItem( $item['id'], $item_name, '', $quantity, $item['item_price'], ( $use_taxes && !empty( $item['tax'] ) && $item['tax'] > 0 ? 'Y' : 'N' ) ); |
|
134 | + $authorizeAIM->addLineItem($item['id'], $item_name, '', $quantity, $item['item_price'], ($use_taxes && !empty($item['tax']) && $item['tax'] > 0 ? 'Y' : 'N')); |
|
135 | 135 | } |
136 | 136 | |
137 | - $item_desc = '#' . $invoice->get_number() . ': ' . implode( ', ', $item_desc ); |
|
137 | + $item_desc = '#' . $invoice->get_number() . ': ' . implode(', ', $item_desc); |
|
138 | 138 | |
139 | - if ( $use_taxes && $invoice->get_tax() > 0 ) { |
|
140 | - $authorizeAIM->tax = $invoice->get_tax(); |
|
139 | + if ($use_taxes && $invoice->get_tax() > 0) { |
|
140 | + $authorizeAIM->tax = $invoice->get_tax(); |
|
141 | 141 | |
142 | - $item_desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) ); |
|
142 | + $item_desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true)); |
|
143 | 143 | } |
144 | 144 | |
145 | - if ( $invoice->get_discount() > 0 ) { |
|
146 | - $item_desc .= ', ' . wp_sprintf( __( 'Discount: %s', 'invoicing' ), $invoice->get_discount( true ) ); |
|
145 | + if ($invoice->get_discount() > 0) { |
|
146 | + $item_desc .= ', ' . wp_sprintf(__('Discount: %s', 'invoicing'), $invoice->get_discount(true)); |
|
147 | 147 | } |
148 | 148 | |
149 | - $item_description = wpinv_utf8_substr( $item_desc, 0, 255 ); |
|
150 | - $item_description = html_entity_decode( $item_desc , ENT_QUOTES, 'UTF-8' ); |
|
149 | + $item_description = wpinv_utf8_substr($item_desc, 0, 255); |
|
150 | + $item_description = html_entity_decode($item_desc, ENT_QUOTES, 'UTF-8'); |
|
151 | 151 | |
152 | - $authorizeAIM->description = wpinv_utf8_substr( $item_description, 0, 255 ); |
|
152 | + $authorizeAIM->description = wpinv_utf8_substr($item_description, 0, 255); |
|
153 | 153 | |
154 | 154 | $is_recurring = $invoice->is_recurring(); // Recurring payment. |
155 | 155 | |
156 | - if ( $is_recurring ) { |
|
156 | + if ($is_recurring) { |
|
157 | 157 | $authorizeAIM->recurring_billing = true; |
158 | 158 | } |
159 | 159 | |
160 | 160 | try { |
161 | 161 | |
162 | - if ( $is_recurring ) { |
|
162 | + if ($is_recurring) { |
|
163 | 163 | $trx_type = wpinv_get_option('authorizenet_transaction_type_recurring', 'authorize_only'); |
164 | - if('authorize_capture' == $trx_type){ |
|
164 | + if ('authorize_capture' == $trx_type) { |
|
165 | 165 | $response = $authorizeAIM->authorizeAndCapture(); |
166 | 166 | } else { |
167 | 167 | $response = $authorizeAIM->authorizeOnly(); |
168 | 168 | } |
169 | 169 | } else { |
170 | 170 | $trx_type = wpinv_get_option('authorizenet_transaction_type', 'authorize_capture'); |
171 | - if('authorize_capture' == $trx_type){ |
|
171 | + if ('authorize_capture' == $trx_type) { |
|
172 | 172 | $response = $authorizeAIM->authorizeAndCapture(); |
173 | 173 | } else { |
174 | 174 | $response = $authorizeAIM->authorizeOnly(); |
175 | 175 | } |
176 | 176 | } |
177 | 177 | |
178 | - if ( $response->approved || $response->held ) { |
|
179 | - if ( $response->approved ) { |
|
180 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
178 | + if ($response->approved || $response->held) { |
|
179 | + if ($response->approved) { |
|
180 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
181 | 181 | } |
182 | - wpinv_set_payment_transaction_id( $invoice_id, $response->transaction_id ); |
|
182 | + wpinv_set_payment_transaction_id($invoice_id, $response->transaction_id); |
|
183 | 183 | |
184 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'Authorize.Net payment response: %s', 'invoicing' ), $response->response_reason_text ), '', '', true ); |
|
185 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'Authorize.Net payment: Transaction ID %s, Transaction Type %s, Authorization Code %s', 'invoicing' ), $response->transaction_id, strtoupper( $response->transaction_type ), $response->authorization_code ), '', '', true ); |
|
184 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('Authorize.Net payment response: %s', 'invoicing'), $response->response_reason_text), '', '', true); |
|
185 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('Authorize.Net payment: Transaction ID %s, Transaction Type %s, Authorization Code %s', 'invoicing'), $response->transaction_id, strtoupper($response->transaction_type), $response->authorization_code), '', '', true); |
|
186 | 186 | |
187 | - do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card ); |
|
187 | + do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card); |
|
188 | 188 | |
189 | 189 | wpinv_clear_errors(); |
190 | 190 | wpinv_empty_cart(); |
191 | 191 | |
192 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
192 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
193 | 193 | } else { |
194 | - if ( !empty( $response->response_reason_text ) ) { |
|
195 | - $error = __( $response->response_reason_text, 'invoicing' ); |
|
196 | - } else if ( !empty( $response->error_message ) ) { |
|
197 | - $error = __( $response->error_message, 'invoicing' ); |
|
194 | + if (!empty($response->response_reason_text)) { |
|
195 | + $error = __($response->response_reason_text, 'invoicing'); |
|
196 | + } else if (!empty($response->error_message)) { |
|
197 | + $error = __($response->error_message, 'invoicing'); |
|
198 | 198 | } else { |
199 | - $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) ); |
|
199 | + $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true)); |
|
200 | 200 | } |
201 | 201 | |
202 | - $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error ); |
|
202 | + $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error); |
|
203 | 203 | |
204 | - wpinv_set_error( 'payment_error', $error ); |
|
205 | - wpinv_record_gateway_error( $error, $response ); |
|
206 | - wpinv_insert_payment_note( $invoice_id, $error, '', '', true ); |
|
204 | + wpinv_set_error('payment_error', $error); |
|
205 | + wpinv_record_gateway_error($error, $response); |
|
206 | + wpinv_insert_payment_note($invoice_id, $error, '', '', true); |
|
207 | 207 | |
208 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
208 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
209 | 209 | } |
210 | - } catch ( AuthorizeNetException $e ) { |
|
211 | - wpinv_set_error( 'request_error', $e->getMessage() ); |
|
212 | - wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) ); |
|
213 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
210 | + } catch (AuthorizeNetException $e) { |
|
211 | + wpinv_set_error('request_error', $e->getMessage()); |
|
212 | + wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage())); |
|
213 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
214 | 214 | } |
215 | 215 | } else { |
216 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
216 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
217 | 217 | } |
218 | 218 | } else { |
219 | - 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 ); |
|
220 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
219 | + 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); |
|
220 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
221 | 221 | } |
222 | 222 | } |
223 | -add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' ); |
|
223 | +add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment'); |
|
224 | 224 | |
225 | -function wpinv_authorizenet_cancel_subscription( $subscription_id = '' ) { |
|
226 | - if ( empty( $subscription_id ) ) { |
|
225 | +function wpinv_authorizenet_cancel_subscription($subscription_id = '') { |
|
226 | + if (empty($subscription_id)) { |
|
227 | 227 | return false; |
228 | 228 | } |
229 | 229 | |
230 | 230 | try { |
231 | 231 | $authnetXML = wpinv_authorizenet_XML(); |
232 | - $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription_id ) ); |
|
232 | + $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription_id)); |
|
233 | 233 | return $authnetXML->isSuccessful(); |
234 | - } catch( Exception $e ) { |
|
235 | - wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) ); |
|
234 | + } catch (Exception $e) { |
|
235 | + wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing')); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | return false; |
239 | 239 | } |
240 | 240 | |
241 | -function wpinv_recurring_cancel_authorizenet_subscription( $subscription, $valid = false ) { |
|
242 | - if ( ! empty( $valid ) && ! empty( $subscription->profile_id ) ) { |
|
243 | - return wpinv_authorizenet_cancel_subscription( $subscription->profile_id ); |
|
241 | +function wpinv_recurring_cancel_authorizenet_subscription($subscription, $valid = false) { |
|
242 | + if (!empty($valid) && !empty($subscription->profile_id)) { |
|
243 | + return wpinv_authorizenet_cancel_subscription($subscription->profile_id); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | return false; |
247 | 247 | } |
248 | -add_action( 'wpinv_recurring_cancel_authorizenet_subscription', 'wpinv_recurring_cancel_authorizenet_subscription', 10, 2 ); |
|
248 | +add_action('wpinv_recurring_cancel_authorizenet_subscription', 'wpinv_recurring_cancel_authorizenet_subscription', 10, 2); |
|
249 | 249 | |
250 | -function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) { |
|
251 | - $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' ); |
|
252 | - if ( empty( $authorizenet_md5_hash ) ) { |
|
250 | +function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) { |
|
251 | + $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash'); |
|
252 | + if (empty($authorizenet_md5_hash)) { |
|
253 | 253 | return true; |
254 | 254 | } |
255 | 255 | |
256 | - $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) ); |
|
256 | + $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount)); |
|
257 | 257 | |
258 | - return hash_equals( $compare_md5, $md5_hash ); |
|
258 | + return hash_equals($compare_md5, $md5_hash); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | function wpinv_authorizenet_AIM() { |
262 | - if ( !class_exists( 'AuthorizeNetException' ) ) { |
|
263 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php'; |
|
262 | + if (!class_exists('AuthorizeNetException')) { |
|
263 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php'; |
|
264 | 264 | } |
265 | 265 | |
266 | - $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) ); |
|
266 | + $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key')); |
|
267 | 267 | |
268 | - if ( wpinv_is_test_mode( 'authorizenet' ) ) { |
|
269 | - $authorizeAIM->setSandbox( true ); |
|
268 | + if (wpinv_is_test_mode('authorizenet')) { |
|
269 | + $authorizeAIM->setSandbox(true); |
|
270 | 270 | } else { |
271 | - $authorizeAIM->setSandbox( false ); |
|
271 | + $authorizeAIM->setSandbox(false); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | $authorizeAIM->customer_ip = wpinv_get_ip(); |
@@ -277,250 +277,250 @@ discard block |
||
277 | 277 | } |
278 | 278 | |
279 | 279 | function wpinv_authorizenet_XML() { |
280 | - if ( !class_exists( 'AuthnetXML' ) ) { |
|
281 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php'; |
|
280 | + if (!class_exists('AuthnetXML')) { |
|
281 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php'; |
|
282 | 282 | } |
283 | 283 | |
284 | - $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) ); |
|
284 | + $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool) wpinv_is_test_mode('authorizenet')); |
|
285 | 285 | |
286 | 286 | return $authnetXML; |
287 | 287 | } |
288 | 288 | |
289 | -function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) { |
|
290 | - if ( empty( $response ) || empty( $invoice ) ) { |
|
289 | +function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) { |
|
290 | + if (empty($response) || empty($invoice)) { |
|
291 | 291 | return false; |
292 | 292 | } |
293 | 293 | |
294 | - if ( $invoice->is_recurring() && !empty( $response->approved ) ) { |
|
295 | - $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info ); |
|
294 | + if ($invoice->is_recurring() && !empty($response->approved)) { |
|
295 | + $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info); |
|
296 | 296 | $success = false; |
297 | - if ( wpinv_is_test_mode( 'authorizenet' ) ) { |
|
297 | + if (wpinv_is_test_mode('authorizenet')) { |
|
298 | 298 | $success = true; |
299 | 299 | } else { |
300 | 300 | $success = $subscription->isSuccessful(); |
301 | 301 | } |
302 | 302 | |
303 | - if ( !empty( $subscription ) && $success ) { |
|
304 | - do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' ); |
|
303 | + if (!empty($subscription) && $success) { |
|
304 | + do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet'); |
|
305 | 305 | |
306 | - wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ); |
|
306 | + wpinv_authorizenet_subscription_record_signup($subscription, $invoice); |
|
307 | 307 | |
308 | - do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' ); |
|
308 | + do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet'); |
|
309 | 309 | } else { |
310 | - if ( isset( $subscription->messages->message ) ) { |
|
310 | + if (isset($subscription->messages->message)) { |
|
311 | 311 | $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text; |
312 | - wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' ); |
|
312 | + wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing'); |
|
313 | 313 | } else { |
314 | - $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' ); |
|
315 | - wpinv_set_error( 'wpinv_authorize_recurring_error', $error ); |
|
314 | + $error = __('Your subscription cannot be created due to an error.', 'invoicing'); |
|
315 | + wpinv_set_error('wpinv_authorize_recurring_error', $error); |
|
316 | 316 | } |
317 | 317 | |
318 | - wpinv_record_gateway_error( $error, $subscription ); |
|
318 | + wpinv_record_gateway_error($error, $subscription); |
|
319 | 319 | |
320 | - wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ), '', '', true ); |
|
320 | + wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error), '', '', true); |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | } |
324 | -add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 ); |
|
324 | +add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3); |
|
325 | 325 | |
326 | -function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) { |
|
327 | - if ( empty( $invoice ) ) { |
|
326 | +function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) { |
|
327 | + if (empty($invoice)) { |
|
328 | 328 | return false; |
329 | 329 | } |
330 | 330 | |
331 | - $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response ); |
|
331 | + $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response); |
|
332 | 332 | |
333 | 333 | try { |
334 | 334 | $authnetXML = wpinv_authorizenet_XML(); |
335 | - $authnetXML->ARBCreateSubscriptionRequest( $params ); |
|
336 | - } catch( Exception $e ) { |
|
335 | + $authnetXML->ARBCreateSubscriptionRequest($params); |
|
336 | + } catch (Exception $e) { |
|
337 | 337 | $authnetXML = array(); |
338 | - wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) ); |
|
338 | + wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing')); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | return $authnetXML; |
342 | 342 | } |
343 | 343 | |
344 | -function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) { |
|
345 | - if ( empty( $invoice ) ) { |
|
344 | +function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) { |
|
345 | + if (empty($invoice)) { |
|
346 | 346 | return false; |
347 | 347 | } |
348 | 348 | |
349 | - $subscription_item = $invoice->get_recurring( true ); |
|
350 | - if ( empty( $subscription_item->ID ) ) { |
|
349 | + $subscription_item = $invoice->get_recurring(true); |
|
350 | + if (empty($subscription_item->ID)) { |
|
351 | 351 | return false; |
352 | 352 | } |
353 | 353 | |
354 | - $item = $invoice->get_recurring( true ); |
|
354 | + $item = $invoice->get_recurring(true); |
|
355 | 355 | |
356 | - if ( empty( $item ) ) { |
|
356 | + if (empty($item)) { |
|
357 | 357 | $name = ''; |
358 | 358 | } |
359 | 359 | |
360 | - if ( !( $name = $item->get_name() ) ) { |
|
360 | + if (!($name = $item->get_name())) { |
|
361 | 361 | $name = $item->post_name; |
362 | 362 | } |
363 | 363 | |
364 | - $card_details = wpinv_authorizenet_generate_card_info( $card_info ); |
|
364 | + $card_details = wpinv_authorizenet_generate_card_info($card_info); |
|
365 | 365 | $subscription_name = $invoice->get_subscription_name(); |
366 | - $initial_amount = wpinv_round_amount( $invoice->get_total() ); |
|
367 | - $recurring_amount = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) ); |
|
366 | + $initial_amount = wpinv_round_amount($invoice->get_total()); |
|
367 | + $recurring_amount = wpinv_round_amount($invoice->get_recurring_details('total')); |
|
368 | 368 | $interval = $subscription_item->get_recurring_interval(); |
369 | 369 | $period = $subscription_item->get_recurring_period(); |
370 | - $bill_times = (int)$subscription_item->get_recurring_limit(); |
|
370 | + $bill_times = (int) $subscription_item->get_recurring_limit(); |
|
371 | 371 | $bill_times = $bill_times > 0 ? $bill_times : 9999; |
372 | 372 | |
373 | - $time_period = wpinv_authorizenet_get_time_period( $interval, $period ); |
|
373 | + $time_period = wpinv_authorizenet_get_time_period($interval, $period); |
|
374 | 374 | $interval = $time_period['interval']; |
375 | 375 | $period = $time_period['period']; |
376 | 376 | |
377 | 377 | $current_tz = date_default_timezone_get(); |
378 | - date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts. |
|
379 | - $today = date( 'Y-m-d' ); |
|
380 | - date_default_timezone_set( $current_tz ); |
|
378 | + date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts. |
|
379 | + $today = date('Y-m-d'); |
|
380 | + date_default_timezone_set($current_tz); |
|
381 | 381 | |
382 | 382 | $free_trial = $invoice->is_free_trial(); |
383 | - if ( $free_trial && $subscription_item->has_free_trial() ) { |
|
383 | + if ($free_trial && $subscription_item->has_free_trial()) { |
|
384 | 384 | $trial_interval = $subscription_item->get_trial_interval(); |
385 | - $trial_period = $subscription_item->get_trial_period( true ); |
|
385 | + $trial_period = $subscription_item->get_trial_period(true); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | $subscription = array(); |
389 | 389 | $subscription['name'] = $subscription_name; |
390 | 390 | |
391 | 391 | $subscription['paymentSchedule'] = array( |
392 | - 'interval' => array( 'length' => $interval, 'unit' => $period ), |
|
392 | + 'interval' => array('length' => $interval, 'unit' => $period), |
|
393 | 393 | 'startDate' => $today, |
394 | 394 | 'totalOccurrences' => $bill_times, |
395 | - 'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0, |
|
395 | + 'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0, |
|
396 | 396 | ); |
397 | 397 | |
398 | 398 | $subscription['amount'] = $recurring_amount; |
399 | 399 | $subscription['trialAmount'] = $initial_amount; |
400 | - $subscription['payment'] = array( 'creditCard' => $card_details ); |
|
401 | - $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() ); |
|
402 | - $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone ); |
|
400 | + $subscription['payment'] = array('creditCard' => $card_details); |
|
401 | + $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number()); |
|
402 | + $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone); |
|
403 | 403 | |
404 | 404 | $subscription['billTo'] = array( |
405 | 405 | 'firstName' => $invoice->get_first_name(), |
406 | 406 | 'lastName' => $invoice->get_last_name(), |
407 | 407 | 'company' => $invoice->company, |
408 | - 'address' => wp_strip_all_tags( $invoice->get_address(), true ), |
|
408 | + 'address' => wp_strip_all_tags($invoice->get_address(), true), |
|
409 | 409 | 'city' => $invoice->city, |
410 | 410 | 'state' => $invoice->state, |
411 | 411 | 'zip' => $invoice->zip, |
412 | 412 | 'country' => $invoice->country, |
413 | 413 | ); |
414 | 414 | |
415 | - $params = array( 'subscription' => $subscription ); |
|
415 | + $params = array('subscription' => $subscription); |
|
416 | 416 | |
417 | - return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response ); |
|
417 | + return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response); |
|
418 | 418 | } |
419 | 419 | |
420 | -function wpinv_authorizenet_generate_card_info( $card_info = array() ) { |
|
421 | - $card_defaults = array( |
|
420 | +function wpinv_authorizenet_generate_card_info($card_info = array()) { |
|
421 | + $card_defaults = array( |
|
422 | 422 | 'cc_owner' => null, |
423 | 423 | 'cc_number' => null, |
424 | 424 | 'cc_expire_month' => null, |
425 | 425 | 'cc_expire_year' => null, |
426 | 426 | 'cc_cvv2' => null, |
427 | 427 | ); |
428 | - $card_info = wp_parse_args( $card_info, $card_defaults ); |
|
428 | + $card_info = wp_parse_args($card_info, $card_defaults); |
|
429 | 429 | |
430 | 430 | $card_details = array( |
431 | - 'cardNumber' => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ), |
|
432 | - 'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ), |
|
433 | - 'cardCode' => sanitize_text_field( $card_info['cc_cvv2'] ), |
|
431 | + 'cardNumber' => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])), |
|
432 | + 'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']), |
|
433 | + 'cardCode' => sanitize_text_field($card_info['cc_cvv2']), |
|
434 | 434 | ); |
435 | 435 | |
436 | 436 | return $card_details; |
437 | 437 | } |
438 | 438 | |
439 | -function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) { |
|
440 | - $parent_invoice_id = absint( $invoice->ID ); |
|
439 | +function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) { |
|
440 | + $parent_invoice_id = absint($invoice->ID); |
|
441 | 441 | |
442 | - if( empty( $parent_invoice_id ) ) { |
|
442 | + if (empty($parent_invoice_id)) { |
|
443 | 443 | return; |
444 | 444 | } |
445 | 445 | |
446 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
447 | - if ( empty( $invoice ) ) { |
|
446 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
447 | + if (empty($invoice)) { |
|
448 | 448 | return; |
449 | 449 | } |
450 | 450 | |
451 | - $subscriptionId = (array)$subscription->subscriptionId; |
|
452 | - $subscription_id = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $parent_invoice_id; |
|
451 | + $subscriptionId = (array) $subscription->subscriptionId; |
|
452 | + $subscription_id = !empty($subscriptionId[0]) ? $subscriptionId[0] : $parent_invoice_id; |
|
453 | 453 | |
454 | - $subscription = wpinv_get_authorizenet_subscription( $subscription, $parent_invoice_id ); |
|
454 | + $subscription = wpinv_get_authorizenet_subscription($subscription, $parent_invoice_id); |
|
455 | 455 | |
456 | - if ( false === $subscription ) { |
|
456 | + if (false === $subscription) { |
|
457 | 457 | return; |
458 | 458 | } |
459 | 459 | |
460 | 460 | // Set payment to complete |
461 | - wpinv_update_payment_status( $subscription->parent_payment_id, 'publish' ); |
|
461 | + wpinv_update_payment_status($subscription->parent_payment_id, 'publish'); |
|
462 | 462 | sleep(1); |
463 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ), '', '', true ); |
|
464 | - update_post_meta($parent_invoice_id,'_wpinv_subscr_profile_id', $subscription_id); |
|
463 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id), '', '', true); |
|
464 | + update_post_meta($parent_invoice_id, '_wpinv_subscr_profile_id', $subscription_id); |
|
465 | 465 | |
466 | 466 | $status = 'trialling' == $subscription->status ? 'trialling' : 'active'; |
467 | - $diff_days = absint( ( ( strtotime( $subscription->expiration ) - strtotime( $subscription->created ) ) / DAY_IN_SECONDS ) ); |
|
468 | - $created = date_i18n( 'Y-m-d H:i:s' ); |
|
469 | - $expiration = date_i18n( 'Y-m-d 23:59:59', ( strtotime( $created ) + ( $diff_days * DAY_IN_SECONDS ) ) ); |
|
467 | + $diff_days = absint(((strtotime($subscription->expiration) - strtotime($subscription->created)) / DAY_IN_SECONDS)); |
|
468 | + $created = date_i18n('Y-m-d H:i:s'); |
|
469 | + $expiration = date_i18n('Y-m-d 23:59:59', (strtotime($created) + ($diff_days * DAY_IN_SECONDS))); |
|
470 | 470 | |
471 | 471 | // Retrieve pending subscription from database and update it's status to active and set proper profile ID |
472 | - $subscription->update( array( 'profile_id' => $subscription_id, 'status' => $status, 'created' => $created, 'expiration' => $expiration ) ); |
|
472 | + $subscription->update(array('profile_id' => $subscription_id, 'status' => $status, 'created' => $created, 'expiration' => $expiration)); |
|
473 | 473 | } |
474 | 474 | |
475 | -function wpinv_authorizenet_validate_checkout( $valid_data, $post ) { |
|
476 | - if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) { |
|
475 | +function wpinv_authorizenet_validate_checkout($valid_data, $post) { |
|
476 | + if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') { |
|
477 | 477 | $error = false; |
478 | 478 | |
479 | - if ( empty( $post['authorizenet']['cc_owner'] ) ) { |
|
479 | + if (empty($post['authorizenet']['cc_owner'])) { |
|
480 | 480 | $error = true; |
481 | - wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing')); |
|
481 | + wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing')); |
|
482 | 482 | } |
483 | - if ( empty( $post['authorizenet']['cc_number'] ) ) { |
|
483 | + if (empty($post['authorizenet']['cc_number'])) { |
|
484 | 484 | $error = true; |
485 | - wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing')); |
|
485 | + wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing')); |
|
486 | 486 | } |
487 | - if ( empty( $post['authorizenet']['cc_expire_month'] ) ) { |
|
487 | + if (empty($post['authorizenet']['cc_expire_month'])) { |
|
488 | 488 | $error = true; |
489 | - wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing')); |
|
489 | + wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing')); |
|
490 | 490 | } |
491 | - if ( empty( $post['authorizenet']['cc_expire_year'] ) ) { |
|
491 | + if (empty($post['authorizenet']['cc_expire_year'])) { |
|
492 | 492 | $error = true; |
493 | - wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing')); |
|
493 | + wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing')); |
|
494 | 494 | } |
495 | - if ( empty( $post['authorizenet']['cc_cvv2'] ) ) { |
|
495 | + if (empty($post['authorizenet']['cc_cvv2'])) { |
|
496 | 496 | $error = true; |
497 | - wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) ); |
|
497 | + wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing')); |
|
498 | 498 | } |
499 | 499 | |
500 | - if ( $error ) { |
|
500 | + if ($error) { |
|
501 | 501 | return; |
502 | 502 | } |
503 | 503 | |
504 | 504 | $invoice = wpinv_get_invoice_cart(); |
505 | 505 | |
506 | - if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) { |
|
507 | - $subscription_item = $invoice->get_recurring( true ); |
|
506 | + if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) { |
|
507 | + $subscription_item = $invoice->get_recurring(true); |
|
508 | 508 | |
509 | 509 | $interval = $subscription_item->get_recurring_interval(); |
510 | 510 | $period = $subscription_item->get_recurring_period(); |
511 | 511 | |
512 | - if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) { |
|
513 | - wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) ); |
|
512 | + if ($period == 'D' && ($interval < 7 || $interval > 365)) { |
|
513 | + wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing')); |
|
514 | 514 | } |
515 | 515 | } |
516 | 516 | } |
517 | 517 | } |
518 | -add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 ); |
|
518 | +add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2); |
|
519 | 519 | |
520 | -function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) { |
|
521 | - $subscription_interval = absint( $subscription_interval ); |
|
520 | +function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) { |
|
521 | + $subscription_interval = absint($subscription_interval); |
|
522 | 522 | |
523 | - switch( $subscription_period ) { |
|
523 | + switch ($subscription_period) { |
|
524 | 524 | case 'W': |
525 | 525 | case 'week': |
526 | 526 | case 'weeks': |
@@ -530,14 +530,14 @@ discard block |
||
530 | 530 | case 'M': |
531 | 531 | case 'month': |
532 | 532 | case 'months': |
533 | - if ( $subscription_interval > 12 ) { |
|
533 | + if ($subscription_interval > 12) { |
|
534 | 534 | $subscription_interval = 12; |
535 | 535 | } |
536 | 536 | |
537 | 537 | $interval = $subscription_interval; |
538 | 538 | $period = 'months'; |
539 | 539 | |
540 | - if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) { |
|
540 | + if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) { |
|
541 | 541 | $interval = $subscription_interval * 30; |
542 | 542 | $period = 'days'; |
543 | 543 | } |
@@ -554,30 +554,30 @@ discard block |
||
554 | 554 | break; |
555 | 555 | } |
556 | 556 | |
557 | - return compact( 'interval', 'period' ); |
|
557 | + return compact('interval', 'period'); |
|
558 | 558 | } |
559 | 559 | |
560 | 560 | function wpinv_authorizenet_process_ipn() { |
561 | - if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) { |
|
561 | + if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) { |
|
562 | 562 | return; |
563 | 563 | } |
564 | 564 | |
565 | - $subscription_id = !empty( $_POST['x_subscription_id'] ) ? intval( $_POST['x_subscription_id'] ) : false; |
|
565 | + $subscription_id = !empty($_POST['x_subscription_id']) ? intval($_POST['x_subscription_id']) : false; |
|
566 | 566 | |
567 | - if ( $subscription_id ) { |
|
568 | - $response_code = intval( $_POST['x_response_code'] ); |
|
569 | - $reason_code = intval( $_POST['x_response_reason_code'] ); |
|
567 | + if ($subscription_id) { |
|
568 | + $response_code = intval($_POST['x_response_code']); |
|
569 | + $reason_code = intval($_POST['x_response_reason_code']); |
|
570 | 570 | |
571 | - $subscription = new WPInv_Subscription( $subscription_id, true ); |
|
571 | + $subscription = new WPInv_Subscription($subscription_id, true); |
|
572 | 572 | |
573 | - if ( !$subscription->id ) { |
|
573 | + if (!$subscription->id) { |
|
574 | 574 | return; |
575 | 575 | } |
576 | 576 | |
577 | - if ( 1 == $response_code ) { |
|
577 | + if (1 == $response_code) { |
|
578 | 578 | // Approved |
579 | - $transaction_id = sanitize_text_field( $_POST['x_trans_id'] ); |
|
580 | - $renewal_amount = sanitize_text_field( $_POST['x_amount'] ); |
|
579 | + $transaction_id = sanitize_text_field($_POST['x_trans_id']); |
|
580 | + $renewal_amount = sanitize_text_field($_POST['x_amount']); |
|
581 | 581 | |
582 | 582 | $args = array( |
583 | 583 | 'amount' => $renewal_amount, |
@@ -585,63 +585,63 @@ discard block |
||
585 | 585 | 'gateway' => 'authorizenet' |
586 | 586 | ); |
587 | 587 | |
588 | - $subscription->add_payment( $args ); |
|
588 | + $subscription->add_payment($args); |
|
589 | 589 | $subscription->renew(); |
590 | 590 | |
591 | - do_action( 'wpinv_recurring_authorizenet_silent_post_payment', $subscription ); |
|
592 | - do_action( 'wpinv_authorizenet_renewal_payment', $subscription ); |
|
593 | - } else if ( 2 == $response_code ) { |
|
591 | + do_action('wpinv_recurring_authorizenet_silent_post_payment', $subscription); |
|
592 | + do_action('wpinv_authorizenet_renewal_payment', $subscription); |
|
593 | + } else if (2 == $response_code) { |
|
594 | 594 | // Declined |
595 | 595 | $subscription->failing(); |
596 | - do_action( 'wpinv_authorizenet_renewal_payment_failed', $subscription ); |
|
597 | - do_action( 'wpinv_authorizenet_renewal_error', $subscription ); |
|
598 | - } else if ( 3 == $response_code || 8 == $reason_code ) { |
|
596 | + do_action('wpinv_authorizenet_renewal_payment_failed', $subscription); |
|
597 | + do_action('wpinv_authorizenet_renewal_error', $subscription); |
|
598 | + } else if (3 == $response_code || 8 == $reason_code) { |
|
599 | 599 | // An expired card |
600 | 600 | $subscription->failing(); |
601 | - do_action( 'wpinv_authorizenet_renewal_payment_failed', $subscription ); |
|
602 | - do_action( 'wpinv_authorizenet_renewal_error', $subscription ); |
|
601 | + do_action('wpinv_authorizenet_renewal_payment_failed', $subscription); |
|
602 | + do_action('wpinv_authorizenet_renewal_error', $subscription); |
|
603 | 603 | } else { |
604 | 604 | // Other Error |
605 | - do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription ); |
|
605 | + do_action('wpinv_authorizenet_renewal_payment_error', $subscription); |
|
606 | 606 | } |
607 | 607 | |
608 | 608 | exit; |
609 | 609 | } |
610 | 610 | } |
611 | -add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' ); |
|
611 | +add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn'); |
|
612 | 612 | |
613 | 613 | /** |
614 | 614 | * Retrieve the subscription |
615 | 615 | */ |
616 | -function wpinv_get_authorizenet_subscription( $subscription_data = array(), $invoice_id ) { |
|
617 | - $parent_invoice_id = absint( $invoice_id ); |
|
616 | +function wpinv_get_authorizenet_subscription($subscription_data = array(), $invoice_id) { |
|
617 | + $parent_invoice_id = absint($invoice_id); |
|
618 | 618 | |
619 | - if ( empty( $subscription_data ) ) { |
|
619 | + if (empty($subscription_data)) { |
|
620 | 620 | return false; |
621 | 621 | } |
622 | 622 | |
623 | - if ( empty( $parent_invoice_id ) ) { |
|
623 | + if (empty($parent_invoice_id)) { |
|
624 | 624 | return false; |
625 | 625 | } |
626 | 626 | |
627 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
628 | - if ( empty( $invoice ) ) { |
|
627 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
628 | + if (empty($invoice)) { |
|
629 | 629 | return false; |
630 | 630 | } |
631 | 631 | |
632 | - $subscriptionId = (array)$subscription_data->subscriptionId; |
|
633 | - $subscription_id = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $parent_invoice_id; |
|
632 | + $subscriptionId = (array) $subscription_data->subscriptionId; |
|
633 | + $subscription_id = !empty($subscriptionId[0]) ? $subscriptionId[0] : $parent_invoice_id; |
|
634 | 634 | |
635 | - $subscription = new WPInv_Subscription( $subscription_id, true ); |
|
635 | + $subscription = new WPInv_Subscription($subscription_id, true); |
|
636 | 636 | |
637 | - if ( ! $subscription || $subscription->id < 1 ) { |
|
637 | + if (!$subscription || $subscription->id < 1) { |
|
638 | 638 | $subs_db = new WPInv_Subscriptions_DB; |
639 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $parent_invoice_id, 'number' => 1 ) ); |
|
640 | - $subscription = reset( $subs ); |
|
639 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $parent_invoice_id, 'number' => 1)); |
|
640 | + $subscription = reset($subs); |
|
641 | 641 | |
642 | - if ( $subscription && $subscription->id > 0 ) { |
|
642 | + if ($subscription && $subscription->id > 0) { |
|
643 | 643 | // Update the profile ID so it is set for future renewals |
644 | - $subscription->update( array( 'profile_id' => sanitize_text_field( $subscription_id ) ) ); |
|
644 | + $subscription->update(array('profile_id' => sanitize_text_field($subscription_id))); |
|
645 | 645 | } else { |
646 | 646 | // No subscription found with a matching payment ID, bail |
647 | 647 | return false; |
@@ -652,67 +652,67 @@ discard block |
||
652 | 652 | } |
653 | 653 | |
654 | 654 | function wpinv_is_authorizenet_valid_for_use() { |
655 | - return in_array( wpinv_get_currency(), apply_filters( 'wpinv_authorizenet_supported_currencies', array( 'AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'JPY', 'NOK', 'NZD', 'PLN', 'SEK', 'USD', 'ZAR' ) ) ); |
|
655 | + return in_array(wpinv_get_currency(), apply_filters('wpinv_authorizenet_supported_currencies', array('AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'JPY', 'NOK', 'NZD', 'PLN', 'SEK', 'USD', 'ZAR'))); |
|
656 | 656 | } |
657 | -function wpinv_check_authorizenet_currency_support( $gateway_list ) { |
|
658 | - if ( isset( $gateway_list['authorizenet'] ) && ! wpinv_is_authorizenet_valid_for_use() ) { |
|
659 | - unset( $gateway_list['authorizenet'] ); |
|
657 | +function wpinv_check_authorizenet_currency_support($gateway_list) { |
|
658 | + if (isset($gateway_list['authorizenet']) && !wpinv_is_authorizenet_valid_for_use()) { |
|
659 | + unset($gateway_list['authorizenet']); |
|
660 | 660 | } |
661 | 661 | return $gateway_list; |
662 | 662 | } |
663 | -add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1 ); |
|
663 | +add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1); |
|
664 | 664 | |
665 | -function wpinv_authorizenet_link_transaction_id( $transaction_id, $invoice_id, $invoice ) { |
|
666 | - if ( $transaction_id == $invoice_id ) { |
|
665 | +function wpinv_authorizenet_link_transaction_id($transaction_id, $invoice_id, $invoice) { |
|
666 | + if ($transaction_id == $invoice_id) { |
|
667 | 667 | $link = $transaction_id; |
668 | 668 | } else { |
669 | - if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) { |
|
669 | + if (!empty($invoice) && !empty($invoice->mode)) { |
|
670 | 670 | $mode = $invoice->mode; |
671 | 671 | } else { |
672 | - $mode = wpinv_is_test_mode( 'authorizenet' ) ? 'test' : 'live'; |
|
672 | + $mode = wpinv_is_test_mode('authorizenet') ? 'test' : 'live'; |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | $url = $mode == 'test' ? 'https://sandbox.authorize.net/' : 'https://authorize.net/'; |
676 | 676 | $url .= 'ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=' . $transaction_id; |
677 | 677 | |
678 | - $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $transaction_id . '</a>'; |
|
678 | + $link = '<a href="' . esc_url($url) . '" target="_blank">' . $transaction_id . '</a>'; |
|
679 | 679 | } |
680 | 680 | |
681 | - return apply_filters( 'wpinv_authorizenet_link_payment_details_transaction_id', $link, $transaction_id, $invoice ); |
|
681 | + return apply_filters('wpinv_authorizenet_link_payment_details_transaction_id', $link, $transaction_id, $invoice); |
|
682 | 682 | } |
683 | -add_filter( 'wpinv_payment_details_transaction_id-authorizenet', 'wpinv_authorizenet_link_transaction_id', 10, 3 ); |
|
683 | +add_filter('wpinv_payment_details_transaction_id-authorizenet', 'wpinv_authorizenet_link_transaction_id', 10, 3); |
|
684 | 684 | |
685 | -function wpinv_authorizenet_transaction_id_link( $transaction_id, $subscription ) { |
|
686 | - if ( ! empty( $transaction_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) { |
|
687 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
685 | +function wpinv_authorizenet_transaction_id_link($transaction_id, $subscription) { |
|
686 | + if (!empty($transaction_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) { |
|
687 | + $invoice = wpinv_get_invoice($invoice_id); |
|
688 | 688 | |
689 | - if ( ! empty( $invoice ) ) { |
|
690 | - return wpinv_authorizenet_link_transaction_id( $transaction_id, $invoice_id, $invoice ); |
|
689 | + if (!empty($invoice)) { |
|
690 | + return wpinv_authorizenet_link_transaction_id($transaction_id, $invoice_id, $invoice); |
|
691 | 691 | } |
692 | 692 | } |
693 | 693 | |
694 | 694 | return $transaction_id; |
695 | 695 | } |
696 | -add_filter( 'wpinv_subscription_transaction_link_authorizenet', 'wpinv_authorizenet_transaction_id_link', 10, 2 ); |
|
696 | +add_filter('wpinv_subscription_transaction_link_authorizenet', 'wpinv_authorizenet_transaction_id_link', 10, 2); |
|
697 | 697 | |
698 | -function wpinv_authorizenet_profile_id_link( $profile_id, $subscription ) { |
|
698 | +function wpinv_authorizenet_profile_id_link($profile_id, $subscription) { |
|
699 | 699 | $link = $profile_id; |
700 | 700 | |
701 | - if ( ! empty( $profile_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) { |
|
702 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
701 | + if (!empty($profile_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) { |
|
702 | + $invoice = wpinv_get_invoice($invoice_id); |
|
703 | 703 | |
704 | - if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) { |
|
704 | + if (!empty($invoice) && !empty($invoice->mode)) { |
|
705 | 705 | $mode = $invoice->mode; |
706 | 706 | } else { |
707 | - $mode = wpinv_is_test_mode( 'authorizenet' ) ? 'test' : 'live'; |
|
707 | + $mode = wpinv_is_test_mode('authorizenet') ? 'test' : 'live'; |
|
708 | 708 | } |
709 | 709 | |
710 | 710 | $url = $mode == 'test' ? 'https://sandbox.authorize.net/' : 'https://authorize.net/'; |
711 | 711 | $url .= 'ui/themes/sandbox/ARB/SubscriptionDetail.aspx?SubscrID=' . $profile_id; |
712 | 712 | |
713 | - $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $profile_id . '</a>'; |
|
713 | + $link = '<a href="' . esc_url($url) . '" target="_blank">' . $profile_id . '</a>'; |
|
714 | 714 | } |
715 | 715 | |
716 | - return apply_filters( 'wpinv_authorizenet_profile_id_link', $link, $profile_id, $subscription ); |
|
716 | + return apply_filters('wpinv_authorizenet_profile_id_link', $link, $profile_id, $subscription); |
|
717 | 717 | } |
718 | -add_filter( 'wpinv_subscription_profile_link_authorizenet', 'wpinv_authorizenet_profile_id_link', 10, 2 ); |
|
719 | 718 | \ No newline at end of file |
719 | +add_filter('wpinv_subscription_profile_link_authorizenet', 'wpinv_authorizenet_profile_id_link', 10, 2); |
|
720 | 720 | \ No newline at end of file |
@@ -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,12 +98,12 @@ 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) { |
106 | - $batch_id = (string)$batch->batchId; |
|
106 | + $batch_id = (string) $batch->batchId; |
|
107 | 107 | $request = new AuthorizeNetTD; |
108 | 108 | $tran_list = $request->getTransactionList($batch_id); |
109 | 109 | $transactions = array_merge($transactions, $tran_list->xpath("transactions/transaction")); |
@@ -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 | } |
@@ -178,11 +178,11 @@ |
||
178 | 178 | */ |
179 | 179 | public function getHiddenFieldString() |
180 | 180 | { |
181 | - $array = (array)$this; |
|
181 | + $array = (array) $this; |
|
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; |
@@ -114,24 +114,24 @@ |
||
114 | 114 | |
115 | 115 | public function __construct() |
116 | 116 | { |
117 | - $this->tax = (object)array(); |
|
117 | + $this->tax = (object) array(); |
|
118 | 118 | $this->tax->amount = ""; |
119 | 119 | $this->tax->name = ""; |
120 | 120 | $this->tax->description = ""; |
121 | 121 | |
122 | - $this->shipping = (object)array(); |
|
122 | + $this->shipping = (object) array(); |
|
123 | 123 | $this->shipping->amount = ""; |
124 | 124 | $this->shipping->name = ""; |
125 | 125 | $this->shipping->description = ""; |
126 | 126 | |
127 | - $this->duty = (object)array(); |
|
127 | + $this->duty = (object) array(); |
|
128 | 128 | $this->duty->amount = ""; |
129 | 129 | $this->duty->name = ""; |
130 | 130 | $this->duty->description = ""; |
131 | 131 | |
132 | 132 | // line items |
133 | 133 | |
134 | - $this->order = (object)array(); |
|
134 | + $this->order = (object) array(); |
|
135 | 135 | $this->order->invoiceNumber = ""; |
136 | 136 | $this->order->description = ""; |
137 | 137 | $this->order->purchaseOrderNumber = ""; |
@@ -309,10 +309,10 @@ discard block |
||
309 | 309 | { |
310 | 310 | $this->_validationMode = $validationMode; |
311 | 311 | $this->_constructXml("validateCustomerPaymentProfileRequest"); |
312 | - $this->_xml->addChild("customerProfileId",$customerProfileId); |
|
313 | - $this->_xml->addChild("customerPaymentProfileId",$customerPaymentProfileId); |
|
314 | - $this->_xml->addChild("customerShippingAddressId",$customerShippingAddressId); |
|
315 | - $this->_xml->addChild("cardCode",$cardCode); |
|
312 | + $this->_xml->addChild("customerProfileId", $customerProfileId); |
|
313 | + $this->_xml->addChild("customerPaymentProfileId", $customerPaymentProfileId); |
|
314 | + $this->_xml->addChild("customerShippingAddressId", $customerShippingAddressId); |
|
315 | + $this->_xml->addChild("cardCode", $cardCode); |
|
316 | 316 | return $this->_sendRequest(); |
317 | 317 | } |
318 | 318 | |
@@ -341,13 +341,13 @@ discard block |
||
341 | 341 | */ |
342 | 342 | protected function _setPostString() |
343 | 343 | { |
344 | - ($this->_validationMode != "none" ? $this->_xml->addChild('validationMode',$this->_validationMode) : ""); |
|
344 | + ($this->_validationMode != "none" ? $this->_xml->addChild('validationMode', $this->_validationMode) : ""); |
|
345 | 345 | $this->_post_string = $this->_xml->asXML(); |
346 | 346 | |
347 | 347 | // Add extraOptions CDATA |
348 | 348 | if ($this->_extraOptions) { |
349 | 349 | $this->_xml->addChild("extraOptions"); |
350 | - $this->_post_string = str_replace("<extraOptions></extraOptions>",'<extraOptions><![CDATA[' . $this->_extraOptions . ']]></extraOptions>', $this->_xml->asXML()); |
|
350 | + $this->_post_string = str_replace("<extraOptions></extraOptions>", '<extraOptions><![CDATA[' . $this->_extraOptions . ']]></extraOptions>', $this->_xml->asXML()); |
|
351 | 351 | $this->_extraOptions = false; |
352 | 352 | } |
353 | 353 | // Blank out our validation mode, so that we don't include it in calls that |
@@ -362,12 +362,12 @@ discard block |
||
362 | 362 | */ |
363 | 363 | private function _constructXml($request_type) |
364 | 364 | { |
365 | - $string = '<?xml version="1.0" encoding="utf-8"?><'.$request_type.' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></'.$request_type.'>'; |
|
365 | + $string = '<?xml version="1.0" encoding="utf-8"?><' . $request_type . ' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></' . $request_type . '>'; |
|
366 | 366 | $this->_xml = @new SimpleXMLElement($string); |
367 | 367 | $merchant = $this->_xml->addChild('merchantAuthentication'); |
368 | - $merchant->addChild('name',$this->_api_login); |
|
369 | - $merchant->addChild('transactionKey',$this->_transaction_key); |
|
370 | - ($this->_refId ? $this->_xml->addChild('refId',$this->_refId) : ""); |
|
368 | + $merchant->addChild('name', $this->_api_login); |
|
369 | + $merchant->addChild('transactionKey', $this->_transaction_key); |
|
370 | + ($this->_refId ? $this->_xml->addChild('refId', $this->_refId) : ""); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | */ |
379 | 379 | private function _addObject($destination, $object) |
380 | 380 | { |
381 | - $array = (array)$object; |
|
381 | + $array = (array) $object; |
|
382 | 382 | foreach ($array as $key => $value) { |
383 | 383 | if ($value && !is_object($value)) { |
384 | 384 | if (is_array($value) && count($value)) { |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | $this->_addObject($items, $item); |
388 | 388 | } |
389 | 389 | } else { |
390 | - $destination->addChild($key,$value); |
|
390 | + $destination->addChild($key, $value); |
|
391 | 391 | } |
392 | 392 | } elseif (is_object($value) && self::_notEmpty($value)) { |
393 | 393 | $dest = $destination->addChild($key); |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | */ |
406 | 406 | private static function _notEmpty($object) |
407 | 407 | { |
408 | - $array = (array)$object; |
|
408 | + $array = (array) $object; |
|
409 | 409 | foreach ($array as $key => $value) { |
410 | 410 | if ($value && !is_object($value)) { |
411 | 411 | return true; |
@@ -441,9 +441,9 @@ discard block |
||
441 | 441 | */ |
442 | 442 | public function getValidationResponses() |
443 | 443 | { |
444 | - $responses = (array)$this->xml->validationDirectResponseList; |
|
444 | + $responses = (array) $this->xml->validationDirectResponseList; |
|
445 | 445 | $return = array(); |
446 | - foreach ((array)$responses["string"] as $response) { |
|
446 | + foreach ((array) $responses["string"] as $response) { |
|
447 | 447 | $return[] = new AuthorizeNetAIM_Response($response, ",", "", array()); |
448 | 448 | } |
449 | 449 | return $return; |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | */ |
463 | 463 | public function getCustomerProfileIds() |
464 | 464 | { |
465 | - $ids = (array)$this->xml->ids; |
|
465 | + $ids = (array) $this->xml->ids; |
|
466 | 466 | return $ids["numericString"]; |
467 | 467 | } |
468 | 468 | |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | */ |
472 | 472 | public function getCustomerPaymentProfileIds() |
473 | 473 | { |
474 | - $ids = (array)$this->xml->customerPaymentProfileIdList; |
|
474 | + $ids = (array) $this->xml->customerPaymentProfileIdList; |
|
475 | 475 | return $ids["numericString"]; |
476 | 476 | } |
477 | 477 | |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | */ |
481 | 481 | public function getCustomerShippingAddressIds() |
482 | 482 | { |
483 | - $ids = (array)$this->xml->customerShippingAddressIdList; |
|
483 | + $ids = (array) $this->xml->customerShippingAddressIdList; |
|
484 | 484 | return $ids["numericString"]; |
485 | 485 | } |
486 | 486 |
@@ -77,19 +77,19 @@ discard block |
||
77 | 77 | * A list of all fields in the AIM API. |
78 | 78 | * Used to warn user if they try to set a field not offered in the API. |
79 | 79 | */ |
80 | - private $_all_aim_fields = array("address","allow_partial_auth","amount", |
|
81 | - "auth_code","authentication_indicator", "bank_aba_code","bank_acct_name", |
|
82 | - "bank_acct_num","bank_acct_type","bank_check_number","bank_name", |
|
83 | - "card_code","card_num","cardholder_authentication_value","city","company", |
|
84 | - "country","cust_id","customer_ip","delim_char","delim_data","description", |
|
85 | - "duplicate_window","duty","echeck_type","email","email_customer", |
|
86 | - "encap_char","exp_date","fax","first_name","footer_email_receipt", |
|
87 | - "freight","header_email_receipt","invoice_num","last_name","line_item", |
|
88 | - "login","method","phone","po_num","recurring_billing","relay_response", |
|
89 | - "ship_to_address","ship_to_city","ship_to_company","ship_to_country", |
|
90 | - "ship_to_first_name","ship_to_last_name","ship_to_state","ship_to_zip", |
|
91 | - "split_tender_id","state","tax","tax_exempt","test_request","tran_key", |
|
92 | - "trans_id","type","version","zip" |
|
80 | + private $_all_aim_fields = array("address", "allow_partial_auth", "amount", |
|
81 | + "auth_code", "authentication_indicator", "bank_aba_code", "bank_acct_name", |
|
82 | + "bank_acct_num", "bank_acct_type", "bank_check_number", "bank_name", |
|
83 | + "card_code", "card_num", "cardholder_authentication_value", "city", "company", |
|
84 | + "country", "cust_id", "customer_ip", "delim_char", "delim_data", "description", |
|
85 | + "duplicate_window", "duty", "echeck_type", "email", "email_customer", |
|
86 | + "encap_char", "exp_date", "fax", "first_name", "footer_email_receipt", |
|
87 | + "freight", "header_email_receipt", "invoice_num", "last_name", "line_item", |
|
88 | + "login", "method", "phone", "po_num", "recurring_billing", "relay_response", |
|
89 | + "ship_to_address", "ship_to_city", "ship_to_company", "ship_to_country", |
|
90 | + "ship_to_first_name", "ship_to_last_name", "ship_to_state", "ship_to_zip", |
|
91 | + "split_tender_id", "state", "tax", "tax_exempt", "test_request", "tran_key", |
|
92 | + "trans_id", "type", "version", "zip" |
|
93 | 93 | ); |
94 | 94 | |
95 | 95 | /** |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | */ |
235 | 235 | public function setFields($fields) |
236 | 236 | { |
237 | - $array = (array)$fields; |
|
237 | + $array = (array) $fields; |
|
238 | 238 | foreach ($array as $key => $value) { |
239 | 239 | $this->setField($key, $value); |
240 | 240 | } |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | */ |
248 | 248 | public function setCustomFields($fields) |
249 | 249 | { |
250 | - $array = (array)$fields; |
|
250 | + $array = (array) $fields; |
|
251 | 251 | foreach ($array as $key => $value) { |
252 | 252 | $this->setCustomField($key, $value); |
253 | 253 | } |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | // Split Array |
404 | 404 | $this->response = $response; |
405 | 405 | if ($encap_char) { |
406 | - $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1)); |
|
406 | + $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
407 | 407 | } else { |
408 | 408 | $this->_response_array = explode($delimiter, $response); |
409 | 409 | } |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | $this->duty = $this->_response_array[33]; |
458 | 458 | $this->freight = $this->_response_array[34]; |
459 | 459 | $this->tax_exempt = $this->_response_array[35]; |
460 | - $this->purchase_order_number= $this->_response_array[36]; |
|
460 | + $this->purchase_order_number = $this->_response_array[36]; |
|
461 | 461 | $this->md5_hash = $this->_response_array[37]; |
462 | 462 | $this->card_code_response = $this->_response_array[38]; |
463 | 463 | $this->cavv_response = $this->_response_array[39]; |
@@ -484,10 +484,10 @@ discard block |
||
484 | 484 | |
485 | 485 | if ($this->error) { |
486 | 486 | $this->error_message = "AuthorizeNet Error: |
487 | - Response Code: ".$this->response_code." |
|
488 | - Response Subcode: ".$this->response_subcode." |
|
489 | - Response Reason Code: ".$this->response_reason_code." |
|
490 | - Response Reason Text: ".$this->response_reason_text." |
|
487 | + Response Code: ".$this->response_code . " |
|
488 | + Response Subcode: ".$this->response_subcode . " |
|
489 | + Response Reason Code: ".$this->response_reason_code . " |
|
490 | + Response Reason Text: ".$this->response_reason_text . " |
|
491 | 491 | "; |
492 | 492 | } |
493 | 493 | } else { |
@@ -116,27 +116,27 @@ discard block |
||
116 | 116 | |
117 | 117 | $this->xml = @simplexml_load_string($response); |
118 | 118 | // Set all fields |
119 | - $this->version = array_pop(array_slice(explode('"', $response), 1,1)); |
|
120 | - $this->response_code = (string)$this->xml->ResponseCode; |
|
119 | + $this->version = array_pop(array_slice(explode('"', $response), 1, 1)); |
|
120 | + $this->response_code = (string) $this->xml->ResponseCode; |
|
121 | 121 | |
122 | 122 | if ($this->response_code == 1) { |
123 | - $this->response_reason_code = (string)$this->xml->Messages->Message->Code; |
|
124 | - $this->response_reason_text = (string)$this->xml->Messages->Message->Description; |
|
123 | + $this->response_reason_code = (string) $this->xml->Messages->Message->Code; |
|
124 | + $this->response_reason_text = (string) $this->xml->Messages->Message->Description; |
|
125 | 125 | } else { |
126 | - $this->response_reason_code = (string)$this->xml->Errors->Error->ErrorCode; |
|
127 | - $this->response_reason_text = (string)$this->xml->Errors->Error->ErrorText; |
|
126 | + $this->response_reason_code = (string) $this->xml->Errors->Error->ErrorCode; |
|
127 | + $this->response_reason_text = (string) $this->xml->Errors->Error->ErrorText; |
|
128 | 128 | } |
129 | 129 | |
130 | - $this->authorization_code = (string)$this->xml->AuthCode; |
|
131 | - $this->avs_code = (string)$this->xml->AVSResultCode; |
|
132 | - $this->card_code_response = (string)$this->xml->CVVResultCode; |
|
133 | - $this->transaction_id = (string)$this->xml->TransID; |
|
134 | - $this->md5_hash = (string)$this->xml->TransHash; |
|
135 | - $this->user_ref = (string)$this->xml->UserRef; |
|
136 | - $this->card_num = (string)$this->xml->AccountNumber; |
|
137 | - $this->card_type = (string)$this->xml->AccountType; |
|
138 | - $this->test_mode = (string)$this->xml->TestMode; |
|
139 | - $this->ref_trans_id = (string)$this->xml->RefTransID; |
|
130 | + $this->authorization_code = (string) $this->xml->AuthCode; |
|
131 | + $this->avs_code = (string) $this->xml->AVSResultCode; |
|
132 | + $this->card_code_response = (string) $this->xml->CVVResultCode; |
|
133 | + $this->transaction_id = (string) $this->xml->TransID; |
|
134 | + $this->md5_hash = (string) $this->xml->TransHash; |
|
135 | + $this->user_ref = (string) $this->xml->UserRef; |
|
136 | + $this->card_num = (string) $this->xml->AccountNumber; |
|
137 | + $this->card_type = (string) $this->xml->AccountType; |
|
138 | + $this->test_mode = (string) $this->xml->TestMode; |
|
139 | + $this->ref_trans_id = (string) $this->xml->RefTransID; |
|
140 | 140 | |
141 | 141 | |
142 | 142 | } else { // If it's an NVP response |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | // Split Array |
145 | 145 | $this->response = $response; |
146 | 146 | if ($encap_char) { |
147 | - $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1)); |
|
147 | + $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
148 | 148 | } else { |
149 | 149 | $this->_response_array = explode($delimiter, $response); |
150 | 150 | } |
@@ -190,9 +190,9 @@ discard block |
||
190 | 190 | |
191 | 191 | if ($this->error) { |
192 | 192 | $this->error_message = "AuthorizeNet Error: |
193 | - Response Code: ".$this->response_code." |
|
194 | - Response Reason Code: ".$this->response_reason_code." |
|
195 | - Response Reason Text: ".$this->response_reason_text." |
|
193 | + Response Code: ".$this->response_code . " |
|
194 | + Response Reason Code: ".$this->response_reason_code . " |
|
195 | + Response Reason Text: ".$this->response_reason_text . " |
|
196 | 196 | "; |
197 | 197 | } |
198 | 198 |