| @@ 127-177 (lines=51) @@ | ||
| 124 | $headers = $response['headers']; |
|
| 125 | $response = $response['body']; |
|
| 126 | ||
| 127 | if ( ! empty( $response->error ) ) { |
|
| 128 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
|
| 129 | if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
| 130 | if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 131 | delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
| 132 | delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 133 | } else { |
|
| 134 | delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
| 135 | $order->delete_meta_data( '_stripe_customer_id' ); |
|
| 136 | $order->save(); |
|
| 137 | } |
|
| 138 | } |
|
| 139 | ||
| 140 | if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) { |
|
| 141 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
|
| 142 | $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
| 143 | $wc_token->delete(); |
|
| 144 | $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
| 145 | $order->add_order_note( $localized_message ); |
|
| 146 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 147 | } |
|
| 148 | ||
| 149 | // We want to retry. |
|
| 150 | if ( $this->is_retryable_error( $response->error ) ) { |
|
| 151 | if ( $retry ) { |
|
| 152 | // Don't do anymore retries after this. |
|
| 153 | if ( 5 <= $this->retry_interval ) { |
|
| 154 | return $this->process_redirect_payment( $order_id, false, $response->error ); |
|
| 155 | } |
|
| 156 | ||
| 157 | sleep( $this->retry_interval ); |
|
| 158 | ||
| 159 | $this->retry_interval++; |
|
| 160 | return $this->process_redirect_payment( $order_id, true, $response->error ); |
|
| 161 | } else { |
|
| 162 | $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
| 163 | $order->add_order_note( $localized_message ); |
|
| 164 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 165 | } |
|
| 166 | } |
|
| 167 | ||
| 168 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
|
| 169 | ||
| 170 | if ( 'card_error' === $response->error->type ) { |
|
| 171 | $message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 172 | } else { |
|
| 173 | $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 174 | } |
|
| 175 | ||
| 176 | throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
| 177 | } |
|
| 178 | ||
| 179 | // To prevent double processing the order on WC side. |
|
| 180 | if ( ! $this->is_original_request( $headers ) ) { |
|
| @@ 170-223 (lines=54) @@ | ||
| 167 | $headers = $response['headers']; |
|
| 168 | $response = $response['body']; |
|
| 169 | ||
| 170 | if ( ! empty( $response->error ) ) { |
|
| 171 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
|
| 172 | if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
| 173 | if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 174 | delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
| 175 | delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 176 | } else { |
|
| 177 | delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
| 178 | $order->delete_meta_data( '_stripe_customer_id' ); |
|
| 179 | $order->save(); |
|
| 180 | } |
|
| 181 | } |
|
| 182 | ||
| 183 | if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) { |
|
| 184 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
|
| 185 | $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
| 186 | $wc_token->delete(); |
|
| 187 | $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
| 188 | $order->add_order_note( $localized_message ); |
|
| 189 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 190 | } |
|
| 191 | ||
| 192 | // We want to retry. |
|
| 193 | if ( $this->is_retryable_error( $response->error ) ) { |
|
| 194 | if ( $retry ) { |
|
| 195 | // Don't do anymore retries after this. |
|
| 196 | if ( 5 <= $this->retry_interval ) { |
|
| 197 | ||
| 198 | return $this->process_webhook_payment( $notification, false ); |
|
| 199 | } |
|
| 200 | ||
| 201 | sleep( $this->retry_interval ); |
|
| 202 | ||
| 203 | $this->retry_interval++; |
|
| 204 | return $this->process_webhook_payment( $notification, true ); |
|
| 205 | } else { |
|
| 206 | $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
| 207 | $order->add_order_note( $localized_message ); |
|
| 208 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 209 | } |
|
| 210 | } |
|
| 211 | ||
| 212 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
|
| 213 | ||
| 214 | if ( 'card_error' === $response->error->type ) { |
|
| 215 | $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 216 | } else { |
|
| 217 | $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 218 | } |
|
| 219 | ||
| 220 | $order->add_order_note( $localized_message ); |
|
| 221 | ||
| 222 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 223 | } |
|
| 224 | ||
| 225 | // To prevent double processing the order on WC side. |
|
| 226 | if ( ! $this->is_original_request( $headers ) ) { |
|
| @@ 336-390 (lines=55) @@ | ||
| 333 | // Make the request. |
|
| 334 | $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
| 335 | ||
| 336 | if ( ! empty( $response->error ) ) { |
|
| 337 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
|
| 338 | if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
| 339 | if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 340 | delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
| 341 | delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 342 | } else { |
|
| 343 | delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
| 344 | $order->delete_meta_data( '_stripe_customer_id' ); |
|
| 345 | $order->save(); |
|
| 346 | } |
|
| 347 | } |
|
| 348 | ||
| 349 | if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) { |
|
| 350 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
|
| 351 | $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
| 352 | $wc_token->delete(); |
|
| 353 | $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
| 354 | $order->add_order_note( $localized_message ); |
|
| 355 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 356 | } |
|
| 357 | ||
| 358 | // We want to retry. |
|
| 359 | if ( $this->is_retryable_error( $response->error ) ) { |
|
| 360 | if ( $retry ) { |
|
| 361 | // Don't do anymore retries after this. |
|
| 362 | if ( 5 <= $this->retry_interval ) { |
|
| 363 | ||
| 364 | return $this->process_payment( $order_id, false, $force_save_source ); |
|
| 365 | } |
|
| 366 | ||
| 367 | sleep( $this->retry_interval ); |
|
| 368 | ||
| 369 | $this->retry_interval++; |
|
| 370 | ||
| 371 | return $this->process_payment( $order_id, true, $force_save_source ); |
|
| 372 | } else { |
|
| 373 | $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
| 374 | $order->add_order_note( $localized_message ); |
|
| 375 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 376 | } |
|
| 377 | } |
|
| 378 | ||
| 379 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
|
| 380 | ||
| 381 | if ( 'card_error' === $response->error->type ) { |
|
| 382 | $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 383 | } else { |
|
| 384 | $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 385 | } |
|
| 386 | ||
| 387 | $order->add_order_note( $localized_message ); |
|
| 388 | ||
| 389 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 390 | } |
|
| 391 | ||
| 392 | do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
| 393 | ||