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