@@ -15,20 +15,20 @@ discard block |
||
15 | 15 | * |
16 | 16 | */ |
17 | 17 | |
18 | -if ( ! defined( 'ABSPATH' ) ) { |
|
18 | +if ( ! defined('ABSPATH')) { |
|
19 | 19 | exit; |
20 | 20 | } |
21 | 21 | |
22 | -if ( ! class_exists( 'WC_Stripe' ) ) : |
|
22 | +if ( ! class_exists('WC_Stripe')) : |
|
23 | 23 | /** |
24 | 24 | * Required minimums and constants |
25 | 25 | */ |
26 | - define( 'WC_STRIPE_VERSION', '4.0.7' ); |
|
27 | - define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' ); |
|
28 | - define( 'WC_STRIPE_MIN_WC_VER', '2.6.0' ); |
|
29 | - define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
30 | - define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
31 | - define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
|
26 | + define('WC_STRIPE_VERSION', '4.0.7'); |
|
27 | + define('WC_STRIPE_MIN_PHP_VER', '5.6.0'); |
|
28 | + define('WC_STRIPE_MIN_WC_VER', '2.6.0'); |
|
29 | + define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
30 | + define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
31 | + define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); |
|
32 | 32 | |
33 | 33 | class WC_Stripe { |
34 | 34 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @return Singleton The *Singleton* instance. |
49 | 49 | */ |
50 | 50 | public static function get_instance() { |
51 | - if ( null === self::$instance ) { |
|
51 | + if (null === self::$instance) { |
|
52 | 52 | self::$instance = new self(); |
53 | 53 | } |
54 | 54 | return self::$instance; |
@@ -81,10 +81,10 @@ discard block |
||
81 | 81 | * *Singleton* via the `new` operator from outside of this class. |
82 | 82 | */ |
83 | 83 | private function __construct() { |
84 | - add_action( 'admin_init', array( $this, 'check_environment' ) ); |
|
85 | - add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 ); |
|
86 | - add_action( 'plugins_loaded', array( $this, 'init' ) ); |
|
87 | - add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
84 | + add_action('admin_init', array($this, 'check_environment')); |
|
85 | + add_action('admin_notices', array($this, 'admin_notices'), 15); |
|
86 | + add_action('plugins_loaded', array($this, 'init')); |
|
87 | + add_action('wp_loaded', array($this, 'hide_notices')); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -94,44 +94,44 @@ discard block |
||
94 | 94 | * @version 4.0.0 |
95 | 95 | */ |
96 | 96 | public function init() { |
97 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php' ); |
|
98 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php' ); |
|
99 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php' ); |
|
100 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
97 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-exception.php'); |
|
98 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-logger.php'); |
|
99 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-helper.php'); |
|
100 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
101 | 101 | |
102 | 102 | // Don't hook anything else in the plugin if we're in an incompatible environment. |
103 | - if ( self::get_environment_warning() ) { |
|
103 | + if (self::get_environment_warning()) { |
|
104 | 104 | return; |
105 | 105 | } |
106 | 106 | |
107 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
108 | - |
|
109 | - require_once( dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php' ); |
|
110 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php' ); |
|
111 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php' ); |
|
112 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay-registration.php' ); |
|
113 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' ); |
|
114 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php' ); |
|
115 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php' ); |
|
116 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php' ); |
|
117 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php' ); |
|
118 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php' ); |
|
119 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php' ); |
|
120 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php' ); |
|
121 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php' ); |
|
122 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php' ); |
|
123 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-compat.php' ); |
|
124 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-compat.php' ); |
|
125 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php' ); |
|
126 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php' ); |
|
127 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' ); |
|
107 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
108 | + |
|
109 | + require_once(dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'); |
|
110 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php'); |
|
111 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php'); |
|
112 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay-registration.php'); |
|
113 | + require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'); |
|
114 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'); |
|
115 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'); |
|
116 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'); |
|
117 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'); |
|
118 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'); |
|
119 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'); |
|
120 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'); |
|
121 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php'); |
|
122 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php'); |
|
123 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-compat.php'); |
|
124 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-compat.php'); |
|
125 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php'); |
|
126 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php'); |
|
127 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'); |
|
128 | 128 | |
129 | 129 | // REMOVE IN THE FUTURE. |
130 | - require_once( dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php' ); |
|
130 | + require_once(dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php'); |
|
131 | 131 | |
132 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
133 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
134 | - add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); |
|
132 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
133 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
134 | + add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin')); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -141,23 +141,23 @@ discard block |
||
141 | 141 | * @version 4.0.0 |
142 | 142 | */ |
143 | 143 | public function hide_notices() { |
144 | - if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) { |
|
145 | - if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) { |
|
146 | - wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) ); |
|
144 | + if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) { |
|
145 | + if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) { |
|
146 | + wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe')); |
|
147 | 147 | } |
148 | 148 | |
149 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
150 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
149 | + if ( ! current_user_can('manage_woocommerce')) { |
|
150 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
151 | 151 | } |
152 | 152 | |
153 | - $notice = wc_clean( $_GET['wc-stripe-hide-notice'] ); |
|
153 | + $notice = wc_clean($_GET['wc-stripe-hide-notice']); |
|
154 | 154 | |
155 | - switch ( $notice ) { |
|
155 | + switch ($notice) { |
|
156 | 156 | case 'ssl': |
157 | - update_option( 'wc_stripe_show_ssl_notice', 'no' ); |
|
157 | + update_option('wc_stripe_show_ssl_notice', 'no'); |
|
158 | 158 | break; |
159 | 159 | case 'keys': |
160 | - update_option( 'wc_stripe_show_keys_notice', 'no' ); |
|
160 | + update_option('wc_stripe_show_keys_notice', 'no'); |
|
161 | 161 | break; |
162 | 162 | } |
163 | 163 | } |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | * @since 1.0.0 |
170 | 170 | * @version 4.0.0 |
171 | 171 | */ |
172 | - public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
|
173 | - $this->notices[ $slug ] = array( |
|
172 | + public function add_admin_notice($slug, $class, $message, $dismissible = false) { |
|
173 | + $this->notices[$slug] = array( |
|
174 | 174 | 'class' => $class, |
175 | 175 | 'message' => $message, |
176 | 176 | 'dismissible' => $dismissible, |
@@ -184,21 +184,21 @@ discard block |
||
184 | 184 | * @version 4.0.0 |
185 | 185 | */ |
186 | 186 | public function admin_notices() { |
187 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
187 | + if ( ! current_user_can('manage_woocommerce')) { |
|
188 | 188 | return; |
189 | 189 | } |
190 | 190 | |
191 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
192 | - echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">'; |
|
191 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
192 | + echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">'; |
|
193 | 193 | |
194 | - if ( $notice['dismissible'] ) { |
|
194 | + if ($notice['dismissible']) { |
|
195 | 195 | ?> |
196 | - <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> |
|
196 | + <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> |
|
197 | 197 | <?php |
198 | 198 | } |
199 | 199 | |
200 | 200 | echo '<p>'; |
201 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
201 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
202 | 202 | echo '</p></div>'; |
203 | 203 | } |
204 | 204 | } |
@@ -211,26 +211,26 @@ discard block |
||
211 | 211 | * @version 4.0.0 |
212 | 212 | */ |
213 | 213 | public function get_environment_warning() { |
214 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
214 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
215 | 215 | /* translators: 1) int version 2) int version */ |
216 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
216 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
217 | 217 | |
218 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
218 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
219 | 219 | } |
220 | 220 | |
221 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
222 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
221 | + if ( ! defined('WC_VERSION')) { |
|
222 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
223 | 223 | } |
224 | 224 | |
225 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
225 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
226 | 226 | /* translators: 1) int version 2) int version */ |
227 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
227 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
228 | 228 | |
229 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
229 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
230 | 230 | } |
231 | 231 | |
232 | - if ( ! function_exists( 'curl_init' ) ) { |
|
233 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
232 | + if ( ! function_exists('curl_init')) { |
|
233 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | return false; |
@@ -244,11 +244,11 @@ discard block |
||
244 | 244 | * @return string Setting link |
245 | 245 | */ |
246 | 246 | public function get_setting_link() { |
247 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
247 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
248 | 248 | |
249 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
249 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
250 | 250 | |
251 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
251 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
@@ -259,65 +259,65 @@ discard block |
||
259 | 259 | * @version 4.0.0 |
260 | 260 | */ |
261 | 261 | public function check_environment() { |
262 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
|
262 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) { |
|
263 | 263 | $this->install(); |
264 | 264 | |
265 | - do_action( 'woocommerce_stripe_updated' ); |
|
265 | + do_action('woocommerce_stripe_updated'); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | $environment_warning = $this->get_environment_warning(); |
269 | 269 | |
270 | - if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
271 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
270 | + if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) { |
|
271 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
272 | 272 | } |
273 | 273 | |
274 | - $show_ssl_notice = get_option( 'wc_stripe_show_ssl_notice' ); |
|
275 | - $show_keys_notice = get_option( 'wc_stripe_show_keys_notice' ); |
|
276 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
277 | - $testmode = ( isset( $options['testmode'] ) && 'yes' === $options['testmode'] ) ? true : false; |
|
278 | - $test_pub_key = isset( $options['test_publishable_key'] ) ? $options['test_publishable_key'] : ''; |
|
279 | - $test_secret_key = isset( $options['test_secret_key'] ) ? $options['test_secret_key'] : ''; |
|
280 | - $live_pub_key = isset( $options['publishable_key'] ) ? $options['publishable_key'] : ''; |
|
281 | - $live_secret_key = isset( $options['secret_key'] ) ? $options['secret_key'] : ''; |
|
274 | + $show_ssl_notice = get_option('wc_stripe_show_ssl_notice'); |
|
275 | + $show_keys_notice = get_option('wc_stripe_show_keys_notice'); |
|
276 | + $options = get_option('woocommerce_stripe_settings'); |
|
277 | + $testmode = (isset($options['testmode']) && 'yes' === $options['testmode']) ? true : false; |
|
278 | + $test_pub_key = isset($options['test_publishable_key']) ? $options['test_publishable_key'] : ''; |
|
279 | + $test_secret_key = isset($options['test_secret_key']) ? $options['test_secret_key'] : ''; |
|
280 | + $live_pub_key = isset($options['publishable_key']) ? $options['publishable_key'] : ''; |
|
281 | + $live_secret_key = isset($options['secret_key']) ? $options['secret_key'] : ''; |
|
282 | 282 | |
283 | - if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] && empty( $show_keys_notice ) ) { |
|
284 | - $secret = WC_Stripe_API::get_secret_key(); |
|
283 | + if (isset($options['enabled']) && 'yes' === $options['enabled'] && empty($show_keys_notice)) { |
|
284 | + $secret = WC_Stripe_API::get_secret_key(); |
|
285 | 285 | |
286 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
286 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
287 | 287 | $setting_link = $this->get_setting_link(); |
288 | 288 | /* translators: 1) link */ |
289 | - $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 ); |
|
289 | + $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); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | // Check if keys are entered properly per live/test mode. |
293 | - if ( $testmode ) { |
|
293 | + if ($testmode) { |
|
294 | 294 | if ( |
295 | - ! empty( $test_pub_key ) && ! preg_match( '/^pk_test_/', $test_pub_key ) |
|
296 | - || ( ! empty( $test_secret_key ) && ! preg_match( '/^sk_test_/', $test_secret_key ) |
|
297 | - && ! empty( $test_secret_key ) && ! preg_match( '/^rk_test_/', $test_secret_key ) ) ) |
|
295 | + ! empty($test_pub_key) && ! preg_match('/^pk_test_/', $test_pub_key) |
|
296 | + || ( ! empty($test_secret_key) && ! preg_match('/^sk_test_/', $test_secret_key) |
|
297 | + && ! empty($test_secret_key) && ! preg_match('/^rk_test_/', $test_secret_key)) ) |
|
298 | 298 | { |
299 | 299 | $setting_link = $this->get_setting_link(); |
300 | 300 | /* translators: 1) link */ |
301 | - $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 ); |
|
301 | + $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); |
|
302 | 302 | } |
303 | 303 | } else { |
304 | 304 | if ( |
305 | - ! empty( $live_pub_key ) && ! preg_match( '/^pk_live_/', $live_pub_key ) |
|
306 | - || ( ! empty( $live_secret_key ) && ! preg_match( '/^sk_live_/', $live_secret_key ) |
|
307 | - && ! empty( $live_secret_key ) && ! preg_match( '/^rk_live_/', $live_secret_key ) ) ) |
|
305 | + ! empty($live_pub_key) && ! preg_match('/^pk_live_/', $live_pub_key) |
|
306 | + || ( ! empty($live_secret_key) && ! preg_match('/^sk_live_/', $live_secret_key) |
|
307 | + && ! empty($live_secret_key) && ! preg_match('/^rk_live_/', $live_secret_key)) ) |
|
308 | 308 | { |
309 | 309 | $setting_link = $this->get_setting_link(); |
310 | 310 | /* translators: 1) link */ |
311 | - $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 ); |
|
311 | + $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); |
|
312 | 312 | } |
313 | 313 | } |
314 | 314 | } |
315 | 315 | |
316 | - if ( empty( $show_ssl_notice ) && isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) { |
|
316 | + if (empty($show_ssl_notice) && isset($options['enabled']) && 'yes' === $options['enabled']) { |
|
317 | 317 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
318 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
318 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
319 | 319 | /* translators: 1) link 2) link */ |
320 | - $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 ); |
|
320 | + $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); |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | } |
@@ -329,8 +329,8 @@ discard block |
||
329 | 329 | * @version 4.0.0 |
330 | 330 | */ |
331 | 331 | public function update_plugin_version() { |
332 | - delete_option( 'wc_stripe_version' ); |
|
333 | - update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
332 | + delete_option('wc_stripe_version'); |
|
333 | + update_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -340,8 +340,8 @@ discard block |
||
340 | 340 | * @version 3.1.0 |
341 | 341 | */ |
342 | 342 | public function install() { |
343 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
344 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
343 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
344 | + define('WC_STRIPE_INSTALLING', true); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | $this->update_plugin_version(); |
@@ -353,13 +353,13 @@ discard block |
||
353 | 353 | * @since 1.0.0 |
354 | 354 | * @version 4.0.0 |
355 | 355 | */ |
356 | - public function plugin_action_links( $links ) { |
|
356 | + public function plugin_action_links($links) { |
|
357 | 357 | $plugin_links = array( |
358 | - '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
359 | - '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
360 | - '<a href="https://woocommerce.com/contact-us/">' . esc_html__( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
358 | + '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
359 | + '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
360 | + '<a href="https://woocommerce.com/contact-us/">' . esc_html__('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
361 | 361 | ); |
362 | - return array_merge( $plugin_links, $links ); |
|
362 | + return array_merge($plugin_links, $links); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -368,8 +368,8 @@ discard block |
||
368 | 368 | * @since 1.0.0 |
369 | 369 | * @version 4.0.0 |
370 | 370 | */ |
371 | - public function add_gateways( $methods ) { |
|
372 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
371 | + public function add_gateways($methods) { |
|
372 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order') || class_exists('WC_Pre_Orders_Order')) { |
|
373 | 373 | $methods[] = 'WC_Stripe_Compat'; |
374 | 374 | $methods[] = 'WC_Stripe_Sepa_Compat'; |
375 | 375 | } else { |
@@ -394,26 +394,26 @@ discard block |
||
394 | 394 | * @since 4.0.0 |
395 | 395 | * @version 4.0.0 |
396 | 396 | */ |
397 | - public function filter_gateway_order_admin( $sections ) { |
|
398 | - unset( $sections['stripe'] ); |
|
399 | - unset( $sections['stripe_bancontact'] ); |
|
400 | - unset( $sections['stripe_sofort'] ); |
|
401 | - unset( $sections['stripe_giropay'] ); |
|
402 | - unset( $sections['stripe_ideal'] ); |
|
403 | - unset( $sections['stripe_p24'] ); |
|
404 | - unset( $sections['stripe_alipay'] ); |
|
405 | - unset( $sections['stripe_sepa'] ); |
|
406 | - unset( $sections['stripe_bitcoin'] ); |
|
397 | + public function filter_gateway_order_admin($sections) { |
|
398 | + unset($sections['stripe']); |
|
399 | + unset($sections['stripe_bancontact']); |
|
400 | + unset($sections['stripe_sofort']); |
|
401 | + unset($sections['stripe_giropay']); |
|
402 | + unset($sections['stripe_ideal']); |
|
403 | + unset($sections['stripe_p24']); |
|
404 | + unset($sections['stripe_alipay']); |
|
405 | + unset($sections['stripe_sepa']); |
|
406 | + unset($sections['stripe_bitcoin']); |
|
407 | 407 | |
408 | 408 | $sections['stripe'] = 'Stripe'; |
409 | - $sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
410 | - $sections['stripe_sofort'] = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
411 | - $sections['stripe_giropay'] = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
412 | - $sections['stripe_ideal'] = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
413 | - $sections['stripe_p24'] = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
414 | - $sections['stripe_alipay'] = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
415 | - $sections['stripe_sepa'] = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
416 | - $sections['stripe_bitcoin'] = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
409 | + $sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
410 | + $sections['stripe_sofort'] = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
411 | + $sections['stripe_giropay'] = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
412 | + $sections['stripe_ideal'] = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
413 | + $sections['stripe_p24'] = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
414 | + $sections['stripe_alipay'] = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
415 | + $sections['stripe_sepa'] = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
416 | + $sections['stripe_bitcoin'] = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
417 | 417 | |
418 | 418 | return $sections; |
419 | 419 | } |
@@ -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,7 +21,7 @@ discard block |
||
21 | 21 | * @since 4.0.5 |
22 | 22 | * @param array $error |
23 | 23 | */ |
24 | - public function is_retryable_error( $error ) { |
|
24 | + public function is_retryable_error($error) { |
|
25 | 25 | return ( |
26 | 26 | 'invalid_request_error' === $error->type || |
27 | 27 | 'idempotency_error' === $error->type || |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | * Check if this gateway is enabled |
36 | 36 | */ |
37 | 37 | public function is_available() { |
38 | - if ( 'yes' === $this->enabled ) { |
|
39 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
38 | + if ('yes' === $this->enabled) { |
|
39 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
40 | 40 | return false; |
41 | 41 | } |
42 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
42 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
43 | 43 | return false; |
44 | 44 | } |
45 | 45 | return true; |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | * @since 4.0.0 |
55 | 55 | * @version 4.0.0 |
56 | 56 | */ |
57 | - public function add_admin_notice( $slug, $class, $message ) { |
|
58 | - $this->notices[ $slug ] = array( |
|
57 | + public function add_admin_notice($slug, $class, $message) { |
|
58 | + $this->notices[$slug] = array( |
|
59 | 59 | 'class' => $class, |
60 | 60 | 'message' => $message, |
61 | 61 | ); |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | * @version 4.0.0 |
69 | 69 | */ |
70 | 70 | public function remove_admin_notice() { |
71 | - if ( did_action( 'woocommerce_update_options' ) ) { |
|
72 | - remove_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
71 | + if (did_action('woocommerce_update_options')) { |
|
72 | + remove_action('admin_notices', array($this, 'check_environment')); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * @return array |
82 | 82 | */ |
83 | 83 | public function payment_icons() { |
84 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
84 | + return apply_filters('wc_stripe_payment_icons', array( |
|
85 | 85 | 'visa' => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>', |
86 | 86 | 'amex' => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>', |
87 | 87 | 'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>', |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | 'eps' => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>', |
99 | 99 | 'sofort' => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>', |
100 | 100 | 'sepa' => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>', |
101 | - ) ); |
|
101 | + )); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -109,10 +109,10 @@ discard block |
||
109 | 109 | * @version 4.0.0 |
110 | 110 | * @param object $order |
111 | 111 | */ |
112 | - public function validate_minimum_order_amount( $order ) { |
|
113 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
112 | + public function validate_minimum_order_amount($order) { |
|
113 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
114 | 114 | /* translators: 1) dollar amount */ |
115 | - throw new WC_Stripe_Exception( 'Did not meet minimum amount', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
115 | + throw new WC_Stripe_Exception('Did not meet minimum amount', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
@@ -122,14 +122,14 @@ discard block |
||
122 | 122 | * @since 4.0.0 |
123 | 123 | * @version 4.0.0 |
124 | 124 | */ |
125 | - public function get_transaction_url( $order ) { |
|
126 | - if ( $this->testmode ) { |
|
125 | + public function get_transaction_url($order) { |
|
126 | + if ($this->testmode) { |
|
127 | 127 | $this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s'; |
128 | 128 | } else { |
129 | 129 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
130 | 130 | } |
131 | 131 | |
132 | - return parent::get_transaction_url( $order ); |
|
132 | + return parent::get_transaction_url($order); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -138,15 +138,15 @@ discard block |
||
138 | 138 | * @since 4.0.0 |
139 | 139 | * @version 4.0.0 |
140 | 140 | */ |
141 | - public function get_stripe_customer_id( $order ) { |
|
142 | - $customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true ); |
|
141 | + public function get_stripe_customer_id($order) { |
|
142 | + $customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true); |
|
143 | 143 | |
144 | - if ( empty( $customer ) ) { |
|
144 | + if (empty($customer)) { |
|
145 | 145 | // Try to get it via the order. |
146 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
147 | - return get_post_meta( $order->id, '_stripe_customer_id', true ); |
|
146 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
147 | + return get_post_meta($order->id, '_stripe_customer_id', true); |
|
148 | 148 | } else { |
149 | - return $order->get_meta( '_stripe_customer_id', true ); |
|
149 | + return $order->get_meta('_stripe_customer_id', true); |
|
150 | 150 | } |
151 | 151 | } else { |
152 | 152 | return $customer; |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | * @param object $order |
164 | 164 | * @param int $id Stripe session id. |
165 | 165 | */ |
166 | - public function get_stripe_return_url( $order = null, $id = null ) { |
|
167 | - if ( is_object( $order ) ) { |
|
168 | - if ( empty( $id ) ) { |
|
166 | + public function get_stripe_return_url($order = null, $id = null) { |
|
167 | + if (is_object($order)) { |
|
168 | + if (empty($id)) { |
|
169 | 169 | $id = uniqid(); |
170 | 170 | } |
171 | 171 | |
@@ -176,10 +176,10 @@ discard block |
||
176 | 176 | 'order_id' => $order_id, |
177 | 177 | ); |
178 | 178 | |
179 | - return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ); |
|
179 | + return esc_url_raw(add_query_arg($args, $this->get_return_url($order))); |
|
180 | 180 | } |
181 | 181 | |
182 | - return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ); |
|
182 | + return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -187,8 +187,8 @@ discard block |
||
187 | 187 | * @param int $order_id |
188 | 188 | * @return boolean |
189 | 189 | */ |
190 | - public function has_subscription( $order_id ) { |
|
191 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
190 | + public function has_subscription($order_id) { |
|
191 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -200,34 +200,33 @@ discard block |
||
200 | 200 | * @param object $prepared_source |
201 | 201 | * @return array() |
202 | 202 | */ |
203 | - public function generate_payment_request( $order, $prepared_source ) { |
|
204 | - $settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
205 | - $statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : ''; |
|
206 | - $capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false; |
|
203 | + public function generate_payment_request($order, $prepared_source) { |
|
204 | + $settings = get_option('woocommerce_stripe_settings', array()); |
|
205 | + $statement_descriptor = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : ''; |
|
206 | + $capture = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false; |
|
207 | 207 | $post_data = array(); |
208 | - $post_data['currency'] = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() ); |
|
209 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
208 | + $post_data['currency'] = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency()); |
|
209 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
210 | 210 | /* translators: 1) blog name 2) order number */ |
211 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
211 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
212 | 212 | $billing_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
213 | 213 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
214 | 214 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
215 | 215 | |
216 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
216 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
217 | 217 | $post_data['receipt_email'] = $billing_email; |
218 | 218 | } |
219 | 219 | |
220 | - switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) { |
|
221 | - case 'stripe': |
|
222 | - if ( ! empty( $statement_descriptor ) ) { |
|
223 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
220 | + switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) { |
|
221 | + case 'stripe' : if ( ! empty($statement_descriptor)) { |
|
222 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
224 | 223 | } |
225 | 224 | |
226 | 225 | $post_data['capture'] = $capture ? 'true' : 'false'; |
227 | 226 | break; |
228 | 227 | case 'stripe_sepa': |
229 | - if ( ! empty( $statement_descriptor ) ) { |
|
230 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
228 | + if ( ! empty($statement_descriptor)) { |
|
229 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
231 | 230 | } |
232 | 231 | break; |
233 | 232 | } |
@@ -235,25 +234,25 @@ discard block |
||
235 | 234 | $post_data['expand[]'] = 'balance_transaction'; |
236 | 235 | |
237 | 236 | $metadata = array( |
238 | - __( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
239 | - __( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
237 | + __('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
238 | + __('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
240 | 239 | 'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(), |
241 | 240 | ); |
242 | 241 | |
243 | - if ( $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) { |
|
242 | + if ($this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) { |
|
244 | 243 | $metadata += array( |
245 | 244 | 'payment_type' => 'recurring', |
246 | - 'site_url' => esc_url( get_site_url() ), |
|
245 | + 'site_url' => esc_url(get_site_url()), |
|
247 | 246 | ); |
248 | 247 | } |
249 | 248 | |
250 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $prepared_source ); |
|
249 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $prepared_source); |
|
251 | 250 | |
252 | - if ( $prepared_source->customer ) { |
|
251 | + if ($prepared_source->customer) { |
|
253 | 252 | $post_data['customer'] = $prepared_source->customer; |
254 | 253 | } |
255 | 254 | |
256 | - if ( $prepared_source->source ) { |
|
255 | + if ($prepared_source->source) { |
|
257 | 256 | $post_data['source'] = $prepared_source->source; |
258 | 257 | } |
259 | 258 | |
@@ -265,79 +264,79 @@ discard block |
||
265 | 264 | * @param WC_Order $order |
266 | 265 | * @param object $source |
267 | 266 | */ |
268 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $prepared_source ); |
|
267 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $prepared_source); |
|
269 | 268 | } |
270 | 269 | |
271 | 270 | /** |
272 | 271 | * Store extra meta data for an order from a Stripe Response. |
273 | 272 | */ |
274 | - public function process_response( $response, $order ) { |
|
275 | - WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) ); |
|
273 | + public function process_response($response, $order) { |
|
274 | + WC_Stripe_Logger::log('Processing response: ' . print_r($response, true)); |
|
276 | 275 | |
277 | 276 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
278 | 277 | |
279 | - $captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no'; |
|
278 | + $captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no'; |
|
280 | 279 | |
281 | 280 | // Store charge data. |
282 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured ); |
|
281 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured); |
|
283 | 282 | |
284 | 283 | // Store other data such as fees. |
285 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
284 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
286 | 285 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
287 | 286 | // values are in the local currency of the Stripe account, not from WC. |
288 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0; |
|
289 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0; |
|
290 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
291 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
287 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0; |
|
288 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0; |
|
289 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
290 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
292 | 291 | } |
293 | 292 | |
294 | - if ( 'yes' === $captured ) { |
|
293 | + if ('yes' === $captured) { |
|
295 | 294 | /** |
296 | 295 | * Charge can be captured but in a pending state. Payment methods |
297 | 296 | * that are asynchronous may take couple days to clear. Webhook will |
298 | 297 | * take care of the status changes. |
299 | 298 | */ |
300 | - if ( 'pending' === $response->status ) { |
|
301 | - $order_stock_reduced = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_order_stock_reduced', true ) : $order->get_meta( '_order_stock_reduced', true ); |
|
299 | + if ('pending' === $response->status) { |
|
300 | + $order_stock_reduced = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_order_stock_reduced', true) : $order->get_meta('_order_stock_reduced', true); |
|
302 | 301 | |
303 | - if ( ! $order_stock_reduced ) { |
|
304 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
302 | + if ( ! $order_stock_reduced) { |
|
303 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
305 | 304 | } |
306 | 305 | |
307 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
306 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
308 | 307 | /* translators: transaction id */ |
309 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
308 | + $order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id)); |
|
310 | 309 | } |
311 | 310 | |
312 | - if ( 'succeeded' === $response->status ) { |
|
313 | - $order->payment_complete( $response->id ); |
|
311 | + if ('succeeded' === $response->status) { |
|
312 | + $order->payment_complete($response->id); |
|
314 | 313 | |
315 | 314 | /* translators: transaction id */ |
316 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
317 | - $order->add_order_note( $message ); |
|
315 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
316 | + $order->add_order_note($message); |
|
318 | 317 | } |
319 | 318 | |
320 | - if ( 'failed' === $response->status ) { |
|
321 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
322 | - $order->add_order_note( $localized_message ); |
|
323 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
319 | + if ('failed' === $response->status) { |
|
320 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
321 | + $order->add_order_note($localized_message); |
|
322 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
324 | 323 | } |
325 | 324 | } else { |
326 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
325 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
327 | 326 | |
328 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
329 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
327 | + if ($order->has_status(array('pending', 'failed'))) { |
|
328 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
330 | 329 | } |
331 | 330 | |
332 | 331 | /* translators: transaction id */ |
333 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
332 | + $order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id)); |
|
334 | 333 | } |
335 | 334 | |
336 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
335 | + if (is_callable(array($order, 'save'))) { |
|
337 | 336 | $order->save(); |
338 | 337 | } |
339 | 338 | |
340 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
339 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
341 | 340 | |
342 | 341 | return $response; |
343 | 342 | } |
@@ -350,10 +349,10 @@ discard block |
||
350 | 349 | * @param int $order_id |
351 | 350 | * @return null |
352 | 351 | */ |
353 | - public function send_failed_order_email( $order_id ) { |
|
352 | + public function send_failed_order_email($order_id) { |
|
354 | 353 | $emails = WC()->mailer()->get_emails(); |
355 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
356 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
354 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
355 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
357 | 356 | } |
358 | 357 | } |
359 | 358 | |
@@ -365,7 +364,7 @@ discard block |
||
365 | 364 | * @param object $order |
366 | 365 | * @return object $details |
367 | 366 | */ |
368 | - public function get_owner_details( $order ) { |
|
367 | + public function get_owner_details($order) { |
|
369 | 368 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
370 | 369 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
371 | 370 | |
@@ -376,8 +375,8 @@ discard block |
||
376 | 375 | |
377 | 376 | $phone = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone(); |
378 | 377 | |
379 | - if ( ! empty( $phone ) ) { |
|
380 | - $details['phone'] = $phone; |
|
378 | + if ( ! empty($phone)) { |
|
379 | + $details['phone'] = $phone; |
|
381 | 380 | } |
382 | 381 | |
383 | 382 | $details['address']['line1'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1(); |
@@ -387,7 +386,7 @@ discard block |
||
387 | 386 | $details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode(); |
388 | 387 | $details['address']['country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
389 | 388 | |
390 | - return (object) apply_filters( 'wc_stripe_owner_details', $details, $order ); |
|
389 | + return (object) apply_filters('wc_stripe_owner_details', $details, $order); |
|
391 | 390 | } |
392 | 391 | |
393 | 392 | /** |
@@ -396,15 +395,15 @@ discard block |
||
396 | 395 | * @since 4.0.3 |
397 | 396 | * @param string $source_id The source ID to get source object for. |
398 | 397 | */ |
399 | - public function get_source_object( $source_id = '' ) { |
|
400 | - if ( empty( $source_id ) ) { |
|
398 | + public function get_source_object($source_id = '') { |
|
399 | + if (empty($source_id)) { |
|
401 | 400 | return ''; |
402 | 401 | } |
403 | 402 | |
404 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id ); |
|
403 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source_id); |
|
405 | 404 | |
406 | - if ( ! empty( $source_object->error ) ) { |
|
407 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message ); |
|
405 | + if ( ! empty($source_object->error)) { |
|
406 | + throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message); |
|
408 | 407 | } |
409 | 408 | |
410 | 409 | return $source_object; |
@@ -417,11 +416,11 @@ discard block |
||
417 | 416 | * @param object $source_object |
418 | 417 | * @return bool |
419 | 418 | */ |
420 | - public function is_3ds_required( $source_object ) { |
|
419 | + public function is_3ds_required($source_object) { |
|
421 | 420 | return ( |
422 | - $source_object && ! empty( $source_object->card ) ) && |
|
423 | - ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
424 | - ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) |
|
421 | + $source_object && ! empty($source_object->card) ) && |
|
422 | + ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
423 | + ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure) |
|
425 | 424 | ); |
426 | 425 | } |
427 | 426 | |
@@ -432,8 +431,8 @@ discard block |
||
432 | 431 | * @param object $source_object |
433 | 432 | * @return bool |
434 | 433 | */ |
435 | - public function is_3ds_card( $source_object ) { |
|
436 | - return ( $source_object && 'three_d_secure' === $source_object->type ); |
|
434 | + public function is_3ds_card($source_object) { |
|
435 | + return ($source_object && 'three_d_secure' === $source_object->type); |
|
437 | 436 | } |
438 | 437 | |
439 | 438 | /** |
@@ -443,8 +442,8 @@ discard block |
||
443 | 442 | * @param object $source_object |
444 | 443 | * @return bool |
445 | 444 | */ |
446 | - public function is_prepaid_card( $source_object ) { |
|
447 | - return ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ); |
|
445 | + public function is_prepaid_card($source_object) { |
|
446 | + return ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding); |
|
448 | 447 | } |
449 | 448 | |
450 | 449 | /** |
@@ -457,22 +456,22 @@ discard block |
||
457 | 456 | * @param string $return_url |
458 | 457 | * @return mixed |
459 | 458 | */ |
460 | - public function create_3ds_source( $order, $source_object, $return_url = '' ) { |
|
459 | + public function create_3ds_source($order, $source_object, $return_url = '') { |
|
461 | 460 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
462 | 461 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
463 | - $return_url = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url; |
|
462 | + $return_url = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url; |
|
464 | 463 | |
465 | 464 | $post_data = array(); |
466 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
467 | - $post_data['currency'] = strtolower( $currency ); |
|
465 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
466 | + $post_data['currency'] = strtolower($currency); |
|
468 | 467 | $post_data['type'] = 'three_d_secure'; |
469 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
470 | - $post_data['three_d_secure'] = array( 'card' => $source_object->id ); |
|
471 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
468 | + $post_data['owner'] = $this->get_owner_details($order); |
|
469 | + $post_data['three_d_secure'] = array('card' => $source_object->id); |
|
470 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
472 | 471 | |
473 | - WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' ); |
|
472 | + WC_Stripe_Logger::log('Info: Begin creating 3DS source...'); |
|
474 | 473 | |
475 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' ); |
|
474 | + return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources'); |
|
476 | 475 | } |
477 | 476 | |
478 | 477 | /** |
@@ -488,58 +487,58 @@ discard block |
||
488 | 487 | * @throws Exception When card was not added or for and invalid card. |
489 | 488 | * @return object |
490 | 489 | */ |
491 | - public function prepare_source( $user_id, $force_save_source = false ) { |
|
492 | - $customer = new WC_Stripe_Customer( $user_id ); |
|
490 | + public function prepare_source($user_id, $force_save_source = false) { |
|
491 | + $customer = new WC_Stripe_Customer($user_id); |
|
493 | 492 | $set_customer = true; |
494 | - $force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer ); |
|
493 | + $force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer); |
|
495 | 494 | $source_object = ''; |
496 | 495 | $source_id = ''; |
497 | 496 | $wc_token_id = false; |
498 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
497 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
499 | 498 | $is_token = false; |
500 | 499 | |
501 | 500 | // New CC info was entered and we have a new source to process. |
502 | - if ( ! empty( $_POST['stripe_source'] ) ) { |
|
503 | - $source_object = self::get_source_object( wc_clean( $_POST['stripe_source'] ) ); |
|
501 | + if ( ! empty($_POST['stripe_source'])) { |
|
502 | + $source_object = self::get_source_object(wc_clean($_POST['stripe_source'])); |
|
504 | 503 | $source_id = $source_object->id; |
505 | 504 | |
506 | 505 | // This checks to see if customer opted to save the payment method to file. |
507 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
506 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
508 | 507 | |
509 | 508 | /** |
510 | 509 | * This is true if the user wants to store the card to their account. |
511 | 510 | * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is |
512 | 511 | * actually reusable. Either that or force_save_source is true. |
513 | 512 | */ |
514 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) { |
|
515 | - $response = $customer->add_source( $source_object->id ); |
|
513 | + if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) { |
|
514 | + $response = $customer->add_source($source_object->id); |
|
516 | 515 | |
517 | - if ( ! empty( $response->error ) ) { |
|
518 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
516 | + if ( ! empty($response->error)) { |
|
517 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
519 | 518 | } |
520 | 519 | } |
521 | - } elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) { |
|
520 | + } elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) { |
|
522 | 521 | // Use an existing token, and then process the payment. |
523 | - $wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
524 | - $wc_token = WC_Payment_Tokens::get( $wc_token_id ); |
|
522 | + $wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']); |
|
523 | + $wc_token = WC_Payment_Tokens::get($wc_token_id); |
|
525 | 524 | |
526 | - if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) { |
|
527 | - WC()->session->set( 'refresh_totals', true ); |
|
528 | - throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
525 | + if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) { |
|
526 | + WC()->session->set('refresh_totals', true); |
|
527 | + throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
529 | 528 | } |
530 | 529 | |
531 | 530 | $source_id = $wc_token->get_token(); |
532 | 531 | $is_token = true; |
533 | - } elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) { |
|
534 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
535 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
532 | + } elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) { |
|
533 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
534 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
536 | 535 | |
537 | 536 | // This is true if the user wants to store the card to their account. |
538 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) { |
|
539 | - $response = $customer->add_source( $stripe_token ); |
|
537 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) { |
|
538 | + $response = $customer->add_source($stripe_token); |
|
540 | 539 | |
541 | - if ( ! empty( $response->error ) ) { |
|
542 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
540 | + if ( ! empty($response->error)) { |
|
541 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
543 | 542 | } |
544 | 543 | } else { |
545 | 544 | $set_customer = false; |
@@ -548,14 +547,14 @@ discard block |
||
548 | 547 | } |
549 | 548 | } |
550 | 549 | |
551 | - if ( ! $set_customer ) { |
|
550 | + if ( ! $set_customer) { |
|
552 | 551 | $customer_id = false; |
553 | 552 | } else { |
554 | 553 | $customer_id = $customer->get_id() ? $customer->get_id() : false; |
555 | 554 | } |
556 | 555 | |
557 | - if ( empty( $source_object ) && ! $is_token ) { |
|
558 | - $source_object = self::get_source_object( $source_id ); |
|
556 | + if (empty($source_object) && ! $is_token) { |
|
557 | + $source_object = self::get_source_object($source_id); |
|
559 | 558 | } |
560 | 559 | |
561 | 560 | return (object) array( |
@@ -579,37 +578,37 @@ discard block |
||
579 | 578 | * @param object $order |
580 | 579 | * @return object |
581 | 580 | */ |
582 | - public function prepare_order_source( $order = null ) { |
|
581 | + public function prepare_order_source($order = null) { |
|
583 | 582 | $stripe_customer = new WC_Stripe_Customer(); |
584 | 583 | $stripe_source = false; |
585 | 584 | $token_id = false; |
586 | 585 | |
587 | - if ( $order ) { |
|
586 | + if ($order) { |
|
588 | 587 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
589 | 588 | |
590 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
589 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
591 | 590 | |
592 | - if ( $stripe_customer_id ) { |
|
593 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
591 | + if ($stripe_customer_id) { |
|
592 | + $stripe_customer->set_id($stripe_customer_id); |
|
594 | 593 | } |
595 | 594 | |
596 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true ); |
|
595 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true); |
|
597 | 596 | |
598 | 597 | // Since 4.0.0, we changed card to source so we need to account for that. |
599 | - if ( empty( $source_id ) ) { |
|
600 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true ); |
|
598 | + if (empty($source_id)) { |
|
599 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true); |
|
601 | 600 | |
602 | 601 | // Take this opportunity to update the key name. |
603 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id ); |
|
602 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id); |
|
604 | 603 | |
605 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
604 | + if (is_callable(array($order, 'save'))) { |
|
606 | 605 | $order->save(); |
607 | 606 | } |
608 | 607 | } |
609 | 608 | |
610 | - if ( $source_id ) { |
|
609 | + if ($source_id) { |
|
611 | 610 | $stripe_source = $source_id; |
612 | - } elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
611 | + } elseif (apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
613 | 612 | /* |
614 | 613 | * We can attempt to charge the customer's default source |
615 | 614 | * by sending empty source id. |
@@ -633,27 +632,27 @@ discard block |
||
633 | 632 | * @param WC_Order $order For to which the source applies. |
634 | 633 | * @param stdClass $source Source information. |
635 | 634 | */ |
636 | - public function save_source_to_order( $order, $source ) { |
|
635 | + public function save_source_to_order($order, $source) { |
|
637 | 636 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
638 | 637 | |
639 | 638 | // Store source in the order. |
640 | - if ( $source->customer ) { |
|
641 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
642 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
639 | + if ($source->customer) { |
|
640 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
641 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
643 | 642 | } else { |
644 | - $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
643 | + $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
645 | 644 | } |
646 | 645 | } |
647 | 646 | |
648 | - if ( $source->source ) { |
|
649 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
650 | - update_post_meta( $order_id, '_stripe_source_id', $source->source ); |
|
647 | + if ($source->source) { |
|
648 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
649 | + update_post_meta($order_id, '_stripe_source_id', $source->source); |
|
651 | 650 | } else { |
652 | - $order->update_meta_data( '_stripe_source_id', $source->source ); |
|
651 | + $order->update_meta_data('_stripe_source_id', $source->source); |
|
653 | 652 | } |
654 | 653 | } |
655 | 654 | |
656 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
655 | + if (is_callable(array($order, 'save'))) { |
|
657 | 656 | $order->save(); |
658 | 657 | } |
659 | 658 | } |
@@ -667,35 +666,35 @@ discard block |
||
667 | 666 | * @param object $order The order object |
668 | 667 | * @param int $balance_transaction_id |
669 | 668 | */ |
670 | - public function update_fees( $order, $balance_transaction_id ) { |
|
669 | + public function update_fees($order, $balance_transaction_id) { |
|
671 | 670 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
672 | 671 | |
673 | - $balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id ); |
|
672 | + $balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id); |
|
674 | 673 | |
675 | - if ( empty( $balance_transaction->error ) ) { |
|
676 | - if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) { |
|
674 | + if (empty($balance_transaction->error)) { |
|
675 | + if (isset($balance_transaction) && isset($balance_transaction->fee)) { |
|
677 | 676 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
678 | 677 | // values are in the local currency of the Stripe account, not from WC. |
679 | - $fee_refund = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0; |
|
680 | - $net_refund = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0; |
|
678 | + $fee_refund = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0; |
|
679 | + $net_refund = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0; |
|
681 | 680 | |
682 | 681 | // Current data fee & net. |
683 | - $fee_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::META_NAME_FEE, true ) : $order->get_meta( self::META_NAME_FEE, true ); |
|
684 | - $net_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, self::META_NAME_NET, true ) : $order->get_meta( self::META_NAME_NET, true ); |
|
682 | + $fee_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::META_NAME_FEE, true) : $order->get_meta(self::META_NAME_FEE, true); |
|
683 | + $net_current = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, self::META_NAME_NET, true) : $order->get_meta(self::META_NAME_NET, true); |
|
685 | 684 | |
686 | 685 | // Calculation. |
687 | 686 | $fee = (float) $fee_current + (float) $fee_refund; |
688 | 687 | $net = (float) $net_current + (float) $net_refund; |
689 | 688 | |
690 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
691 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
689 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
690 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
692 | 691 | |
693 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
692 | + if (is_callable(array($order, 'save'))) { |
|
694 | 693 | $order->save(); |
695 | 694 | } |
696 | 695 | } |
697 | 696 | } else { |
698 | - WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" ); |
|
697 | + WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}"); |
|
699 | 698 | } |
700 | 699 | } |
701 | 700 | |
@@ -708,33 +707,33 @@ discard block |
||
708 | 707 | * @param float $amount |
709 | 708 | * @return bool |
710 | 709 | */ |
711 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
712 | - $order = wc_get_order( $order_id ); |
|
710 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
711 | + $order = wc_get_order($order_id); |
|
713 | 712 | |
714 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
713 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
715 | 714 | return false; |
716 | 715 | } |
717 | 716 | |
718 | 717 | $request = array(); |
719 | 718 | |
720 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
721 | - $order_currency = get_post_meta( $order_id, '_order_currency', true ); |
|
722 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
719 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
720 | + $order_currency = get_post_meta($order_id, '_order_currency', true); |
|
721 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
723 | 722 | } else { |
724 | 723 | $order_currency = $order->get_currency(); |
725 | - $captured = $order->get_meta( '_stripe_charge_captured', true ); |
|
724 | + $captured = $order->get_meta('_stripe_charge_captured', true); |
|
726 | 725 | } |
727 | 726 | |
728 | - if ( ! is_null( $amount ) ) { |
|
729 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency ); |
|
727 | + if ( ! is_null($amount)) { |
|
728 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency); |
|
730 | 729 | } |
731 | 730 | |
732 | 731 | // If order is only authorized, don't pass amount. |
733 | - if ( 'yes' !== $captured ) { |
|
734 | - unset( $request['amount'] ); |
|
732 | + if ('yes' !== $captured) { |
|
733 | + unset($request['amount']); |
|
735 | 734 | } |
736 | 735 | |
737 | - if ( $reason ) { |
|
736 | + if ($reason) { |
|
738 | 737 | $request['metadata'] = array( |
739 | 738 | 'reason' => $reason, |
740 | 739 | ); |
@@ -742,35 +741,35 @@ discard block |
||
742 | 741 | |
743 | 742 | $request['charge'] = $order->get_transaction_id(); |
744 | 743 | |
745 | - WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" ); |
|
744 | + WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}"); |
|
746 | 745 | |
747 | - $request = apply_filters( 'wc_stripe_refund_request', $request, $order ); |
|
746 | + $request = apply_filters('wc_stripe_refund_request', $request, $order); |
|
748 | 747 | |
749 | - $response = WC_Stripe_API::request( $request, 'refunds' ); |
|
748 | + $response = WC_Stripe_API::request($request, 'refunds'); |
|
750 | 749 | |
751 | - if ( ! empty( $response->error ) ) { |
|
752 | - WC_Stripe_Logger::log( 'Error: ' . $response->error->message ); |
|
750 | + if ( ! empty($response->error)) { |
|
751 | + WC_Stripe_Logger::log('Error: ' . $response->error->message); |
|
753 | 752 | |
754 | 753 | return $response; |
755 | 754 | |
756 | - } elseif ( ! empty( $response->id ) ) { |
|
757 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id ); |
|
755 | + } elseif ( ! empty($response->id)) { |
|
756 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id); |
|
758 | 757 | |
759 | - $amount = wc_price( $response->amount / 100 ); |
|
758 | + $amount = wc_price($response->amount / 100); |
|
760 | 759 | |
761 | - if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
762 | - $amount = wc_price( $response->amount ); |
|
760 | + if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
761 | + $amount = wc_price($response->amount); |
|
763 | 762 | } |
764 | 763 | |
765 | - if ( isset( $response->balance_transaction ) ) { |
|
766 | - $this->update_fees( $order, $response->balance_transaction ); |
|
764 | + if (isset($response->balance_transaction)) { |
|
765 | + $this->update_fees($order, $response->balance_transaction); |
|
767 | 766 | } |
768 | 767 | |
769 | 768 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
770 | - $refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ) : __( 'Pre-Authorization Released', 'woocommerce-gateway-stripe' ); |
|
769 | + $refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason) : __('Pre-Authorization Released', 'woocommerce-gateway-stripe'); |
|
771 | 770 | |
772 | - $order->add_order_note( $refund_message ); |
|
773 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
771 | + $order->add_order_note($refund_message); |
|
772 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
774 | 773 | |
775 | 774 | return true; |
776 | 775 | } |
@@ -785,44 +784,44 @@ discard block |
||
785 | 784 | */ |
786 | 785 | public function add_payment_method() { |
787 | 786 | $error = false; |
788 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
787 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
789 | 788 | $source_id = ''; |
790 | 789 | |
791 | - if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
790 | + if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
792 | 791 | $error = true; |
793 | 792 | } |
794 | 793 | |
795 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
794 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
796 | 795 | |
797 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
796 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
798 | 797 | |
799 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
798 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
800 | 799 | |
801 | - if ( isset( $source_object ) ) { |
|
802 | - if ( ! empty( $source_object->error ) ) { |
|
800 | + if (isset($source_object)) { |
|
801 | + if ( ! empty($source_object->error)) { |
|
803 | 802 | $error = true; |
804 | 803 | } |
805 | 804 | |
806 | 805 | $source_id = $source_object->id; |
807 | - } elseif ( isset( $_POST['stripe_token'] ) ) { |
|
808 | - $source_id = wc_clean( $_POST['stripe_token'] ); |
|
806 | + } elseif (isset($_POST['stripe_token'])) { |
|
807 | + $source_id = wc_clean($_POST['stripe_token']); |
|
809 | 808 | } |
810 | 809 | |
811 | - $response = $stripe_customer->add_source( $source_id ); |
|
810 | + $response = $stripe_customer->add_source($source_id); |
|
812 | 811 | |
813 | - if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) { |
|
812 | + if ( ! $response || is_wp_error($response) || ! empty($response->error)) { |
|
814 | 813 | $error = true; |
815 | 814 | } |
816 | 815 | |
817 | - if ( $error ) { |
|
818 | - wc_add_notice( $error_msg, 'error' ); |
|
819 | - WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg ); |
|
816 | + if ($error) { |
|
817 | + wc_add_notice($error_msg, 'error'); |
|
818 | + WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg); |
|
820 | 819 | return; |
821 | 820 | } |
822 | 821 | |
823 | 822 | return array( |
824 | 823 | 'result' => 'success', |
825 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
824 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
826 | 825 | ); |
827 | 826 | } |
828 | 827 | |
@@ -839,10 +838,10 @@ discard block |
||
839 | 838 | * Stripe expects Norwegian to only be passed NO. |
840 | 839 | * But WP has different dialects. |
841 | 840 | */ |
842 | - if ( 'NO' === substr( $locale, 3, 2 ) ) { |
|
841 | + if ('NO' === substr($locale, 3, 2)) { |
|
843 | 842 | $locale = 'no'; |
844 | 843 | } else { |
845 | - $locale = substr( get_locale(), 0, 2 ); |
|
844 | + $locale = substr(get_locale(), 0, 2); |
|
846 | 845 | } |
847 | 846 | |
848 | 847 | return $locale; |
@@ -856,9 +855,9 @@ discard block |
||
856 | 855 | * @param string $idempotency_key |
857 | 856 | * @param array $request |
858 | 857 | */ |
859 | - public function change_idempotency_key( $idempotency_key, $request ) { |
|
860 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
861 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
858 | + public function change_idempotency_key($idempotency_key, $request) { |
|
859 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
860 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
862 | 861 | $count = $this->retry_interval; |
863 | 862 | |
864 | 863 | return $request['metadata']['order_id'] . '-' . $count . '-' . $source; |
@@ -872,8 +871,8 @@ discard block |
||
872 | 871 | * @since 4.0.6 |
873 | 872 | * @param array $headers |
874 | 873 | */ |
875 | - public function is_original_request( $headers ) { |
|
876 | - if ( $headers['original-request'] === $headers['request-id'] ) { |
|
874 | + public function is_original_request($headers) { |
|
875 | + if ($headers['original-request'] === $headers['request-id']) { |
|
877 | 876 | return true; |
878 | 877 | } |
879 | 878 |