@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -85,9 +85,9 @@ discard block |
||
| 85 | 85 | public function __construct() { |
| 86 | 86 | $this->retry_interval = 1; |
| 87 | 87 | $this->id = 'stripe'; |
| 88 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
| 88 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
| 89 | 89 | /* translators: 1) link to Stripe register page 2) link to Stripe api keys page */ |
| 90 | - $this->method_description = __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' ); |
|
| 90 | + $this->method_description = __('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe'); |
|
| 91 | 91 | $this->has_fields = true; |
| 92 | 92 | $this->supports = array( |
| 93 | 93 | 'products', |
@@ -114,40 +114,40 @@ discard block |
||
| 114 | 114 | $this->init_settings(); |
| 115 | 115 | |
| 116 | 116 | // Get setting values. |
| 117 | - $this->title = $this->get_option( 'title' ); |
|
| 118 | - $this->description = $this->get_option( 'description' ); |
|
| 119 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 120 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
| 121 | - $this->inline_cc_form = 'yes' === $this->get_option( 'inline_cc_form' ); |
|
| 122 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
| 123 | - $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) ); |
|
| 124 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
| 125 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
| 126 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
| 127 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
| 128 | - |
|
| 129 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
| 117 | + $this->title = $this->get_option('title'); |
|
| 118 | + $this->description = $this->get_option('description'); |
|
| 119 | + $this->enabled = $this->get_option('enabled'); |
|
| 120 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
| 121 | + $this->inline_cc_form = 'yes' === $this->get_option('inline_cc_form'); |
|
| 122 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
| 123 | + $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor')); |
|
| 124 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
| 125 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
| 126 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
| 127 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
| 128 | + |
|
| 129 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
| 130 | 130 | |
| 131 | 131 | // Hooks. |
| 132 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 133 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
| 134 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 135 | - add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_fee' ) ); |
|
| 136 | - add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_payout' ), 20 ); |
|
| 137 | - add_action( 'woocommerce_customer_save_address', array( $this, 'show_update_card_notice' ), 10, 2 ); |
|
| 138 | - add_filter( 'woocommerce_available_payment_gateways', array( $this, 'prepare_order_pay_page' ) ); |
|
| 139 | - add_action( 'woocommerce_account_view-order_endpoint', array( $this, 'check_intent_status_on_order_page' ), 1 ); |
|
| 140 | - add_filter( 'woocommerce_payment_successful_result', array( $this, 'modify_successful_payment_result' ), 99999, 2 ); |
|
| 141 | - add_action( 'set_logged_in_cookie', array( $this, 'set_cookie_on_current_request' ) ); |
|
| 142 | - add_filter( 'woocommerce_get_checkout_payment_url', array( $this, 'get_checkout_payment_url' ), 10, 2 ); |
|
| 132 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 133 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
| 134 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 135 | + add_action('woocommerce_admin_order_totals_after_total', array($this, 'display_order_fee')); |
|
| 136 | + add_action('woocommerce_admin_order_totals_after_total', array($this, 'display_order_payout'), 20); |
|
| 137 | + add_action('woocommerce_customer_save_address', array($this, 'show_update_card_notice'), 10, 2); |
|
| 138 | + add_filter('woocommerce_available_payment_gateways', array($this, 'prepare_order_pay_page')); |
|
| 139 | + add_action('woocommerce_account_view-order_endpoint', array($this, 'check_intent_status_on_order_page'), 1); |
|
| 140 | + add_filter('woocommerce_payment_successful_result', array($this, 'modify_successful_payment_result'), 99999, 2); |
|
| 141 | + add_action('set_logged_in_cookie', array($this, 'set_cookie_on_current_request')); |
|
| 142 | + add_filter('woocommerce_get_checkout_payment_url', array($this, 'get_checkout_payment_url'), 10, 2); |
|
| 143 | 143 | |
| 144 | 144 | // Note: display error is in the parent class. |
| 145 | - add_action( 'admin_notices', array( $this, 'display_errors' ), 9999 ); |
|
| 145 | + add_action('admin_notices', array($this, 'display_errors'), 9999); |
|
| 146 | 146 | |
| 147 | - if ( WC_Stripe_Helper::is_pre_orders_exists() ) { |
|
| 147 | + if (WC_Stripe_Helper::is_pre_orders_exists()) { |
|
| 148 | 148 | $this->pre_orders = new WC_Stripe_Pre_Orders_Compat(); |
| 149 | 149 | |
| 150 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this->pre_orders, 'process_pre_order_release_payment' ) ); |
|
| 150 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this->pre_orders, 'process_pre_order_release_payment')); |
|
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * @since 4.0.2 |
| 158 | 158 | */ |
| 159 | 159 | public function is_available() { |
| 160 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
| 160 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
| 161 | 161 | return false; |
| 162 | 162 | } |
| 163 | 163 | |
@@ -171,13 +171,13 @@ discard block |
||
| 171 | 171 | * @param int $user_id The ID of the current user. |
| 172 | 172 | * @param string $load_address The address to load. |
| 173 | 173 | */ |
| 174 | - public function show_update_card_notice( $user_id, $load_address ) { |
|
| 175 | - if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods( $user_id ) || 'billing' !== $load_address ) { |
|
| 174 | + public function show_update_card_notice($user_id, $load_address) { |
|
| 175 | + if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods($user_id) || 'billing' !== $load_address) { |
|
| 176 | 176 | return; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /* translators: 1) Opening anchor tag 2) closing anchor tag */ |
| 180 | - wc_add_notice( sprintf( __( 'If your billing address has been changed for saved payment methods, be sure to remove any %1$ssaved payment methods%2$s on file and re-add them.', 'woocommerce-gateway-stripe' ), '<a href="' . esc_url( wc_get_endpoint_url( 'payment-methods' ) ) . '" class="wc-stripe-update-card-notice" style="text-decoration:underline;">', '</a>' ), 'notice' ); |
|
| 180 | + wc_add_notice(sprintf(__('If your billing address has been changed for saved payment methods, be sure to remove any %1$ssaved payment methods%2$s on file and re-add them.', 'woocommerce-gateway-stripe'), '<a href="' . esc_url(wc_get_endpoint_url('payment-methods')) . '" class="wc-stripe-update-card-notice" style="text-decoration:underline;">', '</a>'), 'notice'); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -192,24 +192,24 @@ discard block |
||
| 192 | 192 | |
| 193 | 193 | $icons_str = ''; |
| 194 | 194 | |
| 195 | - $icons_str .= isset( $icons['visa'] ) ? $icons['visa'] : ''; |
|
| 196 | - $icons_str .= isset( $icons['amex'] ) ? $icons['amex'] : ''; |
|
| 197 | - $icons_str .= isset( $icons['mastercard'] ) ? $icons['mastercard'] : ''; |
|
| 195 | + $icons_str .= isset($icons['visa']) ? $icons['visa'] : ''; |
|
| 196 | + $icons_str .= isset($icons['amex']) ? $icons['amex'] : ''; |
|
| 197 | + $icons_str .= isset($icons['mastercard']) ? $icons['mastercard'] : ''; |
|
| 198 | 198 | |
| 199 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
| 200 | - $icons_str .= isset( $icons['discover'] ) ? $icons['discover'] : ''; |
|
| 201 | - $icons_str .= isset( $icons['jcb'] ) ? $icons['jcb'] : ''; |
|
| 202 | - $icons_str .= isset( $icons['diners'] ) ? $icons['diners'] : ''; |
|
| 199 | + if ('USD' === get_woocommerce_currency()) { |
|
| 200 | + $icons_str .= isset($icons['discover']) ? $icons['discover'] : ''; |
|
| 201 | + $icons_str .= isset($icons['jcb']) ? $icons['jcb'] : ''; |
|
| 202 | + $icons_str .= isset($icons['diners']) ? $icons['diners'] : ''; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 205 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
| 209 | 209 | * Initialise Gateway Settings Form Fields |
| 210 | 210 | */ |
| 211 | 211 | public function init_form_fields() { |
| 212 | - $this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' ); |
|
| 212 | + $this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php'); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -218,27 +218,27 @@ discard block |
||
| 218 | 218 | public function payment_fields() { |
| 219 | 219 | global $wp; |
| 220 | 220 | $user = wp_get_current_user(); |
| 221 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
| 221 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
| 222 | 222 | $total = WC()->cart->total; |
| 223 | 223 | $user_email = ''; |
| 224 | 224 | $description = $this->get_description(); |
| 225 | - $description = ! empty( $description ) ? $description : ''; |
|
| 225 | + $description = ! empty($description) ? $description : ''; |
|
| 226 | 226 | $firstname = ''; |
| 227 | 227 | $lastname = ''; |
| 228 | 228 | |
| 229 | 229 | // If paying from order, we need to get total from order not cart. |
| 230 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { // wpcs: csrf ok. |
|
| 231 | - $order = wc_get_order( wc_clean( $wp->query_vars['order-pay'] ) ); // wpcs: csrf ok, sanitization ok. |
|
| 230 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { // wpcs: csrf ok. |
|
| 231 | + $order = wc_get_order(wc_clean($wp->query_vars['order-pay'])); // wpcs: csrf ok, sanitization ok. |
|
| 232 | 232 | $total = $order->get_total(); |
| 233 | 233 | $user_email = $order->get_billing_email(); |
| 234 | 234 | } else { |
| 235 | - if ( $user->ID ) { |
|
| 236 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
| 235 | + if ($user->ID) { |
|
| 236 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
| 237 | 237 | $user_email = $user_email ? $user_email : $user->user_email; |
| 238 | 238 | } |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - if ( is_add_payment_method_page() ) { |
|
| 241 | + if (is_add_payment_method_page()) { |
|
| 242 | 242 | $firstname = $user->user_firstname; |
| 243 | 243 | $lastname = $user->user_lastname; |
| 244 | 244 | } |
@@ -247,33 +247,33 @@ discard block |
||
| 247 | 247 | |
| 248 | 248 | echo '<div |
| 249 | 249 | id="stripe-payment-data" |
| 250 | - data-email="' . esc_attr( $user_email ) . '" |
|
| 251 | - data-full-name="' . esc_attr( $firstname . ' ' . $lastname ) . '" |
|
| 252 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
| 250 | + data-email="' . esc_attr($user_email) . '" |
|
| 251 | + data-full-name="' . esc_attr($firstname . ' ' . $lastname) . '" |
|
| 252 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
| 253 | 253 | >'; |
| 254 | 254 | |
| 255 | - if ( $this->testmode ) { |
|
| 255 | + if ($this->testmode) { |
|
| 256 | 256 | /* translators: link to Stripe testing page */ |
| 257 | - $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 <a href="%s" target="_blank">Testing Stripe documentation</a> for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
| 257 | + $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 <a href="%s" target="_blank">Testing Stripe documentation</a> for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - $description = trim( $description ); |
|
| 260 | + $description = trim($description); |
|
| 261 | 261 | |
| 262 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); // wpcs: xss ok. |
|
| 262 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); // wpcs: xss ok. |
|
| 263 | 263 | |
| 264 | - if ( $display_tokenization ) { |
|
| 264 | + if ($display_tokenization) { |
|
| 265 | 265 | $this->tokenization_script(); |
| 266 | 266 | $this->saved_payment_methods(); |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | $this->elements_form(); |
| 270 | 270 | |
| 271 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { // wpcs: csrf ok. |
|
| 271 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { // wpcs: csrf ok. |
|
| 272 | 272 | |
| 273 | 273 | $this->save_payment_method_checkbox(); |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - do_action( 'wc_stripe_cards_payment_fields', $this->id ); |
|
| 276 | + do_action('wc_stripe_cards_payment_fields', $this->id); |
|
| 277 | 277 | |
| 278 | 278 | echo '</div>'; |
| 279 | 279 | |
@@ -288,12 +288,12 @@ discard block |
||
| 288 | 288 | */ |
| 289 | 289 | public function elements_form() { |
| 290 | 290 | ?> |
| 291 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
| 292 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
| 291 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
| 292 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
| 293 | 293 | |
| 294 | - <?php if ( $this->inline_cc_form ) { ?> |
|
| 294 | + <?php if ($this->inline_cc_form) { ?> |
|
| 295 | 295 | <label for="card-element"> |
| 296 | - <?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?> |
|
| 296 | + <?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?> |
|
| 297 | 297 | </label> |
| 298 | 298 | |
| 299 | 299 | <div id="stripe-card-element" class="wc-stripe-elements-field"> |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | </div> |
| 302 | 302 | <?php } else { ?> |
| 303 | 303 | <div class="form-row form-row-wide"> |
| 304 | - <label for="stripe-card-element"><?php esc_html_e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
| 304 | + <label for="stripe-card-element"><?php esc_html_e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
| 305 | 305 | <div class="stripe-card-group"> |
| 306 | 306 | <div id="stripe-card-element" class="wc-stripe-elements-field"> |
| 307 | 307 | <!-- a Stripe Element will be inserted here. --> |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | </div> |
| 313 | 313 | |
| 314 | 314 | <div class="form-row form-row-first"> |
| 315 | - <label for="stripe-exp-element"><?php esc_html_e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
| 315 | + <label for="stripe-exp-element"><?php esc_html_e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
| 316 | 316 | |
| 317 | 317 | <div id="stripe-exp-element" class="wc-stripe-elements-field"> |
| 318 | 318 | <!-- a Stripe Element will be inserted here. --> |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | </div> |
| 321 | 321 | |
| 322 | 322 | <div class="form-row form-row-last"> |
| 323 | - <label for="stripe-cvc-element"><?php esc_html_e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
| 323 | + <label for="stripe-cvc-element"><?php esc_html_e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
| 324 | 324 | <div id="stripe-cvc-element" class="wc-stripe-elements-field"> |
| 325 | 325 | <!-- a Stripe Element will be inserted here. --> |
| 326 | 326 | </div> |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | <!-- Used to display form errors --> |
| 332 | 332 | <div class="stripe-source-errors" role="alert"></div> |
| 333 | 333 | <br /> |
| 334 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
| 334 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
| 335 | 335 | <div class="clear"></div> |
| 336 | 336 | </fieldset> |
| 337 | 337 | <?php |
@@ -344,13 +344,13 @@ discard block |
||
| 344 | 344 | * @version 3.1.0 |
| 345 | 345 | */ |
| 346 | 346 | public function admin_scripts() { |
| 347 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
| 347 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
| 348 | 348 | return; |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 351 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 352 | 352 | |
| 353 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
| 353 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
@@ -367,54 +367,54 @@ discard block |
||
| 367 | 367 | ! is_product() |
| 368 | 368 | && ! is_cart() |
| 369 | 369 | && ! is_checkout() |
| 370 | - && ! isset( $_GET['pay_for_order'] ) // wpcs: csrf ok. |
|
| 370 | + && ! isset($_GET['pay_for_order']) // wpcs: csrf ok. |
|
| 371 | 371 | && ! is_add_payment_method_page() |
| 372 | - && ! isset( $_GET['change_payment_method'] ) // wpcs: csrf ok. |
|
| 373 | - && ! ( ! empty( get_query_var( 'view-subscription' ) ) && is_callable( 'WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled' ) && WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled() ) |
|
| 374 | - || ( is_order_received_page() ) |
|
| 372 | + && ! isset($_GET['change_payment_method']) // wpcs: csrf ok. |
|
| 373 | + && ! ( ! empty(get_query_var('view-subscription')) && is_callable('WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled') && WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled()) |
|
| 374 | + || (is_order_received_page()) |
|
| 375 | 375 | ) { |
| 376 | 376 | return; |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | // If Stripe is not enabled bail. |
| 380 | - if ( 'no' === $this->enabled ) { |
|
| 380 | + if ('no' === $this->enabled) { |
|
| 381 | 381 | return; |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | // If keys are not set bail. |
| 385 | - if ( ! $this->are_keys_set() ) { |
|
| 386 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
| 385 | + if ( ! $this->are_keys_set()) { |
|
| 386 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
| 387 | 387 | return; |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | // If no SSL bail. |
| 391 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
| 392 | - WC_Stripe_Logger::log( 'Stripe live mode requires SSL.' ); |
|
| 391 | + if ( ! $this->testmode && ! is_ssl()) { |
|
| 392 | + WC_Stripe_Logger::log('Stripe live mode requires SSL.'); |
|
| 393 | 393 | return; |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | $current_theme = wp_get_theme(); |
| 397 | 397 | |
| 398 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 398 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 399 | 399 | |
| 400 | - wp_register_style( 'stripe_styles', plugins_url( 'assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
| 401 | - wp_enqueue_style( 'stripe_styles' ); |
|
| 400 | + wp_register_style('stripe_styles', plugins_url('assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
| 401 | + wp_enqueue_style('stripe_styles'); |
|
| 402 | 402 | |
| 403 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
| 404 | - wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 403 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
| 404 | + wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true); |
|
| 405 | 405 | |
| 406 | 406 | $stripe_params = array( |
| 407 | 407 | 'key' => $this->publishable_key, |
| 408 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
| 409 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
| 408 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
| 409 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
| 410 | 410 | ); |
| 411 | 411 | |
| 412 | 412 | // If we're on the pay page we need to pass stripe.js the address of the order. |
| 413 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { // wpcs: csrf ok. |
|
| 414 | - $order_id = wc_clean( $wp->query_vars['order-pay'] ); // wpcs: csrf ok, sanitization ok, xss ok. |
|
| 415 | - $order = wc_get_order( $order_id ); |
|
| 413 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { // wpcs: csrf ok. |
|
| 414 | + $order_id = wc_clean($wp->query_vars['order-pay']); // wpcs: csrf ok, sanitization ok, xss ok. |
|
| 415 | + $order = wc_get_order($order_id); |
|
| 416 | 416 | |
| 417 | - if ( is_a( $order, 'WC_Order' ) ) { |
|
| 417 | + if (is_a($order, 'WC_Order')) { |
|
| 418 | 418 | $stripe_params['billing_first_name'] = $order->get_billing_first_name(); |
| 419 | 419 | $stripe_params['billing_last_name'] = $order->get_billing_last_name(); |
| 420 | 420 | $stripe_params['billing_address_1'] = $order->get_billing_address_1(); |
@@ -429,41 +429,41 @@ discard block |
||
| 429 | 429 | $sepa_elements_options = apply_filters( |
| 430 | 430 | 'wc_stripe_sepa_elements_options', |
| 431 | 431 | array( |
| 432 | - 'supportedCountries' => array( 'SEPA' ), |
|
| 432 | + 'supportedCountries' => array('SEPA'), |
|
| 433 | 433 | 'placeholderCountry' => WC()->countries->get_base_country(), |
| 434 | - 'style' => array( 'base' => array( 'fontSize' => '15px' ) ), |
|
| 434 | + 'style' => array('base' => array('fontSize' => '15px')), |
|
| 435 | 435 | ) |
| 436 | 436 | ); |
| 437 | 437 | |
| 438 | - $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
| 439 | - $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
| 440 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
| 441 | - $stripe_params['payment_intent_error'] = __( 'We couldn\'t initiate the payment. Please try again.', 'woocommerce-gateway-stripe' ); |
|
| 442 | - $stripe_params['sepa_mandate_notification'] = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' ); |
|
| 443 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
| 438 | + $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
| 439 | + $stripe_params['no_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
| 440 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
| 441 | + $stripe_params['payment_intent_error'] = __('We couldn\'t initiate the payment. Please try again.', 'woocommerce-gateway-stripe'); |
|
| 442 | + $stripe_params['sepa_mandate_notification'] = apply_filters('wc_stripe_sepa_mandate_notification', 'email'); |
|
| 443 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
| 444 | 444 | $stripe_params['inline_cc_form'] = $this->inline_cc_form ? 'yes' : 'no'; |
| 445 | - $stripe_params['is_checkout'] = ( is_checkout() && empty( $_GET['pay_for_order'] ) ) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
| 445 | + $stripe_params['is_checkout'] = (is_checkout() && empty($_GET['pay_for_order'])) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
| 446 | 446 | $stripe_params['return_url'] = $this->get_stripe_return_url(); |
| 447 | - $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); |
|
| 448 | - $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); |
|
| 447 | + $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint('%%endpoint%%'); |
|
| 448 | + $stripe_params['stripe_nonce'] = wp_create_nonce('_wc_stripe_nonce'); |
|
| 449 | 449 | $stripe_params['statement_descriptor'] = $this->statement_descriptor; |
| 450 | - $stripe_params['elements_options'] = apply_filters( 'wc_stripe_elements_options', array() ); |
|
| 450 | + $stripe_params['elements_options'] = apply_filters('wc_stripe_elements_options', array()); |
|
| 451 | 451 | $stripe_params['sepa_elements_options'] = $sepa_elements_options; |
| 452 | - $stripe_params['invalid_owner_name'] = __( 'Billing First Name and Last Name are required.', 'woocommerce-gateway-stripe' ); |
|
| 453 | - $stripe_params['is_change_payment_page'] = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
| 454 | - $stripe_params['is_add_payment_page'] = is_wc_endpoint_url( 'add-payment-method' ) ? 'yes' : 'no'; |
|
| 455 | - $stripe_params['is_pay_for_order_page'] = is_wc_endpoint_url( 'order-pay' ) ? 'yes' : 'no'; |
|
| 456 | - $stripe_params['elements_styling'] = apply_filters( 'wc_stripe_elements_styling', false ); |
|
| 457 | - $stripe_params['elements_classes'] = apply_filters( 'wc_stripe_elements_classes', false ); |
|
| 458 | - $stripe_params['add_card_nonce'] = wp_create_nonce( 'wc_stripe_create_si' ); |
|
| 452 | + $stripe_params['invalid_owner_name'] = __('Billing First Name and Last Name are required.', 'woocommerce-gateway-stripe'); |
|
| 453 | + $stripe_params['is_change_payment_page'] = isset($_GET['change_payment_method']) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
| 454 | + $stripe_params['is_add_payment_page'] = is_wc_endpoint_url('add-payment-method') ? 'yes' : 'no'; |
|
| 455 | + $stripe_params['is_pay_for_order_page'] = is_wc_endpoint_url('order-pay') ? 'yes' : 'no'; |
|
| 456 | + $stripe_params['elements_styling'] = apply_filters('wc_stripe_elements_styling', false); |
|
| 457 | + $stripe_params['elements_classes'] = apply_filters('wc_stripe_elements_classes', false); |
|
| 458 | + $stripe_params['add_card_nonce'] = wp_create_nonce('wc_stripe_create_si'); |
|
| 459 | 459 | |
| 460 | 460 | // Merge localized messages to be use in JS. |
| 461 | - $stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() ); |
|
| 461 | + $stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages()); |
|
| 462 | 462 | |
| 463 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
| 463 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
| 464 | 464 | |
| 465 | 465 | $this->tokenization_script(); |
| 466 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 466 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | /** |
@@ -474,14 +474,14 @@ discard block |
||
| 474 | 474 | * @param object $prepared_source The object with source details. |
| 475 | 475 | * @throws WC_Stripe_Exception An exception if the card is prepaid, but prepaid cards are not allowed. |
| 476 | 476 | */ |
| 477 | - public function maybe_disallow_prepaid_card( $prepared_source ) { |
|
| 477 | + public function maybe_disallow_prepaid_card($prepared_source) { |
|
| 478 | 478 | // Check if we don't allow prepaid credit cards. |
| 479 | - if ( apply_filters( 'wc_stripe_allow_prepaid_card', true ) || ! $this->is_prepaid_card( $prepared_source->source_object ) ) { |
|
| 479 | + if (apply_filters('wc_stripe_allow_prepaid_card', true) || ! $this->is_prepaid_card($prepared_source->source_object)) { |
|
| 480 | 480 | return; |
| 481 | 481 | } |
| 482 | 482 | |
| 483 | - $localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
| 484 | - throw new WC_Stripe_Exception( print_r( $prepared_source->source_object, true ), $localized_message ); |
|
| 483 | + $localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charged. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
| 484 | + throw new WC_Stripe_Exception(print_r($prepared_source->source_object, true), $localized_message); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | /** |
@@ -491,10 +491,10 @@ discard block |
||
| 491 | 491 | * @param object $prepared_source The source that should be verified. |
| 492 | 492 | * @throws WC_Stripe_Exception An exception if the source ID is missing. |
| 493 | 493 | */ |
| 494 | - public function check_source( $prepared_source ) { |
|
| 495 | - if ( empty( $prepared_source->source ) ) { |
|
| 496 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
| 497 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
| 494 | + public function check_source($prepared_source) { |
|
| 495 | + if (empty($prepared_source->source)) { |
|
| 496 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
| 497 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
| 498 | 498 | } |
| 499 | 499 | } |
| 500 | 500 | |
@@ -506,13 +506,13 @@ discard block |
||
| 506 | 506 | * @param WC_Order $order The order those payment is being processed. |
| 507 | 507 | * @return bool A flag that indicates that the customer does not exist and should be removed. |
| 508 | 508 | */ |
| 509 | - public function maybe_remove_non_existent_customer( $error, $order ) { |
|
| 510 | - if ( ! $this->is_no_such_customer_error( $error ) ) { |
|
| 509 | + public function maybe_remove_non_existent_customer($error, $order) { |
|
| 510 | + if ( ! $this->is_no_such_customer_error($error)) { |
|
| 511 | 511 | return false; |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | - delete_user_option( $order->get_customer_id(), '_stripe_customer_id' ); |
|
| 515 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
| 514 | + delete_user_option($order->get_customer_id(), '_stripe_customer_id'); |
|
| 515 | + $order->delete_meta_data('_stripe_customer_id'); |
|
| 516 | 516 | $order->save(); |
| 517 | 517 | |
| 518 | 518 | return true; |
@@ -527,15 +527,15 @@ discard block |
||
| 527 | 527 | * @param boolean $force_save_source Whether the payment source must be saved, like when dealing with a Subscription setup. |
| 528 | 528 | * @return array Redirection data for `process_payment`. |
| 529 | 529 | */ |
| 530 | - public function complete_free_order( $order, $prepared_source, $force_save_source ) { |
|
| 531 | - if ( $force_save_source ) { |
|
| 532 | - $intent_secret = $this->setup_intent( $order, $prepared_source ); |
|
| 530 | + public function complete_free_order($order, $prepared_source, $force_save_source) { |
|
| 531 | + if ($force_save_source) { |
|
| 532 | + $intent_secret = $this->setup_intent($order, $prepared_source); |
|
| 533 | 533 | |
| 534 | - if ( ! empty( $intent_secret ) ) { |
|
| 534 | + if ( ! empty($intent_secret)) { |
|
| 535 | 535 | // `get_return_url()` must be called immediately before returning a value. |
| 536 | 536 | return array( |
| 537 | 537 | 'result' => 'success', |
| 538 | - 'redirect' => $this->get_return_url( $order ), |
|
| 538 | + 'redirect' => $this->get_return_url($order), |
|
| 539 | 539 | 'setup_intent_secret' => $intent_secret, |
| 540 | 540 | ); |
| 541 | 541 | } |
@@ -549,7 +549,7 @@ discard block |
||
| 549 | 549 | // Return thank you page redirect. |
| 550 | 550 | return array( |
| 551 | 551 | 'result' => 'success', |
| 552 | - 'redirect' => $this->get_return_url( $order ), |
|
| 552 | + 'redirect' => $this->get_return_url($order), |
|
| 553 | 553 | ); |
| 554 | 554 | } |
| 555 | 555 | |
@@ -567,81 +567,81 @@ discard block |
||
| 567 | 567 | * @throws Exception If payment will not be accepted. |
| 568 | 568 | * @return array|void |
| 569 | 569 | */ |
| 570 | - public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false, $use_order_source = false ) { |
|
| 570 | + public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false, $use_order_source = false) { |
|
| 571 | 571 | try { |
| 572 | - $order = wc_get_order( $order_id ); |
|
| 572 | + $order = wc_get_order($order_id); |
|
| 573 | 573 | |
| 574 | 574 | // ToDo: `process_pre_order` saves the source to the order for a later payment. |
| 575 | 575 | // This might not work well with PaymentIntents. |
| 576 | - if ( $this->maybe_process_pre_orders( $order_id ) ) { |
|
| 577 | - return $this->pre_orders->process_pre_order( $order_id ); |
|
| 576 | + if ($this->maybe_process_pre_orders($order_id)) { |
|
| 577 | + return $this->pre_orders->process_pre_order($order_id); |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | // Check whether there is an existing intent. |
| 581 | - $intent = $this->get_intent_from_order( $order ); |
|
| 582 | - if ( isset( $intent->object ) && 'setup_intent' === $intent->object ) { |
|
| 581 | + $intent = $this->get_intent_from_order($order); |
|
| 582 | + if (isset($intent->object) && 'setup_intent' === $intent->object) { |
|
| 583 | 583 | $intent = false; // This function can only deal with *payment* intents |
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | $stripe_customer_id = null; |
| 587 | - if ( $intent && ! empty( $intent->customer ) ) { |
|
| 587 | + if ($intent && ! empty($intent->customer)) { |
|
| 588 | 588 | $stripe_customer_id = $intent->customer; |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | // For some payments the source should already be present in the order. |
| 592 | - if ( $use_order_source ) { |
|
| 593 | - $prepared_source = $this->prepare_order_source( $order ); |
|
| 592 | + if ($use_order_source) { |
|
| 593 | + $prepared_source = $this->prepare_order_source($order); |
|
| 594 | 594 | } else { |
| 595 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source, $stripe_customer_id ); |
|
| 595 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source, $stripe_customer_id); |
|
| 596 | 596 | } |
| 597 | 597 | |
| 598 | - $this->maybe_disallow_prepaid_card( $prepared_source ); |
|
| 599 | - $this->check_source( $prepared_source ); |
|
| 600 | - $this->save_source_to_order( $order, $prepared_source ); |
|
| 598 | + $this->maybe_disallow_prepaid_card($prepared_source); |
|
| 599 | + $this->check_source($prepared_source); |
|
| 600 | + $this->save_source_to_order($order, $prepared_source); |
|
| 601 | 601 | |
| 602 | - if ( 0 >= $order->get_total() ) { |
|
| 603 | - return $this->complete_free_order( $order, $prepared_source, $force_save_source ); |
|
| 602 | + if (0 >= $order->get_total()) { |
|
| 603 | + return $this->complete_free_order($order, $prepared_source, $force_save_source); |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | // This will throw exception if not valid. |
| 607 | - $this->validate_minimum_order_amount( $order ); |
|
| 607 | + $this->validate_minimum_order_amount($order); |
|
| 608 | 608 | |
| 609 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
| 609 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
| 610 | 610 | |
| 611 | - if ( $intent ) { |
|
| 612 | - $intent = $this->update_existing_intent( $intent, $order, $prepared_source ); |
|
| 611 | + if ($intent) { |
|
| 612 | + $intent = $this->update_existing_intent($intent, $order, $prepared_source); |
|
| 613 | 613 | } else { |
| 614 | - $intent = $this->create_intent( $order, $prepared_source ); |
|
| 614 | + $intent = $this->create_intent($order, $prepared_source); |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | // Confirm the intent after locking the order to make sure webhooks will not interfere. |
| 618 | - if ( empty( $intent->error ) ) { |
|
| 619 | - $this->lock_order_payment( $order, $intent ); |
|
| 620 | - $intent = $this->confirm_intent( $intent, $order, $prepared_source ); |
|
| 618 | + if (empty($intent->error)) { |
|
| 619 | + $this->lock_order_payment($order, $intent); |
|
| 620 | + $intent = $this->confirm_intent($intent, $order, $prepared_source); |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - if ( ! empty( $intent->error ) ) { |
|
| 624 | - $this->maybe_remove_non_existent_customer( $intent->error, $order ); |
|
| 623 | + if ( ! empty($intent->error)) { |
|
| 624 | + $this->maybe_remove_non_existent_customer($intent->error, $order); |
|
| 625 | 625 | |
| 626 | 626 | // We want to retry. |
| 627 | - if ( $this->is_retryable_error( $intent->error ) ) { |
|
| 628 | - return $this->retry_after_error( $intent, $order, $retry, $force_save_source, $previous_error, $use_order_source ); |
|
| 627 | + if ($this->is_retryable_error($intent->error)) { |
|
| 628 | + return $this->retry_after_error($intent, $order, $retry, $force_save_source, $previous_error, $use_order_source); |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | - $this->unlock_order_payment( $order ); |
|
| 632 | - $this->throw_localized_message( $intent, $order ); |
|
| 631 | + $this->unlock_order_payment($order); |
|
| 632 | + $this->throw_localized_message($intent, $order); |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | - if ( ! empty( $intent ) ) { |
|
| 635 | + if ( ! empty($intent)) { |
|
| 636 | 636 | // Use the last charge within the intent to proceed. |
| 637 | - $response = end( $intent->charges->data ); |
|
| 637 | + $response = end($intent->charges->data); |
|
| 638 | 638 | |
| 639 | 639 | // If the intent requires a 3DS flow, redirect to it. |
| 640 | - if ( 'requires_action' === $intent->status ) { |
|
| 641 | - $this->unlock_order_payment( $order ); |
|
| 640 | + if ('requires_action' === $intent->status) { |
|
| 641 | + $this->unlock_order_payment($order); |
|
| 642 | 642 | |
| 643 | - if ( is_wc_endpoint_url( 'order-pay' ) ) { |
|
| 644 | - $redirect_url = add_query_arg( 'wc-stripe-confirmation', 1, $order->get_checkout_payment_url( false ) ); |
|
| 643 | + if (is_wc_endpoint_url('order-pay')) { |
|
| 644 | + $redirect_url = add_query_arg('wc-stripe-confirmation', 1, $order->get_checkout_payment_url(false)); |
|
| 645 | 645 | |
| 646 | 646 | return array( |
| 647 | 647 | 'result' => 'success', |
@@ -656,7 +656,7 @@ discard block |
||
| 656 | 656 | |
| 657 | 657 | return array( |
| 658 | 658 | 'result' => 'success', |
| 659 | - 'redirect' => $this->get_return_url( $order ), |
|
| 659 | + 'redirect' => $this->get_return_url($order), |
|
| 660 | 660 | 'payment_intent_secret' => $intent->client_secret, |
| 661 | 661 | ); |
| 662 | 662 | } |
@@ -664,30 +664,30 @@ discard block |
||
| 664 | 664 | } |
| 665 | 665 | |
| 666 | 666 | // Process valid response. |
| 667 | - $this->process_response( $response, $order ); |
|
| 667 | + $this->process_response($response, $order); |
|
| 668 | 668 | |
| 669 | 669 | // Remove cart. |
| 670 | - if ( isset( WC()->cart ) ) { |
|
| 670 | + if (isset(WC()->cart)) { |
|
| 671 | 671 | WC()->cart->empty_cart(); |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | // Unlock the order. |
| 675 | - $this->unlock_order_payment( $order ); |
|
| 675 | + $this->unlock_order_payment($order); |
|
| 676 | 676 | |
| 677 | 677 | // Return thank you page redirect. |
| 678 | 678 | return array( |
| 679 | 679 | 'result' => 'success', |
| 680 | - 'redirect' => $this->get_return_url( $order ), |
|
| 680 | + 'redirect' => $this->get_return_url($order), |
|
| 681 | 681 | ); |
| 682 | 682 | |
| 683 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 684 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 685 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 683 | + } catch (WC_Stripe_Exception $e) { |
|
| 684 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 685 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 686 | 686 | |
| 687 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 687 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 688 | 688 | |
| 689 | 689 | /* translators: error message */ |
| 690 | - $order->update_status( 'failed' ); |
|
| 690 | + $order->update_status('failed'); |
|
| 691 | 691 | |
| 692 | 692 | return array( |
| 693 | 693 | 'result' => 'fail', |
@@ -703,17 +703,17 @@ discard block |
||
| 703 | 703 | * |
| 704 | 704 | * @param int $order_id The ID of the order. |
| 705 | 705 | */ |
| 706 | - public function display_order_fee( $order_id ) { |
|
| 707 | - if ( apply_filters( 'wc_stripe_hide_display_order_fee', false, $order_id ) ) { |
|
| 706 | + public function display_order_fee($order_id) { |
|
| 707 | + if (apply_filters('wc_stripe_hide_display_order_fee', false, $order_id)) { |
|
| 708 | 708 | return; |
| 709 | 709 | } |
| 710 | 710 | |
| 711 | - $order = wc_get_order( $order_id ); |
|
| 711 | + $order = wc_get_order($order_id); |
|
| 712 | 712 | |
| 713 | - $fee = WC_Stripe_Helper::get_stripe_fee( $order ); |
|
| 714 | - $currency = WC_Stripe_Helper::get_stripe_currency( $order ); |
|
| 713 | + $fee = WC_Stripe_Helper::get_stripe_fee($order); |
|
| 714 | + $currency = WC_Stripe_Helper::get_stripe_currency($order); |
|
| 715 | 715 | |
| 716 | - if ( ! $fee || ! $currency ) { |
|
| 716 | + if ( ! $fee || ! $currency) { |
|
| 717 | 717 | return; |
| 718 | 718 | } |
| 719 | 719 | |
@@ -721,12 +721,12 @@ discard block |
||
| 721 | 721 | |
| 722 | 722 | <tr> |
| 723 | 723 | <td class="label stripe-fee"> |
| 724 | - <?php echo wc_help_tip( __( 'This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe' ) ); // wpcs: xss ok. ?> |
|
| 725 | - <?php esc_html_e( 'Stripe Fee:', 'woocommerce-gateway-stripe' ); ?> |
|
| 724 | + <?php echo wc_help_tip(__('This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe')); // wpcs: xss ok. ?> |
|
| 725 | + <?php esc_html_e('Stripe Fee:', 'woocommerce-gateway-stripe'); ?> |
|
| 726 | 726 | </td> |
| 727 | 727 | <td width="1%"></td> |
| 728 | 728 | <td class="total"> |
| 729 | - - <?php echo wc_price( $fee, array( 'currency' => $currency ) ); // wpcs: xss ok. ?> |
|
| 729 | + - <?php echo wc_price($fee, array('currency' => $currency)); // wpcs: xss ok. ?> |
|
| 730 | 730 | </td> |
| 731 | 731 | </tr> |
| 732 | 732 | |
@@ -740,17 +740,17 @@ discard block |
||
| 740 | 740 | * |
| 741 | 741 | * @param int $order_id The ID of the order. |
| 742 | 742 | */ |
| 743 | - public function display_order_payout( $order_id ) { |
|
| 744 | - if ( apply_filters( 'wc_stripe_hide_display_order_payout', false, $order_id ) ) { |
|
| 743 | + public function display_order_payout($order_id) { |
|
| 744 | + if (apply_filters('wc_stripe_hide_display_order_payout', false, $order_id)) { |
|
| 745 | 745 | return; |
| 746 | 746 | } |
| 747 | 747 | |
| 748 | - $order = wc_get_order( $order_id ); |
|
| 748 | + $order = wc_get_order($order_id); |
|
| 749 | 749 | |
| 750 | - $net = WC_Stripe_Helper::get_stripe_net( $order ); |
|
| 751 | - $currency = WC_Stripe_Helper::get_stripe_currency( $order ); |
|
| 750 | + $net = WC_Stripe_Helper::get_stripe_net($order); |
|
| 751 | + $currency = WC_Stripe_Helper::get_stripe_currency($order); |
|
| 752 | 752 | |
| 753 | - if ( ! $net || ! $currency ) { |
|
| 753 | + if ( ! $net || ! $currency) { |
|
| 754 | 754 | return; |
| 755 | 755 | } |
| 756 | 756 | |
@@ -758,12 +758,12 @@ discard block |
||
| 758 | 758 | |
| 759 | 759 | <tr> |
| 760 | 760 | <td class="label stripe-payout"> |
| 761 | - <?php echo wc_help_tip( __( 'This represents the net total that will be credited to your Stripe bank account. This may be in the currency that is set in your Stripe account.', 'woocommerce-gateway-stripe' ) ); // wpcs: xss ok. ?> |
|
| 762 | - <?php esc_html_e( 'Stripe Payout:', 'woocommerce-gateway-stripe' ); ?> |
|
| 761 | + <?php echo wc_help_tip(__('This represents the net total that will be credited to your Stripe bank account. This may be in the currency that is set in your Stripe account.', 'woocommerce-gateway-stripe')); // wpcs: xss ok. ?> |
|
| 762 | + <?php esc_html_e('Stripe Payout:', 'woocommerce-gateway-stripe'); ?> |
|
| 763 | 763 | </td> |
| 764 | 764 | <td width="1%"></td> |
| 765 | 765 | <td class="total"> |
| 766 | - <?php echo wc_price( $net, array( 'currency' => $currency ) ); // wpcs: xss ok. ?> |
|
| 766 | + <?php echo wc_price($net, array('currency' => $currency)); // wpcs: xss ok. ?> |
|
| 767 | 767 | </td> |
| 768 | 768 | </tr> |
| 769 | 769 | |
@@ -779,13 +779,13 @@ discard block |
||
| 779 | 779 | * |
| 780 | 780 | * @return string The localized error message. |
| 781 | 781 | */ |
| 782 | - public function get_localized_error_message_from_response( $response ) { |
|
| 782 | + public function get_localized_error_message_from_response($response) { |
|
| 783 | 783 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
| 784 | 784 | |
| 785 | - if ( 'card_error' === $response->error->type ) { |
|
| 786 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 785 | + if ('card_error' === $response->error->type) { |
|
| 786 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
| 787 | 787 | } else { |
| 788 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 788 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | 791 | return $localized_message; |
@@ -799,12 +799,12 @@ discard block |
||
| 799 | 799 | * @param WC_Order $order The order to add a note to. |
| 800 | 800 | * @throws WC_Stripe_Exception An exception with the right message. |
| 801 | 801 | */ |
| 802 | - public function throw_localized_message( $response, $order ) { |
|
| 803 | - $localized_message = $this->get_localized_error_message_from_response( $response ); |
|
| 802 | + public function throw_localized_message($response, $order) { |
|
| 803 | + $localized_message = $this->get_localized_error_message_from_response($response); |
|
| 804 | 804 | |
| 805 | - $order->add_order_note( $localized_message ); |
|
| 805 | + $order->add_order_note($localized_message); |
|
| 806 | 806 | |
| 807 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 807 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | /** |
@@ -820,22 +820,22 @@ discard block |
||
| 820 | 820 | * @throws WC_Stripe_Exception If the payment is not accepted. |
| 821 | 821 | * @return array|void |
| 822 | 822 | */ |
| 823 | - public function retry_after_error( $response, $order, $retry, $force_save_source, $previous_error, $use_order_source ) { |
|
| 824 | - if ( ! $retry ) { |
|
| 825 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
| 826 | - $order->add_order_note( $localized_message ); |
|
| 827 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions. |
|
| 823 | + public function retry_after_error($response, $order, $retry, $force_save_source, $previous_error, $use_order_source) { |
|
| 824 | + if ( ! $retry) { |
|
| 825 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
| 826 | + $order->add_order_note($localized_message); |
|
| 827 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); // phpcs:ignore WordPress.PHP.DevelopmentFunctions. |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | // Don't do anymore retries after this. |
| 831 | - if ( 5 <= $this->retry_interval ) { |
|
| 832 | - return $this->process_payment( $order->get_id(), false, $force_save_source, $response->error, $previous_error ); |
|
| 831 | + if (5 <= $this->retry_interval) { |
|
| 832 | + return $this->process_payment($order->get_id(), false, $force_save_source, $response->error, $previous_error); |
|
| 833 | 833 | } |
| 834 | 834 | |
| 835 | - sleep( $this->retry_interval ); |
|
| 835 | + sleep($this->retry_interval); |
|
| 836 | 836 | $this->retry_interval++; |
| 837 | 837 | |
| 838 | - return $this->process_payment( $order->get_id(), true, $force_save_source, $response->error, $previous_error, $use_order_source ); |
|
| 838 | + return $this->process_payment($order->get_id(), true, $force_save_source, $response->error, $previous_error, $use_order_source); |
|
| 839 | 839 | } |
| 840 | 840 | |
| 841 | 841 | /** |
@@ -846,23 +846,23 @@ discard block |
||
| 846 | 846 | * @param WC_Payment_Gateway[] $gateways A list of all available gateways. |
| 847 | 847 | * @return WC_Payment_Gateway[] Either the same list or an empty one in the right conditions. |
| 848 | 848 | */ |
| 849 | - public function prepare_order_pay_page( $gateways ) { |
|
| 850 | - if ( ! is_wc_endpoint_url( 'order-pay' ) || ! isset( $_GET['wc-stripe-confirmation'] ) ) { // wpcs: csrf ok. |
|
| 849 | + public function prepare_order_pay_page($gateways) { |
|
| 850 | + if ( ! is_wc_endpoint_url('order-pay') || ! isset($_GET['wc-stripe-confirmation'])) { // wpcs: csrf ok. |
|
| 851 | 851 | return $gateways; |
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | try { |
| 855 | 855 | $this->prepare_intent_for_order_pay_page(); |
| 856 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 856 | + } catch (WC_Stripe_Exception $e) { |
|
| 857 | 857 | // Just show the full order pay page if there was a problem preparing the Payment Intent |
| 858 | 858 | return $gateways; |
| 859 | 859 | } |
| 860 | 860 | |
| 861 | - add_filter( 'woocommerce_checkout_show_terms', '__return_false' ); |
|
| 862 | - add_filter( 'woocommerce_pay_order_button_html', '__return_false' ); |
|
| 863 | - add_filter( 'woocommerce_available_payment_gateways', '__return_empty_array' ); |
|
| 864 | - add_filter( 'woocommerce_no_available_payment_methods_message', array( $this, 'change_no_available_methods_message' ) ); |
|
| 865 | - add_action( 'woocommerce_pay_order_after_submit', array( $this, 'render_payment_intent_inputs' ) ); |
|
| 861 | + add_filter('woocommerce_checkout_show_terms', '__return_false'); |
|
| 862 | + add_filter('woocommerce_pay_order_button_html', '__return_false'); |
|
| 863 | + add_filter('woocommerce_available_payment_gateways', '__return_empty_array'); |
|
| 864 | + add_filter('woocommerce_no_available_payment_methods_message', array($this, 'change_no_available_methods_message')); |
|
| 865 | + add_action('woocommerce_pay_order_after_submit', array($this, 'render_payment_intent_inputs')); |
|
| 866 | 866 | |
| 867 | 867 | return array(); |
| 868 | 868 | } |
@@ -875,7 +875,7 @@ discard block |
||
| 875 | 875 | * @return string the new message. |
| 876 | 876 | */ |
| 877 | 877 | public function change_no_available_methods_message() { |
| 878 | - return wpautop( __( "Almost there!\n\nYour order has already been created, the only thing that still needs to be done is for you to authorize the payment with your bank.", 'woocommerce-gateway-stripe' ) ); |
|
| 878 | + return wpautop(__("Almost there!\n\nYour order has already been created, the only thing that still needs to be done is for you to authorize the payment with your bank.", 'woocommerce-gateway-stripe')); |
|
| 879 | 879 | } |
| 880 | 880 | |
| 881 | 881 | /** |
@@ -886,19 +886,19 @@ discard block |
||
| 886 | 886 | * @throws WC_Stripe_Exception |
| 887 | 887 | * @since 4.3 |
| 888 | 888 | */ |
| 889 | - public function prepare_intent_for_order_pay_page( $order = null ) { |
|
| 890 | - if ( ! isset( $order ) || empty( $order ) ) { |
|
| 891 | - $order = wc_get_order( absint( get_query_var( 'order-pay' ) ) ); |
|
| 889 | + public function prepare_intent_for_order_pay_page($order = null) { |
|
| 890 | + if ( ! isset($order) || empty($order)) { |
|
| 891 | + $order = wc_get_order(absint(get_query_var('order-pay'))); |
|
| 892 | 892 | } |
| 893 | - $intent = $this->get_intent_from_order( $order ); |
|
| 893 | + $intent = $this->get_intent_from_order($order); |
|
| 894 | 894 | |
| 895 | - if ( ! $intent ) { |
|
| 896 | - throw new WC_Stripe_Exception( 'Payment Intent not found', __( 'Payment Intent not found for order #' . $order->get_id(), 'woocommerce-gateway-stripe' ) ); |
|
| 895 | + if ( ! $intent) { |
|
| 896 | + throw new WC_Stripe_Exception('Payment Intent not found', __('Payment Intent not found for order #' . $order->get_id(), 'woocommerce-gateway-stripe')); |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | - if ( 'requires_payment_method' === $intent->status && isset( $intent->last_payment_error ) |
|
| 900 | - && 'authentication_required' === $intent->last_payment_error->code ) { |
|
| 901 | - $level3_data = $this->get_level3_data_from_order( $order ); |
|
| 899 | + if ('requires_payment_method' === $intent->status && isset($intent->last_payment_error) |
|
| 900 | + && 'authentication_required' === $intent->last_payment_error->code) { |
|
| 901 | + $level3_data = $this->get_level3_data_from_order($order); |
|
| 902 | 902 | $intent = WC_Stripe_API::request_with_level3_data( |
| 903 | 903 | array( |
| 904 | 904 | 'payment_method' => $intent->last_payment_error->source->id, |
@@ -908,8 +908,8 @@ discard block |
||
| 908 | 908 | $order |
| 909 | 909 | ); |
| 910 | 910 | |
| 911 | - if ( isset( $intent->error ) ) { |
|
| 912 | - throw new WC_Stripe_Exception( print_r( $intent, true ), $intent->error->message ); |
|
| 911 | + if (isset($intent->error)) { |
|
| 912 | + throw new WC_Stripe_Exception(print_r($intent, true), $intent->error->message); |
|
| 913 | 913 | } |
| 914 | 914 | } |
| 915 | 915 | |
@@ -924,26 +924,26 @@ discard block |
||
| 924 | 924 | * @throws WC_Stripe_Exception |
| 925 | 925 | * @since 4.2 |
| 926 | 926 | */ |
| 927 | - public function render_payment_intent_inputs( $order = null ) { |
|
| 928 | - if ( ! isset( $order ) || empty( $order ) ) { |
|
| 929 | - $order = wc_get_order( absint( get_query_var( 'order-pay' ) ) ); |
|
| 927 | + public function render_payment_intent_inputs($order = null) { |
|
| 928 | + if ( ! isset($order) || empty($order)) { |
|
| 929 | + $order = wc_get_order(absint(get_query_var('order-pay'))); |
|
| 930 | 930 | } |
| 931 | - if ( ! isset( $this->order_pay_intent ) ) { |
|
| 932 | - $this->prepare_intent_for_order_pay_page( $order ); |
|
| 931 | + if ( ! isset($this->order_pay_intent)) { |
|
| 932 | + $this->prepare_intent_for_order_pay_page($order); |
|
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | $verification_url = add_query_arg( |
| 936 | 936 | array( |
| 937 | 937 | 'order' => $order->get_id(), |
| 938 | - 'nonce' => wp_create_nonce( 'wc_stripe_confirm_pi' ), |
|
| 939 | - 'redirect_to' => rawurlencode( $this->get_return_url( $order ) ), |
|
| 938 | + 'nonce' => wp_create_nonce('wc_stripe_confirm_pi'), |
|
| 939 | + 'redirect_to' => rawurlencode($this->get_return_url($order)), |
|
| 940 | 940 | 'is_pay_for_order' => true, |
| 941 | 941 | ), |
| 942 | - WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' ) |
|
| 942 | + WC_AJAX::get_endpoint('wc_stripe_verify_intent') |
|
| 943 | 943 | ); |
| 944 | 944 | |
| 945 | - echo '<input type="hidden" id="stripe-intent-id" value="' . esc_attr( $this->order_pay_intent->client_secret ) . '" />'; |
|
| 946 | - echo '<input type="hidden" id="stripe-intent-return" value="' . esc_attr( $verification_url ) . '" />'; |
|
| 945 | + echo '<input type="hidden" id="stripe-intent-id" value="' . esc_attr($this->order_pay_intent->client_secret) . '" />'; |
|
| 946 | + echo '<input type="hidden" id="stripe-intent-return" value="' . esc_attr($verification_url) . '" />'; |
|
| 947 | 947 | } |
| 948 | 948 | |
| 949 | 949 | /** |
@@ -953,11 +953,11 @@ discard block |
||
| 953 | 953 | * @param WC_Payment_Token $token Payment Token. |
| 954 | 954 | * @return string Generated payment method HTML |
| 955 | 955 | */ |
| 956 | - public function get_saved_payment_method_option_html( $token ) { |
|
| 957 | - $html = parent::get_saved_payment_method_option_html( $token ); |
|
| 956 | + public function get_saved_payment_method_option_html($token) { |
|
| 957 | + $html = parent::get_saved_payment_method_option_html($token); |
|
| 958 | 958 | $error_wrapper = '<div class="stripe-source-errors" role="alert"></div>'; |
| 959 | 959 | |
| 960 | - return preg_replace( '~</(\w+)>\s*$~', "$error_wrapper</$1>", $html ); |
|
| 960 | + return preg_replace('~</(\w+)>\s*$~', "$error_wrapper</$1>", $html); |
|
| 961 | 961 | } |
| 962 | 962 | |
| 963 | 963 | /** |
@@ -967,18 +967,18 @@ discard block |
||
| 967 | 967 | * @since 4.2.0 |
| 968 | 968 | * @param int $order_id The ID that will be used for the thank you page. |
| 969 | 969 | */ |
| 970 | - public function check_intent_status_on_order_page( $order_id ) { |
|
| 971 | - if ( empty( $order_id ) || absint( $order_id ) <= 0 ) { |
|
| 970 | + public function check_intent_status_on_order_page($order_id) { |
|
| 971 | + if (empty($order_id) || absint($order_id) <= 0) { |
|
| 972 | 972 | return; |
| 973 | 973 | } |
| 974 | 974 | |
| 975 | - $order = wc_get_order( absint( $order_id ) ); |
|
| 975 | + $order = wc_get_order(absint($order_id)); |
|
| 976 | 976 | |
| 977 | - if ( ! $order ) { |
|
| 977 | + if ( ! $order) { |
|
| 978 | 978 | return; |
| 979 | 979 | } |
| 980 | 980 | |
| 981 | - $this->verify_intent_after_checkout( $order ); |
|
| 981 | + $this->verify_intent_after_checkout($order); |
|
| 982 | 982 | } |
| 983 | 983 | |
| 984 | 984 | /** |
@@ -992,8 +992,8 @@ discard block |
||
| 992 | 992 | * @param int $order_id The ID of the order which is being paid for. |
| 993 | 993 | * @return array |
| 994 | 994 | */ |
| 995 | - public function modify_successful_payment_result( $result, $order_id ) { |
|
| 996 | - if ( ! isset( $result['payment_intent_secret'] ) && ! isset( $result['setup_intent_secret'] ) ) { |
|
| 995 | + public function modify_successful_payment_result($result, $order_id) { |
|
| 996 | + if ( ! isset($result['payment_intent_secret']) && ! isset($result['setup_intent_secret'])) { |
|
| 997 | 997 | // Only redirects with intents need to be modified. |
| 998 | 998 | return $result; |
| 999 | 999 | } |
@@ -1002,16 +1002,16 @@ discard block |
||
| 1002 | 1002 | $verification_url = add_query_arg( |
| 1003 | 1003 | array( |
| 1004 | 1004 | 'order' => $order_id, |
| 1005 | - 'nonce' => wp_create_nonce( 'wc_stripe_confirm_pi' ), |
|
| 1006 | - 'redirect_to' => rawurlencode( $result['redirect'] ), |
|
| 1005 | + 'nonce' => wp_create_nonce('wc_stripe_confirm_pi'), |
|
| 1006 | + 'redirect_to' => rawurlencode($result['redirect']), |
|
| 1007 | 1007 | ), |
| 1008 | - WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' ) |
|
| 1008 | + WC_AJAX::get_endpoint('wc_stripe_verify_intent') |
|
| 1009 | 1009 | ); |
| 1010 | 1010 | |
| 1011 | - if ( isset( $result['payment_intent_secret'] ) ) { |
|
| 1012 | - $redirect = sprintf( '#confirm-pi-%s:%s', $result['payment_intent_secret'], rawurlencode( $verification_url ) ); |
|
| 1013 | - } else if ( isset( $result['setup_intent_secret'] ) ) { |
|
| 1014 | - $redirect = sprintf( '#confirm-si-%s:%s', $result['setup_intent_secret'], rawurlencode( $verification_url ) ); |
|
| 1011 | + if (isset($result['payment_intent_secret'])) { |
|
| 1012 | + $redirect = sprintf('#confirm-pi-%s:%s', $result['payment_intent_secret'], rawurlencode($verification_url)); |
|
| 1013 | + } else if (isset($result['setup_intent_secret'])) { |
|
| 1014 | + $redirect = sprintf('#confirm-si-%s:%s', $result['setup_intent_secret'], rawurlencode($verification_url)); |
|
| 1015 | 1015 | } |
| 1016 | 1016 | |
| 1017 | 1017 | return array( |
@@ -1023,8 +1023,8 @@ discard block |
||
| 1023 | 1023 | /** |
| 1024 | 1024 | * Proceed with current request using new login session (to ensure consistent nonce). |
| 1025 | 1025 | */ |
| 1026 | - public function set_cookie_on_current_request( $cookie ) { |
|
| 1027 | - $_COOKIE[ LOGGED_IN_COOKIE ] = $cookie; |
|
| 1026 | + public function set_cookie_on_current_request($cookie) { |
|
| 1027 | + $_COOKIE[LOGGED_IN_COOKIE] = $cookie; |
|
| 1028 | 1028 | } |
| 1029 | 1029 | |
| 1030 | 1030 | /** |
@@ -1034,48 +1034,48 @@ discard block |
||
| 1034 | 1034 | * @since 4.2.0 |
| 1035 | 1035 | * @param WC_Order $order The order which is in a transitional state. |
| 1036 | 1036 | */ |
| 1037 | - public function verify_intent_after_checkout( $order ) { |
|
| 1037 | + public function verify_intent_after_checkout($order) { |
|
| 1038 | 1038 | $payment_method = $order->get_payment_method(); |
| 1039 | - if ( $payment_method !== $this->id ) { |
|
| 1039 | + if ($payment_method !== $this->id) { |
|
| 1040 | 1040 | // If this is not the payment method, an intent would not be available. |
| 1041 | 1041 | return; |
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | - $intent = $this->get_intent_from_order( $order ); |
|
| 1045 | - if ( ! $intent ) { |
|
| 1044 | + $intent = $this->get_intent_from_order($order); |
|
| 1045 | + if ( ! $intent) { |
|
| 1046 | 1046 | // No intent, redirect to the order received page for further actions. |
| 1047 | 1047 | return; |
| 1048 | 1048 | } |
| 1049 | 1049 | |
| 1050 | 1050 | // A webhook might have modified or locked the order while the intent was retreived. This ensures we are reading the right status. |
| 1051 | - clean_post_cache( $order->get_id() ); |
|
| 1052 | - $order = wc_get_order( $order->get_id() ); |
|
| 1051 | + clean_post_cache($order->get_id()); |
|
| 1052 | + $order = wc_get_order($order->get_id()); |
|
| 1053 | 1053 | |
| 1054 | - if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 1054 | + if ( ! $order->has_status(array('pending', 'failed'))) { |
|
| 1055 | 1055 | // If payment has already been completed, this function is redundant. |
| 1056 | 1056 | return; |
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | - if ( $this->lock_order_payment( $order, $intent ) ) { |
|
| 1059 | + if ($this->lock_order_payment($order, $intent)) { |
|
| 1060 | 1060 | return; |
| 1061 | 1061 | } |
| 1062 | 1062 | |
| 1063 | - if ( 'setup_intent' === $intent->object && 'succeeded' === $intent->status ) { |
|
| 1063 | + if ('setup_intent' === $intent->object && 'succeeded' === $intent->status) { |
|
| 1064 | 1064 | WC()->cart->empty_cart(); |
| 1065 | - if ( WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order( $order ) ) { |
|
| 1066 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
| 1065 | + if (WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order($order)) { |
|
| 1066 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
| 1067 | 1067 | } else { |
| 1068 | 1068 | $order->payment_complete(); |
| 1069 | 1069 | } |
| 1070 | - } else if ( 'succeeded' === $intent->status || 'requires_capture' === $intent->status ) { |
|
| 1070 | + } else if ('succeeded' === $intent->status || 'requires_capture' === $intent->status) { |
|
| 1071 | 1071 | // Proceed with the payment completion. |
| 1072 | - $this->handle_intent_verification_success( $order, $intent ); |
|
| 1073 | - } else if ( 'requires_payment_method' === $intent->status ) { |
|
| 1072 | + $this->handle_intent_verification_success($order, $intent); |
|
| 1073 | + } else if ('requires_payment_method' === $intent->status) { |
|
| 1074 | 1074 | // `requires_payment_method` means that SCA got denied for the current payment method. |
| 1075 | - $this->handle_intent_verification_failure( $order, $intent ); |
|
| 1075 | + $this->handle_intent_verification_failure($order, $intent); |
|
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | - $this->unlock_order_payment( $order ); |
|
| 1078 | + $this->unlock_order_payment($order); |
|
| 1079 | 1079 | } |
| 1080 | 1080 | |
| 1081 | 1081 | /** |
@@ -1085,8 +1085,8 @@ discard block |
||
| 1085 | 1085 | * @param WC_Order $order The order whose verification succeeded. |
| 1086 | 1086 | * @param stdClass $intent The Payment Intent object. |
| 1087 | 1087 | */ |
| 1088 | - protected function handle_intent_verification_success( $order, $intent ) { |
|
| 1089 | - $this->process_response( end( $intent->charges->data ), $order ); |
|
| 1088 | + protected function handle_intent_verification_success($order, $intent) { |
|
| 1089 | + $this->process_response(end($intent->charges->data), $order); |
|
| 1090 | 1090 | } |
| 1091 | 1091 | |
| 1092 | 1092 | /** |
@@ -1096,8 +1096,8 @@ discard block |
||
| 1096 | 1096 | * @param WC_Order $order The order whose verification failed. |
| 1097 | 1097 | * @param stdClass $intent The Payment Intent object. |
| 1098 | 1098 | */ |
| 1099 | - protected function handle_intent_verification_failure( $order, $intent ) { |
|
| 1100 | - $this->failed_sca_auth( $order, $intent ); |
|
| 1099 | + protected function handle_intent_verification_failure($order, $intent) { |
|
| 1100 | + $this->failed_sca_auth($order, $intent); |
|
| 1101 | 1101 | } |
| 1102 | 1102 | |
| 1103 | 1103 | /** |
@@ -1107,18 +1107,18 @@ discard block |
||
| 1107 | 1107 | * @param WC_Order $order The order which should be checked. |
| 1108 | 1108 | * @param object $intent The intent, associated with the order. |
| 1109 | 1109 | */ |
| 1110 | - public function failed_sca_auth( $order, $intent ) { |
|
| 1110 | + public function failed_sca_auth($order, $intent) { |
|
| 1111 | 1111 | // If the order has already failed, do not repeat the same message. |
| 1112 | - if ( $order->has_status( 'failed' ) ) { |
|
| 1112 | + if ($order->has_status('failed')) { |
|
| 1113 | 1113 | return; |
| 1114 | 1114 | } |
| 1115 | 1115 | |
| 1116 | 1116 | // Load the right message and update the status. |
| 1117 | - $status_message = isset( $intent->last_payment_error ) |
|
| 1117 | + $status_message = isset($intent->last_payment_error) |
|
| 1118 | 1118 | /* translators: 1) The error message that was received from Stripe. */ |
| 1119 | - ? sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $intent->last_payment_error->message ) |
|
| 1120 | - : __( 'Stripe SCA authentication failed.', 'woocommerce-gateway-stripe' ); |
|
| 1121 | - $order->update_status( 'failed', $status_message ); |
|
| 1119 | + ? sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $intent->last_payment_error->message) |
|
| 1120 | + : __('Stripe SCA authentication failed.', 'woocommerce-gateway-stripe'); |
|
| 1121 | + $order->update_status('failed', $status_message); |
|
| 1122 | 1122 | } |
| 1123 | 1123 | |
| 1124 | 1124 | /** |
@@ -1129,10 +1129,10 @@ discard block |
||
| 1129 | 1129 | * |
| 1130 | 1130 | * @return string Checkout URL for the given order. |
| 1131 | 1131 | */ |
| 1132 | - public function get_checkout_payment_url( $pay_url, $order ) { |
|
| 1132 | + public function get_checkout_payment_url($pay_url, $order) { |
|
| 1133 | 1133 | global $wp; |
| 1134 | - if ( isset( $_GET['wc-stripe-confirmation'] ) && isset( $wp->query_vars['order-pay'] ) && $wp->query_vars['order-pay'] == $order->get_id() ) { |
|
| 1135 | - $pay_url = add_query_arg( 'wc-stripe-confirmation', 1, $pay_url ); |
|
| 1134 | + if (isset($_GET['wc-stripe-confirmation']) && isset($wp->query_vars['order-pay']) && $wp->query_vars['order-pay'] == $order->get_id()) { |
|
| 1135 | + $pay_url = add_query_arg('wc-stripe-confirmation', 1, $pay_url); |
|
| 1136 | 1136 | } |
| 1137 | 1137 | return $pay_url; |
| 1138 | 1138 | } |
@@ -1142,63 +1142,63 @@ discard block |
||
| 1142 | 1142 | */ |
| 1143 | 1143 | public function process_admin_options() { |
| 1144 | 1144 | // Load all old values before the new settings get saved. |
| 1145 | - $old_publishable_key = $this->get_option( 'publishable_key' ); |
|
| 1146 | - $old_secret_key = $this->get_option( 'secret_key' ); |
|
| 1147 | - $old_test_publishable_key = $this->get_option( 'test_publishable_key' ); |
|
| 1148 | - $old_test_secret_key = $this->get_option( 'test_secret_key' ); |
|
| 1145 | + $old_publishable_key = $this->get_option('publishable_key'); |
|
| 1146 | + $old_secret_key = $this->get_option('secret_key'); |
|
| 1147 | + $old_test_publishable_key = $this->get_option('test_publishable_key'); |
|
| 1148 | + $old_test_secret_key = $this->get_option('test_secret_key'); |
|
| 1149 | 1149 | |
| 1150 | 1150 | parent::process_admin_options(); |
| 1151 | 1151 | |
| 1152 | 1152 | // Load all old values after the new settings have been saved. |
| 1153 | - $new_publishable_key = $this->get_option( 'publishable_key' ); |
|
| 1154 | - $new_secret_key = $this->get_option( 'secret_key' ); |
|
| 1155 | - $new_test_publishable_key = $this->get_option( 'test_publishable_key' ); |
|
| 1156 | - $new_test_secret_key = $this->get_option( 'test_secret_key' ); |
|
| 1153 | + $new_publishable_key = $this->get_option('publishable_key'); |
|
| 1154 | + $new_secret_key = $this->get_option('secret_key'); |
|
| 1155 | + $new_test_publishable_key = $this->get_option('test_publishable_key'); |
|
| 1156 | + $new_test_secret_key = $this->get_option('test_secret_key'); |
|
| 1157 | 1157 | |
| 1158 | 1158 | // Checks whether a value has transitioned from a non-empty value to a new one. |
| 1159 | - $has_changed = function( $old_value, $new_value ) { |
|
| 1160 | - return ! empty( $old_value ) && ( $old_value !== $new_value ); |
|
| 1159 | + $has_changed = function($old_value, $new_value) { |
|
| 1160 | + return ! empty($old_value) && ($old_value !== $new_value); |
|
| 1161 | 1161 | }; |
| 1162 | 1162 | |
| 1163 | 1163 | // Look for updates. |
| 1164 | 1164 | if ( |
| 1165 | - $has_changed( $old_publishable_key, $new_publishable_key ) |
|
| 1166 | - || $has_changed( $old_secret_key, $new_secret_key ) |
|
| 1167 | - || $has_changed( $old_test_publishable_key, $new_test_publishable_key ) |
|
| 1168 | - || $has_changed( $old_test_secret_key, $new_test_secret_key ) |
|
| 1165 | + $has_changed($old_publishable_key, $new_publishable_key) |
|
| 1166 | + || $has_changed($old_secret_key, $new_secret_key) |
|
| 1167 | + || $has_changed($old_test_publishable_key, $new_test_publishable_key) |
|
| 1168 | + || $has_changed($old_test_secret_key, $new_test_secret_key) |
|
| 1169 | 1169 | ) { |
| 1170 | - update_option( 'wc_stripe_show_changed_keys_notice', 'yes' ); |
|
| 1170 | + update_option('wc_stripe_show_changed_keys_notice', 'yes'); |
|
| 1171 | 1171 | } |
| 1172 | 1172 | } |
| 1173 | 1173 | |
| 1174 | - public function validate_publishable_key_field( $key, $value ) { |
|
| 1175 | - $value = $this->validate_text_field( $key, $value ); |
|
| 1176 | - if ( ! empty( $value ) && ! preg_match( '/^pk_live_/', $value ) ) { |
|
| 1177 | - throw new Exception( __( 'The "Live Publishable Key" should start with "pk_live", enter the correct key.', 'woocommerce-gateway-stripe' ) ); |
|
| 1174 | + public function validate_publishable_key_field($key, $value) { |
|
| 1175 | + $value = $this->validate_text_field($key, $value); |
|
| 1176 | + if ( ! empty($value) && ! preg_match('/^pk_live_/', $value)) { |
|
| 1177 | + throw new Exception(__('The "Live Publishable Key" should start with "pk_live", enter the correct key.', 'woocommerce-gateway-stripe')); |
|
| 1178 | 1178 | } |
| 1179 | 1179 | return $value; |
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | - public function validate_secret_key_field( $key, $value ) { |
|
| 1183 | - $value = $this->validate_text_field( $key, $value ); |
|
| 1184 | - if ( ! empty( $value ) && ! preg_match( '/^[rs]k_live_/', $value ) ) { |
|
| 1185 | - throw new Exception( __( 'The "Live Secret Key" should start with "sk_live" or "rk_live", enter the correct key.', 'woocommerce-gateway-stripe' ) ); |
|
| 1182 | + public function validate_secret_key_field($key, $value) { |
|
| 1183 | + $value = $this->validate_text_field($key, $value); |
|
| 1184 | + if ( ! empty($value) && ! preg_match('/^[rs]k_live_/', $value)) { |
|
| 1185 | + throw new Exception(__('The "Live Secret Key" should start with "sk_live" or "rk_live", enter the correct key.', 'woocommerce-gateway-stripe')); |
|
| 1186 | 1186 | } |
| 1187 | 1187 | return $value; |
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | - public function validate_test_publishable_key_field( $key, $value ) { |
|
| 1191 | - $value = $this->validate_text_field( $key, $value ); |
|
| 1192 | - if ( ! empty( $value ) && ! preg_match( '/^pk_test_/', $value ) ) { |
|
| 1193 | - throw new Exception( __( 'The "Test Publishable Key" should start with "pk_test", enter the correct key.', 'woocommerce-gateway-stripe' ) ); |
|
| 1190 | + public function validate_test_publishable_key_field($key, $value) { |
|
| 1191 | + $value = $this->validate_text_field($key, $value); |
|
| 1192 | + if ( ! empty($value) && ! preg_match('/^pk_test_/', $value)) { |
|
| 1193 | + throw new Exception(__('The "Test Publishable Key" should start with "pk_test", enter the correct key.', 'woocommerce-gateway-stripe')); |
|
| 1194 | 1194 | } |
| 1195 | 1195 | return $value; |
| 1196 | 1196 | } |
| 1197 | 1197 | |
| 1198 | - public function validate_test_secret_key_field( $key, $value ) { |
|
| 1199 | - $value = $this->validate_text_field( $key, $value ); |
|
| 1200 | - if ( ! empty( $value ) && ! preg_match( '/^[rs]k_test_/', $value ) ) { |
|
| 1201 | - throw new Exception( __( 'The "Test Secret Key" should start with "sk_test" or "rk_test", enter the correct key.', 'woocommerce-gateway-stripe' ) ); |
|
| 1198 | + public function validate_test_secret_key_field($key, $value) { |
|
| 1199 | + $value = $this->validate_text_field($key, $value); |
|
| 1200 | + if ( ! empty($value) && ! preg_match('/^[rs]k_test_/', $value)) { |
|
| 1201 | + throw new Exception(__('The "Test Secret Key" should start with "sk_test" or "rk_test", enter the correct key.', 'woocommerce-gateway-stripe')); |
|
| 1202 | 1202 | } |
| 1203 | 1203 | return $value; |
| 1204 | 1204 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -22,12 +22,12 @@ discard block |
||
| 22 | 22 | * @param object $order |
| 23 | 23 | * @return string $currency |
| 24 | 24 | */ |
| 25 | - public static function get_stripe_currency( $order = null ) { |
|
| 26 | - if ( is_null( $order ) ) { |
|
| 25 | + public static function get_stripe_currency($order = null) { |
|
| 26 | + if (is_null($order)) { |
|
| 27 | 27 | return false; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - return $order->get_meta( self::META_NAME_STRIPE_CURRENCY, true ); |
|
| 30 | + return $order->get_meta(self::META_NAME_STRIPE_CURRENCY, true); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -37,12 +37,12 @@ discard block |
||
| 37 | 37 | * @param object $order |
| 38 | 38 | * @param string $currency |
| 39 | 39 | */ |
| 40 | - public static function update_stripe_currency( $order = null, $currency ) { |
|
| 41 | - if ( is_null( $order ) ) { |
|
| 40 | + public static function update_stripe_currency($order = null, $currency) { |
|
| 41 | + if (is_null($order)) { |
|
| 42 | 42 | return false; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - $order->update_meta_data( self::META_NAME_STRIPE_CURRENCY, $currency ); |
|
| 45 | + $order->update_meta_data(self::META_NAME_STRIPE_CURRENCY, $currency); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -52,20 +52,20 @@ discard block |
||
| 52 | 52 | * @param object $order |
| 53 | 53 | * @return string $amount |
| 54 | 54 | */ |
| 55 | - public static function get_stripe_fee( $order = null ) { |
|
| 56 | - if ( is_null( $order ) ) { |
|
| 55 | + public static function get_stripe_fee($order = null) { |
|
| 56 | + if (is_null($order)) { |
|
| 57 | 57 | return false; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - $amount = $order->get_meta( self::META_NAME_FEE, true ); |
|
| 60 | + $amount = $order->get_meta(self::META_NAME_FEE, true); |
|
| 61 | 61 | |
| 62 | 62 | // If not found let's check for legacy name. |
| 63 | - if ( empty( $amount ) ) { |
|
| 64 | - $amount = $order->get_meta( self::LEGACY_META_NAME_FEE, true ); |
|
| 63 | + if (empty($amount)) { |
|
| 64 | + $amount = $order->get_meta(self::LEGACY_META_NAME_FEE, true); |
|
| 65 | 65 | |
| 66 | 66 | // If found update to new name. |
| 67 | - if ( $amount ) { |
|
| 68 | - self::update_stripe_fee( $order, $amount ); |
|
| 67 | + if ($amount) { |
|
| 68 | + self::update_stripe_fee($order, $amount); |
|
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | 71 | |
@@ -79,12 +79,12 @@ discard block |
||
| 79 | 79 | * @param object $order |
| 80 | 80 | * @param float $amount |
| 81 | 81 | */ |
| 82 | - public static function update_stripe_fee( $order = null, $amount = 0.0 ) { |
|
| 83 | - if ( is_null( $order ) ) { |
|
| 82 | + public static function update_stripe_fee($order = null, $amount = 0.0) { |
|
| 83 | + if (is_null($order)) { |
|
| 84 | 84 | return false; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - $order->update_meta_data( self::META_NAME_FEE, $amount ); |
|
| 87 | + $order->update_meta_data(self::META_NAME_FEE, $amount); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -93,15 +93,15 @@ discard block |
||
| 93 | 93 | * @since 4.1.0 |
| 94 | 94 | * @param object $order |
| 95 | 95 | */ |
| 96 | - public static function delete_stripe_fee( $order = null ) { |
|
| 97 | - if ( is_null( $order ) ) { |
|
| 96 | + public static function delete_stripe_fee($order = null) { |
|
| 97 | + if (is_null($order)) { |
|
| 98 | 98 | return false; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | $order_id = $order->get_id(); |
| 102 | 102 | |
| 103 | - delete_post_meta( $order_id, self::META_NAME_FEE ); |
|
| 104 | - delete_post_meta( $order_id, self::LEGACY_META_NAME_FEE ); |
|
| 103 | + delete_post_meta($order_id, self::META_NAME_FEE); |
|
| 104 | + delete_post_meta($order_id, self::LEGACY_META_NAME_FEE); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -111,20 +111,20 @@ discard block |
||
| 111 | 111 | * @param object $order |
| 112 | 112 | * @return string $amount |
| 113 | 113 | */ |
| 114 | - public static function get_stripe_net( $order = null ) { |
|
| 115 | - if ( is_null( $order ) ) { |
|
| 114 | + public static function get_stripe_net($order = null) { |
|
| 115 | + if (is_null($order)) { |
|
| 116 | 116 | return false; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - $amount = $order->get_meta( self::META_NAME_NET, true ); |
|
| 119 | + $amount = $order->get_meta(self::META_NAME_NET, true); |
|
| 120 | 120 | |
| 121 | 121 | // If not found let's check for legacy name. |
| 122 | - if ( empty( $amount ) ) { |
|
| 123 | - $amount = $order->get_meta( self::LEGACY_META_NAME_NET, true ); |
|
| 122 | + if (empty($amount)) { |
|
| 123 | + $amount = $order->get_meta(self::LEGACY_META_NAME_NET, true); |
|
| 124 | 124 | |
| 125 | 125 | // If found update to new name. |
| 126 | - if ( $amount ) { |
|
| 127 | - self::update_stripe_net( $order, $amount ); |
|
| 126 | + if ($amount) { |
|
| 127 | + self::update_stripe_net($order, $amount); |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | |
@@ -138,12 +138,12 @@ discard block |
||
| 138 | 138 | * @param object $order |
| 139 | 139 | * @param float $amount |
| 140 | 140 | */ |
| 141 | - public static function update_stripe_net( $order = null, $amount = 0.0 ) { |
|
| 142 | - if ( is_null( $order ) ) { |
|
| 141 | + public static function update_stripe_net($order = null, $amount = 0.0) { |
|
| 142 | + if (is_null($order)) { |
|
| 143 | 143 | return false; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - $order->update_meta_data( self::META_NAME_NET, $amount ); |
|
| 146 | + $order->update_meta_data(self::META_NAME_NET, $amount); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -152,15 +152,15 @@ discard block |
||
| 152 | 152 | * @since 4.1.0 |
| 153 | 153 | * @param object $order |
| 154 | 154 | */ |
| 155 | - public static function delete_stripe_net( $order = null ) { |
|
| 156 | - if ( is_null( $order ) ) { |
|
| 155 | + public static function delete_stripe_net($order = null) { |
|
| 156 | + if (is_null($order)) { |
|
| 157 | 157 | return false; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | $order_id = $order->get_id(); |
| 161 | 161 | |
| 162 | - delete_post_meta( $order_id, self::META_NAME_NET ); |
|
| 163 | - delete_post_meta( $order_id, self::LEGACY_META_NAME_NET ); |
|
| 162 | + delete_post_meta($order_id, self::META_NAME_NET); |
|
| 163 | + delete_post_meta($order_id, self::LEGACY_META_NAME_NET); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -171,15 +171,15 @@ discard block |
||
| 171 | 171 | * |
| 172 | 172 | * @return float|int |
| 173 | 173 | */ |
| 174 | - public static function get_stripe_amount( $total, $currency = '' ) { |
|
| 175 | - if ( ! $currency ) { |
|
| 174 | + public static function get_stripe_amount($total, $currency = '') { |
|
| 175 | + if ( ! $currency) { |
|
| 176 | 176 | $currency = get_woocommerce_currency(); |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - if ( in_array( strtolower( $currency ), self::no_decimal_currencies() ) ) { |
|
| 180 | - return absint( $total ); |
|
| 179 | + if (in_array(strtolower($currency), self::no_decimal_currencies())) { |
|
| 180 | + return absint($total); |
|
| 181 | 181 | } else { |
| 182 | - return absint( wc_format_decimal( ( (float) $total * 100 ), wc_get_price_decimals() ) ); // In cents. |
|
| 182 | + return absint(wc_format_decimal(((float) $total * 100), wc_get_price_decimals())); // In cents. |
|
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | |
@@ -194,26 +194,26 @@ discard block |
||
| 194 | 194 | return apply_filters( |
| 195 | 195 | 'wc_stripe_localized_messages', |
| 196 | 196 | array( |
| 197 | - 'invalid_number' => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ), |
|
| 198 | - 'invalid_expiry_month' => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 199 | - 'invalid_expiry_year' => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 200 | - 'invalid_cvc' => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 201 | - 'incorrect_number' => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ), |
|
| 202 | - 'incomplete_number' => __( 'The card number is incomplete.', 'woocommerce-gateway-stripe' ), |
|
| 203 | - 'incomplete_cvc' => __( 'The card\'s security code is incomplete.', 'woocommerce-gateway-stripe' ), |
|
| 204 | - 'incomplete_expiry' => __( 'The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe' ), |
|
| 205 | - 'expired_card' => __( 'The card has expired.', 'woocommerce-gateway-stripe' ), |
|
| 206 | - 'incorrect_cvc' => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ), |
|
| 207 | - 'incorrect_zip' => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ), |
|
| 208 | - 'invalid_expiry_year_past' => __( 'The card\'s expiration year is in the past', 'woocommerce-gateway-stripe' ), |
|
| 209 | - 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
| 210 | - 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
| 211 | - 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
| 212 | - 'invalid_sofort_country' => __( 'The billing country is not accepted by SOFORT. Please try another country.', 'woocommerce-gateway-stripe' ), |
|
| 213 | - 'email_invalid' => __( 'Invalid email address, please correct and try again.', 'woocommerce-gateway-stripe' ), |
|
| 197 | + 'invalid_number' => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'), |
|
| 198 | + 'invalid_expiry_month' => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'), |
|
| 199 | + 'invalid_expiry_year' => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'), |
|
| 200 | + 'invalid_cvc' => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'), |
|
| 201 | + 'incorrect_number' => __('The card number is incorrect.', 'woocommerce-gateway-stripe'), |
|
| 202 | + 'incomplete_number' => __('The card number is incomplete.', 'woocommerce-gateway-stripe'), |
|
| 203 | + 'incomplete_cvc' => __('The card\'s security code is incomplete.', 'woocommerce-gateway-stripe'), |
|
| 204 | + 'incomplete_expiry' => __('The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe'), |
|
| 205 | + 'expired_card' => __('The card has expired.', 'woocommerce-gateway-stripe'), |
|
| 206 | + 'incorrect_cvc' => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'), |
|
| 207 | + 'incorrect_zip' => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'), |
|
| 208 | + 'invalid_expiry_year_past' => __('The card\'s expiration year is in the past', 'woocommerce-gateway-stripe'), |
|
| 209 | + 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
| 210 | + 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
| 211 | + 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
| 212 | + 'invalid_sofort_country' => __('The billing country is not accepted by SOFORT. Please try another country.', 'woocommerce-gateway-stripe'), |
|
| 213 | + 'email_invalid' => __('Invalid email address, please correct and try again.', 'woocommerce-gateway-stripe'), |
|
| 214 | 214 | 'invalid_request_error' => is_add_payment_method_page() |
| 215 | - ? __( 'Unable to save this payment method, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) |
|
| 216 | - : __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ), |
|
| 215 | + ? __('Unable to save this payment method, please try again or use alternative method.', 'woocommerce-gateway-stripe') |
|
| 216 | + : __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'), |
|
| 217 | 217 | ) |
| 218 | 218 | ); |
| 219 | 219 | } |
@@ -254,24 +254,24 @@ discard block |
||
| 254 | 254 | * @param string $type Type of number to format |
| 255 | 255 | * @return string |
| 256 | 256 | */ |
| 257 | - public static function format_balance_fee( $balance_transaction, $type = 'fee' ) { |
|
| 258 | - if ( ! is_object( $balance_transaction ) ) { |
|
| 257 | + public static function format_balance_fee($balance_transaction, $type = 'fee') { |
|
| 258 | + if ( ! is_object($balance_transaction)) { |
|
| 259 | 259 | return; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) { |
|
| 263 | - if ( 'fee' === $type ) { |
|
| 262 | + if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) { |
|
| 263 | + if ('fee' === $type) { |
|
| 264 | 264 | return $balance_transaction->fee; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | return $balance_transaction->net; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - if ( 'fee' === $type ) { |
|
| 271 | - return number_format( $balance_transaction->fee / 100, 2, '.', '' ); |
|
| 270 | + if ('fee' === $type) { |
|
| 271 | + return number_format($balance_transaction->fee / 100, 2, '.', ''); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - return number_format( $balance_transaction->net / 100, 2, '.', '' ); |
|
| 274 | + return number_format($balance_transaction->net / 100, 2, '.', ''); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | */ |
| 280 | 280 | public static function get_minimum_amount() { |
| 281 | 281 | // Check order amount |
| 282 | - switch ( get_woocommerce_currency() ) { |
|
| 282 | + switch (get_woocommerce_currency()) { |
|
| 283 | 283 | case 'USD': |
| 284 | 284 | case 'CAD': |
| 285 | 285 | case 'EUR': |
@@ -324,14 +324,14 @@ discard block |
||
| 324 | 324 | * @param string $method The payment method to get the settings from. |
| 325 | 325 | * @param string $setting The name of the setting to get. |
| 326 | 326 | */ |
| 327 | - public static function get_settings( $method = null, $setting = null ) { |
|
| 328 | - $all_settings = null === $method ? get_option( 'woocommerce_stripe_settings', array() ) : get_option( 'woocommerce_stripe_' . $method . '_settings', array() ); |
|
| 327 | + public static function get_settings($method = null, $setting = null) { |
|
| 328 | + $all_settings = null === $method ? get_option('woocommerce_stripe_settings', array()) : get_option('woocommerce_stripe_' . $method . '_settings', array()); |
|
| 329 | 329 | |
| 330 | - if ( null === $setting ) { |
|
| 330 | + if (null === $setting) { |
|
| 331 | 331 | return $all_settings; |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - return isset( $all_settings[ $setting ] ) ? $all_settings[ $setting ] : ''; |
|
| 334 | + return isset($all_settings[$setting]) ? $all_settings[$setting] : ''; |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | * @return bool |
| 342 | 342 | */ |
| 343 | 343 | public static function is_pre_orders_exists() { |
| 344 | - return class_exists( 'WC_Pre_Orders_Order' ); |
|
| 344 | + return class_exists('WC_Pre_Orders_Order'); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | /** |
@@ -351,8 +351,8 @@ discard block |
||
| 351 | 351 | * @param string $version Version to check against. |
| 352 | 352 | * @return bool |
| 353 | 353 | */ |
| 354 | - public static function is_wc_lt( $version ) { |
|
| 355 | - return version_compare( WC_VERSION, $version, '<' ); |
|
| 354 | + public static function is_wc_lt($version) { |
|
| 355 | + return version_compare(WC_VERSION, $version, '<'); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | /** |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | * @return string |
| 366 | 366 | */ |
| 367 | 367 | public static function get_webhook_url() { |
| 368 | - return add_query_arg( 'wc-api', 'wc_stripe', trailingslashit( get_home_url() ) ); |
|
| 368 | + return add_query_arg('wc-api', 'wc_stripe', trailingslashit(get_home_url())); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | /** |
@@ -375,13 +375,13 @@ discard block |
||
| 375 | 375 | * @version 4.0.0 |
| 376 | 376 | * @param string $source_id |
| 377 | 377 | */ |
| 378 | - public static function get_order_by_source_id( $source_id ) { |
|
| 378 | + public static function get_order_by_source_id($source_id) { |
|
| 379 | 379 | global $wpdb; |
| 380 | 380 | |
| 381 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $source_id, '_stripe_source_id' ) ); |
|
| 381 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $source_id, '_stripe_source_id')); |
|
| 382 | 382 | |
| 383 | - if ( ! empty( $order_id ) ) { |
|
| 384 | - return wc_get_order( $order_id ); |
|
| 383 | + if ( ! empty($order_id)) { |
|
| 384 | + return wc_get_order($order_id); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | return false; |
@@ -394,17 +394,17 @@ discard block |
||
| 394 | 394 | * @since 4.1.16 Return false if charge_id is empty. |
| 395 | 395 | * @param string $charge_id |
| 396 | 396 | */ |
| 397 | - public static function get_order_by_charge_id( $charge_id ) { |
|
| 397 | + public static function get_order_by_charge_id($charge_id) { |
|
| 398 | 398 | global $wpdb; |
| 399 | 399 | |
| 400 | - if ( empty( $charge_id ) ) { |
|
| 400 | + if (empty($charge_id)) { |
|
| 401 | 401 | return false; |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $charge_id, '_transaction_id' ) ); |
|
| 404 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $charge_id, '_transaction_id')); |
|
| 405 | 405 | |
| 406 | - if ( ! empty( $order_id ) ) { |
|
| 407 | - return wc_get_order( $order_id ); |
|
| 406 | + if ( ! empty($order_id)) { |
|
| 407 | + return wc_get_order($order_id); |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | return false; |
@@ -417,13 +417,13 @@ discard block |
||
| 417 | 417 | * @param string $intent_id The ID of the intent. |
| 418 | 418 | * @return WC_Order|bool Either an order or false when not found. |
| 419 | 419 | */ |
| 420 | - public static function get_order_by_intent_id( $intent_id ) { |
|
| 420 | + public static function get_order_by_intent_id($intent_id) { |
|
| 421 | 421 | global $wpdb; |
| 422 | 422 | |
| 423 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $intent_id, '_stripe_intent_id' ) ); |
|
| 423 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $intent_id, '_stripe_intent_id')); |
|
| 424 | 424 | |
| 425 | - if ( ! empty( $order_id ) ) { |
|
| 426 | - return wc_get_order( $order_id ); |
|
| 425 | + if ( ! empty($order_id)) { |
|
| 426 | + return wc_get_order($order_id); |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | return false; |
@@ -436,13 +436,13 @@ discard block |
||
| 436 | 436 | * @param string $intent_id The ID of the intent. |
| 437 | 437 | * @return WC_Order|bool Either an order or false when not found. |
| 438 | 438 | */ |
| 439 | - public static function get_order_by_setup_intent_id( $intent_id ) { |
|
| 439 | + public static function get_order_by_setup_intent_id($intent_id) { |
|
| 440 | 440 | global $wpdb; |
| 441 | 441 | |
| 442 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $intent_id, '_stripe_setup_intent' ) ); |
|
| 442 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $intent_id, '_stripe_setup_intent')); |
|
| 443 | 443 | |
| 444 | - if ( ! empty( $order_id ) ) { |
|
| 445 | - return wc_get_order( $order_id ); |
|
| 444 | + if ( ! empty($order_id)) { |
|
| 445 | + return wc_get_order($order_id); |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | return false; |
@@ -458,13 +458,13 @@ discard block |
||
| 458 | 458 | * @param string $statement_descriptor |
| 459 | 459 | * @return string $statement_descriptor Sanitized statement descriptor |
| 460 | 460 | */ |
| 461 | - public static function clean_statement_descriptor( $statement_descriptor = '' ) { |
|
| 462 | - $disallowed_characters = array( '<', '>', '"', "'" ); |
|
| 461 | + public static function clean_statement_descriptor($statement_descriptor = '') { |
|
| 462 | + $disallowed_characters = array('<', '>', '"', "'"); |
|
| 463 | 463 | |
| 464 | 464 | // Remove special characters. |
| 465 | - $statement_descriptor = str_replace( $disallowed_characters, '', $statement_descriptor ); |
|
| 465 | + $statement_descriptor = str_replace($disallowed_characters, '', $statement_descriptor); |
|
| 466 | 466 | |
| 467 | - $statement_descriptor = substr( trim( $statement_descriptor ), 0, 22 ); |
|
| 467 | + $statement_descriptor = substr(trim($statement_descriptor), 0, 22); |
|
| 468 | 468 | |
| 469 | 469 | return $statement_descriptor; |
| 470 | 470 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | * Constructor |
| 33 | 33 | * @param int $user_id The WP user ID |
| 34 | 34 | */ |
| 35 | - public function __construct( $user_id = 0 ) { |
|
| 36 | - if ( $user_id ) { |
|
| 37 | - $this->set_user_id( $user_id ); |
|
| 38 | - $this->set_id( $this->get_id_from_meta( $user_id ) ); |
|
| 35 | + public function __construct($user_id = 0) { |
|
| 36 | + if ($user_id) { |
|
| 37 | + $this->set_user_id($user_id); |
|
| 38 | + $this->set_id($this->get_id_from_meta($user_id)); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
@@ -51,15 +51,15 @@ discard block |
||
| 51 | 51 | * Set Stripe customer ID. |
| 52 | 52 | * @param [type] $id [description] |
| 53 | 53 | */ |
| 54 | - public function set_id( $id ) { |
|
| 54 | + public function set_id($id) { |
|
| 55 | 55 | // Backwards compat for customer ID stored in array format. (Pre 3.0) |
| 56 | - if ( is_array( $id ) && isset( $id['customer_id'] ) ) { |
|
| 56 | + if (is_array($id) && isset($id['customer_id'])) { |
|
| 57 | 57 | $id = $id['customer_id']; |
| 58 | 58 | |
| 59 | - $this->update_id_in_meta( $id ); |
|
| 59 | + $this->update_id_in_meta($id); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - $this->id = wc_clean( $id ); |
|
| 62 | + $this->id = wc_clean($id); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -67,15 +67,15 @@ discard block |
||
| 67 | 67 | * @return int |
| 68 | 68 | */ |
| 69 | 69 | public function get_user_id() { |
| 70 | - return absint( $this->user_id ); |
|
| 70 | + return absint($this->user_id); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | 74 | * Set User ID used by WordPress. |
| 75 | 75 | * @param int $user_id |
| 76 | 76 | */ |
| 77 | - public function set_user_id( $user_id ) { |
|
| 78 | - $this->user_id = absint( $user_id ); |
|
| 77 | + public function set_user_id($user_id) { |
|
| 78 | + $this->user_id = absint($user_id); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -83,13 +83,13 @@ discard block |
||
| 83 | 83 | * @return WP_User |
| 84 | 84 | */ |
| 85 | 85 | protected function get_user() { |
| 86 | - return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false; |
|
| 86 | + return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
| 90 | 90 | * Store data from the Stripe API about this customer |
| 91 | 91 | */ |
| 92 | - public function set_customer_data( $data ) { |
|
| 92 | + public function set_customer_data($data) { |
|
| 93 | 93 | $this->customer_data = $data; |
| 94 | 94 | } |
| 95 | 95 | |
@@ -99,58 +99,58 @@ discard block |
||
| 99 | 99 | * @param array $args Additional arguments (optional). |
| 100 | 100 | * @return array |
| 101 | 101 | */ |
| 102 | - protected function generate_customer_request( $args = array() ) { |
|
| 103 | - $billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : ''; |
|
| 102 | + protected function generate_customer_request($args = array()) { |
|
| 103 | + $billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : ''; |
|
| 104 | 104 | $user = $this->get_user(); |
| 105 | 105 | |
| 106 | - if ( $user ) { |
|
| 107 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
| 108 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
| 106 | + if ($user) { |
|
| 107 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
| 108 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
| 109 | 109 | |
| 110 | 110 | // If billing first name does not exists try the user first name. |
| 111 | - if ( empty( $billing_first_name ) ) { |
|
| 112 | - $billing_first_name = get_user_meta( $user->ID, 'first_name', true ); |
|
| 111 | + if (empty($billing_first_name)) { |
|
| 112 | + $billing_first_name = get_user_meta($user->ID, 'first_name', true); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | // If billing last name does not exists try the user last name. |
| 116 | - if ( empty( $billing_last_name ) ) { |
|
| 117 | - $billing_last_name = get_user_meta( $user->ID, 'last_name', true ); |
|
| 116 | + if (empty($billing_last_name)) { |
|
| 117 | + $billing_last_name = get_user_meta($user->ID, 'last_name', true); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | // translators: %1$s First name, %2$s Second name, %3$s Username. |
| 121 | - $description = sprintf( __( 'Name: %1$s %2$s, Username: %s', 'woocommerce-gateway-stripe' ), $billing_first_name, $billing_last_name, $user->user_login ); |
|
| 121 | + $description = sprintf(__('Name: %1$s %2$s, Username: %s', 'woocommerce-gateway-stripe'), $billing_first_name, $billing_last_name, $user->user_login); |
|
| 122 | 122 | |
| 123 | 123 | $defaults = array( |
| 124 | 124 | 'email' => $user->user_email, |
| 125 | 125 | 'description' => $description, |
| 126 | 126 | ); |
| 127 | 127 | |
| 128 | - $billing_full_name = trim( $billing_first_name . ' ' . $billing_last_name ); |
|
| 129 | - if ( ! empty( $billing_full_name ) ) { |
|
| 128 | + $billing_full_name = trim($billing_first_name . ' ' . $billing_last_name); |
|
| 129 | + if ( ! empty($billing_full_name)) { |
|
| 130 | 130 | $defaults['name'] = $billing_full_name; |
| 131 | 131 | } |
| 132 | 132 | } else { |
| 133 | - $billing_first_name = isset( $_POST['billing_first_name'] ) ? filter_var( wp_unslash( $_POST['billing_first_name'] ), FILTER_SANITIZE_STRING ) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
| 134 | - $billing_last_name = isset( $_POST['billing_last_name'] ) ? filter_var( wp_unslash( $_POST['billing_last_name'] ), FILTER_SANITIZE_STRING ) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
| 133 | + $billing_first_name = isset($_POST['billing_first_name']) ? filter_var(wp_unslash($_POST['billing_first_name']), FILTER_SANITIZE_STRING) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
| 134 | + $billing_last_name = isset($_POST['billing_last_name']) ? filter_var(wp_unslash($_POST['billing_last_name']), FILTER_SANITIZE_STRING) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
| 135 | 135 | |
| 136 | 136 | // translators: %1$s First name, %2$s Second name. |
| 137 | - $description = sprintf( __( 'Name: %1$s %2$s, Guest', 'woocommerce-gateway-stripe' ), $billing_first_name, $billing_last_name ); |
|
| 137 | + $description = sprintf(__('Name: %1$s %2$s, Guest', 'woocommerce-gateway-stripe'), $billing_first_name, $billing_last_name); |
|
| 138 | 138 | |
| 139 | 139 | $defaults = array( |
| 140 | 140 | 'email' => $billing_email, |
| 141 | 141 | 'description' => $description, |
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | - $billing_full_name = trim( $billing_first_name . ' ' . $billing_last_name ); |
|
| 145 | - if ( ! empty( $billing_full_name ) ) { |
|
| 144 | + $billing_full_name = trim($billing_first_name . ' ' . $billing_last_name); |
|
| 145 | + if ( ! empty($billing_full_name)) { |
|
| 146 | 146 | $defaults['name'] = $billing_full_name; |
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | $metadata = array(); |
| 151 | - $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user ); |
|
| 151 | + $defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user); |
|
| 152 | 152 | |
| 153 | - return wp_parse_args( $args, $defaults ); |
|
| 153 | + return wp_parse_args($args, $defaults); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -158,23 +158,23 @@ discard block |
||
| 158 | 158 | * @param array $args |
| 159 | 159 | * @return WP_Error|int |
| 160 | 160 | */ |
| 161 | - public function create_customer( $args = array() ) { |
|
| 162 | - $args = $this->generate_customer_request( $args ); |
|
| 163 | - $response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' ); |
|
| 161 | + public function create_customer($args = array()) { |
|
| 162 | + $args = $this->generate_customer_request($args); |
|
| 163 | + $response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers'); |
|
| 164 | 164 | |
| 165 | - if ( ! empty( $response->error ) ) { |
|
| 166 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 165 | + if ( ! empty($response->error)) { |
|
| 166 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - $this->set_id( $response->id ); |
|
| 169 | + $this->set_id($response->id); |
|
| 170 | 170 | $this->clear_cache(); |
| 171 | - $this->set_customer_data( $response ); |
|
| 171 | + $this->set_customer_data($response); |
|
| 172 | 172 | |
| 173 | - if ( $this->get_user_id() ) { |
|
| 174 | - $this->update_id_in_meta( $response->id ); |
|
| 173 | + if ($this->get_user_id()) { |
|
| 174 | + $this->update_id_in_meta($response->id); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
| 177 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
| 178 | 178 | |
| 179 | 179 | return $response->id; |
| 180 | 180 | } |
@@ -189,30 +189,30 @@ discard block |
||
| 189 | 189 | * |
| 190 | 190 | * @throws WC_Stripe_Exception |
| 191 | 191 | */ |
| 192 | - public function update_customer( $args = array(), $is_retry = false ) { |
|
| 193 | - if ( empty( $this->get_id() ) ) { |
|
| 194 | - throw new WC_Stripe_Exception( 'id_required_to_update_user', __( 'Attempting to update a Stripe customer without a customer ID.', 'woocommerce-gateway-stripe' ) ); |
|
| 192 | + public function update_customer($args = array(), $is_retry = false) { |
|
| 193 | + if (empty($this->get_id())) { |
|
| 194 | + throw new WC_Stripe_Exception('id_required_to_update_user', __('Attempting to update a Stripe customer without a customer ID.', 'woocommerce-gateway-stripe')); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - $args = $this->generate_customer_request( $args ); |
|
| 198 | - $args = apply_filters( 'wc_stripe_update_customer_args', $args ); |
|
| 199 | - $response = WC_Stripe_API::request( $args, 'customers/' . $this->get_id() ); |
|
| 197 | + $args = $this->generate_customer_request($args); |
|
| 198 | + $args = apply_filters('wc_stripe_update_customer_args', $args); |
|
| 199 | + $response = WC_Stripe_API::request($args, 'customers/' . $this->get_id()); |
|
| 200 | 200 | |
| 201 | - if ( ! empty( $response->error ) ) { |
|
| 202 | - if ( $this->is_no_such_customer_error( $response->error ) && ! $is_retry ) { |
|
| 201 | + if ( ! empty($response->error)) { |
|
| 202 | + if ($this->is_no_such_customer_error($response->error) && ! $is_retry) { |
|
| 203 | 203 | // This can happen when switching the main Stripe account or importing users from another site. |
| 204 | 204 | // If not already retrying, recreate the customer and then try updating it again. |
| 205 | 205 | $this->recreate_customer(); |
| 206 | - return $this->update_customer( $args, true ); |
|
| 206 | + return $this->update_customer($args, true); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 209 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | $this->clear_cache(); |
| 213 | - $this->set_customer_data( $response ); |
|
| 213 | + $this->set_customer_data($response); |
|
| 214 | 214 | |
| 215 | - do_action( 'woocommerce_stripe_update_customer', $args, $response ); |
|
| 215 | + do_action('woocommerce_stripe_update_customer', $args, $response); |
|
| 216 | 216 | |
| 217 | 217 | return $this->get_id(); |
| 218 | 218 | } |
@@ -224,11 +224,11 @@ discard block |
||
| 224 | 224 | * @since 4.1.2 |
| 225 | 225 | * @param array $error |
| 226 | 226 | */ |
| 227 | - public function is_no_such_customer_error( $error ) { |
|
| 227 | + public function is_no_such_customer_error($error) { |
|
| 228 | 228 | return ( |
| 229 | 229 | $error && |
| 230 | 230 | 'invalid_request_error' === $error->type && |
| 231 | - preg_match( '/No such customer/i', $error->message ) |
|
| 231 | + preg_match('/No such customer/i', $error->message) |
|
| 232 | 232 | ); |
| 233 | 233 | } |
| 234 | 234 | |
@@ -240,11 +240,11 @@ discard block |
||
| 240 | 240 | * @param array $error |
| 241 | 241 | * @return bool |
| 242 | 242 | */ |
| 243 | - public function is_source_already_attached_error( $error ) { |
|
| 243 | + public function is_source_already_attached_error($error) { |
|
| 244 | 244 | return ( |
| 245 | 245 | $error && |
| 246 | 246 | 'invalid_request_error' === $error->type && |
| 247 | - preg_match( '/already been attached to a customer/i', $error->message ) |
|
| 247 | + preg_match('/already been attached to a customer/i', $error->message) |
|
| 248 | 248 | ); |
| 249 | 249 | } |
| 250 | 250 | |
@@ -253,56 +253,56 @@ discard block |
||
| 253 | 253 | * @param string $source_id |
| 254 | 254 | * @return WP_Error|int |
| 255 | 255 | */ |
| 256 | - public function add_source( $source_id ) { |
|
| 257 | - $response = $this->attach_source( $source_id ); |
|
| 258 | - if ( is_wp_error( $response ) ) { |
|
| 256 | + public function add_source($source_id) { |
|
| 257 | + $response = $this->attach_source($source_id); |
|
| 258 | + if (is_wp_error($response)) { |
|
| 259 | 259 | return $response; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | // Add token to WooCommerce. |
| 263 | 263 | $wc_token = false; |
| 264 | 264 | |
| 265 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
| 266 | - if ( ! empty( $response->type ) ) { |
|
| 267 | - switch ( $response->type ) { |
|
| 265 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
| 266 | + if ( ! empty($response->type)) { |
|
| 267 | + switch ($response->type) { |
|
| 268 | 268 | case 'alipay': |
| 269 | 269 | break; |
| 270 | 270 | case 'sepa_debit': |
| 271 | 271 | $wc_token = new WC_Payment_Token_SEPA(); |
| 272 | - $wc_token->set_token( $response->id ); |
|
| 273 | - $wc_token->set_gateway_id( 'stripe_sepa' ); |
|
| 274 | - $wc_token->set_last4( $response->sepa_debit->last4 ); |
|
| 272 | + $wc_token->set_token($response->id); |
|
| 273 | + $wc_token->set_gateway_id('stripe_sepa'); |
|
| 274 | + $wc_token->set_last4($response->sepa_debit->last4); |
|
| 275 | 275 | break; |
| 276 | 276 | default: |
| 277 | - if ( 'source' === $response->object && 'card' === $response->type ) { |
|
| 277 | + if ('source' === $response->object && 'card' === $response->type) { |
|
| 278 | 278 | $wc_token = new WC_Payment_Token_CC(); |
| 279 | - $wc_token->set_token( $response->id ); |
|
| 280 | - $wc_token->set_gateway_id( 'stripe' ); |
|
| 281 | - $wc_token->set_card_type( strtolower( $response->card->brand ) ); |
|
| 282 | - $wc_token->set_last4( $response->card->last4 ); |
|
| 283 | - $wc_token->set_expiry_month( $response->card->exp_month ); |
|
| 284 | - $wc_token->set_expiry_year( $response->card->exp_year ); |
|
| 279 | + $wc_token->set_token($response->id); |
|
| 280 | + $wc_token->set_gateway_id('stripe'); |
|
| 281 | + $wc_token->set_card_type(strtolower($response->card->brand)); |
|
| 282 | + $wc_token->set_last4($response->card->last4); |
|
| 283 | + $wc_token->set_expiry_month($response->card->exp_month); |
|
| 284 | + $wc_token->set_expiry_year($response->card->exp_year); |
|
| 285 | 285 | } |
| 286 | 286 | break; |
| 287 | 287 | } |
| 288 | 288 | } else { |
| 289 | 289 | // Legacy. |
| 290 | 290 | $wc_token = new WC_Payment_Token_CC(); |
| 291 | - $wc_token->set_token( $response->id ); |
|
| 292 | - $wc_token->set_gateway_id( 'stripe' ); |
|
| 293 | - $wc_token->set_card_type( strtolower( $response->brand ) ); |
|
| 294 | - $wc_token->set_last4( $response->last4 ); |
|
| 295 | - $wc_token->set_expiry_month( $response->exp_month ); |
|
| 296 | - $wc_token->set_expiry_year( $response->exp_year ); |
|
| 291 | + $wc_token->set_token($response->id); |
|
| 292 | + $wc_token->set_gateway_id('stripe'); |
|
| 293 | + $wc_token->set_card_type(strtolower($response->brand)); |
|
| 294 | + $wc_token->set_last4($response->last4); |
|
| 295 | + $wc_token->set_expiry_month($response->exp_month); |
|
| 296 | + $wc_token->set_expiry_year($response->exp_year); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - $wc_token->set_user_id( $this->get_user_id() ); |
|
| 299 | + $wc_token->set_user_id($this->get_user_id()); |
|
| 300 | 300 | $wc_token->save(); |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | $this->clear_cache(); |
| 304 | 304 | |
| 305 | - do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id ); |
|
| 305 | + do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id); |
|
| 306 | 306 | |
| 307 | 307 | return $response->id; |
| 308 | 308 | } |
@@ -313,9 +313,9 @@ discard block |
||
| 313 | 313 | * @param string $source_id The ID of the new source. |
| 314 | 314 | * @return object|WP_Error Either a source object, or a WP error. |
| 315 | 315 | */ |
| 316 | - public function attach_source( $source_id ) { |
|
| 317 | - if ( ! $this->get_id() ) { |
|
| 318 | - $this->set_id( $this->create_customer() ); |
|
| 316 | + public function attach_source($source_id) { |
|
| 317 | + if ( ! $this->get_id()) { |
|
| 318 | + $this->set_id($this->create_customer()); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | $response = WC_Stripe_API::request( |
@@ -325,20 +325,20 @@ discard block |
||
| 325 | 325 | 'customers/' . $this->get_id() . '/sources' |
| 326 | 326 | ); |
| 327 | 327 | |
| 328 | - if ( ! empty( $response->error ) ) { |
|
| 328 | + if ( ! empty($response->error)) { |
|
| 329 | 329 | // It is possible the WC user once was linked to a customer on Stripe |
| 330 | 330 | // but no longer exists. Instead of failing, lets try to create a |
| 331 | 331 | // new customer. |
| 332 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
| 332 | + if ($this->is_no_such_customer_error($response->error)) { |
|
| 333 | 333 | $this->recreate_customer(); |
| 334 | - return $this->attach_source( $source_id ); |
|
| 335 | - } elseif( $this->is_source_already_attached_error( $response->error ) ) { |
|
| 336 | - return WC_Stripe_API::request( array(), 'sources/' . $source_id, 'GET' ); |
|
| 334 | + return $this->attach_source($source_id); |
|
| 335 | + } elseif ($this->is_source_already_attached_error($response->error)) { |
|
| 336 | + return WC_Stripe_API::request(array(), 'sources/' . $source_id, 'GET'); |
|
| 337 | 337 | } else { |
| 338 | 338 | return $response; |
| 339 | 339 | } |
| 340 | - } elseif ( empty( $response->id ) ) { |
|
| 341 | - return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) ); |
|
| 340 | + } elseif (empty($response->id)) { |
|
| 341 | + return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe')); |
|
| 342 | 342 | } else { |
| 343 | 343 | return $response; |
| 344 | 344 | } |
@@ -351,13 +351,13 @@ discard block |
||
| 351 | 351 | * @return array |
| 352 | 352 | */ |
| 353 | 353 | public function get_sources() { |
| 354 | - if ( ! $this->get_id() ) { |
|
| 354 | + if ( ! $this->get_id()) { |
|
| 355 | 355 | return array(); |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | - $sources = get_transient( 'stripe_sources_' . $this->get_id() ); |
|
| 358 | + $sources = get_transient('stripe_sources_' . $this->get_id()); |
|
| 359 | 359 | |
| 360 | - if ( false === $sources ) { |
|
| 360 | + if (false === $sources) { |
|
| 361 | 361 | $response = WC_Stripe_API::request( |
| 362 | 362 | array( |
| 363 | 363 | 'limit' => 100, |
@@ -366,35 +366,35 @@ discard block |
||
| 366 | 366 | 'GET' |
| 367 | 367 | ); |
| 368 | 368 | |
| 369 | - if ( ! empty( $response->error ) ) { |
|
| 369 | + if ( ! empty($response->error)) { |
|
| 370 | 370 | return array(); |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - if ( is_array( $response->data ) ) { |
|
| 373 | + if (is_array($response->data)) { |
|
| 374 | 374 | $sources = $response->data; |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - set_transient( 'stripe_sources_' . $this->get_id(), $sources, DAY_IN_SECONDS ); |
|
| 377 | + set_transient('stripe_sources_' . $this->get_id(), $sources, DAY_IN_SECONDS); |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | - return empty( $sources ) ? array() : $sources; |
|
| 380 | + return empty($sources) ? array() : $sources; |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | /** |
| 384 | 384 | * Delete a source from stripe. |
| 385 | 385 | * @param string $source_id |
| 386 | 386 | */ |
| 387 | - public function delete_source( $source_id ) { |
|
| 388 | - if ( ! $this->get_id() ) { |
|
| 387 | + public function delete_source($source_id) { |
|
| 388 | + if ( ! $this->get_id()) { |
|
| 389 | 389 | return false; |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' ); |
|
| 392 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE'); |
|
| 393 | 393 | |
| 394 | 394 | $this->clear_cache(); |
| 395 | 395 | |
| 396 | - if ( empty( $response->error ) ) { |
|
| 397 | - do_action( 'wc_stripe_delete_source', $this->get_id(), $response ); |
|
| 396 | + if (empty($response->error)) { |
|
| 397 | + do_action('wc_stripe_delete_source', $this->get_id(), $response); |
|
| 398 | 398 | |
| 399 | 399 | return true; |
| 400 | 400 | } |
@@ -406,10 +406,10 @@ discard block |
||
| 406 | 406 | * Set default source in Stripe |
| 407 | 407 | * @param string $source_id |
| 408 | 408 | */ |
| 409 | - public function set_default_source( $source_id ) { |
|
| 409 | + public function set_default_source($source_id) { |
|
| 410 | 410 | $response = WC_Stripe_API::request( |
| 411 | 411 | array( |
| 412 | - 'default_source' => sanitize_text_field( $source_id ), |
|
| 412 | + 'default_source' => sanitize_text_field($source_id), |
|
| 413 | 413 | ), |
| 414 | 414 | 'customers/' . $this->get_id(), |
| 415 | 415 | 'POST' |
@@ -417,8 +417,8 @@ discard block |
||
| 417 | 417 | |
| 418 | 418 | $this->clear_cache(); |
| 419 | 419 | |
| 420 | - if ( empty( $response->error ) ) { |
|
| 421 | - do_action( 'wc_stripe_set_default_source', $this->get_id(), $response ); |
|
| 420 | + if (empty($response->error)) { |
|
| 421 | + do_action('wc_stripe_set_default_source', $this->get_id(), $response); |
|
| 422 | 422 | |
| 423 | 423 | return true; |
| 424 | 424 | } |
@@ -430,8 +430,8 @@ discard block |
||
| 430 | 430 | * Deletes caches for this users cards. |
| 431 | 431 | */ |
| 432 | 432 | public function clear_cache() { |
| 433 | - delete_transient( 'stripe_sources_' . $this->get_id() ); |
|
| 434 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
| 433 | + delete_transient('stripe_sources_' . $this->get_id()); |
|
| 434 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
| 435 | 435 | $this->customer_data = array(); |
| 436 | 436 | } |
| 437 | 437 | |
@@ -441,8 +441,8 @@ discard block |
||
| 441 | 441 | * @param int $user_id The ID of the WordPress user. |
| 442 | 442 | * @return string|bool Either the Stripe ID or false. |
| 443 | 443 | */ |
| 444 | - public function get_id_from_meta( $user_id ) { |
|
| 445 | - return get_user_option( '_stripe_customer_id', $user_id ); |
|
| 444 | + public function get_id_from_meta($user_id) { |
|
| 445 | + return get_user_option('_stripe_customer_id', $user_id); |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | /** |
@@ -450,15 +450,15 @@ discard block |
||
| 450 | 450 | * |
| 451 | 451 | * @param string $id The Stripe customer ID. |
| 452 | 452 | */ |
| 453 | - public function update_id_in_meta( $id ) { |
|
| 454 | - update_user_option( $this->get_user_id(), '_stripe_customer_id', $id, false ); |
|
| 453 | + public function update_id_in_meta($id) { |
|
| 454 | + update_user_option($this->get_user_id(), '_stripe_customer_id', $id, false); |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | /** |
| 458 | 458 | * Deletes the user ID from the meta table with the right key. |
| 459 | 459 | */ |
| 460 | 460 | public function delete_id_from_meta() { |
| 461 | - delete_user_option( $this->get_user_id(), '_stripe_customer_id', false ); |
|
| 461 | + delete_user_option($this->get_user_id(), '_stripe_customer_id', false); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | /** |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -23,8 +23,8 @@ discard block |
||
| 23 | 23 | * @since 4.2.0 |
| 24 | 24 | */ |
| 25 | 25 | public function __construct() { |
| 26 | - add_action( 'wc_ajax_wc_stripe_verify_intent', array( $this, 'verify_intent' ) ); |
|
| 27 | - add_action( 'wc_ajax_wc_stripe_create_setup_intent', array( $this, 'create_setup_intent' ) ); |
|
| 26 | + add_action('wc_ajax_wc_stripe_verify_intent', array($this, 'verify_intent')); |
|
| 27 | + add_action('wc_ajax_wc_stripe_create_setup_intent', array($this, 'create_setup_intent')); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -34,8 +34,8 @@ discard block |
||
| 34 | 34 | * @return WC_Gateway_Stripe |
| 35 | 35 | */ |
| 36 | 36 | protected function get_gateway() { |
| 37 | - if ( ! isset( $this->gateway ) ) { |
|
| 38 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) { |
|
| 37 | + if ( ! isset($this->gateway)) { |
|
| 38 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) { |
|
| 39 | 39 | $class_name = 'WC_Stripe_Subs_Compat'; |
| 40 | 40 | } else { |
| 41 | 41 | $class_name = 'WC_Gateway_Stripe'; |
@@ -55,21 +55,21 @@ discard block |
||
| 55 | 55 | * @return WC_Order |
| 56 | 56 | */ |
| 57 | 57 | protected function get_order_from_request() { |
| 58 | - if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['nonce'] ), 'wc_stripe_confirm_pi' ) ) { |
|
| 59 | - throw new WC_Stripe_Exception( 'missing-nonce', __( 'CSRF verification failed.', 'woocommerce-gateway-stripe' ) ); |
|
| 58 | + if ( ! isset($_GET['nonce']) || ! wp_verify_nonce(sanitize_key($_GET['nonce']), 'wc_stripe_confirm_pi')) { |
|
| 59 | + throw new WC_Stripe_Exception('missing-nonce', __('CSRF verification failed.', 'woocommerce-gateway-stripe')); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | // Load the order ID. |
| 63 | 63 | $order_id = null; |
| 64 | - if ( isset( $_GET['order'] ) && absint( $_GET['order'] ) ) { |
|
| 65 | - $order_id = absint( $_GET['order'] ); |
|
| 64 | + if (isset($_GET['order']) && absint($_GET['order'])) { |
|
| 65 | + $order_id = absint($_GET['order']); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // Retrieve the order. |
| 69 | - $order = wc_get_order( $order_id ); |
|
| 69 | + $order = wc_get_order($order_id); |
|
| 70 | 70 | |
| 71 | - if ( ! $order ) { |
|
| 72 | - throw new WC_Stripe_Exception( 'missing-order', __( 'Missing order ID for payment confirmation', 'woocommerce-gateway-stripe' ) ); |
|
| 71 | + if ( ! $order) { |
|
| 72 | + throw new WC_Stripe_Exception('missing-order', __('Missing order ID for payment confirmation', 'woocommerce-gateway-stripe')); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | return $order; |
@@ -87,32 +87,32 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | try { |
| 89 | 89 | $order = $this->get_order_from_request(); |
| 90 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 90 | + } catch (WC_Stripe_Exception $e) { |
|
| 91 | 91 | /* translators: Error message text */ |
| 92 | - $message = sprintf( __( 'Payment verification error: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ); |
|
| 93 | - wc_add_notice( esc_html( $message ), 'error' ); |
|
| 92 | + $message = sprintf(__('Payment verification error: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage()); |
|
| 93 | + wc_add_notice(esc_html($message), 'error'); |
|
| 94 | 94 | |
| 95 | 95 | $redirect_url = $woocommerce->cart->is_empty() |
| 96 | - ? get_permalink( wc_get_page_id( 'shop' ) ) |
|
| 96 | + ? get_permalink(wc_get_page_id('shop')) |
|
| 97 | 97 | : wc_get_checkout_url(); |
| 98 | 98 | |
| 99 | - $this->handle_error( $e, $redirect_url ); |
|
| 99 | + $this->handle_error($e, $redirect_url); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | try { |
| 103 | - $gateway->verify_intent_after_checkout( $order ); |
|
| 103 | + $gateway->verify_intent_after_checkout($order); |
|
| 104 | 104 | |
| 105 | - if ( ! isset( $_GET['is_ajax'] ) ) { |
|
| 106 | - $redirect_url = isset( $_GET['redirect_to'] ) // wpcs: csrf ok. |
|
| 107 | - ? esc_url_raw( wp_unslash( $_GET['redirect_to'] ) ) // wpcs: csrf ok. |
|
| 108 | - : $gateway->get_return_url( $order ); |
|
| 105 | + if ( ! isset($_GET['is_ajax'])) { |
|
| 106 | + $redirect_url = isset($_GET['redirect_to']) // wpcs: csrf ok. |
|
| 107 | + ? esc_url_raw(wp_unslash($_GET['redirect_to'])) // wpcs: csrf ok. |
|
| 108 | + : $gateway->get_return_url($order); |
|
| 109 | 109 | |
| 110 | - wp_safe_redirect( $redirect_url ); |
|
| 110 | + wp_safe_redirect($redirect_url); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | exit; |
| 114 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 115 | - $this->handle_error( $e, $gateway->get_return_url( $order ) ); |
|
| 114 | + } catch (WC_Stripe_Exception $e) { |
|
| 115 | + $this->handle_error($e, $gateway->get_return_url($order)); |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | |
@@ -123,17 +123,17 @@ discard block |
||
| 123 | 123 | * @param WC_Stripe_Exception $e The exception that was thrown. |
| 124 | 124 | * @param string $redirect_url An URL to use if a redirect is needed. |
| 125 | 125 | */ |
| 126 | - protected function handle_error( $e, $redirect_url ) { |
|
| 126 | + protected function handle_error($e, $redirect_url) { |
|
| 127 | 127 | // Log the exception before redirecting. |
| 128 | - $message = sprintf( 'PaymentIntent verification exception: %s', $e->getLocalizedMessage() ); |
|
| 129 | - WC_Stripe_Logger::log( $message ); |
|
| 128 | + $message = sprintf('PaymentIntent verification exception: %s', $e->getLocalizedMessage()); |
|
| 129 | + WC_Stripe_Logger::log($message); |
|
| 130 | 130 | |
| 131 | 131 | // `is_ajax` is only used for PI error reporting, a response is not expected. |
| 132 | - if ( isset( $_GET['is_ajax'] ) ) { |
|
| 132 | + if (isset($_GET['is_ajax'])) { |
|
| 133 | 133 | exit; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - wp_safe_redirect( $redirect_url ); |
|
| 136 | + wp_safe_redirect($redirect_url); |
|
| 137 | 137 | exit; |
| 138 | 138 | } |
| 139 | 139 | |
@@ -143,31 +143,31 @@ discard block |
||
| 143 | 143 | public function create_setup_intent() { |
| 144 | 144 | if ( |
| 145 | 145 | ! is_user_logged_in() |
| 146 | - || ! isset( $_POST['stripe_source_id'] ) |
|
| 147 | - || ! isset( $_POST['nonce'] ) |
|
| 146 | + || ! isset($_POST['stripe_source_id']) |
|
| 147 | + || ! isset($_POST['nonce']) |
|
| 148 | 148 | ) { |
| 149 | 149 | return; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | try { |
| 153 | - $source_id = wc_clean( $_POST['stripe_source_id'] ); |
|
| 153 | + $source_id = wc_clean($_POST['stripe_source_id']); |
|
| 154 | 154 | |
| 155 | 155 | // 1. Verify. |
| 156 | 156 | if ( |
| 157 | - ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'wc_stripe_create_si' ) |
|
| 158 | - || ! preg_match( '/^src_.*$/', $source_id ) |
|
| 157 | + ! wp_verify_nonce(sanitize_key($_POST['nonce']), 'wc_stripe_create_si') |
|
| 158 | + || ! preg_match('/^src_.*$/', $source_id) |
|
| 159 | 159 | ) { |
| 160 | - throw new Exception( __( 'Unable to verify your request. Please reload the page and try again.', 'woocommerce-gateway-stripe' ) ); |
|
| 160 | + throw new Exception(__('Unable to verify your request. Please reload the page and try again.', 'woocommerce-gateway-stripe')); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | |
| 164 | 164 | // 2. Load the customer ID (and create a customer eventually). |
| 165 | - $customer = new WC_Stripe_Customer( wp_get_current_user()->ID ); |
|
| 165 | + $customer = new WC_Stripe_Customer(wp_get_current_user()->ID); |
|
| 166 | 166 | |
| 167 | 167 | // 3. Attach the source to the customer (Setup Intents require that). |
| 168 | - $source_object = $customer->attach_source( $source_id ); |
|
| 169 | - if ( is_wp_error( $source_object ) ) { |
|
| 170 | - throw new Exception( $source_object->get_error_message() ); |
|
| 168 | + $source_object = $customer->attach_source($source_id); |
|
| 169 | + if (is_wp_error($source_object)) { |
|
| 170 | + throw new Exception($source_object->get_error_message()); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | // 4. Generate the setup intent |
@@ -180,28 +180,28 @@ discard block |
||
| 180 | 180 | 'setup_intents' |
| 181 | 181 | ); |
| 182 | 182 | |
| 183 | - if ( $setup_intent->error ) { |
|
| 184 | - $error_response_message = print_r( $setup_intent, true ); |
|
| 183 | + if ($setup_intent->error) { |
|
| 184 | + $error_response_message = print_r($setup_intent, true); |
|
| 185 | 185 | WC_Stripe_Logger::log("Failed create Setup Intent while saving a card."); |
| 186 | 186 | WC_Stripe_Logger::log("Response: $error_response_message"); |
| 187 | - throw new Exception( __( 'Your card could not be set up for future usage.', 'woocommerce-gateway-stripe' ) ); |
|
| 187 | + throw new Exception(__('Your card could not be set up for future usage.', 'woocommerce-gateway-stripe')); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | // 5. Respond. |
| 191 | - if ( 'requires_action' === $setup_intent->status ) { |
|
| 191 | + if ('requires_action' === $setup_intent->status) { |
|
| 192 | 192 | $response = [ |
| 193 | 193 | 'status' => 'requires_action', |
| 194 | 194 | 'client_secret' => $setup_intent->client_secret, |
| 195 | 195 | ]; |
| 196 | - } elseif ( 'requires_payment_method' === $setup_intent->status |
|
| 196 | + } elseif ('requires_payment_method' === $setup_intent->status |
|
| 197 | 197 | || 'requires_confirmation' === $setup_intent->status |
| 198 | - || 'canceled' === $setup_intent->status ) { |
|
| 198 | + || 'canceled' === $setup_intent->status) { |
|
| 199 | 199 | // These statuses should not be possible, as such we return an error. |
| 200 | 200 | $response = [ |
| 201 | 201 | 'status' => 'error', |
| 202 | 202 | 'error' => [ |
| 203 | 203 | 'type' => 'setup_intent_error', |
| 204 | - 'message' => __( 'Failed to save payment method.', 'woocommerce-gateway-stripe' ), |
|
| 204 | + 'message' => __('Failed to save payment method.', 'woocommerce-gateway-stripe'), |
|
| 205 | 205 | ], |
| 206 | 206 | ]; |
| 207 | 207 | } else { |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | 'status' => 'success', |
| 212 | 212 | ]; |
| 213 | 213 | } |
| 214 | - } catch ( Exception $e ) { |
|
| 214 | + } catch (Exception $e) { |
|
| 215 | 215 | $response = [ |
| 216 | 216 | 'status' => 'error', |
| 217 | 217 | 'error' => array( |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | ]; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - echo wp_json_encode( $response ); |
|
| 224 | + echo wp_json_encode($response); |
|
| 225 | 225 | exit; |
| 226 | 226 | } |
| 227 | 227 | } |