@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function __construct() { |
114 | 114 | $this->id = 'stripe'; |
115 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
115 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
116 | 116 | /* translators: 1) link to Stripe register page 2) link to Stripe api keys page */ |
117 | - $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' ); |
|
117 | + $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'); |
|
118 | 118 | $this->has_fields = true; |
119 | 119 | $this->supports = array( |
120 | 120 | 'products', |
@@ -141,37 +141,37 @@ discard block |
||
141 | 141 | $this->init_settings(); |
142 | 142 | |
143 | 143 | // Get setting values. |
144 | - $this->title = $this->get_option( 'title' ); |
|
145 | - $this->description = $this->get_option( 'description' ); |
|
146 | - $this->enabled = $this->get_option( 'enabled' ); |
|
147 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
148 | - $this->inline_cc_form = 'yes' === $this->get_option( 'inline_cc_form' ); |
|
149 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
150 | - $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) ); |
|
151 | - $this->three_d_secure = 'yes' === $this->get_option( 'three_d_secure' ); |
|
152 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
153 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
154 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
155 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
156 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
157 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
158 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
159 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
144 | + $this->title = $this->get_option('title'); |
|
145 | + $this->description = $this->get_option('description'); |
|
146 | + $this->enabled = $this->get_option('enabled'); |
|
147 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
148 | + $this->inline_cc_form = 'yes' === $this->get_option('inline_cc_form'); |
|
149 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
150 | + $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor')); |
|
151 | + $this->three_d_secure = 'yes' === $this->get_option('three_d_secure'); |
|
152 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
153 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
154 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
155 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
156 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
157 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
158 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
159 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
160 | 160 | $this->apple_pay_verify_notice = ''; |
161 | 161 | |
162 | - if ( $this->stripe_checkout ) { |
|
163 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
162 | + if ($this->stripe_checkout) { |
|
163 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
164 | 164 | } |
165 | 165 | |
166 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
166 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
167 | 167 | |
168 | 168 | $this->init_apple_pay(); |
169 | 169 | |
170 | 170 | // Hooks. |
171 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
172 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
173 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
174 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
171 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
172 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
173 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
174 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * @since 4.0.2 |
181 | 181 | */ |
182 | 182 | public function is_available() { |
183 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
183 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
184 | 184 | return false; |
185 | 185 | } |
186 | 186 | |
@@ -203,17 +203,17 @@ discard block |
||
203 | 203 | $icons_str .= $icons['amex']; |
204 | 204 | $icons_str .= $icons['mastercard']; |
205 | 205 | |
206 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
206 | + if ('USD' === get_woocommerce_currency()) { |
|
207 | 207 | $icons_str .= $icons['discover']; |
208 | 208 | $icons_str .= $icons['jcb']; |
209 | 209 | $icons_str .= $icons['diners']; |
210 | 210 | } |
211 | 211 | |
212 | - if ( $this->bitcoin && $this->stripe_checkout ) { |
|
212 | + if ($this->bitcoin && $this->stripe_checkout) { |
|
213 | 213 | $icons_str .= $icons['bitcoin']; |
214 | 214 | } |
215 | 215 | |
216 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
216 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -225,9 +225,9 @@ discard block |
||
225 | 225 | public function init_apple_pay() { |
226 | 226 | if ( |
227 | 227 | is_admin() && |
228 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
229 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
230 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] && |
|
228 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
229 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
230 | + isset($_GET['section']) && 'stripe' === $_GET['section'] && |
|
231 | 231 | $this->payment_request |
232 | 232 | ) { |
233 | 233 | $this->process_apple_pay_verification(); |
@@ -241,9 +241,9 @@ discard block |
||
241 | 241 | * @version 3.1.0 |
242 | 242 | * @param string $secret_key |
243 | 243 | */ |
244 | - private function register_apple_pay_domain( $secret_key = '' ) { |
|
245 | - if ( empty( $secret_key ) ) { |
|
246 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
244 | + private function register_apple_pay_domain($secret_key = '') { |
|
245 | + if (empty($secret_key)) { |
|
246 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -257,23 +257,23 @@ discard block |
||
257 | 257 | 'Authorization' => 'Bearer ' . $secret_key, |
258 | 258 | ); |
259 | 259 | |
260 | - $response = wp_remote_post( $endpoint, array( |
|
260 | + $response = wp_remote_post($endpoint, array( |
|
261 | 261 | 'headers' => $headers, |
262 | - 'body' => http_build_query( $data ), |
|
263 | - ) ); |
|
262 | + 'body' => http_build_query($data), |
|
263 | + )); |
|
264 | 264 | |
265 | - if ( is_wp_error( $response ) ) { |
|
265 | + if (is_wp_error($response)) { |
|
266 | 266 | /* translators: error message */ |
267 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
267 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
268 | 268 | } |
269 | 269 | |
270 | - if ( 200 !== $response['response']['code'] ) { |
|
271 | - $parsed_response = json_decode( $response['body'] ); |
|
270 | + if (200 !== $response['response']['code']) { |
|
271 | + $parsed_response = json_decode($response['body']); |
|
272 | 272 | |
273 | 273 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
274 | 274 | |
275 | 275 | /* translators: error message */ |
276 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
276 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
277 | 277 | } |
278 | 278 | } |
279 | 279 | |
@@ -284,48 +284,48 @@ discard block |
||
284 | 284 | * @version 3.1.0 |
285 | 285 | */ |
286 | 286 | public function process_apple_pay_verification() { |
287 | - $gateway_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
287 | + $gateway_settings = get_option('woocommerce_stripe_settings', array()); |
|
288 | 288 | |
289 | 289 | try { |
290 | - $path = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] ); |
|
290 | + $path = untrailingslashit($_SERVER['DOCUMENT_ROOT']); |
|
291 | 291 | $dir = '.well-known'; |
292 | 292 | $file = 'apple-developer-merchantid-domain-association'; |
293 | 293 | $fullpath = $path . '/' . $dir . '/' . $file; |
294 | 294 | |
295 | - if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) { |
|
295 | + if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) { |
|
296 | 296 | return; |
297 | 297 | } |
298 | 298 | |
299 | - if ( ! file_exists( $path . '/' . $dir ) ) { |
|
300 | - if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { |
|
301 | - throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
299 | + if ( ! file_exists($path . '/' . $dir)) { |
|
300 | + if ( ! @mkdir($path . '/' . $dir, 0755)) { |
|
301 | + throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
305 | - if ( ! file_exists( $fullpath ) ) { |
|
306 | - if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { |
|
307 | - throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
305 | + if ( ! file_exists($fullpath)) { |
|
306 | + if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { |
|
307 | + throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 | |
311 | 311 | // At this point then the domain association folder and file should be available. |
312 | 312 | // Proceed to verify/and or verify again. |
313 | - $this->register_apple_pay_domain( $this->secret_key ); |
|
313 | + $this->register_apple_pay_domain($this->secret_key); |
|
314 | 314 | |
315 | 315 | // No errors to this point, verification success! |
316 | 316 | $gateway_settings['apple_pay_domain_set'] = 'yes'; |
317 | 317 | $this->apple_pay_domain_set = true; |
318 | 318 | |
319 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
319 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
320 | 320 | |
321 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
321 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
322 | 322 | |
323 | - } catch ( Exception $e ) { |
|
323 | + } catch (Exception $e) { |
|
324 | 324 | $gateway_settings['apple_pay_domain_set'] = 'no'; |
325 | 325 | |
326 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
326 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
327 | 327 | |
328 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
328 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
329 | 329 | } |
330 | 330 | } |
331 | 331 | |
@@ -333,11 +333,11 @@ discard block |
||
333 | 333 | * Check if SSL is enabled and notify the user |
334 | 334 | */ |
335 | 335 | public function admin_notices() { |
336 | - if ( 'no' === $this->enabled ) { |
|
336 | + if ('no' === $this->enabled) { |
|
337 | 337 | return; |
338 | 338 | } |
339 | 339 | |
340 | - if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) { |
|
340 | + if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) { |
|
341 | 341 | $allowed_html = array( |
342 | 342 | 'a' => array( |
343 | 343 | 'href' => array(), |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | ), |
346 | 346 | ); |
347 | 347 | |
348 | - echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>'; |
|
348 | + echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>'; |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
@@ -353,9 +353,9 @@ discard block |
||
353 | 353 | * when setting screen is displayed. So if domain verification is not set, |
354 | 354 | * something went wrong so lets notify user. |
355 | 355 | */ |
356 | - if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) { |
|
356 | + if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) { |
|
357 | 357 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
358 | - 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>'; |
|
358 | + 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>'; |
|
359 | 359 | } |
360 | 360 | } |
361 | 361 | |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | * Initialise Gateway Settings Form Fields |
364 | 364 | */ |
365 | 365 | public function init_form_fields() { |
366 | - $this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' ); |
|
366 | + $this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php'); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | /** |
@@ -371,59 +371,59 @@ discard block |
||
371 | 371 | */ |
372 | 372 | public function payment_fields() { |
373 | 373 | $user = wp_get_current_user(); |
374 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
374 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
375 | 375 | $total = WC()->cart->total; |
376 | 376 | $user_email = ''; |
377 | 377 | |
378 | 378 | // If paying from order, we need to get total from order not cart. |
379 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
380 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
379 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
380 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
381 | 381 | $total = $order->get_total(); |
382 | 382 | $user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
383 | 383 | } else { |
384 | - if ( $user->ID ) { |
|
385 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
384 | + if ($user->ID) { |
|
385 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
386 | 386 | $user_email = $user_email ? $user_email : $user->user_email; |
387 | 387 | } |
388 | 388 | } |
389 | 389 | |
390 | - if ( is_add_payment_method_page() ) { |
|
391 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
392 | - $total = ''; |
|
390 | + if (is_add_payment_method_page()) { |
|
391 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
392 | + $total = ''; |
|
393 | 393 | } else { |
394 | 394 | $pay_button_text = ''; |
395 | 395 | } |
396 | 396 | |
397 | 397 | echo '<div |
398 | 398 | id="stripe-payment-data" |
399 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
399 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
400 | 400 | data-description="" |
401 | - data-email="' . esc_attr( $user_email ) . '" |
|
402 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
403 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
404 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
405 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
406 | - data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '" |
|
407 | - data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', substr( get_locale(), 0, 2 ) ) ) . '" |
|
408 | - data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '" |
|
409 | - data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">'; |
|
410 | - |
|
411 | - if ( $this->description ) { |
|
412 | - if ( $this->testmode ) { |
|
401 | + data-email="' . esc_attr($user_email) . '" |
|
402 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
403 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
404 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
405 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
406 | + data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '" |
|
407 | + data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', substr(get_locale(), 0, 2))) . '" |
|
408 | + data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '" |
|
409 | + data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">'; |
|
410 | + |
|
411 | + if ($this->description) { |
|
412 | + if ($this->testmode) { |
|
413 | 413 | /* translators: link to Stripe testing page */ |
414 | - $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' ); |
|
415 | - $this->description = trim( $this->description ); |
|
414 | + $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'); |
|
415 | + $this->description = trim($this->description); |
|
416 | 416 | } |
417 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
417 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
418 | 418 | } |
419 | 419 | |
420 | - if ( $display_tokenization ) { |
|
420 | + if ($display_tokenization) { |
|
421 | 421 | $this->tokenization_script(); |
422 | 422 | $this->saved_payment_methods(); |
423 | 423 | } |
424 | 424 | |
425 | - if ( ! $this->stripe_checkout ) { |
|
426 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
425 | + if ( ! $this->stripe_checkout) { |
|
426 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
427 | 427 | $this->elements_form(); |
428 | 428 | } else { |
429 | 429 | $this->form(); |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | } |
432 | 432 | } |
433 | 433 | |
434 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
434 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
435 | 435 | $this->save_payment_method_checkbox(); |
436 | 436 | } |
437 | 437 | |
@@ -446,12 +446,12 @@ discard block |
||
446 | 446 | */ |
447 | 447 | public function elements_form() { |
448 | 448 | ?> |
449 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
450 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
449 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
450 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
451 | 451 | |
452 | - <?php if ( $this->inline_cc_form ) { ?> |
|
452 | + <?php if ($this->inline_cc_form) { ?> |
|
453 | 453 | <label for="card-element"> |
454 | - <?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?> |
|
454 | + <?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?> |
|
455 | 455 | </label> |
456 | 456 | |
457 | 457 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | </div> |
460 | 460 | <?php } else { ?> |
461 | 461 | <div class="form-row form-row-wide"> |
462 | - <label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
462 | + <label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
463 | 463 | |
464 | 464 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
465 | 465 | <!-- a Stripe Element will be inserted here. --> |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | </div> |
468 | 468 | |
469 | 469 | <div class="form-row form-row-first"> |
470 | - <label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
470 | + <label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
471 | 471 | |
472 | 472 | <div id="stripe-exp-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-last"> |
478 | - <label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
478 | + <label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
479 | 479 | <div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
480 | 480 | <!-- a Stripe Element will be inserted here. --> |
481 | 481 | </div> |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | |
486 | 486 | <!-- Used to display form errors --> |
487 | 487 | <div class="stripe-source-errors" role="alert"></div> |
488 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
488 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
489 | 489 | <div class="clear"></div> |
490 | 490 | </fieldset> |
491 | 491 | <?php |
@@ -498,13 +498,13 @@ discard block |
||
498 | 498 | * @version 3.1.0 |
499 | 499 | */ |
500 | 500 | public function admin_scripts() { |
501 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
501 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
502 | 502 | return; |
503 | 503 | } |
504 | 504 | |
505 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
505 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
506 | 506 | |
507 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
507 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | /** |
@@ -516,29 +516,29 @@ discard block |
||
516 | 516 | * @version 4.0.0 |
517 | 517 | */ |
518 | 518 | public function payment_scripts() { |
519 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
519 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
520 | 520 | return; |
521 | 521 | } |
522 | 522 | |
523 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
523 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
524 | 524 | |
525 | - wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' ); |
|
526 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
527 | - wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true ); |
|
528 | - wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true ); |
|
529 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
530 | - 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 ); |
|
525 | + wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5'); |
|
526 | + wp_enqueue_style('stripe_paymentfonts'); |
|
527 | + wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true); |
|
528 | + wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true); |
|
529 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
530 | + 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); |
|
531 | 531 | |
532 | 532 | $stripe_params = array( |
533 | 533 | 'key' => $this->publishable_key, |
534 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
535 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
534 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
535 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
536 | 536 | ); |
537 | 537 | |
538 | 538 | // If we're on the pay page we need to pass stripe.js the address of the order. |
539 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
540 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
541 | - $order = wc_get_order( $order_id ); |
|
539 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
540 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
541 | + $order = wc_get_order($order_id); |
|
542 | 542 | |
543 | 543 | $stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
544 | 544 | $stripe_params['billing_last_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
@@ -550,38 +550,38 @@ discard block |
||
550 | 550 | $stripe_params['billing_country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
551 | 551 | } |
552 | 552 | |
553 | - $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' ); |
|
554 | - $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
555 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
556 | - $stripe_params['sepa_mandate_notification'] = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' ); |
|
557 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
553 | + $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'); |
|
554 | + $stripe_params['no_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
555 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
556 | + $stripe_params['sepa_mandate_notification'] = apply_filters('wc_stripe_sepa_mandate_notification', 'email'); |
|
557 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
558 | 558 | $stripe_params['inline_cc_form'] = $this->inline_cc_form ? 'yes' : 'no'; |
559 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
560 | - $stripe_params['is_checkout'] = ( is_checkout() && empty( $_GET['pay_for_order'] ) ); |
|
559 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
560 | + $stripe_params['is_checkout'] = (is_checkout() && empty($_GET['pay_for_order'])); |
|
561 | 561 | $stripe_params['return_url'] = $this->get_stripe_return_url(); |
562 | - $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); |
|
563 | - $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); |
|
562 | + $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint('%%endpoint%%'); |
|
563 | + $stripe_params['stripe_nonce'] = wp_create_nonce('_wc_stripe_nonce'); |
|
564 | 564 | $stripe_params['statement_descriptor'] = $this->statement_descriptor; |
565 | - $stripe_params['use_elements'] = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no'; |
|
566 | - $stripe_params['elements_options'] = apply_filters( 'wc_stripe_elements_options', array() ); |
|
565 | + $stripe_params['use_elements'] = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no'; |
|
566 | + $stripe_params['elements_options'] = apply_filters('wc_stripe_elements_options', array()); |
|
567 | 567 | $stripe_params['is_stripe_checkout'] = $this->stripe_checkout ? 'yes' : 'no'; |
568 | - $stripe_params['is_change_payment_page'] = ( isset( $_GET['pay_for_order'] ) || isset( $_GET['change_payment_method'] ) ) ? 'yes' : 'no'; |
|
568 | + $stripe_params['is_change_payment_page'] = (isset($_GET['pay_for_order']) || isset($_GET['change_payment_method'])) ? 'yes' : 'no'; |
|
569 | 569 | $stripe_params['is_add_payment_method_page'] = is_add_payment_method_page() ? 'yes' : 'no'; |
570 | - $stripe_params['elements_styling'] = apply_filters( 'wc_stripe_elements_styling', false ); |
|
571 | - $stripe_params['elements_classes'] = apply_filters( 'wc_stripe_elements_classes', false ); |
|
570 | + $stripe_params['elements_styling'] = apply_filters('wc_stripe_elements_styling', false); |
|
571 | + $stripe_params['elements_classes'] = apply_filters('wc_stripe_elements_classes', false); |
|
572 | 572 | |
573 | 573 | // merge localized messages to be use in JS |
574 | - $stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() ); |
|
574 | + $stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages()); |
|
575 | 575 | |
576 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
577 | - wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
576 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
577 | + wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
578 | 578 | |
579 | - if ( $this->stripe_checkout ) { |
|
580 | - wp_enqueue_script( 'stripe_checkout' ); |
|
579 | + if ($this->stripe_checkout) { |
|
580 | + wp_enqueue_script('stripe_checkout'); |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | $this->tokenization_script(); |
584 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
584 | + wp_enqueue_script('woocommerce_stripe'); |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | /** |
@@ -597,43 +597,43 @@ discard block |
||
597 | 597 | * |
598 | 598 | * @return array|void |
599 | 599 | */ |
600 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
600 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
601 | 601 | try { |
602 | - $order = wc_get_order( $order_id ); |
|
602 | + $order = wc_get_order($order_id); |
|
603 | 603 | |
604 | 604 | // This comes from the create account checkbox in the checkout page. |
605 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
605 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
606 | 606 | |
607 | - if ( $create_account ) { |
|
607 | + if ($create_account) { |
|
608 | 608 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
609 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
609 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
610 | 610 | $new_stripe_customer->create_customer(); |
611 | 611 | } |
612 | 612 | |
613 | 613 | $source_object = $this->get_source_object(); |
614 | - $prepared_source = $this->prepare_source( $source_object, get_current_user_id(), $force_save_source ); |
|
614 | + $prepared_source = $this->prepare_source($source_object, get_current_user_id(), $force_save_source); |
|
615 | 615 | |
616 | 616 | // Check if we don't allow prepaid credit cards. |
617 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) { |
|
618 | - if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) { |
|
619 | - $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' ); |
|
620 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message ); |
|
617 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) { |
|
618 | + if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) { |
|
619 | + $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'); |
|
620 | + throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message); |
|
621 | 621 | } |
622 | 622 | } |
623 | 623 | |
624 | - if ( empty( $prepared_source->source ) ) { |
|
625 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
626 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
624 | + if (empty($prepared_source->source)) { |
|
625 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
626 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
627 | 627 | } |
628 | 628 | |
629 | - $this->save_source_to_order( $order, $prepared_source ); |
|
629 | + $this->save_source_to_order($order, $prepared_source); |
|
630 | 630 | |
631 | 631 | // Result from Stripe API request. |
632 | 632 | $response = null; |
633 | 633 | |
634 | - if ( $order->get_total() > 0 ) { |
|
634 | + if ($order->get_total() > 0) { |
|
635 | 635 | // This will throw exception if not valid. |
636 | - $this->validate_minimum_order_amount( $order ); |
|
636 | + $this->validate_minimum_order_amount($order); |
|
637 | 637 | |
638 | 638 | /* |
639 | 639 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -642,109 +642,109 @@ discard block |
||
642 | 642 | * Note that if we need to save source, the original source must be first |
643 | 643 | * attached to a customer in Stripe before it can be charged. |
644 | 644 | */ |
645 | - if ( $this->is_3ds_required( $source_object ) ) { |
|
646 | - $response = $this->create_3ds_source( $order, $source_object ); |
|
645 | + if ($this->is_3ds_required($source_object)) { |
|
646 | + $response = $this->create_3ds_source($order, $source_object); |
|
647 | 647 | |
648 | - if ( ! empty( $response->error ) ) { |
|
648 | + if ( ! empty($response->error)) { |
|
649 | 649 | $localized_message = $response->error->message; |
650 | 650 | |
651 | - $order->add_order_note( $localized_message ); |
|
651 | + $order->add_order_note($localized_message); |
|
652 | 652 | |
653 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
653 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
654 | 654 | } |
655 | 655 | |
656 | 656 | // Update order meta with 3DS source. |
657 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
658 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
657 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
658 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
659 | 659 | } else { |
660 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
660 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
661 | 661 | $order->save(); |
662 | 662 | } |
663 | 663 | |
664 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
664 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
665 | 665 | |
666 | 666 | return array( |
667 | 667 | 'result' => 'success', |
668 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
668 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
669 | 669 | ); |
670 | 670 | } |
671 | 671 | |
672 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
672 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
673 | 673 | |
674 | 674 | // Make the request. |
675 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
675 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
676 | 676 | |
677 | - if ( ! empty( $response->error ) ) { |
|
677 | + if ( ! empty($response->error)) { |
|
678 | 678 | // If it is an API error such connection or server, let's retry. |
679 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
680 | - if ( $retry ) { |
|
681 | - sleep( 5 ); |
|
682 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
679 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
680 | + if ($retry) { |
|
681 | + sleep(5); |
|
682 | + return $this->process_payment($order_id, false, $force_save_source); |
|
683 | 683 | } else { |
684 | 684 | $localized_message = 'API connection error and retries exhausted.'; |
685 | - $order->add_order_note( $localized_message ); |
|
686 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
685 | + $order->add_order_note($localized_message); |
|
686 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
687 | 687 | } |
688 | 688 | } |
689 | 689 | |
690 | 690 | // We want to retry. |
691 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
692 | - if ( $retry ) { |
|
691 | + if ($this->is_retryable_error($response->error)) { |
|
692 | + if ($retry) { |
|
693 | 693 | // Don't do anymore retries after this. |
694 | - if ( 5 <= $this->retry_interval ) { |
|
694 | + if (5 <= $this->retry_interval) { |
|
695 | 695 | |
696 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
696 | + return $this->process_payment($order_id, false, $force_save_source); |
|
697 | 697 | } |
698 | 698 | |
699 | - sleep( $this->retry_interval ); |
|
699 | + sleep($this->retry_interval); |
|
700 | 700 | |
701 | 701 | $this->retry_interval++; |
702 | - return $this->process_payment( $order_id, true, $force_save_source ); |
|
702 | + return $this->process_payment($order_id, true, $force_save_source); |
|
703 | 703 | } else { |
704 | - $localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' ); |
|
705 | - $order->add_order_note( $localized_message ); |
|
706 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
704 | + $localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe'); |
|
705 | + $order->add_order_note($localized_message); |
|
706 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
707 | 707 | } |
708 | 708 | } |
709 | 709 | |
710 | 710 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
711 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
712 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
713 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
714 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
711 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
712 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
713 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
714 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
715 | 715 | } else { |
716 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
717 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
716 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
717 | + $order->delete_meta_data('_stripe_customer_id'); |
|
718 | 718 | $order->save(); |
719 | 719 | } |
720 | 720 | |
721 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
722 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) { |
|
721 | + return $this->process_payment($order_id, false, $force_save_source); |
|
722 | + } elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) { |
|
723 | 723 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
724 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
724 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
725 | 725 | $wc_token->delete(); |
726 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
727 | - $order->add_order_note( $localized_message ); |
|
728 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
726 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
727 | + $order->add_order_note($localized_message); |
|
728 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
729 | 729 | } |
730 | 730 | |
731 | 731 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
732 | 732 | |
733 | - if ( 'card_error' === $response->error->type ) { |
|
734 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
733 | + if ('card_error' === $response->error->type) { |
|
734 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
735 | 735 | } else { |
736 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
736 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
737 | 737 | } |
738 | 738 | |
739 | - $order->add_order_note( $localized_message ); |
|
739 | + $order->add_order_note($localized_message); |
|
740 | 740 | |
741 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
741 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
742 | 742 | } |
743 | 743 | |
744 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
744 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
745 | 745 | |
746 | 746 | // Process valid response. |
747 | - $this->process_response( $response, $order ); |
|
747 | + $this->process_response($response, $order); |
|
748 | 748 | } else { |
749 | 749 | $order->payment_complete(); |
750 | 750 | } |
@@ -755,17 +755,17 @@ discard block |
||
755 | 755 | // Return thank you page redirect. |
756 | 756 | return array( |
757 | 757 | 'result' => 'success', |
758 | - 'redirect' => $this->get_return_url( $order ), |
|
758 | + 'redirect' => $this->get_return_url($order), |
|
759 | 759 | ); |
760 | 760 | |
761 | - } catch ( WC_Stripe_Exception $e ) { |
|
762 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
763 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
761 | + } catch (WC_Stripe_Exception $e) { |
|
762 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
763 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
764 | 764 | |
765 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
765 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
766 | 766 | |
767 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
768 | - $this->send_failed_order_email( $order_id ); |
|
767 | + if ($order->has_status(array('pending', 'failed'))) { |
|
768 | + $this->send_failed_order_email($order_id); |
|
769 | 769 | } |
770 | 770 | |
771 | 771 | return array( |