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