@@ 150-189 (lines=40) @@ | ||
147 | // Make the request. |
|
148 | $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) ); |
|
149 | ||
150 | if ( ! empty( $response->error ) ) { |
|
151 | // If it is an API error such connection or server, let's retry. |
|
152 | if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
153 | if ( $retry ) { |
|
154 | sleep( 5 ); |
|
155 | return $this->process_payment( $order_id, false ); |
|
156 | } else { |
|
157 | $message = 'API connection error and retries exhausted.'; |
|
158 | $order->add_order_note( $message ); |
|
159 | throw new Exception( $message ); |
|
160 | } |
|
161 | } |
|
162 | ||
163 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
|
164 | if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
165 | delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
166 | ||
167 | return $this->process_payment( $order_id, false ); |
|
168 | ||
169 | } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
170 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
|
171 | $wc_token = WC_Payment_Tokens::get( $source_object->token_id ); |
|
172 | $wc_token->delete(); |
|
173 | $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
174 | $order->add_order_note( $message ); |
|
175 | throw new Exception( $message ); |
|
176 | } |
|
177 | ||
178 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
|
179 | ||
180 | if ( 'card_error' === $response->error->type ) { |
|
181 | $message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
182 | } else { |
|
183 | $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
184 | } |
|
185 | ||
186 | $order->add_order_note( $message ); |
|
187 | ||
188 | throw new Exception( $message ); |
|
189 | } |
|
190 | ||
191 | do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order ); |
|
192 |
@@ 688-726 (lines=39) @@ | ||
685 | // Make the request. |
|
686 | $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
687 | ||
688 | if ( ! empty( $response->error ) ) { |
|
689 | // If it is an API error such connection or server, let's retry. |
|
690 | if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
691 | if ( $retry ) { |
|
692 | sleep( 5 ); |
|
693 | return $this->process_payment( $order_id, false, $force_save_source ); |
|
694 | } else { |
|
695 | $message = 'API connection error and retries exhausted.'; |
|
696 | $order->add_order_note( $message ); |
|
697 | throw new Exception( $message ); |
|
698 | } |
|
699 | } |
|
700 | ||
701 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
|
702 | if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
703 | delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
704 | ||
705 | return $this->process_payment( $order_id, false, $force_save_source ); |
|
706 | } elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) { |
|
707 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
|
708 | $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
709 | $wc_token->delete(); |
|
710 | $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
711 | $order->add_order_note( $message ); |
|
712 | throw new Exception( $message ); |
|
713 | } |
|
714 | ||
715 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
|
716 | ||
717 | if ( 'card_error' === $response->error->type ) { |
|
718 | $message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
719 | } else { |
|
720 | $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
721 | } |
|
722 | ||
723 | $order->add_order_note( $message ); |
|
724 | ||
725 | throw new Exception( $message ); |
|
726 | } |
|
727 | ||
728 | do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
729 |
@@ 349-387 (lines=39) @@ | ||
346 | // Make the request. |
|
347 | $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
348 | ||
349 | if ( ! empty( $response->error ) ) { |
|
350 | // If it is an API error such connection or server, let's retry. |
|
351 | if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
352 | if ( $retry ) { |
|
353 | sleep( 5 ); |
|
354 | return $this->process_payment( $order_id, false, $force_save_source ); |
|
355 | } else { |
|
356 | $message = 'API connection error and retries exhausted.'; |
|
357 | $order->add_order_note( $message ); |
|
358 | throw new Exception( $message ); |
|
359 | } |
|
360 | } |
|
361 | ||
362 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
|
363 | if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
364 | delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
365 | ||
366 | return $this->process_payment( $order_id, false, $force_save_source ); |
|
367 | } elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) { |
|
368 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
|
369 | $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
370 | $wc_token->delete(); |
|
371 | $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
372 | $order->add_order_note( $message ); |
|
373 | throw new Exception( $message ); |
|
374 | } |
|
375 | ||
376 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
|
377 | ||
378 | if ( 'card_error' === $response->error->type ) { |
|
379 | $message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
380 | } else { |
|
381 | $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
382 | } |
|
383 | ||
384 | $order->add_order_note( $message ); |
|
385 | ||
386 | throw new Exception( $message ); |
|
387 | } |
|
388 | ||
389 | do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
390 |