@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -115,9 +115,9 @@ discard block |
||
| 115 | 115 | public function __construct() { |
| 116 | 116 | $this->retry_interval = 2; |
| 117 | 117 | $this->id = 'stripe'; |
| 118 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
| 118 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
| 119 | 119 | /* translators: 1) link to Stripe register page 2) link to Stripe api keys page */ |
| 120 | - $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' ); |
|
| 120 | + $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'); |
|
| 121 | 121 | $this->has_fields = true; |
| 122 | 122 | $this->supports = array( |
| 123 | 123 | 'products', |
@@ -144,37 +144,37 @@ discard block |
||
| 144 | 144 | $this->init_settings(); |
| 145 | 145 | |
| 146 | 146 | // Get setting values. |
| 147 | - $this->title = $this->get_option( 'title' ); |
|
| 148 | - $this->description = $this->get_option( 'description' ); |
|
| 149 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 150 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
| 151 | - $this->inline_cc_form = 'yes' === $this->get_option( 'inline_cc_form' ); |
|
| 152 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
| 153 | - $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) ); |
|
| 154 | - $this->three_d_secure = 'yes' === $this->get_option( 'three_d_secure' ); |
|
| 155 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
| 156 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
| 157 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
| 158 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
| 159 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
| 160 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
| 161 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
| 162 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
| 147 | + $this->title = $this->get_option('title'); |
|
| 148 | + $this->description = $this->get_option('description'); |
|
| 149 | + $this->enabled = $this->get_option('enabled'); |
|
| 150 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
| 151 | + $this->inline_cc_form = 'yes' === $this->get_option('inline_cc_form'); |
|
| 152 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
| 153 | + $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor')); |
|
| 154 | + $this->three_d_secure = 'yes' === $this->get_option('three_d_secure'); |
|
| 155 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
| 156 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
| 157 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
| 158 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
| 159 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
| 160 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
| 161 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
| 162 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
| 163 | 163 | $this->apple_pay_verify_notice = ''; |
| 164 | 164 | |
| 165 | - if ( $this->stripe_checkout ) { |
|
| 166 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
| 165 | + if ($this->stripe_checkout) { |
|
| 166 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
| 169 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
| 170 | 170 | |
| 171 | 171 | $this->init_apple_pay(); |
| 172 | 172 | |
| 173 | 173 | // Hooks. |
| 174 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 175 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
| 176 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
| 177 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 174 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 175 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
| 176 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
| 177 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * @since 4.0.2 |
| 184 | 184 | */ |
| 185 | 185 | public function is_available() { |
| 186 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
| 186 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
| 187 | 187 | return false; |
| 188 | 188 | } |
| 189 | 189 | |
@@ -206,17 +206,17 @@ discard block |
||
| 206 | 206 | $icons_str .= $icons['amex']; |
| 207 | 207 | $icons_str .= $icons['mastercard']; |
| 208 | 208 | |
| 209 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
| 209 | + if ('USD' === get_woocommerce_currency()) { |
|
| 210 | 210 | $icons_str .= $icons['discover']; |
| 211 | 211 | $icons_str .= $icons['jcb']; |
| 212 | 212 | $icons_str .= $icons['diners']; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - if ( $this->bitcoin && $this->stripe_checkout ) { |
|
| 215 | + if ($this->bitcoin && $this->stripe_checkout) { |
|
| 216 | 216 | $icons_str .= $icons['bitcoin']; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 219 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -228,9 +228,9 @@ discard block |
||
| 228 | 228 | public function init_apple_pay() { |
| 229 | 229 | if ( |
| 230 | 230 | is_admin() && |
| 231 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
| 232 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
| 233 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] && |
|
| 231 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
| 232 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
| 233 | + isset($_GET['section']) && 'stripe' === $_GET['section'] && |
|
| 234 | 234 | $this->payment_request |
| 235 | 235 | ) { |
| 236 | 236 | $this->process_apple_pay_verification(); |
@@ -244,9 +244,9 @@ discard block |
||
| 244 | 244 | * @version 3.1.0 |
| 245 | 245 | * @param string $secret_key |
| 246 | 246 | */ |
| 247 | - private function register_apple_pay_domain( $secret_key = '' ) { |
|
| 248 | - if ( empty( $secret_key ) ) { |
|
| 249 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
| 247 | + private function register_apple_pay_domain($secret_key = '') { |
|
| 248 | + if (empty($secret_key)) { |
|
| 249 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -260,23 +260,23 @@ discard block |
||
| 260 | 260 | 'Authorization' => 'Bearer ' . $secret_key, |
| 261 | 261 | ); |
| 262 | 262 | |
| 263 | - $response = wp_remote_post( $endpoint, array( |
|
| 263 | + $response = wp_remote_post($endpoint, array( |
|
| 264 | 264 | 'headers' => $headers, |
| 265 | - 'body' => http_build_query( $data ), |
|
| 266 | - ) ); |
|
| 265 | + 'body' => http_build_query($data), |
|
| 266 | + )); |
|
| 267 | 267 | |
| 268 | - if ( is_wp_error( $response ) ) { |
|
| 268 | + if (is_wp_error($response)) { |
|
| 269 | 269 | /* translators: error message */ |
| 270 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
| 270 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - if ( 200 !== $response['response']['code'] ) { |
|
| 274 | - $parsed_response = json_decode( $response['body'] ); |
|
| 273 | + if (200 !== $response['response']['code']) { |
|
| 274 | + $parsed_response = json_decode($response['body']); |
|
| 275 | 275 | |
| 276 | 276 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
| 277 | 277 | |
| 278 | 278 | /* translators: error message */ |
| 279 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
| 279 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
| 280 | 280 | } |
| 281 | 281 | } |
| 282 | 282 | |
@@ -287,48 +287,48 @@ discard block |
||
| 287 | 287 | * @version 3.1.0 |
| 288 | 288 | */ |
| 289 | 289 | public function process_apple_pay_verification() { |
| 290 | - $gateway_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
| 290 | + $gateway_settings = get_option('woocommerce_stripe_settings', array()); |
|
| 291 | 291 | |
| 292 | 292 | try { |
| 293 | - $path = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] ); |
|
| 293 | + $path = untrailingslashit($_SERVER['DOCUMENT_ROOT']); |
|
| 294 | 294 | $dir = '.well-known'; |
| 295 | 295 | $file = 'apple-developer-merchantid-domain-association'; |
| 296 | 296 | $fullpath = $path . '/' . $dir . '/' . $file; |
| 297 | 297 | |
| 298 | - if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) { |
|
| 298 | + if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) { |
|
| 299 | 299 | return; |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - if ( ! file_exists( $path . '/' . $dir ) ) { |
|
| 303 | - if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { |
|
| 304 | - throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
| 302 | + if ( ! file_exists($path . '/' . $dir)) { |
|
| 303 | + if ( ! @mkdir($path . '/' . $dir, 0755)) { |
|
| 304 | + throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - if ( ! file_exists( $fullpath ) ) { |
|
| 309 | - if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { |
|
| 310 | - throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
| 308 | + if ( ! file_exists($fullpath)) { |
|
| 309 | + if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { |
|
| 310 | + throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
| 311 | 311 | } |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | // At this point then the domain association folder and file should be available. |
| 315 | 315 | // Proceed to verify/and or verify again. |
| 316 | - $this->register_apple_pay_domain( $this->secret_key ); |
|
| 316 | + $this->register_apple_pay_domain($this->secret_key); |
|
| 317 | 317 | |
| 318 | 318 | // No errors to this point, verification success! |
| 319 | 319 | $gateway_settings['apple_pay_domain_set'] = 'yes'; |
| 320 | 320 | $this->apple_pay_domain_set = true; |
| 321 | 321 | |
| 322 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
| 322 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
| 323 | 323 | |
| 324 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
| 324 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
| 325 | 325 | |
| 326 | - } catch ( Exception $e ) { |
|
| 326 | + } catch (Exception $e) { |
|
| 327 | 327 | $gateway_settings['apple_pay_domain_set'] = 'no'; |
| 328 | 328 | |
| 329 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
| 329 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
| 330 | 330 | |
| 331 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 331 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | |
@@ -336,11 +336,11 @@ discard block |
||
| 336 | 336 | * Check if SSL is enabled and notify the user |
| 337 | 337 | */ |
| 338 | 338 | public function admin_notices() { |
| 339 | - if ( 'no' === $this->enabled ) { |
|
| 339 | + if ('no' === $this->enabled) { |
|
| 340 | 340 | return; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) { |
|
| 343 | + if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) { |
|
| 344 | 344 | $allowed_html = array( |
| 345 | 345 | 'a' => array( |
| 346 | 346 | 'href' => array(), |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | ), |
| 349 | 349 | ); |
| 350 | 350 | |
| 351 | - echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>'; |
|
| 351 | + echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>'; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | /** |
@@ -356,9 +356,9 @@ discard block |
||
| 356 | 356 | * when setting screen is displayed. So if domain verification is not set, |
| 357 | 357 | * something went wrong so lets notify user. |
| 358 | 358 | */ |
| 359 | - if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) { |
|
| 359 | + if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) { |
|
| 360 | 360 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
| 361 | - 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>'; |
|
| 361 | + 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>'; |
|
| 362 | 362 | } |
| 363 | 363 | } |
| 364 | 364 | |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | * Initialise Gateway Settings Form Fields |
| 367 | 367 | */ |
| 368 | 368 | public function init_form_fields() { |
| 369 | - $this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' ); |
|
| 369 | + $this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php'); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -374,59 +374,59 @@ discard block |
||
| 374 | 374 | */ |
| 375 | 375 | public function payment_fields() { |
| 376 | 376 | $user = wp_get_current_user(); |
| 377 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
| 377 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
| 378 | 378 | $total = WC()->cart->total; |
| 379 | 379 | $user_email = ''; |
| 380 | 380 | |
| 381 | 381 | // If paying from order, we need to get total from order not cart. |
| 382 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 383 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 382 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 383 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 384 | 384 | $total = $order->get_total(); |
| 385 | 385 | $user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
| 386 | 386 | } else { |
| 387 | - if ( $user->ID ) { |
|
| 388 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
| 387 | + if ($user->ID) { |
|
| 388 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
| 389 | 389 | $user_email = $user_email ? $user_email : $user->user_email; |
| 390 | 390 | } |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | - if ( is_add_payment_method_page() ) { |
|
| 394 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
| 395 | - $total = ''; |
|
| 393 | + if (is_add_payment_method_page()) { |
|
| 394 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
| 395 | + $total = ''; |
|
| 396 | 396 | } else { |
| 397 | 397 | $pay_button_text = ''; |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | echo '<div |
| 401 | 401 | id="stripe-payment-data" |
| 402 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
| 402 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
| 403 | 403 | data-description="" |
| 404 | - data-email="' . esc_attr( $user_email ) . '" |
|
| 405 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 406 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
| 407 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
| 408 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
| 409 | - data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '" |
|
| 410 | - data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', substr( get_locale(), 0, 2 ) ) ) . '" |
|
| 411 | - data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '" |
|
| 412 | - data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">'; |
|
| 413 | - |
|
| 414 | - if ( $this->description ) { |
|
| 415 | - if ( $this->testmode ) { |
|
| 404 | + data-email="' . esc_attr($user_email) . '" |
|
| 405 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 406 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
| 407 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
| 408 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
| 409 | + data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '" |
|
| 410 | + data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', substr(get_locale(), 0, 2))) . '" |
|
| 411 | + data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '" |
|
| 412 | + data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">'; |
|
| 413 | + |
|
| 414 | + if ($this->description) { |
|
| 415 | + if ($this->testmode) { |
|
| 416 | 416 | /* translators: link to Stripe testing page */ |
| 417 | - $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' ); |
|
| 418 | - $this->description = trim( $this->description ); |
|
| 417 | + $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'); |
|
| 418 | + $this->description = trim($this->description); |
|
| 419 | 419 | } |
| 420 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 420 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - if ( $display_tokenization ) { |
|
| 423 | + if ($display_tokenization) { |
|
| 424 | 424 | $this->tokenization_script(); |
| 425 | 425 | $this->saved_payment_methods(); |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | - if ( ! $this->stripe_checkout ) { |
|
| 429 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
| 428 | + if ( ! $this->stripe_checkout) { |
|
| 429 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
| 430 | 430 | $this->elements_form(); |
| 431 | 431 | } else { |
| 432 | 432 | $this->form(); |
@@ -434,7 +434,7 @@ discard block |
||
| 434 | 434 | } |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
| 437 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
| 438 | 438 | $this->save_payment_method_checkbox(); |
| 439 | 439 | } |
| 440 | 440 | |
@@ -449,12 +449,12 @@ discard block |
||
| 449 | 449 | */ |
| 450 | 450 | public function elements_form() { |
| 451 | 451 | ?> |
| 452 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
| 453 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
| 452 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
| 453 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
| 454 | 454 | |
| 455 | - <?php if ( $this->inline_cc_form ) { ?> |
|
| 455 | + <?php if ($this->inline_cc_form) { ?> |
|
| 456 | 456 | <label for="card-element"> |
| 457 | - <?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?> |
|
| 457 | + <?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?> |
|
| 458 | 458 | </label> |
| 459 | 459 | |
| 460 | 460 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | </div> |
| 463 | 463 | <?php } else { ?> |
| 464 | 464 | <div class="form-row form-row-wide"> |
| 465 | - <label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
| 465 | + <label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
| 466 | 466 | |
| 467 | 467 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
| 468 | 468 | <!-- a Stripe Element will be inserted here. --> |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | </div> |
| 471 | 471 | |
| 472 | 472 | <div class="form-row form-row-first"> |
| 473 | - <label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
| 473 | + <label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
| 474 | 474 | |
| 475 | 475 | <div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
| 476 | 476 | <!-- a Stripe Element will be inserted here. --> |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | </div> |
| 479 | 479 | |
| 480 | 480 | <div class="form-row form-row-last"> |
| 481 | - <label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
| 481 | + <label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
| 482 | 482 | <div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
| 483 | 483 | <!-- a Stripe Element will be inserted here. --> |
| 484 | 484 | </div> |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | |
| 489 | 489 | <!-- Used to display form errors --> |
| 490 | 490 | <div class="stripe-source-errors" role="alert"></div> |
| 491 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
| 491 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
| 492 | 492 | <div class="clear"></div> |
| 493 | 493 | </fieldset> |
| 494 | 494 | <?php |
@@ -501,13 +501,13 @@ discard block |
||
| 501 | 501 | * @version 3.1.0 |
| 502 | 502 | */ |
| 503 | 503 | public function admin_scripts() { |
| 504 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
| 504 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
| 505 | 505 | return; |
| 506 | 506 | } |
| 507 | 507 | |
| 508 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 508 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 509 | 509 | |
| 510 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
| 510 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | /** |
@@ -519,29 +519,29 @@ discard block |
||
| 519 | 519 | * @version 4.0.0 |
| 520 | 520 | */ |
| 521 | 521 | public function payment_scripts() { |
| 522 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
| 522 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
| 523 | 523 | return; |
| 524 | 524 | } |
| 525 | 525 | |
| 526 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 526 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 527 | 527 | |
| 528 | - wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' ); |
|
| 529 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 530 | - wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true ); |
|
| 531 | - wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true ); |
|
| 532 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
| 533 | - 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 ); |
|
| 528 | + wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5'); |
|
| 529 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 530 | + wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true); |
|
| 531 | + wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true); |
|
| 532 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
| 533 | + 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); |
|
| 534 | 534 | |
| 535 | 535 | $stripe_params = array( |
| 536 | 536 | 'key' => $this->publishable_key, |
| 537 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
| 538 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
| 537 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
| 538 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
| 539 | 539 | ); |
| 540 | 540 | |
| 541 | 541 | // If we're on the pay page we need to pass stripe.js the address of the order. |
| 542 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
| 543 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
| 544 | - $order = wc_get_order( $order_id ); |
|
| 542 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
| 543 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
| 544 | + $order = wc_get_order($order_id); |
|
| 545 | 545 | |
| 546 | 546 | $stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
| 547 | 547 | $stripe_params['billing_last_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
@@ -553,38 +553,38 @@ discard block |
||
| 553 | 553 | $stripe_params['billing_country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | - $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' ); |
|
| 557 | - $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
| 558 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
| 559 | - $stripe_params['sepa_mandate_notification'] = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' ); |
|
| 560 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
| 556 | + $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'); |
|
| 557 | + $stripe_params['no_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
| 558 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
| 559 | + $stripe_params['sepa_mandate_notification'] = apply_filters('wc_stripe_sepa_mandate_notification', 'email'); |
|
| 560 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
| 561 | 561 | $stripe_params['inline_cc_form'] = $this->inline_cc_form ? 'yes' : 'no'; |
| 562 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
| 563 | - $stripe_params['is_checkout'] = ( is_checkout() && empty( $_GET['pay_for_order'] ) ); |
|
| 562 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
| 563 | + $stripe_params['is_checkout'] = (is_checkout() && empty($_GET['pay_for_order'])); |
|
| 564 | 564 | $stripe_params['return_url'] = $this->get_stripe_return_url(); |
| 565 | - $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); |
|
| 566 | - $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); |
|
| 565 | + $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint('%%endpoint%%'); |
|
| 566 | + $stripe_params['stripe_nonce'] = wp_create_nonce('_wc_stripe_nonce'); |
|
| 567 | 567 | $stripe_params['statement_descriptor'] = $this->statement_descriptor; |
| 568 | - $stripe_params['use_elements'] = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no'; |
|
| 569 | - $stripe_params['elements_options'] = apply_filters( 'wc_stripe_elements_options', array() ); |
|
| 568 | + $stripe_params['use_elements'] = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no'; |
|
| 569 | + $stripe_params['elements_options'] = apply_filters('wc_stripe_elements_options', array()); |
|
| 570 | 570 | $stripe_params['is_stripe_checkout'] = $this->stripe_checkout ? 'yes' : 'no'; |
| 571 | - $stripe_params['is_change_payment_page'] = ( isset( $_GET['pay_for_order'] ) || isset( $_GET['change_payment_method'] ) ) ? 'yes' : 'no'; |
|
| 571 | + $stripe_params['is_change_payment_page'] = (isset($_GET['pay_for_order']) || isset($_GET['change_payment_method'])) ? 'yes' : 'no'; |
|
| 572 | 572 | $stripe_params['is_add_payment_method_page'] = is_add_payment_method_page() ? 'yes' : 'no'; |
| 573 | - $stripe_params['elements_styling'] = apply_filters( 'wc_stripe_elements_styling', false ); |
|
| 574 | - $stripe_params['elements_classes'] = apply_filters( 'wc_stripe_elements_classes', false ); |
|
| 573 | + $stripe_params['elements_styling'] = apply_filters('wc_stripe_elements_styling', false); |
|
| 574 | + $stripe_params['elements_classes'] = apply_filters('wc_stripe_elements_classes', false); |
|
| 575 | 575 | |
| 576 | 576 | // merge localized messages to be use in JS |
| 577 | - $stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() ); |
|
| 577 | + $stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages()); |
|
| 578 | 578 | |
| 579 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
| 580 | - wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
| 579 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
| 580 | + wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
| 581 | 581 | |
| 582 | - if ( $this->stripe_checkout ) { |
|
| 583 | - wp_enqueue_script( 'stripe_checkout' ); |
|
| 582 | + if ($this->stripe_checkout) { |
|
| 583 | + wp_enqueue_script('stripe_checkout'); |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | $this->tokenization_script(); |
| 587 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 587 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | /** |
@@ -600,43 +600,43 @@ discard block |
||
| 600 | 600 | * |
| 601 | 601 | * @return array|void |
| 602 | 602 | */ |
| 603 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 603 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 604 | 604 | try { |
| 605 | - $order = wc_get_order( $order_id ); |
|
| 605 | + $order = wc_get_order($order_id); |
|
| 606 | 606 | |
| 607 | 607 | // This comes from the create account checkbox in the checkout page. |
| 608 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 608 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 609 | 609 | |
| 610 | - if ( $create_account ) { |
|
| 610 | + if ($create_account) { |
|
| 611 | 611 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 612 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 612 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 613 | 613 | $new_stripe_customer->create_customer(); |
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | $source_object = $this->get_source_object(); |
| 617 | - $prepared_source = $this->prepare_source( $source_object, get_current_user_id(), $force_save_source ); |
|
| 617 | + $prepared_source = $this->prepare_source($source_object, get_current_user_id(), $force_save_source); |
|
| 618 | 618 | |
| 619 | 619 | // Check if we don't allow prepaid credit cards. |
| 620 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) { |
|
| 621 | - if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) { |
|
| 622 | - $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' ); |
|
| 623 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message ); |
|
| 620 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) { |
|
| 621 | + if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) { |
|
| 622 | + $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'); |
|
| 623 | + throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message); |
|
| 624 | 624 | } |
| 625 | 625 | } |
| 626 | 626 | |
| 627 | - if ( empty( $prepared_source->source ) ) { |
|
| 628 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
| 629 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
| 627 | + if (empty($prepared_source->source)) { |
|
| 628 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
| 629 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | - $this->save_source_to_order( $order, $prepared_source ); |
|
| 632 | + $this->save_source_to_order($order, $prepared_source); |
|
| 633 | 633 | |
| 634 | 634 | // Result from Stripe API request. |
| 635 | 635 | $response = null; |
| 636 | 636 | |
| 637 | - if ( $order->get_total() > 0 ) { |
|
| 637 | + if ($order->get_total() > 0) { |
|
| 638 | 638 | // This will throw exception if not valid. |
| 639 | - $this->validate_minimum_order_amount( $order ); |
|
| 639 | + $this->validate_minimum_order_amount($order); |
|
| 640 | 640 | |
| 641 | 641 | /* |
| 642 | 642 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -645,109 +645,109 @@ discard block |
||
| 645 | 645 | * Note that if we need to save source, the original source must be first |
| 646 | 646 | * attached to a customer in Stripe before it can be charged. |
| 647 | 647 | */ |
| 648 | - if ( $this->is_3ds_required( $source_object ) ) { |
|
| 649 | - $response = $this->create_3ds_source( $order, $source_object ); |
|
| 648 | + if ($this->is_3ds_required($source_object)) { |
|
| 649 | + $response = $this->create_3ds_source($order, $source_object); |
|
| 650 | 650 | |
| 651 | - if ( ! empty( $response->error ) ) { |
|
| 651 | + if ( ! empty($response->error)) { |
|
| 652 | 652 | $localized_message = $response->error->message; |
| 653 | 653 | |
| 654 | - $order->add_order_note( $localized_message ); |
|
| 654 | + $order->add_order_note($localized_message); |
|
| 655 | 655 | |
| 656 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 656 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | // Update order meta with 3DS source. |
| 660 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 661 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 660 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 661 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 662 | 662 | } else { |
| 663 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 663 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 664 | 664 | $order->save(); |
| 665 | 665 | } |
| 666 | 666 | |
| 667 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
| 667 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
| 668 | 668 | |
| 669 | 669 | return array( |
| 670 | 670 | 'result' => 'success', |
| 671 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 671 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 672 | 672 | ); |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
| 675 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
| 676 | 676 | |
| 677 | 677 | // Make the request. |
| 678 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
| 678 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
| 679 | 679 | |
| 680 | - if ( ! empty( $response->error ) ) { |
|
| 680 | + if ( ! empty($response->error)) { |
|
| 681 | 681 | // If it is an API error such connection or server, let's retry. |
| 682 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
| 683 | - if ( $retry ) { |
|
| 684 | - sleep( 5 ); |
|
| 685 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
| 682 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
| 683 | + if ($retry) { |
|
| 684 | + sleep(5); |
|
| 685 | + return $this->process_payment($order_id, false, $force_save_source); |
|
| 686 | 686 | } else { |
| 687 | 687 | $localized_message = 'API connection error and retries exhausted.'; |
| 688 | - $order->add_order_note( $localized_message ); |
|
| 689 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 688 | + $order->add_order_note($localized_message); |
|
| 689 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 690 | 690 | } |
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | // We want to retry. |
| 694 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
| 695 | - if ( $retry ) { |
|
| 694 | + if ($this->is_retryable_error($response->error)) { |
|
| 695 | + if ($retry) { |
|
| 696 | 696 | // Don't do anymore retries after this. |
| 697 | - if ( 5 <= $this->retry_interval ) { |
|
| 697 | + if (5 <= $this->retry_interval) { |
|
| 698 | 698 | |
| 699 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
| 699 | + return $this->process_payment($order_id, false, $force_save_source); |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | - sleep( $this->retry_interval ); |
|
| 702 | + sleep($this->retry_interval); |
|
| 703 | 703 | |
| 704 | 704 | $this->retry_interval++; |
| 705 | - return $this->process_payment( $order_id, true, $force_save_source ); |
|
| 705 | + return $this->process_payment($order_id, true, $force_save_source); |
|
| 706 | 706 | } else { |
| 707 | - $localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' ); |
|
| 708 | - $order->add_order_note( $localized_message ); |
|
| 709 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 707 | + $localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe'); |
|
| 708 | + $order->add_order_note($localized_message); |
|
| 709 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 710 | 710 | } |
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
| 714 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
| 715 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 716 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
| 717 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 714 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
| 715 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 716 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
| 717 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
| 718 | 718 | } else { |
| 719 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
| 720 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
| 719 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
| 720 | + $order->delete_meta_data('_stripe_customer_id'); |
|
| 721 | 721 | $order->save(); |
| 722 | 722 | } |
| 723 | 723 | |
| 724 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
| 725 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) { |
|
| 724 | + return $this->process_payment($order_id, false, $force_save_source); |
|
| 725 | + } elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) { |
|
| 726 | 726 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
| 727 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
| 727 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
| 728 | 728 | $wc_token->delete(); |
| 729 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
| 730 | - $order->add_order_note( $localized_message ); |
|
| 731 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 729 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
| 730 | + $order->add_order_note($localized_message); |
|
| 731 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
| 735 | 735 | |
| 736 | - if ( 'card_error' === $response->error->type ) { |
|
| 737 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 736 | + if ('card_error' === $response->error->type) { |
|
| 737 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
| 738 | 738 | } else { |
| 739 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 739 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
| 740 | 740 | } |
| 741 | 741 | |
| 742 | - $order->add_order_note( $localized_message ); |
|
| 742 | + $order->add_order_note($localized_message); |
|
| 743 | 743 | |
| 744 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 744 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
| 747 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
| 748 | 748 | |
| 749 | 749 | // Process valid response. |
| 750 | - $this->process_response( $response, $order ); |
|
| 750 | + $this->process_response($response, $order); |
|
| 751 | 751 | } else { |
| 752 | 752 | $order->payment_complete(); |
| 753 | 753 | } |
@@ -758,17 +758,17 @@ discard block |
||
| 758 | 758 | // Return thank you page redirect. |
| 759 | 759 | return array( |
| 760 | 760 | 'result' => 'success', |
| 761 | - 'redirect' => $this->get_return_url( $order ), |
|
| 761 | + 'redirect' => $this->get_return_url($order), |
|
| 762 | 762 | ); |
| 763 | 763 | |
| 764 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 765 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 766 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 764 | + } catch (WC_Stripe_Exception $e) { |
|
| 765 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 766 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 767 | 767 | |
| 768 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 768 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 769 | 769 | |
| 770 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 771 | - $this->send_failed_order_email( $order_id ); |
|
| 770 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 771 | + $this->send_failed_order_email($order_id); |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -15,24 +15,24 @@ discard block |
||
| 15 | 15 | public function __construct() { |
| 16 | 16 | parent::__construct(); |
| 17 | 17 | |
| 18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
| 19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
| 20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
| 21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
| 22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
| 18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
| 19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
| 20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
| 21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
| 22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
| 23 | 23 | |
| 24 | 24 | // display the credit card used for a subscription in the "My Subscriptions" table |
| 25 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
| 25 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
| 26 | 26 | |
| 27 | 27 | // allow store managers to manually set Stripe as the payment method on a subscription |
| 28 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
| 29 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
| 30 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
| 31 | - add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 ); |
|
| 28 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
| 29 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
| 30 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
| 31 | + add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
| 35 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) ); |
|
| 34 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
| 35 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment')); |
|
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * @since 4.0.0 |
| 44 | 44 | * @version 4.0.0 |
| 45 | 45 | */ |
| 46 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
| 47 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
| 46 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
| 47 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
| 48 | 48 | return false; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | * @param int $order_id |
| 57 | 57 | * @return boolean |
| 58 | 58 | */ |
| 59 | - public function has_subscription( $order_id ) { |
|
| 60 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
| 59 | + public function has_subscription($order_id) { |
|
| 60 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | * @param int $order_id |
| 66 | 66 | * @return boolean |
| 67 | 67 | */ |
| 68 | - protected function is_pre_order( $order_id ) { |
|
| 69 | - return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
| 68 | + protected function is_pre_order($order_id) { |
|
| 69 | + return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | * @param int $order_id |
| 75 | 75 | * @return array |
| 76 | 76 | */ |
| 77 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 78 | - if ( $this->has_subscription( $order_id ) ) { |
|
| 77 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 78 | + if ($this->has_subscription($order_id)) { |
|
| 79 | 79 | // Regular payment with force customer enabled |
| 80 | - return parent::process_payment( $order_id, true, true ); |
|
| 81 | - } elseif ( $this->is_pre_order( $order_id ) ) { |
|
| 82 | - return $this->process_pre_order( $order_id, $retry, $force_save_source ); |
|
| 80 | + return parent::process_payment($order_id, true, true); |
|
| 81 | + } elseif ($this->is_pre_order($order_id)) { |
|
| 82 | + return $this->process_pre_order($order_id, $retry, $force_save_source); |
|
| 83 | 83 | } else { |
| 84 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
| 84 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
@@ -92,14 +92,14 @@ discard block |
||
| 92 | 92 | * @param array $metadata |
| 93 | 93 | * @param object $order |
| 94 | 94 | */ |
| 95 | - public function add_subscription_meta_data( $metadata, $order ) { |
|
| 96 | - if ( ! $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) { |
|
| 95 | + public function add_subscription_meta_data($metadata, $order) { |
|
| 96 | + if ( ! $this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) { |
|
| 97 | 97 | return $metadata; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | return $metadata += array( |
| 101 | 101 | 'payment_type' => 'recurring', |
| 102 | - 'site_url' => esc_url( get_site_url() ), |
|
| 102 | + 'site_url' => esc_url(get_site_url()), |
|
| 103 | 103 | ); |
| 104 | 104 | } |
| 105 | 105 | |
@@ -109,24 +109,24 @@ discard block |
||
| 109 | 109 | * @since 3.1.0 |
| 110 | 110 | * @version 4.0.0 |
| 111 | 111 | */ |
| 112 | - public function save_source_to_order( $order, $source ) { |
|
| 113 | - parent::save_source_to_order( $order, $source ); |
|
| 112 | + public function save_source_to_order($order, $source) { |
|
| 113 | + parent::save_source_to_order($order, $source); |
|
| 114 | 114 | |
| 115 | - $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
| 115 | + $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
| 116 | 116 | |
| 117 | 117 | // Also store it on the subscriptions being purchased or paid for in the order |
| 118 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
| 119 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
| 120 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
| 121 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
| 118 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
| 119 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
| 120 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
| 121 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
| 122 | 122 | } else { |
| 123 | 123 | $subscriptions = array(); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - foreach ( $subscriptions as $subscription ) { |
|
| 126 | + foreach ($subscriptions as $subscription) { |
|
| 127 | 127 | $subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id(); |
| 128 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
| 129 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
| 128 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
| 129 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
@@ -139,45 +139,45 @@ discard block |
||
| 139 | 139 | * @param mixed $renewal_order |
| 140 | 140 | * @param bool $is_retry Is this a retry process. |
| 141 | 141 | */ |
| 142 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) { |
|
| 143 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 142 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) { |
|
| 143 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 144 | 144 | /* translators: minimum amount */ |
| 145 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
| 145 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | $order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id(); |
| 149 | 149 | |
| 150 | 150 | // Get source from order |
| 151 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
| 151 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
| 152 | 152 | |
| 153 | - if ( ! $prepared_source->customer ) { |
|
| 154 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
| 153 | + if ( ! $prepared_source->customer) { |
|
| 154 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
| 157 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
| 158 | 158 | |
| 159 | - if ( $is_retry ) { |
|
| 159 | + if ($is_retry) { |
|
| 160 | 160 | // Passing empty source with charge customer default. |
| 161 | 161 | $prepared_source->source = ''; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
| 164 | + $request = $this->generate_payment_request($renewal_order, $prepared_source); |
|
| 165 | 165 | $request['capture'] = 'true'; |
| 166 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
| 167 | - $response = WC_Stripe_API::request( $request ); |
|
| 166 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
| 167 | + $response = WC_Stripe_API::request($request); |
|
| 168 | 168 | |
| 169 | - if ( ! empty( $response->error ) || is_wp_error( $response ) ) { |
|
| 170 | - if ( $is_retry ) { |
|
| 169 | + if ( ! empty($response->error) || is_wp_error($response)) { |
|
| 170 | + if ($is_retry) { |
|
| 171 | 171 | /* translators: error message */ |
| 172 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
| 172 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | return $response; // Default catch all errors. |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - $this->process_response( $response, $renewal_order ); |
|
| 178 | + $this->process_response($response, $renewal_order); |
|
| 179 | 179 | |
| 180 | - if ( ! $is_retry ) { |
|
| 180 | + if ( ! $is_retry) { |
|
| 181 | 181 | return $response; |
| 182 | 182 | } |
| 183 | 183 | } |
@@ -186,21 +186,21 @@ discard block |
||
| 186 | 186 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
| 187 | 187 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 188 | 188 | */ |
| 189 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
| 190 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
| 191 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
| 189 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
| 190 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
| 191 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
| 192 | 192 | // For BW compat will remove in future |
| 193 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
| 194 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
| 193 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
| 194 | + $this->delete_renewal_meta($resubscribe_order); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
| 198 | 198 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 199 | 199 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 200 | 200 | */ |
| 201 | - public function delete_renewal_meta( $renewal_order ) { |
|
| 202 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
|
| 203 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' ); |
|
| 201 | + public function delete_renewal_meta($renewal_order) { |
|
| 202 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee'); |
|
| 203 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe'); |
|
| 204 | 204 | return $renewal_order; |
| 205 | 205 | } |
| 206 | 206 | |
@@ -210,21 +210,21 @@ discard block |
||
| 210 | 210 | * @param $amount_to_charge float The amount to charge. |
| 211 | 211 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
| 212 | 212 | */ |
| 213 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
| 214 | - $response = $this->process_subscription_payment( $amount_to_charge, $renewal_order ); |
|
| 213 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
| 214 | + $response = $this->process_subscription_payment($amount_to_charge, $renewal_order); |
|
| 215 | 215 | |
| 216 | - if ( is_wp_error( $response ) ) { |
|
| 216 | + if (is_wp_error($response)) { |
|
| 217 | 217 | /* translators: error message */ |
| 218 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
| 218 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - if ( ! empty( $response->error ) ) { |
|
| 221 | + if ( ! empty($response->error)) { |
|
| 222 | 222 | // This is a very generic error to listen for but worth a retry before total fail. |
| 223 | - if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
| 224 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true ); |
|
| 223 | + if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
| 224 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true); |
|
| 225 | 225 | } else { |
| 226 | 226 | /* translators: error message */ |
| 227 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
| 227 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | } |
@@ -233,20 +233,20 @@ discard block |
||
| 233 | 233 | * Remove order meta |
| 234 | 234 | * @param object $order |
| 235 | 235 | */ |
| 236 | - public function remove_order_source_before_retry( $order ) { |
|
| 236 | + public function remove_order_source_before_retry($order) { |
|
| 237 | 237 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 238 | - delete_post_meta( $order_id, '_stripe_source_id' ); |
|
| 238 | + delete_post_meta($order_id, '_stripe_source_id'); |
|
| 239 | 239 | // For BW compat will remove in the future. |
| 240 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
| 240 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | /** |
| 244 | 244 | * Remove order meta |
| 245 | 245 | * @param object $order |
| 246 | 246 | */ |
| 247 | - public function remove_order_customer_before_retry( $order ) { |
|
| 247 | + public function remove_order_customer_before_retry($order) { |
|
| 248 | 248 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 249 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 249 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -258,14 +258,14 @@ discard block |
||
| 258 | 258 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
| 259 | 259 | * @return void |
| 260 | 260 | */ |
| 261 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
| 262 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 263 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
| 264 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
| 261 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
| 262 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 263 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
| 264 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
| 265 | 265 | |
| 266 | 266 | } else { |
| 267 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
| 268 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
| 267 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
| 268 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | |
@@ -278,21 +278,21 @@ discard block |
||
| 278 | 278 | * @param WC_Subscription $subscription An instance of a subscription object |
| 279 | 279 | * @return array |
| 280 | 280 | */ |
| 281 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
| 282 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 281 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
| 282 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 283 | 283 | |
| 284 | 284 | // For BW compat will remove in future. |
| 285 | - if ( empty( $source_id ) ) { |
|
| 286 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 285 | + if (empty($source_id)) { |
|
| 286 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 287 | 287 | |
| 288 | 288 | // Take this opportunity to update the key name. |
| 289 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
| 289 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - $payment_meta[ $this->id ] = array( |
|
| 292 | + $payment_meta[$this->id] = array( |
|
| 293 | 293 | 'post_meta' => array( |
| 294 | 294 | '_stripe_customer_id' => array( |
| 295 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
| 295 | + 'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
| 296 | 296 | 'label' => 'Stripe Customer ID', |
| 297 | 297 | ), |
| 298 | 298 | '_stripe_source_id' => array( |
@@ -313,22 +313,22 @@ discard block |
||
| 313 | 313 | * @param array $payment_meta associative array of meta data required for automatic payments |
| 314 | 314 | * @return array |
| 315 | 315 | */ |
| 316 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
| 317 | - if ( $this->id === $payment_method_id ) { |
|
| 316 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
| 317 | + if ($this->id === $payment_method_id) { |
|
| 318 | 318 | |
| 319 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
| 320 | - throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
| 321 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
| 322 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
| 319 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
| 320 | + throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
| 321 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
| 322 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | if ( |
| 326 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
| 327 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
| 328 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
| 329 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
| 326 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
| 327 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
| 328 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
| 329 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
| 330 | 330 | |
| 331 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
| 331 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | } |
@@ -341,89 +341,89 @@ discard block |
||
| 341 | 341 | * @param WC_Subscription $subscription the subscription details |
| 342 | 342 | * @return string the subscription payment method |
| 343 | 343 | */ |
| 344 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
| 344 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
| 345 | 345 | $customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
| 346 | 346 | |
| 347 | 347 | // bail for other payment methods |
| 348 | - if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
| 348 | + if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
| 349 | 349 | return $payment_method_to_display; |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 352 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 353 | 353 | |
| 354 | 354 | // For BW compat will remove in future. |
| 355 | - if ( empty( $stripe_source_id ) ) { |
|
| 356 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 355 | + if (empty($stripe_source_id)) { |
|
| 356 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 357 | 357 | |
| 358 | 358 | // Take this opportunity to update the key name. |
| 359 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 359 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | $stripe_customer = new WC_Stripe_Customer(); |
| 363 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
| 363 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
| 364 | 364 | |
| 365 | 365 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
| 366 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
| 366 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
| 367 | 367 | $user_id = $customer_user; |
| 368 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
| 369 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
| 368 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
| 369 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
| 370 | 370 | |
| 371 | 371 | // For BW compat will remove in future. |
| 372 | - if ( empty( $stripe_source_id ) ) { |
|
| 373 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
| 372 | + if (empty($stripe_source_id)) { |
|
| 373 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
| 374 | 374 | |
| 375 | 375 | // Take this opportunity to update the key name. |
| 376 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
| 376 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
| 377 | 377 | } |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
| 381 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
| 382 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
| 383 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
| 381 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
| 382 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
| 383 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
| 384 | 384 | |
| 385 | 385 | // For BW compat will remove in future. |
| 386 | - if ( empty( $stripe_source_id ) ) { |
|
| 387 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
| 386 | + if (empty($stripe_source_id)) { |
|
| 387 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
| 388 | 388 | |
| 389 | 389 | // Take this opportunity to update the key name. |
| 390 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 390 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
| 391 | 391 | } |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 394 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 395 | 395 | $sources = $stripe_customer->get_sources(); |
| 396 | 396 | |
| 397 | - if ( $sources ) { |
|
| 397 | + if ($sources) { |
|
| 398 | 398 | $found_source = false; |
| 399 | - foreach ( $sources as $source ) { |
|
| 400 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
| 399 | + foreach ($sources as $source) { |
|
| 400 | + if (isset($source->type) && 'card' === $source->type) { |
|
| 401 | 401 | $card = $source->card; |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | - if ( $source->id === $stripe_source_id ) { |
|
| 404 | + if ($source->id === $stripe_source_id) { |
|
| 405 | 405 | $found_source = true; |
| 406 | 406 | |
| 407 | - if ( $card ) { |
|
| 407 | + if ($card) { |
|
| 408 | 408 | /* translators: 1) card brand 2) last 4 digits */ |
| 409 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
| 409 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
| 410 | 410 | } else { |
| 411 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 411 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 412 | 412 | } |
| 413 | 413 | break; |
| 414 | 414 | } |
| 415 | 415 | } |
| 416 | 416 | |
| 417 | - if ( ! $found_source ) { |
|
| 418 | - if ( 'card' === $sources[0]->type ) { |
|
| 417 | + if ( ! $found_source) { |
|
| 418 | + if ('card' === $sources[0]->type) { |
|
| 419 | 419 | $card = $sources[0]->card; |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | - if ( $card ) { |
|
| 422 | + if ($card) { |
|
| 423 | 423 | /* translators: 1) card brand 2) last 4 digits */ |
| 424 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
| 424 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
| 425 | 425 | } else { |
| 426 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 426 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 427 | 427 | } |
| 428 | 428 | } |
| 429 | 429 | } |
@@ -436,42 +436,42 @@ discard block |
||
| 436 | 436 | * @param int $order_id |
| 437 | 437 | * @return array |
| 438 | 438 | */ |
| 439 | - public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
| 440 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
| 439 | + public function process_pre_order($order_id, $retry, $force_save_source) { |
|
| 440 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
| 441 | 441 | try { |
| 442 | - $order = wc_get_order( $order_id ); |
|
| 442 | + $order = wc_get_order($order_id); |
|
| 443 | 443 | |
| 444 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 444 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 445 | 445 | /* translators: minimum amount */ |
| 446 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
| 446 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | - $source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true ); |
|
| 449 | + $source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true); |
|
| 450 | 450 | |
| 451 | 451 | // We need a source on file to continue. |
| 452 | - if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
| 453 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
| 452 | + if (empty($source->customer) || empty($source->source)) { |
|
| 453 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | - $this->save_source_to_order( $order, $source ); |
|
| 456 | + $this->save_source_to_order($order, $source); |
|
| 457 | 457 | |
| 458 | 458 | // Remove cart |
| 459 | 459 | WC()->cart->empty_cart(); |
| 460 | 460 | |
| 461 | 461 | // Is pre ordered! |
| 462 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
| 462 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
| 463 | 463 | |
| 464 | 464 | // Return thank you page redirect |
| 465 | 465 | return array( |
| 466 | 466 | 'result' => 'success', |
| 467 | - 'redirect' => $this->get_return_url( $order ), |
|
| 467 | + 'redirect' => $this->get_return_url($order), |
|
| 468 | 468 | ); |
| 469 | - } catch ( Exception $e ) { |
|
| 470 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 469 | + } catch (Exception $e) { |
|
| 470 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 471 | 471 | return; |
| 472 | 472 | } |
| 473 | 473 | } else { |
| 474 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
| 474 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
| 475 | 475 | } |
| 476 | 476 | } |
| 477 | 477 | |
@@ -480,7 +480,7 @@ discard block |
||
| 480 | 480 | * @param WC_Order $order |
| 481 | 481 | * @return void |
| 482 | 482 | */ |
| 483 | - public function process_pre_order_release_payment( $order ) { |
|
| 483 | + public function process_pre_order_release_payment($order) { |
|
| 484 | 484 | try { |
| 485 | 485 | // Define some callbacks if the first attempt fails. |
| 486 | 486 | $retry_callbacks = array( |
@@ -488,33 +488,33 @@ discard block |
||
| 488 | 488 | 'remove_order_customer_before_retry', |
| 489 | 489 | ); |
| 490 | 490 | |
| 491 | - while ( 1 ) { |
|
| 492 | - $source = $this->prepare_order_source( $order ); |
|
| 493 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
| 491 | + while (1) { |
|
| 492 | + $source = $this->prepare_order_source($order); |
|
| 493 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
| 494 | 494 | |
| 495 | - if ( ! empty( $response->error ) ) { |
|
| 496 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
| 497 | - throw new Exception( $response->error->message ); |
|
| 495 | + if ( ! empty($response->error)) { |
|
| 496 | + if (0 === sizeof($retry_callbacks)) { |
|
| 497 | + throw new Exception($response->error->message); |
|
| 498 | 498 | } else { |
| 499 | - $retry_callback = array_shift( $retry_callbacks ); |
|
| 500 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
| 499 | + $retry_callback = array_shift($retry_callbacks); |
|
| 500 | + call_user_func(array($this, $retry_callback), $order); |
|
| 501 | 501 | } |
| 502 | 502 | } else { |
| 503 | 503 | // Successful |
| 504 | - $this->process_response( $response, $order ); |
|
| 504 | + $this->process_response($response, $order); |
|
| 505 | 505 | break; |
| 506 | 506 | } |
| 507 | 507 | } |
| 508 | - } catch ( Exception $e ) { |
|
| 508 | + } catch (Exception $e) { |
|
| 509 | 509 | /* translators: error message */ |
| 510 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
| 510 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
| 511 | 511 | |
| 512 | 512 | // Mark order as failed if not already set, |
| 513 | 513 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
| 514 | - if ( ! $order->has_status( 'failed' ) ) { |
|
| 515 | - $order->update_status( 'failed', $order_note ); |
|
| 514 | + if ( ! $order->has_status('failed')) { |
|
| 515 | + $order->update_status('failed', $order_note); |
|
| 516 | 516 | } else { |
| 517 | - $order->add_order_note( $order_note ); |
|
| 517 | + $order->add_order_note($order_note); |
|
| 518 | 518 | } |
| 519 | 519 | } |
| 520 | 520 | } |
@@ -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.5' ); |
|
| 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.5'); |
|
| 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,43 +94,43 @@ 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-gateway-stripe.php' ); |
|
| 113 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php' ); |
|
| 114 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php' ); |
|
| 115 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php' ); |
|
| 116 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php' ); |
|
| 117 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php' ); |
|
| 118 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php' ); |
|
| 119 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php' ); |
|
| 120 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php' ); |
|
| 121 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php' ); |
|
| 122 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-compat.php' ); |
|
| 123 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-compat.php' ); |
|
| 124 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php' ); |
|
| 125 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php' ); |
|
| 126 | - 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-gateway-stripe.php'); |
|
| 113 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'); |
|
| 114 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'); |
|
| 115 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'); |
|
| 116 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'); |
|
| 117 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'); |
|
| 118 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'); |
|
| 119 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'); |
|
| 120 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php'); |
|
| 121 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php'); |
|
| 122 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-compat.php'); |
|
| 123 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-compat.php'); |
|
| 124 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php'); |
|
| 125 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php'); |
|
| 126 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'); |
|
| 127 | 127 | |
| 128 | 128 | // REMOVE IN THE FUTURE. |
| 129 | - require_once( dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php' ); |
|
| 129 | + require_once(dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php'); |
|
| 130 | 130 | |
| 131 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
| 132 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
| 133 | - add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); |
|
| 131 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
| 132 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
| 133 | + add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin')); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -140,23 +140,23 @@ discard block |
||
| 140 | 140 | * @version 4.0.0 |
| 141 | 141 | */ |
| 142 | 142 | public function hide_notices() { |
| 143 | - if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) { |
|
| 144 | - if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) { |
|
| 145 | - wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) ); |
|
| 143 | + if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) { |
|
| 144 | + if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) { |
|
| 145 | + wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe')); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 149 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 148 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 149 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - $notice = wc_clean( $_GET['wc-stripe-hide-notice'] ); |
|
| 152 | + $notice = wc_clean($_GET['wc-stripe-hide-notice']); |
|
| 153 | 153 | |
| 154 | - switch ( $notice ) { |
|
| 154 | + switch ($notice) { |
|
| 155 | 155 | case 'ssl': |
| 156 | - update_option( 'wc_stripe_show_ssl_notice', 'no' ); |
|
| 156 | + update_option('wc_stripe_show_ssl_notice', 'no'); |
|
| 157 | 157 | break; |
| 158 | 158 | case 'keys': |
| 159 | - update_option( 'wc_stripe_show_keys_notice', 'no' ); |
|
| 159 | + update_option('wc_stripe_show_keys_notice', 'no'); |
|
| 160 | 160 | break; |
| 161 | 161 | } |
| 162 | 162 | } |
@@ -168,8 +168,8 @@ discard block |
||
| 168 | 168 | * @since 1.0.0 |
| 169 | 169 | * @version 4.0.0 |
| 170 | 170 | */ |
| 171 | - public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
|
| 172 | - $this->notices[ $slug ] = array( |
|
| 171 | + public function add_admin_notice($slug, $class, $message, $dismissible = false) { |
|
| 172 | + $this->notices[$slug] = array( |
|
| 173 | 173 | 'class' => $class, |
| 174 | 174 | 'message' => $message, |
| 175 | 175 | 'dismissible' => $dismissible, |
@@ -183,21 +183,21 @@ discard block |
||
| 183 | 183 | * @version 4.0.0 |
| 184 | 184 | */ |
| 185 | 185 | public function admin_notices() { |
| 186 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 186 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 187 | 187 | return; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 191 | - echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">'; |
|
| 190 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 191 | + echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">'; |
|
| 192 | 192 | |
| 193 | - if ( $notice['dismissible'] ) { |
|
| 193 | + if ($notice['dismissible']) { |
|
| 194 | 194 | ?> |
| 195 | - <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-stripe-hide-notice', $notice_key ), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce' ) ); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a> |
|
| 195 | + <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 | 196 | <?php |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | echo '<p>'; |
| 200 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 200 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 201 | 201 | echo '</p></div>'; |
| 202 | 202 | } |
| 203 | 203 | } |
@@ -210,26 +210,26 @@ discard block |
||
| 210 | 210 | * @version 4.0.0 |
| 211 | 211 | */ |
| 212 | 212 | public function get_environment_warning() { |
| 213 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
| 213 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
| 214 | 214 | /* translators: 1) int version 2) int version */ |
| 215 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
| 215 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
| 216 | 216 | |
| 217 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
| 217 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
| 221 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
| 220 | + if ( ! defined('WC_VERSION')) { |
|
| 221 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
| 224 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
| 225 | 225 | /* translators: 1) int version 2) int version */ |
| 226 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
| 226 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
| 227 | 227 | |
| 228 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
| 228 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - if ( ! function_exists( 'curl_init' ) ) { |
|
| 232 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
| 231 | + if ( ! function_exists('curl_init')) { |
|
| 232 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | return false; |
@@ -243,11 +243,11 @@ discard block |
||
| 243 | 243 | * @return string Setting link |
| 244 | 244 | */ |
| 245 | 245 | public function get_setting_link() { |
| 246 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
| 246 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
| 247 | 247 | |
| 248 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
| 248 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
| 249 | 249 | |
| 250 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
| 250 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -258,65 +258,65 @@ discard block |
||
| 258 | 258 | * @version 4.0.0 |
| 259 | 259 | */ |
| 260 | 260 | public function check_environment() { |
| 261 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
|
| 261 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) { |
|
| 262 | 262 | $this->install(); |
| 263 | 263 | |
| 264 | - do_action( 'woocommerce_stripe_updated' ); |
|
| 264 | + do_action('woocommerce_stripe_updated'); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | $environment_warning = $this->get_environment_warning(); |
| 268 | 268 | |
| 269 | - if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
| 270 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 269 | + if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) { |
|
| 270 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - $show_ssl_notice = get_option( 'wc_stripe_show_ssl_notice' ); |
|
| 274 | - $show_keys_notice = get_option( 'wc_stripe_show_keys_notice' ); |
|
| 275 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
| 276 | - $testmode = ( isset( $options['testmode'] ) && 'yes' === $options['testmode'] ) ? true : false; |
|
| 277 | - $test_pub_key = isset( $options['test_publishable_key'] ) ? $options['test_publishable_key'] : ''; |
|
| 278 | - $test_secret_key = isset( $options['test_secret_key'] ) ? $options['test_secret_key'] : ''; |
|
| 279 | - $live_pub_key = isset( $options['publishable_key'] ) ? $options['publishable_key'] : ''; |
|
| 280 | - $live_secret_key = isset( $options['secret_key'] ) ? $options['secret_key'] : ''; |
|
| 273 | + $show_ssl_notice = get_option('wc_stripe_show_ssl_notice'); |
|
| 274 | + $show_keys_notice = get_option('wc_stripe_show_keys_notice'); |
|
| 275 | + $options = get_option('woocommerce_stripe_settings'); |
|
| 276 | + $testmode = (isset($options['testmode']) && 'yes' === $options['testmode']) ? true : false; |
|
| 277 | + $test_pub_key = isset($options['test_publishable_key']) ? $options['test_publishable_key'] : ''; |
|
| 278 | + $test_secret_key = isset($options['test_secret_key']) ? $options['test_secret_key'] : ''; |
|
| 279 | + $live_pub_key = isset($options['publishable_key']) ? $options['publishable_key'] : ''; |
|
| 280 | + $live_secret_key = isset($options['secret_key']) ? $options['secret_key'] : ''; |
|
| 281 | 281 | |
| 282 | - if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] && empty( $show_keys_notice ) ) { |
|
| 283 | - $secret = WC_Stripe_API::get_secret_key(); |
|
| 282 | + if (isset($options['enabled']) && 'yes' === $options['enabled'] && empty($show_keys_notice)) { |
|
| 283 | + $secret = WC_Stripe_API::get_secret_key(); |
|
| 284 | 284 | |
| 285 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
| 285 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
| 286 | 286 | $setting_link = $this->get_setting_link(); |
| 287 | 287 | /* translators: 1) link */ |
| 288 | - $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 ); |
|
| 288 | + $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 | 289 | } |
| 290 | 290 | |
| 291 | 291 | // Check if keys are entered properly per live/test mode. |
| 292 | - if ( $testmode ) { |
|
| 292 | + if ($testmode) { |
|
| 293 | 293 | if ( |
| 294 | - ! empty( $test_pub_key ) && ! preg_match( '/^pk_test_/', $test_pub_key ) |
|
| 295 | - || ( ! empty( $test_secret_key ) && ! preg_match( '/^sk_test_/', $test_secret_key ) |
|
| 296 | - && ! empty( $test_secret_key ) && ! preg_match( '/^rk_test_/', $test_secret_key ) ) ) |
|
| 294 | + ! empty($test_pub_key) && ! preg_match('/^pk_test_/', $test_pub_key) |
|
| 295 | + || ( ! empty($test_secret_key) && ! preg_match('/^sk_test_/', $test_secret_key) |
|
| 296 | + && ! empty($test_secret_key) && ! preg_match('/^rk_test_/', $test_secret_key)) ) |
|
| 297 | 297 | { |
| 298 | 298 | $setting_link = $this->get_setting_link(); |
| 299 | 299 | /* translators: 1) link */ |
| 300 | - $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 ); |
|
| 300 | + $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 | 301 | } |
| 302 | 302 | } else { |
| 303 | 303 | if ( |
| 304 | - ! empty( $live_pub_key ) && ! preg_match( '/^pk_live_/', $live_pub_key ) |
|
| 305 | - || ( ! empty( $live_secret_key ) && ! preg_match( '/^sk_live_/', $live_secret_key ) |
|
| 306 | - && ! empty( $live_secret_key ) && ! preg_match( '/^rk_live_/', $live_secret_key ) ) ) |
|
| 304 | + ! empty($live_pub_key) && ! preg_match('/^pk_live_/', $live_pub_key) |
|
| 305 | + || ( ! empty($live_secret_key) && ! preg_match('/^sk_live_/', $live_secret_key) |
|
| 306 | + && ! empty($live_secret_key) && ! preg_match('/^rk_live_/', $live_secret_key)) ) |
|
| 307 | 307 | { |
| 308 | 308 | $setting_link = $this->get_setting_link(); |
| 309 | 309 | /* translators: 1) link */ |
| 310 | - $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 ); |
|
| 310 | + $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 | 311 | } |
| 312 | 312 | } |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - if ( empty( $show_ssl_notice ) && isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) { |
|
| 315 | + if (empty($show_ssl_notice) && isset($options['enabled']) && 'yes' === $options['enabled']) { |
|
| 316 | 316 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
| 317 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
| 317 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
| 318 | 318 | /* translators: 1) link 2) link */ |
| 319 | - $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 ); |
|
| 319 | + $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 | 320 | } |
| 321 | 321 | } |
| 322 | 322 | } |
@@ -328,8 +328,8 @@ discard block |
||
| 328 | 328 | * @version 4.0.0 |
| 329 | 329 | */ |
| 330 | 330 | public function update_plugin_version() { |
| 331 | - delete_option( 'wc_stripe_version' ); |
|
| 332 | - update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
| 331 | + delete_option('wc_stripe_version'); |
|
| 332 | + update_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
@@ -339,8 +339,8 @@ discard block |
||
| 339 | 339 | * @version 3.1.0 |
| 340 | 340 | */ |
| 341 | 341 | public function install() { |
| 342 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
| 343 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
| 342 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
| 343 | + define('WC_STRIPE_INSTALLING', true); |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | $this->update_plugin_version(); |
@@ -352,13 +352,13 @@ discard block |
||
| 352 | 352 | * @since 1.0.0 |
| 353 | 353 | * @version 4.0.0 |
| 354 | 354 | */ |
| 355 | - public function plugin_action_links( $links ) { |
|
| 355 | + public function plugin_action_links($links) { |
|
| 356 | 356 | $plugin_links = array( |
| 357 | - '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
| 358 | - '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
| 359 | - '<a href="https://woocommerce.com/contact-us/">' . esc_html__( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
| 357 | + '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
| 358 | + '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
| 359 | + '<a href="https://woocommerce.com/contact-us/">' . esc_html__('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
| 360 | 360 | ); |
| 361 | - return array_merge( $plugin_links, $links ); |
|
| 361 | + return array_merge($plugin_links, $links); |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | /** |
@@ -367,8 +367,8 @@ discard block |
||
| 367 | 367 | * @since 1.0.0 |
| 368 | 368 | * @version 4.0.0 |
| 369 | 369 | */ |
| 370 | - public function add_gateways( $methods ) { |
|
| 371 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
| 370 | + public function add_gateways($methods) { |
|
| 371 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order') || class_exists('WC_Pre_Orders_Order')) { |
|
| 372 | 372 | $methods[] = 'WC_Stripe_Compat'; |
| 373 | 373 | $methods[] = 'WC_Stripe_Sepa_Compat'; |
| 374 | 374 | } else { |
@@ -393,26 +393,26 @@ discard block |
||
| 393 | 393 | * @since 4.0.0 |
| 394 | 394 | * @version 4.0.0 |
| 395 | 395 | */ |
| 396 | - public function filter_gateway_order_admin( $sections ) { |
|
| 397 | - unset( $sections['stripe'] ); |
|
| 398 | - unset( $sections['stripe_bancontact'] ); |
|
| 399 | - unset( $sections['stripe_sofort'] ); |
|
| 400 | - unset( $sections['stripe_giropay'] ); |
|
| 401 | - unset( $sections['stripe_ideal'] ); |
|
| 402 | - unset( $sections['stripe_p24'] ); |
|
| 403 | - unset( $sections['stripe_alipay'] ); |
|
| 404 | - unset( $sections['stripe_sepa'] ); |
|
| 405 | - unset( $sections['stripe_bitcoin'] ); |
|
| 396 | + public function filter_gateway_order_admin($sections) { |
|
| 397 | + unset($sections['stripe']); |
|
| 398 | + unset($sections['stripe_bancontact']); |
|
| 399 | + unset($sections['stripe_sofort']); |
|
| 400 | + unset($sections['stripe_giropay']); |
|
| 401 | + unset($sections['stripe_ideal']); |
|
| 402 | + unset($sections['stripe_p24']); |
|
| 403 | + unset($sections['stripe_alipay']); |
|
| 404 | + unset($sections['stripe_sepa']); |
|
| 405 | + unset($sections['stripe_bitcoin']); |
|
| 406 | 406 | |
| 407 | 407 | $sections['stripe'] = 'Stripe'; |
| 408 | - $sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
| 409 | - $sections['stripe_sofort'] = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
| 410 | - $sections['stripe_giropay'] = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
| 411 | - $sections['stripe_ideal'] = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
| 412 | - $sections['stripe_p24'] = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
| 413 | - $sections['stripe_alipay'] = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
| 414 | - $sections['stripe_sepa'] = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
| 415 | - $sections['stripe_bitcoin'] = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
| 408 | + $sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
| 409 | + $sections['stripe_sofort'] = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
| 410 | + $sections['stripe_giropay'] = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
| 411 | + $sections['stripe_ideal'] = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
| 412 | + $sections['stripe_p24'] = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
| 413 | + $sections['stripe_alipay'] = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
| 414 | + $sections['stripe_sepa'] = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
| 415 | + $sections['stripe_bitcoin'] = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
| 416 | 416 | |
| 417 | 417 | return $sections; |
| 418 | 418 | } |