| @@ 269-301 (lines=33) @@ | ||
| 266 | $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
| 267 | $response = WC_Stripe_API::request( $request ); |
|
| 268 | ||
| 269 | if ( ! empty( $response->error ) ) { |
|
| 270 | // We want to retry. |
|
| 271 | if ( $this->is_retryable_error( $response->error ) ) { |
|
| 272 | if ( $retry ) { |
|
| 273 | // Don't do anymore retries after this. |
|
| 274 | if ( 5 <= $this->retry_interval ) { |
|
| 275 | return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error ); |
|
| 276 | } |
|
| 277 | ||
| 278 | sleep( $this->retry_interval ); |
|
| 279 | ||
| 280 | $this->retry_interval++; |
|
| 281 | ||
| 282 | return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error ); |
|
| 283 | } else { |
|
| 284 | $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
| 285 | $renewal_order->add_order_note( $localized_message ); |
|
| 286 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 287 | } |
|
| 288 | } |
|
| 289 | ||
| 290 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
|
| 291 | ||
| 292 | if ( 'card_error' === $response->error->type ) { |
|
| 293 | $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 294 | } else { |
|
| 295 | $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 296 | } |
|
| 297 | ||
| 298 | $renewal_order->add_order_note( $localized_message ); |
|
| 299 | ||
| 300 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 301 | } |
|
| 302 | ||
| 303 | do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order ); |
|
| 304 | ||
| @@ 319-351 (lines=33) @@ | ||
| 316 | ||
| 317 | // It's only a failed payment if it's an error and it's not of the type 'authentication_required'. |
|
| 318 | // If it's 'authentication_required', then we should email the user and ask them to authenticate. |
|
| 319 | if ( ! empty( $response->error ) && ! $is_authentication_required ) { |
|
| 320 | // We want to retry. |
|
| 321 | if ( $this->is_retryable_error( $response->error ) ) { |
|
| 322 | if ( $retry ) { |
|
| 323 | // Don't do anymore retries after this. |
|
| 324 | if ( 5 <= $this->retry_interval ) { |
|
| 325 | return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error ); |
|
| 326 | } |
|
| 327 | ||
| 328 | sleep( $this->retry_interval ); |
|
| 329 | ||
| 330 | $this->retry_interval++; |
|
| 331 | ||
| 332 | return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error ); |
|
| 333 | } else { |
|
| 334 | $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
| 335 | $renewal_order->add_order_note( $localized_message ); |
|
| 336 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 337 | } |
|
| 338 | } |
|
| 339 | ||
| 340 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
|
| 341 | ||
| 342 | if ( 'card_error' === $response->error->type ) { |
|
| 343 | $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 344 | } else { |
|
| 345 | $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 346 | } |
|
| 347 | ||
| 348 | $renewal_order->add_order_note( $localized_message ); |
|
| 349 | ||
| 350 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 351 | } |
|
| 352 | ||
| 353 | // Either the charge was successfully captured, or it requires further authentication. |
|
| 354 | ||