@@ 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_pre_30() ) { |
|
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_pre_30() ) { |
|
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 ) ) { |
@@ 330-384 (lines=55) @@ | ||
327 | // Make the request. |
|
328 | $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
329 | ||
330 | if ( ! empty( $response->error ) ) { |
|
331 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
|
332 | if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
333 | if ( WC_Stripe_Helper::is_pre_30() ) { |
|
334 | delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
335 | delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
336 | } else { |
|
337 | delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
338 | $order->delete_meta_data( '_stripe_customer_id' ); |
|
339 | $order->save(); |
|
340 | } |
|
341 | } |
|
342 | ||
343 | if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) { |
|
344 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
|
345 | $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
346 | $wc_token->delete(); |
|
347 | $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
348 | $order->add_order_note( $localized_message ); |
|
349 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
350 | } |
|
351 | ||
352 | // We want to retry. |
|
353 | if ( $this->is_retryable_error( $response->error ) ) { |
|
354 | if ( $retry ) { |
|
355 | // Don't do anymore retries after this. |
|
356 | if ( 5 <= $this->retry_interval ) { |
|
357 | ||
358 | return $this->process_payment( $order_id, false, $force_save_source ); |
|
359 | } |
|
360 | ||
361 | sleep( $this->retry_interval ); |
|
362 | ||
363 | $this->retry_interval++; |
|
364 | ||
365 | return $this->process_payment( $order_id, true, $force_save_source ); |
|
366 | } else { |
|
367 | $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
368 | $order->add_order_note( $localized_message ); |
|
369 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
370 | } |
|
371 | } |
|
372 | ||
373 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
|
374 | ||
375 | if ( 'card_error' === $response->error->type ) { |
|
376 | $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
377 | } else { |
|
378 | $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
379 | } |
|
380 | ||
381 | $order->add_order_note( $localized_message ); |
|
382 | ||
383 | throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
384 | } |
|
385 | ||
386 | do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
387 |