@@ -14,20 +14,20 @@ discard block |
||
14 | 14 | * |
15 | 15 | */ |
16 | 16 | |
17 | -if ( ! defined( 'ABSPATH' ) ) { |
|
17 | +if ( ! defined('ABSPATH')) { |
|
18 | 18 | exit; |
19 | 19 | } |
20 | 20 | |
21 | -if ( ! class_exists( 'WC_Stripe' ) ) : |
|
21 | +if ( ! class_exists('WC_Stripe')) : |
|
22 | 22 | /** |
23 | 23 | * Required minimums and constants |
24 | 24 | */ |
25 | - define( 'WC_STRIPE_VERSION', '4.0.3' ); |
|
26 | - define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' ); |
|
27 | - define( 'WC_STRIPE_MIN_WC_VER', '2.6.0' ); |
|
28 | - define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
29 | - define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
30 | - define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
|
25 | + define('WC_STRIPE_VERSION', '4.0.3'); |
|
26 | + define('WC_STRIPE_MIN_PHP_VER', '5.6.0'); |
|
27 | + define('WC_STRIPE_MIN_WC_VER', '2.6.0'); |
|
28 | + define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
29 | + define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
30 | + define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); |
|
31 | 31 | |
32 | 32 | class WC_Stripe { |
33 | 33 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @return Singleton The *Singleton* instance. |
48 | 48 | */ |
49 | 49 | public static function get_instance() { |
50 | - if ( null === self::$instance ) { |
|
50 | + if (null === self::$instance) { |
|
51 | 51 | self::$instance = new self(); |
52 | 52 | } |
53 | 53 | return self::$instance; |
@@ -80,10 +80,10 @@ discard block |
||
80 | 80 | * *Singleton* via the `new` operator from outside of this class. |
81 | 81 | */ |
82 | 82 | private function __construct() { |
83 | - add_action( 'admin_init', array( $this, 'check_environment' ) ); |
|
84 | - add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 ); |
|
85 | - add_action( 'plugins_loaded', array( $this, 'init' ) ); |
|
86 | - add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
83 | + add_action('admin_init', array($this, 'check_environment')); |
|
84 | + add_action('admin_notices', array($this, 'admin_notices'), 15); |
|
85 | + add_action('plugins_loaded', array($this, 'init')); |
|
86 | + add_action('wp_loaded', array($this, 'hide_notices')); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -93,43 +93,43 @@ discard block |
||
93 | 93 | * @version 4.0.0 |
94 | 94 | */ |
95 | 95 | public function init() { |
96 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php' ); |
|
97 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php' ); |
|
98 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php' ); |
|
99 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
96 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-exception.php'); |
|
97 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-logger.php'); |
|
98 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-helper.php'); |
|
99 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
100 | 100 | |
101 | 101 | // Don't hook anything else in the plugin if we're in an incompatible environment |
102 | - if ( self::get_environment_warning() ) { |
|
102 | + if (self::get_environment_warning()) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
107 | - |
|
108 | - require_once( dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php' ); |
|
109 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php' ); |
|
110 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php' ); |
|
111 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' ); |
|
112 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php' ); |
|
113 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php' ); |
|
114 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php' ); |
|
115 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php' ); |
|
116 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php' ); |
|
117 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php' ); |
|
118 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php' ); |
|
119 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php' ); |
|
120 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php' ); |
|
121 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-compat.php' ); |
|
122 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-compat.php' ); |
|
123 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php' ); |
|
124 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php' ); |
|
125 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' ); |
|
106 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
107 | + |
|
108 | + require_once(dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'); |
|
109 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php'); |
|
110 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php'); |
|
111 | + require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'); |
|
112 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'); |
|
113 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'); |
|
114 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'); |
|
115 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'); |
|
116 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'); |
|
117 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'); |
|
118 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'); |
|
119 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php'); |
|
120 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php'); |
|
121 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-compat.php'); |
|
122 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-compat.php'); |
|
123 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php'); |
|
124 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php'); |
|
125 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'); |
|
126 | 126 | |
127 | 127 | // REMOVE IN THE FUTURE. |
128 | - require_once( dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php' ); |
|
128 | + require_once(dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php'); |
|
129 | 129 | |
130 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
131 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
132 | - add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); |
|
130 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
131 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
132 | + add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin')); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -139,23 +139,23 @@ discard block |
||
139 | 139 | * @version 4.0.0 |
140 | 140 | */ |
141 | 141 | public function hide_notices() { |
142 | - if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) { |
|
143 | - if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) { |
|
144 | - wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) ); |
|
142 | + if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) { |
|
143 | + if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) { |
|
144 | + wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe')); |
|
145 | 145 | } |
146 | 146 | |
147 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
148 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
147 | + if ( ! current_user_can('manage_woocommerce')) { |
|
148 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
149 | 149 | } |
150 | 150 | |
151 | - $notice = wc_clean( $_GET['wc-stripe-hide-notice'] ); |
|
151 | + $notice = wc_clean($_GET['wc-stripe-hide-notice']); |
|
152 | 152 | |
153 | - switch ( $notice ) { |
|
153 | + switch ($notice) { |
|
154 | 154 | case 'ssl': |
155 | - update_option( 'wc_stripe_show_ssl_notice', 'no' ); |
|
155 | + update_option('wc_stripe_show_ssl_notice', 'no'); |
|
156 | 156 | break; |
157 | 157 | case 'keys': |
158 | - update_option( 'wc_stripe_show_keys_notice', 'no' ); |
|
158 | + update_option('wc_stripe_show_keys_notice', 'no'); |
|
159 | 159 | break; |
160 | 160 | } |
161 | 161 | } |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | * @since 1.0.0 |
168 | 168 | * @version 4.0.0 |
169 | 169 | */ |
170 | - public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
|
171 | - $this->notices[ $slug ] = array( |
|
170 | + public function add_admin_notice($slug, $class, $message, $dismissible = false) { |
|
171 | + $this->notices[$slug] = array( |
|
172 | 172 | 'class' => $class, |
173 | 173 | 'message' => $message, |
174 | 174 | 'dismissible' => $dismissible, |
@@ -182,21 +182,21 @@ discard block |
||
182 | 182 | * @version 4.0.0 |
183 | 183 | */ |
184 | 184 | public function admin_notices() { |
185 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
185 | + if ( ! current_user_can('manage_woocommerce')) { |
|
186 | 186 | return; |
187 | 187 | } |
188 | 188 | |
189 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
190 | - echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">'; |
|
189 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
190 | + echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">'; |
|
191 | 191 | |
192 | - if ( $notice['dismissible'] ) { |
|
192 | + if ($notice['dismissible']) { |
|
193 | 193 | ?> |
194 | - <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> |
|
194 | + <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> |
|
195 | 195 | <?php |
196 | 196 | } |
197 | 197 | |
198 | 198 | echo '<p>'; |
199 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
199 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
200 | 200 | echo '</p></div>'; |
201 | 201 | } |
202 | 202 | } |
@@ -209,26 +209,26 @@ discard block |
||
209 | 209 | * @version 4.0.0 |
210 | 210 | */ |
211 | 211 | public function get_environment_warning() { |
212 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
212 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
213 | 213 | /* translators: 1) int version 2) int version */ |
214 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
214 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
215 | 215 | |
216 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
216 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
217 | 217 | } |
218 | 218 | |
219 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
220 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
219 | + if ( ! defined('WC_VERSION')) { |
|
220 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
221 | 221 | } |
222 | 222 | |
223 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
223 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
224 | 224 | /* translators: 1) int version 2) int version */ |
225 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
225 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
226 | 226 | |
227 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
227 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
228 | 228 | } |
229 | 229 | |
230 | - if ( ! function_exists( 'curl_init' ) ) { |
|
231 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
230 | + if ( ! function_exists('curl_init')) { |
|
231 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | return false; |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | * @return string Setting link |
243 | 243 | */ |
244 | 244 | public function get_setting_link() { |
245 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
245 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
246 | 246 | |
247 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
247 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
248 | 248 | |
249 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
249 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -257,37 +257,37 @@ discard block |
||
257 | 257 | * @version 4.0.0 |
258 | 258 | */ |
259 | 259 | public function check_environment() { |
260 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
|
260 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) { |
|
261 | 261 | $this->install(); |
262 | 262 | |
263 | - do_action( 'woocommerce_stripe_updated' ); |
|
263 | + do_action('woocommerce_stripe_updated'); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | $environment_warning = $this->get_environment_warning(); |
267 | 267 | |
268 | - if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
269 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
268 | + if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) { |
|
269 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
270 | 270 | } |
271 | 271 | |
272 | - $show_ssl_notice = get_option( 'wc_stripe_show_ssl_notice' ); |
|
273 | - $show_keys_notice = get_option( 'wc_stripe_show_keys_notice' ); |
|
274 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
272 | + $show_ssl_notice = get_option('wc_stripe_show_ssl_notice'); |
|
273 | + $show_keys_notice = get_option('wc_stripe_show_keys_notice'); |
|
274 | + $options = get_option('woocommerce_stripe_settings'); |
|
275 | 275 | |
276 | - if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] && empty( $show_keys_notice ) ) { |
|
277 | - $secret = WC_Stripe_API::get_secret_key(); |
|
276 | + if (isset($options['enabled']) && 'yes' === $options['enabled'] && empty($show_keys_notice)) { |
|
277 | + $secret = WC_Stripe_API::get_secret_key(); |
|
278 | 278 | |
279 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
279 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
280 | 280 | $setting_link = $this->get_setting_link(); |
281 | 281 | /* translators: 1) link */ |
282 | - $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 ); |
|
282 | + $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); |
|
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
286 | - if ( empty( $show_ssl_notice ) && isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) { |
|
286 | + if (empty($show_ssl_notice) && isset($options['enabled']) && 'yes' === $options['enabled']) { |
|
287 | 287 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
288 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
288 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
289 | 289 | /* translators: 1) link 2) link */ |
290 | - $this->add_admin_notice( 'ssl', 'notice notice-warning', sprintf( __( 'Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; 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 ); |
|
290 | + $this->add_admin_notice('ssl', 'notice notice-warning', sprintf(__('Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; 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); |
|
291 | 291 | } |
292 | 292 | } |
293 | 293 | } |
@@ -299,8 +299,8 @@ discard block |
||
299 | 299 | * @version 4.0.0 |
300 | 300 | */ |
301 | 301 | public function update_plugin_version() { |
302 | - delete_option( 'wc_stripe_version' ); |
|
303 | - update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
302 | + delete_option('wc_stripe_version'); |
|
303 | + update_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
@@ -310,8 +310,8 @@ discard block |
||
310 | 310 | * @version 3.1.0 |
311 | 311 | */ |
312 | 312 | public function install() { |
313 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
314 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
313 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
314 | + define('WC_STRIPE_INSTALLING', true); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | $this->update_plugin_version(); |
@@ -323,13 +323,13 @@ discard block |
||
323 | 323 | * @since 1.0.0 |
324 | 324 | * @version 4.0.0 |
325 | 325 | */ |
326 | - public function plugin_action_links( $links ) { |
|
326 | + public function plugin_action_links($links) { |
|
327 | 327 | $plugin_links = array( |
328 | - '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
329 | - '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
330 | - '<a href="https://woocommerce.com/contact-us/">' . esc_html__( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
328 | + '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
329 | + '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
330 | + '<a href="https://woocommerce.com/contact-us/">' . esc_html__('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
331 | 331 | ); |
332 | - return array_merge( $plugin_links, $links ); |
|
332 | + return array_merge($plugin_links, $links); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
@@ -338,8 +338,8 @@ discard block |
||
338 | 338 | * @since 1.0.0 |
339 | 339 | * @version 4.0.0 |
340 | 340 | */ |
341 | - public function add_gateways( $methods ) { |
|
342 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
341 | + public function add_gateways($methods) { |
|
342 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order') || class_exists('WC_Pre_Orders_Order')) { |
|
343 | 343 | $methods[] = 'WC_Stripe_Compat'; |
344 | 344 | $methods[] = 'WC_Stripe_Sepa_Compat'; |
345 | 345 | } else { |
@@ -364,26 +364,26 @@ discard block |
||
364 | 364 | * @since 4.0.0 |
365 | 365 | * @version 4.0.0 |
366 | 366 | */ |
367 | - public function filter_gateway_order_admin( $sections ) { |
|
368 | - unset( $sections['stripe'] ); |
|
369 | - unset( $sections['stripe_bancontact'] ); |
|
370 | - unset( $sections['stripe_sofort'] ); |
|
371 | - unset( $sections['stripe_giropay'] ); |
|
372 | - unset( $sections['stripe_ideal'] ); |
|
373 | - unset( $sections['stripe_p24'] ); |
|
374 | - unset( $sections['stripe_alipay'] ); |
|
375 | - unset( $sections['stripe_sepa'] ); |
|
376 | - unset( $sections['stripe_bitcoin'] ); |
|
367 | + public function filter_gateway_order_admin($sections) { |
|
368 | + unset($sections['stripe']); |
|
369 | + unset($sections['stripe_bancontact']); |
|
370 | + unset($sections['stripe_sofort']); |
|
371 | + unset($sections['stripe_giropay']); |
|
372 | + unset($sections['stripe_ideal']); |
|
373 | + unset($sections['stripe_p24']); |
|
374 | + unset($sections['stripe_alipay']); |
|
375 | + unset($sections['stripe_sepa']); |
|
376 | + unset($sections['stripe_bitcoin']); |
|
377 | 377 | |
378 | 378 | $sections['stripe'] = 'Stripe'; |
379 | - $sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
380 | - $sections['stripe_sofort'] = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
381 | - $sections['stripe_giropay'] = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
382 | - $sections['stripe_ideal'] = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
383 | - $sections['stripe_p24'] = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
384 | - $sections['stripe_alipay'] = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
385 | - $sections['stripe_sepa'] = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
386 | - $sections['stripe_bitcoin'] = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
379 | + $sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
380 | + $sections['stripe_sofort'] = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
381 | + $sections['stripe_giropay'] = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
382 | + $sections['stripe_ideal'] = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
383 | + $sections['stripe_p24'] = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
384 | + $sections['stripe_alipay'] = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
385 | + $sections['stripe_sepa'] = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
386 | + $sections['stripe_bitcoin'] = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
387 | 387 | |
388 | 388 | return $sections; |
389 | 389 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function __construct() { |
121 | 121 | $this->id = 'stripe'; |
122 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
122 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
123 | 123 | /* translators: 1) link to Stripe register page 2) link to Stripe api keys page */ |
124 | - $this->method_description = sprintf( __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' ); |
|
124 | + $this->method_description = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys'); |
|
125 | 125 | $this->has_fields = true; |
126 | 126 | $this->supports = array( |
127 | 127 | 'products', |
@@ -148,38 +148,38 @@ discard block |
||
148 | 148 | $this->init_settings(); |
149 | 149 | |
150 | 150 | // Get setting values. |
151 | - $this->title = $this->get_option( 'title' ); |
|
152 | - $this->description = $this->get_option( 'description' ); |
|
153 | - $this->enabled = $this->get_option( 'enabled' ); |
|
154 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
155 | - $this->inline_cc_form = 'yes' === $this->get_option( 'inline_cc_form' ); |
|
156 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
157 | - $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) ); |
|
158 | - $this->three_d_secure = 'yes' === $this->get_option( 'three_d_secure' ); |
|
159 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
160 | - $this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' ); |
|
161 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
162 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
163 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
164 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
165 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
166 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
167 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
151 | + $this->title = $this->get_option('title'); |
|
152 | + $this->description = $this->get_option('description'); |
|
153 | + $this->enabled = $this->get_option('enabled'); |
|
154 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
155 | + $this->inline_cc_form = 'yes' === $this->get_option('inline_cc_form'); |
|
156 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
157 | + $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor')); |
|
158 | + $this->three_d_secure = 'yes' === $this->get_option('three_d_secure'); |
|
159 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
160 | + $this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale'); |
|
161 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
162 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
163 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
164 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
165 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
166 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
167 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
168 | 168 | $this->apple_pay_verify_notice = ''; |
169 | 169 | |
170 | - if ( $this->stripe_checkout ) { |
|
171 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
170 | + if ($this->stripe_checkout) { |
|
171 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
172 | 172 | } |
173 | 173 | |
174 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
174 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
175 | 175 | |
176 | 176 | $this->init_apple_pay(); |
177 | 177 | |
178 | 178 | // Hooks. |
179 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
180 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
181 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
182 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
179 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
180 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
181 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
182 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @since 4.0.2 |
189 | 189 | */ |
190 | 190 | public function is_available() { |
191 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
191 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
192 | 192 | return false; |
193 | 193 | } |
194 | 194 | |
@@ -211,17 +211,17 @@ discard block |
||
211 | 211 | $icons_str .= $icons['amex']; |
212 | 212 | $icons_str .= $icons['mastercard']; |
213 | 213 | |
214 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
214 | + if ('USD' === get_woocommerce_currency()) { |
|
215 | 215 | $icons_str .= $icons['discover']; |
216 | 216 | $icons_str .= $icons['jcb']; |
217 | 217 | $icons_str .= $icons['diners']; |
218 | 218 | } |
219 | 219 | |
220 | - if ( $this->bitcoin && $this->stripe_checkout ) { |
|
220 | + if ($this->bitcoin && $this->stripe_checkout) { |
|
221 | 221 | $icons_str .= $icons['bitcoin']; |
222 | 222 | } |
223 | 223 | |
224 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
224 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -233,9 +233,9 @@ discard block |
||
233 | 233 | public function init_apple_pay() { |
234 | 234 | if ( |
235 | 235 | is_admin() && |
236 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
237 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
238 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] && |
|
236 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
237 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
238 | + isset($_GET['section']) && 'stripe' === $_GET['section'] && |
|
239 | 239 | $this->payment_request |
240 | 240 | ) { |
241 | 241 | $this->process_apple_pay_verification(); |
@@ -249,9 +249,9 @@ discard block |
||
249 | 249 | * @version 3.1.0 |
250 | 250 | * @param string $secret_key |
251 | 251 | */ |
252 | - private function register_apple_pay_domain( $secret_key = '' ) { |
|
253 | - if ( empty( $secret_key ) ) { |
|
254 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
252 | + private function register_apple_pay_domain($secret_key = '') { |
|
253 | + if (empty($secret_key)) { |
|
254 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -265,23 +265,23 @@ discard block |
||
265 | 265 | 'Authorization' => 'Bearer ' . $secret_key, |
266 | 266 | ); |
267 | 267 | |
268 | - $response = wp_remote_post( $endpoint, array( |
|
268 | + $response = wp_remote_post($endpoint, array( |
|
269 | 269 | 'headers' => $headers, |
270 | - 'body' => http_build_query( $data ), |
|
271 | - ) ); |
|
270 | + 'body' => http_build_query($data), |
|
271 | + )); |
|
272 | 272 | |
273 | - if ( is_wp_error( $response ) ) { |
|
273 | + if (is_wp_error($response)) { |
|
274 | 274 | /* translators: error message */ |
275 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
275 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
276 | 276 | } |
277 | 277 | |
278 | - if ( 200 !== $response['response']['code'] ) { |
|
279 | - $parsed_response = json_decode( $response['body'] ); |
|
278 | + if (200 !== $response['response']['code']) { |
|
279 | + $parsed_response = json_decode($response['body']); |
|
280 | 280 | |
281 | 281 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
282 | 282 | |
283 | 283 | /* translators: error message */ |
284 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
284 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
285 | 285 | } |
286 | 286 | } |
287 | 287 | |
@@ -292,48 +292,48 @@ discard block |
||
292 | 292 | * @version 3.1.0 |
293 | 293 | */ |
294 | 294 | public function process_apple_pay_verification() { |
295 | - $gateway_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
295 | + $gateway_settings = get_option('woocommerce_stripe_settings', array()); |
|
296 | 296 | |
297 | 297 | try { |
298 | - $path = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] ); |
|
298 | + $path = untrailingslashit($_SERVER['DOCUMENT_ROOT']); |
|
299 | 299 | $dir = '.well-known'; |
300 | 300 | $file = 'apple-developer-merchantid-domain-association'; |
301 | 301 | $fullpath = $path . '/' . $dir . '/' . $file; |
302 | 302 | |
303 | - if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) { |
|
303 | + if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) { |
|
304 | 304 | return; |
305 | 305 | } |
306 | 306 | |
307 | - if ( ! file_exists( $path . '/' . $dir ) ) { |
|
308 | - if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { |
|
309 | - throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
307 | + if ( ! file_exists($path . '/' . $dir)) { |
|
308 | + if ( ! @mkdir($path . '/' . $dir, 0755)) { |
|
309 | + throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
310 | 310 | } |
311 | 311 | } |
312 | 312 | |
313 | - if ( ! file_exists( $fullpath ) ) { |
|
314 | - if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { |
|
315 | - throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
313 | + if ( ! file_exists($fullpath)) { |
|
314 | + if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { |
|
315 | + throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
316 | 316 | } |
317 | 317 | } |
318 | 318 | |
319 | 319 | // At this point then the domain association folder and file should be available. |
320 | 320 | // Proceed to verify/and or verify again. |
321 | - $this->register_apple_pay_domain( $this->secret_key ); |
|
321 | + $this->register_apple_pay_domain($this->secret_key); |
|
322 | 322 | |
323 | 323 | // No errors to this point, verification success! |
324 | 324 | $gateway_settings['apple_pay_domain_set'] = 'yes'; |
325 | 325 | $this->apple_pay_domain_set = true; |
326 | 326 | |
327 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
327 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
328 | 328 | |
329 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
329 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
330 | 330 | |
331 | - } catch ( Exception $e ) { |
|
331 | + } catch (Exception $e) { |
|
332 | 332 | $gateway_settings['apple_pay_domain_set'] = 'no'; |
333 | 333 | |
334 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
334 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
335 | 335 | |
336 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
336 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
337 | 337 | } |
338 | 338 | } |
339 | 339 | |
@@ -341,11 +341,11 @@ discard block |
||
341 | 341 | * Check if SSL is enabled and notify the user |
342 | 342 | */ |
343 | 343 | public function admin_notices() { |
344 | - if ( 'no' === $this->enabled ) { |
|
344 | + if ('no' === $this->enabled) { |
|
345 | 345 | return; |
346 | 346 | } |
347 | 347 | |
348 | - if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) { |
|
348 | + if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) { |
|
349 | 349 | $allowed_html = array( |
350 | 350 | 'a' => array( |
351 | 351 | 'href' => array(), |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | ), |
354 | 354 | ); |
355 | 355 | |
356 | - echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>'; |
|
356 | + echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>'; |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
@@ -361,9 +361,9 @@ discard block |
||
361 | 361 | * when setting screen is displayed. So if domain verification is not set, |
362 | 362 | * something went wrong so lets notify user. |
363 | 363 | */ |
364 | - if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) { |
|
364 | + if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) { |
|
365 | 365 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
366 | - 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. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>'; |
|
366 | + 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. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>'; |
|
367 | 367 | } |
368 | 368 | } |
369 | 369 | |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | * Initialise Gateway Settings Form Fields |
372 | 372 | */ |
373 | 373 | public function init_form_fields() { |
374 | - $this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' ); |
|
374 | + $this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php'); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | /** |
@@ -379,59 +379,59 @@ discard block |
||
379 | 379 | */ |
380 | 380 | public function payment_fields() { |
381 | 381 | $user = wp_get_current_user(); |
382 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
382 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
383 | 383 | $total = WC()->cart->total; |
384 | 384 | $user_email = ''; |
385 | 385 | |
386 | 386 | // If paying from order, we need to get total from order not cart. |
387 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
388 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
387 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
388 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
389 | 389 | $total = $order->get_total(); |
390 | 390 | $user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
391 | 391 | } else { |
392 | - if ( $user->ID ) { |
|
393 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
392 | + if ($user->ID) { |
|
393 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
394 | 394 | $user_email = $user_email ? $user_email : $user->user_email; |
395 | 395 | } |
396 | 396 | } |
397 | 397 | |
398 | - if ( is_add_payment_method_page() ) { |
|
399 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
400 | - $total = ''; |
|
398 | + if (is_add_payment_method_page()) { |
|
399 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
400 | + $total = ''; |
|
401 | 401 | } else { |
402 | 402 | $pay_button_text = ''; |
403 | 403 | } |
404 | 404 | |
405 | 405 | echo '<div |
406 | 406 | id="stripe-payment-data" |
407 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
407 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
408 | 408 | data-description="" |
409 | - data-email="' . esc_attr( $user_email ) . '" |
|
410 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
411 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
412 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
413 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
414 | - data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '" |
|
415 | - data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '" |
|
416 | - data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '" |
|
417 | - data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">'; |
|
418 | - |
|
419 | - if ( $this->description ) { |
|
420 | - if ( $this->testmode ) { |
|
409 | + data-email="' . esc_attr($user_email) . '" |
|
410 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
411 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
412 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
413 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
414 | + data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '" |
|
415 | + data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '" |
|
416 | + data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '" |
|
417 | + data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">'; |
|
418 | + |
|
419 | + if ($this->description) { |
|
420 | + if ($this->testmode) { |
|
421 | 421 | /* translators: link to Stripe testing page */ |
422 | - $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" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
423 | - $this->description = trim( $this->description ); |
|
422 | + $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" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
423 | + $this->description = trim($this->description); |
|
424 | 424 | } |
425 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
425 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
426 | 426 | } |
427 | 427 | |
428 | - if ( $display_tokenization ) { |
|
428 | + if ($display_tokenization) { |
|
429 | 429 | $this->tokenization_script(); |
430 | 430 | $this->saved_payment_methods(); |
431 | 431 | } |
432 | 432 | |
433 | - if ( ! $this->stripe_checkout ) { |
|
434 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
433 | + if ( ! $this->stripe_checkout) { |
|
434 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
435 | 435 | $this->elements_form(); |
436 | 436 | } else { |
437 | 437 | $this->form(); |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | } |
440 | 440 | } |
441 | 441 | |
442 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
442 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
443 | 443 | $this->save_payment_method_checkbox(); |
444 | 444 | } |
445 | 445 | |
@@ -454,12 +454,12 @@ discard block |
||
454 | 454 | */ |
455 | 455 | public function elements_form() { |
456 | 456 | ?> |
457 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
458 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
457 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
458 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
459 | 459 | |
460 | - <?php if ( $this->inline_cc_form ) { ?> |
|
460 | + <?php if ($this->inline_cc_form) { ?> |
|
461 | 461 | <label for="card-element"> |
462 | - <?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?> |
|
462 | + <?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?> |
|
463 | 463 | </label> |
464 | 464 | |
465 | 465 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | </div> |
468 | 468 | <?php } else { ?> |
469 | 469 | <div class="form-row form-row-wide"> |
470 | - <label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
470 | + <label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
471 | 471 | |
472 | 472 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
473 | 473 | <!-- a Stripe Element will be inserted here. --> |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | </div> |
476 | 476 | |
477 | 477 | <div class="form-row form-row-first"> |
478 | - <label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
478 | + <label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
479 | 479 | |
480 | 480 | <div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
481 | 481 | <!-- a Stripe Element will be inserted here. --> |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | </div> |
484 | 484 | |
485 | 485 | <div class="form-row form-row-last"> |
486 | - <label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
486 | + <label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
487 | 487 | <div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
488 | 488 | <!-- a Stripe Element will be inserted here. --> |
489 | 489 | </div> |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | |
494 | 494 | <!-- Used to display form errors --> |
495 | 495 | <div class="stripe-source-errors" role="alert"></div> |
496 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
496 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
497 | 497 | <div class="clear"></div> |
498 | 498 | </fieldset> |
499 | 499 | <?php |
@@ -506,13 +506,13 @@ discard block |
||
506 | 506 | * @version 3.1.0 |
507 | 507 | */ |
508 | 508 | public function admin_scripts() { |
509 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
509 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
510 | 510 | return; |
511 | 511 | } |
512 | 512 | |
513 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
513 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
514 | 514 | |
515 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
515 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | /** |
@@ -524,29 +524,29 @@ discard block |
||
524 | 524 | * @version 4.0.0 |
525 | 525 | */ |
526 | 526 | public function payment_scripts() { |
527 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
527 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
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 | - wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' ); |
|
534 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
535 | - wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true ); |
|
536 | - wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true ); |
|
537 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
538 | - wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripev2', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
533 | + wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5'); |
|
534 | + wp_enqueue_style('stripe_paymentfonts'); |
|
535 | + wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true); |
|
536 | + wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true); |
|
537 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
538 | + wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripev2', 'stripe'), WC_STRIPE_VERSION, true); |
|
539 | 539 | |
540 | 540 | $stripe_params = array( |
541 | 541 | 'key' => $this->publishable_key, |
542 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
543 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
542 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
543 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
544 | 544 | ); |
545 | 545 | |
546 | 546 | // If we're on the pay page we need to pass stripe.js the address of the order. |
547 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
548 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
549 | - $order = wc_get_order( $order_id ); |
|
547 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
548 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
549 | + $order = wc_get_order($order_id); |
|
550 | 550 | |
551 | 551 | $stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
552 | 552 | $stripe_params['billing_last_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
@@ -558,37 +558,37 @@ discard block |
||
558 | 558 | $stripe_params['billing_country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
559 | 559 | } |
560 | 560 | |
561 | - $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
562 | - $stripe_params['no_bank_country_msg'] = __( 'Please select a country for your bank.', 'woocommerce-gateway-stripe' ); |
|
563 | - $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
564 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
565 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
561 | + $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
562 | + $stripe_params['no_bank_country_msg'] = __('Please select a country for your bank.', 'woocommerce-gateway-stripe'); |
|
563 | + $stripe_params['no_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
564 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
565 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
566 | 566 | $stripe_params['inline_cc_form'] = $this->inline_cc_form ? 'yes' : 'no'; |
567 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
568 | - $stripe_params['is_checkout'] = ( is_checkout() && empty( $_GET['pay_for_order'] ) ); |
|
567 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
568 | + $stripe_params['is_checkout'] = (is_checkout() && empty($_GET['pay_for_order'])); |
|
569 | 569 | $stripe_params['return_url'] = $this->get_stripe_return_url(); |
570 | - $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); |
|
571 | - $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); |
|
570 | + $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint('%%endpoint%%'); |
|
571 | + $stripe_params['stripe_nonce'] = wp_create_nonce('_wc_stripe_nonce'); |
|
572 | 572 | $stripe_params['statement_descriptor'] = $this->statement_descriptor; |
573 | - $stripe_params['use_elements'] = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no'; |
|
573 | + $stripe_params['use_elements'] = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no'; |
|
574 | 574 | $stripe_params['is_stripe_checkout'] = $this->stripe_checkout ? 'yes' : 'no'; |
575 | - $stripe_params['is_change_payment_page'] = ( isset( $_GET['pay_for_order'] ) || isset( $_GET['change_payment_method'] ) ) ? 'yes' : 'no'; |
|
575 | + $stripe_params['is_change_payment_page'] = (isset($_GET['pay_for_order']) || isset($_GET['change_payment_method'])) ? 'yes' : 'no'; |
|
576 | 576 | $stripe_params['is_add_payment_method_page'] = is_add_payment_method_page() ? 'yes' : 'no'; |
577 | - $stripe_params['elements_styling'] = apply_filters( 'wc_stripe_elements_styling', false ); |
|
578 | - $stripe_params['elements_classes'] = apply_filters( 'wc_stripe_elements_classes', false ); |
|
577 | + $stripe_params['elements_styling'] = apply_filters('wc_stripe_elements_styling', false); |
|
578 | + $stripe_params['elements_classes'] = apply_filters('wc_stripe_elements_classes', false); |
|
579 | 579 | |
580 | 580 | // merge localized messages to be use in JS |
581 | - $stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() ); |
|
581 | + $stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages()); |
|
582 | 582 | |
583 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
584 | - wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
583 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
584 | + wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
585 | 585 | |
586 | - if ( $this->stripe_checkout ) { |
|
587 | - wp_enqueue_script( 'stripe_checkout' ); |
|
586 | + if ($this->stripe_checkout) { |
|
587 | + wp_enqueue_script('stripe_checkout'); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | $this->tokenization_script(); |
591 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
591 | + wp_enqueue_script('woocommerce_stripe'); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | /** |
@@ -600,22 +600,22 @@ discard block |
||
600 | 600 | * @param object $source_object |
601 | 601 | * @return mixed |
602 | 602 | */ |
603 | - public function create_3ds_source( $order, $source_object ) { |
|
603 | + public function create_3ds_source($order, $source_object) { |
|
604 | 604 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
605 | 605 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
606 | - $return_url = $this->get_stripe_return_url( $order ); |
|
606 | + $return_url = $this->get_stripe_return_url($order); |
|
607 | 607 | |
608 | 608 | $post_data = array(); |
609 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
610 | - $post_data['currency'] = strtolower( $currency ); |
|
609 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
610 | + $post_data['currency'] = strtolower($currency); |
|
611 | 611 | $post_data['type'] = 'three_d_secure'; |
612 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
613 | - $post_data['three_d_secure'] = array( 'card' => $source_object->id ); |
|
614 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
612 | + $post_data['owner'] = $this->get_owner_details($order); |
|
613 | + $post_data['three_d_secure'] = array('card' => $source_object->id); |
|
614 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
615 | 615 | |
616 | - WC_Stripe_Logger::log( 'Info: Begin creating 3DS source' ); |
|
616 | + WC_Stripe_Logger::log('Info: Begin creating 3DS source'); |
|
617 | 617 | |
618 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
618 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | /** |
@@ -631,45 +631,45 @@ discard block |
||
631 | 631 | * |
632 | 632 | * @return array|void |
633 | 633 | */ |
634 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
634 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
635 | 635 | try { |
636 | - $order = wc_get_order( $order_id ); |
|
636 | + $order = wc_get_order($order_id); |
|
637 | 637 | |
638 | 638 | // This comes from the create account checkbox in the checkout page. |
639 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
639 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
640 | 640 | |
641 | - if ( $create_account ) { |
|
641 | + if ($create_account) { |
|
642 | 642 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
643 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
643 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
644 | 644 | $new_stripe_customer->create_customer(); |
645 | 645 | } |
646 | 646 | |
647 | 647 | $source_object = $this->create_source_object(); |
648 | 648 | |
649 | - $prepared_source = $this->prepare_source( $source_object, get_current_user_id(), $force_save_source ); |
|
649 | + $prepared_source = $this->prepare_source($source_object, get_current_user_id(), $force_save_source); |
|
650 | 650 | |
651 | 651 | // Check if we don't allow prepaid credit cards. |
652 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) { |
|
653 | - if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) { |
|
654 | - $localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
655 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message ); |
|
652 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) { |
|
653 | + if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) { |
|
654 | + $localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
655 | + throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message); |
|
656 | 656 | } |
657 | 657 | } |
658 | 658 | |
659 | - if ( empty( $prepared_source->source ) ) { |
|
660 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
661 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
659 | + if (empty($prepared_source->source)) { |
|
660 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
661 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
662 | 662 | } |
663 | 663 | |
664 | 664 | // Store source to order meta. |
665 | - $this->save_source( $order, $prepared_source ); |
|
665 | + $this->save_source($order, $prepared_source); |
|
666 | 666 | |
667 | 667 | // Result from Stripe API request. |
668 | 668 | $response = null; |
669 | 669 | |
670 | - if ( $order->get_total() > 0 ) { |
|
670 | + if ($order->get_total() > 0) { |
|
671 | 671 | // This will throw exception if not valid. |
672 | - $this->validate_minimum_order_amount( $order ); |
|
672 | + $this->validate_minimum_order_amount($order); |
|
673 | 673 | |
674 | 674 | /** |
675 | 675 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -678,83 +678,83 @@ discard block |
||
678 | 678 | * Note that if we need to save source, the original source must be first |
679 | 679 | * attached to a customer in Stripe before it can be charged. |
680 | 680 | */ |
681 | - if ( ( $source_object && ! empty( $source_object->card ) ) && ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) ) ) { |
|
681 | + if (($source_object && ! empty($source_object->card)) && ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure))) { |
|
682 | 682 | |
683 | - $response = $this->create_3ds_source( $order, $source_object ); |
|
683 | + $response = $this->create_3ds_source($order, $source_object); |
|
684 | 684 | |
685 | - if ( ! empty( $response->error ) ) { |
|
685 | + if ( ! empty($response->error)) { |
|
686 | 686 | $localized_message = $response->error->message; |
687 | 687 | |
688 | - $order->add_order_note( $localized_message ); |
|
688 | + $order->add_order_note($localized_message); |
|
689 | 689 | |
690 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
690 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | // Update order meta with 3DS source. |
694 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
695 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
694 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
695 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
696 | 696 | } else { |
697 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
697 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
698 | 698 | $order->save(); |
699 | 699 | } |
700 | 700 | |
701 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
701 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
702 | 702 | |
703 | 703 | return array( |
704 | 704 | 'result' => 'success', |
705 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
705 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
706 | 706 | ); |
707 | 707 | } |
708 | 708 | |
709 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
709 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
710 | 710 | |
711 | 711 | // Make the request. |
712 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
712 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
713 | 713 | |
714 | - if ( ! empty( $response->error ) ) { |
|
714 | + if ( ! empty($response->error)) { |
|
715 | 715 | // If it is an API error such connection or server, let's retry. |
716 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
717 | - if ( $retry ) { |
|
718 | - sleep( 5 ); |
|
719 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
716 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
717 | + if ($retry) { |
|
718 | + sleep(5); |
|
719 | + return $this->process_payment($order_id, false, $force_save_source); |
|
720 | 720 | } else { |
721 | 721 | $localized_message = 'API connection error and retries exhausted.'; |
722 | - $order->add_order_note( $localized_message ); |
|
723 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
722 | + $order->add_order_note($localized_message); |
|
723 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
724 | 724 | } |
725 | 725 | } |
726 | 726 | |
727 | 727 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
728 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
729 | - delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
728 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
729 | + delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id'); |
|
730 | 730 | |
731 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
732 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) { |
|
731 | + return $this->process_payment($order_id, false, $force_save_source); |
|
732 | + } elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) { |
|
733 | 733 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
734 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
734 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
735 | 735 | $wc_token->delete(); |
736 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
737 | - $order->add_order_note( $localized_message ); |
|
738 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
736 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
737 | + $order->add_order_note($localized_message); |
|
738 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
739 | 739 | } |
740 | 740 | |
741 | 741 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
742 | 742 | |
743 | - if ( 'card_error' === $response->error->type ) { |
|
744 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
743 | + if ('card_error' === $response->error->type) { |
|
744 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
745 | 745 | } else { |
746 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
746 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
747 | 747 | } |
748 | 748 | |
749 | - $order->add_order_note( $localized_message ); |
|
749 | + $order->add_order_note($localized_message); |
|
750 | 750 | |
751 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
751 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
752 | 752 | } |
753 | 753 | |
754 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
754 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
755 | 755 | |
756 | 756 | // Process valid response. |
757 | - $this->process_response( $response, $order ); |
|
757 | + $this->process_response($response, $order); |
|
758 | 758 | } else { |
759 | 759 | $order->payment_complete(); |
760 | 760 | } |
@@ -765,17 +765,17 @@ discard block |
||
765 | 765 | // Return thank you page redirect. |
766 | 766 | return array( |
767 | 767 | 'result' => 'success', |
768 | - 'redirect' => $this->get_return_url( $order ), |
|
768 | + 'redirect' => $this->get_return_url($order), |
|
769 | 769 | ); |
770 | 770 | |
771 | - } catch ( WC_Stripe_Exception $e ) { |
|
772 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
773 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
771 | + } catch (WC_Stripe_Exception $e) { |
|
772 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
773 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
774 | 774 | |
775 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
775 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
776 | 776 | |
777 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
778 | - $this->send_failed_order_email( $order_id ); |
|
777 | + if ($order->has_status(array('pending', 'failed'))) { |
|
778 | + $this->send_failed_order_email($order_id); |
|
779 | 779 | } |
780 | 780 | |
781 | 781 | return array( |