| @@ 112-146 (lines=35) @@ | ||
| 109 | // Make the request. |
|
| 110 | $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) ); |
|
| 111 | ||
| 112 | if ( ! empty( $response->error ) ) { |
|
| 113 | // If it is an API error such connection or server, let's retry. |
|
| 114 | if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
| 115 | if ( $retry ) { |
|
| 116 | sleep( 5 ); |
|
| 117 | return $this->process_redirect_payment( $order_id, false ); |
|
| 118 | } else { |
|
| 119 | $message = 'API connection error and retries exhausted.'; |
|
| 120 | $order->add_order_note( $message ); |
|
| 121 | throw new Exception( $message ); |
|
| 122 | } |
|
| 123 | } |
|
| 124 | ||
| 125 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
|
| 126 | if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
| 127 | delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
| 128 | ||
| 129 | return $this->process_redirect_payment( $order_id, false ); |
|
| 130 | ||
| 131 | } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
| 132 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
|
| 133 | ||
| 134 | $wc_token = WC_Payment_Tokens::get( $source_object->token_id ); |
|
| 135 | $wc_token->delete(); |
|
| 136 | $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
| 137 | $order->add_order_note( $message ); |
|
| 138 | throw new Exception( $message ); |
|
| 139 | } |
|
| 140 | ||
| 141 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
|
| 142 | ||
| 143 | $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 144 | ||
| 145 | throw new Exception( $message ); |
|
| 146 | } |
|
| 147 | ||
| 148 | do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order ); |
|
| 149 | ||
| @@ 150-185 (lines=36) @@ | ||
| 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 | $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 181 | ||
| 182 | $order->add_order_note( $message ); |
|
| 183 | ||
| 184 | throw new Exception( $message ); |
|
| 185 | } |
|
| 186 | ||
| 187 | do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order ); |
|
| 188 | ||