@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -39,12 +39,12 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function __construct() { |
41 | 41 | $this->retry_interval = 2; |
42 | - $stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
43 | - $this->testmode = ( ! empty( $stripe_settings['testmode'] ) && 'yes' === $stripe_settings['testmode'] ) ? true : false; |
|
44 | - $secret_key = ( $this->testmode ? 'test_' : '' ) . 'webhook_secret'; |
|
45 | - $this->secret = ! empty( $stripe_settings[ $secret_key ] ) ? $stripe_settings[ $secret_key ] : false; |
|
42 | + $stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
43 | + $this->testmode = ( ! empty($stripe_settings['testmode']) && 'yes' === $stripe_settings['testmode']) ? true : false; |
|
44 | + $secret_key = ($this->testmode ? 'test_' : '') . 'webhook_secret'; |
|
45 | + $this->secret = ! empty($stripe_settings[$secret_key]) ? $stripe_settings[$secret_key] : false; |
|
46 | 46 | |
47 | - add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) ); |
|
47 | + add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook')); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -54,24 +54,24 @@ discard block |
||
54 | 54 | * @version 4.0.0 |
55 | 55 | */ |
56 | 56 | public function check_for_webhook() { |
57 | - if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) |
|
58 | - || ! isset( $_GET['wc-api'] ) |
|
59 | - || ( 'wc_stripe' !== $_GET['wc-api'] ) |
|
57 | + if (('POST' !== $_SERVER['REQUEST_METHOD']) |
|
58 | + || ! isset($_GET['wc-api']) |
|
59 | + || ('wc_stripe' !== $_GET['wc-api']) |
|
60 | 60 | ) { |
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | - $request_body = file_get_contents( 'php://input' ); |
|
65 | - $request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER ); |
|
64 | + $request_body = file_get_contents('php://input'); |
|
65 | + $request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER); |
|
66 | 66 | |
67 | 67 | // Validate it to make sure it is legit. |
68 | - if ( $this->is_valid_request( $request_headers, $request_body ) ) { |
|
69 | - $this->process_webhook( $request_body ); |
|
70 | - status_header( 200 ); |
|
68 | + if ($this->is_valid_request($request_headers, $request_body)) { |
|
69 | + $this->process_webhook($request_body); |
|
70 | + status_header(200); |
|
71 | 71 | exit; |
72 | 72 | } else { |
73 | - WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) ); |
|
74 | - status_header( 400 ); |
|
73 | + WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true)); |
|
74 | + status_header(400); |
|
75 | 75 | exit; |
76 | 76 | } |
77 | 77 | } |
@@ -85,34 +85,34 @@ discard block |
||
85 | 85 | * @param string $request_body The request body from Stripe. |
86 | 86 | * @return bool |
87 | 87 | */ |
88 | - public function is_valid_request( $request_headers = null, $request_body = null ) { |
|
89 | - if ( null === $request_headers || null === $request_body ) { |
|
88 | + public function is_valid_request($request_headers = null, $request_body = null) { |
|
89 | + if (null === $request_headers || null === $request_body) { |
|
90 | 90 | return false; |
91 | 91 | } |
92 | 92 | |
93 | - if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) { |
|
93 | + if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) { |
|
94 | 94 | return false; |
95 | 95 | } |
96 | 96 | |
97 | - if ( ! empty( $this->secret ) ) { |
|
97 | + if ( ! empty($this->secret)) { |
|
98 | 98 | // Check for a valid signature. |
99 | 99 | $signature_format = '/^t=(?P<timestamp>\d+)(?P<signatures>(,v\d+=[a-z0-9]+){1,2})$/'; |
100 | - if ( empty( $request_headers['STRIPE-SIGNATURE'] ) || ! preg_match( $signature_format, $request_headers['STRIPE-SIGNATURE'], $matches ) ) { |
|
100 | + if (empty($request_headers['STRIPE-SIGNATURE']) || ! preg_match($signature_format, $request_headers['STRIPE-SIGNATURE'], $matches)) { |
|
101 | 101 | return false; |
102 | 102 | } |
103 | 103 | |
104 | 104 | // Verify the timestamp. |
105 | - $timestamp = intval( $matches['timestamp'] ); |
|
106 | - if ( abs( $timestamp - time() ) > 5 * MINUTE_IN_SECONDS ) { |
|
105 | + $timestamp = intval($matches['timestamp']); |
|
106 | + if (abs($timestamp - time()) > 5 * MINUTE_IN_SECONDS) { |
|
107 | 107 | return; |
108 | 108 | } |
109 | 109 | |
110 | 110 | // Generate the expected signature. |
111 | 111 | $signed_payload = $timestamp . '.' . $request_body; |
112 | - $expected_signature = hash_hmac( 'sha256', $signed_payload, $this->secret ); |
|
112 | + $expected_signature = hash_hmac('sha256', $signed_payload, $this->secret); |
|
113 | 113 | |
114 | 114 | // Check if the expected signature is present. |
115 | - if ( ! preg_match( '/,v\d+=' . preg_quote( $expected_signature, '/' ) . '/', $matches['signatures'] ) ) { |
|
115 | + if ( ! preg_match('/,v\d+=' . preg_quote($expected_signature, '/') . '/', $matches['signatures'])) { |
|
116 | 116 | return false; |
117 | 117 | } |
118 | 118 | } |
@@ -129,12 +129,12 @@ discard block |
||
129 | 129 | * @version 4.0.0 |
130 | 130 | */ |
131 | 131 | public function get_request_headers() { |
132 | - if ( ! function_exists( 'getallheaders' ) ) { |
|
132 | + if ( ! function_exists('getallheaders')) { |
|
133 | 133 | $headers = array(); |
134 | 134 | |
135 | - foreach ( $_SERVER as $name => $value ) { |
|
136 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
137 | - $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
135 | + foreach ($_SERVER as $name => $value) { |
|
136 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
137 | + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -153,30 +153,30 @@ discard block |
||
153 | 153 | * @param object $notification |
154 | 154 | * @param bool $retry |
155 | 155 | */ |
156 | - public function process_webhook_payment( $notification, $retry = true ) { |
|
156 | + public function process_webhook_payment($notification, $retry = true) { |
|
157 | 157 | // The following 3 payment methods are synchronous so does not need to be handle via webhook. |
158 | - if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type ) { |
|
158 | + if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type || 'three_d_secure' === $notification->data->object->type) { |
|
159 | 159 | return; |
160 | 160 | } |
161 | 161 | |
162 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
162 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
163 | 163 | |
164 | - if ( ! $order ) { |
|
165 | - WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id ); |
|
164 | + if ( ! $order) { |
|
165 | + WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id); |
|
166 | 166 | return; |
167 | 167 | } |
168 | 168 | |
169 | 169 | $order_id = $order->get_id(); |
170 | 170 | $source_id = $notification->data->object->id; |
171 | 171 | |
172 | - $is_pending_receiver = ( 'receiver' === $notification->data->object->flow ); |
|
172 | + $is_pending_receiver = ('receiver' === $notification->data->object->flow); |
|
173 | 173 | |
174 | 174 | try { |
175 | - if ( $order->has_status( array( 'processing', 'completed' ) ) ) { |
|
175 | + if ($order->has_status(array('processing', 'completed'))) { |
|
176 | 176 | return; |
177 | 177 | } |
178 | 178 | |
179 | - if ( $order->has_status( 'on-hold' ) && ! $is_pending_receiver ) { |
|
179 | + if ($order->has_status('on-hold') && ! $is_pending_receiver) { |
|
180 | 180 | return; |
181 | 181 | } |
182 | 182 | |
@@ -184,89 +184,89 @@ discard block |
||
184 | 184 | $response = null; |
185 | 185 | |
186 | 186 | // This will throw exception if not valid. |
187 | - $this->validate_minimum_order_amount( $order ); |
|
187 | + $this->validate_minimum_order_amount($order); |
|
188 | 188 | |
189 | - WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
189 | + WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
190 | 190 | |
191 | 191 | // Prep source object. |
192 | 192 | $source_object = new stdClass(); |
193 | 193 | $source_object->token_id = ''; |
194 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
194 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
195 | 195 | $source_object->source = $source_id; |
196 | 196 | |
197 | 197 | // Make the request. |
198 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true ); |
|
198 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true); |
|
199 | 199 | $headers = $response['headers']; |
200 | 200 | $response = $response['body']; |
201 | 201 | |
202 | - if ( ! empty( $response->error ) ) { |
|
202 | + if ( ! empty($response->error)) { |
|
203 | 203 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
204 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
205 | - delete_user_option( $order->get_customer_id(), '_stripe_customer_id' ); |
|
206 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
204 | + if ($this->is_no_such_customer_error($response->error)) { |
|
205 | + delete_user_option($order->get_customer_id(), '_stripe_customer_id'); |
|
206 | + $order->delete_meta_data('_stripe_customer_id'); |
|
207 | 207 | $order->save(); |
208 | 208 | } |
209 | 209 | |
210 | - if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) { |
|
210 | + if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) { |
|
211 | 211 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
212 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
212 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
213 | 213 | $wc_token->delete(); |
214 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
215 | - $order->add_order_note( $localized_message ); |
|
216 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
214 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
215 | + $order->add_order_note($localized_message); |
|
216 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | // We want to retry. |
220 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
221 | - if ( $retry ) { |
|
220 | + if ($this->is_retryable_error($response->error)) { |
|
221 | + if ($retry) { |
|
222 | 222 | // Don't do anymore retries after this. |
223 | - if ( 5 <= $this->retry_interval ) { |
|
223 | + if (5 <= $this->retry_interval) { |
|
224 | 224 | |
225 | - return $this->process_webhook_payment( $notification, false ); |
|
225 | + return $this->process_webhook_payment($notification, false); |
|
226 | 226 | } |
227 | 227 | |
228 | - sleep( $this->retry_interval ); |
|
228 | + sleep($this->retry_interval); |
|
229 | 229 | |
230 | 230 | $this->retry_interval++; |
231 | - return $this->process_webhook_payment( $notification, true ); |
|
231 | + return $this->process_webhook_payment($notification, true); |
|
232 | 232 | } else { |
233 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
234 | - $order->add_order_note( $localized_message ); |
|
235 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
233 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
234 | + $order->add_order_note($localized_message); |
|
235 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
239 | 239 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
240 | 240 | |
241 | - if ( 'card_error' === $response->error->type ) { |
|
242 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
241 | + if ('card_error' === $response->error->type) { |
|
242 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
243 | 243 | } else { |
244 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
244 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
245 | 245 | } |
246 | 246 | |
247 | - $order->add_order_note( $localized_message ); |
|
247 | + $order->add_order_note($localized_message); |
|
248 | 248 | |
249 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
249 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | // To prevent double processing the order on WC side. |
253 | - if ( ! $this->is_original_request( $headers ) ) { |
|
253 | + if ( ! $this->is_original_request($headers)) { |
|
254 | 254 | return; |
255 | 255 | } |
256 | 256 | |
257 | - do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order ); |
|
257 | + do_action('wc_gateway_stripe_process_webhook_payment', $response, $order); |
|
258 | 258 | |
259 | - $this->process_response( $response, $order ); |
|
259 | + $this->process_response($response, $order); |
|
260 | 260 | |
261 | - } catch ( WC_Stripe_Exception $e ) { |
|
262 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
261 | + } catch (WC_Stripe_Exception $e) { |
|
262 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
263 | 263 | |
264 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e ); |
|
264 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e); |
|
265 | 265 | |
266 | - $statuses = array( 'pending', 'failed' ); |
|
266 | + $statuses = array('pending', 'failed'); |
|
267 | 267 | |
268 | - if ( $order->has_status( $statuses ) ) { |
|
269 | - $this->send_failed_order_email( $order_id ); |
|
268 | + if ($order->has_status($statuses)) { |
|
269 | + $this->send_failed_order_email($order_id); |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | } |
@@ -279,28 +279,28 @@ discard block |
||
279 | 279 | * @since 4.0.0 |
280 | 280 | * @param object $notification |
281 | 281 | */ |
282 | - public function process_webhook_dispute( $notification ) { |
|
283 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
282 | + public function process_webhook_dispute($notification) { |
|
283 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
284 | 284 | |
285 | - if ( ! $order ) { |
|
286 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
285 | + if ( ! $order) { |
|
286 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge); |
|
287 | 287 | return; |
288 | 288 | } |
289 | 289 | |
290 | - $order->update_meta_data( '_stripe_status_before_hold', $order->get_status() ); |
|
290 | + $order->update_meta_data('_stripe_status_before_hold', $order->get_status()); |
|
291 | 291 | |
292 | 292 | /* translators: 1) The URL to the order. */ |
293 | - $message = sprintf( __( 'A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ) ); |
|
294 | - if ( ! $order->get_meta( '_stripe_status_final', false ) ) { |
|
295 | - $order->update_status( 'on-hold', $message ); |
|
293 | + $message = sprintf(__('A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order)); |
|
294 | + if ( ! $order->get_meta('_stripe_status_final', false)) { |
|
295 | + $order->update_status('on-hold', $message); |
|
296 | 296 | } else { |
297 | - $order->add_order_note( $message ); |
|
297 | + $order->add_order_note($message); |
|
298 | 298 | } |
299 | 299 | |
300 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
300 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
301 | 301 | |
302 | 302 | $order_id = $order->get_id(); |
303 | - $this->send_failed_order_email( $order_id ); |
|
303 | + $this->send_failed_order_email($order_id); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
@@ -309,34 +309,34 @@ discard block |
||
309 | 309 | * @since 4.4.1 |
310 | 310 | * @param object $notification |
311 | 311 | */ |
312 | - public function process_webhook_dispute_closed( $notification ) { |
|
313 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
312 | + public function process_webhook_dispute_closed($notification) { |
|
313 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
314 | 314 | $status = $notification->data->object->status; |
315 | 315 | |
316 | - if ( ! $order ) { |
|
317 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
316 | + if ( ! $order) { |
|
317 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge); |
|
318 | 318 | return; |
319 | 319 | } |
320 | 320 | |
321 | - if ( 'lost' === $status ) { |
|
322 | - $message = __( 'The dispute was lost or accepted.', 'woocommerce-gateway-stripe' ); |
|
323 | - } elseif ( 'won' === $status ) { |
|
324 | - $message = __( 'The dispute was resolved in your favor.', 'woocommerce-gateway-stripe' ); |
|
325 | - } elseif ( 'warning_closed' === $status ) { |
|
326 | - $message = __( 'The inquiry or retrieval was closed.', 'woocommerce-gateway-stripe' ); |
|
321 | + if ('lost' === $status) { |
|
322 | + $message = __('The dispute was lost or accepted.', 'woocommerce-gateway-stripe'); |
|
323 | + } elseif ('won' === $status) { |
|
324 | + $message = __('The dispute was resolved in your favor.', 'woocommerce-gateway-stripe'); |
|
325 | + } elseif ('warning_closed' === $status) { |
|
326 | + $message = __('The inquiry or retrieval was closed.', 'woocommerce-gateway-stripe'); |
|
327 | 327 | } else { |
328 | 328 | return; |
329 | 329 | } |
330 | 330 | |
331 | - if ( apply_filters( 'wc_stripe_webhook_dispute_change_order_status', true, $order, $notification ) ) { |
|
331 | + if (apply_filters('wc_stripe_webhook_dispute_change_order_status', true, $order, $notification)) { |
|
332 | 332 | // Mark final so that order status is not overridden by out-of-sequence events. |
333 | - $order->update_meta_data( '_stripe_status_final', true ); |
|
333 | + $order->update_meta_data('_stripe_status_final', true); |
|
334 | 334 | |
335 | 335 | // Fail order if dispute is lost, or else revert to pre-dispute status. |
336 | - $order_status = 'lost' === $status ? 'failed' : $order->get_meta( '_stripe_status_before_hold', 'processing' ); |
|
337 | - $order->update_status( $order_status, $message ); |
|
336 | + $order_status = 'lost' === $status ? 'failed' : $order->get_meta('_stripe_status_before_hold', 'processing'); |
|
337 | + $order->update_status($order_status, $message); |
|
338 | 338 | } else { |
339 | - $order->add_order_note( $message ); |
|
339 | + $order->add_order_note($message); |
|
340 | 340 | } |
341 | 341 | } |
342 | 342 | |
@@ -348,43 +348,43 @@ discard block |
||
348 | 348 | * @version 4.0.0 |
349 | 349 | * @param object $notification |
350 | 350 | */ |
351 | - public function process_webhook_capture( $notification ) { |
|
352 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
351 | + public function process_webhook_capture($notification) { |
|
352 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
353 | 353 | |
354 | - if ( ! $order ) { |
|
355 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
354 | + if ( ! $order) { |
|
355 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
356 | 356 | return; |
357 | 357 | } |
358 | 358 | |
359 | - if ( 'stripe' === $order->get_payment_method() ) { |
|
359 | + if ('stripe' === $order->get_payment_method()) { |
|
360 | 360 | $charge = $order->get_transaction_id(); |
361 | - $captured = $order->get_meta( '_stripe_charge_captured', true ); |
|
361 | + $captured = $order->get_meta('_stripe_charge_captured', true); |
|
362 | 362 | |
363 | - if ( $charge && 'no' === $captured ) { |
|
364 | - $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
363 | + if ($charge && 'no' === $captured) { |
|
364 | + $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
365 | 365 | |
366 | 366 | // Store other data such as fees |
367 | - $order->set_transaction_id( $notification->data->object->id ); |
|
367 | + $order->set_transaction_id($notification->data->object->id); |
|
368 | 368 | |
369 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
370 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
369 | + if (isset($notification->data->object->balance_transaction)) { |
|
370 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | // Check and see if capture is partial. |
374 | - if ( $this->is_partial_capture( $notification ) ) { |
|
375 | - $partial_amount = $this->get_partial_amount_to_charge( $notification ); |
|
376 | - $order->set_total( $partial_amount ); |
|
377 | - $this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction ); |
|
374 | + if ($this->is_partial_capture($notification)) { |
|
375 | + $partial_amount = $this->get_partial_amount_to_charge($notification); |
|
376 | + $order->set_total($partial_amount); |
|
377 | + $this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction); |
|
378 | 378 | /* translators: partial captured amount */ |
379 | - $order->add_order_note( sprintf( __( 'This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe' ), $partial_amount ) ); |
|
379 | + $order->add_order_note(sprintf(__('This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe'), $partial_amount)); |
|
380 | 380 | } else { |
381 | - $order->payment_complete( $notification->data->object->id ); |
|
381 | + $order->payment_complete($notification->data->object->id); |
|
382 | 382 | |
383 | 383 | /* translators: transaction id */ |
384 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
384 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
385 | 385 | } |
386 | 386 | |
387 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
387 | + if (is_callable(array($order, 'save'))) { |
|
388 | 388 | $order->save(); |
389 | 389 | } |
390 | 390 | } |
@@ -399,41 +399,41 @@ discard block |
||
399 | 399 | * @version 4.0.0 |
400 | 400 | * @param object $notification |
401 | 401 | */ |
402 | - public function process_webhook_charge_succeeded( $notification ) { |
|
402 | + public function process_webhook_charge_succeeded($notification) { |
|
403 | 403 | // Ignore the notification for charges, created through PaymentIntents. |
404 | - if ( isset( $notification->data->object->payment_intent ) && $notification->data->object->payment_intent ) { |
|
404 | + if (isset($notification->data->object->payment_intent) && $notification->data->object->payment_intent) { |
|
405 | 405 | return; |
406 | 406 | } |
407 | 407 | |
408 | 408 | // The following payment methods are synchronous so does not need to be handle via webhook. |
409 | - if ( ( isset( $notification->data->object->source->type ) && 'card' === $notification->data->object->source->type ) || ( isset( $notification->data->object->source->type ) && 'three_d_secure' === $notification->data->object->source->type ) ) { |
|
409 | + if ((isset($notification->data->object->source->type) && 'card' === $notification->data->object->source->type) || (isset($notification->data->object->source->type) && 'three_d_secure' === $notification->data->object->source->type)) { |
|
410 | 410 | return; |
411 | 411 | } |
412 | 412 | |
413 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
413 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
414 | 414 | |
415 | - if ( ! $order ) { |
|
416 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
415 | + if ( ! $order) { |
|
416 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
417 | 417 | return; |
418 | 418 | } |
419 | 419 | |
420 | - if ( ! $order->has_status( 'on-hold' ) ) { |
|
420 | + if ( ! $order->has_status('on-hold')) { |
|
421 | 421 | return; |
422 | 422 | } |
423 | 423 | |
424 | 424 | // Store other data such as fees |
425 | - $order->set_transaction_id( $notification->data->object->id ); |
|
425 | + $order->set_transaction_id($notification->data->object->id); |
|
426 | 426 | |
427 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
428 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
427 | + if (isset($notification->data->object->balance_transaction)) { |
|
428 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
429 | 429 | } |
430 | 430 | |
431 | - $order->payment_complete( $notification->data->object->id ); |
|
431 | + $order->payment_complete($notification->data->object->id); |
|
432 | 432 | |
433 | 433 | /* translators: transaction id */ |
434 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
434 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
435 | 435 | |
436 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
436 | + if (is_callable(array($order, 'save'))) { |
|
437 | 437 | $order->save(); |
438 | 438 | } |
439 | 439 | } |
@@ -445,27 +445,27 @@ discard block |
||
445 | 445 | * @since 4.1.5 Can handle any fail payments from any methods. |
446 | 446 | * @param object $notification |
447 | 447 | */ |
448 | - public function process_webhook_charge_failed( $notification ) { |
|
449 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
448 | + public function process_webhook_charge_failed($notification) { |
|
449 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
450 | 450 | |
451 | - if ( ! $order ) { |
|
452 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
451 | + if ( ! $order) { |
|
452 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
453 | 453 | return; |
454 | 454 | } |
455 | 455 | |
456 | 456 | // If order status is already in failed status don't continue. |
457 | - if ( $order->has_status( 'failed' ) ) { |
|
457 | + if ($order->has_status('failed')) { |
|
458 | 458 | return; |
459 | 459 | } |
460 | 460 | |
461 | - $message = __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ); |
|
462 | - if ( ! $order->get_meta( '_stripe_status_final', false ) ) { |
|
463 | - $order->update_status( 'failed', $message ); |
|
461 | + $message = __('This payment failed to clear.', 'woocommerce-gateway-stripe'); |
|
462 | + if ( ! $order->get_meta('_stripe_status_final', false)) { |
|
463 | + $order->update_status('failed', $message); |
|
464 | 464 | } else { |
465 | - $order->add_order_note( $message ); |
|
465 | + $order->add_order_note($message); |
|
466 | 466 | } |
467 | 467 | |
468 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
468 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | /** |
@@ -476,33 +476,33 @@ discard block |
||
476 | 476 | * @since 4.1.15 Add check to make sure order is processed by Stripe. |
477 | 477 | * @param object $notification |
478 | 478 | */ |
479 | - public function process_webhook_source_canceled( $notification ) { |
|
480 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
479 | + public function process_webhook_source_canceled($notification) { |
|
480 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
481 | 481 | |
482 | 482 | // If can't find order by charge ID, try source ID. |
483 | - if ( ! $order ) { |
|
484 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
483 | + if ( ! $order) { |
|
484 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
485 | 485 | |
486 | - if ( ! $order ) { |
|
487 | - WC_Stripe_Logger::log( 'Could not find order via charge/source ID: ' . $notification->data->object->id ); |
|
486 | + if ( ! $order) { |
|
487 | + WC_Stripe_Logger::log('Could not find order via charge/source ID: ' . $notification->data->object->id); |
|
488 | 488 | return; |
489 | 489 | } |
490 | 490 | } |
491 | 491 | |
492 | 492 | // Don't proceed if payment method isn't Stripe. |
493 | - if ( 'stripe' !== $order->get_payment_method() ) { |
|
494 | - WC_Stripe_Logger::log( 'Canceled webhook abort: Order was not processed by Stripe: ' . $order->get_id() ); |
|
493 | + if ('stripe' !== $order->get_payment_method()) { |
|
494 | + WC_Stripe_Logger::log('Canceled webhook abort: Order was not processed by Stripe: ' . $order->get_id()); |
|
495 | 495 | return; |
496 | 496 | } |
497 | 497 | |
498 | - $message = __( 'This payment was cancelled.', 'woocommerce-gateway-stripe' ); |
|
499 | - if ( ! $order->has_status( 'cancelled' ) && ! $order->get_meta( '_stripe_status_final', false ) ) { |
|
500 | - $order->update_status( 'cancelled', $message ); |
|
498 | + $message = __('This payment was cancelled.', 'woocommerce-gateway-stripe'); |
|
499 | + if ( ! $order->has_status('cancelled') && ! $order->get_meta('_stripe_status_final', false)) { |
|
500 | + $order->update_status('cancelled', $message); |
|
501 | 501 | } else { |
502 | - $order->add_order_note( $message ); |
|
502 | + $order->add_order_note($message); |
|
503 | 503 | } |
504 | 504 | |
505 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
505 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
506 | 506 | } |
507 | 507 | |
508 | 508 | /** |
@@ -512,59 +512,59 @@ discard block |
||
512 | 512 | * @version 4.0.0 |
513 | 513 | * @param object $notification |
514 | 514 | */ |
515 | - public function process_webhook_refund( $notification ) { |
|
516 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
515 | + public function process_webhook_refund($notification) { |
|
516 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
517 | 517 | |
518 | - if ( ! $order ) { |
|
519 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
518 | + if ( ! $order) { |
|
519 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
520 | 520 | return; |
521 | 521 | } |
522 | 522 | |
523 | 523 | $order_id = $order->get_id(); |
524 | 524 | |
525 | - if ( 'stripe' === $order->get_payment_method() ) { |
|
525 | + if ('stripe' === $order->get_payment_method()) { |
|
526 | 526 | $charge = $order->get_transaction_id(); |
527 | - $captured = $order->get_meta( '_stripe_charge_captured', true ); |
|
528 | - $refund_id = $order->get_meta( '_stripe_refund_id', true ); |
|
527 | + $captured = $order->get_meta('_stripe_charge_captured', true); |
|
528 | + $refund_id = $order->get_meta('_stripe_refund_id', true); |
|
529 | 529 | |
530 | 530 | // If the refund ID matches, don't continue to prevent double refunding. |
531 | - if ( $notification->data->object->refunds->data[0]->id === $refund_id ) { |
|
531 | + if ($notification->data->object->refunds->data[0]->id === $refund_id) { |
|
532 | 532 | return; |
533 | 533 | } |
534 | 534 | |
535 | 535 | // Only refund captured charge. |
536 | - if ( $charge ) { |
|
537 | - $reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' ); |
|
536 | + if ($charge) { |
|
537 | + $reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe'); |
|
538 | 538 | |
539 | 539 | // Create the refund. |
540 | 540 | $refund = wc_create_refund( |
541 | 541 | array( |
542 | 542 | 'order_id' => $order_id, |
543 | - 'amount' => $this->get_refund_amount( $notification ), |
|
543 | + 'amount' => $this->get_refund_amount($notification), |
|
544 | 544 | 'reason' => $reason, |
545 | 545 | ) |
546 | 546 | ); |
547 | 547 | |
548 | - if ( is_wp_error( $refund ) ) { |
|
549 | - WC_Stripe_Logger::log( $refund->get_error_message() ); |
|
548 | + if (is_wp_error($refund)) { |
|
549 | + WC_Stripe_Logger::log($refund->get_error_message()); |
|
550 | 550 | } |
551 | 551 | |
552 | - $order->update_meta_data( '_stripe_refund_id', $notification->data->object->refunds->data[0]->id ); |
|
552 | + $order->update_meta_data('_stripe_refund_id', $notification->data->object->refunds->data[0]->id); |
|
553 | 553 | |
554 | - $amount = wc_price( $notification->data->object->refunds->data[0]->amount / 100 ); |
|
554 | + $amount = wc_price($notification->data->object->refunds->data[0]->amount / 100); |
|
555 | 555 | |
556 | - if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
557 | - $amount = wc_price( $notification->data->object->refunds->data[0]->amount ); |
|
556 | + if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
557 | + $amount = wc_price($notification->data->object->refunds->data[0]->amount); |
|
558 | 558 | } |
559 | 559 | |
560 | - if ( isset( $notification->data->object->refunds->data[0]->balance_transaction ) ) { |
|
561 | - $this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction ); |
|
560 | + if (isset($notification->data->object->refunds->data[0]->balance_transaction)) { |
|
561 | + $this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction); |
|
562 | 562 | } |
563 | 563 | |
564 | 564 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
565 | - $refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - %3$s', 'woocommerce-gateway-stripe' ), $amount, $notification->data->object->refunds->data[0]->id, $reason ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' ); |
|
565 | + $refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - %3$s', 'woocommerce-gateway-stripe'), $amount, $notification->data->object->refunds->data[0]->id, $reason) : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe'); |
|
566 | 566 | |
567 | - $order->add_order_note( $refund_message ); |
|
567 | + $order->add_order_note($refund_message); |
|
568 | 568 | } |
569 | 569 | } |
570 | 570 | } |
@@ -575,32 +575,32 @@ discard block |
||
575 | 575 | * @since 4.0.6 |
576 | 576 | * @param object $notification |
577 | 577 | */ |
578 | - public function process_review_opened( $notification ) { |
|
579 | - if ( isset( $notification->data->object->payment_intent ) ) { |
|
580 | - $order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent ); |
|
578 | + public function process_review_opened($notification) { |
|
579 | + if (isset($notification->data->object->payment_intent)) { |
|
580 | + $order = WC_Stripe_Helper::get_order_by_intent_id($notification->data->object->payment_intent); |
|
581 | 581 | |
582 | - if ( ! $order ) { |
|
583 | - WC_Stripe_Logger::log( '[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent ); |
|
582 | + if ( ! $order) { |
|
583 | + WC_Stripe_Logger::log('[Review Opened] Could not find order via intent ID: ' . $notification->data->object->payment_intent); |
|
584 | 584 | return; |
585 | 585 | } |
586 | 586 | } else { |
587 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
587 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
588 | 588 | |
589 | - if ( ! $order ) { |
|
590 | - WC_Stripe_Logger::log( '[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
589 | + if ( ! $order) { |
|
590 | + WC_Stripe_Logger::log('[Review Opened] Could not find order via charge ID: ' . $notification->data->object->charge); |
|
591 | 591 | return; |
592 | 592 | } |
593 | 593 | } |
594 | 594 | |
595 | - $order->update_meta_data( '_stripe_status_before_hold', $order->get_status() ); |
|
595 | + $order->update_meta_data('_stripe_status_before_hold', $order->get_status()); |
|
596 | 596 | |
597 | 597 | /* translators: 1) The URL to the order. 2) The reason type. */ |
598 | - $message = sprintf( __( 'A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ), $notification->data->object->reason ); |
|
598 | + $message = sprintf(__('A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order), $notification->data->object->reason); |
|
599 | 599 | |
600 | - if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) && ! $order->get_meta( '_stripe_status_final', false ) ) { |
|
601 | - $order->update_status( 'on-hold', $message ); |
|
600 | + if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification) && ! $order->get_meta('_stripe_status_final', false)) { |
|
601 | + $order->update_status('on-hold', $message); |
|
602 | 602 | } else { |
603 | - $order->add_order_note( $message ); |
|
603 | + $order->add_order_note($message); |
|
604 | 604 | } |
605 | 605 | } |
606 | 606 | |
@@ -610,34 +610,34 @@ discard block |
||
610 | 610 | * @since 4.0.6 |
611 | 611 | * @param object $notification |
612 | 612 | */ |
613 | - public function process_review_closed( $notification ) { |
|
614 | - if ( isset( $notification->data->object->payment_intent ) ) { |
|
615 | - $order = WC_Stripe_Helper::get_order_by_intent_id( $notification->data->object->payment_intent ); |
|
613 | + public function process_review_closed($notification) { |
|
614 | + if (isset($notification->data->object->payment_intent)) { |
|
615 | + $order = WC_Stripe_Helper::get_order_by_intent_id($notification->data->object->payment_intent); |
|
616 | 616 | |
617 | - if ( ! $order ) { |
|
618 | - WC_Stripe_Logger::log( '[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent ); |
|
617 | + if ( ! $order) { |
|
618 | + WC_Stripe_Logger::log('[Review Closed] Could not find order via intent ID: ' . $notification->data->object->payment_intent); |
|
619 | 619 | return; |
620 | 620 | } |
621 | 621 | } else { |
622 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
622 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
623 | 623 | |
624 | - if ( ! $order ) { |
|
625 | - WC_Stripe_Logger::log( '[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
624 | + if ( ! $order) { |
|
625 | + WC_Stripe_Logger::log('[Review Closed] Could not find order via charge ID: ' . $notification->data->object->charge); |
|
626 | 626 | return; |
627 | 627 | } |
628 | 628 | } |
629 | 629 | |
630 | 630 | /* translators: 1) The reason type. */ |
631 | - $message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason ); |
|
631 | + $message = sprintf(__('The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe'), $notification->data->object->reason); |
|
632 | 632 | |
633 | 633 | if ( |
634 | - $order->has_status( 'on-hold' ) && |
|
635 | - apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) && |
|
636 | - ! $order->get_meta( '_stripe_status_final', false ) |
|
634 | + $order->has_status('on-hold') && |
|
635 | + apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification) && |
|
636 | + ! $order->get_meta('_stripe_status_final', false) |
|
637 | 637 | ) { |
638 | - $order->update_status( $order->get_meta( '_stripe_status_before_hold', 'processing' ), $message ); |
|
638 | + $order->update_status($order->get_meta('_stripe_status_before_hold', 'processing'), $message); |
|
639 | 639 | } else { |
640 | - $order->add_order_note( $message ); |
|
640 | + $order->add_order_note($message); |
|
641 | 641 | } |
642 | 642 | } |
643 | 643 | |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | * @version 4.0.0 |
649 | 649 | * @param object $notification |
650 | 650 | */ |
651 | - public function is_partial_capture( $notification ) { |
|
651 | + public function is_partial_capture($notification) { |
|
652 | 652 | return 0 < $notification->data->object->amount_refunded; |
653 | 653 | } |
654 | 654 | |
@@ -659,11 +659,11 @@ discard block |
||
659 | 659 | * @version 4.0.0 |
660 | 660 | * @param object $notification |
661 | 661 | */ |
662 | - public function get_refund_amount( $notification ) { |
|
663 | - if ( $this->is_partial_capture( $notification ) ) { |
|
662 | + public function get_refund_amount($notification) { |
|
663 | + if ($this->is_partial_capture($notification)) { |
|
664 | 664 | $amount = $notification->data->object->refunds->data[0]->amount / 100; |
665 | 665 | |
666 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
666 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
667 | 667 | $amount = $notification->data->object->refunds->data[0]->amount; |
668 | 668 | } |
669 | 669 | |
@@ -680,12 +680,12 @@ discard block |
||
680 | 680 | * @version 4.0.0 |
681 | 681 | * @param object $notification |
682 | 682 | */ |
683 | - public function get_partial_amount_to_charge( $notification ) { |
|
684 | - if ( $this->is_partial_capture( $notification ) ) { |
|
685 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100; |
|
683 | + public function get_partial_amount_to_charge($notification) { |
|
684 | + if ($this->is_partial_capture($notification)) { |
|
685 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100; |
|
686 | 686 | |
687 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
688 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ); |
|
687 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
688 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded); |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | return $amount; |
@@ -694,75 +694,75 @@ discard block |
||
694 | 694 | return false; |
695 | 695 | } |
696 | 696 | |
697 | - public function process_payment_intent_success( $notification ) { |
|
697 | + public function process_payment_intent_success($notification) { |
|
698 | 698 | $intent = $notification->data->object; |
699 | - $order = WC_Stripe_Helper::get_order_by_intent_id( $intent->id ); |
|
699 | + $order = WC_Stripe_Helper::get_order_by_intent_id($intent->id); |
|
700 | 700 | |
701 | - if ( ! $order ) { |
|
702 | - WC_Stripe_Logger::log( 'Could not find order via intent ID: ' . $intent->id ); |
|
701 | + if ( ! $order) { |
|
702 | + WC_Stripe_Logger::log('Could not find order via intent ID: ' . $intent->id); |
|
703 | 703 | return; |
704 | 704 | } |
705 | 705 | |
706 | - if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
706 | + if ( ! $order->has_status(array('pending', 'failed'))) { |
|
707 | 707 | return; |
708 | 708 | } |
709 | 709 | |
710 | - if ( $this->lock_order_payment( $order, $intent ) ) { |
|
710 | + if ($this->lock_order_payment($order, $intent)) { |
|
711 | 711 | return; |
712 | 712 | } |
713 | 713 | |
714 | 714 | $order_id = $order->get_id(); |
715 | - if ( 'payment_intent.succeeded' === $notification->type || 'payment_intent.amount_capturable_updated' === $notification->type ) { |
|
716 | - $charge = end( $intent->charges->data ); |
|
717 | - WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id succeeded for order $order_id" ); |
|
715 | + if ('payment_intent.succeeded' === $notification->type || 'payment_intent.amount_capturable_updated' === $notification->type) { |
|
716 | + $charge = end($intent->charges->data); |
|
717 | + WC_Stripe_Logger::log("Stripe PaymentIntent $intent->id succeeded for order $order_id"); |
|
718 | 718 | |
719 | - do_action( 'wc_gateway_stripe_process_payment', $charge, $order ); |
|
719 | + do_action('wc_gateway_stripe_process_payment', $charge, $order); |
|
720 | 720 | |
721 | 721 | // Process valid response. |
722 | - $this->process_response( $charge, $order ); |
|
722 | + $this->process_response($charge, $order); |
|
723 | 723 | |
724 | 724 | } else { |
725 | 725 | $error_message = $intent->last_payment_error ? $intent->last_payment_error->message : ""; |
726 | 726 | |
727 | 727 | /* translators: 1) The error message that was received from Stripe. */ |
728 | - $message = sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message ); |
|
728 | + $message = sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $error_message); |
|
729 | 729 | |
730 | - if ( ! $order->get_meta( '_stripe_status_final', false ) ) { |
|
731 | - $order->update_status( 'failed', $message ); |
|
730 | + if ( ! $order->get_meta('_stripe_status_final', false)) { |
|
731 | + $order->update_status('failed', $message); |
|
732 | 732 | } else { |
733 | - $order->add_order_note( $message ); |
|
733 | + $order->add_order_note($message); |
|
734 | 734 | } |
735 | 735 | |
736 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
736 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
737 | 737 | |
738 | - $this->send_failed_order_email( $order_id ); |
|
738 | + $this->send_failed_order_email($order_id); |
|
739 | 739 | } |
740 | 740 | |
741 | - $this->unlock_order_payment( $order ); |
|
741 | + $this->unlock_order_payment($order); |
|
742 | 742 | } |
743 | 743 | |
744 | - public function process_setup_intent( $notification ) { |
|
744 | + public function process_setup_intent($notification) { |
|
745 | 745 | $intent = $notification->data->object; |
746 | - $order = WC_Stripe_Helper::get_order_by_setup_intent_id( $intent->id ); |
|
746 | + $order = WC_Stripe_Helper::get_order_by_setup_intent_id($intent->id); |
|
747 | 747 | |
748 | - if ( ! $order ) { |
|
749 | - WC_Stripe_Logger::log( 'Could not find order via setup intent ID: ' . $intent->id ); |
|
748 | + if ( ! $order) { |
|
749 | + WC_Stripe_Logger::log('Could not find order via setup intent ID: ' . $intent->id); |
|
750 | 750 | return; |
751 | 751 | } |
752 | 752 | |
753 | - if ( ! $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
753 | + if ( ! $order->has_status(array('pending', 'failed'))) { |
|
754 | 754 | return; |
755 | 755 | } |
756 | 756 | |
757 | - if ( $this->lock_order_payment( $order, $intent ) ) { |
|
757 | + if ($this->lock_order_payment($order, $intent)) { |
|
758 | 758 | return; |
759 | 759 | } |
760 | 760 | |
761 | 761 | $order_id = $order->get_id(); |
762 | - if ( 'setup_intent.succeeded' === $notification->type ) { |
|
763 | - WC_Stripe_Logger::log( "Stripe SetupIntent $intent->id succeeded for order $order_id" ); |
|
764 | - if ( WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order( $order ) ) { |
|
765 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
762 | + if ('setup_intent.succeeded' === $notification->type) { |
|
763 | + WC_Stripe_Logger::log("Stripe SetupIntent $intent->id succeeded for order $order_id"); |
|
764 | + if (WC_Stripe_Helper::is_pre_orders_exists() && WC_Pre_Orders_Order::order_contains_pre_order($order)) { |
|
765 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
766 | 766 | } else { |
767 | 767 | $order->payment_complete(); |
768 | 768 | } |
@@ -770,18 +770,18 @@ discard block |
||
770 | 770 | $error_message = $intent->last_setup_error ? $intent->last_setup_error->message : ""; |
771 | 771 | |
772 | 772 | /* translators: 1) The error message that was received from Stripe. */ |
773 | - $message = sprintf( __( 'Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe' ), $error_message ); |
|
773 | + $message = sprintf(__('Stripe SCA authentication failed. Reason: %s', 'woocommerce-gateway-stripe'), $error_message); |
|
774 | 774 | |
775 | - if ( ! $order->get_meta( '_stripe_status_final', false ) ) { |
|
776 | - $order->update_status( 'failed', $message ); |
|
775 | + if ( ! $order->get_meta('_stripe_status_final', false)) { |
|
776 | + $order->update_status('failed', $message); |
|
777 | 777 | } else { |
778 | - $order->add_order_note( $message ); |
|
778 | + $order->add_order_note($message); |
|
779 | 779 | } |
780 | 780 | |
781 | - $this->send_failed_order_email( $order_id ); |
|
781 | + $this->send_failed_order_email($order_id); |
|
782 | 782 | } |
783 | 783 | |
784 | - $this->unlock_order_payment( $order ); |
|
784 | + $this->unlock_order_payment($order); |
|
785 | 785 | } |
786 | 786 | |
787 | 787 | /** |
@@ -791,59 +791,59 @@ discard block |
||
791 | 791 | * @version 4.0.0 |
792 | 792 | * @param string $request_body |
793 | 793 | */ |
794 | - public function process_webhook( $request_body ) { |
|
795 | - $notification = json_decode( $request_body ); |
|
794 | + public function process_webhook($request_body) { |
|
795 | + $notification = json_decode($request_body); |
|
796 | 796 | |
797 | - switch ( $notification->type ) { |
|
797 | + switch ($notification->type) { |
|
798 | 798 | case 'source.chargeable': |
799 | - $this->process_webhook_payment( $notification ); |
|
799 | + $this->process_webhook_payment($notification); |
|
800 | 800 | break; |
801 | 801 | |
802 | 802 | case 'source.canceled': |
803 | - $this->process_webhook_source_canceled( $notification ); |
|
803 | + $this->process_webhook_source_canceled($notification); |
|
804 | 804 | break; |
805 | 805 | |
806 | 806 | case 'charge.succeeded': |
807 | - $this->process_webhook_charge_succeeded( $notification ); |
|
807 | + $this->process_webhook_charge_succeeded($notification); |
|
808 | 808 | break; |
809 | 809 | |
810 | 810 | case 'charge.failed': |
811 | - $this->process_webhook_charge_failed( $notification ); |
|
811 | + $this->process_webhook_charge_failed($notification); |
|
812 | 812 | break; |
813 | 813 | |
814 | 814 | case 'charge.captured': |
815 | - $this->process_webhook_capture( $notification ); |
|
815 | + $this->process_webhook_capture($notification); |
|
816 | 816 | break; |
817 | 817 | |
818 | 818 | case 'charge.dispute.created': |
819 | - $this->process_webhook_dispute( $notification ); |
|
819 | + $this->process_webhook_dispute($notification); |
|
820 | 820 | break; |
821 | 821 | |
822 | 822 | case 'charge.dispute.closed': |
823 | - $this->process_webhook_dispute_closed( $notification ); |
|
823 | + $this->process_webhook_dispute_closed($notification); |
|
824 | 824 | break; |
825 | 825 | |
826 | 826 | case 'charge.refunded': |
827 | - $this->process_webhook_refund( $notification ); |
|
827 | + $this->process_webhook_refund($notification); |
|
828 | 828 | break; |
829 | 829 | |
830 | 830 | case 'review.opened': |
831 | - $this->process_review_opened( $notification ); |
|
831 | + $this->process_review_opened($notification); |
|
832 | 832 | break; |
833 | 833 | |
834 | 834 | case 'review.closed': |
835 | - $this->process_review_closed( $notification ); |
|
835 | + $this->process_review_closed($notification); |
|
836 | 836 | break; |
837 | 837 | |
838 | 838 | case 'payment_intent.succeeded': |
839 | 839 | case 'payment_intent.payment_failed': |
840 | 840 | case 'payment_intent.amount_capturable_updated': |
841 | - $this->process_payment_intent_success( $notification ); |
|
841 | + $this->process_payment_intent_success($notification); |
|
842 | 842 | break; |
843 | 843 | |
844 | 844 | case 'setup_intent.succeeded': |
845 | 845 | case 'setup_intent.setup_failed': |
846 | - $this->process_setup_intent( $notification ); |
|
846 | + $this->process_setup_intent($notification); |
|
847 | 847 | |
848 | 848 | } |
849 | 849 | } |