@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -15,21 +15,21 @@ discard block |
||
| 15 | 15 | public function __construct() { |
| 16 | 16 | parent::__construct(); |
| 17 | 17 | |
| 18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
| 19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
| 20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
| 21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
| 22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
| 23 | - add_action( 'wc_stripe_cards_payment_fields', array( $this, 'display_update_subs_payment_checkout' ) ); |
|
| 24 | - add_action( 'wc_stripe_add_payment_method_' . $this->id . '_success', array( $this, 'handle_add_payment_method_success' ), 10, 2 ); |
|
| 18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
| 19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
| 20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
| 21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
| 22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
| 23 | + add_action('wc_stripe_cards_payment_fields', array($this, 'display_update_subs_payment_checkout')); |
|
| 24 | + add_action('wc_stripe_add_payment_method_' . $this->id . '_success', array($this, 'handle_add_payment_method_success'), 10, 2); |
|
| 25 | 25 | |
| 26 | 26 | // display the credit card used for a subscription in the "My Subscriptions" table |
| 27 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
| 27 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
| 28 | 28 | |
| 29 | 29 | // allow store managers to manually set Stripe as the payment method on a subscription |
| 30 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
| 31 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
| 32 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
| 30 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
| 31 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
| 32 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
| 33 | 33 | |
| 34 | 34 | /* |
| 35 | 35 | * WC subscriptions hooks into the "template_redirect" hook with priority 100. |
@@ -37,8 +37,8 @@ discard block |
||
| 37 | 37 | * See: https://github.com/woocommerce/woocommerce-subscriptions/blob/99a75687e109b64cbc07af6e5518458a6305f366/includes/class-wcs-cart-renewal.php#L165 |
| 38 | 38 | * If we are in the "You just need to authorize SCA" flow, we don't want that redirection to happen. |
| 39 | 39 | */ |
| 40 | - add_action( 'template_redirect', array( $this, 'remove_order_pay_var' ), 99 ); |
|
| 41 | - add_action( 'template_redirect', array( $this, 'restore_order_pay_var' ), 101 ); |
|
| 40 | + add_action('template_redirect', array($this, 'remove_order_pay_var'), 99); |
|
| 41 | + add_action('template_redirect', array($this, 'restore_order_pay_var'), 101); |
|
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | * @since 4.0.0 |
| 50 | 50 | * @version 4.0.0 |
| 51 | 51 | */ |
| 52 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
| 53 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
| 52 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
| 53 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
| 54 | 54 | return false; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | * @param int $order_id |
| 63 | 63 | * @return boolean |
| 64 | 64 | */ |
| 65 | - public function has_subscription( $order_id ) { |
|
| 66 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
| 65 | + public function has_subscription($order_id) { |
|
| 66 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @return bool |
| 74 | 74 | */ |
| 75 | 75 | public function is_subs_change_payment() { |
| 76 | - return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) ); |
|
| 76 | + return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method'])); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function display_update_subs_payment_checkout() { |
| 86 | 86 | if ( |
| 87 | - apply_filters( 'wc_stripe_display_update_subs_payment_method_card_checkbox', true ) && |
|
| 88 | - wcs_user_has_subscription( get_current_user_id(), '', 'active' ) && |
|
| 87 | + apply_filters('wc_stripe_display_update_subs_payment_method_card_checkbox', true) && |
|
| 88 | + wcs_user_has_subscription(get_current_user_id(), '', 'active') && |
|
| 89 | 89 | is_add_payment_method_page() |
| 90 | 90 | ) { |
| 91 | 91 | printf( |
@@ -93,8 +93,8 @@ discard block |
||
| 93 | 93 | <input id="wc-%1$s-update-subs-payment-method-card" name="wc-%1$s-update-subs-payment-method-card" type="checkbox" value="true" style="width:auto;" /> |
| 94 | 94 | <label for="wc-%1$s-update-subs-payment-method-card" style="display:inline;">%2$s</label> |
| 95 | 95 | </p>', |
| 96 | - esc_attr( $this->id ), |
|
| 97 | - esc_html( apply_filters( 'wc_stripe_save_to_subs_text', __( 'Update the Payment Method used for all of my active subscriptions (optional).', 'woocommerce-gateway-stripe' ) ) ) |
|
| 96 | + esc_attr($this->id), |
|
| 97 | + esc_html(apply_filters('wc_stripe_save_to_subs_text', __('Update the Payment Method used for all of my active subscriptions (optional).', 'woocommerce-gateway-stripe'))) |
|
| 98 | 98 | ); |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -106,16 +106,16 @@ discard block |
||
| 106 | 106 | * @param string $source_id |
| 107 | 107 | * @param object $source_object |
| 108 | 108 | */ |
| 109 | - public function handle_add_payment_method_success( $source_id, $source_object ) { |
|
| 110 | - if ( isset( $_POST[ 'wc-' . $this->id . '-update-subs-payment-method-card' ] ) ) { |
|
| 109 | + public function handle_add_payment_method_success($source_id, $source_object) { |
|
| 110 | + if (isset($_POST['wc-' . $this->id . '-update-subs-payment-method-card'])) { |
|
| 111 | 111 | $all_subs = wcs_get_users_subscriptions(); |
| 112 | 112 | |
| 113 | - if ( ! empty( $all_subs ) ) { |
|
| 114 | - foreach ( $all_subs as $sub ) { |
|
| 115 | - if ( 'active' === $sub->get_status() ) { |
|
| 116 | - update_post_meta( $sub->get_id(), '_stripe_source_id', $source_id ); |
|
| 117 | - update_post_meta( $sub->get_id(), '_payment_method', $this->id ); |
|
| 118 | - update_post_meta( $sub->get_id(), '_payment_method_title', $this->method_title ); |
|
| 113 | + if ( ! empty($all_subs)) { |
|
| 114 | + foreach ($all_subs as $sub) { |
|
| 115 | + if ('active' === $sub->get_status()) { |
|
| 116 | + update_post_meta($sub->get_id(), '_stripe_source_id', $source_id); |
|
| 117 | + update_post_meta($sub->get_id(), '_payment_method', $this->id); |
|
| 118 | + update_post_meta($sub->get_id(), '_payment_method_title', $this->method_title); |
|
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | } |
@@ -129,24 +129,24 @@ discard block |
||
| 129 | 129 | * @since 4.1.11 Remove 3DS check as it is not needed. |
| 130 | 130 | * @param int $order_id |
| 131 | 131 | */ |
| 132 | - public function change_subs_payment_method( $order_id ) { |
|
| 132 | + public function change_subs_payment_method($order_id) { |
|
| 133 | 133 | try { |
| 134 | - $subscription = wc_get_order( $order_id ); |
|
| 135 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
| 134 | + $subscription = wc_get_order($order_id); |
|
| 135 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
| 136 | 136 | |
| 137 | - $this->maybe_disallow_prepaid_card( $prepared_source ); |
|
| 138 | - $this->check_source( $prepared_source ); |
|
| 139 | - $this->save_source_to_order( $subscription, $prepared_source ); |
|
| 137 | + $this->maybe_disallow_prepaid_card($prepared_source); |
|
| 138 | + $this->check_source($prepared_source); |
|
| 139 | + $this->save_source_to_order($subscription, $prepared_source); |
|
| 140 | 140 | |
| 141 | - do_action( 'wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source ); |
|
| 141 | + do_action('wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source); |
|
| 142 | 142 | |
| 143 | 143 | return array( |
| 144 | 144 | 'result' => 'success', |
| 145 | - 'redirect' => $this->get_return_url( $subscription ), |
|
| 145 | + 'redirect' => $this->get_return_url($subscription), |
|
| 146 | 146 | ); |
| 147 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 148 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 149 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 147 | + } catch (WC_Stripe_Exception $e) { |
|
| 148 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 149 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | |
@@ -155,16 +155,16 @@ discard block |
||
| 155 | 155 | * @param int $order_id |
| 156 | 156 | * @return array |
| 157 | 157 | */ |
| 158 | - public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) { |
|
| 159 | - if ( $this->has_subscription( $order_id ) ) { |
|
| 160 | - if ( $this->is_subs_change_payment() ) { |
|
| 161 | - return $this->change_subs_payment_method( $order_id ); |
|
| 158 | + public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) { |
|
| 159 | + if ($this->has_subscription($order_id)) { |
|
| 160 | + if ($this->is_subs_change_payment()) { |
|
| 161 | + return $this->change_subs_payment_method($order_id); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // Regular payment with force customer enabled |
| 165 | - return parent::process_payment( $order_id, $retry, true, $previous_error ); |
|
| 165 | + return parent::process_payment($order_id, $retry, true, $previous_error); |
|
| 166 | 166 | } else { |
| 167 | - return parent::process_payment( $order_id, $retry, $force_save_source, $previous_error ); |
|
| 167 | + return parent::process_payment($order_id, $retry, $force_save_source, $previous_error); |
|
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
@@ -176,11 +176,11 @@ discard block |
||
| 176 | 176 | * @param object $prepared_source The source that is used for the payment. |
| 177 | 177 | * @return array The arguments for the request. |
| 178 | 178 | */ |
| 179 | - public function generate_create_intent_request( $order, $prepared_source ) { |
|
| 180 | - $request = parent::generate_create_intent_request( $order, $prepared_source ); |
|
| 179 | + public function generate_create_intent_request($order, $prepared_source) { |
|
| 180 | + $request = parent::generate_create_intent_request($order, $prepared_source); |
|
| 181 | 181 | |
| 182 | 182 | // Non-subscription orders do not need any additional parameters. |
| 183 | - if ( ! $this->has_subscription( $order ) ) { |
|
| 183 | + if ( ! $this->has_subscription($order)) { |
|
| 184 | 184 | return $request; |
| 185 | 185 | } |
| 186 | 186 | |
@@ -196,8 +196,8 @@ discard block |
||
| 196 | 196 | * @param $amount_to_charge float The amount to charge. |
| 197 | 197 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
| 198 | 198 | */ |
| 199 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
| 200 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true, false ); |
|
| 199 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
| 200 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true, false); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -211,143 +211,143 @@ discard block |
||
| 211 | 211 | * @param bool $retry Should we retry the process? |
| 212 | 212 | * @param object $previous_error |
| 213 | 213 | */ |
| 214 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) { |
|
| 214 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $retry = true, $previous_error) { |
|
| 215 | 215 | try { |
| 216 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 216 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 217 | 217 | /* translators: minimum amount */ |
| 218 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
| 218 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id(); |
|
| 221 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id(); |
|
| 222 | 222 | |
| 223 | - if ( isset( $_REQUEST['process_early_renewal'] ) ) { |
|
| 224 | - $response = parent::process_payment( $order_id, true, false, $previous_error ); |
|
| 223 | + if (isset($_REQUEST['process_early_renewal'])) { |
|
| 224 | + $response = parent::process_payment($order_id, true, false, $previous_error); |
|
| 225 | 225 | |
| 226 | - if( 'success' === $response['result'] && isset( $response['payment_intent_secret'] ) ) { |
|
| 226 | + if ('success' === $response['result'] && isset($response['payment_intent_secret'])) { |
|
| 227 | 227 | $verification_url = add_query_arg( |
| 228 | 228 | array( |
| 229 | 229 | 'order' => $order_id, |
| 230 | - 'nonce' => wp_create_nonce( 'wc_stripe_confirm_pi' ), |
|
| 231 | - 'redirect_to' => remove_query_arg( array( 'process_early_renewal', 'subscription_id', 'wcs_nonce' ) ), |
|
| 230 | + 'nonce' => wp_create_nonce('wc_stripe_confirm_pi'), |
|
| 231 | + 'redirect_to' => remove_query_arg(array('process_early_renewal', 'subscription_id', 'wcs_nonce')), |
|
| 232 | 232 | 'early_renewal' => true, |
| 233 | 233 | ), |
| 234 | - WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' ) |
|
| 234 | + WC_AJAX::get_endpoint('wc_stripe_verify_intent') |
|
| 235 | 235 | ); |
| 236 | 236 | |
| 237 | - echo wp_json_encode( array( |
|
| 237 | + echo wp_json_encode(array( |
|
| 238 | 238 | 'stripe_sca_required' => true, |
| 239 | 239 | 'intent_secret' => $response['payment_intent_secret'], |
| 240 | 240 | 'redirect_url' => $verification_url, |
| 241 | - ) ); |
|
| 241 | + )); |
|
| 242 | 242 | exit; |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | // Hijack all other redirects in order to do the redirection in JavaScript. |
| 246 | - add_action( 'wp_redirect', array( $this, 'redirect_after_early_renewal' ), 100 ); |
|
| 246 | + add_action('wp_redirect', array($this, 'redirect_after_early_renewal'), 100); |
|
| 247 | 247 | |
| 248 | 248 | return; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | // Check for an existing intent, which is associated with the order. |
| 252 | - if ( $this->has_authentication_already_failed( $renewal_order ) ) { |
|
| 252 | + if ($this->has_authentication_already_failed($renewal_order)) { |
|
| 253 | 253 | return; |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | // Get source from order |
| 257 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
| 257 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
| 258 | 258 | $source_object = $prepared_source->source_object; |
| 259 | 259 | |
| 260 | - if ( ! $prepared_source->customer ) { |
|
| 261 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
| 260 | + if ( ! $prepared_source->customer) { |
|
| 261 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
| 264 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
| 265 | 265 | |
| 266 | 266 | /* If we're doing a retry and source is chargeable, we need to pass |
| 267 | 267 | * a different idempotency key and retry for success. |
| 268 | 268 | */ |
| 269 | - if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) { |
|
| 270 | - add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 ); |
|
| 269 | + if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) { |
|
| 270 | + add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - if ( ( $this->is_no_such_source_error( $previous_error ) || $this->is_no_linked_source_error( $previous_error ) ) && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
| 273 | + if (($this->is_no_such_source_error($previous_error) || $this->is_no_linked_source_error($previous_error)) && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
| 274 | 274 | // Passing empty source will charge customer default. |
| 275 | 275 | $prepared_source->source = ''; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - $this->lock_order_payment( $renewal_order ); |
|
| 278 | + $this->lock_order_payment($renewal_order); |
|
| 279 | 279 | |
| 280 | - $response = $this->create_and_confirm_intent_for_off_session( $renewal_order, $prepared_source, $amount ); |
|
| 281 | - $is_authentication_required = $this->is_authentication_required_for_payment( $response ); |
|
| 280 | + $response = $this->create_and_confirm_intent_for_off_session($renewal_order, $prepared_source, $amount); |
|
| 281 | + $is_authentication_required = $this->is_authentication_required_for_payment($response); |
|
| 282 | 282 | |
| 283 | 283 | // It's only a failed payment if it's an error and it's not of the type 'authentication_required'. |
| 284 | 284 | // If it's 'authentication_required', then we should email the user and ask them to authenticate. |
| 285 | - if ( ! empty( $response->error ) && ! $is_authentication_required ) { |
|
| 285 | + if ( ! empty($response->error) && ! $is_authentication_required) { |
|
| 286 | 286 | // We want to retry. |
| 287 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
| 288 | - if ( $retry ) { |
|
| 287 | + if ($this->is_retryable_error($response->error)) { |
|
| 288 | + if ($retry) { |
|
| 289 | 289 | // Don't do anymore retries after this. |
| 290 | - if ( 5 <= $this->retry_interval ) { |
|
| 291 | - return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error ); |
|
| 290 | + if (5 <= $this->retry_interval) { |
|
| 291 | + return $this->process_subscription_payment($amount, $renewal_order, false, $response->error); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - sleep( $this->retry_interval ); |
|
| 294 | + sleep($this->retry_interval); |
|
| 295 | 295 | |
| 296 | 296 | $this->retry_interval++; |
| 297 | 297 | |
| 298 | - return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error ); |
|
| 298 | + return $this->process_subscription_payment($amount, $renewal_order, true, $response->error); |
|
| 299 | 299 | } else { |
| 300 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
| 301 | - $renewal_order->add_order_note( $localized_message ); |
|
| 302 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 300 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
| 301 | + $renewal_order->add_order_note($localized_message); |
|
| 302 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 303 | 303 | } |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
| 307 | 307 | |
| 308 | - if ( 'card_error' === $response->error->type ) { |
|
| 309 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 308 | + if ('card_error' === $response->error->type) { |
|
| 309 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
| 310 | 310 | } else { |
| 311 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 311 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - $renewal_order->add_order_note( $localized_message ); |
|
| 314 | + $renewal_order->add_order_note($localized_message); |
|
| 315 | 315 | |
| 316 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 316 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | // Either the charge was successfully captured, or it requires further authentication. |
| 320 | 320 | |
| 321 | - if ( $is_authentication_required ) { |
|
| 322 | - do_action( 'wc_gateway_stripe_process_payment_authentication_required', $renewal_order, $response ); |
|
| 321 | + if ($is_authentication_required) { |
|
| 322 | + do_action('wc_gateway_stripe_process_payment_authentication_required', $renewal_order, $response); |
|
| 323 | 323 | |
| 324 | - $error_message = __( 'This transaction requires authentication.', 'woocommerce-gateway-stripe' ); |
|
| 325 | - $renewal_order->add_order_note( $error_message ); |
|
| 324 | + $error_message = __('This transaction requires authentication.', 'woocommerce-gateway-stripe'); |
|
| 325 | + $renewal_order->add_order_note($error_message); |
|
| 326 | 326 | |
| 327 | - $charge = end( $response->error->payment_intent->charges->data ); |
|
| 327 | + $charge = end($response->error->payment_intent->charges->data); |
|
| 328 | 328 | $id = $charge->id; |
| 329 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id(); |
|
| 329 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id(); |
|
| 330 | 330 | |
| 331 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $id ) : $renewal_order->set_transaction_id( $id ); |
|
| 332 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe' ), $id ) ); |
|
| 333 | - if ( is_callable( array( $renewal_order, 'save' ) ) ) { |
|
| 331 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $id) : $renewal_order->set_transaction_id($id); |
|
| 332 | + $renewal_order->update_status('failed', sprintf(__('Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe'), $id)); |
|
| 333 | + if (is_callable(array($renewal_order, 'save'))) { |
|
| 334 | 334 | $renewal_order->save(); |
| 335 | 335 | } |
| 336 | 336 | } else { |
| 337 | 337 | // The charge was successfully captured |
| 338 | - do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order ); |
|
| 338 | + do_action('wc_gateway_stripe_process_payment', $response, $renewal_order); |
|
| 339 | 339 | |
| 340 | - $this->process_response( end( $response->charges->data ), $renewal_order ); |
|
| 340 | + $this->process_response(end($response->charges->data), $renewal_order); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - $this->unlock_order_payment( $renewal_order ); |
|
| 344 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 345 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 343 | + $this->unlock_order_payment($renewal_order); |
|
| 344 | + } catch (WC_Stripe_Exception $e) { |
|
| 345 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 346 | 346 | |
| 347 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order ); |
|
| 347 | + do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order); |
|
| 348 | 348 | |
| 349 | 349 | /* translators: error message */ |
| 350 | - $renewal_order->update_status( 'failed' ); |
|
| 350 | + $renewal_order->update_status('failed'); |
|
| 351 | 351 | } |
| 352 | 352 | } |
| 353 | 353 | |
@@ -357,24 +357,24 @@ discard block |
||
| 357 | 357 | * @since 3.1.0 |
| 358 | 358 | * @version 4.0.0 |
| 359 | 359 | */ |
| 360 | - public function save_source_to_order( $order, $source ) { |
|
| 361 | - parent::save_source_to_order( $order, $source ); |
|
| 360 | + public function save_source_to_order($order, $source) { |
|
| 361 | + parent::save_source_to_order($order, $source); |
|
| 362 | 362 | |
| 363 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 363 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 364 | 364 | |
| 365 | 365 | // Also store it on the subscriptions being purchased or paid for in the order |
| 366 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
| 367 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
| 368 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
| 369 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
| 366 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
| 367 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
| 368 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
| 369 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
| 370 | 370 | } else { |
| 371 | 371 | $subscriptions = array(); |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - foreach ( $subscriptions as $subscription ) { |
|
| 375 | - $subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id(); |
|
| 376 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
| 377 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
| 374 | + foreach ($subscriptions as $subscription) { |
|
| 375 | + $subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id(); |
|
| 376 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
| 377 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | |
@@ -382,26 +382,26 @@ discard block |
||
| 382 | 382 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
| 383 | 383 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 384 | 384 | */ |
| 385 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
| 386 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
| 387 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
| 385 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
| 386 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
| 387 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
| 388 | 388 | // For BW compat will remove in future |
| 389 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
| 389 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
| 390 | 390 | // delete payment intent ID |
| 391 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_intent_id' ); |
|
| 392 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
| 391 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_intent_id'); |
|
| 392 | + $this->delete_renewal_meta($resubscribe_order); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | /** |
| 396 | 396 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 397 | 397 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 398 | 398 | */ |
| 399 | - public function delete_renewal_meta( $renewal_order ) { |
|
| 400 | - WC_Stripe_Helper::delete_stripe_fee( $renewal_order ); |
|
| 401 | - WC_Stripe_Helper::delete_stripe_net( $renewal_order ); |
|
| 399 | + public function delete_renewal_meta($renewal_order) { |
|
| 400 | + WC_Stripe_Helper::delete_stripe_fee($renewal_order); |
|
| 401 | + WC_Stripe_Helper::delete_stripe_net($renewal_order); |
|
| 402 | 402 | |
| 403 | 403 | // delete payment intent ID |
| 404 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id() ), '_stripe_intent_id' ); |
|
| 404 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id()), '_stripe_intent_id'); |
|
| 405 | 405 | |
| 406 | 406 | return $renewal_order; |
| 407 | 407 | } |
@@ -415,14 +415,14 @@ discard block |
||
| 415 | 415 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
| 416 | 416 | * @return void |
| 417 | 417 | */ |
| 418 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
| 419 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 420 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
| 421 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
| 418 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
| 419 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 420 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
| 421 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
| 422 | 422 | |
| 423 | 423 | } else { |
| 424 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
| 425 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
| 424 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
| 425 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
| 426 | 426 | } |
| 427 | 427 | } |
| 428 | 428 | |
@@ -435,23 +435,23 @@ discard block |
||
| 435 | 435 | * @param WC_Subscription $subscription An instance of a subscription object |
| 436 | 436 | * @return array |
| 437 | 437 | */ |
| 438 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
| 439 | - $subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id(); |
|
| 440 | - $source_id = get_post_meta( $subscription_id, '_stripe_source_id', true ); |
|
| 438 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
| 439 | + $subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id(); |
|
| 440 | + $source_id = get_post_meta($subscription_id, '_stripe_source_id', true); |
|
| 441 | 441 | |
| 442 | 442 | // For BW compat will remove in future. |
| 443 | - if ( empty( $source_id ) ) { |
|
| 444 | - $source_id = get_post_meta( $subscription_id, '_stripe_card_id', true ); |
|
| 443 | + if (empty($source_id)) { |
|
| 444 | + $source_id = get_post_meta($subscription_id, '_stripe_card_id', true); |
|
| 445 | 445 | |
| 446 | 446 | // Take this opportunity to update the key name. |
| 447 | - update_post_meta( $subscription_id, '_stripe_source_id', $source_id ); |
|
| 448 | - delete_post_meta( $subscription_id, '_stripe_card_id', $source_id ); |
|
| 447 | + update_post_meta($subscription_id, '_stripe_source_id', $source_id); |
|
| 448 | + delete_post_meta($subscription_id, '_stripe_card_id', $source_id); |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - $payment_meta[ $this->id ] = array( |
|
| 451 | + $payment_meta[$this->id] = array( |
|
| 452 | 452 | 'post_meta' => array( |
| 453 | 453 | '_stripe_customer_id' => array( |
| 454 | - 'value' => get_post_meta( $subscription_id, '_stripe_customer_id', true ), |
|
| 454 | + 'value' => get_post_meta($subscription_id, '_stripe_customer_id', true), |
|
| 455 | 455 | 'label' => 'Stripe Customer ID', |
| 456 | 456 | ), |
| 457 | 457 | '_stripe_source_id' => array( |
@@ -474,22 +474,22 @@ discard block |
||
| 474 | 474 | * @param array $payment_meta associative array of meta data required for automatic payments |
| 475 | 475 | * @return array |
| 476 | 476 | */ |
| 477 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
| 478 | - if ( $this->id === $payment_method_id ) { |
|
| 477 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
| 478 | + if ($this->id === $payment_method_id) { |
|
| 479 | 479 | |
| 480 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
| 481 | - throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
| 482 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
| 483 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
| 480 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
| 481 | + throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
| 482 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
| 483 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | if ( |
| 487 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
| 488 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
| 489 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
| 490 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
| 487 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
| 488 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
| 489 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
| 490 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
| 491 | 491 | |
| 492 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
| 492 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
| 493 | 493 | } |
| 494 | 494 | } |
| 495 | 495 | } |
@@ -502,75 +502,75 @@ discard block |
||
| 502 | 502 | * @param WC_Subscription $subscription the subscription details |
| 503 | 503 | * @return string the subscription payment method |
| 504 | 504 | */ |
| 505 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
| 506 | - $customer_user = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->customer_user : $subscription->get_customer_id(); |
|
| 505 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
| 506 | + $customer_user = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->customer_user : $subscription->get_customer_id(); |
|
| 507 | 507 | |
| 508 | 508 | // bail for other payment methods |
| 509 | - if ( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
| 509 | + if ((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
| 510 | 510 | return $payment_method_to_display; |
| 511 | 511 | } |
| 512 | 512 | |
| 513 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 513 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 514 | 514 | |
| 515 | 515 | // For BW compat will remove in future. |
| 516 | - if ( empty( $stripe_source_id ) ) { |
|
| 517 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 516 | + if (empty($stripe_source_id)) { |
|
| 517 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 518 | 518 | |
| 519 | 519 | // Take this opportunity to update the key name. |
| 520 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 520 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | $stripe_customer = new WC_Stripe_Customer(); |
| 524 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
| 524 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
| 525 | 525 | |
| 526 | 526 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
| 527 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
| 527 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
| 528 | 528 | $user_id = $customer_user; |
| 529 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
| 530 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
| 529 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
| 530 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
| 531 | 531 | |
| 532 | 532 | // For BW compat will remove in future. |
| 533 | - if ( empty( $stripe_source_id ) ) { |
|
| 534 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
| 533 | + if (empty($stripe_source_id)) { |
|
| 534 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
| 535 | 535 | |
| 536 | 536 | // Take this opportunity to update the key name. |
| 537 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
| 537 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
| 538 | 538 | } |
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
| 542 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
| 543 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
| 544 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
| 542 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
| 543 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
| 544 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
| 545 | 545 | |
| 546 | 546 | // For BW compat will remove in future. |
| 547 | - if ( empty( $stripe_source_id ) ) { |
|
| 548 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
| 547 | + if (empty($stripe_source_id)) { |
|
| 548 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
| 549 | 549 | |
| 550 | 550 | // Take this opportunity to update the key name. |
| 551 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 551 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
| 552 | 552 | } |
| 553 | 553 | } |
| 554 | 554 | |
| 555 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 555 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 556 | 556 | |
| 557 | 557 | $sources = $stripe_customer->get_sources(); |
| 558 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 558 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 559 | 559 | |
| 560 | - if ( $sources ) { |
|
| 560 | + if ($sources) { |
|
| 561 | 561 | $card = false; |
| 562 | 562 | |
| 563 | - foreach ( $sources as $source ) { |
|
| 564 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
| 563 | + foreach ($sources as $source) { |
|
| 564 | + if (isset($source->type) && 'card' === $source->type) { |
|
| 565 | 565 | $card = $source->card; |
| 566 | - } elseif ( isset( $source->object ) && 'card' === $source->object ) { |
|
| 566 | + } elseif (isset($source->object) && 'card' === $source->object) { |
|
| 567 | 567 | $card = $source; |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | - if ( $source->id === $stripe_source_id ) { |
|
| 571 | - if ( $card ) { |
|
| 570 | + if ($source->id === $stripe_source_id) { |
|
| 571 | + if ($card) { |
|
| 572 | 572 | /* translators: 1) card brand 2) last 4 digits */ |
| 573 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
| 573 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | break; |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | */ |
| 588 | 588 | public function remove_order_pay_var() { |
| 589 | 589 | global $wp; |
| 590 | - if ( isset( $_GET['wc-stripe-confirmation'] ) ) { |
|
| 590 | + if (isset($_GET['wc-stripe-confirmation'])) { |
|
| 591 | 591 | $this->order_pay_var = $wp->query_vars['order-pay']; |
| 592 | 592 | $wp->query_vars['order-pay'] = null; |
| 593 | 593 | } |
@@ -598,7 +598,7 @@ discard block |
||
| 598 | 598 | */ |
| 599 | 599 | public function restore_order_pay_var() { |
| 600 | 600 | global $wp; |
| 601 | - if ( isset( $this->order_pay_var ) ) { |
|
| 601 | + if (isset($this->order_pay_var)) { |
|
| 602 | 602 | $wp->query_vars['order-pay'] = $this->order_pay_var; |
| 603 | 603 | } |
| 604 | 604 | } |
@@ -609,13 +609,13 @@ discard block |
||
| 609 | 609 | * @param WC_Order $renewal_order The renewal order. |
| 610 | 610 | * @return boolean |
| 611 | 611 | */ |
| 612 | - public function has_authentication_already_failed( $renewal_order ) { |
|
| 613 | - $existing_intent = $this->get_intent_from_order( $renewal_order ); |
|
| 612 | + public function has_authentication_already_failed($renewal_order) { |
|
| 613 | + $existing_intent = $this->get_intent_from_order($renewal_order); |
|
| 614 | 614 | |
| 615 | 615 | if ( |
| 616 | 616 | ! $existing_intent |
| 617 | 617 | || 'requires_payment_method' !== $existing_intent->status |
| 618 | - || empty( $existing_intent->last_payment_error ) |
|
| 618 | + || empty($existing_intent->last_payment_error) |
|
| 619 | 619 | || 'authentication_required' !== $existing_intent->last_payment_error->code |
| 620 | 620 | ) { |
| 621 | 621 | return false; |
@@ -629,21 +629,21 @@ discard block |
||
| 629 | 629 | * |
| 630 | 630 | * @param WC_Order $renewal_order The order that is being renewed. |
| 631 | 631 | */ |
| 632 | - do_action( 'wc_gateway_stripe_process_payment_authentication_required', $renewal_order ); |
|
| 632 | + do_action('wc_gateway_stripe_process_payment_authentication_required', $renewal_order); |
|
| 633 | 633 | |
| 634 | 634 | // Fail the payment attempt (order would be currently pending because of retry rules). |
| 635 | - $charge = end( $existing_intent->charges->data ); |
|
| 635 | + $charge = end($existing_intent->charges->data); |
|
| 636 | 636 | $charge_id = $charge->id; |
| 637 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe' ), $charge_id ) ); |
|
| 637 | + $renewal_order->update_status('failed', sprintf(__('Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe'), $charge_id)); |
|
| 638 | 638 | |
| 639 | 639 | return true; |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | - public function redirect_after_early_renewal( $url ) { |
|
| 643 | - echo wp_json_encode( array( |
|
| 642 | + public function redirect_after_early_renewal($url) { |
|
| 643 | + echo wp_json_encode(array( |
|
| 644 | 644 | 'stripe_sca_required' => false, |
| 645 | 645 | 'redirect_url' => $url, |
| 646 | - ) ); |
|
| 646 | + )); |
|
| 647 | 647 | exit; |
| 648 | 648 | } |
| 649 | 649 | } |
@@ -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 = sprintf( __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' ); |
|
| 90 | + $this->method_description = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys'); |
|
| 91 | 91 | $this->has_fields = true; |
| 92 | 92 | $this->supports = array( |
| 93 | 93 | 'products', |
@@ -114,37 +114,37 @@ 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 ); |
|
| 143 | - |
|
| 144 | - if ( WC_Stripe_Helper::is_pre_orders_exists() ) { |
|
| 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 | + |
|
| 144 | + if (WC_Stripe_Helper::is_pre_orders_exists()) { |
|
| 145 | 145 | $this->pre_orders = new WC_Stripe_Pre_Orders_Compat(); |
| 146 | 146 | |
| 147 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this->pre_orders, 'process_pre_order_release_payment' ) ); |
|
| 147 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this->pre_orders, 'process_pre_order_release_payment')); |
|
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * @return bool |
| 156 | 156 | */ |
| 157 | 157 | public function are_keys_set() { |
| 158 | - if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) { |
|
| 158 | + if (empty($this->secret_key) || empty($this->publishable_key)) { |
|
| 159 | 159 | return false; |
| 160 | 160 | } |
| 161 | 161 | |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * @since 4.0.2 |
| 169 | 169 | */ |
| 170 | 170 | public function is_available() { |
| 171 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
| 171 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
| 172 | 172 | return false; |
| 173 | 173 | } |
| 174 | 174 | |
@@ -182,13 +182,13 @@ discard block |
||
| 182 | 182 | * @param int $user_id The ID of the current user. |
| 183 | 183 | * @param string $load_address The address to load. |
| 184 | 184 | */ |
| 185 | - public function show_update_card_notice( $user_id, $load_address ) { |
|
| 186 | - if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods( $user_id ) || 'billing' !== $load_address ) { |
|
| 185 | + public function show_update_card_notice($user_id, $load_address) { |
|
| 186 | + if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods($user_id) || 'billing' !== $load_address) { |
|
| 187 | 187 | return; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /* translators: 1) Opening anchor tag 2) closing anchor tag */ |
| 191 | - 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' ); |
|
| 191 | + 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'); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -203,24 +203,24 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | $icons_str = ''; |
| 205 | 205 | |
| 206 | - $icons_str .= isset( $icons['visa'] ) ? $icons['visa'] : ''; |
|
| 207 | - $icons_str .= isset( $icons['amex'] ) ? $icons['amex'] : ''; |
|
| 208 | - $icons_str .= isset( $icons['mastercard'] ) ? $icons['mastercard'] : ''; |
|
| 206 | + $icons_str .= isset($icons['visa']) ? $icons['visa'] : ''; |
|
| 207 | + $icons_str .= isset($icons['amex']) ? $icons['amex'] : ''; |
|
| 208 | + $icons_str .= isset($icons['mastercard']) ? $icons['mastercard'] : ''; |
|
| 209 | 209 | |
| 210 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
| 211 | - $icons_str .= isset( $icons['discover'] ) ? $icons['discover'] : ''; |
|
| 212 | - $icons_str .= isset( $icons['jcb'] ) ? $icons['jcb'] : ''; |
|
| 213 | - $icons_str .= isset( $icons['diners'] ) ? $icons['diners'] : ''; |
|
| 210 | + if ('USD' === get_woocommerce_currency()) { |
|
| 211 | + $icons_str .= isset($icons['discover']) ? $icons['discover'] : ''; |
|
| 212 | + $icons_str .= isset($icons['jcb']) ? $icons['jcb'] : ''; |
|
| 213 | + $icons_str .= isset($icons['diners']) ? $icons['diners'] : ''; |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 216 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
| 220 | 220 | * Initialise Gateway Settings Form Fields |
| 221 | 221 | */ |
| 222 | 222 | public function init_form_fields() { |
| 223 | - $this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' ); |
|
| 223 | + $this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php'); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -228,27 +228,27 @@ discard block |
||
| 228 | 228 | */ |
| 229 | 229 | public function payment_fields() { |
| 230 | 230 | $user = wp_get_current_user(); |
| 231 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
| 231 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
| 232 | 232 | $total = WC()->cart->total; |
| 233 | 233 | $user_email = ''; |
| 234 | 234 | $description = $this->get_description(); |
| 235 | - $description = ! empty( $description ) ? $description : ''; |
|
| 235 | + $description = ! empty($description) ? $description : ''; |
|
| 236 | 236 | $firstname = ''; |
| 237 | 237 | $lastname = ''; |
| 238 | 238 | |
| 239 | 239 | // If paying from order, we need to get total from order not cart. |
| 240 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { // wpcs: csrf ok. |
|
| 241 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); // wpcs: csrf ok, sanitization ok. |
|
| 240 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { // wpcs: csrf ok. |
|
| 241 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); // wpcs: csrf ok, sanitization ok. |
|
| 242 | 242 | $total = $order->get_total(); |
| 243 | - $user_email = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_email : $order->get_billing_email(); |
|
| 243 | + $user_email = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_email : $order->get_billing_email(); |
|
| 244 | 244 | } else { |
| 245 | - if ( $user->ID ) { |
|
| 246 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
| 245 | + if ($user->ID) { |
|
| 246 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
| 247 | 247 | $user_email = $user_email ? $user_email : $user->user_email; |
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - if ( is_add_payment_method_page() ) { |
|
| 251 | + if (is_add_payment_method_page()) { |
|
| 252 | 252 | $firstname = $user->user_firstname; |
| 253 | 253 | $lastname = $user->user_lastname; |
| 254 | 254 | } |
@@ -257,33 +257,33 @@ discard block |
||
| 257 | 257 | |
| 258 | 258 | echo '<div |
| 259 | 259 | id="stripe-payment-data" |
| 260 | - data-email="' . esc_attr( $user_email ) . '" |
|
| 261 | - data-full-name="' . esc_attr( $firstname . ' ' . $lastname ) . '" |
|
| 262 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
| 260 | + data-email="' . esc_attr($user_email) . '" |
|
| 261 | + data-full-name="' . esc_attr($firstname . ' ' . $lastname) . '" |
|
| 262 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
| 263 | 263 | >'; |
| 264 | 264 | |
| 265 | - if ( $this->testmode ) { |
|
| 265 | + if ($this->testmode) { |
|
| 266 | 266 | /* translators: link to Stripe testing page */ |
| 267 | - $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' ); |
|
| 267 | + $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'); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - $description = trim( $description ); |
|
| 270 | + $description = trim($description); |
|
| 271 | 271 | |
| 272 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); // wpcs: xss ok. |
|
| 272 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); // wpcs: xss ok. |
|
| 273 | 273 | |
| 274 | - if ( $display_tokenization ) { |
|
| 274 | + if ($display_tokenization) { |
|
| 275 | 275 | $this->tokenization_script(); |
| 276 | 276 | $this->saved_payment_methods(); |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | $this->elements_form(); |
| 280 | 280 | |
| 281 | - 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. |
|
| 281 | + 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. |
|
| 282 | 282 | |
| 283 | 283 | $this->save_payment_method_checkbox(); |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - do_action( 'wc_stripe_cards_payment_fields', $this->id ); |
|
| 286 | + do_action('wc_stripe_cards_payment_fields', $this->id); |
|
| 287 | 287 | |
| 288 | 288 | echo '</div>'; |
| 289 | 289 | |
@@ -298,12 +298,12 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | public function elements_form() { |
| 300 | 300 | ?> |
| 301 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
| 302 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
| 301 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
| 302 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
| 303 | 303 | |
| 304 | - <?php if ( $this->inline_cc_form ) { ?> |
|
| 304 | + <?php if ($this->inline_cc_form) { ?> |
|
| 305 | 305 | <label for="card-element"> |
| 306 | - <?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?> |
|
| 306 | + <?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?> |
|
| 307 | 307 | </label> |
| 308 | 308 | |
| 309 | 309 | <div id="stripe-card-element" class="wc-stripe-elements-field"> |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | </div> |
| 312 | 312 | <?php } else { ?> |
| 313 | 313 | <div class="form-row form-row-wide"> |
| 314 | - <label for="stripe-card-element"><?php esc_html_e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
| 314 | + <label for="stripe-card-element"><?php esc_html_e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
| 315 | 315 | <div class="stripe-card-group"> |
| 316 | 316 | <div id="stripe-card-element" class="wc-stripe-elements-field"> |
| 317 | 317 | <!-- a Stripe Element will be inserted here. --> |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | </div> |
| 323 | 323 | |
| 324 | 324 | <div class="form-row form-row-first"> |
| 325 | - <label for="stripe-exp-element"><?php esc_html_e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
| 325 | + <label for="stripe-exp-element"><?php esc_html_e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
| 326 | 326 | |
| 327 | 327 | <div id="stripe-exp-element" class="wc-stripe-elements-field"> |
| 328 | 328 | <!-- a Stripe Element will be inserted here. --> |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | </div> |
| 331 | 331 | |
| 332 | 332 | <div class="form-row form-row-last"> |
| 333 | - <label for="stripe-cvc-element"><?php esc_html_e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
| 333 | + <label for="stripe-cvc-element"><?php esc_html_e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
| 334 | 334 | <div id="stripe-cvc-element" class="wc-stripe-elements-field"> |
| 335 | 335 | <!-- a Stripe Element will be inserted here. --> |
| 336 | 336 | </div> |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | <!-- Used to display form errors --> |
| 342 | 342 | <div class="stripe-source-errors" role="alert"></div> |
| 343 | 343 | <br /> |
| 344 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
| 344 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
| 345 | 345 | <div class="clear"></div> |
| 346 | 346 | </fieldset> |
| 347 | 347 | <?php |
@@ -354,13 +354,13 @@ discard block |
||
| 354 | 354 | * @version 3.1.0 |
| 355 | 355 | */ |
| 356 | 356 | public function admin_scripts() { |
| 357 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
| 357 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
| 358 | 358 | return; |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 361 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 362 | 362 | |
| 363 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
| 363 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | /** |
@@ -376,102 +376,102 @@ discard block |
||
| 376 | 376 | ! is_product() |
| 377 | 377 | && ! is_cart() |
| 378 | 378 | && ! is_checkout() |
| 379 | - && ! isset( $_GET['pay_for_order'] ) // wpcs: csrf ok. |
|
| 379 | + && ! isset($_GET['pay_for_order']) // wpcs: csrf ok. |
|
| 380 | 380 | && ! is_add_payment_method_page() |
| 381 | - && ! isset( $_GET['change_payment_method'] ) // wpcs: csrf ok. |
|
| 382 | - && ! ( ! empty( get_query_var( 'view-subscription' ) ) && class_exists( 'WCS_Early_Renewal_Manager' ) && WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled() ) |
|
| 383 | - || ( is_order_received_page() ) |
|
| 381 | + && ! isset($_GET['change_payment_method']) // wpcs: csrf ok. |
|
| 382 | + && ! ( ! empty(get_query_var('view-subscription')) && class_exists('WCS_Early_Renewal_Manager') && WCS_Early_Renewal_Manager::is_early_renewal_via_modal_enabled()) |
|
| 383 | + || (is_order_received_page()) |
|
| 384 | 384 | ) { |
| 385 | 385 | return; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | // If Stripe is not enabled bail. |
| 389 | - if ( 'no' === $this->enabled ) { |
|
| 389 | + if ('no' === $this->enabled) { |
|
| 390 | 390 | return; |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | // If keys are not set bail. |
| 394 | - if ( ! $this->are_keys_set() ) { |
|
| 395 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
| 394 | + if ( ! $this->are_keys_set()) { |
|
| 395 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
| 396 | 396 | return; |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | // If no SSL bail. |
| 400 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
| 401 | - WC_Stripe_Logger::log( 'Stripe live mode requires SSL.' ); |
|
| 400 | + if ( ! $this->testmode && ! is_ssl()) { |
|
| 401 | + WC_Stripe_Logger::log('Stripe live mode requires SSL.'); |
|
| 402 | 402 | return; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | $current_theme = wp_get_theme(); |
| 406 | 406 | |
| 407 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 407 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 408 | 408 | |
| 409 | - wp_register_style( 'stripe_styles', plugins_url( 'assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
| 410 | - wp_enqueue_style( 'stripe_styles' ); |
|
| 409 | + wp_register_style('stripe_styles', plugins_url('assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
| 410 | + wp_enqueue_style('stripe_styles'); |
|
| 411 | 411 | |
| 412 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
| 413 | - wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 412 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
| 413 | + wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true); |
|
| 414 | 414 | |
| 415 | 415 | $stripe_params = array( |
| 416 | 416 | 'key' => $this->publishable_key, |
| 417 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
| 418 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
| 417 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
| 418 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
| 419 | 419 | ); |
| 420 | 420 | |
| 421 | 421 | // If we're on the pay page we need to pass stripe.js the address of the order. |
| 422 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { // wpcs: csrf ok. |
|
| 423 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); // wpcs: csrf ok, sanitization ok, xss ok. |
|
| 424 | - $order = wc_get_order( $order_id ); |
|
| 425 | - |
|
| 426 | - if ( is_a( $order, 'WC_Order' ) ) { |
|
| 427 | - $stripe_params['billing_first_name'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_first_name : $order->get_billing_first_name(); |
|
| 428 | - $stripe_params['billing_last_name'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_last_name : $order->get_billing_last_name(); |
|
| 429 | - $stripe_params['billing_address_1'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_address_1 : $order->get_billing_address_1(); |
|
| 430 | - $stripe_params['billing_address_2'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_address_2 : $order->get_billing_address_2(); |
|
| 431 | - $stripe_params['billing_state'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_state : $order->get_billing_state(); |
|
| 432 | - $stripe_params['billing_city'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_city : $order->get_billing_city(); |
|
| 433 | - $stripe_params['billing_postcode'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_postcode : $order->get_billing_postcode(); |
|
| 434 | - $stripe_params['billing_country'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_country : $order->get_billing_country(); |
|
| 422 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { // wpcs: csrf ok. |
|
| 423 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); // wpcs: csrf ok, sanitization ok, xss ok. |
|
| 424 | + $order = wc_get_order($order_id); |
|
| 425 | + |
|
| 426 | + if (is_a($order, 'WC_Order')) { |
|
| 427 | + $stripe_params['billing_first_name'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_first_name : $order->get_billing_first_name(); |
|
| 428 | + $stripe_params['billing_last_name'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_last_name : $order->get_billing_last_name(); |
|
| 429 | + $stripe_params['billing_address_1'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_address_1 : $order->get_billing_address_1(); |
|
| 430 | + $stripe_params['billing_address_2'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_address_2 : $order->get_billing_address_2(); |
|
| 431 | + $stripe_params['billing_state'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_state : $order->get_billing_state(); |
|
| 432 | + $stripe_params['billing_city'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_city : $order->get_billing_city(); |
|
| 433 | + $stripe_params['billing_postcode'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_postcode : $order->get_billing_postcode(); |
|
| 434 | + $stripe_params['billing_country'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_country : $order->get_billing_country(); |
|
| 435 | 435 | } |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | $sepa_elements_options = apply_filters( |
| 439 | 439 | 'wc_stripe_sepa_elements_options', |
| 440 | 440 | array( |
| 441 | - 'supportedCountries' => array( 'SEPA' ), |
|
| 441 | + 'supportedCountries' => array('SEPA'), |
|
| 442 | 442 | 'placeholderCountry' => WC()->countries->get_base_country(), |
| 443 | - 'style' => array( 'base' => array( 'fontSize' => '15px' ) ), |
|
| 443 | + 'style' => array('base' => array('fontSize' => '15px')), |
|
| 444 | 444 | ) |
| 445 | 445 | ); |
| 446 | 446 | |
| 447 | - $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' ); |
|
| 448 | - $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
| 449 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
| 450 | - $stripe_params['payment_intent_error'] = __( 'We couldn\'t initiate the payment. Please try again.', 'woocommerce-gateway-stripe' ); |
|
| 451 | - $stripe_params['sepa_mandate_notification'] = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' ); |
|
| 452 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
| 447 | + $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'); |
|
| 448 | + $stripe_params['no_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
| 449 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
| 450 | + $stripe_params['payment_intent_error'] = __('We couldn\'t initiate the payment. Please try again.', 'woocommerce-gateway-stripe'); |
|
| 451 | + $stripe_params['sepa_mandate_notification'] = apply_filters('wc_stripe_sepa_mandate_notification', 'email'); |
|
| 452 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
| 453 | 453 | $stripe_params['inline_cc_form'] = $this->inline_cc_form ? 'yes' : 'no'; |
| 454 | - $stripe_params['is_checkout'] = ( is_checkout() && empty( $_GET['pay_for_order'] ) ) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
| 454 | + $stripe_params['is_checkout'] = (is_checkout() && empty($_GET['pay_for_order'])) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
| 455 | 455 | $stripe_params['return_url'] = $this->get_stripe_return_url(); |
| 456 | - $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); |
|
| 457 | - $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); |
|
| 456 | + $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint('%%endpoint%%'); |
|
| 457 | + $stripe_params['stripe_nonce'] = wp_create_nonce('_wc_stripe_nonce'); |
|
| 458 | 458 | $stripe_params['statement_descriptor'] = $this->statement_descriptor; |
| 459 | - $stripe_params['elements_options'] = apply_filters( 'wc_stripe_elements_options', array() ); |
|
| 459 | + $stripe_params['elements_options'] = apply_filters('wc_stripe_elements_options', array()); |
|
| 460 | 460 | $stripe_params['sepa_elements_options'] = $sepa_elements_options; |
| 461 | - $stripe_params['invalid_owner_name'] = __( 'Billing First Name and Last Name are required.', 'woocommerce-gateway-stripe' ); |
|
| 462 | - $stripe_params['is_change_payment_page'] = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
| 463 | - $stripe_params['is_add_payment_page'] = is_wc_endpoint_url( 'add-payment-method' ) ? 'yes' : 'no'; |
|
| 464 | - $stripe_params['is_pay_for_order_page'] = is_wc_endpoint_url( 'order-pay' ) ? 'yes' : 'no'; |
|
| 465 | - $stripe_params['elements_styling'] = apply_filters( 'wc_stripe_elements_styling', false ); |
|
| 466 | - $stripe_params['elements_classes'] = apply_filters( 'wc_stripe_elements_classes', false ); |
|
| 461 | + $stripe_params['invalid_owner_name'] = __('Billing First Name and Last Name are required.', 'woocommerce-gateway-stripe'); |
|
| 462 | + $stripe_params['is_change_payment_page'] = isset($_GET['change_payment_method']) ? 'yes' : 'no'; // wpcs: csrf ok. |
|
| 463 | + $stripe_params['is_add_payment_page'] = is_wc_endpoint_url('add-payment-method') ? 'yes' : 'no'; |
|
| 464 | + $stripe_params['is_pay_for_order_page'] = is_wc_endpoint_url('order-pay') ? 'yes' : 'no'; |
|
| 465 | + $stripe_params['elements_styling'] = apply_filters('wc_stripe_elements_styling', false); |
|
| 466 | + $stripe_params['elements_classes'] = apply_filters('wc_stripe_elements_classes', false); |
|
| 467 | 467 | |
| 468 | 468 | // Merge localized messages to be use in JS. |
| 469 | - $stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() ); |
|
| 469 | + $stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages()); |
|
| 470 | 470 | |
| 471 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
| 471 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
| 472 | 472 | |
| 473 | 473 | $this->tokenization_script(); |
| 474 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 474 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | /** |
@@ -482,14 +482,14 @@ discard block |
||
| 482 | 482 | * @param object $prepared_source The object with source details. |
| 483 | 483 | * @throws WC_Stripe_Exception An exception if the card is prepaid, but prepaid cards are not allowed. |
| 484 | 484 | */ |
| 485 | - public function maybe_disallow_prepaid_card( $prepared_source ) { |
|
| 485 | + public function maybe_disallow_prepaid_card($prepared_source) { |
|
| 486 | 486 | // Check if we don't allow prepaid credit cards. |
| 487 | - if ( apply_filters( 'wc_stripe_allow_prepaid_card', true ) || ! $this->is_prepaid_card( $prepared_source->source_object ) ) { |
|
| 487 | + if (apply_filters('wc_stripe_allow_prepaid_card', true) || ! $this->is_prepaid_card($prepared_source->source_object)) { |
|
| 488 | 488 | return; |
| 489 | 489 | } |
| 490 | 490 | |
| 491 | - $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' ); |
|
| 492 | - throw new WC_Stripe_Exception( print_r( $prepared_source->source_object, true ), $localized_message ); |
|
| 491 | + $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'); |
|
| 492 | + throw new WC_Stripe_Exception(print_r($prepared_source->source_object, true), $localized_message); |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | /** |
@@ -499,10 +499,10 @@ discard block |
||
| 499 | 499 | * @param object $prepared_source The source that should be verified. |
| 500 | 500 | * @throws WC_Stripe_Exception An exception if the source ID is missing. |
| 501 | 501 | */ |
| 502 | - public function check_source( $prepared_source ) { |
|
| 503 | - if ( empty( $prepared_source->source ) ) { |
|
| 504 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
| 505 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
| 502 | + public function check_source($prepared_source) { |
|
| 503 | + if (empty($prepared_source->source)) { |
|
| 504 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
| 505 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
| 506 | 506 | } |
| 507 | 507 | } |
| 508 | 508 | |
@@ -514,17 +514,17 @@ discard block |
||
| 514 | 514 | * @param WC_Order $order The order those payment is being processed. |
| 515 | 515 | * @return bool A flag that indicates that the customer does not exist and should be removed. |
| 516 | 516 | */ |
| 517 | - public function maybe_remove_non_existent_customer( $error, $order ) { |
|
| 518 | - if ( ! $this->is_no_such_customer_error( $error ) ) { |
|
| 517 | + public function maybe_remove_non_existent_customer($error, $order) { |
|
| 518 | + if ( ! $this->is_no_such_customer_error($error)) { |
|
| 519 | 519 | return false; |
| 520 | 520 | } |
| 521 | 521 | |
| 522 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 523 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
| 524 | - delete_post_meta( $order->get_id(), '_stripe_customer_id' ); |
|
| 522 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 523 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
| 524 | + delete_post_meta($order->get_id(), '_stripe_customer_id'); |
|
| 525 | 525 | } else { |
| 526 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
| 527 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
| 526 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
| 527 | + $order->delete_meta_data('_stripe_customer_id'); |
|
| 528 | 528 | $order->save(); |
| 529 | 529 | } |
| 530 | 530 | |
@@ -540,16 +540,16 @@ discard block |
||
| 540 | 540 | * @param boolean $force_save_source Whether the payment source must be saved, like when dealing with a Subscription setup. |
| 541 | 541 | * @return array Redirection data for `process_payment`. |
| 542 | 542 | */ |
| 543 | - public function complete_free_order( $order, $prepared_source, $force_save_source ) { |
|
| 543 | + public function complete_free_order($order, $prepared_source, $force_save_source) { |
|
| 544 | 544 | $response = array( |
| 545 | 545 | 'result' => 'success', |
| 546 | - 'redirect' => $this->get_return_url( $order ), |
|
| 546 | + 'redirect' => $this->get_return_url($order), |
|
| 547 | 547 | ); |
| 548 | 548 | |
| 549 | - if ( $force_save_source ) { |
|
| 550 | - $intent_secret = $this->setup_intent( $order, $prepared_source ); |
|
| 549 | + if ($force_save_source) { |
|
| 550 | + $intent_secret = $this->setup_intent($order, $prepared_source); |
|
| 551 | 551 | |
| 552 | - if ( ! empty( $intent_secret ) ) { |
|
| 552 | + if ( ! empty($intent_secret)) { |
|
| 553 | 553 | $response['setup_intent_secret'] = $intent_secret; |
| 554 | 554 | return $response; |
| 555 | 555 | } |
@@ -577,74 +577,74 @@ discard block |
||
| 577 | 577 | * @throws Exception If payment will not be accepted. |
| 578 | 578 | * @return array|void |
| 579 | 579 | */ |
| 580 | - public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) { |
|
| 580 | + public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) { |
|
| 581 | 581 | try { |
| 582 | - $order = wc_get_order( $order_id ); |
|
| 582 | + $order = wc_get_order($order_id); |
|
| 583 | 583 | |
| 584 | 584 | // ToDo: `process_pre_order` saves the source to the order for a later payment. |
| 585 | 585 | // This might not work well with PaymentIntents. |
| 586 | - if ( $this->maybe_process_pre_orders( $order_id ) ) { |
|
| 587 | - return $this->pre_orders->process_pre_order( $order_id ); |
|
| 586 | + if ($this->maybe_process_pre_orders($order_id)) { |
|
| 587 | + return $this->pre_orders->process_pre_order($order_id); |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | - if ( isset( $_REQUEST['process_early_renewal'] ) ) { |
|
| 591 | - $prepared_source = $this->prepare_order_source( $order ); |
|
| 590 | + if (isset($_REQUEST['process_early_renewal'])) { |
|
| 591 | + $prepared_source = $this->prepare_order_source($order); |
|
| 592 | 592 | } else { |
| 593 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
| 593 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | - $this->maybe_disallow_prepaid_card( $prepared_source ); |
|
| 597 | - $this->check_source( $prepared_source ); |
|
| 598 | - $this->save_source_to_order( $order, $prepared_source ); |
|
| 596 | + $this->maybe_disallow_prepaid_card($prepared_source); |
|
| 597 | + $this->check_source($prepared_source); |
|
| 598 | + $this->save_source_to_order($order, $prepared_source); |
|
| 599 | 599 | |
| 600 | - if ( 0 >= $order->get_total() ) { |
|
| 601 | - return $this->complete_free_order( $order, $prepared_source, $force_save_source ); |
|
| 600 | + if (0 >= $order->get_total()) { |
|
| 601 | + return $this->complete_free_order($order, $prepared_source, $force_save_source); |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | // This will throw exception if not valid. |
| 605 | - $this->validate_minimum_order_amount( $order ); |
|
| 605 | + $this->validate_minimum_order_amount($order); |
|
| 606 | 606 | |
| 607 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
| 607 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
| 608 | 608 | |
| 609 | - $intent = $this->get_intent_from_order( $order ); |
|
| 610 | - if ( isset( $intent->object ) && 'setup_intent' === $intent->object ) { |
|
| 609 | + $intent = $this->get_intent_from_order($order); |
|
| 610 | + if (isset($intent->object) && 'setup_intent' === $intent->object) { |
|
| 611 | 611 | $intent = false; // This function can only deal with *payment* intents |
| 612 | 612 | } |
| 613 | 613 | |
| 614 | - if ( $intent ) { |
|
| 615 | - $intent = $this->update_existing_intent( $intent, $order, $prepared_source ); |
|
| 614 | + if ($intent) { |
|
| 615 | + $intent = $this->update_existing_intent($intent, $order, $prepared_source); |
|
| 616 | 616 | } else { |
| 617 | - $intent = $this->create_intent( $order, $prepared_source ); |
|
| 617 | + $intent = $this->create_intent($order, $prepared_source); |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | // Confirm the intent after locking the order to make sure webhooks will not interfere. |
| 621 | - if ( empty( $intent->error ) ) { |
|
| 622 | - $this->lock_order_payment( $order, $intent ); |
|
| 623 | - $intent = $this->confirm_intent( $intent, $order, $prepared_source ); |
|
| 621 | + if (empty($intent->error)) { |
|
| 622 | + $this->lock_order_payment($order, $intent); |
|
| 623 | + $intent = $this->confirm_intent($intent, $order, $prepared_source); |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | - if ( ! empty( $intent->error ) ) { |
|
| 627 | - $this->maybe_remove_non_existent_customer( $intent->error, $order ); |
|
| 626 | + if ( ! empty($intent->error)) { |
|
| 627 | + $this->maybe_remove_non_existent_customer($intent->error, $order); |
|
| 628 | 628 | |
| 629 | 629 | // We want to retry. |
| 630 | - if ( $this->is_retryable_error( $intent->error ) ) { |
|
| 631 | - return $this->retry_after_error( $intent, $order, $retry, $force_save_source, $previous_error ); |
|
| 630 | + if ($this->is_retryable_error($intent->error)) { |
|
| 631 | + return $this->retry_after_error($intent, $order, $retry, $force_save_source, $previous_error); |
|
| 632 | 632 | } |
| 633 | 633 | |
| 634 | - $this->unlock_order_payment( $order ); |
|
| 635 | - $this->throw_localized_message( $intent, $order ); |
|
| 634 | + $this->unlock_order_payment($order); |
|
| 635 | + $this->throw_localized_message($intent, $order); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | - if ( ! empty( $intent ) ) { |
|
| 638 | + if ( ! empty($intent)) { |
|
| 639 | 639 | // Use the last charge within the intent to proceed. |
| 640 | - $response = end( $intent->charges->data ); |
|
| 640 | + $response = end($intent->charges->data); |
|
| 641 | 641 | |
| 642 | 642 | // If the intent requires a 3DS flow, redirect to it. |
| 643 | - if ( 'requires_action' === $intent->status ) { |
|
| 644 | - $this->unlock_order_payment( $order ); |
|
| 643 | + if ('requires_action' === $intent->status) { |
|
| 644 | + $this->unlock_order_payment($order); |
|
| 645 | 645 | |
| 646 | - if ( is_wc_endpoint_url( 'order-pay' ) ) { |
|
| 647 | - $redirect_url = add_query_arg( 'wc-stripe-confirmation', 1, $order->get_checkout_payment_url( false ) ); |
|
| 646 | + if (is_wc_endpoint_url('order-pay')) { |
|
| 647 | + $redirect_url = add_query_arg('wc-stripe-confirmation', 1, $order->get_checkout_payment_url(false)); |
|
| 648 | 648 | |
| 649 | 649 | return array( |
| 650 | 650 | 'result' => 'success', |
@@ -659,7 +659,7 @@ discard block |
||
| 659 | 659 | |
| 660 | 660 | return array( |
| 661 | 661 | 'result' => 'success', |
| 662 | - 'redirect' => $this->get_return_url( $order ), |
|
| 662 | + 'redirect' => $this->get_return_url($order), |
|
| 663 | 663 | 'payment_intent_secret' => $intent->client_secret, |
| 664 | 664 | ); |
| 665 | 665 | } |
@@ -667,30 +667,30 @@ discard block |
||
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | // Process valid response. |
| 670 | - $this->process_response( $response, $order ); |
|
| 670 | + $this->process_response($response, $order); |
|
| 671 | 671 | |
| 672 | 672 | // Remove cart. |
| 673 | - if ( isset( WC()->cart ) ) { |
|
| 673 | + if (isset(WC()->cart)) { |
|
| 674 | 674 | WC()->cart->empty_cart(); |
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | // Unlock the order. |
| 678 | - $this->unlock_order_payment( $order ); |
|
| 678 | + $this->unlock_order_payment($order); |
|
| 679 | 679 | |
| 680 | 680 | // Return thank you page redirect. |
| 681 | 681 | return array( |
| 682 | 682 | 'result' => 'success', |
| 683 | - 'redirect' => $this->get_return_url( $order ), |
|
| 683 | + 'redirect' => $this->get_return_url($order), |
|
| 684 | 684 | ); |
| 685 | 685 | |
| 686 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 687 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 688 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 686 | + } catch (WC_Stripe_Exception $e) { |
|
| 687 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 688 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 689 | 689 | |
| 690 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 690 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 691 | 691 | |
| 692 | 692 | /* translators: error message */ |
| 693 | - $order->update_status( 'failed' ); |
|
| 693 | + $order->update_status('failed'); |
|
| 694 | 694 | |
| 695 | 695 | return array( |
| 696 | 696 | 'result' => 'fail', |
@@ -706,17 +706,17 @@ discard block |
||
| 706 | 706 | * |
| 707 | 707 | * @param int $order_id The ID of the order. |
| 708 | 708 | */ |
| 709 | - public function display_order_fee( $order_id ) { |
|
| 710 | - if ( apply_filters( 'wc_stripe_hide_display_order_fee', false, $order_id ) ) { |
|
| 709 | + public function display_order_fee($order_id) { |
|
| 710 | + if (apply_filters('wc_stripe_hide_display_order_fee', false, $order_id)) { |
|
| 711 | 711 | return; |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | - $order = wc_get_order( $order_id ); |
|
| 714 | + $order = wc_get_order($order_id); |
|
| 715 | 715 | |
| 716 | - $fee = WC_Stripe_Helper::get_stripe_fee( $order ); |
|
| 717 | - $currency = WC_Stripe_Helper::get_stripe_currency( $order ); |
|
| 716 | + $fee = WC_Stripe_Helper::get_stripe_fee($order); |
|
| 717 | + $currency = WC_Stripe_Helper::get_stripe_currency($order); |
|
| 718 | 718 | |
| 719 | - if ( ! $fee || ! $currency ) { |
|
| 719 | + if ( ! $fee || ! $currency) { |
|
| 720 | 720 | return; |
| 721 | 721 | } |
| 722 | 722 | |
@@ -724,12 +724,12 @@ discard block |
||
| 724 | 724 | |
| 725 | 725 | <tr> |
| 726 | 726 | <td class="label stripe-fee"> |
| 727 | - <?php echo wc_help_tip( __( 'This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe' ) ); // wpcs: xss ok. ?> |
|
| 728 | - <?php esc_html_e( 'Stripe Fee:', 'woocommerce-gateway-stripe' ); ?> |
|
| 727 | + <?php echo wc_help_tip(__('This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe')); // wpcs: xss ok. ?> |
|
| 728 | + <?php esc_html_e('Stripe Fee:', 'woocommerce-gateway-stripe'); ?> |
|
| 729 | 729 | </td> |
| 730 | 730 | <td width="1%"></td> |
| 731 | 731 | <td class="total"> |
| 732 | - - <?php echo wc_price( $fee, array( 'currency' => $currency ) ); // wpcs: xss ok. ?> |
|
| 732 | + - <?php echo wc_price($fee, array('currency' => $currency)); // wpcs: xss ok. ?> |
|
| 733 | 733 | </td> |
| 734 | 734 | </tr> |
| 735 | 735 | |
@@ -743,17 +743,17 @@ discard block |
||
| 743 | 743 | * |
| 744 | 744 | * @param int $order_id The ID of the order. |
| 745 | 745 | */ |
| 746 | - public function display_order_payout( $order_id ) { |
|
| 747 | - if ( apply_filters( 'wc_stripe_hide_display_order_payout', false, $order_id ) ) { |
|
| 746 | + public function display_order_payout($order_id) { |
|
| 747 | + if (apply_filters('wc_stripe_hide_display_order_payout', false, $order_id)) { |
|
| 748 | 748 | return; |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | - $order = wc_get_order( $order_id ); |
|
| 751 | + $order = wc_get_order($order_id); |
|
| 752 | 752 | |
| 753 | - $net = WC_Stripe_Helper::get_stripe_net( $order ); |
|
| 754 | - $currency = WC_Stripe_Helper::get_stripe_currency( $order ); |
|
| 753 | + $net = WC_Stripe_Helper::get_stripe_net($order); |
|
| 754 | + $currency = WC_Stripe_Helper::get_stripe_currency($order); |
|
| 755 | 755 | |
| 756 | - if ( ! $net || ! $currency ) { |
|
| 756 | + if ( ! $net || ! $currency) { |
|
| 757 | 757 | return; |
| 758 | 758 | } |
| 759 | 759 | |
@@ -761,12 +761,12 @@ discard block |
||
| 761 | 761 | |
| 762 | 762 | <tr> |
| 763 | 763 | <td class="label stripe-payout"> |
| 764 | - <?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. ?> |
|
| 765 | - <?php esc_html_e( 'Stripe Payout:', 'woocommerce-gateway-stripe' ); ?> |
|
| 764 | + <?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. ?> |
|
| 765 | + <?php esc_html_e('Stripe Payout:', 'woocommerce-gateway-stripe'); ?> |
|
| 766 | 766 | </td> |
| 767 | 767 | <td width="1%"></td> |
| 768 | 768 | <td class="total"> |
| 769 | - <?php echo wc_price( $net, array( 'currency' => $currency ) ); // wpcs: xss ok. ?> |
|
| 769 | + <?php echo wc_price($net, array('currency' => $currency)); // wpcs: xss ok. ?> |
|
| 770 | 770 | </td> |
| 771 | 771 | </tr> |
| 772 | 772 | |
@@ -781,18 +781,18 @@ discard block |
||
| 781 | 781 | * @param WC_Order $order The order to add a note to. |
| 782 | 782 | * @throws WC_Stripe_Exception An exception with the right message. |
| 783 | 783 | */ |
| 784 | - public function throw_localized_message( $response, $order ) { |
|
| 784 | + public function throw_localized_message($response, $order) { |
|
| 785 | 785 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
| 786 | 786 | |
| 787 | - if ( 'card_error' === $response->error->type ) { |
|
| 788 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 787 | + if ('card_error' === $response->error->type) { |
|
| 788 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
| 789 | 789 | } else { |
| 790 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 790 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | - $order->add_order_note( $localized_message ); |
|
| 793 | + $order->add_order_note($localized_message); |
|
| 794 | 794 | |
| 795 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 795 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /** |
@@ -807,22 +807,22 @@ discard block |
||
| 807 | 807 | * @throws WC_Stripe_Exception If the payment is not accepted. |
| 808 | 808 | * @return array|void |
| 809 | 809 | */ |
| 810 | - public function retry_after_error( $response, $order, $retry, $force_save_source, $previous_error ) { |
|
| 811 | - if ( ! $retry ) { |
|
| 812 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
| 813 | - $order->add_order_note( $localized_message ); |
|
| 814 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions. |
|
| 810 | + public function retry_after_error($response, $order, $retry, $force_save_source, $previous_error) { |
|
| 811 | + if ( ! $retry) { |
|
| 812 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
| 813 | + $order->add_order_note($localized_message); |
|
| 814 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); // phpcs:ignore WordPress.PHP.DevelopmentFunctions. |
|
| 815 | 815 | } |
| 816 | 816 | |
| 817 | 817 | // Don't do anymore retries after this. |
| 818 | - if ( 5 <= $this->retry_interval ) { |
|
| 819 | - return $this->process_payment( $order->get_id(), false, $force_save_source, $response->error, $previous_error ); |
|
| 818 | + if (5 <= $this->retry_interval) { |
|
| 819 | + return $this->process_payment($order->get_id(), false, $force_save_source, $response->error, $previous_error); |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | - sleep( $this->retry_interval ); |
|
| 822 | + sleep($this->retry_interval); |
|
| 823 | 823 | $this->retry_interval++; |
| 824 | 824 | |
| 825 | - return $this->process_payment( $order->get_id(), true, $force_save_source, $response->error, $previous_error ); |
|
| 825 | + return $this->process_payment($order->get_id(), true, $force_save_source, $response->error, $previous_error); |
|
| 826 | 826 | } |
| 827 | 827 | |
| 828 | 828 | /** |
@@ -833,23 +833,23 @@ discard block |
||
| 833 | 833 | * @param WC_Payment_Gateway[] $gateways A list of all available gateways. |
| 834 | 834 | * @return WC_Payment_Gateway[] Either the same list or an empty one in the right conditions. |
| 835 | 835 | */ |
| 836 | - public function prepare_order_pay_page( $gateways ) { |
|
| 837 | - if ( ! is_wc_endpoint_url( 'order-pay' ) || ! isset( $_GET['wc-stripe-confirmation'] ) ) { // wpcs: csrf ok. |
|
| 836 | + public function prepare_order_pay_page($gateways) { |
|
| 837 | + if ( ! is_wc_endpoint_url('order-pay') || ! isset($_GET['wc-stripe-confirmation'])) { // wpcs: csrf ok. |
|
| 838 | 838 | return $gateways; |
| 839 | 839 | } |
| 840 | 840 | |
| 841 | 841 | try { |
| 842 | 842 | $this->prepare_intent_for_order_pay_page(); |
| 843 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 843 | + } catch (WC_Stripe_Exception $e) { |
|
| 844 | 844 | // Just show the full order pay page if there was a problem preparing the Payment Intent |
| 845 | 845 | return $gateways; |
| 846 | 846 | } |
| 847 | 847 | |
| 848 | - add_filter( 'woocommerce_checkout_show_terms', '__return_false' ); |
|
| 849 | - add_filter( 'woocommerce_pay_order_button_html', '__return_false' ); |
|
| 850 | - add_filter( 'woocommerce_available_payment_gateways', '__return_empty_array' ); |
|
| 851 | - add_filter( 'woocommerce_no_available_payment_methods_message', array( $this, 'change_no_available_methods_message' ) ); |
|
| 852 | - add_action( 'woocommerce_pay_order_after_submit', array( $this, 'render_payment_intent_inputs' ) ); |
|
| 848 | + add_filter('woocommerce_checkout_show_terms', '__return_false'); |
|
| 849 | + add_filter('woocommerce_pay_order_button_html', '__return_false'); |
|
| 850 | + add_filter('woocommerce_available_payment_gateways', '__return_empty_array'); |
|
| 851 | + add_filter('woocommerce_no_available_payment_methods_message', array($this, 'change_no_available_methods_message')); |
|
| 852 | + add_action('woocommerce_pay_order_after_submit', array($this, 'render_payment_intent_inputs')); |
|
| 853 | 853 | |
| 854 | 854 | return array(); |
| 855 | 855 | } |
@@ -862,7 +862,7 @@ discard block |
||
| 862 | 862 | * @return string the new message. |
| 863 | 863 | */ |
| 864 | 864 | public function change_no_available_methods_message() { |
| 865 | - 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' ) ); |
|
| 865 | + 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')); |
|
| 866 | 866 | } |
| 867 | 867 | |
| 868 | 868 | /** |
@@ -873,23 +873,23 @@ discard block |
||
| 873 | 873 | * @throws WC_Stripe_Exception |
| 874 | 874 | * @since 4.3 |
| 875 | 875 | */ |
| 876 | - public function prepare_intent_for_order_pay_page( $order = null ) { |
|
| 877 | - if ( ! isset( $order ) || empty( $order ) ) { |
|
| 878 | - $order = wc_get_order( absint( get_query_var( 'order-pay' ) ) ); |
|
| 876 | + public function prepare_intent_for_order_pay_page($order = null) { |
|
| 877 | + if ( ! isset($order) || empty($order)) { |
|
| 878 | + $order = wc_get_order(absint(get_query_var('order-pay'))); |
|
| 879 | 879 | } |
| 880 | - $intent = $this->get_intent_from_order( $order ); |
|
| 880 | + $intent = $this->get_intent_from_order($order); |
|
| 881 | 881 | |
| 882 | - if ( ! $intent ) { |
|
| 883 | - throw new WC_Stripe_Exception( 'Payment Intent not found', __( 'Payment Intent not found for order #' . $order->get_id(), 'woocommerce-gateway-stripe' ) ); |
|
| 882 | + if ( ! $intent) { |
|
| 883 | + throw new WC_Stripe_Exception('Payment Intent not found', __('Payment Intent not found for order #' . $order->get_id(), 'woocommerce-gateway-stripe')); |
|
| 884 | 884 | } |
| 885 | 885 | |
| 886 | - if ( 'requires_payment_method' === $intent->status && isset( $intent->last_payment_error ) |
|
| 887 | - && 'authentication_required' === $intent->last_payment_error->code ) { |
|
| 888 | - $intent = WC_Stripe_API::request( array( |
|
| 886 | + if ('requires_payment_method' === $intent->status && isset($intent->last_payment_error) |
|
| 887 | + && 'authentication_required' === $intent->last_payment_error->code) { |
|
| 888 | + $intent = WC_Stripe_API::request(array( |
|
| 889 | 889 | 'payment_method' => $intent->last_payment_error->source->id, |
| 890 | - ), 'payment_intents/' . $intent->id . '/confirm' ); |
|
| 891 | - if ( isset( $intent->error ) ) { |
|
| 892 | - throw new WC_Stripe_Exception( print_r( $intent, true ), $intent->error->message ); |
|
| 890 | + ), 'payment_intents/' . $intent->id . '/confirm'); |
|
| 891 | + if (isset($intent->error)) { |
|
| 892 | + throw new WC_Stripe_Exception(print_r($intent, true), $intent->error->message); |
|
| 893 | 893 | } |
| 894 | 894 | } |
| 895 | 895 | |
@@ -904,26 +904,26 @@ discard block |
||
| 904 | 904 | * @throws WC_Stripe_Exception |
| 905 | 905 | * @since 4.2 |
| 906 | 906 | */ |
| 907 | - public function render_payment_intent_inputs( $order = null ) { |
|
| 908 | - if ( ! isset( $order ) || empty( $order ) ) { |
|
| 909 | - $order = wc_get_order( absint( get_query_var( 'order-pay' ) ) ); |
|
| 907 | + public function render_payment_intent_inputs($order = null) { |
|
| 908 | + if ( ! isset($order) || empty($order)) { |
|
| 909 | + $order = wc_get_order(absint(get_query_var('order-pay'))); |
|
| 910 | 910 | } |
| 911 | - if ( ! isset( $this->order_pay_intent ) ) { |
|
| 912 | - $this->prepare_intent_for_order_pay_page( $order ); |
|
| 911 | + if ( ! isset($this->order_pay_intent)) { |
|
| 912 | + $this->prepare_intent_for_order_pay_page($order); |
|
| 913 | 913 | } |
| 914 | 914 | |
| 915 | 915 | $verification_url = add_query_arg( |
| 916 | 916 | array( |
| 917 | 917 | 'order' => $order->get_id(), |
| 918 | - 'nonce' => wp_create_nonce( 'wc_stripe_confirm_pi' ), |
|
| 919 | - 'redirect_to' => rawurlencode( $this->get_return_url( $order ) ), |
|
| 918 | + 'nonce' => wp_create_nonce('wc_stripe_confirm_pi'), |
|
| 919 | + 'redirect_to' => rawurlencode($this->get_return_url($order)), |
|
| 920 | 920 | 'is_pay_for_order' => true, |
| 921 | 921 | ), |
| 922 | - WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' ) |
|
| 922 | + WC_AJAX::get_endpoint('wc_stripe_verify_intent') |
|
| 923 | 923 | ); |
| 924 | 924 | |
| 925 | - echo '<input type="hidden" id="stripe-intent-id" value="' . esc_attr( $this->order_pay_intent->client_secret ) . '" />'; |
|
| 926 | - echo '<input type="hidden" id="stripe-intent-return" value="' . esc_attr( $verification_url ) . '" />'; |
|
| 925 | + echo '<input type="hidden" id="stripe-intent-id" value="' . esc_attr($this->order_pay_intent->client_secret) . '" />'; |
|
| 926 | + echo '<input type="hidden" id="stripe-intent-return" value="' . esc_attr($verification_url) . '" />'; |
|
| 927 | 927 | } |
| 928 | 928 | |
| 929 | 929 | /** |
@@ -933,11 +933,11 @@ discard block |
||
| 933 | 933 | * @param WC_Payment_Token $token Payment Token. |
| 934 | 934 | * @return string Generated payment method HTML |
| 935 | 935 | */ |
| 936 | - public function get_saved_payment_method_option_html( $token ) { |
|
| 937 | - $html = parent::get_saved_payment_method_option_html( $token ); |
|
| 936 | + public function get_saved_payment_method_option_html($token) { |
|
| 937 | + $html = parent::get_saved_payment_method_option_html($token); |
|
| 938 | 938 | $error_wrapper = '<div class="stripe-source-errors" role="alert"></div>'; |
| 939 | 939 | |
| 940 | - return preg_replace( '~</(\w+)>\s*$~', "$error_wrapper</$1>", $html ); |
|
| 940 | + return preg_replace('~</(\w+)>\s*$~', "$error_wrapper</$1>", $html); |
|
| 941 | 941 | } |
| 942 | 942 | |
| 943 | 943 | /** |
@@ -947,18 +947,18 @@ discard block |
||
| 947 | 947 | * @since 4.2.0 |
| 948 | 948 | * @param int $order_id The ID that will be used for the thank you page. |
| 949 | 949 | */ |
| 950 | - public function check_intent_status_on_order_page( $order_id ) { |
|
| 951 | - if ( empty( $order_id ) || absint( $order_id ) <= 0 ) { |
|
| 950 | + public function check_intent_status_on_order_page($order_id) { |
|
| 951 | + if (empty($order_id) || absint($order_id) <= 0) { |
|
| 952 | 952 | return; |
| 953 | 953 | } |
| 954 | 954 | |
| 955 | - $order = wc_get_order( absint( $order_id ) ); |
|
| 955 | + $order = wc_get_order(absint($order_id)); |
|
| 956 | 956 | |
| 957 | - if ( ! $order ) { |
|
| 957 | + if ( ! $order) { |
|
| 958 | 958 | return; |
| 959 | 959 | } |
| 960 | 960 | |
| 961 | - $this->verify_intent_after_checkout( $order ); |
|
| 961 | + $this->verify_intent_after_checkout($order); |
|
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | /** |
@@ -972,8 +972,8 @@ discard block |
||
| 972 | 972 | * @param int $order_id The ID of the order which is being paid for. |
| 973 | 973 | * @return array |
| 974 | 974 | */ |
| 975 | - public function modify_successful_payment_result( $result, $order_id ) { |
|
| 976 | - if ( ! isset( $result['payment_intent_secret'] ) && ! isset( $result['setup_intent_secret'] ) ) { |
|
| 975 | + public function modify_successful_payment_result($result, $order_id) { |
|
| 976 | + if ( ! isset($result['payment_intent_secret']) && ! isset($result['setup_intent_secret'])) { |
|
| 977 | 977 | // Only redirects with intents need to be modified. |
| 978 | 978 | return $result; |
| 979 | 979 | } |
@@ -982,16 +982,16 @@ discard block |
||
| 982 | 982 | $verification_url = add_query_arg( |
| 983 | 983 | array( |
| 984 | 984 | 'order' => $order_id, |
| 985 | - 'nonce' => wp_create_nonce( 'wc_stripe_confirm_pi' ), |
|
| 986 | - 'redirect_to' => rawurlencode( $result['redirect'] ), |
|
| 985 | + 'nonce' => wp_create_nonce('wc_stripe_confirm_pi'), |
|
| 986 | + 'redirect_to' => rawurlencode($result['redirect']), |
|
| 987 | 987 | ), |
| 988 | - WC_AJAX::get_endpoint( 'wc_stripe_verify_intent' ) |
|
| 988 | + WC_AJAX::get_endpoint('wc_stripe_verify_intent') |
|
| 989 | 989 | ); |
| 990 | 990 | |
| 991 | - if ( isset( $result['payment_intent_secret'] ) ) { |
|
| 992 | - $redirect = sprintf( '#confirm-pi-%s:%s', $result['payment_intent_secret'], rawurlencode( $verification_url ) ); |
|
| 993 | - } else if ( isset( $result['setup_intent_secret'] ) ) { |
|
| 994 | - $redirect = sprintf( '#confirm-si-%s:%s', $result['setup_intent_secret'], rawurlencode( $verification_url ) ); |
|
| 991 | + if (isset($result['payment_intent_secret'])) { |
|
| 992 | + $redirect = sprintf('#confirm-pi-%s:%s', $result['payment_intent_secret'], rawurlencode($verification_url)); |
|
| 993 | + } else if (isset($result['setup_intent_secret'])) { |
|
| 994 | + $redirect = sprintf('#confirm-si-%s:%s', $result['setup_intent_secret'], rawurlencode($verification_url)); |
|
| 995 | 995 | } |
| 996 | 996 | |
| 997 | 997 | return array( |
@@ -1003,8 +1003,8 @@ discard block |
||
| 1003 | 1003 | /** |
| 1004 | 1004 | * Proceed with current request using new login session (to ensure consistent nonce). |
| 1005 | 1005 | */ |
| 1006 | - public function set_cookie_on_current_request( $cookie ) { |
|
| 1007 | - $_COOKIE[ LOGGED_IN_COOKIE ] = $cookie; |
|
| 1006 | + public function set_cookie_on_current_request($cookie) { |
|
| 1007 | + $_COOKIE[LOGGED_IN_COOKIE] = $cookie; |
|
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | 1010 | /** |
@@ -1014,58 +1014,58 @@ discard block |
||
| 1014 | 1014 | * @since 4.2.0 |
| 1015 | 1015 | * @param WC_Order $order The order which is in a transitional state. |
| 1016 | 1016 | */ |
| 1017 | - public function verify_intent_after_checkout( $order ) { |
|
| 1018 | - $payment_method = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method(); |
|
| 1019 | - if ( $payment_method !== $this->id ) { |
|
| 1017 | + public function verify_intent_after_checkout($order) { |
|
| 1018 | + $payment_method = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method(); |
|
| 1019 | + if ($payment_method !== $this->id) { |
|
| 1020 | 1020 | // If this is not the payment method, an intent would not be available. |
| 1021 | 1021 | return; |
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | - $intent = $this->get_intent_from_order( $order ); |
|
| 1025 | - if ( ! $intent ) { |
|
| 1024 | + $intent = $this->get_intent_from_order($order); |
|
| 1025 | + if ( ! $intent) { |
|
| 1026 | 1026 | // No intent, redirect to the order received page for further actions. |
| 1027 | 1027 | return; |
| 1028 | 1028 | } |
| 1029 | 1029 | |
| 1030 | 1030 | // A webhook might have modified or locked the order while the intent was retreived. This ensures we are reading the right status. |
| 1031 | - clean_post_cache( $order->get_id() ); |
|
| 1032 | - $order = wc_get_order( $order->get_id() ); |
|
| 1031 | + clean_post_cache($order->get_id()); |
|
| 1032 | + $order = wc_get_order($order->get_id()); |
|
| 1033 | 1033 | |
| 1034 | - if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 1034 | + if ( ! $order->has_status(array('pending', 'failed'))) { |
|
| 1035 | 1035 | // If payment has already been completed, this function is redundant. |
| 1036 | 1036 | return; |
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | - if ( $this->lock_order_payment( $order, $intent ) ) { |
|
| 1039 | + if ($this->lock_order_payment($order, $intent)) { |
|
| 1040 | 1040 | return; |
| 1041 | 1041 | } |
| 1042 | 1042 | |
| 1043 | - if ( 'setup_intent' === $intent->object && 'succeeded' === $intent->status ) { |
|
| 1043 | + if ('setup_intent' === $intent->object && 'succeeded' === $intent->status) { |
|
| 1044 | 1044 | WC()->cart->empty_cart(); |
| 1045 | - if ( WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order( $order ) ) { |
|
| 1046 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
| 1045 | + if (WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order($order)) { |
|
| 1046 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
| 1047 | 1047 | } else { |
| 1048 | 1048 | $order->payment_complete(); |
| 1049 | 1049 | } |
| 1050 | - } else if ( 'succeeded' === $intent->status || 'requires_capture' === $intent->status ) { |
|
| 1050 | + } else if ('succeeded' === $intent->status || 'requires_capture' === $intent->status) { |
|
| 1051 | 1051 | // Proceed with the payment completion. |
| 1052 | - $this->process_response( end( $intent->charges->data ), $order ); |
|
| 1053 | - |
|
| 1054 | - wcs_update_dates_after_early_renewal( wcs_get_subscription( $order->get_meta( '_subscription_renewal' ) ), $order ); |
|
| 1055 | - wc_add_notice( __( 'Your early renewal order was successful.', 'woocommerce-subscriptions' ), 'success' ); |
|
| 1056 | - } else if ( 'requires_payment_method' === $intent->status ) { |
|
| 1057 | - if ( isset( $_GET['early_renewal'] ) ) { |
|
| 1058 | - $order->delete( true ); |
|
| 1059 | - wc_add_notice( __( 'Payment authorization for the renewal order was unsuccessful, please try again.', 'woocommerce-gateway-stripe' ), 'error' ); |
|
| 1060 | - $renewal_url = wcs_get_early_renewal_url( wcs_get_subscription( $order->get_meta( '_subscription_renewal' ) ) ); |
|
| 1061 | - wp_redirect( $renewal_url ); exit; |
|
| 1052 | + $this->process_response(end($intent->charges->data), $order); |
|
| 1053 | + |
|
| 1054 | + wcs_update_dates_after_early_renewal(wcs_get_subscription($order->get_meta('_subscription_renewal')), $order); |
|
| 1055 | + wc_add_notice(__('Your early renewal order was successful.', 'woocommerce-subscriptions'), 'success'); |
|
| 1056 | + } else if ('requires_payment_method' === $intent->status) { |
|
| 1057 | + if (isset($_GET['early_renewal'])) { |
|
| 1058 | + $order->delete(true); |
|
| 1059 | + wc_add_notice(__('Payment authorization for the renewal order was unsuccessful, please try again.', 'woocommerce-gateway-stripe'), 'error'); |
|
| 1060 | + $renewal_url = wcs_get_early_renewal_url(wcs_get_subscription($order->get_meta('_subscription_renewal'))); |
|
| 1061 | + wp_redirect($renewal_url); exit; |
|
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | 1064 | // `requires_payment_method` means that SCA got denied for the current payment method. |
| 1065 | - $this->failed_sca_auth( $order, $intent ); |
|
| 1065 | + $this->failed_sca_auth($order, $intent); |
|
| 1066 | 1066 | } |
| 1067 | 1067 | |
| 1068 | - $this->unlock_order_payment( $order ); |
|
| 1068 | + $this->unlock_order_payment($order); |
|
| 1069 | 1069 | } |
| 1070 | 1070 | |
| 1071 | 1071 | /** |
@@ -1075,18 +1075,18 @@ discard block |
||
| 1075 | 1075 | * @param WC_Order $order The order which should be checked. |
| 1076 | 1076 | * @param object $intent The intent, associated with the order. |
| 1077 | 1077 | */ |
| 1078 | - public function failed_sca_auth( $order, $intent ) { |
|
| 1078 | + public function failed_sca_auth($order, $intent) { |
|
| 1079 | 1079 | // If the order has already failed, do not repeat the same message. |
| 1080 | - if ( $order->has_status( 'failed' ) ) { |
|
| 1080 | + if ($order->has_status('failed')) { |
|
| 1081 | 1081 | return; |
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | 1084 | // Load the right message and update the status. |
| 1085 | - $status_message = isset( $intent->last_payment_error ) |
|
| 1085 | + $status_message = isset($intent->last_payment_error) |
|
| 1086 | 1086 | /* translators: 1) The error message that was received from Stripe. */ |
| 1087 | - ? sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $intent->last_payment_error->message ) |
|
| 1088 | - : __( 'Stripe SCA authentication failed.', 'woocommerce-gateway-stripe' ); |
|
| 1089 | - $order->update_status( 'failed', $status_message ); |
|
| 1087 | + ? sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $intent->last_payment_error->message) |
|
| 1088 | + : __('Stripe SCA authentication failed.', 'woocommerce-gateway-stripe'); |
|
| 1089 | + $order->update_status('failed', $status_message); |
|
| 1090 | 1090 | } |
| 1091 | 1091 | |
| 1092 | 1092 | /** |
@@ -1097,10 +1097,10 @@ discard block |
||
| 1097 | 1097 | * |
| 1098 | 1098 | * @return string Checkout URL for the given order. |
| 1099 | 1099 | */ |
| 1100 | - public function get_checkout_payment_url( $pay_url, $order ) { |
|
| 1100 | + public function get_checkout_payment_url($pay_url, $order) { |
|
| 1101 | 1101 | global $wp; |
| 1102 | - if ( isset( $_GET['wc-stripe-confirmation'] ) && isset( $wp->query_vars['order-pay'] ) && $wp->query_vars['order-pay'] == $order->get_id() ) { |
|
| 1103 | - $pay_url = add_query_arg( 'wc-stripe-confirmation', 1, $pay_url ); |
|
| 1102 | + if (isset($_GET['wc-stripe-confirmation']) && isset($wp->query_vars['order-pay']) && $wp->query_vars['order-pay'] == $order->get_id()) { |
|
| 1103 | + $pay_url = add_query_arg('wc-stripe-confirmation', 1, $pay_url); |
|
| 1104 | 1104 | } |
| 1105 | 1105 | return $pay_url; |
| 1106 | 1106 | } |