@@ -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.0.6' ); |
|
| 36 | -define( 'WC_STRIPE_MIN_PHP_VER', '5.3.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.0.6'); |
|
| 36 | +define('WC_STRIPE_MIN_PHP_VER', '5.3.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( 'woocommerce_stripe_version' ) ) ) { |
|
| 160 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('woocommerce_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 | - add_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
| 194 | + delete_option('wc_stripe_version'); |
|
| 195 | + add_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,12 +224,12 @@ 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 | // @TODO remove this in the future. |
| 232 | - update_option( 'wc_stripe_show_features_notice', 'yes' ); |
|
| 232 | + update_option('wc_stripe_show_features_notice', 'yes'); |
|
| 233 | 233 | |
| 234 | 234 | $this->_update_plugin_version(); |
| 235 | 235 | } |
@@ -239,24 +239,24 @@ discard block |
||
| 239 | 239 | * found or false if the environment has no problems. |
| 240 | 240 | */ |
| 241 | 241 | static function get_environment_warning() { |
| 242 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
| 243 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
| 242 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
| 243 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
| 244 | 244 | |
| 245 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
| 245 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
| 249 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
| 248 | + if ( ! defined('WC_VERSION')) { |
|
| 249 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
| 253 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
| 252 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
| 253 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
| 254 | 254 | |
| 255 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
| 255 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - if ( ! function_exists( 'curl_init' ) ) { |
|
| 259 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
| 258 | + if ( ! function_exists('curl_init')) { |
|
| 259 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | return false; |
@@ -267,15 +267,15 @@ discard block |
||
| 267 | 267 | * |
| 268 | 268 | * @since 1.0.0 |
| 269 | 269 | */ |
| 270 | - public function plugin_action_links( $links ) { |
|
| 270 | + public function plugin_action_links($links) { |
|
| 271 | 271 | $setting_link = $this->get_setting_link(); |
| 272 | 272 | |
| 273 | 273 | $plugin_links = array( |
| 274 | - '<a href="' . $setting_link . '">' . __( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
| 275 | - '<a href="https://docs.woothemes.com/document/stripe/">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
| 276 | - '<a href="http://support.woothemes.com/">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
| 274 | + '<a href="' . $setting_link . '">' . __('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
| 275 | + '<a href="https://docs.woothemes.com/document/stripe/">' . __('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
| 276 | + '<a href="http://support.woothemes.com/">' . __('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
| 277 | 277 | ); |
| 278 | - return array_merge( $plugin_links, $links ); |
|
| 278 | + return array_merge($plugin_links, $links); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
@@ -286,24 +286,24 @@ discard block |
||
| 286 | 286 | * @return string Setting link |
| 287 | 287 | */ |
| 288 | 288 | public function get_setting_link() { |
| 289 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
| 289 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
| 290 | 290 | |
| 291 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
| 291 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
| 292 | 292 | |
| 293 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
| 293 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | /** |
| 297 | 297 | * Display any notices we've collected thus far (e.g. for connection, disconnection) |
| 298 | 298 | */ |
| 299 | 299 | public function admin_notices() { |
| 300 | - $show_request_api_notice = get_option( 'wc_stripe_show_request_api_notice' ); |
|
| 301 | - $show_apple_pay_notice = get_option( 'wc_stripe_show_apple_pay_notice' ); |
|
| 300 | + $show_request_api_notice = get_option('wc_stripe_show_request_api_notice'); |
|
| 301 | + $show_apple_pay_notice = get_option('wc_stripe_show_apple_pay_notice'); |
|
| 302 | 302 | |
| 303 | - if ( empty( $show_apple_pay_notice ) || 'yes' === $show_apple_pay_notice ) { |
|
| 303 | + if (empty($show_apple_pay_notice) || 'yes' === $show_apple_pay_notice) { |
|
| 304 | 304 | // @TODO remove this notice in the future. |
| 305 | 305 | ?> |
| 306 | - <div class="notice notice-warning wc-stripe-apple-pay-notice is-dismissible"><p><?php esc_html_e( 'New Feature! Stripe now supports Apple Pay. Your customers can now purchase your products even faster. Apple Pay has been enabled by default.', 'woocommerce-gateway-stripe' ); ?></p></div> |
|
| 306 | + <div class="notice notice-warning wc-stripe-apple-pay-notice is-dismissible"><p><?php esc_html_e('New Feature! Stripe now supports Apple Pay. Your customers can now purchase your products even faster. Apple Pay has been enabled by default.', 'woocommerce-gateway-stripe'); ?></p></div> |
|
| 307 | 307 | |
| 308 | 308 | <script type="application/javascript"> |
| 309 | 309 | window.onload = function() { |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | action: 'stripe_dismiss_apple_pay_notice' |
| 313 | 313 | }; |
| 314 | 314 | |
| 315 | - jQuery.post( '<?php echo admin_url( 'admin-ajax.php' ); ?>', data ); |
|
| 315 | + jQuery.post( '<?php echo admin_url('admin-ajax.php'); ?>', data ); |
|
| 316 | 316 | }); |
| 317 | 317 | } |
| 318 | 318 | </script> |
@@ -320,10 +320,10 @@ discard block |
||
| 320 | 320 | <?php |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | - if ( empty( $show_request_api_notice ) || 'yes' === $show_request_api_notice ) { |
|
| 323 | + if (empty($show_request_api_notice) || 'yes' === $show_request_api_notice) { |
|
| 324 | 324 | // @TODO remove this notice in the future. |
| 325 | 325 | ?> |
| 326 | - <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> |
|
| 326 | + <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> |
|
| 327 | 327 | |
| 328 | 328 | <script type="application/javascript"> |
| 329 | 329 | window.onload = function() { |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | action: 'stripe_dismiss_request_api_notice' |
| 333 | 333 | }; |
| 334 | 334 | |
| 335 | - jQuery.post( '<?php echo admin_url( 'admin-ajax.php' ); ?>', data ); |
|
| 335 | + jQuery.post( '<?php echo admin_url('admin-ajax.php'); ?>', data ); |
|
| 336 | 336 | }); |
| 337 | 337 | } |
| 338 | 338 | </script> |
@@ -340,9 +340,9 @@ discard block |
||
| 340 | 340 | <?php |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 344 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 345 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 343 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 344 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 345 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 346 | 346 | echo '</p></div>'; |
| 347 | 347 | } |
| 348 | 348 | } |
@@ -353,28 +353,28 @@ discard block |
||
| 353 | 353 | * @since 1.0.0 |
| 354 | 354 | */ |
| 355 | 355 | public function init_gateways() { |
| 356 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) { |
|
| 356 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) { |
|
| 357 | 357 | $this->subscription_support_enabled = true; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
| 360 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
| 361 | 361 | $this->pre_order_enabled = true; |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - if ( ! class_exists( 'WC_Payment_Gateway' ) ) { |
|
| 364 | + if ( ! class_exists('WC_Payment_Gateway')) { |
|
| 365 | 365 | return; |
| 366 | 366 | } |
| 367 | 367 | |
| 368 | - if ( class_exists( 'WC_Payment_Gateway_CC' ) ) { |
|
| 369 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' ); |
|
| 370 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay.php' ); |
|
| 368 | + if (class_exists('WC_Payment_Gateway_CC')) { |
|
| 369 | + include_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'); |
|
| 370 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay.php'); |
|
| 371 | 371 | } else { |
| 372 | - include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe.php' ); |
|
| 373 | - include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php' ); |
|
| 372 | + include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe.php'); |
|
| 373 | + include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php'); |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
| 377 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
| 376 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
| 377 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
| 378 | 378 | |
| 379 | 379 | $load_addons = ( |
| 380 | 380 | $this->subscription_support_enabled |
@@ -382,8 +382,8 @@ discard block |
||
| 382 | 382 | $this->pre_order_enabled |
| 383 | 383 | ); |
| 384 | 384 | |
| 385 | - if ( $load_addons ) { |
|
| 386 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe-addons.php' ); |
|
| 385 | + if ($load_addons) { |
|
| 386 | + require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe-addons.php'); |
|
| 387 | 387 | } |
| 388 | 388 | } |
| 389 | 389 | |
@@ -392,8 +392,8 @@ discard block |
||
| 392 | 392 | * |
| 393 | 393 | * @since 1.0.0 |
| 394 | 394 | */ |
| 395 | - public function add_gateways( $methods ) { |
|
| 396 | - if ( $this->subscription_support_enabled || $this->pre_order_enabled ) { |
|
| 395 | + public function add_gateways($methods) { |
|
| 396 | + if ($this->subscription_support_enabled || $this->pre_order_enabled) { |
|
| 397 | 397 | $methods[] = 'WC_Gateway_Stripe_Addons'; |
| 398 | 398 | } else { |
| 399 | 399 | $methods[] = 'WC_Gateway_Stripe'; |
@@ -406,35 +406,35 @@ discard block |
||
| 406 | 406 | * |
| 407 | 407 | * @param int $order_id |
| 408 | 408 | */ |
| 409 | - public function capture_payment( $order_id ) { |
|
| 410 | - $order = wc_get_order( $order_id ); |
|
| 409 | + public function capture_payment($order_id) { |
|
| 410 | + $order = wc_get_order($order_id); |
|
| 411 | 411 | |
| 412 | - if ( 'stripe' === $order->payment_method ) { |
|
| 413 | - $charge = get_post_meta( $order_id, '_stripe_charge_id', true ); |
|
| 414 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
| 412 | + if ('stripe' === $order->payment_method) { |
|
| 413 | + $charge = get_post_meta($order_id, '_stripe_charge_id', true); |
|
| 414 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
| 415 | 415 | |
| 416 | - if ( $charge && 'no' === $captured ) { |
|
| 417 | - $result = WC_Stripe_API::request( array( |
|
| 416 | + if ($charge && 'no' === $captured) { |
|
| 417 | + $result = WC_Stripe_API::request(array( |
|
| 418 | 418 | 'amount' => $order->get_total() * 100, |
| 419 | 419 | 'expand[]' => 'balance_transaction', |
| 420 | - ), 'charges/' . $charge . '/capture' ); |
|
| 420 | + ), 'charges/' . $charge . '/capture'); |
|
| 421 | 421 | |
| 422 | - if ( is_wp_error( $result ) ) { |
|
| 423 | - $order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() ); |
|
| 422 | + if (is_wp_error($result)) { |
|
| 423 | + $order->add_order_note(__('Unable to capture charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message()); |
|
| 424 | 424 | } else { |
| 425 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
| 426 | - update_post_meta( $order->id, '_stripe_charge_captured', 'yes' ); |
|
| 425 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
| 426 | + update_post_meta($order->id, '_stripe_charge_captured', 'yes'); |
|
| 427 | 427 | |
| 428 | 428 | // Store other data such as fees |
| 429 | - update_post_meta( $order->id, 'Stripe Payment ID', $result->id ); |
|
| 429 | + update_post_meta($order->id, 'Stripe Payment ID', $result->id); |
|
| 430 | 430 | |
| 431 | - if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) { |
|
| 431 | + if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) { |
|
| 432 | 432 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
| 433 | 433 | // values are in the local currency of the Stripe account, not from WC. |
| 434 | - $fee = ! empty( $result->balance_transaction->fee ) ? number_format( $result->balance_transaction->fee / 100, 2, '.', '' ) : 0; |
|
| 435 | - $net = ! empty( $result->balance_transaction->net ) ? number_format( $result->balance_transaction->net / 100, 2, '.', '' ) : 0; |
|
| 436 | - update_post_meta( $order->id, 'Stripe Fee', $fee ); |
|
| 437 | - update_post_meta( $order->id, 'Net Revenue From Stripe', $net ); |
|
| 434 | + $fee = ! empty($result->balance_transaction->fee) ? number_format($result->balance_transaction->fee / 100, 2, '.', '') : 0; |
|
| 435 | + $net = ! empty($result->balance_transaction->net) ? number_format($result->balance_transaction->net / 100, 2, '.', '') : 0; |
|
| 436 | + update_post_meta($order->id, 'Stripe Fee', $fee); |
|
| 437 | + update_post_meta($order->id, 'Net Revenue From Stripe', $net); |
|
| 438 | 438 | } |
| 439 | 439 | } |
| 440 | 440 | } |
@@ -446,23 +446,23 @@ discard block |
||
| 446 | 446 | * |
| 447 | 447 | * @param int $order_id |
| 448 | 448 | */ |
| 449 | - public function cancel_payment( $order_id ) { |
|
| 450 | - $order = wc_get_order( $order_id ); |
|
| 449 | + public function cancel_payment($order_id) { |
|
| 450 | + $order = wc_get_order($order_id); |
|
| 451 | 451 | |
| 452 | - if ( 'stripe' === $order->payment_method ) { |
|
| 453 | - $charge = get_post_meta( $order_id, '_stripe_charge_id', true ); |
|
| 452 | + if ('stripe' === $order->payment_method) { |
|
| 453 | + $charge = get_post_meta($order_id, '_stripe_charge_id', true); |
|
| 454 | 454 | |
| 455 | - if ( $charge ) { |
|
| 456 | - $result = WC_Stripe_API::request( array( |
|
| 455 | + if ($charge) { |
|
| 456 | + $result = WC_Stripe_API::request(array( |
|
| 457 | 457 | 'amount' => $order->get_total() * 100, |
| 458 | - ), 'charges/' . $charge . '/refund' ); |
|
| 458 | + ), 'charges/' . $charge . '/refund'); |
|
| 459 | 459 | |
| 460 | - if ( is_wp_error( $result ) ) { |
|
| 461 | - $order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() ); |
|
| 460 | + if (is_wp_error($result)) { |
|
| 461 | + $order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message()); |
|
| 462 | 462 | } else { |
| 463 | - $order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
| 464 | - delete_post_meta( $order->id, '_stripe_charge_captured' ); |
|
| 465 | - delete_post_meta( $order->id, '_stripe_charge_id' ); |
|
| 463 | + $order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
| 464 | + delete_post_meta($order->id, '_stripe_charge_captured'); |
|
| 465 | + delete_post_meta($order->id, '_stripe_charge_id'); |
|
| 466 | 466 | } |
| 467 | 467 | } |
| 468 | 468 | } |
@@ -473,28 +473,28 @@ discard block |
||
| 473 | 473 | * @param array $tokens |
| 474 | 474 | * @return array |
| 475 | 475 | */ |
| 476 | - public function woocommerce_get_customer_payment_tokens( $tokens, $customer_id, $gateway_id ) { |
|
| 477 | - if ( is_user_logged_in() && 'stripe' === $gateway_id && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
| 478 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
| 476 | + public function woocommerce_get_customer_payment_tokens($tokens, $customer_id, $gateway_id) { |
|
| 477 | + if (is_user_logged_in() && 'stripe' === $gateway_id && class_exists('WC_Payment_Token_CC')) { |
|
| 478 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
| 479 | 479 | $stripe_cards = $stripe_customer->get_cards(); |
| 480 | 480 | $stored_tokens = array(); |
| 481 | 481 | |
| 482 | - foreach ( $tokens as $token ) { |
|
| 482 | + foreach ($tokens as $token) { |
|
| 483 | 483 | $stored_tokens[] = $token->get_token(); |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | - foreach ( $stripe_cards as $card ) { |
|
| 487 | - if ( ! in_array( $card->id, $stored_tokens ) ) { |
|
| 486 | + foreach ($stripe_cards as $card) { |
|
| 487 | + if ( ! in_array($card->id, $stored_tokens)) { |
|
| 488 | 488 | $token = new WC_Payment_Token_CC(); |
| 489 | - $token->set_token( $card->id ); |
|
| 490 | - $token->set_gateway_id( 'stripe' ); |
|
| 491 | - $token->set_card_type( strtolower( $card->brand ) ); |
|
| 492 | - $token->set_last4( $card->last4 ); |
|
| 493 | - $token->set_expiry_month( $card->exp_month ); |
|
| 494 | - $token->set_expiry_year( $card->exp_year ); |
|
| 495 | - $token->set_user_id( $customer_id ); |
|
| 489 | + $token->set_token($card->id); |
|
| 490 | + $token->set_gateway_id('stripe'); |
|
| 491 | + $token->set_card_type(strtolower($card->brand)); |
|
| 492 | + $token->set_last4($card->last4); |
|
| 493 | + $token->set_expiry_month($card->exp_month); |
|
| 494 | + $token->set_expiry_year($card->exp_year); |
|
| 495 | + $token->set_user_id($customer_id); |
|
| 496 | 496 | $token->save(); |
| 497 | - $tokens[ $token->get_id() ] = $token; |
|
| 497 | + $tokens[$token->get_id()] = $token; |
|
| 498 | 498 | } |
| 499 | 499 | } |
| 500 | 500 | } |
@@ -504,21 +504,21 @@ discard block |
||
| 504 | 504 | /** |
| 505 | 505 | * Delete token from Stripe |
| 506 | 506 | */ |
| 507 | - public function woocommerce_payment_token_deleted( $token_id, $token ) { |
|
| 508 | - if ( 'stripe' === $token->get_gateway_id() ) { |
|
| 509 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 510 | - $stripe_customer->delete_card( $token->get_token() ); |
|
| 507 | + public function woocommerce_payment_token_deleted($token_id, $token) { |
|
| 508 | + if ('stripe' === $token->get_gateway_id()) { |
|
| 509 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 510 | + $stripe_customer->delete_card($token->get_token()); |
|
| 511 | 511 | } |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | /** |
| 515 | 515 | * Set as default in Stripe |
| 516 | 516 | */ |
| 517 | - public function woocommerce_payment_token_set_default( $token_id ) { |
|
| 518 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
| 519 | - if ( 'stripe' === $token->get_gateway_id() ) { |
|
| 520 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 521 | - $stripe_customer->set_default_card( $token->get_token() ); |
|
| 517 | + public function woocommerce_payment_token_set_default($token_id) { |
|
| 518 | + $token = WC_Payment_Tokens::get($token_id); |
|
| 519 | + if ('stripe' === $token->get_gateway_id()) { |
|
| 520 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 521 | + $stripe_customer->set_default_card($token->get_token()); |
|
| 522 | 522 | } |
| 523 | 523 | } |
| 524 | 524 | |
@@ -527,7 +527,7 @@ discard block |
||
| 527 | 527 | */ |
| 528 | 528 | public static function get_minimum_amount() { |
| 529 | 529 | // Check order amount |
| 530 | - switch ( get_woocommerce_currency() ) { |
|
| 530 | + switch (get_woocommerce_currency()) { |
|
| 531 | 531 | case 'USD': |
| 532 | 532 | case 'CAD': |
| 533 | 533 | case 'EUR': |
@@ -571,12 +571,12 @@ discard block |
||
| 571 | 571 | * And fits on your back? |
| 572 | 572 | * It's log, log, log |
| 573 | 573 | */ |
| 574 | - public static function log( $message ) { |
|
| 575 | - if ( empty( self::$log ) ) { |
|
| 574 | + public static function log($message) { |
|
| 575 | + if (empty(self::$log)) { |
|
| 576 | 576 | self::$log = new WC_Logger(); |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | - self::$log->add( 'woocommerce-gateway-stripe', $message ); |
|
| 579 | + self::$log->add('woocommerce-gateway-stripe', $message); |
|
| 580 | 580 | } |
| 581 | 581 | } |
| 582 | 582 | |