| @@ 754-807 (lines=54) @@ | ||
| 751 | // Make the request. |
|
| 752 | $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
| 753 | ||
| 754 | if ( ! empty( $response->error ) ) { |
|
| 755 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
|
| 756 | if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
| 757 | if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 758 | delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
| 759 | delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 760 | } else { |
|
| 761 | delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
| 762 | $order->delete_meta_data( '_stripe_customer_id' ); |
|
| 763 | $order->save(); |
|
| 764 | } |
|
| 765 | } |
|
| 766 | ||
| 767 | if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) { |
|
| 768 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
|
| 769 | $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
| 770 | $wc_token->delete(); |
|
| 771 | $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
| 772 | $order->add_order_note( $localized_message ); |
|
| 773 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 774 | } |
|
| 775 | ||
| 776 | // We want to retry. |
|
| 777 | if ( $this->is_retryable_error( $response->error ) ) { |
|
| 778 | if ( $retry ) { |
|
| 779 | // Don't do anymore retries after this. |
|
| 780 | if ( 5 <= $this->retry_interval ) { |
|
| 781 | return $this->process_payment( $order_id, false, $force_save_source, $response->error ); |
|
| 782 | } |
|
| 783 | ||
| 784 | sleep( $this->retry_interval ); |
|
| 785 | ||
| 786 | $this->retry_interval++; |
|
| 787 | ||
| 788 | return $this->process_payment( $order_id, true, $force_save_source, $response->error ); |
|
| 789 | } else { |
|
| 790 | $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
| 791 | $order->add_order_note( $localized_message ); |
|
| 792 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 793 | } |
|
| 794 | } |
|
| 795 | ||
| 796 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
|
| 797 | ||
| 798 | if ( 'card_error' === $response->error->type ) { |
|
| 799 | $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 800 | } else { |
|
| 801 | $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 802 | } |
|
| 803 | ||
| 804 | $order->add_order_note( $localized_message ); |
|
| 805 | ||
| 806 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 807 | } |
|
| 808 | ||
| 809 | do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
| 810 | ||
| @@ 335-389 (lines=55) @@ | ||
| 332 | // Make the request. |
|
| 333 | $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
| 334 | ||
| 335 | if ( ! empty( $response->error ) ) { |
|
| 336 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
|
| 337 | if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
| 338 | if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 339 | delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
| 340 | delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 341 | } else { |
|
| 342 | delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
| 343 | $order->delete_meta_data( '_stripe_customer_id' ); |
|
| 344 | $order->save(); |
|
| 345 | } |
|
| 346 | } |
|
| 347 | ||
| 348 | if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) { |
|
| 349 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
|
| 350 | $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
| 351 | $wc_token->delete(); |
|
| 352 | $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
| 353 | $order->add_order_note( $localized_message ); |
|
| 354 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 355 | } |
|
| 356 | ||
| 357 | // We want to retry. |
|
| 358 | if ( $this->is_retryable_error( $response->error ) ) { |
|
| 359 | if ( $retry ) { |
|
| 360 | // Don't do anymore retries after this. |
|
| 361 | if ( 5 <= $this->retry_interval ) { |
|
| 362 | ||
| 363 | return $this->process_payment( $order_id, false, $force_save_source ); |
|
| 364 | } |
|
| 365 | ||
| 366 | sleep( $this->retry_interval ); |
|
| 367 | ||
| 368 | $this->retry_interval++; |
|
| 369 | ||
| 370 | return $this->process_payment( $order_id, true, $force_save_source ); |
|
| 371 | } else { |
|
| 372 | $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
| 373 | $order->add_order_note( $localized_message ); |
|
| 374 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 375 | } |
|
| 376 | } |
|
| 377 | ||
| 378 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
|
| 379 | ||
| 380 | if ( 'card_error' === $response->error->type ) { |
|
| 381 | $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 382 | } else { |
|
| 383 | $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 384 | } |
|
| 385 | ||
| 386 | $order->add_order_note( $localized_message ); |
|
| 387 | ||
| 388 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 389 | } |
|
| 390 | ||
| 391 | do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
| 392 | ||