@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -21,8 +21,8 @@ discard block |
||
| 21 | 21 | * @since 4.1.0 |
| 22 | 22 | */ |
| 23 | 23 | public function __construct() { |
| 24 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
| 25 | - add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
| 24 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
| 25 | + add_action('wp_loaded', array($this, 'hide_notices')); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -31,8 +31,8 @@ discard block |
||
| 31 | 31 | * @since 1.0.0 |
| 32 | 32 | * @version 4.0.0 |
| 33 | 33 | */ |
| 34 | - public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
|
| 35 | - $this->notices[ $slug ] = array( |
|
| 34 | + public function add_admin_notice($slug, $class, $message, $dismissible = false) { |
|
| 35 | + $this->notices[$slug] = array( |
|
| 36 | 36 | 'class' => $class, |
| 37 | 37 | 'message' => $message, |
| 38 | 38 | 'dismissible' => $dismissible, |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * @version 4.0.0 |
| 47 | 47 | */ |
| 48 | 48 | public function admin_notices() { |
| 49 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 49 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 50 | 50 | return; |
| 51 | 51 | } |
| 52 | 52 | |
@@ -56,17 +56,17 @@ discard block |
||
| 56 | 56 | // All other payment methods. |
| 57 | 57 | $this->payment_methods_check_environment(); |
| 58 | 58 | |
| 59 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 60 | - echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">'; |
|
| 59 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 60 | + echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">'; |
|
| 61 | 61 | |
| 62 | - if ( $notice['dismissible'] ) { |
|
| 62 | + if ($notice['dismissible']) { |
|
| 63 | 63 | ?> |
| 64 | - <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-stripe-hide-notice', $notice_key ), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce' ) ); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a> |
|
| 64 | + <a href="<?php echo esc_url(wp_nonce_url(add_query_arg('wc-stripe-hide-notice', $notice_key), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce')); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a> |
|
| 65 | 65 | <?php |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | echo '<p>'; |
| 69 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 69 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 70 | 70 | echo '</p></div>'; |
| 71 | 71 | } |
| 72 | 72 | } |
@@ -99,85 +99,85 @@ discard block |
||
| 99 | 99 | * @version 4.0.0 |
| 100 | 100 | */ |
| 101 | 101 | public function stripe_check_environment() { |
| 102 | - $show_ssl_notice = get_option( 'wc_stripe_show_ssl_notice' ); |
|
| 103 | - $show_keys_notice = get_option( 'wc_stripe_show_keys_notice' ); |
|
| 104 | - $show_phpver_notice = get_option( 'wc_stripe_show_phpver_notice' ); |
|
| 105 | - $show_wcver_notice = get_option( 'wc_stripe_show_wcver_notice' ); |
|
| 106 | - $show_curl_notice = get_option( 'wc_stripe_show_curl_notice' ); |
|
| 107 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
| 108 | - $testmode = ( isset( $options['testmode'] ) && 'yes' === $options['testmode'] ) ? true : false; |
|
| 109 | - $test_pub_key = isset( $options['test_publishable_key'] ) ? $options['test_publishable_key'] : ''; |
|
| 110 | - $test_secret_key = isset( $options['test_secret_key'] ) ? $options['test_secret_key'] : ''; |
|
| 111 | - $live_pub_key = isset( $options['publishable_key'] ) ? $options['publishable_key'] : ''; |
|
| 112 | - $live_secret_key = isset( $options['secret_key'] ) ? $options['secret_key'] : ''; |
|
| 113 | - |
|
| 114 | - if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) { |
|
| 115 | - if ( empty( $show_phpver_notice ) ) { |
|
| 116 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
| 102 | + $show_ssl_notice = get_option('wc_stripe_show_ssl_notice'); |
|
| 103 | + $show_keys_notice = get_option('wc_stripe_show_keys_notice'); |
|
| 104 | + $show_phpver_notice = get_option('wc_stripe_show_phpver_notice'); |
|
| 105 | + $show_wcver_notice = get_option('wc_stripe_show_wcver_notice'); |
|
| 106 | + $show_curl_notice = get_option('wc_stripe_show_curl_notice'); |
|
| 107 | + $options = get_option('woocommerce_stripe_settings'); |
|
| 108 | + $testmode = (isset($options['testmode']) && 'yes' === $options['testmode']) ? true : false; |
|
| 109 | + $test_pub_key = isset($options['test_publishable_key']) ? $options['test_publishable_key'] : ''; |
|
| 110 | + $test_secret_key = isset($options['test_secret_key']) ? $options['test_secret_key'] : ''; |
|
| 111 | + $live_pub_key = isset($options['publishable_key']) ? $options['publishable_key'] : ''; |
|
| 112 | + $live_secret_key = isset($options['secret_key']) ? $options['secret_key'] : ''; |
|
| 113 | + |
|
| 114 | + if (isset($options['enabled']) && 'yes' === $options['enabled']) { |
|
| 115 | + if (empty($show_phpver_notice)) { |
|
| 116 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
| 117 | 117 | /* translators: 1) int version 2) int version */ |
| 118 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
| 118 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
| 119 | 119 | |
| 120 | - $this->add_admin_notice( 'phpver', 'error', sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ), true ); |
|
| 120 | + $this->add_admin_notice('phpver', 'error', sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()), true); |
|
| 121 | 121 | |
| 122 | 122 | return; |
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - if ( empty( $show_wcver_notice ) ) { |
|
| 127 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
| 126 | + if (empty($show_wcver_notice)) { |
|
| 127 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
| 128 | 128 | /* translators: 1) int version 2) int version */ |
| 129 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
| 129 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
| 130 | 130 | |
| 131 | - $this->add_admin_notice( 'wcver', 'notice notice-warning', sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ), true ); |
|
| 131 | + $this->add_admin_notice('wcver', 'notice notice-warning', sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION), true); |
|
| 132 | 132 | |
| 133 | 133 | return; |
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if ( empty( $show_curl_notice ) ) { |
|
| 138 | - if ( ! function_exists( 'curl_init' ) ) { |
|
| 139 | - $this->add_admin_notice( 'curl', 'notice notice-warning', __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ), true ); |
|
| 137 | + if (empty($show_curl_notice)) { |
|
| 138 | + if ( ! function_exists('curl_init')) { |
|
| 139 | + $this->add_admin_notice('curl', 'notice notice-warning', __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'), true); |
|
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - if ( empty( $show_keys_notice ) ) { |
|
| 143 | + if (empty($show_keys_notice)) { |
|
| 144 | 144 | $secret = WC_Stripe_API::get_secret_key(); |
| 145 | 145 | |
| 146 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
| 146 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
| 147 | 147 | $setting_link = $this->get_setting_link(); |
| 148 | 148 | /* translators: 1) link */ |
| 149 | - $this->add_admin_notice( 'keys', '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 ), true ); |
|
| 149 | + $this->add_admin_notice('keys', '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), true); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | // Check if keys are entered properly per live/test mode. |
| 153 | - if ( $testmode ) { |
|
| 153 | + if ($testmode) { |
|
| 154 | 154 | if ( |
| 155 | - ! empty( $test_pub_key ) && ! preg_match( '/^pk_test_/', $test_pub_key ) |
|
| 156 | - || ( ! empty( $test_secret_key ) && ! preg_match( '/^sk_test_/', $test_secret_key ) |
|
| 157 | - && ! empty( $test_secret_key ) && ! preg_match( '/^rk_test_/', $test_secret_key ) ) ) |
|
| 155 | + ! empty($test_pub_key) && ! preg_match('/^pk_test_/', $test_pub_key) |
|
| 156 | + || ( ! empty($test_secret_key) && ! preg_match('/^sk_test_/', $test_secret_key) |
|
| 157 | + && ! empty($test_secret_key) && ! preg_match('/^rk_test_/', $test_secret_key)) ) |
|
| 158 | 158 | { |
| 159 | 159 | $setting_link = $this->get_setting_link(); |
| 160 | 160 | /* translators: 1) link */ |
| 161 | - $this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
| 161 | + $this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
| 162 | 162 | } |
| 163 | 163 | } else { |
| 164 | 164 | if ( |
| 165 | - ! empty( $live_pub_key ) && ! preg_match( '/^pk_live_/', $live_pub_key ) |
|
| 166 | - || ( ! empty( $live_secret_key ) && ! preg_match( '/^sk_live_/', $live_secret_key ) |
|
| 167 | - && ! empty( $live_secret_key ) && ! preg_match( '/^rk_live_/', $live_secret_key ) ) ) |
|
| 165 | + ! empty($live_pub_key) && ! preg_match('/^pk_live_/', $live_pub_key) |
|
| 166 | + || ( ! empty($live_secret_key) && ! preg_match('/^sk_live_/', $live_secret_key) |
|
| 167 | + && ! empty($live_secret_key) && ! preg_match('/^rk_live_/', $live_secret_key)) ) |
|
| 168 | 168 | { |
| 169 | 169 | $setting_link = $this->get_setting_link(); |
| 170 | 170 | /* translators: 1) link */ |
| 171 | - $this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
| 171 | + $this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - if ( empty( $show_ssl_notice ) ) { |
|
| 176 | + if (empty($show_ssl_notice)) { |
|
| 177 | 177 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
| 178 | - if ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) { |
|
| 178 | + if (function_exists('wc_site_is_https') && ! wc_site_is_https()) { |
|
| 179 | 179 | /* translators: 1) link 2) link */ |
| 180 | - $this->add_admin_notice( 'ssl', 'notice notice-warning', sprintf( __( 'Stripe is enabled, but the <a href="%1$s">SSL</a> is not detected. Your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ), true ); |
|
| 180 | + $this->add_admin_notice('ssl', 'notice notice-warning', sprintf(__('Stripe is enabled, but the <a href="%1$s">SSL</a> is not detected. Your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout'), 'https://en.wikipedia.org/wiki/Transport_Layer_Security'), true); |
|
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | 183 | } |
@@ -191,16 +191,16 @@ discard block |
||
| 191 | 191 | public function payment_methods_check_environment() { |
| 192 | 192 | $payment_methods = $this->get_payment_methods(); |
| 193 | 193 | |
| 194 | - foreach ( $payment_methods as $method => $class ) { |
|
| 195 | - $show_notice = get_option( 'wc_stripe_show_' . strtolower( $method ) . '_notice' ); |
|
| 194 | + foreach ($payment_methods as $method => $class) { |
|
| 195 | + $show_notice = get_option('wc_stripe_show_' . strtolower($method) . '_notice'); |
|
| 196 | 196 | $gateway = new $class(); |
| 197 | 197 | |
| 198 | - if ( 'yes' !== $gateway->enabled || 'no' === $show_notice ) { |
|
| 198 | + if ('yes' !== $gateway->enabled || 'no' === $show_notice) { |
|
| 199 | 199 | continue; |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - if ( ! in_array( get_woocommerce_currency(), $gateway->get_supported_currency() ) ) { |
|
| 203 | - $this->add_admin_notice( $method, 'notice notice-error', sprintf( __( '%s is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe' ), $method, implode( ', ', $gateway->get_supported_currency() ) ), true ); |
|
| 202 | + if ( ! in_array(get_woocommerce_currency(), $gateway->get_supported_currency())) { |
|
| 203 | + $this->add_admin_notice($method, 'notice notice-error', sprintf(__('%s is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe'), $method, implode(', ', $gateway->get_supported_currency())), true); |
|
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | } |
@@ -212,59 +212,59 @@ discard block |
||
| 212 | 212 | * @version 4.0.0 |
| 213 | 213 | */ |
| 214 | 214 | public function hide_notices() { |
| 215 | - if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) { |
|
| 216 | - if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) { |
|
| 217 | - wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) ); |
|
| 215 | + if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) { |
|
| 216 | + if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) { |
|
| 217 | + wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe')); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 221 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 220 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 221 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - $notice = wc_clean( $_GET['wc-stripe-hide-notice'] ); |
|
| 224 | + $notice = wc_clean($_GET['wc-stripe-hide-notice']); |
|
| 225 | 225 | |
| 226 | - switch ( $notice ) { |
|
| 226 | + switch ($notice) { |
|
| 227 | 227 | case 'phpver': |
| 228 | - update_option( 'wc_stripe_show_phpver_notice', 'no' ); |
|
| 228 | + update_option('wc_stripe_show_phpver_notice', 'no'); |
|
| 229 | 229 | break; |
| 230 | 230 | case 'wcver': |
| 231 | - update_option( 'wc_stripe_show_wcver_notice', 'no' ); |
|
| 231 | + update_option('wc_stripe_show_wcver_notice', 'no'); |
|
| 232 | 232 | break; |
| 233 | 233 | case 'curl': |
| 234 | - update_option( 'wc_stripe_show_curl_notice', 'no' ); |
|
| 234 | + update_option('wc_stripe_show_curl_notice', 'no'); |
|
| 235 | 235 | break; |
| 236 | 236 | case 'ssl': |
| 237 | - update_option( 'wc_stripe_show_ssl_notice', 'no' ); |
|
| 237 | + update_option('wc_stripe_show_ssl_notice', 'no'); |
|
| 238 | 238 | break; |
| 239 | 239 | case 'keys': |
| 240 | - update_option( 'wc_stripe_show_keys_notice', 'no' ); |
|
| 240 | + update_option('wc_stripe_show_keys_notice', 'no'); |
|
| 241 | 241 | break; |
| 242 | 242 | case 'Alipay': |
| 243 | - update_option( 'wc_stripe_show_alipay_notice', 'no' ); |
|
| 243 | + update_option('wc_stripe_show_alipay_notice', 'no'); |
|
| 244 | 244 | break; |
| 245 | 245 | case 'Bancontact': |
| 246 | - update_option( 'wc_stripe_show_bancontact_notice', 'no' ); |
|
| 246 | + update_option('wc_stripe_show_bancontact_notice', 'no'); |
|
| 247 | 247 | break; |
| 248 | 248 | case 'EPS': |
| 249 | - update_option( 'wc_stripe_show_eps_notice', 'no' ); |
|
| 249 | + update_option('wc_stripe_show_eps_notice', 'no'); |
|
| 250 | 250 | break; |
| 251 | 251 | case 'Giropay': |
| 252 | - update_option( 'wc_stripe_show_giropay_notice', 'no' ); |
|
| 252 | + update_option('wc_stripe_show_giropay_notice', 'no'); |
|
| 253 | 253 | break; |
| 254 | 254 | case 'iDeal': |
| 255 | - update_option( 'wc_stripe_show_ideal_notice', 'no' ); |
|
| 255 | + update_option('wc_stripe_show_ideal_notice', 'no'); |
|
| 256 | 256 | break; |
| 257 | 257 | case 'Multibanco': |
| 258 | - update_option( 'wc_stripe_show_multibanco_notice', 'no' ); |
|
| 258 | + update_option('wc_stripe_show_multibanco_notice', 'no'); |
|
| 259 | 259 | break; |
| 260 | 260 | case 'P24': |
| 261 | - update_option( 'wc_stripe_show_p24_notice', 'no' ); |
|
| 261 | + update_option('wc_stripe_show_p24_notice', 'no'); |
|
| 262 | 262 | break; |
| 263 | 263 | case 'SEPA': |
| 264 | - update_option( 'wc_stripe_show_sepa_notice', 'no' ); |
|
| 264 | + update_option('wc_stripe_show_sepa_notice', 'no'); |
|
| 265 | 265 | break; |
| 266 | 266 | case 'SOFORT': |
| 267 | - update_option( 'wc_stripe_show_sofort_notice', 'no' ); |
|
| 267 | + update_option('wc_stripe_show_sofort_notice', 'no'); |
|
| 268 | 268 | break; |
| 269 | 269 | } |
| 270 | 270 | } |
@@ -278,11 +278,11 @@ discard block |
||
| 278 | 278 | * @return string Setting link |
| 279 | 279 | */ |
| 280 | 280 | public function get_setting_link() { |
| 281 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
| 281 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
| 282 | 282 | |
| 283 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
| 283 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
| 284 | 284 | |
| 285 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
| 285 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
| 286 | 286 | } |
| 287 | 287 | } |
| 288 | 288 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | * Constructor |
| 33 | 33 | * @param int $user_id The WP user ID |
| 34 | 34 | */ |
| 35 | - public function __construct( $user_id = 0 ) { |
|
| 36 | - if ( $user_id ) { |
|
| 37 | - $this->set_user_id( $user_id ); |
|
| 38 | - $this->set_id( get_user_meta( $user_id, '_stripe_customer_id', true ) ); |
|
| 35 | + public function __construct($user_id = 0) { |
|
| 36 | + if ($user_id) { |
|
| 37 | + $this->set_user_id($user_id); |
|
| 38 | + $this->set_id(get_user_meta($user_id, '_stripe_customer_id', true)); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
@@ -51,15 +51,15 @@ discard block |
||
| 51 | 51 | * Set Stripe customer ID. |
| 52 | 52 | * @param [type] $id [description] |
| 53 | 53 | */ |
| 54 | - public function set_id( $id ) { |
|
| 54 | + public function set_id($id) { |
|
| 55 | 55 | // Backwards compat for customer ID stored in array format. (Pre 3.0) |
| 56 | - if ( is_array( $id ) && isset( $id['customer_id'] ) ) { |
|
| 56 | + if (is_array($id) && isset($id['customer_id'])) { |
|
| 57 | 57 | $id = $id['customer_id']; |
| 58 | 58 | |
| 59 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $id ); |
|
| 59 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $id); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - $this->id = wc_clean( $id ); |
|
| 62 | + $this->id = wc_clean($id); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -67,15 +67,15 @@ discard block |
||
| 67 | 67 | * @return int |
| 68 | 68 | */ |
| 69 | 69 | public function get_user_id() { |
| 70 | - return absint( $this->user_id ); |
|
| 70 | + return absint($this->user_id); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | 74 | * Set User ID used by WordPress. |
| 75 | 75 | * @param int $user_id |
| 76 | 76 | */ |
| 77 | - public function set_user_id( $user_id ) { |
|
| 78 | - $this->user_id = absint( $user_id ); |
|
| 77 | + public function set_user_id($user_id) { |
|
| 78 | + $this->user_id = absint($user_id); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -83,13 +83,13 @@ discard block |
||
| 83 | 83 | * @return WP_User |
| 84 | 84 | */ |
| 85 | 85 | protected function get_user() { |
| 86 | - return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false; |
|
| 86 | + return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
| 90 | 90 | * Store data from the Stripe API about this customer |
| 91 | 91 | */ |
| 92 | - public function set_customer_data( $data ) { |
|
| 92 | + public function set_customer_data($data) { |
|
| 93 | 93 | $this->customer_data = $data; |
| 94 | 94 | } |
| 95 | 95 | |
@@ -98,14 +98,14 @@ discard block |
||
| 98 | 98 | * @param array $args |
| 99 | 99 | * @return WP_Error|int |
| 100 | 100 | */ |
| 101 | - public function create_customer( $args = array() ) { |
|
| 102 | - $billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : ''; |
|
| 101 | + public function create_customer($args = array()) { |
|
| 102 | + $billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : ''; |
|
| 103 | 103 | $user = $this->get_user(); |
| 104 | 104 | |
| 105 | - if ( $user ) { |
|
| 106 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
| 107 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
| 108 | - $description = __( 'Name', 'woocommerce-gateway-stripe' ) . ': ' . $billing_first_name . ' ' . $billing_last_name . ' ' . __( 'Username', 'woocommerce-gateway-stripe' ) . ': ' . $user->user_login; |
|
| 105 | + if ($user) { |
|
| 106 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
| 107 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
| 108 | + $description = __('Name', 'woocommerce-gateway-stripe') . ': ' . $billing_first_name . ' ' . $billing_last_name . ' ' . __('Username', 'woocommerce-gateway-stripe') . ': ' . $user->user_login; |
|
| 109 | 109 | |
| 110 | 110 | $defaults = array( |
| 111 | 111 | 'email' => $user->user_email, |
@@ -120,24 +120,24 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | $metadata = array(); |
| 122 | 122 | |
| 123 | - $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user ); |
|
| 123 | + $defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user); |
|
| 124 | 124 | |
| 125 | - $args = wp_parse_args( $args, $defaults ); |
|
| 126 | - $response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' ); |
|
| 125 | + $args = wp_parse_args($args, $defaults); |
|
| 126 | + $response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers'); |
|
| 127 | 127 | |
| 128 | - if ( ! empty( $response->error ) ) { |
|
| 129 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 128 | + if ( ! empty($response->error)) { |
|
| 129 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - $this->set_id( $response->id ); |
|
| 132 | + $this->set_id($response->id); |
|
| 133 | 133 | $this->clear_cache(); |
| 134 | - $this->set_customer_data( $response ); |
|
| 134 | + $this->set_customer_data($response); |
|
| 135 | 135 | |
| 136 | - if ( $this->get_user_id() ) { |
|
| 137 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id ); |
|
| 136 | + if ($this->get_user_id()) { |
|
| 137 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
| 140 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
| 141 | 141 | |
| 142 | 142 | return $response->id; |
| 143 | 143 | } |
@@ -149,11 +149,11 @@ discard block |
||
| 149 | 149 | * @since 4.1.2 |
| 150 | 150 | * @param array $error |
| 151 | 151 | */ |
| 152 | - public function is_no_such_customer_error( $error ) { |
|
| 152 | + public function is_no_such_customer_error($error) { |
|
| 153 | 153 | return ( |
| 154 | 154 | $error && |
| 155 | 155 | 'invalid_request_error' === $error->type && |
| 156 | - preg_match( '/No such customer/i', $error->message ) |
|
| 156 | + preg_match('/No such customer/i', $error->message) |
|
| 157 | 157 | ); |
| 158 | 158 | } |
| 159 | 159 | |
@@ -163,74 +163,74 @@ discard block |
||
| 163 | 163 | * @param bool $retry |
| 164 | 164 | * @return WP_Error|int |
| 165 | 165 | */ |
| 166 | - public function add_source( $source_id, $retry = true ) { |
|
| 167 | - if ( ! $this->get_id() ) { |
|
| 168 | - $this->set_id( $this->create_customer() ); |
|
| 166 | + public function add_source($source_id, $retry = true) { |
|
| 167 | + if ( ! $this->get_id()) { |
|
| 168 | + $this->set_id($this->create_customer()); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - $response = WC_Stripe_API::request( array( |
|
| 171 | + $response = WC_Stripe_API::request(array( |
|
| 172 | 172 | 'source' => $source_id, |
| 173 | - ), 'customers/' . $this->get_id() . '/sources' ); |
|
| 173 | + ), 'customers/' . $this->get_id() . '/sources'); |
|
| 174 | 174 | |
| 175 | 175 | $wc_token = false; |
| 176 | 176 | |
| 177 | - if ( ! empty( $response->error ) ) { |
|
| 177 | + if ( ! empty($response->error)) { |
|
| 178 | 178 | // It is possible the WC user once was linked to a customer on Stripe |
| 179 | 179 | // but no longer exists. Instead of failing, lets try to create a |
| 180 | 180 | // new customer. |
| 181 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
| 182 | - delete_user_meta( $this->get_user_id(), '_stripe_customer_id' ); |
|
| 181 | + if ($this->is_no_such_customer_error($response->error)) { |
|
| 182 | + delete_user_meta($this->get_user_id(), '_stripe_customer_id'); |
|
| 183 | 183 | $this->create_customer(); |
| 184 | - return $this->add_source( $source_id, false ); |
|
| 184 | + return $this->add_source($source_id, false); |
|
| 185 | 185 | } else { |
| 186 | 186 | return $response; |
| 187 | 187 | } |
| 188 | - } elseif ( empty( $response->id ) ) { |
|
| 189 | - return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) ); |
|
| 188 | + } elseif (empty($response->id)) { |
|
| 189 | + return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe')); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | // Add token to WooCommerce. |
| 193 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
| 194 | - if ( ! empty( $response->type ) ) { |
|
| 195 | - switch ( $response->type ) { |
|
| 193 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
| 194 | + if ( ! empty($response->type)) { |
|
| 195 | + switch ($response->type) { |
|
| 196 | 196 | case 'alipay': |
| 197 | 197 | break; |
| 198 | 198 | case 'sepa_debit': |
| 199 | 199 | $wc_token = new WC_Payment_Token_SEPA(); |
| 200 | - $wc_token->set_token( $response->id ); |
|
| 201 | - $wc_token->set_gateway_id( 'stripe_sepa' ); |
|
| 202 | - $wc_token->set_last4( $response->sepa_debit->last4 ); |
|
| 200 | + $wc_token->set_token($response->id); |
|
| 201 | + $wc_token->set_gateway_id('stripe_sepa'); |
|
| 202 | + $wc_token->set_last4($response->sepa_debit->last4); |
|
| 203 | 203 | break; |
| 204 | 204 | default: |
| 205 | - if ( 'source' === $response->object && 'card' === $response->type ) { |
|
| 205 | + if ('source' === $response->object && 'card' === $response->type) { |
|
| 206 | 206 | $wc_token = new WC_Payment_Token_CC(); |
| 207 | - $wc_token->set_token( $response->id ); |
|
| 208 | - $wc_token->set_gateway_id( 'stripe' ); |
|
| 209 | - $wc_token->set_card_type( strtolower( $response->card->brand ) ); |
|
| 210 | - $wc_token->set_last4( $response->card->last4 ); |
|
| 211 | - $wc_token->set_expiry_month( $response->card->exp_month ); |
|
| 212 | - $wc_token->set_expiry_year( $response->card->exp_year ); |
|
| 207 | + $wc_token->set_token($response->id); |
|
| 208 | + $wc_token->set_gateway_id('stripe'); |
|
| 209 | + $wc_token->set_card_type(strtolower($response->card->brand)); |
|
| 210 | + $wc_token->set_last4($response->card->last4); |
|
| 211 | + $wc_token->set_expiry_month($response->card->exp_month); |
|
| 212 | + $wc_token->set_expiry_year($response->card->exp_year); |
|
| 213 | 213 | } |
| 214 | 214 | break; |
| 215 | 215 | } |
| 216 | 216 | } else { |
| 217 | 217 | // Legacy. |
| 218 | 218 | $wc_token = new WC_Payment_Token_CC(); |
| 219 | - $wc_token->set_token( $response->id ); |
|
| 220 | - $wc_token->set_gateway_id( 'stripe' ); |
|
| 221 | - $wc_token->set_card_type( strtolower( $response->brand ) ); |
|
| 222 | - $wc_token->set_last4( $response->last4 ); |
|
| 223 | - $wc_token->set_expiry_month( $response->exp_month ); |
|
| 224 | - $wc_token->set_expiry_year( $response->exp_year ); |
|
| 219 | + $wc_token->set_token($response->id); |
|
| 220 | + $wc_token->set_gateway_id('stripe'); |
|
| 221 | + $wc_token->set_card_type(strtolower($response->brand)); |
|
| 222 | + $wc_token->set_last4($response->last4); |
|
| 223 | + $wc_token->set_expiry_month($response->exp_month); |
|
| 224 | + $wc_token->set_expiry_year($response->exp_year); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - $wc_token->set_user_id( $this->get_user_id() ); |
|
| 227 | + $wc_token->set_user_id($this->get_user_id()); |
|
| 228 | 228 | $wc_token->save(); |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | $this->clear_cache(); |
| 232 | 232 | |
| 233 | - do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id ); |
|
| 233 | + do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id); |
|
| 234 | 234 | |
| 235 | 235 | return $response->id; |
| 236 | 236 | } |
@@ -242,42 +242,42 @@ discard block |
||
| 242 | 242 | * @return array |
| 243 | 243 | */ |
| 244 | 244 | public function get_sources() { |
| 245 | - if ( ! $this->get_id() ) { |
|
| 245 | + if ( ! $this->get_id()) { |
|
| 246 | 246 | return array(); |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - $sources = get_transient( 'stripe_sources_' . $this->get_id() ); |
|
| 249 | + $sources = get_transient('stripe_sources_' . $this->get_id()); |
|
| 250 | 250 | |
| 251 | - $response = WC_Stripe_API::request( array( |
|
| 251 | + $response = WC_Stripe_API::request(array( |
|
| 252 | 252 | 'limit' => 100, |
| 253 | - ), 'customers/' . $this->get_id() . '/sources', 'GET' ); |
|
| 253 | + ), 'customers/' . $this->get_id() . '/sources', 'GET'); |
|
| 254 | 254 | |
| 255 | - if ( ! empty( $response->error ) ) { |
|
| 255 | + if ( ! empty($response->error)) { |
|
| 256 | 256 | return array(); |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - if ( is_array( $response->data ) ) { |
|
| 259 | + if (is_array($response->data)) { |
|
| 260 | 260 | $sources = $response->data; |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - return empty( $sources ) ? array() : $sources; |
|
| 263 | + return empty($sources) ? array() : $sources; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
| 267 | 267 | * Delete a source from stripe. |
| 268 | 268 | * @param string $source_id |
| 269 | 269 | */ |
| 270 | - public function delete_source( $source_id ) { |
|
| 271 | - if ( ! $this->get_id() ) { |
|
| 270 | + public function delete_source($source_id) { |
|
| 271 | + if ( ! $this->get_id()) { |
|
| 272 | 272 | return false; |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' ); |
|
| 275 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE'); |
|
| 276 | 276 | |
| 277 | 277 | $this->clear_cache(); |
| 278 | 278 | |
| 279 | - if ( empty( $response->error ) ) { |
|
| 280 | - do_action( 'wc_stripe_delete_source', $this->get_id(), $response ); |
|
| 279 | + if (empty($response->error)) { |
|
| 280 | + do_action('wc_stripe_delete_source', $this->get_id(), $response); |
|
| 281 | 281 | |
| 282 | 282 | return true; |
| 283 | 283 | } |
@@ -289,15 +289,15 @@ discard block |
||
| 289 | 289 | * Set default source in Stripe |
| 290 | 290 | * @param string $source_id |
| 291 | 291 | */ |
| 292 | - public function set_default_source( $source_id ) { |
|
| 293 | - $response = WC_Stripe_API::request( array( |
|
| 294 | - 'default_source' => sanitize_text_field( $source_id ), |
|
| 295 | - ), 'customers/' . $this->get_id(), 'POST' ); |
|
| 292 | + public function set_default_source($source_id) { |
|
| 293 | + $response = WC_Stripe_API::request(array( |
|
| 294 | + 'default_source' => sanitize_text_field($source_id), |
|
| 295 | + ), 'customers/' . $this->get_id(), 'POST'); |
|
| 296 | 296 | |
| 297 | 297 | $this->clear_cache(); |
| 298 | 298 | |
| 299 | - if ( empty( $response->error ) ) { |
|
| 300 | - do_action( 'wc_stripe_set_default_source', $this->get_id(), $response ); |
|
| 299 | + if (empty($response->error)) { |
|
| 300 | + do_action('wc_stripe_set_default_source', $this->get_id(), $response); |
|
| 301 | 301 | |
| 302 | 302 | return true; |
| 303 | 303 | } |
@@ -309,8 +309,8 @@ discard block |
||
| 309 | 309 | * Deletes caches for this users cards. |
| 310 | 310 | */ |
| 311 | 311 | public function clear_cache() { |
| 312 | - delete_transient( 'stripe_sources_' . $this->get_id() ); |
|
| 313 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
| 312 | + delete_transient('stripe_sources_' . $this->get_id()); |
|
| 313 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
| 314 | 314 | $this->customer_data = array(); |
| 315 | 315 | } |
| 316 | 316 | } |