@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function __construct() { |
121 | 121 | $this->id = 'stripe'; |
122 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
122 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
123 | 123 | /* translators: 1) link to Stripe register page 2) link to Stripe api keys page */ |
124 | - $this->method_description = sprintf( __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' ); |
|
124 | + $this->method_description = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys'); |
|
125 | 125 | $this->has_fields = true; |
126 | 126 | $this->supports = array( |
127 | 127 | 'products', |
@@ -148,38 +148,38 @@ discard block |
||
148 | 148 | $this->init_settings(); |
149 | 149 | |
150 | 150 | // Get setting values. |
151 | - $this->title = $this->get_option( 'title' ); |
|
152 | - $this->description = $this->get_option( 'description' ); |
|
153 | - $this->enabled = $this->get_option( 'enabled' ); |
|
154 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
155 | - $this->inline_cc_form = 'yes' === $this->get_option( 'inline_cc_form' ); |
|
156 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
157 | - $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) ); |
|
158 | - $this->three_d_secure = 'yes' === $this->get_option( 'three_d_secure' ); |
|
159 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
160 | - $this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' ); |
|
161 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
162 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
163 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
164 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
165 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
166 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
167 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
151 | + $this->title = $this->get_option('title'); |
|
152 | + $this->description = $this->get_option('description'); |
|
153 | + $this->enabled = $this->get_option('enabled'); |
|
154 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
155 | + $this->inline_cc_form = 'yes' === $this->get_option('inline_cc_form'); |
|
156 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
157 | + $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor')); |
|
158 | + $this->three_d_secure = 'yes' === $this->get_option('three_d_secure'); |
|
159 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
160 | + $this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale'); |
|
161 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
162 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
163 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
164 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
165 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
166 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
167 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
168 | 168 | $this->apple_pay_verify_notice = ''; |
169 | 169 | |
170 | - if ( $this->stripe_checkout ) { |
|
171 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
170 | + if ($this->stripe_checkout) { |
|
171 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
172 | 172 | } |
173 | 173 | |
174 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
174 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
175 | 175 | |
176 | 176 | $this->init_apple_pay(); |
177 | 177 | |
178 | 178 | // Hooks. |
179 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
180 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
181 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
182 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
179 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
180 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
181 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
182 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @since 4.0.2 |
189 | 189 | */ |
190 | 190 | public function is_available() { |
191 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
191 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
192 | 192 | return false; |
193 | 193 | } |
194 | 194 | |
@@ -211,17 +211,17 @@ discard block |
||
211 | 211 | $icons_str .= $icons['amex']; |
212 | 212 | $icons_str .= $icons['mastercard']; |
213 | 213 | |
214 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
214 | + if ('USD' === get_woocommerce_currency()) { |
|
215 | 215 | $icons_str .= $icons['discover']; |
216 | 216 | $icons_str .= $icons['jcb']; |
217 | 217 | $icons_str .= $icons['diners']; |
218 | 218 | } |
219 | 219 | |
220 | - if ( $this->bitcoin && $this->stripe_checkout ) { |
|
220 | + if ($this->bitcoin && $this->stripe_checkout) { |
|
221 | 221 | $icons_str .= $icons['bitcoin']; |
222 | 222 | } |
223 | 223 | |
224 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
224 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -233,9 +233,9 @@ discard block |
||
233 | 233 | public function init_apple_pay() { |
234 | 234 | if ( |
235 | 235 | is_admin() && |
236 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
237 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
238 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] && |
|
236 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
237 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
238 | + isset($_GET['section']) && 'stripe' === $_GET['section'] && |
|
239 | 239 | $this->payment_request |
240 | 240 | ) { |
241 | 241 | $this->process_apple_pay_verification(); |
@@ -249,9 +249,9 @@ discard block |
||
249 | 249 | * @version 3.1.0 |
250 | 250 | * @param string $secret_key |
251 | 251 | */ |
252 | - private function register_apple_pay_domain( $secret_key = '' ) { |
|
253 | - if ( empty( $secret_key ) ) { |
|
254 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
252 | + private function register_apple_pay_domain($secret_key = '') { |
|
253 | + if (empty($secret_key)) { |
|
254 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -265,23 +265,23 @@ discard block |
||
265 | 265 | 'Authorization' => 'Bearer ' . $secret_key, |
266 | 266 | ); |
267 | 267 | |
268 | - $response = wp_remote_post( $endpoint, array( |
|
268 | + $response = wp_remote_post($endpoint, array( |
|
269 | 269 | 'headers' => $headers, |
270 | - 'body' => http_build_query( $data ), |
|
271 | - ) ); |
|
270 | + 'body' => http_build_query($data), |
|
271 | + )); |
|
272 | 272 | |
273 | - if ( is_wp_error( $response ) ) { |
|
273 | + if (is_wp_error($response)) { |
|
274 | 274 | /* translators: error message */ |
275 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
275 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
276 | 276 | } |
277 | 277 | |
278 | - if ( 200 !== $response['response']['code'] ) { |
|
279 | - $parsed_response = json_decode( $response['body'] ); |
|
278 | + if (200 !== $response['response']['code']) { |
|
279 | + $parsed_response = json_decode($response['body']); |
|
280 | 280 | |
281 | 281 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
282 | 282 | |
283 | 283 | /* translators: error message */ |
284 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
284 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
285 | 285 | } |
286 | 286 | } |
287 | 287 | |
@@ -292,48 +292,48 @@ discard block |
||
292 | 292 | * @version 3.1.0 |
293 | 293 | */ |
294 | 294 | public function process_apple_pay_verification() { |
295 | - $gateway_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
295 | + $gateway_settings = get_option('woocommerce_stripe_settings', array()); |
|
296 | 296 | |
297 | 297 | try { |
298 | - $path = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] ); |
|
298 | + $path = untrailingslashit($_SERVER['DOCUMENT_ROOT']); |
|
299 | 299 | $dir = '.well-known'; |
300 | 300 | $file = 'apple-developer-merchantid-domain-association'; |
301 | 301 | $fullpath = $path . '/' . $dir . '/' . $file; |
302 | 302 | |
303 | - if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) { |
|
303 | + if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) { |
|
304 | 304 | return; |
305 | 305 | } |
306 | 306 | |
307 | - if ( ! file_exists( $path . '/' . $dir ) ) { |
|
308 | - if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { |
|
309 | - throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
307 | + if ( ! file_exists($path . '/' . $dir)) { |
|
308 | + if ( ! @mkdir($path . '/' . $dir, 0755)) { |
|
309 | + throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
310 | 310 | } |
311 | 311 | } |
312 | 312 | |
313 | - if ( ! file_exists( $fullpath ) ) { |
|
314 | - if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { |
|
315 | - throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
313 | + if ( ! file_exists($fullpath)) { |
|
314 | + if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { |
|
315 | + throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
316 | 316 | } |
317 | 317 | } |
318 | 318 | |
319 | 319 | // At this point then the domain association folder and file should be available. |
320 | 320 | // Proceed to verify/and or verify again. |
321 | - $this->register_apple_pay_domain( $this->secret_key ); |
|
321 | + $this->register_apple_pay_domain($this->secret_key); |
|
322 | 322 | |
323 | 323 | // No errors to this point, verification success! |
324 | 324 | $gateway_settings['apple_pay_domain_set'] = 'yes'; |
325 | 325 | $this->apple_pay_domain_set = true; |
326 | 326 | |
327 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
327 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
328 | 328 | |
329 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
329 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
330 | 330 | |
331 | - } catch ( Exception $e ) { |
|
331 | + } catch (Exception $e) { |
|
332 | 332 | $gateway_settings['apple_pay_domain_set'] = 'no'; |
333 | 333 | |
334 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
334 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
335 | 335 | |
336 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
336 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
337 | 337 | } |
338 | 338 | } |
339 | 339 | |
@@ -341,11 +341,11 @@ discard block |
||
341 | 341 | * Check if SSL is enabled and notify the user |
342 | 342 | */ |
343 | 343 | public function admin_notices() { |
344 | - if ( 'no' === $this->enabled ) { |
|
344 | + if ('no' === $this->enabled) { |
|
345 | 345 | return; |
346 | 346 | } |
347 | 347 | |
348 | - if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) { |
|
348 | + if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) { |
|
349 | 349 | $allowed_html = array( |
350 | 350 | 'a' => array( |
351 | 351 | 'href' => array(), |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | ), |
354 | 354 | ); |
355 | 355 | |
356 | - echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>'; |
|
356 | + echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>'; |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
@@ -361,9 +361,9 @@ discard block |
||
361 | 361 | * when setting screen is displayed. So if domain verification is not set, |
362 | 362 | * something went wrong so lets notify user. |
363 | 363 | */ |
364 | - if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) { |
|
364 | + if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) { |
|
365 | 365 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
366 | - echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>'; |
|
366 | + echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>'; |
|
367 | 367 | } |
368 | 368 | } |
369 | 369 | |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | * Initialise Gateway Settings Form Fields |
372 | 372 | */ |
373 | 373 | public function init_form_fields() { |
374 | - $this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' ); |
|
374 | + $this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php'); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | /** |
@@ -379,59 +379,59 @@ discard block |
||
379 | 379 | */ |
380 | 380 | public function payment_fields() { |
381 | 381 | $user = wp_get_current_user(); |
382 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
382 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
383 | 383 | $total = WC()->cart->total; |
384 | 384 | $user_email = ''; |
385 | 385 | |
386 | 386 | // If paying from order, we need to get total from order not cart. |
387 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
388 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
387 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
388 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
389 | 389 | $total = $order->get_total(); |
390 | 390 | $user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
391 | 391 | } else { |
392 | - if ( $user->ID ) { |
|
393 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
392 | + if ($user->ID) { |
|
393 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
394 | 394 | $user_email = $user_email ? $user_email : $user->user_email; |
395 | 395 | } |
396 | 396 | } |
397 | 397 | |
398 | - if ( is_add_payment_method_page() ) { |
|
399 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
400 | - $total = ''; |
|
398 | + if (is_add_payment_method_page()) { |
|
399 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
400 | + $total = ''; |
|
401 | 401 | } else { |
402 | 402 | $pay_button_text = ''; |
403 | 403 | } |
404 | 404 | |
405 | 405 | echo '<div |
406 | 406 | id="stripe-payment-data" |
407 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
407 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
408 | 408 | data-description="" |
409 | - data-email="' . esc_attr( $user_email ) . '" |
|
410 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
411 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
412 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
413 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
414 | - data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '" |
|
415 | - data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '" |
|
416 | - data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '" |
|
417 | - data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">'; |
|
418 | - |
|
419 | - if ( $this->description ) { |
|
420 | - if ( $this->testmode ) { |
|
409 | + data-email="' . esc_attr($user_email) . '" |
|
410 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
411 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
412 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
413 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
414 | + data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '" |
|
415 | + data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '" |
|
416 | + data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '" |
|
417 | + data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">'; |
|
418 | + |
|
419 | + if ($this->description) { |
|
420 | + if ($this->testmode) { |
|
421 | 421 | /* translators: link to Stripe testing page */ |
422 | - $this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
423 | - $this->description = trim( $this->description ); |
|
422 | + $this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
423 | + $this->description = trim($this->description); |
|
424 | 424 | } |
425 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
425 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
426 | 426 | } |
427 | 427 | |
428 | - if ( $display_tokenization ) { |
|
428 | + if ($display_tokenization) { |
|
429 | 429 | $this->tokenization_script(); |
430 | 430 | $this->saved_payment_methods(); |
431 | 431 | } |
432 | 432 | |
433 | - if ( ! $this->stripe_checkout ) { |
|
434 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
433 | + if ( ! $this->stripe_checkout) { |
|
434 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
435 | 435 | $this->elements_form(); |
436 | 436 | } else { |
437 | 437 | $this->form(); |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | } |
440 | 440 | } |
441 | 441 | |
442 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
442 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
443 | 443 | $this->save_payment_method_checkbox(); |
444 | 444 | } |
445 | 445 | |
@@ -454,12 +454,12 @@ discard block |
||
454 | 454 | */ |
455 | 455 | public function elements_form() { |
456 | 456 | ?> |
457 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
458 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
457 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
458 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
459 | 459 | |
460 | - <?php if ( $this->inline_cc_form ) { ?> |
|
460 | + <?php if ($this->inline_cc_form) { ?> |
|
461 | 461 | <label for="card-element"> |
462 | - <?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?> |
|
462 | + <?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?> |
|
463 | 463 | </label> |
464 | 464 | |
465 | 465 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | </div> |
468 | 468 | <?php } else { ?> |
469 | 469 | <div class="form-row form-row-wide"> |
470 | - <label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?><span class="required">*</span></label> |
|
470 | + <label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?><span class="required">*</span></label> |
|
471 | 471 | |
472 | 472 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
473 | 473 | <!-- a Stripe Element will be inserted here. --> |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | </div> |
476 | 476 | |
477 | 477 | <div class="form-row form-row-first"> |
478 | - <label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?><span class="required">*</span></label> |
|
478 | + <label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?><span class="required">*</span></label> |
|
479 | 479 | |
480 | 480 | <div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
481 | 481 | <!-- a Stripe Element will be inserted here. --> |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | </div> |
484 | 484 | |
485 | 485 | <div class="form-row form-row-last"> |
486 | - <label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?><span class="required">*</span></label> |
|
486 | + <label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?><span class="required">*</span></label> |
|
487 | 487 | <div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
488 | 488 | <!-- a Stripe Element will be inserted here. --> |
489 | 489 | </div> |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | |
494 | 494 | <!-- Used to display form errors --> |
495 | 495 | <div class="stripe-source-errors" role="alert"></div> |
496 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
496 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
497 | 497 | <div class="clear"></div> |
498 | 498 | </fieldset> |
499 | 499 | <?php |
@@ -506,13 +506,13 @@ discard block |
||
506 | 506 | * @version 3.1.0 |
507 | 507 | */ |
508 | 508 | public function admin_scripts() { |
509 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
509 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
510 | 510 | return; |
511 | 511 | } |
512 | 512 | |
513 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
513 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
514 | 514 | |
515 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
515 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | /** |
@@ -524,29 +524,29 @@ discard block |
||
524 | 524 | * @version 4.0.0 |
525 | 525 | */ |
526 | 526 | public function payment_scripts() { |
527 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
527 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
528 | 528 | return; |
529 | 529 | } |
530 | 530 | |
531 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
531 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
532 | 532 | |
533 | - wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' ); |
|
534 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
535 | - wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true ); |
|
536 | - wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true ); |
|
537 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
538 | - wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripev2', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
533 | + wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5'); |
|
534 | + wp_enqueue_style('stripe_paymentfonts'); |
|
535 | + wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true); |
|
536 | + wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true); |
|
537 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
538 | + wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripev2', 'stripe'), WC_STRIPE_VERSION, true); |
|
539 | 539 | |
540 | 540 | $stripe_params = array( |
541 | 541 | 'key' => $this->publishable_key, |
542 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
543 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
542 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
543 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
544 | 544 | ); |
545 | 545 | |
546 | 546 | // If we're on the pay page we need to pass stripe.js the address of the order. |
547 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
548 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
549 | - $order = wc_get_order( $order_id ); |
|
547 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
548 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
549 | + $order = wc_get_order($order_id); |
|
550 | 550 | |
551 | 551 | $stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
552 | 552 | $stripe_params['billing_last_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
@@ -558,37 +558,37 @@ discard block |
||
558 | 558 | $stripe_params['billing_country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
559 | 559 | } |
560 | 560 | |
561 | - $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
562 | - $stripe_params['no_bank_country_msg'] = __( 'Please select a country for your bank.', 'woocommerce-gateway-stripe' ); |
|
563 | - $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
564 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
565 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
561 | + $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
562 | + $stripe_params['no_bank_country_msg'] = __('Please select a country for your bank.', 'woocommerce-gateway-stripe'); |
|
563 | + $stripe_params['no_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
564 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
565 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
566 | 566 | $stripe_params['inline_cc_form'] = $this->inline_cc_form ? 'yes' : 'no'; |
567 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
568 | - $stripe_params['is_checkout'] = ( is_checkout() && empty( $_GET['pay_for_order'] ) ); |
|
567 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
568 | + $stripe_params['is_checkout'] = (is_checkout() && empty($_GET['pay_for_order'])); |
|
569 | 569 | $stripe_params['return_url'] = $this->get_stripe_return_url(); |
570 | - $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); |
|
571 | - $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); |
|
570 | + $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint('%%endpoint%%'); |
|
571 | + $stripe_params['stripe_nonce'] = wp_create_nonce('_wc_stripe_nonce'); |
|
572 | 572 | $stripe_params['statement_descriptor'] = $this->statement_descriptor; |
573 | - $stripe_params['use_elements'] = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no'; |
|
573 | + $stripe_params['use_elements'] = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no'; |
|
574 | 574 | $stripe_params['is_stripe_checkout'] = $this->stripe_checkout ? 'yes' : 'no'; |
575 | - $stripe_params['is_change_payment_page'] = ( isset( $_GET['pay_for_order'] ) || isset( $_GET['change_payment_method'] ) ) ? 'yes' : 'no'; |
|
575 | + $stripe_params['is_change_payment_page'] = (isset($_GET['pay_for_order']) || isset($_GET['change_payment_method'])) ? 'yes' : 'no'; |
|
576 | 576 | $stripe_params['is_add_payment_method_page'] = is_add_payment_method_page() ? 'yes' : 'no'; |
577 | - $stripe_params['elements_styling'] = apply_filters( 'wc_stripe_elements_styling', false ); |
|
578 | - $stripe_params['elements_classes'] = apply_filters( 'wc_stripe_elements_classes', false ); |
|
577 | + $stripe_params['elements_styling'] = apply_filters('wc_stripe_elements_styling', false); |
|
578 | + $stripe_params['elements_classes'] = apply_filters('wc_stripe_elements_classes', false); |
|
579 | 579 | |
580 | 580 | // merge localized messages to be use in JS |
581 | - $stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() ); |
|
581 | + $stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages()); |
|
582 | 582 | |
583 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
584 | - wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
583 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
584 | + wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
585 | 585 | |
586 | - if ( $this->stripe_checkout ) { |
|
587 | - wp_enqueue_script( 'stripe_checkout' ); |
|
586 | + if ($this->stripe_checkout) { |
|
587 | + wp_enqueue_script('stripe_checkout'); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | $this->tokenization_script(); |
591 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
591 | + wp_enqueue_script('woocommerce_stripe'); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | /** |
@@ -600,22 +600,22 @@ discard block |
||
600 | 600 | * @param object $source_object |
601 | 601 | * @return mixed |
602 | 602 | */ |
603 | - public function create_3ds_source( $order, $source_object ) { |
|
603 | + public function create_3ds_source($order, $source_object) { |
|
604 | 604 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
605 | 605 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
606 | - $return_url = $this->get_stripe_return_url( $order ); |
|
606 | + $return_url = $this->get_stripe_return_url($order); |
|
607 | 607 | |
608 | 608 | $post_data = array(); |
609 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
610 | - $post_data['currency'] = strtolower( $currency ); |
|
609 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
610 | + $post_data['currency'] = strtolower($currency); |
|
611 | 611 | $post_data['type'] = 'three_d_secure'; |
612 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
613 | - $post_data['three_d_secure'] = array( 'card' => $source_object->id ); |
|
614 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
612 | + $post_data['owner'] = $this->get_owner_details($order); |
|
613 | + $post_data['three_d_secure'] = array('card' => $source_object->id); |
|
614 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
615 | 615 | |
616 | - WC_Stripe_Logger::log( 'Info: Begin creating 3DS source' ); |
|
616 | + WC_Stripe_Logger::log('Info: Begin creating 3DS source'); |
|
617 | 617 | |
618 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
618 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | /** |
@@ -631,46 +631,46 @@ discard block |
||
631 | 631 | * |
632 | 632 | * @return array|void |
633 | 633 | */ |
634 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
634 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
635 | 635 | try { |
636 | - $order = wc_get_order( $order_id ); |
|
637 | - $source_object = ! empty( $_POST['stripe_source'] ) ? json_decode( wc_clean( stripslashes( $_POST['stripe_source'] ) ) ) : false; |
|
636 | + $order = wc_get_order($order_id); |
|
637 | + $source_object = ! empty($_POST['stripe_source']) ? json_decode(wc_clean(stripslashes($_POST['stripe_source']))) : false; |
|
638 | 638 | |
639 | 639 | // This comes from the create account checkbox in the checkout page. |
640 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
640 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
641 | 641 | |
642 | - if ( $create_account ) { |
|
642 | + if ($create_account) { |
|
643 | 643 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
644 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
644 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
645 | 645 | $new_stripe_customer->create_customer(); |
646 | 646 | } |
647 | 647 | |
648 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
648 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
649 | 649 | |
650 | 650 | // Check if we don't allow prepaid credit cards. |
651 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) { |
|
652 | - $stripe_checkout_object = ! empty( $_POST['stripe_checkout_object'] ) ? json_decode( wc_clean( stripslashes( $_POST['stripe_checkout_object'] ) ) ) : false; |
|
651 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) { |
|
652 | + $stripe_checkout_object = ! empty($_POST['stripe_checkout_object']) ? json_decode(wc_clean(stripslashes($_POST['stripe_checkout_object']))) : false; |
|
653 | 653 | |
654 | - if ( $stripe_checkout_object && 'token' === $stripe_checkout_object->object && 'prepaid' === $stripe_checkout_object->card->funding ) { |
|
655 | - $localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
656 | - throw new WC_Stripe_Exception( print_r( $stripe_checkout_object, true ), $localized_message ); |
|
654 | + if ($stripe_checkout_object && 'token' === $stripe_checkout_object->object && 'prepaid' === $stripe_checkout_object->card->funding) { |
|
655 | + $localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
656 | + throw new WC_Stripe_Exception(print_r($stripe_checkout_object, true), $localized_message); |
|
657 | 657 | } |
658 | 658 | } |
659 | 659 | |
660 | - if ( empty( $prepared_source->source ) ) { |
|
661 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
662 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
660 | + if (empty($prepared_source->source)) { |
|
661 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
662 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
663 | 663 | } |
664 | 664 | |
665 | 665 | // Store source to order meta. |
666 | - $this->save_source( $order, $prepared_source ); |
|
666 | + $this->save_source($order, $prepared_source); |
|
667 | 667 | |
668 | 668 | // Result from Stripe API request. |
669 | 669 | $response = null; |
670 | 670 | |
671 | - if ( $order->get_total() > 0 ) { |
|
671 | + if ($order->get_total() > 0) { |
|
672 | 672 | // This will throw exception if not valid. |
673 | - $this->validate_minimum_order_amount( $order ); |
|
673 | + $this->validate_minimum_order_amount($order); |
|
674 | 674 | |
675 | 675 | /** |
676 | 676 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -679,83 +679,83 @@ discard block |
||
679 | 679 | * Note that if we need to save source, the original source must be first |
680 | 680 | * attached to a customer in Stripe before it can be charged. |
681 | 681 | */ |
682 | - if ( $source_object && ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) ) ) { |
|
682 | + if ($source_object && ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure))) { |
|
683 | 683 | |
684 | - $response = $this->create_3ds_source( $order, $source_object ); |
|
684 | + $response = $this->create_3ds_source($order, $source_object); |
|
685 | 685 | |
686 | - if ( ! empty( $response->error ) ) { |
|
686 | + if ( ! empty($response->error)) { |
|
687 | 687 | $localized_message = $response->error->message; |
688 | 688 | |
689 | - $order->add_order_note( $localized_message ); |
|
689 | + $order->add_order_note($localized_message); |
|
690 | 690 | |
691 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
691 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
692 | 692 | } |
693 | 693 | |
694 | 694 | // Update order meta with 3DS source. |
695 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
696 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
695 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
696 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
697 | 697 | } else { |
698 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
698 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
699 | 699 | $order->save(); |
700 | 700 | } |
701 | 701 | |
702 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
702 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
703 | 703 | |
704 | 704 | return array( |
705 | 705 | 'result' => 'success', |
706 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
706 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
707 | 707 | ); |
708 | 708 | } |
709 | 709 | |
710 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
710 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
711 | 711 | |
712 | 712 | // Make the request. |
713 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
713 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
714 | 714 | |
715 | - if ( ! empty( $response->error ) ) { |
|
715 | + if ( ! empty($response->error)) { |
|
716 | 716 | // If it is an API error such connection or server, let's retry. |
717 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
718 | - if ( $retry ) { |
|
719 | - sleep( 5 ); |
|
720 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
717 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
718 | + if ($retry) { |
|
719 | + sleep(5); |
|
720 | + return $this->process_payment($order_id, false, $force_save_source); |
|
721 | 721 | } else { |
722 | 722 | $localized_message = 'API connection error and retries exhausted.'; |
723 | - $order->add_order_note( $localized_message ); |
|
724 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
723 | + $order->add_order_note($localized_message); |
|
724 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
725 | 725 | } |
726 | 726 | } |
727 | 727 | |
728 | 728 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
729 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
730 | - delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
729 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
730 | + delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id'); |
|
731 | 731 | |
732 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
733 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) { |
|
732 | + return $this->process_payment($order_id, false, $force_save_source); |
|
733 | + } elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) { |
|
734 | 734 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
735 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
735 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
736 | 736 | $wc_token->delete(); |
737 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
738 | - $order->add_order_note( $localized_message ); |
|
739 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
737 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
738 | + $order->add_order_note($localized_message); |
|
739 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
740 | 740 | } |
741 | 741 | |
742 | 742 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
743 | 743 | |
744 | - if ( 'card_error' === $response->error->type ) { |
|
745 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
744 | + if ('card_error' === $response->error->type) { |
|
745 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
746 | 746 | } else { |
747 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
747 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
748 | 748 | } |
749 | 749 | |
750 | - $order->add_order_note( $localized_message ); |
|
750 | + $order->add_order_note($localized_message); |
|
751 | 751 | |
752 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
752 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
753 | 753 | } |
754 | 754 | |
755 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
755 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
756 | 756 | |
757 | 757 | // Process valid response. |
758 | - $this->process_response( $response, $order ); |
|
758 | + $this->process_response($response, $order); |
|
759 | 759 | } else { |
760 | 760 | $order->payment_complete(); |
761 | 761 | } |
@@ -766,17 +766,17 @@ discard block |
||
766 | 766 | // Return thank you page redirect. |
767 | 767 | return array( |
768 | 768 | 'result' => 'success', |
769 | - 'redirect' => $this->get_return_url( $order ), |
|
769 | + 'redirect' => $this->get_return_url($order), |
|
770 | 770 | ); |
771 | 771 | |
772 | - } catch ( WC_Stripe_Exception $e ) { |
|
773 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
774 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
772 | + } catch (WC_Stripe_Exception $e) { |
|
773 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
774 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
775 | 775 | |
776 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
776 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
777 | 777 | |
778 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
779 | - $this->send_failed_order_email( $order_id ); |
|
778 | + if ($order->has_status(array('pending', 'failed'))) { |
|
779 | + $this->send_failed_order_email($order_id); |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * @version 4.0.0 |
18 | 18 | */ |
19 | 19 | public function __construct() { |
20 | - add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) ); |
|
20 | + add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook')); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
@@ -27,24 +27,24 @@ discard block |
||
27 | 27 | * @version 4.0.0 |
28 | 28 | */ |
29 | 29 | public function check_for_webhook() { |
30 | - if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) |
|
31 | - || ! isset( $_GET['wc-api'] ) |
|
32 | - || ( 'wc_stripe' !== $_GET['wc-api'] ) |
|
30 | + if (('POST' !== $_SERVER['REQUEST_METHOD']) |
|
31 | + || ! isset($_GET['wc-api']) |
|
32 | + || ('wc_stripe' !== $_GET['wc-api']) |
|
33 | 33 | ) { |
34 | 34 | return; |
35 | 35 | } |
36 | 36 | |
37 | - $request_body = file_get_contents( 'php://input' ); |
|
38 | - $request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER ); |
|
37 | + $request_body = file_get_contents('php://input'); |
|
38 | + $request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER); |
|
39 | 39 | |
40 | 40 | // Validate it to make sure it is legit. |
41 | - if ( $this->is_valid_request( $request_headers, $request_body ) ) { |
|
42 | - $this->process_webhook( $request_body ); |
|
43 | - status_header( 200 ); |
|
41 | + if ($this->is_valid_request($request_headers, $request_body)) { |
|
42 | + $this->process_webhook($request_body); |
|
43 | + status_header(200); |
|
44 | 44 | exit; |
45 | 45 | } else { |
46 | - WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) ); |
|
47 | - status_header( 400 ); |
|
46 | + WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true)); |
|
47 | + status_header(400); |
|
48 | 48 | exit; |
49 | 49 | } |
50 | 50 | } |
@@ -59,12 +59,12 @@ discard block |
||
59 | 59 | * @param string $request_body The request body from Stripe. |
60 | 60 | * @return bool |
61 | 61 | */ |
62 | - public function is_valid_request( $request_headers = null, $request_body = null ) { |
|
63 | - if ( null === $request_headers || null === $request_body ) { |
|
62 | + public function is_valid_request($request_headers = null, $request_body = null) { |
|
63 | + if (null === $request_headers || null === $request_body) { |
|
64 | 64 | return false; |
65 | 65 | } |
66 | 66 | |
67 | - if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) { |
|
67 | + if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) { |
|
68 | 68 | return false; |
69 | 69 | } |
70 | 70 | |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | * @version 4.0.0 |
81 | 81 | */ |
82 | 82 | public function get_request_headers() { |
83 | - if ( ! function_exists( 'getallheaders' ) ) { |
|
83 | + if ( ! function_exists('getallheaders')) { |
|
84 | 84 | $headers = []; |
85 | - foreach ( $_SERVER as $name => $value ) { |
|
86 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
87 | - $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
85 | + foreach ($_SERVER as $name => $value) { |
|
86 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
87 | + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
@@ -103,30 +103,30 @@ discard block |
||
103 | 103 | * @param object $notification |
104 | 104 | * @param bool $retry |
105 | 105 | */ |
106 | - public function process_webhook_payment( $notification, $retry = true ) { |
|
106 | + public function process_webhook_payment($notification, $retry = true) { |
|
107 | 107 | // The following 2 payment methods are synchronous so does not need to be handle via webhook. |
108 | - if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) { |
|
108 | + if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) { |
|
109 | 109 | return; |
110 | 110 | } |
111 | 111 | |
112 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
112 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
113 | 113 | |
114 | - if ( ! $order ) { |
|
115 | - WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id ); |
|
114 | + if ( ! $order) { |
|
115 | + WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id); |
|
116 | 116 | return; |
117 | 117 | } |
118 | 118 | |
119 | 119 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
120 | 120 | $source_id = $notification->data->object->id; |
121 | 121 | |
122 | - $is_pending_receiver = ( 'receiver' === $notification->data->object->flow ); |
|
122 | + $is_pending_receiver = ('receiver' === $notification->data->object->flow); |
|
123 | 123 | |
124 | 124 | try { |
125 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) { |
|
125 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status()) { |
|
126 | 126 | return; |
127 | 127 | } |
128 | 128 | |
129 | - if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) { |
|
129 | + if ('on-hold' === $order->get_status() && ! $is_pending_receiver) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | 132 | |
@@ -134,73 +134,73 @@ discard block |
||
134 | 134 | $response = null; |
135 | 135 | |
136 | 136 | // This will throw exception if not valid. |
137 | - $this->validate_minimum_order_amount( $order ); |
|
137 | + $this->validate_minimum_order_amount($order); |
|
138 | 138 | |
139 | - WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
139 | + WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
140 | 140 | |
141 | 141 | // Prep source object. |
142 | 142 | $source_object = new stdClass(); |
143 | 143 | $source_object->token_id = ''; |
144 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
144 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
145 | 145 | $source_object->source = $source_id; |
146 | 146 | |
147 | 147 | // Make the request. |
148 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) ); |
|
148 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object)); |
|
149 | 149 | |
150 | - if ( ! empty( $response->error ) ) { |
|
150 | + if ( ! empty($response->error)) { |
|
151 | 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 ); |
|
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 | 156 | } else { |
157 | 157 | $localized_message = 'API connection error and retries exhausted.'; |
158 | - $order->add_order_note( $localized_message ); |
|
159 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
158 | + $order->add_order_note($localized_message); |
|
159 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | 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' ); |
|
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 | 166 | |
167 | - return $this->process_payment( $order_id, false ); |
|
167 | + return $this->process_payment($order_id, false); |
|
168 | 168 | |
169 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
169 | + } elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) { |
|
170 | 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 ); |
|
171 | + $wc_token = WC_Payment_Tokens::get($source_object->token_id); |
|
172 | 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 WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
173 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
174 | + $order->add_order_note($message); |
|
175 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
179 | 179 | |
180 | - if ( 'card_error' === $response->error->type ) { |
|
181 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
180 | + if ('card_error' === $response->error->type) { |
|
181 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
182 | 182 | } else { |
183 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
183 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
184 | 184 | } |
185 | 185 | |
186 | - $order->add_order_note( $localized_message ); |
|
186 | + $order->add_order_note($localized_message); |
|
187 | 187 | |
188 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
188 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
189 | 189 | } |
190 | 190 | |
191 | - do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order ); |
|
191 | + do_action('wc_gateway_stripe_process_webhook_payment', $response, $order); |
|
192 | 192 | |
193 | - $this->process_response( $response, $order ); |
|
193 | + $this->process_response($response, $order); |
|
194 | 194 | |
195 | - } catch ( WC_Stripe_Exception $e ) { |
|
196 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
195 | + } catch (WC_Stripe_Exception $e) { |
|
196 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
197 | 197 | |
198 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order ); |
|
198 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order); |
|
199 | 199 | |
200 | - $statuses = array( 'pending', 'failed' ); |
|
200 | + $statuses = array('pending', 'failed'); |
|
201 | 201 | |
202 | - if ( $order->has_status( $statuses ) ) { |
|
203 | - $this->send_failed_order_email( $order_id ); |
|
202 | + if ($order->has_status($statuses)) { |
|
203 | + $this->send_failed_order_email($order_id); |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 | } |
@@ -214,18 +214,18 @@ discard block |
||
214 | 214 | * @version 4.0.0 |
215 | 215 | * @param object $notification |
216 | 216 | */ |
217 | - public function process_webhook_dispute( $notification ) { |
|
218 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
217 | + public function process_webhook_dispute($notification) { |
|
218 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
219 | 219 | |
220 | - if ( ! $order ) { |
|
221 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
220 | + if ( ! $order) { |
|
221 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
222 | 222 | return; |
223 | 223 | } |
224 | 224 | |
225 | - $order->update_status( 'on-hold', __( 'A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe' ) ); |
|
225 | + $order->update_status('on-hold', __('A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe')); |
|
226 | 226 | |
227 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
228 | - $this->send_failed_order_email( $order_id ); |
|
227 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
228 | + $this->send_failed_order_email($order_id); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -236,41 +236,41 @@ discard block |
||
236 | 236 | * @version 4.0.0 |
237 | 237 | * @param object $notification |
238 | 238 | */ |
239 | - public function process_webhook_capture( $notification ) { |
|
240 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
239 | + public function process_webhook_capture($notification) { |
|
240 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
241 | 241 | |
242 | - if ( ! $order ) { |
|
243 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
242 | + if ( ! $order) { |
|
243 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
244 | 244 | return; |
245 | 245 | } |
246 | 246 | |
247 | 247 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
248 | 248 | |
249 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
250 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
251 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
249 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
250 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
251 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
252 | 252 | |
253 | - if ( $charge && 'no' === $captured ) { |
|
254 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
253 | + if ($charge && 'no' === $captured) { |
|
254 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
255 | 255 | |
256 | 256 | // Store other data such as fees |
257 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
257 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
258 | 258 | |
259 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
260 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
259 | + if (isset($notification->data->object->balance_transaction)) { |
|
260 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
261 | 261 | } |
262 | 262 | |
263 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
263 | + if (is_callable(array($order, 'save'))) { |
|
264 | 264 | $order->save(); |
265 | 265 | } |
266 | 266 | |
267 | 267 | /* translators: transaction id */ |
268 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
268 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
269 | 269 | |
270 | 270 | // Check and see if capture is partial. |
271 | - if ( $this->is_partial_capture( $notification ) ) { |
|
272 | - $order->set_total( $this->get_partial_amount_to_charge( $notification ) ); |
|
273 | - $order->add_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) ); |
|
271 | + if ($this->is_partial_capture($notification)) { |
|
272 | + $order->set_total($this->get_partial_amount_to_charge($notification)); |
|
273 | + $order->add_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe')); |
|
274 | 274 | $order->save(); |
275 | 275 | } |
276 | 276 | } |
@@ -285,38 +285,38 @@ discard block |
||
285 | 285 | * @version 4.0.0 |
286 | 286 | * @param object $notification |
287 | 287 | */ |
288 | - public function process_webhook_charge_succeeded( $notification ) { |
|
288 | + public function process_webhook_charge_succeeded($notification) { |
|
289 | 289 | // The following payment methods are synchronous so does not need to be handle via webhook. |
290 | - 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 ) ) { |
|
290 | + 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)) { |
|
291 | 291 | return; |
292 | 292 | } |
293 | 293 | |
294 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
294 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
295 | 295 | |
296 | - if ( ! $order ) { |
|
297 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
296 | + if ( ! $order) { |
|
297 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
298 | 298 | return; |
299 | 299 | } |
300 | 300 | |
301 | 301 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
302 | 302 | |
303 | - if ( 'on-hold' !== $order->get_status() ) { |
|
303 | + if ('on-hold' !== $order->get_status()) { |
|
304 | 304 | return; |
305 | 305 | } |
306 | 306 | |
307 | 307 | // Store other data such as fees |
308 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
308 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
309 | 309 | |
310 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
311 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
310 | + if (isset($notification->data->object->balance_transaction)) { |
|
311 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
312 | 312 | } |
313 | 313 | |
314 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
314 | + if (is_callable(array($order, 'save'))) { |
|
315 | 315 | $order->save(); |
316 | 316 | } |
317 | 317 | |
318 | 318 | /* translators: transaction id */ |
319 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
319 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
@@ -327,23 +327,23 @@ discard block |
||
327 | 327 | * @version 4.0.0 |
328 | 328 | * @param object $notification |
329 | 329 | */ |
330 | - public function process_webhook_charge_failed( $notification ) { |
|
331 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
330 | + public function process_webhook_charge_failed($notification) { |
|
331 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
332 | 332 | |
333 | - if ( ! $order ) { |
|
334 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
333 | + if ( ! $order) { |
|
334 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
335 | 335 | return; |
336 | 336 | } |
337 | 337 | |
338 | 338 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
339 | 339 | |
340 | - if ( 'on-hold' !== $order->get_status() ) { |
|
340 | + if ('on-hold' !== $order->get_status()) { |
|
341 | 341 | return; |
342 | 342 | } |
343 | 343 | |
344 | - $order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) ); |
|
344 | + $order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe')); |
|
345 | 345 | |
346 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
346 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | /** |
@@ -354,23 +354,23 @@ discard block |
||
354 | 354 | * @version 4.0.0 |
355 | 355 | * @param object $notification |
356 | 356 | */ |
357 | - public function process_webhook_source_canceled( $notification ) { |
|
358 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
357 | + public function process_webhook_source_canceled($notification) { |
|
358 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
359 | 359 | |
360 | - if ( ! $order ) { |
|
361 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
360 | + if ( ! $order) { |
|
361 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
362 | 362 | return; |
363 | 363 | } |
364 | 364 | |
365 | 365 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
366 | 366 | |
367 | - if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) { |
|
367 | + if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) { |
|
368 | 368 | return; |
369 | 369 | } |
370 | 370 | |
371 | - $order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) ); |
|
371 | + $order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe')); |
|
372 | 372 | |
373 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
373 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | /** |
@@ -381,37 +381,37 @@ discard block |
||
381 | 381 | * @version 4.0.0 |
382 | 382 | * @param object $notification |
383 | 383 | */ |
384 | - public function process_webhook_refund( $notification ) { |
|
385 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
384 | + public function process_webhook_refund($notification) { |
|
385 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
386 | 386 | |
387 | - if ( ! $order ) { |
|
388 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
387 | + if ( ! $order) { |
|
388 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
389 | 389 | return; |
390 | 390 | } |
391 | 391 | |
392 | 392 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
393 | 393 | |
394 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
395 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
396 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
397 | - $refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_refund_id', true ) : $order->get_meta( '_stripe_refund_id', true ); |
|
394 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
395 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
396 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
397 | + $refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_refund_id', true) : $order->get_meta('_stripe_refund_id', true); |
|
398 | 398 | |
399 | 399 | // If the refund ID matches, don't continue to prevent double refunding. |
400 | - if ( $notification->data->object->refunds->data[0]->id === $refund_id ) { |
|
400 | + if ($notification->data->object->refunds->data[0]->id === $refund_id) { |
|
401 | 401 | return; |
402 | 402 | } |
403 | 403 | |
404 | 404 | // Only refund captured charge. |
405 | - if ( $charge && 'yes' === $captured ) { |
|
405 | + if ($charge && 'yes' === $captured) { |
|
406 | 406 | // Create the refund. |
407 | - $refund = wc_create_refund( array( |
|
407 | + $refund = wc_create_refund(array( |
|
408 | 408 | 'order_id' => $order_id, |
409 | - 'amount' => $this->get_refund_amount( $notification ), |
|
410 | - 'reason' => __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ), |
|
411 | - ) ); |
|
409 | + 'amount' => $this->get_refund_amount($notification), |
|
410 | + 'reason' => __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe'), |
|
411 | + )); |
|
412 | 412 | |
413 | - if ( is_wp_error( $refund ) ) { |
|
414 | - WC_Stripe_Logger::log( $refund->get_error_message() ); |
|
413 | + if (is_wp_error($refund)) { |
|
414 | + WC_Stripe_Logger::log($refund->get_error_message()); |
|
415 | 415 | } |
416 | 416 | } |
417 | 417 | } |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | * @version 4.0.0 |
425 | 425 | * @param object $notification |
426 | 426 | */ |
427 | - public function is_partial_capture( $notification ) { |
|
427 | + public function is_partial_capture($notification) { |
|
428 | 428 | return 0 < $notification->data->object->amount_refunded; |
429 | 429 | } |
430 | 430 | |
@@ -435,11 +435,11 @@ discard block |
||
435 | 435 | * @version 4.0.0 |
436 | 436 | * @param object $notification |
437 | 437 | */ |
438 | - public function get_refund_amount( $notification ) { |
|
439 | - if ( $this->is_partial_capture( $notification ) ) { |
|
438 | + public function get_refund_amount($notification) { |
|
439 | + if ($this->is_partial_capture($notification)) { |
|
440 | 440 | $amount = $notification->data->object->amount_refunded / 100; |
441 | 441 | |
442 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
442 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
443 | 443 | $amount = $notification->data->object->amount_refunded; |
444 | 444 | } |
445 | 445 | |
@@ -456,12 +456,12 @@ discard block |
||
456 | 456 | * @version 4.0.0 |
457 | 457 | * @param object $notification |
458 | 458 | */ |
459 | - public function get_partial_amount_to_charge( $notification ) { |
|
460 | - if ( $this->is_partial_capture( $notification ) ) { |
|
461 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100; |
|
459 | + public function get_partial_amount_to_charge($notification) { |
|
460 | + if ($this->is_partial_capture($notification)) { |
|
461 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100; |
|
462 | 462 | |
463 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
464 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ); |
|
463 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
464 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | return $amount; |
@@ -477,36 +477,36 @@ discard block |
||
477 | 477 | * @version 4.0.0 |
478 | 478 | * @param string $request_body |
479 | 479 | */ |
480 | - public function process_webhook( $request_body ) { |
|
481 | - $notification = json_decode( $request_body ); |
|
480 | + public function process_webhook($request_body) { |
|
481 | + $notification = json_decode($request_body); |
|
482 | 482 | |
483 | - switch ( $notification->type ) { |
|
483 | + switch ($notification->type) { |
|
484 | 484 | case 'source.chargeable': |
485 | - $this->process_webhook_payment( $notification ); |
|
485 | + $this->process_webhook_payment($notification); |
|
486 | 486 | break; |
487 | 487 | |
488 | 488 | case 'source.canceled': |
489 | - $this->process_webhook_source_canceled( $notification ); |
|
489 | + $this->process_webhook_source_canceled($notification); |
|
490 | 490 | break; |
491 | 491 | |
492 | 492 | case 'charge.succeeded': |
493 | - $this->process_webhook_charge_succeeded( $notification ); |
|
493 | + $this->process_webhook_charge_succeeded($notification); |
|
494 | 494 | break; |
495 | 495 | |
496 | 496 | case 'charge.failed': |
497 | - $this->process_webhook_charge_failed( $notification ); |
|
497 | + $this->process_webhook_charge_failed($notification); |
|
498 | 498 | break; |
499 | 499 | |
500 | 500 | case 'charge.captured': |
501 | - $this->process_webhook_capture( $notification ); |
|
501 | + $this->process_webhook_capture($notification); |
|
502 | 502 | break; |
503 | 503 | |
504 | 504 | case 'charge.dispute.created': |
505 | - $this->process_webhook_dispute( $notification ); |
|
505 | + $this->process_webhook_dispute($notification); |
|
506 | 506 | break; |
507 | 507 | |
508 | 508 | case 'charge.refunded': |
509 | - $this->process_webhook_refund( $notification ); |
|
509 | + $this->process_webhook_refund($notification); |
|
510 | 510 | break; |
511 | 511 | |
512 | 512 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | * Check if this gateway is enabled |
19 | 19 | */ |
20 | 20 | public function is_available() { |
21 | - if ( 'yes' === $this->enabled ) { |
|
22 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
21 | + if ('yes' === $this->enabled) { |
|
22 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
23 | 23 | return false; |
24 | 24 | } |
25 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
25 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
26 | 26 | return false; |
27 | 27 | } |
28 | 28 | return true; |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | * @since 4.0.0 |
38 | 38 | * @version 4.0.0 |
39 | 39 | */ |
40 | - public function add_admin_notice( $slug, $class, $message ) { |
|
41 | - $this->notices[ $slug ] = array( |
|
40 | + public function add_admin_notice($slug, $class, $message) { |
|
41 | + $this->notices[$slug] = array( |
|
42 | 42 | 'class' => $class, |
43 | 43 | 'message' => $message, |
44 | 44 | ); |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * @version 4.0.0 |
52 | 52 | */ |
53 | 53 | public function remove_admin_notice() { |
54 | - if ( did_action( 'woocommerce_update_options' ) ) { |
|
55 | - remove_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
54 | + if (did_action('woocommerce_update_options')) { |
|
55 | + remove_action('admin_notices', array($this, 'check_environment')); |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @return array |
65 | 65 | */ |
66 | 66 | public function payment_icons() { |
67 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
67 | + return apply_filters('wc_stripe_payment_icons', array( |
|
68 | 68 | 'visa' => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>', |
69 | 69 | 'amex' => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>', |
70 | 70 | 'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>', |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | 'eps' => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>', |
82 | 82 | 'sofort' => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>', |
83 | 83 | 'sepa' => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>', |
84 | - ) ); |
|
84 | + )); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -92,10 +92,10 @@ discard block |
||
92 | 92 | * @version 4.0.0 |
93 | 93 | * @param object $order |
94 | 94 | */ |
95 | - public function validate_minimum_order_amount( $order ) { |
|
96 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
95 | + public function validate_minimum_order_amount($order) { |
|
96 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
97 | 97 | /* translators: 1) dollar amount */ |
98 | - throw new WC_Stripe_Exception( 'Did not meet minimum amount', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
98 | + throw new WC_Stripe_Exception('Did not meet minimum amount', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
@@ -105,14 +105,14 @@ discard block |
||
105 | 105 | * @since 4.0.0 |
106 | 106 | * @version 4.0.0 |
107 | 107 | */ |
108 | - public function get_transaction_url( $order ) { |
|
109 | - if ( $this->testmode ) { |
|
108 | + public function get_transaction_url($order) { |
|
109 | + if ($this->testmode) { |
|
110 | 110 | $this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s'; |
111 | 111 | } else { |
112 | 112 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
113 | 113 | } |
114 | 114 | |
115 | - return parent::get_transaction_url( $order ); |
|
115 | + return parent::get_transaction_url($order); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -121,15 +121,15 @@ discard block |
||
121 | 121 | * @since 4.0.0 |
122 | 122 | * @version 4.0.0 |
123 | 123 | */ |
124 | - public function get_stripe_customer_id( $order ) { |
|
125 | - $customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true ); |
|
124 | + public function get_stripe_customer_id($order) { |
|
125 | + $customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true); |
|
126 | 126 | |
127 | - if ( empty( $customer ) ) { |
|
127 | + if (empty($customer)) { |
|
128 | 128 | // Try to get it via the order. |
129 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
130 | - return get_post_meta( $order->id, '_stripe_customer_id', true ); |
|
129 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
130 | + return get_post_meta($order->id, '_stripe_customer_id', true); |
|
131 | 131 | } else { |
132 | - return $order->get_meta( '_stripe_customer_id', true ); |
|
132 | + return $order->get_meta('_stripe_customer_id', true); |
|
133 | 133 | } |
134 | 134 | } else { |
135 | 135 | return $customer; |
@@ -146,9 +146,9 @@ discard block |
||
146 | 146 | * @param object $order |
147 | 147 | * @param int $id Stripe session id. |
148 | 148 | */ |
149 | - public function get_stripe_return_url( $order = null, $id = null ) { |
|
150 | - if ( is_object( $order ) ) { |
|
151 | - if ( empty( $id ) ) { |
|
149 | + public function get_stripe_return_url($order = null, $id = null) { |
|
150 | + if (is_object($order)) { |
|
151 | + if (empty($id)) { |
|
152 | 152 | $id = uniqid(); |
153 | 153 | } |
154 | 154 | |
@@ -159,10 +159,10 @@ discard block |
||
159 | 159 | 'order_id' => $order_id, |
160 | 160 | ); |
161 | 161 | |
162 | - return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ); |
|
162 | + return esc_url_raw(add_query_arg($args, $this->get_return_url($order))); |
|
163 | 163 | } |
164 | 164 | |
165 | - return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ); |
|
165 | + return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -174,48 +174,47 @@ discard block |
||
174 | 174 | * @param object $source |
175 | 175 | * @return array() |
176 | 176 | */ |
177 | - public function generate_payment_request( $order, $source ) { |
|
178 | - $settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
179 | - $statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : ''; |
|
180 | - $capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false; |
|
177 | + public function generate_payment_request($order, $source) { |
|
178 | + $settings = get_option('woocommerce_stripe_settings', array()); |
|
179 | + $statement_descriptor = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : ''; |
|
180 | + $capture = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false; |
|
181 | 181 | $post_data = array(); |
182 | - $post_data['currency'] = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() ); |
|
183 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
182 | + $post_data['currency'] = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency()); |
|
183 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
184 | 184 | /* translators: 1) blog name 2) order number */ |
185 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
185 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
186 | 186 | $billing_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
187 | 187 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
188 | 188 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
189 | 189 | |
190 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
190 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
191 | 191 | $post_data['receipt_email'] = $billing_email; |
192 | 192 | } |
193 | 193 | |
194 | - switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) { |
|
195 | - case 'stripe': |
|
196 | - if ( ! empty( $statement_descriptor ) ) { |
|
197 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
194 | + switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) { |
|
195 | + case 'stripe' : if ( ! empty($statement_descriptor)) { |
|
196 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
198 | 197 | } |
199 | 198 | |
200 | - $post_data['capture'] = $capture ? 'true' : 'false'; |
|
199 | + $post_data['capture'] = $capture ? 'true' : 'false'; |
|
201 | 200 | break; |
202 | 201 | } |
203 | 202 | |
204 | 203 | $post_data['expand[]'] = 'balance_transaction'; |
205 | 204 | |
206 | 205 | $metadata = array( |
207 | - __( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
208 | - __( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
206 | + __('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
207 | + __('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
209 | 208 | 'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(), |
210 | 209 | ); |
211 | 210 | |
212 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source ); |
|
211 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source); |
|
213 | 212 | |
214 | - if ( $source->customer ) { |
|
213 | + if ($source->customer) { |
|
215 | 214 | $post_data['customer'] = $source->customer; |
216 | 215 | } |
217 | 216 | |
218 | - if ( $source->source ) { |
|
217 | + if ($source->source) { |
|
219 | 218 | $post_data['source'] = $source->source; |
220 | 219 | } |
221 | 220 | |
@@ -227,77 +226,77 @@ discard block |
||
227 | 226 | * @param WC_Order $order |
228 | 227 | * @param object $source |
229 | 228 | */ |
230 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
229 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
231 | 230 | } |
232 | 231 | |
233 | 232 | /** |
234 | 233 | * Store extra meta data for an order from a Stripe Response. |
235 | 234 | */ |
236 | - public function process_response( $response, $order ) { |
|
237 | - WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) ); |
|
235 | + public function process_response($response, $order) { |
|
236 | + WC_Stripe_Logger::log('Processing response: ' . print_r($response, true)); |
|
238 | 237 | |
239 | 238 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
240 | 239 | |
241 | - $captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no'; |
|
240 | + $captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no'; |
|
242 | 241 | |
243 | 242 | // Store charge data |
244 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured ); |
|
243 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured); |
|
245 | 244 | |
246 | 245 | // Store other data such as fees |
247 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
246 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
248 | 247 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
249 | 248 | // values are in the local currency of the Stripe account, not from WC. |
250 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0; |
|
251 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0; |
|
252 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
253 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
249 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0; |
|
250 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0; |
|
251 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
252 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
254 | 253 | } |
255 | 254 | |
256 | - if ( 'yes' === $captured ) { |
|
255 | + if ('yes' === $captured) { |
|
257 | 256 | /** |
258 | 257 | * Charge can be captured but in a pending state. Payment methods |
259 | 258 | * that are asynchronous may take couple days to clear. Webhook will |
260 | 259 | * take care of the status changes. |
261 | 260 | */ |
262 | - if ( 'pending' === $response->status ) { |
|
263 | - if ( ! wc_string_to_bool( get_post_meta( $order_id, '_order_stock_reduced', true ) ) ) { |
|
264 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
261 | + if ('pending' === $response->status) { |
|
262 | + if ( ! wc_string_to_bool(get_post_meta($order_id, '_order_stock_reduced', true))) { |
|
263 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
265 | 264 | } |
266 | 265 | |
267 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id, true ) : $order->set_transaction_id( $response->id ); |
|
266 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id, true) : $order->set_transaction_id($response->id); |
|
268 | 267 | /* translators: transaction id */ |
269 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
268 | + $order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id)); |
|
270 | 269 | } |
271 | 270 | |
272 | - if ( 'succeeded' === $response->status ) { |
|
273 | - $order->payment_complete( $response->id ); |
|
271 | + if ('succeeded' === $response->status) { |
|
272 | + $order->payment_complete($response->id); |
|
274 | 273 | |
275 | 274 | /* translators: transaction id */ |
276 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
277 | - $order->add_order_note( $message ); |
|
275 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
276 | + $order->add_order_note($message); |
|
278 | 277 | } |
279 | 278 | |
280 | - if ( 'failed' === $response->status ) { |
|
281 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
282 | - $order->add_order_note( $localized_message ); |
|
283 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
279 | + if ('failed' === $response->status) { |
|
280 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
281 | + $order->add_order_note($localized_message); |
|
282 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
284 | 283 | } |
285 | 284 | } else { |
286 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id, true ) : $order->set_transaction_id( $response->id ); |
|
285 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id, true) : $order->set_transaction_id($response->id); |
|
287 | 286 | |
288 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
289 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
287 | + if ($order->has_status(array('pending', 'failed'))) { |
|
288 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
290 | 289 | } |
291 | 290 | |
292 | 291 | /* translators: transaction id */ |
293 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
292 | + $order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id)); |
|
294 | 293 | } |
295 | 294 | |
296 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
295 | + if (is_callable(array($order, 'save'))) { |
|
297 | 296 | $order->save(); |
298 | 297 | } |
299 | 298 | |
300 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
299 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
301 | 300 | |
302 | 301 | return $response; |
303 | 302 | } |
@@ -310,10 +309,10 @@ discard block |
||
310 | 309 | * @param int $order_id |
311 | 310 | * @return null |
312 | 311 | */ |
313 | - public function send_failed_order_email( $order_id ) { |
|
312 | + public function send_failed_order_email($order_id) { |
|
314 | 313 | $emails = WC()->mailer()->get_emails(); |
315 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
316 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
314 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
315 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
317 | 316 | } |
318 | 317 | } |
319 | 318 | |
@@ -325,7 +324,7 @@ discard block |
||
325 | 324 | * @param object $order |
326 | 325 | * @return object $details |
327 | 326 | */ |
328 | - public function get_owner_details( $order ) { |
|
327 | + public function get_owner_details($order) { |
|
329 | 328 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
330 | 329 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
331 | 330 | |
@@ -336,8 +335,8 @@ discard block |
||
336 | 335 | |
337 | 336 | $phone = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone(); |
338 | 337 | |
339 | - if ( ! empty( $phone ) ) { |
|
340 | - $details['phone'] = $phone; |
|
338 | + if ( ! empty($phone)) { |
|
339 | + $details['phone'] = $phone; |
|
341 | 340 | } |
342 | 341 | |
343 | 342 | $details['address']['line1'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1(); |
@@ -347,7 +346,7 @@ discard block |
||
347 | 346 | $details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode(); |
348 | 347 | $details['address']['country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
349 | 348 | |
350 | - return (object) apply_filters( 'wc_stripe_owner_details', $details, $order ); |
|
349 | + return (object) apply_filters('wc_stripe_owner_details', $details, $order); |
|
351 | 350 | } |
352 | 351 | |
353 | 352 | /** |
@@ -363,58 +362,58 @@ discard block |
||
363 | 362 | * @throws Exception When card was not added or for and invalid card. |
364 | 363 | * @return object |
365 | 364 | */ |
366 | - public function prepare_source( $user_id, $force_save_source = false ) { |
|
367 | - $customer = new WC_Stripe_Customer( $user_id ); |
|
365 | + public function prepare_source($user_id, $force_save_source = false) { |
|
366 | + $customer = new WC_Stripe_Customer($user_id); |
|
368 | 367 | $set_customer = true; |
369 | - $force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer ); |
|
368 | + $force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer); |
|
370 | 369 | $source = ''; |
371 | 370 | $wc_token_id = false; |
372 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
371 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
373 | 372 | |
374 | 373 | // New CC info was entered and we have a new source to process. |
375 | - if ( ! empty( $_POST['stripe_source'] ) ) { |
|
374 | + if ( ! empty($_POST['stripe_source'])) { |
|
376 | 375 | // This gets the source object from Stripe. |
377 | - $source = json_decode( wc_clean( stripslashes( $_POST['stripe_source'] ) ) ); |
|
376 | + $source = json_decode(wc_clean(stripslashes($_POST['stripe_source']))); |
|
378 | 377 | |
379 | 378 | // This checks to see if customer opted to save the payment method to file. |
380 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
379 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
381 | 380 | |
382 | 381 | /** |
383 | 382 | * This is true if the user wants to store the card to their account. |
384 | 383 | * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is |
385 | 384 | * actually reusable. Either that or force_save_source is true. |
386 | 385 | */ |
387 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source->usage ) || $force_save_source ) { |
|
388 | - $source = $customer->add_source( $source->id ); |
|
386 | + if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source->usage) || $force_save_source) { |
|
387 | + $source = $customer->add_source($source->id); |
|
389 | 388 | |
390 | - if ( ! empty( $source->error ) ) { |
|
391 | - throw new WC_Stripe_Exception( print_r( $source, true ), $source->error->message ); |
|
389 | + if ( ! empty($source->error)) { |
|
390 | + throw new WC_Stripe_Exception(print_r($source, true), $source->error->message); |
|
392 | 391 | } |
393 | 392 | } else { |
394 | 393 | $source = $source->id; |
395 | 394 | } |
396 | - } elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) { |
|
395 | + } elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) { |
|
397 | 396 | // Use an existing token, and then process the payment |
398 | 397 | |
399 | - $wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
400 | - $wc_token = WC_Payment_Tokens::get( $wc_token_id ); |
|
398 | + $wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']); |
|
399 | + $wc_token = WC_Payment_Tokens::get($wc_token_id); |
|
401 | 400 | |
402 | - if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) { |
|
403 | - WC()->session->set( 'refresh_totals', true ); |
|
404 | - throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
401 | + if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) { |
|
402 | + WC()->session->set('refresh_totals', true); |
|
403 | + throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
405 | 404 | } |
406 | 405 | |
407 | 406 | $source = $wc_token->get_token(); |
408 | - } elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) { |
|
409 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
410 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
407 | + } elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) { |
|
408 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
409 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
411 | 410 | |
412 | 411 | // This is true if the user wants to store the card to their account. |
413 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) { |
|
414 | - $source = $customer->add_source( $stripe_token ); |
|
412 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) { |
|
413 | + $source = $customer->add_source($stripe_token); |
|
415 | 414 | |
416 | - if ( ! empty( $source->error ) ) { |
|
417 | - throw new WC_Stripe_Exception( print_r( $source, true ), $source->error->message ); |
|
415 | + if ( ! empty($source->error)) { |
|
416 | + throw new WC_Stripe_Exception(print_r($source, true), $source->error->message); |
|
418 | 417 | } |
419 | 418 | } else { |
420 | 419 | $set_customer = false; |
@@ -422,7 +421,7 @@ discard block |
||
422 | 421 | } |
423 | 422 | } |
424 | 423 | |
425 | - if ( ! $set_customer ) { |
|
424 | + if ( ! $set_customer) { |
|
426 | 425 | $customer_id = false; |
427 | 426 | } else { |
428 | 427 | $customer_id = $customer->get_id() ? $customer->get_id() : false; |
@@ -443,27 +442,27 @@ discard block |
||
443 | 442 | * @param WC_Order $order For to which the source applies. |
444 | 443 | * @param stdClass $source Source information. |
445 | 444 | */ |
446 | - public function save_source( $order, $source ) { |
|
445 | + public function save_source($order, $source) { |
|
447 | 446 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
448 | 447 | |
449 | 448 | // Store source in the order. |
450 | - if ( $source->customer ) { |
|
451 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
452 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
449 | + if ($source->customer) { |
|
450 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
451 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
453 | 452 | } else { |
454 | - $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
453 | + $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
455 | 454 | } |
456 | 455 | } |
457 | 456 | |
458 | - if ( $source->source ) { |
|
459 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
460 | - update_post_meta( $order_id, '_stripe_source_id', $source->source ); |
|
457 | + if ($source->source) { |
|
458 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
459 | + update_post_meta($order_id, '_stripe_source_id', $source->source); |
|
461 | 460 | } else { |
462 | - $order->update_meta_data( '_stripe_source_id', $source->source ); |
|
461 | + $order->update_meta_data('_stripe_source_id', $source->source); |
|
463 | 462 | } |
464 | 463 | } |
465 | 464 | |
466 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
465 | + if (is_callable(array($order, 'save'))) { |
|
467 | 466 | $order->save(); |
468 | 467 | } |
469 | 468 | } |
@@ -481,35 +480,35 @@ discard block |
||
481 | 480 | * @param object $order |
482 | 481 | * @return object |
483 | 482 | */ |
484 | - public function prepare_order_source( $order = null ) { |
|
483 | + public function prepare_order_source($order = null) { |
|
485 | 484 | $stripe_customer = new WC_Stripe_Customer(); |
486 | 485 | $stripe_source = false; |
487 | 486 | $token_id = false; |
488 | 487 | |
489 | - if ( $order ) { |
|
488 | + if ($order) { |
|
490 | 489 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
491 | 490 | |
492 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
491 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
493 | 492 | |
494 | - if ( $stripe_customer_id ) { |
|
495 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
493 | + if ($stripe_customer_id) { |
|
494 | + $stripe_customer->set_id($stripe_customer_id); |
|
496 | 495 | } |
497 | 496 | |
498 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true ); |
|
497 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true); |
|
499 | 498 | |
500 | 499 | // Since 4.0.0, we changed card to source so we need to account for that. |
501 | - if ( empty( $source_id ) ) { |
|
502 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true ); |
|
500 | + if (empty($source_id)) { |
|
501 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true); |
|
503 | 502 | |
504 | 503 | // Take this opportunity to update the key name. |
505 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id ); |
|
504 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id); |
|
506 | 505 | |
507 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
506 | + if (is_callable(array($order, 'save'))) { |
|
508 | 507 | $order->save(); |
509 | 508 | } |
510 | 509 | } |
511 | 510 | |
512 | - if ( $source_id ) { |
|
511 | + if ($source_id) { |
|
513 | 512 | $stripe_source = $source_id; |
514 | 513 | } |
515 | 514 | } |
@@ -530,27 +529,27 @@ discard block |
||
530 | 529 | * @param object $order The order object |
531 | 530 | * @param int $balance_transaction_id |
532 | 531 | */ |
533 | - public function update_fees( $order, $balance_transaction_id ) { |
|
532 | + public function update_fees($order, $balance_transaction_id) { |
|
534 | 533 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
535 | 534 | |
536 | - $balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id ); |
|
535 | + $balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id); |
|
537 | 536 | |
538 | - if ( empty( $balance_transaction->error ) ) { |
|
539 | - if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) { |
|
537 | + if (empty($balance_transaction->error)) { |
|
538 | + if (isset($balance_transaction) && isset($balance_transaction->fee)) { |
|
540 | 539 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
541 | 540 | // values are in the local currency of the Stripe account, not from WC. |
542 | - $fee = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0; |
|
543 | - $net = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0; |
|
541 | + $fee = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0; |
|
542 | + $net = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0; |
|
544 | 543 | |
545 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
546 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
544 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
545 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
547 | 546 | |
548 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
547 | + if (is_callable(array($order, 'save'))) { |
|
549 | 548 | $order->save(); |
550 | 549 | } |
551 | 550 | } |
552 | 551 | } else { |
553 | - WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" ); |
|
552 | + WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}"); |
|
554 | 553 | } |
555 | 554 | } |
556 | 555 | |
@@ -563,57 +562,57 @@ discard block |
||
563 | 562 | * @param float $amount |
564 | 563 | * @return bool |
565 | 564 | */ |
566 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
567 | - $order = wc_get_order( $order_id ); |
|
565 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
566 | + $order = wc_get_order($order_id); |
|
568 | 567 | |
569 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
568 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
570 | 569 | return false; |
571 | 570 | } |
572 | 571 | |
573 | 572 | $body = array(); |
574 | 573 | |
575 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
576 | - $order_currency = get_post_meta( $order_id, '_order_currency', true ); |
|
574 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
575 | + $order_currency = get_post_meta($order_id, '_order_currency', true); |
|
577 | 576 | } else { |
578 | 577 | $order_currency = $order->get_currency(); |
579 | 578 | } |
580 | 579 | |
581 | - if ( ! is_null( $amount ) ) { |
|
582 | - $body['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency ); |
|
580 | + if ( ! is_null($amount)) { |
|
581 | + $body['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency); |
|
583 | 582 | } |
584 | 583 | |
585 | - if ( $reason ) { |
|
584 | + if ($reason) { |
|
586 | 585 | $body['metadata'] = array( |
587 | 586 | 'reason' => $reason, |
588 | 587 | ); |
589 | 588 | } |
590 | 589 | |
591 | - WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" ); |
|
590 | + WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}"); |
|
592 | 591 | |
593 | - $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
592 | + $response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds'); |
|
594 | 593 | |
595 | - if ( ! empty( $response->error ) ) { |
|
596 | - WC_Stripe_Logger::log( 'Error: ' . $response->error->message ); |
|
594 | + if ( ! empty($response->error)) { |
|
595 | + WC_Stripe_Logger::log('Error: ' . $response->error->message); |
|
597 | 596 | |
598 | 597 | return $response; |
599 | 598 | |
600 | - } elseif ( ! empty( $response->id ) ) { |
|
601 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id ); |
|
599 | + } elseif ( ! empty($response->id)) { |
|
600 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id); |
|
602 | 601 | |
603 | - $amount = wc_price( $response->amount / 100 ); |
|
602 | + $amount = wc_price($response->amount / 100); |
|
604 | 603 | |
605 | - if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
606 | - $amount = wc_price( $response->amount ); |
|
604 | + if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
605 | + $amount = wc_price($response->amount); |
|
607 | 606 | } |
608 | 607 | |
609 | - if ( isset( $response->balance_transaction ) ) { |
|
610 | - $this->update_fees( $order, $response->balance_transaction ); |
|
608 | + if (isset($response->balance_transaction)) { |
|
609 | + $this->update_fees($order, $response->balance_transaction); |
|
611 | 610 | } |
612 | 611 | |
613 | 612 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
614 | - $refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ); |
|
615 | - $order->add_order_note( $refund_message ); |
|
616 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
613 | + $refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason); |
|
614 | + $order->add_order_note($refund_message); |
|
615 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
617 | 616 | |
618 | 617 | return true; |
619 | 618 | } |
@@ -628,41 +627,41 @@ discard block |
||
628 | 627 | */ |
629 | 628 | public function add_payment_method() { |
630 | 629 | $error = false; |
631 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
630 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
632 | 631 | $source_id = ''; |
633 | 632 | |
634 | - if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
633 | + if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
635 | 634 | $error = true; |
636 | 635 | } |
637 | 636 | |
638 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
637 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
639 | 638 | |
640 | - if ( isset( $_POST['stripe_source'] ) ) { |
|
641 | - $source = json_decode( wc_clean( stripslashes( $_POST['stripe_source'] ) ) ); |
|
639 | + if (isset($_POST['stripe_source'])) { |
|
640 | + $source = json_decode(wc_clean(stripslashes($_POST['stripe_source']))); |
|
642 | 641 | |
643 | - if ( ! empty( $source->error ) ) { |
|
642 | + if ( ! empty($source->error)) { |
|
644 | 643 | $error = true; |
645 | 644 | } |
646 | 645 | |
647 | 646 | $source_id = $source->id; |
648 | - } elseif ( isset( $_POST['stripe_token'] ) ) { |
|
649 | - $source_id = wc_clean( $_POST['stripe_token'] ); |
|
647 | + } elseif (isset($_POST['stripe_token'])) { |
|
648 | + $source_id = wc_clean($_POST['stripe_token']); |
|
650 | 649 | } |
651 | 650 | |
652 | - $response = $stripe_customer->add_source( $source_id ); |
|
651 | + $response = $stripe_customer->add_source($source_id); |
|
653 | 652 | |
654 | - if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) { |
|
653 | + if ( ! $response || is_wp_error($response) || ! empty($response->error)) { |
|
655 | 654 | $error = true; |
656 | 655 | } |
657 | 656 | |
658 | - if ( $error ) { |
|
659 | - wc_add_notice( $error_msg, 'error' ); |
|
657 | + if ($error) { |
|
658 | + wc_add_notice($error_msg, 'error'); |
|
660 | 659 | return; |
661 | 660 | } |
662 | 661 | |
663 | 662 | return array( |
664 | 663 | 'result' => 'success', |
665 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
664 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
666 | 665 | ); |
667 | 666 | } |
668 | 667 | } |