@@ -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 | - add_option( 'wc_stripe_show_request_api_notice', 'no' ); |
|
| 207 | + add_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 | - add_option( 'wc_stripe_show_apple_pay_notice', 'no' ); |
|
| 217 | + add_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.woothemes.com/document/stripe/">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
| 273 | - '<a href="http://support.woothemes.com/">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
| 271 | + '<a href="' . $setting_link . '">' . __('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
| 272 | + '<a href="https://docs.woothemes.com/document/stripe/">' . __('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
| 273 | + '<a href="http://support.woothemes.com/">' . __('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 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> |
|
| 303 | + <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> |
|
| 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,35 +451,35 @@ 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, '2.7.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, '2.7.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 ); |
|
| 474 | + update_post_meta($order_id, 'Stripe Payment ID', $result->id); |
|
| 475 | 475 | |
| 476 | - if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) { |
|
| 476 | + if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) { |
|
| 477 | 477 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
| 478 | 478 | // values are in the local currency of the Stripe account, not from WC. |
| 479 | - $fee = ! empty( $result->balance_transaction->fee ) ? self::format_number( $result->balance_transaction, 'fee' ) : 0; |
|
| 480 | - $net = ! empty( $result->balance_transaction->net ) ? self::format_number( $result->balance_transaction, 'net' ) : 0; |
|
| 481 | - update_post_meta( $order_id, 'Stripe Fee', $fee ); |
|
| 482 | - update_post_meta( $order_id, 'Net Revenue From Stripe', $net ); |
|
| 479 | + $fee = ! empty($result->balance_transaction->fee) ? self::format_number($result->balance_transaction, 'fee') : 0; |
|
| 480 | + $net = ! empty($result->balance_transaction->net) ? self::format_number($result->balance_transaction, 'net') : 0; |
|
| 481 | + update_post_meta($order_id, 'Stripe Fee', $fee); |
|
| 482 | + update_post_meta($order_id, 'Net Revenue From Stripe', $net); |
|
| 483 | 483 | } |
| 484 | 484 | } |
| 485 | 485 | } |
@@ -491,23 +491,23 @@ discard block |
||
| 491 | 491 | * |
| 492 | 492 | * @param int $order_id |
| 493 | 493 | */ |
| 494 | - public function cancel_payment( $order_id ) { |
|
| 495 | - $order = wc_get_order( $order_id ); |
|
| 494 | + public function cancel_payment($order_id) { |
|
| 495 | + $order = wc_get_order($order_id); |
|
| 496 | 496 | |
| 497 | - if ( 'stripe' === ( version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->payment_method : $order->get_payment_method() ) ) { |
|
| 498 | - $charge = get_post_meta( $order_id, '_stripe_charge_id', true ); |
|
| 497 | + if ('stripe' === (version_compare(WC_VERSION, '2.7.0', '<') ? $order->payment_method : $order->get_payment_method())) { |
|
| 498 | + $charge = get_post_meta($order_id, '_stripe_charge_id', true); |
|
| 499 | 499 | |
| 500 | - if ( $charge ) { |
|
| 501 | - $result = WC_Stripe_API::request( array( |
|
| 500 | + if ($charge) { |
|
| 501 | + $result = WC_Stripe_API::request(array( |
|
| 502 | 502 | 'amount' => $order->get_total() * 100, |
| 503 | - ), 'charges/' . $charge . '/refund' ); |
|
| 503 | + ), 'charges/' . $charge . '/refund'); |
|
| 504 | 504 | |
| 505 | - if ( is_wp_error( $result ) ) { |
|
| 506 | - $order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() ); |
|
| 505 | + if (is_wp_error($result)) { |
|
| 506 | + $order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message()); |
|
| 507 | 507 | } else { |
| 508 | - $order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
| 509 | - delete_post_meta( $order_id, '_stripe_charge_captured' ); |
|
| 510 | - delete_post_meta( $order_id, '_stripe_charge_id' ); |
|
| 508 | + $order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
| 509 | + delete_post_meta($order_id, '_stripe_charge_captured'); |
|
| 510 | + delete_post_meta($order_id, '_stripe_charge_id'); |
|
| 511 | 511 | } |
| 512 | 512 | } |
| 513 | 513 | } |
@@ -518,28 +518,28 @@ discard block |
||
| 518 | 518 | * @param array $tokens |
| 519 | 519 | * @return array |
| 520 | 520 | */ |
| 521 | - public function woocommerce_get_customer_payment_tokens( $tokens, $customer_id, $gateway_id ) { |
|
| 522 | - if ( is_user_logged_in() && 'stripe' === $gateway_id && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
| 523 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
| 521 | + public function woocommerce_get_customer_payment_tokens($tokens, $customer_id, $gateway_id) { |
|
| 522 | + if (is_user_logged_in() && 'stripe' === $gateway_id && class_exists('WC_Payment_Token_CC')) { |
|
| 523 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
| 524 | 524 | $stripe_cards = $stripe_customer->get_cards(); |
| 525 | 525 | $stored_tokens = array(); |
| 526 | 526 | |
| 527 | - foreach ( $tokens as $token ) { |
|
| 527 | + foreach ($tokens as $token) { |
|
| 528 | 528 | $stored_tokens[] = $token->get_token(); |
| 529 | 529 | } |
| 530 | 530 | |
| 531 | - foreach ( $stripe_cards as $card ) { |
|
| 532 | - if ( ! in_array( $card->id, $stored_tokens ) ) { |
|
| 531 | + foreach ($stripe_cards as $card) { |
|
| 532 | + if ( ! in_array($card->id, $stored_tokens)) { |
|
| 533 | 533 | $token = new WC_Payment_Token_CC(); |
| 534 | - $token->set_token( $card->id ); |
|
| 535 | - $token->set_gateway_id( 'stripe' ); |
|
| 536 | - $token->set_card_type( strtolower( $card->brand ) ); |
|
| 537 | - $token->set_last4( $card->last4 ); |
|
| 538 | - $token->set_expiry_month( $card->exp_month ); |
|
| 539 | - $token->set_expiry_year( $card->exp_year ); |
|
| 540 | - $token->set_user_id( $customer_id ); |
|
| 534 | + $token->set_token($card->id); |
|
| 535 | + $token->set_gateway_id('stripe'); |
|
| 536 | + $token->set_card_type(strtolower($card->brand)); |
|
| 537 | + $token->set_last4($card->last4); |
|
| 538 | + $token->set_expiry_month($card->exp_month); |
|
| 539 | + $token->set_expiry_year($card->exp_year); |
|
| 540 | + $token->set_user_id($customer_id); |
|
| 541 | 541 | $token->save(); |
| 542 | - $tokens[ $token->get_id() ] = $token; |
|
| 542 | + $tokens[$token->get_id()] = $token; |
|
| 543 | 543 | } |
| 544 | 544 | } |
| 545 | 545 | } |
@@ -549,21 +549,21 @@ discard block |
||
| 549 | 549 | /** |
| 550 | 550 | * Delete token from Stripe |
| 551 | 551 | */ |
| 552 | - public function woocommerce_payment_token_deleted( $token_id, $token ) { |
|
| 553 | - if ( 'stripe' === $token->get_gateway_id() ) { |
|
| 554 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 555 | - $stripe_customer->delete_card( $token->get_token() ); |
|
| 552 | + public function woocommerce_payment_token_deleted($token_id, $token) { |
|
| 553 | + if ('stripe' === $token->get_gateway_id()) { |
|
| 554 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 555 | + $stripe_customer->delete_card($token->get_token()); |
|
| 556 | 556 | } |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | /** |
| 560 | 560 | * Set as default in Stripe |
| 561 | 561 | */ |
| 562 | - public function woocommerce_payment_token_set_default( $token_id ) { |
|
| 563 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
| 564 | - if ( 'stripe' === $token->get_gateway_id() ) { |
|
| 565 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 566 | - $stripe_customer->set_default_card( $token->get_token() ); |
|
| 562 | + public function woocommerce_payment_token_set_default($token_id) { |
|
| 563 | + $token = WC_Payment_Tokens::get($token_id); |
|
| 564 | + if ('stripe' === $token->get_gateway_id()) { |
|
| 565 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 566 | + $stripe_customer->set_default_card($token->get_token()); |
|
| 567 | 567 | } |
| 568 | 568 | } |
| 569 | 569 | |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | */ |
| 573 | 573 | public static function get_minimum_amount() { |
| 574 | 574 | // Check order amount |
| 575 | - switch ( get_woocommerce_currency() ) { |
|
| 575 | + switch (get_woocommerce_currency()) { |
|
| 576 | 576 | case 'USD': |
| 577 | 577 | case 'CAD': |
| 578 | 578 | case 'EUR': |
@@ -616,12 +616,12 @@ discard block |
||
| 616 | 616 | * And fits on your back? |
| 617 | 617 | * It's log, log, log |
| 618 | 618 | */ |
| 619 | - public static function log( $message ) { |
|
| 620 | - if ( empty( self::$log ) ) { |
|
| 619 | + public static function log($message) { |
|
| 620 | + if (empty(self::$log)) { |
|
| 621 | 621 | self::$log = new WC_Logger(); |
| 622 | 622 | } |
| 623 | 623 | |
| 624 | - self::$log->add( 'woocommerce-gateway-stripe', $message ); |
|
| 624 | + self::$log->add('woocommerce-gateway-stripe', $message); |
|
| 625 | 625 | } |
| 626 | 626 | } |
| 627 | 627 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -120,8 +120,8 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | public function __construct() { |
| 122 | 122 | $this->id = 'stripe'; |
| 123 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
| 124 | - $this->method_description = __( 'Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' ); |
|
| 123 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
| 124 | + $this->method_description = __('Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe'); |
|
| 125 | 125 | $this->has_fields = true; |
| 126 | 126 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
| 127 | 127 | $this->supports = array( |
@@ -149,43 +149,43 @@ discard block |
||
| 149 | 149 | $this->init_settings(); |
| 150 | 150 | |
| 151 | 151 | // Get setting values. |
| 152 | - $this->title = $this->get_option( 'title' ); |
|
| 153 | - $this->description = $this->get_option( 'description' ); |
|
| 154 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 155 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
| 156 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
| 157 | - $this->statement_descriptor = $this->get_option( 'statement_descriptor', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ); |
|
| 158 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
| 159 | - $this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' ); |
|
| 160 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
| 161 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
| 162 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
| 163 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
| 164 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
| 165 | - $this->apple_pay = 'yes' === $this->get_option( 'apple_pay', 'yes' ); |
|
| 166 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
| 167 | - $this->apple_pay_button = $this->get_option( 'apple_pay_button', 'black' ); |
|
| 168 | - $this->logging = 'yes' === $this->get_option( 'logging' ); |
|
| 169 | - $this->allow_remember_me = 'yes' === $this->get_option( 'allow_remember_me', 'no' ); |
|
| 170 | - |
|
| 171 | - if ( $this->stripe_checkout ) { |
|
| 172 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - if ( $this->testmode ) { |
|
| 176 | - $this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
| 177 | - $this->description = trim( $this->description ); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
| 152 | + $this->title = $this->get_option('title'); |
|
| 153 | + $this->description = $this->get_option('description'); |
|
| 154 | + $this->enabled = $this->get_option('enabled'); |
|
| 155 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
| 156 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
| 157 | + $this->statement_descriptor = $this->get_option('statement_descriptor', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)); |
|
| 158 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
| 159 | + $this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale'); |
|
| 160 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
| 161 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
| 162 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
| 163 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
| 164 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
| 165 | + $this->apple_pay = 'yes' === $this->get_option('apple_pay', 'yes'); |
|
| 166 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
| 167 | + $this->apple_pay_button = $this->get_option('apple_pay_button', 'black'); |
|
| 168 | + $this->logging = 'yes' === $this->get_option('logging'); |
|
| 169 | + $this->allow_remember_me = 'yes' === $this->get_option('allow_remember_me', 'no'); |
|
| 170 | + |
|
| 171 | + if ($this->stripe_checkout) { |
|
| 172 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + if ($this->testmode) { |
|
| 176 | + $this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
| 177 | + $this->description = trim($this->description); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
| 181 | 181 | |
| 182 | 182 | $this->init_apple_pay(); |
| 183 | 183 | |
| 184 | 184 | // Hooks. |
| 185 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 186 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
| 187 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
| 188 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 185 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 186 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
| 187 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
| 188 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -195,24 +195,24 @@ discard block |
||
| 195 | 195 | * @return string |
| 196 | 196 | */ |
| 197 | 197 | public function get_icon() { |
| 198 | - $ext = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png'; |
|
| 199 | - $style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : ''; |
|
| 198 | + $ext = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png'; |
|
| 199 | + $style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : ''; |
|
| 200 | 200 | |
| 201 | - $icon = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
| 202 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
| 203 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
| 201 | + $icon = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
| 202 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
| 203 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
| 204 | 204 | |
| 205 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
| 206 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
| 207 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
| 208 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
| 205 | + if ('USD' === get_woocommerce_currency()) { |
|
| 206 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
| 207 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
| 208 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if ( $this->bitcoin && $this->stripe_checkout ) { |
|
| 212 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="24" ' . $style . ' />'; |
|
| 211 | + if ($this->bitcoin && $this->stripe_checkout) { |
|
| 212 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="24" ' . $style . ' />'; |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id ); |
|
| 215 | + return apply_filters('woocommerce_gateway_icon', $icon, $this->id); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -223,11 +223,11 @@ discard block |
||
| 223 | 223 | * |
| 224 | 224 | * @return float|int |
| 225 | 225 | */ |
| 226 | - public function get_stripe_amount( $total, $currency = '' ) { |
|
| 227 | - if ( ! $currency ) { |
|
| 226 | + public function get_stripe_amount($total, $currency = '') { |
|
| 227 | + if ( ! $currency) { |
|
| 228 | 228 | $currency = get_woocommerce_currency(); |
| 229 | 229 | } |
| 230 | - switch ( strtoupper( $currency ) ) { |
|
| 230 | + switch (strtoupper($currency)) { |
|
| 231 | 231 | // Zero decimal currencies. |
| 232 | 232 | case 'BIF' : |
| 233 | 233 | case 'CLP' : |
@@ -244,10 +244,10 @@ discard block |
||
| 244 | 244 | case 'XAF' : |
| 245 | 245 | case 'XOF' : |
| 246 | 246 | case 'XPF' : |
| 247 | - $total = absint( $total ); |
|
| 247 | + $total = absint($total); |
|
| 248 | 248 | break; |
| 249 | 249 | default : |
| 250 | - $total = round( $total, 2 ) * 100; // In cents. |
|
| 250 | + $total = round($total, 2) * 100; // In cents. |
|
| 251 | 251 | break; |
| 252 | 252 | } |
| 253 | 253 | return $total; |
@@ -262,9 +262,9 @@ discard block |
||
| 262 | 262 | public function init_apple_pay() { |
| 263 | 263 | if ( |
| 264 | 264 | is_admin() && |
| 265 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
| 266 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
| 267 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] |
|
| 265 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
| 266 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
| 267 | + isset($_GET['section']) && 'stripe' === $_GET['section'] |
|
| 268 | 268 | ) { |
| 269 | 269 | $this->process_apple_pay_verification(); |
| 270 | 270 | } |
@@ -277,9 +277,9 @@ discard block |
||
| 277 | 277 | * @version 3.1.0 |
| 278 | 278 | * @param string $secret_key |
| 279 | 279 | */ |
| 280 | - private function _register_apple_pay_domain( $secret_key = '' ) { |
|
| 281 | - if ( empty( $secret_key ) ) { |
|
| 282 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
| 280 | + private function _register_apple_pay_domain($secret_key = '') { |
|
| 281 | + if (empty($secret_key)) { |
|
| 282 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -293,13 +293,13 @@ discard block |
||
| 293 | 293 | 'Authorization' => 'Bearer ' . $secret_key, |
| 294 | 294 | ); |
| 295 | 295 | |
| 296 | - $response = wp_remote_post( $endpoint, array( |
|
| 296 | + $response = wp_remote_post($endpoint, array( |
|
| 297 | 297 | 'headers' => $headers, |
| 298 | - 'body' => http_build_query( $data ), |
|
| 299 | - ) ); |
|
| 298 | + 'body' => http_build_query($data), |
|
| 299 | + )); |
|
| 300 | 300 | |
| 301 | - if ( 200 !== $response['response']['code'] ) { |
|
| 302 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response['response']['message'] ) ); |
|
| 301 | + if (200 !== $response['response']['code']) { |
|
| 302 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response['response']['message'])); |
|
| 303 | 303 | } |
| 304 | 304 | } |
| 305 | 305 | |
@@ -310,48 +310,48 @@ discard block |
||
| 310 | 310 | * @version 3.1.0 |
| 311 | 311 | */ |
| 312 | 312 | public function process_apple_pay_verification() { |
| 313 | - $gateway_settings = get_option( 'woocommerce_stripe_settings', '' ); |
|
| 313 | + $gateway_settings = get_option('woocommerce_stripe_settings', ''); |
|
| 314 | 314 | |
| 315 | 315 | try { |
| 316 | - $path = untrailingslashit( preg_replace( "!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME'] ) ); |
|
| 316 | + $path = untrailingslashit(preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME'])); |
|
| 317 | 317 | $dir = '.well-known'; |
| 318 | 318 | $file = 'apple-developer-merchantid-domain-association'; |
| 319 | 319 | $fullpath = $path . '/' . $dir . '/' . $file; |
| 320 | 320 | |
| 321 | - if ( 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) { |
|
| 321 | + if ('yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) { |
|
| 322 | 322 | return; |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - if ( ! file_exists( $path . '/' . $dir ) || ! file_exists( $fullpath ) ) { |
|
| 326 | - if ( ! mkdir( $path . '/' . $dir, 0755 ) ) { |
|
| 327 | - throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
| 325 | + if ( ! file_exists($path . '/' . $dir) || ! file_exists($fullpath)) { |
|
| 326 | + if ( ! mkdir($path . '/' . $dir, 0755)) { |
|
| 327 | + throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | - if ( ! file_exists( $path . '/' . $dir . '/' . 'apple-developer-merchantid-domain-association' ) ) { |
|
| 331 | - if ( ! copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { |
|
| 332 | - throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
| 330 | + if ( ! file_exists($path . '/' . $dir . '/' . 'apple-developer-merchantid-domain-association')) { |
|
| 331 | + if ( ! copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { |
|
| 332 | + throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | // At this point then the domain association folder and file should be available. |
| 338 | 338 | // Proceed to verify/and or verify again. |
| 339 | - $this->_register_apple_pay_domain( $this->secret_key ); |
|
| 339 | + $this->_register_apple_pay_domain($this->secret_key); |
|
| 340 | 340 | |
| 341 | 341 | // No errors to this point, verification success! |
| 342 | 342 | $gateway_settings['apple_pay_domain_set'] = 'yes'; |
| 343 | 343 | $this->apple_pay_domain_set = true; |
| 344 | 344 | |
| 345 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
| 345 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
| 346 | 346 | |
| 347 | - $this->log( __( 'Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe' ) ); |
|
| 347 | + $this->log(__('Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe')); |
|
| 348 | 348 | |
| 349 | - } catch ( Exception $e ) { |
|
| 349 | + } catch (Exception $e) { |
|
| 350 | 350 | $gateway_settings['apple_pay_domain_set'] = 'no'; |
| 351 | 351 | |
| 352 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
| 352 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
| 353 | 353 | |
| 354 | - $this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
| 354 | + $this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | * Check if SSL is enabled and notify the user |
| 360 | 360 | */ |
| 361 | 361 | public function admin_notices() { |
| 362 | - if ( 'no' === $this->enabled ) { |
|
| 362 | + if ('no' === $this->enabled) { |
|
| 363 | 363 | return; |
| 364 | 364 | } |
| 365 | 365 | |
@@ -368,13 +368,13 @@ discard block |
||
| 368 | 368 | * when setting screen is displayed. So if domain verification is not set, |
| 369 | 369 | * something went wrong so lets notify user. |
| 370 | 370 | */ |
| 371 | - if ( ! empty( $this->secret_key ) && $this->apple_pay && ! $this->apple_pay_domain_set ) { |
|
| 372 | - echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue.', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>'; |
|
| 371 | + if ( ! empty($this->secret_key) && $this->apple_pay && ! $this->apple_pay_domain_set) { |
|
| 372 | + echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue.', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('page=wc-status&tab=logs') . '">', '</a>') . '</p></div>'; |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
| 376 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
| 377 | - echo '<div class="error stripe-ssl-message"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ) . '</p></div>'; |
|
| 376 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
| 377 | + echo '<div class="error stripe-ssl-message"><p>' . sprintf(__('Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout')) . '</p></div>'; |
|
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | |
@@ -382,11 +382,11 @@ discard block |
||
| 382 | 382 | * Check if this gateway is enabled |
| 383 | 383 | */ |
| 384 | 384 | public function is_available() { |
| 385 | - if ( 'yes' === $this->enabled ) { |
|
| 386 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
| 385 | + if ('yes' === $this->enabled) { |
|
| 386 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
| 387 | 387 | return false; |
| 388 | 388 | } |
| 389 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
| 389 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
| 390 | 390 | return false; |
| 391 | 391 | } |
| 392 | 392 | return true; |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | * Initialise Gateway Settings Form Fields |
| 399 | 399 | */ |
| 400 | 400 | public function init_form_fields() { |
| 401 | - $this->form_fields = include( 'settings-stripe.php' ); |
|
| 401 | + $this->form_fields = include('settings-stripe.php'); |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | /** |
@@ -406,54 +406,54 @@ discard block |
||
| 406 | 406 | */ |
| 407 | 407 | public function payment_fields() { |
| 408 | 408 | $user = wp_get_current_user(); |
| 409 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
| 409 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
| 410 | 410 | $total = WC()->cart->total; |
| 411 | 411 | |
| 412 | 412 | // If paying from order, we need to get total from order not cart. |
| 413 | - if ( isset( $_GET['pay_for_order'] ) && isset( $_GET['key'] ) ) { |
|
| 414 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 413 | + if (isset($_GET['pay_for_order']) && isset($_GET['key'])) { |
|
| 414 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 415 | 415 | $total = $order->get_total(); |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | - if ( $user->ID ) { |
|
| 419 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
| 418 | + if ($user->ID) { |
|
| 419 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
| 420 | 420 | $user_email = $user_email ? $user_email : $user->user_email; |
| 421 | 421 | } else { |
| 422 | 422 | $user_email = ''; |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | - if ( is_add_payment_method_page() ) { |
|
| 426 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
| 425 | + if (is_add_payment_method_page()) { |
|
| 426 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
| 427 | 427 | } else { |
| 428 | 428 | $pay_button_text = ''; |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | echo '<div |
| 432 | 432 | id="stripe-payment-data" |
| 433 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
| 433 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
| 434 | 434 | data-description="" |
| 435 | - data-email="' . esc_attr( $user_email ) . '" |
|
| 436 | - data-amount="' . esc_attr( $this->get_stripe_amount( $total ) ) . '" |
|
| 437 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
| 438 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
| 439 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
| 440 | - data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '" |
|
| 441 | - data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '" |
|
| 442 | - data-allow-remember-me="' . esc_attr( $this->allow_remember_me ? 'true' : 'false' ) . '">'; |
|
| 435 | + data-email="' . esc_attr($user_email) . '" |
|
| 436 | + data-amount="' . esc_attr($this->get_stripe_amount($total)) . '" |
|
| 437 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
| 438 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
| 439 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
| 440 | + data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '" |
|
| 441 | + data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '" |
|
| 442 | + data-allow-remember-me="' . esc_attr($this->allow_remember_me ? 'true' : 'false') . '">'; |
|
| 443 | 443 | |
| 444 | - if ( $this->description ) { |
|
| 445 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 444 | + if ($this->description) { |
|
| 445 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | - if ( $display_tokenization ) { |
|
| 448 | + if ($display_tokenization) { |
|
| 449 | 449 | $this->tokenization_script(); |
| 450 | 450 | $this->saved_payment_methods(); |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | - if ( ! $this->stripe_checkout ) { |
|
| 453 | + if ( ! $this->stripe_checkout) { |
|
| 454 | 454 | $this->form(); |
| 455 | 455 | |
| 456 | - if ( $display_tokenization ) { |
|
| 456 | + if ($display_tokenization) { |
|
| 457 | 457 | $this->save_payment_method_checkbox(); |
| 458 | 458 | } |
| 459 | 459 | } |
@@ -469,20 +469,20 @@ discard block |
||
| 469 | 469 | * @return array |
| 470 | 470 | */ |
| 471 | 471 | public function get_localized_messages() { |
| 472 | - return apply_filters( 'wc_stripe_localized_messages', array( |
|
| 473 | - 'invalid_number' => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ), |
|
| 474 | - 'invalid_expiry_month' => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 475 | - 'invalid_expiry_year' => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 476 | - 'invalid_cvc' => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 477 | - 'incorrect_number' => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ), |
|
| 478 | - 'expired_card' => __( 'The card has expired.', 'woocommerce-gateway-stripe' ), |
|
| 479 | - 'incorrect_cvc' => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ), |
|
| 480 | - 'incorrect_zip' => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ), |
|
| 481 | - 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
| 482 | - 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
| 483 | - 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
| 484 | - 'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ), |
|
| 485 | - ) ); |
|
| 472 | + return apply_filters('wc_stripe_localized_messages', array( |
|
| 473 | + 'invalid_number' => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'), |
|
| 474 | + 'invalid_expiry_month' => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'), |
|
| 475 | + 'invalid_expiry_year' => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'), |
|
| 476 | + 'invalid_cvc' => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'), |
|
| 477 | + 'incorrect_number' => __('The card number is incorrect.', 'woocommerce-gateway-stripe'), |
|
| 478 | + 'expired_card' => __('The card has expired.', 'woocommerce-gateway-stripe'), |
|
| 479 | + 'incorrect_cvc' => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'), |
|
| 480 | + 'incorrect_zip' => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'), |
|
| 481 | + 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
| 482 | + 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
| 483 | + 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
| 484 | + 'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'), |
|
| 485 | + )); |
|
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | /** |
@@ -492,28 +492,28 @@ discard block |
||
| 492 | 492 | * @version 3.1.0 |
| 493 | 493 | */ |
| 494 | 494 | public function admin_scripts() { |
| 495 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
| 495 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
| 496 | 496 | return; |
| 497 | 497 | } |
| 498 | 498 | |
| 499 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 499 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 500 | 500 | |
| 501 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
| 501 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
| 502 | 502 | |
| 503 | 503 | $stripe_admin_params = array( |
| 504 | 504 | 'localized_messages' => array( |
| 505 | - 'not_valid_live_key_msg' => __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ), |
|
| 506 | - 'not_valid_test_key_msg' => __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ), |
|
| 507 | - 're_verify_button_text' => __( 'Re-verify Domain', 'woocommerce-gateway-stripe' ), |
|
| 508 | - 'missing_secret_key' => __( 'Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe' ), |
|
| 505 | + 'not_valid_live_key_msg' => __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe'), |
|
| 506 | + 'not_valid_test_key_msg' => __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe'), |
|
| 507 | + 're_verify_button_text' => __('Re-verify Domain', 'woocommerce-gateway-stripe'), |
|
| 508 | + 'missing_secret_key' => __('Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe'), |
|
| 509 | 509 | ), |
| 510 | - 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
| 510 | + 'ajaxurl' => admin_url('admin-ajax.php'), |
|
| 511 | 511 | 'nonce' => array( |
| 512 | - 'apple_pay_domain_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_domain_nonce' ), |
|
| 512 | + 'apple_pay_domain_nonce' => wp_create_nonce('_wc_stripe_apple_pay_domain_nonce'), |
|
| 513 | 513 | ), |
| 514 | 514 | ); |
| 515 | 515 | |
| 516 | - wp_localize_script( 'woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters( 'wc_stripe_admin_params', $stripe_admin_params ) ); |
|
| 516 | + wp_localize_script('woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters('wc_stripe_admin_params', $stripe_admin_params)); |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | /** |
@@ -524,49 +524,49 @@ discard block |
||
| 524 | 524 | * @access public |
| 525 | 525 | */ |
| 526 | 526 | public function payment_scripts() { |
| 527 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 527 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
| 528 | 528 | return; |
| 529 | 529 | } |
| 530 | 530 | |
| 531 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 531 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 532 | 532 | |
| 533 | - if ( $this->stripe_checkout ) { |
|
| 534 | - wp_enqueue_script( 'stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true ); |
|
| 535 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 533 | + if ($this->stripe_checkout) { |
|
| 534 | + wp_enqueue_script('stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true); |
|
| 535 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
| 536 | 536 | } else { |
| 537 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
| 538 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 537 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
| 538 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true); |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | $stripe_params = array( |
| 542 | 542 | 'key' => $this->publishable_key, |
| 543 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
| 544 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
| 543 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
| 544 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
| 545 | 545 | ); |
| 546 | 546 | |
| 547 | 547 | // If we're on the pay page we need to pass stripe.js the address of the order. |
| 548 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
| 549 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
| 550 | - $order = wc_get_order( $order_id ); |
|
| 548 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
| 549 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
| 550 | + $order = wc_get_order($order_id); |
|
| 551 | 551 | |
| 552 | - $stripe_params['billing_first_name'] = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->billing_first_name : $order->get_billing_first_name(); |
|
| 553 | - $stripe_params['billing_last_name'] = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->billing_last_name : $order->get_billing_last_name(); |
|
| 554 | - $stripe_params['billing_address_1'] = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->billing_address_1 : $order->get_billing_address_1(); |
|
| 555 | - $stripe_params['billing_address_2'] = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->billing_address_2 : $order->get_billing_address_2(); |
|
| 556 | - $stripe_params['billing_state'] = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->billing_state : $order->get_billing_state(); |
|
| 557 | - $stripe_params['billing_city'] = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->billing_city : $order->get_billing_city(); |
|
| 558 | - $stripe_params['billing_postcode'] = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->billing_postcode : $order->get_billing_postcode(); |
|
| 559 | - $stripe_params['billing_country'] = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->billing_country : $order->get_billing_country(); |
|
| 552 | + $stripe_params['billing_first_name'] = version_compare(WC_VERSION, '2.7.0', '<') ? $order->billing_first_name : $order->get_billing_first_name(); |
|
| 553 | + $stripe_params['billing_last_name'] = version_compare(WC_VERSION, '2.7.0', '<') ? $order->billing_last_name : $order->get_billing_last_name(); |
|
| 554 | + $stripe_params['billing_address_1'] = version_compare(WC_VERSION, '2.7.0', '<') ? $order->billing_address_1 : $order->get_billing_address_1(); |
|
| 555 | + $stripe_params['billing_address_2'] = version_compare(WC_VERSION, '2.7.0', '<') ? $order->billing_address_2 : $order->get_billing_address_2(); |
|
| 556 | + $stripe_params['billing_state'] = version_compare(WC_VERSION, '2.7.0', '<') ? $order->billing_state : $order->get_billing_state(); |
|
| 557 | + $stripe_params['billing_city'] = version_compare(WC_VERSION, '2.7.0', '<') ? $order->billing_city : $order->get_billing_city(); |
|
| 558 | + $stripe_params['billing_postcode'] = version_compare(WC_VERSION, '2.7.0', '<') ? $order->billing_postcode : $order->get_billing_postcode(); |
|
| 559 | + $stripe_params['billing_country'] = version_compare(WC_VERSION, '2.7.0', '<') ? $order->billing_country : $order->get_billing_country(); |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | - $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ); |
|
| 563 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
| 564 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
| 562 | + $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'); |
|
| 563 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
| 564 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
| 565 | 565 | |
| 566 | 566 | // merge localized messages to be use in JS |
| 567 | - $stripe_params = array_merge( $stripe_params, $this->get_localized_messages() ); |
|
| 567 | + $stripe_params = array_merge($stripe_params, $this->get_localized_messages()); |
|
| 568 | 568 | |
| 569 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
| 569 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | /** |
@@ -575,35 +575,35 @@ discard block |
||
| 575 | 575 | * @param object $source |
| 576 | 576 | * @return array() |
| 577 | 577 | */ |
| 578 | - protected function generate_payment_request( $order, $source ) { |
|
| 578 | + protected function generate_payment_request($order, $source) { |
|
| 579 | 579 | $post_data = array(); |
| 580 | - $post_data['currency'] = strtolower( version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->get_order_currency() : $order->get_currency() ); |
|
| 581 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
| 582 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() ); |
|
| 580 | + $post_data['currency'] = strtolower(version_compare(WC_VERSION, '2.7.0', '<') ? $order->get_order_currency() : $order->get_currency()); |
|
| 581 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
| 582 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number()); |
|
| 583 | 583 | $post_data['capture'] = $this->capture ? 'true' : 'false'; |
| 584 | 584 | |
| 585 | - $billing_email = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->billing_email : $order->get_billing_email(); |
|
| 586 | - $billing_first_name = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->billing_first_name : $order->get_billing_first_name(); |
|
| 587 | - $billing_last_name = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->billing_last_name : $order->get_billing_last_name(); |
|
| 585 | + $billing_email = version_compare(WC_VERSION, '2.7.0', '<') ? $order->billing_email : $order->get_billing_email(); |
|
| 586 | + $billing_first_name = version_compare(WC_VERSION, '2.7.0', '<') ? $order->billing_first_name : $order->get_billing_first_name(); |
|
| 587 | + $billing_last_name = version_compare(WC_VERSION, '2.7.0', '<') ? $order->billing_last_name : $order->get_billing_last_name(); |
|
| 588 | 588 | |
| 589 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
| 589 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
| 590 | 590 | $post_data['receipt_email'] = $billing_email; |
| 591 | 591 | } |
| 592 | 592 | |
| 593 | - $post_data['expand[]'] = 'balance_transaction'; |
|
| 593 | + $post_data['expand[]'] = 'balance_transaction'; |
|
| 594 | 594 | |
| 595 | 595 | $metadata = array( |
| 596 | - __( 'Customer Name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
| 597 | - __( 'Customer Email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
| 596 | + __('Customer Name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
| 597 | + __('Customer Email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
| 598 | 598 | ); |
| 599 | 599 | |
| 600 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source ); |
|
| 600 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source); |
|
| 601 | 601 | |
| 602 | - if ( $source->customer ) { |
|
| 602 | + if ($source->customer) { |
|
| 603 | 603 | $post_data['customer'] = $source->customer; |
| 604 | 604 | } |
| 605 | 605 | |
| 606 | - if ( $source->source ) { |
|
| 606 | + if ($source->source) { |
|
| 607 | 607 | $post_data['source'] = $source->source; |
| 608 | 608 | } |
| 609 | 609 | |
@@ -615,7 +615,7 @@ discard block |
||
| 615 | 615 | * @param WC_Order $order |
| 616 | 616 | * @param object $source |
| 617 | 617 | */ |
| 618 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
| 618 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | /** |
@@ -627,37 +627,37 @@ discard block |
||
| 627 | 627 | * @throws Exception When card was not added or for and invalid card. |
| 628 | 628 | * @return object |
| 629 | 629 | */ |
| 630 | - protected function get_source( $user_id, $force_customer = false ) { |
|
| 631 | - $stripe_customer = new WC_Stripe_Customer( $user_id ); |
|
| 630 | + protected function get_source($user_id, $force_customer = false) { |
|
| 631 | + $stripe_customer = new WC_Stripe_Customer($user_id); |
|
| 632 | 632 | $stripe_source = false; |
| 633 | 633 | $token_id = false; |
| 634 | 634 | |
| 635 | 635 | // New CC info was entered and we have a new token to process |
| 636 | - if ( isset( $_POST['stripe_token'] ) ) { |
|
| 637 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
| 638 | - $maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] ); |
|
| 636 | + if (isset($_POST['stripe_token'])) { |
|
| 637 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
| 638 | + $maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']); |
|
| 639 | 639 | |
| 640 | 640 | // This is true if the user wants to store the card to their account. |
| 641 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) { |
|
| 642 | - $stripe_source = $stripe_customer->add_card( $stripe_token ); |
|
| 641 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) { |
|
| 642 | + $stripe_source = $stripe_customer->add_card($stripe_token); |
|
| 643 | 643 | |
| 644 | - if ( is_wp_error( $stripe_source ) ) { |
|
| 645 | - throw new Exception( $stripe_source->get_error_message() ); |
|
| 644 | + if (is_wp_error($stripe_source)) { |
|
| 645 | + throw new Exception($stripe_source->get_error_message()); |
|
| 646 | 646 | } |
| 647 | 647 | } else { |
| 648 | 648 | // Not saving token, so don't define customer either. |
| 649 | 649 | $stripe_source = $stripe_token; |
| 650 | 650 | $stripe_customer = false; |
| 651 | 651 | } |
| 652 | - } elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) { |
|
| 652 | + } elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) { |
|
| 653 | 653 | // Use an existing token, and then process the payment |
| 654 | 654 | |
| 655 | - $token_id = wc_clean( $_POST['wc-stripe-payment-token'] ); |
|
| 656 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
| 655 | + $token_id = wc_clean($_POST['wc-stripe-payment-token']); |
|
| 656 | + $token = WC_Payment_Tokens::get($token_id); |
|
| 657 | 657 | |
| 658 | - if ( ! $token || $token->get_user_id() !== get_current_user_id() ) { |
|
| 659 | - WC()->session->set( 'refresh_totals', true ); |
|
| 660 | - throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
| 658 | + if ( ! $token || $token->get_user_id() !== get_current_user_id()) { |
|
| 659 | + WC()->session->set('refresh_totals', true); |
|
| 660 | + throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | $stripe_source = $token->get_token(); |
@@ -681,19 +681,19 @@ discard block |
||
| 681 | 681 | * @param object $order |
| 682 | 682 | * @return object |
| 683 | 683 | */ |
| 684 | - protected function get_order_source( $order = null ) { |
|
| 684 | + protected function get_order_source($order = null) { |
|
| 685 | 685 | $stripe_customer = new WC_Stripe_Customer(); |
| 686 | 686 | $stripe_source = false; |
| 687 | 687 | $token_id = false; |
| 688 | 688 | |
| 689 | - if ( $order ) { |
|
| 690 | - $order_id = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->id : $order->get_id(); |
|
| 689 | + if ($order) { |
|
| 690 | + $order_id = version_compare(WC_VERSION, '2.7.0', '<') ? $order->id : $order->get_id(); |
|
| 691 | 691 | |
| 692 | - if ( $meta_value = get_post_meta( $order_id, '_stripe_customer_id', true ) ) { |
|
| 693 | - $stripe_customer->set_id( $meta_value ); |
|
| 692 | + if ($meta_value = get_post_meta($order_id, '_stripe_customer_id', true)) { |
|
| 693 | + $stripe_customer->set_id($meta_value); |
|
| 694 | 694 | } |
| 695 | 695 | |
| 696 | - if ( $meta_value = get_post_meta( $order_id, '_stripe_card_id', true ) ) { |
|
| 696 | + if ($meta_value = get_post_meta($order_id, '_stripe_card_id', true)) { |
|
| 697 | 697 | $stripe_source = $meta_value; |
| 698 | 698 | } |
| 699 | 699 | } |
@@ -716,57 +716,57 @@ discard block |
||
| 716 | 716 | * |
| 717 | 717 | * @return array|void |
| 718 | 718 | */ |
| 719 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
| 719 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
| 720 | 720 | try { |
| 721 | - $order = wc_get_order( $order_id ); |
|
| 722 | - $source = $this->get_source( get_current_user_id(), $force_customer ); |
|
| 721 | + $order = wc_get_order($order_id); |
|
| 722 | + $source = $this->get_source(get_current_user_id(), $force_customer); |
|
| 723 | 723 | |
| 724 | - if ( empty( $source->source ) && empty( $source->customer ) ) { |
|
| 725 | - $error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' ); |
|
| 726 | - $error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' ); |
|
| 727 | - throw new Exception( $error_msg ); |
|
| 724 | + if (empty($source->source) && empty($source->customer)) { |
|
| 725 | + $error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe'); |
|
| 726 | + $error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe'); |
|
| 727 | + throw new Exception($error_msg); |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | // Store source to order meta. |
| 731 | - $this->save_source( $order, $source ); |
|
| 731 | + $this->save_source($order, $source); |
|
| 732 | 732 | |
| 733 | 733 | // Handle payment. |
| 734 | - if ( $order->get_total() > 0 ) { |
|
| 734 | + if ($order->get_total() > 0) { |
|
| 735 | 735 | |
| 736 | - if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) { |
|
| 737 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) ); |
|
| 736 | + if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) { |
|
| 737 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100))); |
|
| 738 | 738 | } |
| 739 | 739 | |
| 740 | - $this->log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
| 740 | + $this->log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
| 741 | 741 | |
| 742 | 742 | // Make the request. |
| 743 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
| 743 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
| 744 | 744 | |
| 745 | - if ( is_wp_error( $response ) ) { |
|
| 745 | + if (is_wp_error($response)) { |
|
| 746 | 746 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
| 747 | - if ( 'customer' === $response->get_error_code() && $retry ) { |
|
| 748 | - delete_user_meta( get_current_user_id(), '_stripe_customer_id' ); |
|
| 749 | - return $this->process_payment( $order_id, false, $force_customer ); |
|
| 747 | + if ('customer' === $response->get_error_code() && $retry) { |
|
| 748 | + delete_user_meta(get_current_user_id(), '_stripe_customer_id'); |
|
| 749 | + return $this->process_payment($order_id, false, $force_customer); |
|
| 750 | 750 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
| 751 | - } elseif ( 'source' === $response->get_error_code() && $source->token_id ) { |
|
| 752 | - $token = WC_Payment_Tokens::get( $source->token_id ); |
|
| 751 | + } elseif ('source' === $response->get_error_code() && $source->token_id) { |
|
| 752 | + $token = WC_Payment_Tokens::get($source->token_id); |
|
| 753 | 753 | $token->delete(); |
| 754 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
| 755 | - $order->add_order_note( $message ); |
|
| 756 | - throw new Exception( $message ); |
|
| 754 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
| 755 | + $order->add_order_note($message); |
|
| 756 | + throw new Exception($message); |
|
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | $localized_messages = $this->get_localized_messages(); |
| 760 | 760 | |
| 761 | - $message = isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message(); |
|
| 761 | + $message = isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message(); |
|
| 762 | 762 | |
| 763 | - $order->add_order_note( $message ); |
|
| 763 | + $order->add_order_note($message); |
|
| 764 | 764 | |
| 765 | - throw new Exception( $message ); |
|
| 765 | + throw new Exception($message); |
|
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | // Process valid response. |
| 769 | - $this->process_response( $response, $order ); |
|
| 769 | + $this->process_response($response, $order); |
|
| 770 | 770 | } else { |
| 771 | 771 | $order->payment_complete(); |
| 772 | 772 | } |
@@ -774,23 +774,23 @@ discard block |
||
| 774 | 774 | // Remove cart. |
| 775 | 775 | WC()->cart->empty_cart(); |
| 776 | 776 | |
| 777 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
| 777 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
| 778 | 778 | |
| 779 | 779 | // Return thank you page redirect. |
| 780 | 780 | return array( |
| 781 | 781 | 'result' => 'success', |
| 782 | - 'redirect' => $this->get_return_url( $order ), |
|
| 782 | + 'redirect' => $this->get_return_url($order), |
|
| 783 | 783 | ); |
| 784 | 784 | |
| 785 | - } catch ( Exception $e ) { |
|
| 786 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 787 | - $this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
| 785 | + } catch (Exception $e) { |
|
| 786 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 787 | + $this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
| 788 | 788 | |
| 789 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 790 | - $this->send_failed_order_email( $order_id ); |
|
| 789 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 790 | + $this->send_failed_order_email($order_id); |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 793 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 794 | 794 | |
| 795 | 795 | return array( |
| 796 | 796 | 'result' => 'fail', |
@@ -805,56 +805,56 @@ discard block |
||
| 805 | 805 | * @param WC_Order $order For to which the source applies. |
| 806 | 806 | * @param stdClass $source Source information. |
| 807 | 807 | */ |
| 808 | - protected function save_source( $order, $source ) { |
|
| 809 | - $order_id = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->id : $order->get_id(); |
|
| 808 | + protected function save_source($order, $source) { |
|
| 809 | + $order_id = version_compare(WC_VERSION, '2.7.0', '<') ? $order->id : $order->get_id(); |
|
| 810 | 810 | |
| 811 | 811 | // Store source in the order. |
| 812 | - if ( $source->customer ) { |
|
| 813 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
| 812 | + if ($source->customer) { |
|
| 813 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
| 814 | 814 | } |
| 815 | - if ( $source->source ) { |
|
| 816 | - update_post_meta( $order_id, '_stripe_card_id', $source->source ); |
|
| 815 | + if ($source->source) { |
|
| 816 | + update_post_meta($order_id, '_stripe_card_id', $source->source); |
|
| 817 | 817 | } |
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | /** |
| 821 | 821 | * Store extra meta data for an order from a Stripe Response. |
| 822 | 822 | */ |
| 823 | - public function process_response( $response, $order ) { |
|
| 824 | - $this->log( 'Processing response: ' . print_r( $response, true ) ); |
|
| 823 | + public function process_response($response, $order) { |
|
| 824 | + $this->log('Processing response: ' . print_r($response, true)); |
|
| 825 | 825 | |
| 826 | - $order_id = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->id : $order->get_id(); |
|
| 826 | + $order_id = version_compare(WC_VERSION, '2.7.0', '<') ? $order->id : $order->get_id(); |
|
| 827 | 827 | |
| 828 | 828 | // Store charge data |
| 829 | - update_post_meta( $order_id, '_stripe_charge_id', $response->id ); |
|
| 830 | - update_post_meta( $order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' ); |
|
| 829 | + update_post_meta($order_id, '_stripe_charge_id', $response->id); |
|
| 830 | + update_post_meta($order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no'); |
|
| 831 | 831 | |
| 832 | 832 | // Store other data such as fees |
| 833 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
| 833 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
| 834 | 834 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
| 835 | 835 | // values are in the local currency of the Stripe account, not from WC. |
| 836 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe::format_number( $response->balance_transaction, 'fee' ) : 0; |
|
| 837 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe::format_number( $response->balance_transaction, 'net' ) : 0; |
|
| 838 | - update_post_meta( $order_id, 'Stripe Fee', $fee ); |
|
| 839 | - update_post_meta( $order_id, 'Net Revenue From Stripe', $net ); |
|
| 836 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe::format_number($response->balance_transaction, 'fee') : 0; |
|
| 837 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe::format_number($response->balance_transaction, 'net') : 0; |
|
| 838 | + update_post_meta($order_id, 'Stripe Fee', $fee); |
|
| 839 | + update_post_meta($order_id, 'Net Revenue From Stripe', $net); |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | - if ( $response->captured ) { |
|
| 843 | - $order->payment_complete( $response->id ); |
|
| 842 | + if ($response->captured) { |
|
| 843 | + $order->payment_complete($response->id); |
|
| 844 | 844 | |
| 845 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
| 846 | - $order->add_order_note( $message ); |
|
| 847 | - $this->log( 'Success: ' . $message ); |
|
| 845 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
| 846 | + $order->add_order_note($message); |
|
| 847 | + $this->log('Success: ' . $message); |
|
| 848 | 848 | |
| 849 | 849 | } else { |
| 850 | - add_post_meta( $order_id, '_transaction_id', $response->id, true ); |
|
| 850 | + add_post_meta($order_id, '_transaction_id', $response->id, true); |
|
| 851 | 851 | |
| 852 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 853 | - version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
| 852 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 853 | + version_compare(WC_VERSION, '2.7.0', '<') ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
| 854 | 854 | } |
| 855 | 855 | |
| 856 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
| 857 | - $this->log( "Successful auth: $response->id" ); |
|
| 856 | + $order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id)); |
|
| 857 | + $this->log("Successful auth: $response->id"); |
|
| 858 | 858 | } |
| 859 | 859 | |
| 860 | 860 | return $response; |
@@ -866,32 +866,32 @@ discard block |
||
| 866 | 866 | * @since 3.0.0 |
| 867 | 867 | */ |
| 868 | 868 | public function add_payment_method() { |
| 869 | - if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
| 870 | - wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' ); |
|
| 869 | + if (empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
| 870 | + wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error'); |
|
| 871 | 871 | return; |
| 872 | 872 | } |
| 873 | 873 | |
| 874 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 875 | - $card = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) ); |
|
| 874 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 875 | + $card = $stripe_customer->add_card(wc_clean($_POST['stripe_token'])); |
|
| 876 | 876 | |
| 877 | - if ( is_wp_error( $card ) ) { |
|
| 877 | + if (is_wp_error($card)) { |
|
| 878 | 878 | $localized_messages = $this->get_localized_messages(); |
| 879 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
| 879 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
| 880 | 880 | |
| 881 | 881 | // loop through the errors to find matching localized message |
| 882 | - foreach ( $card->errors as $error => $msg ) { |
|
| 883 | - if ( isset( $localized_messages[ $error ] ) ) { |
|
| 884 | - $error_msg = $localized_messages[ $error ]; |
|
| 882 | + foreach ($card->errors as $error => $msg) { |
|
| 883 | + if (isset($localized_messages[$error])) { |
|
| 884 | + $error_msg = $localized_messages[$error]; |
|
| 885 | 885 | } |
| 886 | 886 | } |
| 887 | 887 | |
| 888 | - wc_add_notice( $error_msg, 'error' ); |
|
| 888 | + wc_add_notice($error_msg, 'error'); |
|
| 889 | 889 | return; |
| 890 | 890 | } |
| 891 | 891 | |
| 892 | 892 | return array( |
| 893 | 893 | 'result' => 'success', |
| 894 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
| 894 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
| 895 | 895 | ); |
| 896 | 896 | } |
| 897 | 897 | |
@@ -901,36 +901,36 @@ discard block |
||
| 901 | 901 | * @param float $amount |
| 902 | 902 | * @return bool |
| 903 | 903 | */ |
| 904 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
| 905 | - $order = wc_get_order( $order_id ); |
|
| 904 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
| 905 | + $order = wc_get_order($order_id); |
|
| 906 | 906 | |
| 907 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
| 907 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
| 908 | 908 | return false; |
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | $body = array(); |
| 912 | 912 | |
| 913 | - if ( ! is_null( $amount ) ) { |
|
| 914 | - $body['amount'] = $this->get_stripe_amount( $amount ); |
|
| 913 | + if ( ! is_null($amount)) { |
|
| 914 | + $body['amount'] = $this->get_stripe_amount($amount); |
|
| 915 | 915 | } |
| 916 | 916 | |
| 917 | - if ( $reason ) { |
|
| 917 | + if ($reason) { |
|
| 918 | 918 | $body['metadata'] = array( |
| 919 | 919 | 'reason' => $reason, |
| 920 | 920 | ); |
| 921 | 921 | } |
| 922 | 922 | |
| 923 | - $this->log( "Info: Beginning refund for order $order_id for the amount of {$amount}" ); |
|
| 923 | + $this->log("Info: Beginning refund for order $order_id for the amount of {$amount}"); |
|
| 924 | 924 | |
| 925 | - $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
| 925 | + $response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds'); |
|
| 926 | 926 | |
| 927 | - if ( is_wp_error( $response ) ) { |
|
| 928 | - $this->log( 'Error: ' . $response->get_error_message() ); |
|
| 927 | + if (is_wp_error($response)) { |
|
| 928 | + $this->log('Error: ' . $response->get_error_message()); |
|
| 929 | 929 | return $response; |
| 930 | - } elseif ( ! empty( $response->id ) ) { |
|
| 931 | - $refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason ); |
|
| 932 | - $order->add_order_note( $refund_message ); |
|
| 933 | - $this->log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
| 930 | + } elseif ( ! empty($response->id)) { |
|
| 931 | + $refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason); |
|
| 932 | + $order->add_order_note($refund_message); |
|
| 933 | + $this->log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
| 934 | 934 | return true; |
| 935 | 935 | } |
| 936 | 936 | } |
@@ -943,10 +943,10 @@ discard block |
||
| 943 | 943 | * @param int $order_id |
| 944 | 944 | * @return null |
| 945 | 945 | */ |
| 946 | - public function send_failed_order_email( $order_id ) { |
|
| 946 | + public function send_failed_order_email($order_id) { |
|
| 947 | 947 | $emails = WC()->mailer()->get_emails(); |
| 948 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
| 949 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
| 948 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
| 949 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
| 950 | 950 | } |
| 951 | 951 | } |
| 952 | 952 | |
@@ -958,9 +958,9 @@ discard block |
||
| 958 | 958 | * |
| 959 | 959 | * @param string $message |
| 960 | 960 | */ |
| 961 | - public function log( $message ) { |
|
| 962 | - if ( $this->logging ) { |
|
| 963 | - WC_Stripe::log( $message ); |
|
| 961 | + public function log($message) { |
|
| 962 | + if ($this->logging) { |
|
| 963 | + WC_Stripe::log($message); |
|
| 964 | 964 | } |
| 965 | 965 | } |
| 966 | 966 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -47,9 +47,9 @@ discard block |
||
| 47 | 47 | public function __construct() { |
| 48 | 48 | self::$_this = $this; |
| 49 | 49 | |
| 50 | - $this->_gateway_settings = get_option( 'woocommerce_stripe_settings', '' ); |
|
| 50 | + $this->_gateway_settings = get_option('woocommerce_stripe_settings', ''); |
|
| 51 | 51 | |
| 52 | - $this->statement_descriptor = ! empty( $this->_gateway_settings['statement_descriptor'] ) ? $this->_gateway_settings['statement_descriptor'] : wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); |
|
| 52 | + $this->statement_descriptor = ! empty($this->_gateway_settings['statement_descriptor']) ? $this->_gateway_settings['statement_descriptor'] : wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 53 | 53 | |
| 54 | 54 | $this->init(); |
| 55 | 55 | } |
@@ -66,35 +66,35 @@ discard block |
||
| 66 | 66 | * @version 3.1.0 |
| 67 | 67 | */ |
| 68 | 68 | public function init() { |
| 69 | - add_action( 'wp_enqueue_scripts', array( $this, 'cart_scripts' ) ); |
|
| 70 | - add_action( 'wp_enqueue_scripts', array( $this, 'single_scripts' ) ); |
|
| 71 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_apple_pay_button' ), 1 ); |
|
| 72 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 1 ); |
|
| 73 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_separator_html' ), 2 ); |
|
| 74 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_button' ), 1 ); |
|
| 75 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_separator_html' ), 2 ); |
|
| 76 | - add_action( 'wc_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) ); |
|
| 77 | - add_action( 'wc_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) ); |
|
| 78 | - add_action( 'wc_ajax_wc_stripe_generate_apple_pay_single', array( $this, 'generate_apple_pay_single' ) ); |
|
| 79 | - add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) ); |
|
| 80 | - add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) ); |
|
| 81 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
| 69 | + add_action('wp_enqueue_scripts', array($this, 'cart_scripts')); |
|
| 70 | + add_action('wp_enqueue_scripts', array($this, 'single_scripts')); |
|
| 71 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_apple_pay_button'), 1); |
|
| 72 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 1); |
|
| 73 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_separator_html'), 2); |
|
| 74 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_button'), 1); |
|
| 75 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_separator_html'), 2); |
|
| 76 | + add_action('wc_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay')); |
|
| 77 | + add_action('wc_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart')); |
|
| 78 | + add_action('wc_ajax_wc_stripe_generate_apple_pay_single', array($this, 'generate_apple_pay_single')); |
|
| 79 | + add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods')); |
|
| 80 | + add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method')); |
|
| 81 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | 85 | * Filters the gateway title to reflect Apple Pay. |
| 86 | 86 | * |
| 87 | 87 | */ |
| 88 | - public function filter_gateway_title( $title, $id ) { |
|
| 88 | + public function filter_gateway_title($title, $id) { |
|
| 89 | 89 | global $post; |
| 90 | 90 | |
| 91 | - if ( ! is_object( $post ) ) { |
|
| 91 | + if ( ! is_object($post)) { |
|
| 92 | 92 | return $title; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
| 95 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
| 96 | 96 | |
| 97 | - if ( 'stripe' === $id && ! empty( $method_title ) ) { |
|
| 97 | + if ('stripe' === $id && ! empty($method_title)) { |
|
| 98 | 98 | return $method_title; |
| 99 | 99 | } |
| 100 | 100 | |
@@ -108,41 +108,41 @@ discard block |
||
| 108 | 108 | * @version 3.1.0 |
| 109 | 109 | */ |
| 110 | 110 | public function single_scripts() { |
| 111 | - if ( ! is_single() ) { |
|
| 111 | + if ( ! is_single()) { |
|
| 112 | 112 | return; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | global $post; |
| 116 | 116 | |
| 117 | - $product = wc_get_product( $post->ID ); |
|
| 117 | + $product = wc_get_product($post->ID); |
|
| 118 | 118 | |
| 119 | - if ( ! in_array( ( version_compare( WC_VERSION, '2.7.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 119 | + if ( ! in_array((version_compare(WC_VERSION, '2.7.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 120 | 120 | return; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 123 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 124 | 124 | |
| 125 | - wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
| 125 | + wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
| 126 | 126 | |
| 127 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
| 128 | - wp_enqueue_script( 'woocommerce_stripe_apple_pay_single', plugins_url( 'assets/js/stripe-apple-pay-single' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 127 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
| 128 | + wp_enqueue_script('woocommerce_stripe_apple_pay_single', plugins_url('assets/js/stripe-apple-pay-single' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
| 129 | 129 | |
| 130 | 130 | $publishable_key = 'yes' === $this->_gateway_settings['testmode'] ? $this->_gateway_settings['test_publishable_key'] : $this->_gateway_settings['publishable_key']; |
| 131 | 131 | |
| 132 | 132 | $stripe_params = array( |
| 133 | 133 | 'key' => $publishable_key, |
| 134 | 134 | 'currency_code' => get_woocommerce_currency(), |
| 135 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 135 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 136 | 136 | 'label' => $this->statement_descriptor, |
| 137 | - 'ajaxurl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
| 138 | - 'stripe_apple_pay_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ), |
|
| 139 | - 'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ), |
|
| 140 | - 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ), |
|
| 141 | - 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ), |
|
| 137 | + 'ajaxurl' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
| 138 | + 'stripe_apple_pay_nonce' => wp_create_nonce('_wc_stripe_apple_pay_nonce'), |
|
| 139 | + 'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'), |
|
| 140 | + 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'), |
|
| 141 | + 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'), |
|
| 142 | 142 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
| 143 | 143 | ); |
| 144 | 144 | |
| 145 | - wp_localize_script( 'woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters( 'wc_stripe_apple_pay_single_params', $stripe_params ) ); |
|
| 145 | + wp_localize_script('woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters('wc_stripe_apple_pay_single_params', $stripe_params)); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
@@ -152,34 +152,34 @@ discard block |
||
| 152 | 152 | * @version 3.1.0 |
| 153 | 153 | */ |
| 154 | 154 | public function cart_scripts() { |
| 155 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 155 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
| 156 | 156 | return; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 159 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 160 | 160 | |
| 161 | - wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
| 161 | + wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
| 162 | 162 | |
| 163 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
| 164 | - wp_enqueue_script( 'woocommerce_stripe_apple_pay', plugins_url( 'assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 163 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
| 164 | + wp_enqueue_script('woocommerce_stripe_apple_pay', plugins_url('assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
| 165 | 165 | |
| 166 | 166 | $publishable_key = 'yes' === $this->_gateway_settings['testmode'] ? $this->_gateway_settings['test_publishable_key'] : $this->_gateway_settings['publishable_key']; |
| 167 | 167 | |
| 168 | 168 | $stripe_params = array( |
| 169 | 169 | 'key' => $publishable_key, |
| 170 | 170 | 'currency_code' => get_woocommerce_currency(), |
| 171 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 171 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 172 | 172 | 'label' => $this->statement_descriptor, |
| 173 | - 'ajaxurl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
| 174 | - 'stripe_apple_pay_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ), |
|
| 175 | - 'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ), |
|
| 176 | - 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ), |
|
| 177 | - 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ), |
|
| 173 | + 'ajaxurl' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
| 174 | + 'stripe_apple_pay_nonce' => wp_create_nonce('_wc_stripe_apple_pay_nonce'), |
|
| 175 | + 'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'), |
|
| 176 | + 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'), |
|
| 177 | + 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'), |
|
| 178 | 178 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
| 179 | 179 | 'is_cart_page' => is_cart() ? 'yes' : 'no', |
| 180 | 180 | ); |
| 181 | 181 | |
| 182 | - wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) ); |
|
| 182 | + wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params)); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -208,25 +208,25 @@ discard block |
||
| 208 | 208 | */ |
| 209 | 209 | if ( |
| 210 | 210 | 'yes' !== $this->_gateway_settings['apple_pay'] |
| 211 | - || ! isset( $gateways['stripe'] ) |
|
| 211 | + || ! isset($gateways['stripe']) |
|
| 212 | 212 | ) { |
| 213 | 213 | return; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - if ( is_single() ) { |
|
| 216 | + if (is_single()) { |
|
| 217 | 217 | global $post; |
| 218 | 218 | |
| 219 | - $product = wc_get_product( $post->ID ); |
|
| 219 | + $product = wc_get_product($post->ID); |
|
| 220 | 220 | |
| 221 | - if ( ! in_array( ( version_compare( WC_VERSION, '2.7.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 221 | + if ( ! in_array((version_compare(WC_VERSION, '2.7.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 222 | 222 | return; |
| 223 | 223 | } |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - $apple_pay_button = ! empty( $this->_gateway_settings['apple_pay_button'] ) ? $this->_gateway_settings['apple_pay_button'] : 'black'; |
|
| 227 | - $button_lang = ! empty( $this->_gateway_settings['apple_pay_button_lang'] ) ? strtolower( $this->_gateway_settings['apple_pay_button_lang'] ) : 'en'; |
|
| 226 | + $apple_pay_button = ! empty($this->_gateway_settings['apple_pay_button']) ? $this->_gateway_settings['apple_pay_button'] : 'black'; |
|
| 227 | + $button_lang = ! empty($this->_gateway_settings['apple_pay_button_lang']) ? strtolower($this->_gateway_settings['apple_pay_button_lang']) : 'en'; |
|
| 228 | 228 | ?> |
| 229 | - <button class="apple-pay-button" lang="<?php echo esc_attr( $button_lang ); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr( $apple_pay_button ); ?>;"></button> |
|
| 229 | + <button class="apple-pay-button" lang="<?php echo esc_attr($button_lang); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr($apple_pay_button); ?>;"></button> |
|
| 230 | 230 | <?php |
| 231 | 231 | } |
| 232 | 232 | |
@@ -245,22 +245,22 @@ discard block |
||
| 245 | 245 | */ |
| 246 | 246 | if ( |
| 247 | 247 | 'yes' !== $this->_gateway_settings['apple_pay'] |
| 248 | - || ! isset( $gateways['stripe'] ) |
|
| 248 | + || ! isset($gateways['stripe']) |
|
| 249 | 249 | ) { |
| 250 | 250 | return; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - if ( is_single() ) { |
|
| 253 | + if (is_single()) { |
|
| 254 | 254 | global $post; |
| 255 | 255 | |
| 256 | - $product = wc_get_product( $post->ID ); |
|
| 256 | + $product = wc_get_product($post->ID); |
|
| 257 | 257 | |
| 258 | - if ( ! in_array( ( version_compare( WC_VERSION, '2.7.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 258 | + if ( ! in_array((version_compare(WC_VERSION, '2.7.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 259 | 259 | return; |
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | 262 | ?> |
| 263 | - <p class="apple-pay-button-checkout-separator">- <?php esc_html_e( 'Or', 'woocommerce-gateway-stripe' ); ?> -</p> |
|
| 263 | + <p class="apple-pay-button-checkout-separator">- <?php esc_html_e('Or', 'woocommerce-gateway-stripe'); ?> -</p> |
|
| 264 | 264 | <?php |
| 265 | 265 | } |
| 266 | 266 | |
@@ -271,44 +271,44 @@ discard block |
||
| 271 | 271 | * @version 3.1.0 |
| 272 | 272 | */ |
| 273 | 273 | public function generate_apple_pay_single() { |
| 274 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
| 275 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 274 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
| 275 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 279 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 278 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 279 | + define('WOOCOMMERCE_CART', true); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | global $post; |
| 283 | 283 | |
| 284 | - $product = wc_get_product( $post->ID ); |
|
| 285 | - $qty = absint( $_POST['qty'] ); |
|
| 284 | + $product = wc_get_product($post->ID); |
|
| 285 | + $qty = absint($_POST['qty']); |
|
| 286 | 286 | |
| 287 | 287 | /** |
| 288 | 288 | * If this page is single product page, we need to simulate |
| 289 | 289 | * adding the product to the cart taken account if it is a |
| 290 | 290 | * simple or variable product. |
| 291 | 291 | */ |
| 292 | - if ( is_single() ) { |
|
| 292 | + if (is_single()) { |
|
| 293 | 293 | // First empty the cart to prevent wrong calculation. |
| 294 | 294 | WC()->cart->empty_cart(); |
| 295 | 295 | |
| 296 | - if ( 'variable' === ( version_compare( WC_VERSION, '2.7.0', '<' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
| 297 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
| 296 | + if ('variable' === (version_compare(WC_VERSION, '2.7.0', '<') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
| 297 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
| 298 | 298 | |
| 299 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
| 299 | + $variation_id = $product->get_matching_variation($attributes); |
|
| 300 | 300 | |
| 301 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
| 301 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - if ( 'simple' === ( version_compare( WC_VERSION, '2.7.0', '<' ) ? $product->product_type : $product->get_type() ) ) { |
|
| 305 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
| 304 | + if ('simple' === (version_compare(WC_VERSION, '2.7.0', '<') ? $product->product_type : $product->get_type())) { |
|
| 305 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
| 306 | 306 | } |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | WC()->cart->calculate_totals(); |
| 310 | 310 | |
| 311 | - wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 311 | + wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | /** |
@@ -318,11 +318,11 @@ discard block |
||
| 318 | 318 | * @version 3.1.0 |
| 319 | 319 | */ |
| 320 | 320 | public function generate_apple_pay_cart() { |
| 321 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
| 322 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 321 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
| 322 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 325 | + wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -332,29 +332,29 @@ discard block |
||
| 332 | 332 | * @version 3.1.0 |
| 333 | 333 | * @param array $address |
| 334 | 334 | */ |
| 335 | - public function calculate_shipping( $address = array() ) { |
|
| 336 | - $country = strtoupper( $address['countryCode'] ); |
|
| 337 | - $state = strtoupper( $address['administrativeArea'] ); |
|
| 335 | + public function calculate_shipping($address = array()) { |
|
| 336 | + $country = strtoupper($address['countryCode']); |
|
| 337 | + $state = strtoupper($address['administrativeArea']); |
|
| 338 | 338 | $postcode = $address['postalCode']; |
| 339 | 339 | $city = $address['locality']; |
| 340 | 340 | |
| 341 | 341 | WC()->shipping->reset_shipping(); |
| 342 | 342 | |
| 343 | - if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
| 344 | - throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
| 345 | - } elseif ( $postcode ) { |
|
| 346 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
| 343 | + if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) { |
|
| 344 | + throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe')); |
|
| 345 | + } elseif ($postcode) { |
|
| 346 | + $postcode = wc_format_postcode($postcode, $country); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | - if ( $country ) { |
|
| 350 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
| 351 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
| 349 | + if ($country) { |
|
| 350 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
| 351 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
| 352 | 352 | } else { |
| 353 | 353 | WC()->customer->set_to_base(); |
| 354 | 354 | WC()->customer->set_shipping_to_base(); |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - WC()->customer->calculated_shipping( true ); |
|
| 357 | + WC()->customer->calculated_shipping(true); |
|
| 358 | 358 | |
| 359 | 359 | /** |
| 360 | 360 | * Set the shipping package. |
@@ -376,17 +376,17 @@ discard block |
||
| 376 | 376 | $packages[0]['destination']['postcode'] = $postcode; |
| 377 | 377 | $packages[0]['destination']['city'] = $city; |
| 378 | 378 | |
| 379 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
| 380 | - if ( $item['data']->needs_shipping() ) { |
|
| 381 | - if ( isset( $item['line_total'] ) ) { |
|
| 379 | + foreach (WC()->cart->get_cart() as $item) { |
|
| 380 | + if ($item['data']->needs_shipping()) { |
|
| 381 | + if (isset($item['line_total'])) { |
|
| 382 | 382 | $packages[0]['contents_cost'] += $item['line_total']; |
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
| 387 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
| 388 | 388 | |
| 389 | - WC()->shipping->calculate_shipping( $packages ); |
|
| 389 | + WC()->shipping->calculate_shipping($packages); |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | /** |
@@ -396,18 +396,18 @@ discard block |
||
| 396 | 396 | * @version 3.1.0 |
| 397 | 397 | */ |
| 398 | 398 | public function get_shipping_methods() { |
| 399 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) { |
|
| 400 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 399 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) { |
|
| 400 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 404 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 403 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 404 | + define('WOOCOMMERCE_CART', true); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | try { |
| 408 | - $address = array_map( 'wc_clean', $_POST['address'] ); |
|
| 408 | + $address = array_map('wc_clean', $_POST['address']); |
|
| 409 | 409 | |
| 410 | - $this->calculate_shipping( $address ); |
|
| 410 | + $this->calculate_shipping($address); |
|
| 411 | 411 | |
| 412 | 412 | // Set the shipping options. |
| 413 | 413 | $currency = get_woocommerce_currency(); |
@@ -415,13 +415,13 @@ discard block |
||
| 415 | 415 | |
| 416 | 416 | $packages = WC()->shipping->get_packages(); |
| 417 | 417 | |
| 418 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
| 419 | - foreach ( $packages as $package_key => $package ) { |
|
| 420 | - if ( empty( $package['rates'] ) ) { |
|
| 421 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 418 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
| 419 | + foreach ($packages as $package_key => $package) { |
|
| 420 | + if (empty($package['rates'])) { |
|
| 421 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 422 | 422 | } |
| 423 | 423 | |
| 424 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 424 | + foreach ($package['rates'] as $key => $rate) { |
|
| 425 | 425 | $data[] = array( |
| 426 | 426 | 'id' => $rate->id, |
| 427 | 427 | 'label' => $rate->label, |
@@ -435,16 +435,16 @@ discard block |
||
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | // Auto select the first shipping method. |
| 438 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
| 438 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
| 439 | 439 | |
| 440 | 440 | WC()->cart->calculate_totals(); |
| 441 | 441 | |
| 442 | - wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 442 | + wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 443 | 443 | } else { |
| 444 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 444 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 445 | 445 | } |
| 446 | - } catch ( Exception $e ) { |
|
| 447 | - wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 446 | + } catch (Exception $e) { |
|
| 447 | + wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 448 | 448 | } |
| 449 | 449 | } |
| 450 | 450 | |
@@ -455,29 +455,29 @@ discard block |
||
| 455 | 455 | * @version 3.1.0 |
| 456 | 456 | */ |
| 457 | 457 | public function update_shipping_method() { |
| 458 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 459 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 458 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 459 | + define('WOOCOMMERCE_CART', true); |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) { |
|
| 463 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 462 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) { |
|
| 463 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | - $selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] ); |
|
| 466 | + $selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']); |
|
| 467 | 467 | |
| 468 | - WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) ); |
|
| 468 | + WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier'])); |
|
| 469 | 469 | |
| 470 | 470 | WC()->cart->calculate_totals(); |
| 471 | 471 | |
| 472 | 472 | // Send back the new cart total. |
| 473 | 473 | $currency = get_woocommerce_currency(); |
| 474 | - $tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) ); |
|
| 474 | + $tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp)); |
|
| 475 | 475 | $data = array( |
| 476 | 476 | 'total' => WC()->cart->total, |
| 477 | 477 | ); |
| 478 | 478 | |
| 479 | 479 | // Include fees and taxes as displayItems. |
| 480 | - foreach ( WC()->cart->fees as $key => $fee ) { |
|
| 480 | + foreach (WC()->cart->fees as $key => $fee) { |
|
| 481 | 481 | $data['items'][] = array( |
| 482 | 482 | 'label' => $fee->name, |
| 483 | 483 | 'amount' => array( |
@@ -486,9 +486,9 @@ discard block |
||
| 486 | 486 | ), |
| 487 | 487 | ); |
| 488 | 488 | } |
| 489 | - if ( 0 < $tax_total ) { |
|
| 489 | + if (0 < $tax_total) { |
|
| 490 | 490 | $data['items'][] = array( |
| 491 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 491 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 492 | 492 | 'amount' => array( |
| 493 | 493 | 'currency' => $currency, |
| 494 | 494 | 'value' => $tax_total, |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | ); |
| 497 | 497 | } |
| 498 | 498 | |
| 499 | - wp_send_json( array( 'success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 499 | + wp_send_json(array('success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | /** |
@@ -507,37 +507,37 @@ discard block |
||
| 507 | 507 | * @version 3.1.0 |
| 508 | 508 | */ |
| 509 | 509 | public function process_apple_pay() { |
| 510 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) { |
|
| 511 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 510 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) { |
|
| 511 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | try { |
| 515 | - $result = array_map( 'wc_clean', $_POST['result'] ); |
|
| 515 | + $result = array_map('wc_clean', $_POST['result']); |
|
| 516 | 516 | |
| 517 | - $order = $this->create_order( $result ); |
|
| 517 | + $order = $this->create_order($result); |
|
| 518 | 518 | |
| 519 | - $order_id = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->id : $order->get_id(); |
|
| 519 | + $order_id = version_compare(WC_VERSION, '2.7.0', '<') ? $order->id : $order->get_id(); |
|
| 520 | 520 | |
| 521 | 521 | // Handle payment. |
| 522 | - if ( $order->get_total() > 0 ) { |
|
| 522 | + if ($order->get_total() > 0) { |
|
| 523 | 523 | |
| 524 | - if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) { |
|
| 525 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) ); |
|
| 524 | + if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) { |
|
| 525 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100))); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | - WC_Stripe::log( "Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}" ); |
|
| 528 | + WC_Stripe::log("Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}"); |
|
| 529 | 529 | |
| 530 | 530 | // Make the request. |
| 531 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) ); |
|
| 531 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id'])); |
|
| 532 | 532 | |
| 533 | - if ( is_wp_error( $response ) ) { |
|
| 533 | + if (is_wp_error($response)) { |
|
| 534 | 534 | $localized_messages = $this->get_localized_messages(); |
| 535 | 535 | |
| 536 | - throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) ); |
|
| 536 | + throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message())); |
|
| 537 | 537 | } |
| 538 | 538 | |
| 539 | 539 | // Process valid response. |
| 540 | - $this->process_response( $response, $order ); |
|
| 540 | + $this->process_response($response, $order); |
|
| 541 | 541 | } else { |
| 542 | 542 | $order->payment_complete(); |
| 543 | 543 | } |
@@ -545,24 +545,24 @@ discard block |
||
| 545 | 545 | // Remove cart. |
| 546 | 546 | WC()->cart->empty_cart(); |
| 547 | 547 | |
| 548 | - update_post_meta( $order_id, '_customer_user', get_current_user_id() ); |
|
| 549 | - update_post_meta( $order_id, '_payment_method_title', __( 'Apple Pay (Stripe)', 'woocommerce-gateway-stripe' ) ); |
|
| 548 | + update_post_meta($order_id, '_customer_user', get_current_user_id()); |
|
| 549 | + update_post_meta($order_id, '_payment_method_title', __('Apple Pay (Stripe)', 'woocommerce-gateway-stripe')); |
|
| 550 | 550 | |
| 551 | 551 | // Return thank you page redirect. |
| 552 | - wp_send_json( array( |
|
| 552 | + wp_send_json(array( |
|
| 553 | 553 | 'success' => 'true', |
| 554 | - 'redirect' => $this->get_return_url( $order ), |
|
| 555 | - ) ); |
|
| 554 | + 'redirect' => $this->get_return_url($order), |
|
| 555 | + )); |
|
| 556 | 556 | |
| 557 | - } catch ( Exception $e ) { |
|
| 558 | - WC()->session->set( 'refresh_totals', true ); |
|
| 559 | - WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
| 557 | + } catch (Exception $e) { |
|
| 558 | + WC()->session->set('refresh_totals', true); |
|
| 559 | + WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
| 560 | 560 | |
| 561 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 562 | - $this->send_failed_order_email( $order_id ); |
|
| 561 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 562 | + $this->send_failed_order_email($order_id); |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | - wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) ); |
|
| 565 | + wp_send_json(array('success' => 'false', 'msg' => $e->getMessage())); |
|
| 566 | 566 | } |
| 567 | 567 | } |
| 568 | 568 | |
@@ -572,16 +572,16 @@ discard block |
||
| 572 | 572 | * @param string $source token |
| 573 | 573 | * @return array() |
| 574 | 574 | */ |
| 575 | - protected function generate_payment_request( $order, $source ) { |
|
| 575 | + protected function generate_payment_request($order, $source) { |
|
| 576 | 576 | $post_data = array(); |
| 577 | - $post_data['currency'] = strtolower( version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->get_order_currency() : $order->get_currency() ); |
|
| 578 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
| 579 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() ); |
|
| 577 | + $post_data['currency'] = strtolower(version_compare(WC_VERSION, '2.7.0', '<') ? $order->get_order_currency() : $order->get_currency()); |
|
| 578 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
| 579 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number()); |
|
| 580 | 580 | $post_data['capture'] = 'yes' === $this->_gateway_settings['capture'] ? 'true' : 'false'; |
| 581 | 581 | |
| 582 | - $billing_email = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->billing_email : $order->get_billing_email(); |
|
| 582 | + $billing_email = version_compare(WC_VERSION, '2.7.0', '<') ? $order->billing_email : $order->get_billing_email(); |
|
| 583 | 583 | |
| 584 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
| 584 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
| 585 | 585 | $post_data['receipt_email'] = $billing_email; |
| 586 | 586 | } |
| 587 | 587 | |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | * @param WC_Order $order |
| 597 | 597 | * @param object $source |
| 598 | 598 | */ |
| 599 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order ); |
|
| 599 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order); |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | /** |
@@ -605,14 +605,14 @@ discard block |
||
| 605 | 605 | * @since 3.1.0 |
| 606 | 606 | * @version 3.1.0 |
| 607 | 607 | */ |
| 608 | - public function build_shipping_methods( $shipping_methods ) { |
|
| 609 | - if ( empty( $shipping_methods ) ) { |
|
| 608 | + public function build_shipping_methods($shipping_methods) { |
|
| 609 | + if (empty($shipping_methods)) { |
|
| 610 | 610 | return array(); |
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | $shipping = array(); |
| 614 | 614 | |
| 615 | - foreach ( $shipping_methods as $method ) { |
|
| 615 | + foreach ($shipping_methods as $method) { |
|
| 616 | 616 | $shipping[] = array( |
| 617 | 617 | 'label' => $method['label'], |
| 618 | 618 | 'detail' => '', |
@@ -631,53 +631,53 @@ discard block |
||
| 631 | 631 | * @version 3.1.0 |
| 632 | 632 | */ |
| 633 | 633 | public function build_line_items() { |
| 634 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 635 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 634 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 635 | + define('WOOCOMMERCE_CART', true); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | - $decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 ); |
|
| 638 | + $decimals = apply_filters('wc_stripe_apple_pay_decimals', 2); |
|
| 639 | 639 | |
| 640 | 640 | $items = array(); |
| 641 | 641 | |
| 642 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 643 | - $amount = wc_format_decimal( $values['line_subtotal'], $decimals ); |
|
| 642 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
| 643 | + $amount = wc_format_decimal($values['line_subtotal'], $decimals); |
|
| 644 | 644 | $quantity_label = 1 < $values['quantity'] ? ' (x' . $values['quantity'] . ')' : ''; |
| 645 | 645 | |
| 646 | 646 | $item = array( |
| 647 | 647 | 'type' => 'final', |
| 648 | 648 | 'label' => $values['data']->post->post_title . $quantity_label, |
| 649 | - 'amount' => wc_format_decimal( $amount, $decimals ), |
|
| 649 | + 'amount' => wc_format_decimal($amount, $decimals), |
|
| 650 | 650 | ); |
| 651 | 651 | |
| 652 | 652 | $items[] = $item; |
| 653 | 653 | } |
| 654 | 654 | |
| 655 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals ); |
|
| 656 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals ); |
|
| 657 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, $decimals ); |
|
| 658 | - $item_total = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts; |
|
| 659 | - $order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals ); |
|
| 655 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals); |
|
| 656 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals); |
|
| 657 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, $decimals); |
|
| 658 | + $item_total = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts; |
|
| 659 | + $order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals); |
|
| 660 | 660 | |
| 661 | - if ( wc_tax_enabled() ) { |
|
| 661 | + if (wc_tax_enabled()) { |
|
| 662 | 662 | $items[] = array( |
| 663 | 663 | 'type' => 'final', |
| 664 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 664 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 665 | 665 | 'amount' => $tax, |
| 666 | 666 | ); |
| 667 | 667 | } |
| 668 | 668 | |
| 669 | - if ( WC()->cart->needs_shipping() ) { |
|
| 669 | + if (WC()->cart->needs_shipping()) { |
|
| 670 | 670 | $items[] = array( |
| 671 | 671 | 'type' => 'final', |
| 672 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
| 672 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
| 673 | 673 | 'amount' => $shipping, |
| 674 | 674 | ); |
| 675 | 675 | } |
| 676 | 676 | |
| 677 | - if ( WC()->cart->has_discount() ) { |
|
| 677 | + if (WC()->cart->has_discount()) { |
|
| 678 | 678 | $items[] = array( |
| 679 | 679 | 'type' => 'final', |
| 680 | - 'label' => __( 'Discount', 'woocommerce-gateway-stripe' ), |
|
| 680 | + 'label' => __('Discount', 'woocommerce-gateway-stripe'), |
|
| 681 | 681 | 'amount' => $discounts, |
| 682 | 682 | ); |
| 683 | 683 | } |
@@ -693,24 +693,24 @@ discard block |
||
| 693 | 693 | * @param array $data |
| 694 | 694 | * @return object $order |
| 695 | 695 | */ |
| 696 | - public function create_order( $data = array() ) { |
|
| 697 | - if ( empty( $data ) ) { |
|
| 698 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
| 696 | + public function create_order($data = array()) { |
|
| 697 | + if (empty($data)) { |
|
| 698 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | $order = wc_create_order(); |
| 702 | - $order_id = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->id : $order->get_id(); |
|
| 702 | + $order_id = version_compare(WC_VERSION, '2.7.0', '<') ? $order->id : $order->get_id(); |
|
| 703 | 703 | |
| 704 | - if ( is_wp_error( $order ) ) { |
|
| 705 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
| 706 | - } elseif ( false === $order ) { |
|
| 707 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) ); |
|
| 704 | + if (is_wp_error($order)) { |
|
| 705 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
| 706 | + } elseif (false === $order) { |
|
| 707 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521)); |
|
| 708 | 708 | } else { |
| 709 | - do_action( 'woocommerce_new_order', $order_id ); |
|
| 709 | + do_action('woocommerce_new_order', $order_id); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | // Store the line items to the new/resumed order |
| 713 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 713 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
| 714 | 714 | $item_id = $order->add_product( |
| 715 | 715 | $values['data'], |
| 716 | 716 | $values['quantity'], |
@@ -726,47 +726,47 @@ discard block |
||
| 726 | 726 | ) |
| 727 | 727 | ); |
| 728 | 728 | |
| 729 | - if ( ! $item_id ) { |
|
| 730 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) ); |
|
| 729 | + if ( ! $item_id) { |
|
| 730 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525)); |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | // Allow plugins to add order item meta |
| 734 | - do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key ); |
|
| 734 | + do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key); |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | // Store fees |
| 738 | - foreach ( WC()->cart->get_fees() as $fee_key => $fee ) { |
|
| 739 | - $item_id = $order->add_fee( $fee ); |
|
| 738 | + foreach (WC()->cart->get_fees() as $fee_key => $fee) { |
|
| 739 | + $item_id = $order->add_fee($fee); |
|
| 740 | 740 | |
| 741 | - if ( ! $item_id ) { |
|
| 742 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) ); |
|
| 741 | + if ( ! $item_id) { |
|
| 742 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526)); |
|
| 743 | 743 | } |
| 744 | 744 | |
| 745 | 745 | // Allow plugins to add order item meta to fees |
| 746 | - do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key ); |
|
| 746 | + do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key); |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | // Store tax rows |
| 750 | - foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) { |
|
| 751 | - if ( $tax_rate_id && ! $order->add_tax( $tax_rate_id, WC()->cart->get_tax_amount( $tax_rate_id ), WC()->cart->get_shipping_tax_amount( $tax_rate_id ) ) && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) { |
|
| 752 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) ); |
|
| 750 | + foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) { |
|
| 751 | + if ($tax_rate_id && ! $order->add_tax($tax_rate_id, WC()->cart->get_tax_amount($tax_rate_id), WC()->cart->get_shipping_tax_amount($tax_rate_id)) && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) { |
|
| 752 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528)); |
|
| 753 | 753 | } |
| 754 | 754 | } |
| 755 | 755 | |
| 756 | 756 | // Store coupons |
| 757 | - foreach ( WC()->cart->get_coupons() as $code => $coupon ) { |
|
| 758 | - if ( ! $order->add_coupon( $code, WC()->cart->get_coupon_discount_amount( $code ), WC()->cart->get_coupon_discount_tax_amount( $code ) ) ) { |
|
| 759 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) ); |
|
| 757 | + foreach (WC()->cart->get_coupons() as $code => $coupon) { |
|
| 758 | + if ( ! $order->add_coupon($code, WC()->cart->get_coupon_discount_amount($code), WC()->cart->get_coupon_discount_tax_amount($code))) { |
|
| 759 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529)); |
|
| 760 | 760 | } |
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | // Billing address |
| 764 | 764 | $billing_address = array(); |
| 765 | - if ( ! empty( $data['token']['card'] ) ) { |
|
| 765 | + if ( ! empty($data['token']['card'])) { |
|
| 766 | 766 | // Name from Stripe is a full name string. |
| 767 | - $name = explode( ' ', $data['token']['card']['name'] ); |
|
| 768 | - $lastname = array_pop( $name ); |
|
| 769 | - $firstname = implode( ' ', $name ); |
|
| 767 | + $name = explode(' ', $data['token']['card']['name']); |
|
| 768 | + $lastname = array_pop($name); |
|
| 769 | + $firstname = implode(' ', $name); |
|
| 770 | 770 | $billing_address['first_name'] = $firstname; |
| 771 | 771 | $billing_address['last_name'] = $lastname; |
| 772 | 772 | $billing_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -781,7 +781,7 @@ discard block |
||
| 781 | 781 | |
| 782 | 782 | // Shipping address. |
| 783 | 783 | $shipping_address = array(); |
| 784 | - if ( WC()->cart->needs_shipping() && ! empty( $data['shippingContact'] ) ) { |
|
| 784 | + if (WC()->cart->needs_shipping() && ! empty($data['shippingContact'])) { |
|
| 785 | 785 | $shipping_address['first_name'] = $data['shippingContact']['givenName']; |
| 786 | 786 | $shipping_address['last_name'] = $data['shippingContact']['familyName']; |
| 787 | 787 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -792,7 +792,7 @@ discard block |
||
| 792 | 792 | $shipping_address['city'] = $data['shippingContact']['locality']; |
| 793 | 793 | $shipping_address['state'] = $data['shippingContact']['administrativeArea']; |
| 794 | 794 | $shipping_address['postcode'] = $data['shippingContact']['postalCode']; |
| 795 | - } elseif ( ! empty( $data['shippingContact'] ) ) { |
|
| 795 | + } elseif ( ! empty($data['shippingContact'])) { |
|
| 796 | 796 | $shipping_address['first_name'] = $firstname; |
| 797 | 797 | $shipping_address['last_name'] = $lastname; |
| 798 | 798 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -805,34 +805,34 @@ discard block |
||
| 805 | 805 | $shipping_address['postcode'] = $data['token']['card']['address_zip']; |
| 806 | 806 | } |
| 807 | 807 | |
| 808 | - $order->set_address( $billing_address, 'billing' ); |
|
| 809 | - $order->set_address( $shipping_address, 'shipping' ); |
|
| 808 | + $order->set_address($billing_address, 'billing'); |
|
| 809 | + $order->set_address($shipping_address, 'shipping'); |
|
| 810 | 810 | |
| 811 | - WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() ); |
|
| 811 | + WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages()); |
|
| 812 | 812 | |
| 813 | 813 | // Get the rate object selected by user. |
| 814 | - foreach ( WC()->shipping->get_packages() as $package_key => $package ) { |
|
| 815 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 814 | + foreach (WC()->shipping->get_packages() as $package_key => $package) { |
|
| 815 | + foreach ($package['rates'] as $key => $rate) { |
|
| 816 | 816 | // Loop through user chosen shipping methods. |
| 817 | - foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) { |
|
| 818 | - if ( $method === $key ) { |
|
| 819 | - $order->add_shipping( $rate ); |
|
| 817 | + foreach (WC()->session->get('chosen_shipping_methods') as $method) { |
|
| 818 | + if ($method === $key) { |
|
| 819 | + $order->add_shipping($rate); |
|
| 820 | 820 | } |
| 821 | 821 | } |
| 822 | 822 | } |
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 826 | - $order->set_payment_method( $available_gateways['stripe'] ); |
|
| 827 | - $order->set_total( WC()->cart->shipping_total, 'shipping' ); |
|
| 828 | - $order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' ); |
|
| 829 | - $order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' ); |
|
| 830 | - $order->set_total( WC()->cart->tax_total, 'tax' ); |
|
| 831 | - $order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' ); |
|
| 832 | - $order->set_total( WC()->cart->total ); |
|
| 826 | + $order->set_payment_method($available_gateways['stripe']); |
|
| 827 | + $order->set_total(WC()->cart->shipping_total, 'shipping'); |
|
| 828 | + $order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount'); |
|
| 829 | + $order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax'); |
|
| 830 | + $order->set_total(WC()->cart->tax_total, 'tax'); |
|
| 831 | + $order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax'); |
|
| 832 | + $order->set_total(WC()->cart->total); |
|
| 833 | 833 | |
| 834 | 834 | // If we got here, the order was created without problems! |
| 835 | - wc_transaction_query( 'commit' ); |
|
| 835 | + wc_transaction_query('commit'); |
|
| 836 | 836 | |
| 837 | 837 | return $order; |
| 838 | 838 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -16,22 +16,22 @@ discard block |
||
| 16 | 16 | public function __construct() { |
| 17 | 17 | parent::__construct(); |
| 18 | 18 | |
| 19 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
| 20 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
| 21 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
| 22 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
| 23 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
| 19 | + if (class_exists('WC_Subscriptions_Order')) { |
|
| 20 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
| 21 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
| 22 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
| 23 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
| 24 | 24 | |
| 25 | 25 | // display the credit card used for a subscription in the "My Subscriptions" table |
| 26 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
| 26 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
| 27 | 27 | |
| 28 | 28 | // allow store managers to manually set Stripe as the payment method on a subscription |
| 29 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
| 30 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
| 29 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
| 30 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
| 34 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) ); |
|
| 33 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
| 34 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment')); |
|
| 35 | 35 | } |
| 36 | 36 | } |
| 37 | 37 | |
@@ -40,8 +40,8 @@ discard block |
||
| 40 | 40 | * @param int $order_id |
| 41 | 41 | * @return boolean |
| 42 | 42 | */ |
| 43 | - protected function is_subscription( $order_id ) { |
|
| 44 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
| 43 | + protected function is_subscription($order_id) { |
|
| 44 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | * @param int $order_id |
| 50 | 50 | * @return boolean |
| 51 | 51 | */ |
| 52 | - protected function is_pre_order( $order_id ) { |
|
| 53 | - return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
| 52 | + protected function is_pre_order($order_id) { |
|
| 53 | + return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -58,39 +58,39 @@ discard block |
||
| 58 | 58 | * @param int $order_id |
| 59 | 59 | * @return array |
| 60 | 60 | */ |
| 61 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
| 62 | - if ( $this->is_subscription( $order_id ) ) { |
|
| 61 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
| 62 | + if ($this->is_subscription($order_id)) { |
|
| 63 | 63 | // Regular payment with force customer enabled |
| 64 | - return parent::process_payment( $order_id, true, true ); |
|
| 64 | + return parent::process_payment($order_id, true, true); |
|
| 65 | 65 | |
| 66 | - } elseif ( $this->is_pre_order( $order_id ) ) { |
|
| 67 | - return $this->process_pre_order( $order_id, $retry, $force_customer ); |
|
| 66 | + } elseif ($this->is_pre_order($order_id)) { |
|
| 67 | + return $this->process_pre_order($order_id, $retry, $force_customer); |
|
| 68 | 68 | |
| 69 | 69 | } else { |
| 70 | - return parent::process_payment( $order_id, $retry, $force_customer ); |
|
| 70 | + return parent::process_payment($order_id, $retry, $force_customer); |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * Updates other subscription sources. |
| 76 | 76 | */ |
| 77 | - protected function save_source( $order, $source ) { |
|
| 78 | - parent::save_source( $order, $source ); |
|
| 77 | + protected function save_source($order, $source) { |
|
| 78 | + parent::save_source($order, $source); |
|
| 79 | 79 | |
| 80 | - $order_id = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->id : $order->get_id(); |
|
| 80 | + $order_id = version_compare(WC_VERSION, '2.7.0', '<') ? $order->id : $order->get_id(); |
|
| 81 | 81 | |
| 82 | 82 | // Also store it on the subscriptions being purchased or paid for in the order |
| 83 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
| 84 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
| 85 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
| 86 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
| 83 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
| 84 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
| 85 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
| 86 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
| 87 | 87 | } else { |
| 88 | 88 | $subscriptions = array(); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - foreach ( $subscriptions as $subscription ) { |
|
| 92 | - update_post_meta( $subscription->id, '_stripe_customer_id', $source->customer ); |
|
| 93 | - update_post_meta( $subscription->id, '_stripe_card_id', $source->source ); |
|
| 91 | + foreach ($subscriptions as $subscription) { |
|
| 92 | + update_post_meta($subscription->id, '_stripe_customer_id', $source->customer); |
|
| 93 | + update_post_meta($subscription->id, '_stripe_card_id', $source->source); |
|
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | |
@@ -101,39 +101,39 @@ discard block |
||
| 101 | 101 | * @param string $stripe_token (default: '') |
| 102 | 102 | * @param bool initial_payment |
| 103 | 103 | */ |
| 104 | - public function process_subscription_payment( $order = '', $amount = 0 ) { |
|
| 105 | - if ( $amount * 100 < WC_Stripe::get_minimum_amount() ) { |
|
| 106 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) ); |
|
| 104 | + public function process_subscription_payment($order = '', $amount = 0) { |
|
| 105 | + if ($amount * 100 < WC_Stripe::get_minimum_amount()) { |
|
| 106 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100))); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | // Get source from order |
| 110 | - $source = $this->get_order_source( $order ); |
|
| 110 | + $source = $this->get_order_source($order); |
|
| 111 | 111 | |
| 112 | 112 | // If no order source was defined, use user source instead. |
| 113 | - if ( ! $source->customer ) { |
|
| 114 | - $source = $this->get_source( $order->customer_user ); |
|
| 113 | + if ( ! $source->customer) { |
|
| 114 | + $source = $this->get_source($order->customer_user); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | // Or fail :( |
| 118 | - if ( ! $source->customer ) { |
|
| 119 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
| 118 | + if ( ! $source->customer) { |
|
| 119 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - $order_id = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->id : $order->get_id(); |
|
| 123 | - $this->log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
| 122 | + $order_id = version_compare(WC_VERSION, '2.7.0', '<') ? $order->id : $order->get_id(); |
|
| 123 | + $this->log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
| 124 | 124 | |
| 125 | 125 | // Make the request |
| 126 | - $request = $this->generate_payment_request( $order, $source ); |
|
| 126 | + $request = $this->generate_payment_request($order, $source); |
|
| 127 | 127 | $request['capture'] = 'true'; |
| 128 | - $request['amount'] = $this->get_stripe_amount( $amount, $request['currency'] ); |
|
| 128 | + $request['amount'] = $this->get_stripe_amount($amount, $request['currency']); |
|
| 129 | 129 | $request['metadata'] = array( |
| 130 | 130 | 'payment_type' => 'recurring', |
| 131 | 131 | ); |
| 132 | - $response = WC_Stripe_API::request( $request ); |
|
| 132 | + $response = WC_Stripe_API::request($request); |
|
| 133 | 133 | |
| 134 | 134 | // Process valid response |
| 135 | - if ( ! is_wp_error( $response ) ) { |
|
| 136 | - $this->process_response( $response, $order ); |
|
| 135 | + if ( ! is_wp_error($response)) { |
|
| 136 | + $this->process_response($response, $order); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | return $response; |
@@ -144,42 +144,42 @@ discard block |
||
| 144 | 144 | * @param int $order_id |
| 145 | 145 | * @return array |
| 146 | 146 | */ |
| 147 | - public function process_pre_order( $order_id, $retry, $force_customer ) { |
|
| 148 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
| 147 | + public function process_pre_order($order_id, $retry, $force_customer) { |
|
| 148 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
| 149 | 149 | try { |
| 150 | - $order = wc_get_order( $order_id ); |
|
| 150 | + $order = wc_get_order($order_id); |
|
| 151 | 151 | |
| 152 | - if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) { |
|
| 153 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) ); |
|
| 152 | + if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) { |
|
| 153 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100))); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - $source = $this->get_source( get_current_user_id(), true ); |
|
| 156 | + $source = $this->get_source(get_current_user_id(), true); |
|
| 157 | 157 | |
| 158 | 158 | // We need a source on file to continue. |
| 159 | - if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
| 160 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
| 159 | + if (empty($source->customer) || empty($source->source)) { |
|
| 160 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // Store source to order meta |
| 164 | - $this->save_source( $order, $source ); |
|
| 164 | + $this->save_source($order, $source); |
|
| 165 | 165 | |
| 166 | 166 | // Remove cart |
| 167 | 167 | WC()->cart->empty_cart(); |
| 168 | 168 | |
| 169 | 169 | // Is pre ordered! |
| 170 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
| 170 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
| 171 | 171 | |
| 172 | 172 | // Return thank you page redirect |
| 173 | 173 | return array( |
| 174 | 174 | 'result' => 'success', |
| 175 | - 'redirect' => $this->get_return_url( $order ), |
|
| 175 | + 'redirect' => $this->get_return_url($order), |
|
| 176 | 176 | ); |
| 177 | - } catch ( Exception $e ) { |
|
| 178 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 177 | + } catch (Exception $e) { |
|
| 178 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 179 | 179 | return; |
| 180 | 180 | } |
| 181 | 181 | } else { |
| 182 | - return parent::process_payment( $order_id, $retry, $force_customer ); |
|
| 182 | + return parent::process_payment($order_id, $retry, $force_customer); |
|
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | * @param WC_Order $order |
| 189 | 189 | * @return void |
| 190 | 190 | */ |
| 191 | - public function process_pre_order_release_payment( $order ) { |
|
| 191 | + public function process_pre_order_release_payment($order) { |
|
| 192 | 192 | try { |
| 193 | 193 | // Define some callbacks if the first attempt fails. |
| 194 | 194 | $retry_callbacks = array( |
@@ -196,32 +196,32 @@ discard block |
||
| 196 | 196 | 'remove_order_customer_before_retry', |
| 197 | 197 | ); |
| 198 | 198 | |
| 199 | - while ( 1 ) { |
|
| 200 | - $source = $this->get_order_source( $order ); |
|
| 201 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
| 199 | + while (1) { |
|
| 200 | + $source = $this->get_order_source($order); |
|
| 201 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
| 202 | 202 | |
| 203 | - if ( is_wp_error( $response ) ) { |
|
| 204 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
| 205 | - throw new Exception( $response->get_error_message() ); |
|
| 203 | + if (is_wp_error($response)) { |
|
| 204 | + if (0 === sizeof($retry_callbacks)) { |
|
| 205 | + throw new Exception($response->get_error_message()); |
|
| 206 | 206 | } else { |
| 207 | - $retry_callback = array_shift( $retry_callbacks ); |
|
| 208 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
| 207 | + $retry_callback = array_shift($retry_callbacks); |
|
| 208 | + call_user_func(array($this, $retry_callback), $order); |
|
| 209 | 209 | } |
| 210 | 210 | } else { |
| 211 | 211 | // Successful |
| 212 | - $this->process_response( $response, $order ); |
|
| 212 | + $this->process_response($response, $order); |
|
| 213 | 213 | break; |
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | - } catch ( Exception $e ) { |
|
| 217 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
| 216 | + } catch (Exception $e) { |
|
| 217 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
| 218 | 218 | |
| 219 | 219 | // Mark order as failed if not already set, |
| 220 | 220 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
| 221 | - if ( ! $order->has_status( 'failed' ) ) { |
|
| 222 | - $order->update_status( 'failed', $order_note ); |
|
| 221 | + if ( ! $order->has_status('failed')) { |
|
| 222 | + $order->update_status('failed', $order_note); |
|
| 223 | 223 | } else { |
| 224 | - $order->add_order_note( $order_note ); |
|
| 224 | + $order->add_order_note($order_note); |
|
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | } |
@@ -230,20 +230,20 @@ discard block |
||
| 230 | 230 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
| 231 | 231 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 232 | 232 | */ |
| 233 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
| 234 | - delete_post_meta( $resubscribe_order->id, '_stripe_customer_id' ); |
|
| 235 | - delete_post_meta( $resubscribe_order->id, '_stripe_card_id' ); |
|
| 236 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
| 233 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
| 234 | + delete_post_meta($resubscribe_order->id, '_stripe_customer_id'); |
|
| 235 | + delete_post_meta($resubscribe_order->id, '_stripe_card_id'); |
|
| 236 | + $this->delete_renewal_meta($resubscribe_order); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
| 240 | 240 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 241 | 241 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 242 | 242 | */ |
| 243 | - public function delete_renewal_meta( $renewal_order ) { |
|
| 244 | - delete_post_meta( $renewal_order->id, 'Stripe Fee' ); |
|
| 245 | - delete_post_meta( $renewal_order->id, 'Net Revenue From Stripe' ); |
|
| 246 | - delete_post_meta( $renewal_order->id, 'Stripe Payment ID' ); |
|
| 243 | + public function delete_renewal_meta($renewal_order) { |
|
| 244 | + delete_post_meta($renewal_order->id, 'Stripe Fee'); |
|
| 245 | + delete_post_meta($renewal_order->id, 'Net Revenue From Stripe'); |
|
| 246 | + delete_post_meta($renewal_order->id, 'Stripe Payment ID'); |
|
| 247 | 247 | return $renewal_order; |
| 248 | 248 | } |
| 249 | 249 | |
@@ -253,11 +253,11 @@ discard block |
||
| 253 | 253 | * @param $amount_to_charge float The amount to charge. |
| 254 | 254 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
| 255 | 255 | */ |
| 256 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
| 257 | - $response = $this->process_subscription_payment( $renewal_order, $amount_to_charge ); |
|
| 256 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
| 257 | + $response = $this->process_subscription_payment($renewal_order, $amount_to_charge); |
|
| 258 | 258 | |
| 259 | - if ( is_wp_error( $response ) ) { |
|
| 260 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
| 259 | + if (is_wp_error($response)) { |
|
| 260 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
| 261 | 261 | } |
| 262 | 262 | } |
| 263 | 263 | |
@@ -265,18 +265,18 @@ discard block |
||
| 265 | 265 | * Remove order meta |
| 266 | 266 | * @param object $order |
| 267 | 267 | */ |
| 268 | - public function remove_order_source_before_retry( $order ) { |
|
| 269 | - $order_id = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->id : $order->get_id(); |
|
| 270 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
| 268 | + public function remove_order_source_before_retry($order) { |
|
| 269 | + $order_id = version_compare(WC_VERSION, '2.7.0', '<') ? $order->id : $order->get_id(); |
|
| 270 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
| 274 | 274 | * Remove order meta |
| 275 | 275 | * @param object $order |
| 276 | 276 | */ |
| 277 | - public function remove_order_customer_before_retry( $order ) { |
|
| 278 | - $order_id = version_compare( WC_VERSION, '2.7.0', '<' ) ? $order->id : $order->get_id(); |
|
| 279 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 277 | + public function remove_order_customer_before_retry($order) { |
|
| 278 | + $order_id = version_compare(WC_VERSION, '2.7.0', '<') ? $order->id : $order->get_id(); |
|
| 279 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | /** |
@@ -288,9 +288,9 @@ discard block |
||
| 288 | 288 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
| 289 | 289 | * @return void |
| 290 | 290 | */ |
| 291 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
| 292 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
| 293 | - update_post_meta( $subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id ); |
|
| 291 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
| 292 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
| 293 | + update_post_meta($subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | /** |
@@ -302,15 +302,15 @@ discard block |
||
| 302 | 302 | * @param WC_Subscription $subscription An instance of a subscription object |
| 303 | 303 | * @return array |
| 304 | 304 | */ |
| 305 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
| 306 | - $payment_meta[ $this->id ] = array( |
|
| 305 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
| 306 | + $payment_meta[$this->id] = array( |
|
| 307 | 307 | 'post_meta' => array( |
| 308 | 308 | '_stripe_customer_id' => array( |
| 309 | - 'value' => get_post_meta( $subscription->id, '_stripe_customer_id', true ), |
|
| 309 | + 'value' => get_post_meta($subscription->id, '_stripe_customer_id', true), |
|
| 310 | 310 | 'label' => 'Stripe Customer ID', |
| 311 | 311 | ), |
| 312 | 312 | '_stripe_card_id' => array( |
| 313 | - 'value' => get_post_meta( $subscription->id, '_stripe_card_id', true ), |
|
| 313 | + 'value' => get_post_meta($subscription->id, '_stripe_card_id', true), |
|
| 314 | 314 | 'label' => 'Stripe Card ID', |
| 315 | 315 | ), |
| 316 | 316 | ), |
@@ -327,17 +327,17 @@ discard block |
||
| 327 | 327 | * @param array $payment_meta associative array of meta data required for automatic payments |
| 328 | 328 | * @return array |
| 329 | 329 | */ |
| 330 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
| 331 | - if ( $this->id === $payment_method_id ) { |
|
| 330 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
| 331 | + if ($this->id === $payment_method_id) { |
|
| 332 | 332 | |
| 333 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
| 334 | - throw new Exception( 'A "_stripe_customer_id" value is required.' ); |
|
| 335 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
| 336 | - throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' ); |
|
| 333 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
| 334 | + throw new Exception('A "_stripe_customer_id" value is required.'); |
|
| 335 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
| 336 | + throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".'); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | - if ( ! empty( $payment_meta['post_meta']['_stripe_card_id']['value'] ) && 0 !== strpos( $payment_meta['post_meta']['_stripe_card_id']['value'], 'card_' ) ) { |
|
| 340 | - throw new Exception( 'Invalid card ID. A valid "_stripe_card_id" must begin with "card_".' ); |
|
| 339 | + if ( ! empty($payment_meta['post_meta']['_stripe_card_id']['value']) && 0 !== strpos($payment_meta['post_meta']['_stripe_card_id']['value'], 'card_')) { |
|
| 340 | + throw new Exception('Invalid card ID. A valid "_stripe_card_id" must begin with "card_".'); |
|
| 341 | 341 | } |
| 342 | 342 | } |
| 343 | 343 | } |
@@ -350,43 +350,43 @@ discard block |
||
| 350 | 350 | * @param WC_Subscription $subscription the subscription details |
| 351 | 351 | * @return string the subscription payment method |
| 352 | 352 | */ |
| 353 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
| 353 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
| 354 | 354 | // bail for other payment methods |
| 355 | - if ( $this->id !== $subscription->payment_method || ! $subscription->customer_user ) { |
|
| 355 | + if ($this->id !== $subscription->payment_method || ! $subscription->customer_user) { |
|
| 356 | 356 | return $payment_method_to_display; |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | $stripe_customer = new WC_Stripe_Customer(); |
| 360 | - $stripe_customer_id = get_post_meta( $subscription->id, '_stripe_customer_id', true ); |
|
| 361 | - $stripe_card_id = get_post_meta( $subscription->id, '_stripe_card_id', true ); |
|
| 360 | + $stripe_customer_id = get_post_meta($subscription->id, '_stripe_customer_id', true); |
|
| 361 | + $stripe_card_id = get_post_meta($subscription->id, '_stripe_card_id', true); |
|
| 362 | 362 | |
| 363 | 363 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
| 364 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
| 364 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
| 365 | 365 | $user_id = $subscription->customer_user; |
| 366 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
| 367 | - $stripe_card_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
| 366 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
| 367 | + $stripe_card_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
| 371 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
| 372 | - $stripe_customer_id = get_post_meta( $subscription->order->id, '_stripe_customer_id', true ); |
|
| 373 | - $stripe_card_id = get_post_meta( $subscription->order->id, '_stripe_card_id', true ); |
|
| 371 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
| 372 | + $stripe_customer_id = get_post_meta($subscription->order->id, '_stripe_customer_id', true); |
|
| 373 | + $stripe_card_id = get_post_meta($subscription->order->id, '_stripe_card_id', true); |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 376 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 377 | 377 | $cards = $stripe_customer->get_cards(); |
| 378 | 378 | |
| 379 | - if ( $cards ) { |
|
| 379 | + if ($cards) { |
|
| 380 | 380 | $found_card = false; |
| 381 | - foreach ( $cards as $card ) { |
|
| 382 | - if ( $card->id === $stripe_card_id ) { |
|
| 381 | + foreach ($cards as $card) { |
|
| 382 | + if ($card->id === $stripe_card_id) { |
|
| 383 | 383 | $found_card = true; |
| 384 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->type ) ? $card->type : $card->brand ), $card->last4 ); |
|
| 384 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->type) ? $card->type : $card->brand), $card->last4); |
|
| 385 | 385 | break; |
| 386 | 386 | } |
| 387 | 387 | } |
| 388 | - if ( ! $found_card ) { |
|
| 389 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $cards[0]->type ) ? $cards[0]->type : $cards[0]->brand ), $cards[0]->last4 ); |
|
| 388 | + if ( ! $found_card) { |
|
| 389 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($cards[0]->type) ? $cards[0]->type : $cards[0]->brand), $cards[0]->last4); |
|
| 390 | 390 | } |
| 391 | 391 | } |
| 392 | 392 | |
@@ -401,11 +401,11 @@ discard block |
||
| 401 | 401 | * |
| 402 | 402 | * @param string $message |
| 403 | 403 | */ |
| 404 | - public function log( $message ) { |
|
| 405 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
| 404 | + public function log($message) { |
|
| 405 | + $options = get_option('woocommerce_stripe_settings'); |
|
| 406 | 406 | |
| 407 | - if ( 'yes' === $options['logging'] ) { |
|
| 408 | - WC_Stripe::log( $message ); |
|
| 407 | + if ('yes' === $options['logging']) { |
|
| 408 | + WC_Stripe::log($message); |
|
| 409 | 409 | } |
| 410 | 410 | } |
| 411 | 411 | } |