@@ -27,21 +27,21 @@ discard block |
||
27 | 27 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
28 | 28 | */ |
29 | 29 | |
30 | -if ( ! defined( 'ABSPATH' ) ) { |
|
30 | +if ( ! defined('ABSPATH')) { |
|
31 | 31 | exit; |
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
35 | 35 | * Required minimums and constants |
36 | 36 | */ |
37 | -define( 'WC_STRIPE_VERSION', '3.2.2' ); |
|
38 | -define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' ); |
|
39 | -define( 'WC_STRIPE_MIN_WC_VER', '2.5.0' ); |
|
40 | -define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
41 | -define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
42 | -define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
|
37 | +define('WC_STRIPE_VERSION', '3.2.2'); |
|
38 | +define('WC_STRIPE_MIN_PHP_VER', '5.6.0'); |
|
39 | +define('WC_STRIPE_MIN_WC_VER', '2.5.0'); |
|
40 | +define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
41 | +define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
42 | +define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); |
|
43 | 43 | |
44 | -if ( ! class_exists( 'WC_Stripe' ) ) : |
|
44 | +if ( ! class_exists('WC_Stripe')) : |
|
45 | 45 | |
46 | 46 | class WC_Stripe { |
47 | 47 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @return Singleton The *Singleton* instance. |
62 | 62 | */ |
63 | 63 | public static function get_instance() { |
64 | - if ( null === self::$instance ) { |
|
64 | + if (null === self::$instance) { |
|
65 | 65 | self::$instance = new self(); |
66 | 66 | } |
67 | 67 | return self::$instance; |
@@ -110,9 +110,9 @@ discard block |
||
110 | 110 | * *Singleton* via the `new` operator from outside of this class. |
111 | 111 | */ |
112 | 112 | protected function __construct() { |
113 | - add_action( 'admin_init', array( $this, 'check_environment' ) ); |
|
114 | - add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 ); |
|
115 | - add_action( 'plugins_loaded', array( $this, 'init' ) ); |
|
113 | + add_action('admin_init', array($this, 'check_environment')); |
|
114 | + add_action('admin_notices', array($this, 'admin_notices'), 15); |
|
115 | + add_action('plugins_loaded', array($this, 'init')); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -120,35 +120,35 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function init() { |
122 | 122 | // Don't hook anything else in the plugin if we're in an incompatible environment |
123 | - if ( self::get_environment_warning() ) { |
|
123 | + if (self::get_environment_warning()) { |
|
124 | 124 | return; |
125 | 125 | } |
126 | 126 | |
127 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
128 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' ); |
|
127 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
128 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'); |
|
129 | 129 | |
130 | 130 | // Init the gateway itself |
131 | 131 | $this->init_gateways(); |
132 | 132 | |
133 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
134 | - add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) ); |
|
135 | - add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) ); |
|
136 | - add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) ); |
|
137 | - add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) ); |
|
138 | - add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 ); |
|
139 | - add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 ); |
|
140 | - add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) ); |
|
141 | - add_action( 'wp_ajax_stripe_dismiss_request_api_notice', array( $this, 'dismiss_request_api_notice' ) ); |
|
142 | - add_action( 'wp_ajax_stripe_dismiss_apple_pay_notice', array( $this, 'dismiss_apple_pay_notice' ) ); |
|
143 | - |
|
144 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-request.php' ); |
|
133 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
134 | + add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment')); |
|
135 | + add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment')); |
|
136 | + add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment')); |
|
137 | + add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment')); |
|
138 | + add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3); |
|
139 | + add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2); |
|
140 | + add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default')); |
|
141 | + add_action('wp_ajax_stripe_dismiss_request_api_notice', array($this, 'dismiss_request_api_notice')); |
|
142 | + add_action('wp_ajax_stripe_dismiss_apple_pay_notice', array($this, 'dismiss_apple_pay_notice')); |
|
143 | + |
|
144 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-request.php'); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
148 | 148 | * Allow this class and other classes to add slug keyed notices (to avoid duplication) |
149 | 149 | */ |
150 | - public function add_admin_notice( $slug, $class, $message ) { |
|
151 | - $this->notices[ $slug ] = array( |
|
150 | + public function add_admin_notice($slug, $class, $message) { |
|
151 | + $this->notices[$slug] = array( |
|
152 | 152 | 'class' => $class, |
153 | 153 | 'message' => $message, |
154 | 154 | ); |
@@ -159,29 +159,29 @@ discard block |
||
159 | 159 | * or the environment changes after activation. Also handles upgrade routines. |
160 | 160 | */ |
161 | 161 | public function check_environment() { |
162 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
|
162 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) { |
|
163 | 163 | $this->install(); |
164 | 164 | |
165 | - do_action( 'woocommerce_stripe_updated' ); |
|
165 | + do_action('woocommerce_stripe_updated'); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | $environment_warning = self::get_environment_warning(); |
169 | 169 | |
170 | - if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
171 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
170 | + if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) { |
|
171 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | // Check if secret key present. Otherwise prompt, via notice, to go to |
175 | 175 | // setting. |
176 | - if ( ! class_exists( 'WC_Stripe_API' ) ) { |
|
177 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
176 | + if ( ! class_exists('WC_Stripe_API')) { |
|
177 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | $secret = WC_Stripe_API::get_secret_key(); |
181 | 181 | |
182 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
182 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
183 | 183 | $setting_link = $this->get_setting_link(); |
184 | - $this->add_admin_notice( 'prompt_connect', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ) ); |
|
184 | + $this->add_admin_notice('prompt_connect', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link)); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
@@ -193,8 +193,8 @@ discard block |
||
193 | 193 | * @return bool |
194 | 194 | */ |
195 | 195 | private static function _update_plugin_version() { |
196 | - delete_option( 'wc_stripe_version' ); |
|
197 | - update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
196 | + delete_option('wc_stripe_version'); |
|
197 | + update_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
198 | 198 | |
199 | 199 | return true; |
200 | 200 | } |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | * @version 3.1.0 |
207 | 207 | */ |
208 | 208 | public function dismiss_request_api_notice() { |
209 | - update_option( 'wc_stripe_show_request_api_notice', 'no' ); |
|
209 | + update_option('wc_stripe_show_request_api_notice', 'no'); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * @version 3.1.0 |
217 | 217 | */ |
218 | 218 | public function dismiss_apple_pay_notice() { |
219 | - update_option( 'wc_stripe_show_apple_pay_notice', 'no' ); |
|
219 | + update_option('wc_stripe_show_apple_pay_notice', 'no'); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -226,8 +226,8 @@ discard block |
||
226 | 226 | * @version 3.1.0 |
227 | 227 | */ |
228 | 228 | public function install() { |
229 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
230 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
229 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
230 | + define('WC_STRIPE_INSTALLING', true); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | $this->_update_plugin_version(); |
@@ -238,24 +238,24 @@ discard block |
||
238 | 238 | * found or false if the environment has no problems. |
239 | 239 | */ |
240 | 240 | static function get_environment_warning() { |
241 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
242 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
241 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
242 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
243 | 243 | |
244 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
244 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
245 | 245 | } |
246 | 246 | |
247 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
248 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
247 | + if ( ! defined('WC_VERSION')) { |
|
248 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
249 | 249 | } |
250 | 250 | |
251 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
252 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
251 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
252 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
253 | 253 | |
254 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
254 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
255 | 255 | } |
256 | 256 | |
257 | - if ( ! function_exists( 'curl_init' ) ) { |
|
258 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
257 | + if ( ! function_exists('curl_init')) { |
|
258 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | return false; |
@@ -266,15 +266,15 @@ discard block |
||
266 | 266 | * |
267 | 267 | * @since 1.0.0 |
268 | 268 | */ |
269 | - public function plugin_action_links( $links ) { |
|
269 | + public function plugin_action_links($links) { |
|
270 | 270 | $setting_link = $this->get_setting_link(); |
271 | 271 | |
272 | 272 | $plugin_links = array( |
273 | - '<a href="' . $setting_link . '">' . __( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
274 | - '<a href="https://docs.woocommerce.com/document/stripe/">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
275 | - '<a href="https://woocommerce.com/contact-us/">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
273 | + '<a href="' . $setting_link . '">' . __('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
274 | + '<a href="https://docs.woocommerce.com/document/stripe/">' . __('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
275 | + '<a href="https://woocommerce.com/contact-us/">' . __('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
276 | 276 | ); |
277 | - return array_merge( $plugin_links, $links ); |
|
277 | + return array_merge($plugin_links, $links); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -285,24 +285,24 @@ discard block |
||
285 | 285 | * @return string Setting link |
286 | 286 | */ |
287 | 287 | public function get_setting_link() { |
288 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
288 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
289 | 289 | |
290 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
290 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
291 | 291 | |
292 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
292 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | /** |
296 | 296 | * Display any notices we've collected thus far (e.g. for connection, disconnection) |
297 | 297 | */ |
298 | 298 | public function admin_notices() { |
299 | - $show_request_api_notice = get_option( 'wc_stripe_show_request_api_notice' ); |
|
300 | - $show_apple_pay_notice = get_option( 'wc_stripe_show_apple_pay_notice' ); |
|
299 | + $show_request_api_notice = get_option('wc_stripe_show_request_api_notice'); |
|
300 | + $show_apple_pay_notice = get_option('wc_stripe_show_apple_pay_notice'); |
|
301 | 301 | |
302 | - if ( empty( $show_apple_pay_notice ) ) { |
|
302 | + if (empty($show_apple_pay_notice)) { |
|
303 | 303 | // @TODO remove this notice in the future. |
304 | 304 | ?> |
305 | - <div class="notice notice-warning wc-stripe-apple-pay-notice is-dismissible"><p><?php echo sprintf( esc_html__( 'New Feature! Stripe now supports %s. Your customers can now purchase your products even faster. Apple Pay has been enabled by default.', 'woocommerce-gateway-stripe' ), '<a href="https://woocommerce.com/apple-pay/">Apple Pay</a>'); ?></p></div> |
|
305 | + <div class="notice notice-warning wc-stripe-apple-pay-notice is-dismissible"><p><?php echo sprintf(esc_html__('New Feature! Stripe now supports %s. Your customers can now purchase your products even faster. Apple Pay has been enabled by default.', 'woocommerce-gateway-stripe'), '<a href="https://woocommerce.com/apple-pay/">Apple Pay</a>'); ?></p></div> |
|
306 | 306 | |
307 | 307 | <script type="application/javascript"> |
308 | 308 | jQuery( '.wc-stripe-apple-pay-notice' ).on( 'click', '.notice-dismiss', function() { |
@@ -310,17 +310,17 @@ discard block |
||
310 | 310 | action: 'stripe_dismiss_apple_pay_notice' |
311 | 311 | }; |
312 | 312 | |
313 | - jQuery.post( '<?php echo admin_url( 'admin-ajax.php' ); ?>', data ); |
|
313 | + jQuery.post( '<?php echo admin_url('admin-ajax.php'); ?>', data ); |
|
314 | 314 | }); |
315 | 315 | </script> |
316 | 316 | |
317 | 317 | <?php |
318 | 318 | } |
319 | 319 | |
320 | - if ( empty( $show_request_api_notice ) ) { |
|
320 | + if (empty($show_request_api_notice)) { |
|
321 | 321 | // @TODO remove this notice in the future. |
322 | 322 | ?> |
323 | - <div class="notice notice-warning wc-stripe-request-api-notice is-dismissible"><p><?php esc_html_e( 'New Feature! Stripe now supports Google Payment Request. Your customers can now use mobile phones with supported browsers such as Chrome to make purchases easier and faster.', 'woocommerce-gateway-stripe' ); ?></p></div> |
|
323 | + <div class="notice notice-warning wc-stripe-request-api-notice is-dismissible"><p><?php esc_html_e('New Feature! Stripe now supports Google Payment Request. Your customers can now use mobile phones with supported browsers such as Chrome to make purchases easier and faster.', 'woocommerce-gateway-stripe'); ?></p></div> |
|
324 | 324 | |
325 | 325 | <script type="application/javascript"> |
326 | 326 | jQuery( '.wc-stripe-request-api-notice' ).on( 'click', '.notice-dismiss', function() { |
@@ -328,16 +328,16 @@ discard block |
||
328 | 328 | action: 'stripe_dismiss_request_api_notice' |
329 | 329 | }; |
330 | 330 | |
331 | - jQuery.post( '<?php echo admin_url( 'admin-ajax.php' ); ?>', data ); |
|
331 | + jQuery.post( '<?php echo admin_url('admin-ajax.php'); ?>', data ); |
|
332 | 332 | }); |
333 | 333 | </script> |
334 | 334 | |
335 | 335 | <?php |
336 | 336 | } |
337 | 337 | |
338 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
339 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
340 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
338 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
339 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
340 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
341 | 341 | echo '</p></div>'; |
342 | 342 | } |
343 | 343 | } |
@@ -348,28 +348,28 @@ discard block |
||
348 | 348 | * @since 1.0.0 |
349 | 349 | */ |
350 | 350 | public function init_gateways() { |
351 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) { |
|
351 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) { |
|
352 | 352 | $this->subscription_support_enabled = true; |
353 | 353 | } |
354 | 354 | |
355 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
355 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
356 | 356 | $this->pre_order_enabled = true; |
357 | 357 | } |
358 | 358 | |
359 | - if ( ! class_exists( 'WC_Payment_Gateway' ) ) { |
|
359 | + if ( ! class_exists('WC_Payment_Gateway')) { |
|
360 | 360 | return; |
361 | 361 | } |
362 | 362 | |
363 | - if ( class_exists( 'WC_Payment_Gateway_CC' ) ) { |
|
364 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' ); |
|
365 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay.php' ); |
|
363 | + if (class_exists('WC_Payment_Gateway_CC')) { |
|
364 | + include_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'); |
|
365 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay.php'); |
|
366 | 366 | } else { |
367 | - include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe.php' ); |
|
368 | - include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php' ); |
|
367 | + include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe.php'); |
|
368 | + include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php'); |
|
369 | 369 | } |
370 | 370 | |
371 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
372 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
371 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
372 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
373 | 373 | |
374 | 374 | $load_addons = ( |
375 | 375 | $this->subscription_support_enabled |
@@ -377,8 +377,8 @@ discard block |
||
377 | 377 | $this->pre_order_enabled |
378 | 378 | ); |
379 | 379 | |
380 | - if ( $load_addons ) { |
|
381 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe-addons.php' ); |
|
380 | + if ($load_addons) { |
|
381 | + require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe-addons.php'); |
|
382 | 382 | } |
383 | 383 | } |
384 | 384 | |
@@ -387,8 +387,8 @@ discard block |
||
387 | 387 | * |
388 | 388 | * @since 1.0.0 |
389 | 389 | */ |
390 | - public function add_gateways( $methods ) { |
|
391 | - if ( $this->subscription_support_enabled || $this->pre_order_enabled ) { |
|
390 | + public function add_gateways($methods) { |
|
391 | + if ($this->subscription_support_enabled || $this->pre_order_enabled) { |
|
392 | 392 | $methods[] = 'WC_Gateway_Stripe_Addons'; |
393 | 393 | } else { |
394 | 394 | $methods[] = 'WC_Gateway_Stripe'; |
@@ -428,24 +428,24 @@ discard block |
||
428 | 428 | * @param object $balance_transaction |
429 | 429 | * @param string $type Type of number to format |
430 | 430 | */ |
431 | - public static function format_number( $balance_transaction, $type = 'fee' ) { |
|
432 | - if ( ! is_object( $balance_transaction ) ) { |
|
431 | + public static function format_number($balance_transaction, $type = 'fee') { |
|
432 | + if ( ! is_object($balance_transaction)) { |
|
433 | 433 | return; |
434 | 434 | } |
435 | 435 | |
436 | - if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) { |
|
437 | - if ( 'fee' === $type ) { |
|
436 | + if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) { |
|
437 | + if ('fee' === $type) { |
|
438 | 438 | return $balance_transaction->fee; |
439 | 439 | } |
440 | 440 | |
441 | 441 | return $balance_transaction->net; |
442 | 442 | } |
443 | 443 | |
444 | - if ( 'fee' === $type ) { |
|
445 | - return number_format( $balance_transaction->fee / 100, 2, '.', '' ); |
|
444 | + if ('fee' === $type) { |
|
445 | + return number_format($balance_transaction->fee / 100, 2, '.', ''); |
|
446 | 446 | } |
447 | 447 | |
448 | - return number_format( $balance_transaction->net / 100, 2, '.', '' ); |
|
448 | + return number_format($balance_transaction->net / 100, 2, '.', ''); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | /** |
@@ -453,36 +453,36 @@ discard block |
||
453 | 453 | * |
454 | 454 | * @param int $order_id |
455 | 455 | */ |
456 | - public function capture_payment( $order_id ) { |
|
457 | - $order = wc_get_order( $order_id ); |
|
456 | + public function capture_payment($order_id) { |
|
457 | + $order = wc_get_order($order_id); |
|
458 | 458 | |
459 | - if ( 'stripe' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->payment_method : $order->get_payment_method() ) ) { |
|
460 | - $charge = get_post_meta( $order_id, '_stripe_charge_id', true ); |
|
461 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
459 | + if ('stripe' === (version_compare(WC_VERSION, '3.0.0', '<') ? $order->payment_method : $order->get_payment_method())) { |
|
460 | + $charge = get_post_meta($order_id, '_stripe_charge_id', true); |
|
461 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
462 | 462 | |
463 | - if ( $charge && 'no' === $captured ) { |
|
464 | - $result = WC_Stripe_API::request( array( |
|
463 | + if ($charge && 'no' === $captured) { |
|
464 | + $result = WC_Stripe_API::request(array( |
|
465 | 465 | 'amount' => $order->get_total() * 100, |
466 | 466 | 'expand[]' => 'balance_transaction', |
467 | - ), 'charges/' . $charge . '/capture' ); |
|
467 | + ), 'charges/' . $charge . '/capture'); |
|
468 | 468 | |
469 | - if ( is_wp_error( $result ) ) { |
|
470 | - $order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() ); |
|
469 | + if (is_wp_error($result)) { |
|
470 | + $order->add_order_note(__('Unable to capture charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message()); |
|
471 | 471 | } else { |
472 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
473 | - update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ); |
|
472 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
473 | + update_post_meta($order_id, '_stripe_charge_captured', 'yes'); |
|
474 | 474 | |
475 | 475 | // Store other data such as fees |
476 | - update_post_meta( $order_id, 'Stripe Payment ID', $result->id ); |
|
477 | - update_post_meta( $order_id, '_transaction_id', $result->id ); |
|
476 | + update_post_meta($order_id, 'Stripe Payment ID', $result->id); |
|
477 | + update_post_meta($order_id, '_transaction_id', $result->id); |
|
478 | 478 | |
479 | - if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) { |
|
479 | + if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) { |
|
480 | 480 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
481 | 481 | // values are in the local currency of the Stripe account, not from WC. |
482 | - $fee = ! empty( $result->balance_transaction->fee ) ? self::format_number( $result->balance_transaction, 'fee' ) : 0; |
|
483 | - $net = ! empty( $result->balance_transaction->net ) ? self::format_number( $result->balance_transaction, 'net' ) : 0; |
|
484 | - update_post_meta( $order_id, 'Stripe Fee', $fee ); |
|
485 | - update_post_meta( $order_id, 'Net Revenue From Stripe', $net ); |
|
482 | + $fee = ! empty($result->balance_transaction->fee) ? self::format_number($result->balance_transaction, 'fee') : 0; |
|
483 | + $net = ! empty($result->balance_transaction->net) ? self::format_number($result->balance_transaction, 'net') : 0; |
|
484 | + update_post_meta($order_id, 'Stripe Fee', $fee); |
|
485 | + update_post_meta($order_id, 'Net Revenue From Stripe', $net); |
|
486 | 486 | } |
487 | 487 | } |
488 | 488 | } |
@@ -494,23 +494,23 @@ discard block |
||
494 | 494 | * |
495 | 495 | * @param int $order_id |
496 | 496 | */ |
497 | - public function cancel_payment( $order_id ) { |
|
498 | - $order = wc_get_order( $order_id ); |
|
497 | + public function cancel_payment($order_id) { |
|
498 | + $order = wc_get_order($order_id); |
|
499 | 499 | |
500 | - if ( 'stripe' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->payment_method : $order->get_payment_method() ) ) { |
|
501 | - $charge = get_post_meta( $order_id, '_stripe_charge_id', true ); |
|
500 | + if ('stripe' === (version_compare(WC_VERSION, '3.0.0', '<') ? $order->payment_method : $order->get_payment_method())) { |
|
501 | + $charge = get_post_meta($order_id, '_stripe_charge_id', true); |
|
502 | 502 | |
503 | - if ( $charge ) { |
|
504 | - $result = WC_Stripe_API::request( array( |
|
503 | + if ($charge) { |
|
504 | + $result = WC_Stripe_API::request(array( |
|
505 | 505 | 'amount' => $order->get_total() * 100, |
506 | - ), 'charges/' . $charge . '/refund' ); |
|
506 | + ), 'charges/' . $charge . '/refund'); |
|
507 | 507 | |
508 | - if ( is_wp_error( $result ) ) { |
|
509 | - $order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() ); |
|
508 | + if (is_wp_error($result)) { |
|
509 | + $order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message()); |
|
510 | 510 | } else { |
511 | - $order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
512 | - delete_post_meta( $order_id, '_stripe_charge_captured' ); |
|
513 | - delete_post_meta( $order_id, '_stripe_charge_id' ); |
|
511 | + $order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
512 | + delete_post_meta($order_id, '_stripe_charge_captured'); |
|
513 | + delete_post_meta($order_id, '_stripe_charge_id'); |
|
514 | 514 | } |
515 | 515 | } |
516 | 516 | } |
@@ -521,28 +521,28 @@ discard block |
||
521 | 521 | * @param array $tokens |
522 | 522 | * @return array |
523 | 523 | */ |
524 | - public function woocommerce_get_customer_payment_tokens( $tokens, $customer_id, $gateway_id ) { |
|
525 | - if ( is_user_logged_in() && 'stripe' === $gateway_id && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
526 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
524 | + public function woocommerce_get_customer_payment_tokens($tokens, $customer_id, $gateway_id) { |
|
525 | + if (is_user_logged_in() && 'stripe' === $gateway_id && class_exists('WC_Payment_Token_CC')) { |
|
526 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
527 | 527 | $stripe_cards = $stripe_customer->get_cards(); |
528 | 528 | $stored_tokens = array(); |
529 | 529 | |
530 | - foreach ( $tokens as $token ) { |
|
530 | + foreach ($tokens as $token) { |
|
531 | 531 | $stored_tokens[] = $token->get_token(); |
532 | 532 | } |
533 | 533 | |
534 | - foreach ( $stripe_cards as $card ) { |
|
535 | - if ( ! in_array( $card->id, $stored_tokens ) ) { |
|
534 | + foreach ($stripe_cards as $card) { |
|
535 | + if ( ! in_array($card->id, $stored_tokens)) { |
|
536 | 536 | $token = new WC_Payment_Token_CC(); |
537 | - $token->set_token( $card->id ); |
|
538 | - $token->set_gateway_id( 'stripe' ); |
|
539 | - $token->set_card_type( strtolower( $card->brand ) ); |
|
540 | - $token->set_last4( $card->last4 ); |
|
541 | - $token->set_expiry_month( $card->exp_month ); |
|
542 | - $token->set_expiry_year( $card->exp_year ); |
|
543 | - $token->set_user_id( $customer_id ); |
|
537 | + $token->set_token($card->id); |
|
538 | + $token->set_gateway_id('stripe'); |
|
539 | + $token->set_card_type(strtolower($card->brand)); |
|
540 | + $token->set_last4($card->last4); |
|
541 | + $token->set_expiry_month($card->exp_month); |
|
542 | + $token->set_expiry_year($card->exp_year); |
|
543 | + $token->set_user_id($customer_id); |
|
544 | 544 | $token->save(); |
545 | - $tokens[ $token->get_id() ] = $token; |
|
545 | + $tokens[$token->get_id()] = $token; |
|
546 | 546 | } |
547 | 547 | } |
548 | 548 | } |
@@ -552,21 +552,21 @@ discard block |
||
552 | 552 | /** |
553 | 553 | * Delete token from Stripe |
554 | 554 | */ |
555 | - public function woocommerce_payment_token_deleted( $token_id, $token ) { |
|
556 | - if ( 'stripe' === $token->get_gateway_id() ) { |
|
557 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
558 | - $stripe_customer->delete_card( $token->get_token() ); |
|
555 | + public function woocommerce_payment_token_deleted($token_id, $token) { |
|
556 | + if ('stripe' === $token->get_gateway_id()) { |
|
557 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
558 | + $stripe_customer->delete_card($token->get_token()); |
|
559 | 559 | } |
560 | 560 | } |
561 | 561 | |
562 | 562 | /** |
563 | 563 | * Set as default in Stripe |
564 | 564 | */ |
565 | - public function woocommerce_payment_token_set_default( $token_id ) { |
|
566 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
567 | - if ( 'stripe' === $token->get_gateway_id() ) { |
|
568 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
569 | - $stripe_customer->set_default_card( $token->get_token() ); |
|
565 | + public function woocommerce_payment_token_set_default($token_id) { |
|
566 | + $token = WC_Payment_Tokens::get($token_id); |
|
567 | + if ('stripe' === $token->get_gateway_id()) { |
|
568 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
569 | + $stripe_customer->set_default_card($token->get_token()); |
|
570 | 570 | } |
571 | 571 | } |
572 | 572 | |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | */ |
576 | 576 | public static function get_minimum_amount() { |
577 | 577 | // Check order amount |
578 | - switch ( get_woocommerce_currency() ) { |
|
578 | + switch (get_woocommerce_currency()) { |
|
579 | 579 | case 'USD': |
580 | 580 | case 'CAD': |
581 | 581 | case 'EUR': |
@@ -619,12 +619,12 @@ discard block |
||
619 | 619 | * And fits on your back? |
620 | 620 | * It's log, log, log |
621 | 621 | */ |
622 | - public static function log( $message ) { |
|
623 | - if ( empty( self::$log ) ) { |
|
622 | + public static function log($message) { |
|
623 | + if (empty(self::$log)) { |
|
624 | 624 | self::$log = new WC_Logger(); |
625 | 625 | } |
626 | 626 | |
627 | - self::$log->add( 'woocommerce-gateway-stripe', $message ); |
|
627 | + self::$log->add('woocommerce-gateway-stripe', $message); |
|
628 | 628 | } |
629 | 629 | } |
630 | 630 |